From e30851c9831fedeae876c2c1ef149e73596273b8 Mon Sep 17 00:00:00 2001 From: xeolabs Date: Wed, 15 May 2024 11:39:21 +0200 Subject: [PATCH] Rebuild --- dist/xeokit-sdk.cjs.js | 6 +++--- dist/xeokit-sdk.es.js | 6 +++--- dist/xeokit-sdk.es5.js | 4 ++-- dist/xeokit-sdk.min.cjs.js | 2 +- dist/xeokit-sdk.min.es.js | 2 +- dist/xeokit-sdk.min.es5.js | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dist/xeokit-sdk.cjs.js b/dist/xeokit-sdk.cjs.js index e34c8109a..d2c41f274 100644 --- a/dist/xeokit-sdk.cjs.js +++ b/dist/xeokit-sdk.cjs.js @@ -10460,7 +10460,7 @@ const tempVec4b$6 = math.vec4(); * }); * * // Create the Marker, associated with our Mesh Entity - * const myMarker = new Marker({ + * const myMarker = new Marker(viewer, { * entity: entity, * worldPos: [10,0,0], * occludable: true @@ -96618,8 +96618,8 @@ function getCanvasPosFromEvent$2(event, canvas, canvasPos) { canvasPos[1] = event.y; } else { const { left, top } = canvas.getBoundingClientRect(); - canvasPos[0] = event.clientX - left - window.scrollX; - canvasPos[1] = event.clientY - top - window.scrollY; + canvasPos[0] = event.clientX - left; + canvasPos[1] = event.clientY - top; } return canvasPos; } diff --git a/dist/xeokit-sdk.es.js b/dist/xeokit-sdk.es.js index b0369aeb0..0838cba48 100644 --- a/dist/xeokit-sdk.es.js +++ b/dist/xeokit-sdk.es.js @@ -10456,7 +10456,7 @@ const tempVec4b$6 = math.vec4(); * }); * * // Create the Marker, associated with our Mesh Entity - * const myMarker = new Marker({ + * const myMarker = new Marker(viewer, { * entity: entity, * worldPos: [10,0,0], * occludable: true @@ -96614,8 +96614,8 @@ function getCanvasPosFromEvent$2(event, canvas, canvasPos) { canvasPos[1] = event.y; } else { const { left, top } = canvas.getBoundingClientRect(); - canvasPos[0] = event.clientX - left - window.scrollX; - canvasPos[1] = event.clientY - top - window.scrollY; + canvasPos[0] = event.clientX - left; + canvasPos[1] = event.clientY - top; } return canvasPos; } diff --git a/dist/xeokit-sdk.es5.js b/dist/xeokit-sdk.es5.js index 618edf4db..3a683aa75 100644 --- a/dist/xeokit-sdk.es5.js +++ b/dist/xeokit-sdk.es5.js @@ -2615,7 +2615,7 @@ if(lastOpacityQuantized===opacityQuantized){return;}}else{opacityQuantized=255.0 * }); * * // Create the Marker, associated with our Mesh Entity - * const myMarker = new Marker({ + * const myMarker = new Marker(viewer, { * entity: entity, * worldPos: [10,0,0], * occludable: true @@ -22587,7 +22587,7 @@ if(Math.abs(updates.panDeltaX)>t;i.sort(PA);const s=new Int32Array(e.length);for(let t=0,r=i.length;te[t+1]){let i=e[t];e[t]=e[t+1],e[t+1]=i}CA=new Int32Array(e),t.sort(MA);const i=new Int32Array(e.length);for(let s=0,r=t.length;st){let i=e;e=t,t=i}function i(i,s){return i!==e?e-i:s!==t?t-s:0}let s=0,r=(o.length>>1)-1;for(;s<=r;){const e=r+s>>1,t=i(o[2*e],o[2*e+1]);if(t>0)s=e+1;else{if(!(t<0))return e;r=e-1}}return-s-1}const a=new Int32Array(o.length/2);a.fill(0);const l=s.length/3;if(l>8*(1<u.maxNumPositions&&(u=c()),u.bucketNumber>8)return[e];let p;-1===A[l]&&(A[l]=u.numPositions++,u.positionsCompressed.push(s[3*l]),u.positionsCompressed.push(s[3*l+1]),u.positionsCompressed.push(s[3*l+2])),-1===A[h]&&(A[h]=u.numPositions++,u.positionsCompressed.push(s[3*h]),u.positionsCompressed.push(s[3*h+1]),u.positionsCompressed.push(s[3*h+2])),-1===A[d]&&(A[d]=u.numPositions++,u.positionsCompressed.push(s[3*d]),u.positionsCompressed.push(s[3*d+1]),u.positionsCompressed.push(s[3*d+2])),u.indices.push(A[l]),u.indices.push(A[h]),u.indices.push(A[d]),(p=n(l,h))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(l,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(h,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]]))}const d=t/8*2,p=t/8,f=2*s.length+(r.length+o.length)*d;let g=0,m=-s.length/3;return h.forEach((e=>{g+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*p,m+=e.positionsCompressed.length/3})),g>f?[e]:(i&&function(e,t){const i={},s={};let r=0;e.forEach((e=>{const t=e.indices,o=e.edgeIndices,n=e.positionsCompressed;for(let e=0,s=t.length;e0){const e=t._meshes;for(let t=0,i=e.length;t0){const e=this._meshes;for(let t=0,i=e.length;t{this._viewMatrixDirty=!0})),this._meshesWithDirtyMatrices=[],this._numMeshesWithDirtyMatrices=0,this._onTick=this.scene.on("tick",(()=>{for(;this._numMeshesWithDirtyMatrices>0;)this._meshesWithDirtyMatrices[--this._numMeshesWithDirtyMatrices]._updateMatrix()})),this._createDefaultTextureSet(),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.backfaces=t.backfaces}_meshMatrixDirty(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}_createDefaultTextureSet(){const e=new lA({id:"defaultColorTexture",texture:new _s({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new lA({id:"defaultMetalRoughTexture",texture:new _s({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),i=new lA({id:"defaultNormalsTexture",texture:new _s({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),s=new lA({id:"defaultEmissiveTexture",texture:new _s({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),r=new lA({id:"defaultOcclusionTexture",texture:new _s({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=i,this._textures.defaultEmissiveTexture=s,this._textures.defaultOcclusionTexture=r,this._textureSets.defaultTextureSet=new aA({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:i,emissiveTexture:s,occlusionTexture:r})}get isPerformanceModel(){return!0}get transforms(){return this._transforms}get textures(){return this._textures}get textureSets(){return this._textureSets}get meshes(){return this._meshes}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),c.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),c.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||jA),c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),c.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),c.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),c.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),c.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0,this._aabbDirty=!0}_transformDirty(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}_sceneModelDirty(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(let e=0,t=this._entityList.length;e0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,i=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,i=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,i=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,i=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,i=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,i=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,i=new Uint8Array(t.length);for(let e=0,s=t.length;e{l.setImage(A,{minFilter:i,magFilter:s,wrapS:r,wrapT:o,wrapR:n,flipY:e.flipY,encoding:a}),this.glRedraw()},A.src=e.src;break;default:this._textureTranscoder?_.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new lA({id:t,texture:l})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let i,s,r,o,n;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(i=this._textures[e.colorTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(s=this._textures[e.metallicRoughnessTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(r=this._textures[e.normalsTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(o=this._textures[e.emissiveTextureId],!o)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else o=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(n=this._textures[e.occlusionTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultOcclusionTexture;const a=new aA({id:t,model:this,colorTexture:i,metallicRoughnessTexture:s,normalsTexture:r,emissiveTexture:o,occlusionTexture:n});return this._textureSets[t]=a,a}createTransform(e){if(void 0===e.id||null===e.id)return void this.error("[createTransform] SceneModel.createTransform() config missing: id");if(this._transforms[e.id])return void this.error(`[createTransform] SceneModel already has a transform with this ID: ${e.id}`);let t;if(e.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const i=new UA({id:e.id,model:this,parent:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[i.id]=i,i}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._meshes[e.id])return this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`),!1;if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!(e.buckets||e.indices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)){const t=(e.positions||e.positionsCompressed).length/3;e.indices=this._createDefaultIndices(t)}if(!e.buckets&&!e.indices&&"points"!==e.primitive)return e.indices=this._createDefaultIndices(numIndices),this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;const t=!(!this._dtxEnabled||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||e.textureSetId);if(e.origin=e.origin?c.addVec3(this._origin,e.origin,c.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){const t=e.scale||NA,i=e.position||QA,s=e.rotation||VA;c.eulerToQuaternion(s,"XYZ",HA),e.meshMatrix=c.composeMat4(i,HA,t,c.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Rr(e.positionsDecodeBoundary,c.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):GA,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=c.vec3(),i=[];z(e.positions,i,t)&&(e.positions=i,e.origin=c.addVec3(e.origin,t,t))}if(e.positions){const t=c.collapseAABB3();e.positionsDecodeMatrix=c.mat4(),c.expandAABB3Points3(t,e.positions),e.positionsCompressed=Tr(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=c.collapseAABB3();c.expandAABB3Points3(t,e.positionsCompressed),Tt.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=c.collapseAABB3();for(let i=0,s=e.buckets.length;i>24&255,r=i>>16&255,o=i>>8&255,n=255&i;switch(e.pickColor=new Uint8Array([n,o,r,s]),e.solid="solid"===e.primitive,t.origin=c.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),this._meshes[e.id]=t,this._unusedMeshes[e.id]=t,this._meshList.push(t),t}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let i=0,s=e.buckets.length;i>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,i=e.origin,s=e.textureSetId||"-",r=e.geometryId,o=`${Math.round(i[0])}.${Math.round(i[1])}.${Math.round(i[2])}.${s}.${r}`;let n=this._vboInstancingLayers[o];if(n)return n;let a=e.textureSet;const l=e.geometry;for(;!n;)switch(l.primitive){case"triangles":case"surface":n=new No({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!1});break;case"solid":n=new No({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!0});break;case"lines":n=new Pn({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0});break;case"points":n=new _a({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0})}return this._vboInstancingLayers[o]=n,this.layerList.push(n),n}createEntity(e){if(void 0===e.id?e.id=c.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=c.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;this._visible&&!1!==e.visible&&(t|=K),this._pickable&&!1!==e.pickable&&(t|=J),this._culled&&!1!==e.culled&&(t|=X),this._clippable&&!1!==e.clippable&&(t|=Y),this._collidable&&!1!==e.collidable&&(t|=Z),this._edges&&!1!==e.edges&&(t|=te),this._xrayed&&!1!==e.xrayed&&(t|=q),this._highlighted&&!1!==e.highlighted&&(t|=$),this._selected&&!1!==e.selected&&(t|=ee),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let i=0,s=e.meshIds.length;ie.sortIdt.sortId?1:0));for(let e=0,t=this.layerList.length;e0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,i=this.layerList.length;t0){const t=`${this.id}-dummyEntityForUnusedMeshes`;this.warn(`Creating dummy SceneModelEntity "${t}" for unused SceneMeshes: [${e.join(",")}]`),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}_getActiveSectionPlanesForLayer(e){const t=this.renderFlags,i=this.scene._sectionPlanesState.sectionPlanes,s=i.length,r=e.layerIndex*s;if(s>0)for(let e=0;e0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}drawColorOpaque(e){const t=this.renderFlags;for(let i=0,s=t.visibleLayers.length;i65536?16:8)}else n=[{positionsCompressed:s,indices:r,edgeIndices:o}];return n}class KA extends D{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e{var r=e-i,o=t-s;return Math.sqrt(r*r+o*o)};class rh extends D{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._eventSubs={};var i=this.plugin.viewer.scene;this._originMarker=new ae(i,t.origin),this._targetMarker=new ae(i,t.target),this._originWorld=c.vec3(),this._targetWorld=c.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;const s=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,r=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},n=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,A=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new Ae(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._targetDot=new Ae(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthWire=new le(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisWire=new le(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisWire=new le(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisWire=new le(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthLabel=new he(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisLabel=new he(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisLabel=new he(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisLabel=new he(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._sectionPlanesDirty=!0,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,this._labelsVisible=!1,this._labelsOnWires=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.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=i.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=i.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=i.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=i.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=i.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=i.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=i.on("sectionPlaneUpdated",(()=>{this._sectionPlanesDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.labelsVisible=t.labelsVisible,this.labelsOnWires=t.labelsOnWires}_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._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(c.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._originWorld)||this._isSliced(this._targetWorld))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}const t=this._originMarker.viewPos[2],i=this._targetMarker.viewPos[2];if(t>-.3||i>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){c.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var s=this._pp,r=this._cp,o=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var n=o.top-t.top,a=o.left-t.left,l=e.canvas.boundary,A=l[2],h=l[3],u=0;const i=this.plugin.viewer.scene.metrics,f=i.scale,g=i.units,m=i.unitsInfo[g].abbrev;for(var d=0,p=s.length;de.offsetTop+(e.offsetParent&&e.offsetParent!==s.parentNode&&h(e.offsetParent)),u=e=>e.offsetLeft+(e.offsetParent&&e.offsetParent!==s.parentNode&&u(e.offsetParent)),d=c.vec2();this._onCameraControlHoverSnapOrSurface=i.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(e=>{const t=e.snappedCanvasPos||e.canvasPos;r=!0,o.set(e.worldPos),n.set(e.canvasPos),0===this._mouseState?(this._canvasToPagePos?(this._canvasToPagePos(s,t,d),this._markerDiv.style.left=d[0]-5+"px",this._markerDiv.style.top=d[1]-5+"px"):(this._markerDiv.style.left=u(s)+t[0]-5+"px",this._markerDiv.style.top=h(s)+t[1]-5+"px"),this._markerDiv.style.background="pink",e.snappedToVertex||e.snappedToEdge?(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos,this.pointerLens.snapped=!0),this._markerDiv.style.background="greenyellow",this._markerDiv.style.border="2px solid green"):(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.canvasPos,this.pointerLens.snapped=!1),this._markerDiv.style.background="pink",this._markerDiv.style.border="2px solid red"),A=e.entity):(this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px"),s.style.cursor="pointer",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=this._currentDistanceMeasurementInitState.wireVisible,this._currentDistanceMeasurement.axisVisible=this._currentDistanceMeasurementInitState.axisVisible&&this.distanceMeasurementsPlugin.defaultAxisVisible,this._currentDistanceMeasurement.xAxisVisible=this._currentDistanceMeasurementInitState.xAxisVisible&&this.distanceMeasurementsPlugin.defaultXAxisVisible,this._currentDistanceMeasurement.yAxisVisible=this._currentDistanceMeasurementInitState.yAxisVisible&&this.distanceMeasurementsPlugin.defaultYAxisVisible,this._currentDistanceMeasurement.zAxisVisible=this._currentDistanceMeasurementInitState.zAxisVisible&&this.distanceMeasurementsPlugin.defaultZAxisVisible,this._currentDistanceMeasurement.targetVisible=this._currentDistanceMeasurementInitState.targetVisible,this._currentDistanceMeasurement.target.worldPos=o.slice(),this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px")})),s.addEventListener("mousedown",this._onMouseDown=e=>{1===e.which&&(a=e.clientX,l=e.clientY)}),s.addEventListener("mouseup",this._onMouseUp=t=>{1===t.which&&(t.clientX>a+20||t.clientXl+20||t.clientY{this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos),r=!1,this._markerDiv.style.left="-100px",this._markerDiv.style.top="-100px",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.axisVisible=!1),s.style.cursor="default"})),this._active=!0}deactivate(){if(!this._active)return;this.fire("activated",!1),this.pointerLens&&(this.pointerLens.visible=!1),this._markerDiv&&this._destroyMarkerDiv(),this.reset();const e=this.scene.canvas.canvas;e.removeEventListener("mousedown",this._onMouseDown),e.removeEventListener("mouseup",this._onMouseUp);const t=this.distanceMeasurementsPlugin.viewer.cameraControl;t.off(this._onCameraControlHoverSnapOrSurface),t.off(this._onCameraControlHoverSnapOrSurfaceOff),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null),this._active=!1}reset(){this._active&&(this._destroyMarkerDiv(),this._initMarkerDiv(),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null))}destroy(){this.deactivate(),super.destroy()}}class ah{constructor(){}getMetaModel(e,t,i){_.loadJSON(e,(e=>{t(e)}),(function(e){i(e)}))}getGLTF(e,t,i){_.loadArraybuffer(e,(e=>{t(e)}),(function(e){i(e)}))}getGLB(e,t,i){_.loadArraybuffer(e,(e=>{t(e)}),(function(e){i(e)}))}getArrayBuffer(e,t,i,s){!function(e,t,i,s){var r=()=>{};i=i||r,s=s||r;const o=/^data:(.*?)(;base64)?,(.*)$/,n=t.match(o);if(n){const e=!!n[2];var a=n[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),t=new Uint8Array(e);for(var l=0;l{i(e)}),(function(e){s(e)}))}}class lh{constructor(e={}){this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=e.messages,this.locale=e.locale}set messages(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}loadMessages(e={}){for(let t in e)this._messages[t]=e[t];this.messages=this._messages}clearMessages(){this.messages={}}get locales(){return this._locales}set locale(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}get locale(){return this._locale}translate(e,t){const i=this._messages[this._locale];if(!i)return null;const s=Ah(e,i);return s?t?hh(s,t):s:null}translatePlurals(e,t,i){const s=this._messages[this._locale];if(!s)return null;let r=Ah(e,s);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=hh(r,[t]),i&&(r=hh(r,i)),r):null}fire(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);const s=this._eventSubs[e];if(s)for(const e in s)if(s.hasOwnProperty(e)){s[e].callback(t)}}on(t,i){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let s=this._eventSubs[t];s||(s={},this._eventSubs[t]=s);const r=this._eventSubIDMap.addItem();s[r]={callback:i},this._eventSubEvents[r]=t;const o=this._events[t];return void 0!==o&&i(o),r}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}function Ah(e,t){if(t[e])return t[e];const i=e.split(".");let s=t;for(let e=0,t=i.length;s&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,s=e+t;i<0&&(i=0),s>1&&(s=1);var r=this.getPoint(i),o=this.getPoint(s),n=c.subVec3(o,r,[]);return c.normalizeVec3(n,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,s=[],r=this.getPoint(0),o=0;for(s.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),o+=c.lenVec3(c.subVec3(t,r,[])),s.push(o),r=t;return this.cacheArcLengths=s,s}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var i,s=this._getLengths(),r=0,o=s.length;i=t||e*s[o-1];for(var n,a=0,l=o-1;a<=l;)if((n=s[r=Math.floor(a+(l-a)/2)]-i)<0)a=r+1;else{if(!(n>0)){l=r;break}l=r-1}if(s[r=l]===i)return r/(o-1);var A=s[r];return(r+(i-A)/(s[r+1]-A))/(o-1)}}class uh extends ch{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,s=Math.floor(i),r=i-s,o=t[0===s?s:s-1],n=t[s],a=t[s>t.length-2?t.length-1:s+1],l=t[s>t.length-3?t.length-1:s+2],A=c.vec3();return A[0]=c.catmullRomInterpolate(o[0],n[0],a[0],l[0],r),A[1]=c.catmullRomInterpolate(o[1],n[1],a[1],l[1],r),A[2]=c.catmullRomInterpolate(o[2],n[2],a[2],l[2],r),A}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const dh=c.vec3();const ph=c.vec3(),fh=c.vec3(),gh=c.vec3(),mh=c.vec3(),_h=c.vec3();class vh extends D{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=c.vec3(),this._eye1=c.vec3(),this._up1=c.vec3(),this._look2=c.vec3(),this._eye2=c.vec3(),this._up2=c.vec3(),this._orthoScale1=1,this._orthoScale2=1,this._flying=!1,this._flyEyeLookUp=!1,this._flyingEye=!1,this._flyingLook=!1,this._callback=null,this._callbackScope=null,this._time1=null,this._time2=null,this.easing=!1!==t.easing,this.duration=t.duration,this.fit=t.fit,this.fitFOV=t.fitFOV,this.trail=t.trail}flyTo(e,t,i){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=i;const s=this.scene.camera,r=!!e.projection&&e.projection!==s.projection;let o,n,a,l,A;if(this._eye1[0]=s.eye[0],this._eye1[1]=s.eye[1],this._eye1[2]=s.eye[2],this._look1[0]=s.look[0],this._look1[1]=s.look[1],this._look1[2]=s.look[2],this._up1[0]=s.up[0],this._up1[1]=s.up[1],this._up1[2]=s.up[2],this._orthoScale1=s.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)o=e.aabb;else if(6===e.length)o=e;else if(e.eye&&e.look||e.up)n=e.eye,a=e.look,l=e.up;else if(e.eye)n=e.eye;else if(e.look)a=e.look;else{let s=e;if((_.isNumeric(s)||_.isString(s))&&(A=s,s=this.scene.components[A],!s))return this.error("Component not found: "+_.inQuotes(A)),void(t&&(i?t.call(i):t()));r||(o=s.aabb||this.scene.aabb)}const h=e.poi;if(o){if(o[3]=1;e>1&&(e=1);const i=this.easing?vh._ease(e,0,1,1):e,s=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(c.subVec3(s.eye,s.look,_h),s.eye=c.lerpVec3(i,0,1,this._eye1,this._eye2,gh),s.look=c.subVec3(gh,_h,fh)):this._flyingLook&&(s.look=c.lerpVec3(i,0,1,this._look1,this._look2,fh),s.up=c.lerpVec3(i,0,1,this._up1,this._up2,mh)):this._flyingEyeLookUp&&(s.eye=c.lerpVec3(i,0,1,this._eye1,this._eye2,gh),s.look=c.lerpVec3(i,0,1,this._look1,this._look2,fh),s.up=c.lerpVec3(i,0,1,this._up1,this._up2,mh)),this._projection2){const t="ortho"===this._projection2?vh._easeOutExpo(e,0,1,1):vh._easeInCubic(e,0,1,1);s.customProjection.matrix=c.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else s.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return s.ortho.scale=this._orthoScale2,void this.stop();M.scheduleTask(this._update,this)}static _ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}static _easeInCubic(e,t,i,s){return i*(e/=s)*e*e+t}static _easeOutExpo(e,t,i,s){return i*(1-Math.pow(2,-10*e/s))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class bh extends D{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new vh(this),this._t=0,this.state=bh.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,i;const s=performance.now(),r=this._lastTime?.001*(s-this._lastTime):0;if(this._lastTime=s,0!==r)switch(this.state){case bh.SCRUBBING:return;case bh.PLAYING:if(this._t+=this._playingRate*r,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=bh.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case bh.PLAYING_TO:i=this._t+this._playingRate*r*this._playingDir,(this._playingDir<0&&i<=this._playingToT||this._playingDir>0&&i>=this._playingToT)&&(i=this._playingToT,this.state=bh.SCRUBBING,this.fire("stopped")),this._t=i,e.loadFrame(this._t)}}_ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=bh.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=bh.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const i=this._cameraPath;if(!i)return;const s=i.frames[e];s?(this.state=bh.SCRUBBING,this._cameraFlightAnimation.flyTo(s,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=bh.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=bh.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=bh.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}bh.STOPPED=0,bh.SCRUBBING=1,bh.PLAYING=2,bh.PLAYING_TO=3;const yh=c.vec3(),Bh=c.vec3();c.vec3();const xh=c.vec3([0,-1,0]),wh=c.vec4([0,0,0,1]);function Ph(e){if(!Ch(e.width)||!Ch(e.height)){const t=document.createElement("canvas");t.width=Mh(e.width),t.height=Mh(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Ch(e){return 0==(e&e-1)}function Mh(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Fh extends D{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const i=this.scene.canvas.gl;this._state=new et({texture:new _s({gl:i,target:i.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),p.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,i=this.scene.canvas.gl;this._images=[];let s=!1,r=0;for(let o=0;o{r(),t()})):(i.eye=this._eye,i.look=this._look,i.up=this._up,r(),i.projection=s.projection)}}const Ih=c.vec3();const Dh=c.vec3();class Sh{constructor(){this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}saveObjects(e,t){this.numObjects=0,this._mask=t?_.apply(t,{}):null;const i=e.objects,s=!t||t.visible,r=!t||t.edges,o=!t||t.xrayed,n=!t||t.highlighted,a=!t||t.selected,l=!t||t.clippable,A=!t||t.pickable,h=!t||t.colorize,c=!t||t.opacity;for(let e in i)if(i.hasOwnProperty(e)){const t=i[e],u=this.numObjects;if(s&&(this.objectsVisible[u]=t.visible),r&&(this.objectsEdges[u]=t.edges),o&&(this.objectsXrayed[u]=t.xrayed),n&&(this.objectsHighlighted[u]=t.highlighted),a&&(this.objectsSelected[u]=t.selected),l&&(this.objectsClippable[u]=t.clippable),A&&(this.objectsPickable[u]=t.pickable),h){const e=t.colorize;e?(this.objectsColorize[3*u+0]=e[0],this.objectsColorize[3*u+1]=e[1],this.objectsColorize[3*u+2]=e[2],this.objectsHasColorize[u]=!0):this.objectsHasColorize[u]=!1}c&&(this.objectsOpacity[u]=t.opacity),this.numObjects++}}restoreObjects(e){const t=this._mask,i=!t||t.visible,s=!t||t.edges,r=!t||t.xrayed,o=!t||t.highlighted,n=!t||t.selected,a=!t||t.clippable,l=!t||t.pickable,A=!t||t.colorize,h=!t||t.opacity;var c=0;const u=e.objects;for(let e in u)if(u.hasOwnProperty(e)){const t=u[e];i&&(t.visible=this.objectsVisible[c]),s&&(t.edges=this.objectsEdges[c]),r&&(t.xrayed=this.objectsXrayed[c]),o&&(t.highlighted=this.objectsHighlighted[c]),n&&(t.selected=this.objectsSelected[c]),a&&(t.clippable=this.objectsClippable[c]),l&&(t.pickable=this.objectsPickable[c]),A&&(this.objectsHasColorize[c]?(Dh[0]=this.objectsColorize[3*c+0],Dh[1]=this.objectsColorize[3*c+1],Dh[2]=this.objectsColorize[3*c+2],t.colorize=Dh):t.colorize=null),h&&(t.opacity=this.objectsOpacity[c]),c++}}}class Th extends D{constructor(e,t={}){super(e,t),this._skyboxMesh=new Wi(this,{geometry:new Ut(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],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]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new Vt(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new ws(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}const Rh=c.vec4(),Lh=c.vec4(),Uh=c.vec3(),kh=c.vec3(),Oh=c.vec3(),Nh=c.vec4(),Qh=c.vec4(),Vh=c.vec4();class Hh{constructor(e){this._scene=e}dollyToCanvasPos(e,t,i){let s=!1;const r=this._scene.camera;if(e){const t=c.subVec3(e,r.eye,Uh);s=c.lenVec3(t){this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=c.vec3();c.decomposeMat4(c.inverseMat4(this._scene.viewer.camera.viewMatrix,c.mat4()),t,c.vec4(),c.vec3());const i=c.distVec3(t,e);let s=Math.tan(Math.PI/500)*i*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(s/=this._scene.camera.ortho.scale/2),G(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Ms(this._scene,Ji({radius:s})),this._pivotSphere=new Wi(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){c.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,c.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const i=t.boundary,s=i[2],r=i[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*s/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*r/2);let o=t._lastBoundingClientRect;if(!o||t._canvasSizeChanged){const e=t.canvas;o=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(o.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(o.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(G(this.getPivotPos(),this._rtcCenter,this._rtcPos),c.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new Vt(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=c.lookAtMat4v(e.eye,e.look,e.worldUp);c.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const i=this.getPivotPos();this._cameraOffset[2]+=c.distVec3(e.eye,i),t=c.inverseMat4(t);const s=c.transformVec3(t,this._cameraOffset),r=c.vec3();if(c.subVec3(e.eye,i,r),c.addVec3(r,s),e.zUp){const e=r[1];r[1]=r[2],r[2]=e}this._radius=c.lenVec3(r),this._polar=Math.acos(r[1]/this._radius),this._azimuth=Math.atan2(r[0],r[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=c.normalizeVec3(c.subVec3(e.look,e.eye,jh)),i=c.cross3Vec3(t,e.worldUp,Gh);return c.sqLenVec3(i)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,i=Math.abs(c.distVec3(this._scene.center,t.eye)),s=t.project.transposedMatrix,r=s.subarray(8,12),o=s.subarray(12),n=[0,0,-1,1],a=c.dotVec4(n,r)/c.dotVec4(n,o),l=Wh;t.project.unproject(e,a,Kh,Xh,l);const A=c.normalizeVec3(c.subVec3(l,t.eye,jh)),h=c.addVec3(t.eye,c.mulVec3Scalar(A,i,Gh),zh);this.setPivotPos(h)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const i=this._scene.camera;var s=-e;const r=-t;1===i.worldUp[2]&&(s=-s),this._azimuth+=.01*-s,this._polar+=.01*r,this._polar=c.clamp(this._polar,.001,Math.PI-.001);const o=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===i.worldUp[2]){const e=o[1];o[1]=o[2],o[2]=e}const n=c.lenVec3(c.subVec3(i.look,i.eye,c.vec3())),a=this.getPivotPos();c.addVec3(o,a);let l=c.lookAtMat4v(o,a,i.worldUp);l=c.inverseMat4(l);const A=c.transformVec3(l,this._cameraOffset);l[12]-=A[0],l[13]-=A[1],l[14]-=A[2];const h=[l[8],l[9],l[10]];i.eye=[l[12],l[13],l[14]],c.subVec3(i.eye,c.mulVec3Scalar(h,n),i.look),i.up=[l[4],l[5],l[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class Yh{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=c.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;const e=`${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;if(this._lastHash===e)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;const t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&(e.snappedToEdge||e.snappedToVertex)?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const e=this.pickResult.canvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new Ce;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}const Zh=c.vec2();class qh{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController;let n,a,l,A=0,h=0,u=0,d=0,p=!1;const f=c.vec3();let g=!0;const m=this._scene.canvas.canvas,_=[];function v(e=!0){m.style.cursor="move",A=s.pointerCanvasPos[0],h=s.pointerCanvasPos[1],u=s.pointerCanvasPos[0],d=s.pointerCanvasPos[1],e&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(p=!0,f.set(o.pickResult.worldPos)):p=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(i.active&&i.pointerEnabled)switch(t.which){case 1:_[e.input.KEY_SHIFT]||i.planView?(n=!0,v()):(n=!0,v(!1));break;case 2:a=!0,v();break;case 3:l=!0,i.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(!n&&!a&&!l)return;const o=e.canvas.boundary,u=o[2],d=o[3],g=s.pointerCanvasPos[0],m=s.pointerCanvasPos[1],v=_[e.input.KEY_SHIFT]||i.planView||!i.panRightClick&&a||i.panRightClick&&l,b=document.pointerLockElement?t.movementX:g-A,y=document.pointerLockElement?t.movementY:m-h;if(v){const t=e.camera;if("perspective"===t.projection){const i=Math.abs(p?c.lenVec3(c.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(t.perspective.fov/2*Math.PI/180);r.panDeltaX+=1.5*b*i/d,r.panDeltaY+=1.5*y*i/d}else r.panDeltaX+=.5*t.ortho.scale*(b/d),r.panDeltaY+=.5*t.ortho.scale*(y/d)}else!n||a||l||i.planView||(i.firstPerson?(r.rotateDeltaY-=b/u*i.dragRotationRate/2,r.rotateDeltaX+=y/d*(i.dragRotationRate/4)):(r.rotateDeltaY-=b/u*(1.5*i.dragRotationRate),r.rotateDeltaX+=y/d*(1.5*i.dragRotationRate)));A=g,h=m}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{i.active&&i.pointerEnabled&&s.mouseover&&(g=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(i.active&&i.pointerEnabled)switch(e.which){case 1:case 2:case 3:n=!1,a=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(i.active&&i.pointerEnabled){if(3===e.which){!function(e,t){if(e){let i=e.target,s=0,r=0,o=0,n=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,o+=i.scrollLeft,n+=i.scrollTop,i=i.offsetParent;t[0]=e.pageX+o-s,t[1]=e.pageY+n-r}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Zh);const i=Zh[0],s=Zh[1];Math.abs(i-u)<3&&Math.abs(s-d)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Zh,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{i.active&&i.pointerEnabled});const b=1/60;let y=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!i.active||!i.pointerEnabled)return;const t=performance.now()/1e3;var o=null!==y?t-y:0;y=t,o>.05&&(o=.05),o{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(!s.mouseover)return;const n=r._isKeyDownForAction(r.AXIS_VIEW_RIGHT),a=r._isKeyDownForAction(r.AXIS_VIEW_BACK),l=r._isKeyDownForAction(r.AXIS_VIEW_LEFT),A=r._isKeyDownForAction(r.AXIS_VIEW_FRONT),h=r._isKeyDownForAction(r.AXIS_VIEW_TOP),u=r._isKeyDownForAction(r.AXIS_VIEW_BOTTOM);if(!(n||a||l||A||h||u))return;const d=e.aabb,p=c.getAABB3Diag(d);c.getAABB3Center(d,$h);const f=Math.abs(p/Math.tan(t.cameraFlight.fitFOV*c.DEGTORAD)),g=1.1*p;rc.orthoScale=g,n?(rc.eye.set(c.addVec3($h,c.mulVec3Scalar(o.worldRight,f,ec),sc)),rc.look.set($h),rc.up.set(o.worldUp)):a?(rc.eye.set(c.addVec3($h,c.mulVec3Scalar(o.worldForward,f,ec),sc)),rc.look.set($h),rc.up.set(o.worldUp)):l?(rc.eye.set(c.addVec3($h,c.mulVec3Scalar(o.worldRight,-f,ec),sc)),rc.look.set($h),rc.up.set(o.worldUp)):A?(rc.eye.set(c.addVec3($h,c.mulVec3Scalar(o.worldForward,-f,ec),sc)),rc.look.set($h),rc.up.set(o.worldUp)):h?(rc.eye.set(c.addVec3($h,c.mulVec3Scalar(o.worldUp,f,ec),sc)),rc.look.set($h),rc.up.set(c.normalizeVec3(c.mulVec3Scalar(o.worldForward,1,tc),ic))):u&&(rc.eye.set(c.addVec3($h,c.mulVec3Scalar(o.worldUp,-f,ec),sc)),rc.look.set($h),rc.up.set(c.normalizeVec3(c.mulVec3Scalar(o.worldForward,-1,tc)))),!i.firstPerson&&i.followPointer&&t.pivotController.setPivotPos($h),t.cameraFlight.duration>0?t.cameraFlight.flyTo(rc,(()=>{t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(rc),t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class nc{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,A=!1;const h=this._scene.canvas.canvas,u=i=>{let s;i&&i.worldPos&&(s=i.worldPos);const r=i&&i.entity?i.entity.aabb:e.aabb;if(s){const i=e.camera;c.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})},d=e.tickify(this._canvasMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(l||A)return;const r=a.hasSubs("hover"),n=a.hasSubs("hoverEnter"),h=a.hasSubs("hoverOut"),c=a.hasSubs("hoverOff"),u=a.hasSubs("hoverSurface"),d=a.hasSubs("hoverSnapOrSurface");if(r||n||h||c||u||d)if(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=u,o.scheduleSnapOrPick=d,o.update(),o.pickResult){if(o.pickResult.entity){const t=o.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),a.fire("hoverEnter",o.pickResult,!0),this._lastPickedEntityId=t)}a.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&a.fire("hoverSurface",o.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),a.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)});h.addEventListener("mousemove",d),h.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(A=!0);if(1===t.which&&i.active&&i.pointerEnabled&&(s.mouseDownClientX=t.clientX,s.mouseDownClientY=t.clientY,s.mouseDownCursorX=s.pointerCanvasPos[0],s.mouseDownCursorY=s.pointerCanvasPos[1],!i.firstPerson&&i.followPointer&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===t.which))){const t=o.pickResult;t&&t.worldPos?(n.setPivotPos(t.worldPos),n.startPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),n.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(A=!1),n.getPivoting()&&n.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=r=>{if(!i.active||!i.pointerEnabled)return;if(!(1===r.which))return;if(n.hidePivot(),Math.abs(r.clientX-s.mouseDownClientX)>3||Math.abs(r.clientY-s.mouseDownClientY)>3)return;const l=a.hasSubs("picked"),A=a.hasSubs("pickedNothing"),h=a.hasSubs("pickedSurface"),d=a.hasSubs("doublePicked"),p=a.hasSubs("doublePickedSurface"),f=a.hasSubs("doublePickedNothing");if(!(i.doublePickFlyTo||d||p||f))return(l||A||h)&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=h,o.update(),o.pickResult?(a.fire("picked",o.pickResult,!0),o.pickedSurface&&a.fire("pickedSurface",o.pickResult,!0)):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo,o.schedulePickSurface=h,o.update();const e=o.pickResult,r=o.pickedSurface;this._timeout=setTimeout((()=>{e?(a.fire("picked",e,!0),r&&(a.fire("pickedSurface",e,!0),!i.firstPerson&&i.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0),this._clicks=0}),i.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo||d||p,o.schedulePickSurface=o.schedulePickEntity&&p,o.update(),o.pickResult){if(a.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&a.fire("doublePickedSurface",o.pickResult,!0),i.doublePickFlyTo&&(u(o.pickResult),!i.firstPerson&&i.followPointer)){const e=o.pickResult.entity.aabb,i=c.getAABB3Center(e);t.pivotController.setPivotPos(i),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(a.fire("doublePickedNothing",{canvasPos:s.pointerCanvasPos},!0),i.doublePickFlyTo&&(u(),!i.firstPerson&&i.followPointer)){const i=e.aabb,s=c.getAABB3Center(i);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class ac{constructor(e,t,i,s,r){this._scene=e;const o=e.input,n=[],a=e.canvas.canvas;let l=!0;this._onSceneMouseMove=o.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=o.on("keydown",(t=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&s.mouseover&&(n[t]=!0,t===o.KEY_SHIFT&&(a.style.cursor="move"))})),this._onSceneKeyUp=o.on("keyup",(s=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&(n[s]=!1,s===o.KEY_SHIFT&&(a.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(a=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(!s.mouseover)return;const A=t.cameraControl,h=a.deltaTime/1e3;if(!i.planView){const e=A._isKeyDownForAction(A.ROTATE_Y_POS,n),s=A._isKeyDownForAction(A.ROTATE_Y_NEG,n),o=A._isKeyDownForAction(A.ROTATE_X_POS,n),a=A._isKeyDownForAction(A.ROTATE_X_NEG,n),l=h*i.keyboardRotationRate;(e||s||o||a)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),e?r.rotateDeltaY+=l:s&&(r.rotateDeltaY-=l),o?r.rotateDeltaX+=l:a&&(r.rotateDeltaX-=l),!i.firstPerson&&i.followPointer&&t.pivotController.startPivot())}if(!n[o.KEY_CTRL]&&!n[o.KEY_ALT]){const e=A._isKeyDownForAction(A.DOLLY_BACKWARDS,n),o=A._isKeyDownForAction(A.DOLLY_FORWARDS,n);if(e||o){const n=h*i.keyboardDollyRate;!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),o?r.dollyDelta-=n:e&&(r.dollyDelta+=n),l&&(s.followPointerDirty=!0,l=!1)}}const c=A._isKeyDownForAction(A.PAN_FORWARDS,n),u=A._isKeyDownForAction(A.PAN_BACKWARDS,n),d=A._isKeyDownForAction(A.PAN_LEFT,n),p=A._isKeyDownForAction(A.PAN_RIGHT,n),f=A._isKeyDownForAction(A.PAN_UP,n),g=A._isKeyDownForAction(A.PAN_DOWN,n),m=(n[o.KEY_ALT]?.3:1)*h*i.keyboardPanRate;(c||u||d||p||f||g)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),g?r.panDeltaY+=m:f&&(r.panDeltaY+=-m),p?r.panDeltaX+=-m:d&&(r.panDeltaX+=m),u?r.panDeltaZ+=m:c&&(r.panDeltaZ+=-m))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const lc=c.vec3();class Ac{constructor(e,t,i,s,r){this._scene=e;const o=e.camera,n=t.pickController,a=t.pivotController,l=t.panController;let A=1,h=1,u=null;this._onTick=e.on("tick",(()=>{if(!i.active||!i.pointerEnabled)return;let t="default";if(Math.abs(r.dollyDelta)<.001&&(r.dollyDelta=0),Math.abs(r.rotateDeltaX)<.001&&(r.rotateDeltaX=0),Math.abs(r.rotateDeltaY)<.001&&(r.rotateDeltaY=0),0===r.rotateDeltaX&&0===r.rotateDeltaY||(r.dollyDelta=0),i.followPointer){if(--A<=0&&(A=1,0!==r.dollyDelta)){if(0===r.rotateDeltaY&&0===r.rotateDeltaX&&i.followPointer&&s.followPointerDirty&&(n.pickCursorPos=s.pointerCanvasPos,n.schedulePickSurface=!0,n.update(),n.pickResult&&n.pickResult.worldPos?u=n.pickResult.worldPos:(h=1,u=null),s.followPointerDirty=!1),u){const t=Math.abs(c.lenVec3(c.subVec3(u,e.camera.eye,lc)));h=t/i.dollyProximityThreshold}h{s.mouseover=!0}),o.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{s.mouseover=!1,o.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{cc(e,o,s.pointerCanvasPos)}),o.addEventListener("mousedown",this._mouseDownHandler=e=>{i.active&&i.pointerEnabled&&(cc(e,o,s.pointerCanvasPos),s.mouseover=!0)}),o.addEventListener("mouseup",this._mouseUpHandler=e=>{i.active&&i.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function cc(e,t,i){if(e){const{left:s,top:r}=t.getBoundingClientRect();i[0]=e.clientX-s-window.scrollX,i[1]=e.clientY-r-window.scrollY}else e=window.event,i[0]=e.x,i[1]=e.y;return i}const uc=function(e,t){if(e){let i=e.target,s=0,r=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;t[0]=e.pageX-s,t[1]=e.pageY-r}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class dc{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=c.vec2(),l=c.vec2(),A=c.vec2(),h=c.vec2(),u=[],d=this._scene.canvas.canvas;let p=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),d.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!i.active||!i.pointerEnabled)return;t.preventDefault();const r=t.touches,l=t.changedTouches;for(s.touchStartTime=Date.now(),1===r.length&&1===l.length&&(uc(r[0],a),i.followPointer&&(o.pickCursorPos=a,o.schedulePickSurface=!0,o.update(),i.planView||(o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(n.setPivotPos(o.pickResult.worldPos),!i.firstPerson&&n.startPivot()&&n.showPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),!i.firstPerson&&n.startPivot()&&n.showPivot()))));u.length{n.getPivoting()&&n.endPivot()}),d.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const n=e.canvas.boundary,a=n[2],d=n[3],g=t.touches;if(t.touches.length===p){if(1===p){uc(g[0],l),c.subVec2(l,u[0],h);const t=h[0],o=h[1];if(null!==s.longTouchTimeout&&(Math.abs(t)>i.longTapRadius||Math.abs(o)>i.longTapRadius)&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),i.planView){const s=e.camera;if("perspective"===s.projection){const n=Math.abs(e.camera.eyeLookDist)*Math.tan(s.perspective.fov/2*Math.PI/180);r.panDeltaX+=t*n/d*i.touchPanRate,r.panDeltaY+=o*n/d*i.touchPanRate}else r.panDeltaX+=.5*s.ortho.scale*(t/d)*i.touchPanRate,r.panDeltaY+=.5*s.ortho.scale*(o/d)*i.touchPanRate}else r.rotateDeltaY-=t/a*(1*i.dragRotationRate),r.rotateDeltaX+=o/d*(1.5*i.dragRotationRate)}else if(2===p){const t=g[0],n=g[1];uc(t,l),uc(n,A);const a=c.geometricMeanVec2(u[0],u[1]),h=c.geometricMeanVec2(l,A),p=c.vec2();c.subVec2(a,h,p);const f=p[0],m=p[1],_=e.camera,v=c.distVec2([t.pageX,t.pageY],[n.pageX,n.pageY]),b=(c.distVec2(u[0],u[1])-v)*i.touchDollyRate;if(r.dollyDelta=b,Math.abs(b)<1)if("perspective"===_.projection){const t=o.pickResult?o.pickResult.worldPos:e.center,s=Math.abs(c.lenVec3(c.subVec3(t,e.camera.eye,[])))*Math.tan(_.perspective.fov/2*Math.PI/180);r.panDeltaX-=f*s/d*i.touchPanRate,r.panDeltaY-=m*s/d*i.touchPanRate}else r.panDeltaX-=.5*_.ortho.scale*(f/d)*i.touchPanRate,r.panDeltaY-=.5*_.ortho.scale*(m/d)*i.touchPanRate;s.pointerCanvasPos=h}for(let e=0;e{let s;i&&i.worldPos&&(s=i.worldPos);const r=i?i.entity.aabb:e.aabb;if(s){const i=e.camera;c.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})};d.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!i.active||!i.pointerEnabled)return;null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null);const r=e.touches,o=e.changedTouches;if(a=Date.now(),1===r.length&&1===o.length){h=a,pc(r[0],A);const o=A[0],n=A[1],l=r[0].pageX,c=r[0].pageY;s.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(c)],canvasPos:[Math.round(o),Math.round(n)],event:e},!0),s.longTouchTimeout=null}),i.longTapTimeout)}else h=-1;for(;l.length{if(!i.active||!i.pointerEnabled)return;const t=Date.now(),r=e.touches,a=e.changedTouches,d=n.hasSubs("pickedSurface");null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),0===r.length&&1===a.length&&h>-1&&t-h<150&&(u>-1&&h-u<325?(pc(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=d,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("doublePicked",o.pickResult),o.pickedSurface&&n.fire("doublePickedSurface",o.pickResult),i.doublePickFlyTo&&p(o.pickResult)):(n.fire("doublePickedNothing"),i.doublePickFlyTo&&p()),u=-1):c.distVec2(l[0],A)<4&&(pc(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=d,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("picked",o.pickResult),o.pickedSurface&&n.fire("pickedSurface",o.pickResult)):n.fire("pickedNothing"),u=t),h=-1),l.length=r.length;for(let e=0,t=r.length;e{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:c.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:c.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const i=this.scene;this._controllers={cameraControl:this,pickController:new Yh(this,this._configs),pivotController:new Jh(i,this._configs),panController:new Hh(i),cameraFlight:new vh(this,{duration:.5})},this._handlers=[new hc(this.scene,this._controllers,this._configs,this._states,this._updates),new dc(this.scene,this._controllers,this._configs,this._states,this._updates),new qh(this.scene,this._controllers,this._configs,this._states,this._updates),new oc(this.scene,this._controllers,this._configs,this._states,this._updates),new nc(this.scene,this._controllers,this._configs,this._states,this._updates),new fc(this.scene,this._controllers,this._configs,this._states,this._updates),new ac(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new Ac(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",_.isString(e)){const t=this.scene.input,i={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":i[this.PAN_LEFT]=[t.KEY_A],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_Z],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":i[this.PAN_LEFT]=[t.KEY_Q],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_W],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=i}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const i=this._keyMap[e];if(!i)return!1;t||(t=this.scene.input.keyDown);for(let e=0,s=i.length;e0?Bc(t):null,n=i&&i.length>0?Bc(i):null,a=e=>{if(!e)return;var t=!0;(n&&n[e.type]||o&&!o[e.type])&&(t=!1),t&&s.push(e.id);const i=e.children;if(i)for(var r=0,l=i.length;r>t;i.sort(PA);const s=new Int32Array(e.length);for(let t=0,r=i.length;te[t+1]){let i=e[t];e[t]=e[t+1],e[t+1]=i}CA=new Int32Array(e),t.sort(MA);const i=new Int32Array(e.length);for(let s=0,r=t.length;st){let i=e;e=t,t=i}function i(i,s){return i!==e?e-i:s!==t?t-s:0}let s=0,r=(o.length>>1)-1;for(;s<=r;){const e=r+s>>1,t=i(o[2*e],o[2*e+1]);if(t>0)s=e+1;else{if(!(t<0))return e;r=e-1}}return-s-1}const a=new Int32Array(o.length/2);a.fill(0);const l=s.length/3;if(l>8*(1<u.maxNumPositions&&(u=c()),u.bucketNumber>8)return[e];let p;-1===A[l]&&(A[l]=u.numPositions++,u.positionsCompressed.push(s[3*l]),u.positionsCompressed.push(s[3*l+1]),u.positionsCompressed.push(s[3*l+2])),-1===A[h]&&(A[h]=u.numPositions++,u.positionsCompressed.push(s[3*h]),u.positionsCompressed.push(s[3*h+1]),u.positionsCompressed.push(s[3*h+2])),-1===A[d]&&(A[d]=u.numPositions++,u.positionsCompressed.push(s[3*d]),u.positionsCompressed.push(s[3*d+1]),u.positionsCompressed.push(s[3*d+2])),u.indices.push(A[l]),u.indices.push(A[h]),u.indices.push(A[d]),(p=n(l,h))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(l,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(h,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]]))}const d=t/8*2,p=t/8,f=2*s.length+(r.length+o.length)*d;let g=0,m=-s.length/3;return h.forEach((e=>{g+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*p,m+=e.positionsCompressed.length/3})),g>f?[e]:(i&&function(e,t){const i={},s={};let r=0;e.forEach((e=>{const t=e.indices,o=e.edgeIndices,n=e.positionsCompressed;for(let e=0,s=t.length;e0){const e=t._meshes;for(let t=0,i=e.length;t0){const e=this._meshes;for(let t=0,i=e.length;t{this._viewMatrixDirty=!0})),this._meshesWithDirtyMatrices=[],this._numMeshesWithDirtyMatrices=0,this._onTick=this.scene.on("tick",(()=>{for(;this._numMeshesWithDirtyMatrices>0;)this._meshesWithDirtyMatrices[--this._numMeshesWithDirtyMatrices]._updateMatrix()})),this._createDefaultTextureSet(),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.backfaces=t.backfaces}_meshMatrixDirty(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}_createDefaultTextureSet(){const e=new lA({id:"defaultColorTexture",texture:new _s({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new lA({id:"defaultMetalRoughTexture",texture:new _s({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),i=new lA({id:"defaultNormalsTexture",texture:new _s({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),s=new lA({id:"defaultEmissiveTexture",texture:new _s({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),r=new lA({id:"defaultOcclusionTexture",texture:new _s({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=i,this._textures.defaultEmissiveTexture=s,this._textures.defaultOcclusionTexture=r,this._textureSets.defaultTextureSet=new aA({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:i,emissiveTexture:s,occlusionTexture:r})}get isPerformanceModel(){return!0}get transforms(){return this._transforms}get textures(){return this._textures}get textureSets(){return this._textureSets}get meshes(){return this._meshes}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),c.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),c.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||jA),c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),c.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),c.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),c.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),c.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0,this._aabbDirty=!0}_transformDirty(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}_sceneModelDirty(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(let e=0,t=this._entityList.length;e0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,i=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,i=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,i=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,i=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,i=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,i=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,i=new Uint8Array(t.length);for(let e=0,s=t.length;e{l.setImage(A,{minFilter:i,magFilter:s,wrapS:r,wrapT:o,wrapR:n,flipY:e.flipY,encoding:a}),this.glRedraw()},A.src=e.src;break;default:this._textureTranscoder?_.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new lA({id:t,texture:l})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let i,s,r,o,n;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(i=this._textures[e.colorTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(s=this._textures[e.metallicRoughnessTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(r=this._textures[e.normalsTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(o=this._textures[e.emissiveTextureId],!o)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else o=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(n=this._textures[e.occlusionTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultOcclusionTexture;const a=new aA({id:t,model:this,colorTexture:i,metallicRoughnessTexture:s,normalsTexture:r,emissiveTexture:o,occlusionTexture:n});return this._textureSets[t]=a,a}createTransform(e){if(void 0===e.id||null===e.id)return void this.error("[createTransform] SceneModel.createTransform() config missing: id");if(this._transforms[e.id])return void this.error(`[createTransform] SceneModel already has a transform with this ID: ${e.id}`);let t;if(e.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const i=new UA({id:e.id,model:this,parent:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[i.id]=i,i}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._meshes[e.id])return this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`),!1;if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!(e.buckets||e.indices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)){const t=(e.positions||e.positionsCompressed).length/3;e.indices=this._createDefaultIndices(t)}if(!e.buckets&&!e.indices&&"points"!==e.primitive)return e.indices=this._createDefaultIndices(numIndices),this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;const t=!(!this._dtxEnabled||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||e.textureSetId);if(e.origin=e.origin?c.addVec3(this._origin,e.origin,c.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){const t=e.scale||NA,i=e.position||QA,s=e.rotation||VA;c.eulerToQuaternion(s,"XYZ",HA),e.meshMatrix=c.composeMat4(i,HA,t,c.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Rr(e.positionsDecodeBoundary,c.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):GA,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=c.vec3(),i=[];z(e.positions,i,t)&&(e.positions=i,e.origin=c.addVec3(e.origin,t,t))}if(e.positions){const t=c.collapseAABB3();e.positionsDecodeMatrix=c.mat4(),c.expandAABB3Points3(t,e.positions),e.positionsCompressed=Tr(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=c.collapseAABB3();c.expandAABB3Points3(t,e.positionsCompressed),Tt.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=c.collapseAABB3();for(let i=0,s=e.buckets.length;i>24&255,r=i>>16&255,o=i>>8&255,n=255&i;switch(e.pickColor=new Uint8Array([n,o,r,s]),e.solid="solid"===e.primitive,t.origin=c.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),this._meshes[e.id]=t,this._unusedMeshes[e.id]=t,this._meshList.push(t),t}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let i=0,s=e.buckets.length;i>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,i=e.origin,s=e.textureSetId||"-",r=e.geometryId,o=`${Math.round(i[0])}.${Math.round(i[1])}.${Math.round(i[2])}.${s}.${r}`;let n=this._vboInstancingLayers[o];if(n)return n;let a=e.textureSet;const l=e.geometry;for(;!n;)switch(l.primitive){case"triangles":case"surface":n=new No({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!1});break;case"solid":n=new No({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!0});break;case"lines":n=new Pn({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0});break;case"points":n=new _a({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0})}return this._vboInstancingLayers[o]=n,this.layerList.push(n),n}createEntity(e){if(void 0===e.id?e.id=c.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=c.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;this._visible&&!1!==e.visible&&(t|=K),this._pickable&&!1!==e.pickable&&(t|=J),this._culled&&!1!==e.culled&&(t|=X),this._clippable&&!1!==e.clippable&&(t|=Y),this._collidable&&!1!==e.collidable&&(t|=Z),this._edges&&!1!==e.edges&&(t|=te),this._xrayed&&!1!==e.xrayed&&(t|=q),this._highlighted&&!1!==e.highlighted&&(t|=$),this._selected&&!1!==e.selected&&(t|=ee),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let i=0,s=e.meshIds.length;ie.sortIdt.sortId?1:0));for(let e=0,t=this.layerList.length;e0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,i=this.layerList.length;t0){const t=`${this.id}-dummyEntityForUnusedMeshes`;this.warn(`Creating dummy SceneModelEntity "${t}" for unused SceneMeshes: [${e.join(",")}]`),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}_getActiveSectionPlanesForLayer(e){const t=this.renderFlags,i=this.scene._sectionPlanesState.sectionPlanes,s=i.length,r=e.layerIndex*s;if(s>0)for(let e=0;e0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}drawColorOpaque(e){const t=this.renderFlags;for(let i=0,s=t.visibleLayers.length;i65536?16:8)}else n=[{positionsCompressed:s,indices:r,edgeIndices:o}];return n}class KA extends D{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e{var r=e-i,o=t-s;return Math.sqrt(r*r+o*o)};class rh extends D{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._eventSubs={};var i=this.plugin.viewer.scene;this._originMarker=new ae(i,t.origin),this._targetMarker=new ae(i,t.target),this._originWorld=c.vec3(),this._targetWorld=c.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;const s=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,r=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},n=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,A=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new Ae(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._targetDot=new Ae(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthWire=new le(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisWire=new le(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisWire=new le(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisWire=new le(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthLabel=new he(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisLabel=new he(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisLabel=new he(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisLabel=new he(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._sectionPlanesDirty=!0,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,this._labelsVisible=!1,this._labelsOnWires=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.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=i.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=i.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=i.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=i.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=i.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=i.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=i.on("sectionPlaneUpdated",(()=>{this._sectionPlanesDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.labelsVisible=t.labelsVisible,this.labelsOnWires=t.labelsOnWires}_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._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(c.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._originWorld)||this._isSliced(this._targetWorld))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}const t=this._originMarker.viewPos[2],i=this._targetMarker.viewPos[2];if(t>-.3||i>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){c.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var s=this._pp,r=this._cp,o=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var n=o.top-t.top,a=o.left-t.left,l=e.canvas.boundary,A=l[2],h=l[3],u=0;const i=this.plugin.viewer.scene.metrics,f=i.scale,g=i.units,m=i.unitsInfo[g].abbrev;for(var d=0,p=s.length;de.offsetTop+(e.offsetParent&&e.offsetParent!==s.parentNode&&h(e.offsetParent)),u=e=>e.offsetLeft+(e.offsetParent&&e.offsetParent!==s.parentNode&&u(e.offsetParent)),d=c.vec2();this._onCameraControlHoverSnapOrSurface=i.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(e=>{const t=e.snappedCanvasPos||e.canvasPos;r=!0,o.set(e.worldPos),n.set(e.canvasPos),0===this._mouseState?(this._canvasToPagePos?(this._canvasToPagePos(s,t,d),this._markerDiv.style.left=d[0]-5+"px",this._markerDiv.style.top=d[1]-5+"px"):(this._markerDiv.style.left=u(s)+t[0]-5+"px",this._markerDiv.style.top=h(s)+t[1]-5+"px"),this._markerDiv.style.background="pink",e.snappedToVertex||e.snappedToEdge?(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos,this.pointerLens.snapped=!0),this._markerDiv.style.background="greenyellow",this._markerDiv.style.border="2px solid green"):(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.canvasPos,this.pointerLens.snapped=!1),this._markerDiv.style.background="pink",this._markerDiv.style.border="2px solid red"),A=e.entity):(this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px"),s.style.cursor="pointer",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=this._currentDistanceMeasurementInitState.wireVisible,this._currentDistanceMeasurement.axisVisible=this._currentDistanceMeasurementInitState.axisVisible&&this.distanceMeasurementsPlugin.defaultAxisVisible,this._currentDistanceMeasurement.xAxisVisible=this._currentDistanceMeasurementInitState.xAxisVisible&&this.distanceMeasurementsPlugin.defaultXAxisVisible,this._currentDistanceMeasurement.yAxisVisible=this._currentDistanceMeasurementInitState.yAxisVisible&&this.distanceMeasurementsPlugin.defaultYAxisVisible,this._currentDistanceMeasurement.zAxisVisible=this._currentDistanceMeasurementInitState.zAxisVisible&&this.distanceMeasurementsPlugin.defaultZAxisVisible,this._currentDistanceMeasurement.targetVisible=this._currentDistanceMeasurementInitState.targetVisible,this._currentDistanceMeasurement.target.worldPos=o.slice(),this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px")})),s.addEventListener("mousedown",this._onMouseDown=e=>{1===e.which&&(a=e.clientX,l=e.clientY)}),s.addEventListener("mouseup",this._onMouseUp=t=>{1===t.which&&(t.clientX>a+20||t.clientXl+20||t.clientY{this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos),r=!1,this._markerDiv.style.left="-100px",this._markerDiv.style.top="-100px",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.axisVisible=!1),s.style.cursor="default"})),this._active=!0}deactivate(){if(!this._active)return;this.fire("activated",!1),this.pointerLens&&(this.pointerLens.visible=!1),this._markerDiv&&this._destroyMarkerDiv(),this.reset();const e=this.scene.canvas.canvas;e.removeEventListener("mousedown",this._onMouseDown),e.removeEventListener("mouseup",this._onMouseUp);const t=this.distanceMeasurementsPlugin.viewer.cameraControl;t.off(this._onCameraControlHoverSnapOrSurface),t.off(this._onCameraControlHoverSnapOrSurfaceOff),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null),this._active=!1}reset(){this._active&&(this._destroyMarkerDiv(),this._initMarkerDiv(),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null))}destroy(){this.deactivate(),super.destroy()}}class ah{constructor(){}getMetaModel(e,t,i){_.loadJSON(e,(e=>{t(e)}),(function(e){i(e)}))}getGLTF(e,t,i){_.loadArraybuffer(e,(e=>{t(e)}),(function(e){i(e)}))}getGLB(e,t,i){_.loadArraybuffer(e,(e=>{t(e)}),(function(e){i(e)}))}getArrayBuffer(e,t,i,s){!function(e,t,i,s){var r=()=>{};i=i||r,s=s||r;const o=/^data:(.*?)(;base64)?,(.*)$/,n=t.match(o);if(n){const e=!!n[2];var a=n[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),t=new Uint8Array(e);for(var l=0;l{i(e)}),(function(e){s(e)}))}}class lh{constructor(e={}){this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=e.messages,this.locale=e.locale}set messages(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}loadMessages(e={}){for(let t in e)this._messages[t]=e[t];this.messages=this._messages}clearMessages(){this.messages={}}get locales(){return this._locales}set locale(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}get locale(){return this._locale}translate(e,t){const i=this._messages[this._locale];if(!i)return null;const s=Ah(e,i);return s?t?hh(s,t):s:null}translatePlurals(e,t,i){const s=this._messages[this._locale];if(!s)return null;let r=Ah(e,s);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=hh(r,[t]),i&&(r=hh(r,i)),r):null}fire(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);const s=this._eventSubs[e];if(s)for(const e in s)if(s.hasOwnProperty(e)){s[e].callback(t)}}on(t,i){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let s=this._eventSubs[t];s||(s={},this._eventSubs[t]=s);const r=this._eventSubIDMap.addItem();s[r]={callback:i},this._eventSubEvents[r]=t;const o=this._events[t];return void 0!==o&&i(o),r}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}function Ah(e,t){if(t[e])return t[e];const i=e.split(".");let s=t;for(let e=0,t=i.length;s&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,s=e+t;i<0&&(i=0),s>1&&(s=1);var r=this.getPoint(i),o=this.getPoint(s),n=c.subVec3(o,r,[]);return c.normalizeVec3(n,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,s=[],r=this.getPoint(0),o=0;for(s.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),o+=c.lenVec3(c.subVec3(t,r,[])),s.push(o),r=t;return this.cacheArcLengths=s,s}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var i,s=this._getLengths(),r=0,o=s.length;i=t||e*s[o-1];for(var n,a=0,l=o-1;a<=l;)if((n=s[r=Math.floor(a+(l-a)/2)]-i)<0)a=r+1;else{if(!(n>0)){l=r;break}l=r-1}if(s[r=l]===i)return r/(o-1);var A=s[r];return(r+(i-A)/(s[r+1]-A))/(o-1)}}class uh extends ch{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,s=Math.floor(i),r=i-s,o=t[0===s?s:s-1],n=t[s],a=t[s>t.length-2?t.length-1:s+1],l=t[s>t.length-3?t.length-1:s+2],A=c.vec3();return A[0]=c.catmullRomInterpolate(o[0],n[0],a[0],l[0],r),A[1]=c.catmullRomInterpolate(o[1],n[1],a[1],l[1],r),A[2]=c.catmullRomInterpolate(o[2],n[2],a[2],l[2],r),A}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const dh=c.vec3();const ph=c.vec3(),fh=c.vec3(),gh=c.vec3(),mh=c.vec3(),_h=c.vec3();class vh extends D{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=c.vec3(),this._eye1=c.vec3(),this._up1=c.vec3(),this._look2=c.vec3(),this._eye2=c.vec3(),this._up2=c.vec3(),this._orthoScale1=1,this._orthoScale2=1,this._flying=!1,this._flyEyeLookUp=!1,this._flyingEye=!1,this._flyingLook=!1,this._callback=null,this._callbackScope=null,this._time1=null,this._time2=null,this.easing=!1!==t.easing,this.duration=t.duration,this.fit=t.fit,this.fitFOV=t.fitFOV,this.trail=t.trail}flyTo(e,t,i){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=i;const s=this.scene.camera,r=!!e.projection&&e.projection!==s.projection;let o,n,a,l,A;if(this._eye1[0]=s.eye[0],this._eye1[1]=s.eye[1],this._eye1[2]=s.eye[2],this._look1[0]=s.look[0],this._look1[1]=s.look[1],this._look1[2]=s.look[2],this._up1[0]=s.up[0],this._up1[1]=s.up[1],this._up1[2]=s.up[2],this._orthoScale1=s.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)o=e.aabb;else if(6===e.length)o=e;else if(e.eye&&e.look||e.up)n=e.eye,a=e.look,l=e.up;else if(e.eye)n=e.eye;else if(e.look)a=e.look;else{let s=e;if((_.isNumeric(s)||_.isString(s))&&(A=s,s=this.scene.components[A],!s))return this.error("Component not found: "+_.inQuotes(A)),void(t&&(i?t.call(i):t()));r||(o=s.aabb||this.scene.aabb)}const h=e.poi;if(o){if(o[3]=1;e>1&&(e=1);const i=this.easing?vh._ease(e,0,1,1):e,s=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(c.subVec3(s.eye,s.look,_h),s.eye=c.lerpVec3(i,0,1,this._eye1,this._eye2,gh),s.look=c.subVec3(gh,_h,fh)):this._flyingLook&&(s.look=c.lerpVec3(i,0,1,this._look1,this._look2,fh),s.up=c.lerpVec3(i,0,1,this._up1,this._up2,mh)):this._flyingEyeLookUp&&(s.eye=c.lerpVec3(i,0,1,this._eye1,this._eye2,gh),s.look=c.lerpVec3(i,0,1,this._look1,this._look2,fh),s.up=c.lerpVec3(i,0,1,this._up1,this._up2,mh)),this._projection2){const t="ortho"===this._projection2?vh._easeOutExpo(e,0,1,1):vh._easeInCubic(e,0,1,1);s.customProjection.matrix=c.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else s.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return s.ortho.scale=this._orthoScale2,void this.stop();M.scheduleTask(this._update,this)}static _ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}static _easeInCubic(e,t,i,s){return i*(e/=s)*e*e+t}static _easeOutExpo(e,t,i,s){return i*(1-Math.pow(2,-10*e/s))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class bh extends D{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new vh(this),this._t=0,this.state=bh.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,i;const s=performance.now(),r=this._lastTime?.001*(s-this._lastTime):0;if(this._lastTime=s,0!==r)switch(this.state){case bh.SCRUBBING:return;case bh.PLAYING:if(this._t+=this._playingRate*r,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=bh.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case bh.PLAYING_TO:i=this._t+this._playingRate*r*this._playingDir,(this._playingDir<0&&i<=this._playingToT||this._playingDir>0&&i>=this._playingToT)&&(i=this._playingToT,this.state=bh.SCRUBBING,this.fire("stopped")),this._t=i,e.loadFrame(this._t)}}_ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=bh.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=bh.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const i=this._cameraPath;if(!i)return;const s=i.frames[e];s?(this.state=bh.SCRUBBING,this._cameraFlightAnimation.flyTo(s,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=bh.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=bh.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=bh.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}bh.STOPPED=0,bh.SCRUBBING=1,bh.PLAYING=2,bh.PLAYING_TO=3;const yh=c.vec3(),Bh=c.vec3();c.vec3();const xh=c.vec3([0,-1,0]),wh=c.vec4([0,0,0,1]);function Ph(e){if(!Ch(e.width)||!Ch(e.height)){const t=document.createElement("canvas");t.width=Mh(e.width),t.height=Mh(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Ch(e){return 0==(e&e-1)}function Mh(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Fh extends D{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const i=this.scene.canvas.gl;this._state=new et({texture:new _s({gl:i,target:i.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),p.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,i=this.scene.canvas.gl;this._images=[];let s=!1,r=0;for(let o=0;o{r(),t()})):(i.eye=this._eye,i.look=this._look,i.up=this._up,r(),i.projection=s.projection)}}const Ih=c.vec3();const Dh=c.vec3();class Sh{constructor(){this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}saveObjects(e,t){this.numObjects=0,this._mask=t?_.apply(t,{}):null;const i=e.objects,s=!t||t.visible,r=!t||t.edges,o=!t||t.xrayed,n=!t||t.highlighted,a=!t||t.selected,l=!t||t.clippable,A=!t||t.pickable,h=!t||t.colorize,c=!t||t.opacity;for(let e in i)if(i.hasOwnProperty(e)){const t=i[e],u=this.numObjects;if(s&&(this.objectsVisible[u]=t.visible),r&&(this.objectsEdges[u]=t.edges),o&&(this.objectsXrayed[u]=t.xrayed),n&&(this.objectsHighlighted[u]=t.highlighted),a&&(this.objectsSelected[u]=t.selected),l&&(this.objectsClippable[u]=t.clippable),A&&(this.objectsPickable[u]=t.pickable),h){const e=t.colorize;e?(this.objectsColorize[3*u+0]=e[0],this.objectsColorize[3*u+1]=e[1],this.objectsColorize[3*u+2]=e[2],this.objectsHasColorize[u]=!0):this.objectsHasColorize[u]=!1}c&&(this.objectsOpacity[u]=t.opacity),this.numObjects++}}restoreObjects(e){const t=this._mask,i=!t||t.visible,s=!t||t.edges,r=!t||t.xrayed,o=!t||t.highlighted,n=!t||t.selected,a=!t||t.clippable,l=!t||t.pickable,A=!t||t.colorize,h=!t||t.opacity;var c=0;const u=e.objects;for(let e in u)if(u.hasOwnProperty(e)){const t=u[e];i&&(t.visible=this.objectsVisible[c]),s&&(t.edges=this.objectsEdges[c]),r&&(t.xrayed=this.objectsXrayed[c]),o&&(t.highlighted=this.objectsHighlighted[c]),n&&(t.selected=this.objectsSelected[c]),a&&(t.clippable=this.objectsClippable[c]),l&&(t.pickable=this.objectsPickable[c]),A&&(this.objectsHasColorize[c]?(Dh[0]=this.objectsColorize[3*c+0],Dh[1]=this.objectsColorize[3*c+1],Dh[2]=this.objectsColorize[3*c+2],t.colorize=Dh):t.colorize=null),h&&(t.opacity=this.objectsOpacity[c]),c++}}}class Th extends D{constructor(e,t={}){super(e,t),this._skyboxMesh=new Wi(this,{geometry:new Ut(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],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]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new Vt(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new ws(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}const Rh=c.vec4(),Lh=c.vec4(),Uh=c.vec3(),kh=c.vec3(),Oh=c.vec3(),Nh=c.vec4(),Qh=c.vec4(),Vh=c.vec4();class Hh{constructor(e){this._scene=e}dollyToCanvasPos(e,t,i){let s=!1;const r=this._scene.camera;if(e){const t=c.subVec3(e,r.eye,Uh);s=c.lenVec3(t){this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=c.vec3();c.decomposeMat4(c.inverseMat4(this._scene.viewer.camera.viewMatrix,c.mat4()),t,c.vec4(),c.vec3());const i=c.distVec3(t,e);let s=Math.tan(Math.PI/500)*i*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(s/=this._scene.camera.ortho.scale/2),G(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Ms(this._scene,Ji({radius:s})),this._pivotSphere=new Wi(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){c.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,c.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const i=t.boundary,s=i[2],r=i[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*s/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*r/2);let o=t._lastBoundingClientRect;if(!o||t._canvasSizeChanged){const e=t.canvas;o=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(o.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(o.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(G(this.getPivotPos(),this._rtcCenter,this._rtcPos),c.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new Vt(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=c.lookAtMat4v(e.eye,e.look,e.worldUp);c.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const i=this.getPivotPos();this._cameraOffset[2]+=c.distVec3(e.eye,i),t=c.inverseMat4(t);const s=c.transformVec3(t,this._cameraOffset),r=c.vec3();if(c.subVec3(e.eye,i,r),c.addVec3(r,s),e.zUp){const e=r[1];r[1]=r[2],r[2]=e}this._radius=c.lenVec3(r),this._polar=Math.acos(r[1]/this._radius),this._azimuth=Math.atan2(r[0],r[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=c.normalizeVec3(c.subVec3(e.look,e.eye,jh)),i=c.cross3Vec3(t,e.worldUp,Gh);return c.sqLenVec3(i)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,i=Math.abs(c.distVec3(this._scene.center,t.eye)),s=t.project.transposedMatrix,r=s.subarray(8,12),o=s.subarray(12),n=[0,0,-1,1],a=c.dotVec4(n,r)/c.dotVec4(n,o),l=Wh;t.project.unproject(e,a,Kh,Xh,l);const A=c.normalizeVec3(c.subVec3(l,t.eye,jh)),h=c.addVec3(t.eye,c.mulVec3Scalar(A,i,Gh),zh);this.setPivotPos(h)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const i=this._scene.camera;var s=-e;const r=-t;1===i.worldUp[2]&&(s=-s),this._azimuth+=.01*-s,this._polar+=.01*r,this._polar=c.clamp(this._polar,.001,Math.PI-.001);const o=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===i.worldUp[2]){const e=o[1];o[1]=o[2],o[2]=e}const n=c.lenVec3(c.subVec3(i.look,i.eye,c.vec3())),a=this.getPivotPos();c.addVec3(o,a);let l=c.lookAtMat4v(o,a,i.worldUp);l=c.inverseMat4(l);const A=c.transformVec3(l,this._cameraOffset);l[12]-=A[0],l[13]-=A[1],l[14]-=A[2];const h=[l[8],l[9],l[10]];i.eye=[l[12],l[13],l[14]],c.subVec3(i.eye,c.mulVec3Scalar(h,n),i.look),i.up=[l[4],l[5],l[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class Yh{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=c.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;const e=`${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;if(this._lastHash===e)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;const t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&(e.snappedToEdge||e.snappedToVertex)?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const e=this.pickResult.canvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new Ce;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}const Zh=c.vec2();class qh{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController;let n,a,l,A=0,h=0,u=0,d=0,p=!1;const f=c.vec3();let g=!0;const m=this._scene.canvas.canvas,_=[];function v(e=!0){m.style.cursor="move",A=s.pointerCanvasPos[0],h=s.pointerCanvasPos[1],u=s.pointerCanvasPos[0],d=s.pointerCanvasPos[1],e&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(p=!0,f.set(o.pickResult.worldPos)):p=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(i.active&&i.pointerEnabled)switch(t.which){case 1:_[e.input.KEY_SHIFT]||i.planView?(n=!0,v()):(n=!0,v(!1));break;case 2:a=!0,v();break;case 3:l=!0,i.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(!n&&!a&&!l)return;const o=e.canvas.boundary,u=o[2],d=o[3],g=s.pointerCanvasPos[0],m=s.pointerCanvasPos[1],v=_[e.input.KEY_SHIFT]||i.planView||!i.panRightClick&&a||i.panRightClick&&l,b=document.pointerLockElement?t.movementX:g-A,y=document.pointerLockElement?t.movementY:m-h;if(v){const t=e.camera;if("perspective"===t.projection){const i=Math.abs(p?c.lenVec3(c.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(t.perspective.fov/2*Math.PI/180);r.panDeltaX+=1.5*b*i/d,r.panDeltaY+=1.5*y*i/d}else r.panDeltaX+=.5*t.ortho.scale*(b/d),r.panDeltaY+=.5*t.ortho.scale*(y/d)}else!n||a||l||i.planView||(i.firstPerson?(r.rotateDeltaY-=b/u*i.dragRotationRate/2,r.rotateDeltaX+=y/d*(i.dragRotationRate/4)):(r.rotateDeltaY-=b/u*(1.5*i.dragRotationRate),r.rotateDeltaX+=y/d*(1.5*i.dragRotationRate)));A=g,h=m}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{i.active&&i.pointerEnabled&&s.mouseover&&(g=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(i.active&&i.pointerEnabled)switch(e.which){case 1:case 2:case 3:n=!1,a=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(i.active&&i.pointerEnabled){if(3===e.which){!function(e,t){if(e){let i=e.target,s=0,r=0,o=0,n=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,o+=i.scrollLeft,n+=i.scrollTop,i=i.offsetParent;t[0]=e.pageX+o-s,t[1]=e.pageY+n-r}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Zh);const i=Zh[0],s=Zh[1];Math.abs(i-u)<3&&Math.abs(s-d)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Zh,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{i.active&&i.pointerEnabled});const b=1/60;let y=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!i.active||!i.pointerEnabled)return;const t=performance.now()/1e3;var o=null!==y?t-y:0;y=t,o>.05&&(o=.05),o{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(!s.mouseover)return;const n=r._isKeyDownForAction(r.AXIS_VIEW_RIGHT),a=r._isKeyDownForAction(r.AXIS_VIEW_BACK),l=r._isKeyDownForAction(r.AXIS_VIEW_LEFT),A=r._isKeyDownForAction(r.AXIS_VIEW_FRONT),h=r._isKeyDownForAction(r.AXIS_VIEW_TOP),u=r._isKeyDownForAction(r.AXIS_VIEW_BOTTOM);if(!(n||a||l||A||h||u))return;const d=e.aabb,p=c.getAABB3Diag(d);c.getAABB3Center(d,$h);const f=Math.abs(p/Math.tan(t.cameraFlight.fitFOV*c.DEGTORAD)),g=1.1*p;rc.orthoScale=g,n?(rc.eye.set(c.addVec3($h,c.mulVec3Scalar(o.worldRight,f,ec),sc)),rc.look.set($h),rc.up.set(o.worldUp)):a?(rc.eye.set(c.addVec3($h,c.mulVec3Scalar(o.worldForward,f,ec),sc)),rc.look.set($h),rc.up.set(o.worldUp)):l?(rc.eye.set(c.addVec3($h,c.mulVec3Scalar(o.worldRight,-f,ec),sc)),rc.look.set($h),rc.up.set(o.worldUp)):A?(rc.eye.set(c.addVec3($h,c.mulVec3Scalar(o.worldForward,-f,ec),sc)),rc.look.set($h),rc.up.set(o.worldUp)):h?(rc.eye.set(c.addVec3($h,c.mulVec3Scalar(o.worldUp,f,ec),sc)),rc.look.set($h),rc.up.set(c.normalizeVec3(c.mulVec3Scalar(o.worldForward,1,tc),ic))):u&&(rc.eye.set(c.addVec3($h,c.mulVec3Scalar(o.worldUp,-f,ec),sc)),rc.look.set($h),rc.up.set(c.normalizeVec3(c.mulVec3Scalar(o.worldForward,-1,tc)))),!i.firstPerson&&i.followPointer&&t.pivotController.setPivotPos($h),t.cameraFlight.duration>0?t.cameraFlight.flyTo(rc,(()=>{t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(rc),t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class nc{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,A=!1;const h=this._scene.canvas.canvas,u=i=>{let s;i&&i.worldPos&&(s=i.worldPos);const r=i&&i.entity?i.entity.aabb:e.aabb;if(s){const i=e.camera;c.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})},d=e.tickify(this._canvasMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(l||A)return;const r=a.hasSubs("hover"),n=a.hasSubs("hoverEnter"),h=a.hasSubs("hoverOut"),c=a.hasSubs("hoverOff"),u=a.hasSubs("hoverSurface"),d=a.hasSubs("hoverSnapOrSurface");if(r||n||h||c||u||d)if(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=u,o.scheduleSnapOrPick=d,o.update(),o.pickResult){if(o.pickResult.entity){const t=o.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),a.fire("hoverEnter",o.pickResult,!0),this._lastPickedEntityId=t)}a.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&a.fire("hoverSurface",o.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),a.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)});h.addEventListener("mousemove",d),h.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(A=!0);if(1===t.which&&i.active&&i.pointerEnabled&&(s.mouseDownClientX=t.clientX,s.mouseDownClientY=t.clientY,s.mouseDownCursorX=s.pointerCanvasPos[0],s.mouseDownCursorY=s.pointerCanvasPos[1],!i.firstPerson&&i.followPointer&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===t.which))){const t=o.pickResult;t&&t.worldPos?(n.setPivotPos(t.worldPos),n.startPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),n.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(A=!1),n.getPivoting()&&n.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=r=>{if(!i.active||!i.pointerEnabled)return;if(!(1===r.which))return;if(n.hidePivot(),Math.abs(r.clientX-s.mouseDownClientX)>3||Math.abs(r.clientY-s.mouseDownClientY)>3)return;const l=a.hasSubs("picked"),A=a.hasSubs("pickedNothing"),h=a.hasSubs("pickedSurface"),d=a.hasSubs("doublePicked"),p=a.hasSubs("doublePickedSurface"),f=a.hasSubs("doublePickedNothing");if(!(i.doublePickFlyTo||d||p||f))return(l||A||h)&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=h,o.update(),o.pickResult?(a.fire("picked",o.pickResult,!0),o.pickedSurface&&a.fire("pickedSurface",o.pickResult,!0)):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo,o.schedulePickSurface=h,o.update();const e=o.pickResult,r=o.pickedSurface;this._timeout=setTimeout((()=>{e?(a.fire("picked",e,!0),r&&(a.fire("pickedSurface",e,!0),!i.firstPerson&&i.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0),this._clicks=0}),i.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo||d||p,o.schedulePickSurface=o.schedulePickEntity&&p,o.update(),o.pickResult){if(a.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&a.fire("doublePickedSurface",o.pickResult,!0),i.doublePickFlyTo&&(u(o.pickResult),!i.firstPerson&&i.followPointer)){const e=o.pickResult.entity.aabb,i=c.getAABB3Center(e);t.pivotController.setPivotPos(i),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(a.fire("doublePickedNothing",{canvasPos:s.pointerCanvasPos},!0),i.doublePickFlyTo&&(u(),!i.firstPerson&&i.followPointer)){const i=e.aabb,s=c.getAABB3Center(i);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class ac{constructor(e,t,i,s,r){this._scene=e;const o=e.input,n=[],a=e.canvas.canvas;let l=!0;this._onSceneMouseMove=o.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=o.on("keydown",(t=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&s.mouseover&&(n[t]=!0,t===o.KEY_SHIFT&&(a.style.cursor="move"))})),this._onSceneKeyUp=o.on("keyup",(s=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&(n[s]=!1,s===o.KEY_SHIFT&&(a.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(a=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(!s.mouseover)return;const A=t.cameraControl,h=a.deltaTime/1e3;if(!i.planView){const e=A._isKeyDownForAction(A.ROTATE_Y_POS,n),s=A._isKeyDownForAction(A.ROTATE_Y_NEG,n),o=A._isKeyDownForAction(A.ROTATE_X_POS,n),a=A._isKeyDownForAction(A.ROTATE_X_NEG,n),l=h*i.keyboardRotationRate;(e||s||o||a)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),e?r.rotateDeltaY+=l:s&&(r.rotateDeltaY-=l),o?r.rotateDeltaX+=l:a&&(r.rotateDeltaX-=l),!i.firstPerson&&i.followPointer&&t.pivotController.startPivot())}if(!n[o.KEY_CTRL]&&!n[o.KEY_ALT]){const e=A._isKeyDownForAction(A.DOLLY_BACKWARDS,n),o=A._isKeyDownForAction(A.DOLLY_FORWARDS,n);if(e||o){const n=h*i.keyboardDollyRate;!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),o?r.dollyDelta-=n:e&&(r.dollyDelta+=n),l&&(s.followPointerDirty=!0,l=!1)}}const c=A._isKeyDownForAction(A.PAN_FORWARDS,n),u=A._isKeyDownForAction(A.PAN_BACKWARDS,n),d=A._isKeyDownForAction(A.PAN_LEFT,n),p=A._isKeyDownForAction(A.PAN_RIGHT,n),f=A._isKeyDownForAction(A.PAN_UP,n),g=A._isKeyDownForAction(A.PAN_DOWN,n),m=(n[o.KEY_ALT]?.3:1)*h*i.keyboardPanRate;(c||u||d||p||f||g)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),g?r.panDeltaY+=m:f&&(r.panDeltaY+=-m),p?r.panDeltaX+=-m:d&&(r.panDeltaX+=m),u?r.panDeltaZ+=m:c&&(r.panDeltaZ+=-m))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const lc=c.vec3();class Ac{constructor(e,t,i,s,r){this._scene=e;const o=e.camera,n=t.pickController,a=t.pivotController,l=t.panController;let A=1,h=1,u=null;this._onTick=e.on("tick",(()=>{if(!i.active||!i.pointerEnabled)return;let t="default";if(Math.abs(r.dollyDelta)<.001&&(r.dollyDelta=0),Math.abs(r.rotateDeltaX)<.001&&(r.rotateDeltaX=0),Math.abs(r.rotateDeltaY)<.001&&(r.rotateDeltaY=0),0===r.rotateDeltaX&&0===r.rotateDeltaY||(r.dollyDelta=0),i.followPointer){if(--A<=0&&(A=1,0!==r.dollyDelta)){if(0===r.rotateDeltaY&&0===r.rotateDeltaX&&i.followPointer&&s.followPointerDirty&&(n.pickCursorPos=s.pointerCanvasPos,n.schedulePickSurface=!0,n.update(),n.pickResult&&n.pickResult.worldPos?u=n.pickResult.worldPos:(h=1,u=null),s.followPointerDirty=!1),u){const t=Math.abs(c.lenVec3(c.subVec3(u,e.camera.eye,lc)));h=t/i.dollyProximityThreshold}h{s.mouseover=!0}),o.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{s.mouseover=!1,o.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{cc(e,o,s.pointerCanvasPos)}),o.addEventListener("mousedown",this._mouseDownHandler=e=>{i.active&&i.pointerEnabled&&(cc(e,o,s.pointerCanvasPos),s.mouseover=!0)}),o.addEventListener("mouseup",this._mouseUpHandler=e=>{i.active&&i.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function cc(e,t,i){if(e){const{left:s,top:r}=t.getBoundingClientRect();i[0]=e.clientX-s,i[1]=e.clientY-r}else e=window.event,i[0]=e.x,i[1]=e.y;return i}const uc=function(e,t){if(e){let i=e.target,s=0,r=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;t[0]=e.pageX-s,t[1]=e.pageY-r}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class dc{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=c.vec2(),l=c.vec2(),A=c.vec2(),h=c.vec2(),u=[],d=this._scene.canvas.canvas;let p=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),d.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!i.active||!i.pointerEnabled)return;t.preventDefault();const r=t.touches,l=t.changedTouches;for(s.touchStartTime=Date.now(),1===r.length&&1===l.length&&(uc(r[0],a),i.followPointer&&(o.pickCursorPos=a,o.schedulePickSurface=!0,o.update(),i.planView||(o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(n.setPivotPos(o.pickResult.worldPos),!i.firstPerson&&n.startPivot()&&n.showPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),!i.firstPerson&&n.startPivot()&&n.showPivot()))));u.length{n.getPivoting()&&n.endPivot()}),d.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const n=e.canvas.boundary,a=n[2],d=n[3],g=t.touches;if(t.touches.length===p){if(1===p){uc(g[0],l),c.subVec2(l,u[0],h);const t=h[0],o=h[1];if(null!==s.longTouchTimeout&&(Math.abs(t)>i.longTapRadius||Math.abs(o)>i.longTapRadius)&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),i.planView){const s=e.camera;if("perspective"===s.projection){const n=Math.abs(e.camera.eyeLookDist)*Math.tan(s.perspective.fov/2*Math.PI/180);r.panDeltaX+=t*n/d*i.touchPanRate,r.panDeltaY+=o*n/d*i.touchPanRate}else r.panDeltaX+=.5*s.ortho.scale*(t/d)*i.touchPanRate,r.panDeltaY+=.5*s.ortho.scale*(o/d)*i.touchPanRate}else r.rotateDeltaY-=t/a*(1*i.dragRotationRate),r.rotateDeltaX+=o/d*(1.5*i.dragRotationRate)}else if(2===p){const t=g[0],n=g[1];uc(t,l),uc(n,A);const a=c.geometricMeanVec2(u[0],u[1]),h=c.geometricMeanVec2(l,A),p=c.vec2();c.subVec2(a,h,p);const f=p[0],m=p[1],_=e.camera,v=c.distVec2([t.pageX,t.pageY],[n.pageX,n.pageY]),b=(c.distVec2(u[0],u[1])-v)*i.touchDollyRate;if(r.dollyDelta=b,Math.abs(b)<1)if("perspective"===_.projection){const t=o.pickResult?o.pickResult.worldPos:e.center,s=Math.abs(c.lenVec3(c.subVec3(t,e.camera.eye,[])))*Math.tan(_.perspective.fov/2*Math.PI/180);r.panDeltaX-=f*s/d*i.touchPanRate,r.panDeltaY-=m*s/d*i.touchPanRate}else r.panDeltaX-=.5*_.ortho.scale*(f/d)*i.touchPanRate,r.panDeltaY-=.5*_.ortho.scale*(m/d)*i.touchPanRate;s.pointerCanvasPos=h}for(let e=0;e{let s;i&&i.worldPos&&(s=i.worldPos);const r=i?i.entity.aabb:e.aabb;if(s){const i=e.camera;c.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})};d.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!i.active||!i.pointerEnabled)return;null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null);const r=e.touches,o=e.changedTouches;if(a=Date.now(),1===r.length&&1===o.length){h=a,pc(r[0],A);const o=A[0],n=A[1],l=r[0].pageX,c=r[0].pageY;s.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(c)],canvasPos:[Math.round(o),Math.round(n)],event:e},!0),s.longTouchTimeout=null}),i.longTapTimeout)}else h=-1;for(;l.length{if(!i.active||!i.pointerEnabled)return;const t=Date.now(),r=e.touches,a=e.changedTouches,d=n.hasSubs("pickedSurface");null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),0===r.length&&1===a.length&&h>-1&&t-h<150&&(u>-1&&h-u<325?(pc(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=d,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("doublePicked",o.pickResult),o.pickedSurface&&n.fire("doublePickedSurface",o.pickResult),i.doublePickFlyTo&&p(o.pickResult)):(n.fire("doublePickedNothing"),i.doublePickFlyTo&&p()),u=-1):c.distVec2(l[0],A)<4&&(pc(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=d,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("picked",o.pickResult),o.pickedSurface&&n.fire("pickedSurface",o.pickResult)):n.fire("pickedNothing"),u=t),h=-1),l.length=r.length;for(let e=0,t=r.length;e{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:c.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:c.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const i=this.scene;this._controllers={cameraControl:this,pickController:new Yh(this,this._configs),pivotController:new Jh(i,this._configs),panController:new Hh(i),cameraFlight:new vh(this,{duration:.5})},this._handlers=[new hc(this.scene,this._controllers,this._configs,this._states,this._updates),new dc(this.scene,this._controllers,this._configs,this._states,this._updates),new qh(this.scene,this._controllers,this._configs,this._states,this._updates),new oc(this.scene,this._controllers,this._configs,this._states,this._updates),new nc(this.scene,this._controllers,this._configs,this._states,this._updates),new fc(this.scene,this._controllers,this._configs,this._states,this._updates),new ac(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new Ac(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",_.isString(e)){const t=this.scene.input,i={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":i[this.PAN_LEFT]=[t.KEY_A],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_Z],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":i[this.PAN_LEFT]=[t.KEY_Q],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_W],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=i}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const i=this._keyMap[e];if(!i)return!1;t||(t=this.scene.input.keyDown);for(let e=0,s=i.length;e0?Bc(t):null,n=i&&i.length>0?Bc(i):null,a=e=>{if(!e)return;var t=!0;(n&&n[e.type]||o&&!o[e.type])&&(t=!1),t&&s.push(e.id);const i=e.children;if(i)for(var r=0,l=i.length;r * Copyright (c) 2022 Niklas von Hertzen diff --git a/dist/xeokit-sdk.min.es.js b/dist/xeokit-sdk.min.es.js index 7795c038f..e4203ce25 100644 --- a/dist/xeokit-sdk.min.es.js +++ b/dist/xeokit-sdk.min.es.js @@ -14,7 +14,7 @@ class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){ /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT - **/let qh=null;function $h(e,t){const i=3*e,s=3*t;let r,o,n,a,l,A;const h=Math.min(r=qh[i],o=qh[i+1],n=qh[i+2]),c=Math.min(a=qh[s],l=qh[s+1],A=qh[s+2]);if(h!==c)return h-c;const u=Math.max(r,o,n),d=Math.max(a,l,A);return u!==d?u-d:0}let ec=null;function tc(e,t){let i=ec[2*e]-ec[2*t];return 0!==i?i:ec[2*e+1]-ec[2*t+1]}function ic(e,t,i=!1){const s=e.positionsCompressed||[],r=function(e,t){const i=new Int32Array(e.length/3);for(let e=0,t=i.length;e>t;i.sort($h);const s=new Int32Array(e.length);for(let t=0,r=i.length;te[t+1]){let i=e[t];e[t]=e[t+1],e[t+1]=i}ec=new Int32Array(e),t.sort(tc);const i=new Int32Array(e.length);for(let s=0,r=t.length;st){let i=e;e=t,t=i}function i(i,s){return i!==e?e-i:s!==t?t-s:0}let s=0,r=(o.length>>1)-1;for(;s<=r;){const e=r+s>>1,t=i(o[2*e],o[2*e+1]);if(t>0)s=e+1;else{if(!(t<0))return e;r=e-1}}return-s-1}const a=new Int32Array(o.length/2);a.fill(0);const l=s.length/3;if(l>8*(1<u.maxNumPositions&&(u=c()),u.bucketNumber>8)return[e];let p;-1===A[l]&&(A[l]=u.numPositions++,u.positionsCompressed.push(s[3*l]),u.positionsCompressed.push(s[3*l+1]),u.positionsCompressed.push(s[3*l+2])),-1===A[h]&&(A[h]=u.numPositions++,u.positionsCompressed.push(s[3*h]),u.positionsCompressed.push(s[3*h+1]),u.positionsCompressed.push(s[3*h+2])),-1===A[d]&&(A[d]=u.numPositions++,u.positionsCompressed.push(s[3*d]),u.positionsCompressed.push(s[3*d+1]),u.positionsCompressed.push(s[3*d+2])),u.indices.push(A[l]),u.indices.push(A[h]),u.indices.push(A[d]),(p=n(l,h))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(l,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(h,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]]))}const d=t/8*2,p=t/8,f=2*s.length+(r.length+o.length)*d;let g=0,m=-s.length/3;return h.forEach((e=>{g+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*p,m+=e.positionsCompressed.length/3})),g>f?[e]:(i&&function(e,t){const i={},s={};let r=0;e.forEach((e=>{const t=e.indices,o=e.edgeIndices,n=e.positionsCompressed;for(let e=0,s=t.length;e0){const e=t._meshes;for(let t=0,i=e.length;t0){const e=this._meshes;for(let t=0,i=e.length;t{this._viewMatrixDirty=!0})),this._meshesWithDirtyMatrices=[],this._numMeshesWithDirtyMatrices=0,this._onTick=this.scene.on("tick",(()=>{for(;this._numMeshesWithDirtyMatrices>0;)this._meshesWithDirtyMatrices[--this._numMeshesWithDirtyMatrices]._updateMatrix()})),this._createDefaultTextureSet(),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.backfaces=t.backfaces}_meshMatrixDirty(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}_createDefaultTextureSet(){const e=new Uh({id:"defaultColorTexture",texture:new Vr({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Uh({id:"defaultMetalRoughTexture",texture:new Vr({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),i=new Uh({id:"defaultNormalsTexture",texture:new Vr({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),s=new Uh({id:"defaultEmissiveTexture",texture:new Vr({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),r=new Uh({id:"defaultOcclusionTexture",texture:new Vr({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=i,this._textures.defaultEmissiveTexture=s,this._textures.defaultOcclusionTexture=r,this._textureSets.defaultTextureSet=new Lh({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:i,emissiveTexture:s,occlusionTexture:r})}get isPerformanceModel(){return!0}get transforms(){return this._transforms}get textures(){return this._textures}get textureSets(){return this._textureSets}get meshes(){return this._meshes}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),d.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),d.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||mc),d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),d.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),d.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),d.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),d.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0,this._aabbDirty=!0}_transformDirty(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}_sceneModelDirty(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(let e=0,t=this._entityList.length;e0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,i=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,i=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,i=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,i=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,i=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,i=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,i=new Uint8Array(t.length);for(let e=0,s=t.length;e{l.setImage(A,{minFilter:i,magFilter:s,wrapS:r,wrapT:o,wrapR:n,flipY:e.flipY,encoding:a}),this.glRedraw()},A.src=e.src;break;default:this._textureTranscoder?y.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new Uh({id:t,texture:l})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let i,s,r,o,n;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(i=this._textures[e.colorTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(s=this._textures[e.metallicRoughnessTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(r=this._textures[e.normalsTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(o=this._textures[e.emissiveTextureId],!o)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else o=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(n=this._textures[e.occlusionTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultOcclusionTexture;const a=new Lh({id:t,model:this,colorTexture:i,metallicRoughnessTexture:s,normalsTexture:r,emissiveTexture:o,occlusionTexture:n});return this._textureSets[t]=a,a}createTransform(e){if(void 0===e.id||null===e.id)return void this.error("[createTransform] SceneModel.createTransform() config missing: id");if(this._transforms[e.id])return void this.error(`[createTransform] SceneModel already has a transform with this ID: ${e.id}`);let t;if(e.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const i=new hc({id:e.id,model:this,parent:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[i.id]=i,i}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._meshes[e.id])return this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`),!1;if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!(e.buckets||e.indices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)){const t=(e.positions||e.positionsCompressed).length/3;e.indices=this._createDefaultIndices(t)}if(!e.buckets&&!e.indices&&"points"!==e.primitive)return e.indices=this._createDefaultIndices(numIndices),this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;const t=!(!this._dtxEnabled||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||e.textureSetId);if(e.origin=e.origin?d.addVec3(this._origin,e.origin,d.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){const t=e.scale||dc,i=e.position||pc,s=e.rotation||fc;d.eulerToQuaternion(s,"XYZ",gc),e.meshMatrix=d.composeMat4(i,gc,t,d.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=hn(e.positionsDecodeBoundary,d.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):_c,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=d.vec3(),i=[];J(e.positions,i,t)&&(e.positions=i,e.origin=d.addVec3(e.origin,t,t))}if(e.positions){const t=d.collapseAABB3();e.positionsDecodeMatrix=d.mat4(),d.expandAABB3Points3(t,e.positions),e.positionsCompressed=An(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=d.collapseAABB3();d.expandAABB3Points3(t,e.positionsCompressed),Vt.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=d.collapseAABB3();for(let i=0,s=e.buckets.length;i>24&255,r=i>>16&255,o=i>>8&255,n=255&i;switch(e.pickColor=new Uint8Array([n,o,r,s]),e.solid="solid"===e.primitive,t.origin=d.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),this._meshes[e.id]=t,this._unusedMeshes[e.id]=t,this._meshList.push(t),t}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let i=0,s=e.buckets.length;i>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,i=e.origin,s=e.textureSetId||"-",r=e.geometryId,o=`${Math.round(i[0])}.${Math.round(i[1])}.${Math.round(i[2])}.${s}.${r}`;let n=this._vboInstancingLayers[o];if(n)return n;let a=e.textureSet;const l=e.geometry;for(;!n;)switch(l.primitive){case"triangles":case"surface":n=new pa({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!1});break;case"solid":n=new pa({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!0});break;case"lines":n=new $a({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0});break;case"points":n=new Wl({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0})}return this._vboInstancingLayers[o]=n,this.layerList.push(n),n}createEntity(e){if(void 0===e.id?e.id=d.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=d.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;this._visible&&!1!==e.visible&&(t|=q),this._pickable&&!1!==e.pickable&&(t|=ee),this._culled&&!1!==e.culled&&(t|=$),this._clippable&&!1!==e.clippable&&(t|=te),this._collidable&&!1!==e.collidable&&(t|=ie),this._edges&&!1!==e.edges&&(t|=ne),this._xrayed&&!1!==e.xrayed&&(t|=se),this._highlighted&&!1!==e.highlighted&&(t|=re),this._selected&&!1!==e.selected&&(t|=oe),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let i=0,s=e.meshIds.length;ie.sortIdt.sortId?1:0));for(let e=0,t=this.layerList.length;e0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,i=this.layerList.length;t0){const t=`${this.id}-dummyEntityForUnusedMeshes`;this.warn(`Creating dummy SceneModelEntity "${t}" for unused SceneMeshes: [${e.join(",")}]`),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}_getActiveSectionPlanesForLayer(e){const t=this.renderFlags,i=this.scene._sectionPlanesState.sectionPlanes,s=i.length,r=e.layerIndex*s;if(s>0)for(let e=0;e0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}drawColorOpaque(e){const t=this.renderFlags;for(let i=0,s=t.visibleLayers.length;i65536?16:8)}else n=[{positionsCompressed:s,indices:r,edgeIndices:o}];return n}class yc extends R{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;ep.has(e.id)||g.has(e.id)||f.has(e.id))).reduce(((e,i)=>{let s,r=function(e){let t="";return t+=Math.round(255*e[0]).toString(16).padStart(2,"0"),t+=Math.round(255*e[1]).toString(16).padStart(2,"0"),t+=Math.round(255*e[2]).toString(16).padStart(2,"0"),t}(i.colorize);i.xrayed?(s=0===t.xrayMaterial.fillAlpha&&0!==t.xrayMaterial.edgeAlpha?.1:t.xrayMaterial.fillAlpha,s=Math.round(255*s).toString(16).padStart(2,"0"),r=s+r):p.has(i.id)&&(s=Math.round(255*i.opacity).toString(16).padStart(2,"0"),r=s+r),e[r]||(e[r]=[]);const o=i.id,n=i.originalSystemId,a={ifc_guid:n,originating_system:this.originatingSystem};return n!==o&&(a.authoring_tool_id=o),e[r].push(a),e}),{}),_=Object.entries(m).map((([e,t])=>({color:e,components:t})));o.components.coloring=_;const v=t.objectIds,b=t.visibleObjects,y=t.visibleObjectIds,B=v.filter((e=>!b[e])),w=t.selectedObjectIds;return e.defaultInvisible||y.length0&&e.clipping_planes.forEach((function(e){let t=Fc(e.location,Bc),i=Fc(e.direction,Bc);A&&d.negateVec3(i),d.subVec3(t,l),r.yUp&&(t=Ic(t),i=Ic(i)),new yr(s,{pos:t,dir:i})})),s.clearLines(),e.lines&&e.lines.length>0){const t=[],i=[];let r=0;e.lines.forEach((e=>{e.start_point&&e.end_point&&(t.push(e.start_point.x),t.push(e.start_point.y),t.push(e.start_point.z),t.push(e.end_point.x),t.push(e.end_point.y),t.push(e.end_point.z),i.push(r++),i.push(r++))})),new yc(s,{positions:t,indices:i,clippable:!1,collidable:!0})}if(s.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){const t=e.bitmap_type||"jpg",i=e.bitmap_data;let o=Fc(e.location,wc),n=Fc(e.normal,xc),a=Fc(e.up,Pc),l=e.height||1;t&&i&&o&&n&&a&&(r.yUp&&(o=Ic(o),n=Ic(n),a=Ic(a)),new lo(s,{src:i,type:t,pos:o,normal:n,up:a,clippable:!1,collidable:!0,height:l}))})),a&&(s.setObjectsXRayed(s.xrayedObjectIds,!1),s.setObjectsHighlighted(s.highlightedObjectIds,!1),s.setObjectsSelected(s.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(s.setObjectsVisible(s.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!1))))):(s.setObjectsVisible(s.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!0)))));const r=e.components.visibility.view_setup_hints;r&&(!1===r.spaces_visible&&s.setObjectsVisible(i.metaScene.getObjectIDsByType("IfcSpace"),!1),void 0!==r.spaces_translucent&&s.setObjectsXRayed(i.metaScene.getObjectIDsByType("IfcSpace"),!0),r.space_boundaries_visible,!1===r.openings_visible&&s.setObjectsVisible(i.metaScene.getObjectIDsByType("IfcOpening"),!0),r.space_boundaries_translucent,void 0!==r.openings_translucent&&s.setObjectsXRayed(i.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(s.setObjectsSelected(s.selectedObjectIds,!1),e.components.selection.forEach((e=>this._withBCFComponent(t,e,(e=>e.selected=!0))))),e.components.translucency&&(s.setObjectsXRayed(s.xrayedObjectIds,!1),e.components.translucency.forEach((e=>this._withBCFComponent(t,e,(e=>e.xrayed=!0))))),e.components.coloring&&e.components.coloring.forEach((e=>{let i=e.color,s=0,r=!1;8===i.length&&(s=parseInt(i.substring(0,2),16)/256,s<=1&&s>=.95&&(s=1),i=i.substring(2),r=!0);const o=[parseInt(i.substring(0,2),16)/256,parseInt(i.substring(2,4),16)/256,parseInt(i.substring(4,6),16)/256];e.components.map((e=>this._withBCFComponent(t,e,(e=>{e.colorize=o,r&&(e.opacity=s)}))))}))}if(e.perspective_camera||e.orthogonal_camera){let a,A,h,c;if(e.perspective_camera?(a=Fc(e.perspective_camera.camera_view_point,Bc),A=Fc(e.perspective_camera.camera_direction,Bc),h=Fc(e.perspective_camera.camera_up_vector,Bc),r.perspective.fov=e.perspective_camera.field_of_view,c="perspective"):(a=Fc(e.orthogonal_camera.camera_view_point,Bc),A=Fc(e.orthogonal_camera.camera_direction,Bc),h=Fc(e.orthogonal_camera.camera_up_vector,Bc),r.ortho.scale=e.orthogonal_camera.view_to_world_scale,c="ortho"),d.subVec3(a,l),r.yUp&&(a=Ic(a),A=Ic(A),h=Ic(h)),o){const e=s.pick({pickSurface:!0,origin:a,direction:A});A=e?e.worldPos:d.addVec3(a,A,Bc)}else A=d.addVec3(a,A,Bc);n?(r.eye=a,r.look=A,r.up=h,r.projection=c):i.cameraFlight.flyTo({eye:a,look:A,up:h,duration:t.duration,projection:c})}}_withBCFComponent(e,t,i){const s=this.viewer,r=s.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){const o=t.authoring_tool_id,n=r.objects[o];if(n)return void i(n);if(e.updateCompositeObjects){if(s.metaScene.metaObjects[o])return void r.withObjects(s.metaScene.getObjectIDsInSubtree(o),i)}}if(t.ifc_guid){const o=t.ifc_guid,n=r.objects[o];if(n)return void i(n);if(e.updateCompositeObjects){if(s.metaScene.metaObjects[o])return void r.withObjects(s.metaScene.getObjectIDsInSubtree(o),i)}Object.keys(r.models).forEach((t=>{const n=d.globalizeObjectId(t,o),a=r.objects[n];if(a)i(a);else if(e.updateCompositeObjects){s.metaScene.metaObjects[n]&&r.withObjects(s.metaScene.getObjectIDsInSubtree(n),i)}}))}}destroy(){super.destroy()}}function Mc(e){return{x:e[0],y:e[1],z:e[2]}}function Fc(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function Ec(e){return new Float64Array([e[0],-e[2],e[1]])}function Ic(e){return new Float64Array([e[0],e[2],-e[1]])}const Dc=d.vec3(),Sc=(e,t,i,s)=>{var r=e-i,o=t-s;return Math.sqrt(r*r+o*o)};class Tc extends R{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._eventSubs={};var i=this.plugin.viewer.scene;this._originMarker=new ue(i,t.origin),this._targetMarker=new ue(i,t.target),this._originWorld=d.vec3(),this._targetWorld=d.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;const s=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,r=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},n=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,A=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new pe(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._targetDot=new pe(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthWire=new de(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisWire=new de(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisWire=new de(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisWire=new de(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthLabel=new fe(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisLabel=new fe(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisLabel=new fe(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisLabel=new fe(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._sectionPlanesDirty=!0,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,this._labelsVisible=!1,this._labelsOnWires=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.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=i.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=i.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=i.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=i.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=i.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=i.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=i.on("sectionPlaneUpdated",(()=>{this._sectionPlanesDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.labelsVisible=t.labelsVisible,this.labelsOnWires=t.labelsOnWires}_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._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(d.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._originWorld)||this._isSliced(this._targetWorld))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}const t=this._originMarker.viewPos[2],i=this._targetMarker.viewPos[2];if(t>-.3||i>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){d.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var s=this._pp,r=this._cp,o=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var n=o.top-t.top,a=o.left-t.left,l=e.canvas.boundary,A=l[2],h=l[3],c=0;const i=this.plugin.viewer.scene.metrics,f=i.scale,g=i.units,m=i.unitsInfo[g].abbrev;for(var u=0,p=s.length;ue.offsetTop+(e.offsetParent&&e.offsetParent!==s.parentNode&&h(e.offsetParent)),c=e=>e.offsetLeft+(e.offsetParent&&e.offsetParent!==s.parentNode&&c(e.offsetParent)),u=d.vec2();this._onCameraControlHoverSnapOrSurface=i.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(e=>{const t=e.snappedCanvasPos||e.canvasPos;r=!0,o.set(e.worldPos),n.set(e.canvasPos),0===this._mouseState?(this._canvasToPagePos?(this._canvasToPagePos(s,t,u),this._markerDiv.style.left=u[0]-5+"px",this._markerDiv.style.top=u[1]-5+"px"):(this._markerDiv.style.left=c(s)+t[0]-5+"px",this._markerDiv.style.top=h(s)+t[1]-5+"px"),this._markerDiv.style.background="pink",e.snappedToVertex||e.snappedToEdge?(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos,this.pointerLens.snapped=!0),this._markerDiv.style.background="greenyellow",this._markerDiv.style.border="2px solid green"):(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.canvasPos,this.pointerLens.snapped=!1),this._markerDiv.style.background="pink",this._markerDiv.style.border="2px solid red"),A=e.entity):(this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px"),s.style.cursor="pointer",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=this._currentDistanceMeasurementInitState.wireVisible,this._currentDistanceMeasurement.axisVisible=this._currentDistanceMeasurementInitState.axisVisible&&this.distanceMeasurementsPlugin.defaultAxisVisible,this._currentDistanceMeasurement.xAxisVisible=this._currentDistanceMeasurementInitState.xAxisVisible&&this.distanceMeasurementsPlugin.defaultXAxisVisible,this._currentDistanceMeasurement.yAxisVisible=this._currentDistanceMeasurementInitState.yAxisVisible&&this.distanceMeasurementsPlugin.defaultYAxisVisible,this._currentDistanceMeasurement.zAxisVisible=this._currentDistanceMeasurementInitState.zAxisVisible&&this.distanceMeasurementsPlugin.defaultZAxisVisible,this._currentDistanceMeasurement.targetVisible=this._currentDistanceMeasurementInitState.targetVisible,this._currentDistanceMeasurement.target.worldPos=o.slice(),this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px")})),s.addEventListener("mousedown",this._onMouseDown=e=>{1===e.which&&(a=e.clientX,l=e.clientY)}),s.addEventListener("mouseup",this._onMouseUp=t=>{1===t.which&&(t.clientX>a+20||t.clientXl+20||t.clientY{this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos),r=!1,this._markerDiv.style.left="-100px",this._markerDiv.style.top="-100px",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.axisVisible=!1),s.style.cursor="default"})),this._active=!0}deactivate(){if(!this._active)return;this.fire("activated",!1),this.pointerLens&&(this.pointerLens.visible=!1),this._markerDiv&&this._destroyMarkerDiv(),this.reset();const e=this.scene.canvas.canvas;e.removeEventListener("mousedown",this._onMouseDown),e.removeEventListener("mouseup",this._onMouseUp);const t=this.distanceMeasurementsPlugin.viewer.cameraControl;t.off(this._onCameraControlHoverSnapOrSurface),t.off(this._onCameraControlHoverSnapOrSurfaceOff),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null),this._active=!1}reset(){this._active&&(this._destroyMarkerDiv(),this._initMarkerDiv(),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null))}destroy(){this.deactivate(),super.destroy()}}class Uc extends z{constructor(e,t={}){super("DistanceMeasurements",e),this._pointerLens=t.pointerLens,this._container=t.container||document.body,this._defaultControl=null,this._measurements={},this.labelMinAxisLength=t.labelMinAxisLength,this.defaultVisible=!1!==t.defaultVisible,this.defaultOriginVisible=!1!==t.defaultOriginVisible,this.defaultTargetVisible=!1!==t.defaultTargetVisible,this.defaultWireVisible=!1!==t.defaultWireVisible,this.defaultLabelsVisible=!1!==t.defaultLabelsVisible,this.defaultAxisVisible=!1!==t.defaultAxisVisible,this.defaultXAxisVisible=!1!==t.defaultXAxisVisible,this.defaultYAxisVisible=!1!==t.defaultYAxisVisible,this.defaultZAxisVisible=!1!==t.defaultZAxisVisible,this.defaultColor=void 0!==t.defaultColor?t.defaultColor:"#00BBFF",this.zIndex=t.zIndex||1e4,this.defaultLabelsOnWires=!1!==t.defaultLabelsOnWires,this._onMouseOver=(e,t)=>{this.fire("mouseOver",{plugin:this,distanceMeasurement:t,measurement:t,event:e})},this._onMouseLeave=(e,t)=>{this.fire("mouseLeave",{plugin:this,distanceMeasurement:t,measurement:t,event:e})},this._onContextMenu=(e,t)=>{this.fire("contextMenu",{plugin:this,distanceMeasurement:t,measurement:t,event:e})}}getContainerElement(){return this._container}send(e,t){}get pointerLens(){return this._pointerLens}get control(){return this._defaultControl||(this._defaultControl=new Lc(this,{})),this._defaultControl}get measurements(){return this._measurements}set labelMinAxisLength(e){e<1&&(this.error("labelMinAxisLength must be >= 1; defaulting to 25"),e=25),this._labelMinAxisLength=e||25}get labelMinAxisLength(){return this._labelMinAxisLength}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,i=e.target,s=new Tc(this,{id:e.id,plugin:this,container:this._container,origin:{entity:t.entity,worldPos:t.worldPos},target:{entity:i.entity,worldPos:i.worldPos},visible:e.visible,wireVisible:e.wireVisible,axisVisible:!1!==e.axisVisible&&!1!==this.defaultAxisVisible,xAxisVisible:!1!==e.xAxisVisible&&!1!==this.defaultXAxisVisible,yAxisVisible:!1!==e.yAxisVisible&&!1!==this.defaultYAxisVisible,zAxisVisible:!1!==e.zAxisVisible&&!1!==this.defaultZAxisVisible,labelsVisible:!1!==e.labelsVisible&&!1!==this.defaultLabelsVisible,originVisible:e.originVisible,targetVisible:e.targetVisible,color:e.color,labelsOnWires:!1!==e.labelsOnWires&&!1!==this.defaultLabelsOnWires,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[s.id]=s,s.on("destroyed",(()=>{delete this._measurements[s.id]})),this.fire("measurementCreated",s),s}destroyMeasurement(e){const t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("DistanceMeasurement not found: "+e)}setLabelsShown(e){for(const[t,i]of Object.entries(this.measurements))i.labelShown=e}setAxisVisible(e){for(const[t,i]of Object.entries(this.measurements))i.axisVisible=e;this.defaultAxisVisible=e}getAxisVisible(){return this.defaultAxisVisible}clear(){const e=Object.keys(this._measurements);for(var t=0,i=e.length;t{this.plugin.viewer.cameraControl.active=!1},c=()=>{this.plugin.viewer.cameraControl.active=!0},u=()=>{o&&(clearTimeout(o),o=null),this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null),c(),this._touchState=0};i.addEventListener("touchstart",this._onCanvasTouchStart=i=>{const l=i.touches.length;if(1!==l)return void(o&&(clearTimeout(o),o=null));const c=i.touches[0],p=c.clientX,f=c.clientY;switch(n.set([p,f]),a.set([p,f]),this._touchState){case 0:if(1!==l&&null!==o)return void u();const i=t.pick({canvasPos:a,snapping:this._snapping,snapToEdge:this._snapping});if(i&&i.snapped)s.set(i.worldPos),this.pointerCircle.start(i.snappedCanvasPos);else{const e=t.pick({canvasPos:a,pickSurface:!0});if(!e||!e.worldPos)return;s.set(e.worldPos),this.pointerCircle.start(e.canvasPos)}o=setTimeout((()=>{1!==l||a[0]>n[0]+r||a[0]n[1]+r||a[1]{if(o=null,1!==l||a[0]>n[0]+r||a[0]n[1]+r||a[1]{this.pointerCircle.stop();const r=i.touches.length;if(1!==r||1!==i.changedTouches.length)return void(o&&(clearTimeout(o),o=null));const n=i.touches[0],l=n.clientX,h=n.clientY;if(n.identifier!==A)return;let c,u;switch(a.set([l,h]),this._touchState){case 2:this.pointerLens&&(this.pointerLens.canvasPos=a),c=t.pick({canvasPos:a,snapToVertex:this._snapping,snapToEdge:this._snapping}),c&&c.snapped?(this.pointerLens&&(this.pointerLens.snappedCanvasPos=c.snappedCanvasPos,this.pointerLens.snapped=!0),s.set(c.worldPos),this._currentDistanceMeasurement?this._currentDistanceMeasurement.origin.worldPos=c.worldPos:(this._currentDistanceMeasurement=e.createMeasurement({id:d.createUUID(),origin:{worldPos:c.worldPos,entity:c.entity},target:{worldPos:c.worldPos,entity:c.entity}}),this._currentDistanceMeasurement.labelsVisible=!1,this._currentDistanceMeasurement.xAxisVisible=!1,this._currentDistanceMeasurement.yAxisVisible=!1,this._currentDistanceMeasurement.zAxisVisible=!1,this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.originVisible=!0,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.clickable=!1),this.distanceMeasurementsPlugin.fire("measurementStart",this._currentDistanceMeasurement)):(u=t.pick({canvasPos:a,pickSurface:!0}),u&&u.worldPos?(this.pointerLens&&(this.pointerLens.cursorPos=u.canvasPos,this.pointerLens.snapped=!1),s.set(u.worldPos),this._currentDistanceMeasurement?this._currentDistanceMeasurement.origin.worldPos=u.worldPos:(this._currentDistanceMeasurement=e.createMeasurement({id:d.createUUID(),origin:{worldPos:u.worldPos,entity:u.entity},target:{worldPos:u.worldPos,entity:u.entity}}),this._currentDistanceMeasurement.labelsVisible=!1,this._currentDistanceMeasurement.xAxisVisible=!1,this._currentDistanceMeasurement.yAxisVisible=!1,this._currentDistanceMeasurement.zAxisVisible=!1,this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.originVisible=!0,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.clickable=!1),this.distanceMeasurementsPlugin.fire("measurementStart",this._currentDistanceMeasurement)):this.pointerLens&&(this.pointerLens.cursorPos=null,this.pointerLens.snapped=!1)),this._touchState=2;break;case 5:if(1!==r&&null!==o)return clearTimeout(o),o=null,this.pointerLens&&(this.pointerLens.visible=!1),void(this._touchState=7);this.pointerLens&&(this.pointerLens.canvasPos=a),c=t.pick({canvasPos:a,snapToVertex:this._snapping,snapToEdge:this._snapping}),c&&c.worldPos?(this.pointerLens&&(this.pointerLens.cursorPos=c.snappedCanvasPos,this.pointerLens.snapped=!0),this._currentDistanceMeasurement.target.worldPos=c.worldPos,this._currentDistanceMeasurement.target.entity=c.entity,this._currentDistanceMeasurement.targetVisible=!0,this._currentDistanceMeasurement.wireVisible=!0,this._currentDistanceMeasurement.labelsVisible=!0):(u=t.pick({canvasPos:a,pickSurface:!0}),u&&u.worldPos&&(this.pointerLens&&(this.pointerLens.cursorPos=u.canvasPos,this.pointerLens.snapped=!1),this._currentDistanceMeasurement.target.worldPos=u.worldPos,this._currentDistanceMeasurement.target.entity=u.entity,this._currentDistanceMeasurement.targetVisible=!0,this._currentDistanceMeasurement.wireVisible=!0,this._currentDistanceMeasurement.labelsVisible=!0)),this._touchState=5}}),{passive:!0}),i.addEventListener("touchend",this._onCanvasTouchEnd=i=>{this.pointerCircle.stop();const s=i.changedTouches.length;if(1!==s)return;const h=i.changedTouches[0],u=h.clientX,p=h.clientY;if(h.identifier===A)switch(o&&(clearTimeout(o),o=null),l.set([u,p]),this._touchState){case 1:{if(1!==s||u>n[0]+r||un[1]+r||pn[0]+r||un[1]+r||p{i=1e3*this._delayBeforeRestoreSeconds,s||(e.scene._renderer.setColorTextureEnabled(!this._hideColorTexture),e.scene._renderer.setPBREnabled(!this._hidePBR),e.scene._renderer.setSAOEnabled(!this._hideSAO),e.scene._renderer.setTransparentEnabled(!this._hideTransparentObjects),e.scene._renderer.setEdgesEnabled(!this._hideEdges),this._scaleCanvasResolution?e.scene.canvas.resolutionScale=this._scaleCanvasResolutionFactor:e.scene.canvas.resolutionScale=this._defaultScaleCanvasResolutionFactor,s=!0)},o=()=>{e.scene.canvas.resolutionScale=this._defaultScaleCanvasResolutionFactor,e.scene._renderer.setEdgesEnabled(!0),e.scene._renderer.setColorTextureEnabled(!0),e.scene._renderer.setPBREnabled(!0),e.scene._renderer.setSAOEnabled(!0),e.scene._renderer.setTransparentEnabled(!0),s=!1};this._onCanvasBoundary=e.scene.canvas.on("boundary",r),this._onCameraMatrix=e.scene.camera.on("matrix",r),this._onSceneTick=e.scene.on("tick",(e=>{s&&(i-=e.deltaTime,(!this._delayBeforeRestore||i<=0)&&o())}));let n=!1;this._onSceneMouseDown=e.scene.input.on("mousedown",(()=>{n=!0})),this._onSceneMouseUp=e.scene.input.on("mouseup",(()=>{n=!1})),this._onSceneMouseMove=e.scene.input.on("mousemove",(()=>{n&&r()}))}get hideColorTexture(){return this._hideColorTexture}set hideColorTexture(e){this._hideColorTexture=e}get hidePBR(){return this._hidePBR}set hidePBR(e){this._hidePBR=e}get hideSAO(){return this._hideSAO}set hideSAO(e){this._hideSAO=e}get hideEdges(){return this._hideEdges}set hideEdges(e){this._hideEdges=e}get hideTransparentObjects(){return this._hideTransparentObjects}set hideTransparentObjects(e){this._hideTransparentObjects=!1!==e}get scaleCanvasResolution(){return this._scaleCanvasResolution}set scaleCanvasResolution(e){this._scaleCanvasResolution=e}get defaultScaleCanvasResolutionFactor(){return this._defaultScaleCanvasResolutionFactor}set defaultScaleCanvasResolutionFactor(e){this._defaultScaleCanvasResolutionFactor=e||1}get scaleCanvasResolutionFactor(){return this._scaleCanvasResolutionFactor}set scaleCanvasResolutionFactor(e){this._scaleCanvasResolutionFactor=e||.6}get delayBeforeRestore(){return this._delayBeforeRestore}set delayBeforeRestore(e){this._delayBeforeRestore=e}get delayBeforeRestoreSeconds(){return this._delayBeforeRestoreSeconds}set delayBeforeRestoreSeconds(e){this._delayBeforeRestoreSeconds=null!=e?e:.5}send(e,t){}destroy(){this.viewer.scene.camera.off(this._onCameraMatrix),this.viewer.scene.canvas.off(this._onCanvasBoundary),this.viewer.scene.input.off(this._onSceneMouseDown),this.viewer.scene.input.off(this._onSceneMouseUp),this.viewer.scene.input.off(this._onSceneMouseMove),this.viewer.scene.off(this._onSceneTick),super.destroy()}}class Nc{constructor(){}getMetaModel(e,t,i){y.loadJSON(e,(e=>{t(e)}),(function(e){i(e)}))}getGLTF(e,t,i){y.loadArraybuffer(e,(e=>{t(e)}),(function(e){i(e)}))}getGLB(e,t,i){y.loadArraybuffer(e,(e=>{t(e)}),(function(e){i(e)}))}getArrayBuffer(e,t,i,s){!function(e,t,i,s){var r=()=>{};i=i||r,s=s||r;const o=/^data:(.*?)(;base64)?,(.*)$/,n=t.match(o);if(n){const e=!!n[2];var a=n[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),t=new Uint8Array(e);for(var l=0;l{i(e)}),(function(e){s(e)}))}}class Qc{constructor(e={}){this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=e.messages,this.locale=e.locale}set messages(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}loadMessages(e={}){for(let t in e)this._messages[t]=e[t];this.messages=this._messages}clearMessages(){this.messages={}}get locales(){return this._locales}set locale(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}get locale(){return this._locale}translate(e,t){const i=this._messages[this._locale];if(!i)return null;const s=Vc(e,i);return s?t?Hc(s,t):s:null}translatePlurals(e,t,i){const s=this._messages[this._locale];if(!s)return null;let r=Vc(e,s);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=Hc(r,[t]),i&&(r=Hc(r,i)),r):null}fire(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);const s=this._eventSubs[e];if(s)for(const e in s)if(s.hasOwnProperty(e)){s[e].callback(t)}}on(t,i){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let s=this._eventSubs[t];s||(s={},this._eventSubs[t]=s);const r=this._eventSubIDMap.addItem();s[r]={callback:i},this._eventSubEvents[r]=t;const o=this._events[t];return void 0!==o&&i(o),r}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}function Vc(e,t){if(t[e])return t[e];const i=e.split(".");let s=t;for(let e=0,t=i.length;s&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,s=e+t;i<0&&(i=0),s>1&&(s=1);var r=this.getPoint(i),o=this.getPoint(s),n=d.subVec3(o,r,[]);return d.normalizeVec3(n,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,s=[],r=this.getPoint(0),o=0;for(s.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),o+=d.lenVec3(d.subVec3(t,r,[])),s.push(o),r=t;return this.cacheArcLengths=s,s}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var i,s=this._getLengths(),r=0,o=s.length;i=t||e*s[o-1];for(var n,a=0,l=o-1;a<=l;)if((n=s[r=Math.floor(a+(l-a)/2)]-i)<0)a=r+1;else{if(!(n>0)){l=r;break}l=r-1}if(s[r=l]===i)return r/(o-1);var A=s[r];return(r+(i-A)/(s[r+1]-A))/(o-1)}}class Gc extends jc{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,s=Math.floor(i),r=i-s,o=t[0===s?s:s-1],n=t[s],a=t[s>t.length-2?t.length-1:s+1],l=t[s>t.length-3?t.length-1:s+2],A=d.vec3();return A[0]=d.catmullRomInterpolate(o[0],n[0],a[0],l[0],r),A[1]=d.catmullRomInterpolate(o[1],n[1],a[1],l[1],r),A[2]=d.catmullRomInterpolate(o[2],n[2],a[2],l[2],r),A}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const zc=d.vec3();class Wc extends R{get type(){return"CameraPath"}constructor(e,t={}){super(e,t),this._frames=[],this._eyeCurve=new Gc(this),this._lookCurve=new Gc(this),this._upCurve=new Gc(this),t.frames&&(this.addFrames(t.frames),this.smoothFrameTimes(1))}get frames(){return this._frames}get eyeCurve(){return this._eyeCurve}get lookCurve(){return this._lookCurve}get upCurve(){return this._upCurve}saveFrame(e){const t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}addFrame(e,t,i,s){const r={t:e,eye:t.slice(0),look:i.slice(0),up:s.slice(0)};this._frames.push(r),this._eyeCurve.points.push(r.eye),this._lookCurve.points.push(r.look),this._upCurve.points.push(r.up)}addFrames(e){let t;for(let i=0,s=e.length;i1?1:e,t.eye=this._eyeCurve.getPoint(e,zc),t.look=this._lookCurve.getPoint(e,zc),t.up=this._upCurve.getPoint(e,zc)}sampleFrame(e,t,i,s){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,i),this._upCurve.getPoint(e,s)}smoothFrameTimes(e){if(0===this._frames.length)return;const t=d.vec3();var i=0;this._frames[0].t=0;const s=[];for(let e=1,o=this._frames.length;e=1;e>1&&(e=1);const i=this.easing?qc._ease(e,0,1,1):e,s=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(d.subVec3(s.eye,s.look,Zc),s.eye=d.lerpVec3(i,0,1,this._eye1,this._eye2,Jc),s.look=d.subVec3(Jc,Zc,Xc)):this._flyingLook&&(s.look=d.lerpVec3(i,0,1,this._look1,this._look2,Xc),s.up=d.lerpVec3(i,0,1,this._up1,this._up2,Yc)):this._flyingEyeLookUp&&(s.eye=d.lerpVec3(i,0,1,this._eye1,this._eye2,Jc),s.look=d.lerpVec3(i,0,1,this._look1,this._look2,Xc),s.up=d.lerpVec3(i,0,1,this._up1,this._up2,Yc)),this._projection2){const t="ortho"===this._projection2?qc._easeOutExpo(e,0,1,1):qc._easeInCubic(e,0,1,1);s.customProjection.matrix=d.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else s.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return s.ortho.scale=this._orthoScale2,void this.stop();I.scheduleTask(this._update,this)}static _ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}static _easeInCubic(e,t,i,s){return i*(e/=s)*e*e+t}static _easeOutExpo(e,t,i,s){return i*(1-Math.pow(2,-10*e/s))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class $c extends R{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new qc(this),this._t=0,this.state=$c.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,i;const s=performance.now(),r=this._lastTime?.001*(s-this._lastTime):0;if(this._lastTime=s,0!==r)switch(this.state){case $c.SCRUBBING:return;case $c.PLAYING:if(this._t+=this._playingRate*r,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=$c.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case $c.PLAYING_TO:i=this._t+this._playingRate*r*this._playingDir,(this._playingDir<0&&i<=this._playingToT||this._playingDir>0&&i>=this._playingToT)&&(i=this._playingToT,this.state=$c.SCRUBBING,this.fire("stopped")),this._t=i,e.loadFrame(this._t)}}_ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=$c.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=$c.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const i=this._cameraPath;if(!i)return;const s=i.frames[e];s?(this.state=$c.SCRUBBING,this._cameraFlightAnimation.flyTo(s,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=$c.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=$c.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=$c.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}$c.STOPPED=0,$c.SCRUBBING=1,$c.PLAYING=2,$c.PLAYING_TO=3;const eu=d.vec3(),tu=d.vec3();d.vec3();const iu=d.vec3([0,-1,0]),su=d.vec4([0,0,0,1]);class ru extends R{constructor(e,t={}){super(e,t),this._src=null,this._image=null,this._pos=d.vec3(),this._origin=d.vec3(),this._rtcPos=d.vec3(),this._dir=d.vec3(),this._size=1,this._imageSize=d.vec2(),this._texture=new Kr(this),this._plane=new pr(this,{geometry:new Gt(this,ro({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Jt(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0}),clippable:t.clippable}),this._grid=new pr(this,{geometry:new Gt(this,so({size:1,divisions:10})),material:new Jt(this,{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:t.clippable}),this._node=new Dr(this,{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[this._plane,this._grid]}),this._gridVisible=!1,this.visible=!0,this.gridVisible=t.gridVisible,this.position=t.position,this.rotation=t.rotation,this.dir=t.dir,this.size=t.size,this.collidable=t.collidable,this.clippable=t.clippable,this.pickable=t.pickable,this.opacity=t.opacity,t.image?this.image=t.image:this.src=t.src}set visible(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}get visible(){return this._plane.visible}set gridVisible(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}get gridVisible(){return this._gridVisible}set image(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}get image(){return this._image}set src(e){if(this._src=e,this._src){this._image=null;const e=new Image;e.onload=()=>{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set position(e){this._pos.set(e||[0,0,0]),X(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}get position(){return this._pos}set rotation(e){this._node.rotation=e}get rotation(){return this._node.rotation}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set dir(e){if(this._dir.set(e||[0,0,-1]),e){const t=this.scene.center,i=[-this._dir[0],-this._dir[1],-this._dir[2]];d.subVec3(t,this.position,eu);const s=-d.dotVec3(i,eu);d.normalizeVec3(i),d.mulVec3Scalar(i,s,tu),d.vec3PairToQuaternion(iu,e,su),this._node.quaternion=su}}get dir(){return this._dir}set collidable(e){this._node.collidable=!1!==e}get collidable(){return this._node.collidable}set clippable(e){this._node.clippable=!1!==e}get clippable(){return this._node.clippable}set pickable(e){this._node.pickable=!1!==e}get pickable(){return this._node.pickable}set opacity(e){this._node.opacity=e}get opacity(){return this._node.opacity}destroy(){super.destroy()}_updatePlaneSizeFromImage(){const e=this._size,t=this._imageSize[0],i=this._imageSize[1];if(t>i){const s=i/t;this._node.scale=[e,1,e*s]}else{const s=t/i;this._node.scale=[e*s,1,e]}}}class ou extends It{get type(){return"PointLight"}constructor(e,t={}){super(e,t);const i=this;this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const s=this.scene.camera,r=this.scene.canvas;this._onCameraViewMatrix=s.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=r.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new lt({type:"point",pos:d.vec3([1,1,1]),color:d.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(i._shadowViewMatrixDirty){i._shadowViewMatrix||(i._shadowViewMatrix=d.identityMat4());const e=i._state.pos,t=s.look,r=s.up;d.lookAtMat4v(e,t,r,i._shadowViewMatrix),i._shadowViewMatrixDirty=!1}return i._shadowViewMatrix},getShadowProjMatrix:()=>{if(i._shadowProjMatrixDirty){i._shadowProjMatrix||(i._shadowProjMatrix=d.identityMat4());const e=i.scene.canvas.canvas;d.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,i._shadowProjMatrix),i._shadowProjMatrixDirty=!1}return i._shadowProjMatrix},getShadowRenderBuf:()=>(i._shadowRenderBuf||(i._shadowRenderBuf=new it(i.scene.canvas.canvas,i.scene.canvas.gl,{size:[1024,1024]})),i._shadowRenderBuf)}),this.pos=t.pos,this.color=t.color,this.intensity=t.intensity,this.constantAttenuation=t.constantAttenuation,this.linearAttenuation=t.linearAttenuation,this.quadraticAttenuation=t.quadraticAttenuation,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set pos(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get pos(){return this._state.pos}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 constantAttenuation(e){this._state.attenuation[0]=e||0,this.glRedraw()}get constantAttenuation(){return this._state.attenuation[0]}set linearAttenuation(e){this._state.attenuation[1]=e||0,this.glRedraw()}get linearAttenuation(){return this._state.attenuation[1]}set quadraticAttenuation(e){this._state.attenuation[2]=e||0,this.glRedraw()}get quadraticAttenuation(){return this._state.attenuation[2]}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()}}function nu(e){if(!au(e.width)||!au(e.height)){const t=document.createElement("canvas");t.width=lu(e.width),t.height=lu(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function au(e){return 0==(e&e-1)}function lu(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Au extends R{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const i=this.scene.canvas.gl;this._state=new lt({texture:new Vr({gl:i,target:i.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),m.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,i=this.scene.canvas.gl;this._images=[];let s=!1,r=0;for(let o=0;o{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set collidable(e){this._mesh.collidable=!1!==e}get collidable(){return this._mesh.collidable}set clippable(e){this._mesh.clippable=!1!==e}get clippable(){return this._mesh.clippable}set pickable(e){this._mesh.pickable=!1!==e}get pickable(){return this._mesh.pickable}set opacity(e){this._mesh.opacity=e}get opacity(){return this._mesh.opacity}_updatePlaneSizeFromImage(){const e=.5*this._size,t=this._imageSize[0],i=this._imageSize[1],s=i/t;this._geometry.positions=t>i?[e,e*s,0,-e,e*s,0,-e,-e*s,0,e,-e*s,0]:[e/s,e,0,-e/s,e,0,-e/s,-e,0,e/s,-e,0]}}class du{constructor(e){this._eye=d.vec3(),this._look=d.vec3(),this._up=d.vec3(),this._projection={},e&&this.saveCamera(e)}saveCamera(e){const t=e.camera,i=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:i.fov,fovAxis:i.fovAxis,near:i.near,far:i.far};break;case"ortho":this._projection={projection:"ortho",scale:i.scale,near:i.near,far:i.far};break;case"frustum":this._projection={projection:"frustum",left:i.left,right:i.right,top:i.top,bottom:i.bottom,near:i.near,far:i.far};break;case"custom":this._projection={projection:"custom",matrix:i.matrix.slice()}}}restoreCamera(e,t){const i=e.camera,s=this._projection;function r(){switch(s.type){case"perspective":i.perspective.fov=s.fov,i.perspective.fovAxis=s.fovAxis,i.perspective.near=s.near,i.perspective.far=s.far;break;case"ortho":i.ortho.scale=s.scale,i.ortho.near=s.near,i.ortho.far=s.far;break;case"frustum":i.frustum.left=s.left,i.frustum.right=s.right,i.frustum.top=s.top,i.frustum.bottom=s.bottom,i.frustum.near=s.near,i.frustum.far=s.far;break;case"custom":i.customProjection.matrix=s.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:s.scale,projection:s.projection},(()=>{r(),t()})):(i.eye=this._eye,i.look=this._look,i.up=this._up,r(),i.projection=s.projection)}}const pu=d.vec3();class fu{constructor(e){if(this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,e){const t=e.metaScene.scene;this.saveObjects(t,e)}}saveObjects(e,t,i){this.numObjects=0,this._mask=i?y.apply(i,{}):null;const s=!i||i.visible,r=!i||i.edges,o=!i||i.xrayed,n=!i||i.highlighted,a=!i||i.selected,l=!i||i.clippable,A=!i||i.pickable,h=!i||i.colorize,c=!i||i.opacity,u=t.metaObjects,d=e.objects;for(let e=0,t=u.length;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=d.vec3();return t[0]=d.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=d.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=d.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}class vu extends jc{constructor(e,t={}){super(e,t),this._cachedLengths=[],this._dirty=!0,this._curves=[],this._t=0,this._dirtySubs=[],this._destroyedSubs=[],this.curves=t.curves||[],this.t=t.t}addCurve(e){this._curves.push(e),this._dirty=!0}set curves(e){var t,i,s;for(e=e||[],i=0,s=this._curves.length;i1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}get length(){var e=this._getCurveLengths();return e[e.length-1]}getPoint(e){for(var t,i=e*this.length,s=this._getCurveLengths(),r=0;r=i){var o=1-(s[r]-i)/(t=this._curves[r]).length;return t.getPointAt(o)}r++}return null}_getCurveLengths(){if(!this._dirty)return this._cachedLengths;var e,t=[],i=0,s=this._curves.length;for(e=0;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=d.vec3();return t[0]=d.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=d.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=d.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}class yu extends vc{constructor(e,t={}){super(e,t)}}class Bu extends R{constructor(e,t={}){super(e,t),this._skyboxMesh=new pr(this,{geometry:new Gt(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],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]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new Jt(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Kr(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}class wu{transcode(e,t,i={}){}destroy(){}}const xu=d.vec4(),Pu=d.vec4(),Cu=d.vec3(),Mu=d.vec3(),Fu=d.vec3(),Eu=d.vec4(),Iu=d.vec4(),Du=d.vec4();class Su{constructor(e){this._scene=e}dollyToCanvasPos(e,t,i){let s=!1;const r=this._scene.camera;if(e){const t=d.subVec3(e,r.eye,Cu);s=d.lenVec3(t){this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=d.vec3();d.decomposeMat4(d.inverseMat4(this._scene.viewer.camera.viewMatrix,d.mat4()),t,d.vec4(),d.vec3());const i=d.distVec3(t,e);let s=Math.tan(Math.PI/500)*i*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(s/=this._scene.camera.ortho.scale/2),X(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Zr(this._scene,mr({radius:s})),this._pivotSphere=new pr(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){d.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,d.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const i=t.boundary,s=i[2],r=i[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*s/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*r/2);let o=t._lastBoundingClientRect;if(!o||t._canvasSizeChanged){const e=t.canvas;o=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(o.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(o.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(X(this.getPivotPos(),this._rtcCenter,this._rtcPos),d.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new Jt(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=d.lookAtMat4v(e.eye,e.look,e.worldUp);d.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const i=this.getPivotPos();this._cameraOffset[2]+=d.distVec3(e.eye,i),t=d.inverseMat4(t);const s=d.transformVec3(t,this._cameraOffset),r=d.vec3();if(d.subVec3(e.eye,i,r),d.addVec3(r,s),e.zUp){const e=r[1];r[1]=r[2],r[2]=e}this._radius=d.lenVec3(r),this._polar=Math.acos(r[1]/this._radius),this._azimuth=Math.atan2(r[0],r[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=d.normalizeVec3(d.subVec3(e.look,e.eye,Tu)),i=d.cross3Vec3(t,e.worldUp,Ru);return d.sqLenVec3(i)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,i=Math.abs(d.distVec3(this._scene.center,t.eye)),s=t.project.transposedMatrix,r=s.subarray(8,12),o=s.subarray(12),n=[0,0,-1,1],a=d.dotVec4(n,r)/d.dotVec4(n,o),l=Uu;t.project.unproject(e,a,ku,Ou,l);const A=d.normalizeVec3(d.subVec3(l,t.eye,Tu)),h=d.addVec3(t.eye,d.mulVec3Scalar(A,i,Ru),Lu);this.setPivotPos(h)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const i=this._scene.camera;var s=-e;const r=-t;1===i.worldUp[2]&&(s=-s),this._azimuth+=.01*-s,this._polar+=.01*r,this._polar=d.clamp(this._polar,.001,Math.PI-.001);const o=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===i.worldUp[2]){const e=o[1];o[1]=o[2],o[2]=e}const n=d.lenVec3(d.subVec3(i.look,i.eye,d.vec3())),a=this.getPivotPos();d.addVec3(o,a);let l=d.lookAtMat4v(o,a,i.worldUp);l=d.inverseMat4(l);const A=d.transformVec3(l,this._cameraOffset);l[12]-=A[0],l[13]-=A[1],l[14]-=A[2];const h=[l[8],l[9],l[10]];i.eye=[l[12],l[13],l[14]],d.subVec3(i.eye,d.mulVec3Scalar(h,n),i.look),i.up=[l[4],l[5],l[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class Qu{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=d.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;const e=`${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;if(this._lastHash===e)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;const t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&(e.snappedToEdge||e.snappedToVertex)?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const e=this.pickResult.canvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new Re;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}const Vu=d.vec2();class Hu{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController;let n,a,l,A=0,h=0,c=0,u=0,p=!1;const f=d.vec3();let g=!0;const m=this._scene.canvas.canvas,_=[];function v(e=!0){m.style.cursor="move",A=s.pointerCanvasPos[0],h=s.pointerCanvasPos[1],c=s.pointerCanvasPos[0],u=s.pointerCanvasPos[1],e&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(p=!0,f.set(o.pickResult.worldPos)):p=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(i.active&&i.pointerEnabled)switch(t.which){case 1:_[e.input.KEY_SHIFT]||i.planView?(n=!0,v()):(n=!0,v(!1));break;case 2:a=!0,v();break;case 3:l=!0,i.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(!n&&!a&&!l)return;const o=e.canvas.boundary,c=o[2],u=o[3],g=s.pointerCanvasPos[0],m=s.pointerCanvasPos[1],v=_[e.input.KEY_SHIFT]||i.planView||!i.panRightClick&&a||i.panRightClick&&l,b=document.pointerLockElement?t.movementX:g-A,y=document.pointerLockElement?t.movementY:m-h;if(v){const t=e.camera;if("perspective"===t.projection){const i=Math.abs(p?d.lenVec3(d.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(t.perspective.fov/2*Math.PI/180);r.panDeltaX+=1.5*b*i/u,r.panDeltaY+=1.5*y*i/u}else r.panDeltaX+=.5*t.ortho.scale*(b/u),r.panDeltaY+=.5*t.ortho.scale*(y/u)}else!n||a||l||i.planView||(i.firstPerson?(r.rotateDeltaY-=b/c*i.dragRotationRate/2,r.rotateDeltaX+=y/u*(i.dragRotationRate/4)):(r.rotateDeltaY-=b/c*(1.5*i.dragRotationRate),r.rotateDeltaX+=y/u*(1.5*i.dragRotationRate)));A=g,h=m}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{i.active&&i.pointerEnabled&&s.mouseover&&(g=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(i.active&&i.pointerEnabled)switch(e.which){case 1:case 2:case 3:n=!1,a=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(i.active&&i.pointerEnabled){if(3===e.which){!function(e,t){if(e){let i=e.target,s=0,r=0,o=0,n=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,o+=i.scrollLeft,n+=i.scrollTop,i=i.offsetParent;t[0]=e.pageX+o-s,t[1]=e.pageY+n-r}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Vu);const i=Vu[0],s=Vu[1];Math.abs(i-c)<3&&Math.abs(s-u)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Vu,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{i.active&&i.pointerEnabled});const b=1/60;let y=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!i.active||!i.pointerEnabled)return;const t=performance.now()/1e3;var o=null!==y?t-y:0;y=t,o>.05&&(o=.05),o{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(!s.mouseover)return;const n=r._isKeyDownForAction(r.AXIS_VIEW_RIGHT),a=r._isKeyDownForAction(r.AXIS_VIEW_BACK),l=r._isKeyDownForAction(r.AXIS_VIEW_LEFT),A=r._isKeyDownForAction(r.AXIS_VIEW_FRONT),h=r._isKeyDownForAction(r.AXIS_VIEW_TOP),c=r._isKeyDownForAction(r.AXIS_VIEW_BOTTOM);if(!(n||a||l||A||h||c))return;const u=e.aabb,p=d.getAABB3Diag(u);d.getAABB3Center(u,ju);const f=Math.abs(p/Math.tan(t.cameraFlight.fitFOV*d.DEGTORAD)),g=1.1*p;Xu.orthoScale=g,n?(Xu.eye.set(d.addVec3(ju,d.mulVec3Scalar(o.worldRight,f,Gu),Ku)),Xu.look.set(ju),Xu.up.set(o.worldUp)):a?(Xu.eye.set(d.addVec3(ju,d.mulVec3Scalar(o.worldForward,f,Gu),Ku)),Xu.look.set(ju),Xu.up.set(o.worldUp)):l?(Xu.eye.set(d.addVec3(ju,d.mulVec3Scalar(o.worldRight,-f,Gu),Ku)),Xu.look.set(ju),Xu.up.set(o.worldUp)):A?(Xu.eye.set(d.addVec3(ju,d.mulVec3Scalar(o.worldForward,-f,Gu),Ku)),Xu.look.set(ju),Xu.up.set(o.worldUp)):h?(Xu.eye.set(d.addVec3(ju,d.mulVec3Scalar(o.worldUp,f,Gu),Ku)),Xu.look.set(ju),Xu.up.set(d.normalizeVec3(d.mulVec3Scalar(o.worldForward,1,zu),Wu))):c&&(Xu.eye.set(d.addVec3(ju,d.mulVec3Scalar(o.worldUp,-f,Gu),Ku)),Xu.look.set(ju),Xu.up.set(d.normalizeVec3(d.mulVec3Scalar(o.worldForward,-1,zu)))),!i.firstPerson&&i.followPointer&&t.pivotController.setPivotPos(ju),t.cameraFlight.duration>0?t.cameraFlight.flyTo(Xu,(()=>{t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(Xu),t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class Yu{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,A=!1;const h=this._scene.canvas.canvas,c=i=>{let s;i&&i.worldPos&&(s=i.worldPos);const r=i&&i.entity?i.entity.aabb:e.aabb;if(s){const i=e.camera;d.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})},u=e.tickify(this._canvasMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(l||A)return;const r=a.hasSubs("hover"),n=a.hasSubs("hoverEnter"),h=a.hasSubs("hoverOut"),c=a.hasSubs("hoverOff"),u=a.hasSubs("hoverSurface"),d=a.hasSubs("hoverSnapOrSurface");if(r||n||h||c||u||d)if(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=u,o.scheduleSnapOrPick=d,o.update(),o.pickResult){if(o.pickResult.entity){const t=o.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),a.fire("hoverEnter",o.pickResult,!0),this._lastPickedEntityId=t)}a.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&a.fire("hoverSurface",o.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),a.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)});h.addEventListener("mousemove",u),h.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(A=!0);if(1===t.which&&i.active&&i.pointerEnabled&&(s.mouseDownClientX=t.clientX,s.mouseDownClientY=t.clientY,s.mouseDownCursorX=s.pointerCanvasPos[0],s.mouseDownCursorY=s.pointerCanvasPos[1],!i.firstPerson&&i.followPointer&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===t.which))){const t=o.pickResult;t&&t.worldPos?(n.setPivotPos(t.worldPos),n.startPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),n.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(A=!1),n.getPivoting()&&n.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=r=>{if(!i.active||!i.pointerEnabled)return;if(!(1===r.which))return;if(n.hidePivot(),Math.abs(r.clientX-s.mouseDownClientX)>3||Math.abs(r.clientY-s.mouseDownClientY)>3)return;const l=a.hasSubs("picked"),A=a.hasSubs("pickedNothing"),h=a.hasSubs("pickedSurface"),u=a.hasSubs("doublePicked"),p=a.hasSubs("doublePickedSurface"),f=a.hasSubs("doublePickedNothing");if(!(i.doublePickFlyTo||u||p||f))return(l||A||h)&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=h,o.update(),o.pickResult?(a.fire("picked",o.pickResult,!0),o.pickedSurface&&a.fire("pickedSurface",o.pickResult,!0)):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo,o.schedulePickSurface=h,o.update();const e=o.pickResult,r=o.pickedSurface;this._timeout=setTimeout((()=>{e?(a.fire("picked",e,!0),r&&(a.fire("pickedSurface",e,!0),!i.firstPerson&&i.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0),this._clicks=0}),i.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo||u||p,o.schedulePickSurface=o.schedulePickEntity&&p,o.update(),o.pickResult){if(a.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&a.fire("doublePickedSurface",o.pickResult,!0),i.doublePickFlyTo&&(c(o.pickResult),!i.firstPerson&&i.followPointer)){const e=o.pickResult.entity.aabb,i=d.getAABB3Center(e);t.pivotController.setPivotPos(i),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(a.fire("doublePickedNothing",{canvasPos:s.pointerCanvasPos},!0),i.doublePickFlyTo&&(c(),!i.firstPerson&&i.followPointer)){const i=e.aabb,s=d.getAABB3Center(i);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class Zu{constructor(e,t,i,s,r){this._scene=e;const o=e.input,n=[],a=e.canvas.canvas;let l=!0;this._onSceneMouseMove=o.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=o.on("keydown",(t=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&s.mouseover&&(n[t]=!0,t===o.KEY_SHIFT&&(a.style.cursor="move"))})),this._onSceneKeyUp=o.on("keyup",(s=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&(n[s]=!1,s===o.KEY_SHIFT&&(a.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(a=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(!s.mouseover)return;const A=t.cameraControl,h=a.deltaTime/1e3;if(!i.planView){const e=A._isKeyDownForAction(A.ROTATE_Y_POS,n),s=A._isKeyDownForAction(A.ROTATE_Y_NEG,n),o=A._isKeyDownForAction(A.ROTATE_X_POS,n),a=A._isKeyDownForAction(A.ROTATE_X_NEG,n),l=h*i.keyboardRotationRate;(e||s||o||a)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),e?r.rotateDeltaY+=l:s&&(r.rotateDeltaY-=l),o?r.rotateDeltaX+=l:a&&(r.rotateDeltaX-=l),!i.firstPerson&&i.followPointer&&t.pivotController.startPivot())}if(!n[o.KEY_CTRL]&&!n[o.KEY_ALT]){const e=A._isKeyDownForAction(A.DOLLY_BACKWARDS,n),o=A._isKeyDownForAction(A.DOLLY_FORWARDS,n);if(e||o){const n=h*i.keyboardDollyRate;!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),o?r.dollyDelta-=n:e&&(r.dollyDelta+=n),l&&(s.followPointerDirty=!0,l=!1)}}const c=A._isKeyDownForAction(A.PAN_FORWARDS,n),u=A._isKeyDownForAction(A.PAN_BACKWARDS,n),d=A._isKeyDownForAction(A.PAN_LEFT,n),p=A._isKeyDownForAction(A.PAN_RIGHT,n),f=A._isKeyDownForAction(A.PAN_UP,n),g=A._isKeyDownForAction(A.PAN_DOWN,n),m=(n[o.KEY_ALT]?.3:1)*h*i.keyboardPanRate;(c||u||d||p||f||g)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),g?r.panDeltaY+=m:f&&(r.panDeltaY+=-m),p?r.panDeltaX+=-m:d&&(r.panDeltaX+=m),u?r.panDeltaZ+=m:c&&(r.panDeltaZ+=-m))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const qu=d.vec3();class $u{constructor(e,t,i,s,r){this._scene=e;const o=e.camera,n=t.pickController,a=t.pivotController,l=t.panController;let A=1,h=1,c=null;this._onTick=e.on("tick",(()=>{if(!i.active||!i.pointerEnabled)return;let t="default";if(Math.abs(r.dollyDelta)<.001&&(r.dollyDelta=0),Math.abs(r.rotateDeltaX)<.001&&(r.rotateDeltaX=0),Math.abs(r.rotateDeltaY)<.001&&(r.rotateDeltaY=0),0===r.rotateDeltaX&&0===r.rotateDeltaY||(r.dollyDelta=0),i.followPointer){if(--A<=0&&(A=1,0!==r.dollyDelta)){if(0===r.rotateDeltaY&&0===r.rotateDeltaX&&i.followPointer&&s.followPointerDirty&&(n.pickCursorPos=s.pointerCanvasPos,n.schedulePickSurface=!0,n.update(),n.pickResult&&n.pickResult.worldPos?c=n.pickResult.worldPos:(h=1,c=null),s.followPointerDirty=!1),c){const t=Math.abs(d.lenVec3(d.subVec3(c,e.camera.eye,qu)));h=t/i.dollyProximityThreshold}h{s.mouseover=!0}),o.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{s.mouseover=!1,o.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{td(e,o,s.pointerCanvasPos)}),o.addEventListener("mousedown",this._mouseDownHandler=e=>{i.active&&i.pointerEnabled&&(td(e,o,s.pointerCanvasPos),s.mouseover=!0)}),o.addEventListener("mouseup",this._mouseUpHandler=e=>{i.active&&i.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function td(e,t,i){if(e){const{left:s,top:r}=t.getBoundingClientRect();i[0]=e.clientX-s-window.scrollX,i[1]=e.clientY-r-window.scrollY}else e=window.event,i[0]=e.x,i[1]=e.y;return i}const id=function(e,t){if(e){let i=e.target,s=0,r=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;t[0]=e.pageX-s,t[1]=e.pageY-r}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class sd{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=d.vec2(),l=d.vec2(),A=d.vec2(),h=d.vec2(),c=[],u=this._scene.canvas.canvas;let p=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),u.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!i.active||!i.pointerEnabled)return;t.preventDefault();const r=t.touches,l=t.changedTouches;for(s.touchStartTime=Date.now(),1===r.length&&1===l.length&&(id(r[0],a),i.followPointer&&(o.pickCursorPos=a,o.schedulePickSurface=!0,o.update(),i.planView||(o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(n.setPivotPos(o.pickResult.worldPos),!i.firstPerson&&n.startPivot()&&n.showPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),!i.firstPerson&&n.startPivot()&&n.showPivot()))));c.length{n.getPivoting()&&n.endPivot()}),u.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const n=e.canvas.boundary,a=n[2],u=n[3],g=t.touches;if(t.touches.length===p){if(1===p){id(g[0],l),d.subVec2(l,c[0],h);const t=h[0],o=h[1];if(null!==s.longTouchTimeout&&(Math.abs(t)>i.longTapRadius||Math.abs(o)>i.longTapRadius)&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),i.planView){const s=e.camera;if("perspective"===s.projection){const n=Math.abs(e.camera.eyeLookDist)*Math.tan(s.perspective.fov/2*Math.PI/180);r.panDeltaX+=t*n/u*i.touchPanRate,r.panDeltaY+=o*n/u*i.touchPanRate}else r.panDeltaX+=.5*s.ortho.scale*(t/u)*i.touchPanRate,r.panDeltaY+=.5*s.ortho.scale*(o/u)*i.touchPanRate}else r.rotateDeltaY-=t/a*(1*i.dragRotationRate),r.rotateDeltaX+=o/u*(1.5*i.dragRotationRate)}else if(2===p){const t=g[0],n=g[1];id(t,l),id(n,A);const a=d.geometricMeanVec2(c[0],c[1]),h=d.geometricMeanVec2(l,A),p=d.vec2();d.subVec2(a,h,p);const f=p[0],m=p[1],_=e.camera,v=d.distVec2([t.pageX,t.pageY],[n.pageX,n.pageY]),b=(d.distVec2(c[0],c[1])-v)*i.touchDollyRate;if(r.dollyDelta=b,Math.abs(b)<1)if("perspective"===_.projection){const t=o.pickResult?o.pickResult.worldPos:e.center,s=Math.abs(d.lenVec3(d.subVec3(t,e.camera.eye,[])))*Math.tan(_.perspective.fov/2*Math.PI/180);r.panDeltaX-=f*s/u*i.touchPanRate,r.panDeltaY-=m*s/u*i.touchPanRate}else r.panDeltaX-=.5*_.ortho.scale*(f/u)*i.touchPanRate,r.panDeltaY-=.5*_.ortho.scale*(m/u)*i.touchPanRate;s.pointerCanvasPos=h}for(let e=0;e{let s;i&&i.worldPos&&(s=i.worldPos);const r=i?i.entity.aabb:e.aabb;if(s){const i=e.camera;d.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})};u.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!i.active||!i.pointerEnabled)return;null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null);const r=e.touches,o=e.changedTouches;if(a=Date.now(),1===r.length&&1===o.length){h=a,rd(r[0],A);const o=A[0],n=A[1],l=r[0].pageX,c=r[0].pageY;s.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(c)],canvasPos:[Math.round(o),Math.round(n)],event:e},!0),s.longTouchTimeout=null}),i.longTapTimeout)}else h=-1;for(;l.length{if(!i.active||!i.pointerEnabled)return;const t=Date.now(),r=e.touches,a=e.changedTouches,u=n.hasSubs("pickedSurface");null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),0===r.length&&1===a.length&&h>-1&&t-h<150&&(c>-1&&h-c<325?(rd(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=u,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("doublePicked",o.pickResult),o.pickedSurface&&n.fire("doublePickedSurface",o.pickResult),i.doublePickFlyTo&&p(o.pickResult)):(n.fire("doublePickedNothing"),i.doublePickFlyTo&&p()),c=-1):d.distVec2(l[0],A)<4&&(rd(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=u,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("picked",o.pickResult),o.pickedSurface&&n.fire("pickedSurface",o.pickResult)):n.fire("pickedNothing"),c=t),h=-1),l.length=r.length;for(let e=0,t=r.length;e{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:d.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:d.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const i=this.scene;this._controllers={cameraControl:this,pickController:new Qu(this,this._configs),pivotController:new Nu(i,this._configs),panController:new Su(i),cameraFlight:new qc(this,{duration:.5})},this._handlers=[new ed(this.scene,this._controllers,this._configs,this._states,this._updates),new sd(this.scene,this._controllers,this._configs,this._states,this._updates),new Hu(this.scene,this._controllers,this._configs,this._states,this._updates),new Ju(this.scene,this._controllers,this._configs,this._states,this._updates),new Yu(this.scene,this._controllers,this._configs,this._states,this._updates),new od(this.scene,this._controllers,this._configs,this._states,this._updates),new Zu(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new $u(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",y.isString(e)){const t=this.scene.input,i={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":i[this.PAN_LEFT]=[t.KEY_A],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_Z],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":i[this.PAN_LEFT]=[t.KEY_Q],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_W],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=i}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const i=this._keyMap[e];if(!i)return!1;t||(t=this.scene.input.keyDown);for(let e=0,s=i.length;e0?ud(t):null,n=i&&i.length>0?ud(i):null,a=e=>{if(!e)return;var t=!0;(n&&n[e.type]||o&&!o[e.type])&&(t=!1),t&&s.push(e.id);const i=e.children;if(i)for(var r=0,l=i.length;r>t;i.sort($h);const s=new Int32Array(e.length);for(let t=0,r=i.length;te[t+1]){let i=e[t];e[t]=e[t+1],e[t+1]=i}ec=new Int32Array(e),t.sort(tc);const i=new Int32Array(e.length);for(let s=0,r=t.length;st){let i=e;e=t,t=i}function i(i,s){return i!==e?e-i:s!==t?t-s:0}let s=0,r=(o.length>>1)-1;for(;s<=r;){const e=r+s>>1,t=i(o[2*e],o[2*e+1]);if(t>0)s=e+1;else{if(!(t<0))return e;r=e-1}}return-s-1}const a=new Int32Array(o.length/2);a.fill(0);const l=s.length/3;if(l>8*(1<u.maxNumPositions&&(u=c()),u.bucketNumber>8)return[e];let p;-1===A[l]&&(A[l]=u.numPositions++,u.positionsCompressed.push(s[3*l]),u.positionsCompressed.push(s[3*l+1]),u.positionsCompressed.push(s[3*l+2])),-1===A[h]&&(A[h]=u.numPositions++,u.positionsCompressed.push(s[3*h]),u.positionsCompressed.push(s[3*h+1]),u.positionsCompressed.push(s[3*h+2])),-1===A[d]&&(A[d]=u.numPositions++,u.positionsCompressed.push(s[3*d]),u.positionsCompressed.push(s[3*d+1]),u.positionsCompressed.push(s[3*d+2])),u.indices.push(A[l]),u.indices.push(A[h]),u.indices.push(A[d]),(p=n(l,h))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(l,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(h,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]]))}const d=t/8*2,p=t/8,f=2*s.length+(r.length+o.length)*d;let g=0,m=-s.length/3;return h.forEach((e=>{g+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*p,m+=e.positionsCompressed.length/3})),g>f?[e]:(i&&function(e,t){const i={},s={};let r=0;e.forEach((e=>{const t=e.indices,o=e.edgeIndices,n=e.positionsCompressed;for(let e=0,s=t.length;e0){const e=t._meshes;for(let t=0,i=e.length;t0){const e=this._meshes;for(let t=0,i=e.length;t{this._viewMatrixDirty=!0})),this._meshesWithDirtyMatrices=[],this._numMeshesWithDirtyMatrices=0,this._onTick=this.scene.on("tick",(()=>{for(;this._numMeshesWithDirtyMatrices>0;)this._meshesWithDirtyMatrices[--this._numMeshesWithDirtyMatrices]._updateMatrix()})),this._createDefaultTextureSet(),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.backfaces=t.backfaces}_meshMatrixDirty(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}_createDefaultTextureSet(){const e=new Uh({id:"defaultColorTexture",texture:new Vr({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Uh({id:"defaultMetalRoughTexture",texture:new Vr({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),i=new Uh({id:"defaultNormalsTexture",texture:new Vr({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),s=new Uh({id:"defaultEmissiveTexture",texture:new Vr({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),r=new Uh({id:"defaultOcclusionTexture",texture:new Vr({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=i,this._textures.defaultEmissiveTexture=s,this._textures.defaultOcclusionTexture=r,this._textureSets.defaultTextureSet=new Lh({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:i,emissiveTexture:s,occlusionTexture:r})}get isPerformanceModel(){return!0}get transforms(){return this._transforms}get textures(){return this._textures}get textureSets(){return this._textureSets}get meshes(){return this._meshes}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),d.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),d.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||mc),d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),d.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),d.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),d.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),d.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0,this._aabbDirty=!0}_transformDirty(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}_sceneModelDirty(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(let e=0,t=this._entityList.length;e0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,i=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,i=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,i=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,i=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,i=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,i=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,i=new Uint8Array(t.length);for(let e=0,s=t.length;e{l.setImage(A,{minFilter:i,magFilter:s,wrapS:r,wrapT:o,wrapR:n,flipY:e.flipY,encoding:a}),this.glRedraw()},A.src=e.src;break;default:this._textureTranscoder?y.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new Uh({id:t,texture:l})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let i,s,r,o,n;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(i=this._textures[e.colorTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(s=this._textures[e.metallicRoughnessTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(r=this._textures[e.normalsTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(o=this._textures[e.emissiveTextureId],!o)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else o=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(n=this._textures[e.occlusionTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultOcclusionTexture;const a=new Lh({id:t,model:this,colorTexture:i,metallicRoughnessTexture:s,normalsTexture:r,emissiveTexture:o,occlusionTexture:n});return this._textureSets[t]=a,a}createTransform(e){if(void 0===e.id||null===e.id)return void this.error("[createTransform] SceneModel.createTransform() config missing: id");if(this._transforms[e.id])return void this.error(`[createTransform] SceneModel already has a transform with this ID: ${e.id}`);let t;if(e.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const i=new hc({id:e.id,model:this,parent:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[i.id]=i,i}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._meshes[e.id])return this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`),!1;if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!(e.buckets||e.indices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)){const t=(e.positions||e.positionsCompressed).length/3;e.indices=this._createDefaultIndices(t)}if(!e.buckets&&!e.indices&&"points"!==e.primitive)return e.indices=this._createDefaultIndices(numIndices),this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;const t=!(!this._dtxEnabled||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||e.textureSetId);if(e.origin=e.origin?d.addVec3(this._origin,e.origin,d.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){const t=e.scale||dc,i=e.position||pc,s=e.rotation||fc;d.eulerToQuaternion(s,"XYZ",gc),e.meshMatrix=d.composeMat4(i,gc,t,d.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=hn(e.positionsDecodeBoundary,d.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):_c,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=d.vec3(),i=[];J(e.positions,i,t)&&(e.positions=i,e.origin=d.addVec3(e.origin,t,t))}if(e.positions){const t=d.collapseAABB3();e.positionsDecodeMatrix=d.mat4(),d.expandAABB3Points3(t,e.positions),e.positionsCompressed=An(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=d.collapseAABB3();d.expandAABB3Points3(t,e.positionsCompressed),Vt.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=d.collapseAABB3();for(let i=0,s=e.buckets.length;i>24&255,r=i>>16&255,o=i>>8&255,n=255&i;switch(e.pickColor=new Uint8Array([n,o,r,s]),e.solid="solid"===e.primitive,t.origin=d.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),this._meshes[e.id]=t,this._unusedMeshes[e.id]=t,this._meshList.push(t),t}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let i=0,s=e.buckets.length;i>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,i=e.origin,s=e.textureSetId||"-",r=e.geometryId,o=`${Math.round(i[0])}.${Math.round(i[1])}.${Math.round(i[2])}.${s}.${r}`;let n=this._vboInstancingLayers[o];if(n)return n;let a=e.textureSet;const l=e.geometry;for(;!n;)switch(l.primitive){case"triangles":case"surface":n=new pa({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!1});break;case"solid":n=new pa({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!0});break;case"lines":n=new $a({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0});break;case"points":n=new Wl({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0})}return this._vboInstancingLayers[o]=n,this.layerList.push(n),n}createEntity(e){if(void 0===e.id?e.id=d.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=d.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;this._visible&&!1!==e.visible&&(t|=q),this._pickable&&!1!==e.pickable&&(t|=ee),this._culled&&!1!==e.culled&&(t|=$),this._clippable&&!1!==e.clippable&&(t|=te),this._collidable&&!1!==e.collidable&&(t|=ie),this._edges&&!1!==e.edges&&(t|=ne),this._xrayed&&!1!==e.xrayed&&(t|=se),this._highlighted&&!1!==e.highlighted&&(t|=re),this._selected&&!1!==e.selected&&(t|=oe),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let i=0,s=e.meshIds.length;ie.sortIdt.sortId?1:0));for(let e=0,t=this.layerList.length;e0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,i=this.layerList.length;t0){const t=`${this.id}-dummyEntityForUnusedMeshes`;this.warn(`Creating dummy SceneModelEntity "${t}" for unused SceneMeshes: [${e.join(",")}]`),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}_getActiveSectionPlanesForLayer(e){const t=this.renderFlags,i=this.scene._sectionPlanesState.sectionPlanes,s=i.length,r=e.layerIndex*s;if(s>0)for(let e=0;e0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}drawColorOpaque(e){const t=this.renderFlags;for(let i=0,s=t.visibleLayers.length;i65536?16:8)}else n=[{positionsCompressed:s,indices:r,edgeIndices:o}];return n}class yc extends R{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;ep.has(e.id)||g.has(e.id)||f.has(e.id))).reduce(((e,i)=>{let s,r=function(e){let t="";return t+=Math.round(255*e[0]).toString(16).padStart(2,"0"),t+=Math.round(255*e[1]).toString(16).padStart(2,"0"),t+=Math.round(255*e[2]).toString(16).padStart(2,"0"),t}(i.colorize);i.xrayed?(s=0===t.xrayMaterial.fillAlpha&&0!==t.xrayMaterial.edgeAlpha?.1:t.xrayMaterial.fillAlpha,s=Math.round(255*s).toString(16).padStart(2,"0"),r=s+r):p.has(i.id)&&(s=Math.round(255*i.opacity).toString(16).padStart(2,"0"),r=s+r),e[r]||(e[r]=[]);const o=i.id,n=i.originalSystemId,a={ifc_guid:n,originating_system:this.originatingSystem};return n!==o&&(a.authoring_tool_id=o),e[r].push(a),e}),{}),_=Object.entries(m).map((([e,t])=>({color:e,components:t})));o.components.coloring=_;const v=t.objectIds,b=t.visibleObjects,y=t.visibleObjectIds,B=v.filter((e=>!b[e])),w=t.selectedObjectIds;return e.defaultInvisible||y.length0&&e.clipping_planes.forEach((function(e){let t=Fc(e.location,Bc),i=Fc(e.direction,Bc);A&&d.negateVec3(i),d.subVec3(t,l),r.yUp&&(t=Ic(t),i=Ic(i)),new yr(s,{pos:t,dir:i})})),s.clearLines(),e.lines&&e.lines.length>0){const t=[],i=[];let r=0;e.lines.forEach((e=>{e.start_point&&e.end_point&&(t.push(e.start_point.x),t.push(e.start_point.y),t.push(e.start_point.z),t.push(e.end_point.x),t.push(e.end_point.y),t.push(e.end_point.z),i.push(r++),i.push(r++))})),new yc(s,{positions:t,indices:i,clippable:!1,collidable:!0})}if(s.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){const t=e.bitmap_type||"jpg",i=e.bitmap_data;let o=Fc(e.location,wc),n=Fc(e.normal,xc),a=Fc(e.up,Pc),l=e.height||1;t&&i&&o&&n&&a&&(r.yUp&&(o=Ic(o),n=Ic(n),a=Ic(a)),new lo(s,{src:i,type:t,pos:o,normal:n,up:a,clippable:!1,collidable:!0,height:l}))})),a&&(s.setObjectsXRayed(s.xrayedObjectIds,!1),s.setObjectsHighlighted(s.highlightedObjectIds,!1),s.setObjectsSelected(s.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(s.setObjectsVisible(s.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!1))))):(s.setObjectsVisible(s.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!0)))));const r=e.components.visibility.view_setup_hints;r&&(!1===r.spaces_visible&&s.setObjectsVisible(i.metaScene.getObjectIDsByType("IfcSpace"),!1),void 0!==r.spaces_translucent&&s.setObjectsXRayed(i.metaScene.getObjectIDsByType("IfcSpace"),!0),r.space_boundaries_visible,!1===r.openings_visible&&s.setObjectsVisible(i.metaScene.getObjectIDsByType("IfcOpening"),!0),r.space_boundaries_translucent,void 0!==r.openings_translucent&&s.setObjectsXRayed(i.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(s.setObjectsSelected(s.selectedObjectIds,!1),e.components.selection.forEach((e=>this._withBCFComponent(t,e,(e=>e.selected=!0))))),e.components.translucency&&(s.setObjectsXRayed(s.xrayedObjectIds,!1),e.components.translucency.forEach((e=>this._withBCFComponent(t,e,(e=>e.xrayed=!0))))),e.components.coloring&&e.components.coloring.forEach((e=>{let i=e.color,s=0,r=!1;8===i.length&&(s=parseInt(i.substring(0,2),16)/256,s<=1&&s>=.95&&(s=1),i=i.substring(2),r=!0);const o=[parseInt(i.substring(0,2),16)/256,parseInt(i.substring(2,4),16)/256,parseInt(i.substring(4,6),16)/256];e.components.map((e=>this._withBCFComponent(t,e,(e=>{e.colorize=o,r&&(e.opacity=s)}))))}))}if(e.perspective_camera||e.orthogonal_camera){let a,A,h,c;if(e.perspective_camera?(a=Fc(e.perspective_camera.camera_view_point,Bc),A=Fc(e.perspective_camera.camera_direction,Bc),h=Fc(e.perspective_camera.camera_up_vector,Bc),r.perspective.fov=e.perspective_camera.field_of_view,c="perspective"):(a=Fc(e.orthogonal_camera.camera_view_point,Bc),A=Fc(e.orthogonal_camera.camera_direction,Bc),h=Fc(e.orthogonal_camera.camera_up_vector,Bc),r.ortho.scale=e.orthogonal_camera.view_to_world_scale,c="ortho"),d.subVec3(a,l),r.yUp&&(a=Ic(a),A=Ic(A),h=Ic(h)),o){const e=s.pick({pickSurface:!0,origin:a,direction:A});A=e?e.worldPos:d.addVec3(a,A,Bc)}else A=d.addVec3(a,A,Bc);n?(r.eye=a,r.look=A,r.up=h,r.projection=c):i.cameraFlight.flyTo({eye:a,look:A,up:h,duration:t.duration,projection:c})}}_withBCFComponent(e,t,i){const s=this.viewer,r=s.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){const o=t.authoring_tool_id,n=r.objects[o];if(n)return void i(n);if(e.updateCompositeObjects){if(s.metaScene.metaObjects[o])return void r.withObjects(s.metaScene.getObjectIDsInSubtree(o),i)}}if(t.ifc_guid){const o=t.ifc_guid,n=r.objects[o];if(n)return void i(n);if(e.updateCompositeObjects){if(s.metaScene.metaObjects[o])return void r.withObjects(s.metaScene.getObjectIDsInSubtree(o),i)}Object.keys(r.models).forEach((t=>{const n=d.globalizeObjectId(t,o),a=r.objects[n];if(a)i(a);else if(e.updateCompositeObjects){s.metaScene.metaObjects[n]&&r.withObjects(s.metaScene.getObjectIDsInSubtree(n),i)}}))}}destroy(){super.destroy()}}function Mc(e){return{x:e[0],y:e[1],z:e[2]}}function Fc(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function Ec(e){return new Float64Array([e[0],-e[2],e[1]])}function Ic(e){return new Float64Array([e[0],e[2],-e[1]])}const Dc=d.vec3(),Sc=(e,t,i,s)=>{var r=e-i,o=t-s;return Math.sqrt(r*r+o*o)};class Tc extends R{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._eventSubs={};var i=this.plugin.viewer.scene;this._originMarker=new ue(i,t.origin),this._targetMarker=new ue(i,t.target),this._originWorld=d.vec3(),this._targetWorld=d.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;const s=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,r=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},n=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,A=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new pe(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._targetDot=new pe(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthWire=new de(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisWire=new de(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisWire=new de(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisWire=new de(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthLabel=new fe(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisLabel=new fe(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisLabel=new fe(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisLabel=new fe(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._sectionPlanesDirty=!0,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,this._labelsVisible=!1,this._labelsOnWires=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.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=i.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=i.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=i.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=i.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=i.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=i.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=i.on("sectionPlaneUpdated",(()=>{this._sectionPlanesDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.labelsVisible=t.labelsVisible,this.labelsOnWires=t.labelsOnWires}_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._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(d.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._originWorld)||this._isSliced(this._targetWorld))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}const t=this._originMarker.viewPos[2],i=this._targetMarker.viewPos[2];if(t>-.3||i>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){d.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var s=this._pp,r=this._cp,o=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var n=o.top-t.top,a=o.left-t.left,l=e.canvas.boundary,A=l[2],h=l[3],c=0;const i=this.plugin.viewer.scene.metrics,f=i.scale,g=i.units,m=i.unitsInfo[g].abbrev;for(var u=0,p=s.length;ue.offsetTop+(e.offsetParent&&e.offsetParent!==s.parentNode&&h(e.offsetParent)),c=e=>e.offsetLeft+(e.offsetParent&&e.offsetParent!==s.parentNode&&c(e.offsetParent)),u=d.vec2();this._onCameraControlHoverSnapOrSurface=i.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(e=>{const t=e.snappedCanvasPos||e.canvasPos;r=!0,o.set(e.worldPos),n.set(e.canvasPos),0===this._mouseState?(this._canvasToPagePos?(this._canvasToPagePos(s,t,u),this._markerDiv.style.left=u[0]-5+"px",this._markerDiv.style.top=u[1]-5+"px"):(this._markerDiv.style.left=c(s)+t[0]-5+"px",this._markerDiv.style.top=h(s)+t[1]-5+"px"),this._markerDiv.style.background="pink",e.snappedToVertex||e.snappedToEdge?(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos,this.pointerLens.snapped=!0),this._markerDiv.style.background="greenyellow",this._markerDiv.style.border="2px solid green"):(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.canvasPos,this.pointerLens.snapped=!1),this._markerDiv.style.background="pink",this._markerDiv.style.border="2px solid red"),A=e.entity):(this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px"),s.style.cursor="pointer",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=this._currentDistanceMeasurementInitState.wireVisible,this._currentDistanceMeasurement.axisVisible=this._currentDistanceMeasurementInitState.axisVisible&&this.distanceMeasurementsPlugin.defaultAxisVisible,this._currentDistanceMeasurement.xAxisVisible=this._currentDistanceMeasurementInitState.xAxisVisible&&this.distanceMeasurementsPlugin.defaultXAxisVisible,this._currentDistanceMeasurement.yAxisVisible=this._currentDistanceMeasurementInitState.yAxisVisible&&this.distanceMeasurementsPlugin.defaultYAxisVisible,this._currentDistanceMeasurement.zAxisVisible=this._currentDistanceMeasurementInitState.zAxisVisible&&this.distanceMeasurementsPlugin.defaultZAxisVisible,this._currentDistanceMeasurement.targetVisible=this._currentDistanceMeasurementInitState.targetVisible,this._currentDistanceMeasurement.target.worldPos=o.slice(),this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px")})),s.addEventListener("mousedown",this._onMouseDown=e=>{1===e.which&&(a=e.clientX,l=e.clientY)}),s.addEventListener("mouseup",this._onMouseUp=t=>{1===t.which&&(t.clientX>a+20||t.clientXl+20||t.clientY{this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos),r=!1,this._markerDiv.style.left="-100px",this._markerDiv.style.top="-100px",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.axisVisible=!1),s.style.cursor="default"})),this._active=!0}deactivate(){if(!this._active)return;this.fire("activated",!1),this.pointerLens&&(this.pointerLens.visible=!1),this._markerDiv&&this._destroyMarkerDiv(),this.reset();const e=this.scene.canvas.canvas;e.removeEventListener("mousedown",this._onMouseDown),e.removeEventListener("mouseup",this._onMouseUp);const t=this.distanceMeasurementsPlugin.viewer.cameraControl;t.off(this._onCameraControlHoverSnapOrSurface),t.off(this._onCameraControlHoverSnapOrSurfaceOff),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null),this._active=!1}reset(){this._active&&(this._destroyMarkerDiv(),this._initMarkerDiv(),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null))}destroy(){this.deactivate(),super.destroy()}}class Uc extends z{constructor(e,t={}){super("DistanceMeasurements",e),this._pointerLens=t.pointerLens,this._container=t.container||document.body,this._defaultControl=null,this._measurements={},this.labelMinAxisLength=t.labelMinAxisLength,this.defaultVisible=!1!==t.defaultVisible,this.defaultOriginVisible=!1!==t.defaultOriginVisible,this.defaultTargetVisible=!1!==t.defaultTargetVisible,this.defaultWireVisible=!1!==t.defaultWireVisible,this.defaultLabelsVisible=!1!==t.defaultLabelsVisible,this.defaultAxisVisible=!1!==t.defaultAxisVisible,this.defaultXAxisVisible=!1!==t.defaultXAxisVisible,this.defaultYAxisVisible=!1!==t.defaultYAxisVisible,this.defaultZAxisVisible=!1!==t.defaultZAxisVisible,this.defaultColor=void 0!==t.defaultColor?t.defaultColor:"#00BBFF",this.zIndex=t.zIndex||1e4,this.defaultLabelsOnWires=!1!==t.defaultLabelsOnWires,this._onMouseOver=(e,t)=>{this.fire("mouseOver",{plugin:this,distanceMeasurement:t,measurement:t,event:e})},this._onMouseLeave=(e,t)=>{this.fire("mouseLeave",{plugin:this,distanceMeasurement:t,measurement:t,event:e})},this._onContextMenu=(e,t)=>{this.fire("contextMenu",{plugin:this,distanceMeasurement:t,measurement:t,event:e})}}getContainerElement(){return this._container}send(e,t){}get pointerLens(){return this._pointerLens}get control(){return this._defaultControl||(this._defaultControl=new Lc(this,{})),this._defaultControl}get measurements(){return this._measurements}set labelMinAxisLength(e){e<1&&(this.error("labelMinAxisLength must be >= 1; defaulting to 25"),e=25),this._labelMinAxisLength=e||25}get labelMinAxisLength(){return this._labelMinAxisLength}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,i=e.target,s=new Tc(this,{id:e.id,plugin:this,container:this._container,origin:{entity:t.entity,worldPos:t.worldPos},target:{entity:i.entity,worldPos:i.worldPos},visible:e.visible,wireVisible:e.wireVisible,axisVisible:!1!==e.axisVisible&&!1!==this.defaultAxisVisible,xAxisVisible:!1!==e.xAxisVisible&&!1!==this.defaultXAxisVisible,yAxisVisible:!1!==e.yAxisVisible&&!1!==this.defaultYAxisVisible,zAxisVisible:!1!==e.zAxisVisible&&!1!==this.defaultZAxisVisible,labelsVisible:!1!==e.labelsVisible&&!1!==this.defaultLabelsVisible,originVisible:e.originVisible,targetVisible:e.targetVisible,color:e.color,labelsOnWires:!1!==e.labelsOnWires&&!1!==this.defaultLabelsOnWires,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[s.id]=s,s.on("destroyed",(()=>{delete this._measurements[s.id]})),this.fire("measurementCreated",s),s}destroyMeasurement(e){const t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("DistanceMeasurement not found: "+e)}setLabelsShown(e){for(const[t,i]of Object.entries(this.measurements))i.labelShown=e}setAxisVisible(e){for(const[t,i]of Object.entries(this.measurements))i.axisVisible=e;this.defaultAxisVisible=e}getAxisVisible(){return this.defaultAxisVisible}clear(){const e=Object.keys(this._measurements);for(var t=0,i=e.length;t{this.plugin.viewer.cameraControl.active=!1},c=()=>{this.plugin.viewer.cameraControl.active=!0},u=()=>{o&&(clearTimeout(o),o=null),this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null),c(),this._touchState=0};i.addEventListener("touchstart",this._onCanvasTouchStart=i=>{const l=i.touches.length;if(1!==l)return void(o&&(clearTimeout(o),o=null));const c=i.touches[0],p=c.clientX,f=c.clientY;switch(n.set([p,f]),a.set([p,f]),this._touchState){case 0:if(1!==l&&null!==o)return void u();const i=t.pick({canvasPos:a,snapping:this._snapping,snapToEdge:this._snapping});if(i&&i.snapped)s.set(i.worldPos),this.pointerCircle.start(i.snappedCanvasPos);else{const e=t.pick({canvasPos:a,pickSurface:!0});if(!e||!e.worldPos)return;s.set(e.worldPos),this.pointerCircle.start(e.canvasPos)}o=setTimeout((()=>{1!==l||a[0]>n[0]+r||a[0]n[1]+r||a[1]{if(o=null,1!==l||a[0]>n[0]+r||a[0]n[1]+r||a[1]{this.pointerCircle.stop();const r=i.touches.length;if(1!==r||1!==i.changedTouches.length)return void(o&&(clearTimeout(o),o=null));const n=i.touches[0],l=n.clientX,h=n.clientY;if(n.identifier!==A)return;let c,u;switch(a.set([l,h]),this._touchState){case 2:this.pointerLens&&(this.pointerLens.canvasPos=a),c=t.pick({canvasPos:a,snapToVertex:this._snapping,snapToEdge:this._snapping}),c&&c.snapped?(this.pointerLens&&(this.pointerLens.snappedCanvasPos=c.snappedCanvasPos,this.pointerLens.snapped=!0),s.set(c.worldPos),this._currentDistanceMeasurement?this._currentDistanceMeasurement.origin.worldPos=c.worldPos:(this._currentDistanceMeasurement=e.createMeasurement({id:d.createUUID(),origin:{worldPos:c.worldPos,entity:c.entity},target:{worldPos:c.worldPos,entity:c.entity}}),this._currentDistanceMeasurement.labelsVisible=!1,this._currentDistanceMeasurement.xAxisVisible=!1,this._currentDistanceMeasurement.yAxisVisible=!1,this._currentDistanceMeasurement.zAxisVisible=!1,this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.originVisible=!0,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.clickable=!1),this.distanceMeasurementsPlugin.fire("measurementStart",this._currentDistanceMeasurement)):(u=t.pick({canvasPos:a,pickSurface:!0}),u&&u.worldPos?(this.pointerLens&&(this.pointerLens.cursorPos=u.canvasPos,this.pointerLens.snapped=!1),s.set(u.worldPos),this._currentDistanceMeasurement?this._currentDistanceMeasurement.origin.worldPos=u.worldPos:(this._currentDistanceMeasurement=e.createMeasurement({id:d.createUUID(),origin:{worldPos:u.worldPos,entity:u.entity},target:{worldPos:u.worldPos,entity:u.entity}}),this._currentDistanceMeasurement.labelsVisible=!1,this._currentDistanceMeasurement.xAxisVisible=!1,this._currentDistanceMeasurement.yAxisVisible=!1,this._currentDistanceMeasurement.zAxisVisible=!1,this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.originVisible=!0,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.clickable=!1),this.distanceMeasurementsPlugin.fire("measurementStart",this._currentDistanceMeasurement)):this.pointerLens&&(this.pointerLens.cursorPos=null,this.pointerLens.snapped=!1)),this._touchState=2;break;case 5:if(1!==r&&null!==o)return clearTimeout(o),o=null,this.pointerLens&&(this.pointerLens.visible=!1),void(this._touchState=7);this.pointerLens&&(this.pointerLens.canvasPos=a),c=t.pick({canvasPos:a,snapToVertex:this._snapping,snapToEdge:this._snapping}),c&&c.worldPos?(this.pointerLens&&(this.pointerLens.cursorPos=c.snappedCanvasPos,this.pointerLens.snapped=!0),this._currentDistanceMeasurement.target.worldPos=c.worldPos,this._currentDistanceMeasurement.target.entity=c.entity,this._currentDistanceMeasurement.targetVisible=!0,this._currentDistanceMeasurement.wireVisible=!0,this._currentDistanceMeasurement.labelsVisible=!0):(u=t.pick({canvasPos:a,pickSurface:!0}),u&&u.worldPos&&(this.pointerLens&&(this.pointerLens.cursorPos=u.canvasPos,this.pointerLens.snapped=!1),this._currentDistanceMeasurement.target.worldPos=u.worldPos,this._currentDistanceMeasurement.target.entity=u.entity,this._currentDistanceMeasurement.targetVisible=!0,this._currentDistanceMeasurement.wireVisible=!0,this._currentDistanceMeasurement.labelsVisible=!0)),this._touchState=5}}),{passive:!0}),i.addEventListener("touchend",this._onCanvasTouchEnd=i=>{this.pointerCircle.stop();const s=i.changedTouches.length;if(1!==s)return;const h=i.changedTouches[0],u=h.clientX,p=h.clientY;if(h.identifier===A)switch(o&&(clearTimeout(o),o=null),l.set([u,p]),this._touchState){case 1:{if(1!==s||u>n[0]+r||un[1]+r||pn[0]+r||un[1]+r||p{i=1e3*this._delayBeforeRestoreSeconds,s||(e.scene._renderer.setColorTextureEnabled(!this._hideColorTexture),e.scene._renderer.setPBREnabled(!this._hidePBR),e.scene._renderer.setSAOEnabled(!this._hideSAO),e.scene._renderer.setTransparentEnabled(!this._hideTransparentObjects),e.scene._renderer.setEdgesEnabled(!this._hideEdges),this._scaleCanvasResolution?e.scene.canvas.resolutionScale=this._scaleCanvasResolutionFactor:e.scene.canvas.resolutionScale=this._defaultScaleCanvasResolutionFactor,s=!0)},o=()=>{e.scene.canvas.resolutionScale=this._defaultScaleCanvasResolutionFactor,e.scene._renderer.setEdgesEnabled(!0),e.scene._renderer.setColorTextureEnabled(!0),e.scene._renderer.setPBREnabled(!0),e.scene._renderer.setSAOEnabled(!0),e.scene._renderer.setTransparentEnabled(!0),s=!1};this._onCanvasBoundary=e.scene.canvas.on("boundary",r),this._onCameraMatrix=e.scene.camera.on("matrix",r),this._onSceneTick=e.scene.on("tick",(e=>{s&&(i-=e.deltaTime,(!this._delayBeforeRestore||i<=0)&&o())}));let n=!1;this._onSceneMouseDown=e.scene.input.on("mousedown",(()=>{n=!0})),this._onSceneMouseUp=e.scene.input.on("mouseup",(()=>{n=!1})),this._onSceneMouseMove=e.scene.input.on("mousemove",(()=>{n&&r()}))}get hideColorTexture(){return this._hideColorTexture}set hideColorTexture(e){this._hideColorTexture=e}get hidePBR(){return this._hidePBR}set hidePBR(e){this._hidePBR=e}get hideSAO(){return this._hideSAO}set hideSAO(e){this._hideSAO=e}get hideEdges(){return this._hideEdges}set hideEdges(e){this._hideEdges=e}get hideTransparentObjects(){return this._hideTransparentObjects}set hideTransparentObjects(e){this._hideTransparentObjects=!1!==e}get scaleCanvasResolution(){return this._scaleCanvasResolution}set scaleCanvasResolution(e){this._scaleCanvasResolution=e}get defaultScaleCanvasResolutionFactor(){return this._defaultScaleCanvasResolutionFactor}set defaultScaleCanvasResolutionFactor(e){this._defaultScaleCanvasResolutionFactor=e||1}get scaleCanvasResolutionFactor(){return this._scaleCanvasResolutionFactor}set scaleCanvasResolutionFactor(e){this._scaleCanvasResolutionFactor=e||.6}get delayBeforeRestore(){return this._delayBeforeRestore}set delayBeforeRestore(e){this._delayBeforeRestore=e}get delayBeforeRestoreSeconds(){return this._delayBeforeRestoreSeconds}set delayBeforeRestoreSeconds(e){this._delayBeforeRestoreSeconds=null!=e?e:.5}send(e,t){}destroy(){this.viewer.scene.camera.off(this._onCameraMatrix),this.viewer.scene.canvas.off(this._onCanvasBoundary),this.viewer.scene.input.off(this._onSceneMouseDown),this.viewer.scene.input.off(this._onSceneMouseUp),this.viewer.scene.input.off(this._onSceneMouseMove),this.viewer.scene.off(this._onSceneTick),super.destroy()}}class Nc{constructor(){}getMetaModel(e,t,i){y.loadJSON(e,(e=>{t(e)}),(function(e){i(e)}))}getGLTF(e,t,i){y.loadArraybuffer(e,(e=>{t(e)}),(function(e){i(e)}))}getGLB(e,t,i){y.loadArraybuffer(e,(e=>{t(e)}),(function(e){i(e)}))}getArrayBuffer(e,t,i,s){!function(e,t,i,s){var r=()=>{};i=i||r,s=s||r;const o=/^data:(.*?)(;base64)?,(.*)$/,n=t.match(o);if(n){const e=!!n[2];var a=n[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),t=new Uint8Array(e);for(var l=0;l{i(e)}),(function(e){s(e)}))}}class Qc{constructor(e={}){this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=e.messages,this.locale=e.locale}set messages(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}loadMessages(e={}){for(let t in e)this._messages[t]=e[t];this.messages=this._messages}clearMessages(){this.messages={}}get locales(){return this._locales}set locale(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}get locale(){return this._locale}translate(e,t){const i=this._messages[this._locale];if(!i)return null;const s=Vc(e,i);return s?t?Hc(s,t):s:null}translatePlurals(e,t,i){const s=this._messages[this._locale];if(!s)return null;let r=Vc(e,s);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=Hc(r,[t]),i&&(r=Hc(r,i)),r):null}fire(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);const s=this._eventSubs[e];if(s)for(const e in s)if(s.hasOwnProperty(e)){s[e].callback(t)}}on(t,i){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let s=this._eventSubs[t];s||(s={},this._eventSubs[t]=s);const r=this._eventSubIDMap.addItem();s[r]={callback:i},this._eventSubEvents[r]=t;const o=this._events[t];return void 0!==o&&i(o),r}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}function Vc(e,t){if(t[e])return t[e];const i=e.split(".");let s=t;for(let e=0,t=i.length;s&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,s=e+t;i<0&&(i=0),s>1&&(s=1);var r=this.getPoint(i),o=this.getPoint(s),n=d.subVec3(o,r,[]);return d.normalizeVec3(n,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,s=[],r=this.getPoint(0),o=0;for(s.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),o+=d.lenVec3(d.subVec3(t,r,[])),s.push(o),r=t;return this.cacheArcLengths=s,s}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var i,s=this._getLengths(),r=0,o=s.length;i=t||e*s[o-1];for(var n,a=0,l=o-1;a<=l;)if((n=s[r=Math.floor(a+(l-a)/2)]-i)<0)a=r+1;else{if(!(n>0)){l=r;break}l=r-1}if(s[r=l]===i)return r/(o-1);var A=s[r];return(r+(i-A)/(s[r+1]-A))/(o-1)}}class Gc extends jc{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,s=Math.floor(i),r=i-s,o=t[0===s?s:s-1],n=t[s],a=t[s>t.length-2?t.length-1:s+1],l=t[s>t.length-3?t.length-1:s+2],A=d.vec3();return A[0]=d.catmullRomInterpolate(o[0],n[0],a[0],l[0],r),A[1]=d.catmullRomInterpolate(o[1],n[1],a[1],l[1],r),A[2]=d.catmullRomInterpolate(o[2],n[2],a[2],l[2],r),A}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const zc=d.vec3();class Wc extends R{get type(){return"CameraPath"}constructor(e,t={}){super(e,t),this._frames=[],this._eyeCurve=new Gc(this),this._lookCurve=new Gc(this),this._upCurve=new Gc(this),t.frames&&(this.addFrames(t.frames),this.smoothFrameTimes(1))}get frames(){return this._frames}get eyeCurve(){return this._eyeCurve}get lookCurve(){return this._lookCurve}get upCurve(){return this._upCurve}saveFrame(e){const t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}addFrame(e,t,i,s){const r={t:e,eye:t.slice(0),look:i.slice(0),up:s.slice(0)};this._frames.push(r),this._eyeCurve.points.push(r.eye),this._lookCurve.points.push(r.look),this._upCurve.points.push(r.up)}addFrames(e){let t;for(let i=0,s=e.length;i1?1:e,t.eye=this._eyeCurve.getPoint(e,zc),t.look=this._lookCurve.getPoint(e,zc),t.up=this._upCurve.getPoint(e,zc)}sampleFrame(e,t,i,s){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,i),this._upCurve.getPoint(e,s)}smoothFrameTimes(e){if(0===this._frames.length)return;const t=d.vec3();var i=0;this._frames[0].t=0;const s=[];for(let e=1,o=this._frames.length;e=1;e>1&&(e=1);const i=this.easing?qc._ease(e,0,1,1):e,s=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(d.subVec3(s.eye,s.look,Zc),s.eye=d.lerpVec3(i,0,1,this._eye1,this._eye2,Jc),s.look=d.subVec3(Jc,Zc,Xc)):this._flyingLook&&(s.look=d.lerpVec3(i,0,1,this._look1,this._look2,Xc),s.up=d.lerpVec3(i,0,1,this._up1,this._up2,Yc)):this._flyingEyeLookUp&&(s.eye=d.lerpVec3(i,0,1,this._eye1,this._eye2,Jc),s.look=d.lerpVec3(i,0,1,this._look1,this._look2,Xc),s.up=d.lerpVec3(i,0,1,this._up1,this._up2,Yc)),this._projection2){const t="ortho"===this._projection2?qc._easeOutExpo(e,0,1,1):qc._easeInCubic(e,0,1,1);s.customProjection.matrix=d.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else s.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return s.ortho.scale=this._orthoScale2,void this.stop();I.scheduleTask(this._update,this)}static _ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}static _easeInCubic(e,t,i,s){return i*(e/=s)*e*e+t}static _easeOutExpo(e,t,i,s){return i*(1-Math.pow(2,-10*e/s))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class $c extends R{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new qc(this),this._t=0,this.state=$c.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,i;const s=performance.now(),r=this._lastTime?.001*(s-this._lastTime):0;if(this._lastTime=s,0!==r)switch(this.state){case $c.SCRUBBING:return;case $c.PLAYING:if(this._t+=this._playingRate*r,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=$c.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case $c.PLAYING_TO:i=this._t+this._playingRate*r*this._playingDir,(this._playingDir<0&&i<=this._playingToT||this._playingDir>0&&i>=this._playingToT)&&(i=this._playingToT,this.state=$c.SCRUBBING,this.fire("stopped")),this._t=i,e.loadFrame(this._t)}}_ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=$c.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=$c.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const i=this._cameraPath;if(!i)return;const s=i.frames[e];s?(this.state=$c.SCRUBBING,this._cameraFlightAnimation.flyTo(s,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=$c.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=$c.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=$c.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}$c.STOPPED=0,$c.SCRUBBING=1,$c.PLAYING=2,$c.PLAYING_TO=3;const eu=d.vec3(),tu=d.vec3();d.vec3();const iu=d.vec3([0,-1,0]),su=d.vec4([0,0,0,1]);class ru extends R{constructor(e,t={}){super(e,t),this._src=null,this._image=null,this._pos=d.vec3(),this._origin=d.vec3(),this._rtcPos=d.vec3(),this._dir=d.vec3(),this._size=1,this._imageSize=d.vec2(),this._texture=new Kr(this),this._plane=new pr(this,{geometry:new Gt(this,ro({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Jt(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0}),clippable:t.clippable}),this._grid=new pr(this,{geometry:new Gt(this,so({size:1,divisions:10})),material:new Jt(this,{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:t.clippable}),this._node=new Dr(this,{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[this._plane,this._grid]}),this._gridVisible=!1,this.visible=!0,this.gridVisible=t.gridVisible,this.position=t.position,this.rotation=t.rotation,this.dir=t.dir,this.size=t.size,this.collidable=t.collidable,this.clippable=t.clippable,this.pickable=t.pickable,this.opacity=t.opacity,t.image?this.image=t.image:this.src=t.src}set visible(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}get visible(){return this._plane.visible}set gridVisible(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}get gridVisible(){return this._gridVisible}set image(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}get image(){return this._image}set src(e){if(this._src=e,this._src){this._image=null;const e=new Image;e.onload=()=>{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set position(e){this._pos.set(e||[0,0,0]),X(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}get position(){return this._pos}set rotation(e){this._node.rotation=e}get rotation(){return this._node.rotation}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set dir(e){if(this._dir.set(e||[0,0,-1]),e){const t=this.scene.center,i=[-this._dir[0],-this._dir[1],-this._dir[2]];d.subVec3(t,this.position,eu);const s=-d.dotVec3(i,eu);d.normalizeVec3(i),d.mulVec3Scalar(i,s,tu),d.vec3PairToQuaternion(iu,e,su),this._node.quaternion=su}}get dir(){return this._dir}set collidable(e){this._node.collidable=!1!==e}get collidable(){return this._node.collidable}set clippable(e){this._node.clippable=!1!==e}get clippable(){return this._node.clippable}set pickable(e){this._node.pickable=!1!==e}get pickable(){return this._node.pickable}set opacity(e){this._node.opacity=e}get opacity(){return this._node.opacity}destroy(){super.destroy()}_updatePlaneSizeFromImage(){const e=this._size,t=this._imageSize[0],i=this._imageSize[1];if(t>i){const s=i/t;this._node.scale=[e,1,e*s]}else{const s=t/i;this._node.scale=[e*s,1,e]}}}class ou extends It{get type(){return"PointLight"}constructor(e,t={}){super(e,t);const i=this;this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const s=this.scene.camera,r=this.scene.canvas;this._onCameraViewMatrix=s.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=r.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new lt({type:"point",pos:d.vec3([1,1,1]),color:d.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(i._shadowViewMatrixDirty){i._shadowViewMatrix||(i._shadowViewMatrix=d.identityMat4());const e=i._state.pos,t=s.look,r=s.up;d.lookAtMat4v(e,t,r,i._shadowViewMatrix),i._shadowViewMatrixDirty=!1}return i._shadowViewMatrix},getShadowProjMatrix:()=>{if(i._shadowProjMatrixDirty){i._shadowProjMatrix||(i._shadowProjMatrix=d.identityMat4());const e=i.scene.canvas.canvas;d.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,i._shadowProjMatrix),i._shadowProjMatrixDirty=!1}return i._shadowProjMatrix},getShadowRenderBuf:()=>(i._shadowRenderBuf||(i._shadowRenderBuf=new it(i.scene.canvas.canvas,i.scene.canvas.gl,{size:[1024,1024]})),i._shadowRenderBuf)}),this.pos=t.pos,this.color=t.color,this.intensity=t.intensity,this.constantAttenuation=t.constantAttenuation,this.linearAttenuation=t.linearAttenuation,this.quadraticAttenuation=t.quadraticAttenuation,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set pos(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get pos(){return this._state.pos}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 constantAttenuation(e){this._state.attenuation[0]=e||0,this.glRedraw()}get constantAttenuation(){return this._state.attenuation[0]}set linearAttenuation(e){this._state.attenuation[1]=e||0,this.glRedraw()}get linearAttenuation(){return this._state.attenuation[1]}set quadraticAttenuation(e){this._state.attenuation[2]=e||0,this.glRedraw()}get quadraticAttenuation(){return this._state.attenuation[2]}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()}}function nu(e){if(!au(e.width)||!au(e.height)){const t=document.createElement("canvas");t.width=lu(e.width),t.height=lu(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function au(e){return 0==(e&e-1)}function lu(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Au extends R{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const i=this.scene.canvas.gl;this._state=new lt({texture:new Vr({gl:i,target:i.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),m.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,i=this.scene.canvas.gl;this._images=[];let s=!1,r=0;for(let o=0;o{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set collidable(e){this._mesh.collidable=!1!==e}get collidable(){return this._mesh.collidable}set clippable(e){this._mesh.clippable=!1!==e}get clippable(){return this._mesh.clippable}set pickable(e){this._mesh.pickable=!1!==e}get pickable(){return this._mesh.pickable}set opacity(e){this._mesh.opacity=e}get opacity(){return this._mesh.opacity}_updatePlaneSizeFromImage(){const e=.5*this._size,t=this._imageSize[0],i=this._imageSize[1],s=i/t;this._geometry.positions=t>i?[e,e*s,0,-e,e*s,0,-e,-e*s,0,e,-e*s,0]:[e/s,e,0,-e/s,e,0,-e/s,-e,0,e/s,-e,0]}}class du{constructor(e){this._eye=d.vec3(),this._look=d.vec3(),this._up=d.vec3(),this._projection={},e&&this.saveCamera(e)}saveCamera(e){const t=e.camera,i=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:i.fov,fovAxis:i.fovAxis,near:i.near,far:i.far};break;case"ortho":this._projection={projection:"ortho",scale:i.scale,near:i.near,far:i.far};break;case"frustum":this._projection={projection:"frustum",left:i.left,right:i.right,top:i.top,bottom:i.bottom,near:i.near,far:i.far};break;case"custom":this._projection={projection:"custom",matrix:i.matrix.slice()}}}restoreCamera(e,t){const i=e.camera,s=this._projection;function r(){switch(s.type){case"perspective":i.perspective.fov=s.fov,i.perspective.fovAxis=s.fovAxis,i.perspective.near=s.near,i.perspective.far=s.far;break;case"ortho":i.ortho.scale=s.scale,i.ortho.near=s.near,i.ortho.far=s.far;break;case"frustum":i.frustum.left=s.left,i.frustum.right=s.right,i.frustum.top=s.top,i.frustum.bottom=s.bottom,i.frustum.near=s.near,i.frustum.far=s.far;break;case"custom":i.customProjection.matrix=s.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:s.scale,projection:s.projection},(()=>{r(),t()})):(i.eye=this._eye,i.look=this._look,i.up=this._up,r(),i.projection=s.projection)}}const pu=d.vec3();class fu{constructor(e){if(this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,e){const t=e.metaScene.scene;this.saveObjects(t,e)}}saveObjects(e,t,i){this.numObjects=0,this._mask=i?y.apply(i,{}):null;const s=!i||i.visible,r=!i||i.edges,o=!i||i.xrayed,n=!i||i.highlighted,a=!i||i.selected,l=!i||i.clippable,A=!i||i.pickable,h=!i||i.colorize,c=!i||i.opacity,u=t.metaObjects,d=e.objects;for(let e=0,t=u.length;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=d.vec3();return t[0]=d.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=d.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=d.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}class vu extends jc{constructor(e,t={}){super(e,t),this._cachedLengths=[],this._dirty=!0,this._curves=[],this._t=0,this._dirtySubs=[],this._destroyedSubs=[],this.curves=t.curves||[],this.t=t.t}addCurve(e){this._curves.push(e),this._dirty=!0}set curves(e){var t,i,s;for(e=e||[],i=0,s=this._curves.length;i1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}get length(){var e=this._getCurveLengths();return e[e.length-1]}getPoint(e){for(var t,i=e*this.length,s=this._getCurveLengths(),r=0;r=i){var o=1-(s[r]-i)/(t=this._curves[r]).length;return t.getPointAt(o)}r++}return null}_getCurveLengths(){if(!this._dirty)return this._cachedLengths;var e,t=[],i=0,s=this._curves.length;for(e=0;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=d.vec3();return t[0]=d.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=d.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=d.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}class yu extends vc{constructor(e,t={}){super(e,t)}}class Bu extends R{constructor(e,t={}){super(e,t),this._skyboxMesh=new pr(this,{geometry:new Gt(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],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]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new Jt(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Kr(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}class wu{transcode(e,t,i={}){}destroy(){}}const xu=d.vec4(),Pu=d.vec4(),Cu=d.vec3(),Mu=d.vec3(),Fu=d.vec3(),Eu=d.vec4(),Iu=d.vec4(),Du=d.vec4();class Su{constructor(e){this._scene=e}dollyToCanvasPos(e,t,i){let s=!1;const r=this._scene.camera;if(e){const t=d.subVec3(e,r.eye,Cu);s=d.lenVec3(t){this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=d.vec3();d.decomposeMat4(d.inverseMat4(this._scene.viewer.camera.viewMatrix,d.mat4()),t,d.vec4(),d.vec3());const i=d.distVec3(t,e);let s=Math.tan(Math.PI/500)*i*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(s/=this._scene.camera.ortho.scale/2),X(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Zr(this._scene,mr({radius:s})),this._pivotSphere=new pr(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){d.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,d.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const i=t.boundary,s=i[2],r=i[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*s/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*r/2);let o=t._lastBoundingClientRect;if(!o||t._canvasSizeChanged){const e=t.canvas;o=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(o.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(o.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(X(this.getPivotPos(),this._rtcCenter,this._rtcPos),d.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new Jt(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=d.lookAtMat4v(e.eye,e.look,e.worldUp);d.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const i=this.getPivotPos();this._cameraOffset[2]+=d.distVec3(e.eye,i),t=d.inverseMat4(t);const s=d.transformVec3(t,this._cameraOffset),r=d.vec3();if(d.subVec3(e.eye,i,r),d.addVec3(r,s),e.zUp){const e=r[1];r[1]=r[2],r[2]=e}this._radius=d.lenVec3(r),this._polar=Math.acos(r[1]/this._radius),this._azimuth=Math.atan2(r[0],r[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=d.normalizeVec3(d.subVec3(e.look,e.eye,Tu)),i=d.cross3Vec3(t,e.worldUp,Ru);return d.sqLenVec3(i)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,i=Math.abs(d.distVec3(this._scene.center,t.eye)),s=t.project.transposedMatrix,r=s.subarray(8,12),o=s.subarray(12),n=[0,0,-1,1],a=d.dotVec4(n,r)/d.dotVec4(n,o),l=Uu;t.project.unproject(e,a,ku,Ou,l);const A=d.normalizeVec3(d.subVec3(l,t.eye,Tu)),h=d.addVec3(t.eye,d.mulVec3Scalar(A,i,Ru),Lu);this.setPivotPos(h)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const i=this._scene.camera;var s=-e;const r=-t;1===i.worldUp[2]&&(s=-s),this._azimuth+=.01*-s,this._polar+=.01*r,this._polar=d.clamp(this._polar,.001,Math.PI-.001);const o=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===i.worldUp[2]){const e=o[1];o[1]=o[2],o[2]=e}const n=d.lenVec3(d.subVec3(i.look,i.eye,d.vec3())),a=this.getPivotPos();d.addVec3(o,a);let l=d.lookAtMat4v(o,a,i.worldUp);l=d.inverseMat4(l);const A=d.transformVec3(l,this._cameraOffset);l[12]-=A[0],l[13]-=A[1],l[14]-=A[2];const h=[l[8],l[9],l[10]];i.eye=[l[12],l[13],l[14]],d.subVec3(i.eye,d.mulVec3Scalar(h,n),i.look),i.up=[l[4],l[5],l[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class Qu{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=d.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;const e=`${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;if(this._lastHash===e)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;const t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&(e.snappedToEdge||e.snappedToVertex)?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const e=this.pickResult.canvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new Re;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}const Vu=d.vec2();class Hu{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController;let n,a,l,A=0,h=0,c=0,u=0,p=!1;const f=d.vec3();let g=!0;const m=this._scene.canvas.canvas,_=[];function v(e=!0){m.style.cursor="move",A=s.pointerCanvasPos[0],h=s.pointerCanvasPos[1],c=s.pointerCanvasPos[0],u=s.pointerCanvasPos[1],e&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(p=!0,f.set(o.pickResult.worldPos)):p=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(i.active&&i.pointerEnabled)switch(t.which){case 1:_[e.input.KEY_SHIFT]||i.planView?(n=!0,v()):(n=!0,v(!1));break;case 2:a=!0,v();break;case 3:l=!0,i.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(!n&&!a&&!l)return;const o=e.canvas.boundary,c=o[2],u=o[3],g=s.pointerCanvasPos[0],m=s.pointerCanvasPos[1],v=_[e.input.KEY_SHIFT]||i.planView||!i.panRightClick&&a||i.panRightClick&&l,b=document.pointerLockElement?t.movementX:g-A,y=document.pointerLockElement?t.movementY:m-h;if(v){const t=e.camera;if("perspective"===t.projection){const i=Math.abs(p?d.lenVec3(d.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(t.perspective.fov/2*Math.PI/180);r.panDeltaX+=1.5*b*i/u,r.panDeltaY+=1.5*y*i/u}else r.panDeltaX+=.5*t.ortho.scale*(b/u),r.panDeltaY+=.5*t.ortho.scale*(y/u)}else!n||a||l||i.planView||(i.firstPerson?(r.rotateDeltaY-=b/c*i.dragRotationRate/2,r.rotateDeltaX+=y/u*(i.dragRotationRate/4)):(r.rotateDeltaY-=b/c*(1.5*i.dragRotationRate),r.rotateDeltaX+=y/u*(1.5*i.dragRotationRate)));A=g,h=m}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{i.active&&i.pointerEnabled&&s.mouseover&&(g=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(i.active&&i.pointerEnabled)switch(e.which){case 1:case 2:case 3:n=!1,a=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(i.active&&i.pointerEnabled){if(3===e.which){!function(e,t){if(e){let i=e.target,s=0,r=0,o=0,n=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,o+=i.scrollLeft,n+=i.scrollTop,i=i.offsetParent;t[0]=e.pageX+o-s,t[1]=e.pageY+n-r}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Vu);const i=Vu[0],s=Vu[1];Math.abs(i-c)<3&&Math.abs(s-u)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Vu,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{i.active&&i.pointerEnabled});const b=1/60;let y=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!i.active||!i.pointerEnabled)return;const t=performance.now()/1e3;var o=null!==y?t-y:0;y=t,o>.05&&(o=.05),o{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(!s.mouseover)return;const n=r._isKeyDownForAction(r.AXIS_VIEW_RIGHT),a=r._isKeyDownForAction(r.AXIS_VIEW_BACK),l=r._isKeyDownForAction(r.AXIS_VIEW_LEFT),A=r._isKeyDownForAction(r.AXIS_VIEW_FRONT),h=r._isKeyDownForAction(r.AXIS_VIEW_TOP),c=r._isKeyDownForAction(r.AXIS_VIEW_BOTTOM);if(!(n||a||l||A||h||c))return;const u=e.aabb,p=d.getAABB3Diag(u);d.getAABB3Center(u,ju);const f=Math.abs(p/Math.tan(t.cameraFlight.fitFOV*d.DEGTORAD)),g=1.1*p;Xu.orthoScale=g,n?(Xu.eye.set(d.addVec3(ju,d.mulVec3Scalar(o.worldRight,f,Gu),Ku)),Xu.look.set(ju),Xu.up.set(o.worldUp)):a?(Xu.eye.set(d.addVec3(ju,d.mulVec3Scalar(o.worldForward,f,Gu),Ku)),Xu.look.set(ju),Xu.up.set(o.worldUp)):l?(Xu.eye.set(d.addVec3(ju,d.mulVec3Scalar(o.worldRight,-f,Gu),Ku)),Xu.look.set(ju),Xu.up.set(o.worldUp)):A?(Xu.eye.set(d.addVec3(ju,d.mulVec3Scalar(o.worldForward,-f,Gu),Ku)),Xu.look.set(ju),Xu.up.set(o.worldUp)):h?(Xu.eye.set(d.addVec3(ju,d.mulVec3Scalar(o.worldUp,f,Gu),Ku)),Xu.look.set(ju),Xu.up.set(d.normalizeVec3(d.mulVec3Scalar(o.worldForward,1,zu),Wu))):c&&(Xu.eye.set(d.addVec3(ju,d.mulVec3Scalar(o.worldUp,-f,Gu),Ku)),Xu.look.set(ju),Xu.up.set(d.normalizeVec3(d.mulVec3Scalar(o.worldForward,-1,zu)))),!i.firstPerson&&i.followPointer&&t.pivotController.setPivotPos(ju),t.cameraFlight.duration>0?t.cameraFlight.flyTo(Xu,(()=>{t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(Xu),t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class Yu{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,A=!1;const h=this._scene.canvas.canvas,c=i=>{let s;i&&i.worldPos&&(s=i.worldPos);const r=i&&i.entity?i.entity.aabb:e.aabb;if(s){const i=e.camera;d.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})},u=e.tickify(this._canvasMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(l||A)return;const r=a.hasSubs("hover"),n=a.hasSubs("hoverEnter"),h=a.hasSubs("hoverOut"),c=a.hasSubs("hoverOff"),u=a.hasSubs("hoverSurface"),d=a.hasSubs("hoverSnapOrSurface");if(r||n||h||c||u||d)if(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=u,o.scheduleSnapOrPick=d,o.update(),o.pickResult){if(o.pickResult.entity){const t=o.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),a.fire("hoverEnter",o.pickResult,!0),this._lastPickedEntityId=t)}a.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&a.fire("hoverSurface",o.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),a.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)});h.addEventListener("mousemove",u),h.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(A=!0);if(1===t.which&&i.active&&i.pointerEnabled&&(s.mouseDownClientX=t.clientX,s.mouseDownClientY=t.clientY,s.mouseDownCursorX=s.pointerCanvasPos[0],s.mouseDownCursorY=s.pointerCanvasPos[1],!i.firstPerson&&i.followPointer&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===t.which))){const t=o.pickResult;t&&t.worldPos?(n.setPivotPos(t.worldPos),n.startPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),n.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(A=!1),n.getPivoting()&&n.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=r=>{if(!i.active||!i.pointerEnabled)return;if(!(1===r.which))return;if(n.hidePivot(),Math.abs(r.clientX-s.mouseDownClientX)>3||Math.abs(r.clientY-s.mouseDownClientY)>3)return;const l=a.hasSubs("picked"),A=a.hasSubs("pickedNothing"),h=a.hasSubs("pickedSurface"),u=a.hasSubs("doublePicked"),p=a.hasSubs("doublePickedSurface"),f=a.hasSubs("doublePickedNothing");if(!(i.doublePickFlyTo||u||p||f))return(l||A||h)&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=h,o.update(),o.pickResult?(a.fire("picked",o.pickResult,!0),o.pickedSurface&&a.fire("pickedSurface",o.pickResult,!0)):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo,o.schedulePickSurface=h,o.update();const e=o.pickResult,r=o.pickedSurface;this._timeout=setTimeout((()=>{e?(a.fire("picked",e,!0),r&&(a.fire("pickedSurface",e,!0),!i.firstPerson&&i.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0),this._clicks=0}),i.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo||u||p,o.schedulePickSurface=o.schedulePickEntity&&p,o.update(),o.pickResult){if(a.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&a.fire("doublePickedSurface",o.pickResult,!0),i.doublePickFlyTo&&(c(o.pickResult),!i.firstPerson&&i.followPointer)){const e=o.pickResult.entity.aabb,i=d.getAABB3Center(e);t.pivotController.setPivotPos(i),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(a.fire("doublePickedNothing",{canvasPos:s.pointerCanvasPos},!0),i.doublePickFlyTo&&(c(),!i.firstPerson&&i.followPointer)){const i=e.aabb,s=d.getAABB3Center(i);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class Zu{constructor(e,t,i,s,r){this._scene=e;const o=e.input,n=[],a=e.canvas.canvas;let l=!0;this._onSceneMouseMove=o.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=o.on("keydown",(t=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&s.mouseover&&(n[t]=!0,t===o.KEY_SHIFT&&(a.style.cursor="move"))})),this._onSceneKeyUp=o.on("keyup",(s=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&(n[s]=!1,s===o.KEY_SHIFT&&(a.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(a=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(!s.mouseover)return;const A=t.cameraControl,h=a.deltaTime/1e3;if(!i.planView){const e=A._isKeyDownForAction(A.ROTATE_Y_POS,n),s=A._isKeyDownForAction(A.ROTATE_Y_NEG,n),o=A._isKeyDownForAction(A.ROTATE_X_POS,n),a=A._isKeyDownForAction(A.ROTATE_X_NEG,n),l=h*i.keyboardRotationRate;(e||s||o||a)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),e?r.rotateDeltaY+=l:s&&(r.rotateDeltaY-=l),o?r.rotateDeltaX+=l:a&&(r.rotateDeltaX-=l),!i.firstPerson&&i.followPointer&&t.pivotController.startPivot())}if(!n[o.KEY_CTRL]&&!n[o.KEY_ALT]){const e=A._isKeyDownForAction(A.DOLLY_BACKWARDS,n),o=A._isKeyDownForAction(A.DOLLY_FORWARDS,n);if(e||o){const n=h*i.keyboardDollyRate;!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),o?r.dollyDelta-=n:e&&(r.dollyDelta+=n),l&&(s.followPointerDirty=!0,l=!1)}}const c=A._isKeyDownForAction(A.PAN_FORWARDS,n),u=A._isKeyDownForAction(A.PAN_BACKWARDS,n),d=A._isKeyDownForAction(A.PAN_LEFT,n),p=A._isKeyDownForAction(A.PAN_RIGHT,n),f=A._isKeyDownForAction(A.PAN_UP,n),g=A._isKeyDownForAction(A.PAN_DOWN,n),m=(n[o.KEY_ALT]?.3:1)*h*i.keyboardPanRate;(c||u||d||p||f||g)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),g?r.panDeltaY+=m:f&&(r.panDeltaY+=-m),p?r.panDeltaX+=-m:d&&(r.panDeltaX+=m),u?r.panDeltaZ+=m:c&&(r.panDeltaZ+=-m))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const qu=d.vec3();class $u{constructor(e,t,i,s,r){this._scene=e;const o=e.camera,n=t.pickController,a=t.pivotController,l=t.panController;let A=1,h=1,c=null;this._onTick=e.on("tick",(()=>{if(!i.active||!i.pointerEnabled)return;let t="default";if(Math.abs(r.dollyDelta)<.001&&(r.dollyDelta=0),Math.abs(r.rotateDeltaX)<.001&&(r.rotateDeltaX=0),Math.abs(r.rotateDeltaY)<.001&&(r.rotateDeltaY=0),0===r.rotateDeltaX&&0===r.rotateDeltaY||(r.dollyDelta=0),i.followPointer){if(--A<=0&&(A=1,0!==r.dollyDelta)){if(0===r.rotateDeltaY&&0===r.rotateDeltaX&&i.followPointer&&s.followPointerDirty&&(n.pickCursorPos=s.pointerCanvasPos,n.schedulePickSurface=!0,n.update(),n.pickResult&&n.pickResult.worldPos?c=n.pickResult.worldPos:(h=1,c=null),s.followPointerDirty=!1),c){const t=Math.abs(d.lenVec3(d.subVec3(c,e.camera.eye,qu)));h=t/i.dollyProximityThreshold}h{s.mouseover=!0}),o.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{s.mouseover=!1,o.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{td(e,o,s.pointerCanvasPos)}),o.addEventListener("mousedown",this._mouseDownHandler=e=>{i.active&&i.pointerEnabled&&(td(e,o,s.pointerCanvasPos),s.mouseover=!0)}),o.addEventListener("mouseup",this._mouseUpHandler=e=>{i.active&&i.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function td(e,t,i){if(e){const{left:s,top:r}=t.getBoundingClientRect();i[0]=e.clientX-s,i[1]=e.clientY-r}else e=window.event,i[0]=e.x,i[1]=e.y;return i}const id=function(e,t){if(e){let i=e.target,s=0,r=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;t[0]=e.pageX-s,t[1]=e.pageY-r}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class sd{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=d.vec2(),l=d.vec2(),A=d.vec2(),h=d.vec2(),c=[],u=this._scene.canvas.canvas;let p=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),u.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!i.active||!i.pointerEnabled)return;t.preventDefault();const r=t.touches,l=t.changedTouches;for(s.touchStartTime=Date.now(),1===r.length&&1===l.length&&(id(r[0],a),i.followPointer&&(o.pickCursorPos=a,o.schedulePickSurface=!0,o.update(),i.planView||(o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(n.setPivotPos(o.pickResult.worldPos),!i.firstPerson&&n.startPivot()&&n.showPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),!i.firstPerson&&n.startPivot()&&n.showPivot()))));c.length{n.getPivoting()&&n.endPivot()}),u.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const n=e.canvas.boundary,a=n[2],u=n[3],g=t.touches;if(t.touches.length===p){if(1===p){id(g[0],l),d.subVec2(l,c[0],h);const t=h[0],o=h[1];if(null!==s.longTouchTimeout&&(Math.abs(t)>i.longTapRadius||Math.abs(o)>i.longTapRadius)&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),i.planView){const s=e.camera;if("perspective"===s.projection){const n=Math.abs(e.camera.eyeLookDist)*Math.tan(s.perspective.fov/2*Math.PI/180);r.panDeltaX+=t*n/u*i.touchPanRate,r.panDeltaY+=o*n/u*i.touchPanRate}else r.panDeltaX+=.5*s.ortho.scale*(t/u)*i.touchPanRate,r.panDeltaY+=.5*s.ortho.scale*(o/u)*i.touchPanRate}else r.rotateDeltaY-=t/a*(1*i.dragRotationRate),r.rotateDeltaX+=o/u*(1.5*i.dragRotationRate)}else if(2===p){const t=g[0],n=g[1];id(t,l),id(n,A);const a=d.geometricMeanVec2(c[0],c[1]),h=d.geometricMeanVec2(l,A),p=d.vec2();d.subVec2(a,h,p);const f=p[0],m=p[1],_=e.camera,v=d.distVec2([t.pageX,t.pageY],[n.pageX,n.pageY]),b=(d.distVec2(c[0],c[1])-v)*i.touchDollyRate;if(r.dollyDelta=b,Math.abs(b)<1)if("perspective"===_.projection){const t=o.pickResult?o.pickResult.worldPos:e.center,s=Math.abs(d.lenVec3(d.subVec3(t,e.camera.eye,[])))*Math.tan(_.perspective.fov/2*Math.PI/180);r.panDeltaX-=f*s/u*i.touchPanRate,r.panDeltaY-=m*s/u*i.touchPanRate}else r.panDeltaX-=.5*_.ortho.scale*(f/u)*i.touchPanRate,r.panDeltaY-=.5*_.ortho.scale*(m/u)*i.touchPanRate;s.pointerCanvasPos=h}for(let e=0;e{let s;i&&i.worldPos&&(s=i.worldPos);const r=i?i.entity.aabb:e.aabb;if(s){const i=e.camera;d.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})};u.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!i.active||!i.pointerEnabled)return;null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null);const r=e.touches,o=e.changedTouches;if(a=Date.now(),1===r.length&&1===o.length){h=a,rd(r[0],A);const o=A[0],n=A[1],l=r[0].pageX,c=r[0].pageY;s.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(c)],canvasPos:[Math.round(o),Math.round(n)],event:e},!0),s.longTouchTimeout=null}),i.longTapTimeout)}else h=-1;for(;l.length{if(!i.active||!i.pointerEnabled)return;const t=Date.now(),r=e.touches,a=e.changedTouches,u=n.hasSubs("pickedSurface");null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),0===r.length&&1===a.length&&h>-1&&t-h<150&&(c>-1&&h-c<325?(rd(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=u,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("doublePicked",o.pickResult),o.pickedSurface&&n.fire("doublePickedSurface",o.pickResult),i.doublePickFlyTo&&p(o.pickResult)):(n.fire("doublePickedNothing"),i.doublePickFlyTo&&p()),c=-1):d.distVec2(l[0],A)<4&&(rd(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=u,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("picked",o.pickResult),o.pickedSurface&&n.fire("pickedSurface",o.pickResult)):n.fire("pickedNothing"),c=t),h=-1),l.length=r.length;for(let e=0,t=r.length;e{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:d.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:d.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const i=this.scene;this._controllers={cameraControl:this,pickController:new Qu(this,this._configs),pivotController:new Nu(i,this._configs),panController:new Su(i),cameraFlight:new qc(this,{duration:.5})},this._handlers=[new ed(this.scene,this._controllers,this._configs,this._states,this._updates),new sd(this.scene,this._controllers,this._configs,this._states,this._updates),new Hu(this.scene,this._controllers,this._configs,this._states,this._updates),new Ju(this.scene,this._controllers,this._configs,this._states,this._updates),new Yu(this.scene,this._controllers,this._configs,this._states,this._updates),new od(this.scene,this._controllers,this._configs,this._states,this._updates),new Zu(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new $u(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",y.isString(e)){const t=this.scene.input,i={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":i[this.PAN_LEFT]=[t.KEY_A],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_Z],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":i[this.PAN_LEFT]=[t.KEY_Q],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_W],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=i}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const i=this._keyMap[e];if(!i)return!1;t||(t=this.scene.input.keyDown);for(let e=0,s=i.length;e0?ud(t):null,n=i&&i.length>0?ud(i):null,a=e=>{if(!e)return;var t=!0;(n&&n[e.type]||o&&!o[e.type])&&(t=!1),t&&s.push(e.id);const i=e.children;if(i)for(var r=0,l=i.length;r * Copyright (c) 2022 Niklas von Hertzen diff --git a/dist/xeokit-sdk.min.es5.js b/dist/xeokit-sdk.min.es5.js index 632232e0c..7d4b829dd 100644 --- a/dist/xeokit-sdk.min.es5.js +++ b/dist/xeokit-sdk.min.es5.js @@ -1,4 +1,4 @@ -var e,t=a().mark(KB),i=a().mark(XB),s=a().mark(nM);function r(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,s)}return i}function n(e){for(var t=1;t=0;--r){var n=this.tryEntries[r],o=n.completion;if("root"===n.tryLoc)return s("end");if(n.tryLoc<=this.prev){var a=i.call(n,"catchLoc"),l=i.call(n,"finallyLoc");if(a&&l){if(this.prev=0;--s){var r=this.tryEntries[s];if(r.tryLoc<=this.prev&&i.call(r,"finallyLoc")&&this.prev=0;--t){var i=this.tryEntries[t];if(i.finallyLoc===e)return this.complete(i.completion,i.afterLoc),x(i),c}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var i=this.tryEntries[t];if(i.tryLoc===e){var s=i.completion;if("throw"===s.type){var r=s.arg;x(i)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,i){return this.delegate={iterator:C(e),resultName:t,nextLoc:i},"next"===this.method&&(this.arg=void 0),c}},e}function l(e,t,i,s,r,n,o){try{var a=e[n](o),l=a.value}catch(e){return void i(e)}a.done?t(l):Promise.resolve(l).then(s,r)}function u(e){return function(){var t=this,i=arguments;return new Promise((function(s,r){var n=e.apply(t,i);function o(e){l(n,s,r,o,a,"next",e)}function a(e){l(n,s,r,o,a,"throw",e)}o(void 0)}))}}function A(e){return function(e){if(Array.isArray(e))return p(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||d(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 c(e,t){var i="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!i){if(Array.isArray(e)||(i=d(e))||t&&e&&"number"==typeof e.length){i&&(e=i);var s=0,r=function(){};return{s:r,n:function(){return s>=e.length?{done:!0}:{done:!1,value:e[s++]}},e:function(e){throw e},f:r}}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 n,o=!0,a=!1;return{s:function(){i=i.call(e)},n:function(){var e=i.next();return o=e.done,e},e:function(e){a=!0,n=e},f:function(){try{o||null==i.return||i.return()}finally{if(a)throw n}}}}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var i=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==i)return;var s,r,n=[],o=!0,a=!1;try{for(i=i.call(e);!(o=(s=i.next()).done)&&(n.push(s.value),!t||n.length!==t);o=!0);}catch(e){a=!0,r=e}finally{try{o||null==i.return||i.return()}finally{if(a)throw r}}return n}(e,t)||d(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 d(e,t){if(e){if("string"==typeof e)return p(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?p(e,t):void 0}}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,s=new Array(t);i0&&void 0!==arguments[0]?arguments[0]:{};x(this,e),this._id=V.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!==i.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()})),i.items&&(this.items=i.items),this._hideOnAction=!1!==i.hideOnAction,this.context=i.context,this.enabled=!1!==i.enabled,this.hide()}return C(e,[{key:"on",value:function(e,t){var i=this._eventSubs[e];i||(i=[],this._eventSubs[e]=i),i.push(t)}},{key:"fire",value:function(e,t){var i=this._eventSubs[e];if(i)for(var s=0,r=i.length;s0,A=t._getNextId(),c=n.getTitle||function(){return n.title||""},h=n.doAction||n.callback||function(){},d=n.getEnabled||function(){return!0},p=n.getShown||function(){return!0},f=new G(A,c,h,d,p);if(f.parentMenu=r,l.items.push(f),u){var v=e(o);f.subMenu=v,v.parentItem=f}t._itemList.push(f),t._itemMap[f.id]=f},A=0,c=a.length;A'),s.push("
    "),i)for(var r=0,n=i.length;r'+d+" [MORE]"):s.push('
  • '+d+"
  • ")}}s.push("
"),s.push("");var p=s.join("");document.body.insertAdjacentHTML("beforeend",p);var f=document.querySelector("."+e.id);e.menuElement=f,f.style["border-radius"]="4px",f.style.display="none",f.style["z-index"]=3e5,f.style.background="white",f.style.border="1px solid black",f.style["box-shadow"]="0 4px 5px 0 gray",f.oncontextmenu=function(e){e.preventDefault()};var v=this,g=null;if(i)for(var m=0,_=i.length;m<_;m++){var y=i[m].items;if(y)for(var b=function(e,i){var s=y[e],r=s.subMenu;if(s.itemElement=document.getElementById(s.id),!s.itemElement)return console.error("ContextMenu item element not found: "+s.id),"continue";s.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault();var t=s.subMenu;if(t){if(g&&g.id!==t.id&&(v._hideMenu(g.id),g=null),!1!==s.enabled){var i=s.itemElement,r=t.menuElement,n=i.getBoundingClientRect();r.getBoundingClientRect();n.right+200>window.innerWidth?v._showMenu(t.id,n.left-200,n.top-1):v._showMenu(t.id,n.right-5,n.top-1),g=t}}else g&&(v._hideMenu(g.id),g=null)})),r||(s.itemElement.addEventListener("click",(function(e){e.preventDefault(),v._context&&!1!==s.enabled&&(s.doAction&&s.doAction(v._context),t._hideOnAction?v.hide():(v._updateItemsTitles(),v._updateItemsEnabledStatus()))})),s.itemElement.addEventListener("mouseup",(function(e){3===e.which&&(e.preventDefault(),v._context&&!1!==s.enabled&&(s.doAction&&s.doAction(v._context),t._hideOnAction?v.hide():(v._updateItemsTitles(),v._updateItemsEnabledStatus())))})),s.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault(),!1!==s.enabled&&s.doHover&&s.doHover(v._context)})))},w=0,B=y.length;wwindow.innerHeight&&(i=window.innerHeight-s),t+r>window.innerWidth&&(t=window.innerWidth-r),e.style.left=t+"px",e.style.top=i+"px"}},{key:"_hideMenuElement",value:function(e){e.style.display="none"}}]),e}(),W=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this.viewer=t,this.scene=this.viewer.scene,this._lensCursorDiv=document.createElement("div"),this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._lensCursorDiv,this.viewer.scene.canvas.canvas),this._lensCursorDiv.style.background="pink",this._lensCursorDiv.style.border="2px solid red",this._lensCursorDiv.style.borderRadius="20px",this._lensCursorDiv.style.width="10px",this._lensCursorDiv.style.height="10px",this._lensCursorDiv.style.margin="-200px -200px",this._lensCursorDiv.style.zIndex="100000",this._lensCursorDiv.style.position="absolute",this._lensCursorDiv.style.pointerEvents="none",this._lensContainer=document.createElement("div"),this._lensContainer.style.border="1px solid black",this._lensContainer.style.background="white",this._lensContainer.style.borderRadius="50%",this._lensContainer.style.width="300px",this._lensContainer.style.height="300px",this._lensContainer.style.marginTop="85px",this._lensContainer.style.marginLeft="25px",this._lensContainer.style.zIndex="15000",this._lensContainer.style.position="absolute",this._lensContainer.style.pointerEvents="none",this._lensContainer.style.visibility="hidden",this._lensCanvas=document.createElement("canvas"),this._lensCanvas.style.borderRadius="50%",this._lensCanvas.style.width="300px",this._lensCanvas.style.height="300px",this._lensCanvas.style.zIndex="15000",this._lensCanvas.style.pointerEvents="none",document.body.appendChild(this._lensContainer),this._lensContainer.appendChild(this._lensCanvas),this._lensCanvasContext=this._lensCanvas.getContext("2d"),this._canvasElement=this.viewer.scene.canvas.canvas,this._canvasPos=null,this._snappedCanvasPos=null,this._lensPosToggle=!0,this._zoomLevel=s.zoomLevel||2,this._active=!1!==s.active,this._visible=!1,this._snapped=!1,this._onViewerRendering=this.viewer.scene.on("rendering",(function(){i._active&&i._visible&&i.update()}))}return C(e,[{key:"update",value:function(){if(this._active&&this._visible&&this._canvasPos){var e=this._lensContainer.getBoundingClientRect(),t=this._canvasElement.getBoundingClientRect(),i=this._canvasPos[0]e.left&&this._canvasPos[1]e.top;this._lensContainer.style.marginLeft="25px",i&&(this._lensPosToggle?this._lensContainer.style.marginTop="".concat(t.bottom-t.top-this._lensCanvas.height-85,"px"):this._lensContainer.style.marginTop="85px",this._lensPosToggle=!this._lensPosToggle),this._lensCanvasContext.clearRect(0,0,this._lensCanvas.width,this._lensCanvas.height);var s=Math.max(this._lensCanvas.width,this._lensCanvas.height)/this._zoomLevel;this._lensCanvasContext.drawImage(this._canvasElement,this._canvasPos[0]-s/2,this._canvasPos[1]-s/2,s,s,0,0,this._lensCanvas.width,this._lensCanvas.height);var r=[(e.left+e.right)/2,(e.top+e.bottom)/2];if(this._snappedCanvasPos){var n=this._snappedCanvasPos[0]-this._canvasPos[0],o=this._snappedCanvasPos[1]-this._canvasPos[1];this._lensCursorDiv.style.marginLeft="".concat(r[0]+n*this._zoomLevel-10,"px"),this._lensCursorDiv.style.marginTop="".concat(r[1]+o*this._zoomLevel-10,"px")}else this._lensCursorDiv.style.marginLeft="".concat(r[0]-10,"px"),this._lensCursorDiv.style.marginTop="".concat(r[1]-10,"px")}}},{key:"zoomFactor",get:function(){return this._zoomFactor},set:function(e){this._zoomFactor=e,this.update()}},{key:"canvasPos",get:function(){return this._canvasPos},set:function(e){this._canvasPos=e,this.update()}},{key:"snappedCanvasPos",get:function(){return this._snappedCanvasPos},set:function(e){this._snappedCanvasPos=e,this.update()}},{key:"snapped",get:function(){return this._snapped},set:function(e){this._snapped=e,e?(this._lensCursorDiv.style.background="greenyellow",this._lensCursorDiv.style.border="2px solid green"):(this._lensCursorDiv.style.background="pink",this._lensCursorDiv.style.border="2px solid red")}},{key:"active",get:function(){return this._active},set:function(e){this._active=e,this._lensContainer.style.visibility=e&&this._visible?"visible":"hidden",e&&this._visible||(this._lensCursorDiv.style.marginLeft="-100px",this._lensCursorDiv.style.marginTop="-100px"),this.update()}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=e,this._lensContainer.style.visibility=e&&this._active?"visible":"hidden",e&&this._active||(this._lensCursorDiv.style.marginLeft="-100px",this._lensCursorDiv.style.marginTop="-100px"),this.update()}},{key:"destroy",value:function(){this._destroyed||(this.viewer.scene.off(this._onViewerRendering),this._lensContainer.removeChild(this._lensCanvas),document.body.removeChild(this._lensContainer),this._destroyed=!0)}}]),e}(),K=!0,X=K?Float64Array:Float32Array,J=new X(3),Y=new X(16),Z=new X(16),q=new X(4),$={setDoublePrecisionEnabled:function(e){X=(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 i=t.indexOf("#");return i===e.length&&t.startsWith(e)?t.substring(i+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 X(e||2)},vec3:function(e){return new X(e||3)},vec4:function(e){return new X(e||4)},mat3:function(e){return new X(e||9)},mat3ToMat4:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new X(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 X(e||16)},mat4ToMat3:function(e,t){},doublesToFloats:function(e,t,i){for(var s=new X(2),r=0,n=e.length;r>8&255]+e[t>>16&255]+e[t>>24&255],"-").concat(e[255&i]).concat(e[i>>8&255],"-").concat(e[i>>16&15|64]).concat(e[i>>24&255],"-").concat(e[63&s|128]).concat(e[s>>8&255],"-").concat(e[s>>16&255]).concat(e[s>>24&255]).concat(e[255&r]).concat(e[r>>8&255]).concat(e[r>>16&255]).concat(e[r>>24&255])}}(),clamp:function(e,t,i){return Math.max(t,Math.min(i,e))},fmod:function(e,t){if(e1?1:i,Math.acos(i)},vec3FromMat4Scale:function(){var e=new X(3);return function(t,i){return e[0]=t[0],e[1]=t[1],e[2]=t[2],i[0]=$.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],i[1]=$.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],i[2]=$.lenVec3(e),i}}(),vecToArray:function(){function e(e){return Math.round(1e5*e)/1e5}return function(t){for(var i=0,s=(t=Array.prototype.slice.call(t)).length;i0&&void 0!==arguments[0]?arguments[0]:new X(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 X(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,i){return i||(i=e),i[0]=e[0]+t[0],i[1]=e[1]+t[1],i[2]=e[2]+t[2],i[3]=e[3]+t[3],i[4]=e[4]+t[4],i[5]=e[5]+t[5],i[6]=e[6]+t[6],i[7]=e[7]+t[7],i[8]=e[8]+t[8],i[9]=e[9]+t[9],i[10]=e[10]+t[10],i[11]=e[11]+t[11],i[12]=e[12]+t[12],i[13]=e[13]+t[13],i[14]=e[14]+t[14],i[15]=e[15]+t[15],i},addMat4Scalar:function(e,t,i){return i||(i=e),i[0]=e[0]+t,i[1]=e[1]+t,i[2]=e[2]+t,i[3]=e[3]+t,i[4]=e[4]+t,i[5]=e[5]+t,i[6]=e[6]+t,i[7]=e[7]+t,i[8]=e[8]+t,i[9]=e[9]+t,i[10]=e[10]+t,i[11]=e[11]+t,i[12]=e[12]+t,i[13]=e[13]+t,i[14]=e[14]+t,i[15]=e[15]+t,i},addScalarMat4:function(e,t,i){return $.addMat4Scalar(t,e,i)},subMat4:function(e,t,i){return i||(i=e),i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],i[3]=e[3]-t[3],i[4]=e[4]-t[4],i[5]=e[5]-t[5],i[6]=e[6]-t[6],i[7]=e[7]-t[7],i[8]=e[8]-t[8],i[9]=e[9]-t[9],i[10]=e[10]-t[10],i[11]=e[11]-t[11],i[12]=e[12]-t[12],i[13]=e[13]-t[13],i[14]=e[14]-t[14],i[15]=e[15]-t[15],i},subMat4Scalar:function(e,t,i){return i||(i=e),i[0]=e[0]-t,i[1]=e[1]-t,i[2]=e[2]-t,i[3]=e[3]-t,i[4]=e[4]-t,i[5]=e[5]-t,i[6]=e[6]-t,i[7]=e[7]-t,i[8]=e[8]-t,i[9]=e[9]-t,i[10]=e[10]-t,i[11]=e[11]-t,i[12]=e[12]-t,i[13]=e[13]-t,i[14]=e[14]-t,i[15]=e[15]-t,i},subScalarMat4:function(e,t,i){return i||(i=t),i[0]=e-t[0],i[1]=e-t[1],i[2]=e-t[2],i[3]=e-t[3],i[4]=e-t[4],i[5]=e-t[5],i[6]=e-t[6],i[7]=e-t[7],i[8]=e-t[8],i[9]=e-t[9],i[10]=e-t[10],i[11]=e-t[11],i[12]=e-t[12],i[13]=e-t[13],i[14]=e-t[14],i[15]=e-t[15],i},mulMat4:function(e,t,i){i||(i=e);var s=e[0],r=e[1],n=e[2],o=e[3],a=e[4],l=e[5],u=e[6],A=e[7],c=e[8],h=e[9],d=e[10],p=e[11],f=e[12],v=e[13],g=e[14],m=e[15],_=t[0],y=t[1],b=t[2],w=t[3],B=t[4],x=t[5],P=t[6],C=t[7],M=t[8],F=t[9],E=t[10],k=t[11],I=t[12],D=t[13],S=t[14],T=t[15];return i[0]=_*s+y*a+b*c+w*f,i[1]=_*r+y*l+b*h+w*v,i[2]=_*n+y*u+b*d+w*g,i[3]=_*o+y*A+b*p+w*m,i[4]=B*s+x*a+P*c+C*f,i[5]=B*r+x*l+P*h+C*v,i[6]=B*n+x*u+P*d+C*g,i[7]=B*o+x*A+P*p+C*m,i[8]=M*s+F*a+E*c+k*f,i[9]=M*r+F*l+E*h+k*v,i[10]=M*n+F*u+E*d+k*g,i[11]=M*o+F*A+E*p+k*m,i[12]=I*s+D*a+S*c+T*f,i[13]=I*r+D*l+S*h+T*v,i[14]=I*n+D*u+S*d+T*g,i[15]=I*o+D*A+S*p+T*m,i},mulMat3:function(e,t,i){i||(i=new X(9));var s=e[0],r=e[3],n=e[6],o=e[1],a=e[4],l=e[7],u=e[2],A=e[5],c=e[8],h=t[0],d=t[3],p=t[6],f=t[1],v=t[4],g=t[7],m=t[2],_=t[5],y=t[8];return i[0]=s*h+r*f+n*m,i[3]=s*d+r*v+n*_,i[6]=s*p+r*g+n*y,i[1]=o*h+a*f+l*m,i[4]=o*d+a*v+l*_,i[7]=o*p+a*g+l*y,i[2]=u*h+A*f+c*m,i[5]=u*d+A*v+c*_,i[8]=u*p+A*g+c*y,i},mulMat4Scalar:function(e,t,i){return i||(i=e),i[0]=e[0]*t,i[1]=e[1]*t,i[2]=e[2]*t,i[3]=e[3]*t,i[4]=e[4]*t,i[5]=e[5]*t,i[6]=e[6]*t,i[7]=e[7]*t,i[8]=e[8]*t,i[9]=e[9]*t,i[10]=e[10]*t,i[11]=e[11]*t,i[12]=e[12]*t,i[13]=e[13]*t,i[14]=e[14]*t,i[15]=e[15]*t,i},mulMat4v4:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),s=t[0],r=t[1],n=t[2],o=t[3];return i[0]=e[0]*s+e[4]*r+e[8]*n+e[12]*o,i[1]=e[1]*s+e[5]*r+e[9]*n+e[13]*o,i[2]=e[2]*s+e[6]*r+e[10]*n+e[14]*o,i[3]=e[3]*s+e[7]*r+e[11]*n+e[15]*o,i},transposeMat4:function(e,t){var i=e[4],s=e[14],r=e[8],n=e[13],o=e[12],a=e[9];if(!t||e===t){var l=e[1],u=e[2],A=e[3],c=e[6],h=e[7],d=e[11];return e[1]=i,e[2]=r,e[3]=o,e[4]=l,e[6]=a,e[7]=n,e[8]=u,e[9]=c,e[11]=s,e[12]=A,e[13]=h,e[14]=d,e}return t[0]=e[0],t[1]=i,t[2]=r,t[3]=o,t[4]=e[1],t[5]=e[5],t[6]=a,t[7]=n,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=s,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 i=e[1],s=e[2],r=e[5];t[1]=e[3],t[2]=e[6],t[3]=i,t[5]=e[7],t[6]=s,t[7]=r}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],i=e[1],s=e[2],r=e[3],n=e[4],o=e[5],a=e[6],l=e[7],u=e[8],A=e[9],c=e[10],h=e[11],d=e[12],p=e[13],f=e[14],v=e[15];return d*A*a*r-u*p*a*r-d*o*c*r+n*p*c*r+u*o*f*r-n*A*f*r-d*A*s*l+u*p*s*l+d*i*c*l-t*p*c*l-u*i*f*l+t*A*f*l+d*o*s*h-n*p*s*h-d*i*a*h+t*p*a*h+n*i*f*h-t*o*f*h-u*o*s*v+n*A*s*v+u*i*a*v-t*A*a*v-n*i*c*v+t*o*c*v},inverseMat4:function(e,t){t||(t=e);var i=e[0],s=e[1],r=e[2],n=e[3],o=e[4],a=e[5],l=e[6],u=e[7],A=e[8],c=e[9],h=e[10],d=e[11],p=e[12],f=e[13],v=e[14],g=e[15],m=i*a-s*o,_=i*l-r*o,y=i*u-n*o,b=s*l-r*a,w=s*u-n*a,B=r*u-n*l,x=A*f-c*p,P=A*v-h*p,C=A*g-d*p,M=c*v-h*f,F=c*g-d*f,E=h*g-d*v,k=1/(m*E-_*F+y*M+b*C-w*P+B*x);return t[0]=(a*E-l*F+u*M)*k,t[1]=(-s*E+r*F-n*M)*k,t[2]=(f*B-v*w+g*b)*k,t[3]=(-c*B+h*w-d*b)*k,t[4]=(-o*E+l*C-u*P)*k,t[5]=(i*E-r*C+n*P)*k,t[6]=(-p*B+v*y-g*_)*k,t[7]=(A*B-h*y+d*_)*k,t[8]=(o*F-a*C+u*x)*k,t[9]=(-i*F+s*C-n*x)*k,t[10]=(p*w-f*y+g*m)*k,t[11]=(-A*w+c*y-d*m)*k,t[12]=(-o*M+a*P-l*x)*k,t[13]=(i*M-s*P+r*x)*k,t[14]=(-p*b+f*_-v*m)*k,t[15]=(A*b-c*_+h*m)*k,t},traceMat4:function(e){return e[0]+e[5]+e[10]+e[15]},translationMat4v:function(e,t){var i=t||$.identityMat4();return i[12]=e[0],i[13]=e[1],i[14]=e[2],i},translationMat3v:function(e,t){var i=t||$.identityMat3();return i[6]=e[0],i[7]=e[1],i},translationMat4c:(O=new X(3),function(e,t,i,s){return O[0]=e,O[1]=t,O[2]=i,$.translationMat4v(O,s)}),translationMat4s:function(e,t){return $.translationMat4c(e,e,e,t)},translateMat4v:function(e,t){return $.translateMat4c(e[0],e[1],e[2],t)},translateMat4c:function(e,t,i,s){var r=s[3];s[0]+=r*e,s[1]+=r*t,s[2]+=r*i;var n=s[7];s[4]+=n*e,s[5]+=n*t,s[6]+=n*i;var o=s[11];s[8]+=o*e,s[9]+=o*t,s[10]+=o*i;var a=s[15];return s[12]+=a*e,s[13]+=a*t,s[14]+=a*i,s},setMat4Translation:function(e,t,i){return i[0]=e[0],i[1]=e[1],i[2]=e[2],i[3]=e[3],i[4]=e[4],i[5]=e[5],i[6]=e[6],i[7]=e[7],i[8]=e[8],i[9]=e[9],i[10]=e[10],i[11]=e[11],i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=e[15],i},rotationMat4v:function(e,t,i){var s,r,n,o,a,l,u=$.normalizeVec4([t[0],t[1],t[2],0],[]),A=Math.sin(e),c=Math.cos(e),h=1-c,d=u[0],p=u[1],f=u[2];return s=d*p,r=p*f,n=f*d,o=d*A,a=p*A,l=f*A,(i=i||$.mat4())[0]=h*d*d+c,i[1]=h*s+l,i[2]=h*n-a,i[3]=0,i[4]=h*s-l,i[5]=h*p*p+c,i[6]=h*r+o,i[7]=0,i[8]=h*n+a,i[9]=h*r-o,i[10]=h*f*f+c,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i},rotationMat4c:function(e,t,i,s,r){return $.rotationMat4v(e,[t,i,s],r)},scalingMat4v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.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]:$.identityMat3();return t[0]=e[0],t[4]=e[1],t},scalingMat4c:function(){var e=new X(3);return function(t,i,s,r){return e[0]=t,e[1]=i,e[2]=s,$.scalingMat4v(e,r)}}(),scaleMat4c:function(e,t,i,s){return s[0]*=e,s[4]*=t,s[8]*=i,s[1]*=e,s[5]*=t,s[9]*=i,s[2]*=e,s[6]*=t,s[10]*=i,s[3]*=e,s[7]*=t,s[11]*=i,s},scaleMat4v:function(e,t){var i=e[0],s=e[1],r=e[2];return t[0]*=i,t[4]*=s,t[8]*=r,t[1]*=i,t[5]*=s,t[9]*=r,t[2]*=i,t[6]*=s,t[10]*=r,t[3]*=i,t[7]*=s,t[11]*=r,t},scalingMat4s:function(e){return $.scalingMat4c(e,e,e)},rotationTranslationMat4:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.mat4(),s=e[0],r=e[1],n=e[2],o=e[3],a=s+s,l=r+r,u=n+n,A=s*a,c=s*l,h=s*u,d=r*l,p=r*u,f=n*u,v=o*a,g=o*l,m=o*u;return i[0]=1-(d+f),i[1]=c+m,i[2]=h-g,i[3]=0,i[4]=c-m,i[5]=1-(A+f),i[6]=p+v,i[7]=0,i[8]=h+g,i[9]=p-v,i[10]=1-(A+d),i[11]=0,i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=1,i},mat4ToEuler:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),s=$.clamp,r=e[0],n=e[4],o=e[8],a=e[1],l=e[5],u=e[9],A=e[2],c=e[6],h=e[10];return"XYZ"===t?(i[1]=Math.asin(s(o,-1,1)),Math.abs(o)<.99999?(i[0]=Math.atan2(-u,h),i[2]=Math.atan2(-n,r)):(i[0]=Math.atan2(c,l),i[2]=0)):"YXZ"===t?(i[0]=Math.asin(-s(u,-1,1)),Math.abs(u)<.99999?(i[1]=Math.atan2(o,h),i[2]=Math.atan2(a,l)):(i[1]=Math.atan2(-A,r),i[2]=0)):"ZXY"===t?(i[0]=Math.asin(s(c,-1,1)),Math.abs(c)<.99999?(i[1]=Math.atan2(-A,h),i[2]=Math.atan2(-n,l)):(i[1]=0,i[2]=Math.atan2(a,r))):"ZYX"===t?(i[1]=Math.asin(-s(A,-1,1)),Math.abs(A)<.99999?(i[0]=Math.atan2(c,h),i[2]=Math.atan2(a,r)):(i[0]=0,i[2]=Math.atan2(-n,l))):"YZX"===t?(i[2]=Math.asin(s(a,-1,1)),Math.abs(a)<.99999?(i[0]=Math.atan2(-u,l),i[1]=Math.atan2(-A,r)):(i[0]=0,i[1]=Math.atan2(o,h))):"XZY"===t&&(i[2]=Math.asin(-s(n,-1,1)),Math.abs(n)<.99999?(i[0]=Math.atan2(c,l),i[1]=Math.atan2(o,r)):(i[0]=Math.atan2(-u,h),i[1]=0)),i},composeMat4:function(e,t,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:$.mat4();return $.quaternionToRotationMat4(t,s),$.scaleMat4v(i,s),$.translateMat4v(e,s),s},decomposeMat4:function(){var e=new X(3),t=new X(16);return function(i,s,r,n){e[0]=i[0],e[1]=i[1],e[2]=i[2];var o=$.lenVec3(e);e[0]=i[4],e[1]=i[5],e[2]=i[6];var a=$.lenVec3(e);e[8]=i[8],e[9]=i[9],e[10]=i[10];var l=$.lenVec3(e);$.determinantMat4(i)<0&&(o=-o),s[0]=i[12],s[1]=i[13],s[2]=i[14],t.set(i);var u=1/o,A=1/a,c=1/l;return t[0]*=u,t[1]*=u,t[2]*=u,t[4]*=A,t[5]*=A,t[6]*=A,t[8]*=c,t[9]*=c,t[10]*=c,$.mat4ToQuaternion(t,r),n[0]=o,n[1]=a,n[2]=l,this}}(),getColMat4:function(e,t){var i=4*t;return[e[i],e[i+1],e[i+2],e[i+3]]},setRowMat4:function(e,t,i){e[t]=i[0],e[t+4]=i[1],e[t+8]=i[2],e[t+12]=i[3]},lookAtMat4v:function(e,t,i,s){s||(s=$.mat4());var r,n,o,a,l,u,A,c,h,d,p=e[0],f=e[1],v=e[2],g=i[0],m=i[1],_=i[2],y=t[0],b=t[1],w=t[2];return p===y&&f===b&&v===w?$.identityMat4():(r=p-y,n=f-b,o=v-w,a=m*(o*=d=1/Math.sqrt(r*r+n*n+o*o))-_*(n*=d),l=_*(r*=d)-g*o,u=g*n-m*r,(d=Math.sqrt(a*a+l*l+u*u))?(a*=d=1/d,l*=d,u*=d):(a=0,l=0,u=0),A=n*u-o*l,c=o*a-r*u,h=r*l-n*a,(d=Math.sqrt(A*A+c*c+h*h))?(A*=d=1/d,c*=d,h*=d):(A=0,c=0,h=0),s[0]=a,s[1]=A,s[2]=r,s[3]=0,s[4]=l,s[5]=c,s[6]=n,s[7]=0,s[8]=u,s[9]=h,s[10]=o,s[11]=0,s[12]=-(a*p+l*f+u*v),s[13]=-(A*p+c*f+h*v),s[14]=-(r*p+n*f+o*v),s[15]=1,s)},lookAtMat4c:function(e,t,i,s,r,n,o,a,l){return $.lookAtMat4v([e,t,i],[s,r,n],[o,a,l],[])},orthoMat4c:function(e,t,i,s,r,n,o){o||(o=$.mat4());var a=t-e,l=s-i,u=n-r;return o[0]=2/a,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2/l,o[6]=0,o[7]=0,o[8]=0,o[9]=0,o[10]=-2/u,o[11]=0,o[12]=-(e+t)/a,o[13]=-(s+i)/l,o[14]=-(n+r)/u,o[15]=1,o},frustumMat4v:function(e,t,i){i||(i=$.mat4());var s=[e[0],e[1],e[2],0],r=[t[0],t[1],t[2],0];$.addVec4(r,s,Y),$.subVec4(r,s,Z);var n=2*s[2],o=Z[0],a=Z[1],l=Z[2];return i[0]=n/o,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=n/a,i[6]=0,i[7]=0,i[8]=Y[0]/o,i[9]=Y[1]/a,i[10]=-Y[2]/l,i[11]=-1,i[12]=0,i[13]=0,i[14]=-n*r[2]/l,i[15]=0,i},frustumMat4:function(e,t,i,s,r,n,o){o||(o=$.mat4());var a=t-e,l=s-i,u=n-r;return o[0]=2*r/a,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2*r/l,o[6]=0,o[7]=0,o[8]=(t+e)/a,o[9]=(s+i)/l,o[10]=-(n+r)/u,o[11]=-1,o[12]=0,o[13]=0,o[14]=-n*r*2/u,o[15]=0,o},perspectiveMat4:function(e,t,i,s,r){var n=[],o=[];return n[2]=i,o[2]=s,o[1]=n[2]*Math.tan(e/2),n[1]=-o[1],o[0]=o[1]*t,n[0]=-o[0],$.frustumMat4v(n,o,r)},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 i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec3(),s=t[0],r=t[1],n=t[2];return i[0]=e[0]*s+e[4]*r+e[8]*n+e[12],i[1]=e[1]*s+e[5]*r+e[9]*n+e[13],i[2]=e[2]*s+e[6]*r+e[10]*n+e[14],i},transformPoint4:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4();return i[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],i[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],i[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],i[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],i},transformPoints3:function(e,t,i){for(var s,r,n,o,a,l=i||[],u=t.length,A=e[0],c=e[1],h=e[2],d=e[3],p=e[4],f=e[5],v=e[6],g=e[7],m=e[8],_=e[9],y=e[10],b=e[11],w=e[12],B=e[13],x=e[14],P=e[15],C=0;C2&&void 0!==arguments[2]?arguments[2]:t,a=t.length,l=e[0],u=e[1],A=e[2];e[3];var c=e[4],h=e[5],d=e[6];e[7];var p=e[8],f=e[9],v=e[10];e[11];var g=e[12],m=e[13],_=e[14];for(e[15],i=0;i2&&void 0!==arguments[2]?arguments[2]:t,a=t.length,l=e[0],u=e[1],A=e[2],c=e[3],h=e[4],d=e[5],p=e[6],f=e[7],v=e[8],g=e[9],m=e[10],_=e[11],y=e[12],b=e[13],w=e[14],B=e[15];for(i=0;i3&&void 0!==arguments[3]?arguments[3]:e,r=Math.cos(i),n=Math.sin(i),o=e[0]-t[0],a=e[1]-t[1];return s[0]=o*r-a*n+t[0],s[1]=o*n+a*r+t[1],e},rotateVec3X:function(e,t,i,s){var r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[0],n[1]=r[1]*Math.cos(i)-r[2]*Math.sin(i),n[2]=r[1]*Math.sin(i)+r[2]*Math.cos(i),s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s},rotateVec3Y:function(e,t,i,s){var r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[2]*Math.sin(i)+r[0]*Math.cos(i),n[1]=r[1],n[2]=r[2]*Math.cos(i)-r[0]*Math.sin(i),s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s},rotateVec3Z:function(e,t,i,s){var r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[0]*Math.cos(i)-r[1]*Math.sin(i),n[1]=r[0]*Math.sin(i)+r[1]*Math.cos(i),n[2]=r[2],s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s},projectVec4:function(e,t){var i=1/e[3];return(t=t||$.vec2())[0]=e[0]*i,t[1]=e[1]*i,t},unprojectVec3:(R=new X(16),L=new X(16),U=new X(16),function(e,t,i,s){return this.transformVec3(this.mulMat4(this.inverseMat4(t,R),this.inverseMat4(i,L),U),e,s)}),lerpVec3:function(e,t,i,s,r,n){var o=n||$.vec3(),a=(e-t)/(i-t);return o[0]=s[0]+a*(r[0]-s[0]),o[1]=s[1]+a*(r[1]-s[1]),o[2]=s[2]+a*(r[2]-s[2]),o},lerpMat4:function(e,t,i,s,r,n){var o=n||$.mat4(),a=(e-t)/(i-t);return o[0]=s[0]+a*(r[0]-s[0]),o[1]=s[1]+a*(r[1]-s[1]),o[2]=s[2]+a*(r[2]-s[2]),o[3]=s[3]+a*(r[3]-s[3]),o[4]=s[4]+a*(r[4]-s[4]),o[5]=s[5]+a*(r[5]-s[5]),o[6]=s[6]+a*(r[6]-s[6]),o[7]=s[7]+a*(r[7]-s[7]),o[8]=s[8]+a*(r[8]-s[8]),o[9]=s[9]+a*(r[9]-s[9]),o[10]=s[10]+a*(r[10]-s[10]),o[11]=s[11]+a*(r[11]-s[11]),o[12]=s[12]+a*(r[12]-s[12]),o[13]=s[13]+a*(r[13]-s[13]),o[14]=s[14]+a*(r[14]-s[14]),o[15]=s[15]+a*(r[15]-s[15]),o},flatten:function(e){var t,i,s,r,n,o=[];for(t=0,i=e.length;t0&&void 0!==arguments[0]?arguments[0]:$.vec4();return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},eulerToQuaternion:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),s=e[0]*$.DEGTORAD/2,r=e[1]*$.DEGTORAD/2,n=e[2]*$.DEGTORAD/2,o=Math.cos(s),a=Math.cos(r),l=Math.cos(n),u=Math.sin(s),A=Math.sin(r),c=Math.sin(n);return"XYZ"===t?(i[0]=u*a*l+o*A*c,i[1]=o*A*l-u*a*c,i[2]=o*a*c+u*A*l,i[3]=o*a*l-u*A*c):"YXZ"===t?(i[0]=u*a*l+o*A*c,i[1]=o*A*l-u*a*c,i[2]=o*a*c-u*A*l,i[3]=o*a*l+u*A*c):"ZXY"===t?(i[0]=u*a*l-o*A*c,i[1]=o*A*l+u*a*c,i[2]=o*a*c+u*A*l,i[3]=o*a*l-u*A*c):"ZYX"===t?(i[0]=u*a*l-o*A*c,i[1]=o*A*l+u*a*c,i[2]=o*a*c-u*A*l,i[3]=o*a*l+u*A*c):"YZX"===t?(i[0]=u*a*l+o*A*c,i[1]=o*A*l+u*a*c,i[2]=o*a*c-u*A*l,i[3]=o*a*l-u*A*c):"XZY"===t&&(i[0]=u*a*l-o*A*c,i[1]=o*A*l-u*a*c,i[2]=o*a*c+u*A*l,i[3]=o*a*l+u*A*c),i},mat4ToQuaternion:function(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec4(),s=e[0],r=e[4],n=e[8],o=e[1],a=e[5],l=e[9],u=e[2],A=e[6],c=e[10],h=s+a+c;return h>0?(t=.5/Math.sqrt(h+1),i[3]=.25/t,i[0]=(A-l)*t,i[1]=(n-u)*t,i[2]=(o-r)*t):s>a&&s>c?(t=2*Math.sqrt(1+s-a-c),i[3]=(A-l)/t,i[0]=.25*t,i[1]=(r+o)/t,i[2]=(n+u)/t):a>c?(t=2*Math.sqrt(1+a-s-c),i[3]=(n-u)/t,i[0]=(r+o)/t,i[1]=.25*t,i[2]=(l+A)/t):(t=2*Math.sqrt(1+c-s-a),i[3]=(o-r)/t,i[0]=(n+u)/t,i[1]=(l+A)/t,i[2]=.25*t),i},vec3PairToQuaternion:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),s=Math.sqrt($.dotVec3(e,e)*$.dotVec3(t,t)),r=s+$.dotVec3(e,t);return r<1e-8*s?(r=0,Math.abs(e[0])>Math.abs(e[2])?(i[0]=-e[1],i[1]=e[0],i[2]=0):(i[0]=0,i[1]=-e[2],i[2]=e[1])):$.cross3Vec3(e,t,i),i[3]=r,$.normalizeQuaternion(i)},angleAxisToQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec4(),i=e[3]/2,s=Math.sin(i);return t[0]=s*e[0],t[1]=s*e[1],t[2]=s*e[2],t[3]=Math.cos(i),t},quaternionToEuler:function(){var e=new X(16);return function(t,i,s){return s=s||$.vec3(),$.quaternionToRotationMat4(t,e),$.mat4ToEuler(e,i,s),s}}(),mulQuaternions:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),s=e[0],r=e[1],n=e[2],o=e[3],a=t[0],l=t[1],u=t[2],A=t[3];return i[0]=o*a+s*A+r*u-n*l,i[1]=o*l+r*A+n*a-s*u,i[2]=o*u+n*A+s*l-r*a,i[3]=o*A-s*a-r*l-n*u,i},vec3ApplyQuaternion:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec3(),s=t[0],r=t[1],n=t[2],o=e[0],a=e[1],l=e[2],u=e[3],A=u*s+a*n-l*r,c=u*r+l*s-o*n,h=u*n+o*r-a*s,d=-o*s-a*r-l*n;return i[0]=A*u+d*-o+c*-l-h*-a,i[1]=c*u+d*-a+h*-o-A*-l,i[2]=h*u+d*-l+A*-a-c*-o,i},quaternionToMat4:function(e,t){t=$.identityMat4(t);var i=e[0],s=e[1],r=e[2],n=e[3],o=2*i,a=2*s,l=2*r,u=o*n,A=a*n,c=l*n,h=o*i,d=a*i,p=l*i,f=a*s,v=l*s,g=l*r;return t[0]=1-(f+g),t[1]=d+c,t[2]=p-A,t[4]=d-c,t[5]=1-(h+g),t[6]=v+u,t[8]=p+A,t[9]=v-u,t[10]=1-(h+f),t},quaternionToRotationMat4:function(e,t){var i=e[0],s=e[1],r=e[2],n=e[3],o=i+i,a=s+s,l=r+r,u=i*o,A=i*a,c=i*l,h=s*a,d=s*l,p=r*l,f=n*o,v=n*a,g=n*l;return t[0]=1-(h+p),t[4]=A-g,t[8]=c+v,t[1]=A+g,t[5]=1-(u+p),t[9]=d-f,t[2]=c-v,t[6]=d+f,t[10]=1-(u+h),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,i=$.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i,t[3]=e[3]/i,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 $.normalizeQuaternion($.conjugateQuaternion(e,t))},quaternionToAngleAxis:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec4(),i=(e=$.normalizeQuaternion(e,q))[3],s=2*Math.acos(i),r=Math.sqrt(1-i*i);return r<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/r,t[1]=e[1]/r,t[2]=e[2]/r),t[3]=s,t},AABB3:function(e){return new X(e||6)},AABB2:function(e){return new X(e||4)},OBB3:function(e){return new X(e||32)},OBB2:function(e){return new X(e||16)},Sphere3:function(e,t,i,s){return new X([e,t,i,s])},transformOBB3:function(e,t){var i,s,r,n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,a=t.length,l=e[0],u=e[1],A=e[2],c=e[3],h=e[4],d=e[5],p=e[6],f=e[7],v=e[8],g=e[9],m=e[10],_=e[11],y=e[12],b=e[13],w=e[14],B=e[15];for(i=0;ia?o:a,n[1]+=l>u?l:u,n[2]+=A>c?A:c,Math.abs($.lenVec3(n))}}(),getAABB3Area:function(e){return(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2])},getAABB3Center:function(e,t){var i=t||$.vec3();return i[0]=(e[0]+e[3])/2,i[1]=(e[1]+e[4])/2,i[2]=(e[2]+e[5])/2,i},getAABB2Center:function(e,t){var i=t||$.vec2();return i[0]=(e[2]+e[0])/2,i[1]=(e[3]+e[1])/2,i},collapseAABB3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:$.AABB3();return e[0]=$.MAX_DOUBLE,e[1]=$.MAX_DOUBLE,e[2]=$.MAX_DOUBLE,e[3]=$.MIN_DOUBLE,e[4]=$.MIN_DOUBLE,e[5]=$.MIN_DOUBLE,e},AABB3ToOBB3:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.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 X(3);return function(t,i,s){i=i||$.AABB3();for(var r,n,o,a=$.MAX_DOUBLE,l=$.MAX_DOUBLE,u=$.MAX_DOUBLE,A=$.MIN_DOUBLE,c=$.MIN_DOUBLE,h=$.MIN_DOUBLE,d=0,p=t.length;dA&&(A=r),n>c&&(c=n),o>h&&(h=o);return i[0]=a,i[1]=l,i[2]=u,i[3]=A,i[4]=c,i[5]=h,i}}(),OBB3ToAABB3:function(e){for(var t,i,s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.AABB3(),n=$.MAX_DOUBLE,o=$.MAX_DOUBLE,a=$.MAX_DOUBLE,l=$.MIN_DOUBLE,u=$.MIN_DOUBLE,A=$.MIN_DOUBLE,c=0,h=e.length;cl&&(l=t),i>u&&(u=i),s>A&&(A=s);return r[0]=n,r[1]=o,r[2]=a,r[3]=l,r[4]=u,r[5]=A,r},points3ToAABB3:function(e){for(var t,i,s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.AABB3(),n=$.MAX_DOUBLE,o=$.MAX_DOUBLE,a=$.MAX_DOUBLE,l=$.MIN_DOUBLE,u=$.MIN_DOUBLE,A=$.MIN_DOUBLE,c=0,h=e.length;cl&&(l=t),i>u&&(u=i),s>A&&(A=s);return r[0]=n,r[1]=o,r[2]=a,r[3]=l,r[4]=u,r[5]=A,r},points3ToSphere3:function(){var e=new X(3);return function(t,i){i=i||$.vec4();var s,r=0,n=0,o=0,a=t.length;for(s=0;su&&(u=l);return i[3]=u,i}}(),positions3ToSphere3:function(){var e=new X(3),t=new X(3);return function(i,s){s=s||$.vec4();var r,n=0,o=0,a=0,l=i.length,u=0;for(r=0;ru&&(u=A);return s[3]=u,s}}(),OBB3ToSphere3:function(){var e=new X(3),t=new X(3);return function(i,s){s=s||$.vec4();var r,n=0,o=0,a=0,l=i.length,u=l/4;for(r=0;rc&&(c=A);return s[3]=c,s}}(),getSphere3Center:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.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]:$.vec3(),i=0,s=0,r=0,n=0,o=e.length;nt[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]i&&(e[0]=i),e[1]>s&&(e[1]=s),e[2]>r&&(e[2]=r),e[3]0&&void 0!==arguments[0]?arguments[0]:$.AABB2();return e[0]=$.MAX_DOUBLE,e[1]=$.MAX_DOUBLE,e[2]=$.MIN_DOUBLE,e[3]=$.MIN_DOUBLE,e},point3AABB3Intersect:function(e,t){return e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(s=e[0]*i[0],r=e[0]*i[3]):(s=e[0]*i[3],r=e[0]*i[0]),e[1]>0?(s+=e[1]*i[1],r+=e[1]*i[4]):(s+=e[1]*i[4],r+=e[1]*i[1]),e[2]>0?(s+=e[2]*i[2],r+=e[2]*i[5]):(s+=e[2]*i[5],r+=e[2]*i[2]),s<=-t&&r<=-t?-1:s>=-t&&r>=-t?1:0},OBB3ToAABB2:function(e){for(var t,i,s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.AABB2(),n=$.MAX_DOUBLE,o=$.MAX_DOUBLE,a=$.MIN_DOUBLE,l=$.MIN_DOUBLE,u=0,A=e.length;ua&&(a=t),i>l&&(l=i);return r[0]=n,r[1]=o,r[2]=a,r[3]=l,r},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,r=.5*(e[0]+1),n=.5*(e[1]+1),o=.5*(e[2]+1),a=.5*(e[3]+1);return s[0]=Math.floor(r*t),s[1]=i-Math.floor(a*i),s[2]=Math.floor(o*t),s[3]=i-Math.floor(n*i),s},tangentQuadraticBezier:function(e,t,i,s){return 2*(1-e)*(i-t)+2*e*(s-i)},tangentQuadraticBezier3:function(e,t,i,s,r){return-3*t*(1-e)*(1-e)+3*i*(1-e)*(1-e)-6*e*i*(1-e)+6*e*s*(1-e)-3*e*e*s+3*e*e*r},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,i,s,r){var n=.5*(i-e),o=.5*(s-t),a=r*r;return(2*t-2*i+n+o)*(r*a)+(-3*t+3*i-2*n-o)*a+n*r+t},b2p0:function(e,t){var i=1-e;return i*i*t},b2p1:function(e,t){return 2*(1-e)*e*t},b2p2:function(e,t){return e*e*t},b2:function(e,t,i,s){return this.b2p0(e,t)+this.b2p1(e,i)+this.b2p2(e,s)},b3p0:function(e,t){var i=1-e;return i*i*i*t},b3p1:function(e,t){var i=1-e;return 3*i*i*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,i,s,r){return this.b3p0(e,t)+this.b3p1(e,i)+this.b3p2(e,s)+this.b3p3(e,r)},triangleNormal:function(e,t,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:$.vec3(),r=t[0]-e[0],n=t[1]-e[1],o=t[2]-e[2],a=i[0]-e[0],l=i[1]-e[1],u=i[2]-e[2],A=n*u-o*l,c=o*a-r*u,h=r*l-n*a,d=Math.sqrt(A*A+c*c+h*h);return 0===d?(s[0]=0,s[1]=0,s[2]=0):(s[0]=A/d,s[1]=c/d,s[2]=h/d),s},rayTriangleIntersect:function(){var e=new X(3),t=new X(3),i=new X(3),s=new X(3),r=new X(3);return function(n,o,a,l,u,A){A=A||$.vec3();var c=$.subVec3(l,a,e),h=$.subVec3(u,a,t),d=$.cross3Vec3(o,h,i),p=$.dotVec3(c,d);if(p<1e-6)return null;var f=$.subVec3(n,a,s),v=$.dotVec3(f,d);if(v<0||v>p)return null;var g=$.cross3Vec3(f,c,r),m=$.dotVec3(o,g);if(m<0||v+m>p)return null;var _=$.dotVec3(h,g)/p;return A[0]=n[0]+_*o[0],A[1]=n[1]+_*o[1],A[2]=n[2]+_*o[2],A}}(),rayPlaneIntersect:function(){var e=new X(3),t=new X(3),i=new X(3),s=new X(3);return function(r,n,o,a,l,u){u=u||$.vec3(),n=$.normalizeVec3(n,e);var A=$.subVec3(a,o,t),c=$.subVec3(l,o,i),h=$.cross3Vec3(A,c,s);$.normalizeVec3(h,h);var d=-$.dotVec3(o,h),p=-($.dotVec3(r,h)+d)/$.dotVec3(n,h);return u[0]=r[0]+p*n[0],u[1]=r[1]+p*n[1],u[2]=r[2]+p*n[2],u}}(),cartesianToBarycentric:function(){var e=new X(3),t=new X(3),i=new X(3);return function(s,r,n,o,a){var l=$.subVec3(o,r,e),u=$.subVec3(n,r,t),A=$.subVec3(s,r,i),c=$.dotVec3(l,l),h=$.dotVec3(l,u),d=$.dotVec3(l,A),p=$.dotVec3(u,u),f=$.dotVec3(u,A),v=c*p-h*h;if(0===v)return null;var g=1/v,m=(p*d-h*f)*g,_=(c*f-h*d)*g;return a[0]=1-m-_,a[1]=_,a[2]=m,a}}(),barycentricInsideTriangle:function(e){var t=e[1],i=e[2];return i>=0&&t>=0&&i+t<1},barycentricToCartesian:function(e,t,i,s){var r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:$.vec3(),n=e[0],o=e[1],a=e[2];return r[0]=t[0]*n+i[0]*o+s[0]*a,r[1]=t[1]*n+i[1]*o+s[1]*a,r[2]=t[2]*n+i[2]*o+s[2]*a,r},mergeVertices:function(e,t,i,s){var r,n,o,a,l,u,A={},c=[],h=[],d=t?[]:null,p=i?[]:null,f=[],v=Math.pow(10,4),g=0;for(l=0,u=e.length;l>24&255,o=c>>16&255,n=c>>8&255,r=255&c,s=3*t[p],u[h++]=e[s],u[h++]=e[s+1],u[h++]=e[s+2],A[d++]=r,A[d++]=n,A[d++]=o,A[d++]=a,s=3*t[p+1],u[h++]=e[s],u[h++]=e[s+1],u[h++]=e[s+2],A[d++]=r,A[d++]=n,A[d++]=o,A[d++]=a,s=3*t[p+2],u[h++]=e[s],u[h++]=e[s+1],u[h++]=e[s+2],A[d++]=r,A[d++]=n,A[d++]=o,A[d++]=a,c++;return{positions:u,colors:A}},faceToVertexNormals:function(e,t){var i,s,r,n,o,a,l,u,A,c,h,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},p=d.smoothNormalsAngleThreshold||20,f={},v=[],g={},m=4,_=Math.pow(10,m);for(l=0,A=e.length;ll[3]&&(l[3]=r[h]),r[h+1]l[4]&&(l[4]=r[h+1]),r[h+2]l[5]&&(l[5]=r[h+2])}if(i.length<20||n>10)return u.triangles=i,u.leaf=!0,u;e[0]=l[3]-l[0],e[1]=l[4]-l[1],e[2]=l[5]-l[2];var d=0;e[1]>e[d]&&(d=1),e[2]>e[d]&&(d=2),u.splitDim=d;var p=(l[d]+l[d+3])/2,f=new Array(i.length),v=0,g=new Array(i.length),m=0;for(o=0,a=i.length;o2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),s=0,r=e.length;s2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),s=0,r=e.length;s=0?1:-1),s=(1-Math.abs(i))*(s>=0?1:-1));var n=Math.sqrt(i*i+s*s+r*r);return t[0]=i/n,t[1]=s/n,t[2]=r/n,t},octDecodeVec2s:function(e,t){for(var i=0,s=0,r=e.length;i=0?1:-1),o=(1-Math.abs(n))*(o>=0?1:-1));var l=Math.sqrt(n*n+o*o+a*a);t[s+0]=n/l,t[s+1]=o/l,t[s+2]=a/l,s+=3}return t}};$.buildEdgeIndices=function(){var e=[],t=[],i=[],s=[],r=[],n=0,o=new Uint16Array(3),a=new Uint16Array(3),l=new Uint16Array(3),u=$.vec3(),A=$.vec3(),c=$.vec3(),h=$.vec3(),d=$.vec3(),p=$.vec3(),f=$.vec3();return function(v,g,m,_){!function(r,n){var o,a,l,u,A,c,h={},d=Math.pow(10,4),p=0;for(A=0,c=r.length;AI)||(F=i[P.index1],E=i[P.index2],(!S&&F>65535||E>65535)&&(S=!0),k.push(F),k.push(E));return S?new Uint32Array(k):new Uint16Array(k)}}(),$.planeClipsPositions3=function(e,t,i){for(var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:3,r=0,n=i.length;r=this._maxTreeDepth)return e.entities=e.entities||[],void e.entities.push(t);if(e.left&&$.containsAABB3(e.left.aabb,s))this._insertEntity(e.left,t,i+1);else if(e.right&&$.containsAABB3(e.right.aabb,s))this._insertEntity(e.right,t,i+1);else{var r=e.aabb;ee[0]=r[3]-r[0],ee[1]=r[4]-r[1],ee[2]=r[5]-r[2];var n=0;if(ee[1]>ee[n]&&(n=1),ee[2]>ee[n]&&(n=2),!e.left){var o=r.slice();if(o[n+3]=(r[n]+r[n+3])/2,e.left={aabb:o},$.containsAABB3(o,s))return void this._insertEntity(e.left,t,i+1)}if(!e.right){var a=r.slice();if(a[n]=(r[n]+r[n+3])/2,e.right={aabb:a},$.containsAABB3(a,s))return void this._insertEntity(e.right,t,i+1)}e.entities=e.entities||[],e.entities.push(t)}}},{key:"destroy",value:function(){var e=this.viewer.scene;e.off(this._onModelLoaded),e.off(this._onModelUnloaded),this._root=null,this._needsRebuild=!0}}]),e}(),ie=function(){function e(){x(this,e),this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}return C(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}(),se={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 re=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],i=e[0].charCodeAt(0),s=i+e[1],r=i;r1&&void 0!==arguments[1]?arguments[1]:null;ce.push(e),ce.push(t)},this.runTasks=function(){for(var e,t,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1,s=(new Date).getTime(),r=0;ce.length>0&&(i<0||s0&&ae>0){var t=1e3/ae;fe+=t,de.push(t),de.length>=30&&(fe-=de.shift()),se.frame.fps=Math.round(fe/de.length)}for(var i in _e.scenes)_e.scenes[i].compile();be(e),pe=e};ve=function(){ye()},ge=100,me=Date.now()+ge,function e(){var t=Date.now()-me;ve(),me+=ge,setTimeout(e,Math.max(0,ge-t))}();function be(e){var t=_e.runTasks(e+10),i=_e.getNumTasks();se.frame.tasksRun=t,se.frame.tasksScheduled=i,se.frame.tasksBudget=10}!function e(){var t=Date.now();if(ae=t-pe,pe>0&&ae>0){var i=1e3/ae;fe+=i,de.push(i),de.length>=30&&(fe-=de.shift()),se.frame.fps=Math.round(fe/de.length)}be(t),function(e){for(var t in he.time=e,_e.scenes)if(_e.scenes.hasOwnProperty(t)){var i=_e.scenes[t];he.sceneId=t,he.startTime=i.startTime,he.deltaTime=null!=he.prevTime?he.time-he.prevTime:0,i.fire("tick",he,!0)}he.prevTime=e}(t),function(){var e,t,i,s,r,n=_e.scenes,o=!1;for(r in n)n.hasOwnProperty(r)&&(e=n[r],(t=ue[r])||(t=ue[r]={}),i=e.ticksPerOcclusionTest,t.ticksPerOcclusionTest!==i&&(t.ticksPerOcclusionTest=i,t.renderCountdown=i),--e.occlusionTestCountdown<=0&&(e.doOcclusionTest(),e.occlusionTestCountdown=i),s=e.ticksPerRender,t.ticksPerRender!==s&&(t.ticksPerRender=s,t.renderCountdown=s),0==--t.renderCountdown&&(e.render(o),t.renderCountdown=s))}(),void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(ye):requestAnimationFrame(e)}();var we=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,e),this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=i.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=!!i.dontClear,this._renderer=this.scene._renderer,this.meta=i.meta||{},this.id=i.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 C(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,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==i&&(this._events[e]=t||!0);var s,r=this._eventSubs[e];if(r)for(var n in r)r.hasOwnProperty(n)&&(s=r[n],this._eventCallDepth++,this._eventCallDepth<300?s.callback.call(s.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,i){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new Q),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var s=this._eventSubs[e];s?this._eventSubsNum[e]++:(s={},this._eventSubs[e]=s,this._eventSubsNum[e]=1);var r=this._subIdMap.addItem();s[r]={callback:t,scope:i||this},this._subIdEvents[r]=e;var n=this._events[e];return void 0!==n&&t.call(i||this,n),r}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var i=this._eventSubs[t];i&&(delete i[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,i){var s=this,r=this.on(e,(function(e){s.off(r),t.call(i||this,e)}),i)}},{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+" "+le.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 i=e.component,s=e.sceneDefault,r=e.sceneSingleton,n=e.type,o=e.on,a=!1!==e.recompiles;if(i&&(le.isNumeric(i)||le.isString(i))){var l=i;if(!(i=this.scene.components[l]))return void this.error("Component not found: "+le.inQuotes(l))}if(!i)if(!0===r){var u=this.scene.types[n];for(var A in u)if(u.hasOwnProperty){i=u[A];break}if(!i)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===s&&!(i=this.scene[t]))return this.error("Scene has no default component for '"+t+"'"),null;if(i){if(i.scene.id!==this.scene.id)return void this.error("Not in same scene: "+i.type+" "+le.inQuotes(i.id));if(n&&!i.isType(n))return void this.error("Expected a "+n+" type or subtype: "+i.type+" "+le.inQuotes(i.id))}this._attachments||(this._attachments={});var c,h,d,p=this._attached[t];if(p){if(i&&p.id===i.id)return;var f=this._attachments[p.id];for(h=0,d=(c=f.subs).length;h=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}]),e}(),Me=C((function e(){x(this,e),this.planes=[new Ce,new Ce,new Ce,new Ce,new Ce,new Ce]}));function Fe(e,t,i){var s=$.mulMat4(i,t,Pe),r=s[0],n=s[1],o=s[2],a=s[3],l=s[4],u=s[5],A=s[6],c=s[7],h=s[8],d=s[9],p=s[10],f=s[11],v=s[12],g=s[13],m=s[14],_=s[15];e.planes[0].set(a-r,c-l,f-h,_-v),e.planes[1].set(a+r,c+l,f+h,_+v),e.planes[2].set(a-n,c-u,f-d,_-g),e.planes[3].set(a+n,c+u,f+d,_+g),e.planes[4].set(a-o,c-A,f-p,_-m),e.planes[5].set(a+o,c+A,f+p,_+m)}function Ee(e,t){var i=Me.INSIDE,s=Be,r=xe;s[0]=t[0],s[1]=t[1],s[2]=t[2],r[0]=t[3],r[1]=t[4],r[2]=t[5];for(var n=[s,r],o=0;o<6;++o){var a=e.planes[o];if(a.normal[0]*n[a.testVertex[0]][0]+a.normal[1]*n[a.testVertex[1]][1]+a.normal[2]*n[a.testVertex[2]][2]+a.offset<0)return Me.OUTSIDE;a.normal[0]*n[1-a.testVertex[0]][0]+a.normal[1]*n[1-a.testVertex[1]][1]+a.normal[2]*n[1-a.testVertex[2]][2]+a.offset<0&&(i=Me.INTERSECT)}return i}Me.INSIDE=0,Me.INTERSECT=1,Me.OUTSIDE=2;var ke=function(e){g(i,we);var t=_(i);function i(){var e,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(x(this,i),!s.viewer)throw"[MarqueePicker] Missing config: viewer";if(!s.objectsKdTree3)throw"[MarqueePicker] Missing config: objectsKdTree3";return(e=t.call(this,s.viewer.scene,s)).viewer=s.viewer,e._objectsKdTree3=s.objectsKdTree3,e._canvasMarqueeCorner1=$.vec2(),e._canvasMarqueeCorner2=$.vec2(),e._canvasMarquee=$.AABB2(),e._marqueeFrustum=new Me,e._marqueeFrustumProjMat=$.mat4(),e._pickMode=!1,e._marqueeElement=document.createElement("div"),document.body.appendChild(e._marqueeElement),e._marqueeElement.style.position="absolute",e._marqueeElement.style["z-index"]="40000005",e._marqueeElement.style.width="8px",e._marqueeElement.style.height="8px",e._marqueeElement.style.visibility="hidden",e._marqueeElement.style.top="0px",e._marqueeElement.style.left="0px",e._marqueeElement.style["box-shadow"]="0 2px 5px 0 #182A3D;",e._marqueeElement.style.opacity=1,e._marqueeElement.style["pointer-events"]="none",e}return C(i,[{key:"setMarqueeCorner1",value:function(e){this._canvasMarqueeCorner1.set(e),this._canvasMarqueeCorner2.set(e),this._updateMarquee()}},{key:"setMarqueeCorner2",value:function(e){this._canvasMarqueeCorner2.set(e),this._updateMarquee()}},{key:"setMarquee",value:function(e,t){this._canvasMarqueeCorner1.set(e),this._canvasMarqueeCorner2.set(t),this._updateMarquee()}},{key:"setMarqueeVisible",value:function(e){this._marqueVisible=e,this._marqueeElement.style.visibility=e?"visible":"hidden"}},{key:"getMarqueeVisible",value:function(){return this._marqueVisible}},{key:"setPickMode",value:function(e){if(e!==i.PICK_MODE_INSIDE&&e!==i.PICK_MODE_INTERSECTS)throw"Illegal MarqueePicker pickMode: must be MarqueePicker.PICK_MODE_INSIDE or MarqueePicker.PICK_MODE_INTERSECTS";e!==this._pickMode&&(this._marqueeElement.style["background-image"]=e===i.PICK_MODE_INSIDE?"url(\"data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='6' ry='6' stroke='%23333' stroke-width='4'/%3e%3c/svg%3e\")":"url(\"data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='6' ry='6' stroke='%23333' stroke-width='4' stroke-dasharray='6%2c 14' stroke-dashoffset='0' stroke-linecap='square'/%3e%3c/svg%3e\")",this._pickMode=e)}},{key:"getPickMode",value:function(){return this._pickMode}},{key:"clear",value:function(){this.fire("clear",{})}},{key:"pick",value:function(){var e=this;this._updateMarquee(),this._buildMarqueeFrustum();var t=[];return(this._canvasMarquee[2]-this._canvasMarquee[0]>3||this._canvasMarquee[3]-this._canvasMarquee[1]>3)&&function s(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Me.INTERSECT;if(n===Me.INTERSECT&&(n=Ee(e._marqueeFrustum,r.aabb)),n!==Me.OUTSIDE){if(r.entities)for(var o=r.entities,a=0,l=o.length;a3||i>3)&&c.pick()}})),document.addEventListener("mouseup",(function(e){s.getActive()&&0===e.button&&(clearTimeout(A),d&&(c.setMarqueeVisible(!1),d=!1,p=!1,f=!0,c.viewer.cameraControl.pointerEnabled=!0))}),!0),h.addEventListener("mousemove",(function(e){s.getActive()&&0===e.button&&p&&(clearTimeout(A),d&&(o=e.pageX,a=e.pageY,u=e.offsetX,c.setMarqueeVisible(!0),c.setMarqueeCorner2([o,a]),c.setPickMode(l1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this.viewer=t,this.scene=this.viewer.scene,this._circleDiv=document.createElement("div"),this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._circleDiv,this.viewer.scene.canvas.canvas),this._circleDiv.style.backgroundColor="transparent",this._circleDiv.style.border="2px solid green",this._circleDiv.style.borderRadius="50px",this._circleDiv.style.width="50px",this._circleDiv.style.height="50px",this._circleDiv.style.margin="-200px -200px",this._circleDiv.style.zIndex="100000",this._circleDiv.style.position="absolute",this._circleDiv.style.pointerEvents="none",this._circlePos=null,this._circleMaxRadius=200,this._circleMinRadius=2,this._active=!1!==i.active,this._visible=!1,this._running=!1,this._destroyed=!1}return C(e,[{key:"start",value:function(e){var t=this;if(!this._destroyed){this._circlePos=e,this._running=!1,this._circleRadius=this._circleMaxRadius,this._circleDiv.style.borderRadius="".concat(this._circleRadius,"px"),this._circleDiv.style.marginLeft="".concat(this._circlePos[0]-this._circleRadius,"px"),this._circleDiv.style.marginTop="".concat(this._circlePos[1]-this._circleRadius,"px");var i,s=this._circleMaxRadius;this._running=!0,requestAnimationFrame((function e(r){if(t._running){i||(i=r);var n=r-i,o=Math.min(n/300,1),a=s+(2-s)*o;t._circleRadius=a,t._circleDiv.style.width="".concat(t._circleRadius,"px"),t._circleDiv.style.height="".concat(t._circleRadius,"px"),t._circleDiv.style.marginLeft="".concat(t._circlePos[0]-t._circleRadius/2,"px"),t._circleDiv.style.marginTop="".concat(t._circlePos[1]-t._circleRadius/2,"px"),o<1&&requestAnimationFrame(e)}})),this._circleDiv.style.visibility="visible"}}},{key:"stop",value:function(){this._destroyed||(this._running=!1,this._circleRadius=this._circleMaxRadius,this._circleDiv.style.borderRadius="".concat(this._circleRadius,"px"),this._circleDiv.style.visibility="hidden")}},{key:"durationMs",get:function(){return this._durationMs},set:function(e){this.stop(),this._durationMs=e}},{key:"destroy",value:function(){this._destroyed||(this.stop(),document.body.removeChild(this._circleDiv),this._destroyed=!0)}}]),e}(),Se=function(){function e(t,i,s){x(this,e),this.id=s&&s.id?s.id:t,this.viewer=i,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,i.addPlugin(this)}return C(e,[{key:"scheduleTask",value:function(e){_e.scheduleTask(e,null)}},{key:"fire",value:function(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==i&&(this._events[e]=t||!0);var s,r=this._eventSubs[e];if(r)for(var n in r)r.hasOwnProperty(n)&&(s=r[n],this._eventCallDepth++,this._eventCallDepth<300?s.callback.call(s.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,i){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new Q),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var s=this._eventSubs[e];s?this._eventSubsNum[e]++:(s={},this._eventSubs[e]=s,this._eventSubsNum[e]=1);var r=this._subIdMap.addItem();s[r]={callback:t,scope:i||this},this._subIdEvents[r]=e;var n=this._events[e];return void 0!==n&&t.call(i||this,n),r}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var i=this._eventSubs[t];i&&(delete i[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,i){var s=this,r=this.on(e,(function(e){s.off(r),t.call(i||this,e)}),i)}},{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}(),Te=$.vec3(),Re=function(){var e=new Float64Array(16),t=new Float64Array(4),i=new Float64Array(4);return function(s,r,n){return n=n||e,t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,$.transformVec4(s,t,i),$.setMat4Translation(s,i,n),n.slice()}}();function Le(e,t,i){var s=Float32Array.from([e[0]])[0],r=e[0]-s,n=Float32Array.from([e[1]])[0],o=e[1]-n,a=Float32Array.from([e[2]])[0],l=e[2]-a;t[0]=s,t[1]=n,t[2]=a,i[0]=r,i[1]=o,i[2]=l}function Ue(e,t,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1e3,r=$.getPositionsCenter(e,Te),n=Math.round(r[0]/s)*s,o=Math.round(r[1]/s)*s,a=Math.round(r[2]/s)*s;i[0]=n,i[1]=o,i[2]=a;var l=0!==i[0]||0!==i[1]||0!==i[2];if(l)for(var u=0,A=e.length;u0?this.meshes[0]._colorize[3]/255:1},set:function(e){if(0!==this.meshes.length){var t=null!=e,i=this.meshes[0]._colorize[3],s=255;if(t){if(e<0?e=0:e>1&&(e=1),i===(s=Math.floor(255*e)))return}else if(i===(s=255))return;for(var r=0,n=this.meshes.length;r1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this._color=s.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=s.thickness||1,this._thicknessClickable=s.thicknessClickable||6,this._visible=!0,this._culled=!1;var r=this._wire,n=r.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===s.zIndex?"2000001":s.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",s.onContextMenu,t.appendChild(r);var o=this._wireClickable,a=o.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===s.zIndex?"2000002":s.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",s.onContextMenu,t.appendChild(o),s.onMouseOver&&o.addEventListener("mouseover",(function(e){s.onMouseOver(e,i)})),s.onMouseLeave&&o.addEventListener("mouseleave",(function(e){s.onMouseLeave(e,i)})),s.onMouseWheel&&o.addEventListener("wheel",(function(e){s.onMouseWheel(e,i)})),s.onMouseDown&&o.addEventListener("mousedown",(function(e){s.onMouseDown(e,i)})),s.onMouseUp&&o.addEventListener("mouseup",(function(e){s.onMouseUp(e,i)})),s.onMouseMove&&o.addEventListener("mousemove",(function(e){s.onMouseMove(e,i)})),s.onContextMenu&&o.addEventListener("contextmenu",(function(e){s.onContextMenu(e,i),e.preventDefault(),e.stopPropagation()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}return C(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,i=this._wire.style;i.width=Math.round(e)+"px",i.left=Math.round(this._x1)+"px",i.top=Math.round(this._y1)+"px",i["-webkit-transform"]="rotate("+t+"deg)",i["-moz-transform"]="rotate("+t+"deg)",i["-ms-transform"]="rotate("+t+"deg)",i["-o-transform"]="rotate("+t+"deg)",i.transform="rotate("+t+"deg)";var s=this._wireClickable.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)"}},{key:"setStartAndEnd",value:function(e,t,i,s){this._x1=e,this._y1=t,this._x2=i,this._y2=s,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){this._visible!==e&&(this._visible=!!e,this._wire.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setCulled",value:function(e){this._culled!==e&&(this._culled=!!e,this._wire.style.visibility=this._visible&&!this._culled?"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}(),it=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=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",this._visible=!!s.visible,this._culled=!1;var r=this._dot,n=r.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===s.zIndex?"40000005":s.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==s.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",s.onContextMenu,t.appendChild(r);var o=this._dotClickable,a=o.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===s.zIndex?"40000007":s.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",s.onContextMenu,t.appendChild(o),o.addEventListener("click",(function(e){t.dispatchEvent(new MouseEvent("mouseover",e))})),s.onMouseOver&&o.addEventListener("mouseover",(function(e){s.onMouseOver(e,i),t.dispatchEvent(new MouseEvent("mouseover",e))})),s.onMouseLeave&&o.addEventListener("mouseleave",(function(e){s.onMouseLeave(e,i)})),s.onMouseWheel&&o.addEventListener("wheel",(function(e){s.onMouseWheel(e,i)})),s.onMouseDown&&o.addEventListener("mousedown",(function(e){s.onMouseDown(e,i)})),s.onMouseUp&&o.addEventListener("mouseup",(function(e){s.onMouseUp(e,i)})),s.onMouseMove&&o.addEventListener("mousemove",(function(e){s.onMouseMove(e,i)})),s.onContextMenu&&o.addEventListener("contextmenu",(function(e){s.onContextMenu(e,i),e.preventDefault(),e.stopPropagation()})),this.setPos(s.x||0,s.y||0),this.setFillColor(s.fillColor),this.setBorderColor(s.borderColor)}return C(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var i=this._dot.style;i.left=Math.round(e)-4+"px",i.top=Math.round(t)-4+"px";var s=this._dotClickable.style;s.left=Math.round(e)-9+"px",s.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&&!this._culled?"visible":"hidden")}},{key:"setCulled",value:function(e){this._culled!==e&&(this._culled=!!e,this._dot.style.visibility=this._visible&&!this._culled?"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}(),st=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this._highlightClass="viewer-ruler-label-highlighted",this._prefix=s.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 r=this._label,n=r.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===s.zIndex?"5000005":s.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,s.onContextMenu,r.innerText="",t.appendChild(r),this.setPos(s.x||0,s.y||0),this.setFillColor(s.fillColor),this.setBorderColor(s.fillColor),this.setText(s.text),s.onMouseOver&&r.addEventListener("mouseover",(function(e){s.onMouseOver(e,i),e.preventDefault()})),s.onMouseLeave&&r.addEventListener("mouseleave",(function(e){s.onMouseLeave(e,i),e.preventDefault()})),s.onMouseWheel&&r.addEventListener("wheel",(function(e){s.onMouseWheel(e,i)})),s.onMouseDown&&r.addEventListener("mousedown",(function(e){s.onMouseDown(e,i),e.stopPropagation()})),s.onMouseUp&&r.addEventListener("mouseup",(function(e){s.onMouseUp(e,i),e.stopPropagation()})),s.onMouseMove&&r.addEventListener("mousemove",(function(e){s.onMouseMove(e,i)})),s.onContextMenu&&r.addEventListener("contextmenu",(function(e){s.onContextMenu(e,i),e.preventDefault(),e.stopPropagation(),console.log("Label context menu")}))}return C(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var i=this._label.style;i.left=Math.round(e)-20+"px",i.top=Math.round(t)-12+"px"}},{key:"setPosOnWire",value:function(e,t,i,s){var r=e+.5*(i-e),n=t+.5*(s-t),o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(n)-12+"px"}},{key:"setPosBetweenWires",value:function(e,t,i,s,r,n){var o=(e+i+r)/3,a=(t+s+n)/3,l=this._label.style;l.left=Math.round(o)-20+"px",l.top=Math.round(a)-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}(),rt=$.vec3(),nt=$.vec3(),ot=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,e.viewer.scene,r)).plugin=e,s._container=r.container,!s._container)throw"config missing: container";s._color=r.color||e.defaultColor;var n=s.plugin.viewer.scene;s._originMarker=new et(n,r.origin),s._cornerMarker=new et(n,r.corner),s._targetMarker=new et(n,r.target),s._originWorld=$.vec3(),s._cornerWorld=$.vec3(),s._targetWorld=$.vec3(),s._wp=new Float64Array(12),s._vp=new Float64Array(12),s._pp=new Float64Array(12),s._cp=new Int16Array(6);var o=r.onMouseOver?function(e){r.onMouseOver(e,b(s)),s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,a=r.onMouseLeave?function(e){r.onMouseLeave(e,b(s)),s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,l=r.onContextMenu?function(e){r.onContextMenu(e,b(s))}:null,u=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))},A=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},c=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},h=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))};return s._originDot=new it(s._container,{fillColor:s._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:u,onMouseDown:A,onMouseUp:c,onMouseMove:h,onContextMenu:l}),s._cornerDot=new it(s._container,{fillColor:s._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:u,onMouseDown:A,onMouseUp:c,onMouseMove:h,onContextMenu:l}),s._targetDot=new it(s._container,{fillColor:s._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:u,onMouseDown:A,onMouseUp:c,onMouseMove:h,onContextMenu:l}),s._originWire=new tt(s._container,{color:s._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:o,onMouseLeave:a,onMouseWheel:u,onMouseDown:A,onMouseUp:c,onMouseMove:h,onContextMenu:l}),s._targetWire=new tt(s._container,{color:s._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:u,onMouseDown:A,onMouseUp:c,onMouseMove:h,onContextMenu:l}),s._angleLabel=new st(s._container,{fillColor:s._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:o,onMouseLeave:a,onMouseWheel:u,onMouseDown:A,onMouseUp:c,onMouseMove:h,onContextMenu:l}),s._wpDirty=!1,s._vpDirty=!1,s._cpDirty=!1,s._visible=!1,s._originVisible=!1,s._cornerVisible=!1,s._targetVisible=!1,s._originWireVisible=!1,s._targetWireVisible=!1,s._angleVisible=!1,s._labelsVisible=!1,s._clickable=!1,s._originMarker.on("worldPos",(function(e){s._originWorld.set(e||[0,0,0]),s._wpDirty=!0,s._needUpdate(0)})),s._cornerMarker.on("worldPos",(function(e){s._cornerWorld.set(e||[0,0,0]),s._wpDirty=!0,s._needUpdate(0)})),s._targetMarker.on("worldPos",(function(e){s._targetWorld.set(e||[0,0,0]),s._wpDirty=!0,s._needUpdate(0)})),s._onViewMatrix=n.camera.on("viewMatrix",(function(){s._vpDirty=!0,s._needUpdate(0)})),s._onProjMatrix=n.camera.on("projMatrix",(function(){s._cpDirty=!0,s._needUpdate()})),s._onCanvasBoundary=n.canvas.on("boundary",(function(){s._cpDirty=!0,s._needUpdate(0)})),s._onSectionPlaneUpdated=n.on("sectionPlaneUpdated",(function(){s._sectionPlanesDirty=!0,s._needUpdate()})),s.approximate=r.approximate,s.visible=r.visible,s.originVisible=r.originVisible,s.cornerVisible=r.cornerVisible,s.targetVisible=r.targetVisible,s.originWireVisible=r.originWireVisible,s.targetWireVisible=r.targetWireVisible,s.angleVisible=r.angleVisible,s.labelsVisible=r.labelsVisible,s}return C(i,[{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&&($.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._sectionPlanesDirty){if(this._isSliced(this._wp))return this._angleLabel.setCulled(!0),this._originWire.setCulled(!0),this._targetWire.setCulled(!0),this._originDot.setCulled(!0),this._cornerDot.setCulled(!0),void this._targetDot.setCulled(!0);this._angleLabel.setCulled(!1),this._originWire.setCulled(!1),this._targetWire.setCulled(!1),this._originDot.setCulled(!1),this._cornerDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}if(this._cpDirty){var t=-.3,i=this._originMarker.viewPos[2],s=this._cornerMarker.viewPos[2],r=this._targetMarker.viewPos[2];if(i>t||s>t||r>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);$.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var n=this._pp,o=this._cp,a=e.canvas.canvas.getBoundingClientRect(),l=this._container.getBoundingClientRect(),u=a.top-l.top,A=a.left-l.left,c=e.canvas.boundary,h=c[2],d=c[3],p=0,f=0,v=n.length;f1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e.viewer.scene))._canvasToPagePos=r.canvasToPagePos,s.pointerLens=r.pointerLens,s._active=!1,s._mouseState=0,s._currentAngleMeasurement=null,s._initMarkerDiv(),s._onMouseHoverSurface=null,s._onHoverNothing=null,s._onPickedNothing=null,s._onPickedSurface=null,s._onInputMouseDown=null,s._onInputMouseUp=null,s._snapping=!1!==r.snapping,s._attachPlugin(e,r),s}return C(i,[{key:"_initMarkerDiv",value:function(){var e=document.createElement("div");e.setAttribute("id","myMarkerDiv");var t=this.scene.canvas.canvas;t.parentNode.insertBefore(e,t),e.style.background="black",e.style.border="2px solid blue",e.style.borderRadius="10px",e.style.width="5px",e.style.height="5px",e.style.top="-200px",e.style.left="-200px",e.style.margin="0 0",e.style.zIndex="100",e.style.position="absolute",e.style.pointerEvents="none",this.markerDiv=e}},{key:"_destroyMarkerDiv",value:function(){if(this._markerDiv){var e=document.getElementById("myMarkerDiv");e.parentNode.removeChild(e),this._markerDiv=null}}},{key:"_attachPlugin",value:function(e){this.angleMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){this.markerDiv||this._initMarkerDiv(),this.angleMeasurementsPlugin;var t=this.scene;t.input;var i=t.canvas.canvas,s=this.angleMeasurementsPlugin.viewer.cameraControl,r=this.pointerLens,n=!1,o=null,a=0,l=0,u=$.vec3(),A=$.vec2();this._currentAngleMeasurement=null;var c=function e(t){return t.offsetTop+(t.offsetParent&&t.offsetParent!==i.parentNode&&e(t.offsetParent))},h=function e(t){return t.offsetLeft+(t.offsetParent&&t.offsetParent!==i.parentNode&&e(t.offsetParent))},d=$.vec2();this._onMouseHoverSurface=s.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(function(t){t.snappedToVertex||t.snappedToEdge?(r&&(r.visible=!0,r.canvasPos=t.canvasPos,r.snappedCanvasPos=t.snappedCanvasPos||t.canvasPos,r.snapped=!0),e.markerDiv.style.background="greenyellow",e.markerDiv.style.border="2px solid green"):(r&&(r.visible=!0,r.canvasPos=t.canvasPos,r.snappedCanvasPos=t.canvasPos,r.snapped=!1),e.markerDiv.style.background="pink",e.markerDiv.style.border="2px solid red");var s=t.snappedCanvasPos||t.canvasPos;switch(n=!0,o=t.entity,u.set(t.worldPos),A.set(s),e._mouseState){case 0:e._canvasToPagePos?(e._canvasToPagePos(i,s,d),e.markerDiv.style.left="".concat(d[0]-5,"px"),e.markerDiv.style.top="".concat(d[1]-5,"px")):(e.markerDiv.style.left="".concat(h(i)+s[0]-5,"px"),e.markerDiv.style.top="".concat(c(i)+s[1]-5,"px"));break;case 1:e._currentAngleMeasurement&&(e._currentAngleMeasurement.originWireVisible=!0,e._currentAngleMeasurement.targetWireVisible=!1,e._currentAngleMeasurement.cornerVisible=!0,e._currentAngleMeasurement.angleVisible=!1,e._currentAngleMeasurement.corner.worldPos=t.worldPos,e._currentAngleMeasurement.corner.entity=t.entity),e.markerDiv.style.left="-10000px",e.markerDiv.style.top="-10000px",i.style.cursor="pointer";break;case 2:e._currentAngleMeasurement&&(e._currentAngleMeasurement.targetWireVisible=!0,e._currentAngleMeasurement.targetVisible=!0,e._currentAngleMeasurement.angleVisible=!0,e._currentAngleMeasurement.target.worldPos=t.worldPos,e._currentAngleMeasurement.target.entity=t.entity),e.markerDiv.style.left="-10000px",e.markerDiv.style.top="-10000px",i.style.cursor="pointer"}})),i.addEventListener("mousedown",this._onMouseDown=function(e){1===e.which&&(a=e.clientX,l=e.clientY)}),i.addEventListener("mouseup",this._onMouseUp=function(t){if(1===t.which&&!(t.clientX>a+20||t.clientXl+20||t.clientY1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"AngleMeasurements",e))._container=r.container||document.body,s._defaultControl=null,s._measurements={},s.defaultColor=void 0!==r.defaultColor?r.defaultColor:"#00BBFF",s.defaultLabelsVisible=!1!==r.defaultLabelsVisible,s.zIndex=r.zIndex||1e4,s._onMouseOver=function(e,t){s.fire("mouseOver",{plugin:b(s),angleMeasurement:t,measurement:t,event:e})},s._onMouseLeave=function(e,t){s.fire("mouseLeave",{plugin:b(s),angleMeasurement:t,measurement:t,event:e})},s._onContextMenu=function(e,t){s.fire("contextMenu",{plugin:b(s),angleMeasurement:t,measurement:t,event:e})},s}return C(i,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){}},{key:"control",get:function(){return this._defaultControl||(this._defaultControl=new lt(this,{})),this._defaultControl}},{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 i=t.origin,s=t.corner,r=t.target,n=new ot(this,{id:t.id,plugin:this,container:this._container,origin:{entity:i.entity,worldPos:i.worldPos},corner:{entity:s.entity,worldPos:s.worldPos},target:{entity:r.entity,worldPos:r.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[n.id]=n,n.on("destroyed",(function(){delete e._measurements[n.id]})),n.clickable=!0,this.fire("measurementCreated",n),n}},{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,i=Object.entries(this.measurements);t1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e.viewer.scene)).pointerLens=r.pointerLens,s.pointerCircle=new De(e.viewer),s._active=!1;var n=document.createElement("div"),o=s.scene.canvas.canvas;return o.parentNode.insertBefore(n,o),n.style.background="black",n.style.border="2px solid blue",n.style.borderRadius="10px",n.style.width="5px",n.style.height="5px",n.style.margin="-200px -200px",n.style.zIndex="100",n.style.position="absolute",n.style.pointerEvents="none",s.markerDiv=n,s._currentAngleMeasurement=null,s._onCanvasTouchStart=null,s._onCanvasTouchEnd=null,s._longTouchTimeoutMs=300,s._snapping=!1!==r.snapping,s._touchState=0,s._attachPlugin(e,r),s}return C(i,[{key:"_attachPlugin",value:function(e){this.angleMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){var t=this.plugin,i=this.scene,s=i.canvas.canvas;t.pointerLens;var r=$.vec3(),n=20,o=null;this._touchState=0;var a=$.vec2(),l=$.vec2(),u=$.vec2(),A=null,c=function(){e.plugin.viewer.cameraControl.active=!1},h=function(){e.plugin.viewer.cameraControl.active=!0};s.addEventListener("touchstart",this._onCanvasTouchStart=function(s){var u=s.touches.length;if(1===u){var d=s.touches[0],p=d.clientX,f=d.clientY;switch(a.set([p,f]),l.set([p,f]),e._touchState){case 0:if(1!==u&&null!==o)return o&&(clearTimeout(o),o=null),e._currentAngleMeasurement&&(e._currentAngleMeasurement.destroy(),e._currentAngleMeasurement=null),h(),void(e._touchState=0);var v=i.pick({canvasPos:l,snapToVertex:e._snapping,snapToEdge:e._snapping});if(v&&v.snapped)r.set(v.worldPos),e.pointerCircle.start(v.snappedCanvasPos);else{var g=i.pick({canvasPos:l,pickSurface:!0});if(!g||!g.worldPos)return;r.set(g.worldPos),e.pointerCircle.start(g.canvasPos)}o=setTimeout((function(){1!==u||l[0]>a[0]+n||l[0]a[1]+n||l[1]a[0]+n||l[0]a[1]+n||l[1]a[0]+n||l[0]a[1]+n||l[1]a[0]+n||da[1]+n||pa[0]+n||da[1]+n||pa[0]+n||da[1]+n||p

";le.isArray(t)&&(t=t.join("")),t=this._renderTemplate(t.trim());var i=document.createRange().createContextualFragment(t);this._marker=i.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 s=this._labelHTML||"

";le.isArray(s)&&(s=s.join("")),s=this._renderTemplate(s.trim());var r=document.createRange().createContextualFragment(s);this._label=r.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],i=e[1],s=this.canvasPos;this._marker.style.left=Math.floor(t+s[0])-12+"px",this._marker.style.top=Math.floor(i+s[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+s[0]+20)+"px",this._label.style.top=Math.floor(i+s[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 i=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),i)}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 i=e[t];this.setField(t,i)}}},{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),f(w(i.prototype),"destroy",this).call(this)}}]),i}(),ht=$.vec3(),dt=$.vec3(),pt=$.vec3(),ft=function(e){g(i,Se);var t=_(i);function i(e,s){var r;return x(this,i),(r=t.call(this,"Annotations",e))._labelHTML=s.labelHTML||"
",r._markerHTML=s.markerHTML||"
",r._container=s.container||document.body,r._values=s.values||{},r.annotations={},r.surfaceOffset=s.surfaceOffset,r}return C(i,[{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,i,s=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 r=e.pickResult;if(r.worldPos&&r.worldNormal){var n=$.normalizeVec3(r.worldNormal,ht),o=$.mulVec3Scalar(n,this._surfaceOffset,dt);t=$.addVec3(r.worldPos,o,pt),i=r.entity}else this.error("Param 'pickResult' does not have both worldPos and worldNormal")}else t=e.worldPos,i=e.entity;var a=null;e.markerElementId&&((a=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 ct(this.viewer.scene,{id:e.id,plugin:this,entity:i,worldPos:t,container:this._container,markerElement:a,labelElement:l,markerHTML:e.markerHTML||this._markerHTML,labelHTML:e.labelHTML||this._labelHTML,occludable:e.occludable,values:le.apply(e.values,le.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 s.annotations[u.id],s.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,i=e.length;t1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._canvas=r.canvas,s._element=null,s._isCustom=!1,r.elementId&&(s._element=document.getElementById(r.elementId),s._element?s._adjustPosition():s.error("Can't find given Spinner HTML element: '"+r.elementId+"' - will automatically create default element")),s._element||s._createDefaultSpinner(),s.processes=0,s}return C(i,[{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,i=t.style;i.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",i.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 i=this._element;i&&(i.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)}}]),i}(),gt=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],mt=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e,r))._backgroundColor=$.vec3([r.backgroundColor?r.backgroundColor[0]:1,r.backgroundColor?r.backgroundColor[1]:1,r.backgroundColor?r.backgroundColor[2]:1]),s._backgroundColorFromAmbientLight=!!r.backgroundColorFromAmbientLight,s.canvas=r.canvas,s.gl=null,s.webgl2=!1,s.transparent=!!r.transparent,s.contextAttr=r.contextAttr||{},s.contextAttr.alpha=s.transparent,s.contextAttr.preserveDrawingBuffer=!!s.contextAttr.preserveDrawingBuffer,s.contextAttr.stencil=!1,s.contextAttr.premultipliedAlpha=!!s.contextAttr.premultipliedAlpha,s.contextAttr.antialias=!1!==s.contextAttr.antialias,s.resolutionScale=r.resolutionScale,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary=[s.canvas.offsetLeft,s.canvas.offsetTop,s.canvas.clientWidth,s.canvas.clientHeight],s._initWebGL(r);var n=b(s);s.canvas.addEventListener("webglcontextlost",s._webglcontextlostListener=function(e){console.time("webglcontextrestored"),n.scene._webglContextLost(),n.fire("webglcontextlost"),e.preventDefault()},!1),s.canvas.addEventListener("webglcontextrestored",s._webglcontextrestoredListener=function(e){n._initWebGL(),n.gl&&(n.scene._webglContextRestored(n.gl),n.fire("webglcontextrestored",n.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);var o=!0,a=new ResizeObserver((function(e){var t,i=c(e);try{for(i.s();!(t=i.n()).done;){t.value.contentBoxSize&&(o=!0)}}catch(e){i.e(e)}finally{i.f()}}));return a.observe(s.canvas),s._tick=s.scene.on("tick",(function(){o&&(o=!1,n.canvas.width=Math.round(n.canvas.clientWidth*n._resolutionScale),n.canvas.height=Math.round(n.canvas.clientHeight*n._resolutionScale),n.boundary[0]=n.canvas.offsetLeft,n.boundary[1]=n.canvas.offsetTop,n.boundary[2]=n.canvas.clientWidth,n.boundary[3]=n.canvas.clientHeight,n.fire("boundary",n.boundary))})),s._spinner=new vt(s.scene,{canvas:s.canvas,elementId:r.spinnerElementId}),s}return C(i,[{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-"+$.createUUID(),t=document.getElementsByTagName("body")[0],i=document.createElement("div"),s=i.style;s.height="100%",s.width="100%",s.padding="0",s.margin="0",s.background="rgba(0,0,0,0);",s.float="left",s.left="0",s.top="0",s.position="absolute",s.opacity="1.0",s["z-index"]="-10000",i.innerHTML+='',t.appendChild(i),this.canvas=document.getElementById(e)}},{key:"_getElementXY",value:function(e){for(var t=0,i=0;e;)t+=e.offsetLeft-e.scrollLeft,i+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:i}}},{key:"_initWebGL",value:function(){if(!this.gl)for(var e=0;!this.gl&&e0?yt.FS_MAX_FLOAT_PRECISION="highp":wt.getShaderPrecisionFormat(wt.FRAGMENT_SHADER,wt.MEDIUM_FLOAT).precision>0?yt.FS_MAX_FLOAT_PRECISION="mediump":yt.FS_MAX_FLOAT_PRECISION="lowp":yt.FS_MAX_FLOAT_PRECISION="mediump",yt.DEPTH_BUFFER_BITS=wt.getParameter(wt.DEPTH_BITS),yt.MAX_TEXTURE_SIZE=wt.getParameter(wt.MAX_TEXTURE_SIZE),yt.MAX_CUBE_MAP_SIZE=wt.getParameter(wt.MAX_CUBE_MAP_TEXTURE_SIZE),yt.MAX_RENDERBUFFER_SIZE=wt.getParameter(wt.MAX_RENDERBUFFER_SIZE),yt.MAX_TEXTURE_UNITS=wt.getParameter(wt.MAX_COMBINED_TEXTURE_IMAGE_UNITS),yt.MAX_TEXTURE_IMAGE_UNITS=wt.getParameter(wt.MAX_TEXTURE_IMAGE_UNITS),yt.MAX_VERTEX_ATTRIBS=wt.getParameter(wt.MAX_VERTEX_ATTRIBS),yt.MAX_VERTEX_UNIFORM_VECTORS=wt.getParameter(wt.MAX_VERTEX_UNIFORM_VECTORS),yt.MAX_FRAGMENT_UNIFORM_VECTORS=wt.getParameter(wt.MAX_FRAGMENT_UNIFORM_VECTORS),yt.MAX_VARYING_VECTORS=wt.getParameter(wt.MAX_VARYING_VECTORS),wt.getSupportedExtensions().forEach((function(e){yt.SUPPORTED_EXTENSIONS[e]=!0})))}var Bt=function(){function e(){x(this,e),this.entity=null,this.primitive=null,this.primIndex=-1,this.pickSurfacePrecision=!1,this.touchInput=!1,this.snappedToEdge=!1,this.snappedToVertex=!1,this._origin=new Float64Array([0,0,0]),this._direction=new Float64Array([0,0,0]),this._indices=new Int32Array(3),this._localPos=new Float64Array([0,0,0]),this._worldPos=new Float64Array([0,0,0]),this._viewPos=new Float64Array([0,0,0]),this._canvasPos=new Int16Array([0,0]),this._snappedCanvasPos=new Int16Array([0,0]),this._bary=new Float64Array([0,0,0]),this._worldNormal=new Float64Array([0,0,0]),this._uv=new Float64Array([0,0]),this.reset()}return C(e,[{key:"canvasPos",get:function(){return this._gotCanvasPos?this._canvasPos:null},set:function(e){e?(this._canvasPos[0]=e[0],this._canvasPos[1]=e[1],this._gotCanvasPos=!0):this._gotCanvasPos=!1}},{key:"origin",get:function(){return this._gotOrigin?this._origin:null},set:function(e){e?(this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this._gotOrigin=!0):this._gotOrigin=!1}},{key:"direction",get:function(){return this._gotDirection?this._direction:null},set:function(e){e?(this._direction[0]=e[0],this._direction[1]=e[1],this._direction[2]=e[2],this._gotDirection=!0):this._gotDirection=!1}},{key:"indices",get:function(){return this.entity&&this._gotIndices?this._indices:null},set:function(e){e?(this._indices[0]=e[0],this._indices[1]=e[1],this._indices[2]=e[2],this._gotIndices=!0):this._gotIndices=!1}},{key:"localPos",get:function(){return this.entity&&this._gotLocalPos?this._localPos:null},set:function(e){e?(this._localPos[0]=e[0],this._localPos[1]=e[1],this._localPos[2]=e[2],this._gotLocalPos=!0):this._gotLocalPos=!1}},{key:"snappedCanvasPos",get:function(){return this._gotSnappedCanvasPos?this._snappedCanvasPos:null},set:function(e){e?(this._snappedCanvasPos[0]=e[0],this._snappedCanvasPos[1]=e[1],this._gotSnappedCanvasPos=!0):this._gotSnappedCanvasPos=!1}},{key:"worldPos",get:function(){return this._gotWorldPos?this._worldPos:null},set:function(e){e?(this._worldPos[0]=e[0],this._worldPos[1]=e[1],this._worldPos[2]=e[2],this._gotWorldPos=!0):this._gotWorldPos=!1}},{key:"viewPos",get:function(){return this.entity&&this._gotViewPos?this._viewPos:null},set:function(e){e?(this._viewPos[0]=e[0],this._viewPos[1]=e[1],this._viewPos[2]=e[2],this._gotViewPos=!0):this._gotViewPos=!1}},{key:"bary",get:function(){return this.entity&&this._gotBary?this._bary:null},set:function(e){e?(this._bary[0]=e[0],this._bary[1]=e[1],this._bary[2]=e[2],this._gotBary=!0):this._gotBary=!1}},{key:"worldNormal",get:function(){return this.entity&&this._gotWorldNormal?this._worldNormal:null},set:function(e){e?(this._worldNormal[0]=e[0],this._worldNormal[1]=e[1],this._worldNormal[2]=e[2],this._gotWorldNormal=!0):this._gotWorldNormal=!1}},{key:"uv",get:function(){return this.entity&&this._gotUV?this._uv:null},set:function(e){e?(this._uv[0]=e[0],this._uv[1]=e[1],this._gotUV=!0):this._gotUV=!1}},{key:"snapped",get:function(){return this.snappedToEdge||this.snappedToVertex}},{key:"reset",value:function(){this.entity=null,this.primIndex=-1,this.primitive=null,this.pickSurfacePrecision=!1,this._gotCanvasPos=!1,this._gotSnappedCanvasPos=!1,this._gotOrigin=!1,this._gotDirection=!1,this._gotIndices=!1,this._gotLocalPos=!1,this._gotWorldPos=!1,this._gotViewPos=!1,this._gotBary=!1,this._gotWorldNormal=!1,this._gotUV=!1,this.touchInput=!1,this.snappedToEdge=!1,this.snappedToVertex=!1}}]),e}(),xt=function(){function e(t,i,s){if(x(this,e),this.allocated=!1,this.compiled=!1,this.handle=t.createShader(i),this.handle){if(this.allocated=!0,t.shaderSource(this.handle,s),t.compileShader(this.handle),this.compiled=t.getShaderParameter(this.handle,t.COMPILE_STATUS),!this.compiled&&!t.isContextLost()){for(var r=s.split("\n"),n=[],o=0;o0&&"/"===t.charAt(i+1)&&(t=t.substring(0,i)),s.push(t);return s.join("\n")}function Et(e){console.error(e.join("\n"))}var kt=function(){function e(t,i){x(this,e),this.id=Mt.addItem({}),this.source=i,this.init(t)}return C(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 xt(e,e.VERTEX_SHADER,Ft(this.source.vertex)),this._fragmentShader=new xt(e,e.FRAGMENT_SHADER,Ft(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void Et(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void Et(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void Et(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void Et(this.errors);var t,i,s,r,n;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 Et(this.errors);var o=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(i=0;ithis.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}(),Dt=function(){function e(t,i){x(this,e),this.scene=t,this.aabb=$.AABB3(),this.origin=$.vec3(i),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 C(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)a._setVisible(!1);else{var l=a.canvasPos,u=l[0],A=l[1];u+10<0||A+10<0||u-10>s||A-10>r?a._setVisible(!1):!a.entity||a.entity.visible?a.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=a,this.pixels[n++]=u,this.pixels[n++]=A):a._setVisible(!0):a._setVisible(!1)}}}},{key:"_updateActiveSectionPlanes",value:function(){var e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(var i=0;i0,i=[];return i.push("#version 300 es"),i.push("// OcclusionTester vertex shader"),i.push("in vec3 position;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;")),t&&i.push("out vec4 vWorldPosition;"),i.push("void main(void) {"),i.push("vec4 worldPosition = vec4(position, 1.0); "),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&i.push(" vWorldPosition = worldPosition;"),i.push(" vec4 clipPos = projMatrix * viewPosition;"),i.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?i.push("vFragDepth = 1.0 + clipPos.w;"):i.push("clipPos.z += -0.001;"),i.push(" gl_Position = clipPos;"),i.push("}"),i}},{key:"_buildFragmentShaderSource",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// OcclusionTester fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;");for(var r=0;r 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),s.push("}"),s}},{key:"_buildProgram",value:function(){this._program&&this._program.destroy();var e=this._scene,t=e.canvas.gl,i=e._sectionPlanesState;if(this._program=new kt(t,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var s=this._program;this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,n=i.sectionPlanes.length;r0)for(var h=s.sectionPlanes,d=0;d= ( 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 s=new Float32Array([1,1,0,1,0,0,1,0]),r=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 It(i,i.ARRAY_BUFFER,r,r.length,3,i.STATIC_DRAW),this._uvBuf=new It(i,i.ARRAY_BUFFER,s,s.length,2,i.STATIC_DRAW),this._indicesBuf=new It(i,i.ELEMENT_ARRAY_BUFFER,n,n.length,1,i.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}(),Ot=new Float32Array(Gt(17,[0,1])),Nt=new Float32Array(Gt(17,[1,0])),Qt=new Float32Array(function(e,t){for(var i=[],s=0;s<=e;s++)i.push(jt(s,t));return i}(17,4)),Vt=new Float32Array(2),Ht=function(){function e(t){x(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 C(e,[{key:"init",value:function(){var e=this._scene.canvas.gl;if(this._program=new kt(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]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),s=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new It(e,e.ARRAY_BUFFER,i,i.length,3,e.STATIC_DRAW),this._uvBuf=new It(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new It(e,e.ELEMENT_ARRAY_BUFFER,s,s.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,i){var s=this;if(!this._programError){this._getInverseProjectMat||(this._getInverseProjectMat=function(){var e=!0;s._scene.camera.on("projMatrix",(function(){e=!0}));var t=$.mat4();return function(){return e&&$.inverseMat4(o.camera.projMatrix,t),t}}());var r=this._scene.canvas.gl,n=this._program,o=this._scene,a=r.drawingBufferWidth,l=r.drawingBufferHeight,u=o.camera.project._state,A=u.near,c=u.far;r.viewport(0,0,a,l),r.clearColor(0,0,0,1),r.enable(r.DEPTH_TEST),r.disable(r.BLEND),r.frontFace(r.CCW),r.clear(r.COLOR_BUFFER_BIT|r.DEPTH_BUFFER_BIT),n.bind(),Vt[0]=a,Vt[1]=l,r.uniform2fv(this._uViewport,Vt),r.uniform1f(this._uCameraNear,A),r.uniform1f(this._uCameraFar,c),r.uniform1f(this._uDepthCutoff,.01),0===i?r.uniform2fv(this._uSampleOffsets,Nt):r.uniform2fv(this._uSampleOffsets,Ot),r.uniform1fv(this._uSampleWeights,Qt);var h=e.getDepthTexture(),d=t.getTexture();n.bindTexture(this._uDepthTexture,h,0),n.bindTexture(this._uOcclusionTexture,d,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),r.drawElements(r.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}}},{key:"destroy",value:function(){this._program.destroy()}}]),e}();function jt(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function Gt(e,t){for(var i=[],s=0;s<=e;s++)i.push(t[0]*s),i.push(t[1]*s);return i}var zt=function(){function e(t,i,s){x(this,e),s=s||{},this.gl=i,this.allocated=!1,this.canvas=t,this.buffer=null,this.bound=!1,this.size=s.size,this._hasDepthTexture=!!s.depthTexture}return C(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(){if(this._touch.apply(this,arguments),!this.bound){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}}},{key:"createTexture",value:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,s=this.gl,r=s.createTexture();return s.bindTexture(s.TEXTURE_2D,r),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),i?s.texStorage2D(s.TEXTURE_2D,1,i,e,t):s.texImage2D(s.TEXTURE_2D,0,s.RGBA,e,t,0,s.RGBA,s.UNSIGNED_BYTE,null),r}},{key:"_touch",value:function(){var e,t,i=this,s=this.gl;if(this.size?(e=this.size[0],t=this.size[1]):(e=s.drawingBufferWidth,t=s.drawingBufferHeight),this.buffer){if(this.buffer.width===e&&this.buffer.height===t)return;this.buffer.textures.forEach((function(e){return s.deleteTexture(e)})),s.deleteFramebuffer(this.buffer.framebuf),s.deleteRenderbuffer(this.buffer.renderbuf)}for(var r,n=[],o=arguments.length,a=new Array(o),l=0;l0?n.push.apply(n,A(a.map((function(s){return i.createTexture(e,t,s)})))):n.push(this.createTexture(e,t)),this._hasDepthTexture&&(r=s.createTexture(),s.bindTexture(s.TEXTURE_2D,r),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texImage2D(s.TEXTURE_2D,0,s.DEPTH_COMPONENT32F,e,t,0,s.DEPTH_COMPONENT,s.FLOAT,null));var u=s.createRenderbuffer();s.bindRenderbuffer(s.RENDERBUFFER,u),s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_COMPONENT32F,e,t);var c=s.createFramebuffer();s.bindFramebuffer(s.FRAMEBUFFER,c);for(var h=0;h0&&s.drawBuffers(n.map((function(e,t){return s.COLOR_ATTACHMENT0+t}))),this._hasDepthTexture?s.framebufferTexture2D(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.TEXTURE_2D,r,0):s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,u),s.bindTexture(s.TEXTURE_2D,null),s.bindRenderbuffer(s.RENDERBUFFER,null),s.bindFramebuffer(s.FRAMEBUFFER,null),s.bindFramebuffer(s.FRAMEBUFFER,c),!s.isFramebuffer(c))throw"Invalid framebuffer";s.bindFramebuffer(s.FRAMEBUFFER,null);var d=s.checkFramebufferStatus(s.FRAMEBUFFER);switch(d){case s.FRAMEBUFFER_COMPLETE:break;case s.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case s.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case s.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case s.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+d}this.buffer={framebuf:c,renderbuf:u,texture:n[0],textures:n,depthTexture:r,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 i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Uint8Array,n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4,o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0,a=e,l=this.buffer.height?this.buffer.height-t-1:this.gl.drawingBufferHeight-t,u=new r(n),A=this.gl;return A.readBuffer(A.COLOR_ATTACHMENT0+o),A.readPixels(a,l,1,1,i||A.RGBA,s||A.UNSIGNED_BYTE,u,0),u}},{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,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Uint8Array,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:4,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,n=new i(this.buffer.width*this.buffer.height*s),o=this.gl;return o.readBuffer(o.COLOR_ATTACHMENT0+r),o.readPixels(0,0,this.buffer.width,this.buffer.height,e||o.RGBA,t||o.UNSIGNED_BYTE,n,0),n}},{key:"readImageAsCanvas",value:function(){var e=this.gl,t=this._getImageDataCache(),i=t.pixelData,s=t.canvas,r=t.imageData,n=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,i);for(var o=this.buffer.width,a=this.buffer.height,l=a/2|0,u=4*o,A=new Uint8Array(4*o),c=0;c0&&void 0!==arguments[0]?arguments[0]:Uint8Array,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4,i=this.buffer.width,s=this.buffer.height,r=this._imageDataCache;if(r&&(r.width===i&&r.height===s||(this._imageDataCache=null,r=null)),!r){var n=document.createElement("canvas"),o=n.getContext("2d");n.width=i,n.height=s,r={pixelData:new e(i*s*t),canvas:n,context:o,imageData:o.createImageData(i,s),width:i,height:s},this._imageDataCache=r}return r.context.resetTransform(),r}},{key:"unbind",value:function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.bound=!1}},{key:"getTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this;return this._texture||(this._texture={renderBuffer:this,bind:function(i){return!(!t.buffer||!t.buffer.textures[e])&&(t.gl.activeTexture(t.gl["TEXTURE"+i]),t.gl.bindTexture(t.gl.TEXTURE_2D,t.buffer.textures[e]),!0)},unbind:function(i){t.buffer&&t.buffer.textures[e]&&(t.gl.activeTexture(t.gl["TEXTURE"+i]),t.gl.bindTexture(t.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;this.buffer.textures.forEach((function(t){return e.deleteTexture(t)})),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}(),Wt=function(){function e(t){x(this,e),this.scene=t,this._renderBuffersBasic={},this._renderBuffersScaled={}}return C(e,[{key:"getRenderBuffer",value:function(e,t){var i=1===this.scene.canvas.resolutionScale?this._renderBuffersBasic:this._renderBuffersScaled,s=i[e];return s||(s=new zt(this.scene.canvas.canvas,this.scene.canvas.gl,t),i[e]=s),s}},{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 Kt(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];var i;switch(t){case"WEBGL_depth_texture":i=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":i=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":i=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":i=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:i=e.getExtension(t)}return e._cachedExtensions[t]=i,i}var Xt=function(e,t){t=t||{};var i=new _t(e),s=e.canvas.canvas,r=e.canvas.gl,n=!!t.transparent,o=t.alphaDepthMask,a=new Q({}),l={},u={},A=!0,c=!0,h=!0,d=!0,p=!0,f=!0,v=!0,g=!0,m=new Wt(e),_=!1,y=new Ut(e),b=new Ht(e);function w(){A&&(!function(){for(var e in l)if(l.hasOwnProperty(e)){var t=l[e],i=t.drawableMap,s=t.drawableListPreCull,r=0;for(var n in i)i.hasOwnProperty(n)&&(s[r++]=i[n]);s.length=r}}(),A=!1,c=!0),c&&(!function(){for(var e in l)if(l.hasOwnProperty(e)){var t=l[e];t.isStateSortable&&t.drawableListPreCull.sort(t.stateSortCompare)}}(),c=!1,h=!0),h&&function(){for(var e in l)if(l.hasOwnProperty(e)){for(var t=l[e],i=t.drawableListPreCull,s=t.drawableList,r=0,n=0,o=i.length;n0)for(i.withSAO=!0,I=0;I0)for(I=0;I0)for(I=0;I0)for(I=0;I0||G>0||N>0||Q>0){if(r.enable(r.CULL_FACE),r.enable(r.BLEND),n?(r.blendEquation(r.FUNC_ADD),r.blendFuncSeparate(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA)):(r.blendEquation(r.FUNC_ADD),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA)),i.backfaces=!1,o||r.depthMask(!1),(N>0||Q>0)&&r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA),Q>0)for(I=0;I0)for(I=0;I0)for(I=0;I0)for(I=0;I0||W>0){if(i.lastProgramId=null,e.highlightMaterial.glowThrough&&r.clear(r.DEPTH_BUFFER_BIT),W>0)for(I=0;I0)for(I=0;I0||X>0||z>0){if(i.lastProgramId=null,e.selectedMaterial.glowThrough&&r.clear(r.DEPTH_BUFFER_BIT),r.enable(r.BLEND),n?(r.blendEquation(r.FUNC_ADD),r.blendFuncSeparate(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA)):r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA),r.enable(r.CULL_FACE),X>0)for(I=0;I0)for(I=0;I0||Y>0){if(i.lastProgramId=null,e.selectedMaterial.glowThrough&&r.clear(r.DEPTH_BUFFER_BIT),Y>0)for(I=0;I0)for(I=0;I0||q>0){if(i.lastProgramId=null,e.selectedMaterial.glowThrough&&r.clear(r.DEPTH_BUFFER_BIT),r.enable(r.CULL_FACE),r.enable(r.BLEND),n?(r.blendEquation(r.FUNC_ADD),r.blendFuncSeparate(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA)):r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA),q>0)for(I=0;I0)for(I=0;I1&&void 0!==arguments[1]?arguments[1]:o;p.reset(),w();var f=null,v=null;for(var g in p.pickSurface=h.pickSurface,h.canvasPos?(u[0]=h.canvasPos[0],u[1]=h.canvasPos[1],f=e.camera.viewMatrix,v=e.camera.projMatrix,p.canvasPos=h.canvasPos):(h.matrix?(f=h.matrix,v=e.camera.projMatrix):(A.set(h.origin||[0,0,0]),c.set(h.direction||[0,0,1]),d=$.addVec3(A,c,t),r[0]=Math.random(),r[1]=Math.random(),r[2]=Math.random(),$.normalizeVec3(r),$.cross3Vec3(c,r,n),f=$.lookAtMat4v(A,d,n,i),v=e.camera.ortho.matrix,p.origin=A,p.direction=c),u[0]=.5*s.clientWidth,u[1]=.5*s.clientHeight),l)if(l.hasOwnProperty(g))for(var _=l[g].drawableList,y=0,b=_.length;y4&&void 0!==arguments[4]?arguments[4]:C;if(!n&&!o)return this.pick({canvasPos:t,pickSurface:!0});var A=e.canvas.resolutionScale;i.reset(),i.backfaces=!0,i.frontface=!0,i.pickZNear=e.camera.project.near,i.pickZFar=e.camera.project.far,s=s||30;var c=m.getRenderBuffer("uniquePickColors-aabs",{depthTexture:!0,size:[2*s+1,2*s+1]});i.snapVectorA=[k(t[0]*A,r.drawingBufferWidth),I(t[1]*A,r.drawingBufferHeight)],i.snapInvVectorAB=[r.drawingBufferWidth/(2*s),r.drawingBufferHeight/(2*s)],c.bind(r.RGBA32I,r.RGBA32I,r.RGBA8UI),r.viewport(0,0,c.size[0],c.size[1]),r.enable(r.DEPTH_TEST),r.frontFace(r.CCW),r.disable(r.CULL_FACE),r.depthMask(!0),r.disable(r.BLEND),r.depthFunc(r.LEQUAL),r.clear(r.DEPTH_BUFFER_BIT),r.clearBufferiv(r.COLOR,0,new Int32Array([0,0,0,0])),r.clearBufferiv(r.COLOR,1,new Int32Array([0,0,0,0])),r.clearBufferuiv(r.COLOR,2,new Uint32Array([0,0,0,0]));var h=e.camera.viewMatrix,d=e.camera.projMatrix;for(var p in l)if(l.hasOwnProperty(p))for(var f=l[p].drawableList,v=0,g=f.length;v0){var j=Math.floor(H/4),G=c.size[0],z=j%G-Math.floor(G/2),W=Math.floor(j/G)-Math.floor(G/2),K=Math.sqrt(Math.pow(z,2)+Math.pow(W,2));V.push({x:z,y:W,dist:K,isVertex:n&&o?w[H+3]>b.length/2:n,result:[w[H+0],w[H+1],w[H+2],w[H+3]],normal:[B[H+0],B[H+1],B[H+2],B[H+3]],id:[x[H+0],x[H+1],x[H+2],x[H+3]]})}var X=null,J=null,Y=null,Z=null;if(V.length>0){V.sort((function(e,t){return e.isVertex!==t.isVertex?e.isVertex?-1:1:e.dist-t.dist})),Z=V[0].isVertex?"vertex":"edge";var q=V[0].result,ee=V[0].normal,te=V[0].id,ie=b[q[3]],se=ie.origin,re=ie.coordinateScale;J=$.normalizeVec3([ee[0]/$.MAX_INT,ee[1]/$.MAX_INT,ee[2]/$.MAX_INT]),X=[q[0]*re[0]+se[0],q[1]*re[1]+se[1],q[2]*re[2]+se[2]],Y=a.items[te[0]+(te[1]<<8)+(te[2]<<16)+(te[3]<<24)]}if(null===P&&null==X)return null;var ne=null;null!==X&&(ne=e.camera.projectWorldPos(X));var oe=Y&&Y.delegatePickedEntity?Y.delegatePickedEntity():Y;return u.reset(),u.snappedToEdge="edge"===Z,u.snappedToVertex="vertex"===Z,u.worldPos=X,u.worldNormal=J,u.entity=oe,u.canvasPos=t,u.snappedCanvasPos=ne||t,u}),this.addMarker=function(t){this._occlusionTester=this._occlusionTester||new Rt(e,m),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 w(),this._occlusionTester.bindRenderBuf(),i.reset(),i.backfaces=!0,i.frontface=!0,r.viewport(0,0,r.drawingBufferWidth,r.drawingBufferHeight),r.clearColor(0,0,0,0),r.enable(r.DEPTH_TEST),r.disable(r.CULL_FACE),r.disable(r.BLEND),r.clear(r.COLOR_BUFFER_BIT|r.DEPTH_BUFFER_BIT),l)if(l.hasOwnProperty(e))for(var t=l[e].drawableList,s=0,n=t.length;s0&&void 0!==arguments[0]?arguments[0]:{},t=m.getRenderBuffer("snapshot");e.width&&e.height&&t.setSize([e.width,e.height]),t.bind(),t.clear(),_=!0},this.renderSnapshot=function(){_&&(m.getRenderBuffer("snapshot").clear(),this.render({force:!0,opaqueOnly:!1}),h=!0)},this.readSnapshot=function(e){return m.getRenderBuffer("snapshot").readImage(e)},this.readSnapshotAsCanvas=function(){return m.getRenderBuffer("snapshot").readImageAsCanvas()},this.endSnapshot=function(){_&&(m.getRenderBuffer("snapshot").unbind(),_=!1)},this.destroy=function(){l={},u={},m.destroy(),y.destroy(),b.destroy(),this._occlusionTester&&this._occlusionTester.destroy()}},Jt=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).KEY_BACKSPACE=8,s.KEY_TAB=9,s.KEY_ENTER=13,s.KEY_SHIFT=16,s.KEY_CTRL=17,s.KEY_ALT=18,s.KEY_PAUSE_BREAK=19,s.KEY_CAPS_LOCK=20,s.KEY_ESCAPE=27,s.KEY_PAGE_UP=33,s.KEY_PAGE_DOWN=34,s.KEY_END=35,s.KEY_HOME=36,s.KEY_LEFT_ARROW=37,s.KEY_UP_ARROW=38,s.KEY_RIGHT_ARROW=39,s.KEY_DOWN_ARROW=40,s.KEY_INSERT=45,s.KEY_DELETE=46,s.KEY_NUM_0=48,s.KEY_NUM_1=49,s.KEY_NUM_2=50,s.KEY_NUM_3=51,s.KEY_NUM_4=52,s.KEY_NUM_5=53,s.KEY_NUM_6=54,s.KEY_NUM_7=55,s.KEY_NUM_8=56,s.KEY_NUM_9=57,s.KEY_A=65,s.KEY_B=66,s.KEY_C=67,s.KEY_D=68,s.KEY_E=69,s.KEY_F=70,s.KEY_G=71,s.KEY_H=72,s.KEY_I=73,s.KEY_J=74,s.KEY_K=75,s.KEY_L=76,s.KEY_M=77,s.KEY_N=78,s.KEY_O=79,s.KEY_P=80,s.KEY_Q=81,s.KEY_R=82,s.KEY_S=83,s.KEY_T=84,s.KEY_U=85,s.KEY_V=86,s.KEY_W=87,s.KEY_X=88,s.KEY_Y=89,s.KEY_Z=90,s.KEY_LEFT_WINDOW=91,s.KEY_RIGHT_WINDOW=92,s.KEY_SELECT_KEY=93,s.KEY_NUMPAD_0=96,s.KEY_NUMPAD_1=97,s.KEY_NUMPAD_2=98,s.KEY_NUMPAD_3=99,s.KEY_NUMPAD_4=100,s.KEY_NUMPAD_5=101,s.KEY_NUMPAD_6=102,s.KEY_NUMPAD_7=103,s.KEY_NUMPAD_8=104,s.KEY_NUMPAD_9=105,s.KEY_MULTIPLY=106,s.KEY_ADD=107,s.KEY_SUBTRACT=109,s.KEY_DECIMAL_POINT=110,s.KEY_DIVIDE=111,s.KEY_F1=112,s.KEY_F2=113,s.KEY_F3=114,s.KEY_F4=115,s.KEY_F5=116,s.KEY_F6=117,s.KEY_F7=118,s.KEY_F8=119,s.KEY_F9=120,s.KEY_F10=121,s.KEY_F11=122,s.KEY_F12=123,s.KEY_NUM_LOCK=144,s.KEY_SCROLL_LOCK=145,s.KEY_SEMI_COLON=186,s.KEY_EQUAL_SIGN=187,s.KEY_COMMA=188,s.KEY_DASH=189,s.KEY_PERIOD=190,s.KEY_FORWARD_SLASH=191,s.KEY_GRAVE_ACCENT=192,s.KEY_OPEN_BRACKET=219,s.KEY_BACK_SLASH=220,s.KEY_CLOSE_BRACKET=221,s.KEY_SINGLE_QUOTE=222,s.KEY_SPACE=32,s.element=r.element,s.altDown=!1,s.ctrlDown=!1,s.mouseDownLeft=!1,s.mouseDownMiddle=!1,s.mouseDownRight=!1,s.keyDown=[],s.enabled=!0,s.keyboardEnabled=!0,s.mouseover=!1,s.mouseCanvasPos=$.vec2(),s._keyboardEventsElement=r.keyboardEventsElement||document,s._bindEvents(),s}return C(i,[{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()}});var t=this.scene.tickify((function(){return e.fire("mousemove",e.mouseCanvasPos,!0)}));this.element.addEventListener("mousemove",this._mouseMoveListener=function(i){e.enabled&&(e._getMouseCanvasPos(i),t(),e.mouseover&&i.preventDefault())});var i=this.scene.tickify((function(t){e.fire("mousewheel",t,!0)}));this.element.addEventListener("wheel",this._mouseWheelListener=function(t,s){if(e.enabled){var r=Math.max(-1,Math.min(1,40*-t.deltaY));i(r)}},{passive:!0});var s,r;this.on("mousedown",(function(e){s=e[0],r=e[1]})),this.on("mouseup",(function(t){s>=t[0]-2&&s<=t[0]+2&&r>=t[1]-2&&r<=t[1]+2&&e.fire("mouseclicked",t,!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,i=0,s=0;t.offsetParent;)i+=t.offsetLeft,s+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-i,this.mouseCanvasPos[1]=e.pageY-s}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(){f(w(i.prototype),"destroy",this).call(this),this._unbindEvents()}}]),i}(),Yt=new Q({}),Zt=function(){function e(t){for(var i in x(this,e),this.id=Yt.addItem({}),t)t.hasOwnProperty(i)&&(this[i]=t[i])}return C(e,[{key:"destroy",value:function(){Yt.removeItem(this.id)}}]),e}(),qt=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({boundary:[0,0,100,100]}),s.boundary=r.boundary,s.autoBoundary=r.autoBoundary,s}return C(i,[{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],i=e[3];this._state.boundary=[0,0,t,i],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(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),$t=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).camera=e,s._state=new Zt({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4(),near:.1,far:1e4}),s._inverseMatrixDirty=!0,s._transposedMatrixDirty=!0,s._fov=60,s._canvasResized=s.scene.canvas.on("boundary",s._needUpdate,b(s)),s.fov=r.fov,s.fovAxis=r.fovAxis,s.near=r.near,s.far=r.far,s}return C(i,[{key:"type",get:function(){return"Perspective"}},{key:"_update",value:function(){var e=this.scene.canvas.boundary,t=e[2]/e[3],i=this._fovAxis,s=this._fov;("x"===i||"min"===i&&t<1||"max"===i&&t>1)&&(s/=t),s=Math.min(s,120),$.perspectiveMat4(s*(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:1e4;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&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,i,s,r){var n=this.scene.canvas.canvas,o=n.offsetWidth/2,a=n.offsetHeight/2;return i[0]=(e[0]-o)/o,i[1]=(e[1]-a)/a,i[2]=t,i[3]=1,$.mulMat4v4(this.inverseMatrix,i,s),$.mulVec3Scalar(s,1/s[3]),s[3]=1,s[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,s,r),r}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}]),i}(),ei=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).camera=e,s._state=new Zt({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4(),near:.1,far:1e4}),s._inverseMatrixDirty=!0,s._transposedMatrixDirty=!0,s.scale=r.scale,s.near=r.near,s.far=r.far,s._onCanvasBoundary=s.scene.canvas.on("boundary",s._needUpdate,b(s)),s}return C(i,[{key:"type",get:function(){return"Ortho"}},{key:"_update",value:function(){var e,t,i,s,r=this.scene,n=.5*this._scale,o=r.canvas.boundary,a=o[2],l=o[3],u=a/l;a>l?(e=-n,t=n,i=n/u,s=-n/u):(e=-n*u,t=n*u,i=n,s=-n),$.orthoMat4c(e,t,s,i,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:1e4;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&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,i,s,r){var n=this.scene.canvas.canvas,o=n.offsetWidth/2,a=n.offsetHeight/2;return i[0]=(e[0]-o)/o,i[1]=(e[1]-a)/a,i[2]=t,i[3]=1,$.mulMat4v4(this.inverseMatrix,i,s),$.mulVec3Scalar(s,1/s[3]),s[3]=1,s[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,s,r),r}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}]),i}(),ti=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).camera=e,s._state=new Zt({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4(),near:.1,far:1e4}),s._left=-1,s._right=1,s._bottom=-1,s._top=1,s._inverseMatrixDirty=!0,s._transposedMatrixDirty=!0,s.left=r.left,s.right=r.right,s.bottom=r.bottom,s.top=r.top,s.near=r.near,s.far=r.far,s}return C(i,[{key:"type",get:function(){return"Frustum"}},{key:"_update",value:function(){$.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&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,i,s,r){var n=this.scene.canvas.canvas,o=n.offsetWidth/2,a=n.offsetHeight/2;return i[0]=(e[0]-o)/o,i[1]=(e[1]-a)/a,i[2]=t,i[3]=1,$.mulMat4v4(this.inverseMatrix,i,s),$.mulVec3Scalar(s,1/s[3]),s[3]=1,s[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,s,r),r}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy(),f(w(i.prototype),"destroy",this).call(this)}}]),i}(),ii=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).camera=e,s._state=new Zt({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4()}),s._inverseMatrixDirty=!0,s._transposedMatrixDirty=!1,s.matrix=r.matrix,s}return C(i,[{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&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,i,s,r){var n=this.scene.canvas.canvas,o=n.offsetWidth/2,a=n.offsetHeight/2;return i[0]=(e[0]-o)/o,i[1]=(e[1]-a)/a,i[2]=t,i[3]=1,$.mulMat4v4(this.inverseMatrix,i,s),$.mulVec3Scalar(s,1/s[3]),s[3]=1,s[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,s,r),r}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),si=$.vec3(),ri=$.vec3(),ni=$.vec3(),oi=$.vec3(),ai=$.vec3(),li=$.vec3(),ui=$.vec4(),Ai=$.vec4(),ci=$.vec4(),hi=$.mat4(),di=$.mat4(),pi=$.vec3(),fi=$.vec3(),vi=$.vec3(),gi=$.vec3(),mi=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({deviceMatrix:$.mat4(),hasDeviceMatrix:!1,matrix:$.mat4(),normalMatrix:$.mat4(),inverseMatrix:$.mat4()}),s._perspective=new $t(b(s)),s._ortho=new ei(b(s)),s._frustum=new ti(b(s)),s._customProjection=new ii(b(s)),s._project=s._perspective,s._eye=$.vec3([0,0,10]),s._look=$.vec3([0,0,0]),s._up=$.vec3([0,1,0]),s._worldUp=$.vec3([0,1,0]),s._worldRight=$.vec3([1,0,0]),s._worldForward=$.vec3([0,0,-1]),s.deviceMatrix=r.deviceMatrix,s.eye=r.eye,s.look=r.look,s.up=r.up,s.worldAxis=r.worldAxis,s.gimbalLock=r.gimbalLock,s.constrainPitch=r.constrainPitch,s.projection=r.projection,s._perspective.on("matrix",(function(){"perspective"===s._projectionType&&s.fire("projMatrix",s._perspective.matrix)})),s._ortho.on("matrix",(function(){"ortho"===s._projectionType&&s.fire("projMatrix",s._ortho.matrix)})),s._frustum.on("matrix",(function(){"frustum"===s._projectionType&&s.fire("projMatrix",s._frustum.matrix)})),s._customProjection.on("matrix",(function(){"customProjection"===s._projectionType&&s.fire("projMatrix",s._customProjection.matrix)})),s}return C(i,[{key:"type",get:function(){return"Camera"}},{key:"_update",value:function(){var e,t=this._state;"ortho"===this.projection?($.subVec3(this._eye,this._look,pi),$.normalizeVec3(pi,fi),$.mulVec3Scalar(fi,1e3,vi),$.addVec3(this._look,vi,gi),e=gi):e=this._eye,t.hasDeviceMatrix?($.lookAtMat4v(e,this._look,this._up,di),$.mulMat4(t.deviceMatrix,di,t.matrix)):$.lookAtMat4v(e,this._look,this._up,t.matrix),$.inverseMat4(this._state.matrix,this._state.inverseMatrix),$.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=$.subVec3(this._eye,this._look,si);$.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,hi),t=$.transformPoint3(hi,t,ri),this.eye=$.addVec3(this._look,t,ni),this.up=$.transformPoint3(hi,this._up,oi)}},{key:"orbitPitch",value:function(e){if(!(this._constrainPitch&&(e=$.dotVec3(this._up,this._worldUp)/$.DEGTORAD)<1)){var t=$.subVec3(this._eye,this._look,si),i=$.cross3Vec3($.normalizeVec3(t,ri),$.normalizeVec3(this._up,ni));$.rotationMat4v(.0174532925*e,i,hi),t=$.transformPoint3(hi,t,oi),this.up=$.transformPoint3(hi,this._up,ai),this.eye=$.addVec3(t,this._look,li)}}},{key:"yaw",value:function(e){var t=$.subVec3(this._look,this._eye,si);$.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,hi),t=$.transformPoint3(hi,t,ri),this.look=$.addVec3(t,this._eye,ni),this._gimbalLock&&(this.up=$.transformPoint3(hi,this._up,oi))}},{key:"pitch",value:function(e){if(!(this._constrainPitch&&(e=$.dotVec3(this._up,this._worldUp)/$.DEGTORAD)<1)){var t=$.subVec3(this._look,this._eye,si),i=$.cross3Vec3($.normalizeVec3(t,ri),$.normalizeVec3(this._up,ni));$.rotationMat4v(.0174532925*e,i,hi),this.up=$.transformPoint3(hi,this._up,li),t=$.transformPoint3(hi,t,oi),this.look=$.addVec3(t,this._eye,ai)}}},{key:"pan",value:function(e){var t,i=$.subVec3(this._eye,this._look,si),s=[0,0,0];if(0!==e[0]){var r=$.cross3Vec3($.normalizeVec3(i,[]),$.normalizeVec3(this._up,ri));t=$.mulVec3Scalar(r,e[0]),s[0]+=t[0],s[1]+=t[1],s[2]+=t[2]}0!==e[1]&&(t=$.mulVec3Scalar($.normalizeVec3(this._up,ni),e[1]),s[0]+=t[0],s[1]+=t[1],s[2]+=t[2]),0!==e[2]&&(t=$.mulVec3Scalar($.normalizeVec3(i,oi),e[2]),s[0]+=t[0],s[1]+=t[1],s[2]+=t[2]),this.eye=$.addVec3(this._eye,s,ai),this.look=$.addVec3(this._look,s,li)}},{key:"zoom",value:function(e){var t=$.subVec3(this._eye,this._look,si),i=Math.abs($.lenVec3(t,ri)),s=Math.abs(i+e);if(!(s<.5)){var r=$.normalizeVec3(t,ni);this.eye=$.addVec3(this._look,$.mulVec3Scalar(r,s),oi)}}},{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=$.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 $.lenVec3($.subVec3(this._look,this._eye,si))}},{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=ui,i=Ai,s=ci;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,$.mulMat4v4(this.viewMatrix,t,i),$.mulMat4v4(this.projMatrix,i,s),$.mulVec3Scalar(s,1/s[3]),s[3]=1,s[1]*=-1;var r=this.scene.canvas.canvas,n=r.offsetWidth/2,o=r.offsetHeight/2;return[s[0]*n+n,s[1]*o+o]}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),_i=function(e){g(i,we);var t=_(i);function i(e){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),t.call(this,e,s)}return C(i,[{key:"type",get:function(){return"Light"}},{key:"isLight",get:function(){return!0}}]),i}(),yi=function(e){g(i,_i);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e,r))._shadowRenderBuf=null,s._shadowViewMatrix=null,s._shadowProjMatrix=null,s._shadowViewMatrixDirty=!0,s._shadowProjMatrixDirty=!0;var n=s.scene.camera,o=s.scene.canvas;return s._onCameraViewMatrix=n.on("viewMatrix",(function(){s._shadowViewMatrixDirty=!0})),s._onCameraProjMatrix=n.on("projMatrix",(function(){s._shadowProjMatrixDirty=!0})),s._onCanvasBoundary=o.on("boundary",(function(){s._shadowProjMatrixDirty=!0})),s._state=new Zt({type:"dir",dir:$.vec3([1,1,1]),color:$.vec3([.7,.7,.8]),intensity:1,space:r.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(s._shadowViewMatrixDirty){s._shadowViewMatrix||(s._shadowViewMatrix=$.identityMat4());var e=s.scene.camera,t=s._state.dir,i=e.look,r=[i[0]-t[0],i[1]-t[1],i[2]-t[2]];$.lookAtMat4v(r,i,[0,1,0],s._shadowViewMatrix),s._shadowViewMatrixDirty=!1}return s._shadowViewMatrix},getShadowProjMatrix:function(){return s._shadowProjMatrixDirty&&(s._shadowProjMatrix||(s._shadowProjMatrix=$.identityMat4()),$.orthoMat4c(-40,40,-40,40,-40,80,s._shadowProjMatrix),s._shadowProjMatrixDirty=!1),s._shadowProjMatrix},getShadowRenderBuf:function(){return s._shadowRenderBuf||(s._shadowRenderBuf=new zt(s.scene.canvas.canvas,s.scene.canvas.gl,{size:[1024,1024]})),s._shadowRenderBuf}}),s.dir=r.dir,s.color=r.color,s.intensity=r.intensity,s.castsShadow=r.castsShadow,s.scene._lightCreated(b(s)),s}return C(i,[{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),f(w(i.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),i}(),bi=function(e){g(i,_i);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state={type:"ambient",color:$.vec3([.7,.7,.7]),intensity:1},s.color=r.color,s.intensity=r.intensity,s.scene._lightCreated(b(s)),s}return C(i,[{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(){f(w(i.prototype),"destroy",this).call(this),this.scene._lightDestroyed(this)}}]),i}(),wi=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),s=t.call(this,e,r),se.memory.meshes++,s}return C(i,[{key:"type",get:function(){return"Geometry"}},{key:"isGeometry",get:function(){return!0}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),se.memory.meshes--}}]),i}(),Bi=function(){var e=[],t=[],i=[],s=[],r=[],n=0,o=new Uint16Array(3),a=new Uint16Array(3),l=new Uint16Array(3),u=$.vec3(),A=$.vec3(),c=$.vec3(),h=$.vec3(),d=$.vec3(),p=$.vec3(),f=$.vec3();return function(v,g,m,_){!function(r,n){var o,a,l,u,A,c,h={},d=Math.pow(10,4),p=0;for(A=0,c=r.length;AI)||(F=i[P.index1],E=i[P.index2],(!S&&F>65535||E>65535)&&(S=!0),k.push(F),k.push(E));return S?new Uint32Array(k):new Uint16Array(k)}}();var xi=function(){var e=$.mat4(),t=$.mat4();return function(i,s){s=s||$.mat4();var r=i[0],n=i[1],o=i[2],a=i[3]-r,l=i[4]-n,u=i[5]-o,A=65535;return $.identityMat4(e),$.translationMat4v(i,e),$.identityMat4(t),$.scalingMat4v([a/A,l/A,u/A],t),$.mulMat4(e,t,s),s}}(),Pi=function(){var e=$.mat4(),t=$.mat4();return function(i,s,r){var n,o=new Uint16Array(i.length),a=new Float32Array([r[0]!==s[0]?65535/(r[0]-s[0]):0,r[1]!==s[1]?65535/(r[1]-s[1]):0,r[2]!==s[2]?65535/(r[2]-s[2]):0]);for(n=0;n=0?1:-1),a=(1-Math.abs(r))*(n>=0?1:-1);r=o,n=a}return new Int8Array([Math[i](127.5*r+(r<0?-1:0)),Math[s](127.5*n+(n<0?-1:0))])}function Fi(e){var t=e[0],i=e[1];t/=t<0?127:128,i/=i<0?127:128;var s=1-Math.abs(t)-Math.abs(i);s<0&&(t=(1-Math.abs(i))*(t>=0?1:-1),i=(1-Math.abs(t))*(i>=0?1:-1));var r=Math.sqrt(t*t+i*i+s*s);return[t/r,i/r,s/r]}function Ei(e,t,i){return e[t]*i[0]+e[t+1]*i[1]+e[t+2]*i[2]}var ki={getPositionsBounds:function(e){var t,i,s=new Float32Array(3),r=new Float32Array(3);for(t=0;t<3;t++)s[t]=Number.MAX_VALUE,r[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),s=0,r=e.length;s2&&void 0!==arguments[2]?arguments[2]:e;return i[0]=e[0]*t[0]+t[12],i[1]=e[1]*t[5]+t[13],i[2]=e[2]*t[10]+t[14],i[3]=e[3]*t[0]+t[12],i[4]=e[4]*t[5]+t[13],i[5]=e[5]*t[10]+t[14],i},getUVBounds:function(e){var t,i,s=new Float32Array(2),r=new Float32Array(2);for(t=0;t<2;t++)s[t]=Number.MAX_VALUE,r[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),s=0,r=e.length;sr&&(i=t,r=s),(s=Ei(e,o,Fi(t=Mi(e,o,"floor","ceil"))))>r&&(i=t,r=s),(s=Ei(e,o,Fi(t=Mi(e,o,"ceil","ceil"))))>r&&(i=t,r=s),n[o]=i[0],n[o+1]=i[1];return n},decompressNormals:function(e,t){for(var i=0,s=0,r=e.length;i=0?1:-1),o=(1-Math.abs(n))*(o>=0?1:-1));var l=Math.sqrt(n*n+o*o+a*a);t[s+0]=n/l,t[s+1]=o/l,t[s+2]=a/l,s+=3}return t},decompressNormal:function(e,t){var i=e[0],s=e[1];i=(2*i+1)/255,s=(2*s+1)/255;var r=1-Math.abs(i)-Math.abs(s);r<0&&(i=(1-Math.abs(s))*(i>=0?1:-1),s=(1-Math.abs(i))*(s>=0?1:-1));var n=Math.sqrt(i*i+s*s+r*r);return t[0]=i/n,t[1]=s/n,t[2]=r/n,t}},Ii=se.memory,Di=$.AABB3(),Si=function(e){g(i,wi);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e,r))._state=new Zt({compressGeometry:!!r.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:""}),s._numTriangles=0,s._edgeThreshold=r.edgeThreshold||10,s._edgeIndicesBuf=null,s._pickTrianglePositionsBuf=null,s._pickTriangleColorsBuf=null,s._aabbDirty=!0,s._boundingSphere=!0,s._aabb=null,s._aabbDirty=!0,s._obb=null,s._obbDirty=!0;var n=s._state,o=s.scene.canvas.gl;switch(r.primitive=r.primitive||"triangles",r.primitive){case"points":n.primitive=o.POINTS,n.primitiveName=r.primitive;break;case"lines":n.primitive=o.LINES,n.primitiveName=r.primitive;break;case"line-loop":n.primitive=o.LINE_LOOP,n.primitiveName=r.primitive;break;case"line-strip":n.primitive=o.LINE_STRIP,n.primitiveName=r.primitive;break;case"triangles":n.primitive=o.TRIANGLES,n.primitiveName=r.primitive;break;case"triangle-strip":n.primitive=o.TRIANGLE_STRIP,n.primitiveName=r.primitive;break;case"triangle-fan":n.primitive=o.TRIANGLE_FAN,n.primitiveName=r.primitive;break;default:s.error("Unsupported value for 'primitive': '"+r.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),n.primitive=o.TRIANGLES,n.primitiveName=r.primitive}if(r.positions)if(s._state.compressGeometry){var a=ki.getPositionsBounds(r.positions),l=ki.compressPositions(r.positions,a.min,a.max);n.positions=l.quantized,n.positionsDecodeMatrix=l.decodeMatrix}else n.positions=r.positions.constructor===Float32Array?r.positions:new Float32Array(r.positions);if(r.colors&&(n.colors=r.colors.constructor===Float32Array?r.colors:new Float32Array(r.colors)),r.uv)if(s._state.compressGeometry){var u=ki.getUVBounds(r.uv),A=ki.compressUVs(r.uv,u.min,u.max);n.uv=A.quantized,n.uvDecodeMatrix=A.decodeMatrix}else n.uv=r.uv.constructor===Float32Array?r.uv:new Float32Array(r.uv);return r.normals&&(s._state.compressGeometry?n.normals=ki.compressNormals(r.normals):n.normals=r.normals.constructor===Float32Array?r.normals:new Float32Array(r.normals)),r.indices&&(n.indices=r.indices.constructor===Uint32Array||r.indices.constructor===Uint16Array?r.indices:new Uint32Array(r.indices),"triangles"===s._state.primitiveName&&(s._numTriangles=r.indices.length/3)),s._buildHash(),Ii.meshes++,s._buildVBOs(),s}return C(i,[{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 It(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),Ii.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new It(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),Ii.positions+=e.positionsBuf.numItems),e.normals){var i=e.compressGeometry;e.normalsBuf=new It(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,i),Ii.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new It(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),Ii.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new It(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),Ii.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,i=Bi(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new It(t,t.ELEMENT_ARRAY_BUFFER,i,i.length,1,t.STATIC_DRAW),Ii.indices+=this._edgeIndicesBuf.numItems}}},{key:"_buildPickTriangleVBOs",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,i=$.buildPickTriangles(e.positions,e.indices,e.compressGeometry),s=i.positions,r=i.colors;this._pickTrianglePositionsBuf=new It(t,t.ARRAY_BUFFER,s,s.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new It(t,t.ARRAY_BUFFER,r,r.length,4,t.STATIC_DRAW,!0),Ii.positions+=this._pickTrianglePositionsBuf.numItems,Ii.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),ki.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null},set:function(e){var t=this._state,i=t.positions;if(i)if(i.length===e.length){if(this._state.compressGeometry){var s=ki.getPositionsBounds(e),r=ki.compressPositions(e,s.min,s.max);e=r.quantized,t.positionsDecodeMatrix=r.decodeMatrix}i.set(e),t.positionsBuf&&t.positionsBuf.setData(i),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),ki.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,i=t.normals;i?i.length===e.length?(i.set(e),t.normalsBuf&&t.normalsBuf.setData(i),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),ki.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,i=t.uv;i?i.length===e.length?(i.set(e),t.uvBuf&&t.uvBuf.setData(i),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,i=t.colors;i?i.length===e.length?(i.set(e),t.colorsBuf&&t.colorsBuf.setData(i),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=$.AABB3()),$.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=$.OBB3()),$.positions3ToAABB3(this._state.positions,Di,this._state.positionsDecodeMatrix),$.AABB3ToOBB3(Di,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(){f(w(i.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(),Ii.meshes--}}]),i}();function Ti(){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 i=e.ySize||1;i<0&&(console.error("negative ySize not allowed - will invert"),i*=-1);var s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);var r=e.center,n=r?r[0]:0,o=r?r[1]:0,a=r?r[2]:0,l=-t+n,u=-i+o,A=-s+a,c=t+n,h=i+o,d=s+a;return le.apply(e,{positions:[c,h,d,l,h,d,l,u,d,c,u,d,c,h,d,c,u,d,c,u,A,c,h,A,c,h,d,c,h,A,l,h,A,l,h,d,l,h,d,l,h,A,l,u,A,l,u,d,l,u,A,c,u,A,c,u,d,l,u,d,c,u,A,l,u,A,l,h,A,c,h,A],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 Ri=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),s=t.call(this,e,r),se.memory.materials++,s}return C(i,[{key:"type",get:function(){return"Material"}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),se.memory.materials--}}]),i}(),Li={opaque:0,mask:1,blend:2},Ui=["opaque","mask","blend"],Oi=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"PhongMaterial",ambient:$.vec3([1,1,1]),diffuse:$.vec3([1,1,1]),specular:$.vec3([1,1,1]),emissive:$.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),s.ambient=r.ambient,s.diffuse=r.diffuse,s.specular=r.specular,s.emissive=r.emissive,s.alpha=r.alpha,s.shininess=r.shininess,s.reflectivity=r.reflectivity,s.lineWidth=r.lineWidth,s.pointSize=r.pointSize,r.ambientMap&&(s._ambientMap=s._checkComponent("Texture",r.ambientMap)),r.diffuseMap&&(s._diffuseMap=s._checkComponent("Texture",r.diffuseMap)),r.specularMap&&(s._specularMap=s._checkComponent("Texture",r.specularMap)),r.emissiveMap&&(s._emissiveMap=s._checkComponent("Texture",r.emissiveMap)),r.alphaMap&&(s._alphaMap=s._checkComponent("Texture",r.alphaMap)),r.reflectivityMap&&(s._reflectivityMap=s._checkComponent("Texture",r.reflectivityMap)),r.normalMap&&(s._normalMap=s._checkComponent("Texture",r.normalMap)),r.occlusionMap&&(s._occlusionMap=s._checkComponent("Texture",r.occlusionMap)),r.diffuseFresnel&&(s._diffuseFresnel=s._checkComponent("Fresnel",r.diffuseFresnel)),r.specularFresnel&&(s._specularFresnel=s._checkComponent("Fresnel",r.specularFresnel)),r.emissiveFresnel&&(s._emissiveFresnel=s._checkComponent("Fresnel",r.emissiveFresnel)),r.alphaFresnel&&(s._alphaFresnel=s._checkComponent("Fresnel",r.alphaFresnel)),r.reflectivityFresnel&&(s._reflectivityFresnel=s._checkComponent("Fresnel",r.reflectivityFresnel)),s.alphaMode=r.alphaMode,s.alphaCutoff=r.alphaCutoff,s.backfaces=r.backfaces,s.frontface=r.frontface,s._makeHash(),s}return C(i,[{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 Ui[this._state.alphaMode]},set:function(e){var t=Li[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(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),Ni={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:[1,1,1],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}},Qi=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),s._preset="default",r.preset?(s.preset=r.preset,void 0!==r.fill&&(s.fill=r.fill),r.fillColor&&(s.fillColor=r.fillColor),void 0!==r.fillAlpha&&(s.fillAlpha=r.fillAlpha),void 0!==r.edges&&(s.edges=r.edges),r.edgeColor&&(s.edgeColor=r.edgeColor),void 0!==r.edgeAlpha&&(s.edgeAlpha=r.edgeAlpha),void 0!==r.edgeWidth&&(s.edgeWidth=r.edgeWidth),void 0!==r.backfaces&&(s.backfaces=r.backfaces),void 0!==r.glowThrough&&(s.glowThrough=r.glowThrough)):(s.fill=r.fill,s.fillColor=r.fillColor,s.fillAlpha=r.fillAlpha,s.edges=r.edges,s.edgeColor=r.edgeColor,s.edgeAlpha=r.edgeAlpha,s.edgeWidth=r.edgeWidth,s.backfaces=r.backfaces,s.glowThrough=r.glowThrough),s}return C(i,[{key:"type",get:function(){return"EmphasisMaterial"}},{key:"presets",get:function(){return Ni}},{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=Ni[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(Ni).join(", "))}}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),Vi={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}},Hi=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),s._preset="default",r.preset?(s.preset=r.preset,r.edgeColor&&(s.edgeColor=r.edgeColor),void 0!==r.edgeAlpha&&(s.edgeAlpha=r.edgeAlpha),void 0!==r.edgeWidth&&(s.edgeWidth=r.edgeWidth)):(s.edgeColor=r.edgeColor,s.edgeAlpha=r.edgeAlpha,s.edgeWidth=r.edgeWidth),s.edges=!1!==r.edges,s}return C(i,[{key:"type",get:function(){return"EdgeMaterial"}},{key:"presets",get:function(){return Vi}},{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=Vi[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(Vi).join(", "))}}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),ji={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"}},Gi=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._units="meters",s._scale=1,s._origin=$.vec3([0,0,0]),s.units=r.units,s.scale=r.scale,s.origin=r.origin,s}return C(i,[{key:"unitsInfo",get:function(){return ji}},{key:"units",get:function(){return this._units},set:function(e){e||(e="meters"),ji[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]:$.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]:$.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}}]),i}(),zi=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._supported=yt.SUPPORTED_EXTENSIONS.OES_standard_derivatives,s.enabled=r.enabled,s.kernelRadius=r.kernelRadius,s.intensity=r.intensity,s.bias=r.bias,s.scale=r.scale,s.minResolution=r.minResolution,s.numSamples=r.numSamples,s.blur=r.blur,s.blendCutoff=r.blendCutoff,s.blendFactor=r.blendFactor,s}return C(i,[{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(){f(w(i.prototype),"destroy",this).call(this)}}]),i}(),Wi=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).sliceColor=r.sliceColor,s.sliceThickness=r.sliceThickness,s}return C(i,[{key:"sliceThickness",get:function(){return this._sliceThickness},set:function(e){null==e&&(e=0),this._sliceThickness!==e&&(this._sliceThickness=e,this.glRedraw())}},{key:"sliceColor",get:function(){return this._sliceColor},set:function(e){null==e&&(e=[0,0,0,1]),this._sliceColor!==e&&(this._sliceColor=e,this.glRedraw())}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this)}}]),i}(),Ki={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}},Xi=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),r.preset?(s.preset=r.preset,void 0!==r.pointSize&&(s.pointSize=r.pointSize),void 0!==r.roundPoints&&(s.roundPoints=r.roundPoints),void 0!==r.perspectivePoints&&(s.perspectivePoints=r.perspectivePoints),void 0!==r.minPerspectivePointSize&&(s.minPerspectivePointSize=r.minPerspectivePointSize),void 0!==r.maxPerspectivePointSize&&(s.maxPerspectivePointSize=r.minPerspectivePointSize)):(s._preset="default",s.pointSize=r.pointSize,s.roundPoints=r.roundPoints,s.perspectivePoints=r.perspectivePoints,s.minPerspectivePointSize=r.minPerspectivePointSize,s.maxPerspectivePointSize=r.maxPerspectivePointSize),s.filterIntensity=r.filterIntensity,s.minIntensity=r.minIntensity,s.maxIntensity=r.maxIntensity,s}return C(i,[{key:"type",get:function(){return"PointsMaterial"}},{key:"presets",get:function(){return Ki}},{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=Ki[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(Ki).join(", "))}}},{key:"hash",get:function(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),Ji={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}},Yi=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"LinesMaterial",lineWidth:null}),r.preset?(s.preset=r.preset,void 0!==r.lineWidth&&(s.lineWidth=r.lineWidth)):(s._preset="default",s.lineWidth=r.lineWidth),s}return C(i,[{key:"type",get:function(){return"LinesMaterial"}},{key:"presets",get:function(){return Ji}},{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=Ji[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Ji).join(", "))}}},{key:"hash",get:function(){return[""+this.lineWidth].join(";")}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}();function Zi(e,t){for(var i,s,r={},n=0,o=t.length;n1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),s=t.call(this,null,r);var n=r.canvasElement||document.getElementById(r.canvasId);if(!(n instanceof HTMLCanvasElement))throw"Mandatory config expected: valid canvasId or canvasElement";s._tickifiedFunctions={};var o=!!r.transparent,a=!!r.alphaDepthMask;return s._aabbDirty=!0,s.viewer=e,s.occlusionTestCountdown=0,s.loading=0,s.startTime=(new Date).getTime(),s.models={},s.objects={},s._numObjects=0,s.visibleObjects={},s._numVisibleObjects=0,s.xrayedObjects={},s._numXRayedObjects=0,s.highlightedObjects={},s._numHighlightedObjects=0,s.selectedObjects={},s._numSelectedObjects=0,s.colorizedObjects={},s._numColorizedObjects=0,s.opacityObjects={},s._numOpacityObjects=0,s.offsetObjects={},s._numOffsetObjects=0,s._modelIds=null,s._objectIds=null,s._visibleObjectIds=null,s._xrayedObjectIds=null,s._highlightedObjectIds=null,s._selectedObjectIds=null,s._colorizedObjectIds=null,s._opacityObjectIds=null,s._offsetObjectIds=null,s._collidables={},s._compilables={},s._needRecompile=!1,s.types={},s.components={},s.sectionPlanes={},s.lights={},s.lightMaps={},s.reflectionMaps={},s.bitmaps={},s.lineSets={},s.realWorldOffset=r.realWorldOffset||new Float64Array([0,0,0]),s.canvas=new mt(b(s),{dontClear:!0,canvas:n,spinnerElementId:r.spinnerElementId,transparent:o,webgl2:!1!==r.webgl2,contextAttr:r.contextAttr||{},backgroundColor:r.backgroundColor,backgroundColorFromAmbientLight:r.backgroundColorFromAmbientLight,premultipliedAlpha:r.premultipliedAlpha}),s.canvas.on("boundary",(function(){s.glRedraw()})),s.canvas.on("webglContextFailed",(function(){alert("xeokit failed to find WebGL!")})),s._renderer=new Xt(b(s),{transparent:o,alphaDepthMask:a}),s._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1,this._numCachedSectionPlanes=0;var e=null;this.getHash=function(){if(e)return e;var t=this.getNumAllocatedSectionPlanes();if(this.sectionPlanes,0===t)return this.hash=";";for(var i=[],s=0,r=t;sthis._numCachedSectionPlanes?e:this._numCachedSectionPlanes}},s._sectionPlanesState.setNumCachedSectionPlanes(r.numCachedSectionPlanes||0),s._lightsState=new function(){var e=$.vec4([0,0,0,0]),t=$.vec4();this.lights=[],this.reflectionMaps=[],this.lightMaps=[];var i=null,s=null;this.getHash=function(){if(i)return i;for(var e,t=[],s=this.lights,r=0,n=s.length;r0&&t.push("/lm"),this.reflectionMaps.length>0&&t.push("/rm"),t.push(";"),i=t.join("")},this.addLight=function(e){this.lights.push(e),s=null,i=null},this.removeLight=function(e){for(var t=0,r=this.lights.length;t1&&void 0!==arguments[1])||arguments[1];e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}},{key:"_deRegisterVisibleObject",value:function(e){delete this.visibleObjects[e.id],this._numVisibleObjects--,this._visibleObjectIds=null}},{key:"_objectXRayedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}},{key:"_deRegisterXRayedObject",value:function(e){delete this.xrayedObjects[e.id],this._numXRayedObjects--,this._xrayedObjectIds=null}},{key:"_objectHighlightedUpdated",value:function(e){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null}},{key:"_deRegisterHighlightedObject",value:function(e){delete this.highlightedObjects[e.id],this._numHighlightedObjects--,this._highlightedObjectIds=null}},{key:"_objectSelectedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}},{key:"_deRegisterSelectedObject",value:function(e){delete this.selectedObjects[e.id],this._numSelectedObjects--,this._selectedObjectIds=null}},{key:"_objectColorizeUpdated",value:function(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}},{key:"_deRegisterColorizedObject",value:function(e){delete this.colorizedObjects[e.id],this._numColorizedObjects--,this._colorizedObjectIds=null}},{key:"_objectOpacityUpdated",value:function(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}},{key:"_deRegisterOpacityObject",value:function(e){delete this.opacityObjects[e.id],this._numOpacityObjects--,this._opacityObjectIds=null}},{key:"_objectOffsetUpdated",value:function(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}},{key:"_deRegisterOffsetObject",value:function(e){delete this.offsetObjects[e.id],this._numOffsetObjects--,this._offsetObjectIds=null}},{key:"_webglContextLost",value:function(){for(var e in this.canvas.spinner.processes++,this.components)if(this.components.hasOwnProperty(e)){var t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}},{key:"_webglContextRestored",value:function(){var e=this.canvas.gl;for(var t in this.components)if(this.components.hasOwnProperty(t)){var i=this.components[t];i._webglContextRestored&&i._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}},{key:"capabilities",get:function(){return this._renderer.capabilities}},{key:"entityOffsetsEnabled",get:function(){return this._entityOffsetsEnabled}},{key:"pickSurfacePrecisionEnabled",get:function(){return!1}},{key:"logarithmicDepthBufferEnabled",get:function(){return this._logarithmicDepthBufferEnabled}},{key:"numCachedSectionPlanes",get:function(){return this._sectionPlanesState.getNumCachedSectionPlanes()},set:function(e){e=e||0,this._sectionPlanesState.getNumCachedSectionPlanes()!==e&&(this._sectionPlanesState.setNumCachedSectionPlanes(e),this._needRecompile=!0,this.glRedraw())}},{key:"pbrEnabled",get:function(){return this._pbrEnabled},set:function(e){this._pbrEnabled=!!e,this.glRedraw()}},{key:"dtxEnabled",get:function(){return this._dtxEnabled},set:function(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled},set:function(e){this._colorTextureEnabled=!!e,this.glRedraw()}},{key:"doOcclusionTest",value:function(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}},{key:"render",value:function(e){e&&_e.runTasks();var t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),e||this._renderer.needsRender()){t.sceneId=this.id;var i,s,r=this._passes,n=this._clearEachPass;for(i=0;in&&(n=e[3]),e[4]>o&&(o=e[4]),e[5]>a&&(a=e[5]),u=!0}u||(i=-100,s=-100,r=-100,n=100,o=100,a=100),this._aabb[0]=i,this._aabb[1]=s,this._aabb[2]=r,this._aabb[3]=n,this._aabb[4]=o,this._aabb[5]=a,this._aabbDirty=!1}return this._aabb}},{key:"_setAABBDirty",value:function(){this._aabbDirty=!0,this.fire("boundary")}},{key:"pick",value:function(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");var i=e.includeEntities||e.include;i&&(e.includeEntityIds=Zi(this,i));var s=e.excludeEntities||e.exclude;return s&&(e.excludeEntityIds=Zi(this,s)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=e.snapToEdge||e.snapToVertex?this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapToVertex,e.snapToEdge,t):this._renderer.pick(e,t))&&t.entity&&t.entity.fire&&t.entity.fire("picked",t),t}},{key:"snapPick",value:function(e){return void 0===this._warnSnapPickDeprecated&&(this._warnSnapPickDeprecated=!0,this.warn("Scene.snapPick() is deprecated since v2.4.2 - use Scene.pick() instead")),this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapToVertex,e.snapToEdge)}},{key:"clear",value:function(){var e;for(var t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}},{key:"clearLights",value:function(){for(var e=Object.keys(this.lights),t=0,i=e.length;to&&(o=t[3]),t[4]>a&&(a=t[4]),t[5]>l&&(l=t[5]),i=!0}})),i){var u=$.AABB3();return u[0]=s,u[1]=r,u[2]=n,u[3]=o,u[4]=a,u[5]=l,u}return this.aabb}},{key:"setObjectsVisible",value:function(e,t){return this.withObjects(e,(function(e){var i=e.visible!==t;return e.visible=t,i}))}},{key:"setObjectsCollidable",value:function(e,t){return this.withObjects(e,(function(e){var i=e.collidable!==t;return e.collidable=t,i}))}},{key:"setObjectsCulled",value:function(e,t){return this.withObjects(e,(function(e){var i=e.culled!==t;return e.culled=t,i}))}},{key:"setObjectsSelected",value:function(e,t){return this.withObjects(e,(function(e){var i=e.selected!==t;return e.selected=t,i}))}},{key:"setObjectsHighlighted",value:function(e,t){return this.withObjects(e,(function(e){var i=e.highlighted!==t;return e.highlighted=t,i}))}},{key:"setObjectsXRayed",value:function(e,t){return this.withObjects(e,(function(e){var i=e.xrayed!==t;return e.xrayed=t,i}))}},{key:"setObjectsEdges",value:function(e,t){return this.withObjects(e,(function(e){var i=e.edges!==t;return e.edges=t,i}))}},{key:"setObjectsColorized",value:function(e,t){return this.withObjects(e,(function(e){e.colorize=t}))}},{key:"setObjectsOpacity",value:function(e,t){return this.withObjects(e,(function(e){var i=e.opacity!==t;return e.opacity=t,i}))}},{key:"setObjectsPickable",value:function(e,t){return this.withObjects(e,(function(e){var i=e.pickable!==t;return e.pickable=t,i}))}},{key:"setObjectsOffset",value:function(e,t){this.withObjects(e,(function(e){e.offset=t}))}},{key:"withObjects",value:function(e,t){le.isString(e)&&(e=[e]);for(var i=!1,s=0,r=e.length;ss&&(s=r,e.apply(void 0,A(i)))}));return this._tickifiedFunctions[t]={tickSubId:o,wrapperFunc:n},n}},{key:"destroy",value:function(){for(var e in f(w(i.prototype),"destroy",this).call(this),this.components)this.components.hasOwnProperty(e)&&this.components[e].destroy();this.canvas.gl=null,this.components=null,this.models=null,this.objects=null,this.visibleObjects=null,this.xrayedObjects=null,this.highlightedObjects=null,this.selectedObjects=null,this.colorizedObjects=null,this.opacityObjects=null,this.sectionPlanes=null,this.lights=null,this.lightMaps=null,this.reflectionMaps=null,this._objectIds=null,this._visibleObjectIds=null,this._xrayedObjectIds=null,this._highlightedObjectIds=null,this._selectedObjectIds=null,this._colorizedObjectIds=null,this.types=null,this.components=null,this.canvas=null,this._renderer=null,this.input=null,this._viewport=null,this._camera=null}}]),i}(),$i=1e3,es=1001,ts=1002,is=1003,ss=1004,rs=1004,ns=1005,os=1005,as=1006,ls=1007,us=1007,As=1008,cs=1008,hs=1009,ds=1010,ps=1011,fs=1012,vs=1013,gs=1014,ms=1015,_s=1016,ys=1017,bs=1018,ws=1020,Bs=1021,xs=1022,Ps=1023,Cs=1024,Ms=1025,Fs=1026,Es=1027,ks=1028,Is=1029,Ds=1030,Ss=1031,Ts=1033,Rs=33776,Ls=33777,Us=33778,Os=33779,Ns=35840,Qs=35841,Vs=35842,Hs=35843,js=36196,Gs=37492,zs=37496,Ws=37808,Ks=37809,Xs=37810,Js=37811,Ys=37812,Zs=37813,qs=37814,$s=37815,er=37816,tr=37817,ir=37818,sr=37819,rr=37820,nr=37821,or=36492,ar=3e3,lr=3001,ur=1e4,Ar=10001,cr=10002,hr=10003,dr=function(e){"LambertMaterial"===e._material._state.type?(this.vertex=function(e){var t=e.scene,i=e.scene._sectionPlanesState,s=e.scene._lightsState,r=e._geometry._state,n=e._state.billboard,o=e._state.stationary,a=i.getNumAllocatedSectionPlanes()>0,l=!!r.compressGeometry,u=[];u.push("#version 300 es"),u.push("// Lambertian drawing vertex shader"),u.push("in vec3 position;"),u.push("uniform mat4 modelMatrix;"),u.push("uniform mat4 viewMatrix;"),u.push("uniform mat4 projMatrix;"),u.push("uniform vec4 colorize;"),u.push("uniform vec3 offset;"),l&&u.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(u.push("uniform float logDepthBufFC;"),u.push("out float vFragDepth;"),u.push("bool isPerspectiveMatrix(mat4 m) {"),u.push(" return (m[2][3] == - 1.0);"),u.push("}"),u.push("out float isPerspective;"));a&&u.push("out vec4 vWorldPosition;");if(u.push("uniform vec4 lightAmbient;"),u.push("uniform vec4 materialColor;"),u.push("uniform vec3 materialEmissive;"),r.normalsBuf){u.push("in vec3 normal;"),u.push("uniform mat4 modelNormalMatrix;"),u.push("uniform mat4 viewNormalMatrix;");for(var A=0,c=s.lights.length;A= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),u.push(" }"),u.push(" return normalize(v);"),u.push("}"))}u.push("out vec4 vColor;"),"points"===r.primitiveName&&u.push("uniform float pointSize;");"spherical"!==n&&"cylindrical"!==n||(u.push("void billboard(inout mat4 mat) {"),u.push(" mat[0][0] = 1.0;"),u.push(" mat[0][1] = 0.0;"),u.push(" mat[0][2] = 0.0;"),"spherical"===n&&(u.push(" mat[1][0] = 0.0;"),u.push(" mat[1][1] = 1.0;"),u.push(" mat[1][2] = 0.0;")),u.push(" mat[2][0] = 0.0;"),u.push(" mat[2][1] = 0.0;"),u.push(" mat[2][2] =1.0;"),u.push("}"));u.push("void main(void) {"),u.push("vec4 localPosition = vec4(position, 1.0); "),u.push("vec4 worldPosition;"),l&&u.push("localPosition = positionsDecodeMatrix * localPosition;");r.normalsBuf&&(l?u.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):u.push("vec4 localNormal = vec4(normal, 0.0); "),u.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),u.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));u.push("mat4 viewMatrix2 = viewMatrix;"),u.push("mat4 modelMatrix2 = modelMatrix;"),o&&u.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===n||"cylindrical"===n?(u.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),u.push("billboard(modelMatrix2);"),u.push("billboard(viewMatrix2);"),u.push("billboard(modelViewMatrix);"),r.normalsBuf&&(u.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),u.push("billboard(modelNormalMatrix2);"),u.push("billboard(viewNormalMatrix2);"),u.push("billboard(modelViewNormalMatrix);")),u.push("worldPosition = modelMatrix2 * localPosition;"),u.push("worldPosition.xyz = worldPosition.xyz + offset;"),u.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(u.push("worldPosition = modelMatrix2 * localPosition;"),u.push("worldPosition.xyz = worldPosition.xyz + offset;"),u.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r.normalsBuf&&u.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(u.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),u.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),u.push("float lambertian = 1.0;"),r.normalsBuf)for(var d=0,p=s.lights.length;d0,n=t.gammaOutput,o=[];o.push("#version 300 es"),o.push("// Lambertian drawing fragment shader"),o.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),o.push("precision highp float;"),o.push("precision highp int;"),o.push("#else"),o.push("precision mediump float;"),o.push("precision mediump int;"),o.push("#endif"),t.logarithmicDepthBufferEnabled&&(o.push("in float isPerspective;"),o.push("uniform float logDepthBufFC;"),o.push("in float vFragDepth;"));if(r){o.push("in vec4 vWorldPosition;"),o.push("uniform bool clippable;");for(var a=0,l=i.getNumAllocatedSectionPlanes();a 0.0) { discard; }"),o.push("}")}"points"===s.primitiveName&&(o.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),o.push("float r = dot(cxy, cxy);"),o.push("if (r > 1.0) {"),o.push(" discard;"),o.push("}"));t.logarithmicDepthBufferEnabled&&o.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?o.push("outColor = linearToGamma(vColor, gammaFactor);"):o.push("outColor = vColor;");return o.push("}"),o}(e)):(this.vertex=function(e){var t=e.scene;e._material;var i,s=e._state,r=t._sectionPlanesState,n=e._geometry._state,o=t._lightsState,a=s.billboard,l=s.background,u=s.stationary,A=function(e){if(!e._geometry._state.uvBuf)return!1;var t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),c=vr(e),h=r.getNumAllocatedSectionPlanes()>0,d=fr(e),p=!!n.compressGeometry,f=[];f.push("#version 300 es"),f.push("// Drawing vertex shader"),f.push("in vec3 position;"),p&&f.push("uniform mat4 positionsDecodeMatrix;");f.push("uniform mat4 modelMatrix;"),f.push("uniform mat4 viewMatrix;"),f.push("uniform mat4 projMatrix;"),f.push("out vec3 vViewPosition;"),f.push("uniform vec3 offset;"),h&&f.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(f.push("uniform float logDepthBufFC;"),f.push("out float vFragDepth;"),f.push("bool isPerspectiveMatrix(mat4 m) {"),f.push(" return (m[2][3] == - 1.0);"),f.push("}"),f.push("out float isPerspective;"));o.lightMaps.length>0&&f.push("out vec3 vWorldNormal;");if(c){f.push("in vec3 normal;"),f.push("uniform mat4 modelNormalMatrix;"),f.push("uniform mat4 viewNormalMatrix;"),f.push("out vec3 vViewNormal;");for(var v=0,g=o.lights.length;v= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),f.push(" }"),f.push(" return normalize(v);"),f.push("}"))}A&&(f.push("in vec2 uv;"),f.push("out vec2 vUV;"),p&&f.push("uniform mat3 uvDecodeMatrix;"));n.colors&&(f.push("in vec4 color;"),f.push("out vec4 vColor;"));"points"===n.primitiveName&&f.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(f.push("void billboard(inout mat4 mat) {"),f.push(" mat[0][0] = 1.0;"),f.push(" mat[0][1] = 0.0;"),f.push(" mat[0][2] = 0.0;"),"spherical"===a&&(f.push(" mat[1][0] = 0.0;"),f.push(" mat[1][1] = 1.0;"),f.push(" mat[1][2] = 0.0;")),f.push(" mat[2][0] = 0.0;"),f.push(" mat[2][1] = 0.0;"),f.push(" mat[2][2] =1.0;"),f.push("}"));if(d){f.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(var m=0,_=o.lights.length;m<_;m++)o.lights[m].castsShadow&&(f.push("uniform mat4 shadowViewMatrix"+m+";"),f.push("uniform mat4 shadowProjMatrix"+m+";"),f.push("out vec4 vShadowPosFromLight"+m+";"))}f.push("void main(void) {"),f.push("vec4 localPosition = vec4(position, 1.0); "),f.push("vec4 worldPosition;"),p&&f.push("localPosition = positionsDecodeMatrix * localPosition;");c&&(p?f.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):f.push("vec4 localNormal = vec4(normal, 0.0); "),f.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),f.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));f.push("mat4 viewMatrix2 = viewMatrix;"),f.push("mat4 modelMatrix2 = modelMatrix;"),u?f.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;"):l&&f.push("viewMatrix2[3] = vec4(0.0, 0.0, 0.0 ,1.0);");"spherical"===a||"cylindrical"===a?(f.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),f.push("billboard(modelMatrix2);"),f.push("billboard(viewMatrix2);"),f.push("billboard(modelViewMatrix);"),c&&(f.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),f.push("billboard(modelNormalMatrix2);"),f.push("billboard(viewNormalMatrix2);"),f.push("billboard(modelViewNormalMatrix);")),f.push("worldPosition = modelMatrix2 * localPosition;"),f.push("worldPosition.xyz = worldPosition.xyz + offset;"),f.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(f.push("worldPosition = modelMatrix2 * localPosition;"),f.push("worldPosition.xyz = worldPosition.xyz + offset;"),f.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));if(c){f.push("vec3 worldNormal = (modelNormalMatrix2 * localNormal).xyz; "),o.lightMaps.length>0&&f.push("vWorldNormal = worldNormal;"),f.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),f.push("vec3 tmpVec3;"),f.push("float lightDist;");for(var y=0,b=o.lights.length;y0,l=vr(e),u=s.uvBuf,A="PhongMaterial"===o.type,c="MetallicMaterial"===o.type,h="SpecularMaterial"===o.type,d=fr(e);t.gammaInput;var p=t.gammaOutput,f=[];f.push("#version 300 es"),f.push("// Drawing fragment shader"),f.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),f.push("precision highp float;"),f.push("precision highp int;"),f.push("#else"),f.push("precision mediump float;"),f.push("precision mediump int;"),f.push("#endif"),t.logarithmicDepthBufferEnabled&&(f.push("in float isPerspective;"),f.push("uniform float logDepthBufFC;"),f.push("in float vFragDepth;"));d&&(f.push("float unpackDepth (vec4 color) {"),f.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),f.push(" return dot(color, bitShift);"),f.push("}"));f.push("uniform float gammaFactor;"),f.push("vec4 linearToLinear( in vec4 value ) {"),f.push(" return value;"),f.push("}"),f.push("vec4 sRGBToLinear( in vec4 value ) {"),f.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),f.push("}"),f.push("vec4 gammaToLinear( in vec4 value) {"),f.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),f.push("}"),p&&(f.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),f.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),f.push("}"));if(a){f.push("in vec4 vWorldPosition;"),f.push("uniform bool clippable;");for(var v=0;v0&&(f.push("uniform samplerCube lightMap;"),f.push("uniform mat4 viewNormalMatrix;")),n.reflectionMaps.length>0&&f.push("uniform samplerCube reflectionMap;"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&f.push("uniform mat4 viewMatrix;"),f.push("#define PI 3.14159265359"),f.push("#define RECIPROCAL_PI 0.31830988618"),f.push("#define RECIPROCAL_PI2 0.15915494"),f.push("#define EPSILON 1e-6"),f.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),f.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),f.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),f.push("}"),f.push("struct IncidentLight {"),f.push(" vec3 color;"),f.push(" vec3 direction;"),f.push("};"),f.push("struct ReflectedLight {"),f.push(" vec3 diffuse;"),f.push(" vec3 specular;"),f.push("};"),f.push("struct Geometry {"),f.push(" vec3 position;"),f.push(" vec3 viewNormal;"),f.push(" vec3 worldNormal;"),f.push(" vec3 viewEyeDir;"),f.push("};"),f.push("struct Material {"),f.push(" vec3 diffuseColor;"),f.push(" float specularRoughness;"),f.push(" vec3 specularColor;"),f.push(" float shine;"),f.push("};"),A&&((n.lightMaps.length>0||n.reflectionMaps.length>0)&&(f.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(f.push(" vec3 irradiance = "+pr[n.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),f.push(" radiance *= PI;"),f.push(" reflectedLight.specular += radiance;")),f.push("}")),f.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),f.push(" vec3 irradiance = dotNL * directLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),f.push("}")),(c||h)&&(f.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),f.push(" float r = ggxRoughness + 0.0001;"),f.push(" return (2.0 / (r * r) - 2.0);"),f.push("}"),f.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),f.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),f.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),f.push("}"),n.reflectionMaps.length>0&&(f.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),f.push(" vec3 envMapColor = "+pr[n.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),f.push(" return envMapColor;"),f.push("}")),f.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),f.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),f.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),f.push("}"),f.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" return 1.0 / ( gl * gv );"),f.push("}"),f.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" return 0.5 / max( gv + gl, EPSILON );"),f.push("}"),f.push("float D_GGX(const in float alpha, const in float dotNH) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),f.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float alpha = ( roughness * roughness );"),f.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),f.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),f.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),f.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),f.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),f.push(" vec3 F = F_Schlick( specularColor, dotLH );"),f.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),f.push(" float D = D_GGX( alpha, dotNH );"),f.push(" return F * (G * D);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),f.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),f.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),f.push(" vec4 r = roughness * c0 + c1;"),f.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),f.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),f.push(" return specularColor * AB.x + AB.y;"),f.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(f.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(f.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),f.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),f.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),f.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),f.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),f.push("}")),f.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),f.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),f.push("}")));f.push("in vec3 vViewPosition;"),s.colors&&f.push("in vec4 vColor;");u&&(l&&i._normalMap||i._ambientMap||i._baseColorMap||i._diffuseMap||i._emissiveMap||i._metallicMap||i._roughnessMap||i._metallicRoughnessMap||i._specularMap||i._glossinessMap||i._specularGlossinessMap||i._occlusionMap||i._alphaMap)&&f.push("in vec2 vUV;");l&&(n.lightMaps.length>0&&f.push("in vec3 vWorldNormal;"),f.push("in vec3 vViewNormal;"));o.ambient&&f.push("uniform vec3 materialAmbient;");o.baseColor&&f.push("uniform vec3 materialBaseColor;");void 0!==o.alpha&&null!==o.alpha&&f.push("uniform vec4 materialAlphaModeCutoff;");o.emissive&&f.push("uniform vec3 materialEmissive;");o.diffuse&&f.push("uniform vec3 materialDiffuse;");void 0!==o.glossiness&&null!==o.glossiness&&f.push("uniform float materialGlossiness;");void 0!==o.shininess&&null!==o.shininess&&f.push("uniform float materialShininess;");o.specular&&f.push("uniform vec3 materialSpecular;");void 0!==o.metallic&&null!==o.metallic&&f.push("uniform float materialMetallic;");void 0!==o.roughness&&null!==o.roughness&&f.push("uniform float materialRoughness;");void 0!==o.specularF0&&null!==o.specularF0&&f.push("uniform float materialSpecularF0;");u&&i._ambientMap&&(f.push("uniform sampler2D ambientMap;"),i._ambientMap._state.matrix&&f.push("uniform mat4 ambientMapMatrix;"));u&&i._baseColorMap&&(f.push("uniform sampler2D baseColorMap;"),i._baseColorMap._state.matrix&&f.push("uniform mat4 baseColorMapMatrix;"));u&&i._diffuseMap&&(f.push("uniform sampler2D diffuseMap;"),i._diffuseMap._state.matrix&&f.push("uniform mat4 diffuseMapMatrix;"));u&&i._emissiveMap&&(f.push("uniform sampler2D emissiveMap;"),i._emissiveMap._state.matrix&&f.push("uniform mat4 emissiveMapMatrix;"));l&&u&&i._metallicMap&&(f.push("uniform sampler2D metallicMap;"),i._metallicMap._state.matrix&&f.push("uniform mat4 metallicMapMatrix;"));l&&u&&i._roughnessMap&&(f.push("uniform sampler2D roughnessMap;"),i._roughnessMap._state.matrix&&f.push("uniform mat4 roughnessMapMatrix;"));l&&u&&i._metallicRoughnessMap&&(f.push("uniform sampler2D metallicRoughnessMap;"),i._metallicRoughnessMap._state.matrix&&f.push("uniform mat4 metallicRoughnessMapMatrix;"));l&&i._normalMap&&(f.push("uniform sampler2D normalMap;"),i._normalMap._state.matrix&&f.push("uniform mat4 normalMapMatrix;"),f.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),f.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),f.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),f.push(" vec2 st0 = dFdx( uv.st );"),f.push(" vec2 st1 = dFdy( uv.st );"),f.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),f.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),f.push(" vec3 N = normalize( surf_norm );"),f.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),f.push(" mat3 tsn = mat3( S, T, N );"),f.push(" return normalize( tsn * mapN );"),f.push("}"));u&&i._occlusionMap&&(f.push("uniform sampler2D occlusionMap;"),i._occlusionMap._state.matrix&&f.push("uniform mat4 occlusionMapMatrix;"));u&&i._alphaMap&&(f.push("uniform sampler2D alphaMap;"),i._alphaMap._state.matrix&&f.push("uniform mat4 alphaMapMatrix;"));l&&u&&i._specularMap&&(f.push("uniform sampler2D specularMap;"),i._specularMap._state.matrix&&f.push("uniform mat4 specularMapMatrix;"));l&&u&&i._glossinessMap&&(f.push("uniform sampler2D glossinessMap;"),i._glossinessMap._state.matrix&&f.push("uniform mat4 glossinessMapMatrix;"));l&&u&&i._specularGlossinessMap&&(f.push("uniform sampler2D materialSpecularGlossinessMap;"),i._specularGlossinessMap._state.matrix&&f.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));l&&(i._diffuseFresnel||i._specularFresnel||i._alphaFresnel||i._emissiveFresnel||i._reflectivityFresnel)&&(f.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),f.push(" float fr = abs(dot(eyeDir, normal));"),f.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),f.push(" return pow(finalFr, power);"),f.push("}"),i._diffuseFresnel&&(f.push("uniform float diffuseFresnelCenterBias;"),f.push("uniform float diffuseFresnelEdgeBias;"),f.push("uniform float diffuseFresnelPower;"),f.push("uniform vec3 diffuseFresnelCenterColor;"),f.push("uniform vec3 diffuseFresnelEdgeColor;")),i._specularFresnel&&(f.push("uniform float specularFresnelCenterBias;"),f.push("uniform float specularFresnelEdgeBias;"),f.push("uniform float specularFresnelPower;"),f.push("uniform vec3 specularFresnelCenterColor;"),f.push("uniform vec3 specularFresnelEdgeColor;")),i._alphaFresnel&&(f.push("uniform float alphaFresnelCenterBias;"),f.push("uniform float alphaFresnelEdgeBias;"),f.push("uniform float alphaFresnelPower;"),f.push("uniform vec3 alphaFresnelCenterColor;"),f.push("uniform vec3 alphaFresnelEdgeColor;")),i._reflectivityFresnel&&(f.push("uniform float materialSpecularF0FresnelCenterBias;"),f.push("uniform float materialSpecularF0FresnelEdgeBias;"),f.push("uniform float materialSpecularF0FresnelPower;"),f.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),f.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),i._emissiveFresnel&&(f.push("uniform float emissiveFresnelCenterBias;"),f.push("uniform float emissiveFresnelEdgeBias;"),f.push("uniform float emissiveFresnelPower;"),f.push("uniform vec3 emissiveFresnelCenterColor;"),f.push("uniform vec3 emissiveFresnelEdgeColor;")));if(f.push("uniform vec4 lightAmbient;"),l)for(var g=0,m=n.lights.length;g 0.0) { discard; }"),f.push("}")}"points"===s.primitiveName&&(f.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),f.push("float r = dot(cxy, cxy);"),f.push("if (r > 1.0) {"),f.push(" discard;"),f.push("}"));f.push("float occlusion = 1.0;"),o.ambient?f.push("vec3 ambientColor = materialAmbient;"):f.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");o.diffuse?f.push("vec3 diffuseColor = materialDiffuse;"):o.baseColor?f.push("vec3 diffuseColor = materialBaseColor;"):f.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");s.colors&&f.push("diffuseColor *= vColor.rgb;");o.emissive?f.push("vec3 emissiveColor = materialEmissive;"):f.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");o.specular?f.push("vec3 specular = materialSpecular;"):f.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==o.alpha?f.push("float alpha = materialAlphaModeCutoff[0];"):f.push("float alpha = 1.0;");s.colors&&f.push("alpha *= vColor.a;");void 0!==o.glossiness?f.push("float glossiness = materialGlossiness;"):f.push("float glossiness = 1.0;");void 0!==o.metallic?f.push("float metallic = materialMetallic;"):f.push("float metallic = 1.0;");void 0!==o.roughness?f.push("float roughness = materialRoughness;"):f.push("float roughness = 1.0;");void 0!==o.specularF0?f.push("float specularF0 = materialSpecularF0;"):f.push("float specularF0 = 1.0;");u&&(l&&i._normalMap||i._ambientMap||i._baseColorMap||i._diffuseMap||i._occlusionMap||i._emissiveMap||i._metallicMap||i._roughnessMap||i._metallicRoughnessMap||i._specularMap||i._glossinessMap||i._specularGlossinessMap||i._alphaMap)&&(f.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),f.push("vec2 textureCoord;"));u&&i._ambientMap&&(i._ambientMap._state.matrix?f.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),f.push("ambientTexel = "+pr[i._ambientMap._state.encoding]+"(ambientTexel);"),f.push("ambientColor *= ambientTexel.rgb;"));u&&i._diffuseMap&&(i._diffuseMap._state.matrix?f.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),f.push("diffuseTexel = "+pr[i._diffuseMap._state.encoding]+"(diffuseTexel);"),f.push("diffuseColor *= diffuseTexel.rgb;"),f.push("alpha *= diffuseTexel.a;"));u&&i._baseColorMap&&(i._baseColorMap._state.matrix?f.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),f.push("baseColorTexel = "+pr[i._baseColorMap._state.encoding]+"(baseColorTexel);"),f.push("diffuseColor *= baseColorTexel.rgb;"),f.push("alpha *= baseColorTexel.a;"));u&&i._emissiveMap&&(i._emissiveMap._state.matrix?f.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),f.push("emissiveTexel = "+pr[i._emissiveMap._state.encoding]+"(emissiveTexel);"),f.push("emissiveColor = emissiveTexel.rgb;"));u&&i._alphaMap&&(i._alphaMap._state.matrix?f.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("alpha *= texture(alphaMap, textureCoord).r;"));u&&i._occlusionMap&&(i._occlusionMap._state.matrix?f.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(l&&(n.lights.length>0||n.lightMaps.length>0||n.reflectionMaps.length>0)){u&&i._normalMap?(i._normalMap._state.matrix?f.push("textureCoord = (normalMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):f.push("vec3 viewNormal = normalize(vViewNormal);"),u&&i._specularMap&&(i._specularMap._state.matrix?f.push("textureCoord = (specularMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("specular *= texture(specularMap, textureCoord).rgb;")),u&&i._glossinessMap&&(i._glossinessMap._state.matrix?f.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("glossiness *= texture(glossinessMap, textureCoord).r;")),u&&i._specularGlossinessMap&&(i._specularGlossinessMap._state.matrix?f.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),f.push("specular *= specGlossRGB.rgb;"),f.push("glossiness *= specGlossRGB.a;")),u&&i._metallicMap&&(i._metallicMap._state.matrix?f.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("metallic *= texture(metallicMap, textureCoord).r;")),u&&i._roughnessMap&&(i._roughnessMap._state.matrix?f.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("roughness *= texture(roughnessMap, textureCoord).r;")),u&&i._metallicRoughnessMap&&(i._metallicRoughnessMap._state.matrix?f.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),f.push("metallic *= metalRoughRGB.b;"),f.push("roughness *= metalRoughRGB.g;")),f.push("vec3 viewEyeDir = normalize(-vViewPosition);"),i._diffuseFresnel&&(f.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),f.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),i._specularFresnel&&(f.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),f.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),i._alphaFresnel&&(f.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),f.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),i._emissiveFresnel&&(f.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),f.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),f.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),f.push(" discard;"),f.push("}"),f.push("IncidentLight light;"),f.push("Material material;"),f.push("Geometry geometry;"),f.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),f.push("vec3 viewLightDir;"),A&&(f.push("material.diffuseColor = diffuseColor;"),f.push("material.specularColor = specular;"),f.push("material.shine = materialShininess;")),h&&(f.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),f.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),f.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),f.push("material.specularColor = specular;")),c&&(f.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),f.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),f.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),f.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),f.push("geometry.position = vViewPosition;"),n.lightMaps.length>0&&f.push("geometry.worldNormal = normalize(vWorldNormal);"),f.push("geometry.viewNormal = viewNormal;"),f.push("geometry.viewEyeDir = viewEyeDir;"),A&&(n.lightMaps.length>0||n.reflectionMaps.length>0)&&f.push("computePhongLightMapping(geometry, material, reflectedLight);"),(h||c)&&(n.lightMaps.length>0||n.reflectionMaps.length>0)&&f.push("computePBRLightMapping(geometry, material, reflectedLight);"),f.push("float shadow = 1.0;"),f.push("float shadowAcneRemover = 0.007;"),f.push("vec3 fragmentDepth;"),f.push("float texelSize = 1.0 / 1024.0;"),f.push("float amountInLight = 0.0;"),f.push("vec3 shadowCoord;"),f.push("vec4 rgbaDepth;"),f.push("float depth;");for(var w=0,B=n.lights.length;w0)for(var f=s._sectionPlanesState.sectionPlanes,v=t.renderFlags,g=0;g0&&(this._uLightMap="lightMap"),r.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(A=0,c=n.sectionPlanes.length;A0&&n.lightMaps[0].texture&&this._uLightMap&&(a.bindTexture(this._uLightMap,n.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%i,e.bindTexture++),n.reflectionMaps.length>0&&n.reflectionMaps[0].texture&&this._uReflectionMap&&(a.bindTexture(this._uReflectionMap,n.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%i,e.bindTexture++),this._uGammaFactor&&r.uniform1f(this._uGammaFactor,s.gammaFactor),this._baseTextureUnit=e.textureUnit};var br=C((function e(t){x(this,e),this.vertex=function(e){var t=e.scene,i=t._lightsState,s=function(e){var t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),r=t._sectionPlanesState.getNumAllocatedSectionPlanes()>0,n=!!e._geometry._state.compressGeometry,o=e._state.billboard,a=e._state.stationary,l=[];l.push("#version 300 es"),l.push("// EmphasisFillShaderSource vertex shader"),l.push("in vec3 position;"),l.push("uniform mat4 modelMatrix;"),l.push("uniform mat4 viewMatrix;"),l.push("uniform mat4 projMatrix;"),l.push("uniform vec4 colorize;"),l.push("uniform vec3 offset;"),n&&l.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;"));r&&l.push("out vec4 vWorldPosition;");if(l.push("uniform vec4 lightAmbient;"),l.push("uniform vec4 fillColor;"),s){l.push("in vec3 normal;"),l.push("uniform mat4 modelNormalMatrix;"),l.push("uniform mat4 viewNormalMatrix;");for(var u=0,A=i.lights.length;u= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"))}l.push("out vec4 vColor;"),("spherical"===o||"cylindrical"===o)&&(l.push("void billboard(inout mat4 mat) {"),l.push(" mat[0][0] = 1.0;"),l.push(" mat[0][1] = 0.0;"),l.push(" mat[0][2] = 0.0;"),"spherical"===o&&(l.push(" mat[1][0] = 0.0;"),l.push(" mat[1][1] = 1.0;"),l.push(" mat[1][2] = 0.0;")),l.push(" mat[2][0] = 0.0;"),l.push(" mat[2][1] = 0.0;"),l.push(" mat[2][2] =1.0;"),l.push("}"));l.push("void main(void) {"),l.push("vec4 localPosition = vec4(position, 1.0); "),l.push("vec4 worldPosition;"),n&&l.push("localPosition = positionsDecodeMatrix * localPosition;");s&&(n?l.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):l.push("vec4 localNormal = vec4(normal, 0.0); "),l.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),l.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));l.push("mat4 viewMatrix2 = viewMatrix;"),l.push("mat4 modelMatrix2 = modelMatrix;"),a&&l.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===o||"cylindrical"===o?(l.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),l.push("billboard(modelMatrix2);"),l.push("billboard(viewMatrix2);"),l.push("billboard(modelViewMatrix);"),s&&(l.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),l.push("billboard(modelNormalMatrix2);"),l.push("billboard(viewNormalMatrix2);"),l.push("billboard(modelViewNormalMatrix);")),l.push("worldPosition = modelMatrix2 * localPosition;"),l.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(l.push("worldPosition = modelMatrix2 * localPosition;"),l.push("worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s&&l.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),s)for(var h=0,d=i.lights.length;h0,n=[];n.push("#version 300 es"),n.push("// Lambertian drawing 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"),t.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"));s&&(n.push("uniform float gammaFactor;"),n.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),n.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),n.push("}"));if(r){n.push("in vec4 vWorldPosition;"),n.push("uniform bool clippable;");for(var o=0,a=i.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),n.push("}")}"points"===e._geometry._state.primitiveName&&(n.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),n.push("float r = dot(cxy, cxy);"),n.push("if (r > 1.0) {"),n.push(" discard;"),n.push("}"));t.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");s?n.push("outColor = linearToGamma(vColor, gammaFactor);"):n.push("outColor = vColor;");return n.push("}"),n}(t)}));var wr=new Q({}),Br=$.vec3(),xr=function(e,t){this.id=wr.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new br(t),this._allocate(t)},Pr={};xr.get=function(e){var t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),i=Pr[t];return i||(i=new xr(t,e),Pr[t]=i,se.memory.programs++),i._useCount++,i},xr.prototype.put=function(){0==--this._useCount&&(wr.removeItem(this.id),this._program&&this._program.destroy(),delete Pr[this._hash],se.memory.programs--)},xr.prototype.webglContextRestored=function(){this._program=null},xr.prototype.drawMesh=function(e,t,i){this._program||this._allocate(t);var s=this._scene,r=s.camera,n=s.canvas.gl,o=0===i?t._xrayMaterial._state:1===i?t._highlightMaterial._state:t._selectedMaterial._state,a=t._state,l=t._geometry._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(a.originHash,u):r.viewMatrix),n.uniformMatrix4fv(this._uViewNormalMatrix,!1,r.viewNormalMatrix),a.clippable){var A=s._sectionPlanesState.getNumAllocatedSectionPlanes(),c=s._sectionPlanesState.sectionPlanes.length;if(A>0)for(var h=s._sectionPlanesState.sectionPlanes,d=t.renderFlags,p=0;p0,s=!!e._geometry._state.compressGeometry,r=e._state.billboard,n=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// Edges drawing vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("uniform vec4 edgeColor;"),o.push("uniform vec3 offset;"),s&&o.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));i&&o.push("out vec4 vWorldPosition;");o.push("out vec4 vColor;"),("spherical"===r||"cylindrical"===r)&&(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),o.push("vec4 worldPosition;"),s&&o.push("localPosition = positionsDecodeMatrix * localPosition;");o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),n&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===r||"cylindrical"===r?(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"),o.push("billboard(modelViewMatrix);"),o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));o.push("vColor = edgeColor;"),i&&o.push("vWorldPosition = worldPosition;");o.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(o.push("vFragDepth = 1.0 + clipPos.w;"),o.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return o.push("gl_Position = clipPos;"),o.push("}"),o}(t),this.fragment=function(e){var t=e.scene,i=e.scene._sectionPlanesState,s=e.scene.gammaOutput,r=i.getNumAllocatedSectionPlanes()>0,n=[];n.push("#version 300 es"),n.push("// Edges drawing 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"),t.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"));s&&(n.push("uniform float gammaFactor;"),n.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),n.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),n.push("}"));if(r){n.push("in vec4 vWorldPosition;"),n.push("uniform bool clippable;");for(var o=0,a=i.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),n.push("}")}t.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");s?n.push("outColor = linearToGamma(vColor, gammaFactor);"):n.push("outColor = vColor;");return n.push("}"),n}(t)}));var Mr=new Q({}),Fr=$.vec3(),Er=function(e,t){this.id=Mr.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Cr(t),this._allocate(t)},kr={};Er.get=function(e){var t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),i=kr[t];return i||(i=new Er(t,e),kr[t]=i,se.memory.programs++),i._useCount++,i},Er.prototype.put=function(){0==--this._useCount&&(Mr.removeItem(this.id),this._program&&this._program.destroy(),delete kr[this._hash],se.memory.programs--)},Er.prototype.webglContextRestored=function(){this._program=null},Er.prototype.drawMesh=function(e,t,i){this._program||this._allocate(t);var s,r,n=this._scene,o=n.camera,a=n.canvas.gl,l=t._state,u=t._geometry,A=u._state,c=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,c?e.getRTCViewMatrix(l.originHash,c):o.viewMatrix),l.clippable){var h=n._sectionPlanesState.getNumAllocatedSectionPlanes(),d=n._sectionPlanesState.sectionPlanes.length;if(h>0)for(var p=n._sectionPlanesState.sectionPlanes,f=t.renderFlags,v=0;v0,s=!!e._geometry._state.compressGeometry,r=e._state.billboard,n=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// Mesh picking vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("out vec4 vViewPosition;"),o.push("uniform vec3 offset;"),s&&o.push("uniform mat4 positionsDecodeMatrix;");i&&o.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));"spherical"!==r&&"cylindrical"!==r||(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("uniform vec2 pickClipPos;"),o.push("vec4 remapClipPos(vec4 clipPos) {"),o.push(" clipPos.xy /= clipPos.w;"),o.push(" clipPos.xy -= pickClipPos;"),o.push(" clipPos.xy *= clipPos.w;"),o.push(" return clipPos;"),o.push("}"),o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),s&&o.push("localPosition = positionsDecodeMatrix * localPosition;");o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),n&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==r&&"cylindrical"!==r||(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"));o.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),o.push(" worldPosition.xyz = worldPosition.xyz + offset;"),o.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),i&&o.push(" vWorldPosition = worldPosition;");o.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(o.push("vFragDepth = 1.0 + clipPos.w;"),o.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return o.push("gl_Position = remapClipPos(clipPos);"),o.push("}"),o}(t),this.fragment=function(e){var t=e.scene,i=t._sectionPlanesState,s=i.getNumAllocatedSectionPlanes()>0,r=[];r.push("#version 300 es"),r.push("// Mesh picking 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"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(r.push("uniform vec4 pickColor;"),s){r.push("uniform bool clippable;"),r.push("in vec4 vWorldPosition;");for(var n=0;n 0.0) { discard; }"),r.push("}")}t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return r.push(" outColor = pickColor; "),r.push("}"),r}(t)}));var Dr=$.vec3(),Sr=function(e,t){this._hash=e,this._shaderSource=new Ir(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Tr={};Sr.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";"),i=Tr[t];if(!i){if((i=new Sr(t,e)).errors)return console.log(i.errors.join("\n")),null;Tr[t]=i,se.memory.programs++}return i._useCount++,i},Sr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Tr[this._hash],se.memory.programs--)},Sr.prototype.webglContextRestored=function(){this._program=null},Sr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var i=this._scene,s=i.canvas.gl,r=t._state,n=t._material._state,o=t._geometry._state,a=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),s.uniformMatrix4fv(this._uViewMatrix,!1,a?e.getRTCPickViewMatrix(r.originHash,a):e.pickViewMatrix),r.clippable){var l=i._sectionPlanesState.getNumAllocatedSectionPlanes(),u=i._sectionPlanesState.sectionPlanes.length;if(l>0)for(var A=i._sectionPlanesState.sectionPlanes,c=t.renderFlags,h=0;h>24&255,b=_>>16&255,w=_>>8&255,B=255&_;s.uniform4f(this._uPickColor,B/255,w/255,b/255,y/255),s.uniform2fv(this._uPickClipPos,e.pickClipPos),o.indicesBuf?(s.drawElements(o.primitive,o.indicesBuf.numItems,o.indicesBuf.itemType,0),e.drawElements++):o.positions&&s.drawArrays(s.TRIANGLES,0,o.positions.numItems)},Sr.prototype._allocate=function(e){var t=e.scene,i=t.canvas.gl;if(this._program=new kt(i,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var s=this._program;this._uPositionsDecodeMatrix=s.getLocation("positionsDecodeMatrix"),this._uModelMatrix=s.getLocation("modelMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,n=t._sectionPlanesState.sectionPlanes.length;r0,s=!!e._geometry._state.compressGeometry,r=[];r.push("#version 300 es"),r.push("// Surface picking vertex shader"),r.push("in vec3 position;"),r.push("in vec4 color;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec3 offset;"),i&&(r.push("uniform bool clippable;"),r.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));r.push("uniform vec2 pickClipPos;"),r.push("vec4 remapClipPos(vec4 clipPos) {"),r.push(" clipPos.xy /= clipPos.w;"),r.push(" clipPos.xy -= pickClipPos;"),r.push(" clipPos.xy *= clipPos.w;"),r.push(" return clipPos;"),r.push("}"),r.push("out vec4 vColor;"),s&&r.push("uniform mat4 positionsDecodeMatrix;");r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),s&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push(" vec4 worldPosition = modelMatrix * localPosition; "),r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition;"),i&&r.push(" vWorldPosition = worldPosition;");r.push(" vColor = color;"),r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = remapClipPos(clipPos);"),r.push("}"),r}(t),this.fragment=function(e){var t=e.scene,i=t._sectionPlanesState,s=i.getNumAllocatedSectionPlanes()>0,r=[];r.push("#version 300 es"),r.push("// Surface picking 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"),r.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(s){r.push("uniform bool clippable;"),r.push("in vec4 vWorldPosition;");for(var n=0;n 0.0) { discard; }"),r.push("}")}t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return r.push(" outColor = vColor;"),r.push("}"),r}(t)}));var Lr=$.vec3(),Ur=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Rr(t),this._allocate(t)},Or={};Ur.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),i=Or[t];if(!i){if((i=new Ur(t,e)).errors)return console.log(i.errors.join("\n")),null;Or[t]=i,se.memory.programs++}return i._useCount++,i},Ur.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Or[this._hash],se.memory.programs--)},Ur.prototype.webglContextRestored=function(){this._program=null},Ur.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var i=this._scene,s=i.canvas.gl,r=t._state,n=t._material._state,o=t._geometry,a=t._geometry._state,l=t.origin,u=n.backfaces,A=n.frontface,c=i.camera.project,h=o._getPickTrianglePositions(),d=o._getPickTriangleColors();if(this._program.bind(),e.useProgram++,i.logarithmicDepthBufferEnabled){var p=2/(Math.log(c.far+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,p)}if(s.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(r.originHash,l):e.pickViewMatrix),r.clippable){var f=i._sectionPlanesState.getNumAllocatedSectionPlanes(),v=i._sectionPlanesState.sectionPlanes.length;if(f>0)for(var g=i._sectionPlanesState.sectionPlanes,m=t.renderFlags,_=0;_0,s=!!e._geometry._state.compressGeometry,r=e._state.billboard,n=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// Mesh occlusion vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("uniform vec3 offset;"),s&&o.push("uniform mat4 positionsDecodeMatrix;");i&&o.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));"spherical"!==r&&"cylindrical"!==r||(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),o.push("vec4 worldPosition;"),s&&o.push("localPosition = positionsDecodeMatrix * localPosition;");o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),n&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===r||"cylindrical"===r?(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"),o.push("billboard(modelViewMatrix);"),o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i&&o.push(" vWorldPosition = worldPosition;");o.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(o.push("vFragDepth = 1.0 + clipPos.w;"),o.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return o.push("gl_Position = clipPos;"),o.push("}"),o}(t),this.fragment=function(e){var t=e.scene,i=t._sectionPlanesState,s=i.getNumAllocatedSectionPlanes()>0,r=[];r.push("#version 300 es"),r.push("// Mesh occlusion 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"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(s){r.push("uniform bool clippable;"),r.push("in vec4 vWorldPosition;");for(var n=0;n 0.0) { discard; }"),r.push("}")}r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return r.push("}"),r}(t)}));var Qr=$.vec3(),Vr=function(e,t){this._hash=e,this._shaderSource=new Nr(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Hr={};Vr.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";"),i=Hr[t];if(!i){if((i=new Vr(t,e)).errors)return console.log(i.errors.join("\n")),null;Hr[t]=i,se.memory.programs++}return i._useCount++,i},Vr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Hr[this._hash],se.memory.programs--)},Vr.prototype.webglContextRestored=function(){this._program=null},Vr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var i=this._scene,s=i.canvas.gl,r=t._material._state,n=t._state,o=t._geometry._state,a=t.origin;if(!(r.alpha<1)){if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),r.id!==this._lastMaterialId){var l=r.backfaces;e.backfaces!==l&&(l?s.disable(s.CULL_FACE):s.enable(s.CULL_FACE),e.backfaces=l);var u=r.frontface;e.frontface!==u&&(u?s.frontFace(s.CCW):s.frontFace(s.CW),e.frontface=u),this._lastMaterialId=r.id}var A=i.camera;if(s.uniformMatrix4fv(this._uViewMatrix,!1,a?e.getRTCViewMatrix(n.originHash,a):A.viewMatrix),n.clippable){var c=i._sectionPlanesState.getNumAllocatedSectionPlanes(),h=i._sectionPlanesState.sectionPlanes.length;if(c>0)for(var d=i._sectionPlanesState.sectionPlanes,p=t.renderFlags,f=0;f0,i=!!e._geometry._state.compressGeometry,s=[];s.push("// Mesh shadow vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),s.push("uniform vec3 offset;"),i&&s.push("uniform mat4 positionsDecodeMatrix;");t&&s.push("out vec4 vWorldPosition;");s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),s.push("vec4 worldPosition;"),i&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("worldPosition = modelMatrix * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&s.push("vWorldPosition = worldPosition;");return s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene;t.canvas.gl;var i=t._sectionPlanesState,s=i.getNumAllocatedSectionPlanes()>0,r=[];if(r.push("// Mesh shadow 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"),s){r.push("uniform bool clippable;"),r.push("in vec4 vWorldPosition;");for(var n=0;n 0.0) { discard; }"),r.push("}")}return r.push("outColor = encodeFloat(gl_FragCoord.z);"),r.push("}"),r}(t)}));var Gr=function(e,t){this._hash=e,this._shaderSource=new jr(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},zr={};Gr.get=function(e){var t=e.scene,i=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";"),s=zr[i];if(!s){if((s=new Gr(i,e)).errors)return console.log(s.errors.join("\n")),null;zr[i]=s,se.memory.programs++}return s._useCount++,s},Gr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete zr[this._hash],se.memory.programs--)},Gr.prototype.webglContextRestored=function(){this._program=null},Gr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var i=this._scene.canvas.gl,s=t._material._state,r=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),s.id!==this._lastMaterialId){var n=s.backfaces;e.backfaces!==n&&(n?i.disable(i.CULL_FACE):i.enable(i.CULL_FACE),e.backfaces=n);var o=s.frontface;e.frontface!==o&&(o?i.frontFace(i.CCW):i.frontFace(i.CW),e.frontface=o),e.lineWidth!==s.lineWidth&&(i.lineWidth(s.lineWidth),e.lineWidth=s.lineWidth),this._uPointSize&&i.uniform1i(this._uPointSize,s.pointSize),this._lastMaterialId=s.id}if(i.uniformMatrix4fv(this._uModelMatrix,i.FALSE,t.worldMatrix),r.combineGeometry){var a=t.vertexBufs;a.id!==this._lastVertexBufsId&&(a.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(a.positionsBuf,a.compressGeometry?i.UNSIGNED_SHORT:i.FLOAT),e.bindArray++),this._lastVertexBufsId=a.id)}this._uClippable&&i.uniform1i(this._uClippable,t._state.clippable),i.uniform3fv(this._uOffset,t._state.offset),r.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&i.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,r.positionsDecodeMatrix),r.combineGeometry?r.indicesBufCombined&&(r.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(r.positionsBuf,r.compressGeometry?i.UNSIGNED_SHORT:i.FLOAT),e.bindArray++),r.indicesBuf&&(r.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=r.id),r.combineGeometry?r.indicesBufCombined&&(i.drawElements(r.primitive,r.indicesBufCombined.numItems,r.indicesBufCombined.itemType,0),e.drawElements++):r.indicesBuf?(i.drawElements(r.primitive,r.indicesBuf.numItems,r.indicesBuf.itemType,0),e.drawElements++):r.positions&&(i.drawArrays(i.TRIANGLES,0,r.positions.numItems),e.drawArrays++)},Gr.prototype._allocate=function(e){var t=e.scene,i=t.canvas.gl;if(this._program=new kt(i,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)this.errors=this._program.errors;else{var s=this._program;this._uPositionsDecodeMatrix=s.getLocation("positionsDecodeMatrix"),this._uModelMatrix=s.getLocation("modelMatrix"),this._uShadowViewMatrix=s.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=s.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(var r=0,n=t._sectionPlanesState.sectionPlanes.length;r0)for(var r,n,o,a=0,l=this._uSectionPlanes.length;a1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e,r)).originalSystemId=r.originalSystemId||s.id,s.renderFlags=new Wr,s._state=new Zt({visible:!0,culled:!1,pickable:null,clippable:null,collidable:null,occluder:!1!==r.occluder,castsShadow:null,receivesShadow:null,xrayed:!1,highlighted:!1,selected:!1,edges:!1,stationary:!!r.stationary,background:!!r.background,billboard:s._checkBillboard(r.billboard),layer:null,colorize:null,pickID:s.scene._renderer.getPickID(b(s)),drawHash:"",pickHash:"",offset:$.vec3(),origin:null,originHash:null}),s._drawRenderer=null,s._shadowRenderer=null,s._emphasisFillRenderer=null,s._emphasisEdgesRenderer=null,s._pickMeshRenderer=null,s._pickTriangleRenderer=null,s._occlusionRenderer=null,s._geometry=r.geometry?s._checkComponent2(["ReadableGeometry","VBOGeometry"],r.geometry):s.scene.geometry,s._material=r.material?s._checkComponent2(["PhongMaterial","MetallicMaterial","SpecularMaterial","LambertMaterial"],r.material):s.scene.material,s._xrayMaterial=r.xrayMaterial?s._checkComponent("EmphasisMaterial",r.xrayMaterial):s.scene.xrayMaterial,s._highlightMaterial=r.highlightMaterial?s._checkComponent("EmphasisMaterial",r.highlightMaterial):s.scene.highlightMaterial,s._selectedMaterial=r.selectedMaterial?s._checkComponent("EmphasisMaterial",r.selectedMaterial):s.scene.selectedMaterial,s._edgeMaterial=r.edgeMaterial?s._checkComponent("EdgeMaterial",r.edgeMaterial):s.scene.edgeMaterial,s._parentNode=null,s._aabb=null,s._aabbDirty=!0,s._numTriangles=s._geometry?s._geometry.numTriangles:0,s.scene._aabbDirty=!0,s._scale=$.vec3(),s._quaternion=$.identityQuaternion(),s._rotation=$.vec3(),s._position=$.vec3(),s._worldMatrix=$.identityMat4(),s._worldNormalMatrix=$.identityMat4(),s._localMatrixDirty=!0,s._worldMatrixDirty=!0,s._worldNormalMatrixDirty=!0;var n=r.origin||r.rtcCenter;if(n&&(s._state.origin=$.vec3(n),s._state.originHash=n.join()),r.matrix?s.matrix=r.matrix:(s.scale=r.scale,s.position=r.position,r.quaternion||(s.rotation=r.rotation)),s._isObject=r.isObject,s._isObject&&s.scene._registerObject(b(s)),s._isModel=r.isModel,s._isModel&&s.scene._registerModel(b(s)),s.visible=r.visible,s.culled=r.culled,s.pickable=r.pickable,s.clippable=r.clippable,s.collidable=r.collidable,s.castsShadow=r.castsShadow,s.receivesShadow=r.receivesShadow,s.xrayed=r.xrayed,s.highlighted=r.highlighted,s.selected=r.selected,s.edges=r.edges,s.layer=r.layer,s.colorize=r.colorize,s.opacity=r.opacity,s.offset=r.offset,r.parentId){var o=s.scene.components[r.parentId];o?o.isNode?o.addChild(b(s)):s.error("Parent is not a Node: '"+r.parentId+"'"):s.error("Parent not found: '"+r.parentId+"'"),s._parentNode=o}else r.parent&&(r.parent.isNode||s.error("Parent is not a Node"),r.parent.addChild(b(s)),s._parentNode=r.parent);return s.compile(),s}return C(i,[{key:"type",get:function(){return"Mesh"}},{key:"isMesh",get:function(){return!0}},{key:"parent",get:function(){return this._parentNode}},{key:"geometry",get:function(){return this._geometry}},{key:"material",get:function(){return this._material}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),$.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),$.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"matrix",get:function(){return this._localMatrixDirty&&(this.__localMatrix||(this.__localMatrix=$.identityMat4()),$.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix},set:function(e){this.__localMatrix||(this.__localMatrix=$.identityMat4()),this.__localMatrix.set(e||sn),$.decomposeMat4(this.__localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrixDirty&&this._buildWorldNormalMatrix(),this._worldNormalMatrix}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return this._isObject}},{key:"aabb",get:function(){return this._aabbDirty&&this._updateAABB(),this._aabb}},{key:"origin",get:function(){return this._state.origin},set:function(e){e?(this._state.origin||(this._state.origin=$.vec3()),this._state.origin.set(e),this._state.originHash=e.join(),this._setAABBDirty(),this.scene._aabbDirty=!0):this._state.origin&&(this._state.origin=null,this._state.originHash=null,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"rtcCenter",get:function(){return this.origin},set:function(e){this.origin=e}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"visible",get:function(){return this._state.visible},set:function(e){e=!1!==e,this._state.visible=e,this._isObject&&this.scene._objectVisibilityUpdated(this,e),this.glRedraw()}},{key:"xrayed",get:function(){return this._state.xrayed},set:function(e){e=!!e,this._state.xrayed!==e&&(this._state.xrayed=e,this._isObject&&this.scene._objectXRayedUpdated(this,e),this.glRedraw())}},{key:"highlighted",get:function(){return this._state.highlighted},set:function(e){(e=!!e)!==this._state.highlighted&&(this._state.highlighted=e,this._isObject&&this.scene._objectHighlightedUpdated(this,e),this.glRedraw())}},{key:"selected",get:function(){return this._state.selected},set:function(e){(e=!!e)!==this._state.selected&&(this._state.selected=e,this._isObject&&this.scene._objectSelectedUpdated(this,e),this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){(e=!!e)!==this._state.edges&&(this._state.edges=e,this.glRedraw())}},{key:"culled",get:function(){return this._state.culled},set:function(e){this._state.culled=!!e,this.glRedraw()}},{key:"clippable",get:function(){return this._state.clippable},set:function(e){e=!1!==e,this._state.clippable!==e&&(this._state.clippable=e,this.glRedraw())}},{key:"collidable",get:function(){return this._state.collidable},set:function(e){(e=!1!==e)!==this._state.collidable&&(this._state.collidable=e,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"pickable",get:function(){return this._state.pickable},set:function(e){e=!1!==e,this._state.pickable!==e&&(this._state.pickable=e)}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){(e=!1!==e)!==this._state.castsShadow&&(this._state.castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._state.receivesShadow},set:function(e){(e=!1!==e)!==this._state.receivesShadow&&(this._state.receivesShadow=e,this._state.hash=e?"/mod/rs;":"/mod;",this.fire("dirty",this))}},{key:"saoEnabled",get:function(){return!1}},{key:"colorize",get:function(){return this._state.colorize},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);var i=!!e;this.scene._objectColorizeUpdated(this,i),this.glRedraw()}},{key:"opacity",get:function(){return this._state.colorize[3]},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[0]=1,t[1]=1,t[2]=1);var i=null!=e;t[3]=i?e:1,this.scene._objectOpacityUpdated(this,i),this.glRedraw()}},{key:"transparent",get:function(){return 2===this._material.alphaMode||this._state.colorize[3]<1}},{key:"layer",get:function(){return this._state.layer},set:function(e){e=e||0,(e=Math.round(e))!==this._state.layer&&(this._state.layer=e,this._renderer.needStateSort())}},{key:"stationary",get:function(){return this._state.stationary}},{key:"billboard",get:function(){return this._state.billboard}},{key:"offset",get:function(){return this._state.offset},set:function(e){this._state.offset.set(e||[0,0,0]),this._setAABBDirty(),this.glRedraw()}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!0}},{key:"xrayMaterial",get:function(){return this._xrayMaterial}},{key:"highlightMaterial",get:function(){return this._highlightMaterial}},{key:"selectedMaterial",get:function(){return this._selectedMaterial}},{key:"edgeMaterial",get:function(){return this._edgeMaterial}},{key:"_checkBillboard",value:function(e){return"spherical"!==(e=e||"none")&&"cylindrical"!==e&&"none"!==e&&(this.error("Unsupported value for 'billboard': "+e+" - accepted values are 'spherical', 'cylindrical' and 'none' - defaulting to 'none'."),e="none"),e}},{key:"compile",value:function(){var e=this._makeDrawHash();this._state.drawHash!==e&&(this._state.drawHash=e,this._putDrawRenderers(),this._drawRenderer=_r.get(this),this._emphasisFillRenderer=xr.get(this),this._emphasisEdgesRenderer=Er.get(this));var t=this._makePickHash();if(this._state.pickHash!==t&&(this._state.pickHash=t,this._putPickRenderers(),this._pickMeshRenderer=Sr.get(this)),this._state.occluder){var i=this._makeOcclusionHash();this._state.occlusionHash!==i&&(this._state.occlusionHash=i,this._putOcclusionRenderer(),this._occlusionRenderer=Vr.get(this))}}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}},{key:"_setWorldMatrixDirty",value:function(){this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentNode)$.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(var t=0,i=e.length;t0)for(var i=0;i-1){var R=k.geometry._state,L=k.scene,U=L.camera,O=L.canvas;if("triangles"===R.primitiveName){S.primitive="triangle";var N,Q,V,H=T,j=R.indices,G=R.positions;if(j){var z=j[H+0],W=j[H+1],K=j[H+2];n[0]=z,n[1]=W,n[2]=K,S.indices=n,N=3*z,Q=3*W,V=3*K}else V=(Q=(N=3*H)+3)+3;if(i[0]=G[N+0],i[1]=G[N+1],i[2]=G[N+2],s[0]=G[Q+0],s[1]=G[Q+1],s[2]=G[Q+2],r[0]=G[V+0],r[1]=G[V+1],r[2]=G[V+2],R.compressGeometry){var X=R.positionsDecodeMatrix;X&&(ki.decompressPosition(i,X,i),ki.decompressPosition(s,X,s),ki.decompressPosition(r,X,r))}S.canvasPos?$.canvasPosToLocalRay(O.canvas,k.origin?Re(I,k.origin):I,D,k.worldMatrix,S.canvasPos,e,t):S.origin&&S.direction&&$.worldRayToLocalRay(k.worldMatrix,S.origin,S.direction,e,t),$.normalizeVec3(t),$.rayPlaneIntersect(e,t,i,s,r,o),S.localPos=o,S.position=o,v[0]=o[0],v[1]=o[1],v[2]=o[2],v[3]=1,$.transformVec4(k.worldMatrix,v,g),a[0]=g[0],a[1]=g[1],a[2]=g[2],S.canvasPos&&k.origin&&(a[0]+=k.origin[0],a[1]+=k.origin[1],a[2]+=k.origin[2]),S.worldPos=a,$.transformVec4(U.matrix,g,m),l[0]=m[0],l[1]=m[1],l[2]=m[2],S.viewPos=l,$.cartesianToBarycentric(o,i,s,r,u),S.bary=u;var J=R.normals;if(J){if(R.compressGeometry){var Y=3*z,Z=3*W,q=3*K;ki.decompressNormal(J.subarray(Y,Y+2),A),ki.decompressNormal(J.subarray(Z,Z+2),c),ki.decompressNormal(J.subarray(q,q+2),h)}else A[0]=J[N],A[1]=J[N+1],A[2]=J[N+2],c[0]=J[Q],c[1]=J[Q+1],c[2]=J[Q+2],h[0]=J[V],h[1]=J[V+1],h[2]=J[V+2];var ee=$.addVec3($.addVec3($.mulVec3Scalar(A,u[0],_),$.mulVec3Scalar(c,u[1],y),b),$.mulVec3Scalar(h,u[2],w),B);S.worldNormal=$.normalizeVec3($.transformVec3(k.worldNormalMatrix,ee,x))}var te=R.uv;if(te){if(d[0]=te[2*z],d[1]=te[2*z+1],p[0]=te[2*W],p[1]=te[2*W+1],f[0]=te[2*K],f[1]=te[2*K+1],R.compressGeometry){var ie=R.uvDecodeMatrix;ie&&(ki.decompressUV(d,ie,d),ki.decompressUV(p,ie,p),ki.decompressUV(f,ie,f))}S.uv=$.addVec3($.addVec3($.mulVec2Scalar(d,u[0],P),$.mulVec2Scalar(p,u[1],C),M),$.mulVec2Scalar(f,u[2],F),E)}}}}}();function on(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);var i=e.radiusBottom||1;i<0&&(console.error("negative radiusBottom not allowed - will invert"),i*=-1);var s=e.height||1;s<0&&(console.error("negative height not allowed - will invert"),s*=-1);var r=e.radialSegments||32;r<0&&(console.error("negative radialSegments not allowed - will invert"),r*=-1),r<3&&(r=3);var n=e.heightSegments||1;n<0&&(console.error("negative heightSegments not allowed - will invert"),n*=-1),n<1&&(n=1);var o,a,l,u,A,c,h,d,p,f,v,g=!!e.openEnded,m=e.center,_=m?m[0]:0,y=m?m[1]:0,b=m?m[2]:0,w=s/2,B=s/n,x=2*Math.PI/r,P=1/r,C=(t-i)/n,M=[],F=[],E=[],k=[],I=(90-180*Math.atan(s/(i-t))/Math.PI)/90;for(o=0;o<=n;o++)for(A=t-o*C,c=w-o*B,a=0;a<=r;a++)l=Math.sin(a*x),u=Math.cos(a*x),F.push(A*l),F.push(I),F.push(A*u),E.push(a*P),E.push(1*o/n),M.push(A*l+_),M.push(c+y),M.push(A*u+b);for(o=0;o0){for(p=M.length/3,F.push(0),F.push(1),F.push(0),E.push(.5),E.push(.5),M.push(0+_),M.push(w+y),M.push(0+b),a=0;a<=r;a++)l=Math.sin(a*x),u=Math.cos(a*x),f=.5*Math.sin(a*x)+.5,v=.5*Math.cos(a*x)+.5,F.push(t*l),F.push(1),F.push(t*u),E.push(f),E.push(v),M.push(t*l+_),M.push(w+y),M.push(t*u+b);for(a=0;a0){for(p=M.length/3,F.push(0),F.push(-1),F.push(0),E.push(.5),E.push(.5),M.push(0+_),M.push(0-w+y),M.push(0+b),a=0;a<=r;a++)l=Math.sin(a*x),u=Math.cos(a*x),f=.5*Math.sin(a*x)+.5,v=.5*Math.cos(a*x)+.5,F.push(i*l),F.push(-1),F.push(i*u),E.push(f),E.push(v),M.push(i*l+_),M.push(0-w+y),M.push(i*u+b);for(a=0;a0&&void 0!==arguments[0]?arguments[0]:{},t=e.lod||1,i=e.center?e.center[0]:0,s=e.center?e.center[1]:0,r=e.center?e.center[2]:0,n=e.radius||1;n<0&&(console.error("negative radius not allowed - will invert"),n*=-1);var o=e.heightSegments||18;o<0&&(console.error("negative heightSegments not allowed - will invert"),o*=-1),(o=Math.floor(t*o))<18&&(o=18);var a=e.widthSegments||18;a<0&&(console.error("negative widthSegments not allowed - will invert"),a*=-1),(a=Math.floor(t*a))<18&&(a=18);var l,u,A,c,h,d,p,f,v,g,m,_,y,b,w=[],B=[],x=[],P=[];for(l=0;l<=o;l++)for(A=l*Math.PI/o,c=Math.sin(A),h=Math.cos(A),u=0;u<=a;u++)d=2*u*Math.PI/a,p=Math.sin(d),f=Math.cos(d)*c,v=h,g=p*c,m=1-u/a,_=l/o,B.push(f),B.push(v),B.push(g),x.push(m),x.push(_),w.push(i+n*f),w.push(s+n*v),w.push(r+n*g);for(l=0;l":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function un(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.origin||[0,0,0],i=t[0],s=t[1],r=t[2],n=e.size||1,o=[],a=[],l=e.text;le.isNumeric(l)&&(l=""+l);for(var u,A,c,h,d,p,f,v,g,m=(l||"").split("\n"),_=0,y=0,b=.04,w=0;w1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({active:!0,pos:$.vec3(),dir:$.vec3(),dist:0}),s.active=r.active,s.pos=r.pos,s.dir=r.dir,s.scene._sectionPlaneCreated(b(s)),s}return C(i,[{key:"type",get:function(){return"SectionPlane"}},{key:"active",get:function(){return this._state.active},set:function(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active)}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-$.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos),this.scene.fire("sectionPlaneUpdated",this)}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||[0,0,-1]),this._state.dist=-$.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir),this.scene.fire("sectionPlaneUpdated",this)}},{key:"dist",get:function(){return this._state.dist}},{key:"flipDir",value:function(){var e=this._state.dir;e[0]*=-1,e[1]*=-1,e[2]*=-1,this._state.dist=-$.dotVec3(this._state.pos,this._state.dir),this.fire("dir",this._state.dir),this.glRedraw()}},{key:"destroy",value:function(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),f(w(i.prototype),"destroy",this).call(this)}}]),i}(),hn=$.vec4(4),dn=$.vec4(),pn=$.vec4(),fn=$.vec3([1,0,0]),vn=$.vec3([0,1,0]),gn=$.vec3([0,0,1]),mn=$.vec3(3),_n=$.vec3(3),yn=$.identityMat4(),bn=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,e,r))._parentNode=null,s._children=[],s._aabb=null,s._aabbDirty=!0,s.scene._aabbDirty=!0,s._numTriangles=0,s._scale=$.vec3(),s._quaternion=$.identityQuaternion(),s._rotation=$.vec3(),s._position=$.vec3(),s._offset=$.vec3(),s._localMatrix=$.identityMat4(),s._worldMatrix=$.identityMat4(),s._localMatrixDirty=!0,s._worldMatrixDirty=!0,r.matrix?s.matrix=r.matrix:(s.scale=r.scale,s.position=r.position,r.quaternion||(s.rotation=r.rotation)),s._isModel=r.isModel,s._isModel&&s.scene._registerModel(b(s)),s._isObject=r.isObject,s._isObject&&s.scene._registerObject(b(s)),s.origin=r.origin,s.visible=r.visible,s.culled=r.culled,s.pickable=r.pickable,s.clippable=r.clippable,s.collidable=r.collidable,s.castsShadow=r.castsShadow,s.receivesShadow=r.receivesShadow,s.xrayed=r.xrayed,s.highlighted=r.highlighted,s.selected=r.selected,s.edges=r.edges,s.colorize=r.colorize,s.opacity=r.opacity,s.offset=r.offset,r.children)for(var n=r.children,o=0,a=n.length;o1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"LambertMaterial",ambient:$.vec3([1,1,1]),color:$.vec3([1,1,1]),emissive:$.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),s.ambient=r.ambient,s.color=r.color,s.emissive=r.emissive,s.alpha=r.alpha,s.lineWidth=r.lineWidth,s.pointSize=r.pointSize,s.backfaces=r.backfaces,s.frontface=r.frontface,s}return C(i,[{key:"type",get:function(){return"LambertMaterial"}},{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:"color",get:function(){return this._state.color},set:function(e){var t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=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._state.alphaMode=e<1?2:0,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:"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:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),Bn={opaque:0,mask:1,blend:2},xn=["opaque","mask","blend"],Pn=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"MetallicMaterial",baseColor:$.vec4([1,1,1]),emissive:$.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),s.baseColor=r.baseColor,s.metallic=r.metallic,s.roughness=r.roughness,s.specularF0=r.specularF0,s.emissive=r.emissive,s.alpha=r.alpha,r.baseColorMap&&(s._baseColorMap=s._checkComponent("Texture",r.baseColorMap)),r.metallicMap&&(s._metallicMap=s._checkComponent("Texture",r.metallicMap)),r.roughnessMap&&(s._roughnessMap=s._checkComponent("Texture",r.roughnessMap)),r.metallicRoughnessMap&&(s._metallicRoughnessMap=s._checkComponent("Texture",r.metallicRoughnessMap)),r.emissiveMap&&(s._emissiveMap=s._checkComponent("Texture",r.emissiveMap)),r.occlusionMap&&(s._occlusionMap=s._checkComponent("Texture",r.occlusionMap)),r.alphaMap&&(s._alphaMap=s._checkComponent("Texture",r.alphaMap)),r.normalMap&&(s._normalMap=s._checkComponent("Texture",r.normalMap)),s.alphaMode=r.alphaMode,s.alphaCutoff=r.alphaCutoff,s.backfaces=r.backfaces,s.frontface=r.frontface,s.lineWidth=r.lineWidth,s.pointSize=r.pointSize,s._makeHash(),s}return C(i,[{key:"type",get:function(){return"MetallicMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"baseColor",get:function(){return this._state.baseColor},set:function(e){var t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=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:"baseColorMap",get:function(){return this._baseColorMap}},{key:"metallic",get:function(){return this._state.metallic},set:function(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}},{key:"metallicMap",get:function(){return this._attached.metallicMap}},{key:"roughness",get:function(){return this._state.roughness},set:function(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}},{key:"roughnessMap",get:function(){return this._attached.roughnessMap}},{key:"metallicRoughnessMap",get:function(){return this._attached.metallicRoughnessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,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:"emissiveMap",get:function(){return this._attached.emissiveMap}},{key:"occlusionMap",get:function(){return this._attached.occlusionMap}},{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:"alphaMap",get:function(){return this._attached.alphaMap}},{key:"normalMap",get:function(){return this._attached.normalMap}},{key:"alphaMode",get:function(){return xn[this._state.alphaMode]},set:function(e){var t=Bn[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:"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:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),Cn={opaque:0,mask:1,blend:2},Mn=["opaque","mask","blend"],Fn=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"SpecularMaterial",diffuse:$.vec3([1,1,1]),emissive:$.vec3([0,0,0]),specular:$.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),s.diffuse=r.diffuse,s.specular=r.specular,s.glossiness=r.glossiness,s.specularF0=r.specularF0,s.emissive=r.emissive,s.alpha=r.alpha,r.diffuseMap&&(s._diffuseMap=s._checkComponent("Texture",r.diffuseMap)),r.emissiveMap&&(s._emissiveMap=s._checkComponent("Texture",r.emissiveMap)),r.specularMap&&(s._specularMap=s._checkComponent("Texture",r.specularMap)),r.glossinessMap&&(s._glossinessMap=s._checkComponent("Texture",r.glossinessMap)),r.specularGlossinessMap&&(s._specularGlossinessMap=s._checkComponent("Texture",r.specularGlossinessMap)),r.occlusionMap&&(s._occlusionMap=s._checkComponent("Texture",r.occlusionMap)),r.alphaMap&&(s._alphaMap=s._checkComponent("Texture",r.alphaMap)),r.normalMap&&(s._normalMap=s._checkComponent("Texture",r.normalMap)),s.alphaMode=r.alphaMode,s.alphaCutoff=r.alphaCutoff,s.backfaces=r.backfaces,s.frontface=r.frontface,s.lineWidth=r.lineWidth,s.pointSize=r.pointSize,s._makeHash(),s}return C(i,[{key:"type",get:function(){return"SpecularMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{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:"diffuseMap",get:function(){return this._diffuseMap}},{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:"specularMap",get:function(){return this._specularMap}},{key:"specularGlossinessMap",get:function(){return this._specularGlossinessMap}},{key:"glossiness",get:function(){return this._state.glossiness},set:function(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}},{key:"glossinessMap",get:function(){return this._glossinessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,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:"emissiveMap",get:function(){return this._emissiveMap}},{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:"alphaMap",get:function(){return this._alphaMap}},{key:"normalMap",get:function(){return this._normalMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"alphaMode",get:function(){return Mn[this._state.alphaMode]},set:function(e){var t=Cn[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:"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:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}();function En(e,t){var i,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=t;if(1009===r)return e.UNSIGNED_BYTE;if(1017===r)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===r)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===r)return e.BYTE;if(1011===r)return e.SHORT;if(1012===r)return e.UNSIGNED_SHORT;if(1013===r)return e.INT;if(1014===r)return e.UNSIGNED_INT;if(1015===r)return e.FLOAT;if(1016===r)return e.HALF_FLOAT;if(1021===r)return e.ALPHA;if(1023===r)return e.RGBA;if(1024===r)return e.LUMINANCE;if(1025===r)return e.LUMINANCE_ALPHA;if(1026===r)return e.DEPTH_COMPONENT;if(1027===r)return e.DEPTH_STENCIL;if(1028===r)return e.RED;if(1022===r)return e.RGBA;if(1029===r)return e.RED_INTEGER;if(1030===r)return e.RG;if(1031===r)return e.RG_INTEGER;if(1033===r)return e.RGBA_INTEGER;if(33776===r||33777===r||33778===r||33779===r)if(3001===s){var n=Kt(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===n)return null;if(33776===r)return n.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===r)return n.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===r)return n.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===r)return n.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(null===(i=Kt(e,"WEBGL_compressed_texture_s3tc")))return null;if(33776===r)return i.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===r)return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===r)return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===r)return i.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===r||35841===r||35842===r||35843===r){var o=Kt(e,"WEBGL_compressed_texture_pvrtc");if(null===o)return null;if(35840===r)return o.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===r)return o.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===r)return o.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===r)return o.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===r){var a=Kt(e,"WEBGL_compressed_texture_etc1");return null!==a?a.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===r||37496===r){var l=Kt(e,"WEBGL_compressed_texture_etc");if(null===l)return null;if(37492===r)return 3001===s?l.COMPRESSED_SRGB8_ETC2:l.COMPRESSED_RGB8_ETC2;if(37496===r)return 3001===s?l.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:l.COMPRESSED_RGBA8_ETC2_EAC}if(37808===r||37809===r||37810===r||37811===r||37812===r||37813===r||37814===r||37815===r||37816===r||37817===r||37818===r||37819===r||37820===r||37821===r){var u=Kt(e,"WEBGL_compressed_texture_astc");if(null===u)return null;if(37808===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:u.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:u.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:u.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:u.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:u.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:u.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:u.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:u.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:u.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:u.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:u.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:u.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:u.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:u.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===r){var A=Kt(e,"EXT_texture_compression_bptc");if(null===A)return null;if(36492===r)return 3001===s?A.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:A.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===r?e.UNSIGNED_INT_24_8:1e3===r?e.REPEAT:1001===r?e.CLAMP_TO_EDGE:1004===r||1005===r?e.NEAREST_MIPMAP_LINEAR:1007===r?e.LINEAR_MIPMAP_NEAREST:1008===r?e.LINEAR_MIPMAP_LINEAR:1003===r?e.NEAREST:1006===r?e.LINEAR:null}var kn=new Uint8Array([0,0,0,1]),In=function(){function e(t){var i=t.gl,s=t.target,r=t.format,n=t.type,o=t.wrapS,a=t.wrapT,l=t.wrapR,u=t.encoding,A=t.preloadColor,c=t.premultiplyAlpha,h=t.flipY;x(this,e),this.gl=i,this.target=s||i.TEXTURE_2D,this.format=r||1023,this.type=n||1009,this.internalFormat=null,this.premultiplyAlpha=!!c,this.flipY=!!h,this.unpackAlignment=4,this.wrapS=o||1e3,this.wrapT=a||1e3,this.wrapR=l||1e3,this.encoding=u||3001,this.texture=i.createTexture(),A&&this.setPreloadColor(A),this.allocated=!0}return C(e,[{key:"setPreloadColor",value:function(e){e?(kn[0]=Math.floor(255*e[0]),kn[1]=Math.floor(255*e[1]),kn[2]=Math.floor(255*e[2]),kn[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(kn[0]=0,kn[1]=0,kn[2]=0,kn[3]=255);var t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP)for(var i=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z],s=0,r=i.length;s1&&void 0!==arguments[1]?arguments[1]:{},i=this.gl;void 0!==t.format&&(this.format=t.format),void 0!==t.internalFormat&&(this.internalFormat=t.internalFormat),void 0!==t.encoding&&(this.encoding=t.encoding),void 0!==t.type&&(this.type=t.type),void 0!==t.flipY&&(this.flipY=t.flipY),void 0!==t.premultiplyAlpha&&(this.premultiplyAlpha=t.premultiplyAlpha),void 0!==t.unpackAlignment&&(this.unpackAlignment=t.unpackAlignment),void 0!==t.minFilter&&(this.minFilter=t.minFilter),void 0!==t.magFilter&&(this.magFilter=t.magFilter),void 0!==t.wrapS&&(this.wrapS=t.wrapS),void 0!==t.wrapT&&(this.wrapT=t.wrapT),void 0!==t.wrapR&&(this.wrapR=t.wrapR);var s=!1;i.bindTexture(this.target,this.texture);var r=i.getParameter(i.UNPACK_FLIP_Y_WEBGL);i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,this.flipY);var n=i.getParameter(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL);i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha);var o=i.getParameter(i.UNPACK_ALIGNMENT);i.pixelStorei(i.UNPACK_ALIGNMENT,this.unpackAlignment);var a=i.getParameter(i.UNPACK_COLORSPACE_CONVERSION_WEBGL);i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.NONE);var l=En(i,this.minFilter);i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,l),l!==i.NEAREST_MIPMAP_NEAREST&&l!==i.LINEAR_MIPMAP_NEAREST&&l!==i.NEAREST_MIPMAP_LINEAR&&l!==i.LINEAR_MIPMAP_LINEAR||(s=!0);var u=En(i,this.magFilter);u&&i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,u);var A=En(i,this.wrapS);A&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,A);var c=En(i,this.wrapT);c&&i.texParameteri(this.target,i.TEXTURE_WRAP_T,c);var h=En(i,this.format,this.encoding),d=En(i,this.type),p=Dn(i,this.internalFormat,h,d,this.encoding,!1);if(this.target===i.TEXTURE_CUBE_MAP){if(le.isArray(e))for(var f=e,v=[i.TEXTURE_CUBE_MAP_POSITIVE_X,i.TEXTURE_CUBE_MAP_NEGATIVE_X,i.TEXTURE_CUBE_MAP_POSITIVE_Y,i.TEXTURE_CUBE_MAP_NEGATIVE_Y,i.TEXTURE_CUBE_MAP_POSITIVE_Z,i.TEXTURE_CUBE_MAP_NEGATIVE_Z],g=0,m=v.length;g1;r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,this.flipY),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),r.pixelStorei(r.UNPACK_ALIGNMENT,this.unpackAlignment),r.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,r.NONE);var a=En(r,this.wrapS);a&&r.texParameteri(this.target,r.TEXTURE_WRAP_S,a);var l=En(r,this.wrapT);if(l&&r.texParameteri(this.target,r.TEXTURE_WRAP_T,l),this.type===r.TEXTURE_3D||this.type===r.TEXTURE_2D_ARRAY){var u=En(r,this.wrapR);u&&r.texParameteri(this.target,r.TEXTURE_WRAP_R,u),r.texParameteri(this.type,r.TEXTURE_WRAP_R,u)}o?(r.texParameteri(this.target,r.TEXTURE_MIN_FILTER,Sn(r,this.minFilter)),r.texParameteri(this.target,r.TEXTURE_MAG_FILTER,Sn(r,this.magFilter))):(r.texParameteri(this.target,r.TEXTURE_MIN_FILTER,En(r,this.minFilter)),r.texParameteri(this.target,r.TEXTURE_MAG_FILTER,En(r,this.magFilter)));var A=En(r,this.format,this.encoding),c=En(r,this.type),h=Dn(r,this.internalFormat,A,c,this.encoding,!1);r.texStorage2D(r.TEXTURE_2D,n,h,t[0].width,t[0].height);for(var d=0,p=t.length;d5&&void 0!==arguments[5]&&arguments[5];if(null!==t){if(void 0!==e[t])return e[t];console.warn("Attempt to use non-existing WebGL internal format '"+t+"'")}var o=i;return i===e.RED&&(s===e.FLOAT&&(o=e.R32F),s===e.HALF_FLOAT&&(o=e.R16F),s===e.UNSIGNED_BYTE&&(o=e.R8)),i===e.RG&&(s===e.FLOAT&&(o=e.RG32F),s===e.HALF_FLOAT&&(o=e.RG16F),s===e.UNSIGNED_BYTE&&(o=e.RG8)),i===e.RGBA&&(s===e.FLOAT&&(o=e.RGBA32F),s===e.HALF_FLOAT&&(o=e.RGBA16F),s===e.UNSIGNED_BYTE&&(o=3001===r&&!1===n?e.SRGB8_ALPHA8:e.RGBA8),s===e.UNSIGNED_SHORT_4_4_4_4&&(o=e.RGBA4),s===e.UNSIGNED_SHORT_5_5_5_1&&(o=e.RGB5_A1)),o!==e.R16F&&o!==e.R32F&&o!==e.RG16F&&o!==e.RG32F&&o!==e.RGBA16F&&o!==e.RGBA32F||Kt(e,"EXT_color_buffer_float"),o}function Sn(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function Tn(e){if(!Rn(e.width)||!Rn(e.height)){var t=document.createElement("canvas");t.width=Ln(e.width),t.height=Ln(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Rn(e){return 0==(e&e-1)}function Ln(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var Un=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({texture:new In({gl:s.scene.canvas.gl}),matrix:$.identityMat4(),hasMatrix:r.translate&&(0!==r.translate[0]||0!==r.translate[1])||!!r.rotate||r.scale&&(0!==r.scale[0]||0!==r.scale[1]),minFilter:s._checkMinFilter(r.minFilter),magFilter:s._checkMagFilter(r.magFilter),wrapS:s._checkWrapS(r.wrapS),wrapT:s._checkWrapT(r.wrapT),flipY:s._checkFlipY(r.flipY),encoding:s._checkEncoding(r.encoding)}),s._src=null,s._image=null,s._translate=$.vec2([0,0]),s._scale=$.vec2([1,1]),s._rotate=$.vec2([0,0]),s._matrixDirty=!1,s.translate=r.translate,s.scale=r.scale,s.rotate=r.rotate,r.src?s.src=r.src:r.image&&(s.image=r.image),se.memory.textures++,s}return C(i,[{key:"type",get:function(){return"Texture"}},{key:"_checkMinFilter",value:function(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}},{key:"_checkMagFilter",value:function(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}},{key:"_checkWrapS",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkWrapT",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this._state.texture=new In({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}},{key:"_update",value:function(){var e,t,i=this._state;this._matrixDirty&&(0===this._translate[0]&&0===this._translate[1]||(e=$.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(t=$.scalingMat4v([this._scale[0],this._scale[1],1]),e=e?$.mulMat4(e,t):t),0!==this._rotate&&(t=$.rotationMat4v(.0174532925*this._rotate,[0,0,1]),e=e?$.mulMat4(e,t):t),e&&(i.matrix=e),this._matrixDirty=!1);this.glRedraw()}},{key:"image",get:function(){return this._image},set:function(e){this._image=Tn(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}},{key:"src",get:function(){return this._src},set:function(e){this.scene.loading++,this.scene.canvas.spinner.processes++;var t=this,i=new Image;i.onload=function(){i=Tn(i),t._state.texture.setImage(i,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},i.src=e,this._src=e,this._image=null}},{key:"translate",get:function(){return this._translate},set:function(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}},{key:"rotate",get:function(){return this._rotate},set:function(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}},{key:"minFilter",get:function(){return this._state.minFilter}},{key:"magFilter",get:function(){return this._state.magFilter}},{key:"wrapS",get:function(){return this._state.wrapS}},{key:"wrapT",get:function(){return this._state.wrapT}},{key:"flipY",get:function(){return this._state.flipY}},{key:"encoding",get:function(){return this._state.encoding}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),se.memory.textures--}}]),i}(),On=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({edgeColor:$.vec3([0,0,0]),centerColor:$.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),s.edgeColor=r.edgeColor,s.centerColor=r.centerColor,s.edgeBias=r.edgeBias,s.centerBias=r.centerBias,s.power=r.power,s}return C(i,[{key:"type",get:function(){return"Fresnel"}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}},{key:"centerColor",get:function(){return this._state.centerColor},set:function(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}},{key:"edgeBias",get:function(){return this._state.edgeBias},set:function(e){this._state.edgeBias=e||0,this.glRedraw()}},{key:"centerBias",get:function(){return this._state.centerBias},set:function(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}},{key:"power",get:function(){return this._state.power},set:function(e){this._state.power=null!=e?e:1,this.glRedraw()}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),Nn=se.memory,Qn=$.AABB3(),Vn=function(e){g(i,wi);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e,r))._state=new Zt({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),s._numTriangles=0,s._edgeThreshold=r.edgeThreshold||10,s._aabb=null,s._obb=$.OBB3();var n,o=s._state,a=s.scene.canvas.gl;switch(r.primitive=r.primitive||"triangles",r.primitive){case"points":o.primitive=a.POINTS,o.primitiveName=r.primitive;break;case"lines":o.primitive=a.LINES,o.primitiveName=r.primitive;break;case"line-loop":o.primitive=a.LINE_LOOP,o.primitiveName=r.primitive;break;case"line-strip":o.primitive=a.LINE_STRIP,o.primitiveName=r.primitive;break;case"triangles":o.primitive=a.TRIANGLES,o.primitiveName=r.primitive;break;case"triangle-strip":o.primitive=a.TRIANGLE_STRIP,o.primitiveName=r.primitive;break;case"triangle-fan":o.primitive=a.TRIANGLE_FAN,o.primitiveName=r.primitive;break;default:s.error("Unsupported value for 'primitive': '"+r.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),o.primitive=a.TRIANGLES,o.primitiveName=r.primitive}if(!r.positions)return s.error("Config expected: positions"),y(s);if(!r.indices)return s.error("Config expected: indices"),y(s);var l=r.positionsDecodeMatrix;if(l);else{var u=ki.getPositionsBounds(r.positions),A=ki.compressPositions(r.positions,u.min,u.max);n=A.quantized,o.positionsDecodeMatrix=A.decodeMatrix,o.positionsBuf=new It(a,a.ARRAY_BUFFER,n,n.length,3,a.STATIC_DRAW),Nn.positions+=o.positionsBuf.numItems,$.positions3ToAABB3(r.positions,s._aabb),$.positions3ToAABB3(n,Qn,o.positionsDecodeMatrix),$.AABB3ToOBB3(Qn,s._obb)}if(r.colors){var c=r.colors.constructor===Float32Array?r.colors:new Float32Array(r.colors);o.colorsBuf=new It(a,a.ARRAY_BUFFER,c,c.length,4,a.STATIC_DRAW),Nn.colors+=o.colorsBuf.numItems}if(r.uv){var h=ki.getUVBounds(r.uv),d=ki.compressUVs(r.uv,h.min,h.max),p=d.quantized;o.uvDecodeMatrix=d.decodeMatrix,o.uvBuf=new It(a,a.ARRAY_BUFFER,p,p.length,2,a.STATIC_DRAW),Nn.uvs+=o.uvBuf.numItems}if(r.normals){var f=ki.compressNormals(r.normals),v=o.compressGeometry;o.normalsBuf=new It(a,a.ARRAY_BUFFER,f,f.length,3,a.STATIC_DRAW,v),Nn.normals+=o.normalsBuf.numItems}var g=r.indices.constructor===Uint32Array||r.indices.constructor===Uint16Array?r.indices:new Uint32Array(r.indices);o.indicesBuf=new It(a,a.ELEMENT_ARRAY_BUFFER,g,g.length,1,a.STATIC_DRAW),Nn.indices+=o.indicesBuf.numItems;var m=Bi(n,g,o.positionsDecodeMatrix,s._edgeThreshold);return s._edgeIndicesBuf=new It(a,a.ELEMENT_ARRAY_BUFFER,m,m.length,1,a.STATIC_DRAW),"triangles"===s._state.primitiveName&&(s._numTriangles=r.indices.length/3),s._buildHash(),Nn.meshes++,s}return C(i,[{key:"type",get:function(){return"VBOGeometry"}},{key:"isVBOGeometry",get:function(){return!0}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"aabb",get:function(){return this._aabb}},{key:"obb",get:function(){return this._obb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){f(w(i.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(),e.destroy(),Nn.meshes--}}]),i}(),Hn={};function jn(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(i,s){t.src||(console.error("load3DSGeometry: Parameter expected: src"),s());var r=e.canvas.spinner;r.processes++,le.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),r.processes--,s());var n=Hn.parse.from3DS(e).edit.objects[0].mesh,o=n.vertices,a=n.uvt,l=n.indices;r.processes--,i(le.apply(t,{primitive:"triangles",positions:o,normals:null,uv:a,indices:l}))}),(function(e){console.error("load3DSGeometry: "+e),r.processes--,s()}))}))}function Gn(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(i,s){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),s());var r=e.canvas.spinner;r.processes++,le.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),r.processes--,s());for(var n=Hn.parse.fromOBJ(e),o=Hn.edit.unwrap(n.i_verts,n.c_verts,3),a=Hn.edit.unwrap(n.i_norms,n.c_norms,3),l=Hn.edit.unwrap(n.i_uvt,n.c_uvt,2),u=new Int32Array(n.i_verts.length),A=0;A0?a:null,autoNormals:0===a.length,uv:l,indices:u}))}),(function(e){console.error("loadOBJGeometry: "+e),r.processes--,s()}))}))}function zn(){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 i=e.ySize||1;i<0&&(console.error("negative ySize not allowed - will invert"),i*=-1);var s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);var r=e.center,n=r?r[0]:0,o=r?r[1]:0,a=r?r[2]:0,l=-t+n,u=-i+o,A=-s+a,c=t+n,h=i+o,d=s+a;return le.apply(e,{primitive:"lines",positions:[l,u,A,l,u,d,l,h,A,l,h,d,c,u,A,c,u,d,c,h,A,c,h,d],indices:[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,2,6,3,7]})}function Wn(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return zn({id:e.id,center:[(e.aabb[0]+e.aabb[3])/2,(e.aabb[1]+e.aabb[4])/2,(e.aabb[2]+e.aabb[5])/2],xSize:Math.abs(e.aabb[3]-e.aabb[0])/2,ySize:Math.abs(e.aabb[4]-e.aabb[1])/2,zSize:Math.abs(e.aabb[5]-e.aabb[2])/2})}function Kn(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);var i=e.divisions||1;i<0&&(console.error("negative divisions not allowed - will invert"),i*=-1),i<1&&(i=1);for(var s=(t=t||10)/(i=i||10),r=t/2,n=[],o=[],a=0,l=0,u=-r;l<=i;l++,u+=s)n.push(-r),n.push(0),n.push(u),n.push(r),n.push(0),n.push(u),n.push(u),n.push(0),n.push(-r),n.push(u),n.push(0),n.push(r),o.push(a++),o.push(a++),o.push(a++),o.push(a++);return le.apply(e,{primitive:"lines",positions:n,indices:o})}function Xn(){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 i=e.zSize||1;i<0&&(console.error("negative zSize not allowed - will invert"),i*=-1);var s=e.xSegments||1;s<0&&(console.error("negative xSegments not allowed - will invert"),s*=-1),s<1&&(s=1);var r=e.xSegments||1;r<0&&(console.error("negative zSegments not allowed - will invert"),r*=-1),r<1&&(r=1);var n,o,a,l,u,A,c,h=e.center,d=h?h[0]:0,p=h?h[1]:0,f=h?h[2]:0,v=t/2,g=i/2,m=Math.floor(s)||1,_=Math.floor(r)||1,y=m+1,b=_+1,w=t/m,B=i/_,x=new Float32Array(y*b*3),P=new Float32Array(y*b*3),C=new Float32Array(y*b*2),M=0,F=0;for(n=0;n65535?Uint32Array:Uint16Array)(m*_*6);for(n=0;n<_;n++)for(o=0;o0&&void 0!==arguments[0]?arguments[0]:{},t=e.radius||1;t<0&&(console.error("negative radius not allowed - will invert"),t*=-1),t*=.5;var i=e.tube||.3;i<0&&(console.error("negative tube not allowed - will invert"),i*=-1);var s=e.radialSegments||32;s<0&&(console.error("negative radialSegments not allowed - will invert"),s*=-1),s<4&&(s=4);var r=e.tubeSegments||24;r<0&&(console.error("negative tubeSegments not allowed - will invert"),r*=-1),r<4&&(r=4);var n=e.arc||2*Math.PI;n<0&&(console.warn("negative arc not allowed - will invert"),n*=-1),n>360&&(n=360);var o,a,l,u,A,c,h,d,p,f,v,g,m=e.center,_=m?m[0]:0,y=m?m[1]:0,b=m?m[2]:0,w=[],B=[],x=[],P=[];for(d=0;d<=r;d++)for(h=0;h<=s;h++)o=h/s*n,a=.785398+d/r*Math.PI*2,_=t*Math.cos(o),y=t*Math.sin(o),l=(t+i*Math.cos(a))*Math.cos(o),u=(t+i*Math.cos(a))*Math.sin(o),A=i*Math.sin(a),w.push(l+_),w.push(u+y),w.push(A+b),x.push(1-h/s),x.push(d/r),c=$.normalizeVec3($.subVec3([l,u,A],[_,y,b],[]),[]),B.push(c[0]),B.push(c[1]),B.push(c[2]);for(d=1;d<=r;d++)for(h=1;h<=s;h++)p=(s+1)*d+h-1,f=(s+1)*(d-1)+h-1,v=(s+1)*(d-1)+h,g=(s+1)*d+h,P.push(p),P.push(f),P.push(v),P.push(v),P.push(g),P.push(p);return le.apply(e,{positions:w,normals:B,uv:x,indices:P})}function Yn(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e.points.length%3!=0)throw"Size of points array for given polyline should be divisible by 3";var t=e.points.length/3;if(t<2)throw"There should be at least 2 points to create a polyline";for(var i=[],s=0;s0&&void 0!==arguments[0]?arguments[0]:{},t=e.curve.getPoints(e.divisions).map((function(e){return A(e)})).flat();return Yn({id:e.id,points:t})}Hn.load=function(e,t){var i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="arraybuffer",i.onload=function(e){t(e.target.response)},i.send()},Hn.save=function(e,t){var i="data:application/octet-stream;base64,"+btoa(Hn.parse._buffToStr(e));window.location.href=i},Hn.clone=function(e){return JSON.parse(JSON.stringify(e))},Hn.bin={},Hn.bin.f=new Float32Array(1),Hn.bin.fb=new Uint8Array(Hn.bin.f.buffer),Hn.bin.rf=function(e,t){for(var i=Hn.bin.f,s=Hn.bin.fb,r=0;r<4;r++)s[r]=e[t+r];return i[0]},Hn.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Hn.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Hn.bin.rASCII0=function(e,t){for(var i="";0!=e[t];)i+=String.fromCharCode(e[t++]);return i},Hn.bin.wf=function(e,t,i){new Float32Array(e.buffer,t,1)[0]=i},Hn.bin.wsl=function(e,t,i){e[t]=i,e[t+1]=i>>8},Hn.bin.wil=function(e,t,i){e[t]=i,e[t+1]=i>>8,e[t+2]=i>>16,e[t+3]},Hn.parse={},Hn.parse._buffToStr=function(e){for(var t=new Uint8Array(e),i="",s=0;sr&&(r=l),un&&(n=u),Ao&&(o=A)}return{min:{x:t,y:i,z:s},max:{x:r,y:n,z:o}}};var qn=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._type=r.type||(r.src?r.src.split(".").pop():null)||"jpg",s._pos=$.vec3(r.pos||[0,0,0]),s._up=$.vec3(r.up||[0,1,0]),s._normal=$.vec3(r.normal||[0,0,1]),s._height=r.height||1,s._origin=$.vec3(),s._rtcPos=$.vec3(),s._imageSize=$.vec2(),s._texture=new Un(b(s),{flipY:!0}),s._image=new Image,"jpg"!==s._type&&"png"!==s._type&&(s.error('Unsupported type - defaulting to "jpg"'),s._type="jpg"),s._node=new bn(b(s),{matrix:$.inverseMat4($.lookAtMat4v(s._pos,$.subVec3(s._pos,s._normal,$.mat4()),s._up,$.mat4())),children:[s._bitmapMesh=new rn(b(s),{scale:[1,1,1],rotation:[-90,0,0],collidable:r.collidable,pickable:r.pickable,opacity:r.opacity,clippable:r.clippable,geometry:new Si(b(s),Xn({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new Oi(b(s),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:s._texture,emissiveMap:s._texture,backfaces:!0})})]}),r.image?s.image=r.image:r.src?s.src=r.src:r.imageData&&(s.imageData=r.imageData),s.scene._bitmapCreated(b(s)),s}return C(i,[{key:"visible",get:function(){return this._bitmapMesh.visible},set:function(e){this._bitmapMesh.visible=e}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}},{key:"src",get:function(){return this._image.src},set:function(e){var t=this;if(e)switch(this._image.onload=function(){t._texture.image=t._image,t._imageSize[0]=t._image.width,t._imageSize[1]=t._image.height,t._updateBitmapMeshScale()},this._image.src=e,e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}},{key:"imageData",get:function(){var e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")},set:function(e){var t=this;this._image.onload=function(){t._texture.image=image,t._imageSize[0]=image.width,t._imageSize[1]=image.height,t._updateBitmapMeshScale()},this._image.src=e}},{key:"type",get:function(){return this._type},set:function(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}},{key:"pos",get:function(){return this._pos}},{key:"normal",get:function(){return this._normal}},{key:"up",get:function(){return this._up}},{key:"height",get:function(){return this._height},set:function(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}},{key:"collidable",get:function(){return this._bitmapMesh.collidable},set:function(e){this._bitmapMesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._bitmapMesh.clippable},set:function(e){this._bitmapMesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._bitmapMesh.pickable},set:function(e){this._bitmapMesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._bitmapMesh.opacity},set:function(e){this._bitmapMesh.opacity=e}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this.scene._bitmapDestroyed(this)}},{key:"_updateBitmapMeshScale",value:function(){var e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height/e,1,this._height]}}]),i}(),$n=$.OBB3(),eo=$.OBB3(),to=$.OBB3(),io=function(){function e(t,i,s,r,n,o){var a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null,l=arguments.length>7&&void 0!==arguments[7]?arguments[7]:0;x(this,e),this.model=t,this.object=null,this.parent=null,this.transform=n,this.textureSet=o,this._matrixDirty=!1,this._matrixUpdateScheduled=!1,this.id=i,this.obb=null,this._aabbLocal=null,this._aabbWorld=$.AABB3(),this._aabbWorldDirty=!1,this.layer=a,this.portionId=l,this._color=new Uint8Array([s[0],s[1],s[2],r]),this._colorize=new Uint8Array([s[0],s[1],s[2],r]),this._colorizing=!1,this._transparent=r<255,this.numTriangles=0,this.origin=null,this.entity=null,n&&n._addMesh(this)}return C(e,[{key:"_sceneModelDirty",value:function(){this._aabbWorldDirty=!0,this.layer.aabbDirty=!0}},{key:"_transformDirty",value:function(){this._matrixDirty||this._matrixUpdateScheduled||(this.model._meshMatrixDirty(this),this._matrixDirty=!0,this._matrixUpdateScheduled=!0),this._aabbWorldDirty=!0,this.layer.aabbDirty=!0,this.entity&&this.entity._transformDirty()}},{key:"_updateMatrix",value:function(){this.transform&&this._matrixDirty&&this.layer.setMatrix(this.portionId,this.transform.worldMatrix),this._matrixDirty=!1,this._matrixUpdateScheduled=!1}},{key:"_finalize",value:function(e){this.layer.initFlags(this.portionId,e,this._transparent)}},{key:"_finalize2",value:function(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}},{key:"_setVisible",value:function(e){this.layer.setVisible(this.portionId,e,this._transparent)}},{key:"_setColor",value:function(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}},{key:"_setColorize",value:function(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}},{key:"_setOpacity",value:function(e,t){var i=e<255,s=this._transparent!==i;this._color[3]=e,this._colorize[3]=e,this._transparent=i,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),s&&this.layer.setTransparent(this.portionId,t,i)}},{key:"_setOffset",value:function(e){this.layer.setOffset(this.portionId,e)}},{key:"_setHighlighted",value:function(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}},{key:"_setXRayed",value:function(e){this.layer.setXRayed(this.portionId,e,this._transparent)}},{key:"_setSelected",value:function(e){this.layer.setSelected(this.portionId,e,this._transparent)}},{key:"_setEdges",value:function(e){this.layer.setEdges(this.portionId,e,this._transparent)}},{key:"_setClippable",value:function(e){this.layer.setClippable(this.portionId,e,this._transparent)}},{key:"_setCollidable",value:function(e){this.layer.setCollidable(this.portionId,e)}},{key:"_setPickable",value:function(e){this.layer.setPickable(this.portionId,e,this._transparent)}},{key:"_setCulled",value:function(e){this.layer.setCulled(this.portionId,e,this._transparent)}},{key:"canPickTriangle",value:function(){return!1}},{key:"drawPickTriangles",value:function(e,t){}},{key:"pickTriangleSurface",value:function(e){}},{key:"precisionRayPickSurface",value:function(e,t,i,s){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,i,s)}},{key:"canPickWorldPos",value:function(){return!0}},{key:"drawPickDepths",value:function(e){this.model.drawPickDepths(e)}},{key:"drawPickNormals",value:function(e){this.model.drawPickNormals(e)}},{key:"delegatePickedEntity",value:function(){return this.parent}},{key:"getEachVertex",value:function(e){this.layer.getEachVertex(this.portionId,e)}},{key:"aabb",get:function(){if(this._aabbWorldDirty){if($.AABB3ToOBB3(this._aabbLocal,$n),this.transform?($.transformOBB3(this.transform.worldMatrix,$n,eo),$.transformOBB3(this.model.worldMatrix,eo,to),$.OBB3ToAABB3(to,this._aabbWorld)):($.transformOBB3(this.model.worldMatrix,$n,eo),$.OBB3ToAABB3(eo,this._aabbWorld)),this.origin){var e=this.origin;this._aabbWorld[0]+=e[0],this._aabbWorld[1]+=e[1],this._aabbWorld[2]+=e[2],this._aabbWorld[3]+=e[0],this._aabbWorld[4]+=e[1],this._aabbWorld[5]+=e[2]}this._aabbWorldDirty=!1}return this._aabbWorld},set:function(e){this._aabbLocal=e}},{key:"_destroy",value:function(){this.model.scene._renderer.putPickID(this.pickId)}}]),e}(),so=new(function(){function e(){x(this,e),this._uint8Arrays={},this._float32Arrays={}}return C(e,[{key:"_clear",value:function(){this._uint8Arrays={},this._float32Arrays={}}},{key:"getUInt8Array",value:function(e){var t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}},{key:"getFloat32Array",value:function(e){var t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}}]),e}()),ro=0;function no(){return ro++,so}var oo={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},ao=new Float32Array([1,1,1,1]),lo=new Float32Array([0,0,0,1]),uo=$.vec4(),Ao=$.vec3(),co=$.vec3(),ho=$.mat4(),po=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=s.instancing,n=void 0!==r&&r,o=s.edges,a=void 0!==o&&o;x(this,e),this._scene=t,this._withSAO=i,this._instancing=n,this._edges=a,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}return C(e,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){return[""]}},{key:"_buildFragmentShader",value:function(){return[""]}},{key:"_addMatricesUniformBlockLines",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}},{key:"_addRemapClipPosLines",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return e.push("uniform vec2 drawingBufferSize;"),e.push("uniform vec2 pickClipPos;"),e.push("vec4 remapClipPos(vec4 clipPos) {"),e.push(" clipPos.xy /= clipPos.w;"),1===t?e.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"):e.push(" clipPos.xy = (clipPos.xy - pickClipPos) * (drawingBufferSize / float(".concat(t,"));")),e.push(" clipPos.xy *= clipPos.w;"),e.push(" return clipPos;"),e.push("}"),e}},{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"setSectionPlanesStateUniforms",value:function(e){var t=this._scene,i=t.canvas.gl,s=e.model,r=e.layerIndex,n=t._sectionPlanesState.getNumAllocatedSectionPlanes(),o=t._sectionPlanesState.sectionPlanes.length;if(n>0){var a=t._sectionPlanesState.sectionPlanes,l=r*o,u=s.renderFlags;t.crossSections&&(i.uniform4fv(this._uSliceColor,t.crossSections.sliceColor),i.uniform1f(this._uSliceThickness,t.crossSections.sliceThickness));for(var A=0;A0&&(this._uReflectionMap="reflectionMap"),i.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(var a=0,l=e._sectionPlanesState.getNumAllocatedSectionPlanes();a3&&void 0!==arguments[3]?arguments[3]:{},r=s.colorUniform,n=void 0!==r&&r,o=s.incrementDrawState,a=void 0!==o&&o,l=yt.MAX_TEXTURE_IMAGE_UNITS,u=this._scene,A=u.canvas.gl,c=t._state,h=t.model,d=c.textureSet,p=c.origin,f=c.positionsDecodeMatrix,v=u._lightsState,g=u.pointsMaterial,m=h.scene.camera,_=m.viewNormalMatrix,y=m.project,b=e.pickViewMatrix||m.viewMatrix,w=h.position,B=h.rotationMatrix,x=h.rotationMatrixConjugate,P=h.worldNormalMatrix;if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),this._vaoCache.has(t)?A.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(c));var C=0,M=16;this._matricesUniformBlockBufferData.set(x,0);var F=0!==p[0]||0!==p[1]||0!==p[2],E=0!==w[0]||0!==w[1]||0!==w[2];if(F||E){var k=Ao;if(F){var I=$.transformPoint3(B,p,co);k[0]=I[0],k[1]=I[1],k[2]=I[2]}else k[0]=0,k[1]=0,k[2]=0;k[0]+=w[0],k[1]+=w[1],k[2]+=w[2],this._matricesUniformBlockBufferData.set(Re(b,k,ho),C+=M)}else this._matricesUniformBlockBufferData.set(b,C+=M);if(this._matricesUniformBlockBufferData.set(e.pickProjMatrix||y.matrix,C+=M),this._matricesUniformBlockBufferData.set(f,C+=M),this._matricesUniformBlockBufferData.set(P,C+=M),this._matricesUniformBlockBufferData.set(_,C+=M),A.bindBuffer(A.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),A.bufferData(A.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,A.DYNAMIC_DRAW),A.bindBufferBase(A.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer),A.uniform1i(this._uRenderPass,i),this.setSectionPlanesStateUniforms(t),u.logarithmicDepthBufferEnabled){if(this._uLogDepthBufFC){var D=2/(Math.log(e.pickZFar+1)/Math.LN2);A.uniform1f(this._uLogDepthBufFC,D)}this._uZFar&&A.uniform1f(this._uZFar,u.camera.project.far)}if(this._uPickInvisible&&A.uniform1i(this._uPickInvisible,e.pickInvisible),this._uPickZNear&&A.uniform1f(this._uPickZNear,e.pickZNear),this._uPickZFar&&A.uniform1f(this._uPickZFar,e.pickZFar),this._uPickClipPos&&A.uniform2fv(this._uPickClipPos,e.pickClipPos),this._uDrawingBufferSize&&A.uniform2f(this._uDrawingBufferSize,A.drawingBufferWidth,A.drawingBufferHeight),this._uUVDecodeMatrix&&A.uniformMatrix3fv(this._uUVDecodeMatrix,!1,c.uvDecodeMatrix),this._uIntensityRange&&g.filterIntensity&&A.uniform2f(this._uIntensityRange,g.minIntensity,g.maxIntensity),this._uPointSize&&A.uniform1f(this._uPointSize,g.pointSize),this._uNearPlaneHeight){var S="ortho"===u.camera.projection?1:A.drawingBufferHeight/(2*Math.tan(.5*u.camera.perspective.fov*Math.PI/180));A.uniform1f(this._uNearPlaneHeight,S)}if(d){var T=d.colorTexture,R=d.metallicRoughnessTexture,L=d.emissiveTexture,U=d.normalsTexture,O=d.occlusionTexture;this._uColorMap&&T&&(this._program.bindTexture(this._uColorMap,T.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uMetallicRoughMap&&R&&(this._program.bindTexture(this._uMetallicRoughMap,R.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uEmissiveMap&&L&&(this._program.bindTexture(this._uEmissiveMap,L.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uNormalMap&&U&&(this._program.bindTexture(this._uNormalMap,U.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uAOMap&&O&&(this._program.bindTexture(this._uAOMap,O.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l)}if(v.reflectionMaps.length>0&&v.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,v.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++),v.lightMaps.length>0&&v.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,v.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++),this._withSAO){var N=u.sao,Q=N.possible;if(Q){var V=A.drawingBufferWidth,H=A.drawingBufferHeight;uo[0]=V,uo[1]=H,uo[2]=N.blendCutoff,uo[3]=N.blendFactor,A.uniform4fv(this._uSAOParams,uo),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++}}if(n){var j=this._edges?"edgeColor":"fillColor",G=this._edges?"edgeAlpha":"fillAlpha";if(i===oo["".concat(this._edges?"EDGES":"SILHOUETTE","_XRAYED")]){var z=u.xrayMaterial._state,W=z[j],K=z[G];A.uniform4f(this._uColor,W[0],W[1],W[2],K)}else if(i===oo["".concat(this._edges?"EDGES":"SILHOUETTE","_HIGHLIGHTED")]){var X=u.highlightMaterial._state,J=X[j],Y=X[G];A.uniform4f(this._uColor,J[0],J[1],J[2],Y)}else if(i===oo["".concat(this._edges?"EDGES":"SILHOUETTE","_SELECTED")]){var Z=u.selectedMaterial._state,q=Z[j],ee=Z[G];A.uniform4f(this._uColor,q[0],q[1],q[2],ee)}else A.uniform4fv(this._uColor,this._edges?lo:ao)}this._draw({state:c,frameCtx:e,incrementDrawState:a}),A.bindVertexArray(null)}}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null,se.memory.programs--}}]),e}(),fo=function(e){g(i,po);var t=_(i);function i(e,s){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.edges,o=void 0!==n&&n;return x(this,i),t.call(this,e,s,{instancing:!1,edges:o})}return C(i,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,i=e.state,s=e.frameCtx,r=e.incrementDrawState;if(this._edges)t.drawElements(t.LINES,i.edgeIndicesBuf.numItems,i.edgeIndicesBuf.itemType,0);else{var n=s.pickElementsCount||i.indicesBuf.numItems,o=s.pickElementsOffset?s.pickElementsOffset*i.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,n,i.indicesBuf.itemType,o),r&&s.drawElements++}}}]),i}(),vo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e,t=this._scene,i=t._sectionPlanesState,s=t._lightsState,r=i.getNumAllocatedSectionPlanes()>0,n=[];n.push("#version 300 es"),n.push("// Triangles batching draw vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in float flags;"),t.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n,!0),t.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("uniform vec4 lightAmbient;");for(var o=0,a=s.lights.length;o= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),r&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),t.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),n.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),n.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),n.push("float lambertian = 1.0;");for(var l=0,u=s.lights.length;l0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching draw fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o sliceThickness) { "),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" newColor = sliceColor;"),s.push(" }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(s.push(" float viewportWidth = uSAOParams[0];"),s.push(" float viewportHeight = uSAOParams[1];"),s.push(" float blendCutoff = uSAOParams[2];"),s.push(" float blendFactor = uSAOParams[3];"),s.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),s.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),s.push(" outColor = vec4(newColor.rgb * ambient, 1.0);")):s.push(" outColor = newColor;"),s.push("}"),s}}]),i}(),go=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("in float flags;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vViewPosition;"),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push("worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vViewPosition = viewPosition;"),i.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._lightsState,i=e._sectionPlanesState,s=i.getNumAllocatedSectionPlanes()>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching flat-shading draw 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("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),s){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var n=0,o=i.getNumAllocatedSectionPlanes();n> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var A=0,c=i.getNumAllocatedSectionPlanes();A sliceThickness) { "),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" newColor = sliceColor;"),r.push(" }"),r.push("}")}r.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),r.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),r.push("float lambertian = 1.0;"),r.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),r.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),r.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var h=0,d=t.lights.length;h0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching silhouette vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 color;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),i.push("if (silhouetteFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, color.a ));"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i._sectionPlanesState,r=s.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching silhouette 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"),i.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),r){for(n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;"),e=0,t=s.getNumAllocatedSectionPlanes();e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var o=0,a=s.getNumAllocatedSectionPlanes();o sliceThickness) { "),n.push(" discard;"),n.push(" }"),n.push(" if (dist > 0.0) { "),n.push(" newColor = sliceColor;"),n.push(" }"),n.push("}")}return i.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = newColor;"),n.push("}"),n}}]),i}(),_o=function(e){g(i,fo);var t=_(i);function i(e){return x(this,i),t.call(this,e,!1,{instancing:!1,edges:!0})}return C(i)}(),yo=function(e){g(i,_o);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// EdgesEmphasisRenderer vertex shader"),i.push("uniform int renderPass;"),i.push("uniform vec4 color;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int edgeFlag = int(flags) >> 8 & 0xF;"),i.push("if (edgeFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vColor = vec4(color.r, color.g, color.b, color.a);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// EdgesEmphasisRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vColor;"),s.push("}"),s}}]),i}(),bo=function(e){g(i,_o);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!1})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Batched geometry edges drawing vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int edgeFlag = int(flags) >> 8 & 0xF;"),i.push("if (edgeFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry edges drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vColor;"),s.push("}"),s}}]),i}(),wo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Batched geometry picking vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 pickColor;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),this._addRemapClipPosLines(i),i.push("out vec4 vPickColor;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry picking fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vPickColor; "),s.push("}"),s}}]),i}(),Bo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching pick depth vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),this._addRemapClipPosLines(i),i.push("out vec4 vViewPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vViewPosition = viewPosition;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform float pickZNear;"),s.push("uniform float pickZFar;"),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),s.push(" outColor = packDepth(zNormalizedDepth); "),s.push("}"),s}}]),i}(),xo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching pick normals vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec3 normal;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),this._addRemapClipPosLines(i,3),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),i.push("vec3 octDecode(vec2 oct) {"),i.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),i.push(" if (v.z < 0.0) {"),i.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),i.push(" }"),i.push(" return normalize(v);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec3 vWorldNormal;"),i.push("out vec4 outColor;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vec3 worldNormal = octDecode(normal.xy); "),i.push(" vWorldNormal = worldNormal;"),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching pick normals fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outNormal = ivec4(vWorldNormal * float(".concat($.MAX_INT,"), 1.0);")),s.push("}"),s}}]),i}(),Po=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching occlusion vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 color;"),i.push("in float flags;"),this._addMatricesUniformBlockLines(i),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),i.push("}"),i}}]),i}(),Co=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching depth vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec2 vHighPrecisionZW;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vHighPrecisionZW = gl_Position.zw;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching depth fragment shader"),s.push("precision highp float;"),s.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),s.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),s.push("}"),s}}]),i}(),Mo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Batched geometry normals vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec3 normal;"),i.push("in vec4 color;"),i.push("in float flags;"),this._addMatricesUniformBlockLines(i,!0),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),i.push("vec3 octDecode(vec2 oct) {"),i.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),i.push(" if (v.z < 0.0) {"),i.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),i.push(" }"),i.push(" return normalize(v);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec3 vViewNormal;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),i.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push(" vViewNormal = viewNormal;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry normals fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),s.push("}"),s}}]),i}(),Fo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Batched geometry shadow vertex shader"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 color;"),i.push("in float flags;"),i.push("uniform mat4 shadowViewMatrix;"),i.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(i),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vViewPosition;"),i.push("out vec4 outColor;"),i.push("void main(void) {"),i.push(" int colorFlag = int(flags) & 0xF;"),i.push(" bool visible = (colorFlag > 0);"),i.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),i.push(" if (!visible || transparent) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push(" vViewPosition = viewPosition;"),i.push(" gl_Position = shadowProjMatrix * viewPosition;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Batched geometry shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" outColor = encodeFloat( gl_FragCoord.z); "),i.push("}"),i}}]),i}(),Eo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=e._lightsState,s=t.getNumAllocatedSectionPlanes()>0,r=t.clippingCaps,n=[];return n.push("#version 300 es"),n.push("// Triangles batching quality draw vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in vec2 uv;"),n.push("in vec2 metallicRoughness;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n,!0),n.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),n.push("out vec4 vViewPosition;"),n.push("out vec3 vViewNormal;"),n.push("out vec4 vColor;"),n.push("out vec2 vUV;"),n.push("out vec2 vMetallicRoughness;"),i.lightMaps.length>0&&n.push("out vec3 vWorldNormal;"),s&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;"),r&&n.push("out vec4 vClipPosition;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("vFragDepth = 1.0 + clipPos.w;")),s&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;"),r&&n.push("vClipPosition = clipPos;")),n.push("vViewPosition = viewPosition;"),n.push("vViewNormal = viewNormal;"),n.push("vColor = color;"),n.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),n.push("vMetallicRoughness = metallicRoughness;"),i.lightMaps.length>0&&n.push("vWorldNormal = worldNormal.xyz;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,i=e._sectionPlanesState,s=e._lightsState,r=i.getNumAllocatedSectionPlanes()>0,n=i.clippingCaps,o=[];o.push("#version 300 es"),o.push("// Triangles batching quality draw fragment shader"),o.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),o.push("precision highp float;"),o.push("precision highp int;"),o.push("#else"),o.push("precision mediump float;"),o.push("precision mediump int;"),o.push("#endif"),e.logarithmicDepthBufferEnabled&&(o.push("in float isPerspective;"),o.push("uniform float logDepthBufFC;"),o.push("in float vFragDepth;")),o.push("uniform sampler2D uColorMap;"),o.push("uniform sampler2D uMetallicRoughMap;"),o.push("uniform sampler2D uEmissiveMap;"),o.push("uniform sampler2D uNormalMap;"),o.push("uniform sampler2D uAOMap;"),o.push("in vec4 vViewPosition;"),o.push("in vec3 vViewNormal;"),o.push("in vec4 vColor;"),o.push("in vec2 vUV;"),o.push("in vec2 vMetallicRoughness;"),s.lightMaps.length>0&&o.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(o,!0),s.reflectionMaps.length>0&&o.push("uniform samplerCube reflectionMap;"),s.lightMaps.length>0&&o.push("uniform samplerCube lightMap;"),o.push("uniform vec4 lightAmbient;");for(var a=0,l=s.lights.length;a0&&(o.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),o.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),o.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),o.push(" return envMapColor;"),o.push("}")),o.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),o.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),o.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),o.push("}"),o.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),o.push(" float a2 = ( alpha * alpha );"),o.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),o.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),o.push(" return 1.0 / ( gl * gv );"),o.push("}"),o.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),o.push(" float a2 = ( alpha * alpha );"),o.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),o.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),o.push(" return 0.5 / max( gv + gl, EPSILON );"),o.push("}"),o.push("float D_GGX(const in float alpha, const in float dotNH) {"),o.push(" float a2 = ( alpha * alpha );"),o.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),o.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),o.push("}"),o.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),o.push(" float alpha = ( roughness * roughness );"),o.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),o.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),o.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),o.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),o.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),o.push(" vec3 F = F_Schlick( specularColor, dotLH );"),o.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),o.push(" float D = D_GGX( alpha, dotNH );"),o.push(" return F * (G * D);"),o.push("}"),o.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),o.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),o.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),o.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),o.push(" vec4 r = roughness * c0 + c1;"),o.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),o.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),o.push(" return specularColor * AB.x + AB.y;"),o.push("}"),(s.lightMaps.length>0||s.reflectionMaps.length>0)&&(o.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),s.lightMaps.length>0&&(o.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),o.push(" irradiance *= PI;"),o.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),o.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),s.reflectionMaps.length>0&&(o.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),o.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),o.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),o.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),o.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),o.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),o.push("}")),o.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),o.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),o.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),o.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),o.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),o.push("}"),o.push("out vec4 outColor;"),o.push("void main(void) {"),r){o.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),o.push(" if (clippable) {"),o.push(" float dist = 0.0;");for(var h=0,d=i.getNumAllocatedSectionPlanes();h (0.002 * vClipPosition.w)) {"),o.push(" discard;"),o.push(" }"),o.push(" if (dist > 0.0) { "),o.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&o.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),o.push(" return;"),o.push("}")):(o.push(" if (dist > 0.0) { "),o.push(" discard;"),o.push(" }")),o.push("}")}o.push("IncidentLight light;"),o.push("Material material;"),o.push("Geometry geometry;"),o.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),o.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),o.push("float opacity = float(vColor.a) / 255.0;"),o.push("vec3 baseColor = rgb;"),o.push("float specularF0 = 1.0;"),o.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),o.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),o.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),o.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),o.push("baseColor *= colorTexel.rgb;"),o.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),o.push("metallic *= metalRoughTexel.b;"),o.push("roughness *= metalRoughTexel.g;"),o.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),o.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),o.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),o.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),o.push("geometry.position = vViewPosition.xyz;"),o.push("geometry.viewNormal = -normalize(viewNormal);"),o.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),s.lightMaps.length>0&&o.push("geometry.worldNormal = normalize(vWorldNormal);"),(s.lightMaps.length>0||s.reflectionMaps.length>0)&&o.push("computePBRLightMapping(geometry, material, reflectedLight);");for(var p=0,f=s.lights.length;p0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching pick flat normals vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),this._addRemapClipPosLines(i,3),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching pick flat normals fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("in vec4 vWorldPosition;"),i){s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),s.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),s.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),s.push(" outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),s.push("}"),s}}]),i}(),Io=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching color texture vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("in vec2 uv;"),i.push("in float flags;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),this._addMatricesUniformBlockLines(i),i.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vViewPosition;"),i.push("out vec4 vColor;"),i.push("out vec2 vUV;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push("worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vViewPosition = viewPosition;"),i.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),i.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,i=e._lightsState,s=e._sectionPlanesState,r=s.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching color texture 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("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform sampler2D uColorMap;"),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),n.push("uniform float gammaFactor;"),n.push("vec4 linearToLinear( in vec4 value ) {"),n.push(" return value;"),n.push("}"),n.push("vec4 sRGBToLinear( in vec4 value ) {"),n.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),n.push("}"),n.push("vec4 gammaToLinear( in vec4 value) {"),n.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),n.push("}"),t&&(n.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),n.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),n.push("}")),r){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var o=0,a=s.getNumAllocatedSectionPlanes();o> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var c=0,h=s.getNumAllocatedSectionPlanes();c sliceThickness) { "),n.push(" discard;"),n.push(" }"),n.push(" if (dist > 0.0) { "),n.push(" newColor = sliceColor;"),n.push(" }"),n.push("}")}n.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),n.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),n.push("float lambertian = 1.0;"),n.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),n.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),n.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var d=0,p=i.lights.length;d0,i=[];return i.push("#version 300 es"),i.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec4 pickColor;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vPickColor = pickColor;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),i.push("vec3 xTangent = dFdx( vWorldPosition.xyz );"),i.push("vec3 yTangent = dFdy( vWorldPosition.xyz );"),i.push("vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),i.push("outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Oo=$.vec3(),No=$.vec3(),Qo=$.vec3(),Vo=$.vec3(),Ho=$.mat4(),jo=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f,v=Oo;if(v[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,v[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,v[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(v[0]),e.snapPickCoordinateScale[1]=$.safeInv(v[1]),e.snapPickCoordinateScale[2]=$.safeInv(v[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var g=No;if(l){var m=Qo;$.transformPoint3(A,l,m),g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],p=Re(d,g,Ho),(f=Vo)[0]=n.eye[0]-g[0],f[1]=n.eye[1]-g[1],f[2]=n.eye[2]-g[2],e.snapPickOrigin[0]=g[0],e.snapPickOrigin[1]=g[1],e.snapPickOrigin[2]=g[2]}else p=d,f=n.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,v),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var _=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,_+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,_+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,_+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var y=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,y),this.setSectionPlanesStateUniforms(t),"edge"===e.snapMode?(a.edgeIndicesBuf.bind(),o.drawElements(o.LINES,a.edgeIndicesBuf.numItems,a.edgeIndicesBuf.itemType,0),a.edgeIndicesBuf.unbind()):o.drawArrays(o.POINTS,0,a.positionsBuf.numItems)}}},{key:"_allocate",value:function(){f(w(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0;e.pointsMaterial._state;var i=[];return i.push("#version 300 es"),i.push("// SnapBatchingDepthRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// SnapBatchingDepthRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Go=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorTextureRenderer&&!this._colorTextureRenderer.getValid()&&(this._colorTextureRenderer.destroy(),this._colorTextureRenderer=null),this._colorTextureRendererWithSAO&&!this._colorTextureRendererWithSAO.getValid()&&(this._colorTextureRendererWithSAO.destroy(),this._colorTextureRendererWithSAO=null),this._pbrRenderer&&!this._pbrRenderer.getValid()&&(this._pbrRenderer.destroy(),this._pbrRenderer=null),this._pbrRendererWithSAO&&!this._pbrRendererWithSAO.getValid()&&(this._pbrRendererWithSAO.destroy(),this._pbrRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null)}},{key:"eagerCreateRenders",value:function(){this._silhouetteRenderer||(this._silhouetteRenderer=new mo(this._scene)),this._pickMeshRenderer||(this._pickMeshRenderer=new wo(this._scene)),this._pickDepthRenderer||(this._pickDepthRenderer=new Bo(this._scene)),this._snapInitRenderer||(this._snapInitRenderer=new Uo(this._scene,!1)),this._snapRenderer||(this._snapRenderer=new jo(this._scene))}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new vo(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new vo(this._scene,!0)),this._colorRendererWithSAO}},{key:"flatColorRenderer",get:function(){return this._flatColorRenderer||(this._flatColorRenderer=new go(this._scene,!1)),this._flatColorRenderer}},{key:"flatColorRendererWithSAO",get:function(){return this._flatColorRendererWithSAO||(this._flatColorRendererWithSAO=new go(this._scene,!0)),this._flatColorRendererWithSAO}},{key:"colorTextureRenderer",get:function(){return this._colorTextureRenderer||(this._colorTextureRenderer=new Io(this._scene,!1)),this._colorTextureRenderer}},{key:"colorTextureRendererWithSAO",get:function(){return this._colorTextureRendererWithSAO||(this._colorTextureRendererWithSAO=new Io(this._scene,!0)),this._colorTextureRendererWithSAO}},{key:"pbrRenderer",get:function(){return this._pbrRenderer||(this._pbrRenderer=new Eo(this._scene,!1)),this._pbrRenderer}},{key:"pbrRendererWithSAO",get:function(){return this._pbrRendererWithSAO||(this._pbrRendererWithSAO=new Eo(this._scene,!0)),this._pbrRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new mo(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new Co(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new Mo(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new yo(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new bo(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new wo(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new xo(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new ko(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Bo(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Po(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new Fo(this._scene)),this._shadowRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new jo(this._scene)),this._snapRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new Uo(this._scene)),this._snapInitRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._colorTextureRenderer&&this._colorTextureRenderer.destroy(),this._colorTextureRendererWithSAO&&this._colorTextureRendererWithSAO.destroy(),this._pbrRenderer&&this._pbrRenderer.destroy(),this._pbrRendererWithSAO&&this._pbrRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy()}}]),e}(),zo={};var Wo=65536,Ko=5e6,Xo=function(){function e(){x(this,e)}return C(e,[{key:"doublePrecisionEnabled",get:function(){return $.getDoublePrecisionEnabled()},set:function(e){$.setDoublePrecisionEnabled(e)}},{key:"maxDataTextureHeight",get:function(){return Wo},set:function(e){(e=1024*Math.ceil(e/1024))>4096?e=4096:e<1024&&(e=1024),Wo=e}},{key:"maxGeometryBatchSize",get:function(){return Ko},set:function(e){e<1e5?e=1e5:e>5e6&&(e=5e6),Ko=e}}]),e}(),Jo=new Xo,Yo=C((function e(){x(this,e),this.maxVerts=Jo.maxGeometryBatchSize,this.maxIndices=3*Jo.maxGeometryBatchSize,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]})),Zo=$.mat4(),qo=$.mat4();function $o(e,t,i){for(var s=e.length,r=new Uint16Array(s),n=t[0],o=t[1],a=t[2],l=t[3]-n,u=t[4]-o,A=t[5]-a,c=65525,h=c/l,d=c/u,p=c/A,f=function(e){return e>=0?e:0},v=0;v=0?1:-1),o=(1-Math.abs(s))*(r>=0?1:-1),s=n,r=o}return new Int8Array([Math[t](127.5*s+(s<0?-1:0)),Math[i](127.5*r+(r<0?-1:0))])}function ia(e){var t=e[0],i=e[1];t/=t<0?127:128,i/=i<0?127:128;var s=1-Math.abs(t)-Math.abs(i);s<0&&(t=(1-Math.abs(i))*(t>=0?1:-1),i=(1-Math.abs(t))*(i>=0?1:-1));var r=Math.sqrt(t*t+i*i+s*s);return[t/r,i/r,s/r]}var sa=$.mat4(),ra=$.mat4(),na=$.vec4([0,0,0,1]),oa=$.vec3(),aa=$.vec3(),la=$.vec3(),ua=$.vec3(),Aa=$.vec3(),ca=$.vec3(),ha=$.vec3(),da=function(){function e(t){var i,s,r;x(this,e),console.info("Creating VBOBatchingTrianglesLayer"),this.model=t.model,this.sortId="TrianglesBatchingLayer"+(t.solid?"-solid":"-surface")+(t.autoNormals?"-autonormals":"-normals")+(t.textureSet&&t.textureSet.colorTexture?"-colorTexture":"")+(t.textureSet&&t.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=t.layerIndex,this._renderers=(i=t.model.scene,s=i.id,(r=zo[s])||(r=new Go(i),zo[s]=r,r._compile(),r.eagerCreateRenders(),i.on("compile",(function(){r._compile(),r.eagerCreateRenders()})),i.on("destroyed",(function(){delete zo[s],r._destroy()}))),r),this._buffer=new Yo(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new Zt({origin:$.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:t.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=$.collapseAABB3(),this._portions=[],this._meshes=[],this._numVerts=0,this._aabb=$.collapseAABB3(),this.aabbDirty=!0,this._finalized=!1,t.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=$.mat4(t.positionsDecodeMatrix)),t.uvDecodeMatrix?(this._state.uvDecodeMatrix=$.mat3(t.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,t.origin&&this._state.origin.set(t.origin),this.solid=!!t.solid}return C(e,[{key:"aabb",get:function(){if(this.aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._meshes.length;e0)for(var C=0,M=o.length;C0){var F=sa;g?$.inverseMat4($.transposeMat4(g,ra),F):$.identityMat4(F,F),function(e,t,i,s,r){function n(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}var o,a,l,u,A,c=new Float32Array([0,0,0,0]),h=new Float32Array([0,0,0,0]);for(A=0;Au&&(a=o,u=l),(l=n(h,ia(o=ta(h,"floor","ceil"))))>u&&(a=o,u=l),(l=n(h,ia(o=ta(h,"ceil","ceil"))))>u&&(a=o,u=l),s[r+A+0]=a[0],s[r+A+1]=a[1],s[r+A+2]=0}(F,n,n.length,y.normals,y.normals.length)}if(u)for(var E=0,k=u.length;E0)for(var V=0,H=a.length;V0)for(var j=0,G=l.length;j0){var s=this._state.positionsDecodeMatrix?new Uint16Array(i.positions):$o(i.positions,this._modelAABB,this._state.positionsDecodeMatrix=$.mat4());if(e.positionsBuf=new It(t,t.ARRAY_BUFFER,s,s.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(var r=0,n=this._portions.length;r0){var u=new Int8Array(i.normals);e.normalsBuf=new It(t,t.ARRAY_BUFFER,u,i.normals.length,3,t.STATIC_DRAW,!0)}if(i.colors.length>0){var A=new Uint8Array(i.colors);e.colorsBuf=new It(t,t.ARRAY_BUFFER,A,i.colors.length,4,t.DYNAMIC_DRAW,!1)}if(i.uv.length>0)if(e.uvDecodeMatrix){e.uvBuf=new It(t,t.ARRAY_BUFFER,i.uv,i.uv.length,2,t.STATIC_DRAW,!1)}else{var c=ki.getUVBounds(i.uv),h=ki.compressUVs(i.uv,c.min,c.max),d=h.quantized;e.uvDecodeMatrix=$.mat3(h.decodeMatrix),e.uvBuf=new It(t,t.ARRAY_BUFFER,d,d.length,2,t.STATIC_DRAW,!1)}if(i.metallicRoughness.length>0){var p=new Uint8Array(i.metallicRoughness);e.metallicRoughnessBuf=new It(t,t.ARRAY_BUFFER,p,i.metallicRoughness.length,2,t.STATIC_DRAW,!1)}if(i.positions.length>0){var f=i.positions.length/3,v=new Float32Array(f);e.flagsBuf=new It(t,t.ARRAY_BUFFER,v,v.length,1,t.DYNAMIC_DRAW,!1)}if(i.pickColors.length>0){var g=new Uint8Array(i.pickColors);e.pickColorsBuf=new It(t,t.ARRAY_BUFFER,g,i.pickColors.length,4,t.STATIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&i.offsets.length>0){var m=new Float32Array(i.offsets);e.offsetsBuf=new It(t,t.ARRAY_BUFFER,m,i.offsets.length,3,t.DYNAMIC_DRAW)}if(i.indices.length>0){var _=new Uint32Array(i.indices);e.indicesBuf=new It(t,t.ELEMENT_ARRAY_BUFFER,_,i.indices.length,1,t.STATIC_DRAW)}if(i.edgeIndices.length>0){var y=new Uint32Array(i.edgeIndices);e.edgeIndicesBuf=new It(t,t.ELEMENT_ARRAY_BUFFER,y,i.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}}},{key:"isEmpty",value:function(){return!this._state.indicesBuf}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Xe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,i,!0)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags()}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Xe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,i)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var i=e,s=this._portions[i],r=4*s.vertsBaseIndex,n=4*s.numVerts,o=this._scratchMemory.getUInt8Array(n),a=t[0],l=t[1],u=t[2],A=t[3],c=0;c3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var r,n,o=e,a=this._portions[o],l=a.vertsBaseIndex,u=a.numVerts,A=l,c=u,h=!!(t&Qe),d=!!(t&ze),p=!!(t&We),f=!!(t&Ke),v=!!(t&Xe),g=!!(t&He),m=!!(t&Ve);r=!h||m||d||p&&!this.model.scene.highlightMaterial.glowThrough||f&&!this.model.scene.selectedMaterial.glowThrough?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,n=!h||m?oo.NOT_RENDERED:f?oo.SILHOUETTE_SELECTED:p?oo.SILHOUETTE_HIGHLIGHTED:d?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED;var _=0;_=!h||m?oo.NOT_RENDERED:f?oo.EDGES_SELECTED:p?oo.EDGES_HIGHLIGHTED:d?oo.EDGES_XRAYED:v?i?oo.EDGES_COLOR_TRANSPARENT:oo.EDGES_COLOR_OPAQUE:oo.NOT_RENDERED;var y=h&&!m&&g?oo.PICK:oo.NOT_RENDERED,b=t&je?1:0;if(s){this._deferredFlagValues||(this._deferredFlagValues=new Float32Array(this._numVerts));for(var w=A,B=A+c;wg)&&(g=x,s.set(m),r&&$.triangleNormal(d,p,f,r),v=!0)}}return v&&r&&($.transformVec3(this.model.worldNormalMatrix,r,r),$.normalizeVec3(r)),v}},{key:"destroy",value:function(){var e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}]),e}(),pa=function(e){g(i,po);var t=_(i);function i(e,s){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.edges,o=void 0!==n&&n;return x(this,i),t.call(this,e,s,{instancing:!0,edges:o})}return C(i,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,i=e.state,s=e.frameCtx,r=e.incrementDrawState;this._edges?t.drawElementsInstanced(t.LINES,i.edgeIndicesBuf.numItems,i.edgeIndicesBuf.itemType,0,i.numInstances):(t.drawElementsInstanced(t.TRIANGLES,i.indicesBuf.numItems,i.indicesBuf.itemType,0,i.numInstances),r&&s.drawElements++)}}]),i}(),fa=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e,t,i,s=this._scene,r=s._sectionPlanesState,n=s._lightsState,o=r.getNumAllocatedSectionPlanes()>0,a=[];for(a.push("#version 300 es"),a.push("// Instancing geometry drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec2 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),s.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),s.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;"),e=0,t=n.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),o&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),s.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),a.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),e=0,t=n.lights.length;e0,s=[];if(s.push("#version 300 es"),s.push("// Instancing geometry drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o sliceThickness) { "),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" newColor = sliceColor;"),s.push(" }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(s.push(" float viewportWidth = uSAOParams[0];"),s.push(" float viewportHeight = uSAOParams[1];"),s.push(" float blendCutoff = uSAOParams[2];"),s.push(" float blendFactor = uSAOParams[3];"),s.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),s.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),s.push(" outColor = vec4(newColor.rgb * ambient, 1.0);")):s.push(" outColor = newColor;"),s.push("}"),s}}]),i}(),va=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry flat-shading drawing vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("in float flags;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vViewPosition;"),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vViewPosition = viewPosition;"),i.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i._sectionPlanesState,r=i._lightsState,n=s.getNumAllocatedSectionPlanes()>0,o=[];if(o.push("#version 300 es"),o.push("// Instancing geometry flat-shading drawing fragment shader"),o.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),o.push("precision highp float;"),o.push("precision highp int;"),o.push("#else"),o.push("precision mediump float;"),o.push("precision mediump int;"),o.push("#endif"),i.logarithmicDepthBufferEnabled&&(o.push("in float isPerspective;"),o.push("uniform float logDepthBufFC;"),o.push("in float vFragDepth;")),this._withSAO&&(o.push("uniform sampler2D uOcclusionTexture;"),o.push("uniform vec4 uSAOParams;"),o.push("const float packUpscale = 256. / 255.;"),o.push("const float unpackDownScale = 255. / 256.;"),o.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),o.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),o.push("float unpackRGBToFloat( const in vec4 v ) {"),o.push(" return dot( v, unPackFactors );"),o.push("}")),n){o.push("in vec4 vWorldPosition;"),o.push("in float vFlags;");for(var a=0,l=s.getNumAllocatedSectionPlanes();a> 16 & 0xF) == 1;"),o.push(" if (clippable) {"),o.push(" float dist = 0.0;");for(var A=0,c=s.getNumAllocatedSectionPlanes();A sliceThickness) { "),o.push(" discard;"),o.push(" }"),o.push(" if (dist > 0.0) { "),o.push(" newColor = sliceColor;"),o.push(" }"),o.push("}")}for(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),o.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),o.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),o.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),e=0,t=r.lights.length;e0,i=[];return i.push("#version 300 es"),i.push("// Instancing silhouette vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 color;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),i.push("if (silhouetteFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Instancing fill fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o sliceThickness) { "),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" newColor = sliceColor;"),s.push(" }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = newColor;"),s.push("}"),s}}]),i}(),ma=function(e){g(i,pa);var t=_(i);function i(e,s){return x(this,i),t.call(this,e,s,{instancing:!0,edges:!0})}return C(i)}(),_a=function(e){g(i,ma);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// EdgesEmphasisRenderer vertex shader"),i.push("uniform int renderPass;"),i.push("uniform vec4 color;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int edgeFlag = int(flags) >> 8 & 0xF;"),i.push("if (edgeFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = worldMatrix * positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vColor = vec4(color.r, color.g, color.b, color.a);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// EdgesEmphasisRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vColor;"),s.push("}"),s}}]),i}(),ya=function(e){g(i,ma);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!1})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// EdgesColorRenderer vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int edgeFlag = int(flags) >> 8 & 0xF;"),i.push("if (edgeFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// EdgesColorRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vColor;"),s.push("}"),s}}]),i}(),ba=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry picking vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 pickColor;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),this._addRemapClipPosLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vPickColor;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry picking fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vPickColor; "),s.push("}"),s}}]),i}(),wa=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry depth vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),this._addRemapClipPosLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vViewPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push(" vViewPosition = viewPosition;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform float pickZNear;"),s.push("uniform float pickZFar;"),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),s.push(" outColor = packDepth(zNormalizedDepth); "),s.push("}"),s}}]),i}(),Ba=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry normals vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec2 normal;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("in vec4 modelNormalMatrixCol0;"),i.push("in vec4 modelNormalMatrixCol1;"),i.push("in vec4 modelNormalMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),this._addRemapClipPosLines(i,3),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),i.push("vec3 octDecode(vec2 oct) {"),i.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),i.push(" if (v.z < 0.0) {"),i.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),i.push(" }"),i.push(" return normalize(v);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec3 vWorldNormal;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),i.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),i.push(" vWorldNormal = worldNormal;"),t&&(i.push(" vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry normals fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outNormal = ivec4(vWorldNormal * float(".concat($.MAX_INT,"), 1.0);")),s.push("}"),s}}]),i}(),xa=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// TrianglesInstancingOcclusionRenderer vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 color;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// TrianglesInstancingOcclusionRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),i.push("}"),i}}]),i}(),Pa=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry depth drawing vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec2 vHighPrecisionZW;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vHighPrecisionZW = gl_Position.zw;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i._sectionPlanesState,r=s.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("precision highp float;"),n.push("precision highp int;"),i.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),r)for(n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;"),e=0,t=s.getNumAllocatedSectionPlanes();e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;"),e=0,t=s.getNumAllocatedSectionPlanes();e 0.0) { discard; }"),n.push("}")}return i.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}}]),i}(),Ca=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry normals drawing vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec3 normal;"),i.push("in vec4 color;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i,!0),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),i.push("vec3 octDecode(vec2 oct) {"),i.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),i.push(" if (v.z < 0.0) {"),i.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),i.push(" }"),i.push(" return normalize(v);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec3 vViewNormal;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),i.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push(" vViewNormal = viewNormal;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Instancing geometry depth drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),s.push("}"),s}}]),i}(),Ma=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry shadow drawing vertex shader"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 color;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform mat4 shadowViewMatrix;"),i.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(i),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("bool visible = (colorFlag > 0);"),i.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),i.push("if (!visible || transparent) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push(" gl_Position = shadowProjMatrix * viewPosition;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Instancing geometry depth drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),s.push("}"),s}}]),i}(),Fa={3e3:"linearToLinear",3001:"sRGBToLinear"},Ea=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=e._lightsState,s=t.getNumAllocatedSectionPlanes()>0,r=t.clippingCaps,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry quality drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in vec2 uv;"),n.push("in vec2 metallicRoughness;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("in vec4 modelNormalMatrixCol0;"),n.push("in vec4 modelNormalMatrixCol1;"),n.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(n,!0),n.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),n.push("out vec4 vViewPosition;"),n.push("out vec3 vViewNormal;"),n.push("out vec4 vColor;"),n.push("out vec2 vUV;"),n.push("out vec2 vMetallicRoughness;"),i.lightMaps.length>0&&n.push("out vec3 vWorldNormal;"),s&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;"),r&&n.push("out vec4 vClipPosition;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),n.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),n.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;"),r&&n.push("vClipPosition = clipPos;")),n.push("vViewPosition = viewPosition;"),n.push("vViewNormal = viewNormal;"),n.push("vColor = color;"),n.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),n.push("vMetallicRoughness = metallicRoughness;"),i.lightMaps.length>0&&n.push("vWorldNormal = worldNormal.xyz;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,i=e._sectionPlanesState,s=e._lightsState,r=i.getNumAllocatedSectionPlanes()>0,n=i.clippingCaps,o=[];o.push("#version 300 es"),o.push("// Instancing geometry quality drawing fragment shader"),o.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),o.push("precision highp float;"),o.push("precision highp int;"),o.push("#else"),o.push("precision mediump float;"),o.push("precision mediump int;"),o.push("#endif"),e.logarithmicDepthBufferEnabled&&(o.push("in float isPerspective;"),o.push("uniform float logDepthBufFC;"),o.push("in float vFragDepth;")),o.push("uniform sampler2D uColorMap;"),o.push("uniform sampler2D uMetallicRoughMap;"),o.push("uniform sampler2D uEmissiveMap;"),o.push("uniform sampler2D uNormalMap;"),this._withSAO&&(o.push("uniform sampler2D uOcclusionTexture;"),o.push("uniform vec4 uSAOParams;"),o.push("const float packUpscale = 256. / 255.;"),o.push("const float unpackDownScale = 255. / 256.;"),o.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),o.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),o.push("float unpackRGBToFloat( const in vec4 v ) {"),o.push(" return dot( v, unPackFactors );"),o.push("}")),s.reflectionMaps.length>0&&o.push("uniform samplerCube reflectionMap;"),s.lightMaps.length>0&&o.push("uniform samplerCube lightMap;"),o.push("uniform vec4 lightAmbient;");for(var a=0,l=s.lights.length;a0&&o.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(o,!0),o.push("#define PI 3.14159265359"),o.push("#define RECIPROCAL_PI 0.31830988618"),o.push("#define RECIPROCAL_PI2 0.15915494"),o.push("#define EPSILON 1e-6"),o.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),o.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),o.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),o.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),o.push(" return normalize(surf_norm );"),o.push(" }"),o.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),o.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),o.push(" vec2 st0 = dFdx( uv.st );"),o.push(" vec2 st1 = dFdy( uv.st );"),o.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),o.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),o.push(" vec3 N = normalize( surf_norm );"),o.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),o.push(" mat3 tsn = mat3( S, T, N );"),o.push(" return normalize( tsn * mapN );"),o.push("}"),o.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),o.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),o.push("}"),o.push("struct IncidentLight {"),o.push(" vec3 color;"),o.push(" vec3 direction;"),o.push("};"),o.push("struct ReflectedLight {"),o.push(" vec3 diffuse;"),o.push(" vec3 specular;"),o.push("};"),o.push("struct Geometry {"),o.push(" vec3 position;"),o.push(" vec3 viewNormal;"),o.push(" vec3 worldNormal;"),o.push(" vec3 viewEyeDir;"),o.push("};"),o.push("struct Material {"),o.push(" vec3 diffuseColor;"),o.push(" float specularRoughness;"),o.push(" vec3 specularColor;"),o.push(" float shine;"),o.push("};"),o.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),o.push(" float r = ggxRoughness + 0.0001;"),o.push(" return (2.0 / (r * r) - 2.0);"),o.push("}"),o.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),o.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),o.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),o.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),o.push("}"),s.reflectionMaps.length>0&&(o.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),o.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),o.push(" vec3 envMapColor = "+Fa[s.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),o.push(" return envMapColor;"),o.push("}")),o.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),o.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),o.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),o.push("}"),o.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),o.push(" float a2 = ( alpha * alpha );"),o.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),o.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),o.push(" return 1.0 / ( gl * gv );"),o.push("}"),o.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),o.push(" float a2 = ( alpha * alpha );"),o.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),o.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),o.push(" return 0.5 / max( gv + gl, EPSILON );"),o.push("}"),o.push("float D_GGX(const in float alpha, const in float dotNH) {"),o.push(" float a2 = ( alpha * alpha );"),o.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),o.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),o.push("}"),o.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),o.push(" float alpha = ( roughness * roughness );"),o.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),o.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),o.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),o.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),o.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),o.push(" vec3 F = F_Schlick( specularColor, dotLH );"),o.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),o.push(" float D = D_GGX( alpha, dotNH );"),o.push(" return F * (G * D);"),o.push("}"),o.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),o.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),o.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),o.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),o.push(" vec4 r = roughness * c0 + c1;"),o.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),o.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),o.push(" return specularColor * AB.x + AB.y;"),o.push("}"),(s.lightMaps.length>0||s.reflectionMaps.length>0)&&(o.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),s.lightMaps.length>0&&(o.push(" vec3 irradiance = "+Fa[s.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),o.push(" irradiance *= PI;"),o.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),o.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),s.reflectionMaps.length>0&&(o.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),o.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),o.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),o.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),o.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),o.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),o.push("}")),o.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),o.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),o.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),o.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),o.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),o.push("}"),o.push("out vec4 outColor;"),o.push("void main(void) {"),r){o.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),o.push(" if (clippable) {"),o.push(" float dist = 0.0;");for(var h=0,d=i.getNumAllocatedSectionPlanes();h (0.002 * vClipPosition.w)) {"),o.push(" discard;"),o.push(" }"),o.push(" if (dist > 0.0) { "),o.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&o.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),o.push(" return;"),o.push("}")):(o.push(" if (dist > 0.0) { "),o.push(" discard;"),o.push(" }")),o.push("}")}o.push("IncidentLight light;"),o.push("Material material;"),o.push("Geometry geometry;"),o.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),o.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),o.push("float opacity = float(vColor.a) / 255.0;"),o.push("vec3 baseColor = rgb;"),o.push("float specularF0 = 1.0;"),o.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),o.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),o.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),o.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),o.push("baseColor *= colorTexel.rgb;"),o.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),o.push("metallic *= metalRoughTexel.b;"),o.push("roughness *= metalRoughTexel.g;"),o.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),o.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),o.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),o.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),o.push("geometry.position = vViewPosition.xyz;"),o.push("geometry.viewNormal = -normalize(viewNormal);"),o.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),s.lightMaps.length>0&&o.push("geometry.worldNormal = normalize(vWorldNormal);"),(s.lightMaps.length>0||s.reflectionMaps.length>0)&&o.push("computePBRLightMapping(geometry, material, reflectedLight);");for(var p=0,f=s.lights.length;p0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry normals vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),this._addRemapClipPosLines(i,3),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&i.push("out float vFlags;"),i.push("out vec4 vWorldPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&i.push("vFlags = flags;"),i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry normals fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("in vec4 vWorldPosition;"),i){s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),s.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),s.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),s.push(" outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),s.push("}"),s}}]),i}(),Ia=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry drawing vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("in vec2 uv;"),i.push("in float flags;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),i.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vViewPosition;"),i.push("out vec4 vColor;"),i.push("out vec2 vUV;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vViewPosition = viewPosition;"),i.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),i.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i.gammaOutput,r=i._sectionPlanesState,n=i._lightsState,o=r.getNumAllocatedSectionPlanes()>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),i.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),s&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),o){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(var l=0,u=r.getNumAllocatedSectionPlanes();l> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(var c=0,h=r.getNumAllocatedSectionPlanes();c sliceThickness) { "),a.push(" discard;"),a.push(" }"),a.push(" if (dist > 0.0) { "),a.push(" newColor = sliceColor;"),a.push(" }"),a.push("}")}for(a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),e=0,t=n.lights.length;e0,i=[];return i.push("#version 300 es"),i.push("// SnapInstancingDepthBufInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec4 pickColor;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vPickColor = pickColor;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Points instancing pick depth fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),i.push("vec3 xTangent = dFdx( vWorldPosition.xyz );"),i.push("vec3 yTangent = dFdy( vWorldPosition.xyz );"),i.push("vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),i.push("outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Oa=$.vec3(),Na=$.vec3(),Qa=$.vec3(),Va=$.vec3(),Ha=$.mat4(),ja=function(e){g(i,po);var t=_(i);function i(e){return x(this,i),t.call(this,e,!1,{instancing:!0})}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f,v=Oa;if(v[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,v[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,v[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(v[0]),e.snapPickCoordinateScale[1]=$.safeInv(v[1]),e.snapPickCoordinateScale[2]=$.safeInv(v[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var g=Na;if(l){var m=$.transformPoint3(A,l,Qa);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],p=Re(d,g,Ha),(f=Va)[0]=n.eye[0]-g[0],f[1]=n.eye[1]-g[1],f[2]=n.eye[2]-g[2],e.snapPickOrigin[0]=g[0],e.snapPickOrigin[1]=g[1],e.snapPickOrigin[2]=g[2]}else p=d,f=n.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,v),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var _=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,_+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,_+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,_+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var y=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,y),this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(a.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(a.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(a.modelMatrixCol2Buf),o.vertexAttribDivisor(this._aModelMatrixCol0.location,1),o.vertexAttribDivisor(this._aModelMatrixCol1.location,1),o.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags.bindArrayBuffer(a.flagsBuf),o.vertexAttribDivisor(this._aFlags.location,1),"edge"===e.snapMode?(a.edgeIndicesBuf.bind(),o.drawElementsInstanced(o.LINES,a.edgeIndicesBuf.numItems,a.edgeIndicesBuf.itemType,0,a.numInstances),a.edgeIndicesBuf.unbind()):o.drawArraysInstanced(o.POINTS,0,a.positionsBuf.numItems,a.numInstances),o.vertexAttribDivisor(this._aModelMatrixCol0.location,0),o.vertexAttribDivisor(this._aModelMatrixCol1.location,0),o.vertexAttribDivisor(this._aModelMatrixCol2.location,0),o.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&o.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){f(w(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// SnapInstancingDepthRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// SnapInstancingDepthRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Ga=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._pbrRenderer&&!this._pbrRenderer.getValid()&&(this._pbrRenderer.destroy(),this._pbrRenderer=null),this._pbrRendererWithSAO&&!this._pbrRendererWithSAO.getValid()&&(this._pbrRendererWithSAO.destroy(),this._pbrRendererWithSAO=null),this._colorTextureRenderer&&!this._colorTextureRenderer.getValid()&&(this._colorTextureRenderer.destroy(),this._colorTextureRenderer=null),this._colorTextureRendererWithSAO&&!this._colorTextureRendererWithSAO.getValid()&&(this._colorTextureRendererWithSAO.destroy(),this._colorTextureRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null)}},{key:"eagerCreateRenders",value:function(){this._silhouetteRenderer||(this._silhouetteRenderer=new ga(this._scene)),this._pickMeshRenderer||(this._pickMeshRenderer=new ba(this._scene)),this._pickDepthRenderer||(this._pickDepthRenderer=new wa(this._scene)),this._snapInitRenderer||(this._snapInitRenderer=new Ua(this._scene,!1)),this._snapRenderer||(this._snapRenderer=new ja(this._scene))}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new fa(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new fa(this._scene,!0)),this._colorRendererWithSAO}},{key:"flatColorRenderer",get:function(){return this._flatColorRenderer||(this._flatColorRenderer=new va(this._scene,!1)),this._flatColorRenderer}},{key:"flatColorRendererWithSAO",get:function(){return this._flatColorRendererWithSAO||(this._flatColorRendererWithSAO=new va(this._scene,!0)),this._flatColorRendererWithSAO}},{key:"pbrRenderer",get:function(){return this._pbrRenderer||(this._pbrRenderer=new Ea(this._scene,!1)),this._pbrRenderer}},{key:"pbrRendererWithSAO",get:function(){return this._pbrRendererWithSAO||(this._pbrRendererWithSAO=new Ea(this._scene,!0)),this._pbrRendererWithSAO}},{key:"colorTextureRenderer",get:function(){return this._colorTextureRenderer||(this._colorTextureRenderer=new Ia(this._scene,!1)),this._colorTextureRenderer}},{key:"colorTextureRendererWithSAO",get:function(){return this._colorTextureRendererWithSAO||(this._colorTextureRendererWithSAO=new Ia(this._scene,!0)),this._colorTextureRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ga(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new Pa(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new Ca(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new _a(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new ya(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new ba(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new Ba(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new ka(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new wa(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new xa(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new Ma(this._scene)),this._shadowRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new Ua(this._scene,!1)),this._snapInitRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new ja(this._scene)),this._snapRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._pbrRenderer&&this._pbrRenderer.destroy(),this._pbrRendererWithSAO&&this._pbrRendererWithSAO.destroy(),this._colorTextureRenderer&&this._colorTextureRenderer.destroy(),this._colorTextureRendererWithSAO&&this._colorTextureRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy()}}]),e}(),za={};var Wa=new Uint8Array(4),Ka=new Float32Array(1),Xa=$.vec4([0,0,0,1]),Ja=new Float32Array(3),Ya=$.vec3(),Za=$.vec3(),qa=$.vec3(),$a=$.vec3(),el=$.vec3(),tl=$.vec3(),il=$.vec3(),sl=new Float32Array(4),rl=function(){function e(t){var i,s,r;x(this,e),console.info("Creating VBOInstancingTrianglesLayer"),this.model=t.model,this.sortId="TrianglesInstancingLayer"+(t.solid?"-solid":"-surface")+(t.normals?"-normals":"-autoNormals"),this.layerIndex=t.layerIndex,this._renderers=(i=t.model.scene,s=i.id,(r=za[s])||(r=new Ga(i),za[s]=r,r._compile(),r.eagerCreateRenders(),i.on("compile",(function(){r._compile(),r.eagerCreateRenders()})),i.on("destroyed",(function(){delete za[s],r._destroy()}))),r),this._aabb=$.collapseAABB3(),this._state=new Zt({numInstances:0,obb:$.OBB3(),origin:$.vec3(),geometry:t.geometry,textureSet:t.textureSet,pbrSupported:!1,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrix=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],this._meshes=[],this._aabb=$.collapseAABB3(),this.aabbDirty=!0,t.origin&&this._state.origin.set(t.origin),this._finalized=!1,this.solid=!!t.solid,this.numIndices=t.geometry.numIndices}return C(e,[{key:"aabb",get:function(){if(this.aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._meshes.length;e0){e.colorsBuf=new It(s,s.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,s.DYNAMIC_DRAW,!1),this._colors=[]}if(this._metallicRoughness.length>0){var o=new Uint8Array(this._metallicRoughness);e.metallicRoughnessBuf=new It(s,s.ARRAY_BUFFER,o,this._metallicRoughness.length,2,s.STATIC_DRAW,!1)}if(n>0){e.flagsBuf=new It(s,s.ARRAY_BUFFER,new Float32Array(n),n,1,s.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){e.offsetsBuf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,s.DYNAMIC_DRAW,!1),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){e.positionsBuf=new It(s,s.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,s.STATIC_DRAW,!1),e.positionsDecodeMatrix=$.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){var a=new Uint8Array(t.colorsCompressed);e.colorsBuf=new It(s,s.ARRAY_BUFFER,a,a.length,4,s.STATIC_DRAW,!1)}if(t.uvCompressed&&t.uvCompressed.length>0){var l=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new It(s,s.ARRAY_BUFFER,l,l.length,2,s.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new It(s,s.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,s.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new It(s,s.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,s.STATIC_DRAW)),this._modelMatrixCol0.length>0){var u=!1;e.modelMatrixCol0Buf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,s.STATIC_DRAW,u),e.modelMatrixCol1Buf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,s.STATIC_DRAW,u),e.modelMatrixCol2Buf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,s.STATIC_DRAW,u),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,s.STATIC_DRAW,u),e.modelNormalMatrixCol1Buf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,s.STATIC_DRAW,u),e.modelNormalMatrixCol2Buf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,s.STATIC_DRAW,u),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){e.pickColorsBuf=new It(s,s.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,s.STATIC_DRAW,!1),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&i&&i.colorTexture&&i.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!i&&!!i.colorTexture,this._state.geometry=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Xe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,i)}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Xe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,i)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";Wa[0]=t[0],Wa[1]=t[1],Wa[2]=t[2],Wa[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(Wa,4*e)}},{key:"setTransparent",value:function(e,t,i){i?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,i)}},{key:"_setFlags",value:function(e,t,i){if(!this._finalized)throw"Not finalized";var s=!!(t&Qe),r=!!(t&ze),n=!!(t&We),o=!!(t&Ke),a=!!(t&Xe),l=!!(t&He),u=!!(t&Ve),A=0;A|=!s||u||r||n&&!this.model.scene.highlightMaterial.glowThrough||o&&!this.model.scene.selectedMaterial.glowThrough?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,A|=(!s||u?oo.NOT_RENDERED:o?oo.SILHOUETTE_SELECTED:n?oo.SILHOUETTE_HIGHLIGHTED:r?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED)<<4,A|=(!s||u?oo.NOT_RENDERED:o?oo.EDGES_SELECTED:n?oo.EDGES_HIGHLIGHTED:r?oo.EDGES_XRAYED:a?i?oo.EDGES_COLOR_TRANSPARENT:oo.EDGES_COLOR_OPAQUE:oo.NOT_RENDERED)<<8,A|=(s&&!u&&l?oo.PICK:oo.NOT_RENDERED)<<12,A|=(t&je?1:0)<<16,Ka[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(Ka,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Ja[0]=t[0],Ja[1]=t[1],Ja[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Ja,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"getEachVertex",value:function(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;var i=this._state,s=i.geometry,r=this._portions[e];if(r)for(var n=s.quantizedPositions,o=i.origin,a=r.offset,l=o[0]+a[0],u=o[1]+a[1],A=o[2]+a[2],c=Xa,h=r.matrix,d=this.model.sceneModelMatrix,p=i.positionsDecodeMatrix,f=0,v=n.length;fm)&&(m=C,s.set(_),r&&$.triangleNormal(p,f,v,r),g=!0)}}return g&&r&&($.transformVec3(a.normalMatrix,r,r),$.transformVec3(this.model.worldNormalMatrix,r,r),$.normalizeVec3(r)),g}},{key:"destroy",value:function(){var e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}]),e}(),nl=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,i=e.state,s=e.frameCtx,r=e.incrementDrawState;t.drawElements(t.LINES,i.indicesBuf.numItems,i.indicesBuf.itemType,0),r&&s.drawElements++}}]),i}(),ol=function(e){g(i,nl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Lines batching color vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("in float flags;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push("worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Lines batching color fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return s.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),i}(),al=function(e){g(i,nl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Lines batching silhouette vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("void main(void) {"),i.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),i.push("if (silhouetteFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Lines batching silhouette fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = color;"),s.push("}"),s}}]),i}(),ll=$.vec3(),ul=$.vec3(),Al=$.vec3(),cl=$.vec3(),hl=$.mat4(),dl=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f,v=ll;if(v[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,v[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,v[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(v[0]),e.snapPickCoordinateScale[1]=$.safeInv(v[1]),e.snapPickCoordinateScale[2]=$.safeInv(v[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var g=ul;if(l){var m=Al;$.transformPoint3(A,l,m),g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],p=Re(d,g,hl),(f=cl)[0]=n.eye[0]-g[0],f[1]=n.eye[1]-g[1],f[2]=n.eye[2]-g[2],e.snapPickOrigin[0]=g[0],e.snapPickOrigin[1]=g[1],e.snapPickOrigin[2]=g[2]}else p=d,f=n.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,v),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var _=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,_+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,_+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,_+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var y=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,y),this.setSectionPlanesStateUniforms(t),a.indicesBuf.bind(),o.drawElements(o.LINES,a.indicesBuf.numItems,a.indicesBuf.itemType,0),a.indicesBuf.unbind()}}},{key:"_allocate",value:function(){f(w(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec4 pickColor;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vPickColor = pickColor;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),i.push("vec3 xTangent = dFdx( vWorldPosition.xyz );"),i.push("vec3 yTangent = dFdy( vWorldPosition.xyz );"),i.push("vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),i.push("outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),pl=$.vec3(),fl=$.vec3(),vl=$.vec3(),gl=$.vec3(),ml=$.mat4(),_l=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f,v=pl;if(v[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,v[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,v[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(v[0]),e.snapPickCoordinateScale[1]=$.safeInv(v[1]),e.snapPickCoordinateScale[2]=$.safeInv(v[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var g=fl;if(l){var m=vl;$.transformPoint3(A,l,m),g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],p=Re(d,g,ml),(f=gl)[0]=n.eye[0]-g[0],f[1]=n.eye[1]-g[1],f[2]=n.eye[2]-g[2],e.snapPickOrigin[0]=g[0],e.snapPickOrigin[1]=g[1],e.snapPickOrigin[2]=g[2]}else p=d,f=n.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,v),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var _=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,_+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,_+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,_+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var y=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,y),this.setSectionPlanesStateUniforms(t),"edge"===e.snapMode?(a.indicesBuf.bind(),o.drawElements(o.LINES,a.indicesBuf.numItems,a.indicesBuf.itemType,0),a.indicesBuf.unbind()):o.drawArrays(o.POINTS,0,a.positionsBuf.numItems)}}},{key:"_allocate",value:function(){f(w(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0;e.pointsMaterial._state;var i=[];return i.push("#version 300 es"),i.push("// SnapBatchingDepthRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// SnapBatchingDepthRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),yl=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new ol(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new al(this._scene)),this._silhouetteRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new dl(this._scene,!1)),this._snapInitRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new _l(this._scene)),this._snapRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy()}}]),e}(),bl={};var wl=C((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e6;x(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]})),Bl=function(){function e(t){var i,s,r;x(this,e),console.info("Creating VBOBatchingLinesLayer"),this.layerIndex=t.layerIndex,this._renderers=(i=t.model.scene,s=i.id,(r=bl[s])||(r=new yl(i),bl[s]=r,r._compile(),i.on("compile",(function(){r._compile()})),i.on("destroyed",(function(){delete bl[s],r._destroy()}))),r),this.model=t.model,this._buffer=new wl(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new Zt({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:$.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=$.collapseAABB3(),this._portions=[],this._meshes=[],this._numVerts=0,this._aabb=$.collapseAABB3(),this.aabbDirty=!0,this._finalized=!1,t.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(t.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,t.origin&&(this._state.origin=$.vec3(t.origin))}return C(e,[{key:"aabb",get:function(){if(this.aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._meshes.length;e0)if(this._preCompressedPositionsExpected){var s=new Uint16Array(i.positions);e.positionsBuf=new It(t,t.ARRAY_BUFFER,s,i.positions.length,3,t.STATIC_DRAW)}else{var r=$o(new Float32Array(i.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new It(t,t.ARRAY_BUFFER,r,i.positions.length,3,t.STATIC_DRAW)}if(i.colors.length>0){var n=new Uint8Array(i.colors);e.colorsBuf=new It(t,t.ARRAY_BUFFER,n,i.colors.length,4,t.DYNAMIC_DRAW,!1)}if(i.colors.length>0){var o=i.colors.length/4,a=new Float32Array(o);e.flagsBuf=new It(t,t.ARRAY_BUFFER,a,a.length,1,t.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&i.offsets.length>0){var l=new Float32Array(i.offsets);e.offsetsBuf=new It(t,t.ARRAY_BUFFER,l,i.offsets.length,3,t.DYNAMIC_DRAW)}if(i.indices.length>0){var u=new Uint32Array(i.indices);e.indicesBuf=new It(t,t.ELEMENT_ARRAY_BUFFER,u,i.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Xe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,i,!0)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags()}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Xe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,i)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var i=2*e,s=4*this._portions[i],r=4*this._portions[i+1],n=this._scratchMemory.getUInt8Array(r),o=t[0],a=t[1],l=t[2],u=t[3],A=0;A3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var r,n,o=2*e,a=this._portions[o],l=this._portions[o+1],u=a,A=l,c=!!(t&Qe),h=!!(t&ze),d=!!(t&We),p=!!(t&Ke),f=!!(t&He),v=!!(t&Ve);r=!c||v||h||d&&!this.model.scene.highlightMaterial.glowThrough||p&&!this.model.scene.selectedMaterial.glowThrough?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,n=!c||v?oo.NOT_RENDERED:p?oo.SILHOUETTE_SELECTED:d?oo.SILHOUETTE_HIGHLIGHTED:h?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED;var g=c&&!v&&f?oo.PICK:oo.NOT_RENDERED,m=t&je?1:0;if(s){this._deferredFlagValues||(this._deferredFlagValues=new Float32Array(this._numVerts));for(var _=u,y=u+A;_0,i=[];return i.push("#version 300 es"),i.push("// Lines instancing color vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("in float flags;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;")),i.push("uniform vec4 lightAmbient;"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i._sectionPlanesState,r=s.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Lines instancing color 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"),i.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),r)for(n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;"),e=0,t=s.getNumAllocatedSectionPlanes();e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;"),e=0,t=s.getNumAllocatedSectionPlanes();e 0.0) { discard; }"),n.push("}")}return this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):n.push(" outColor = vColor;"),i.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}]),i}(),Cl=function(e){g(i,xl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Lines instancing silhouette vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;")),i.push("uniform vec4 color;"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("void main(void) {"),i.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),i.push("if (silhouetteFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Lines instancing silhouette fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = color;"),s.push("}"),s}}]),i}(),Ml=$.vec3(),Fl=$.vec3(),El=$.vec3();$.vec3();var kl=$.mat4(),Il=function(e){g(i,po);var t=_(i);function i(e){return x(this,i),t.call(this,e,!1,{instancing:!0})}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.canvas.gl,o=r.camera,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||o.viewMatrix;this._vaoCache.has(t)?n.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f=Ml;if(f[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,f[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,f[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(f[0]),e.snapPickCoordinateScale[1]=$.safeInv(f[1]),e.snapPickCoordinateScale[2]=$.safeInv(f[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var v=Fl;if(l){var g=$.transformPoint3(A,l,El);v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=u[0],v[1]+=u[1],v[2]+=u[2],p=Re(d,v,kl),e.snapPickOrigin[0]=v[0],e.snapPickOrigin[1]=v[1],e.snapPickOrigin[2]=v[2]}else p=d,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;n.uniform2fv(this.uVectorA,e.snapVectorA),n.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),n.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),n.uniform3fv(this._uCoordinateScaler,f),n.uniform1i(this._uRenderPass,i),n.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,m+=16),this._matricesUniformBlockBufferData.set(o.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,m+=16),n.bindBuffer(n.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),n.bufferData(n.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,n.DYNAMIC_DRAW),n.bindBufferBase(n.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var _=2/(Math.log(e.pickZFar+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,_),this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(a.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(a.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(a.modelMatrixCol2Buf),n.vertexAttribDivisor(this._aModelMatrixCol0.location,1),n.vertexAttribDivisor(this._aModelMatrixCol1.location,1),n.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags&&(this._aFlags.bindArrayBuffer(a.flagsBuf),n.vertexAttribDivisor(this._aFlags.location,1)),a.indicesBuf.bind(),n.drawElementsInstanced(n.LINES,a.indicesBuf.numItems,a.indicesBuf.itemType,0,a.numInstances),a.indicesBuf.unbind(),n.vertexAttribDivisor(this._aModelMatrixCol0.location,0),n.vertexAttribDivisor(this._aModelMatrixCol1.location,0),n.vertexAttribDivisor(this._aModelMatrixCol2.location,0),this._aFlags&&n.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&n.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){f(w(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// SnapInstancingDepthBufInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec4 pickColor;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vPickColor = pickColor;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Points instancing pick depth fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Dl=$.vec3(),Sl=$.vec3(),Tl=$.vec3();$.vec3();var Rl=$.mat4(),Ll=function(e){g(i,po);var t=_(i);function i(e){return x(this,i),t.call(this,e,!1,{instancing:!0})}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f=Dl;if(f[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,f[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,f[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(f[0]),e.snapPickCoordinateScale[1]=$.safeInv(f[1]),e.snapPickCoordinateScale[2]=$.safeInv(f[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var v=Sl;if(l){var g=$.transformPoint3(A,l,Tl);v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=u[0],v[1]+=u[1],v[2]+=u[2],p=Re(d,v,Rl),e.snapPickOrigin[0]=v[0],e.snapPickOrigin[1]=v[1],e.snapPickOrigin[2]=v[2]}else p=d,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,f),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,m+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,m+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var _=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,_),this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(a.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(a.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(a.modelMatrixCol2Buf),o.vertexAttribDivisor(this._aModelMatrixCol0.location,1),o.vertexAttribDivisor(this._aModelMatrixCol1.location,1),o.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags.bindArrayBuffer(a.flagsBuf),o.vertexAttribDivisor(this._aFlags.location,1),"edge"===e.snapMode?(a.indicesBuf.bind(),o.drawElementsInstanced(o.LINES,a.indicesBuf.numItems,a.indicesBuf.itemType,0,a.numInstances),a.indicesBuf.unbind()):o.drawArraysInstanced(o.POINTS,0,a.positionsBuf.numItems,a.numInstances),o.vertexAttribDivisor(this._aModelMatrixCol0.location,0),o.vertexAttribDivisor(this._aModelMatrixCol1.location,0),o.vertexAttribDivisor(this._aModelMatrixCol2.location,0),o.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&o.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){f(w(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// SnapInstancingDepthRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// SnapInstancingDepthRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Ul=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null)}},{key:"eagerCreateRenders",value:function(){this._snapInitRenderer||(this._snapInitRenderer=new Il(this._scene,!1)),this._snapRenderer||(this._snapRenderer=new Ll(this._scene))}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Pl(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Cl(this._scene)),this._silhouetteRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new Il(this._scene,!1)),this._snapInitRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new Ll(this._scene)),this._snapRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy()}}]),e}(),Ol={};var Nl=new Uint8Array(4),Ql=new Float32Array(1),Vl=new Float32Array(3),Hl=new Float32Array(4),jl=function(){function e(t){var i,s,r;x(this,e),console.info("VBOInstancingLinesLayer"),this.model=t.model,this.material=t.material,this.sortId="LinesInstancingLayer",this.layerIndex=t.layerIndex,this._renderers=(i=t.model.scene,s=i.id,(r=Ol[s])||(r=new Ul(i),Ol[s]=r,r._compile(),i.on("compile",(function(){r._compile()})),i.on("destroyed",(function(){delete Ol[s],r._destroy()}))),r),this._aabb=$.collapseAABB3(),this._state=new Zt({obb:$.OBB3(),numInstances:0,origin:null,geometry:t.geometry,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._meshes=[],this._aabb=$.collapseAABB3(),this.aabbDirty=!0,t.origin&&(this._state.origin=$.vec3(t.origin)),this._finalized=!1}return C(e,[{key:"aabb",get:function(){if(this.aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._meshes.length;e0){this._state.colorsBuf=new It(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,!1),this._colors=[]}if(r>0){this._state.flagsBuf=new It(e,e.ARRAY_BUFFER,new Float32Array(r),r,1,e.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){this._state.offsetsBuf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,!1),this._offsets=[]}if(i.colorsCompressed&&i.colorsCompressed.length>0){var n=new Uint8Array(i.colorsCompressed);t.colorsBuf=new It(e,e.ARRAY_BUFFER,n,n.length,4,e.STATIC_DRAW,!1)}if(i.positionsCompressed&&i.positionsCompressed.length>0){t.positionsBuf=new It(e,e.ARRAY_BUFFER,i.positionsCompressed,i.positionsCompressed.length,3,e.STATIC_DRAW,!1),t.positionsDecodeMatrix=$.mat4(i.positionsDecodeMatrix)}if(i.indices&&i.indices.length>0&&(t.indicesBuf=new It(e,e.ELEMENT_ARRAY_BUFFER,new Uint32Array(i.indices),i.indices.length,1,e.STATIC_DRAW),t.numIndices=i.indices.length),this._modelMatrixCol0.length>0){var o=!1;this._state.modelMatrixCol0Buf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,o),this._state.modelMatrixCol1Buf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,o),this._state.modelMatrixCol2Buf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,o),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Xe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,i)}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Xe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,i)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";Nl[0]=t[0],Nl[1]=t[1],Nl[2]=t[2],Nl[3]=t[3],this._state.colorsBuf.setData(Nl,4*e,4)}},{key:"setTransparent",value:function(e,t,i){i?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,i)}},{key:"_setFlags",value:function(e,t,i){if(!this._finalized)throw"Not finalized";var s=!!(t&Qe),r=!!(t&ze),n=!!(t&We),o=!!(t&Ke),a=!!(t&Xe),l=!!(t&He),u=!!(t&Ve),A=0;A|=!s||u||r||n&&!this.model.scene.highlightMaterial.glowThrough||o&&!this.model.scene.selectedMaterial.glowThrough?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,A|=(!s||u?oo.NOT_RENDERED:o?oo.SILHOUETTE_SELECTED:n?oo.SILHOUETTE_HIGHLIGHTED:r?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED)<<4,A|=(!s||u?oo.NOT_RENDERED:o?oo.EDGES_SELECTED:n?oo.EDGES_HIGHLIGHTED:r?oo.EDGES_XRAYED:a?i?oo.EDGES_COLOR_TRANSPARENT:oo.EDGES_COLOR_OPAQUE:oo.NOT_RENDERED)<<8,A|=(s&&!u&&l?oo.PICK:oo.NOT_RENDERED)<<12,A|=(t&je?255:0)<<16,Ql[0]=A,this._state.flagsBuf.setData(Ql,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Vl[0]=t[0],Vl[1]=t[1],Vl[2]=t[2],this._state.offsetsBuf.setData(Vl,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"setMatrix",value:function(e,t){if(!this._finalized)throw"Not finalized";var i=4*e;Hl[0]=t[0],Hl[1]=t[4],Hl[2]=t[8],Hl[3]=t[12],this._state.modelMatrixCol0Buf.setData(Hl,i),Hl[0]=t[1],Hl[1]=t[5],Hl[2]=t[9],Hl[3]=t[13],this._state.modelMatrixCol1Buf.setData(Hl,i),Hl[0]=t[2],Hl[1]=t[6],Hl[2]=t[10],Hl[3]=t[14],this._state.modelMatrixCol2Buf.setData(Hl,i)}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_SELECTED)}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawSnapInit",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.snapInitRenderer&&this._renderers.snapInitRenderer.drawLayer(t,this,oo.PICK)}},{key:"drawSnap",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.snapRenderer&&this._renderers.snapRenderer.drawLayer(t,this,oo.PICK)}},{key:"drawOcclusion",value:function(e,t){}},{key:"drawShadow",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){}},{key:"drawPickDepths",value:function(e,t){}},{key:"drawPickNormals",value:function(e,t){}},{key:"destroy",value:function(){var e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}]),e}(),Gl=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,i=e.state,s=e.frameCtx,r=e.incrementDrawState;t.drawArrays(t.POINTS,0,i.positionsBuf.numItems),r&&s.drawArrays++}}]),i}(),zl=function(e){g(i,Gl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial,s=[];return s.push("#version 300 es"),s.push("// Points batching color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),i.filterIntensity&&s.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),i.filterIntensity&&(s.push("float intensity = float(color.a) / 255.0;"),s.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {")),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),i.filterIntensity&&s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points batching color fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return s.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),i}(),Wl=function(e){g(i,Gl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 color;"),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i._sectionPlanesState,r=s.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching silhouette vertex 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"),i.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),r)for(n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;"),e=0,t=s.getNumAllocatedSectionPlanes();e 1.0) {"),n.push(" discard;"),n.push(" }")),r){for(n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;"),e=0,t=s.getNumAllocatedSectionPlanes();e 0.0) { discard; }"),n.push("}")}return i.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}]),i}(),Kl=function(e){g(i,Gl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points batching pick mesh vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = remapClipPos(clipPos);"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("gl_PointSize += 10.0;"),s.push(" }"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points batching pick mesh vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vPickColor; "),s.push("}"),s}}]),i}(),Xl=function(e){g(i,Gl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points batched pick depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = remapClipPos(clipPos);"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("gl_PointSize += 10.0;"),s.push(" }"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points batched pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform float pickZNear;"),s.push("uniform float pickZFar;"),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),s.push(" outColor = packDepth(zNormalizedDepth); "),s.push("}"),s}}]),i}(),Jl=function(e){g(i,Gl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points batching occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push(" gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push(" }"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points batching occlusion fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}}]),i}(),Yl=$.vec3(),Zl=$.vec3(),ql=$.vec3(),$l=$.vec3(),eu=$.mat4(),tu=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f,v=Yl;if(v[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,v[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,v[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(v[0]),e.snapPickCoordinateScale[1]=$.safeInv(v[1]),e.snapPickCoordinateScale[2]=$.safeInv(v[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var g=Zl;if(l){var m=ql;$.transformPoint3(A,l,m),g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],p=Re(d,g,eu),(f=$l)[0]=n.eye[0]-g[0],f[1]=n.eye[1]-g[1],f[2]=n.eye[2]-g[2],e.snapPickOrigin[0]=g[0],e.snapPickOrigin[1]=g[1],e.snapPickOrigin[2]=g[2]}else p=d,f=n.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,v),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var _=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,_+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,_+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,_+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var y=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,y),this.setSectionPlanesStateUniforms(t),o.drawArrays(o.POINTS,0,a.positionsBuf.numItems)}}},{key:"_allocate",value:function(){f(w(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// VBOBatchingPointsSnapInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec4 pickColor;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vPickColor = pickColor;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// VBOBatchingPointsSnapInitRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),i.push("outNormal = ivec4(1.0, 1.0, 1.0, 1.0);"),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),iu=$.vec3(),su=$.vec3(),ru=$.vec3(),nu=$.vec3(),ou=$.mat4(),au=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f,v=iu;if(v[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,v[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,v[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(v[0]),e.snapPickCoordinateScale[1]=$.safeInv(v[1]),e.snapPickCoordinateScale[2]=$.safeInv(v[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var g=su;if(l){var m=ru;$.transformPoint3(A,l,m),g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],p=Re(d,g,ou),(f=nu)[0]=n.eye[0]-g[0],f[1]=n.eye[1]-g[1],f[2]=n.eye[2]-g[2],e.snapPickOrigin[0]=g[0],e.snapPickOrigin[1]=g[1],e.snapPickOrigin[2]=g[2]}else p=d,f=n.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,v),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var _=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,_+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,_+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,_+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var y=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,y),this.setSectionPlanesStateUniforms(t),o.drawArrays(o.POINTS,0,a.positionsBuf.numItems)}}},{key:"_allocate",value:function(){f(w(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0;e.pointsMaterial._state;var i=[];return i.push("#version 300 es"),i.push("// VBOBatchingPointsSnapRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// VBOBatchingPointsSnapRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),lu=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new zl(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Wl(this._scene)),this._silhouetteRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Kl(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Xl(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Jl(this._scene)),this._occlusionRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new tu(this._scene,!1)),this._snapInitRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new au(this._scene)),this._snapRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy()}}]),e}(),uu={};var Au=C((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e6;x(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]})),cu=function(){function e(t){x(this,e),console.info("Creating VBOBatchingPointsLayer"),this.model=t.model,this.sortId="PointsBatchingLayer",this.layerIndex=t.layerIndex,this._renderers=function(e){var t=e.id,i=uu[t];return i||(i=new lu(e),uu[t]=i,i._compile(),e.on("compile",(function(){i._compile()})),e.on("destroyed",(function(){delete uu[t],i._destroy()}))),i}(t.model.scene),this._buffer=new Au(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new Zt({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:$.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=$.collapseAABB3(),this._portions=[],this._meshes=[],this._aabb=$.collapseAABB3(),this.aabbDirty=!0,this._finalized=!1,t.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(t.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,t.origin&&(this._state.origin=$.vec3(t.origin))}return C(e,[{key:"aabb",get:function(){if(this.aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._meshes.length;e0)if(this._preCompressedPositionsExpected){var s=new Uint16Array(i.positions);e.positionsBuf=new It(t,t.ARRAY_BUFFER,s,i.positions.length,3,t.STATIC_DRAW)}else{var r=$o(new Float32Array(i.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new It(t,t.ARRAY_BUFFER,r,i.positions.length,3,t.STATIC_DRAW)}if(i.colors.length>0){var n=new Uint8Array(i.colors);e.colorsBuf=new It(t,t.ARRAY_BUFFER,n,i.colors.length,4,t.STATIC_DRAW,!1)}if(i.positions.length>0){var o=i.positions.length/3,a=new Float32Array(o);e.flagsBuf=new It(t,t.ARRAY_BUFFER,a,a.length,1,t.DYNAMIC_DRAW,!1)}if(i.pickColors.length>0){var l=new Uint8Array(i.pickColors);e.pickColorsBuf=new It(t,t.ARRAY_BUFFER,l,i.pickColors.length,4,t.STATIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&i.offsets.length>0){var u=new Float32Array(i.offsets);e.offsetsBuf=new It(t,t.ARRAY_BUFFER,u,i.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,i)}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized"}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var i=2*e,s=4*this._portions[i],r=4*this._portions[i+1],n=this._scratchMemory.getUInt8Array(r),o=t[0],a=t[1],l=t[2],u=0;u0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points instancing color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),i.filterIntensity&&s.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),i.filterIntensity&&(s.push("float intensity = float(color.a) / 255.0;"),s.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {")),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),i.filterIntensity&&s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing color fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return s.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),i}(),pu=function(e){g(i,hu);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,s){f(w(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 silhouetteColor;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),s.push("gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing silhouette fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vColor;"),s.push("}"),s}}]),i}(),fu=function(e){g(i,hu);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points instancing pick mesh vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("gl_Position = remapClipPos(clipPos);"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing pick mesh fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vPickColor; "),s.push("}"),s}}]),i}(),vu=function(e){g(i,hu);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points instancing pick depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("gl_Position = remapClipPos(clipPos);"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = remapClipPos(clipPos);"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform float pickZNear;"),s.push("uniform float pickZFar;"),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),s.push(" outColor = packDepth(zNormalizedDepth); "),s.push("}"),s}}]),i}(),gu=function(e){g(i,hu);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points instancing occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing occlusion vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),i}(),mu=function(e){g(i,hu);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points instancing depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i._sectionPlanesState,r=s.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing depth vertex 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"),i.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),r)for(n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;"),e=0,t=s.getNumAllocatedSectionPlanes();e 1.0) {"),n.push(" discard;"),n.push(" }")),r){for(n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;"),e=0,t=s.getNumAllocatedSectionPlanes();e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),i.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}]),i}(),_u=function(e){g(i,hu);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry shadow drawing vertex shader"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 color;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform mat4 shadowViewMatrix;"),i.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(i),i.push("uniform float pointSize;"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("bool visible = (colorFlag > 0);"),i.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),i.push("if (!visible || transparent) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push(" gl_Position = shadowProjMatrix * viewPosition;"),i.push("}"),i.push("gl_PointSize = pointSize;"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Instancing geometry depth drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r 1.0) {"),s.push(" discard;"),s.push(" }"),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),s.push("}"),s}}]),i}(),yu=$.vec3(),bu=$.vec3(),wu=$.vec3();$.vec3();var Bu=$.mat4(),xu=function(e){g(i,po);var t=_(i);function i(e){return x(this,i),t.call(this,e,!1,{instancing:!0})}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.canvas.gl,o=r.camera,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||o.viewMatrix;this._vaoCache.has(t)?n.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f=yu;if(f[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,f[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,f[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(f[0]),e.snapPickCoordinateScale[1]=$.safeInv(f[1]),e.snapPickCoordinateScale[2]=$.safeInv(f[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var v=bu;if(l){var g=$.transformPoint3(A,l,wu);v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=u[0],v[1]+=u[1],v[2]+=u[2],p=Re(d,v,Bu),e.snapPickOrigin[0]=v[0],e.snapPickOrigin[1]=v[1],e.snapPickOrigin[2]=v[2]}else p=d,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;n.uniform2fv(this.uVectorA,e.snapVectorA),n.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),n.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),n.uniform3fv(this._uCoordinateScaler,f),n.uniform1i(this._uRenderPass,i),n.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,m+=16),this._matricesUniformBlockBufferData.set(o.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,m+=16),n.bindBuffer(n.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),n.bufferData(n.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,n.DYNAMIC_DRAW),n.bindBufferBase(n.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var _=2/(Math.log(e.pickZFar+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,_),this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(a.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(a.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(a.modelMatrixCol2Buf),n.vertexAttribDivisor(this._aModelMatrixCol0.location,1),n.vertexAttribDivisor(this._aModelMatrixCol1.location,1),n.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags&&(this._aFlags.bindArrayBuffer(a.flagsBuf),n.vertexAttribDivisor(this._aFlags.location,1)),n.drawArraysInstanced(n.POINTS,0,a.positionsBuf.numItems,a.numInstances),n.vertexAttribDivisor(this._aModelMatrixCol0.location,0),n.vertexAttribDivisor(this._aModelMatrixCol1.location,0),n.vertexAttribDivisor(this._aModelMatrixCol2.location,0),this._aFlags&&n.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&n.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){f(w(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// SnapInstancingDepthBufInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec4 pickColor;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vPickColor = pickColor;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Points instancing pick depth fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),i.push("outNormal = ivec4(1.0, 1.0, 1.0, 1.0);"),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Pu=$.vec3(),Cu=$.vec3(),Mu=$.vec3();$.vec3();var Fu=$.mat4(),Eu=function(e){g(i,po);var t=_(i);function i(e){return x(this,i),t.call(this,e,!1,{instancing:!0})}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f=Pu;if(f[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,f[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,f[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(f[0]),e.snapPickCoordinateScale[1]=$.safeInv(f[1]),e.snapPickCoordinateScale[2]=$.safeInv(f[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var v=Cu;if(l){var g=$.transformPoint3(A,l,Mu);v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=u[0],v[1]+=u[1],v[2]+=u[2],p=Re(d,v,Fu),e.snapPickOrigin[0]=v[0],e.snapPickOrigin[1]=v[1],e.snapPickOrigin[2]=v[2]}else p=d,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,f),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,m+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,m+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var _=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,_),this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(a.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(a.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(a.modelMatrixCol2Buf),o.vertexAttribDivisor(this._aModelMatrixCol0.location,1),o.vertexAttribDivisor(this._aModelMatrixCol1.location,1),o.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags.bindArrayBuffer(a.flagsBuf),o.vertexAttribDivisor(this._aFlags.location,1),o.drawArraysInstanced(o.POINTS,0,a.positionsBuf.numItems,a.numInstances),o.vertexAttribDivisor(this._aModelMatrixCol0.location,0),o.vertexAttribDivisor(this._aModelMatrixCol1.location,0),o.vertexAttribDivisor(this._aModelMatrixCol2.location,0),o.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&o.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){f(w(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// SnapInstancingDepthRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// SnapInstancingDepthRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),ku=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new du(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new pu(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new mu(this._scene)),this._depthRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new fu(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new vu(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new gu(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new _u(this._scene)),this._shadowRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new xu(this._scene,!1)),this._snapInitRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new Eu(this._scene)),this._snapRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy()}}]),e}(),Iu={};var Du=new Uint8Array(4),Su=new Float32Array(1),Tu=new Float32Array(3),Ru=new Float32Array(4),Lu=function(){function e(t){var i,s,r;x(this,e),console.info("VBOInstancingPointsLayer"),this.model=t.model,this.material=t.material,this.sortId="PointsInstancingLayer",this.layerIndex=t.layerIndex,this._renderers=(i=t.model.scene,s=i.id,(r=Iu[s])||(r=new ku(i),Iu[s]=r,r._compile(),i.on("compile",(function(){r._compile()})),i.on("destroyed",(function(){delete Iu[s],r._destroy()}))),r),this._aabb=$.collapseAABB3(),this._state=new Zt({obb:$.OBB3(),numInstances:0,origin:t.origin?$.vec3(t.origin):null,geometry:t.geometry,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._meshes=[],this._aabb=$.collapseAABB3(),this.aabbDirty=!0,this._finalized=!1}return C(e,[{key:"aabb",get:function(){if(this.aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._meshes.length;e0){i.flagsBuf=new It(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){i.offsetsBuf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,!1),this._offsets=[]}if(s.positionsCompressed&&s.positionsCompressed.length>0){i.positionsBuf=new It(e,e.ARRAY_BUFFER,s.positionsCompressed,s.positionsCompressed.length,3,e.STATIC_DRAW,!1),i.positionsDecodeMatrix=$.mat4(s.positionsDecodeMatrix)}if(s.colorsCompressed&&s.colorsCompressed.length>0){var r=new Uint8Array(s.colorsCompressed);i.colorsBuf=new It(e,e.ARRAY_BUFFER,r,r.length,4,e.STATIC_DRAW,!1)}if(this._modelMatrixCol0.length>0){var n=!1;i.modelMatrixCol0Buf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,n),i.modelMatrixCol1Buf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,n),i.modelMatrixCol2Buf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,n),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){i.pickColorsBuf=new It(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,!1),this._pickColors=[]}i.geometry=null,this._finalized=!0}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Xe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,i)}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Xe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,i)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";Du[0]=t[0],Du[1]=t[1],Du[2]=t[2],this._state.colorsBuf.setData(Du,3*e)}},{key:"setTransparent",value:function(e,t,i){i?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,i)}},{key:"_setFlags",value:function(e,t,i){if(!this._finalized)throw"Not finalized";var s=!!(t&Qe),r=!!(t&ze),n=!!(t&We),o=!!(t&Ke),a=!!(t&Xe),l=!!(t&He),u=!!(t&Ve),A=0;A|=!s||u||r||n&&!this.model.scene.highlightMaterial.glowThrough||o&&!this.model.scene.selectedMaterial.glowThrough?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,A|=(!s||u?oo.NOT_RENDERED:o?oo.SILHOUETTE_SELECTED:n?oo.SILHOUETTE_HIGHLIGHTED:r?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED)<<4,A|=(!s||u?oo.NOT_RENDERED:o?oo.EDGES_SELECTED:n?oo.EDGES_HIGHLIGHTED:r?oo.EDGES_XRAYED:a?i?oo.EDGES_COLOR_TRANSPARENT:oo.EDGES_COLOR_OPAQUE:oo.NOT_RENDERED)<<8,A|=(s&&!u&&l?oo.PICK:oo.NOT_RENDERED)<<12,A|=(t&je?255:0)<<16,Su[0]=A,this._state.flagsBuf.setData(Su,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Tu[0]=t[0],Tu[1]=t[1],Tu[2]=t[2],this._state.offsetsBuf.setData(Tu,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"setMatrix",value:function(e,t){if(!this._finalized)throw"Not finalized";var i=4*e;Ru[0]=t[0],Ru[1]=t[4],Ru[2]=t[8],Ru[3]=t[12],this._state.modelMatrixCol0Buf.setData(Ru,i),Ru[0]=t[1],Ru[1]=t[5],Ru[2]=t[9],Ru[3]=t[13],this._state.modelMatrixCol1Buf.setData(Ru,i),Ru[0]=t[2],Ru[1]=t[6],Ru[2]=t[10],Ru[3]=t[14],this._state.modelMatrixCol2Buf.setData(Ru,i)}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_SELECTED)}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.occlusionRenderer&&this._renderers.occlusionRenderer.drawLayer(t,this,oo.COLOR_OPAQUE)}},{key:"drawShadow",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.pickMeshRenderer&&this._renderers.pickMeshRenderer.drawLayer(t,this,oo.PICK)}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.pickDepthRenderer&&this._renderers.pickDepthRenderer.drawLayer(t,this,oo.PICK)}},{key:"drawPickNormals",value:function(e,t){}},{key:"drawSnapInit",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.snapInitRenderer&&this._renderers.snapInitRenderer.drawLayer(t,this,oo.PICK)}},{key:"drawSnap",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.snapRenderer&&this._renderers.snapRenderer.drawLayer(t,this,oo.PICK)}},{key:"destroy",value:function(){var e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}]),e}(),Uu=$.vec3(),Ou=$.vec3(),Nu=$.mat4(),Qu=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=this._scene,r=s.camera,n=t.model,o=s.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=n.position,c=n.rotationMatrix,h=n.rotationMatrixConjugate,d=r.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,a)),l.bindCommonTextures(this._program,this.uPerObjectDecodeMatrix,this._uPerVertexPosition,this.uPerObjectColorAndFlags,this._uPerObjectMatrix);var f=0!==u[0]||0!==u[1]||0!==u[2],v=0!==A[0]||0!==A[1]||0!==A[2];if(f||v){var g=Uu;if(f){var m=$.transformPoint3(c,u,Ou);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=A[0],g[1]+=A[1],g[2]+=A[2],p=Re(d,g,Nu)}else p=d;if(o.uniformMatrix4fv(this._uSceneModelMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,p),o.uniformMatrix4fv(this._uProjMatrix,!1,r.projMatrix),o.uniform1i(this._uRenderPass,i),s.logarithmicDepthBufferEnabled){var _=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,_)}var y=s._sectionPlanesState.getNumAllocatedSectionPlanes(),b=s._sectionPlanesState.sectionPlanes.length;if(y>0)for(var w=s._sectionPlanesState.sectionPlanes,B=t.layerIndex*b,x=n.renderFlags,P=0;P0&&(l.bindLineIndicesTextures(this._program,this._uPerLineObject,this._uPerLineIndices,8),o.drawArrays(o.LINES,0,a.numIndices8Bits)),a.numIndices16Bits>0&&(l.bindLineIndicesTextures(this._program,this._uPerLineObject,this._uPerLineIndices,16),o.drawArrays(o.LINES,0,a.numIndices16Bits)),a.numIndices32Bits>0&&(l.bindLineIndicesTextures(this._program,this._uPerLineObject,this._uPerLineIndices,32),o.drawArrays(o.LINES,0,a.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)return this.errors=this._program.errors,void console.error(this.errors);var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// LinesDataTextureColorRenderer"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled,i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uPerObjectDecodeMatrix;"),i.push("uniform highp sampler2D uPerObjectMatrix;"),i.push("uniform lowp usampler2D uPerObjectColorAndFlags;"),i.push("uniform mediump usampler2D uPerVertexPosition;"),i.push("uniform highp usampler2D uPerLineIndices;"),i.push("uniform mediump usampler2D uPerLineObject;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push(" int lineIndex = gl_VertexID / 2;"),i.push(" int h_packed_object_id_index = (lineIndex >> 3) & 4095;"),i.push(" int v_packed_object_id_index = (lineIndex >> 3) >> 12;"),i.push(" int objectIndex = int(texelFetch(uPerLineObject, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push(" ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push(" uvec4 flags = texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push(" uvec4 flags2 = texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push(" if (int(flags.x) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push(" } else {"),i.push(" ivec4 packedVertexBase = ivec4(texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push(" ivec4 packedLineIndexBaseOffset = ivec4(texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),i.push(" int lineIndexBaseOffset = (packedLineIndexBaseOffset.r << 24) + (packedLineIndexBaseOffset.g << 16) + (packedLineIndexBaseOffset.b << 8) + packedLineIndexBaseOffset.a;"),i.push(" int h_index = (lineIndex - lineIndexBaseOffset) & 4095;"),i.push(" int v_index = (lineIndex - lineIndexBaseOffset) >> 12;"),i.push(" ivec3 vertexIndices = ivec3(texelFetch(uPerLineIndices, ivec2(h_index, v_index), 0));"),i.push(" ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push(" int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),i.push(" int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),i.push(" mat4 objectInstanceMatrix = mat4 (texelFetch (uPerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uPerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uPerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uPerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push(" mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uPerObjectDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uPerObjectDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uPerObjectDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uPerObjectDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push(" uvec4 flags = texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push(" uvec4 flags2 = texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push(" vec3 position = vec3(texelFetch(uPerVertexPosition, ivec2(indexPositionH, indexPositionV), 0));"),i.push(" uvec4 color = texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push(" if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push(" };"),i.push(" vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2.r;")),i.push(" vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push(" vFragDepth = 1.0 + clipPos.w;"),i.push(" isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push(" gl_Position = clipPos;"),i.push(" vec4 rgb = vec4(color.rgba);"),i.push(" vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// LinesDataTextureColorRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("flat in uint vFlags2;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r 0u;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { "),s.push(" discard;"),s.push(" }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vColor;"),s.push("}"),s}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Vu=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null)}},{key:"eagerCreateRenders",value:function(){}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Qu(this._scene,!1)),this._colorRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy()}}]),e}(),Hu={};var ju=C((function e(){x(this,e),this.positionsCompressed=[],this.lenPositionsCompressed=0,this.indices8Bits=[],this.lenIndices8Bits=0,this.indices16Bits=[],this.lenIndices16Bits=0,this.indices32Bits=[],this.lenIndices32Bits=0,this.perObjectColors=[],this.perObjectPickColors=[],this.perObjectSolid=[],this.perObjectOffsets=[],this.perObjectPositionsDecodeMatrices=[],this.perObjectInstancePositioningMatrices=[],this.perObjectVertexBases=[],this.perObjectIndexBaseOffsets=[],this.perLineNumberPortionId8Bits=[],this.perLineNumberPortionId16Bits=[],this.perLineNumberPortionId32Bits=[]})),Gu=function(){function e(){x(this,e),this.texturePerObjectColorsAndFlags=null,this.texturePerObjectOffsets=null,this.texturePerObjectInstanceMatrices=null,this.texturePerObjectPositionsDecodeMatrix=null,this.texturePerVertexIdCoordinates=null,this.texturePerLineIdPortionIds8Bits=null,this.texturePerLineIdPortionIds16Bits=null,this.texturePerLineIdPortionIds32Bits=null,this.texturePerLineIdIndices8Bits=null,this.texturePerLineIdIndices16Bits=null,this.texturePerLineIdIndices32Bits=null,this.textureModelMatrices=null}return C(e,[{key:"finalize",value:function(){this.indicesPerBitnessTextures={8:this.texturePerLineIdIndices8Bits,16:this.texturePerLineIdIndices16Bits,32:this.texturePerLineIdIndices32Bits},this.indicesPortionIdsPerBitnessTextures={8:this.texturePerLineIdPortionIds8Bits,16:this.texturePerLineIdPortionIds16Bits,32:this.texturePerLineIdPortionIds32Bits}}},{key:"bindCommonTextures",value:function(e,t,i,s,r){this.texturePerObjectPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,i,2),this.texturePerObjectColorsAndFlags.bindTexture(e,s,3),this.texturePerObjectInstanceMatrices.bindTexture(e,r,4)}},{key:"bindLineIndicesTextures",value:function(e,t,i,s){this.indicesPortionIdsPerBitnessTextures[s].bindTexture(e,t,5),this.indicesPerBitnessTextures[s].bindTexture(e,i,6)}}]),e}(),zu=function(){function e(t,i,s,r){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;x(this,e),this._gl=t,this._texture=i,this._textureWidth=s,this._textureHeight=r,this._textureData=n}return C(e,[{key:"bindTexture",value:function(e,t,i){return e.bindTexture(t,this,i)}},{key:"bind",value:function(e){return this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,this._texture),!0}},{key:"unbind",value:function(e){}}]),e}(),Wu={sizeDataColorsAndFlags:0,sizeDataPositionDecodeMatrices:0,sizeDataTextureOffsets:0,sizeDataTexturePositions:0,sizeDataTextureIndices:0,sizeDataTexturePortionIds:0,numberOfGeometries:0,numberOfPortions:0,numberOfLayers:0,numberOfTextures:0,totalLines:0,totalLines8Bits:0,totalLines16Bits:0,totalLines32Bits:0,cannotCreatePortion:{because10BitsObjectId:0,becauseTextureSize:0},overheadSizeAlignementIndices:0,overheadSizeAlignementEdgeIndices:0};window.printDataTextureRamStats=function(){console.log(JSON.stringify(Wu,null,4));var e=0;Object.keys(Wu).forEach((function(t){t.startsWith("size")&&(e+=Wu[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/Wu.totalLines).toFixed(2)));var t={};Object.keys(Wu).forEach((function(i){i.startsWith("size")&&(t[i]="".concat((Wu[i]/e*100).toFixed(2)," % of total"))})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};var Ku=function(){function e(){x(this,e)}return C(e,[{key:"disableBindedTextureFiltering",value:function(e){e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}},{key:"generateTextureForColorsAndFlags",value:function(e,t,i,s,r){var n=t.length;this.numPortions=n;var o=4096,a=Math.ceil(n/512);if(0===a)throw"texture height===0";var l=new Uint8Array(16384*a);Wu.sizeDataColorsAndFlags+=l.byteLength,Wu.numberOfTextures++;for(var u=0;u>24&255,s[u]>>16&255,s[u]>>8&255,255&s[u]],32*u+16),l.set([r[u]>>24&255,r[u]>>16&255,r[u]>>8&255,255&r[u]],32*u+20);var A=e.createTexture();return e.bindTexture(e.TEXTURE_2D,A),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8UI,o,a),e.texSubImage2D(e.TEXTURE_2D,0,0,0,o,a,e.RGBA_INTEGER,e.UNSIGNED_BYTE,l,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new zu(e,A,o,a,l)}},{key:"generateTextureForObjectOffsets",value:function(e,t){var i=512,s=Math.ceil(t/i);if(0===s)throw"texture height===0";var r=new Float32Array(1536*s).fill(0);Wu.sizeDataTextureOffsets+=r.byteLength,Wu.numberOfTextures++;var n=e.createTexture();return e.bindTexture(e.TEXTURE_2D,n),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32F,i,s),e.texSubImage2D(e.TEXTURE_2D,0,0,0,i,s,e.RGB,e.FLOAT,r,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new zu(e,n,i,s,r)}},{key:"generateTextureForInstancingMatrices",value:function(e,t){var i=t.length;if(0===i)throw"num instance matrices===0";var s=2048,r=Math.ceil(i/512),n=new Float32Array(8192*r);Wu.numberOfTextures++;for(var o=0;o65536&&Wu.cannotCreatePortion.because10BitsObjectId++;var i=this._numPortions+t<=65536,s=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(0):"".concat(e.id,"#").concat(0);if(!this._bucketGeometries[s]){var r=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits),n=0,o=0;e.buckets.forEach((function(e){n+=e.positionsCompressed.length/3,o+=e.indices.length/2})),(this._state.numVertices+n>4096*Ju||r+o>4096*Ju)&&Wu.cannotCreatePortion.becauseTextureSize++,i&&(i=this._state.numVertices+n<=4096*Ju&&r+o<=4096*Ju)}return i}},{key:"createPortion",value:function(e,t){var i=this;if(this._finalized)throw"Already finalized";var s=[];t.buckets.forEach((function(e,r){var n=void 0!==t.geometryId&&null!==t.geometryId?"".concat(t.geometryId,"#").concat(r):"".concat(t.id,"#").concat(r),o=i._bucketGeometries[n];o||(o=i._createBucketGeometry(t,e),i._bucketGeometries[n]=o);var a=i._createSubPortion(t,o,e);s.push(a)}));var r=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(s),this.model.numPortions++,this._meshes.push(e),r}},{key:"_createBucketGeometry",value:function(e,t){if(t.indices){var i=8*Math.ceil(t.indices.length/2/8)*2;Wu.overheadSizeAlignementIndices+=2*(i-t.indices.length);var s=new Uint32Array(i);s.fill(0),s.set(t.indices),t.indices=s}var r=t.positionsCompressed,n=t.indices,o=this._buffer;o.positionsCompressed.push(r);var a,l=o.lenPositionsCompressed/3,u=r.length/3;o.lenPositionsCompressed+=r.length;var A,c=0;n&&(c=n.length/2,u<=256?(A=o.indices8Bits,a=o.lenIndices8Bits/2,o.lenIndices8Bits+=n.length):u<=65536?(A=o.indices16Bits,a=o.lenIndices16Bits/2,o.lenIndices16Bits+=n.length):(A=o.indices32Bits,a=o.lenIndices32Bits/2,o.lenIndices32Bits+=n.length),A.push(n));return this._state.numVertices+=u,Wu.numberOfGeometries++,{vertexBase:l,numVertices:u,numLines:c,indicesBase:a}}},{key:"_createSubPortion",value:function(e,t){var i,s=e.color,r=e.colors,n=e.opacity,o=e.meshMatrix,a=e.pickColor,l=this._buffer,u=this._state;l.perObjectPositionsDecodeMatrices.push(e.positionsDecodeMatrix),l.perObjectInstancePositioningMatrices.push(o||eA),l.perObjectSolid.push(!!e.solid),r?l.perObjectColors.push([255*r[0],255*r[1],255*r[2],255]):s&&l.perObjectColors.push([s[0],s[1],s[2],n]),l.perObjectPickColors.push(a),l.perObjectVertexBases.push(t.vertexBase),i=t.numVertices<=256?u.numIndices8Bits:t.numVertices<=65536?u.numIndices16Bits:u.numIndices32Bits,l.perObjectIndexBaseOffsets.push(i/2-t.indicesBase);var A=this._subPortions.length;if(t.numLines>0){var c,h=2*t.numLines;t.numVertices<=256?(c=l.perLineNumberPortionId8Bits,u.numIndices8Bits+=h,Wu.totalLines8Bits+=t.numLines):t.numVertices<=65536?(c=l.perLineNumberPortionId16Bits,u.numIndices16Bits+=h,Wu.totalLines16Bits+=t.numLines):(c=l.perLineNumberPortionId32Bits,u.numIndices32Bits+=h,Wu.totalLines32Bits+=t.numLines),Wu.totalLines+=t.numLines;for(var d=0;d0&&(i.texturePerLineIdIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitIndices(s,r.indices8Bits,r.lenIndices8Bits)),r.lenIndices16Bits>0&&(i.texturePerLineIdIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitIndices(s,r.indices16Bits,r.lenIndices16Bits)),r.lenIndices32Bits>0&&(i.texturePerLineIdIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitIndices(s,r.indices32Bits,r.lenIndices32Bits)),i.finalize(),this._buffer=null,this._bucketGeometries={},this._finalized=!0,this._deferredSetFlagsDirty=!1,this._onSceneRendering=this.model.scene.on("rendering",(function(){e._deferredSetFlagsDirty&&e._uploadDeferredFlags(),e._numUpdatesInFrame=0}))}}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,i,true),this._setFlags2(e,t,true)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags(),this._setDeferredFlags2()}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags2(e,t)}},{key:"_beginDeferredFlags",value:function(){this._deferredSetFlagsActive=!0}},{key:"_uploadDeferredFlags",value:function(){if(this._deferredSetFlagsActive=!1,this._deferredSetFlagsDirty){this._deferredSetFlagsDirty=!1;var e=this.model.scene.canvas.gl,t=this._dataTextureState;e.bindTexture(e.TEXTURE_2D,t.texturePerObjectColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectColorsAndFlags._textureWidth,t.texturePerObjectColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectColorsAndFlags._textureData)}}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions+=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions-=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){for(var i=this._portionToSubPortionsMap[e],s=0,r=i.length;s=10&&this._beginDeferredFlags(),s.bindTexture(s.TEXTURE_2D,i.texturePerObjectColorsAndFlags._texture),s.texSubImage2D(s.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,s.RGBA_INTEGER,s.UNSIGNED_BYTE,Zu))}},{key:"setTransparent",value:function(e,t,i){i?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,i)}},{key:"_setFlags",value:function(e,t,i){for(var s=arguments.length>3&&void 0!==arguments[3]&&arguments[3],r=this._portionToSubPortionsMap[e],n=0,o=r.length;n3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var r,n,o=!!(t&Qe),a=!!(t&ze),l=!!(t&We),u=!!(t&Ke),A=!!(t&He),c=!!(t&Ve);r=!o||c||a?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,n=!o||c?oo.NOT_RENDERED:u?oo.SILHOUETTE_SELECTED:l?oo.SILHOUETTE_HIGHLIGHTED:a?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED;var h=o&&!c&&A?oo.PICK:oo.NOT_RENDERED,d=this._dataTextureState,p=this.model.scene.canvas.gl;Zu[0]=r,Zu[1]=n,Zu[3]=h,d.texturePerObjectColorsAndFlags._textureData.set(Zu,32*e+8),this._deferredSetFlagsActive||s?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),p.bindTexture(p.TEXTURE_2D,d.texturePerObjectColorsAndFlags._texture),p.texSubImage2D(p.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,p.RGBA_INTEGER,p.UNSIGNED_BYTE,Zu))}},{key:"_setDeferredFlags",value:function(){}},{key:"_setFlags2",value:function(e,t){for(var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=this._portionToSubPortionsMap[e],r=0,n=s.length;r2&&void 0!==arguments[2]&&arguments[2];if(!this._finalized)throw"Not finalized";var s=t&je?255:0,r=this._dataTextureState,n=this.model.scene.canvas.gl;Zu[0]=s,Zu[1]=0,Zu[2]=1,Zu[3]=2,r.texturePerObjectColorsAndFlags._textureData.set(Zu,32*e+12),this._deferredSetFlagsActive||i?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),n.bindTexture(n.TEXTURE_2D,r.texturePerObjectColorsAndFlags._texture),n.texSubImage2D(n.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,n.RGBA_INTEGER,n.UNSIGNED_BYTE,Zu))}},{key:"_setDeferredFlags2",value:function(){}},{key:"setOffset",value:function(e,t){for(var i=this._portionToSubPortionsMap[e],s=0,r=i.length;s=10&&this._beginDeferredFlags(),s.bindTexture(s.TEXTURE_2D,i.texturePerObjectOffsets._texture),s.texSubImage2D(s.TEXTURE_2D,0,0,e,1,1,s.RGB,s.FLOAT,qu))}},{key:"setMatrix",value:function(e,t){for(var i=this._portionToSubPortionsMap[e],s=0,r=i.length;s=10&&this._beginDeferredFlags(),s.bindTexture(s.TEXTURE_2D,i.texturePerObjectInstanceMatrices._texture),s.texSubImage2D(s.TEXTURE_2D,0,e%512*4,Math.floor(e/512),4,1,s.RGBA,s.FLOAT,Yu))}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){}},{key:"drawSilhouetteHighlighted",value:function(e,t){}},{key:"drawSilhouetteSelected",value:function(e,t){}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){}},{key:"drawShadow",value:function(e,t){}},{key:"setPickMatrices",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){}},{key:"drawPickDepths",value:function(e,t){}},{key:"drawSnapInit",value:function(e,t){}},{key:"drawSnap",value:function(e,t){}},{key:"drawPickNormals",value:function(e,t){}},{key:"destroy",value:function(){if(!this._destroyed){var e=this._state;this.model.scene.off(this._onSceneRendering),e.destroy(),this._destroyed=!0}}}]),e}(),iA=$.vec3(),sA=$.vec3(),rA=$.vec3();$.vec3();var nA=$.vec4(),oA=$.mat4(),aA=function(){function e(t,i){x(this,e),this._scene=t,this._withSAO=i,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,i){var s=this._scene,r=s.camera,n=t.model,o=s.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=n.position,c=n.rotationMatrix,h=n.rotationMatrixConjugate;if(this._program||(this._allocate(),!this.errors)){var d,p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,a)),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var f=0!==u[0]||0!==u[1]||0!==u[2],v=0!==A[0]||0!==A[1]||0!==A[2];if(f||v){var g=iA;if(f){var m=$.transformPoint3(c,u,sA);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=A[0],g[1]+=A[1],g[2]+=A[2],d=Re(r.viewMatrix,g,oA),(p=rA)[0]=r.eye[0]-g[0],p[1]=r.eye[1]-g[1],p[2]=r.eye[2]-g[2]}else d=r.viewMatrix,p=r.eye;if(o.uniformMatrix4fv(this._uSceneModelMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,d),o.uniformMatrix4fv(this._uProjMatrix,!1,r.projMatrix),o.uniform3fv(this._uCameraEyeRtc,p),o.uniform1i(this._uRenderPass,i),s.logarithmicDepthBufferEnabled){var _=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,_)}var y=s._sectionPlanesState.getNumAllocatedSectionPlanes(),b=s._sectionPlanesState.sectionPlanes.length;if(y>0)for(var w=s._sectionPlanesState.sectionPlanes,B=t.layerIndex*b,x=n.renderFlags,P=0;P0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),o.drawArrays(o.TRIANGLES,0,a.numIndices8Bits)),a.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),o.drawArrays(o.TRIANGLES,0,a.numIndices16Bits)),a.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),o.drawArrays(o.TRIANGLES,0,a.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl,i=e._lightsState;if(this._program=new kt(t,this._buildShader()),this._program.errors)return this.errors=this._program.errors,void console.error(this.errors);var s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uLightAmbient=s.getLocation("lightAmbient"),this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];for(var r=i.lights,n=0,o=r.length;n0,n=[];n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("uniform mat4 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),t.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("uniform vec4 lightAmbient;");for(var o=0,a=s.lights.length;o> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("} else {"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = sceneModelMatrix * ((objectDecodeAndInstanceMatrix * vec4(position, 1.0))); "),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),n.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),n.push("float lambertian = 1.0;");for(var l=0,u=s.lights.length;l0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesDataTextureColorRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),i){s.push("in vec4 vWorldPosition;"),s.push("flat in uint vFlags2;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r 0u;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { "),s.push(" discard;"),s.push(" }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(s.push(" float viewportWidth = uSAOParams[0];"),s.push(" float viewportHeight = uSAOParams[1];"),s.push(" float blendCutoff = uSAOParams[2];"),s.push(" float blendFactor = uSAOParams[3];"),s.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),s.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),s.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):s.push(" outColor = vColor;"),s.push("}"),s}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),lA=new Float32Array([1,1,1]),uA=$.vec3(),AA=$.vec3(),cA=$.vec3();$.vec3();var hA=$.mat4(),dA=function(){function e(t,i){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=this._scene,r=s.camera,n=t.model,o=s.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=n.position,c=n.rotationMatrix,h=n.rotationMatrixConjugate,d=r.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var p,f;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,a)),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix),u||0!==A[0]||0!==A[1]||0!==A[2]){var v=uA;if(u){var g=AA;$.transformPoint3(c,u,g),v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=A[0],v[1]+=A[1],v[2]+=A[2],p=Re(d,v,hA),(f=cA)[0]=r.eye[0]-v[0],f[1]=r.eye[1]-v[1],f[2]=r.eye[2]-v[2]}else p=d,f=r.eye;if(o.uniform3fv(this._uCameraEyeRtc,f),o.uniform1i(this._uRenderPass,i),o.uniformMatrix4fv(this._uWorldMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,p),o.uniformMatrix4fv(this._uProjMatrix,!1,r.projMatrix),i===oo.SILHOUETTE_XRAYED){var m=s.xrayMaterial._state,_=m.fillColor,y=m.fillAlpha;o.uniform4f(this._uColor,_[0],_[1],_[2],y)}else if(i===oo.SILHOUETTE_HIGHLIGHTED){var b=s.highlightMaterial._state,w=b.fillColor,B=b.fillAlpha;o.uniform4f(this._uColor,w[0],w[1],w[2],B)}else if(i===oo.SILHOUETTE_SELECTED){var x=s.selectedMaterial._state,P=x.fillColor,C=x.fillAlpha;o.uniform4f(this._uColor,P[0],P[1],P[2],C)}else o.uniform4fv(this._uColor,lA);if(s.logarithmicDepthBufferEnabled){var M=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,M)}var F=s._sectionPlanesState.getNumAllocatedSectionPlanes(),E=s._sectionPlanesState.sectionPlanes.length;if(F>0)for(var k=s._sectionPlanesState.sectionPlanes,I=t.layerIndex*E,D=n.renderFlags,S=0;S0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),o.drawArrays(o.TRIANGLES,0,a.numIndices8Bits)),a.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),o.drawArrays(o.TRIANGLES,0,a.numIndices16Bits)),a.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),o.drawArrays(o.TRIANGLES,0,a.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uColor=i.getLocation("color"),this._uWorldMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// Triangles dataTexture silhouette vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;")),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.y) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (solid != 1u) {"),i.push("if (isPerspectiveMatrix(projMatrix)) {"),i.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("viewNormal = -viewNormal;"),i.push("}"),i.push("} else {"),i.push("if (viewNormal.z < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("viewNormal = -viewNormal;"),i.push("}"),i.push("}"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags2 = flags2.r;")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles dataTexture draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0,o=e._sectionPlanesState.getNumAllocatedSectionPlanes();n 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" outColor = color;"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),pA=new Float32Array([0,0,0,1]),fA=$.vec3(),vA=$.vec3();$.vec3();var gA=$.mat4(),mA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=s.position,c=s.rotationMatrix,h=s.rotationMatrixConjugate,d=n.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var f=0!==u[0]||0!==u[1]||0!==u[2],v=0!==A[0]||0!==A[1]||0!==A[2];if(f||v){var g=fA;if(f){var m=$.transformPoint3(c,u,vA);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=A[0],g[1]+=A[1],g[2]+=A[2],p=Re(d,g,gA)}else p=d;if(o.uniform1i(this._uRenderPass,i),o.uniformMatrix4fv(this._uSceneModelMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,p),o.uniformMatrix4fv(this._uProjMatrix,!1,n.projMatrix),i===oo.EDGES_XRAYED){var _=r.xrayMaterial._state,y=_.edgeColor,b=_.edgeAlpha;o.uniform4f(this._uColor,y[0],y[1],y[2],b)}else if(i===oo.EDGES_HIGHLIGHTED){var w=r.highlightMaterial._state,B=w.edgeColor,x=w.edgeAlpha;o.uniform4f(this._uColor,B[0],B[1],B[2],x)}else if(i===oo.EDGES_SELECTED){var P=r.selectedMaterial._state,C=P.edgeColor,M=P.edgeAlpha;o.uniform4f(this._uColor,C[0],C[1],C[2],M)}else o.uniform4fv(this._uColor,pA);var F=r._sectionPlanesState.getNumAllocatedSectionPlanes(),E=r._sectionPlanesState.sectionPlanes.length;if(F>0)for(var k=r._sectionPlanesState.sectionPlanes,I=t.layerIndex*E,D=s.renderFlags,S=0;S0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),o.drawArrays(o.LINES,0,a.numEdgeIndices8Bits)),a.numEdgeIndices16Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),o.drawArrays(o.LINES,0,a.numEdgeIndices16Bits)),a.numEdgeIndices32Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),o.drawArrays(o.LINES,0,a.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uColor=i.getLocation("color"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uWorldMatrix=i.getLocation("worldMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// DTXTrianglesEdgesRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),i.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),i.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int edgeIndex = gl_VertexID / 2;"),i.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.z) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),i.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),i.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),i.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),i.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),i.push("mat4 matrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2.r;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vColor = vec4(color.r, color.g, color.b, color.a);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// DTXTrianglesEdgesRenderer fragment shader"),e.logarithmicDepthBufferEnabled&&i.push("#extension GL_EXT_frag_depth : enable"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0,o=e._sectionPlanesState.getNumAllocatedSectionPlanes();n 0.0) { discard; }"),i.push("}")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" outColor = vColor;"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),_A=$.vec3(),yA=$.vec3(),bA=$.mat4(),wA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=s.position,c=s.rotationMatrix,h=s.rotationMatrixConjugate,d=n.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var f=0!==u[0]||0!==u[1]||0!==u[2],v=0!==A[0]||0!==A[1]||0!==A[2];if(f||v){var g=_A;if(f){var m=$.transformPoint3(c,u,yA);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=A[0],g[1]+=A[1],g[2]+=A[2],p=Re(d,g,bA)}else p=d;o.uniform1i(this._uRenderPass,i),o.uniformMatrix4fv(this._uSceneModelMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,p),o.uniformMatrix4fv(this._uProjMatrix,!1,n.projMatrix);var _=r._sectionPlanesState.getNumAllocatedSectionPlanes(),y=r._sectionPlanesState.sectionPlanes.length;if(_>0)for(var b=r._sectionPlanesState.sectionPlanes,w=t.layerIndex*y,B=s.renderFlags,x=0;x<_;x++){var P=this._uSectionPlanes[x];if(P)if(x0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),o.drawArrays(o.LINES,0,a.numEdgeIndices8Bits)),a.numEdgeIndices16Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),o.drawArrays(o.LINES,0,a.numEdgeIndices16Bits)),a.numEdgeIndices32Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),o.drawArrays(o.LINES,0,a.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// TrianglesDataTextureEdgesColorRenderer"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled,i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform highp sampler2D uObjectPerObjectOffsets;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),i.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int edgeIndex = gl_VertexID / 2;"),i.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.z) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),i.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),i.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),i.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),i.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("};"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2.r;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vec4 rgb = vec4(color.rgba);"),i.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// TrianglesDataTextureEdgesColorRenderer"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0,o=e._sectionPlanesState.getNumAllocatedSectionPlanes();n 0.0) { discard; }"),i.push("}")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" outColor = vColor;"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),BA=$.vec3(),xA=$.vec3(),PA=$.vec3(),CA=$.mat4(),MA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e));var s,r,n=t.model,o=n.scene,a=o.camera,l=o.canvas.gl,u=t._state,A=u.textureState,c=t._state.origin,h=n.position,d=n.rotationMatrix,p=n.rotationMatrixConjugate;A.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var f=0!==c[0]||0!==c[1]||0!==c[2],v=0!==h[0]||0!==h[1]||0!==h[2];if(f||v){var g=BA;if(f){var m=$.transformPoint3(d,c,xA);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=h[0],g[1]+=h[1],g[2]+=h[2],s=Re(a.viewMatrix,g,CA),(r=PA)[0]=a.eye[0]-g[0],r[1]=a.eye[1]-g[1],r[2]=a.eye[2]-g[2]}else s=a.viewMatrix,r=a.eye;if(l.uniform2fv(this._uPickClipPos,e.pickClipPos),l.uniform2f(this._uDrawingBufferSize,l.drawingBufferWidth,l.drawingBufferHeight),l.uniformMatrix4fv(this._uSceneModelMatrix,!1,p),l.uniformMatrix4fv(this._uViewMatrix,!1,s),l.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),l.uniform3fv(this._uCameraEyeRtc,r),l.uniform1i(this._uRenderPass,i),o.logarithmicDepthBufferEnabled){var _=2/(Math.log(a.project.far+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,_)}var y=o._sectionPlanesState.getNumAllocatedSectionPlanes(),b=o._sectionPlanesState.sectionPlanes.length;if(y>0)for(var w=o._sectionPlanesState.sectionPlanes,B=t.layerIndex*b,x=n.renderFlags,P=0;P0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),l.drawArrays(l.TRIANGLES,0,u.numIndices8Bits)),u.numIndices16Bits>0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),l.drawArrays(l.TRIANGLES,0,u.numIndices16Bits)),u.numIndices32Bits>0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),l.drawArrays(l.TRIANGLES,0,u.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPickInvisible=i.getLocation("pickInvisible"),this._uPickClipPos=i.getLocation("pickClipPos"),this._uDrawingBufferSize=i.getLocation("drawingBufferSize"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// Batched geometry picking vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform bool pickInvisible;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;")),i.push("uniform vec2 pickClipPos;"),i.push("uniform vec2 drawingBufferSize;"),i.push("vec4 remapClipPos(vec4 clipPos) {"),i.push(" clipPos.xy /= clipPos.w;"),i.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"),i.push(" clipPos.xy *= clipPos.w;"),i.push(" return clipPos;"),i.push("}"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),t&&(i.push("smooth out vec4 vWorldPosition;"),i.push("flat out uvec4 vFlags2;")),i.push("out vec4 vPickColor;"),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.w) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("vPickColor = vec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0)) / 255.0;"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("if (solid != 1u) {"),i.push("if (isPerspectiveMatrix(projMatrix)) {"),i.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("}"),i.push("} else {"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (viewNormal.z < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("}"),i.push("}"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Batched geometry picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uvec4 vFlags2;");for(var s=0;s 0.0);"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(s=0;s 0.0) { discard; }"),i.push(" }")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" outPickColor = vPickColor; "),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),FA=$.vec3(),EA=$.vec3(),kA=$.vec3();$.vec3();var IA=$.mat4(),DA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s,r,n=t.model,o=n.scene,a=o.camera,l=o.canvas.gl,u=t._state,A=u.textureState,c=t._state.origin,h=n.position,d=n.rotationMatrix,p=n.rotationMatrixConjugate,f=e.pickViewMatrix||a.viewMatrix;if(this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),A.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix),c||0!==h[0]||0!==h[1]||0!==h[2]){var v=FA;if(c){var g=EA;$.transformPoint3(d,c,g),v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=h[0],v[1]+=h[1],v[2]+=h[2],s=Re(f,v,IA),(r=kA)[0]=a.eye[0]-v[0],r[1]=a.eye[1]-v[1],r[2]=a.eye[2]-v[2],e.snapPickOrigin[0]=v[0],e.snapPickOrigin[1]=v[1],e.snapPickOrigin[2]=v[2]}else s=f,r=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;if(l.uniform3fv(this._uCameraEyeRtc,r),l.uniform1i(this._uRenderPass,i),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniform2fv(this._uPickClipPos,e.pickClipPos),l.uniform2f(this._uDrawingBufferSize,l.drawingBufferWidth,l.drawingBufferHeight),l.uniform1f(this._uPickZNear,e.pickZNear),l.uniform1f(this._uPickZFar,e.pickZFar),l.uniformMatrix4fv(this._uSceneModelMatrix,!1,p),l.uniformMatrix4fv(this._uViewMatrix,!1,s),l.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),o.logarithmicDepthBufferEnabled){var m=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,m)}var _=o._sectionPlanesState.getNumAllocatedSectionPlanes(),y=o._sectionPlanesState.sectionPlanes.length;if(_>0)for(var b=o._sectionPlanesState.sectionPlanes,w=t.layerIndex*y,B=n.renderFlags,x=0;x<_;x++){var P=this._uSectionPlanes[x];if(P)if(x0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),l.drawArrays(l.TRIANGLES,0,u.numIndices8Bits)),u.numIndices16Bits>0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),l.drawArrays(l.TRIANGLES,0,u.numIndices16Bits)),u.numIndices32Bits>0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),l.drawArrays(l.TRIANGLES,0,u.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPickInvisible=i.getLocation("pickInvisible"),this._uPickClipPos=i.getLocation("pickClipPos"),this._uDrawingBufferSize=i.getLocation("drawingBufferSize"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// Triangles dataTexture pick depth vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform bool pickInvisible;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;")),i.push("uniform vec2 pickClipPos;"),i.push("uniform vec2 drawingBufferSize;"),i.push("vec4 remapClipPos(vec4 clipPos) {"),i.push(" clipPos.xy /= clipPos.w;"),i.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"),i.push(" clipPos.xy *= clipPos.w;"),i.push(" return clipPos;"),i.push("}"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("out vec4 vViewPosition;"),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.w) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("};"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("if (solid != 1u) {"),i.push("if (isPerspectiveMatrix(projMatrix)) {"),i.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("}"),i.push("} else {"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (viewNormal.z < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("}"),i.push("}"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2.r;")),i.push("vViewPosition = viewPosition;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles dataTexture pick depth fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),i.push("uniform float pickZNear;"),i.push("uniform float pickZFar;"),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0;s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(s=0;s 0.0) { discard; }"),i.push(" }")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),i.push(" outPackedDepth = packDepth(zNormalizedDepth); "),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),SA=$.vec3(),TA=$.vec3(),RA=$.vec3(),LA=$.vec3();$.vec3();var UA=$.mat4(),OA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s,r,n=t.model,o=n.scene,a=o.camera,l=o.canvas.gl,u=t._state,A=u.textureState,c=t._state.origin,h=n.position,d=n.rotationMatrix,p=n.rotationMatrixConjugate,f=t.aabb,v=e.pickViewMatrix||a.viewMatrix,g=SA;g[0]=$.safeInv(f[3]-f[0])*$.MAX_INT,g[1]=$.safeInv(f[4]-f[1])*$.MAX_INT,g[2]=$.safeInv(f[5]-f[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(g[0]),e.snapPickCoordinateScale[1]=$.safeInv(g[1]),e.snapPickCoordinateScale[2]=$.safeInv(g[2]),A.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var m=0!==c[0]||0!==c[1]||0!==c[2],_=0!==h[0]||0!==h[1]||0!==h[2];if(m||_){var y=TA;if(m){var b=$.transformPoint3(d,c,RA);y[0]=b[0],y[1]=b[1],y[2]=b[2]}else y[0]=0,y[1]=0,y[2]=0;y[0]+=h[0],y[1]+=h[1],y[2]+=h[2],s=Re(v,y,UA),(r=LA)[0]=a.eye[0]-y[0],r[1]=a.eye[1]-y[1],r[2]=a.eye[2]-y[2],e.snapPickOrigin[0]=y[0],e.snapPickOrigin[1]=y[1],e.snapPickOrigin[2]=y[2]}else s=v,r=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;l.uniform3fv(this._uCameraEyeRtc,r),l.uniform2fv(this.uVectorA,e.snapVectorA),l.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),l.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),l.uniform3fv(this._uCoordinateScaler,g),l.uniform1i(this._uRenderPass,i),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniformMatrix4fv(this._uSceneModelMatrix,!1,p),l.uniformMatrix4fv(this._uViewMatrix,!1,s),l.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var w=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,w);var B=o._sectionPlanesState.getNumAllocatedSectionPlanes(),x=o._sectionPlanesState.sectionPlanes.length;if(B>0)for(var P=o._sectionPlanesState.sectionPlanes,C=t.layerIndex*x,M=n.renderFlags,F=0;F0&&(A.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),l.drawArrays(S,0,u.numEdgeIndices8Bits)),u.numEdgeIndices16Bits>0&&(A.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),l.drawArrays(S,0,u.numEdgeIndices16Bits)),u.numEdgeIndices32Bits>0&&(A.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),l.drawArrays(S,0,u.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPickInvisible=i.getLocation("pickInvisible"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// Batched geometry edges drawing vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),i.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 uSnapVectorA;"),i.push("uniform vec2 uSnapInvVectorAB;"),i.push("vec3 positions[3];"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - uSnapVectorA.x) * uSnapInvVectorAB.x;"),i.push(" float y = (clipPos.y - uSnapVectorA.y) * uSnapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("out vec4 vViewPosition;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int edgeIndex = gl_VertexID / 2;"),i.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("{"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),i.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),i.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),i.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),i.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2.r;")),i.push("vViewPosition = viewPosition;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vViewPosition = clipPos;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles dataTexture pick depth fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int uLayerNumber;"),i.push("uniform vec3 uCoordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),i.push(" }")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, uLayerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),NA=$.vec3(),QA=$.vec3(),VA=$.vec3(),HA=$.vec3();$.vec3();var jA=$.mat4(),GA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s,r,n=t.model,o=n.scene,a=o.camera,l=o.canvas.gl,u=t._state,A=u.textureState,c=t._state.origin,h=n.position,d=n.rotationMatrix,p=n.rotationMatrixConjugate,f=t.aabb,v=e.pickViewMatrix||a.viewMatrix,g=NA;g[0]=$.safeInv(f[3]-f[0])*$.MAX_INT,g[1]=$.safeInv(f[4]-f[1])*$.MAX_INT,g[2]=$.safeInv(f[5]-f[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(g[0]),e.snapPickCoordinateScale[1]=$.safeInv(g[1]),e.snapPickCoordinateScale[2]=$.safeInv(g[2]),A.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var m=0!==c[0]||0!==c[1]||0!==c[2],_=0!==h[0]||0!==h[1]||0!==h[2];if(m||_){var y=QA;if(m){var b=VA;$.transformPoint3(d,c,b),y[0]=b[0],y[1]=b[1],y[2]=b[2]}else y[0]=0,y[1]=0,y[2]=0;y[0]+=h[0],y[1]+=h[1],y[2]+=h[2],s=Re(v,y,jA),(r=HA)[0]=a.eye[0]-y[0],r[1]=a.eye[1]-y[1],r[2]=a.eye[2]-y[2],e.snapPickOrigin[0]=y[0],e.snapPickOrigin[1]=y[1],e.snapPickOrigin[2]=y[2]}else s=v,r=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;l.uniform3fv(this._uCameraEyeRtc,r),l.uniform2fv(this._uVectorA,e.snapVectorA),l.uniform2fv(this._uInverseVectorAB,e.snapInvVectorAB),l.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),l.uniform3fv(this._uCoordinateScaler,g),l.uniform1i(this._uRenderPass,i),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniformMatrix4fv(this._uSceneWorldModelMatrix,!1,p),l.uniformMatrix4fv(this._uViewMatrix,!1,s),l.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var w=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,w);var B=o._sectionPlanesState.getNumAllocatedSectionPlanes(),x=o._sectionPlanesState.sectionPlanes.length;if(B>0)for(var P=o._sectionPlanesState.sectionPlanes,C=t.layerIndex*x,M=n.renderFlags,F=0;F0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),l.drawArrays(l.TRIANGLES,0,u.numIndices8Bits)),u.numIndices16Bits>0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),l.drawArrays(l.TRIANGLES,0,u.numIndices16Bits)),u.numIndices32Bits>0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),l.drawArrays(l.TRIANGLES,0,u.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPickInvisible=i.getLocation("pickInvisible"),this._uSceneWorldModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// DTXTrianglesSnapInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 uVectorAB;"),i.push("uniform vec2 uInverseVectorAB;"),i.push("vec3 positions[3];"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - uVectorAB.x) * uInverseVectorAB.x;"),i.push(" float y = (clipPos.y - uVectorAB.y) * uInverseVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("flat out uint vFlags2;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("{"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("};"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (solid != 1u) {"),i.push(" if (isPerspectiveMatrix(projMatrix)) {"),i.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push(" position = positions[2 - (gl_VertexID % 3)];"),i.push(" viewNormal = -viewNormal;"),i.push(" }"),i.push(" } else {"),i.push(" if (viewNormal.z < 0.0) {"),i.push(" position = positions[2 - (gl_VertexID % 3)];"),i.push(" viewNormal = -viewNormal;"),i.push(" }"),i.push(" }"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vWorldPosition = worldPosition;"),t&&i.push("vFlags2 = flags2.r;"),i.push("vPickColor = vec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0));"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// DTXTrianglesSnapInitRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int uLayerNumber;"),i.push("uniform vec3 uCoordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),i.push(" }")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, - uLayerNumber);"),i.push("vec3 xTangent = dFdx( vWorldPosition.xyz );"),i.push("vec3 yTangent = dFdy( vWorldPosition.xyz );"),i.push("vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),i.push("outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),zA=$.vec3(),WA=$.vec3(),KA=$.vec3();$.vec3();var XA=$.mat4(),JA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=s.position,c=s.rotationMatrix,h=s.rotationMatrixConjugate,d=e.pickViewMatrix||n.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var p,f;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix),u||0!==A[0]||0!==A[1]||0!==A[2]){var v=zA;if(u){var g=WA;$.transformPoint3(c,u,g),v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=A[0],v[1]+=A[1],v[2]+=A[2],p=Re(d,v,XA),(f=KA)[0]=n.eye[0]-v[0],f[1]=n.eye[1]-v[1],f[2]=n.eye[2]-v[2]}else p=d,f=n.eye;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform1i(this._uRenderPass,i),o.uniformMatrix4fv(this._uWorldMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,p),o.uniformMatrix4fv(this._uProjMatrix,!1,n.projMatrix);var m=r._sectionPlanesState.getNumAllocatedSectionPlanes(),_=r._sectionPlanesState.sectionPlanes.length;if(m>0)for(var y=r._sectionPlanesState.sectionPlanes,b=t.layerIndex*_,w=s.renderFlags,B=0;B0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),o.drawArrays(o.TRIANGLES,0,a.numIndices8Bits)),a.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),o.drawArrays(o.TRIANGLES,0,a.numIndices16Bits)),a.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),o.drawArrays(o.TRIANGLES,0,a.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPickInvisible=i.getLocation("pickInvisible"),this._uWorldMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// TrianglesDataTextureOcclusionRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("vec3 positions[3];"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.x) != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("};"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("if (solid != 1u) {"),i.push(" if (isPerspectiveMatrix(projMatrix)) {"),i.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push(" position = positions[2 - (gl_VertexID % 3)];"),i.push(" }"),i.push(" } else {"),i.push(" vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push(" if (viewNormal.z < 0.0) {"),i.push(" position = positions[2 - (gl_VertexID % 3)];"),i.push(" }"),i.push(" }"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vec4 clipPos = projMatrix * viewPosition;"),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags2 = flags2.r;")),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// TrianglesDataTextureColorRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0;s 0.0);"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),YA=$.vec3(),ZA=$.vec3(),qA=$.vec3();$.vec3();var $A=$.mat4(),ec=function(){function e(t){x(this,e),this._scene=t,this._allocate(),this._hash=this._getHash()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=this._scene,r=s.camera,n=t.model,o=s.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=n.position,c=n.rotationMatrix,h=n.rotationMatrixConjugate;if(this._program||(this._allocate(),!this.errors)){var d,p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,a)),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var f=0!==u[0]||0!==u[1]||0!==u[2],v=0!==A[0]||0!==A[1]||0!==A[2];if(f||v){var g=YA;if(f){var m=$.transformPoint3(c,u,ZA);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=A[0],g[1]+=A[1],g[2]+=A[2],d=Re(r.viewMatrix,g,$A),(p=qA)[0]=r.eye[0]-g[0],p[1]=r.eye[1]-g[1],p[2]=r.eye[2]-g[2]}else d=r.viewMatrix,p=r.eye;if(o.uniformMatrix4fv(this._uSceneModelMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,d),o.uniformMatrix4fv(this._uProjMatrix,!1,r.projMatrix),o.uniform3fv(this._uCameraEyeRtc,p),o.uniform1i(this._uRenderPass,i),s.logarithmicDepthBufferEnabled){var _=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,_)}var y=s._sectionPlanesState.getNumAllocatedSectionPlanes(),b=s._sectionPlanesState.sectionPlanes.length;if(y>0)for(var w=s._sectionPlanesState.sectionPlanes,B=t.layerIndex*b,x=n.renderFlags,P=0;P0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),o.drawArrays(o.TRIANGLES,0,a.numIndices8Bits)),a.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),o.drawArrays(o.TRIANGLES,0,a.numIndices16Bits)),a.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),o.drawArrays(o.TRIANGLES,0,a.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPositionsDecodeMatrix=i.getLocation("objectDecodeAndInstanceMatrix"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// Triangles dataTexture draw vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;")),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out highp vec2 vHighPrecisionZW;"),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.x) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("};"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (solid != 1u) {"),i.push("if (isPerspectiveMatrix(projMatrix)) {"),i.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("viewNormal = -viewNormal;"),i.push("}"),i.push("} else {"),i.push("if (viewNormal.z < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("viewNormal = -viewNormal;"),i.push("}"),i.push("}"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags2 = flags2.r;")),i.push("gl_Position = clipPos;"),i.push("vHighPrecisionZW = gl_Position.zw;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles dataTexture draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in highp vec2 vHighPrecisionZW;"),i.push("out vec4 outColor;"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0,o=e._sectionPlanesState.getNumAllocatedSectionPlanes();n 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),i.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),tc=$.vec3(),ic=$.vec3(),sc=$.vec3();$.vec3();var rc=$.mat4(),nc=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=n.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var d,p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(t));var f=0!==l[0]||0!==l[1]||0!==l[2],v=0!==u[0]||0!==u[1]||0!==u[2];if(f||v){var g=tc;if(f){var m=ic;$.transformPoint3(A,l,m),g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],d=Re(h,g,rc),(p=sc)[0]=n.eye[0]-g[0],p[1]=n.eye[1]-g[1],p[2]=n.eye[2]-g[2]}else d=h,p=n.eye;o.uniform1i(this._uRenderPass,i),o.uniformMatrix4fv(this._uWorldMatrix,!1,c),o.uniformMatrix4fv(this._uViewMatrix,!1,d),o.uniformMatrix4fv(this._uProjMatrix,!1,n.projMatrix),o.uniformMatrix4fv(this._uViewNormalMatrix,!1,n.viewNormalMatrix),o.uniformMatrix4fv(this._uWorldNormalMatrix,!1,s.worldNormalMatrix);var _=r._sectionPlanesState.getNumAllocatedSectionPlanes(),y=r._sectionPlanesState.sectionPlanes.length;if(_>0)for(var b=r._sectionPlanesState.sectionPlanes,w=t.layerIndex*y,B=s.renderFlags,x=0;x<_;x++){var P=this._uSectionPlanes[x];if(P)if(x0,i=[];return i.push("// Batched geometry normals vertex shader"),e.logarithmicDepthBufferEnabled&&yt.SUPPORTED_EXTENSIONS.EXT_frag_depth&&i.push("#extension GL_EXT_frag_depth : enable"),i.push("uniform int renderPass;"),i.push("attribute vec3 position;"),e.entityOffsetsEnabled&&i.push("attribute vec3 offset;"),i.push("attribute vec3 normal;"),i.push("attribute vec4 color;"),i.push("attribute vec4 flags;"),i.push("attribute vec4 flags2;"),i.push("uniform mat4 worldMatrix;"),i.push("uniform mat4 worldNormalMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform mat4 viewNormalMatrix;"),i.push("uniform mat4 objectDecodeAndInstanceMatrix;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),yt.SUPPORTED_EXTENSIONS.EXT_frag_depth&&i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("varying float isPerspective;")),i.push("vec3 octDecode(vec2 oct) {"),i.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),i.push(" if (v.z < 0.0) {"),i.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),i.push(" }"),i.push(" return normalize(v);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out vec4 vFlags2;")),i.push("out vec3 vViewNormal;"),i.push("void main(void) {"),i.push("if (int(flags.x) != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),i.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2;")),i.push(" vViewNormal = viewNormal;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(yt.SUPPORTED_EXTENSIONS.EXT_frag_depth?i.push("vFragDepth = 1.0 + clipPos.w;"):(i.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;"),i.push("clipPos.z *= clipPos.w;")),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Batched geometry normals fragment shader"),e.logarithmicDepthBufferEnabled&&yt.SUPPORTED_EXTENSIONS.EXT_frag_depth&&i.push("#extension GL_EXT_frag_depth : enable"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&yt.SUPPORTED_EXTENSIONS.EXT_frag_depth&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),t){i.push("in vec4 vWorldPosition;"),i.push("in vec4 vFlags2;");for(var s=0;s 0.0);"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return e.logarithmicDepthBufferEnabled&&yt.SUPPORTED_EXTENSIONS.EXT_frag_depth&&i.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" gl_FragColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),oc=$.vec3(),ac=$.vec3(),lc=$.vec3();$.vec3(),$.vec4();var uc=$.mat4(),Ac=function(){function e(t,i){x(this,e),this._scene=t,this._withSAO=i,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,i){var s=this._scene,r=s.camera,n=t.model,o=s.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=n.position,c=n.rotationMatrix,h=n.rotationMatrixConjugate;if(this._program||(this._allocate(),!this.errors)){var d,p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,a)),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var f=0!==u[0]||0!==u[1]||0!==u[2],v=0!==A[0]||0!==A[1]||0!==A[2];if(f||v){var g=oc;if(f){var m=$.transformPoint3(c,u,ac);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=A[0],g[1]+=A[1],g[2]+=A[2],d=Re(r.viewMatrix,g,uc),(p=lc)[0]=r.eye[0]-g[0],p[1]=r.eye[1]-g[1],p[2]=r.eye[2]-g[2]}else d=r.viewMatrix,p=r.eye;if(o.uniform2fv(this._uPickClipPos,e.pickClipPos),o.uniform2f(this._uDrawingBufferSize,o.drawingBufferWidth,o.drawingBufferHeight),o.uniformMatrix4fv(this._uSceneModelMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,d),o.uniformMatrix4fv(this._uProjMatrix,!1,r.projMatrix),o.uniform3fv(this._uCameraEyeRtc,p),o.uniform1i(this._uRenderPass,i),s.logarithmicDepthBufferEnabled){var _=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,_)}var y=s._sectionPlanesState.getNumAllocatedSectionPlanes(),b=s._sectionPlanesState.sectionPlanes.length;if(y>0)for(var w=s._sectionPlanesState.sectionPlanes,B=t.layerIndex*b,x=n.renderFlags,P=0;P0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),o.drawArrays(o.TRIANGLES,0,a.numIndices8Bits)),a.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),o.drawArrays(o.TRIANGLES,0,a.numIndices16Bits)),a.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),o.drawArrays(o.TRIANGLES,0,a.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPickInvisible=i.getLocation("pickInvisible"),this._uPickClipPos=i.getLocation("pickClipPos"),this._uDrawingBufferSize=i.getLocation("drawingBufferSize"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// trianglesDatatextureNormalsRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;")),i.push("uniform vec2 pickClipPos;"),i.push("uniform vec2 drawingBufferSize;"),i.push("vec4 remapClipPos(vec4 clipPos) {"),i.push(" clipPos.xy /= clipPos.w;"),i.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"),i.push(" clipPos.xy *= clipPos.w;"),i.push(" return clipPos;"),i.push("}"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out vec4 vWorldPosition;"),t&&i.push("flat out uint vFlags2;"),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.w) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("};"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (solid != 1u) {"),i.push("if (isPerspectiveMatrix(projMatrix)) {"),i.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("viewNormal = -viewNormal;"),i.push("}"),i.push("} else {"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (viewNormal.z < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("}"),i.push("}"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("vWorldPosition = worldPosition;"),t&&i.push("vFlags2 = flags2.r;"),i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// TrianglesDataTexturePickNormalsRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),i.push("in vec4 vWorldPosition;"),t){i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0,o=e._sectionPlanesState.getNumAllocatedSectionPlanes();n 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),i.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),i.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),i.push(" outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),cc=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorQualityRendererWithSAO&&!this._colorQualityRendererWithSAO.getValid()&&(this._colorQualityRendererWithSAO.destroy(),this._colorQualityRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}},{key:"eagerCreateRenders",value:function(){this._silhouetteRenderer||(this._silhouetteRenderer=new dA(this._scene)),this._pickMeshRenderer||(this._pickMeshRenderer=new MA(this._scene)),this._pickDepthRenderer||(this._pickDepthRenderer=new DA(this._scene)),this._pickNormalsRenderer||(this._pickNormalsRenderer=new Ac(this._scene)),this._snapRenderer||(this._snapRenderer=new OA(this._scene)),this._snapInitRenderer||(this._snapInitRenderer=new GA(this._scene)),this._snapRenderer||(this._snapRenderer=new OA(this._scene))}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new aA(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new aA(this._scene,!0)),this._colorRendererWithSAO}},{key:"colorQualityRendererWithSAO",get:function(){return this._colorQualityRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new dA(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new ec(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new nc(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new mA(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new wA(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new MA(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new Ac(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new Ac(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new DA(this._scene)),this._pickDepthRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new OA(this._scene)),this._snapRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new GA(this._scene)),this._snapInitRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new JA(this._scene)),this._occlusionRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._colorQualityRendererWithSAO&&this._colorQualityRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}]),e}(),hc={};var dc=C((function e(){x(this,e),this.positionsCompressed=[],this.lenPositionsCompressed=0,this.metallicRoughness=[],this.indices8Bits=[],this.lenIndices8Bits=0,this.indices16Bits=[],this.lenIndices16Bits=0,this.indices32Bits=[],this.lenIndices32Bits=0,this.edgeIndices8Bits=[],this.lenEdgeIndices8Bits=0,this.edgeIndices16Bits=[],this.lenEdgeIndices16Bits=0,this.edgeIndices32Bits=[],this.lenEdgeIndices32Bits=0,this.perObjectColors=[],this.perObjectPickColors=[],this.perObjectSolid=[],this.perObjectOffsets=[],this.perObjectPositionsDecodeMatrices=[],this.perObjectInstancePositioningMatrices=[],this.perObjectVertexBases=[],this.perObjectIndexBaseOffsets=[],this.perObjectEdgeIndexBaseOffsets=[],this.perTriangleNumberPortionId8Bits=[],this.perTriangleNumberPortionId16Bits=[],this.perTriangleNumberPortionId32Bits=[],this.perEdgeNumberPortionId8Bits=[],this.perEdgeNumberPortionId16Bits=[],this.perEdgeNumberPortionId32Bits=[]})),pc=function(){function e(){x(this,e),this.texturePerObjectColorsAndFlags=null,this.texturePerObjectOffsets=null,this.texturePerObjectInstanceMatrices=null,this.texturePerObjectPositionsDecodeMatrix=null,this.texturePerVertexIdCoordinates=null,this.texturePerPolygonIdPortionIds8Bits=null,this.texturePerPolygonIdPortionIds16Bits=null,this.texturePerPolygonIdPortionIds32Bits=null,this.texturePerEdgeIdPortionIds8Bits=null,this.texturePerEdgeIdPortionIds16Bits=null,this.texturePerEdgeIdPortionIds32Bits=null,this.texturePerPolygonIdIndices8Bits=null,this.texturePerPolygonIdIndices16Bits=null,this.texturePerPolygonIdIndices32Bits=null,this.texturePerPolygonIdEdgeIndices8Bits=null,this.texturePerPolygonIdEdgeIndices16Bits=null,this.texturePerPolygonIdEdgeIndices32Bits=null,this.textureModelMatrices=null}return C(e,[{key:"finalize",value:function(){this.indicesPerBitnessTextures={8:this.texturePerPolygonIdIndices8Bits,16:this.texturePerPolygonIdIndices16Bits,32:this.texturePerPolygonIdIndices32Bits},this.indicesPortionIdsPerBitnessTextures={8:this.texturePerPolygonIdPortionIds8Bits,16:this.texturePerPolygonIdPortionIds16Bits,32:this.texturePerPolygonIdPortionIds32Bits},this.edgeIndicesPerBitnessTextures={8:this.texturePerPolygonIdEdgeIndices8Bits,16:this.texturePerPolygonIdEdgeIndices16Bits,32:this.texturePerPolygonIdEdgeIndices32Bits},this.edgeIndicesPortionIdsPerBitnessTextures={8:this.texturePerEdgeIdPortionIds8Bits,16:this.texturePerEdgeIdPortionIds16Bits,32:this.texturePerEdgeIdPortionIds32Bits}}},{key:"bindCommonTextures",value:function(e,t,i,s,r){this.texturePerObjectPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,i,2),this.texturePerObjectColorsAndFlags.bindTexture(e,s,3),this.texturePerObjectInstanceMatrices.bindTexture(e,r,4)}},{key:"bindTriangleIndicesTextures",value:function(e,t,i,s){this.indicesPortionIdsPerBitnessTextures[s].bindTexture(e,t,5),this.indicesPerBitnessTextures[s].bindTexture(e,i,6)}},{key:"bindEdgeIndicesTextures",value:function(e,t,i,s){this.edgeIndicesPortionIdsPerBitnessTextures[s].bindTexture(e,t,5),this.edgeIndicesPerBitnessTextures[s].bindTexture(e,i,6)}}]),e}(),fc={sizeDataColorsAndFlags:0,sizeDataPositionDecodeMatrices:0,sizeDataTextureOffsets:0,sizeDataTexturePositions:0,sizeDataTextureIndices:0,sizeDataTextureEdgeIndices:0,sizeDataTexturePortionIds:0,numberOfGeometries:0,numberOfPortions:0,numberOfLayers:0,numberOfTextures:0,totalPolygons:0,totalPolygons8Bits:0,totalPolygons16Bits:0,totalPolygons32Bits:0,totalEdges:0,totalEdges8Bits:0,totalEdges16Bits:0,totalEdges32Bits:0,cannotCreatePortion:{because10BitsObjectId:0,becauseTextureSize:0},overheadSizeAlignementIndices:0,overheadSizeAlignementEdgeIndices:0};window.printDataTextureRamStats=function(){console.log(JSON.stringify(fc,null,4));var e=0;Object.keys(fc).forEach((function(t){t.startsWith("size")&&(e+=fc[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/fc.totalPolygons).toFixed(2)));var t={};Object.keys(fc).forEach((function(i){i.startsWith("size")&&(t[i]="".concat((fc[i]/e*100).toFixed(2)," % of total"))})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};var vc=function(){function e(){x(this,e)}return C(e,[{key:"disableBindedTextureFiltering",value:function(e){e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}},{key:"createTextureForColorsAndFlags",value:function(e,t,i,s,r,n,o){var a=t.length;this.numPortions=a;var l=4096,u=Math.ceil(a/512);if(0===u)throw"texture height===0";var A=new Uint8Array(16384*u);fc.sizeDataColorsAndFlags+=A.byteLength,fc.numberOfTextures++;for(var c=0;c>24&255,s[c]>>16&255,s[c]>>8&255,255&s[c]],32*c+16),A.set([r[c]>>24&255,r[c]>>16&255,r[c]>>8&255,255&r[c]],32*c+20),A.set([n[c]>>24&255,n[c]>>16&255,n[c]>>8&255,255&n[c]],32*c+24),A.set([o[c]?1:0,0,0,0],32*c+28);var h=e.createTexture();return e.bindTexture(e.TEXTURE_2D,h),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8UI,l,u),e.texSubImage2D(e.TEXTURE_2D,0,0,0,l,u,e.RGBA_INTEGER,e.UNSIGNED_BYTE,A,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new zu(e,h,l,u,A)}},{key:"createTextureForObjectOffsets",value:function(e,t){var i=512,s=Math.ceil(t/i);if(0===s)throw"texture height===0";var r=new Float32Array(1536*s).fill(0);fc.sizeDataTextureOffsets+=r.byteLength,fc.numberOfTextures++;var n=e.createTexture();return e.bindTexture(e.TEXTURE_2D,n),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32F,i,s),e.texSubImage2D(e.TEXTURE_2D,0,0,0,i,s,e.RGB,e.FLOAT,r,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new zu(e,n,i,s,r)}},{key:"createTextureForInstancingMatrices",value:function(e,t){var i=t.length;if(0===i)throw"num instance matrices===0";var s=2048,r=Math.ceil(i/512),n=new Float32Array(8192*r);fc.numberOfTextures++;for(var o=0;o65536&&fc.cannotCreatePortion.because10BitsObjectId++;var i=this._numPortions+t<=65536,s=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(0):"".concat(e.id,"#").concat(0);if(!this._bucketGeometries[s]){var r=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits),n=0,o=0;e.buckets.forEach((function(e){n+=e.positionsCompressed.length/3,o+=e.indices.length/3})),(this._state.numVertices+n>4096*mc||r+o>4096*mc)&&fc.cannotCreatePortion.becauseTextureSize++,i&&(i=this._state.numVertices+n<=4096*mc&&r+o<=4096*mc)}return i}},{key:"createPortion",value:function(e,t){var i=this;if(this._finalized)throw"Already finalized";var s=[];t.buckets.forEach((function(e,r){var n=void 0!==t.geometryId&&null!==t.geometryId?"".concat(t.geometryId,"#").concat(r):"".concat(t.id,"#").concat(r),o=i._bucketGeometries[n];o||(o=i._createBucketGeometry(t,e),i._bucketGeometries[n]=o);var a=i._createSubPortion(t,o,e);s.push(a)}));var r=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(s),this.model.numPortions++,this._meshes.push(e),r}},{key:"_createBucketGeometry",value:function(e,t){if(t.indices){var i=8*Math.ceil(t.indices.length/3/8)*3;fc.overheadSizeAlignementIndices+=2*(i-t.indices.length);var s=new Uint32Array(i);s.fill(0),s.set(t.indices),t.indices=s}if(t.edgeIndices){var r=8*Math.ceil(t.edgeIndices.length/2/8)*2;fc.overheadSizeAlignementEdgeIndices+=2*(r-t.edgeIndices.length);var n=new Uint32Array(r);n.fill(0),n.set(t.edgeIndices),t.edgeIndices=n}var o=t.positionsCompressed,a=t.indices,l=t.edgeIndices,u=this._buffer;u.positionsCompressed.push(o);var A,c=u.lenPositionsCompressed/3,h=o.length/3;u.lenPositionsCompressed+=o.length;var d,p,f=0;a&&(f=a.length/3,h<=256?(d=u.indices8Bits,A=u.lenIndices8Bits/3,u.lenIndices8Bits+=a.length):h<=65536?(d=u.indices16Bits,A=u.lenIndices16Bits/3,u.lenIndices16Bits+=a.length):(d=u.indices32Bits,A=u.lenIndices32Bits/3,u.lenIndices32Bits+=a.length),d.push(a));var v,g=0;l&&(g=l.length/2,h<=256?(v=u.edgeIndices8Bits,p=u.lenEdgeIndices8Bits/2,u.lenEdgeIndices8Bits+=l.length):h<=65536?(v=u.edgeIndices16Bits,p=u.lenEdgeIndices16Bits/2,u.lenEdgeIndices16Bits+=l.length):(v=u.edgeIndices32Bits,p=u.lenEdgeIndices32Bits/2,u.lenEdgeIndices32Bits+=l.length),v.push(l));return this._state.numVertices+=h,fc.numberOfGeometries++,{vertexBase:c,numVertices:h,numTriangles:f,numEdges:g,indicesBase:A,edgeIndicesBase:p}}},{key:"_createSubPortion",value:function(e,t,i,s){var r=e.color;e.metallic,e.roughness;var n,o,a=e.colors,l=e.opacity,u=e.meshMatrix,A=e.pickColor,c=this._buffer,h=this._state;c.perObjectPositionsDecodeMatrices.push(e.positionsDecodeMatrix),c.perObjectInstancePositioningMatrices.push(u||Bc),c.perObjectSolid.push(!!e.solid),a?c.perObjectColors.push([255*a[0],255*a[1],255*a[2],255]):r&&c.perObjectColors.push([r[0],r[1],r[2],l]),c.perObjectPickColors.push(A),c.perObjectVertexBases.push(t.vertexBase),n=t.numVertices<=256?h.numIndices8Bits:t.numVertices<=65536?h.numIndices16Bits:h.numIndices32Bits,c.perObjectIndexBaseOffsets.push(n/3-t.indicesBase),o=t.numVertices<=256?h.numEdgeIndices8Bits:t.numVertices<=65536?h.numEdgeIndices16Bits:h.numEdgeIndices32Bits,c.perObjectEdgeIndexBaseOffsets.push(o/2-t.edgeIndicesBase);var d=this._subPortions.length;if(t.numTriangles>0){var p,f=3*t.numTriangles;t.numVertices<=256?(p=c.perTriangleNumberPortionId8Bits,h.numIndices8Bits+=f,fc.totalPolygons8Bits+=t.numTriangles):t.numVertices<=65536?(p=c.perTriangleNumberPortionId16Bits,h.numIndices16Bits+=f,fc.totalPolygons16Bits+=t.numTriangles):(p=c.perTriangleNumberPortionId32Bits,h.numIndices32Bits+=f,fc.totalPolygons32Bits+=t.numTriangles),fc.totalPolygons+=t.numTriangles;for(var v=0;v0){var g,m=2*t.numEdges;t.numVertices<=256?(g=c.perEdgeNumberPortionId8Bits,h.numEdgeIndices8Bits+=m,fc.totalEdges8Bits+=t.numEdges):t.numVertices<=65536?(g=c.perEdgeNumberPortionId16Bits,h.numEdgeIndices16Bits+=m,fc.totalEdges16Bits+=t.numEdges):(g=c.perEdgeNumberPortionId32Bits,h.numEdgeIndices32Bits+=m,fc.totalEdges32Bits+=t.numEdges),fc.totalEdges+=t.numEdges;for(var _=0;_0&&(i.texturePerEdgeIdPortionIds8Bits=this._dtxTextureFactory.createTextureForPackedPortionIds(s,r.perEdgeNumberPortionId8Bits)),r.perEdgeNumberPortionId16Bits.length>0&&(i.texturePerEdgeIdPortionIds16Bits=this._dtxTextureFactory.createTextureForPackedPortionIds(s,r.perEdgeNumberPortionId16Bits)),r.perEdgeNumberPortionId32Bits.length>0&&(i.texturePerEdgeIdPortionIds32Bits=this._dtxTextureFactory.createTextureForPackedPortionIds(s,r.perEdgeNumberPortionId32Bits)),r.lenIndices8Bits>0&&(i.texturePerPolygonIdIndices8Bits=this._dtxTextureFactory.createTextureFor8BitIndices(s,r.indices8Bits,r.lenIndices8Bits)),r.lenIndices16Bits>0&&(i.texturePerPolygonIdIndices16Bits=this._dtxTextureFactory.createTextureFor16BitIndices(s,r.indices16Bits,r.lenIndices16Bits)),r.lenIndices32Bits>0&&(i.texturePerPolygonIdIndices32Bits=this._dtxTextureFactory.createTextureFor32BitIndices(s,r.indices32Bits,r.lenIndices32Bits)),r.lenEdgeIndices8Bits>0&&(i.texturePerPolygonIdEdgeIndices8Bits=this._dtxTextureFactory.createTextureFor8BitsEdgeIndices(s,r.edgeIndices8Bits,r.lenEdgeIndices8Bits)),r.lenEdgeIndices16Bits>0&&(i.texturePerPolygonIdEdgeIndices16Bits=this._dtxTextureFactory.createTextureFor16BitsEdgeIndices(s,r.edgeIndices16Bits,r.lenEdgeIndices16Bits)),r.lenEdgeIndices32Bits>0&&(i.texturePerPolygonIdEdgeIndices32Bits=this._dtxTextureFactory.createTextureFor32BitsEdgeIndices(s,r.edgeIndices32Bits,r.lenEdgeIndices32Bits)),i.finalize(),this._buffer=null,this._bucketGeometries={},this._finalized=!0,this._deferredSetFlagsDirty=!1,this._onSceneRendering=this.model.scene.on("rendering",(function(){e._deferredSetFlagsDirty&&e._uploadDeferredFlags(),e._numUpdatesInFrame=0}))}}},{key:"isEmpty",value:function(){return 0===this._numPortions}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Xe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,i,true),this._setFlags2(e,t,true)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags(),this._setDeferredFlags2()}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Xe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,i)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags2(e,t)}},{key:"_beginDeferredFlags",value:function(){this._deferredSetFlagsActive=!0}},{key:"_uploadDeferredFlags",value:function(){if(this._deferredSetFlagsActive=!1,this._deferredSetFlagsDirty){this._deferredSetFlagsDirty=!1;var e=this.model.scene.canvas.gl,t=this._dtxState;e.bindTexture(e.TEXTURE_2D,t.texturePerObjectColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectColorsAndFlags._textureWidth,t.texturePerObjectColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectColorsAndFlags._textureData)}}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions+=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions-=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){for(var i=this._portionToSubPortionsMap[e],s=0,r=i.length;s=10&&this._beginDeferredFlags(),console.info("_subPortionSetColor write through"),s.bindTexture(s.TEXTURE_2D,i.texturePerObjectColorsAndFlags._texture),s.texSubImage2D(s.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,s.RGBA_INTEGER,s.UNSIGNED_BYTE,yc)}},{key:"setTransparent",value:function(e,t,i){i?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,i)}},{key:"_setFlags",value:function(e,t,i){for(var s=arguments.length>3&&void 0!==arguments[3]&&arguments[3],r=this._portionToSubPortionsMap[e],n=0,o=r.length;n3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var r,n,o=!!(t&Qe),a=!!(t&ze),l=!!(t&We),u=!!(t&Ke),A=!!(t&Xe),c=!!(t&He),h=!!(t&Ve);r=!o||h||a||l&&!this.model.scene.highlightMaterial.glowThrough||u&&!this.model.scene.selectedMaterial.glowThrough?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,n=!o||h?oo.NOT_RENDERED:u?oo.SILHOUETTE_SELECTED:l?oo.SILHOUETTE_HIGHLIGHTED:a?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED;var d=0;d=!o||h?oo.NOT_RENDERED:u?oo.EDGES_SELECTED:l?oo.EDGES_HIGHLIGHTED:a?oo.EDGES_XRAYED:A?i?oo.EDGES_COLOR_TRANSPARENT:oo.EDGES_COLOR_OPAQUE:oo.NOT_RENDERED;var p=o&&!h&&c?oo.PICK:oo.NOT_RENDERED,f=this._dtxState,v=this.model.scene.canvas.gl;yc[0]=r,yc[1]=n,yc[2]=d,yc[3]=p,f.texturePerObjectColorsAndFlags._textureData.set(yc,32*e+8),this._deferredSetFlagsActive||s?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),v.bindTexture(v.TEXTURE_2D,f.texturePerObjectColorsAndFlags._texture),v.texSubImage2D(v.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,v.RGBA_INTEGER,v.UNSIGNED_BYTE,yc))}},{key:"_setDeferredFlags",value:function(){}},{key:"_setFlags2",value:function(e,t){for(var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=this._portionToSubPortionsMap[e],r=0,n=s.length;r2&&void 0!==arguments[2]&&arguments[2];if(!this._finalized)throw"Not finalized";var s=t&je?255:0,r=this._dtxState,n=this.model.scene.canvas.gl;yc[0]=s,yc[1]=0,yc[2]=1,yc[3]=2,r.texturePerObjectColorsAndFlags._textureData.set(yc,32*e+12),this._deferredSetFlagsActive||i?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),n.bindTexture(n.TEXTURE_2D,r.texturePerObjectColorsAndFlags._texture),n.texSubImage2D(n.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,n.RGBA_INTEGER,n.UNSIGNED_BYTE,yc))}},{key:"_setDeferredFlags2",value:function(){}},{key:"setOffset",value:function(e,t){for(var i=this._portionToSubPortionsMap[e],s=0,r=i.length;s=10&&this._beginDeferredFlags(),s.bindTexture(s.TEXTURE_2D,i.texturePerObjectOffsets._texture),s.texSubImage2D(s.TEXTURE_2D,0,0,e,1,1,s.RGB,s.FLOAT,bc))}},{key:"setMatrix",value:function(e,t){for(var i=this._portionToSubPortionsMap[e],s=0,r=i.length;s=10&&this._beginDeferredFlags(),s.bindTexture(s.TEXTURE_2D,i.texturePerObjectInstanceMatrices._texture),s.texSubImage2D(s.TEXTURE_2D,0,e%512*4,Math.floor(e/512),4,1,s.RGBA,s.FLOAT,_c))}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.withSAO&&this.model.saoEnabled?this._renderers.colorRendererWithSAO&&this._renderers.colorRendererWithSAO.drawLayer(t,this,oo.COLOR_OPAQUE):this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_OPAQUE))}},{key:"_updateBackfaceCull",value:function(e,t){var i=this.model.backfaces||e.sectioned;if(t.backfaces!==i){var s=t.gl;i?s.disable(s.CULL_FACE):s.enable(s.CULL_FACE),t.backfaces=i}}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_TRANSPARENT))}},{key:"drawDepth",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._renderers.depthRenderer&&this._renderers.depthRenderer.drawLayer(t,this,oo.COLOR_OPAQUE))}},{key:"drawNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._renderers.normalsRenderer&&this._renderers.normalsRenderer.drawLayer(t,this,oo.COLOR_OPAQUE))}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_XRAYED))}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_HIGHLIGHTED))}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_SELECTED))}},{key:"drawEdgesColorOpaque",value:function(e,t){this.model.scene.logarithmicDepthBufferEnabled?this.model.scene._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),this.model.scene._loggedWarning=!0):this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._renderers.edgesColorRenderer&&this._renderers.edgesColorRenderer.drawLayer(t,this,oo.EDGES_COLOR_OPAQUE)}},{key:"drawEdgesColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&0!==this._numTransparentLayerPortions&&this._renderers.edgesColorRenderer&&this._renderers.edgesColorRenderer.drawLayer(t,this,oo.EDGES_COLOR_TRANSPARENT)}},{key:"drawEdgesHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._renderers.edgesRenderer&&this._renderers.edgesRenderer.drawLayer(t,this,oo.EDGES_HIGHLIGHTED)}},{key:"drawEdgesSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._renderers.edgesRenderer&&this._renderers.edgesRenderer.drawLayer(t,this,oo.EDGES_SELECTED)}},{key:"drawEdgesXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._renderers.edgesRenderer&&this._renderers.edgesRenderer.drawLayer(t,this,oo.EDGES_XRAYED)}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.occlusionRenderer&&this._renderers.occlusionRenderer.drawLayer(t,this,oo.COLOR_OPAQUE))}},{key:"drawShadow",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.shadowRenderer&&this._renderers.shadowRenderer.drawLayer(t,this,oo.COLOR_OPAQUE))}},{key:"setPickMatrices",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.pickMeshRenderer&&this._renderers.pickMeshRenderer.drawLayer(t,this,oo.PICK))}},{key:"drawPickDepths",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.pickDepthRenderer&&this._renderers.pickDepthRenderer.drawLayer(t,this,oo.PICK))}},{key:"drawSnapInit",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.snapInitRenderer&&this._renderers.snapInitRenderer.drawLayer(t,this,oo.PICK))}},{key:"drawSnap",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.snapRenderer&&this._renderers.snapRenderer.drawLayer(t,this,oo.PICK))}},{key:"drawPickNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.pickNormalsRenderer&&this._renderers.pickNormalsRenderer.drawLayer(t,this,oo.PICK))}},{key:"destroy",value:function(){if(!this._destroyed){var e=this._state;e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),this.model.scene.off(this._onSceneRendering),e.destroy(),this._destroyed=!0}}}]),e}(),Pc=function(){function e(t){x(this,e),this.id=t.id,this.colorTexture=t.colorTexture,this.metallicRoughnessTexture=t.metallicRoughnessTexture,this.normalsTexture=t.normalsTexture,this.emissiveTexture=t.emissiveTexture,this.occlusionTexture=t.occlusionTexture}return C(e,[{key:"destroy",value:function(){}}]),e}(),Cc=function(){function e(t){x(this,e),this.id=t.id,this.texture=t.texture}return C(e,[{key:"destroy",value:function(){this.texture&&(this.texture.destroy(),this.texture=null)}}]),e}(),Mc={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}},Fc=function(){function e(t,i,s){x(this,e),this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=t,this.onProgress=i,this.onError=s}return C(e,[{key:"itemStart",value:function(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}},{key:"itemEnd",value:function(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}},{key:"itemError",value:function(e){void 0!==this.onError&&this.onError(e)}},{key:"resolveURL",value:function(e){return this.urlModifier?this.urlModifier(e):e}},{key:"setURLModifier",value:function(e){return this.urlModifier=e,this}},{key:"addHandler",value:function(e,t){return this.handlers.push(e,t),this}},{key:"removeHandler",value:function(e){var t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}},{key:"getHandler",value:function(e){for(var t=0,i=this.handlers.length;t0&&void 0!==arguments[0]?arguments[0]:4;x(this,e),this.pool=t,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}return C(e,[{key:"_initWorker",value:function(e){if(!this.workers[e]){var t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}},{key:"_getIdleWorker",value:function(){for(var e=0;e0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),Tc++}return this._transcoderPending}},{key:"transcode",value:function(e,t){var i=this,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(r,n){var o=s;i._init().then((function(){return i._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:o},e)})).then((function(e){var i=e.data,s=i.mipmaps,o=(i.width,i.height,i.format),a=i.type,l=i.error,u=i.dfdTransferFn,A=i.dfdFlags;if("error"===a)return n(l);t.setCompressedData({mipmaps:s,props:{format:o,minFilter:1===s.length?1006:1008,magFilter:1===s.length?1006:1008,encoding:2===u?3001:3e3,premultiplyAlpha:!!(1&A)}}),r()}))}))}},{key:"destroy",value:function(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),Tc--}}]),e}();Rc.BasisFormat={ETC1S:0,UASTC_4x4:1},Rc.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},Rc.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},Rc.BasisWorker=function(){var e,t,i,s=_EngineFormat,r=_TranscoderFormat,n=_BasisFormat;self.addEventListener("message",(function(o){var A,c=o.data;switch(c.type){case"init":e=c.config,A=c.transcoderBinary,t=new Promise((function(e){i={wasmBinary:A,onRuntimeInitialized:e},BASIS(i)})).then((function(){i.initializeBasis(),void 0===i.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((function(){try{for(var t=function(t){var o=new i.KTX2File(new Uint8Array(t));function A(){o.close(),o.delete()}if(!o.isValid())throw A(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");var c=o.isUASTC()?n.UASTC_4x4:n.ETC1S,h=o.getWidth(),d=o.getHeight(),p=o.getLevels(),f=o.getHasAlpha(),v=o.getDFDTransferFunc(),g=o.getDFDFlags(),m=function(t,i,o,A){for(var c,h,d=t===n.ETC1S?a:l,p=0;p=0;--r){var n=this.tryEntries[r],o=n.completion;if("root"===n.tryLoc)return s("end");if(n.tryLoc<=this.prev){var a=i.call(n,"catchLoc"),l=i.call(n,"finallyLoc");if(a&&l){if(this.prev=0;--s){var r=this.tryEntries[s];if(r.tryLoc<=this.prev&&i.call(r,"finallyLoc")&&this.prev=0;--t){var i=this.tryEntries[t];if(i.finallyLoc===e)return this.complete(i.completion,i.afterLoc),x(i),c}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var i=this.tryEntries[t];if(i.tryLoc===e){var s=i.completion;if("throw"===s.type){var r=s.arg;x(i)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,i){return this.delegate={iterator:C(e),resultName:t,nextLoc:i},"next"===this.method&&(this.arg=void 0),c}},e}function l(e,t,i,s,r,n,o){try{var a=e[n](o),l=a.value}catch(e){return void i(e)}a.done?t(l):Promise.resolve(l).then(s,r)}function u(e){return function(){var t=this,i=arguments;return new Promise((function(s,r){var n=e.apply(t,i);function o(e){l(n,s,r,o,a,"next",e)}function a(e){l(n,s,r,o,a,"throw",e)}o(void 0)}))}}function A(e){return function(e){if(Array.isArray(e))return p(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||d(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 c(e,t){var i="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!i){if(Array.isArray(e)||(i=d(e))||t&&e&&"number"==typeof e.length){i&&(e=i);var s=0,r=function(){};return{s:r,n:function(){return s>=e.length?{done:!0}:{done:!1,value:e[s++]}},e:function(e){throw e},f:r}}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 n,o=!0,a=!1;return{s:function(){i=i.call(e)},n:function(){var e=i.next();return o=e.done,e},e:function(e){a=!0,n=e},f:function(){try{o||null==i.return||i.return()}finally{if(a)throw n}}}}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var i=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==i)return;var s,r,n=[],o=!0,a=!1;try{for(i=i.call(e);!(o=(s=i.next()).done)&&(n.push(s.value),!t||n.length!==t);o=!0);}catch(e){a=!0,r=e}finally{try{o||null==i.return||i.return()}finally{if(a)throw r}}return n}(e,t)||d(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 d(e,t){if(e){if("string"==typeof e)return p(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?p(e,t):void 0}}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,s=new Array(t);i0&&void 0!==arguments[0]?arguments[0]:{};x(this,e),this._id=V.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!==i.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()})),i.items&&(this.items=i.items),this._hideOnAction=!1!==i.hideOnAction,this.context=i.context,this.enabled=!1!==i.enabled,this.hide()}return C(e,[{key:"on",value:function(e,t){var i=this._eventSubs[e];i||(i=[],this._eventSubs[e]=i),i.push(t)}},{key:"fire",value:function(e,t){var i=this._eventSubs[e];if(i)for(var s=0,r=i.length;s0,A=t._getNextId(),c=n.getTitle||function(){return n.title||""},h=n.doAction||n.callback||function(){},d=n.getEnabled||function(){return!0},p=n.getShown||function(){return!0},f=new G(A,c,h,d,p);if(f.parentMenu=r,l.items.push(f),u){var v=e(o);f.subMenu=v,v.parentItem=f}t._itemList.push(f),t._itemMap[f.id]=f},A=0,c=a.length;A'),s.push("
    "),i)for(var r=0,n=i.length;r'+d+" [MORE]"):s.push('
  • '+d+"
  • ")}}s.push("
"),s.push("");var p=s.join("");document.body.insertAdjacentHTML("beforeend",p);var f=document.querySelector("."+e.id);e.menuElement=f,f.style["border-radius"]="4px",f.style.display="none",f.style["z-index"]=3e5,f.style.background="white",f.style.border="1px solid black",f.style["box-shadow"]="0 4px 5px 0 gray",f.oncontextmenu=function(e){e.preventDefault()};var v=this,g=null;if(i)for(var m=0,_=i.length;m<_;m++){var y=i[m].items;if(y)for(var b=function(e,i){var s=y[e],r=s.subMenu;if(s.itemElement=document.getElementById(s.id),!s.itemElement)return console.error("ContextMenu item element not found: "+s.id),"continue";s.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault();var t=s.subMenu;if(t){if(g&&g.id!==t.id&&(v._hideMenu(g.id),g=null),!1!==s.enabled){var i=s.itemElement,r=t.menuElement,n=i.getBoundingClientRect();r.getBoundingClientRect();n.right+200>window.innerWidth?v._showMenu(t.id,n.left-200,n.top-1):v._showMenu(t.id,n.right-5,n.top-1),g=t}}else g&&(v._hideMenu(g.id),g=null)})),r||(s.itemElement.addEventListener("click",(function(e){e.preventDefault(),v._context&&!1!==s.enabled&&(s.doAction&&s.doAction(v._context),t._hideOnAction?v.hide():(v._updateItemsTitles(),v._updateItemsEnabledStatus()))})),s.itemElement.addEventListener("mouseup",(function(e){3===e.which&&(e.preventDefault(),v._context&&!1!==s.enabled&&(s.doAction&&s.doAction(v._context),t._hideOnAction?v.hide():(v._updateItemsTitles(),v._updateItemsEnabledStatus())))})),s.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault(),!1!==s.enabled&&s.doHover&&s.doHover(v._context)})))},B=0,w=y.length;Bwindow.innerHeight&&(i=window.innerHeight-s),t+r>window.innerWidth&&(t=window.innerWidth-r),e.style.left=t+"px",e.style.top=i+"px"}},{key:"_hideMenuElement",value:function(e){e.style.display="none"}}]),e}(),W=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this.viewer=t,this.scene=this.viewer.scene,this._lensCursorDiv=document.createElement("div"),this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._lensCursorDiv,this.viewer.scene.canvas.canvas),this._lensCursorDiv.style.background="pink",this._lensCursorDiv.style.border="2px solid red",this._lensCursorDiv.style.borderRadius="20px",this._lensCursorDiv.style.width="10px",this._lensCursorDiv.style.height="10px",this._lensCursorDiv.style.margin="-200px -200px",this._lensCursorDiv.style.zIndex="100000",this._lensCursorDiv.style.position="absolute",this._lensCursorDiv.style.pointerEvents="none",this._lensContainer=document.createElement("div"),this._lensContainer.style.border="1px solid black",this._lensContainer.style.background="white",this._lensContainer.style.borderRadius="50%",this._lensContainer.style.width="300px",this._lensContainer.style.height="300px",this._lensContainer.style.marginTop="85px",this._lensContainer.style.marginLeft="25px",this._lensContainer.style.zIndex="15000",this._lensContainer.style.position="absolute",this._lensContainer.style.pointerEvents="none",this._lensContainer.style.visibility="hidden",this._lensCanvas=document.createElement("canvas"),this._lensCanvas.style.borderRadius="50%",this._lensCanvas.style.width="300px",this._lensCanvas.style.height="300px",this._lensCanvas.style.zIndex="15000",this._lensCanvas.style.pointerEvents="none",document.body.appendChild(this._lensContainer),this._lensContainer.appendChild(this._lensCanvas),this._lensCanvasContext=this._lensCanvas.getContext("2d"),this._canvasElement=this.viewer.scene.canvas.canvas,this._canvasPos=null,this._snappedCanvasPos=null,this._lensPosToggle=!0,this._zoomLevel=s.zoomLevel||2,this._active=!1!==s.active,this._visible=!1,this._snapped=!1,this._onViewerRendering=this.viewer.scene.on("rendering",(function(){i._active&&i._visible&&i.update()}))}return C(e,[{key:"update",value:function(){if(this._active&&this._visible&&this._canvasPos){var e=this._lensContainer.getBoundingClientRect(),t=this._canvasElement.getBoundingClientRect(),i=this._canvasPos[0]e.left&&this._canvasPos[1]e.top;this._lensContainer.style.marginLeft="25px",i&&(this._lensPosToggle?this._lensContainer.style.marginTop="".concat(t.bottom-t.top-this._lensCanvas.height-85,"px"):this._lensContainer.style.marginTop="85px",this._lensPosToggle=!this._lensPosToggle),this._lensCanvasContext.clearRect(0,0,this._lensCanvas.width,this._lensCanvas.height);var s=Math.max(this._lensCanvas.width,this._lensCanvas.height)/this._zoomLevel;this._lensCanvasContext.drawImage(this._canvasElement,this._canvasPos[0]-s/2,this._canvasPos[1]-s/2,s,s,0,0,this._lensCanvas.width,this._lensCanvas.height);var r=[(e.left+e.right)/2,(e.top+e.bottom)/2];if(this._snappedCanvasPos){var n=this._snappedCanvasPos[0]-this._canvasPos[0],o=this._snappedCanvasPos[1]-this._canvasPos[1];this._lensCursorDiv.style.marginLeft="".concat(r[0]+n*this._zoomLevel-10,"px"),this._lensCursorDiv.style.marginTop="".concat(r[1]+o*this._zoomLevel-10,"px")}else this._lensCursorDiv.style.marginLeft="".concat(r[0]-10,"px"),this._lensCursorDiv.style.marginTop="".concat(r[1]-10,"px")}}},{key:"zoomFactor",get:function(){return this._zoomFactor},set:function(e){this._zoomFactor=e,this.update()}},{key:"canvasPos",get:function(){return this._canvasPos},set:function(e){this._canvasPos=e,this.update()}},{key:"snappedCanvasPos",get:function(){return this._snappedCanvasPos},set:function(e){this._snappedCanvasPos=e,this.update()}},{key:"snapped",get:function(){return this._snapped},set:function(e){this._snapped=e,e?(this._lensCursorDiv.style.background="greenyellow",this._lensCursorDiv.style.border="2px solid green"):(this._lensCursorDiv.style.background="pink",this._lensCursorDiv.style.border="2px solid red")}},{key:"active",get:function(){return this._active},set:function(e){this._active=e,this._lensContainer.style.visibility=e&&this._visible?"visible":"hidden",e&&this._visible||(this._lensCursorDiv.style.marginLeft="-100px",this._lensCursorDiv.style.marginTop="-100px"),this.update()}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=e,this._lensContainer.style.visibility=e&&this._active?"visible":"hidden",e&&this._active||(this._lensCursorDiv.style.marginLeft="-100px",this._lensCursorDiv.style.marginTop="-100px"),this.update()}},{key:"destroy",value:function(){this._destroyed||(this.viewer.scene.off(this._onViewerRendering),this._lensContainer.removeChild(this._lensCanvas),document.body.removeChild(this._lensContainer),this._destroyed=!0)}}]),e}(),K=!0,X=K?Float64Array:Float32Array,J=new X(3),Y=new X(16),Z=new X(16),q=new X(4),$={setDoublePrecisionEnabled:function(e){X=(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 i=t.indexOf("#");return i===e.length&&t.startsWith(e)?t.substring(i+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 X(e||2)},vec3:function(e){return new X(e||3)},vec4:function(e){return new X(e||4)},mat3:function(e){return new X(e||9)},mat3ToMat4:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new X(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 X(e||16)},mat4ToMat3:function(e,t){},doublesToFloats:function(e,t,i){for(var s=new X(2),r=0,n=e.length;r>8&255]+e[t>>16&255]+e[t>>24&255],"-").concat(e[255&i]).concat(e[i>>8&255],"-").concat(e[i>>16&15|64]).concat(e[i>>24&255],"-").concat(e[63&s|128]).concat(e[s>>8&255],"-").concat(e[s>>16&255]).concat(e[s>>24&255]).concat(e[255&r]).concat(e[r>>8&255]).concat(e[r>>16&255]).concat(e[r>>24&255])}}(),clamp:function(e,t,i){return Math.max(t,Math.min(i,e))},fmod:function(e,t){if(e1?1:i,Math.acos(i)},vec3FromMat4Scale:function(){var e=new X(3);return function(t,i){return e[0]=t[0],e[1]=t[1],e[2]=t[2],i[0]=$.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],i[1]=$.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],i[2]=$.lenVec3(e),i}}(),vecToArray:function(){function e(e){return Math.round(1e5*e)/1e5}return function(t){for(var i=0,s=(t=Array.prototype.slice.call(t)).length;i0&&void 0!==arguments[0]?arguments[0]:new X(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 X(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,i){return i||(i=e),i[0]=e[0]+t[0],i[1]=e[1]+t[1],i[2]=e[2]+t[2],i[3]=e[3]+t[3],i[4]=e[4]+t[4],i[5]=e[5]+t[5],i[6]=e[6]+t[6],i[7]=e[7]+t[7],i[8]=e[8]+t[8],i[9]=e[9]+t[9],i[10]=e[10]+t[10],i[11]=e[11]+t[11],i[12]=e[12]+t[12],i[13]=e[13]+t[13],i[14]=e[14]+t[14],i[15]=e[15]+t[15],i},addMat4Scalar:function(e,t,i){return i||(i=e),i[0]=e[0]+t,i[1]=e[1]+t,i[2]=e[2]+t,i[3]=e[3]+t,i[4]=e[4]+t,i[5]=e[5]+t,i[6]=e[6]+t,i[7]=e[7]+t,i[8]=e[8]+t,i[9]=e[9]+t,i[10]=e[10]+t,i[11]=e[11]+t,i[12]=e[12]+t,i[13]=e[13]+t,i[14]=e[14]+t,i[15]=e[15]+t,i},addScalarMat4:function(e,t,i){return $.addMat4Scalar(t,e,i)},subMat4:function(e,t,i){return i||(i=e),i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],i[3]=e[3]-t[3],i[4]=e[4]-t[4],i[5]=e[5]-t[5],i[6]=e[6]-t[6],i[7]=e[7]-t[7],i[8]=e[8]-t[8],i[9]=e[9]-t[9],i[10]=e[10]-t[10],i[11]=e[11]-t[11],i[12]=e[12]-t[12],i[13]=e[13]-t[13],i[14]=e[14]-t[14],i[15]=e[15]-t[15],i},subMat4Scalar:function(e,t,i){return i||(i=e),i[0]=e[0]-t,i[1]=e[1]-t,i[2]=e[2]-t,i[3]=e[3]-t,i[4]=e[4]-t,i[5]=e[5]-t,i[6]=e[6]-t,i[7]=e[7]-t,i[8]=e[8]-t,i[9]=e[9]-t,i[10]=e[10]-t,i[11]=e[11]-t,i[12]=e[12]-t,i[13]=e[13]-t,i[14]=e[14]-t,i[15]=e[15]-t,i},subScalarMat4:function(e,t,i){return i||(i=t),i[0]=e-t[0],i[1]=e-t[1],i[2]=e-t[2],i[3]=e-t[3],i[4]=e-t[4],i[5]=e-t[5],i[6]=e-t[6],i[7]=e-t[7],i[8]=e-t[8],i[9]=e-t[9],i[10]=e-t[10],i[11]=e-t[11],i[12]=e-t[12],i[13]=e-t[13],i[14]=e-t[14],i[15]=e-t[15],i},mulMat4:function(e,t,i){i||(i=e);var s=e[0],r=e[1],n=e[2],o=e[3],a=e[4],l=e[5],u=e[6],A=e[7],c=e[8],h=e[9],d=e[10],p=e[11],f=e[12],v=e[13],g=e[14],m=e[15],_=t[0],y=t[1],b=t[2],B=t[3],w=t[4],x=t[5],P=t[6],C=t[7],M=t[8],F=t[9],E=t[10],k=t[11],I=t[12],D=t[13],S=t[14],T=t[15];return i[0]=_*s+y*a+b*c+B*f,i[1]=_*r+y*l+b*h+B*v,i[2]=_*n+y*u+b*d+B*g,i[3]=_*o+y*A+b*p+B*m,i[4]=w*s+x*a+P*c+C*f,i[5]=w*r+x*l+P*h+C*v,i[6]=w*n+x*u+P*d+C*g,i[7]=w*o+x*A+P*p+C*m,i[8]=M*s+F*a+E*c+k*f,i[9]=M*r+F*l+E*h+k*v,i[10]=M*n+F*u+E*d+k*g,i[11]=M*o+F*A+E*p+k*m,i[12]=I*s+D*a+S*c+T*f,i[13]=I*r+D*l+S*h+T*v,i[14]=I*n+D*u+S*d+T*g,i[15]=I*o+D*A+S*p+T*m,i},mulMat3:function(e,t,i){i||(i=new X(9));var s=e[0],r=e[3],n=e[6],o=e[1],a=e[4],l=e[7],u=e[2],A=e[5],c=e[8],h=t[0],d=t[3],p=t[6],f=t[1],v=t[4],g=t[7],m=t[2],_=t[5],y=t[8];return i[0]=s*h+r*f+n*m,i[3]=s*d+r*v+n*_,i[6]=s*p+r*g+n*y,i[1]=o*h+a*f+l*m,i[4]=o*d+a*v+l*_,i[7]=o*p+a*g+l*y,i[2]=u*h+A*f+c*m,i[5]=u*d+A*v+c*_,i[8]=u*p+A*g+c*y,i},mulMat4Scalar:function(e,t,i){return i||(i=e),i[0]=e[0]*t,i[1]=e[1]*t,i[2]=e[2]*t,i[3]=e[3]*t,i[4]=e[4]*t,i[5]=e[5]*t,i[6]=e[6]*t,i[7]=e[7]*t,i[8]=e[8]*t,i[9]=e[9]*t,i[10]=e[10]*t,i[11]=e[11]*t,i[12]=e[12]*t,i[13]=e[13]*t,i[14]=e[14]*t,i[15]=e[15]*t,i},mulMat4v4:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),s=t[0],r=t[1],n=t[2],o=t[3];return i[0]=e[0]*s+e[4]*r+e[8]*n+e[12]*o,i[1]=e[1]*s+e[5]*r+e[9]*n+e[13]*o,i[2]=e[2]*s+e[6]*r+e[10]*n+e[14]*o,i[3]=e[3]*s+e[7]*r+e[11]*n+e[15]*o,i},transposeMat4:function(e,t){var i=e[4],s=e[14],r=e[8],n=e[13],o=e[12],a=e[9];if(!t||e===t){var l=e[1],u=e[2],A=e[3],c=e[6],h=e[7],d=e[11];return e[1]=i,e[2]=r,e[3]=o,e[4]=l,e[6]=a,e[7]=n,e[8]=u,e[9]=c,e[11]=s,e[12]=A,e[13]=h,e[14]=d,e}return t[0]=e[0],t[1]=i,t[2]=r,t[3]=o,t[4]=e[1],t[5]=e[5],t[6]=a,t[7]=n,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=s,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 i=e[1],s=e[2],r=e[5];t[1]=e[3],t[2]=e[6],t[3]=i,t[5]=e[7],t[6]=s,t[7]=r}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],i=e[1],s=e[2],r=e[3],n=e[4],o=e[5],a=e[6],l=e[7],u=e[8],A=e[9],c=e[10],h=e[11],d=e[12],p=e[13],f=e[14],v=e[15];return d*A*a*r-u*p*a*r-d*o*c*r+n*p*c*r+u*o*f*r-n*A*f*r-d*A*s*l+u*p*s*l+d*i*c*l-t*p*c*l-u*i*f*l+t*A*f*l+d*o*s*h-n*p*s*h-d*i*a*h+t*p*a*h+n*i*f*h-t*o*f*h-u*o*s*v+n*A*s*v+u*i*a*v-t*A*a*v-n*i*c*v+t*o*c*v},inverseMat4:function(e,t){t||(t=e);var i=e[0],s=e[1],r=e[2],n=e[3],o=e[4],a=e[5],l=e[6],u=e[7],A=e[8],c=e[9],h=e[10],d=e[11],p=e[12],f=e[13],v=e[14],g=e[15],m=i*a-s*o,_=i*l-r*o,y=i*u-n*o,b=s*l-r*a,B=s*u-n*a,w=r*u-n*l,x=A*f-c*p,P=A*v-h*p,C=A*g-d*p,M=c*v-h*f,F=c*g-d*f,E=h*g-d*v,k=1/(m*E-_*F+y*M+b*C-B*P+w*x);return t[0]=(a*E-l*F+u*M)*k,t[1]=(-s*E+r*F-n*M)*k,t[2]=(f*w-v*B+g*b)*k,t[3]=(-c*w+h*B-d*b)*k,t[4]=(-o*E+l*C-u*P)*k,t[5]=(i*E-r*C+n*P)*k,t[6]=(-p*w+v*y-g*_)*k,t[7]=(A*w-h*y+d*_)*k,t[8]=(o*F-a*C+u*x)*k,t[9]=(-i*F+s*C-n*x)*k,t[10]=(p*B-f*y+g*m)*k,t[11]=(-A*B+c*y-d*m)*k,t[12]=(-o*M+a*P-l*x)*k,t[13]=(i*M-s*P+r*x)*k,t[14]=(-p*b+f*_-v*m)*k,t[15]=(A*b-c*_+h*m)*k,t},traceMat4:function(e){return e[0]+e[5]+e[10]+e[15]},translationMat4v:function(e,t){var i=t||$.identityMat4();return i[12]=e[0],i[13]=e[1],i[14]=e[2],i},translationMat3v:function(e,t){var i=t||$.identityMat3();return i[6]=e[0],i[7]=e[1],i},translationMat4c:(O=new X(3),function(e,t,i,s){return O[0]=e,O[1]=t,O[2]=i,$.translationMat4v(O,s)}),translationMat4s:function(e,t){return $.translationMat4c(e,e,e,t)},translateMat4v:function(e,t){return $.translateMat4c(e[0],e[1],e[2],t)},translateMat4c:function(e,t,i,s){var r=s[3];s[0]+=r*e,s[1]+=r*t,s[2]+=r*i;var n=s[7];s[4]+=n*e,s[5]+=n*t,s[6]+=n*i;var o=s[11];s[8]+=o*e,s[9]+=o*t,s[10]+=o*i;var a=s[15];return s[12]+=a*e,s[13]+=a*t,s[14]+=a*i,s},setMat4Translation:function(e,t,i){return i[0]=e[0],i[1]=e[1],i[2]=e[2],i[3]=e[3],i[4]=e[4],i[5]=e[5],i[6]=e[6],i[7]=e[7],i[8]=e[8],i[9]=e[9],i[10]=e[10],i[11]=e[11],i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=e[15],i},rotationMat4v:function(e,t,i){var s,r,n,o,a,l,u=$.normalizeVec4([t[0],t[1],t[2],0],[]),A=Math.sin(e),c=Math.cos(e),h=1-c,d=u[0],p=u[1],f=u[2];return s=d*p,r=p*f,n=f*d,o=d*A,a=p*A,l=f*A,(i=i||$.mat4())[0]=h*d*d+c,i[1]=h*s+l,i[2]=h*n-a,i[3]=0,i[4]=h*s-l,i[5]=h*p*p+c,i[6]=h*r+o,i[7]=0,i[8]=h*n+a,i[9]=h*r-o,i[10]=h*f*f+c,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i},rotationMat4c:function(e,t,i,s,r){return $.rotationMat4v(e,[t,i,s],r)},scalingMat4v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.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]:$.identityMat3();return t[0]=e[0],t[4]=e[1],t},scalingMat4c:function(){var e=new X(3);return function(t,i,s,r){return e[0]=t,e[1]=i,e[2]=s,$.scalingMat4v(e,r)}}(),scaleMat4c:function(e,t,i,s){return s[0]*=e,s[4]*=t,s[8]*=i,s[1]*=e,s[5]*=t,s[9]*=i,s[2]*=e,s[6]*=t,s[10]*=i,s[3]*=e,s[7]*=t,s[11]*=i,s},scaleMat4v:function(e,t){var i=e[0],s=e[1],r=e[2];return t[0]*=i,t[4]*=s,t[8]*=r,t[1]*=i,t[5]*=s,t[9]*=r,t[2]*=i,t[6]*=s,t[10]*=r,t[3]*=i,t[7]*=s,t[11]*=r,t},scalingMat4s:function(e){return $.scalingMat4c(e,e,e)},rotationTranslationMat4:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.mat4(),s=e[0],r=e[1],n=e[2],o=e[3],a=s+s,l=r+r,u=n+n,A=s*a,c=s*l,h=s*u,d=r*l,p=r*u,f=n*u,v=o*a,g=o*l,m=o*u;return i[0]=1-(d+f),i[1]=c+m,i[2]=h-g,i[3]=0,i[4]=c-m,i[5]=1-(A+f),i[6]=p+v,i[7]=0,i[8]=h+g,i[9]=p-v,i[10]=1-(A+d),i[11]=0,i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=1,i},mat4ToEuler:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),s=$.clamp,r=e[0],n=e[4],o=e[8],a=e[1],l=e[5],u=e[9],A=e[2],c=e[6],h=e[10];return"XYZ"===t?(i[1]=Math.asin(s(o,-1,1)),Math.abs(o)<.99999?(i[0]=Math.atan2(-u,h),i[2]=Math.atan2(-n,r)):(i[0]=Math.atan2(c,l),i[2]=0)):"YXZ"===t?(i[0]=Math.asin(-s(u,-1,1)),Math.abs(u)<.99999?(i[1]=Math.atan2(o,h),i[2]=Math.atan2(a,l)):(i[1]=Math.atan2(-A,r),i[2]=0)):"ZXY"===t?(i[0]=Math.asin(s(c,-1,1)),Math.abs(c)<.99999?(i[1]=Math.atan2(-A,h),i[2]=Math.atan2(-n,l)):(i[1]=0,i[2]=Math.atan2(a,r))):"ZYX"===t?(i[1]=Math.asin(-s(A,-1,1)),Math.abs(A)<.99999?(i[0]=Math.atan2(c,h),i[2]=Math.atan2(a,r)):(i[0]=0,i[2]=Math.atan2(-n,l))):"YZX"===t?(i[2]=Math.asin(s(a,-1,1)),Math.abs(a)<.99999?(i[0]=Math.atan2(-u,l),i[1]=Math.atan2(-A,r)):(i[0]=0,i[1]=Math.atan2(o,h))):"XZY"===t&&(i[2]=Math.asin(-s(n,-1,1)),Math.abs(n)<.99999?(i[0]=Math.atan2(c,l),i[1]=Math.atan2(o,r)):(i[0]=Math.atan2(-u,h),i[1]=0)),i},composeMat4:function(e,t,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:$.mat4();return $.quaternionToRotationMat4(t,s),$.scaleMat4v(i,s),$.translateMat4v(e,s),s},decomposeMat4:function(){var e=new X(3),t=new X(16);return function(i,s,r,n){e[0]=i[0],e[1]=i[1],e[2]=i[2];var o=$.lenVec3(e);e[0]=i[4],e[1]=i[5],e[2]=i[6];var a=$.lenVec3(e);e[8]=i[8],e[9]=i[9],e[10]=i[10];var l=$.lenVec3(e);$.determinantMat4(i)<0&&(o=-o),s[0]=i[12],s[1]=i[13],s[2]=i[14],t.set(i);var u=1/o,A=1/a,c=1/l;return t[0]*=u,t[1]*=u,t[2]*=u,t[4]*=A,t[5]*=A,t[6]*=A,t[8]*=c,t[9]*=c,t[10]*=c,$.mat4ToQuaternion(t,r),n[0]=o,n[1]=a,n[2]=l,this}}(),getColMat4:function(e,t){var i=4*t;return[e[i],e[i+1],e[i+2],e[i+3]]},setRowMat4:function(e,t,i){e[t]=i[0],e[t+4]=i[1],e[t+8]=i[2],e[t+12]=i[3]},lookAtMat4v:function(e,t,i,s){s||(s=$.mat4());var r,n,o,a,l,u,A,c,h,d,p=e[0],f=e[1],v=e[2],g=i[0],m=i[1],_=i[2],y=t[0],b=t[1],B=t[2];return p===y&&f===b&&v===B?$.identityMat4():(r=p-y,n=f-b,o=v-B,a=m*(o*=d=1/Math.sqrt(r*r+n*n+o*o))-_*(n*=d),l=_*(r*=d)-g*o,u=g*n-m*r,(d=Math.sqrt(a*a+l*l+u*u))?(a*=d=1/d,l*=d,u*=d):(a=0,l=0,u=0),A=n*u-o*l,c=o*a-r*u,h=r*l-n*a,(d=Math.sqrt(A*A+c*c+h*h))?(A*=d=1/d,c*=d,h*=d):(A=0,c=0,h=0),s[0]=a,s[1]=A,s[2]=r,s[3]=0,s[4]=l,s[5]=c,s[6]=n,s[7]=0,s[8]=u,s[9]=h,s[10]=o,s[11]=0,s[12]=-(a*p+l*f+u*v),s[13]=-(A*p+c*f+h*v),s[14]=-(r*p+n*f+o*v),s[15]=1,s)},lookAtMat4c:function(e,t,i,s,r,n,o,a,l){return $.lookAtMat4v([e,t,i],[s,r,n],[o,a,l],[])},orthoMat4c:function(e,t,i,s,r,n,o){o||(o=$.mat4());var a=t-e,l=s-i,u=n-r;return o[0]=2/a,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2/l,o[6]=0,o[7]=0,o[8]=0,o[9]=0,o[10]=-2/u,o[11]=0,o[12]=-(e+t)/a,o[13]=-(s+i)/l,o[14]=-(n+r)/u,o[15]=1,o},frustumMat4v:function(e,t,i){i||(i=$.mat4());var s=[e[0],e[1],e[2],0],r=[t[0],t[1],t[2],0];$.addVec4(r,s,Y),$.subVec4(r,s,Z);var n=2*s[2],o=Z[0],a=Z[1],l=Z[2];return i[0]=n/o,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=n/a,i[6]=0,i[7]=0,i[8]=Y[0]/o,i[9]=Y[1]/a,i[10]=-Y[2]/l,i[11]=-1,i[12]=0,i[13]=0,i[14]=-n*r[2]/l,i[15]=0,i},frustumMat4:function(e,t,i,s,r,n,o){o||(o=$.mat4());var a=t-e,l=s-i,u=n-r;return o[0]=2*r/a,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2*r/l,o[6]=0,o[7]=0,o[8]=(t+e)/a,o[9]=(s+i)/l,o[10]=-(n+r)/u,o[11]=-1,o[12]=0,o[13]=0,o[14]=-n*r*2/u,o[15]=0,o},perspectiveMat4:function(e,t,i,s,r){var n=[],o=[];return n[2]=i,o[2]=s,o[1]=n[2]*Math.tan(e/2),n[1]=-o[1],o[0]=o[1]*t,n[0]=-o[0],$.frustumMat4v(n,o,r)},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 i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec3(),s=t[0],r=t[1],n=t[2];return i[0]=e[0]*s+e[4]*r+e[8]*n+e[12],i[1]=e[1]*s+e[5]*r+e[9]*n+e[13],i[2]=e[2]*s+e[6]*r+e[10]*n+e[14],i},transformPoint4:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4();return i[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],i[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],i[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],i[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],i},transformPoints3:function(e,t,i){for(var s,r,n,o,a,l=i||[],u=t.length,A=e[0],c=e[1],h=e[2],d=e[3],p=e[4],f=e[5],v=e[6],g=e[7],m=e[8],_=e[9],y=e[10],b=e[11],B=e[12],w=e[13],x=e[14],P=e[15],C=0;C2&&void 0!==arguments[2]?arguments[2]:t,a=t.length,l=e[0],u=e[1],A=e[2];e[3];var c=e[4],h=e[5],d=e[6];e[7];var p=e[8],f=e[9],v=e[10];e[11];var g=e[12],m=e[13],_=e[14];for(e[15],i=0;i2&&void 0!==arguments[2]?arguments[2]:t,a=t.length,l=e[0],u=e[1],A=e[2],c=e[3],h=e[4],d=e[5],p=e[6],f=e[7],v=e[8],g=e[9],m=e[10],_=e[11],y=e[12],b=e[13],B=e[14],w=e[15];for(i=0;i3&&void 0!==arguments[3]?arguments[3]:e,r=Math.cos(i),n=Math.sin(i),o=e[0]-t[0],a=e[1]-t[1];return s[0]=o*r-a*n+t[0],s[1]=o*n+a*r+t[1],e},rotateVec3X:function(e,t,i,s){var r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[0],n[1]=r[1]*Math.cos(i)-r[2]*Math.sin(i),n[2]=r[1]*Math.sin(i)+r[2]*Math.cos(i),s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s},rotateVec3Y:function(e,t,i,s){var r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[2]*Math.sin(i)+r[0]*Math.cos(i),n[1]=r[1],n[2]=r[2]*Math.cos(i)-r[0]*Math.sin(i),s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s},rotateVec3Z:function(e,t,i,s){var r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[0]*Math.cos(i)-r[1]*Math.sin(i),n[1]=r[0]*Math.sin(i)+r[1]*Math.cos(i),n[2]=r[2],s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s},projectVec4:function(e,t){var i=1/e[3];return(t=t||$.vec2())[0]=e[0]*i,t[1]=e[1]*i,t},unprojectVec3:(R=new X(16),L=new X(16),U=new X(16),function(e,t,i,s){return this.transformVec3(this.mulMat4(this.inverseMat4(t,R),this.inverseMat4(i,L),U),e,s)}),lerpVec3:function(e,t,i,s,r,n){var o=n||$.vec3(),a=(e-t)/(i-t);return o[0]=s[0]+a*(r[0]-s[0]),o[1]=s[1]+a*(r[1]-s[1]),o[2]=s[2]+a*(r[2]-s[2]),o},lerpMat4:function(e,t,i,s,r,n){var o=n||$.mat4(),a=(e-t)/(i-t);return o[0]=s[0]+a*(r[0]-s[0]),o[1]=s[1]+a*(r[1]-s[1]),o[2]=s[2]+a*(r[2]-s[2]),o[3]=s[3]+a*(r[3]-s[3]),o[4]=s[4]+a*(r[4]-s[4]),o[5]=s[5]+a*(r[5]-s[5]),o[6]=s[6]+a*(r[6]-s[6]),o[7]=s[7]+a*(r[7]-s[7]),o[8]=s[8]+a*(r[8]-s[8]),o[9]=s[9]+a*(r[9]-s[9]),o[10]=s[10]+a*(r[10]-s[10]),o[11]=s[11]+a*(r[11]-s[11]),o[12]=s[12]+a*(r[12]-s[12]),o[13]=s[13]+a*(r[13]-s[13]),o[14]=s[14]+a*(r[14]-s[14]),o[15]=s[15]+a*(r[15]-s[15]),o},flatten:function(e){var t,i,s,r,n,o=[];for(t=0,i=e.length;t0&&void 0!==arguments[0]?arguments[0]:$.vec4();return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},eulerToQuaternion:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),s=e[0]*$.DEGTORAD/2,r=e[1]*$.DEGTORAD/2,n=e[2]*$.DEGTORAD/2,o=Math.cos(s),a=Math.cos(r),l=Math.cos(n),u=Math.sin(s),A=Math.sin(r),c=Math.sin(n);return"XYZ"===t?(i[0]=u*a*l+o*A*c,i[1]=o*A*l-u*a*c,i[2]=o*a*c+u*A*l,i[3]=o*a*l-u*A*c):"YXZ"===t?(i[0]=u*a*l+o*A*c,i[1]=o*A*l-u*a*c,i[2]=o*a*c-u*A*l,i[3]=o*a*l+u*A*c):"ZXY"===t?(i[0]=u*a*l-o*A*c,i[1]=o*A*l+u*a*c,i[2]=o*a*c+u*A*l,i[3]=o*a*l-u*A*c):"ZYX"===t?(i[0]=u*a*l-o*A*c,i[1]=o*A*l+u*a*c,i[2]=o*a*c-u*A*l,i[3]=o*a*l+u*A*c):"YZX"===t?(i[0]=u*a*l+o*A*c,i[1]=o*A*l+u*a*c,i[2]=o*a*c-u*A*l,i[3]=o*a*l-u*A*c):"XZY"===t&&(i[0]=u*a*l-o*A*c,i[1]=o*A*l-u*a*c,i[2]=o*a*c+u*A*l,i[3]=o*a*l+u*A*c),i},mat4ToQuaternion:function(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec4(),s=e[0],r=e[4],n=e[8],o=e[1],a=e[5],l=e[9],u=e[2],A=e[6],c=e[10],h=s+a+c;return h>0?(t=.5/Math.sqrt(h+1),i[3]=.25/t,i[0]=(A-l)*t,i[1]=(n-u)*t,i[2]=(o-r)*t):s>a&&s>c?(t=2*Math.sqrt(1+s-a-c),i[3]=(A-l)/t,i[0]=.25*t,i[1]=(r+o)/t,i[2]=(n+u)/t):a>c?(t=2*Math.sqrt(1+a-s-c),i[3]=(n-u)/t,i[0]=(r+o)/t,i[1]=.25*t,i[2]=(l+A)/t):(t=2*Math.sqrt(1+c-s-a),i[3]=(o-r)/t,i[0]=(n+u)/t,i[1]=(l+A)/t,i[2]=.25*t),i},vec3PairToQuaternion:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),s=Math.sqrt($.dotVec3(e,e)*$.dotVec3(t,t)),r=s+$.dotVec3(e,t);return r<1e-8*s?(r=0,Math.abs(e[0])>Math.abs(e[2])?(i[0]=-e[1],i[1]=e[0],i[2]=0):(i[0]=0,i[1]=-e[2],i[2]=e[1])):$.cross3Vec3(e,t,i),i[3]=r,$.normalizeQuaternion(i)},angleAxisToQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec4(),i=e[3]/2,s=Math.sin(i);return t[0]=s*e[0],t[1]=s*e[1],t[2]=s*e[2],t[3]=Math.cos(i),t},quaternionToEuler:function(){var e=new X(16);return function(t,i,s){return s=s||$.vec3(),$.quaternionToRotationMat4(t,e),$.mat4ToEuler(e,i,s),s}}(),mulQuaternions:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),s=e[0],r=e[1],n=e[2],o=e[3],a=t[0],l=t[1],u=t[2],A=t[3];return i[0]=o*a+s*A+r*u-n*l,i[1]=o*l+r*A+n*a-s*u,i[2]=o*u+n*A+s*l-r*a,i[3]=o*A-s*a-r*l-n*u,i},vec3ApplyQuaternion:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec3(),s=t[0],r=t[1],n=t[2],o=e[0],a=e[1],l=e[2],u=e[3],A=u*s+a*n-l*r,c=u*r+l*s-o*n,h=u*n+o*r-a*s,d=-o*s-a*r-l*n;return i[0]=A*u+d*-o+c*-l-h*-a,i[1]=c*u+d*-a+h*-o-A*-l,i[2]=h*u+d*-l+A*-a-c*-o,i},quaternionToMat4:function(e,t){t=$.identityMat4(t);var i=e[0],s=e[1],r=e[2],n=e[3],o=2*i,a=2*s,l=2*r,u=o*n,A=a*n,c=l*n,h=o*i,d=a*i,p=l*i,f=a*s,v=l*s,g=l*r;return t[0]=1-(f+g),t[1]=d+c,t[2]=p-A,t[4]=d-c,t[5]=1-(h+g),t[6]=v+u,t[8]=p+A,t[9]=v-u,t[10]=1-(h+f),t},quaternionToRotationMat4:function(e,t){var i=e[0],s=e[1],r=e[2],n=e[3],o=i+i,a=s+s,l=r+r,u=i*o,A=i*a,c=i*l,h=s*a,d=s*l,p=r*l,f=n*o,v=n*a,g=n*l;return t[0]=1-(h+p),t[4]=A-g,t[8]=c+v,t[1]=A+g,t[5]=1-(u+p),t[9]=d-f,t[2]=c-v,t[6]=d+f,t[10]=1-(u+h),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,i=$.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i,t[3]=e[3]/i,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 $.normalizeQuaternion($.conjugateQuaternion(e,t))},quaternionToAngleAxis:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec4(),i=(e=$.normalizeQuaternion(e,q))[3],s=2*Math.acos(i),r=Math.sqrt(1-i*i);return r<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/r,t[1]=e[1]/r,t[2]=e[2]/r),t[3]=s,t},AABB3:function(e){return new X(e||6)},AABB2:function(e){return new X(e||4)},OBB3:function(e){return new X(e||32)},OBB2:function(e){return new X(e||16)},Sphere3:function(e,t,i,s){return new X([e,t,i,s])},transformOBB3:function(e,t){var i,s,r,n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,a=t.length,l=e[0],u=e[1],A=e[2],c=e[3],h=e[4],d=e[5],p=e[6],f=e[7],v=e[8],g=e[9],m=e[10],_=e[11],y=e[12],b=e[13],B=e[14],w=e[15];for(i=0;ia?o:a,n[1]+=l>u?l:u,n[2]+=A>c?A:c,Math.abs($.lenVec3(n))}}(),getAABB3Area:function(e){return(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2])},getAABB3Center:function(e,t){var i=t||$.vec3();return i[0]=(e[0]+e[3])/2,i[1]=(e[1]+e[4])/2,i[2]=(e[2]+e[5])/2,i},getAABB2Center:function(e,t){var i=t||$.vec2();return i[0]=(e[2]+e[0])/2,i[1]=(e[3]+e[1])/2,i},collapseAABB3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:$.AABB3();return e[0]=$.MAX_DOUBLE,e[1]=$.MAX_DOUBLE,e[2]=$.MAX_DOUBLE,e[3]=$.MIN_DOUBLE,e[4]=$.MIN_DOUBLE,e[5]=$.MIN_DOUBLE,e},AABB3ToOBB3:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.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 X(3);return function(t,i,s){i=i||$.AABB3();for(var r,n,o,a=$.MAX_DOUBLE,l=$.MAX_DOUBLE,u=$.MAX_DOUBLE,A=$.MIN_DOUBLE,c=$.MIN_DOUBLE,h=$.MIN_DOUBLE,d=0,p=t.length;dA&&(A=r),n>c&&(c=n),o>h&&(h=o);return i[0]=a,i[1]=l,i[2]=u,i[3]=A,i[4]=c,i[5]=h,i}}(),OBB3ToAABB3:function(e){for(var t,i,s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.AABB3(),n=$.MAX_DOUBLE,o=$.MAX_DOUBLE,a=$.MAX_DOUBLE,l=$.MIN_DOUBLE,u=$.MIN_DOUBLE,A=$.MIN_DOUBLE,c=0,h=e.length;cl&&(l=t),i>u&&(u=i),s>A&&(A=s);return r[0]=n,r[1]=o,r[2]=a,r[3]=l,r[4]=u,r[5]=A,r},points3ToAABB3:function(e){for(var t,i,s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.AABB3(),n=$.MAX_DOUBLE,o=$.MAX_DOUBLE,a=$.MAX_DOUBLE,l=$.MIN_DOUBLE,u=$.MIN_DOUBLE,A=$.MIN_DOUBLE,c=0,h=e.length;cl&&(l=t),i>u&&(u=i),s>A&&(A=s);return r[0]=n,r[1]=o,r[2]=a,r[3]=l,r[4]=u,r[5]=A,r},points3ToSphere3:function(){var e=new X(3);return function(t,i){i=i||$.vec4();var s,r=0,n=0,o=0,a=t.length;for(s=0;su&&(u=l);return i[3]=u,i}}(),positions3ToSphere3:function(){var e=new X(3),t=new X(3);return function(i,s){s=s||$.vec4();var r,n=0,o=0,a=0,l=i.length,u=0;for(r=0;ru&&(u=A);return s[3]=u,s}}(),OBB3ToSphere3:function(){var e=new X(3),t=new X(3);return function(i,s){s=s||$.vec4();var r,n=0,o=0,a=0,l=i.length,u=l/4;for(r=0;rc&&(c=A);return s[3]=c,s}}(),getSphere3Center:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.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]:$.vec3(),i=0,s=0,r=0,n=0,o=e.length;nt[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]i&&(e[0]=i),e[1]>s&&(e[1]=s),e[2]>r&&(e[2]=r),e[3]0&&void 0!==arguments[0]?arguments[0]:$.AABB2();return e[0]=$.MAX_DOUBLE,e[1]=$.MAX_DOUBLE,e[2]=$.MIN_DOUBLE,e[3]=$.MIN_DOUBLE,e},point3AABB3Intersect:function(e,t){return e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(s=e[0]*i[0],r=e[0]*i[3]):(s=e[0]*i[3],r=e[0]*i[0]),e[1]>0?(s+=e[1]*i[1],r+=e[1]*i[4]):(s+=e[1]*i[4],r+=e[1]*i[1]),e[2]>0?(s+=e[2]*i[2],r+=e[2]*i[5]):(s+=e[2]*i[5],r+=e[2]*i[2]),s<=-t&&r<=-t?-1:s>=-t&&r>=-t?1:0},OBB3ToAABB2:function(e){for(var t,i,s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.AABB2(),n=$.MAX_DOUBLE,o=$.MAX_DOUBLE,a=$.MIN_DOUBLE,l=$.MIN_DOUBLE,u=0,A=e.length;ua&&(a=t),i>l&&(l=i);return r[0]=n,r[1]=o,r[2]=a,r[3]=l,r},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,r=.5*(e[0]+1),n=.5*(e[1]+1),o=.5*(e[2]+1),a=.5*(e[3]+1);return s[0]=Math.floor(r*t),s[1]=i-Math.floor(a*i),s[2]=Math.floor(o*t),s[3]=i-Math.floor(n*i),s},tangentQuadraticBezier:function(e,t,i,s){return 2*(1-e)*(i-t)+2*e*(s-i)},tangentQuadraticBezier3:function(e,t,i,s,r){return-3*t*(1-e)*(1-e)+3*i*(1-e)*(1-e)-6*e*i*(1-e)+6*e*s*(1-e)-3*e*e*s+3*e*e*r},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,i,s,r){var n=.5*(i-e),o=.5*(s-t),a=r*r;return(2*t-2*i+n+o)*(r*a)+(-3*t+3*i-2*n-o)*a+n*r+t},b2p0:function(e,t){var i=1-e;return i*i*t},b2p1:function(e,t){return 2*(1-e)*e*t},b2p2:function(e,t){return e*e*t},b2:function(e,t,i,s){return this.b2p0(e,t)+this.b2p1(e,i)+this.b2p2(e,s)},b3p0:function(e,t){var i=1-e;return i*i*i*t},b3p1:function(e,t){var i=1-e;return 3*i*i*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,i,s,r){return this.b3p0(e,t)+this.b3p1(e,i)+this.b3p2(e,s)+this.b3p3(e,r)},triangleNormal:function(e,t,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:$.vec3(),r=t[0]-e[0],n=t[1]-e[1],o=t[2]-e[2],a=i[0]-e[0],l=i[1]-e[1],u=i[2]-e[2],A=n*u-o*l,c=o*a-r*u,h=r*l-n*a,d=Math.sqrt(A*A+c*c+h*h);return 0===d?(s[0]=0,s[1]=0,s[2]=0):(s[0]=A/d,s[1]=c/d,s[2]=h/d),s},rayTriangleIntersect:function(){var e=new X(3),t=new X(3),i=new X(3),s=new X(3),r=new X(3);return function(n,o,a,l,u,A){A=A||$.vec3();var c=$.subVec3(l,a,e),h=$.subVec3(u,a,t),d=$.cross3Vec3(o,h,i),p=$.dotVec3(c,d);if(p<1e-6)return null;var f=$.subVec3(n,a,s),v=$.dotVec3(f,d);if(v<0||v>p)return null;var g=$.cross3Vec3(f,c,r),m=$.dotVec3(o,g);if(m<0||v+m>p)return null;var _=$.dotVec3(h,g)/p;return A[0]=n[0]+_*o[0],A[1]=n[1]+_*o[1],A[2]=n[2]+_*o[2],A}}(),rayPlaneIntersect:function(){var e=new X(3),t=new X(3),i=new X(3),s=new X(3);return function(r,n,o,a,l,u){u=u||$.vec3(),n=$.normalizeVec3(n,e);var A=$.subVec3(a,o,t),c=$.subVec3(l,o,i),h=$.cross3Vec3(A,c,s);$.normalizeVec3(h,h);var d=-$.dotVec3(o,h),p=-($.dotVec3(r,h)+d)/$.dotVec3(n,h);return u[0]=r[0]+p*n[0],u[1]=r[1]+p*n[1],u[2]=r[2]+p*n[2],u}}(),cartesianToBarycentric:function(){var e=new X(3),t=new X(3),i=new X(3);return function(s,r,n,o,a){var l=$.subVec3(o,r,e),u=$.subVec3(n,r,t),A=$.subVec3(s,r,i),c=$.dotVec3(l,l),h=$.dotVec3(l,u),d=$.dotVec3(l,A),p=$.dotVec3(u,u),f=$.dotVec3(u,A),v=c*p-h*h;if(0===v)return null;var g=1/v,m=(p*d-h*f)*g,_=(c*f-h*d)*g;return a[0]=1-m-_,a[1]=_,a[2]=m,a}}(),barycentricInsideTriangle:function(e){var t=e[1],i=e[2];return i>=0&&t>=0&&i+t<1},barycentricToCartesian:function(e,t,i,s){var r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:$.vec3(),n=e[0],o=e[1],a=e[2];return r[0]=t[0]*n+i[0]*o+s[0]*a,r[1]=t[1]*n+i[1]*o+s[1]*a,r[2]=t[2]*n+i[2]*o+s[2]*a,r},mergeVertices:function(e,t,i,s){var r,n,o,a,l,u,A={},c=[],h=[],d=t?[]:null,p=i?[]:null,f=[],v=Math.pow(10,4),g=0;for(l=0,u=e.length;l>24&255,o=c>>16&255,n=c>>8&255,r=255&c,s=3*t[p],u[h++]=e[s],u[h++]=e[s+1],u[h++]=e[s+2],A[d++]=r,A[d++]=n,A[d++]=o,A[d++]=a,s=3*t[p+1],u[h++]=e[s],u[h++]=e[s+1],u[h++]=e[s+2],A[d++]=r,A[d++]=n,A[d++]=o,A[d++]=a,s=3*t[p+2],u[h++]=e[s],u[h++]=e[s+1],u[h++]=e[s+2],A[d++]=r,A[d++]=n,A[d++]=o,A[d++]=a,c++;return{positions:u,colors:A}},faceToVertexNormals:function(e,t){var i,s,r,n,o,a,l,u,A,c,h,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},p=d.smoothNormalsAngleThreshold||20,f={},v=[],g={},m=4,_=Math.pow(10,m);for(l=0,A=e.length;ll[3]&&(l[3]=r[h]),r[h+1]l[4]&&(l[4]=r[h+1]),r[h+2]l[5]&&(l[5]=r[h+2])}if(i.length<20||n>10)return u.triangles=i,u.leaf=!0,u;e[0]=l[3]-l[0],e[1]=l[4]-l[1],e[2]=l[5]-l[2];var d=0;e[1]>e[d]&&(d=1),e[2]>e[d]&&(d=2),u.splitDim=d;var p=(l[d]+l[d+3])/2,f=new Array(i.length),v=0,g=new Array(i.length),m=0;for(o=0,a=i.length;o2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),s=0,r=e.length;s2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),s=0,r=e.length;s=0?1:-1),s=(1-Math.abs(i))*(s>=0?1:-1));var n=Math.sqrt(i*i+s*s+r*r);return t[0]=i/n,t[1]=s/n,t[2]=r/n,t},octDecodeVec2s:function(e,t){for(var i=0,s=0,r=e.length;i=0?1:-1),o=(1-Math.abs(n))*(o>=0?1:-1));var l=Math.sqrt(n*n+o*o+a*a);t[s+0]=n/l,t[s+1]=o/l,t[s+2]=a/l,s+=3}return t}};$.buildEdgeIndices=function(){var e=[],t=[],i=[],s=[],r=[],n=0,o=new Uint16Array(3),a=new Uint16Array(3),l=new Uint16Array(3),u=$.vec3(),A=$.vec3(),c=$.vec3(),h=$.vec3(),d=$.vec3(),p=$.vec3(),f=$.vec3();return function(v,g,m,_){!function(r,n){var o,a,l,u,A,c,h={},d=Math.pow(10,4),p=0;for(A=0,c=r.length;AI)||(F=i[P.index1],E=i[P.index2],(!S&&F>65535||E>65535)&&(S=!0),k.push(F),k.push(E));return S?new Uint32Array(k):new Uint16Array(k)}}(),$.planeClipsPositions3=function(e,t,i){for(var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:3,r=0,n=i.length;r=this._maxTreeDepth)return e.entities=e.entities||[],void e.entities.push(t);if(e.left&&$.containsAABB3(e.left.aabb,s))this._insertEntity(e.left,t,i+1);else if(e.right&&$.containsAABB3(e.right.aabb,s))this._insertEntity(e.right,t,i+1);else{var r=e.aabb;ee[0]=r[3]-r[0],ee[1]=r[4]-r[1],ee[2]=r[5]-r[2];var n=0;if(ee[1]>ee[n]&&(n=1),ee[2]>ee[n]&&(n=2),!e.left){var o=r.slice();if(o[n+3]=(r[n]+r[n+3])/2,e.left={aabb:o},$.containsAABB3(o,s))return void this._insertEntity(e.left,t,i+1)}if(!e.right){var a=r.slice();if(a[n]=(r[n]+r[n+3])/2,e.right={aabb:a},$.containsAABB3(a,s))return void this._insertEntity(e.right,t,i+1)}e.entities=e.entities||[],e.entities.push(t)}}},{key:"destroy",value:function(){var e=this.viewer.scene;e.off(this._onModelLoaded),e.off(this._onModelUnloaded),this._root=null,this._needsRebuild=!0}}]),e}(),ie=function(){function e(){x(this,e),this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}return C(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}(),se={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 re=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],i=e[0].charCodeAt(0),s=i+e[1],r=i;r1&&void 0!==arguments[1]?arguments[1]:null;ce.push(e),ce.push(t)},this.runTasks=function(){for(var e,t,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1,s=(new Date).getTime(),r=0;ce.length>0&&(i<0||s0&&ae>0){var t=1e3/ae;fe+=t,de.push(t),de.length>=30&&(fe-=de.shift()),se.frame.fps=Math.round(fe/de.length)}for(var i in _e.scenes)_e.scenes[i].compile();be(e),pe=e};ve=function(){ye()},ge=100,me=Date.now()+ge,function e(){var t=Date.now()-me;ve(),me+=ge,setTimeout(e,Math.max(0,ge-t))}();function be(e){var t=_e.runTasks(e+10),i=_e.getNumTasks();se.frame.tasksRun=t,se.frame.tasksScheduled=i,se.frame.tasksBudget=10}!function e(){var t=Date.now();if(ae=t-pe,pe>0&&ae>0){var i=1e3/ae;fe+=i,de.push(i),de.length>=30&&(fe-=de.shift()),se.frame.fps=Math.round(fe/de.length)}be(t),function(e){for(var t in he.time=e,_e.scenes)if(_e.scenes.hasOwnProperty(t)){var i=_e.scenes[t];he.sceneId=t,he.startTime=i.startTime,he.deltaTime=null!=he.prevTime?he.time-he.prevTime:0,i.fire("tick",he,!0)}he.prevTime=e}(t),function(){var e,t,i,s,r,n=_e.scenes,o=!1;for(r in n)n.hasOwnProperty(r)&&(e=n[r],(t=ue[r])||(t=ue[r]={}),i=e.ticksPerOcclusionTest,t.ticksPerOcclusionTest!==i&&(t.ticksPerOcclusionTest=i,t.renderCountdown=i),--e.occlusionTestCountdown<=0&&(e.doOcclusionTest(),e.occlusionTestCountdown=i),s=e.ticksPerRender,t.ticksPerRender!==s&&(t.ticksPerRender=s,t.renderCountdown=s),0==--t.renderCountdown&&(e.render(o),t.renderCountdown=s))}(),void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(ye):requestAnimationFrame(e)}();var Be=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,e),this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=i.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=!!i.dontClear,this._renderer=this.scene._renderer,this.meta=i.meta||{},this.id=i.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 C(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,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==i&&(this._events[e]=t||!0);var s,r=this._eventSubs[e];if(r)for(var n in r)r.hasOwnProperty(n)&&(s=r[n],this._eventCallDepth++,this._eventCallDepth<300?s.callback.call(s.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,i){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new Q),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var s=this._eventSubs[e];s?this._eventSubsNum[e]++:(s={},this._eventSubs[e]=s,this._eventSubsNum[e]=1);var r=this._subIdMap.addItem();s[r]={callback:t,scope:i||this},this._subIdEvents[r]=e;var n=this._events[e];return void 0!==n&&t.call(i||this,n),r}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var i=this._eventSubs[t];i&&(delete i[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,i){var s=this,r=this.on(e,(function(e){s.off(r),t.call(i||this,e)}),i)}},{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+" "+le.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 i=e.component,s=e.sceneDefault,r=e.sceneSingleton,n=e.type,o=e.on,a=!1!==e.recompiles;if(i&&(le.isNumeric(i)||le.isString(i))){var l=i;if(!(i=this.scene.components[l]))return void this.error("Component not found: "+le.inQuotes(l))}if(!i)if(!0===r){var u=this.scene.types[n];for(var A in u)if(u.hasOwnProperty){i=u[A];break}if(!i)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===s&&!(i=this.scene[t]))return this.error("Scene has no default component for '"+t+"'"),null;if(i){if(i.scene.id!==this.scene.id)return void this.error("Not in same scene: "+i.type+" "+le.inQuotes(i.id));if(n&&!i.isType(n))return void this.error("Expected a "+n+" type or subtype: "+i.type+" "+le.inQuotes(i.id))}this._attachments||(this._attachments={});var c,h,d,p=this._attached[t];if(p){if(i&&p.id===i.id)return;var f=this._attachments[p.id];for(h=0,d=(c=f.subs).length;h=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}]),e}(),Me=C((function e(){x(this,e),this.planes=[new Ce,new Ce,new Ce,new Ce,new Ce,new Ce]}));function Fe(e,t,i){var s=$.mulMat4(i,t,Pe),r=s[0],n=s[1],o=s[2],a=s[3],l=s[4],u=s[5],A=s[6],c=s[7],h=s[8],d=s[9],p=s[10],f=s[11],v=s[12],g=s[13],m=s[14],_=s[15];e.planes[0].set(a-r,c-l,f-h,_-v),e.planes[1].set(a+r,c+l,f+h,_+v),e.planes[2].set(a-n,c-u,f-d,_-g),e.planes[3].set(a+n,c+u,f+d,_+g),e.planes[4].set(a-o,c-A,f-p,_-m),e.planes[5].set(a+o,c+A,f+p,_+m)}function Ee(e,t){var i=Me.INSIDE,s=we,r=xe;s[0]=t[0],s[1]=t[1],s[2]=t[2],r[0]=t[3],r[1]=t[4],r[2]=t[5];for(var n=[s,r],o=0;o<6;++o){var a=e.planes[o];if(a.normal[0]*n[a.testVertex[0]][0]+a.normal[1]*n[a.testVertex[1]][1]+a.normal[2]*n[a.testVertex[2]][2]+a.offset<0)return Me.OUTSIDE;a.normal[0]*n[1-a.testVertex[0]][0]+a.normal[1]*n[1-a.testVertex[1]][1]+a.normal[2]*n[1-a.testVertex[2]][2]+a.offset<0&&(i=Me.INTERSECT)}return i}Me.INSIDE=0,Me.INTERSECT=1,Me.OUTSIDE=2;var ke=function(e){g(i,Be);var t=_(i);function i(){var e,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(x(this,i),!s.viewer)throw"[MarqueePicker] Missing config: viewer";if(!s.objectsKdTree3)throw"[MarqueePicker] Missing config: objectsKdTree3";return(e=t.call(this,s.viewer.scene,s)).viewer=s.viewer,e._objectsKdTree3=s.objectsKdTree3,e._canvasMarqueeCorner1=$.vec2(),e._canvasMarqueeCorner2=$.vec2(),e._canvasMarquee=$.AABB2(),e._marqueeFrustum=new Me,e._marqueeFrustumProjMat=$.mat4(),e._pickMode=!1,e._marqueeElement=document.createElement("div"),document.body.appendChild(e._marqueeElement),e._marqueeElement.style.position="absolute",e._marqueeElement.style["z-index"]="40000005",e._marqueeElement.style.width="8px",e._marqueeElement.style.height="8px",e._marqueeElement.style.visibility="hidden",e._marqueeElement.style.top="0px",e._marqueeElement.style.left="0px",e._marqueeElement.style["box-shadow"]="0 2px 5px 0 #182A3D;",e._marqueeElement.style.opacity=1,e._marqueeElement.style["pointer-events"]="none",e}return C(i,[{key:"setMarqueeCorner1",value:function(e){this._canvasMarqueeCorner1.set(e),this._canvasMarqueeCorner2.set(e),this._updateMarquee()}},{key:"setMarqueeCorner2",value:function(e){this._canvasMarqueeCorner2.set(e),this._updateMarquee()}},{key:"setMarquee",value:function(e,t){this._canvasMarqueeCorner1.set(e),this._canvasMarqueeCorner2.set(t),this._updateMarquee()}},{key:"setMarqueeVisible",value:function(e){this._marqueVisible=e,this._marqueeElement.style.visibility=e?"visible":"hidden"}},{key:"getMarqueeVisible",value:function(){return this._marqueVisible}},{key:"setPickMode",value:function(e){if(e!==i.PICK_MODE_INSIDE&&e!==i.PICK_MODE_INTERSECTS)throw"Illegal MarqueePicker pickMode: must be MarqueePicker.PICK_MODE_INSIDE or MarqueePicker.PICK_MODE_INTERSECTS";e!==this._pickMode&&(this._marqueeElement.style["background-image"]=e===i.PICK_MODE_INSIDE?"url(\"data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='6' ry='6' stroke='%23333' stroke-width='4'/%3e%3c/svg%3e\")":"url(\"data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='6' ry='6' stroke='%23333' stroke-width='4' stroke-dasharray='6%2c 14' stroke-dashoffset='0' stroke-linecap='square'/%3e%3c/svg%3e\")",this._pickMode=e)}},{key:"getPickMode",value:function(){return this._pickMode}},{key:"clear",value:function(){this.fire("clear",{})}},{key:"pick",value:function(){var e=this;this._updateMarquee(),this._buildMarqueeFrustum();var t=[];return(this._canvasMarquee[2]-this._canvasMarquee[0]>3||this._canvasMarquee[3]-this._canvasMarquee[1]>3)&&function s(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Me.INTERSECT;if(n===Me.INTERSECT&&(n=Ee(e._marqueeFrustum,r.aabb)),n!==Me.OUTSIDE){if(r.entities)for(var o=r.entities,a=0,l=o.length;a3||i>3)&&c.pick()}})),document.addEventListener("mouseup",(function(e){s.getActive()&&0===e.button&&(clearTimeout(A),d&&(c.setMarqueeVisible(!1),d=!1,p=!1,f=!0,c.viewer.cameraControl.pointerEnabled=!0))}),!0),h.addEventListener("mousemove",(function(e){s.getActive()&&0===e.button&&p&&(clearTimeout(A),d&&(o=e.pageX,a=e.pageY,u=e.offsetX,c.setMarqueeVisible(!0),c.setMarqueeCorner2([o,a]),c.setPickMode(l1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this.viewer=t,this.scene=this.viewer.scene,this._circleDiv=document.createElement("div"),this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._circleDiv,this.viewer.scene.canvas.canvas),this._circleDiv.style.backgroundColor="transparent",this._circleDiv.style.border="2px solid green",this._circleDiv.style.borderRadius="50px",this._circleDiv.style.width="50px",this._circleDiv.style.height="50px",this._circleDiv.style.margin="-200px -200px",this._circleDiv.style.zIndex="100000",this._circleDiv.style.position="absolute",this._circleDiv.style.pointerEvents="none",this._circlePos=null,this._circleMaxRadius=200,this._circleMinRadius=2,this._active=!1!==i.active,this._visible=!1,this._running=!1,this._destroyed=!1}return C(e,[{key:"start",value:function(e){var t=this;if(!this._destroyed){this._circlePos=e,this._running=!1,this._circleRadius=this._circleMaxRadius,this._circleDiv.style.borderRadius="".concat(this._circleRadius,"px"),this._circleDiv.style.marginLeft="".concat(this._circlePos[0]-this._circleRadius,"px"),this._circleDiv.style.marginTop="".concat(this._circlePos[1]-this._circleRadius,"px");var i,s=this._circleMaxRadius;this._running=!0,requestAnimationFrame((function e(r){if(t._running){i||(i=r);var n=r-i,o=Math.min(n/300,1),a=s+(2-s)*o;t._circleRadius=a,t._circleDiv.style.width="".concat(t._circleRadius,"px"),t._circleDiv.style.height="".concat(t._circleRadius,"px"),t._circleDiv.style.marginLeft="".concat(t._circlePos[0]-t._circleRadius/2,"px"),t._circleDiv.style.marginTop="".concat(t._circlePos[1]-t._circleRadius/2,"px"),o<1&&requestAnimationFrame(e)}})),this._circleDiv.style.visibility="visible"}}},{key:"stop",value:function(){this._destroyed||(this._running=!1,this._circleRadius=this._circleMaxRadius,this._circleDiv.style.borderRadius="".concat(this._circleRadius,"px"),this._circleDiv.style.visibility="hidden")}},{key:"durationMs",get:function(){return this._durationMs},set:function(e){this.stop(),this._durationMs=e}},{key:"destroy",value:function(){this._destroyed||(this.stop(),document.body.removeChild(this._circleDiv),this._destroyed=!0)}}]),e}(),Se=function(){function e(t,i,s){x(this,e),this.id=s&&s.id?s.id:t,this.viewer=i,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,i.addPlugin(this)}return C(e,[{key:"scheduleTask",value:function(e){_e.scheduleTask(e,null)}},{key:"fire",value:function(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==i&&(this._events[e]=t||!0);var s,r=this._eventSubs[e];if(r)for(var n in r)r.hasOwnProperty(n)&&(s=r[n],this._eventCallDepth++,this._eventCallDepth<300?s.callback.call(s.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,i){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new Q),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var s=this._eventSubs[e];s?this._eventSubsNum[e]++:(s={},this._eventSubs[e]=s,this._eventSubsNum[e]=1);var r=this._subIdMap.addItem();s[r]={callback:t,scope:i||this},this._subIdEvents[r]=e;var n=this._events[e];return void 0!==n&&t.call(i||this,n),r}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var i=this._eventSubs[t];i&&(delete i[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,i){var s=this,r=this.on(e,(function(e){s.off(r),t.call(i||this,e)}),i)}},{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}(),Te=$.vec3(),Re=function(){var e=new Float64Array(16),t=new Float64Array(4),i=new Float64Array(4);return function(s,r,n){return n=n||e,t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,$.transformVec4(s,t,i),$.setMat4Translation(s,i,n),n.slice()}}();function Le(e,t,i){var s=Float32Array.from([e[0]])[0],r=e[0]-s,n=Float32Array.from([e[1]])[0],o=e[1]-n,a=Float32Array.from([e[2]])[0],l=e[2]-a;t[0]=s,t[1]=n,t[2]=a,i[0]=r,i[1]=o,i[2]=l}function Ue(e,t,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1e3,r=$.getPositionsCenter(e,Te),n=Math.round(r[0]/s)*s,o=Math.round(r[1]/s)*s,a=Math.round(r[2]/s)*s;i[0]=n,i[1]=o,i[2]=a;var l=0!==i[0]||0!==i[1]||0!==i[2];if(l)for(var u=0,A=e.length;u0?this.meshes[0]._colorize[3]/255:1},set:function(e){if(0!==this.meshes.length){var t=null!=e,i=this.meshes[0]._colorize[3],s=255;if(t){if(e<0?e=0:e>1&&(e=1),i===(s=Math.floor(255*e)))return}else if(i===(s=255))return;for(var r=0,n=this.meshes.length;r1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this._color=s.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=s.thickness||1,this._thicknessClickable=s.thicknessClickable||6,this._visible=!0,this._culled=!1;var r=this._wire,n=r.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===s.zIndex?"2000001":s.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",s.onContextMenu,t.appendChild(r);var o=this._wireClickable,a=o.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===s.zIndex?"2000002":s.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",s.onContextMenu,t.appendChild(o),s.onMouseOver&&o.addEventListener("mouseover",(function(e){s.onMouseOver(e,i)})),s.onMouseLeave&&o.addEventListener("mouseleave",(function(e){s.onMouseLeave(e,i)})),s.onMouseWheel&&o.addEventListener("wheel",(function(e){s.onMouseWheel(e,i)})),s.onMouseDown&&o.addEventListener("mousedown",(function(e){s.onMouseDown(e,i)})),s.onMouseUp&&o.addEventListener("mouseup",(function(e){s.onMouseUp(e,i)})),s.onMouseMove&&o.addEventListener("mousemove",(function(e){s.onMouseMove(e,i)})),s.onContextMenu&&o.addEventListener("contextmenu",(function(e){s.onContextMenu(e,i),e.preventDefault(),e.stopPropagation()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}return C(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,i=this._wire.style;i.width=Math.round(e)+"px",i.left=Math.round(this._x1)+"px",i.top=Math.round(this._y1)+"px",i["-webkit-transform"]="rotate("+t+"deg)",i["-moz-transform"]="rotate("+t+"deg)",i["-ms-transform"]="rotate("+t+"deg)",i["-o-transform"]="rotate("+t+"deg)",i.transform="rotate("+t+"deg)";var s=this._wireClickable.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)"}},{key:"setStartAndEnd",value:function(e,t,i,s){this._x1=e,this._y1=t,this._x2=i,this._y2=s,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){this._visible!==e&&(this._visible=!!e,this._wire.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setCulled",value:function(e){this._culled!==e&&(this._culled=!!e,this._wire.style.visibility=this._visible&&!this._culled?"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}(),it=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=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",this._visible=!!s.visible,this._culled=!1;var r=this._dot,n=r.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===s.zIndex?"40000005":s.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==s.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",s.onContextMenu,t.appendChild(r);var o=this._dotClickable,a=o.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===s.zIndex?"40000007":s.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",s.onContextMenu,t.appendChild(o),o.addEventListener("click",(function(e){t.dispatchEvent(new MouseEvent("mouseover",e))})),s.onMouseOver&&o.addEventListener("mouseover",(function(e){s.onMouseOver(e,i),t.dispatchEvent(new MouseEvent("mouseover",e))})),s.onMouseLeave&&o.addEventListener("mouseleave",(function(e){s.onMouseLeave(e,i)})),s.onMouseWheel&&o.addEventListener("wheel",(function(e){s.onMouseWheel(e,i)})),s.onMouseDown&&o.addEventListener("mousedown",(function(e){s.onMouseDown(e,i)})),s.onMouseUp&&o.addEventListener("mouseup",(function(e){s.onMouseUp(e,i)})),s.onMouseMove&&o.addEventListener("mousemove",(function(e){s.onMouseMove(e,i)})),s.onContextMenu&&o.addEventListener("contextmenu",(function(e){s.onContextMenu(e,i),e.preventDefault(),e.stopPropagation()})),this.setPos(s.x||0,s.y||0),this.setFillColor(s.fillColor),this.setBorderColor(s.borderColor)}return C(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var i=this._dot.style;i.left=Math.round(e)-4+"px",i.top=Math.round(t)-4+"px";var s=this._dotClickable.style;s.left=Math.round(e)-9+"px",s.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&&!this._culled?"visible":"hidden")}},{key:"setCulled",value:function(e){this._culled!==e&&(this._culled=!!e,this._dot.style.visibility=this._visible&&!this._culled?"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}(),st=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this._highlightClass="viewer-ruler-label-highlighted",this._prefix=s.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 r=this._label,n=r.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===s.zIndex?"5000005":s.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,s.onContextMenu,r.innerText="",t.appendChild(r),this.setPos(s.x||0,s.y||0),this.setFillColor(s.fillColor),this.setBorderColor(s.fillColor),this.setText(s.text),s.onMouseOver&&r.addEventListener("mouseover",(function(e){s.onMouseOver(e,i),e.preventDefault()})),s.onMouseLeave&&r.addEventListener("mouseleave",(function(e){s.onMouseLeave(e,i),e.preventDefault()})),s.onMouseWheel&&r.addEventListener("wheel",(function(e){s.onMouseWheel(e,i)})),s.onMouseDown&&r.addEventListener("mousedown",(function(e){s.onMouseDown(e,i),e.stopPropagation()})),s.onMouseUp&&r.addEventListener("mouseup",(function(e){s.onMouseUp(e,i),e.stopPropagation()})),s.onMouseMove&&r.addEventListener("mousemove",(function(e){s.onMouseMove(e,i)})),s.onContextMenu&&r.addEventListener("contextmenu",(function(e){s.onContextMenu(e,i),e.preventDefault(),e.stopPropagation(),console.log("Label context menu")}))}return C(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var i=this._label.style;i.left=Math.round(e)-20+"px",i.top=Math.round(t)-12+"px"}},{key:"setPosOnWire",value:function(e,t,i,s){var r=e+.5*(i-e),n=t+.5*(s-t),o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(n)-12+"px"}},{key:"setPosBetweenWires",value:function(e,t,i,s,r,n){var o=(e+i+r)/3,a=(t+s+n)/3,l=this._label.style;l.left=Math.round(o)-20+"px",l.top=Math.round(a)-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}(),rt=$.vec3(),nt=$.vec3(),ot=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,e.viewer.scene,r)).plugin=e,s._container=r.container,!s._container)throw"config missing: container";s._color=r.color||e.defaultColor;var n=s.plugin.viewer.scene;s._originMarker=new et(n,r.origin),s._cornerMarker=new et(n,r.corner),s._targetMarker=new et(n,r.target),s._originWorld=$.vec3(),s._cornerWorld=$.vec3(),s._targetWorld=$.vec3(),s._wp=new Float64Array(12),s._vp=new Float64Array(12),s._pp=new Float64Array(12),s._cp=new Int16Array(6);var o=r.onMouseOver?function(e){r.onMouseOver(e,b(s)),s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,a=r.onMouseLeave?function(e){r.onMouseLeave(e,b(s)),s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,l=r.onContextMenu?function(e){r.onContextMenu(e,b(s))}:null,u=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))},A=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},c=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},h=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))};return s._originDot=new it(s._container,{fillColor:s._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:u,onMouseDown:A,onMouseUp:c,onMouseMove:h,onContextMenu:l}),s._cornerDot=new it(s._container,{fillColor:s._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:u,onMouseDown:A,onMouseUp:c,onMouseMove:h,onContextMenu:l}),s._targetDot=new it(s._container,{fillColor:s._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:u,onMouseDown:A,onMouseUp:c,onMouseMove:h,onContextMenu:l}),s._originWire=new tt(s._container,{color:s._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:o,onMouseLeave:a,onMouseWheel:u,onMouseDown:A,onMouseUp:c,onMouseMove:h,onContextMenu:l}),s._targetWire=new tt(s._container,{color:s._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:u,onMouseDown:A,onMouseUp:c,onMouseMove:h,onContextMenu:l}),s._angleLabel=new st(s._container,{fillColor:s._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:o,onMouseLeave:a,onMouseWheel:u,onMouseDown:A,onMouseUp:c,onMouseMove:h,onContextMenu:l}),s._wpDirty=!1,s._vpDirty=!1,s._cpDirty=!1,s._visible=!1,s._originVisible=!1,s._cornerVisible=!1,s._targetVisible=!1,s._originWireVisible=!1,s._targetWireVisible=!1,s._angleVisible=!1,s._labelsVisible=!1,s._clickable=!1,s._originMarker.on("worldPos",(function(e){s._originWorld.set(e||[0,0,0]),s._wpDirty=!0,s._needUpdate(0)})),s._cornerMarker.on("worldPos",(function(e){s._cornerWorld.set(e||[0,0,0]),s._wpDirty=!0,s._needUpdate(0)})),s._targetMarker.on("worldPos",(function(e){s._targetWorld.set(e||[0,0,0]),s._wpDirty=!0,s._needUpdate(0)})),s._onViewMatrix=n.camera.on("viewMatrix",(function(){s._vpDirty=!0,s._needUpdate(0)})),s._onProjMatrix=n.camera.on("projMatrix",(function(){s._cpDirty=!0,s._needUpdate()})),s._onCanvasBoundary=n.canvas.on("boundary",(function(){s._cpDirty=!0,s._needUpdate(0)})),s._onSectionPlaneUpdated=n.on("sectionPlaneUpdated",(function(){s._sectionPlanesDirty=!0,s._needUpdate()})),s.approximate=r.approximate,s.visible=r.visible,s.originVisible=r.originVisible,s.cornerVisible=r.cornerVisible,s.targetVisible=r.targetVisible,s.originWireVisible=r.originWireVisible,s.targetWireVisible=r.targetWireVisible,s.angleVisible=r.angleVisible,s.labelsVisible=r.labelsVisible,s}return C(i,[{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&&($.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._sectionPlanesDirty){if(this._isSliced(this._wp))return this._angleLabel.setCulled(!0),this._originWire.setCulled(!0),this._targetWire.setCulled(!0),this._originDot.setCulled(!0),this._cornerDot.setCulled(!0),void this._targetDot.setCulled(!0);this._angleLabel.setCulled(!1),this._originWire.setCulled(!1),this._targetWire.setCulled(!1),this._originDot.setCulled(!1),this._cornerDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}if(this._cpDirty){var t=-.3,i=this._originMarker.viewPos[2],s=this._cornerMarker.viewPos[2],r=this._targetMarker.viewPos[2];if(i>t||s>t||r>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);$.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var n=this._pp,o=this._cp,a=e.canvas.canvas.getBoundingClientRect(),l=this._container.getBoundingClientRect(),u=a.top-l.top,A=a.left-l.left,c=e.canvas.boundary,h=c[2],d=c[3],p=0,f=0,v=n.length;f1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e.viewer.scene))._canvasToPagePos=r.canvasToPagePos,s.pointerLens=r.pointerLens,s._active=!1,s._mouseState=0,s._currentAngleMeasurement=null,s._initMarkerDiv(),s._onMouseHoverSurface=null,s._onHoverNothing=null,s._onPickedNothing=null,s._onPickedSurface=null,s._onInputMouseDown=null,s._onInputMouseUp=null,s._snapping=!1!==r.snapping,s._attachPlugin(e,r),s}return C(i,[{key:"_initMarkerDiv",value:function(){var e=document.createElement("div");e.setAttribute("id","myMarkerDiv");var t=this.scene.canvas.canvas;t.parentNode.insertBefore(e,t),e.style.background="black",e.style.border="2px solid blue",e.style.borderRadius="10px",e.style.width="5px",e.style.height="5px",e.style.top="-200px",e.style.left="-200px",e.style.margin="0 0",e.style.zIndex="100",e.style.position="absolute",e.style.pointerEvents="none",this.markerDiv=e}},{key:"_destroyMarkerDiv",value:function(){if(this._markerDiv){var e=document.getElementById("myMarkerDiv");e.parentNode.removeChild(e),this._markerDiv=null}}},{key:"_attachPlugin",value:function(e){this.angleMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){this.markerDiv||this._initMarkerDiv(),this.angleMeasurementsPlugin;var t=this.scene;t.input;var i=t.canvas.canvas,s=this.angleMeasurementsPlugin.viewer.cameraControl,r=this.pointerLens,n=!1,o=null,a=0,l=0,u=$.vec3(),A=$.vec2();this._currentAngleMeasurement=null;var c=function e(t){return t.offsetTop+(t.offsetParent&&t.offsetParent!==i.parentNode&&e(t.offsetParent))},h=function e(t){return t.offsetLeft+(t.offsetParent&&t.offsetParent!==i.parentNode&&e(t.offsetParent))},d=$.vec2();this._onMouseHoverSurface=s.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(function(t){t.snappedToVertex||t.snappedToEdge?(r&&(r.visible=!0,r.canvasPos=t.canvasPos,r.snappedCanvasPos=t.snappedCanvasPos||t.canvasPos,r.snapped=!0),e.markerDiv.style.background="greenyellow",e.markerDiv.style.border="2px solid green"):(r&&(r.visible=!0,r.canvasPos=t.canvasPos,r.snappedCanvasPos=t.canvasPos,r.snapped=!1),e.markerDiv.style.background="pink",e.markerDiv.style.border="2px solid red");var s=t.snappedCanvasPos||t.canvasPos;switch(n=!0,o=t.entity,u.set(t.worldPos),A.set(s),e._mouseState){case 0:e._canvasToPagePos?(e._canvasToPagePos(i,s,d),e.markerDiv.style.left="".concat(d[0]-5,"px"),e.markerDiv.style.top="".concat(d[1]-5,"px")):(e.markerDiv.style.left="".concat(h(i)+s[0]-5,"px"),e.markerDiv.style.top="".concat(c(i)+s[1]-5,"px"));break;case 1:e._currentAngleMeasurement&&(e._currentAngleMeasurement.originWireVisible=!0,e._currentAngleMeasurement.targetWireVisible=!1,e._currentAngleMeasurement.cornerVisible=!0,e._currentAngleMeasurement.angleVisible=!1,e._currentAngleMeasurement.corner.worldPos=t.worldPos,e._currentAngleMeasurement.corner.entity=t.entity),e.markerDiv.style.left="-10000px",e.markerDiv.style.top="-10000px",i.style.cursor="pointer";break;case 2:e._currentAngleMeasurement&&(e._currentAngleMeasurement.targetWireVisible=!0,e._currentAngleMeasurement.targetVisible=!0,e._currentAngleMeasurement.angleVisible=!0,e._currentAngleMeasurement.target.worldPos=t.worldPos,e._currentAngleMeasurement.target.entity=t.entity),e.markerDiv.style.left="-10000px",e.markerDiv.style.top="-10000px",i.style.cursor="pointer"}})),i.addEventListener("mousedown",this._onMouseDown=function(e){1===e.which&&(a=e.clientX,l=e.clientY)}),i.addEventListener("mouseup",this._onMouseUp=function(t){if(1===t.which&&!(t.clientX>a+20||t.clientXl+20||t.clientY1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"AngleMeasurements",e))._container=r.container||document.body,s._defaultControl=null,s._measurements={},s.defaultColor=void 0!==r.defaultColor?r.defaultColor:"#00BBFF",s.defaultLabelsVisible=!1!==r.defaultLabelsVisible,s.zIndex=r.zIndex||1e4,s._onMouseOver=function(e,t){s.fire("mouseOver",{plugin:b(s),angleMeasurement:t,measurement:t,event:e})},s._onMouseLeave=function(e,t){s.fire("mouseLeave",{plugin:b(s),angleMeasurement:t,measurement:t,event:e})},s._onContextMenu=function(e,t){s.fire("contextMenu",{plugin:b(s),angleMeasurement:t,measurement:t,event:e})},s}return C(i,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){}},{key:"control",get:function(){return this._defaultControl||(this._defaultControl=new lt(this,{})),this._defaultControl}},{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 i=t.origin,s=t.corner,r=t.target,n=new ot(this,{id:t.id,plugin:this,container:this._container,origin:{entity:i.entity,worldPos:i.worldPos},corner:{entity:s.entity,worldPos:s.worldPos},target:{entity:r.entity,worldPos:r.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[n.id]=n,n.on("destroyed",(function(){delete e._measurements[n.id]})),n.clickable=!0,this.fire("measurementCreated",n),n}},{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,i=Object.entries(this.measurements);t1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e.viewer.scene)).pointerLens=r.pointerLens,s.pointerCircle=new De(e.viewer),s._active=!1;var n=document.createElement("div"),o=s.scene.canvas.canvas;return o.parentNode.insertBefore(n,o),n.style.background="black",n.style.border="2px solid blue",n.style.borderRadius="10px",n.style.width="5px",n.style.height="5px",n.style.margin="-200px -200px",n.style.zIndex="100",n.style.position="absolute",n.style.pointerEvents="none",s.markerDiv=n,s._currentAngleMeasurement=null,s._onCanvasTouchStart=null,s._onCanvasTouchEnd=null,s._longTouchTimeoutMs=300,s._snapping=!1!==r.snapping,s._touchState=0,s._attachPlugin(e,r),s}return C(i,[{key:"_attachPlugin",value:function(e){this.angleMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){var t=this.plugin,i=this.scene,s=i.canvas.canvas;t.pointerLens;var r=$.vec3(),n=20,o=null;this._touchState=0;var a=$.vec2(),l=$.vec2(),u=$.vec2(),A=null,c=function(){e.plugin.viewer.cameraControl.active=!1},h=function(){e.plugin.viewer.cameraControl.active=!0};s.addEventListener("touchstart",this._onCanvasTouchStart=function(s){var u=s.touches.length;if(1===u){var d=s.touches[0],p=d.clientX,f=d.clientY;switch(a.set([p,f]),l.set([p,f]),e._touchState){case 0:if(1!==u&&null!==o)return o&&(clearTimeout(o),o=null),e._currentAngleMeasurement&&(e._currentAngleMeasurement.destroy(),e._currentAngleMeasurement=null),h(),void(e._touchState=0);var v=i.pick({canvasPos:l,snapToVertex:e._snapping,snapToEdge:e._snapping});if(v&&v.snapped)r.set(v.worldPos),e.pointerCircle.start(v.snappedCanvasPos);else{var g=i.pick({canvasPos:l,pickSurface:!0});if(!g||!g.worldPos)return;r.set(g.worldPos),e.pointerCircle.start(g.canvasPos)}o=setTimeout((function(){1!==u||l[0]>a[0]+n||l[0]a[1]+n||l[1]a[0]+n||l[0]a[1]+n||l[1]a[0]+n||l[0]a[1]+n||l[1]a[0]+n||da[1]+n||pa[0]+n||da[1]+n||pa[0]+n||da[1]+n||p

";le.isArray(t)&&(t=t.join("")),t=this._renderTemplate(t.trim());var i=document.createRange().createContextualFragment(t);this._marker=i.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 s=this._labelHTML||"

";le.isArray(s)&&(s=s.join("")),s=this._renderTemplate(s.trim());var r=document.createRange().createContextualFragment(s);this._label=r.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],i=e[1],s=this.canvasPos;this._marker.style.left=Math.floor(t+s[0])-12+"px",this._marker.style.top=Math.floor(i+s[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+s[0]+20)+"px",this._label.style.top=Math.floor(i+s[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 i=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),i)}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 i=e[t];this.setField(t,i)}}},{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),f(B(i.prototype),"destroy",this).call(this)}}]),i}(),ht=$.vec3(),dt=$.vec3(),pt=$.vec3(),ft=function(e){g(i,Se);var t=_(i);function i(e,s){var r;return x(this,i),(r=t.call(this,"Annotations",e))._labelHTML=s.labelHTML||"
",r._markerHTML=s.markerHTML||"
",r._container=s.container||document.body,r._values=s.values||{},r.annotations={},r.surfaceOffset=s.surfaceOffset,r}return C(i,[{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,i,s=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 r=e.pickResult;if(r.worldPos&&r.worldNormal){var n=$.normalizeVec3(r.worldNormal,ht),o=$.mulVec3Scalar(n,this._surfaceOffset,dt);t=$.addVec3(r.worldPos,o,pt),i=r.entity}else this.error("Param 'pickResult' does not have both worldPos and worldNormal")}else t=e.worldPos,i=e.entity;var a=null;e.markerElementId&&((a=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 ct(this.viewer.scene,{id:e.id,plugin:this,entity:i,worldPos:t,container:this._container,markerElement:a,labelElement:l,markerHTML:e.markerHTML||this._markerHTML,labelHTML:e.labelHTML||this._labelHTML,occludable:e.occludable,values:le.apply(e.values,le.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 s.annotations[u.id],s.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,i=e.length;t1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._canvas=r.canvas,s._element=null,s._isCustom=!1,r.elementId&&(s._element=document.getElementById(r.elementId),s._element?s._adjustPosition():s.error("Can't find given Spinner HTML element: '"+r.elementId+"' - will automatically create default element")),s._element||s._createDefaultSpinner(),s.processes=0,s}return C(i,[{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,i=t.style;i.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",i.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 i=this._element;i&&(i.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)}}]),i}(),gt=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],mt=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e,r))._backgroundColor=$.vec3([r.backgroundColor?r.backgroundColor[0]:1,r.backgroundColor?r.backgroundColor[1]:1,r.backgroundColor?r.backgroundColor[2]:1]),s._backgroundColorFromAmbientLight=!!r.backgroundColorFromAmbientLight,s.canvas=r.canvas,s.gl=null,s.webgl2=!1,s.transparent=!!r.transparent,s.contextAttr=r.contextAttr||{},s.contextAttr.alpha=s.transparent,s.contextAttr.preserveDrawingBuffer=!!s.contextAttr.preserveDrawingBuffer,s.contextAttr.stencil=!1,s.contextAttr.premultipliedAlpha=!!s.contextAttr.premultipliedAlpha,s.contextAttr.antialias=!1!==s.contextAttr.antialias,s.resolutionScale=r.resolutionScale,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary=[s.canvas.offsetLeft,s.canvas.offsetTop,s.canvas.clientWidth,s.canvas.clientHeight],s._initWebGL(r);var n=b(s);s.canvas.addEventListener("webglcontextlost",s._webglcontextlostListener=function(e){console.time("webglcontextrestored"),n.scene._webglContextLost(),n.fire("webglcontextlost"),e.preventDefault()},!1),s.canvas.addEventListener("webglcontextrestored",s._webglcontextrestoredListener=function(e){n._initWebGL(),n.gl&&(n.scene._webglContextRestored(n.gl),n.fire("webglcontextrestored",n.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);var o=!0,a=new ResizeObserver((function(e){var t,i=c(e);try{for(i.s();!(t=i.n()).done;){t.value.contentBoxSize&&(o=!0)}}catch(e){i.e(e)}finally{i.f()}}));return a.observe(s.canvas),s._tick=s.scene.on("tick",(function(){o&&(o=!1,n.canvas.width=Math.round(n.canvas.clientWidth*n._resolutionScale),n.canvas.height=Math.round(n.canvas.clientHeight*n._resolutionScale),n.boundary[0]=n.canvas.offsetLeft,n.boundary[1]=n.canvas.offsetTop,n.boundary[2]=n.canvas.clientWidth,n.boundary[3]=n.canvas.clientHeight,n.fire("boundary",n.boundary))})),s._spinner=new vt(s.scene,{canvas:s.canvas,elementId:r.spinnerElementId}),s}return C(i,[{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-"+$.createUUID(),t=document.getElementsByTagName("body")[0],i=document.createElement("div"),s=i.style;s.height="100%",s.width="100%",s.padding="0",s.margin="0",s.background="rgba(0,0,0,0);",s.float="left",s.left="0",s.top="0",s.position="absolute",s.opacity="1.0",s["z-index"]="-10000",i.innerHTML+='',t.appendChild(i),this.canvas=document.getElementById(e)}},{key:"_getElementXY",value:function(e){for(var t=0,i=0;e;)t+=e.offsetLeft-e.scrollLeft,i+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:i}}},{key:"_initWebGL",value:function(){if(!this.gl)for(var e=0;!this.gl&&e0?yt.FS_MAX_FLOAT_PRECISION="highp":Bt.getShaderPrecisionFormat(Bt.FRAGMENT_SHADER,Bt.MEDIUM_FLOAT).precision>0?yt.FS_MAX_FLOAT_PRECISION="mediump":yt.FS_MAX_FLOAT_PRECISION="lowp":yt.FS_MAX_FLOAT_PRECISION="mediump",yt.DEPTH_BUFFER_BITS=Bt.getParameter(Bt.DEPTH_BITS),yt.MAX_TEXTURE_SIZE=Bt.getParameter(Bt.MAX_TEXTURE_SIZE),yt.MAX_CUBE_MAP_SIZE=Bt.getParameter(Bt.MAX_CUBE_MAP_TEXTURE_SIZE),yt.MAX_RENDERBUFFER_SIZE=Bt.getParameter(Bt.MAX_RENDERBUFFER_SIZE),yt.MAX_TEXTURE_UNITS=Bt.getParameter(Bt.MAX_COMBINED_TEXTURE_IMAGE_UNITS),yt.MAX_TEXTURE_IMAGE_UNITS=Bt.getParameter(Bt.MAX_TEXTURE_IMAGE_UNITS),yt.MAX_VERTEX_ATTRIBS=Bt.getParameter(Bt.MAX_VERTEX_ATTRIBS),yt.MAX_VERTEX_UNIFORM_VECTORS=Bt.getParameter(Bt.MAX_VERTEX_UNIFORM_VECTORS),yt.MAX_FRAGMENT_UNIFORM_VECTORS=Bt.getParameter(Bt.MAX_FRAGMENT_UNIFORM_VECTORS),yt.MAX_VARYING_VECTORS=Bt.getParameter(Bt.MAX_VARYING_VECTORS),Bt.getSupportedExtensions().forEach((function(e){yt.SUPPORTED_EXTENSIONS[e]=!0})))}var wt=function(){function e(){x(this,e),this.entity=null,this.primitive=null,this.primIndex=-1,this.pickSurfacePrecision=!1,this.touchInput=!1,this.snappedToEdge=!1,this.snappedToVertex=!1,this._origin=new Float64Array([0,0,0]),this._direction=new Float64Array([0,0,0]),this._indices=new Int32Array(3),this._localPos=new Float64Array([0,0,0]),this._worldPos=new Float64Array([0,0,0]),this._viewPos=new Float64Array([0,0,0]),this._canvasPos=new Int16Array([0,0]),this._snappedCanvasPos=new Int16Array([0,0]),this._bary=new Float64Array([0,0,0]),this._worldNormal=new Float64Array([0,0,0]),this._uv=new Float64Array([0,0]),this.reset()}return C(e,[{key:"canvasPos",get:function(){return this._gotCanvasPos?this._canvasPos:null},set:function(e){e?(this._canvasPos[0]=e[0],this._canvasPos[1]=e[1],this._gotCanvasPos=!0):this._gotCanvasPos=!1}},{key:"origin",get:function(){return this._gotOrigin?this._origin:null},set:function(e){e?(this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this._gotOrigin=!0):this._gotOrigin=!1}},{key:"direction",get:function(){return this._gotDirection?this._direction:null},set:function(e){e?(this._direction[0]=e[0],this._direction[1]=e[1],this._direction[2]=e[2],this._gotDirection=!0):this._gotDirection=!1}},{key:"indices",get:function(){return this.entity&&this._gotIndices?this._indices:null},set:function(e){e?(this._indices[0]=e[0],this._indices[1]=e[1],this._indices[2]=e[2],this._gotIndices=!0):this._gotIndices=!1}},{key:"localPos",get:function(){return this.entity&&this._gotLocalPos?this._localPos:null},set:function(e){e?(this._localPos[0]=e[0],this._localPos[1]=e[1],this._localPos[2]=e[2],this._gotLocalPos=!0):this._gotLocalPos=!1}},{key:"snappedCanvasPos",get:function(){return this._gotSnappedCanvasPos?this._snappedCanvasPos:null},set:function(e){e?(this._snappedCanvasPos[0]=e[0],this._snappedCanvasPos[1]=e[1],this._gotSnappedCanvasPos=!0):this._gotSnappedCanvasPos=!1}},{key:"worldPos",get:function(){return this._gotWorldPos?this._worldPos:null},set:function(e){e?(this._worldPos[0]=e[0],this._worldPos[1]=e[1],this._worldPos[2]=e[2],this._gotWorldPos=!0):this._gotWorldPos=!1}},{key:"viewPos",get:function(){return this.entity&&this._gotViewPos?this._viewPos:null},set:function(e){e?(this._viewPos[0]=e[0],this._viewPos[1]=e[1],this._viewPos[2]=e[2],this._gotViewPos=!0):this._gotViewPos=!1}},{key:"bary",get:function(){return this.entity&&this._gotBary?this._bary:null},set:function(e){e?(this._bary[0]=e[0],this._bary[1]=e[1],this._bary[2]=e[2],this._gotBary=!0):this._gotBary=!1}},{key:"worldNormal",get:function(){return this.entity&&this._gotWorldNormal?this._worldNormal:null},set:function(e){e?(this._worldNormal[0]=e[0],this._worldNormal[1]=e[1],this._worldNormal[2]=e[2],this._gotWorldNormal=!0):this._gotWorldNormal=!1}},{key:"uv",get:function(){return this.entity&&this._gotUV?this._uv:null},set:function(e){e?(this._uv[0]=e[0],this._uv[1]=e[1],this._gotUV=!0):this._gotUV=!1}},{key:"snapped",get:function(){return this.snappedToEdge||this.snappedToVertex}},{key:"reset",value:function(){this.entity=null,this.primIndex=-1,this.primitive=null,this.pickSurfacePrecision=!1,this._gotCanvasPos=!1,this._gotSnappedCanvasPos=!1,this._gotOrigin=!1,this._gotDirection=!1,this._gotIndices=!1,this._gotLocalPos=!1,this._gotWorldPos=!1,this._gotViewPos=!1,this._gotBary=!1,this._gotWorldNormal=!1,this._gotUV=!1,this.touchInput=!1,this.snappedToEdge=!1,this.snappedToVertex=!1}}]),e}(),xt=function(){function e(t,i,s){if(x(this,e),this.allocated=!1,this.compiled=!1,this.handle=t.createShader(i),this.handle){if(this.allocated=!0,t.shaderSource(this.handle,s),t.compileShader(this.handle),this.compiled=t.getShaderParameter(this.handle,t.COMPILE_STATUS),!this.compiled&&!t.isContextLost()){for(var r=s.split("\n"),n=[],o=0;o0&&"/"===t.charAt(i+1)&&(t=t.substring(0,i)),s.push(t);return s.join("\n")}function Et(e){console.error(e.join("\n"))}var kt=function(){function e(t,i){x(this,e),this.id=Mt.addItem({}),this.source=i,this.init(t)}return C(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 xt(e,e.VERTEX_SHADER,Ft(this.source.vertex)),this._fragmentShader=new xt(e,e.FRAGMENT_SHADER,Ft(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void Et(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void Et(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void Et(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void Et(this.errors);var t,i,s,r,n;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 Et(this.errors);var o=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(i=0;ithis.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}(),Dt=function(){function e(t,i){x(this,e),this.scene=t,this.aabb=$.AABB3(),this.origin=$.vec3(i),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 C(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)a._setVisible(!1);else{var l=a.canvasPos,u=l[0],A=l[1];u+10<0||A+10<0||u-10>s||A-10>r?a._setVisible(!1):!a.entity||a.entity.visible?a.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=a,this.pixels[n++]=u,this.pixels[n++]=A):a._setVisible(!0):a._setVisible(!1)}}}},{key:"_updateActiveSectionPlanes",value:function(){var e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(var i=0;i0,i=[];return i.push("#version 300 es"),i.push("// OcclusionTester vertex shader"),i.push("in vec3 position;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;")),t&&i.push("out vec4 vWorldPosition;"),i.push("void main(void) {"),i.push("vec4 worldPosition = vec4(position, 1.0); "),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&i.push(" vWorldPosition = worldPosition;"),i.push(" vec4 clipPos = projMatrix * viewPosition;"),i.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?i.push("vFragDepth = 1.0 + clipPos.w;"):i.push("clipPos.z += -0.001;"),i.push(" gl_Position = clipPos;"),i.push("}"),i}},{key:"_buildFragmentShaderSource",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// OcclusionTester fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;");for(var r=0;r 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),s.push("}"),s}},{key:"_buildProgram",value:function(){this._program&&this._program.destroy();var e=this._scene,t=e.canvas.gl,i=e._sectionPlanesState;if(this._program=new kt(t,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var s=this._program;this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,n=i.sectionPlanes.length;r0)for(var h=s.sectionPlanes,d=0;d= ( 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 s=new Float32Array([1,1,0,1,0,0,1,0]),r=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 It(i,i.ARRAY_BUFFER,r,r.length,3,i.STATIC_DRAW),this._uvBuf=new It(i,i.ARRAY_BUFFER,s,s.length,2,i.STATIC_DRAW),this._indicesBuf=new It(i,i.ELEMENT_ARRAY_BUFFER,n,n.length,1,i.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}(),Ot=new Float32Array(Gt(17,[0,1])),Nt=new Float32Array(Gt(17,[1,0])),Qt=new Float32Array(function(e,t){for(var i=[],s=0;s<=e;s++)i.push(jt(s,t));return i}(17,4)),Vt=new Float32Array(2),Ht=function(){function e(t){x(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 C(e,[{key:"init",value:function(){var e=this._scene.canvas.gl;if(this._program=new kt(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]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),s=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new It(e,e.ARRAY_BUFFER,i,i.length,3,e.STATIC_DRAW),this._uvBuf=new It(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new It(e,e.ELEMENT_ARRAY_BUFFER,s,s.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,i){var s=this;if(!this._programError){this._getInverseProjectMat||(this._getInverseProjectMat=function(){var e=!0;s._scene.camera.on("projMatrix",(function(){e=!0}));var t=$.mat4();return function(){return e&&$.inverseMat4(o.camera.projMatrix,t),t}}());var r=this._scene.canvas.gl,n=this._program,o=this._scene,a=r.drawingBufferWidth,l=r.drawingBufferHeight,u=o.camera.project._state,A=u.near,c=u.far;r.viewport(0,0,a,l),r.clearColor(0,0,0,1),r.enable(r.DEPTH_TEST),r.disable(r.BLEND),r.frontFace(r.CCW),r.clear(r.COLOR_BUFFER_BIT|r.DEPTH_BUFFER_BIT),n.bind(),Vt[0]=a,Vt[1]=l,r.uniform2fv(this._uViewport,Vt),r.uniform1f(this._uCameraNear,A),r.uniform1f(this._uCameraFar,c),r.uniform1f(this._uDepthCutoff,.01),0===i?r.uniform2fv(this._uSampleOffsets,Nt):r.uniform2fv(this._uSampleOffsets,Ot),r.uniform1fv(this._uSampleWeights,Qt);var h=e.getDepthTexture(),d=t.getTexture();n.bindTexture(this._uDepthTexture,h,0),n.bindTexture(this._uOcclusionTexture,d,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),r.drawElements(r.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}}},{key:"destroy",value:function(){this._program.destroy()}}]),e}();function jt(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function Gt(e,t){for(var i=[],s=0;s<=e;s++)i.push(t[0]*s),i.push(t[1]*s);return i}var zt=function(){function e(t,i,s){x(this,e),s=s||{},this.gl=i,this.allocated=!1,this.canvas=t,this.buffer=null,this.bound=!1,this.size=s.size,this._hasDepthTexture=!!s.depthTexture}return C(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(){if(this._touch.apply(this,arguments),!this.bound){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}}},{key:"createTexture",value:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,s=this.gl,r=s.createTexture();return s.bindTexture(s.TEXTURE_2D,r),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),i?s.texStorage2D(s.TEXTURE_2D,1,i,e,t):s.texImage2D(s.TEXTURE_2D,0,s.RGBA,e,t,0,s.RGBA,s.UNSIGNED_BYTE,null),r}},{key:"_touch",value:function(){var e,t,i=this,s=this.gl;if(this.size?(e=this.size[0],t=this.size[1]):(e=s.drawingBufferWidth,t=s.drawingBufferHeight),this.buffer){if(this.buffer.width===e&&this.buffer.height===t)return;this.buffer.textures.forEach((function(e){return s.deleteTexture(e)})),s.deleteFramebuffer(this.buffer.framebuf),s.deleteRenderbuffer(this.buffer.renderbuf)}for(var r,n=[],o=arguments.length,a=new Array(o),l=0;l0?n.push.apply(n,A(a.map((function(s){return i.createTexture(e,t,s)})))):n.push(this.createTexture(e,t)),this._hasDepthTexture&&(r=s.createTexture(),s.bindTexture(s.TEXTURE_2D,r),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texImage2D(s.TEXTURE_2D,0,s.DEPTH_COMPONENT32F,e,t,0,s.DEPTH_COMPONENT,s.FLOAT,null));var u=s.createRenderbuffer();s.bindRenderbuffer(s.RENDERBUFFER,u),s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_COMPONENT32F,e,t);var c=s.createFramebuffer();s.bindFramebuffer(s.FRAMEBUFFER,c);for(var h=0;h0&&s.drawBuffers(n.map((function(e,t){return s.COLOR_ATTACHMENT0+t}))),this._hasDepthTexture?s.framebufferTexture2D(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.TEXTURE_2D,r,0):s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,u),s.bindTexture(s.TEXTURE_2D,null),s.bindRenderbuffer(s.RENDERBUFFER,null),s.bindFramebuffer(s.FRAMEBUFFER,null),s.bindFramebuffer(s.FRAMEBUFFER,c),!s.isFramebuffer(c))throw"Invalid framebuffer";s.bindFramebuffer(s.FRAMEBUFFER,null);var d=s.checkFramebufferStatus(s.FRAMEBUFFER);switch(d){case s.FRAMEBUFFER_COMPLETE:break;case s.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case s.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case s.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case s.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+d}this.buffer={framebuf:c,renderbuf:u,texture:n[0],textures:n,depthTexture:r,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 i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Uint8Array,n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4,o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0,a=e,l=this.buffer.height?this.buffer.height-t-1:this.gl.drawingBufferHeight-t,u=new r(n),A=this.gl;return A.readBuffer(A.COLOR_ATTACHMENT0+o),A.readPixels(a,l,1,1,i||A.RGBA,s||A.UNSIGNED_BYTE,u,0),u}},{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,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Uint8Array,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:4,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,n=new i(this.buffer.width*this.buffer.height*s),o=this.gl;return o.readBuffer(o.COLOR_ATTACHMENT0+r),o.readPixels(0,0,this.buffer.width,this.buffer.height,e||o.RGBA,t||o.UNSIGNED_BYTE,n,0),n}},{key:"readImageAsCanvas",value:function(){var e=this.gl,t=this._getImageDataCache(),i=t.pixelData,s=t.canvas,r=t.imageData,n=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,i);for(var o=this.buffer.width,a=this.buffer.height,l=a/2|0,u=4*o,A=new Uint8Array(4*o),c=0;c0&&void 0!==arguments[0]?arguments[0]:Uint8Array,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4,i=this.buffer.width,s=this.buffer.height,r=this._imageDataCache;if(r&&(r.width===i&&r.height===s||(this._imageDataCache=null,r=null)),!r){var n=document.createElement("canvas"),o=n.getContext("2d");n.width=i,n.height=s,r={pixelData:new e(i*s*t),canvas:n,context:o,imageData:o.createImageData(i,s),width:i,height:s},this._imageDataCache=r}return r.context.resetTransform(),r}},{key:"unbind",value:function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.bound=!1}},{key:"getTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this;return this._texture||(this._texture={renderBuffer:this,bind:function(i){return!(!t.buffer||!t.buffer.textures[e])&&(t.gl.activeTexture(t.gl["TEXTURE"+i]),t.gl.bindTexture(t.gl.TEXTURE_2D,t.buffer.textures[e]),!0)},unbind:function(i){t.buffer&&t.buffer.textures[e]&&(t.gl.activeTexture(t.gl["TEXTURE"+i]),t.gl.bindTexture(t.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;this.buffer.textures.forEach((function(t){return e.deleteTexture(t)})),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}(),Wt=function(){function e(t){x(this,e),this.scene=t,this._renderBuffersBasic={},this._renderBuffersScaled={}}return C(e,[{key:"getRenderBuffer",value:function(e,t){var i=1===this.scene.canvas.resolutionScale?this._renderBuffersBasic:this._renderBuffersScaled,s=i[e];return s||(s=new zt(this.scene.canvas.canvas,this.scene.canvas.gl,t),i[e]=s),s}},{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 Kt(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];var i;switch(t){case"WEBGL_depth_texture":i=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":i=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":i=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":i=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:i=e.getExtension(t)}return e._cachedExtensions[t]=i,i}var Xt=function(e,t){t=t||{};var i=new _t(e),s=e.canvas.canvas,r=e.canvas.gl,n=!!t.transparent,o=t.alphaDepthMask,a=new Q({}),l={},u={},A=!0,c=!0,h=!0,d=!0,p=!0,f=!0,v=!0,g=!0,m=new Wt(e),_=!1,y=new Ut(e),b=new Ht(e);function B(){A&&(!function(){for(var e in l)if(l.hasOwnProperty(e)){var t=l[e],i=t.drawableMap,s=t.drawableListPreCull,r=0;for(var n in i)i.hasOwnProperty(n)&&(s[r++]=i[n]);s.length=r}}(),A=!1,c=!0),c&&(!function(){for(var e in l)if(l.hasOwnProperty(e)){var t=l[e];t.isStateSortable&&t.drawableListPreCull.sort(t.stateSortCompare)}}(),c=!1,h=!0),h&&function(){for(var e in l)if(l.hasOwnProperty(e)){for(var t=l[e],i=t.drawableListPreCull,s=t.drawableList,r=0,n=0,o=i.length;n0)for(i.withSAO=!0,I=0;I0)for(I=0;I0)for(I=0;I0)for(I=0;I0||G>0||N>0||Q>0){if(r.enable(r.CULL_FACE),r.enable(r.BLEND),n?(r.blendEquation(r.FUNC_ADD),r.blendFuncSeparate(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA)):(r.blendEquation(r.FUNC_ADD),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA)),i.backfaces=!1,o||r.depthMask(!1),(N>0||Q>0)&&r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA),Q>0)for(I=0;I0)for(I=0;I0)for(I=0;I0)for(I=0;I0||W>0){if(i.lastProgramId=null,e.highlightMaterial.glowThrough&&r.clear(r.DEPTH_BUFFER_BIT),W>0)for(I=0;I0)for(I=0;I0||X>0||z>0){if(i.lastProgramId=null,e.selectedMaterial.glowThrough&&r.clear(r.DEPTH_BUFFER_BIT),r.enable(r.BLEND),n?(r.blendEquation(r.FUNC_ADD),r.blendFuncSeparate(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA)):r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA),r.enable(r.CULL_FACE),X>0)for(I=0;I0)for(I=0;I0||Y>0){if(i.lastProgramId=null,e.selectedMaterial.glowThrough&&r.clear(r.DEPTH_BUFFER_BIT),Y>0)for(I=0;I0)for(I=0;I0||q>0){if(i.lastProgramId=null,e.selectedMaterial.glowThrough&&r.clear(r.DEPTH_BUFFER_BIT),r.enable(r.CULL_FACE),r.enable(r.BLEND),n?(r.blendEquation(r.FUNC_ADD),r.blendFuncSeparate(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA)):r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA),q>0)for(I=0;I0)for(I=0;I1&&void 0!==arguments[1]?arguments[1]:o;p.reset(),B();var f=null,v=null;for(var g in p.pickSurface=h.pickSurface,h.canvasPos?(u[0]=h.canvasPos[0],u[1]=h.canvasPos[1],f=e.camera.viewMatrix,v=e.camera.projMatrix,p.canvasPos=h.canvasPos):(h.matrix?(f=h.matrix,v=e.camera.projMatrix):(A.set(h.origin||[0,0,0]),c.set(h.direction||[0,0,1]),d=$.addVec3(A,c,t),r[0]=Math.random(),r[1]=Math.random(),r[2]=Math.random(),$.normalizeVec3(r),$.cross3Vec3(c,r,n),f=$.lookAtMat4v(A,d,n,i),v=e.camera.ortho.matrix,p.origin=A,p.direction=c),u[0]=.5*s.clientWidth,u[1]=.5*s.clientHeight),l)if(l.hasOwnProperty(g))for(var _=l[g].drawableList,y=0,b=_.length;y4&&void 0!==arguments[4]?arguments[4]:C;if(!n&&!o)return this.pick({canvasPos:t,pickSurface:!0});var A=e.canvas.resolutionScale;i.reset(),i.backfaces=!0,i.frontface=!0,i.pickZNear=e.camera.project.near,i.pickZFar=e.camera.project.far,s=s||30;var c=m.getRenderBuffer("uniquePickColors-aabs",{depthTexture:!0,size:[2*s+1,2*s+1]});i.snapVectorA=[k(t[0]*A,r.drawingBufferWidth),I(t[1]*A,r.drawingBufferHeight)],i.snapInvVectorAB=[r.drawingBufferWidth/(2*s),r.drawingBufferHeight/(2*s)],c.bind(r.RGBA32I,r.RGBA32I,r.RGBA8UI),r.viewport(0,0,c.size[0],c.size[1]),r.enable(r.DEPTH_TEST),r.frontFace(r.CCW),r.disable(r.CULL_FACE),r.depthMask(!0),r.disable(r.BLEND),r.depthFunc(r.LEQUAL),r.clear(r.DEPTH_BUFFER_BIT),r.clearBufferiv(r.COLOR,0,new Int32Array([0,0,0,0])),r.clearBufferiv(r.COLOR,1,new Int32Array([0,0,0,0])),r.clearBufferuiv(r.COLOR,2,new Uint32Array([0,0,0,0]));var h=e.camera.viewMatrix,d=e.camera.projMatrix;for(var p in l)if(l.hasOwnProperty(p))for(var f=l[p].drawableList,v=0,g=f.length;v0){var j=Math.floor(H/4),G=c.size[0],z=j%G-Math.floor(G/2),W=Math.floor(j/G)-Math.floor(G/2),K=Math.sqrt(Math.pow(z,2)+Math.pow(W,2));V.push({x:z,y:W,dist:K,isVertex:n&&o?B[H+3]>b.length/2:n,result:[B[H+0],B[H+1],B[H+2],B[H+3]],normal:[w[H+0],w[H+1],w[H+2],w[H+3]],id:[x[H+0],x[H+1],x[H+2],x[H+3]]})}var X=null,J=null,Y=null,Z=null;if(V.length>0){V.sort((function(e,t){return e.isVertex!==t.isVertex?e.isVertex?-1:1:e.dist-t.dist})),Z=V[0].isVertex?"vertex":"edge";var q=V[0].result,ee=V[0].normal,te=V[0].id,ie=b[q[3]],se=ie.origin,re=ie.coordinateScale;J=$.normalizeVec3([ee[0]/$.MAX_INT,ee[1]/$.MAX_INT,ee[2]/$.MAX_INT]),X=[q[0]*re[0]+se[0],q[1]*re[1]+se[1],q[2]*re[2]+se[2]],Y=a.items[te[0]+(te[1]<<8)+(te[2]<<16)+(te[3]<<24)]}if(null===P&&null==X)return null;var ne=null;null!==X&&(ne=e.camera.projectWorldPos(X));var oe=Y&&Y.delegatePickedEntity?Y.delegatePickedEntity():Y;return u.reset(),u.snappedToEdge="edge"===Z,u.snappedToVertex="vertex"===Z,u.worldPos=X,u.worldNormal=J,u.entity=oe,u.canvasPos=t,u.snappedCanvasPos=ne||t,u}),this.addMarker=function(t){this._occlusionTester=this._occlusionTester||new Rt(e,m),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 B(),this._occlusionTester.bindRenderBuf(),i.reset(),i.backfaces=!0,i.frontface=!0,r.viewport(0,0,r.drawingBufferWidth,r.drawingBufferHeight),r.clearColor(0,0,0,0),r.enable(r.DEPTH_TEST),r.disable(r.CULL_FACE),r.disable(r.BLEND),r.clear(r.COLOR_BUFFER_BIT|r.DEPTH_BUFFER_BIT),l)if(l.hasOwnProperty(e))for(var t=l[e].drawableList,s=0,n=t.length;s0&&void 0!==arguments[0]?arguments[0]:{},t=m.getRenderBuffer("snapshot");e.width&&e.height&&t.setSize([e.width,e.height]),t.bind(),t.clear(),_=!0},this.renderSnapshot=function(){_&&(m.getRenderBuffer("snapshot").clear(),this.render({force:!0,opaqueOnly:!1}),h=!0)},this.readSnapshot=function(e){return m.getRenderBuffer("snapshot").readImage(e)},this.readSnapshotAsCanvas=function(){return m.getRenderBuffer("snapshot").readImageAsCanvas()},this.endSnapshot=function(){_&&(m.getRenderBuffer("snapshot").unbind(),_=!1)},this.destroy=function(){l={},u={},m.destroy(),y.destroy(),b.destroy(),this._occlusionTester&&this._occlusionTester.destroy()}},Jt=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).KEY_BACKSPACE=8,s.KEY_TAB=9,s.KEY_ENTER=13,s.KEY_SHIFT=16,s.KEY_CTRL=17,s.KEY_ALT=18,s.KEY_PAUSE_BREAK=19,s.KEY_CAPS_LOCK=20,s.KEY_ESCAPE=27,s.KEY_PAGE_UP=33,s.KEY_PAGE_DOWN=34,s.KEY_END=35,s.KEY_HOME=36,s.KEY_LEFT_ARROW=37,s.KEY_UP_ARROW=38,s.KEY_RIGHT_ARROW=39,s.KEY_DOWN_ARROW=40,s.KEY_INSERT=45,s.KEY_DELETE=46,s.KEY_NUM_0=48,s.KEY_NUM_1=49,s.KEY_NUM_2=50,s.KEY_NUM_3=51,s.KEY_NUM_4=52,s.KEY_NUM_5=53,s.KEY_NUM_6=54,s.KEY_NUM_7=55,s.KEY_NUM_8=56,s.KEY_NUM_9=57,s.KEY_A=65,s.KEY_B=66,s.KEY_C=67,s.KEY_D=68,s.KEY_E=69,s.KEY_F=70,s.KEY_G=71,s.KEY_H=72,s.KEY_I=73,s.KEY_J=74,s.KEY_K=75,s.KEY_L=76,s.KEY_M=77,s.KEY_N=78,s.KEY_O=79,s.KEY_P=80,s.KEY_Q=81,s.KEY_R=82,s.KEY_S=83,s.KEY_T=84,s.KEY_U=85,s.KEY_V=86,s.KEY_W=87,s.KEY_X=88,s.KEY_Y=89,s.KEY_Z=90,s.KEY_LEFT_WINDOW=91,s.KEY_RIGHT_WINDOW=92,s.KEY_SELECT_KEY=93,s.KEY_NUMPAD_0=96,s.KEY_NUMPAD_1=97,s.KEY_NUMPAD_2=98,s.KEY_NUMPAD_3=99,s.KEY_NUMPAD_4=100,s.KEY_NUMPAD_5=101,s.KEY_NUMPAD_6=102,s.KEY_NUMPAD_7=103,s.KEY_NUMPAD_8=104,s.KEY_NUMPAD_9=105,s.KEY_MULTIPLY=106,s.KEY_ADD=107,s.KEY_SUBTRACT=109,s.KEY_DECIMAL_POINT=110,s.KEY_DIVIDE=111,s.KEY_F1=112,s.KEY_F2=113,s.KEY_F3=114,s.KEY_F4=115,s.KEY_F5=116,s.KEY_F6=117,s.KEY_F7=118,s.KEY_F8=119,s.KEY_F9=120,s.KEY_F10=121,s.KEY_F11=122,s.KEY_F12=123,s.KEY_NUM_LOCK=144,s.KEY_SCROLL_LOCK=145,s.KEY_SEMI_COLON=186,s.KEY_EQUAL_SIGN=187,s.KEY_COMMA=188,s.KEY_DASH=189,s.KEY_PERIOD=190,s.KEY_FORWARD_SLASH=191,s.KEY_GRAVE_ACCENT=192,s.KEY_OPEN_BRACKET=219,s.KEY_BACK_SLASH=220,s.KEY_CLOSE_BRACKET=221,s.KEY_SINGLE_QUOTE=222,s.KEY_SPACE=32,s.element=r.element,s.altDown=!1,s.ctrlDown=!1,s.mouseDownLeft=!1,s.mouseDownMiddle=!1,s.mouseDownRight=!1,s.keyDown=[],s.enabled=!0,s.keyboardEnabled=!0,s.mouseover=!1,s.mouseCanvasPos=$.vec2(),s._keyboardEventsElement=r.keyboardEventsElement||document,s._bindEvents(),s}return C(i,[{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()}});var t=this.scene.tickify((function(){return e.fire("mousemove",e.mouseCanvasPos,!0)}));this.element.addEventListener("mousemove",this._mouseMoveListener=function(i){e.enabled&&(e._getMouseCanvasPos(i),t(),e.mouseover&&i.preventDefault())});var i=this.scene.tickify((function(t){e.fire("mousewheel",t,!0)}));this.element.addEventListener("wheel",this._mouseWheelListener=function(t,s){if(e.enabled){var r=Math.max(-1,Math.min(1,40*-t.deltaY));i(r)}},{passive:!0});var s,r;this.on("mousedown",(function(e){s=e[0],r=e[1]})),this.on("mouseup",(function(t){s>=t[0]-2&&s<=t[0]+2&&r>=t[1]-2&&r<=t[1]+2&&e.fire("mouseclicked",t,!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,i=0,s=0;t.offsetParent;)i+=t.offsetLeft,s+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-i,this.mouseCanvasPos[1]=e.pageY-s}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(){f(B(i.prototype),"destroy",this).call(this),this._unbindEvents()}}]),i}(),Yt=new Q({}),Zt=function(){function e(t){for(var i in x(this,e),this.id=Yt.addItem({}),t)t.hasOwnProperty(i)&&(this[i]=t[i])}return C(e,[{key:"destroy",value:function(){Yt.removeItem(this.id)}}]),e}(),qt=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({boundary:[0,0,100,100]}),s.boundary=r.boundary,s.autoBoundary=r.autoBoundary,s}return C(i,[{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],i=e[3];this._state.boundary=[0,0,t,i],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(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),$t=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).camera=e,s._state=new Zt({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4(),near:.1,far:1e4}),s._inverseMatrixDirty=!0,s._transposedMatrixDirty=!0,s._fov=60,s._canvasResized=s.scene.canvas.on("boundary",s._needUpdate,b(s)),s.fov=r.fov,s.fovAxis=r.fovAxis,s.near=r.near,s.far=r.far,s}return C(i,[{key:"type",get:function(){return"Perspective"}},{key:"_update",value:function(){var e=this.scene.canvas.boundary,t=e[2]/e[3],i=this._fovAxis,s=this._fov;("x"===i||"min"===i&&t<1||"max"===i&&t>1)&&(s/=t),s=Math.min(s,120),$.perspectiveMat4(s*(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:1e4;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&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,i,s,r){var n=this.scene.canvas.canvas,o=n.offsetWidth/2,a=n.offsetHeight/2;return i[0]=(e[0]-o)/o,i[1]=(e[1]-a)/a,i[2]=t,i[3]=1,$.mulMat4v4(this.inverseMatrix,i,s),$.mulVec3Scalar(s,1/s[3]),s[3]=1,s[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,s,r),r}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}]),i}(),ei=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).camera=e,s._state=new Zt({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4(),near:.1,far:1e4}),s._inverseMatrixDirty=!0,s._transposedMatrixDirty=!0,s.scale=r.scale,s.near=r.near,s.far=r.far,s._onCanvasBoundary=s.scene.canvas.on("boundary",s._needUpdate,b(s)),s}return C(i,[{key:"type",get:function(){return"Ortho"}},{key:"_update",value:function(){var e,t,i,s,r=this.scene,n=.5*this._scale,o=r.canvas.boundary,a=o[2],l=o[3],u=a/l;a>l?(e=-n,t=n,i=n/u,s=-n/u):(e=-n*u,t=n*u,i=n,s=-n),$.orthoMat4c(e,t,s,i,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:1e4;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&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,i,s,r){var n=this.scene.canvas.canvas,o=n.offsetWidth/2,a=n.offsetHeight/2;return i[0]=(e[0]-o)/o,i[1]=(e[1]-a)/a,i[2]=t,i[3]=1,$.mulMat4v4(this.inverseMatrix,i,s),$.mulVec3Scalar(s,1/s[3]),s[3]=1,s[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,s,r),r}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}]),i}(),ti=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).camera=e,s._state=new Zt({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4(),near:.1,far:1e4}),s._left=-1,s._right=1,s._bottom=-1,s._top=1,s._inverseMatrixDirty=!0,s._transposedMatrixDirty=!0,s.left=r.left,s.right=r.right,s.bottom=r.bottom,s.top=r.top,s.near=r.near,s.far=r.far,s}return C(i,[{key:"type",get:function(){return"Frustum"}},{key:"_update",value:function(){$.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&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,i,s,r){var n=this.scene.canvas.canvas,o=n.offsetWidth/2,a=n.offsetHeight/2;return i[0]=(e[0]-o)/o,i[1]=(e[1]-a)/a,i[2]=t,i[3]=1,$.mulMat4v4(this.inverseMatrix,i,s),$.mulVec3Scalar(s,1/s[3]),s[3]=1,s[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,s,r),r}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy(),f(B(i.prototype),"destroy",this).call(this)}}]),i}(),ii=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).camera=e,s._state=new Zt({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4()}),s._inverseMatrixDirty=!0,s._transposedMatrixDirty=!1,s.matrix=r.matrix,s}return C(i,[{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&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,i,s,r){var n=this.scene.canvas.canvas,o=n.offsetWidth/2,a=n.offsetHeight/2;return i[0]=(e[0]-o)/o,i[1]=(e[1]-a)/a,i[2]=t,i[3]=1,$.mulMat4v4(this.inverseMatrix,i,s),$.mulVec3Scalar(s,1/s[3]),s[3]=1,s[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,s,r),r}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),si=$.vec3(),ri=$.vec3(),ni=$.vec3(),oi=$.vec3(),ai=$.vec3(),li=$.vec3(),ui=$.vec4(),Ai=$.vec4(),ci=$.vec4(),hi=$.mat4(),di=$.mat4(),pi=$.vec3(),fi=$.vec3(),vi=$.vec3(),gi=$.vec3(),mi=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({deviceMatrix:$.mat4(),hasDeviceMatrix:!1,matrix:$.mat4(),normalMatrix:$.mat4(),inverseMatrix:$.mat4()}),s._perspective=new $t(b(s)),s._ortho=new ei(b(s)),s._frustum=new ti(b(s)),s._customProjection=new ii(b(s)),s._project=s._perspective,s._eye=$.vec3([0,0,10]),s._look=$.vec3([0,0,0]),s._up=$.vec3([0,1,0]),s._worldUp=$.vec3([0,1,0]),s._worldRight=$.vec3([1,0,0]),s._worldForward=$.vec3([0,0,-1]),s.deviceMatrix=r.deviceMatrix,s.eye=r.eye,s.look=r.look,s.up=r.up,s.worldAxis=r.worldAxis,s.gimbalLock=r.gimbalLock,s.constrainPitch=r.constrainPitch,s.projection=r.projection,s._perspective.on("matrix",(function(){"perspective"===s._projectionType&&s.fire("projMatrix",s._perspective.matrix)})),s._ortho.on("matrix",(function(){"ortho"===s._projectionType&&s.fire("projMatrix",s._ortho.matrix)})),s._frustum.on("matrix",(function(){"frustum"===s._projectionType&&s.fire("projMatrix",s._frustum.matrix)})),s._customProjection.on("matrix",(function(){"customProjection"===s._projectionType&&s.fire("projMatrix",s._customProjection.matrix)})),s}return C(i,[{key:"type",get:function(){return"Camera"}},{key:"_update",value:function(){var e,t=this._state;"ortho"===this.projection?($.subVec3(this._eye,this._look,pi),$.normalizeVec3(pi,fi),$.mulVec3Scalar(fi,1e3,vi),$.addVec3(this._look,vi,gi),e=gi):e=this._eye,t.hasDeviceMatrix?($.lookAtMat4v(e,this._look,this._up,di),$.mulMat4(t.deviceMatrix,di,t.matrix)):$.lookAtMat4v(e,this._look,this._up,t.matrix),$.inverseMat4(this._state.matrix,this._state.inverseMatrix),$.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=$.subVec3(this._eye,this._look,si);$.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,hi),t=$.transformPoint3(hi,t,ri),this.eye=$.addVec3(this._look,t,ni),this.up=$.transformPoint3(hi,this._up,oi)}},{key:"orbitPitch",value:function(e){if(!(this._constrainPitch&&(e=$.dotVec3(this._up,this._worldUp)/$.DEGTORAD)<1)){var t=$.subVec3(this._eye,this._look,si),i=$.cross3Vec3($.normalizeVec3(t,ri),$.normalizeVec3(this._up,ni));$.rotationMat4v(.0174532925*e,i,hi),t=$.transformPoint3(hi,t,oi),this.up=$.transformPoint3(hi,this._up,ai),this.eye=$.addVec3(t,this._look,li)}}},{key:"yaw",value:function(e){var t=$.subVec3(this._look,this._eye,si);$.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,hi),t=$.transformPoint3(hi,t,ri),this.look=$.addVec3(t,this._eye,ni),this._gimbalLock&&(this.up=$.transformPoint3(hi,this._up,oi))}},{key:"pitch",value:function(e){if(!(this._constrainPitch&&(e=$.dotVec3(this._up,this._worldUp)/$.DEGTORAD)<1)){var t=$.subVec3(this._look,this._eye,si),i=$.cross3Vec3($.normalizeVec3(t,ri),$.normalizeVec3(this._up,ni));$.rotationMat4v(.0174532925*e,i,hi),this.up=$.transformPoint3(hi,this._up,li),t=$.transformPoint3(hi,t,oi),this.look=$.addVec3(t,this._eye,ai)}}},{key:"pan",value:function(e){var t,i=$.subVec3(this._eye,this._look,si),s=[0,0,0];if(0!==e[0]){var r=$.cross3Vec3($.normalizeVec3(i,[]),$.normalizeVec3(this._up,ri));t=$.mulVec3Scalar(r,e[0]),s[0]+=t[0],s[1]+=t[1],s[2]+=t[2]}0!==e[1]&&(t=$.mulVec3Scalar($.normalizeVec3(this._up,ni),e[1]),s[0]+=t[0],s[1]+=t[1],s[2]+=t[2]),0!==e[2]&&(t=$.mulVec3Scalar($.normalizeVec3(i,oi),e[2]),s[0]+=t[0],s[1]+=t[1],s[2]+=t[2]),this.eye=$.addVec3(this._eye,s,ai),this.look=$.addVec3(this._look,s,li)}},{key:"zoom",value:function(e){var t=$.subVec3(this._eye,this._look,si),i=Math.abs($.lenVec3(t,ri)),s=Math.abs(i+e);if(!(s<.5)){var r=$.normalizeVec3(t,ni);this.eye=$.addVec3(this._look,$.mulVec3Scalar(r,s),oi)}}},{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=$.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 $.lenVec3($.subVec3(this._look,this._eye,si))}},{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=ui,i=Ai,s=ci;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,$.mulMat4v4(this.viewMatrix,t,i),$.mulMat4v4(this.projMatrix,i,s),$.mulVec3Scalar(s,1/s[3]),s[3]=1,s[1]*=-1;var r=this.scene.canvas.canvas,n=r.offsetWidth/2,o=r.offsetHeight/2;return[s[0]*n+n,s[1]*o+o]}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),_i=function(e){g(i,Be);var t=_(i);function i(e){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),t.call(this,e,s)}return C(i,[{key:"type",get:function(){return"Light"}},{key:"isLight",get:function(){return!0}}]),i}(),yi=function(e){g(i,_i);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e,r))._shadowRenderBuf=null,s._shadowViewMatrix=null,s._shadowProjMatrix=null,s._shadowViewMatrixDirty=!0,s._shadowProjMatrixDirty=!0;var n=s.scene.camera,o=s.scene.canvas;return s._onCameraViewMatrix=n.on("viewMatrix",(function(){s._shadowViewMatrixDirty=!0})),s._onCameraProjMatrix=n.on("projMatrix",(function(){s._shadowProjMatrixDirty=!0})),s._onCanvasBoundary=o.on("boundary",(function(){s._shadowProjMatrixDirty=!0})),s._state=new Zt({type:"dir",dir:$.vec3([1,1,1]),color:$.vec3([.7,.7,.8]),intensity:1,space:r.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(s._shadowViewMatrixDirty){s._shadowViewMatrix||(s._shadowViewMatrix=$.identityMat4());var e=s.scene.camera,t=s._state.dir,i=e.look,r=[i[0]-t[0],i[1]-t[1],i[2]-t[2]];$.lookAtMat4v(r,i,[0,1,0],s._shadowViewMatrix),s._shadowViewMatrixDirty=!1}return s._shadowViewMatrix},getShadowProjMatrix:function(){return s._shadowProjMatrixDirty&&(s._shadowProjMatrix||(s._shadowProjMatrix=$.identityMat4()),$.orthoMat4c(-40,40,-40,40,-40,80,s._shadowProjMatrix),s._shadowProjMatrixDirty=!1),s._shadowProjMatrix},getShadowRenderBuf:function(){return s._shadowRenderBuf||(s._shadowRenderBuf=new zt(s.scene.canvas.canvas,s.scene.canvas.gl,{size:[1024,1024]})),s._shadowRenderBuf}}),s.dir=r.dir,s.color=r.color,s.intensity=r.intensity,s.castsShadow=r.castsShadow,s.scene._lightCreated(b(s)),s}return C(i,[{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),f(B(i.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),i}(),bi=function(e){g(i,_i);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state={type:"ambient",color:$.vec3([.7,.7,.7]),intensity:1},s.color=r.color,s.intensity=r.intensity,s.scene._lightCreated(b(s)),s}return C(i,[{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(){f(B(i.prototype),"destroy",this).call(this),this.scene._lightDestroyed(this)}}]),i}(),Bi=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),s=t.call(this,e,r),se.memory.meshes++,s}return C(i,[{key:"type",get:function(){return"Geometry"}},{key:"isGeometry",get:function(){return!0}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),se.memory.meshes--}}]),i}(),wi=function(){var e=[],t=[],i=[],s=[],r=[],n=0,o=new Uint16Array(3),a=new Uint16Array(3),l=new Uint16Array(3),u=$.vec3(),A=$.vec3(),c=$.vec3(),h=$.vec3(),d=$.vec3(),p=$.vec3(),f=$.vec3();return function(v,g,m,_){!function(r,n){var o,a,l,u,A,c,h={},d=Math.pow(10,4),p=0;for(A=0,c=r.length;AI)||(F=i[P.index1],E=i[P.index2],(!S&&F>65535||E>65535)&&(S=!0),k.push(F),k.push(E));return S?new Uint32Array(k):new Uint16Array(k)}}();var xi=function(){var e=$.mat4(),t=$.mat4();return function(i,s){s=s||$.mat4();var r=i[0],n=i[1],o=i[2],a=i[3]-r,l=i[4]-n,u=i[5]-o,A=65535;return $.identityMat4(e),$.translationMat4v(i,e),$.identityMat4(t),$.scalingMat4v([a/A,l/A,u/A],t),$.mulMat4(e,t,s),s}}(),Pi=function(){var e=$.mat4(),t=$.mat4();return function(i,s,r){var n,o=new Uint16Array(i.length),a=new Float32Array([r[0]!==s[0]?65535/(r[0]-s[0]):0,r[1]!==s[1]?65535/(r[1]-s[1]):0,r[2]!==s[2]?65535/(r[2]-s[2]):0]);for(n=0;n=0?1:-1),a=(1-Math.abs(r))*(n>=0?1:-1);r=o,n=a}return new Int8Array([Math[i](127.5*r+(r<0?-1:0)),Math[s](127.5*n+(n<0?-1:0))])}function Fi(e){var t=e[0],i=e[1];t/=t<0?127:128,i/=i<0?127:128;var s=1-Math.abs(t)-Math.abs(i);s<0&&(t=(1-Math.abs(i))*(t>=0?1:-1),i=(1-Math.abs(t))*(i>=0?1:-1));var r=Math.sqrt(t*t+i*i+s*s);return[t/r,i/r,s/r]}function Ei(e,t,i){return e[t]*i[0]+e[t+1]*i[1]+e[t+2]*i[2]}var ki={getPositionsBounds:function(e){var t,i,s=new Float32Array(3),r=new Float32Array(3);for(t=0;t<3;t++)s[t]=Number.MAX_VALUE,r[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),s=0,r=e.length;s2&&void 0!==arguments[2]?arguments[2]:e;return i[0]=e[0]*t[0]+t[12],i[1]=e[1]*t[5]+t[13],i[2]=e[2]*t[10]+t[14],i[3]=e[3]*t[0]+t[12],i[4]=e[4]*t[5]+t[13],i[5]=e[5]*t[10]+t[14],i},getUVBounds:function(e){var t,i,s=new Float32Array(2),r=new Float32Array(2);for(t=0;t<2;t++)s[t]=Number.MAX_VALUE,r[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),s=0,r=e.length;sr&&(i=t,r=s),(s=Ei(e,o,Fi(t=Mi(e,o,"floor","ceil"))))>r&&(i=t,r=s),(s=Ei(e,o,Fi(t=Mi(e,o,"ceil","ceil"))))>r&&(i=t,r=s),n[o]=i[0],n[o+1]=i[1];return n},decompressNormals:function(e,t){for(var i=0,s=0,r=e.length;i=0?1:-1),o=(1-Math.abs(n))*(o>=0?1:-1));var l=Math.sqrt(n*n+o*o+a*a);t[s+0]=n/l,t[s+1]=o/l,t[s+2]=a/l,s+=3}return t},decompressNormal:function(e,t){var i=e[0],s=e[1];i=(2*i+1)/255,s=(2*s+1)/255;var r=1-Math.abs(i)-Math.abs(s);r<0&&(i=(1-Math.abs(s))*(i>=0?1:-1),s=(1-Math.abs(i))*(s>=0?1:-1));var n=Math.sqrt(i*i+s*s+r*r);return t[0]=i/n,t[1]=s/n,t[2]=r/n,t}},Ii=se.memory,Di=$.AABB3(),Si=function(e){g(i,Bi);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e,r))._state=new Zt({compressGeometry:!!r.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:""}),s._numTriangles=0,s._edgeThreshold=r.edgeThreshold||10,s._edgeIndicesBuf=null,s._pickTrianglePositionsBuf=null,s._pickTriangleColorsBuf=null,s._aabbDirty=!0,s._boundingSphere=!0,s._aabb=null,s._aabbDirty=!0,s._obb=null,s._obbDirty=!0;var n=s._state,o=s.scene.canvas.gl;switch(r.primitive=r.primitive||"triangles",r.primitive){case"points":n.primitive=o.POINTS,n.primitiveName=r.primitive;break;case"lines":n.primitive=o.LINES,n.primitiveName=r.primitive;break;case"line-loop":n.primitive=o.LINE_LOOP,n.primitiveName=r.primitive;break;case"line-strip":n.primitive=o.LINE_STRIP,n.primitiveName=r.primitive;break;case"triangles":n.primitive=o.TRIANGLES,n.primitiveName=r.primitive;break;case"triangle-strip":n.primitive=o.TRIANGLE_STRIP,n.primitiveName=r.primitive;break;case"triangle-fan":n.primitive=o.TRIANGLE_FAN,n.primitiveName=r.primitive;break;default:s.error("Unsupported value for 'primitive': '"+r.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),n.primitive=o.TRIANGLES,n.primitiveName=r.primitive}if(r.positions)if(s._state.compressGeometry){var a=ki.getPositionsBounds(r.positions),l=ki.compressPositions(r.positions,a.min,a.max);n.positions=l.quantized,n.positionsDecodeMatrix=l.decodeMatrix}else n.positions=r.positions.constructor===Float32Array?r.positions:new Float32Array(r.positions);if(r.colors&&(n.colors=r.colors.constructor===Float32Array?r.colors:new Float32Array(r.colors)),r.uv)if(s._state.compressGeometry){var u=ki.getUVBounds(r.uv),A=ki.compressUVs(r.uv,u.min,u.max);n.uv=A.quantized,n.uvDecodeMatrix=A.decodeMatrix}else n.uv=r.uv.constructor===Float32Array?r.uv:new Float32Array(r.uv);return r.normals&&(s._state.compressGeometry?n.normals=ki.compressNormals(r.normals):n.normals=r.normals.constructor===Float32Array?r.normals:new Float32Array(r.normals)),r.indices&&(n.indices=r.indices.constructor===Uint32Array||r.indices.constructor===Uint16Array?r.indices:new Uint32Array(r.indices),"triangles"===s._state.primitiveName&&(s._numTriangles=r.indices.length/3)),s._buildHash(),Ii.meshes++,s._buildVBOs(),s}return C(i,[{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 It(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),Ii.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new It(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),Ii.positions+=e.positionsBuf.numItems),e.normals){var i=e.compressGeometry;e.normalsBuf=new It(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,i),Ii.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new It(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),Ii.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new It(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),Ii.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,i=wi(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new It(t,t.ELEMENT_ARRAY_BUFFER,i,i.length,1,t.STATIC_DRAW),Ii.indices+=this._edgeIndicesBuf.numItems}}},{key:"_buildPickTriangleVBOs",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,i=$.buildPickTriangles(e.positions,e.indices,e.compressGeometry),s=i.positions,r=i.colors;this._pickTrianglePositionsBuf=new It(t,t.ARRAY_BUFFER,s,s.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new It(t,t.ARRAY_BUFFER,r,r.length,4,t.STATIC_DRAW,!0),Ii.positions+=this._pickTrianglePositionsBuf.numItems,Ii.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),ki.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null},set:function(e){var t=this._state,i=t.positions;if(i)if(i.length===e.length){if(this._state.compressGeometry){var s=ki.getPositionsBounds(e),r=ki.compressPositions(e,s.min,s.max);e=r.quantized,t.positionsDecodeMatrix=r.decodeMatrix}i.set(e),t.positionsBuf&&t.positionsBuf.setData(i),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),ki.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,i=t.normals;i?i.length===e.length?(i.set(e),t.normalsBuf&&t.normalsBuf.setData(i),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),ki.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,i=t.uv;i?i.length===e.length?(i.set(e),t.uvBuf&&t.uvBuf.setData(i),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,i=t.colors;i?i.length===e.length?(i.set(e),t.colorsBuf&&t.colorsBuf.setData(i),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=$.AABB3()),$.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=$.OBB3()),$.positions3ToAABB3(this._state.positions,Di,this._state.positionsDecodeMatrix),$.AABB3ToOBB3(Di,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(){f(B(i.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(),Ii.meshes--}}]),i}();function Ti(){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 i=e.ySize||1;i<0&&(console.error("negative ySize not allowed - will invert"),i*=-1);var s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);var r=e.center,n=r?r[0]:0,o=r?r[1]:0,a=r?r[2]:0,l=-t+n,u=-i+o,A=-s+a,c=t+n,h=i+o,d=s+a;return le.apply(e,{positions:[c,h,d,l,h,d,l,u,d,c,u,d,c,h,d,c,u,d,c,u,A,c,h,A,c,h,d,c,h,A,l,h,A,l,h,d,l,h,d,l,h,A,l,u,A,l,u,d,l,u,A,c,u,A,c,u,d,l,u,d,c,u,A,l,u,A,l,h,A,c,h,A],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 Ri=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),s=t.call(this,e,r),se.memory.materials++,s}return C(i,[{key:"type",get:function(){return"Material"}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),se.memory.materials--}}]),i}(),Li={opaque:0,mask:1,blend:2},Ui=["opaque","mask","blend"],Oi=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"PhongMaterial",ambient:$.vec3([1,1,1]),diffuse:$.vec3([1,1,1]),specular:$.vec3([1,1,1]),emissive:$.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),s.ambient=r.ambient,s.diffuse=r.diffuse,s.specular=r.specular,s.emissive=r.emissive,s.alpha=r.alpha,s.shininess=r.shininess,s.reflectivity=r.reflectivity,s.lineWidth=r.lineWidth,s.pointSize=r.pointSize,r.ambientMap&&(s._ambientMap=s._checkComponent("Texture",r.ambientMap)),r.diffuseMap&&(s._diffuseMap=s._checkComponent("Texture",r.diffuseMap)),r.specularMap&&(s._specularMap=s._checkComponent("Texture",r.specularMap)),r.emissiveMap&&(s._emissiveMap=s._checkComponent("Texture",r.emissiveMap)),r.alphaMap&&(s._alphaMap=s._checkComponent("Texture",r.alphaMap)),r.reflectivityMap&&(s._reflectivityMap=s._checkComponent("Texture",r.reflectivityMap)),r.normalMap&&(s._normalMap=s._checkComponent("Texture",r.normalMap)),r.occlusionMap&&(s._occlusionMap=s._checkComponent("Texture",r.occlusionMap)),r.diffuseFresnel&&(s._diffuseFresnel=s._checkComponent("Fresnel",r.diffuseFresnel)),r.specularFresnel&&(s._specularFresnel=s._checkComponent("Fresnel",r.specularFresnel)),r.emissiveFresnel&&(s._emissiveFresnel=s._checkComponent("Fresnel",r.emissiveFresnel)),r.alphaFresnel&&(s._alphaFresnel=s._checkComponent("Fresnel",r.alphaFresnel)),r.reflectivityFresnel&&(s._reflectivityFresnel=s._checkComponent("Fresnel",r.reflectivityFresnel)),s.alphaMode=r.alphaMode,s.alphaCutoff=r.alphaCutoff,s.backfaces=r.backfaces,s.frontface=r.frontface,s._makeHash(),s}return C(i,[{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 Ui[this._state.alphaMode]},set:function(e){var t=Li[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(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),Ni={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:[1,1,1],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}},Qi=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),s._preset="default",r.preset?(s.preset=r.preset,void 0!==r.fill&&(s.fill=r.fill),r.fillColor&&(s.fillColor=r.fillColor),void 0!==r.fillAlpha&&(s.fillAlpha=r.fillAlpha),void 0!==r.edges&&(s.edges=r.edges),r.edgeColor&&(s.edgeColor=r.edgeColor),void 0!==r.edgeAlpha&&(s.edgeAlpha=r.edgeAlpha),void 0!==r.edgeWidth&&(s.edgeWidth=r.edgeWidth),void 0!==r.backfaces&&(s.backfaces=r.backfaces),void 0!==r.glowThrough&&(s.glowThrough=r.glowThrough)):(s.fill=r.fill,s.fillColor=r.fillColor,s.fillAlpha=r.fillAlpha,s.edges=r.edges,s.edgeColor=r.edgeColor,s.edgeAlpha=r.edgeAlpha,s.edgeWidth=r.edgeWidth,s.backfaces=r.backfaces,s.glowThrough=r.glowThrough),s}return C(i,[{key:"type",get:function(){return"EmphasisMaterial"}},{key:"presets",get:function(){return Ni}},{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=Ni[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(Ni).join(", "))}}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),Vi={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}},Hi=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),s._preset="default",r.preset?(s.preset=r.preset,r.edgeColor&&(s.edgeColor=r.edgeColor),void 0!==r.edgeAlpha&&(s.edgeAlpha=r.edgeAlpha),void 0!==r.edgeWidth&&(s.edgeWidth=r.edgeWidth)):(s.edgeColor=r.edgeColor,s.edgeAlpha=r.edgeAlpha,s.edgeWidth=r.edgeWidth),s.edges=!1!==r.edges,s}return C(i,[{key:"type",get:function(){return"EdgeMaterial"}},{key:"presets",get:function(){return Vi}},{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=Vi[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(Vi).join(", "))}}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),ji={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"}},Gi=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._units="meters",s._scale=1,s._origin=$.vec3([0,0,0]),s.units=r.units,s.scale=r.scale,s.origin=r.origin,s}return C(i,[{key:"unitsInfo",get:function(){return ji}},{key:"units",get:function(){return this._units},set:function(e){e||(e="meters"),ji[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]:$.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]:$.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}}]),i}(),zi=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._supported=yt.SUPPORTED_EXTENSIONS.OES_standard_derivatives,s.enabled=r.enabled,s.kernelRadius=r.kernelRadius,s.intensity=r.intensity,s.bias=r.bias,s.scale=r.scale,s.minResolution=r.minResolution,s.numSamples=r.numSamples,s.blur=r.blur,s.blendCutoff=r.blendCutoff,s.blendFactor=r.blendFactor,s}return C(i,[{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(){f(B(i.prototype),"destroy",this).call(this)}}]),i}(),Wi=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).sliceColor=r.sliceColor,s.sliceThickness=r.sliceThickness,s}return C(i,[{key:"sliceThickness",get:function(){return this._sliceThickness},set:function(e){null==e&&(e=0),this._sliceThickness!==e&&(this._sliceThickness=e,this.glRedraw())}},{key:"sliceColor",get:function(){return this._sliceColor},set:function(e){null==e&&(e=[0,0,0,1]),this._sliceColor!==e&&(this._sliceColor=e,this.glRedraw())}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this)}}]),i}(),Ki={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}},Xi=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),r.preset?(s.preset=r.preset,void 0!==r.pointSize&&(s.pointSize=r.pointSize),void 0!==r.roundPoints&&(s.roundPoints=r.roundPoints),void 0!==r.perspectivePoints&&(s.perspectivePoints=r.perspectivePoints),void 0!==r.minPerspectivePointSize&&(s.minPerspectivePointSize=r.minPerspectivePointSize),void 0!==r.maxPerspectivePointSize&&(s.maxPerspectivePointSize=r.minPerspectivePointSize)):(s._preset="default",s.pointSize=r.pointSize,s.roundPoints=r.roundPoints,s.perspectivePoints=r.perspectivePoints,s.minPerspectivePointSize=r.minPerspectivePointSize,s.maxPerspectivePointSize=r.maxPerspectivePointSize),s.filterIntensity=r.filterIntensity,s.minIntensity=r.minIntensity,s.maxIntensity=r.maxIntensity,s}return C(i,[{key:"type",get:function(){return"PointsMaterial"}},{key:"presets",get:function(){return Ki}},{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=Ki[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(Ki).join(", "))}}},{key:"hash",get:function(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),Ji={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}},Yi=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"LinesMaterial",lineWidth:null}),r.preset?(s.preset=r.preset,void 0!==r.lineWidth&&(s.lineWidth=r.lineWidth)):(s._preset="default",s.lineWidth=r.lineWidth),s}return C(i,[{key:"type",get:function(){return"LinesMaterial"}},{key:"presets",get:function(){return Ji}},{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=Ji[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Ji).join(", "))}}},{key:"hash",get:function(){return[""+this.lineWidth].join(";")}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}();function Zi(e,t){for(var i,s,r={},n=0,o=t.length;n1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),s=t.call(this,null,r);var n=r.canvasElement||document.getElementById(r.canvasId);if(!(n instanceof HTMLCanvasElement))throw"Mandatory config expected: valid canvasId or canvasElement";s._tickifiedFunctions={};var o=!!r.transparent,a=!!r.alphaDepthMask;return s._aabbDirty=!0,s.viewer=e,s.occlusionTestCountdown=0,s.loading=0,s.startTime=(new Date).getTime(),s.models={},s.objects={},s._numObjects=0,s.visibleObjects={},s._numVisibleObjects=0,s.xrayedObjects={},s._numXRayedObjects=0,s.highlightedObjects={},s._numHighlightedObjects=0,s.selectedObjects={},s._numSelectedObjects=0,s.colorizedObjects={},s._numColorizedObjects=0,s.opacityObjects={},s._numOpacityObjects=0,s.offsetObjects={},s._numOffsetObjects=0,s._modelIds=null,s._objectIds=null,s._visibleObjectIds=null,s._xrayedObjectIds=null,s._highlightedObjectIds=null,s._selectedObjectIds=null,s._colorizedObjectIds=null,s._opacityObjectIds=null,s._offsetObjectIds=null,s._collidables={},s._compilables={},s._needRecompile=!1,s.types={},s.components={},s.sectionPlanes={},s.lights={},s.lightMaps={},s.reflectionMaps={},s.bitmaps={},s.lineSets={},s.realWorldOffset=r.realWorldOffset||new Float64Array([0,0,0]),s.canvas=new mt(b(s),{dontClear:!0,canvas:n,spinnerElementId:r.spinnerElementId,transparent:o,webgl2:!1!==r.webgl2,contextAttr:r.contextAttr||{},backgroundColor:r.backgroundColor,backgroundColorFromAmbientLight:r.backgroundColorFromAmbientLight,premultipliedAlpha:r.premultipliedAlpha}),s.canvas.on("boundary",(function(){s.glRedraw()})),s.canvas.on("webglContextFailed",(function(){alert("xeokit failed to find WebGL!")})),s._renderer=new Xt(b(s),{transparent:o,alphaDepthMask:a}),s._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1,this._numCachedSectionPlanes=0;var e=null;this.getHash=function(){if(e)return e;var t=this.getNumAllocatedSectionPlanes();if(this.sectionPlanes,0===t)return this.hash=";";for(var i=[],s=0,r=t;sthis._numCachedSectionPlanes?e:this._numCachedSectionPlanes}},s._sectionPlanesState.setNumCachedSectionPlanes(r.numCachedSectionPlanes||0),s._lightsState=new function(){var e=$.vec4([0,0,0,0]),t=$.vec4();this.lights=[],this.reflectionMaps=[],this.lightMaps=[];var i=null,s=null;this.getHash=function(){if(i)return i;for(var e,t=[],s=this.lights,r=0,n=s.length;r0&&t.push("/lm"),this.reflectionMaps.length>0&&t.push("/rm"),t.push(";"),i=t.join("")},this.addLight=function(e){this.lights.push(e),s=null,i=null},this.removeLight=function(e){for(var t=0,r=this.lights.length;t1&&void 0!==arguments[1])||arguments[1];e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}},{key:"_deRegisterVisibleObject",value:function(e){delete this.visibleObjects[e.id],this._numVisibleObjects--,this._visibleObjectIds=null}},{key:"_objectXRayedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}},{key:"_deRegisterXRayedObject",value:function(e){delete this.xrayedObjects[e.id],this._numXRayedObjects--,this._xrayedObjectIds=null}},{key:"_objectHighlightedUpdated",value:function(e){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null}},{key:"_deRegisterHighlightedObject",value:function(e){delete this.highlightedObjects[e.id],this._numHighlightedObjects--,this._highlightedObjectIds=null}},{key:"_objectSelectedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}},{key:"_deRegisterSelectedObject",value:function(e){delete this.selectedObjects[e.id],this._numSelectedObjects--,this._selectedObjectIds=null}},{key:"_objectColorizeUpdated",value:function(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}},{key:"_deRegisterColorizedObject",value:function(e){delete this.colorizedObjects[e.id],this._numColorizedObjects--,this._colorizedObjectIds=null}},{key:"_objectOpacityUpdated",value:function(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}},{key:"_deRegisterOpacityObject",value:function(e){delete this.opacityObjects[e.id],this._numOpacityObjects--,this._opacityObjectIds=null}},{key:"_objectOffsetUpdated",value:function(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}},{key:"_deRegisterOffsetObject",value:function(e){delete this.offsetObjects[e.id],this._numOffsetObjects--,this._offsetObjectIds=null}},{key:"_webglContextLost",value:function(){for(var e in this.canvas.spinner.processes++,this.components)if(this.components.hasOwnProperty(e)){var t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}},{key:"_webglContextRestored",value:function(){var e=this.canvas.gl;for(var t in this.components)if(this.components.hasOwnProperty(t)){var i=this.components[t];i._webglContextRestored&&i._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}},{key:"capabilities",get:function(){return this._renderer.capabilities}},{key:"entityOffsetsEnabled",get:function(){return this._entityOffsetsEnabled}},{key:"pickSurfacePrecisionEnabled",get:function(){return!1}},{key:"logarithmicDepthBufferEnabled",get:function(){return this._logarithmicDepthBufferEnabled}},{key:"numCachedSectionPlanes",get:function(){return this._sectionPlanesState.getNumCachedSectionPlanes()},set:function(e){e=e||0,this._sectionPlanesState.getNumCachedSectionPlanes()!==e&&(this._sectionPlanesState.setNumCachedSectionPlanes(e),this._needRecompile=!0,this.glRedraw())}},{key:"pbrEnabled",get:function(){return this._pbrEnabled},set:function(e){this._pbrEnabled=!!e,this.glRedraw()}},{key:"dtxEnabled",get:function(){return this._dtxEnabled},set:function(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled},set:function(e){this._colorTextureEnabled=!!e,this.glRedraw()}},{key:"doOcclusionTest",value:function(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}},{key:"render",value:function(e){e&&_e.runTasks();var t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),e||this._renderer.needsRender()){t.sceneId=this.id;var i,s,r=this._passes,n=this._clearEachPass;for(i=0;in&&(n=e[3]),e[4]>o&&(o=e[4]),e[5]>a&&(a=e[5]),u=!0}u||(i=-100,s=-100,r=-100,n=100,o=100,a=100),this._aabb[0]=i,this._aabb[1]=s,this._aabb[2]=r,this._aabb[3]=n,this._aabb[4]=o,this._aabb[5]=a,this._aabbDirty=!1}return this._aabb}},{key:"_setAABBDirty",value:function(){this._aabbDirty=!0,this.fire("boundary")}},{key:"pick",value:function(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");var i=e.includeEntities||e.include;i&&(e.includeEntityIds=Zi(this,i));var s=e.excludeEntities||e.exclude;return s&&(e.excludeEntityIds=Zi(this,s)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=e.snapToEdge||e.snapToVertex?this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapToVertex,e.snapToEdge,t):this._renderer.pick(e,t))&&t.entity&&t.entity.fire&&t.entity.fire("picked",t),t}},{key:"snapPick",value:function(e){return void 0===this._warnSnapPickDeprecated&&(this._warnSnapPickDeprecated=!0,this.warn("Scene.snapPick() is deprecated since v2.4.2 - use Scene.pick() instead")),this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapToVertex,e.snapToEdge)}},{key:"clear",value:function(){var e;for(var t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}},{key:"clearLights",value:function(){for(var e=Object.keys(this.lights),t=0,i=e.length;to&&(o=t[3]),t[4]>a&&(a=t[4]),t[5]>l&&(l=t[5]),i=!0}})),i){var u=$.AABB3();return u[0]=s,u[1]=r,u[2]=n,u[3]=o,u[4]=a,u[5]=l,u}return this.aabb}},{key:"setObjectsVisible",value:function(e,t){return this.withObjects(e,(function(e){var i=e.visible!==t;return e.visible=t,i}))}},{key:"setObjectsCollidable",value:function(e,t){return this.withObjects(e,(function(e){var i=e.collidable!==t;return e.collidable=t,i}))}},{key:"setObjectsCulled",value:function(e,t){return this.withObjects(e,(function(e){var i=e.culled!==t;return e.culled=t,i}))}},{key:"setObjectsSelected",value:function(e,t){return this.withObjects(e,(function(e){var i=e.selected!==t;return e.selected=t,i}))}},{key:"setObjectsHighlighted",value:function(e,t){return this.withObjects(e,(function(e){var i=e.highlighted!==t;return e.highlighted=t,i}))}},{key:"setObjectsXRayed",value:function(e,t){return this.withObjects(e,(function(e){var i=e.xrayed!==t;return e.xrayed=t,i}))}},{key:"setObjectsEdges",value:function(e,t){return this.withObjects(e,(function(e){var i=e.edges!==t;return e.edges=t,i}))}},{key:"setObjectsColorized",value:function(e,t){return this.withObjects(e,(function(e){e.colorize=t}))}},{key:"setObjectsOpacity",value:function(e,t){return this.withObjects(e,(function(e){var i=e.opacity!==t;return e.opacity=t,i}))}},{key:"setObjectsPickable",value:function(e,t){return this.withObjects(e,(function(e){var i=e.pickable!==t;return e.pickable=t,i}))}},{key:"setObjectsOffset",value:function(e,t){this.withObjects(e,(function(e){e.offset=t}))}},{key:"withObjects",value:function(e,t){le.isString(e)&&(e=[e]);for(var i=!1,s=0,r=e.length;ss&&(s=r,e.apply(void 0,A(i)))}));return this._tickifiedFunctions[t]={tickSubId:o,wrapperFunc:n},n}},{key:"destroy",value:function(){for(var e in f(B(i.prototype),"destroy",this).call(this),this.components)this.components.hasOwnProperty(e)&&this.components[e].destroy();this.canvas.gl=null,this.components=null,this.models=null,this.objects=null,this.visibleObjects=null,this.xrayedObjects=null,this.highlightedObjects=null,this.selectedObjects=null,this.colorizedObjects=null,this.opacityObjects=null,this.sectionPlanes=null,this.lights=null,this.lightMaps=null,this.reflectionMaps=null,this._objectIds=null,this._visibleObjectIds=null,this._xrayedObjectIds=null,this._highlightedObjectIds=null,this._selectedObjectIds=null,this._colorizedObjectIds=null,this.types=null,this.components=null,this.canvas=null,this._renderer=null,this.input=null,this._viewport=null,this._camera=null}}]),i}(),$i=1e3,es=1001,ts=1002,is=1003,ss=1004,rs=1004,ns=1005,os=1005,as=1006,ls=1007,us=1007,As=1008,cs=1008,hs=1009,ds=1010,ps=1011,fs=1012,vs=1013,gs=1014,ms=1015,_s=1016,ys=1017,bs=1018,Bs=1020,ws=1021,xs=1022,Ps=1023,Cs=1024,Ms=1025,Fs=1026,Es=1027,ks=1028,Is=1029,Ds=1030,Ss=1031,Ts=1033,Rs=33776,Ls=33777,Us=33778,Os=33779,Ns=35840,Qs=35841,Vs=35842,Hs=35843,js=36196,Gs=37492,zs=37496,Ws=37808,Ks=37809,Xs=37810,Js=37811,Ys=37812,Zs=37813,qs=37814,$s=37815,er=37816,tr=37817,ir=37818,sr=37819,rr=37820,nr=37821,or=36492,ar=3e3,lr=3001,ur=1e4,Ar=10001,cr=10002,hr=10003,dr=function(e){"LambertMaterial"===e._material._state.type?(this.vertex=function(e){var t=e.scene,i=e.scene._sectionPlanesState,s=e.scene._lightsState,r=e._geometry._state,n=e._state.billboard,o=e._state.stationary,a=i.getNumAllocatedSectionPlanes()>0,l=!!r.compressGeometry,u=[];u.push("#version 300 es"),u.push("// Lambertian drawing vertex shader"),u.push("in vec3 position;"),u.push("uniform mat4 modelMatrix;"),u.push("uniform mat4 viewMatrix;"),u.push("uniform mat4 projMatrix;"),u.push("uniform vec4 colorize;"),u.push("uniform vec3 offset;"),l&&u.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(u.push("uniform float logDepthBufFC;"),u.push("out float vFragDepth;"),u.push("bool isPerspectiveMatrix(mat4 m) {"),u.push(" return (m[2][3] == - 1.0);"),u.push("}"),u.push("out float isPerspective;"));a&&u.push("out vec4 vWorldPosition;");if(u.push("uniform vec4 lightAmbient;"),u.push("uniform vec4 materialColor;"),u.push("uniform vec3 materialEmissive;"),r.normalsBuf){u.push("in vec3 normal;"),u.push("uniform mat4 modelNormalMatrix;"),u.push("uniform mat4 viewNormalMatrix;");for(var A=0,c=s.lights.length;A= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),u.push(" }"),u.push(" return normalize(v);"),u.push("}"))}u.push("out vec4 vColor;"),"points"===r.primitiveName&&u.push("uniform float pointSize;");"spherical"!==n&&"cylindrical"!==n||(u.push("void billboard(inout mat4 mat) {"),u.push(" mat[0][0] = 1.0;"),u.push(" mat[0][1] = 0.0;"),u.push(" mat[0][2] = 0.0;"),"spherical"===n&&(u.push(" mat[1][0] = 0.0;"),u.push(" mat[1][1] = 1.0;"),u.push(" mat[1][2] = 0.0;")),u.push(" mat[2][0] = 0.0;"),u.push(" mat[2][1] = 0.0;"),u.push(" mat[2][2] =1.0;"),u.push("}"));u.push("void main(void) {"),u.push("vec4 localPosition = vec4(position, 1.0); "),u.push("vec4 worldPosition;"),l&&u.push("localPosition = positionsDecodeMatrix * localPosition;");r.normalsBuf&&(l?u.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):u.push("vec4 localNormal = vec4(normal, 0.0); "),u.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),u.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));u.push("mat4 viewMatrix2 = viewMatrix;"),u.push("mat4 modelMatrix2 = modelMatrix;"),o&&u.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===n||"cylindrical"===n?(u.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),u.push("billboard(modelMatrix2);"),u.push("billboard(viewMatrix2);"),u.push("billboard(modelViewMatrix);"),r.normalsBuf&&(u.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),u.push("billboard(modelNormalMatrix2);"),u.push("billboard(viewNormalMatrix2);"),u.push("billboard(modelViewNormalMatrix);")),u.push("worldPosition = modelMatrix2 * localPosition;"),u.push("worldPosition.xyz = worldPosition.xyz + offset;"),u.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(u.push("worldPosition = modelMatrix2 * localPosition;"),u.push("worldPosition.xyz = worldPosition.xyz + offset;"),u.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r.normalsBuf&&u.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(u.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),u.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),u.push("float lambertian = 1.0;"),r.normalsBuf)for(var d=0,p=s.lights.length;d0,n=t.gammaOutput,o=[];o.push("#version 300 es"),o.push("// Lambertian drawing fragment shader"),o.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),o.push("precision highp float;"),o.push("precision highp int;"),o.push("#else"),o.push("precision mediump float;"),o.push("precision mediump int;"),o.push("#endif"),t.logarithmicDepthBufferEnabled&&(o.push("in float isPerspective;"),o.push("uniform float logDepthBufFC;"),o.push("in float vFragDepth;"));if(r){o.push("in vec4 vWorldPosition;"),o.push("uniform bool clippable;");for(var a=0,l=i.getNumAllocatedSectionPlanes();a 0.0) { discard; }"),o.push("}")}"points"===s.primitiveName&&(o.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),o.push("float r = dot(cxy, cxy);"),o.push("if (r > 1.0) {"),o.push(" discard;"),o.push("}"));t.logarithmicDepthBufferEnabled&&o.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?o.push("outColor = linearToGamma(vColor, gammaFactor);"):o.push("outColor = vColor;");return o.push("}"),o}(e)):(this.vertex=function(e){var t=e.scene;e._material;var i,s=e._state,r=t._sectionPlanesState,n=e._geometry._state,o=t._lightsState,a=s.billboard,l=s.background,u=s.stationary,A=function(e){if(!e._geometry._state.uvBuf)return!1;var t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),c=vr(e),h=r.getNumAllocatedSectionPlanes()>0,d=fr(e),p=!!n.compressGeometry,f=[];f.push("#version 300 es"),f.push("// Drawing vertex shader"),f.push("in vec3 position;"),p&&f.push("uniform mat4 positionsDecodeMatrix;");f.push("uniform mat4 modelMatrix;"),f.push("uniform mat4 viewMatrix;"),f.push("uniform mat4 projMatrix;"),f.push("out vec3 vViewPosition;"),f.push("uniform vec3 offset;"),h&&f.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(f.push("uniform float logDepthBufFC;"),f.push("out float vFragDepth;"),f.push("bool isPerspectiveMatrix(mat4 m) {"),f.push(" return (m[2][3] == - 1.0);"),f.push("}"),f.push("out float isPerspective;"));o.lightMaps.length>0&&f.push("out vec3 vWorldNormal;");if(c){f.push("in vec3 normal;"),f.push("uniform mat4 modelNormalMatrix;"),f.push("uniform mat4 viewNormalMatrix;"),f.push("out vec3 vViewNormal;");for(var v=0,g=o.lights.length;v= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),f.push(" }"),f.push(" return normalize(v);"),f.push("}"))}A&&(f.push("in vec2 uv;"),f.push("out vec2 vUV;"),p&&f.push("uniform mat3 uvDecodeMatrix;"));n.colors&&(f.push("in vec4 color;"),f.push("out vec4 vColor;"));"points"===n.primitiveName&&f.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(f.push("void billboard(inout mat4 mat) {"),f.push(" mat[0][0] = 1.0;"),f.push(" mat[0][1] = 0.0;"),f.push(" mat[0][2] = 0.0;"),"spherical"===a&&(f.push(" mat[1][0] = 0.0;"),f.push(" mat[1][1] = 1.0;"),f.push(" mat[1][2] = 0.0;")),f.push(" mat[2][0] = 0.0;"),f.push(" mat[2][1] = 0.0;"),f.push(" mat[2][2] =1.0;"),f.push("}"));if(d){f.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(var m=0,_=o.lights.length;m<_;m++)o.lights[m].castsShadow&&(f.push("uniform mat4 shadowViewMatrix"+m+";"),f.push("uniform mat4 shadowProjMatrix"+m+";"),f.push("out vec4 vShadowPosFromLight"+m+";"))}f.push("void main(void) {"),f.push("vec4 localPosition = vec4(position, 1.0); "),f.push("vec4 worldPosition;"),p&&f.push("localPosition = positionsDecodeMatrix * localPosition;");c&&(p?f.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):f.push("vec4 localNormal = vec4(normal, 0.0); "),f.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),f.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));f.push("mat4 viewMatrix2 = viewMatrix;"),f.push("mat4 modelMatrix2 = modelMatrix;"),u?f.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;"):l&&f.push("viewMatrix2[3] = vec4(0.0, 0.0, 0.0 ,1.0);");"spherical"===a||"cylindrical"===a?(f.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),f.push("billboard(modelMatrix2);"),f.push("billboard(viewMatrix2);"),f.push("billboard(modelViewMatrix);"),c&&(f.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),f.push("billboard(modelNormalMatrix2);"),f.push("billboard(viewNormalMatrix2);"),f.push("billboard(modelViewNormalMatrix);")),f.push("worldPosition = modelMatrix2 * localPosition;"),f.push("worldPosition.xyz = worldPosition.xyz + offset;"),f.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(f.push("worldPosition = modelMatrix2 * localPosition;"),f.push("worldPosition.xyz = worldPosition.xyz + offset;"),f.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));if(c){f.push("vec3 worldNormal = (modelNormalMatrix2 * localNormal).xyz; "),o.lightMaps.length>0&&f.push("vWorldNormal = worldNormal;"),f.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),f.push("vec3 tmpVec3;"),f.push("float lightDist;");for(var y=0,b=o.lights.length;y0,l=vr(e),u=s.uvBuf,A="PhongMaterial"===o.type,c="MetallicMaterial"===o.type,h="SpecularMaterial"===o.type,d=fr(e);t.gammaInput;var p=t.gammaOutput,f=[];f.push("#version 300 es"),f.push("// Drawing fragment shader"),f.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),f.push("precision highp float;"),f.push("precision highp int;"),f.push("#else"),f.push("precision mediump float;"),f.push("precision mediump int;"),f.push("#endif"),t.logarithmicDepthBufferEnabled&&(f.push("in float isPerspective;"),f.push("uniform float logDepthBufFC;"),f.push("in float vFragDepth;"));d&&(f.push("float unpackDepth (vec4 color) {"),f.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),f.push(" return dot(color, bitShift);"),f.push("}"));f.push("uniform float gammaFactor;"),f.push("vec4 linearToLinear( in vec4 value ) {"),f.push(" return value;"),f.push("}"),f.push("vec4 sRGBToLinear( in vec4 value ) {"),f.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),f.push("}"),f.push("vec4 gammaToLinear( in vec4 value) {"),f.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),f.push("}"),p&&(f.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),f.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),f.push("}"));if(a){f.push("in vec4 vWorldPosition;"),f.push("uniform bool clippable;");for(var v=0;v0&&(f.push("uniform samplerCube lightMap;"),f.push("uniform mat4 viewNormalMatrix;")),n.reflectionMaps.length>0&&f.push("uniform samplerCube reflectionMap;"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&f.push("uniform mat4 viewMatrix;"),f.push("#define PI 3.14159265359"),f.push("#define RECIPROCAL_PI 0.31830988618"),f.push("#define RECIPROCAL_PI2 0.15915494"),f.push("#define EPSILON 1e-6"),f.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),f.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),f.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),f.push("}"),f.push("struct IncidentLight {"),f.push(" vec3 color;"),f.push(" vec3 direction;"),f.push("};"),f.push("struct ReflectedLight {"),f.push(" vec3 diffuse;"),f.push(" vec3 specular;"),f.push("};"),f.push("struct Geometry {"),f.push(" vec3 position;"),f.push(" vec3 viewNormal;"),f.push(" vec3 worldNormal;"),f.push(" vec3 viewEyeDir;"),f.push("};"),f.push("struct Material {"),f.push(" vec3 diffuseColor;"),f.push(" float specularRoughness;"),f.push(" vec3 specularColor;"),f.push(" float shine;"),f.push("};"),A&&((n.lightMaps.length>0||n.reflectionMaps.length>0)&&(f.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(f.push(" vec3 irradiance = "+pr[n.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),f.push(" radiance *= PI;"),f.push(" reflectedLight.specular += radiance;")),f.push("}")),f.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),f.push(" vec3 irradiance = dotNL * directLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),f.push("}")),(c||h)&&(f.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),f.push(" float r = ggxRoughness + 0.0001;"),f.push(" return (2.0 / (r * r) - 2.0);"),f.push("}"),f.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),f.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),f.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),f.push("}"),n.reflectionMaps.length>0&&(f.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),f.push(" vec3 envMapColor = "+pr[n.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),f.push(" return envMapColor;"),f.push("}")),f.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),f.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),f.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),f.push("}"),f.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" return 1.0 / ( gl * gv );"),f.push("}"),f.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" return 0.5 / max( gv + gl, EPSILON );"),f.push("}"),f.push("float D_GGX(const in float alpha, const in float dotNH) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),f.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float alpha = ( roughness * roughness );"),f.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),f.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),f.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),f.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),f.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),f.push(" vec3 F = F_Schlick( specularColor, dotLH );"),f.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),f.push(" float D = D_GGX( alpha, dotNH );"),f.push(" return F * (G * D);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),f.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),f.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),f.push(" vec4 r = roughness * c0 + c1;"),f.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),f.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),f.push(" return specularColor * AB.x + AB.y;"),f.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(f.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(f.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),f.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),f.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),f.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),f.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),f.push("}")),f.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),f.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),f.push("}")));f.push("in vec3 vViewPosition;"),s.colors&&f.push("in vec4 vColor;");u&&(l&&i._normalMap||i._ambientMap||i._baseColorMap||i._diffuseMap||i._emissiveMap||i._metallicMap||i._roughnessMap||i._metallicRoughnessMap||i._specularMap||i._glossinessMap||i._specularGlossinessMap||i._occlusionMap||i._alphaMap)&&f.push("in vec2 vUV;");l&&(n.lightMaps.length>0&&f.push("in vec3 vWorldNormal;"),f.push("in vec3 vViewNormal;"));o.ambient&&f.push("uniform vec3 materialAmbient;");o.baseColor&&f.push("uniform vec3 materialBaseColor;");void 0!==o.alpha&&null!==o.alpha&&f.push("uniform vec4 materialAlphaModeCutoff;");o.emissive&&f.push("uniform vec3 materialEmissive;");o.diffuse&&f.push("uniform vec3 materialDiffuse;");void 0!==o.glossiness&&null!==o.glossiness&&f.push("uniform float materialGlossiness;");void 0!==o.shininess&&null!==o.shininess&&f.push("uniform float materialShininess;");o.specular&&f.push("uniform vec3 materialSpecular;");void 0!==o.metallic&&null!==o.metallic&&f.push("uniform float materialMetallic;");void 0!==o.roughness&&null!==o.roughness&&f.push("uniform float materialRoughness;");void 0!==o.specularF0&&null!==o.specularF0&&f.push("uniform float materialSpecularF0;");u&&i._ambientMap&&(f.push("uniform sampler2D ambientMap;"),i._ambientMap._state.matrix&&f.push("uniform mat4 ambientMapMatrix;"));u&&i._baseColorMap&&(f.push("uniform sampler2D baseColorMap;"),i._baseColorMap._state.matrix&&f.push("uniform mat4 baseColorMapMatrix;"));u&&i._diffuseMap&&(f.push("uniform sampler2D diffuseMap;"),i._diffuseMap._state.matrix&&f.push("uniform mat4 diffuseMapMatrix;"));u&&i._emissiveMap&&(f.push("uniform sampler2D emissiveMap;"),i._emissiveMap._state.matrix&&f.push("uniform mat4 emissiveMapMatrix;"));l&&u&&i._metallicMap&&(f.push("uniform sampler2D metallicMap;"),i._metallicMap._state.matrix&&f.push("uniform mat4 metallicMapMatrix;"));l&&u&&i._roughnessMap&&(f.push("uniform sampler2D roughnessMap;"),i._roughnessMap._state.matrix&&f.push("uniform mat4 roughnessMapMatrix;"));l&&u&&i._metallicRoughnessMap&&(f.push("uniform sampler2D metallicRoughnessMap;"),i._metallicRoughnessMap._state.matrix&&f.push("uniform mat4 metallicRoughnessMapMatrix;"));l&&i._normalMap&&(f.push("uniform sampler2D normalMap;"),i._normalMap._state.matrix&&f.push("uniform mat4 normalMapMatrix;"),f.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),f.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),f.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),f.push(" vec2 st0 = dFdx( uv.st );"),f.push(" vec2 st1 = dFdy( uv.st );"),f.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),f.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),f.push(" vec3 N = normalize( surf_norm );"),f.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),f.push(" mat3 tsn = mat3( S, T, N );"),f.push(" return normalize( tsn * mapN );"),f.push("}"));u&&i._occlusionMap&&(f.push("uniform sampler2D occlusionMap;"),i._occlusionMap._state.matrix&&f.push("uniform mat4 occlusionMapMatrix;"));u&&i._alphaMap&&(f.push("uniform sampler2D alphaMap;"),i._alphaMap._state.matrix&&f.push("uniform mat4 alphaMapMatrix;"));l&&u&&i._specularMap&&(f.push("uniform sampler2D specularMap;"),i._specularMap._state.matrix&&f.push("uniform mat4 specularMapMatrix;"));l&&u&&i._glossinessMap&&(f.push("uniform sampler2D glossinessMap;"),i._glossinessMap._state.matrix&&f.push("uniform mat4 glossinessMapMatrix;"));l&&u&&i._specularGlossinessMap&&(f.push("uniform sampler2D materialSpecularGlossinessMap;"),i._specularGlossinessMap._state.matrix&&f.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));l&&(i._diffuseFresnel||i._specularFresnel||i._alphaFresnel||i._emissiveFresnel||i._reflectivityFresnel)&&(f.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),f.push(" float fr = abs(dot(eyeDir, normal));"),f.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),f.push(" return pow(finalFr, power);"),f.push("}"),i._diffuseFresnel&&(f.push("uniform float diffuseFresnelCenterBias;"),f.push("uniform float diffuseFresnelEdgeBias;"),f.push("uniform float diffuseFresnelPower;"),f.push("uniform vec3 diffuseFresnelCenterColor;"),f.push("uniform vec3 diffuseFresnelEdgeColor;")),i._specularFresnel&&(f.push("uniform float specularFresnelCenterBias;"),f.push("uniform float specularFresnelEdgeBias;"),f.push("uniform float specularFresnelPower;"),f.push("uniform vec3 specularFresnelCenterColor;"),f.push("uniform vec3 specularFresnelEdgeColor;")),i._alphaFresnel&&(f.push("uniform float alphaFresnelCenterBias;"),f.push("uniform float alphaFresnelEdgeBias;"),f.push("uniform float alphaFresnelPower;"),f.push("uniform vec3 alphaFresnelCenterColor;"),f.push("uniform vec3 alphaFresnelEdgeColor;")),i._reflectivityFresnel&&(f.push("uniform float materialSpecularF0FresnelCenterBias;"),f.push("uniform float materialSpecularF0FresnelEdgeBias;"),f.push("uniform float materialSpecularF0FresnelPower;"),f.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),f.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),i._emissiveFresnel&&(f.push("uniform float emissiveFresnelCenterBias;"),f.push("uniform float emissiveFresnelEdgeBias;"),f.push("uniform float emissiveFresnelPower;"),f.push("uniform vec3 emissiveFresnelCenterColor;"),f.push("uniform vec3 emissiveFresnelEdgeColor;")));if(f.push("uniform vec4 lightAmbient;"),l)for(var g=0,m=n.lights.length;g 0.0) { discard; }"),f.push("}")}"points"===s.primitiveName&&(f.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),f.push("float r = dot(cxy, cxy);"),f.push("if (r > 1.0) {"),f.push(" discard;"),f.push("}"));f.push("float occlusion = 1.0;"),o.ambient?f.push("vec3 ambientColor = materialAmbient;"):f.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");o.diffuse?f.push("vec3 diffuseColor = materialDiffuse;"):o.baseColor?f.push("vec3 diffuseColor = materialBaseColor;"):f.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");s.colors&&f.push("diffuseColor *= vColor.rgb;");o.emissive?f.push("vec3 emissiveColor = materialEmissive;"):f.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");o.specular?f.push("vec3 specular = materialSpecular;"):f.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==o.alpha?f.push("float alpha = materialAlphaModeCutoff[0];"):f.push("float alpha = 1.0;");s.colors&&f.push("alpha *= vColor.a;");void 0!==o.glossiness?f.push("float glossiness = materialGlossiness;"):f.push("float glossiness = 1.0;");void 0!==o.metallic?f.push("float metallic = materialMetallic;"):f.push("float metallic = 1.0;");void 0!==o.roughness?f.push("float roughness = materialRoughness;"):f.push("float roughness = 1.0;");void 0!==o.specularF0?f.push("float specularF0 = materialSpecularF0;"):f.push("float specularF0 = 1.0;");u&&(l&&i._normalMap||i._ambientMap||i._baseColorMap||i._diffuseMap||i._occlusionMap||i._emissiveMap||i._metallicMap||i._roughnessMap||i._metallicRoughnessMap||i._specularMap||i._glossinessMap||i._specularGlossinessMap||i._alphaMap)&&(f.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),f.push("vec2 textureCoord;"));u&&i._ambientMap&&(i._ambientMap._state.matrix?f.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),f.push("ambientTexel = "+pr[i._ambientMap._state.encoding]+"(ambientTexel);"),f.push("ambientColor *= ambientTexel.rgb;"));u&&i._diffuseMap&&(i._diffuseMap._state.matrix?f.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),f.push("diffuseTexel = "+pr[i._diffuseMap._state.encoding]+"(diffuseTexel);"),f.push("diffuseColor *= diffuseTexel.rgb;"),f.push("alpha *= diffuseTexel.a;"));u&&i._baseColorMap&&(i._baseColorMap._state.matrix?f.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),f.push("baseColorTexel = "+pr[i._baseColorMap._state.encoding]+"(baseColorTexel);"),f.push("diffuseColor *= baseColorTexel.rgb;"),f.push("alpha *= baseColorTexel.a;"));u&&i._emissiveMap&&(i._emissiveMap._state.matrix?f.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),f.push("emissiveTexel = "+pr[i._emissiveMap._state.encoding]+"(emissiveTexel);"),f.push("emissiveColor = emissiveTexel.rgb;"));u&&i._alphaMap&&(i._alphaMap._state.matrix?f.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("alpha *= texture(alphaMap, textureCoord).r;"));u&&i._occlusionMap&&(i._occlusionMap._state.matrix?f.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(l&&(n.lights.length>0||n.lightMaps.length>0||n.reflectionMaps.length>0)){u&&i._normalMap?(i._normalMap._state.matrix?f.push("textureCoord = (normalMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):f.push("vec3 viewNormal = normalize(vViewNormal);"),u&&i._specularMap&&(i._specularMap._state.matrix?f.push("textureCoord = (specularMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("specular *= texture(specularMap, textureCoord).rgb;")),u&&i._glossinessMap&&(i._glossinessMap._state.matrix?f.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("glossiness *= texture(glossinessMap, textureCoord).r;")),u&&i._specularGlossinessMap&&(i._specularGlossinessMap._state.matrix?f.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),f.push("specular *= specGlossRGB.rgb;"),f.push("glossiness *= specGlossRGB.a;")),u&&i._metallicMap&&(i._metallicMap._state.matrix?f.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("metallic *= texture(metallicMap, textureCoord).r;")),u&&i._roughnessMap&&(i._roughnessMap._state.matrix?f.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("roughness *= texture(roughnessMap, textureCoord).r;")),u&&i._metallicRoughnessMap&&(i._metallicRoughnessMap._state.matrix?f.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),f.push("metallic *= metalRoughRGB.b;"),f.push("roughness *= metalRoughRGB.g;")),f.push("vec3 viewEyeDir = normalize(-vViewPosition);"),i._diffuseFresnel&&(f.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),f.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),i._specularFresnel&&(f.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),f.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),i._alphaFresnel&&(f.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),f.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),i._emissiveFresnel&&(f.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),f.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),f.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),f.push(" discard;"),f.push("}"),f.push("IncidentLight light;"),f.push("Material material;"),f.push("Geometry geometry;"),f.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),f.push("vec3 viewLightDir;"),A&&(f.push("material.diffuseColor = diffuseColor;"),f.push("material.specularColor = specular;"),f.push("material.shine = materialShininess;")),h&&(f.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),f.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),f.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),f.push("material.specularColor = specular;")),c&&(f.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),f.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),f.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),f.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),f.push("geometry.position = vViewPosition;"),n.lightMaps.length>0&&f.push("geometry.worldNormal = normalize(vWorldNormal);"),f.push("geometry.viewNormal = viewNormal;"),f.push("geometry.viewEyeDir = viewEyeDir;"),A&&(n.lightMaps.length>0||n.reflectionMaps.length>0)&&f.push("computePhongLightMapping(geometry, material, reflectedLight);"),(h||c)&&(n.lightMaps.length>0||n.reflectionMaps.length>0)&&f.push("computePBRLightMapping(geometry, material, reflectedLight);"),f.push("float shadow = 1.0;"),f.push("float shadowAcneRemover = 0.007;"),f.push("vec3 fragmentDepth;"),f.push("float texelSize = 1.0 / 1024.0;"),f.push("float amountInLight = 0.0;"),f.push("vec3 shadowCoord;"),f.push("vec4 rgbaDepth;"),f.push("float depth;");for(var B=0,w=n.lights.length;B0)for(var f=s._sectionPlanesState.sectionPlanes,v=t.renderFlags,g=0;g0&&(this._uLightMap="lightMap"),r.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(A=0,c=n.sectionPlanes.length;A0&&n.lightMaps[0].texture&&this._uLightMap&&(a.bindTexture(this._uLightMap,n.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%i,e.bindTexture++),n.reflectionMaps.length>0&&n.reflectionMaps[0].texture&&this._uReflectionMap&&(a.bindTexture(this._uReflectionMap,n.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%i,e.bindTexture++),this._uGammaFactor&&r.uniform1f(this._uGammaFactor,s.gammaFactor),this._baseTextureUnit=e.textureUnit};var br=C((function e(t){x(this,e),this.vertex=function(e){var t=e.scene,i=t._lightsState,s=function(e){var t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),r=t._sectionPlanesState.getNumAllocatedSectionPlanes()>0,n=!!e._geometry._state.compressGeometry,o=e._state.billboard,a=e._state.stationary,l=[];l.push("#version 300 es"),l.push("// EmphasisFillShaderSource vertex shader"),l.push("in vec3 position;"),l.push("uniform mat4 modelMatrix;"),l.push("uniform mat4 viewMatrix;"),l.push("uniform mat4 projMatrix;"),l.push("uniform vec4 colorize;"),l.push("uniform vec3 offset;"),n&&l.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;"));r&&l.push("out vec4 vWorldPosition;");if(l.push("uniform vec4 lightAmbient;"),l.push("uniform vec4 fillColor;"),s){l.push("in vec3 normal;"),l.push("uniform mat4 modelNormalMatrix;"),l.push("uniform mat4 viewNormalMatrix;");for(var u=0,A=i.lights.length;u= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"))}l.push("out vec4 vColor;"),("spherical"===o||"cylindrical"===o)&&(l.push("void billboard(inout mat4 mat) {"),l.push(" mat[0][0] = 1.0;"),l.push(" mat[0][1] = 0.0;"),l.push(" mat[0][2] = 0.0;"),"spherical"===o&&(l.push(" mat[1][0] = 0.0;"),l.push(" mat[1][1] = 1.0;"),l.push(" mat[1][2] = 0.0;")),l.push(" mat[2][0] = 0.0;"),l.push(" mat[2][1] = 0.0;"),l.push(" mat[2][2] =1.0;"),l.push("}"));l.push("void main(void) {"),l.push("vec4 localPosition = vec4(position, 1.0); "),l.push("vec4 worldPosition;"),n&&l.push("localPosition = positionsDecodeMatrix * localPosition;");s&&(n?l.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):l.push("vec4 localNormal = vec4(normal, 0.0); "),l.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),l.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));l.push("mat4 viewMatrix2 = viewMatrix;"),l.push("mat4 modelMatrix2 = modelMatrix;"),a&&l.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===o||"cylindrical"===o?(l.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),l.push("billboard(modelMatrix2);"),l.push("billboard(viewMatrix2);"),l.push("billboard(modelViewMatrix);"),s&&(l.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),l.push("billboard(modelNormalMatrix2);"),l.push("billboard(viewNormalMatrix2);"),l.push("billboard(modelViewNormalMatrix);")),l.push("worldPosition = modelMatrix2 * localPosition;"),l.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(l.push("worldPosition = modelMatrix2 * localPosition;"),l.push("worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s&&l.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),s)for(var h=0,d=i.lights.length;h0,n=[];n.push("#version 300 es"),n.push("// Lambertian drawing 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"),t.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"));s&&(n.push("uniform float gammaFactor;"),n.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),n.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),n.push("}"));if(r){n.push("in vec4 vWorldPosition;"),n.push("uniform bool clippable;");for(var o=0,a=i.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),n.push("}")}"points"===e._geometry._state.primitiveName&&(n.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),n.push("float r = dot(cxy, cxy);"),n.push("if (r > 1.0) {"),n.push(" discard;"),n.push("}"));t.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");s?n.push("outColor = linearToGamma(vColor, gammaFactor);"):n.push("outColor = vColor;");return n.push("}"),n}(t)}));var Br=new Q({}),wr=$.vec3(),xr=function(e,t){this.id=Br.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new br(t),this._allocate(t)},Pr={};xr.get=function(e){var t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),i=Pr[t];return i||(i=new xr(t,e),Pr[t]=i,se.memory.programs++),i._useCount++,i},xr.prototype.put=function(){0==--this._useCount&&(Br.removeItem(this.id),this._program&&this._program.destroy(),delete Pr[this._hash],se.memory.programs--)},xr.prototype.webglContextRestored=function(){this._program=null},xr.prototype.drawMesh=function(e,t,i){this._program||this._allocate(t);var s=this._scene,r=s.camera,n=s.canvas.gl,o=0===i?t._xrayMaterial._state:1===i?t._highlightMaterial._state:t._selectedMaterial._state,a=t._state,l=t._geometry._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(a.originHash,u):r.viewMatrix),n.uniformMatrix4fv(this._uViewNormalMatrix,!1,r.viewNormalMatrix),a.clippable){var A=s._sectionPlanesState.getNumAllocatedSectionPlanes(),c=s._sectionPlanesState.sectionPlanes.length;if(A>0)for(var h=s._sectionPlanesState.sectionPlanes,d=t.renderFlags,p=0;p0,s=!!e._geometry._state.compressGeometry,r=e._state.billboard,n=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// Edges drawing vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("uniform vec4 edgeColor;"),o.push("uniform vec3 offset;"),s&&o.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));i&&o.push("out vec4 vWorldPosition;");o.push("out vec4 vColor;"),("spherical"===r||"cylindrical"===r)&&(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),o.push("vec4 worldPosition;"),s&&o.push("localPosition = positionsDecodeMatrix * localPosition;");o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),n&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===r||"cylindrical"===r?(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"),o.push("billboard(modelViewMatrix);"),o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));o.push("vColor = edgeColor;"),i&&o.push("vWorldPosition = worldPosition;");o.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(o.push("vFragDepth = 1.0 + clipPos.w;"),o.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return o.push("gl_Position = clipPos;"),o.push("}"),o}(t),this.fragment=function(e){var t=e.scene,i=e.scene._sectionPlanesState,s=e.scene.gammaOutput,r=i.getNumAllocatedSectionPlanes()>0,n=[];n.push("#version 300 es"),n.push("// Edges drawing 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"),t.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"));s&&(n.push("uniform float gammaFactor;"),n.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),n.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),n.push("}"));if(r){n.push("in vec4 vWorldPosition;"),n.push("uniform bool clippable;");for(var o=0,a=i.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),n.push("}")}t.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");s?n.push("outColor = linearToGamma(vColor, gammaFactor);"):n.push("outColor = vColor;");return n.push("}"),n}(t)}));var Mr=new Q({}),Fr=$.vec3(),Er=function(e,t){this.id=Mr.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Cr(t),this._allocate(t)},kr={};Er.get=function(e){var t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),i=kr[t];return i||(i=new Er(t,e),kr[t]=i,se.memory.programs++),i._useCount++,i},Er.prototype.put=function(){0==--this._useCount&&(Mr.removeItem(this.id),this._program&&this._program.destroy(),delete kr[this._hash],se.memory.programs--)},Er.prototype.webglContextRestored=function(){this._program=null},Er.prototype.drawMesh=function(e,t,i){this._program||this._allocate(t);var s,r,n=this._scene,o=n.camera,a=n.canvas.gl,l=t._state,u=t._geometry,A=u._state,c=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,c?e.getRTCViewMatrix(l.originHash,c):o.viewMatrix),l.clippable){var h=n._sectionPlanesState.getNumAllocatedSectionPlanes(),d=n._sectionPlanesState.sectionPlanes.length;if(h>0)for(var p=n._sectionPlanesState.sectionPlanes,f=t.renderFlags,v=0;v0,s=!!e._geometry._state.compressGeometry,r=e._state.billboard,n=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// Mesh picking vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("out vec4 vViewPosition;"),o.push("uniform vec3 offset;"),s&&o.push("uniform mat4 positionsDecodeMatrix;");i&&o.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));"spherical"!==r&&"cylindrical"!==r||(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("uniform vec2 pickClipPos;"),o.push("vec4 remapClipPos(vec4 clipPos) {"),o.push(" clipPos.xy /= clipPos.w;"),o.push(" clipPos.xy -= pickClipPos;"),o.push(" clipPos.xy *= clipPos.w;"),o.push(" return clipPos;"),o.push("}"),o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),s&&o.push("localPosition = positionsDecodeMatrix * localPosition;");o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),n&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==r&&"cylindrical"!==r||(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"));o.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),o.push(" worldPosition.xyz = worldPosition.xyz + offset;"),o.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),i&&o.push(" vWorldPosition = worldPosition;");o.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(o.push("vFragDepth = 1.0 + clipPos.w;"),o.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return o.push("gl_Position = remapClipPos(clipPos);"),o.push("}"),o}(t),this.fragment=function(e){var t=e.scene,i=t._sectionPlanesState,s=i.getNumAllocatedSectionPlanes()>0,r=[];r.push("#version 300 es"),r.push("// Mesh picking 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"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(r.push("uniform vec4 pickColor;"),s){r.push("uniform bool clippable;"),r.push("in vec4 vWorldPosition;");for(var n=0;n 0.0) { discard; }"),r.push("}")}t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return r.push(" outColor = pickColor; "),r.push("}"),r}(t)}));var Dr=$.vec3(),Sr=function(e,t){this._hash=e,this._shaderSource=new Ir(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Tr={};Sr.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";"),i=Tr[t];if(!i){if((i=new Sr(t,e)).errors)return console.log(i.errors.join("\n")),null;Tr[t]=i,se.memory.programs++}return i._useCount++,i},Sr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Tr[this._hash],se.memory.programs--)},Sr.prototype.webglContextRestored=function(){this._program=null},Sr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var i=this._scene,s=i.canvas.gl,r=t._state,n=t._material._state,o=t._geometry._state,a=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),s.uniformMatrix4fv(this._uViewMatrix,!1,a?e.getRTCPickViewMatrix(r.originHash,a):e.pickViewMatrix),r.clippable){var l=i._sectionPlanesState.getNumAllocatedSectionPlanes(),u=i._sectionPlanesState.sectionPlanes.length;if(l>0)for(var A=i._sectionPlanesState.sectionPlanes,c=t.renderFlags,h=0;h>24&255,b=_>>16&255,B=_>>8&255,w=255&_;s.uniform4f(this._uPickColor,w/255,B/255,b/255,y/255),s.uniform2fv(this._uPickClipPos,e.pickClipPos),o.indicesBuf?(s.drawElements(o.primitive,o.indicesBuf.numItems,o.indicesBuf.itemType,0),e.drawElements++):o.positions&&s.drawArrays(s.TRIANGLES,0,o.positions.numItems)},Sr.prototype._allocate=function(e){var t=e.scene,i=t.canvas.gl;if(this._program=new kt(i,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var s=this._program;this._uPositionsDecodeMatrix=s.getLocation("positionsDecodeMatrix"),this._uModelMatrix=s.getLocation("modelMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,n=t._sectionPlanesState.sectionPlanes.length;r0,s=!!e._geometry._state.compressGeometry,r=[];r.push("#version 300 es"),r.push("// Surface picking vertex shader"),r.push("in vec3 position;"),r.push("in vec4 color;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec3 offset;"),i&&(r.push("uniform bool clippable;"),r.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));r.push("uniform vec2 pickClipPos;"),r.push("vec4 remapClipPos(vec4 clipPos) {"),r.push(" clipPos.xy /= clipPos.w;"),r.push(" clipPos.xy -= pickClipPos;"),r.push(" clipPos.xy *= clipPos.w;"),r.push(" return clipPos;"),r.push("}"),r.push("out vec4 vColor;"),s&&r.push("uniform mat4 positionsDecodeMatrix;");r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),s&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push(" vec4 worldPosition = modelMatrix * localPosition; "),r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition;"),i&&r.push(" vWorldPosition = worldPosition;");r.push(" vColor = color;"),r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = remapClipPos(clipPos);"),r.push("}"),r}(t),this.fragment=function(e){var t=e.scene,i=t._sectionPlanesState,s=i.getNumAllocatedSectionPlanes()>0,r=[];r.push("#version 300 es"),r.push("// Surface picking 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"),r.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(s){r.push("uniform bool clippable;"),r.push("in vec4 vWorldPosition;");for(var n=0;n 0.0) { discard; }"),r.push("}")}t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return r.push(" outColor = vColor;"),r.push("}"),r}(t)}));var Lr=$.vec3(),Ur=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Rr(t),this._allocate(t)},Or={};Ur.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),i=Or[t];if(!i){if((i=new Ur(t,e)).errors)return console.log(i.errors.join("\n")),null;Or[t]=i,se.memory.programs++}return i._useCount++,i},Ur.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Or[this._hash],se.memory.programs--)},Ur.prototype.webglContextRestored=function(){this._program=null},Ur.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var i=this._scene,s=i.canvas.gl,r=t._state,n=t._material._state,o=t._geometry,a=t._geometry._state,l=t.origin,u=n.backfaces,A=n.frontface,c=i.camera.project,h=o._getPickTrianglePositions(),d=o._getPickTriangleColors();if(this._program.bind(),e.useProgram++,i.logarithmicDepthBufferEnabled){var p=2/(Math.log(c.far+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,p)}if(s.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(r.originHash,l):e.pickViewMatrix),r.clippable){var f=i._sectionPlanesState.getNumAllocatedSectionPlanes(),v=i._sectionPlanesState.sectionPlanes.length;if(f>0)for(var g=i._sectionPlanesState.sectionPlanes,m=t.renderFlags,_=0;_0,s=!!e._geometry._state.compressGeometry,r=e._state.billboard,n=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// Mesh occlusion vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("uniform vec3 offset;"),s&&o.push("uniform mat4 positionsDecodeMatrix;");i&&o.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));"spherical"!==r&&"cylindrical"!==r||(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),o.push("vec4 worldPosition;"),s&&o.push("localPosition = positionsDecodeMatrix * localPosition;");o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),n&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===r||"cylindrical"===r?(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"),o.push("billboard(modelViewMatrix);"),o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i&&o.push(" vWorldPosition = worldPosition;");o.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(o.push("vFragDepth = 1.0 + clipPos.w;"),o.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return o.push("gl_Position = clipPos;"),o.push("}"),o}(t),this.fragment=function(e){var t=e.scene,i=t._sectionPlanesState,s=i.getNumAllocatedSectionPlanes()>0,r=[];r.push("#version 300 es"),r.push("// Mesh occlusion 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"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(s){r.push("uniform bool clippable;"),r.push("in vec4 vWorldPosition;");for(var n=0;n 0.0) { discard; }"),r.push("}")}r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return r.push("}"),r}(t)}));var Qr=$.vec3(),Vr=function(e,t){this._hash=e,this._shaderSource=new Nr(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Hr={};Vr.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";"),i=Hr[t];if(!i){if((i=new Vr(t,e)).errors)return console.log(i.errors.join("\n")),null;Hr[t]=i,se.memory.programs++}return i._useCount++,i},Vr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Hr[this._hash],se.memory.programs--)},Vr.prototype.webglContextRestored=function(){this._program=null},Vr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var i=this._scene,s=i.canvas.gl,r=t._material._state,n=t._state,o=t._geometry._state,a=t.origin;if(!(r.alpha<1)){if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),r.id!==this._lastMaterialId){var l=r.backfaces;e.backfaces!==l&&(l?s.disable(s.CULL_FACE):s.enable(s.CULL_FACE),e.backfaces=l);var u=r.frontface;e.frontface!==u&&(u?s.frontFace(s.CCW):s.frontFace(s.CW),e.frontface=u),this._lastMaterialId=r.id}var A=i.camera;if(s.uniformMatrix4fv(this._uViewMatrix,!1,a?e.getRTCViewMatrix(n.originHash,a):A.viewMatrix),n.clippable){var c=i._sectionPlanesState.getNumAllocatedSectionPlanes(),h=i._sectionPlanesState.sectionPlanes.length;if(c>0)for(var d=i._sectionPlanesState.sectionPlanes,p=t.renderFlags,f=0;f0,i=!!e._geometry._state.compressGeometry,s=[];s.push("// Mesh shadow vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),s.push("uniform vec3 offset;"),i&&s.push("uniform mat4 positionsDecodeMatrix;");t&&s.push("out vec4 vWorldPosition;");s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),s.push("vec4 worldPosition;"),i&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("worldPosition = modelMatrix * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&s.push("vWorldPosition = worldPosition;");return s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene;t.canvas.gl;var i=t._sectionPlanesState,s=i.getNumAllocatedSectionPlanes()>0,r=[];if(r.push("// Mesh shadow 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"),s){r.push("uniform bool clippable;"),r.push("in vec4 vWorldPosition;");for(var n=0;n 0.0) { discard; }"),r.push("}")}return r.push("outColor = encodeFloat(gl_FragCoord.z);"),r.push("}"),r}(t)}));var Gr=function(e,t){this._hash=e,this._shaderSource=new jr(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},zr={};Gr.get=function(e){var t=e.scene,i=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";"),s=zr[i];if(!s){if((s=new Gr(i,e)).errors)return console.log(s.errors.join("\n")),null;zr[i]=s,se.memory.programs++}return s._useCount++,s},Gr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete zr[this._hash],se.memory.programs--)},Gr.prototype.webglContextRestored=function(){this._program=null},Gr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var i=this._scene.canvas.gl,s=t._material._state,r=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),s.id!==this._lastMaterialId){var n=s.backfaces;e.backfaces!==n&&(n?i.disable(i.CULL_FACE):i.enable(i.CULL_FACE),e.backfaces=n);var o=s.frontface;e.frontface!==o&&(o?i.frontFace(i.CCW):i.frontFace(i.CW),e.frontface=o),e.lineWidth!==s.lineWidth&&(i.lineWidth(s.lineWidth),e.lineWidth=s.lineWidth),this._uPointSize&&i.uniform1i(this._uPointSize,s.pointSize),this._lastMaterialId=s.id}if(i.uniformMatrix4fv(this._uModelMatrix,i.FALSE,t.worldMatrix),r.combineGeometry){var a=t.vertexBufs;a.id!==this._lastVertexBufsId&&(a.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(a.positionsBuf,a.compressGeometry?i.UNSIGNED_SHORT:i.FLOAT),e.bindArray++),this._lastVertexBufsId=a.id)}this._uClippable&&i.uniform1i(this._uClippable,t._state.clippable),i.uniform3fv(this._uOffset,t._state.offset),r.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&i.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,r.positionsDecodeMatrix),r.combineGeometry?r.indicesBufCombined&&(r.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(r.positionsBuf,r.compressGeometry?i.UNSIGNED_SHORT:i.FLOAT),e.bindArray++),r.indicesBuf&&(r.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=r.id),r.combineGeometry?r.indicesBufCombined&&(i.drawElements(r.primitive,r.indicesBufCombined.numItems,r.indicesBufCombined.itemType,0),e.drawElements++):r.indicesBuf?(i.drawElements(r.primitive,r.indicesBuf.numItems,r.indicesBuf.itemType,0),e.drawElements++):r.positions&&(i.drawArrays(i.TRIANGLES,0,r.positions.numItems),e.drawArrays++)},Gr.prototype._allocate=function(e){var t=e.scene,i=t.canvas.gl;if(this._program=new kt(i,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)this.errors=this._program.errors;else{var s=this._program;this._uPositionsDecodeMatrix=s.getLocation("positionsDecodeMatrix"),this._uModelMatrix=s.getLocation("modelMatrix"),this._uShadowViewMatrix=s.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=s.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(var r=0,n=t._sectionPlanesState.sectionPlanes.length;r0)for(var r,n,o,a=0,l=this._uSectionPlanes.length;a1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e,r)).originalSystemId=r.originalSystemId||s.id,s.renderFlags=new Wr,s._state=new Zt({visible:!0,culled:!1,pickable:null,clippable:null,collidable:null,occluder:!1!==r.occluder,castsShadow:null,receivesShadow:null,xrayed:!1,highlighted:!1,selected:!1,edges:!1,stationary:!!r.stationary,background:!!r.background,billboard:s._checkBillboard(r.billboard),layer:null,colorize:null,pickID:s.scene._renderer.getPickID(b(s)),drawHash:"",pickHash:"",offset:$.vec3(),origin:null,originHash:null}),s._drawRenderer=null,s._shadowRenderer=null,s._emphasisFillRenderer=null,s._emphasisEdgesRenderer=null,s._pickMeshRenderer=null,s._pickTriangleRenderer=null,s._occlusionRenderer=null,s._geometry=r.geometry?s._checkComponent2(["ReadableGeometry","VBOGeometry"],r.geometry):s.scene.geometry,s._material=r.material?s._checkComponent2(["PhongMaterial","MetallicMaterial","SpecularMaterial","LambertMaterial"],r.material):s.scene.material,s._xrayMaterial=r.xrayMaterial?s._checkComponent("EmphasisMaterial",r.xrayMaterial):s.scene.xrayMaterial,s._highlightMaterial=r.highlightMaterial?s._checkComponent("EmphasisMaterial",r.highlightMaterial):s.scene.highlightMaterial,s._selectedMaterial=r.selectedMaterial?s._checkComponent("EmphasisMaterial",r.selectedMaterial):s.scene.selectedMaterial,s._edgeMaterial=r.edgeMaterial?s._checkComponent("EdgeMaterial",r.edgeMaterial):s.scene.edgeMaterial,s._parentNode=null,s._aabb=null,s._aabbDirty=!0,s._numTriangles=s._geometry?s._geometry.numTriangles:0,s.scene._aabbDirty=!0,s._scale=$.vec3(),s._quaternion=$.identityQuaternion(),s._rotation=$.vec3(),s._position=$.vec3(),s._worldMatrix=$.identityMat4(),s._worldNormalMatrix=$.identityMat4(),s._localMatrixDirty=!0,s._worldMatrixDirty=!0,s._worldNormalMatrixDirty=!0;var n=r.origin||r.rtcCenter;if(n&&(s._state.origin=$.vec3(n),s._state.originHash=n.join()),r.matrix?s.matrix=r.matrix:(s.scale=r.scale,s.position=r.position,r.quaternion||(s.rotation=r.rotation)),s._isObject=r.isObject,s._isObject&&s.scene._registerObject(b(s)),s._isModel=r.isModel,s._isModel&&s.scene._registerModel(b(s)),s.visible=r.visible,s.culled=r.culled,s.pickable=r.pickable,s.clippable=r.clippable,s.collidable=r.collidable,s.castsShadow=r.castsShadow,s.receivesShadow=r.receivesShadow,s.xrayed=r.xrayed,s.highlighted=r.highlighted,s.selected=r.selected,s.edges=r.edges,s.layer=r.layer,s.colorize=r.colorize,s.opacity=r.opacity,s.offset=r.offset,r.parentId){var o=s.scene.components[r.parentId];o?o.isNode?o.addChild(b(s)):s.error("Parent is not a Node: '"+r.parentId+"'"):s.error("Parent not found: '"+r.parentId+"'"),s._parentNode=o}else r.parent&&(r.parent.isNode||s.error("Parent is not a Node"),r.parent.addChild(b(s)),s._parentNode=r.parent);return s.compile(),s}return C(i,[{key:"type",get:function(){return"Mesh"}},{key:"isMesh",get:function(){return!0}},{key:"parent",get:function(){return this._parentNode}},{key:"geometry",get:function(){return this._geometry}},{key:"material",get:function(){return this._material}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),$.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),$.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"matrix",get:function(){return this._localMatrixDirty&&(this.__localMatrix||(this.__localMatrix=$.identityMat4()),$.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix},set:function(e){this.__localMatrix||(this.__localMatrix=$.identityMat4()),this.__localMatrix.set(e||sn),$.decomposeMat4(this.__localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrixDirty&&this._buildWorldNormalMatrix(),this._worldNormalMatrix}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return this._isObject}},{key:"aabb",get:function(){return this._aabbDirty&&this._updateAABB(),this._aabb}},{key:"origin",get:function(){return this._state.origin},set:function(e){e?(this._state.origin||(this._state.origin=$.vec3()),this._state.origin.set(e),this._state.originHash=e.join(),this._setAABBDirty(),this.scene._aabbDirty=!0):this._state.origin&&(this._state.origin=null,this._state.originHash=null,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"rtcCenter",get:function(){return this.origin},set:function(e){this.origin=e}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"visible",get:function(){return this._state.visible},set:function(e){e=!1!==e,this._state.visible=e,this._isObject&&this.scene._objectVisibilityUpdated(this,e),this.glRedraw()}},{key:"xrayed",get:function(){return this._state.xrayed},set:function(e){e=!!e,this._state.xrayed!==e&&(this._state.xrayed=e,this._isObject&&this.scene._objectXRayedUpdated(this,e),this.glRedraw())}},{key:"highlighted",get:function(){return this._state.highlighted},set:function(e){(e=!!e)!==this._state.highlighted&&(this._state.highlighted=e,this._isObject&&this.scene._objectHighlightedUpdated(this,e),this.glRedraw())}},{key:"selected",get:function(){return this._state.selected},set:function(e){(e=!!e)!==this._state.selected&&(this._state.selected=e,this._isObject&&this.scene._objectSelectedUpdated(this,e),this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){(e=!!e)!==this._state.edges&&(this._state.edges=e,this.glRedraw())}},{key:"culled",get:function(){return this._state.culled},set:function(e){this._state.culled=!!e,this.glRedraw()}},{key:"clippable",get:function(){return this._state.clippable},set:function(e){e=!1!==e,this._state.clippable!==e&&(this._state.clippable=e,this.glRedraw())}},{key:"collidable",get:function(){return this._state.collidable},set:function(e){(e=!1!==e)!==this._state.collidable&&(this._state.collidable=e,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"pickable",get:function(){return this._state.pickable},set:function(e){e=!1!==e,this._state.pickable!==e&&(this._state.pickable=e)}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){(e=!1!==e)!==this._state.castsShadow&&(this._state.castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._state.receivesShadow},set:function(e){(e=!1!==e)!==this._state.receivesShadow&&(this._state.receivesShadow=e,this._state.hash=e?"/mod/rs;":"/mod;",this.fire("dirty",this))}},{key:"saoEnabled",get:function(){return!1}},{key:"colorize",get:function(){return this._state.colorize},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);var i=!!e;this.scene._objectColorizeUpdated(this,i),this.glRedraw()}},{key:"opacity",get:function(){return this._state.colorize[3]},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[0]=1,t[1]=1,t[2]=1);var i=null!=e;t[3]=i?e:1,this.scene._objectOpacityUpdated(this,i),this.glRedraw()}},{key:"transparent",get:function(){return 2===this._material.alphaMode||this._state.colorize[3]<1}},{key:"layer",get:function(){return this._state.layer},set:function(e){e=e||0,(e=Math.round(e))!==this._state.layer&&(this._state.layer=e,this._renderer.needStateSort())}},{key:"stationary",get:function(){return this._state.stationary}},{key:"billboard",get:function(){return this._state.billboard}},{key:"offset",get:function(){return this._state.offset},set:function(e){this._state.offset.set(e||[0,0,0]),this._setAABBDirty(),this.glRedraw()}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!0}},{key:"xrayMaterial",get:function(){return this._xrayMaterial}},{key:"highlightMaterial",get:function(){return this._highlightMaterial}},{key:"selectedMaterial",get:function(){return this._selectedMaterial}},{key:"edgeMaterial",get:function(){return this._edgeMaterial}},{key:"_checkBillboard",value:function(e){return"spherical"!==(e=e||"none")&&"cylindrical"!==e&&"none"!==e&&(this.error("Unsupported value for 'billboard': "+e+" - accepted values are 'spherical', 'cylindrical' and 'none' - defaulting to 'none'."),e="none"),e}},{key:"compile",value:function(){var e=this._makeDrawHash();this._state.drawHash!==e&&(this._state.drawHash=e,this._putDrawRenderers(),this._drawRenderer=_r.get(this),this._emphasisFillRenderer=xr.get(this),this._emphasisEdgesRenderer=Er.get(this));var t=this._makePickHash();if(this._state.pickHash!==t&&(this._state.pickHash=t,this._putPickRenderers(),this._pickMeshRenderer=Sr.get(this)),this._state.occluder){var i=this._makeOcclusionHash();this._state.occlusionHash!==i&&(this._state.occlusionHash=i,this._putOcclusionRenderer(),this._occlusionRenderer=Vr.get(this))}}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}},{key:"_setWorldMatrixDirty",value:function(){this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentNode)$.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(var t=0,i=e.length;t0)for(var i=0;i-1){var R=k.geometry._state,L=k.scene,U=L.camera,O=L.canvas;if("triangles"===R.primitiveName){S.primitive="triangle";var N,Q,V,H=T,j=R.indices,G=R.positions;if(j){var z=j[H+0],W=j[H+1],K=j[H+2];n[0]=z,n[1]=W,n[2]=K,S.indices=n,N=3*z,Q=3*W,V=3*K}else V=(Q=(N=3*H)+3)+3;if(i[0]=G[N+0],i[1]=G[N+1],i[2]=G[N+2],s[0]=G[Q+0],s[1]=G[Q+1],s[2]=G[Q+2],r[0]=G[V+0],r[1]=G[V+1],r[2]=G[V+2],R.compressGeometry){var X=R.positionsDecodeMatrix;X&&(ki.decompressPosition(i,X,i),ki.decompressPosition(s,X,s),ki.decompressPosition(r,X,r))}S.canvasPos?$.canvasPosToLocalRay(O.canvas,k.origin?Re(I,k.origin):I,D,k.worldMatrix,S.canvasPos,e,t):S.origin&&S.direction&&$.worldRayToLocalRay(k.worldMatrix,S.origin,S.direction,e,t),$.normalizeVec3(t),$.rayPlaneIntersect(e,t,i,s,r,o),S.localPos=o,S.position=o,v[0]=o[0],v[1]=o[1],v[2]=o[2],v[3]=1,$.transformVec4(k.worldMatrix,v,g),a[0]=g[0],a[1]=g[1],a[2]=g[2],S.canvasPos&&k.origin&&(a[0]+=k.origin[0],a[1]+=k.origin[1],a[2]+=k.origin[2]),S.worldPos=a,$.transformVec4(U.matrix,g,m),l[0]=m[0],l[1]=m[1],l[2]=m[2],S.viewPos=l,$.cartesianToBarycentric(o,i,s,r,u),S.bary=u;var J=R.normals;if(J){if(R.compressGeometry){var Y=3*z,Z=3*W,q=3*K;ki.decompressNormal(J.subarray(Y,Y+2),A),ki.decompressNormal(J.subarray(Z,Z+2),c),ki.decompressNormal(J.subarray(q,q+2),h)}else A[0]=J[N],A[1]=J[N+1],A[2]=J[N+2],c[0]=J[Q],c[1]=J[Q+1],c[2]=J[Q+2],h[0]=J[V],h[1]=J[V+1],h[2]=J[V+2];var ee=$.addVec3($.addVec3($.mulVec3Scalar(A,u[0],_),$.mulVec3Scalar(c,u[1],y),b),$.mulVec3Scalar(h,u[2],B),w);S.worldNormal=$.normalizeVec3($.transformVec3(k.worldNormalMatrix,ee,x))}var te=R.uv;if(te){if(d[0]=te[2*z],d[1]=te[2*z+1],p[0]=te[2*W],p[1]=te[2*W+1],f[0]=te[2*K],f[1]=te[2*K+1],R.compressGeometry){var ie=R.uvDecodeMatrix;ie&&(ki.decompressUV(d,ie,d),ki.decompressUV(p,ie,p),ki.decompressUV(f,ie,f))}S.uv=$.addVec3($.addVec3($.mulVec2Scalar(d,u[0],P),$.mulVec2Scalar(p,u[1],C),M),$.mulVec2Scalar(f,u[2],F),E)}}}}}();function on(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);var i=e.radiusBottom||1;i<0&&(console.error("negative radiusBottom not allowed - will invert"),i*=-1);var s=e.height||1;s<0&&(console.error("negative height not allowed - will invert"),s*=-1);var r=e.radialSegments||32;r<0&&(console.error("negative radialSegments not allowed - will invert"),r*=-1),r<3&&(r=3);var n=e.heightSegments||1;n<0&&(console.error("negative heightSegments not allowed - will invert"),n*=-1),n<1&&(n=1);var o,a,l,u,A,c,h,d,p,f,v,g=!!e.openEnded,m=e.center,_=m?m[0]:0,y=m?m[1]:0,b=m?m[2]:0,B=s/2,w=s/n,x=2*Math.PI/r,P=1/r,C=(t-i)/n,M=[],F=[],E=[],k=[],I=(90-180*Math.atan(s/(i-t))/Math.PI)/90;for(o=0;o<=n;o++)for(A=t-o*C,c=B-o*w,a=0;a<=r;a++)l=Math.sin(a*x),u=Math.cos(a*x),F.push(A*l),F.push(I),F.push(A*u),E.push(a*P),E.push(1*o/n),M.push(A*l+_),M.push(c+y),M.push(A*u+b);for(o=0;o0){for(p=M.length/3,F.push(0),F.push(1),F.push(0),E.push(.5),E.push(.5),M.push(0+_),M.push(B+y),M.push(0+b),a=0;a<=r;a++)l=Math.sin(a*x),u=Math.cos(a*x),f=.5*Math.sin(a*x)+.5,v=.5*Math.cos(a*x)+.5,F.push(t*l),F.push(1),F.push(t*u),E.push(f),E.push(v),M.push(t*l+_),M.push(B+y),M.push(t*u+b);for(a=0;a0){for(p=M.length/3,F.push(0),F.push(-1),F.push(0),E.push(.5),E.push(.5),M.push(0+_),M.push(0-B+y),M.push(0+b),a=0;a<=r;a++)l=Math.sin(a*x),u=Math.cos(a*x),f=.5*Math.sin(a*x)+.5,v=.5*Math.cos(a*x)+.5,F.push(i*l),F.push(-1),F.push(i*u),E.push(f),E.push(v),M.push(i*l+_),M.push(0-B+y),M.push(i*u+b);for(a=0;a0&&void 0!==arguments[0]?arguments[0]:{},t=e.lod||1,i=e.center?e.center[0]:0,s=e.center?e.center[1]:0,r=e.center?e.center[2]:0,n=e.radius||1;n<0&&(console.error("negative radius not allowed - will invert"),n*=-1);var o=e.heightSegments||18;o<0&&(console.error("negative heightSegments not allowed - will invert"),o*=-1),(o=Math.floor(t*o))<18&&(o=18);var a=e.widthSegments||18;a<0&&(console.error("negative widthSegments not allowed - will invert"),a*=-1),(a=Math.floor(t*a))<18&&(a=18);var l,u,A,c,h,d,p,f,v,g,m,_,y,b,B=[],w=[],x=[],P=[];for(l=0;l<=o;l++)for(A=l*Math.PI/o,c=Math.sin(A),h=Math.cos(A),u=0;u<=a;u++)d=2*u*Math.PI/a,p=Math.sin(d),f=Math.cos(d)*c,v=h,g=p*c,m=1-u/a,_=l/o,w.push(f),w.push(v),w.push(g),x.push(m),x.push(_),B.push(i+n*f),B.push(s+n*v),B.push(r+n*g);for(l=0;l":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function un(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.origin||[0,0,0],i=t[0],s=t[1],r=t[2],n=e.size||1,o=[],a=[],l=e.text;le.isNumeric(l)&&(l=""+l);for(var u,A,c,h,d,p,f,v,g,m=(l||"").split("\n"),_=0,y=0,b=.04,B=0;B1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({active:!0,pos:$.vec3(),dir:$.vec3(),dist:0}),s.active=r.active,s.pos=r.pos,s.dir=r.dir,s.scene._sectionPlaneCreated(b(s)),s}return C(i,[{key:"type",get:function(){return"SectionPlane"}},{key:"active",get:function(){return this._state.active},set:function(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active)}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-$.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos),this.scene.fire("sectionPlaneUpdated",this)}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||[0,0,-1]),this._state.dist=-$.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir),this.scene.fire("sectionPlaneUpdated",this)}},{key:"dist",get:function(){return this._state.dist}},{key:"flipDir",value:function(){var e=this._state.dir;e[0]*=-1,e[1]*=-1,e[2]*=-1,this._state.dist=-$.dotVec3(this._state.pos,this._state.dir),this.fire("dir",this._state.dir),this.glRedraw()}},{key:"destroy",value:function(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),f(B(i.prototype),"destroy",this).call(this)}}]),i}(),hn=$.vec4(4),dn=$.vec4(),pn=$.vec4(),fn=$.vec3([1,0,0]),vn=$.vec3([0,1,0]),gn=$.vec3([0,0,1]),mn=$.vec3(3),_n=$.vec3(3),yn=$.identityMat4(),bn=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,e,r))._parentNode=null,s._children=[],s._aabb=null,s._aabbDirty=!0,s.scene._aabbDirty=!0,s._numTriangles=0,s._scale=$.vec3(),s._quaternion=$.identityQuaternion(),s._rotation=$.vec3(),s._position=$.vec3(),s._offset=$.vec3(),s._localMatrix=$.identityMat4(),s._worldMatrix=$.identityMat4(),s._localMatrixDirty=!0,s._worldMatrixDirty=!0,r.matrix?s.matrix=r.matrix:(s.scale=r.scale,s.position=r.position,r.quaternion||(s.rotation=r.rotation)),s._isModel=r.isModel,s._isModel&&s.scene._registerModel(b(s)),s._isObject=r.isObject,s._isObject&&s.scene._registerObject(b(s)),s.origin=r.origin,s.visible=r.visible,s.culled=r.culled,s.pickable=r.pickable,s.clippable=r.clippable,s.collidable=r.collidable,s.castsShadow=r.castsShadow,s.receivesShadow=r.receivesShadow,s.xrayed=r.xrayed,s.highlighted=r.highlighted,s.selected=r.selected,s.edges=r.edges,s.colorize=r.colorize,s.opacity=r.opacity,s.offset=r.offset,r.children)for(var n=r.children,o=0,a=n.length;o1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"LambertMaterial",ambient:$.vec3([1,1,1]),color:$.vec3([1,1,1]),emissive:$.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),s.ambient=r.ambient,s.color=r.color,s.emissive=r.emissive,s.alpha=r.alpha,s.lineWidth=r.lineWidth,s.pointSize=r.pointSize,s.backfaces=r.backfaces,s.frontface=r.frontface,s}return C(i,[{key:"type",get:function(){return"LambertMaterial"}},{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:"color",get:function(){return this._state.color},set:function(e){var t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=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._state.alphaMode=e<1?2:0,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:"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:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),wn={opaque:0,mask:1,blend:2},xn=["opaque","mask","blend"],Pn=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"MetallicMaterial",baseColor:$.vec4([1,1,1]),emissive:$.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),s.baseColor=r.baseColor,s.metallic=r.metallic,s.roughness=r.roughness,s.specularF0=r.specularF0,s.emissive=r.emissive,s.alpha=r.alpha,r.baseColorMap&&(s._baseColorMap=s._checkComponent("Texture",r.baseColorMap)),r.metallicMap&&(s._metallicMap=s._checkComponent("Texture",r.metallicMap)),r.roughnessMap&&(s._roughnessMap=s._checkComponent("Texture",r.roughnessMap)),r.metallicRoughnessMap&&(s._metallicRoughnessMap=s._checkComponent("Texture",r.metallicRoughnessMap)),r.emissiveMap&&(s._emissiveMap=s._checkComponent("Texture",r.emissiveMap)),r.occlusionMap&&(s._occlusionMap=s._checkComponent("Texture",r.occlusionMap)),r.alphaMap&&(s._alphaMap=s._checkComponent("Texture",r.alphaMap)),r.normalMap&&(s._normalMap=s._checkComponent("Texture",r.normalMap)),s.alphaMode=r.alphaMode,s.alphaCutoff=r.alphaCutoff,s.backfaces=r.backfaces,s.frontface=r.frontface,s.lineWidth=r.lineWidth,s.pointSize=r.pointSize,s._makeHash(),s}return C(i,[{key:"type",get:function(){return"MetallicMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"baseColor",get:function(){return this._state.baseColor},set:function(e){var t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=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:"baseColorMap",get:function(){return this._baseColorMap}},{key:"metallic",get:function(){return this._state.metallic},set:function(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}},{key:"metallicMap",get:function(){return this._attached.metallicMap}},{key:"roughness",get:function(){return this._state.roughness},set:function(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}},{key:"roughnessMap",get:function(){return this._attached.roughnessMap}},{key:"metallicRoughnessMap",get:function(){return this._attached.metallicRoughnessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,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:"emissiveMap",get:function(){return this._attached.emissiveMap}},{key:"occlusionMap",get:function(){return this._attached.occlusionMap}},{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:"alphaMap",get:function(){return this._attached.alphaMap}},{key:"normalMap",get:function(){return this._attached.normalMap}},{key:"alphaMode",get:function(){return xn[this._state.alphaMode]},set:function(e){var t=wn[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:"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:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),Cn={opaque:0,mask:1,blend:2},Mn=["opaque","mask","blend"],Fn=function(e){g(i,Ri);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({type:"SpecularMaterial",diffuse:$.vec3([1,1,1]),emissive:$.vec3([0,0,0]),specular:$.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),s.diffuse=r.diffuse,s.specular=r.specular,s.glossiness=r.glossiness,s.specularF0=r.specularF0,s.emissive=r.emissive,s.alpha=r.alpha,r.diffuseMap&&(s._diffuseMap=s._checkComponent("Texture",r.diffuseMap)),r.emissiveMap&&(s._emissiveMap=s._checkComponent("Texture",r.emissiveMap)),r.specularMap&&(s._specularMap=s._checkComponent("Texture",r.specularMap)),r.glossinessMap&&(s._glossinessMap=s._checkComponent("Texture",r.glossinessMap)),r.specularGlossinessMap&&(s._specularGlossinessMap=s._checkComponent("Texture",r.specularGlossinessMap)),r.occlusionMap&&(s._occlusionMap=s._checkComponent("Texture",r.occlusionMap)),r.alphaMap&&(s._alphaMap=s._checkComponent("Texture",r.alphaMap)),r.normalMap&&(s._normalMap=s._checkComponent("Texture",r.normalMap)),s.alphaMode=r.alphaMode,s.alphaCutoff=r.alphaCutoff,s.backfaces=r.backfaces,s.frontface=r.frontface,s.lineWidth=r.lineWidth,s.pointSize=r.pointSize,s._makeHash(),s}return C(i,[{key:"type",get:function(){return"SpecularMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{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:"diffuseMap",get:function(){return this._diffuseMap}},{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:"specularMap",get:function(){return this._specularMap}},{key:"specularGlossinessMap",get:function(){return this._specularGlossinessMap}},{key:"glossiness",get:function(){return this._state.glossiness},set:function(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}},{key:"glossinessMap",get:function(){return this._glossinessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,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:"emissiveMap",get:function(){return this._emissiveMap}},{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:"alphaMap",get:function(){return this._alphaMap}},{key:"normalMap",get:function(){return this._normalMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"alphaMode",get:function(){return Mn[this._state.alphaMode]},set:function(e){var t=Cn[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:"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:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}();function En(e,t){var i,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=t;if(1009===r)return e.UNSIGNED_BYTE;if(1017===r)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===r)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===r)return e.BYTE;if(1011===r)return e.SHORT;if(1012===r)return e.UNSIGNED_SHORT;if(1013===r)return e.INT;if(1014===r)return e.UNSIGNED_INT;if(1015===r)return e.FLOAT;if(1016===r)return e.HALF_FLOAT;if(1021===r)return e.ALPHA;if(1023===r)return e.RGBA;if(1024===r)return e.LUMINANCE;if(1025===r)return e.LUMINANCE_ALPHA;if(1026===r)return e.DEPTH_COMPONENT;if(1027===r)return e.DEPTH_STENCIL;if(1028===r)return e.RED;if(1022===r)return e.RGBA;if(1029===r)return e.RED_INTEGER;if(1030===r)return e.RG;if(1031===r)return e.RG_INTEGER;if(1033===r)return e.RGBA_INTEGER;if(33776===r||33777===r||33778===r||33779===r)if(3001===s){var n=Kt(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===n)return null;if(33776===r)return n.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===r)return n.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===r)return n.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===r)return n.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(null===(i=Kt(e,"WEBGL_compressed_texture_s3tc")))return null;if(33776===r)return i.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===r)return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===r)return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===r)return i.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===r||35841===r||35842===r||35843===r){var o=Kt(e,"WEBGL_compressed_texture_pvrtc");if(null===o)return null;if(35840===r)return o.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===r)return o.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===r)return o.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===r)return o.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===r){var a=Kt(e,"WEBGL_compressed_texture_etc1");return null!==a?a.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===r||37496===r){var l=Kt(e,"WEBGL_compressed_texture_etc");if(null===l)return null;if(37492===r)return 3001===s?l.COMPRESSED_SRGB8_ETC2:l.COMPRESSED_RGB8_ETC2;if(37496===r)return 3001===s?l.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:l.COMPRESSED_RGBA8_ETC2_EAC}if(37808===r||37809===r||37810===r||37811===r||37812===r||37813===r||37814===r||37815===r||37816===r||37817===r||37818===r||37819===r||37820===r||37821===r){var u=Kt(e,"WEBGL_compressed_texture_astc");if(null===u)return null;if(37808===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:u.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:u.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:u.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:u.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:u.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:u.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:u.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:u.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:u.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:u.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:u.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:u.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:u.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===r)return 3001===s?u.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:u.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===r){var A=Kt(e,"EXT_texture_compression_bptc");if(null===A)return null;if(36492===r)return 3001===s?A.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:A.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===r?e.UNSIGNED_INT_24_8:1e3===r?e.REPEAT:1001===r?e.CLAMP_TO_EDGE:1004===r||1005===r?e.NEAREST_MIPMAP_LINEAR:1007===r?e.LINEAR_MIPMAP_NEAREST:1008===r?e.LINEAR_MIPMAP_LINEAR:1003===r?e.NEAREST:1006===r?e.LINEAR:null}var kn=new Uint8Array([0,0,0,1]),In=function(){function e(t){var i=t.gl,s=t.target,r=t.format,n=t.type,o=t.wrapS,a=t.wrapT,l=t.wrapR,u=t.encoding,A=t.preloadColor,c=t.premultiplyAlpha,h=t.flipY;x(this,e),this.gl=i,this.target=s||i.TEXTURE_2D,this.format=r||1023,this.type=n||1009,this.internalFormat=null,this.premultiplyAlpha=!!c,this.flipY=!!h,this.unpackAlignment=4,this.wrapS=o||1e3,this.wrapT=a||1e3,this.wrapR=l||1e3,this.encoding=u||3001,this.texture=i.createTexture(),A&&this.setPreloadColor(A),this.allocated=!0}return C(e,[{key:"setPreloadColor",value:function(e){e?(kn[0]=Math.floor(255*e[0]),kn[1]=Math.floor(255*e[1]),kn[2]=Math.floor(255*e[2]),kn[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(kn[0]=0,kn[1]=0,kn[2]=0,kn[3]=255);var t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP)for(var i=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z],s=0,r=i.length;s1&&void 0!==arguments[1]?arguments[1]:{},i=this.gl;void 0!==t.format&&(this.format=t.format),void 0!==t.internalFormat&&(this.internalFormat=t.internalFormat),void 0!==t.encoding&&(this.encoding=t.encoding),void 0!==t.type&&(this.type=t.type),void 0!==t.flipY&&(this.flipY=t.flipY),void 0!==t.premultiplyAlpha&&(this.premultiplyAlpha=t.premultiplyAlpha),void 0!==t.unpackAlignment&&(this.unpackAlignment=t.unpackAlignment),void 0!==t.minFilter&&(this.minFilter=t.minFilter),void 0!==t.magFilter&&(this.magFilter=t.magFilter),void 0!==t.wrapS&&(this.wrapS=t.wrapS),void 0!==t.wrapT&&(this.wrapT=t.wrapT),void 0!==t.wrapR&&(this.wrapR=t.wrapR);var s=!1;i.bindTexture(this.target,this.texture);var r=i.getParameter(i.UNPACK_FLIP_Y_WEBGL);i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,this.flipY);var n=i.getParameter(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL);i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha);var o=i.getParameter(i.UNPACK_ALIGNMENT);i.pixelStorei(i.UNPACK_ALIGNMENT,this.unpackAlignment);var a=i.getParameter(i.UNPACK_COLORSPACE_CONVERSION_WEBGL);i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.NONE);var l=En(i,this.minFilter);i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,l),l!==i.NEAREST_MIPMAP_NEAREST&&l!==i.LINEAR_MIPMAP_NEAREST&&l!==i.NEAREST_MIPMAP_LINEAR&&l!==i.LINEAR_MIPMAP_LINEAR||(s=!0);var u=En(i,this.magFilter);u&&i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,u);var A=En(i,this.wrapS);A&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,A);var c=En(i,this.wrapT);c&&i.texParameteri(this.target,i.TEXTURE_WRAP_T,c);var h=En(i,this.format,this.encoding),d=En(i,this.type),p=Dn(i,this.internalFormat,h,d,this.encoding,!1);if(this.target===i.TEXTURE_CUBE_MAP){if(le.isArray(e))for(var f=e,v=[i.TEXTURE_CUBE_MAP_POSITIVE_X,i.TEXTURE_CUBE_MAP_NEGATIVE_X,i.TEXTURE_CUBE_MAP_POSITIVE_Y,i.TEXTURE_CUBE_MAP_NEGATIVE_Y,i.TEXTURE_CUBE_MAP_POSITIVE_Z,i.TEXTURE_CUBE_MAP_NEGATIVE_Z],g=0,m=v.length;g1;r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,this.flipY),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),r.pixelStorei(r.UNPACK_ALIGNMENT,this.unpackAlignment),r.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,r.NONE);var a=En(r,this.wrapS);a&&r.texParameteri(this.target,r.TEXTURE_WRAP_S,a);var l=En(r,this.wrapT);if(l&&r.texParameteri(this.target,r.TEXTURE_WRAP_T,l),this.type===r.TEXTURE_3D||this.type===r.TEXTURE_2D_ARRAY){var u=En(r,this.wrapR);u&&r.texParameteri(this.target,r.TEXTURE_WRAP_R,u),r.texParameteri(this.type,r.TEXTURE_WRAP_R,u)}o?(r.texParameteri(this.target,r.TEXTURE_MIN_FILTER,Sn(r,this.minFilter)),r.texParameteri(this.target,r.TEXTURE_MAG_FILTER,Sn(r,this.magFilter))):(r.texParameteri(this.target,r.TEXTURE_MIN_FILTER,En(r,this.minFilter)),r.texParameteri(this.target,r.TEXTURE_MAG_FILTER,En(r,this.magFilter)));var A=En(r,this.format,this.encoding),c=En(r,this.type),h=Dn(r,this.internalFormat,A,c,this.encoding,!1);r.texStorage2D(r.TEXTURE_2D,n,h,t[0].width,t[0].height);for(var d=0,p=t.length;d5&&void 0!==arguments[5]&&arguments[5];if(null!==t){if(void 0!==e[t])return e[t];console.warn("Attempt to use non-existing WebGL internal format '"+t+"'")}var o=i;return i===e.RED&&(s===e.FLOAT&&(o=e.R32F),s===e.HALF_FLOAT&&(o=e.R16F),s===e.UNSIGNED_BYTE&&(o=e.R8)),i===e.RG&&(s===e.FLOAT&&(o=e.RG32F),s===e.HALF_FLOAT&&(o=e.RG16F),s===e.UNSIGNED_BYTE&&(o=e.RG8)),i===e.RGBA&&(s===e.FLOAT&&(o=e.RGBA32F),s===e.HALF_FLOAT&&(o=e.RGBA16F),s===e.UNSIGNED_BYTE&&(o=3001===r&&!1===n?e.SRGB8_ALPHA8:e.RGBA8),s===e.UNSIGNED_SHORT_4_4_4_4&&(o=e.RGBA4),s===e.UNSIGNED_SHORT_5_5_5_1&&(o=e.RGB5_A1)),o!==e.R16F&&o!==e.R32F&&o!==e.RG16F&&o!==e.RG32F&&o!==e.RGBA16F&&o!==e.RGBA32F||Kt(e,"EXT_color_buffer_float"),o}function Sn(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function Tn(e){if(!Rn(e.width)||!Rn(e.height)){var t=document.createElement("canvas");t.width=Ln(e.width),t.height=Ln(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Rn(e){return 0==(e&e-1)}function Ln(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var Un=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({texture:new In({gl:s.scene.canvas.gl}),matrix:$.identityMat4(),hasMatrix:r.translate&&(0!==r.translate[0]||0!==r.translate[1])||!!r.rotate||r.scale&&(0!==r.scale[0]||0!==r.scale[1]),minFilter:s._checkMinFilter(r.minFilter),magFilter:s._checkMagFilter(r.magFilter),wrapS:s._checkWrapS(r.wrapS),wrapT:s._checkWrapT(r.wrapT),flipY:s._checkFlipY(r.flipY),encoding:s._checkEncoding(r.encoding)}),s._src=null,s._image=null,s._translate=$.vec2([0,0]),s._scale=$.vec2([1,1]),s._rotate=$.vec2([0,0]),s._matrixDirty=!1,s.translate=r.translate,s.scale=r.scale,s.rotate=r.rotate,r.src?s.src=r.src:r.image&&(s.image=r.image),se.memory.textures++,s}return C(i,[{key:"type",get:function(){return"Texture"}},{key:"_checkMinFilter",value:function(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}},{key:"_checkMagFilter",value:function(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}},{key:"_checkWrapS",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkWrapT",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this._state.texture=new In({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}},{key:"_update",value:function(){var e,t,i=this._state;this._matrixDirty&&(0===this._translate[0]&&0===this._translate[1]||(e=$.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(t=$.scalingMat4v([this._scale[0],this._scale[1],1]),e=e?$.mulMat4(e,t):t),0!==this._rotate&&(t=$.rotationMat4v(.0174532925*this._rotate,[0,0,1]),e=e?$.mulMat4(e,t):t),e&&(i.matrix=e),this._matrixDirty=!1);this.glRedraw()}},{key:"image",get:function(){return this._image},set:function(e){this._image=Tn(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}},{key:"src",get:function(){return this._src},set:function(e){this.scene.loading++,this.scene.canvas.spinner.processes++;var t=this,i=new Image;i.onload=function(){i=Tn(i),t._state.texture.setImage(i,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},i.src=e,this._src=e,this._image=null}},{key:"translate",get:function(){return this._translate},set:function(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}},{key:"rotate",get:function(){return this._rotate},set:function(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}},{key:"minFilter",get:function(){return this._state.minFilter}},{key:"magFilter",get:function(){return this._state.magFilter}},{key:"wrapS",get:function(){return this._state.wrapS}},{key:"wrapT",get:function(){return this._state.wrapT}},{key:"flipY",get:function(){return this._state.flipY}},{key:"encoding",get:function(){return this._state.encoding}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),se.memory.textures--}}]),i}(),On=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._state=new Zt({edgeColor:$.vec3([0,0,0]),centerColor:$.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),s.edgeColor=r.edgeColor,s.centerColor=r.centerColor,s.edgeBias=r.edgeBias,s.centerBias=r.centerBias,s.power=r.power,s}return C(i,[{key:"type",get:function(){return"Fresnel"}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}},{key:"centerColor",get:function(){return this._state.centerColor},set:function(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}},{key:"edgeBias",get:function(){return this._state.edgeBias},set:function(e){this._state.edgeBias=e||0,this.glRedraw()}},{key:"centerBias",get:function(){return this._state.centerBias},set:function(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}},{key:"power",get:function(){return this._state.power},set:function(e){this._state.power=null!=e?e:1,this.glRedraw()}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this._state.destroy()}}]),i}(),Nn=se.memory,Qn=$.AABB3(),Vn=function(e){g(i,Bi);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e,r))._state=new Zt({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),s._numTriangles=0,s._edgeThreshold=r.edgeThreshold||10,s._aabb=null,s._obb=$.OBB3();var n,o=s._state,a=s.scene.canvas.gl;switch(r.primitive=r.primitive||"triangles",r.primitive){case"points":o.primitive=a.POINTS,o.primitiveName=r.primitive;break;case"lines":o.primitive=a.LINES,o.primitiveName=r.primitive;break;case"line-loop":o.primitive=a.LINE_LOOP,o.primitiveName=r.primitive;break;case"line-strip":o.primitive=a.LINE_STRIP,o.primitiveName=r.primitive;break;case"triangles":o.primitive=a.TRIANGLES,o.primitiveName=r.primitive;break;case"triangle-strip":o.primitive=a.TRIANGLE_STRIP,o.primitiveName=r.primitive;break;case"triangle-fan":o.primitive=a.TRIANGLE_FAN,o.primitiveName=r.primitive;break;default:s.error("Unsupported value for 'primitive': '"+r.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),o.primitive=a.TRIANGLES,o.primitiveName=r.primitive}if(!r.positions)return s.error("Config expected: positions"),y(s);if(!r.indices)return s.error("Config expected: indices"),y(s);var l=r.positionsDecodeMatrix;if(l);else{var u=ki.getPositionsBounds(r.positions),A=ki.compressPositions(r.positions,u.min,u.max);n=A.quantized,o.positionsDecodeMatrix=A.decodeMatrix,o.positionsBuf=new It(a,a.ARRAY_BUFFER,n,n.length,3,a.STATIC_DRAW),Nn.positions+=o.positionsBuf.numItems,$.positions3ToAABB3(r.positions,s._aabb),$.positions3ToAABB3(n,Qn,o.positionsDecodeMatrix),$.AABB3ToOBB3(Qn,s._obb)}if(r.colors){var c=r.colors.constructor===Float32Array?r.colors:new Float32Array(r.colors);o.colorsBuf=new It(a,a.ARRAY_BUFFER,c,c.length,4,a.STATIC_DRAW),Nn.colors+=o.colorsBuf.numItems}if(r.uv){var h=ki.getUVBounds(r.uv),d=ki.compressUVs(r.uv,h.min,h.max),p=d.quantized;o.uvDecodeMatrix=d.decodeMatrix,o.uvBuf=new It(a,a.ARRAY_BUFFER,p,p.length,2,a.STATIC_DRAW),Nn.uvs+=o.uvBuf.numItems}if(r.normals){var f=ki.compressNormals(r.normals),v=o.compressGeometry;o.normalsBuf=new It(a,a.ARRAY_BUFFER,f,f.length,3,a.STATIC_DRAW,v),Nn.normals+=o.normalsBuf.numItems}var g=r.indices.constructor===Uint32Array||r.indices.constructor===Uint16Array?r.indices:new Uint32Array(r.indices);o.indicesBuf=new It(a,a.ELEMENT_ARRAY_BUFFER,g,g.length,1,a.STATIC_DRAW),Nn.indices+=o.indicesBuf.numItems;var m=wi(n,g,o.positionsDecodeMatrix,s._edgeThreshold);return s._edgeIndicesBuf=new It(a,a.ELEMENT_ARRAY_BUFFER,m,m.length,1,a.STATIC_DRAW),"triangles"===s._state.primitiveName&&(s._numTriangles=r.indices.length/3),s._buildHash(),Nn.meshes++,s}return C(i,[{key:"type",get:function(){return"VBOGeometry"}},{key:"isVBOGeometry",get:function(){return!0}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"aabb",get:function(){return this._aabb}},{key:"obb",get:function(){return this._obb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){f(B(i.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(),e.destroy(),Nn.meshes--}}]),i}(),Hn={};function jn(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(i,s){t.src||(console.error("load3DSGeometry: Parameter expected: src"),s());var r=e.canvas.spinner;r.processes++,le.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),r.processes--,s());var n=Hn.parse.from3DS(e).edit.objects[0].mesh,o=n.vertices,a=n.uvt,l=n.indices;r.processes--,i(le.apply(t,{primitive:"triangles",positions:o,normals:null,uv:a,indices:l}))}),(function(e){console.error("load3DSGeometry: "+e),r.processes--,s()}))}))}function Gn(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(i,s){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),s());var r=e.canvas.spinner;r.processes++,le.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),r.processes--,s());for(var n=Hn.parse.fromOBJ(e),o=Hn.edit.unwrap(n.i_verts,n.c_verts,3),a=Hn.edit.unwrap(n.i_norms,n.c_norms,3),l=Hn.edit.unwrap(n.i_uvt,n.c_uvt,2),u=new Int32Array(n.i_verts.length),A=0;A0?a:null,autoNormals:0===a.length,uv:l,indices:u}))}),(function(e){console.error("loadOBJGeometry: "+e),r.processes--,s()}))}))}function zn(){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 i=e.ySize||1;i<0&&(console.error("negative ySize not allowed - will invert"),i*=-1);var s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);var r=e.center,n=r?r[0]:0,o=r?r[1]:0,a=r?r[2]:0,l=-t+n,u=-i+o,A=-s+a,c=t+n,h=i+o,d=s+a;return le.apply(e,{primitive:"lines",positions:[l,u,A,l,u,d,l,h,A,l,h,d,c,u,A,c,u,d,c,h,A,c,h,d],indices:[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,2,6,3,7]})}function Wn(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return zn({id:e.id,center:[(e.aabb[0]+e.aabb[3])/2,(e.aabb[1]+e.aabb[4])/2,(e.aabb[2]+e.aabb[5])/2],xSize:Math.abs(e.aabb[3]-e.aabb[0])/2,ySize:Math.abs(e.aabb[4]-e.aabb[1])/2,zSize:Math.abs(e.aabb[5]-e.aabb[2])/2})}function Kn(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);var i=e.divisions||1;i<0&&(console.error("negative divisions not allowed - will invert"),i*=-1),i<1&&(i=1);for(var s=(t=t||10)/(i=i||10),r=t/2,n=[],o=[],a=0,l=0,u=-r;l<=i;l++,u+=s)n.push(-r),n.push(0),n.push(u),n.push(r),n.push(0),n.push(u),n.push(u),n.push(0),n.push(-r),n.push(u),n.push(0),n.push(r),o.push(a++),o.push(a++),o.push(a++),o.push(a++);return le.apply(e,{primitive:"lines",positions:n,indices:o})}function Xn(){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 i=e.zSize||1;i<0&&(console.error("negative zSize not allowed - will invert"),i*=-1);var s=e.xSegments||1;s<0&&(console.error("negative xSegments not allowed - will invert"),s*=-1),s<1&&(s=1);var r=e.xSegments||1;r<0&&(console.error("negative zSegments not allowed - will invert"),r*=-1),r<1&&(r=1);var n,o,a,l,u,A,c,h=e.center,d=h?h[0]:0,p=h?h[1]:0,f=h?h[2]:0,v=t/2,g=i/2,m=Math.floor(s)||1,_=Math.floor(r)||1,y=m+1,b=_+1,B=t/m,w=i/_,x=new Float32Array(y*b*3),P=new Float32Array(y*b*3),C=new Float32Array(y*b*2),M=0,F=0;for(n=0;n65535?Uint32Array:Uint16Array)(m*_*6);for(n=0;n<_;n++)for(o=0;o0&&void 0!==arguments[0]?arguments[0]:{},t=e.radius||1;t<0&&(console.error("negative radius not allowed - will invert"),t*=-1),t*=.5;var i=e.tube||.3;i<0&&(console.error("negative tube not allowed - will invert"),i*=-1);var s=e.radialSegments||32;s<0&&(console.error("negative radialSegments not allowed - will invert"),s*=-1),s<4&&(s=4);var r=e.tubeSegments||24;r<0&&(console.error("negative tubeSegments not allowed - will invert"),r*=-1),r<4&&(r=4);var n=e.arc||2*Math.PI;n<0&&(console.warn("negative arc not allowed - will invert"),n*=-1),n>360&&(n=360);var o,a,l,u,A,c,h,d,p,f,v,g,m=e.center,_=m?m[0]:0,y=m?m[1]:0,b=m?m[2]:0,B=[],w=[],x=[],P=[];for(d=0;d<=r;d++)for(h=0;h<=s;h++)o=h/s*n,a=.785398+d/r*Math.PI*2,_=t*Math.cos(o),y=t*Math.sin(o),l=(t+i*Math.cos(a))*Math.cos(o),u=(t+i*Math.cos(a))*Math.sin(o),A=i*Math.sin(a),B.push(l+_),B.push(u+y),B.push(A+b),x.push(1-h/s),x.push(d/r),c=$.normalizeVec3($.subVec3([l,u,A],[_,y,b],[]),[]),w.push(c[0]),w.push(c[1]),w.push(c[2]);for(d=1;d<=r;d++)for(h=1;h<=s;h++)p=(s+1)*d+h-1,f=(s+1)*(d-1)+h-1,v=(s+1)*(d-1)+h,g=(s+1)*d+h,P.push(p),P.push(f),P.push(v),P.push(v),P.push(g),P.push(p);return le.apply(e,{positions:B,normals:w,uv:x,indices:P})}function Yn(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e.points.length%3!=0)throw"Size of points array for given polyline should be divisible by 3";var t=e.points.length/3;if(t<2)throw"There should be at least 2 points to create a polyline";for(var i=[],s=0;s0&&void 0!==arguments[0]?arguments[0]:{},t=e.curve.getPoints(e.divisions).map((function(e){return A(e)})).flat();return Yn({id:e.id,points:t})}Hn.load=function(e,t){var i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="arraybuffer",i.onload=function(e){t(e.target.response)},i.send()},Hn.save=function(e,t){var i="data:application/octet-stream;base64,"+btoa(Hn.parse._buffToStr(e));window.location.href=i},Hn.clone=function(e){return JSON.parse(JSON.stringify(e))},Hn.bin={},Hn.bin.f=new Float32Array(1),Hn.bin.fb=new Uint8Array(Hn.bin.f.buffer),Hn.bin.rf=function(e,t){for(var i=Hn.bin.f,s=Hn.bin.fb,r=0;r<4;r++)s[r]=e[t+r];return i[0]},Hn.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Hn.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Hn.bin.rASCII0=function(e,t){for(var i="";0!=e[t];)i+=String.fromCharCode(e[t++]);return i},Hn.bin.wf=function(e,t,i){new Float32Array(e.buffer,t,1)[0]=i},Hn.bin.wsl=function(e,t,i){e[t]=i,e[t+1]=i>>8},Hn.bin.wil=function(e,t,i){e[t]=i,e[t+1]=i>>8,e[t+2]=i>>16,e[t+3]},Hn.parse={},Hn.parse._buffToStr=function(e){for(var t=new Uint8Array(e),i="",s=0;sr&&(r=l),un&&(n=u),Ao&&(o=A)}return{min:{x:t,y:i,z:s},max:{x:r,y:n,z:o}}};var qn=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._type=r.type||(r.src?r.src.split(".").pop():null)||"jpg",s._pos=$.vec3(r.pos||[0,0,0]),s._up=$.vec3(r.up||[0,1,0]),s._normal=$.vec3(r.normal||[0,0,1]),s._height=r.height||1,s._origin=$.vec3(),s._rtcPos=$.vec3(),s._imageSize=$.vec2(),s._texture=new Un(b(s),{flipY:!0}),s._image=new Image,"jpg"!==s._type&&"png"!==s._type&&(s.error('Unsupported type - defaulting to "jpg"'),s._type="jpg"),s._node=new bn(b(s),{matrix:$.inverseMat4($.lookAtMat4v(s._pos,$.subVec3(s._pos,s._normal,$.mat4()),s._up,$.mat4())),children:[s._bitmapMesh=new rn(b(s),{scale:[1,1,1],rotation:[-90,0,0],collidable:r.collidable,pickable:r.pickable,opacity:r.opacity,clippable:r.clippable,geometry:new Si(b(s),Xn({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new Oi(b(s),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:s._texture,emissiveMap:s._texture,backfaces:!0})})]}),r.image?s.image=r.image:r.src?s.src=r.src:r.imageData&&(s.imageData=r.imageData),s.scene._bitmapCreated(b(s)),s}return C(i,[{key:"visible",get:function(){return this._bitmapMesh.visible},set:function(e){this._bitmapMesh.visible=e}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}},{key:"src",get:function(){return this._image.src},set:function(e){var t=this;if(e)switch(this._image.onload=function(){t._texture.image=t._image,t._imageSize[0]=t._image.width,t._imageSize[1]=t._image.height,t._updateBitmapMeshScale()},this._image.src=e,e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}},{key:"imageData",get:function(){var e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")},set:function(e){var t=this;this._image.onload=function(){t._texture.image=image,t._imageSize[0]=image.width,t._imageSize[1]=image.height,t._updateBitmapMeshScale()},this._image.src=e}},{key:"type",get:function(){return this._type},set:function(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}},{key:"pos",get:function(){return this._pos}},{key:"normal",get:function(){return this._normal}},{key:"up",get:function(){return this._up}},{key:"height",get:function(){return this._height},set:function(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}},{key:"collidable",get:function(){return this._bitmapMesh.collidable},set:function(e){this._bitmapMesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._bitmapMesh.clippable},set:function(e){this._bitmapMesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._bitmapMesh.pickable},set:function(e){this._bitmapMesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._bitmapMesh.opacity},set:function(e){this._bitmapMesh.opacity=e}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this.scene._bitmapDestroyed(this)}},{key:"_updateBitmapMeshScale",value:function(){var e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height/e,1,this._height]}}]),i}(),$n=$.OBB3(),eo=$.OBB3(),to=$.OBB3(),io=function(){function e(t,i,s,r,n,o){var a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null,l=arguments.length>7&&void 0!==arguments[7]?arguments[7]:0;x(this,e),this.model=t,this.object=null,this.parent=null,this.transform=n,this.textureSet=o,this._matrixDirty=!1,this._matrixUpdateScheduled=!1,this.id=i,this.obb=null,this._aabbLocal=null,this._aabbWorld=$.AABB3(),this._aabbWorldDirty=!1,this.layer=a,this.portionId=l,this._color=new Uint8Array([s[0],s[1],s[2],r]),this._colorize=new Uint8Array([s[0],s[1],s[2],r]),this._colorizing=!1,this._transparent=r<255,this.numTriangles=0,this.origin=null,this.entity=null,n&&n._addMesh(this)}return C(e,[{key:"_sceneModelDirty",value:function(){this._aabbWorldDirty=!0,this.layer.aabbDirty=!0}},{key:"_transformDirty",value:function(){this._matrixDirty||this._matrixUpdateScheduled||(this.model._meshMatrixDirty(this),this._matrixDirty=!0,this._matrixUpdateScheduled=!0),this._aabbWorldDirty=!0,this.layer.aabbDirty=!0,this.entity&&this.entity._transformDirty()}},{key:"_updateMatrix",value:function(){this.transform&&this._matrixDirty&&this.layer.setMatrix(this.portionId,this.transform.worldMatrix),this._matrixDirty=!1,this._matrixUpdateScheduled=!1}},{key:"_finalize",value:function(e){this.layer.initFlags(this.portionId,e,this._transparent)}},{key:"_finalize2",value:function(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}},{key:"_setVisible",value:function(e){this.layer.setVisible(this.portionId,e,this._transparent)}},{key:"_setColor",value:function(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}},{key:"_setColorize",value:function(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}},{key:"_setOpacity",value:function(e,t){var i=e<255,s=this._transparent!==i;this._color[3]=e,this._colorize[3]=e,this._transparent=i,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),s&&this.layer.setTransparent(this.portionId,t,i)}},{key:"_setOffset",value:function(e){this.layer.setOffset(this.portionId,e)}},{key:"_setHighlighted",value:function(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}},{key:"_setXRayed",value:function(e){this.layer.setXRayed(this.portionId,e,this._transparent)}},{key:"_setSelected",value:function(e){this.layer.setSelected(this.portionId,e,this._transparent)}},{key:"_setEdges",value:function(e){this.layer.setEdges(this.portionId,e,this._transparent)}},{key:"_setClippable",value:function(e){this.layer.setClippable(this.portionId,e,this._transparent)}},{key:"_setCollidable",value:function(e){this.layer.setCollidable(this.portionId,e)}},{key:"_setPickable",value:function(e){this.layer.setPickable(this.portionId,e,this._transparent)}},{key:"_setCulled",value:function(e){this.layer.setCulled(this.portionId,e,this._transparent)}},{key:"canPickTriangle",value:function(){return!1}},{key:"drawPickTriangles",value:function(e,t){}},{key:"pickTriangleSurface",value:function(e){}},{key:"precisionRayPickSurface",value:function(e,t,i,s){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,i,s)}},{key:"canPickWorldPos",value:function(){return!0}},{key:"drawPickDepths",value:function(e){this.model.drawPickDepths(e)}},{key:"drawPickNormals",value:function(e){this.model.drawPickNormals(e)}},{key:"delegatePickedEntity",value:function(){return this.parent}},{key:"getEachVertex",value:function(e){this.layer.getEachVertex(this.portionId,e)}},{key:"aabb",get:function(){if(this._aabbWorldDirty){if($.AABB3ToOBB3(this._aabbLocal,$n),this.transform?($.transformOBB3(this.transform.worldMatrix,$n,eo),$.transformOBB3(this.model.worldMatrix,eo,to),$.OBB3ToAABB3(to,this._aabbWorld)):($.transformOBB3(this.model.worldMatrix,$n,eo),$.OBB3ToAABB3(eo,this._aabbWorld)),this.origin){var e=this.origin;this._aabbWorld[0]+=e[0],this._aabbWorld[1]+=e[1],this._aabbWorld[2]+=e[2],this._aabbWorld[3]+=e[0],this._aabbWorld[4]+=e[1],this._aabbWorld[5]+=e[2]}this._aabbWorldDirty=!1}return this._aabbWorld},set:function(e){this._aabbLocal=e}},{key:"_destroy",value:function(){this.model.scene._renderer.putPickID(this.pickId)}}]),e}(),so=new(function(){function e(){x(this,e),this._uint8Arrays={},this._float32Arrays={}}return C(e,[{key:"_clear",value:function(){this._uint8Arrays={},this._float32Arrays={}}},{key:"getUInt8Array",value:function(e){var t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}},{key:"getFloat32Array",value:function(e){var t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}}]),e}()),ro=0;function no(){return ro++,so}var oo={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},ao=new Float32Array([1,1,1,1]),lo=new Float32Array([0,0,0,1]),uo=$.vec4(),Ao=$.vec3(),co=$.vec3(),ho=$.mat4(),po=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=s.instancing,n=void 0!==r&&r,o=s.edges,a=void 0!==o&&o;x(this,e),this._scene=t,this._withSAO=i,this._instancing=n,this._edges=a,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}return C(e,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){return[""]}},{key:"_buildFragmentShader",value:function(){return[""]}},{key:"_addMatricesUniformBlockLines",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}},{key:"_addRemapClipPosLines",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return e.push("uniform vec2 drawingBufferSize;"),e.push("uniform vec2 pickClipPos;"),e.push("vec4 remapClipPos(vec4 clipPos) {"),e.push(" clipPos.xy /= clipPos.w;"),1===t?e.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"):e.push(" clipPos.xy = (clipPos.xy - pickClipPos) * (drawingBufferSize / float(".concat(t,"));")),e.push(" clipPos.xy *= clipPos.w;"),e.push(" return clipPos;"),e.push("}"),e}},{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"setSectionPlanesStateUniforms",value:function(e){var t=this._scene,i=t.canvas.gl,s=e.model,r=e.layerIndex,n=t._sectionPlanesState.getNumAllocatedSectionPlanes(),o=t._sectionPlanesState.sectionPlanes.length;if(n>0){var a=t._sectionPlanesState.sectionPlanes,l=r*o,u=s.renderFlags;t.crossSections&&(i.uniform4fv(this._uSliceColor,t.crossSections.sliceColor),i.uniform1f(this._uSliceThickness,t.crossSections.sliceThickness));for(var A=0;A0&&(this._uReflectionMap="reflectionMap"),i.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(var a=0,l=e._sectionPlanesState.getNumAllocatedSectionPlanes();a3&&void 0!==arguments[3]?arguments[3]:{},r=s.colorUniform,n=void 0!==r&&r,o=s.incrementDrawState,a=void 0!==o&&o,l=yt.MAX_TEXTURE_IMAGE_UNITS,u=this._scene,A=u.canvas.gl,c=t._state,h=t.model,d=c.textureSet,p=c.origin,f=c.positionsDecodeMatrix,v=u._lightsState,g=u.pointsMaterial,m=h.scene.camera,_=m.viewNormalMatrix,y=m.project,b=e.pickViewMatrix||m.viewMatrix,B=h.position,w=h.rotationMatrix,x=h.rotationMatrixConjugate,P=h.worldNormalMatrix;if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),this._vaoCache.has(t)?A.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(c));var C=0,M=16;this._matricesUniformBlockBufferData.set(x,0);var F=0!==p[0]||0!==p[1]||0!==p[2],E=0!==B[0]||0!==B[1]||0!==B[2];if(F||E){var k=Ao;if(F){var I=$.transformPoint3(w,p,co);k[0]=I[0],k[1]=I[1],k[2]=I[2]}else k[0]=0,k[1]=0,k[2]=0;k[0]+=B[0],k[1]+=B[1],k[2]+=B[2],this._matricesUniformBlockBufferData.set(Re(b,k,ho),C+=M)}else this._matricesUniformBlockBufferData.set(b,C+=M);if(this._matricesUniformBlockBufferData.set(e.pickProjMatrix||y.matrix,C+=M),this._matricesUniformBlockBufferData.set(f,C+=M),this._matricesUniformBlockBufferData.set(P,C+=M),this._matricesUniformBlockBufferData.set(_,C+=M),A.bindBuffer(A.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),A.bufferData(A.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,A.DYNAMIC_DRAW),A.bindBufferBase(A.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer),A.uniform1i(this._uRenderPass,i),this.setSectionPlanesStateUniforms(t),u.logarithmicDepthBufferEnabled){if(this._uLogDepthBufFC){var D=2/(Math.log(e.pickZFar+1)/Math.LN2);A.uniform1f(this._uLogDepthBufFC,D)}this._uZFar&&A.uniform1f(this._uZFar,u.camera.project.far)}if(this._uPickInvisible&&A.uniform1i(this._uPickInvisible,e.pickInvisible),this._uPickZNear&&A.uniform1f(this._uPickZNear,e.pickZNear),this._uPickZFar&&A.uniform1f(this._uPickZFar,e.pickZFar),this._uPickClipPos&&A.uniform2fv(this._uPickClipPos,e.pickClipPos),this._uDrawingBufferSize&&A.uniform2f(this._uDrawingBufferSize,A.drawingBufferWidth,A.drawingBufferHeight),this._uUVDecodeMatrix&&A.uniformMatrix3fv(this._uUVDecodeMatrix,!1,c.uvDecodeMatrix),this._uIntensityRange&&g.filterIntensity&&A.uniform2f(this._uIntensityRange,g.minIntensity,g.maxIntensity),this._uPointSize&&A.uniform1f(this._uPointSize,g.pointSize),this._uNearPlaneHeight){var S="ortho"===u.camera.projection?1:A.drawingBufferHeight/(2*Math.tan(.5*u.camera.perspective.fov*Math.PI/180));A.uniform1f(this._uNearPlaneHeight,S)}if(d){var T=d.colorTexture,R=d.metallicRoughnessTexture,L=d.emissiveTexture,U=d.normalsTexture,O=d.occlusionTexture;this._uColorMap&&T&&(this._program.bindTexture(this._uColorMap,T.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uMetallicRoughMap&&R&&(this._program.bindTexture(this._uMetallicRoughMap,R.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uEmissiveMap&&L&&(this._program.bindTexture(this._uEmissiveMap,L.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uNormalMap&&U&&(this._program.bindTexture(this._uNormalMap,U.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uAOMap&&O&&(this._program.bindTexture(this._uAOMap,O.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l)}if(v.reflectionMaps.length>0&&v.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,v.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++),v.lightMaps.length>0&&v.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,v.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++),this._withSAO){var N=u.sao,Q=N.possible;if(Q){var V=A.drawingBufferWidth,H=A.drawingBufferHeight;uo[0]=V,uo[1]=H,uo[2]=N.blendCutoff,uo[3]=N.blendFactor,A.uniform4fv(this._uSAOParams,uo),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++}}if(n){var j=this._edges?"edgeColor":"fillColor",G=this._edges?"edgeAlpha":"fillAlpha";if(i===oo["".concat(this._edges?"EDGES":"SILHOUETTE","_XRAYED")]){var z=u.xrayMaterial._state,W=z[j],K=z[G];A.uniform4f(this._uColor,W[0],W[1],W[2],K)}else if(i===oo["".concat(this._edges?"EDGES":"SILHOUETTE","_HIGHLIGHTED")]){var X=u.highlightMaterial._state,J=X[j],Y=X[G];A.uniform4f(this._uColor,J[0],J[1],J[2],Y)}else if(i===oo["".concat(this._edges?"EDGES":"SILHOUETTE","_SELECTED")]){var Z=u.selectedMaterial._state,q=Z[j],ee=Z[G];A.uniform4f(this._uColor,q[0],q[1],q[2],ee)}else A.uniform4fv(this._uColor,this._edges?lo:ao)}this._draw({state:c,frameCtx:e,incrementDrawState:a}),A.bindVertexArray(null)}}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null,se.memory.programs--}}]),e}(),fo=function(e){g(i,po);var t=_(i);function i(e,s){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.edges,o=void 0!==n&&n;return x(this,i),t.call(this,e,s,{instancing:!1,edges:o})}return C(i,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,i=e.state,s=e.frameCtx,r=e.incrementDrawState;if(this._edges)t.drawElements(t.LINES,i.edgeIndicesBuf.numItems,i.edgeIndicesBuf.itemType,0);else{var n=s.pickElementsCount||i.indicesBuf.numItems,o=s.pickElementsOffset?s.pickElementsOffset*i.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,n,i.indicesBuf.itemType,o),r&&s.drawElements++}}}]),i}(),vo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e,t=this._scene,i=t._sectionPlanesState,s=t._lightsState,r=i.getNumAllocatedSectionPlanes()>0,n=[];n.push("#version 300 es"),n.push("// Triangles batching draw vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in float flags;"),t.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n,!0),t.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("uniform vec4 lightAmbient;");for(var o=0,a=s.lights.length;o= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),r&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),t.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),n.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),n.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),n.push("float lambertian = 1.0;");for(var l=0,u=s.lights.length;l0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching draw fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o sliceThickness) { "),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" newColor = sliceColor;"),s.push(" }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(s.push(" float viewportWidth = uSAOParams[0];"),s.push(" float viewportHeight = uSAOParams[1];"),s.push(" float blendCutoff = uSAOParams[2];"),s.push(" float blendFactor = uSAOParams[3];"),s.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),s.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),s.push(" outColor = vec4(newColor.rgb * ambient, 1.0);")):s.push(" outColor = newColor;"),s.push("}"),s}}]),i}(),go=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("in float flags;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vViewPosition;"),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push("worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vViewPosition = viewPosition;"),i.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._lightsState,i=e._sectionPlanesState,s=i.getNumAllocatedSectionPlanes()>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching flat-shading draw 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("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),s){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var n=0,o=i.getNumAllocatedSectionPlanes();n> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var A=0,c=i.getNumAllocatedSectionPlanes();A sliceThickness) { "),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" newColor = sliceColor;"),r.push(" }"),r.push("}")}r.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),r.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),r.push("float lambertian = 1.0;"),r.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),r.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),r.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var h=0,d=t.lights.length;h0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching silhouette vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 color;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),i.push("if (silhouetteFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, color.a ));"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i._sectionPlanesState,r=s.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching silhouette 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"),i.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),r){for(n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;"),e=0,t=s.getNumAllocatedSectionPlanes();e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var o=0,a=s.getNumAllocatedSectionPlanes();o sliceThickness) { "),n.push(" discard;"),n.push(" }"),n.push(" if (dist > 0.0) { "),n.push(" newColor = sliceColor;"),n.push(" }"),n.push("}")}return i.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = newColor;"),n.push("}"),n}}]),i}(),_o=function(e){g(i,fo);var t=_(i);function i(e){return x(this,i),t.call(this,e,!1,{instancing:!1,edges:!0})}return C(i)}(),yo=function(e){g(i,_o);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// EdgesEmphasisRenderer vertex shader"),i.push("uniform int renderPass;"),i.push("uniform vec4 color;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int edgeFlag = int(flags) >> 8 & 0xF;"),i.push("if (edgeFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vColor = vec4(color.r, color.g, color.b, color.a);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// EdgesEmphasisRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vColor;"),s.push("}"),s}}]),i}(),bo=function(e){g(i,_o);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!1})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Batched geometry edges drawing vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int edgeFlag = int(flags) >> 8 & 0xF;"),i.push("if (edgeFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry edges drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vColor;"),s.push("}"),s}}]),i}(),Bo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Batched geometry picking vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 pickColor;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),this._addRemapClipPosLines(i),i.push("out vec4 vPickColor;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry picking fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vPickColor; "),s.push("}"),s}}]),i}(),wo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching pick depth vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),this._addRemapClipPosLines(i),i.push("out vec4 vViewPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vViewPosition = viewPosition;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform float pickZNear;"),s.push("uniform float pickZFar;"),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),s.push(" outColor = packDepth(zNormalizedDepth); "),s.push("}"),s}}]),i}(),xo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching pick normals vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec3 normal;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),this._addRemapClipPosLines(i,3),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),i.push("vec3 octDecode(vec2 oct) {"),i.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),i.push(" if (v.z < 0.0) {"),i.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),i.push(" }"),i.push(" return normalize(v);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec3 vWorldNormal;"),i.push("out vec4 outColor;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vec3 worldNormal = octDecode(normal.xy); "),i.push(" vWorldNormal = worldNormal;"),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching pick normals fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outNormal = ivec4(vWorldNormal * float(".concat($.MAX_INT,"), 1.0);")),s.push("}"),s}}]),i}(),Po=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching occlusion vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 color;"),i.push("in float flags;"),this._addMatricesUniformBlockLines(i),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),i.push("}"),i}}]),i}(),Co=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching depth vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec2 vHighPrecisionZW;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vHighPrecisionZW = gl_Position.zw;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching depth fragment shader"),s.push("precision highp float;"),s.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),s.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),s.push("}"),s}}]),i}(),Mo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Batched geometry normals vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec3 normal;"),i.push("in vec4 color;"),i.push("in float flags;"),this._addMatricesUniformBlockLines(i,!0),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),i.push("vec3 octDecode(vec2 oct) {"),i.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),i.push(" if (v.z < 0.0) {"),i.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),i.push(" }"),i.push(" return normalize(v);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec3 vViewNormal;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),i.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push(" vViewNormal = viewNormal;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry normals fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),s.push("}"),s}}]),i}(),Fo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Batched geometry shadow vertex shader"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 color;"),i.push("in float flags;"),i.push("uniform mat4 shadowViewMatrix;"),i.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(i),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vViewPosition;"),i.push("out vec4 outColor;"),i.push("void main(void) {"),i.push(" int colorFlag = int(flags) & 0xF;"),i.push(" bool visible = (colorFlag > 0);"),i.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),i.push(" if (!visible || transparent) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push(" vViewPosition = viewPosition;"),i.push(" gl_Position = shadowProjMatrix * viewPosition;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Batched geometry shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" outColor = encodeFloat( gl_FragCoord.z); "),i.push("}"),i}}]),i}(),Eo=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=e._lightsState,s=t.getNumAllocatedSectionPlanes()>0,r=t.clippingCaps,n=[];return n.push("#version 300 es"),n.push("// Triangles batching quality draw vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in vec2 uv;"),n.push("in vec2 metallicRoughness;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n,!0),n.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),n.push("out vec4 vViewPosition;"),n.push("out vec3 vViewNormal;"),n.push("out vec4 vColor;"),n.push("out vec2 vUV;"),n.push("out vec2 vMetallicRoughness;"),i.lightMaps.length>0&&n.push("out vec3 vWorldNormal;"),s&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;"),r&&n.push("out vec4 vClipPosition;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("vFragDepth = 1.0 + clipPos.w;")),s&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;"),r&&n.push("vClipPosition = clipPos;")),n.push("vViewPosition = viewPosition;"),n.push("vViewNormal = viewNormal;"),n.push("vColor = color;"),n.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),n.push("vMetallicRoughness = metallicRoughness;"),i.lightMaps.length>0&&n.push("vWorldNormal = worldNormal.xyz;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,i=e._sectionPlanesState,s=e._lightsState,r=i.getNumAllocatedSectionPlanes()>0,n=i.clippingCaps,o=[];o.push("#version 300 es"),o.push("// Triangles batching quality draw fragment shader"),o.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),o.push("precision highp float;"),o.push("precision highp int;"),o.push("#else"),o.push("precision mediump float;"),o.push("precision mediump int;"),o.push("#endif"),e.logarithmicDepthBufferEnabled&&(o.push("in float isPerspective;"),o.push("uniform float logDepthBufFC;"),o.push("in float vFragDepth;")),o.push("uniform sampler2D uColorMap;"),o.push("uniform sampler2D uMetallicRoughMap;"),o.push("uniform sampler2D uEmissiveMap;"),o.push("uniform sampler2D uNormalMap;"),o.push("uniform sampler2D uAOMap;"),o.push("in vec4 vViewPosition;"),o.push("in vec3 vViewNormal;"),o.push("in vec4 vColor;"),o.push("in vec2 vUV;"),o.push("in vec2 vMetallicRoughness;"),s.lightMaps.length>0&&o.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(o,!0),s.reflectionMaps.length>0&&o.push("uniform samplerCube reflectionMap;"),s.lightMaps.length>0&&o.push("uniform samplerCube lightMap;"),o.push("uniform vec4 lightAmbient;");for(var a=0,l=s.lights.length;a0&&(o.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),o.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),o.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),o.push(" return envMapColor;"),o.push("}")),o.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),o.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),o.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),o.push("}"),o.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),o.push(" float a2 = ( alpha * alpha );"),o.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),o.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),o.push(" return 1.0 / ( gl * gv );"),o.push("}"),o.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),o.push(" float a2 = ( alpha * alpha );"),o.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),o.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),o.push(" return 0.5 / max( gv + gl, EPSILON );"),o.push("}"),o.push("float D_GGX(const in float alpha, const in float dotNH) {"),o.push(" float a2 = ( alpha * alpha );"),o.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),o.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),o.push("}"),o.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),o.push(" float alpha = ( roughness * roughness );"),o.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),o.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),o.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),o.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),o.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),o.push(" vec3 F = F_Schlick( specularColor, dotLH );"),o.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),o.push(" float D = D_GGX( alpha, dotNH );"),o.push(" return F * (G * D);"),o.push("}"),o.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),o.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),o.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),o.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),o.push(" vec4 r = roughness * c0 + c1;"),o.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),o.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),o.push(" return specularColor * AB.x + AB.y;"),o.push("}"),(s.lightMaps.length>0||s.reflectionMaps.length>0)&&(o.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),s.lightMaps.length>0&&(o.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),o.push(" irradiance *= PI;"),o.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),o.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),s.reflectionMaps.length>0&&(o.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),o.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),o.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),o.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),o.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),o.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),o.push("}")),o.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),o.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),o.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),o.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),o.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),o.push("}"),o.push("out vec4 outColor;"),o.push("void main(void) {"),r){o.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),o.push(" if (clippable) {"),o.push(" float dist = 0.0;");for(var h=0,d=i.getNumAllocatedSectionPlanes();h (0.002 * vClipPosition.w)) {"),o.push(" discard;"),o.push(" }"),o.push(" if (dist > 0.0) { "),o.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&o.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),o.push(" return;"),o.push("}")):(o.push(" if (dist > 0.0) { "),o.push(" discard;"),o.push(" }")),o.push("}")}o.push("IncidentLight light;"),o.push("Material material;"),o.push("Geometry geometry;"),o.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),o.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),o.push("float opacity = float(vColor.a) / 255.0;"),o.push("vec3 baseColor = rgb;"),o.push("float specularF0 = 1.0;"),o.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),o.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),o.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),o.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),o.push("baseColor *= colorTexel.rgb;"),o.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),o.push("metallic *= metalRoughTexel.b;"),o.push("roughness *= metalRoughTexel.g;"),o.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),o.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),o.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),o.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),o.push("geometry.position = vViewPosition.xyz;"),o.push("geometry.viewNormal = -normalize(viewNormal);"),o.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),s.lightMaps.length>0&&o.push("geometry.worldNormal = normalize(vWorldNormal);"),(s.lightMaps.length>0||s.reflectionMaps.length>0)&&o.push("computePBRLightMapping(geometry, material, reflectedLight);");for(var p=0,f=s.lights.length;p0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching pick flat normals vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),this._addRemapClipPosLines(i,3),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching pick flat normals fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("in vec4 vWorldPosition;"),i){s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),s.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),s.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),s.push(" outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),s.push("}"),s}}]),i}(),Io=function(e){g(i,fo);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Triangles batching color texture vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("in vec2 uv;"),i.push("in float flags;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),this._addMatricesUniformBlockLines(i),i.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vViewPosition;"),i.push("out vec4 vColor;"),i.push("out vec2 vUV;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push("worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vViewPosition = viewPosition;"),i.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),i.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,i=e._lightsState,s=e._sectionPlanesState,r=s.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching color texture 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("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform sampler2D uColorMap;"),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),n.push("uniform float gammaFactor;"),n.push("vec4 linearToLinear( in vec4 value ) {"),n.push(" return value;"),n.push("}"),n.push("vec4 sRGBToLinear( in vec4 value ) {"),n.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),n.push("}"),n.push("vec4 gammaToLinear( in vec4 value) {"),n.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),n.push("}"),t&&(n.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),n.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),n.push("}")),r){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var o=0,a=s.getNumAllocatedSectionPlanes();o> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var c=0,h=s.getNumAllocatedSectionPlanes();c sliceThickness) { "),n.push(" discard;"),n.push(" }"),n.push(" if (dist > 0.0) { "),n.push(" newColor = sliceColor;"),n.push(" }"),n.push("}")}n.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),n.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),n.push("float lambertian = 1.0;"),n.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),n.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),n.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var d=0,p=i.lights.length;d0,i=[];return i.push("#version 300 es"),i.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec4 pickColor;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vPickColor = pickColor;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),i.push("vec3 xTangent = dFdx( vWorldPosition.xyz );"),i.push("vec3 yTangent = dFdy( vWorldPosition.xyz );"),i.push("vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),i.push("outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Oo=$.vec3(),No=$.vec3(),Qo=$.vec3(),Vo=$.vec3(),Ho=$.mat4(),jo=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f,v=Oo;if(v[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,v[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,v[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(v[0]),e.snapPickCoordinateScale[1]=$.safeInv(v[1]),e.snapPickCoordinateScale[2]=$.safeInv(v[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var g=No;if(l){var m=Qo;$.transformPoint3(A,l,m),g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],p=Re(d,g,Ho),(f=Vo)[0]=n.eye[0]-g[0],f[1]=n.eye[1]-g[1],f[2]=n.eye[2]-g[2],e.snapPickOrigin[0]=g[0],e.snapPickOrigin[1]=g[1],e.snapPickOrigin[2]=g[2]}else p=d,f=n.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,v),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var _=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,_+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,_+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,_+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var y=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,y),this.setSectionPlanesStateUniforms(t),"edge"===e.snapMode?(a.edgeIndicesBuf.bind(),o.drawElements(o.LINES,a.edgeIndicesBuf.numItems,a.edgeIndicesBuf.itemType,0),a.edgeIndicesBuf.unbind()):o.drawArrays(o.POINTS,0,a.positionsBuf.numItems)}}},{key:"_allocate",value:function(){f(B(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0;e.pointsMaterial._state;var i=[];return i.push("#version 300 es"),i.push("// SnapBatchingDepthRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// SnapBatchingDepthRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Go=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorTextureRenderer&&!this._colorTextureRenderer.getValid()&&(this._colorTextureRenderer.destroy(),this._colorTextureRenderer=null),this._colorTextureRendererWithSAO&&!this._colorTextureRendererWithSAO.getValid()&&(this._colorTextureRendererWithSAO.destroy(),this._colorTextureRendererWithSAO=null),this._pbrRenderer&&!this._pbrRenderer.getValid()&&(this._pbrRenderer.destroy(),this._pbrRenderer=null),this._pbrRendererWithSAO&&!this._pbrRendererWithSAO.getValid()&&(this._pbrRendererWithSAO.destroy(),this._pbrRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null)}},{key:"eagerCreateRenders",value:function(){this._silhouetteRenderer||(this._silhouetteRenderer=new mo(this._scene)),this._pickMeshRenderer||(this._pickMeshRenderer=new Bo(this._scene)),this._pickDepthRenderer||(this._pickDepthRenderer=new wo(this._scene)),this._snapInitRenderer||(this._snapInitRenderer=new Uo(this._scene,!1)),this._snapRenderer||(this._snapRenderer=new jo(this._scene))}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new vo(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new vo(this._scene,!0)),this._colorRendererWithSAO}},{key:"flatColorRenderer",get:function(){return this._flatColorRenderer||(this._flatColorRenderer=new go(this._scene,!1)),this._flatColorRenderer}},{key:"flatColorRendererWithSAO",get:function(){return this._flatColorRendererWithSAO||(this._flatColorRendererWithSAO=new go(this._scene,!0)),this._flatColorRendererWithSAO}},{key:"colorTextureRenderer",get:function(){return this._colorTextureRenderer||(this._colorTextureRenderer=new Io(this._scene,!1)),this._colorTextureRenderer}},{key:"colorTextureRendererWithSAO",get:function(){return this._colorTextureRendererWithSAO||(this._colorTextureRendererWithSAO=new Io(this._scene,!0)),this._colorTextureRendererWithSAO}},{key:"pbrRenderer",get:function(){return this._pbrRenderer||(this._pbrRenderer=new Eo(this._scene,!1)),this._pbrRenderer}},{key:"pbrRendererWithSAO",get:function(){return this._pbrRendererWithSAO||(this._pbrRendererWithSAO=new Eo(this._scene,!0)),this._pbrRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new mo(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new Co(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new Mo(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new yo(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new bo(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Bo(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new xo(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new ko(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new wo(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Po(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new Fo(this._scene)),this._shadowRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new jo(this._scene)),this._snapRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new Uo(this._scene)),this._snapInitRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._colorTextureRenderer&&this._colorTextureRenderer.destroy(),this._colorTextureRendererWithSAO&&this._colorTextureRendererWithSAO.destroy(),this._pbrRenderer&&this._pbrRenderer.destroy(),this._pbrRendererWithSAO&&this._pbrRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy()}}]),e}(),zo={};var Wo=65536,Ko=5e6,Xo=function(){function e(){x(this,e)}return C(e,[{key:"doublePrecisionEnabled",get:function(){return $.getDoublePrecisionEnabled()},set:function(e){$.setDoublePrecisionEnabled(e)}},{key:"maxDataTextureHeight",get:function(){return Wo},set:function(e){(e=1024*Math.ceil(e/1024))>4096?e=4096:e<1024&&(e=1024),Wo=e}},{key:"maxGeometryBatchSize",get:function(){return Ko},set:function(e){e<1e5?e=1e5:e>5e6&&(e=5e6),Ko=e}}]),e}(),Jo=new Xo,Yo=C((function e(){x(this,e),this.maxVerts=Jo.maxGeometryBatchSize,this.maxIndices=3*Jo.maxGeometryBatchSize,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]})),Zo=$.mat4(),qo=$.mat4();function $o(e,t,i){for(var s=e.length,r=new Uint16Array(s),n=t[0],o=t[1],a=t[2],l=t[3]-n,u=t[4]-o,A=t[5]-a,c=65525,h=c/l,d=c/u,p=c/A,f=function(e){return e>=0?e:0},v=0;v=0?1:-1),o=(1-Math.abs(s))*(r>=0?1:-1),s=n,r=o}return new Int8Array([Math[t](127.5*s+(s<0?-1:0)),Math[i](127.5*r+(r<0?-1:0))])}function ia(e){var t=e[0],i=e[1];t/=t<0?127:128,i/=i<0?127:128;var s=1-Math.abs(t)-Math.abs(i);s<0&&(t=(1-Math.abs(i))*(t>=0?1:-1),i=(1-Math.abs(t))*(i>=0?1:-1));var r=Math.sqrt(t*t+i*i+s*s);return[t/r,i/r,s/r]}var sa=$.mat4(),ra=$.mat4(),na=$.vec4([0,0,0,1]),oa=$.vec3(),aa=$.vec3(),la=$.vec3(),ua=$.vec3(),Aa=$.vec3(),ca=$.vec3(),ha=$.vec3(),da=function(){function e(t){var i,s,r;x(this,e),console.info("Creating VBOBatchingTrianglesLayer"),this.model=t.model,this.sortId="TrianglesBatchingLayer"+(t.solid?"-solid":"-surface")+(t.autoNormals?"-autonormals":"-normals")+(t.textureSet&&t.textureSet.colorTexture?"-colorTexture":"")+(t.textureSet&&t.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=t.layerIndex,this._renderers=(i=t.model.scene,s=i.id,(r=zo[s])||(r=new Go(i),zo[s]=r,r._compile(),r.eagerCreateRenders(),i.on("compile",(function(){r._compile(),r.eagerCreateRenders()})),i.on("destroyed",(function(){delete zo[s],r._destroy()}))),r),this._buffer=new Yo(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new Zt({origin:$.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:t.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=$.collapseAABB3(),this._portions=[],this._meshes=[],this._numVerts=0,this._aabb=$.collapseAABB3(),this.aabbDirty=!0,this._finalized=!1,t.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=$.mat4(t.positionsDecodeMatrix)),t.uvDecodeMatrix?(this._state.uvDecodeMatrix=$.mat3(t.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,t.origin&&this._state.origin.set(t.origin),this.solid=!!t.solid}return C(e,[{key:"aabb",get:function(){if(this.aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._meshes.length;e0)for(var C=0,M=o.length;C0){var F=sa;g?$.inverseMat4($.transposeMat4(g,ra),F):$.identityMat4(F,F),function(e,t,i,s,r){function n(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}var o,a,l,u,A,c=new Float32Array([0,0,0,0]),h=new Float32Array([0,0,0,0]);for(A=0;Au&&(a=o,u=l),(l=n(h,ia(o=ta(h,"floor","ceil"))))>u&&(a=o,u=l),(l=n(h,ia(o=ta(h,"ceil","ceil"))))>u&&(a=o,u=l),s[r+A+0]=a[0],s[r+A+1]=a[1],s[r+A+2]=0}(F,n,n.length,y.normals,y.normals.length)}if(u)for(var E=0,k=u.length;E0)for(var V=0,H=a.length;V0)for(var j=0,G=l.length;j0){var s=this._state.positionsDecodeMatrix?new Uint16Array(i.positions):$o(i.positions,this._modelAABB,this._state.positionsDecodeMatrix=$.mat4());if(e.positionsBuf=new It(t,t.ARRAY_BUFFER,s,s.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(var r=0,n=this._portions.length;r0){var u=new Int8Array(i.normals);e.normalsBuf=new It(t,t.ARRAY_BUFFER,u,i.normals.length,3,t.STATIC_DRAW,!0)}if(i.colors.length>0){var A=new Uint8Array(i.colors);e.colorsBuf=new It(t,t.ARRAY_BUFFER,A,i.colors.length,4,t.DYNAMIC_DRAW,!1)}if(i.uv.length>0)if(e.uvDecodeMatrix){e.uvBuf=new It(t,t.ARRAY_BUFFER,i.uv,i.uv.length,2,t.STATIC_DRAW,!1)}else{var c=ki.getUVBounds(i.uv),h=ki.compressUVs(i.uv,c.min,c.max),d=h.quantized;e.uvDecodeMatrix=$.mat3(h.decodeMatrix),e.uvBuf=new It(t,t.ARRAY_BUFFER,d,d.length,2,t.STATIC_DRAW,!1)}if(i.metallicRoughness.length>0){var p=new Uint8Array(i.metallicRoughness);e.metallicRoughnessBuf=new It(t,t.ARRAY_BUFFER,p,i.metallicRoughness.length,2,t.STATIC_DRAW,!1)}if(i.positions.length>0){var f=i.positions.length/3,v=new Float32Array(f);e.flagsBuf=new It(t,t.ARRAY_BUFFER,v,v.length,1,t.DYNAMIC_DRAW,!1)}if(i.pickColors.length>0){var g=new Uint8Array(i.pickColors);e.pickColorsBuf=new It(t,t.ARRAY_BUFFER,g,i.pickColors.length,4,t.STATIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&i.offsets.length>0){var m=new Float32Array(i.offsets);e.offsetsBuf=new It(t,t.ARRAY_BUFFER,m,i.offsets.length,3,t.DYNAMIC_DRAW)}if(i.indices.length>0){var _=new Uint32Array(i.indices);e.indicesBuf=new It(t,t.ELEMENT_ARRAY_BUFFER,_,i.indices.length,1,t.STATIC_DRAW)}if(i.edgeIndices.length>0){var y=new Uint32Array(i.edgeIndices);e.edgeIndicesBuf=new It(t,t.ELEMENT_ARRAY_BUFFER,y,i.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}}},{key:"isEmpty",value:function(){return!this._state.indicesBuf}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Xe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,i,!0)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags()}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Xe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,i)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var i=e,s=this._portions[i],r=4*s.vertsBaseIndex,n=4*s.numVerts,o=this._scratchMemory.getUInt8Array(n),a=t[0],l=t[1],u=t[2],A=t[3],c=0;c3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var r,n,o=e,a=this._portions[o],l=a.vertsBaseIndex,u=a.numVerts,A=l,c=u,h=!!(t&Qe),d=!!(t&ze),p=!!(t&We),f=!!(t&Ke),v=!!(t&Xe),g=!!(t&He),m=!!(t&Ve);r=!h||m||d||p&&!this.model.scene.highlightMaterial.glowThrough||f&&!this.model.scene.selectedMaterial.glowThrough?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,n=!h||m?oo.NOT_RENDERED:f?oo.SILHOUETTE_SELECTED:p?oo.SILHOUETTE_HIGHLIGHTED:d?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED;var _=0;_=!h||m?oo.NOT_RENDERED:f?oo.EDGES_SELECTED:p?oo.EDGES_HIGHLIGHTED:d?oo.EDGES_XRAYED:v?i?oo.EDGES_COLOR_TRANSPARENT:oo.EDGES_COLOR_OPAQUE:oo.NOT_RENDERED;var y=h&&!m&&g?oo.PICK:oo.NOT_RENDERED,b=t&je?1:0;if(s){this._deferredFlagValues||(this._deferredFlagValues=new Float32Array(this._numVerts));for(var B=A,w=A+c;Bg)&&(g=x,s.set(m),r&&$.triangleNormal(d,p,f,r),v=!0)}}return v&&r&&($.transformVec3(this.model.worldNormalMatrix,r,r),$.normalizeVec3(r)),v}},{key:"destroy",value:function(){var e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}]),e}(),pa=function(e){g(i,po);var t=_(i);function i(e,s){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.edges,o=void 0!==n&&n;return x(this,i),t.call(this,e,s,{instancing:!0,edges:o})}return C(i,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,i=e.state,s=e.frameCtx,r=e.incrementDrawState;this._edges?t.drawElementsInstanced(t.LINES,i.edgeIndicesBuf.numItems,i.edgeIndicesBuf.itemType,0,i.numInstances):(t.drawElementsInstanced(t.TRIANGLES,i.indicesBuf.numItems,i.indicesBuf.itemType,0,i.numInstances),r&&s.drawElements++)}}]),i}(),fa=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e,t,i,s=this._scene,r=s._sectionPlanesState,n=s._lightsState,o=r.getNumAllocatedSectionPlanes()>0,a=[];for(a.push("#version 300 es"),a.push("// Instancing geometry drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec2 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),s.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),s.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;"),e=0,t=n.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),o&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),s.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),a.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),e=0,t=n.lights.length;e0,s=[];if(s.push("#version 300 es"),s.push("// Instancing geometry drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o sliceThickness) { "),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" newColor = sliceColor;"),s.push(" }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(s.push(" float viewportWidth = uSAOParams[0];"),s.push(" float viewportHeight = uSAOParams[1];"),s.push(" float blendCutoff = uSAOParams[2];"),s.push(" float blendFactor = uSAOParams[3];"),s.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),s.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),s.push(" outColor = vec4(newColor.rgb * ambient, 1.0);")):s.push(" outColor = newColor;"),s.push("}"),s}}]),i}(),va=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry flat-shading drawing vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("in float flags;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vViewPosition;"),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vViewPosition = viewPosition;"),i.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i._sectionPlanesState,r=i._lightsState,n=s.getNumAllocatedSectionPlanes()>0,o=[];if(o.push("#version 300 es"),o.push("// Instancing geometry flat-shading drawing fragment shader"),o.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),o.push("precision highp float;"),o.push("precision highp int;"),o.push("#else"),o.push("precision mediump float;"),o.push("precision mediump int;"),o.push("#endif"),i.logarithmicDepthBufferEnabled&&(o.push("in float isPerspective;"),o.push("uniform float logDepthBufFC;"),o.push("in float vFragDepth;")),this._withSAO&&(o.push("uniform sampler2D uOcclusionTexture;"),o.push("uniform vec4 uSAOParams;"),o.push("const float packUpscale = 256. / 255.;"),o.push("const float unpackDownScale = 255. / 256.;"),o.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),o.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),o.push("float unpackRGBToFloat( const in vec4 v ) {"),o.push(" return dot( v, unPackFactors );"),o.push("}")),n){o.push("in vec4 vWorldPosition;"),o.push("in float vFlags;");for(var a=0,l=s.getNumAllocatedSectionPlanes();a> 16 & 0xF) == 1;"),o.push(" if (clippable) {"),o.push(" float dist = 0.0;");for(var A=0,c=s.getNumAllocatedSectionPlanes();A sliceThickness) { "),o.push(" discard;"),o.push(" }"),o.push(" if (dist > 0.0) { "),o.push(" newColor = sliceColor;"),o.push(" }"),o.push("}")}for(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),o.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),o.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),o.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),e=0,t=r.lights.length;e0,i=[];return i.push("#version 300 es"),i.push("// Instancing silhouette vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 color;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),i.push("if (silhouetteFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Instancing fill fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o sliceThickness) { "),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" newColor = sliceColor;"),s.push(" }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = newColor;"),s.push("}"),s}}]),i}(),ma=function(e){g(i,pa);var t=_(i);function i(e,s){return x(this,i),t.call(this,e,s,{instancing:!0,edges:!0})}return C(i)}(),_a=function(e){g(i,ma);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// EdgesEmphasisRenderer vertex shader"),i.push("uniform int renderPass;"),i.push("uniform vec4 color;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int edgeFlag = int(flags) >> 8 & 0xF;"),i.push("if (edgeFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = worldMatrix * positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vColor = vec4(color.r, color.g, color.b, color.a);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// EdgesEmphasisRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vColor;"),s.push("}"),s}}]),i}(),ya=function(e){g(i,ma);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!1})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// EdgesColorRenderer vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int edgeFlag = int(flags) >> 8 & 0xF;"),i.push("if (edgeFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// EdgesColorRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vColor;"),s.push("}"),s}}]),i}(),ba=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry picking vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 pickColor;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),this._addRemapClipPosLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vPickColor;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry picking fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vPickColor; "),s.push("}"),s}}]),i}(),Ba=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry depth vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),this._addRemapClipPosLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vViewPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push(" vViewPosition = viewPosition;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform float pickZNear;"),s.push("uniform float pickZFar;"),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),s.push(" outColor = packDepth(zNormalizedDepth); "),s.push("}"),s}}]),i}(),wa=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry normals vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec2 normal;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("in vec4 modelNormalMatrixCol0;"),i.push("in vec4 modelNormalMatrixCol1;"),i.push("in vec4 modelNormalMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),this._addRemapClipPosLines(i,3),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),i.push("vec3 octDecode(vec2 oct) {"),i.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),i.push(" if (v.z < 0.0) {"),i.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),i.push(" }"),i.push(" return normalize(v);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec3 vWorldNormal;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),i.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),i.push(" vWorldNormal = worldNormal;"),t&&(i.push(" vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry normals fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outNormal = ivec4(vWorldNormal * float(".concat($.MAX_INT,"), 1.0);")),s.push("}"),s}}]),i}(),xa=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// TrianglesInstancingOcclusionRenderer vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 color;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// TrianglesInstancingOcclusionRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),i.push("}"),i}}]),i}(),Pa=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry depth drawing vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec2 vHighPrecisionZW;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vHighPrecisionZW = gl_Position.zw;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i._sectionPlanesState,r=s.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("precision highp float;"),n.push("precision highp int;"),i.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),r)for(n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;"),e=0,t=s.getNumAllocatedSectionPlanes();e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;"),e=0,t=s.getNumAllocatedSectionPlanes();e 0.0) { discard; }"),n.push("}")}return i.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}}]),i}(),Ca=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry normals drawing vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec3 normal;"),i.push("in vec4 color;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i,!0),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),i.push("vec3 octDecode(vec2 oct) {"),i.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),i.push(" if (v.z < 0.0) {"),i.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),i.push(" }"),i.push(" return normalize(v);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec3 vViewNormal;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),i.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push(" vViewNormal = viewNormal;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Instancing geometry depth drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),s.push("}"),s}}]),i}(),Ma=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry shadow drawing vertex shader"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 color;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform mat4 shadowViewMatrix;"),i.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(i),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("bool visible = (colorFlag > 0);"),i.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),i.push("if (!visible || transparent) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push(" gl_Position = shadowProjMatrix * viewPosition;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Instancing geometry depth drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),s.push("}"),s}}]),i}(),Fa={3e3:"linearToLinear",3001:"sRGBToLinear"},Ea=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=e._lightsState,s=t.getNumAllocatedSectionPlanes()>0,r=t.clippingCaps,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry quality drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in vec2 uv;"),n.push("in vec2 metallicRoughness;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("in vec4 modelNormalMatrixCol0;"),n.push("in vec4 modelNormalMatrixCol1;"),n.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(n,!0),n.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),n.push("out vec4 vViewPosition;"),n.push("out vec3 vViewNormal;"),n.push("out vec4 vColor;"),n.push("out vec2 vUV;"),n.push("out vec2 vMetallicRoughness;"),i.lightMaps.length>0&&n.push("out vec3 vWorldNormal;"),s&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;"),r&&n.push("out vec4 vClipPosition;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),n.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),n.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;"),r&&n.push("vClipPosition = clipPos;")),n.push("vViewPosition = viewPosition;"),n.push("vViewNormal = viewNormal;"),n.push("vColor = color;"),n.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),n.push("vMetallicRoughness = metallicRoughness;"),i.lightMaps.length>0&&n.push("vWorldNormal = worldNormal.xyz;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,i=e._sectionPlanesState,s=e._lightsState,r=i.getNumAllocatedSectionPlanes()>0,n=i.clippingCaps,o=[];o.push("#version 300 es"),o.push("// Instancing geometry quality drawing fragment shader"),o.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),o.push("precision highp float;"),o.push("precision highp int;"),o.push("#else"),o.push("precision mediump float;"),o.push("precision mediump int;"),o.push("#endif"),e.logarithmicDepthBufferEnabled&&(o.push("in float isPerspective;"),o.push("uniform float logDepthBufFC;"),o.push("in float vFragDepth;")),o.push("uniform sampler2D uColorMap;"),o.push("uniform sampler2D uMetallicRoughMap;"),o.push("uniform sampler2D uEmissiveMap;"),o.push("uniform sampler2D uNormalMap;"),this._withSAO&&(o.push("uniform sampler2D uOcclusionTexture;"),o.push("uniform vec4 uSAOParams;"),o.push("const float packUpscale = 256. / 255.;"),o.push("const float unpackDownScale = 255. / 256.;"),o.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),o.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),o.push("float unpackRGBToFloat( const in vec4 v ) {"),o.push(" return dot( v, unPackFactors );"),o.push("}")),s.reflectionMaps.length>0&&o.push("uniform samplerCube reflectionMap;"),s.lightMaps.length>0&&o.push("uniform samplerCube lightMap;"),o.push("uniform vec4 lightAmbient;");for(var a=0,l=s.lights.length;a0&&o.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(o,!0),o.push("#define PI 3.14159265359"),o.push("#define RECIPROCAL_PI 0.31830988618"),o.push("#define RECIPROCAL_PI2 0.15915494"),o.push("#define EPSILON 1e-6"),o.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),o.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),o.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),o.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),o.push(" return normalize(surf_norm );"),o.push(" }"),o.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),o.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),o.push(" vec2 st0 = dFdx( uv.st );"),o.push(" vec2 st1 = dFdy( uv.st );"),o.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),o.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),o.push(" vec3 N = normalize( surf_norm );"),o.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),o.push(" mat3 tsn = mat3( S, T, N );"),o.push(" return normalize( tsn * mapN );"),o.push("}"),o.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),o.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),o.push("}"),o.push("struct IncidentLight {"),o.push(" vec3 color;"),o.push(" vec3 direction;"),o.push("};"),o.push("struct ReflectedLight {"),o.push(" vec3 diffuse;"),o.push(" vec3 specular;"),o.push("};"),o.push("struct Geometry {"),o.push(" vec3 position;"),o.push(" vec3 viewNormal;"),o.push(" vec3 worldNormal;"),o.push(" vec3 viewEyeDir;"),o.push("};"),o.push("struct Material {"),o.push(" vec3 diffuseColor;"),o.push(" float specularRoughness;"),o.push(" vec3 specularColor;"),o.push(" float shine;"),o.push("};"),o.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),o.push(" float r = ggxRoughness + 0.0001;"),o.push(" return (2.0 / (r * r) - 2.0);"),o.push("}"),o.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),o.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),o.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),o.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),o.push("}"),s.reflectionMaps.length>0&&(o.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),o.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),o.push(" vec3 envMapColor = "+Fa[s.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),o.push(" return envMapColor;"),o.push("}")),o.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),o.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),o.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),o.push("}"),o.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),o.push(" float a2 = ( alpha * alpha );"),o.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),o.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),o.push(" return 1.0 / ( gl * gv );"),o.push("}"),o.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),o.push(" float a2 = ( alpha * alpha );"),o.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),o.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),o.push(" return 0.5 / max( gv + gl, EPSILON );"),o.push("}"),o.push("float D_GGX(const in float alpha, const in float dotNH) {"),o.push(" float a2 = ( alpha * alpha );"),o.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),o.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),o.push("}"),o.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),o.push(" float alpha = ( roughness * roughness );"),o.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),o.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),o.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),o.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),o.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),o.push(" vec3 F = F_Schlick( specularColor, dotLH );"),o.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),o.push(" float D = D_GGX( alpha, dotNH );"),o.push(" return F * (G * D);"),o.push("}"),o.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),o.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),o.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),o.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),o.push(" vec4 r = roughness * c0 + c1;"),o.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),o.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),o.push(" return specularColor * AB.x + AB.y;"),o.push("}"),(s.lightMaps.length>0||s.reflectionMaps.length>0)&&(o.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),s.lightMaps.length>0&&(o.push(" vec3 irradiance = "+Fa[s.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),o.push(" irradiance *= PI;"),o.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),o.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),s.reflectionMaps.length>0&&(o.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),o.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),o.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),o.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),o.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),o.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),o.push("}")),o.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),o.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),o.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),o.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),o.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),o.push("}"),o.push("out vec4 outColor;"),o.push("void main(void) {"),r){o.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),o.push(" if (clippable) {"),o.push(" float dist = 0.0;");for(var h=0,d=i.getNumAllocatedSectionPlanes();h (0.002 * vClipPosition.w)) {"),o.push(" discard;"),o.push(" }"),o.push(" if (dist > 0.0) { "),o.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&o.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),o.push(" return;"),o.push("}")):(o.push(" if (dist > 0.0) { "),o.push(" discard;"),o.push(" }")),o.push("}")}o.push("IncidentLight light;"),o.push("Material material;"),o.push("Geometry geometry;"),o.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),o.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),o.push("float opacity = float(vColor.a) / 255.0;"),o.push("vec3 baseColor = rgb;"),o.push("float specularF0 = 1.0;"),o.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),o.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),o.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),o.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),o.push("baseColor *= colorTexel.rgb;"),o.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),o.push("metallic *= metalRoughTexel.b;"),o.push("roughness *= metalRoughTexel.g;"),o.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),o.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),o.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),o.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),o.push("geometry.position = vViewPosition.xyz;"),o.push("geometry.viewNormal = -normalize(viewNormal);"),o.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),s.lightMaps.length>0&&o.push("geometry.worldNormal = normalize(vWorldNormal);"),(s.lightMaps.length>0||s.reflectionMaps.length>0)&&o.push("computePBRLightMapping(geometry, material, reflectedLight);");for(var p=0,f=s.lights.length;p0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry normals vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),this._addRemapClipPosLines(i,3),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&i.push("out float vFlags;"),i.push("out vec4 vWorldPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&i.push("vFlags = flags;"),i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry normals fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("in vec4 vWorldPosition;"),i){s.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),s.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),s.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),s.push(" outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),s.push("}"),s}}]),i}(),Ia=function(e){g(i,pa);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry drawing vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("in vec2 uv;"),i.push("in float flags;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),i.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vViewPosition;"),i.push("out vec4 vColor;"),i.push("out vec2 vUV;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vViewPosition = viewPosition;"),i.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),i.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i.gammaOutput,r=i._sectionPlanesState,n=i._lightsState,o=r.getNumAllocatedSectionPlanes()>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),i.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),s&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),o){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(var l=0,u=r.getNumAllocatedSectionPlanes();l> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(var c=0,h=r.getNumAllocatedSectionPlanes();c sliceThickness) { "),a.push(" discard;"),a.push(" }"),a.push(" if (dist > 0.0) { "),a.push(" newColor = sliceColor;"),a.push(" }"),a.push("}")}for(a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),e=0,t=n.lights.length;e0,i=[];return i.push("#version 300 es"),i.push("// SnapInstancingDepthBufInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec4 pickColor;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vPickColor = pickColor;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Points instancing pick depth fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),i.push("vec3 xTangent = dFdx( vWorldPosition.xyz );"),i.push("vec3 yTangent = dFdy( vWorldPosition.xyz );"),i.push("vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),i.push("outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Oa=$.vec3(),Na=$.vec3(),Qa=$.vec3(),Va=$.vec3(),Ha=$.mat4(),ja=function(e){g(i,po);var t=_(i);function i(e){return x(this,i),t.call(this,e,!1,{instancing:!0})}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f,v=Oa;if(v[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,v[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,v[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(v[0]),e.snapPickCoordinateScale[1]=$.safeInv(v[1]),e.snapPickCoordinateScale[2]=$.safeInv(v[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var g=Na;if(l){var m=$.transformPoint3(A,l,Qa);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],p=Re(d,g,Ha),(f=Va)[0]=n.eye[0]-g[0],f[1]=n.eye[1]-g[1],f[2]=n.eye[2]-g[2],e.snapPickOrigin[0]=g[0],e.snapPickOrigin[1]=g[1],e.snapPickOrigin[2]=g[2]}else p=d,f=n.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,v),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var _=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,_+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,_+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,_+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var y=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,y),this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(a.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(a.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(a.modelMatrixCol2Buf),o.vertexAttribDivisor(this._aModelMatrixCol0.location,1),o.vertexAttribDivisor(this._aModelMatrixCol1.location,1),o.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags.bindArrayBuffer(a.flagsBuf),o.vertexAttribDivisor(this._aFlags.location,1),"edge"===e.snapMode?(a.edgeIndicesBuf.bind(),o.drawElementsInstanced(o.LINES,a.edgeIndicesBuf.numItems,a.edgeIndicesBuf.itemType,0,a.numInstances),a.edgeIndicesBuf.unbind()):o.drawArraysInstanced(o.POINTS,0,a.positionsBuf.numItems,a.numInstances),o.vertexAttribDivisor(this._aModelMatrixCol0.location,0),o.vertexAttribDivisor(this._aModelMatrixCol1.location,0),o.vertexAttribDivisor(this._aModelMatrixCol2.location,0),o.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&o.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){f(B(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// SnapInstancingDepthRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// SnapInstancingDepthRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Ga=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._pbrRenderer&&!this._pbrRenderer.getValid()&&(this._pbrRenderer.destroy(),this._pbrRenderer=null),this._pbrRendererWithSAO&&!this._pbrRendererWithSAO.getValid()&&(this._pbrRendererWithSAO.destroy(),this._pbrRendererWithSAO=null),this._colorTextureRenderer&&!this._colorTextureRenderer.getValid()&&(this._colorTextureRenderer.destroy(),this._colorTextureRenderer=null),this._colorTextureRendererWithSAO&&!this._colorTextureRendererWithSAO.getValid()&&(this._colorTextureRendererWithSAO.destroy(),this._colorTextureRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null)}},{key:"eagerCreateRenders",value:function(){this._silhouetteRenderer||(this._silhouetteRenderer=new ga(this._scene)),this._pickMeshRenderer||(this._pickMeshRenderer=new ba(this._scene)),this._pickDepthRenderer||(this._pickDepthRenderer=new Ba(this._scene)),this._snapInitRenderer||(this._snapInitRenderer=new Ua(this._scene,!1)),this._snapRenderer||(this._snapRenderer=new ja(this._scene))}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new fa(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new fa(this._scene,!0)),this._colorRendererWithSAO}},{key:"flatColorRenderer",get:function(){return this._flatColorRenderer||(this._flatColorRenderer=new va(this._scene,!1)),this._flatColorRenderer}},{key:"flatColorRendererWithSAO",get:function(){return this._flatColorRendererWithSAO||(this._flatColorRendererWithSAO=new va(this._scene,!0)),this._flatColorRendererWithSAO}},{key:"pbrRenderer",get:function(){return this._pbrRenderer||(this._pbrRenderer=new Ea(this._scene,!1)),this._pbrRenderer}},{key:"pbrRendererWithSAO",get:function(){return this._pbrRendererWithSAO||(this._pbrRendererWithSAO=new Ea(this._scene,!0)),this._pbrRendererWithSAO}},{key:"colorTextureRenderer",get:function(){return this._colorTextureRenderer||(this._colorTextureRenderer=new Ia(this._scene,!1)),this._colorTextureRenderer}},{key:"colorTextureRendererWithSAO",get:function(){return this._colorTextureRendererWithSAO||(this._colorTextureRendererWithSAO=new Ia(this._scene,!0)),this._colorTextureRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ga(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new Pa(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new Ca(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new _a(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new ya(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new ba(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new wa(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new ka(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Ba(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new xa(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new Ma(this._scene)),this._shadowRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new Ua(this._scene,!1)),this._snapInitRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new ja(this._scene)),this._snapRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._pbrRenderer&&this._pbrRenderer.destroy(),this._pbrRendererWithSAO&&this._pbrRendererWithSAO.destroy(),this._colorTextureRenderer&&this._colorTextureRenderer.destroy(),this._colorTextureRendererWithSAO&&this._colorTextureRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy()}}]),e}(),za={};var Wa=new Uint8Array(4),Ka=new Float32Array(1),Xa=$.vec4([0,0,0,1]),Ja=new Float32Array(3),Ya=$.vec3(),Za=$.vec3(),qa=$.vec3(),$a=$.vec3(),el=$.vec3(),tl=$.vec3(),il=$.vec3(),sl=new Float32Array(4),rl=function(){function e(t){var i,s,r;x(this,e),console.info("Creating VBOInstancingTrianglesLayer"),this.model=t.model,this.sortId="TrianglesInstancingLayer"+(t.solid?"-solid":"-surface")+(t.normals?"-normals":"-autoNormals"),this.layerIndex=t.layerIndex,this._renderers=(i=t.model.scene,s=i.id,(r=za[s])||(r=new Ga(i),za[s]=r,r._compile(),r.eagerCreateRenders(),i.on("compile",(function(){r._compile(),r.eagerCreateRenders()})),i.on("destroyed",(function(){delete za[s],r._destroy()}))),r),this._aabb=$.collapseAABB3(),this._state=new Zt({numInstances:0,obb:$.OBB3(),origin:$.vec3(),geometry:t.geometry,textureSet:t.textureSet,pbrSupported:!1,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrix=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],this._meshes=[],this._aabb=$.collapseAABB3(),this.aabbDirty=!0,t.origin&&this._state.origin.set(t.origin),this._finalized=!1,this.solid=!!t.solid,this.numIndices=t.geometry.numIndices}return C(e,[{key:"aabb",get:function(){if(this.aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._meshes.length;e0){e.colorsBuf=new It(s,s.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,s.DYNAMIC_DRAW,!1),this._colors=[]}if(this._metallicRoughness.length>0){var o=new Uint8Array(this._metallicRoughness);e.metallicRoughnessBuf=new It(s,s.ARRAY_BUFFER,o,this._metallicRoughness.length,2,s.STATIC_DRAW,!1)}if(n>0){e.flagsBuf=new It(s,s.ARRAY_BUFFER,new Float32Array(n),n,1,s.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){e.offsetsBuf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,s.DYNAMIC_DRAW,!1),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){e.positionsBuf=new It(s,s.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,s.STATIC_DRAW,!1),e.positionsDecodeMatrix=$.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){var a=new Uint8Array(t.colorsCompressed);e.colorsBuf=new It(s,s.ARRAY_BUFFER,a,a.length,4,s.STATIC_DRAW,!1)}if(t.uvCompressed&&t.uvCompressed.length>0){var l=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new It(s,s.ARRAY_BUFFER,l,l.length,2,s.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new It(s,s.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,s.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new It(s,s.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,s.STATIC_DRAW)),this._modelMatrixCol0.length>0){var u=!1;e.modelMatrixCol0Buf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,s.STATIC_DRAW,u),e.modelMatrixCol1Buf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,s.STATIC_DRAW,u),e.modelMatrixCol2Buf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,s.STATIC_DRAW,u),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,s.STATIC_DRAW,u),e.modelNormalMatrixCol1Buf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,s.STATIC_DRAW,u),e.modelNormalMatrixCol2Buf=new It(s,s.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,s.STATIC_DRAW,u),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){e.pickColorsBuf=new It(s,s.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,s.STATIC_DRAW,!1),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&i&&i.colorTexture&&i.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!i&&!!i.colorTexture,this._state.geometry=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Xe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,i)}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Xe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,i)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";Wa[0]=t[0],Wa[1]=t[1],Wa[2]=t[2],Wa[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(Wa,4*e)}},{key:"setTransparent",value:function(e,t,i){i?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,i)}},{key:"_setFlags",value:function(e,t,i){if(!this._finalized)throw"Not finalized";var s=!!(t&Qe),r=!!(t&ze),n=!!(t&We),o=!!(t&Ke),a=!!(t&Xe),l=!!(t&He),u=!!(t&Ve),A=0;A|=!s||u||r||n&&!this.model.scene.highlightMaterial.glowThrough||o&&!this.model.scene.selectedMaterial.glowThrough?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,A|=(!s||u?oo.NOT_RENDERED:o?oo.SILHOUETTE_SELECTED:n?oo.SILHOUETTE_HIGHLIGHTED:r?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED)<<4,A|=(!s||u?oo.NOT_RENDERED:o?oo.EDGES_SELECTED:n?oo.EDGES_HIGHLIGHTED:r?oo.EDGES_XRAYED:a?i?oo.EDGES_COLOR_TRANSPARENT:oo.EDGES_COLOR_OPAQUE:oo.NOT_RENDERED)<<8,A|=(s&&!u&&l?oo.PICK:oo.NOT_RENDERED)<<12,A|=(t&je?1:0)<<16,Ka[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(Ka,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Ja[0]=t[0],Ja[1]=t[1],Ja[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Ja,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"getEachVertex",value:function(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;var i=this._state,s=i.geometry,r=this._portions[e];if(r)for(var n=s.quantizedPositions,o=i.origin,a=r.offset,l=o[0]+a[0],u=o[1]+a[1],A=o[2]+a[2],c=Xa,h=r.matrix,d=this.model.sceneModelMatrix,p=i.positionsDecodeMatrix,f=0,v=n.length;fm)&&(m=C,s.set(_),r&&$.triangleNormal(p,f,v,r),g=!0)}}return g&&r&&($.transformVec3(a.normalMatrix,r,r),$.transformVec3(this.model.worldNormalMatrix,r,r),$.normalizeVec3(r)),g}},{key:"destroy",value:function(){var e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}]),e}(),nl=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,i=e.state,s=e.frameCtx,r=e.incrementDrawState;t.drawElements(t.LINES,i.indicesBuf.numItems,i.indicesBuf.itemType,0),r&&s.drawElements++}}]),i}(),ol=function(e){g(i,nl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Lines batching color vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("in float flags;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push("worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Lines batching color fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return s.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),i}(),al=function(e){g(i,nl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Lines batching silhouette vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("void main(void) {"),i.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),i.push("if (silhouetteFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Lines batching silhouette fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = color;"),s.push("}"),s}}]),i}(),ll=$.vec3(),ul=$.vec3(),Al=$.vec3(),cl=$.vec3(),hl=$.mat4(),dl=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f,v=ll;if(v[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,v[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,v[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(v[0]),e.snapPickCoordinateScale[1]=$.safeInv(v[1]),e.snapPickCoordinateScale[2]=$.safeInv(v[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var g=ul;if(l){var m=Al;$.transformPoint3(A,l,m),g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],p=Re(d,g,hl),(f=cl)[0]=n.eye[0]-g[0],f[1]=n.eye[1]-g[1],f[2]=n.eye[2]-g[2],e.snapPickOrigin[0]=g[0],e.snapPickOrigin[1]=g[1],e.snapPickOrigin[2]=g[2]}else p=d,f=n.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,v),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var _=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,_+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,_+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,_+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var y=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,y),this.setSectionPlanesStateUniforms(t),a.indicesBuf.bind(),o.drawElements(o.LINES,a.indicesBuf.numItems,a.indicesBuf.itemType,0),a.indicesBuf.unbind()}}},{key:"_allocate",value:function(){f(B(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec4 pickColor;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vPickColor = pickColor;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),i.push("vec3 xTangent = dFdx( vWorldPosition.xyz );"),i.push("vec3 yTangent = dFdy( vWorldPosition.xyz );"),i.push("vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),i.push("outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),pl=$.vec3(),fl=$.vec3(),vl=$.vec3(),gl=$.vec3(),ml=$.mat4(),_l=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f,v=pl;if(v[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,v[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,v[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(v[0]),e.snapPickCoordinateScale[1]=$.safeInv(v[1]),e.snapPickCoordinateScale[2]=$.safeInv(v[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var g=fl;if(l){var m=vl;$.transformPoint3(A,l,m),g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],p=Re(d,g,ml),(f=gl)[0]=n.eye[0]-g[0],f[1]=n.eye[1]-g[1],f[2]=n.eye[2]-g[2],e.snapPickOrigin[0]=g[0],e.snapPickOrigin[1]=g[1],e.snapPickOrigin[2]=g[2]}else p=d,f=n.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,v),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var _=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,_+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,_+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,_+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var y=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,y),this.setSectionPlanesStateUniforms(t),"edge"===e.snapMode?(a.indicesBuf.bind(),o.drawElements(o.LINES,a.indicesBuf.numItems,a.indicesBuf.itemType,0),a.indicesBuf.unbind()):o.drawArrays(o.POINTS,0,a.positionsBuf.numItems)}}},{key:"_allocate",value:function(){f(B(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0;e.pointsMaterial._state;var i=[];return i.push("#version 300 es"),i.push("// SnapBatchingDepthRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// SnapBatchingDepthRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),yl=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new ol(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new al(this._scene)),this._silhouetteRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new dl(this._scene,!1)),this._snapInitRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new _l(this._scene)),this._snapRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy()}}]),e}(),bl={};var Bl=C((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e6;x(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]})),wl=function(){function e(t){var i,s,r;x(this,e),console.info("Creating VBOBatchingLinesLayer"),this.layerIndex=t.layerIndex,this._renderers=(i=t.model.scene,s=i.id,(r=bl[s])||(r=new yl(i),bl[s]=r,r._compile(),i.on("compile",(function(){r._compile()})),i.on("destroyed",(function(){delete bl[s],r._destroy()}))),r),this.model=t.model,this._buffer=new Bl(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new Zt({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:$.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=$.collapseAABB3(),this._portions=[],this._meshes=[],this._numVerts=0,this._aabb=$.collapseAABB3(),this.aabbDirty=!0,this._finalized=!1,t.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(t.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,t.origin&&(this._state.origin=$.vec3(t.origin))}return C(e,[{key:"aabb",get:function(){if(this.aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._meshes.length;e0)if(this._preCompressedPositionsExpected){var s=new Uint16Array(i.positions);e.positionsBuf=new It(t,t.ARRAY_BUFFER,s,i.positions.length,3,t.STATIC_DRAW)}else{var r=$o(new Float32Array(i.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new It(t,t.ARRAY_BUFFER,r,i.positions.length,3,t.STATIC_DRAW)}if(i.colors.length>0){var n=new Uint8Array(i.colors);e.colorsBuf=new It(t,t.ARRAY_BUFFER,n,i.colors.length,4,t.DYNAMIC_DRAW,!1)}if(i.colors.length>0){var o=i.colors.length/4,a=new Float32Array(o);e.flagsBuf=new It(t,t.ARRAY_BUFFER,a,a.length,1,t.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&i.offsets.length>0){var l=new Float32Array(i.offsets);e.offsetsBuf=new It(t,t.ARRAY_BUFFER,l,i.offsets.length,3,t.DYNAMIC_DRAW)}if(i.indices.length>0){var u=new Uint32Array(i.indices);e.indicesBuf=new It(t,t.ELEMENT_ARRAY_BUFFER,u,i.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Xe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,i,!0)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags()}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Xe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,i)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var i=2*e,s=4*this._portions[i],r=4*this._portions[i+1],n=this._scratchMemory.getUInt8Array(r),o=t[0],a=t[1],l=t[2],u=t[3],A=0;A3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var r,n,o=2*e,a=this._portions[o],l=this._portions[o+1],u=a,A=l,c=!!(t&Qe),h=!!(t&ze),d=!!(t&We),p=!!(t&Ke),f=!!(t&He),v=!!(t&Ve);r=!c||v||h||d&&!this.model.scene.highlightMaterial.glowThrough||p&&!this.model.scene.selectedMaterial.glowThrough?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,n=!c||v?oo.NOT_RENDERED:p?oo.SILHOUETTE_SELECTED:d?oo.SILHOUETTE_HIGHLIGHTED:h?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED;var g=c&&!v&&f?oo.PICK:oo.NOT_RENDERED,m=t&je?1:0;if(s){this._deferredFlagValues||(this._deferredFlagValues=new Float32Array(this._numVerts));for(var _=u,y=u+A;_0,i=[];return i.push("#version 300 es"),i.push("// Lines instancing color vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("in float flags;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;")),i.push("uniform vec4 lightAmbient;"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("if (colorFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i._sectionPlanesState,r=s.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Lines instancing color 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"),i.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),r)for(n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;"),e=0,t=s.getNumAllocatedSectionPlanes();e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;"),e=0,t=s.getNumAllocatedSectionPlanes();e 0.0) { discard; }"),n.push("}")}return this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):n.push(" outColor = vColor;"),i.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}]),i}(),Cl=function(e){g(i,xl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Lines instancing silhouette vertex shader"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(i),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;")),i.push("uniform vec4 color;"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("void main(void) {"),i.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),i.push("if (silhouetteFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Lines instancing silhouette fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = color;"),s.push("}"),s}}]),i}(),Ml=$.vec3(),Fl=$.vec3(),El=$.vec3();$.vec3();var kl=$.mat4(),Il=function(e){g(i,po);var t=_(i);function i(e){return x(this,i),t.call(this,e,!1,{instancing:!0})}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.canvas.gl,o=r.camera,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||o.viewMatrix;this._vaoCache.has(t)?n.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f=Ml;if(f[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,f[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,f[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(f[0]),e.snapPickCoordinateScale[1]=$.safeInv(f[1]),e.snapPickCoordinateScale[2]=$.safeInv(f[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var v=Fl;if(l){var g=$.transformPoint3(A,l,El);v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=u[0],v[1]+=u[1],v[2]+=u[2],p=Re(d,v,kl),e.snapPickOrigin[0]=v[0],e.snapPickOrigin[1]=v[1],e.snapPickOrigin[2]=v[2]}else p=d,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;n.uniform2fv(this.uVectorA,e.snapVectorA),n.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),n.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),n.uniform3fv(this._uCoordinateScaler,f),n.uniform1i(this._uRenderPass,i),n.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,m+=16),this._matricesUniformBlockBufferData.set(o.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,m+=16),n.bindBuffer(n.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),n.bufferData(n.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,n.DYNAMIC_DRAW),n.bindBufferBase(n.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var _=2/(Math.log(e.pickZFar+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,_),this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(a.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(a.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(a.modelMatrixCol2Buf),n.vertexAttribDivisor(this._aModelMatrixCol0.location,1),n.vertexAttribDivisor(this._aModelMatrixCol1.location,1),n.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags&&(this._aFlags.bindArrayBuffer(a.flagsBuf),n.vertexAttribDivisor(this._aFlags.location,1)),a.indicesBuf.bind(),n.drawElementsInstanced(n.LINES,a.indicesBuf.numItems,a.indicesBuf.itemType,0,a.numInstances),a.indicesBuf.unbind(),n.vertexAttribDivisor(this._aModelMatrixCol0.location,0),n.vertexAttribDivisor(this._aModelMatrixCol1.location,0),n.vertexAttribDivisor(this._aModelMatrixCol2.location,0),this._aFlags&&n.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&n.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){f(B(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// SnapInstancingDepthBufInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec4 pickColor;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vPickColor = pickColor;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Points instancing pick depth fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Dl=$.vec3(),Sl=$.vec3(),Tl=$.vec3();$.vec3();var Rl=$.mat4(),Ll=function(e){g(i,po);var t=_(i);function i(e){return x(this,i),t.call(this,e,!1,{instancing:!0})}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f=Dl;if(f[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,f[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,f[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(f[0]),e.snapPickCoordinateScale[1]=$.safeInv(f[1]),e.snapPickCoordinateScale[2]=$.safeInv(f[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var v=Sl;if(l){var g=$.transformPoint3(A,l,Tl);v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=u[0],v[1]+=u[1],v[2]+=u[2],p=Re(d,v,Rl),e.snapPickOrigin[0]=v[0],e.snapPickOrigin[1]=v[1],e.snapPickOrigin[2]=v[2]}else p=d,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,f),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,m+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,m+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var _=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,_),this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(a.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(a.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(a.modelMatrixCol2Buf),o.vertexAttribDivisor(this._aModelMatrixCol0.location,1),o.vertexAttribDivisor(this._aModelMatrixCol1.location,1),o.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags.bindArrayBuffer(a.flagsBuf),o.vertexAttribDivisor(this._aFlags.location,1),"edge"===e.snapMode?(a.indicesBuf.bind(),o.drawElementsInstanced(o.LINES,a.indicesBuf.numItems,a.indicesBuf.itemType,0,a.numInstances),a.indicesBuf.unbind()):o.drawArraysInstanced(o.POINTS,0,a.positionsBuf.numItems,a.numInstances),o.vertexAttribDivisor(this._aModelMatrixCol0.location,0),o.vertexAttribDivisor(this._aModelMatrixCol1.location,0),o.vertexAttribDivisor(this._aModelMatrixCol2.location,0),o.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&o.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){f(B(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// SnapInstancingDepthRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// SnapInstancingDepthRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Ul=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null)}},{key:"eagerCreateRenders",value:function(){this._snapInitRenderer||(this._snapInitRenderer=new Il(this._scene,!1)),this._snapRenderer||(this._snapRenderer=new Ll(this._scene))}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Pl(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Cl(this._scene)),this._silhouetteRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new Il(this._scene,!1)),this._snapInitRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new Ll(this._scene)),this._snapRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy()}}]),e}(),Ol={};var Nl=new Uint8Array(4),Ql=new Float32Array(1),Vl=new Float32Array(3),Hl=new Float32Array(4),jl=function(){function e(t){var i,s,r;x(this,e),console.info("VBOInstancingLinesLayer"),this.model=t.model,this.material=t.material,this.sortId="LinesInstancingLayer",this.layerIndex=t.layerIndex,this._renderers=(i=t.model.scene,s=i.id,(r=Ol[s])||(r=new Ul(i),Ol[s]=r,r._compile(),i.on("compile",(function(){r._compile()})),i.on("destroyed",(function(){delete Ol[s],r._destroy()}))),r),this._aabb=$.collapseAABB3(),this._state=new Zt({obb:$.OBB3(),numInstances:0,origin:null,geometry:t.geometry,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._meshes=[],this._aabb=$.collapseAABB3(),this.aabbDirty=!0,t.origin&&(this._state.origin=$.vec3(t.origin)),this._finalized=!1}return C(e,[{key:"aabb",get:function(){if(this.aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._meshes.length;e0){this._state.colorsBuf=new It(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,!1),this._colors=[]}if(r>0){this._state.flagsBuf=new It(e,e.ARRAY_BUFFER,new Float32Array(r),r,1,e.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){this._state.offsetsBuf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,!1),this._offsets=[]}if(i.colorsCompressed&&i.colorsCompressed.length>0){var n=new Uint8Array(i.colorsCompressed);t.colorsBuf=new It(e,e.ARRAY_BUFFER,n,n.length,4,e.STATIC_DRAW,!1)}if(i.positionsCompressed&&i.positionsCompressed.length>0){t.positionsBuf=new It(e,e.ARRAY_BUFFER,i.positionsCompressed,i.positionsCompressed.length,3,e.STATIC_DRAW,!1),t.positionsDecodeMatrix=$.mat4(i.positionsDecodeMatrix)}if(i.indices&&i.indices.length>0&&(t.indicesBuf=new It(e,e.ELEMENT_ARRAY_BUFFER,new Uint32Array(i.indices),i.indices.length,1,e.STATIC_DRAW),t.numIndices=i.indices.length),this._modelMatrixCol0.length>0){var o=!1;this._state.modelMatrixCol0Buf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,o),this._state.modelMatrixCol1Buf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,o),this._state.modelMatrixCol2Buf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,o),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Xe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,i)}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Xe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,i)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";Nl[0]=t[0],Nl[1]=t[1],Nl[2]=t[2],Nl[3]=t[3],this._state.colorsBuf.setData(Nl,4*e,4)}},{key:"setTransparent",value:function(e,t,i){i?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,i)}},{key:"_setFlags",value:function(e,t,i){if(!this._finalized)throw"Not finalized";var s=!!(t&Qe),r=!!(t&ze),n=!!(t&We),o=!!(t&Ke),a=!!(t&Xe),l=!!(t&He),u=!!(t&Ve),A=0;A|=!s||u||r||n&&!this.model.scene.highlightMaterial.glowThrough||o&&!this.model.scene.selectedMaterial.glowThrough?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,A|=(!s||u?oo.NOT_RENDERED:o?oo.SILHOUETTE_SELECTED:n?oo.SILHOUETTE_HIGHLIGHTED:r?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED)<<4,A|=(!s||u?oo.NOT_RENDERED:o?oo.EDGES_SELECTED:n?oo.EDGES_HIGHLIGHTED:r?oo.EDGES_XRAYED:a?i?oo.EDGES_COLOR_TRANSPARENT:oo.EDGES_COLOR_OPAQUE:oo.NOT_RENDERED)<<8,A|=(s&&!u&&l?oo.PICK:oo.NOT_RENDERED)<<12,A|=(t&je?255:0)<<16,Ql[0]=A,this._state.flagsBuf.setData(Ql,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Vl[0]=t[0],Vl[1]=t[1],Vl[2]=t[2],this._state.offsetsBuf.setData(Vl,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"setMatrix",value:function(e,t){if(!this._finalized)throw"Not finalized";var i=4*e;Hl[0]=t[0],Hl[1]=t[4],Hl[2]=t[8],Hl[3]=t[12],this._state.modelMatrixCol0Buf.setData(Hl,i),Hl[0]=t[1],Hl[1]=t[5],Hl[2]=t[9],Hl[3]=t[13],this._state.modelMatrixCol1Buf.setData(Hl,i),Hl[0]=t[2],Hl[1]=t[6],Hl[2]=t[10],Hl[3]=t[14],this._state.modelMatrixCol2Buf.setData(Hl,i)}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_SELECTED)}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawSnapInit",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.snapInitRenderer&&this._renderers.snapInitRenderer.drawLayer(t,this,oo.PICK)}},{key:"drawSnap",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.snapRenderer&&this._renderers.snapRenderer.drawLayer(t,this,oo.PICK)}},{key:"drawOcclusion",value:function(e,t){}},{key:"drawShadow",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){}},{key:"drawPickDepths",value:function(e,t){}},{key:"drawPickNormals",value:function(e,t){}},{key:"destroy",value:function(){var e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}]),e}(),Gl=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,i=e.state,s=e.frameCtx,r=e.incrementDrawState;t.drawArrays(t.POINTS,0,i.positionsBuf.numItems),r&&s.drawArrays++}}]),i}(),zl=function(e){g(i,Gl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial,s=[];return s.push("#version 300 es"),s.push("// Points batching color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),i.filterIntensity&&s.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),i.filterIntensity&&(s.push("float intensity = float(color.a) / 255.0;"),s.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {")),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),i.filterIntensity&&s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points batching color fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return s.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),i}(),Wl=function(e){g(i,Gl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 color;"),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i._sectionPlanesState,r=s.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching silhouette vertex 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"),i.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),r)for(n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;"),e=0,t=s.getNumAllocatedSectionPlanes();e 1.0) {"),n.push(" discard;"),n.push(" }")),r){for(n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;"),e=0,t=s.getNumAllocatedSectionPlanes();e 0.0) { discard; }"),n.push("}")}return i.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}]),i}(),Kl=function(e){g(i,Gl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points batching pick mesh vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = remapClipPos(clipPos);"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("gl_PointSize += 10.0;"),s.push(" }"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points batching pick mesh vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vPickColor; "),s.push("}"),s}}]),i}(),Xl=function(e){g(i,Gl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points batched pick depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = remapClipPos(clipPos);"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("gl_PointSize += 10.0;"),s.push(" }"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points batched pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform float pickZNear;"),s.push("uniform float pickZFar;"),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),s.push(" outColor = packDepth(zNormalizedDepth); "),s.push("}"),s}}]),i}(),Jl=function(e){g(i,Gl);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points batching occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push(" gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push(" }"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points batching occlusion fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}}]),i}(),Yl=$.vec3(),Zl=$.vec3(),ql=$.vec3(),$l=$.vec3(),eu=$.mat4(),tu=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f,v=Yl;if(v[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,v[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,v[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(v[0]),e.snapPickCoordinateScale[1]=$.safeInv(v[1]),e.snapPickCoordinateScale[2]=$.safeInv(v[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var g=Zl;if(l){var m=ql;$.transformPoint3(A,l,m),g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],p=Re(d,g,eu),(f=$l)[0]=n.eye[0]-g[0],f[1]=n.eye[1]-g[1],f[2]=n.eye[2]-g[2],e.snapPickOrigin[0]=g[0],e.snapPickOrigin[1]=g[1],e.snapPickOrigin[2]=g[2]}else p=d,f=n.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,v),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var _=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,_+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,_+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,_+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var y=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,y),this.setSectionPlanesStateUniforms(t),o.drawArrays(o.POINTS,0,a.positionsBuf.numItems)}}},{key:"_allocate",value:function(){f(B(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// VBOBatchingPointsSnapInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec4 pickColor;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vPickColor = pickColor;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// VBOBatchingPointsSnapInitRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),i.push("outNormal = ivec4(1.0, 1.0, 1.0, 1.0);"),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),iu=$.vec3(),su=$.vec3(),ru=$.vec3(),nu=$.vec3(),ou=$.mat4(),au=function(e){g(i,po);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f,v=iu;if(v[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,v[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,v[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(v[0]),e.snapPickCoordinateScale[1]=$.safeInv(v[1]),e.snapPickCoordinateScale[2]=$.safeInv(v[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var g=su;if(l){var m=ru;$.transformPoint3(A,l,m),g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],p=Re(d,g,ou),(f=nu)[0]=n.eye[0]-g[0],f[1]=n.eye[1]-g[1],f[2]=n.eye[2]-g[2],e.snapPickOrigin[0]=g[0],e.snapPickOrigin[1]=g[1],e.snapPickOrigin[2]=g[2]}else p=d,f=n.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,v),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var _=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,_+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,_+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,_+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var y=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,y),this.setSectionPlanesStateUniforms(t),o.drawArrays(o.POINTS,0,a.positionsBuf.numItems)}}},{key:"_allocate",value:function(){f(B(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0;e.pointsMaterial._state;var i=[];return i.push("#version 300 es"),i.push("// VBOBatchingPointsSnapRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// VBOBatchingPointsSnapRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),lu=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new zl(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Wl(this._scene)),this._silhouetteRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Kl(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Xl(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Jl(this._scene)),this._occlusionRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new tu(this._scene,!1)),this._snapInitRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new au(this._scene)),this._snapRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy()}}]),e}(),uu={};var Au=C((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e6;x(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]})),cu=function(){function e(t){x(this,e),console.info("Creating VBOBatchingPointsLayer"),this.model=t.model,this.sortId="PointsBatchingLayer",this.layerIndex=t.layerIndex,this._renderers=function(e){var t=e.id,i=uu[t];return i||(i=new lu(e),uu[t]=i,i._compile(),e.on("compile",(function(){i._compile()})),e.on("destroyed",(function(){delete uu[t],i._destroy()}))),i}(t.model.scene),this._buffer=new Au(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new Zt({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:$.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=$.collapseAABB3(),this._portions=[],this._meshes=[],this._aabb=$.collapseAABB3(),this.aabbDirty=!0,this._finalized=!1,t.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(t.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,t.origin&&(this._state.origin=$.vec3(t.origin))}return C(e,[{key:"aabb",get:function(){if(this.aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._meshes.length;e0)if(this._preCompressedPositionsExpected){var s=new Uint16Array(i.positions);e.positionsBuf=new It(t,t.ARRAY_BUFFER,s,i.positions.length,3,t.STATIC_DRAW)}else{var r=$o(new Float32Array(i.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new It(t,t.ARRAY_BUFFER,r,i.positions.length,3,t.STATIC_DRAW)}if(i.colors.length>0){var n=new Uint8Array(i.colors);e.colorsBuf=new It(t,t.ARRAY_BUFFER,n,i.colors.length,4,t.STATIC_DRAW,!1)}if(i.positions.length>0){var o=i.positions.length/3,a=new Float32Array(o);e.flagsBuf=new It(t,t.ARRAY_BUFFER,a,a.length,1,t.DYNAMIC_DRAW,!1)}if(i.pickColors.length>0){var l=new Uint8Array(i.pickColors);e.pickColorsBuf=new It(t,t.ARRAY_BUFFER,l,i.pickColors.length,4,t.STATIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&i.offsets.length>0){var u=new Float32Array(i.offsets);e.offsetsBuf=new It(t,t.ARRAY_BUFFER,u,i.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,i)}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized"}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var i=2*e,s=4*this._portions[i],r=4*this._portions[i+1],n=this._scratchMemory.getUInt8Array(r),o=t[0],a=t[1],l=t[2],u=0;u0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points instancing color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),i.filterIntensity&&s.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),i.filterIntensity&&(s.push("float intensity = float(color.a) / 255.0;"),s.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {")),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),i.filterIntensity&&s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing color fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return s.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),i}(),pu=function(e){g(i,hu);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,s){f(B(i.prototype),"drawLayer",this).call(this,e,t,s,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 silhouetteColor;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),s.push("gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing silhouette fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vColor;"),s.push("}"),s}}]),i}(),fu=function(e){g(i,hu);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points instancing pick mesh vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("gl_Position = remapClipPos(clipPos);"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing pick mesh fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outColor = vPickColor; "),s.push("}"),s}}]),i}(),vu=function(e){g(i,hu);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points instancing pick depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("gl_Position = remapClipPos(clipPos);"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = remapClipPos(clipPos);"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform float pickZNear;"),s.push("uniform float pickZFar;"),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),s.push(" outColor = packDepth(zNormalizedDepth); "),s.push("}"),s}}]),i}(),gu=function(e){g(i,hu);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points instancing occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing occlusion vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0;r 1.0) {"),s.push(" discard;"),s.push(" }")),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push("}")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),i}(),mu=function(e){g(i,hu);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=e.pointsMaterial._state,s=[];return s.push("#version 300 es"),s.push("// Points instancing depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),i.perspectivePoints&&s.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),i.perspectivePoints?(s.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),s.push("gl_PointSize = max(gl_PointSize, "+Math.floor(i.minPerspectivePointSize)+".0);"),s.push("gl_PointSize = min(gl_PointSize, "+Math.floor(i.maxPerspectivePointSize)+".0);")):s.push("gl_PointSize = pointSize;"),s.push("}"),s.push("}"),s}},{key:"_buildFragmentShader",value:function(){var e,t,i=this._scene,s=i._sectionPlanesState,r=s.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing depth vertex 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"),i.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),r)for(n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;"),e=0,t=s.getNumAllocatedSectionPlanes();e 1.0) {"),n.push(" discard;"),n.push(" }")),r){for(n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;"),e=0,t=s.getNumAllocatedSectionPlanes();e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),i.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}]),i}(),_u=function(e){g(i,hu);var t=_(i);function i(){return x(this,i),t.apply(this,arguments)}return C(i,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// Instancing geometry shadow drawing vertex shader"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in vec4 color;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform mat4 shadowViewMatrix;"),i.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(i),i.push("uniform float pointSize;"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("void main(void) {"),i.push("int colorFlag = int(flags) & 0xF;"),i.push("bool visible = (colorFlag > 0);"),i.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),i.push("if (!visible || transparent) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags = flags;")),i.push(" gl_Position = shadowProjMatrix * viewPosition;"),i.push("}"),i.push("gl_PointSize = pointSize;"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// Instancing geometry depth drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r 1.0) {"),s.push(" discard;"),s.push(" }"),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { discard; }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),s.push("}"),s}}]),i}(),yu=$.vec3(),bu=$.vec3(),Bu=$.vec3();$.vec3();var wu=$.mat4(),xu=function(e){g(i,po);var t=_(i);function i(e){return x(this,i),t.call(this,e,!1,{instancing:!0})}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.canvas.gl,o=r.camera,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||o.viewMatrix;this._vaoCache.has(t)?n.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f=yu;if(f[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,f[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,f[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(f[0]),e.snapPickCoordinateScale[1]=$.safeInv(f[1]),e.snapPickCoordinateScale[2]=$.safeInv(f[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var v=bu;if(l){var g=$.transformPoint3(A,l,Bu);v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=u[0],v[1]+=u[1],v[2]+=u[2],p=Re(d,v,wu),e.snapPickOrigin[0]=v[0],e.snapPickOrigin[1]=v[1],e.snapPickOrigin[2]=v[2]}else p=d,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;n.uniform2fv(this.uVectorA,e.snapVectorA),n.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),n.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),n.uniform3fv(this._uCoordinateScaler,f),n.uniform1i(this._uRenderPass,i),n.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,m+=16),this._matricesUniformBlockBufferData.set(o.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,m+=16),n.bindBuffer(n.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),n.bufferData(n.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,n.DYNAMIC_DRAW),n.bindBufferBase(n.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var _=2/(Math.log(e.pickZFar+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,_),this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(a.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(a.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(a.modelMatrixCol2Buf),n.vertexAttribDivisor(this._aModelMatrixCol0.location,1),n.vertexAttribDivisor(this._aModelMatrixCol1.location,1),n.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags&&(this._aFlags.bindArrayBuffer(a.flagsBuf),n.vertexAttribDivisor(this._aFlags.location,1)),n.drawArraysInstanced(n.POINTS,0,a.positionsBuf.numItems,a.numInstances),n.vertexAttribDivisor(this._aModelMatrixCol0.location,0),n.vertexAttribDivisor(this._aModelMatrixCol1.location,0),n.vertexAttribDivisor(this._aModelMatrixCol2.location,0),this._aFlags&&n.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&n.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){f(B(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// SnapInstancingDepthBufInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec4 pickColor;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("out float vFlags;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vWorldPosition = worldPosition;"),t&&i.push(" vFlags = flags;"),i.push("vPickColor = pickColor;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Points instancing pick depth fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),i.push("outNormal = ivec4(1.0, 1.0, 1.0, 1.0);"),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),Pu=$.vec3(),Cu=$.vec3(),Mu=$.vec3();$.vec3();var Fu=$.mat4(),Eu=function(e){g(i,po);var t=_(i);function i(e){return x(this,i),t.call(this,e,!1,{instancing:!0})}return C(i,[{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=t.aabb,d=e.pickViewMatrix||n.viewMatrix;this._vaoCache.has(t)?o.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(a));var p,f=Pu;if(f[0]=$.safeInv(h[3]-h[0])*$.MAX_INT,f[1]=$.safeInv(h[4]-h[1])*$.MAX_INT,f[2]=$.safeInv(h[5]-h[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(f[0]),e.snapPickCoordinateScale[1]=$.safeInv(f[1]),e.snapPickCoordinateScale[2]=$.safeInv(f[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var v=Cu;if(l){var g=$.transformPoint3(A,l,Mu);v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=u[0],v[1]+=u[1],v[2]+=u[2],p=Re(d,v,Fu),e.snapPickOrigin[0]=v[0],e.snapPickOrigin[1]=v[1],e.snapPickOrigin[2]=v[2]}else p=d,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;o.uniform2fv(this.uVectorA,e.snapVectorA),o.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),o.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),o.uniform3fv(this._uCoordinateScaler,f),o.uniform1i(this._uRenderPass,i),o.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(c,0),this._matricesUniformBlockBufferData.set(p,m+=16),this._matricesUniformBlockBufferData.set(n.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(a.positionsDecodeMatrix,m+=16),o.bindBuffer(o.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),o.bufferData(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,o.DYNAMIC_DRAW),o.bindBufferBase(o.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var _=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,_),this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(a.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(a.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(a.modelMatrixCol2Buf),o.vertexAttribDivisor(this._aModelMatrixCol0.location,1),o.vertexAttribDivisor(this._aModelMatrixCol1.location,1),o.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags.bindArrayBuffer(a.flagsBuf),o.vertexAttribDivisor(this._aFlags.location,1),o.drawArraysInstanced(o.POINTS,0,a.positionsBuf.numItems,a.numInstances),o.vertexAttribDivisor(this._aModelMatrixCol0.location,0),o.vertexAttribDivisor(this._aModelMatrixCol1.location,0),o.vertexAttribDivisor(this._aModelMatrixCol2.location,0),o.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&o.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){f(B(i.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];return i.push("#version 300 es"),i.push("// SnapInstancingDepthRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("in vec3 position;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("in float flags;"),i.push("in vec4 modelMatrixCol0;"),i.push("in vec4 modelMatrixCol1;"),i.push("in vec4 modelMatrixCol2;"),i.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(i),i.push("uniform vec2 snapVectorA;"),i.push("uniform vec2 snapInvVectorAB;"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),i.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out float vFlags;")),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int pickFlag = int(flags) >> 12 & 0xF;"),i.push("if (pickFlag != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push("} else {"),i.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),i.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags = flags;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// SnapInstancingDepthRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int layerNumber;"),i.push("uniform vec3 coordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var s=0;s> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push("}")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),i}(),ku=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new du(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new pu(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new mu(this._scene)),this._depthRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new fu(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new vu(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new gu(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new _u(this._scene)),this._shadowRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new xu(this._scene,!1)),this._snapInitRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new Eu(this._scene)),this._snapRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy()}}]),e}(),Iu={};var Du=new Uint8Array(4),Su=new Float32Array(1),Tu=new Float32Array(3),Ru=new Float32Array(4),Lu=function(){function e(t){var i,s,r;x(this,e),console.info("VBOInstancingPointsLayer"),this.model=t.model,this.material=t.material,this.sortId="PointsInstancingLayer",this.layerIndex=t.layerIndex,this._renderers=(i=t.model.scene,s=i.id,(r=Iu[s])||(r=new ku(i),Iu[s]=r,r._compile(),i.on("compile",(function(){r._compile()})),i.on("destroyed",(function(){delete Iu[s],r._destroy()}))),r),this._aabb=$.collapseAABB3(),this._state=new Zt({obb:$.OBB3(),numInstances:0,origin:t.origin?$.vec3(t.origin):null,geometry:t.geometry,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._meshes=[],this._aabb=$.collapseAABB3(),this.aabbDirty=!0,this._finalized=!1}return C(e,[{key:"aabb",get:function(){if(this.aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._meshes.length;e0){i.flagsBuf=new It(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){i.offsetsBuf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,!1),this._offsets=[]}if(s.positionsCompressed&&s.positionsCompressed.length>0){i.positionsBuf=new It(e,e.ARRAY_BUFFER,s.positionsCompressed,s.positionsCompressed.length,3,e.STATIC_DRAW,!1),i.positionsDecodeMatrix=$.mat4(s.positionsDecodeMatrix)}if(s.colorsCompressed&&s.colorsCompressed.length>0){var r=new Uint8Array(s.colorsCompressed);i.colorsBuf=new It(e,e.ARRAY_BUFFER,r,r.length,4,e.STATIC_DRAW,!1)}if(this._modelMatrixCol0.length>0){var n=!1;i.modelMatrixCol0Buf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,n),i.modelMatrixCol1Buf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,n),i.modelMatrixCol2Buf=new It(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,n),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){i.pickColorsBuf=new It(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,!1),this._pickColors=[]}i.geometry=null,this._finalized=!0}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Xe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,i)}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Xe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,i)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";Du[0]=t[0],Du[1]=t[1],Du[2]=t[2],this._state.colorsBuf.setData(Du,3*e)}},{key:"setTransparent",value:function(e,t,i){i?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,i)}},{key:"_setFlags",value:function(e,t,i){if(!this._finalized)throw"Not finalized";var s=!!(t&Qe),r=!!(t&ze),n=!!(t&We),o=!!(t&Ke),a=!!(t&Xe),l=!!(t&He),u=!!(t&Ve),A=0;A|=!s||u||r||n&&!this.model.scene.highlightMaterial.glowThrough||o&&!this.model.scene.selectedMaterial.glowThrough?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,A|=(!s||u?oo.NOT_RENDERED:o?oo.SILHOUETTE_SELECTED:n?oo.SILHOUETTE_HIGHLIGHTED:r?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED)<<4,A|=(!s||u?oo.NOT_RENDERED:o?oo.EDGES_SELECTED:n?oo.EDGES_HIGHLIGHTED:r?oo.EDGES_XRAYED:a?i?oo.EDGES_COLOR_TRANSPARENT:oo.EDGES_COLOR_OPAQUE:oo.NOT_RENDERED)<<8,A|=(s&&!u&&l?oo.PICK:oo.NOT_RENDERED)<<12,A|=(t&je?255:0)<<16,Su[0]=A,this._state.flagsBuf.setData(Su,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Tu[0]=t[0],Tu[1]=t[1],Tu[2]=t[2],this._state.offsetsBuf.setData(Tu,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"setMatrix",value:function(e,t){if(!this._finalized)throw"Not finalized";var i=4*e;Ru[0]=t[0],Ru[1]=t[4],Ru[2]=t[8],Ru[3]=t[12],this._state.modelMatrixCol0Buf.setData(Ru,i),Ru[0]=t[1],Ru[1]=t[5],Ru[2]=t[9],Ru[3]=t[13],this._state.modelMatrixCol1Buf.setData(Ru,i),Ru[0]=t[2],Ru[1]=t[6],Ru[2]=t[10],Ru[3]=t[14],this._state.modelMatrixCol2Buf.setData(Ru,i)}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_SELECTED)}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.occlusionRenderer&&this._renderers.occlusionRenderer.drawLayer(t,this,oo.COLOR_OPAQUE)}},{key:"drawShadow",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.pickMeshRenderer&&this._renderers.pickMeshRenderer.drawLayer(t,this,oo.PICK)}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.pickDepthRenderer&&this._renderers.pickDepthRenderer.drawLayer(t,this,oo.PICK)}},{key:"drawPickNormals",value:function(e,t){}},{key:"drawSnapInit",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.snapInitRenderer&&this._renderers.snapInitRenderer.drawLayer(t,this,oo.PICK)}},{key:"drawSnap",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._renderers.snapRenderer&&this._renderers.snapRenderer.drawLayer(t,this,oo.PICK)}},{key:"destroy",value:function(){var e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}]),e}(),Uu=$.vec3(),Ou=$.vec3(),Nu=$.mat4(),Qu=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=this._scene,r=s.camera,n=t.model,o=s.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=n.position,c=n.rotationMatrix,h=n.rotationMatrixConjugate,d=r.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,a)),l.bindCommonTextures(this._program,this.uPerObjectDecodeMatrix,this._uPerVertexPosition,this.uPerObjectColorAndFlags,this._uPerObjectMatrix);var f=0!==u[0]||0!==u[1]||0!==u[2],v=0!==A[0]||0!==A[1]||0!==A[2];if(f||v){var g=Uu;if(f){var m=$.transformPoint3(c,u,Ou);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=A[0],g[1]+=A[1],g[2]+=A[2],p=Re(d,g,Nu)}else p=d;if(o.uniformMatrix4fv(this._uSceneModelMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,p),o.uniformMatrix4fv(this._uProjMatrix,!1,r.projMatrix),o.uniform1i(this._uRenderPass,i),s.logarithmicDepthBufferEnabled){var _=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,_)}var y=s._sectionPlanesState.getNumAllocatedSectionPlanes(),b=s._sectionPlanesState.sectionPlanes.length;if(y>0)for(var B=s._sectionPlanesState.sectionPlanes,w=t.layerIndex*b,x=n.renderFlags,P=0;P0&&(l.bindLineIndicesTextures(this._program,this._uPerLineObject,this._uPerLineIndices,8),o.drawArrays(o.LINES,0,a.numIndices8Bits)),a.numIndices16Bits>0&&(l.bindLineIndicesTextures(this._program,this._uPerLineObject,this._uPerLineIndices,16),o.drawArrays(o.LINES,0,a.numIndices16Bits)),a.numIndices32Bits>0&&(l.bindLineIndicesTextures(this._program,this._uPerLineObject,this._uPerLineIndices,32),o.drawArrays(o.LINES,0,a.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)return this.errors=this._program.errors,void console.error(this.errors);var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// LinesDataTextureColorRenderer"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled,i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uPerObjectDecodeMatrix;"),i.push("uniform highp sampler2D uPerObjectMatrix;"),i.push("uniform lowp usampler2D uPerObjectColorAndFlags;"),i.push("uniform mediump usampler2D uPerVertexPosition;"),i.push("uniform highp usampler2D uPerLineIndices;"),i.push("uniform mediump usampler2D uPerLineObject;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push(" int lineIndex = gl_VertexID / 2;"),i.push(" int h_packed_object_id_index = (lineIndex >> 3) & 4095;"),i.push(" int v_packed_object_id_index = (lineIndex >> 3) >> 12;"),i.push(" int objectIndex = int(texelFetch(uPerLineObject, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push(" ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push(" uvec4 flags = texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push(" uvec4 flags2 = texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push(" if (int(flags.x) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push(" } else {"),i.push(" ivec4 packedVertexBase = ivec4(texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push(" ivec4 packedLineIndexBaseOffset = ivec4(texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),i.push(" int lineIndexBaseOffset = (packedLineIndexBaseOffset.r << 24) + (packedLineIndexBaseOffset.g << 16) + (packedLineIndexBaseOffset.b << 8) + packedLineIndexBaseOffset.a;"),i.push(" int h_index = (lineIndex - lineIndexBaseOffset) & 4095;"),i.push(" int v_index = (lineIndex - lineIndexBaseOffset) >> 12;"),i.push(" ivec3 vertexIndices = ivec3(texelFetch(uPerLineIndices, ivec2(h_index, v_index), 0));"),i.push(" ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push(" int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),i.push(" int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),i.push(" mat4 objectInstanceMatrix = mat4 (texelFetch (uPerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uPerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uPerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uPerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push(" mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uPerObjectDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uPerObjectDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uPerObjectDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uPerObjectDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push(" uvec4 flags = texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push(" uvec4 flags2 = texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push(" vec3 position = vec3(texelFetch(uPerVertexPosition, ivec2(indexPositionH, indexPositionV), 0));"),i.push(" uvec4 color = texelFetch (uPerObjectColorAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push(" if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push(" };"),i.push(" vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2.r;")),i.push(" vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push(" vFragDepth = 1.0 + clipPos.w;"),i.push(" isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push(" gl_Position = clipPos;"),i.push(" vec4 rgb = vec4(color.rgba);"),i.push(" vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,i=t.getNumAllocatedSectionPlanes()>0,s=[];if(s.push("#version 300 es"),s.push("// LinesDataTextureColorRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),i){s.push("in vec4 vWorldPosition;"),s.push("flat in uint vFlags2;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r 0u;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { "),s.push(" discard;"),s.push(" }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" outColor = vColor;"),s.push("}"),s}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Vu=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null)}},{key:"eagerCreateRenders",value:function(){}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Qu(this._scene,!1)),this._colorRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy()}}]),e}(),Hu={};var ju=C((function e(){x(this,e),this.positionsCompressed=[],this.lenPositionsCompressed=0,this.indices8Bits=[],this.lenIndices8Bits=0,this.indices16Bits=[],this.lenIndices16Bits=0,this.indices32Bits=[],this.lenIndices32Bits=0,this.perObjectColors=[],this.perObjectPickColors=[],this.perObjectSolid=[],this.perObjectOffsets=[],this.perObjectPositionsDecodeMatrices=[],this.perObjectInstancePositioningMatrices=[],this.perObjectVertexBases=[],this.perObjectIndexBaseOffsets=[],this.perLineNumberPortionId8Bits=[],this.perLineNumberPortionId16Bits=[],this.perLineNumberPortionId32Bits=[]})),Gu=function(){function e(){x(this,e),this.texturePerObjectColorsAndFlags=null,this.texturePerObjectOffsets=null,this.texturePerObjectInstanceMatrices=null,this.texturePerObjectPositionsDecodeMatrix=null,this.texturePerVertexIdCoordinates=null,this.texturePerLineIdPortionIds8Bits=null,this.texturePerLineIdPortionIds16Bits=null,this.texturePerLineIdPortionIds32Bits=null,this.texturePerLineIdIndices8Bits=null,this.texturePerLineIdIndices16Bits=null,this.texturePerLineIdIndices32Bits=null,this.textureModelMatrices=null}return C(e,[{key:"finalize",value:function(){this.indicesPerBitnessTextures={8:this.texturePerLineIdIndices8Bits,16:this.texturePerLineIdIndices16Bits,32:this.texturePerLineIdIndices32Bits},this.indicesPortionIdsPerBitnessTextures={8:this.texturePerLineIdPortionIds8Bits,16:this.texturePerLineIdPortionIds16Bits,32:this.texturePerLineIdPortionIds32Bits}}},{key:"bindCommonTextures",value:function(e,t,i,s,r){this.texturePerObjectPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,i,2),this.texturePerObjectColorsAndFlags.bindTexture(e,s,3),this.texturePerObjectInstanceMatrices.bindTexture(e,r,4)}},{key:"bindLineIndicesTextures",value:function(e,t,i,s){this.indicesPortionIdsPerBitnessTextures[s].bindTexture(e,t,5),this.indicesPerBitnessTextures[s].bindTexture(e,i,6)}}]),e}(),zu=function(){function e(t,i,s,r){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;x(this,e),this._gl=t,this._texture=i,this._textureWidth=s,this._textureHeight=r,this._textureData=n}return C(e,[{key:"bindTexture",value:function(e,t,i){return e.bindTexture(t,this,i)}},{key:"bind",value:function(e){return this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,this._texture),!0}},{key:"unbind",value:function(e){}}]),e}(),Wu={sizeDataColorsAndFlags:0,sizeDataPositionDecodeMatrices:0,sizeDataTextureOffsets:0,sizeDataTexturePositions:0,sizeDataTextureIndices:0,sizeDataTexturePortionIds:0,numberOfGeometries:0,numberOfPortions:0,numberOfLayers:0,numberOfTextures:0,totalLines:0,totalLines8Bits:0,totalLines16Bits:0,totalLines32Bits:0,cannotCreatePortion:{because10BitsObjectId:0,becauseTextureSize:0},overheadSizeAlignementIndices:0,overheadSizeAlignementEdgeIndices:0};window.printDataTextureRamStats=function(){console.log(JSON.stringify(Wu,null,4));var e=0;Object.keys(Wu).forEach((function(t){t.startsWith("size")&&(e+=Wu[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/Wu.totalLines).toFixed(2)));var t={};Object.keys(Wu).forEach((function(i){i.startsWith("size")&&(t[i]="".concat((Wu[i]/e*100).toFixed(2)," % of total"))})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};var Ku=function(){function e(){x(this,e)}return C(e,[{key:"disableBindedTextureFiltering",value:function(e){e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}},{key:"generateTextureForColorsAndFlags",value:function(e,t,i,s,r){var n=t.length;this.numPortions=n;var o=4096,a=Math.ceil(n/512);if(0===a)throw"texture height===0";var l=new Uint8Array(16384*a);Wu.sizeDataColorsAndFlags+=l.byteLength,Wu.numberOfTextures++;for(var u=0;u>24&255,s[u]>>16&255,s[u]>>8&255,255&s[u]],32*u+16),l.set([r[u]>>24&255,r[u]>>16&255,r[u]>>8&255,255&r[u]],32*u+20);var A=e.createTexture();return e.bindTexture(e.TEXTURE_2D,A),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8UI,o,a),e.texSubImage2D(e.TEXTURE_2D,0,0,0,o,a,e.RGBA_INTEGER,e.UNSIGNED_BYTE,l,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new zu(e,A,o,a,l)}},{key:"generateTextureForObjectOffsets",value:function(e,t){var i=512,s=Math.ceil(t/i);if(0===s)throw"texture height===0";var r=new Float32Array(1536*s).fill(0);Wu.sizeDataTextureOffsets+=r.byteLength,Wu.numberOfTextures++;var n=e.createTexture();return e.bindTexture(e.TEXTURE_2D,n),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32F,i,s),e.texSubImage2D(e.TEXTURE_2D,0,0,0,i,s,e.RGB,e.FLOAT,r,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new zu(e,n,i,s,r)}},{key:"generateTextureForInstancingMatrices",value:function(e,t){var i=t.length;if(0===i)throw"num instance matrices===0";var s=2048,r=Math.ceil(i/512),n=new Float32Array(8192*r);Wu.numberOfTextures++;for(var o=0;o65536&&Wu.cannotCreatePortion.because10BitsObjectId++;var i=this._numPortions+t<=65536,s=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(0):"".concat(e.id,"#").concat(0);if(!this._bucketGeometries[s]){var r=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits),n=0,o=0;e.buckets.forEach((function(e){n+=e.positionsCompressed.length/3,o+=e.indices.length/2})),(this._state.numVertices+n>4096*Ju||r+o>4096*Ju)&&Wu.cannotCreatePortion.becauseTextureSize++,i&&(i=this._state.numVertices+n<=4096*Ju&&r+o<=4096*Ju)}return i}},{key:"createPortion",value:function(e,t){var i=this;if(this._finalized)throw"Already finalized";var s=[];t.buckets.forEach((function(e,r){var n=void 0!==t.geometryId&&null!==t.geometryId?"".concat(t.geometryId,"#").concat(r):"".concat(t.id,"#").concat(r),o=i._bucketGeometries[n];o||(o=i._createBucketGeometry(t,e),i._bucketGeometries[n]=o);var a=i._createSubPortion(t,o,e);s.push(a)}));var r=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(s),this.model.numPortions++,this._meshes.push(e),r}},{key:"_createBucketGeometry",value:function(e,t){if(t.indices){var i=8*Math.ceil(t.indices.length/2/8)*2;Wu.overheadSizeAlignementIndices+=2*(i-t.indices.length);var s=new Uint32Array(i);s.fill(0),s.set(t.indices),t.indices=s}var r=t.positionsCompressed,n=t.indices,o=this._buffer;o.positionsCompressed.push(r);var a,l=o.lenPositionsCompressed/3,u=r.length/3;o.lenPositionsCompressed+=r.length;var A,c=0;n&&(c=n.length/2,u<=256?(A=o.indices8Bits,a=o.lenIndices8Bits/2,o.lenIndices8Bits+=n.length):u<=65536?(A=o.indices16Bits,a=o.lenIndices16Bits/2,o.lenIndices16Bits+=n.length):(A=o.indices32Bits,a=o.lenIndices32Bits/2,o.lenIndices32Bits+=n.length),A.push(n));return this._state.numVertices+=u,Wu.numberOfGeometries++,{vertexBase:l,numVertices:u,numLines:c,indicesBase:a}}},{key:"_createSubPortion",value:function(e,t){var i,s=e.color,r=e.colors,n=e.opacity,o=e.meshMatrix,a=e.pickColor,l=this._buffer,u=this._state;l.perObjectPositionsDecodeMatrices.push(e.positionsDecodeMatrix),l.perObjectInstancePositioningMatrices.push(o||eA),l.perObjectSolid.push(!!e.solid),r?l.perObjectColors.push([255*r[0],255*r[1],255*r[2],255]):s&&l.perObjectColors.push([s[0],s[1],s[2],n]),l.perObjectPickColors.push(a),l.perObjectVertexBases.push(t.vertexBase),i=t.numVertices<=256?u.numIndices8Bits:t.numVertices<=65536?u.numIndices16Bits:u.numIndices32Bits,l.perObjectIndexBaseOffsets.push(i/2-t.indicesBase);var A=this._subPortions.length;if(t.numLines>0){var c,h=2*t.numLines;t.numVertices<=256?(c=l.perLineNumberPortionId8Bits,u.numIndices8Bits+=h,Wu.totalLines8Bits+=t.numLines):t.numVertices<=65536?(c=l.perLineNumberPortionId16Bits,u.numIndices16Bits+=h,Wu.totalLines16Bits+=t.numLines):(c=l.perLineNumberPortionId32Bits,u.numIndices32Bits+=h,Wu.totalLines32Bits+=t.numLines),Wu.totalLines+=t.numLines;for(var d=0;d0&&(i.texturePerLineIdIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitIndices(s,r.indices8Bits,r.lenIndices8Bits)),r.lenIndices16Bits>0&&(i.texturePerLineIdIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitIndices(s,r.indices16Bits,r.lenIndices16Bits)),r.lenIndices32Bits>0&&(i.texturePerLineIdIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitIndices(s,r.indices32Bits,r.lenIndices32Bits)),i.finalize(),this._buffer=null,this._bucketGeometries={},this._finalized=!0,this._deferredSetFlagsDirty=!1,this._onSceneRendering=this.model.scene.on("rendering",(function(){e._deferredSetFlagsDirty&&e._uploadDeferredFlags(),e._numUpdatesInFrame=0}))}}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,i,true),this._setFlags2(e,t,true)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags(),this._setDeferredFlags2()}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags2(e,t)}},{key:"_beginDeferredFlags",value:function(){this._deferredSetFlagsActive=!0}},{key:"_uploadDeferredFlags",value:function(){if(this._deferredSetFlagsActive=!1,this._deferredSetFlagsDirty){this._deferredSetFlagsDirty=!1;var e=this.model.scene.canvas.gl,t=this._dataTextureState;e.bindTexture(e.TEXTURE_2D,t.texturePerObjectColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectColorsAndFlags._textureWidth,t.texturePerObjectColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectColorsAndFlags._textureData)}}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions+=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions-=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){for(var i=this._portionToSubPortionsMap[e],s=0,r=i.length;s=10&&this._beginDeferredFlags(),s.bindTexture(s.TEXTURE_2D,i.texturePerObjectColorsAndFlags._texture),s.texSubImage2D(s.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,s.RGBA_INTEGER,s.UNSIGNED_BYTE,Zu))}},{key:"setTransparent",value:function(e,t,i){i?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,i)}},{key:"_setFlags",value:function(e,t,i){for(var s=arguments.length>3&&void 0!==arguments[3]&&arguments[3],r=this._portionToSubPortionsMap[e],n=0,o=r.length;n3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var r,n,o=!!(t&Qe),a=!!(t&ze),l=!!(t&We),u=!!(t&Ke),A=!!(t&He),c=!!(t&Ve);r=!o||c||a?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,n=!o||c?oo.NOT_RENDERED:u?oo.SILHOUETTE_SELECTED:l?oo.SILHOUETTE_HIGHLIGHTED:a?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED;var h=o&&!c&&A?oo.PICK:oo.NOT_RENDERED,d=this._dataTextureState,p=this.model.scene.canvas.gl;Zu[0]=r,Zu[1]=n,Zu[3]=h,d.texturePerObjectColorsAndFlags._textureData.set(Zu,32*e+8),this._deferredSetFlagsActive||s?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),p.bindTexture(p.TEXTURE_2D,d.texturePerObjectColorsAndFlags._texture),p.texSubImage2D(p.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,p.RGBA_INTEGER,p.UNSIGNED_BYTE,Zu))}},{key:"_setDeferredFlags",value:function(){}},{key:"_setFlags2",value:function(e,t){for(var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=this._portionToSubPortionsMap[e],r=0,n=s.length;r2&&void 0!==arguments[2]&&arguments[2];if(!this._finalized)throw"Not finalized";var s=t&je?255:0,r=this._dataTextureState,n=this.model.scene.canvas.gl;Zu[0]=s,Zu[1]=0,Zu[2]=1,Zu[3]=2,r.texturePerObjectColorsAndFlags._textureData.set(Zu,32*e+12),this._deferredSetFlagsActive||i?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),n.bindTexture(n.TEXTURE_2D,r.texturePerObjectColorsAndFlags._texture),n.texSubImage2D(n.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,n.RGBA_INTEGER,n.UNSIGNED_BYTE,Zu))}},{key:"_setDeferredFlags2",value:function(){}},{key:"setOffset",value:function(e,t){for(var i=this._portionToSubPortionsMap[e],s=0,r=i.length;s=10&&this._beginDeferredFlags(),s.bindTexture(s.TEXTURE_2D,i.texturePerObjectOffsets._texture),s.texSubImage2D(s.TEXTURE_2D,0,0,e,1,1,s.RGB,s.FLOAT,qu))}},{key:"setMatrix",value:function(e,t){for(var i=this._portionToSubPortionsMap[e],s=0,r=i.length;s=10&&this._beginDeferredFlags(),s.bindTexture(s.TEXTURE_2D,i.texturePerObjectInstanceMatrices._texture),s.texSubImage2D(s.TEXTURE_2D,0,e%512*4,Math.floor(e/512),4,1,s.RGBA,s.FLOAT,Yu))}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){}},{key:"drawSilhouetteHighlighted",value:function(e,t){}},{key:"drawSilhouetteSelected",value:function(e,t){}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){}},{key:"drawShadow",value:function(e,t){}},{key:"setPickMatrices",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){}},{key:"drawPickDepths",value:function(e,t){}},{key:"drawSnapInit",value:function(e,t){}},{key:"drawSnap",value:function(e,t){}},{key:"drawPickNormals",value:function(e,t){}},{key:"destroy",value:function(){if(!this._destroyed){var e=this._state;this.model.scene.off(this._onSceneRendering),e.destroy(),this._destroyed=!0}}}]),e}(),iA=$.vec3(),sA=$.vec3(),rA=$.vec3();$.vec3();var nA=$.vec4(),oA=$.mat4(),aA=function(){function e(t,i){x(this,e),this._scene=t,this._withSAO=i,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,i){var s=this._scene,r=s.camera,n=t.model,o=s.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=n.position,c=n.rotationMatrix,h=n.rotationMatrixConjugate;if(this._program||(this._allocate(),!this.errors)){var d,p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,a)),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var f=0!==u[0]||0!==u[1]||0!==u[2],v=0!==A[0]||0!==A[1]||0!==A[2];if(f||v){var g=iA;if(f){var m=$.transformPoint3(c,u,sA);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=A[0],g[1]+=A[1],g[2]+=A[2],d=Re(r.viewMatrix,g,oA),(p=rA)[0]=r.eye[0]-g[0],p[1]=r.eye[1]-g[1],p[2]=r.eye[2]-g[2]}else d=r.viewMatrix,p=r.eye;if(o.uniformMatrix4fv(this._uSceneModelMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,d),o.uniformMatrix4fv(this._uProjMatrix,!1,r.projMatrix),o.uniform3fv(this._uCameraEyeRtc,p),o.uniform1i(this._uRenderPass,i),s.logarithmicDepthBufferEnabled){var _=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,_)}var y=s._sectionPlanesState.getNumAllocatedSectionPlanes(),b=s._sectionPlanesState.sectionPlanes.length;if(y>0)for(var B=s._sectionPlanesState.sectionPlanes,w=t.layerIndex*b,x=n.renderFlags,P=0;P0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),o.drawArrays(o.TRIANGLES,0,a.numIndices8Bits)),a.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),o.drawArrays(o.TRIANGLES,0,a.numIndices16Bits)),a.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),o.drawArrays(o.TRIANGLES,0,a.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl,i=e._lightsState;if(this._program=new kt(t,this._buildShader()),this._program.errors)return this.errors=this._program.errors,void console.error(this.errors);var s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uLightAmbient=s.getLocation("lightAmbient"),this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];for(var r=i.lights,n=0,o=r.length;n0,n=[];n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("uniform mat4 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),t.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("uniform vec4 lightAmbient;");for(var o=0,a=s.lights.length;o> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("} else {"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = sceneModelMatrix * ((objectDecodeAndInstanceMatrix * vec4(position, 1.0))); "),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),n.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),n.push("float lambertian = 1.0;");for(var l=0,u=s.lights.length;l0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesDataTextureColorRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),i){s.push("in vec4 vWorldPosition;"),s.push("flat in uint vFlags2;");for(var r=0,n=t.getNumAllocatedSectionPlanes();r 0u;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var o=0,a=t.getNumAllocatedSectionPlanes();o 0.0) { "),s.push(" discard;"),s.push(" }"),s.push("}")}return e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(s.push(" float viewportWidth = uSAOParams[0];"),s.push(" float viewportHeight = uSAOParams[1];"),s.push(" float blendCutoff = uSAOParams[2];"),s.push(" float blendFactor = uSAOParams[3];"),s.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),s.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),s.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):s.push(" outColor = vColor;"),s.push("}"),s}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),lA=new Float32Array([1,1,1]),uA=$.vec3(),AA=$.vec3(),cA=$.vec3();$.vec3();var hA=$.mat4(),dA=function(){function e(t,i){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=this._scene,r=s.camera,n=t.model,o=s.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=n.position,c=n.rotationMatrix,h=n.rotationMatrixConjugate,d=r.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var p,f;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,a)),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix),u||0!==A[0]||0!==A[1]||0!==A[2]){var v=uA;if(u){var g=AA;$.transformPoint3(c,u,g),v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=A[0],v[1]+=A[1],v[2]+=A[2],p=Re(d,v,hA),(f=cA)[0]=r.eye[0]-v[0],f[1]=r.eye[1]-v[1],f[2]=r.eye[2]-v[2]}else p=d,f=r.eye;if(o.uniform3fv(this._uCameraEyeRtc,f),o.uniform1i(this._uRenderPass,i),o.uniformMatrix4fv(this._uWorldMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,p),o.uniformMatrix4fv(this._uProjMatrix,!1,r.projMatrix),i===oo.SILHOUETTE_XRAYED){var m=s.xrayMaterial._state,_=m.fillColor,y=m.fillAlpha;o.uniform4f(this._uColor,_[0],_[1],_[2],y)}else if(i===oo.SILHOUETTE_HIGHLIGHTED){var b=s.highlightMaterial._state,B=b.fillColor,w=b.fillAlpha;o.uniform4f(this._uColor,B[0],B[1],B[2],w)}else if(i===oo.SILHOUETTE_SELECTED){var x=s.selectedMaterial._state,P=x.fillColor,C=x.fillAlpha;o.uniform4f(this._uColor,P[0],P[1],P[2],C)}else o.uniform4fv(this._uColor,lA);if(s.logarithmicDepthBufferEnabled){var M=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,M)}var F=s._sectionPlanesState.getNumAllocatedSectionPlanes(),E=s._sectionPlanesState.sectionPlanes.length;if(F>0)for(var k=s._sectionPlanesState.sectionPlanes,I=t.layerIndex*E,D=n.renderFlags,S=0;S0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),o.drawArrays(o.TRIANGLES,0,a.numIndices8Bits)),a.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),o.drawArrays(o.TRIANGLES,0,a.numIndices16Bits)),a.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),o.drawArrays(o.TRIANGLES,0,a.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uColor=i.getLocation("color"),this._uWorldMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// Triangles dataTexture silhouette vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;")),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.y) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (solid != 1u) {"),i.push("if (isPerspectiveMatrix(projMatrix)) {"),i.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("viewNormal = -viewNormal;"),i.push("}"),i.push("} else {"),i.push("if (viewNormal.z < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("viewNormal = -viewNormal;"),i.push("}"),i.push("}"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags2 = flags2.r;")),i.push("gl_Position = clipPos;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles dataTexture draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0,o=e._sectionPlanesState.getNumAllocatedSectionPlanes();n 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" outColor = color;"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),pA=new Float32Array([0,0,0,1]),fA=$.vec3(),vA=$.vec3();$.vec3();var gA=$.mat4(),mA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=s.position,c=s.rotationMatrix,h=s.rotationMatrixConjugate,d=n.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var f=0!==u[0]||0!==u[1]||0!==u[2],v=0!==A[0]||0!==A[1]||0!==A[2];if(f||v){var g=fA;if(f){var m=$.transformPoint3(c,u,vA);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=A[0],g[1]+=A[1],g[2]+=A[2],p=Re(d,g,gA)}else p=d;if(o.uniform1i(this._uRenderPass,i),o.uniformMatrix4fv(this._uSceneModelMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,p),o.uniformMatrix4fv(this._uProjMatrix,!1,n.projMatrix),i===oo.EDGES_XRAYED){var _=r.xrayMaterial._state,y=_.edgeColor,b=_.edgeAlpha;o.uniform4f(this._uColor,y[0],y[1],y[2],b)}else if(i===oo.EDGES_HIGHLIGHTED){var B=r.highlightMaterial._state,w=B.edgeColor,x=B.edgeAlpha;o.uniform4f(this._uColor,w[0],w[1],w[2],x)}else if(i===oo.EDGES_SELECTED){var P=r.selectedMaterial._state,C=P.edgeColor,M=P.edgeAlpha;o.uniform4f(this._uColor,C[0],C[1],C[2],M)}else o.uniform4fv(this._uColor,pA);var F=r._sectionPlanesState.getNumAllocatedSectionPlanes(),E=r._sectionPlanesState.sectionPlanes.length;if(F>0)for(var k=r._sectionPlanesState.sectionPlanes,I=t.layerIndex*E,D=s.renderFlags,S=0;S0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),o.drawArrays(o.LINES,0,a.numEdgeIndices8Bits)),a.numEdgeIndices16Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),o.drawArrays(o.LINES,0,a.numEdgeIndices16Bits)),a.numEdgeIndices32Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),o.drawArrays(o.LINES,0,a.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uColor=i.getLocation("color"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uWorldMatrix=i.getLocation("worldMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// DTXTrianglesEdgesRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),i.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),i.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int edgeIndex = gl_VertexID / 2;"),i.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.z) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),i.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),i.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),i.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),i.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),i.push("mat4 matrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2.r;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vColor = vec4(color.r, color.g, color.b, color.a);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// DTXTrianglesEdgesRenderer fragment shader"),e.logarithmicDepthBufferEnabled&&i.push("#extension GL_EXT_frag_depth : enable"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0,o=e._sectionPlanesState.getNumAllocatedSectionPlanes();n 0.0) { discard; }"),i.push("}")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" outColor = vColor;"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),_A=$.vec3(),yA=$.vec3(),bA=$.mat4(),BA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=s.position,c=s.rotationMatrix,h=s.rotationMatrixConjugate,d=n.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var f=0!==u[0]||0!==u[1]||0!==u[2],v=0!==A[0]||0!==A[1]||0!==A[2];if(f||v){var g=_A;if(f){var m=$.transformPoint3(c,u,yA);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=A[0],g[1]+=A[1],g[2]+=A[2],p=Re(d,g,bA)}else p=d;o.uniform1i(this._uRenderPass,i),o.uniformMatrix4fv(this._uSceneModelMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,p),o.uniformMatrix4fv(this._uProjMatrix,!1,n.projMatrix);var _=r._sectionPlanesState.getNumAllocatedSectionPlanes(),y=r._sectionPlanesState.sectionPlanes.length;if(_>0)for(var b=r._sectionPlanesState.sectionPlanes,B=t.layerIndex*y,w=s.renderFlags,x=0;x<_;x++){var P=this._uSectionPlanes[x];if(P)if(x0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),o.drawArrays(o.LINES,0,a.numEdgeIndices8Bits)),a.numEdgeIndices16Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),o.drawArrays(o.LINES,0,a.numEdgeIndices16Bits)),a.numEdgeIndices32Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),o.drawArrays(o.LINES,0,a.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// TrianglesDataTextureEdgesColorRenderer"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled,i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform highp sampler2D uObjectPerObjectOffsets;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),i.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;")),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("out vec4 vColor;"),i.push("void main(void) {"),i.push("int edgeIndex = gl_VertexID / 2;"),i.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.z) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),i.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),i.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),i.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),i.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("};"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2.r;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push("vec4 rgb = vec4(color.rgba);"),i.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// TrianglesDataTextureEdgesColorRenderer"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0,o=e._sectionPlanesState.getNumAllocatedSectionPlanes();n 0.0) { discard; }"),i.push("}")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" outColor = vColor;"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),wA=$.vec3(),xA=$.vec3(),PA=$.vec3(),CA=$.mat4(),MA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e));var s,r,n=t.model,o=n.scene,a=o.camera,l=o.canvas.gl,u=t._state,A=u.textureState,c=t._state.origin,h=n.position,d=n.rotationMatrix,p=n.rotationMatrixConjugate;A.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var f=0!==c[0]||0!==c[1]||0!==c[2],v=0!==h[0]||0!==h[1]||0!==h[2];if(f||v){var g=wA;if(f){var m=$.transformPoint3(d,c,xA);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=h[0],g[1]+=h[1],g[2]+=h[2],s=Re(a.viewMatrix,g,CA),(r=PA)[0]=a.eye[0]-g[0],r[1]=a.eye[1]-g[1],r[2]=a.eye[2]-g[2]}else s=a.viewMatrix,r=a.eye;if(l.uniform2fv(this._uPickClipPos,e.pickClipPos),l.uniform2f(this._uDrawingBufferSize,l.drawingBufferWidth,l.drawingBufferHeight),l.uniformMatrix4fv(this._uSceneModelMatrix,!1,p),l.uniformMatrix4fv(this._uViewMatrix,!1,s),l.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),l.uniform3fv(this._uCameraEyeRtc,r),l.uniform1i(this._uRenderPass,i),o.logarithmicDepthBufferEnabled){var _=2/(Math.log(a.project.far+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,_)}var y=o._sectionPlanesState.getNumAllocatedSectionPlanes(),b=o._sectionPlanesState.sectionPlanes.length;if(y>0)for(var B=o._sectionPlanesState.sectionPlanes,w=t.layerIndex*b,x=n.renderFlags,P=0;P0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),l.drawArrays(l.TRIANGLES,0,u.numIndices8Bits)),u.numIndices16Bits>0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),l.drawArrays(l.TRIANGLES,0,u.numIndices16Bits)),u.numIndices32Bits>0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),l.drawArrays(l.TRIANGLES,0,u.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPickInvisible=i.getLocation("pickInvisible"),this._uPickClipPos=i.getLocation("pickClipPos"),this._uDrawingBufferSize=i.getLocation("drawingBufferSize"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// Batched geometry picking vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform bool pickInvisible;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;")),i.push("uniform vec2 pickClipPos;"),i.push("uniform vec2 drawingBufferSize;"),i.push("vec4 remapClipPos(vec4 clipPos) {"),i.push(" clipPos.xy /= clipPos.w;"),i.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"),i.push(" clipPos.xy *= clipPos.w;"),i.push(" return clipPos;"),i.push("}"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),t&&(i.push("smooth out vec4 vWorldPosition;"),i.push("flat out uvec4 vFlags2;")),i.push("out vec4 vPickColor;"),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.w) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("vPickColor = vec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0)) / 255.0;"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("if (solid != 1u) {"),i.push("if (isPerspectiveMatrix(projMatrix)) {"),i.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("}"),i.push("} else {"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (viewNormal.z < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("}"),i.push("}"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2;")),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Batched geometry picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uvec4 vFlags2;");for(var s=0;s 0.0);"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(s=0;s 0.0) { discard; }"),i.push(" }")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" outPickColor = vPickColor; "),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),FA=$.vec3(),EA=$.vec3(),kA=$.vec3();$.vec3();var IA=$.mat4(),DA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s,r,n=t.model,o=n.scene,a=o.camera,l=o.canvas.gl,u=t._state,A=u.textureState,c=t._state.origin,h=n.position,d=n.rotationMatrix,p=n.rotationMatrixConjugate,f=e.pickViewMatrix||a.viewMatrix;if(this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),A.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix),c||0!==h[0]||0!==h[1]||0!==h[2]){var v=FA;if(c){var g=EA;$.transformPoint3(d,c,g),v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=h[0],v[1]+=h[1],v[2]+=h[2],s=Re(f,v,IA),(r=kA)[0]=a.eye[0]-v[0],r[1]=a.eye[1]-v[1],r[2]=a.eye[2]-v[2],e.snapPickOrigin[0]=v[0],e.snapPickOrigin[1]=v[1],e.snapPickOrigin[2]=v[2]}else s=f,r=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;if(l.uniform3fv(this._uCameraEyeRtc,r),l.uniform1i(this._uRenderPass,i),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniform2fv(this._uPickClipPos,e.pickClipPos),l.uniform2f(this._uDrawingBufferSize,l.drawingBufferWidth,l.drawingBufferHeight),l.uniform1f(this._uPickZNear,e.pickZNear),l.uniform1f(this._uPickZFar,e.pickZFar),l.uniformMatrix4fv(this._uSceneModelMatrix,!1,p),l.uniformMatrix4fv(this._uViewMatrix,!1,s),l.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),o.logarithmicDepthBufferEnabled){var m=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,m)}var _=o._sectionPlanesState.getNumAllocatedSectionPlanes(),y=o._sectionPlanesState.sectionPlanes.length;if(_>0)for(var b=o._sectionPlanesState.sectionPlanes,B=t.layerIndex*y,w=n.renderFlags,x=0;x<_;x++){var P=this._uSectionPlanes[x];if(P)if(x0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),l.drawArrays(l.TRIANGLES,0,u.numIndices8Bits)),u.numIndices16Bits>0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),l.drawArrays(l.TRIANGLES,0,u.numIndices16Bits)),u.numIndices32Bits>0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),l.drawArrays(l.TRIANGLES,0,u.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPickInvisible=i.getLocation("pickInvisible"),this._uPickClipPos=i.getLocation("pickClipPos"),this._uDrawingBufferSize=i.getLocation("drawingBufferSize"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// Triangles dataTexture pick depth vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform bool pickInvisible;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;")),i.push("uniform vec2 pickClipPos;"),i.push("uniform vec2 drawingBufferSize;"),i.push("vec4 remapClipPos(vec4 clipPos) {"),i.push(" clipPos.xy /= clipPos.w;"),i.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"),i.push(" clipPos.xy *= clipPos.w;"),i.push(" return clipPos;"),i.push("}"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("out vec4 vViewPosition;"),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.w) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("};"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("if (solid != 1u) {"),i.push("if (isPerspectiveMatrix(projMatrix)) {"),i.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("}"),i.push("} else {"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (viewNormal.z < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("}"),i.push("}"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2.r;")),i.push("vViewPosition = viewPosition;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = remapClipPos(clipPos);"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles dataTexture pick depth fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),i.push("uniform float pickZNear;"),i.push("uniform float pickZFar;"),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0;s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(s=0;s 0.0) { discard; }"),i.push(" }")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),i.push(" outPackedDepth = packDepth(zNormalizedDepth); "),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),SA=$.vec3(),TA=$.vec3(),RA=$.vec3(),LA=$.vec3();$.vec3();var UA=$.mat4(),OA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s,r,n=t.model,o=n.scene,a=o.camera,l=o.canvas.gl,u=t._state,A=u.textureState,c=t._state.origin,h=n.position,d=n.rotationMatrix,p=n.rotationMatrixConjugate,f=t.aabb,v=e.pickViewMatrix||a.viewMatrix,g=SA;g[0]=$.safeInv(f[3]-f[0])*$.MAX_INT,g[1]=$.safeInv(f[4]-f[1])*$.MAX_INT,g[2]=$.safeInv(f[5]-f[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(g[0]),e.snapPickCoordinateScale[1]=$.safeInv(g[1]),e.snapPickCoordinateScale[2]=$.safeInv(g[2]),A.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var m=0!==c[0]||0!==c[1]||0!==c[2],_=0!==h[0]||0!==h[1]||0!==h[2];if(m||_){var y=TA;if(m){var b=$.transformPoint3(d,c,RA);y[0]=b[0],y[1]=b[1],y[2]=b[2]}else y[0]=0,y[1]=0,y[2]=0;y[0]+=h[0],y[1]+=h[1],y[2]+=h[2],s=Re(v,y,UA),(r=LA)[0]=a.eye[0]-y[0],r[1]=a.eye[1]-y[1],r[2]=a.eye[2]-y[2],e.snapPickOrigin[0]=y[0],e.snapPickOrigin[1]=y[1],e.snapPickOrigin[2]=y[2]}else s=v,r=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;l.uniform3fv(this._uCameraEyeRtc,r),l.uniform2fv(this.uVectorA,e.snapVectorA),l.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),l.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),l.uniform3fv(this._uCoordinateScaler,g),l.uniform1i(this._uRenderPass,i),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniformMatrix4fv(this._uSceneModelMatrix,!1,p),l.uniformMatrix4fv(this._uViewMatrix,!1,s),l.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var B=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,B);var w=o._sectionPlanesState.getNumAllocatedSectionPlanes(),x=o._sectionPlanesState.sectionPlanes.length;if(w>0)for(var P=o._sectionPlanesState.sectionPlanes,C=t.layerIndex*x,M=n.renderFlags,F=0;F0&&(A.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),l.drawArrays(S,0,u.numEdgeIndices8Bits)),u.numEdgeIndices16Bits>0&&(A.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),l.drawArrays(S,0,u.numEdgeIndices16Bits)),u.numEdgeIndices32Bits>0&&(A.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),l.drawArrays(S,0,u.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPickInvisible=i.getLocation("pickInvisible"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// Batched geometry edges drawing vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),i.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 uSnapVectorA;"),i.push("uniform vec2 uSnapInvVectorAB;"),i.push("vec3 positions[3];"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - uSnapVectorA.x) * uSnapInvVectorAB.x;"),i.push(" float y = (clipPos.y - uSnapVectorA.y) * uSnapInvVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("out vec4 vViewPosition;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int edgeIndex = gl_VertexID / 2;"),i.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("{"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),i.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),i.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),i.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),i.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2.r;")),i.push("vViewPosition = viewPosition;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vViewPosition = clipPos;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push("gl_PointSize = 1.0;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles dataTexture pick depth fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int uLayerNumber;"),i.push("uniform vec3 uCoordinateScaler;"),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),i.push(" }")}return i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, uLayerNumber);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),NA=$.vec3(),QA=$.vec3(),VA=$.vec3(),HA=$.vec3();$.vec3();var jA=$.mat4(),GA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var s,r,n=t.model,o=n.scene,a=o.camera,l=o.canvas.gl,u=t._state,A=u.textureState,c=t._state.origin,h=n.position,d=n.rotationMatrix,p=n.rotationMatrixConjugate,f=t.aabb,v=e.pickViewMatrix||a.viewMatrix,g=NA;g[0]=$.safeInv(f[3]-f[0])*$.MAX_INT,g[1]=$.safeInv(f[4]-f[1])*$.MAX_INT,g[2]=$.safeInv(f[5]-f[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(g[0]),e.snapPickCoordinateScale[1]=$.safeInv(g[1]),e.snapPickCoordinateScale[2]=$.safeInv(g[2]),A.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var m=0!==c[0]||0!==c[1]||0!==c[2],_=0!==h[0]||0!==h[1]||0!==h[2];if(m||_){var y=QA;if(m){var b=VA;$.transformPoint3(d,c,b),y[0]=b[0],y[1]=b[1],y[2]=b[2]}else y[0]=0,y[1]=0,y[2]=0;y[0]+=h[0],y[1]+=h[1],y[2]+=h[2],s=Re(v,y,jA),(r=HA)[0]=a.eye[0]-y[0],r[1]=a.eye[1]-y[1],r[2]=a.eye[2]-y[2],e.snapPickOrigin[0]=y[0],e.snapPickOrigin[1]=y[1],e.snapPickOrigin[2]=y[2]}else s=v,r=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;l.uniform3fv(this._uCameraEyeRtc,r),l.uniform2fv(this._uVectorA,e.snapVectorA),l.uniform2fv(this._uInverseVectorAB,e.snapInvVectorAB),l.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),l.uniform3fv(this._uCoordinateScaler,g),l.uniform1i(this._uRenderPass,i),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniformMatrix4fv(this._uSceneWorldModelMatrix,!1,p),l.uniformMatrix4fv(this._uViewMatrix,!1,s),l.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var B=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,B);var w=o._sectionPlanesState.getNumAllocatedSectionPlanes(),x=o._sectionPlanesState.sectionPlanes.length;if(w>0)for(var P=o._sectionPlanesState.sectionPlanes,C=t.layerIndex*x,M=n.renderFlags,F=0;F0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),l.drawArrays(l.TRIANGLES,0,u.numIndices8Bits)),u.numIndices16Bits>0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),l.drawArrays(l.TRIANGLES,0,u.numIndices16Bits)),u.numIndices32Bits>0&&(A.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),l.drawArrays(l.TRIANGLES,0,u.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPickInvisible=i.getLocation("pickInvisible"),this._uSceneWorldModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// DTXTrianglesSnapInitRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("uniform vec2 uVectorAB;"),i.push("uniform vec2 uInverseVectorAB;"),i.push("vec3 positions[3];"),i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("vec2 remapClipPos(vec2 clipPos) {"),i.push(" float x = (clipPos.x - uVectorAB.x) * uInverseVectorAB.x;"),i.push(" float y = (clipPos.y - uVectorAB.y) * uInverseVectorAB.y;"),i.push(" return vec2(x, y);"),i.push("}"),i.push("flat out vec4 vPickColor;"),i.push("out vec4 vWorldPosition;"),t&&i.push("flat out uint vFlags2;"),i.push("out highp vec3 relativeToOriginPosition;"),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("{"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("};"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (solid != 1u) {"),i.push(" if (isPerspectiveMatrix(projMatrix)) {"),i.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push(" position = positions[2 - (gl_VertexID % 3)];"),i.push(" viewNormal = -viewNormal;"),i.push(" }"),i.push(" } else {"),i.push(" if (viewNormal.z < 0.0) {"),i.push(" position = positions[2 - (gl_VertexID % 3)];"),i.push(" viewNormal = -viewNormal;"),i.push(" }"),i.push(" }"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("relativeToOriginPosition = worldPosition.xyz;"),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vWorldPosition = worldPosition;"),t&&i.push("vFlags2 = flags2.r;"),i.push("vPickColor = vec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0));"),i.push("vec4 clipPos = projMatrix * viewPosition;"),i.push("float tmp = clipPos.w;"),i.push("clipPos.xyzw /= tmp;"),i.push("clipPos.xy = remapClipPos(clipPos.xy);"),i.push("clipPos.xyzw *= tmp;"),i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// DTXTrianglesSnapInitRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"),i.push("uniform int uLayerNumber;"),i.push("uniform vec3 uCoordinateScaler;"),i.push("in vec4 vWorldPosition;"),i.push("flat in vec4 vPickColor;"),t){i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),i.push(" }")}return i.push(" float dx = dFdx(vFragDepth);"),i.push(" float dy = dFdy(vFragDepth);"),i.push(" float diff = sqrt(dx*dx+dy*dy);"),i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),i.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, - uLayerNumber);"),i.push("vec3 xTangent = dFdx( vWorldPosition.xyz );"),i.push("vec3 yTangent = dFdy( vWorldPosition.xyz );"),i.push("vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),i.push("outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),i.push("outPickColor = uvec4(vPickColor);"),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),zA=$.vec3(),WA=$.vec3(),KA=$.vec3();$.vec3();var XA=$.mat4(),JA=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=s.position,c=s.rotationMatrix,h=s.rotationMatrixConjugate,d=e.pickViewMatrix||n.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var p,f;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix),u||0!==A[0]||0!==A[1]||0!==A[2]){var v=zA;if(u){var g=WA;$.transformPoint3(c,u,g),v[0]=g[0],v[1]=g[1],v[2]=g[2]}else v[0]=0,v[1]=0,v[2]=0;v[0]+=A[0],v[1]+=A[1],v[2]+=A[2],p=Re(d,v,XA),(f=KA)[0]=n.eye[0]-v[0],f[1]=n.eye[1]-v[1],f[2]=n.eye[2]-v[2]}else p=d,f=n.eye;o.uniform3fv(this._uCameraEyeRtc,f),o.uniform1i(this._uRenderPass,i),o.uniformMatrix4fv(this._uWorldMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,p),o.uniformMatrix4fv(this._uProjMatrix,!1,n.projMatrix);var m=r._sectionPlanesState.getNumAllocatedSectionPlanes(),_=r._sectionPlanesState.sectionPlanes.length;if(m>0)for(var y=r._sectionPlanesState.sectionPlanes,b=t.layerIndex*_,B=s.renderFlags,w=0;w0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),o.drawArrays(o.TRIANGLES,0,a.numIndices8Bits)),a.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),o.drawArrays(o.TRIANGLES,0,a.numIndices16Bits)),a.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),o.drawArrays(o.TRIANGLES,0,a.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPickInvisible=i.getLocation("pickInvisible"),this._uWorldMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// TrianglesDataTextureOcclusionRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("vec3 positions[3];"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.x) != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("};"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("if (solid != 1u) {"),i.push(" if (isPerspectiveMatrix(projMatrix)) {"),i.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push(" position = positions[2 - (gl_VertexID % 3)];"),i.push(" }"),i.push(" } else {"),i.push(" vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push(" if (viewNormal.z < 0.0) {"),i.push(" position = positions[2 - (gl_VertexID % 3)];"),i.push(" }"),i.push(" }"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vec4 clipPos = projMatrix * viewPosition;"),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags2 = flags2.r;")),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// TrianglesDataTextureColorRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0;s 0.0);"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),YA=$.vec3(),ZA=$.vec3(),qA=$.vec3();$.vec3();var $A=$.mat4(),ec=function(){function e(t){x(this,e),this._scene=t,this._allocate(),this._hash=this._getHash()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=this._scene,r=s.camera,n=t.model,o=s.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=n.position,c=n.rotationMatrix,h=n.rotationMatrixConjugate;if(this._program||(this._allocate(),!this.errors)){var d,p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,a)),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var f=0!==u[0]||0!==u[1]||0!==u[2],v=0!==A[0]||0!==A[1]||0!==A[2];if(f||v){var g=YA;if(f){var m=$.transformPoint3(c,u,ZA);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=A[0],g[1]+=A[1],g[2]+=A[2],d=Re(r.viewMatrix,g,$A),(p=qA)[0]=r.eye[0]-g[0],p[1]=r.eye[1]-g[1],p[2]=r.eye[2]-g[2]}else d=r.viewMatrix,p=r.eye;if(o.uniformMatrix4fv(this._uSceneModelMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,d),o.uniformMatrix4fv(this._uProjMatrix,!1,r.projMatrix),o.uniform3fv(this._uCameraEyeRtc,p),o.uniform1i(this._uRenderPass,i),s.logarithmicDepthBufferEnabled){var _=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,_)}var y=s._sectionPlanesState.getNumAllocatedSectionPlanes(),b=s._sectionPlanesState.sectionPlanes.length;if(y>0)for(var B=s._sectionPlanesState.sectionPlanes,w=t.layerIndex*b,x=n.renderFlags,P=0;P0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),o.drawArrays(o.TRIANGLES,0,a.numIndices8Bits)),a.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),o.drawArrays(o.TRIANGLES,0,a.numIndices16Bits)),a.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),o.drawArrays(o.TRIANGLES,0,a.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPositionsDecodeMatrix=i.getLocation("objectDecodeAndInstanceMatrix"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// Triangles dataTexture draw vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;")),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out highp vec2 vHighPrecisionZW;"),t&&(i.push("out vec4 vWorldPosition;"),i.push("flat out uint vFlags2;")),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.x) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("};"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (solid != 1u) {"),i.push("if (isPerspectiveMatrix(projMatrix)) {"),i.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("viewNormal = -viewNormal;"),i.push("}"),i.push("} else {"),i.push("if (viewNormal.z < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("viewNormal = -viewNormal;"),i.push("}"),i.push("}"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(i.push("vWorldPosition = worldPosition;"),i.push("vFlags2 = flags2.r;")),i.push("gl_Position = clipPos;"),i.push("vHighPrecisionZW = gl_Position.zw;"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles dataTexture draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in highp vec2 vHighPrecisionZW;"),i.push("out vec4 outColor;"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),t){i.push("in vec4 vWorldPosition;"),i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0,o=e._sectionPlanesState.getNumAllocatedSectionPlanes();n 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),i.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),tc=$.vec3(),ic=$.vec3(),sc=$.vec3();$.vec3();var rc=$.mat4(),nc=function(){function e(t){x(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,i){var s=t.model,r=s.scene,n=r.camera,o=r.canvas.gl,a=t._state,l=t._state.origin,u=s.position,A=s.rotationMatrix,c=s.rotationMatrixConjugate,h=n.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var d,p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(t));var f=0!==l[0]||0!==l[1]||0!==l[2],v=0!==u[0]||0!==u[1]||0!==u[2];if(f||v){var g=tc;if(f){var m=ic;$.transformPoint3(A,l,m),g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=u[0],g[1]+=u[1],g[2]+=u[2],d=Re(h,g,rc),(p=sc)[0]=n.eye[0]-g[0],p[1]=n.eye[1]-g[1],p[2]=n.eye[2]-g[2]}else d=h,p=n.eye;o.uniform1i(this._uRenderPass,i),o.uniformMatrix4fv(this._uWorldMatrix,!1,c),o.uniformMatrix4fv(this._uViewMatrix,!1,d),o.uniformMatrix4fv(this._uProjMatrix,!1,n.projMatrix),o.uniformMatrix4fv(this._uViewNormalMatrix,!1,n.viewNormalMatrix),o.uniformMatrix4fv(this._uWorldNormalMatrix,!1,s.worldNormalMatrix);var _=r._sectionPlanesState.getNumAllocatedSectionPlanes(),y=r._sectionPlanesState.sectionPlanes.length;if(_>0)for(var b=r._sectionPlanesState.sectionPlanes,B=t.layerIndex*y,w=s.renderFlags,x=0;x<_;x++){var P=this._uSectionPlanes[x];if(P)if(x0,i=[];return i.push("// Batched geometry normals vertex shader"),e.logarithmicDepthBufferEnabled&&yt.SUPPORTED_EXTENSIONS.EXT_frag_depth&&i.push("#extension GL_EXT_frag_depth : enable"),i.push("uniform int renderPass;"),i.push("attribute vec3 position;"),e.entityOffsetsEnabled&&i.push("attribute vec3 offset;"),i.push("attribute vec3 normal;"),i.push("attribute vec4 color;"),i.push("attribute vec4 flags;"),i.push("attribute vec4 flags2;"),i.push("uniform mat4 worldMatrix;"),i.push("uniform mat4 worldNormalMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform mat4 viewNormalMatrix;"),i.push("uniform mat4 objectDecodeAndInstanceMatrix;"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),yt.SUPPORTED_EXTENSIONS.EXT_frag_depth&&i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("varying float isPerspective;")),i.push("vec3 octDecode(vec2 oct) {"),i.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),i.push(" if (v.z < 0.0) {"),i.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),i.push(" }"),i.push(" return normalize(v);"),i.push("}"),t&&(i.push("out vec4 vWorldPosition;"),i.push("out vec4 vFlags2;")),i.push("out vec3 vViewNormal;"),i.push("void main(void) {"),i.push("if (int(flags.x) != renderPass) {"),i.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),i.push(" } else {"),i.push(" vec4 worldPosition = worldMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition; "),i.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),i.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(i.push(" vWorldPosition = worldPosition;"),i.push(" vFlags2 = flags2;")),i.push(" vViewNormal = viewNormal;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(yt.SUPPORTED_EXTENSIONS.EXT_frag_depth?i.push("vFragDepth = 1.0 + clipPos.w;"):(i.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;"),i.push("clipPos.z *= clipPos.w;")),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("gl_Position = clipPos;"),i.push(" }"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// Batched geometry normals fragment shader"),e.logarithmicDepthBufferEnabled&&yt.SUPPORTED_EXTENSIONS.EXT_frag_depth&&i.push("#extension GL_EXT_frag_depth : enable"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&yt.SUPPORTED_EXTENSIONS.EXT_frag_depth&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),t){i.push("in vec4 vWorldPosition;"),i.push("in vec4 vFlags2;");for(var s=0;s 0.0);"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var r=0;r 0.0) { discard; }"),i.push(" }")}return e.logarithmicDepthBufferEnabled&&yt.SUPPORTED_EXTENSIONS.EXT_frag_depth&&i.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" gl_FragColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),oc=$.vec3(),ac=$.vec3(),lc=$.vec3();$.vec3(),$.vec4();var uc=$.mat4(),Ac=function(){function e(t,i){x(this,e),this._scene=t,this._withSAO=i,this._hash=this._getHash(),this._allocate()}return C(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,i){var s=this._scene,r=s.camera,n=t.model,o=s.canvas.gl,a=t._state,l=a.textureState,u=t._state.origin,A=n.position,c=n.rotationMatrix,h=n.rotationMatrixConjugate;if(this._program||(this._allocate(),!this.errors)){var d,p;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,a)),l.bindCommonTextures(this._program,this.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);var f=0!==u[0]||0!==u[1]||0!==u[2],v=0!==A[0]||0!==A[1]||0!==A[2];if(f||v){var g=oc;if(f){var m=$.transformPoint3(c,u,ac);g[0]=m[0],g[1]=m[1],g[2]=m[2]}else g[0]=0,g[1]=0,g[2]=0;g[0]+=A[0],g[1]+=A[1],g[2]+=A[2],d=Re(r.viewMatrix,g,uc),(p=lc)[0]=r.eye[0]-g[0],p[1]=r.eye[1]-g[1],p[2]=r.eye[2]-g[2]}else d=r.viewMatrix,p=r.eye;if(o.uniform2fv(this._uPickClipPos,e.pickClipPos),o.uniform2f(this._uDrawingBufferSize,o.drawingBufferWidth,o.drawingBufferHeight),o.uniformMatrix4fv(this._uSceneModelMatrix,!1,h),o.uniformMatrix4fv(this._uViewMatrix,!1,d),o.uniformMatrix4fv(this._uProjMatrix,!1,r.projMatrix),o.uniform3fv(this._uCameraEyeRtc,p),o.uniform1i(this._uRenderPass,i),s.logarithmicDepthBufferEnabled){var _=2/(Math.log(e.pickZFar+1)/Math.LN2);o.uniform1f(this._uLogDepthBufFC,_)}var y=s._sectionPlanesState.getNumAllocatedSectionPlanes(),b=s._sectionPlanesState.sectionPlanes.length;if(y>0)for(var B=s._sectionPlanesState.sectionPlanes,w=t.layerIndex*b,x=n.renderFlags,P=0;P0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),o.drawArrays(o.TRIANGLES,0,a.numIndices8Bits)),a.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),o.drawArrays(o.TRIANGLES,0,a.numIndices16Bits)),a.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),o.drawArrays(o.TRIANGLES,0,a.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new kt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uRenderPass=i.getLocation("renderPass"),this._uPickInvisible=i.getLocation("pickInvisible"),this._uPickClipPos=i.getLocation("pickClipPos"),this._uDrawingBufferSize=i.getLocation("drawingBufferSize"),this._uSceneModelMatrix=i.getLocation("sceneModelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s0,i=[];return i.push("#version 300 es"),i.push("// trianglesDatatextureNormalsRenderer vertex shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("precision highp usampler2D;"),i.push("precision highp isampler2D;"),i.push("precision highp sampler2D;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("precision mediump usampler2D;"),i.push("precision mediump isampler2D;"),i.push("precision mediump sampler2D;"),i.push("#endif"),i.push("uniform int renderPass;"),e.entityOffsetsEnabled&&i.push("in vec3 offset;"),i.push("uniform mat4 sceneModelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),i.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),i.push("uniform highp sampler2D uTexturePerObjectMatrix;"),i.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),i.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),i.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),i.push("uniform vec3 uCameraEyeRtc;"),i.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("out float isPerspective;")),i.push("uniform vec2 pickClipPos;"),i.push("uniform vec2 drawingBufferSize;"),i.push("vec4 remapClipPos(vec4 clipPos) {"),i.push(" clipPos.xy /= clipPos.w;"),i.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"),i.push(" clipPos.xy *= clipPos.w;"),i.push(" return clipPos;"),i.push("}"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out vec4 vWorldPosition;"),t&&i.push("flat out uint vFlags2;"),i.push("void main(void) {"),i.push("int polygonIndex = gl_VertexID / 3;"),i.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),i.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),i.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),i.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),i.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),i.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),i.push("if (int(flags.w) != renderPass) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("} else {"),i.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),i.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),i.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),i.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),i.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),i.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),i.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),i.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),i.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),i.push("mat4 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),i.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),i.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),i.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),i.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),i.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),i.push("if (color.a == 0u) {"),i.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),i.push(" return;"),i.push("};"),i.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),i.push("vec3 position;"),i.push("position = positions[gl_VertexID % 3];"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (solid != 1u) {"),i.push("if (isPerspectiveMatrix(projMatrix)) {"),i.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),i.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("viewNormal = -viewNormal;"),i.push("}"),i.push("} else {"),i.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),i.push("if (viewNormal.z < 0.0) {"),i.push("position = positions[2 - (gl_VertexID % 3)];"),i.push("}"),i.push("}"),i.push("}"),i.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),i.push("vec4 viewPosition = viewMatrix * worldPosition; "),i.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i.push("vWorldPosition = worldPosition;"),t&&i.push("vFlags2 = flags2.r;"),i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i.push("}"),i}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,i=[];if(i.push("#version 300 es"),i.push("// TrianglesDataTexturePickNormalsRenderer fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),i.push("in vec4 vWorldPosition;"),t){i.push("flat in uint vFlags2;");for(var s=0,r=e._sectionPlanesState.getNumAllocatedSectionPlanes();s 0u;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var n=0,o=e._sectionPlanesState.getNumAllocatedSectionPlanes();n 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}return e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),i.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),i.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),i.push(" outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),i.push("}"),i}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),cc=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorQualityRendererWithSAO&&!this._colorQualityRendererWithSAO.getValid()&&(this._colorQualityRendererWithSAO.destroy(),this._colorQualityRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._snapRenderer&&!this._snapRenderer.getValid()&&(this._snapRenderer.destroy(),this._snapRenderer=null),this._snapInitRenderer&&!this._snapInitRenderer.getValid()&&(this._snapInitRenderer.destroy(),this._snapInitRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}},{key:"eagerCreateRenders",value:function(){this._silhouetteRenderer||(this._silhouetteRenderer=new dA(this._scene)),this._pickMeshRenderer||(this._pickMeshRenderer=new MA(this._scene)),this._pickDepthRenderer||(this._pickDepthRenderer=new DA(this._scene)),this._pickNormalsRenderer||(this._pickNormalsRenderer=new Ac(this._scene)),this._snapRenderer||(this._snapRenderer=new OA(this._scene)),this._snapInitRenderer||(this._snapInitRenderer=new GA(this._scene)),this._snapRenderer||(this._snapRenderer=new OA(this._scene))}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new aA(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new aA(this._scene,!0)),this._colorRendererWithSAO}},{key:"colorQualityRendererWithSAO",get:function(){return this._colorQualityRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new dA(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new ec(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new nc(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new mA(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new BA(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new MA(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new Ac(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new Ac(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new DA(this._scene)),this._pickDepthRenderer}},{key:"snapRenderer",get:function(){return this._snapRenderer||(this._snapRenderer=new OA(this._scene)),this._snapRenderer}},{key:"snapInitRenderer",get:function(){return this._snapInitRenderer||(this._snapInitRenderer=new GA(this._scene)),this._snapInitRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new JA(this._scene)),this._occlusionRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._colorQualityRendererWithSAO&&this._colorQualityRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._snapRenderer&&this._snapRenderer.destroy(),this._snapInitRenderer&&this._snapInitRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}]),e}(),hc={};var dc=C((function e(){x(this,e),this.positionsCompressed=[],this.lenPositionsCompressed=0,this.metallicRoughness=[],this.indices8Bits=[],this.lenIndices8Bits=0,this.indices16Bits=[],this.lenIndices16Bits=0,this.indices32Bits=[],this.lenIndices32Bits=0,this.edgeIndices8Bits=[],this.lenEdgeIndices8Bits=0,this.edgeIndices16Bits=[],this.lenEdgeIndices16Bits=0,this.edgeIndices32Bits=[],this.lenEdgeIndices32Bits=0,this.perObjectColors=[],this.perObjectPickColors=[],this.perObjectSolid=[],this.perObjectOffsets=[],this.perObjectPositionsDecodeMatrices=[],this.perObjectInstancePositioningMatrices=[],this.perObjectVertexBases=[],this.perObjectIndexBaseOffsets=[],this.perObjectEdgeIndexBaseOffsets=[],this.perTriangleNumberPortionId8Bits=[],this.perTriangleNumberPortionId16Bits=[],this.perTriangleNumberPortionId32Bits=[],this.perEdgeNumberPortionId8Bits=[],this.perEdgeNumberPortionId16Bits=[],this.perEdgeNumberPortionId32Bits=[]})),pc=function(){function e(){x(this,e),this.texturePerObjectColorsAndFlags=null,this.texturePerObjectOffsets=null,this.texturePerObjectInstanceMatrices=null,this.texturePerObjectPositionsDecodeMatrix=null,this.texturePerVertexIdCoordinates=null,this.texturePerPolygonIdPortionIds8Bits=null,this.texturePerPolygonIdPortionIds16Bits=null,this.texturePerPolygonIdPortionIds32Bits=null,this.texturePerEdgeIdPortionIds8Bits=null,this.texturePerEdgeIdPortionIds16Bits=null,this.texturePerEdgeIdPortionIds32Bits=null,this.texturePerPolygonIdIndices8Bits=null,this.texturePerPolygonIdIndices16Bits=null,this.texturePerPolygonIdIndices32Bits=null,this.texturePerPolygonIdEdgeIndices8Bits=null,this.texturePerPolygonIdEdgeIndices16Bits=null,this.texturePerPolygonIdEdgeIndices32Bits=null,this.textureModelMatrices=null}return C(e,[{key:"finalize",value:function(){this.indicesPerBitnessTextures={8:this.texturePerPolygonIdIndices8Bits,16:this.texturePerPolygonIdIndices16Bits,32:this.texturePerPolygonIdIndices32Bits},this.indicesPortionIdsPerBitnessTextures={8:this.texturePerPolygonIdPortionIds8Bits,16:this.texturePerPolygonIdPortionIds16Bits,32:this.texturePerPolygonIdPortionIds32Bits},this.edgeIndicesPerBitnessTextures={8:this.texturePerPolygonIdEdgeIndices8Bits,16:this.texturePerPolygonIdEdgeIndices16Bits,32:this.texturePerPolygonIdEdgeIndices32Bits},this.edgeIndicesPortionIdsPerBitnessTextures={8:this.texturePerEdgeIdPortionIds8Bits,16:this.texturePerEdgeIdPortionIds16Bits,32:this.texturePerEdgeIdPortionIds32Bits}}},{key:"bindCommonTextures",value:function(e,t,i,s,r){this.texturePerObjectPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,i,2),this.texturePerObjectColorsAndFlags.bindTexture(e,s,3),this.texturePerObjectInstanceMatrices.bindTexture(e,r,4)}},{key:"bindTriangleIndicesTextures",value:function(e,t,i,s){this.indicesPortionIdsPerBitnessTextures[s].bindTexture(e,t,5),this.indicesPerBitnessTextures[s].bindTexture(e,i,6)}},{key:"bindEdgeIndicesTextures",value:function(e,t,i,s){this.edgeIndicesPortionIdsPerBitnessTextures[s].bindTexture(e,t,5),this.edgeIndicesPerBitnessTextures[s].bindTexture(e,i,6)}}]),e}(),fc={sizeDataColorsAndFlags:0,sizeDataPositionDecodeMatrices:0,sizeDataTextureOffsets:0,sizeDataTexturePositions:0,sizeDataTextureIndices:0,sizeDataTextureEdgeIndices:0,sizeDataTexturePortionIds:0,numberOfGeometries:0,numberOfPortions:0,numberOfLayers:0,numberOfTextures:0,totalPolygons:0,totalPolygons8Bits:0,totalPolygons16Bits:0,totalPolygons32Bits:0,totalEdges:0,totalEdges8Bits:0,totalEdges16Bits:0,totalEdges32Bits:0,cannotCreatePortion:{because10BitsObjectId:0,becauseTextureSize:0},overheadSizeAlignementIndices:0,overheadSizeAlignementEdgeIndices:0};window.printDataTextureRamStats=function(){console.log(JSON.stringify(fc,null,4));var e=0;Object.keys(fc).forEach((function(t){t.startsWith("size")&&(e+=fc[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/fc.totalPolygons).toFixed(2)));var t={};Object.keys(fc).forEach((function(i){i.startsWith("size")&&(t[i]="".concat((fc[i]/e*100).toFixed(2)," % of total"))})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};var vc=function(){function e(){x(this,e)}return C(e,[{key:"disableBindedTextureFiltering",value:function(e){e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}},{key:"createTextureForColorsAndFlags",value:function(e,t,i,s,r,n,o){var a=t.length;this.numPortions=a;var l=4096,u=Math.ceil(a/512);if(0===u)throw"texture height===0";var A=new Uint8Array(16384*u);fc.sizeDataColorsAndFlags+=A.byteLength,fc.numberOfTextures++;for(var c=0;c>24&255,s[c]>>16&255,s[c]>>8&255,255&s[c]],32*c+16),A.set([r[c]>>24&255,r[c]>>16&255,r[c]>>8&255,255&r[c]],32*c+20),A.set([n[c]>>24&255,n[c]>>16&255,n[c]>>8&255,255&n[c]],32*c+24),A.set([o[c]?1:0,0,0,0],32*c+28);var h=e.createTexture();return e.bindTexture(e.TEXTURE_2D,h),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8UI,l,u),e.texSubImage2D(e.TEXTURE_2D,0,0,0,l,u,e.RGBA_INTEGER,e.UNSIGNED_BYTE,A,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new zu(e,h,l,u,A)}},{key:"createTextureForObjectOffsets",value:function(e,t){var i=512,s=Math.ceil(t/i);if(0===s)throw"texture height===0";var r=new Float32Array(1536*s).fill(0);fc.sizeDataTextureOffsets+=r.byteLength,fc.numberOfTextures++;var n=e.createTexture();return e.bindTexture(e.TEXTURE_2D,n),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32F,i,s),e.texSubImage2D(e.TEXTURE_2D,0,0,0,i,s,e.RGB,e.FLOAT,r,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new zu(e,n,i,s,r)}},{key:"createTextureForInstancingMatrices",value:function(e,t){var i=t.length;if(0===i)throw"num instance matrices===0";var s=2048,r=Math.ceil(i/512),n=new Float32Array(8192*r);fc.numberOfTextures++;for(var o=0;o65536&&fc.cannotCreatePortion.because10BitsObjectId++;var i=this._numPortions+t<=65536,s=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(0):"".concat(e.id,"#").concat(0);if(!this._bucketGeometries[s]){var r=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits),n=0,o=0;e.buckets.forEach((function(e){n+=e.positionsCompressed.length/3,o+=e.indices.length/3})),(this._state.numVertices+n>4096*mc||r+o>4096*mc)&&fc.cannotCreatePortion.becauseTextureSize++,i&&(i=this._state.numVertices+n<=4096*mc&&r+o<=4096*mc)}return i}},{key:"createPortion",value:function(e,t){var i=this;if(this._finalized)throw"Already finalized";var s=[];t.buckets.forEach((function(e,r){var n=void 0!==t.geometryId&&null!==t.geometryId?"".concat(t.geometryId,"#").concat(r):"".concat(t.id,"#").concat(r),o=i._bucketGeometries[n];o||(o=i._createBucketGeometry(t,e),i._bucketGeometries[n]=o);var a=i._createSubPortion(t,o,e);s.push(a)}));var r=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(s),this.model.numPortions++,this._meshes.push(e),r}},{key:"_createBucketGeometry",value:function(e,t){if(t.indices){var i=8*Math.ceil(t.indices.length/3/8)*3;fc.overheadSizeAlignementIndices+=2*(i-t.indices.length);var s=new Uint32Array(i);s.fill(0),s.set(t.indices),t.indices=s}if(t.edgeIndices){var r=8*Math.ceil(t.edgeIndices.length/2/8)*2;fc.overheadSizeAlignementEdgeIndices+=2*(r-t.edgeIndices.length);var n=new Uint32Array(r);n.fill(0),n.set(t.edgeIndices),t.edgeIndices=n}var o=t.positionsCompressed,a=t.indices,l=t.edgeIndices,u=this._buffer;u.positionsCompressed.push(o);var A,c=u.lenPositionsCompressed/3,h=o.length/3;u.lenPositionsCompressed+=o.length;var d,p,f=0;a&&(f=a.length/3,h<=256?(d=u.indices8Bits,A=u.lenIndices8Bits/3,u.lenIndices8Bits+=a.length):h<=65536?(d=u.indices16Bits,A=u.lenIndices16Bits/3,u.lenIndices16Bits+=a.length):(d=u.indices32Bits,A=u.lenIndices32Bits/3,u.lenIndices32Bits+=a.length),d.push(a));var v,g=0;l&&(g=l.length/2,h<=256?(v=u.edgeIndices8Bits,p=u.lenEdgeIndices8Bits/2,u.lenEdgeIndices8Bits+=l.length):h<=65536?(v=u.edgeIndices16Bits,p=u.lenEdgeIndices16Bits/2,u.lenEdgeIndices16Bits+=l.length):(v=u.edgeIndices32Bits,p=u.lenEdgeIndices32Bits/2,u.lenEdgeIndices32Bits+=l.length),v.push(l));return this._state.numVertices+=h,fc.numberOfGeometries++,{vertexBase:c,numVertices:h,numTriangles:f,numEdges:g,indicesBase:A,edgeIndicesBase:p}}},{key:"_createSubPortion",value:function(e,t,i,s){var r=e.color;e.metallic,e.roughness;var n,o,a=e.colors,l=e.opacity,u=e.meshMatrix,A=e.pickColor,c=this._buffer,h=this._state;c.perObjectPositionsDecodeMatrices.push(e.positionsDecodeMatrix),c.perObjectInstancePositioningMatrices.push(u||wc),c.perObjectSolid.push(!!e.solid),a?c.perObjectColors.push([255*a[0],255*a[1],255*a[2],255]):r&&c.perObjectColors.push([r[0],r[1],r[2],l]),c.perObjectPickColors.push(A),c.perObjectVertexBases.push(t.vertexBase),n=t.numVertices<=256?h.numIndices8Bits:t.numVertices<=65536?h.numIndices16Bits:h.numIndices32Bits,c.perObjectIndexBaseOffsets.push(n/3-t.indicesBase),o=t.numVertices<=256?h.numEdgeIndices8Bits:t.numVertices<=65536?h.numEdgeIndices16Bits:h.numEdgeIndices32Bits,c.perObjectEdgeIndexBaseOffsets.push(o/2-t.edgeIndicesBase);var d=this._subPortions.length;if(t.numTriangles>0){var p,f=3*t.numTriangles;t.numVertices<=256?(p=c.perTriangleNumberPortionId8Bits,h.numIndices8Bits+=f,fc.totalPolygons8Bits+=t.numTriangles):t.numVertices<=65536?(p=c.perTriangleNumberPortionId16Bits,h.numIndices16Bits+=f,fc.totalPolygons16Bits+=t.numTriangles):(p=c.perTriangleNumberPortionId32Bits,h.numIndices32Bits+=f,fc.totalPolygons32Bits+=t.numTriangles),fc.totalPolygons+=t.numTriangles;for(var v=0;v0){var g,m=2*t.numEdges;t.numVertices<=256?(g=c.perEdgeNumberPortionId8Bits,h.numEdgeIndices8Bits+=m,fc.totalEdges8Bits+=t.numEdges):t.numVertices<=65536?(g=c.perEdgeNumberPortionId16Bits,h.numEdgeIndices16Bits+=m,fc.totalEdges16Bits+=t.numEdges):(g=c.perEdgeNumberPortionId32Bits,h.numEdgeIndices32Bits+=m,fc.totalEdges32Bits+=t.numEdges),fc.totalEdges+=t.numEdges;for(var _=0;_0&&(i.texturePerEdgeIdPortionIds8Bits=this._dtxTextureFactory.createTextureForPackedPortionIds(s,r.perEdgeNumberPortionId8Bits)),r.perEdgeNumberPortionId16Bits.length>0&&(i.texturePerEdgeIdPortionIds16Bits=this._dtxTextureFactory.createTextureForPackedPortionIds(s,r.perEdgeNumberPortionId16Bits)),r.perEdgeNumberPortionId32Bits.length>0&&(i.texturePerEdgeIdPortionIds32Bits=this._dtxTextureFactory.createTextureForPackedPortionIds(s,r.perEdgeNumberPortionId32Bits)),r.lenIndices8Bits>0&&(i.texturePerPolygonIdIndices8Bits=this._dtxTextureFactory.createTextureFor8BitIndices(s,r.indices8Bits,r.lenIndices8Bits)),r.lenIndices16Bits>0&&(i.texturePerPolygonIdIndices16Bits=this._dtxTextureFactory.createTextureFor16BitIndices(s,r.indices16Bits,r.lenIndices16Bits)),r.lenIndices32Bits>0&&(i.texturePerPolygonIdIndices32Bits=this._dtxTextureFactory.createTextureFor32BitIndices(s,r.indices32Bits,r.lenIndices32Bits)),r.lenEdgeIndices8Bits>0&&(i.texturePerPolygonIdEdgeIndices8Bits=this._dtxTextureFactory.createTextureFor8BitsEdgeIndices(s,r.edgeIndices8Bits,r.lenEdgeIndices8Bits)),r.lenEdgeIndices16Bits>0&&(i.texturePerPolygonIdEdgeIndices16Bits=this._dtxTextureFactory.createTextureFor16BitsEdgeIndices(s,r.edgeIndices16Bits,r.lenEdgeIndices16Bits)),r.lenEdgeIndices32Bits>0&&(i.texturePerPolygonIdEdgeIndices32Bits=this._dtxTextureFactory.createTextureFor32BitsEdgeIndices(s,r.edgeIndices32Bits,r.lenEdgeIndices32Bits)),i.finalize(),this._buffer=null,this._bucketGeometries={},this._finalized=!0,this._deferredSetFlagsDirty=!1,this._onSceneRendering=this.model.scene.on("rendering",(function(){e._deferredSetFlagsDirty&&e._uploadDeferredFlags(),e._numUpdatesInFrame=0}))}}},{key:"isEmpty",value:function(){return 0===this._numPortions}},{key:"initFlags",value:function(e,t,i){t&Qe&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&We&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&ze&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Ke&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&je&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Xe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&He&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ve&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),i&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,i,true),this._setFlags2(e,t,true)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags(),this._setDeferredFlags2()}},{key:"setVisible",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Qe?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,i)}},{key:"setHighlighted",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&We?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,i)}},{key:"setXRayed",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&ze?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,i)}},{key:"setSelected",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ke?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,i)}},{key:"setEdges",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Xe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,i)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&je?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags2(e,t)}},{key:"_beginDeferredFlags",value:function(){this._deferredSetFlagsActive=!0}},{key:"_uploadDeferredFlags",value:function(){if(this._deferredSetFlagsActive=!1,this._deferredSetFlagsDirty){this._deferredSetFlagsDirty=!1;var e=this.model.scene.canvas.gl,t=this._dtxState;e.bindTexture(e.TEXTURE_2D,t.texturePerObjectColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectColorsAndFlags._textureWidth,t.texturePerObjectColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectColorsAndFlags._textureData)}}},{key:"setCulled",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&Ve?(this._numCulledLayerPortions+=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions-=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions--),this._setFlags(e,t,i)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,i){if(!this._finalized)throw"Not finalized";t&He?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,i)}},{key:"setColor",value:function(e,t){for(var i=this._portionToSubPortionsMap[e],s=0,r=i.length;s=10&&this._beginDeferredFlags(),console.info("_subPortionSetColor write through"),s.bindTexture(s.TEXTURE_2D,i.texturePerObjectColorsAndFlags._texture),s.texSubImage2D(s.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,s.RGBA_INTEGER,s.UNSIGNED_BYTE,yc)}},{key:"setTransparent",value:function(e,t,i){i?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,i)}},{key:"_setFlags",value:function(e,t,i){for(var s=arguments.length>3&&void 0!==arguments[3]&&arguments[3],r=this._portionToSubPortionsMap[e],n=0,o=r.length;n3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var r,n,o=!!(t&Qe),a=!!(t&ze),l=!!(t&We),u=!!(t&Ke),A=!!(t&Xe),c=!!(t&He),h=!!(t&Ve);r=!o||h||a||l&&!this.model.scene.highlightMaterial.glowThrough||u&&!this.model.scene.selectedMaterial.glowThrough?oo.NOT_RENDERED:i?oo.COLOR_TRANSPARENT:oo.COLOR_OPAQUE,n=!o||h?oo.NOT_RENDERED:u?oo.SILHOUETTE_SELECTED:l?oo.SILHOUETTE_HIGHLIGHTED:a?oo.SILHOUETTE_XRAYED:oo.NOT_RENDERED;var d=0;d=!o||h?oo.NOT_RENDERED:u?oo.EDGES_SELECTED:l?oo.EDGES_HIGHLIGHTED:a?oo.EDGES_XRAYED:A?i?oo.EDGES_COLOR_TRANSPARENT:oo.EDGES_COLOR_OPAQUE:oo.NOT_RENDERED;var p=o&&!h&&c?oo.PICK:oo.NOT_RENDERED,f=this._dtxState,v=this.model.scene.canvas.gl;yc[0]=r,yc[1]=n,yc[2]=d,yc[3]=p,f.texturePerObjectColorsAndFlags._textureData.set(yc,32*e+8),this._deferredSetFlagsActive||s?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),v.bindTexture(v.TEXTURE_2D,f.texturePerObjectColorsAndFlags._texture),v.texSubImage2D(v.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,v.RGBA_INTEGER,v.UNSIGNED_BYTE,yc))}},{key:"_setDeferredFlags",value:function(){}},{key:"_setFlags2",value:function(e,t){for(var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=this._portionToSubPortionsMap[e],r=0,n=s.length;r2&&void 0!==arguments[2]&&arguments[2];if(!this._finalized)throw"Not finalized";var s=t&je?255:0,r=this._dtxState,n=this.model.scene.canvas.gl;yc[0]=s,yc[1]=0,yc[2]=1,yc[3]=2,r.texturePerObjectColorsAndFlags._textureData.set(yc,32*e+12),this._deferredSetFlagsActive||i?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),n.bindTexture(n.TEXTURE_2D,r.texturePerObjectColorsAndFlags._texture),n.texSubImage2D(n.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,n.RGBA_INTEGER,n.UNSIGNED_BYTE,yc))}},{key:"_setDeferredFlags2",value:function(){}},{key:"setOffset",value:function(e,t){for(var i=this._portionToSubPortionsMap[e],s=0,r=i.length;s=10&&this._beginDeferredFlags(),s.bindTexture(s.TEXTURE_2D,i.texturePerObjectOffsets._texture),s.texSubImage2D(s.TEXTURE_2D,0,0,e,1,1,s.RGB,s.FLOAT,bc))}},{key:"setMatrix",value:function(e,t){for(var i=this._portionToSubPortionsMap[e],s=0,r=i.length;s=10&&this._beginDeferredFlags(),s.bindTexture(s.TEXTURE_2D,i.texturePerObjectInstanceMatrices._texture),s.texSubImage2D(s.TEXTURE_2D,0,e%512*4,Math.floor(e/512),4,1,s.RGBA,s.FLOAT,_c))}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.withSAO&&this.model.saoEnabled?this._renderers.colorRendererWithSAO&&this._renderers.colorRendererWithSAO.drawLayer(t,this,oo.COLOR_OPAQUE):this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_OPAQUE))}},{key:"_updateBackfaceCull",value:function(e,t){var i=this.model.backfaces||e.sectioned;if(t.backfaces!==i){var s=t.gl;i?s.disable(s.CULL_FACE):s.enable(s.CULL_FACE),t.backfaces=i}}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._renderers.colorRenderer&&this._renderers.colorRenderer.drawLayer(t,this,oo.COLOR_TRANSPARENT))}},{key:"drawDepth",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._renderers.depthRenderer&&this._renderers.depthRenderer.drawLayer(t,this,oo.COLOR_OPAQUE))}},{key:"drawNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._renderers.normalsRenderer&&this._renderers.normalsRenderer.drawLayer(t,this,oo.COLOR_OPAQUE))}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_XRAYED))}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_HIGHLIGHTED))}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.silhouetteRenderer&&this._renderers.silhouetteRenderer.drawLayer(t,this,oo.SILHOUETTE_SELECTED))}},{key:"drawEdgesColorOpaque",value:function(e,t){this.model.scene.logarithmicDepthBufferEnabled?this.model.scene._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),this.model.scene._loggedWarning=!0):this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._renderers.edgesColorRenderer&&this._renderers.edgesColorRenderer.drawLayer(t,this,oo.EDGES_COLOR_OPAQUE)}},{key:"drawEdgesColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&0!==this._numTransparentLayerPortions&&this._renderers.edgesColorRenderer&&this._renderers.edgesColorRenderer.drawLayer(t,this,oo.EDGES_COLOR_TRANSPARENT)}},{key:"drawEdgesHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._renderers.edgesRenderer&&this._renderers.edgesRenderer.drawLayer(t,this,oo.EDGES_HIGHLIGHTED)}},{key:"drawEdgesSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._renderers.edgesRenderer&&this._renderers.edgesRenderer.drawLayer(t,this,oo.EDGES_SELECTED)}},{key:"drawEdgesXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._renderers.edgesRenderer&&this._renderers.edgesRenderer.drawLayer(t,this,oo.EDGES_XRAYED)}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.occlusionRenderer&&this._renderers.occlusionRenderer.drawLayer(t,this,oo.COLOR_OPAQUE))}},{key:"drawShadow",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.shadowRenderer&&this._renderers.shadowRenderer.drawLayer(t,this,oo.COLOR_OPAQUE))}},{key:"setPickMatrices",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.pickMeshRenderer&&this._renderers.pickMeshRenderer.drawLayer(t,this,oo.PICK))}},{key:"drawPickDepths",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.pickDepthRenderer&&this._renderers.pickDepthRenderer.drawLayer(t,this,oo.PICK))}},{key:"drawSnapInit",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.snapInitRenderer&&this._renderers.snapInitRenderer.drawLayer(t,this,oo.PICK))}},{key:"drawSnap",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.snapRenderer&&this._renderers.snapRenderer.drawLayer(t,this,oo.PICK))}},{key:"drawPickNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._renderers.pickNormalsRenderer&&this._renderers.pickNormalsRenderer.drawLayer(t,this,oo.PICK))}},{key:"destroy",value:function(){if(!this._destroyed){var e=this._state;e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),this.model.scene.off(this._onSceneRendering),e.destroy(),this._destroyed=!0}}}]),e}(),Pc=function(){function e(t){x(this,e),this.id=t.id,this.colorTexture=t.colorTexture,this.metallicRoughnessTexture=t.metallicRoughnessTexture,this.normalsTexture=t.normalsTexture,this.emissiveTexture=t.emissiveTexture,this.occlusionTexture=t.occlusionTexture}return C(e,[{key:"destroy",value:function(){}}]),e}(),Cc=function(){function e(t){x(this,e),this.id=t.id,this.texture=t.texture}return C(e,[{key:"destroy",value:function(){this.texture&&(this.texture.destroy(),this.texture=null)}}]),e}(),Mc={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}},Fc=function(){function e(t,i,s){x(this,e),this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=t,this.onProgress=i,this.onError=s}return C(e,[{key:"itemStart",value:function(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}},{key:"itemEnd",value:function(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}},{key:"itemError",value:function(e){void 0!==this.onError&&this.onError(e)}},{key:"resolveURL",value:function(e){return this.urlModifier?this.urlModifier(e):e}},{key:"setURLModifier",value:function(e){return this.urlModifier=e,this}},{key:"addHandler",value:function(e,t){return this.handlers.push(e,t),this}},{key:"removeHandler",value:function(e){var t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}},{key:"getHandler",value:function(e){for(var t=0,i=this.handlers.length;t0&&void 0!==arguments[0]?arguments[0]:4;x(this,e),this.pool=t,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}return C(e,[{key:"_initWorker",value:function(e){if(!this.workers[e]){var t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}},{key:"_getIdleWorker",value:function(){for(var e=0;e0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),Tc++}return this._transcoderPending}},{key:"transcode",value:function(e,t){var i=this,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(r,n){var o=s;i._init().then((function(){return i._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:o},e)})).then((function(e){var i=e.data,s=i.mipmaps,o=(i.width,i.height,i.format),a=i.type,l=i.error,u=i.dfdTransferFn,A=i.dfdFlags;if("error"===a)return n(l);t.setCompressedData({mipmaps:s,props:{format:o,minFilter:1===s.length?1006:1008,magFilter:1===s.length?1006:1008,encoding:2===u?3001:3e3,premultiplyAlpha:!!(1&A)}}),r()}))}))}},{key:"destroy",value:function(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),Tc--}}]),e}();Rc.BasisFormat={ETC1S:0,UASTC_4x4:1},Rc.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},Rc.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},Rc.BasisWorker=function(){var e,t,i,s=_EngineFormat,r=_TranscoderFormat,n=_BasisFormat;self.addEventListener("message",(function(o){var A,c=o.data;switch(c.type){case"init":e=c.config,A=c.transcoderBinary,t=new Promise((function(e){i={wasmBinary:A,onRuntimeInitialized:e},BASIS(i)})).then((function(){i.initializeBasis(),void 0===i.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((function(){try{for(var t=function(t){var o=new i.KTX2File(new Uint8Array(t));function A(){o.close(),o.delete()}if(!o.isValid())throw A(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");var c=o.isUASTC()?n.UASTC_4x4:n.ETC1S,h=o.getWidth(),d=o.getHeight(),p=o.getLevels(),f=o.getHasAlpha(),v=o.getDFDTransferFunc(),g=o.getDFDFlags(),m=function(t,i,o,A){for(var c,h,d=t===n.ETC1S?a:l,p=0;p>t;i.sort(jc);for(var a=new Int32Array(e.length),l=0,u=i.length;le[r+1]){var o=e[r];e[r]=e[r+1],e[r+1]=o}zc=new Int32Array(e),t.sort(Wc);for(var a=new Int32Array(e.length),l=0,u=t.length;l0)for(var s=i._meshes,r=0,n=s.length;r0)for(var o=this._meshes,a=0,l=o.length;a1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._dtxEnabled=s.scene.dtxEnabled&&!1!==r.dtxEnabled,s._enableVertexWelding=!1,s._enableIndexBucketing=!1,s._vboBatchingLayerScratchMemory=no(),s._textureTranscoder=r.textureTranscoder||Uc(s.scene.viewer),s._maxGeometryBatchSize=r.maxGeometryBatchSize,s._aabb=$.collapseAABB3(),s._aabbDirty=!0,s._quantizationRanges={},s._vboInstancingLayers={},s._vboBatchingLayers={},s._dtxLayers={},s._meshList=[],s.layerList=[],s._entityList=[],s._geometries={},s._dtxBuckets={},s._textures={},s._textureSets={},s._transforms={},s._meshes={},s._unusedMeshes={},s._entities={},s.renderFlags=new Wr,s.numGeometries=0,s.numPortions=0,s.numVisibleLayerPortions=0,s.numTransparentLayerPortions=0,s.numXRayedLayerPortions=0,s.numHighlightedLayerPortions=0,s.numSelectedLayerPortions=0,s.numEdgesLayerPortions=0,s.numPickableLayerPortions=0,s.numClippableLayerPortions=0,s.numCulledLayerPortions=0,s.numEntities=0,s._numTriangles=0,s._numLines=0,s._numPoints=0,s._edgeThreshold=r.edgeThreshold||10,s._origin=$.vec3(r.origin||[0,0,0]),s._position=$.vec3(r.position||[0,0,0]),s._rotation=$.vec3(r.rotation||[0,0,0]),s._quaternion=$.vec4(r.quaternion||[0,0,0,1]),s._conjugateQuaternion=$.vec4(r.quaternion||[0,0,0,1]),r.rotation&&$.eulerToQuaternion(s._rotation,"XYZ",s._quaternion),s._scale=$.vec3(r.scale||[1,1,1]),s._worldRotationMatrix=$.mat4(),s._worldRotationMatrixConjugate=$.mat4(),s._matrix=$.mat4(),s._matrixDirty=!0,s._rebuildMatrices(),s._worldNormalMatrix=$.mat4(),$.inverseMat4(s._matrix,s._worldNormalMatrix),$.transposeMat4(s._worldNormalMatrix),(r.matrix||r.position||r.rotation||r.scale||r.quaternion)&&(s._viewMatrix=$.mat4(),s._viewNormalMatrix=$.mat4(),s._viewMatrixDirty=!0,s._matrixNonIdentity=!0),s._opacity=1,s._colorize=[1,1,1],s._saoEnabled=!1!==r.saoEnabled,s._pbrEnabled=!1!==r.pbrEnabled,s._colorTextureEnabled=!1!==r.colorTextureEnabled,s._isModel=r.isModel,s._isModel&&s.scene._registerModel(b(s)),s._onCameraViewMatrix=s.scene.camera.on("matrix",(function(){s._viewMatrixDirty=!0})),s._meshesWithDirtyMatrices=[],s._numMeshesWithDirtyMatrices=0,s._onTick=s.scene.on("tick",(function(){for(;s._numMeshesWithDirtyMatrices>0;)s._meshesWithDirtyMatrices[--s._numMeshesWithDirtyMatrices]._updateMatrix()})),s._createDefaultTextureSet(),s.visible=r.visible,s.culled=r.culled,s.pickable=r.pickable,s.clippable=r.clippable,s.collidable=r.collidable,s.castsShadow=r.castsShadow,s.receivesShadow=r.receivesShadow,s.xrayed=r.xrayed,s.highlighted=r.highlighted,s.selected=r.selected,s.edges=r.edges,s.colorize=r.colorize,s.opacity=r.opacity,s.backfaces=r.backfaces,s}return C(i,[{key:"_meshMatrixDirty",value:function(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}},{key:"_createDefaultTextureSet",value:function(){var e=new Cc({id:"defaultColorTexture",texture:new In({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Cc({id:"defaultMetalRoughTexture",texture:new In({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),i=new Cc({id:"defaultNormalsTexture",texture:new In({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),s=new Cc({id:"defaultEmissiveTexture",texture:new In({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),r=new Cc({id:"defaultOcclusionTexture",texture:new In({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=i,this._textures.defaultEmissiveTexture=s,this._textures.defaultOcclusionTexture=r,this._textureSets.defaultTextureSet=new Pc({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:i,emissiveTexture:s,occlusionTexture:r})}},{key:"isPerformanceModel",get:function(){return!0}},{key:"transforms",get:function(){return this._transforms}},{key:"textures",get:function(){return this._textures}},{key:"textureSets",get:function(){return this._textureSets}},{key:"meshes",get:function(){return this._meshes}},{key:"objects",get:function(){return this._entities}},{key:"origin",get:function(){return this._origin}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),$.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),$.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){}},{key:"matrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix},set:function(e){this._matrix.set(e||uh),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),$.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),$.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"rotationMatrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}},{key:"_rebuildMatrices",value:function(){this._matrixDirty&&($.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),$.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),$.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}},{key:"rotationMatrixConjugate",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}},{key:"_setWorldMatrixDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0}},{key:"_transformDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}},{key:"_sceneModelDirty",value:function(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(var e=0,t=this._entityList.length;e0},set:function(e){e=!1!==e,this._visible=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._selected=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._edges=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,i=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var l=e.colors,u=new Uint8Array(l.length),A=0,c=l.length;A>24&255,r=i>>16&255,n=i>>8&255,o=255&i;switch(e.pickColor=new Uint8Array([o,n,r,s]),e.solid="solid"===e.primitive,t.origin=$.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),this._meshes[e.id]=t,this._unusedMeshes[e.id]=t,this._meshList.push(t),t}},{key:"_getNumPrimitives",value:function(e){var t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(var i=0,s=e.buckets.length;i>>0).toString(16)}},{key:"_getVBOInstancingLayer",value:function(e){var t=this,i=e.origin,s=e.textureSetId||"-",r=e.geometryId,n="".concat(Math.round(i[0]),".").concat(Math.round(i[1]),".").concat(Math.round(i[2]),".").concat(s,".").concat(r),o=this._vboInstancingLayers[n];if(o)return o;for(var a=e.textureSet,l=e.geometry;!o;)switch(l.primitive){case"triangles":case"surface":o=new rl({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!1});break;case"solid":o=new rl({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!0});break;case"lines":o=new jl({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0});break;case"points":o=new Lu({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0})}return this._vboInstancingLayers[n]=o,this.layerList.push(o),o}},{key:"createEntity",value:function(e){if(void 0===e.id?e.id=$.createUUID():this.scene.components[e.id]&&(this.error("Scene already has a Component with this ID: ".concat(e.id," - will assign random ID")),e.id=$.createUUID()),void 0!==e.meshIds){var t=0;this._visible&&!1!==e.visible&&(t|=Qe),this._pickable&&!1!==e.pickable&&(t|=He),this._culled&&!1!==e.culled&&(t|=Ve),this._clippable&&!1!==e.clippable&&(t|=je),this._collidable&&!1!==e.collidable&&(t|=Ge),this._edges&&!1!==e.edges&&(t|=Xe),this._xrayed&&!1!==e.xrayed&&(t|=ze),this._highlighted&&!1!==e.highlighted&&(t|=We),this._selected&&!1!==e.selected&&(t|=Ke),e.flags=t,this._createEntity(e)}else this.error("Config missing: meshIds")}},{key:"_createEntity",value:function(e){for(var t=[],i=0,s=e.meshIds.length;it.sortId?1:0}));for(var o=0,a=this.layerList.length;o0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}},{key:"_updateRenderFlagsVisibleLayers",value:function(){var e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(var t=0,i=this.layerList.length;t0){var t="".concat(this.id,"-dummyEntityForUnusedMeshes");this.warn('Creating dummy SceneModelEntity "'.concat(t,'" for unused SceneMeshes: [').concat(e.join(","),"]")),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}},{key:"_getActiveSectionPlanesForLayer",value:function(e){var t=this.renderFlags,i=this.scene._sectionPlanesState.sectionPlanes,s=i.length,r=e.layerIndex*s;if(s>0)for(var n=0;n0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){var t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0)this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0));if(this.numSelectedLayerPortions>0){var i=this.scene.selectedMaterial._state;i.fill&&(i.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),i.edges&&(i.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){var s=this.scene.highlightMaterial._state;s.fill&&(s.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),s.edges&&(s.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"drawColorOpaque",value:function(e){for(var t=this.renderFlags,i=0,s=t.visibleLayers.length;i2&&void 0!==arguments[2]&&arguments[2],s=e.positionsCompressed||[],r=Gc(e.indices||[],t),n=Kc(e.edgeIndices||[]);function o(e,t){if(e>t){var i=e;e=t,t=i}function s(i,s){return i!==e?e-i:s!==t?t-s:0}for(var r=0,o=(n.length>>1)-1;r<=o;){var a=o+r>>1,l=s(n[2*a],n[2*a+1]);if(l>0)r=a+1;else{if(!(l<0))return a;o=a-1}}return-r-1}var a=new Int32Array(n.length/2);a.fill(0);var l=s.length/3;if(l>8*(1<h.maxNumPositions&&(h=c()),h.bucketNumber>8)return[e];-1===u[v]&&(u[v]=h.numPositions++,h.positionsCompressed.push(s[3*v]),h.positionsCompressed.push(s[3*v+1]),h.positionsCompressed.push(s[3*v+2])),-1===u[g]&&(u[g]=h.numPositions++,h.positionsCompressed.push(s[3*g]),h.positionsCompressed.push(s[3*g+1]),h.positionsCompressed.push(s[3*g+2])),-1===u[m]&&(u[m]=h.numPositions++,h.positionsCompressed.push(s[3*m]),h.positionsCompressed.push(s[3*m+1]),h.positionsCompressed.push(s[3*m+2])),h.indices.push(u[v]),h.indices.push(u[g]),h.indices.push(u[m]);var _=void 0;(_=o(v,g))>=0&&0===a[_]&&(a[_]=1,h.edgeIndices.push(u[n[2*_]]),h.edgeIndices.push(u[n[2*_+1]])),(_=o(v,m))>=0&&0===a[_]&&(a[_]=1,h.edgeIndices.push(u[n[2*_]]),h.edgeIndices.push(u[n[2*_+1]])),(_=o(g,m))>=0&&0===a[_]&&(a[_]=1,h.edgeIndices.push(u[n[2*_]]),h.edgeIndices.push(u[n[2*_+1]]))}var y=t/8*2,b=t/8,w=2*s.length+(r.length+n.length)*y,B=0;return s.length,A.forEach((function(e){B+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*b,e.positionsCompressed.length})),B>w?[e]:(i&&Xc(A,e),A)}({positionsCompressed:s,indices:r,edgeIndices:n},s.length/3>65536?16:8):o=[{positionsCompressed:s,indices:r,edgeIndices:n}];return o}var dh=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,e,r))._positions=r.positions||[],r.indices)s._indices=r.indices;else{s._indices=[];for(var n=0,o=s._positions.length/3-1;n1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"BCFViewpoints",e,r)).originatingSystem=r.originatingSystem||"xeokit.io",s.authoringTool=r.authoringTool||"xeokit.io",s}return C(i,[{key:"getViewpoint",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=this.viewer.scene,s=i.camera,r=i.realWorldOffset,n=!0===t.reverseClippingPlanes,o={},a=$.normalizeVec3($.subVec3(s.look,s.eye,$.vec3())),l=s.eye,u=s.up;s.yUp&&(a=bh(a),l=bh(l),u=bh(u));var A=_h($.addVec3(l,r));"ortho"===s.projection?o.orthogonal_camera={camera_view_point:A,camera_direction:_h(a),camera_up_vector:_h(u),view_to_world_scale:s.ortho.scale}:o.perspective_camera={camera_view_point:A,camera_direction:_h(a),camera_up_vector:_h(u),field_of_view:s.perspective.fov};var c=i.sectionPlanes;for(var d in c)if(c.hasOwnProperty(d)){var p=c[d];if(!p.active)continue;var f=p.pos,v=void 0;v=n?$.negateVec3(p.dir,$.vec3()):p.dir,s.yUp&&(f=bh(f),v=bh(v)),$.addVec3(f,r),f=_h(f),v=_h(v),o.clipping_planes||(o.clipping_planes=[]),o.clipping_planes.push({location:f,direction:v})}var g=i.lineSets;for(var m in g)if(g.hasOwnProperty(m)){var _=g[m];o.lines||(o.lines=[]);for(var y=_.positions,b=_.indices,w=0,B=b.length/2;w1&&void 0!==arguments[1]?arguments[1]:{};if(e){var s=this.viewer,r=s.scene,n=r.camera,o=!1!==i.rayCast,a=!1!==i.immediate,l=!1!==i.reset,u=r.realWorldOffset,A=!0===i.reverseClippingPlanes;if(r.clearSectionPlanes(),e.clipping_planes&&e.clipping_planes.length>0&&e.clipping_planes.forEach((function(e){var t=yh(e.location,ph),i=yh(e.direction,ph);A&&$.negateVec3(i),$.subVec3(t,u),n.yUp&&(t=wh(t),i=wh(i)),new cn(r,{pos:t,dir:i})})),r.clearLines(),e.lines&&e.lines.length>0){var c=[],h=[],d=0;e.lines.forEach((function(e){e.start_point&&e.end_point&&(c.push(e.start_point.x),c.push(e.start_point.y),c.push(e.start_point.z),c.push(e.end_point.x),c.push(e.end_point.y),c.push(e.end_point.z),h.push(d++),h.push(d++))})),new dh(r,{positions:c,indices:h,clippable:!1,collidable:!0})}if(r.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){var t=e.bitmap_type||"jpg",i=e.bitmap_data,s=yh(e.location,fh),o=yh(e.normal,vh),a=yh(e.up,gh),l=e.height||1;t&&i&&s&&o&&a&&(n.yUp&&(s=wh(s),o=wh(o),a=wh(a)),new qn(r,{src:i,type:t,pos:s,normal:o,up:a,clippable:!1,collidable:!0,height:l}))})),l&&(r.setObjectsXRayed(r.xrayedObjectIds,!1),r.setObjectsHighlighted(r.highlightedObjectIds,!1),r.setObjectsSelected(r.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(r.setObjectsVisible(r.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.visible=!1}))}))):(r.setObjectsVisible(r.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.visible=!0}))})));var p=e.components.visibility.view_setup_hints;p&&(!1===p.spaces_visible&&r.setObjectsVisible(s.metaScene.getObjectIDsByType("IfcSpace"),!1),void 0!==p.spaces_translucent&&r.setObjectsXRayed(s.metaScene.getObjectIDsByType("IfcSpace"),!0),p.space_boundaries_visible,!1===p.openings_visible&&r.setObjectsVisible(s.metaScene.getObjectIDsByType("IfcOpening"),!0),p.space_boundaries_translucent,void 0!==p.openings_translucent&&r.setObjectsXRayed(s.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(r.setObjectsSelected(r.selectedObjectIds,!1),e.components.selection.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.selected=!0}))}))),e.components.translucency&&(r.setObjectsXRayed(r.xrayedObjectIds,!1),e.components.translucency.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.xrayed=!0}))}))),e.components.coloring&&e.components.coloring.forEach((function(e){var s=e.color,r=0,n=!1;8===s.length&&((r=parseInt(s.substring(0,2),16)/256)<=1&&r>=.95&&(r=1),s=s.substring(2),n=!0);var o=[parseInt(s.substring(0,2),16)/256,parseInt(s.substring(2,4),16)/256,parseInt(s.substring(4,6),16)/256];e.components.map((function(e){return t._withBCFComponent(i,e,(function(e){e.colorize=o,n&&(e.opacity=r)}))}))}))}if(e.perspective_camera||e.orthogonal_camera){var f,v,g,m;if(e.perspective_camera?(f=yh(e.perspective_camera.camera_view_point,ph),v=yh(e.perspective_camera.camera_direction,ph),g=yh(e.perspective_camera.camera_up_vector,ph),n.perspective.fov=e.perspective_camera.field_of_view,m="perspective"):(f=yh(e.orthogonal_camera.camera_view_point,ph),v=yh(e.orthogonal_camera.camera_direction,ph),g=yh(e.orthogonal_camera.camera_up_vector,ph),n.ortho.scale=e.orthogonal_camera.view_to_world_scale,m="ortho"),$.subVec3(f,u),n.yUp&&(f=wh(f),v=wh(v),g=wh(g)),o){var _=r.pick({pickSurface:!0,origin:f,direction:v});v=_?_.worldPos:$.addVec3(f,v,ph)}else v=$.addVec3(f,v,ph);a?(n.eye=f,n.look=v,n.up=g,n.projection=m):s.cameraFlight.flyTo({eye:f,look:v,up:g,duration:i.duration,projection:m})}}}},{key:"_withBCFComponent",value:function(e,t,i){var s=this.viewer,r=s.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){var n=t.authoring_tool_id,o=r.objects[n];if(o)return void i(o);if(e.updateCompositeObjects)if(s.metaScene.metaObjects[n])return void r.withObjects(s.metaScene.getObjectIDsInSubtree(n),i)}if(t.ifc_guid){var a=t.ifc_guid,l=r.objects[a];if(l)return void i(l);if(e.updateCompositeObjects)if(s.metaScene.metaObjects[a])return void r.withObjects(s.metaScene.getObjectIDsInSubtree(a),i);Object.keys(r.models).forEach((function(t){var n=$.globalizeObjectId(t,a),o=r.objects[n];o?i(o):e.updateCompositeObjects&&s.metaScene.metaObjects[n]&&r.withObjects(s.metaScene.getObjectIDsInSubtree(n),i)}))}}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this)}}]),i}();function _h(e){return{x:e[0],y:e[1],z:e[2]}}function yh(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function bh(e){return new Float64Array([e[0],-e[2],e[1]])}function wh(e){return new Float64Array([e[0],e[2],-e[1]])}function Bh(e){var t="";return t+=Math.round(255*e[0]).toString(16).padStart(2,"0"),t+=Math.round(255*e[1]).toString(16).padStart(2,"0"),t+=Math.round(255*e[2]).toString(16).padStart(2,"0")}var xh=$.vec3(),Ph=function(e,t,i,s){var r=e-i,n=t-s;return Math.sqrt(r*r+n*n)},Ch=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,e.viewer.scene,r)).plugin=e,s._container=r.container,!s._container)throw"config missing: container";s._eventSubs={};var n=s.plugin.viewer.scene;s._originMarker=new et(n,r.origin),s._targetMarker=new et(n,r.target),s._originWorld=$.vec3(),s._targetWorld=$.vec3(),s._wp=new Float64Array(24),s._vp=new Float64Array(24),s._pp=new Float64Array(24),s._cp=new Float64Array(8),s._xAxisLabelCulled=!1,s._yAxisLabelCulled=!1,s._zAxisLabelCulled=!1,s._color=r.color||s.plugin.defaultColor;var o=r.onMouseOver?function(e){r.onMouseOver(e,b(s)),s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,a=r.onMouseLeave?function(e){r.onMouseLeave(e,b(s)),s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,l=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},u=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},A=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},c=r.onContextMenu?function(e){r.onContextMenu(e,b(s))}:null,h=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return s._originDot=new it(s._container,{fillColor:s._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._targetDot=new it(s._container,{fillColor:s._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._lengthWire=new tt(s._container,{color:s._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._xAxisWire=new tt(s._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._yAxisWire=new tt(s._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._zAxisWire=new tt(s._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._lengthLabel=new st(s._container,{fillColor:s._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._xAxisLabel=new st(s._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._yAxisLabel=new st(s._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._zAxisLabel=new st(s._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._wpDirty=!1,s._vpDirty=!1,s._cpDirty=!1,s._sectionPlanesDirty=!0,s._visible=!1,s._originVisible=!1,s._targetVisible=!1,s._wireVisible=!1,s._axisVisible=!1,s._xAxisVisible=!1,s._yAxisVisible=!1,s._zAxisVisible=!1,s._axisEnabled=!0,s._labelsVisible=!1,s._labelsOnWires=!1,s._clickable=!1,s._originMarker.on("worldPos",(function(e){s._originWorld.set(e||[0,0,0]),s._wpDirty=!0,s._needUpdate(0)})),s._targetMarker.on("worldPos",(function(e){s._targetWorld.set(e||[0,0,0]),s._wpDirty=!0,s._needUpdate(0)})),s._onViewMatrix=n.camera.on("viewMatrix",(function(){s._vpDirty=!0,s._needUpdate(0)})),s._onProjMatrix=n.camera.on("projMatrix",(function(){s._cpDirty=!0,s._needUpdate()})),s._onCanvasBoundary=n.canvas.on("boundary",(function(){s._cpDirty=!0,s._needUpdate(0)})),s._onMetricsUnits=n.metrics.on("units",(function(){s._cpDirty=!0,s._needUpdate()})),s._onMetricsScale=n.metrics.on("scale",(function(){s._cpDirty=!0,s._needUpdate()})),s._onMetricsOrigin=n.metrics.on("origin",(function(){s._cpDirty=!0,s._needUpdate()})),s._onSectionPlaneUpdated=n.on("sectionPlaneUpdated",(function(){s._sectionPlanesDirty=!0,s._needUpdate()})),s.approximate=r.approximate,s.visible=r.visible,s.originVisible=r.originVisible,s.targetVisible=r.targetVisible,s.wireVisible=r.wireVisible,s.axisVisible=r.axisVisible,s.xAxisVisible=r.xAxisVisible,s.yAxisVisible=r.yAxisVisible,s.zAxisVisible=r.zAxisVisible,s.labelsVisible=r.labelsVisible,s.labelsOnWires=r.labelsOnWires,s}return C(i,[{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._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&($.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._originWorld)||this._isSliced(this._targetWorld))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}var t=this._originMarker.viewPos[2],i=this._targetMarker.viewPos[2];if(t>-.3||i>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){$.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var s=this._pp,r=this._cp,n=e.canvas.canvas.getBoundingClientRect(),o=this._container.getBoundingClientRect(),a=n.top-o.top,l=n.left-o.left,u=e.canvas.boundary,A=u[2],c=u[3],h=0,d=this.plugin.viewer.scene.metrics,p=d.scale,f=d.units,v=d.unitsInfo[f].abbrev,g=0,m=s.length;g1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e.viewer.scene))._canvasToPagePos=r.canvasToPagePos,s.pointerLens=r.pointerLens,s._active=!1,s._currentDistanceMeasurement=null,s._currentDistanceMeasurementInitState={wireVisible:null,axisVisible:null,xAxisVisible:null,yaxisVisible:null,zAxisVisible:null,targetVisible:null},s._initMarkerDiv(),s._onCameraControlHoverSnapOrSurface=null,s._onCameraControlHoverSnapOrSurfaceOff=null,s._onMouseDown=null,s._onMouseUp=null,s._onCanvasTouchStart=null,s._onCanvasTouchEnd=null,s._snapping=!1!==r.snapping,s._mouseState=0,s._attachPlugin(e,r),s}return C(i,[{key:"_initMarkerDiv",value:function(){var e=document.createElement("div");e.setAttribute("id","myMarkerDiv");var t=this.scene.canvas.canvas;t.parentNode.insertBefore(e,t),e.style.background="black",e.style.border="2px solid blue",e.style.borderRadius="10px",e.style.width="5px",e.style.height="5px",e.style.top="-200px",e.style.left="-200px",e.style.margin="0 0",e.style.zIndex="100",e.style.position="absolute",e.style.pointerEvents="none",this._markerDiv=e}},{key:"_destroyMarkerDiv",value:function(){if(this._markerDiv){var e=document.getElementById("myMarkerDiv");e.parentNode.removeChild(e),this._markerDiv=null}}},{key:"_attachPlugin",value:function(e){this.distanceMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){this._markerDiv||this._initMarkerDiv(),this.fire("activated",!0);var t=this.distanceMeasurementsPlugin,i=this.scene,s=t.viewer.cameraControl,r=i.canvas.canvas;i.input;var n,o,a=!1,l=$.vec3(),u=$.vec2(),A=null;this._mouseState=0;var c=function e(t){return t.offsetTop+(t.offsetParent&&t.offsetParent!==r.parentNode&&e(t.offsetParent))},h=function e(t){return t.offsetLeft+(t.offsetParent&&t.offsetParent!==r.parentNode&&e(t.offsetParent))},d=$.vec2();this._onCameraControlHoverSnapOrSurface=s.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(function(t){var i=t.snappedCanvasPos||t.canvasPos;a=!0,l.set(t.worldPos),u.set(t.canvasPos),0===e._mouseState?(e._canvasToPagePos?(e._canvasToPagePos(r,i,d),e._markerDiv.style.left="".concat(d[0]-5,"px"),e._markerDiv.style.top="".concat(d[1]-5,"px")):(e._markerDiv.style.left="".concat(h(r)+i[0]-5,"px"),e._markerDiv.style.top="".concat(c(r)+i[1]-5,"px")),e._markerDiv.style.background="pink",t.snappedToVertex||t.snappedToEdge?(e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.snappedCanvasPos||t.canvasPos,e.pointerLens.snapped=!0),e._markerDiv.style.background="greenyellow",e._markerDiv.style.border="2px solid green"):(e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.canvasPos,e.pointerLens.snapped=!1),e._markerDiv.style.background="pink",e._markerDiv.style.border="2px solid red"),A=t.entity):(e._markerDiv.style.left="-10000px",e._markerDiv.style.top="-10000px"),r.style.cursor="pointer",e._currentDistanceMeasurement&&(e._currentDistanceMeasurement.wireVisible=e._currentDistanceMeasurementInitState.wireVisible,e._currentDistanceMeasurement.axisVisible=e._currentDistanceMeasurementInitState.axisVisible&&e.distanceMeasurementsPlugin.defaultAxisVisible,e._currentDistanceMeasurement.xAxisVisible=e._currentDistanceMeasurementInitState.xAxisVisible&&e.distanceMeasurementsPlugin.defaultXAxisVisible,e._currentDistanceMeasurement.yAxisVisible=e._currentDistanceMeasurementInitState.yAxisVisible&&e.distanceMeasurementsPlugin.defaultYAxisVisible,e._currentDistanceMeasurement.zAxisVisible=e._currentDistanceMeasurementInitState.zAxisVisible&&e.distanceMeasurementsPlugin.defaultZAxisVisible,e._currentDistanceMeasurement.targetVisible=e._currentDistanceMeasurementInitState.targetVisible,e._currentDistanceMeasurement.target.worldPos=l.slice(),e._markerDiv.style.left="-10000px",e._markerDiv.style.top="-10000px")})),r.addEventListener("mousedown",this._onMouseDown=function(e){1===e.which&&(n=e.clientX,o=e.clientY)}),r.addEventListener("mouseup",this._onMouseUp=function(i){1===i.which&&(i.clientX>n+20||i.clientXo+20||i.clientY1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"DistanceMeasurements",e))._pointerLens=r.pointerLens,s._container=r.container||document.body,s._defaultControl=null,s._measurements={},s.labelMinAxisLength=r.labelMinAxisLength,s.defaultVisible=!1!==r.defaultVisible,s.defaultOriginVisible=!1!==r.defaultOriginVisible,s.defaultTargetVisible=!1!==r.defaultTargetVisible,s.defaultWireVisible=!1!==r.defaultWireVisible,s.defaultLabelsVisible=!1!==r.defaultLabelsVisible,s.defaultAxisVisible=!1!==r.defaultAxisVisible,s.defaultXAxisVisible=!1!==r.defaultXAxisVisible,s.defaultYAxisVisible=!1!==r.defaultYAxisVisible,s.defaultZAxisVisible=!1!==r.defaultZAxisVisible,s.defaultColor=void 0!==r.defaultColor?r.defaultColor:"#00BBFF",s.zIndex=r.zIndex||1e4,s.defaultLabelsOnWires=!1!==r.defaultLabelsOnWires,s._onMouseOver=function(e,t){s.fire("mouseOver",{plugin:b(s),distanceMeasurement:t,measurement:t,event:e})},s._onMouseLeave=function(e,t){s.fire("mouseLeave",{plugin:b(s),distanceMeasurement:t,measurement:t,event:e})},s._onContextMenu=function(e,t){s.fire("contextMenu",{plugin:b(s),distanceMeasurement:t,measurement:t,event:e})},s}return C(i,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){}},{key:"pointerLens",get:function(){return this._pointerLens}},{key:"control",get:function(){return this._defaultControl||(this._defaultControl=new Fh(this,{})),this._defaultControl}},{key:"measurements",get:function(){return this._measurements}},{key:"labelMinAxisLength",get:function(){return this._labelMinAxisLength},set:function(e){e<1&&(this.error("labelMinAxisLength must be >= 1; defaulting to 25"),e=25),this._labelMinAxisLength=e||25}},{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 i=t.origin,s=t.target,r=new Ch(this,{id:t.id,plugin:this,container:this._container,origin:{entity:i.entity,worldPos:i.worldPos},target:{entity:s.entity,worldPos:s.worldPos},visible:t.visible,wireVisible:t.wireVisible,axisVisible:!1!==t.axisVisible&&!1!==this.defaultAxisVisible,xAxisVisible:!1!==t.xAxisVisible&&!1!==this.defaultXAxisVisible,yAxisVisible:!1!==t.yAxisVisible&&!1!==this.defaultYAxisVisible,zAxisVisible:!1!==t.zAxisVisible&&!1!==this.defaultZAxisVisible,labelsVisible:!1!==t.labelsVisible&&!1!==this.defaultLabelsVisible,originVisible:t.originVisible,targetVisible:t.targetVisible,color:t.color,labelsOnWires:!1!==t.labelsOnWires&&!1!==this.defaultLabelsOnWires,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[r.id]=r,r.on("destroyed",(function(){delete e._measurements[r.id]})),this.fire("measurementCreated",r),r}},{key:"destroyMeasurement",value:function(e){var t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("DistanceMeasurement not found: "+e)}},{key:"setLabelsShown",value:function(e){for(var t=0,i=Object.entries(this.measurements);t1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e.viewer.scene)).pointerLens=r.pointerLens,s.pointerCircle=new De(e.viewer),s._active=!1;var n=document.createElement("div"),o=s.scene.canvas.canvas;return o.parentNode.insertBefore(n,o),n.style.background="black",n.style.border="2px solid blue",n.style.borderRadius="10px",n.style.width="5px",n.style.height="5px",n.style.margin="-200px -200px",n.style.zIndex="100",n.style.position="absolute",n.style.pointerEvents="none",s.markerDiv=n,s._currentDistanceMeasurement=null,s._currentDistanceMeasurementInitState={wireVisible:null,axisVisible:null,xAxisVisible:null,yaxisVisible:null,zAxisVisible:null,targetVisible:null},s._onCanvasTouchStart=null,s._onCanvasTouchEnd=null,s._longTouchTimeoutMs=300,s._snapping=!1!==r.snapping,s._touchState=0,s._attachPlugin(e,r),s}return C(i,[{key:"_attachPlugin",value:function(e){this.distanceMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){var t=this.plugin,i=this.scene,s=i.canvas.canvas;t.pointerLens;var r=$.vec3(),n=20,o=null;this._touchState=0;var a=$.vec2(),l=$.vec2(),u=$.vec2(),A=null,c=function(){e.plugin.viewer.cameraControl.active=!1},h=function(){e.plugin.viewer.cameraControl.active=!0};s.addEventListener("touchstart",this._onCanvasTouchStart=function(s){var u=s.touches.length;if(1===u){var d=s.touches[0],p=d.clientX,f=d.clientY;switch(a.set([p,f]),l.set([p,f]),e._touchState){case 0:if(1!==u&&null!==o)return o&&(clearTimeout(o),o=null),e._currentDistanceMeasurement&&(e._currentDistanceMeasurement.destroy(),e._currentDistanceMeasurement=null),h(),void(e._touchState=0);var v=i.pick({canvasPos:l,snapping:e._snapping,snapToEdge:e._snapping});if(v&&v.snapped)r.set(v.worldPos),e.pointerCircle.start(v.snappedCanvasPos);else{var g=i.pick({canvasPos:l,pickSurface:!0});if(!g||!g.worldPos)return;r.set(g.worldPos),e.pointerCircle.start(g.canvasPos)}o=setTimeout((function(){1!==u||l[0]>a[0]+n||l[0]a[1]+n||l[1]a[0]+n||l[0]a[1]+n||l[1]a[0]+n||da[1]+n||pa[0]+n||da[1]+n||p1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,"FastNav",e))._hideColorTexture=!1!==r.hideColorTexture,s._hidePBR=!1!==r.hidePBR,s._hideSAO=!1!==r.hideSAO,s._hideEdges=!1!==r.hideEdges,s._hideTransparentObjects=!!r.hideTransparentObjects,s._scaleCanvasResolution=!!r.scaleCanvasResolution,s._defaultScaleCanvasResolutionFactor=r.defaultScaleCanvasResolutionFactor||1,s._scaleCanvasResolutionFactor=r.scaleCanvasResolutionFactor||.6,s._delayBeforeRestore=!1!==r.delayBeforeRestore,s._delayBeforeRestoreSeconds=r.delayBeforeRestoreSeconds||.5;var n=1e3*s._delayBeforeRestoreSeconds,o=!1,a=function(){n=1e3*s._delayBeforeRestoreSeconds,o||(e.scene._renderer.setColorTextureEnabled(!s._hideColorTexture),e.scene._renderer.setPBREnabled(!s._hidePBR),e.scene._renderer.setSAOEnabled(!s._hideSAO),e.scene._renderer.setTransparentEnabled(!s._hideTransparentObjects),e.scene._renderer.setEdgesEnabled(!s._hideEdges),s._scaleCanvasResolution?e.scene.canvas.resolutionScale=s._scaleCanvasResolutionFactor:e.scene.canvas.resolutionScale=s._defaultScaleCanvasResolutionFactor,o=!0)},l=function(){e.scene.canvas.resolutionScale=s._defaultScaleCanvasResolutionFactor,e.scene._renderer.setEdgesEnabled(!0),e.scene._renderer.setColorTextureEnabled(!0),e.scene._renderer.setPBREnabled(!0),e.scene._renderer.setSAOEnabled(!0),e.scene._renderer.setTransparentEnabled(!0),o=!1};s._onCanvasBoundary=e.scene.canvas.on("boundary",a),s._onCameraMatrix=e.scene.camera.on("matrix",a),s._onSceneTick=e.scene.on("tick",(function(e){o&&(n-=e.deltaTime,(!s._delayBeforeRestore||n<=0)&&l())}));var u=!1;return s._onSceneMouseDown=e.scene.input.on("mousedown",(function(){u=!0})),s._onSceneMouseUp=e.scene.input.on("mouseup",(function(){u=!1})),s._onSceneMouseMove=e.scene.input.on("mousemove",(function(){u&&a()})),s}return C(i,[{key:"hideColorTexture",get:function(){return this._hideColorTexture},set:function(e){this._hideColorTexture=e}},{key:"hidePBR",get:function(){return this._hidePBR},set:function(e){this._hidePBR=e}},{key:"hideSAO",get:function(){return this._hideSAO},set:function(e){this._hideSAO=e}},{key:"hideEdges",get:function(){return this._hideEdges},set:function(e){this._hideEdges=e}},{key:"hideTransparentObjects",get:function(){return this._hideTransparentObjects},set:function(e){this._hideTransparentObjects=!1!==e}},{key:"scaleCanvasResolution",get:function(){return this._scaleCanvasResolution},set:function(e){this._scaleCanvasResolution=e}},{key:"defaultScaleCanvasResolutionFactor",get:function(){return this._defaultScaleCanvasResolutionFactor},set:function(e){this._defaultScaleCanvasResolutionFactor=e||1}},{key:"scaleCanvasResolutionFactor",get:function(){return this._scaleCanvasResolutionFactor},set:function(e){this._scaleCanvasResolutionFactor=e||.6}},{key:"delayBeforeRestore",get:function(){return this._delayBeforeRestore},set:function(e){this._delayBeforeRestore=e}},{key:"delayBeforeRestoreSeconds",get:function(){return this._delayBeforeRestoreSeconds},set:function(e){this._delayBeforeRestoreSeconds=null!=e?e:.5}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.scene.camera.off(this._onCameraMatrix),this.viewer.scene.canvas.off(this._onCanvasBoundary),this.viewer.scene.input.off(this._onSceneMouseDown),this.viewer.scene.input.off(this._onSceneMouseUp),this.viewer.scene.input.off(this._onSceneMouseMove),this.viewer.scene.off(this._onSceneTick),f(w(i.prototype),"destroy",this).call(this)}}]),i}(),Dh=function(){function e(){x(this,e)}return C(e,[{key:"getMetaModel",value:function(e,t,i){le.loadJSON(e,(function(e){t(e)}),(function(e){i(e)}))}},{key:"getGLTF",value:function(e,t,i){le.loadArraybuffer(e,(function(e){t(e)}),(function(e){i(e)}))}},{key:"getGLB",value:function(e,t,i){le.loadArraybuffer(e,(function(e){t(e)}),(function(e){i(e)}))}},{key:"getArrayBuffer",value:function(e,t,i,s){!function(e,t,i,s){var r=function(){};i=i||r,s=s||r;var n=/^data:(.*?)(;base64)?,(.*)$/,o=t.match(n);if(o){var a=!!o[2],l=o[3];l=window.decodeURIComponent(l),a&&(l=window.atob(l));try{for(var u=new ArrayBuffer(l.length),A=new Uint8Array(u),c=0;c0&&void 0!==arguments[0]?arguments[0]:{};x(this,e),this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=t.messages,this.locale=t.locale}return C(e,[{key:"messages",set:function(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}},{key:"loadMessages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var t in e)this._messages[t]=e[t];this.messages=this._messages}},{key:"clearMessages",value:function(){this.messages={}}},{key:"locales",get:function(){return this._locales}},{key:"locale",get:function(){return this._locale},set:function(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}},{key:"translate",value:function(e,t){var i=this._messages[this._locale];if(!i)return null;var s=Th(e,i);return s?t?Rh(s,t):s:null}},{key:"translatePlurals",value:function(e,t,i){var s=this._messages[this._locale];if(!s)return null;var r=Th(e,s);return(r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one)?(r=Rh(r,[t]),i&&(r=Rh(r,i)),r):null}},{key:"fire",value:function(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);var s=this._eventSubs[e];if(s)for(var r in s){if(s.hasOwnProperty(r))s[r].callback(t)}}},{key:"on",value:function(e,t){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new Q),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});var i=this._eventSubs[e];i||(i={},this._eventSubs[e]=i);var s=this._eventSubIDMap.addItem();i[s]={callback:t},this._eventSubEvents[s]=e;var r=this._events[e];return void 0!==r&&t(r),s}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function Th(e,t){if(t[e])return t[e];for(var i=e.split("."),s=t,r=0,n=i.length;s&&r1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,i){return"{{"===e?"{":"}}"===e?"}":t[i]}))}var Lh=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).t=r.t,s}return C(i,[{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"tangent",get:function(){return this.getTangent(this._t)}},{key:"length",get:function(){var e=this._getLengths();return e[e.length-1]}},{key:"getTangent",value:function(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,s=e+t;i<0&&(i=0),s>1&&(s=1);var r=this.getPoint(i),n=this.getPoint(s),o=$.subVec3(n,r,[]);return $.normalizeVec3(o,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}},{key:"_getLengths",value:function(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,s=[],r=this.getPoint(0),n=0;for(s.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),n+=$.lenVec3($.subVec3(t,r,[])),s.push(n),r=t;return this.cacheArcLengths=s,s}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var i,s=this._getLengths(),r=0,n=s.length;i=t||e*s[n-1];for(var o,a=0,l=n-1;a<=l;)if((o=s[r=Math.floor(a+(l-a)/2)]-i)<0)a=r+1;else{if(!(o>0)){l=r;break}l=r-1}if(s[r=l]===i)return r/(n-1);var u=s[r];return(r+(i-u)/(s[r+1]-u))/(n-1)}}]),i}(),Uh=function(e){g(i,Lh);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).points=r.points,s.t=r.t,s}return C(i,[{key:"points",get:function(){return this._points},set:function(e){this._points=e||[]}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,s=Math.floor(i),r=i-s,n=t[0===s?s:s-1],o=t[s],a=t[s>t.length-2?t.length-1:s+1],l=t[s>t.length-3?t.length-1:s+2],u=$.vec3();return u[0]=$.catmullRomInterpolate(n[0],o[0],a[0],l[0],r),u[1]=$.catmullRomInterpolate(n[1],o[1],a[1],l[1],r),u[2]=$.catmullRomInterpolate(n[2],o[2],a[2],l[2],r),u}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}},{key:"getJSON",value:function(){return{points:points,t:this._t}}}]),i}(),Oh=$.vec3(),Nh=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._frames=[],s._eyeCurve=new Uh(b(s)),s._lookCurve=new Uh(b(s)),s._upCurve=new Uh(b(s)),r.frames&&(s.addFrames(r.frames),s.smoothFrameTimes(1)),s}return C(i,[{key:"type",get:function(){return"CameraPath"}},{key:"frames",get:function(){return this._frames}},{key:"eyeCurve",get:function(){return this._eyeCurve}},{key:"lookCurve",get:function(){return this._lookCurve}},{key:"upCurve",get:function(){return this._upCurve}},{key:"saveFrame",value:function(e){var t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}},{key:"addFrame",value:function(e,t,i,s){var r={t:e,eye:t.slice(0),look:i.slice(0),up:s.slice(0)};this._frames.push(r),this._eyeCurve.points.push(r.eye),this._lookCurve.points.push(r.look),this._upCurve.points.push(r.up)}},{key:"addFrames",value:function(e){for(var t,i=0,s=e.length;i1?1:e,t.eye=this._eyeCurve.getPoint(e,Oh),t.look=this._lookCurve.getPoint(e,Oh),t.up=this._upCurve.getPoint(e,Oh)}},{key:"sampleFrame",value:function(e,t,i,s){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,i),this._upCurve.getPoint(e,s)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=$.vec3(),i=0;this._frames[0].t=0;for(var s=[],r=1,n=this._frames.length;r1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._look1=$.vec3(),s._eye1=$.vec3(),s._up1=$.vec3(),s._look2=$.vec3(),s._eye2=$.vec3(),s._up2=$.vec3(),s._orthoScale1=1,s._orthoScale2=1,s._flying=!1,s._flyEyeLookUp=!1,s._flyingEye=!1,s._flyingLook=!1,s._callback=null,s._callbackScope=null,s._time1=null,s._time2=null,s.easing=!1!==r.easing,s.duration=r.duration,s.fit=r.fit,s.fitFOV=r.fitFOV,s.trail=r.trail,s}return C(i,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,i){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=i;var s,r,n,o,a,l=this.scene.camera,u=!!e.projection&&e.projection!==l.projection;if(this._eye1[0]=l.eye[0],this._eye1[1]=l.eye[1],this._eye1[2]=l.eye[2],this._look1[0]=l.look[0],this._look1[1]=l.look[1],this._look1[2]=l.look[2],this._up1[0]=l.up[0],this._up1[1]=l.up[1],this._up1[2]=l.up[2],this._orthoScale1=l.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)s=e.aabb;else if(6===e.length)s=e;else if(e.eye&&e.look||e.up)r=e.eye,n=e.look,o=e.up;else if(e.eye)r=e.eye;else if(e.look)n=e.look;else{var A=e;if((le.isNumeric(A)||le.isString(A))&&(a=A,!(A=this.scene.components[a])))return this.error("Component not found: "+le.inQuotes(a)),void(t&&(i?t.call(i):t()));u||(s=A.aabb||this.scene.aabb)}var c=e.poi;if(s){if(s[3]=1;e>1&&(e=1);var s=this.easing?i._ease(e,0,1,1):e,r=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?($.subVec3(r.eye,r.look,Gh),r.eye=$.lerpVec3(s,0,1,this._eye1,this._eye2,Hh),r.look=$.subVec3(Hh,Gh,Vh)):this._flyingLook&&(r.look=$.lerpVec3(s,0,1,this._look1,this._look2,Vh),r.up=$.lerpVec3(s,0,1,this._up1,this._up2,jh)):this._flyingEyeLookUp&&(r.eye=$.lerpVec3(s,0,1,this._eye1,this._eye2,Hh),r.look=$.lerpVec3(s,0,1,this._look1,this._look2,Vh),r.up=$.lerpVec3(s,0,1,this._up1,this._up2,jh)),this._projection2){var n="ortho"===this._projection2?i._easeOutExpo(e,0,1,1):i._easeInCubic(e,0,1,1);r.customProjection.matrix=$.lerpMat4(n,0,1,this._projMatrix1,this._projMatrix2)}else r.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return r.ortho.scale=this._orthoScale2,void this.stop();_e.scheduleTask(this._update,this)}}},{key:"stop",value:function(){if(this._flying){this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);var e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}}},{key:"cancel",value:function(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}},{key:"duration",get:function(){return this._duration/1e3},set:function(e){this._duration=e?1e3*e:500,this.stop()}},{key:"fit",get:function(){return this._fit},set:function(e){this._fit=!1!==e}},{key:"fitFOV",get:function(){return this._fitFOV},set:function(e){this._fitFOV=e||45}},{key:"trail",get:function(){return this._trail},set:function(e){this._trail=!!e}},{key:"destroy",value:function(){this.stop(),f(w(i.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,i,s){return-i*(e/=s)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,i,s){return i*(e/=s)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,i,s){return i*(1-Math.pow(2,-10*e/s))+t}}]),i}(),Wh=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._cameraFlightAnimation=new zh(b(s)),s._t=0,s.state=i.SCRUBBING,s._playingFromT=0,s._playingToT=0,s._playingRate=r.playingRate||1,s._playingDir=1,s._lastTime=null,s.cameraPath=r.cameraPath,s._tick=s.scene.on("tick",s._updateT,b(s)),s}return C(i,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,s,r=performance.now(),n=this._lastTime?.001*(r-this._lastTime):0;if(this._lastTime=r,0!==n)switch(this.state){case i.SCRUBBING:return;case i.PLAYING:if(this._t+=this._playingRate*n,0===(t=this._cameraPath.frames.length)||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=i.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case i.PLAYING_TO:s=this._t+this._playingRate*n*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=i.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,i,s){return-i*(e/=s)*(e-2)+t}},{key:"cameraPath",get:function(){return this._cameraPath},set:function(e){this._cameraPath=e}},{key:"rate",get:function(){return this._playingRate},set:function(e){this._playingRate=e}},{key:"play",value:function(){this._cameraPath&&(this._lastTime=null,this.state=i.PLAYING)}},{key:"playToT",value:function(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=i.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var s=this._cameraPath;if(s){var r=s.frames[e];r?(this.state=i.SCRUBBING,this._cameraFlightAnimation.flyTo(r,t)):this.error("flyToFrame - frame index out of range: "+e)}}},{key:"scrubToT",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=i.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=i.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=i.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),i}();Wh.STOPPED=0,Wh.SCRUBBING=1,Wh.PLAYING=2,Wh.PLAYING_TO=3;var Kh=$.vec3(),Xh=$.vec3();$.vec3();var Jh=$.vec3([0,-1,0]),Yh=$.vec4([0,0,0,1]),Zh=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._src=null,s._image=null,s._pos=$.vec3(),s._origin=$.vec3(),s._rtcPos=$.vec3(),s._dir=$.vec3(),s._size=1,s._imageSize=$.vec2(),s._texture=new Un(b(s)),s._plane=new rn(b(s),{geometry:new Si(b(s),Xn({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Oi(b(s),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:s._texture,emissiveMap:s._texture,backfaces:!0}),clippable:r.clippable}),s._grid=new rn(b(s),{geometry:new Si(b(s),Kn({size:1,divisions:10})),material:new Oi(b(s),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:r.clippable}),s._node=new bn(b(s),{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[s._plane,s._grid]}),s._gridVisible=!1,s.visible=!0,s.gridVisible=r.gridVisible,s.position=r.position,s.rotation=r.rotation,s.dir=r.dir,s.size=r.size,s.collidable=r.collidable,s.clippable=r.clippable,s.pickable=r.pickable,s.opacity=r.opacity,r.image?s.image=r.image:s.src=r.src,s}return C(i,[{key:"visible",get:function(){return this._plane.visible},set:function(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}},{key:"gridVisible",get:function(){return this._gridVisible},set:function(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var i=new Image;i.onload=function(){t._texture.image=i,t._imageSize[0]=i.width,t._imageSize[1]=i.height,t._updatePlaneSizeFromImage()},i.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),Le(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}},{key:"rotation",get:function(){return this._node.rotation},set:function(e){this._node.rotation=e}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"dir",get:function(){return this._dir},set:function(e){if(this._dir.set(e||[0,0,-1]),e){var t=this.scene.center,i=[-this._dir[0],-this._dir[1],-this._dir[2]];$.subVec3(t,this.position,Kh);var s=-$.dotVec3(i,Kh);$.normalizeVec3(i),$.mulVec3Scalar(i,s,Xh),$.vec3PairToQuaternion(Jh,e,Yh),this._node.quaternion=Yh}}},{key:"collidable",get:function(){return this._node.collidable},set:function(e){this._node.collidable=!1!==e}},{key:"clippable",get:function(){return this._node.clippable},set:function(e){this._node.clippable=!1!==e}},{key:"pickable",get:function(){return this._node.pickable},set:function(e){this._node.pickable=!1!==e}},{key:"opacity",get:function(){return this._node.opacity},set:function(e){this._node.opacity=e}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],i=this._imageSize[1];if(t>i){var s=i/t;this._node.scale=[e,1,e*s]}else{var r=t/i;this._node.scale=[e*r,1,e]}}}]),i}(),qh=function(e){g(i,_i);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i);var n=b(s=t.call(this,e,r));s._shadowRenderBuf=null,s._shadowViewMatrix=null,s._shadowProjMatrix=null,s._shadowViewMatrixDirty=!0,s._shadowProjMatrixDirty=!0;var o=s.scene.camera,a=s.scene.canvas;return s._onCameraViewMatrix=o.on("viewMatrix",(function(){s._shadowViewMatrixDirty=!0})),s._onCameraProjMatrix=o.on("projMatrix",(function(){s._shadowProjMatrixDirty=!0})),s._onCanvasBoundary=a.on("boundary",(function(){s._shadowProjMatrixDirty=!0})),s._state=new Zt({type:"point",pos:$.vec3([1,1,1]),color:$.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:r.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(n._shadowViewMatrixDirty){n._shadowViewMatrix||(n._shadowViewMatrix=$.identityMat4());var e=n._state.pos,t=o.look,i=o.up;$.lookAtMat4v(e,t,i,n._shadowViewMatrix),n._shadowViewMatrixDirty=!1}return n._shadowViewMatrix},getShadowProjMatrix:function(){if(n._shadowProjMatrixDirty){n._shadowProjMatrix||(n._shadowProjMatrix=$.identityMat4());var e=n.scene.canvas.canvas;$.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,n._shadowProjMatrix),n._shadowProjMatrixDirty=!1}return n._shadowProjMatrix},getShadowRenderBuf:function(){return n._shadowRenderBuf||(n._shadowRenderBuf=new zt(n.scene.canvas.canvas,n.scene.canvas.gl,{size:[1024,1024]})),n._shadowRenderBuf}}),s.pos=r.pos,s.color=r.color,s.intensity=r.intensity,s.constantAttenuation=r.constantAttenuation,s.linearAttenuation=r.linearAttenuation,s.quadraticAttenuation=r.quadraticAttenuation,s.castsShadow=r.castsShadow,s.scene._lightCreated(b(s)),s}return C(i,[{key:"type",get:function(){return"PointLight"}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.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:"constantAttenuation",get:function(){return this._state.attenuation[0]},set:function(e){this._state.attenuation[0]=e||0,this.glRedraw()}},{key:"linearAttenuation",get:function(){return this._state.attenuation[1]},set:function(e){this._state.attenuation[1]=e||0,this.glRedraw()}},{key:"quadraticAttenuation",get:function(){return this._state.attenuation[2]},set:function(e){this._state.attenuation[2]=e||0,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),f(w(i.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),i}();function $h(e){return 0==(e&e-1)}function ed(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var td=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i);var n=(s=t.call(this,e,r)).scene.canvas.gl;return s._state=new Zt({texture:new In({gl:n,target:n.TEXTURE_CUBE_MAP}),flipY:s._checkFlipY(r.minFilter),encoding:s._checkEncoding(r.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),s._src=r.src,s._images=[],s._loadSrc(r.src),se.memory.textures++,s}return C(i,[{key:"type",get:function(){return"CubeTexture"}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}},{key:"_loadSrc",value:function(e){var t=this,i=this.scene.canvas.gl;this._images=[];for(var s=!1,r=0,n=function(n){var o,a,l=new Image;l.onload=(o=l,a=n,function(){if(!s&&(o=function(e){if(!$h(e.width)||!$h(e.height)){var t=document.createElement("canvas");t.width=ed(e.width),t.height=ed(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(o),t._images[a]=o,6==++r)){var e=t._state.texture;e||(e=new In({gl:i,target:i.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}),l.onerror=function(){s=!0},l.src=e[n]},o=0;o1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).scene._lightsState.addReflectionMap(s._state),s.scene._reflectionMapCreated(b(s)),s}return C(i,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),i}(),sd=function(e){g(i,td);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).scene._lightMapCreated(b(s)),s}return C(i,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),i}(),rd=function(e){g(i,et);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,{entity:r.entity,occludable:r.occludable,worldPos:r.worldPos}))._occluded=!1,s._visible=!0,s._src=null,s._image=null,s._pos=$.vec3(),s._origin=$.vec3(),s._rtcPos=$.vec3(),s._dir=$.vec3(),s._size=1,s._imageSize=$.vec2(),s._texture=new Un(b(s),{src:r.src}),s._geometry=new Si(b(s),{primitive:"triangles",positions:[3,3,0,-3,3,0,-3,-3,0,3,-3,0],normals:[-1,0,0,-1,0,0,-1,0,0,-1,0,0],uv:[1,-1,0,-1,0,0,1,0],indices:[0,1,2,0,2,3]}),s._mesh=new rn(b(s),{geometry:s._geometry,material:new Oi(b(s),{ambient:[.9,.3,.9],shininess:30,diffuseMap:s._texture,backfaces:!0}),scale:[1,1,1],position:r.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),s.visible=!0,s.collidable=r.collidable,s.clippable=r.clippable,s.pickable=r.pickable,s.opacity=r.opacity,s.size=r.size,r.image?s.image=r.image:s.src=r.src,s}return C(i,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,f(w(i.prototype),"_setVisible",this).call(this,e)}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var i=new Image;i.onload=function(){t._texture.image=i,t._imageSize[0]=i.width,t._imageSize[1]=i.height,t._updatePlaneSizeFromImage()},i.src=this._src}}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"collidable",get:function(){return this._mesh.collidable},set:function(e){this._mesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._mesh.clippable},set:function(e){this._mesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._mesh.pickable},set:function(e){this._mesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._mesh.opacity},set:function(e){this._mesh.opacity=e}},{key:"_updatePlaneSizeFromImage",value:function(){var e=.5*this._size,t=this._imageSize[0],i=this._imageSize[1],s=i/t;this._geometry.positions=t>i?[e,e*s,0,-e,e*s,0,-e,-e*s,0,e,-e*s,0]:[e/s,e,0,-e/s,e,0,-e/s,-e,0,e/s,-e,0]}}]),i}(),nd=function(){function e(t){x(this,e),this._eye=$.vec3(),this._look=$.vec3(),this._up=$.vec3(),this._projection={},t&&this.saveCamera(t)}return C(e,[{key:"saveCamera",value:function(e){var t=e.camera,i=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:i.fov,fovAxis:i.fovAxis,near:i.near,far:i.far};break;case"ortho":this._projection={projection:"ortho",scale:i.scale,near:i.near,far:i.far};break;case"frustum":this._projection={projection:"frustum",left:i.left,right:i.right,top:i.top,bottom:i.bottom,near:i.near,far:i.far};break;case"custom":this._projection={projection:"custom",matrix:i.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var i=e.camera,s=this._projection;function r(){switch(s.type){case"perspective":i.perspective.fov=s.fov,i.perspective.fovAxis=s.fovAxis,i.perspective.near=s.near,i.perspective.far=s.far;break;case"ortho":i.ortho.scale=s.scale,i.ortho.near=s.near,i.ortho.far=s.far;break;case"frustum":i.frustum.left=s.left,i.frustum.right=s.right,i.frustum.top=s.top,i.frustum.bottom=s.bottom,i.frustum.near=s.near,i.frustum.far=s.far;break;case"custom":i.customProjection.matrix=s.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:s.scale,projection:s.projection},(function(){r(),t()})):(i.eye=this._eye,i.look=this._look,i.up=this._up,r(),i.projection=s.projection)}}]),e}(),od=$.vec3(),ad=function(){function e(t){if(x(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,t){var i=t.metaScene.scene;this.saveObjects(i,t)}}return C(e,[{key:"saveObjects",value:function(e,t,i){this.numObjects=0,this._mask=i?le.apply(i,{}):null;for(var s=!i||i.visible,r=!i||i.edges,n=!i||i.xrayed,o=!i||i.highlighted,a=!i||i.selected,l=!i||i.clippable,u=!i||i.pickable,A=!i||i.colorize,c=!i||i.opacity,h=t.metaObjects,d=e.objects,p=0,f=h.length;p1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).v0=r.v0,s.v1=r.v1,s.v2=r.v2,s.v3=r.v3,s.t=r.t,s}return C(i,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||$.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||$.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||$.vec3([0,0,0])}},{key:"v3",get:function(){return this._v3},set:function(e){this.fire("v3",this._v3=e||$.vec3([0,0,0]))}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=$.vec3();return t[0]=$.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=$.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=$.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}]),i}(),cd=function(e){g(i,Lh);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._cachedLengths=[],s._dirty=!0,s._curves=[],s._t=0,s._dirtySubs=[],s._destroyedSubs=[],s.curves=r.curves||[],s.t=r.t,s}return C(i,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,i,s;for(e=e||[],i=0,s=this._curves.length;i1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"length",get:function(){var e=this._getCurveLengths();return e[e.length-1]}},{key:"getPoint",value:function(e){for(var t,i=e*this.length,s=this._getCurveLengths(),r=0;r=i){var n=1-(s[r]-i)/(t=this._curves[r]).length;return t.getPointAt(n)}r++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],i=0,s=this._curves.length;for(e=0;e1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).v0=r.v0,s.v1=r.v1,s.v2=r.v2,s.t=r.t,s}return C(i,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||$.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||$.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||$.vec3([0,0,0])}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=$.vec3();return t[0]=$.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=$.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=$.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}]),i}(),dd=function(e){g(i,ch);var t=_(i);function i(e){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),t.call(this,e,s)}return C(i)}(),pd=function(e){g(i,we);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._skyboxMesh=new rn(b(s),{geometry:new Si(b(s),{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],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]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new Oi(b(s),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Un(b(s),{src:r.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:r.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),s.size=r.size,s.active=r.active,s}return C(i,[{key:"size",get:function(){return this._size},set:function(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}},{key:"active",get:function(){return this._skyboxMesh.visible},set:function(e){this._skyboxMesh.visible=e}}]),i}(),fd=function(){function e(){x(this,e)}return C(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),vd=$.vec4(),gd=$.vec4(),md=$.vec3(),_d=$.vec3(),yd=$.vec3(),bd=$.vec4(),wd=$.vec4(),Bd=$.vec4(),xd=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"dollyToCanvasPos",value:function(e,t,i){var s=!1,r=this._scene.camera;if(e){var n=$.subVec3(e,r.eye,md);s=$.lenVec3(n)0&&void 0!==arguments[0]?arguments[0]:{};this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);var t=e.color||[1,0,0];this._pivotSphereMaterial=new Oi(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}},{key:"disablePivotSphere",value:function(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}},{key:"startPivot",value:function(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;var e=this._scene.camera,t=$.lookAtMat4v(e.eye,e.look,e.worldUp);$.transformPoint3(t,this.getPivotPos(),this._cameraOffset);var i=this.getPivotPos();this._cameraOffset[2]+=$.distVec3(e.eye,i),t=$.inverseMat4(t);var s=$.transformVec3(t,this._cameraOffset),r=$.vec3();if($.subVec3(e.eye,i,r),$.addVec3(r,s),e.zUp){var n=r[1];r[1]=r[2],r[2]=n}this._radius=$.lenVec3(r),this._polar=Math.acos(r[1]/this._radius),this._azimuth=Math.atan2(r[0],r[2]),this._pivoting=!0}},{key:"_cameraLookingDownwards",value:function(){var e=this._scene.camera,t=$.normalizeVec3($.subVec3(e.look,e.eye,Pd)),i=$.cross3Vec3(t,e.worldUp,Cd);return $.sqLenVec3(i)<=1e-4}},{key:"getPivoting",value:function(){return this._pivoting}},{key:"setPivotPos",value:function(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}},{key:"setCanvasPivotPos",value:function(e){var t=this._scene.camera,i=Math.abs($.distVec3(this._scene.center,t.eye)),s=t.project.transposedMatrix,r=s.subarray(8,12),n=s.subarray(12),o=[0,0,-1,1],a=$.dotVec4(o,r)/$.dotVec4(o,n),l=Fd;t.project.unproject(e,a,Ed,kd,l);var u=$.normalizeVec3($.subVec3(l,t.eye,Pd)),A=$.addVec3(t.eye,$.mulVec3Scalar(u,i,Cd),Md);this.setPivotPos(A)}},{key:"getPivotPos",value:function(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}},{key:"continuePivot",value:function(e,t){if(this._pivoting&&(0!==e||0!==t)){var i=this._scene.camera,s=-e,r=-t;1===i.worldUp[2]&&(s=-s),this._azimuth+=.01*-s,this._polar+=.01*r,this._polar=$.clamp(this._polar,.001,Math.PI-.001);var n=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===i.worldUp[2]){var o=n[1];n[1]=n[2],n[2]=o}var a=$.lenVec3($.subVec3(i.look,i.eye,$.vec3())),l=this.getPivotPos();$.addVec3(n,l);var u=$.lookAtMat4v(n,l,i.worldUp);u=$.inverseMat4(u);var A=$.transformVec3(u,this._cameraOffset);u[12]-=A[0],u[13]-=A[1],u[14]-=A[2];var c=[u[8],u[9],u[10]];i.eye=[u[12],u[13],u[14]],$.subVec3(i.eye,$.mulVec3Scalar(c,a),i.look),i.up=[u[4],u[5],u[6]],this.showPivot()}}},{key:"showPivot",value:function(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}},{key:"hidePivot",value:function(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}},{key:"endPivot",value:function(){this._pivoting=!1}},{key:"destroy",value:function(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}]),e}(),Dd=function(){function e(t,i){x(this,e),this._scene=t.scene,this._cameraControl=t,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=i,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=$.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}return C(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){var e="".concat(~~this.pickCursorPos[0],"-").concat(~~this.pickCursorPos[1],"-").concat(this.scheduleSnapOrPick,"-").concat(this.schedulePickSurface,"-").concat(this.schedulePickEntity);if(this._lastHash!==e){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;var t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var i=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});i&&(i.snappedToEdge||i.snappedToVertex)?(this.snapPickResult=i,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var s=this.pickResult.canvasPos;if(s[0]===this.pickCursorPos[0]&&s[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){var r=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(r[0]===this.pickCursorPos[0]&&r[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}}}},{key:"fireEvents",value:function(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){var e=new Bt;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var t=this.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=t)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}]),e}(),Sd=$.vec2(),Td=function(){function e(t,i,s,r,n){x(this,e),this._scene=t;var o,a,l,u=i.pickController,A=0,c=0,h=0,d=0,p=!1,f=$.vec3(),v=!0,g=this._scene.canvas.canvas,m=[];function _(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];g.style.cursor="move",y(),e&&b()}function y(){A=r.pointerCanvasPos[0],c=r.pointerCanvasPos[1],h=r.pointerCanvasPos[0],d=r.pointerCanvasPos[1]}function b(){u.pickCursorPos=r.pointerCanvasPos,u.schedulePickSurface=!0,u.update(),u.picked&&u.pickedSurface&&u.pickResult&&u.pickResult.worldPos?(p=!0,f.set(u.pickResult.worldPos)):p=!1}document.addEventListener("keydown",this._documentKeyDownHandler=function(e){if(s.active&&s.pointerEnabled&&t.input.keyboardEnabled){var i=e.keyCode;m[i]=!0}}),document.addEventListener("keyup",this._documentKeyUpHandler=function(e){if(s.active&&s.pointerEnabled&&t.input.keyboardEnabled){var i=e.keyCode;m[i]=!1}}),g.addEventListener("mousedown",this._mouseDownHandler=function(e){if(s.active&&s.pointerEnabled)switch(e.which){case 1:m[t.input.KEY_SHIFT]||s.planView?(o=!0,_()):(o=!0,_(!1));break;case 2:a=!0,_();break;case 3:l=!0,s.panRightClick&&_()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=function(e){if(s.active&&s.pointerEnabled&&(o||a||l)){var i=t.canvas.boundary,u=i[2],h=i[3],d=r.pointerCanvasPos[0],v=r.pointerCanvasPos[1],g=m[t.input.KEY_SHIFT]||s.planView||!s.panRightClick&&a||s.panRightClick&&l,_=document.pointerLockElement?e.movementX:d-A,y=document.pointerLockElement?e.movementY:v-c;if(g){var b=t.camera;if("perspective"===b.projection){var w=Math.abs(p?$.lenVec3($.subVec3(f,t.camera.eye,[])):t.camera.eyeLookDist)*Math.tan(b.perspective.fov/2*Math.PI/180);n.panDeltaX+=1.5*_*w/h,n.panDeltaY+=1.5*y*w/h}else n.panDeltaX+=.5*b.ortho.scale*(_/h),n.panDeltaY+=.5*b.ortho.scale*(y/h)}else!o||a||l||s.planView||(s.firstPerson?(n.rotateDeltaY-=_/u*s.dragRotationRate/2,n.rotateDeltaX+=y/h*(s.dragRotationRate/4)):(n.rotateDeltaY-=_/u*(1.5*s.dragRotationRate),n.rotateDeltaX+=y/h*(1.5*s.dragRotationRate)));A=d,c=v}}),g.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){s.active&&s.pointerEnabled&&r.mouseover&&(v=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){if(s.active&&s.pointerEnabled)switch(e.which){case 1:case 2:case 3:o=!1,a=!1,l=!1}}),g.addEventListener("mouseup",this._mouseUpHandler=function(e){if(s.active&&s.pointerEnabled){if(3===e.which){!function(e,t){if(e){for(var i=e.target,s=0,r=0,n=0,o=0;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,n+=i.scrollLeft,o+=i.scrollTop,i=i.offsetParent;t[0]=e.pageX+n-s,t[1]=e.pageY+o-r}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Sd);var t=Sd[0],r=Sd[1];Math.abs(t-h)<3&&Math.abs(r-d)<3&&i.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Sd,event:e},!0)}g.style.removeProperty("cursor")}}),g.addEventListener("mouseenter",this._mouseEnterHandler=function(){s.active&&s.pointerEnabled});var w=1/60,B=null;g.addEventListener("wheel",this._mouseWheelHandler=function(e){if(s.active&&s.pointerEnabled){var t=performance.now()/1e3,i=null!==B?t-B:0;B=t,i>.05&&(i=.05),i0?i.cameraFlight.flyTo(Qd,(function(){i.pivotController.getPivoting()&&s.followPointer&&i.pivotController.showPivot()})):(i.cameraFlight.jumpTo(Qd),i.pivotController.getPivoting()&&s.followPointer&&i.pivotController.showPivot())}}}))}return C(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.input.off(this._onSceneKeyDown)}}]),e}(),Hd=function(){function e(t,i,s,r,n){var o=this;x(this,e),this._scene=t;var a=i.pickController,l=i.pivotController,u=i.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;var A=!1,c=!1,h=this._scene.canvas.canvas,d=function(e){var s;e&&e.worldPos&&(s=e.worldPos);var r=e&&e.entity?e.entity.aabb:t.aabb;if(s){var n=t.camera;$.subVec3(n.eye,n.look,[]),i.cameraFlight.flyTo({aabb:r})}else i.cameraFlight.flyTo({aabb:r})},p=t.tickify(this._canvasMouseMoveHandler=function(e){if(s.active&&s.pointerEnabled&&!A&&!c){var i=u.hasSubs("hover"),n=u.hasSubs("hoverEnter"),l=u.hasSubs("hoverOut"),h=u.hasSubs("hoverOff"),d=u.hasSubs("hoverSurface"),p=u.hasSubs("hoverSnapOrSurface");if(i||n||l||h||d||p)if(a.pickCursorPos=r.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=d,a.scheduleSnapOrPick=p,a.update(),a.pickResult){if(a.pickResult.entity){var f=a.pickResult.entity.id;o._lastPickedEntityId!==f&&(void 0!==o._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[o._lastPickedEntityId]},!0),u.fire("hoverEnter",a.pickResult,!0),o._lastPickedEntityId=f)}u.fire("hover",a.pickResult,!0),(a.pickResult.worldPos||a.pickResult.snappedWorldPos)&&u.fire("hoverSurface",a.pickResult,!0)}else void 0!==o._lastPickedEntityId&&(u.fire("hoverOut",{entity:t.objects[o._lastPickedEntityId]},!0),o._lastPickedEntityId=void 0),u.fire("hoverOff",{canvasPos:a.pickCursorPos},!0)}});h.addEventListener("mousemove",p),h.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(A=!0),3===e.which&&(c=!0),1===e.which&&s.active&&s.pointerEnabled&&(r.mouseDownClientX=e.clientX,r.mouseDownClientY=e.clientY,r.mouseDownCursorX=r.pointerCanvasPos[0],r.mouseDownCursorY=r.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(a.pickCursorPos=r.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),1===e.which))){var i=a.pickResult;i&&i.worldPos?(l.setPivotPos(i.worldPos),l.startPivot()):(s.smartPivot?l.setCanvasPivotPos(r.pointerCanvasPos):l.setPivotPos(t.camera.look),l.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(A=!1),3===e.which&&(c=!1),l.getPivoting()&&l.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(s.active&&s.pointerEnabled&&(1===e.which&&(l.hidePivot(),!(Math.abs(e.clientX-r.mouseDownClientX)>3||Math.abs(e.clientY-r.mouseDownClientY)>3)))){var n=u.hasSubs("picked"),A=u.hasSubs("pickedNothing"),c=u.hasSubs("pickedSurface"),h=u.hasSubs("doublePicked"),p=u.hasSubs("doublePickedSurface"),f=u.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||h||p||f))return(n||A||c)&&(a.pickCursorPos=r.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=c,a.update(),a.pickResult?(u.fire("picked",a.pickResult,!0),a.pickedSurface&&u.fire("pickedSurface",a.pickResult,!0)):u.fire("pickedNothing",{canvasPos:r.pointerCanvasPos},!0)),void(o._clicks=0);if(o._clicks++,1===o._clicks){a.pickCursorPos=r.pointerCanvasPos,a.schedulePickEntity=s.doublePickFlyTo,a.schedulePickSurface=c,a.update();var v=a.pickResult,g=a.pickedSurface;o._timeout=setTimeout((function(){v?(u.fire("picked",v,!0),g&&(u.fire("pickedSurface",v,!0),!s.firstPerson&&s.followPointer&&(i.pivotController.setPivotPos(v.worldPos),i.pivotController.startPivot()&&i.pivotController.showPivot()))):u.fire("pickedNothing",{canvasPos:r.pointerCanvasPos},!0),o._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==o._timeout&&(window.clearTimeout(o._timeout),o._timeout=null),a.pickCursorPos=r.pointerCanvasPos,a.schedulePickEntity=s.doublePickFlyTo||h||p,a.schedulePickSurface=a.schedulePickEntity&&p,a.update(),a.pickResult){if(u.fire("doublePicked",a.pickResult,!0),a.pickedSurface&&u.fire("doublePickedSurface",a.pickResult,!0),s.doublePickFlyTo&&(d(a.pickResult),!s.firstPerson&&s.followPointer)){var m=a.pickResult.entity.aabb,_=$.getAABB3Center(m);i.pivotController.setPivotPos(_),i.pivotController.startPivot()&&i.pivotController.showPivot()}}else if(u.fire("doublePickedNothing",{canvasPos:r.pointerCanvasPos},!0),s.doublePickFlyTo&&(d(),!s.firstPerson&&s.followPointer)){var y=t.aabb,b=$.getAABB3Center(y);i.pivotController.setPivotPos(b),i.pivotController.startPivot()&&i.pivotController.showPivot()}o._clicks=0}}},!1)}return C(e,[{key:"reset",value:function(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}]),e}(),jd=function(){function e(t,i,s,r,n){x(this,e),this._scene=t;var o=t.input,a=[],l=t.canvas.canvas,u=!0;this._onSceneMouseMove=o.on("mousemove",(function(){u=!0})),this._onSceneKeyDown=o.on("keydown",(function(e){s.active&&s.pointerEnabled&&t.input.keyboardEnabled&&r.mouseover&&(a[e]=!0,e===o.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=o.on("keyup",(function(e){s.active&&s.pointerEnabled&&t.input.keyboardEnabled&&(a[e]=!1,e===o.KEY_SHIFT&&(l.style.cursor=null),i.pivotController.getPivoting()&&i.pivotController.endPivot())})),this._onTick=t.on("tick",(function(e){if(s.active&&s.pointerEnabled&&t.input.keyboardEnabled&&r.mouseover){var l=i.cameraControl,A=e.deltaTime/1e3;if(!s.planView){var c=l._isKeyDownForAction(l.ROTATE_Y_POS,a),h=l._isKeyDownForAction(l.ROTATE_Y_NEG,a),d=l._isKeyDownForAction(l.ROTATE_X_POS,a),p=l._isKeyDownForAction(l.ROTATE_X_NEG,a),f=A*s.keyboardRotationRate;(c||h||d||p)&&(!s.firstPerson&&s.followPointer&&i.pivotController.startPivot(),c?n.rotateDeltaY+=f:h&&(n.rotateDeltaY-=f),d?n.rotateDeltaX+=f:p&&(n.rotateDeltaX-=f),!s.firstPerson&&s.followPointer&&i.pivotController.startPivot())}if(!a[o.KEY_CTRL]&&!a[o.KEY_ALT]){var v=l._isKeyDownForAction(l.DOLLY_BACKWARDS,a),g=l._isKeyDownForAction(l.DOLLY_FORWARDS,a);if(v||g){var m=A*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&i.pivotController.startPivot(),g?n.dollyDelta-=m:v&&(n.dollyDelta+=m),u&&(r.followPointerDirty=!0,u=!1)}}var _=l._isKeyDownForAction(l.PAN_FORWARDS,a),y=l._isKeyDownForAction(l.PAN_BACKWARDS,a),b=l._isKeyDownForAction(l.PAN_LEFT,a),w=l._isKeyDownForAction(l.PAN_RIGHT,a),B=l._isKeyDownForAction(l.PAN_UP,a),x=l._isKeyDownForAction(l.PAN_DOWN,a),P=(a[o.KEY_ALT]?.3:1)*A*s.keyboardPanRate;(_||y||b||w||B||x)&&(!s.firstPerson&&s.followPointer&&i.pivotController.startPivot(),x?n.panDeltaY+=P:B&&(n.panDeltaY+=-P),w?n.panDeltaX+=-P:b&&(n.panDeltaX+=P),y?n.panDeltaZ+=P:_&&(n.panDeltaZ+=-P))}}))}return C(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}]),e}(),Gd=$.vec3(),zd=function(){function e(t,i,s,r,n){x(this,e),this._scene=t;var o=t.camera,a=i.pickController,l=i.pivotController,u=i.panController,A=1,c=1,h=null;this._onTick=t.on("tick",(function(){if(s.active&&s.pointerEnabled){var e="default";if(Math.abs(n.dollyDelta)<.001&&(n.dollyDelta=0),Math.abs(n.rotateDeltaX)<.001&&(n.rotateDeltaX=0),Math.abs(n.rotateDeltaY)<.001&&(n.rotateDeltaY=0),0===n.rotateDeltaX&&0===n.rotateDeltaY||(n.dollyDelta=0),s.followPointer){if(--A<=0&&(A=1,0!==n.dollyDelta)){if(0===n.rotateDeltaY&&0===n.rotateDeltaX&&s.followPointer&&r.followPointerDirty&&(a.pickCursorPos=r.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.pickResult&&a.pickResult.worldPos?h=a.pickResult.worldPos:(c=1,h=null),r.followPointerDirty=!1),h){var i=Math.abs($.lenVec3($.subVec3(h,t.camera.eye,Gd)));c=i/s.dollyProximityThreshold}cs.longTapRadius||Math.abs(g)>s.longTapRadius)&&(clearTimeout(r.longTouchTimeout),r.longTouchTimeout=null),s.planView){var m=t.camera;if("perspective"===m.projection){var _=Math.abs(t.camera.eyeLookDist)*Math.tan(m.perspective.fov/2*Math.PI/180);n.panDeltaX+=v*_/l*s.touchPanRate,n.panDeltaY+=g*_/l*s.touchPanRate}else n.panDeltaX+=.5*m.ortho.scale*(v/l)*s.touchPanRate,n.panDeltaY+=.5*m.ortho.scale*(g/l)*s.touchPanRate}else n.rotateDeltaY-=v/a*(1*s.dragRotationRate),n.rotateDeltaX+=g/l*(1.5*s.dragRotationRate)}else if(2===p){var y=d[0],b=d[1];Xd(y,u),Xd(b,A);var w=$.geometricMeanVec2(h[0],h[1]),B=$.geometricMeanVec2(u,A),x=$.vec2();$.subVec2(w,B,x);var P=x[0],C=x[1],M=t.camera,F=$.distVec2([y.pageX,y.pageY],[b.pageX,b.pageY]),E=($.distVec2(h[0],h[1])-F)*s.touchDollyRate;if(n.dollyDelta=E,Math.abs(E)<1)if("perspective"===M.projection){var k=o.pickResult?o.pickResult.worldPos:t.center,I=Math.abs($.lenVec3($.subVec3(k,t.camera.eye,[])))*Math.tan(M.perspective.fov/2*Math.PI/180);n.panDeltaX-=P*I/l*s.touchPanRate,n.panDeltaY-=C*I/l*s.touchPanRate}else n.panDeltaX-=.5*M.ortho.scale*(P/l)*s.touchPanRate,n.panDeltaY-=.5*M.ortho.scale*(C/l)*s.touchPanRate;r.pointerCanvasPos=B}for(var D=0;D-1&&t-c<150&&(h>-1&&c-h<325?(Yd(n[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=o,a.update(),a.pickResult?(a.pickResult.touchInput=!0,l.fire("doublePicked",a.pickResult),a.pickedSurface&&l.fire("doublePickedSurface",a.pickResult),s.doublePickFlyTo&&p(a.pickResult)):(l.fire("doublePickedNothing"),s.doublePickFlyTo&&p()),h=-1):$.distVec2(u[0],A)<4&&(Yd(n[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=o,a.update(),a.pickResult?(a.pickResult.touchInput=!0,l.fire("picked",a.pickResult),a.pickedSurface&&l.fire("pickedSurface",a.pickResult)):l.fire("pickedNothing"),h=t),c=-1),u.length=i.length;for(var d=0,f=i.length;d1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e,r)).PAN_LEFT=0,s.PAN_RIGHT=1,s.PAN_UP=2,s.PAN_DOWN=3,s.PAN_FORWARDS=4,s.PAN_BACKWARDS=5,s.ROTATE_X_POS=6,s.ROTATE_X_NEG=7,s.ROTATE_Y_POS=8,s.ROTATE_Y_NEG=9,s.DOLLY_FORWARDS=10,s.DOLLY_BACKWARDS=11,s.AXIS_VIEW_RIGHT=12,s.AXIS_VIEW_BACK=13,s.AXIS_VIEW_LEFT=14,s.AXIS_VIEW_FRONT=15,s.AXIS_VIEW_TOP=16,s.AXIS_VIEW_BOTTOM=17,s._keyMap={},s.scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},s._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},s._states={pointerCanvasPos:$.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:$.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},s._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};var n=s.scene;return s._controllers={cameraControl:b(s),pickController:new Dd(b(s),s._configs),pivotController:new Id(n,s._configs),panController:new xd(n),cameraFlight:new zh(b(s),{duration:.5})},s._handlers=[new Wd(s.scene,s._controllers,s._configs,s._states,s._updates),new Jd(s.scene,s._controllers,s._configs,s._states,s._updates),new Td(s.scene,s._controllers,s._configs,s._states,s._updates),new Vd(s.scene,s._controllers,s._configs,s._states,s._updates),new Hd(s.scene,s._controllers,s._configs,s._states,s._updates),new Zd(s.scene,s._controllers,s._configs,s._states,s._updates),new jd(s.scene,s._controllers,s._configs,s._states,s._updates)],s._cameraUpdater=new zd(s.scene,s._controllers,s._configs,s._states,s._updates),s.navMode=r.navMode,r.planView&&(s.planView=r.planView),s.constrainVertical=r.constrainVertical,r.keyboardLayout?s.keyboardLayout=r.keyboardLayout:s.keyMap=r.keyMap,s.doublePickFlyTo=r.doublePickFlyTo,s.panRightClick=r.panRightClick,s.active=r.active,s.followPointer=r.followPointer,s.rotationInertia=r.rotationInertia,s.keyboardPanRate=r.keyboardPanRate,s.touchPanRate=r.touchPanRate,s.keyboardRotationRate=r.keyboardRotationRate,s.dragRotationRate=r.dragRotationRate,s.touchDollyRate=r.touchDollyRate,s.dollyInertia=r.dollyInertia,s.dollyProximityThreshold=r.dollyProximityThreshold,s.dollyMinSpeed=r.dollyMinSpeed,s.panInertia=r.panInertia,s.pointerEnabled=!0,s.keyboardDollyRate=r.keyboardDollyRate,s.mouseWheelDollyRate=r.mouseWheelDollyRate,s}return C(i,[{key:"keyMap",get:function(){return this._keyMap},set:function(e){if(e=e||"qwerty",le.isString(e)){var t=this.scene.input,i={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":i[this.PAN_LEFT]=[t.KEY_A],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_Z],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":i[this.PAN_LEFT]=[t.KEY_Q],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_W],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=i}else{var s=e;this._keyMap=s}}},{key:"_isKeyDownForAction",value:function(e,t){var i=this._keyMap[e];if(!i)return!1;t||(t=this.scene.input.keyDown);for(var s=0,r=i.length;s0&&void 0!==arguments[0]?arguments[0]:{};this._controllers.pivotController.enablePivotSphere(e)}},{key:"disablePivotSphere",value:function(){this._controllers.pivotController.disablePivotSphere()}},{key:"smartPivot",get:function(){return this._configs.smartPivot},set:function(e){this._configs.smartPivot=!1!==e}},{key:"doubleClickTimeFrame",get:function(){return this._configs.doubleClickTimeFrame},set:function(e){this._configs.doubleClickTimeFrame=null!=e?e:250}},{key:"destroy",value:function(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),f(w(i.prototype),"destroy",this).call(this)}},{key:"_destroyHandlers",value:function(){for(var e=0,t=this._handlers.length;e1&&void 0!==arguments[1]?arguments[1]:{};if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);var i=this.metaScene,s=e.properties;if(e.propertySets)for(var r=0,n=e.propertySets.length;r0?rp(t):null,o=i&&i.length>0?rp(i):null;return function e(t){if(t){var i=!0;(o&&o[t.type]||n&&!n[t.type])&&(i=!1),i&&s.push(t.id);var r=t.children;if(r)for(var a=0,l=r.length;a>t;i.sort(jc);for(var a=new Int32Array(e.length),l=0,u=i.length;le[r+1]){var o=e[r];e[r]=e[r+1],e[r+1]=o}zc=new Int32Array(e),t.sort(Wc);for(var a=new Int32Array(e.length),l=0,u=t.length;l0)for(var s=i._meshes,r=0,n=s.length;r0)for(var o=this._meshes,a=0,l=o.length;a1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._dtxEnabled=s.scene.dtxEnabled&&!1!==r.dtxEnabled,s._enableVertexWelding=!1,s._enableIndexBucketing=!1,s._vboBatchingLayerScratchMemory=no(),s._textureTranscoder=r.textureTranscoder||Uc(s.scene.viewer),s._maxGeometryBatchSize=r.maxGeometryBatchSize,s._aabb=$.collapseAABB3(),s._aabbDirty=!0,s._quantizationRanges={},s._vboInstancingLayers={},s._vboBatchingLayers={},s._dtxLayers={},s._meshList=[],s.layerList=[],s._entityList=[],s._geometries={},s._dtxBuckets={},s._textures={},s._textureSets={},s._transforms={},s._meshes={},s._unusedMeshes={},s._entities={},s.renderFlags=new Wr,s.numGeometries=0,s.numPortions=0,s.numVisibleLayerPortions=0,s.numTransparentLayerPortions=0,s.numXRayedLayerPortions=0,s.numHighlightedLayerPortions=0,s.numSelectedLayerPortions=0,s.numEdgesLayerPortions=0,s.numPickableLayerPortions=0,s.numClippableLayerPortions=0,s.numCulledLayerPortions=0,s.numEntities=0,s._numTriangles=0,s._numLines=0,s._numPoints=0,s._edgeThreshold=r.edgeThreshold||10,s._origin=$.vec3(r.origin||[0,0,0]),s._position=$.vec3(r.position||[0,0,0]),s._rotation=$.vec3(r.rotation||[0,0,0]),s._quaternion=$.vec4(r.quaternion||[0,0,0,1]),s._conjugateQuaternion=$.vec4(r.quaternion||[0,0,0,1]),r.rotation&&$.eulerToQuaternion(s._rotation,"XYZ",s._quaternion),s._scale=$.vec3(r.scale||[1,1,1]),s._worldRotationMatrix=$.mat4(),s._worldRotationMatrixConjugate=$.mat4(),s._matrix=$.mat4(),s._matrixDirty=!0,s._rebuildMatrices(),s._worldNormalMatrix=$.mat4(),$.inverseMat4(s._matrix,s._worldNormalMatrix),$.transposeMat4(s._worldNormalMatrix),(r.matrix||r.position||r.rotation||r.scale||r.quaternion)&&(s._viewMatrix=$.mat4(),s._viewNormalMatrix=$.mat4(),s._viewMatrixDirty=!0,s._matrixNonIdentity=!0),s._opacity=1,s._colorize=[1,1,1],s._saoEnabled=!1!==r.saoEnabled,s._pbrEnabled=!1!==r.pbrEnabled,s._colorTextureEnabled=!1!==r.colorTextureEnabled,s._isModel=r.isModel,s._isModel&&s.scene._registerModel(b(s)),s._onCameraViewMatrix=s.scene.camera.on("matrix",(function(){s._viewMatrixDirty=!0})),s._meshesWithDirtyMatrices=[],s._numMeshesWithDirtyMatrices=0,s._onTick=s.scene.on("tick",(function(){for(;s._numMeshesWithDirtyMatrices>0;)s._meshesWithDirtyMatrices[--s._numMeshesWithDirtyMatrices]._updateMatrix()})),s._createDefaultTextureSet(),s.visible=r.visible,s.culled=r.culled,s.pickable=r.pickable,s.clippable=r.clippable,s.collidable=r.collidable,s.castsShadow=r.castsShadow,s.receivesShadow=r.receivesShadow,s.xrayed=r.xrayed,s.highlighted=r.highlighted,s.selected=r.selected,s.edges=r.edges,s.colorize=r.colorize,s.opacity=r.opacity,s.backfaces=r.backfaces,s}return C(i,[{key:"_meshMatrixDirty",value:function(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}},{key:"_createDefaultTextureSet",value:function(){var e=new Cc({id:"defaultColorTexture",texture:new In({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Cc({id:"defaultMetalRoughTexture",texture:new In({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),i=new Cc({id:"defaultNormalsTexture",texture:new In({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),s=new Cc({id:"defaultEmissiveTexture",texture:new In({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),r=new Cc({id:"defaultOcclusionTexture",texture:new In({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=i,this._textures.defaultEmissiveTexture=s,this._textures.defaultOcclusionTexture=r,this._textureSets.defaultTextureSet=new Pc({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:i,emissiveTexture:s,occlusionTexture:r})}},{key:"isPerformanceModel",get:function(){return!0}},{key:"transforms",get:function(){return this._transforms}},{key:"textures",get:function(){return this._textures}},{key:"textureSets",get:function(){return this._textureSets}},{key:"meshes",get:function(){return this._meshes}},{key:"objects",get:function(){return this._entities}},{key:"origin",get:function(){return this._origin}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),$.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),$.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){}},{key:"matrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix},set:function(e){this._matrix.set(e||uh),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),$.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),$.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"rotationMatrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}},{key:"_rebuildMatrices",value:function(){this._matrixDirty&&($.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),$.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),$.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}},{key:"rotationMatrixConjugate",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}},{key:"_setWorldMatrixDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0}},{key:"_transformDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}},{key:"_sceneModelDirty",value:function(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(var e=0,t=this._entityList.length;e0},set:function(e){e=!1!==e,this._visible=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._selected=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._edges=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,i=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var l=e.colors,u=new Uint8Array(l.length),A=0,c=l.length;A>24&255,r=i>>16&255,n=i>>8&255,o=255&i;switch(e.pickColor=new Uint8Array([o,n,r,s]),e.solid="solid"===e.primitive,t.origin=$.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),this._meshes[e.id]=t,this._unusedMeshes[e.id]=t,this._meshList.push(t),t}},{key:"_getNumPrimitives",value:function(e){var t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(var i=0,s=e.buckets.length;i>>0).toString(16)}},{key:"_getVBOInstancingLayer",value:function(e){var t=this,i=e.origin,s=e.textureSetId||"-",r=e.geometryId,n="".concat(Math.round(i[0]),".").concat(Math.round(i[1]),".").concat(Math.round(i[2]),".").concat(s,".").concat(r),o=this._vboInstancingLayers[n];if(o)return o;for(var a=e.textureSet,l=e.geometry;!o;)switch(l.primitive){case"triangles":case"surface":o=new rl({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!1});break;case"solid":o=new rl({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!0});break;case"lines":o=new jl({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0});break;case"points":o=new Lu({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0})}return this._vboInstancingLayers[n]=o,this.layerList.push(o),o}},{key:"createEntity",value:function(e){if(void 0===e.id?e.id=$.createUUID():this.scene.components[e.id]&&(this.error("Scene already has a Component with this ID: ".concat(e.id," - will assign random ID")),e.id=$.createUUID()),void 0!==e.meshIds){var t=0;this._visible&&!1!==e.visible&&(t|=Qe),this._pickable&&!1!==e.pickable&&(t|=He),this._culled&&!1!==e.culled&&(t|=Ve),this._clippable&&!1!==e.clippable&&(t|=je),this._collidable&&!1!==e.collidable&&(t|=Ge),this._edges&&!1!==e.edges&&(t|=Xe),this._xrayed&&!1!==e.xrayed&&(t|=ze),this._highlighted&&!1!==e.highlighted&&(t|=We),this._selected&&!1!==e.selected&&(t|=Ke),e.flags=t,this._createEntity(e)}else this.error("Config missing: meshIds")}},{key:"_createEntity",value:function(e){for(var t=[],i=0,s=e.meshIds.length;it.sortId?1:0}));for(var o=0,a=this.layerList.length;o0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}},{key:"_updateRenderFlagsVisibleLayers",value:function(){var e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(var t=0,i=this.layerList.length;t0){var t="".concat(this.id,"-dummyEntityForUnusedMeshes");this.warn('Creating dummy SceneModelEntity "'.concat(t,'" for unused SceneMeshes: [').concat(e.join(","),"]")),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}},{key:"_getActiveSectionPlanesForLayer",value:function(e){var t=this.renderFlags,i=this.scene._sectionPlanesState.sectionPlanes,s=i.length,r=e.layerIndex*s;if(s>0)for(var n=0;n0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){var t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0)this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0));if(this.numSelectedLayerPortions>0){var i=this.scene.selectedMaterial._state;i.fill&&(i.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),i.edges&&(i.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){var s=this.scene.highlightMaterial._state;s.fill&&(s.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),s.edges&&(s.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"drawColorOpaque",value:function(e){for(var t=this.renderFlags,i=0,s=t.visibleLayers.length;i2&&void 0!==arguments[2]&&arguments[2],s=e.positionsCompressed||[],r=Gc(e.indices||[],t),n=Kc(e.edgeIndices||[]);function o(e,t){if(e>t){var i=e;e=t,t=i}function s(i,s){return i!==e?e-i:s!==t?t-s:0}for(var r=0,o=(n.length>>1)-1;r<=o;){var a=o+r>>1,l=s(n[2*a],n[2*a+1]);if(l>0)r=a+1;else{if(!(l<0))return a;o=a-1}}return-r-1}var a=new Int32Array(n.length/2);a.fill(0);var l=s.length/3;if(l>8*(1<h.maxNumPositions&&(h=c()),h.bucketNumber>8)return[e];-1===u[v]&&(u[v]=h.numPositions++,h.positionsCompressed.push(s[3*v]),h.positionsCompressed.push(s[3*v+1]),h.positionsCompressed.push(s[3*v+2])),-1===u[g]&&(u[g]=h.numPositions++,h.positionsCompressed.push(s[3*g]),h.positionsCompressed.push(s[3*g+1]),h.positionsCompressed.push(s[3*g+2])),-1===u[m]&&(u[m]=h.numPositions++,h.positionsCompressed.push(s[3*m]),h.positionsCompressed.push(s[3*m+1]),h.positionsCompressed.push(s[3*m+2])),h.indices.push(u[v]),h.indices.push(u[g]),h.indices.push(u[m]);var _=void 0;(_=o(v,g))>=0&&0===a[_]&&(a[_]=1,h.edgeIndices.push(u[n[2*_]]),h.edgeIndices.push(u[n[2*_+1]])),(_=o(v,m))>=0&&0===a[_]&&(a[_]=1,h.edgeIndices.push(u[n[2*_]]),h.edgeIndices.push(u[n[2*_+1]])),(_=o(g,m))>=0&&0===a[_]&&(a[_]=1,h.edgeIndices.push(u[n[2*_]]),h.edgeIndices.push(u[n[2*_+1]]))}var y=t/8*2,b=t/8,B=2*s.length+(r.length+n.length)*y,w=0;return s.length,A.forEach((function(e){w+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*b,e.positionsCompressed.length})),w>B?[e]:(i&&Xc(A,e),A)}({positionsCompressed:s,indices:r,edgeIndices:n},s.length/3>65536?16:8):o=[{positionsCompressed:s,indices:r,edgeIndices:n}];return o}var dh=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,e,r))._positions=r.positions||[],r.indices)s._indices=r.indices;else{s._indices=[];for(var n=0,o=s._positions.length/3-1;n1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"BCFViewpoints",e,r)).originatingSystem=r.originatingSystem||"xeokit.io",s.authoringTool=r.authoringTool||"xeokit.io",s}return C(i,[{key:"getViewpoint",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=this.viewer.scene,s=i.camera,r=i.realWorldOffset,n=!0===t.reverseClippingPlanes,o={},a=$.normalizeVec3($.subVec3(s.look,s.eye,$.vec3())),l=s.eye,u=s.up;s.yUp&&(a=bh(a),l=bh(l),u=bh(u));var A=_h($.addVec3(l,r));"ortho"===s.projection?o.orthogonal_camera={camera_view_point:A,camera_direction:_h(a),camera_up_vector:_h(u),view_to_world_scale:s.ortho.scale}:o.perspective_camera={camera_view_point:A,camera_direction:_h(a),camera_up_vector:_h(u),field_of_view:s.perspective.fov};var c=i.sectionPlanes;for(var d in c)if(c.hasOwnProperty(d)){var p=c[d];if(!p.active)continue;var f=p.pos,v=void 0;v=n?$.negateVec3(p.dir,$.vec3()):p.dir,s.yUp&&(f=bh(f),v=bh(v)),$.addVec3(f,r),f=_h(f),v=_h(v),o.clipping_planes||(o.clipping_planes=[]),o.clipping_planes.push({location:f,direction:v})}var g=i.lineSets;for(var m in g)if(g.hasOwnProperty(m)){var _=g[m];o.lines||(o.lines=[]);for(var y=_.positions,b=_.indices,B=0,w=b.length/2;B1&&void 0!==arguments[1]?arguments[1]:{};if(e){var s=this.viewer,r=s.scene,n=r.camera,o=!1!==i.rayCast,a=!1!==i.immediate,l=!1!==i.reset,u=r.realWorldOffset,A=!0===i.reverseClippingPlanes;if(r.clearSectionPlanes(),e.clipping_planes&&e.clipping_planes.length>0&&e.clipping_planes.forEach((function(e){var t=yh(e.location,ph),i=yh(e.direction,ph);A&&$.negateVec3(i),$.subVec3(t,u),n.yUp&&(t=Bh(t),i=Bh(i)),new cn(r,{pos:t,dir:i})})),r.clearLines(),e.lines&&e.lines.length>0){var c=[],h=[],d=0;e.lines.forEach((function(e){e.start_point&&e.end_point&&(c.push(e.start_point.x),c.push(e.start_point.y),c.push(e.start_point.z),c.push(e.end_point.x),c.push(e.end_point.y),c.push(e.end_point.z),h.push(d++),h.push(d++))})),new dh(r,{positions:c,indices:h,clippable:!1,collidable:!0})}if(r.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){var t=e.bitmap_type||"jpg",i=e.bitmap_data,s=yh(e.location,fh),o=yh(e.normal,vh),a=yh(e.up,gh),l=e.height||1;t&&i&&s&&o&&a&&(n.yUp&&(s=Bh(s),o=Bh(o),a=Bh(a)),new qn(r,{src:i,type:t,pos:s,normal:o,up:a,clippable:!1,collidable:!0,height:l}))})),l&&(r.setObjectsXRayed(r.xrayedObjectIds,!1),r.setObjectsHighlighted(r.highlightedObjectIds,!1),r.setObjectsSelected(r.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(r.setObjectsVisible(r.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.visible=!1}))}))):(r.setObjectsVisible(r.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.visible=!0}))})));var p=e.components.visibility.view_setup_hints;p&&(!1===p.spaces_visible&&r.setObjectsVisible(s.metaScene.getObjectIDsByType("IfcSpace"),!1),void 0!==p.spaces_translucent&&r.setObjectsXRayed(s.metaScene.getObjectIDsByType("IfcSpace"),!0),p.space_boundaries_visible,!1===p.openings_visible&&r.setObjectsVisible(s.metaScene.getObjectIDsByType("IfcOpening"),!0),p.space_boundaries_translucent,void 0!==p.openings_translucent&&r.setObjectsXRayed(s.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(r.setObjectsSelected(r.selectedObjectIds,!1),e.components.selection.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.selected=!0}))}))),e.components.translucency&&(r.setObjectsXRayed(r.xrayedObjectIds,!1),e.components.translucency.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.xrayed=!0}))}))),e.components.coloring&&e.components.coloring.forEach((function(e){var s=e.color,r=0,n=!1;8===s.length&&((r=parseInt(s.substring(0,2),16)/256)<=1&&r>=.95&&(r=1),s=s.substring(2),n=!0);var o=[parseInt(s.substring(0,2),16)/256,parseInt(s.substring(2,4),16)/256,parseInt(s.substring(4,6),16)/256];e.components.map((function(e){return t._withBCFComponent(i,e,(function(e){e.colorize=o,n&&(e.opacity=r)}))}))}))}if(e.perspective_camera||e.orthogonal_camera){var f,v,g,m;if(e.perspective_camera?(f=yh(e.perspective_camera.camera_view_point,ph),v=yh(e.perspective_camera.camera_direction,ph),g=yh(e.perspective_camera.camera_up_vector,ph),n.perspective.fov=e.perspective_camera.field_of_view,m="perspective"):(f=yh(e.orthogonal_camera.camera_view_point,ph),v=yh(e.orthogonal_camera.camera_direction,ph),g=yh(e.orthogonal_camera.camera_up_vector,ph),n.ortho.scale=e.orthogonal_camera.view_to_world_scale,m="ortho"),$.subVec3(f,u),n.yUp&&(f=Bh(f),v=Bh(v),g=Bh(g)),o){var _=r.pick({pickSurface:!0,origin:f,direction:v});v=_?_.worldPos:$.addVec3(f,v,ph)}else v=$.addVec3(f,v,ph);a?(n.eye=f,n.look=v,n.up=g,n.projection=m):s.cameraFlight.flyTo({eye:f,look:v,up:g,duration:i.duration,projection:m})}}}},{key:"_withBCFComponent",value:function(e,t,i){var s=this.viewer,r=s.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){var n=t.authoring_tool_id,o=r.objects[n];if(o)return void i(o);if(e.updateCompositeObjects)if(s.metaScene.metaObjects[n])return void r.withObjects(s.metaScene.getObjectIDsInSubtree(n),i)}if(t.ifc_guid){var a=t.ifc_guid,l=r.objects[a];if(l)return void i(l);if(e.updateCompositeObjects)if(s.metaScene.metaObjects[a])return void r.withObjects(s.metaScene.getObjectIDsInSubtree(a),i);Object.keys(r.models).forEach((function(t){var n=$.globalizeObjectId(t,a),o=r.objects[n];o?i(o):e.updateCompositeObjects&&s.metaScene.metaObjects[n]&&r.withObjects(s.metaScene.getObjectIDsInSubtree(n),i)}))}}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this)}}]),i}();function _h(e){return{x:e[0],y:e[1],z:e[2]}}function yh(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function bh(e){return new Float64Array([e[0],-e[2],e[1]])}function Bh(e){return new Float64Array([e[0],e[2],-e[1]])}function wh(e){var t="";return t+=Math.round(255*e[0]).toString(16).padStart(2,"0"),t+=Math.round(255*e[1]).toString(16).padStart(2,"0"),t+=Math.round(255*e[2]).toString(16).padStart(2,"0")}var xh=$.vec3(),Ph=function(e,t,i,s){var r=e-i,n=t-s;return Math.sqrt(r*r+n*n)},Ch=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,e.viewer.scene,r)).plugin=e,s._container=r.container,!s._container)throw"config missing: container";s._eventSubs={};var n=s.plugin.viewer.scene;s._originMarker=new et(n,r.origin),s._targetMarker=new et(n,r.target),s._originWorld=$.vec3(),s._targetWorld=$.vec3(),s._wp=new Float64Array(24),s._vp=new Float64Array(24),s._pp=new Float64Array(24),s._cp=new Float64Array(8),s._xAxisLabelCulled=!1,s._yAxisLabelCulled=!1,s._zAxisLabelCulled=!1,s._color=r.color||s.plugin.defaultColor;var o=r.onMouseOver?function(e){r.onMouseOver(e,b(s)),s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,a=r.onMouseLeave?function(e){r.onMouseLeave(e,b(s)),s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,l=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},u=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},A=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},c=r.onContextMenu?function(e){r.onContextMenu(e,b(s))}:null,h=function(e){s.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return s._originDot=new it(s._container,{fillColor:s._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._targetDot=new it(s._container,{fillColor:s._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._lengthWire=new tt(s._container,{color:s._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._xAxisWire=new tt(s._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._yAxisWire=new tt(s._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._zAxisWire=new tt(s._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._lengthLabel=new st(s._container,{fillColor:s._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._xAxisLabel=new st(s._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._yAxisLabel=new st(s._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._zAxisLabel=new st(s._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),s._wpDirty=!1,s._vpDirty=!1,s._cpDirty=!1,s._sectionPlanesDirty=!0,s._visible=!1,s._originVisible=!1,s._targetVisible=!1,s._wireVisible=!1,s._axisVisible=!1,s._xAxisVisible=!1,s._yAxisVisible=!1,s._zAxisVisible=!1,s._axisEnabled=!0,s._labelsVisible=!1,s._labelsOnWires=!1,s._clickable=!1,s._originMarker.on("worldPos",(function(e){s._originWorld.set(e||[0,0,0]),s._wpDirty=!0,s._needUpdate(0)})),s._targetMarker.on("worldPos",(function(e){s._targetWorld.set(e||[0,0,0]),s._wpDirty=!0,s._needUpdate(0)})),s._onViewMatrix=n.camera.on("viewMatrix",(function(){s._vpDirty=!0,s._needUpdate(0)})),s._onProjMatrix=n.camera.on("projMatrix",(function(){s._cpDirty=!0,s._needUpdate()})),s._onCanvasBoundary=n.canvas.on("boundary",(function(){s._cpDirty=!0,s._needUpdate(0)})),s._onMetricsUnits=n.metrics.on("units",(function(){s._cpDirty=!0,s._needUpdate()})),s._onMetricsScale=n.metrics.on("scale",(function(){s._cpDirty=!0,s._needUpdate()})),s._onMetricsOrigin=n.metrics.on("origin",(function(){s._cpDirty=!0,s._needUpdate()})),s._onSectionPlaneUpdated=n.on("sectionPlaneUpdated",(function(){s._sectionPlanesDirty=!0,s._needUpdate()})),s.approximate=r.approximate,s.visible=r.visible,s.originVisible=r.originVisible,s.targetVisible=r.targetVisible,s.wireVisible=r.wireVisible,s.axisVisible=r.axisVisible,s.xAxisVisible=r.xAxisVisible,s.yAxisVisible=r.yAxisVisible,s.zAxisVisible=r.zAxisVisible,s.labelsVisible=r.labelsVisible,s.labelsOnWires=r.labelsOnWires,s}return C(i,[{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._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&($.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._originWorld)||this._isSliced(this._targetWorld))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}var t=this._originMarker.viewPos[2],i=this._targetMarker.viewPos[2];if(t>-.3||i>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){$.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var s=this._pp,r=this._cp,n=e.canvas.canvas.getBoundingClientRect(),o=this._container.getBoundingClientRect(),a=n.top-o.top,l=n.left-o.left,u=e.canvas.boundary,A=u[2],c=u[3],h=0,d=this.plugin.viewer.scene.metrics,p=d.scale,f=d.units,v=d.unitsInfo[f].abbrev,g=0,m=s.length;g1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e.viewer.scene))._canvasToPagePos=r.canvasToPagePos,s.pointerLens=r.pointerLens,s._active=!1,s._currentDistanceMeasurement=null,s._currentDistanceMeasurementInitState={wireVisible:null,axisVisible:null,xAxisVisible:null,yaxisVisible:null,zAxisVisible:null,targetVisible:null},s._initMarkerDiv(),s._onCameraControlHoverSnapOrSurface=null,s._onCameraControlHoverSnapOrSurfaceOff=null,s._onMouseDown=null,s._onMouseUp=null,s._onCanvasTouchStart=null,s._onCanvasTouchEnd=null,s._snapping=!1!==r.snapping,s._mouseState=0,s._attachPlugin(e,r),s}return C(i,[{key:"_initMarkerDiv",value:function(){var e=document.createElement("div");e.setAttribute("id","myMarkerDiv");var t=this.scene.canvas.canvas;t.parentNode.insertBefore(e,t),e.style.background="black",e.style.border="2px solid blue",e.style.borderRadius="10px",e.style.width="5px",e.style.height="5px",e.style.top="-200px",e.style.left="-200px",e.style.margin="0 0",e.style.zIndex="100",e.style.position="absolute",e.style.pointerEvents="none",this._markerDiv=e}},{key:"_destroyMarkerDiv",value:function(){if(this._markerDiv){var e=document.getElementById("myMarkerDiv");e.parentNode.removeChild(e),this._markerDiv=null}}},{key:"_attachPlugin",value:function(e){this.distanceMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){this._markerDiv||this._initMarkerDiv(),this.fire("activated",!0);var t=this.distanceMeasurementsPlugin,i=this.scene,s=t.viewer.cameraControl,r=i.canvas.canvas;i.input;var n,o,a=!1,l=$.vec3(),u=$.vec2(),A=null;this._mouseState=0;var c=function e(t){return t.offsetTop+(t.offsetParent&&t.offsetParent!==r.parentNode&&e(t.offsetParent))},h=function e(t){return t.offsetLeft+(t.offsetParent&&t.offsetParent!==r.parentNode&&e(t.offsetParent))},d=$.vec2();this._onCameraControlHoverSnapOrSurface=s.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(function(t){var i=t.snappedCanvasPos||t.canvasPos;a=!0,l.set(t.worldPos),u.set(t.canvasPos),0===e._mouseState?(e._canvasToPagePos?(e._canvasToPagePos(r,i,d),e._markerDiv.style.left="".concat(d[0]-5,"px"),e._markerDiv.style.top="".concat(d[1]-5,"px")):(e._markerDiv.style.left="".concat(h(r)+i[0]-5,"px"),e._markerDiv.style.top="".concat(c(r)+i[1]-5,"px")),e._markerDiv.style.background="pink",t.snappedToVertex||t.snappedToEdge?(e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.snappedCanvasPos||t.canvasPos,e.pointerLens.snapped=!0),e._markerDiv.style.background="greenyellow",e._markerDiv.style.border="2px solid green"):(e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.canvasPos,e.pointerLens.snapped=!1),e._markerDiv.style.background="pink",e._markerDiv.style.border="2px solid red"),A=t.entity):(e._markerDiv.style.left="-10000px",e._markerDiv.style.top="-10000px"),r.style.cursor="pointer",e._currentDistanceMeasurement&&(e._currentDistanceMeasurement.wireVisible=e._currentDistanceMeasurementInitState.wireVisible,e._currentDistanceMeasurement.axisVisible=e._currentDistanceMeasurementInitState.axisVisible&&e.distanceMeasurementsPlugin.defaultAxisVisible,e._currentDistanceMeasurement.xAxisVisible=e._currentDistanceMeasurementInitState.xAxisVisible&&e.distanceMeasurementsPlugin.defaultXAxisVisible,e._currentDistanceMeasurement.yAxisVisible=e._currentDistanceMeasurementInitState.yAxisVisible&&e.distanceMeasurementsPlugin.defaultYAxisVisible,e._currentDistanceMeasurement.zAxisVisible=e._currentDistanceMeasurementInitState.zAxisVisible&&e.distanceMeasurementsPlugin.defaultZAxisVisible,e._currentDistanceMeasurement.targetVisible=e._currentDistanceMeasurementInitState.targetVisible,e._currentDistanceMeasurement.target.worldPos=l.slice(),e._markerDiv.style.left="-10000px",e._markerDiv.style.top="-10000px")})),r.addEventListener("mousedown",this._onMouseDown=function(e){1===e.which&&(n=e.clientX,o=e.clientY)}),r.addEventListener("mouseup",this._onMouseUp=function(i){1===i.which&&(i.clientX>n+20||i.clientXo+20||i.clientY1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"DistanceMeasurements",e))._pointerLens=r.pointerLens,s._container=r.container||document.body,s._defaultControl=null,s._measurements={},s.labelMinAxisLength=r.labelMinAxisLength,s.defaultVisible=!1!==r.defaultVisible,s.defaultOriginVisible=!1!==r.defaultOriginVisible,s.defaultTargetVisible=!1!==r.defaultTargetVisible,s.defaultWireVisible=!1!==r.defaultWireVisible,s.defaultLabelsVisible=!1!==r.defaultLabelsVisible,s.defaultAxisVisible=!1!==r.defaultAxisVisible,s.defaultXAxisVisible=!1!==r.defaultXAxisVisible,s.defaultYAxisVisible=!1!==r.defaultYAxisVisible,s.defaultZAxisVisible=!1!==r.defaultZAxisVisible,s.defaultColor=void 0!==r.defaultColor?r.defaultColor:"#00BBFF",s.zIndex=r.zIndex||1e4,s.defaultLabelsOnWires=!1!==r.defaultLabelsOnWires,s._onMouseOver=function(e,t){s.fire("mouseOver",{plugin:b(s),distanceMeasurement:t,measurement:t,event:e})},s._onMouseLeave=function(e,t){s.fire("mouseLeave",{plugin:b(s),distanceMeasurement:t,measurement:t,event:e})},s._onContextMenu=function(e,t){s.fire("contextMenu",{plugin:b(s),distanceMeasurement:t,measurement:t,event:e})},s}return C(i,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){}},{key:"pointerLens",get:function(){return this._pointerLens}},{key:"control",get:function(){return this._defaultControl||(this._defaultControl=new Fh(this,{})),this._defaultControl}},{key:"measurements",get:function(){return this._measurements}},{key:"labelMinAxisLength",get:function(){return this._labelMinAxisLength},set:function(e){e<1&&(this.error("labelMinAxisLength must be >= 1; defaulting to 25"),e=25),this._labelMinAxisLength=e||25}},{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 i=t.origin,s=t.target,r=new Ch(this,{id:t.id,plugin:this,container:this._container,origin:{entity:i.entity,worldPos:i.worldPos},target:{entity:s.entity,worldPos:s.worldPos},visible:t.visible,wireVisible:t.wireVisible,axisVisible:!1!==t.axisVisible&&!1!==this.defaultAxisVisible,xAxisVisible:!1!==t.xAxisVisible&&!1!==this.defaultXAxisVisible,yAxisVisible:!1!==t.yAxisVisible&&!1!==this.defaultYAxisVisible,zAxisVisible:!1!==t.zAxisVisible&&!1!==this.defaultZAxisVisible,labelsVisible:!1!==t.labelsVisible&&!1!==this.defaultLabelsVisible,originVisible:t.originVisible,targetVisible:t.targetVisible,color:t.color,labelsOnWires:!1!==t.labelsOnWires&&!1!==this.defaultLabelsOnWires,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[r.id]=r,r.on("destroyed",(function(){delete e._measurements[r.id]})),this.fire("measurementCreated",r),r}},{key:"destroyMeasurement",value:function(e){var t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("DistanceMeasurement not found: "+e)}},{key:"setLabelsShown",value:function(e){for(var t=0,i=Object.entries(this.measurements);t1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e.viewer.scene)).pointerLens=r.pointerLens,s.pointerCircle=new De(e.viewer),s._active=!1;var n=document.createElement("div"),o=s.scene.canvas.canvas;return o.parentNode.insertBefore(n,o),n.style.background="black",n.style.border="2px solid blue",n.style.borderRadius="10px",n.style.width="5px",n.style.height="5px",n.style.margin="-200px -200px",n.style.zIndex="100",n.style.position="absolute",n.style.pointerEvents="none",s.markerDiv=n,s._currentDistanceMeasurement=null,s._currentDistanceMeasurementInitState={wireVisible:null,axisVisible:null,xAxisVisible:null,yaxisVisible:null,zAxisVisible:null,targetVisible:null},s._onCanvasTouchStart=null,s._onCanvasTouchEnd=null,s._longTouchTimeoutMs=300,s._snapping=!1!==r.snapping,s._touchState=0,s._attachPlugin(e,r),s}return C(i,[{key:"_attachPlugin",value:function(e){this.distanceMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){var t=this.plugin,i=this.scene,s=i.canvas.canvas;t.pointerLens;var r=$.vec3(),n=20,o=null;this._touchState=0;var a=$.vec2(),l=$.vec2(),u=$.vec2(),A=null,c=function(){e.plugin.viewer.cameraControl.active=!1},h=function(){e.plugin.viewer.cameraControl.active=!0};s.addEventListener("touchstart",this._onCanvasTouchStart=function(s){var u=s.touches.length;if(1===u){var d=s.touches[0],p=d.clientX,f=d.clientY;switch(a.set([p,f]),l.set([p,f]),e._touchState){case 0:if(1!==u&&null!==o)return o&&(clearTimeout(o),o=null),e._currentDistanceMeasurement&&(e._currentDistanceMeasurement.destroy(),e._currentDistanceMeasurement=null),h(),void(e._touchState=0);var v=i.pick({canvasPos:l,snapping:e._snapping,snapToEdge:e._snapping});if(v&&v.snapped)r.set(v.worldPos),e.pointerCircle.start(v.snappedCanvasPos);else{var g=i.pick({canvasPos:l,pickSurface:!0});if(!g||!g.worldPos)return;r.set(g.worldPos),e.pointerCircle.start(g.canvasPos)}o=setTimeout((function(){1!==u||l[0]>a[0]+n||l[0]a[1]+n||l[1]a[0]+n||l[0]a[1]+n||l[1]a[0]+n||da[1]+n||pa[0]+n||da[1]+n||p1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,"FastNav",e))._hideColorTexture=!1!==r.hideColorTexture,s._hidePBR=!1!==r.hidePBR,s._hideSAO=!1!==r.hideSAO,s._hideEdges=!1!==r.hideEdges,s._hideTransparentObjects=!!r.hideTransparentObjects,s._scaleCanvasResolution=!!r.scaleCanvasResolution,s._defaultScaleCanvasResolutionFactor=r.defaultScaleCanvasResolutionFactor||1,s._scaleCanvasResolutionFactor=r.scaleCanvasResolutionFactor||.6,s._delayBeforeRestore=!1!==r.delayBeforeRestore,s._delayBeforeRestoreSeconds=r.delayBeforeRestoreSeconds||.5;var n=1e3*s._delayBeforeRestoreSeconds,o=!1,a=function(){n=1e3*s._delayBeforeRestoreSeconds,o||(e.scene._renderer.setColorTextureEnabled(!s._hideColorTexture),e.scene._renderer.setPBREnabled(!s._hidePBR),e.scene._renderer.setSAOEnabled(!s._hideSAO),e.scene._renderer.setTransparentEnabled(!s._hideTransparentObjects),e.scene._renderer.setEdgesEnabled(!s._hideEdges),s._scaleCanvasResolution?e.scene.canvas.resolutionScale=s._scaleCanvasResolutionFactor:e.scene.canvas.resolutionScale=s._defaultScaleCanvasResolutionFactor,o=!0)},l=function(){e.scene.canvas.resolutionScale=s._defaultScaleCanvasResolutionFactor,e.scene._renderer.setEdgesEnabled(!0),e.scene._renderer.setColorTextureEnabled(!0),e.scene._renderer.setPBREnabled(!0),e.scene._renderer.setSAOEnabled(!0),e.scene._renderer.setTransparentEnabled(!0),o=!1};s._onCanvasBoundary=e.scene.canvas.on("boundary",a),s._onCameraMatrix=e.scene.camera.on("matrix",a),s._onSceneTick=e.scene.on("tick",(function(e){o&&(n-=e.deltaTime,(!s._delayBeforeRestore||n<=0)&&l())}));var u=!1;return s._onSceneMouseDown=e.scene.input.on("mousedown",(function(){u=!0})),s._onSceneMouseUp=e.scene.input.on("mouseup",(function(){u=!1})),s._onSceneMouseMove=e.scene.input.on("mousemove",(function(){u&&a()})),s}return C(i,[{key:"hideColorTexture",get:function(){return this._hideColorTexture},set:function(e){this._hideColorTexture=e}},{key:"hidePBR",get:function(){return this._hidePBR},set:function(e){this._hidePBR=e}},{key:"hideSAO",get:function(){return this._hideSAO},set:function(e){this._hideSAO=e}},{key:"hideEdges",get:function(){return this._hideEdges},set:function(e){this._hideEdges=e}},{key:"hideTransparentObjects",get:function(){return this._hideTransparentObjects},set:function(e){this._hideTransparentObjects=!1!==e}},{key:"scaleCanvasResolution",get:function(){return this._scaleCanvasResolution},set:function(e){this._scaleCanvasResolution=e}},{key:"defaultScaleCanvasResolutionFactor",get:function(){return this._defaultScaleCanvasResolutionFactor},set:function(e){this._defaultScaleCanvasResolutionFactor=e||1}},{key:"scaleCanvasResolutionFactor",get:function(){return this._scaleCanvasResolutionFactor},set:function(e){this._scaleCanvasResolutionFactor=e||.6}},{key:"delayBeforeRestore",get:function(){return this._delayBeforeRestore},set:function(e){this._delayBeforeRestore=e}},{key:"delayBeforeRestoreSeconds",get:function(){return this._delayBeforeRestoreSeconds},set:function(e){this._delayBeforeRestoreSeconds=null!=e?e:.5}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.scene.camera.off(this._onCameraMatrix),this.viewer.scene.canvas.off(this._onCanvasBoundary),this.viewer.scene.input.off(this._onSceneMouseDown),this.viewer.scene.input.off(this._onSceneMouseUp),this.viewer.scene.input.off(this._onSceneMouseMove),this.viewer.scene.off(this._onSceneTick),f(B(i.prototype),"destroy",this).call(this)}}]),i}(),Dh=function(){function e(){x(this,e)}return C(e,[{key:"getMetaModel",value:function(e,t,i){le.loadJSON(e,(function(e){t(e)}),(function(e){i(e)}))}},{key:"getGLTF",value:function(e,t,i){le.loadArraybuffer(e,(function(e){t(e)}),(function(e){i(e)}))}},{key:"getGLB",value:function(e,t,i){le.loadArraybuffer(e,(function(e){t(e)}),(function(e){i(e)}))}},{key:"getArrayBuffer",value:function(e,t,i,s){!function(e,t,i,s){var r=function(){};i=i||r,s=s||r;var n=/^data:(.*?)(;base64)?,(.*)$/,o=t.match(n);if(o){var a=!!o[2],l=o[3];l=window.decodeURIComponent(l),a&&(l=window.atob(l));try{for(var u=new ArrayBuffer(l.length),A=new Uint8Array(u),c=0;c0&&void 0!==arguments[0]?arguments[0]:{};x(this,e),this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=t.messages,this.locale=t.locale}return C(e,[{key:"messages",set:function(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}},{key:"loadMessages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var t in e)this._messages[t]=e[t];this.messages=this._messages}},{key:"clearMessages",value:function(){this.messages={}}},{key:"locales",get:function(){return this._locales}},{key:"locale",get:function(){return this._locale},set:function(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}},{key:"translate",value:function(e,t){var i=this._messages[this._locale];if(!i)return null;var s=Th(e,i);return s?t?Rh(s,t):s:null}},{key:"translatePlurals",value:function(e,t,i){var s=this._messages[this._locale];if(!s)return null;var r=Th(e,s);return(r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one)?(r=Rh(r,[t]),i&&(r=Rh(r,i)),r):null}},{key:"fire",value:function(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);var s=this._eventSubs[e];if(s)for(var r in s){if(s.hasOwnProperty(r))s[r].callback(t)}}},{key:"on",value:function(e,t){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new Q),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});var i=this._eventSubs[e];i||(i={},this._eventSubs[e]=i);var s=this._eventSubIDMap.addItem();i[s]={callback:t},this._eventSubEvents[s]=e;var r=this._events[e];return void 0!==r&&t(r),s}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function Th(e,t){if(t[e])return t[e];for(var i=e.split("."),s=t,r=0,n=i.length;s&&r1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,i){return"{{"===e?"{":"}}"===e?"}":t[i]}))}var Lh=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).t=r.t,s}return C(i,[{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"tangent",get:function(){return this.getTangent(this._t)}},{key:"length",get:function(){var e=this._getLengths();return e[e.length-1]}},{key:"getTangent",value:function(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,s=e+t;i<0&&(i=0),s>1&&(s=1);var r=this.getPoint(i),n=this.getPoint(s),o=$.subVec3(n,r,[]);return $.normalizeVec3(o,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}},{key:"_getLengths",value:function(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,s=[],r=this.getPoint(0),n=0;for(s.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),n+=$.lenVec3($.subVec3(t,r,[])),s.push(n),r=t;return this.cacheArcLengths=s,s}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var i,s=this._getLengths(),r=0,n=s.length;i=t||e*s[n-1];for(var o,a=0,l=n-1;a<=l;)if((o=s[r=Math.floor(a+(l-a)/2)]-i)<0)a=r+1;else{if(!(o>0)){l=r;break}l=r-1}if(s[r=l]===i)return r/(n-1);var u=s[r];return(r+(i-u)/(s[r+1]-u))/(n-1)}}]),i}(),Uh=function(e){g(i,Lh);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).points=r.points,s.t=r.t,s}return C(i,[{key:"points",get:function(){return this._points},set:function(e){this._points=e||[]}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,s=Math.floor(i),r=i-s,n=t[0===s?s:s-1],o=t[s],a=t[s>t.length-2?t.length-1:s+1],l=t[s>t.length-3?t.length-1:s+2],u=$.vec3();return u[0]=$.catmullRomInterpolate(n[0],o[0],a[0],l[0],r),u[1]=$.catmullRomInterpolate(n[1],o[1],a[1],l[1],r),u[2]=$.catmullRomInterpolate(n[2],o[2],a[2],l[2],r),u}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}},{key:"getJSON",value:function(){return{points:points,t:this._t}}}]),i}(),Oh=$.vec3(),Nh=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._frames=[],s._eyeCurve=new Uh(b(s)),s._lookCurve=new Uh(b(s)),s._upCurve=new Uh(b(s)),r.frames&&(s.addFrames(r.frames),s.smoothFrameTimes(1)),s}return C(i,[{key:"type",get:function(){return"CameraPath"}},{key:"frames",get:function(){return this._frames}},{key:"eyeCurve",get:function(){return this._eyeCurve}},{key:"lookCurve",get:function(){return this._lookCurve}},{key:"upCurve",get:function(){return this._upCurve}},{key:"saveFrame",value:function(e){var t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}},{key:"addFrame",value:function(e,t,i,s){var r={t:e,eye:t.slice(0),look:i.slice(0),up:s.slice(0)};this._frames.push(r),this._eyeCurve.points.push(r.eye),this._lookCurve.points.push(r.look),this._upCurve.points.push(r.up)}},{key:"addFrames",value:function(e){for(var t,i=0,s=e.length;i1?1:e,t.eye=this._eyeCurve.getPoint(e,Oh),t.look=this._lookCurve.getPoint(e,Oh),t.up=this._upCurve.getPoint(e,Oh)}},{key:"sampleFrame",value:function(e,t,i,s){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,i),this._upCurve.getPoint(e,s)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=$.vec3(),i=0;this._frames[0].t=0;for(var s=[],r=1,n=this._frames.length;r1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._look1=$.vec3(),s._eye1=$.vec3(),s._up1=$.vec3(),s._look2=$.vec3(),s._eye2=$.vec3(),s._up2=$.vec3(),s._orthoScale1=1,s._orthoScale2=1,s._flying=!1,s._flyEyeLookUp=!1,s._flyingEye=!1,s._flyingLook=!1,s._callback=null,s._callbackScope=null,s._time1=null,s._time2=null,s.easing=!1!==r.easing,s.duration=r.duration,s.fit=r.fit,s.fitFOV=r.fitFOV,s.trail=r.trail,s}return C(i,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,i){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=i;var s,r,n,o,a,l=this.scene.camera,u=!!e.projection&&e.projection!==l.projection;if(this._eye1[0]=l.eye[0],this._eye1[1]=l.eye[1],this._eye1[2]=l.eye[2],this._look1[0]=l.look[0],this._look1[1]=l.look[1],this._look1[2]=l.look[2],this._up1[0]=l.up[0],this._up1[1]=l.up[1],this._up1[2]=l.up[2],this._orthoScale1=l.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)s=e.aabb;else if(6===e.length)s=e;else if(e.eye&&e.look||e.up)r=e.eye,n=e.look,o=e.up;else if(e.eye)r=e.eye;else if(e.look)n=e.look;else{var A=e;if((le.isNumeric(A)||le.isString(A))&&(a=A,!(A=this.scene.components[a])))return this.error("Component not found: "+le.inQuotes(a)),void(t&&(i?t.call(i):t()));u||(s=A.aabb||this.scene.aabb)}var c=e.poi;if(s){if(s[3]=1;e>1&&(e=1);var s=this.easing?i._ease(e,0,1,1):e,r=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?($.subVec3(r.eye,r.look,Gh),r.eye=$.lerpVec3(s,0,1,this._eye1,this._eye2,Hh),r.look=$.subVec3(Hh,Gh,Vh)):this._flyingLook&&(r.look=$.lerpVec3(s,0,1,this._look1,this._look2,Vh),r.up=$.lerpVec3(s,0,1,this._up1,this._up2,jh)):this._flyingEyeLookUp&&(r.eye=$.lerpVec3(s,0,1,this._eye1,this._eye2,Hh),r.look=$.lerpVec3(s,0,1,this._look1,this._look2,Vh),r.up=$.lerpVec3(s,0,1,this._up1,this._up2,jh)),this._projection2){var n="ortho"===this._projection2?i._easeOutExpo(e,0,1,1):i._easeInCubic(e,0,1,1);r.customProjection.matrix=$.lerpMat4(n,0,1,this._projMatrix1,this._projMatrix2)}else r.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return r.ortho.scale=this._orthoScale2,void this.stop();_e.scheduleTask(this._update,this)}}},{key:"stop",value:function(){if(this._flying){this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);var e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}}},{key:"cancel",value:function(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}},{key:"duration",get:function(){return this._duration/1e3},set:function(e){this._duration=e?1e3*e:500,this.stop()}},{key:"fit",get:function(){return this._fit},set:function(e){this._fit=!1!==e}},{key:"fitFOV",get:function(){return this._fitFOV},set:function(e){this._fitFOV=e||45}},{key:"trail",get:function(){return this._trail},set:function(e){this._trail=!!e}},{key:"destroy",value:function(){this.stop(),f(B(i.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,i,s){return-i*(e/=s)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,i,s){return i*(e/=s)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,i,s){return i*(1-Math.pow(2,-10*e/s))+t}}]),i}(),Wh=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._cameraFlightAnimation=new zh(b(s)),s._t=0,s.state=i.SCRUBBING,s._playingFromT=0,s._playingToT=0,s._playingRate=r.playingRate||1,s._playingDir=1,s._lastTime=null,s.cameraPath=r.cameraPath,s._tick=s.scene.on("tick",s._updateT,b(s)),s}return C(i,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,s,r=performance.now(),n=this._lastTime?.001*(r-this._lastTime):0;if(this._lastTime=r,0!==n)switch(this.state){case i.SCRUBBING:return;case i.PLAYING:if(this._t+=this._playingRate*n,0===(t=this._cameraPath.frames.length)||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=i.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case i.PLAYING_TO:s=this._t+this._playingRate*n*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=i.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,i,s){return-i*(e/=s)*(e-2)+t}},{key:"cameraPath",get:function(){return this._cameraPath},set:function(e){this._cameraPath=e}},{key:"rate",get:function(){return this._playingRate},set:function(e){this._playingRate=e}},{key:"play",value:function(){this._cameraPath&&(this._lastTime=null,this.state=i.PLAYING)}},{key:"playToT",value:function(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=i.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var s=this._cameraPath;if(s){var r=s.frames[e];r?(this.state=i.SCRUBBING,this._cameraFlightAnimation.flyTo(r,t)):this.error("flyToFrame - frame index out of range: "+e)}}},{key:"scrubToT",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=i.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=i.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=i.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),i}();Wh.STOPPED=0,Wh.SCRUBBING=1,Wh.PLAYING=2,Wh.PLAYING_TO=3;var Kh=$.vec3(),Xh=$.vec3();$.vec3();var Jh=$.vec3([0,-1,0]),Yh=$.vec4([0,0,0,1]),Zh=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._src=null,s._image=null,s._pos=$.vec3(),s._origin=$.vec3(),s._rtcPos=$.vec3(),s._dir=$.vec3(),s._size=1,s._imageSize=$.vec2(),s._texture=new Un(b(s)),s._plane=new rn(b(s),{geometry:new Si(b(s),Xn({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Oi(b(s),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:s._texture,emissiveMap:s._texture,backfaces:!0}),clippable:r.clippable}),s._grid=new rn(b(s),{geometry:new Si(b(s),Kn({size:1,divisions:10})),material:new Oi(b(s),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:r.clippable}),s._node=new bn(b(s),{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[s._plane,s._grid]}),s._gridVisible=!1,s.visible=!0,s.gridVisible=r.gridVisible,s.position=r.position,s.rotation=r.rotation,s.dir=r.dir,s.size=r.size,s.collidable=r.collidable,s.clippable=r.clippable,s.pickable=r.pickable,s.opacity=r.opacity,r.image?s.image=r.image:s.src=r.src,s}return C(i,[{key:"visible",get:function(){return this._plane.visible},set:function(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}},{key:"gridVisible",get:function(){return this._gridVisible},set:function(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var i=new Image;i.onload=function(){t._texture.image=i,t._imageSize[0]=i.width,t._imageSize[1]=i.height,t._updatePlaneSizeFromImage()},i.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),Le(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}},{key:"rotation",get:function(){return this._node.rotation},set:function(e){this._node.rotation=e}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"dir",get:function(){return this._dir},set:function(e){if(this._dir.set(e||[0,0,-1]),e){var t=this.scene.center,i=[-this._dir[0],-this._dir[1],-this._dir[2]];$.subVec3(t,this.position,Kh);var s=-$.dotVec3(i,Kh);$.normalizeVec3(i),$.mulVec3Scalar(i,s,Xh),$.vec3PairToQuaternion(Jh,e,Yh),this._node.quaternion=Yh}}},{key:"collidable",get:function(){return this._node.collidable},set:function(e){this._node.collidable=!1!==e}},{key:"clippable",get:function(){return this._node.clippable},set:function(e){this._node.clippable=!1!==e}},{key:"pickable",get:function(){return this._node.pickable},set:function(e){this._node.pickable=!1!==e}},{key:"opacity",get:function(){return this._node.opacity},set:function(e){this._node.opacity=e}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],i=this._imageSize[1];if(t>i){var s=i/t;this._node.scale=[e,1,e*s]}else{var r=t/i;this._node.scale=[e*r,1,e]}}}]),i}(),qh=function(e){g(i,_i);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i);var n=b(s=t.call(this,e,r));s._shadowRenderBuf=null,s._shadowViewMatrix=null,s._shadowProjMatrix=null,s._shadowViewMatrixDirty=!0,s._shadowProjMatrixDirty=!0;var o=s.scene.camera,a=s.scene.canvas;return s._onCameraViewMatrix=o.on("viewMatrix",(function(){s._shadowViewMatrixDirty=!0})),s._onCameraProjMatrix=o.on("projMatrix",(function(){s._shadowProjMatrixDirty=!0})),s._onCanvasBoundary=a.on("boundary",(function(){s._shadowProjMatrixDirty=!0})),s._state=new Zt({type:"point",pos:$.vec3([1,1,1]),color:$.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:r.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(n._shadowViewMatrixDirty){n._shadowViewMatrix||(n._shadowViewMatrix=$.identityMat4());var e=n._state.pos,t=o.look,i=o.up;$.lookAtMat4v(e,t,i,n._shadowViewMatrix),n._shadowViewMatrixDirty=!1}return n._shadowViewMatrix},getShadowProjMatrix:function(){if(n._shadowProjMatrixDirty){n._shadowProjMatrix||(n._shadowProjMatrix=$.identityMat4());var e=n.scene.canvas.canvas;$.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,n._shadowProjMatrix),n._shadowProjMatrixDirty=!1}return n._shadowProjMatrix},getShadowRenderBuf:function(){return n._shadowRenderBuf||(n._shadowRenderBuf=new zt(n.scene.canvas.canvas,n.scene.canvas.gl,{size:[1024,1024]})),n._shadowRenderBuf}}),s.pos=r.pos,s.color=r.color,s.intensity=r.intensity,s.constantAttenuation=r.constantAttenuation,s.linearAttenuation=r.linearAttenuation,s.quadraticAttenuation=r.quadraticAttenuation,s.castsShadow=r.castsShadow,s.scene._lightCreated(b(s)),s}return C(i,[{key:"type",get:function(){return"PointLight"}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.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:"constantAttenuation",get:function(){return this._state.attenuation[0]},set:function(e){this._state.attenuation[0]=e||0,this.glRedraw()}},{key:"linearAttenuation",get:function(){return this._state.attenuation[1]},set:function(e){this._state.attenuation[1]=e||0,this.glRedraw()}},{key:"quadraticAttenuation",get:function(){return this._state.attenuation[2]},set:function(e){this._state.attenuation[2]=e||0,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),f(B(i.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),i}();function $h(e){return 0==(e&e-1)}function ed(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var td=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i);var n=(s=t.call(this,e,r)).scene.canvas.gl;return s._state=new Zt({texture:new In({gl:n,target:n.TEXTURE_CUBE_MAP}),flipY:s._checkFlipY(r.minFilter),encoding:s._checkEncoding(r.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),s._src=r.src,s._images=[],s._loadSrc(r.src),se.memory.textures++,s}return C(i,[{key:"type",get:function(){return"CubeTexture"}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}},{key:"_loadSrc",value:function(e){var t=this,i=this.scene.canvas.gl;this._images=[];for(var s=!1,r=0,n=function(n){var o,a,l=new Image;l.onload=(o=l,a=n,function(){if(!s&&(o=function(e){if(!$h(e.width)||!$h(e.height)){var t=document.createElement("canvas");t.width=ed(e.width),t.height=ed(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(o),t._images[a]=o,6==++r)){var e=t._state.texture;e||(e=new In({gl:i,target:i.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}),l.onerror=function(){s=!0},l.src=e[n]},o=0;o1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).scene._lightsState.addReflectionMap(s._state),s.scene._reflectionMapCreated(b(s)),s}return C(i,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),i}(),sd=function(e){g(i,td);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).scene._lightMapCreated(b(s)),s}return C(i,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),i}(),rd=function(e){g(i,et);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,{entity:r.entity,occludable:r.occludable,worldPos:r.worldPos}))._occluded=!1,s._visible=!0,s._src=null,s._image=null,s._pos=$.vec3(),s._origin=$.vec3(),s._rtcPos=$.vec3(),s._dir=$.vec3(),s._size=1,s._imageSize=$.vec2(),s._texture=new Un(b(s),{src:r.src}),s._geometry=new Si(b(s),{primitive:"triangles",positions:[3,3,0,-3,3,0,-3,-3,0,3,-3,0],normals:[-1,0,0,-1,0,0,-1,0,0,-1,0,0],uv:[1,-1,0,-1,0,0,1,0],indices:[0,1,2,0,2,3]}),s._mesh=new rn(b(s),{geometry:s._geometry,material:new Oi(b(s),{ambient:[.9,.3,.9],shininess:30,diffuseMap:s._texture,backfaces:!0}),scale:[1,1,1],position:r.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),s.visible=!0,s.collidable=r.collidable,s.clippable=r.clippable,s.pickable=r.pickable,s.opacity=r.opacity,s.size=r.size,r.image?s.image=r.image:s.src=r.src,s}return C(i,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,f(B(i.prototype),"_setVisible",this).call(this,e)}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var i=new Image;i.onload=function(){t._texture.image=i,t._imageSize[0]=i.width,t._imageSize[1]=i.height,t._updatePlaneSizeFromImage()},i.src=this._src}}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"collidable",get:function(){return this._mesh.collidable},set:function(e){this._mesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._mesh.clippable},set:function(e){this._mesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._mesh.pickable},set:function(e){this._mesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._mesh.opacity},set:function(e){this._mesh.opacity=e}},{key:"_updatePlaneSizeFromImage",value:function(){var e=.5*this._size,t=this._imageSize[0],i=this._imageSize[1],s=i/t;this._geometry.positions=t>i?[e,e*s,0,-e,e*s,0,-e,-e*s,0,e,-e*s,0]:[e/s,e,0,-e/s,e,0,-e/s,-e,0,e/s,-e,0]}}]),i}(),nd=function(){function e(t){x(this,e),this._eye=$.vec3(),this._look=$.vec3(),this._up=$.vec3(),this._projection={},t&&this.saveCamera(t)}return C(e,[{key:"saveCamera",value:function(e){var t=e.camera,i=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:i.fov,fovAxis:i.fovAxis,near:i.near,far:i.far};break;case"ortho":this._projection={projection:"ortho",scale:i.scale,near:i.near,far:i.far};break;case"frustum":this._projection={projection:"frustum",left:i.left,right:i.right,top:i.top,bottom:i.bottom,near:i.near,far:i.far};break;case"custom":this._projection={projection:"custom",matrix:i.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var i=e.camera,s=this._projection;function r(){switch(s.type){case"perspective":i.perspective.fov=s.fov,i.perspective.fovAxis=s.fovAxis,i.perspective.near=s.near,i.perspective.far=s.far;break;case"ortho":i.ortho.scale=s.scale,i.ortho.near=s.near,i.ortho.far=s.far;break;case"frustum":i.frustum.left=s.left,i.frustum.right=s.right,i.frustum.top=s.top,i.frustum.bottom=s.bottom,i.frustum.near=s.near,i.frustum.far=s.far;break;case"custom":i.customProjection.matrix=s.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:s.scale,projection:s.projection},(function(){r(),t()})):(i.eye=this._eye,i.look=this._look,i.up=this._up,r(),i.projection=s.projection)}}]),e}(),od=$.vec3(),ad=function(){function e(t){if(x(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,t){var i=t.metaScene.scene;this.saveObjects(i,t)}}return C(e,[{key:"saveObjects",value:function(e,t,i){this.numObjects=0,this._mask=i?le.apply(i,{}):null;for(var s=!i||i.visible,r=!i||i.edges,n=!i||i.xrayed,o=!i||i.highlighted,a=!i||i.selected,l=!i||i.clippable,u=!i||i.pickable,A=!i||i.colorize,c=!i||i.opacity,h=t.metaObjects,d=e.objects,p=0,f=h.length;p1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).v0=r.v0,s.v1=r.v1,s.v2=r.v2,s.v3=r.v3,s.t=r.t,s}return C(i,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||$.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||$.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||$.vec3([0,0,0])}},{key:"v3",get:function(){return this._v3},set:function(e){this.fire("v3",this._v3=e||$.vec3([0,0,0]))}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=$.vec3();return t[0]=$.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=$.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=$.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}]),i}(),cd=function(e){g(i,Lh);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._cachedLengths=[],s._dirty=!0,s._curves=[],s._t=0,s._dirtySubs=[],s._destroyedSubs=[],s.curves=r.curves||[],s.t=r.t,s}return C(i,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,i,s;for(e=e||[],i=0,s=this._curves.length;i1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"length",get:function(){var e=this._getCurveLengths();return e[e.length-1]}},{key:"getPoint",value:function(e){for(var t,i=e*this.length,s=this._getCurveLengths(),r=0;r=i){var n=1-(s[r]-i)/(t=this._curves[r]).length;return t.getPointAt(n)}r++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],i=0,s=this._curves.length;for(e=0;e1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r)).v0=r.v0,s.v1=r.v1,s.v2=r.v2,s.t=r.t,s}return C(i,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||$.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||$.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||$.vec3([0,0,0])}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=$.vec3();return t[0]=$.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=$.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=$.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}]),i}(),dd=function(e){g(i,ch);var t=_(i);function i(e){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),t.call(this,e,s)}return C(i)}(),pd=function(e){g(i,Be);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,e,r))._skyboxMesh=new rn(b(s),{geometry:new Si(b(s),{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],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]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new Oi(b(s),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Un(b(s),{src:r.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:r.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),s.size=r.size,s.active=r.active,s}return C(i,[{key:"size",get:function(){return this._size},set:function(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}},{key:"active",get:function(){return this._skyboxMesh.visible},set:function(e){this._skyboxMesh.visible=e}}]),i}(),fd=function(){function e(){x(this,e)}return C(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),vd=$.vec4(),gd=$.vec4(),md=$.vec3(),_d=$.vec3(),yd=$.vec3(),bd=$.vec4(),Bd=$.vec4(),wd=$.vec4(),xd=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"dollyToCanvasPos",value:function(e,t,i){var s=!1,r=this._scene.camera;if(e){var n=$.subVec3(e,r.eye,md);s=$.lenVec3(n)0&&void 0!==arguments[0]?arguments[0]:{};this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);var t=e.color||[1,0,0];this._pivotSphereMaterial=new Oi(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}},{key:"disablePivotSphere",value:function(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}},{key:"startPivot",value:function(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;var e=this._scene.camera,t=$.lookAtMat4v(e.eye,e.look,e.worldUp);$.transformPoint3(t,this.getPivotPos(),this._cameraOffset);var i=this.getPivotPos();this._cameraOffset[2]+=$.distVec3(e.eye,i),t=$.inverseMat4(t);var s=$.transformVec3(t,this._cameraOffset),r=$.vec3();if($.subVec3(e.eye,i,r),$.addVec3(r,s),e.zUp){var n=r[1];r[1]=r[2],r[2]=n}this._radius=$.lenVec3(r),this._polar=Math.acos(r[1]/this._radius),this._azimuth=Math.atan2(r[0],r[2]),this._pivoting=!0}},{key:"_cameraLookingDownwards",value:function(){var e=this._scene.camera,t=$.normalizeVec3($.subVec3(e.look,e.eye,Pd)),i=$.cross3Vec3(t,e.worldUp,Cd);return $.sqLenVec3(i)<=1e-4}},{key:"getPivoting",value:function(){return this._pivoting}},{key:"setPivotPos",value:function(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}},{key:"setCanvasPivotPos",value:function(e){var t=this._scene.camera,i=Math.abs($.distVec3(this._scene.center,t.eye)),s=t.project.transposedMatrix,r=s.subarray(8,12),n=s.subarray(12),o=[0,0,-1,1],a=$.dotVec4(o,r)/$.dotVec4(o,n),l=Fd;t.project.unproject(e,a,Ed,kd,l);var u=$.normalizeVec3($.subVec3(l,t.eye,Pd)),A=$.addVec3(t.eye,$.mulVec3Scalar(u,i,Cd),Md);this.setPivotPos(A)}},{key:"getPivotPos",value:function(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}},{key:"continuePivot",value:function(e,t){if(this._pivoting&&(0!==e||0!==t)){var i=this._scene.camera,s=-e,r=-t;1===i.worldUp[2]&&(s=-s),this._azimuth+=.01*-s,this._polar+=.01*r,this._polar=$.clamp(this._polar,.001,Math.PI-.001);var n=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===i.worldUp[2]){var o=n[1];n[1]=n[2],n[2]=o}var a=$.lenVec3($.subVec3(i.look,i.eye,$.vec3())),l=this.getPivotPos();$.addVec3(n,l);var u=$.lookAtMat4v(n,l,i.worldUp);u=$.inverseMat4(u);var A=$.transformVec3(u,this._cameraOffset);u[12]-=A[0],u[13]-=A[1],u[14]-=A[2];var c=[u[8],u[9],u[10]];i.eye=[u[12],u[13],u[14]],$.subVec3(i.eye,$.mulVec3Scalar(c,a),i.look),i.up=[u[4],u[5],u[6]],this.showPivot()}}},{key:"showPivot",value:function(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}},{key:"hidePivot",value:function(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}},{key:"endPivot",value:function(){this._pivoting=!1}},{key:"destroy",value:function(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}]),e}(),Dd=function(){function e(t,i){x(this,e),this._scene=t.scene,this._cameraControl=t,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=i,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=$.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}return C(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){var e="".concat(~~this.pickCursorPos[0],"-").concat(~~this.pickCursorPos[1],"-").concat(this.scheduleSnapOrPick,"-").concat(this.schedulePickSurface,"-").concat(this.schedulePickEntity);if(this._lastHash!==e){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;var t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var i=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});i&&(i.snappedToEdge||i.snappedToVertex)?(this.snapPickResult=i,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var s=this.pickResult.canvasPos;if(s[0]===this.pickCursorPos[0]&&s[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){var r=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(r[0]===this.pickCursorPos[0]&&r[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}}}},{key:"fireEvents",value:function(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){var e=new wt;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var t=this.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=t)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}]),e}(),Sd=$.vec2(),Td=function(){function e(t,i,s,r,n){x(this,e),this._scene=t;var o,a,l,u=i.pickController,A=0,c=0,h=0,d=0,p=!1,f=$.vec3(),v=!0,g=this._scene.canvas.canvas,m=[];function _(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];g.style.cursor="move",y(),e&&b()}function y(){A=r.pointerCanvasPos[0],c=r.pointerCanvasPos[1],h=r.pointerCanvasPos[0],d=r.pointerCanvasPos[1]}function b(){u.pickCursorPos=r.pointerCanvasPos,u.schedulePickSurface=!0,u.update(),u.picked&&u.pickedSurface&&u.pickResult&&u.pickResult.worldPos?(p=!0,f.set(u.pickResult.worldPos)):p=!1}document.addEventListener("keydown",this._documentKeyDownHandler=function(e){if(s.active&&s.pointerEnabled&&t.input.keyboardEnabled){var i=e.keyCode;m[i]=!0}}),document.addEventListener("keyup",this._documentKeyUpHandler=function(e){if(s.active&&s.pointerEnabled&&t.input.keyboardEnabled){var i=e.keyCode;m[i]=!1}}),g.addEventListener("mousedown",this._mouseDownHandler=function(e){if(s.active&&s.pointerEnabled)switch(e.which){case 1:m[t.input.KEY_SHIFT]||s.planView?(o=!0,_()):(o=!0,_(!1));break;case 2:a=!0,_();break;case 3:l=!0,s.panRightClick&&_()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=function(e){if(s.active&&s.pointerEnabled&&(o||a||l)){var i=t.canvas.boundary,u=i[2],h=i[3],d=r.pointerCanvasPos[0],v=r.pointerCanvasPos[1],g=m[t.input.KEY_SHIFT]||s.planView||!s.panRightClick&&a||s.panRightClick&&l,_=document.pointerLockElement?e.movementX:d-A,y=document.pointerLockElement?e.movementY:v-c;if(g){var b=t.camera;if("perspective"===b.projection){var B=Math.abs(p?$.lenVec3($.subVec3(f,t.camera.eye,[])):t.camera.eyeLookDist)*Math.tan(b.perspective.fov/2*Math.PI/180);n.panDeltaX+=1.5*_*B/h,n.panDeltaY+=1.5*y*B/h}else n.panDeltaX+=.5*b.ortho.scale*(_/h),n.panDeltaY+=.5*b.ortho.scale*(y/h)}else!o||a||l||s.planView||(s.firstPerson?(n.rotateDeltaY-=_/u*s.dragRotationRate/2,n.rotateDeltaX+=y/h*(s.dragRotationRate/4)):(n.rotateDeltaY-=_/u*(1.5*s.dragRotationRate),n.rotateDeltaX+=y/h*(1.5*s.dragRotationRate)));A=d,c=v}}),g.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){s.active&&s.pointerEnabled&&r.mouseover&&(v=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){if(s.active&&s.pointerEnabled)switch(e.which){case 1:case 2:case 3:o=!1,a=!1,l=!1}}),g.addEventListener("mouseup",this._mouseUpHandler=function(e){if(s.active&&s.pointerEnabled){if(3===e.which){!function(e,t){if(e){for(var i=e.target,s=0,r=0,n=0,o=0;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,n+=i.scrollLeft,o+=i.scrollTop,i=i.offsetParent;t[0]=e.pageX+n-s,t[1]=e.pageY+o-r}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Sd);var t=Sd[0],r=Sd[1];Math.abs(t-h)<3&&Math.abs(r-d)<3&&i.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Sd,event:e},!0)}g.style.removeProperty("cursor")}}),g.addEventListener("mouseenter",this._mouseEnterHandler=function(){s.active&&s.pointerEnabled});var B=1/60,w=null;g.addEventListener("wheel",this._mouseWheelHandler=function(e){if(s.active&&s.pointerEnabled){var t=performance.now()/1e3,i=null!==w?t-w:0;w=t,i>.05&&(i=.05),i0?i.cameraFlight.flyTo(Qd,(function(){i.pivotController.getPivoting()&&s.followPointer&&i.pivotController.showPivot()})):(i.cameraFlight.jumpTo(Qd),i.pivotController.getPivoting()&&s.followPointer&&i.pivotController.showPivot())}}}))}return C(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.input.off(this._onSceneKeyDown)}}]),e}(),Hd=function(){function e(t,i,s,r,n){var o=this;x(this,e),this._scene=t;var a=i.pickController,l=i.pivotController,u=i.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;var A=!1,c=!1,h=this._scene.canvas.canvas,d=function(e){var s;e&&e.worldPos&&(s=e.worldPos);var r=e&&e.entity?e.entity.aabb:t.aabb;if(s){var n=t.camera;$.subVec3(n.eye,n.look,[]),i.cameraFlight.flyTo({aabb:r})}else i.cameraFlight.flyTo({aabb:r})},p=t.tickify(this._canvasMouseMoveHandler=function(e){if(s.active&&s.pointerEnabled&&!A&&!c){var i=u.hasSubs("hover"),n=u.hasSubs("hoverEnter"),l=u.hasSubs("hoverOut"),h=u.hasSubs("hoverOff"),d=u.hasSubs("hoverSurface"),p=u.hasSubs("hoverSnapOrSurface");if(i||n||l||h||d||p)if(a.pickCursorPos=r.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=d,a.scheduleSnapOrPick=p,a.update(),a.pickResult){if(a.pickResult.entity){var f=a.pickResult.entity.id;o._lastPickedEntityId!==f&&(void 0!==o._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[o._lastPickedEntityId]},!0),u.fire("hoverEnter",a.pickResult,!0),o._lastPickedEntityId=f)}u.fire("hover",a.pickResult,!0),(a.pickResult.worldPos||a.pickResult.snappedWorldPos)&&u.fire("hoverSurface",a.pickResult,!0)}else void 0!==o._lastPickedEntityId&&(u.fire("hoverOut",{entity:t.objects[o._lastPickedEntityId]},!0),o._lastPickedEntityId=void 0),u.fire("hoverOff",{canvasPos:a.pickCursorPos},!0)}});h.addEventListener("mousemove",p),h.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(A=!0),3===e.which&&(c=!0),1===e.which&&s.active&&s.pointerEnabled&&(r.mouseDownClientX=e.clientX,r.mouseDownClientY=e.clientY,r.mouseDownCursorX=r.pointerCanvasPos[0],r.mouseDownCursorY=r.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(a.pickCursorPos=r.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),1===e.which))){var i=a.pickResult;i&&i.worldPos?(l.setPivotPos(i.worldPos),l.startPivot()):(s.smartPivot?l.setCanvasPivotPos(r.pointerCanvasPos):l.setPivotPos(t.camera.look),l.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(A=!1),3===e.which&&(c=!1),l.getPivoting()&&l.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(s.active&&s.pointerEnabled&&(1===e.which&&(l.hidePivot(),!(Math.abs(e.clientX-r.mouseDownClientX)>3||Math.abs(e.clientY-r.mouseDownClientY)>3)))){var n=u.hasSubs("picked"),A=u.hasSubs("pickedNothing"),c=u.hasSubs("pickedSurface"),h=u.hasSubs("doublePicked"),p=u.hasSubs("doublePickedSurface"),f=u.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||h||p||f))return(n||A||c)&&(a.pickCursorPos=r.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=c,a.update(),a.pickResult?(u.fire("picked",a.pickResult,!0),a.pickedSurface&&u.fire("pickedSurface",a.pickResult,!0)):u.fire("pickedNothing",{canvasPos:r.pointerCanvasPos},!0)),void(o._clicks=0);if(o._clicks++,1===o._clicks){a.pickCursorPos=r.pointerCanvasPos,a.schedulePickEntity=s.doublePickFlyTo,a.schedulePickSurface=c,a.update();var v=a.pickResult,g=a.pickedSurface;o._timeout=setTimeout((function(){v?(u.fire("picked",v,!0),g&&(u.fire("pickedSurface",v,!0),!s.firstPerson&&s.followPointer&&(i.pivotController.setPivotPos(v.worldPos),i.pivotController.startPivot()&&i.pivotController.showPivot()))):u.fire("pickedNothing",{canvasPos:r.pointerCanvasPos},!0),o._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==o._timeout&&(window.clearTimeout(o._timeout),o._timeout=null),a.pickCursorPos=r.pointerCanvasPos,a.schedulePickEntity=s.doublePickFlyTo||h||p,a.schedulePickSurface=a.schedulePickEntity&&p,a.update(),a.pickResult){if(u.fire("doublePicked",a.pickResult,!0),a.pickedSurface&&u.fire("doublePickedSurface",a.pickResult,!0),s.doublePickFlyTo&&(d(a.pickResult),!s.firstPerson&&s.followPointer)){var m=a.pickResult.entity.aabb,_=$.getAABB3Center(m);i.pivotController.setPivotPos(_),i.pivotController.startPivot()&&i.pivotController.showPivot()}}else if(u.fire("doublePickedNothing",{canvasPos:r.pointerCanvasPos},!0),s.doublePickFlyTo&&(d(),!s.firstPerson&&s.followPointer)){var y=t.aabb,b=$.getAABB3Center(y);i.pivotController.setPivotPos(b),i.pivotController.startPivot()&&i.pivotController.showPivot()}o._clicks=0}}},!1)}return C(e,[{key:"reset",value:function(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}]),e}(),jd=function(){function e(t,i,s,r,n){x(this,e),this._scene=t;var o=t.input,a=[],l=t.canvas.canvas,u=!0;this._onSceneMouseMove=o.on("mousemove",(function(){u=!0})),this._onSceneKeyDown=o.on("keydown",(function(e){s.active&&s.pointerEnabled&&t.input.keyboardEnabled&&r.mouseover&&(a[e]=!0,e===o.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=o.on("keyup",(function(e){s.active&&s.pointerEnabled&&t.input.keyboardEnabled&&(a[e]=!1,e===o.KEY_SHIFT&&(l.style.cursor=null),i.pivotController.getPivoting()&&i.pivotController.endPivot())})),this._onTick=t.on("tick",(function(e){if(s.active&&s.pointerEnabled&&t.input.keyboardEnabled&&r.mouseover){var l=i.cameraControl,A=e.deltaTime/1e3;if(!s.planView){var c=l._isKeyDownForAction(l.ROTATE_Y_POS,a),h=l._isKeyDownForAction(l.ROTATE_Y_NEG,a),d=l._isKeyDownForAction(l.ROTATE_X_POS,a),p=l._isKeyDownForAction(l.ROTATE_X_NEG,a),f=A*s.keyboardRotationRate;(c||h||d||p)&&(!s.firstPerson&&s.followPointer&&i.pivotController.startPivot(),c?n.rotateDeltaY+=f:h&&(n.rotateDeltaY-=f),d?n.rotateDeltaX+=f:p&&(n.rotateDeltaX-=f),!s.firstPerson&&s.followPointer&&i.pivotController.startPivot())}if(!a[o.KEY_CTRL]&&!a[o.KEY_ALT]){var v=l._isKeyDownForAction(l.DOLLY_BACKWARDS,a),g=l._isKeyDownForAction(l.DOLLY_FORWARDS,a);if(v||g){var m=A*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&i.pivotController.startPivot(),g?n.dollyDelta-=m:v&&(n.dollyDelta+=m),u&&(r.followPointerDirty=!0,u=!1)}}var _=l._isKeyDownForAction(l.PAN_FORWARDS,a),y=l._isKeyDownForAction(l.PAN_BACKWARDS,a),b=l._isKeyDownForAction(l.PAN_LEFT,a),B=l._isKeyDownForAction(l.PAN_RIGHT,a),w=l._isKeyDownForAction(l.PAN_UP,a),x=l._isKeyDownForAction(l.PAN_DOWN,a),P=(a[o.KEY_ALT]?.3:1)*A*s.keyboardPanRate;(_||y||b||B||w||x)&&(!s.firstPerson&&s.followPointer&&i.pivotController.startPivot(),x?n.panDeltaY+=P:w&&(n.panDeltaY+=-P),B?n.panDeltaX+=-P:b&&(n.panDeltaX+=P),y?n.panDeltaZ+=P:_&&(n.panDeltaZ+=-P))}}))}return C(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}]),e}(),Gd=$.vec3(),zd=function(){function e(t,i,s,r,n){x(this,e),this._scene=t;var o=t.camera,a=i.pickController,l=i.pivotController,u=i.panController,A=1,c=1,h=null;this._onTick=t.on("tick",(function(){if(s.active&&s.pointerEnabled){var e="default";if(Math.abs(n.dollyDelta)<.001&&(n.dollyDelta=0),Math.abs(n.rotateDeltaX)<.001&&(n.rotateDeltaX=0),Math.abs(n.rotateDeltaY)<.001&&(n.rotateDeltaY=0),0===n.rotateDeltaX&&0===n.rotateDeltaY||(n.dollyDelta=0),s.followPointer){if(--A<=0&&(A=1,0!==n.dollyDelta)){if(0===n.rotateDeltaY&&0===n.rotateDeltaX&&s.followPointer&&r.followPointerDirty&&(a.pickCursorPos=r.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.pickResult&&a.pickResult.worldPos?h=a.pickResult.worldPos:(c=1,h=null),r.followPointerDirty=!1),h){var i=Math.abs($.lenVec3($.subVec3(h,t.camera.eye,Gd)));c=i/s.dollyProximityThreshold}cs.longTapRadius||Math.abs(g)>s.longTapRadius)&&(clearTimeout(r.longTouchTimeout),r.longTouchTimeout=null),s.planView){var m=t.camera;if("perspective"===m.projection){var _=Math.abs(t.camera.eyeLookDist)*Math.tan(m.perspective.fov/2*Math.PI/180);n.panDeltaX+=v*_/l*s.touchPanRate,n.panDeltaY+=g*_/l*s.touchPanRate}else n.panDeltaX+=.5*m.ortho.scale*(v/l)*s.touchPanRate,n.panDeltaY+=.5*m.ortho.scale*(g/l)*s.touchPanRate}else n.rotateDeltaY-=v/a*(1*s.dragRotationRate),n.rotateDeltaX+=g/l*(1.5*s.dragRotationRate)}else if(2===p){var y=d[0],b=d[1];Xd(y,u),Xd(b,A);var B=$.geometricMeanVec2(h[0],h[1]),w=$.geometricMeanVec2(u,A),x=$.vec2();$.subVec2(B,w,x);var P=x[0],C=x[1],M=t.camera,F=$.distVec2([y.pageX,y.pageY],[b.pageX,b.pageY]),E=($.distVec2(h[0],h[1])-F)*s.touchDollyRate;if(n.dollyDelta=E,Math.abs(E)<1)if("perspective"===M.projection){var k=o.pickResult?o.pickResult.worldPos:t.center,I=Math.abs($.lenVec3($.subVec3(k,t.camera.eye,[])))*Math.tan(M.perspective.fov/2*Math.PI/180);n.panDeltaX-=P*I/l*s.touchPanRate,n.panDeltaY-=C*I/l*s.touchPanRate}else n.panDeltaX-=.5*M.ortho.scale*(P/l)*s.touchPanRate,n.panDeltaY-=.5*M.ortho.scale*(C/l)*s.touchPanRate;r.pointerCanvasPos=w}for(var D=0;D-1&&t-c<150&&(h>-1&&c-h<325?(Yd(n[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=o,a.update(),a.pickResult?(a.pickResult.touchInput=!0,l.fire("doublePicked",a.pickResult),a.pickedSurface&&l.fire("doublePickedSurface",a.pickResult),s.doublePickFlyTo&&p(a.pickResult)):(l.fire("doublePickedNothing"),s.doublePickFlyTo&&p()),h=-1):$.distVec2(u[0],A)<4&&(Yd(n[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=o,a.update(),a.pickResult?(a.pickResult.touchInput=!0,l.fire("picked",a.pickResult),a.pickedSurface&&l.fire("pickedSurface",a.pickResult)):l.fire("pickedNothing"),h=t),c=-1),u.length=i.length;for(var d=0,f=i.length;d1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,e,r)).PAN_LEFT=0,s.PAN_RIGHT=1,s.PAN_UP=2,s.PAN_DOWN=3,s.PAN_FORWARDS=4,s.PAN_BACKWARDS=5,s.ROTATE_X_POS=6,s.ROTATE_X_NEG=7,s.ROTATE_Y_POS=8,s.ROTATE_Y_NEG=9,s.DOLLY_FORWARDS=10,s.DOLLY_BACKWARDS=11,s.AXIS_VIEW_RIGHT=12,s.AXIS_VIEW_BACK=13,s.AXIS_VIEW_LEFT=14,s.AXIS_VIEW_FRONT=15,s.AXIS_VIEW_TOP=16,s.AXIS_VIEW_BOTTOM=17,s._keyMap={},s.scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},s._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},s._states={pointerCanvasPos:$.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:$.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},s._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};var n=s.scene;return s._controllers={cameraControl:b(s),pickController:new Dd(b(s),s._configs),pivotController:new Id(n,s._configs),panController:new xd(n),cameraFlight:new zh(b(s),{duration:.5})},s._handlers=[new Wd(s.scene,s._controllers,s._configs,s._states,s._updates),new Jd(s.scene,s._controllers,s._configs,s._states,s._updates),new Td(s.scene,s._controllers,s._configs,s._states,s._updates),new Vd(s.scene,s._controllers,s._configs,s._states,s._updates),new Hd(s.scene,s._controllers,s._configs,s._states,s._updates),new Zd(s.scene,s._controllers,s._configs,s._states,s._updates),new jd(s.scene,s._controllers,s._configs,s._states,s._updates)],s._cameraUpdater=new zd(s.scene,s._controllers,s._configs,s._states,s._updates),s.navMode=r.navMode,r.planView&&(s.planView=r.planView),s.constrainVertical=r.constrainVertical,r.keyboardLayout?s.keyboardLayout=r.keyboardLayout:s.keyMap=r.keyMap,s.doublePickFlyTo=r.doublePickFlyTo,s.panRightClick=r.panRightClick,s.active=r.active,s.followPointer=r.followPointer,s.rotationInertia=r.rotationInertia,s.keyboardPanRate=r.keyboardPanRate,s.touchPanRate=r.touchPanRate,s.keyboardRotationRate=r.keyboardRotationRate,s.dragRotationRate=r.dragRotationRate,s.touchDollyRate=r.touchDollyRate,s.dollyInertia=r.dollyInertia,s.dollyProximityThreshold=r.dollyProximityThreshold,s.dollyMinSpeed=r.dollyMinSpeed,s.panInertia=r.panInertia,s.pointerEnabled=!0,s.keyboardDollyRate=r.keyboardDollyRate,s.mouseWheelDollyRate=r.mouseWheelDollyRate,s}return C(i,[{key:"keyMap",get:function(){return this._keyMap},set:function(e){if(e=e||"qwerty",le.isString(e)){var t=this.scene.input,i={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":i[this.PAN_LEFT]=[t.KEY_A],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_Z],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":i[this.PAN_LEFT]=[t.KEY_Q],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_W],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=i}else{var s=e;this._keyMap=s}}},{key:"_isKeyDownForAction",value:function(e,t){var i=this._keyMap[e];if(!i)return!1;t||(t=this.scene.input.keyDown);for(var s=0,r=i.length;s0&&void 0!==arguments[0]?arguments[0]:{};this._controllers.pivotController.enablePivotSphere(e)}},{key:"disablePivotSphere",value:function(){this._controllers.pivotController.disablePivotSphere()}},{key:"smartPivot",get:function(){return this._configs.smartPivot},set:function(e){this._configs.smartPivot=!1!==e}},{key:"doubleClickTimeFrame",get:function(){return this._configs.doubleClickTimeFrame},set:function(e){this._configs.doubleClickTimeFrame=null!=e?e:250}},{key:"destroy",value:function(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),f(B(i.prototype),"destroy",this).call(this)}},{key:"_destroyHandlers",value:function(){for(var e=0,t=this._handlers.length;e1&&void 0!==arguments[1]?arguments[1]:{};if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);var i=this.metaScene,s=e.properties;if(e.propertySets)for(var r=0,n=e.propertySets.length;r0?rp(t):null,o=i&&i.length>0?rp(i):null;return function e(t){if(t){var i=!0;(o&&o[t.type]||n&&!n[t.type])&&(i=!1),i&&s.push(t.id);var r=t.children;if(r)for(var a=0,l=r.length;a * Copyright (c) 2022 Niklas von Hertzen @@ -33,4 +33,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -***************************************************************************** */var np=function(e,t){return np=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},np(e,t)};function op(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function i(){this.constructor=e}np(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}var ap=function(){return ap=Object.assign||function(e){for(var t,i=1,s=arguments.length;i0&&r[r.length-1])||6!==n[0]&&2!==n[0])){o=0;continue}if(3===n[0]&&(!r||n[1]>r[0]&&n[1]=55296&&r<=56319&&i>10),o%1024+56320)),(r+1===i||s.length>16384)&&(n+=String.fromCharCode.apply(String,s),s.length=0)}return n},fp="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",vp="undefined"==typeof Uint8Array?[]:new Uint8Array(256),gp=0;gp=0){if(e<55296||e>56319&&e<=65535)return t=((t=this.index[e>>5])<<2)+(31&e),this.data[t];if(e<=65535)return t=((t=this.index[2048+(e-55296>>5)])<<2)+(31&e),this.data[t];if(e>11),t=this.index[t],t+=e>>5&63,t=((t=this.index[t])<<2)+(31&e),this.data[t];if(e<=1114111)return this.data[this.highValueIndex]}return this.errorValue},e}(),Bp="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",xp="undefined"==typeof Uint8Array?[]:new Uint8Array(256),Pp=0;Pp>4,A[l++]=(15&s)<<4|r>>2,A[l++]=(3&r)<<6|63&n;return u}(e),o=Array.isArray(n)?function(e){for(var t=e.length,i=[],s=0;s0;){var o=s[--n];if(Array.isArray(e)?-1!==e.indexOf(o):e===o)for(var a=i;a<=s.length;){var l;if((l=s[++a])===t)return!0;if(l!==Cp)break}if(o!==Cp)break}return!1},af=function(e,t){for(var i=e;i>=0;){var s=t[i];if(s!==Cp)return s;i--}return 0},lf=function(e,t,i,s,r){if(0===i[s])return"×";var n=s-1;if(Array.isArray(r)&&!0===r[n])return"×";var o=n-1,a=n+1,l=t[n],u=o>=0?t[o]:0,A=t[a];if(2===l&&3===A)return"×";if(-1!==$p.indexOf(l))return"!";if(-1!==$p.indexOf(A))return"×";if(-1!==ef.indexOf(A))return"×";if(8===af(n,t))return"÷";if(11===Zp.get(e[n]))return"×";if((l===Vp||l===Hp)&&11===Zp.get(e[a]))return"×";if(7===l||7===A)return"×";if(9===l)return"×";if(-1===[Cp,Mp,Fp].indexOf(l)&&9===A)return"×";if(-1!==[Ep,kp,Ip,Rp,Np].indexOf(A))return"×";if(af(n,t)===Tp)return"×";if(of(23,Tp,n,t))return"×";if(of([Ep,kp],Sp,n,t))return"×";if(of(12,12,n,t))return"×";if(l===Cp)return"÷";if(23===l||23===A)return"×";if(16===A||16===l)return"÷";if(-1!==[Mp,Fp,Sp].indexOf(A)||14===l)return"×";if(36===u&&-1!==nf.indexOf(l))return"×";if(l===Np&&36===A)return"×";if(A===Dp)return"×";if(-1!==qp.indexOf(A)&&l===Lp||-1!==qp.indexOf(l)&&A===Lp)return"×";if(l===Op&&-1!==[zp,Vp,Hp].indexOf(A)||-1!==[zp,Vp,Hp].indexOf(l)&&A===Up)return"×";if(-1!==qp.indexOf(l)&&-1!==tf.indexOf(A)||-1!==tf.indexOf(l)&&-1!==qp.indexOf(A))return"×";if(-1!==[Op,Up].indexOf(l)&&(A===Lp||-1!==[Tp,Fp].indexOf(A)&&t[a+1]===Lp)||-1!==[Tp,Fp].indexOf(l)&&A===Lp||l===Lp&&-1!==[Lp,Np,Rp].indexOf(A))return"×";if(-1!==[Lp,Np,Rp,Ep,kp].indexOf(A))for(var c=n;c>=0;){if((h=t[c])===Lp)return"×";if(-1===[Np,Rp].indexOf(h))break;c--}if(-1!==[Op,Up].indexOf(A))for(c=-1!==[Ep,kp].indexOf(l)?o:n;c>=0;){var h;if((h=t[c])===Lp)return"×";if(-1===[Np,Rp].indexOf(h))break;c--}if(Wp===l&&-1!==[Wp,Kp,jp,Gp].indexOf(A)||-1!==[Kp,jp].indexOf(l)&&-1!==[Kp,Xp].indexOf(A)||-1!==[Xp,Gp].indexOf(l)&&A===Xp)return"×";if(-1!==rf.indexOf(l)&&-1!==[Dp,Up].indexOf(A)||-1!==rf.indexOf(A)&&l===Op)return"×";if(-1!==qp.indexOf(l)&&-1!==qp.indexOf(A))return"×";if(l===Rp&&-1!==qp.indexOf(A))return"×";if(-1!==qp.concat(Lp).indexOf(l)&&A===Tp&&-1===Yp.indexOf(e[a])||-1!==qp.concat(Lp).indexOf(A)&&l===kp)return"×";if(41===l&&41===A){for(var d=i[n],p=1;d>0&&41===t[--d];)p++;if(p%2!=0)return"×"}return l===Vp&&A===Hp?"×":"÷"},uf=function(e,t){t||(t={lineBreak:"normal",wordBreak:"normal"});var i=function(e,t){void 0===t&&(t="strict");var i=[],s=[],r=[];return e.forEach((function(e,n){var o=Zp.get(e);if(o>50?(r.push(!0),o-=50):r.push(!1),-1!==["normal","auto","loose"].indexOf(t)&&-1!==[8208,8211,12316,12448].indexOf(e))return s.push(n),i.push(16);if(4===o||11===o){if(0===n)return s.push(n),i.push(Qp);var a=i[n-1];return-1===sf.indexOf(a)?(s.push(s[n-1]),i.push(a)):(s.push(n),i.push(Qp))}return s.push(n),31===o?i.push("strict"===t?Sp:zp):o===Jp||29===o?i.push(Qp):43===o?e>=131072&&e<=196605||e>=196608&&e<=262141?i.push(zp):i.push(Qp):void i.push(o)})),[s,i,r]}(e,t.lineBreak),s=i[0],r=i[1],n=i[2];"break-all"!==t.wordBreak&&"break-word"!==t.wordBreak||(r=r.map((function(e){return-1!==[Lp,Qp,Jp].indexOf(e)?zp:e})));var o="keep-all"===t.wordBreak?n.map((function(t,i){return t&&e[i]>=19968&&e[i]<=40959})):void 0;return[s,r,o]},Af=function(){function e(e,t,i,s){this.codePoints=e,this.required="!"===t,this.start=i,this.end=s}return e.prototype.slice=function(){return pp.apply(void 0,this.codePoints.slice(this.start,this.end))},e}(),cf=function(e){return e>=48&&e<=57},hf=function(e){return cf(e)||e>=65&&e<=70||e>=97&&e<=102},df=function(e){return 10===e||9===e||32===e},pf=function(e){return function(e){return function(e){return e>=97&&e<=122}(e)||function(e){return e>=65&&e<=90}(e)}(e)||function(e){return e>=128}(e)||95===e},ff=function(e){return pf(e)||cf(e)||45===e},vf=function(e){return e>=0&&e<=8||11===e||e>=14&&e<=31||127===e},gf=function(e,t){return 92===e&&10!==t},mf=function(e,t,i){return 45===e?pf(t)||gf(t,i):!!pf(e)||!(92!==e||!gf(e,t))},_f=function(e,t,i){return 43===e||45===e?!!cf(t)||46===t&&cf(i):cf(46===e?t:e)},yf=function(e){var t=0,i=1;43!==e[t]&&45!==e[t]||(45===e[t]&&(i=-1),t++);for(var s=[];cf(e[t]);)s.push(e[t++]);var r=s.length?parseInt(pp.apply(void 0,s),10):0;46===e[t]&&t++;for(var n=[];cf(e[t]);)n.push(e[t++]);var o=n.length,a=o?parseInt(pp.apply(void 0,n),10):0;69!==e[t]&&101!==e[t]||t++;var l=1;43!==e[t]&&45!==e[t]||(45===e[t]&&(l=-1),t++);for(var u=[];cf(e[t]);)u.push(e[t++]);var A=u.length?parseInt(pp.apply(void 0,u),10):0;return i*(r+a*Math.pow(10,-o))*Math.pow(10,l*A)},bf={type:2},wf={type:3},Bf={type:4},xf={type:13},Pf={type:8},Cf={type:21},Mf={type:9},Ff={type:10},Ef={type:11},kf={type:12},If={type:14},Df={type:23},Sf={type:1},Tf={type:25},Rf={type:24},Lf={type:26},Uf={type:27},Of={type:28},Nf={type:29},Qf={type:31},Vf={type:32},Hf=function(){function e(){this._value=[]}return e.prototype.write=function(e){this._value=this._value.concat(dp(e))},e.prototype.read=function(){for(var e=[],t=this.consumeToken();t!==Vf;)e.push(t),t=this.consumeToken();return e},e.prototype.consumeToken=function(){var e=this.consumeCodePoint();switch(e){case 34:return this.consumeStringToken(34);case 35:var t=this.peekCodePoint(0),i=this.peekCodePoint(1),s=this.peekCodePoint(2);if(ff(t)||gf(i,s)){var r=mf(t,i,s)?2:1;return{type:5,value:this.consumeName(),flags:r}}break;case 36:if(61===this.peekCodePoint(0))return this.consumeCodePoint(),xf;break;case 39:return this.consumeStringToken(39);case 40:return bf;case 41:return wf;case 42:if(61===this.peekCodePoint(0))return this.consumeCodePoint(),If;break;case 43:if(_f(e,this.peekCodePoint(0),this.peekCodePoint(1)))return this.reconsumeCodePoint(e),this.consumeNumericToken();break;case 44:return Bf;case 45:var n=e,o=this.peekCodePoint(0),a=this.peekCodePoint(1);if(_f(n,o,a))return this.reconsumeCodePoint(e),this.consumeNumericToken();if(mf(n,o,a))return this.reconsumeCodePoint(e),this.consumeIdentLikeToken();if(45===o&&62===a)return this.consumeCodePoint(),this.consumeCodePoint(),Rf;break;case 46:if(_f(e,this.peekCodePoint(0),this.peekCodePoint(1)))return this.reconsumeCodePoint(e),this.consumeNumericToken();break;case 47:if(42===this.peekCodePoint(0))for(this.consumeCodePoint();;){var l=this.consumeCodePoint();if(42===l&&47===(l=this.consumeCodePoint()))return this.consumeToken();if(-1===l)return this.consumeToken()}break;case 58:return Lf;case 59:return Uf;case 60:if(33===this.peekCodePoint(0)&&45===this.peekCodePoint(1)&&45===this.peekCodePoint(2))return this.consumeCodePoint(),this.consumeCodePoint(),Tf;break;case 64:var u=this.peekCodePoint(0),A=this.peekCodePoint(1),c=this.peekCodePoint(2);if(mf(u,A,c))return{type:7,value:this.consumeName()};break;case 91:return Of;case 92:if(gf(e,this.peekCodePoint(0)))return this.reconsumeCodePoint(e),this.consumeIdentLikeToken();break;case 93:return Nf;case 61:if(61===this.peekCodePoint(0))return this.consumeCodePoint(),Pf;break;case 123:return Ef;case 125:return kf;case 117:case 85:var h=this.peekCodePoint(0),d=this.peekCodePoint(1);return 43!==h||!hf(d)&&63!==d||(this.consumeCodePoint(),this.consumeUnicodeRangeToken()),this.reconsumeCodePoint(e),this.consumeIdentLikeToken();case 124:if(61===this.peekCodePoint(0))return this.consumeCodePoint(),Mf;if(124===this.peekCodePoint(0))return this.consumeCodePoint(),Cf;break;case 126:if(61===this.peekCodePoint(0))return this.consumeCodePoint(),Ff;break;case-1:return Vf}return df(e)?(this.consumeWhiteSpace(),Qf):cf(e)?(this.reconsumeCodePoint(e),this.consumeNumericToken()):pf(e)?(this.reconsumeCodePoint(e),this.consumeIdentLikeToken()):{type:6,value:pp(e)}},e.prototype.consumeCodePoint=function(){var e=this._value.shift();return void 0===e?-1:e},e.prototype.reconsumeCodePoint=function(e){this._value.unshift(e)},e.prototype.peekCodePoint=function(e){return e>=this._value.length?-1:this._value[e]},e.prototype.consumeUnicodeRangeToken=function(){for(var e=[],t=this.consumeCodePoint();hf(t)&&e.length<6;)e.push(t),t=this.consumeCodePoint();for(var i=!1;63===t&&e.length<6;)e.push(t),t=this.consumeCodePoint(),i=!0;if(i)return{type:30,start:parseInt(pp.apply(void 0,e.map((function(e){return 63===e?48:e}))),16),end:parseInt(pp.apply(void 0,e.map((function(e){return 63===e?70:e}))),16)};var s=parseInt(pp.apply(void 0,e),16);if(45===this.peekCodePoint(0)&&hf(this.peekCodePoint(1))){this.consumeCodePoint(),t=this.consumeCodePoint();for(var r=[];hf(t)&&r.length<6;)r.push(t),t=this.consumeCodePoint();return{type:30,start:s,end:parseInt(pp.apply(void 0,r),16)}}return{type:30,start:s,end:s}},e.prototype.consumeIdentLikeToken=function(){var e=this.consumeName();return"url"===e.toLowerCase()&&40===this.peekCodePoint(0)?(this.consumeCodePoint(),this.consumeUrlToken()):40===this.peekCodePoint(0)?(this.consumeCodePoint(),{type:19,value:e}):{type:20,value:e}},e.prototype.consumeUrlToken=function(){var e=[];if(this.consumeWhiteSpace(),-1===this.peekCodePoint(0))return{type:22,value:""};var t=this.peekCodePoint(0);if(39===t||34===t){var i=this.consumeStringToken(this.consumeCodePoint());return 0===i.type&&(this.consumeWhiteSpace(),-1===this.peekCodePoint(0)||41===this.peekCodePoint(0))?(this.consumeCodePoint(),{type:22,value:i.value}):(this.consumeBadUrlRemnants(),Df)}for(;;){var s=this.consumeCodePoint();if(-1===s||41===s)return{type:22,value:pp.apply(void 0,e)};if(df(s))return this.consumeWhiteSpace(),-1===this.peekCodePoint(0)||41===this.peekCodePoint(0)?(this.consumeCodePoint(),{type:22,value:pp.apply(void 0,e)}):(this.consumeBadUrlRemnants(),Df);if(34===s||39===s||40===s||vf(s))return this.consumeBadUrlRemnants(),Df;if(92===s){if(!gf(s,this.peekCodePoint(0)))return this.consumeBadUrlRemnants(),Df;e.push(this.consumeEscapedCodePoint())}else e.push(s)}},e.prototype.consumeWhiteSpace=function(){for(;df(this.peekCodePoint(0));)this.consumeCodePoint()},e.prototype.consumeBadUrlRemnants=function(){for(;;){var e=this.consumeCodePoint();if(41===e||-1===e)return;gf(e,this.peekCodePoint(0))&&this.consumeEscapedCodePoint()}},e.prototype.consumeStringSlice=function(e){for(var t="";e>0;){var i=Math.min(5e4,e);t+=pp.apply(void 0,this._value.splice(0,i)),e-=i}return this._value.shift(),t},e.prototype.consumeStringToken=function(e){for(var t="",i=0;;){var s=this._value[i];if(-1===s||void 0===s||s===e)return{type:0,value:t+=this.consumeStringSlice(i)};if(10===s)return this._value.splice(0,i),Sf;if(92===s){var r=this._value[i+1];-1!==r&&void 0!==r&&(10===r?(t+=this.consumeStringSlice(i),i=-1,this._value.shift()):gf(s,r)&&(t+=this.consumeStringSlice(i),t+=pp(this.consumeEscapedCodePoint()),i=-1))}i++}},e.prototype.consumeNumber=function(){var e=[],t=4,i=this.peekCodePoint(0);for(43!==i&&45!==i||e.push(this.consumeCodePoint());cf(this.peekCodePoint(0));)e.push(this.consumeCodePoint());i=this.peekCodePoint(0);var s=this.peekCodePoint(1);if(46===i&&cf(s))for(e.push(this.consumeCodePoint(),this.consumeCodePoint()),t=8;cf(this.peekCodePoint(0));)e.push(this.consumeCodePoint());i=this.peekCodePoint(0),s=this.peekCodePoint(1);var r=this.peekCodePoint(2);if((69===i||101===i)&&((43===s||45===s)&&cf(r)||cf(s)))for(e.push(this.consumeCodePoint(),this.consumeCodePoint()),t=8;cf(this.peekCodePoint(0));)e.push(this.consumeCodePoint());return[yf(e),t]},e.prototype.consumeNumericToken=function(){var e=this.consumeNumber(),t=e[0],i=e[1],s=this.peekCodePoint(0),r=this.peekCodePoint(1),n=this.peekCodePoint(2);return mf(s,r,n)?{type:15,number:t,flags:i,unit:this.consumeName()}:37===s?(this.consumeCodePoint(),{type:16,number:t,flags:i}):{type:17,number:t,flags:i}},e.prototype.consumeEscapedCodePoint=function(){var e=this.consumeCodePoint();if(hf(e)){for(var t=pp(e);hf(this.peekCodePoint(0))&&t.length<6;)t+=pp(this.consumeCodePoint());df(this.peekCodePoint(0))&&this.consumeCodePoint();var i=parseInt(t,16);return 0===i||function(e){return e>=55296&&e<=57343}(i)||i>1114111?65533:i}return-1===e?65533:e},e.prototype.consumeName=function(){for(var e="";;){var t=this.consumeCodePoint();if(ff(t))e+=pp(t);else{if(!gf(t,this.peekCodePoint(0)))return this.reconsumeCodePoint(t),e;e+=pp(this.consumeEscapedCodePoint())}}},e}(),jf=function(){function e(e){this._tokens=e}return e.create=function(t){var i=new Hf;return i.write(t),new e(i.read())},e.parseValue=function(t){return e.create(t).parseComponentValue()},e.parseValues=function(t){return e.create(t).parseComponentValues()},e.prototype.parseComponentValue=function(){for(var e=this.consumeToken();31===e.type;)e=this.consumeToken();if(32===e.type)throw new SyntaxError("Error parsing CSS component value, unexpected EOF");this.reconsumeToken(e);var t=this.consumeComponentValue();do{e=this.consumeToken()}while(31===e.type);if(32===e.type)return t;throw new SyntaxError("Error parsing CSS component value, multiple values found when expecting only one")},e.prototype.parseComponentValues=function(){for(var e=[];;){var t=this.consumeComponentValue();if(32===t.type)return e;e.push(t),e.push()}},e.prototype.consumeComponentValue=function(){var e=this.consumeToken();switch(e.type){case 11:case 28:case 2:return this.consumeSimpleBlock(e.type);case 19:return this.consumeFunction(e)}return e},e.prototype.consumeSimpleBlock=function(e){for(var t={type:e,values:[]},i=this.consumeToken();;){if(32===i.type||qf(i,e))return t;this.reconsumeToken(i),t.values.push(this.consumeComponentValue()),i=this.consumeToken()}},e.prototype.consumeFunction=function(e){for(var t={name:e.value,values:[],type:18};;){var i=this.consumeToken();if(32===i.type||3===i.type)return t;this.reconsumeToken(i),t.values.push(this.consumeComponentValue())}},e.prototype.consumeToken=function(){var e=this._tokens.shift();return void 0===e?Vf:e},e.prototype.reconsumeToken=function(e){this._tokens.unshift(e)},e}(),Gf=function(e){return 15===e.type},zf=function(e){return 17===e.type},Wf=function(e){return 20===e.type},Kf=function(e){return 0===e.type},Xf=function(e,t){return Wf(e)&&e.value===t},Jf=function(e){return 31!==e.type},Yf=function(e){return 31!==e.type&&4!==e.type},Zf=function(e){var t=[],i=[];return e.forEach((function(e){if(4===e.type){if(0===i.length)throw new Error("Error parsing function args, zero tokens for arg");return t.push(i),void(i=[])}31!==e.type&&i.push(e)})),i.length&&t.push(i),t},qf=function(e,t){return 11===t&&12===e.type||(28===t&&29===e.type||2===t&&3===e.type)},$f=function(e){return 17===e.type||15===e.type},ev=function(e){return 16===e.type||$f(e)},tv=function(e){return e.length>1?[e[0],e[1]]:[e[0]]},iv={type:17,number:0,flags:4},sv={type:16,number:50,flags:4},rv={type:16,number:100,flags:4},nv=function(e,t,i){var s=e[0],r=e[1];return[ov(s,t),ov(void 0!==r?r:s,i)]},ov=function(e,t){if(16===e.type)return e.number/100*t;if(Gf(e))switch(e.unit){case"rem":case"em":return 16*e.number;default:return e.number}return e.number},av=function(e,t){if(15===t.type)switch(t.unit){case"deg":return Math.PI*t.number/180;case"grad":return Math.PI/200*t.number;case"rad":return t.number;case"turn":return 2*Math.PI*t.number}throw new Error("Unsupported angle type")},lv=function(e){return 15===e.type&&("deg"===e.unit||"grad"===e.unit||"rad"===e.unit||"turn"===e.unit)},uv=function(e){switch(e.filter(Wf).map((function(e){return e.value})).join(" ")){case"to bottom right":case"to right bottom":case"left top":case"top left":return[iv,iv];case"to top":case"bottom":return Av(0);case"to bottom left":case"to left bottom":case"right top":case"top right":return[iv,rv];case"to right":case"left":return Av(90);case"to top left":case"to left top":case"right bottom":case"bottom right":return[rv,rv];case"to bottom":case"top":return Av(180);case"to top right":case"to right top":case"left bottom":case"bottom left":return[rv,iv];case"to left":case"right":return Av(270)}return 0},Av=function(e){return Math.PI*e/180},cv=function(e,t){if(18===t.type){var i=_v[t.name];if(void 0===i)throw new Error('Attempting to parse an unsupported color function "'+t.name+'"');return i(e,t.values)}if(5===t.type){if(3===t.value.length){var s=t.value.substring(0,1),r=t.value.substring(1,2),n=t.value.substring(2,3);return pv(parseInt(s+s,16),parseInt(r+r,16),parseInt(n+n,16),1)}if(4===t.value.length){s=t.value.substring(0,1),r=t.value.substring(1,2),n=t.value.substring(2,3);var o=t.value.substring(3,4);return pv(parseInt(s+s,16),parseInt(r+r,16),parseInt(n+n,16),parseInt(o+o,16)/255)}if(6===t.value.length){s=t.value.substring(0,2),r=t.value.substring(2,4),n=t.value.substring(4,6);return pv(parseInt(s,16),parseInt(r,16),parseInt(n,16),1)}if(8===t.value.length){s=t.value.substring(0,2),r=t.value.substring(2,4),n=t.value.substring(4,6),o=t.value.substring(6,8);return pv(parseInt(s,16),parseInt(r,16),parseInt(n,16),parseInt(o,16)/255)}}if(20===t.type){var a=bv[t.value.toUpperCase()];if(void 0!==a)return a}return bv.TRANSPARENT},hv=function(e){return 0==(255&e)},dv=function(e){var t=255&e,i=255&e>>8,s=255&e>>16,r=255&e>>24;return t<255?"rgba("+r+","+s+","+i+","+t/255+")":"rgb("+r+","+s+","+i+")"},pv=function(e,t,i,s){return(e<<24|t<<16|i<<8|Math.round(255*s)<<0)>>>0},fv=function(e,t){if(17===e.type)return e.number;if(16===e.type){var i=3===t?1:255;return 3===t?e.number/100*i:Math.round(e.number/100*i)}return 0},vv=function(e,t){var i=t.filter(Yf);if(3===i.length){var s=i.map(fv),r=s[0],n=s[1],o=s[2];return pv(r,n,o,1)}if(4===i.length){var a=i.map(fv),l=(r=a[0],n=a[1],o=a[2],a[3]);return pv(r,n,o,l)}return 0};function gv(e,t,i){return i<0&&(i+=1),i>=1&&(i-=1),i<1/6?(t-e)*i*6+e:i<.5?t:i<2/3?6*(t-e)*(2/3-i)+e:e}var mv=function(e,t){var i=t.filter(Yf),s=i[0],r=i[1],n=i[2],o=i[3],a=(17===s.type?Av(s.number):av(e,s))/(2*Math.PI),l=ev(r)?r.number/100:0,u=ev(n)?n.number/100:0,A=void 0!==o&&ev(o)?ov(o,1):1;if(0===l)return pv(255*u,255*u,255*u,1);var c=u<=.5?u*(l+1):u+l-u*l,h=2*u-c,d=gv(h,c,a+1/3),p=gv(h,c,a),f=gv(h,c,a-1/3);return pv(255*d,255*p,255*f,A)},_v={hsl:mv,hsla:mv,rgb:vv,rgba:vv},yv=function(e,t){return cv(e,jf.create(t).parseComponentValue())},bv={ALICEBLUE:4042850303,ANTIQUEWHITE:4209760255,AQUA:16777215,AQUAMARINE:2147472639,AZURE:4043309055,BEIGE:4126530815,BISQUE:4293182719,BLACK:255,BLANCHEDALMOND:4293643775,BLUE:65535,BLUEVIOLET:2318131967,BROWN:2771004159,BURLYWOOD:3736635391,CADETBLUE:1604231423,CHARTREUSE:2147418367,CHOCOLATE:3530104575,CORAL:4286533887,CORNFLOWERBLUE:1687547391,CORNSILK:4294499583,CRIMSON:3692313855,CYAN:16777215,DARKBLUE:35839,DARKCYAN:9145343,DARKGOLDENROD:3095837695,DARKGRAY:2846468607,DARKGREEN:6553855,DARKGREY:2846468607,DARKKHAKI:3182914559,DARKMAGENTA:2332068863,DARKOLIVEGREEN:1433087999,DARKORANGE:4287365375,DARKORCHID:2570243327,DARKRED:2332033279,DARKSALMON:3918953215,DARKSEAGREEN:2411499519,DARKSLATEBLUE:1211993087,DARKSLATEGRAY:793726975,DARKSLATEGREY:793726975,DARKTURQUOISE:13554175,DARKVIOLET:2483082239,DEEPPINK:4279538687,DEEPSKYBLUE:12582911,DIMGRAY:1768516095,DIMGREY:1768516095,DODGERBLUE:512819199,FIREBRICK:2988581631,FLORALWHITE:4294635775,FORESTGREEN:579543807,FUCHSIA:4278255615,GAINSBORO:3705462015,GHOSTWHITE:4177068031,GOLD:4292280575,GOLDENROD:3668254975,GRAY:2155905279,GREEN:8388863,GREENYELLOW:2919182335,GREY:2155905279,HONEYDEW:4043305215,HOTPINK:4285117695,INDIANRED:3445382399,INDIGO:1258324735,IVORY:4294963455,KHAKI:4041641215,LAVENDER:3873897215,LAVENDERBLUSH:4293981695,LAWNGREEN:2096890111,LEMONCHIFFON:4294626815,LIGHTBLUE:2916673279,LIGHTCORAL:4034953471,LIGHTCYAN:3774873599,LIGHTGOLDENRODYELLOW:4210742015,LIGHTGRAY:3553874943,LIGHTGREEN:2431553791,LIGHTGREY:3553874943,LIGHTPINK:4290167295,LIGHTSALMON:4288707327,LIGHTSEAGREEN:548580095,LIGHTSKYBLUE:2278488831,LIGHTSLATEGRAY:2005441023,LIGHTSLATEGREY:2005441023,LIGHTSTEELBLUE:2965692159,LIGHTYELLOW:4294959359,LIME:16711935,LIMEGREEN:852308735,LINEN:4210091775,MAGENTA:4278255615,MAROON:2147483903,MEDIUMAQUAMARINE:1724754687,MEDIUMBLUE:52735,MEDIUMORCHID:3126187007,MEDIUMPURPLE:2473647103,MEDIUMSEAGREEN:1018393087,MEDIUMSLATEBLUE:2070474495,MEDIUMSPRINGGREEN:16423679,MEDIUMTURQUOISE:1221709055,MEDIUMVIOLETRED:3340076543,MIDNIGHTBLUE:421097727,MINTCREAM:4127193855,MISTYROSE:4293190143,MOCCASIN:4293178879,NAVAJOWHITE:4292783615,NAVY:33023,OLDLACE:4260751103,OLIVE:2155872511,OLIVEDRAB:1804477439,ORANGE:4289003775,ORANGERED:4282712319,ORCHID:3664828159,PALEGOLDENROD:4008225535,PALEGREEN:2566625535,PALETURQUOISE:2951671551,PALEVIOLETRED:3681588223,PAPAYAWHIP:4293907967,PEACHPUFF:4292524543,PERU:3448061951,PINK:4290825215,PLUM:3718307327,POWDERBLUE:2967529215,PURPLE:2147516671,REBECCAPURPLE:1714657791,RED:4278190335,ROSYBROWN:3163525119,ROYALBLUE:1097458175,SADDLEBROWN:2336560127,SALMON:4202722047,SANDYBROWN:4104413439,SEAGREEN:780883967,SEASHELL:4294307583,SIENNA:2689740287,SILVER:3233857791,SKYBLUE:2278484991,SLATEBLUE:1784335871,SLATEGRAY:1887473919,SLATEGREY:1887473919,SNOW:4294638335,SPRINGGREEN:16744447,STEELBLUE:1182971135,TAN:3535047935,TEAL:8421631,THISTLE:3636451583,TOMATO:4284696575,TRANSPARENT:0,TURQUOISE:1088475391,VIOLET:4001558271,WHEAT:4125012991,WHITE:4294967295,WHITESMOKE:4126537215,YELLOW:4294902015,YELLOWGREEN:2597139199},wv={name:"background-clip",initialValue:"border-box",prefix:!1,type:1,parse:function(e,t){return t.map((function(e){if(Wf(e))switch(e.value){case"padding-box":return 1;case"content-box":return 2}return 0}))}},Bv={name:"background-color",initialValue:"transparent",prefix:!1,type:3,format:"color"},xv=function(e,t){var i=cv(e,t[0]),s=t[1];return s&&ev(s)?{color:i,stop:s}:{color:i,stop:null}},Pv=function(e,t){var i=e[0],s=e[e.length-1];null===i.stop&&(i.stop=iv),null===s.stop&&(s.stop=rv);for(var r=[],n=0,o=0;on?r.push(l):r.push(n),n=l}else r.push(null)}var u=null;for(o=0;oe.optimumDistance)?{optimumCorner:t,optimumDistance:a}:e}),{optimumDistance:r?1/0:-1/0,optimumCorner:null}).optimumCorner},Ev=function(e,t){var i=Av(180),s=[];return Zf(t).forEach((function(t,r){if(0===r){var n=t[0];if(20===n.type&&-1!==["top","left","right","bottom"].indexOf(n.value))return void(i=uv(t));if(lv(n))return void(i=(av(e,n)+Av(270))%Av(360))}var o=xv(e,t);s.push(o)})),{angle:i,stops:s,type:1}},kv=function(e,t){var i=0,s=3,r=[],n=[];return Zf(t).forEach((function(t,o){var a=!0;if(0===o?a=t.reduce((function(e,t){if(Wf(t))switch(t.value){case"center":return n.push(sv),!1;case"top":case"left":return n.push(iv),!1;case"right":case"bottom":return n.push(rv),!1}else if(ev(t)||$f(t))return n.push(t),!1;return e}),a):1===o&&(a=t.reduce((function(e,t){if(Wf(t))switch(t.value){case"circle":return i=0,!1;case"ellipse":return i=1,!1;case"contain":case"closest-side":return s=0,!1;case"farthest-side":return s=1,!1;case"closest-corner":return s=2,!1;case"cover":case"farthest-corner":return s=3,!1}else if($f(t)||ev(t))return Array.isArray(s)||(s=[]),s.push(t),!1;return e}),a)),a){var l=xv(e,t);r.push(l)}})),{size:s,shape:i,stops:r,position:n,type:2}},Iv=function(e,t){if(22===t.type){var i={url:t.value,type:0};return e.cache.addImage(t.value),i}if(18===t.type){var s=Sv[t.name];if(void 0===s)throw new Error('Attempting to parse an unsupported image function "'+t.name+'"');return s(e,t.values)}throw new Error("Unsupported image type "+t.type)};var Dv,Sv={"linear-gradient":function(e,t){var i=Av(180),s=[];return Zf(t).forEach((function(t,r){if(0===r){var n=t[0];if(20===n.type&&"to"===n.value)return void(i=uv(t));if(lv(n))return void(i=av(e,n))}var o=xv(e,t);s.push(o)})),{angle:i,stops:s,type:1}},"-moz-linear-gradient":Ev,"-ms-linear-gradient":Ev,"-o-linear-gradient":Ev,"-webkit-linear-gradient":Ev,"radial-gradient":function(e,t){var i=0,s=3,r=[],n=[];return Zf(t).forEach((function(t,o){var a=!0;if(0===o){var l=!1;a=t.reduce((function(e,t){if(l)if(Wf(t))switch(t.value){case"center":return n.push(sv),e;case"top":case"left":return n.push(iv),e;case"right":case"bottom":return n.push(rv),e}else(ev(t)||$f(t))&&n.push(t);else if(Wf(t))switch(t.value){case"circle":return i=0,!1;case"ellipse":return i=1,!1;case"at":return l=!0,!1;case"closest-side":return s=0,!1;case"cover":case"farthest-side":return s=1,!1;case"contain":case"closest-corner":return s=2,!1;case"farthest-corner":return s=3,!1}else if($f(t)||ev(t))return Array.isArray(s)||(s=[]),s.push(t),!1;return e}),a)}if(a){var u=xv(e,t);r.push(u)}})),{size:s,shape:i,stops:r,position:n,type:2}},"-moz-radial-gradient":kv,"-ms-radial-gradient":kv,"-o-radial-gradient":kv,"-webkit-radial-gradient":kv,"-webkit-gradient":function(e,t){var i=Av(180),s=[],r=1;return Zf(t).forEach((function(t,i){var n=t[0];if(0===i){if(Wf(n)&&"linear"===n.value)return void(r=1);if(Wf(n)&&"radial"===n.value)return void(r=2)}if(18===n.type)if("from"===n.name){var o=cv(e,n.values[0]);s.push({stop:iv,color:o})}else if("to"===n.name){o=cv(e,n.values[0]);s.push({stop:rv,color:o})}else if("color-stop"===n.name){var a=n.values.filter(Yf);if(2===a.length){o=cv(e,a[1]);var l=a[0];zf(l)&&s.push({stop:{type:16,number:100*l.number,flags:l.flags},color:o})}}})),1===r?{angle:(i+Av(180))%Av(360),stops:s,type:r}:{size:3,shape:0,stops:s,position:[],type:r}}},Tv={name:"background-image",initialValue:"none",type:1,prefix:!1,parse:function(e,t){if(0===t.length)return[];var i=t[0];return 20===i.type&&"none"===i.value?[]:t.filter((function(e){return Yf(e)&&function(e){return!(20===e.type&&"none"===e.value||18===e.type&&!Sv[e.name])}(e)})).map((function(t){return Iv(e,t)}))}},Rv={name:"background-origin",initialValue:"border-box",prefix:!1,type:1,parse:function(e,t){return t.map((function(e){if(Wf(e))switch(e.value){case"padding-box":return 1;case"content-box":return 2}return 0}))}},Lv={name:"background-position",initialValue:"0% 0%",type:1,prefix:!1,parse:function(e,t){return Zf(t).map((function(e){return e.filter(ev)})).map(tv)}},Uv={name:"background-repeat",initialValue:"repeat",prefix:!1,type:1,parse:function(e,t){return Zf(t).map((function(e){return e.filter(Wf).map((function(e){return e.value})).join(" ")})).map(Ov)}},Ov=function(e){switch(e){case"no-repeat":return 1;case"repeat-x":case"repeat no-repeat":return 2;case"repeat-y":case"no-repeat repeat":return 3;default:return 0}};!function(e){e.AUTO="auto",e.CONTAIN="contain",e.COVER="cover"}(Dv||(Dv={}));var Nv,Qv={name:"background-size",initialValue:"0",prefix:!1,type:1,parse:function(e,t){return Zf(t).map((function(e){return e.filter(Vv)}))}},Vv=function(e){return Wf(e)||ev(e)},Hv=function(e){return{name:"border-"+e+"-color",initialValue:"transparent",prefix:!1,type:3,format:"color"}},jv=Hv("top"),Gv=Hv("right"),zv=Hv("bottom"),Wv=Hv("left"),Kv=function(e){return{name:"border-radius-"+e,initialValue:"0 0",prefix:!1,type:1,parse:function(e,t){return tv(t.filter(ev))}}},Xv=Kv("top-left"),Jv=Kv("top-right"),Yv=Kv("bottom-right"),Zv=Kv("bottom-left"),qv=function(e){return{name:"border-"+e+"-style",initialValue:"solid",prefix:!1,type:2,parse:function(e,t){switch(t){case"none":return 0;case"dashed":return 2;case"dotted":return 3;case"double":return 4}return 1}}},$v=qv("top"),eg=qv("right"),tg=qv("bottom"),ig=qv("left"),sg=function(e){return{name:"border-"+e+"-width",initialValue:"0",type:0,prefix:!1,parse:function(e,t){return Gf(t)?t.number:0}}},rg=sg("top"),ng=sg("right"),og=sg("bottom"),ag=sg("left"),lg={name:"color",initialValue:"transparent",prefix:!1,type:3,format:"color"},ug={name:"direction",initialValue:"ltr",prefix:!1,type:2,parse:function(e,t){return"rtl"===t?1:0}},Ag={name:"display",initialValue:"inline-block",prefix:!1,type:1,parse:function(e,t){return t.filter(Wf).reduce((function(e,t){return e|cg(t.value)}),0)}},cg=function(e){switch(e){case"block":case"-webkit-box":return 2;case"inline":return 4;case"run-in":return 8;case"flow":return 16;case"flow-root":return 32;case"table":return 64;case"flex":case"-webkit-flex":return 128;case"grid":case"-ms-grid":return 256;case"ruby":return 512;case"subgrid":return 1024;case"list-item":return 2048;case"table-row-group":return 4096;case"table-header-group":return 8192;case"table-footer-group":return 16384;case"table-row":return 32768;case"table-cell":return 65536;case"table-column-group":return 131072;case"table-column":return 262144;case"table-caption":return 524288;case"ruby-base":return 1048576;case"ruby-text":return 2097152;case"ruby-base-container":return 4194304;case"ruby-text-container":return 8388608;case"contents":return 16777216;case"inline-block":return 33554432;case"inline-list-item":return 67108864;case"inline-table":return 134217728;case"inline-flex":return 268435456;case"inline-grid":return 536870912}return 0},hg={name:"float",initialValue:"none",prefix:!1,type:2,parse:function(e,t){switch(t){case"left":return 1;case"right":return 2;case"inline-start":return 3;case"inline-end":return 4}return 0}},dg={name:"letter-spacing",initialValue:"0",prefix:!1,type:0,parse:function(e,t){return 20===t.type&&"normal"===t.value?0:17===t.type||15===t.type?t.number:0}};!function(e){e.NORMAL="normal",e.STRICT="strict"}(Nv||(Nv={}));var pg,fg={name:"line-break",initialValue:"normal",prefix:!1,type:2,parse:function(e,t){return"strict"===t?Nv.STRICT:Nv.NORMAL}},vg={name:"line-height",initialValue:"normal",prefix:!1,type:4},gg=function(e,t){return Wf(e)&&"normal"===e.value?1.2*t:17===e.type?t*e.number:ev(e)?ov(e,t):t},mg={name:"list-style-image",initialValue:"none",type:0,prefix:!1,parse:function(e,t){return 20===t.type&&"none"===t.value?null:Iv(e,t)}},_g={name:"list-style-position",initialValue:"outside",prefix:!1,type:2,parse:function(e,t){return"inside"===t?0:1}},yg={name:"list-style-type",initialValue:"none",prefix:!1,type:2,parse:function(e,t){switch(t){case"disc":return 0;case"circle":return 1;case"square":return 2;case"decimal":return 3;case"cjk-decimal":return 4;case"decimal-leading-zero":return 5;case"lower-roman":return 6;case"upper-roman":return 7;case"lower-greek":return 8;case"lower-alpha":return 9;case"upper-alpha":return 10;case"arabic-indic":return 11;case"armenian":return 12;case"bengali":return 13;case"cambodian":return 14;case"cjk-earthly-branch":return 15;case"cjk-heavenly-stem":return 16;case"cjk-ideographic":return 17;case"devanagari":return 18;case"ethiopic-numeric":return 19;case"georgian":return 20;case"gujarati":return 21;case"gurmukhi":case"hebrew":return 22;case"hiragana":return 23;case"hiragana-iroha":return 24;case"japanese-formal":return 25;case"japanese-informal":return 26;case"kannada":return 27;case"katakana":return 28;case"katakana-iroha":return 29;case"khmer":return 30;case"korean-hangul-formal":return 31;case"korean-hanja-formal":return 32;case"korean-hanja-informal":return 33;case"lao":return 34;case"lower-armenian":return 35;case"malayalam":return 36;case"mongolian":return 37;case"myanmar":return 38;case"oriya":return 39;case"persian":return 40;case"simp-chinese-formal":return 41;case"simp-chinese-informal":return 42;case"tamil":return 43;case"telugu":return 44;case"thai":return 45;case"tibetan":return 46;case"trad-chinese-formal":return 47;case"trad-chinese-informal":return 48;case"upper-armenian":return 49;case"disclosure-open":return 50;case"disclosure-closed":return 51;default:return-1}}},bg=function(e){return{name:"margin-"+e,initialValue:"0",prefix:!1,type:4}},wg=bg("top"),Bg=bg("right"),xg=bg("bottom"),Pg=bg("left"),Cg={name:"overflow",initialValue:"visible",prefix:!1,type:1,parse:function(e,t){return t.filter(Wf).map((function(e){switch(e.value){case"hidden":return 1;case"scroll":return 2;case"clip":return 3;case"auto":return 4;default:return 0}}))}},Mg={name:"overflow-wrap",initialValue:"normal",prefix:!1,type:2,parse:function(e,t){return"break-word"===t?"break-word":"normal"}},Fg=function(e){return{name:"padding-"+e,initialValue:"0",prefix:!1,type:3,format:"length-percentage"}},Eg=Fg("top"),kg=Fg("right"),Ig=Fg("bottom"),Dg=Fg("left"),Sg={name:"text-align",initialValue:"left",prefix:!1,type:2,parse:function(e,t){switch(t){case"right":return 2;case"center":case"justify":return 1;default:return 0}}},Tg={name:"position",initialValue:"static",prefix:!1,type:2,parse:function(e,t){switch(t){case"relative":return 1;case"absolute":return 2;case"fixed":return 3;case"sticky":return 4}return 0}},Rg={name:"text-shadow",initialValue:"none",type:1,prefix:!1,parse:function(e,t){return 1===t.length&&Xf(t[0],"none")?[]:Zf(t).map((function(t){for(var i={color:bv.TRANSPARENT,offsetX:iv,offsetY:iv,blur:iv},s=0,r=0;r1?1:0],this.overflowWrap=pm(e,Mg,t.overflowWrap),this.paddingTop=pm(e,Eg,t.paddingTop),this.paddingRight=pm(e,kg,t.paddingRight),this.paddingBottom=pm(e,Ig,t.paddingBottom),this.paddingLeft=pm(e,Dg,t.paddingLeft),this.paintOrder=pm(e,lm,t.paintOrder),this.position=pm(e,Tg,t.position),this.textAlign=pm(e,Sg,t.textAlign),this.textDecorationColor=pm(e,Kg,null!==(i=t.textDecorationColor)&&void 0!==i?i:t.color),this.textDecorationLine=pm(e,Xg,null!==(s=t.textDecorationLine)&&void 0!==s?s:t.textDecoration),this.textShadow=pm(e,Rg,t.textShadow),this.textTransform=pm(e,Lg,t.textTransform),this.transform=pm(e,Ug,t.transform),this.transformOrigin=pm(e,Vg,t.transformOrigin),this.visibility=pm(e,Hg,t.visibility),this.webkitTextStrokeColor=pm(e,um,t.webkitTextStrokeColor),this.webkitTextStrokeWidth=pm(e,Am,t.webkitTextStrokeWidth),this.wordBreak=pm(e,jg,t.wordBreak),this.zIndex=pm(e,Gg,t.zIndex)}return e.prototype.isVisible=function(){return this.display>0&&this.opacity>0&&0===this.visibility},e.prototype.isTransparent=function(){return hv(this.backgroundColor)},e.prototype.isTransformed=function(){return null!==this.transform},e.prototype.isPositioned=function(){return 0!==this.position},e.prototype.isPositionedWithZIndex=function(){return this.isPositioned()&&!this.zIndex.auto},e.prototype.isFloating=function(){return 0!==this.float},e.prototype.isInlineLevel=function(){return em(this.display,4)||em(this.display,33554432)||em(this.display,268435456)||em(this.display,536870912)||em(this.display,67108864)||em(this.display,134217728)},e}(),hm=function(e,t){this.content=pm(e,tm,t.content),this.quotes=pm(e,nm,t.quotes)},dm=function(e,t){this.counterIncrement=pm(e,im,t.counterIncrement),this.counterReset=pm(e,sm,t.counterReset)},pm=function(e,t,i){var s=new Hf,r=null!=i?i.toString():t.initialValue;s.write(r);var n=new jf(s.read());switch(t.type){case 2:var o=n.parseComponentValue();return t.parse(e,Wf(o)?o.value:t.initialValue);case 0:return t.parse(e,n.parseComponentValue());case 1:return t.parse(e,n.parseComponentValues());case 4:return n.parseComponentValue();case 3:switch(t.format){case"angle":return av(e,n.parseComponentValue());case"color":return cv(e,n.parseComponentValue());case"image":return Iv(e,n.parseComponentValue());case"length":var a=n.parseComponentValue();return $f(a)?a:iv;case"length-percentage":var l=n.parseComponentValue();return ev(l)?l:iv;case"time":return zg(e,n.parseComponentValue())}}},fm=function(e,t){var i=function(e){switch(e.getAttribute("data-html2canvas-debug")){case"all":return 1;case"clone":return 2;case"parse":return 3;case"render":return 4;default:return 0}}(e);return 1===i||t===i},vm=function(e,t){this.context=e,this.textNodes=[],this.elements=[],this.flags=0,fm(t,3),this.styles=new cm(e,window.getComputedStyle(t,null)),v_(t)&&(this.styles.animationDuration.some((function(e){return e>0}))&&(t.style.animationDuration="0s"),null!==this.styles.transform&&(t.style.transform="none")),this.bounds=hp(this.context,t),fm(t,4)&&(this.flags|=16)},gm="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",mm="undefined"==typeof Uint8Array?[]:new Uint8Array(256),_m=0;_m=0){if(e<55296||e>56319&&e<=65535)return t=((t=this.index[e>>5])<<2)+(31&e),this.data[t];if(e<=65535)return t=((t=this.index[2048+(e-55296>>5)])<<2)+(31&e),this.data[t];if(e>11),t=this.index[t],t+=e>>5&63,t=((t=this.index[t])<<2)+(31&e),this.data[t];if(e<=1114111)return this.data[this.highValueIndex]}return this.errorValue},e}(),wm="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Bm="undefined"==typeof Uint8Array?[]:new Uint8Array(256),xm=0;xm>10),o%1024+56320)),(r+1===i||s.length>16384)&&(n+=String.fromCharCode.apply(String,s),s.length=0)}return n},Im=function(e,t){var i,s,r,n=function(e){var t,i,s,r,n,o=.75*e.length,a=e.length,l=0;"="===e[e.length-1]&&(o--,"="===e[e.length-2]&&o--);var u="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof Uint8Array&&void 0!==Uint8Array.prototype.slice?new ArrayBuffer(o):new Array(o),A=Array.isArray(u)?u:new Uint8Array(u);for(t=0;t>4,A[l++]=(15&s)<<4|r>>2,A[l++]=(3&r)<<6|63&n;return u}(e),o=Array.isArray(n)?function(e){for(var t=e.length,i=[],s=0;s=55296&&r<=56319&&i=i)return{done:!0,value:null};for(var e="×";so.x||r.y>o.y;return o=r,0===t||a}));return e.body.removeChild(t),a}(document);return Object.defineProperty(Om,"SUPPORT_WORD_BREAKING",{value:e}),e},get SUPPORT_SVG_DRAWING(){var e=function(e){var t=new Image,i=e.createElement("canvas"),s=i.getContext("2d");if(!s)return!1;t.src="data:image/svg+xml,";try{s.drawImage(t,0,0),i.toDataURL()}catch(e){return!1}return!0}(document);return Object.defineProperty(Om,"SUPPORT_SVG_DRAWING",{value:e}),e},get SUPPORT_FOREIGNOBJECT_DRAWING(){var e="function"==typeof Array.from&&"function"==typeof window.fetch?function(e){var t=e.createElement("canvas"),i=100;t.width=i,t.height=i;var s=t.getContext("2d");if(!s)return Promise.reject(!1);s.fillStyle="rgb(0, 255, 0)",s.fillRect(0,0,i,i);var r=new Image,n=t.toDataURL();r.src=n;var o=Lm(i,i,0,0,r);return s.fillStyle="red",s.fillRect(0,0,i,i),Um(o).then((function(t){s.drawImage(t,0,0);var r=s.getImageData(0,0,i,i).data;s.fillStyle="red",s.fillRect(0,0,i,i);var o=e.createElement("div");return o.style.backgroundImage="url("+n+")",o.style.height="100px",Rm(r)?Um(Lm(i,i,0,0,o)):Promise.reject(!1)})).then((function(e){return s.drawImage(e,0,0),Rm(s.getImageData(0,0,i,i).data)})).catch((function(){return!1}))}(document):Promise.resolve(!1);return Object.defineProperty(Om,"SUPPORT_FOREIGNOBJECT_DRAWING",{value:e}),e},get SUPPORT_CORS_IMAGES(){var e=void 0!==(new Image).crossOrigin;return Object.defineProperty(Om,"SUPPORT_CORS_IMAGES",{value:e}),e},get SUPPORT_RESPONSE_TYPE(){var e="string"==typeof(new XMLHttpRequest).responseType;return Object.defineProperty(Om,"SUPPORT_RESPONSE_TYPE",{value:e}),e},get SUPPORT_CORS_XHR(){var e="withCredentials"in new XMLHttpRequest;return Object.defineProperty(Om,"SUPPORT_CORS_XHR",{value:e}),e},get SUPPORT_NATIVE_TEXT_SEGMENTATION(){var e=!("undefined"==typeof Intl||!Intl.Segmenter);return Object.defineProperty(Om,"SUPPORT_NATIVE_TEXT_SEGMENTATION",{value:e}),e}},Nm=function(e,t){this.text=e,this.bounds=t},Qm=function(e,t){var i=t.ownerDocument;if(i){var s=i.createElement("html2canvaswrapper");s.appendChild(t.cloneNode(!0));var r=t.parentNode;if(r){r.replaceChild(s,t);var n=hp(e,s);return s.firstChild&&r.replaceChild(s.firstChild,s),n}}return cp.EMPTY},Vm=function(e,t,i){var s=e.ownerDocument;if(!s)throw new Error("Node has no owner document");var r=s.createRange();return r.setStart(e,t),r.setEnd(e,t+i),r},Hm=function(e){if(Om.SUPPORT_NATIVE_TEXT_SEGMENTATION){var t=new Intl.Segmenter(void 0,{granularity:"grapheme"});return Array.from(t.segment(e)).map((function(e){return e.segment}))}return function(e){for(var t,i=Tm(e),s=[];!(t=i.next()).done;)t.value&&s.push(t.value.slice());return s}(e)},jm=function(e,t){return 0!==t.letterSpacing?Hm(e):function(e,t){if(Om.SUPPORT_NATIVE_TEXT_SEGMENTATION){var i=new Intl.Segmenter(void 0,{granularity:"word"});return Array.from(i.segment(e)).map((function(e){return e.segment}))}return zm(e,t)}(e,t)},Gm=[32,160,4961,65792,65793,4153,4241],zm=function(e,t){for(var i,s=function(e,t){var i=dp(e),s=uf(i,t),r=s[0],n=s[1],o=s[2],a=i.length,l=0,u=0;return{next:function(){if(u>=a)return{done:!0,value:null};for(var e="×";u0)if(Om.SUPPORT_RANGE_BOUNDS){var r=Vm(s,o,t.length).getClientRects();if(r.length>1){var a=Hm(t),l=0;a.forEach((function(t){n.push(new Nm(t,cp.fromDOMRectList(e,Vm(s,l+o,t.length).getClientRects()))),l+=t.length}))}else n.push(new Nm(t,cp.fromDOMRectList(e,r)))}else{var u=s.splitText(t.length);n.push(new Nm(t,Qm(e,s))),s=u}else Om.SUPPORT_RANGE_BOUNDS||(s=s.splitText(t.length));o+=t.length})),n}(e,this.text,i,t)},Km=function(e,t){switch(t){case 1:return e.toLowerCase();case 3:return e.replace(Xm,Jm);case 2:return e.toUpperCase();default:return e}},Xm=/(^|\s|:|-|\(|\))([a-z])/g,Jm=function(e,t,i){return e.length>0?t+i.toUpperCase():e},Ym=function(e){function t(t,i){var s=e.call(this,t,i)||this;return s.src=i.currentSrc||i.src,s.intrinsicWidth=i.naturalWidth,s.intrinsicHeight=i.naturalHeight,s.context.cache.addImage(s.src),s}return op(t,e),t}(vm),Zm=function(e){function t(t,i){var s=e.call(this,t,i)||this;return s.canvas=i,s.intrinsicWidth=i.width,s.intrinsicHeight=i.height,s}return op(t,e),t}(vm),qm=function(e){function t(t,i){var s=e.call(this,t,i)||this,r=new XMLSerializer,n=hp(t,i);return i.setAttribute("width",n.width+"px"),i.setAttribute("height",n.height+"px"),s.svg="data:image/svg+xml,"+encodeURIComponent(r.serializeToString(i)),s.intrinsicWidth=i.width.baseVal.value,s.intrinsicHeight=i.height.baseVal.value,s.context.cache.addImage(s.svg),s}return op(t,e),t}(vm),$m=function(e){function t(t,i){var s=e.call(this,t,i)||this;return s.value=i.value,s}return op(t,e),t}(vm),e_=function(e){function t(t,i){var s=e.call(this,t,i)||this;return s.start=i.start,s.reversed="boolean"==typeof i.reversed&&!0===i.reversed,s}return op(t,e),t}(vm),t_=[{type:15,flags:0,unit:"px",number:3}],i_=[{type:16,flags:0,number:50}],s_="password",r_=function(e){function t(t,i){var s,r=e.call(this,t,i)||this;switch(r.type=i.type.toLowerCase(),r.checked=i.checked,r.value=function(e){var t=e.type===s_?new Array(e.value.length+1).join("•"):e.value;return 0===t.length?e.placeholder||"":t}(i),"checkbox"!==r.type&&"radio"!==r.type||(r.styles.backgroundColor=3739148031,r.styles.borderTopColor=r.styles.borderRightColor=r.styles.borderBottomColor=r.styles.borderLeftColor=2779096575,r.styles.borderTopWidth=r.styles.borderRightWidth=r.styles.borderBottomWidth=r.styles.borderLeftWidth=1,r.styles.borderTopStyle=r.styles.borderRightStyle=r.styles.borderBottomStyle=r.styles.borderLeftStyle=1,r.styles.backgroundClip=[0],r.styles.backgroundOrigin=[0],r.bounds=(s=r.bounds).width>s.height?new cp(s.left+(s.width-s.height)/2,s.top,s.height,s.height):s.width0)s.textNodes.push(new Wm(t,n,s.styles));else if(f_(n))if(k_(n)&&n.assignedNodes)n.assignedNodes().forEach((function(i){return e(t,i,s,r)}));else{var a=A_(t,n);a.styles.isVisible()&&(h_(n,a,r)?a.flags|=4:d_(a.styles)&&(a.flags|=2),-1!==l_.indexOf(n.tagName)&&(a.flags|=8),s.elements.push(a),n.slot,n.shadowRoot?e(t,n.shadowRoot,a,r):F_(n)||b_(n)||E_(n)||e(t,n,a,r))}},A_=function(e,t){return P_(t)?new Ym(e,t):B_(t)?new Zm(e,t):b_(t)?new qm(e,t):m_(t)?new $m(e,t):__(t)?new e_(e,t):y_(t)?new r_(e,t):E_(t)?new n_(e,t):F_(t)?new o_(e,t):C_(t)?new a_(e,t):new vm(e,t)},c_=function(e,t){var i=A_(e,t);return i.flags|=4,u_(e,t,i,i),i},h_=function(e,t,i){return t.styles.isPositionedWithZIndex()||t.styles.opacity<1||t.styles.isTransformed()||w_(e)&&i.styles.isTransparent()},d_=function(e){return e.isPositioned()||e.isFloating()},p_=function(e){return e.nodeType===Node.TEXT_NODE},f_=function(e){return e.nodeType===Node.ELEMENT_NODE},v_=function(e){return f_(e)&&void 0!==e.style&&!g_(e)},g_=function(e){return"object"===B(e.className)},m_=function(e){return"LI"===e.tagName},__=function(e){return"OL"===e.tagName},y_=function(e){return"INPUT"===e.tagName},b_=function(e){return"svg"===e.tagName},w_=function(e){return"BODY"===e.tagName},B_=function(e){return"CANVAS"===e.tagName},x_=function(e){return"VIDEO"===e.tagName},P_=function(e){return"IMG"===e.tagName},C_=function(e){return"IFRAME"===e.tagName},M_=function(e){return"STYLE"===e.tagName},F_=function(e){return"TEXTAREA"===e.tagName},E_=function(e){return"SELECT"===e.tagName},k_=function(e){return"SLOT"===e.tagName},I_=function(e){return e.tagName.indexOf("-")>0},D_=function(){function e(){this.counters={}}return e.prototype.getCounterValue=function(e){var t=this.counters[e];return t&&t.length?t[t.length-1]:1},e.prototype.getCounterValues=function(e){var t=this.counters[e];return t||[]},e.prototype.pop=function(e){var t=this;e.forEach((function(e){return t.counters[e].pop()}))},e.prototype.parse=function(e){var t=this,i=e.counterIncrement,s=e.counterReset,r=!0;null!==i&&i.forEach((function(e){var i=t.counters[e.counter];i&&0!==e.increment&&(r=!1,i.length||i.push(1),i[Math.max(0,i.length-1)]+=e.increment)}));var n=[];return r&&s.forEach((function(e){var i=t.counters[e.counter];n.push(e.counter),i||(i=t.counters[e.counter]=[]),i.push(e.reset)})),n},e}(),S_={integers:[1e3,900,500,400,100,90,50,40,10,9,5,4,1],values:["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]},T_={integers:[9e3,8e3,7e3,6e3,5e3,4e3,3e3,2e3,1e3,900,800,700,600,500,400,300,200,100,90,80,70,60,50,40,30,20,10,9,8,7,6,5,4,3,2,1],values:["Ք","Փ","Ւ","Ց","Ր","Տ","Վ","Ս","Ռ","Ջ","Պ","Չ","Ո","Շ","Ն","Յ","Մ","Ճ","Ղ","Ձ","Հ","Կ","Ծ","Խ","Լ","Ի","Ժ","Թ","Ը","Է","Զ","Ե","Դ","Գ","Բ","Ա"]},R_={integers:[1e4,9e3,8e3,7e3,6e3,5e3,4e3,3e3,2e3,1e3,400,300,200,100,90,80,70,60,50,40,30,20,19,18,17,16,15,10,9,8,7,6,5,4,3,2,1],values:["י׳","ט׳","ח׳","ז׳","ו׳","ה׳","ד׳","ג׳","ב׳","א׳","ת","ש","ר","ק","צ","פ","ע","ס","נ","מ","ל","כ","יט","יח","יז","טז","טו","י","ט","ח","ז","ו","ה","ד","ג","ב","א"]},L_={integers:[1e4,9e3,8e3,7e3,6e3,5e3,4e3,3e3,2e3,1e3,900,800,700,600,500,400,300,200,100,90,80,70,60,50,40,30,20,10,9,8,7,6,5,4,3,2,1],values:["ჵ","ჰ","ჯ","ჴ","ხ","ჭ","წ","ძ","ც","ჩ","შ","ყ","ღ","ქ","ფ","ჳ","ტ","ს","რ","ჟ","პ","ო","ჲ","ნ","მ","ლ","კ","ი","თ","ჱ","ზ","ვ","ე","დ","გ","ბ","ა"]},U_=function(e,t,i,s,r,n){return ei?H_(e,r,n.length>0):s.integers.reduce((function(t,i,r){for(;e>=i;)e-=i,t+=s.values[r];return t}),"")+n},O_=function(e,t,i,s){var r="";do{i||e--,r=s(e)+r,e/=t}while(e*t>=t);return r},N_=function(e,t,i,s,r){var n=i-t+1;return(e<0?"-":"")+(O_(Math.abs(e),n,s,(function(e){return pp(Math.floor(e%n)+t)}))+r)},Q_=function(e,t,i){void 0===i&&(i=". ");var s=t.length;return O_(Math.abs(e),s,!1,(function(e){return t[Math.floor(e%s)]}))+i},V_=function(e,t,i,s,r,n){if(e<-9999||e>9999)return H_(e,4,r.length>0);var o=Math.abs(e),a=r;if(0===o)return t[0]+a;for(var l=0;o>0&&l<=4;l++){var u=o%10;0===u&&em(n,1)&&""!==a?a=t[u]+a:u>1||1===u&&0===l||1===u&&1===l&&em(n,2)||1===u&&1===l&&em(n,4)&&e>100||1===u&&l>1&&em(n,8)?a=t[u]+(l>0?i[l-1]:"")+a:1===u&&l>0&&(a=i[l-1]+a),o=Math.floor(o/10)}return(e<0?s:"")+a},H_=function(e,t,i){var s=i?". ":"",r=i?"、":"",n=i?", ":"",o=i?" ":"";switch(t){case 0:return"•"+o;case 1:return"◦"+o;case 2:return"◾"+o;case 5:var a=N_(e,48,57,!0,s);return a.length<4?"0"+a:a;case 4:return Q_(e,"〇一二三四五六七八九",r);case 6:return U_(e,1,3999,S_,3,s).toLowerCase();case 7:return U_(e,1,3999,S_,3,s);case 8:return N_(e,945,969,!1,s);case 9:return N_(e,97,122,!1,s);case 10:return N_(e,65,90,!1,s);case 11:return N_(e,1632,1641,!0,s);case 12:case 49:return U_(e,1,9999,T_,3,s);case 35:return U_(e,1,9999,T_,3,s).toLowerCase();case 13:return N_(e,2534,2543,!0,s);case 14:case 30:return N_(e,6112,6121,!0,s);case 15:return Q_(e,"子丑寅卯辰巳午未申酉戌亥",r);case 16:return Q_(e,"甲乙丙丁戊己庚辛壬癸",r);case 17:case 48:return V_(e,"零一二三四五六七八九","十百千萬","負",r,14);case 47:return V_(e,"零壹貳參肆伍陸柒捌玖","拾佰仟萬","負",r,15);case 42:return V_(e,"零一二三四五六七八九","十百千萬","负",r,14);case 41:return V_(e,"零壹贰叁肆伍陆柒捌玖","拾佰仟萬","负",r,15);case 26:return V_(e,"〇一二三四五六七八九","十百千万","マイナス",r,0);case 25:return V_(e,"零壱弐参四伍六七八九","拾百千万","マイナス",r,7);case 31:return V_(e,"영일이삼사오육칠팔구","십백천만","마이너스",n,7);case 33:return V_(e,"零一二三四五六七八九","十百千萬","마이너스",n,0);case 32:return V_(e,"零壹貳參四五六七八九","拾百千","마이너스",n,7);case 18:return N_(e,2406,2415,!0,s);case 20:return U_(e,1,19999,L_,3,s);case 21:return N_(e,2790,2799,!0,s);case 22:return N_(e,2662,2671,!0,s);case 22:return U_(e,1,10999,R_,3,s);case 23:return Q_(e,"あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわゐゑをん");case 24:return Q_(e,"いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす");case 27:return N_(e,3302,3311,!0,s);case 28:return Q_(e,"アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヰヱヲン",r);case 29:return Q_(e,"イロハニホヘトチリヌルヲワカヨタレソツネナラムウヰノオクヤマケフコエテアサキユメミシヱヒモセス",r);case 34:return N_(e,3792,3801,!0,s);case 37:return N_(e,6160,6169,!0,s);case 38:return N_(e,4160,4169,!0,s);case 39:return N_(e,2918,2927,!0,s);case 40:return N_(e,1776,1785,!0,s);case 43:return N_(e,3046,3055,!0,s);case 44:return N_(e,3174,3183,!0,s);case 45:return N_(e,3664,3673,!0,s);case 46:return N_(e,3872,3881,!0,s);default:return N_(e,48,57,!0,s)}},j_=function(){function e(e,t,i){if(this.context=e,this.options=i,this.scrolledElements=[],this.referenceElement=t,this.counters=new D_,this.quoteDepth=0,!t.ownerDocument)throw new Error("Cloned element does not have an owner document");this.documentElement=this.cloneNode(t.ownerDocument.documentElement,!1)}return e.prototype.toIFrame=function(e,t){var i=this,s=z_(e,t);if(!s.contentWindow)return Promise.reject("Unable to find iframe window");var r=e.defaultView.pageXOffset,n=e.defaultView.pageYOffset,o=s.contentWindow,a=o.document,l=X_(s).then((function(){return lp(i,void 0,void 0,(function(){var e,i;return up(this,(function(r){switch(r.label){case 0:return this.scrolledElements.forEach($_),o&&(o.scrollTo(t.left,t.top),!/(iPad|iPhone|iPod)/g.test(navigator.userAgent)||o.scrollY===t.top&&o.scrollX===t.left||(this.context.logger.warn("Unable to restore scroll position for cloned document"),this.context.windowBounds=this.context.windowBounds.add(o.scrollX-t.left,o.scrollY-t.top,0,0))),e=this.options.onclone,void 0===(i=this.clonedReferenceElement)?[2,Promise.reject("Error finding the "+this.referenceElement.nodeName+" in the cloned document")]:a.fonts&&a.fonts.ready?[4,a.fonts.ready]:[3,2];case 1:r.sent(),r.label=2;case 2:return/(AppleWebKit)/g.test(navigator.userAgent)?[4,K_(a)]:[3,4];case 3:r.sent(),r.label=4;case 4:return"function"==typeof e?[2,Promise.resolve().then((function(){return e(a,i)})).then((function(){return s}))]:[2,s]}}))}))}));return a.open(),a.write(Z_(document.doctype)+""),q_(this.referenceElement.ownerDocument,r,n),a.replaceChild(a.adoptNode(this.documentElement),a.documentElement),a.close(),l},e.prototype.createElementClone=function(e){if(fm(e,2),B_(e))return this.createCanvasClone(e);if(x_(e))return this.createVideoClone(e);if(M_(e))return this.createStyleClone(e);var t=e.cloneNode(!1);return P_(t)&&(P_(e)&&e.currentSrc&&e.currentSrc!==e.src&&(t.src=e.currentSrc,t.srcset=""),"lazy"===t.loading&&(t.loading="eager")),I_(t)?this.createCustomElementClone(t):t},e.prototype.createCustomElementClone=function(e){var t=document.createElement("html2canvascustomelement");return Y_(e.style,t),t},e.prototype.createStyleClone=function(e){try{var t=e.sheet;if(t&&t.cssRules){var i=[].slice.call(t.cssRules,0).reduce((function(e,t){return t&&"string"==typeof t.cssText?e+t.cssText:e}),""),s=e.cloneNode(!1);return s.textContent=i,s}}catch(e){if(this.context.logger.error("Unable to access cssRules property",e),"SecurityError"!==e.name)throw e}return e.cloneNode(!1)},e.prototype.createCanvasClone=function(e){var t;if(this.options.inlineImages&&e.ownerDocument){var i=e.ownerDocument.createElement("img");try{return i.src=e.toDataURL(),i}catch(t){this.context.logger.info("Unable to inline canvas contents, canvas is tainted",e)}}var s=e.cloneNode(!1);try{s.width=e.width,s.height=e.height;var r=e.getContext("2d"),n=s.getContext("2d");if(n)if(!this.options.allowTaint&&r)n.putImageData(r.getImageData(0,0,e.width,e.height),0,0);else{var o=null!==(t=e.getContext("webgl2"))&&void 0!==t?t:e.getContext("webgl");if(o){var a=o.getContextAttributes();!1===(null==a?void 0:a.preserveDrawingBuffer)&&this.context.logger.warn("Unable to clone WebGL context as it has preserveDrawingBuffer=false",e)}n.drawImage(e,0,0)}return s}catch(t){this.context.logger.info("Unable to clone canvas as it is tainted",e)}return s},e.prototype.createVideoClone=function(e){var t=e.ownerDocument.createElement("canvas");t.width=e.offsetWidth,t.height=e.offsetHeight;var i=t.getContext("2d");try{return i&&(i.drawImage(e,0,0,t.width,t.height),this.options.allowTaint||i.getImageData(0,0,t.width,t.height)),t}catch(t){this.context.logger.info("Unable to clone video as it is tainted",e)}var s=e.ownerDocument.createElement("canvas");return s.width=e.offsetWidth,s.height=e.offsetHeight,s},e.prototype.appendChildNode=function(e,t,i){f_(t)&&(function(e){return"SCRIPT"===e.tagName}(t)||t.hasAttribute("data-html2canvas-ignore")||"function"==typeof this.options.ignoreElements&&this.options.ignoreElements(t))||this.options.copyStyles&&f_(t)&&M_(t)||e.appendChild(this.cloneNode(t,i))},e.prototype.cloneChildNodes=function(e,t,i){for(var s=this,r=e.shadowRoot?e.shadowRoot.firstChild:e.firstChild;r;r=r.nextSibling)if(f_(r)&&k_(r)&&"function"==typeof r.assignedNodes){var n=r.assignedNodes();n.length&&n.forEach((function(e){return s.appendChildNode(t,e,i)}))}else this.appendChildNode(t,r,i)},e.prototype.cloneNode=function(e,t){if(p_(e))return document.createTextNode(e.data);if(!e.ownerDocument)return e.cloneNode(!1);var i=e.ownerDocument.defaultView;if(i&&f_(e)&&(v_(e)||g_(e))){var s=this.createElementClone(e);s.style.transitionProperty="none";var r=i.getComputedStyle(e),n=i.getComputedStyle(e,":before"),o=i.getComputedStyle(e,":after");this.referenceElement===e&&v_(s)&&(this.clonedReferenceElement=s),w_(s)&&iy(s);var a=this.counters.parse(new dm(this.context,r)),l=this.resolvePseudoContent(e,s,n,Pm.BEFORE);I_(e)&&(t=!0),x_(e)||this.cloneChildNodes(e,s,t),l&&s.insertBefore(l,s.firstChild);var u=this.resolvePseudoContent(e,s,o,Pm.AFTER);return u&&s.appendChild(u),this.counters.pop(a),(r&&(this.options.copyStyles||g_(e))&&!C_(e)||t)&&Y_(r,s),0===e.scrollTop&&0===e.scrollLeft||this.scrolledElements.push([s,e.scrollLeft,e.scrollTop]),(F_(e)||E_(e))&&(F_(s)||E_(s))&&(s.value=e.value),s}return e.cloneNode(!1)},e.prototype.resolvePseudoContent=function(e,t,i,s){var r=this;if(i){var n=i.content,o=t.ownerDocument;if(o&&n&&"none"!==n&&"-moz-alt-content"!==n&&"none"!==i.display){this.counters.parse(new dm(this.context,i));var a=new hm(this.context,i),l=o.createElement("html2canvaspseudoelement");Y_(i,l),a.content.forEach((function(t){if(0===t.type)l.appendChild(o.createTextNode(t.value));else if(22===t.type){var i=o.createElement("img");i.src=t.value,i.style.opacity="1",l.appendChild(i)}else if(18===t.type){if("attr"===t.name){var s=t.values.filter(Wf);s.length&&l.appendChild(o.createTextNode(e.getAttribute(s[0].value)||""))}else if("counter"===t.name){var n=t.values.filter(Yf),u=n[0],A=n[1];if(u&&Wf(u)){var c=r.counters.getCounterValue(u.value),h=A&&Wf(A)?yg.parse(r.context,A.value):3;l.appendChild(o.createTextNode(H_(c,h,!1)))}}else if("counters"===t.name){var d=t.values.filter(Yf),p=(u=d[0],d[1]);A=d[2];if(u&&Wf(u)){var f=r.counters.getCounterValues(u.value),v=A&&Wf(A)?yg.parse(r.context,A.value):3,g=p&&0===p.type?p.value:"",m=f.map((function(e){return H_(e,v,!1)})).join(g);l.appendChild(o.createTextNode(m))}}}else if(20===t.type)switch(t.value){case"open-quote":l.appendChild(o.createTextNode(om(a.quotes,r.quoteDepth++,!0)));break;case"close-quote":l.appendChild(o.createTextNode(om(a.quotes,--r.quoteDepth,!1)));break;default:l.appendChild(o.createTextNode(t.value))}})),l.className=ey+" "+ty;var u=s===Pm.BEFORE?" "+ey:" "+ty;return g_(t)?t.className.baseValue+=u:t.className+=u,l}}},e.destroy=function(e){return!!e.parentNode&&(e.parentNode.removeChild(e),!0)},e}();!function(e){e[e.BEFORE=0]="BEFORE",e[e.AFTER=1]="AFTER"}(Pm||(Pm={}));var G_,z_=function(e,t){var i=e.createElement("iframe");return i.className="html2canvas-container",i.style.visibility="hidden",i.style.position="fixed",i.style.left="-10000px",i.style.top="0px",i.style.border="0",i.width=t.width.toString(),i.height=t.height.toString(),i.scrolling="no",i.setAttribute("data-html2canvas-ignore","true"),e.body.appendChild(i),i},W_=function(e){return new Promise((function(t){e.complete?t():e.src?(e.onload=t,e.onerror=t):t()}))},K_=function(e){return Promise.all([].slice.call(e.images,0).map(W_))},X_=function(e){return new Promise((function(t,i){var s=e.contentWindow;if(!s)return i("No window assigned for iframe");var r=s.document;s.onload=e.onload=function(){s.onload=e.onload=null;var i=setInterval((function(){r.body.childNodes.length>0&&"complete"===r.readyState&&(clearInterval(i),t(e))}),50)}}))},J_=["all","d","content"],Y_=function(e,t){for(var i=e.length-1;i>=0;i--){var s=e.item(i);-1===J_.indexOf(s)&&t.style.setProperty(s,e.getPropertyValue(s))}return t},Z_=function(e){var t="";return e&&(t+=""),t},q_=function(e,t,i){e&&e.defaultView&&(t!==e.defaultView.pageXOffset||i!==e.defaultView.pageYOffset)&&e.defaultView.scrollTo(t,i)},$_=function(e){var t=e[0],i=e[1],s=e[2];t.scrollLeft=i,t.scrollTop=s},ey="___html2canvas___pseudoelement_before",ty="___html2canvas___pseudoelement_after",iy=function(e){sy(e,"."+ey+':before{\n content: "" !important;\n display: none !important;\n}\n .'+ty+':after{\n content: "" !important;\n display: none !important;\n}')},sy=function(e,t){var i=e.ownerDocument;if(i){var s=i.createElement("style");s.textContent=t,e.appendChild(s)}},ry=function(){function e(){}return e.getOrigin=function(t){var i=e._link;return i?(i.href=t,i.href=i.href,i.protocol+i.hostname+i.port):"about:blank"},e.isSameOrigin=function(t){return e.getOrigin(t)===e._origin},e.setContext=function(t){e._link=t.document.createElement("a"),e._origin=e.getOrigin(t.location.href)},e._origin="about:blank",e}(),ny=function(){function e(e,t){this.context=e,this._options=t,this._cache={}}return e.prototype.addImage=function(e){var t=Promise.resolve();return this.has(e)?t:hy(e)||uy(e)?((this._cache[e]=this.loadImage(e)).catch((function(){})),t):t},e.prototype.match=function(e){return this._cache[e]},e.prototype.loadImage=function(e){return lp(this,void 0,void 0,(function(){var t,i,s,r,n=this;return up(this,(function(o){switch(o.label){case 0:return t=ry.isSameOrigin(e),i=!Ay(e)&&!0===this._options.useCORS&&Om.SUPPORT_CORS_IMAGES&&!t,s=!Ay(e)&&!t&&!hy(e)&&"string"==typeof this._options.proxy&&Om.SUPPORT_CORS_XHR&&!i,t||!1!==this._options.allowTaint||Ay(e)||hy(e)||s||i?(r=e,s?[4,this.proxy(r)]:[3,2]):[2];case 1:r=o.sent(),o.label=2;case 2:return this.context.logger.debug("Added image "+e.substring(0,256)),[4,new Promise((function(e,t){var s=new Image;s.onload=function(){return e(s)},s.onerror=t,(cy(r)||i)&&(s.crossOrigin="anonymous"),s.src=r,!0===s.complete&&setTimeout((function(){return e(s)}),500),n._options.imageTimeout>0&&setTimeout((function(){return t("Timed out ("+n._options.imageTimeout+"ms) loading image")}),n._options.imageTimeout)}))];case 3:return[2,o.sent()]}}))}))},e.prototype.has=function(e){return void 0!==this._cache[e]},e.prototype.keys=function(){return Promise.resolve(Object.keys(this._cache))},e.prototype.proxy=function(e){var t=this,i=this._options.proxy;if(!i)throw new Error("No proxy defined");var s=e.substring(0,256);return new Promise((function(r,n){var o=Om.SUPPORT_RESPONSE_TYPE?"blob":"text",a=new XMLHttpRequest;a.onload=function(){if(200===a.status)if("text"===o)r(a.response);else{var e=new FileReader;e.addEventListener("load",(function(){return r(e.result)}),!1),e.addEventListener("error",(function(e){return n(e)}),!1),e.readAsDataURL(a.response)}else n("Failed to proxy resource "+s+" with status code "+a.status)},a.onerror=n;var l=i.indexOf("?")>-1?"&":"?";if(a.open("GET",""+i+l+"url="+encodeURIComponent(e)+"&responseType="+o),"text"!==o&&a instanceof XMLHttpRequest&&(a.responseType=o),t._options.imageTimeout){var u=t._options.imageTimeout;a.timeout=u,a.ontimeout=function(){return n("Timed out ("+u+"ms) proxying "+s)}}a.send()}))},e}(),oy=/^data:image\/svg\+xml/i,ay=/^data:image\/.*;base64,/i,ly=/^data:image\/.*/i,uy=function(e){return Om.SUPPORT_SVG_DRAWING||!dy(e)},Ay=function(e){return ly.test(e)},cy=function(e){return ay.test(e)},hy=function(e){return"blob"===e.substr(0,4)},dy=function(e){return"svg"===e.substr(-3).toLowerCase()||oy.test(e)},py=function(){function e(e,t){this.type=0,this.x=e,this.y=t}return e.prototype.add=function(t,i){return new e(this.x+t,this.y+i)},e}(),fy=function(e,t,i){return new py(e.x+(t.x-e.x)*i,e.y+(t.y-e.y)*i)},vy=function(){function e(e,t,i,s){this.type=1,this.start=e,this.startControl=t,this.endControl=i,this.end=s}return e.prototype.subdivide=function(t,i){var s=fy(this.start,this.startControl,t),r=fy(this.startControl,this.endControl,t),n=fy(this.endControl,this.end,t),o=fy(s,r,t),a=fy(r,n,t),l=fy(o,a,t);return i?new e(this.start,s,o,l):new e(l,a,n,this.end)},e.prototype.add=function(t,i){return new e(this.start.add(t,i),this.startControl.add(t,i),this.endControl.add(t,i),this.end.add(t,i))},e.prototype.reverse=function(){return new e(this.end,this.endControl,this.startControl,this.start)},e}(),gy=function(e){return 1===e.type},my=function(e){var t=e.styles,i=e.bounds,s=nv(t.borderTopLeftRadius,i.width,i.height),r=s[0],n=s[1],o=nv(t.borderTopRightRadius,i.width,i.height),a=o[0],l=o[1],u=nv(t.borderBottomRightRadius,i.width,i.height),A=u[0],c=u[1],h=nv(t.borderBottomLeftRadius,i.width,i.height),d=h[0],p=h[1],f=[];f.push((r+a)/i.width),f.push((d+A)/i.width),f.push((n+p)/i.height),f.push((l+c)/i.height);var v=Math.max.apply(Math,f);v>1&&(r/=v,n/=v,a/=v,l/=v,A/=v,c/=v,d/=v,p/=v);var g=i.width-a,m=i.height-c,_=i.width-A,y=i.height-p,b=t.borderTopWidth,w=t.borderRightWidth,B=t.borderBottomWidth,x=t.borderLeftWidth,P=ov(t.paddingTop,e.bounds.width),C=ov(t.paddingRight,e.bounds.width),M=ov(t.paddingBottom,e.bounds.width),F=ov(t.paddingLeft,e.bounds.width);this.topLeftBorderDoubleOuterBox=r>0||n>0?_y(i.left+x/3,i.top+b/3,r-x/3,n-b/3,G_.TOP_LEFT):new py(i.left+x/3,i.top+b/3),this.topRightBorderDoubleOuterBox=r>0||n>0?_y(i.left+g,i.top+b/3,a-w/3,l-b/3,G_.TOP_RIGHT):new py(i.left+i.width-w/3,i.top+b/3),this.bottomRightBorderDoubleOuterBox=A>0||c>0?_y(i.left+_,i.top+m,A-w/3,c-B/3,G_.BOTTOM_RIGHT):new py(i.left+i.width-w/3,i.top+i.height-B/3),this.bottomLeftBorderDoubleOuterBox=d>0||p>0?_y(i.left+x/3,i.top+y,d-x/3,p-B/3,G_.BOTTOM_LEFT):new py(i.left+x/3,i.top+i.height-B/3),this.topLeftBorderDoubleInnerBox=r>0||n>0?_y(i.left+2*x/3,i.top+2*b/3,r-2*x/3,n-2*b/3,G_.TOP_LEFT):new py(i.left+2*x/3,i.top+2*b/3),this.topRightBorderDoubleInnerBox=r>0||n>0?_y(i.left+g,i.top+2*b/3,a-2*w/3,l-2*b/3,G_.TOP_RIGHT):new py(i.left+i.width-2*w/3,i.top+2*b/3),this.bottomRightBorderDoubleInnerBox=A>0||c>0?_y(i.left+_,i.top+m,A-2*w/3,c-2*B/3,G_.BOTTOM_RIGHT):new py(i.left+i.width-2*w/3,i.top+i.height-2*B/3),this.bottomLeftBorderDoubleInnerBox=d>0||p>0?_y(i.left+2*x/3,i.top+y,d-2*x/3,p-2*B/3,G_.BOTTOM_LEFT):new py(i.left+2*x/3,i.top+i.height-2*B/3),this.topLeftBorderStroke=r>0||n>0?_y(i.left+x/2,i.top+b/2,r-x/2,n-b/2,G_.TOP_LEFT):new py(i.left+x/2,i.top+b/2),this.topRightBorderStroke=r>0||n>0?_y(i.left+g,i.top+b/2,a-w/2,l-b/2,G_.TOP_RIGHT):new py(i.left+i.width-w/2,i.top+b/2),this.bottomRightBorderStroke=A>0||c>0?_y(i.left+_,i.top+m,A-w/2,c-B/2,G_.BOTTOM_RIGHT):new py(i.left+i.width-w/2,i.top+i.height-B/2),this.bottomLeftBorderStroke=d>0||p>0?_y(i.left+x/2,i.top+y,d-x/2,p-B/2,G_.BOTTOM_LEFT):new py(i.left+x/2,i.top+i.height-B/2),this.topLeftBorderBox=r>0||n>0?_y(i.left,i.top,r,n,G_.TOP_LEFT):new py(i.left,i.top),this.topRightBorderBox=a>0||l>0?_y(i.left+g,i.top,a,l,G_.TOP_RIGHT):new py(i.left+i.width,i.top),this.bottomRightBorderBox=A>0||c>0?_y(i.left+_,i.top+m,A,c,G_.BOTTOM_RIGHT):new py(i.left+i.width,i.top+i.height),this.bottomLeftBorderBox=d>0||p>0?_y(i.left,i.top+y,d,p,G_.BOTTOM_LEFT):new py(i.left,i.top+i.height),this.topLeftPaddingBox=r>0||n>0?_y(i.left+x,i.top+b,Math.max(0,r-x),Math.max(0,n-b),G_.TOP_LEFT):new py(i.left+x,i.top+b),this.topRightPaddingBox=a>0||l>0?_y(i.left+Math.min(g,i.width-w),i.top+b,g>i.width+w?0:Math.max(0,a-w),Math.max(0,l-b),G_.TOP_RIGHT):new py(i.left+i.width-w,i.top+b),this.bottomRightPaddingBox=A>0||c>0?_y(i.left+Math.min(_,i.width-x),i.top+Math.min(m,i.height-B),Math.max(0,A-w),Math.max(0,c-B),G_.BOTTOM_RIGHT):new py(i.left+i.width-w,i.top+i.height-B),this.bottomLeftPaddingBox=d>0||p>0?_y(i.left+x,i.top+Math.min(y,i.height-B),Math.max(0,d-x),Math.max(0,p-B),G_.BOTTOM_LEFT):new py(i.left+x,i.top+i.height-B),this.topLeftContentBox=r>0||n>0?_y(i.left+x+F,i.top+b+P,Math.max(0,r-(x+F)),Math.max(0,n-(b+P)),G_.TOP_LEFT):new py(i.left+x+F,i.top+b+P),this.topRightContentBox=a>0||l>0?_y(i.left+Math.min(g,i.width+x+F),i.top+b+P,g>i.width+x+F?0:a-x+F,l-(b+P),G_.TOP_RIGHT):new py(i.left+i.width-(w+C),i.top+b+P),this.bottomRightContentBox=A>0||c>0?_y(i.left+Math.min(_,i.width-(x+F)),i.top+Math.min(m,i.height+b+P),Math.max(0,A-(w+C)),c-(B+M),G_.BOTTOM_RIGHT):new py(i.left+i.width-(w+C),i.top+i.height-(B+M)),this.bottomLeftContentBox=d>0||p>0?_y(i.left+x+F,i.top+y,Math.max(0,d-(x+F)),p-(B+M),G_.BOTTOM_LEFT):new py(i.left+x+F,i.top+i.height-(B+M))};!function(e){e[e.TOP_LEFT=0]="TOP_LEFT",e[e.TOP_RIGHT=1]="TOP_RIGHT",e[e.BOTTOM_RIGHT=2]="BOTTOM_RIGHT",e[e.BOTTOM_LEFT=3]="BOTTOM_LEFT"}(G_||(G_={}));var _y=function(e,t,i,s,r){var n=(Math.sqrt(2)-1)/3*4,o=i*n,a=s*n,l=e+i,u=t+s;switch(r){case G_.TOP_LEFT:return new vy(new py(e,u),new py(e,u-a),new py(l-o,t),new py(l,t));case G_.TOP_RIGHT:return new vy(new py(e,t),new py(e+o,t),new py(l,u-a),new py(l,u));case G_.BOTTOM_RIGHT:return new vy(new py(l,t),new py(l,t+a),new py(e+o,u),new py(e,u));case G_.BOTTOM_LEFT:default:return new vy(new py(l,u),new py(l-o,u),new py(e,t+a),new py(e,t))}},yy=function(e){return[e.topLeftBorderBox,e.topRightBorderBox,e.bottomRightBorderBox,e.bottomLeftBorderBox]},by=function(e){return[e.topLeftPaddingBox,e.topRightPaddingBox,e.bottomRightPaddingBox,e.bottomLeftPaddingBox]},wy=function(e,t,i){this.offsetX=e,this.offsetY=t,this.matrix=i,this.type=0,this.target=6},By=function(e,t){this.path=e,this.target=t,this.type=1},xy=function(e){this.opacity=e,this.type=2,this.target=6},Py=function(e){return 1===e.type},Cy=function(e,t){return e.length===t.length&&e.some((function(e,i){return e===t[i]}))},My=function(e){this.element=e,this.inlineLevel=[],this.nonInlineLevel=[],this.negativeZIndex=[],this.zeroOrAutoZIndexOrTransformedOrOpacity=[],this.positiveZIndex=[],this.nonPositionedFloats=[],this.nonPositionedInlineLevel=[]},Fy=function(){function e(e,t){if(this.container=e,this.parent=t,this.effects=[],this.curves=new my(this.container),this.container.styles.opacity<1&&this.effects.push(new xy(this.container.styles.opacity)),null!==this.container.styles.transform){var i=this.container.bounds.left+this.container.styles.transformOrigin[0].number,s=this.container.bounds.top+this.container.styles.transformOrigin[1].number,r=this.container.styles.transform;this.effects.push(new wy(i,s,r))}if(0!==this.container.styles.overflowX){var n=yy(this.curves),o=by(this.curves);Cy(n,o)?this.effects.push(new By(n,6)):(this.effects.push(new By(n,2)),this.effects.push(new By(o,4)))}}return e.prototype.getEffects=function(e){for(var t=-1===[2,3].indexOf(this.container.styles.position),i=this.parent,s=this.effects.slice(0);i;){var r=i.effects.filter((function(e){return!Py(e)}));if(t||0!==i.container.styles.position||!i.parent){if(s.unshift.apply(s,r),t=-1===[2,3].indexOf(i.container.styles.position),0!==i.container.styles.overflowX){var n=yy(i.curves),o=by(i.curves);Cy(n,o)||s.unshift(new By(o,6))}}else s.unshift.apply(s,r);i=i.parent}return s.filter((function(t){return em(t.target,e)}))},e}(),Ey=function e(t,i,s,r){t.container.elements.forEach((function(n){var o=em(n.flags,4),a=em(n.flags,2),l=new Fy(n,t);em(n.styles.display,2048)&&r.push(l);var u=em(n.flags,8)?[]:r;if(o||a){var A=o||n.styles.isPositioned()?s:i,c=new My(l);if(n.styles.isPositioned()||n.styles.opacity<1||n.styles.isTransformed()){var h=n.styles.zIndex.order;if(h<0){var d=0;A.negativeZIndex.some((function(e,t){return h>e.element.container.styles.zIndex.order?(d=t,!1):d>0})),A.negativeZIndex.splice(d,0,c)}else if(h>0){var p=0;A.positiveZIndex.some((function(e,t){return h>=e.element.container.styles.zIndex.order?(p=t+1,!1):p>0})),A.positiveZIndex.splice(p,0,c)}else A.zeroOrAutoZIndexOrTransformedOrOpacity.push(c)}else n.styles.isFloating()?A.nonPositionedFloats.push(c):A.nonPositionedInlineLevel.push(c);e(l,c,o?c:s,u)}else n.styles.isInlineLevel()?i.inlineLevel.push(l):i.nonInlineLevel.push(l),e(l,i,s,u);em(n.flags,8)&&ky(n,u)}))},ky=function(e,t){for(var i=e instanceof e_?e.start:1,s=e instanceof e_&&e.reversed,r=0;r0&&e.intrinsicHeight>0){var s=Ly(e),r=by(t);this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.drawImage(i,0,0,e.intrinsicWidth,e.intrinsicHeight,s.left,s.top,s.width,s.height),this.ctx.restore()}},t.prototype.renderNodeContent=function(e){return lp(this,void 0,void 0,(function(){var i,s,r,n,o,a,l,u,A,c,h,d,p,f,v,g,m,_;return up(this,(function(y){switch(y.label){case 0:this.applyEffects(e.getEffects(4)),i=e.container,s=e.curves,r=i.styles,n=0,o=i.textNodes,y.label=1;case 1:return n0&&B>0&&(g=s.ctx.createPattern(p,"repeat"),s.renderRepeat(_,g,P,C))):function(e){return 2===e.type}(i)&&(m=Uy(e,t,[null,null,null]),_=m[0],y=m[1],b=m[2],w=m[3],B=m[4],x=0===i.position.length?[sv]:i.position,P=ov(x[0],w),C=ov(x[x.length-1],B),M=function(e,t,i,s,r){var n=0,o=0;switch(e.size){case 0:0===e.shape?n=o=Math.min(Math.abs(t),Math.abs(t-s),Math.abs(i),Math.abs(i-r)):1===e.shape&&(n=Math.min(Math.abs(t),Math.abs(t-s)),o=Math.min(Math.abs(i),Math.abs(i-r)));break;case 2:if(0===e.shape)n=o=Math.min(Mv(t,i),Mv(t,i-r),Mv(t-s,i),Mv(t-s,i-r));else if(1===e.shape){var a=Math.min(Math.abs(i),Math.abs(i-r))/Math.min(Math.abs(t),Math.abs(t-s)),l=Fv(s,r,t,i,!0),u=l[0],A=l[1];o=a*(n=Mv(u-t,(A-i)/a))}break;case 1:0===e.shape?n=o=Math.max(Math.abs(t),Math.abs(t-s),Math.abs(i),Math.abs(i-r)):1===e.shape&&(n=Math.max(Math.abs(t),Math.abs(t-s)),o=Math.max(Math.abs(i),Math.abs(i-r)));break;case 3:if(0===e.shape)n=o=Math.max(Mv(t,i),Mv(t,i-r),Mv(t-s,i),Mv(t-s,i-r));else if(1===e.shape){a=Math.max(Math.abs(i),Math.abs(i-r))/Math.max(Math.abs(t),Math.abs(t-s));var c=Fv(s,r,t,i,!1);u=c[0],A=c[1],o=a*(n=Mv(u-t,(A-i)/a))}}return Array.isArray(e.size)&&(n=ov(e.size[0],s),o=2===e.size.length?ov(e.size[1],r):n),[n,o]}(i,P,C,w,B),F=M[0],E=M[1],F>0&&E>0&&(k=s.ctx.createRadialGradient(y+P,b+C,0,y+P,b+C,F),Pv(i.stops,2*F).forEach((function(e){return k.addColorStop(e.stop,dv(e.color))})),s.path(_),s.ctx.fillStyle=k,F!==E?(I=e.bounds.left+.5*e.bounds.width,D=e.bounds.top+.5*e.bounds.height,T=1/(S=E/F),s.ctx.save(),s.ctx.translate(I,D),s.ctx.transform(1,0,0,S,0,0),s.ctx.translate(-I,-D),s.ctx.fillRect(y,T*(b-D)+D,w,B*T),s.ctx.restore()):s.ctx.fill())),R.label=6;case 6:return t--,[2]}}))},s=this,r=0,n=e.styles.backgroundImage.slice(0).reverse(),a.label=1;case 1:return r0?2!==l.style?[3,5]:[4,this.renderDashedDottedBorder(l.color,l.width,n,e.curves,2)]:[3,11]:[3,13];case 4:return A.sent(),[3,11];case 5:return 3!==l.style?[3,7]:[4,this.renderDashedDottedBorder(l.color,l.width,n,e.curves,3)];case 6:return A.sent(),[3,11];case 7:return 4!==l.style?[3,9]:[4,this.renderDoubleBorder(l.color,l.width,n,e.curves)];case 8:return A.sent(),[3,11];case 9:return[4,this.renderSolidBorder(l.color,n,e.curves)];case 10:A.sent(),A.label=11;case 11:n++,A.label=12;case 12:return o++,[3,3];case 13:return[2]}}))}))},t.prototype.renderDashedDottedBorder=function(e,t,i,s,r){return lp(this,void 0,void 0,(function(){var n,o,a,l,u,A,c,h,d,p,f,v,g,m,_,y;return up(this,(function(b){return this.ctx.save(),n=function(e,t){switch(t){case 0:return Sy(e.topLeftBorderStroke,e.topRightBorderStroke);case 1:return Sy(e.topRightBorderStroke,e.bottomRightBorderStroke);case 2:return Sy(e.bottomRightBorderStroke,e.bottomLeftBorderStroke);default:return Sy(e.bottomLeftBorderStroke,e.topLeftBorderStroke)}}(s,i),o=Dy(s,i),2===r&&(this.path(o),this.ctx.clip()),gy(o[0])?(a=o[0].start.x,l=o[0].start.y):(a=o[0].x,l=o[0].y),gy(o[1])?(u=o[1].end.x,A=o[1].end.y):(u=o[1].x,A=o[1].y),c=0===i||2===i?Math.abs(a-u):Math.abs(l-A),this.ctx.beginPath(),3===r?this.formatPath(n):this.formatPath(o.slice(0,2)),h=t<3?3*t:2*t,d=t<3?2*t:t,3===r&&(h=t,d=t),p=!0,c<=2*h?p=!1:c<=2*h+d?(h*=f=c/(2*h+d),d*=f):(v=Math.floor((c+d)/(h+d)),g=(c-v*h)/(v-1),d=(m=(c-(v+1)*h)/v)<=0||Math.abs(d-g)0&&void 0!==arguments[0]?arguments[0]:{},t=!this._snapshotBegun,i=void 0!==e.width&&void 0!==e.height,s=this.scene.canvas.canvas,r=s.clientWidth,n=s.clientHeight,o=e.width?Math.floor(e.width):s.width,a=e.height?Math.floor(e.height):s.height;i&&(s.width=o,s.height=a),this._snapshotBegun||this.beginSnapshot({width:o,height:a}),e.includeGizmos||this.sendToPlugins("snapshotStarting");for(var l={},u=0,A=this._plugins.length;u0&&void 0!==b[0]?b[0]:{},i=!this._snapshotBegun,s=void 0!==t.width&&void 0!==t.height,r=this.scene.canvas.canvas,n=r.clientWidth,o=r.clientHeight,l=t.width?Math.floor(t.width):r.width,u=t.height?Math.floor(t.height):r.height,s&&(r.width=l,r.height=u),this._snapshotBegun||this.beginSnapshot(),t.includeGizmos||this.sendToPlugins("snapshotStarting"),this.scene._renderer.renderSnapshot(),A=this.scene._renderer.readSnapshotAsCanvas(),s&&(r.width=n,r.height=o,this.scene.glRedraw()),c={},h=[],d=0,p=this._plugins.length;d1&&void 0!==arguments[1])||arguments[1],i=arguments.length>2?arguments[2]:void 0,s=i||new Set;if(e){if(wb(e))s.add(e);else if(wb(e.buffer))s.add(e.buffer);else if(ArrayBuffer.isView(e));else if(t&&"object"===B(e))for(var r in e)bb(e[r],t,s)}else;return void 0===i?Array.from(s):[]}function wb(e){return!!e&&(e instanceof ArrayBuffer||("undefined"!=typeof MessagePort&&e instanceof MessagePort||("undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas)))}var Bb=function(){},xb=function(){function e(t){x(this,e),fb(this,"name",void 0),fb(this,"source",void 0),fb(this,"url",void 0),fb(this,"terminated",!1),fb(this,"worker",void 0),fb(this,"onMessage",void 0),fb(this,"onError",void 0),fb(this,"_loadableURL","");var i=t.name,s=t.source,r=t.url;lb(s||r),this.name=i,this.source=s,this.url=r,this.onMessage=Bb,this.onError=function(e){return console.log(e)},this.worker=cb?this._createBrowserWorker():this._createNodeWorker()}return C(e,[{key:"destroy",value:function(){this.onMessage=Bb,this.onError=Bb,this.worker.terminate(),this.terminated=!0}},{key:"isRunning",get:function(){return Boolean(this.onMessage)}},{key:"postMessage",value:function(e,t){t=t||bb(e),this.worker.postMessage(e,t)}},{key:"_getErrorFromErrorEvent",value:function(e){var t="Failed to load ";return t+="worker ".concat(this.name," from ").concat(this.url,". "),e.message&&(t+="".concat(e.message," in ")),e.lineno&&(t+=":".concat(e.lineno,":").concat(e.colno)),new Error(t)}},{key:"_createBrowserWorker",value:function(){var e=this;this._loadableURL=_b({source:this.source,url:this.url});var t=new Worker(this._loadableURL,{name:this.name});return t.onmessage=function(t){t.data?e.onMessage(t.data):e.onError(new Error("No data received"))},t.onerror=function(t){e.onError(e._getErrorFromErrorEvent(t)),e.terminated=!0},t.onmessageerror=function(e){return console.error(e)},t}},{key:"_createNodeWorker",value:function(){var e,t=this;if(this.url){var i=this.url.includes(":/")||this.url.startsWith("/")?this.url:"./".concat(this.url);e=new gb(i,{eval:!1})}else{if(!this.source)throw new Error("no worker");e=new gb(this.source,{eval:!0})}return e.on("message",(function(e){t.onMessage(e)})),e.on("error",(function(e){t.onError(e)})),e.on("exit",(function(e){})),e}}],[{key:"isSupported",value:function(){return"undefined"!=typeof Worker&&cb||void 0!==B(gb)}}]),e}(),Pb=function(){function e(t){x(this,e),fb(this,"name","unnamed"),fb(this,"source",void 0),fb(this,"url",void 0),fb(this,"maxConcurrency",1),fb(this,"maxMobileConcurrency",1),fb(this,"onDebug",(function(){})),fb(this,"reuseWorkers",!0),fb(this,"props",{}),fb(this,"jobQueue",[]),fb(this,"idleQueue",[]),fb(this,"count",0),fb(this,"isDestroyed",!1),this.source=t.source,this.url=t.url,this.setProps(t)}var t,i;return C(e,[{key:"destroy",value:function(){this.idleQueue.forEach((function(e){return e.destroy()})),this.isDestroyed=!0}},{key:"setProps",value:function(e){this.props=n(n({},this.props),e),void 0!==e.name&&(this.name=e.name),void 0!==e.maxConcurrency&&(this.maxConcurrency=e.maxConcurrency),void 0!==e.maxMobileConcurrency&&(this.maxMobileConcurrency=e.maxMobileConcurrency),void 0!==e.reuseWorkers&&(this.reuseWorkers=e.reuseWorkers),void 0!==e.onDebug&&(this.onDebug=e.onDebug)}},{key:"startJob",value:(i=u(a().mark((function e(t){var i,s,r,n=this,o=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=o.length>1&&void 0!==o[1]?o[1]:function(e,t,i){return e.done(i)},s=o.length>2&&void 0!==o[2]?o[2]:function(e,t){return e.error(t)},r=new Promise((function(e){return n.jobQueue.push({name:t,onMessage:i,onError:s,onStart:e}),n})),this._startQueuedJob(),e.next=6,r;case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"_startQueuedJob",value:(t=u(a().mark((function e(){var t,i,s;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.jobQueue.length){e.next=2;break}return e.abrupt("return");case 2:if(t=this._getAvailableWorker()){e.next=5;break}return e.abrupt("return");case 5:if(!(i=this.jobQueue.shift())){e.next=18;break}return this.onDebug({message:"Starting job",name:i.name,workerThread:t,backlog:this.jobQueue.length}),s=new vb(i.name,t),t.onMessage=function(e){return i.onMessage(s,e.type,e.payload)},t.onError=function(e){return i.onError(s,e)},i.onStart(s),e.prev=12,e.next=15,s.result;case 15:return e.prev=15,this.returnWorkerToQueue(t),e.finish(15);case 18:case"end":return e.stop()}}),e,this,[[12,,15,18]])}))),function(){return t.apply(this,arguments)})},{key:"returnWorkerToQueue",value:function(e){this.isDestroyed||!this.reuseWorkers||this.count>this._getMaxConcurrency()?(e.destroy(),this.count--):this.idleQueue.push(e),this.isDestroyed||this._startQueuedJob()}},{key:"_getAvailableWorker",value:function(){if(this.idleQueue.length>0)return this.idleQueue.shift()||null;if(this.count0&&void 0!==arguments[0]?arguments[0]:{};return e._workerFarm=e._workerFarm||new e({}),e._workerFarm.setProps(t),e._workerFarm}}]),e}();fb(Mb,"_workerFarm",void 0);function Fb(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=t[e.id]||{},s="".concat(e.id,"-worker.js"),r=i.workerUrl;if(r||"compression"!==e.id||(r=t.workerUrl),"test"===t._workerType&&(r="modules/".concat(e.module,"/dist/").concat(s)),!r){var n=e.version;"latest"===n&&(n="latest");var o=n?"@".concat(n):"";r="https://unpkg.com/@loaders.gl/".concat(e.module).concat(o,"/dist/").concat(s)}return lb(r),r}function Eb(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"3.2.6";lb(e,"no worker provided");var i=e.version;return!(!t||!i)}var kb=Object.freeze({__proto__:null,default:{}}),Ib={};function Db(e){return Sb.apply(this,arguments)}function Sb(){return Sb=u(a().mark((function e(t){var i,s,r=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=r.length>1&&void 0!==r[1]?r[1]:null,s=r.length>2&&void 0!==r[2]?r[2]:{},i&&(t=Tb(t,i,s)),Ib[t]=Ib[t]||Rb(t),e.next=6,Ib[t];case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)}))),Sb.apply(this,arguments)}function Tb(e,t,i){if(e.startsWith("http"))return e;var s=i.modules||{};return s[e]?s[e]:cb?i.CDN?(lb(i.CDN.startsWith("http")),"".concat(i.CDN,"/").concat(t,"@").concat("3.2.6","/dist/libs/").concat(e)):hb?"../src/libs/".concat(e):"modules/".concat(t,"/src/libs/").concat(e):"modules/".concat(t,"/dist/libs/").concat(e)}function Rb(e){return Lb.apply(this,arguments)}function Lb(){return(Lb=u(a().mark((function e(t){var i,s,r;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.endsWith("wasm")){e.next=7;break}return e.next=3,fetch(t);case 3:return i=e.sent,e.next=6,i.arrayBuffer();case 6:return e.abrupt("return",e.sent);case 7:if(cb){e.next=20;break}if(e.prev=8,e.t0=kb&&void 0,!e.t0){e.next=14;break}return e.next=13,(void 0)(t);case 13:e.t0=e.sent;case 14:return e.abrupt("return",e.t0);case 17:return e.prev=17,e.t1=e.catch(8),e.abrupt("return",null);case 20:if(!hb){e.next=22;break}return e.abrupt("return",importScripts(t));case 22:return e.next=24,fetch(t);case 24:return s=e.sent,e.next=27,s.text();case 27:return r=e.sent,e.abrupt("return",Ub(r,t));case 29:case"end":return e.stop()}}),e,null,[[8,17]])})))).apply(this,arguments)}function Ub(e,t){if(cb){if(hb)return eval.call(Ab,e),null;var i=document.createElement("script");i.id=t;try{i.appendChild(document.createTextNode(e))}catch(t){i.text=e}return document.body.appendChild(i),null}}function Ob(e,t){return!!Mb.isSupported()&&(!!(cb||null!=t&&t._nodeWorkers)&&(e.worker&&(null==t?void 0:t.worker)))}function Nb(e,t,i,s,r){return Qb.apply(this,arguments)}function Qb(){return Qb=u(a().mark((function e(t,i,s,r,n){var o,l,u,A,c,h;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=t.id,l=Fb(t,s),u=Mb.getWorkerFarm(s),A=u.getWorkerPool({name:o,url:l}),s=JSON.parse(JSON.stringify(s)),r=JSON.parse(JSON.stringify(r||{})),e.next=8,A.startJob("process-on-worker",Vb.bind(null,n));case 8:return(c=e.sent).postMessage("process",{input:i,options:s,context:r}),e.next=12,c.result;case 12:return h=e.sent,e.next=15,h.result;case 15:return e.abrupt("return",e.sent);case 16:case"end":return e.stop()}}),e)}))),Qb.apply(this,arguments)}function Vb(e,t,i,s){return Hb.apply(this,arguments)}function Hb(){return(Hb=u(a().mark((function e(t,i,s,r){var n,o,l,u,A;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.t0=s,e.next="done"===e.t0?3:"error"===e.t0?5:"process"===e.t0?7:20;break;case 3:return i.done(r),e.abrupt("break",21);case 5:return i.error(new Error(r.error)),e.abrupt("break",21);case 7:return n=r.id,o=r.input,l=r.options,e.prev=8,e.next=11,t(o,l);case 11:u=e.sent,i.postMessage("done",{id:n,result:u}),e.next=19;break;case 15:e.prev=15,e.t1=e.catch(8),A=e.t1 instanceof Error?e.t1.message:"unknown error",i.postMessage("error",{id:n,error:A});case 19:return e.abrupt("break",21);case 20:console.warn("parse-with-worker unknown message ".concat(s));case 21:case"end":return e.stop()}}),e,null,[[8,15]])})))).apply(this,arguments)}function jb(e,t,i){if(e.byteLength<=t+i)return"";for(var s=new DataView(e),r="",n=0;n1&&void 0!==arguments[1]?arguments[1]:5;if("string"==typeof e)return e.slice(0,t);if(ArrayBuffer.isView(e))return jb(e.buffer,e.byteOffset,t);if(e instanceof ArrayBuffer){return jb(e,0,t)}return""}(e),'"'))}}function zb(e){return e&&"object"===B(e)&&e.isBuffer}function Wb(e){if(zb(e))return zb(t=e)?new Uint8Array(t.buffer,t.byteOffset,t.length).slice().buffer:t;var t;if(e instanceof ArrayBuffer)return e;if(ArrayBuffer.isView(e))return 0===e.byteOffset&&e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);if("string"==typeof e){var i=e;return(new TextEncoder).encode(i).buffer}if(e&&"object"===B(e)&&e._toArrayBuffer)return e._toArrayBuffer();throw new Error("toArrayBuffer")}function Kb(){for(var e=arguments.length,t=new Array(e),i=0;i=0),nb(t>0),e+(t-1)&~(t-1)}function Yb(e,t,i){var s;if(e instanceof ArrayBuffer)s=new Uint8Array(e);else{var r=e.byteOffset,n=e.byteLength;s=new Uint8Array(e.buffer||e.arrayBuffer,r,n)}return t.set(s,i),i+Jb(s.byteLength,4)}function Zb(e){return qb.apply(this,arguments)}function qb(){return(qb=u(a().mark((function e(t){var i,s,r,n,o,l,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=[],s=!1,r=!1,e.prev=3,o=I(t);case 5:return e.next=7,o.next();case 7:if(!(s=!(l=e.sent).done)){e.next=13;break}u=l.value,i.push(u);case 10:s=!1,e.next=5;break;case 13:e.next=19;break;case 15:e.prev=15,e.t0=e.catch(3),r=!0,n=e.t0;case 19:if(e.prev=19,e.prev=20,!s||null==o.return){e.next=24;break}return e.next=24,o.return();case 24:if(e.prev=24,!r){e.next=27;break}throw n;case 27:return e.finish(24);case 28:return e.finish(19);case 29:return e.abrupt("return",Kb.apply(void 0,i));case 30:case"end":return e.stop()}}),e,null,[[3,15,19,29],[20,,24,28]])})))).apply(this,arguments)}var $b={};function ew(e){for(var t in $b)if(e.startsWith(t)){var i=$b[t];e=e.replace(t,i)}return e.startsWith("http://")||e.startsWith("https://")||(e="".concat("").concat(e)),e}var tw=function(e){return"function"==typeof e},iw=function(e){return null!==e&&"object"===B(e)},sw=function(e){return iw(e)&&e.constructor==={}.constructor},rw=function(e){return e&&"function"==typeof e[Symbol.iterator]},nw=function(e){return e&&"function"==typeof e[Symbol.asyncIterator]},ow=function(e){return"undefined"!=typeof Response&&e instanceof Response||e&&e.arrayBuffer&&e.text&&e.json},aw=function(e){return"undefined"!=typeof Blob&&e instanceof Blob},lw=function(e){return function(e){return"undefined"!=typeof ReadableStream&&e instanceof ReadableStream||iw(e)&&tw(e.tee)&&tw(e.cancel)&&tw(e.getReader)}(e)||function(e){return iw(e)&&tw(e.read)&&tw(e.pipe)&&function(e){return"boolean"==typeof e}(e.readable)}(e)},uw=/^data:([-\w.]+\/[-\w.+]+)(;|,)/,Aw=/^([-\w.]+\/[-\w.+]+)/;function cw(e){var t=Aw.exec(e);return t?t[1]:e}function hw(e){var t=uw.exec(e);return t?t[1]:""}var dw=/\?.*/;function pw(e){if(ow(e)){var t=vw(e.url||"");return{url:t,type:cw(e.headers.get("content-type")||"")||hw(t)}}return aw(e)?{url:vw(e.name||""),type:e.type||""}:"string"==typeof e?{url:vw(e),type:hw(e)}:{url:"",type:""}}function fw(e){return ow(e)?e.headers["content-length"]||-1:aw(e)?e.size:"string"==typeof e?e.length:e instanceof ArrayBuffer||ArrayBuffer.isView(e)?e.byteLength:-1}function vw(e){return e.replace(dw,"")}function gw(e){return mw.apply(this,arguments)}function mw(){return(mw=u(a().mark((function e(t){var i,s,r,n,o,l,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!ow(t)){e.next=2;break}return e.abrupt("return",t);case 2:return i={},(s=fw(t))>=0&&(i["content-length"]=String(s)),r=pw(t),n=r.url,(o=r.type)&&(i["content-type"]=o),e.next=9,Bw(t);case 9:return(l=e.sent)&&(i["x-first-bytes"]=l),"string"==typeof t&&(t=(new TextEncoder).encode(t)),u=new Response(t,{headers:i}),Object.defineProperty(u,"url",{value:n}),e.abrupt("return",u);case 15:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function _w(e){return yw.apply(this,arguments)}function yw(){return(yw=u(a().mark((function e(t){var i;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.ok){e.next=5;break}return e.next=3,bw(t);case 3:throw i=e.sent,new Error(i);case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function bw(e){return ww.apply(this,arguments)}function ww(){return(ww=u(a().mark((function e(t){var i,s,r;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i="Failed to fetch resource ".concat(t.url," (").concat(t.status,"): "),e.prev=1,s=t.headers.get("Content-Type"),r=t.statusText,!s.includes("application/json")){e.next=11;break}return e.t0=r,e.t1=" ",e.next=9,t.text();case 9:e.t2=e.sent,r=e.t0+=e.t1.concat.call(e.t1,e.t2);case 11:i=(i+=r).length>60?"".concat(i.slice(0,60),"..."):i,e.next=17;break;case 15:e.prev=15,e.t3=e.catch(1);case 17:return e.abrupt("return",i);case 18:case"end":return e.stop()}}),e,null,[[1,15]])})))).apply(this,arguments)}function Bw(e){return xw.apply(this,arguments)}function xw(){return(xw=u(a().mark((function e(t){var i,s,r,n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=5,"string"!=typeof t){e.next=3;break}return e.abrupt("return","data:,".concat(t.slice(0,i)));case 3:if(!(t instanceof Blob)){e.next=8;break}return s=t.slice(0,5),e.next=7,new Promise((function(e){var t=new FileReader;t.onload=function(t){var i;return e(null==t||null===(i=t.target)||void 0===i?void 0:i.result)},t.readAsDataURL(s)}));case 7:return e.abrupt("return",e.sent);case 8:if(!(t instanceof ArrayBuffer)){e.next=12;break}return r=t.slice(0,i),n=Pw(r),e.abrupt("return","data:base64,".concat(n));case 12:return e.abrupt("return",null);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Pw(e){for(var t="",i=new Uint8Array(e),s=0;s=0)}();function Sw(e){try{var t=window[e],i="__storage_test__";return t.setItem(i,i),t.removeItem(i),t}catch(e){return null}}var Tw=function(){function e(t,i){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"sessionStorage";x(this,e),this.storage=Sw(s),this.id=t,this.config={},Object.assign(this.config,i),this._loadConfiguration()}return C(e,[{key:"getConfiguration",value:function(){return this.config}},{key:"setConfiguration",value:function(e){return this.config={},this.updateConfiguration(e)}},{key:"updateConfiguration",value:function(e){if(Object.assign(this.config,e),this.storage){var t=JSON.stringify(this.config);this.storage.setItem(this.id,t)}return this}},{key:"_loadConfiguration",value:function(){var e={};if(this.storage){var t=this.storage.getItem(this.id);e=t?JSON.parse(t):{}}return Object.assign(this.config,e),this}}]),e}();function Rw(e,t,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:600,r=e.src.replace(/\(/g,"%28").replace(/\)/g,"%29");e.width>s&&(i=Math.min(i,s/e.width));var n=e.width*i,o=e.height*i,a=["font-size:1px;","padding:".concat(Math.floor(o/2),"px ").concat(Math.floor(n/2),"px;"),"line-height:".concat(o,"px;"),"background:url(".concat(r,");"),"background-size:".concat(n,"px ").concat(o,"px;"),"color:transparent;"].join("");return["".concat(t," %c+"),a]}var Lw={BLACK:30,RED:31,GREEN:32,YELLOW:33,BLUE:34,MAGENTA:35,CYAN:36,WHITE:37,BRIGHT_BLACK:90,BRIGHT_RED:91,BRIGHT_GREEN:92,BRIGHT_YELLOW:93,BRIGHT_BLUE:94,BRIGHT_MAGENTA:95,BRIGHT_CYAN:96,BRIGHT_WHITE:97};function Uw(e){return"string"==typeof e?Lw[e.toUpperCase()]||Lw.WHITE:e}function Ow(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:["constructor"],s=Object.getPrototypeOf(e),r=Object.getOwnPropertyNames(s),n=c(r);try{var o=function(){var s=t.value;"function"==typeof e[s]&&(i.find((function(e){return s===e}))||(e[s]=e[s].bind(e)))};for(n.s();!(t=n.n()).done;)o()}catch(e){n.e(e)}finally{n.f()}}function Nw(e,t){if(!e)throw new Error(t||"Assertion failed")}function Qw(){var e;if(Dw&&Ew.performance)e=Ew.performance.now();else if(kw.hrtime){var t=kw.hrtime();e=1e3*t[0]+t[1]/1e6}else e=Date.now();return e}var Vw={debug:Dw&&console.debug||console.log,log:console.log,info:console.info,warn:console.warn,error:console.error},Hw={enabled:!0,level:0};function jw(){}var Gw={},zw={once:!0};function Ww(e){for(var t in e)for(var i in e[t])return i||"untitled";return"empty"}var Kw=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{id:""},i=t.id;x(this,e),this.id=i,this.VERSION=Iw,this._startTs=Qw(),this._deltaTs=Qw(),this.LOG_THROTTLE_TIMEOUT=0,this._storage=new Tw("__probe-".concat(this.id,"__"),Hw),this.userData={},this.timeStamp("".concat(this.id," started")),Ow(this),Object.seal(this)}return C(e,[{key:"level",get:function(){return this.getLevel()},set:function(e){this.setLevel(e)}},{key:"isEnabled",value:function(){return this._storage.config.enabled}},{key:"getLevel",value:function(){return this._storage.config.level}},{key:"getTotal",value:function(){return Number((Qw()-this._startTs).toPrecision(10))}},{key:"getDelta",value:function(){return Number((Qw()-this._deltaTs).toPrecision(10))}},{key:"priority",get:function(){return this.level},set:function(e){this.level=e}},{key:"getPriority",value:function(){return this.level}},{key:"enable",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this._storage.updateConfiguration({enabled:e}),this}},{key:"setLevel",value:function(e){return this._storage.updateConfiguration({level:e}),this}},{key:"assert",value:function(e,t){Nw(e,t)}},{key:"warn",value:function(e){return this._getLogFunction(0,e,Vw.warn,arguments,zw)}},{key:"error",value:function(e){return this._getLogFunction(0,e,Vw.error,arguments)}},{key:"deprecated",value:function(e,t){return this.warn("`".concat(e,"` is deprecated and will be removed in a later version. Use `").concat(t,"` instead"))}},{key:"removed",value:function(e,t){return this.error("`".concat(e,"` has been removed. Use `").concat(t,"` instead"))}},{key:"probe",value:function(e,t){return this._getLogFunction(e,t,Vw.log,arguments,{time:!0,once:!0})}},{key:"log",value:function(e,t){return this._getLogFunction(e,t,Vw.debug,arguments)}},{key:"info",value:function(e,t){return this._getLogFunction(e,t,console.info,arguments)}},{key:"once",value:function(e,t){return this._getLogFunction(e,t,Vw.debug||Vw.info,arguments,zw)}},{key:"table",value:function(e,t,i){return t?this._getLogFunction(e,t,console.table||jw,i&&[i],{tag:Ww(t)}):jw}},{key:"image",value:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}((function(e){var t=e.logLevel,i=e.priority,s=e.image,r=e.message,n=void 0===r?"":r,o=e.scale,a=void 0===o?1:o;return this._shouldLog(t||i)?Dw?function(e){var t=e.image,i=e.message,s=void 0===i?"":i,r=e.scale,n=void 0===r?1:r;if("string"==typeof t){var o=new Image;return o.onload=function(){var e,t=Rw(o,s,n);(e=console).log.apply(e,A(t))},o.src=t,jw}var a=t.nodeName||"";if("img"===a.toLowerCase()){var l;return(l=console).log.apply(l,A(Rw(t,s,n))),jw}if("canvas"===a.toLowerCase()){var u=new Image;return u.onload=function(){var e;return(e=console).log.apply(e,A(Rw(u,s,n)))},u.src=t.toDataURL(),jw}return jw}({image:s,message:n,scale:a}):function(e){var t=e.image,i=(e.message,e.scale),s=void 0===i?1:i,r=null;try{r=module.require("asciify-image")}catch(e){}if(r)return function(){return r(t,{fit:"box",width:"".concat(Math.round(80*s),"%")}).then((function(e){return console.log(e)}))};return jw}({image:s,message:n,scale:a}):jw}))},{key:"settings",value:function(){console.table?console.table(this._storage.config):console.log(this._storage.config)}},{key:"get",value:function(e){return this._storage.config[e]}},{key:"set",value:function(e,t){this._storage.updateConfiguration(o({},e,t))}},{key:"time",value:function(e,t){return this._getLogFunction(e,t,console.time?console.time:console.info)}},{key:"timeEnd",value:function(e,t){return this._getLogFunction(e,t,console.timeEnd?console.timeEnd:console.info)}},{key:"timeStamp",value:function(e,t){return this._getLogFunction(e,t,console.timeStamp||jw)}},{key:"group",value:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{collapsed:!1},s=i=Jw({logLevel:e,message:t,opts:i}),r=s.collapsed;return i.method=(r?console.groupCollapsed:console.group)||console.info,this._getLogFunction(i)}},{key:"groupCollapsed",value:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.group(e,t,Object.assign({},i,{collapsed:!0}))}},{key:"groupEnd",value:function(e){return this._getLogFunction(e,"",console.groupEnd||jw)}},{key:"withGroup",value:function(e,t,i){this.group(e,t)();try{i()}finally{this.groupEnd(e)()}}},{key:"trace",value:function(){console.trace&&console.trace()}},{key:"_shouldLog",value:function(e){return this.isEnabled()&&this.getLevel()>=Xw(e)}},{key:"_getLogFunction",value:function(e,t,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],r=arguments.length>4?arguments[4]:void 0;if(this._shouldLog(e)){var n;r=Jw({logLevel:e,message:t,args:s,opts:r}),Nw(i=i||r.method),r.total=this.getTotal(),r.delta=this.getDelta(),this._deltaTs=Qw();var o=r.tag||r.message;if(r.once){if(Gw[o])return jw;Gw[o]=Qw()}return t=Yw(this.id,r.message,r),(n=i).bind.apply(n,[console,t].concat(A(r.args)))}return jw}}]),e}();function Xw(e){if(!e)return 0;var t;switch(B(e)){case"number":t=e;break;case"object":t=e.logLevel||e.priority||0;break;default:return 0}return Nw(Number.isFinite(t)&&t>=0),t}function Jw(e){var t=e.logLevel,i=e.message;e.logLevel=Xw(t);for(var s=e.args?Array.from(e.args):[];s.length&&s.shift()!==i;);switch(e.args=s,B(t)){case"string":case"function":void 0!==i&&s.unshift(i),e.message=t;break;case"object":Object.assign(e,t)}"function"==typeof e.message&&(e.message=e.message());var r=B(e.message);return Nw("string"===r||"object"===r),Object.assign(e,e.opts)}function Yw(e,t,i){if("string"==typeof t){var s=i.time?function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,i=Math.max(t-e.length,0);return"".concat(" ".repeat(i)).concat(e)}((r=i.total)<10?"".concat(r.toFixed(2),"ms"):r<100?"".concat(r.toFixed(1),"ms"):r<1e3?"".concat(r.toFixed(0),"ms"):"".concat((r/1e3).toFixed(2),"s")):"";t=function(e,t,i){return Dw||"string"!=typeof e||(t&&(t=Uw(t),e="[".concat(t,"m").concat(e,"")),i&&(t=Uw(i),e="[".concat(i+10,"m").concat(e,""))),e}(t=i.time?"".concat(e,": ").concat(s," ").concat(t):"".concat(e,": ").concat(t),i.color,i.background)}var r;return t}Kw.VERSION=Iw;var Zw=new Kw({id:"loaders.gl"}),qw=function(){function e(){x(this,e)}return C(e,[{key:"log",value:function(){return function(){}}},{key:"info",value:function(){return function(){}}},{key:"warn",value:function(){return function(){}}},{key:"error",value:function(){return function(){}}}]),e}(),$w={fetch:null,mimeType:void 0,nothrow:!1,log:new(function(){function e(){x(this,e),fb(this,"console",void 0),this.console=console}return C(e,[{key:"log",value:function(){for(var e,t=arguments.length,i=new Array(t),s=0;s=0)}()}var hB={self:"undefined"!=typeof self&&self,window:"undefined"!=typeof window&&window,global:"undefined"!=typeof global&&global,document:"undefined"!=typeof document&&document,process:"object"===("undefined"==typeof process?"undefined":B(process))&&process},dB=hB.window||hB.self||hB.global,pB=hB.process||{},fB="undefined"!=typeof __VERSION__?__VERSION__:"untranspiled source";function vB(e){try{var t=window[e],i="__storage_test__";return t.setItem(i,i),t.removeItem(i),t}catch(e){return null}}cB();var gB,mB=function(){function e(t){x(this,e);var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"sessionStorage";fb(this,"storage",void 0),fb(this,"id",void 0),fb(this,"config",{}),this.storage=vB(s),this.id=t,this.config={},Object.assign(this.config,i),this._loadConfiguration()}return C(e,[{key:"getConfiguration",value:function(){return this.config}},{key:"setConfiguration",value:function(e){return this.config={},this.updateConfiguration(e)}},{key:"updateConfiguration",value:function(e){if(Object.assign(this.config,e),this.storage){var t=JSON.stringify(this.config);this.storage.setItem(this.id,t)}return this}},{key:"_loadConfiguration",value:function(){var e={};if(this.storage){var t=this.storage.getItem(this.id);e=t?JSON.parse(t):{}}return Object.assign(this.config,e),this}}]),e}();function _B(e,t,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:600,r=e.src.replace(/\(/g,"%28").replace(/\)/g,"%29");e.width>s&&(i=Math.min(i,s/e.width));var n=e.width*i,o=e.height*i,a=["font-size:1px;","padding:".concat(Math.floor(o/2),"px ").concat(Math.floor(n/2),"px;"),"line-height:".concat(o,"px;"),"background:url(".concat(r,");"),"background-size:".concat(n,"px ").concat(o,"px;"),"color:transparent;"].join("");return["".concat(t," %c+"),a]}function yB(e){return"string"==typeof e?gB[e.toUpperCase()]||gB.WHITE:e}function bB(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:["constructor"],s=Object.getPrototypeOf(e),r=Object.getOwnPropertyNames(s),n=c(r);try{var o=function(){var s=t.value;"function"==typeof e[s]&&(i.find((function(e){return s===e}))||(e[s]=e[s].bind(e)))};for(n.s();!(t=n.n()).done;)o()}catch(e){n.e(e)}finally{n.f()}}function wB(e,t){if(!e)throw new Error(t||"Assertion failed")}function BB(){var e,t,i;if(cB&&"performance"in dB)e=null==dB||null===(t=dB.performance)||void 0===t||null===(i=t.now)||void 0===i?void 0:i.call(t);else if("hrtime"in pB){var s,r=null==pB||null===(s=pB.hrtime)||void 0===s?void 0:s.call(pB);e=1e3*r[0]+r[1]/1e6}else e=Date.now();return e}!function(e){e[e.BLACK=30]="BLACK",e[e.RED=31]="RED",e[e.GREEN=32]="GREEN",e[e.YELLOW=33]="YELLOW",e[e.BLUE=34]="BLUE",e[e.MAGENTA=35]="MAGENTA",e[e.CYAN=36]="CYAN",e[e.WHITE=37]="WHITE",e[e.BRIGHT_BLACK=90]="BRIGHT_BLACK",e[e.BRIGHT_RED=91]="BRIGHT_RED",e[e.BRIGHT_GREEN=92]="BRIGHT_GREEN",e[e.BRIGHT_YELLOW=93]="BRIGHT_YELLOW",e[e.BRIGHT_BLUE=94]="BRIGHT_BLUE",e[e.BRIGHT_MAGENTA=95]="BRIGHT_MAGENTA",e[e.BRIGHT_CYAN=96]="BRIGHT_CYAN",e[e.BRIGHT_WHITE=97]="BRIGHT_WHITE"}(gB||(gB={}));var xB={debug:cB&&console.debug||console.log,log:console.log,info:console.info,warn:console.warn,error:console.error},PB={enabled:!0,level:0};function CB(){}var MB={},FB={once:!0},EB=function(){function e(){x(this,e);var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{id:""},i=t.id;fb(this,"id",void 0),fb(this,"VERSION",fB),fb(this,"_startTs",BB()),fb(this,"_deltaTs",BB()),fb(this,"_storage",void 0),fb(this,"userData",{}),fb(this,"LOG_THROTTLE_TIMEOUT",0),this.id=i,this._storage=new mB("__probe-".concat(this.id,"__"),PB),this.userData={},this.timeStamp("".concat(this.id," started")),bB(this),Object.seal(this)}return C(e,[{key:"level",get:function(){return this.getLevel()},set:function(e){this.setLevel(e)}},{key:"isEnabled",value:function(){return this._storage.config.enabled}},{key:"getLevel",value:function(){return this._storage.config.level}},{key:"getTotal",value:function(){return Number((BB()-this._startTs).toPrecision(10))}},{key:"getDelta",value:function(){return Number((BB()-this._deltaTs).toPrecision(10))}},{key:"priority",get:function(){return this.level},set:function(e){this.level=e}},{key:"getPriority",value:function(){return this.level}},{key:"enable",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this._storage.updateConfiguration({enabled:e}),this}},{key:"setLevel",value:function(e){return this._storage.updateConfiguration({level:e}),this}},{key:"get",value:function(e){return this._storage.config[e]}},{key:"set",value:function(e,t){this._storage.updateConfiguration(o({},e,t))}},{key:"settings",value:function(){console.table?console.table(this._storage.config):console.log(this._storage.config)}},{key:"assert",value:function(e,t){wB(e,t)}},{key:"warn",value:function(e){return this._getLogFunction(0,e,xB.warn,arguments,FB)}},{key:"error",value:function(e){return this._getLogFunction(0,e,xB.error,arguments)}},{key:"deprecated",value:function(e,t){return this.warn("`".concat(e,"` is deprecated and will be removed in a later version. Use `").concat(t,"` instead"))}},{key:"removed",value:function(e,t){return this.error("`".concat(e,"` has been removed. Use `").concat(t,"` instead"))}},{key:"probe",value:function(e,t){return this._getLogFunction(e,t,xB.log,arguments,{time:!0,once:!0})}},{key:"log",value:function(e,t){return this._getLogFunction(e,t,xB.debug,arguments)}},{key:"info",value:function(e,t){return this._getLogFunction(e,t,console.info,arguments)}},{key:"once",value:function(e,t){for(var i=arguments.length,s=new Array(i>2?i-2:0),r=2;r2&&void 0!==arguments[2]?arguments[2]:{collapsed:!1},s=IB({logLevel:e,message:t,opts:i}),r=i.collapsed;return s.method=(r?console.groupCollapsed:console.group)||console.info,this._getLogFunction(s)}},{key:"groupCollapsed",value:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.group(e,t,Object.assign({},i,{collapsed:!0}))}},{key:"groupEnd",value:function(e){return this._getLogFunction(e,"",console.groupEnd||CB)}},{key:"withGroup",value:function(e,t,i){this.group(e,t)();try{i()}finally{this.groupEnd(e)()}}},{key:"trace",value:function(){console.trace&&console.trace()}},{key:"_shouldLog",value:function(e){return this.isEnabled()&&this.getLevel()>=kB(e)}},{key:"_getLogFunction",value:function(e,t,i,s,r){if(this._shouldLog(e)){var n;r=IB({logLevel:e,message:t,args:s,opts:r}),wB(i=i||r.method),r.total=this.getTotal(),r.delta=this.getDelta(),this._deltaTs=BB();var o=r.tag||r.message;if(r.once){if(MB[o])return CB;MB[o]=BB()}return t=function(e,t,i){if("string"==typeof t){var s=i.time?function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,i=Math.max(t-e.length,0);return"".concat(" ".repeat(i)).concat(e)}((r=i.total)<10?"".concat(r.toFixed(2),"ms"):r<100?"".concat(r.toFixed(1),"ms"):r<1e3?"".concat(r.toFixed(0),"ms"):"".concat((r/1e3).toFixed(2),"s")):"";t=function(e,t,i){return cB||"string"!=typeof e||(t&&(t=yB(t),e="[".concat(t,"m").concat(e,"")),i&&(t=yB(i),e="[".concat(i+10,"m").concat(e,""))),e}(t=i.time?"".concat(e,": ").concat(s," ").concat(t):"".concat(e,": ").concat(t),i.color,i.background)}var r;return t}(this.id,r.message,r),(n=i).bind.apply(n,[console,t].concat(A(r.args)))}return CB}}]),e}();function kB(e){if(!e)return 0;var t;switch(B(e)){case"number":t=e;break;case"object":t=e.logLevel||e.priority||0;break;default:return 0}return wB(Number.isFinite(t)&&t>=0),t}function IB(e){var t=e.logLevel,i=e.message;e.logLevel=kB(t);for(var s=e.args?Array.from(e.args):[];s.length&&s.shift()!==i;);switch(B(t)){case"string":case"function":void 0!==i&&s.unshift(i),e.message=t;break;case"object":Object.assign(e,t)}"function"==typeof e.message&&(e.message=e.message());var r=B(e.message);return wB("string"===r||"object"===r),Object.assign(e,{args:s},e.opts)}function DB(e){for(var t in e)for(var i in e[t])return i||"untitled";return"empty"}fb(EB,"VERSION",fB);var SB=new EB({id:"loaders.gl"}),TB=/\.([^.]+)$/;function RB(e){return LB.apply(this,arguments)}function LB(){return LB=u(a().mark((function e(t){var i,s,r,o,l=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=l.length>1&&void 0!==l[1]?l[1]:[],s=l.length>2?l[2]:void 0,r=l.length>3?l[3]:void 0,NB(t)){e.next=5;break}return e.abrupt("return",null);case 5:if(!(o=UB(t,i,n(n({},s),{},{nothrow:!0}),r))){e.next=8;break}return e.abrupt("return",o);case 8:if(!aw(t)){e.next=13;break}return e.next=11,t.slice(0,10).arrayBuffer();case 11:t=e.sent,o=UB(t,i,s,r);case 13:if(o||null!=s&&s.nothrow){e.next=15;break}throw new Error(QB(t));case 15:return e.abrupt("return",o);case 16:case"end":return e.stop()}}),e)}))),LB.apply(this,arguments)}function UB(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],i=arguments.length>2?arguments[2]:void 0,s=arguments.length>3?arguments[3]:void 0;if(!NB(e))return null;if(t&&!Array.isArray(t))return uB(t);var r,n=[];(t&&(n=n.concat(t)),null!=i&&i.ignoreRegisteredLoaders)||(r=n).push.apply(r,A(AB()));VB(n);var o=OB(e,n,i,s);if(!(o||null!=i&&i.nothrow))throw new Error(QB(e));return o}function OB(e,t,i,s){var r,n=pw(e),o=n.url,a=n.type,l=o||(null==s?void 0:s.url),u=null,A="";(null!=i&&i.mimeType&&(u=HB(t,null==i?void 0:i.mimeType),A="match forced by supplied MIME type ".concat(null==i?void 0:i.mimeType)),u=u||function(e,t){var i=t&&TB.exec(t),s=i&&i[1];return s?function(e,t){t=t.toLowerCase();var i,s=c(e);try{for(s.s();!(i=s.n()).done;){var r,n=i.value,o=c(n.extensions);try{for(o.s();!(r=o.n()).done;){if(r.value.toLowerCase()===t)return n}}catch(e){o.e(e)}finally{o.f()}}}catch(e){s.e(e)}finally{s.f()}return null}(e,s):null}(t,l),A=A||(u?"matched url ".concat(l):""),u=u||HB(t,a),A=A||(u?"matched MIME type ".concat(a):""),u=u||function(e,t){if(!t)return null;var i,s=c(e);try{for(s.s();!(i=s.n()).done;){var r=i.value;if("string"==typeof t){if(jB(t,r))return r}else if(ArrayBuffer.isView(t)){if(GB(t.buffer,t.byteOffset,r))return r}else if(t instanceof ArrayBuffer){if(GB(t,0,r))return r}}}catch(e){s.e(e)}finally{s.f()}return null}(t,e),A=A||(u?"matched initial data ".concat(zB(e)):""),u=u||HB(t,null==i?void 0:i.fallbackMimeType),A=A||(u?"matched fallback MIME type ".concat(a):""))&&SB.log(1,"selectLoader selected ".concat(null===(r=u)||void 0===r?void 0:r.name,": ").concat(A,"."));return u}function NB(e){return!(e instanceof Response&&204===e.status)}function QB(e){var t=pw(e),i=t.url,s=t.type,r="No valid loader found (";r+=i?"".concat(function(e){var t=e&&e.lastIndexOf("/");return t>=0?e.substr(t+1):""}(i),", "):"no url provided, ",r+="MIME type: ".concat(s?'"'.concat(s,'"'):"not provided",", ");var n=e?zB(e):"";return r+=n?' first bytes: "'.concat(n,'"'):"first bytes: not available",r+=")"}function VB(e){var t,i=c(e);try{for(i.s();!(t=i.n()).done;){uB(t.value)}}catch(e){i.e(e)}finally{i.f()}}function HB(e,t){var i,s=c(e);try{for(s.s();!(i=s.n()).done;){var r=i.value;if(r.mimeTypes&&r.mimeTypes.includes(t))return r;if(t==="application/x.".concat(r.id))return r}}catch(e){s.e(e)}finally{s.f()}return null}function jB(e,t){return t.testText?t.testText(e):(Array.isArray(t.tests)?t.tests:[t.tests]).some((function(t){return e.startsWith(t)}))}function GB(e,t,i){return(Array.isArray(i.tests)?i.tests:[i.tests]).some((function(s){return function(e,t,i,s){if(s instanceof ArrayBuffer)return function(e,t,i){if(i=i||e.byteLength,e.byteLength1&&void 0!==arguments[1]?arguments[1]:5;if("string"==typeof e)return e.slice(0,t);if(ArrayBuffer.isView(e))return WB(e.buffer,e.byteOffset,t);if(e instanceof ArrayBuffer){var i=0;return WB(e,i,t)}return""}function WB(e,t,i){if(e.byteLength1&&void 0!==A[1]?A[1]:{},s=t.chunkSize,r=void 0===s?262144:s,n=0;case 3:if(!(n2&&void 0!==arguments[2]?arguments[2]:null;if(i)return i;var s=n({fetch:rB(t,e)},e);return Array.isArray(s.loaders)||(s.loaders=null),s}function nx(e,t){if(!t&&e&&!Array.isArray(e))return e;var i;if(e&&(i=Array.isArray(e)?e:[e]),t&&t.loaders){var s=Array.isArray(t.loaders)?t.loaders:[t.loaders];i=i?[].concat(A(i),A(s)):s}return i&&i.length?i:null}function ox(e,t,i,s){return ax.apply(this,arguments)}function ax(){return(ax=u(a().mark((function e(t,i,s,r){var n,o,l,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return lb(!r||"object"===B(r)),!i||Array.isArray(i)||lB(i)||(r=void 0,s=i,i=void 0),e.next=4,t;case 4:return t=e.sent,s=s||{},n=pw(t),o=n.url,l=nx(i,r),e.next=11,RB(t,l,s);case 11:if(u=e.sent){e.next=14;break}return e.abrupt("return",null);case 14:return s=sB(s,u,l,o),r=rx({url:o,parse:ox,loaders:l},s,r),e.next=18,lx(u,t,s,r);case 18:return e.abrupt("return",e.sent);case 19:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function lx(e,t,i,s){return ux.apply(this,arguments)}function ux(){return(ux=u(a().mark((function e(t,i,s,r){var n,o,l,u,A,c,h,d;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Eb(t),ow(i)&&(o=(n=i).ok,l=n.redirected,u=n.status,A=n.statusText,c=n.type,h=n.url,d=Object.fromEntries(n.headers.entries()),r.response={headers:d,ok:o,redirected:l,status:u,statusText:A,type:c,url:h}),e.next=4,ix(i,t,s);case 4:if(i=e.sent,!t.parseTextSync||"string"!=typeof i){e.next=8;break}return s.dataType="text",e.abrupt("return",t.parseTextSync(i,s,r,t));case 8:if(!Ob(t,s)){e.next=12;break}return e.next=11,Nb(t,i,s,r,ox);case 11:case 15:case 19:return e.abrupt("return",e.sent);case 12:if(!t.parseText||"string"!=typeof i){e.next=16;break}return e.next=15,t.parseText(i,s,r,t);case 16:if(!t.parse){e.next=20;break}return e.next=19,t.parse(i,s,r,t);case 20:throw lb(!t.parseSync),new Error("".concat(t.id," loader - no parser found and worker is disabled"));case 22:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Ax,cx,hx="https://unpkg.com/@loaders.gl/textures@".concat("3.2.6","/dist/libs/basis_encoder.wasm"),dx="https://unpkg.com/@loaders.gl/textures@".concat("3.2.6","/dist/libs/basis_encoder.js");function px(e){return fx.apply(this,arguments)}function fx(){return(fx=u(a().mark((function e(t){var i;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(i=t.modules||{}).basis){e.next=3;break}return e.abrupt("return",i.basis);case 3:return Ax=Ax||vx(t),e.next=6,Ax;case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function vx(e){return gx.apply(this,arguments)}function gx(){return(gx=u(a().mark((function e(t){var i,s,r,n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=null,s=null,e.t0=Promise,e.next=5,Db("basis_transcoder.js","textures",t);case 5:return e.t1=e.sent,e.next=8,Db("basis_transcoder.wasm","textures",t);case 8:return e.t2=e.sent,e.t3=[e.t1,e.t2],e.next=12,e.t0.all.call(e.t0,e.t3);case 12:return r=e.sent,n=h(r,2),i=n[0],s=n[1],i=i||globalThis.BASIS,e.next=19,mx(i,s);case 19:return e.abrupt("return",e.sent);case 20:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function mx(e,t){var i={};return t&&(i.wasmBinary=t),new Promise((function(t){e(i).then((function(e){var i=e.BasisFile;(0,e.initializeBasis)(),t({BasisFile:i})}))}))}function _x(e){return yx.apply(this,arguments)}function yx(){return(yx=u(a().mark((function e(t){var i;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(i=t.modules||{}).basisEncoder){e.next=3;break}return e.abrupt("return",i.basisEncoder);case 3:return cx=cx||bx(t),e.next=6,cx;case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function bx(e){return wx.apply(this,arguments)}function wx(){return(wx=u(a().mark((function e(t){var i,s,r,n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=null,s=null,e.t0=Promise,e.next=5,Db(dx,"textures",t);case 5:return e.t1=e.sent,e.next=8,Db(hx,"textures",t);case 8:return e.t2=e.sent,e.t3=[e.t1,e.t2],e.next=12,e.t0.all.call(e.t0,e.t3);case 12:return r=e.sent,n=h(r,2),i=n[0],s=n[1],i=i||globalThis.BASIS,e.next=19,Bx(i,s);case 19:return e.abrupt("return",e.sent);case 20:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Bx(e,t){var i={};return t&&(i.wasmBinary=t),new Promise((function(t){e(i).then((function(e){var i=e.BasisFile,s=e.KTX2File,r=e.initializeBasis,n=e.BasisEncoder;r(),t({BasisFile:i,KTX2File:s,BasisEncoder:n})}))}))}var xx,Px,Cx,Mx,Fx,Ex,kx,Ix,Dx,Sx=33776,Tx=33779,Rx=35840,Lx=35842,Ux=36196,Ox=37808,Nx=["","WEBKIT_","MOZ_"],Qx={WEBGL_compressed_texture_s3tc:"dxt",WEBGL_compressed_texture_s3tc_srgb:"dxt-srgb",WEBGL_compressed_texture_etc1:"etc1",WEBGL_compressed_texture_etc:"etc2",WEBGL_compressed_texture_pvrtc:"pvrtc",WEBGL_compressed_texture_atc:"atc",WEBGL_compressed_texture_astc:"astc",EXT_texture_compression_rgtc:"rgtc"},Vx=null;function Hx(e){if(!Vx){e=e||function(){try{return document.createElement("canvas").getContext("webgl")}catch(e){return null}}()||void 0,Vx=new Set;var t,i=c(Nx);try{for(i.s();!(t=i.n()).done;){var s=t.value;for(var r in Qx)if(e&&e.getExtension("".concat(s).concat(r))){var n=Qx[r];Vx.add(n)}}}catch(e){i.e(e)}finally{i.f()}}return Vx}(Dx=xx||(xx={}))[Dx.NONE=0]="NONE",Dx[Dx.BASISLZ=1]="BASISLZ",Dx[Dx.ZSTD=2]="ZSTD",Dx[Dx.ZLIB=3]="ZLIB",function(e){e[e.BASICFORMAT=0]="BASICFORMAT"}(Px||(Px={})),function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.ETC1S=163]="ETC1S",e[e.UASTC=166]="UASTC"}(Cx||(Cx={})),function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.SRGB=1]="SRGB"}(Mx||(Mx={})),function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.LINEAR=1]="LINEAR",e[e.SRGB=2]="SRGB",e[e.ITU=3]="ITU",e[e.NTSC=4]="NTSC",e[e.SLOG=5]="SLOG",e[e.SLOG2=6]="SLOG2"}(Fx||(Fx={})),function(e){e[e.ALPHA_STRAIGHT=0]="ALPHA_STRAIGHT",e[e.ALPHA_PREMULTIPLIED=1]="ALPHA_PREMULTIPLIED"}(Ex||(Ex={})),function(e){e[e.RGB=0]="RGB",e[e.RRR=3]="RRR",e[e.GGG=4]="GGG",e[e.AAA=15]="AAA"}(kx||(kx={})),function(e){e[e.RGB=0]="RGB",e[e.RGBA=3]="RGBA",e[e.RRR=4]="RRR",e[e.RRRG=5]="RRRG"}(Ix||(Ix={}));var jx=[171,75,84,88,32,50,48,187,13,10,26,10];function Gx(e){var t=new Uint8Array(e);return!(t.byteLength1&&void 0!==s[1]?s[1]:null)&&gP||(i=null),!i){e.next=13;break}return e.prev=3,e.next=6,createImageBitmap(t,i);case 6:return e.abrupt("return",e.sent);case 9:e.prev=9,e.t0=e.catch(3),console.warn(e.t0),gP=!1;case 13:return e.next=15,createImageBitmap(t);case 15:return e.abrupt("return",e.sent);case 16:case"end":return e.stop()}}),e,null,[[3,9]])}))),bP.apply(this,arguments)}function wP(e){for(var t in e||vP)return!1;return!0}function BP(e){var t=xP(e);return function(e){var t=xP(e);if(!(t.byteLength>=24&&2303741511===t.getUint32(0,false)))return null;return{mimeType:"image/png",width:t.getUint32(16,false),height:t.getUint32(20,false)}}(t)||function(e){var t=xP(e);if(!(t.byteLength>=3&&65496===t.getUint16(0,false)&&255===t.getUint8(2)))return null;var i=function(){for(var e=new Set([65499,65476,65484,65501,65534]),t=65504;t<65520;++t)e.add(t);var i=new Set([65472,65473,65474,65475,65477,65478,65479,65481,65482,65483,65485,65486,65487,65502]);return{tableMarkers:e,sofMarkers:i}}(),s=i.tableMarkers,r=i.sofMarkers,n=2;for(;n+9=10&&1195984440===t.getUint32(0,false)))return null;return{mimeType:"image/gif",width:t.getUint16(6,true),height:t.getUint16(8,true)}}(t)||function(e){var t=xP(e);if(!(t.byteLength>=14&&16973===t.getUint16(0,false)&&t.getUint32(2,true)===t.byteLength))return null;return{mimeType:"image/bmp",width:t.getUint32(18,true),height:t.getUint32(22,true)}}(t)}function xP(e){if(e instanceof DataView)return e;if(ArrayBuffer.isView(e))return new DataView(e.buffer);if(e instanceof ArrayBuffer)return new DataView(e);throw new Error("toDataView")}function PP(e,t){return CP.apply(this,arguments)}function CP(){return CP=u(a().mark((function e(t,i){var s,r,n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return s=BP(t)||{},r=s.mimeType,nb(n=globalThis._parseImageNode),e.next=5,n(t,r);case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e)}))),CP.apply(this,arguments)}function MP(){return(MP=u(a().mark((function e(t,i,s){var r,n,o,l,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=(i=i||{}).image||{},n=r.type||"auto",o=(s||{}).url,l=FP(n),e.t0=l,e.next="imagebitmap"===e.t0?8:"image"===e.t0?12:"data"===e.t0?16:20;break;case 8:return e.next=10,mP(t,i,o);case 10:return u=e.sent,e.abrupt("break",21);case 12:return e.next=14,hP(t,i,o);case 14:return u=e.sent,e.abrupt("break",21);case 16:return e.next=18,PP(t);case 18:return u=e.sent,e.abrupt("break",21);case 20:nb(!1);case 21:return"data"===n&&(u=oP(u)),e.abrupt("return",u);case 23:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function FP(e){switch(e){case"auto":case"data":return function(){if(iP)return"imagebitmap";if(tP)return"image";if(rP)return"data";throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js")}();default:return function(e){switch(e){case"auto":return iP||tP||rP;case"imagebitmap":return iP;case"image":return tP;case"data":return rP;default:throw new Error("@loaders.gl/images: image ".concat(e," not supported in this environment"))}}(e),e}}var EP={id:"image",module:"images",name:"Images",version:"3.2.6",mimeTypes:["image/png","image/jpeg","image/gif","image/webp","image/bmp","image/vnd.microsoft.icon","image/svg+xml"],extensions:["png","jpg","jpeg","gif","webp","bmp","ico","svg"],parse:function(e,t,i){return MP.apply(this,arguments)},tests:[function(e){return Boolean(BP(new DataView(e)))}],options:{image:{type:"auto",decode:!0}}},kP=["image/png","image/jpeg","image/gif"],IP={};function DP(e){return void 0===IP[e]&&(IP[e]=function(e){switch(e){case"image/webp":return function(){if(!ob)return!1;try{return 0===document.createElement("canvas").toDataURL("image/webp").indexOf("data:image/webp")}catch(e){return!1}}();case"image/svg":return ob;default:if(!ob){var t=globalThis._parseImageNode;return Boolean(t)&&kP.includes(e)}return!0}}(e)),IP[e]}function SP(e,t){if(!e)throw new Error(t||"assert failed: gltf")}function TP(e,t){if(e.startsWith("data:")||e.startsWith("http:")||e.startsWith("https:"))return e;var i=t.baseUri||t.uri;if(!i)throw new Error("'baseUri' must be provided to resolve relative url ".concat(e));return i.substr(0,i.lastIndexOf("/")+1)+e}function RP(e,t,i){var s=e.bufferViews[i];SP(s);var r=t[s.buffer];SP(r);var n=(s.byteOffset||0)+r.byteOffset;return new Uint8Array(r.arrayBuffer,n,s.byteLength)}var LP=["SCALAR","VEC2","VEC3","VEC4"],UP=[[Int8Array,5120],[Uint8Array,5121],[Int16Array,5122],[Uint16Array,5123],[Uint32Array,5125],[Float32Array,5126],[Float64Array,5130]],OP=new Map(UP),NP={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},QP={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},VP={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function HP(e){return LP[e-1]||LP[0]}function jP(e){var t=OP.get(e.constructor);if(!t)throw new Error("Illegal typed array");return t}function GP(e,t){var i=VP[e.componentType],s=NP[e.type],r=QP[e.componentType],n=e.count*s,o=e.count*s*r;return SP(o>=0&&o<=t.byteLength),{ArrayType:i,length:n,byteLength:o}}var zP,WP={asset:{version:"2.0",generator:"loaders.gl"},buffers:[]},KP=function(){function e(t){x(this,e),fb(this,"gltf",void 0),fb(this,"sourceBuffers",void 0),fb(this,"byteLength",void 0),this.gltf=t||{json:n({},WP),buffers:[]},this.sourceBuffers=[],this.byteLength=0,this.gltf.buffers&&this.gltf.buffers[0]&&(this.byteLength=this.gltf.buffers[0].byteLength,this.sourceBuffers=[this.gltf.buffers[0]])}return C(e,[{key:"json",get:function(){return this.gltf.json}},{key:"getApplicationData",value:function(e){return this.json[e]}},{key:"getExtraData",value:function(e){return(this.json.extras||{})[e]}},{key:"getExtension",value:function(e){var t=this.getUsedExtensions().find((function(t){return t===e})),i=this.json.extensions||{};return t?i[e]||!0:null}},{key:"getRequiredExtension",value:function(e){var t=this.getRequiredExtensions().find((function(t){return t===e}));return t?this.getExtension(e):null}},{key:"getRequiredExtensions",value:function(){return this.json.extensionsRequired||[]}},{key:"getUsedExtensions",value:function(){return this.json.extensionsUsed||[]}},{key:"getObjectExtension",value:function(e,t){return(e.extensions||{})[t]}},{key:"getScene",value:function(e){return this.getObject("scenes",e)}},{key:"getNode",value:function(e){return this.getObject("nodes",e)}},{key:"getSkin",value:function(e){return this.getObject("skins",e)}},{key:"getMesh",value:function(e){return this.getObject("meshes",e)}},{key:"getMaterial",value:function(e){return this.getObject("materials",e)}},{key:"getAccessor",value:function(e){return this.getObject("accessors",e)}},{key:"getTexture",value:function(e){return this.getObject("textures",e)}},{key:"getSampler",value:function(e){return this.getObject("samplers",e)}},{key:"getImage",value:function(e){return this.getObject("images",e)}},{key:"getBufferView",value:function(e){return this.getObject("bufferViews",e)}},{key:"getBuffer",value:function(e){return this.getObject("buffers",e)}},{key:"getObject",value:function(e,t){if("object"===B(t))return t;var i=this.json[e]&&this.json[e][t];if(!i)throw new Error("glTF file error: Could not find ".concat(e,"[").concat(t,"]"));return i}},{key:"getTypedArrayForBufferView",value:function(e){var t=(e=this.getBufferView(e)).buffer,i=this.gltf.buffers[t];SP(i);var s=(e.byteOffset||0)+i.byteOffset;return new Uint8Array(i.arrayBuffer,s,e.byteLength)}},{key:"getTypedArrayForAccessor",value:function(e){e=this.getAccessor(e);var t=this.getBufferView(e.bufferView),i=this.getBuffer(t.buffer).data,s=GP(e,t),r=s.ArrayType,n=s.length;return new r(i,t.byteOffset+e.byteOffset,n)}},{key:"getTypedArrayForImageData",value:function(e){e=this.getAccessor(e);var t=this.getBufferView(e.bufferView),i=this.getBuffer(t.buffer).data,s=t.byteOffset||0;return new Uint8Array(i,s,t.byteLength)}},{key:"addApplicationData",value:function(e,t){return this.json[e]=t,this}},{key:"addExtraData",value:function(e,t){return this.json.extras=this.json.extras||{},this.json.extras[e]=t,this}},{key:"addObjectExtension",value:function(e,t,i){return e.extensions=e.extensions||{},e.extensions[t]=i,this.registerUsedExtension(t),this}},{key:"setObjectExtension",value:function(e,t,i){(e.extensions||{})[t]=i}},{key:"removeObjectExtension",value:function(e,t){var i=e.extensions||{},s=i[t];return delete i[t],s}},{key:"addExtension",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return SP(t),this.json.extensions=this.json.extensions||{},this.json.extensions[e]=t,this.registerUsedExtension(e),t}},{key:"addRequiredExtension",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return SP(t),this.addExtension(e,t),this.registerRequiredExtension(e),t}},{key:"registerUsedExtension",value:function(e){this.json.extensionsUsed=this.json.extensionsUsed||[],this.json.extensionsUsed.find((function(t){return t===e}))||this.json.extensionsUsed.push(e)}},{key:"registerRequiredExtension",value:function(e){this.registerUsedExtension(e),this.json.extensionsRequired=this.json.extensionsRequired||[],this.json.extensionsRequired.find((function(t){return t===e}))||this.json.extensionsRequired.push(e)}},{key:"removeExtension",value:function(e){this.json.extensionsRequired&&this._removeStringFromArray(this.json.extensionsRequired,e),this.json.extensionsUsed&&this._removeStringFromArray(this.json.extensionsUsed,e),this.json.extensions&&delete this.json.extensions[e]}},{key:"setDefaultScene",value:function(e){this.json.scene=e}},{key:"addScene",value:function(e){var t=e.nodeIndices;return this.json.scenes=this.json.scenes||[],this.json.scenes.push({nodes:t}),this.json.scenes.length-1}},{key:"addNode",value:function(e){var t=e.meshIndex,i=e.matrix;this.json.nodes=this.json.nodes||[];var s={mesh:t};return i&&(s.matrix=i),this.json.nodes.push(s),this.json.nodes.length-1}},{key:"addMesh",value:function(e){var t=e.attributes,i=e.indices,s=e.material,r=e.mode,n=void 0===r?4:r,o={primitives:[{attributes:this._addAttributes(t),mode:n}]};if(i){var a=this._addIndices(i);o.primitives[0].indices=a}return Number.isFinite(s)&&(o.primitives[0].material=s),this.json.meshes=this.json.meshes||[],this.json.meshes.push(o),this.json.meshes.length-1}},{key:"addPointCloud",value:function(e){var t={primitives:[{attributes:this._addAttributes(e),mode:0}]};return this.json.meshes=this.json.meshes||[],this.json.meshes.push(t),this.json.meshes.length-1}},{key:"addImage",value:function(e,t){var i=BP(e),s=t||(null==i?void 0:i.mimeType),r={bufferView:this.addBufferView(e),mimeType:s};return this.json.images=this.json.images||[],this.json.images.push(r),this.json.images.length-1}},{key:"addBufferView",value:function(e){var t=e.byteLength;SP(Number.isFinite(t)),this.sourceBuffers=this.sourceBuffers||[],this.sourceBuffers.push(e);var i={buffer:0,byteOffset:this.byteLength,byteLength:t};return this.byteLength+=Jb(t,4),this.json.bufferViews=this.json.bufferViews||[],this.json.bufferViews.push(i),this.json.bufferViews.length-1}},{key:"addAccessor",value:function(e,t){var i={bufferView:e,type:HP(t.size),componentType:t.componentType,count:t.count,max:t.max,min:t.min};return this.json.accessors=this.json.accessors||[],this.json.accessors.push(i),this.json.accessors.length-1}},{key:"addBinaryBuffer",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{size:3},i=this.addBufferView(e),s={min:t.min,max:t.max};s.min&&s.max||(s=this._getAccessorMinMax(e,t.size));var r={size:t.size,componentType:jP(e),count:Math.round(e.length/t.size),min:s.min,max:s.max};return this.addAccessor(i,Object.assign(r,t))}},{key:"addTexture",value:function(e){var t={source:e.imageIndex};return this.json.textures=this.json.textures||[],this.json.textures.push(t),this.json.textures.length-1}},{key:"addMaterial",value:function(e){return this.json.materials=this.json.materials||[],this.json.materials.push(e),this.json.materials.length-1}},{key:"createBinaryChunk",value:function(){var e,t;this.gltf.buffers=[];var i,s=this.byteLength,r=new ArrayBuffer(s),n=new Uint8Array(r),o=0,a=c(this.sourceBuffers||[]);try{for(a.s();!(i=a.n()).done;){o=Yb(i.value,n,o)}}catch(e){a.e(e)}finally{a.f()}null!==(e=this.json)&&void 0!==e&&null!==(t=e.buffers)&&void 0!==t&&t[0]?this.json.buffers[0].byteLength=s:this.json.buffers=[{byteLength:s}],this.gltf.binary=r,this.sourceBuffers=[r]}},{key:"_removeStringFromArray",value:function(e,t){for(var i=!0;i;){var s=e.indexOf(t);s>-1?e.splice(s,1):i=!1}}},{key:"_addAttributes",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={};for(var i in e){var s=e[i],r=this._getGltfAttributeName(i),n=this.addBinaryBuffer(s.value,s);t[r]=n}return t}},{key:"_addIndices",value:function(e){return this.addBinaryBuffer(e,{size:1})}},{key:"_getGltfAttributeName",value:function(e){switch(e.toLowerCase()){case"position":case"positions":case"vertices":return"POSITION";case"normal":case"normals":return"NORMAL";case"color":case"colors":return"COLOR_0";case"texcoord":case"texcoords":return"TEXCOORD_0";default:return e}}},{key:"_getAccessorMinMax",value:function(e,t){var i={min:null,max:null};if(e.length5&&void 0!==u[5]?u[5]:"NONE",e.next=3,iC();case 3:aC(l=e.sent,l.exports[$P[n]],t,i,s,r,l.exports[qP[o||"NONE"]]);case 5:case"end":return e.stop()}}),e)}))),tC.apply(this,arguments)}function iC(){return sC.apply(this,arguments)}function sC(){return(sC=u(a().mark((function e(){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return zP||(zP=rC()),e.abrupt("return",zP);case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function rC(){return nC.apply(this,arguments)}function nC(){return(nC=u(a().mark((function e(){var t,i;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=XP,WebAssembly.validate(YP)&&(t=JP,console.log("Warning: meshopt_decoder is using experimental SIMD support")),e.next=4,WebAssembly.instantiate(oC(t),{});case 4:return i=e.sent,e.next=7,i.instance.exports.__wasm_call_ctors();case 7:return e.abrupt("return",i.instance);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function oC(e){for(var t=new Uint8Array(e.length),i=0;i96?s-71:s>64?s-65:s>47?s+4:s>46?63:62}for(var r=0,n=0;nr?A:r,n=c>n?c:n,o=h>o?h:o}return[[t,i,s],[r,n,o]]}var vC=function(){function e(t,i){x(this,e),fb(this,"fields",void 0),fb(this,"metadata",void 0),function(e,t){if(!e)throw new Error(t||"loader assertion failed.")}(Array.isArray(t)),function(e){var t,i={},s=c(e);try{for(s.s();!(t=s.n()).done;){var r=t.value;i[r.name]&&console.warn("Schema: duplicated field name",r.name,r),i[r.name]=!0}}catch(e){s.e(e)}finally{s.f()}}(t),this.fields=t,this.metadata=i||new Map}return C(e,[{key:"compareTo",value:function(e){if(this.metadata!==e.metadata)return!1;if(this.fields.length!==e.fields.length)return!1;for(var t=0;t2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:new Map;x(this,e),fb(this,"name",void 0),fb(this,"type",void 0),fb(this,"nullable",void 0),fb(this,"metadata",void 0),this.name=t,this.type=i,this.nullable=s,this.metadata=r}return C(e,[{key:"typeId",get:function(){return this.type&&this.type.typeId}},{key:"clone",value:function(){return new e(this.name,this.type,this.nullable,this.metadata)}},{key:"compareTo",value:function(e){return this.name===e.name&&this.type===e.type&&this.nullable===e.nullable&&this.metadata===e.metadata}},{key:"toString",value:function(){return"".concat(this.type).concat(this.nullable?", nullable":"").concat(this.metadata?", metadata: ".concat(this.metadata):"")}}]),e}();!function(e){e[e.NONE=0]="NONE",e[e.Null=1]="Null",e[e.Int=2]="Int",e[e.Float=3]="Float",e[e.Binary=4]="Binary",e[e.Utf8=5]="Utf8",e[e.Bool=6]="Bool",e[e.Decimal=7]="Decimal",e[e.Date=8]="Date",e[e.Time=9]="Time",e[e.Timestamp=10]="Timestamp",e[e.Interval=11]="Interval",e[e.List=12]="List",e[e.Struct=13]="Struct",e[e.Union=14]="Union",e[e.FixedSizeBinary=15]="FixedSizeBinary",e[e.FixedSizeList=16]="FixedSizeList",e[e.Map=17]="Map",e[e.Dictionary=-1]="Dictionary",e[e.Int8=-2]="Int8",e[e.Int16=-3]="Int16",e[e.Int32=-4]="Int32",e[e.Int64=-5]="Int64",e[e.Uint8=-6]="Uint8",e[e.Uint16=-7]="Uint16",e[e.Uint32=-8]="Uint32",e[e.Uint64=-9]="Uint64",e[e.Float16=-10]="Float16",e[e.Float32=-11]="Float32",e[e.Float64=-12]="Float64",e[e.DateDay=-13]="DateDay",e[e.DateMillisecond=-14]="DateMillisecond",e[e.TimestampSecond=-15]="TimestampSecond",e[e.TimestampMillisecond=-16]="TimestampMillisecond",e[e.TimestampMicrosecond=-17]="TimestampMicrosecond",e[e.TimestampNanosecond=-18]="TimestampNanosecond",e[e.TimeSecond=-19]="TimeSecond",e[e.TimeMillisecond=-20]="TimeMillisecond",e[e.TimeMicrosecond=-21]="TimeMicrosecond",e[e.TimeNanosecond=-22]="TimeNanosecond",e[e.DenseUnion=-23]="DenseUnion",e[e.SparseUnion=-24]="SparseUnion",e[e.IntervalDayTime=-25]="IntervalDayTime",e[e.IntervalYearMonth=-26]="IntervalYearMonth"}(mC||(mC={}));var yC=function(){function e(){x(this,e)}return C(e,[{key:"typeId",get:function(){return mC.NONE}},{key:"compareTo",value:function(e){return this===e}}],[{key:"isNull",value:function(e){return e&&e.typeId===mC.Null}},{key:"isInt",value:function(e){return e&&e.typeId===mC.Int}},{key:"isFloat",value:function(e){return e&&e.typeId===mC.Float}},{key:"isBinary",value:function(e){return e&&e.typeId===mC.Binary}},{key:"isUtf8",value:function(e){return e&&e.typeId===mC.Utf8}},{key:"isBool",value:function(e){return e&&e.typeId===mC.Bool}},{key:"isDecimal",value:function(e){return e&&e.typeId===mC.Decimal}},{key:"isDate",value:function(e){return e&&e.typeId===mC.Date}},{key:"isTime",value:function(e){return e&&e.typeId===mC.Time}},{key:"isTimestamp",value:function(e){return e&&e.typeId===mC.Timestamp}},{key:"isInterval",value:function(e){return e&&e.typeId===mC.Interval}},{key:"isList",value:function(e){return e&&e.typeId===mC.List}},{key:"isStruct",value:function(e){return e&&e.typeId===mC.Struct}},{key:"isUnion",value:function(e){return e&&e.typeId===mC.Union}},{key:"isFixedSizeBinary",value:function(e){return e&&e.typeId===mC.FixedSizeBinary}},{key:"isFixedSizeList",value:function(e){return e&&e.typeId===mC.FixedSizeList}},{key:"isMap",value:function(e){return e&&e.typeId===mC.Map}},{key:"isDictionary",value:function(e){return e&&e.typeId===mC.Dictionary}}]),e}(),bC=function(e,t){g(s,yC);var i=_(s);function s(e,t){var r;return x(this,s),fb(b(r=i.call(this)),"isSigned",void 0),fb(b(r),"bitWidth",void 0),r.isSigned=e,r.bitWidth=t,r}return C(s,[{key:"typeId",get:function(){return mC.Int}},{key:t,get:function(){return"Int"}},{key:"toString",value:function(){return"".concat(this.isSigned?"I":"Ui","nt").concat(this.bitWidth)}}]),s}(0,Symbol.toStringTag),wC=function(e){g(i,bC);var t=_(i);function i(){return x(this,i),t.call(this,!0,8)}return C(i)}(),BC=function(e){g(i,bC);var t=_(i);function i(){return x(this,i),t.call(this,!0,16)}return C(i)}(),xC=function(e){g(i,bC);var t=_(i);function i(){return x(this,i),t.call(this,!0,32)}return C(i)}(),PC=function(e){g(i,bC);var t=_(i);function i(){return x(this,i),t.call(this,!1,8)}return C(i)}(),CC=function(e){g(i,bC);var t=_(i);function i(){return x(this,i),t.call(this,!1,16)}return C(i)}(),MC=function(e){g(i,bC);var t=_(i);function i(){return x(this,i),t.call(this,!1,32)}return C(i)}(),FC=32,EC=64,kC=function(e,t){g(s,yC);var i=_(s);function s(e){var t;return x(this,s),fb(b(t=i.call(this)),"precision",void 0),t.precision=e,t}return C(s,[{key:"typeId",get:function(){return mC.Float}},{key:t,get:function(){return"Float"}},{key:"toString",value:function(){return"Float".concat(this.precision)}}]),s}(0,Symbol.toStringTag),IC=function(e){g(i,kC);var t=_(i);function i(){return x(this,i),t.call(this,FC)}return C(i)}(),DC=function(e){g(i,kC);var t=_(i);function i(){return x(this,i),t.call(this,EC)}return C(i)}(),SC=function(e,t){g(s,yC);var i=_(s);function s(e,t){var r;return x(this,s),fb(b(r=i.call(this)),"listSize",void 0),fb(b(r),"children",void 0),r.listSize=e,r.children=[t],r}return C(s,[{key:"typeId",get:function(){return mC.FixedSizeList}},{key:"valueType",get:function(){return this.children[0].type}},{key:"valueField",get:function(){return this.children[0]}},{key:t,get:function(){return"FixedSizeList"}},{key:"toString",value:function(){return"FixedSizeList[".concat(this.listSize,"]<").concat(this.valueType,">")}}]),s}(0,Symbol.toStringTag);function TC(e,t,i){var s=function(e){switch(e.constructor){case Int8Array:return new wC;case Uint8Array:return new PC;case Int16Array:return new BC;case Uint16Array:return new CC;case Int32Array:return new xC;case Uint32Array:return new MC;case Float32Array:return new IC;case Float64Array:return new DC;default:throw new Error("array type not supported")}}(t.value),r=i||function(e){var t=new Map;"byteOffset"in e&&t.set("byteOffset",e.byteOffset.toString(10));"byteStride"in e&&t.set("byteStride",e.byteStride.toString(10));"normalized"in e&&t.set("normalized",e.normalized.toString());return t}(t);return new _C(e,new SC(t.size,new _C("value",s)),!1,r)}function RC(e,t,i){var s=UC(t.metadata),r=[],n=function(e){var t={};for(var i in e){var s=e[i];t[s.name||"undefined"]=s}return t}(t.attributes);for(var o in e){var a=LC(o,e[o],n[o]);r.push(a)}if(i){var l=LC("indices",i);r.push(l)}return new vC(r,s)}function LC(e,t,i){return TC(e,t,i?UC(i.metadata):void 0)}function UC(e){var t=new Map;for(var i in e)t.set("".concat(i,".string"),JSON.stringify(e[i]));return t}var OC={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},NC={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},QC=function(){function e(t){x(this,e),fb(this,"draco",void 0),fb(this,"decoder",void 0),fb(this,"metadataQuerier",void 0),this.draco=t,this.decoder=new this.draco.Decoder,this.metadataQuerier=new this.draco.MetadataQuerier}return C(e,[{key:"destroy",value:function(){this.draco.destroy(this.decoder),this.draco.destroy(this.metadataQuerier)}},{key:"parseSync",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=new this.draco.DecoderBuffer;i.Init(new Int8Array(e),e.byteLength),this._disableAttributeTransforms(t);var s=this.decoder.GetEncodedGeometryType(i),r=s===this.draco.TRIANGULAR_MESH?new this.draco.Mesh:new this.draco.PointCloud;try{var o;switch(s){case this.draco.TRIANGULAR_MESH:o=this.decoder.DecodeBufferToMesh(i,r);break;case this.draco.POINT_CLOUD:o=this.decoder.DecodeBufferToPointCloud(i,r);break;default:throw new Error("DRACO: Unknown geometry type.")}if(!o.ok()||!r.ptr){var a="DRACO decompression failed: ".concat(o.error_msg());throw new Error(a)}var l=this._getDracoLoaderData(r,s,t),u=this._getMeshData(r,l,t),A=fC(u.attributes),c=RC(u.attributes,l,u.indices),h=n(n({loader:"draco",loaderData:l,header:{vertexCount:r.num_points(),boundingBox:A}},u),{},{schema:c});return h}finally{this.draco.destroy(i),r&&this.draco.destroy(r)}}},{key:"_getDracoLoaderData",value:function(e,t,i){var s=this._getTopLevelMetadata(e),r=this._getDracoAttributes(e,i);return{geometry_type:t,num_attributes:e.num_attributes(),num_points:e.num_points(),num_faces:e instanceof this.draco.Mesh?e.num_faces():0,metadata:s,attributes:r}}},{key:"_getDracoAttributes",value:function(e,t){for(var i={},s=0;s2&&void 0!==arguments[2]&&arguments[2];if(!e)return null;if(Array.isArray(e))return new t(e);if(i&&!(e instanceof t))return new t(e);return e}(t,Float32Array)),s=t.length/i);return{buffer:t,size:i,count:s}}(e),i=t.buffer,s=t.size;return{value:i,size:s,byteOffset:0,count:t.count,type:HP(s),componentType:jP(i)}}function eM(){return(eM=u(a().mark((function e(t,i,s){var r,n,o,l,u,A;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=i&&null!==(r=i.gltf)&&void 0!==r&&r.decompressMeshes){e.next=2;break}return e.abrupt("return");case 2:n=new KP(t),o=[],l=c(nM(n));try{for(l.s();!(u=l.n()).done;)A=u.value,n.getObjectExtension(A,"KHR_draco_mesh_compression")&&o.push(tM(n,A,i,s))}catch(e){l.e(e)}finally{l.f()}return e.next=8,Promise.all(o);case 8:n.removeExtension("KHR_draco_mesh_compression");case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function tM(e,t,i,s){return iM.apply(this,arguments)}function iM(){return iM=u(a().mark((function e(t,i,s,r){var o,l,u,A,c,d,p,f,v,g,m,_,y,b;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=t.getObjectExtension(i,"KHR_draco_mesh_compression")){e.next=3;break}return e.abrupt("return");case 3:return l=t.getTypedArrayForBufferView(o.bufferView),u=Xb(l.buffer,l.byteOffset),A=r.parse,delete(c=n({},s))["3d-tiles"],e.next=10,A(u,YC,c,r);case 10:for(d=e.sent,p=qC(d.attributes),f=0,v=Object.entries(p);f2&&void 0!==arguments[2]?arguments[2]:4,r=arguments.length>3?arguments[3]:void 0,n=arguments.length>4?arguments[4]:void 0;if(!r.DracoWriter)throw new Error("options.gltf.DracoWriter not provided");var a=r.DracoWriter.encodeSync({attributes:e}),l=null==n||null===(i=n.parseSync)||void 0===i?void 0:i.call(n,{attributes:e}),u=r._addFauxAttributes(l.attributes),A=r.addBufferView(a),c={primitives:[{attributes:u,mode:s,extensions:o({},"KHR_draco_mesh_compression",{bufferView:A,attributes:u})}]};return c}function rM(e){if(!e.attributes&&Object.keys(e.attributes).length>0)throw new Error("glTF: Empty primitive detected: Draco decompression failure?")}function nM(e){var t,i,r,n,o,l;return a().wrap((function(s){for(;;)switch(s.prev=s.next){case 0:t=c(e.json.meshes||[]),s.prev=1,t.s();case 3:if((i=t.n()).done){s.next=24;break}r=i.value,n=c(r.primitives),s.prev=6,n.s();case 8:if((o=n.n()).done){s.next=14;break}return l=o.value,s.next=12,l;case 12:s.next=8;break;case 14:s.next=19;break;case 16:s.prev=16,s.t0=s.catch(6),n.e(s.t0);case 19:return s.prev=19,n.f(),s.finish(19);case 22:s.next=3;break;case 24:s.next=29;break;case 26:s.prev=26,s.t1=s.catch(1),t.e(s.t1);case 29:return s.prev=29,t.f(),s.finish(29);case 32:case"end":return s.stop()}}),s,null,[[1,26,29,32],[6,16,19,22]])}function oM(){return(oM=u(a().mark((function e(t){var i,s,r,n,o,l,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=new KP(t),s=i.json,(r=i.getExtension("KHR_lights_punctual"))&&(i.json.lights=r.lights,i.removeExtension("KHR_lights_punctual")),n=c(s.nodes||[]);try{for(n.s();!(o=n.n()).done;)l=o.value,(u=i.getObjectExtension(l,"KHR_lights_punctual"))&&(l.light=u.light),i.removeObjectExtension(l,"KHR_lights_punctual")}catch(e){n.e(e)}finally{n.f()}case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function aM(){return(aM=u(a().mark((function e(t){var i,s,r,n,o,l,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=new KP(t),(s=i.json).lights&&(SP(!(r=i.addExtension("KHR_lights_punctual")).lights),r.lights=s.lights,delete s.lights),i.json.lights){n=c(i.json.lights);try{for(n.s();!(o=n.n()).done;)l=o.value,u=l.node,i.addObjectExtension(u,"KHR_lights_punctual",l)}catch(e){n.e(e)}finally{n.f()}delete i.json.lights}case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function lM(){return(lM=u(a().mark((function e(t){var i,s,r,n,o;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=new KP(t),s=i.json,i.removeExtension("KHR_materials_unlit"),r=c(s.materials||[]);try{for(r.s();!(n=r.n()).done;)o=n.value,o.extensions&&o.extensions.KHR_materials_unlit&&(o.unlit=!0),i.removeObjectExtension(o,"KHR_materials_unlit")}catch(e){r.e(e)}finally{r.f()}case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function uM(){return(uM=u(a().mark((function e(t){var i,s,r,n,o,l,u,A;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=new KP(t),s=i.json,r=i.getExtension("KHR_techniques_webgl")){n=cM(r,i),o=c(s.materials||[]);try{for(o.s();!(l=o.n()).done;)u=l.value,(A=i.getObjectExtension(u,"KHR_techniques_webgl"))&&(u.technique=Object.assign({},A,n[A.technique]),u.technique.values=hM(u.technique,i)),i.removeObjectExtension(u,"KHR_techniques_webgl")}catch(e){o.e(e)}finally{o.f()}i.removeExtension("KHR_techniques_webgl")}case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function AM(){return(AM=u(a().mark((function e(t,i){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function cM(e,t){var i=e.programs,s=void 0===i?[]:i,r=e.shaders,n=void 0===r?[]:r,o=e.techniques,a=void 0===o?[]:o,l=new TextDecoder;return n.forEach((function(e){if(!Number.isFinite(e.bufferView))throw new Error("KHR_techniques_webgl: no shader code");e.code=l.decode(t.getTypedArrayForBufferView(e.bufferView))})),s.forEach((function(e){e.fragmentShader=n[e.fragmentShader],e.vertexShader=n[e.vertexShader]})),a.forEach((function(e){e.program=s[e.program]})),a}function hM(e,t){var i=Object.assign({},e.values);return Object.keys(e.uniforms||{}).forEach((function(t){e.uniforms[t].value&&!(t in i)&&(i[t]=e.uniforms[t].value)})),Object.keys(i).forEach((function(e){"object"===B(i[e])&&void 0!==i[e].index&&(i[e].texture=t.getTexture(i[e].index))})),i}var dM=[cC,hC,dC,Object.freeze({__proto__:null,name:"KHR_draco_mesh_compression",preprocess:function(e,t,i){var s,r=new KP(e),n=c(nM(r));try{for(n.s();!(s=n.n()).done;){var o=s.value;r.getObjectExtension(o,"KHR_draco_mesh_compression")}}catch(e){n.e(e)}finally{n.f()}},decode:function(e,t,i){return eM.apply(this,arguments)},encode:function(e){var t,i=new KP(e),s=c(i.json.meshes||[]);try{for(s.s();!(t=s.n()).done;){var r=t.value;sM(r),i.addRequiredExtension("KHR_draco_mesh_compression")}}catch(e){s.e(e)}finally{s.f()}}}),Object.freeze({__proto__:null,name:"KHR_lights_punctual",decode:function(e){return oM.apply(this,arguments)},encode:function(e){return aM.apply(this,arguments)}}),Object.freeze({__proto__:null,name:"KHR_materials_unlit",decode:function(e){return lM.apply(this,arguments)},encode:function(e){var t=new KP(e),i=t.json;if(t.materials){var s,r=c(i.materials||[]);try{for(r.s();!(s=r.n()).done;){var n=s.value;n.unlit&&(delete n.unlit,t.addObjectExtension(n,"KHR_materials_unlit",{}),t.addExtension("KHR_materials_unlit"))}}catch(e){r.e(e)}finally{r.f()}}}}),Object.freeze({__proto__:null,name:"KHR_techniques_webgl",decode:function(e){return uM.apply(this,arguments)},encode:function(e,t){return AM.apply(this,arguments)}})];function pM(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,r=dM.filter((function(e){return gM(e.name,i)})),n=c(r);try{for(n.s();!(t=n.n()).done;){var o,a=t.value;null===(o=a.preprocess)||void 0===o||o.call(a,e,i,s)}}catch(e){n.e(e)}finally{n.f()}}function fM(e){return vM.apply(this,arguments)}function vM(){return vM=u(a().mark((function e(t){var i,s,r,n,o,l,u,A=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=A.length>1&&void 0!==A[1]?A[1]:{},s=A.length>2?A[2]:void 0,r=dM.filter((function(e){return gM(e.name,i)})),n=c(r),e.prev=4,n.s();case 6:if((o=n.n()).done){e.next=12;break}return l=o.value,e.next=10,null===(u=l.decode)||void 0===u?void 0:u.call(l,t,i,s);case 10:e.next=6;break;case 12:e.next=17;break;case 14:e.prev=14,e.t0=e.catch(4),n.e(e.t0);case 17:return e.prev=17,n.f(),e.finish(17);case 20:case"end":return e.stop()}}),e,null,[[4,14,17,20]])}))),vM.apply(this,arguments)}function gM(e,t){var i,s=(null==t||null===(i=t.gltf)||void 0===i?void 0:i.excludeExtensions)||{};return!(e in s&&!s[e])}var mM={accessors:"accessor",animations:"animation",buffers:"buffer",bufferViews:"bufferView",images:"image",materials:"material",meshes:"mesh",nodes:"node",samplers:"sampler",scenes:"scene",skins:"skin",textures:"texture"},_M={accessor:"accessors",animations:"animation",buffer:"buffers",bufferView:"bufferViews",image:"images",material:"materials",mesh:"meshes",node:"nodes",sampler:"samplers",scene:"scenes",skin:"skins",texture:"textures"},yM=function(){function e(){x(this,e),fb(this,"idToIndexMap",{animations:{},accessors:{},buffers:{},bufferViews:{},images:{},materials:{},meshes:{},nodes:{},samplers:{},scenes:{},skins:{},textures:{}}),fb(this,"json",void 0)}return C(e,[{key:"normalize",value:function(e,t){this.json=e.json;var i=e.json;switch(i.asset&&i.asset.version){case"2.0":return;case void 0:case"1.0":break;default:return void console.warn("glTF: Unknown version ".concat(i.asset.version))}if(!t.normalize)throw new Error("glTF v1 is not supported.");console.warn("Converting glTF v1 to glTF v2 format. This is experimental and may fail."),this._addAsset(i),this._convertTopLevelObjectsToArrays(i),function(e){var t,i=new KP(e),s=i.json,r=c(s.images||[]);try{for(r.s();!(t=r.n()).done;){var n=t.value,o=i.getObjectExtension(n,"KHR_binary_glTF");o&&Object.assign(n,o),i.removeObjectExtension(n,"KHR_binary_glTF")}}catch(e){r.e(e)}finally{r.f()}s.buffers&&s.buffers[0]&&delete s.buffers[0].uri,i.removeExtension("KHR_binary_glTF")}(e),this._convertObjectIdsToArrayIndices(i),this._updateObjects(i),this._updateMaterial(i)}},{key:"_addAsset",value:function(e){e.asset=e.asset||{},e.asset.version="2.0",e.asset.generator=e.asset.generator||"Normalized to glTF 2.0 by loaders.gl"}},{key:"_convertTopLevelObjectsToArrays",value:function(e){for(var t in mM)this._convertTopLevelObjectToArray(e,t)}},{key:"_convertTopLevelObjectToArray",value:function(e,t){var i=e[t];if(i&&!Array.isArray(i))for(var s in e[t]=[],i){var r=i[s];r.id=r.id||s;var n=e[t].length;e[t].push(r),this.idToIndexMap[t][s]=n}}},{key:"_convertObjectIdsToArrayIndices",value:function(e){for(var t in mM)this._convertIdsToIndices(e,t);"scene"in e&&(e.scene=this._convertIdToIndex(e.scene,"scene"));var i,s=c(e.textures);try{for(s.s();!(i=s.n()).done;){var r=i.value;this._convertTextureIds(r)}}catch(e){s.e(e)}finally{s.f()}var n,o=c(e.meshes);try{for(o.s();!(n=o.n()).done;){var a=n.value;this._convertMeshIds(a)}}catch(e){o.e(e)}finally{o.f()}var l,u=c(e.nodes);try{for(u.s();!(l=u.n()).done;){var A=l.value;this._convertNodeIds(A)}}catch(e){u.e(e)}finally{u.f()}var h,d=c(e.scenes);try{for(d.s();!(h=d.n()).done;){var p=h.value;this._convertSceneIds(p)}}catch(e){d.e(e)}finally{d.f()}}},{key:"_convertTextureIds",value:function(e){e.source&&(e.source=this._convertIdToIndex(e.source,"image"))}},{key:"_convertMeshIds",value:function(e){var t,i=c(e.primitives);try{for(i.s();!(t=i.n()).done;){var s=t.value,r=s.attributes,n=s.indices,o=s.material;for(var a in r)r[a]=this._convertIdToIndex(r[a],"accessor");n&&(s.indices=this._convertIdToIndex(n,"accessor")),o&&(s.material=this._convertIdToIndex(o,"material"))}}catch(e){i.e(e)}finally{i.f()}}},{key:"_convertNodeIds",value:function(e){var t=this;e.children&&(e.children=e.children.map((function(e){return t._convertIdToIndex(e,"node")}))),e.meshes&&(e.meshes=e.meshes.map((function(e){return t._convertIdToIndex(e,"mesh")})))}},{key:"_convertSceneIds",value:function(e){var t=this;e.nodes&&(e.nodes=e.nodes.map((function(e){return t._convertIdToIndex(e,"node")})))}},{key:"_convertIdsToIndices",value:function(e,t){e[t]||(console.warn("gltf v1: json doesn't contain attribute ".concat(t)),e[t]=[]);var i,s=c(e[t]);try{for(s.s();!(i=s.n()).done;){var r=i.value;for(var n in r){var o=r[n],a=this._convertIdToIndex(o,n);r[n]=a}}}catch(e){s.e(e)}finally{s.f()}}},{key:"_convertIdToIndex",value:function(e,t){var i=_M[t];if(i in this.idToIndexMap){var s=this.idToIndexMap[i][e];if(!Number.isFinite(s))throw new Error("gltf v1: failed to resolve ".concat(t," with id ").concat(e));return s}return e}},{key:"_updateObjects",value:function(e){var t,i=c(this.json.buffers);try{for(i.s();!(t=i.n()).done;){delete t.value.type}}catch(e){i.e(e)}finally{i.f()}}},{key:"_updateMaterial",value:function(e){var t,i=c(e.materials);try{var s=function(){var i=t.value;i.pbrMetallicRoughness={baseColorFactor:[1,1,1,1],metallicFactor:1,roughnessFactor:1};var s=(null===(r=i.values)||void 0===r?void 0:r.tex)||(null===(n=i.values)||void 0===n?void 0:n.texture2d_0),o=e.textures.findIndex((function(e){return e.id===s}));-1!==o&&(i.pbrMetallicRoughness.baseColorTexture={index:o})};for(i.s();!(t=i.n()).done;){var r,n;s()}}catch(e){i.e(e)}finally{i.f()}}}]),e}();function bM(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(new yM).normalize(e,t)}var wM={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},BM={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},xM=10240,PM=10241,CM=10242,MM=10243,FM=10497,EM=9986,kM={magFilter:xM,minFilter:PM,wrapS:CM,wrapT:MM},IM=(o(e={},xM,9729),o(e,PM,EM),o(e,CM,FM),o(e,MM,FM),e);var DM=function(){function e(){x(this,e),fb(this,"baseUri",""),fb(this,"json",{}),fb(this,"buffers",[]),fb(this,"images",[])}return C(e,[{key:"postProcess",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=e.json,s=e.buffers,r=void 0===s?[]:s,n=e.images,o=void 0===n?[]:n,a=e.baseUri,l=void 0===a?"":a;return SP(i),this.baseUri=l,this.json=i,this.buffers=r,this.images=o,this._resolveTree(this.json,t),this.json}},{key:"_resolveTree",value:function(e){var t=this;e.bufferViews&&(e.bufferViews=e.bufferViews.map((function(e,i){return t._resolveBufferView(e,i)}))),e.images&&(e.images=e.images.map((function(e,i){return t._resolveImage(e,i)}))),e.samplers&&(e.samplers=e.samplers.map((function(e,i){return t._resolveSampler(e,i)}))),e.textures&&(e.textures=e.textures.map((function(e,i){return t._resolveTexture(e,i)}))),e.accessors&&(e.accessors=e.accessors.map((function(e,i){return t._resolveAccessor(e,i)}))),e.materials&&(e.materials=e.materials.map((function(e,i){return t._resolveMaterial(e,i)}))),e.meshes&&(e.meshes=e.meshes.map((function(e,i){return t._resolveMesh(e,i)}))),e.nodes&&(e.nodes=e.nodes.map((function(e,i){return t._resolveNode(e,i)}))),e.skins&&(e.skins=e.skins.map((function(e,i){return t._resolveSkin(e,i)}))),e.scenes&&(e.scenes=e.scenes.map((function(e,i){return t._resolveScene(e,i)}))),void 0!==e.scene&&(e.scene=e.scenes[this.json.scene])}},{key:"getScene",value:function(e){return this._get("scenes",e)}},{key:"getNode",value:function(e){return this._get("nodes",e)}},{key:"getSkin",value:function(e){return this._get("skins",e)}},{key:"getMesh",value:function(e){return this._get("meshes",e)}},{key:"getMaterial",value:function(e){return this._get("materials",e)}},{key:"getAccessor",value:function(e){return this._get("accessors",e)}},{key:"getCamera",value:function(e){return null}},{key:"getTexture",value:function(e){return this._get("textures",e)}},{key:"getSampler",value:function(e){return this._get("samplers",e)}},{key:"getImage",value:function(e){return this._get("images",e)}},{key:"getBufferView",value:function(e){return this._get("bufferViews",e)}},{key:"getBuffer",value:function(e){return this._get("buffers",e)}},{key:"_get",value:function(e,t){if("object"===B(t))return t;var i=this.json[e]&&this.json[e][t];return i||console.warn("glTF file error: Could not find ".concat(e,"[").concat(t,"]")),i}},{key:"_resolveScene",value:function(e,t){var i=this;return e.id=e.id||"scene-".concat(t),e.nodes=(e.nodes||[]).map((function(e){return i.getNode(e)})),e}},{key:"_resolveNode",value:function(e,t){var i=this;return e.id=e.id||"node-".concat(t),e.children&&(e.children=e.children.map((function(e){return i.getNode(e)}))),void 0!==e.mesh?e.mesh=this.getMesh(e.mesh):void 0!==e.meshes&&e.meshes.length&&(e.mesh=e.meshes.reduce((function(e,t){var s=i.getMesh(t);return e.id=s.id,e.primitives=e.primitives.concat(s.primitives),e}),{primitives:[]})),void 0!==e.camera&&(e.camera=this.getCamera(e.camera)),void 0!==e.skin&&(e.skin=this.getSkin(e.skin)),e}},{key:"_resolveSkin",value:function(e,t){return e.id=e.id||"skin-".concat(t),e.inverseBindMatrices=this.getAccessor(e.inverseBindMatrices),e}},{key:"_resolveMesh",value:function(e,t){var i=this;return e.id=e.id||"mesh-".concat(t),e.primitives&&(e.primitives=e.primitives.map((function(e){var t=(e=n({},e)).attributes;for(var s in e.attributes={},t)e.attributes[s]=i.getAccessor(t[s]);return void 0!==e.indices&&(e.indices=i.getAccessor(e.indices)),void 0!==e.material&&(e.material=i.getMaterial(e.material)),e}))),e}},{key:"_resolveMaterial",value:function(e,t){if(e.id=e.id||"material-".concat(t),e.normalTexture&&(e.normalTexture=n({},e.normalTexture),e.normalTexture.texture=this.getTexture(e.normalTexture.index)),e.occlusionTexture&&(e.occlustionTexture=n({},e.occlustionTexture),e.occlusionTexture.texture=this.getTexture(e.occlusionTexture.index)),e.emissiveTexture&&(e.emmisiveTexture=n({},e.emmisiveTexture),e.emissiveTexture.texture=this.getTexture(e.emissiveTexture.index)),e.emissiveFactor||(e.emissiveFactor=e.emmisiveTexture?[1,1,1]:[0,0,0]),e.pbrMetallicRoughness){e.pbrMetallicRoughness=n({},e.pbrMetallicRoughness);var i=e.pbrMetallicRoughness;i.baseColorTexture&&(i.baseColorTexture=n({},i.baseColorTexture),i.baseColorTexture.texture=this.getTexture(i.baseColorTexture.index)),i.metallicRoughnessTexture&&(i.metallicRoughnessTexture=n({},i.metallicRoughnessTexture),i.metallicRoughnessTexture.texture=this.getTexture(i.metallicRoughnessTexture.index))}return e}},{key:"_resolveAccessor",value:function(e,t){var i,s;if(e.id=e.id||"accessor-".concat(t),void 0!==e.bufferView&&(e.bufferView=this.getBufferView(e.bufferView)),e.bytesPerComponent=(i=e.componentType,BM[i]),e.components=(s=e.type,wM[s]),e.bytesPerElement=e.bytesPerComponent*e.components,e.bufferView){var r=e.bufferView.buffer,n=GP(e,e.bufferView),o=n.ArrayType,a=n.byteLength,l=(e.bufferView.byteOffset||0)+(e.byteOffset||0)+r.byteOffset,u=r.arrayBuffer.slice(l,l+a);e.bufferView.byteStride&&(u=this._getValueFromInterleavedBuffer(r,l,e.bufferView.byteStride,e.bytesPerElement,e.count)),e.value=new o(u)}return e}},{key:"_getValueFromInterleavedBuffer",value:function(e,t,i,s,r){for(var n=new Uint8Array(r*s),o=0;o1&&void 0!==arguments[1]?arguments[1]:0;return"".concat(String.fromCharCode(e.getUint8(t+0))).concat(String.fromCharCode(e.getUint8(t+1))).concat(String.fromCharCode(e.getUint8(t+2))).concat(String.fromCharCode(e.getUint8(t+3)))}function LM(e,t,i){nb(e.header.byteLength>20);var s=t.getUint32(i+0,TM),r=t.getUint32(i+4,TM);return i+=8,nb(0===r),OM(e,t,i,s),i+=s,i+=NM(e,t,i,e.header.byteLength)}function UM(e,t,i,s){return nb(e.header.byteLength>20),function(e,t,i,s){for(;i+8<=e.header.byteLength;){var r=t.getUint32(i+0,TM),n=t.getUint32(i+4,TM);switch(i+=8,n){case 1313821514:OM(e,t,i,r);break;case 5130562:NM(e,t,i,r);break;case 0:s.strict||OM(e,t,i,r);break;case 1:s.strict||NM(e,t,i,r)}i+=Jb(r,4)}}(e,t,i,s),i+e.header.byteLength}function OM(e,t,i,s){var r=new Uint8Array(t.buffer,i,s),n=new TextDecoder("utf8").decode(r);return e.json=JSON.parse(n),Jb(s,4)}function NM(e,t,i,s){return e.header.hasBinChunk=!0,e.binChunks.push({byteOffset:i,byteLength:s,arrayBuffer:t.buffer}),Jb(s,4)}function QM(e,t){return VM.apply(this,arguments)}function VM(){return VM=u(a().mark((function e(t,i){var s,r,n,o,l,u,A,c,h,d,p=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(s=p.length>2&&void 0!==p[2]?p[2]:0,r=p.length>3?p[3]:void 0,n=p.length>4?p[4]:void 0,HM(t,i,s,r),bM(t,{normalize:null==r||null===(o=r.gltf)||void 0===o?void 0:o.normalize}),pM(t,r,n),c=[],null==r||null===(l=r.gltf)||void 0===l||!l.loadBuffers||!t.json.buffers){e.next=10;break}return e.next=10,jM(t,r,n);case 10:return null!=r&&null!==(u=r.gltf)&&void 0!==u&&u.loadImages&&(h=zM(t,r,n),c.push(h)),d=fM(t,r,n),c.push(d),e.next=15,Promise.all(c);case 15:return e.abrupt("return",null!=r&&null!==(A=r.gltf)&&void 0!==A&&A.postProcess?SM(t,r):t);case 16:case"end":return e.stop()}}),e)}))),VM.apply(this,arguments)}function HM(e,t,i,s){(s.uri&&(e.baseUri=s.uri),t instanceof ArrayBuffer&&!function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=new DataView(e),r=i.magic,n=void 0===r?1735152710:r,o=s.getUint32(t,!1);return o===n||1735152710===o}(t,i,s))&&(t=(new TextDecoder).decode(t));if("string"==typeof t)e.json=Gb(t);else if(t instanceof ArrayBuffer){var r={};i=function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=new DataView(t),r=RM(s,i+0),n=s.getUint32(i+4,TM),o=s.getUint32(i+8,TM);switch(Object.assign(e,{header:{byteOffset:i,byteLength:o,hasBinChunk:!1},type:r,version:n,json:{},binChunks:[]}),i+=12,e.version){case 1:return LM(e,s,i);case 2:return UM(e,s,i,{});default:throw new Error("Invalid GLB version ".concat(e.version,". Only supports v1 and v2."))}}(r,t,i,s.glb),SP("glTF"===r.type,"Invalid GLB magic string ".concat(r.type)),e._glb=r,e.json=r.json}else SP(!1,"GLTF: must be ArrayBuffer or string");var n=e.json.buffers||[];if(e.buffers=new Array(n.length).fill(null),e._glb&&e._glb.header.hasBinChunk){var o=e._glb.binChunks;e.buffers[0]={arrayBuffer:o[0].arrayBuffer,byteOffset:o[0].byteOffset,byteLength:o[0].byteLength}}var a=e.json.images||[];e.images=new Array(a.length).fill({})}function jM(e,t,i){return GM.apply(this,arguments)}function GM(){return(GM=u(a().mark((function e(t,i,s){var r,n,o,l,u,A,c,h;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=t.json.buffers||[],n=0;case 2:if(!(n1&&void 0!==u[1]?u[1]:{},s=u.length>2?u[2]:void 0,(i=n(n({},YM.options),i)).gltf=n(n({},YM.options.gltf),i.gltf),r=i.byteOffset,o=void 0===r?0:r,l={},e.next=8,QM(l,t,o,i,s);case 8:return e.abrupt("return",e.sent);case 9:case"end":return e.stop()}}),e)}))),ZM.apply(this,arguments)}var qM=function(){function e(t){x(this,e)}return C(e,[{key:"load",value:function(e,t,i,s,r,n,o){!function(e,t,i,s,r,n,o){var a=e.viewer.scene.canvas.spinner;a.processes++,"glb"===t.split(".").pop()?e.dataSource.getGLB(t,(function(o){s.basePath=eF(t),tF(e,t,o,i,s,r,n),a.processes--}),(function(e){a.processes--,o(e)})):e.dataSource.getGLTF(t,(function(o){s.basePath=eF(t),tF(e,t,o,i,s,r,n),a.processes--}),(function(e){a.processes--,o(e)}))}(e,t,i,s=s||{},r,(function(){_e.scheduleTask((function(){r.scene.fire("modelLoaded",r.id),r.fire("loaded",!0,!1)})),n&&n()}),(function(t){e.error(t),o&&o(t),r.fire("error",t)}))}},{key:"parse",value:function(e,t,i,s,r,n,o){tF(e,"",t,i,s=s||{},r,(function(){r.scene.fire("modelLoaded",r.id),r.fire("loaded",!0,!1),n&&n()}))}}]),e}();function $M(e){for(var t={},i={},s=e.metaObjects||[],r={},n=0,o=s.length;n0)for(var A=0;A0){null==y&&e.log("Warning: 'name' properties not found on glTF scene nodes - will randomly-generate object IDs in XKT");var b=y;if(e.metaModelCorrections){var w=e.metaModelCorrections.eachChildRoot[b];if(w){var B=e.metaModelCorrections.eachRootStats[w.id];B.countChildren++,B.countChildren>=B.numChildren&&(n.createEntity({id:w.id,meshIds:oF}),oF.length=0)}else{e.metaModelCorrections.metaObjectsMap[b]&&(n.createEntity({id:b,meshIds:oF}),oF.length=0)}}else n.createEntity({id:b,meshIds:oF}),oF.length=0}}function lF(e,t){e.plugin.error(t)}var uF={DEFAULT:{}},AF=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"GLTFLoader",e,r))._sceneModelLoader=new qM(b(s),r),s.dataSource=r.dataSource,s.objectDefaults=r.objectDefaults,s}return C(i,[{key:"dataSource",get:function(){return this._dataSource},set:function(e){this._dataSource=e||new Dh}},{key:"objectDefaults",get:function(){return this._objectDefaults},set:function(e){this._objectDefaults=e||uF}},{key:"load",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t.id&&this.viewer.scene.components[t.id]&&(this.error("Component with this ID already exists in viewer: "+t.id+" - will autogenerate this ID"),delete t.id);var i=new ch(this.viewer.scene,le.apply(t,{isModel:!0,dtxEnabled:t.dtxEnabled})),s=i.id;if(!t.src&&!t.gltf)return this.error("load() param expected: src or gltf"),i;if(t.metaModelSrc||t.metaModelJSON){var r=t.objectDefaults||this._objectDefaults||uF,n=function(n){var o;if(e.viewer.metaScene.createMetaModel(s,n,{includeTypes:t.includeTypes,excludeTypes:t.excludeTypes}),e.viewer.scene.canvas.spinner.processes--,t.includeTypes){o={};for(var a=0,l=t.includeTypes.length;a2&&void 0!==arguments[2]?arguments[2]:{},s="lightgrey",r=i.hoverColor||"rgba(0,0,0,0.4)",n=i.textColor||"black",o=500,a=o+o/3,l=a/24,u=[{boundary:[6,6,6,6],color:i.frontColor||i.color||"#55FF55"},{boundary:[18,6,6,6],color:i.backColor||i.color||"#55FF55"},{boundary:[12,6,6,6],color:i.rightColor||i.color||"#FF5555"},{boundary:[0,6,6,6],color:i.leftColor||i.color||"#FF5555"},{boundary:[6,0,6,6],color:i.topColor||i.color||"#7777FF"},{boundary:[6,12,6,6],color:i.bottomColor||i.color||"#7777FF"}],A=[{label:"NavCube.front",boundaries:[[7,7,4,4]],dir:[0,1,0],up:[0,0,1]},{label:"NavCube.back",boundaries:[[19,7,4,4]],dir:[0,-1,0],up:[0,0,1]},{label:"NavCube.right",boundaries:[[13,7,4,4]],dir:[-1,0,0],up:[0,0,1]},{label:"NavCube.left",boundaries:[[1,7,4,4]],dir:[1,0,0],up:[0,0,1]},{label:"NavCube.top",boundaries:[[7,1,4,4]],dir:[0,0,-1],up:[0,1,0]},{label:"NavCube.bottom",boundaries:[[7,13,4,4]],dir:[0,0,1],up:[0,-1,0]},{boundaries:[[7,5,4,2]],dir:[0,1,-1],up:[0,1,1]},{boundaries:[[1,6,4,1],[6,1,1,4]],dir:[1,0,-1],up:[1,0,1]},{boundaries:[[7,0,4,1],[19,6,4,1]],dir:[0,-1,-1],up:[0,-1,1]},{boundaries:[[13,6,4,1],[11,1,1,4]],dir:[-1,0,-1],up:[-1,0,1]},{boundaries:[[7,11,4,2]],dir:[0,1,1],up:[0,-1,1]},{boundaries:[[1,11,4,1],[6,13,1,4]],dir:[1,0,1],up:[-1,0,1]},{boundaries:[[7,17,4,1],[19,11,4,1]],dir:[0,-1,1],up:[0,1,1]},{boundaries:[[13,11,4,1],[11,13,1,4]],dir:[-1,0,1],up:[1,0,1]},{boundaries:[[5,7,2,4]],dir:[1,1,0],up:[0,0,1]},{boundaries:[[11,7,2,4]],dir:[-1,1,0],up:[0,0,1]},{boundaries:[[17,7,2,4]],dir:[-1,-1,0],up:[0,0,1]},{boundaries:[[0,7,1,4],[23,7,1,4]],dir:[1,-1,0],up:[0,0,1]},{boundaries:[[5,11,2,2]],dir:[1,1,1],up:[-1,-1,1]},{boundaries:[[23,11,1,1],[6,17,1,1],[0,11,1,1]],dir:[1,-1,1],up:[-1,1,1]},{boundaries:[[5,5,2,2]],dir:[1,1,-1],up:[1,1,1]},{boundaries:[[11,17,1,1],[17,11,2,1]],dir:[-1,-1,1],up:[1,1,1]},{boundaries:[[17,6,2,1],[11,0,1,1]],dir:[-1,-1,-1],up:[-1,-1,1]},{boundaries:[[11,11,2,2]],dir:[-1,1,1],up:[1,-1,1]},{boundaries:[[0,6,1,1],[6,0,1,1],[23,6,1,1]],dir:[1,-1,-1],up:[1,-1,1]},{boundaries:[[11,5,2,2]],dir:[-1,1,-1],up:[-1,1,1]}];i.frontColor||i.color,i.backColor||i.color,i.rightColor||i.color,i.leftColor||i.color,i.topColor||i.color,i.bottomColor||i.color;for(var c=[{yUp:"",label:"NavCube.front",boundaries:[[7,7,4,4]],dir:[0,0,-1],up:[0,1,0]},{label:"NavCube.back",boundaries:[[19,7,4,4]],dir:[0,0,1],up:[0,1,0]},{label:"NavCube.right",boundaries:[[13,7,4,4]],dir:[-1,0,0],up:[0,1,0]},{label:"NavCube.left",boundaries:[[1,7,4,4]],dir:[1,0,0],up:[0,1,0]},{label:"NavCube.top",boundaries:[[7,1,4,4]],dir:[0,-1,0],up:[0,0,-1]},{label:"NavCube.bottom",boundaries:[[7,13,4,4]],dir:[0,1,0],up:[0,0,1]},{boundaries:[[7,5,4,2]],dir:[0,-.7071,-.7071],up:[0,.7071,-.7071]},{boundaries:[[1,6,4,1],[6,1,1,4]],dir:[1,-1,0],up:[1,1,0]},{boundaries:[[7,0,4,1],[19,6,4,1]],dir:[0,-.7071,.7071],up:[0,.7071,.7071]},{boundaries:[[13,6,4,1],[11,1,1,4]],dir:[-1,-1,0],up:[-1,1,0]},{boundaries:[[7,11,4,2]],dir:[0,1,-1],up:[0,1,1]},{boundaries:[[1,11,4,1],[6,13,1,4]],dir:[1,1,0],up:[-1,1,0]},{boundaries:[[7,17,4,1],[19,11,4,1]],dir:[0,1,1],up:[0,1,-1]},{boundaries:[[13,11,4,1],[11,13,1,4]],dir:[-1,1,0],up:[1,1,0]},{boundaries:[[5,7,2,4]],dir:[1,0,-1],up:[0,1,0]},{boundaries:[[11,7,2,4]],dir:[-1,0,-1],up:[0,1,0]},{boundaries:[[17,7,2,4]],dir:[-1,0,1],up:[0,1,0]},{boundaries:[[0,7,1,4],[23,7,1,4]],dir:[1,0,1],up:[0,1,0]},{boundaries:[[5,11,2,2]],dir:[.5,.7071,-.5],up:[-.5,.7071,.5]},{boundaries:[[23,11,1,1],[6,17,1,1],[0,11,1,1]],dir:[.5,.7071,.5],up:[-.5,.7071,-.5]},{boundaries:[[5,5,2,2]],dir:[.5,-.7071,-.5],up:[.5,.7071,-.5]},{boundaries:[[11,17,1,1],[17,11,2,1]],dir:[-.5,.7071,.5],up:[.5,.7071,-.5]},{boundaries:[[17,6,2,1],[11,0,1,1]],dir:[-.5,-.7071,.5],up:[-.5,.7071,.5]},{boundaries:[[11,11,2,2]],dir:[-.5,.7071,-.5],up:[.5,.7071,.5]},{boundaries:[[0,6,1,1],[6,0,1,1],[23,6,1,1]],dir:[.5,-.7071,.5],up:[.5,.7071,.5]},{boundaries:[[11,5,2,2]],dir:[-.5,-.7071,-.5],up:[-.5,.7071,-.5]}],h=0,d=A.length;h=c[0]*l&&t<=(c[0]+c[2])*l&&i>=c[1]*l&&i<=(c[1]+c[3])*l)return s}return-1},this.setAreaHighlighted=function(e,t){var i=v[e];if(!i)throw"Area not found: "+e;i.highlighted=!!t,y()},this.getAreaDir=function(e){var t=v[e];if(!t)throw"Unknown area: "+e;return t.dir},this.getAreaUp=function(e){var t=v[e];if(!t)throw"Unknown area: "+e;return t.up},this.getImage=function(){return this._textureCanvas},this.destroy=function(){this._textureCanvas&&(this._textureCanvas.parentNode.removeChild(this._textureCanvas),this._textureCanvas=null)}}var hF=$.vec3(),dF=$.vec3();$.mat4();var pF=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),s=t.call(this,"NavCube",e,r),e.navCube=b(s);var n=!0;try{s._navCubeScene=new qi(e,{canvasId:r.canvasId,canvasElement:r.canvasElement,transparent:!0}),s._navCubeCanvas=s._navCubeScene.canvas.canvas,s._navCubeScene.input.keyboardEnabled=!1}catch(e){return s.error(e),y(s)}var o=s._navCubeScene;o.clearLights(),new yi(o,{dir:[.4,-.4,.8],color:[.8,1,1],intensity:1,space:"view"}),new yi(o,{dir:[-.8,-.3,-.4],color:[.8,.8,.8],intensity:1,space:"view"}),new yi(o,{dir:[.8,-.6,-.8],color:[1,1,1],intensity:1,space:"view"}),s._navCubeCamera=o.camera,s._navCubeCamera.ortho.scale=7,s._navCubeCamera.ortho.near=.1,s._navCubeCamera.ortho.far=2e3,o.edgeMaterial.edgeColor=[.2,.2,.2],o.edgeMaterial.edgeAlpha=.6,s._zUp=Boolean(e.camera.zUp);var a=b(s);s.setIsProjectNorth(r.isProjectNorth),s.setProjectNorthOffsetAngle(r.projectNorthOffsetAngle);var l,u=(l=$.mat4(),function(e,t,i){return $.identityMat4(l),$.rotationMat4v(e*a._projectNorthOffsetAngle*$.DEGTORAD,[0,1,0],l),$.transformVec3(l,t,i)});s._synchCamera=function(){var t=$.rotationMat4c(-90*$.DEGTORAD,1,0,0),i=$.vec3(),s=$.vec3(),r=$.vec3();return function(){var n=e.camera.eye,o=e.camera.look,l=e.camera.up;i=$.mulVec3Scalar($.normalizeVec3($.subVec3(n,o,i)),5),a._isProjectNorth&&a._projectNorthOffsetAngle&&(i=u(-1,i,hF),l=u(-1,l,dF)),a._zUp?($.transformVec3(t,i,s),$.transformVec3(t,l,r),a._navCubeCamera.look=[0,0,0],a._navCubeCamera.eye=$.transformVec3(t,i,s),a._navCubeCamera.up=$.transformPoint3(t,l,r)):(a._navCubeCamera.look=[0,0,0],a._navCubeCamera.eye=i,a._navCubeCamera.up=l)}}(),s._cubeTextureCanvas=new cF(e,o,r),s._cubeSampler=new Un(o,{image:s._cubeTextureCanvas.getImage(),flipY:!0,wrapS:1001,wrapT:1001}),s._cubeMesh=new rn(o,{geometry:new Si(o,{primitive:"triangles",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],positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],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]}),material:new Oi(o,{diffuse:[.4,.4,.4],specular:[.4,.4,.4],emissive:[.6,.6,.6],diffuseMap:s._cubeSampler,emissiveMap:s._cubeSampler}),visible:!!n,edges:!0}),s._shadow=!1===r.shadowVisible?null:new rn(o,{geometry:new Si(o,on({center:[0,0,0],radiusTop:.001,radiusBottom:1.4,height:.01,radialSegments:20,heightSegments:1,openEnded:!0})),material:new Oi(o,{diffuse:[0,0,0],specular:[0,0,0],emissive:[0,0,0],alpha:.5}),position:[0,-1.5,0],visible:!!n,pickable:!1,backfaces:!1}),s._onCameraMatrix=e.camera.on("matrix",s._synchCamera),s._onCameraWorldAxis=e.camera.on("worldAxis",(function(){e.camera.zUp?(s._zUp=!0,s._cubeTextureCanvas.setZUp(),s._repaint(),s._synchCamera()):e.camera.yUp&&(s._zUp=!1,s._cubeTextureCanvas.setYUp(),s._repaint(),s._synchCamera())})),s._onCameraFOV=e.camera.perspective.on("fov",(function(e){s._synchProjection&&(s._navCubeCamera.perspective.fov=e)})),s._onCameraProjection=e.camera.on("projection",(function(e){s._synchProjection&&(s._navCubeCamera.projection="ortho"===e||"perspective"===e?e:"perspective")}));var A=-1;function c(t,i){var s=(t-d)*-_,r=(i-p)*-_;e.camera.orbitYaw(s),e.camera.orbitPitch(-r),d=t,p=i}function h(e){var t=[0,0];if(e){for(var i=e.target,s=0,r=0;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;t[0]=e.pageX-s,t[1]=e.pageY-r}else e=window.event,t[0]=e.x,t[1]=e.y;return t}var d,p,f=null,v=null,g=!1,m=!1,_=.5;a._navCubeCanvas.addEventListener("mouseenter",a._onMouseEnter=function(e){m=!0}),a._navCubeCanvas.addEventListener("mouseleave",a._onMouseLeave=function(e){m=!1}),a._navCubeCanvas.addEventListener("mousedown",a._onMouseDown=function(e){if(1===e.which){f=e.x,v=e.y,d=e.clientX,p=e.clientY;var t=h(e),i=o.pick({canvasPos:t});g=!!i}}),document.addEventListener("mouseup",a._onMouseUp=function(e){if(1===e.which&&(g=!1,null!==f)){var t=h(e),i=o.pick({canvasPos:t,pickSurface:!0});if(i&&i.uv){var s=a._cubeTextureCanvas.getArea(i.uv);if(s>=0&&(document.body.style.cursor="pointer",A>=0&&(a._cubeTextureCanvas.setAreaHighlighted(A,!1),a._repaint(),A=-1),s>=0)){if(a._cubeTextureCanvas.setAreaHighlighted(s,!0),A=s,a._repaint(),e.xf+3||e.yv+3)return;var r=a._cubeTextureCanvas.getAreaDir(s);if(r){var n=a._cubeTextureCanvas.getAreaUp(s);a._isProjectNorth&&a._projectNorthOffsetAngle&&(r=u(1,r,hF),n=u(1,n,dF)),w(r,n,(function(){A>=0&&(a._cubeTextureCanvas.setAreaHighlighted(A,!1),a._repaint(),A=-1),document.body.style.cursor="pointer",A>=0&&(a._cubeTextureCanvas.setAreaHighlighted(A,!1),a._repaint(),A=-1),s>=0&&(a._cubeTextureCanvas.setAreaHighlighted(s,!1),A=-1,a._repaint())}))}}}}}),document.addEventListener("mousemove",a._onMouseMove=function(e){if(A>=0&&(a._cubeTextureCanvas.setAreaHighlighted(A,!1),a._repaint(),A=-1),1!==e.buttons||g){if(g){var t=e.clientX,i=e.clientY;return document.body.style.cursor="move",void c(t,i)}if(m){var s=h(e),r=o.pick({canvasPos:s,pickSurface:!0});if(r){if(r.uv){document.body.style.cursor="pointer";var n=a._cubeTextureCanvas.getArea(r.uv);if(n===A)return;A>=0&&a._cubeTextureCanvas.setAreaHighlighted(A,!1),n>=0&&(a._cubeTextureCanvas.setAreaHighlighted(n,!0),a._repaint(),A=n)}}else document.body.style.cursor="default",A>=0&&(a._cubeTextureCanvas.setAreaHighlighted(A,!1),a._repaint(),A=-1)}}});var w=function(){var t=$.vec3();return function(i,s,r){var n=a._fitVisible?e.scene.getAABB(e.scene.visibleObjectIds):e.scene.aabb,o=$.getAABB3Diag(n);$.getAABB3Center(n,t);var l=Math.abs(o/Math.tan(a._cameraFitFOV*$.DEGTORAD));e.cameraControl.pivotPos=t,a._cameraFly?e.cameraFlight.flyTo({look:t,eye:[t[0]-l*i[0],t[1]-l*i[1],t[2]-l*i[2]],up:s||[0,1,0],orthoScale:1.1*o,fitFOV:a._cameraFitFOV,duration:a._cameraFlyDuration},r):e.cameraFlight.jumpTo({look:t,eye:[t[0]-l*i[0],t[1]-l*i[1],t[2]-l*i[2]],up:s||[0,1,0],orthoScale:1.1*o,fitFOV:a._cameraFitFOV},r)}}();return s._onUpdated=e.localeService.on("updated",(function(){s._cubeTextureCanvas.clear(),s._repaint()})),s.setVisible(r.visible),s.setCameraFitFOV(r.cameraFitFOV),s.setCameraFly(r.cameraFly),s.setCameraFlyDuration(r.cameraFlyDuration),s.setFitVisible(r.fitVisible),s.setSynchProjection(r.synchProjection),s}return C(i,[{key:"send",value:function(e,t){if("language"===e)this._cubeTextureCanvas.clear(),this._repaint()}},{key:"_repaint",value:function(){var e=this._cubeTextureCanvas.getImage();this._cubeMesh.material.diffuseMap.image=e,this._cubeMesh.material.emissiveMap.image=e}},{key:"setVisible",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this._navCubeCanvas&&(this._cubeMesh.visible=e,this._shadow&&(this._shadow.visible=e),this._navCubeCanvas.style.visibility=e?"visible":"hidden")}},{key:"getVisible",value:function(){return!!this._navCubeCanvas&&this._cubeMesh.visible}},{key:"setFitVisible",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._fitVisible=e}},{key:"getFitVisible",value:function(){return this._fitVisible}},{key:"setCameraFly",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this._cameraFly=e}},{key:"getCameraFly",value:function(){return this._cameraFly}},{key:"setCameraFitFOV",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:45;this._cameraFitFOV=e}},{key:"getCameraFitFOV",value:function(){return this._cameraFitFOV}},{key:"setCameraFlyDuration",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:.5;this._cameraFlyDuration=e}},{key:"getCameraFlyDuration",value:function(){return this._cameraFlyDuration}},{key:"setSynchProjection",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._synchProjection=e}},{key:"getSynchProjection",value:function(){return this._synchProjection}},{key:"setIsProjectNorth",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._isProjectNorth=e}},{key:"getIsProjectNorth",value:function(){return this._isProjectNorth}},{key:"setProjectNorthOffsetAngle",value:function(e){this._projectNorthOffsetAngle=e}},{key:"getProjectNorthOffsetAngle",value:function(){return this._projectNorthOffsetAngle}},{key:"destroy",value:function(){this._navCubeCanvas&&(this.viewer.localeService.off(this._onUpdated),this.viewer.camera.off(this._onCameraMatrix),this.viewer.camera.off(this._onCameraWorldAxis),this.viewer.camera.perspective.off(this._onCameraFOV),this.viewer.camera.off(this._onCameraProjection),this._navCubeCanvas.removeEventListener("mouseenter",this._onMouseEnter),this._navCubeCanvas.removeEventListener("mouseleave",this._onMouseLeave),this._navCubeCanvas.removeEventListener("mousedown",this._onMouseDown),document.removeEventListener("mousemove",this._onMouseMove),document.removeEventListener("mouseup",this._onMouseUp),this._navCubeCanvas=null,this._cubeTextureCanvas.destroy(),this._cubeTextureCanvas=null,this._onMouseEnter=null,this._onMouseLeave=null,this._onMouseDown=null,this._onMouseMove=null,this._onMouseUp=null),this._navCubeScene.destroy(),this._navCubeScene=null,this._cubeMesh=null,this._shadow=null,f(w(i.prototype),"destroy",this).call(this)}}]),i}(),fF=$.vec3(),vF=function(){function e(){x(this,e)}return C(e,[{key:"load",value:function(e,t){var i=e.scene.canvas.spinner;i.processes++,gF(e,t,(function(t){_F(e,t,(function(){wF(e,t),i.processes--,_e.scheduleTask((function(){e.fire("loaded",!0,!1)}))}))}))}},{key:"parse",value:function(e,t,i,s){if(t){var r=mF(e,t,null);i&&bF(e,i,s),wF(e,r),e.src=null,e.fire("loaded",!0,!1)}else this.warn("load() param expected: objText")}}]),e}(),gF=function(e,t,i){BF(t,(function(s){var r=mF(e,s,t);i(r)}),(function(t){e.error(t)}))},mF=function(){var e={vertex_pattern:/^v\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,normal_pattern:/^vn\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,uv_pattern:/^vt\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,face_vertex:/^f\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)(?:\s+(-?\d+))?/,face_vertex_uv:/^f\s+(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)(?:\s+(-?\d+)\/(-?\d+))?/,face_vertex_uv_normal:/^f\s+(-?\d+)\/(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\/(-?\d+)(?:\s+(-?\d+)\/(-?\d+)\/(-?\d+))?/,face_vertex_normal:/^f\s+(-?\d+)\/\/(-?\d+)\s+(-?\d+)\/\/(-?\d+)\s+(-?\d+)\/\/(-?\d+)(?:\s+(-?\d+)\/\/(-?\d+))?/,object_pattern:/^[og]\s*(.+)?/,smoothing_pattern:/^s\s+(\d+|on|off)/,material_library_pattern:/^mtllib /,material_use_pattern:/^usemtl /};return function(s,r,n){var o={src:n=n||"",basePath:t(n),objects:[],object:{},positions:[],normals:[],uv:[],materialLibraries:{}};i(o,"",!1),-1!==r.indexOf("\r\n")&&(r=r.replace("\r\n","\n"));for(var a=r.split("\n"),l="",u="",A="",d=[],p="function"==typeof"".trimLeft,f=0,v=a.length;f=0?i-1:i+t/3)}function r(e,t){var i=parseInt(e,10);return 3*(i>=0?i-1:i+t/3)}function n(e,t){var i=parseInt(e,10);return 2*(i>=0?i-1:i+t/2)}function o(e,t,i,s){var r=e.positions,n=e.object.geometry.positions;n.push(r[t+0]),n.push(r[t+1]),n.push(r[t+2]),n.push(r[i+0]),n.push(r[i+1]),n.push(r[i+2]),n.push(r[s+0]),n.push(r[s+1]),n.push(r[s+2])}function a(e,t){var i=e.positions,s=e.object.geometry.positions;s.push(i[t+0]),s.push(i[t+1]),s.push(i[t+2])}function l(e,t,i,s){var r=e.normals,n=e.object.geometry.normals;n.push(r[t+0]),n.push(r[t+1]),n.push(r[t+2]),n.push(r[i+0]),n.push(r[i+1]),n.push(r[i+2]),n.push(r[s+0]),n.push(r[s+1]),n.push(r[s+2])}function u(e,t,i,s){var r=e.uv,n=e.object.geometry.uv;n.push(r[t+0]),n.push(r[t+1]),n.push(r[i+0]),n.push(r[i+1]),n.push(r[s+0]),n.push(r[s+1])}function A(e,t){var i=e.uv,s=e.object.geometry.uv;s.push(i[t+0]),s.push(i[t+1])}function c(e,t,i,a,A,c,h,d,p,f,v,g,m){var _,y=e.positions.length,b=s(t,y),w=s(i,y),B=s(a,y);if(void 0===A?o(e,b,w,B):(o(e,b,w,_=s(A,y)),o(e,w,B,_)),void 0!==c){var x=e.uv.length;b=n(c,x),w=n(h,x),B=n(d,x),void 0===A?u(e,b,w,B):(u(e,b,w,_=n(p,x)),u(e,w,B,_))}if(void 0!==f){var P=e.normals.length;b=r(f,P),w=f===v?b:r(v,P),B=f===g?b:r(g,P),void 0===A?l(e,b,w,B):(l(e,b,w,_=r(m,P)),l(e,w,B,_))}}function h(e,t,i){e.object.geometry.type="Line";for(var r=e.positions.length,o=e.uv.length,l=0,u=t.length;l=0?o.substring(0,a):o).toLowerCase(),u=(u=a>=0?o.substring(a+1):"").trim(),l.toLowerCase()){case"newmtl":i(e,h),h={id:u},d=!0;break;case"ka":h.ambient=s(u);break;case"kd":h.diffuse=s(u);break;case"ks":h.specular=s(u);break;case"map_kd":h.diffuseMap||(h.diffuseMap=t(e,n,u,"sRGB"));break;case"map_ks":h.specularMap||(h.specularMap=t(e,n,u,"linear"));break;case"map_bump":case"bump":h.normalMap||(h.normalMap=t(e,n,u));break;case"ns":h.shininess=parseFloat(u);break;case"d":(A=parseFloat(u))<1&&(h.alpha=A,h.alphaMode="blend");break;case"tr":(A=parseFloat(u))>0&&(h.alpha=1-A,h.alphaMode="blend")}d&&i(e,h)};function t(e,t,i,s){var r={},n=i.split(/\s+/),o=n.indexOf("-bm");return o>=0&&n.splice(o,2),(o=n.indexOf("-s"))>=0&&(r.scale=[parseFloat(n[o+1]),parseFloat(n[o+2])],n.splice(o,4)),(o=n.indexOf("-o"))>=0&&(r.translate=[parseFloat(n[o+1]),parseFloat(n[o+2])],n.splice(o,4)),r.src=t+n.join(" ").trim(),r.flipY=!0,r.encoding=s||"linear",new Un(e,r).id}function i(e,t){new Oi(e,t)}function s(t){var i=t.split(e,3);return[parseFloat(i[0]),parseFloat(i[1]),parseFloat(i[2])]}}();function wF(e,t){for(var i=0,s=t.objects.length;i0&&(o.normals=n.normals),n.uv.length>0&&(o.uv=n.uv);for(var a=new Array(o.positions.length/3),l=0;l0&&void 0!==arguments[0]?arguments[0]:{};t.id&&this.viewer.scene.components[t.id]&&(this.error("Component with this ID already exists in viewer: "+t.id+" - will autogenerate this ID"),delete t.id);var i=new bn(this.viewer.scene,le.apply(t,{isModel:!0})),s=i.id,r=t.src;if(!r)return this.error("load() param expected: src"),i;if(t.metaModelSrc){var n=t.metaModelSrc;le.loadJSON(n,(function(n){e.viewer.metaScene.createMetaModel(s,n),e._sceneGraphLoader.load(i,r,t)}),(function(t){e.error("load(): Failed to load model modelMetadata for model '".concat(s," from '").concat(n,"' - ").concat(t))}))}else this._sceneGraphLoader.load(i,r,t);return i.once("destroyed",(function(){e.viewer.metaScene.destroyMetaModel(s)})),i}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this)}}]),i}(),PF=new Float64Array([0,0,1]),CF=new Float64Array(4),MF=function(){function e(t){x(this,e),this.id=null,this._viewer=t.viewer,this._visible=!1,this._pos=$.vec3(),this._origin=$.vec3(),this._rtcPos=$.vec3(),this._baseDir=$.vec3(),this._rootNode=null,this._displayMeshes=null,this._affordanceMeshes=null,this._ignoreNextSectionPlaneDirUpdate=!1,this._createNodes(),this._bindEvents()}return C(e,[{key:"_setSectionPlane",value:function(e){var t=this;this._sectionPlane&&(this._sectionPlane.off(this._onSectionPlanePos),this._sectionPlane.off(this._onSectionPlaneDir),this._onSectionPlanePos=null,this._onSectionPlaneDir=null,this._sectionPlane=null),e&&(this.id=e.id,this._setPos(e.pos),this._setDir(e.dir),this._sectionPlane=e,this._onSectionPlanePos=e.on("pos",(function(){t._setPos(t._sectionPlane.pos)})),this._onSectionPlaneDir=e.on("dir",(function(){t._ignoreNextSectionPlaneDirUpdate?t._ignoreNextSectionPlaneDirUpdate=!1:t._setDir(t._sectionPlane.dir)})))}},{key:"sectionPlane",get:function(){return this._sectionPlane}},{key:"_setPos",value:function(e){this._pos.set(e),Le(this._pos,this._origin,this._rtcPos),this._rootNode.origin=this._origin,this._rootNode.position=this._rtcPos}},{key:"_setDir",value:function(e){this._baseDir.set(e),this._rootNode.quaternion=$.vec3PairToQuaternion(PF,e,CF)}},{key:"_setSectionPlaneDir",value:function(e){this._sectionPlane&&(this._ignoreNextSectionPlaneDirUpdate=!0,this._sectionPlane.dir=e)}},{key:"setVisible",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(this._visible!==e){var t;for(t in this._visible=e,this._displayMeshes)this._displayMeshes.hasOwnProperty(t)&&(this._displayMeshes[t].visible=e);if(!e)for(t in this._affordanceMeshes)this._affordanceMeshes.hasOwnProperty(t)&&(this._affordanceMeshes[t].visible=e)}}},{key:"getVisible",value:function(){return this._visible}},{key:"setCulled",value:function(e){var t;for(t in this._displayMeshes)this._displayMeshes.hasOwnProperty(t)&&(this._displayMeshes[t].culled=e);if(!e)for(t in this._affordanceMeshes)this._affordanceMeshes.hasOwnProperty(t)&&(this._affordanceMeshes[t].culled=e)}},{key:"_createNodes",value:function(){var e=!1,t=this._viewer.scene,i=.01;this._rootNode=new bn(t,{position:[0,0,0],scale:[5,5,5],isObject:!1});var s,r,n=this._rootNode,o={arrowHead:new Si(n,on({radiusTop:.001,radiusBottom:.07,radialSegments:32,heightSegments:1,height:.2,openEnded:!1})),arrowHeadBig:new Si(n,on({radiusTop:.001,radiusBottom:.09,radialSegments:32,heightSegments:1,height:.25,openEnded:!1})),arrowHeadHandle:new Si(n,on({radiusTop:.09,radiusBottom:.09,radialSegments:8,heightSegments:1,height:.37,openEnded:!1})),curve:new Si(n,Jn({radius:.8,tube:i,radialSegments:64,tubeSegments:14,arc:2*Math.PI/4})),curveHandle:new Si(n,Jn({radius:.8,tube:.06,radialSegments:64,tubeSegments:14,arc:2*Math.PI/4})),hoop:new Si(n,Jn({radius:.8,tube:i,radialSegments:64,tubeSegments:8,arc:2*Math.PI})),axis:new Si(n,on({radiusTop:i,radiusBottom:i,radialSegments:20,heightSegments:1,height:1,openEnded:!1})),axisHandle:new Si(n,on({radiusTop:.08,radiusBottom:.08,radialSegments:20,heightSegments:1,height:1,openEnded:!1}))},a={pickable:new Oi(n,{diffuse:[1,1,0],alpha:0,alphaMode:"blend"}),red:new Oi(n,{diffuse:[1,0,0],emissive:[1,0,0],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),highlightRed:new Qi(n,{edges:!1,fill:!0,fillColor:[1,0,0],fillAlpha:.6}),green:new Oi(n,{diffuse:[0,1,0],emissive:[0,1,0],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),highlightGreen:new Qi(n,{edges:!1,fill:!0,fillColor:[0,1,0],fillAlpha:.6}),blue:new Oi(n,{diffuse:[0,0,1],emissive:[0,0,1],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),highlightBlue:new Qi(n,{edges:!1,fill:!0,fillColor:[0,0,1],fillAlpha:.2}),center:new Oi(n,{diffuse:[0,0,0],emissive:[0,0,0],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80}),highlightBall:new Qi(n,{edges:!1,fill:!0,fillColor:[.5,.5,.5],fillAlpha:.5,vertices:!1}),highlightPlane:new Qi(n,{edges:!0,edgeWidth:3,fill:!1,fillColor:[.5,.5,.5],fillAlpha:.5,vertices:!1})};this._displayMeshes={plane:n.addChild(new rn(n,{geometry:new Si(n,{primitive:"triangles",positions:[.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0,.5,.5,-0,.5,-.5,-0,-.5,-.5,-0,-.5,.5,-0],indices:[0,1,2,2,3,0]}),material:new Oi(n,{emissive:[0,0,0],diffuse:[0,0,0],backfaces:!0}),opacity:.6,ghosted:!0,ghostMaterial:new Qi(n,{edges:!1,filled:!0,fillColor:[1,1,0],edgeColor:[0,0,0],fillAlpha:.1,backfaces:!0}),pickable:!1,collidable:!0,clippable:!1,visible:!1,scale:[2.4,2.4,1],isObject:!1}),e),planeFrame:n.addChild(new rn(n,{geometry:new Si(n,Jn({center:[0,0,0],radius:1.7,tube:.02,radialSegments:4,tubeSegments:4,arc:2*Math.PI})),material:new Oi(n,{emissive:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],shininess:0}),highlightMaterial:new Qi(n,{edges:!1,edgeColor:[0,0,0],filled:!0,fillColor:[.8,.8,.8],fillAlpha:1}),pickable:!1,collidable:!1,clippable:!1,visible:!1,scale:[1,1,.1],rotation:[0,0,45],isObject:!1}),e),xCurve:n.addChild(new rn(n,{geometry:o.curve,material:a.red,matrix:(s=$.rotationMat4v(90*$.DEGTORAD,[0,1,0],$.identityMat4()),r=$.rotationMat4v(270*$.DEGTORAD,[1,0,0],$.identityMat4()),$.mulMat4(r,s,$.identityMat4())),pickable:!1,collidable:!0,clippable:!1,backfaces:!0,visible:!1,isObject:!1}),e),xCurveHandle:n.addChild(new rn(n,{geometry:o.curveHandle,material:a.pickable,matrix:function(){var e=$.rotationMat4v(90*$.DEGTORAD,[0,1,0],$.identityMat4()),t=$.rotationMat4v(270*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,backfaces:!0,visible:!1,isObject:!1}),e),xCurveArrow1:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.red,matrix:function(){var e=$.translateMat4c(0,-.07,-.8,$.identityMat4()),t=$.scaleMat4v([.6,.6,.6],$.identityMat4()),i=$.rotationMat4v(0*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4($.mulMat4(e,t,$.identityMat4()),i,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),xCurveArrow2:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.red,matrix:function(){var e=$.translateMat4c(0,-.8,-.07,$.identityMat4()),t=$.scaleMat4v([.6,.6,.6],$.identityMat4()),i=$.rotationMat4v(90*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4($.mulMat4(e,t,$.identityMat4()),i,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yCurve:n.addChild(new rn(n,{geometry:o.curve,material:a.green,rotation:[-90,0,0],pickable:!1,collidable:!0,clippable:!1,backfaces:!0,visible:!1,isObject:!1}),e),yCurveHandle:n.addChild(new rn(n,{geometry:o.curveHandle,material:a.pickable,rotation:[-90,0,0],pickable:!0,collidable:!0,clippable:!1,backfaces:!0,visible:!1,isObject:!1}),e),yCurveArrow1:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.green,matrix:function(){var e=$.translateMat4c(.07,0,-.8,$.identityMat4()),t=$.scaleMat4v([.6,.6,.6],$.identityMat4()),i=$.rotationMat4v(90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4($.mulMat4(e,t,$.identityMat4()),i,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yCurveArrow2:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.green,matrix:function(){var e=$.translateMat4c(.8,0,-.07,$.identityMat4()),t=$.scaleMat4v([.6,.6,.6],$.identityMat4()),i=$.rotationMat4v(90*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4($.mulMat4(e,t,$.identityMat4()),i,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zCurve:n.addChild(new rn(n,{geometry:o.curve,material:a.blue,matrix:$.rotationMat4v(180*$.DEGTORAD,[1,0,0],$.identityMat4()),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zCurveHandle:n.addChild(new rn(n,{geometry:o.curveHandle,material:a.pickable,matrix:$.rotationMat4v(180*$.DEGTORAD,[1,0,0],$.identityMat4()),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zCurveCurveArrow1:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.blue,matrix:function(){var e=$.translateMat4c(.8,-.07,0,$.identityMat4()),t=$.scaleMat4v([.6,.6,.6],$.identityMat4());return $.mulMat4(e,t,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zCurveArrow2:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.blue,matrix:function(){var e=$.translateMat4c(.05,-.8,0,$.identityMat4()),t=$.scaleMat4v([.6,.6,.6],$.identityMat4()),i=$.rotationMat4v(90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4($.mulMat4(e,t,$.identityMat4()),i,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),center:n.addChild(new rn(n,{geometry:new Si(n,an({radius:.05})),material:a.center,pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),xAxisArrow:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.red,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),xAxisArrowHandle:n.addChild(new rn(n,{geometry:o.arrowHeadHandle,material:a.pickable,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),xAxis:n.addChild(new rn(n,{geometry:o.axis,material:a.red,matrix:function(){var e=$.translateMat4c(0,.5,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),xAxisHandle:n.addChild(new rn(n,{geometry:o.axisHandle,material:a.pickable,matrix:function(){var e=$.translateMat4c(0,.5,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yAxisArrow:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.green,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(180*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yAxisArrowHandle:n.addChild(new rn(n,{geometry:o.arrowHeadHandle,material:a.pickable,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(180*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,opacity:.2,isObject:!1}),e),yShaft:n.addChild(new rn(n,{geometry:o.axis,material:a.green,position:[0,-.5,0],pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yShaftHandle:n.addChild(new rn(n,{geometry:o.axisHandle,material:a.pickable,position:[0,-.5,0],pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zAxisArrow:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.blue,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[.8,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zAxisArrowHandle:n.addChild(new rn(n,{geometry:o.arrowHeadHandle,material:a.pickable,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[.8,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zShaft:n.addChild(new rn(n,{geometry:o.axis,material:a.blue,matrix:function(){var e=$.translateMat4c(0,.5,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),clippable:!1,pickable:!1,collidable:!0,visible:!1,isObject:!1}),e),zAxisHandle:n.addChild(new rn(n,{geometry:o.axisHandle,material:a.pickable,matrix:function(){var e=$.translateMat4c(0,.5,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),clippable:!1,pickable:!0,collidable:!0,visible:!1,isObject:!1}),e)},this._affordanceMeshes={planeFrame:n.addChild(new rn(n,{geometry:new Si(n,Jn({center:[0,0,0],radius:2,tube:i,radialSegments:4,tubeSegments:4,arc:2*Math.PI})),material:new Oi(n,{ambient:[1,1,1],diffuse:[0,0,0],emissive:[1,1,0]}),highlighted:!0,highlightMaterial:new Qi(n,{edges:!1,filled:!0,fillColor:[1,1,0],fillAlpha:1}),pickable:!1,collidable:!1,clippable:!1,visible:!1,scale:[1,1,1],rotation:[0,0,45],isObject:!1}),e),xHoop:n.addChild(new rn(n,{geometry:o.hoop,material:a.red,highlighted:!0,highlightMaterial:a.highlightRed,matrix:function(){var e=$.rotationMat4v(90*$.DEGTORAD,[0,1,0],$.identityMat4()),t=$.rotationMat4v(270*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yHoop:n.addChild(new rn(n,{geometry:o.hoop,material:a.green,highlighted:!0,highlightMaterial:a.highlightGreen,rotation:[-90,0,0],pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zHoop:n.addChild(new rn(n,{geometry:o.hoop,material:a.blue,highlighted:!0,highlightMaterial:a.highlightBlue,matrix:$.rotationMat4v(180*$.DEGTORAD,[1,0,0],$.identityMat4()),pickable:!1,collidable:!0,clippable:!1,backfaces:!0,visible:!1,isObject:!1}),e),xAxisArrow:n.addChild(new rn(n,{geometry:o.arrowHeadBig,material:a.red,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yAxisArrow:n.addChild(new rn(n,{geometry:o.arrowHeadBig,material:a.green,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(180*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zAxisArrow:n.addChild(new rn(n,{geometry:o.arrowHeadBig,material:a.blue,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[.8,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e)}}},{key:"_bindEvents",value:function(){var e=this,t=this,i=!1,s=-1,r=0,n=1,o=2,a=3,l=4,u=5,A=this._rootNode,c=null,h=null,d=$.vec2(),p=$.vec3([1,0,0]),f=$.vec3([0,1,0]),v=$.vec3([0,0,1]),g=this._viewer.scene.canvas.canvas,m=this._viewer.camera,_=this._viewer.scene,y=$.vec3([0,0,0]),b=-1;this._onCameraViewMatrix=_.camera.on("viewMatrix",(function(){})),this._onCameraProjMatrix=_.camera.on("projMatrix",(function(){})),this._onSceneTick=_.on("tick",(function(){var t=Math.abs($.lenVec3($.subVec3(_.camera.eye,e._pos,y)));if(t!==b&&"perspective"===m.projection){var i=.07*(Math.tan(m.perspective.fov*$.DEGTORAD)*t);A.scale=[i,i,i],b=t}if("ortho"===m.projection){var s=m.ortho.scale/10;A.scale=[s,s,s],b=t}}));var w,B,x,P,C,M=function(){var e=new Float64Array(2);return function(t){if(t){for(var i=t.target,s=0,r=0;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;e[0]=t.pageX-s,e[1]=t.pageY-r}else t=window.event,e[0]=t.x,e[1]=t.y;return e}}(),F=function(){var e=$.mat4();return function(i,s){return $.quaternionToMat4(t._rootNode.quaternion,e),$.transformVec3(e,i,s),$.normalizeVec3(s),s}}(),E=(w=$.vec3(),function(e){var t=Math.abs(e[0]);return t>Math.abs(e[1])&&t>Math.abs(e[2])?$.cross3Vec3(e,[0,1,0],w):$.cross3Vec3(e,[1,0,0],w),$.cross3Vec3(w,e,w),$.normalizeVec3(w),w}),k=(B=$.vec3(),x=$.vec3(),P=$.vec4(),function(e,i,s){F(e,P);var r=E(P,i,s);D(i,r,B),D(s,r,x),$.subVec3(x,B);var n=$.dotVec3(x,P);t._pos[0]+=P[0]*n,t._pos[1]+=P[1]*n,t._pos[2]+=P[2]*n,t._rootNode.position=t._pos,t._sectionPlane&&(t._sectionPlane.pos=t._pos)}),I=function(){var e=$.vec4(),i=$.vec4(),s=$.vec4(),r=$.vec4();return function(n,o,a){if(F(n,r),!(D(o,r,e)&&D(a,r,i))){var l=E(r,o,a);D(o,l,e,1),D(a,l,i,1);var u=$.dotVec3(e,r);e[0]-=u*r[0],e[1]-=u*r[1],e[2]-=u*r[2],u=$.dotVec3(i,r),i[0]-=u*r[0],i[1]-=u*r[1],i[2]-=u*r[2]}$.normalizeVec3(e),$.normalizeVec3(i),u=$.dotVec3(e,i),u=$.clamp(u,-1,1);var A=Math.acos(u)*$.RADTODEG;$.cross3Vec3(e,i,s),$.dotVec3(s,r)<0&&(A=-A),t._rootNode.rotate(n,A),S()}}(),D=function(){var e=$.vec4([0,0,0,1]),i=$.mat4();return function(s,r,n,o){o=o||0,e[0]=s[0]/g.width*2-1,e[1]=-(s[1]/g.height*2-1),e[2]=0,e[3]=1,$.mulMat4(m.projMatrix,m.viewMatrix,i),$.inverseMat4(i),$.transformVec4(i,e,e),$.mulVec4Scalar(e,1/e[3]);var a=m.eye;$.subVec4(e,a,e);var l=t._sectionPlane.pos,u=-$.dotVec3(l,r)-o,A=$.dotVec3(r,e);if(Math.abs(A)>.005){var c=-($.dotVec3(r,a)+u)/A;return $.mulVec3Scalar(e,c,n),$.addVec3(n,a),$.subVec3(n,l,n),!0}return!1}}(),S=function(){var e=$.vec3(),i=$.mat4();return function(){t.sectionPlane&&($.quaternionToMat4(A.quaternion,i),$.transformVec3(i,[0,0,1],e),t._setSectionPlaneDir(e))}}(),T=!1;this._onCameraControlHover=this._viewer.cameraControl.on("hoverEnter",(function(t){if(e._visible&&!T){var A;switch(i=!1,C&&(C.visible=!1),t.entity.id){case e._displayMeshes.xAxisArrowHandle.id:case e._displayMeshes.xAxisHandle.id:A=e._affordanceMeshes.xAxisArrow,c=r;break;case e._displayMeshes.yAxisArrowHandle.id:case e._displayMeshes.yShaftHandle.id:A=e._affordanceMeshes.yAxisArrow,c=n;break;case e._displayMeshes.zAxisArrowHandle.id:case e._displayMeshes.zAxisHandle.id:A=e._affordanceMeshes.zAxisArrow,c=o;break;case e._displayMeshes.xCurveHandle.id:A=e._affordanceMeshes.xHoop,c=a;break;case e._displayMeshes.yCurveHandle.id:A=e._affordanceMeshes.yHoop,c=l;break;case e._displayMeshes.zCurveHandle.id:A=e._affordanceMeshes.zHoop,c=u;break;default:return void(c=s)}A&&(A.visible=!0),C=A,i=!0}})),this._onCameraControlHoverLeave=this._viewer.cameraControl.on("hoverOutEntity",(function(t){e._visible&&(C&&(C.visible=!1),C=null,c=s)})),g.addEventListener("mousedown",this._canvasMouseDownListener=function(t){if(t.preventDefault(),e._visible&&i&&(e._viewer.cameraControl.pointerEnabled=!1,1===t.which)){T=!0;var s=M(t);h=c,d[0]=s[0],d[1]=s[1]}}),g.addEventListener("mousemove",this._canvasMouseMoveListener=function(t){if(e._visible&&T){var i=M(t),s=i[0],A=i[1];switch(h){case r:k(p,d,i);break;case n:k(f,d,i);break;case o:k(v,d,i);break;case a:I(p,d,i);break;case l:I(f,d,i);break;case u:I(v,d,i)}d[0]=s,d[1]=A}}),g.addEventListener("mouseup",this._canvasMouseUpListener=function(t){e._visible&&(e._viewer.cameraControl.pointerEnabled=!0,T&&(t.which,T=!1,i=!1))}),g.addEventListener("wheel",this._canvasWheelListener=function(t){if(e._visible)Math.max(-1,Math.min(1,40*-t.deltaY))})}},{key:"_destroy",value:function(){this._unbindEvents(),this._destroyNodes()}},{key:"_unbindEvents",value:function(){var e=this._viewer,t=e.scene,i=t.canvas.canvas,s=e.camera,r=e.cameraControl;t.off(this._onSceneTick),i.removeEventListener("mousedown",this._canvasMouseDownListener),i.removeEventListener("mousemove",this._canvasMouseMoveListener),i.removeEventListener("mouseup",this._canvasMouseUpListener),i.removeEventListener("wheel",this._canvasWheelListener),s.off(this._onCameraViewMatrix),s.off(this._onCameraProjMatrix),r.off(this._onCameraControlHover),r.off(this._onCameraControlHoverLeave)}},{key:"_destroyNodes",value:function(){this._setSectionPlane(null),this._rootNode.destroy(),this._displayMeshes={},this._affordanceMeshes={}}}]),e}(),FF=function(){function e(t,i,s){var r=this;x(this,e),this.id=s.id,this._sectionPlane=s,this._mesh=new rn(i,{id:s.id,geometry:new Si(i,Ti({xSize:.5,ySize:.5,zSize:.001})),material:new Oi(i,{emissive:[1,1,1],diffuse:[0,0,0],backfaces:!1}),edgeMaterial:new Hi(i,{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1}),highlightMaterial:new Qi(i,{fill:!0,fillColor:[.5,1,.5],fillAlpha:.7,edges:!0,edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1}),selectedMaterial:new Qi(i,{fill:!0,fillColor:[0,0,1],fillAlpha:.7,edges:!0,edgeColor:[1,0,0],edgeAlpha:1,edgeWidth:1}),highlighted:!0,scale:[3,3,3],position:[0,0,0],rotation:[0,0,0],opacity:.3,edges:!0});var n=$.vec3([0,0,0]),o=$.vec3(),a=$.vec3([0,0,1]),l=$.vec4(4),u=$.vec3(),A=function(){var e=r._sectionPlane.scene.center,t=[-r._sectionPlane.dir[0],-r._sectionPlane.dir[1],-r._sectionPlane.dir[2]];$.subVec3(e,r._sectionPlane.pos,n);var i=-$.dotVec3(t,n);$.normalizeVec3(t),$.mulVec3Scalar(t,i,o);var s=$.vec3PairToQuaternion(a,r._sectionPlane.dir,l);u[0]=.1*o[0],u[1]=.1*o[1],u[2]=.1*o[2],r._mesh.quaternion=s,r._mesh.position=u};this._onSectionPlanePos=this._sectionPlane.on("pos",A),this._onSectionPlaneDir=this._sectionPlane.on("dir",A),this._highlighted=!1,this._selected=!1}return C(e,[{key:"setHighlighted",value:function(e){this._highlighted=!!e,this._mesh.highlighted=this._highlighted,this._mesh.highlightMaterial.fillColor=e?[0,.7,0]:[0,0,0]}},{key:"getHighlighted",value:function(){return this._highlighted}},{key:"setSelected",value:function(e){this._selected=!!e,this._mesh.edgeMaterial.edgeWidth=e?3:1,this._mesh.highlightMaterial.edgeWidth=e?3:1}},{key:"getSelected",value:function(){return this._selected}},{key:"destroy",value:function(){this._sectionPlane.off(this._onSectionPlanePos),this._sectionPlane.off(this._onSectionPlaneDir),this._mesh.destroy()}}]),e}(),EF=function(){function e(t,i){var s=this;if(x(this,e),!(i.onHoverEnterPlane&&i.onHoverLeavePlane&&i.onClickedNothing&&i.onClickedPlane))throw"Missing config(s): onHoverEnterPlane, onHoverLeavePlane, onClickedNothing || onClickedPlane";this.plugin=t,this._viewer=t.viewer,this._onHoverEnterPlane=i.onHoverEnterPlane,this._onHoverLeavePlane=i.onHoverLeavePlane,this._onClickedNothing=i.onClickedNothing,this._onClickedPlane=i.onClickedPlane,this._visible=!0,this._planes={},this._canvas=i.overviewCanvas,this._scene=new qi(this._viewer,{canvasId:this._canvas.id,transparent:!0}),this._scene.clearLights(),new yi(this._scene,{dir:[.4,-.4,.8],color:[.8,1,1],intensity:1,space:"view"}),new yi(this._scene,{dir:[-.8,-.3,-.4],color:[.8,.8,.8],intensity:1,space:"view"}),new yi(this._scene,{dir:[.8,-.6,-.8],color:[1,1,1],intensity:1,space:"view"}),this._scene.camera,this._scene.camera.perspective.fov=70,this._zUp=!1;var r=this._scene.camera,n=$.rotationMat4c(-90*$.DEGTORAD,1,0,0),o=$.vec3(),a=$.vec3(),l=$.vec3();this._synchCamera=function(){var e=s._viewer.camera.eye,t=s._viewer.camera.look,i=s._viewer.camera.up;$.mulVec3Scalar($.normalizeVec3($.subVec3(e,t,o)),7),s._zUp?($.transformVec3(n,o,a),$.transformVec3(n,i,l),r.look=[0,0,0],r.eye=$.transformVec3(n,o,a),r.up=$.transformPoint3(n,i,l)):(r.look=[0,0,0],r.eye=o,r.up=i)},this._onViewerCameraMatrix=this._viewer.camera.on("matrix",this._synchCamera),this._onViewerCameraWorldAxis=this._viewer.camera.on("worldAxis",this._synchCamera),this._onViewerCameraFOV=this._viewer.camera.perspective.on("fov",(function(e){s._scene.camera.perspective.fov=e}));var u=null;this._onInputMouseMove=this._scene.input.on("mousemove",(function(e){var t=s._scene.pick({canvasPos:e});if(t){if(!u||t.entity.id!==u.id){if(u)s._planes[u.id]&&s._onHoverLeavePlane(u.id);u=t.entity,s._planes[u.id]&&s._onHoverEnterPlane(u.id)}}else u&&(s._onHoverLeavePlane(u.id),u=null)})),this._scene.canvas.canvas.addEventListener("mouseup",this._onCanvasMouseUp=function(){u?s._planes[u.id]&&s._onClickedPlane(u.id):s._onClickedNothing()}),this._scene.canvas.canvas.addEventListener("mouseout",this._onCanvasMouseOut=function(){u&&(s._onHoverLeavePlane(u.id),u=null)}),this.setVisible(i.overviewVisible)}return C(e,[{key:"addSectionPlane",value:function(e){this._planes[e.id]=new FF(this,this._scene,e)}},{key:"setPlaneHighlighted",value:function(e,t){var i=this._planes[e];i&&i.setHighlighted(t)}},{key:"setPlaneSelected",value:function(e,t){var i=this._planes[e];i&&i.setSelected(t)}},{key:"removeSectionPlane",value:function(e){var t=this._planes[e.id];t&&(t.destroy(),delete this._planes[e.id])}},{key:"setVisible",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this._visible=e,this._canvas.style.visibility=e?"visible":"hidden"}},{key:"getVisible",value:function(){return this._visible}},{key:"destroy",value:function(){this._viewer.camera.off(this._onViewerCameraMatrix),this._viewer.camera.off(this._onViewerCameraWorldAxis),this._viewer.camera.perspective.off(this._onViewerCameraFOV),this._scene.input.off(this._onInputMouseMove),this._scene.canvas.canvas.removeEventListener("mouseup",this._onCanvasMouseUp),this._scene.canvas.canvas.removeEventListener("mouseout",this._onCanvasMouseOut),this._scene.destroy()}}]),e}(),kF=$.AABB3(),IF=$.vec3(),DF=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,"SectionPlanes",e))._freeControls=[],s._sectionPlanes=e.scene.sectionPlanes,s._controls={},s._shownControlId=null,null!==r.overviewCanvasId&&void 0!==r.overviewCanvasId){var n=document.getElementById(r.overviewCanvasId);n?s._overview=new EF(b(s),{overviewCanvas:n,visible:r.overviewVisible,onHoverEnterPlane:function(e){s._overview.setPlaneHighlighted(e,!0)},onHoverLeavePlane:function(e){s._overview.setPlaneHighlighted(e,!1)},onClickedPlane:function(e){if(s.getShownControl()!==e){s.showControl(e);var t=s.sectionPlanes[e].pos;kF.set(s.viewer.scene.aabb),$.getAABB3Center(kF,IF),kF[0]+=t[0]-IF[0],kF[1]+=t[1]-IF[1],kF[2]+=t[2]-IF[2],kF[3]+=t[0]-IF[0],kF[4]+=t[1]-IF[1],kF[5]+=t[2]-IF[2],s.viewer.cameraFlight.flyTo({aabb:kF,fitFOV:65})}else s.hideControl()},onClickedNothing:function(){s.hideControl()}}):s.warn("Can't find overview canvas: '"+r.overviewCanvasId+"' - will create plugin without overview")}return s._onSceneSectionPlaneCreated=e.scene.on("sectionPlaneCreated",(function(e){s._sectionPlaneCreated(e)})),s}return C(i,[{key:"setOverviewVisible",value:function(e){this._overview&&this._overview.setVisible(e)}},{key:"getOverviewVisible",value:function(){if(this._overview)return this._overview.getVisible()}},{key:"sectionPlanes",get:function(){return this._sectionPlanes}},{key:"createSectionPlane",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};void 0!==e.id&&null!==e.id&&this.viewer.scene.components[e.id]&&(this.error("Viewer component with this ID already exists: "+e.id),delete e.id);var t=new cn(this.viewer.scene,{id:e.id,pos:e.pos,dir:e.dir,active:!0});return t}},{key:"_sectionPlaneCreated",value:function(e){var t=this,i=this._freeControls.length>0?this._freeControls.pop():new MF(this);i._setSectionPlane(e),i.setVisible(!1),this._controls[e.id]=i,this._overview&&this._overview.addSectionPlane(e),e.once("destroyed",(function(){t._sectionPlaneDestroyed(e)}))}},{key:"flipSectionPlanes",value:function(){var e=this.viewer.scene.sectionPlanes;for(var t in e){e[t].flipDir()}}},{key:"showControl",value:function(e){var t=this._controls[e];t?(this.hideControl(),t.setVisible(!0),this._overview&&this._overview.setPlaneSelected(e,!0),this._shownControlId=e):this.error("Control not found: "+e)}},{key:"getShownControl",value:function(){return this._shownControlId}},{key:"hideControl",value:function(){for(var e in this._controls)this._controls.hasOwnProperty(e)&&(this._controls[e].setVisible(!1),this._overview&&this._overview.setPlaneSelected(e,!1));this._shownControlId=null}},{key:"destroySectionPlane",value:function(e){var t=this.viewer.scene.sectionPlanes[e];t?(this._sectionPlaneDestroyed(t),t.destroy(),e===this._shownControlId&&(this._shownControlId=null)):this.error("SectionPlane not found: "+e)}},{key:"_sectionPlaneDestroyed",value:function(e){this._overview&&this._overview.removeSectionPlane(e);var t=this._controls[e.id];t&&(t.setVisible(!1),t._setSectionPlane(null),delete this._controls[e.id],this._freeControls.push(t))}},{key:"clear",value:function(){for(var e=Object.keys(this._sectionPlanes),t=0,i=e.length;t1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"StoreyViews",e))._objectsMemento=new ud,s._cameraMemento=new nd,s.storeys={},s.modelStoreys={},s._fitStoreyMaps=!!r.fitStoreyMaps,s._onModelLoaded=s.viewer.scene.on("modelLoaded",(function(e){s._registerModelStoreys(e),s.fire("storeys",s.storeys)})),s}return C(i,[{key:"_registerModelStoreys",value:function(e){var t=this,i=this.viewer,s=i.scene,r=i.metaScene,n=r.metaModels[e],o=s.models[e];if(n&&n.rootMetaObjects)for(var a=n.rootMetaObjects,l=0,u=a.length;l.5?p.length:0,g=new SF(this,o.aabb,f,e,d,v);g._onModelDestroyed=o.once("destroyed",(function(){t._deregisterModelStoreys(e),t.fire("storeys",t.storeys)})),this.storeys[d]=g,this.modelStoreys[e]||(this.modelStoreys[e]={}),this.modelStoreys[e][d]=g}}},{key:"_deregisterModelStoreys",value:function(e){var t=this.modelStoreys[e];if(t){var i=this.viewer.scene;for(var s in t)if(t.hasOwnProperty(s)){var r=t[s],n=i.models[r.modelId];n&&n.off(r._onModelDestroyed),delete this.storeys[s]}delete this.modelStoreys[e]}}},{key:"fitStoreyMaps",get:function(){return this._fitStoreyMaps}},{key:"gotoStoreyCamera",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=this.storeys[e];if(!i)return this.error("IfcBuildingStorey not found with this ID: "+e),void(t.done&&t.done());var s=this.viewer,r=s.scene,n=r.camera,o=i.storeyAABB;if(o[3]1&&void 0!==arguments[1]?arguments[1]:{},i=this.storeys[e];if(i){var s=this.viewer,r=s.scene,n=s.metaScene,o=n.metaObjects[e];o&&(t.hideOthers&&r.setObjectsVisible(s.scene.visibleObjectIds,!1),this.withStoreyObjects(e,(function(e,t){e&&(e.visible=!0)})))}else this.error("IfcBuildingStorey not found with this ID: "+e)}},{key:"withStoreyObjects",value:function(e,t){var i=this.viewer,s=i.scene,r=i.metaScene,n=r.metaObjects[e];if(n)for(var o=n.getObjectIDsInSubtree(),a=0,l=o.length;a1&&void 0!==arguments[1]?arguments[1]:{},i=this.storeys[e];if(!i)return this.error("IfcBuildingStorey not found with this ID: "+e),UF;var s,r,n=this.viewer,o=n.scene,a=t.format||"png",l=this._fitStoreyMaps?i.storeyAABB:i.modelAABB,u=Math.abs((l[5]-l[2])/(l[3]-l[0])),A=t.padding||0;t.width&&t.height?(s=t.width,r=t.height):t.height?(r=t.height,s=Math.round(r/u)):t.width?(s=t.width,r=Math.round(s*u)):(s=300,r=Math.round(s*u)),this._objectsMemento.saveObjects(o),this._cameraMemento.saveCamera(o),this.showStoreyObjects(e,le.apply(t,{hideOthers:!0})),this._arrangeStoreyMapCamera(i);var c=n.getSnapshot({width:s,height:r,format:a});return this._objectsMemento.restoreObjects(o),this._cameraMemento.restoreCamera(o),new TF(e,c,a,s,r,A)}},{key:"_arrangeStoreyMapCamera",value:function(e){var t=this.viewer,i=t.scene.camera,s=this._fitStoreyMaps?e.storeyAABB:e.modelAABB,r=$.getAABB3Center(s),n=RF;n[0]=r[0]+.5*i.worldUp[0],n[1]=r[1]+.5*i.worldUp[1],n[2]=r[2]+.5*i.worldUp[2];var o=i.worldForward;t.cameraFlight.jumpTo({eye:n,look:r,up:o});var a=(s[3]-s[0])/2,l=(s[4]-s[1])/2,u=(s[5]-s[2])/2,A=-a,c=+a,h=-l,d=+l,p=-u,f=+u;t.camera.customProjection.matrix=$.orthoMat4c(A,c,p,f,h,d,LF),t.camera.projection="customProjection"}},{key:"pickStoreyMap",value:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=e.storeyId,r=this.storeys[s];if(!r)return this.error("IfcBuildingStorey not found with this ID: "+s),null;var n=1-t[0]/e.width,o=1-t[1]/e.height,a=this._fitStoreyMaps?r.storeyAABB:r.modelAABB,l=a[0],u=a[1],A=a[2],c=a[3],h=a[4],d=a[5],p=c-l,f=h-u,v=d-A,g=$.vec3([l+p*n,u+.5*f,A+v*o]),m=$.vec3([0,-1,0]),_=$.addVec3(g,m,RF),y=this.viewer.camera.worldForward,b=$.lookAtMat4v(g,_,y,LF),w=this.viewer.scene.pick({pickSurface:i.pickSurface,pickInvisible:!0,matrix:b});return w}},{key:"storeyMapToWorldPos",value:function(e,t){var i=e.storeyId,s=this.storeys[i];if(!s)return this.error("IfcBuildingStorey not found with this ID: "+i),null;var r=1-t[0]/e.width,n=1-t[1]/e.height,o=this._fitStoreyMaps?s.storeyAABB:s.modelAABB,a=o[0],l=o[1],u=o[2],A=o[3],c=o[4],h=o[5],d=A-a,p=c-l,f=h-u,v=$.vec3([a+d*r,l+.5*p,u+f*n]);return v}},{key:"getStoreyContainingWorldPos",value:function(e){for(var t in this.storeys){var i=this.storeys[t];if($.point3AABB3Intersect(i.storeyAABB,e))return t}return null}},{key:"worldPosToStoreyMap",value:function(e,t,i){var s=e.storeyId,r=this.storeys[s];if(!r)return this.error("IfcBuildingStorey not found with this ID: "+s),!1;var n=this._fitStoreyMaps?r.storeyAABB:r.modelAABB,o=n[0],a=n[1],l=n[2],u=n[3]-o,A=n[4]-a,c=n[5]-l,h=this.viewer.camera.worldUp,d=h[0]>h[1]&&h[0]>h[2],p=!d&&h[1]>h[0]&&h[1]>h[2];!d&&!p&&h[2]>h[0]&&(h[2],h[1]);var f=e.width/u,v=p?e.height/c:e.height/A;return i[0]=Math.floor(e.width-(t[0]-o)*f),i[1]=Math.floor(e.height-(t[2]-l)*v),i[0]>=0&&i[0]=0&&i[1]<=e.height}},{key:"worldDirToStoreyMap",value:function(e,t,i){var s=this.viewer.camera,r=s.eye,n=s.look,o=$.subVec3(n,r,RF),a=s.worldUp,l=a[0]>a[1]&&a[0]>a[2],u=!l&&a[1]>a[0]&&a[1]>a[2];!l&&!u&&a[2]>a[0]&&(a[2],a[1]),l?(i[0]=o[1],i[1]=o[2]):u?(i[0]=o[0],i[1]=o[2]):(i[0]=o[0],i[1]=o[1]),$.normalizeVec2(i)}},{key:"destroy",value:function(){this.viewer.scene.off(this._onModelLoaded),f(w(i.prototype),"destroy",this).call(this)}}]),i}(),NF=new Float64Array([0,0,1]),QF=new Float64Array(4),VF=function(){function e(t){x(this,e),this.id=null,this._viewer=t.viewer,this._plugin=t,this._visible=!1,this._pos=$.vec3(),this._origin=$.vec3(),this._rtcPos=$.vec3(),this._baseDir=$.vec3(),this._rootNode=null,this._displayMeshes=null,this._affordanceMeshes=null,this._ignoreNextSectionPlaneDirUpdate=!1,this._createNodes(),this._bindEvents()}return C(e,[{key:"_setSectionPlane",value:function(e){var t=this;this._sectionPlane&&(this._sectionPlane.off(this._onSectionPlanePos),this._sectionPlane.off(this._onSectionPlaneDir),this._onSectionPlanePos=null,this._onSectionPlaneDir=null,this._sectionPlane=null),e&&(this.id=e.id,this._setPos(e.pos),this._setDir(e.dir),this._sectionPlane=e,this._onSectionPlanePos=e.on("pos",(function(){t._setPos(t._sectionPlane.pos)})),this._onSectionPlaneDir=e.on("dir",(function(){t._ignoreNextSectionPlaneDirUpdate?t._ignoreNextSectionPlaneDirUpdate=!1:t._setDir(t._sectionPlane.dir)})))}},{key:"sectionPlane",get:function(){return this._sectionPlane}},{key:"_setPos",value:function(e){this._pos.set(e),Le(this._pos,this._origin,this._rtcPos),this._rootNode.origin=this._origin,this._rootNode.position=this._rtcPos}},{key:"_setDir",value:function(e){this._baseDir.set(e),this._rootNode.quaternion=$.vec3PairToQuaternion(NF,e,QF)}},{key:"_setSectionPlaneDir",value:function(e){this._sectionPlane&&(this._ignoreNextSectionPlaneDirUpdate=!0,this._sectionPlane.dir=e)}},{key:"setVisible",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(this._visible!==e){var t;for(t in this._visible=e,this._displayMeshes)this._displayMeshes.hasOwnProperty(t)&&(this._displayMeshes[t].visible=e);if(!e)for(t in this._affordanceMeshes)this._affordanceMeshes.hasOwnProperty(t)&&(this._affordanceMeshes[t].visible=e)}}},{key:"getVisible",value:function(){return this._visible}},{key:"setCulled",value:function(e){var t;for(t in this._displayMeshes)this._displayMeshes.hasOwnProperty(t)&&(this._displayMeshes[t].culled=e);if(!e)for(t in this._affordanceMeshes)this._affordanceMeshes.hasOwnProperty(t)&&(this._affordanceMeshes[t].culled=e)}},{key:"_createNodes",value:function(){var e=!1,t=this._viewer.scene,i=.01;this._rootNode=new bn(t,{position:[0,0,0],scale:[5,5,5]});var s=this._rootNode,r={arrowHead:new Si(s,on({radiusTop:.001,radiusBottom:.07,radialSegments:32,heightSegments:1,height:.2,openEnded:!1})),arrowHeadBig:new Si(s,on({radiusTop:.001,radiusBottom:.09,radialSegments:32,heightSegments:1,height:.25,openEnded:!1})),axis:new Si(s,on({radiusTop:i,radiusBottom:i,radialSegments:20,heightSegments:1,height:1,openEnded:!1}))},n={red:new Oi(s,{diffuse:[1,0,0],emissive:[1,0,0],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),green:new Oi(s,{diffuse:[0,1,0],emissive:[1,0,0],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),blue:new Oi(s,{diffuse:[0,0,1],emissive:[1,0,0],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),highlightRed:new Qi(s,{edges:!1,fill:!0,fillColor:[1,0,0],fillAlpha:.6})};this._displayMeshes={plane:s.addChild(new rn(s,{geometry:new Si(s,{primitive:"triangles",positions:[.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0,.5,.5,-0,.5,-.5,-0,-.5,-.5,-0,-.5,.5,-0],indices:[0,1,2,2,3,0]}),material:new Oi(s,{emissive:[0,0,0],diffuse:[0,0,0],backfaces:!0}),opacity:.6,ghosted:!0,pickable:!1,collidable:!0,clippable:!1,visible:!1,scale:[2.4,2.4,1]}),e),planeFrame:s.addChild(new rn(s,{geometry:new Si(s,Jn({center:[0,0,0],radius:1.7,tube:.02,radialSegments:4,tubeSegments:4,arc:2*Math.PI})),material:new Oi(s,{emissive:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],shininess:0}),pickable:!1,collidable:!1,clippable:!1,visible:!1,scale:[1,1,.1],rotation:[0,0,45]}),e),center:s.addChild(new rn(s,{geometry:new Si(s,an({radius:.05})),material:n.center,pickable:!1,collidable:!0,clippable:!1,visible:!1}),e),zAxisArrow:s.addChild(new rn(s,{geometry:r.arrowHead,material:n.blue,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[.8,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1}),e),zShaft:s.addChild(new rn(s,{geometry:r.axis,material:n.blue,matrix:function(){var e=$.translateMat4c(0,.5,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),clippable:!1,pickable:!1,collidable:!0,visible:!1}),e)},this._affordanceMeshes={planeFrame:s.addChild(new rn(s,{geometry:new Si(s,Jn({center:[0,0,0],radius:2,tube:i,radialSegments:4,tubeSegments:4,arc:2*Math.PI})),material:new Oi(s,{ambient:[1,1,1],diffuse:[0,0,0],emissive:[1,1,0]}),highlighted:!0,highlightMaterial:new Qi(s,{edges:!1,filled:!0,fillColor:[1,1,0],fillAlpha:1}),pickable:!1,collidable:!1,clippable:!1,visible:!1,scale:[1,1,1],rotation:[0,0,45]}),e),zAxisArrow:s.addChild(new rn(s,{geometry:r.arrowHeadBig,material:n.blue,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[.8,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1}),e)}}},{key:"_bindEvents",value:function(){var e=this,t=this._rootNode,i=$.vec2(),s=this._viewer.camera,r=this._viewer.scene,n=0,o=!1,a=$.vec3([0,0,0]),l=-1;this._onCameraViewMatrix=r.camera.on("viewMatrix",(function(){})),this._onCameraProjMatrix=r.camera.on("projMatrix",(function(){})),this._onSceneTick=r.on("tick",(function(){o=!1;var i=Math.abs($.lenVec3($.subVec3(r.camera.eye,e._pos,a)));if(i!==l&&"perspective"===s.projection){var u=.07*(Math.tan(s.perspective.fov*$.DEGTORAD)*i);t.scale=[u,u,u],l=i}if("ortho"===s.projection){var c=s.ortho.scale/10;t.scale=[c,c,c],l=i}0!==n&&(A(n),n=0)}));var u=function(){var e=new Float64Array(2);return function(t){if(t){for(var i=t.target,s=0,r=0;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;e[0]=t.pageX-s,e[1]=t.pageY-r}else t=window.event,e[0]=t.x,e[1]=t.y;return e}}(),A=function(t){var i=e._sectionPlane.pos,s=e._sectionPlane.dir;$.addVec3(i,$.mulVec3Scalar(s,.1*t*e._plugin.getDragSensitivity(),$.vec3())),e._sectionPlane.pos=i},c=!1;this._plugin._controlElement.addEventListener("mousedown",this._canvasMouseDownListener=function(t){if(t.preventDefault(),e._visible&&(e._viewer.cameraControl.pointerEnabled=!1,1===t.which)){c=!0;var s=u(t);i[0]=s[0],i[1]=s[1]}}),this._plugin._controlElement.addEventListener("mousemove",this._canvasMouseMoveListener=function(t){if(e._visible&&c&&!o){var s=u(t),r=s[0],n=s[1];A(n-i[1]),i[0]=r,i[1]=n}}),this._plugin._controlElement.addEventListener("mouseup",this._canvasMouseUpListener=function(t){e._visible&&(e._viewer.cameraControl.pointerEnabled=!0,c&&(t.which,c=!1))}),this._plugin._controlElement.addEventListener("wheel",this._canvasWheelListener=function(t){e._visible&&(n+=Math.max(-1,Math.min(1,40*-t.deltaY)))});var h,d,p=null;this._plugin._controlElement.addEventListener("touchstart",this._handleTouchStart=function(t){t.stopPropagation(),t.preventDefault(),e._visible&&(h=t.touches[0].clientY,p=h,n=0)}),this._plugin._controlElement.addEventListener("touchmove",this._handleTouchMove=function(t){t.stopPropagation(),t.preventDefault(),e._visible&&(o||(o=!0,d=t.touches[0].clientY,null!==p&&(n+=d-p),p=d))}),this._plugin._controlElement.addEventListener("touchend",this._handleTouchEnd=function(t){t.stopPropagation(),t.preventDefault(),e._visible&&(h=null,d=null,n=0)})}},{key:"_destroy",value:function(){this._unbindEvents(),this._destroyNodes()}},{key:"_unbindEvents",value:function(){var e=this._viewer,t=e.scene,i=t.canvas.canvas,s=e.camera,r=this._plugin._controlElement;t.off(this._onSceneTick),i.removeEventListener("mousedown",this._canvasMouseDownListener),i.removeEventListener("mousemove",this._canvasMouseMoveListener),i.removeEventListener("mouseup",this._canvasMouseUpListener),i.removeEventListener("wheel",this._canvasWheelListener),r.removeEventListener("touchstart",this._handleTouchStart),r.removeEventListener("touchmove",this._handleTouchMove),r.removeEventListener("touchend",this._handleTouchEnd),s.off(this._onCameraViewMatrix),s.off(this._onCameraProjMatrix)}},{key:"_destroyNodes",value:function(){this._setSectionPlane(null),this._rootNode.destroy(),this._displayMeshes={},this._affordanceMeshes={}}}]),e}(),HF=function(){function e(t,i,s){var r=this;x(this,e),this.id=s.id,this._sectionPlane=s,this._mesh=new rn(i,{id:s.id,geometry:new Si(i,Ti({xSize:.5,ySize:.5,zSize:.001})),material:new Oi(i,{emissive:[1,1,1],diffuse:[0,0,0],backfaces:!1}),edgeMaterial:new Hi(i,{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1}),highlightMaterial:new Qi(i,{fill:!0,fillColor:[.5,1,.5],fillAlpha:.7,edges:!0,edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1}),selectedMaterial:new Qi(i,{fill:!0,fillColor:[0,0,1],fillAlpha:.7,edges:!0,edgeColor:[1,0,0],edgeAlpha:1,edgeWidth:1}),highlighted:!0,scale:[3,3,3],position:[0,0,0],rotation:[0,0,0],opacity:.3,edges:!0});var n=$.vec3([0,0,0]),o=$.vec3(),a=$.vec3([0,0,1]),l=$.vec4(4),u=$.vec3(),A=function(){var e=r._sectionPlane.scene.center,t=[-r._sectionPlane.dir[0],-r._sectionPlane.dir[1],-r._sectionPlane.dir[2]];$.subVec3(e,r._sectionPlane.pos,n);var i=-$.dotVec3(t,n);$.normalizeVec3(t),$.mulVec3Scalar(t,i,o);var s=$.vec3PairToQuaternion(a,r._sectionPlane.dir,l);u[0]=.1*o[0],u[1]=.1*o[1],u[2]=.1*o[2],r._mesh.quaternion=s,r._mesh.position=u};this._onSectionPlanePos=this._sectionPlane.on("pos",A),this._onSectionPlaneDir=this._sectionPlane.on("dir",A),this._highlighted=!1,this._selected=!1}return C(e,[{key:"setHighlighted",value:function(e){this._highlighted=!!e,this._mesh.highlighted=this._highlighted,this._mesh.highlightMaterial.fillColor=e?[0,.7,0]:[0,0,0]}},{key:"getHighlighted",value:function(){return this._highlighted}},{key:"setSelected",value:function(e){this._selected=!!e,this._mesh.edgeMaterial.edgeWidth=e?3:1,this._mesh.highlightMaterial.edgeWidth=e?3:1}},{key:"getSelected",value:function(){return this._selected}},{key:"destroy",value:function(){this._sectionPlane.off(this._onSectionPlanePos),this._sectionPlane.off(this._onSectionPlaneDir),this._mesh.destroy()}}]),e}(),jF=function(){function e(t,i){var s=this;if(x(this,e),!(i.onHoverEnterPlane&&i.onHoverLeavePlane&&i.onClickedNothing&&i.onClickedPlane))throw"Missing config(s): onHoverEnterPlane, onHoverLeavePlane, onClickedNothing || onClickedPlane";this.plugin=t,this._viewer=t.viewer,this._onHoverEnterPlane=i.onHoverEnterPlane,this._onHoverLeavePlane=i.onHoverLeavePlane,this._onClickedNothing=i.onClickedNothing,this._onClickedPlane=i.onClickedPlane,this._visible=!0,this._planes={},this._canvas=i.overviewCanvas,this._scene=new qi(this._viewer,{canvasId:this._canvas.id,transparent:!0}),this._scene.clearLights(),new yi(this._scene,{dir:[.4,-.4,.8],color:[.8,1,1],intensity:1,space:"view"}),new yi(this._scene,{dir:[-.8,-.3,-.4],color:[.8,.8,.8],intensity:1,space:"view"}),new yi(this._scene,{dir:[.8,-.6,-.8],color:[1,1,1],intensity:1,space:"view"}),this._scene.camera,this._scene.camera.perspective.fov=70,this._zUp=!1;var r=this._scene.camera,n=$.rotationMat4c(-90*$.DEGTORAD,1,0,0),o=$.vec3(),a=$.vec3(),l=$.vec3();this._synchCamera=function(){var e=s._viewer.camera.eye,t=s._viewer.camera.look,i=s._viewer.camera.up;$.mulVec3Scalar($.normalizeVec3($.subVec3(e,t,o)),7),s._zUp?($.transformVec3(n,o,a),$.transformVec3(n,i,l),r.look=[0,0,0],r.eye=$.transformVec3(n,o,a),r.up=$.transformPoint3(n,i,l)):(r.look=[0,0,0],r.eye=o,r.up=i)},this._onViewerCameraMatrix=this._viewer.camera.on("matrix",this._synchCamera),this._onViewerCameraWorldAxis=this._viewer.camera.on("worldAxis",this._synchCamera),this._onViewerCameraFOV=this._viewer.camera.perspective.on("fov",(function(e){s._scene.camera.perspective.fov=e}));var u=null;this._onInputMouseMove=this._scene.input.on("mousemove",(function(e){var t=s._scene.pick({canvasPos:e});if(t){if(!u||t.entity.id!==u.id){if(u)s._planes[u.id]&&s._onHoverLeavePlane(u.id);u=t.entity,s._planes[u.id]&&s._onHoverEnterPlane(u.id)}}else u&&(s._onHoverLeavePlane(u.id),u=null)})),this._scene.canvas.canvas.addEventListener("mouseup",this._onCanvasMouseUp=function(){u?s._planes[u.id]&&s._onClickedPlane(u.id):s._onClickedNothing()}),this._scene.canvas.canvas.addEventListener("mouseout",this._onCanvasMouseOut=function(){u&&(s._onHoverLeavePlane(u.id),u=null)}),this.setVisible(i.overviewVisible)}return C(e,[{key:"addSectionPlane",value:function(e){this._planes[e.id]=new HF(this,this._scene,e)}},{key:"setPlaneHighlighted",value:function(e,t){var i=this._planes[e];i&&i.setHighlighted(t)}},{key:"setPlaneSelected",value:function(e,t){var i=this._planes[e];i&&i.setSelected(t)}},{key:"removeSectionPlane",value:function(e){var t=this._planes[e.id];t&&(t.destroy(),delete this._planes[e.id])}},{key:"setVisible",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this._visible=e,this._canvas.style.visibility=e?"visible":"hidden"}},{key:"getVisible",value:function(){return this._visible}},{key:"destroy",value:function(){this._viewer.camera.off(this._onViewerCameraMatrix),this._viewer.camera.off(this._onViewerCameraWorldAxis),this._viewer.camera.perspective.off(this._onViewerCameraFOV),this._scene.input.off(this._onInputMouseMove),this._scene.canvas.canvas.removeEventListener("mouseup",this._onCanvasMouseUp),this._scene.canvas.canvas.removeEventListener("mouseout",this._onCanvasMouseOut),this._scene.destroy()}}]),e}(),GF=$.AABB3(),zF=$.vec3(),WF=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,"FaceAlignedSectionPlanesPlugin",e))._freeControls=[],s._sectionPlanes=e.scene.sectionPlanes,s._controls={},s._shownControlId=null,s._dragSensitivity=r.dragSensitivity||1,null!==r.overviewCanvasId&&void 0!==r.overviewCanvasId){var n=document.getElementById(r.overviewCanvasId);n?s._overview=new jF(b(s),{overviewCanvas:n,visible:r.overviewVisible,onHoverEnterPlane:function(e){s._overview.setPlaneHighlighted(e,!0)},onHoverLeavePlane:function(e){s._overview.setPlaneHighlighted(e,!1)},onClickedPlane:function(e){if(s.getShownControl()!==e){s.showControl(e);var t=s.sectionPlanes[e].pos;GF.set(s.viewer.scene.aabb),$.getAABB3Center(GF,zF),GF[0]+=t[0]-zF[0],GF[1]+=t[1]-zF[1],GF[2]+=t[2]-zF[2],GF[3]+=t[0]-zF[0],GF[4]+=t[1]-zF[1],GF[5]+=t[2]-zF[2],s.viewer.cameraFlight.flyTo({aabb:GF,fitFOV:65})}else s.hideControl()},onClickedNothing:function(){s.hideControl()}}):s.warn("Can't find overview canvas: '"+r.overviewCanvasId+"' - will create plugin without overview")}return null===r.controlElementId||void 0===r.controlElementId?s.error("Parameter expected: controlElementId"):(s._controlElement=document.getElementById(r.controlElementId),s._controlElement||s.warn("Can't find control element: '"+r.controlElementId+"' - will create plugin without control element")),s._onSceneSectionPlaneCreated=e.scene.on("sectionPlaneCreated",(function(e){s._sectionPlaneCreated(e)})),s}return C(i,[{key:"setDragSensitivity",value:function(e){this._dragSensitivity=e||1}},{key:"getDragSensitivity",value:function(){return this._dragSensitivity}},{key:"setOverviewVisible",value:function(e){this._overview&&this._overview.setVisible(e)}},{key:"getOverviewVisible",value:function(){if(this._overview)return this._overview.getVisible()}},{key:"sectionPlanes",get:function(){return this._sectionPlanes}},{key:"createSectionPlane",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};void 0!==e.id&&null!==e.id&&this.viewer.scene.components[e.id]&&(this.error("Viewer component with this ID already exists: "+e.id),delete e.id);var t=new cn(this.viewer.scene,{id:e.id,pos:e.pos,dir:e.dir,active:!0});return t}},{key:"_sectionPlaneCreated",value:function(e){var t=this,i=this._freeControls.length>0?this._freeControls.pop():new VF(this);i._setSectionPlane(e),i.setVisible(!1),this._controls[e.id]=i,this._overview&&this._overview.addSectionPlane(e),e.once("destroyed",(function(){t._sectionPlaneDestroyed(e)}))}},{key:"flipSectionPlanes",value:function(){var e=this.viewer.scene.sectionPlanes;for(var t in e){e[t].flipDir()}}},{key:"showControl",value:function(e){var t=this._controls[e];t?(this.hideControl(),t.setVisible(!0),this._overview&&this._overview.setPlaneSelected(e,!0),this._shownControlId=e):this.error("Control not found: "+e)}},{key:"getShownControl",value:function(){return this._shownControlId}},{key:"hideControl",value:function(){for(var e in this._controls)this._controls.hasOwnProperty(e)&&(this._controls[e].setVisible(!1),this._overview&&this._overview.setPlaneSelected(e,!1));this._shownControlId=null}},{key:"destroySectionPlane",value:function(e){var t=this.viewer.scene.sectionPlanes[e];t?(this._sectionPlaneDestroyed(t),t.destroy(),e===this._shownControlId&&(this._shownControlId=null)):this.error("SectionPlane not found: "+e)}},{key:"_sectionPlaneDestroyed",value:function(e){this._overview&&this._overview.removeSectionPlane(e);var t=this._controls[e.id];t&&(t.setVisible(!1),t._setSectionPlane(null),delete this._controls[e.id],this._freeControls.push(t))}},{key:"clear",value:function(){for(var e=Object.keys(this._sectionPlanes),t=0,i=e.length;t>5&31)/31,o=(F>>10&31)/31):(r=l,n=u,o=A),(w&&r!==p||n!==f||o!==v)&&(null!==p&&(g=!0),p=r,f=n,v=o)}for(var E=1;E<=3;E++){var k=x+12*E;y.push(c.getFloat32(k,!0)),y.push(c.getFloat32(k+4,!0)),y.push(c.getFloat32(k+8,!0)),b.push(P,C,M),d&&a.push(r,n,o,1)}w&&g&&(eE(i,y,b,a,_,s),y=[],b=[],a=a?[]:null,g=!1)}y.length>0&&eE(i,y,b,a,_,s)}function $F(e,t,i,s){for(var r,n,o,a,l,u,A,c=/facet([\s\S]*?)endfacet/g,h=0,d=/[\s]+([+-]?(?:\d+.\d+|\d+.|\d+|.\d+)(?:[eE][+-]?\d+)?)/.source,p=new RegExp("vertex"+d+d+d,"g"),f=new RegExp("normal"+d+d+d,"g"),v=[],g=[];null!==(a=c.exec(t));){for(l=0,u=0,A=a[0];null!==(a=f.exec(A));)r=parseFloat(a[1]),n=parseFloat(a[2]),o=parseFloat(a[3]),u++;for(;null!==(a=p.exec(A));)v.push(parseFloat(a[1]),parseFloat(a[2]),parseFloat(a[3])),g.push(r,n,o),l++;1!==u&&e.error("Error in normal of face "+h),3!==l&&e.error("Error in positions of face "+h),h++}eE(i,v,g,null,new Pn(i,{roughness:.5}),s)}function eE(e,t,i,s,r,n){for(var o=new Int32Array(t.length/3),a=0,l=o.length;a0?i:null,s=s&&s.length>0?s:null,n.smoothNormals&&$.faceToVertexNormals(t,i,n);var u=JF;Ue(t,t,u);var A=new Si(e,{primitive:"triangles",positions:t,normals:i,colors:s,indices:o}),c=new rn(e,{origin:0!==u[0]||0!==u[1]||0!==u[2]?u:null,geometry:A,material:r,edges:n.edges});e.addChild(c)}function tE(e){return"string"!=typeof e?function(e){if("undefined"!=typeof TextDecoder)return(new TextDecoder).decode(e);for(var t="",i=0,s=e.length;i1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"STLLoader",e,r))._sceneGraphLoader=new YF,s.dataSource=r.dataSource,s}return C(i,[{key:"dataSource",get:function(){return this._dataSource},set:function(e){this._dataSource=e||new XF}},{key:"load",value:function(e){e.id&&this.viewer.scene.components[e.id]&&(this.error("Component with this ID already exists in viewer: "+e.id+" - will autogenerate this ID"),delete e.id);var t=new bn(this.viewer.scene,le.apply(e,{isModel:!0})),i=e.src,s=e.stl;return i||s?(i?this._sceneGraphLoader.load(this,t,i,e):this._sceneGraphLoader.parse(this,t,s,e),t):(this.error("load() param expected: either 'src' or 'stl'"),t)}}]),i}(),rE=function(){function e(){x(this,e)}return C(e,[{key:"createRootNode",value:function(){return document.createElement("ul")}},{key:"createNodeElement",value:function(e,t,i,s,r){var n=document.createElement("li");if(n.id=e.nodeId,e.xrayed&&n.classList.add("xrayed-node"),e.children.length>0){var o=document.createElement("a");o.href="#",o.id="switch-".concat(e.nodeId),o.textContent="+",o.classList.add("plus"),t&&o.addEventListener("click",t),n.appendChild(o)}var a=document.createElement("input");a.id="checkbox-".concat(e.nodeId),a.type="checkbox",a.checked=e.checked,a.style["pointer-events"]="all",i&&a.addEventListener("change",i),n.appendChild(a);var l=document.createElement("span");return l.textContent=e.title,n.appendChild(l),s&&(l.oncontextmenu=s),r&&(l.onclick=r),n}},{key:"createDisabledNodeElement",value:function(e){var t=document.createElement("li"),i=document.createElement("a");i.href="#",i.textContent="!",i.classList.add("warn"),i.classList.add("warning"),t.appendChild(i);var s=document.createElement("span");return s.textContent=e,t.appendChild(s),t}},{key:"addChildren",value:function(e,t){var i=document.createElement("ul");t.forEach((function(e){i.appendChild(e)})),e.parentElement.appendChild(i)}},{key:"expand",value:function(e,t,i){e.classList.remove("plus"),e.classList.add("minus"),e.textContent="-",e.removeEventListener("click",t),e.addEventListener("click",i)}},{key:"collapse",value:function(e,t,i){if(e){var s=e.parentElement;if(s){var r=s.querySelector("ul");r&&(s.removeChild(r),e.classList.remove("minus"),e.classList.add("plus"),e.textContent="+",e.removeEventListener("click",i),e.addEventListener("click",t))}}}},{key:"isExpanded",value:function(e){return void 0!==e.parentElement.getElementsByTagName("li")[0]}},{key:"getId",value:function(e){return e.parentElement.id}},{key:"getIdFromCheckbox",value:function(e){return e.id.replace("checkbox-","")}},{key:"getSwitchElement",value:function(e){return document.getElementById("switch-".concat(e))}},{key:"isChecked",value:function(e){return e.checked}},{key:"setCheckbox",value:function(e,t){var i=document.getElementById("checkbox-".concat(e));i&&t!==i.checked&&(i.checked=t)}},{key:"setXRayed",value:function(e,t){var i=document.getElementById(e);i&&(t?i.classList.add("xrayed-node"):i.classList.remove("xrayed-node"))}},{key:"setHighlighted",value:function(e,t){var i=document.getElementById(e);i&&(t?(i.scrollIntoView({block:"center"}),i.classList.add("highlighted-node")):i.classList.remove("highlighted-node"))}}]),e}(),nE=[],oE=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,"TreeViewPlugin",e)).errors=[],s.valid=!0;var n=r.containerElement||document.getElementById(r.containerElementId);if(!(n instanceof HTMLElement))return s.error("Mandatory config expected: valid containerElementId or containerElement"),y(s);for(var o=0;;o++)if(!nE[o]){nE[o]=b(s),s._index=o,s._id="tree-".concat(o);break}if(s._containerElement=n,s._metaModels={},s._autoAddModels=!1!==r.autoAddModels,s._autoExpandDepth=r.autoExpandDepth||0,s._sortNodes=!1!==r.sortNodes,s._viewer=e,s._rootElement=null,s._muteSceneEvents=!1,s._muteTreeEvents=!1,s._rootNodes=[],s._objectNodes={},s._nodeNodes={},s._rootNames={},s._sortNodes=r.sortNodes,s._pruneEmptyNodes=r.pruneEmptyNodes,s._showListItemElementId=null,s._renderService=r.renderService||new rE,!s._renderService)throw new Error("TreeViewPlugin: no render service set");if(s._containerElement.oncontextmenu=function(e){e.preventDefault()},s._onObjectVisibility=s._viewer.scene.on("objectVisibility",(function(e){if(!s._muteSceneEvents){var t=e.id,i=s._objectNodes[t];if(i){var r=e.visible;if(r!==i.checked){s._muteTreeEvents=!0,i.checked=r,r?i.numVisibleEntities++:i.numVisibleEntities--,s._renderService.setCheckbox(i.nodeId,r);for(var n=i.parent;n;)n.checked=r,r?n.numVisibleEntities++:n.numVisibleEntities--,s._renderService.setCheckbox(n.nodeId,n.numVisibleEntities>0),n=n.parent;s._muteTreeEvents=!1}}}})),s._onObjectXrayed=s._viewer.scene.on("objectXRayed",(function(e){if(!s._muteSceneEvents){var t=e.id,i=s._objectNodes[t];if(i){s._muteTreeEvents=!0;var r=e.xrayed;r!==i.xrayed&&(i.xrayed=r,s._renderService.setXRayed(i.nodeId,r),s._muteTreeEvents=!1)}}})),s._switchExpandHandler=function(e){e.preventDefault(),e.stopPropagation();var t=e.target;s._expandSwitchElement(t)},s._switchCollapseHandler=function(e){e.preventDefault(),e.stopPropagation();var t=e.target;s._collapseSwitchElement(t)},s._checkboxChangeHandler=function(e){if(!s._muteTreeEvents){s._muteSceneEvents=!0;var t=e.target,i=s._renderService.isChecked(t),r=s._renderService.getIdFromCheckbox(t),n=s._nodeNodes[r],o=s._viewer.scene.objects,a=0;s._withNodeTree(n,(function(e){var t=e.objectId,r=o[t],n=0===e.children.length;e.numVisibleEntities=i?e.numEntities:0,n&&i!==e.checked&&a++,e.checked=i,s._renderService.setCheckbox(e.nodeId,i),r&&(r.visible=i)}));for(var l=n.parent;l;)l.checked=i,i?l.numVisibleEntities+=a:l.numVisibleEntities-=a,s._renderService.setCheckbox(l.nodeId,l.numVisibleEntities>0),l=l.parent;s._muteSceneEvents=!1}},s._hierarchy=r.hierarchy||"containment",s._autoExpandDepth=r.autoExpandDepth||0,s._autoAddModels){for(var a=Object.keys(s.viewer.metaScene.metaModels),l=0,u=a.length;l1&&void 0!==arguments[1]?arguments[1]:{};if(this._containerElement){var s=this.viewer.scene.models[e];if(!s)throw"Model not found: "+e;var r=this.viewer.metaScene.metaModels[e];r?this._metaModels[e]?this.warn("Model already added: "+e):(this._metaModels[e]=r,i&&i.rootName&&(this._rootNames[e]=i.rootName),s.on("destroyed",(function(){t.removeModel(s.id)})),this._createNodes()):this.error("MetaModel not found: "+e)}}},{key:"removeModel",value:function(e){this._containerElement&&(this._metaModels[e]&&(this._rootNames[e]&&delete this._rootNames[e],delete this._metaModels[e],this._createNodes()))}},{key:"showNode",value:function(e){this.unShowNode();var t=this._objectNodes[e];if(t){var i=t.nodeId,s=this._renderService.getSwitchElement(i);if(s)return this._expandSwitchElement(s),s.scrollIntoView(),!0;var r=[];r.unshift(t);for(var n=t.parent;n;)r.unshift(n),n=n.parent;for(var o=0,a=r.length;o0;return this.valid}},{key:"_validateMetaModelForStoreysHierarchy",value:function(){return!0}},{key:"_createEnabledNodes",value:function(){switch(this._pruneEmptyNodes&&this._findEmptyNodes(),this._hierarchy){case"storeys":this._createStoreysNodes(),0===this._rootNodes.length&&this.error("Failed to build storeys hierarchy");break;case"types":this._createTypesNodes();break;default:this._createContainmentNodes()}this._sortNodes&&this._doSortNodes(),this._synchNodesToEntities(),this._createTrees(),this.expandToDepth(this._autoExpandDepth)}},{key:"_createDisabledNodes",value:function(){var e=this._renderService.createRootNode();this._rootElement=e,this._containerElement.appendChild(e);var t=this._viewer.metaScene.rootMetaObjects;for(var i in t){var s=t[i],r=s.type,n=s.name,o=n&&""!==n&&"Undefined"!==n&&"Default"!==n?n:r,a=this._renderService.createDisabledNodeElement(o);e.appendChild(a)}}},{key:"_findEmptyNodes",value:function(){var e=this._viewer.metaScene.rootMetaObjects;for(var t in e)this._findEmptyNodes2(e[t])}},{key:"_findEmptyNodes2",value:function(e){var t=this.viewer,i=t.scene,s=e.children,r=e.id,n=i.objects[r];if(e._countEntities=0,n&&e._countEntities++,s)for(var o=0,a=s.length;or.aabb[n]?-1:e.aabb[n]s?1:0}},{key:"_synchNodesToEntities",value:function(){for(var e=Object.keys(this.viewer.metaScene.metaObjects),t=this._viewer.metaScene.metaObjects,i=this._viewer.scene.objects,s=0,r=e.length;s0){for(var e=0;e1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"ViewCull",e))._objectCullStates=uE(e.scene),s._maxTreeDepth=r.maxTreeDepth||8,s._modelInfos={},s._frustum=new Me,s._kdRoot=null,s._frustumDirty=!1,s._kdTreeDirty=!1,s._onViewMatrix=e.scene.camera.on("viewMatrix",(function(){s._frustumDirty=!0})),s._onProjMatrix=e.scene.camera.on("projMatMatrix",(function(){s._frustumDirty=!0})),s._onModelLoaded=e.scene.on("modelLoaded",(function(e){var t=s.viewer.scene.models[e];t&&s._addModel(t)})),s._onSceneTick=e.scene.on("tick",(function(){s._doCull()})),s}return C(i,[{key:"enabled",get:function(){return this._enabled},set:function(e){this._enabled=e}},{key:"_addModel",value:function(e){var t=this,i={model:e,onDestroyed:e.on("destroyed",(function(){t._removeModel(e)}))};this._modelInfos[e.id]=i,this._kdTreeDirty=!0}},{key:"_removeModel",value:function(e){var t=this._modelInfos[e.id];t&&(t.model.off(t.onDestroyed),delete this._modelInfos[e.id],this._kdTreeDirty=!0)}},{key:"_doCull",value:function(){var e=this._frustumDirty||this._kdTreeDirty;if(this._frustumDirty&&this._buildFrustum(),this._kdTreeDirty&&this._buildKDTree(),e){var t=this._kdRoot;t&&this._visitKDNode(t)}}},{key:"_buildFrustum",value:function(){var e=this.viewer.scene.camera;Fe(this._frustum,e.viewMatrix,e.projMatrix),this._frustumDirty=!1}},{key:"_buildKDTree",value:function(){var e=this.viewer.scene;this._kdRoot,this._kdRoot={aabb:e.getAABB(),intersection:Me.INTERSECT};for(var t=0,i=this._objectCullStates.numObjects;t=this._maxTreeDepth)return e.objects=e.objects||[],e.objects.push(i),void $.expandAABB3(e.aabb,r);if(e.left&&$.containsAABB3(e.left.aabb,r))this._insertEntityIntoKDTree(e.left,t,i,s+1);else if(e.right&&$.containsAABB3(e.right.aabb,r))this._insertEntityIntoKDTree(e.right,t,i,s+1);else{var n=e.aabb;AE[0]=n[3]-n[0],AE[1]=n[4]-n[1],AE[2]=n[5]-n[2];var o=0;if(AE[1]>AE[o]&&(o=1),AE[2]>AE[o]&&(o=2),!e.left){var a=n.slice();if(a[o+3]=(n[o]+n[o+3])/2,e.left={aabb:a,intersection:Me.INTERSECT},$.containsAABB3(a,r))return void this._insertEntityIntoKDTree(e.left,t,i,s+1)}if(!e.right){var l=n.slice();if(l[o]=(n[o]+n[o+3])/2,e.right={aabb:l,intersection:Me.INTERSECT},$.containsAABB3(l,r))return void this._insertEntityIntoKDTree(e.right,t,i,s+1)}e.objects=e.objects||[],e.objects.push(i),$.expandAABB3(e.aabb,r)}}},{key:"_visitKDNode",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Me.INTERSECT;if(t===Me.INTERSECT||e.intersects!==t){t===Me.INTERSECT&&(t=Ee(this._frustum,e.aabb),e.intersects=t);var i=t===Me.OUTSIDE,s=e.objects;if(s&&s.length>0)for(var r=0,n=s.length;r=0;)e[t]=0}var i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),s=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),r=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),n=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),o=new Array(576);t(o);var a=new Array(60);t(a);var l=new Array(512);t(l);var u=new Array(256);t(u);var A=new Array(29);t(A);var c,h,d,p=new Array(30);function f(e,t,i,s,r){this.static_tree=e,this.extra_bits=t,this.extra_base=i,this.elems=s,this.max_length=r,this.has_stree=e&&e.length}function v(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}t(p);var g=function(e){return e<256?l[e]:l[256+(e>>>7)]},m=function(e,t){e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},_=function(e,t,i){e.bi_valid>16-i?(e.bi_buf|=t<>16-e.bi_valid,e.bi_valid+=i-16):(e.bi_buf|=t<>>=1,i<<=1}while(--t>0);return i>>>1},w=function(e,t,i){var s,r,n=new Array(16),o=0;for(s=1;s<=15;s++)o=o+i[s-1]<<1,n[s]=o;for(r=0;r<=t;r++){var a=e[2*r+1];0!==a&&(e[2*r]=b(n[a]++,a))}},x=function(e){var t;for(t=0;t<286;t++)e.dyn_ltree[2*t]=0;for(t=0;t<30;t++)e.dyn_dtree[2*t]=0;for(t=0;t<19;t++)e.bl_tree[2*t]=0;e.dyn_ltree[512]=1,e.opt_len=e.static_len=0,e.sym_next=e.matches=0},P=function(e){e.bi_valid>8?m(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},C=function(e,t,i,s){var r=2*t,n=2*i;return e[r]>1;i>=1;i--)M(e,n,i);r=l;do{i=e.heap[1],e.heap[1]=e.heap[e.heap_len--],M(e,n,1),s=e.heap[1],e.heap[--e.heap_max]=i,e.heap[--e.heap_max]=s,n[2*r]=n[2*i]+n[2*s],e.depth[r]=(e.depth[i]>=e.depth[s]?e.depth[i]:e.depth[s])+1,n[2*i+1]=n[2*s+1]=r,e.heap[1]=r++,M(e,n,1)}while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],function(e,t){var i,s,r,n,o,a,l=t.dyn_tree,u=t.max_code,A=t.stat_desc.static_tree,c=t.stat_desc.has_stree,h=t.stat_desc.extra_bits,d=t.stat_desc.extra_base,p=t.stat_desc.max_length,f=0;for(n=0;n<=15;n++)e.bl_count[n]=0;for(l[2*e.heap[e.heap_max]+1]=0,i=e.heap_max+1;i<573;i++)(n=l[2*l[2*(s=e.heap[i])+1]+1]+1)>p&&(n=p,f++),l[2*s+1]=n,s>u||(e.bl_count[n]++,o=0,s>=d&&(o=h[s-d]),a=l[2*s],e.opt_len+=a*(n+o),c&&(e.static_len+=a*(A[2*s+1]+o)));if(0!==f){do{for(n=p-1;0===e.bl_count[n];)n--;e.bl_count[n]--,e.bl_count[n+1]+=2,e.bl_count[p]--,f-=2}while(f>0);for(n=p;0!==n;n--)for(s=e.bl_count[n];0!==s;)(r=e.heap[--i])>u||(l[2*r+1]!==n&&(e.opt_len+=(n-l[2*r+1])*l[2*r],l[2*r+1]=n),s--)}}(e,t),w(n,u,e.bl_count)},k=function(e,t,i){var s,r,n=-1,o=t[1],a=0,l=7,u=4;for(0===o&&(l=138,u=3),t[2*(i+1)+1]=65535,s=0;s<=i;s++)r=o,o=t[2*(s+1)+1],++a>=7;v<30;v++)for(p[v]=g<<7,e=0;e<1<0?(2===e.strm.data_type&&(e.strm.data_type=function(e){var t,i=4093624447;for(t=0;t<=31;t++,i>>>=1)if(1&i&&0!==e.dyn_ltree[2*t])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(t=32;t<256;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0}(e)),E(e,e.l_desc),E(e,e.d_desc),u=function(e){var t;for(k(e,e.dyn_ltree,e.l_desc.max_code),k(e,e.dyn_dtree,e.d_desc.max_code),E(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*n[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t}(e),r=e.opt_len+3+7>>>3,(l=e.static_len+3+7>>>3)<=r&&(r=l)):r=l=i+5,i+4<=r&&-1!==t?S(e,t,i,s):4===e.strategy||l===r?(_(e,2+(s?1:0),3),F(e,o,a)):(_(e,4+(s?1:0),3),function(e,t,i,s){var r;for(_(e,t-257,5),_(e,i-1,5),_(e,s-4,4),r=0;r>8,e.pending_buf[e.sym_buf+e.sym_next++]=i,0===t?e.dyn_ltree[2*i]++:(e.matches++,t--,e.dyn_ltree[2*(u[i]+256+1)]++,e.dyn_dtree[2*g(t)]++),e.sym_next===e.sym_end},O=function(e){_(e,2,3),y(e,256,o),function(e){16===e.bi_valid?(m(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}(e)},N=function(e,t,i,s){for(var r=65535&e|0,n=e>>>16&65535|0,o=0;0!==i;){i-=o=i>2e3?2e3:i;do{n=n+(r=r+t[s++]|0)|0}while(--o);r%=65521,n%=65521}return r|n<<16|0},Q=new Uint32Array(function(){for(var e,t=[],i=0;i<256;i++){e=i;for(var s=0;s<8;s++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e}return t}()),V=function(e,t,i,s){var r=Q,n=s+i;e^=-1;for(var o=s;o>>8^r[255&(e^t[o])];return-1^e},H={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},j={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},G=T,z=R,W=L,K=U,X=O,J=j.Z_NO_FLUSH,Y=j.Z_PARTIAL_FLUSH,Z=j.Z_FULL_FLUSH,q=j.Z_FINISH,$=j.Z_BLOCK,ee=j.Z_OK,te=j.Z_STREAM_END,ie=j.Z_STREAM_ERROR,se=j.Z_DATA_ERROR,re=j.Z_BUF_ERROR,ne=j.Z_DEFAULT_COMPRESSION,oe=j.Z_FILTERED,ae=j.Z_HUFFMAN_ONLY,le=j.Z_RLE,ue=j.Z_FIXED,Ae=j.Z_UNKNOWN,ce=j.Z_DEFLATED,he=258,de=262,pe=42,fe=113,ve=666,ge=function(e,t){return e.msg=H[t],t},me=function(e){return 2*e-(e>4?9:0)},_e=function(e){for(var t=e.length;--t>=0;)e[t]=0},ye=function(e){var t,i,s,r=e.w_size;s=t=e.hash_size;do{i=e.head[--s],e.head[s]=i>=r?i-r:0}while(--t);s=t=r;do{i=e.prev[--s],e.prev[s]=i>=r?i-r:0}while(--t)},be=function(e,t,i){return(t<e.avail_out&&(i=e.avail_out),0!==i&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+i),e.next_out),e.next_out+=i,t.pending_out+=i,e.total_out+=i,e.avail_out-=i,t.pending-=i,0===t.pending&&(t.pending_out=0))},Be=function(e,t){W(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,we(e.strm)},xe=function(e,t){e.pending_buf[e.pending++]=t},Pe=function(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},Ce=function(e,t,i,s){var r=e.avail_in;return r>s&&(r=s),0===r?0:(e.avail_in-=r,t.set(e.input.subarray(e.next_in,e.next_in+r),i),1===e.state.wrap?e.adler=N(e.adler,t,r,i):2===e.state.wrap&&(e.adler=V(e.adler,t,r,i)),e.next_in+=r,e.total_in+=r,r)},Me=function(e,t){var i,s,r=e.max_chain_length,n=e.strstart,o=e.prev_length,a=e.nice_match,l=e.strstart>e.w_size-de?e.strstart-(e.w_size-de):0,u=e.window,A=e.w_mask,c=e.prev,h=e.strstart+he,d=u[n+o-1],p=u[n+o];e.prev_length>=e.good_match&&(r>>=2),a>e.lookahead&&(a=e.lookahead);do{if(u[(i=t)+o]===p&&u[i+o-1]===d&&u[i]===u[n]&&u[++i]===u[n+1]){n+=2,i++;do{}while(u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&no){if(e.match_start=t,o=s,s>=a)break;d=u[n+o-1],p=u[n+o]}}}while((t=c[t&A])>l&&0!=--r);return o<=e.lookahead?o:e.lookahead},Fe=function(e){var t,i,s,r=e.w_size;do{if(i=e.window_size-e.lookahead-e.strstart,e.strstart>=r+(r-de)&&(e.window.set(e.window.subarray(r,r+r-i),0),e.match_start-=r,e.strstart-=r,e.block_start-=r,e.insert>e.strstart&&(e.insert=e.strstart),ye(e),i+=r),0===e.strm.avail_in)break;if(t=Ce(e.strm,e.window,e.strstart+e.lookahead,i),e.lookahead+=t,e.lookahead+e.insert>=3)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=be(e,e.ins_h,e.window[s+1]);e.insert&&(e.ins_h=be(e,e.ins_h,e.window[s+3-1]),e.prev[s&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=s,s++,e.insert--,!(e.lookahead+e.insert<3)););}while(e.lookaheade.w_size?e.w_size:e.pending_buf_size-5,o=0,a=e.strm.avail_in;do{if(i=65535,r=e.bi_valid+42>>3,e.strm.avail_out(s=e.strstart-e.block_start)+e.strm.avail_in&&(i=s+e.strm.avail_in),i>r&&(i=r),i>8,e.pending_buf[e.pending-2]=~i,e.pending_buf[e.pending-1]=~i>>8,we(e.strm),s&&(s>i&&(s=i),e.strm.output.set(e.window.subarray(e.block_start,e.block_start+s),e.strm.next_out),e.strm.next_out+=s,e.strm.avail_out-=s,e.strm.total_out+=s,e.block_start+=s,i-=s),i&&(Ce(e.strm,e.strm.output,e.strm.next_out,i),e.strm.next_out+=i,e.strm.avail_out-=i,e.strm.total_out+=i)}while(0===o);return(a-=e.strm.avail_in)&&(a>=e.w_size?(e.matches=2,e.window.set(e.strm.input.subarray(e.strm.next_in-e.w_size,e.strm.next_in),0),e.strstart=e.w_size,e.insert=e.strstart):(e.window_size-e.strstart<=a&&(e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,e.insert>e.strstart&&(e.insert=e.strstart)),e.window.set(e.strm.input.subarray(e.strm.next_in-a,e.strm.next_in),e.strstart),e.strstart+=a,e.insert+=a>e.w_size-e.insert?e.w_size-e.insert:a),e.block_start=e.strstart),e.high_waterr&&e.block_start>=e.w_size&&(e.block_start-=e.w_size,e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,r+=e.w_size,e.insert>e.strstart&&(e.insert=e.strstart)),r>e.strm.avail_in&&(r=e.strm.avail_in),r&&(Ce(e.strm,e.window,e.strstart,r),e.strstart+=r,e.insert+=r>e.w_size-e.insert?e.w_size-e.insert:r),e.high_water>3,n=(r=e.pending_buf_size-r>65535?65535:e.pending_buf_size-r)>e.w_size?e.w_size:r,((s=e.strstart-e.block_start)>=n||(s||t===q)&&t!==J&&0===e.strm.avail_in&&s<=r)&&(i=s>r?r:s,o=t===q&&0===e.strm.avail_in&&i===s?1:0,z(e,e.block_start,i,o),e.block_start+=i,we(e.strm)),o?3:1)},ke=function(e,t){for(var i,s;;){if(e.lookahead=3&&(e.ins_h=be(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==i&&e.strstart-i<=e.w_size-de&&(e.match_length=Me(e,i)),e.match_length>=3)if(s=K(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=3){e.match_length--;do{e.strstart++,e.ins_h=be(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart}while(0!=--e.match_length);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=be(e,e.ins_h,e.window[e.strstart+1]);else s=K(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(s&&(Be(e,!1),0===e.strm.avail_out))return 1}return e.insert=e.strstart<2?e.strstart:2,t===q?(Be(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(Be(e,!1),0===e.strm.avail_out)?1:2},Ie=function(e,t){for(var i,s,r;;){if(e.lookahead=3&&(e.ins_h=be(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==i&&e.prev_length4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){r=e.strstart+e.lookahead-3,s=K(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do{++e.strstart<=r&&(e.ins_h=be(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart)}while(0!=--e.prev_length);if(e.match_available=0,e.match_length=2,e.strstart++,s&&(Be(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if((s=K(e,0,e.window[e.strstart-1]))&&Be(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(s=K(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===q?(Be(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(Be(e,!1),0===e.strm.avail_out)?1:2};function De(e,t,i,s,r){this.good_length=e,this.max_lazy=t,this.nice_length=i,this.max_chain=s,this.func=r}var Se=[new De(0,0,0,0,Ee),new De(4,4,8,4,ke),new De(4,5,16,8,ke),new De(4,6,32,32,ke),new De(4,4,16,16,Ie),new De(8,16,32,32,Ie),new De(8,16,128,128,Ie),new De(8,32,128,256,Ie),new De(32,128,258,1024,Ie),new De(32,258,258,4096,Ie)];function Te(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ce,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),_e(this.dyn_ltree),_e(this.dyn_dtree),_e(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),_e(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),_e(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Re=function(e){if(!e)return 1;var t=e.state;return!t||t.strm!==e||t.status!==pe&&57!==t.status&&69!==t.status&&73!==t.status&&91!==t.status&&103!==t.status&&t.status!==fe&&t.status!==ve?1:0},Le=function(e){if(Re(e))return ge(e,ie);e.total_in=e.total_out=0,e.data_type=Ae;var t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=2===t.wrap?57:t.wrap?pe:fe,e.adler=2===t.wrap?0:1,t.last_flush=-2,G(t),ee},Ue=function(e){var t,i=Le(e);return i===ee&&((t=e.state).window_size=2*t.w_size,_e(t.head),t.max_lazy_match=Se[t.level].max_lazy,t.good_match=Se[t.level].good_length,t.nice_match=Se[t.level].nice_length,t.max_chain_length=Se[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=2,t.match_available=0,t.ins_h=0),i},Oe=function(e,t,i,s,r,n){if(!e)return ie;var o=1;if(t===ne&&(t=6),s<0?(o=0,s=-s):s>15&&(o=2,s-=16),r<1||r>9||i!==ce||s<8||s>15||t<0||t>9||n<0||n>ue||8===s&&1!==o)return ge(e,ie);8===s&&(s=9);var a=new Te;return e.state=a,a.strm=e,a.status=pe,a.wrap=o,a.gzhead=null,a.w_bits=s,a.w_size=1<$||t<0)return e?ge(e,ie):ie;var i=e.state;if(!e.output||0!==e.avail_in&&!e.input||i.status===ve&&t!==q)return ge(e,0===e.avail_out?re:ie);var s=i.last_flush;if(i.last_flush=t,0!==i.pending){if(we(e),0===e.avail_out)return i.last_flush=-1,ee}else if(0===e.avail_in&&me(t)<=me(s)&&t!==q)return ge(e,re);if(i.status===ve&&0!==e.avail_in)return ge(e,re);if(i.status===pe&&0===i.wrap&&(i.status=fe),i.status===pe){var r=ce+(i.w_bits-8<<4)<<8;if(r|=(i.strategy>=ae||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(r|=32),Pe(i,r+=31-r%31),0!==i.strstart&&(Pe(i,e.adler>>>16),Pe(i,65535&e.adler)),e.adler=1,i.status=fe,we(e),0!==i.pending)return i.last_flush=-1,ee}if(57===i.status)if(e.adler=0,xe(i,31),xe(i,139),xe(i,8),i.gzhead)xe(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),xe(i,255&i.gzhead.time),xe(i,i.gzhead.time>>8&255),xe(i,i.gzhead.time>>16&255),xe(i,i.gzhead.time>>24&255),xe(i,9===i.level?2:i.strategy>=ae||i.level<2?4:0),xe(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(xe(i,255&i.gzhead.extra.length),xe(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(e.adler=V(e.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69;else if(xe(i,0),xe(i,0),xe(i,0),xe(i,0),xe(i,0),xe(i,9===i.level?2:i.strategy>=ae||i.level<2?4:0),xe(i,3),i.status=fe,we(e),0!==i.pending)return i.last_flush=-1,ee;if(69===i.status){if(i.gzhead.extra){for(var n=i.pending,o=(65535&i.gzhead.extra.length)-i.gzindex;i.pending+o>i.pending_buf_size;){var a=i.pending_buf_size-i.pending;if(i.pending_buf.set(i.gzhead.extra.subarray(i.gzindex,i.gzindex+a),i.pending),i.pending=i.pending_buf_size,i.gzhead.hcrc&&i.pending>n&&(e.adler=V(e.adler,i.pending_buf,i.pending-n,n)),i.gzindex+=a,we(e),0!==i.pending)return i.last_flush=-1,ee;n=0,o-=a}var l=new Uint8Array(i.gzhead.extra);i.pending_buf.set(l.subarray(i.gzindex,i.gzindex+o),i.pending),i.pending+=o,i.gzhead.hcrc&&i.pending>n&&(e.adler=V(e.adler,i.pending_buf,i.pending-n,n)),i.gzindex=0}i.status=73}if(73===i.status){if(i.gzhead.name){var u,A=i.pending;do{if(i.pending===i.pending_buf_size){if(i.gzhead.hcrc&&i.pending>A&&(e.adler=V(e.adler,i.pending_buf,i.pending-A,A)),we(e),0!==i.pending)return i.last_flush=-1,ee;A=0}u=i.gzindexA&&(e.adler=V(e.adler,i.pending_buf,i.pending-A,A)),i.gzindex=0}i.status=91}if(91===i.status){if(i.gzhead.comment){var c,h=i.pending;do{if(i.pending===i.pending_buf_size){if(i.gzhead.hcrc&&i.pending>h&&(e.adler=V(e.adler,i.pending_buf,i.pending-h,h)),we(e),0!==i.pending)return i.last_flush=-1,ee;h=0}c=i.gzindexh&&(e.adler=V(e.adler,i.pending_buf,i.pending-h,h))}i.status=103}if(103===i.status){if(i.gzhead.hcrc){if(i.pending+2>i.pending_buf_size&&(we(e),0!==i.pending))return i.last_flush=-1,ee;xe(i,255&e.adler),xe(i,e.adler>>8&255),e.adler=0}if(i.status=fe,we(e),0!==i.pending)return i.last_flush=-1,ee}if(0!==e.avail_in||0!==i.lookahead||t!==J&&i.status!==ve){var d=0===i.level?Ee(i,t):i.strategy===ae?function(e,t){for(var i;;){if(0===e.lookahead&&(Fe(e),0===e.lookahead)){if(t===J)return 1;break}if(e.match_length=0,i=K(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,i&&(Be(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===q?(Be(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(Be(e,!1),0===e.strm.avail_out)?1:2}(i,t):i.strategy===le?function(e,t){for(var i,s,r,n,o=e.window;;){if(e.lookahead<=he){if(Fe(e),e.lookahead<=he&&t===J)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&((s=o[r=e.strstart-1])===o[++r]&&s===o[++r]&&s===o[++r])){n=e.strstart+he;do{}while(s===o[++r]&&s===o[++r]&&s===o[++r]&&s===o[++r]&&s===o[++r]&&s===o[++r]&&s===o[++r]&&s===o[++r]&&re.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(i=K(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(i=K(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),i&&(Be(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===q?(Be(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(Be(e,!1),0===e.strm.avail_out)?1:2}(i,t):Se[i.level].func(i,t);if(3!==d&&4!==d||(i.status=ve),1===d||3===d)return 0===e.avail_out&&(i.last_flush=-1),ee;if(2===d&&(t===Y?X(i):t!==$&&(z(i,0,0,!1),t===Z&&(_e(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),we(e),0===e.avail_out))return i.last_flush=-1,ee}return t!==q?ee:i.wrap<=0?te:(2===i.wrap?(xe(i,255&e.adler),xe(i,e.adler>>8&255),xe(i,e.adler>>16&255),xe(i,e.adler>>24&255),xe(i,255&e.total_in),xe(i,e.total_in>>8&255),xe(i,e.total_in>>16&255),xe(i,e.total_in>>24&255)):(Pe(i,e.adler>>>16),Pe(i,65535&e.adler)),we(e),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?ee:te)},He=function(e){if(Re(e))return ie;var t=e.state.status;return e.state=null,t===fe?ge(e,se):ee},je=function(e,t){var i=t.length;if(Re(e))return ie;var s=e.state,r=s.wrap;if(2===r||1===r&&s.status!==pe||s.lookahead)return ie;if(1===r&&(e.adler=N(e.adler,t,i,0)),s.wrap=0,i>=s.w_size){0===r&&(_e(s.head),s.strstart=0,s.block_start=0,s.insert=0);var n=new Uint8Array(s.w_size);n.set(t.subarray(i-s.w_size,i),0),t=n,i=s.w_size}var o=e.avail_in,a=e.next_in,l=e.input;for(e.avail_in=i,e.next_in=0,e.input=t,Fe(s);s.lookahead>=3;){var u=s.strstart,A=s.lookahead-2;do{s.ins_h=be(s,s.ins_h,s.window[u+3-1]),s.prev[u&s.w_mask]=s.head[s.ins_h],s.head[s.ins_h]=u,u++}while(--A);s.strstart=u,s.lookahead=2,Fe(s)}return s.strstart+=s.lookahead,s.block_start=s.strstart,s.insert=s.lookahead,s.lookahead=0,s.match_length=s.prev_length=2,s.match_available=0,e.next_in=a,e.input=l,e.avail_in=o,s.wrap=r,ee},Ge=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},ze=function(e){for(var t=Array.prototype.slice.call(arguments,1);t.length;){var i=t.shift();if(i){if("object"!=B(i))throw new TypeError(i+"must be non-object");for(var s in i)Ge(i,s)&&(e[s]=i[s])}}return e},We=function(e){for(var t=0,i=0,s=e.length;i=252?6:Je>=248?5:Je>=240?4:Je>=224?3:Je>=192?2:1;Xe[254]=Xe[254]=1;var Ye=function(e){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);var t,i,s,r,n,o=e.length,a=0;for(r=0;r>>6,t[n++]=128|63&i):i<65536?(t[n++]=224|i>>>12,t[n++]=128|i>>>6&63,t[n++]=128|63&i):(t[n++]=240|i>>>18,t[n++]=128|i>>>12&63,t[n++]=128|i>>>6&63,t[n++]=128|63&i);return t},Ze=function(e,t){var i,s,r=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));var n=new Array(2*r);for(s=0,i=0;i4)n[s++]=65533,i+=a-1;else{for(o&=2===a?31:3===a?15:7;a>1&&i1?n[s++]=65533:o<65536?n[s++]=o:(o-=65536,n[s++]=55296|o>>10&1023,n[s++]=56320|1023&o)}}}return function(e,t){if(t<65534&&e.subarray&&Ke)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));for(var i="",s=0;se.length&&(t=e.length);for(var i=t-1;i>=0&&128==(192&e[i]);)i--;return i<0||0===i?t:i+Xe[e[i]]>t?i:t},$e=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},et=Object.prototype.toString,tt=j.Z_NO_FLUSH,it=j.Z_SYNC_FLUSH,st=j.Z_FULL_FLUSH,rt=j.Z_FINISH,nt=j.Z_OK,ot=j.Z_STREAM_END,at=j.Z_DEFAULT_COMPRESSION,lt=j.Z_DEFAULT_STRATEGY,ut=j.Z_DEFLATED;function At(e){this.options=ze({level:at,method:ut,chunkSize:16384,windowBits:15,memLevel:8,strategy:lt},e||{});var t=this.options;t.raw&&t.windowBits>0?t.windowBits=-t.windowBits:t.gzip&&t.windowBits>0&&t.windowBits<16&&(t.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new $e,this.strm.avail_out=0;var i=Ne(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(i!==nt)throw new Error(H[i]);if(t.header&&Qe(this.strm,t.header),t.dictionary){var s;if(s="string"==typeof t.dictionary?Ye(t.dictionary):"[object ArrayBuffer]"===et.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,(i=je(this.strm,s))!==nt)throw new Error(H[i]);this._dict_set=!0}}function ct(e,t){var i=new At(t);if(i.push(e,!0),i.err)throw i.msg||H[i.err];return i.result}At.prototype.push=function(e,t){var i,s,r=this.strm,n=this.options.chunkSize;if(this.ended)return!1;for(s=t===~~t?t:!0===t?rt:tt,"string"==typeof e?r.input=Ye(e):"[object ArrayBuffer]"===et.call(e)?r.input=new Uint8Array(e):r.input=e,r.next_in=0,r.avail_in=r.input.length;;)if(0===r.avail_out&&(r.output=new Uint8Array(n),r.next_out=0,r.avail_out=n),(s===it||s===st)&&r.avail_out<=6)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else{if((i=Ve(r,s))===ot)return r.next_out>0&&this.onData(r.output.subarray(0,r.next_out)),i=He(this.strm),this.onEnd(i),this.ended=!0,i===nt;if(0!==r.avail_out){if(s>0&&r.next_out>0)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else if(0===r.avail_in)break}else this.onData(r.output)}return!0},At.prototype.onData=function(e){this.chunks.push(e)},At.prototype.onEnd=function(e){e===nt&&(this.result=We(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var ht=At,dt=ct,pt=function(e,t){return(t=t||{}).raw=!0,ct(e,t)},ft=function(e,t){return(t=t||{}).gzip=!0,ct(e,t)},vt=16209,gt=function(e,t){var i,s,r,n,o,a,l,u,A,c,h,d,p,f,v,g,m,_,y,b,w,B,x,P,C=e.state;i=e.next_in,x=e.input,s=i+(e.avail_in-5),r=e.next_out,P=e.output,n=r-(t-e.avail_out),o=r+(e.avail_out-257),a=C.dmax,l=C.wsize,u=C.whave,A=C.wnext,c=C.window,h=C.hold,d=C.bits,p=C.lencode,f=C.distcode,v=(1<>>=_=m>>>24,d-=_,0===(_=m>>>16&255))P[r++]=65535&m;else{if(!(16&_)){if(0==(64&_)){m=p[(65535&m)+(h&(1<<_)-1)];continue t}if(32&_){C.mode=16191;break e}e.msg="invalid literal/length code",C.mode=vt;break e}y=65535&m,(_&=15)&&(d<_&&(h+=x[i++]<>>=_,d-=_),d<15&&(h+=x[i++]<>>=_=m>>>24,d-=_,!(16&(_=m>>>16&255))){if(0==(64&_)){m=f[(65535&m)+(h&(1<<_)-1)];continue i}e.msg="invalid distance code",C.mode=vt;break e}if(b=65535&m,d<(_&=15)&&(h+=x[i++]<a){e.msg="invalid distance too far back",C.mode=vt;break e}if(h>>>=_,d-=_,b>(_=r-n)){if((_=b-_)>u&&C.sane){e.msg="invalid distance too far back",C.mode=vt;break e}if(w=0,B=c,0===A){if(w+=l-_,_2;)P[r++]=B[w++],P[r++]=B[w++],P[r++]=B[w++],y-=3;y&&(P[r++]=B[w++],y>1&&(P[r++]=B[w++]))}else{w=r-b;do{P[r++]=P[w++],P[r++]=P[w++],P[r++]=P[w++],y-=3}while(y>2);y&&(P[r++]=P[w++],y>1&&(P[r++]=P[w++]))}break}}break}}while(i>3,h&=(1<<(d-=y<<3))-1,e.next_in=i,e.next_out=r,e.avail_in=i=1&&0===E[b];b--);if(w>b&&(w=b),0===b)return r[n++]=20971520,r[n++]=20971520,a.bits=1,0;for(y=1;y0&&(0===e||1!==b))return-1;for(k[1]=0,m=1;m<15;m++)k[m+1]=k[m]+E[m];for(_=0;_852||2===e&&C>592)return 1;for(;;){p=m-x,o[_]+1=d?(f=I[o[_]-d],v=F[o[_]-d]):(f=96,v=0),l=1<>x)+(u-=l)]=p<<24|f<<16|v|0}while(0!==u);for(l=1<>=1;if(0!==l?(M&=l-1,M+=l):M=0,_++,0==--E[m]){if(m===b)break;m=t[i+o[_]]}if(m>w&&(M&c)!==A){for(0===x&&(x=w),h+=y,P=1<<(B=m-x);B+x852||2===e&&C>592)return 1;r[A=M&c]=w<<24|B<<16|h-n|0}}return 0!==M&&(r[h+M]=m-x<<24|64<<16|0),a.bits=w,0},Bt=j.Z_FINISH,xt=j.Z_BLOCK,Pt=j.Z_TREES,Ct=j.Z_OK,Mt=j.Z_STREAM_END,Ft=j.Z_NEED_DICT,Et=j.Z_STREAM_ERROR,kt=j.Z_DATA_ERROR,It=j.Z_MEM_ERROR,Dt=j.Z_BUF_ERROR,St=j.Z_DEFLATED,Tt=16180,Rt=16190,Lt=16191,Ut=16192,Ot=16194,Nt=16199,Qt=16200,Vt=16206,Ht=16209,jt=function(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)};function Gt(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var zt,Wt,Kt=function(e){if(!e)return 1;var t=e.state;return!t||t.strm!==e||t.mode16211?1:0},Xt=function(e){if(Kt(e))return Et;var t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=Tt,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,Ct},Jt=function(e){if(Kt(e))return Et;var t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,Xt(e)},Yt=function(e,t){var i;if(Kt(e))return Et;var s=e.state;return t<0?(i=0,t=-t):(i=5+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?Et:(null!==s.window&&s.wbits!==t&&(s.window=null),s.wrap=i,s.wbits=t,Jt(e))},Zt=function(e,t){if(!e)return Et;var i=new Gt;e.state=i,i.strm=e,i.window=null,i.mode=Tt;var s=Yt(e,t);return s!==Ct&&(e.state=null),s},qt=!0,$t=function(e){if(qt){zt=new Int32Array(512),Wt=new Int32Array(32);for(var t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(wt(1,e.lens,0,288,zt,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;wt(2,e.lens,0,32,Wt,0,e.work,{bits:5}),qt=!1}e.lencode=zt,e.lenbits=9,e.distcode=Wt,e.distbits=5},ei=function(e,t,i,s){var r,n=e.state;return null===n.window&&(n.wsize=1<=n.wsize?(n.window.set(t.subarray(i-n.wsize,i),0),n.wnext=0,n.whave=n.wsize):((r=n.wsize-n.wnext)>s&&(r=s),n.window.set(t.subarray(i-s,i-s+r),n.wnext),(s-=r)?(n.window.set(t.subarray(i-s,i),0),n.wnext=s,n.whave=n.wsize):(n.wnext+=r,n.wnext===n.wsize&&(n.wnext=0),n.whave>>8&255,i.check=V(i.check,M,2,0),u=0,A=0,i.mode=16181;break}if(i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&u)<<8)+(u>>8))%31){e.msg="incorrect header check",i.mode=Ht;break}if((15&u)!==St){e.msg="unknown compression method",i.mode=Ht;break}if(A-=4,w=8+(15&(u>>>=4)),0===i.wbits&&(i.wbits=w),w>15||w>i.wbits){e.msg="invalid window size",i.mode=Ht;break}i.dmax=1<>8&1),512&i.flags&&4&i.wrap&&(M[0]=255&u,M[1]=u>>>8&255,i.check=V(i.check,M,2,0)),u=0,A=0,i.mode=16182;case 16182:for(;A<32;){if(0===a)break e;a--,u+=s[n++]<>>8&255,M[2]=u>>>16&255,M[3]=u>>>24&255,i.check=V(i.check,M,4,0)),u=0,A=0,i.mode=16183;case 16183:for(;A<16;){if(0===a)break e;a--,u+=s[n++]<>8),512&i.flags&&4&i.wrap&&(M[0]=255&u,M[1]=u>>>8&255,i.check=V(i.check,M,2,0)),u=0,A=0,i.mode=16184;case 16184:if(1024&i.flags){for(;A<16;){if(0===a)break e;a--,u+=s[n++]<>>8&255,i.check=V(i.check,M,2,0)),u=0,A=0}else i.head&&(i.head.extra=null);i.mode=16185;case 16185:if(1024&i.flags&&((d=i.length)>a&&(d=a),d&&(i.head&&(w=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(s.subarray(n,n+d),w)),512&i.flags&&4&i.wrap&&(i.check=V(i.check,s,d,n)),a-=d,n+=d,i.length-=d),i.length))break e;i.length=0,i.mode=16186;case 16186:if(2048&i.flags){if(0===a)break e;d=0;do{w=s[n+d++],i.head&&w&&i.length<65536&&(i.head.name+=String.fromCharCode(w))}while(w&&d>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=Lt;break;case 16189:for(;A<32;){if(0===a)break e;a--,u+=s[n++]<>>=7&A,A-=7&A,i.mode=Vt;break}for(;A<3;){if(0===a)break e;a--,u+=s[n++]<>>=1)){case 0:i.mode=16193;break;case 1:if($t(i),i.mode=Nt,t===Pt){u>>>=2,A-=2;break e}break;case 2:i.mode=16196;break;case 3:e.msg="invalid block type",i.mode=Ht}u>>>=2,A-=2;break;case 16193:for(u>>>=7&A,A-=7&A;A<32;){if(0===a)break e;a--,u+=s[n++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=Ht;break}if(i.length=65535&u,u=0,A=0,i.mode=Ot,t===Pt)break e;case Ot:i.mode=16195;case 16195:if(d=i.length){if(d>a&&(d=a),d>l&&(d=l),0===d)break e;r.set(s.subarray(n,n+d),o),a-=d,n+=d,l-=d,o+=d,i.length-=d;break}i.mode=Lt;break;case 16196:for(;A<14;){if(0===a)break e;a--,u+=s[n++]<>>=5,A-=5,i.ndist=1+(31&u),u>>>=5,A-=5,i.ncode=4+(15&u),u>>>=4,A-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=Ht;break}i.have=0,i.mode=16197;case 16197:for(;i.have>>=3,A-=3}for(;i.have<19;)i.lens[F[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,x={bits:i.lenbits},B=wt(0,i.lens,0,19,i.lencode,0,i.work,x),i.lenbits=x.bits,B){e.msg="invalid code lengths set",i.mode=Ht;break}i.have=0,i.mode=16198;case 16198:for(;i.have>>16&255,m=65535&C,!((v=C>>>24)<=A);){if(0===a)break e;a--,u+=s[n++]<>>=v,A-=v,i.lens[i.have++]=m;else{if(16===m){for(P=v+2;A>>=v,A-=v,0===i.have){e.msg="invalid bit length repeat",i.mode=Ht;break}w=i.lens[i.have-1],d=3+(3&u),u>>>=2,A-=2}else if(17===m){for(P=v+3;A>>=v)),u>>>=3,A-=3}else{for(P=v+7;A>>=v)),u>>>=7,A-=7}if(i.have+d>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=Ht;break}for(;d--;)i.lens[i.have++]=w}}if(i.mode===Ht)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=Ht;break}if(i.lenbits=9,x={bits:i.lenbits},B=wt(1,i.lens,0,i.nlen,i.lencode,0,i.work,x),i.lenbits=x.bits,B){e.msg="invalid literal/lengths set",i.mode=Ht;break}if(i.distbits=6,i.distcode=i.distdyn,x={bits:i.distbits},B=wt(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,x),i.distbits=x.bits,B){e.msg="invalid distances set",i.mode=Ht;break}if(i.mode=Nt,t===Pt)break e;case Nt:i.mode=Qt;case Qt:if(a>=6&&l>=258){e.next_out=o,e.avail_out=l,e.next_in=n,e.avail_in=a,i.hold=u,i.bits=A,gt(e,h),o=e.next_out,r=e.output,l=e.avail_out,n=e.next_in,s=e.input,a=e.avail_in,u=i.hold,A=i.bits,i.mode===Lt&&(i.back=-1);break}for(i.back=0;g=(C=i.lencode[u&(1<>>16&255,m=65535&C,!((v=C>>>24)<=A);){if(0===a)break e;a--,u+=s[n++]<>_)])>>>16&255,m=65535&C,!(_+(v=C>>>24)<=A);){if(0===a)break e;a--,u+=s[n++]<>>=_,A-=_,i.back+=_}if(u>>>=v,A-=v,i.back+=v,i.length=m,0===g){i.mode=16205;break}if(32&g){i.back=-1,i.mode=Lt;break}if(64&g){e.msg="invalid literal/length code",i.mode=Ht;break}i.extra=15&g,i.mode=16201;case 16201:if(i.extra){for(P=i.extra;A>>=i.extra,A-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=16202;case 16202:for(;g=(C=i.distcode[u&(1<>>16&255,m=65535&C,!((v=C>>>24)<=A);){if(0===a)break e;a--,u+=s[n++]<>_)])>>>16&255,m=65535&C,!(_+(v=C>>>24)<=A);){if(0===a)break e;a--,u+=s[n++]<>>=_,A-=_,i.back+=_}if(u>>>=v,A-=v,i.back+=v,64&g){e.msg="invalid distance code",i.mode=Ht;break}i.offset=m,i.extra=15&g,i.mode=16203;case 16203:if(i.extra){for(P=i.extra;A>>=i.extra,A-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=Ht;break}i.mode=16204;case 16204:if(0===l)break e;if(d=h-l,i.offset>d){if((d=i.offset-d)>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=Ht;break}d>i.wnext?(d-=i.wnext,p=i.wsize-d):p=i.wnext-d,d>i.length&&(d=i.length),f=i.window}else f=r,p=o-i.offset,d=i.length;d>l&&(d=l),l-=d,i.length-=d;do{r[o++]=f[p++]}while(--d);0===i.length&&(i.mode=Qt);break;case 16205:if(0===l)break e;r[o++]=i.length,l--,i.mode=Qt;break;case Vt:if(i.wrap){for(;A<32;){if(0===a)break e;a--,u|=s[n++]<=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new $e,this.strm.avail_out=0;var i=ii(this.strm,t.windowBits);if(i!==ci)throw new Error(H[i]);if(this.header=new ai,ni(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=Ye(t.dictionary):"[object ArrayBuffer]"===li.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=oi(this.strm,t.dictionary))!==ci))throw new Error(H[i])}function mi(e,t){var i=new gi(t);if(i.push(e),i.err)throw i.msg||H[i.err];return i.result}gi.prototype.push=function(e,t){var i,s,r,n=this.strm,o=this.options.chunkSize,a=this.options.dictionary;if(this.ended)return!1;for(s=t===~~t?t:!0===t?Ai:ui,"[object ArrayBuffer]"===li.call(e)?n.input=new Uint8Array(e):n.input=e,n.next_in=0,n.avail_in=n.input.length;;){for(0===n.avail_out&&(n.output=new Uint8Array(o),n.next_out=0,n.avail_out=o),(i=si(n,s))===di&&a&&((i=oi(n,a))===ci?i=si(n,s):i===fi&&(i=di));n.avail_in>0&&i===hi&&n.state.wrap>0&&0!==e[n.next_in];)ti(n),i=si(n,s);switch(i){case pi:case fi:case di:case vi:return this.onEnd(i),this.ended=!0,!1}if(r=n.avail_out,n.next_out&&(0===n.avail_out||i===hi))if("string"===this.options.to){var l=qe(n.output,n.next_out),u=n.next_out-l,A=Ze(n.output,l);n.next_out=u,n.avail_out=o-u,u&&n.output.set(n.output.subarray(l,l+u),0),this.onData(A)}else this.onData(n.output.length===n.next_out?n.output:n.output.subarray(0,n.next_out));if(i!==ci||0!==r){if(i===hi)return i=ri(this.strm),this.onEnd(i),this.ended=!0,!0;if(0===n.avail_in)break}}return!0},gi.prototype.onData=function(e){this.chunks.push(e)},gi.prototype.onEnd=function(e){e===ci&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=We(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var _i=function(e,t){return(t=t||{}).raw=!0,mi(e,t)},yi=ht,bi=dt,wi=pt,Bi=ft,xi=gi,Pi=mi,Ci=_i,Mi=mi,Fi=j,Ei={Deflate:yi,deflate:bi,deflateRaw:wi,gzip:Bi,Inflate:xi,inflate:Pi,inflateRaw:Ci,ungzip:Mi,constants:Fi};e.Deflate=yi,e.Inflate=xi,e.constants=Fi,e.default=Ei,e.deflate=bi,e.deflateRaw=wi,e.gzip=Bi,e.inflate=Pi,e.inflateRaw=Ci,e.ungzip=Mi,Object.defineProperty(e,"__esModule",{value:!0})}));var dE=Object.freeze({__proto__:null}),pE=window.pako||dE;pE.inflate||(pE=pE.default);var fE,vE=(fE=new Float32Array(3),function(e){return fE[0]=e[0]/255,fE[1]=e[1]/255,fE[2]=e[2]/255,fE});var gE={version:1,parse:function(e,t,i,s,r,n){var o=function(e){return{positions:e[0],normals:e[1],indices:e[2],edgeIndices:e[3],meshPositions:e[4],meshIndices:e[5],meshEdgesIndices:e[6],meshColors:e[7],entityIDs:e[8],entityMeshes:e[9],entityIsObjects:e[10],positionsDecodeMatrix:e[11]}}(i),a=function(e){return{positions:new Uint16Array(pE.inflate(e.positions).buffer),normals:new Int8Array(pE.inflate(e.normals).buffer),indices:new Uint32Array(pE.inflate(e.indices).buffer),edgeIndices:new Uint32Array(pE.inflate(e.edgeIndices).buffer),meshPositions:new Uint32Array(pE.inflate(e.meshPositions).buffer),meshIndices:new Uint32Array(pE.inflate(e.meshIndices).buffer),meshEdgesIndices:new Uint32Array(pE.inflate(e.meshEdgesIndices).buffer),meshColors:new Uint8Array(pE.inflate(e.meshColors).buffer),entityIDs:pE.inflate(e.entityIDs,{to:"string"}),entityMeshes:new Uint32Array(pE.inflate(e.entityMeshes).buffer),entityIsObjects:new Uint8Array(pE.inflate(e.entityIsObjects).buffer),positionsDecodeMatrix:new Float32Array(pE.inflate(e.positionsDecodeMatrix).buffer)}}(o);!function(e,t,i,s,r,n){n.getNextId(),s.positionsCompression="precompressed",s.normalsCompression="precompressed";for(var o=i.positions,a=i.normals,l=i.indices,u=i.edgeIndices,A=i.meshPositions,c=i.meshIndices,h=i.meshEdgesIndices,d=i.meshColors,p=JSON.parse(i.entityIDs),f=i.entityMeshes,v=i.entityIsObjects,g=A.length,m=f.length,_=0;_v[t]?1:0}));for(var F=0;F1||(E[L]=k)}for(var U=0;U1,V=PE(g.subarray(4*O,4*O+3)),H=g[4*O+3]/255,j=a.subarray(d[O],N?a.length:d[O+1]),G=l.subarray(d[O],N?l.length:d[O+1]),z=u.subarray(p[O],N?u.length:p[O+1]),W=A.subarray(f[O],N?A.length:f[O+1]),K=c.subarray(v[O],v[O]+16);if(Q){var X="".concat(o,"-geometry.").concat(O);s.createGeometry({id:X,primitive:"triangles",positionsCompressed:j,normalsCompressed:G,indices:z,edgeIndices:W,positionsDecodeMatrix:K})}else{var J="".concat(o,"-").concat(O);_[E[O]],s.createMesh(le.apply({},{id:J,primitive:"triangles",positionsCompressed:j,normalsCompressed:G,indices:z,edgeIndices:W,positionsDecodeMatrix:K,color:V,opacity:H}))}}for(var Y=0,Z=0;Z1){var oe="".concat(o,"-instance.").concat(Y++),ae="".concat(o,"-geometry.").concat(ne),ue=16*b[Z],Ae=h.subarray(ue,ue+16);s.createMesh(le.apply({},{id:oe,geometryId:ae,matrix:Ae})),se.push(oe)}else se.push(ne)}se.length>0&&s.createEntity(le.apply({},{id:ee,isObject:!0,meshIds:se}))}}(0,0,a,s,0,n)}},ME=window.pako||dE;ME.inflate||(ME=ME.default);var FE=function(){var e=new Float32Array(3);return function(t){return e[0]=t[0]/255,e[1]=t[1]/255,e[2]=t[2]/255,e}}();var EE={version:5,parse:function(e,t,i,s,r,n){var o=function(e){return{positions:e[0],normals:e[1],indices:e[2],edgeIndices:e[3],matrices:e[4],eachPrimitivePositionsAndNormalsPortion:e[5],eachPrimitiveIndicesPortion:e[6],eachPrimitiveEdgeIndicesPortion:e[7],eachPrimitiveColor:e[8],primitiveInstances:e[9],eachEntityId:e[10],eachEntityPrimitiveInstancesPortion:e[11],eachEntityMatricesPortion:e[12]}}(i),a=function(e){return{positions:new Float32Array(ME.inflate(e.positions).buffer),normals:new Int8Array(ME.inflate(e.normals).buffer),indices:new Uint32Array(ME.inflate(e.indices).buffer),edgeIndices:new Uint32Array(ME.inflate(e.edgeIndices).buffer),matrices:new Float32Array(ME.inflate(e.matrices).buffer),eachPrimitivePositionsAndNormalsPortion:new Uint32Array(ME.inflate(e.eachPrimitivePositionsAndNormalsPortion).buffer),eachPrimitiveIndicesPortion:new Uint32Array(ME.inflate(e.eachPrimitiveIndicesPortion).buffer),eachPrimitiveEdgeIndicesPortion:new Uint32Array(ME.inflate(e.eachPrimitiveEdgeIndicesPortion).buffer),eachPrimitiveColor:new Uint8Array(ME.inflate(e.eachPrimitiveColor).buffer),primitiveInstances:new Uint32Array(ME.inflate(e.primitiveInstances).buffer),eachEntityId:ME.inflate(e.eachEntityId,{to:"string"}),eachEntityPrimitiveInstancesPortion:new Uint32Array(ME.inflate(e.eachEntityPrimitiveInstancesPortion).buffer),eachEntityMatricesPortion:new Uint32Array(ME.inflate(e.eachEntityMatricesPortion).buffer)}}(o);!function(e,t,i,s,r,n){var o=n.getNextId();s.positionsCompression="disabled",s.normalsCompression="precompressed";for(var a=i.positions,l=i.normals,u=i.indices,A=i.edgeIndices,c=i.matrices,h=i.eachPrimitivePositionsAndNormalsPortion,d=i.eachPrimitiveIndicesPortion,p=i.eachPrimitiveEdgeIndicesPortion,f=i.eachPrimitiveColor,v=i.primitiveInstances,g=JSON.parse(i.eachEntityId),m=i.eachEntityPrimitiveInstancesPortion,_=i.eachEntityMatricesPortion,y=h.length,b=v.length,w=new Uint8Array(y),B=g.length,x=0;x1||(P[D]=C)}for(var S=0;S1,L=FE(f.subarray(4*S,4*S+3)),U=f[4*S+3]/255,O=a.subarray(h[S],T?a.length:h[S+1]),N=l.subarray(h[S],T?l.length:h[S+1]),Q=u.subarray(d[S],T?u.length:d[S+1]),V=A.subarray(p[S],T?A.length:p[S+1]);if(R){var H="".concat(o,"-geometry.").concat(S);s.createGeometry({id:H,primitive:"triangles",positionsCompressed:O,normalsCompressed:N,indices:Q,edgeIndices:V})}else{var j=S;g[P[S]],s.createMesh(le.apply({},{id:j,primitive:"triangles",positionsCompressed:O,normalsCompressed:N,indices:Q,edgeIndices:V,color:L,opacity:U}))}}for(var G=0,z=0;z1){var ee="instance."+G++,te="geometry"+$,ie=16*_[z],se=c.subarray(ie,ie+16);s.createMesh(le.apply({},{id:ee,geometryId:te,matrix:se})),Z.push(ee)}else Z.push($)}Z.length>0&&s.createEntity(le.apply({},{id:X,isObject:!0,meshIds:Z}))}}(0,0,a,s,0,n)}},kE=window.pako||dE;kE.inflate||(kE=kE.default);var IE,DE=(IE=new Float32Array(3),function(e){return IE[0]=e[0]/255,IE[1]=e[1]/255,IE[2]=e[2]/255,IE});var SE={version:6,parse:function(e,t,i,s,r,n){var o=function(e){return{positions:e[0],normals:e[1],indices:e[2],edgeIndices:e[3],matrices:e[4],reusedPrimitivesDecodeMatrix:e[5],eachPrimitivePositionsAndNormalsPortion:e[6],eachPrimitiveIndicesPortion:e[7],eachPrimitiveEdgeIndicesPortion:e[8],eachPrimitiveColorAndOpacity:e[9],primitiveInstances:e[10],eachEntityId:e[11],eachEntityPrimitiveInstancesPortion:e[12],eachEntityMatricesPortion:e[13],eachTileAABB:e[14],eachTileEntitiesPortion:e[15]}}(i),a=function(e){function t(e,t){return 0===e.length?[]:kE.inflate(e,t).buffer}return{positions:new Uint16Array(t(e.positions)),normals:new Int8Array(t(e.normals)),indices:new Uint32Array(t(e.indices)),edgeIndices:new Uint32Array(t(e.edgeIndices)),matrices:new Float32Array(t(e.matrices)),reusedPrimitivesDecodeMatrix:new Float32Array(t(e.reusedPrimitivesDecodeMatrix)),eachPrimitivePositionsAndNormalsPortion:new Uint32Array(t(e.eachPrimitivePositionsAndNormalsPortion)),eachPrimitiveIndicesPortion:new Uint32Array(t(e.eachPrimitiveIndicesPortion)),eachPrimitiveEdgeIndicesPortion:new Uint32Array(t(e.eachPrimitiveEdgeIndicesPortion)),eachPrimitiveColorAndOpacity:new Uint8Array(t(e.eachPrimitiveColorAndOpacity)),primitiveInstances:new Uint32Array(t(e.primitiveInstances)),eachEntityId:kE.inflate(e.eachEntityId,{to:"string"}),eachEntityPrimitiveInstancesPortion:new Uint32Array(t(e.eachEntityPrimitiveInstancesPortion)),eachEntityMatricesPortion:new Uint32Array(t(e.eachEntityMatricesPortion)),eachTileAABB:new Float64Array(t(e.eachTileAABB)),eachTileEntitiesPortion:new Uint32Array(t(e.eachTileEntitiesPortion))}}(o);!function(e,t,i,s,r,n){for(var o=n.getNextId(),a=i.positions,l=i.normals,u=i.indices,A=i.edgeIndices,c=i.matrices,h=i.reusedPrimitivesDecodeMatrix,d=i.eachPrimitivePositionsAndNormalsPortion,p=i.eachPrimitiveIndicesPortion,f=i.eachPrimitiveEdgeIndicesPortion,v=i.eachPrimitiveColorAndOpacity,g=i.primitiveInstances,m=JSON.parse(i.eachEntityId),_=i.eachEntityPrimitiveInstancesPortion,y=i.eachEntityMatricesPortion,b=i.eachTileAABB,w=i.eachTileEntitiesPortion,B=d.length,x=g.length,P=m.length,C=w.length,M=new Uint32Array(B),F=0;F1,se=te===B-1,re=a.subarray(d[te],se?a.length:d[te+1]),ne=l.subarray(d[te],se?l.length:d[te+1]),oe=u.subarray(p[te],se?u.length:p[te+1]),ae=A.subarray(f[te],se?A.length:f[te+1]),ue=DE(v.subarray(4*te,4*te+3)),Ae=v[4*te+3]/255,ce=n.getNextId();if(ie){var he="".concat(o,"-geometry.").concat(D,".").concat(te);N[he]||(s.createGeometry({id:he,primitive:"triangles",positionsCompressed:re,indices:oe,edgeIndices:ae,positionsDecodeMatrix:h}),N[he]=!0),s.createMesh(le.apply(Z,{id:ce,geometryId:he,origin:k,matrix:G,color:ue,opacity:Ae})),X.push(ce)}else s.createMesh(le.apply(Z,{id:ce,origin:k,primitive:"triangles",positionsCompressed:re,normalsCompressed:ne,indices:oe,edgeIndices:ae,positionsDecodeMatrix:O,color:ue,opacity:Ae})),X.push(ce)}X.length>0&&s.createEntity(le.apply(Y,{id:H,isObject:!0,meshIds:X}))}}}(e,t,a,s,0,n)}},TE=window.pako||dE;TE.inflate||(TE=TE.default);var RE=function(){var e=new Float32Array(3);return function(t){return e[0]=t[0]/255,e[1]=t[1]/255,e[2]=t[2]/255,e}}();function LE(e){for(var t=[],i=0,s=e.length;i1,ne=se===M-1,oe=RE(w.subarray(6*ie,6*ie+3)),ae=w[6*ie+3]/255,ue=w[6*ie+4]/255,Ae=w[6*ie+5]/255,ce=n.getNextId();if(re){var he=b[ie],de=h.slice(he,he+16),pe="".concat(o,"-geometry.").concat(L,".").concat(se);if(!j[pe]){var fe=void 0,ve=void 0,ge=void 0,me=void 0,_e=void 0,ye=void 0;switch(p[se]){case 0:fe="solid",ve=a.subarray(f[se],ne?a.length:f[se+1]),ge=l.subarray(v[se],ne?l.length:v[se+1]),_e=A.subarray(m[se],ne?A.length:m[se+1]),ye=c.subarray(_[se],ne?c.length:_[se+1]);break;case 1:fe="surface",ve=a.subarray(f[se],ne?a.length:f[se+1]),ge=l.subarray(v[se],ne?l.length:v[se+1]),_e=A.subarray(m[se],ne?A.length:m[se+1]),ye=c.subarray(_[se],ne?c.length:_[se+1]);break;case 2:fe="points",ve=a.subarray(f[se],ne?a.length:f[se+1]),me=LE(u.subarray(g[se],ne?u.length:g[se+1]));break;case 3:fe="lines",ve=a.subarray(f[se],ne?a.length:f[se+1]),_e=A.subarray(m[se],ne?A.length:m[se+1]);break;default:continue}s.createGeometry({id:pe,primitive:fe,positionsCompressed:ve,normalsCompressed:ge,colors:me,indices:_e,edgeIndices:ye,positionsDecodeMatrix:d}),j[pe]=!0}s.createMesh(le.apply(ee,{id:ce,geometryId:pe,origin:T,matrix:de,color:oe,metallic:ue,roughness:Ae,opacity:ae})),Y.push(ce)}else{var be=void 0,we=void 0,Be=void 0,xe=void 0,Pe=void 0,Ce=void 0;switch(p[se]){case 0:be="solid",we=a.subarray(f[se],ne?a.length:f[se+1]),Be=l.subarray(v[se],ne?l.length:v[se+1]),Pe=A.subarray(m[se],ne?A.length:m[se+1]),Ce=c.subarray(_[se],ne?c.length:_[se+1]);break;case 1:be="surface",we=a.subarray(f[se],ne?a.length:f[se+1]),Be=l.subarray(v[se],ne?l.length:v[se+1]),Pe=A.subarray(m[se],ne?A.length:m[se+1]),Ce=c.subarray(_[se],ne?c.length:_[se+1]);break;case 2:be="points",we=a.subarray(f[se],ne?a.length:f[se+1]),xe=LE(u.subarray(g[se],ne?u.length:g[se+1]));break;case 3:be="lines",we=a.subarray(f[se],ne?a.length:f[se+1]),Pe=A.subarray(m[se],ne?A.length:m[se+1]);break;default:continue}s.createMesh(le.apply(ee,{id:ce,origin:T,primitive:be,positionsCompressed:we,normalsCompressed:Be,colors:xe,indices:Pe,edgeIndices:Ce,positionsDecodeMatrix:H,color:oe,metallic:ue,roughness:Ae,opacity:ae})),Y.push(ce)}}Y.length>0&&s.createEntity(le.apply(q,{id:W,isObject:!0,meshIds:Y}))}}}(e,t,a,s,0,n)}},OE=window.pako||dE;OE.inflate||(OE=OE.default);var NE=$.vec4(),QE=$.vec4();var VE=function(){var e=new Float32Array(3);return function(t){return e[0]=t[0]/255,e[1]=t[1]/255,e[2]=t[2]/255,e}}();function HE(e){for(var t=[],i=0,s=e.length;i1,ye=me===S-1,be=VE(M.subarray(6*ge,6*ge+3)),we=M[6*ge+3]/255,Be=M[6*ge+4]/255,xe=M[6*ge+5]/255,Pe=n.getNextId();if(_e){var Ce=C[ge],Me=g.slice(Ce,Ce+16),Fe="".concat(o,"-geometry.").concat(Y,".").concat(me),Ee=J[Fe];if(!Ee){Ee={batchThisMesh:!t.reuseGeometries};var ke=!1;switch(_[me]){case 0:Ee.primitiveName="solid",Ee.geometryPositions=h.subarray(y[me],ye?h.length:y[me+1]),Ee.geometryNormals=d.subarray(b[me],ye?d.length:b[me+1]),Ee.geometryIndices=f.subarray(B[me],ye?f.length:B[me+1]),Ee.geometryEdgeIndices=v.subarray(x[me],ye?v.length:x[me+1]),ke=Ee.geometryPositions.length>0&&Ee.geometryIndices.length>0;break;case 1:Ee.primitiveName="surface",Ee.geometryPositions=h.subarray(y[me],ye?h.length:y[me+1]),Ee.geometryNormals=d.subarray(b[me],ye?d.length:b[me+1]),Ee.geometryIndices=f.subarray(B[me],ye?f.length:B[me+1]),Ee.geometryEdgeIndices=v.subarray(x[me],ye?v.length:x[me+1]),ke=Ee.geometryPositions.length>0&&Ee.geometryIndices.length>0;break;case 2:Ee.primitiveName="points",Ee.geometryPositions=h.subarray(y[me],ye?h.length:y[me+1]),Ee.geometryColors=HE(p.subarray(w[me],ye?p.length:w[me+1])),ke=Ee.geometryPositions.length>0;break;case 3:Ee.primitiveName="lines",Ee.geometryPositions=h.subarray(y[me],ye?h.length:y[me+1]),Ee.geometryIndices=f.subarray(B[me],ye?f.length:B[me+1]),ke=Ee.geometryPositions.length>0&&Ee.geometryIndices.length>0;break;default:continue}if(ke||(Ee=null),Ee&&(Ee.geometryPositions.length,Ee.batchThisMesh)){Ee.decompressedPositions=new Float32Array(Ee.geometryPositions.length);for(var Ie=Ee.geometryPositions,De=Ee.decompressedPositions,Se=0,Te=Ie.length;Se0&&je.length>0;break;case 1:Ne="surface",Qe=h.subarray(y[me],ye?h.length:y[me+1]),Ve=d.subarray(b[me],ye?d.length:b[me+1]),je=f.subarray(B[me],ye?f.length:B[me+1]),Ge=v.subarray(x[me],ye?v.length:x[me+1]),ze=Qe.length>0&&je.length>0;break;case 2:Ne="points",Qe=h.subarray(y[me],ye?h.length:y[me+1]),He=HE(p.subarray(w[me],ye?p.length:w[me+1])),ze=Qe.length>0;break;case 3:Ne="lines",Qe=h.subarray(y[me],ye?h.length:y[me+1]),je=f.subarray(B[me],ye?f.length:B[me+1]),ze=Qe.length>0&&je.length>0;break;default:continue}ze&&(s.createMesh(le.apply(fe,{id:Pe,origin:K,primitive:Ne,positionsCompressed:Qe,normalsCompressed:Ve,colorsCompressed:He,indices:je,edgeIndices:Ge,positionsDecodeMatrix:se,color:be,metallic:Be,roughness:xe,opacity:we})),he.push(Pe))}}he.length>0&&s.createEntity(le.apply(pe,{id:ae,isObject:!0,meshIds:he}))}}}(e,t,a,s,r,n)}},GE=window.pako||dE;GE.inflate||(GE=GE.default);var zE=$.vec4(),WE=$.vec4();var KE=function(){var e=new Float32Array(3);return function(t){return e[0]=t[0]/255,e[1]=t[1]/255,e[2]=t[2]/255,e}}();var XE={version:9,parse:function(e,t,i,s,r,n){var o=function(e){return{metadata:e[0],positions:e[1],normals:e[2],colors:e[3],indices:e[4],edgeIndices:e[5],matrices:e[6],reusedGeometriesDecodeMatrix:e[7],eachGeometryPrimitiveType:e[8],eachGeometryPositionsPortion:e[9],eachGeometryNormalsPortion:e[10],eachGeometryColorsPortion:e[11],eachGeometryIndicesPortion:e[12],eachGeometryEdgeIndicesPortion:e[13],eachMeshGeometriesPortion:e[14],eachMeshMatricesPortion:e[15],eachMeshMaterial:e[16],eachEntityId:e[17],eachEntityMeshesPortion:e[18],eachTileAABB:e[19],eachTileEntitiesPortion:e[20]}}(i),a=function(e){function t(e,t){return 0===e.length?[]:GE.inflate(e,t).buffer}return{metadata:JSON.parse(GE.inflate(e.metadata,{to:"string"})),positions:new Uint16Array(t(e.positions)),normals:new Int8Array(t(e.normals)),colors:new Uint8Array(t(e.colors)),indices:new Uint32Array(t(e.indices)),edgeIndices:new Uint32Array(t(e.edgeIndices)),matrices:new Float32Array(t(e.matrices)),reusedGeometriesDecodeMatrix:new Float32Array(t(e.reusedGeometriesDecodeMatrix)),eachGeometryPrimitiveType:new Uint8Array(t(e.eachGeometryPrimitiveType)),eachGeometryPositionsPortion:new Uint32Array(t(e.eachGeometryPositionsPortion)),eachGeometryNormalsPortion:new Uint32Array(t(e.eachGeometryNormalsPortion)),eachGeometryColorsPortion:new Uint32Array(t(e.eachGeometryColorsPortion)),eachGeometryIndicesPortion:new Uint32Array(t(e.eachGeometryIndicesPortion)),eachGeometryEdgeIndicesPortion:new Uint32Array(t(e.eachGeometryEdgeIndicesPortion)),eachMeshGeometriesPortion:new Uint32Array(t(e.eachMeshGeometriesPortion)),eachMeshMatricesPortion:new Uint32Array(t(e.eachMeshMatricesPortion)),eachMeshMaterial:new Uint8Array(t(e.eachMeshMaterial)),eachEntityId:JSON.parse(GE.inflate(e.eachEntityId,{to:"string"})),eachEntityMeshesPortion:new Uint32Array(t(e.eachEntityMeshesPortion)),eachTileAABB:new Float64Array(t(e.eachTileAABB)),eachTileEntitiesPortion:new Uint32Array(t(e.eachTileEntitiesPortion))}}(o);!function(e,t,i,s,r,n){var o=n.getNextId(),a=i.metadata,l=i.positions,u=i.normals,A=i.colors,c=i.indices,h=i.edgeIndices,d=i.matrices,p=i.reusedGeometriesDecodeMatrix,f=i.eachGeometryPrimitiveType,v=i.eachGeometryPositionsPortion,g=i.eachGeometryNormalsPortion,m=i.eachGeometryColorsPortion,_=i.eachGeometryIndicesPortion,y=i.eachGeometryEdgeIndicesPortion,b=i.eachMeshGeometriesPortion,w=i.eachMeshMatricesPortion,B=i.eachMeshMaterial,x=i.eachEntityId,P=i.eachEntityMeshesPortion,C=i.eachTileAABB,M=i.eachTileEntitiesPortion,F=v.length,E=b.length,k=P.length,I=M.length;r&&r.loadData(a,{includeTypes:t.includeTypes,excludeTypes:t.excludeTypes,globalizeObjectIds:t.globalizeObjectIds});for(var D=new Uint32Array(F),S=0;S1,ae=ne===F-1,ue=KE(B.subarray(6*re,6*re+3)),Ae=B[6*re+3]/255,ce=B[6*re+4]/255,he=B[6*re+5]/255,de=n.getNextId();if(oe){var pe=w[re],fe=d.slice(pe,pe+16),ve="".concat(o,"-geometry.").concat(O,".").concat(ne),ge=U[ve];if(!ge){ge={batchThisMesh:!t.reuseGeometries};var me=!1;switch(f[ne]){case 0:ge.primitiveName="solid",ge.geometryPositions=l.subarray(v[ne],ae?l.length:v[ne+1]),ge.geometryNormals=u.subarray(g[ne],ae?u.length:g[ne+1]),ge.geometryIndices=c.subarray(_[ne],ae?c.length:_[ne+1]),ge.geometryEdgeIndices=h.subarray(y[ne],ae?h.length:y[ne+1]),me=ge.geometryPositions.length>0&&ge.geometryIndices.length>0;break;case 1:ge.primitiveName="surface",ge.geometryPositions=l.subarray(v[ne],ae?l.length:v[ne+1]),ge.geometryNormals=u.subarray(g[ne],ae?u.length:g[ne+1]),ge.geometryIndices=c.subarray(_[ne],ae?c.length:_[ne+1]),ge.geometryEdgeIndices=h.subarray(y[ne],ae?h.length:y[ne+1]),me=ge.geometryPositions.length>0&&ge.geometryIndices.length>0;break;case 2:ge.primitiveName="points",ge.geometryPositions=l.subarray(v[ne],ae?l.length:v[ne+1]),ge.geometryColors=A.subarray(m[ne],ae?A.length:m[ne+1]),me=ge.geometryPositions.length>0;break;case 3:ge.primitiveName="lines",ge.geometryPositions=l.subarray(v[ne],ae?l.length:v[ne+1]),ge.geometryIndices=c.subarray(_[ne],ae?c.length:_[ne+1]),me=ge.geometryPositions.length>0&&ge.geometryIndices.length>0;break;default:continue}if(me||(ge=null),ge&&(ge.geometryPositions.length,ge.batchThisMesh)){ge.decompressedPositions=new Float32Array(ge.geometryPositions.length),ge.transformedAndRecompressedPositions=new Uint16Array(ge.geometryPositions.length);for(var _e=ge.geometryPositions,ye=ge.decompressedPositions,be=0,we=_e.length;be0&&Ie.length>0;break;case 1:Me="surface",Fe=l.subarray(v[ne],ae?l.length:v[ne+1]),Ee=u.subarray(g[ne],ae?u.length:g[ne+1]),Ie=c.subarray(_[ne],ae?c.length:_[ne+1]),De=h.subarray(y[ne],ae?h.length:y[ne+1]),Se=Fe.length>0&&Ie.length>0;break;case 2:Me="points",Fe=l.subarray(v[ne],ae?l.length:v[ne+1]),ke=A.subarray(m[ne],ae?A.length:m[ne+1]),Se=Fe.length>0;break;case 3:Me="lines",Fe=l.subarray(v[ne],ae?l.length:v[ne+1]),Ie=c.subarray(_[ne],ae?c.length:_[ne+1]),Se=Fe.length>0&&Ie.length>0;break;default:continue}Se&&(s.createMesh(le.apply(ie,{id:de,origin:R,primitive:Me,positionsCompressed:Fe,normalsCompressed:Ee,colorsCompressed:ke,indices:Ie,edgeIndices:De,positionsDecodeMatrix:G,color:ue,metallic:ce,roughness:he,opacity:Ae})),q.push(de))}}q.length>0&&s.createEntity(le.apply(te,{id:X,isObject:!0,meshIds:q}))}}}(e,t,a,s,r,n)}},JE=window.pako||dE;JE.inflate||(JE=JE.default);var YE=$.vec4(),ZE=$.vec4();var qE=function(){var e=new Float32Array(3);return function(t){return e[0]=t[0]/255,e[1]=t[1]/255,e[2]=t[2]/255,e}}();function $E(e,t){var i=[];if(t.length>1)for(var s=0,r=t.length-1;s1)for(var n=0,o=e.length/3-1;n0,W=9*V,K=1===A[W+0],X=A[W+1];A[W+2],A[W+3];var J=A[W+4],Y=A[W+5],Z=A[W+6],q=A[W+7],ee=A[W+8];if(z){var te=new Uint8Array(l.subarray(j,G)).buffer,ie="".concat(o,"-texture-").concat(V);if(K)s.createTexture({id:ie,buffers:[te],minFilter:J,magFilter:Y,wrapS:Z,wrapT:q,wrapR:ee});else{var se=new Blob([te],{type:10001===X?"image/jpeg":10002===X?"image/png":"image/gif"}),re=(window.URL||window.webkitURL).createObjectURL(se),ne=document.createElement("img");ne.src=re,s.createTexture({id:ie,image:ne,minFilter:J,magFilter:Y,wrapS:Z,wrapT:q,wrapR:ee})}}}for(var oe=0;oe=0?"".concat(o,"-texture-").concat(Ae):null,normalsTextureId:he>=0?"".concat(o,"-texture-").concat(he):null,metallicRoughnessTextureId:ce>=0?"".concat(o,"-texture-").concat(ce):null,emissiveTextureId:de>=0?"".concat(o,"-texture-").concat(de):null,occlusionTextureId:pe>=0?"".concat(o,"-texture-").concat(pe):null})}for(var fe=new Uint32Array(U),ve=0;ve1,je=Ve===U-1,Ge=E[Qe],ze=Ge>=0?"".concat(o,"-textureSet-").concat(Ge):null,We=qE(k.subarray(6*Qe,6*Qe+3)),Ke=k[6*Qe+3]/255,Xe=k[6*Qe+4]/255,Je=k[6*Qe+5]/255,Ye=n.getNextId();if(He){var Ze=F[Qe],qe=m.slice(Ze,Ze+16),$e="".concat(o,"-geometry.").concat(be,".").concat(Ve),et=ye[$e];if(!et){et={batchThisMesh:!t.reuseGeometries};var tt=!1;switch(y[Ve]){case 0:et.primitiveName="solid",et.geometryPositions=c.subarray(b[Ve],je?c.length:b[Ve+1]),et.geometryNormals=h.subarray(w[Ve],je?h.length:w[Ve+1]),et.geometryUVs=p.subarray(x[Ve],je?p.length:x[Ve+1]),et.geometryIndices=f.subarray(P[Ve],je?f.length:P[Ve+1]),et.geometryEdgeIndices=v.subarray(C[Ve],je?v.length:C[Ve+1]),tt=et.geometryPositions.length>0&&et.geometryIndices.length>0;break;case 1:et.primitiveName="surface",et.geometryPositions=c.subarray(b[Ve],je?c.length:b[Ve+1]),et.geometryNormals=h.subarray(w[Ve],je?h.length:w[Ve+1]),et.geometryUVs=p.subarray(x[Ve],je?p.length:x[Ve+1]),et.geometryIndices=f.subarray(P[Ve],je?f.length:P[Ve+1]),et.geometryEdgeIndices=v.subarray(C[Ve],je?v.length:C[Ve+1]),tt=et.geometryPositions.length>0&&et.geometryIndices.length>0;break;case 2:et.primitiveName="points",et.geometryPositions=c.subarray(b[Ve],je?c.length:b[Ve+1]),et.geometryColors=d.subarray(B[Ve],je?d.length:B[Ve+1]),tt=et.geometryPositions.length>0;break;case 3:et.primitiveName="lines",et.geometryPositions=c.subarray(b[Ve],je?c.length:b[Ve+1]),et.geometryIndices=f.subarray(P[Ve],je?f.length:P[Ve+1]),tt=et.geometryPositions.length>0&&et.geometryIndices.length>0;break;case 4:et.primitiveName="lines",et.geometryPositions=c.subarray(b[Ve],je?c.length:b[Ve+1]),et.geometryIndices=$E(et.geometryPositions,f.subarray(P[Ve],je?f.length:P[Ve+1])),tt=et.geometryPositions.length>0&&et.geometryIndices.length>0;break;default:continue}if(tt||(et=null),et&&(et.geometryPositions.length,et.batchThisMesh)){et.decompressedPositions=new Float32Array(et.geometryPositions.length),et.transformedAndRecompressedPositions=new Uint16Array(et.geometryPositions.length);for(var it=et.geometryPositions,st=et.decompressedPositions,rt=0,nt=it.length;rt0&&ft.length>0;break;case 1:At="surface",ct=c.subarray(b[Ve],je?c.length:b[Ve+1]),ht=h.subarray(w[Ve],je?h.length:w[Ve+1]),dt=p.subarray(x[Ve],je?p.length:x[Ve+1]),ft=f.subarray(P[Ve],je?f.length:P[Ve+1]),vt=v.subarray(C[Ve],je?v.length:C[Ve+1]),gt=ct.length>0&&ft.length>0;break;case 2:At="points",ct=c.subarray(b[Ve],je?c.length:b[Ve+1]),pt=d.subarray(B[Ve],je?d.length:B[Ve+1]),gt=ct.length>0;break;case 3:At="lines",ct=c.subarray(b[Ve],je?c.length:b[Ve+1]),ft=f.subarray(P[Ve],je?f.length:P[Ve+1]),gt=ct.length>0&&ft.length>0;break;case 4:At="lines",ft=$E(ct=c.subarray(b[Ve],je?c.length:b[Ve+1]),f.subarray(P[Ve],je?f.length:P[Ve+1])),gt=ct.length>0&&ft.length>0;break;default:continue}gt&&(s.createMesh(le.apply(Oe,{id:Ye,textureSetId:ze,origin:me,primitive:At,positionsCompressed:ct,normalsCompressed:ht,uv:dt&&dt.length>0?dt:null,colorsCompressed:pt,indices:ft,edgeIndices:vt,positionsDecodeMatrix:Me,color:We,metallic:Xe,roughness:Je,opacity:Ke})),Re.push(Ye))}}Re.length>0&&s.createEntity(le.apply(Ue,{id:Ie,isObject:!0,meshIds:Re}))}}}(e,t,a,s,r,n)}},tk={};tk[gE.version]=gE,tk[yE.version]=yE,tk[BE.version]=BE,tk[CE.version]=CE,tk[EE.version]=EE,tk[SE.version]=SE,tk[UE.version]=UE,tk[jE.version]=jE,tk[XE.version]=XE,tk[ek.version]=ek;var ik=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"XKTLoader",e,r))._maxGeometryBatchSize=r.maxGeometryBatchSize,s.textureTranscoder=r.textureTranscoder,s.dataSource=r.dataSource,s.objectDefaults=r.objectDefaults,s.includeTypes=r.includeTypes,s.excludeTypes=r.excludeTypes,s.excludeUnclassifiedObjects=r.excludeUnclassifiedObjects,s.reuseGeometries=r.reuseGeometries,s}return C(i,[{key:"supportedVersions",get:function(){return Object.keys(tk)}},{key:"textureTranscoder",get:function(){return this._textureTranscoder},set:function(e){this._textureTranscoder=e}},{key:"dataSource",get:function(){return this._dataSource},set:function(e){this._dataSource=e||new hE}},{key:"objectDefaults",get:function(){return this._objectDefaults},set:function(e){this._objectDefaults=e||uF}},{key:"includeTypes",get:function(){return this._includeTypes},set:function(e){this._includeTypes=e}},{key:"excludeTypes",get:function(){return this._excludeTypes},set:function(e){this._excludeTypes=e}},{key:"excludeUnclassifiedObjects",get:function(){return this._excludeUnclassifiedObjects},set:function(e){this._excludeUnclassifiedObjects=!!e}},{key:"globalizeObjectIds",get:function(){return this._globalizeObjectIds},set:function(e){this._globalizeObjectIds=!!e}},{key:"reuseGeometries",get:function(){return this._reuseGeometries},set:function(e){this._reuseGeometries=!1!==e}},{key:"load",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t.id&&this.viewer.scene.components[t.id]&&(this.error("Component with this ID already exists in viewer: "+t.id+" - will autogenerate this ID"),delete t.id),!(t.src||t.xkt||t.manifestSrc||t.manifest))return this.error("load() param expected: src, xkt, manifestSrc or manifestData"),A;var i={},s=t.includeTypes||this._includeTypes,r=t.excludeTypes||this._excludeTypes,n=t.objectDefaults||this._objectDefaults;if(i.reuseGeometries=null!==t.reuseGeometries&&void 0!==t.reuseGeometries?t.reuseGeometries:!1!==this._reuseGeometries,s){i.includeTypesMap={};for(var o=0,a=s.length;o=t.length?n():e._dataSource.getMetaModel("".concat(m).concat(t[a]),(function(t){h.loadData(t,{includeTypes:s,excludeTypes:r,globalizeObjectIds:i.globalizeObjectIds}),a++,e.scheduleTask(l,100)}),o)}()},y=function(s,r,n){var o=0;!function a(){o>=s.length?r():e._dataSource.getXKT("".concat(m).concat(s[o]),(function(s){e._parseModel(s,t,i,A,null,v),o++,e.scheduleTask(a,100)}),n)}()},b=function(s,r,n){var o=0;!function a(){o>=s.length?r():e._dataSource.getXKT("".concat(m).concat(s[o]),(function(s){e._parseModel(s,t,i,A,h,v),o++,e.scheduleTask(a,100)}),n)}()};if(t.manifest){var w=t.manifest,B=w.xktFiles;if(!B||0===B.length)return void p("load(): Failed to load model manifest - manifest not valid");var x=w.metaModelFiles;x?_(x,(function(){y(B,d,p)}),p):b(B,d,p)}else this._dataSource.getManifest(t.manifestSrc,(function(e){if(!A.destroyed){var t=e.xktFiles;if(t&&0!==t.length){var i=e.metaModelFiles;i?_(i,(function(){y(t,d,p)}),p):b(t,d,p)}else p("load(): Failed to load model manifest - manifest not valid")}}),p)}return A}},{key:"_loadModel",value:function(e,t,i,s,r,n,o,a){var l=this;this._dataSource.getXKT(t.src,(function(e){l._parseModel(e,t,i,s,r,n),o()}),a)}},{key:"_parseModel",value:function(e,t,i,s,r,n){if(!s.destroyed){var o=new DataView(e),a=new Uint8Array(e),l=o.getUint32(0,!0),u=tk[l];if(u){this.log("Loading .xkt V"+l);for(var A=o.getUint32(4,!0),c=[],h=4*(A+2),d=0;de.size)throw new RangeError("offset:"+t+", length:"+i+", size:"+e.size);return e.slice?e.slice(t,t+i):e.webkitSlice?e.webkitSlice(t,t+i):e.mozSlice?e.mozSlice(t,t+i):e.msSlice?e.msSlice(t,t+i):void 0}(e,t,i))}catch(e){r(e)}}}function p(){}function f(e){var i,s=this;s.init=function(e){i=new Blob([],{type:o}),e()},s.writeUint8Array=function(e,s){i=new Blob([i,t?e:e.buffer],{type:o}),s()},s.getData=function(t,s){var r=new FileReader;r.onload=function(e){t(e.target.result)},r.onerror=s,r.readAsText(i,e)}}function v(t){var i=this,s="",r="";i.init=function(e){s+="data:"+(t||"")+";base64,",e()},i.writeUint8Array=function(t,i){var n,o=r.length,a=r;for(r="",n=0;n<3*Math.floor((o+t.length)/3)-o;n++)a+=String.fromCharCode(t[n]);for(;n2?s+=e.btoa(a):r=a,i()},i.getData=function(t){t(s+e.btoa(r))}}function g(e){var i,s=this;s.init=function(t){i=new Blob([],{type:e}),t()},s.writeUint8Array=function(s,r){i=new Blob([i,t?s:s.buffer],{type:e}),r()},s.getData=function(e){e(i)}}function m(e,t,i,s,r,o,a,l,u,A){var c,h,d,p=0,f=t.sn;function v(){e.removeEventListener("message",g,!1),l(h,d)}function g(t){var i=t.data,r=i.data,n=i.error;if(n)return n.toString=function(){return"Error: "+this.message},void u(n);if(i.sn===f)switch("number"==typeof i.codecTime&&(e.codecTime+=i.codecTime),"number"==typeof i.crcTime&&(e.crcTime+=i.crcTime),i.type){case"append":r?(h+=r.length,s.writeUint8Array(r,(function(){m()}),A)):m();break;case"flush":d=i.crc,r?(h+=r.length,s.writeUint8Array(r,(function(){v()}),A)):v();break;case"progress":a&&a(c+i.loaded,o);break;case"importScripts":case"newTask":case"echo":break;default:console.warn("zip.js:launchWorkerProcess: unknown message: ",i)}}function m(){(c=p*n)<=o?i.readUint8Array(r+c,Math.min(n,o-c),(function(i){a&&a(c,o);var s=0===c?t:{sn:f};s.type="append",s.data=i;try{e.postMessage(s,[i.buffer])}catch(t){e.postMessage(s)}p++}),u):e.postMessage({sn:f,type:"flush"})}h=0,e.addEventListener("message",g,!1),m()}function _(e,t,i,s,r,o,l,u,A,c){var h,d=0,p=0,f="input"===o,v="output"===o,g=new a;!function o(){var a;if((h=d*n)127?r[i-128]:String.fromCharCode(i);return s}function w(e){return decodeURIComponent(escape(e))}function B(e){var t,i="";for(t=0;t>16,i=65535&e;try{return new Date(1980+((65024&t)>>9),((480&t)>>5)-1,31&t,(63488&i)>>11,(2016&i)>>5,2*(31&i),0)}catch(e){}}(e.lastModDateRaw),1!=(1&e.bitFlag)?((s||8!=(8&e.bitFlag))&&(e.crc32=t.view.getUint32(i+10,!0),e.compressedSize=t.view.getUint32(i+14,!0),e.uncompressedSize=t.view.getUint32(i+18,!0)),4294967295!==e.compressedSize&&4294967295!==e.uncompressedSize?(e.filenameLength=t.view.getUint16(i+22,!0),e.extraFieldLength=t.view.getUint16(i+24,!0)):r("File is using Zip64 (4gb+ file size).")):r("File contains encrypted entry.")}function P(t,n,o){var a=0;function l(){}l.prototype.getData=function(s,n,l,A){var c=this;function h(e,t){A&&!function(e){var t=u(4);return t.view.setUint32(0,e),c.crc32==t.view.getUint32(0)}(t)?o("CRC failed."):s.getData((function(e){n(e)}))}function d(e){o(e||r)}function p(e){o(e||"Error while writing file data.")}t.readUint8Array(c.offset,30,(function(r){var n,f=u(r.length,r);1347093252==f.view.getUint32(0)?(x(c,f,4,!1,o),n=c.offset+30+c.filenameLength+c.extraFieldLength,s.init((function(){0===c.compressionMethod?y(c._worker,a++,t,s,n,c.compressedSize,A,h,l,d,p):function(t,i,s,r,n,o,a,l,u,A,c){var h=a?"output":"none";e.zip.useWebWorkers?m(t,{sn:i,codecClass:"Inflater",crcType:h},s,r,n,o,u,l,A,c):_(new e.zip.Inflater,s,r,n,o,h,u,l,A,c)}(c._worker,a++,t,s,n,c.compressedSize,A,h,l,d,p)}),p)):o(i)}),d)};var A={getEntries:function(e){var r=this._worker;!function(e){t.size<22?o(i):r(22,(function(){r(Math.min(65558,t.size),(function(){o(i)}))}));function r(i,r){t.readUint8Array(t.size-i,i,(function(t){for(var i=t.length-22;i>=0;i--)if(80===t[i]&&75===t[i+1]&&5===t[i+2]&&6===t[i+3])return void e(new DataView(t.buffer,i,22));r()}),(function(){o(s)}))}}((function(n){var a,A;a=n.getUint32(16,!0),A=n.getUint16(8,!0),a<0||a>=t.size?o(i):t.readUint8Array(a,t.size-a,(function(t){var s,n,a,c,h=0,d=[],p=u(t.length,t);for(s=0;s>>8^i[255&(t^e[s])];this.crc=t},a.prototype.get=function(){return~this.crc},a.prototype.table=function(){var e,t,i,s=[];for(e=0;e<256;e++){for(i=e,t=0;t<8;t++)1&i?i=i>>>1^3988292384:i>>>=1;s[e]=i}return s}(),l.prototype.append=function(e,t){return e},l.prototype.flush=function(){},c.prototype=new A,c.prototype.constructor=c,h.prototype=new A,h.prototype.constructor=h,d.prototype=new A,d.prototype.constructor=d,p.prototype.getData=function(e){e(this.data)},f.prototype=new p,f.prototype.constructor=f,v.prototype=new p,v.prototype.constructor=v,g.prototype=new p,g.prototype.constructor=g;var E={deflater:["z-worker.js","deflate.js"],inflater:["z-worker.js","inflate.js"]};function k(t,i,s){if(null===e.zip.workerScripts||null===e.zip.workerScriptsPath){var r;if(e.zip.workerScripts){if(r=e.zip.workerScripts[t],!Array.isArray(r))return void s(new Error("zip.workerScripts."+t+" is not an array!"));r=function(e){var t=document.createElement("a");return e.map((function(e){return t.href=e,t.href}))}(r)}else(r=E[t].slice(0))[0]=(e.zip.workerScriptsPath||"")+r[0];var n=new Worker(r[0]);n.codecTime=n.crcTime=0,n.postMessage({type:"importScripts",scripts:r.slice(1)}),n.addEventListener("message",(function e(t){var r=t.data;if(r.error)return n.terminate(),void s(r.error);"importScripts"===r.type&&(n.removeEventListener("message",e),n.removeEventListener("error",o),i(n))})),n.addEventListener("error",o)}else s(new Error("Either zip.workerScripts or zip.workerScriptsPath may be set, not both."));function o(e){n.terminate(),s(e)}}function I(e){console.error(e)}e.zip={Reader:A,Writer:p,BlobReader:d,Data64URIReader:h,TextReader:c,BlobWriter:g,Data64URIWriter:v,TextWriter:f,createReader:function(e,t,i){i=i||I,e.init((function(){P(e,t,i)}),i)},createWriter:function(e,t,i,s){i=i||I,s=!!s,e.init((function(){F(e,t,i,s)}),i)},useWebWorkers:!0,workerScriptsPath:null,workerScripts:null}}(rk);var nk=rk.zip;!function(e){var t,i,s=e.Reader,r=e.Writer;try{i=0===new Blob([new DataView(new ArrayBuffer(0))]).size}catch(e){}function n(e){var t=this;function i(i,s){var r;t.data?i():((r=new XMLHttpRequest).addEventListener("load",(function(){t.size||(t.size=Number(r.getResponseHeader("Content-Length"))||Number(r.response.byteLength)),t.data=new Uint8Array(r.response),i()}),!1),r.addEventListener("error",s,!1),r.open("GET",e),r.responseType="arraybuffer",r.send())}t.size=0,t.init=function(s,r){if(function(e){var t=document.createElement("a");return t.href=e,"http:"===t.protocol||"https:"===t.protocol}(e)){var n=new XMLHttpRequest;n.addEventListener("load",(function(){t.size=Number(n.getResponseHeader("Content-Length")),t.size?s():i(s,r)}),!1),n.addEventListener("error",r,!1),n.open("HEAD",e),n.send()}else i(s,r)},t.readUint8Array=function(e,s,r,n){i((function(){r(new Uint8Array(t.data.subarray(e,e+s)))}),n)}}function o(e){var t=this;t.size=0,t.init=function(i,s){var r=new XMLHttpRequest;r.addEventListener("load",(function(){t.size=Number(r.getResponseHeader("Content-Length")),"bytes"==r.getResponseHeader("Accept-Ranges")?i():s("HTTP Range not supported.")}),!1),r.addEventListener("error",s,!1),r.open("HEAD",e),r.send()},t.readUint8Array=function(t,i,s,r){!function(t,i,s,r){var n=new XMLHttpRequest;n.open("GET",e),n.responseType="arraybuffer",n.setRequestHeader("Range","bytes="+t+"-"+(t+i-1)),n.addEventListener("load",(function(){s(n.response)}),!1),n.addEventListener("error",r,!1),n.send()}(t,i,(function(e){s(new Uint8Array(e))}),r)}}function a(e){var t=this;t.size=0,t.init=function(i,s){t.size=e.byteLength,i()},t.readUint8Array=function(t,i,s,r){s(new Uint8Array(e.slice(t,t+i)))}}function l(){var e,t=this;t.init=function(t,i){e=new Uint8Array,t()},t.writeUint8Array=function(t,i,s){var r=new Uint8Array(e.length+t.length);r.set(e),r.set(t,e.length),e=r,i()},t.getData=function(t){t(e.buffer)}}function u(e,t){var s,r=this;r.init=function(t,i){e.createWriter((function(e){s=e,t()}),i)},r.writeUint8Array=function(e,r,n){var o=new Blob([i?e:e.buffer],{type:t});s.onwrite=function(){s.onwrite=null,r()},s.onerror=n,s.write(o)},r.getData=function(t){e.file(t)}}n.prototype=new s,n.prototype.constructor=n,o.prototype=new s,o.prototype.constructor=o,a.prototype=new s,a.prototype.constructor=a,l.prototype=new r,l.prototype.constructor=l,u.prototype=new r,u.prototype.constructor=u,e.FileWriter=u,e.HttpReader=n,e.HttpRangeReader=o,e.ArrayBufferReader=a,e.ArrayBufferWriter=l,e.fs&&((t=e.fs.ZipDirectoryEntry).prototype.addHttpContent=function(i,s,r){return function(i,s,r,n){if(i.directory)return n?new t(i.fs,s,r,i):new e.fs.ZipFileEntry(i.fs,s,r,i);throw"Parent entry is not a directory."}(this,i,{data:s,Reader:r?o:n})},t.prototype.importHttpContent=function(e,t,i,s){this.importZip(t?new o(e):new n(e),i,s)},e.fs.FS.prototype.importHttpContent=function(e,i,s,r){this.entries=[],this.root=new t(this),this.root.importHttpContent(e,i,s,r)})}(nk);var ok=["4.2"],ak=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this.supportedSchemas=ok,this._xrayOpacity=.7,this._src=null,this._options=i,this.viewpoint=null,i.workerScriptsPath?(nk.workerScriptsPath=i.workerScriptsPath,this.src=i.src,this.xrayOpacity=.7,this.displayEffect=i.displayEffect,this.createMetaModel=i.createMetaModel):t.error("Config expected: workerScriptsPath")}return C(e,[{key:"load",value:function(e,t,i,s,r,n){switch(s.materialType){case"MetallicMaterial":t._defaultMaterial=new Pn(t,{baseColor:[1,1,1],metallic:.6,roughness:.6});break;case"SpecularMaterial":t._defaultMaterial=new Fn(t,{diffuse:[1,1,1],specular:$.vec3([1,1,1]),glossiness:.5});break;default:t._defaultMaterial=new Oi(t,{reflectivity:.75,shiness:100,diffuse:[1,1,1]})}t._wireframeMaterial=new wn(t,{color:[0,0,0],lineWidth:2});var o=t.scene.canvas.spinner;o.processes++,lk(e,t,i,s,(function(){o.processes--,r&&r(),t.fire("loaded",!0,!1)}),(function(e){o.processes--,t.error(e),n&&n(e),t.fire("error",e)}),(function(e){console.log("Error, Will Robinson: "+e)}))}}]),e}(),lk=function(e,t,i,s,r,n){!function(e,t,i){var s=new vk;s.load(e,(function(){t(s)}),(function(e){i("Error loading ZIP archive: "+e)}))}(i,(function(i){uk(e,i,s,t,r,n)}),n)},uk=function(){return function(t,i,s,r,n){var o={plugin:t,zip:i,edgeThreshold:30,materialType:s.materialType,scene:r.scene,modelNode:r,info:{references:{}},materials:{}};s.createMetaModel&&(o.metaModelData={modelId:r.id,metaObjects:[{name:r.id,type:"Default",id:r.id}]}),r.scene.loading++,function(t,i){t.zip.getFile("Manifest.xml",(function(s,r){for(var n=r.children,o=0,a=n.length;o0){for(var o=n.trim().split(" "),a=new Int16Array(o.length),l=0,u=0,A=o.length;u0){i.primitive="triangles";for(var n=[],o=0,a=r.length;o=t.length)i();else{var a=t[n].id,l=a.lastIndexOf(":");l>0&&(a=a.substring(l+1));var u=a.lastIndexOf("#");u>0&&(a=a.substring(0,u)),s[a]?r(n+1):function(e,t,i){e.zip.getFile(t,(function(t,s){!function(e,t,i){for(var s,r=t.children,n=0,o=r.length;n0)for(var s=0,r=t.length;s1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),s=t.call(this,"XML3DLoader",e,r),r.workerScriptsPath?(s._workerScriptsPath=r.workerScriptsPath,s._loader=new ak(b(s),r),s.supportedSchemas=s._loader.supportedSchemas,s):(s.error("Config expected: workerScriptsPath"),y(s))}return C(i,[{key:"load",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e.workerScriptsPath=this._workerScriptsPath,e.id&&this.viewer.scene.components[e.id]&&(this.error("Component with this ID already exists in viewer: "+e.id+" - will autogenerate this ID"),delete e.id);var t=new bn(this.viewer.scene,le.apply(e,{isModel:!0})),i=e.src;return i?(this._loader.load(this,t,i,e),t):(this.error("load() param expected: src"),t)}}]),i}(),_k=function(){function e(){x(this,e)}return C(e,[{key:"getIFC",value:function(e,t,i){var s=function(){};t=t||s,i=i||s;var r=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(r){var n=!!r[2],o=r[3];o=window.decodeURIComponent(o),n&&(o=window.atob(o));try{for(var a=new ArrayBuffer(o.length),l=new Uint8Array(a),u=0;u1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,"ifcLoader",e,r)).dataSource=r.dataSource,s.objectDefaults=r.objectDefaults,s.includeTypes=r.includeTypes,s.excludeTypes=r.excludeTypes,s.excludeUnclassifiedObjects=r.excludeUnclassifiedObjects,!r.WebIFC)throw"Parameter expected: WebIFC";if(!r.IfcAPI)throw"Parameter expected: IfcAPI";return s._webIFC=r.WebIFC,s._ifcAPI=r.IfcAPI,s}return C(i,[{key:"supportedVersions",get:function(){return["2x3","4"]}},{key:"dataSource",get:function(){return this._dataSource},set:function(e){this._dataSource=e||new _k}},{key:"objectDefaults",get:function(){return this._objectDefaults},set:function(e){this._objectDefaults=e||uF}},{key:"includeTypes",get:function(){return this._includeTypes},set:function(e){this._includeTypes=e}},{key:"excludeTypes",get:function(){return this._excludeTypes},set:function(e){this._excludeTypes=e}},{key:"excludeUnclassifiedObjects",get:function(){return this._excludeUnclassifiedObjects},set:function(e){this._excludeUnclassifiedObjects=!!e}},{key:"globalizeObjectIds",get:function(){return this._globalizeObjectIds},set:function(e){this._globalizeObjectIds=!!e}},{key:"load",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e.id&&this.viewer.scene.components[e.id]&&(this.error("Component with this ID already exists in viewer: "+e.id+" - will autogenerate this ID"),delete e.id);var t=new ch(this.viewer.scene,le.apply(e,{isModel:!0}));if(!e.src&&!e.ifc)return this.error("load() param expected: src or IFC"),t;var i={autoNormals:!0};if(!1!==e.loadMetadata){var s=e.includeTypes||this._includeTypes,r=e.excludeTypes||this._excludeTypes,n=e.objectDefaults||this._objectDefaults;if(s){i.includeTypesMap={};for(var o=0,a=s.length;o0){for(var l=n.Name.value,u=[],A=0,c=a.length;A1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"lasLoader",e,r)).dataSource=r.dataSource,s.skip=r.skip,s.fp64=r.fp64,s.colorDepth=r.colorDepth,s}return C(i,[{key:"dataSource",get:function(){return this._dataSource},set:function(e){this._dataSource=e||new bk}},{key:"skip",get:function(){return this._skip},set:function(e){this._skip=e||1}},{key:"fp64",get:function(){return this._fp64},set:function(e){this._fp64=!!e}},{key:"colorDepth",get:function(){return this._colorDepth},set:function(e){this._colorDepth=e||"auto"}},{key:"load",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t.id&&this.viewer.scene.components[t.id]&&(this.error("Component with this ID already exists in viewer: "+t.id+" - will autogenerate this ID"),delete t.id);var i=new ch(this.viewer.scene,le.apply(t,{isModel:!0}));if(!t.src&&!t.las)return this.error("load() param expected: src or las"),i;var s={las:{skip:this._skip,fp64:this._fp64,colorDepth:this._colorDepth}};if(t.src)this._loadModel(t.src,t,s,i);else{var r=this.viewer.scene.canvas.spinner;r.processes++,this._parseModel(t.las,t,s,i).then((function(){r.processes--}),(function(t){r.processes--,e.error(t),i.fire("error",t)}))}return i}},{key:"_loadModel",value:function(e,t,i,s){var r=this,n=this.viewer.scene.canvas.spinner;n.processes++,this._dataSource.getLAS(t.src,(function(e){r._parseModel(e,t,i,s).then((function(){n.processes--}),(function(e){n.processes--,r.error(e),s.fire("error",e)}))}),(function(e){n.processes--,r.error(e),s.fire("error",e)}))}},{key:"_parseModel",value:function(e,t,i,s){var r=this;function n(e){var i=e.value;if(t.rotateX&&i)for(var s=0,r=i.length;s=e.length)return e;for(var i=[],s=0;s80*i){s=n=e[0],r=o=e[1];for(var p=i;pn&&(n=a),l>o&&(o=l);u=0!==(u=Math.max(n-s,o-r))?1/u:0}return Tk(h,d,i,s,r,u),d}function Dk(e,t,i,s,r){var n,o;if(r===iI(e,t,i,s)>0)for(n=t;n=t;n-=s)o=$k(n,e[n],e[n+1],o);return o&&Kk(o,o.next)&&(eI(o),o=o.next),o}function Sk(e,t){if(!e)return e;t||(t=e);var i,s=e;do{if(i=!1,s.steiner||!Kk(s,s.next)&&0!==Wk(s.prev,s,s.next))s=s.next;else{if(eI(s),(s=t=s.prev)===s.next)break;i=!0}}while(i||s!==t);return t}function Tk(e,t,i,s,r,n,o){if(e){!o&&n&&function(e,t,i,s){var r=e;do{null===r.z&&(r.z=Hk(r.x,r.y,t,i,s)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==e);r.prevZ.nextZ=null,r.prevZ=null,function(e){var t,i,s,r,n,o,a,l,u=1;do{for(i=e,e=null,n=null,o=0;i;){for(o++,s=i,a=0,t=0;t0||l>0&&s;)0!==a&&(0===l||!s||i.z<=s.z)?(r=i,i=i.nextZ,a--):(r=s,s=s.nextZ,l--),n?n.nextZ=r:e=r,r.prevZ=n,n=r;i=s}n.nextZ=null,u*=2}while(o>1)}(r)}(e,s,r,n);for(var a,l,u=e;e.prev!==e.next;)if(a=e.prev,l=e.next,n?Lk(e,s,r,n):Rk(e))t.push(a.i/i),t.push(e.i/i),t.push(l.i/i),eI(e),e=l.next,u=l.next;else if((e=l)===u){o?1===o?Tk(e=Uk(Sk(e),t,i),t,i,s,r,n,2):2===o&&Ok(e,t,i,s,r,n):Tk(Sk(e),t,i,s,r,n,1);break}}}function Rk(e){var t=e.prev,i=e,s=e.next;if(Wk(t,i,s)>=0)return!1;for(var r=e.next.next;r!==e.prev;){if(Gk(t.x,t.y,i.x,i.y,s.x,s.y,r.x,r.y)&&Wk(r.prev,r,r.next)>=0)return!1;r=r.next}return!0}function Lk(e,t,i,s){var r=e.prev,n=e,o=e.next;if(Wk(r,n,o)>=0)return!1;for(var a=r.xn.x?r.x>o.x?r.x:o.x:n.x>o.x?n.x:o.x,A=r.y>n.y?r.y>o.y?r.y:o.y:n.y>o.y?n.y:o.y,c=Hk(a,l,t,i,s),h=Hk(u,A,t,i,s),d=e.prevZ,p=e.nextZ;d&&d.z>=c&&p&&p.z<=h;){if(d!==e.prev&&d!==e.next&&Gk(r.x,r.y,n.x,n.y,o.x,o.y,d.x,d.y)&&Wk(d.prev,d,d.next)>=0)return!1;if(d=d.prevZ,p!==e.prev&&p!==e.next&&Gk(r.x,r.y,n.x,n.y,o.x,o.y,p.x,p.y)&&Wk(p.prev,p,p.next)>=0)return!1;p=p.nextZ}for(;d&&d.z>=c;){if(d!==e.prev&&d!==e.next&&Gk(r.x,r.y,n.x,n.y,o.x,o.y,d.x,d.y)&&Wk(d.prev,d,d.next)>=0)return!1;d=d.prevZ}for(;p&&p.z<=h;){if(p!==e.prev&&p!==e.next&&Gk(r.x,r.y,n.x,n.y,o.x,o.y,p.x,p.y)&&Wk(p.prev,p,p.next)>=0)return!1;p=p.nextZ}return!0}function Uk(e,t,i){var s=e;do{var r=s.prev,n=s.next.next;!Kk(r,n)&&Xk(r,s,s.next,n)&&Zk(r,n)&&Zk(n,r)&&(t.push(r.i/i),t.push(s.i/i),t.push(n.i/i),eI(s),eI(s.next),s=e=n),s=s.next}while(s!==e);return Sk(s)}function Ok(e,t,i,s,r,n){var o=e;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&zk(o,a)){var l=qk(o,a);return o=Sk(o,o.next),l=Sk(l,l.next),Tk(o,t,i,s,r,n),void Tk(l,t,i,s,r,n)}a=a.next}o=o.next}while(o!==e)}function Nk(e,t){return e.x-t.x}function Qk(e,t){if(t=function(e,t){var i,s=t,r=e.x,n=e.y,o=-1/0;do{if(n<=s.y&&n>=s.next.y&&s.next.y!==s.y){var a=s.x+(n-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(a<=r&&a>o){if(o=a,a===r){if(n===s.y)return s;if(n===s.next.y)return s.next}i=s.x=s.x&&s.x>=A&&r!==s.x&&Gk(ni.x||s.x===i.x&&Vk(i,s)))&&(i=s,h=l)),s=s.next}while(s!==u);return i}(e,t),t){var i=qk(t,e);Sk(t,t.next),Sk(i,i.next)}}function Vk(e,t){return Wk(e.prev,e,t.prev)<0&&Wk(t.next,e,e.next)<0}function Hk(e,t,i,s,r){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-i)*r)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-s)*r)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function jk(e){var t=e,i=e;do{(t.x=0&&(e-o)*(s-a)-(i-o)*(t-a)>=0&&(i-o)*(n-a)-(r-o)*(s-a)>=0}function zk(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){var i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&Xk(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&(Zk(e,t)&&Zk(t,e)&&function(e,t){var i=e,s=!1,r=(e.x+t.x)/2,n=(e.y+t.y)/2;do{i.y>n!=i.next.y>n&&i.next.y!==i.y&&r<(i.next.x-i.x)*(n-i.y)/(i.next.y-i.y)+i.x&&(s=!s),i=i.next}while(i!==e);return s}(e,t)&&(Wk(e.prev,e,t.prev)||Wk(e,t.prev,t))||Kk(e,t)&&Wk(e.prev,e,e.next)>0&&Wk(t.prev,t,t.next)>0)}function Wk(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function Kk(e,t){return e.x===t.x&&e.y===t.y}function Xk(e,t,i,s){var r=Yk(Wk(e,t,i)),n=Yk(Wk(e,t,s)),o=Yk(Wk(i,s,e)),a=Yk(Wk(i,s,t));return r!==n&&o!==a||(!(0!==r||!Jk(e,i,t))||(!(0!==n||!Jk(e,s,t))||(!(0!==o||!Jk(i,e,s))||!(0!==a||!Jk(i,t,s)))))}function Jk(e,t,i){return t.x<=Math.max(e.x,i.x)&&t.x>=Math.min(e.x,i.x)&&t.y<=Math.max(e.y,i.y)&&t.y>=Math.min(e.y,i.y)}function Yk(e){return e>0?1:e<0?-1:0}function Zk(e,t){return Wk(e.prev,e,e.next)<0?Wk(e,t,e.next)>=0&&Wk(e,e.prev,t)>=0:Wk(e,t,e.prev)<0||Wk(e,e.next,t)<0}function qk(e,t){var i=new tI(e.i,e.x,e.y),s=new tI(t.i,t.x,t.y),r=e.next,n=t.prev;return e.next=t,t.prev=e,i.next=r,r.prev=i,s.next=i,i.prev=s,n.next=s,s.prev=n,s}function $k(e,t,i,s){var r=new tI(e,t,i);return s?(r.next=s.next,r.prev=s,s.next.prev=r,s.next=r):(r.prev=r,r.next=r),r}function eI(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function tI(e,t,i){this.i=e,this.x=t,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function iI(e,t,i,s){for(var r=0,n=t,o=i-s;n0&&(s+=e[r-1].length,i.holes.push(s))}return i};var sI=$.vec2(),rI=$.vec3(),nI=$.vec3(),oI=$.vec3(),aI=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"cityJSONLoader",e,r)).dataSource=r.dataSource,s}return C(i,[{key:"dataSource",get:function(){return this._dataSource},set:function(e){this._dataSource=e||new kk}},{key:"load",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e.id&&this.viewer.scene.components[e.id]&&(this.error("Component with this ID already exists in viewer: "+e.id+" - will autogenerate this ID"),delete e.id);var t=new ch(this.viewer.scene,le.apply(e,{isModel:!0,edges:!0}));if(!e.src&&!e.cityJSON)return this.error("load() param expected: src or cityJSON"),t;var i={};if(e.src)this._loadModel(e.src,e,i,t);else{var s=this.viewer.scene.canvas.spinner;s.processes++,this._parseModel(e.cityJSON,e,i,t),s.processes--}return t}},{key:"_loadModel",value:function(e,t,i,s){var r=this,n=this.viewer.scene.canvas.spinner;n.processes++,this._dataSource.getCityJSON(t.src,(function(e){r._parseModel(e,t,i,s),n.processes--}),(function(e){n.processes--,r.error(e),s.fire("error",e)}))}},{key:"_parseModel",value:function(e,t,i,s){if(!s.destroyed){var r=e.transform?this._transformVertices(e.vertices,e.transform,i.rotateX):e.vertices,n=t.stats||{};n.sourceFormat=e.type||"CityJSON",n.schemaVersion=e.version||"",n.title="",n.author="",n.created="",n.numMetaObjects=0,n.numPropertySets=0,n.numObjects=0,n.numGeometries=0,n.numTriangles=0,n.numVertices=0;var o=!1!==t.loadMetadata,a=o?{id:$.createUUID(),name:"Model",type:"Model"}:null,l=o?{id:"",projectId:"",author:"",createdAt:"",schema:e.version||"",creatingApplication:"",metaObjects:[a],propertySets:[]}:null,u={data:e,vertices:r,sceneModel:s,loadMetadata:o,metadata:l,rootMetaObject:a,nextId:0,stats:n};if(this._parseCityJSON(u),s.finalize(),o){var A=s.id;this.viewer.metaScene.createMetaModel(A,u.metadata,i)}s.scene.once("tick",(function(){s.destroyed||(s.scene.fire("modelLoaded",s.id),s.fire("loaded",!0,!1))}))}}},{key:"_transformVertices",value:function(e,t,i){for(var s=[],r=t.scale||$.vec3([1,1,1]),n=t.translate||$.vec3([0,0,0]),o=0,a=0;o0){for(var u=[],A=0,c=t.geometry.length;A0){var _=g[m[0]];if(void 0!==_.value)d=v[_.value];else{var y=_.values;if(y){p=[];for(var b=0,w=y.length;b0&&(s.createEntity({id:i,meshIds:u,isObject:!0}),e.stats.numObjects++)}}},{key:"_parseGeometrySurfacesWithOwnMaterials",value:function(e,t,i,s){switch(t.type){case"MultiPoint":case"MultiLineString":break;case"MultiSurface":case"CompositeSurface":var r=t.boundaries;this._parseSurfacesWithOwnMaterials(e,i,r,s);break;case"Solid":for(var n=t.boundaries,o=0;o0&&c.push(u.length);var f=this._extractLocalIndices(e,a[p],h,d);u.push.apply(u,A(f))}if(3===u.length)d.indices.push(u[0]),d.indices.push(u[1]),d.indices.push(u[2]);else if(u.length>3){for(var v=[],g=0;g0&&o.indices.length>0){var f=""+e.nextId++;r.createMesh({id:f,primitive:"triangles",positions:o.positions,indices:o.indices,color:i&&i.diffuseColor?i.diffuseColor:[.8,.8,.8],opacity:1}),s.push(f),e.stats.numGeometries++,e.stats.numVertices+=o.positions.length/3,e.stats.numTriangles+=o.indices.length/3}}},{key:"_parseSurfacesWithSharedMaterial",value:function(e,t,i,s){for(var r=e.vertices,n=0;n0&&a.push(o.length);var u=this._extractLocalIndices(e,t[n][l],i,s);o.push.apply(o,A(u))}if(3===o.length)s.indices.push(o[0]),s.indices.push(o[1]),s.indices.push(o[2]);else if(o.length>3){for(var c=[],h=0;h0&&r[r.length-1])||6!==n[0]&&2!==n[0])){o=0;continue}if(3===n[0]&&(!r||n[1]>r[0]&&n[1]=55296&&r<=56319&&i>10),o%1024+56320)),(r+1===i||s.length>16384)&&(n+=String.fromCharCode.apply(String,s),s.length=0)}return n},fp="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",vp="undefined"==typeof Uint8Array?[]:new Uint8Array(256),gp=0;gp=0){if(e<55296||e>56319&&e<=65535)return t=((t=this.index[e>>5])<<2)+(31&e),this.data[t];if(e<=65535)return t=((t=this.index[2048+(e-55296>>5)])<<2)+(31&e),this.data[t];if(e>11),t=this.index[t],t+=e>>5&63,t=((t=this.index[t])<<2)+(31&e),this.data[t];if(e<=1114111)return this.data[this.highValueIndex]}return this.errorValue},e}(),wp="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",xp="undefined"==typeof Uint8Array?[]:new Uint8Array(256),Pp=0;Pp>4,A[l++]=(15&s)<<4|r>>2,A[l++]=(3&r)<<6|63&n;return u}(e),o=Array.isArray(n)?function(e){for(var t=e.length,i=[],s=0;s0;){var o=s[--n];if(Array.isArray(e)?-1!==e.indexOf(o):e===o)for(var a=i;a<=s.length;){var l;if((l=s[++a])===t)return!0;if(l!==Cp)break}if(o!==Cp)break}return!1},af=function(e,t){for(var i=e;i>=0;){var s=t[i];if(s!==Cp)return s;i--}return 0},lf=function(e,t,i,s,r){if(0===i[s])return"×";var n=s-1;if(Array.isArray(r)&&!0===r[n])return"×";var o=n-1,a=n+1,l=t[n],u=o>=0?t[o]:0,A=t[a];if(2===l&&3===A)return"×";if(-1!==$p.indexOf(l))return"!";if(-1!==$p.indexOf(A))return"×";if(-1!==ef.indexOf(A))return"×";if(8===af(n,t))return"÷";if(11===Zp.get(e[n]))return"×";if((l===Vp||l===Hp)&&11===Zp.get(e[a]))return"×";if(7===l||7===A)return"×";if(9===l)return"×";if(-1===[Cp,Mp,Fp].indexOf(l)&&9===A)return"×";if(-1!==[Ep,kp,Ip,Rp,Np].indexOf(A))return"×";if(af(n,t)===Tp)return"×";if(of(23,Tp,n,t))return"×";if(of([Ep,kp],Sp,n,t))return"×";if(of(12,12,n,t))return"×";if(l===Cp)return"÷";if(23===l||23===A)return"×";if(16===A||16===l)return"÷";if(-1!==[Mp,Fp,Sp].indexOf(A)||14===l)return"×";if(36===u&&-1!==nf.indexOf(l))return"×";if(l===Np&&36===A)return"×";if(A===Dp)return"×";if(-1!==qp.indexOf(A)&&l===Lp||-1!==qp.indexOf(l)&&A===Lp)return"×";if(l===Op&&-1!==[zp,Vp,Hp].indexOf(A)||-1!==[zp,Vp,Hp].indexOf(l)&&A===Up)return"×";if(-1!==qp.indexOf(l)&&-1!==tf.indexOf(A)||-1!==tf.indexOf(l)&&-1!==qp.indexOf(A))return"×";if(-1!==[Op,Up].indexOf(l)&&(A===Lp||-1!==[Tp,Fp].indexOf(A)&&t[a+1]===Lp)||-1!==[Tp,Fp].indexOf(l)&&A===Lp||l===Lp&&-1!==[Lp,Np,Rp].indexOf(A))return"×";if(-1!==[Lp,Np,Rp,Ep,kp].indexOf(A))for(var c=n;c>=0;){if((h=t[c])===Lp)return"×";if(-1===[Np,Rp].indexOf(h))break;c--}if(-1!==[Op,Up].indexOf(A))for(c=-1!==[Ep,kp].indexOf(l)?o:n;c>=0;){var h;if((h=t[c])===Lp)return"×";if(-1===[Np,Rp].indexOf(h))break;c--}if(Wp===l&&-1!==[Wp,Kp,jp,Gp].indexOf(A)||-1!==[Kp,jp].indexOf(l)&&-1!==[Kp,Xp].indexOf(A)||-1!==[Xp,Gp].indexOf(l)&&A===Xp)return"×";if(-1!==rf.indexOf(l)&&-1!==[Dp,Up].indexOf(A)||-1!==rf.indexOf(A)&&l===Op)return"×";if(-1!==qp.indexOf(l)&&-1!==qp.indexOf(A))return"×";if(l===Rp&&-1!==qp.indexOf(A))return"×";if(-1!==qp.concat(Lp).indexOf(l)&&A===Tp&&-1===Yp.indexOf(e[a])||-1!==qp.concat(Lp).indexOf(A)&&l===kp)return"×";if(41===l&&41===A){for(var d=i[n],p=1;d>0&&41===t[--d];)p++;if(p%2!=0)return"×"}return l===Vp&&A===Hp?"×":"÷"},uf=function(e,t){t||(t={lineBreak:"normal",wordBreak:"normal"});var i=function(e,t){void 0===t&&(t="strict");var i=[],s=[],r=[];return e.forEach((function(e,n){var o=Zp.get(e);if(o>50?(r.push(!0),o-=50):r.push(!1),-1!==["normal","auto","loose"].indexOf(t)&&-1!==[8208,8211,12316,12448].indexOf(e))return s.push(n),i.push(16);if(4===o||11===o){if(0===n)return s.push(n),i.push(Qp);var a=i[n-1];return-1===sf.indexOf(a)?(s.push(s[n-1]),i.push(a)):(s.push(n),i.push(Qp))}return s.push(n),31===o?i.push("strict"===t?Sp:zp):o===Jp||29===o?i.push(Qp):43===o?e>=131072&&e<=196605||e>=196608&&e<=262141?i.push(zp):i.push(Qp):void i.push(o)})),[s,i,r]}(e,t.lineBreak),s=i[0],r=i[1],n=i[2];"break-all"!==t.wordBreak&&"break-word"!==t.wordBreak||(r=r.map((function(e){return-1!==[Lp,Qp,Jp].indexOf(e)?zp:e})));var o="keep-all"===t.wordBreak?n.map((function(t,i){return t&&e[i]>=19968&&e[i]<=40959})):void 0;return[s,r,o]},Af=function(){function e(e,t,i,s){this.codePoints=e,this.required="!"===t,this.start=i,this.end=s}return e.prototype.slice=function(){return pp.apply(void 0,this.codePoints.slice(this.start,this.end))},e}(),cf=function(e){return e>=48&&e<=57},hf=function(e){return cf(e)||e>=65&&e<=70||e>=97&&e<=102},df=function(e){return 10===e||9===e||32===e},pf=function(e){return function(e){return function(e){return e>=97&&e<=122}(e)||function(e){return e>=65&&e<=90}(e)}(e)||function(e){return e>=128}(e)||95===e},ff=function(e){return pf(e)||cf(e)||45===e},vf=function(e){return e>=0&&e<=8||11===e||e>=14&&e<=31||127===e},gf=function(e,t){return 92===e&&10!==t},mf=function(e,t,i){return 45===e?pf(t)||gf(t,i):!!pf(e)||!(92!==e||!gf(e,t))},_f=function(e,t,i){return 43===e||45===e?!!cf(t)||46===t&&cf(i):cf(46===e?t:e)},yf=function(e){var t=0,i=1;43!==e[t]&&45!==e[t]||(45===e[t]&&(i=-1),t++);for(var s=[];cf(e[t]);)s.push(e[t++]);var r=s.length?parseInt(pp.apply(void 0,s),10):0;46===e[t]&&t++;for(var n=[];cf(e[t]);)n.push(e[t++]);var o=n.length,a=o?parseInt(pp.apply(void 0,n),10):0;69!==e[t]&&101!==e[t]||t++;var l=1;43!==e[t]&&45!==e[t]||(45===e[t]&&(l=-1),t++);for(var u=[];cf(e[t]);)u.push(e[t++]);var A=u.length?parseInt(pp.apply(void 0,u),10):0;return i*(r+a*Math.pow(10,-o))*Math.pow(10,l*A)},bf={type:2},Bf={type:3},wf={type:4},xf={type:13},Pf={type:8},Cf={type:21},Mf={type:9},Ff={type:10},Ef={type:11},kf={type:12},If={type:14},Df={type:23},Sf={type:1},Tf={type:25},Rf={type:24},Lf={type:26},Uf={type:27},Of={type:28},Nf={type:29},Qf={type:31},Vf={type:32},Hf=function(){function e(){this._value=[]}return e.prototype.write=function(e){this._value=this._value.concat(dp(e))},e.prototype.read=function(){for(var e=[],t=this.consumeToken();t!==Vf;)e.push(t),t=this.consumeToken();return e},e.prototype.consumeToken=function(){var e=this.consumeCodePoint();switch(e){case 34:return this.consumeStringToken(34);case 35:var t=this.peekCodePoint(0),i=this.peekCodePoint(1),s=this.peekCodePoint(2);if(ff(t)||gf(i,s)){var r=mf(t,i,s)?2:1;return{type:5,value:this.consumeName(),flags:r}}break;case 36:if(61===this.peekCodePoint(0))return this.consumeCodePoint(),xf;break;case 39:return this.consumeStringToken(39);case 40:return bf;case 41:return Bf;case 42:if(61===this.peekCodePoint(0))return this.consumeCodePoint(),If;break;case 43:if(_f(e,this.peekCodePoint(0),this.peekCodePoint(1)))return this.reconsumeCodePoint(e),this.consumeNumericToken();break;case 44:return wf;case 45:var n=e,o=this.peekCodePoint(0),a=this.peekCodePoint(1);if(_f(n,o,a))return this.reconsumeCodePoint(e),this.consumeNumericToken();if(mf(n,o,a))return this.reconsumeCodePoint(e),this.consumeIdentLikeToken();if(45===o&&62===a)return this.consumeCodePoint(),this.consumeCodePoint(),Rf;break;case 46:if(_f(e,this.peekCodePoint(0),this.peekCodePoint(1)))return this.reconsumeCodePoint(e),this.consumeNumericToken();break;case 47:if(42===this.peekCodePoint(0))for(this.consumeCodePoint();;){var l=this.consumeCodePoint();if(42===l&&47===(l=this.consumeCodePoint()))return this.consumeToken();if(-1===l)return this.consumeToken()}break;case 58:return Lf;case 59:return Uf;case 60:if(33===this.peekCodePoint(0)&&45===this.peekCodePoint(1)&&45===this.peekCodePoint(2))return this.consumeCodePoint(),this.consumeCodePoint(),Tf;break;case 64:var u=this.peekCodePoint(0),A=this.peekCodePoint(1),c=this.peekCodePoint(2);if(mf(u,A,c))return{type:7,value:this.consumeName()};break;case 91:return Of;case 92:if(gf(e,this.peekCodePoint(0)))return this.reconsumeCodePoint(e),this.consumeIdentLikeToken();break;case 93:return Nf;case 61:if(61===this.peekCodePoint(0))return this.consumeCodePoint(),Pf;break;case 123:return Ef;case 125:return kf;case 117:case 85:var h=this.peekCodePoint(0),d=this.peekCodePoint(1);return 43!==h||!hf(d)&&63!==d||(this.consumeCodePoint(),this.consumeUnicodeRangeToken()),this.reconsumeCodePoint(e),this.consumeIdentLikeToken();case 124:if(61===this.peekCodePoint(0))return this.consumeCodePoint(),Mf;if(124===this.peekCodePoint(0))return this.consumeCodePoint(),Cf;break;case 126:if(61===this.peekCodePoint(0))return this.consumeCodePoint(),Ff;break;case-1:return Vf}return df(e)?(this.consumeWhiteSpace(),Qf):cf(e)?(this.reconsumeCodePoint(e),this.consumeNumericToken()):pf(e)?(this.reconsumeCodePoint(e),this.consumeIdentLikeToken()):{type:6,value:pp(e)}},e.prototype.consumeCodePoint=function(){var e=this._value.shift();return void 0===e?-1:e},e.prototype.reconsumeCodePoint=function(e){this._value.unshift(e)},e.prototype.peekCodePoint=function(e){return e>=this._value.length?-1:this._value[e]},e.prototype.consumeUnicodeRangeToken=function(){for(var e=[],t=this.consumeCodePoint();hf(t)&&e.length<6;)e.push(t),t=this.consumeCodePoint();for(var i=!1;63===t&&e.length<6;)e.push(t),t=this.consumeCodePoint(),i=!0;if(i)return{type:30,start:parseInt(pp.apply(void 0,e.map((function(e){return 63===e?48:e}))),16),end:parseInt(pp.apply(void 0,e.map((function(e){return 63===e?70:e}))),16)};var s=parseInt(pp.apply(void 0,e),16);if(45===this.peekCodePoint(0)&&hf(this.peekCodePoint(1))){this.consumeCodePoint(),t=this.consumeCodePoint();for(var r=[];hf(t)&&r.length<6;)r.push(t),t=this.consumeCodePoint();return{type:30,start:s,end:parseInt(pp.apply(void 0,r),16)}}return{type:30,start:s,end:s}},e.prototype.consumeIdentLikeToken=function(){var e=this.consumeName();return"url"===e.toLowerCase()&&40===this.peekCodePoint(0)?(this.consumeCodePoint(),this.consumeUrlToken()):40===this.peekCodePoint(0)?(this.consumeCodePoint(),{type:19,value:e}):{type:20,value:e}},e.prototype.consumeUrlToken=function(){var e=[];if(this.consumeWhiteSpace(),-1===this.peekCodePoint(0))return{type:22,value:""};var t=this.peekCodePoint(0);if(39===t||34===t){var i=this.consumeStringToken(this.consumeCodePoint());return 0===i.type&&(this.consumeWhiteSpace(),-1===this.peekCodePoint(0)||41===this.peekCodePoint(0))?(this.consumeCodePoint(),{type:22,value:i.value}):(this.consumeBadUrlRemnants(),Df)}for(;;){var s=this.consumeCodePoint();if(-1===s||41===s)return{type:22,value:pp.apply(void 0,e)};if(df(s))return this.consumeWhiteSpace(),-1===this.peekCodePoint(0)||41===this.peekCodePoint(0)?(this.consumeCodePoint(),{type:22,value:pp.apply(void 0,e)}):(this.consumeBadUrlRemnants(),Df);if(34===s||39===s||40===s||vf(s))return this.consumeBadUrlRemnants(),Df;if(92===s){if(!gf(s,this.peekCodePoint(0)))return this.consumeBadUrlRemnants(),Df;e.push(this.consumeEscapedCodePoint())}else e.push(s)}},e.prototype.consumeWhiteSpace=function(){for(;df(this.peekCodePoint(0));)this.consumeCodePoint()},e.prototype.consumeBadUrlRemnants=function(){for(;;){var e=this.consumeCodePoint();if(41===e||-1===e)return;gf(e,this.peekCodePoint(0))&&this.consumeEscapedCodePoint()}},e.prototype.consumeStringSlice=function(e){for(var t="";e>0;){var i=Math.min(5e4,e);t+=pp.apply(void 0,this._value.splice(0,i)),e-=i}return this._value.shift(),t},e.prototype.consumeStringToken=function(e){for(var t="",i=0;;){var s=this._value[i];if(-1===s||void 0===s||s===e)return{type:0,value:t+=this.consumeStringSlice(i)};if(10===s)return this._value.splice(0,i),Sf;if(92===s){var r=this._value[i+1];-1!==r&&void 0!==r&&(10===r?(t+=this.consumeStringSlice(i),i=-1,this._value.shift()):gf(s,r)&&(t+=this.consumeStringSlice(i),t+=pp(this.consumeEscapedCodePoint()),i=-1))}i++}},e.prototype.consumeNumber=function(){var e=[],t=4,i=this.peekCodePoint(0);for(43!==i&&45!==i||e.push(this.consumeCodePoint());cf(this.peekCodePoint(0));)e.push(this.consumeCodePoint());i=this.peekCodePoint(0);var s=this.peekCodePoint(1);if(46===i&&cf(s))for(e.push(this.consumeCodePoint(),this.consumeCodePoint()),t=8;cf(this.peekCodePoint(0));)e.push(this.consumeCodePoint());i=this.peekCodePoint(0),s=this.peekCodePoint(1);var r=this.peekCodePoint(2);if((69===i||101===i)&&((43===s||45===s)&&cf(r)||cf(s)))for(e.push(this.consumeCodePoint(),this.consumeCodePoint()),t=8;cf(this.peekCodePoint(0));)e.push(this.consumeCodePoint());return[yf(e),t]},e.prototype.consumeNumericToken=function(){var e=this.consumeNumber(),t=e[0],i=e[1],s=this.peekCodePoint(0),r=this.peekCodePoint(1),n=this.peekCodePoint(2);return mf(s,r,n)?{type:15,number:t,flags:i,unit:this.consumeName()}:37===s?(this.consumeCodePoint(),{type:16,number:t,flags:i}):{type:17,number:t,flags:i}},e.prototype.consumeEscapedCodePoint=function(){var e=this.consumeCodePoint();if(hf(e)){for(var t=pp(e);hf(this.peekCodePoint(0))&&t.length<6;)t+=pp(this.consumeCodePoint());df(this.peekCodePoint(0))&&this.consumeCodePoint();var i=parseInt(t,16);return 0===i||function(e){return e>=55296&&e<=57343}(i)||i>1114111?65533:i}return-1===e?65533:e},e.prototype.consumeName=function(){for(var e="";;){var t=this.consumeCodePoint();if(ff(t))e+=pp(t);else{if(!gf(t,this.peekCodePoint(0)))return this.reconsumeCodePoint(t),e;e+=pp(this.consumeEscapedCodePoint())}}},e}(),jf=function(){function e(e){this._tokens=e}return e.create=function(t){var i=new Hf;return i.write(t),new e(i.read())},e.parseValue=function(t){return e.create(t).parseComponentValue()},e.parseValues=function(t){return e.create(t).parseComponentValues()},e.prototype.parseComponentValue=function(){for(var e=this.consumeToken();31===e.type;)e=this.consumeToken();if(32===e.type)throw new SyntaxError("Error parsing CSS component value, unexpected EOF");this.reconsumeToken(e);var t=this.consumeComponentValue();do{e=this.consumeToken()}while(31===e.type);if(32===e.type)return t;throw new SyntaxError("Error parsing CSS component value, multiple values found when expecting only one")},e.prototype.parseComponentValues=function(){for(var e=[];;){var t=this.consumeComponentValue();if(32===t.type)return e;e.push(t),e.push()}},e.prototype.consumeComponentValue=function(){var e=this.consumeToken();switch(e.type){case 11:case 28:case 2:return this.consumeSimpleBlock(e.type);case 19:return this.consumeFunction(e)}return e},e.prototype.consumeSimpleBlock=function(e){for(var t={type:e,values:[]},i=this.consumeToken();;){if(32===i.type||qf(i,e))return t;this.reconsumeToken(i),t.values.push(this.consumeComponentValue()),i=this.consumeToken()}},e.prototype.consumeFunction=function(e){for(var t={name:e.value,values:[],type:18};;){var i=this.consumeToken();if(32===i.type||3===i.type)return t;this.reconsumeToken(i),t.values.push(this.consumeComponentValue())}},e.prototype.consumeToken=function(){var e=this._tokens.shift();return void 0===e?Vf:e},e.prototype.reconsumeToken=function(e){this._tokens.unshift(e)},e}(),Gf=function(e){return 15===e.type},zf=function(e){return 17===e.type},Wf=function(e){return 20===e.type},Kf=function(e){return 0===e.type},Xf=function(e,t){return Wf(e)&&e.value===t},Jf=function(e){return 31!==e.type},Yf=function(e){return 31!==e.type&&4!==e.type},Zf=function(e){var t=[],i=[];return e.forEach((function(e){if(4===e.type){if(0===i.length)throw new Error("Error parsing function args, zero tokens for arg");return t.push(i),void(i=[])}31!==e.type&&i.push(e)})),i.length&&t.push(i),t},qf=function(e,t){return 11===t&&12===e.type||(28===t&&29===e.type||2===t&&3===e.type)},$f=function(e){return 17===e.type||15===e.type},ev=function(e){return 16===e.type||$f(e)},tv=function(e){return e.length>1?[e[0],e[1]]:[e[0]]},iv={type:17,number:0,flags:4},sv={type:16,number:50,flags:4},rv={type:16,number:100,flags:4},nv=function(e,t,i){var s=e[0],r=e[1];return[ov(s,t),ov(void 0!==r?r:s,i)]},ov=function(e,t){if(16===e.type)return e.number/100*t;if(Gf(e))switch(e.unit){case"rem":case"em":return 16*e.number;default:return e.number}return e.number},av=function(e,t){if(15===t.type)switch(t.unit){case"deg":return Math.PI*t.number/180;case"grad":return Math.PI/200*t.number;case"rad":return t.number;case"turn":return 2*Math.PI*t.number}throw new Error("Unsupported angle type")},lv=function(e){return 15===e.type&&("deg"===e.unit||"grad"===e.unit||"rad"===e.unit||"turn"===e.unit)},uv=function(e){switch(e.filter(Wf).map((function(e){return e.value})).join(" ")){case"to bottom right":case"to right bottom":case"left top":case"top left":return[iv,iv];case"to top":case"bottom":return Av(0);case"to bottom left":case"to left bottom":case"right top":case"top right":return[iv,rv];case"to right":case"left":return Av(90);case"to top left":case"to left top":case"right bottom":case"bottom right":return[rv,rv];case"to bottom":case"top":return Av(180);case"to top right":case"to right top":case"left bottom":case"bottom left":return[rv,iv];case"to left":case"right":return Av(270)}return 0},Av=function(e){return Math.PI*e/180},cv=function(e,t){if(18===t.type){var i=_v[t.name];if(void 0===i)throw new Error('Attempting to parse an unsupported color function "'+t.name+'"');return i(e,t.values)}if(5===t.type){if(3===t.value.length){var s=t.value.substring(0,1),r=t.value.substring(1,2),n=t.value.substring(2,3);return pv(parseInt(s+s,16),parseInt(r+r,16),parseInt(n+n,16),1)}if(4===t.value.length){s=t.value.substring(0,1),r=t.value.substring(1,2),n=t.value.substring(2,3);var o=t.value.substring(3,4);return pv(parseInt(s+s,16),parseInt(r+r,16),parseInt(n+n,16),parseInt(o+o,16)/255)}if(6===t.value.length){s=t.value.substring(0,2),r=t.value.substring(2,4),n=t.value.substring(4,6);return pv(parseInt(s,16),parseInt(r,16),parseInt(n,16),1)}if(8===t.value.length){s=t.value.substring(0,2),r=t.value.substring(2,4),n=t.value.substring(4,6),o=t.value.substring(6,8);return pv(parseInt(s,16),parseInt(r,16),parseInt(n,16),parseInt(o,16)/255)}}if(20===t.type){var a=bv[t.value.toUpperCase()];if(void 0!==a)return a}return bv.TRANSPARENT},hv=function(e){return 0==(255&e)},dv=function(e){var t=255&e,i=255&e>>8,s=255&e>>16,r=255&e>>24;return t<255?"rgba("+r+","+s+","+i+","+t/255+")":"rgb("+r+","+s+","+i+")"},pv=function(e,t,i,s){return(e<<24|t<<16|i<<8|Math.round(255*s)<<0)>>>0},fv=function(e,t){if(17===e.type)return e.number;if(16===e.type){var i=3===t?1:255;return 3===t?e.number/100*i:Math.round(e.number/100*i)}return 0},vv=function(e,t){var i=t.filter(Yf);if(3===i.length){var s=i.map(fv),r=s[0],n=s[1],o=s[2];return pv(r,n,o,1)}if(4===i.length){var a=i.map(fv),l=(r=a[0],n=a[1],o=a[2],a[3]);return pv(r,n,o,l)}return 0};function gv(e,t,i){return i<0&&(i+=1),i>=1&&(i-=1),i<1/6?(t-e)*i*6+e:i<.5?t:i<2/3?6*(t-e)*(2/3-i)+e:e}var mv=function(e,t){var i=t.filter(Yf),s=i[0],r=i[1],n=i[2],o=i[3],a=(17===s.type?Av(s.number):av(e,s))/(2*Math.PI),l=ev(r)?r.number/100:0,u=ev(n)?n.number/100:0,A=void 0!==o&&ev(o)?ov(o,1):1;if(0===l)return pv(255*u,255*u,255*u,1);var c=u<=.5?u*(l+1):u+l-u*l,h=2*u-c,d=gv(h,c,a+1/3),p=gv(h,c,a),f=gv(h,c,a-1/3);return pv(255*d,255*p,255*f,A)},_v={hsl:mv,hsla:mv,rgb:vv,rgba:vv},yv=function(e,t){return cv(e,jf.create(t).parseComponentValue())},bv={ALICEBLUE:4042850303,ANTIQUEWHITE:4209760255,AQUA:16777215,AQUAMARINE:2147472639,AZURE:4043309055,BEIGE:4126530815,BISQUE:4293182719,BLACK:255,BLANCHEDALMOND:4293643775,BLUE:65535,BLUEVIOLET:2318131967,BROWN:2771004159,BURLYWOOD:3736635391,CADETBLUE:1604231423,CHARTREUSE:2147418367,CHOCOLATE:3530104575,CORAL:4286533887,CORNFLOWERBLUE:1687547391,CORNSILK:4294499583,CRIMSON:3692313855,CYAN:16777215,DARKBLUE:35839,DARKCYAN:9145343,DARKGOLDENROD:3095837695,DARKGRAY:2846468607,DARKGREEN:6553855,DARKGREY:2846468607,DARKKHAKI:3182914559,DARKMAGENTA:2332068863,DARKOLIVEGREEN:1433087999,DARKORANGE:4287365375,DARKORCHID:2570243327,DARKRED:2332033279,DARKSALMON:3918953215,DARKSEAGREEN:2411499519,DARKSLATEBLUE:1211993087,DARKSLATEGRAY:793726975,DARKSLATEGREY:793726975,DARKTURQUOISE:13554175,DARKVIOLET:2483082239,DEEPPINK:4279538687,DEEPSKYBLUE:12582911,DIMGRAY:1768516095,DIMGREY:1768516095,DODGERBLUE:512819199,FIREBRICK:2988581631,FLORALWHITE:4294635775,FORESTGREEN:579543807,FUCHSIA:4278255615,GAINSBORO:3705462015,GHOSTWHITE:4177068031,GOLD:4292280575,GOLDENROD:3668254975,GRAY:2155905279,GREEN:8388863,GREENYELLOW:2919182335,GREY:2155905279,HONEYDEW:4043305215,HOTPINK:4285117695,INDIANRED:3445382399,INDIGO:1258324735,IVORY:4294963455,KHAKI:4041641215,LAVENDER:3873897215,LAVENDERBLUSH:4293981695,LAWNGREEN:2096890111,LEMONCHIFFON:4294626815,LIGHTBLUE:2916673279,LIGHTCORAL:4034953471,LIGHTCYAN:3774873599,LIGHTGOLDENRODYELLOW:4210742015,LIGHTGRAY:3553874943,LIGHTGREEN:2431553791,LIGHTGREY:3553874943,LIGHTPINK:4290167295,LIGHTSALMON:4288707327,LIGHTSEAGREEN:548580095,LIGHTSKYBLUE:2278488831,LIGHTSLATEGRAY:2005441023,LIGHTSLATEGREY:2005441023,LIGHTSTEELBLUE:2965692159,LIGHTYELLOW:4294959359,LIME:16711935,LIMEGREEN:852308735,LINEN:4210091775,MAGENTA:4278255615,MAROON:2147483903,MEDIUMAQUAMARINE:1724754687,MEDIUMBLUE:52735,MEDIUMORCHID:3126187007,MEDIUMPURPLE:2473647103,MEDIUMSEAGREEN:1018393087,MEDIUMSLATEBLUE:2070474495,MEDIUMSPRINGGREEN:16423679,MEDIUMTURQUOISE:1221709055,MEDIUMVIOLETRED:3340076543,MIDNIGHTBLUE:421097727,MINTCREAM:4127193855,MISTYROSE:4293190143,MOCCASIN:4293178879,NAVAJOWHITE:4292783615,NAVY:33023,OLDLACE:4260751103,OLIVE:2155872511,OLIVEDRAB:1804477439,ORANGE:4289003775,ORANGERED:4282712319,ORCHID:3664828159,PALEGOLDENROD:4008225535,PALEGREEN:2566625535,PALETURQUOISE:2951671551,PALEVIOLETRED:3681588223,PAPAYAWHIP:4293907967,PEACHPUFF:4292524543,PERU:3448061951,PINK:4290825215,PLUM:3718307327,POWDERBLUE:2967529215,PURPLE:2147516671,REBECCAPURPLE:1714657791,RED:4278190335,ROSYBROWN:3163525119,ROYALBLUE:1097458175,SADDLEBROWN:2336560127,SALMON:4202722047,SANDYBROWN:4104413439,SEAGREEN:780883967,SEASHELL:4294307583,SIENNA:2689740287,SILVER:3233857791,SKYBLUE:2278484991,SLATEBLUE:1784335871,SLATEGRAY:1887473919,SLATEGREY:1887473919,SNOW:4294638335,SPRINGGREEN:16744447,STEELBLUE:1182971135,TAN:3535047935,TEAL:8421631,THISTLE:3636451583,TOMATO:4284696575,TRANSPARENT:0,TURQUOISE:1088475391,VIOLET:4001558271,WHEAT:4125012991,WHITE:4294967295,WHITESMOKE:4126537215,YELLOW:4294902015,YELLOWGREEN:2597139199},Bv={name:"background-clip",initialValue:"border-box",prefix:!1,type:1,parse:function(e,t){return t.map((function(e){if(Wf(e))switch(e.value){case"padding-box":return 1;case"content-box":return 2}return 0}))}},wv={name:"background-color",initialValue:"transparent",prefix:!1,type:3,format:"color"},xv=function(e,t){var i=cv(e,t[0]),s=t[1];return s&&ev(s)?{color:i,stop:s}:{color:i,stop:null}},Pv=function(e,t){var i=e[0],s=e[e.length-1];null===i.stop&&(i.stop=iv),null===s.stop&&(s.stop=rv);for(var r=[],n=0,o=0;on?r.push(l):r.push(n),n=l}else r.push(null)}var u=null;for(o=0;oe.optimumDistance)?{optimumCorner:t,optimumDistance:a}:e}),{optimumDistance:r?1/0:-1/0,optimumCorner:null}).optimumCorner},Ev=function(e,t){var i=Av(180),s=[];return Zf(t).forEach((function(t,r){if(0===r){var n=t[0];if(20===n.type&&-1!==["top","left","right","bottom"].indexOf(n.value))return void(i=uv(t));if(lv(n))return void(i=(av(e,n)+Av(270))%Av(360))}var o=xv(e,t);s.push(o)})),{angle:i,stops:s,type:1}},kv=function(e,t){var i=0,s=3,r=[],n=[];return Zf(t).forEach((function(t,o){var a=!0;if(0===o?a=t.reduce((function(e,t){if(Wf(t))switch(t.value){case"center":return n.push(sv),!1;case"top":case"left":return n.push(iv),!1;case"right":case"bottom":return n.push(rv),!1}else if(ev(t)||$f(t))return n.push(t),!1;return e}),a):1===o&&(a=t.reduce((function(e,t){if(Wf(t))switch(t.value){case"circle":return i=0,!1;case"ellipse":return i=1,!1;case"contain":case"closest-side":return s=0,!1;case"farthest-side":return s=1,!1;case"closest-corner":return s=2,!1;case"cover":case"farthest-corner":return s=3,!1}else if($f(t)||ev(t))return Array.isArray(s)||(s=[]),s.push(t),!1;return e}),a)),a){var l=xv(e,t);r.push(l)}})),{size:s,shape:i,stops:r,position:n,type:2}},Iv=function(e,t){if(22===t.type){var i={url:t.value,type:0};return e.cache.addImage(t.value),i}if(18===t.type){var s=Sv[t.name];if(void 0===s)throw new Error('Attempting to parse an unsupported image function "'+t.name+'"');return s(e,t.values)}throw new Error("Unsupported image type "+t.type)};var Dv,Sv={"linear-gradient":function(e,t){var i=Av(180),s=[];return Zf(t).forEach((function(t,r){if(0===r){var n=t[0];if(20===n.type&&"to"===n.value)return void(i=uv(t));if(lv(n))return void(i=av(e,n))}var o=xv(e,t);s.push(o)})),{angle:i,stops:s,type:1}},"-moz-linear-gradient":Ev,"-ms-linear-gradient":Ev,"-o-linear-gradient":Ev,"-webkit-linear-gradient":Ev,"radial-gradient":function(e,t){var i=0,s=3,r=[],n=[];return Zf(t).forEach((function(t,o){var a=!0;if(0===o){var l=!1;a=t.reduce((function(e,t){if(l)if(Wf(t))switch(t.value){case"center":return n.push(sv),e;case"top":case"left":return n.push(iv),e;case"right":case"bottom":return n.push(rv),e}else(ev(t)||$f(t))&&n.push(t);else if(Wf(t))switch(t.value){case"circle":return i=0,!1;case"ellipse":return i=1,!1;case"at":return l=!0,!1;case"closest-side":return s=0,!1;case"cover":case"farthest-side":return s=1,!1;case"contain":case"closest-corner":return s=2,!1;case"farthest-corner":return s=3,!1}else if($f(t)||ev(t))return Array.isArray(s)||(s=[]),s.push(t),!1;return e}),a)}if(a){var u=xv(e,t);r.push(u)}})),{size:s,shape:i,stops:r,position:n,type:2}},"-moz-radial-gradient":kv,"-ms-radial-gradient":kv,"-o-radial-gradient":kv,"-webkit-radial-gradient":kv,"-webkit-gradient":function(e,t){var i=Av(180),s=[],r=1;return Zf(t).forEach((function(t,i){var n=t[0];if(0===i){if(Wf(n)&&"linear"===n.value)return void(r=1);if(Wf(n)&&"radial"===n.value)return void(r=2)}if(18===n.type)if("from"===n.name){var o=cv(e,n.values[0]);s.push({stop:iv,color:o})}else if("to"===n.name){o=cv(e,n.values[0]);s.push({stop:rv,color:o})}else if("color-stop"===n.name){var a=n.values.filter(Yf);if(2===a.length){o=cv(e,a[1]);var l=a[0];zf(l)&&s.push({stop:{type:16,number:100*l.number,flags:l.flags},color:o})}}})),1===r?{angle:(i+Av(180))%Av(360),stops:s,type:r}:{size:3,shape:0,stops:s,position:[],type:r}}},Tv={name:"background-image",initialValue:"none",type:1,prefix:!1,parse:function(e,t){if(0===t.length)return[];var i=t[0];return 20===i.type&&"none"===i.value?[]:t.filter((function(e){return Yf(e)&&function(e){return!(20===e.type&&"none"===e.value||18===e.type&&!Sv[e.name])}(e)})).map((function(t){return Iv(e,t)}))}},Rv={name:"background-origin",initialValue:"border-box",prefix:!1,type:1,parse:function(e,t){return t.map((function(e){if(Wf(e))switch(e.value){case"padding-box":return 1;case"content-box":return 2}return 0}))}},Lv={name:"background-position",initialValue:"0% 0%",type:1,prefix:!1,parse:function(e,t){return Zf(t).map((function(e){return e.filter(ev)})).map(tv)}},Uv={name:"background-repeat",initialValue:"repeat",prefix:!1,type:1,parse:function(e,t){return Zf(t).map((function(e){return e.filter(Wf).map((function(e){return e.value})).join(" ")})).map(Ov)}},Ov=function(e){switch(e){case"no-repeat":return 1;case"repeat-x":case"repeat no-repeat":return 2;case"repeat-y":case"no-repeat repeat":return 3;default:return 0}};!function(e){e.AUTO="auto",e.CONTAIN="contain",e.COVER="cover"}(Dv||(Dv={}));var Nv,Qv={name:"background-size",initialValue:"0",prefix:!1,type:1,parse:function(e,t){return Zf(t).map((function(e){return e.filter(Vv)}))}},Vv=function(e){return Wf(e)||ev(e)},Hv=function(e){return{name:"border-"+e+"-color",initialValue:"transparent",prefix:!1,type:3,format:"color"}},jv=Hv("top"),Gv=Hv("right"),zv=Hv("bottom"),Wv=Hv("left"),Kv=function(e){return{name:"border-radius-"+e,initialValue:"0 0",prefix:!1,type:1,parse:function(e,t){return tv(t.filter(ev))}}},Xv=Kv("top-left"),Jv=Kv("top-right"),Yv=Kv("bottom-right"),Zv=Kv("bottom-left"),qv=function(e){return{name:"border-"+e+"-style",initialValue:"solid",prefix:!1,type:2,parse:function(e,t){switch(t){case"none":return 0;case"dashed":return 2;case"dotted":return 3;case"double":return 4}return 1}}},$v=qv("top"),eg=qv("right"),tg=qv("bottom"),ig=qv("left"),sg=function(e){return{name:"border-"+e+"-width",initialValue:"0",type:0,prefix:!1,parse:function(e,t){return Gf(t)?t.number:0}}},rg=sg("top"),ng=sg("right"),og=sg("bottom"),ag=sg("left"),lg={name:"color",initialValue:"transparent",prefix:!1,type:3,format:"color"},ug={name:"direction",initialValue:"ltr",prefix:!1,type:2,parse:function(e,t){return"rtl"===t?1:0}},Ag={name:"display",initialValue:"inline-block",prefix:!1,type:1,parse:function(e,t){return t.filter(Wf).reduce((function(e,t){return e|cg(t.value)}),0)}},cg=function(e){switch(e){case"block":case"-webkit-box":return 2;case"inline":return 4;case"run-in":return 8;case"flow":return 16;case"flow-root":return 32;case"table":return 64;case"flex":case"-webkit-flex":return 128;case"grid":case"-ms-grid":return 256;case"ruby":return 512;case"subgrid":return 1024;case"list-item":return 2048;case"table-row-group":return 4096;case"table-header-group":return 8192;case"table-footer-group":return 16384;case"table-row":return 32768;case"table-cell":return 65536;case"table-column-group":return 131072;case"table-column":return 262144;case"table-caption":return 524288;case"ruby-base":return 1048576;case"ruby-text":return 2097152;case"ruby-base-container":return 4194304;case"ruby-text-container":return 8388608;case"contents":return 16777216;case"inline-block":return 33554432;case"inline-list-item":return 67108864;case"inline-table":return 134217728;case"inline-flex":return 268435456;case"inline-grid":return 536870912}return 0},hg={name:"float",initialValue:"none",prefix:!1,type:2,parse:function(e,t){switch(t){case"left":return 1;case"right":return 2;case"inline-start":return 3;case"inline-end":return 4}return 0}},dg={name:"letter-spacing",initialValue:"0",prefix:!1,type:0,parse:function(e,t){return 20===t.type&&"normal"===t.value?0:17===t.type||15===t.type?t.number:0}};!function(e){e.NORMAL="normal",e.STRICT="strict"}(Nv||(Nv={}));var pg,fg={name:"line-break",initialValue:"normal",prefix:!1,type:2,parse:function(e,t){return"strict"===t?Nv.STRICT:Nv.NORMAL}},vg={name:"line-height",initialValue:"normal",prefix:!1,type:4},gg=function(e,t){return Wf(e)&&"normal"===e.value?1.2*t:17===e.type?t*e.number:ev(e)?ov(e,t):t},mg={name:"list-style-image",initialValue:"none",type:0,prefix:!1,parse:function(e,t){return 20===t.type&&"none"===t.value?null:Iv(e,t)}},_g={name:"list-style-position",initialValue:"outside",prefix:!1,type:2,parse:function(e,t){return"inside"===t?0:1}},yg={name:"list-style-type",initialValue:"none",prefix:!1,type:2,parse:function(e,t){switch(t){case"disc":return 0;case"circle":return 1;case"square":return 2;case"decimal":return 3;case"cjk-decimal":return 4;case"decimal-leading-zero":return 5;case"lower-roman":return 6;case"upper-roman":return 7;case"lower-greek":return 8;case"lower-alpha":return 9;case"upper-alpha":return 10;case"arabic-indic":return 11;case"armenian":return 12;case"bengali":return 13;case"cambodian":return 14;case"cjk-earthly-branch":return 15;case"cjk-heavenly-stem":return 16;case"cjk-ideographic":return 17;case"devanagari":return 18;case"ethiopic-numeric":return 19;case"georgian":return 20;case"gujarati":return 21;case"gurmukhi":case"hebrew":return 22;case"hiragana":return 23;case"hiragana-iroha":return 24;case"japanese-formal":return 25;case"japanese-informal":return 26;case"kannada":return 27;case"katakana":return 28;case"katakana-iroha":return 29;case"khmer":return 30;case"korean-hangul-formal":return 31;case"korean-hanja-formal":return 32;case"korean-hanja-informal":return 33;case"lao":return 34;case"lower-armenian":return 35;case"malayalam":return 36;case"mongolian":return 37;case"myanmar":return 38;case"oriya":return 39;case"persian":return 40;case"simp-chinese-formal":return 41;case"simp-chinese-informal":return 42;case"tamil":return 43;case"telugu":return 44;case"thai":return 45;case"tibetan":return 46;case"trad-chinese-formal":return 47;case"trad-chinese-informal":return 48;case"upper-armenian":return 49;case"disclosure-open":return 50;case"disclosure-closed":return 51;default:return-1}}},bg=function(e){return{name:"margin-"+e,initialValue:"0",prefix:!1,type:4}},Bg=bg("top"),wg=bg("right"),xg=bg("bottom"),Pg=bg("left"),Cg={name:"overflow",initialValue:"visible",prefix:!1,type:1,parse:function(e,t){return t.filter(Wf).map((function(e){switch(e.value){case"hidden":return 1;case"scroll":return 2;case"clip":return 3;case"auto":return 4;default:return 0}}))}},Mg={name:"overflow-wrap",initialValue:"normal",prefix:!1,type:2,parse:function(e,t){return"break-word"===t?"break-word":"normal"}},Fg=function(e){return{name:"padding-"+e,initialValue:"0",prefix:!1,type:3,format:"length-percentage"}},Eg=Fg("top"),kg=Fg("right"),Ig=Fg("bottom"),Dg=Fg("left"),Sg={name:"text-align",initialValue:"left",prefix:!1,type:2,parse:function(e,t){switch(t){case"right":return 2;case"center":case"justify":return 1;default:return 0}}},Tg={name:"position",initialValue:"static",prefix:!1,type:2,parse:function(e,t){switch(t){case"relative":return 1;case"absolute":return 2;case"fixed":return 3;case"sticky":return 4}return 0}},Rg={name:"text-shadow",initialValue:"none",type:1,prefix:!1,parse:function(e,t){return 1===t.length&&Xf(t[0],"none")?[]:Zf(t).map((function(t){for(var i={color:bv.TRANSPARENT,offsetX:iv,offsetY:iv,blur:iv},s=0,r=0;r1?1:0],this.overflowWrap=pm(e,Mg,t.overflowWrap),this.paddingTop=pm(e,Eg,t.paddingTop),this.paddingRight=pm(e,kg,t.paddingRight),this.paddingBottom=pm(e,Ig,t.paddingBottom),this.paddingLeft=pm(e,Dg,t.paddingLeft),this.paintOrder=pm(e,lm,t.paintOrder),this.position=pm(e,Tg,t.position),this.textAlign=pm(e,Sg,t.textAlign),this.textDecorationColor=pm(e,Kg,null!==(i=t.textDecorationColor)&&void 0!==i?i:t.color),this.textDecorationLine=pm(e,Xg,null!==(s=t.textDecorationLine)&&void 0!==s?s:t.textDecoration),this.textShadow=pm(e,Rg,t.textShadow),this.textTransform=pm(e,Lg,t.textTransform),this.transform=pm(e,Ug,t.transform),this.transformOrigin=pm(e,Vg,t.transformOrigin),this.visibility=pm(e,Hg,t.visibility),this.webkitTextStrokeColor=pm(e,um,t.webkitTextStrokeColor),this.webkitTextStrokeWidth=pm(e,Am,t.webkitTextStrokeWidth),this.wordBreak=pm(e,jg,t.wordBreak),this.zIndex=pm(e,Gg,t.zIndex)}return e.prototype.isVisible=function(){return this.display>0&&this.opacity>0&&0===this.visibility},e.prototype.isTransparent=function(){return hv(this.backgroundColor)},e.prototype.isTransformed=function(){return null!==this.transform},e.prototype.isPositioned=function(){return 0!==this.position},e.prototype.isPositionedWithZIndex=function(){return this.isPositioned()&&!this.zIndex.auto},e.prototype.isFloating=function(){return 0!==this.float},e.prototype.isInlineLevel=function(){return em(this.display,4)||em(this.display,33554432)||em(this.display,268435456)||em(this.display,536870912)||em(this.display,67108864)||em(this.display,134217728)},e}(),hm=function(e,t){this.content=pm(e,tm,t.content),this.quotes=pm(e,nm,t.quotes)},dm=function(e,t){this.counterIncrement=pm(e,im,t.counterIncrement),this.counterReset=pm(e,sm,t.counterReset)},pm=function(e,t,i){var s=new Hf,r=null!=i?i.toString():t.initialValue;s.write(r);var n=new jf(s.read());switch(t.type){case 2:var o=n.parseComponentValue();return t.parse(e,Wf(o)?o.value:t.initialValue);case 0:return t.parse(e,n.parseComponentValue());case 1:return t.parse(e,n.parseComponentValues());case 4:return n.parseComponentValue();case 3:switch(t.format){case"angle":return av(e,n.parseComponentValue());case"color":return cv(e,n.parseComponentValue());case"image":return Iv(e,n.parseComponentValue());case"length":var a=n.parseComponentValue();return $f(a)?a:iv;case"length-percentage":var l=n.parseComponentValue();return ev(l)?l:iv;case"time":return zg(e,n.parseComponentValue())}}},fm=function(e,t){var i=function(e){switch(e.getAttribute("data-html2canvas-debug")){case"all":return 1;case"clone":return 2;case"parse":return 3;case"render":return 4;default:return 0}}(e);return 1===i||t===i},vm=function(e,t){this.context=e,this.textNodes=[],this.elements=[],this.flags=0,fm(t,3),this.styles=new cm(e,window.getComputedStyle(t,null)),v_(t)&&(this.styles.animationDuration.some((function(e){return e>0}))&&(t.style.animationDuration="0s"),null!==this.styles.transform&&(t.style.transform="none")),this.bounds=hp(this.context,t),fm(t,4)&&(this.flags|=16)},gm="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",mm="undefined"==typeof Uint8Array?[]:new Uint8Array(256),_m=0;_m=0){if(e<55296||e>56319&&e<=65535)return t=((t=this.index[e>>5])<<2)+(31&e),this.data[t];if(e<=65535)return t=((t=this.index[2048+(e-55296>>5)])<<2)+(31&e),this.data[t];if(e>11),t=this.index[t],t+=e>>5&63,t=((t=this.index[t])<<2)+(31&e),this.data[t];if(e<=1114111)return this.data[this.highValueIndex]}return this.errorValue},e}(),Bm="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",wm="undefined"==typeof Uint8Array?[]:new Uint8Array(256),xm=0;xm>10),o%1024+56320)),(r+1===i||s.length>16384)&&(n+=String.fromCharCode.apply(String,s),s.length=0)}return n},Im=function(e,t){var i,s,r,n=function(e){var t,i,s,r,n,o=.75*e.length,a=e.length,l=0;"="===e[e.length-1]&&(o--,"="===e[e.length-2]&&o--);var u="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof Uint8Array&&void 0!==Uint8Array.prototype.slice?new ArrayBuffer(o):new Array(o),A=Array.isArray(u)?u:new Uint8Array(u);for(t=0;t>4,A[l++]=(15&s)<<4|r>>2,A[l++]=(3&r)<<6|63&n;return u}(e),o=Array.isArray(n)?function(e){for(var t=e.length,i=[],s=0;s=55296&&r<=56319&&i=i)return{done:!0,value:null};for(var e="×";so.x||r.y>o.y;return o=r,0===t||a}));return e.body.removeChild(t),a}(document);return Object.defineProperty(Om,"SUPPORT_WORD_BREAKING",{value:e}),e},get SUPPORT_SVG_DRAWING(){var e=function(e){var t=new Image,i=e.createElement("canvas"),s=i.getContext("2d");if(!s)return!1;t.src="data:image/svg+xml,";try{s.drawImage(t,0,0),i.toDataURL()}catch(e){return!1}return!0}(document);return Object.defineProperty(Om,"SUPPORT_SVG_DRAWING",{value:e}),e},get SUPPORT_FOREIGNOBJECT_DRAWING(){var e="function"==typeof Array.from&&"function"==typeof window.fetch?function(e){var t=e.createElement("canvas"),i=100;t.width=i,t.height=i;var s=t.getContext("2d");if(!s)return Promise.reject(!1);s.fillStyle="rgb(0, 255, 0)",s.fillRect(0,0,i,i);var r=new Image,n=t.toDataURL();r.src=n;var o=Lm(i,i,0,0,r);return s.fillStyle="red",s.fillRect(0,0,i,i),Um(o).then((function(t){s.drawImage(t,0,0);var r=s.getImageData(0,0,i,i).data;s.fillStyle="red",s.fillRect(0,0,i,i);var o=e.createElement("div");return o.style.backgroundImage="url("+n+")",o.style.height="100px",Rm(r)?Um(Lm(i,i,0,0,o)):Promise.reject(!1)})).then((function(e){return s.drawImage(e,0,0),Rm(s.getImageData(0,0,i,i).data)})).catch((function(){return!1}))}(document):Promise.resolve(!1);return Object.defineProperty(Om,"SUPPORT_FOREIGNOBJECT_DRAWING",{value:e}),e},get SUPPORT_CORS_IMAGES(){var e=void 0!==(new Image).crossOrigin;return Object.defineProperty(Om,"SUPPORT_CORS_IMAGES",{value:e}),e},get SUPPORT_RESPONSE_TYPE(){var e="string"==typeof(new XMLHttpRequest).responseType;return Object.defineProperty(Om,"SUPPORT_RESPONSE_TYPE",{value:e}),e},get SUPPORT_CORS_XHR(){var e="withCredentials"in new XMLHttpRequest;return Object.defineProperty(Om,"SUPPORT_CORS_XHR",{value:e}),e},get SUPPORT_NATIVE_TEXT_SEGMENTATION(){var e=!("undefined"==typeof Intl||!Intl.Segmenter);return Object.defineProperty(Om,"SUPPORT_NATIVE_TEXT_SEGMENTATION",{value:e}),e}},Nm=function(e,t){this.text=e,this.bounds=t},Qm=function(e,t){var i=t.ownerDocument;if(i){var s=i.createElement("html2canvaswrapper");s.appendChild(t.cloneNode(!0));var r=t.parentNode;if(r){r.replaceChild(s,t);var n=hp(e,s);return s.firstChild&&r.replaceChild(s.firstChild,s),n}}return cp.EMPTY},Vm=function(e,t,i){var s=e.ownerDocument;if(!s)throw new Error("Node has no owner document");var r=s.createRange();return r.setStart(e,t),r.setEnd(e,t+i),r},Hm=function(e){if(Om.SUPPORT_NATIVE_TEXT_SEGMENTATION){var t=new Intl.Segmenter(void 0,{granularity:"grapheme"});return Array.from(t.segment(e)).map((function(e){return e.segment}))}return function(e){for(var t,i=Tm(e),s=[];!(t=i.next()).done;)t.value&&s.push(t.value.slice());return s}(e)},jm=function(e,t){return 0!==t.letterSpacing?Hm(e):function(e,t){if(Om.SUPPORT_NATIVE_TEXT_SEGMENTATION){var i=new Intl.Segmenter(void 0,{granularity:"word"});return Array.from(i.segment(e)).map((function(e){return e.segment}))}return zm(e,t)}(e,t)},Gm=[32,160,4961,65792,65793,4153,4241],zm=function(e,t){for(var i,s=function(e,t){var i=dp(e),s=uf(i,t),r=s[0],n=s[1],o=s[2],a=i.length,l=0,u=0;return{next:function(){if(u>=a)return{done:!0,value:null};for(var e="×";u0)if(Om.SUPPORT_RANGE_BOUNDS){var r=Vm(s,o,t.length).getClientRects();if(r.length>1){var a=Hm(t),l=0;a.forEach((function(t){n.push(new Nm(t,cp.fromDOMRectList(e,Vm(s,l+o,t.length).getClientRects()))),l+=t.length}))}else n.push(new Nm(t,cp.fromDOMRectList(e,r)))}else{var u=s.splitText(t.length);n.push(new Nm(t,Qm(e,s))),s=u}else Om.SUPPORT_RANGE_BOUNDS||(s=s.splitText(t.length));o+=t.length})),n}(e,this.text,i,t)},Km=function(e,t){switch(t){case 1:return e.toLowerCase();case 3:return e.replace(Xm,Jm);case 2:return e.toUpperCase();default:return e}},Xm=/(^|\s|:|-|\(|\))([a-z])/g,Jm=function(e,t,i){return e.length>0?t+i.toUpperCase():e},Ym=function(e){function t(t,i){var s=e.call(this,t,i)||this;return s.src=i.currentSrc||i.src,s.intrinsicWidth=i.naturalWidth,s.intrinsicHeight=i.naturalHeight,s.context.cache.addImage(s.src),s}return op(t,e),t}(vm),Zm=function(e){function t(t,i){var s=e.call(this,t,i)||this;return s.canvas=i,s.intrinsicWidth=i.width,s.intrinsicHeight=i.height,s}return op(t,e),t}(vm),qm=function(e){function t(t,i){var s=e.call(this,t,i)||this,r=new XMLSerializer,n=hp(t,i);return i.setAttribute("width",n.width+"px"),i.setAttribute("height",n.height+"px"),s.svg="data:image/svg+xml,"+encodeURIComponent(r.serializeToString(i)),s.intrinsicWidth=i.width.baseVal.value,s.intrinsicHeight=i.height.baseVal.value,s.context.cache.addImage(s.svg),s}return op(t,e),t}(vm),$m=function(e){function t(t,i){var s=e.call(this,t,i)||this;return s.value=i.value,s}return op(t,e),t}(vm),e_=function(e){function t(t,i){var s=e.call(this,t,i)||this;return s.start=i.start,s.reversed="boolean"==typeof i.reversed&&!0===i.reversed,s}return op(t,e),t}(vm),t_=[{type:15,flags:0,unit:"px",number:3}],i_=[{type:16,flags:0,number:50}],s_="password",r_=function(e){function t(t,i){var s,r=e.call(this,t,i)||this;switch(r.type=i.type.toLowerCase(),r.checked=i.checked,r.value=function(e){var t=e.type===s_?new Array(e.value.length+1).join("•"):e.value;return 0===t.length?e.placeholder||"":t}(i),"checkbox"!==r.type&&"radio"!==r.type||(r.styles.backgroundColor=3739148031,r.styles.borderTopColor=r.styles.borderRightColor=r.styles.borderBottomColor=r.styles.borderLeftColor=2779096575,r.styles.borderTopWidth=r.styles.borderRightWidth=r.styles.borderBottomWidth=r.styles.borderLeftWidth=1,r.styles.borderTopStyle=r.styles.borderRightStyle=r.styles.borderBottomStyle=r.styles.borderLeftStyle=1,r.styles.backgroundClip=[0],r.styles.backgroundOrigin=[0],r.bounds=(s=r.bounds).width>s.height?new cp(s.left+(s.width-s.height)/2,s.top,s.height,s.height):s.width0)s.textNodes.push(new Wm(t,n,s.styles));else if(f_(n))if(k_(n)&&n.assignedNodes)n.assignedNodes().forEach((function(i){return e(t,i,s,r)}));else{var a=A_(t,n);a.styles.isVisible()&&(h_(n,a,r)?a.flags|=4:d_(a.styles)&&(a.flags|=2),-1!==l_.indexOf(n.tagName)&&(a.flags|=8),s.elements.push(a),n.slot,n.shadowRoot?e(t,n.shadowRoot,a,r):F_(n)||b_(n)||E_(n)||e(t,n,a,r))}},A_=function(e,t){return P_(t)?new Ym(e,t):w_(t)?new Zm(e,t):b_(t)?new qm(e,t):m_(t)?new $m(e,t):__(t)?new e_(e,t):y_(t)?new r_(e,t):E_(t)?new n_(e,t):F_(t)?new o_(e,t):C_(t)?new a_(e,t):new vm(e,t)},c_=function(e,t){var i=A_(e,t);return i.flags|=4,u_(e,t,i,i),i},h_=function(e,t,i){return t.styles.isPositionedWithZIndex()||t.styles.opacity<1||t.styles.isTransformed()||B_(e)&&i.styles.isTransparent()},d_=function(e){return e.isPositioned()||e.isFloating()},p_=function(e){return e.nodeType===Node.TEXT_NODE},f_=function(e){return e.nodeType===Node.ELEMENT_NODE},v_=function(e){return f_(e)&&void 0!==e.style&&!g_(e)},g_=function(e){return"object"===w(e.className)},m_=function(e){return"LI"===e.tagName},__=function(e){return"OL"===e.tagName},y_=function(e){return"INPUT"===e.tagName},b_=function(e){return"svg"===e.tagName},B_=function(e){return"BODY"===e.tagName},w_=function(e){return"CANVAS"===e.tagName},x_=function(e){return"VIDEO"===e.tagName},P_=function(e){return"IMG"===e.tagName},C_=function(e){return"IFRAME"===e.tagName},M_=function(e){return"STYLE"===e.tagName},F_=function(e){return"TEXTAREA"===e.tagName},E_=function(e){return"SELECT"===e.tagName},k_=function(e){return"SLOT"===e.tagName},I_=function(e){return e.tagName.indexOf("-")>0},D_=function(){function e(){this.counters={}}return e.prototype.getCounterValue=function(e){var t=this.counters[e];return t&&t.length?t[t.length-1]:1},e.prototype.getCounterValues=function(e){var t=this.counters[e];return t||[]},e.prototype.pop=function(e){var t=this;e.forEach((function(e){return t.counters[e].pop()}))},e.prototype.parse=function(e){var t=this,i=e.counterIncrement,s=e.counterReset,r=!0;null!==i&&i.forEach((function(e){var i=t.counters[e.counter];i&&0!==e.increment&&(r=!1,i.length||i.push(1),i[Math.max(0,i.length-1)]+=e.increment)}));var n=[];return r&&s.forEach((function(e){var i=t.counters[e.counter];n.push(e.counter),i||(i=t.counters[e.counter]=[]),i.push(e.reset)})),n},e}(),S_={integers:[1e3,900,500,400,100,90,50,40,10,9,5,4,1],values:["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]},T_={integers:[9e3,8e3,7e3,6e3,5e3,4e3,3e3,2e3,1e3,900,800,700,600,500,400,300,200,100,90,80,70,60,50,40,30,20,10,9,8,7,6,5,4,3,2,1],values:["Ք","Փ","Ւ","Ց","Ր","Տ","Վ","Ս","Ռ","Ջ","Պ","Չ","Ո","Շ","Ն","Յ","Մ","Ճ","Ղ","Ձ","Հ","Կ","Ծ","Խ","Լ","Ի","Ժ","Թ","Ը","Է","Զ","Ե","Դ","Գ","Բ","Ա"]},R_={integers:[1e4,9e3,8e3,7e3,6e3,5e3,4e3,3e3,2e3,1e3,400,300,200,100,90,80,70,60,50,40,30,20,19,18,17,16,15,10,9,8,7,6,5,4,3,2,1],values:["י׳","ט׳","ח׳","ז׳","ו׳","ה׳","ד׳","ג׳","ב׳","א׳","ת","ש","ר","ק","צ","פ","ע","ס","נ","מ","ל","כ","יט","יח","יז","טז","טו","י","ט","ח","ז","ו","ה","ד","ג","ב","א"]},L_={integers:[1e4,9e3,8e3,7e3,6e3,5e3,4e3,3e3,2e3,1e3,900,800,700,600,500,400,300,200,100,90,80,70,60,50,40,30,20,10,9,8,7,6,5,4,3,2,1],values:["ჵ","ჰ","ჯ","ჴ","ხ","ჭ","წ","ძ","ც","ჩ","შ","ყ","ღ","ქ","ფ","ჳ","ტ","ს","რ","ჟ","პ","ო","ჲ","ნ","მ","ლ","კ","ი","თ","ჱ","ზ","ვ","ე","დ","გ","ბ","ა"]},U_=function(e,t,i,s,r,n){return ei?H_(e,r,n.length>0):s.integers.reduce((function(t,i,r){for(;e>=i;)e-=i,t+=s.values[r];return t}),"")+n},O_=function(e,t,i,s){var r="";do{i||e--,r=s(e)+r,e/=t}while(e*t>=t);return r},N_=function(e,t,i,s,r){var n=i-t+1;return(e<0?"-":"")+(O_(Math.abs(e),n,s,(function(e){return pp(Math.floor(e%n)+t)}))+r)},Q_=function(e,t,i){void 0===i&&(i=". ");var s=t.length;return O_(Math.abs(e),s,!1,(function(e){return t[Math.floor(e%s)]}))+i},V_=function(e,t,i,s,r,n){if(e<-9999||e>9999)return H_(e,4,r.length>0);var o=Math.abs(e),a=r;if(0===o)return t[0]+a;for(var l=0;o>0&&l<=4;l++){var u=o%10;0===u&&em(n,1)&&""!==a?a=t[u]+a:u>1||1===u&&0===l||1===u&&1===l&&em(n,2)||1===u&&1===l&&em(n,4)&&e>100||1===u&&l>1&&em(n,8)?a=t[u]+(l>0?i[l-1]:"")+a:1===u&&l>0&&(a=i[l-1]+a),o=Math.floor(o/10)}return(e<0?s:"")+a},H_=function(e,t,i){var s=i?". ":"",r=i?"、":"",n=i?", ":"",o=i?" ":"";switch(t){case 0:return"•"+o;case 1:return"◦"+o;case 2:return"◾"+o;case 5:var a=N_(e,48,57,!0,s);return a.length<4?"0"+a:a;case 4:return Q_(e,"〇一二三四五六七八九",r);case 6:return U_(e,1,3999,S_,3,s).toLowerCase();case 7:return U_(e,1,3999,S_,3,s);case 8:return N_(e,945,969,!1,s);case 9:return N_(e,97,122,!1,s);case 10:return N_(e,65,90,!1,s);case 11:return N_(e,1632,1641,!0,s);case 12:case 49:return U_(e,1,9999,T_,3,s);case 35:return U_(e,1,9999,T_,3,s).toLowerCase();case 13:return N_(e,2534,2543,!0,s);case 14:case 30:return N_(e,6112,6121,!0,s);case 15:return Q_(e,"子丑寅卯辰巳午未申酉戌亥",r);case 16:return Q_(e,"甲乙丙丁戊己庚辛壬癸",r);case 17:case 48:return V_(e,"零一二三四五六七八九","十百千萬","負",r,14);case 47:return V_(e,"零壹貳參肆伍陸柒捌玖","拾佰仟萬","負",r,15);case 42:return V_(e,"零一二三四五六七八九","十百千萬","负",r,14);case 41:return V_(e,"零壹贰叁肆伍陆柒捌玖","拾佰仟萬","负",r,15);case 26:return V_(e,"〇一二三四五六七八九","十百千万","マイナス",r,0);case 25:return V_(e,"零壱弐参四伍六七八九","拾百千万","マイナス",r,7);case 31:return V_(e,"영일이삼사오육칠팔구","십백천만","마이너스",n,7);case 33:return V_(e,"零一二三四五六七八九","十百千萬","마이너스",n,0);case 32:return V_(e,"零壹貳參四五六七八九","拾百千","마이너스",n,7);case 18:return N_(e,2406,2415,!0,s);case 20:return U_(e,1,19999,L_,3,s);case 21:return N_(e,2790,2799,!0,s);case 22:return N_(e,2662,2671,!0,s);case 22:return U_(e,1,10999,R_,3,s);case 23:return Q_(e,"あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわゐゑをん");case 24:return Q_(e,"いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす");case 27:return N_(e,3302,3311,!0,s);case 28:return Q_(e,"アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヰヱヲン",r);case 29:return Q_(e,"イロハニホヘトチリヌルヲワカヨタレソツネナラムウヰノオクヤマケフコエテアサキユメミシヱヒモセス",r);case 34:return N_(e,3792,3801,!0,s);case 37:return N_(e,6160,6169,!0,s);case 38:return N_(e,4160,4169,!0,s);case 39:return N_(e,2918,2927,!0,s);case 40:return N_(e,1776,1785,!0,s);case 43:return N_(e,3046,3055,!0,s);case 44:return N_(e,3174,3183,!0,s);case 45:return N_(e,3664,3673,!0,s);case 46:return N_(e,3872,3881,!0,s);default:return N_(e,48,57,!0,s)}},j_=function(){function e(e,t,i){if(this.context=e,this.options=i,this.scrolledElements=[],this.referenceElement=t,this.counters=new D_,this.quoteDepth=0,!t.ownerDocument)throw new Error("Cloned element does not have an owner document");this.documentElement=this.cloneNode(t.ownerDocument.documentElement,!1)}return e.prototype.toIFrame=function(e,t){var i=this,s=z_(e,t);if(!s.contentWindow)return Promise.reject("Unable to find iframe window");var r=e.defaultView.pageXOffset,n=e.defaultView.pageYOffset,o=s.contentWindow,a=o.document,l=X_(s).then((function(){return lp(i,void 0,void 0,(function(){var e,i;return up(this,(function(r){switch(r.label){case 0:return this.scrolledElements.forEach($_),o&&(o.scrollTo(t.left,t.top),!/(iPad|iPhone|iPod)/g.test(navigator.userAgent)||o.scrollY===t.top&&o.scrollX===t.left||(this.context.logger.warn("Unable to restore scroll position for cloned document"),this.context.windowBounds=this.context.windowBounds.add(o.scrollX-t.left,o.scrollY-t.top,0,0))),e=this.options.onclone,void 0===(i=this.clonedReferenceElement)?[2,Promise.reject("Error finding the "+this.referenceElement.nodeName+" in the cloned document")]:a.fonts&&a.fonts.ready?[4,a.fonts.ready]:[3,2];case 1:r.sent(),r.label=2;case 2:return/(AppleWebKit)/g.test(navigator.userAgent)?[4,K_(a)]:[3,4];case 3:r.sent(),r.label=4;case 4:return"function"==typeof e?[2,Promise.resolve().then((function(){return e(a,i)})).then((function(){return s}))]:[2,s]}}))}))}));return a.open(),a.write(Z_(document.doctype)+""),q_(this.referenceElement.ownerDocument,r,n),a.replaceChild(a.adoptNode(this.documentElement),a.documentElement),a.close(),l},e.prototype.createElementClone=function(e){if(fm(e,2),w_(e))return this.createCanvasClone(e);if(x_(e))return this.createVideoClone(e);if(M_(e))return this.createStyleClone(e);var t=e.cloneNode(!1);return P_(t)&&(P_(e)&&e.currentSrc&&e.currentSrc!==e.src&&(t.src=e.currentSrc,t.srcset=""),"lazy"===t.loading&&(t.loading="eager")),I_(t)?this.createCustomElementClone(t):t},e.prototype.createCustomElementClone=function(e){var t=document.createElement("html2canvascustomelement");return Y_(e.style,t),t},e.prototype.createStyleClone=function(e){try{var t=e.sheet;if(t&&t.cssRules){var i=[].slice.call(t.cssRules,0).reduce((function(e,t){return t&&"string"==typeof t.cssText?e+t.cssText:e}),""),s=e.cloneNode(!1);return s.textContent=i,s}}catch(e){if(this.context.logger.error("Unable to access cssRules property",e),"SecurityError"!==e.name)throw e}return e.cloneNode(!1)},e.prototype.createCanvasClone=function(e){var t;if(this.options.inlineImages&&e.ownerDocument){var i=e.ownerDocument.createElement("img");try{return i.src=e.toDataURL(),i}catch(t){this.context.logger.info("Unable to inline canvas contents, canvas is tainted",e)}}var s=e.cloneNode(!1);try{s.width=e.width,s.height=e.height;var r=e.getContext("2d"),n=s.getContext("2d");if(n)if(!this.options.allowTaint&&r)n.putImageData(r.getImageData(0,0,e.width,e.height),0,0);else{var o=null!==(t=e.getContext("webgl2"))&&void 0!==t?t:e.getContext("webgl");if(o){var a=o.getContextAttributes();!1===(null==a?void 0:a.preserveDrawingBuffer)&&this.context.logger.warn("Unable to clone WebGL context as it has preserveDrawingBuffer=false",e)}n.drawImage(e,0,0)}return s}catch(t){this.context.logger.info("Unable to clone canvas as it is tainted",e)}return s},e.prototype.createVideoClone=function(e){var t=e.ownerDocument.createElement("canvas");t.width=e.offsetWidth,t.height=e.offsetHeight;var i=t.getContext("2d");try{return i&&(i.drawImage(e,0,0,t.width,t.height),this.options.allowTaint||i.getImageData(0,0,t.width,t.height)),t}catch(t){this.context.logger.info("Unable to clone video as it is tainted",e)}var s=e.ownerDocument.createElement("canvas");return s.width=e.offsetWidth,s.height=e.offsetHeight,s},e.prototype.appendChildNode=function(e,t,i){f_(t)&&(function(e){return"SCRIPT"===e.tagName}(t)||t.hasAttribute("data-html2canvas-ignore")||"function"==typeof this.options.ignoreElements&&this.options.ignoreElements(t))||this.options.copyStyles&&f_(t)&&M_(t)||e.appendChild(this.cloneNode(t,i))},e.prototype.cloneChildNodes=function(e,t,i){for(var s=this,r=e.shadowRoot?e.shadowRoot.firstChild:e.firstChild;r;r=r.nextSibling)if(f_(r)&&k_(r)&&"function"==typeof r.assignedNodes){var n=r.assignedNodes();n.length&&n.forEach((function(e){return s.appendChildNode(t,e,i)}))}else this.appendChildNode(t,r,i)},e.prototype.cloneNode=function(e,t){if(p_(e))return document.createTextNode(e.data);if(!e.ownerDocument)return e.cloneNode(!1);var i=e.ownerDocument.defaultView;if(i&&f_(e)&&(v_(e)||g_(e))){var s=this.createElementClone(e);s.style.transitionProperty="none";var r=i.getComputedStyle(e),n=i.getComputedStyle(e,":before"),o=i.getComputedStyle(e,":after");this.referenceElement===e&&v_(s)&&(this.clonedReferenceElement=s),B_(s)&&iy(s);var a=this.counters.parse(new dm(this.context,r)),l=this.resolvePseudoContent(e,s,n,Pm.BEFORE);I_(e)&&(t=!0),x_(e)||this.cloneChildNodes(e,s,t),l&&s.insertBefore(l,s.firstChild);var u=this.resolvePseudoContent(e,s,o,Pm.AFTER);return u&&s.appendChild(u),this.counters.pop(a),(r&&(this.options.copyStyles||g_(e))&&!C_(e)||t)&&Y_(r,s),0===e.scrollTop&&0===e.scrollLeft||this.scrolledElements.push([s,e.scrollLeft,e.scrollTop]),(F_(e)||E_(e))&&(F_(s)||E_(s))&&(s.value=e.value),s}return e.cloneNode(!1)},e.prototype.resolvePseudoContent=function(e,t,i,s){var r=this;if(i){var n=i.content,o=t.ownerDocument;if(o&&n&&"none"!==n&&"-moz-alt-content"!==n&&"none"!==i.display){this.counters.parse(new dm(this.context,i));var a=new hm(this.context,i),l=o.createElement("html2canvaspseudoelement");Y_(i,l),a.content.forEach((function(t){if(0===t.type)l.appendChild(o.createTextNode(t.value));else if(22===t.type){var i=o.createElement("img");i.src=t.value,i.style.opacity="1",l.appendChild(i)}else if(18===t.type){if("attr"===t.name){var s=t.values.filter(Wf);s.length&&l.appendChild(o.createTextNode(e.getAttribute(s[0].value)||""))}else if("counter"===t.name){var n=t.values.filter(Yf),u=n[0],A=n[1];if(u&&Wf(u)){var c=r.counters.getCounterValue(u.value),h=A&&Wf(A)?yg.parse(r.context,A.value):3;l.appendChild(o.createTextNode(H_(c,h,!1)))}}else if("counters"===t.name){var d=t.values.filter(Yf),p=(u=d[0],d[1]);A=d[2];if(u&&Wf(u)){var f=r.counters.getCounterValues(u.value),v=A&&Wf(A)?yg.parse(r.context,A.value):3,g=p&&0===p.type?p.value:"",m=f.map((function(e){return H_(e,v,!1)})).join(g);l.appendChild(o.createTextNode(m))}}}else if(20===t.type)switch(t.value){case"open-quote":l.appendChild(o.createTextNode(om(a.quotes,r.quoteDepth++,!0)));break;case"close-quote":l.appendChild(o.createTextNode(om(a.quotes,--r.quoteDepth,!1)));break;default:l.appendChild(o.createTextNode(t.value))}})),l.className=ey+" "+ty;var u=s===Pm.BEFORE?" "+ey:" "+ty;return g_(t)?t.className.baseValue+=u:t.className+=u,l}}},e.destroy=function(e){return!!e.parentNode&&(e.parentNode.removeChild(e),!0)},e}();!function(e){e[e.BEFORE=0]="BEFORE",e[e.AFTER=1]="AFTER"}(Pm||(Pm={}));var G_,z_=function(e,t){var i=e.createElement("iframe");return i.className="html2canvas-container",i.style.visibility="hidden",i.style.position="fixed",i.style.left="-10000px",i.style.top="0px",i.style.border="0",i.width=t.width.toString(),i.height=t.height.toString(),i.scrolling="no",i.setAttribute("data-html2canvas-ignore","true"),e.body.appendChild(i),i},W_=function(e){return new Promise((function(t){e.complete?t():e.src?(e.onload=t,e.onerror=t):t()}))},K_=function(e){return Promise.all([].slice.call(e.images,0).map(W_))},X_=function(e){return new Promise((function(t,i){var s=e.contentWindow;if(!s)return i("No window assigned for iframe");var r=s.document;s.onload=e.onload=function(){s.onload=e.onload=null;var i=setInterval((function(){r.body.childNodes.length>0&&"complete"===r.readyState&&(clearInterval(i),t(e))}),50)}}))},J_=["all","d","content"],Y_=function(e,t){for(var i=e.length-1;i>=0;i--){var s=e.item(i);-1===J_.indexOf(s)&&t.style.setProperty(s,e.getPropertyValue(s))}return t},Z_=function(e){var t="";return e&&(t+=""),t},q_=function(e,t,i){e&&e.defaultView&&(t!==e.defaultView.pageXOffset||i!==e.defaultView.pageYOffset)&&e.defaultView.scrollTo(t,i)},$_=function(e){var t=e[0],i=e[1],s=e[2];t.scrollLeft=i,t.scrollTop=s},ey="___html2canvas___pseudoelement_before",ty="___html2canvas___pseudoelement_after",iy=function(e){sy(e,"."+ey+':before{\n content: "" !important;\n display: none !important;\n}\n .'+ty+':after{\n content: "" !important;\n display: none !important;\n}')},sy=function(e,t){var i=e.ownerDocument;if(i){var s=i.createElement("style");s.textContent=t,e.appendChild(s)}},ry=function(){function e(){}return e.getOrigin=function(t){var i=e._link;return i?(i.href=t,i.href=i.href,i.protocol+i.hostname+i.port):"about:blank"},e.isSameOrigin=function(t){return e.getOrigin(t)===e._origin},e.setContext=function(t){e._link=t.document.createElement("a"),e._origin=e.getOrigin(t.location.href)},e._origin="about:blank",e}(),ny=function(){function e(e,t){this.context=e,this._options=t,this._cache={}}return e.prototype.addImage=function(e){var t=Promise.resolve();return this.has(e)?t:hy(e)||uy(e)?((this._cache[e]=this.loadImage(e)).catch((function(){})),t):t},e.prototype.match=function(e){return this._cache[e]},e.prototype.loadImage=function(e){return lp(this,void 0,void 0,(function(){var t,i,s,r,n=this;return up(this,(function(o){switch(o.label){case 0:return t=ry.isSameOrigin(e),i=!Ay(e)&&!0===this._options.useCORS&&Om.SUPPORT_CORS_IMAGES&&!t,s=!Ay(e)&&!t&&!hy(e)&&"string"==typeof this._options.proxy&&Om.SUPPORT_CORS_XHR&&!i,t||!1!==this._options.allowTaint||Ay(e)||hy(e)||s||i?(r=e,s?[4,this.proxy(r)]:[3,2]):[2];case 1:r=o.sent(),o.label=2;case 2:return this.context.logger.debug("Added image "+e.substring(0,256)),[4,new Promise((function(e,t){var s=new Image;s.onload=function(){return e(s)},s.onerror=t,(cy(r)||i)&&(s.crossOrigin="anonymous"),s.src=r,!0===s.complete&&setTimeout((function(){return e(s)}),500),n._options.imageTimeout>0&&setTimeout((function(){return t("Timed out ("+n._options.imageTimeout+"ms) loading image")}),n._options.imageTimeout)}))];case 3:return[2,o.sent()]}}))}))},e.prototype.has=function(e){return void 0!==this._cache[e]},e.prototype.keys=function(){return Promise.resolve(Object.keys(this._cache))},e.prototype.proxy=function(e){var t=this,i=this._options.proxy;if(!i)throw new Error("No proxy defined");var s=e.substring(0,256);return new Promise((function(r,n){var o=Om.SUPPORT_RESPONSE_TYPE?"blob":"text",a=new XMLHttpRequest;a.onload=function(){if(200===a.status)if("text"===o)r(a.response);else{var e=new FileReader;e.addEventListener("load",(function(){return r(e.result)}),!1),e.addEventListener("error",(function(e){return n(e)}),!1),e.readAsDataURL(a.response)}else n("Failed to proxy resource "+s+" with status code "+a.status)},a.onerror=n;var l=i.indexOf("?")>-1?"&":"?";if(a.open("GET",""+i+l+"url="+encodeURIComponent(e)+"&responseType="+o),"text"!==o&&a instanceof XMLHttpRequest&&(a.responseType=o),t._options.imageTimeout){var u=t._options.imageTimeout;a.timeout=u,a.ontimeout=function(){return n("Timed out ("+u+"ms) proxying "+s)}}a.send()}))},e}(),oy=/^data:image\/svg\+xml/i,ay=/^data:image\/.*;base64,/i,ly=/^data:image\/.*/i,uy=function(e){return Om.SUPPORT_SVG_DRAWING||!dy(e)},Ay=function(e){return ly.test(e)},cy=function(e){return ay.test(e)},hy=function(e){return"blob"===e.substr(0,4)},dy=function(e){return"svg"===e.substr(-3).toLowerCase()||oy.test(e)},py=function(){function e(e,t){this.type=0,this.x=e,this.y=t}return e.prototype.add=function(t,i){return new e(this.x+t,this.y+i)},e}(),fy=function(e,t,i){return new py(e.x+(t.x-e.x)*i,e.y+(t.y-e.y)*i)},vy=function(){function e(e,t,i,s){this.type=1,this.start=e,this.startControl=t,this.endControl=i,this.end=s}return e.prototype.subdivide=function(t,i){var s=fy(this.start,this.startControl,t),r=fy(this.startControl,this.endControl,t),n=fy(this.endControl,this.end,t),o=fy(s,r,t),a=fy(r,n,t),l=fy(o,a,t);return i?new e(this.start,s,o,l):new e(l,a,n,this.end)},e.prototype.add=function(t,i){return new e(this.start.add(t,i),this.startControl.add(t,i),this.endControl.add(t,i),this.end.add(t,i))},e.prototype.reverse=function(){return new e(this.end,this.endControl,this.startControl,this.start)},e}(),gy=function(e){return 1===e.type},my=function(e){var t=e.styles,i=e.bounds,s=nv(t.borderTopLeftRadius,i.width,i.height),r=s[0],n=s[1],o=nv(t.borderTopRightRadius,i.width,i.height),a=o[0],l=o[1],u=nv(t.borderBottomRightRadius,i.width,i.height),A=u[0],c=u[1],h=nv(t.borderBottomLeftRadius,i.width,i.height),d=h[0],p=h[1],f=[];f.push((r+a)/i.width),f.push((d+A)/i.width),f.push((n+p)/i.height),f.push((l+c)/i.height);var v=Math.max.apply(Math,f);v>1&&(r/=v,n/=v,a/=v,l/=v,A/=v,c/=v,d/=v,p/=v);var g=i.width-a,m=i.height-c,_=i.width-A,y=i.height-p,b=t.borderTopWidth,B=t.borderRightWidth,w=t.borderBottomWidth,x=t.borderLeftWidth,P=ov(t.paddingTop,e.bounds.width),C=ov(t.paddingRight,e.bounds.width),M=ov(t.paddingBottom,e.bounds.width),F=ov(t.paddingLeft,e.bounds.width);this.topLeftBorderDoubleOuterBox=r>0||n>0?_y(i.left+x/3,i.top+b/3,r-x/3,n-b/3,G_.TOP_LEFT):new py(i.left+x/3,i.top+b/3),this.topRightBorderDoubleOuterBox=r>0||n>0?_y(i.left+g,i.top+b/3,a-B/3,l-b/3,G_.TOP_RIGHT):new py(i.left+i.width-B/3,i.top+b/3),this.bottomRightBorderDoubleOuterBox=A>0||c>0?_y(i.left+_,i.top+m,A-B/3,c-w/3,G_.BOTTOM_RIGHT):new py(i.left+i.width-B/3,i.top+i.height-w/3),this.bottomLeftBorderDoubleOuterBox=d>0||p>0?_y(i.left+x/3,i.top+y,d-x/3,p-w/3,G_.BOTTOM_LEFT):new py(i.left+x/3,i.top+i.height-w/3),this.topLeftBorderDoubleInnerBox=r>0||n>0?_y(i.left+2*x/3,i.top+2*b/3,r-2*x/3,n-2*b/3,G_.TOP_LEFT):new py(i.left+2*x/3,i.top+2*b/3),this.topRightBorderDoubleInnerBox=r>0||n>0?_y(i.left+g,i.top+2*b/3,a-2*B/3,l-2*b/3,G_.TOP_RIGHT):new py(i.left+i.width-2*B/3,i.top+2*b/3),this.bottomRightBorderDoubleInnerBox=A>0||c>0?_y(i.left+_,i.top+m,A-2*B/3,c-2*w/3,G_.BOTTOM_RIGHT):new py(i.left+i.width-2*B/3,i.top+i.height-2*w/3),this.bottomLeftBorderDoubleInnerBox=d>0||p>0?_y(i.left+2*x/3,i.top+y,d-2*x/3,p-2*w/3,G_.BOTTOM_LEFT):new py(i.left+2*x/3,i.top+i.height-2*w/3),this.topLeftBorderStroke=r>0||n>0?_y(i.left+x/2,i.top+b/2,r-x/2,n-b/2,G_.TOP_LEFT):new py(i.left+x/2,i.top+b/2),this.topRightBorderStroke=r>0||n>0?_y(i.left+g,i.top+b/2,a-B/2,l-b/2,G_.TOP_RIGHT):new py(i.left+i.width-B/2,i.top+b/2),this.bottomRightBorderStroke=A>0||c>0?_y(i.left+_,i.top+m,A-B/2,c-w/2,G_.BOTTOM_RIGHT):new py(i.left+i.width-B/2,i.top+i.height-w/2),this.bottomLeftBorderStroke=d>0||p>0?_y(i.left+x/2,i.top+y,d-x/2,p-w/2,G_.BOTTOM_LEFT):new py(i.left+x/2,i.top+i.height-w/2),this.topLeftBorderBox=r>0||n>0?_y(i.left,i.top,r,n,G_.TOP_LEFT):new py(i.left,i.top),this.topRightBorderBox=a>0||l>0?_y(i.left+g,i.top,a,l,G_.TOP_RIGHT):new py(i.left+i.width,i.top),this.bottomRightBorderBox=A>0||c>0?_y(i.left+_,i.top+m,A,c,G_.BOTTOM_RIGHT):new py(i.left+i.width,i.top+i.height),this.bottomLeftBorderBox=d>0||p>0?_y(i.left,i.top+y,d,p,G_.BOTTOM_LEFT):new py(i.left,i.top+i.height),this.topLeftPaddingBox=r>0||n>0?_y(i.left+x,i.top+b,Math.max(0,r-x),Math.max(0,n-b),G_.TOP_LEFT):new py(i.left+x,i.top+b),this.topRightPaddingBox=a>0||l>0?_y(i.left+Math.min(g,i.width-B),i.top+b,g>i.width+B?0:Math.max(0,a-B),Math.max(0,l-b),G_.TOP_RIGHT):new py(i.left+i.width-B,i.top+b),this.bottomRightPaddingBox=A>0||c>0?_y(i.left+Math.min(_,i.width-x),i.top+Math.min(m,i.height-w),Math.max(0,A-B),Math.max(0,c-w),G_.BOTTOM_RIGHT):new py(i.left+i.width-B,i.top+i.height-w),this.bottomLeftPaddingBox=d>0||p>0?_y(i.left+x,i.top+Math.min(y,i.height-w),Math.max(0,d-x),Math.max(0,p-w),G_.BOTTOM_LEFT):new py(i.left+x,i.top+i.height-w),this.topLeftContentBox=r>0||n>0?_y(i.left+x+F,i.top+b+P,Math.max(0,r-(x+F)),Math.max(0,n-(b+P)),G_.TOP_LEFT):new py(i.left+x+F,i.top+b+P),this.topRightContentBox=a>0||l>0?_y(i.left+Math.min(g,i.width+x+F),i.top+b+P,g>i.width+x+F?0:a-x+F,l-(b+P),G_.TOP_RIGHT):new py(i.left+i.width-(B+C),i.top+b+P),this.bottomRightContentBox=A>0||c>0?_y(i.left+Math.min(_,i.width-(x+F)),i.top+Math.min(m,i.height+b+P),Math.max(0,A-(B+C)),c-(w+M),G_.BOTTOM_RIGHT):new py(i.left+i.width-(B+C),i.top+i.height-(w+M)),this.bottomLeftContentBox=d>0||p>0?_y(i.left+x+F,i.top+y,Math.max(0,d-(x+F)),p-(w+M),G_.BOTTOM_LEFT):new py(i.left+x+F,i.top+i.height-(w+M))};!function(e){e[e.TOP_LEFT=0]="TOP_LEFT",e[e.TOP_RIGHT=1]="TOP_RIGHT",e[e.BOTTOM_RIGHT=2]="BOTTOM_RIGHT",e[e.BOTTOM_LEFT=3]="BOTTOM_LEFT"}(G_||(G_={}));var _y=function(e,t,i,s,r){var n=(Math.sqrt(2)-1)/3*4,o=i*n,a=s*n,l=e+i,u=t+s;switch(r){case G_.TOP_LEFT:return new vy(new py(e,u),new py(e,u-a),new py(l-o,t),new py(l,t));case G_.TOP_RIGHT:return new vy(new py(e,t),new py(e+o,t),new py(l,u-a),new py(l,u));case G_.BOTTOM_RIGHT:return new vy(new py(l,t),new py(l,t+a),new py(e+o,u),new py(e,u));case G_.BOTTOM_LEFT:default:return new vy(new py(l,u),new py(l-o,u),new py(e,t+a),new py(e,t))}},yy=function(e){return[e.topLeftBorderBox,e.topRightBorderBox,e.bottomRightBorderBox,e.bottomLeftBorderBox]},by=function(e){return[e.topLeftPaddingBox,e.topRightPaddingBox,e.bottomRightPaddingBox,e.bottomLeftPaddingBox]},By=function(e,t,i){this.offsetX=e,this.offsetY=t,this.matrix=i,this.type=0,this.target=6},wy=function(e,t){this.path=e,this.target=t,this.type=1},xy=function(e){this.opacity=e,this.type=2,this.target=6},Py=function(e){return 1===e.type},Cy=function(e,t){return e.length===t.length&&e.some((function(e,i){return e===t[i]}))},My=function(e){this.element=e,this.inlineLevel=[],this.nonInlineLevel=[],this.negativeZIndex=[],this.zeroOrAutoZIndexOrTransformedOrOpacity=[],this.positiveZIndex=[],this.nonPositionedFloats=[],this.nonPositionedInlineLevel=[]},Fy=function(){function e(e,t){if(this.container=e,this.parent=t,this.effects=[],this.curves=new my(this.container),this.container.styles.opacity<1&&this.effects.push(new xy(this.container.styles.opacity)),null!==this.container.styles.transform){var i=this.container.bounds.left+this.container.styles.transformOrigin[0].number,s=this.container.bounds.top+this.container.styles.transformOrigin[1].number,r=this.container.styles.transform;this.effects.push(new By(i,s,r))}if(0!==this.container.styles.overflowX){var n=yy(this.curves),o=by(this.curves);Cy(n,o)?this.effects.push(new wy(n,6)):(this.effects.push(new wy(n,2)),this.effects.push(new wy(o,4)))}}return e.prototype.getEffects=function(e){for(var t=-1===[2,3].indexOf(this.container.styles.position),i=this.parent,s=this.effects.slice(0);i;){var r=i.effects.filter((function(e){return!Py(e)}));if(t||0!==i.container.styles.position||!i.parent){if(s.unshift.apply(s,r),t=-1===[2,3].indexOf(i.container.styles.position),0!==i.container.styles.overflowX){var n=yy(i.curves),o=by(i.curves);Cy(n,o)||s.unshift(new wy(o,6))}}else s.unshift.apply(s,r);i=i.parent}return s.filter((function(t){return em(t.target,e)}))},e}(),Ey=function e(t,i,s,r){t.container.elements.forEach((function(n){var o=em(n.flags,4),a=em(n.flags,2),l=new Fy(n,t);em(n.styles.display,2048)&&r.push(l);var u=em(n.flags,8)?[]:r;if(o||a){var A=o||n.styles.isPositioned()?s:i,c=new My(l);if(n.styles.isPositioned()||n.styles.opacity<1||n.styles.isTransformed()){var h=n.styles.zIndex.order;if(h<0){var d=0;A.negativeZIndex.some((function(e,t){return h>e.element.container.styles.zIndex.order?(d=t,!1):d>0})),A.negativeZIndex.splice(d,0,c)}else if(h>0){var p=0;A.positiveZIndex.some((function(e,t){return h>=e.element.container.styles.zIndex.order?(p=t+1,!1):p>0})),A.positiveZIndex.splice(p,0,c)}else A.zeroOrAutoZIndexOrTransformedOrOpacity.push(c)}else n.styles.isFloating()?A.nonPositionedFloats.push(c):A.nonPositionedInlineLevel.push(c);e(l,c,o?c:s,u)}else n.styles.isInlineLevel()?i.inlineLevel.push(l):i.nonInlineLevel.push(l),e(l,i,s,u);em(n.flags,8)&&ky(n,u)}))},ky=function(e,t){for(var i=e instanceof e_?e.start:1,s=e instanceof e_&&e.reversed,r=0;r0&&e.intrinsicHeight>0){var s=Ly(e),r=by(t);this.path(r),this.ctx.save(),this.ctx.clip(),this.ctx.drawImage(i,0,0,e.intrinsicWidth,e.intrinsicHeight,s.left,s.top,s.width,s.height),this.ctx.restore()}},t.prototype.renderNodeContent=function(e){return lp(this,void 0,void 0,(function(){var i,s,r,n,o,a,l,u,A,c,h,d,p,f,v,g,m,_;return up(this,(function(y){switch(y.label){case 0:this.applyEffects(e.getEffects(4)),i=e.container,s=e.curves,r=i.styles,n=0,o=i.textNodes,y.label=1;case 1:return n0&&w>0&&(g=s.ctx.createPattern(p,"repeat"),s.renderRepeat(_,g,P,C))):function(e){return 2===e.type}(i)&&(m=Uy(e,t,[null,null,null]),_=m[0],y=m[1],b=m[2],B=m[3],w=m[4],x=0===i.position.length?[sv]:i.position,P=ov(x[0],B),C=ov(x[x.length-1],w),M=function(e,t,i,s,r){var n=0,o=0;switch(e.size){case 0:0===e.shape?n=o=Math.min(Math.abs(t),Math.abs(t-s),Math.abs(i),Math.abs(i-r)):1===e.shape&&(n=Math.min(Math.abs(t),Math.abs(t-s)),o=Math.min(Math.abs(i),Math.abs(i-r)));break;case 2:if(0===e.shape)n=o=Math.min(Mv(t,i),Mv(t,i-r),Mv(t-s,i),Mv(t-s,i-r));else if(1===e.shape){var a=Math.min(Math.abs(i),Math.abs(i-r))/Math.min(Math.abs(t),Math.abs(t-s)),l=Fv(s,r,t,i,!0),u=l[0],A=l[1];o=a*(n=Mv(u-t,(A-i)/a))}break;case 1:0===e.shape?n=o=Math.max(Math.abs(t),Math.abs(t-s),Math.abs(i),Math.abs(i-r)):1===e.shape&&(n=Math.max(Math.abs(t),Math.abs(t-s)),o=Math.max(Math.abs(i),Math.abs(i-r)));break;case 3:if(0===e.shape)n=o=Math.max(Mv(t,i),Mv(t,i-r),Mv(t-s,i),Mv(t-s,i-r));else if(1===e.shape){a=Math.max(Math.abs(i),Math.abs(i-r))/Math.max(Math.abs(t),Math.abs(t-s));var c=Fv(s,r,t,i,!1);u=c[0],A=c[1],o=a*(n=Mv(u-t,(A-i)/a))}}return Array.isArray(e.size)&&(n=ov(e.size[0],s),o=2===e.size.length?ov(e.size[1],r):n),[n,o]}(i,P,C,B,w),F=M[0],E=M[1],F>0&&E>0&&(k=s.ctx.createRadialGradient(y+P,b+C,0,y+P,b+C,F),Pv(i.stops,2*F).forEach((function(e){return k.addColorStop(e.stop,dv(e.color))})),s.path(_),s.ctx.fillStyle=k,F!==E?(I=e.bounds.left+.5*e.bounds.width,D=e.bounds.top+.5*e.bounds.height,T=1/(S=E/F),s.ctx.save(),s.ctx.translate(I,D),s.ctx.transform(1,0,0,S,0,0),s.ctx.translate(-I,-D),s.ctx.fillRect(y,T*(b-D)+D,B,w*T),s.ctx.restore()):s.ctx.fill())),R.label=6;case 6:return t--,[2]}}))},s=this,r=0,n=e.styles.backgroundImage.slice(0).reverse(),a.label=1;case 1:return r0?2!==l.style?[3,5]:[4,this.renderDashedDottedBorder(l.color,l.width,n,e.curves,2)]:[3,11]:[3,13];case 4:return A.sent(),[3,11];case 5:return 3!==l.style?[3,7]:[4,this.renderDashedDottedBorder(l.color,l.width,n,e.curves,3)];case 6:return A.sent(),[3,11];case 7:return 4!==l.style?[3,9]:[4,this.renderDoubleBorder(l.color,l.width,n,e.curves)];case 8:return A.sent(),[3,11];case 9:return[4,this.renderSolidBorder(l.color,n,e.curves)];case 10:A.sent(),A.label=11;case 11:n++,A.label=12;case 12:return o++,[3,3];case 13:return[2]}}))}))},t.prototype.renderDashedDottedBorder=function(e,t,i,s,r){return lp(this,void 0,void 0,(function(){var n,o,a,l,u,A,c,h,d,p,f,v,g,m,_,y;return up(this,(function(b){return this.ctx.save(),n=function(e,t){switch(t){case 0:return Sy(e.topLeftBorderStroke,e.topRightBorderStroke);case 1:return Sy(e.topRightBorderStroke,e.bottomRightBorderStroke);case 2:return Sy(e.bottomRightBorderStroke,e.bottomLeftBorderStroke);default:return Sy(e.bottomLeftBorderStroke,e.topLeftBorderStroke)}}(s,i),o=Dy(s,i),2===r&&(this.path(o),this.ctx.clip()),gy(o[0])?(a=o[0].start.x,l=o[0].start.y):(a=o[0].x,l=o[0].y),gy(o[1])?(u=o[1].end.x,A=o[1].end.y):(u=o[1].x,A=o[1].y),c=0===i||2===i?Math.abs(a-u):Math.abs(l-A),this.ctx.beginPath(),3===r?this.formatPath(n):this.formatPath(o.slice(0,2)),h=t<3?3*t:2*t,d=t<3?2*t:t,3===r&&(h=t,d=t),p=!0,c<=2*h?p=!1:c<=2*h+d?(h*=f=c/(2*h+d),d*=f):(v=Math.floor((c+d)/(h+d)),g=(c-v*h)/(v-1),d=(m=(c-(v+1)*h)/v)<=0||Math.abs(d-g)0&&void 0!==arguments[0]?arguments[0]:{},t=!this._snapshotBegun,i=void 0!==e.width&&void 0!==e.height,s=this.scene.canvas.canvas,r=s.clientWidth,n=s.clientHeight,o=e.width?Math.floor(e.width):s.width,a=e.height?Math.floor(e.height):s.height;i&&(s.width=o,s.height=a),this._snapshotBegun||this.beginSnapshot({width:o,height:a}),e.includeGizmos||this.sendToPlugins("snapshotStarting");for(var l={},u=0,A=this._plugins.length;u0&&void 0!==b[0]?b[0]:{},i=!this._snapshotBegun,s=void 0!==t.width&&void 0!==t.height,r=this.scene.canvas.canvas,n=r.clientWidth,o=r.clientHeight,l=t.width?Math.floor(t.width):r.width,u=t.height?Math.floor(t.height):r.height,s&&(r.width=l,r.height=u),this._snapshotBegun||this.beginSnapshot(),t.includeGizmos||this.sendToPlugins("snapshotStarting"),this.scene._renderer.renderSnapshot(),A=this.scene._renderer.readSnapshotAsCanvas(),s&&(r.width=n,r.height=o,this.scene.glRedraw()),c={},h=[],d=0,p=this._plugins.length;d1&&void 0!==arguments[1])||arguments[1],i=arguments.length>2?arguments[2]:void 0,s=i||new Set;if(e){if(Bb(e))s.add(e);else if(Bb(e.buffer))s.add(e.buffer);else if(ArrayBuffer.isView(e));else if(t&&"object"===w(e))for(var r in e)bb(e[r],t,s)}else;return void 0===i?Array.from(s):[]}function Bb(e){return!!e&&(e instanceof ArrayBuffer||("undefined"!=typeof MessagePort&&e instanceof MessagePort||("undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas)))}var wb=function(){},xb=function(){function e(t){x(this,e),fb(this,"name",void 0),fb(this,"source",void 0),fb(this,"url",void 0),fb(this,"terminated",!1),fb(this,"worker",void 0),fb(this,"onMessage",void 0),fb(this,"onError",void 0),fb(this,"_loadableURL","");var i=t.name,s=t.source,r=t.url;lb(s||r),this.name=i,this.source=s,this.url=r,this.onMessage=wb,this.onError=function(e){return console.log(e)},this.worker=cb?this._createBrowserWorker():this._createNodeWorker()}return C(e,[{key:"destroy",value:function(){this.onMessage=wb,this.onError=wb,this.worker.terminate(),this.terminated=!0}},{key:"isRunning",get:function(){return Boolean(this.onMessage)}},{key:"postMessage",value:function(e,t){t=t||bb(e),this.worker.postMessage(e,t)}},{key:"_getErrorFromErrorEvent",value:function(e){var t="Failed to load ";return t+="worker ".concat(this.name," from ").concat(this.url,". "),e.message&&(t+="".concat(e.message," in ")),e.lineno&&(t+=":".concat(e.lineno,":").concat(e.colno)),new Error(t)}},{key:"_createBrowserWorker",value:function(){var e=this;this._loadableURL=_b({source:this.source,url:this.url});var t=new Worker(this._loadableURL,{name:this.name});return t.onmessage=function(t){t.data?e.onMessage(t.data):e.onError(new Error("No data received"))},t.onerror=function(t){e.onError(e._getErrorFromErrorEvent(t)),e.terminated=!0},t.onmessageerror=function(e){return console.error(e)},t}},{key:"_createNodeWorker",value:function(){var e,t=this;if(this.url){var i=this.url.includes(":/")||this.url.startsWith("/")?this.url:"./".concat(this.url);e=new gb(i,{eval:!1})}else{if(!this.source)throw new Error("no worker");e=new gb(this.source,{eval:!0})}return e.on("message",(function(e){t.onMessage(e)})),e.on("error",(function(e){t.onError(e)})),e.on("exit",(function(e){})),e}}],[{key:"isSupported",value:function(){return"undefined"!=typeof Worker&&cb||void 0!==w(gb)}}]),e}(),Pb=function(){function e(t){x(this,e),fb(this,"name","unnamed"),fb(this,"source",void 0),fb(this,"url",void 0),fb(this,"maxConcurrency",1),fb(this,"maxMobileConcurrency",1),fb(this,"onDebug",(function(){})),fb(this,"reuseWorkers",!0),fb(this,"props",{}),fb(this,"jobQueue",[]),fb(this,"idleQueue",[]),fb(this,"count",0),fb(this,"isDestroyed",!1),this.source=t.source,this.url=t.url,this.setProps(t)}var t,i;return C(e,[{key:"destroy",value:function(){this.idleQueue.forEach((function(e){return e.destroy()})),this.isDestroyed=!0}},{key:"setProps",value:function(e){this.props=n(n({},this.props),e),void 0!==e.name&&(this.name=e.name),void 0!==e.maxConcurrency&&(this.maxConcurrency=e.maxConcurrency),void 0!==e.maxMobileConcurrency&&(this.maxMobileConcurrency=e.maxMobileConcurrency),void 0!==e.reuseWorkers&&(this.reuseWorkers=e.reuseWorkers),void 0!==e.onDebug&&(this.onDebug=e.onDebug)}},{key:"startJob",value:(i=u(a().mark((function e(t){var i,s,r,n=this,o=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=o.length>1&&void 0!==o[1]?o[1]:function(e,t,i){return e.done(i)},s=o.length>2&&void 0!==o[2]?o[2]:function(e,t){return e.error(t)},r=new Promise((function(e){return n.jobQueue.push({name:t,onMessage:i,onError:s,onStart:e}),n})),this._startQueuedJob(),e.next=6,r;case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"_startQueuedJob",value:(t=u(a().mark((function e(){var t,i,s;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.jobQueue.length){e.next=2;break}return e.abrupt("return");case 2:if(t=this._getAvailableWorker()){e.next=5;break}return e.abrupt("return");case 5:if(!(i=this.jobQueue.shift())){e.next=18;break}return this.onDebug({message:"Starting job",name:i.name,workerThread:t,backlog:this.jobQueue.length}),s=new vb(i.name,t),t.onMessage=function(e){return i.onMessage(s,e.type,e.payload)},t.onError=function(e){return i.onError(s,e)},i.onStart(s),e.prev=12,e.next=15,s.result;case 15:return e.prev=15,this.returnWorkerToQueue(t),e.finish(15);case 18:case"end":return e.stop()}}),e,this,[[12,,15,18]])}))),function(){return t.apply(this,arguments)})},{key:"returnWorkerToQueue",value:function(e){this.isDestroyed||!this.reuseWorkers||this.count>this._getMaxConcurrency()?(e.destroy(),this.count--):this.idleQueue.push(e),this.isDestroyed||this._startQueuedJob()}},{key:"_getAvailableWorker",value:function(){if(this.idleQueue.length>0)return this.idleQueue.shift()||null;if(this.count0&&void 0!==arguments[0]?arguments[0]:{};return e._workerFarm=e._workerFarm||new e({}),e._workerFarm.setProps(t),e._workerFarm}}]),e}();fb(Mb,"_workerFarm",void 0);function Fb(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=t[e.id]||{},s="".concat(e.id,"-worker.js"),r=i.workerUrl;if(r||"compression"!==e.id||(r=t.workerUrl),"test"===t._workerType&&(r="modules/".concat(e.module,"/dist/").concat(s)),!r){var n=e.version;"latest"===n&&(n="latest");var o=n?"@".concat(n):"";r="https://unpkg.com/@loaders.gl/".concat(e.module).concat(o,"/dist/").concat(s)}return lb(r),r}function Eb(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"3.2.6";lb(e,"no worker provided");var i=e.version;return!(!t||!i)}var kb=Object.freeze({__proto__:null,default:{}}),Ib={};function Db(e){return Sb.apply(this,arguments)}function Sb(){return Sb=u(a().mark((function e(t){var i,s,r=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=r.length>1&&void 0!==r[1]?r[1]:null,s=r.length>2&&void 0!==r[2]?r[2]:{},i&&(t=Tb(t,i,s)),Ib[t]=Ib[t]||Rb(t),e.next=6,Ib[t];case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)}))),Sb.apply(this,arguments)}function Tb(e,t,i){if(e.startsWith("http"))return e;var s=i.modules||{};return s[e]?s[e]:cb?i.CDN?(lb(i.CDN.startsWith("http")),"".concat(i.CDN,"/").concat(t,"@").concat("3.2.6","/dist/libs/").concat(e)):hb?"../src/libs/".concat(e):"modules/".concat(t,"/src/libs/").concat(e):"modules/".concat(t,"/dist/libs/").concat(e)}function Rb(e){return Lb.apply(this,arguments)}function Lb(){return(Lb=u(a().mark((function e(t){var i,s,r;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.endsWith("wasm")){e.next=7;break}return e.next=3,fetch(t);case 3:return i=e.sent,e.next=6,i.arrayBuffer();case 6:return e.abrupt("return",e.sent);case 7:if(cb){e.next=20;break}if(e.prev=8,e.t0=kb&&void 0,!e.t0){e.next=14;break}return e.next=13,(void 0)(t);case 13:e.t0=e.sent;case 14:return e.abrupt("return",e.t0);case 17:return e.prev=17,e.t1=e.catch(8),e.abrupt("return",null);case 20:if(!hb){e.next=22;break}return e.abrupt("return",importScripts(t));case 22:return e.next=24,fetch(t);case 24:return s=e.sent,e.next=27,s.text();case 27:return r=e.sent,e.abrupt("return",Ub(r,t));case 29:case"end":return e.stop()}}),e,null,[[8,17]])})))).apply(this,arguments)}function Ub(e,t){if(cb){if(hb)return eval.call(Ab,e),null;var i=document.createElement("script");i.id=t;try{i.appendChild(document.createTextNode(e))}catch(t){i.text=e}return document.body.appendChild(i),null}}function Ob(e,t){return!!Mb.isSupported()&&(!!(cb||null!=t&&t._nodeWorkers)&&(e.worker&&(null==t?void 0:t.worker)))}function Nb(e,t,i,s,r){return Qb.apply(this,arguments)}function Qb(){return Qb=u(a().mark((function e(t,i,s,r,n){var o,l,u,A,c,h;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=t.id,l=Fb(t,s),u=Mb.getWorkerFarm(s),A=u.getWorkerPool({name:o,url:l}),s=JSON.parse(JSON.stringify(s)),r=JSON.parse(JSON.stringify(r||{})),e.next=8,A.startJob("process-on-worker",Vb.bind(null,n));case 8:return(c=e.sent).postMessage("process",{input:i,options:s,context:r}),e.next=12,c.result;case 12:return h=e.sent,e.next=15,h.result;case 15:return e.abrupt("return",e.sent);case 16:case"end":return e.stop()}}),e)}))),Qb.apply(this,arguments)}function Vb(e,t,i,s){return Hb.apply(this,arguments)}function Hb(){return(Hb=u(a().mark((function e(t,i,s,r){var n,o,l,u,A;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.t0=s,e.next="done"===e.t0?3:"error"===e.t0?5:"process"===e.t0?7:20;break;case 3:return i.done(r),e.abrupt("break",21);case 5:return i.error(new Error(r.error)),e.abrupt("break",21);case 7:return n=r.id,o=r.input,l=r.options,e.prev=8,e.next=11,t(o,l);case 11:u=e.sent,i.postMessage("done",{id:n,result:u}),e.next=19;break;case 15:e.prev=15,e.t1=e.catch(8),A=e.t1 instanceof Error?e.t1.message:"unknown error",i.postMessage("error",{id:n,error:A});case 19:return e.abrupt("break",21);case 20:console.warn("parse-with-worker unknown message ".concat(s));case 21:case"end":return e.stop()}}),e,null,[[8,15]])})))).apply(this,arguments)}function jb(e,t,i){if(e.byteLength<=t+i)return"";for(var s=new DataView(e),r="",n=0;n1&&void 0!==arguments[1]?arguments[1]:5;if("string"==typeof e)return e.slice(0,t);if(ArrayBuffer.isView(e))return jb(e.buffer,e.byteOffset,t);if(e instanceof ArrayBuffer){return jb(e,0,t)}return""}(e),'"'))}}function zb(e){return e&&"object"===w(e)&&e.isBuffer}function Wb(e){if(zb(e))return zb(t=e)?new Uint8Array(t.buffer,t.byteOffset,t.length).slice().buffer:t;var t;if(e instanceof ArrayBuffer)return e;if(ArrayBuffer.isView(e))return 0===e.byteOffset&&e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);if("string"==typeof e){var i=e;return(new TextEncoder).encode(i).buffer}if(e&&"object"===w(e)&&e._toArrayBuffer)return e._toArrayBuffer();throw new Error("toArrayBuffer")}function Kb(){for(var e=arguments.length,t=new Array(e),i=0;i=0),nb(t>0),e+(t-1)&~(t-1)}function Yb(e,t,i){var s;if(e instanceof ArrayBuffer)s=new Uint8Array(e);else{var r=e.byteOffset,n=e.byteLength;s=new Uint8Array(e.buffer||e.arrayBuffer,r,n)}return t.set(s,i),i+Jb(s.byteLength,4)}function Zb(e){return qb.apply(this,arguments)}function qb(){return(qb=u(a().mark((function e(t){var i,s,r,n,o,l,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=[],s=!1,r=!1,e.prev=3,o=I(t);case 5:return e.next=7,o.next();case 7:if(!(s=!(l=e.sent).done)){e.next=13;break}u=l.value,i.push(u);case 10:s=!1,e.next=5;break;case 13:e.next=19;break;case 15:e.prev=15,e.t0=e.catch(3),r=!0,n=e.t0;case 19:if(e.prev=19,e.prev=20,!s||null==o.return){e.next=24;break}return e.next=24,o.return();case 24:if(e.prev=24,!r){e.next=27;break}throw n;case 27:return e.finish(24);case 28:return e.finish(19);case 29:return e.abrupt("return",Kb.apply(void 0,i));case 30:case"end":return e.stop()}}),e,null,[[3,15,19,29],[20,,24,28]])})))).apply(this,arguments)}var $b={};function eB(e){for(var t in $b)if(e.startsWith(t)){var i=$b[t];e=e.replace(t,i)}return e.startsWith("http://")||e.startsWith("https://")||(e="".concat("").concat(e)),e}var tB=function(e){return"function"==typeof e},iB=function(e){return null!==e&&"object"===w(e)},sB=function(e){return iB(e)&&e.constructor==={}.constructor},rB=function(e){return e&&"function"==typeof e[Symbol.iterator]},nB=function(e){return e&&"function"==typeof e[Symbol.asyncIterator]},oB=function(e){return"undefined"!=typeof Response&&e instanceof Response||e&&e.arrayBuffer&&e.text&&e.json},aB=function(e){return"undefined"!=typeof Blob&&e instanceof Blob},lB=function(e){return function(e){return"undefined"!=typeof ReadableStream&&e instanceof ReadableStream||iB(e)&&tB(e.tee)&&tB(e.cancel)&&tB(e.getReader)}(e)||function(e){return iB(e)&&tB(e.read)&&tB(e.pipe)&&function(e){return"boolean"==typeof e}(e.readable)}(e)},uB=/^data:([-\w.]+\/[-\w.+]+)(;|,)/,AB=/^([-\w.]+\/[-\w.+]+)/;function cB(e){var t=AB.exec(e);return t?t[1]:e}function hB(e){var t=uB.exec(e);return t?t[1]:""}var dB=/\?.*/;function pB(e){if(oB(e)){var t=vB(e.url||"");return{url:t,type:cB(e.headers.get("content-type")||"")||hB(t)}}return aB(e)?{url:vB(e.name||""),type:e.type||""}:"string"==typeof e?{url:vB(e),type:hB(e)}:{url:"",type:""}}function fB(e){return oB(e)?e.headers["content-length"]||-1:aB(e)?e.size:"string"==typeof e?e.length:e instanceof ArrayBuffer||ArrayBuffer.isView(e)?e.byteLength:-1}function vB(e){return e.replace(dB,"")}function gB(e){return mB.apply(this,arguments)}function mB(){return(mB=u(a().mark((function e(t){var i,s,r,n,o,l,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!oB(t)){e.next=2;break}return e.abrupt("return",t);case 2:return i={},(s=fB(t))>=0&&(i["content-length"]=String(s)),r=pB(t),n=r.url,(o=r.type)&&(i["content-type"]=o),e.next=9,wB(t);case 9:return(l=e.sent)&&(i["x-first-bytes"]=l),"string"==typeof t&&(t=(new TextEncoder).encode(t)),u=new Response(t,{headers:i}),Object.defineProperty(u,"url",{value:n}),e.abrupt("return",u);case 15:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function _B(e){return yB.apply(this,arguments)}function yB(){return(yB=u(a().mark((function e(t){var i;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.ok){e.next=5;break}return e.next=3,bB(t);case 3:throw i=e.sent,new Error(i);case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function bB(e){return BB.apply(this,arguments)}function BB(){return(BB=u(a().mark((function e(t){var i,s,r;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i="Failed to fetch resource ".concat(t.url," (").concat(t.status,"): "),e.prev=1,s=t.headers.get("Content-Type"),r=t.statusText,!s.includes("application/json")){e.next=11;break}return e.t0=r,e.t1=" ",e.next=9,t.text();case 9:e.t2=e.sent,r=e.t0+=e.t1.concat.call(e.t1,e.t2);case 11:i=(i+=r).length>60?"".concat(i.slice(0,60),"..."):i,e.next=17;break;case 15:e.prev=15,e.t3=e.catch(1);case 17:return e.abrupt("return",i);case 18:case"end":return e.stop()}}),e,null,[[1,15]])})))).apply(this,arguments)}function wB(e){return xB.apply(this,arguments)}function xB(){return(xB=u(a().mark((function e(t){var i,s,r,n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=5,"string"!=typeof t){e.next=3;break}return e.abrupt("return","data:,".concat(t.slice(0,i)));case 3:if(!(t instanceof Blob)){e.next=8;break}return s=t.slice(0,5),e.next=7,new Promise((function(e){var t=new FileReader;t.onload=function(t){var i;return e(null==t||null===(i=t.target)||void 0===i?void 0:i.result)},t.readAsDataURL(s)}));case 7:return e.abrupt("return",e.sent);case 8:if(!(t instanceof ArrayBuffer)){e.next=12;break}return r=t.slice(0,i),n=PB(r),e.abrupt("return","data:base64,".concat(n));case 12:return e.abrupt("return",null);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function PB(e){for(var t="",i=new Uint8Array(e),s=0;s=0)}();function SB(e){try{var t=window[e],i="__storage_test__";return t.setItem(i,i),t.removeItem(i),t}catch(e){return null}}var TB=function(){function e(t,i){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"sessionStorage";x(this,e),this.storage=SB(s),this.id=t,this.config={},Object.assign(this.config,i),this._loadConfiguration()}return C(e,[{key:"getConfiguration",value:function(){return this.config}},{key:"setConfiguration",value:function(e){return this.config={},this.updateConfiguration(e)}},{key:"updateConfiguration",value:function(e){if(Object.assign(this.config,e),this.storage){var t=JSON.stringify(this.config);this.storage.setItem(this.id,t)}return this}},{key:"_loadConfiguration",value:function(){var e={};if(this.storage){var t=this.storage.getItem(this.id);e=t?JSON.parse(t):{}}return Object.assign(this.config,e),this}}]),e}();function RB(e,t,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:600,r=e.src.replace(/\(/g,"%28").replace(/\)/g,"%29");e.width>s&&(i=Math.min(i,s/e.width));var n=e.width*i,o=e.height*i,a=["font-size:1px;","padding:".concat(Math.floor(o/2),"px ").concat(Math.floor(n/2),"px;"),"line-height:".concat(o,"px;"),"background:url(".concat(r,");"),"background-size:".concat(n,"px ").concat(o,"px;"),"color:transparent;"].join("");return["".concat(t," %c+"),a]}var LB={BLACK:30,RED:31,GREEN:32,YELLOW:33,BLUE:34,MAGENTA:35,CYAN:36,WHITE:37,BRIGHT_BLACK:90,BRIGHT_RED:91,BRIGHT_GREEN:92,BRIGHT_YELLOW:93,BRIGHT_BLUE:94,BRIGHT_MAGENTA:95,BRIGHT_CYAN:96,BRIGHT_WHITE:97};function UB(e){return"string"==typeof e?LB[e.toUpperCase()]||LB.WHITE:e}function OB(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:["constructor"],s=Object.getPrototypeOf(e),r=Object.getOwnPropertyNames(s),n=c(r);try{var o=function(){var s=t.value;"function"==typeof e[s]&&(i.find((function(e){return s===e}))||(e[s]=e[s].bind(e)))};for(n.s();!(t=n.n()).done;)o()}catch(e){n.e(e)}finally{n.f()}}function NB(e,t){if(!e)throw new Error(t||"Assertion failed")}function QB(){var e;if(DB&&EB.performance)e=EB.performance.now();else if(kB.hrtime){var t=kB.hrtime();e=1e3*t[0]+t[1]/1e6}else e=Date.now();return e}var VB={debug:DB&&console.debug||console.log,log:console.log,info:console.info,warn:console.warn,error:console.error},HB={enabled:!0,level:0};function jB(){}var GB={},zB={once:!0};function WB(e){for(var t in e)for(var i in e[t])return i||"untitled";return"empty"}var KB=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{id:""},i=t.id;x(this,e),this.id=i,this.VERSION=IB,this._startTs=QB(),this._deltaTs=QB(),this.LOG_THROTTLE_TIMEOUT=0,this._storage=new TB("__probe-".concat(this.id,"__"),HB),this.userData={},this.timeStamp("".concat(this.id," started")),OB(this),Object.seal(this)}return C(e,[{key:"level",get:function(){return this.getLevel()},set:function(e){this.setLevel(e)}},{key:"isEnabled",value:function(){return this._storage.config.enabled}},{key:"getLevel",value:function(){return this._storage.config.level}},{key:"getTotal",value:function(){return Number((QB()-this._startTs).toPrecision(10))}},{key:"getDelta",value:function(){return Number((QB()-this._deltaTs).toPrecision(10))}},{key:"priority",get:function(){return this.level},set:function(e){this.level=e}},{key:"getPriority",value:function(){return this.level}},{key:"enable",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this._storage.updateConfiguration({enabled:e}),this}},{key:"setLevel",value:function(e){return this._storage.updateConfiguration({level:e}),this}},{key:"assert",value:function(e,t){NB(e,t)}},{key:"warn",value:function(e){return this._getLogFunction(0,e,VB.warn,arguments,zB)}},{key:"error",value:function(e){return this._getLogFunction(0,e,VB.error,arguments)}},{key:"deprecated",value:function(e,t){return this.warn("`".concat(e,"` is deprecated and will be removed in a later version. Use `").concat(t,"` instead"))}},{key:"removed",value:function(e,t){return this.error("`".concat(e,"` has been removed. Use `").concat(t,"` instead"))}},{key:"probe",value:function(e,t){return this._getLogFunction(e,t,VB.log,arguments,{time:!0,once:!0})}},{key:"log",value:function(e,t){return this._getLogFunction(e,t,VB.debug,arguments)}},{key:"info",value:function(e,t){return this._getLogFunction(e,t,console.info,arguments)}},{key:"once",value:function(e,t){return this._getLogFunction(e,t,VB.debug||VB.info,arguments,zB)}},{key:"table",value:function(e,t,i){return t?this._getLogFunction(e,t,console.table||jB,i&&[i],{tag:WB(t)}):jB}},{key:"image",value:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}((function(e){var t=e.logLevel,i=e.priority,s=e.image,r=e.message,n=void 0===r?"":r,o=e.scale,a=void 0===o?1:o;return this._shouldLog(t||i)?DB?function(e){var t=e.image,i=e.message,s=void 0===i?"":i,r=e.scale,n=void 0===r?1:r;if("string"==typeof t){var o=new Image;return o.onload=function(){var e,t=RB(o,s,n);(e=console).log.apply(e,A(t))},o.src=t,jB}var a=t.nodeName||"";if("img"===a.toLowerCase()){var l;return(l=console).log.apply(l,A(RB(t,s,n))),jB}if("canvas"===a.toLowerCase()){var u=new Image;return u.onload=function(){var e;return(e=console).log.apply(e,A(RB(u,s,n)))},u.src=t.toDataURL(),jB}return jB}({image:s,message:n,scale:a}):function(e){var t=e.image,i=(e.message,e.scale),s=void 0===i?1:i,r=null;try{r=module.require("asciify-image")}catch(e){}if(r)return function(){return r(t,{fit:"box",width:"".concat(Math.round(80*s),"%")}).then((function(e){return console.log(e)}))};return jB}({image:s,message:n,scale:a}):jB}))},{key:"settings",value:function(){console.table?console.table(this._storage.config):console.log(this._storage.config)}},{key:"get",value:function(e){return this._storage.config[e]}},{key:"set",value:function(e,t){this._storage.updateConfiguration(o({},e,t))}},{key:"time",value:function(e,t){return this._getLogFunction(e,t,console.time?console.time:console.info)}},{key:"timeEnd",value:function(e,t){return this._getLogFunction(e,t,console.timeEnd?console.timeEnd:console.info)}},{key:"timeStamp",value:function(e,t){return this._getLogFunction(e,t,console.timeStamp||jB)}},{key:"group",value:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{collapsed:!1},s=i=JB({logLevel:e,message:t,opts:i}),r=s.collapsed;return i.method=(r?console.groupCollapsed:console.group)||console.info,this._getLogFunction(i)}},{key:"groupCollapsed",value:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.group(e,t,Object.assign({},i,{collapsed:!0}))}},{key:"groupEnd",value:function(e){return this._getLogFunction(e,"",console.groupEnd||jB)}},{key:"withGroup",value:function(e,t,i){this.group(e,t)();try{i()}finally{this.groupEnd(e)()}}},{key:"trace",value:function(){console.trace&&console.trace()}},{key:"_shouldLog",value:function(e){return this.isEnabled()&&this.getLevel()>=XB(e)}},{key:"_getLogFunction",value:function(e,t,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],r=arguments.length>4?arguments[4]:void 0;if(this._shouldLog(e)){var n;r=JB({logLevel:e,message:t,args:s,opts:r}),NB(i=i||r.method),r.total=this.getTotal(),r.delta=this.getDelta(),this._deltaTs=QB();var o=r.tag||r.message;if(r.once){if(GB[o])return jB;GB[o]=QB()}return t=YB(this.id,r.message,r),(n=i).bind.apply(n,[console,t].concat(A(r.args)))}return jB}}]),e}();function XB(e){if(!e)return 0;var t;switch(w(e)){case"number":t=e;break;case"object":t=e.logLevel||e.priority||0;break;default:return 0}return NB(Number.isFinite(t)&&t>=0),t}function JB(e){var t=e.logLevel,i=e.message;e.logLevel=XB(t);for(var s=e.args?Array.from(e.args):[];s.length&&s.shift()!==i;);switch(e.args=s,w(t)){case"string":case"function":void 0!==i&&s.unshift(i),e.message=t;break;case"object":Object.assign(e,t)}"function"==typeof e.message&&(e.message=e.message());var r=w(e.message);return NB("string"===r||"object"===r),Object.assign(e,e.opts)}function YB(e,t,i){if("string"==typeof t){var s=i.time?function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,i=Math.max(t-e.length,0);return"".concat(" ".repeat(i)).concat(e)}((r=i.total)<10?"".concat(r.toFixed(2),"ms"):r<100?"".concat(r.toFixed(1),"ms"):r<1e3?"".concat(r.toFixed(0),"ms"):"".concat((r/1e3).toFixed(2),"s")):"";t=function(e,t,i){return DB||"string"!=typeof e||(t&&(t=UB(t),e="[".concat(t,"m").concat(e,"")),i&&(t=UB(i),e="[".concat(i+10,"m").concat(e,""))),e}(t=i.time?"".concat(e,": ").concat(s," ").concat(t):"".concat(e,": ").concat(t),i.color,i.background)}var r;return t}KB.VERSION=IB;var ZB=new KB({id:"loaders.gl"}),qB=function(){function e(){x(this,e)}return C(e,[{key:"log",value:function(){return function(){}}},{key:"info",value:function(){return function(){}}},{key:"warn",value:function(){return function(){}}},{key:"error",value:function(){return function(){}}}]),e}(),$B={fetch:null,mimeType:void 0,nothrow:!1,log:new(function(){function e(){x(this,e),fb(this,"console",void 0),this.console=console}return C(e,[{key:"log",value:function(){for(var e,t=arguments.length,i=new Array(t),s=0;s=0)}()}var hw={self:"undefined"!=typeof self&&self,window:"undefined"!=typeof window&&window,global:"undefined"!=typeof global&&global,document:"undefined"!=typeof document&&document,process:"object"===("undefined"==typeof process?"undefined":w(process))&&process},dw=hw.window||hw.self||hw.global,pw=hw.process||{},fw="undefined"!=typeof __VERSION__?__VERSION__:"untranspiled source";function vw(e){try{var t=window[e],i="__storage_test__";return t.setItem(i,i),t.removeItem(i),t}catch(e){return null}}cw();var gw,mw=function(){function e(t){x(this,e);var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"sessionStorage";fb(this,"storage",void 0),fb(this,"id",void 0),fb(this,"config",{}),this.storage=vw(s),this.id=t,this.config={},Object.assign(this.config,i),this._loadConfiguration()}return C(e,[{key:"getConfiguration",value:function(){return this.config}},{key:"setConfiguration",value:function(e){return this.config={},this.updateConfiguration(e)}},{key:"updateConfiguration",value:function(e){if(Object.assign(this.config,e),this.storage){var t=JSON.stringify(this.config);this.storage.setItem(this.id,t)}return this}},{key:"_loadConfiguration",value:function(){var e={};if(this.storage){var t=this.storage.getItem(this.id);e=t?JSON.parse(t):{}}return Object.assign(this.config,e),this}}]),e}();function _w(e,t,i){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:600,r=e.src.replace(/\(/g,"%28").replace(/\)/g,"%29");e.width>s&&(i=Math.min(i,s/e.width));var n=e.width*i,o=e.height*i,a=["font-size:1px;","padding:".concat(Math.floor(o/2),"px ").concat(Math.floor(n/2),"px;"),"line-height:".concat(o,"px;"),"background:url(".concat(r,");"),"background-size:".concat(n,"px ").concat(o,"px;"),"color:transparent;"].join("");return["".concat(t," %c+"),a]}function yw(e){return"string"==typeof e?gw[e.toUpperCase()]||gw.WHITE:e}function bw(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:["constructor"],s=Object.getPrototypeOf(e),r=Object.getOwnPropertyNames(s),n=c(r);try{var o=function(){var s=t.value;"function"==typeof e[s]&&(i.find((function(e){return s===e}))||(e[s]=e[s].bind(e)))};for(n.s();!(t=n.n()).done;)o()}catch(e){n.e(e)}finally{n.f()}}function Bw(e,t){if(!e)throw new Error(t||"Assertion failed")}function ww(){var e,t,i;if(cw&&"performance"in dw)e=null==dw||null===(t=dw.performance)||void 0===t||null===(i=t.now)||void 0===i?void 0:i.call(t);else if("hrtime"in pw){var s,r=null==pw||null===(s=pw.hrtime)||void 0===s?void 0:s.call(pw);e=1e3*r[0]+r[1]/1e6}else e=Date.now();return e}!function(e){e[e.BLACK=30]="BLACK",e[e.RED=31]="RED",e[e.GREEN=32]="GREEN",e[e.YELLOW=33]="YELLOW",e[e.BLUE=34]="BLUE",e[e.MAGENTA=35]="MAGENTA",e[e.CYAN=36]="CYAN",e[e.WHITE=37]="WHITE",e[e.BRIGHT_BLACK=90]="BRIGHT_BLACK",e[e.BRIGHT_RED=91]="BRIGHT_RED",e[e.BRIGHT_GREEN=92]="BRIGHT_GREEN",e[e.BRIGHT_YELLOW=93]="BRIGHT_YELLOW",e[e.BRIGHT_BLUE=94]="BRIGHT_BLUE",e[e.BRIGHT_MAGENTA=95]="BRIGHT_MAGENTA",e[e.BRIGHT_CYAN=96]="BRIGHT_CYAN",e[e.BRIGHT_WHITE=97]="BRIGHT_WHITE"}(gw||(gw={}));var xw={debug:cw&&console.debug||console.log,log:console.log,info:console.info,warn:console.warn,error:console.error},Pw={enabled:!0,level:0};function Cw(){}var Mw={},Fw={once:!0},Ew=function(){function e(){x(this,e);var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{id:""},i=t.id;fb(this,"id",void 0),fb(this,"VERSION",fw),fb(this,"_startTs",ww()),fb(this,"_deltaTs",ww()),fb(this,"_storage",void 0),fb(this,"userData",{}),fb(this,"LOG_THROTTLE_TIMEOUT",0),this.id=i,this._storage=new mw("__probe-".concat(this.id,"__"),Pw),this.userData={},this.timeStamp("".concat(this.id," started")),bw(this),Object.seal(this)}return C(e,[{key:"level",get:function(){return this.getLevel()},set:function(e){this.setLevel(e)}},{key:"isEnabled",value:function(){return this._storage.config.enabled}},{key:"getLevel",value:function(){return this._storage.config.level}},{key:"getTotal",value:function(){return Number((ww()-this._startTs).toPrecision(10))}},{key:"getDelta",value:function(){return Number((ww()-this._deltaTs).toPrecision(10))}},{key:"priority",get:function(){return this.level},set:function(e){this.level=e}},{key:"getPriority",value:function(){return this.level}},{key:"enable",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this._storage.updateConfiguration({enabled:e}),this}},{key:"setLevel",value:function(e){return this._storage.updateConfiguration({level:e}),this}},{key:"get",value:function(e){return this._storage.config[e]}},{key:"set",value:function(e,t){this._storage.updateConfiguration(o({},e,t))}},{key:"settings",value:function(){console.table?console.table(this._storage.config):console.log(this._storage.config)}},{key:"assert",value:function(e,t){Bw(e,t)}},{key:"warn",value:function(e){return this._getLogFunction(0,e,xw.warn,arguments,Fw)}},{key:"error",value:function(e){return this._getLogFunction(0,e,xw.error,arguments)}},{key:"deprecated",value:function(e,t){return this.warn("`".concat(e,"` is deprecated and will be removed in a later version. Use `").concat(t,"` instead"))}},{key:"removed",value:function(e,t){return this.error("`".concat(e,"` has been removed. Use `").concat(t,"` instead"))}},{key:"probe",value:function(e,t){return this._getLogFunction(e,t,xw.log,arguments,{time:!0,once:!0})}},{key:"log",value:function(e,t){return this._getLogFunction(e,t,xw.debug,arguments)}},{key:"info",value:function(e,t){return this._getLogFunction(e,t,console.info,arguments)}},{key:"once",value:function(e,t){for(var i=arguments.length,s=new Array(i>2?i-2:0),r=2;r2&&void 0!==arguments[2]?arguments[2]:{collapsed:!1},s=Iw({logLevel:e,message:t,opts:i}),r=i.collapsed;return s.method=(r?console.groupCollapsed:console.group)||console.info,this._getLogFunction(s)}},{key:"groupCollapsed",value:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.group(e,t,Object.assign({},i,{collapsed:!0}))}},{key:"groupEnd",value:function(e){return this._getLogFunction(e,"",console.groupEnd||Cw)}},{key:"withGroup",value:function(e,t,i){this.group(e,t)();try{i()}finally{this.groupEnd(e)()}}},{key:"trace",value:function(){console.trace&&console.trace()}},{key:"_shouldLog",value:function(e){return this.isEnabled()&&this.getLevel()>=kw(e)}},{key:"_getLogFunction",value:function(e,t,i,s,r){if(this._shouldLog(e)){var n;r=Iw({logLevel:e,message:t,args:s,opts:r}),Bw(i=i||r.method),r.total=this.getTotal(),r.delta=this.getDelta(),this._deltaTs=ww();var o=r.tag||r.message;if(r.once){if(Mw[o])return Cw;Mw[o]=ww()}return t=function(e,t,i){if("string"==typeof t){var s=i.time?function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,i=Math.max(t-e.length,0);return"".concat(" ".repeat(i)).concat(e)}((r=i.total)<10?"".concat(r.toFixed(2),"ms"):r<100?"".concat(r.toFixed(1),"ms"):r<1e3?"".concat(r.toFixed(0),"ms"):"".concat((r/1e3).toFixed(2),"s")):"";t=function(e,t,i){return cw||"string"!=typeof e||(t&&(t=yw(t),e="[".concat(t,"m").concat(e,"")),i&&(t=yw(i),e="[".concat(i+10,"m").concat(e,""))),e}(t=i.time?"".concat(e,": ").concat(s," ").concat(t):"".concat(e,": ").concat(t),i.color,i.background)}var r;return t}(this.id,r.message,r),(n=i).bind.apply(n,[console,t].concat(A(r.args)))}return Cw}}]),e}();function kw(e){if(!e)return 0;var t;switch(w(e)){case"number":t=e;break;case"object":t=e.logLevel||e.priority||0;break;default:return 0}return Bw(Number.isFinite(t)&&t>=0),t}function Iw(e){var t=e.logLevel,i=e.message;e.logLevel=kw(t);for(var s=e.args?Array.from(e.args):[];s.length&&s.shift()!==i;);switch(w(t)){case"string":case"function":void 0!==i&&s.unshift(i),e.message=t;break;case"object":Object.assign(e,t)}"function"==typeof e.message&&(e.message=e.message());var r=w(e.message);return Bw("string"===r||"object"===r),Object.assign(e,{args:s},e.opts)}function Dw(e){for(var t in e)for(var i in e[t])return i||"untitled";return"empty"}fb(Ew,"VERSION",fw);var Sw=new Ew({id:"loaders.gl"}),Tw=/\.([^.]+)$/;function Rw(e){return Lw.apply(this,arguments)}function Lw(){return Lw=u(a().mark((function e(t){var i,s,r,o,l=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=l.length>1&&void 0!==l[1]?l[1]:[],s=l.length>2?l[2]:void 0,r=l.length>3?l[3]:void 0,Nw(t)){e.next=5;break}return e.abrupt("return",null);case 5:if(!(o=Uw(t,i,n(n({},s),{},{nothrow:!0}),r))){e.next=8;break}return e.abrupt("return",o);case 8:if(!aB(t)){e.next=13;break}return e.next=11,t.slice(0,10).arrayBuffer();case 11:t=e.sent,o=Uw(t,i,s,r);case 13:if(o||null!=s&&s.nothrow){e.next=15;break}throw new Error(Qw(t));case 15:return e.abrupt("return",o);case 16:case"end":return e.stop()}}),e)}))),Lw.apply(this,arguments)}function Uw(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],i=arguments.length>2?arguments[2]:void 0,s=arguments.length>3?arguments[3]:void 0;if(!Nw(e))return null;if(t&&!Array.isArray(t))return uw(t);var r,n=[];(t&&(n=n.concat(t)),null!=i&&i.ignoreRegisteredLoaders)||(r=n).push.apply(r,A(Aw()));Vw(n);var o=Ow(e,n,i,s);if(!(o||null!=i&&i.nothrow))throw new Error(Qw(e));return o}function Ow(e,t,i,s){var r,n=pB(e),o=n.url,a=n.type,l=o||(null==s?void 0:s.url),u=null,A="";(null!=i&&i.mimeType&&(u=Hw(t,null==i?void 0:i.mimeType),A="match forced by supplied MIME type ".concat(null==i?void 0:i.mimeType)),u=u||function(e,t){var i=t&&Tw.exec(t),s=i&&i[1];return s?function(e,t){t=t.toLowerCase();var i,s=c(e);try{for(s.s();!(i=s.n()).done;){var r,n=i.value,o=c(n.extensions);try{for(o.s();!(r=o.n()).done;){if(r.value.toLowerCase()===t)return n}}catch(e){o.e(e)}finally{o.f()}}}catch(e){s.e(e)}finally{s.f()}return null}(e,s):null}(t,l),A=A||(u?"matched url ".concat(l):""),u=u||Hw(t,a),A=A||(u?"matched MIME type ".concat(a):""),u=u||function(e,t){if(!t)return null;var i,s=c(e);try{for(s.s();!(i=s.n()).done;){var r=i.value;if("string"==typeof t){if(jw(t,r))return r}else if(ArrayBuffer.isView(t)){if(Gw(t.buffer,t.byteOffset,r))return r}else if(t instanceof ArrayBuffer){if(Gw(t,0,r))return r}}}catch(e){s.e(e)}finally{s.f()}return null}(t,e),A=A||(u?"matched initial data ".concat(zw(e)):""),u=u||Hw(t,null==i?void 0:i.fallbackMimeType),A=A||(u?"matched fallback MIME type ".concat(a):""))&&Sw.log(1,"selectLoader selected ".concat(null===(r=u)||void 0===r?void 0:r.name,": ").concat(A,"."));return u}function Nw(e){return!(e instanceof Response&&204===e.status)}function Qw(e){var t=pB(e),i=t.url,s=t.type,r="No valid loader found (";r+=i?"".concat(function(e){var t=e&&e.lastIndexOf("/");return t>=0?e.substr(t+1):""}(i),", "):"no url provided, ",r+="MIME type: ".concat(s?'"'.concat(s,'"'):"not provided",", ");var n=e?zw(e):"";return r+=n?' first bytes: "'.concat(n,'"'):"first bytes: not available",r+=")"}function Vw(e){var t,i=c(e);try{for(i.s();!(t=i.n()).done;){uw(t.value)}}catch(e){i.e(e)}finally{i.f()}}function Hw(e,t){var i,s=c(e);try{for(s.s();!(i=s.n()).done;){var r=i.value;if(r.mimeTypes&&r.mimeTypes.includes(t))return r;if(t==="application/x.".concat(r.id))return r}}catch(e){s.e(e)}finally{s.f()}return null}function jw(e,t){return t.testText?t.testText(e):(Array.isArray(t.tests)?t.tests:[t.tests]).some((function(t){return e.startsWith(t)}))}function Gw(e,t,i){return(Array.isArray(i.tests)?i.tests:[i.tests]).some((function(s){return function(e,t,i,s){if(s instanceof ArrayBuffer)return function(e,t,i){if(i=i||e.byteLength,e.byteLength1&&void 0!==arguments[1]?arguments[1]:5;if("string"==typeof e)return e.slice(0,t);if(ArrayBuffer.isView(e))return Ww(e.buffer,e.byteOffset,t);if(e instanceof ArrayBuffer){var i=0;return Ww(e,i,t)}return""}function Ww(e,t,i){if(e.byteLength1&&void 0!==A[1]?A[1]:{},s=t.chunkSize,r=void 0===s?262144:s,n=0;case 3:if(!(n2&&void 0!==arguments[2]?arguments[2]:null;if(i)return i;var s=n({fetch:rw(t,e)},e);return Array.isArray(s.loaders)||(s.loaders=null),s}function nx(e,t){if(!t&&e&&!Array.isArray(e))return e;var i;if(e&&(i=Array.isArray(e)?e:[e]),t&&t.loaders){var s=Array.isArray(t.loaders)?t.loaders:[t.loaders];i=i?[].concat(A(i),A(s)):s}return i&&i.length?i:null}function ox(e,t,i,s){return ax.apply(this,arguments)}function ax(){return(ax=u(a().mark((function e(t,i,s,r){var n,o,l,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return lb(!r||"object"===w(r)),!i||Array.isArray(i)||lw(i)||(r=void 0,s=i,i=void 0),e.next=4,t;case 4:return t=e.sent,s=s||{},n=pB(t),o=n.url,l=nx(i,r),e.next=11,Rw(t,l,s);case 11:if(u=e.sent){e.next=14;break}return e.abrupt("return",null);case 14:return s=sw(s,u,l,o),r=rx({url:o,parse:ox,loaders:l},s,r),e.next=18,lx(u,t,s,r);case 18:return e.abrupt("return",e.sent);case 19:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function lx(e,t,i,s){return ux.apply(this,arguments)}function ux(){return(ux=u(a().mark((function e(t,i,s,r){var n,o,l,u,A,c,h,d;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Eb(t),oB(i)&&(o=(n=i).ok,l=n.redirected,u=n.status,A=n.statusText,c=n.type,h=n.url,d=Object.fromEntries(n.headers.entries()),r.response={headers:d,ok:o,redirected:l,status:u,statusText:A,type:c,url:h}),e.next=4,ix(i,t,s);case 4:if(i=e.sent,!t.parseTextSync||"string"!=typeof i){e.next=8;break}return s.dataType="text",e.abrupt("return",t.parseTextSync(i,s,r,t));case 8:if(!Ob(t,s)){e.next=12;break}return e.next=11,Nb(t,i,s,r,ox);case 11:case 15:case 19:return e.abrupt("return",e.sent);case 12:if(!t.parseText||"string"!=typeof i){e.next=16;break}return e.next=15,t.parseText(i,s,r,t);case 16:if(!t.parse){e.next=20;break}return e.next=19,t.parse(i,s,r,t);case 20:throw lb(!t.parseSync),new Error("".concat(t.id," loader - no parser found and worker is disabled"));case 22:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Ax,cx,hx="https://unpkg.com/@loaders.gl/textures@".concat("3.2.6","/dist/libs/basis_encoder.wasm"),dx="https://unpkg.com/@loaders.gl/textures@".concat("3.2.6","/dist/libs/basis_encoder.js");function px(e){return fx.apply(this,arguments)}function fx(){return(fx=u(a().mark((function e(t){var i;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(i=t.modules||{}).basis){e.next=3;break}return e.abrupt("return",i.basis);case 3:return Ax=Ax||vx(t),e.next=6,Ax;case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function vx(e){return gx.apply(this,arguments)}function gx(){return(gx=u(a().mark((function e(t){var i,s,r,n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=null,s=null,e.t0=Promise,e.next=5,Db("basis_transcoder.js","textures",t);case 5:return e.t1=e.sent,e.next=8,Db("basis_transcoder.wasm","textures",t);case 8:return e.t2=e.sent,e.t3=[e.t1,e.t2],e.next=12,e.t0.all.call(e.t0,e.t3);case 12:return r=e.sent,n=h(r,2),i=n[0],s=n[1],i=i||globalThis.BASIS,e.next=19,mx(i,s);case 19:return e.abrupt("return",e.sent);case 20:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function mx(e,t){var i={};return t&&(i.wasmBinary=t),new Promise((function(t){e(i).then((function(e){var i=e.BasisFile;(0,e.initializeBasis)(),t({BasisFile:i})}))}))}function _x(e){return yx.apply(this,arguments)}function yx(){return(yx=u(a().mark((function e(t){var i;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(i=t.modules||{}).basisEncoder){e.next=3;break}return e.abrupt("return",i.basisEncoder);case 3:return cx=cx||bx(t),e.next=6,cx;case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function bx(e){return Bx.apply(this,arguments)}function Bx(){return(Bx=u(a().mark((function e(t){var i,s,r,n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=null,s=null,e.t0=Promise,e.next=5,Db(dx,"textures",t);case 5:return e.t1=e.sent,e.next=8,Db(hx,"textures",t);case 8:return e.t2=e.sent,e.t3=[e.t1,e.t2],e.next=12,e.t0.all.call(e.t0,e.t3);case 12:return r=e.sent,n=h(r,2),i=n[0],s=n[1],i=i||globalThis.BASIS,e.next=19,wx(i,s);case 19:return e.abrupt("return",e.sent);case 20:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function wx(e,t){var i={};return t&&(i.wasmBinary=t),new Promise((function(t){e(i).then((function(e){var i=e.BasisFile,s=e.KTX2File,r=e.initializeBasis,n=e.BasisEncoder;r(),t({BasisFile:i,KTX2File:s,BasisEncoder:n})}))}))}var xx,Px,Cx,Mx,Fx,Ex,kx,Ix,Dx,Sx=33776,Tx=33779,Rx=35840,Lx=35842,Ux=36196,Ox=37808,Nx=["","WEBKIT_","MOZ_"],Qx={WEBGL_compressed_texture_s3tc:"dxt",WEBGL_compressed_texture_s3tc_srgb:"dxt-srgb",WEBGL_compressed_texture_etc1:"etc1",WEBGL_compressed_texture_etc:"etc2",WEBGL_compressed_texture_pvrtc:"pvrtc",WEBGL_compressed_texture_atc:"atc",WEBGL_compressed_texture_astc:"astc",EXT_texture_compression_rgtc:"rgtc"},Vx=null;function Hx(e){if(!Vx){e=e||function(){try{return document.createElement("canvas").getContext("webgl")}catch(e){return null}}()||void 0,Vx=new Set;var t,i=c(Nx);try{for(i.s();!(t=i.n()).done;){var s=t.value;for(var r in Qx)if(e&&e.getExtension("".concat(s).concat(r))){var n=Qx[r];Vx.add(n)}}}catch(e){i.e(e)}finally{i.f()}}return Vx}(Dx=xx||(xx={}))[Dx.NONE=0]="NONE",Dx[Dx.BASISLZ=1]="BASISLZ",Dx[Dx.ZSTD=2]="ZSTD",Dx[Dx.ZLIB=3]="ZLIB",function(e){e[e.BASICFORMAT=0]="BASICFORMAT"}(Px||(Px={})),function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.ETC1S=163]="ETC1S",e[e.UASTC=166]="UASTC"}(Cx||(Cx={})),function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.SRGB=1]="SRGB"}(Mx||(Mx={})),function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.LINEAR=1]="LINEAR",e[e.SRGB=2]="SRGB",e[e.ITU=3]="ITU",e[e.NTSC=4]="NTSC",e[e.SLOG=5]="SLOG",e[e.SLOG2=6]="SLOG2"}(Fx||(Fx={})),function(e){e[e.ALPHA_STRAIGHT=0]="ALPHA_STRAIGHT",e[e.ALPHA_PREMULTIPLIED=1]="ALPHA_PREMULTIPLIED"}(Ex||(Ex={})),function(e){e[e.RGB=0]="RGB",e[e.RRR=3]="RRR",e[e.GGG=4]="GGG",e[e.AAA=15]="AAA"}(kx||(kx={})),function(e){e[e.RGB=0]="RGB",e[e.RGBA=3]="RGBA",e[e.RRR=4]="RRR",e[e.RRRG=5]="RRRG"}(Ix||(Ix={}));var jx=[171,75,84,88,32,50,48,187,13,10,26,10];function Gx(e){var t=new Uint8Array(e);return!(t.byteLength1&&void 0!==s[1]?s[1]:null)&&gP||(i=null),!i){e.next=13;break}return e.prev=3,e.next=6,createImageBitmap(t,i);case 6:return e.abrupt("return",e.sent);case 9:e.prev=9,e.t0=e.catch(3),console.warn(e.t0),gP=!1;case 13:return e.next=15,createImageBitmap(t);case 15:return e.abrupt("return",e.sent);case 16:case"end":return e.stop()}}),e,null,[[3,9]])}))),bP.apply(this,arguments)}function BP(e){for(var t in e||vP)return!1;return!0}function wP(e){var t=xP(e);return function(e){var t=xP(e);if(!(t.byteLength>=24&&2303741511===t.getUint32(0,false)))return null;return{mimeType:"image/png",width:t.getUint32(16,false),height:t.getUint32(20,false)}}(t)||function(e){var t=xP(e);if(!(t.byteLength>=3&&65496===t.getUint16(0,false)&&255===t.getUint8(2)))return null;var i=function(){for(var e=new Set([65499,65476,65484,65501,65534]),t=65504;t<65520;++t)e.add(t);var i=new Set([65472,65473,65474,65475,65477,65478,65479,65481,65482,65483,65485,65486,65487,65502]);return{tableMarkers:e,sofMarkers:i}}(),s=i.tableMarkers,r=i.sofMarkers,n=2;for(;n+9=10&&1195984440===t.getUint32(0,false)))return null;return{mimeType:"image/gif",width:t.getUint16(6,true),height:t.getUint16(8,true)}}(t)||function(e){var t=xP(e);if(!(t.byteLength>=14&&16973===t.getUint16(0,false)&&t.getUint32(2,true)===t.byteLength))return null;return{mimeType:"image/bmp",width:t.getUint32(18,true),height:t.getUint32(22,true)}}(t)}function xP(e){if(e instanceof DataView)return e;if(ArrayBuffer.isView(e))return new DataView(e.buffer);if(e instanceof ArrayBuffer)return new DataView(e);throw new Error("toDataView")}function PP(e,t){return CP.apply(this,arguments)}function CP(){return CP=u(a().mark((function e(t,i){var s,r,n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return s=wP(t)||{},r=s.mimeType,nb(n=globalThis._parseImageNode),e.next=5,n(t,r);case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e)}))),CP.apply(this,arguments)}function MP(){return(MP=u(a().mark((function e(t,i,s){var r,n,o,l,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=(i=i||{}).image||{},n=r.type||"auto",o=(s||{}).url,l=FP(n),e.t0=l,e.next="imagebitmap"===e.t0?8:"image"===e.t0?12:"data"===e.t0?16:20;break;case 8:return e.next=10,mP(t,i,o);case 10:return u=e.sent,e.abrupt("break",21);case 12:return e.next=14,hP(t,i,o);case 14:return u=e.sent,e.abrupt("break",21);case 16:return e.next=18,PP(t);case 18:return u=e.sent,e.abrupt("break",21);case 20:nb(!1);case 21:return"data"===n&&(u=oP(u)),e.abrupt("return",u);case 23:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function FP(e){switch(e){case"auto":case"data":return function(){if(iP)return"imagebitmap";if(tP)return"image";if(rP)return"data";throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js")}();default:return function(e){switch(e){case"auto":return iP||tP||rP;case"imagebitmap":return iP;case"image":return tP;case"data":return rP;default:throw new Error("@loaders.gl/images: image ".concat(e," not supported in this environment"))}}(e),e}}var EP={id:"image",module:"images",name:"Images",version:"3.2.6",mimeTypes:["image/png","image/jpeg","image/gif","image/webp","image/bmp","image/vnd.microsoft.icon","image/svg+xml"],extensions:["png","jpg","jpeg","gif","webp","bmp","ico","svg"],parse:function(e,t,i){return MP.apply(this,arguments)},tests:[function(e){return Boolean(wP(new DataView(e)))}],options:{image:{type:"auto",decode:!0}}},kP=["image/png","image/jpeg","image/gif"],IP={};function DP(e){return void 0===IP[e]&&(IP[e]=function(e){switch(e){case"image/webp":return function(){if(!ob)return!1;try{return 0===document.createElement("canvas").toDataURL("image/webp").indexOf("data:image/webp")}catch(e){return!1}}();case"image/svg":return ob;default:if(!ob){var t=globalThis._parseImageNode;return Boolean(t)&&kP.includes(e)}return!0}}(e)),IP[e]}function SP(e,t){if(!e)throw new Error(t||"assert failed: gltf")}function TP(e,t){if(e.startsWith("data:")||e.startsWith("http:")||e.startsWith("https:"))return e;var i=t.baseUri||t.uri;if(!i)throw new Error("'baseUri' must be provided to resolve relative url ".concat(e));return i.substr(0,i.lastIndexOf("/")+1)+e}function RP(e,t,i){var s=e.bufferViews[i];SP(s);var r=t[s.buffer];SP(r);var n=(s.byteOffset||0)+r.byteOffset;return new Uint8Array(r.arrayBuffer,n,s.byteLength)}var LP=["SCALAR","VEC2","VEC3","VEC4"],UP=[[Int8Array,5120],[Uint8Array,5121],[Int16Array,5122],[Uint16Array,5123],[Uint32Array,5125],[Float32Array,5126],[Float64Array,5130]],OP=new Map(UP),NP={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},QP={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},VP={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function HP(e){return LP[e-1]||LP[0]}function jP(e){var t=OP.get(e.constructor);if(!t)throw new Error("Illegal typed array");return t}function GP(e,t){var i=VP[e.componentType],s=NP[e.type],r=QP[e.componentType],n=e.count*s,o=e.count*s*r;return SP(o>=0&&o<=t.byteLength),{ArrayType:i,length:n,byteLength:o}}var zP,WP={asset:{version:"2.0",generator:"loaders.gl"},buffers:[]},KP=function(){function e(t){x(this,e),fb(this,"gltf",void 0),fb(this,"sourceBuffers",void 0),fb(this,"byteLength",void 0),this.gltf=t||{json:n({},WP),buffers:[]},this.sourceBuffers=[],this.byteLength=0,this.gltf.buffers&&this.gltf.buffers[0]&&(this.byteLength=this.gltf.buffers[0].byteLength,this.sourceBuffers=[this.gltf.buffers[0]])}return C(e,[{key:"json",get:function(){return this.gltf.json}},{key:"getApplicationData",value:function(e){return this.json[e]}},{key:"getExtraData",value:function(e){return(this.json.extras||{})[e]}},{key:"getExtension",value:function(e){var t=this.getUsedExtensions().find((function(t){return t===e})),i=this.json.extensions||{};return t?i[e]||!0:null}},{key:"getRequiredExtension",value:function(e){var t=this.getRequiredExtensions().find((function(t){return t===e}));return t?this.getExtension(e):null}},{key:"getRequiredExtensions",value:function(){return this.json.extensionsRequired||[]}},{key:"getUsedExtensions",value:function(){return this.json.extensionsUsed||[]}},{key:"getObjectExtension",value:function(e,t){return(e.extensions||{})[t]}},{key:"getScene",value:function(e){return this.getObject("scenes",e)}},{key:"getNode",value:function(e){return this.getObject("nodes",e)}},{key:"getSkin",value:function(e){return this.getObject("skins",e)}},{key:"getMesh",value:function(e){return this.getObject("meshes",e)}},{key:"getMaterial",value:function(e){return this.getObject("materials",e)}},{key:"getAccessor",value:function(e){return this.getObject("accessors",e)}},{key:"getTexture",value:function(e){return this.getObject("textures",e)}},{key:"getSampler",value:function(e){return this.getObject("samplers",e)}},{key:"getImage",value:function(e){return this.getObject("images",e)}},{key:"getBufferView",value:function(e){return this.getObject("bufferViews",e)}},{key:"getBuffer",value:function(e){return this.getObject("buffers",e)}},{key:"getObject",value:function(e,t){if("object"===w(t))return t;var i=this.json[e]&&this.json[e][t];if(!i)throw new Error("glTF file error: Could not find ".concat(e,"[").concat(t,"]"));return i}},{key:"getTypedArrayForBufferView",value:function(e){var t=(e=this.getBufferView(e)).buffer,i=this.gltf.buffers[t];SP(i);var s=(e.byteOffset||0)+i.byteOffset;return new Uint8Array(i.arrayBuffer,s,e.byteLength)}},{key:"getTypedArrayForAccessor",value:function(e){e=this.getAccessor(e);var t=this.getBufferView(e.bufferView),i=this.getBuffer(t.buffer).data,s=GP(e,t),r=s.ArrayType,n=s.length;return new r(i,t.byteOffset+e.byteOffset,n)}},{key:"getTypedArrayForImageData",value:function(e){e=this.getAccessor(e);var t=this.getBufferView(e.bufferView),i=this.getBuffer(t.buffer).data,s=t.byteOffset||0;return new Uint8Array(i,s,t.byteLength)}},{key:"addApplicationData",value:function(e,t){return this.json[e]=t,this}},{key:"addExtraData",value:function(e,t){return this.json.extras=this.json.extras||{},this.json.extras[e]=t,this}},{key:"addObjectExtension",value:function(e,t,i){return e.extensions=e.extensions||{},e.extensions[t]=i,this.registerUsedExtension(t),this}},{key:"setObjectExtension",value:function(e,t,i){(e.extensions||{})[t]=i}},{key:"removeObjectExtension",value:function(e,t){var i=e.extensions||{},s=i[t];return delete i[t],s}},{key:"addExtension",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return SP(t),this.json.extensions=this.json.extensions||{},this.json.extensions[e]=t,this.registerUsedExtension(e),t}},{key:"addRequiredExtension",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return SP(t),this.addExtension(e,t),this.registerRequiredExtension(e),t}},{key:"registerUsedExtension",value:function(e){this.json.extensionsUsed=this.json.extensionsUsed||[],this.json.extensionsUsed.find((function(t){return t===e}))||this.json.extensionsUsed.push(e)}},{key:"registerRequiredExtension",value:function(e){this.registerUsedExtension(e),this.json.extensionsRequired=this.json.extensionsRequired||[],this.json.extensionsRequired.find((function(t){return t===e}))||this.json.extensionsRequired.push(e)}},{key:"removeExtension",value:function(e){this.json.extensionsRequired&&this._removeStringFromArray(this.json.extensionsRequired,e),this.json.extensionsUsed&&this._removeStringFromArray(this.json.extensionsUsed,e),this.json.extensions&&delete this.json.extensions[e]}},{key:"setDefaultScene",value:function(e){this.json.scene=e}},{key:"addScene",value:function(e){var t=e.nodeIndices;return this.json.scenes=this.json.scenes||[],this.json.scenes.push({nodes:t}),this.json.scenes.length-1}},{key:"addNode",value:function(e){var t=e.meshIndex,i=e.matrix;this.json.nodes=this.json.nodes||[];var s={mesh:t};return i&&(s.matrix=i),this.json.nodes.push(s),this.json.nodes.length-1}},{key:"addMesh",value:function(e){var t=e.attributes,i=e.indices,s=e.material,r=e.mode,n=void 0===r?4:r,o={primitives:[{attributes:this._addAttributes(t),mode:n}]};if(i){var a=this._addIndices(i);o.primitives[0].indices=a}return Number.isFinite(s)&&(o.primitives[0].material=s),this.json.meshes=this.json.meshes||[],this.json.meshes.push(o),this.json.meshes.length-1}},{key:"addPointCloud",value:function(e){var t={primitives:[{attributes:this._addAttributes(e),mode:0}]};return this.json.meshes=this.json.meshes||[],this.json.meshes.push(t),this.json.meshes.length-1}},{key:"addImage",value:function(e,t){var i=wP(e),s=t||(null==i?void 0:i.mimeType),r={bufferView:this.addBufferView(e),mimeType:s};return this.json.images=this.json.images||[],this.json.images.push(r),this.json.images.length-1}},{key:"addBufferView",value:function(e){var t=e.byteLength;SP(Number.isFinite(t)),this.sourceBuffers=this.sourceBuffers||[],this.sourceBuffers.push(e);var i={buffer:0,byteOffset:this.byteLength,byteLength:t};return this.byteLength+=Jb(t,4),this.json.bufferViews=this.json.bufferViews||[],this.json.bufferViews.push(i),this.json.bufferViews.length-1}},{key:"addAccessor",value:function(e,t){var i={bufferView:e,type:HP(t.size),componentType:t.componentType,count:t.count,max:t.max,min:t.min};return this.json.accessors=this.json.accessors||[],this.json.accessors.push(i),this.json.accessors.length-1}},{key:"addBinaryBuffer",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{size:3},i=this.addBufferView(e),s={min:t.min,max:t.max};s.min&&s.max||(s=this._getAccessorMinMax(e,t.size));var r={size:t.size,componentType:jP(e),count:Math.round(e.length/t.size),min:s.min,max:s.max};return this.addAccessor(i,Object.assign(r,t))}},{key:"addTexture",value:function(e){var t={source:e.imageIndex};return this.json.textures=this.json.textures||[],this.json.textures.push(t),this.json.textures.length-1}},{key:"addMaterial",value:function(e){return this.json.materials=this.json.materials||[],this.json.materials.push(e),this.json.materials.length-1}},{key:"createBinaryChunk",value:function(){var e,t;this.gltf.buffers=[];var i,s=this.byteLength,r=new ArrayBuffer(s),n=new Uint8Array(r),o=0,a=c(this.sourceBuffers||[]);try{for(a.s();!(i=a.n()).done;){o=Yb(i.value,n,o)}}catch(e){a.e(e)}finally{a.f()}null!==(e=this.json)&&void 0!==e&&null!==(t=e.buffers)&&void 0!==t&&t[0]?this.json.buffers[0].byteLength=s:this.json.buffers=[{byteLength:s}],this.gltf.binary=r,this.sourceBuffers=[r]}},{key:"_removeStringFromArray",value:function(e,t){for(var i=!0;i;){var s=e.indexOf(t);s>-1?e.splice(s,1):i=!1}}},{key:"_addAttributes",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={};for(var i in e){var s=e[i],r=this._getGltfAttributeName(i),n=this.addBinaryBuffer(s.value,s);t[r]=n}return t}},{key:"_addIndices",value:function(e){return this.addBinaryBuffer(e,{size:1})}},{key:"_getGltfAttributeName",value:function(e){switch(e.toLowerCase()){case"position":case"positions":case"vertices":return"POSITION";case"normal":case"normals":return"NORMAL";case"color":case"colors":return"COLOR_0";case"texcoord":case"texcoords":return"TEXCOORD_0";default:return e}}},{key:"_getAccessorMinMax",value:function(e,t){var i={min:null,max:null};if(e.length5&&void 0!==u[5]?u[5]:"NONE",e.next=3,iC();case 3:aC(l=e.sent,l.exports[$P[n]],t,i,s,r,l.exports[qP[o||"NONE"]]);case 5:case"end":return e.stop()}}),e)}))),tC.apply(this,arguments)}function iC(){return sC.apply(this,arguments)}function sC(){return(sC=u(a().mark((function e(){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return zP||(zP=rC()),e.abrupt("return",zP);case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function rC(){return nC.apply(this,arguments)}function nC(){return(nC=u(a().mark((function e(){var t,i;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=XP,WebAssembly.validate(YP)&&(t=JP,console.log("Warning: meshopt_decoder is using experimental SIMD support")),e.next=4,WebAssembly.instantiate(oC(t),{});case 4:return i=e.sent,e.next=7,i.instance.exports.__wasm_call_ctors();case 7:return e.abrupt("return",i.instance);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function oC(e){for(var t=new Uint8Array(e.length),i=0;i96?s-71:s>64?s-65:s>47?s+4:s>46?63:62}for(var r=0,n=0;nr?A:r,n=c>n?c:n,o=h>o?h:o}return[[t,i,s],[r,n,o]]}var vC=function(){function e(t,i){x(this,e),fb(this,"fields",void 0),fb(this,"metadata",void 0),function(e,t){if(!e)throw new Error(t||"loader assertion failed.")}(Array.isArray(t)),function(e){var t,i={},s=c(e);try{for(s.s();!(t=s.n()).done;){var r=t.value;i[r.name]&&console.warn("Schema: duplicated field name",r.name,r),i[r.name]=!0}}catch(e){s.e(e)}finally{s.f()}}(t),this.fields=t,this.metadata=i||new Map}return C(e,[{key:"compareTo",value:function(e){if(this.metadata!==e.metadata)return!1;if(this.fields.length!==e.fields.length)return!1;for(var t=0;t2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:new Map;x(this,e),fb(this,"name",void 0),fb(this,"type",void 0),fb(this,"nullable",void 0),fb(this,"metadata",void 0),this.name=t,this.type=i,this.nullable=s,this.metadata=r}return C(e,[{key:"typeId",get:function(){return this.type&&this.type.typeId}},{key:"clone",value:function(){return new e(this.name,this.type,this.nullable,this.metadata)}},{key:"compareTo",value:function(e){return this.name===e.name&&this.type===e.type&&this.nullable===e.nullable&&this.metadata===e.metadata}},{key:"toString",value:function(){return"".concat(this.type).concat(this.nullable?", nullable":"").concat(this.metadata?", metadata: ".concat(this.metadata):"")}}]),e}();!function(e){e[e.NONE=0]="NONE",e[e.Null=1]="Null",e[e.Int=2]="Int",e[e.Float=3]="Float",e[e.Binary=4]="Binary",e[e.Utf8=5]="Utf8",e[e.Bool=6]="Bool",e[e.Decimal=7]="Decimal",e[e.Date=8]="Date",e[e.Time=9]="Time",e[e.Timestamp=10]="Timestamp",e[e.Interval=11]="Interval",e[e.List=12]="List",e[e.Struct=13]="Struct",e[e.Union=14]="Union",e[e.FixedSizeBinary=15]="FixedSizeBinary",e[e.FixedSizeList=16]="FixedSizeList",e[e.Map=17]="Map",e[e.Dictionary=-1]="Dictionary",e[e.Int8=-2]="Int8",e[e.Int16=-3]="Int16",e[e.Int32=-4]="Int32",e[e.Int64=-5]="Int64",e[e.Uint8=-6]="Uint8",e[e.Uint16=-7]="Uint16",e[e.Uint32=-8]="Uint32",e[e.Uint64=-9]="Uint64",e[e.Float16=-10]="Float16",e[e.Float32=-11]="Float32",e[e.Float64=-12]="Float64",e[e.DateDay=-13]="DateDay",e[e.DateMillisecond=-14]="DateMillisecond",e[e.TimestampSecond=-15]="TimestampSecond",e[e.TimestampMillisecond=-16]="TimestampMillisecond",e[e.TimestampMicrosecond=-17]="TimestampMicrosecond",e[e.TimestampNanosecond=-18]="TimestampNanosecond",e[e.TimeSecond=-19]="TimeSecond",e[e.TimeMillisecond=-20]="TimeMillisecond",e[e.TimeMicrosecond=-21]="TimeMicrosecond",e[e.TimeNanosecond=-22]="TimeNanosecond",e[e.DenseUnion=-23]="DenseUnion",e[e.SparseUnion=-24]="SparseUnion",e[e.IntervalDayTime=-25]="IntervalDayTime",e[e.IntervalYearMonth=-26]="IntervalYearMonth"}(mC||(mC={}));var yC=function(){function e(){x(this,e)}return C(e,[{key:"typeId",get:function(){return mC.NONE}},{key:"compareTo",value:function(e){return this===e}}],[{key:"isNull",value:function(e){return e&&e.typeId===mC.Null}},{key:"isInt",value:function(e){return e&&e.typeId===mC.Int}},{key:"isFloat",value:function(e){return e&&e.typeId===mC.Float}},{key:"isBinary",value:function(e){return e&&e.typeId===mC.Binary}},{key:"isUtf8",value:function(e){return e&&e.typeId===mC.Utf8}},{key:"isBool",value:function(e){return e&&e.typeId===mC.Bool}},{key:"isDecimal",value:function(e){return e&&e.typeId===mC.Decimal}},{key:"isDate",value:function(e){return e&&e.typeId===mC.Date}},{key:"isTime",value:function(e){return e&&e.typeId===mC.Time}},{key:"isTimestamp",value:function(e){return e&&e.typeId===mC.Timestamp}},{key:"isInterval",value:function(e){return e&&e.typeId===mC.Interval}},{key:"isList",value:function(e){return e&&e.typeId===mC.List}},{key:"isStruct",value:function(e){return e&&e.typeId===mC.Struct}},{key:"isUnion",value:function(e){return e&&e.typeId===mC.Union}},{key:"isFixedSizeBinary",value:function(e){return e&&e.typeId===mC.FixedSizeBinary}},{key:"isFixedSizeList",value:function(e){return e&&e.typeId===mC.FixedSizeList}},{key:"isMap",value:function(e){return e&&e.typeId===mC.Map}},{key:"isDictionary",value:function(e){return e&&e.typeId===mC.Dictionary}}]),e}(),bC=function(e,t){g(s,yC);var i=_(s);function s(e,t){var r;return x(this,s),fb(b(r=i.call(this)),"isSigned",void 0),fb(b(r),"bitWidth",void 0),r.isSigned=e,r.bitWidth=t,r}return C(s,[{key:"typeId",get:function(){return mC.Int}},{key:t,get:function(){return"Int"}},{key:"toString",value:function(){return"".concat(this.isSigned?"I":"Ui","nt").concat(this.bitWidth)}}]),s}(0,Symbol.toStringTag),BC=function(e){g(i,bC);var t=_(i);function i(){return x(this,i),t.call(this,!0,8)}return C(i)}(),wC=function(e){g(i,bC);var t=_(i);function i(){return x(this,i),t.call(this,!0,16)}return C(i)}(),xC=function(e){g(i,bC);var t=_(i);function i(){return x(this,i),t.call(this,!0,32)}return C(i)}(),PC=function(e){g(i,bC);var t=_(i);function i(){return x(this,i),t.call(this,!1,8)}return C(i)}(),CC=function(e){g(i,bC);var t=_(i);function i(){return x(this,i),t.call(this,!1,16)}return C(i)}(),MC=function(e){g(i,bC);var t=_(i);function i(){return x(this,i),t.call(this,!1,32)}return C(i)}(),FC=32,EC=64,kC=function(e,t){g(s,yC);var i=_(s);function s(e){var t;return x(this,s),fb(b(t=i.call(this)),"precision",void 0),t.precision=e,t}return C(s,[{key:"typeId",get:function(){return mC.Float}},{key:t,get:function(){return"Float"}},{key:"toString",value:function(){return"Float".concat(this.precision)}}]),s}(0,Symbol.toStringTag),IC=function(e){g(i,kC);var t=_(i);function i(){return x(this,i),t.call(this,FC)}return C(i)}(),DC=function(e){g(i,kC);var t=_(i);function i(){return x(this,i),t.call(this,EC)}return C(i)}(),SC=function(e,t){g(s,yC);var i=_(s);function s(e,t){var r;return x(this,s),fb(b(r=i.call(this)),"listSize",void 0),fb(b(r),"children",void 0),r.listSize=e,r.children=[t],r}return C(s,[{key:"typeId",get:function(){return mC.FixedSizeList}},{key:"valueType",get:function(){return this.children[0].type}},{key:"valueField",get:function(){return this.children[0]}},{key:t,get:function(){return"FixedSizeList"}},{key:"toString",value:function(){return"FixedSizeList[".concat(this.listSize,"]<").concat(this.valueType,">")}}]),s}(0,Symbol.toStringTag);function TC(e,t,i){var s=function(e){switch(e.constructor){case Int8Array:return new BC;case Uint8Array:return new PC;case Int16Array:return new wC;case Uint16Array:return new CC;case Int32Array:return new xC;case Uint32Array:return new MC;case Float32Array:return new IC;case Float64Array:return new DC;default:throw new Error("array type not supported")}}(t.value),r=i||function(e){var t=new Map;"byteOffset"in e&&t.set("byteOffset",e.byteOffset.toString(10));"byteStride"in e&&t.set("byteStride",e.byteStride.toString(10));"normalized"in e&&t.set("normalized",e.normalized.toString());return t}(t);return new _C(e,new SC(t.size,new _C("value",s)),!1,r)}function RC(e,t,i){var s=UC(t.metadata),r=[],n=function(e){var t={};for(var i in e){var s=e[i];t[s.name||"undefined"]=s}return t}(t.attributes);for(var o in e){var a=LC(o,e[o],n[o]);r.push(a)}if(i){var l=LC("indices",i);r.push(l)}return new vC(r,s)}function LC(e,t,i){return TC(e,t,i?UC(i.metadata):void 0)}function UC(e){var t=new Map;for(var i in e)t.set("".concat(i,".string"),JSON.stringify(e[i]));return t}var OC={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},NC={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},QC=function(){function e(t){x(this,e),fb(this,"draco",void 0),fb(this,"decoder",void 0),fb(this,"metadataQuerier",void 0),this.draco=t,this.decoder=new this.draco.Decoder,this.metadataQuerier=new this.draco.MetadataQuerier}return C(e,[{key:"destroy",value:function(){this.draco.destroy(this.decoder),this.draco.destroy(this.metadataQuerier)}},{key:"parseSync",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=new this.draco.DecoderBuffer;i.Init(new Int8Array(e),e.byteLength),this._disableAttributeTransforms(t);var s=this.decoder.GetEncodedGeometryType(i),r=s===this.draco.TRIANGULAR_MESH?new this.draco.Mesh:new this.draco.PointCloud;try{var o;switch(s){case this.draco.TRIANGULAR_MESH:o=this.decoder.DecodeBufferToMesh(i,r);break;case this.draco.POINT_CLOUD:o=this.decoder.DecodeBufferToPointCloud(i,r);break;default:throw new Error("DRACO: Unknown geometry type.")}if(!o.ok()||!r.ptr){var a="DRACO decompression failed: ".concat(o.error_msg());throw new Error(a)}var l=this._getDracoLoaderData(r,s,t),u=this._getMeshData(r,l,t),A=fC(u.attributes),c=RC(u.attributes,l,u.indices),h=n(n({loader:"draco",loaderData:l,header:{vertexCount:r.num_points(),boundingBox:A}},u),{},{schema:c});return h}finally{this.draco.destroy(i),r&&this.draco.destroy(r)}}},{key:"_getDracoLoaderData",value:function(e,t,i){var s=this._getTopLevelMetadata(e),r=this._getDracoAttributes(e,i);return{geometry_type:t,num_attributes:e.num_attributes(),num_points:e.num_points(),num_faces:e instanceof this.draco.Mesh?e.num_faces():0,metadata:s,attributes:r}}},{key:"_getDracoAttributes",value:function(e,t){for(var i={},s=0;s2&&void 0!==arguments[2]&&arguments[2];if(!e)return null;if(Array.isArray(e))return new t(e);if(i&&!(e instanceof t))return new t(e);return e}(t,Float32Array)),s=t.length/i);return{buffer:t,size:i,count:s}}(e),i=t.buffer,s=t.size;return{value:i,size:s,byteOffset:0,count:t.count,type:HP(s),componentType:jP(i)}}function eM(){return(eM=u(a().mark((function e(t,i,s){var r,n,o,l,u,A;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=i&&null!==(r=i.gltf)&&void 0!==r&&r.decompressMeshes){e.next=2;break}return e.abrupt("return");case 2:n=new KP(t),o=[],l=c(nM(n));try{for(l.s();!(u=l.n()).done;)A=u.value,n.getObjectExtension(A,"KHR_draco_mesh_compression")&&o.push(tM(n,A,i,s))}catch(e){l.e(e)}finally{l.f()}return e.next=8,Promise.all(o);case 8:n.removeExtension("KHR_draco_mesh_compression");case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function tM(e,t,i,s){return iM.apply(this,arguments)}function iM(){return iM=u(a().mark((function e(t,i,s,r){var o,l,u,A,c,d,p,f,v,g,m,_,y,b;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=t.getObjectExtension(i,"KHR_draco_mesh_compression")){e.next=3;break}return e.abrupt("return");case 3:return l=t.getTypedArrayForBufferView(o.bufferView),u=Xb(l.buffer,l.byteOffset),A=r.parse,delete(c=n({},s))["3d-tiles"],e.next=10,A(u,YC,c,r);case 10:for(d=e.sent,p=qC(d.attributes),f=0,v=Object.entries(p);f2&&void 0!==arguments[2]?arguments[2]:4,r=arguments.length>3?arguments[3]:void 0,n=arguments.length>4?arguments[4]:void 0;if(!r.DracoWriter)throw new Error("options.gltf.DracoWriter not provided");var a=r.DracoWriter.encodeSync({attributes:e}),l=null==n||null===(i=n.parseSync)||void 0===i?void 0:i.call(n,{attributes:e}),u=r._addFauxAttributes(l.attributes),A=r.addBufferView(a),c={primitives:[{attributes:u,mode:s,extensions:o({},"KHR_draco_mesh_compression",{bufferView:A,attributes:u})}]};return c}function rM(e){if(!e.attributes&&Object.keys(e.attributes).length>0)throw new Error("glTF: Empty primitive detected: Draco decompression failure?")}function nM(e){var t,i,r,n,o,l;return a().wrap((function(s){for(;;)switch(s.prev=s.next){case 0:t=c(e.json.meshes||[]),s.prev=1,t.s();case 3:if((i=t.n()).done){s.next=24;break}r=i.value,n=c(r.primitives),s.prev=6,n.s();case 8:if((o=n.n()).done){s.next=14;break}return l=o.value,s.next=12,l;case 12:s.next=8;break;case 14:s.next=19;break;case 16:s.prev=16,s.t0=s.catch(6),n.e(s.t0);case 19:return s.prev=19,n.f(),s.finish(19);case 22:s.next=3;break;case 24:s.next=29;break;case 26:s.prev=26,s.t1=s.catch(1),t.e(s.t1);case 29:return s.prev=29,t.f(),s.finish(29);case 32:case"end":return s.stop()}}),s,null,[[1,26,29,32],[6,16,19,22]])}function oM(){return(oM=u(a().mark((function e(t){var i,s,r,n,o,l,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=new KP(t),s=i.json,(r=i.getExtension("KHR_lights_punctual"))&&(i.json.lights=r.lights,i.removeExtension("KHR_lights_punctual")),n=c(s.nodes||[]);try{for(n.s();!(o=n.n()).done;)l=o.value,(u=i.getObjectExtension(l,"KHR_lights_punctual"))&&(l.light=u.light),i.removeObjectExtension(l,"KHR_lights_punctual")}catch(e){n.e(e)}finally{n.f()}case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function aM(){return(aM=u(a().mark((function e(t){var i,s,r,n,o,l,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=new KP(t),(s=i.json).lights&&(SP(!(r=i.addExtension("KHR_lights_punctual")).lights),r.lights=s.lights,delete s.lights),i.json.lights){n=c(i.json.lights);try{for(n.s();!(o=n.n()).done;)l=o.value,u=l.node,i.addObjectExtension(u,"KHR_lights_punctual",l)}catch(e){n.e(e)}finally{n.f()}delete i.json.lights}case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function lM(){return(lM=u(a().mark((function e(t){var i,s,r,n,o;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=new KP(t),s=i.json,i.removeExtension("KHR_materials_unlit"),r=c(s.materials||[]);try{for(r.s();!(n=r.n()).done;)o=n.value,o.extensions&&o.extensions.KHR_materials_unlit&&(o.unlit=!0),i.removeObjectExtension(o,"KHR_materials_unlit")}catch(e){r.e(e)}finally{r.f()}case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function uM(){return(uM=u(a().mark((function e(t){var i,s,r,n,o,l,u,A;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=new KP(t),s=i.json,r=i.getExtension("KHR_techniques_webgl")){n=cM(r,i),o=c(s.materials||[]);try{for(o.s();!(l=o.n()).done;)u=l.value,(A=i.getObjectExtension(u,"KHR_techniques_webgl"))&&(u.technique=Object.assign({},A,n[A.technique]),u.technique.values=hM(u.technique,i)),i.removeObjectExtension(u,"KHR_techniques_webgl")}catch(e){o.e(e)}finally{o.f()}i.removeExtension("KHR_techniques_webgl")}case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function AM(){return(AM=u(a().mark((function e(t,i){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function cM(e,t){var i=e.programs,s=void 0===i?[]:i,r=e.shaders,n=void 0===r?[]:r,o=e.techniques,a=void 0===o?[]:o,l=new TextDecoder;return n.forEach((function(e){if(!Number.isFinite(e.bufferView))throw new Error("KHR_techniques_webgl: no shader code");e.code=l.decode(t.getTypedArrayForBufferView(e.bufferView))})),s.forEach((function(e){e.fragmentShader=n[e.fragmentShader],e.vertexShader=n[e.vertexShader]})),a.forEach((function(e){e.program=s[e.program]})),a}function hM(e,t){var i=Object.assign({},e.values);return Object.keys(e.uniforms||{}).forEach((function(t){e.uniforms[t].value&&!(t in i)&&(i[t]=e.uniforms[t].value)})),Object.keys(i).forEach((function(e){"object"===w(i[e])&&void 0!==i[e].index&&(i[e].texture=t.getTexture(i[e].index))})),i}var dM=[cC,hC,dC,Object.freeze({__proto__:null,name:"KHR_draco_mesh_compression",preprocess:function(e,t,i){var s,r=new KP(e),n=c(nM(r));try{for(n.s();!(s=n.n()).done;){var o=s.value;r.getObjectExtension(o,"KHR_draco_mesh_compression")}}catch(e){n.e(e)}finally{n.f()}},decode:function(e,t,i){return eM.apply(this,arguments)},encode:function(e){var t,i=new KP(e),s=c(i.json.meshes||[]);try{for(s.s();!(t=s.n()).done;){var r=t.value;sM(r),i.addRequiredExtension("KHR_draco_mesh_compression")}}catch(e){s.e(e)}finally{s.f()}}}),Object.freeze({__proto__:null,name:"KHR_lights_punctual",decode:function(e){return oM.apply(this,arguments)},encode:function(e){return aM.apply(this,arguments)}}),Object.freeze({__proto__:null,name:"KHR_materials_unlit",decode:function(e){return lM.apply(this,arguments)},encode:function(e){var t=new KP(e),i=t.json;if(t.materials){var s,r=c(i.materials||[]);try{for(r.s();!(s=r.n()).done;){var n=s.value;n.unlit&&(delete n.unlit,t.addObjectExtension(n,"KHR_materials_unlit",{}),t.addExtension("KHR_materials_unlit"))}}catch(e){r.e(e)}finally{r.f()}}}}),Object.freeze({__proto__:null,name:"KHR_techniques_webgl",decode:function(e){return uM.apply(this,arguments)},encode:function(e,t){return AM.apply(this,arguments)}})];function pM(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,r=dM.filter((function(e){return gM(e.name,i)})),n=c(r);try{for(n.s();!(t=n.n()).done;){var o,a=t.value;null===(o=a.preprocess)||void 0===o||o.call(a,e,i,s)}}catch(e){n.e(e)}finally{n.f()}}function fM(e){return vM.apply(this,arguments)}function vM(){return vM=u(a().mark((function e(t){var i,s,r,n,o,l,u,A=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=A.length>1&&void 0!==A[1]?A[1]:{},s=A.length>2?A[2]:void 0,r=dM.filter((function(e){return gM(e.name,i)})),n=c(r),e.prev=4,n.s();case 6:if((o=n.n()).done){e.next=12;break}return l=o.value,e.next=10,null===(u=l.decode)||void 0===u?void 0:u.call(l,t,i,s);case 10:e.next=6;break;case 12:e.next=17;break;case 14:e.prev=14,e.t0=e.catch(4),n.e(e.t0);case 17:return e.prev=17,n.f(),e.finish(17);case 20:case"end":return e.stop()}}),e,null,[[4,14,17,20]])}))),vM.apply(this,arguments)}function gM(e,t){var i,s=(null==t||null===(i=t.gltf)||void 0===i?void 0:i.excludeExtensions)||{};return!(e in s&&!s[e])}var mM={accessors:"accessor",animations:"animation",buffers:"buffer",bufferViews:"bufferView",images:"image",materials:"material",meshes:"mesh",nodes:"node",samplers:"sampler",scenes:"scene",skins:"skin",textures:"texture"},_M={accessor:"accessors",animations:"animation",buffer:"buffers",bufferView:"bufferViews",image:"images",material:"materials",mesh:"meshes",node:"nodes",sampler:"samplers",scene:"scenes",skin:"skins",texture:"textures"},yM=function(){function e(){x(this,e),fb(this,"idToIndexMap",{animations:{},accessors:{},buffers:{},bufferViews:{},images:{},materials:{},meshes:{},nodes:{},samplers:{},scenes:{},skins:{},textures:{}}),fb(this,"json",void 0)}return C(e,[{key:"normalize",value:function(e,t){this.json=e.json;var i=e.json;switch(i.asset&&i.asset.version){case"2.0":return;case void 0:case"1.0":break;default:return void console.warn("glTF: Unknown version ".concat(i.asset.version))}if(!t.normalize)throw new Error("glTF v1 is not supported.");console.warn("Converting glTF v1 to glTF v2 format. This is experimental and may fail."),this._addAsset(i),this._convertTopLevelObjectsToArrays(i),function(e){var t,i=new KP(e),s=i.json,r=c(s.images||[]);try{for(r.s();!(t=r.n()).done;){var n=t.value,o=i.getObjectExtension(n,"KHR_binary_glTF");o&&Object.assign(n,o),i.removeObjectExtension(n,"KHR_binary_glTF")}}catch(e){r.e(e)}finally{r.f()}s.buffers&&s.buffers[0]&&delete s.buffers[0].uri,i.removeExtension("KHR_binary_glTF")}(e),this._convertObjectIdsToArrayIndices(i),this._updateObjects(i),this._updateMaterial(i)}},{key:"_addAsset",value:function(e){e.asset=e.asset||{},e.asset.version="2.0",e.asset.generator=e.asset.generator||"Normalized to glTF 2.0 by loaders.gl"}},{key:"_convertTopLevelObjectsToArrays",value:function(e){for(var t in mM)this._convertTopLevelObjectToArray(e,t)}},{key:"_convertTopLevelObjectToArray",value:function(e,t){var i=e[t];if(i&&!Array.isArray(i))for(var s in e[t]=[],i){var r=i[s];r.id=r.id||s;var n=e[t].length;e[t].push(r),this.idToIndexMap[t][s]=n}}},{key:"_convertObjectIdsToArrayIndices",value:function(e){for(var t in mM)this._convertIdsToIndices(e,t);"scene"in e&&(e.scene=this._convertIdToIndex(e.scene,"scene"));var i,s=c(e.textures);try{for(s.s();!(i=s.n()).done;){var r=i.value;this._convertTextureIds(r)}}catch(e){s.e(e)}finally{s.f()}var n,o=c(e.meshes);try{for(o.s();!(n=o.n()).done;){var a=n.value;this._convertMeshIds(a)}}catch(e){o.e(e)}finally{o.f()}var l,u=c(e.nodes);try{for(u.s();!(l=u.n()).done;){var A=l.value;this._convertNodeIds(A)}}catch(e){u.e(e)}finally{u.f()}var h,d=c(e.scenes);try{for(d.s();!(h=d.n()).done;){var p=h.value;this._convertSceneIds(p)}}catch(e){d.e(e)}finally{d.f()}}},{key:"_convertTextureIds",value:function(e){e.source&&(e.source=this._convertIdToIndex(e.source,"image"))}},{key:"_convertMeshIds",value:function(e){var t,i=c(e.primitives);try{for(i.s();!(t=i.n()).done;){var s=t.value,r=s.attributes,n=s.indices,o=s.material;for(var a in r)r[a]=this._convertIdToIndex(r[a],"accessor");n&&(s.indices=this._convertIdToIndex(n,"accessor")),o&&(s.material=this._convertIdToIndex(o,"material"))}}catch(e){i.e(e)}finally{i.f()}}},{key:"_convertNodeIds",value:function(e){var t=this;e.children&&(e.children=e.children.map((function(e){return t._convertIdToIndex(e,"node")}))),e.meshes&&(e.meshes=e.meshes.map((function(e){return t._convertIdToIndex(e,"mesh")})))}},{key:"_convertSceneIds",value:function(e){var t=this;e.nodes&&(e.nodes=e.nodes.map((function(e){return t._convertIdToIndex(e,"node")})))}},{key:"_convertIdsToIndices",value:function(e,t){e[t]||(console.warn("gltf v1: json doesn't contain attribute ".concat(t)),e[t]=[]);var i,s=c(e[t]);try{for(s.s();!(i=s.n()).done;){var r=i.value;for(var n in r){var o=r[n],a=this._convertIdToIndex(o,n);r[n]=a}}}catch(e){s.e(e)}finally{s.f()}}},{key:"_convertIdToIndex",value:function(e,t){var i=_M[t];if(i in this.idToIndexMap){var s=this.idToIndexMap[i][e];if(!Number.isFinite(s))throw new Error("gltf v1: failed to resolve ".concat(t," with id ").concat(e));return s}return e}},{key:"_updateObjects",value:function(e){var t,i=c(this.json.buffers);try{for(i.s();!(t=i.n()).done;){delete t.value.type}}catch(e){i.e(e)}finally{i.f()}}},{key:"_updateMaterial",value:function(e){var t,i=c(e.materials);try{var s=function(){var i=t.value;i.pbrMetallicRoughness={baseColorFactor:[1,1,1,1],metallicFactor:1,roughnessFactor:1};var s=(null===(r=i.values)||void 0===r?void 0:r.tex)||(null===(n=i.values)||void 0===n?void 0:n.texture2d_0),o=e.textures.findIndex((function(e){return e.id===s}));-1!==o&&(i.pbrMetallicRoughness.baseColorTexture={index:o})};for(i.s();!(t=i.n()).done;){var r,n;s()}}catch(e){i.e(e)}finally{i.f()}}}]),e}();function bM(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(new yM).normalize(e,t)}var BM={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},wM={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},xM=10240,PM=10241,CM=10242,MM=10243,FM=10497,EM=9986,kM={magFilter:xM,minFilter:PM,wrapS:CM,wrapT:MM},IM=(o(e={},xM,9729),o(e,PM,EM),o(e,CM,FM),o(e,MM,FM),e);var DM=function(){function e(){x(this,e),fb(this,"baseUri",""),fb(this,"json",{}),fb(this,"buffers",[]),fb(this,"images",[])}return C(e,[{key:"postProcess",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=e.json,s=e.buffers,r=void 0===s?[]:s,n=e.images,o=void 0===n?[]:n,a=e.baseUri,l=void 0===a?"":a;return SP(i),this.baseUri=l,this.json=i,this.buffers=r,this.images=o,this._resolveTree(this.json,t),this.json}},{key:"_resolveTree",value:function(e){var t=this;e.bufferViews&&(e.bufferViews=e.bufferViews.map((function(e,i){return t._resolveBufferView(e,i)}))),e.images&&(e.images=e.images.map((function(e,i){return t._resolveImage(e,i)}))),e.samplers&&(e.samplers=e.samplers.map((function(e,i){return t._resolveSampler(e,i)}))),e.textures&&(e.textures=e.textures.map((function(e,i){return t._resolveTexture(e,i)}))),e.accessors&&(e.accessors=e.accessors.map((function(e,i){return t._resolveAccessor(e,i)}))),e.materials&&(e.materials=e.materials.map((function(e,i){return t._resolveMaterial(e,i)}))),e.meshes&&(e.meshes=e.meshes.map((function(e,i){return t._resolveMesh(e,i)}))),e.nodes&&(e.nodes=e.nodes.map((function(e,i){return t._resolveNode(e,i)}))),e.skins&&(e.skins=e.skins.map((function(e,i){return t._resolveSkin(e,i)}))),e.scenes&&(e.scenes=e.scenes.map((function(e,i){return t._resolveScene(e,i)}))),void 0!==e.scene&&(e.scene=e.scenes[this.json.scene])}},{key:"getScene",value:function(e){return this._get("scenes",e)}},{key:"getNode",value:function(e){return this._get("nodes",e)}},{key:"getSkin",value:function(e){return this._get("skins",e)}},{key:"getMesh",value:function(e){return this._get("meshes",e)}},{key:"getMaterial",value:function(e){return this._get("materials",e)}},{key:"getAccessor",value:function(e){return this._get("accessors",e)}},{key:"getCamera",value:function(e){return null}},{key:"getTexture",value:function(e){return this._get("textures",e)}},{key:"getSampler",value:function(e){return this._get("samplers",e)}},{key:"getImage",value:function(e){return this._get("images",e)}},{key:"getBufferView",value:function(e){return this._get("bufferViews",e)}},{key:"getBuffer",value:function(e){return this._get("buffers",e)}},{key:"_get",value:function(e,t){if("object"===w(t))return t;var i=this.json[e]&&this.json[e][t];return i||console.warn("glTF file error: Could not find ".concat(e,"[").concat(t,"]")),i}},{key:"_resolveScene",value:function(e,t){var i=this;return e.id=e.id||"scene-".concat(t),e.nodes=(e.nodes||[]).map((function(e){return i.getNode(e)})),e}},{key:"_resolveNode",value:function(e,t){var i=this;return e.id=e.id||"node-".concat(t),e.children&&(e.children=e.children.map((function(e){return i.getNode(e)}))),void 0!==e.mesh?e.mesh=this.getMesh(e.mesh):void 0!==e.meshes&&e.meshes.length&&(e.mesh=e.meshes.reduce((function(e,t){var s=i.getMesh(t);return e.id=s.id,e.primitives=e.primitives.concat(s.primitives),e}),{primitives:[]})),void 0!==e.camera&&(e.camera=this.getCamera(e.camera)),void 0!==e.skin&&(e.skin=this.getSkin(e.skin)),e}},{key:"_resolveSkin",value:function(e,t){return e.id=e.id||"skin-".concat(t),e.inverseBindMatrices=this.getAccessor(e.inverseBindMatrices),e}},{key:"_resolveMesh",value:function(e,t){var i=this;return e.id=e.id||"mesh-".concat(t),e.primitives&&(e.primitives=e.primitives.map((function(e){var t=(e=n({},e)).attributes;for(var s in e.attributes={},t)e.attributes[s]=i.getAccessor(t[s]);return void 0!==e.indices&&(e.indices=i.getAccessor(e.indices)),void 0!==e.material&&(e.material=i.getMaterial(e.material)),e}))),e}},{key:"_resolveMaterial",value:function(e,t){if(e.id=e.id||"material-".concat(t),e.normalTexture&&(e.normalTexture=n({},e.normalTexture),e.normalTexture.texture=this.getTexture(e.normalTexture.index)),e.occlusionTexture&&(e.occlustionTexture=n({},e.occlustionTexture),e.occlusionTexture.texture=this.getTexture(e.occlusionTexture.index)),e.emissiveTexture&&(e.emmisiveTexture=n({},e.emmisiveTexture),e.emissiveTexture.texture=this.getTexture(e.emissiveTexture.index)),e.emissiveFactor||(e.emissiveFactor=e.emmisiveTexture?[1,1,1]:[0,0,0]),e.pbrMetallicRoughness){e.pbrMetallicRoughness=n({},e.pbrMetallicRoughness);var i=e.pbrMetallicRoughness;i.baseColorTexture&&(i.baseColorTexture=n({},i.baseColorTexture),i.baseColorTexture.texture=this.getTexture(i.baseColorTexture.index)),i.metallicRoughnessTexture&&(i.metallicRoughnessTexture=n({},i.metallicRoughnessTexture),i.metallicRoughnessTexture.texture=this.getTexture(i.metallicRoughnessTexture.index))}return e}},{key:"_resolveAccessor",value:function(e,t){var i,s;if(e.id=e.id||"accessor-".concat(t),void 0!==e.bufferView&&(e.bufferView=this.getBufferView(e.bufferView)),e.bytesPerComponent=(i=e.componentType,wM[i]),e.components=(s=e.type,BM[s]),e.bytesPerElement=e.bytesPerComponent*e.components,e.bufferView){var r=e.bufferView.buffer,n=GP(e,e.bufferView),o=n.ArrayType,a=n.byteLength,l=(e.bufferView.byteOffset||0)+(e.byteOffset||0)+r.byteOffset,u=r.arrayBuffer.slice(l,l+a);e.bufferView.byteStride&&(u=this._getValueFromInterleavedBuffer(r,l,e.bufferView.byteStride,e.bytesPerElement,e.count)),e.value=new o(u)}return e}},{key:"_getValueFromInterleavedBuffer",value:function(e,t,i,s,r){for(var n=new Uint8Array(r*s),o=0;o1&&void 0!==arguments[1]?arguments[1]:0;return"".concat(String.fromCharCode(e.getUint8(t+0))).concat(String.fromCharCode(e.getUint8(t+1))).concat(String.fromCharCode(e.getUint8(t+2))).concat(String.fromCharCode(e.getUint8(t+3)))}function LM(e,t,i){nb(e.header.byteLength>20);var s=t.getUint32(i+0,TM),r=t.getUint32(i+4,TM);return i+=8,nb(0===r),OM(e,t,i,s),i+=s,i+=NM(e,t,i,e.header.byteLength)}function UM(e,t,i,s){return nb(e.header.byteLength>20),function(e,t,i,s){for(;i+8<=e.header.byteLength;){var r=t.getUint32(i+0,TM),n=t.getUint32(i+4,TM);switch(i+=8,n){case 1313821514:OM(e,t,i,r);break;case 5130562:NM(e,t,i,r);break;case 0:s.strict||OM(e,t,i,r);break;case 1:s.strict||NM(e,t,i,r)}i+=Jb(r,4)}}(e,t,i,s),i+e.header.byteLength}function OM(e,t,i,s){var r=new Uint8Array(t.buffer,i,s),n=new TextDecoder("utf8").decode(r);return e.json=JSON.parse(n),Jb(s,4)}function NM(e,t,i,s){return e.header.hasBinChunk=!0,e.binChunks.push({byteOffset:i,byteLength:s,arrayBuffer:t.buffer}),Jb(s,4)}function QM(e,t){return VM.apply(this,arguments)}function VM(){return VM=u(a().mark((function e(t,i){var s,r,n,o,l,u,A,c,h,d,p=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(s=p.length>2&&void 0!==p[2]?p[2]:0,r=p.length>3?p[3]:void 0,n=p.length>4?p[4]:void 0,HM(t,i,s,r),bM(t,{normalize:null==r||null===(o=r.gltf)||void 0===o?void 0:o.normalize}),pM(t,r,n),c=[],null==r||null===(l=r.gltf)||void 0===l||!l.loadBuffers||!t.json.buffers){e.next=10;break}return e.next=10,jM(t,r,n);case 10:return null!=r&&null!==(u=r.gltf)&&void 0!==u&&u.loadImages&&(h=zM(t,r,n),c.push(h)),d=fM(t,r,n),c.push(d),e.next=15,Promise.all(c);case 15:return e.abrupt("return",null!=r&&null!==(A=r.gltf)&&void 0!==A&&A.postProcess?SM(t,r):t);case 16:case"end":return e.stop()}}),e)}))),VM.apply(this,arguments)}function HM(e,t,i,s){(s.uri&&(e.baseUri=s.uri),t instanceof ArrayBuffer&&!function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=new DataView(e),r=i.magic,n=void 0===r?1735152710:r,o=s.getUint32(t,!1);return o===n||1735152710===o}(t,i,s))&&(t=(new TextDecoder).decode(t));if("string"==typeof t)e.json=Gb(t);else if(t instanceof ArrayBuffer){var r={};i=function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=new DataView(t),r=RM(s,i+0),n=s.getUint32(i+4,TM),o=s.getUint32(i+8,TM);switch(Object.assign(e,{header:{byteOffset:i,byteLength:o,hasBinChunk:!1},type:r,version:n,json:{},binChunks:[]}),i+=12,e.version){case 1:return LM(e,s,i);case 2:return UM(e,s,i,{});default:throw new Error("Invalid GLB version ".concat(e.version,". Only supports v1 and v2."))}}(r,t,i,s.glb),SP("glTF"===r.type,"Invalid GLB magic string ".concat(r.type)),e._glb=r,e.json=r.json}else SP(!1,"GLTF: must be ArrayBuffer or string");var n=e.json.buffers||[];if(e.buffers=new Array(n.length).fill(null),e._glb&&e._glb.header.hasBinChunk){var o=e._glb.binChunks;e.buffers[0]={arrayBuffer:o[0].arrayBuffer,byteOffset:o[0].byteOffset,byteLength:o[0].byteLength}}var a=e.json.images||[];e.images=new Array(a.length).fill({})}function jM(e,t,i){return GM.apply(this,arguments)}function GM(){return(GM=u(a().mark((function e(t,i,s){var r,n,o,l,u,A,c,h;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=t.json.buffers||[],n=0;case 2:if(!(n1&&void 0!==u[1]?u[1]:{},s=u.length>2?u[2]:void 0,(i=n(n({},YM.options),i)).gltf=n(n({},YM.options.gltf),i.gltf),r=i.byteOffset,o=void 0===r?0:r,l={},e.next=8,QM(l,t,o,i,s);case 8:return e.abrupt("return",e.sent);case 9:case"end":return e.stop()}}),e)}))),ZM.apply(this,arguments)}var qM=function(){function e(t){x(this,e)}return C(e,[{key:"load",value:function(e,t,i,s,r,n,o){!function(e,t,i,s,r,n,o){var a=e.viewer.scene.canvas.spinner;a.processes++,"glb"===t.split(".").pop()?e.dataSource.getGLB(t,(function(o){s.basePath=eF(t),tF(e,t,o,i,s,r,n),a.processes--}),(function(e){a.processes--,o(e)})):e.dataSource.getGLTF(t,(function(o){s.basePath=eF(t),tF(e,t,o,i,s,r,n),a.processes--}),(function(e){a.processes--,o(e)}))}(e,t,i,s=s||{},r,(function(){_e.scheduleTask((function(){r.scene.fire("modelLoaded",r.id),r.fire("loaded",!0,!1)})),n&&n()}),(function(t){e.error(t),o&&o(t),r.fire("error",t)}))}},{key:"parse",value:function(e,t,i,s,r,n,o){tF(e,"",t,i,s=s||{},r,(function(){r.scene.fire("modelLoaded",r.id),r.fire("loaded",!0,!1),n&&n()}))}}]),e}();function $M(e){for(var t={},i={},s=e.metaObjects||[],r={},n=0,o=s.length;n0)for(var A=0;A0){null==y&&e.log("Warning: 'name' properties not found on glTF scene nodes - will randomly-generate object IDs in XKT");var b=y;if(e.metaModelCorrections){var B=e.metaModelCorrections.eachChildRoot[b];if(B){var w=e.metaModelCorrections.eachRootStats[B.id];w.countChildren++,w.countChildren>=w.numChildren&&(n.createEntity({id:B.id,meshIds:oF}),oF.length=0)}else{e.metaModelCorrections.metaObjectsMap[b]&&(n.createEntity({id:b,meshIds:oF}),oF.length=0)}}else n.createEntity({id:b,meshIds:oF}),oF.length=0}}function lF(e,t){e.plugin.error(t)}var uF={DEFAULT:{}},AF=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"GLTFLoader",e,r))._sceneModelLoader=new qM(b(s),r),s.dataSource=r.dataSource,s.objectDefaults=r.objectDefaults,s}return C(i,[{key:"dataSource",get:function(){return this._dataSource},set:function(e){this._dataSource=e||new Dh}},{key:"objectDefaults",get:function(){return this._objectDefaults},set:function(e){this._objectDefaults=e||uF}},{key:"load",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t.id&&this.viewer.scene.components[t.id]&&(this.error("Component with this ID already exists in viewer: "+t.id+" - will autogenerate this ID"),delete t.id);var i=new ch(this.viewer.scene,le.apply(t,{isModel:!0,dtxEnabled:t.dtxEnabled})),s=i.id;if(!t.src&&!t.gltf)return this.error("load() param expected: src or gltf"),i;if(t.metaModelSrc||t.metaModelJSON){var r=t.objectDefaults||this._objectDefaults||uF,n=function(n){var o;if(e.viewer.metaScene.createMetaModel(s,n,{includeTypes:t.includeTypes,excludeTypes:t.excludeTypes}),e.viewer.scene.canvas.spinner.processes--,t.includeTypes){o={};for(var a=0,l=t.includeTypes.length;a2&&void 0!==arguments[2]?arguments[2]:{},s="lightgrey",r=i.hoverColor||"rgba(0,0,0,0.4)",n=i.textColor||"black",o=500,a=o+o/3,l=a/24,u=[{boundary:[6,6,6,6],color:i.frontColor||i.color||"#55FF55"},{boundary:[18,6,6,6],color:i.backColor||i.color||"#55FF55"},{boundary:[12,6,6,6],color:i.rightColor||i.color||"#FF5555"},{boundary:[0,6,6,6],color:i.leftColor||i.color||"#FF5555"},{boundary:[6,0,6,6],color:i.topColor||i.color||"#7777FF"},{boundary:[6,12,6,6],color:i.bottomColor||i.color||"#7777FF"}],A=[{label:"NavCube.front",boundaries:[[7,7,4,4]],dir:[0,1,0],up:[0,0,1]},{label:"NavCube.back",boundaries:[[19,7,4,4]],dir:[0,-1,0],up:[0,0,1]},{label:"NavCube.right",boundaries:[[13,7,4,4]],dir:[-1,0,0],up:[0,0,1]},{label:"NavCube.left",boundaries:[[1,7,4,4]],dir:[1,0,0],up:[0,0,1]},{label:"NavCube.top",boundaries:[[7,1,4,4]],dir:[0,0,-1],up:[0,1,0]},{label:"NavCube.bottom",boundaries:[[7,13,4,4]],dir:[0,0,1],up:[0,-1,0]},{boundaries:[[7,5,4,2]],dir:[0,1,-1],up:[0,1,1]},{boundaries:[[1,6,4,1],[6,1,1,4]],dir:[1,0,-1],up:[1,0,1]},{boundaries:[[7,0,4,1],[19,6,4,1]],dir:[0,-1,-1],up:[0,-1,1]},{boundaries:[[13,6,4,1],[11,1,1,4]],dir:[-1,0,-1],up:[-1,0,1]},{boundaries:[[7,11,4,2]],dir:[0,1,1],up:[0,-1,1]},{boundaries:[[1,11,4,1],[6,13,1,4]],dir:[1,0,1],up:[-1,0,1]},{boundaries:[[7,17,4,1],[19,11,4,1]],dir:[0,-1,1],up:[0,1,1]},{boundaries:[[13,11,4,1],[11,13,1,4]],dir:[-1,0,1],up:[1,0,1]},{boundaries:[[5,7,2,4]],dir:[1,1,0],up:[0,0,1]},{boundaries:[[11,7,2,4]],dir:[-1,1,0],up:[0,0,1]},{boundaries:[[17,7,2,4]],dir:[-1,-1,0],up:[0,0,1]},{boundaries:[[0,7,1,4],[23,7,1,4]],dir:[1,-1,0],up:[0,0,1]},{boundaries:[[5,11,2,2]],dir:[1,1,1],up:[-1,-1,1]},{boundaries:[[23,11,1,1],[6,17,1,1],[0,11,1,1]],dir:[1,-1,1],up:[-1,1,1]},{boundaries:[[5,5,2,2]],dir:[1,1,-1],up:[1,1,1]},{boundaries:[[11,17,1,1],[17,11,2,1]],dir:[-1,-1,1],up:[1,1,1]},{boundaries:[[17,6,2,1],[11,0,1,1]],dir:[-1,-1,-1],up:[-1,-1,1]},{boundaries:[[11,11,2,2]],dir:[-1,1,1],up:[1,-1,1]},{boundaries:[[0,6,1,1],[6,0,1,1],[23,6,1,1]],dir:[1,-1,-1],up:[1,-1,1]},{boundaries:[[11,5,2,2]],dir:[-1,1,-1],up:[-1,1,1]}];i.frontColor||i.color,i.backColor||i.color,i.rightColor||i.color,i.leftColor||i.color,i.topColor||i.color,i.bottomColor||i.color;for(var c=[{yUp:"",label:"NavCube.front",boundaries:[[7,7,4,4]],dir:[0,0,-1],up:[0,1,0]},{label:"NavCube.back",boundaries:[[19,7,4,4]],dir:[0,0,1],up:[0,1,0]},{label:"NavCube.right",boundaries:[[13,7,4,4]],dir:[-1,0,0],up:[0,1,0]},{label:"NavCube.left",boundaries:[[1,7,4,4]],dir:[1,0,0],up:[0,1,0]},{label:"NavCube.top",boundaries:[[7,1,4,4]],dir:[0,-1,0],up:[0,0,-1]},{label:"NavCube.bottom",boundaries:[[7,13,4,4]],dir:[0,1,0],up:[0,0,1]},{boundaries:[[7,5,4,2]],dir:[0,-.7071,-.7071],up:[0,.7071,-.7071]},{boundaries:[[1,6,4,1],[6,1,1,4]],dir:[1,-1,0],up:[1,1,0]},{boundaries:[[7,0,4,1],[19,6,4,1]],dir:[0,-.7071,.7071],up:[0,.7071,.7071]},{boundaries:[[13,6,4,1],[11,1,1,4]],dir:[-1,-1,0],up:[-1,1,0]},{boundaries:[[7,11,4,2]],dir:[0,1,-1],up:[0,1,1]},{boundaries:[[1,11,4,1],[6,13,1,4]],dir:[1,1,0],up:[-1,1,0]},{boundaries:[[7,17,4,1],[19,11,4,1]],dir:[0,1,1],up:[0,1,-1]},{boundaries:[[13,11,4,1],[11,13,1,4]],dir:[-1,1,0],up:[1,1,0]},{boundaries:[[5,7,2,4]],dir:[1,0,-1],up:[0,1,0]},{boundaries:[[11,7,2,4]],dir:[-1,0,-1],up:[0,1,0]},{boundaries:[[17,7,2,4]],dir:[-1,0,1],up:[0,1,0]},{boundaries:[[0,7,1,4],[23,7,1,4]],dir:[1,0,1],up:[0,1,0]},{boundaries:[[5,11,2,2]],dir:[.5,.7071,-.5],up:[-.5,.7071,.5]},{boundaries:[[23,11,1,1],[6,17,1,1],[0,11,1,1]],dir:[.5,.7071,.5],up:[-.5,.7071,-.5]},{boundaries:[[5,5,2,2]],dir:[.5,-.7071,-.5],up:[.5,.7071,-.5]},{boundaries:[[11,17,1,1],[17,11,2,1]],dir:[-.5,.7071,.5],up:[.5,.7071,-.5]},{boundaries:[[17,6,2,1],[11,0,1,1]],dir:[-.5,-.7071,.5],up:[-.5,.7071,.5]},{boundaries:[[11,11,2,2]],dir:[-.5,.7071,-.5],up:[.5,.7071,.5]},{boundaries:[[0,6,1,1],[6,0,1,1],[23,6,1,1]],dir:[.5,-.7071,.5],up:[.5,.7071,.5]},{boundaries:[[11,5,2,2]],dir:[-.5,-.7071,-.5],up:[-.5,.7071,-.5]}],h=0,d=A.length;h=c[0]*l&&t<=(c[0]+c[2])*l&&i>=c[1]*l&&i<=(c[1]+c[3])*l)return s}return-1},this.setAreaHighlighted=function(e,t){var i=v[e];if(!i)throw"Area not found: "+e;i.highlighted=!!t,y()},this.getAreaDir=function(e){var t=v[e];if(!t)throw"Unknown area: "+e;return t.dir},this.getAreaUp=function(e){var t=v[e];if(!t)throw"Unknown area: "+e;return t.up},this.getImage=function(){return this._textureCanvas},this.destroy=function(){this._textureCanvas&&(this._textureCanvas.parentNode.removeChild(this._textureCanvas),this._textureCanvas=null)}}var hF=$.vec3(),dF=$.vec3();$.mat4();var pF=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),s=t.call(this,"NavCube",e,r),e.navCube=b(s);var n=!0;try{s._navCubeScene=new qi(e,{canvasId:r.canvasId,canvasElement:r.canvasElement,transparent:!0}),s._navCubeCanvas=s._navCubeScene.canvas.canvas,s._navCubeScene.input.keyboardEnabled=!1}catch(e){return s.error(e),y(s)}var o=s._navCubeScene;o.clearLights(),new yi(o,{dir:[.4,-.4,.8],color:[.8,1,1],intensity:1,space:"view"}),new yi(o,{dir:[-.8,-.3,-.4],color:[.8,.8,.8],intensity:1,space:"view"}),new yi(o,{dir:[.8,-.6,-.8],color:[1,1,1],intensity:1,space:"view"}),s._navCubeCamera=o.camera,s._navCubeCamera.ortho.scale=7,s._navCubeCamera.ortho.near=.1,s._navCubeCamera.ortho.far=2e3,o.edgeMaterial.edgeColor=[.2,.2,.2],o.edgeMaterial.edgeAlpha=.6,s._zUp=Boolean(e.camera.zUp);var a=b(s);s.setIsProjectNorth(r.isProjectNorth),s.setProjectNorthOffsetAngle(r.projectNorthOffsetAngle);var l,u=(l=$.mat4(),function(e,t,i){return $.identityMat4(l),$.rotationMat4v(e*a._projectNorthOffsetAngle*$.DEGTORAD,[0,1,0],l),$.transformVec3(l,t,i)});s._synchCamera=function(){var t=$.rotationMat4c(-90*$.DEGTORAD,1,0,0),i=$.vec3(),s=$.vec3(),r=$.vec3();return function(){var n=e.camera.eye,o=e.camera.look,l=e.camera.up;i=$.mulVec3Scalar($.normalizeVec3($.subVec3(n,o,i)),5),a._isProjectNorth&&a._projectNorthOffsetAngle&&(i=u(-1,i,hF),l=u(-1,l,dF)),a._zUp?($.transformVec3(t,i,s),$.transformVec3(t,l,r),a._navCubeCamera.look=[0,0,0],a._navCubeCamera.eye=$.transformVec3(t,i,s),a._navCubeCamera.up=$.transformPoint3(t,l,r)):(a._navCubeCamera.look=[0,0,0],a._navCubeCamera.eye=i,a._navCubeCamera.up=l)}}(),s._cubeTextureCanvas=new cF(e,o,r),s._cubeSampler=new Un(o,{image:s._cubeTextureCanvas.getImage(),flipY:!0,wrapS:1001,wrapT:1001}),s._cubeMesh=new rn(o,{geometry:new Si(o,{primitive:"triangles",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],positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],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]}),material:new Oi(o,{diffuse:[.4,.4,.4],specular:[.4,.4,.4],emissive:[.6,.6,.6],diffuseMap:s._cubeSampler,emissiveMap:s._cubeSampler}),visible:!!n,edges:!0}),s._shadow=!1===r.shadowVisible?null:new rn(o,{geometry:new Si(o,on({center:[0,0,0],radiusTop:.001,radiusBottom:1.4,height:.01,radialSegments:20,heightSegments:1,openEnded:!0})),material:new Oi(o,{diffuse:[0,0,0],specular:[0,0,0],emissive:[0,0,0],alpha:.5}),position:[0,-1.5,0],visible:!!n,pickable:!1,backfaces:!1}),s._onCameraMatrix=e.camera.on("matrix",s._synchCamera),s._onCameraWorldAxis=e.camera.on("worldAxis",(function(){e.camera.zUp?(s._zUp=!0,s._cubeTextureCanvas.setZUp(),s._repaint(),s._synchCamera()):e.camera.yUp&&(s._zUp=!1,s._cubeTextureCanvas.setYUp(),s._repaint(),s._synchCamera())})),s._onCameraFOV=e.camera.perspective.on("fov",(function(e){s._synchProjection&&(s._navCubeCamera.perspective.fov=e)})),s._onCameraProjection=e.camera.on("projection",(function(e){s._synchProjection&&(s._navCubeCamera.projection="ortho"===e||"perspective"===e?e:"perspective")}));var A=-1;function c(t,i){var s=(t-d)*-_,r=(i-p)*-_;e.camera.orbitYaw(s),e.camera.orbitPitch(-r),d=t,p=i}function h(e){var t=[0,0];if(e){for(var i=e.target,s=0,r=0;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;t[0]=e.pageX-s,t[1]=e.pageY-r}else e=window.event,t[0]=e.x,t[1]=e.y;return t}var d,p,f=null,v=null,g=!1,m=!1,_=.5;a._navCubeCanvas.addEventListener("mouseenter",a._onMouseEnter=function(e){m=!0}),a._navCubeCanvas.addEventListener("mouseleave",a._onMouseLeave=function(e){m=!1}),a._navCubeCanvas.addEventListener("mousedown",a._onMouseDown=function(e){if(1===e.which){f=e.x,v=e.y,d=e.clientX,p=e.clientY;var t=h(e),i=o.pick({canvasPos:t});g=!!i}}),document.addEventListener("mouseup",a._onMouseUp=function(e){if(1===e.which&&(g=!1,null!==f)){var t=h(e),i=o.pick({canvasPos:t,pickSurface:!0});if(i&&i.uv){var s=a._cubeTextureCanvas.getArea(i.uv);if(s>=0&&(document.body.style.cursor="pointer",A>=0&&(a._cubeTextureCanvas.setAreaHighlighted(A,!1),a._repaint(),A=-1),s>=0)){if(a._cubeTextureCanvas.setAreaHighlighted(s,!0),A=s,a._repaint(),e.xf+3||e.yv+3)return;var r=a._cubeTextureCanvas.getAreaDir(s);if(r){var n=a._cubeTextureCanvas.getAreaUp(s);a._isProjectNorth&&a._projectNorthOffsetAngle&&(r=u(1,r,hF),n=u(1,n,dF)),B(r,n,(function(){A>=0&&(a._cubeTextureCanvas.setAreaHighlighted(A,!1),a._repaint(),A=-1),document.body.style.cursor="pointer",A>=0&&(a._cubeTextureCanvas.setAreaHighlighted(A,!1),a._repaint(),A=-1),s>=0&&(a._cubeTextureCanvas.setAreaHighlighted(s,!1),A=-1,a._repaint())}))}}}}}),document.addEventListener("mousemove",a._onMouseMove=function(e){if(A>=0&&(a._cubeTextureCanvas.setAreaHighlighted(A,!1),a._repaint(),A=-1),1!==e.buttons||g){if(g){var t=e.clientX,i=e.clientY;return document.body.style.cursor="move",void c(t,i)}if(m){var s=h(e),r=o.pick({canvasPos:s,pickSurface:!0});if(r){if(r.uv){document.body.style.cursor="pointer";var n=a._cubeTextureCanvas.getArea(r.uv);if(n===A)return;A>=0&&a._cubeTextureCanvas.setAreaHighlighted(A,!1),n>=0&&(a._cubeTextureCanvas.setAreaHighlighted(n,!0),a._repaint(),A=n)}}else document.body.style.cursor="default",A>=0&&(a._cubeTextureCanvas.setAreaHighlighted(A,!1),a._repaint(),A=-1)}}});var B=function(){var t=$.vec3();return function(i,s,r){var n=a._fitVisible?e.scene.getAABB(e.scene.visibleObjectIds):e.scene.aabb,o=$.getAABB3Diag(n);$.getAABB3Center(n,t);var l=Math.abs(o/Math.tan(a._cameraFitFOV*$.DEGTORAD));e.cameraControl.pivotPos=t,a._cameraFly?e.cameraFlight.flyTo({look:t,eye:[t[0]-l*i[0],t[1]-l*i[1],t[2]-l*i[2]],up:s||[0,1,0],orthoScale:1.1*o,fitFOV:a._cameraFitFOV,duration:a._cameraFlyDuration},r):e.cameraFlight.jumpTo({look:t,eye:[t[0]-l*i[0],t[1]-l*i[1],t[2]-l*i[2]],up:s||[0,1,0],orthoScale:1.1*o,fitFOV:a._cameraFitFOV},r)}}();return s._onUpdated=e.localeService.on("updated",(function(){s._cubeTextureCanvas.clear(),s._repaint()})),s.setVisible(r.visible),s.setCameraFitFOV(r.cameraFitFOV),s.setCameraFly(r.cameraFly),s.setCameraFlyDuration(r.cameraFlyDuration),s.setFitVisible(r.fitVisible),s.setSynchProjection(r.synchProjection),s}return C(i,[{key:"send",value:function(e,t){if("language"===e)this._cubeTextureCanvas.clear(),this._repaint()}},{key:"_repaint",value:function(){var e=this._cubeTextureCanvas.getImage();this._cubeMesh.material.diffuseMap.image=e,this._cubeMesh.material.emissiveMap.image=e}},{key:"setVisible",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this._navCubeCanvas&&(this._cubeMesh.visible=e,this._shadow&&(this._shadow.visible=e),this._navCubeCanvas.style.visibility=e?"visible":"hidden")}},{key:"getVisible",value:function(){return!!this._navCubeCanvas&&this._cubeMesh.visible}},{key:"setFitVisible",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._fitVisible=e}},{key:"getFitVisible",value:function(){return this._fitVisible}},{key:"setCameraFly",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this._cameraFly=e}},{key:"getCameraFly",value:function(){return this._cameraFly}},{key:"setCameraFitFOV",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:45;this._cameraFitFOV=e}},{key:"getCameraFitFOV",value:function(){return this._cameraFitFOV}},{key:"setCameraFlyDuration",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:.5;this._cameraFlyDuration=e}},{key:"getCameraFlyDuration",value:function(){return this._cameraFlyDuration}},{key:"setSynchProjection",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._synchProjection=e}},{key:"getSynchProjection",value:function(){return this._synchProjection}},{key:"setIsProjectNorth",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._isProjectNorth=e}},{key:"getIsProjectNorth",value:function(){return this._isProjectNorth}},{key:"setProjectNorthOffsetAngle",value:function(e){this._projectNorthOffsetAngle=e}},{key:"getProjectNorthOffsetAngle",value:function(){return this._projectNorthOffsetAngle}},{key:"destroy",value:function(){this._navCubeCanvas&&(this.viewer.localeService.off(this._onUpdated),this.viewer.camera.off(this._onCameraMatrix),this.viewer.camera.off(this._onCameraWorldAxis),this.viewer.camera.perspective.off(this._onCameraFOV),this.viewer.camera.off(this._onCameraProjection),this._navCubeCanvas.removeEventListener("mouseenter",this._onMouseEnter),this._navCubeCanvas.removeEventListener("mouseleave",this._onMouseLeave),this._navCubeCanvas.removeEventListener("mousedown",this._onMouseDown),document.removeEventListener("mousemove",this._onMouseMove),document.removeEventListener("mouseup",this._onMouseUp),this._navCubeCanvas=null,this._cubeTextureCanvas.destroy(),this._cubeTextureCanvas=null,this._onMouseEnter=null,this._onMouseLeave=null,this._onMouseDown=null,this._onMouseMove=null,this._onMouseUp=null),this._navCubeScene.destroy(),this._navCubeScene=null,this._cubeMesh=null,this._shadow=null,f(B(i.prototype),"destroy",this).call(this)}}]),i}(),fF=$.vec3(),vF=function(){function e(){x(this,e)}return C(e,[{key:"load",value:function(e,t){var i=e.scene.canvas.spinner;i.processes++,gF(e,t,(function(t){_F(e,t,(function(){BF(e,t),i.processes--,_e.scheduleTask((function(){e.fire("loaded",!0,!1)}))}))}))}},{key:"parse",value:function(e,t,i,s){if(t){var r=mF(e,t,null);i&&bF(e,i,s),BF(e,r),e.src=null,e.fire("loaded",!0,!1)}else this.warn("load() param expected: objText")}}]),e}(),gF=function(e,t,i){wF(t,(function(s){var r=mF(e,s,t);i(r)}),(function(t){e.error(t)}))},mF=function(){var e={vertex_pattern:/^v\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,normal_pattern:/^vn\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,uv_pattern:/^vt\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,face_vertex:/^f\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)(?:\s+(-?\d+))?/,face_vertex_uv:/^f\s+(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)(?:\s+(-?\d+)\/(-?\d+))?/,face_vertex_uv_normal:/^f\s+(-?\d+)\/(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\/(-?\d+)(?:\s+(-?\d+)\/(-?\d+)\/(-?\d+))?/,face_vertex_normal:/^f\s+(-?\d+)\/\/(-?\d+)\s+(-?\d+)\/\/(-?\d+)\s+(-?\d+)\/\/(-?\d+)(?:\s+(-?\d+)\/\/(-?\d+))?/,object_pattern:/^[og]\s*(.+)?/,smoothing_pattern:/^s\s+(\d+|on|off)/,material_library_pattern:/^mtllib /,material_use_pattern:/^usemtl /};return function(s,r,n){var o={src:n=n||"",basePath:t(n),objects:[],object:{},positions:[],normals:[],uv:[],materialLibraries:{}};i(o,"",!1),-1!==r.indexOf("\r\n")&&(r=r.replace("\r\n","\n"));for(var a=r.split("\n"),l="",u="",A="",d=[],p="function"==typeof"".trimLeft,f=0,v=a.length;f=0?i-1:i+t/3)}function r(e,t){var i=parseInt(e,10);return 3*(i>=0?i-1:i+t/3)}function n(e,t){var i=parseInt(e,10);return 2*(i>=0?i-1:i+t/2)}function o(e,t,i,s){var r=e.positions,n=e.object.geometry.positions;n.push(r[t+0]),n.push(r[t+1]),n.push(r[t+2]),n.push(r[i+0]),n.push(r[i+1]),n.push(r[i+2]),n.push(r[s+0]),n.push(r[s+1]),n.push(r[s+2])}function a(e,t){var i=e.positions,s=e.object.geometry.positions;s.push(i[t+0]),s.push(i[t+1]),s.push(i[t+2])}function l(e,t,i,s){var r=e.normals,n=e.object.geometry.normals;n.push(r[t+0]),n.push(r[t+1]),n.push(r[t+2]),n.push(r[i+0]),n.push(r[i+1]),n.push(r[i+2]),n.push(r[s+0]),n.push(r[s+1]),n.push(r[s+2])}function u(e,t,i,s){var r=e.uv,n=e.object.geometry.uv;n.push(r[t+0]),n.push(r[t+1]),n.push(r[i+0]),n.push(r[i+1]),n.push(r[s+0]),n.push(r[s+1])}function A(e,t){var i=e.uv,s=e.object.geometry.uv;s.push(i[t+0]),s.push(i[t+1])}function c(e,t,i,a,A,c,h,d,p,f,v,g,m){var _,y=e.positions.length,b=s(t,y),B=s(i,y),w=s(a,y);if(void 0===A?o(e,b,B,w):(o(e,b,B,_=s(A,y)),o(e,B,w,_)),void 0!==c){var x=e.uv.length;b=n(c,x),B=n(h,x),w=n(d,x),void 0===A?u(e,b,B,w):(u(e,b,B,_=n(p,x)),u(e,B,w,_))}if(void 0!==f){var P=e.normals.length;b=r(f,P),B=f===v?b:r(v,P),w=f===g?b:r(g,P),void 0===A?l(e,b,B,w):(l(e,b,B,_=r(m,P)),l(e,B,w,_))}}function h(e,t,i){e.object.geometry.type="Line";for(var r=e.positions.length,o=e.uv.length,l=0,u=t.length;l=0?o.substring(0,a):o).toLowerCase(),u=(u=a>=0?o.substring(a+1):"").trim(),l.toLowerCase()){case"newmtl":i(e,h),h={id:u},d=!0;break;case"ka":h.ambient=s(u);break;case"kd":h.diffuse=s(u);break;case"ks":h.specular=s(u);break;case"map_kd":h.diffuseMap||(h.diffuseMap=t(e,n,u,"sRGB"));break;case"map_ks":h.specularMap||(h.specularMap=t(e,n,u,"linear"));break;case"map_bump":case"bump":h.normalMap||(h.normalMap=t(e,n,u));break;case"ns":h.shininess=parseFloat(u);break;case"d":(A=parseFloat(u))<1&&(h.alpha=A,h.alphaMode="blend");break;case"tr":(A=parseFloat(u))>0&&(h.alpha=1-A,h.alphaMode="blend")}d&&i(e,h)};function t(e,t,i,s){var r={},n=i.split(/\s+/),o=n.indexOf("-bm");return o>=0&&n.splice(o,2),(o=n.indexOf("-s"))>=0&&(r.scale=[parseFloat(n[o+1]),parseFloat(n[o+2])],n.splice(o,4)),(o=n.indexOf("-o"))>=0&&(r.translate=[parseFloat(n[o+1]),parseFloat(n[o+2])],n.splice(o,4)),r.src=t+n.join(" ").trim(),r.flipY=!0,r.encoding=s||"linear",new Un(e,r).id}function i(e,t){new Oi(e,t)}function s(t){var i=t.split(e,3);return[parseFloat(i[0]),parseFloat(i[1]),parseFloat(i[2])]}}();function BF(e,t){for(var i=0,s=t.objects.length;i0&&(o.normals=n.normals),n.uv.length>0&&(o.uv=n.uv);for(var a=new Array(o.positions.length/3),l=0;l0&&void 0!==arguments[0]?arguments[0]:{};t.id&&this.viewer.scene.components[t.id]&&(this.error("Component with this ID already exists in viewer: "+t.id+" - will autogenerate this ID"),delete t.id);var i=new bn(this.viewer.scene,le.apply(t,{isModel:!0})),s=i.id,r=t.src;if(!r)return this.error("load() param expected: src"),i;if(t.metaModelSrc){var n=t.metaModelSrc;le.loadJSON(n,(function(n){e.viewer.metaScene.createMetaModel(s,n),e._sceneGraphLoader.load(i,r,t)}),(function(t){e.error("load(): Failed to load model modelMetadata for model '".concat(s," from '").concat(n,"' - ").concat(t))}))}else this._sceneGraphLoader.load(i,r,t);return i.once("destroyed",(function(){e.viewer.metaScene.destroyMetaModel(s)})),i}},{key:"destroy",value:function(){f(B(i.prototype),"destroy",this).call(this)}}]),i}(),PF=new Float64Array([0,0,1]),CF=new Float64Array(4),MF=function(){function e(t){x(this,e),this.id=null,this._viewer=t.viewer,this._visible=!1,this._pos=$.vec3(),this._origin=$.vec3(),this._rtcPos=$.vec3(),this._baseDir=$.vec3(),this._rootNode=null,this._displayMeshes=null,this._affordanceMeshes=null,this._ignoreNextSectionPlaneDirUpdate=!1,this._createNodes(),this._bindEvents()}return C(e,[{key:"_setSectionPlane",value:function(e){var t=this;this._sectionPlane&&(this._sectionPlane.off(this._onSectionPlanePos),this._sectionPlane.off(this._onSectionPlaneDir),this._onSectionPlanePos=null,this._onSectionPlaneDir=null,this._sectionPlane=null),e&&(this.id=e.id,this._setPos(e.pos),this._setDir(e.dir),this._sectionPlane=e,this._onSectionPlanePos=e.on("pos",(function(){t._setPos(t._sectionPlane.pos)})),this._onSectionPlaneDir=e.on("dir",(function(){t._ignoreNextSectionPlaneDirUpdate?t._ignoreNextSectionPlaneDirUpdate=!1:t._setDir(t._sectionPlane.dir)})))}},{key:"sectionPlane",get:function(){return this._sectionPlane}},{key:"_setPos",value:function(e){this._pos.set(e),Le(this._pos,this._origin,this._rtcPos),this._rootNode.origin=this._origin,this._rootNode.position=this._rtcPos}},{key:"_setDir",value:function(e){this._baseDir.set(e),this._rootNode.quaternion=$.vec3PairToQuaternion(PF,e,CF)}},{key:"_setSectionPlaneDir",value:function(e){this._sectionPlane&&(this._ignoreNextSectionPlaneDirUpdate=!0,this._sectionPlane.dir=e)}},{key:"setVisible",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(this._visible!==e){var t;for(t in this._visible=e,this._displayMeshes)this._displayMeshes.hasOwnProperty(t)&&(this._displayMeshes[t].visible=e);if(!e)for(t in this._affordanceMeshes)this._affordanceMeshes.hasOwnProperty(t)&&(this._affordanceMeshes[t].visible=e)}}},{key:"getVisible",value:function(){return this._visible}},{key:"setCulled",value:function(e){var t;for(t in this._displayMeshes)this._displayMeshes.hasOwnProperty(t)&&(this._displayMeshes[t].culled=e);if(!e)for(t in this._affordanceMeshes)this._affordanceMeshes.hasOwnProperty(t)&&(this._affordanceMeshes[t].culled=e)}},{key:"_createNodes",value:function(){var e=!1,t=this._viewer.scene,i=.01;this._rootNode=new bn(t,{position:[0,0,0],scale:[5,5,5],isObject:!1});var s,r,n=this._rootNode,o={arrowHead:new Si(n,on({radiusTop:.001,radiusBottom:.07,radialSegments:32,heightSegments:1,height:.2,openEnded:!1})),arrowHeadBig:new Si(n,on({radiusTop:.001,radiusBottom:.09,radialSegments:32,heightSegments:1,height:.25,openEnded:!1})),arrowHeadHandle:new Si(n,on({radiusTop:.09,radiusBottom:.09,radialSegments:8,heightSegments:1,height:.37,openEnded:!1})),curve:new Si(n,Jn({radius:.8,tube:i,radialSegments:64,tubeSegments:14,arc:2*Math.PI/4})),curveHandle:new Si(n,Jn({radius:.8,tube:.06,radialSegments:64,tubeSegments:14,arc:2*Math.PI/4})),hoop:new Si(n,Jn({radius:.8,tube:i,radialSegments:64,tubeSegments:8,arc:2*Math.PI})),axis:new Si(n,on({radiusTop:i,radiusBottom:i,radialSegments:20,heightSegments:1,height:1,openEnded:!1})),axisHandle:new Si(n,on({radiusTop:.08,radiusBottom:.08,radialSegments:20,heightSegments:1,height:1,openEnded:!1}))},a={pickable:new Oi(n,{diffuse:[1,1,0],alpha:0,alphaMode:"blend"}),red:new Oi(n,{diffuse:[1,0,0],emissive:[1,0,0],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),highlightRed:new Qi(n,{edges:!1,fill:!0,fillColor:[1,0,0],fillAlpha:.6}),green:new Oi(n,{diffuse:[0,1,0],emissive:[0,1,0],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),highlightGreen:new Qi(n,{edges:!1,fill:!0,fillColor:[0,1,0],fillAlpha:.6}),blue:new Oi(n,{diffuse:[0,0,1],emissive:[0,0,1],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),highlightBlue:new Qi(n,{edges:!1,fill:!0,fillColor:[0,0,1],fillAlpha:.2}),center:new Oi(n,{diffuse:[0,0,0],emissive:[0,0,0],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80}),highlightBall:new Qi(n,{edges:!1,fill:!0,fillColor:[.5,.5,.5],fillAlpha:.5,vertices:!1}),highlightPlane:new Qi(n,{edges:!0,edgeWidth:3,fill:!1,fillColor:[.5,.5,.5],fillAlpha:.5,vertices:!1})};this._displayMeshes={plane:n.addChild(new rn(n,{geometry:new Si(n,{primitive:"triangles",positions:[.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0,.5,.5,-0,.5,-.5,-0,-.5,-.5,-0,-.5,.5,-0],indices:[0,1,2,2,3,0]}),material:new Oi(n,{emissive:[0,0,0],diffuse:[0,0,0],backfaces:!0}),opacity:.6,ghosted:!0,ghostMaterial:new Qi(n,{edges:!1,filled:!0,fillColor:[1,1,0],edgeColor:[0,0,0],fillAlpha:.1,backfaces:!0}),pickable:!1,collidable:!0,clippable:!1,visible:!1,scale:[2.4,2.4,1],isObject:!1}),e),planeFrame:n.addChild(new rn(n,{geometry:new Si(n,Jn({center:[0,0,0],radius:1.7,tube:.02,radialSegments:4,tubeSegments:4,arc:2*Math.PI})),material:new Oi(n,{emissive:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],shininess:0}),highlightMaterial:new Qi(n,{edges:!1,edgeColor:[0,0,0],filled:!0,fillColor:[.8,.8,.8],fillAlpha:1}),pickable:!1,collidable:!1,clippable:!1,visible:!1,scale:[1,1,.1],rotation:[0,0,45],isObject:!1}),e),xCurve:n.addChild(new rn(n,{geometry:o.curve,material:a.red,matrix:(s=$.rotationMat4v(90*$.DEGTORAD,[0,1,0],$.identityMat4()),r=$.rotationMat4v(270*$.DEGTORAD,[1,0,0],$.identityMat4()),$.mulMat4(r,s,$.identityMat4())),pickable:!1,collidable:!0,clippable:!1,backfaces:!0,visible:!1,isObject:!1}),e),xCurveHandle:n.addChild(new rn(n,{geometry:o.curveHandle,material:a.pickable,matrix:function(){var e=$.rotationMat4v(90*$.DEGTORAD,[0,1,0],$.identityMat4()),t=$.rotationMat4v(270*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,backfaces:!0,visible:!1,isObject:!1}),e),xCurveArrow1:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.red,matrix:function(){var e=$.translateMat4c(0,-.07,-.8,$.identityMat4()),t=$.scaleMat4v([.6,.6,.6],$.identityMat4()),i=$.rotationMat4v(0*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4($.mulMat4(e,t,$.identityMat4()),i,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),xCurveArrow2:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.red,matrix:function(){var e=$.translateMat4c(0,-.8,-.07,$.identityMat4()),t=$.scaleMat4v([.6,.6,.6],$.identityMat4()),i=$.rotationMat4v(90*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4($.mulMat4(e,t,$.identityMat4()),i,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yCurve:n.addChild(new rn(n,{geometry:o.curve,material:a.green,rotation:[-90,0,0],pickable:!1,collidable:!0,clippable:!1,backfaces:!0,visible:!1,isObject:!1}),e),yCurveHandle:n.addChild(new rn(n,{geometry:o.curveHandle,material:a.pickable,rotation:[-90,0,0],pickable:!0,collidable:!0,clippable:!1,backfaces:!0,visible:!1,isObject:!1}),e),yCurveArrow1:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.green,matrix:function(){var e=$.translateMat4c(.07,0,-.8,$.identityMat4()),t=$.scaleMat4v([.6,.6,.6],$.identityMat4()),i=$.rotationMat4v(90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4($.mulMat4(e,t,$.identityMat4()),i,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yCurveArrow2:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.green,matrix:function(){var e=$.translateMat4c(.8,0,-.07,$.identityMat4()),t=$.scaleMat4v([.6,.6,.6],$.identityMat4()),i=$.rotationMat4v(90*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4($.mulMat4(e,t,$.identityMat4()),i,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zCurve:n.addChild(new rn(n,{geometry:o.curve,material:a.blue,matrix:$.rotationMat4v(180*$.DEGTORAD,[1,0,0],$.identityMat4()),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zCurveHandle:n.addChild(new rn(n,{geometry:o.curveHandle,material:a.pickable,matrix:$.rotationMat4v(180*$.DEGTORAD,[1,0,0],$.identityMat4()),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zCurveCurveArrow1:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.blue,matrix:function(){var e=$.translateMat4c(.8,-.07,0,$.identityMat4()),t=$.scaleMat4v([.6,.6,.6],$.identityMat4());return $.mulMat4(e,t,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zCurveArrow2:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.blue,matrix:function(){var e=$.translateMat4c(.05,-.8,0,$.identityMat4()),t=$.scaleMat4v([.6,.6,.6],$.identityMat4()),i=$.rotationMat4v(90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4($.mulMat4(e,t,$.identityMat4()),i,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),center:n.addChild(new rn(n,{geometry:new Si(n,an({radius:.05})),material:a.center,pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),xAxisArrow:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.red,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),xAxisArrowHandle:n.addChild(new rn(n,{geometry:o.arrowHeadHandle,material:a.pickable,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),xAxis:n.addChild(new rn(n,{geometry:o.axis,material:a.red,matrix:function(){var e=$.translateMat4c(0,.5,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),xAxisHandle:n.addChild(new rn(n,{geometry:o.axisHandle,material:a.pickable,matrix:function(){var e=$.translateMat4c(0,.5,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yAxisArrow:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.green,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(180*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yAxisArrowHandle:n.addChild(new rn(n,{geometry:o.arrowHeadHandle,material:a.pickable,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(180*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,opacity:.2,isObject:!1}),e),yShaft:n.addChild(new rn(n,{geometry:o.axis,material:a.green,position:[0,-.5,0],pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yShaftHandle:n.addChild(new rn(n,{geometry:o.axisHandle,material:a.pickable,position:[0,-.5,0],pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zAxisArrow:n.addChild(new rn(n,{geometry:o.arrowHead,material:a.blue,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[.8,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zAxisArrowHandle:n.addChild(new rn(n,{geometry:o.arrowHeadHandle,material:a.pickable,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[.8,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!0,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zShaft:n.addChild(new rn(n,{geometry:o.axis,material:a.blue,matrix:function(){var e=$.translateMat4c(0,.5,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),clippable:!1,pickable:!1,collidable:!0,visible:!1,isObject:!1}),e),zAxisHandle:n.addChild(new rn(n,{geometry:o.axisHandle,material:a.pickable,matrix:function(){var e=$.translateMat4c(0,.5,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),clippable:!1,pickable:!0,collidable:!0,visible:!1,isObject:!1}),e)},this._affordanceMeshes={planeFrame:n.addChild(new rn(n,{geometry:new Si(n,Jn({center:[0,0,0],radius:2,tube:i,radialSegments:4,tubeSegments:4,arc:2*Math.PI})),material:new Oi(n,{ambient:[1,1,1],diffuse:[0,0,0],emissive:[1,1,0]}),highlighted:!0,highlightMaterial:new Qi(n,{edges:!1,filled:!0,fillColor:[1,1,0],fillAlpha:1}),pickable:!1,collidable:!1,clippable:!1,visible:!1,scale:[1,1,1],rotation:[0,0,45],isObject:!1}),e),xHoop:n.addChild(new rn(n,{geometry:o.hoop,material:a.red,highlighted:!0,highlightMaterial:a.highlightRed,matrix:function(){var e=$.rotationMat4v(90*$.DEGTORAD,[0,1,0],$.identityMat4()),t=$.rotationMat4v(270*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yHoop:n.addChild(new rn(n,{geometry:o.hoop,material:a.green,highlighted:!0,highlightMaterial:a.highlightGreen,rotation:[-90,0,0],pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zHoop:n.addChild(new rn(n,{geometry:o.hoop,material:a.blue,highlighted:!0,highlightMaterial:a.highlightBlue,matrix:$.rotationMat4v(180*$.DEGTORAD,[1,0,0],$.identityMat4()),pickable:!1,collidable:!0,clippable:!1,backfaces:!0,visible:!1,isObject:!1}),e),xAxisArrow:n.addChild(new rn(n,{geometry:o.arrowHeadBig,material:a.red,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[0,0,1],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),yAxisArrow:n.addChild(new rn(n,{geometry:o.arrowHeadBig,material:a.green,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(180*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e),zAxisArrow:n.addChild(new rn(n,{geometry:o.arrowHeadBig,material:a.blue,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[.8,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1,isObject:!1}),e)}}},{key:"_bindEvents",value:function(){var e=this,t=this,i=!1,s=-1,r=0,n=1,o=2,a=3,l=4,u=5,A=this._rootNode,c=null,h=null,d=$.vec2(),p=$.vec3([1,0,0]),f=$.vec3([0,1,0]),v=$.vec3([0,0,1]),g=this._viewer.scene.canvas.canvas,m=this._viewer.camera,_=this._viewer.scene,y=$.vec3([0,0,0]),b=-1;this._onCameraViewMatrix=_.camera.on("viewMatrix",(function(){})),this._onCameraProjMatrix=_.camera.on("projMatrix",(function(){})),this._onSceneTick=_.on("tick",(function(){var t=Math.abs($.lenVec3($.subVec3(_.camera.eye,e._pos,y)));if(t!==b&&"perspective"===m.projection){var i=.07*(Math.tan(m.perspective.fov*$.DEGTORAD)*t);A.scale=[i,i,i],b=t}if("ortho"===m.projection){var s=m.ortho.scale/10;A.scale=[s,s,s],b=t}}));var B,w,x,P,C,M=function(){var e=new Float64Array(2);return function(t){if(t){for(var i=t.target,s=0,r=0;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;e[0]=t.pageX-s,e[1]=t.pageY-r}else t=window.event,e[0]=t.x,e[1]=t.y;return e}}(),F=function(){var e=$.mat4();return function(i,s){return $.quaternionToMat4(t._rootNode.quaternion,e),$.transformVec3(e,i,s),$.normalizeVec3(s),s}}(),E=(B=$.vec3(),function(e){var t=Math.abs(e[0]);return t>Math.abs(e[1])&&t>Math.abs(e[2])?$.cross3Vec3(e,[0,1,0],B):$.cross3Vec3(e,[1,0,0],B),$.cross3Vec3(B,e,B),$.normalizeVec3(B),B}),k=(w=$.vec3(),x=$.vec3(),P=$.vec4(),function(e,i,s){F(e,P);var r=E(P,i,s);D(i,r,w),D(s,r,x),$.subVec3(x,w);var n=$.dotVec3(x,P);t._pos[0]+=P[0]*n,t._pos[1]+=P[1]*n,t._pos[2]+=P[2]*n,t._rootNode.position=t._pos,t._sectionPlane&&(t._sectionPlane.pos=t._pos)}),I=function(){var e=$.vec4(),i=$.vec4(),s=$.vec4(),r=$.vec4();return function(n,o,a){if(F(n,r),!(D(o,r,e)&&D(a,r,i))){var l=E(r,o,a);D(o,l,e,1),D(a,l,i,1);var u=$.dotVec3(e,r);e[0]-=u*r[0],e[1]-=u*r[1],e[2]-=u*r[2],u=$.dotVec3(i,r),i[0]-=u*r[0],i[1]-=u*r[1],i[2]-=u*r[2]}$.normalizeVec3(e),$.normalizeVec3(i),u=$.dotVec3(e,i),u=$.clamp(u,-1,1);var A=Math.acos(u)*$.RADTODEG;$.cross3Vec3(e,i,s),$.dotVec3(s,r)<0&&(A=-A),t._rootNode.rotate(n,A),S()}}(),D=function(){var e=$.vec4([0,0,0,1]),i=$.mat4();return function(s,r,n,o){o=o||0,e[0]=s[0]/g.width*2-1,e[1]=-(s[1]/g.height*2-1),e[2]=0,e[3]=1,$.mulMat4(m.projMatrix,m.viewMatrix,i),$.inverseMat4(i),$.transformVec4(i,e,e),$.mulVec4Scalar(e,1/e[3]);var a=m.eye;$.subVec4(e,a,e);var l=t._sectionPlane.pos,u=-$.dotVec3(l,r)-o,A=$.dotVec3(r,e);if(Math.abs(A)>.005){var c=-($.dotVec3(r,a)+u)/A;return $.mulVec3Scalar(e,c,n),$.addVec3(n,a),$.subVec3(n,l,n),!0}return!1}}(),S=function(){var e=$.vec3(),i=$.mat4();return function(){t.sectionPlane&&($.quaternionToMat4(A.quaternion,i),$.transformVec3(i,[0,0,1],e),t._setSectionPlaneDir(e))}}(),T=!1;this._onCameraControlHover=this._viewer.cameraControl.on("hoverEnter",(function(t){if(e._visible&&!T){var A;switch(i=!1,C&&(C.visible=!1),t.entity.id){case e._displayMeshes.xAxisArrowHandle.id:case e._displayMeshes.xAxisHandle.id:A=e._affordanceMeshes.xAxisArrow,c=r;break;case e._displayMeshes.yAxisArrowHandle.id:case e._displayMeshes.yShaftHandle.id:A=e._affordanceMeshes.yAxisArrow,c=n;break;case e._displayMeshes.zAxisArrowHandle.id:case e._displayMeshes.zAxisHandle.id:A=e._affordanceMeshes.zAxisArrow,c=o;break;case e._displayMeshes.xCurveHandle.id:A=e._affordanceMeshes.xHoop,c=a;break;case e._displayMeshes.yCurveHandle.id:A=e._affordanceMeshes.yHoop,c=l;break;case e._displayMeshes.zCurveHandle.id:A=e._affordanceMeshes.zHoop,c=u;break;default:return void(c=s)}A&&(A.visible=!0),C=A,i=!0}})),this._onCameraControlHoverLeave=this._viewer.cameraControl.on("hoverOutEntity",(function(t){e._visible&&(C&&(C.visible=!1),C=null,c=s)})),g.addEventListener("mousedown",this._canvasMouseDownListener=function(t){if(t.preventDefault(),e._visible&&i&&(e._viewer.cameraControl.pointerEnabled=!1,1===t.which)){T=!0;var s=M(t);h=c,d[0]=s[0],d[1]=s[1]}}),g.addEventListener("mousemove",this._canvasMouseMoveListener=function(t){if(e._visible&&T){var i=M(t),s=i[0],A=i[1];switch(h){case r:k(p,d,i);break;case n:k(f,d,i);break;case o:k(v,d,i);break;case a:I(p,d,i);break;case l:I(f,d,i);break;case u:I(v,d,i)}d[0]=s,d[1]=A}}),g.addEventListener("mouseup",this._canvasMouseUpListener=function(t){e._visible&&(e._viewer.cameraControl.pointerEnabled=!0,T&&(t.which,T=!1,i=!1))}),g.addEventListener("wheel",this._canvasWheelListener=function(t){if(e._visible)Math.max(-1,Math.min(1,40*-t.deltaY))})}},{key:"_destroy",value:function(){this._unbindEvents(),this._destroyNodes()}},{key:"_unbindEvents",value:function(){var e=this._viewer,t=e.scene,i=t.canvas.canvas,s=e.camera,r=e.cameraControl;t.off(this._onSceneTick),i.removeEventListener("mousedown",this._canvasMouseDownListener),i.removeEventListener("mousemove",this._canvasMouseMoveListener),i.removeEventListener("mouseup",this._canvasMouseUpListener),i.removeEventListener("wheel",this._canvasWheelListener),s.off(this._onCameraViewMatrix),s.off(this._onCameraProjMatrix),r.off(this._onCameraControlHover),r.off(this._onCameraControlHoverLeave)}},{key:"_destroyNodes",value:function(){this._setSectionPlane(null),this._rootNode.destroy(),this._displayMeshes={},this._affordanceMeshes={}}}]),e}(),FF=function(){function e(t,i,s){var r=this;x(this,e),this.id=s.id,this._sectionPlane=s,this._mesh=new rn(i,{id:s.id,geometry:new Si(i,Ti({xSize:.5,ySize:.5,zSize:.001})),material:new Oi(i,{emissive:[1,1,1],diffuse:[0,0,0],backfaces:!1}),edgeMaterial:new Hi(i,{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1}),highlightMaterial:new Qi(i,{fill:!0,fillColor:[.5,1,.5],fillAlpha:.7,edges:!0,edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1}),selectedMaterial:new Qi(i,{fill:!0,fillColor:[0,0,1],fillAlpha:.7,edges:!0,edgeColor:[1,0,0],edgeAlpha:1,edgeWidth:1}),highlighted:!0,scale:[3,3,3],position:[0,0,0],rotation:[0,0,0],opacity:.3,edges:!0});var n=$.vec3([0,0,0]),o=$.vec3(),a=$.vec3([0,0,1]),l=$.vec4(4),u=$.vec3(),A=function(){var e=r._sectionPlane.scene.center,t=[-r._sectionPlane.dir[0],-r._sectionPlane.dir[1],-r._sectionPlane.dir[2]];$.subVec3(e,r._sectionPlane.pos,n);var i=-$.dotVec3(t,n);$.normalizeVec3(t),$.mulVec3Scalar(t,i,o);var s=$.vec3PairToQuaternion(a,r._sectionPlane.dir,l);u[0]=.1*o[0],u[1]=.1*o[1],u[2]=.1*o[2],r._mesh.quaternion=s,r._mesh.position=u};this._onSectionPlanePos=this._sectionPlane.on("pos",A),this._onSectionPlaneDir=this._sectionPlane.on("dir",A),this._highlighted=!1,this._selected=!1}return C(e,[{key:"setHighlighted",value:function(e){this._highlighted=!!e,this._mesh.highlighted=this._highlighted,this._mesh.highlightMaterial.fillColor=e?[0,.7,0]:[0,0,0]}},{key:"getHighlighted",value:function(){return this._highlighted}},{key:"setSelected",value:function(e){this._selected=!!e,this._mesh.edgeMaterial.edgeWidth=e?3:1,this._mesh.highlightMaterial.edgeWidth=e?3:1}},{key:"getSelected",value:function(){return this._selected}},{key:"destroy",value:function(){this._sectionPlane.off(this._onSectionPlanePos),this._sectionPlane.off(this._onSectionPlaneDir),this._mesh.destroy()}}]),e}(),EF=function(){function e(t,i){var s=this;if(x(this,e),!(i.onHoverEnterPlane&&i.onHoverLeavePlane&&i.onClickedNothing&&i.onClickedPlane))throw"Missing config(s): onHoverEnterPlane, onHoverLeavePlane, onClickedNothing || onClickedPlane";this.plugin=t,this._viewer=t.viewer,this._onHoverEnterPlane=i.onHoverEnterPlane,this._onHoverLeavePlane=i.onHoverLeavePlane,this._onClickedNothing=i.onClickedNothing,this._onClickedPlane=i.onClickedPlane,this._visible=!0,this._planes={},this._canvas=i.overviewCanvas,this._scene=new qi(this._viewer,{canvasId:this._canvas.id,transparent:!0}),this._scene.clearLights(),new yi(this._scene,{dir:[.4,-.4,.8],color:[.8,1,1],intensity:1,space:"view"}),new yi(this._scene,{dir:[-.8,-.3,-.4],color:[.8,.8,.8],intensity:1,space:"view"}),new yi(this._scene,{dir:[.8,-.6,-.8],color:[1,1,1],intensity:1,space:"view"}),this._scene.camera,this._scene.camera.perspective.fov=70,this._zUp=!1;var r=this._scene.camera,n=$.rotationMat4c(-90*$.DEGTORAD,1,0,0),o=$.vec3(),a=$.vec3(),l=$.vec3();this._synchCamera=function(){var e=s._viewer.camera.eye,t=s._viewer.camera.look,i=s._viewer.camera.up;$.mulVec3Scalar($.normalizeVec3($.subVec3(e,t,o)),7),s._zUp?($.transformVec3(n,o,a),$.transformVec3(n,i,l),r.look=[0,0,0],r.eye=$.transformVec3(n,o,a),r.up=$.transformPoint3(n,i,l)):(r.look=[0,0,0],r.eye=o,r.up=i)},this._onViewerCameraMatrix=this._viewer.camera.on("matrix",this._synchCamera),this._onViewerCameraWorldAxis=this._viewer.camera.on("worldAxis",this._synchCamera),this._onViewerCameraFOV=this._viewer.camera.perspective.on("fov",(function(e){s._scene.camera.perspective.fov=e}));var u=null;this._onInputMouseMove=this._scene.input.on("mousemove",(function(e){var t=s._scene.pick({canvasPos:e});if(t){if(!u||t.entity.id!==u.id){if(u)s._planes[u.id]&&s._onHoverLeavePlane(u.id);u=t.entity,s._planes[u.id]&&s._onHoverEnterPlane(u.id)}}else u&&(s._onHoverLeavePlane(u.id),u=null)})),this._scene.canvas.canvas.addEventListener("mouseup",this._onCanvasMouseUp=function(){u?s._planes[u.id]&&s._onClickedPlane(u.id):s._onClickedNothing()}),this._scene.canvas.canvas.addEventListener("mouseout",this._onCanvasMouseOut=function(){u&&(s._onHoverLeavePlane(u.id),u=null)}),this.setVisible(i.overviewVisible)}return C(e,[{key:"addSectionPlane",value:function(e){this._planes[e.id]=new FF(this,this._scene,e)}},{key:"setPlaneHighlighted",value:function(e,t){var i=this._planes[e];i&&i.setHighlighted(t)}},{key:"setPlaneSelected",value:function(e,t){var i=this._planes[e];i&&i.setSelected(t)}},{key:"removeSectionPlane",value:function(e){var t=this._planes[e.id];t&&(t.destroy(),delete this._planes[e.id])}},{key:"setVisible",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this._visible=e,this._canvas.style.visibility=e?"visible":"hidden"}},{key:"getVisible",value:function(){return this._visible}},{key:"destroy",value:function(){this._viewer.camera.off(this._onViewerCameraMatrix),this._viewer.camera.off(this._onViewerCameraWorldAxis),this._viewer.camera.perspective.off(this._onViewerCameraFOV),this._scene.input.off(this._onInputMouseMove),this._scene.canvas.canvas.removeEventListener("mouseup",this._onCanvasMouseUp),this._scene.canvas.canvas.removeEventListener("mouseout",this._onCanvasMouseOut),this._scene.destroy()}}]),e}(),kF=$.AABB3(),IF=$.vec3(),DF=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,"SectionPlanes",e))._freeControls=[],s._sectionPlanes=e.scene.sectionPlanes,s._controls={},s._shownControlId=null,null!==r.overviewCanvasId&&void 0!==r.overviewCanvasId){var n=document.getElementById(r.overviewCanvasId);n?s._overview=new EF(b(s),{overviewCanvas:n,visible:r.overviewVisible,onHoverEnterPlane:function(e){s._overview.setPlaneHighlighted(e,!0)},onHoverLeavePlane:function(e){s._overview.setPlaneHighlighted(e,!1)},onClickedPlane:function(e){if(s.getShownControl()!==e){s.showControl(e);var t=s.sectionPlanes[e].pos;kF.set(s.viewer.scene.aabb),$.getAABB3Center(kF,IF),kF[0]+=t[0]-IF[0],kF[1]+=t[1]-IF[1],kF[2]+=t[2]-IF[2],kF[3]+=t[0]-IF[0],kF[4]+=t[1]-IF[1],kF[5]+=t[2]-IF[2],s.viewer.cameraFlight.flyTo({aabb:kF,fitFOV:65})}else s.hideControl()},onClickedNothing:function(){s.hideControl()}}):s.warn("Can't find overview canvas: '"+r.overviewCanvasId+"' - will create plugin without overview")}return s._onSceneSectionPlaneCreated=e.scene.on("sectionPlaneCreated",(function(e){s._sectionPlaneCreated(e)})),s}return C(i,[{key:"setOverviewVisible",value:function(e){this._overview&&this._overview.setVisible(e)}},{key:"getOverviewVisible",value:function(){if(this._overview)return this._overview.getVisible()}},{key:"sectionPlanes",get:function(){return this._sectionPlanes}},{key:"createSectionPlane",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};void 0!==e.id&&null!==e.id&&this.viewer.scene.components[e.id]&&(this.error("Viewer component with this ID already exists: "+e.id),delete e.id);var t=new cn(this.viewer.scene,{id:e.id,pos:e.pos,dir:e.dir,active:!0});return t}},{key:"_sectionPlaneCreated",value:function(e){var t=this,i=this._freeControls.length>0?this._freeControls.pop():new MF(this);i._setSectionPlane(e),i.setVisible(!1),this._controls[e.id]=i,this._overview&&this._overview.addSectionPlane(e),e.once("destroyed",(function(){t._sectionPlaneDestroyed(e)}))}},{key:"flipSectionPlanes",value:function(){var e=this.viewer.scene.sectionPlanes;for(var t in e){e[t].flipDir()}}},{key:"showControl",value:function(e){var t=this._controls[e];t?(this.hideControl(),t.setVisible(!0),this._overview&&this._overview.setPlaneSelected(e,!0),this._shownControlId=e):this.error("Control not found: "+e)}},{key:"getShownControl",value:function(){return this._shownControlId}},{key:"hideControl",value:function(){for(var e in this._controls)this._controls.hasOwnProperty(e)&&(this._controls[e].setVisible(!1),this._overview&&this._overview.setPlaneSelected(e,!1));this._shownControlId=null}},{key:"destroySectionPlane",value:function(e){var t=this.viewer.scene.sectionPlanes[e];t?(this._sectionPlaneDestroyed(t),t.destroy(),e===this._shownControlId&&(this._shownControlId=null)):this.error("SectionPlane not found: "+e)}},{key:"_sectionPlaneDestroyed",value:function(e){this._overview&&this._overview.removeSectionPlane(e);var t=this._controls[e.id];t&&(t.setVisible(!1),t._setSectionPlane(null),delete this._controls[e.id],this._freeControls.push(t))}},{key:"clear",value:function(){for(var e=Object.keys(this._sectionPlanes),t=0,i=e.length;t1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"StoreyViews",e))._objectsMemento=new ud,s._cameraMemento=new nd,s.storeys={},s.modelStoreys={},s._fitStoreyMaps=!!r.fitStoreyMaps,s._onModelLoaded=s.viewer.scene.on("modelLoaded",(function(e){s._registerModelStoreys(e),s.fire("storeys",s.storeys)})),s}return C(i,[{key:"_registerModelStoreys",value:function(e){var t=this,i=this.viewer,s=i.scene,r=i.metaScene,n=r.metaModels[e],o=s.models[e];if(n&&n.rootMetaObjects)for(var a=n.rootMetaObjects,l=0,u=a.length;l.5?p.length:0,g=new SF(this,o.aabb,f,e,d,v);g._onModelDestroyed=o.once("destroyed",(function(){t._deregisterModelStoreys(e),t.fire("storeys",t.storeys)})),this.storeys[d]=g,this.modelStoreys[e]||(this.modelStoreys[e]={}),this.modelStoreys[e][d]=g}}},{key:"_deregisterModelStoreys",value:function(e){var t=this.modelStoreys[e];if(t){var i=this.viewer.scene;for(var s in t)if(t.hasOwnProperty(s)){var r=t[s],n=i.models[r.modelId];n&&n.off(r._onModelDestroyed),delete this.storeys[s]}delete this.modelStoreys[e]}}},{key:"fitStoreyMaps",get:function(){return this._fitStoreyMaps}},{key:"gotoStoreyCamera",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=this.storeys[e];if(!i)return this.error("IfcBuildingStorey not found with this ID: "+e),void(t.done&&t.done());var s=this.viewer,r=s.scene,n=r.camera,o=i.storeyAABB;if(o[3]1&&void 0!==arguments[1]?arguments[1]:{},i=this.storeys[e];if(i){var s=this.viewer,r=s.scene,n=s.metaScene,o=n.metaObjects[e];o&&(t.hideOthers&&r.setObjectsVisible(s.scene.visibleObjectIds,!1),this.withStoreyObjects(e,(function(e,t){e&&(e.visible=!0)})))}else this.error("IfcBuildingStorey not found with this ID: "+e)}},{key:"withStoreyObjects",value:function(e,t){var i=this.viewer,s=i.scene,r=i.metaScene,n=r.metaObjects[e];if(n)for(var o=n.getObjectIDsInSubtree(),a=0,l=o.length;a1&&void 0!==arguments[1]?arguments[1]:{},i=this.storeys[e];if(!i)return this.error("IfcBuildingStorey not found with this ID: "+e),UF;var s,r,n=this.viewer,o=n.scene,a=t.format||"png",l=this._fitStoreyMaps?i.storeyAABB:i.modelAABB,u=Math.abs((l[5]-l[2])/(l[3]-l[0])),A=t.padding||0;t.width&&t.height?(s=t.width,r=t.height):t.height?(r=t.height,s=Math.round(r/u)):t.width?(s=t.width,r=Math.round(s*u)):(s=300,r=Math.round(s*u)),this._objectsMemento.saveObjects(o),this._cameraMemento.saveCamera(o),this.showStoreyObjects(e,le.apply(t,{hideOthers:!0})),this._arrangeStoreyMapCamera(i);var c=n.getSnapshot({width:s,height:r,format:a});return this._objectsMemento.restoreObjects(o),this._cameraMemento.restoreCamera(o),new TF(e,c,a,s,r,A)}},{key:"_arrangeStoreyMapCamera",value:function(e){var t=this.viewer,i=t.scene.camera,s=this._fitStoreyMaps?e.storeyAABB:e.modelAABB,r=$.getAABB3Center(s),n=RF;n[0]=r[0]+.5*i.worldUp[0],n[1]=r[1]+.5*i.worldUp[1],n[2]=r[2]+.5*i.worldUp[2];var o=i.worldForward;t.cameraFlight.jumpTo({eye:n,look:r,up:o});var a=(s[3]-s[0])/2,l=(s[4]-s[1])/2,u=(s[5]-s[2])/2,A=-a,c=+a,h=-l,d=+l,p=-u,f=+u;t.camera.customProjection.matrix=$.orthoMat4c(A,c,p,f,h,d,LF),t.camera.projection="customProjection"}},{key:"pickStoreyMap",value:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=e.storeyId,r=this.storeys[s];if(!r)return this.error("IfcBuildingStorey not found with this ID: "+s),null;var n=1-t[0]/e.width,o=1-t[1]/e.height,a=this._fitStoreyMaps?r.storeyAABB:r.modelAABB,l=a[0],u=a[1],A=a[2],c=a[3],h=a[4],d=a[5],p=c-l,f=h-u,v=d-A,g=$.vec3([l+p*n,u+.5*f,A+v*o]),m=$.vec3([0,-1,0]),_=$.addVec3(g,m,RF),y=this.viewer.camera.worldForward,b=$.lookAtMat4v(g,_,y,LF),B=this.viewer.scene.pick({pickSurface:i.pickSurface,pickInvisible:!0,matrix:b});return B}},{key:"storeyMapToWorldPos",value:function(e,t){var i=e.storeyId,s=this.storeys[i];if(!s)return this.error("IfcBuildingStorey not found with this ID: "+i),null;var r=1-t[0]/e.width,n=1-t[1]/e.height,o=this._fitStoreyMaps?s.storeyAABB:s.modelAABB,a=o[0],l=o[1],u=o[2],A=o[3],c=o[4],h=o[5],d=A-a,p=c-l,f=h-u,v=$.vec3([a+d*r,l+.5*p,u+f*n]);return v}},{key:"getStoreyContainingWorldPos",value:function(e){for(var t in this.storeys){var i=this.storeys[t];if($.point3AABB3Intersect(i.storeyAABB,e))return t}return null}},{key:"worldPosToStoreyMap",value:function(e,t,i){var s=e.storeyId,r=this.storeys[s];if(!r)return this.error("IfcBuildingStorey not found with this ID: "+s),!1;var n=this._fitStoreyMaps?r.storeyAABB:r.modelAABB,o=n[0],a=n[1],l=n[2],u=n[3]-o,A=n[4]-a,c=n[5]-l,h=this.viewer.camera.worldUp,d=h[0]>h[1]&&h[0]>h[2],p=!d&&h[1]>h[0]&&h[1]>h[2];!d&&!p&&h[2]>h[0]&&(h[2],h[1]);var f=e.width/u,v=p?e.height/c:e.height/A;return i[0]=Math.floor(e.width-(t[0]-o)*f),i[1]=Math.floor(e.height-(t[2]-l)*v),i[0]>=0&&i[0]=0&&i[1]<=e.height}},{key:"worldDirToStoreyMap",value:function(e,t,i){var s=this.viewer.camera,r=s.eye,n=s.look,o=$.subVec3(n,r,RF),a=s.worldUp,l=a[0]>a[1]&&a[0]>a[2],u=!l&&a[1]>a[0]&&a[1]>a[2];!l&&!u&&a[2]>a[0]&&(a[2],a[1]),l?(i[0]=o[1],i[1]=o[2]):u?(i[0]=o[0],i[1]=o[2]):(i[0]=o[0],i[1]=o[1]),$.normalizeVec2(i)}},{key:"destroy",value:function(){this.viewer.scene.off(this._onModelLoaded),f(B(i.prototype),"destroy",this).call(this)}}]),i}(),NF=new Float64Array([0,0,1]),QF=new Float64Array(4),VF=function(){function e(t){x(this,e),this.id=null,this._viewer=t.viewer,this._plugin=t,this._visible=!1,this._pos=$.vec3(),this._origin=$.vec3(),this._rtcPos=$.vec3(),this._baseDir=$.vec3(),this._rootNode=null,this._displayMeshes=null,this._affordanceMeshes=null,this._ignoreNextSectionPlaneDirUpdate=!1,this._createNodes(),this._bindEvents()}return C(e,[{key:"_setSectionPlane",value:function(e){var t=this;this._sectionPlane&&(this._sectionPlane.off(this._onSectionPlanePos),this._sectionPlane.off(this._onSectionPlaneDir),this._onSectionPlanePos=null,this._onSectionPlaneDir=null,this._sectionPlane=null),e&&(this.id=e.id,this._setPos(e.pos),this._setDir(e.dir),this._sectionPlane=e,this._onSectionPlanePos=e.on("pos",(function(){t._setPos(t._sectionPlane.pos)})),this._onSectionPlaneDir=e.on("dir",(function(){t._ignoreNextSectionPlaneDirUpdate?t._ignoreNextSectionPlaneDirUpdate=!1:t._setDir(t._sectionPlane.dir)})))}},{key:"sectionPlane",get:function(){return this._sectionPlane}},{key:"_setPos",value:function(e){this._pos.set(e),Le(this._pos,this._origin,this._rtcPos),this._rootNode.origin=this._origin,this._rootNode.position=this._rtcPos}},{key:"_setDir",value:function(e){this._baseDir.set(e),this._rootNode.quaternion=$.vec3PairToQuaternion(NF,e,QF)}},{key:"_setSectionPlaneDir",value:function(e){this._sectionPlane&&(this._ignoreNextSectionPlaneDirUpdate=!0,this._sectionPlane.dir=e)}},{key:"setVisible",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(this._visible!==e){var t;for(t in this._visible=e,this._displayMeshes)this._displayMeshes.hasOwnProperty(t)&&(this._displayMeshes[t].visible=e);if(!e)for(t in this._affordanceMeshes)this._affordanceMeshes.hasOwnProperty(t)&&(this._affordanceMeshes[t].visible=e)}}},{key:"getVisible",value:function(){return this._visible}},{key:"setCulled",value:function(e){var t;for(t in this._displayMeshes)this._displayMeshes.hasOwnProperty(t)&&(this._displayMeshes[t].culled=e);if(!e)for(t in this._affordanceMeshes)this._affordanceMeshes.hasOwnProperty(t)&&(this._affordanceMeshes[t].culled=e)}},{key:"_createNodes",value:function(){var e=!1,t=this._viewer.scene,i=.01;this._rootNode=new bn(t,{position:[0,0,0],scale:[5,5,5]});var s=this._rootNode,r={arrowHead:new Si(s,on({radiusTop:.001,radiusBottom:.07,radialSegments:32,heightSegments:1,height:.2,openEnded:!1})),arrowHeadBig:new Si(s,on({radiusTop:.001,radiusBottom:.09,radialSegments:32,heightSegments:1,height:.25,openEnded:!1})),axis:new Si(s,on({radiusTop:i,radiusBottom:i,radialSegments:20,heightSegments:1,height:1,openEnded:!1}))},n={red:new Oi(s,{diffuse:[1,0,0],emissive:[1,0,0],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),green:new Oi(s,{diffuse:[0,1,0],emissive:[1,0,0],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),blue:new Oi(s,{diffuse:[0,0,1],emissive:[1,0,0],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),highlightRed:new Qi(s,{edges:!1,fill:!0,fillColor:[1,0,0],fillAlpha:.6})};this._displayMeshes={plane:s.addChild(new rn(s,{geometry:new Si(s,{primitive:"triangles",positions:[.5,.5,0,.5,-.5,0,-.5,-.5,0,-.5,.5,0,.5,.5,-0,.5,-.5,-0,-.5,-.5,-0,-.5,.5,-0],indices:[0,1,2,2,3,0]}),material:new Oi(s,{emissive:[0,0,0],diffuse:[0,0,0],backfaces:!0}),opacity:.6,ghosted:!0,pickable:!1,collidable:!0,clippable:!1,visible:!1,scale:[2.4,2.4,1]}),e),planeFrame:s.addChild(new rn(s,{geometry:new Si(s,Jn({center:[0,0,0],radius:1.7,tube:.02,radialSegments:4,tubeSegments:4,arc:2*Math.PI})),material:new Oi(s,{emissive:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],shininess:0}),pickable:!1,collidable:!1,clippable:!1,visible:!1,scale:[1,1,.1],rotation:[0,0,45]}),e),center:s.addChild(new rn(s,{geometry:new Si(s,an({radius:.05})),material:n.center,pickable:!1,collidable:!0,clippable:!1,visible:!1}),e),zAxisArrow:s.addChild(new rn(s,{geometry:r.arrowHead,material:n.blue,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[.8,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1}),e),zShaft:s.addChild(new rn(s,{geometry:r.axis,material:n.blue,matrix:function(){var e=$.translateMat4c(0,.5,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[1,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),clippable:!1,pickable:!1,collidable:!0,visible:!1}),e)},this._affordanceMeshes={planeFrame:s.addChild(new rn(s,{geometry:new Si(s,Jn({center:[0,0,0],radius:2,tube:i,radialSegments:4,tubeSegments:4,arc:2*Math.PI})),material:new Oi(s,{ambient:[1,1,1],diffuse:[0,0,0],emissive:[1,1,0]}),highlighted:!0,highlightMaterial:new Qi(s,{edges:!1,filled:!0,fillColor:[1,1,0],fillAlpha:1}),pickable:!1,collidable:!1,clippable:!1,visible:!1,scale:[1,1,1],rotation:[0,0,45]}),e),zAxisArrow:s.addChild(new rn(s,{geometry:r.arrowHeadBig,material:n.blue,matrix:function(){var e=$.translateMat4c(0,1.1,0,$.identityMat4()),t=$.rotationMat4v(-90*$.DEGTORAD,[.8,0,0],$.identityMat4());return $.mulMat4(t,e,$.identityMat4())}(),pickable:!1,collidable:!0,clippable:!1,visible:!1}),e)}}},{key:"_bindEvents",value:function(){var e=this,t=this._rootNode,i=$.vec2(),s=this._viewer.camera,r=this._viewer.scene,n=0,o=!1,a=$.vec3([0,0,0]),l=-1;this._onCameraViewMatrix=r.camera.on("viewMatrix",(function(){})),this._onCameraProjMatrix=r.camera.on("projMatrix",(function(){})),this._onSceneTick=r.on("tick",(function(){o=!1;var i=Math.abs($.lenVec3($.subVec3(r.camera.eye,e._pos,a)));if(i!==l&&"perspective"===s.projection){var u=.07*(Math.tan(s.perspective.fov*$.DEGTORAD)*i);t.scale=[u,u,u],l=i}if("ortho"===s.projection){var c=s.ortho.scale/10;t.scale=[c,c,c],l=i}0!==n&&(A(n),n=0)}));var u=function(){var e=new Float64Array(2);return function(t){if(t){for(var i=t.target,s=0,r=0;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;e[0]=t.pageX-s,e[1]=t.pageY-r}else t=window.event,e[0]=t.x,e[1]=t.y;return e}}(),A=function(t){var i=e._sectionPlane.pos,s=e._sectionPlane.dir;$.addVec3(i,$.mulVec3Scalar(s,.1*t*e._plugin.getDragSensitivity(),$.vec3())),e._sectionPlane.pos=i},c=!1;this._plugin._controlElement.addEventListener("mousedown",this._canvasMouseDownListener=function(t){if(t.preventDefault(),e._visible&&(e._viewer.cameraControl.pointerEnabled=!1,1===t.which)){c=!0;var s=u(t);i[0]=s[0],i[1]=s[1]}}),this._plugin._controlElement.addEventListener("mousemove",this._canvasMouseMoveListener=function(t){if(e._visible&&c&&!o){var s=u(t),r=s[0],n=s[1];A(n-i[1]),i[0]=r,i[1]=n}}),this._plugin._controlElement.addEventListener("mouseup",this._canvasMouseUpListener=function(t){e._visible&&(e._viewer.cameraControl.pointerEnabled=!0,c&&(t.which,c=!1))}),this._plugin._controlElement.addEventListener("wheel",this._canvasWheelListener=function(t){e._visible&&(n+=Math.max(-1,Math.min(1,40*-t.deltaY)))});var h,d,p=null;this._plugin._controlElement.addEventListener("touchstart",this._handleTouchStart=function(t){t.stopPropagation(),t.preventDefault(),e._visible&&(h=t.touches[0].clientY,p=h,n=0)}),this._plugin._controlElement.addEventListener("touchmove",this._handleTouchMove=function(t){t.stopPropagation(),t.preventDefault(),e._visible&&(o||(o=!0,d=t.touches[0].clientY,null!==p&&(n+=d-p),p=d))}),this._plugin._controlElement.addEventListener("touchend",this._handleTouchEnd=function(t){t.stopPropagation(),t.preventDefault(),e._visible&&(h=null,d=null,n=0)})}},{key:"_destroy",value:function(){this._unbindEvents(),this._destroyNodes()}},{key:"_unbindEvents",value:function(){var e=this._viewer,t=e.scene,i=t.canvas.canvas,s=e.camera,r=this._plugin._controlElement;t.off(this._onSceneTick),i.removeEventListener("mousedown",this._canvasMouseDownListener),i.removeEventListener("mousemove",this._canvasMouseMoveListener),i.removeEventListener("mouseup",this._canvasMouseUpListener),i.removeEventListener("wheel",this._canvasWheelListener),r.removeEventListener("touchstart",this._handleTouchStart),r.removeEventListener("touchmove",this._handleTouchMove),r.removeEventListener("touchend",this._handleTouchEnd),s.off(this._onCameraViewMatrix),s.off(this._onCameraProjMatrix)}},{key:"_destroyNodes",value:function(){this._setSectionPlane(null),this._rootNode.destroy(),this._displayMeshes={},this._affordanceMeshes={}}}]),e}(),HF=function(){function e(t,i,s){var r=this;x(this,e),this.id=s.id,this._sectionPlane=s,this._mesh=new rn(i,{id:s.id,geometry:new Si(i,Ti({xSize:.5,ySize:.5,zSize:.001})),material:new Oi(i,{emissive:[1,1,1],diffuse:[0,0,0],backfaces:!1}),edgeMaterial:new Hi(i,{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1}),highlightMaterial:new Qi(i,{fill:!0,fillColor:[.5,1,.5],fillAlpha:.7,edges:!0,edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1}),selectedMaterial:new Qi(i,{fill:!0,fillColor:[0,0,1],fillAlpha:.7,edges:!0,edgeColor:[1,0,0],edgeAlpha:1,edgeWidth:1}),highlighted:!0,scale:[3,3,3],position:[0,0,0],rotation:[0,0,0],opacity:.3,edges:!0});var n=$.vec3([0,0,0]),o=$.vec3(),a=$.vec3([0,0,1]),l=$.vec4(4),u=$.vec3(),A=function(){var e=r._sectionPlane.scene.center,t=[-r._sectionPlane.dir[0],-r._sectionPlane.dir[1],-r._sectionPlane.dir[2]];$.subVec3(e,r._sectionPlane.pos,n);var i=-$.dotVec3(t,n);$.normalizeVec3(t),$.mulVec3Scalar(t,i,o);var s=$.vec3PairToQuaternion(a,r._sectionPlane.dir,l);u[0]=.1*o[0],u[1]=.1*o[1],u[2]=.1*o[2],r._mesh.quaternion=s,r._mesh.position=u};this._onSectionPlanePos=this._sectionPlane.on("pos",A),this._onSectionPlaneDir=this._sectionPlane.on("dir",A),this._highlighted=!1,this._selected=!1}return C(e,[{key:"setHighlighted",value:function(e){this._highlighted=!!e,this._mesh.highlighted=this._highlighted,this._mesh.highlightMaterial.fillColor=e?[0,.7,0]:[0,0,0]}},{key:"getHighlighted",value:function(){return this._highlighted}},{key:"setSelected",value:function(e){this._selected=!!e,this._mesh.edgeMaterial.edgeWidth=e?3:1,this._mesh.highlightMaterial.edgeWidth=e?3:1}},{key:"getSelected",value:function(){return this._selected}},{key:"destroy",value:function(){this._sectionPlane.off(this._onSectionPlanePos),this._sectionPlane.off(this._onSectionPlaneDir),this._mesh.destroy()}}]),e}(),jF=function(){function e(t,i){var s=this;if(x(this,e),!(i.onHoverEnterPlane&&i.onHoverLeavePlane&&i.onClickedNothing&&i.onClickedPlane))throw"Missing config(s): onHoverEnterPlane, onHoverLeavePlane, onClickedNothing || onClickedPlane";this.plugin=t,this._viewer=t.viewer,this._onHoverEnterPlane=i.onHoverEnterPlane,this._onHoverLeavePlane=i.onHoverLeavePlane,this._onClickedNothing=i.onClickedNothing,this._onClickedPlane=i.onClickedPlane,this._visible=!0,this._planes={},this._canvas=i.overviewCanvas,this._scene=new qi(this._viewer,{canvasId:this._canvas.id,transparent:!0}),this._scene.clearLights(),new yi(this._scene,{dir:[.4,-.4,.8],color:[.8,1,1],intensity:1,space:"view"}),new yi(this._scene,{dir:[-.8,-.3,-.4],color:[.8,.8,.8],intensity:1,space:"view"}),new yi(this._scene,{dir:[.8,-.6,-.8],color:[1,1,1],intensity:1,space:"view"}),this._scene.camera,this._scene.camera.perspective.fov=70,this._zUp=!1;var r=this._scene.camera,n=$.rotationMat4c(-90*$.DEGTORAD,1,0,0),o=$.vec3(),a=$.vec3(),l=$.vec3();this._synchCamera=function(){var e=s._viewer.camera.eye,t=s._viewer.camera.look,i=s._viewer.camera.up;$.mulVec3Scalar($.normalizeVec3($.subVec3(e,t,o)),7),s._zUp?($.transformVec3(n,o,a),$.transformVec3(n,i,l),r.look=[0,0,0],r.eye=$.transformVec3(n,o,a),r.up=$.transformPoint3(n,i,l)):(r.look=[0,0,0],r.eye=o,r.up=i)},this._onViewerCameraMatrix=this._viewer.camera.on("matrix",this._synchCamera),this._onViewerCameraWorldAxis=this._viewer.camera.on("worldAxis",this._synchCamera),this._onViewerCameraFOV=this._viewer.camera.perspective.on("fov",(function(e){s._scene.camera.perspective.fov=e}));var u=null;this._onInputMouseMove=this._scene.input.on("mousemove",(function(e){var t=s._scene.pick({canvasPos:e});if(t){if(!u||t.entity.id!==u.id){if(u)s._planes[u.id]&&s._onHoverLeavePlane(u.id);u=t.entity,s._planes[u.id]&&s._onHoverEnterPlane(u.id)}}else u&&(s._onHoverLeavePlane(u.id),u=null)})),this._scene.canvas.canvas.addEventListener("mouseup",this._onCanvasMouseUp=function(){u?s._planes[u.id]&&s._onClickedPlane(u.id):s._onClickedNothing()}),this._scene.canvas.canvas.addEventListener("mouseout",this._onCanvasMouseOut=function(){u&&(s._onHoverLeavePlane(u.id),u=null)}),this.setVisible(i.overviewVisible)}return C(e,[{key:"addSectionPlane",value:function(e){this._planes[e.id]=new HF(this,this._scene,e)}},{key:"setPlaneHighlighted",value:function(e,t){var i=this._planes[e];i&&i.setHighlighted(t)}},{key:"setPlaneSelected",value:function(e,t){var i=this._planes[e];i&&i.setSelected(t)}},{key:"removeSectionPlane",value:function(e){var t=this._planes[e.id];t&&(t.destroy(),delete this._planes[e.id])}},{key:"setVisible",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this._visible=e,this._canvas.style.visibility=e?"visible":"hidden"}},{key:"getVisible",value:function(){return this._visible}},{key:"destroy",value:function(){this._viewer.camera.off(this._onViewerCameraMatrix),this._viewer.camera.off(this._onViewerCameraWorldAxis),this._viewer.camera.perspective.off(this._onViewerCameraFOV),this._scene.input.off(this._onInputMouseMove),this._scene.canvas.canvas.removeEventListener("mouseup",this._onCanvasMouseUp),this._scene.canvas.canvas.removeEventListener("mouseout",this._onCanvasMouseOut),this._scene.destroy()}}]),e}(),GF=$.AABB3(),zF=$.vec3(),WF=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,"FaceAlignedSectionPlanesPlugin",e))._freeControls=[],s._sectionPlanes=e.scene.sectionPlanes,s._controls={},s._shownControlId=null,s._dragSensitivity=r.dragSensitivity||1,null!==r.overviewCanvasId&&void 0!==r.overviewCanvasId){var n=document.getElementById(r.overviewCanvasId);n?s._overview=new jF(b(s),{overviewCanvas:n,visible:r.overviewVisible,onHoverEnterPlane:function(e){s._overview.setPlaneHighlighted(e,!0)},onHoverLeavePlane:function(e){s._overview.setPlaneHighlighted(e,!1)},onClickedPlane:function(e){if(s.getShownControl()!==e){s.showControl(e);var t=s.sectionPlanes[e].pos;GF.set(s.viewer.scene.aabb),$.getAABB3Center(GF,zF),GF[0]+=t[0]-zF[0],GF[1]+=t[1]-zF[1],GF[2]+=t[2]-zF[2],GF[3]+=t[0]-zF[0],GF[4]+=t[1]-zF[1],GF[5]+=t[2]-zF[2],s.viewer.cameraFlight.flyTo({aabb:GF,fitFOV:65})}else s.hideControl()},onClickedNothing:function(){s.hideControl()}}):s.warn("Can't find overview canvas: '"+r.overviewCanvasId+"' - will create plugin without overview")}return null===r.controlElementId||void 0===r.controlElementId?s.error("Parameter expected: controlElementId"):(s._controlElement=document.getElementById(r.controlElementId),s._controlElement||s.warn("Can't find control element: '"+r.controlElementId+"' - will create plugin without control element")),s._onSceneSectionPlaneCreated=e.scene.on("sectionPlaneCreated",(function(e){s._sectionPlaneCreated(e)})),s}return C(i,[{key:"setDragSensitivity",value:function(e){this._dragSensitivity=e||1}},{key:"getDragSensitivity",value:function(){return this._dragSensitivity}},{key:"setOverviewVisible",value:function(e){this._overview&&this._overview.setVisible(e)}},{key:"getOverviewVisible",value:function(){if(this._overview)return this._overview.getVisible()}},{key:"sectionPlanes",get:function(){return this._sectionPlanes}},{key:"createSectionPlane",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};void 0!==e.id&&null!==e.id&&this.viewer.scene.components[e.id]&&(this.error("Viewer component with this ID already exists: "+e.id),delete e.id);var t=new cn(this.viewer.scene,{id:e.id,pos:e.pos,dir:e.dir,active:!0});return t}},{key:"_sectionPlaneCreated",value:function(e){var t=this,i=this._freeControls.length>0?this._freeControls.pop():new VF(this);i._setSectionPlane(e),i.setVisible(!1),this._controls[e.id]=i,this._overview&&this._overview.addSectionPlane(e),e.once("destroyed",(function(){t._sectionPlaneDestroyed(e)}))}},{key:"flipSectionPlanes",value:function(){var e=this.viewer.scene.sectionPlanes;for(var t in e){e[t].flipDir()}}},{key:"showControl",value:function(e){var t=this._controls[e];t?(this.hideControl(),t.setVisible(!0),this._overview&&this._overview.setPlaneSelected(e,!0),this._shownControlId=e):this.error("Control not found: "+e)}},{key:"getShownControl",value:function(){return this._shownControlId}},{key:"hideControl",value:function(){for(var e in this._controls)this._controls.hasOwnProperty(e)&&(this._controls[e].setVisible(!1),this._overview&&this._overview.setPlaneSelected(e,!1));this._shownControlId=null}},{key:"destroySectionPlane",value:function(e){var t=this.viewer.scene.sectionPlanes[e];t?(this._sectionPlaneDestroyed(t),t.destroy(),e===this._shownControlId&&(this._shownControlId=null)):this.error("SectionPlane not found: "+e)}},{key:"_sectionPlaneDestroyed",value:function(e){this._overview&&this._overview.removeSectionPlane(e);var t=this._controls[e.id];t&&(t.setVisible(!1),t._setSectionPlane(null),delete this._controls[e.id],this._freeControls.push(t))}},{key:"clear",value:function(){for(var e=Object.keys(this._sectionPlanes),t=0,i=e.length;t>5&31)/31,o=(F>>10&31)/31):(r=l,n=u,o=A),(B&&r!==p||n!==f||o!==v)&&(null!==p&&(g=!0),p=r,f=n,v=o)}for(var E=1;E<=3;E++){var k=x+12*E;y.push(c.getFloat32(k,!0)),y.push(c.getFloat32(k+4,!0)),y.push(c.getFloat32(k+8,!0)),b.push(P,C,M),d&&a.push(r,n,o,1)}B&&g&&(eE(i,y,b,a,_,s),y=[],b=[],a=a?[]:null,g=!1)}y.length>0&&eE(i,y,b,a,_,s)}function $F(e,t,i,s){for(var r,n,o,a,l,u,A,c=/facet([\s\S]*?)endfacet/g,h=0,d=/[\s]+([+-]?(?:\d+.\d+|\d+.|\d+|.\d+)(?:[eE][+-]?\d+)?)/.source,p=new RegExp("vertex"+d+d+d,"g"),f=new RegExp("normal"+d+d+d,"g"),v=[],g=[];null!==(a=c.exec(t));){for(l=0,u=0,A=a[0];null!==(a=f.exec(A));)r=parseFloat(a[1]),n=parseFloat(a[2]),o=parseFloat(a[3]),u++;for(;null!==(a=p.exec(A));)v.push(parseFloat(a[1]),parseFloat(a[2]),parseFloat(a[3])),g.push(r,n,o),l++;1!==u&&e.error("Error in normal of face "+h),3!==l&&e.error("Error in positions of face "+h),h++}eE(i,v,g,null,new Pn(i,{roughness:.5}),s)}function eE(e,t,i,s,r,n){for(var o=new Int32Array(t.length/3),a=0,l=o.length;a0?i:null,s=s&&s.length>0?s:null,n.smoothNormals&&$.faceToVertexNormals(t,i,n);var u=JF;Ue(t,t,u);var A=new Si(e,{primitive:"triangles",positions:t,normals:i,colors:s,indices:o}),c=new rn(e,{origin:0!==u[0]||0!==u[1]||0!==u[2]?u:null,geometry:A,material:r,edges:n.edges});e.addChild(c)}function tE(e){return"string"!=typeof e?function(e){if("undefined"!=typeof TextDecoder)return(new TextDecoder).decode(e);for(var t="",i=0,s=e.length;i1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"STLLoader",e,r))._sceneGraphLoader=new YF,s.dataSource=r.dataSource,s}return C(i,[{key:"dataSource",get:function(){return this._dataSource},set:function(e){this._dataSource=e||new XF}},{key:"load",value:function(e){e.id&&this.viewer.scene.components[e.id]&&(this.error("Component with this ID already exists in viewer: "+e.id+" - will autogenerate this ID"),delete e.id);var t=new bn(this.viewer.scene,le.apply(e,{isModel:!0})),i=e.src,s=e.stl;return i||s?(i?this._sceneGraphLoader.load(this,t,i,e):this._sceneGraphLoader.parse(this,t,s,e),t):(this.error("load() param expected: either 'src' or 'stl'"),t)}}]),i}(),rE=function(){function e(){x(this,e)}return C(e,[{key:"createRootNode",value:function(){return document.createElement("ul")}},{key:"createNodeElement",value:function(e,t,i,s,r){var n=document.createElement("li");if(n.id=e.nodeId,e.xrayed&&n.classList.add("xrayed-node"),e.children.length>0){var o=document.createElement("a");o.href="#",o.id="switch-".concat(e.nodeId),o.textContent="+",o.classList.add("plus"),t&&o.addEventListener("click",t),n.appendChild(o)}var a=document.createElement("input");a.id="checkbox-".concat(e.nodeId),a.type="checkbox",a.checked=e.checked,a.style["pointer-events"]="all",i&&a.addEventListener("change",i),n.appendChild(a);var l=document.createElement("span");return l.textContent=e.title,n.appendChild(l),s&&(l.oncontextmenu=s),r&&(l.onclick=r),n}},{key:"createDisabledNodeElement",value:function(e){var t=document.createElement("li"),i=document.createElement("a");i.href="#",i.textContent="!",i.classList.add("warn"),i.classList.add("warning"),t.appendChild(i);var s=document.createElement("span");return s.textContent=e,t.appendChild(s),t}},{key:"addChildren",value:function(e,t){var i=document.createElement("ul");t.forEach((function(e){i.appendChild(e)})),e.parentElement.appendChild(i)}},{key:"expand",value:function(e,t,i){e.classList.remove("plus"),e.classList.add("minus"),e.textContent="-",e.removeEventListener("click",t),e.addEventListener("click",i)}},{key:"collapse",value:function(e,t,i){if(e){var s=e.parentElement;if(s){var r=s.querySelector("ul");r&&(s.removeChild(r),e.classList.remove("minus"),e.classList.add("plus"),e.textContent="+",e.removeEventListener("click",i),e.addEventListener("click",t))}}}},{key:"isExpanded",value:function(e){return void 0!==e.parentElement.getElementsByTagName("li")[0]}},{key:"getId",value:function(e){return e.parentElement.id}},{key:"getIdFromCheckbox",value:function(e){return e.id.replace("checkbox-","")}},{key:"getSwitchElement",value:function(e){return document.getElementById("switch-".concat(e))}},{key:"isChecked",value:function(e){return e.checked}},{key:"setCheckbox",value:function(e,t){var i=document.getElementById("checkbox-".concat(e));i&&t!==i.checked&&(i.checked=t)}},{key:"setXRayed",value:function(e,t){var i=document.getElementById(e);i&&(t?i.classList.add("xrayed-node"):i.classList.remove("xrayed-node"))}},{key:"setHighlighted",value:function(e,t){var i=document.getElementById(e);i&&(t?(i.scrollIntoView({block:"center"}),i.classList.add("highlighted-node")):i.classList.remove("highlighted-node"))}}]),e}(),nE=[],oE=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(s=t.call(this,"TreeViewPlugin",e)).errors=[],s.valid=!0;var n=r.containerElement||document.getElementById(r.containerElementId);if(!(n instanceof HTMLElement))return s.error("Mandatory config expected: valid containerElementId or containerElement"),y(s);for(var o=0;;o++)if(!nE[o]){nE[o]=b(s),s._index=o,s._id="tree-".concat(o);break}if(s._containerElement=n,s._metaModels={},s._autoAddModels=!1!==r.autoAddModels,s._autoExpandDepth=r.autoExpandDepth||0,s._sortNodes=!1!==r.sortNodes,s._viewer=e,s._rootElement=null,s._muteSceneEvents=!1,s._muteTreeEvents=!1,s._rootNodes=[],s._objectNodes={},s._nodeNodes={},s._rootNames={},s._sortNodes=r.sortNodes,s._pruneEmptyNodes=r.pruneEmptyNodes,s._showListItemElementId=null,s._renderService=r.renderService||new rE,!s._renderService)throw new Error("TreeViewPlugin: no render service set");if(s._containerElement.oncontextmenu=function(e){e.preventDefault()},s._onObjectVisibility=s._viewer.scene.on("objectVisibility",(function(e){if(!s._muteSceneEvents){var t=e.id,i=s._objectNodes[t];if(i){var r=e.visible;if(r!==i.checked){s._muteTreeEvents=!0,i.checked=r,r?i.numVisibleEntities++:i.numVisibleEntities--,s._renderService.setCheckbox(i.nodeId,r);for(var n=i.parent;n;)n.checked=r,r?n.numVisibleEntities++:n.numVisibleEntities--,s._renderService.setCheckbox(n.nodeId,n.numVisibleEntities>0),n=n.parent;s._muteTreeEvents=!1}}}})),s._onObjectXrayed=s._viewer.scene.on("objectXRayed",(function(e){if(!s._muteSceneEvents){var t=e.id,i=s._objectNodes[t];if(i){s._muteTreeEvents=!0;var r=e.xrayed;r!==i.xrayed&&(i.xrayed=r,s._renderService.setXRayed(i.nodeId,r),s._muteTreeEvents=!1)}}})),s._switchExpandHandler=function(e){e.preventDefault(),e.stopPropagation();var t=e.target;s._expandSwitchElement(t)},s._switchCollapseHandler=function(e){e.preventDefault(),e.stopPropagation();var t=e.target;s._collapseSwitchElement(t)},s._checkboxChangeHandler=function(e){if(!s._muteTreeEvents){s._muteSceneEvents=!0;var t=e.target,i=s._renderService.isChecked(t),r=s._renderService.getIdFromCheckbox(t),n=s._nodeNodes[r],o=s._viewer.scene.objects,a=0;s._withNodeTree(n,(function(e){var t=e.objectId,r=o[t],n=0===e.children.length;e.numVisibleEntities=i?e.numEntities:0,n&&i!==e.checked&&a++,e.checked=i,s._renderService.setCheckbox(e.nodeId,i),r&&(r.visible=i)}));for(var l=n.parent;l;)l.checked=i,i?l.numVisibleEntities+=a:l.numVisibleEntities-=a,s._renderService.setCheckbox(l.nodeId,l.numVisibleEntities>0),l=l.parent;s._muteSceneEvents=!1}},s._hierarchy=r.hierarchy||"containment",s._autoExpandDepth=r.autoExpandDepth||0,s._autoAddModels){for(var a=Object.keys(s.viewer.metaScene.metaModels),l=0,u=a.length;l1&&void 0!==arguments[1]?arguments[1]:{};if(this._containerElement){var s=this.viewer.scene.models[e];if(!s)throw"Model not found: "+e;var r=this.viewer.metaScene.metaModels[e];r?this._metaModels[e]?this.warn("Model already added: "+e):(this._metaModels[e]=r,i&&i.rootName&&(this._rootNames[e]=i.rootName),s.on("destroyed",(function(){t.removeModel(s.id)})),this._createNodes()):this.error("MetaModel not found: "+e)}}},{key:"removeModel",value:function(e){this._containerElement&&(this._metaModels[e]&&(this._rootNames[e]&&delete this._rootNames[e],delete this._metaModels[e],this._createNodes()))}},{key:"showNode",value:function(e){this.unShowNode();var t=this._objectNodes[e];if(t){var i=t.nodeId,s=this._renderService.getSwitchElement(i);if(s)return this._expandSwitchElement(s),s.scrollIntoView(),!0;var r=[];r.unshift(t);for(var n=t.parent;n;)r.unshift(n),n=n.parent;for(var o=0,a=r.length;o0;return this.valid}},{key:"_validateMetaModelForStoreysHierarchy",value:function(){return!0}},{key:"_createEnabledNodes",value:function(){switch(this._pruneEmptyNodes&&this._findEmptyNodes(),this._hierarchy){case"storeys":this._createStoreysNodes(),0===this._rootNodes.length&&this.error("Failed to build storeys hierarchy");break;case"types":this._createTypesNodes();break;default:this._createContainmentNodes()}this._sortNodes&&this._doSortNodes(),this._synchNodesToEntities(),this._createTrees(),this.expandToDepth(this._autoExpandDepth)}},{key:"_createDisabledNodes",value:function(){var e=this._renderService.createRootNode();this._rootElement=e,this._containerElement.appendChild(e);var t=this._viewer.metaScene.rootMetaObjects;for(var i in t){var s=t[i],r=s.type,n=s.name,o=n&&""!==n&&"Undefined"!==n&&"Default"!==n?n:r,a=this._renderService.createDisabledNodeElement(o);e.appendChild(a)}}},{key:"_findEmptyNodes",value:function(){var e=this._viewer.metaScene.rootMetaObjects;for(var t in e)this._findEmptyNodes2(e[t])}},{key:"_findEmptyNodes2",value:function(e){var t=this.viewer,i=t.scene,s=e.children,r=e.id,n=i.objects[r];if(e._countEntities=0,n&&e._countEntities++,s)for(var o=0,a=s.length;or.aabb[n]?-1:e.aabb[n]s?1:0}},{key:"_synchNodesToEntities",value:function(){for(var e=Object.keys(this.viewer.metaScene.metaObjects),t=this._viewer.metaScene.metaObjects,i=this._viewer.scene.objects,s=0,r=e.length;s0){for(var e=0;e1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"ViewCull",e))._objectCullStates=uE(e.scene),s._maxTreeDepth=r.maxTreeDepth||8,s._modelInfos={},s._frustum=new Me,s._kdRoot=null,s._frustumDirty=!1,s._kdTreeDirty=!1,s._onViewMatrix=e.scene.camera.on("viewMatrix",(function(){s._frustumDirty=!0})),s._onProjMatrix=e.scene.camera.on("projMatMatrix",(function(){s._frustumDirty=!0})),s._onModelLoaded=e.scene.on("modelLoaded",(function(e){var t=s.viewer.scene.models[e];t&&s._addModel(t)})),s._onSceneTick=e.scene.on("tick",(function(){s._doCull()})),s}return C(i,[{key:"enabled",get:function(){return this._enabled},set:function(e){this._enabled=e}},{key:"_addModel",value:function(e){var t=this,i={model:e,onDestroyed:e.on("destroyed",(function(){t._removeModel(e)}))};this._modelInfos[e.id]=i,this._kdTreeDirty=!0}},{key:"_removeModel",value:function(e){var t=this._modelInfos[e.id];t&&(t.model.off(t.onDestroyed),delete this._modelInfos[e.id],this._kdTreeDirty=!0)}},{key:"_doCull",value:function(){var e=this._frustumDirty||this._kdTreeDirty;if(this._frustumDirty&&this._buildFrustum(),this._kdTreeDirty&&this._buildKDTree(),e){var t=this._kdRoot;t&&this._visitKDNode(t)}}},{key:"_buildFrustum",value:function(){var e=this.viewer.scene.camera;Fe(this._frustum,e.viewMatrix,e.projMatrix),this._frustumDirty=!1}},{key:"_buildKDTree",value:function(){var e=this.viewer.scene;this._kdRoot,this._kdRoot={aabb:e.getAABB(),intersection:Me.INTERSECT};for(var t=0,i=this._objectCullStates.numObjects;t=this._maxTreeDepth)return e.objects=e.objects||[],e.objects.push(i),void $.expandAABB3(e.aabb,r);if(e.left&&$.containsAABB3(e.left.aabb,r))this._insertEntityIntoKDTree(e.left,t,i,s+1);else if(e.right&&$.containsAABB3(e.right.aabb,r))this._insertEntityIntoKDTree(e.right,t,i,s+1);else{var n=e.aabb;AE[0]=n[3]-n[0],AE[1]=n[4]-n[1],AE[2]=n[5]-n[2];var o=0;if(AE[1]>AE[o]&&(o=1),AE[2]>AE[o]&&(o=2),!e.left){var a=n.slice();if(a[o+3]=(n[o]+n[o+3])/2,e.left={aabb:a,intersection:Me.INTERSECT},$.containsAABB3(a,r))return void this._insertEntityIntoKDTree(e.left,t,i,s+1)}if(!e.right){var l=n.slice();if(l[o]=(n[o]+n[o+3])/2,e.right={aabb:l,intersection:Me.INTERSECT},$.containsAABB3(l,r))return void this._insertEntityIntoKDTree(e.right,t,i,s+1)}e.objects=e.objects||[],e.objects.push(i),$.expandAABB3(e.aabb,r)}}},{key:"_visitKDNode",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Me.INTERSECT;if(t===Me.INTERSECT||e.intersects!==t){t===Me.INTERSECT&&(t=Ee(this._frustum,e.aabb),e.intersects=t);var i=t===Me.OUTSIDE,s=e.objects;if(s&&s.length>0)for(var r=0,n=s.length;r=0;)e[t]=0}var i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),s=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),r=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),n=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),o=new Array(576);t(o);var a=new Array(60);t(a);var l=new Array(512);t(l);var u=new Array(256);t(u);var A=new Array(29);t(A);var c,h,d,p=new Array(30);function f(e,t,i,s,r){this.static_tree=e,this.extra_bits=t,this.extra_base=i,this.elems=s,this.max_length=r,this.has_stree=e&&e.length}function v(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}t(p);var g=function(e){return e<256?l[e]:l[256+(e>>>7)]},m=function(e,t){e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},_=function(e,t,i){e.bi_valid>16-i?(e.bi_buf|=t<>16-e.bi_valid,e.bi_valid+=i-16):(e.bi_buf|=t<>>=1,i<<=1}while(--t>0);return i>>>1},B=function(e,t,i){var s,r,n=new Array(16),o=0;for(s=1;s<=15;s++)o=o+i[s-1]<<1,n[s]=o;for(r=0;r<=t;r++){var a=e[2*r+1];0!==a&&(e[2*r]=b(n[a]++,a))}},x=function(e){var t;for(t=0;t<286;t++)e.dyn_ltree[2*t]=0;for(t=0;t<30;t++)e.dyn_dtree[2*t]=0;for(t=0;t<19;t++)e.bl_tree[2*t]=0;e.dyn_ltree[512]=1,e.opt_len=e.static_len=0,e.sym_next=e.matches=0},P=function(e){e.bi_valid>8?m(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},C=function(e,t,i,s){var r=2*t,n=2*i;return e[r]>1;i>=1;i--)M(e,n,i);r=l;do{i=e.heap[1],e.heap[1]=e.heap[e.heap_len--],M(e,n,1),s=e.heap[1],e.heap[--e.heap_max]=i,e.heap[--e.heap_max]=s,n[2*r]=n[2*i]+n[2*s],e.depth[r]=(e.depth[i]>=e.depth[s]?e.depth[i]:e.depth[s])+1,n[2*i+1]=n[2*s+1]=r,e.heap[1]=r++,M(e,n,1)}while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],function(e,t){var i,s,r,n,o,a,l=t.dyn_tree,u=t.max_code,A=t.stat_desc.static_tree,c=t.stat_desc.has_stree,h=t.stat_desc.extra_bits,d=t.stat_desc.extra_base,p=t.stat_desc.max_length,f=0;for(n=0;n<=15;n++)e.bl_count[n]=0;for(l[2*e.heap[e.heap_max]+1]=0,i=e.heap_max+1;i<573;i++)(n=l[2*l[2*(s=e.heap[i])+1]+1]+1)>p&&(n=p,f++),l[2*s+1]=n,s>u||(e.bl_count[n]++,o=0,s>=d&&(o=h[s-d]),a=l[2*s],e.opt_len+=a*(n+o),c&&(e.static_len+=a*(A[2*s+1]+o)));if(0!==f){do{for(n=p-1;0===e.bl_count[n];)n--;e.bl_count[n]--,e.bl_count[n+1]+=2,e.bl_count[p]--,f-=2}while(f>0);for(n=p;0!==n;n--)for(s=e.bl_count[n];0!==s;)(r=e.heap[--i])>u||(l[2*r+1]!==n&&(e.opt_len+=(n-l[2*r+1])*l[2*r],l[2*r+1]=n),s--)}}(e,t),B(n,u,e.bl_count)},k=function(e,t,i){var s,r,n=-1,o=t[1],a=0,l=7,u=4;for(0===o&&(l=138,u=3),t[2*(i+1)+1]=65535,s=0;s<=i;s++)r=o,o=t[2*(s+1)+1],++a>=7;v<30;v++)for(p[v]=g<<7,e=0;e<1<0?(2===e.strm.data_type&&(e.strm.data_type=function(e){var t,i=4093624447;for(t=0;t<=31;t++,i>>>=1)if(1&i&&0!==e.dyn_ltree[2*t])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(t=32;t<256;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0}(e)),E(e,e.l_desc),E(e,e.d_desc),u=function(e){var t;for(k(e,e.dyn_ltree,e.l_desc.max_code),k(e,e.dyn_dtree,e.d_desc.max_code),E(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*n[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t}(e),r=e.opt_len+3+7>>>3,(l=e.static_len+3+7>>>3)<=r&&(r=l)):r=l=i+5,i+4<=r&&-1!==t?S(e,t,i,s):4===e.strategy||l===r?(_(e,2+(s?1:0),3),F(e,o,a)):(_(e,4+(s?1:0),3),function(e,t,i,s){var r;for(_(e,t-257,5),_(e,i-1,5),_(e,s-4,4),r=0;r>8,e.pending_buf[e.sym_buf+e.sym_next++]=i,0===t?e.dyn_ltree[2*i]++:(e.matches++,t--,e.dyn_ltree[2*(u[i]+256+1)]++,e.dyn_dtree[2*g(t)]++),e.sym_next===e.sym_end},O=function(e){_(e,2,3),y(e,256,o),function(e){16===e.bi_valid?(m(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}(e)},N=function(e,t,i,s){for(var r=65535&e|0,n=e>>>16&65535|0,o=0;0!==i;){i-=o=i>2e3?2e3:i;do{n=n+(r=r+t[s++]|0)|0}while(--o);r%=65521,n%=65521}return r|n<<16|0},Q=new Uint32Array(function(){for(var e,t=[],i=0;i<256;i++){e=i;for(var s=0;s<8;s++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e}return t}()),V=function(e,t,i,s){var r=Q,n=s+i;e^=-1;for(var o=s;o>>8^r[255&(e^t[o])];return-1^e},H={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},j={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},G=T,z=R,W=L,K=U,X=O,J=j.Z_NO_FLUSH,Y=j.Z_PARTIAL_FLUSH,Z=j.Z_FULL_FLUSH,q=j.Z_FINISH,$=j.Z_BLOCK,ee=j.Z_OK,te=j.Z_STREAM_END,ie=j.Z_STREAM_ERROR,se=j.Z_DATA_ERROR,re=j.Z_BUF_ERROR,ne=j.Z_DEFAULT_COMPRESSION,oe=j.Z_FILTERED,ae=j.Z_HUFFMAN_ONLY,le=j.Z_RLE,ue=j.Z_FIXED,Ae=j.Z_UNKNOWN,ce=j.Z_DEFLATED,he=258,de=262,pe=42,fe=113,ve=666,ge=function(e,t){return e.msg=H[t],t},me=function(e){return 2*e-(e>4?9:0)},_e=function(e){for(var t=e.length;--t>=0;)e[t]=0},ye=function(e){var t,i,s,r=e.w_size;s=t=e.hash_size;do{i=e.head[--s],e.head[s]=i>=r?i-r:0}while(--t);s=t=r;do{i=e.prev[--s],e.prev[s]=i>=r?i-r:0}while(--t)},be=function(e,t,i){return(t<e.avail_out&&(i=e.avail_out),0!==i&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+i),e.next_out),e.next_out+=i,t.pending_out+=i,e.total_out+=i,e.avail_out-=i,t.pending-=i,0===t.pending&&(t.pending_out=0))},we=function(e,t){W(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,Be(e.strm)},xe=function(e,t){e.pending_buf[e.pending++]=t},Pe=function(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},Ce=function(e,t,i,s){var r=e.avail_in;return r>s&&(r=s),0===r?0:(e.avail_in-=r,t.set(e.input.subarray(e.next_in,e.next_in+r),i),1===e.state.wrap?e.adler=N(e.adler,t,r,i):2===e.state.wrap&&(e.adler=V(e.adler,t,r,i)),e.next_in+=r,e.total_in+=r,r)},Me=function(e,t){var i,s,r=e.max_chain_length,n=e.strstart,o=e.prev_length,a=e.nice_match,l=e.strstart>e.w_size-de?e.strstart-(e.w_size-de):0,u=e.window,A=e.w_mask,c=e.prev,h=e.strstart+he,d=u[n+o-1],p=u[n+o];e.prev_length>=e.good_match&&(r>>=2),a>e.lookahead&&(a=e.lookahead);do{if(u[(i=t)+o]===p&&u[i+o-1]===d&&u[i]===u[n]&&u[++i]===u[n+1]){n+=2,i++;do{}while(u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&u[++n]===u[++i]&&no){if(e.match_start=t,o=s,s>=a)break;d=u[n+o-1],p=u[n+o]}}}while((t=c[t&A])>l&&0!=--r);return o<=e.lookahead?o:e.lookahead},Fe=function(e){var t,i,s,r=e.w_size;do{if(i=e.window_size-e.lookahead-e.strstart,e.strstart>=r+(r-de)&&(e.window.set(e.window.subarray(r,r+r-i),0),e.match_start-=r,e.strstart-=r,e.block_start-=r,e.insert>e.strstart&&(e.insert=e.strstart),ye(e),i+=r),0===e.strm.avail_in)break;if(t=Ce(e.strm,e.window,e.strstart+e.lookahead,i),e.lookahead+=t,e.lookahead+e.insert>=3)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=be(e,e.ins_h,e.window[s+1]);e.insert&&(e.ins_h=be(e,e.ins_h,e.window[s+3-1]),e.prev[s&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=s,s++,e.insert--,!(e.lookahead+e.insert<3)););}while(e.lookaheade.w_size?e.w_size:e.pending_buf_size-5,o=0,a=e.strm.avail_in;do{if(i=65535,r=e.bi_valid+42>>3,e.strm.avail_out(s=e.strstart-e.block_start)+e.strm.avail_in&&(i=s+e.strm.avail_in),i>r&&(i=r),i>8,e.pending_buf[e.pending-2]=~i,e.pending_buf[e.pending-1]=~i>>8,Be(e.strm),s&&(s>i&&(s=i),e.strm.output.set(e.window.subarray(e.block_start,e.block_start+s),e.strm.next_out),e.strm.next_out+=s,e.strm.avail_out-=s,e.strm.total_out+=s,e.block_start+=s,i-=s),i&&(Ce(e.strm,e.strm.output,e.strm.next_out,i),e.strm.next_out+=i,e.strm.avail_out-=i,e.strm.total_out+=i)}while(0===o);return(a-=e.strm.avail_in)&&(a>=e.w_size?(e.matches=2,e.window.set(e.strm.input.subarray(e.strm.next_in-e.w_size,e.strm.next_in),0),e.strstart=e.w_size,e.insert=e.strstart):(e.window_size-e.strstart<=a&&(e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,e.insert>e.strstart&&(e.insert=e.strstart)),e.window.set(e.strm.input.subarray(e.strm.next_in-a,e.strm.next_in),e.strstart),e.strstart+=a,e.insert+=a>e.w_size-e.insert?e.w_size-e.insert:a),e.block_start=e.strstart),e.high_waterr&&e.block_start>=e.w_size&&(e.block_start-=e.w_size,e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,r+=e.w_size,e.insert>e.strstart&&(e.insert=e.strstart)),r>e.strm.avail_in&&(r=e.strm.avail_in),r&&(Ce(e.strm,e.window,e.strstart,r),e.strstart+=r,e.insert+=r>e.w_size-e.insert?e.w_size-e.insert:r),e.high_water>3,n=(r=e.pending_buf_size-r>65535?65535:e.pending_buf_size-r)>e.w_size?e.w_size:r,((s=e.strstart-e.block_start)>=n||(s||t===q)&&t!==J&&0===e.strm.avail_in&&s<=r)&&(i=s>r?r:s,o=t===q&&0===e.strm.avail_in&&i===s?1:0,z(e,e.block_start,i,o),e.block_start+=i,Be(e.strm)),o?3:1)},ke=function(e,t){for(var i,s;;){if(e.lookahead=3&&(e.ins_h=be(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==i&&e.strstart-i<=e.w_size-de&&(e.match_length=Me(e,i)),e.match_length>=3)if(s=K(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=3){e.match_length--;do{e.strstart++,e.ins_h=be(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart}while(0!=--e.match_length);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=be(e,e.ins_h,e.window[e.strstart+1]);else s=K(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(s&&(we(e,!1),0===e.strm.avail_out))return 1}return e.insert=e.strstart<2?e.strstart:2,t===q?(we(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(we(e,!1),0===e.strm.avail_out)?1:2},Ie=function(e,t){for(var i,s,r;;){if(e.lookahead=3&&(e.ins_h=be(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==i&&e.prev_length4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){r=e.strstart+e.lookahead-3,s=K(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do{++e.strstart<=r&&(e.ins_h=be(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart)}while(0!=--e.prev_length);if(e.match_available=0,e.match_length=2,e.strstart++,s&&(we(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if((s=K(e,0,e.window[e.strstart-1]))&&we(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(s=K(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===q?(we(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(we(e,!1),0===e.strm.avail_out)?1:2};function De(e,t,i,s,r){this.good_length=e,this.max_lazy=t,this.nice_length=i,this.max_chain=s,this.func=r}var Se=[new De(0,0,0,0,Ee),new De(4,4,8,4,ke),new De(4,5,16,8,ke),new De(4,6,32,32,ke),new De(4,4,16,16,Ie),new De(8,16,32,32,Ie),new De(8,16,128,128,Ie),new De(8,32,128,256,Ie),new De(32,128,258,1024,Ie),new De(32,258,258,4096,Ie)];function Te(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ce,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),_e(this.dyn_ltree),_e(this.dyn_dtree),_e(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),_e(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),_e(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Re=function(e){if(!e)return 1;var t=e.state;return!t||t.strm!==e||t.status!==pe&&57!==t.status&&69!==t.status&&73!==t.status&&91!==t.status&&103!==t.status&&t.status!==fe&&t.status!==ve?1:0},Le=function(e){if(Re(e))return ge(e,ie);e.total_in=e.total_out=0,e.data_type=Ae;var t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=2===t.wrap?57:t.wrap?pe:fe,e.adler=2===t.wrap?0:1,t.last_flush=-2,G(t),ee},Ue=function(e){var t,i=Le(e);return i===ee&&((t=e.state).window_size=2*t.w_size,_e(t.head),t.max_lazy_match=Se[t.level].max_lazy,t.good_match=Se[t.level].good_length,t.nice_match=Se[t.level].nice_length,t.max_chain_length=Se[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=2,t.match_available=0,t.ins_h=0),i},Oe=function(e,t,i,s,r,n){if(!e)return ie;var o=1;if(t===ne&&(t=6),s<0?(o=0,s=-s):s>15&&(o=2,s-=16),r<1||r>9||i!==ce||s<8||s>15||t<0||t>9||n<0||n>ue||8===s&&1!==o)return ge(e,ie);8===s&&(s=9);var a=new Te;return e.state=a,a.strm=e,a.status=pe,a.wrap=o,a.gzhead=null,a.w_bits=s,a.w_size=1<$||t<0)return e?ge(e,ie):ie;var i=e.state;if(!e.output||0!==e.avail_in&&!e.input||i.status===ve&&t!==q)return ge(e,0===e.avail_out?re:ie);var s=i.last_flush;if(i.last_flush=t,0!==i.pending){if(Be(e),0===e.avail_out)return i.last_flush=-1,ee}else if(0===e.avail_in&&me(t)<=me(s)&&t!==q)return ge(e,re);if(i.status===ve&&0!==e.avail_in)return ge(e,re);if(i.status===pe&&0===i.wrap&&(i.status=fe),i.status===pe){var r=ce+(i.w_bits-8<<4)<<8;if(r|=(i.strategy>=ae||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(r|=32),Pe(i,r+=31-r%31),0!==i.strstart&&(Pe(i,e.adler>>>16),Pe(i,65535&e.adler)),e.adler=1,i.status=fe,Be(e),0!==i.pending)return i.last_flush=-1,ee}if(57===i.status)if(e.adler=0,xe(i,31),xe(i,139),xe(i,8),i.gzhead)xe(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),xe(i,255&i.gzhead.time),xe(i,i.gzhead.time>>8&255),xe(i,i.gzhead.time>>16&255),xe(i,i.gzhead.time>>24&255),xe(i,9===i.level?2:i.strategy>=ae||i.level<2?4:0),xe(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(xe(i,255&i.gzhead.extra.length),xe(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(e.adler=V(e.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69;else if(xe(i,0),xe(i,0),xe(i,0),xe(i,0),xe(i,0),xe(i,9===i.level?2:i.strategy>=ae||i.level<2?4:0),xe(i,3),i.status=fe,Be(e),0!==i.pending)return i.last_flush=-1,ee;if(69===i.status){if(i.gzhead.extra){for(var n=i.pending,o=(65535&i.gzhead.extra.length)-i.gzindex;i.pending+o>i.pending_buf_size;){var a=i.pending_buf_size-i.pending;if(i.pending_buf.set(i.gzhead.extra.subarray(i.gzindex,i.gzindex+a),i.pending),i.pending=i.pending_buf_size,i.gzhead.hcrc&&i.pending>n&&(e.adler=V(e.adler,i.pending_buf,i.pending-n,n)),i.gzindex+=a,Be(e),0!==i.pending)return i.last_flush=-1,ee;n=0,o-=a}var l=new Uint8Array(i.gzhead.extra);i.pending_buf.set(l.subarray(i.gzindex,i.gzindex+o),i.pending),i.pending+=o,i.gzhead.hcrc&&i.pending>n&&(e.adler=V(e.adler,i.pending_buf,i.pending-n,n)),i.gzindex=0}i.status=73}if(73===i.status){if(i.gzhead.name){var u,A=i.pending;do{if(i.pending===i.pending_buf_size){if(i.gzhead.hcrc&&i.pending>A&&(e.adler=V(e.adler,i.pending_buf,i.pending-A,A)),Be(e),0!==i.pending)return i.last_flush=-1,ee;A=0}u=i.gzindexA&&(e.adler=V(e.adler,i.pending_buf,i.pending-A,A)),i.gzindex=0}i.status=91}if(91===i.status){if(i.gzhead.comment){var c,h=i.pending;do{if(i.pending===i.pending_buf_size){if(i.gzhead.hcrc&&i.pending>h&&(e.adler=V(e.adler,i.pending_buf,i.pending-h,h)),Be(e),0!==i.pending)return i.last_flush=-1,ee;h=0}c=i.gzindexh&&(e.adler=V(e.adler,i.pending_buf,i.pending-h,h))}i.status=103}if(103===i.status){if(i.gzhead.hcrc){if(i.pending+2>i.pending_buf_size&&(Be(e),0!==i.pending))return i.last_flush=-1,ee;xe(i,255&e.adler),xe(i,e.adler>>8&255),e.adler=0}if(i.status=fe,Be(e),0!==i.pending)return i.last_flush=-1,ee}if(0!==e.avail_in||0!==i.lookahead||t!==J&&i.status!==ve){var d=0===i.level?Ee(i,t):i.strategy===ae?function(e,t){for(var i;;){if(0===e.lookahead&&(Fe(e),0===e.lookahead)){if(t===J)return 1;break}if(e.match_length=0,i=K(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,i&&(we(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===q?(we(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(we(e,!1),0===e.strm.avail_out)?1:2}(i,t):i.strategy===le?function(e,t){for(var i,s,r,n,o=e.window;;){if(e.lookahead<=he){if(Fe(e),e.lookahead<=he&&t===J)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&((s=o[r=e.strstart-1])===o[++r]&&s===o[++r]&&s===o[++r])){n=e.strstart+he;do{}while(s===o[++r]&&s===o[++r]&&s===o[++r]&&s===o[++r]&&s===o[++r]&&s===o[++r]&&s===o[++r]&&s===o[++r]&&re.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(i=K(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(i=K(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),i&&(we(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===q?(we(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(we(e,!1),0===e.strm.avail_out)?1:2}(i,t):Se[i.level].func(i,t);if(3!==d&&4!==d||(i.status=ve),1===d||3===d)return 0===e.avail_out&&(i.last_flush=-1),ee;if(2===d&&(t===Y?X(i):t!==$&&(z(i,0,0,!1),t===Z&&(_e(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),Be(e),0===e.avail_out))return i.last_flush=-1,ee}return t!==q?ee:i.wrap<=0?te:(2===i.wrap?(xe(i,255&e.adler),xe(i,e.adler>>8&255),xe(i,e.adler>>16&255),xe(i,e.adler>>24&255),xe(i,255&e.total_in),xe(i,e.total_in>>8&255),xe(i,e.total_in>>16&255),xe(i,e.total_in>>24&255)):(Pe(i,e.adler>>>16),Pe(i,65535&e.adler)),Be(e),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?ee:te)},He=function(e){if(Re(e))return ie;var t=e.state.status;return e.state=null,t===fe?ge(e,se):ee},je=function(e,t){var i=t.length;if(Re(e))return ie;var s=e.state,r=s.wrap;if(2===r||1===r&&s.status!==pe||s.lookahead)return ie;if(1===r&&(e.adler=N(e.adler,t,i,0)),s.wrap=0,i>=s.w_size){0===r&&(_e(s.head),s.strstart=0,s.block_start=0,s.insert=0);var n=new Uint8Array(s.w_size);n.set(t.subarray(i-s.w_size,i),0),t=n,i=s.w_size}var o=e.avail_in,a=e.next_in,l=e.input;for(e.avail_in=i,e.next_in=0,e.input=t,Fe(s);s.lookahead>=3;){var u=s.strstart,A=s.lookahead-2;do{s.ins_h=be(s,s.ins_h,s.window[u+3-1]),s.prev[u&s.w_mask]=s.head[s.ins_h],s.head[s.ins_h]=u,u++}while(--A);s.strstart=u,s.lookahead=2,Fe(s)}return s.strstart+=s.lookahead,s.block_start=s.strstart,s.insert=s.lookahead,s.lookahead=0,s.match_length=s.prev_length=2,s.match_available=0,e.next_in=a,e.input=l,e.avail_in=o,s.wrap=r,ee},Ge=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},ze=function(e){for(var t=Array.prototype.slice.call(arguments,1);t.length;){var i=t.shift();if(i){if("object"!=w(i))throw new TypeError(i+"must be non-object");for(var s in i)Ge(i,s)&&(e[s]=i[s])}}return e},We=function(e){for(var t=0,i=0,s=e.length;i=252?6:Je>=248?5:Je>=240?4:Je>=224?3:Je>=192?2:1;Xe[254]=Xe[254]=1;var Ye=function(e){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);var t,i,s,r,n,o=e.length,a=0;for(r=0;r>>6,t[n++]=128|63&i):i<65536?(t[n++]=224|i>>>12,t[n++]=128|i>>>6&63,t[n++]=128|63&i):(t[n++]=240|i>>>18,t[n++]=128|i>>>12&63,t[n++]=128|i>>>6&63,t[n++]=128|63&i);return t},Ze=function(e,t){var i,s,r=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));var n=new Array(2*r);for(s=0,i=0;i4)n[s++]=65533,i+=a-1;else{for(o&=2===a?31:3===a?15:7;a>1&&i1?n[s++]=65533:o<65536?n[s++]=o:(o-=65536,n[s++]=55296|o>>10&1023,n[s++]=56320|1023&o)}}}return function(e,t){if(t<65534&&e.subarray&&Ke)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));for(var i="",s=0;se.length&&(t=e.length);for(var i=t-1;i>=0&&128==(192&e[i]);)i--;return i<0||0===i?t:i+Xe[e[i]]>t?i:t},$e=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},et=Object.prototype.toString,tt=j.Z_NO_FLUSH,it=j.Z_SYNC_FLUSH,st=j.Z_FULL_FLUSH,rt=j.Z_FINISH,nt=j.Z_OK,ot=j.Z_STREAM_END,at=j.Z_DEFAULT_COMPRESSION,lt=j.Z_DEFAULT_STRATEGY,ut=j.Z_DEFLATED;function At(e){this.options=ze({level:at,method:ut,chunkSize:16384,windowBits:15,memLevel:8,strategy:lt},e||{});var t=this.options;t.raw&&t.windowBits>0?t.windowBits=-t.windowBits:t.gzip&&t.windowBits>0&&t.windowBits<16&&(t.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new $e,this.strm.avail_out=0;var i=Ne(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(i!==nt)throw new Error(H[i]);if(t.header&&Qe(this.strm,t.header),t.dictionary){var s;if(s="string"==typeof t.dictionary?Ye(t.dictionary):"[object ArrayBuffer]"===et.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,(i=je(this.strm,s))!==nt)throw new Error(H[i]);this._dict_set=!0}}function ct(e,t){var i=new At(t);if(i.push(e,!0),i.err)throw i.msg||H[i.err];return i.result}At.prototype.push=function(e,t){var i,s,r=this.strm,n=this.options.chunkSize;if(this.ended)return!1;for(s=t===~~t?t:!0===t?rt:tt,"string"==typeof e?r.input=Ye(e):"[object ArrayBuffer]"===et.call(e)?r.input=new Uint8Array(e):r.input=e,r.next_in=0,r.avail_in=r.input.length;;)if(0===r.avail_out&&(r.output=new Uint8Array(n),r.next_out=0,r.avail_out=n),(s===it||s===st)&&r.avail_out<=6)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else{if((i=Ve(r,s))===ot)return r.next_out>0&&this.onData(r.output.subarray(0,r.next_out)),i=He(this.strm),this.onEnd(i),this.ended=!0,i===nt;if(0!==r.avail_out){if(s>0&&r.next_out>0)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else if(0===r.avail_in)break}else this.onData(r.output)}return!0},At.prototype.onData=function(e){this.chunks.push(e)},At.prototype.onEnd=function(e){e===nt&&(this.result=We(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var ht=At,dt=ct,pt=function(e,t){return(t=t||{}).raw=!0,ct(e,t)},ft=function(e,t){return(t=t||{}).gzip=!0,ct(e,t)},vt=16209,gt=function(e,t){var i,s,r,n,o,a,l,u,A,c,h,d,p,f,v,g,m,_,y,b,B,w,x,P,C=e.state;i=e.next_in,x=e.input,s=i+(e.avail_in-5),r=e.next_out,P=e.output,n=r-(t-e.avail_out),o=r+(e.avail_out-257),a=C.dmax,l=C.wsize,u=C.whave,A=C.wnext,c=C.window,h=C.hold,d=C.bits,p=C.lencode,f=C.distcode,v=(1<>>=_=m>>>24,d-=_,0===(_=m>>>16&255))P[r++]=65535&m;else{if(!(16&_)){if(0==(64&_)){m=p[(65535&m)+(h&(1<<_)-1)];continue t}if(32&_){C.mode=16191;break e}e.msg="invalid literal/length code",C.mode=vt;break e}y=65535&m,(_&=15)&&(d<_&&(h+=x[i++]<>>=_,d-=_),d<15&&(h+=x[i++]<>>=_=m>>>24,d-=_,!(16&(_=m>>>16&255))){if(0==(64&_)){m=f[(65535&m)+(h&(1<<_)-1)];continue i}e.msg="invalid distance code",C.mode=vt;break e}if(b=65535&m,d<(_&=15)&&(h+=x[i++]<a){e.msg="invalid distance too far back",C.mode=vt;break e}if(h>>>=_,d-=_,b>(_=r-n)){if((_=b-_)>u&&C.sane){e.msg="invalid distance too far back",C.mode=vt;break e}if(B=0,w=c,0===A){if(B+=l-_,_2;)P[r++]=w[B++],P[r++]=w[B++],P[r++]=w[B++],y-=3;y&&(P[r++]=w[B++],y>1&&(P[r++]=w[B++]))}else{B=r-b;do{P[r++]=P[B++],P[r++]=P[B++],P[r++]=P[B++],y-=3}while(y>2);y&&(P[r++]=P[B++],y>1&&(P[r++]=P[B++]))}break}}break}}while(i>3,h&=(1<<(d-=y<<3))-1,e.next_in=i,e.next_out=r,e.avail_in=i=1&&0===E[b];b--);if(B>b&&(B=b),0===b)return r[n++]=20971520,r[n++]=20971520,a.bits=1,0;for(y=1;y0&&(0===e||1!==b))return-1;for(k[1]=0,m=1;m<15;m++)k[m+1]=k[m]+E[m];for(_=0;_852||2===e&&C>592)return 1;for(;;){p=m-x,o[_]+1=d?(f=I[o[_]-d],v=F[o[_]-d]):(f=96,v=0),l=1<>x)+(u-=l)]=p<<24|f<<16|v|0}while(0!==u);for(l=1<>=1;if(0!==l?(M&=l-1,M+=l):M=0,_++,0==--E[m]){if(m===b)break;m=t[i+o[_]]}if(m>B&&(M&c)!==A){for(0===x&&(x=B),h+=y,P=1<<(w=m-x);w+x852||2===e&&C>592)return 1;r[A=M&c]=B<<24|w<<16|h-n|0}}return 0!==M&&(r[h+M]=m-x<<24|64<<16|0),a.bits=B,0},wt=j.Z_FINISH,xt=j.Z_BLOCK,Pt=j.Z_TREES,Ct=j.Z_OK,Mt=j.Z_STREAM_END,Ft=j.Z_NEED_DICT,Et=j.Z_STREAM_ERROR,kt=j.Z_DATA_ERROR,It=j.Z_MEM_ERROR,Dt=j.Z_BUF_ERROR,St=j.Z_DEFLATED,Tt=16180,Rt=16190,Lt=16191,Ut=16192,Ot=16194,Nt=16199,Qt=16200,Vt=16206,Ht=16209,jt=function(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)};function Gt(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var zt,Wt,Kt=function(e){if(!e)return 1;var t=e.state;return!t||t.strm!==e||t.mode16211?1:0},Xt=function(e){if(Kt(e))return Et;var t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=Tt,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,Ct},Jt=function(e){if(Kt(e))return Et;var t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,Xt(e)},Yt=function(e,t){var i;if(Kt(e))return Et;var s=e.state;return t<0?(i=0,t=-t):(i=5+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?Et:(null!==s.window&&s.wbits!==t&&(s.window=null),s.wrap=i,s.wbits=t,Jt(e))},Zt=function(e,t){if(!e)return Et;var i=new Gt;e.state=i,i.strm=e,i.window=null,i.mode=Tt;var s=Yt(e,t);return s!==Ct&&(e.state=null),s},qt=!0,$t=function(e){if(qt){zt=new Int32Array(512),Wt=new Int32Array(32);for(var t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(Bt(1,e.lens,0,288,zt,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;Bt(2,e.lens,0,32,Wt,0,e.work,{bits:5}),qt=!1}e.lencode=zt,e.lenbits=9,e.distcode=Wt,e.distbits=5},ei=function(e,t,i,s){var r,n=e.state;return null===n.window&&(n.wsize=1<=n.wsize?(n.window.set(t.subarray(i-n.wsize,i),0),n.wnext=0,n.whave=n.wsize):((r=n.wsize-n.wnext)>s&&(r=s),n.window.set(t.subarray(i-s,i-s+r),n.wnext),(s-=r)?(n.window.set(t.subarray(i-s,i),0),n.wnext=s,n.whave=n.wsize):(n.wnext+=r,n.wnext===n.wsize&&(n.wnext=0),n.whave>>8&255,i.check=V(i.check,M,2,0),u=0,A=0,i.mode=16181;break}if(i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&u)<<8)+(u>>8))%31){e.msg="incorrect header check",i.mode=Ht;break}if((15&u)!==St){e.msg="unknown compression method",i.mode=Ht;break}if(A-=4,B=8+(15&(u>>>=4)),0===i.wbits&&(i.wbits=B),B>15||B>i.wbits){e.msg="invalid window size",i.mode=Ht;break}i.dmax=1<>8&1),512&i.flags&&4&i.wrap&&(M[0]=255&u,M[1]=u>>>8&255,i.check=V(i.check,M,2,0)),u=0,A=0,i.mode=16182;case 16182:for(;A<32;){if(0===a)break e;a--,u+=s[n++]<>>8&255,M[2]=u>>>16&255,M[3]=u>>>24&255,i.check=V(i.check,M,4,0)),u=0,A=0,i.mode=16183;case 16183:for(;A<16;){if(0===a)break e;a--,u+=s[n++]<>8),512&i.flags&&4&i.wrap&&(M[0]=255&u,M[1]=u>>>8&255,i.check=V(i.check,M,2,0)),u=0,A=0,i.mode=16184;case 16184:if(1024&i.flags){for(;A<16;){if(0===a)break e;a--,u+=s[n++]<>>8&255,i.check=V(i.check,M,2,0)),u=0,A=0}else i.head&&(i.head.extra=null);i.mode=16185;case 16185:if(1024&i.flags&&((d=i.length)>a&&(d=a),d&&(i.head&&(B=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(s.subarray(n,n+d),B)),512&i.flags&&4&i.wrap&&(i.check=V(i.check,s,d,n)),a-=d,n+=d,i.length-=d),i.length))break e;i.length=0,i.mode=16186;case 16186:if(2048&i.flags){if(0===a)break e;d=0;do{B=s[n+d++],i.head&&B&&i.length<65536&&(i.head.name+=String.fromCharCode(B))}while(B&&d>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=Lt;break;case 16189:for(;A<32;){if(0===a)break e;a--,u+=s[n++]<>>=7&A,A-=7&A,i.mode=Vt;break}for(;A<3;){if(0===a)break e;a--,u+=s[n++]<>>=1)){case 0:i.mode=16193;break;case 1:if($t(i),i.mode=Nt,t===Pt){u>>>=2,A-=2;break e}break;case 2:i.mode=16196;break;case 3:e.msg="invalid block type",i.mode=Ht}u>>>=2,A-=2;break;case 16193:for(u>>>=7&A,A-=7&A;A<32;){if(0===a)break e;a--,u+=s[n++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=Ht;break}if(i.length=65535&u,u=0,A=0,i.mode=Ot,t===Pt)break e;case Ot:i.mode=16195;case 16195:if(d=i.length){if(d>a&&(d=a),d>l&&(d=l),0===d)break e;r.set(s.subarray(n,n+d),o),a-=d,n+=d,l-=d,o+=d,i.length-=d;break}i.mode=Lt;break;case 16196:for(;A<14;){if(0===a)break e;a--,u+=s[n++]<>>=5,A-=5,i.ndist=1+(31&u),u>>>=5,A-=5,i.ncode=4+(15&u),u>>>=4,A-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=Ht;break}i.have=0,i.mode=16197;case 16197:for(;i.have>>=3,A-=3}for(;i.have<19;)i.lens[F[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,x={bits:i.lenbits},w=Bt(0,i.lens,0,19,i.lencode,0,i.work,x),i.lenbits=x.bits,w){e.msg="invalid code lengths set",i.mode=Ht;break}i.have=0,i.mode=16198;case 16198:for(;i.have>>16&255,m=65535&C,!((v=C>>>24)<=A);){if(0===a)break e;a--,u+=s[n++]<>>=v,A-=v,i.lens[i.have++]=m;else{if(16===m){for(P=v+2;A>>=v,A-=v,0===i.have){e.msg="invalid bit length repeat",i.mode=Ht;break}B=i.lens[i.have-1],d=3+(3&u),u>>>=2,A-=2}else if(17===m){for(P=v+3;A>>=v)),u>>>=3,A-=3}else{for(P=v+7;A>>=v)),u>>>=7,A-=7}if(i.have+d>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=Ht;break}for(;d--;)i.lens[i.have++]=B}}if(i.mode===Ht)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=Ht;break}if(i.lenbits=9,x={bits:i.lenbits},w=Bt(1,i.lens,0,i.nlen,i.lencode,0,i.work,x),i.lenbits=x.bits,w){e.msg="invalid literal/lengths set",i.mode=Ht;break}if(i.distbits=6,i.distcode=i.distdyn,x={bits:i.distbits},w=Bt(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,x),i.distbits=x.bits,w){e.msg="invalid distances set",i.mode=Ht;break}if(i.mode=Nt,t===Pt)break e;case Nt:i.mode=Qt;case Qt:if(a>=6&&l>=258){e.next_out=o,e.avail_out=l,e.next_in=n,e.avail_in=a,i.hold=u,i.bits=A,gt(e,h),o=e.next_out,r=e.output,l=e.avail_out,n=e.next_in,s=e.input,a=e.avail_in,u=i.hold,A=i.bits,i.mode===Lt&&(i.back=-1);break}for(i.back=0;g=(C=i.lencode[u&(1<>>16&255,m=65535&C,!((v=C>>>24)<=A);){if(0===a)break e;a--,u+=s[n++]<>_)])>>>16&255,m=65535&C,!(_+(v=C>>>24)<=A);){if(0===a)break e;a--,u+=s[n++]<>>=_,A-=_,i.back+=_}if(u>>>=v,A-=v,i.back+=v,i.length=m,0===g){i.mode=16205;break}if(32&g){i.back=-1,i.mode=Lt;break}if(64&g){e.msg="invalid literal/length code",i.mode=Ht;break}i.extra=15&g,i.mode=16201;case 16201:if(i.extra){for(P=i.extra;A>>=i.extra,A-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=16202;case 16202:for(;g=(C=i.distcode[u&(1<>>16&255,m=65535&C,!((v=C>>>24)<=A);){if(0===a)break e;a--,u+=s[n++]<>_)])>>>16&255,m=65535&C,!(_+(v=C>>>24)<=A);){if(0===a)break e;a--,u+=s[n++]<>>=_,A-=_,i.back+=_}if(u>>>=v,A-=v,i.back+=v,64&g){e.msg="invalid distance code",i.mode=Ht;break}i.offset=m,i.extra=15&g,i.mode=16203;case 16203:if(i.extra){for(P=i.extra;A>>=i.extra,A-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=Ht;break}i.mode=16204;case 16204:if(0===l)break e;if(d=h-l,i.offset>d){if((d=i.offset-d)>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=Ht;break}d>i.wnext?(d-=i.wnext,p=i.wsize-d):p=i.wnext-d,d>i.length&&(d=i.length),f=i.window}else f=r,p=o-i.offset,d=i.length;d>l&&(d=l),l-=d,i.length-=d;do{r[o++]=f[p++]}while(--d);0===i.length&&(i.mode=Qt);break;case 16205:if(0===l)break e;r[o++]=i.length,l--,i.mode=Qt;break;case Vt:if(i.wrap){for(;A<32;){if(0===a)break e;a--,u|=s[n++]<=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new $e,this.strm.avail_out=0;var i=ii(this.strm,t.windowBits);if(i!==ci)throw new Error(H[i]);if(this.header=new ai,ni(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=Ye(t.dictionary):"[object ArrayBuffer]"===li.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=oi(this.strm,t.dictionary))!==ci))throw new Error(H[i])}function mi(e,t){var i=new gi(t);if(i.push(e),i.err)throw i.msg||H[i.err];return i.result}gi.prototype.push=function(e,t){var i,s,r,n=this.strm,o=this.options.chunkSize,a=this.options.dictionary;if(this.ended)return!1;for(s=t===~~t?t:!0===t?Ai:ui,"[object ArrayBuffer]"===li.call(e)?n.input=new Uint8Array(e):n.input=e,n.next_in=0,n.avail_in=n.input.length;;){for(0===n.avail_out&&(n.output=new Uint8Array(o),n.next_out=0,n.avail_out=o),(i=si(n,s))===di&&a&&((i=oi(n,a))===ci?i=si(n,s):i===fi&&(i=di));n.avail_in>0&&i===hi&&n.state.wrap>0&&0!==e[n.next_in];)ti(n),i=si(n,s);switch(i){case pi:case fi:case di:case vi:return this.onEnd(i),this.ended=!0,!1}if(r=n.avail_out,n.next_out&&(0===n.avail_out||i===hi))if("string"===this.options.to){var l=qe(n.output,n.next_out),u=n.next_out-l,A=Ze(n.output,l);n.next_out=u,n.avail_out=o-u,u&&n.output.set(n.output.subarray(l,l+u),0),this.onData(A)}else this.onData(n.output.length===n.next_out?n.output:n.output.subarray(0,n.next_out));if(i!==ci||0!==r){if(i===hi)return i=ri(this.strm),this.onEnd(i),this.ended=!0,!0;if(0===n.avail_in)break}}return!0},gi.prototype.onData=function(e){this.chunks.push(e)},gi.prototype.onEnd=function(e){e===ci&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=We(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var _i=function(e,t){return(t=t||{}).raw=!0,mi(e,t)},yi=ht,bi=dt,Bi=pt,wi=ft,xi=gi,Pi=mi,Ci=_i,Mi=mi,Fi=j,Ei={Deflate:yi,deflate:bi,deflateRaw:Bi,gzip:wi,Inflate:xi,inflate:Pi,inflateRaw:Ci,ungzip:Mi,constants:Fi};e.Deflate=yi,e.Inflate=xi,e.constants=Fi,e.default=Ei,e.deflate=bi,e.deflateRaw=Bi,e.gzip=wi,e.inflate=Pi,e.inflateRaw=Ci,e.ungzip=Mi,Object.defineProperty(e,"__esModule",{value:!0})}));var dE=Object.freeze({__proto__:null}),pE=window.pako||dE;pE.inflate||(pE=pE.default);var fE,vE=(fE=new Float32Array(3),function(e){return fE[0]=e[0]/255,fE[1]=e[1]/255,fE[2]=e[2]/255,fE});var gE={version:1,parse:function(e,t,i,s,r,n){var o=function(e){return{positions:e[0],normals:e[1],indices:e[2],edgeIndices:e[3],meshPositions:e[4],meshIndices:e[5],meshEdgesIndices:e[6],meshColors:e[7],entityIDs:e[8],entityMeshes:e[9],entityIsObjects:e[10],positionsDecodeMatrix:e[11]}}(i),a=function(e){return{positions:new Uint16Array(pE.inflate(e.positions).buffer),normals:new Int8Array(pE.inflate(e.normals).buffer),indices:new Uint32Array(pE.inflate(e.indices).buffer),edgeIndices:new Uint32Array(pE.inflate(e.edgeIndices).buffer),meshPositions:new Uint32Array(pE.inflate(e.meshPositions).buffer),meshIndices:new Uint32Array(pE.inflate(e.meshIndices).buffer),meshEdgesIndices:new Uint32Array(pE.inflate(e.meshEdgesIndices).buffer),meshColors:new Uint8Array(pE.inflate(e.meshColors).buffer),entityIDs:pE.inflate(e.entityIDs,{to:"string"}),entityMeshes:new Uint32Array(pE.inflate(e.entityMeshes).buffer),entityIsObjects:new Uint8Array(pE.inflate(e.entityIsObjects).buffer),positionsDecodeMatrix:new Float32Array(pE.inflate(e.positionsDecodeMatrix).buffer)}}(o);!function(e,t,i,s,r,n){n.getNextId(),s.positionsCompression="precompressed",s.normalsCompression="precompressed";for(var o=i.positions,a=i.normals,l=i.indices,u=i.edgeIndices,A=i.meshPositions,c=i.meshIndices,h=i.meshEdgesIndices,d=i.meshColors,p=JSON.parse(i.entityIDs),f=i.entityMeshes,v=i.entityIsObjects,g=A.length,m=f.length,_=0;_v[t]?1:0}));for(var F=0;F1||(E[L]=k)}for(var U=0;U1,V=PE(g.subarray(4*O,4*O+3)),H=g[4*O+3]/255,j=a.subarray(d[O],N?a.length:d[O+1]),G=l.subarray(d[O],N?l.length:d[O+1]),z=u.subarray(p[O],N?u.length:p[O+1]),W=A.subarray(f[O],N?A.length:f[O+1]),K=c.subarray(v[O],v[O]+16);if(Q){var X="".concat(o,"-geometry.").concat(O);s.createGeometry({id:X,primitive:"triangles",positionsCompressed:j,normalsCompressed:G,indices:z,edgeIndices:W,positionsDecodeMatrix:K})}else{var J="".concat(o,"-").concat(O);_[E[O]],s.createMesh(le.apply({},{id:J,primitive:"triangles",positionsCompressed:j,normalsCompressed:G,indices:z,edgeIndices:W,positionsDecodeMatrix:K,color:V,opacity:H}))}}for(var Y=0,Z=0;Z1){var oe="".concat(o,"-instance.").concat(Y++),ae="".concat(o,"-geometry.").concat(ne),ue=16*b[Z],Ae=h.subarray(ue,ue+16);s.createMesh(le.apply({},{id:oe,geometryId:ae,matrix:Ae})),se.push(oe)}else se.push(ne)}se.length>0&&s.createEntity(le.apply({},{id:ee,isObject:!0,meshIds:se}))}}(0,0,a,s,0,n)}},ME=window.pako||dE;ME.inflate||(ME=ME.default);var FE=function(){var e=new Float32Array(3);return function(t){return e[0]=t[0]/255,e[1]=t[1]/255,e[2]=t[2]/255,e}}();var EE={version:5,parse:function(e,t,i,s,r,n){var o=function(e){return{positions:e[0],normals:e[1],indices:e[2],edgeIndices:e[3],matrices:e[4],eachPrimitivePositionsAndNormalsPortion:e[5],eachPrimitiveIndicesPortion:e[6],eachPrimitiveEdgeIndicesPortion:e[7],eachPrimitiveColor:e[8],primitiveInstances:e[9],eachEntityId:e[10],eachEntityPrimitiveInstancesPortion:e[11],eachEntityMatricesPortion:e[12]}}(i),a=function(e){return{positions:new Float32Array(ME.inflate(e.positions).buffer),normals:new Int8Array(ME.inflate(e.normals).buffer),indices:new Uint32Array(ME.inflate(e.indices).buffer),edgeIndices:new Uint32Array(ME.inflate(e.edgeIndices).buffer),matrices:new Float32Array(ME.inflate(e.matrices).buffer),eachPrimitivePositionsAndNormalsPortion:new Uint32Array(ME.inflate(e.eachPrimitivePositionsAndNormalsPortion).buffer),eachPrimitiveIndicesPortion:new Uint32Array(ME.inflate(e.eachPrimitiveIndicesPortion).buffer),eachPrimitiveEdgeIndicesPortion:new Uint32Array(ME.inflate(e.eachPrimitiveEdgeIndicesPortion).buffer),eachPrimitiveColor:new Uint8Array(ME.inflate(e.eachPrimitiveColor).buffer),primitiveInstances:new Uint32Array(ME.inflate(e.primitiveInstances).buffer),eachEntityId:ME.inflate(e.eachEntityId,{to:"string"}),eachEntityPrimitiveInstancesPortion:new Uint32Array(ME.inflate(e.eachEntityPrimitiveInstancesPortion).buffer),eachEntityMatricesPortion:new Uint32Array(ME.inflate(e.eachEntityMatricesPortion).buffer)}}(o);!function(e,t,i,s,r,n){var o=n.getNextId();s.positionsCompression="disabled",s.normalsCompression="precompressed";for(var a=i.positions,l=i.normals,u=i.indices,A=i.edgeIndices,c=i.matrices,h=i.eachPrimitivePositionsAndNormalsPortion,d=i.eachPrimitiveIndicesPortion,p=i.eachPrimitiveEdgeIndicesPortion,f=i.eachPrimitiveColor,v=i.primitiveInstances,g=JSON.parse(i.eachEntityId),m=i.eachEntityPrimitiveInstancesPortion,_=i.eachEntityMatricesPortion,y=h.length,b=v.length,B=new Uint8Array(y),w=g.length,x=0;x1||(P[D]=C)}for(var S=0;S1,L=FE(f.subarray(4*S,4*S+3)),U=f[4*S+3]/255,O=a.subarray(h[S],T?a.length:h[S+1]),N=l.subarray(h[S],T?l.length:h[S+1]),Q=u.subarray(d[S],T?u.length:d[S+1]),V=A.subarray(p[S],T?A.length:p[S+1]);if(R){var H="".concat(o,"-geometry.").concat(S);s.createGeometry({id:H,primitive:"triangles",positionsCompressed:O,normalsCompressed:N,indices:Q,edgeIndices:V})}else{var j=S;g[P[S]],s.createMesh(le.apply({},{id:j,primitive:"triangles",positionsCompressed:O,normalsCompressed:N,indices:Q,edgeIndices:V,color:L,opacity:U}))}}for(var G=0,z=0;z1){var ee="instance."+G++,te="geometry"+$,ie=16*_[z],se=c.subarray(ie,ie+16);s.createMesh(le.apply({},{id:ee,geometryId:te,matrix:se})),Z.push(ee)}else Z.push($)}Z.length>0&&s.createEntity(le.apply({},{id:X,isObject:!0,meshIds:Z}))}}(0,0,a,s,0,n)}},kE=window.pako||dE;kE.inflate||(kE=kE.default);var IE,DE=(IE=new Float32Array(3),function(e){return IE[0]=e[0]/255,IE[1]=e[1]/255,IE[2]=e[2]/255,IE});var SE={version:6,parse:function(e,t,i,s,r,n){var o=function(e){return{positions:e[0],normals:e[1],indices:e[2],edgeIndices:e[3],matrices:e[4],reusedPrimitivesDecodeMatrix:e[5],eachPrimitivePositionsAndNormalsPortion:e[6],eachPrimitiveIndicesPortion:e[7],eachPrimitiveEdgeIndicesPortion:e[8],eachPrimitiveColorAndOpacity:e[9],primitiveInstances:e[10],eachEntityId:e[11],eachEntityPrimitiveInstancesPortion:e[12],eachEntityMatricesPortion:e[13],eachTileAABB:e[14],eachTileEntitiesPortion:e[15]}}(i),a=function(e){function t(e,t){return 0===e.length?[]:kE.inflate(e,t).buffer}return{positions:new Uint16Array(t(e.positions)),normals:new Int8Array(t(e.normals)),indices:new Uint32Array(t(e.indices)),edgeIndices:new Uint32Array(t(e.edgeIndices)),matrices:new Float32Array(t(e.matrices)),reusedPrimitivesDecodeMatrix:new Float32Array(t(e.reusedPrimitivesDecodeMatrix)),eachPrimitivePositionsAndNormalsPortion:new Uint32Array(t(e.eachPrimitivePositionsAndNormalsPortion)),eachPrimitiveIndicesPortion:new Uint32Array(t(e.eachPrimitiveIndicesPortion)),eachPrimitiveEdgeIndicesPortion:new Uint32Array(t(e.eachPrimitiveEdgeIndicesPortion)),eachPrimitiveColorAndOpacity:new Uint8Array(t(e.eachPrimitiveColorAndOpacity)),primitiveInstances:new Uint32Array(t(e.primitiveInstances)),eachEntityId:kE.inflate(e.eachEntityId,{to:"string"}),eachEntityPrimitiveInstancesPortion:new Uint32Array(t(e.eachEntityPrimitiveInstancesPortion)),eachEntityMatricesPortion:new Uint32Array(t(e.eachEntityMatricesPortion)),eachTileAABB:new Float64Array(t(e.eachTileAABB)),eachTileEntitiesPortion:new Uint32Array(t(e.eachTileEntitiesPortion))}}(o);!function(e,t,i,s,r,n){for(var o=n.getNextId(),a=i.positions,l=i.normals,u=i.indices,A=i.edgeIndices,c=i.matrices,h=i.reusedPrimitivesDecodeMatrix,d=i.eachPrimitivePositionsAndNormalsPortion,p=i.eachPrimitiveIndicesPortion,f=i.eachPrimitiveEdgeIndicesPortion,v=i.eachPrimitiveColorAndOpacity,g=i.primitiveInstances,m=JSON.parse(i.eachEntityId),_=i.eachEntityPrimitiveInstancesPortion,y=i.eachEntityMatricesPortion,b=i.eachTileAABB,B=i.eachTileEntitiesPortion,w=d.length,x=g.length,P=m.length,C=B.length,M=new Uint32Array(w),F=0;F1,se=te===w-1,re=a.subarray(d[te],se?a.length:d[te+1]),ne=l.subarray(d[te],se?l.length:d[te+1]),oe=u.subarray(p[te],se?u.length:p[te+1]),ae=A.subarray(f[te],se?A.length:f[te+1]),ue=DE(v.subarray(4*te,4*te+3)),Ae=v[4*te+3]/255,ce=n.getNextId();if(ie){var he="".concat(o,"-geometry.").concat(D,".").concat(te);N[he]||(s.createGeometry({id:he,primitive:"triangles",positionsCompressed:re,indices:oe,edgeIndices:ae,positionsDecodeMatrix:h}),N[he]=!0),s.createMesh(le.apply(Z,{id:ce,geometryId:he,origin:k,matrix:G,color:ue,opacity:Ae})),X.push(ce)}else s.createMesh(le.apply(Z,{id:ce,origin:k,primitive:"triangles",positionsCompressed:re,normalsCompressed:ne,indices:oe,edgeIndices:ae,positionsDecodeMatrix:O,color:ue,opacity:Ae})),X.push(ce)}X.length>0&&s.createEntity(le.apply(Y,{id:H,isObject:!0,meshIds:X}))}}}(e,t,a,s,0,n)}},TE=window.pako||dE;TE.inflate||(TE=TE.default);var RE=function(){var e=new Float32Array(3);return function(t){return e[0]=t[0]/255,e[1]=t[1]/255,e[2]=t[2]/255,e}}();function LE(e){for(var t=[],i=0,s=e.length;i1,ne=se===M-1,oe=RE(B.subarray(6*ie,6*ie+3)),ae=B[6*ie+3]/255,ue=B[6*ie+4]/255,Ae=B[6*ie+5]/255,ce=n.getNextId();if(re){var he=b[ie],de=h.slice(he,he+16),pe="".concat(o,"-geometry.").concat(L,".").concat(se);if(!j[pe]){var fe=void 0,ve=void 0,ge=void 0,me=void 0,_e=void 0,ye=void 0;switch(p[se]){case 0:fe="solid",ve=a.subarray(f[se],ne?a.length:f[se+1]),ge=l.subarray(v[se],ne?l.length:v[se+1]),_e=A.subarray(m[se],ne?A.length:m[se+1]),ye=c.subarray(_[se],ne?c.length:_[se+1]);break;case 1:fe="surface",ve=a.subarray(f[se],ne?a.length:f[se+1]),ge=l.subarray(v[se],ne?l.length:v[se+1]),_e=A.subarray(m[se],ne?A.length:m[se+1]),ye=c.subarray(_[se],ne?c.length:_[se+1]);break;case 2:fe="points",ve=a.subarray(f[se],ne?a.length:f[se+1]),me=LE(u.subarray(g[se],ne?u.length:g[se+1]));break;case 3:fe="lines",ve=a.subarray(f[se],ne?a.length:f[se+1]),_e=A.subarray(m[se],ne?A.length:m[se+1]);break;default:continue}s.createGeometry({id:pe,primitive:fe,positionsCompressed:ve,normalsCompressed:ge,colors:me,indices:_e,edgeIndices:ye,positionsDecodeMatrix:d}),j[pe]=!0}s.createMesh(le.apply(ee,{id:ce,geometryId:pe,origin:T,matrix:de,color:oe,metallic:ue,roughness:Ae,opacity:ae})),Y.push(ce)}else{var be=void 0,Be=void 0,we=void 0,xe=void 0,Pe=void 0,Ce=void 0;switch(p[se]){case 0:be="solid",Be=a.subarray(f[se],ne?a.length:f[se+1]),we=l.subarray(v[se],ne?l.length:v[se+1]),Pe=A.subarray(m[se],ne?A.length:m[se+1]),Ce=c.subarray(_[se],ne?c.length:_[se+1]);break;case 1:be="surface",Be=a.subarray(f[se],ne?a.length:f[se+1]),we=l.subarray(v[se],ne?l.length:v[se+1]),Pe=A.subarray(m[se],ne?A.length:m[se+1]),Ce=c.subarray(_[se],ne?c.length:_[se+1]);break;case 2:be="points",Be=a.subarray(f[se],ne?a.length:f[se+1]),xe=LE(u.subarray(g[se],ne?u.length:g[se+1]));break;case 3:be="lines",Be=a.subarray(f[se],ne?a.length:f[se+1]),Pe=A.subarray(m[se],ne?A.length:m[se+1]);break;default:continue}s.createMesh(le.apply(ee,{id:ce,origin:T,primitive:be,positionsCompressed:Be,normalsCompressed:we,colors:xe,indices:Pe,edgeIndices:Ce,positionsDecodeMatrix:H,color:oe,metallic:ue,roughness:Ae,opacity:ae})),Y.push(ce)}}Y.length>0&&s.createEntity(le.apply(q,{id:W,isObject:!0,meshIds:Y}))}}}(e,t,a,s,0,n)}},OE=window.pako||dE;OE.inflate||(OE=OE.default);var NE=$.vec4(),QE=$.vec4();var VE=function(){var e=new Float32Array(3);return function(t){return e[0]=t[0]/255,e[1]=t[1]/255,e[2]=t[2]/255,e}}();function HE(e){for(var t=[],i=0,s=e.length;i1,ye=me===S-1,be=VE(M.subarray(6*ge,6*ge+3)),Be=M[6*ge+3]/255,we=M[6*ge+4]/255,xe=M[6*ge+5]/255,Pe=n.getNextId();if(_e){var Ce=C[ge],Me=g.slice(Ce,Ce+16),Fe="".concat(o,"-geometry.").concat(Y,".").concat(me),Ee=J[Fe];if(!Ee){Ee={batchThisMesh:!t.reuseGeometries};var ke=!1;switch(_[me]){case 0:Ee.primitiveName="solid",Ee.geometryPositions=h.subarray(y[me],ye?h.length:y[me+1]),Ee.geometryNormals=d.subarray(b[me],ye?d.length:b[me+1]),Ee.geometryIndices=f.subarray(w[me],ye?f.length:w[me+1]),Ee.geometryEdgeIndices=v.subarray(x[me],ye?v.length:x[me+1]),ke=Ee.geometryPositions.length>0&&Ee.geometryIndices.length>0;break;case 1:Ee.primitiveName="surface",Ee.geometryPositions=h.subarray(y[me],ye?h.length:y[me+1]),Ee.geometryNormals=d.subarray(b[me],ye?d.length:b[me+1]),Ee.geometryIndices=f.subarray(w[me],ye?f.length:w[me+1]),Ee.geometryEdgeIndices=v.subarray(x[me],ye?v.length:x[me+1]),ke=Ee.geometryPositions.length>0&&Ee.geometryIndices.length>0;break;case 2:Ee.primitiveName="points",Ee.geometryPositions=h.subarray(y[me],ye?h.length:y[me+1]),Ee.geometryColors=HE(p.subarray(B[me],ye?p.length:B[me+1])),ke=Ee.geometryPositions.length>0;break;case 3:Ee.primitiveName="lines",Ee.geometryPositions=h.subarray(y[me],ye?h.length:y[me+1]),Ee.geometryIndices=f.subarray(w[me],ye?f.length:w[me+1]),ke=Ee.geometryPositions.length>0&&Ee.geometryIndices.length>0;break;default:continue}if(ke||(Ee=null),Ee&&(Ee.geometryPositions.length,Ee.batchThisMesh)){Ee.decompressedPositions=new Float32Array(Ee.geometryPositions.length);for(var Ie=Ee.geometryPositions,De=Ee.decompressedPositions,Se=0,Te=Ie.length;Se0&&je.length>0;break;case 1:Ne="surface",Qe=h.subarray(y[me],ye?h.length:y[me+1]),Ve=d.subarray(b[me],ye?d.length:b[me+1]),je=f.subarray(w[me],ye?f.length:w[me+1]),Ge=v.subarray(x[me],ye?v.length:x[me+1]),ze=Qe.length>0&&je.length>0;break;case 2:Ne="points",Qe=h.subarray(y[me],ye?h.length:y[me+1]),He=HE(p.subarray(B[me],ye?p.length:B[me+1])),ze=Qe.length>0;break;case 3:Ne="lines",Qe=h.subarray(y[me],ye?h.length:y[me+1]),je=f.subarray(w[me],ye?f.length:w[me+1]),ze=Qe.length>0&&je.length>0;break;default:continue}ze&&(s.createMesh(le.apply(fe,{id:Pe,origin:K,primitive:Ne,positionsCompressed:Qe,normalsCompressed:Ve,colorsCompressed:He,indices:je,edgeIndices:Ge,positionsDecodeMatrix:se,color:be,metallic:we,roughness:xe,opacity:Be})),he.push(Pe))}}he.length>0&&s.createEntity(le.apply(pe,{id:ae,isObject:!0,meshIds:he}))}}}(e,t,a,s,r,n)}},GE=window.pako||dE;GE.inflate||(GE=GE.default);var zE=$.vec4(),WE=$.vec4();var KE=function(){var e=new Float32Array(3);return function(t){return e[0]=t[0]/255,e[1]=t[1]/255,e[2]=t[2]/255,e}}();var XE={version:9,parse:function(e,t,i,s,r,n){var o=function(e){return{metadata:e[0],positions:e[1],normals:e[2],colors:e[3],indices:e[4],edgeIndices:e[5],matrices:e[6],reusedGeometriesDecodeMatrix:e[7],eachGeometryPrimitiveType:e[8],eachGeometryPositionsPortion:e[9],eachGeometryNormalsPortion:e[10],eachGeometryColorsPortion:e[11],eachGeometryIndicesPortion:e[12],eachGeometryEdgeIndicesPortion:e[13],eachMeshGeometriesPortion:e[14],eachMeshMatricesPortion:e[15],eachMeshMaterial:e[16],eachEntityId:e[17],eachEntityMeshesPortion:e[18],eachTileAABB:e[19],eachTileEntitiesPortion:e[20]}}(i),a=function(e){function t(e,t){return 0===e.length?[]:GE.inflate(e,t).buffer}return{metadata:JSON.parse(GE.inflate(e.metadata,{to:"string"})),positions:new Uint16Array(t(e.positions)),normals:new Int8Array(t(e.normals)),colors:new Uint8Array(t(e.colors)),indices:new Uint32Array(t(e.indices)),edgeIndices:new Uint32Array(t(e.edgeIndices)),matrices:new Float32Array(t(e.matrices)),reusedGeometriesDecodeMatrix:new Float32Array(t(e.reusedGeometriesDecodeMatrix)),eachGeometryPrimitiveType:new Uint8Array(t(e.eachGeometryPrimitiveType)),eachGeometryPositionsPortion:new Uint32Array(t(e.eachGeometryPositionsPortion)),eachGeometryNormalsPortion:new Uint32Array(t(e.eachGeometryNormalsPortion)),eachGeometryColorsPortion:new Uint32Array(t(e.eachGeometryColorsPortion)),eachGeometryIndicesPortion:new Uint32Array(t(e.eachGeometryIndicesPortion)),eachGeometryEdgeIndicesPortion:new Uint32Array(t(e.eachGeometryEdgeIndicesPortion)),eachMeshGeometriesPortion:new Uint32Array(t(e.eachMeshGeometriesPortion)),eachMeshMatricesPortion:new Uint32Array(t(e.eachMeshMatricesPortion)),eachMeshMaterial:new Uint8Array(t(e.eachMeshMaterial)),eachEntityId:JSON.parse(GE.inflate(e.eachEntityId,{to:"string"})),eachEntityMeshesPortion:new Uint32Array(t(e.eachEntityMeshesPortion)),eachTileAABB:new Float64Array(t(e.eachTileAABB)),eachTileEntitiesPortion:new Uint32Array(t(e.eachTileEntitiesPortion))}}(o);!function(e,t,i,s,r,n){var o=n.getNextId(),a=i.metadata,l=i.positions,u=i.normals,A=i.colors,c=i.indices,h=i.edgeIndices,d=i.matrices,p=i.reusedGeometriesDecodeMatrix,f=i.eachGeometryPrimitiveType,v=i.eachGeometryPositionsPortion,g=i.eachGeometryNormalsPortion,m=i.eachGeometryColorsPortion,_=i.eachGeometryIndicesPortion,y=i.eachGeometryEdgeIndicesPortion,b=i.eachMeshGeometriesPortion,B=i.eachMeshMatricesPortion,w=i.eachMeshMaterial,x=i.eachEntityId,P=i.eachEntityMeshesPortion,C=i.eachTileAABB,M=i.eachTileEntitiesPortion,F=v.length,E=b.length,k=P.length,I=M.length;r&&r.loadData(a,{includeTypes:t.includeTypes,excludeTypes:t.excludeTypes,globalizeObjectIds:t.globalizeObjectIds});for(var D=new Uint32Array(F),S=0;S1,ae=ne===F-1,ue=KE(w.subarray(6*re,6*re+3)),Ae=w[6*re+3]/255,ce=w[6*re+4]/255,he=w[6*re+5]/255,de=n.getNextId();if(oe){var pe=B[re],fe=d.slice(pe,pe+16),ve="".concat(o,"-geometry.").concat(O,".").concat(ne),ge=U[ve];if(!ge){ge={batchThisMesh:!t.reuseGeometries};var me=!1;switch(f[ne]){case 0:ge.primitiveName="solid",ge.geometryPositions=l.subarray(v[ne],ae?l.length:v[ne+1]),ge.geometryNormals=u.subarray(g[ne],ae?u.length:g[ne+1]),ge.geometryIndices=c.subarray(_[ne],ae?c.length:_[ne+1]),ge.geometryEdgeIndices=h.subarray(y[ne],ae?h.length:y[ne+1]),me=ge.geometryPositions.length>0&&ge.geometryIndices.length>0;break;case 1:ge.primitiveName="surface",ge.geometryPositions=l.subarray(v[ne],ae?l.length:v[ne+1]),ge.geometryNormals=u.subarray(g[ne],ae?u.length:g[ne+1]),ge.geometryIndices=c.subarray(_[ne],ae?c.length:_[ne+1]),ge.geometryEdgeIndices=h.subarray(y[ne],ae?h.length:y[ne+1]),me=ge.geometryPositions.length>0&&ge.geometryIndices.length>0;break;case 2:ge.primitiveName="points",ge.geometryPositions=l.subarray(v[ne],ae?l.length:v[ne+1]),ge.geometryColors=A.subarray(m[ne],ae?A.length:m[ne+1]),me=ge.geometryPositions.length>0;break;case 3:ge.primitiveName="lines",ge.geometryPositions=l.subarray(v[ne],ae?l.length:v[ne+1]),ge.geometryIndices=c.subarray(_[ne],ae?c.length:_[ne+1]),me=ge.geometryPositions.length>0&&ge.geometryIndices.length>0;break;default:continue}if(me||(ge=null),ge&&(ge.geometryPositions.length,ge.batchThisMesh)){ge.decompressedPositions=new Float32Array(ge.geometryPositions.length),ge.transformedAndRecompressedPositions=new Uint16Array(ge.geometryPositions.length);for(var _e=ge.geometryPositions,ye=ge.decompressedPositions,be=0,Be=_e.length;be0&&Ie.length>0;break;case 1:Me="surface",Fe=l.subarray(v[ne],ae?l.length:v[ne+1]),Ee=u.subarray(g[ne],ae?u.length:g[ne+1]),Ie=c.subarray(_[ne],ae?c.length:_[ne+1]),De=h.subarray(y[ne],ae?h.length:y[ne+1]),Se=Fe.length>0&&Ie.length>0;break;case 2:Me="points",Fe=l.subarray(v[ne],ae?l.length:v[ne+1]),ke=A.subarray(m[ne],ae?A.length:m[ne+1]),Se=Fe.length>0;break;case 3:Me="lines",Fe=l.subarray(v[ne],ae?l.length:v[ne+1]),Ie=c.subarray(_[ne],ae?c.length:_[ne+1]),Se=Fe.length>0&&Ie.length>0;break;default:continue}Se&&(s.createMesh(le.apply(ie,{id:de,origin:R,primitive:Me,positionsCompressed:Fe,normalsCompressed:Ee,colorsCompressed:ke,indices:Ie,edgeIndices:De,positionsDecodeMatrix:G,color:ue,metallic:ce,roughness:he,opacity:Ae})),q.push(de))}}q.length>0&&s.createEntity(le.apply(te,{id:X,isObject:!0,meshIds:q}))}}}(e,t,a,s,r,n)}},JE=window.pako||dE;JE.inflate||(JE=JE.default);var YE=$.vec4(),ZE=$.vec4();var qE=function(){var e=new Float32Array(3);return function(t){return e[0]=t[0]/255,e[1]=t[1]/255,e[2]=t[2]/255,e}}();function $E(e,t){var i=[];if(t.length>1)for(var s=0,r=t.length-1;s1)for(var n=0,o=e.length/3-1;n0,W=9*V,K=1===A[W+0],X=A[W+1];A[W+2],A[W+3];var J=A[W+4],Y=A[W+5],Z=A[W+6],q=A[W+7],ee=A[W+8];if(z){var te=new Uint8Array(l.subarray(j,G)).buffer,ie="".concat(o,"-texture-").concat(V);if(K)s.createTexture({id:ie,buffers:[te],minFilter:J,magFilter:Y,wrapS:Z,wrapT:q,wrapR:ee});else{var se=new Blob([te],{type:10001===X?"image/jpeg":10002===X?"image/png":"image/gif"}),re=(window.URL||window.webkitURL).createObjectURL(se),ne=document.createElement("img");ne.src=re,s.createTexture({id:ie,image:ne,minFilter:J,magFilter:Y,wrapS:Z,wrapT:q,wrapR:ee})}}}for(var oe=0;oe=0?"".concat(o,"-texture-").concat(Ae):null,normalsTextureId:he>=0?"".concat(o,"-texture-").concat(he):null,metallicRoughnessTextureId:ce>=0?"".concat(o,"-texture-").concat(ce):null,emissiveTextureId:de>=0?"".concat(o,"-texture-").concat(de):null,occlusionTextureId:pe>=0?"".concat(o,"-texture-").concat(pe):null})}for(var fe=new Uint32Array(U),ve=0;ve1,je=Ve===U-1,Ge=E[Qe],ze=Ge>=0?"".concat(o,"-textureSet-").concat(Ge):null,We=qE(k.subarray(6*Qe,6*Qe+3)),Ke=k[6*Qe+3]/255,Xe=k[6*Qe+4]/255,Je=k[6*Qe+5]/255,Ye=n.getNextId();if(He){var Ze=F[Qe],qe=m.slice(Ze,Ze+16),$e="".concat(o,"-geometry.").concat(be,".").concat(Ve),et=ye[$e];if(!et){et={batchThisMesh:!t.reuseGeometries};var tt=!1;switch(y[Ve]){case 0:et.primitiveName="solid",et.geometryPositions=c.subarray(b[Ve],je?c.length:b[Ve+1]),et.geometryNormals=h.subarray(B[Ve],je?h.length:B[Ve+1]),et.geometryUVs=p.subarray(x[Ve],je?p.length:x[Ve+1]),et.geometryIndices=f.subarray(P[Ve],je?f.length:P[Ve+1]),et.geometryEdgeIndices=v.subarray(C[Ve],je?v.length:C[Ve+1]),tt=et.geometryPositions.length>0&&et.geometryIndices.length>0;break;case 1:et.primitiveName="surface",et.geometryPositions=c.subarray(b[Ve],je?c.length:b[Ve+1]),et.geometryNormals=h.subarray(B[Ve],je?h.length:B[Ve+1]),et.geometryUVs=p.subarray(x[Ve],je?p.length:x[Ve+1]),et.geometryIndices=f.subarray(P[Ve],je?f.length:P[Ve+1]),et.geometryEdgeIndices=v.subarray(C[Ve],je?v.length:C[Ve+1]),tt=et.geometryPositions.length>0&&et.geometryIndices.length>0;break;case 2:et.primitiveName="points",et.geometryPositions=c.subarray(b[Ve],je?c.length:b[Ve+1]),et.geometryColors=d.subarray(w[Ve],je?d.length:w[Ve+1]),tt=et.geometryPositions.length>0;break;case 3:et.primitiveName="lines",et.geometryPositions=c.subarray(b[Ve],je?c.length:b[Ve+1]),et.geometryIndices=f.subarray(P[Ve],je?f.length:P[Ve+1]),tt=et.geometryPositions.length>0&&et.geometryIndices.length>0;break;case 4:et.primitiveName="lines",et.geometryPositions=c.subarray(b[Ve],je?c.length:b[Ve+1]),et.geometryIndices=$E(et.geometryPositions,f.subarray(P[Ve],je?f.length:P[Ve+1])),tt=et.geometryPositions.length>0&&et.geometryIndices.length>0;break;default:continue}if(tt||(et=null),et&&(et.geometryPositions.length,et.batchThisMesh)){et.decompressedPositions=new Float32Array(et.geometryPositions.length),et.transformedAndRecompressedPositions=new Uint16Array(et.geometryPositions.length);for(var it=et.geometryPositions,st=et.decompressedPositions,rt=0,nt=it.length;rt0&&ft.length>0;break;case 1:At="surface",ct=c.subarray(b[Ve],je?c.length:b[Ve+1]),ht=h.subarray(B[Ve],je?h.length:B[Ve+1]),dt=p.subarray(x[Ve],je?p.length:x[Ve+1]),ft=f.subarray(P[Ve],je?f.length:P[Ve+1]),vt=v.subarray(C[Ve],je?v.length:C[Ve+1]),gt=ct.length>0&&ft.length>0;break;case 2:At="points",ct=c.subarray(b[Ve],je?c.length:b[Ve+1]),pt=d.subarray(w[Ve],je?d.length:w[Ve+1]),gt=ct.length>0;break;case 3:At="lines",ct=c.subarray(b[Ve],je?c.length:b[Ve+1]),ft=f.subarray(P[Ve],je?f.length:P[Ve+1]),gt=ct.length>0&&ft.length>0;break;case 4:At="lines",ft=$E(ct=c.subarray(b[Ve],je?c.length:b[Ve+1]),f.subarray(P[Ve],je?f.length:P[Ve+1])),gt=ct.length>0&&ft.length>0;break;default:continue}gt&&(s.createMesh(le.apply(Oe,{id:Ye,textureSetId:ze,origin:me,primitive:At,positionsCompressed:ct,normalsCompressed:ht,uv:dt&&dt.length>0?dt:null,colorsCompressed:pt,indices:ft,edgeIndices:vt,positionsDecodeMatrix:Me,color:We,metallic:Xe,roughness:Je,opacity:Ke})),Re.push(Ye))}}Re.length>0&&s.createEntity(le.apply(Ue,{id:Ie,isObject:!0,meshIds:Re}))}}}(e,t,a,s,r,n)}},tk={};tk[gE.version]=gE,tk[yE.version]=yE,tk[wE.version]=wE,tk[CE.version]=CE,tk[EE.version]=EE,tk[SE.version]=SE,tk[UE.version]=UE,tk[jE.version]=jE,tk[XE.version]=XE,tk[ek.version]=ek;var ik=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"XKTLoader",e,r))._maxGeometryBatchSize=r.maxGeometryBatchSize,s.textureTranscoder=r.textureTranscoder,s.dataSource=r.dataSource,s.objectDefaults=r.objectDefaults,s.includeTypes=r.includeTypes,s.excludeTypes=r.excludeTypes,s.excludeUnclassifiedObjects=r.excludeUnclassifiedObjects,s.reuseGeometries=r.reuseGeometries,s}return C(i,[{key:"supportedVersions",get:function(){return Object.keys(tk)}},{key:"textureTranscoder",get:function(){return this._textureTranscoder},set:function(e){this._textureTranscoder=e}},{key:"dataSource",get:function(){return this._dataSource},set:function(e){this._dataSource=e||new hE}},{key:"objectDefaults",get:function(){return this._objectDefaults},set:function(e){this._objectDefaults=e||uF}},{key:"includeTypes",get:function(){return this._includeTypes},set:function(e){this._includeTypes=e}},{key:"excludeTypes",get:function(){return this._excludeTypes},set:function(e){this._excludeTypes=e}},{key:"excludeUnclassifiedObjects",get:function(){return this._excludeUnclassifiedObjects},set:function(e){this._excludeUnclassifiedObjects=!!e}},{key:"globalizeObjectIds",get:function(){return this._globalizeObjectIds},set:function(e){this._globalizeObjectIds=!!e}},{key:"reuseGeometries",get:function(){return this._reuseGeometries},set:function(e){this._reuseGeometries=!1!==e}},{key:"load",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t.id&&this.viewer.scene.components[t.id]&&(this.error("Component with this ID already exists in viewer: "+t.id+" - will autogenerate this ID"),delete t.id),!(t.src||t.xkt||t.manifestSrc||t.manifest))return this.error("load() param expected: src, xkt, manifestSrc or manifestData"),A;var i={},s=t.includeTypes||this._includeTypes,r=t.excludeTypes||this._excludeTypes,n=t.objectDefaults||this._objectDefaults;if(i.reuseGeometries=null!==t.reuseGeometries&&void 0!==t.reuseGeometries?t.reuseGeometries:!1!==this._reuseGeometries,s){i.includeTypesMap={};for(var o=0,a=s.length;o=t.length?n():e._dataSource.getMetaModel("".concat(m).concat(t[a]),(function(t){h.loadData(t,{includeTypes:s,excludeTypes:r,globalizeObjectIds:i.globalizeObjectIds}),a++,e.scheduleTask(l,100)}),o)}()},y=function(s,r,n){var o=0;!function a(){o>=s.length?r():e._dataSource.getXKT("".concat(m).concat(s[o]),(function(s){e._parseModel(s,t,i,A,null,v),o++,e.scheduleTask(a,100)}),n)}()},b=function(s,r,n){var o=0;!function a(){o>=s.length?r():e._dataSource.getXKT("".concat(m).concat(s[o]),(function(s){e._parseModel(s,t,i,A,h,v),o++,e.scheduleTask(a,100)}),n)}()};if(t.manifest){var B=t.manifest,w=B.xktFiles;if(!w||0===w.length)return void p("load(): Failed to load model manifest - manifest not valid");var x=B.metaModelFiles;x?_(x,(function(){y(w,d,p)}),p):b(w,d,p)}else this._dataSource.getManifest(t.manifestSrc,(function(e){if(!A.destroyed){var t=e.xktFiles;if(t&&0!==t.length){var i=e.metaModelFiles;i?_(i,(function(){y(t,d,p)}),p):b(t,d,p)}else p("load(): Failed to load model manifest - manifest not valid")}}),p)}return A}},{key:"_loadModel",value:function(e,t,i,s,r,n,o,a){var l=this;this._dataSource.getXKT(t.src,(function(e){l._parseModel(e,t,i,s,r,n),o()}),a)}},{key:"_parseModel",value:function(e,t,i,s,r,n){if(!s.destroyed){var o=new DataView(e),a=new Uint8Array(e),l=o.getUint32(0,!0),u=tk[l];if(u){this.log("Loading .xkt V"+l);for(var A=o.getUint32(4,!0),c=[],h=4*(A+2),d=0;de.size)throw new RangeError("offset:"+t+", length:"+i+", size:"+e.size);return e.slice?e.slice(t,t+i):e.webkitSlice?e.webkitSlice(t,t+i):e.mozSlice?e.mozSlice(t,t+i):e.msSlice?e.msSlice(t,t+i):void 0}(e,t,i))}catch(e){r(e)}}}function p(){}function f(e){var i,s=this;s.init=function(e){i=new Blob([],{type:o}),e()},s.writeUint8Array=function(e,s){i=new Blob([i,t?e:e.buffer],{type:o}),s()},s.getData=function(t,s){var r=new FileReader;r.onload=function(e){t(e.target.result)},r.onerror=s,r.readAsText(i,e)}}function v(t){var i=this,s="",r="";i.init=function(e){s+="data:"+(t||"")+";base64,",e()},i.writeUint8Array=function(t,i){var n,o=r.length,a=r;for(r="",n=0;n<3*Math.floor((o+t.length)/3)-o;n++)a+=String.fromCharCode(t[n]);for(;n2?s+=e.btoa(a):r=a,i()},i.getData=function(t){t(s+e.btoa(r))}}function g(e){var i,s=this;s.init=function(t){i=new Blob([],{type:e}),t()},s.writeUint8Array=function(s,r){i=new Blob([i,t?s:s.buffer],{type:e}),r()},s.getData=function(e){e(i)}}function m(e,t,i,s,r,o,a,l,u,A){var c,h,d,p=0,f=t.sn;function v(){e.removeEventListener("message",g,!1),l(h,d)}function g(t){var i=t.data,r=i.data,n=i.error;if(n)return n.toString=function(){return"Error: "+this.message},void u(n);if(i.sn===f)switch("number"==typeof i.codecTime&&(e.codecTime+=i.codecTime),"number"==typeof i.crcTime&&(e.crcTime+=i.crcTime),i.type){case"append":r?(h+=r.length,s.writeUint8Array(r,(function(){m()}),A)):m();break;case"flush":d=i.crc,r?(h+=r.length,s.writeUint8Array(r,(function(){v()}),A)):v();break;case"progress":a&&a(c+i.loaded,o);break;case"importScripts":case"newTask":case"echo":break;default:console.warn("zip.js:launchWorkerProcess: unknown message: ",i)}}function m(){(c=p*n)<=o?i.readUint8Array(r+c,Math.min(n,o-c),(function(i){a&&a(c,o);var s=0===c?t:{sn:f};s.type="append",s.data=i;try{e.postMessage(s,[i.buffer])}catch(t){e.postMessage(s)}p++}),u):e.postMessage({sn:f,type:"flush"})}h=0,e.addEventListener("message",g,!1),m()}function _(e,t,i,s,r,o,l,u,A,c){var h,d=0,p=0,f="input"===o,v="output"===o,g=new a;!function o(){var a;if((h=d*n)127?r[i-128]:String.fromCharCode(i);return s}function B(e){return decodeURIComponent(escape(e))}function w(e){var t,i="";for(t=0;t>16,i=65535&e;try{return new Date(1980+((65024&t)>>9),((480&t)>>5)-1,31&t,(63488&i)>>11,(2016&i)>>5,2*(31&i),0)}catch(e){}}(e.lastModDateRaw),1!=(1&e.bitFlag)?((s||8!=(8&e.bitFlag))&&(e.crc32=t.view.getUint32(i+10,!0),e.compressedSize=t.view.getUint32(i+14,!0),e.uncompressedSize=t.view.getUint32(i+18,!0)),4294967295!==e.compressedSize&&4294967295!==e.uncompressedSize?(e.filenameLength=t.view.getUint16(i+22,!0),e.extraFieldLength=t.view.getUint16(i+24,!0)):r("File is using Zip64 (4gb+ file size).")):r("File contains encrypted entry.")}function P(t,n,o){var a=0;function l(){}l.prototype.getData=function(s,n,l,A){var c=this;function h(e,t){A&&!function(e){var t=u(4);return t.view.setUint32(0,e),c.crc32==t.view.getUint32(0)}(t)?o("CRC failed."):s.getData((function(e){n(e)}))}function d(e){o(e||r)}function p(e){o(e||"Error while writing file data.")}t.readUint8Array(c.offset,30,(function(r){var n,f=u(r.length,r);1347093252==f.view.getUint32(0)?(x(c,f,4,!1,o),n=c.offset+30+c.filenameLength+c.extraFieldLength,s.init((function(){0===c.compressionMethod?y(c._worker,a++,t,s,n,c.compressedSize,A,h,l,d,p):function(t,i,s,r,n,o,a,l,u,A,c){var h=a?"output":"none";e.zip.useWebWorkers?m(t,{sn:i,codecClass:"Inflater",crcType:h},s,r,n,o,u,l,A,c):_(new e.zip.Inflater,s,r,n,o,h,u,l,A,c)}(c._worker,a++,t,s,n,c.compressedSize,A,h,l,d,p)}),p)):o(i)}),d)};var A={getEntries:function(e){var r=this._worker;!function(e){t.size<22?o(i):r(22,(function(){r(Math.min(65558,t.size),(function(){o(i)}))}));function r(i,r){t.readUint8Array(t.size-i,i,(function(t){for(var i=t.length-22;i>=0;i--)if(80===t[i]&&75===t[i+1]&&5===t[i+2]&&6===t[i+3])return void e(new DataView(t.buffer,i,22));r()}),(function(){o(s)}))}}((function(n){var a,A;a=n.getUint32(16,!0),A=n.getUint16(8,!0),a<0||a>=t.size?o(i):t.readUint8Array(a,t.size-a,(function(t){var s,n,a,c,h=0,d=[],p=u(t.length,t);for(s=0;s>>8^i[255&(t^e[s])];this.crc=t},a.prototype.get=function(){return~this.crc},a.prototype.table=function(){var e,t,i,s=[];for(e=0;e<256;e++){for(i=e,t=0;t<8;t++)1&i?i=i>>>1^3988292384:i>>>=1;s[e]=i}return s}(),l.prototype.append=function(e,t){return e},l.prototype.flush=function(){},c.prototype=new A,c.prototype.constructor=c,h.prototype=new A,h.prototype.constructor=h,d.prototype=new A,d.prototype.constructor=d,p.prototype.getData=function(e){e(this.data)},f.prototype=new p,f.prototype.constructor=f,v.prototype=new p,v.prototype.constructor=v,g.prototype=new p,g.prototype.constructor=g;var E={deflater:["z-worker.js","deflate.js"],inflater:["z-worker.js","inflate.js"]};function k(t,i,s){if(null===e.zip.workerScripts||null===e.zip.workerScriptsPath){var r;if(e.zip.workerScripts){if(r=e.zip.workerScripts[t],!Array.isArray(r))return void s(new Error("zip.workerScripts."+t+" is not an array!"));r=function(e){var t=document.createElement("a");return e.map((function(e){return t.href=e,t.href}))}(r)}else(r=E[t].slice(0))[0]=(e.zip.workerScriptsPath||"")+r[0];var n=new Worker(r[0]);n.codecTime=n.crcTime=0,n.postMessage({type:"importScripts",scripts:r.slice(1)}),n.addEventListener("message",(function e(t){var r=t.data;if(r.error)return n.terminate(),void s(r.error);"importScripts"===r.type&&(n.removeEventListener("message",e),n.removeEventListener("error",o),i(n))})),n.addEventListener("error",o)}else s(new Error("Either zip.workerScripts or zip.workerScriptsPath may be set, not both."));function o(e){n.terminate(),s(e)}}function I(e){console.error(e)}e.zip={Reader:A,Writer:p,BlobReader:d,Data64URIReader:h,TextReader:c,BlobWriter:g,Data64URIWriter:v,TextWriter:f,createReader:function(e,t,i){i=i||I,e.init((function(){P(e,t,i)}),i)},createWriter:function(e,t,i,s){i=i||I,s=!!s,e.init((function(){F(e,t,i,s)}),i)},useWebWorkers:!0,workerScriptsPath:null,workerScripts:null}}(rk);var nk=rk.zip;!function(e){var t,i,s=e.Reader,r=e.Writer;try{i=0===new Blob([new DataView(new ArrayBuffer(0))]).size}catch(e){}function n(e){var t=this;function i(i,s){var r;t.data?i():((r=new XMLHttpRequest).addEventListener("load",(function(){t.size||(t.size=Number(r.getResponseHeader("Content-Length"))||Number(r.response.byteLength)),t.data=new Uint8Array(r.response),i()}),!1),r.addEventListener("error",s,!1),r.open("GET",e),r.responseType="arraybuffer",r.send())}t.size=0,t.init=function(s,r){if(function(e){var t=document.createElement("a");return t.href=e,"http:"===t.protocol||"https:"===t.protocol}(e)){var n=new XMLHttpRequest;n.addEventListener("load",(function(){t.size=Number(n.getResponseHeader("Content-Length")),t.size?s():i(s,r)}),!1),n.addEventListener("error",r,!1),n.open("HEAD",e),n.send()}else i(s,r)},t.readUint8Array=function(e,s,r,n){i((function(){r(new Uint8Array(t.data.subarray(e,e+s)))}),n)}}function o(e){var t=this;t.size=0,t.init=function(i,s){var r=new XMLHttpRequest;r.addEventListener("load",(function(){t.size=Number(r.getResponseHeader("Content-Length")),"bytes"==r.getResponseHeader("Accept-Ranges")?i():s("HTTP Range not supported.")}),!1),r.addEventListener("error",s,!1),r.open("HEAD",e),r.send()},t.readUint8Array=function(t,i,s,r){!function(t,i,s,r){var n=new XMLHttpRequest;n.open("GET",e),n.responseType="arraybuffer",n.setRequestHeader("Range","bytes="+t+"-"+(t+i-1)),n.addEventListener("load",(function(){s(n.response)}),!1),n.addEventListener("error",r,!1),n.send()}(t,i,(function(e){s(new Uint8Array(e))}),r)}}function a(e){var t=this;t.size=0,t.init=function(i,s){t.size=e.byteLength,i()},t.readUint8Array=function(t,i,s,r){s(new Uint8Array(e.slice(t,t+i)))}}function l(){var e,t=this;t.init=function(t,i){e=new Uint8Array,t()},t.writeUint8Array=function(t,i,s){var r=new Uint8Array(e.length+t.length);r.set(e),r.set(t,e.length),e=r,i()},t.getData=function(t){t(e.buffer)}}function u(e,t){var s,r=this;r.init=function(t,i){e.createWriter((function(e){s=e,t()}),i)},r.writeUint8Array=function(e,r,n){var o=new Blob([i?e:e.buffer],{type:t});s.onwrite=function(){s.onwrite=null,r()},s.onerror=n,s.write(o)},r.getData=function(t){e.file(t)}}n.prototype=new s,n.prototype.constructor=n,o.prototype=new s,o.prototype.constructor=o,a.prototype=new s,a.prototype.constructor=a,l.prototype=new r,l.prototype.constructor=l,u.prototype=new r,u.prototype.constructor=u,e.FileWriter=u,e.HttpReader=n,e.HttpRangeReader=o,e.ArrayBufferReader=a,e.ArrayBufferWriter=l,e.fs&&((t=e.fs.ZipDirectoryEntry).prototype.addHttpContent=function(i,s,r){return function(i,s,r,n){if(i.directory)return n?new t(i.fs,s,r,i):new e.fs.ZipFileEntry(i.fs,s,r,i);throw"Parent entry is not a directory."}(this,i,{data:s,Reader:r?o:n})},t.prototype.importHttpContent=function(e,t,i,s){this.importZip(t?new o(e):new n(e),i,s)},e.fs.FS.prototype.importHttpContent=function(e,i,s,r){this.entries=[],this.root=new t(this),this.root.importHttpContent(e,i,s,r)})}(nk);var ok=["4.2"],ak=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this.supportedSchemas=ok,this._xrayOpacity=.7,this._src=null,this._options=i,this.viewpoint=null,i.workerScriptsPath?(nk.workerScriptsPath=i.workerScriptsPath,this.src=i.src,this.xrayOpacity=.7,this.displayEffect=i.displayEffect,this.createMetaModel=i.createMetaModel):t.error("Config expected: workerScriptsPath")}return C(e,[{key:"load",value:function(e,t,i,s,r,n){switch(s.materialType){case"MetallicMaterial":t._defaultMaterial=new Pn(t,{baseColor:[1,1,1],metallic:.6,roughness:.6});break;case"SpecularMaterial":t._defaultMaterial=new Fn(t,{diffuse:[1,1,1],specular:$.vec3([1,1,1]),glossiness:.5});break;default:t._defaultMaterial=new Oi(t,{reflectivity:.75,shiness:100,diffuse:[1,1,1]})}t._wireframeMaterial=new Bn(t,{color:[0,0,0],lineWidth:2});var o=t.scene.canvas.spinner;o.processes++,lk(e,t,i,s,(function(){o.processes--,r&&r(),t.fire("loaded",!0,!1)}),(function(e){o.processes--,t.error(e),n&&n(e),t.fire("error",e)}),(function(e){console.log("Error, Will Robinson: "+e)}))}}]),e}(),lk=function(e,t,i,s,r,n){!function(e,t,i){var s=new vk;s.load(e,(function(){t(s)}),(function(e){i("Error loading ZIP archive: "+e)}))}(i,(function(i){uk(e,i,s,t,r,n)}),n)},uk=function(){return function(t,i,s,r,n){var o={plugin:t,zip:i,edgeThreshold:30,materialType:s.materialType,scene:r.scene,modelNode:r,info:{references:{}},materials:{}};s.createMetaModel&&(o.metaModelData={modelId:r.id,metaObjects:[{name:r.id,type:"Default",id:r.id}]}),r.scene.loading++,function(t,i){t.zip.getFile("Manifest.xml",(function(s,r){for(var n=r.children,o=0,a=n.length;o0){for(var o=n.trim().split(" "),a=new Int16Array(o.length),l=0,u=0,A=o.length;u0){i.primitive="triangles";for(var n=[],o=0,a=r.length;o=t.length)i();else{var a=t[n].id,l=a.lastIndexOf(":");l>0&&(a=a.substring(l+1));var u=a.lastIndexOf("#");u>0&&(a=a.substring(0,u)),s[a]?r(n+1):function(e,t,i){e.zip.getFile(t,(function(t,s){!function(e,t,i){for(var s,r=t.children,n=0,o=r.length;n0)for(var s=0,r=t.length;s1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),s=t.call(this,"XML3DLoader",e,r),r.workerScriptsPath?(s._workerScriptsPath=r.workerScriptsPath,s._loader=new ak(b(s),r),s.supportedSchemas=s._loader.supportedSchemas,s):(s.error("Config expected: workerScriptsPath"),y(s))}return C(i,[{key:"load",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e.workerScriptsPath=this._workerScriptsPath,e.id&&this.viewer.scene.components[e.id]&&(this.error("Component with this ID already exists in viewer: "+e.id+" - will autogenerate this ID"),delete e.id);var t=new bn(this.viewer.scene,le.apply(e,{isModel:!0})),i=e.src;return i?(this._loader.load(this,t,i,e),t):(this.error("load() param expected: src"),t)}}]),i}(),_k=function(){function e(){x(this,e)}return C(e,[{key:"getIFC",value:function(e,t,i){var s=function(){};t=t||s,i=i||s;var r=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(r){var n=!!r[2],o=r[3];o=window.decodeURIComponent(o),n&&(o=window.atob(o));try{for(var a=new ArrayBuffer(o.length),l=new Uint8Array(a),u=0;u1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(s=t.call(this,"ifcLoader",e,r)).dataSource=r.dataSource,s.objectDefaults=r.objectDefaults,s.includeTypes=r.includeTypes,s.excludeTypes=r.excludeTypes,s.excludeUnclassifiedObjects=r.excludeUnclassifiedObjects,!r.WebIFC)throw"Parameter expected: WebIFC";if(!r.IfcAPI)throw"Parameter expected: IfcAPI";return s._webIFC=r.WebIFC,s._ifcAPI=r.IfcAPI,s}return C(i,[{key:"supportedVersions",get:function(){return["2x3","4"]}},{key:"dataSource",get:function(){return this._dataSource},set:function(e){this._dataSource=e||new _k}},{key:"objectDefaults",get:function(){return this._objectDefaults},set:function(e){this._objectDefaults=e||uF}},{key:"includeTypes",get:function(){return this._includeTypes},set:function(e){this._includeTypes=e}},{key:"excludeTypes",get:function(){return this._excludeTypes},set:function(e){this._excludeTypes=e}},{key:"excludeUnclassifiedObjects",get:function(){return this._excludeUnclassifiedObjects},set:function(e){this._excludeUnclassifiedObjects=!!e}},{key:"globalizeObjectIds",get:function(){return this._globalizeObjectIds},set:function(e){this._globalizeObjectIds=!!e}},{key:"load",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e.id&&this.viewer.scene.components[e.id]&&(this.error("Component with this ID already exists in viewer: "+e.id+" - will autogenerate this ID"),delete e.id);var t=new ch(this.viewer.scene,le.apply(e,{isModel:!0}));if(!e.src&&!e.ifc)return this.error("load() param expected: src or IFC"),t;var i={autoNormals:!0};if(!1!==e.loadMetadata){var s=e.includeTypes||this._includeTypes,r=e.excludeTypes||this._excludeTypes,n=e.objectDefaults||this._objectDefaults;if(s){i.includeTypesMap={};for(var o=0,a=s.length;o0){for(var l=n.Name.value,u=[],A=0,c=a.length;A1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"lasLoader",e,r)).dataSource=r.dataSource,s.skip=r.skip,s.fp64=r.fp64,s.colorDepth=r.colorDepth,s}return C(i,[{key:"dataSource",get:function(){return this._dataSource},set:function(e){this._dataSource=e||new bk}},{key:"skip",get:function(){return this._skip},set:function(e){this._skip=e||1}},{key:"fp64",get:function(){return this._fp64},set:function(e){this._fp64=!!e}},{key:"colorDepth",get:function(){return this._colorDepth},set:function(e){this._colorDepth=e||"auto"}},{key:"load",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t.id&&this.viewer.scene.components[t.id]&&(this.error("Component with this ID already exists in viewer: "+t.id+" - will autogenerate this ID"),delete t.id);var i=new ch(this.viewer.scene,le.apply(t,{isModel:!0}));if(!t.src&&!t.las)return this.error("load() param expected: src or las"),i;var s={las:{skip:this._skip,fp64:this._fp64,colorDepth:this._colorDepth}};if(t.src)this._loadModel(t.src,t,s,i);else{var r=this.viewer.scene.canvas.spinner;r.processes++,this._parseModel(t.las,t,s,i).then((function(){r.processes--}),(function(t){r.processes--,e.error(t),i.fire("error",t)}))}return i}},{key:"_loadModel",value:function(e,t,i,s){var r=this,n=this.viewer.scene.canvas.spinner;n.processes++,this._dataSource.getLAS(t.src,(function(e){r._parseModel(e,t,i,s).then((function(){n.processes--}),(function(e){n.processes--,r.error(e),s.fire("error",e)}))}),(function(e){n.processes--,r.error(e),s.fire("error",e)}))}},{key:"_parseModel",value:function(e,t,i,s){var r=this;function n(e){var i=e.value;if(t.rotateX&&i)for(var s=0,r=i.length;s=e.length)return e;for(var i=[],s=0;s80*i){s=n=e[0],r=o=e[1];for(var p=i;pn&&(n=a),l>o&&(o=l);u=0!==(u=Math.max(n-s,o-r))?1/u:0}return Tk(h,d,i,s,r,u),d}function Dk(e,t,i,s,r){var n,o;if(r===iI(e,t,i,s)>0)for(n=t;n=t;n-=s)o=$k(n,e[n],e[n+1],o);return o&&Kk(o,o.next)&&(eI(o),o=o.next),o}function Sk(e,t){if(!e)return e;t||(t=e);var i,s=e;do{if(i=!1,s.steiner||!Kk(s,s.next)&&0!==Wk(s.prev,s,s.next))s=s.next;else{if(eI(s),(s=t=s.prev)===s.next)break;i=!0}}while(i||s!==t);return t}function Tk(e,t,i,s,r,n,o){if(e){!o&&n&&function(e,t,i,s){var r=e;do{null===r.z&&(r.z=Hk(r.x,r.y,t,i,s)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==e);r.prevZ.nextZ=null,r.prevZ=null,function(e){var t,i,s,r,n,o,a,l,u=1;do{for(i=e,e=null,n=null,o=0;i;){for(o++,s=i,a=0,t=0;t0||l>0&&s;)0!==a&&(0===l||!s||i.z<=s.z)?(r=i,i=i.nextZ,a--):(r=s,s=s.nextZ,l--),n?n.nextZ=r:e=r,r.prevZ=n,n=r;i=s}n.nextZ=null,u*=2}while(o>1)}(r)}(e,s,r,n);for(var a,l,u=e;e.prev!==e.next;)if(a=e.prev,l=e.next,n?Lk(e,s,r,n):Rk(e))t.push(a.i/i),t.push(e.i/i),t.push(l.i/i),eI(e),e=l.next,u=l.next;else if((e=l)===u){o?1===o?Tk(e=Uk(Sk(e),t,i),t,i,s,r,n,2):2===o&&Ok(e,t,i,s,r,n):Tk(Sk(e),t,i,s,r,n,1);break}}}function Rk(e){var t=e.prev,i=e,s=e.next;if(Wk(t,i,s)>=0)return!1;for(var r=e.next.next;r!==e.prev;){if(Gk(t.x,t.y,i.x,i.y,s.x,s.y,r.x,r.y)&&Wk(r.prev,r,r.next)>=0)return!1;r=r.next}return!0}function Lk(e,t,i,s){var r=e.prev,n=e,o=e.next;if(Wk(r,n,o)>=0)return!1;for(var a=r.xn.x?r.x>o.x?r.x:o.x:n.x>o.x?n.x:o.x,A=r.y>n.y?r.y>o.y?r.y:o.y:n.y>o.y?n.y:o.y,c=Hk(a,l,t,i,s),h=Hk(u,A,t,i,s),d=e.prevZ,p=e.nextZ;d&&d.z>=c&&p&&p.z<=h;){if(d!==e.prev&&d!==e.next&&Gk(r.x,r.y,n.x,n.y,o.x,o.y,d.x,d.y)&&Wk(d.prev,d,d.next)>=0)return!1;if(d=d.prevZ,p!==e.prev&&p!==e.next&&Gk(r.x,r.y,n.x,n.y,o.x,o.y,p.x,p.y)&&Wk(p.prev,p,p.next)>=0)return!1;p=p.nextZ}for(;d&&d.z>=c;){if(d!==e.prev&&d!==e.next&&Gk(r.x,r.y,n.x,n.y,o.x,o.y,d.x,d.y)&&Wk(d.prev,d,d.next)>=0)return!1;d=d.prevZ}for(;p&&p.z<=h;){if(p!==e.prev&&p!==e.next&&Gk(r.x,r.y,n.x,n.y,o.x,o.y,p.x,p.y)&&Wk(p.prev,p,p.next)>=0)return!1;p=p.nextZ}return!0}function Uk(e,t,i){var s=e;do{var r=s.prev,n=s.next.next;!Kk(r,n)&&Xk(r,s,s.next,n)&&Zk(r,n)&&Zk(n,r)&&(t.push(r.i/i),t.push(s.i/i),t.push(n.i/i),eI(s),eI(s.next),s=e=n),s=s.next}while(s!==e);return Sk(s)}function Ok(e,t,i,s,r,n){var o=e;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&zk(o,a)){var l=qk(o,a);return o=Sk(o,o.next),l=Sk(l,l.next),Tk(o,t,i,s,r,n),void Tk(l,t,i,s,r,n)}a=a.next}o=o.next}while(o!==e)}function Nk(e,t){return e.x-t.x}function Qk(e,t){if(t=function(e,t){var i,s=t,r=e.x,n=e.y,o=-1/0;do{if(n<=s.y&&n>=s.next.y&&s.next.y!==s.y){var a=s.x+(n-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(a<=r&&a>o){if(o=a,a===r){if(n===s.y)return s;if(n===s.next.y)return s.next}i=s.x=s.x&&s.x>=A&&r!==s.x&&Gk(ni.x||s.x===i.x&&Vk(i,s)))&&(i=s,h=l)),s=s.next}while(s!==u);return i}(e,t),t){var i=qk(t,e);Sk(t,t.next),Sk(i,i.next)}}function Vk(e,t){return Wk(e.prev,e,t.prev)<0&&Wk(t.next,e,e.next)<0}function Hk(e,t,i,s,r){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-i)*r)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-s)*r)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function jk(e){var t=e,i=e;do{(t.x=0&&(e-o)*(s-a)-(i-o)*(t-a)>=0&&(i-o)*(n-a)-(r-o)*(s-a)>=0}function zk(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){var i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&Xk(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&(Zk(e,t)&&Zk(t,e)&&function(e,t){var i=e,s=!1,r=(e.x+t.x)/2,n=(e.y+t.y)/2;do{i.y>n!=i.next.y>n&&i.next.y!==i.y&&r<(i.next.x-i.x)*(n-i.y)/(i.next.y-i.y)+i.x&&(s=!s),i=i.next}while(i!==e);return s}(e,t)&&(Wk(e.prev,e,t.prev)||Wk(e,t.prev,t))||Kk(e,t)&&Wk(e.prev,e,e.next)>0&&Wk(t.prev,t,t.next)>0)}function Wk(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function Kk(e,t){return e.x===t.x&&e.y===t.y}function Xk(e,t,i,s){var r=Yk(Wk(e,t,i)),n=Yk(Wk(e,t,s)),o=Yk(Wk(i,s,e)),a=Yk(Wk(i,s,t));return r!==n&&o!==a||(!(0!==r||!Jk(e,i,t))||(!(0!==n||!Jk(e,s,t))||(!(0!==o||!Jk(i,e,s))||!(0!==a||!Jk(i,t,s)))))}function Jk(e,t,i){return t.x<=Math.max(e.x,i.x)&&t.x>=Math.min(e.x,i.x)&&t.y<=Math.max(e.y,i.y)&&t.y>=Math.min(e.y,i.y)}function Yk(e){return e>0?1:e<0?-1:0}function Zk(e,t){return Wk(e.prev,e,e.next)<0?Wk(e,t,e.next)>=0&&Wk(e,e.prev,t)>=0:Wk(e,t,e.prev)<0||Wk(e,e.next,t)<0}function qk(e,t){var i=new tI(e.i,e.x,e.y),s=new tI(t.i,t.x,t.y),r=e.next,n=t.prev;return e.next=t,t.prev=e,i.next=r,r.prev=i,s.next=i,i.prev=s,n.next=s,s.prev=n,s}function $k(e,t,i,s){var r=new tI(e,t,i);return s?(r.next=s.next,r.prev=s,s.next.prev=r,s.next=r):(r.prev=r,r.next=r),r}function eI(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function tI(e,t,i){this.i=e,this.x=t,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function iI(e,t,i,s){for(var r=0,n=t,o=i-s;n0&&(s+=e[r-1].length,i.holes.push(s))}return i};var sI=$.vec2(),rI=$.vec3(),nI=$.vec3(),oI=$.vec3(),aI=function(e){g(i,Se);var t=_(i);function i(e){var s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(s=t.call(this,"cityJSONLoader",e,r)).dataSource=r.dataSource,s}return C(i,[{key:"dataSource",get:function(){return this._dataSource},set:function(e){this._dataSource=e||new kk}},{key:"load",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e.id&&this.viewer.scene.components[e.id]&&(this.error("Component with this ID already exists in viewer: "+e.id+" - will autogenerate this ID"),delete e.id);var t=new ch(this.viewer.scene,le.apply(e,{isModel:!0,edges:!0}));if(!e.src&&!e.cityJSON)return this.error("load() param expected: src or cityJSON"),t;var i={};if(e.src)this._loadModel(e.src,e,i,t);else{var s=this.viewer.scene.canvas.spinner;s.processes++,this._parseModel(e.cityJSON,e,i,t),s.processes--}return t}},{key:"_loadModel",value:function(e,t,i,s){var r=this,n=this.viewer.scene.canvas.spinner;n.processes++,this._dataSource.getCityJSON(t.src,(function(e){r._parseModel(e,t,i,s),n.processes--}),(function(e){n.processes--,r.error(e),s.fire("error",e)}))}},{key:"_parseModel",value:function(e,t,i,s){if(!s.destroyed){var r=e.transform?this._transformVertices(e.vertices,e.transform,i.rotateX):e.vertices,n=t.stats||{};n.sourceFormat=e.type||"CityJSON",n.schemaVersion=e.version||"",n.title="",n.author="",n.created="",n.numMetaObjects=0,n.numPropertySets=0,n.numObjects=0,n.numGeometries=0,n.numTriangles=0,n.numVertices=0;var o=!1!==t.loadMetadata,a=o?{id:$.createUUID(),name:"Model",type:"Model"}:null,l=o?{id:"",projectId:"",author:"",createdAt:"",schema:e.version||"",creatingApplication:"",metaObjects:[a],propertySets:[]}:null,u={data:e,vertices:r,sceneModel:s,loadMetadata:o,metadata:l,rootMetaObject:a,nextId:0,stats:n};if(this._parseCityJSON(u),s.finalize(),o){var A=s.id;this.viewer.metaScene.createMetaModel(A,u.metadata,i)}s.scene.once("tick",(function(){s.destroyed||(s.scene.fire("modelLoaded",s.id),s.fire("loaded",!0,!1))}))}}},{key:"_transformVertices",value:function(e,t,i){for(var s=[],r=t.scale||$.vec3([1,1,1]),n=t.translate||$.vec3([0,0,0]),o=0,a=0;o0){for(var u=[],A=0,c=t.geometry.length;A0){var _=g[m[0]];if(void 0!==_.value)d=v[_.value];else{var y=_.values;if(y){p=[];for(var b=0,B=y.length;b0&&(s.createEntity({id:i,meshIds:u,isObject:!0}),e.stats.numObjects++)}}},{key:"_parseGeometrySurfacesWithOwnMaterials",value:function(e,t,i,s){switch(t.type){case"MultiPoint":case"MultiLineString":break;case"MultiSurface":case"CompositeSurface":var r=t.boundaries;this._parseSurfacesWithOwnMaterials(e,i,r,s);break;case"Solid":for(var n=t.boundaries,o=0;o0&&c.push(u.length);var f=this._extractLocalIndices(e,a[p],h,d);u.push.apply(u,A(f))}if(3===u.length)d.indices.push(u[0]),d.indices.push(u[1]),d.indices.push(u[2]);else if(u.length>3){for(var v=[],g=0;g0&&o.indices.length>0){var f=""+e.nextId++;r.createMesh({id:f,primitive:"triangles",positions:o.positions,indices:o.indices,color:i&&i.diffuseColor?i.diffuseColor:[.8,.8,.8],opacity:1}),s.push(f),e.stats.numGeometries++,e.stats.numVertices+=o.positions.length/3,e.stats.numTriangles+=o.indices.length/3}}},{key:"_parseSurfacesWithSharedMaterial",value:function(e,t,i,s){for(var r=e.vertices,n=0;n0&&a.push(o.length);var u=this._extractLocalIndices(e,t[n][l],i,s);o.push.apply(o,A(u))}if(3===o.length)s.indices.push(o[0]),s.indices.push(o[1]),s.indices.push(o[2]);else if(o.length>3){for(var c=[],h=0;h