From adfc3bf49c3207c8964a7a39552fb147ee2c8d59 Mon Sep 17 00:00:00 2001 From: lindsay Date: Tue, 13 Feb 2024 03:35:25 +0100 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 | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/dist/xeokit-sdk.cjs.js b/dist/xeokit-sdk.cjs.js index 10919f4add..d678cccb4f 100644 --- a/dist/xeokit-sdk.cjs.js +++ b/dist/xeokit-sdk.cjs.js @@ -82150,7 +82150,8 @@ class SceneModel extends Component { const useDTX = (!!this._dtxEnabled && (cfg.primitive === "triangles" || cfg.primitive === "solid" - || cfg.primitive === "surface")); + || cfg.primitive === "surface")) + && (!cfg.textureSetId); cfg.origin = cfg.origin ? math.addVec3(this._origin, cfg.origin, math.vec3()) : this._origin; @@ -82368,7 +82369,8 @@ class SceneModel extends Component { const useDTX = (!!this._dtxEnabled && (cfg.geometry.primitive === "triangles" || cfg.geometry.primitive === "solid" - || cfg.geometry.primitive === "surface")); + || cfg.geometry.primitive === "surface")) + && (!cfg.textureSetId); if (useDTX) { diff --git a/dist/xeokit-sdk.es.js b/dist/xeokit-sdk.es.js index e8a4b2fc2f..17a48535eb 100644 --- a/dist/xeokit-sdk.es.js +++ b/dist/xeokit-sdk.es.js @@ -82146,7 +82146,8 @@ class SceneModel extends Component { const useDTX = (!!this._dtxEnabled && (cfg.primitive === "triangles" || cfg.primitive === "solid" - || cfg.primitive === "surface")); + || cfg.primitive === "surface")) + && (!cfg.textureSetId); cfg.origin = cfg.origin ? math.addVec3(this._origin, cfg.origin, math.vec3()) : this._origin; @@ -82364,7 +82365,8 @@ class SceneModel extends Component { const useDTX = (!!this._dtxEnabled && (cfg.geometry.primitive === "triangles" || cfg.geometry.primitive === "solid" - || cfg.geometry.primitive === "surface")); + || cfg.geometry.primitive === "surface")) + && (!cfg.textureSetId); if (useDTX) { diff --git a/dist/xeokit-sdk.es5.js b/dist/xeokit-sdk.es5.js index a63cc67d86..4f3851bce1 100644 --- a/dist/xeokit-sdk.es5.js +++ b/dist/xeokit-sdk.es5.js @@ -18190,7 +18190,7 @@ if(!this._textureTranscoder){this.error("[createTexture] Can't create texture fr * @param {Number} [cfg.roughness=1] Roughness factor in range ````[0..1]````. Overridden by texture set ````metallicRoughnessTexture````. * @returns {Boolean} True = successfully mesh was created. False = error during creation of a mesh. */},{key:"createMesh",value:function createMesh(cfg){if(cfg.id===undefined||cfg.id===null){this.error("[createMesh] SceneModel.createMesh() config missing: id");return false;}if(this._scheduledMeshes[cfg.id]){this.error("[createMesh] SceneModel already has a mesh with this ID: ".concat(cfg.id));return false;}var instancing=cfg.geometryId!==undefined;var batching=!instancing;if(batching){// Batched geometry -if(cfg.primitive===undefined||cfg.primitive===null){cfg.primitive="triangles";}if(cfg.primitive!=="points"&&cfg.primitive!=="lines"&&cfg.primitive!=="triangles"&&cfg.primitive!=="solid"&&cfg.primitive!=="surface"){this.error("Unsupported value for 'primitive': '".concat(primitive,"' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'."));return false;}if(!cfg.positions&&!cfg.positionsCompressed&&!cfg.buckets){this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)");return false;}if(cfg.positions&&(cfg.positionsDecodeMatrix||cfg.positionsDecodeBoundary)){this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)");return false;}if(cfg.positionsCompressed&&!cfg.positionsDecodeMatrix&&!cfg.positionsDecodeBoundary){this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)");return false;}if(cfg.uvCompressed&&!cfg.uvDecodeMatrix){this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)");return false;}if(!cfg.buckets&&!cfg.indices&&cfg.primitive!=="points"){this.error("Param expected: indices (required for '".concat(cfg.primitive,"' primitive type)"));return false;}if((cfg.matrix||cfg.position||cfg.rotation||cfg.scale)&&(cfg.positionsCompressed||cfg.positionsDecodeBoundary)){this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'");return false;}var useDTX=!!this._dtxEnabled&&(cfg.primitive==="triangles"||cfg.primitive==="solid"||cfg.primitive==="surface");cfg.origin=cfg.origin?math.addVec3(this._origin,cfg.origin,math.vec3()):this._origin;// MATRIX - optional for batching +if(cfg.primitive===undefined||cfg.primitive===null){cfg.primitive="triangles";}if(cfg.primitive!=="points"&&cfg.primitive!=="lines"&&cfg.primitive!=="triangles"&&cfg.primitive!=="solid"&&cfg.primitive!=="surface"){this.error("Unsupported value for 'primitive': '".concat(primitive,"' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'."));return false;}if(!cfg.positions&&!cfg.positionsCompressed&&!cfg.buckets){this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)");return false;}if(cfg.positions&&(cfg.positionsDecodeMatrix||cfg.positionsDecodeBoundary)){this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)");return false;}if(cfg.positionsCompressed&&!cfg.positionsDecodeMatrix&&!cfg.positionsDecodeBoundary){this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)");return false;}if(cfg.uvCompressed&&!cfg.uvDecodeMatrix){this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)");return false;}if(!cfg.buckets&&!cfg.indices&&cfg.primitive!=="points"){this.error("Param expected: indices (required for '".concat(cfg.primitive,"' primitive type)"));return false;}if((cfg.matrix||cfg.position||cfg.rotation||cfg.scale)&&(cfg.positionsCompressed||cfg.positionsDecodeBoundary)){this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'");return false;}var useDTX=!!this._dtxEnabled&&(cfg.primitive==="triangles"||cfg.primitive==="solid"||cfg.primitive==="surface")&&!cfg.textureSetId;cfg.origin=cfg.origin?math.addVec3(this._origin,cfg.origin,math.vec3()):this._origin;// MATRIX - optional for batching if(cfg.matrix){cfg.meshMatrix=cfg.matrix;}else if(cfg.scale||cfg.rotation||cfg.position){var _scale3=cfg.scale||DEFAULT_SCALE;var _position=cfg.position||DEFAULT_POSITION;var rotation=cfg.rotation||DEFAULT_ROTATION;math.eulerToQuaternion(rotation,"XYZ",DEFAULT_QUATERNION);cfg.meshMatrix=math.composeMat4(_position,DEFAULT_QUATERNION,_scale3,math.mat4());}if(cfg.positionsDecodeBoundary){cfg.positionsDecodeMatrix=createPositionsDecodeMatrix(cfg.positionsDecodeBoundary,math.mat4());}if(useDTX){// DTX cfg.type=DTX;// NPR cfg.color=cfg.color?new Uint8Array([Math.floor(cfg.color[0]*255),Math.floor(cfg.color[1]*255),Math.floor(cfg.color[2]*255)]):defaultCompressedColor;cfg.opacity=cfg.opacity!==undefined&&cfg.opacity!==null?Math.floor(cfg.opacity*255):255;// RTC @@ -18208,7 +18208,7 @@ if(!cfg.buckets&&!cfg.edgeIndices&&(cfg.primitive==="triangles"||cfg.primitive== if(cfg.textureSetId){cfg.textureSet=this._textureSets[cfg.textureSetId];if(!cfg.textureSet){this.error("[createMesh] Texture set not found: ".concat(cfg.textureSetId," - ensure that you create it first with createTextureSet()"));return false;}}}}else{// INSTANCING if(cfg.positions||cfg.positionsCompressed||cfg.indices||cfg.edgeIndices||cfg.normals||cfg.normalsCompressed||cfg.uv||cfg.uvCompressed||cfg.positionsDecodeMatrix){this.error("Mesh geometry parameters not expected when instancing a geometry (not expected: positions, positionsCompressed, indices, edgeIndices, normals, normalsCompressed, uv, uvCompressed, positionsDecodeMatrix)");return false;}cfg.geometry=this._geometries[cfg.geometryId];if(!cfg.geometry){this.error("[createMesh] Geometry not found: ".concat(cfg.geometryId," - ensure that you create it first with createGeometry()"));return false;}cfg.origin=cfg.origin?math.addVec3(this._origin,cfg.origin,math.vec3()):this._origin;cfg.positionsDecodeMatrix=cfg.geometry.positionsDecodeMatrix;if(cfg.transformId){// TRANSFORM cfg.transform=this._transforms[cfg.transformId];if(!cfg.transform){this.error("[createMesh] Transform not found: ".concat(cfg.transformId," - ensure that you create it first with createTransform()"));return false;}cfg.aabb=cfg.geometry.aabb;}else{// MATRIX -if(cfg.matrix){cfg.meshMatrix=cfg.matrix.slice();}else{var _scale4=cfg.scale||DEFAULT_SCALE;var _position2=cfg.position||DEFAULT_POSITION;var _rotation=cfg.rotation||DEFAULT_ROTATION;math.eulerToQuaternion(_rotation,"XYZ",DEFAULT_QUATERNION);cfg.meshMatrix=math.composeMat4(_position2,DEFAULT_QUATERNION,_scale4,math.mat4());}math.AABB3ToOBB3(cfg.geometry.aabb,tempOBB3);math.transformOBB3(cfg.meshMatrix,tempOBB3);cfg.aabb=math.OBB3ToAABB3(tempOBB3,math.AABB3());}var _useDTX=!!this._dtxEnabled&&(cfg.geometry.primitive==="triangles"||cfg.geometry.primitive==="solid"||cfg.geometry.primitive==="surface");if(_useDTX){// DTX +if(cfg.matrix){cfg.meshMatrix=cfg.matrix.slice();}else{var _scale4=cfg.scale||DEFAULT_SCALE;var _position2=cfg.position||DEFAULT_POSITION;var _rotation=cfg.rotation||DEFAULT_ROTATION;math.eulerToQuaternion(_rotation,"XYZ",DEFAULT_QUATERNION);cfg.meshMatrix=math.composeMat4(_position2,DEFAULT_QUATERNION,_scale4,math.mat4());}math.AABB3ToOBB3(cfg.geometry.aabb,tempOBB3);math.transformOBB3(cfg.meshMatrix,tempOBB3);cfg.aabb=math.OBB3ToAABB3(tempOBB3,math.AABB3());}var _useDTX=!!this._dtxEnabled&&(cfg.geometry.primitive==="triangles"||cfg.geometry.primitive==="solid"||cfg.geometry.primitive==="surface")&&!cfg.textureSetId;if(_useDTX){// DTX cfg.type=DTX;// NPR cfg.color=cfg.color?new Uint8Array([Math.floor(cfg.color[0]*255),Math.floor(cfg.color[1]*255),Math.floor(cfg.color[2]*255)]):defaultCompressedColor;cfg.opacity=cfg.opacity!==undefined&&cfg.opacity!==null?Math.floor(cfg.opacity*255):255;// BUCKETING - lazy generated, reused var buckets=this._dtxBuckets[cfg.geometryId];if(!buckets){buckets=createDTXBuckets(cfg.geometry,this._enableVertexWelding,this._enableIndexBucketing);this._dtxBuckets[cfg.geometryId]=buckets;}cfg.buckets=buckets;}else{// VBO diff --git a/dist/xeokit-sdk.min.cjs.js b/dist/xeokit-sdk.min.cjs.js index 17c1aad9a8..20e633271c 100644 --- a/dist/xeokit-sdk.min.cjs.js +++ b/dist/xeokit-sdk.min.cjs.js @@ -14,7 +14,7 @@ /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT - **/let gc=null;function Ec(e,t){const s=3*e,n=3*t;let i,r,a,o,l,c;const u=Math.min(i=gc[s],r=gc[s+1],a=gc[s+2]),h=Math.min(o=gc[n],l=gc[n+1],c=gc[n+2]);if(u!==h)return u-h;const p=Math.max(i,r,a),d=Math.max(o,l,c);return p!==d?p-d:0}let Tc=null;function bc(e,t){let s=Tc[2*e]-Tc[2*t];return 0!==s?s:Tc[2*e+1]-Tc[2*t+1]}function Dc(e,t,s=!1){const n=e.positionsCompressed||[],i=function(e,t){const s=new Int32Array(e.length/3);for(let e=0,t=s.length;e>t;s.sort(Ec);const n=new Int32Array(e.length);for(let t=0,i=s.length;te[t+1]){let s=e[t];e[t]=e[t+1],e[t+1]=s}Tc=new Int32Array(e),t.sort(bc);const s=new Int32Array(e.length);for(let n=0,i=t.length;nt){let s=e;e=t,t=s}function s(s,n){return s!==e?e-s:n!==t?t-n:0}let n=0,i=(r.length>>1)-1;for(;n<=i;){const e=i+n>>1,t=s(r[2*e],r[2*e+1]);if(t>0)n=e+1;else{if(!(t<0))return e;i=e-1}}return-n-1}const o=new Int32Array(r.length/2);o.fill(0);const l=n.length/3;if(l>8*(1<p.maxNumPositions&&(p=h()),p.bucketNumber>8)return[e];let A;-1===c[l]&&(c[l]=p.numPositions++,p.positionsCompressed.push(n[3*l]),p.positionsCompressed.push(n[3*l+1]),p.positionsCompressed.push(n[3*l+2])),-1===c[u]&&(c[u]=p.numPositions++,p.positionsCompressed.push(n[3*u]),p.positionsCompressed.push(n[3*u+1]),p.positionsCompressed.push(n[3*u+2])),-1===c[d]&&(c[d]=p.numPositions++,p.positionsCompressed.push(n[3*d]),p.positionsCompressed.push(n[3*d+1]),p.positionsCompressed.push(n[3*d+2])),p.indices.push(c[l]),p.indices.push(c[u]),p.indices.push(c[d]),(A=a(l,u))>=0&&0===o[A]&&(o[A]=1,p.edgeIndices.push(c[r[2*A]]),p.edgeIndices.push(c[r[2*A+1]])),(A=a(l,d))>=0&&0===o[A]&&(o[A]=1,p.edgeIndices.push(c[r[2*A]]),p.edgeIndices.push(c[r[2*A+1]])),(A=a(u,d))>=0&&0===o[A]&&(o[A]=1,p.edgeIndices.push(c[r[2*A]]),p.edgeIndices.push(c[r[2*A+1]]))}const d=t/8*2,A=t/8,f=2*n.length+(i.length+r.length)*d;let I=0,m=-n.length/3;return u.forEach((e=>{I+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*A,m+=e.positionsCompressed.length/3})),I>f?[e]:(s&&function(e,t){const s={},n={};let i=0;e.forEach((e=>{const t=e.indices,r=e.edgeIndices,a=e.positionsCompressed;for(let e=0,n=t.length;e0){const e=t._meshes;for(let t=0,s=e.length;t0){const e=this._meshes;for(let t=0,s=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 rc({id:"defaultColorTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new rc({id:"defaultMetalRoughTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),s=new rc({id:"defaultNormalsTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),n=new rc({id:"defaultEmissiveTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new rc({id:"defaultOcclusionTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=s,this._textures.defaultEmissiveTexture=n,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new ic({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:s,emissiveTexture:n,occlusionTexture:i})}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]),h.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]),h.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||Gc),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),h.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),h.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&&(h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),h.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),h.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,s=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,s=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,s=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,s=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,s=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,s=new Uint8Array(t.length);for(let e=0,n=t.length;e{l.setImage(c,{minFilter:s,magFilter:n,wrapS:i,wrapT:r,wrapR:a,flipY:e.flipY,encoding:o}),this.glRedraw()},c.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 rc({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 s,n,i,r,a;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(s=this._textures[e.colorTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(n=this._textures[e.metallicRoughnessTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(i=this._textures[e.normalsTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(r=this._textures[e.emissiveTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(a=this._textures[e.occlusionTextureId],!a)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else a=this._textures.defaultOcclusionTexture;const o=new ic({id:t,model:this,colorTexture:s,metallicRoughnessTexture:n,normalsTexture:i,emissiveTexture:r,occlusionTexture:a});return this._textureSets[t]=o,o}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(this.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const s=new Nc({id:e.id,model:this,parentTransform:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[s.id]=s,s}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._scheduledMeshes[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&&"points"!==e.primitive)return 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);if(e.origin=e.origin?h.addVec3(this._origin,e.origin,h.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){const t=e.scale||Mc,s=e.position||Fc,n=e.rotation||Hc;h.eulerToQuaternion(n,"XYZ",Uc),e.meshMatrix=h.composeMat4(s,Uc,t,h.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Si(e.positionsDecodeBoundary,h.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])]):jc,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=h.vec3(),s=[];Q(e.positions,s,t)&&(e.positions=s,e.origin=h.addVec3(e.origin,t,t))}if(e.positions){const t=h.collapseAABB3();e.positionsDecodeMatrix=h.mat4(),h.expandAABB3Points3(t,e.positions),e.positionsCompressed=Oi(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=h.collapseAABB3();h.expandAABB3Points3(t,e.positionsCompressed),St.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=h.collapseAABB3();for(let s=0,n=e.buckets.length;s>24&255,i=s>>16&255,r=s>>8&255,a=255&s;switch(e.pickColor=new Uint8Array([a,r,i,n]),e.solid="solid"===e.primitive,t.origin=h.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),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 s=0,n=e.buckets.length;s>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,s=e.origin,n=e.textureSetId||"-",i=e.geometryId,r=`${Math.round(s[0])}.${Math.round(s[1])}.${Math.round(s[2])}.${n}.${i}`;let a=this._vboInstancingLayers[r];if(a)return a;let o=e.textureSet;const l=e.geometry;for(;!a;)switch(l.primitive){case"triangles":case"surface":a=new Mr({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0,solid:!1});break;case"solid":a=new Mr({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0,solid:!0});break;case"lines":a=new ga({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0});break;case"points":a=new fo({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0})}return this._vboInstancingLayers[r]=a,this.layerList.push(a),a}createEntity(e){if(void 0===e.id?e.id=h.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=h.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;this._visible&&!1!==e.visible&&(t|=z),this._pickable&&!1!==e.pickable&&(t|=Y),this._culled&&!1!==e.culled&&(t|=K),this._clippable&&!1!==e.clippable&&(t|=X),this._collidable&&!1!==e.collidable&&(t|=q),this._edges&&!1!==e.edges&&(t|=ee),this._xrayed&&!1!==e.xrayed&&(t|=J),this._highlighted&&!1!==e.highlighted&&(t|=Z),this._selected&&!1!==e.selected&&(t|=$),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let s=0,n=e.meshIds.length;se.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,s=this.layerList.length;t0)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 s=0,n=t.visibleLayers.length;s65536?16:8)}else a=[{positionsCompressed:n,indices:i,edgeIndices:r}];return a}class Qc extends O{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 i=e-s,r=t-n;return Math.sqrt(i*i+r*r)};class tu extends O{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 s=this.plugin.viewer.scene;this._originMarker=new ae(s,t.origin),this._targetMarker=new ae(s,t.target),this._originWorld=h.vec3(),this._targetWorld=h.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 n=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,c=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new le(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._targetDot=new le(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._lengthWire=new oe(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._xAxisWire=new oe(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._yAxisWire=new oe(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._zAxisWire=new oe(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._lengthLabel=new ce(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._xAxisLabel=new ce(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._yAxisLabel=new ce(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._zAxisLabel=new ce(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,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=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=s.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=s.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=s.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=s.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&&(h.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._wp))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],s=this._targetMarker.viewPos[2];if(t>-.3||s>-.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){h.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var n=this._pp,i=this._cp,r=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var a=r.top-t.top,o=r.left-t.left,l=e.canvas.boundary,c=l[2],u=l[3],p=0;const s=this.plugin.viewer.scene.metrics,f=s.scale,I=s.units,m=s.unitsInfo[I].abbrev;for(var d=0,A=n.length;d{const t=e.snappedCanvasPos||e.canvasPos;if(i=!0,r.set(e.worldPos),a.set(e.canvasPos),0===this._mouseState){const s=n.getBoundingClientRect(),i=window.pageXOffset||document.documentElement.scrollLeft,r=window.pageYOffset||document.documentElement.scrollTop,a=s.left+i,o=s.top+r;this._markerDiv.style.marginLeft=a+t[0]-5+"px",this._markerDiv.style.marginTop=o+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"),c=e.entity}else this._markerDiv.style.marginLeft="-10000px",this._markerDiv.style.marginTop="-10000px";n.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=r.slice(),this._markerDiv.style.marginLeft="-10000px",this._markerDiv.style.marginTop="-10000px")})),n.addEventListener("mousedown",this._onMouseDown=e=>{1===e.which&&(o=e.clientX,l=e.clientY)}),n.addEventListener("mouseup",this._onMouseUp=t=>{1===t.which&&(t.clientX>o+20||t.clientXl+20||t.clientY{this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos),i=!1,this._markerDiv.style.marginLeft="-100px",this._markerDiv.style.marginTop="-100px",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.axisVisible=!1),n.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 iu{constructor(){}getMetaModel(e,t,s){y.loadJSON(e,(e=>{t(e)}),(function(e){s(e)}))}getGLTF(e,t,s){y.loadArraybuffer(e,(e=>{t(e)}),(function(e){s(e)}))}getGLB(e,t,s){y.loadArraybuffer(e,(e=>{t(e)}),(function(e){s(e)}))}getArrayBuffer(e,t,s,n){!function(e,t,s,n){var i=()=>{};s=s||i,n=n||i;const r=/^data:(.*?)(;base64)?,(.*)$/,a=t.match(r);if(a){const e=!!a[2];var o=a[3];o=window.decodeURIComponent(o),e&&(o=window.atob(o));try{const e=new ArrayBuffer(o.length),t=new Uint8Array(e);for(var l=0;l{s(e)}),(function(e){n(e)}))}}class ru{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 s=this._messages[this._locale];if(!s)return null;const n=au(e,s);return n?t?ou(n,t):n:null}translatePlurals(e,t,s){const n=this._messages[this._locale];if(!n)return null;let i=au(e,n);return i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one,i?(i=ou(i,[t]),s&&(i=ou(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const r=this._events[t];return void 0!==r&&s(r),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function au(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&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 s=e-t,n=e+t;s<0&&(s=0),n>1&&(n=1);var i=this.getPoint(s),r=this.getPoint(n),a=h.subVec3(r,i,[]);return h.normalizeVec3(a,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_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,s,n=[],i=this.getPoint(0),r=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),r+=h.lenVec3(h.subVec3(t,i,[])),n.push(r),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,r=n.length;s=t||e*n[r-1];for(var a,o=0,l=r-1;o<=l;)if((a=n[i=Math.floor(o+(l-o)/2)]-s)<0)o=i+1;else{if(!(a>0)){l=i;break}l=i-1}if(n[i=l]===s)return i/(r-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(r-1)}}class cu extends lu{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 s=(t.length-1)*e,n=Math.floor(s),i=s-n,r=t[0===n?n:n-1],a=t[n],o=t[n>t.length-2?t.length-1:n+1],l=t[n>t.length-3?t.length-1:n+2],c=h.vec3();return c[0]=h.catmullRomInterpolate(r[0],a[0],o[0],l[0],i),c[1]=h.catmullRomInterpolate(r[1],a[1],o[1],l[1],i),c[2]=h.catmullRomInterpolate(r[2],a[2],o[2],l[2],i),c}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 uu=h.vec3();const hu=h.vec3(),pu=h.vec3(),du=h.vec3(),Au=h.vec3(),fu=h.vec3();class Iu extends O{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=h.vec3(),this._eye1=h.vec3(),this._up1=h.vec3(),this._look2=h.vec3(),this._eye2=h.vec3(),this._up2=h.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,s){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=s;const n=this.scene.camera,i=!!e.projection&&e.projection!==n.projection;let r,a,o,l,c;if(this._eye1[0]=n.eye[0],this._eye1[1]=n.eye[1],this._eye1[2]=n.eye[2],this._look1[0]=n.look[0],this._look1[1]=n.look[1],this._look1[2]=n.look[2],this._up1[0]=n.up[0],this._up1[1]=n.up[1],this._up1[2]=n.up[2],this._orthoScale1=n.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)a=e.eye,o=e.look,l=e.up;else if(e.eye)a=e.eye;else if(e.look)o=e.look;else{let n=e;if((y.isNumeric(n)||y.isString(n))&&(c=n,n=this.scene.components[c],!n))return this.error("Component not found: "+y.inQuotes(c)),void(t&&(s?t.call(s):t()));i||(r=n.aabb||this.scene.aabb)}const u=e.poi;if(r){if(r[3]=1;e>1&&(e=1);const s=this.easing?Iu._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(h.subVec3(n.eye,n.look,fu),n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,du),n.look=h.subVec3(du,fu,pu)):this._flyingLook&&(n.look=h.lerpVec3(s,0,1,this._look1,this._look2,pu),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,Au)):this._flyingEyeLookUp&&(n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,du),n.look=h.lerpVec3(s,0,1,this._look1,this._look2,pu),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,Au)),this._projection2){const t="ortho"===this._projection2?Iu._easeOutExpo(e,0,1,1):Iu._easeInCubic(e,0,1,1);n.customProjection.matrix=h.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();C.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+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 mu extends O{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new Iu(this),this._t=0,this.state=mu.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,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case mu.SCRUBBING:return;case mu.PLAYING:if(this._t+=this._playingRate*i,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=mu.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case mu.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=mu.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(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=mu.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=mu.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=mu.SCRUBBING,this._cameraFlightAnimation.flyTo(n,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=mu.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=mu.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=mu.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}mu.STOPPED=0,mu.SCRUBBING=1,mu.PLAYING=2,mu.PLAYING_TO=3;const yu=h.vec3(),vu=h.vec3();h.vec3();const wu=h.vec3([0,-1,0]),gu=h.vec4([0,0,0,1]);function Eu(e){if(!Tu(e.width)||!Tu(e.height)){const t=document.createElement("canvas");t.width=bu(e.width),t.height=bu(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Tu(e){return 0==(e&e-1)}function bu(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Du extends O{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new $e({texture:new mn({gl:s,target:s.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),A.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,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let r=0;r{i(),t()})):(s.eye=this._eye,s.look=this._look,s.up=this._up,i(),s.projection=n.projection)}}const Cu=h.vec3();const _u=h.vec3();class Ru{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?y.apply(t,{}):null;const s=e.objects,n=!t||t.visible,i=!t||t.edges,r=!t||t.xrayed,a=!t||t.highlighted,o=!t||t.selected,l=!t||t.clippable,c=!t||t.pickable,u=!t||t.colorize,h=!t||t.opacity;for(let e in s)if(s.hasOwnProperty(e)){const t=s[e],p=this.numObjects;if(n&&(this.objectsVisible[p]=t.visible),i&&(this.objectsEdges[p]=t.edges),r&&(this.objectsXrayed[p]=t.xrayed),a&&(this.objectsHighlighted[p]=t.highlighted),o&&(this.objectsSelected[p]=t.selected),l&&(this.objectsClippable[p]=t.clippable),c&&(this.objectsPickable[p]=t.pickable),u){const e=t.colorize;e?(this.objectsColorize[3*p+0]=e[0],this.objectsColorize[3*p+1]=e[1],this.objectsColorize[3*p+2]=e[2],this.objectsHasColorize[p]=!0):this.objectsHasColorize[p]=!1}h&&(this.objectsOpacity[p]=t.opacity),this.numObjects++}}restoreObjects(e){const t=this._mask,s=!t||t.visible,n=!t||t.edges,i=!t||t.xrayed,r=!t||t.highlighted,a=!t||t.selected,o=!t||t.clippable,l=!t||t.pickable,c=!t||t.colorize,u=!t||t.opacity;var h=0;const p=e.objects;for(let e in p)if(p.hasOwnProperty(e)){const t=p[e];s&&(t.visible=this.objectsVisible[h]),n&&(t.edges=this.objectsEdges[h]),i&&(t.xrayed=this.objectsXrayed[h]),r&&(t.highlighted=this.objectsHighlighted[h]),a&&(t.selected=this.objectsSelected[h]),o&&(t.clippable=this.objectsClippable[h]),l&&(t.pickable=this.objectsPickable[h]),c&&(this.objectsHasColorize[h]?(_u[0]=this.objectsColorize[3*h+0],_u[1]=this.objectsColorize[3*h+1],_u[2]=this.objectsColorize[3*h+2],t.colorize=_u):t.colorize=null),u&&(t.opacity=this.objectsOpacity[h]),h++}}}class Bu extends O{constructor(e,t={}){super(e,t),this._skyboxMesh=new Qs(this,{geometry:new Lt(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 Gt(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Tn(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 Ou=h.vec4(),Su=h.vec4(),Nu=h.vec3(),xu=h.vec3(),Lu=h.vec3(),Mu=h.vec4(),Fu=h.vec4(),Hu=h.vec4();class Uu{constructor(e){this._scene=e}dollyToCanvasPos(e,t,s){let n=!1;const i=this._scene.camera;if(e){const t=h.subVec3(e,i.eye,Nu);n=h.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=h.vec3();h.decomposeMat4(h.inverseMat4(this._scene.viewer.camera.viewMatrix,h.mat4()),t,h.vec4(),h.vec3());const s=h.distVec3(t,e);let n=Math.tan(Math.PI/500)*s*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(n/=this._scene.camera.ortho.scale/2),k(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Pn(this._scene,Ks({radius:n})),this._pivotSphere=new Qs(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){h.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,h.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const s=t.boundary,n=s[2],i=s[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*n/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);let r=t._lastBoundingClientRect;if(!r||t._canvasSizeChanged){const e=t.canvas;r=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(r.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(r.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(k(this.getPivotPos(),this._rtcCenter,this._rtcPos),h.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 Gt(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=h.lookAtMat4v(e.eye,e.look,e.worldUp);h.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const s=this.getPivotPos();this._cameraOffset[2]+=h.distVec3(e.eye,s),t=h.inverseMat4(t);const n=h.transformVec3(t,this._cameraOffset),i=h.vec3();if(h.subVec3(e.eye,s,i),h.addVec3(i,n),e.zUp){const e=i[1];i[1]=i[2],i[2]=e}this._radius=h.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=h.normalizeVec3(h.subVec3(e.look,e.eye,Gu)),s=h.cross3Vec3(t,e.worldUp,ju);return h.sqLenVec3(s)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,s=Math.abs(h.distVec3(this._scene.center,t.eye)),n=t.project.transposedMatrix,i=n.subarray(8,12),r=n.subarray(12),a=[0,0,-1,1],o=h.dotVec4(a,i)/h.dotVec4(a,r),l=ku;t.project.unproject(e,o,Qu,Wu,l);const c=h.normalizeVec3(h.subVec3(l,t.eye,Gu)),u=h.addVec3(t.eye,h.mulVec3Scalar(c,s,ju),Vu);this.setPivotPos(u)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const s=this._scene.camera;var n=-e;const i=-t;1===s.worldUp[2]&&(n=-n),this._azimuth+=.01*-n,this._polar+=.01*i,this._polar=h.clamp(this._polar,.001,Math.PI-.001);const r=[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===s.worldUp[2]){const e=r[1];r[1]=r[2],r[2]=e}const a=h.lenVec3(h.subVec3(s.look,s.eye,h.vec3())),o=this.getPivotPos();h.addVec3(r,o);let l=h.lookAtMat4v(r,o,s.worldUp);l=h.inverseMat4(l);const c=h.transformVec3(l,this._cameraOffset);l[12]-=c[0],l[13]-=c[1],l[14]-=c[2];const u=[l[8],l[9],l[10]];s.eye=[l[12],l[13],l[14]],h.subVec3(s.eye,h.mulVec3Scalar(u,a),s.look),s.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 Ku{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=h.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 De;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 Yu=h.vec2();class Xu{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController;let a,o,l,c=0,u=0,p=0,d=0,A=!1;const f=h.vec3();let I=!0;const m=this._scene.canvas.canvas,y=[];function v(e=!0){m.style.cursor="move",c=n.pointerCanvasPos[0],u=n.pointerCanvasPos[1],p=n.pointerCanvasPos[0],d=n.pointerCanvasPos[1],e&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),r.picked&&r.pickedSurface&&r.pickResult&&r.pickResult.worldPos?(A=!0,f.set(r.pickResult.worldPos)):A=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;y[n]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;y[n]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:y[e.input.KEY_SHIFT]||s.planView?(a=!0,v()):(a=!0,v(!1));break;case 2:o=!0,v();break;case 3:l=!0,s.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=()=>{if(!s.active||!s.pointerEnabled)return;if(!a&&!o&&!l)return;const t=e.canvas.boundary,r=t[2],p=t[3],d=n.pointerCanvasPos[0],I=n.pointerCanvasPos[1];if(y[e.input.KEY_SHIFT]||s.planView||!s.panRightClick&&o||s.panRightClick&&l){const t=d-c,s=I-u,n=e.camera;if("perspective"===n.projection){const r=Math.abs(A?h.lenVec3(h.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=1.5*t*r/p,i.panDeltaY+=1.5*s*r/p}else i.panDeltaX+=.5*n.ortho.scale*(t/p),i.panDeltaY+=.5*n.ortho.scale*(s/p)}else!a||o||l||s.planView||(s.firstPerson?(i.rotateDeltaY-=(d-c)/r*s.dragRotationRate/2,i.rotateDeltaX+=(I-u)/p*(s.dragRotationRate/4)):(i.rotateDeltaY-=(d-c)/r*(1.5*s.dragRotationRate),i.rotateDeltaX+=(I-u)/p*(1.5*s.dragRotationRate)));c=d,u=I}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{s.active&&s.pointerEnabled&&n.mouseover&&(I=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(s.active&&s.pointerEnabled)switch(e.which){case 1:case 2:case 3:a=!1,o=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(s.active&&s.pointerEnabled){if(3===e.which){!function(e,t){if(e){let s=e.target,n=0,i=0,r=0,a=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,r+=s.scrollLeft,a+=s.scrollTop,s=s.offsetParent;t[0]=e.pageX+r-n,t[1]=e.pageY+a-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Yu);const s=Yu[0],n=Yu[1];Math.abs(s-p)<3&&Math.abs(n-d)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Yu,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{s.active&&s.pointerEnabled});const w=1/60;let g=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=performance.now()/1e3;var r=null!==g?t-g:0;g=t,r>.05&&(r=.05),r{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const a=i._isKeyDownForAction(i.AXIS_VIEW_RIGHT),o=i._isKeyDownForAction(i.AXIS_VIEW_BACK),l=i._isKeyDownForAction(i.AXIS_VIEW_LEFT),c=i._isKeyDownForAction(i.AXIS_VIEW_FRONT),u=i._isKeyDownForAction(i.AXIS_VIEW_TOP),p=i._isKeyDownForAction(i.AXIS_VIEW_BOTTOM);if(!(a||o||l||c||u||p))return;const d=e.aabb,A=h.getAABB3Diag(d);h.getAABB3Center(d,qu);const f=Math.abs(A/Math.tan(t.cameraFlight.fitFOV*h.DEGTORAD)),I=1.1*A;th.orthoScale=I,a?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldRight,f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):o?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldForward,f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):l?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldRight,-f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):c?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldForward,-f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):u?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldUp,f,Ju),eh)),th.look.set(qu),th.up.set(h.normalizeVec3(h.mulVec3Scalar(r.worldForward,1,Zu),$u))):p&&(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldUp,-f,Ju),eh)),th.look.set(qu),th.up.set(h.normalizeVec3(h.mulVec3Scalar(r.worldForward,-1,Zu)))),!s.firstPerson&&s.followPointer&&t.pivotController.setPivotPos(qu),t.cameraFlight.duration>0?t.cameraFlight.flyTo(th,(()=>{t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(th),t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class nh{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.pivotController,o=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,c=!1;const u=this._scene.canvas.canvas,p=s=>{let n;s&&s.worldPos&&(n=s.worldPos);const i=s&&s.entity?s.entity.aabb:e.aabb;if(n){const s=e.camera;h.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})},d=e.tickify(this._canvasMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(l||c)return;const i=o.hasSubs("hover"),a=o.hasSubs("hoverEnter"),u=o.hasSubs("hoverOut"),h=o.hasSubs("hoverOff"),p=o.hasSubs("hoverSurface"),d=o.hasSubs("hoverSnapOrSurface");if(i||a||u||h||p||d)if(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=!0,r.schedulePickSurface=p,r.scheduleSnapOrPick=d,r.update(),r.pickResult){if(r.pickResult.entity){const t=r.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),o.fire("hoverEnter",r.pickResult,!0),this._lastPickedEntityId=t)}o.fire("hover",r.pickResult,!0),(r.pickResult.worldPos||r.pickResult.snappedWorldPos)&&o.fire("hoverSurface",r.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),o.fire("hoverOff",{canvasPos:r.pickCursorPos},!0)});u.addEventListener("mousemove",d),u.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(c=!0);if(1===t.which&&s.active&&s.pointerEnabled&&(n.mouseDownClientX=t.clientX,n.mouseDownClientY=t.clientY,n.mouseDownCursorX=n.pointerCanvasPos[0],n.mouseDownCursorY=n.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),1===t.which))){const t=r.pickResult;t&&t.worldPos?(a.setPivotPos(t.worldPos),a.startPivot()):(s.smartPivot?a.setCanvasPivotPos(n.pointerCanvasPos):a.setPivotPos(e.camera.look),a.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(c=!1),a.getPivoting()&&a.endPivot()}),u.addEventListener("mouseup",this._canvasMouseUpHandler=i=>{if(!s.active||!s.pointerEnabled)return;if(!(1===i.which))return;if(a.hidePivot(),Math.abs(i.clientX-n.mouseDownClientX)>3||Math.abs(i.clientY-n.mouseDownClientY)>3)return;const l=o.hasSubs("picked"),c=o.hasSubs("pickedNothing"),u=o.hasSubs("pickedSurface"),d=o.hasSubs("doublePicked"),A=o.hasSubs("doublePickedSurface"),f=o.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||d||A||f))return(l||c||u)&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=!0,r.schedulePickSurface=u,r.update(),r.pickResult?(o.fire("picked",r.pickResult,!0),r.pickedSurface&&o.fire("pickedSurface",r.pickResult,!0)):o.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=s.doublePickFlyTo,r.schedulePickSurface=u,r.update();const e=r.pickResult,i=r.pickedSurface;this._timeout=setTimeout((()=>{e?(o.fire("picked",e,!0),i&&(o.fire("pickedSurface",e,!0),!s.firstPerson&&s.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):o.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0),this._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=s.doublePickFlyTo||d||A,r.schedulePickSurface=r.schedulePickEntity&&A,r.update(),r.pickResult){if(o.fire("doublePicked",r.pickResult,!0),r.pickedSurface&&o.fire("doublePickedSurface",r.pickResult,!0),s.doublePickFlyTo&&(p(r.pickResult),!s.firstPerson&&s.followPointer)){const e=r.pickResult.entity.aabb,s=h.getAABB3Center(e);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(o.fire("doublePickedNothing",{canvasPos:n.pointerCanvasPos},!0),s.doublePickFlyTo&&(p(),!s.firstPerson&&s.followPointer)){const s=e.aabb,n=h.getAABB3Center(s);t.pivotController.setPivotPos(n),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 ih{constructor(e,t,s,n,i){this._scene=e;const r=e.input,a=[],o=e.canvas.canvas;let l=!0;this._onSceneMouseMove=r.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=r.on("keydown",(t=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&n.mouseover&&(a[t]=!0,t===r.KEY_SHIFT&&(o.style.cursor="move"))})),this._onSceneKeyUp=r.on("keyup",(n=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(a[n]=!1,n===r.KEY_SHIFT&&(o.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(o=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const c=t.cameraControl,u=o.deltaTime/1e3;if(!s.planView){const e=c._isKeyDownForAction(c.ROTATE_Y_POS,a),n=c._isKeyDownForAction(c.ROTATE_Y_NEG,a),r=c._isKeyDownForAction(c.ROTATE_X_POS,a),o=c._isKeyDownForAction(c.ROTATE_X_NEG,a),l=u*s.keyboardRotationRate;(e||n||r||o)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),e?i.rotateDeltaY+=l:n&&(i.rotateDeltaY-=l),r?i.rotateDeltaX+=l:o&&(i.rotateDeltaX-=l),!s.firstPerson&&s.followPointer&&t.pivotController.startPivot())}if(!a[r.KEY_CTRL]&&!a[r.KEY_ALT]){const e=c._isKeyDownForAction(c.DOLLY_BACKWARDS,a),r=c._isKeyDownForAction(c.DOLLY_FORWARDS,a);if(e||r){const a=u*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),r?i.dollyDelta-=a:e&&(i.dollyDelta+=a),l&&(n.followPointerDirty=!0,l=!1)}}const h=c._isKeyDownForAction(c.PAN_FORWARDS,a),p=c._isKeyDownForAction(c.PAN_BACKWARDS,a),d=c._isKeyDownForAction(c.PAN_LEFT,a),A=c._isKeyDownForAction(c.PAN_RIGHT,a),f=c._isKeyDownForAction(c.PAN_UP,a),I=c._isKeyDownForAction(c.PAN_DOWN,a),m=(a[r.KEY_ALT]?.3:1)*u*s.keyboardPanRate;(h||p||d||A||f||I)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),I?i.panDeltaY+=m:f&&(i.panDeltaY+=-m),A?i.panDeltaX+=-m:d&&(i.panDeltaX+=m),p?i.panDeltaZ+=m:h&&(i.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 rh=h.vec3();class ah{constructor(e,t,s,n,i){this._scene=e;const r=e.camera,a=t.pickController,o=t.pivotController,l=t.panController;let c=1,u=1,p=null;this._onTick=e.on("tick",(()=>{if(!s.active||!s.pointerEnabled)return;let t="default";if(Math.abs(i.dollyDelta)<.001&&(i.dollyDelta=0),Math.abs(i.rotateDeltaX)<.001&&(i.rotateDeltaX=0),Math.abs(i.rotateDeltaY)<.001&&(i.rotateDeltaY=0),0===i.rotateDeltaX&&0===i.rotateDeltaY||(i.dollyDelta=0),s.followPointer&&--c<=0&&(c=1,0!==i.dollyDelta)){if(0===i.rotateDeltaY&&0===i.rotateDeltaX&&s.followPointer&&n.followPointerDirty&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.pickResult&&a.pickResult.worldPos?p=a.pickResult.worldPos:(u=1,p=null),n.followPointerDirty=!1),p){const t=Math.abs(h.lenVec3(h.subVec3(p,e.camera.eye,rh)));u=t/s.dollyProximityThreshold}u{n.mouseover=!0}),r.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{n.mouseover=!1,r.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{lh(e,r,n.pointerCanvasPos)}),r.addEventListener("mousedown",this._mouseDownHandler=e=>{s.active&&s.pointerEnabled&&(lh(e,r,n.pointerCanvasPos),n.mouseover=!0)}),r.addEventListener("mouseup",this._mouseUpHandler=e=>{s.active&&s.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 lh(e,t,s){if(e){const{x:n,y:i}=t.getBoundingClientRect();s[0]=e.clientX-n,s[1]=e.clientY-i}else e=window.event,s[0]=e.x,s[1]=e.y;return s}const ch=function(e,t){if(e){let s=e.target,n=0,i=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,s=s.offsetParent;t[0]=e.pageX-n,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class uh{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.pivotController,o=h.vec2(),l=h.vec2(),c=h.vec2(),u=h.vec2(),p=[],d=this._scene.canvas.canvas;let A=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),d.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!s.active||!s.pointerEnabled)return;t.preventDefault();const i=t.touches,l=t.changedTouches;for(n.touchStartTime=Date.now(),1===i.length&&1===l.length&&(ch(i[0],o),s.followPointer&&(r.pickCursorPos=o,r.schedulePickSurface=!0,r.update(),s.planView||(r.picked&&r.pickedSurface&&r.pickResult&&r.pickResult.worldPos?(a.setPivotPos(r.pickResult.worldPos),!s.firstPerson&&a.startPivot()&&a.showPivot()):(s.smartPivot?a.setCanvasPivotPos(n.pointerCanvasPos):a.setPivotPos(e.camera.look),!s.firstPerson&&a.startPivot()&&a.showPivot()))));p.length{a.getPivoting()&&a.endPivot()}),d.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const a=e.canvas.boundary,o=a[2],d=a[3],I=t.touches;if(t.touches.length===A){if(1===A){ch(I[0],l),h.subVec2(l,p[0],u);const t=u[0],r=u[1];if(null!==n.longTouchTimeout&&(Math.abs(t)>s.longTapRadius||Math.abs(r)>s.longTapRadius)&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),s.planView){const n=e.camera;if("perspective"===n.projection){const a=Math.abs(e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=t*a/d*s.touchPanRate,i.panDeltaY+=r*a/d*s.touchPanRate}else i.panDeltaX+=.5*n.ortho.scale*(t/d)*s.touchPanRate,i.panDeltaY+=.5*n.ortho.scale*(r/d)*s.touchPanRate}else i.rotateDeltaY-=t/o*(1*s.dragRotationRate),i.rotateDeltaX+=r/d*(1.5*s.dragRotationRate)}else if(2===A){const t=I[0],a=I[1];ch(t,l),ch(a,c);const o=h.geometricMeanVec2(p[0],p[1]),u=h.geometricMeanVec2(l,c),A=h.vec2();h.subVec2(o,u,A);const f=A[0],m=A[1],y=e.camera,v=h.distVec2([t.pageX,t.pageY],[a.pageX,a.pageY]),w=(h.distVec2(p[0],p[1])-v)*s.touchDollyRate;if(i.dollyDelta=w,Math.abs(w)<1)if("perspective"===y.projection){const t=r.pickResult?r.pickResult.worldPos:e.center,n=Math.abs(h.lenVec3(h.subVec3(t,e.camera.eye,[])))*Math.tan(y.perspective.fov/2*Math.PI/180);i.panDeltaX-=f*n/d*s.touchPanRate,i.panDeltaY-=m*n/d*s.touchPanRate}else i.panDeltaX-=.5*y.ortho.scale*(f/d)*s.touchPanRate,i.panDeltaY-=.5*y.ortho.scale*(m/d)*s.touchPanRate;n.pointerCanvasPos=u}for(let e=0;e{let n;s&&s.worldPos&&(n=s.worldPos);const i=s?s.entity.aabb:e.aabb;if(n){const s=e.camera;h.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};d.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!s.active||!s.pointerEnabled)return;null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null);const i=e.touches,r=e.changedTouches;if(o=Date.now(),1===i.length&&1===r.length){u=o,hh(i[0],c);const r=c[0],a=c[1],l=i[0].pageX,h=i[0].pageY;n.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(h)],canvasPos:[Math.round(r),Math.round(a)],event:e},!0),n.longTouchTimeout=null}),s.longTapTimeout)}else u=-1;for(;l.length{if(!s.active||!s.pointerEnabled)return;const t=Date.now(),i=e.touches,o=e.changedTouches,d=a.hasSubs("pickedSurface");null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),0===i.length&&1===o.length&&u>-1&&t-u<150&&(p>-1&&u-p<325?(hh(o[0],r.pickCursorPos),r.schedulePickEntity=!0,r.schedulePickSurface=d,r.update(),r.pickResult?(r.pickResult.touchInput=!0,a.fire("doublePicked",r.pickResult),r.pickedSurface&&a.fire("doublePickedSurface",r.pickResult),s.doublePickFlyTo&&A(r.pickResult)):(a.fire("doublePickedNothing"),s.doublePickFlyTo&&A()),p=-1):h.distVec2(l[0],c)<4&&(hh(o[0],r.pickCursorPos),r.schedulePickEntity=!0,r.schedulePickSurface=d,r.update(),r.pickResult?(r.pickResult.touchInput=!0,a.fire("picked",r.pickResult),r.pickedSurface&&a.fire("pickedSurface",r.pickResult)):a.fire("pickedNothing"),p=t),u=-1),l.length=i.length;for(let e=0,t=i.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:h.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:h.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const s=this.scene;this._controllers={cameraControl:this,pickController:new Ku(this,this._configs),pivotController:new zu(s,this._configs),panController:new Uu(s),cameraFlight:new Iu(this,{duration:.5})},this._handlers=[new oh(this.scene,this._controllers,this._configs,this._states,this._updates),new uh(this.scene,this._controllers,this._configs,this._states,this._updates),new Xu(this.scene,this._controllers,this._configs,this._states,this._updates),new sh(this.scene,this._controllers,this._configs,this._states,this._updates),new nh(this.scene,this._controllers,this._configs,this._states,this._updates),new ph(this.scene,this._controllers,this._configs,this._states,this._updates),new ih(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new ah(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,s={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":s[this.PAN_LEFT]=[t.KEY_A],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_Z],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":s[this.PAN_LEFT]=[t.KEY_Q],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_W],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=s}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const s=this._keyMap[e];if(!s)return!1;t||(t=this.scene.input.keyDown);for(let e=0,n=s.length;e0?vh(t):null,a=s&&s.length>0?vh(s):null,o=e=>{if(!e)return;var t=!0;(a&&a[e.type]||r&&!r[e.type])&&(t=!1),t&&n.push(e.id);const s=e.children;if(s)for(var i=0,l=s.length;i>t;s.sort(Ec);const n=new Int32Array(e.length);for(let t=0,i=s.length;te[t+1]){let s=e[t];e[t]=e[t+1],e[t+1]=s}Tc=new Int32Array(e),t.sort(bc);const s=new Int32Array(e.length);for(let n=0,i=t.length;nt){let s=e;e=t,t=s}function s(s,n){return s!==e?e-s:n!==t?t-n:0}let n=0,i=(r.length>>1)-1;for(;n<=i;){const e=i+n>>1,t=s(r[2*e],r[2*e+1]);if(t>0)n=e+1;else{if(!(t<0))return e;i=e-1}}return-n-1}const o=new Int32Array(r.length/2);o.fill(0);const l=n.length/3;if(l>8*(1<p.maxNumPositions&&(p=h()),p.bucketNumber>8)return[e];let A;-1===c[l]&&(c[l]=p.numPositions++,p.positionsCompressed.push(n[3*l]),p.positionsCompressed.push(n[3*l+1]),p.positionsCompressed.push(n[3*l+2])),-1===c[u]&&(c[u]=p.numPositions++,p.positionsCompressed.push(n[3*u]),p.positionsCompressed.push(n[3*u+1]),p.positionsCompressed.push(n[3*u+2])),-1===c[d]&&(c[d]=p.numPositions++,p.positionsCompressed.push(n[3*d]),p.positionsCompressed.push(n[3*d+1]),p.positionsCompressed.push(n[3*d+2])),p.indices.push(c[l]),p.indices.push(c[u]),p.indices.push(c[d]),(A=a(l,u))>=0&&0===o[A]&&(o[A]=1,p.edgeIndices.push(c[r[2*A]]),p.edgeIndices.push(c[r[2*A+1]])),(A=a(l,d))>=0&&0===o[A]&&(o[A]=1,p.edgeIndices.push(c[r[2*A]]),p.edgeIndices.push(c[r[2*A+1]])),(A=a(u,d))>=0&&0===o[A]&&(o[A]=1,p.edgeIndices.push(c[r[2*A]]),p.edgeIndices.push(c[r[2*A+1]]))}const d=t/8*2,A=t/8,f=2*n.length+(i.length+r.length)*d;let I=0,m=-n.length/3;return u.forEach((e=>{I+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*A,m+=e.positionsCompressed.length/3})),I>f?[e]:(s&&function(e,t){const s={},n={};let i=0;e.forEach((e=>{const t=e.indices,r=e.edgeIndices,a=e.positionsCompressed;for(let e=0,n=t.length;e0){const e=t._meshes;for(let t=0,s=e.length;t0){const e=this._meshes;for(let t=0,s=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 rc({id:"defaultColorTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new rc({id:"defaultMetalRoughTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),s=new rc({id:"defaultNormalsTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),n=new rc({id:"defaultEmissiveTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new rc({id:"defaultOcclusionTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=s,this._textures.defaultEmissiveTexture=n,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new ic({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:s,emissiveTexture:n,occlusionTexture:i})}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]),h.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]),h.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||Gc),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),h.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),h.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&&(h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),h.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),h.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,s=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,s=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,s=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,s=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,s=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,s=new Uint8Array(t.length);for(let e=0,n=t.length;e{l.setImage(c,{minFilter:s,magFilter:n,wrapS:i,wrapT:r,wrapR:a,flipY:e.flipY,encoding:o}),this.glRedraw()},c.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 rc({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 s,n,i,r,a;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(s=this._textures[e.colorTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(n=this._textures[e.metallicRoughnessTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(i=this._textures[e.normalsTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(r=this._textures[e.emissiveTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(a=this._textures[e.occlusionTextureId],!a)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else a=this._textures.defaultOcclusionTexture;const o=new ic({id:t,model:this,colorTexture:s,metallicRoughnessTexture:n,normalsTexture:i,emissiveTexture:r,occlusionTexture:a});return this._textureSets[t]=o,o}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(this.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const s=new Nc({id:e.id,model:this,parentTransform:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[s.id]=s,s}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._scheduledMeshes[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&&"points"!==e.primitive)return 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?h.addVec3(this._origin,e.origin,h.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){const t=e.scale||Mc,s=e.position||Fc,n=e.rotation||Hc;h.eulerToQuaternion(n,"XYZ",Uc),e.meshMatrix=h.composeMat4(s,Uc,t,h.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Si(e.positionsDecodeBoundary,h.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])]):jc,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=h.vec3(),s=[];Q(e.positions,s,t)&&(e.positions=s,e.origin=h.addVec3(e.origin,t,t))}if(e.positions){const t=h.collapseAABB3();e.positionsDecodeMatrix=h.mat4(),h.expandAABB3Points3(t,e.positions),e.positionsCompressed=Oi(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=h.collapseAABB3();h.expandAABB3Points3(t,e.positionsCompressed),St.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=h.collapseAABB3();for(let s=0,n=e.buckets.length;s>24&255,i=s>>16&255,r=s>>8&255,a=255&s;switch(e.pickColor=new Uint8Array([a,r,i,n]),e.solid="solid"===e.primitive,t.origin=h.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),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 s=0,n=e.buckets.length;s>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,s=e.origin,n=e.textureSetId||"-",i=e.geometryId,r=`${Math.round(s[0])}.${Math.round(s[1])}.${Math.round(s[2])}.${n}.${i}`;let a=this._vboInstancingLayers[r];if(a)return a;let o=e.textureSet;const l=e.geometry;for(;!a;)switch(l.primitive){case"triangles":case"surface":a=new Mr({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0,solid:!1});break;case"solid":a=new Mr({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0,solid:!0});break;case"lines":a=new ga({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0});break;case"points":a=new fo({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0})}return this._vboInstancingLayers[r]=a,this.layerList.push(a),a}createEntity(e){if(void 0===e.id?e.id=h.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=h.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;this._visible&&!1!==e.visible&&(t|=z),this._pickable&&!1!==e.pickable&&(t|=Y),this._culled&&!1!==e.culled&&(t|=K),this._clippable&&!1!==e.clippable&&(t|=X),this._collidable&&!1!==e.collidable&&(t|=q),this._edges&&!1!==e.edges&&(t|=ee),this._xrayed&&!1!==e.xrayed&&(t|=J),this._highlighted&&!1!==e.highlighted&&(t|=Z),this._selected&&!1!==e.selected&&(t|=$),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let s=0,n=e.meshIds.length;se.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,s=this.layerList.length;t0)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 s=0,n=t.visibleLayers.length;s65536?16:8)}else a=[{positionsCompressed:n,indices:i,edgeIndices:r}];return a}class Qc extends O{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 i=e-s,r=t-n;return Math.sqrt(i*i+r*r)};class tu extends O{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 s=this.plugin.viewer.scene;this._originMarker=new ae(s,t.origin),this._targetMarker=new ae(s,t.target),this._originWorld=h.vec3(),this._targetWorld=h.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 n=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,c=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new le(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._targetDot=new le(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._lengthWire=new oe(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._xAxisWire=new oe(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._yAxisWire=new oe(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._zAxisWire=new oe(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._lengthLabel=new ce(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._xAxisLabel=new ce(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._yAxisLabel=new ce(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._zAxisLabel=new ce(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,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=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=s.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=s.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=s.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=s.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&&(h.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._wp))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],s=this._targetMarker.viewPos[2];if(t>-.3||s>-.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){h.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var n=this._pp,i=this._cp,r=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var a=r.top-t.top,o=r.left-t.left,l=e.canvas.boundary,c=l[2],u=l[3],p=0;const s=this.plugin.viewer.scene.metrics,f=s.scale,I=s.units,m=s.unitsInfo[I].abbrev;for(var d=0,A=n.length;d{const t=e.snappedCanvasPos||e.canvasPos;if(i=!0,r.set(e.worldPos),a.set(e.canvasPos),0===this._mouseState){const s=n.getBoundingClientRect(),i=window.pageXOffset||document.documentElement.scrollLeft,r=window.pageYOffset||document.documentElement.scrollTop,a=s.left+i,o=s.top+r;this._markerDiv.style.marginLeft=a+t[0]-5+"px",this._markerDiv.style.marginTop=o+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"),c=e.entity}else this._markerDiv.style.marginLeft="-10000px",this._markerDiv.style.marginTop="-10000px";n.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=r.slice(),this._markerDiv.style.marginLeft="-10000px",this._markerDiv.style.marginTop="-10000px")})),n.addEventListener("mousedown",this._onMouseDown=e=>{1===e.which&&(o=e.clientX,l=e.clientY)}),n.addEventListener("mouseup",this._onMouseUp=t=>{1===t.which&&(t.clientX>o+20||t.clientXl+20||t.clientY{this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos),i=!1,this._markerDiv.style.marginLeft="-100px",this._markerDiv.style.marginTop="-100px",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.axisVisible=!1),n.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 iu{constructor(){}getMetaModel(e,t,s){y.loadJSON(e,(e=>{t(e)}),(function(e){s(e)}))}getGLTF(e,t,s){y.loadArraybuffer(e,(e=>{t(e)}),(function(e){s(e)}))}getGLB(e,t,s){y.loadArraybuffer(e,(e=>{t(e)}),(function(e){s(e)}))}getArrayBuffer(e,t,s,n){!function(e,t,s,n){var i=()=>{};s=s||i,n=n||i;const r=/^data:(.*?)(;base64)?,(.*)$/,a=t.match(r);if(a){const e=!!a[2];var o=a[3];o=window.decodeURIComponent(o),e&&(o=window.atob(o));try{const e=new ArrayBuffer(o.length),t=new Uint8Array(e);for(var l=0;l{s(e)}),(function(e){n(e)}))}}class ru{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 s=this._messages[this._locale];if(!s)return null;const n=au(e,s);return n?t?ou(n,t):n:null}translatePlurals(e,t,s){const n=this._messages[this._locale];if(!n)return null;let i=au(e,n);return i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one,i?(i=ou(i,[t]),s&&(i=ou(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const r=this._events[t];return void 0!==r&&s(r),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function au(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&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 s=e-t,n=e+t;s<0&&(s=0),n>1&&(n=1);var i=this.getPoint(s),r=this.getPoint(n),a=h.subVec3(r,i,[]);return h.normalizeVec3(a,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_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,s,n=[],i=this.getPoint(0),r=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),r+=h.lenVec3(h.subVec3(t,i,[])),n.push(r),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,r=n.length;s=t||e*n[r-1];for(var a,o=0,l=r-1;o<=l;)if((a=n[i=Math.floor(o+(l-o)/2)]-s)<0)o=i+1;else{if(!(a>0)){l=i;break}l=i-1}if(n[i=l]===s)return i/(r-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(r-1)}}class cu extends lu{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 s=(t.length-1)*e,n=Math.floor(s),i=s-n,r=t[0===n?n:n-1],a=t[n],o=t[n>t.length-2?t.length-1:n+1],l=t[n>t.length-3?t.length-1:n+2],c=h.vec3();return c[0]=h.catmullRomInterpolate(r[0],a[0],o[0],l[0],i),c[1]=h.catmullRomInterpolate(r[1],a[1],o[1],l[1],i),c[2]=h.catmullRomInterpolate(r[2],a[2],o[2],l[2],i),c}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 uu=h.vec3();const hu=h.vec3(),pu=h.vec3(),du=h.vec3(),Au=h.vec3(),fu=h.vec3();class Iu extends O{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=h.vec3(),this._eye1=h.vec3(),this._up1=h.vec3(),this._look2=h.vec3(),this._eye2=h.vec3(),this._up2=h.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,s){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=s;const n=this.scene.camera,i=!!e.projection&&e.projection!==n.projection;let r,a,o,l,c;if(this._eye1[0]=n.eye[0],this._eye1[1]=n.eye[1],this._eye1[2]=n.eye[2],this._look1[0]=n.look[0],this._look1[1]=n.look[1],this._look1[2]=n.look[2],this._up1[0]=n.up[0],this._up1[1]=n.up[1],this._up1[2]=n.up[2],this._orthoScale1=n.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)a=e.eye,o=e.look,l=e.up;else if(e.eye)a=e.eye;else if(e.look)o=e.look;else{let n=e;if((y.isNumeric(n)||y.isString(n))&&(c=n,n=this.scene.components[c],!n))return this.error("Component not found: "+y.inQuotes(c)),void(t&&(s?t.call(s):t()));i||(r=n.aabb||this.scene.aabb)}const u=e.poi;if(r){if(r[3]=1;e>1&&(e=1);const s=this.easing?Iu._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(h.subVec3(n.eye,n.look,fu),n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,du),n.look=h.subVec3(du,fu,pu)):this._flyingLook&&(n.look=h.lerpVec3(s,0,1,this._look1,this._look2,pu),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,Au)):this._flyingEyeLookUp&&(n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,du),n.look=h.lerpVec3(s,0,1,this._look1,this._look2,pu),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,Au)),this._projection2){const t="ortho"===this._projection2?Iu._easeOutExpo(e,0,1,1):Iu._easeInCubic(e,0,1,1);n.customProjection.matrix=h.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();C.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+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 mu extends O{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new Iu(this),this._t=0,this.state=mu.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,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case mu.SCRUBBING:return;case mu.PLAYING:if(this._t+=this._playingRate*i,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=mu.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case mu.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=mu.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(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=mu.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=mu.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=mu.SCRUBBING,this._cameraFlightAnimation.flyTo(n,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=mu.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=mu.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=mu.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}mu.STOPPED=0,mu.SCRUBBING=1,mu.PLAYING=2,mu.PLAYING_TO=3;const yu=h.vec3(),vu=h.vec3();h.vec3();const wu=h.vec3([0,-1,0]),gu=h.vec4([0,0,0,1]);function Eu(e){if(!Tu(e.width)||!Tu(e.height)){const t=document.createElement("canvas");t.width=bu(e.width),t.height=bu(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Tu(e){return 0==(e&e-1)}function bu(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Du extends O{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new $e({texture:new mn({gl:s,target:s.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),A.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,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let r=0;r{i(),t()})):(s.eye=this._eye,s.look=this._look,s.up=this._up,i(),s.projection=n.projection)}}const Cu=h.vec3();const _u=h.vec3();class Ru{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?y.apply(t,{}):null;const s=e.objects,n=!t||t.visible,i=!t||t.edges,r=!t||t.xrayed,a=!t||t.highlighted,o=!t||t.selected,l=!t||t.clippable,c=!t||t.pickable,u=!t||t.colorize,h=!t||t.opacity;for(let e in s)if(s.hasOwnProperty(e)){const t=s[e],p=this.numObjects;if(n&&(this.objectsVisible[p]=t.visible),i&&(this.objectsEdges[p]=t.edges),r&&(this.objectsXrayed[p]=t.xrayed),a&&(this.objectsHighlighted[p]=t.highlighted),o&&(this.objectsSelected[p]=t.selected),l&&(this.objectsClippable[p]=t.clippable),c&&(this.objectsPickable[p]=t.pickable),u){const e=t.colorize;e?(this.objectsColorize[3*p+0]=e[0],this.objectsColorize[3*p+1]=e[1],this.objectsColorize[3*p+2]=e[2],this.objectsHasColorize[p]=!0):this.objectsHasColorize[p]=!1}h&&(this.objectsOpacity[p]=t.opacity),this.numObjects++}}restoreObjects(e){const t=this._mask,s=!t||t.visible,n=!t||t.edges,i=!t||t.xrayed,r=!t||t.highlighted,a=!t||t.selected,o=!t||t.clippable,l=!t||t.pickable,c=!t||t.colorize,u=!t||t.opacity;var h=0;const p=e.objects;for(let e in p)if(p.hasOwnProperty(e)){const t=p[e];s&&(t.visible=this.objectsVisible[h]),n&&(t.edges=this.objectsEdges[h]),i&&(t.xrayed=this.objectsXrayed[h]),r&&(t.highlighted=this.objectsHighlighted[h]),a&&(t.selected=this.objectsSelected[h]),o&&(t.clippable=this.objectsClippable[h]),l&&(t.pickable=this.objectsPickable[h]),c&&(this.objectsHasColorize[h]?(_u[0]=this.objectsColorize[3*h+0],_u[1]=this.objectsColorize[3*h+1],_u[2]=this.objectsColorize[3*h+2],t.colorize=_u):t.colorize=null),u&&(t.opacity=this.objectsOpacity[h]),h++}}}class Bu extends O{constructor(e,t={}){super(e,t),this._skyboxMesh=new Qs(this,{geometry:new Lt(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 Gt(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Tn(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 Ou=h.vec4(),Su=h.vec4(),Nu=h.vec3(),xu=h.vec3(),Lu=h.vec3(),Mu=h.vec4(),Fu=h.vec4(),Hu=h.vec4();class Uu{constructor(e){this._scene=e}dollyToCanvasPos(e,t,s){let n=!1;const i=this._scene.camera;if(e){const t=h.subVec3(e,i.eye,Nu);n=h.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=h.vec3();h.decomposeMat4(h.inverseMat4(this._scene.viewer.camera.viewMatrix,h.mat4()),t,h.vec4(),h.vec3());const s=h.distVec3(t,e);let n=Math.tan(Math.PI/500)*s*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(n/=this._scene.camera.ortho.scale/2),k(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Pn(this._scene,Ks({radius:n})),this._pivotSphere=new Qs(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){h.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,h.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const s=t.boundary,n=s[2],i=s[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*n/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);let r=t._lastBoundingClientRect;if(!r||t._canvasSizeChanged){const e=t.canvas;r=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(r.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(r.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(k(this.getPivotPos(),this._rtcCenter,this._rtcPos),h.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 Gt(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=h.lookAtMat4v(e.eye,e.look,e.worldUp);h.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const s=this.getPivotPos();this._cameraOffset[2]+=h.distVec3(e.eye,s),t=h.inverseMat4(t);const n=h.transformVec3(t,this._cameraOffset),i=h.vec3();if(h.subVec3(e.eye,s,i),h.addVec3(i,n),e.zUp){const e=i[1];i[1]=i[2],i[2]=e}this._radius=h.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=h.normalizeVec3(h.subVec3(e.look,e.eye,Gu)),s=h.cross3Vec3(t,e.worldUp,ju);return h.sqLenVec3(s)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,s=Math.abs(h.distVec3(this._scene.center,t.eye)),n=t.project.transposedMatrix,i=n.subarray(8,12),r=n.subarray(12),a=[0,0,-1,1],o=h.dotVec4(a,i)/h.dotVec4(a,r),l=ku;t.project.unproject(e,o,Qu,Wu,l);const c=h.normalizeVec3(h.subVec3(l,t.eye,Gu)),u=h.addVec3(t.eye,h.mulVec3Scalar(c,s,ju),Vu);this.setPivotPos(u)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const s=this._scene.camera;var n=-e;const i=-t;1===s.worldUp[2]&&(n=-n),this._azimuth+=.01*-n,this._polar+=.01*i,this._polar=h.clamp(this._polar,.001,Math.PI-.001);const r=[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===s.worldUp[2]){const e=r[1];r[1]=r[2],r[2]=e}const a=h.lenVec3(h.subVec3(s.look,s.eye,h.vec3())),o=this.getPivotPos();h.addVec3(r,o);let l=h.lookAtMat4v(r,o,s.worldUp);l=h.inverseMat4(l);const c=h.transformVec3(l,this._cameraOffset);l[12]-=c[0],l[13]-=c[1],l[14]-=c[2];const u=[l[8],l[9],l[10]];s.eye=[l[12],l[13],l[14]],h.subVec3(s.eye,h.mulVec3Scalar(u,a),s.look),s.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 Ku{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=h.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 De;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 Yu=h.vec2();class Xu{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController;let a,o,l,c=0,u=0,p=0,d=0,A=!1;const f=h.vec3();let I=!0;const m=this._scene.canvas.canvas,y=[];function v(e=!0){m.style.cursor="move",c=n.pointerCanvasPos[0],u=n.pointerCanvasPos[1],p=n.pointerCanvasPos[0],d=n.pointerCanvasPos[1],e&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),r.picked&&r.pickedSurface&&r.pickResult&&r.pickResult.worldPos?(A=!0,f.set(r.pickResult.worldPos)):A=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;y[n]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;y[n]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:y[e.input.KEY_SHIFT]||s.planView?(a=!0,v()):(a=!0,v(!1));break;case 2:o=!0,v();break;case 3:l=!0,s.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=()=>{if(!s.active||!s.pointerEnabled)return;if(!a&&!o&&!l)return;const t=e.canvas.boundary,r=t[2],p=t[3],d=n.pointerCanvasPos[0],I=n.pointerCanvasPos[1];if(y[e.input.KEY_SHIFT]||s.planView||!s.panRightClick&&o||s.panRightClick&&l){const t=d-c,s=I-u,n=e.camera;if("perspective"===n.projection){const r=Math.abs(A?h.lenVec3(h.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=1.5*t*r/p,i.panDeltaY+=1.5*s*r/p}else i.panDeltaX+=.5*n.ortho.scale*(t/p),i.panDeltaY+=.5*n.ortho.scale*(s/p)}else!a||o||l||s.planView||(s.firstPerson?(i.rotateDeltaY-=(d-c)/r*s.dragRotationRate/2,i.rotateDeltaX+=(I-u)/p*(s.dragRotationRate/4)):(i.rotateDeltaY-=(d-c)/r*(1.5*s.dragRotationRate),i.rotateDeltaX+=(I-u)/p*(1.5*s.dragRotationRate)));c=d,u=I}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{s.active&&s.pointerEnabled&&n.mouseover&&(I=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(s.active&&s.pointerEnabled)switch(e.which){case 1:case 2:case 3:a=!1,o=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(s.active&&s.pointerEnabled){if(3===e.which){!function(e,t){if(e){let s=e.target,n=0,i=0,r=0,a=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,r+=s.scrollLeft,a+=s.scrollTop,s=s.offsetParent;t[0]=e.pageX+r-n,t[1]=e.pageY+a-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Yu);const s=Yu[0],n=Yu[1];Math.abs(s-p)<3&&Math.abs(n-d)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Yu,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{s.active&&s.pointerEnabled});const w=1/60;let g=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=performance.now()/1e3;var r=null!==g?t-g:0;g=t,r>.05&&(r=.05),r{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const a=i._isKeyDownForAction(i.AXIS_VIEW_RIGHT),o=i._isKeyDownForAction(i.AXIS_VIEW_BACK),l=i._isKeyDownForAction(i.AXIS_VIEW_LEFT),c=i._isKeyDownForAction(i.AXIS_VIEW_FRONT),u=i._isKeyDownForAction(i.AXIS_VIEW_TOP),p=i._isKeyDownForAction(i.AXIS_VIEW_BOTTOM);if(!(a||o||l||c||u||p))return;const d=e.aabb,A=h.getAABB3Diag(d);h.getAABB3Center(d,qu);const f=Math.abs(A/Math.tan(t.cameraFlight.fitFOV*h.DEGTORAD)),I=1.1*A;th.orthoScale=I,a?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldRight,f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):o?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldForward,f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):l?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldRight,-f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):c?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldForward,-f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):u?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldUp,f,Ju),eh)),th.look.set(qu),th.up.set(h.normalizeVec3(h.mulVec3Scalar(r.worldForward,1,Zu),$u))):p&&(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldUp,-f,Ju),eh)),th.look.set(qu),th.up.set(h.normalizeVec3(h.mulVec3Scalar(r.worldForward,-1,Zu)))),!s.firstPerson&&s.followPointer&&t.pivotController.setPivotPos(qu),t.cameraFlight.duration>0?t.cameraFlight.flyTo(th,(()=>{t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(th),t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class nh{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.pivotController,o=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,c=!1;const u=this._scene.canvas.canvas,p=s=>{let n;s&&s.worldPos&&(n=s.worldPos);const i=s&&s.entity?s.entity.aabb:e.aabb;if(n){const s=e.camera;h.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})},d=e.tickify(this._canvasMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(l||c)return;const i=o.hasSubs("hover"),a=o.hasSubs("hoverEnter"),u=o.hasSubs("hoverOut"),h=o.hasSubs("hoverOff"),p=o.hasSubs("hoverSurface"),d=o.hasSubs("hoverSnapOrSurface");if(i||a||u||h||p||d)if(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=!0,r.schedulePickSurface=p,r.scheduleSnapOrPick=d,r.update(),r.pickResult){if(r.pickResult.entity){const t=r.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),o.fire("hoverEnter",r.pickResult,!0),this._lastPickedEntityId=t)}o.fire("hover",r.pickResult,!0),(r.pickResult.worldPos||r.pickResult.snappedWorldPos)&&o.fire("hoverSurface",r.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),o.fire("hoverOff",{canvasPos:r.pickCursorPos},!0)});u.addEventListener("mousemove",d),u.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(c=!0);if(1===t.which&&s.active&&s.pointerEnabled&&(n.mouseDownClientX=t.clientX,n.mouseDownClientY=t.clientY,n.mouseDownCursorX=n.pointerCanvasPos[0],n.mouseDownCursorY=n.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),1===t.which))){const t=r.pickResult;t&&t.worldPos?(a.setPivotPos(t.worldPos),a.startPivot()):(s.smartPivot?a.setCanvasPivotPos(n.pointerCanvasPos):a.setPivotPos(e.camera.look),a.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(c=!1),a.getPivoting()&&a.endPivot()}),u.addEventListener("mouseup",this._canvasMouseUpHandler=i=>{if(!s.active||!s.pointerEnabled)return;if(!(1===i.which))return;if(a.hidePivot(),Math.abs(i.clientX-n.mouseDownClientX)>3||Math.abs(i.clientY-n.mouseDownClientY)>3)return;const l=o.hasSubs("picked"),c=o.hasSubs("pickedNothing"),u=o.hasSubs("pickedSurface"),d=o.hasSubs("doublePicked"),A=o.hasSubs("doublePickedSurface"),f=o.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||d||A||f))return(l||c||u)&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=!0,r.schedulePickSurface=u,r.update(),r.pickResult?(o.fire("picked",r.pickResult,!0),r.pickedSurface&&o.fire("pickedSurface",r.pickResult,!0)):o.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=s.doublePickFlyTo,r.schedulePickSurface=u,r.update();const e=r.pickResult,i=r.pickedSurface;this._timeout=setTimeout((()=>{e?(o.fire("picked",e,!0),i&&(o.fire("pickedSurface",e,!0),!s.firstPerson&&s.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):o.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0),this._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=s.doublePickFlyTo||d||A,r.schedulePickSurface=r.schedulePickEntity&&A,r.update(),r.pickResult){if(o.fire("doublePicked",r.pickResult,!0),r.pickedSurface&&o.fire("doublePickedSurface",r.pickResult,!0),s.doublePickFlyTo&&(p(r.pickResult),!s.firstPerson&&s.followPointer)){const e=r.pickResult.entity.aabb,s=h.getAABB3Center(e);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(o.fire("doublePickedNothing",{canvasPos:n.pointerCanvasPos},!0),s.doublePickFlyTo&&(p(),!s.firstPerson&&s.followPointer)){const s=e.aabb,n=h.getAABB3Center(s);t.pivotController.setPivotPos(n),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 ih{constructor(e,t,s,n,i){this._scene=e;const r=e.input,a=[],o=e.canvas.canvas;let l=!0;this._onSceneMouseMove=r.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=r.on("keydown",(t=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&n.mouseover&&(a[t]=!0,t===r.KEY_SHIFT&&(o.style.cursor="move"))})),this._onSceneKeyUp=r.on("keyup",(n=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(a[n]=!1,n===r.KEY_SHIFT&&(o.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(o=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const c=t.cameraControl,u=o.deltaTime/1e3;if(!s.planView){const e=c._isKeyDownForAction(c.ROTATE_Y_POS,a),n=c._isKeyDownForAction(c.ROTATE_Y_NEG,a),r=c._isKeyDownForAction(c.ROTATE_X_POS,a),o=c._isKeyDownForAction(c.ROTATE_X_NEG,a),l=u*s.keyboardRotationRate;(e||n||r||o)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),e?i.rotateDeltaY+=l:n&&(i.rotateDeltaY-=l),r?i.rotateDeltaX+=l:o&&(i.rotateDeltaX-=l),!s.firstPerson&&s.followPointer&&t.pivotController.startPivot())}if(!a[r.KEY_CTRL]&&!a[r.KEY_ALT]){const e=c._isKeyDownForAction(c.DOLLY_BACKWARDS,a),r=c._isKeyDownForAction(c.DOLLY_FORWARDS,a);if(e||r){const a=u*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),r?i.dollyDelta-=a:e&&(i.dollyDelta+=a),l&&(n.followPointerDirty=!0,l=!1)}}const h=c._isKeyDownForAction(c.PAN_FORWARDS,a),p=c._isKeyDownForAction(c.PAN_BACKWARDS,a),d=c._isKeyDownForAction(c.PAN_LEFT,a),A=c._isKeyDownForAction(c.PAN_RIGHT,a),f=c._isKeyDownForAction(c.PAN_UP,a),I=c._isKeyDownForAction(c.PAN_DOWN,a),m=(a[r.KEY_ALT]?.3:1)*u*s.keyboardPanRate;(h||p||d||A||f||I)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),I?i.panDeltaY+=m:f&&(i.panDeltaY+=-m),A?i.panDeltaX+=-m:d&&(i.panDeltaX+=m),p?i.panDeltaZ+=m:h&&(i.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 rh=h.vec3();class ah{constructor(e,t,s,n,i){this._scene=e;const r=e.camera,a=t.pickController,o=t.pivotController,l=t.panController;let c=1,u=1,p=null;this._onTick=e.on("tick",(()=>{if(!s.active||!s.pointerEnabled)return;let t="default";if(Math.abs(i.dollyDelta)<.001&&(i.dollyDelta=0),Math.abs(i.rotateDeltaX)<.001&&(i.rotateDeltaX=0),Math.abs(i.rotateDeltaY)<.001&&(i.rotateDeltaY=0),0===i.rotateDeltaX&&0===i.rotateDeltaY||(i.dollyDelta=0),s.followPointer&&--c<=0&&(c=1,0!==i.dollyDelta)){if(0===i.rotateDeltaY&&0===i.rotateDeltaX&&s.followPointer&&n.followPointerDirty&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.pickResult&&a.pickResult.worldPos?p=a.pickResult.worldPos:(u=1,p=null),n.followPointerDirty=!1),p){const t=Math.abs(h.lenVec3(h.subVec3(p,e.camera.eye,rh)));u=t/s.dollyProximityThreshold}u{n.mouseover=!0}),r.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{n.mouseover=!1,r.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{lh(e,r,n.pointerCanvasPos)}),r.addEventListener("mousedown",this._mouseDownHandler=e=>{s.active&&s.pointerEnabled&&(lh(e,r,n.pointerCanvasPos),n.mouseover=!0)}),r.addEventListener("mouseup",this._mouseUpHandler=e=>{s.active&&s.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 lh(e,t,s){if(e){const{x:n,y:i}=t.getBoundingClientRect();s[0]=e.clientX-n,s[1]=e.clientY-i}else e=window.event,s[0]=e.x,s[1]=e.y;return s}const ch=function(e,t){if(e){let s=e.target,n=0,i=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,s=s.offsetParent;t[0]=e.pageX-n,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class uh{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.pivotController,o=h.vec2(),l=h.vec2(),c=h.vec2(),u=h.vec2(),p=[],d=this._scene.canvas.canvas;let A=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),d.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!s.active||!s.pointerEnabled)return;t.preventDefault();const i=t.touches,l=t.changedTouches;for(n.touchStartTime=Date.now(),1===i.length&&1===l.length&&(ch(i[0],o),s.followPointer&&(r.pickCursorPos=o,r.schedulePickSurface=!0,r.update(),s.planView||(r.picked&&r.pickedSurface&&r.pickResult&&r.pickResult.worldPos?(a.setPivotPos(r.pickResult.worldPos),!s.firstPerson&&a.startPivot()&&a.showPivot()):(s.smartPivot?a.setCanvasPivotPos(n.pointerCanvasPos):a.setPivotPos(e.camera.look),!s.firstPerson&&a.startPivot()&&a.showPivot()))));p.length{a.getPivoting()&&a.endPivot()}),d.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const a=e.canvas.boundary,o=a[2],d=a[3],I=t.touches;if(t.touches.length===A){if(1===A){ch(I[0],l),h.subVec2(l,p[0],u);const t=u[0],r=u[1];if(null!==n.longTouchTimeout&&(Math.abs(t)>s.longTapRadius||Math.abs(r)>s.longTapRadius)&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),s.planView){const n=e.camera;if("perspective"===n.projection){const a=Math.abs(e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=t*a/d*s.touchPanRate,i.panDeltaY+=r*a/d*s.touchPanRate}else i.panDeltaX+=.5*n.ortho.scale*(t/d)*s.touchPanRate,i.panDeltaY+=.5*n.ortho.scale*(r/d)*s.touchPanRate}else i.rotateDeltaY-=t/o*(1*s.dragRotationRate),i.rotateDeltaX+=r/d*(1.5*s.dragRotationRate)}else if(2===A){const t=I[0],a=I[1];ch(t,l),ch(a,c);const o=h.geometricMeanVec2(p[0],p[1]),u=h.geometricMeanVec2(l,c),A=h.vec2();h.subVec2(o,u,A);const f=A[0],m=A[1],y=e.camera,v=h.distVec2([t.pageX,t.pageY],[a.pageX,a.pageY]),w=(h.distVec2(p[0],p[1])-v)*s.touchDollyRate;if(i.dollyDelta=w,Math.abs(w)<1)if("perspective"===y.projection){const t=r.pickResult?r.pickResult.worldPos:e.center,n=Math.abs(h.lenVec3(h.subVec3(t,e.camera.eye,[])))*Math.tan(y.perspective.fov/2*Math.PI/180);i.panDeltaX-=f*n/d*s.touchPanRate,i.panDeltaY-=m*n/d*s.touchPanRate}else i.panDeltaX-=.5*y.ortho.scale*(f/d)*s.touchPanRate,i.panDeltaY-=.5*y.ortho.scale*(m/d)*s.touchPanRate;n.pointerCanvasPos=u}for(let e=0;e{let n;s&&s.worldPos&&(n=s.worldPos);const i=s?s.entity.aabb:e.aabb;if(n){const s=e.camera;h.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};d.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!s.active||!s.pointerEnabled)return;null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null);const i=e.touches,r=e.changedTouches;if(o=Date.now(),1===i.length&&1===r.length){u=o,hh(i[0],c);const r=c[0],a=c[1],l=i[0].pageX,h=i[0].pageY;n.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(h)],canvasPos:[Math.round(r),Math.round(a)],event:e},!0),n.longTouchTimeout=null}),s.longTapTimeout)}else u=-1;for(;l.length{if(!s.active||!s.pointerEnabled)return;const t=Date.now(),i=e.touches,o=e.changedTouches,d=a.hasSubs("pickedSurface");null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),0===i.length&&1===o.length&&u>-1&&t-u<150&&(p>-1&&u-p<325?(hh(o[0],r.pickCursorPos),r.schedulePickEntity=!0,r.schedulePickSurface=d,r.update(),r.pickResult?(r.pickResult.touchInput=!0,a.fire("doublePicked",r.pickResult),r.pickedSurface&&a.fire("doublePickedSurface",r.pickResult),s.doublePickFlyTo&&A(r.pickResult)):(a.fire("doublePickedNothing"),s.doublePickFlyTo&&A()),p=-1):h.distVec2(l[0],c)<4&&(hh(o[0],r.pickCursorPos),r.schedulePickEntity=!0,r.schedulePickSurface=d,r.update(),r.pickResult?(r.pickResult.touchInput=!0,a.fire("picked",r.pickResult),r.pickedSurface&&a.fire("pickedSurface",r.pickResult)):a.fire("pickedNothing"),p=t),u=-1),l.length=i.length;for(let e=0,t=i.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:h.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:h.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const s=this.scene;this._controllers={cameraControl:this,pickController:new Ku(this,this._configs),pivotController:new zu(s,this._configs),panController:new Uu(s),cameraFlight:new Iu(this,{duration:.5})},this._handlers=[new oh(this.scene,this._controllers,this._configs,this._states,this._updates),new uh(this.scene,this._controllers,this._configs,this._states,this._updates),new Xu(this.scene,this._controllers,this._configs,this._states,this._updates),new sh(this.scene,this._controllers,this._configs,this._states,this._updates),new nh(this.scene,this._controllers,this._configs,this._states,this._updates),new ph(this.scene,this._controllers,this._configs,this._states,this._updates),new ih(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new ah(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,s={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":s[this.PAN_LEFT]=[t.KEY_A],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_Z],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":s[this.PAN_LEFT]=[t.KEY_Q],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_W],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=s}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const s=this._keyMap[e];if(!s)return!1;t||(t=this.scene.input.keyDown);for(let e=0,n=s.length;e0?vh(t):null,a=s&&s.length>0?vh(s):null,o=e=>{if(!e)return;var t=!0;(a&&a[e.type]||r&&!r[e.type])&&(t=!1),t&&n.push(e.id);const s=e.children;if(s)for(var i=0,l=s.length;i * Copyright (c) 2022 Niklas von Hertzen diff --git a/dist/xeokit-sdk.min.es.js b/dist/xeokit-sdk.min.es.js index f42f3d0fe9..3ac89d6028 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 Ku=null;function Yu(e,t){const s=3*e,n=3*t;let i,r,a,o,l,c;const u=Math.min(i=Ku[s],r=Ku[s+1],a=Ku[s+2]),h=Math.min(o=Ku[n],l=Ku[n+1],c=Ku[n+2]);if(u!==h)return u-h;const p=Math.max(i,r,a),d=Math.max(o,l,c);return p!==d?p-d:0}let Xu=null;function qu(e,t){let s=Xu[2*e]-Xu[2*t];return 0!==s?s:Xu[2*e+1]-Xu[2*t+1]}function Ju(e,t,s=!1){const n=e.positionsCompressed||[],i=function(e,t){const s=new Int32Array(e.length/3);for(let e=0,t=s.length;e>t;s.sort(Yu);const n=new Int32Array(e.length);for(let t=0,i=s.length;te[t+1]){let s=e[t];e[t]=e[t+1],e[t+1]=s}Xu=new Int32Array(e),t.sort(qu);const s=new Int32Array(e.length);for(let n=0,i=t.length;nt){let s=e;e=t,t=s}function s(s,n){return s!==e?e-s:n!==t?t-n:0}let n=0,i=(r.length>>1)-1;for(;n<=i;){const e=i+n>>1,t=s(r[2*e],r[2*e+1]);if(t>0)n=e+1;else{if(!(t<0))return e;i=e-1}}return-n-1}const o=new Int32Array(r.length/2);o.fill(0);const l=n.length/3;if(l>8*(1<p.maxNumPositions&&(p=h()),p.bucketNumber>8)return[e];let A;-1===c[l]&&(c[l]=p.numPositions++,p.positionsCompressed.push(n[3*l]),p.positionsCompressed.push(n[3*l+1]),p.positionsCompressed.push(n[3*l+2])),-1===c[u]&&(c[u]=p.numPositions++,p.positionsCompressed.push(n[3*u]),p.positionsCompressed.push(n[3*u+1]),p.positionsCompressed.push(n[3*u+2])),-1===c[d]&&(c[d]=p.numPositions++,p.positionsCompressed.push(n[3*d]),p.positionsCompressed.push(n[3*d+1]),p.positionsCompressed.push(n[3*d+2])),p.indices.push(c[l]),p.indices.push(c[u]),p.indices.push(c[d]),(A=a(l,u))>=0&&0===o[A]&&(o[A]=1,p.edgeIndices.push(c[r[2*A]]),p.edgeIndices.push(c[r[2*A+1]])),(A=a(l,d))>=0&&0===o[A]&&(o[A]=1,p.edgeIndices.push(c[r[2*A]]),p.edgeIndices.push(c[r[2*A+1]])),(A=a(u,d))>=0&&0===o[A]&&(o[A]=1,p.edgeIndices.push(c[r[2*A]]),p.edgeIndices.push(c[r[2*A+1]]))}const d=t/8*2,A=t/8,f=2*n.length+(i.length+r.length)*d;let I=0,m=-n.length/3;return u.forEach((e=>{I+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*A,m+=e.positionsCompressed.length/3})),I>f?[e]:(s&&function(e,t){const s={},n={};let i=0;e.forEach((e=>{const t=e.indices,r=e.edgeIndices,a=e.positionsCompressed;for(let e=0,n=t.length;e0){const e=t._meshes;for(let t=0,s=e.length;t0){const e=this._meshes;for(let t=0,s=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 Ou({id:"defaultColorTexture",texture:new Ui({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Ou({id:"defaultMetalRoughTexture",texture:new Ui({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),s=new Ou({id:"defaultNormalsTexture",texture:new Ui({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),n=new Ou({id:"defaultEmissiveTexture",texture:new Ui({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new Ou({id:"defaultOcclusionTexture",texture:new Ui({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=s,this._textures.defaultEmissiveTexture=n,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new Bu({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:s,emissiveTexture:n,occlusionTexture:i})}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||ph),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,s=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,s=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,s=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,s=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,s=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,s=new Uint8Array(t.length);for(let e=0,n=t.length;e{l.setImage(c,{minFilter:s,magFilter:n,wrapS:i,wrapT:r,wrapR:a,flipY:e.flipY,encoding:o}),this.glRedraw()},c.src=e.src;break;default:this._textureTranscoder?g.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 Ou({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 s,n,i,r,a;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(s=this._textures[e.colorTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(n=this._textures[e.metallicRoughnessTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(i=this._textures[e.normalsTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(r=this._textures[e.emissiveTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(a=this._textures[e.occlusionTextureId],!a)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else a=this._textures.defaultOcclusionTexture;const o=new Bu({id:t,model:this,colorTexture:s,metallicRoughnessTexture:n,normalsTexture:i,emissiveTexture:r,occlusionTexture:a});return this._textureSets[t]=o,o}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(this.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const s=new rh({id:e.id,model:this,parentTransform:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[s.id]=s,s}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._scheduledMeshes[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&&"points"!==e.primitive)return 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);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||lh,s=e.position||ch,n=e.rotation||uh;d.eulerToQuaternion(n,"XYZ",hh),e.meshMatrix=d.composeMat4(s,hh,t,d.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=ia(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])]):dh,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=d.vec3(),s=[];Y(e.positions,s,t)&&(e.positions=s,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=na(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=d.collapseAABB3();d.expandAABB3Points3(t,e.positionsCompressed),Ut.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=d.collapseAABB3();for(let s=0,n=e.buckets.length;s>24&255,i=s>>16&255,r=s>>8&255,a=255&s;switch(e.pickColor=new Uint8Array([a,r,i,n]),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),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 s=0,n=e.buckets.length;s>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,s=e.origin,n=e.textureSetId||"-",i=e.geometryId,r=`${Math.round(s[0])}.${Math.round(s[1])}.${Math.round(s[2])}.${n}.${i}`;let a=this._vboInstancingLayers[r];if(a)return a;let o=e.textureSet;const l=e.geometry;for(;!a;)switch(l.primitive){case"triangles":case"surface":a=new lo({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0,solid:!1});break;case"solid":a=new lo({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0,solid:!0});break;case"lines":a=new Yo({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0});break;case"points":a=new jl({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0})}return this._vboInstancingLayers[r]=a,this.layerList.push(a),a}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|=J),this._pickable&&!1!==e.pickable&&(t|=$),this._culled&&!1!==e.culled&&(t|=Z),this._clippable&&!1!==e.clippable&&(t|=ee),this._collidable&&!1!==e.collidable&&(t|=te),this._edges&&!1!==e.edges&&(t|=re),this._xrayed&&!1!==e.xrayed&&(t|=se),this._highlighted&&!1!==e.highlighted&&(t|=ne),this._selected&&!1!==e.selected&&(t|=ie),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let s=0,n=e.meshIds.length;se.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,s=this.layerList.length;t0)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 s=0,n=t.visibleLayers.length;s65536?16:8)}else a=[{positionsCompressed:n,indices:i,edgeIndices:r}];return a}class Ih extends x{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;eA.has(e.id)||I.has(e.id)||f.has(e.id))).reduce(((e,s)=>{let n,i=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}(s.colorize);s.xrayed?(n=0===t.xrayMaterial.fillAlpha&&0!==t.xrayMaterial.edgeAlpha?.1:t.xrayMaterial.fillAlpha,n=Math.round(255*n).toString(16).padStart(2,"0"),i=n+i):A.has(s.id)&&(n=Math.round(255*s.opacity).toString(16).padStart(2,"0"),i=n+i),e[i]||(e[i]=[]);const r=s.id,a=s.originalSystemId,o={ifc_guid:a,originating_system:this.originatingSystem};return a!==r&&(o.authoring_tool_id=r),e[i].push(o),e}),{}),y=Object.entries(m).map((([e,t])=>({color:e,components:t})));r.components.coloring=y;const v=t.objectIds,w=t.visibleObjects,g=t.visibleObjectIds,E=v.filter((e=>!w[e])),T=t.selectedObjectIds;return e.defaultInvisible||g.length0&&e.clipping_planes.forEach((function(e){let t=Th(e.location,mh),s=Th(e.direction,mh);c&&d.negateVec3(s),d.subVec3(t,l),i.yUp&&(t=Dh(t),s=Dh(s)),new vi(n,{pos:t,dir:s})})),n.clearLines(),e.lines&&e.lines.length>0){const t=[],s=[];let i=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),s.push(i++),s.push(i++))})),new Ih(n,{positions:t,indices:s,clippable:!1,collidable:!0})}if(n.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){const t=e.bitmap_type||"jpg",s=e.bitmap_data;let r=Th(e.location,yh),a=Th(e.normal,vh),o=Th(e.up,wh),l=e.height||1;t&&s&&r&&a&&o&&(i.yUp&&(r=Dh(r),a=Dh(a),o=Dh(o)),new ir(n,{src:s,type:t,pos:r,normal:a,up:o,clippable:!1,collidable:!0,height:l}))})),o&&(n.setObjectsXRayed(n.xrayedObjectIds,!1),n.setObjectsHighlighted(n.highlightedObjectIds,!1),n.setObjectsSelected(n.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(n.setObjectsVisible(n.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!1))))):(n.setObjectsVisible(n.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!0)))));const i=e.components.visibility.view_setup_hints;i&&(!1===i.spaces_visible&&n.setObjectsVisible(s.metaScene.getObjectIDsByType("IfcSpace"),!0),void 0!==i.spaces_translucent&&n.setObjectsXRayed(s.metaScene.getObjectIDsByType("IfcSpace"),!0),i.space_boundaries_visible,!1===i.openings_visible&&n.setObjectsVisible(s.metaScene.getObjectIDsByType("IfcOpening"),!0),i.space_boundaries_translucent,void 0!==i.openings_translucent&&n.setObjectsXRayed(s.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(n.setObjectsSelected(n.selectedObjectIds,!1),e.components.selection.forEach((e=>this._withBCFComponent(t,e,(e=>e.selected=!0))))),e.components.translucency&&(n.setObjectsXRayed(n.xrayedObjectIds,!1),e.components.translucency.forEach((e=>this._withBCFComponent(t,e,(e=>e.xrayed=!0))))),e.components.coloring&&e.components.coloring.forEach((e=>{let s=e.color,n=0,i=!1;8===s.length&&(n=parseInt(s.substring(0,2),16)/256,n<=1&&n>=.95&&(n=1),s=s.substring(2),i=!0);const r=[parseInt(s.substring(0,2),16)/256,parseInt(s.substring(2,4),16)/256,parseInt(s.substring(4,6),16)/256];e.components.map((e=>this._withBCFComponent(t,e,(e=>{e.colorize=r,i&&(e.opacity=n)}))))}))}if(e.perspective_camera||e.orthogonal_camera){let o,c,u,h;if(e.perspective_camera?(o=Th(e.perspective_camera.camera_view_point,mh),c=Th(e.perspective_camera.camera_direction,mh),u=Th(e.perspective_camera.camera_up_vector,mh),i.perspective.fov=e.perspective_camera.field_of_view,h="perspective"):(o=Th(e.orthogonal_camera.camera_view_point,mh),c=Th(e.orthogonal_camera.camera_direction,mh),u=Th(e.orthogonal_camera.camera_up_vector,mh),i.ortho.scale=e.orthogonal_camera.view_to_world_scale,h="ortho"),d.subVec3(o,l),i.yUp&&(o=Dh(o),c=Dh(c),u=Dh(u)),r){const e=n.pick({pickSurface:!0,origin:o,direction:c});c=e?e.worldPos:d.addVec3(o,c,mh)}else c=d.addVec3(o,c,mh);a?(i.eye=o,i.look=c,i.up=u,i.projection=h):s.cameraFlight.flyTo({eye:o,look:c,up:u,duration:t.duration,projection:h})}}_withBCFComponent(e,t,s){const n=this.viewer,i=n.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){const r=t.authoring_tool_id,a=i.objects[r];if(a)return void s(a);if(e.updateCompositeObjects){if(n.metaScene.metaObjects[r])return void i.withObjects(n.metaScene.getObjectIDsInSubtree(r),s)}}if(t.ifc_guid){const r=t.ifc_guid,a=i.objects[r];if(a)return void s(a);if(e.updateCompositeObjects){if(n.metaScene.metaObjects[r])return void i.withObjects(n.metaScene.getObjectIDsInSubtree(r),s)}Object.keys(i.models).forEach((t=>{const a=d.globalizeObjectId(t,r),o=i.objects[a];if(o)s(o);else if(e.updateCompositeObjects){n.metaScene.metaObjects[a]&&i.withObjects(n.metaScene.getObjectIDsInSubtree(a),s)}}))}}destroy(){super.destroy()}}function Eh(e){return{x:e[0],y:e[1],z:e[2]}}function Th(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 Dh(e){return new Float64Array([e[0],e[2],-e[1]])}const Ph=d.vec3(),Ch=(e,t,s,n)=>{var i=e-s,r=t-n;return Math.sqrt(i*i+r*r)};class _h extends x{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 s=this.plugin.viewer.scene;this._originMarker=new he(s,t.origin),this._targetMarker=new he(s,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 n=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,c=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new de(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._targetDot=new de(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._lengthWire=new pe(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._xAxisWire=new pe(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._yAxisWire=new pe(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._zAxisWire=new pe(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._lengthLabel=new Ae(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._xAxisLabel=new Ae(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._yAxisLabel=new Ae(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._zAxisLabel=new Ae(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,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=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=s.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=s.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=s.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=s.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._wp))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],s=this._targetMarker.viewPos[2];if(t>-.3||s>-.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 n=this._pp,i=this._cp,r=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var a=r.top-t.top,o=r.left-t.left,l=e.canvas.boundary,c=l[2],u=l[3],h=0;const s=this.plugin.viewer.scene.metrics,f=s.scale,I=s.units,m=s.unitsInfo[I].abbrev;for(var p=0,A=n.length;p{const t=e.snappedCanvasPos||e.canvasPos;if(i=!0,r.set(e.worldPos),a.set(e.canvasPos),0===this._mouseState){const s=n.getBoundingClientRect(),i=window.pageXOffset||document.documentElement.scrollLeft,r=window.pageYOffset||document.documentElement.scrollTop,a=s.left+i,o=s.top+r;this._markerDiv.style.marginLeft=a+t[0]-5+"px",this._markerDiv.style.marginTop=o+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"),c=e.entity}else this._markerDiv.style.marginLeft="-10000px",this._markerDiv.style.marginTop="-10000px";n.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=r.slice(),this._markerDiv.style.marginLeft="-10000px",this._markerDiv.style.marginTop="-10000px")})),n.addEventListener("mousedown",this._onMouseDown=e=>{1===e.which&&(o=e.clientX,l=e.clientY)}),n.addEventListener("mouseup",this._onMouseUp=t=>{1===t.which&&(t.clientX>o+20||t.clientXl+20||t.clientY{this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos),i=!1,this._markerDiv.style.marginLeft="-100px",this._markerDiv.style.marginTop="-100px",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.axisVisible=!1),n.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 Oh extends Q{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 Bh(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,s=e.target,n=new _h(this,{id:e.id,plugin:this,container:this._container,origin:{entity:t.entity,worldPos:t.worldPos},target:{entity:s.entity,worldPos:s.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[n.id]=n,n.on("destroyed",(()=>{delete this._measurements[n.id]})),this.fire("measurementCreated",n),n}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,s]of Object.entries(this.measurements))s.labelShown=e}setAxisVisible(e){for(const[t,s]of Object.entries(this.measurements))s.axisVisible=e;this.defaultAxisVisible=e}getAxisVisible(){return this.defaultAxisVisible}clear(){const e=Object.keys(this._measurements);for(var t=0,s=e.length;t{s=1e3*this._delayBeforeRestoreSeconds,n||(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=1,n=!0)};this._onCanvasBoundary=e.scene.canvas.on("boundary",i),this._onCameraMatrix=e.scene.camera.on("matrix",i),this._onSceneTick=e.scene.on("tick",(t=>{n&&(s-=t.deltaTime,(!this._delayBeforeRestore||s<=0)&&(e.scene.canvas.resolutionScale=1,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),n=!1))}));let r=!1;this._onSceneMouseDown=e.scene.input.on("mousedown",(()=>{r=!0})),this._onSceneMouseUp=e.scene.input.on("mouseup",(()=>{r=!1})),this._onSceneMouseMove=e.scene.input.on("mousemove",(()=>{r&&i()}))}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 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 Nh{constructor(){}getMetaModel(e,t,s){g.loadJSON(e,(e=>{t(e)}),(function(e){s(e)}))}getGLTF(e,t,s){g.loadArraybuffer(e,(e=>{t(e)}),(function(e){s(e)}))}getGLB(e,t,s){g.loadArraybuffer(e,(e=>{t(e)}),(function(e){s(e)}))}getArrayBuffer(e,t,s,n){!function(e,t,s,n){var i=()=>{};s=s||i,n=n||i;const r=/^data:(.*?)(;base64)?,(.*)$/,a=t.match(r);if(a){const e=!!a[2];var o=a[3];o=window.decodeURIComponent(o),e&&(o=window.atob(o));try{const e=new ArrayBuffer(o.length),t=new Uint8Array(e);for(var l=0;l{s(e)}),(function(e){n(e)}))}}class xh{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 s=this._messages[this._locale];if(!s)return null;const n=Lh(e,s);return n?t?Mh(n,t):n:null}translatePlurals(e,t,s){const n=this._messages[this._locale];if(!n)return null;let i=Lh(e,n);return i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one,i?(i=Mh(i,[t]),s&&(i=Mh(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const r=this._events[t];return void 0!==r&&s(r),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function Lh(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&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 s=e-t,n=e+t;s<0&&(s=0),n>1&&(n=1);var i=this.getPoint(s),r=this.getPoint(n),a=d.subVec3(r,i,[]);return d.normalizeVec3(a,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_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,s,n=[],i=this.getPoint(0),r=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),r+=d.lenVec3(d.subVec3(t,i,[])),n.push(r),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,r=n.length;s=t||e*n[r-1];for(var a,o=0,l=r-1;o<=l;)if((a=n[i=Math.floor(o+(l-o)/2)]-s)<0)o=i+1;else{if(!(a>0)){l=i;break}l=i-1}if(n[i=l]===s)return i/(r-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(r-1)}}class Hh extends Fh{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 s=(t.length-1)*e,n=Math.floor(s),i=s-n,r=t[0===n?n:n-1],a=t[n],o=t[n>t.length-2?t.length-1:n+1],l=t[n>t.length-3?t.length-1:n+2],c=d.vec3();return c[0]=d.catmullRomInterpolate(r[0],a[0],o[0],l[0],i),c[1]=d.catmullRomInterpolate(r[1],a[1],o[1],l[1],i),c[2]=d.catmullRomInterpolate(r[2],a[2],o[2],l[2],i),c}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 Uh=d.vec3();class Gh extends x{get type(){return"CameraPath"}constructor(e,t={}){super(e,t),this._frames=[],this._eyeCurve=new Hh(this),this._lookCurve=new Hh(this),this._upCurve=new Hh(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,s,n){const i={t:e,eye:t.slice(0),look:s.slice(0),up:n.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}addFrames(e){let t;for(let s=0,n=e.length;s1?1:e,t.eye=this._eyeCurve.getPoint(e,Uh),t.look=this._lookCurve.getPoint(e,Uh),t.up=this._upCurve.getPoint(e,Uh)}sampleFrame(e,t,s,n){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,s),this._upCurve.getPoint(e,n)}smoothFrameTimes(e){if(0===this._frames.length)return;const t=d.vec3();var s=0;this._frames[0].t=0;const n=[];for(let e=1,r=this._frames.length;e=1;e>1&&(e=1);const s=this.easing?zh._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(d.subVec3(n.eye,n.look,Wh),n.eye=d.lerpVec3(s,0,1,this._eye1,this._eye2,kh),n.look=d.subVec3(kh,Wh,Vh)):this._flyingLook&&(n.look=d.lerpVec3(s,0,1,this._look1,this._look2,Vh),n.up=d.lerpVec3(s,0,1,this._up1,this._up2,Qh)):this._flyingEyeLookUp&&(n.eye=d.lerpVec3(s,0,1,this._eye1,this._eye2,kh),n.look=d.lerpVec3(s,0,1,this._look1,this._look2,Vh),n.up=d.lerpVec3(s,0,1,this._up1,this._up2,Qh)),this._projection2){const t="ortho"===this._projection2?zh._easeOutExpo(e,0,1,1):zh._easeInCubic(e,0,1,1);n.customProjection.matrix=d.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();B.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+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 Kh extends x{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new zh(this),this._t=0,this.state=Kh.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,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case Kh.SCRUBBING:return;case Kh.PLAYING:if(this._t+=this._playingRate*i,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=Kh.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case Kh.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=Kh.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(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=Kh.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=Kh.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=Kh.SCRUBBING,this._cameraFlightAnimation.flyTo(n,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=Kh.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=Kh.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=Kh.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}Kh.STOPPED=0,Kh.SCRUBBING=1,Kh.PLAYING=2,Kh.PLAYING_TO=3;const Yh=d.vec3(),Xh=d.vec3();d.vec3();const qh=d.vec3([0,-1,0]),Jh=d.vec4([0,0,0,1]);class Zh extends x{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 Wi(this),this._plane=new pi(this,{geometry:new Vt(this,sr({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Kt(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 pi(this,{geometry:new Vt(this,tr({size:1,divisions:10})),material:new Kt(this,{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:t.clippable}),this._node=new Ri(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]),K(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,s=[-this._dir[0],-this._dir[1],-this._dir[2]];d.subVec3(t,this.position,Yh);const n=-d.dotVec3(s,Yh);d.normalizeVec3(s),d.mulVec3Scalar(s,n,Xh),d.vec3PairToQuaternion(qh,e,Jh),this._node.quaternion=Jh}}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],s=this._imageSize[1];if(t>s){const n=s/t;this._node.scale=[e,1,e*n]}else{const n=t/s;this._node.scale=[e*n,1,e]}}}class $h extends _t{get type(){return"PointLight"}constructor(e,t={}){super(e,t);const s=this;this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const n=this.scene.camera,i=this.scene.canvas;this._onCameraViewMatrix=n.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=n.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=i.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new at({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(s._shadowViewMatrixDirty){s._shadowViewMatrix||(s._shadowViewMatrix=d.identityMat4());const e=s._state.pos,t=n.look,i=n.up;d.lookAtMat4v(e,t,i,s._shadowViewMatrix),s._shadowViewMatrixDirty=!1}return s._shadowViewMatrix},getShadowProjMatrix:()=>{if(s._shadowProjMatrixDirty){s._shadowProjMatrix||(s._shadowProjMatrix=d.identityMat4());const e=s.scene.canvas.canvas;d.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,s._shadowProjMatrix),s._shadowProjMatrixDirty=!1}return s._shadowProjMatrix},getShadowRenderBuf:()=>(s._shadowRenderBuf||(s._shadowRenderBuf=new et(s.scene.canvas.canvas,s.scene.canvas.gl,{size:[1024,1024]})),s._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 ep(e){if(!tp(e.width)||!tp(e.height)){const t=document.createElement("canvas");t.width=sp(e.width),t.height=sp(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function tp(e){return 0==(e&e-1)}function sp(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class np extends x{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new at({texture:new Ui({gl:s,target:s.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,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let r=0;r{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],s=this._imageSize[1],n=s/t;this._geometry.positions=t>s?[e,e*n,0,-e,e*n,0,-e,-e*n,0,e,-e*n,0]:[e/n,e,0,-e/n,e,0,-e/n,-e,0,e/n,-e,0]}}class op{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,s=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:s.fov,fovAxis:s.fovAxis,near:s.near,far:s.far};break;case"ortho":this._projection={projection:"ortho",scale:s.scale,near:s.near,far:s.far};break;case"frustum":this._projection={projection:"frustum",left:s.left,right:s.right,top:s.top,bottom:s.bottom,near:s.near,far:s.far};break;case"custom":this._projection={projection:"custom",matrix:s.matrix.slice()}}}restoreCamera(e,t){const s=e.camera,n=this._projection;function i(){switch(n.type){case"perspective":s.perspective.fov=n.fov,s.perspective.fovAxis=n.fovAxis,s.perspective.near=n.near,s.perspective.far=n.far;break;case"ortho":s.ortho.scale=n.scale,s.ortho.near=n.near,s.ortho.far=n.far;break;case"frustum":s.frustum.left=n.left,s.frustum.right=n.right,s.frustum.top=n.top,s.frustum.bottom=n.bottom,s.frustum.near=n.near,s.frustum.far=n.far;break;case"custom":s.customProjection.matrix=n.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:n.scale,projection:n.projection},(()=>{i(),t()})):(s.eye=this._eye,s.look=this._look,s.up=this._up,i(),s.projection=n.projection)}}const lp=d.vec3();class cp{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,s){this.numObjects=0,this._mask=s?g.apply(s,{}):null;const n=!s||s.visible,i=!s||s.edges,r=!s||s.xrayed,a=!s||s.highlighted,o=!s||s.selected,l=!s||s.clippable,c=!s||s.pickable,u=!s||s.colorize,h=!s||s.opacity,p=t.metaObjects,d=e.objects;for(let e=0,t=p.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 dp extends Fh{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,s,n;for(e=e||[],s=0,n=this._curves.length;s1?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,s=e*this.length,n=this._getCurveLengths(),i=0;i=s){var r=1-(n[i]-s)/(t=this._curves[i]).length;return t.getPointAt(r)}i++}return null}_getCurveLengths(){if(!this._dirty)return this._cachedLengths;var e,t=[],s=0,n=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 fp extends Ah{constructor(e,t={}){super(e,t)}}class Ip extends x{constructor(e,t={}){super(e,t),this._skyboxMesh=new pi(this,{geometry:new Vt(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 Kt(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Wi(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 mp{transcode(e,t,s={}){}destroy(){}}const yp=d.vec4(),vp=d.vec4(),wp=d.vec3(),gp=d.vec3(),Ep=d.vec3(),Tp=d.vec4(),bp=d.vec4(),Dp=d.vec4();class Pp{constructor(e){this._scene=e}dollyToCanvasPos(e,t,s){let n=!1;const i=this._scene.camera;if(e){const t=d.subVec3(e,i.eye,wp);n=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 s=d.distVec3(t,e);let n=Math.tan(Math.PI/500)*s*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(n/=this._scene.camera.ortho.scale/2),K(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Xi(this._scene,fi({radius:n})),this._pivotSphere=new pi(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 s=t.boundary,n=s[2],i=s[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*n/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);let r=t._lastBoundingClientRect;if(!r||t._canvasSizeChanged){const e=t.canvas;r=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(r.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(r.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(K(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 Kt(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 s=this.getPivotPos();this._cameraOffset[2]+=d.distVec3(e.eye,s),t=d.inverseMat4(t);const n=d.transformVec3(t,this._cameraOffset),i=d.vec3();if(d.subVec3(e.eye,s,i),d.addVec3(i,n),e.zUp){const e=i[1];i[1]=i[2],i[2]=e}this._radius=d.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=d.normalizeVec3(d.subVec3(e.look,e.eye,Cp)),s=d.cross3Vec3(t,e.worldUp,_p);return d.sqLenVec3(s)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,s=Math.abs(d.distVec3(this._scene.center,t.eye)),n=t.project.transposedMatrix,i=n.subarray(8,12),r=n.subarray(12),a=[0,0,-1,1],o=d.dotVec4(a,i)/d.dotVec4(a,r),l=Bp;t.project.unproject(e,o,Op,Sp,l);const c=d.normalizeVec3(d.subVec3(l,t.eye,Cp)),u=d.addVec3(t.eye,d.mulVec3Scalar(c,s,_p),Rp);this.setPivotPos(u)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const s=this._scene.camera;var n=-e;const i=-t;1===s.worldUp[2]&&(n=-n),this._azimuth+=.01*-n,this._polar+=.01*i,this._polar=d.clamp(this._polar,.001,Math.PI-.001);const r=[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===s.worldUp[2]){const e=r[1];r[1]=r[2],r[2]=e}const a=d.lenVec3(d.subVec3(s.look,s.eye,d.vec3())),o=this.getPivotPos();d.addVec3(r,o);let l=d.lookAtMat4v(r,o,s.worldUp);l=d.inverseMat4(l);const c=d.transformVec3(l,this._cameraOffset);l[12]-=c[0],l[13]-=c[1],l[14]-=c[2];const u=[l[8],l[9],l[10]];s.eye=[l[12],l[13],l[14]],d.subVec3(s.eye,d.mulVec3Scalar(u,a),s.look),s.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 xp{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 Se;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 Lp=d.vec2();class Mp{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController;let a,o,l,c=0,u=0,h=0,p=0,A=!1;const f=d.vec3();let I=!0;const m=this._scene.canvas.canvas,y=[];function v(e=!0){m.style.cursor="move",c=n.pointerCanvasPos[0],u=n.pointerCanvasPos[1],h=n.pointerCanvasPos[0],p=n.pointerCanvasPos[1],e&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),r.picked&&r.pickedSurface&&r.pickResult&&r.pickResult.worldPos?(A=!0,f.set(r.pickResult.worldPos)):A=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;y[n]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;y[n]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:y[e.input.KEY_SHIFT]||s.planView?(a=!0,v()):(a=!0,v(!1));break;case 2:o=!0,v();break;case 3:l=!0,s.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=()=>{if(!s.active||!s.pointerEnabled)return;if(!a&&!o&&!l)return;const t=e.canvas.boundary,r=t[2],h=t[3],p=n.pointerCanvasPos[0],I=n.pointerCanvasPos[1];if(y[e.input.KEY_SHIFT]||s.planView||!s.panRightClick&&o||s.panRightClick&&l){const t=p-c,s=I-u,n=e.camera;if("perspective"===n.projection){const r=Math.abs(A?d.lenVec3(d.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=1.5*t*r/h,i.panDeltaY+=1.5*s*r/h}else i.panDeltaX+=.5*n.ortho.scale*(t/h),i.panDeltaY+=.5*n.ortho.scale*(s/h)}else!a||o||l||s.planView||(s.firstPerson?(i.rotateDeltaY-=(p-c)/r*s.dragRotationRate/2,i.rotateDeltaX+=(I-u)/h*(s.dragRotationRate/4)):(i.rotateDeltaY-=(p-c)/r*(1.5*s.dragRotationRate),i.rotateDeltaX+=(I-u)/h*(1.5*s.dragRotationRate)));c=p,u=I}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{s.active&&s.pointerEnabled&&n.mouseover&&(I=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(s.active&&s.pointerEnabled)switch(e.which){case 1:case 2:case 3:a=!1,o=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(s.active&&s.pointerEnabled){if(3===e.which){!function(e,t){if(e){let s=e.target,n=0,i=0,r=0,a=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,r+=s.scrollLeft,a+=s.scrollTop,s=s.offsetParent;t[0]=e.pageX+r-n,t[1]=e.pageY+a-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Lp);const s=Lp[0],n=Lp[1];Math.abs(s-h)<3&&Math.abs(n-p)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Lp,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{s.active&&s.pointerEnabled});const w=1/60;let g=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=performance.now()/1e3;var r=null!==g?t-g:0;g=t,r>.05&&(r=.05),r{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const a=i._isKeyDownForAction(i.AXIS_VIEW_RIGHT),o=i._isKeyDownForAction(i.AXIS_VIEW_BACK),l=i._isKeyDownForAction(i.AXIS_VIEW_LEFT),c=i._isKeyDownForAction(i.AXIS_VIEW_FRONT),u=i._isKeyDownForAction(i.AXIS_VIEW_TOP),h=i._isKeyDownForAction(i.AXIS_VIEW_BOTTOM);if(!(a||o||l||c||u||h))return;const p=e.aabb,A=d.getAABB3Diag(p);d.getAABB3Center(p,Fp);const f=Math.abs(A/Math.tan(t.cameraFlight.fitFOV*d.DEGTORAD)),I=1.1*A;Vp.orthoScale=I,a?(Vp.eye.set(d.addVec3(Fp,d.mulVec3Scalar(r.worldRight,f,Hp),jp)),Vp.look.set(Fp),Vp.up.set(r.worldUp)):o?(Vp.eye.set(d.addVec3(Fp,d.mulVec3Scalar(r.worldForward,f,Hp),jp)),Vp.look.set(Fp),Vp.up.set(r.worldUp)):l?(Vp.eye.set(d.addVec3(Fp,d.mulVec3Scalar(r.worldRight,-f,Hp),jp)),Vp.look.set(Fp),Vp.up.set(r.worldUp)):c?(Vp.eye.set(d.addVec3(Fp,d.mulVec3Scalar(r.worldForward,-f,Hp),jp)),Vp.look.set(Fp),Vp.up.set(r.worldUp)):u?(Vp.eye.set(d.addVec3(Fp,d.mulVec3Scalar(r.worldUp,f,Hp),jp)),Vp.look.set(Fp),Vp.up.set(d.normalizeVec3(d.mulVec3Scalar(r.worldForward,1,Up),Gp))):h&&(Vp.eye.set(d.addVec3(Fp,d.mulVec3Scalar(r.worldUp,-f,Hp),jp)),Vp.look.set(Fp),Vp.up.set(d.normalizeVec3(d.mulVec3Scalar(r.worldForward,-1,Up)))),!s.firstPerson&&s.followPointer&&t.pivotController.setPivotPos(Fp),t.cameraFlight.duration>0?t.cameraFlight.flyTo(Vp,(()=>{t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(Vp),t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class Qp{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.pivotController,o=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,c=!1;const u=this._scene.canvas.canvas,h=s=>{let n;s&&s.worldPos&&(n=s.worldPos);const i=s&&s.entity?s.entity.aabb:e.aabb;if(n){const s=e.camera;d.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})},p=e.tickify(this._canvasMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(l||c)return;const i=o.hasSubs("hover"),a=o.hasSubs("hoverEnter"),u=o.hasSubs("hoverOut"),h=o.hasSubs("hoverOff"),p=o.hasSubs("hoverSurface"),d=o.hasSubs("hoverSnapOrSurface");if(i||a||u||h||p||d)if(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=!0,r.schedulePickSurface=p,r.scheduleSnapOrPick=d,r.update(),r.pickResult){if(r.pickResult.entity){const t=r.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),o.fire("hoverEnter",r.pickResult,!0),this._lastPickedEntityId=t)}o.fire("hover",r.pickResult,!0),(r.pickResult.worldPos||r.pickResult.snappedWorldPos)&&o.fire("hoverSurface",r.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),o.fire("hoverOff",{canvasPos:r.pickCursorPos},!0)});u.addEventListener("mousemove",p),u.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(c=!0);if(1===t.which&&s.active&&s.pointerEnabled&&(n.mouseDownClientX=t.clientX,n.mouseDownClientY=t.clientY,n.mouseDownCursorX=n.pointerCanvasPos[0],n.mouseDownCursorY=n.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),1===t.which))){const t=r.pickResult;t&&t.worldPos?(a.setPivotPos(t.worldPos),a.startPivot()):(s.smartPivot?a.setCanvasPivotPos(n.pointerCanvasPos):a.setPivotPos(e.camera.look),a.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(c=!1),a.getPivoting()&&a.endPivot()}),u.addEventListener("mouseup",this._canvasMouseUpHandler=i=>{if(!s.active||!s.pointerEnabled)return;if(!(1===i.which))return;if(a.hidePivot(),Math.abs(i.clientX-n.mouseDownClientX)>3||Math.abs(i.clientY-n.mouseDownClientY)>3)return;const l=o.hasSubs("picked"),c=o.hasSubs("pickedNothing"),u=o.hasSubs("pickedSurface"),p=o.hasSubs("doublePicked"),A=o.hasSubs("doublePickedSurface"),f=o.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||p||A||f))return(l||c||u)&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=!0,r.schedulePickSurface=u,r.update(),r.pickResult?(o.fire("picked",r.pickResult,!0),r.pickedSurface&&o.fire("pickedSurface",r.pickResult,!0)):o.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=s.doublePickFlyTo,r.schedulePickSurface=u,r.update();const e=r.pickResult,i=r.pickedSurface;this._timeout=setTimeout((()=>{e?(o.fire("picked",e,!0),i&&(o.fire("pickedSurface",e,!0),!s.firstPerson&&s.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):o.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0),this._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=s.doublePickFlyTo||p||A,r.schedulePickSurface=r.schedulePickEntity&&A,r.update(),r.pickResult){if(o.fire("doublePicked",r.pickResult,!0),r.pickedSurface&&o.fire("doublePickedSurface",r.pickResult,!0),s.doublePickFlyTo&&(h(r.pickResult),!s.firstPerson&&s.followPointer)){const e=r.pickResult.entity.aabb,s=d.getAABB3Center(e);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(o.fire("doublePickedNothing",{canvasPos:n.pointerCanvasPos},!0),s.doublePickFlyTo&&(h(),!s.firstPerson&&s.followPointer)){const s=e.aabb,n=d.getAABB3Center(s);t.pivotController.setPivotPos(n),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 Wp{constructor(e,t,s,n,i){this._scene=e;const r=e.input,a=[],o=e.canvas.canvas;let l=!0;this._onSceneMouseMove=r.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=r.on("keydown",(t=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&n.mouseover&&(a[t]=!0,t===r.KEY_SHIFT&&(o.style.cursor="move"))})),this._onSceneKeyUp=r.on("keyup",(n=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(a[n]=!1,n===r.KEY_SHIFT&&(o.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(o=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const c=t.cameraControl,u=o.deltaTime/1e3;if(!s.planView){const e=c._isKeyDownForAction(c.ROTATE_Y_POS,a),n=c._isKeyDownForAction(c.ROTATE_Y_NEG,a),r=c._isKeyDownForAction(c.ROTATE_X_POS,a),o=c._isKeyDownForAction(c.ROTATE_X_NEG,a),l=u*s.keyboardRotationRate;(e||n||r||o)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),e?i.rotateDeltaY+=l:n&&(i.rotateDeltaY-=l),r?i.rotateDeltaX+=l:o&&(i.rotateDeltaX-=l),!s.firstPerson&&s.followPointer&&t.pivotController.startPivot())}if(!a[r.KEY_CTRL]&&!a[r.KEY_ALT]){const e=c._isKeyDownForAction(c.DOLLY_BACKWARDS,a),r=c._isKeyDownForAction(c.DOLLY_FORWARDS,a);if(e||r){const a=u*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),r?i.dollyDelta-=a:e&&(i.dollyDelta+=a),l&&(n.followPointerDirty=!0,l=!1)}}const h=c._isKeyDownForAction(c.PAN_FORWARDS,a),p=c._isKeyDownForAction(c.PAN_BACKWARDS,a),d=c._isKeyDownForAction(c.PAN_LEFT,a),A=c._isKeyDownForAction(c.PAN_RIGHT,a),f=c._isKeyDownForAction(c.PAN_UP,a),I=c._isKeyDownForAction(c.PAN_DOWN,a),m=(a[r.KEY_ALT]?.3:1)*u*s.keyboardPanRate;(h||p||d||A||f||I)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),I?i.panDeltaY+=m:f&&(i.panDeltaY+=-m),A?i.panDeltaX+=-m:d&&(i.panDeltaX+=m),p?i.panDeltaZ+=m:h&&(i.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 zp=d.vec3();class Kp{constructor(e,t,s,n,i){this._scene=e;const r=e.camera,a=t.pickController,o=t.pivotController,l=t.panController;let c=1,u=1,h=null;this._onTick=e.on("tick",(()=>{if(!s.active||!s.pointerEnabled)return;let t="default";if(Math.abs(i.dollyDelta)<.001&&(i.dollyDelta=0),Math.abs(i.rotateDeltaX)<.001&&(i.rotateDeltaX=0),Math.abs(i.rotateDeltaY)<.001&&(i.rotateDeltaY=0),0===i.rotateDeltaX&&0===i.rotateDeltaY||(i.dollyDelta=0),s.followPointer&&--c<=0&&(c=1,0!==i.dollyDelta)){if(0===i.rotateDeltaY&&0===i.rotateDeltaX&&s.followPointer&&n.followPointerDirty&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.pickResult&&a.pickResult.worldPos?h=a.pickResult.worldPos:(u=1,h=null),n.followPointerDirty=!1),h){const t=Math.abs(d.lenVec3(d.subVec3(h,e.camera.eye,zp)));u=t/s.dollyProximityThreshold}u{n.mouseover=!0}),r.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{n.mouseover=!1,r.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{Xp(e,r,n.pointerCanvasPos)}),r.addEventListener("mousedown",this._mouseDownHandler=e=>{s.active&&s.pointerEnabled&&(Xp(e,r,n.pointerCanvasPos),n.mouseover=!0)}),r.addEventListener("mouseup",this._mouseUpHandler=e=>{s.active&&s.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 Xp(e,t,s){if(e){const{x:n,y:i}=t.getBoundingClientRect();s[0]=e.clientX-n,s[1]=e.clientY-i}else e=window.event,s[0]=e.x,s[1]=e.y;return s}const qp=function(e,t){if(e){let s=e.target,n=0,i=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,s=s.offsetParent;t[0]=e.pageX-n,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class Jp{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.pivotController,o=d.vec2(),l=d.vec2(),c=d.vec2(),u=d.vec2(),h=[],p=this._scene.canvas.canvas;let A=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),p.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!s.active||!s.pointerEnabled)return;t.preventDefault();const i=t.touches,l=t.changedTouches;for(n.touchStartTime=Date.now(),1===i.length&&1===l.length&&(qp(i[0],o),s.followPointer&&(r.pickCursorPos=o,r.schedulePickSurface=!0,r.update(),s.planView||(r.picked&&r.pickedSurface&&r.pickResult&&r.pickResult.worldPos?(a.setPivotPos(r.pickResult.worldPos),!s.firstPerson&&a.startPivot()&&a.showPivot()):(s.smartPivot?a.setCanvasPivotPos(n.pointerCanvasPos):a.setPivotPos(e.camera.look),!s.firstPerson&&a.startPivot()&&a.showPivot()))));h.length{a.getPivoting()&&a.endPivot()}),p.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const a=e.canvas.boundary,o=a[2],p=a[3],I=t.touches;if(t.touches.length===A){if(1===A){qp(I[0],l),d.subVec2(l,h[0],u);const t=u[0],r=u[1];if(null!==n.longTouchTimeout&&(Math.abs(t)>s.longTapRadius||Math.abs(r)>s.longTapRadius)&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),s.planView){const n=e.camera;if("perspective"===n.projection){const a=Math.abs(e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=t*a/p*s.touchPanRate,i.panDeltaY+=r*a/p*s.touchPanRate}else i.panDeltaX+=.5*n.ortho.scale*(t/p)*s.touchPanRate,i.panDeltaY+=.5*n.ortho.scale*(r/p)*s.touchPanRate}else i.rotateDeltaY-=t/o*(1*s.dragRotationRate),i.rotateDeltaX+=r/p*(1.5*s.dragRotationRate)}else if(2===A){const t=I[0],a=I[1];qp(t,l),qp(a,c);const o=d.geometricMeanVec2(h[0],h[1]),u=d.geometricMeanVec2(l,c),A=d.vec2();d.subVec2(o,u,A);const f=A[0],m=A[1],y=e.camera,v=d.distVec2([t.pageX,t.pageY],[a.pageX,a.pageY]),w=(d.distVec2(h[0],h[1])-v)*s.touchDollyRate;if(i.dollyDelta=w,Math.abs(w)<1)if("perspective"===y.projection){const t=r.pickResult?r.pickResult.worldPos:e.center,n=Math.abs(d.lenVec3(d.subVec3(t,e.camera.eye,[])))*Math.tan(y.perspective.fov/2*Math.PI/180);i.panDeltaX-=f*n/p*s.touchPanRate,i.panDeltaY-=m*n/p*s.touchPanRate}else i.panDeltaX-=.5*y.ortho.scale*(f/p)*s.touchPanRate,i.panDeltaY-=.5*y.ortho.scale*(m/p)*s.touchPanRate;n.pointerCanvasPos=u}for(let e=0;e{let n;s&&s.worldPos&&(n=s.worldPos);const i=s?s.entity.aabb:e.aabb;if(n){const s=e.camera;d.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};p.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!s.active||!s.pointerEnabled)return;null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null);const i=e.touches,r=e.changedTouches;if(o=Date.now(),1===i.length&&1===r.length){u=o,Zp(i[0],c);const r=c[0],a=c[1],l=i[0].pageX,h=i[0].pageY;n.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(h)],canvasPos:[Math.round(r),Math.round(a)],event:e},!0),n.longTouchTimeout=null}),s.longTapTimeout)}else u=-1;for(;l.length{if(!s.active||!s.pointerEnabled)return;const t=Date.now(),i=e.touches,o=e.changedTouches,p=a.hasSubs("pickedSurface");null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),0===i.length&&1===o.length&&u>-1&&t-u<150&&(h>-1&&u-h<325?(Zp(o[0],r.pickCursorPos),r.schedulePickEntity=!0,r.schedulePickSurface=p,r.update(),r.pickResult?(r.pickResult.touchInput=!0,a.fire("doublePicked",r.pickResult),r.pickedSurface&&a.fire("doublePickedSurface",r.pickResult),s.doublePickFlyTo&&A(r.pickResult)):(a.fire("doublePickedNothing"),s.doublePickFlyTo&&A()),h=-1):d.distVec2(l[0],c)<4&&(Zp(o[0],r.pickCursorPos),r.schedulePickEntity=!0,r.schedulePickSurface=p,r.update(),r.pickResult?(r.pickResult.touchInput=!0,a.fire("picked",r.pickResult),r.pickedSurface&&a.fire("pickedSurface",r.pickResult)):a.fire("pickedNothing"),h=t),u=-1),l.length=i.length;for(let e=0,t=i.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 s=this.scene;this._controllers={cameraControl:this,pickController:new xp(this,this._configs),pivotController:new Np(s,this._configs),panController:new Pp(s),cameraFlight:new zh(this,{duration:.5})},this._handlers=[new Yp(this.scene,this._controllers,this._configs,this._states,this._updates),new Jp(this.scene,this._controllers,this._configs,this._states,this._updates),new Mp(this.scene,this._controllers,this._configs,this._states,this._updates),new kp(this.scene,this._controllers,this._configs,this._states,this._updates),new Qp(this.scene,this._controllers,this._configs,this._states,this._updates),new $p(this.scene,this._controllers,this._configs,this._states,this._updates),new Wp(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new Kp(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",g.isString(e)){const t=this.scene.input,s={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":s[this.PAN_LEFT]=[t.KEY_A],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_Z],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":s[this.PAN_LEFT]=[t.KEY_Q],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_W],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=s}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const s=this._keyMap[e];if(!s)return!1;t||(t=this.scene.input.keyDown);for(let e=0,n=s.length;e0?ad(t):null,a=s&&s.length>0?ad(s):null,o=e=>{if(!e)return;var t=!0;(a&&a[e.type]||r&&!r[e.type])&&(t=!1),t&&n.push(e.id);const s=e.children;if(s)for(var i=0,l=s.length;i>t;s.sort(Yu);const n=new Int32Array(e.length);for(let t=0,i=s.length;te[t+1]){let s=e[t];e[t]=e[t+1],e[t+1]=s}Xu=new Int32Array(e),t.sort(qu);const s=new Int32Array(e.length);for(let n=0,i=t.length;nt){let s=e;e=t,t=s}function s(s,n){return s!==e?e-s:n!==t?t-n:0}let n=0,i=(r.length>>1)-1;for(;n<=i;){const e=i+n>>1,t=s(r[2*e],r[2*e+1]);if(t>0)n=e+1;else{if(!(t<0))return e;i=e-1}}return-n-1}const o=new Int32Array(r.length/2);o.fill(0);const l=n.length/3;if(l>8*(1<p.maxNumPositions&&(p=h()),p.bucketNumber>8)return[e];let A;-1===c[l]&&(c[l]=p.numPositions++,p.positionsCompressed.push(n[3*l]),p.positionsCompressed.push(n[3*l+1]),p.positionsCompressed.push(n[3*l+2])),-1===c[u]&&(c[u]=p.numPositions++,p.positionsCompressed.push(n[3*u]),p.positionsCompressed.push(n[3*u+1]),p.positionsCompressed.push(n[3*u+2])),-1===c[d]&&(c[d]=p.numPositions++,p.positionsCompressed.push(n[3*d]),p.positionsCompressed.push(n[3*d+1]),p.positionsCompressed.push(n[3*d+2])),p.indices.push(c[l]),p.indices.push(c[u]),p.indices.push(c[d]),(A=a(l,u))>=0&&0===o[A]&&(o[A]=1,p.edgeIndices.push(c[r[2*A]]),p.edgeIndices.push(c[r[2*A+1]])),(A=a(l,d))>=0&&0===o[A]&&(o[A]=1,p.edgeIndices.push(c[r[2*A]]),p.edgeIndices.push(c[r[2*A+1]])),(A=a(u,d))>=0&&0===o[A]&&(o[A]=1,p.edgeIndices.push(c[r[2*A]]),p.edgeIndices.push(c[r[2*A+1]]))}const d=t/8*2,A=t/8,f=2*n.length+(i.length+r.length)*d;let I=0,m=-n.length/3;return u.forEach((e=>{I+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*A,m+=e.positionsCompressed.length/3})),I>f?[e]:(s&&function(e,t){const s={},n={};let i=0;e.forEach((e=>{const t=e.indices,r=e.edgeIndices,a=e.positionsCompressed;for(let e=0,n=t.length;e0){const e=t._meshes;for(let t=0,s=e.length;t0){const e=this._meshes;for(let t=0,s=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 Ou({id:"defaultColorTexture",texture:new Ui({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Ou({id:"defaultMetalRoughTexture",texture:new Ui({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),s=new Ou({id:"defaultNormalsTexture",texture:new Ui({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),n=new Ou({id:"defaultEmissiveTexture",texture:new Ui({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new Ou({id:"defaultOcclusionTexture",texture:new Ui({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=s,this._textures.defaultEmissiveTexture=n,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new Bu({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:s,emissiveTexture:n,occlusionTexture:i})}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||ph),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,s=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,s=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,s=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,s=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,s=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,s=new Uint8Array(t.length);for(let e=0,n=t.length;e{l.setImage(c,{minFilter:s,magFilter:n,wrapS:i,wrapT:r,wrapR:a,flipY:e.flipY,encoding:o}),this.glRedraw()},c.src=e.src;break;default:this._textureTranscoder?g.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 Ou({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 s,n,i,r,a;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(s=this._textures[e.colorTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(n=this._textures[e.metallicRoughnessTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(i=this._textures[e.normalsTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(r=this._textures[e.emissiveTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(a=this._textures[e.occlusionTextureId],!a)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else a=this._textures.defaultOcclusionTexture;const o=new Bu({id:t,model:this,colorTexture:s,metallicRoughnessTexture:n,normalsTexture:i,emissiveTexture:r,occlusionTexture:a});return this._textureSets[t]=o,o}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(this.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const s=new rh({id:e.id,model:this,parentTransform:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[s.id]=s,s}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._scheduledMeshes[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&&"points"!==e.primitive)return 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||lh,s=e.position||ch,n=e.rotation||uh;d.eulerToQuaternion(n,"XYZ",hh),e.meshMatrix=d.composeMat4(s,hh,t,d.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=ia(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])]):dh,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=d.vec3(),s=[];Y(e.positions,s,t)&&(e.positions=s,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=na(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=d.collapseAABB3();d.expandAABB3Points3(t,e.positionsCompressed),Ut.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=d.collapseAABB3();for(let s=0,n=e.buckets.length;s>24&255,i=s>>16&255,r=s>>8&255,a=255&s;switch(e.pickColor=new Uint8Array([a,r,i,n]),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),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 s=0,n=e.buckets.length;s>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,s=e.origin,n=e.textureSetId||"-",i=e.geometryId,r=`${Math.round(s[0])}.${Math.round(s[1])}.${Math.round(s[2])}.${n}.${i}`;let a=this._vboInstancingLayers[r];if(a)return a;let o=e.textureSet;const l=e.geometry;for(;!a;)switch(l.primitive){case"triangles":case"surface":a=new lo({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0,solid:!1});break;case"solid":a=new lo({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0,solid:!0});break;case"lines":a=new Yo({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0});break;case"points":a=new jl({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0})}return this._vboInstancingLayers[r]=a,this.layerList.push(a),a}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|=J),this._pickable&&!1!==e.pickable&&(t|=$),this._culled&&!1!==e.culled&&(t|=Z),this._clippable&&!1!==e.clippable&&(t|=ee),this._collidable&&!1!==e.collidable&&(t|=te),this._edges&&!1!==e.edges&&(t|=re),this._xrayed&&!1!==e.xrayed&&(t|=se),this._highlighted&&!1!==e.highlighted&&(t|=ne),this._selected&&!1!==e.selected&&(t|=ie),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let s=0,n=e.meshIds.length;se.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,s=this.layerList.length;t0)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 s=0,n=t.visibleLayers.length;s65536?16:8)}else a=[{positionsCompressed:n,indices:i,edgeIndices:r}];return a}class Ih extends x{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;eA.has(e.id)||I.has(e.id)||f.has(e.id))).reduce(((e,s)=>{let n,i=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}(s.colorize);s.xrayed?(n=0===t.xrayMaterial.fillAlpha&&0!==t.xrayMaterial.edgeAlpha?.1:t.xrayMaterial.fillAlpha,n=Math.round(255*n).toString(16).padStart(2,"0"),i=n+i):A.has(s.id)&&(n=Math.round(255*s.opacity).toString(16).padStart(2,"0"),i=n+i),e[i]||(e[i]=[]);const r=s.id,a=s.originalSystemId,o={ifc_guid:a,originating_system:this.originatingSystem};return a!==r&&(o.authoring_tool_id=r),e[i].push(o),e}),{}),y=Object.entries(m).map((([e,t])=>({color:e,components:t})));r.components.coloring=y;const v=t.objectIds,w=t.visibleObjects,g=t.visibleObjectIds,E=v.filter((e=>!w[e])),T=t.selectedObjectIds;return e.defaultInvisible||g.length0&&e.clipping_planes.forEach((function(e){let t=Th(e.location,mh),s=Th(e.direction,mh);c&&d.negateVec3(s),d.subVec3(t,l),i.yUp&&(t=Dh(t),s=Dh(s)),new vi(n,{pos:t,dir:s})})),n.clearLines(),e.lines&&e.lines.length>0){const t=[],s=[];let i=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),s.push(i++),s.push(i++))})),new Ih(n,{positions:t,indices:s,clippable:!1,collidable:!0})}if(n.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){const t=e.bitmap_type||"jpg",s=e.bitmap_data;let r=Th(e.location,yh),a=Th(e.normal,vh),o=Th(e.up,wh),l=e.height||1;t&&s&&r&&a&&o&&(i.yUp&&(r=Dh(r),a=Dh(a),o=Dh(o)),new ir(n,{src:s,type:t,pos:r,normal:a,up:o,clippable:!1,collidable:!0,height:l}))})),o&&(n.setObjectsXRayed(n.xrayedObjectIds,!1),n.setObjectsHighlighted(n.highlightedObjectIds,!1),n.setObjectsSelected(n.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(n.setObjectsVisible(n.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!1))))):(n.setObjectsVisible(n.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!0)))));const i=e.components.visibility.view_setup_hints;i&&(!1===i.spaces_visible&&n.setObjectsVisible(s.metaScene.getObjectIDsByType("IfcSpace"),!0),void 0!==i.spaces_translucent&&n.setObjectsXRayed(s.metaScene.getObjectIDsByType("IfcSpace"),!0),i.space_boundaries_visible,!1===i.openings_visible&&n.setObjectsVisible(s.metaScene.getObjectIDsByType("IfcOpening"),!0),i.space_boundaries_translucent,void 0!==i.openings_translucent&&n.setObjectsXRayed(s.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(n.setObjectsSelected(n.selectedObjectIds,!1),e.components.selection.forEach((e=>this._withBCFComponent(t,e,(e=>e.selected=!0))))),e.components.translucency&&(n.setObjectsXRayed(n.xrayedObjectIds,!1),e.components.translucency.forEach((e=>this._withBCFComponent(t,e,(e=>e.xrayed=!0))))),e.components.coloring&&e.components.coloring.forEach((e=>{let s=e.color,n=0,i=!1;8===s.length&&(n=parseInt(s.substring(0,2),16)/256,n<=1&&n>=.95&&(n=1),s=s.substring(2),i=!0);const r=[parseInt(s.substring(0,2),16)/256,parseInt(s.substring(2,4),16)/256,parseInt(s.substring(4,6),16)/256];e.components.map((e=>this._withBCFComponent(t,e,(e=>{e.colorize=r,i&&(e.opacity=n)}))))}))}if(e.perspective_camera||e.orthogonal_camera){let o,c,u,h;if(e.perspective_camera?(o=Th(e.perspective_camera.camera_view_point,mh),c=Th(e.perspective_camera.camera_direction,mh),u=Th(e.perspective_camera.camera_up_vector,mh),i.perspective.fov=e.perspective_camera.field_of_view,h="perspective"):(o=Th(e.orthogonal_camera.camera_view_point,mh),c=Th(e.orthogonal_camera.camera_direction,mh),u=Th(e.orthogonal_camera.camera_up_vector,mh),i.ortho.scale=e.orthogonal_camera.view_to_world_scale,h="ortho"),d.subVec3(o,l),i.yUp&&(o=Dh(o),c=Dh(c),u=Dh(u)),r){const e=n.pick({pickSurface:!0,origin:o,direction:c});c=e?e.worldPos:d.addVec3(o,c,mh)}else c=d.addVec3(o,c,mh);a?(i.eye=o,i.look=c,i.up=u,i.projection=h):s.cameraFlight.flyTo({eye:o,look:c,up:u,duration:t.duration,projection:h})}}_withBCFComponent(e,t,s){const n=this.viewer,i=n.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){const r=t.authoring_tool_id,a=i.objects[r];if(a)return void s(a);if(e.updateCompositeObjects){if(n.metaScene.metaObjects[r])return void i.withObjects(n.metaScene.getObjectIDsInSubtree(r),s)}}if(t.ifc_guid){const r=t.ifc_guid,a=i.objects[r];if(a)return void s(a);if(e.updateCompositeObjects){if(n.metaScene.metaObjects[r])return void i.withObjects(n.metaScene.getObjectIDsInSubtree(r),s)}Object.keys(i.models).forEach((t=>{const a=d.globalizeObjectId(t,r),o=i.objects[a];if(o)s(o);else if(e.updateCompositeObjects){n.metaScene.metaObjects[a]&&i.withObjects(n.metaScene.getObjectIDsInSubtree(a),s)}}))}}destroy(){super.destroy()}}function Eh(e){return{x:e[0],y:e[1],z:e[2]}}function Th(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 Dh(e){return new Float64Array([e[0],e[2],-e[1]])}const Ph=d.vec3(),Ch=(e,t,s,n)=>{var i=e-s,r=t-n;return Math.sqrt(i*i+r*r)};class _h extends x{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 s=this.plugin.viewer.scene;this._originMarker=new he(s,t.origin),this._targetMarker=new he(s,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 n=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,c=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new de(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._targetDot=new de(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._lengthWire=new pe(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._xAxisWire=new pe(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._yAxisWire=new pe(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._zAxisWire=new pe(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._lengthLabel=new Ae(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._xAxisLabel=new Ae(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._yAxisLabel=new Ae(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._zAxisLabel=new Ae(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,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=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=s.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=s.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=s.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=s.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._wp))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],s=this._targetMarker.viewPos[2];if(t>-.3||s>-.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 n=this._pp,i=this._cp,r=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var a=r.top-t.top,o=r.left-t.left,l=e.canvas.boundary,c=l[2],u=l[3],h=0;const s=this.plugin.viewer.scene.metrics,f=s.scale,I=s.units,m=s.unitsInfo[I].abbrev;for(var p=0,A=n.length;p{const t=e.snappedCanvasPos||e.canvasPos;if(i=!0,r.set(e.worldPos),a.set(e.canvasPos),0===this._mouseState){const s=n.getBoundingClientRect(),i=window.pageXOffset||document.documentElement.scrollLeft,r=window.pageYOffset||document.documentElement.scrollTop,a=s.left+i,o=s.top+r;this._markerDiv.style.marginLeft=a+t[0]-5+"px",this._markerDiv.style.marginTop=o+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"),c=e.entity}else this._markerDiv.style.marginLeft="-10000px",this._markerDiv.style.marginTop="-10000px";n.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=r.slice(),this._markerDiv.style.marginLeft="-10000px",this._markerDiv.style.marginTop="-10000px")})),n.addEventListener("mousedown",this._onMouseDown=e=>{1===e.which&&(o=e.clientX,l=e.clientY)}),n.addEventListener("mouseup",this._onMouseUp=t=>{1===t.which&&(t.clientX>o+20||t.clientXl+20||t.clientY{this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos),i=!1,this._markerDiv.style.marginLeft="-100px",this._markerDiv.style.marginTop="-100px",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.axisVisible=!1),n.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 Oh extends Q{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 Bh(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,s=e.target,n=new _h(this,{id:e.id,plugin:this,container:this._container,origin:{entity:t.entity,worldPos:t.worldPos},target:{entity:s.entity,worldPos:s.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[n.id]=n,n.on("destroyed",(()=>{delete this._measurements[n.id]})),this.fire("measurementCreated",n),n}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,s]of Object.entries(this.measurements))s.labelShown=e}setAxisVisible(e){for(const[t,s]of Object.entries(this.measurements))s.axisVisible=e;this.defaultAxisVisible=e}getAxisVisible(){return this.defaultAxisVisible}clear(){const e=Object.keys(this._measurements);for(var t=0,s=e.length;t{s=1e3*this._delayBeforeRestoreSeconds,n||(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=1,n=!0)};this._onCanvasBoundary=e.scene.canvas.on("boundary",i),this._onCameraMatrix=e.scene.camera.on("matrix",i),this._onSceneTick=e.scene.on("tick",(t=>{n&&(s-=t.deltaTime,(!this._delayBeforeRestore||s<=0)&&(e.scene.canvas.resolutionScale=1,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),n=!1))}));let r=!1;this._onSceneMouseDown=e.scene.input.on("mousedown",(()=>{r=!0})),this._onSceneMouseUp=e.scene.input.on("mouseup",(()=>{r=!1})),this._onSceneMouseMove=e.scene.input.on("mousemove",(()=>{r&&i()}))}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 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 Nh{constructor(){}getMetaModel(e,t,s){g.loadJSON(e,(e=>{t(e)}),(function(e){s(e)}))}getGLTF(e,t,s){g.loadArraybuffer(e,(e=>{t(e)}),(function(e){s(e)}))}getGLB(e,t,s){g.loadArraybuffer(e,(e=>{t(e)}),(function(e){s(e)}))}getArrayBuffer(e,t,s,n){!function(e,t,s,n){var i=()=>{};s=s||i,n=n||i;const r=/^data:(.*?)(;base64)?,(.*)$/,a=t.match(r);if(a){const e=!!a[2];var o=a[3];o=window.decodeURIComponent(o),e&&(o=window.atob(o));try{const e=new ArrayBuffer(o.length),t=new Uint8Array(e);for(var l=0;l{s(e)}),(function(e){n(e)}))}}class xh{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 s=this._messages[this._locale];if(!s)return null;const n=Lh(e,s);return n?t?Mh(n,t):n:null}translatePlurals(e,t,s){const n=this._messages[this._locale];if(!n)return null;let i=Lh(e,n);return i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one,i?(i=Mh(i,[t]),s&&(i=Mh(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const r=this._events[t];return void 0!==r&&s(r),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function Lh(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&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 s=e-t,n=e+t;s<0&&(s=0),n>1&&(n=1);var i=this.getPoint(s),r=this.getPoint(n),a=d.subVec3(r,i,[]);return d.normalizeVec3(a,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_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,s,n=[],i=this.getPoint(0),r=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),r+=d.lenVec3(d.subVec3(t,i,[])),n.push(r),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,r=n.length;s=t||e*n[r-1];for(var a,o=0,l=r-1;o<=l;)if((a=n[i=Math.floor(o+(l-o)/2)]-s)<0)o=i+1;else{if(!(a>0)){l=i;break}l=i-1}if(n[i=l]===s)return i/(r-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(r-1)}}class Hh extends Fh{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 s=(t.length-1)*e,n=Math.floor(s),i=s-n,r=t[0===n?n:n-1],a=t[n],o=t[n>t.length-2?t.length-1:n+1],l=t[n>t.length-3?t.length-1:n+2],c=d.vec3();return c[0]=d.catmullRomInterpolate(r[0],a[0],o[0],l[0],i),c[1]=d.catmullRomInterpolate(r[1],a[1],o[1],l[1],i),c[2]=d.catmullRomInterpolate(r[2],a[2],o[2],l[2],i),c}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 Uh=d.vec3();class Gh extends x{get type(){return"CameraPath"}constructor(e,t={}){super(e,t),this._frames=[],this._eyeCurve=new Hh(this),this._lookCurve=new Hh(this),this._upCurve=new Hh(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,s,n){const i={t:e,eye:t.slice(0),look:s.slice(0),up:n.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}addFrames(e){let t;for(let s=0,n=e.length;s1?1:e,t.eye=this._eyeCurve.getPoint(e,Uh),t.look=this._lookCurve.getPoint(e,Uh),t.up=this._upCurve.getPoint(e,Uh)}sampleFrame(e,t,s,n){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,s),this._upCurve.getPoint(e,n)}smoothFrameTimes(e){if(0===this._frames.length)return;const t=d.vec3();var s=0;this._frames[0].t=0;const n=[];for(let e=1,r=this._frames.length;e=1;e>1&&(e=1);const s=this.easing?zh._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(d.subVec3(n.eye,n.look,Wh),n.eye=d.lerpVec3(s,0,1,this._eye1,this._eye2,kh),n.look=d.subVec3(kh,Wh,Vh)):this._flyingLook&&(n.look=d.lerpVec3(s,0,1,this._look1,this._look2,Vh),n.up=d.lerpVec3(s,0,1,this._up1,this._up2,Qh)):this._flyingEyeLookUp&&(n.eye=d.lerpVec3(s,0,1,this._eye1,this._eye2,kh),n.look=d.lerpVec3(s,0,1,this._look1,this._look2,Vh),n.up=d.lerpVec3(s,0,1,this._up1,this._up2,Qh)),this._projection2){const t="ortho"===this._projection2?zh._easeOutExpo(e,0,1,1):zh._easeInCubic(e,0,1,1);n.customProjection.matrix=d.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();B.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+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 Kh extends x{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new zh(this),this._t=0,this.state=Kh.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,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case Kh.SCRUBBING:return;case Kh.PLAYING:if(this._t+=this._playingRate*i,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=Kh.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case Kh.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=Kh.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(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=Kh.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=Kh.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=Kh.SCRUBBING,this._cameraFlightAnimation.flyTo(n,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=Kh.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=Kh.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=Kh.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}Kh.STOPPED=0,Kh.SCRUBBING=1,Kh.PLAYING=2,Kh.PLAYING_TO=3;const Yh=d.vec3(),Xh=d.vec3();d.vec3();const qh=d.vec3([0,-1,0]),Jh=d.vec4([0,0,0,1]);class Zh extends x{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 Wi(this),this._plane=new pi(this,{geometry:new Vt(this,sr({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Kt(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 pi(this,{geometry:new Vt(this,tr({size:1,divisions:10})),material:new Kt(this,{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:t.clippable}),this._node=new Ri(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]),K(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,s=[-this._dir[0],-this._dir[1],-this._dir[2]];d.subVec3(t,this.position,Yh);const n=-d.dotVec3(s,Yh);d.normalizeVec3(s),d.mulVec3Scalar(s,n,Xh),d.vec3PairToQuaternion(qh,e,Jh),this._node.quaternion=Jh}}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],s=this._imageSize[1];if(t>s){const n=s/t;this._node.scale=[e,1,e*n]}else{const n=t/s;this._node.scale=[e*n,1,e]}}}class $h extends _t{get type(){return"PointLight"}constructor(e,t={}){super(e,t);const s=this;this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const n=this.scene.camera,i=this.scene.canvas;this._onCameraViewMatrix=n.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=n.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=i.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new at({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(s._shadowViewMatrixDirty){s._shadowViewMatrix||(s._shadowViewMatrix=d.identityMat4());const e=s._state.pos,t=n.look,i=n.up;d.lookAtMat4v(e,t,i,s._shadowViewMatrix),s._shadowViewMatrixDirty=!1}return s._shadowViewMatrix},getShadowProjMatrix:()=>{if(s._shadowProjMatrixDirty){s._shadowProjMatrix||(s._shadowProjMatrix=d.identityMat4());const e=s.scene.canvas.canvas;d.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,s._shadowProjMatrix),s._shadowProjMatrixDirty=!1}return s._shadowProjMatrix},getShadowRenderBuf:()=>(s._shadowRenderBuf||(s._shadowRenderBuf=new et(s.scene.canvas.canvas,s.scene.canvas.gl,{size:[1024,1024]})),s._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 ep(e){if(!tp(e.width)||!tp(e.height)){const t=document.createElement("canvas");t.width=sp(e.width),t.height=sp(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function tp(e){return 0==(e&e-1)}function sp(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class np extends x{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new at({texture:new Ui({gl:s,target:s.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,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let r=0;r{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],s=this._imageSize[1],n=s/t;this._geometry.positions=t>s?[e,e*n,0,-e,e*n,0,-e,-e*n,0,e,-e*n,0]:[e/n,e,0,-e/n,e,0,-e/n,-e,0,e/n,-e,0]}}class op{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,s=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:s.fov,fovAxis:s.fovAxis,near:s.near,far:s.far};break;case"ortho":this._projection={projection:"ortho",scale:s.scale,near:s.near,far:s.far};break;case"frustum":this._projection={projection:"frustum",left:s.left,right:s.right,top:s.top,bottom:s.bottom,near:s.near,far:s.far};break;case"custom":this._projection={projection:"custom",matrix:s.matrix.slice()}}}restoreCamera(e,t){const s=e.camera,n=this._projection;function i(){switch(n.type){case"perspective":s.perspective.fov=n.fov,s.perspective.fovAxis=n.fovAxis,s.perspective.near=n.near,s.perspective.far=n.far;break;case"ortho":s.ortho.scale=n.scale,s.ortho.near=n.near,s.ortho.far=n.far;break;case"frustum":s.frustum.left=n.left,s.frustum.right=n.right,s.frustum.top=n.top,s.frustum.bottom=n.bottom,s.frustum.near=n.near,s.frustum.far=n.far;break;case"custom":s.customProjection.matrix=n.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:n.scale,projection:n.projection},(()=>{i(),t()})):(s.eye=this._eye,s.look=this._look,s.up=this._up,i(),s.projection=n.projection)}}const lp=d.vec3();class cp{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,s){this.numObjects=0,this._mask=s?g.apply(s,{}):null;const n=!s||s.visible,i=!s||s.edges,r=!s||s.xrayed,a=!s||s.highlighted,o=!s||s.selected,l=!s||s.clippable,c=!s||s.pickable,u=!s||s.colorize,h=!s||s.opacity,p=t.metaObjects,d=e.objects;for(let e=0,t=p.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 dp extends Fh{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,s,n;for(e=e||[],s=0,n=this._curves.length;s1?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,s=e*this.length,n=this._getCurveLengths(),i=0;i=s){var r=1-(n[i]-s)/(t=this._curves[i]).length;return t.getPointAt(r)}i++}return null}_getCurveLengths(){if(!this._dirty)return this._cachedLengths;var e,t=[],s=0,n=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 fp extends Ah{constructor(e,t={}){super(e,t)}}class Ip extends x{constructor(e,t={}){super(e,t),this._skyboxMesh=new pi(this,{geometry:new Vt(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 Kt(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Wi(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 mp{transcode(e,t,s={}){}destroy(){}}const yp=d.vec4(),vp=d.vec4(),wp=d.vec3(),gp=d.vec3(),Ep=d.vec3(),Tp=d.vec4(),bp=d.vec4(),Dp=d.vec4();class Pp{constructor(e){this._scene=e}dollyToCanvasPos(e,t,s){let n=!1;const i=this._scene.camera;if(e){const t=d.subVec3(e,i.eye,wp);n=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 s=d.distVec3(t,e);let n=Math.tan(Math.PI/500)*s*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(n/=this._scene.camera.ortho.scale/2),K(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Xi(this._scene,fi({radius:n})),this._pivotSphere=new pi(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 s=t.boundary,n=s[2],i=s[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*n/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);let r=t._lastBoundingClientRect;if(!r||t._canvasSizeChanged){const e=t.canvas;r=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(r.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(r.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(K(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 Kt(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 s=this.getPivotPos();this._cameraOffset[2]+=d.distVec3(e.eye,s),t=d.inverseMat4(t);const n=d.transformVec3(t,this._cameraOffset),i=d.vec3();if(d.subVec3(e.eye,s,i),d.addVec3(i,n),e.zUp){const e=i[1];i[1]=i[2],i[2]=e}this._radius=d.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=d.normalizeVec3(d.subVec3(e.look,e.eye,Cp)),s=d.cross3Vec3(t,e.worldUp,_p);return d.sqLenVec3(s)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,s=Math.abs(d.distVec3(this._scene.center,t.eye)),n=t.project.transposedMatrix,i=n.subarray(8,12),r=n.subarray(12),a=[0,0,-1,1],o=d.dotVec4(a,i)/d.dotVec4(a,r),l=Bp;t.project.unproject(e,o,Op,Sp,l);const c=d.normalizeVec3(d.subVec3(l,t.eye,Cp)),u=d.addVec3(t.eye,d.mulVec3Scalar(c,s,_p),Rp);this.setPivotPos(u)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const s=this._scene.camera;var n=-e;const i=-t;1===s.worldUp[2]&&(n=-n),this._azimuth+=.01*-n,this._polar+=.01*i,this._polar=d.clamp(this._polar,.001,Math.PI-.001);const r=[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===s.worldUp[2]){const e=r[1];r[1]=r[2],r[2]=e}const a=d.lenVec3(d.subVec3(s.look,s.eye,d.vec3())),o=this.getPivotPos();d.addVec3(r,o);let l=d.lookAtMat4v(r,o,s.worldUp);l=d.inverseMat4(l);const c=d.transformVec3(l,this._cameraOffset);l[12]-=c[0],l[13]-=c[1],l[14]-=c[2];const u=[l[8],l[9],l[10]];s.eye=[l[12],l[13],l[14]],d.subVec3(s.eye,d.mulVec3Scalar(u,a),s.look),s.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 xp{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 Se;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 Lp=d.vec2();class Mp{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController;let a,o,l,c=0,u=0,h=0,p=0,A=!1;const f=d.vec3();let I=!0;const m=this._scene.canvas.canvas,y=[];function v(e=!0){m.style.cursor="move",c=n.pointerCanvasPos[0],u=n.pointerCanvasPos[1],h=n.pointerCanvasPos[0],p=n.pointerCanvasPos[1],e&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),r.picked&&r.pickedSurface&&r.pickResult&&r.pickResult.worldPos?(A=!0,f.set(r.pickResult.worldPos)):A=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;y[n]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;y[n]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:y[e.input.KEY_SHIFT]||s.planView?(a=!0,v()):(a=!0,v(!1));break;case 2:o=!0,v();break;case 3:l=!0,s.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=()=>{if(!s.active||!s.pointerEnabled)return;if(!a&&!o&&!l)return;const t=e.canvas.boundary,r=t[2],h=t[3],p=n.pointerCanvasPos[0],I=n.pointerCanvasPos[1];if(y[e.input.KEY_SHIFT]||s.planView||!s.panRightClick&&o||s.panRightClick&&l){const t=p-c,s=I-u,n=e.camera;if("perspective"===n.projection){const r=Math.abs(A?d.lenVec3(d.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=1.5*t*r/h,i.panDeltaY+=1.5*s*r/h}else i.panDeltaX+=.5*n.ortho.scale*(t/h),i.panDeltaY+=.5*n.ortho.scale*(s/h)}else!a||o||l||s.planView||(s.firstPerson?(i.rotateDeltaY-=(p-c)/r*s.dragRotationRate/2,i.rotateDeltaX+=(I-u)/h*(s.dragRotationRate/4)):(i.rotateDeltaY-=(p-c)/r*(1.5*s.dragRotationRate),i.rotateDeltaX+=(I-u)/h*(1.5*s.dragRotationRate)));c=p,u=I}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{s.active&&s.pointerEnabled&&n.mouseover&&(I=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(s.active&&s.pointerEnabled)switch(e.which){case 1:case 2:case 3:a=!1,o=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(s.active&&s.pointerEnabled){if(3===e.which){!function(e,t){if(e){let s=e.target,n=0,i=0,r=0,a=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,r+=s.scrollLeft,a+=s.scrollTop,s=s.offsetParent;t[0]=e.pageX+r-n,t[1]=e.pageY+a-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Lp);const s=Lp[0],n=Lp[1];Math.abs(s-h)<3&&Math.abs(n-p)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Lp,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{s.active&&s.pointerEnabled});const w=1/60;let g=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=performance.now()/1e3;var r=null!==g?t-g:0;g=t,r>.05&&(r=.05),r{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const a=i._isKeyDownForAction(i.AXIS_VIEW_RIGHT),o=i._isKeyDownForAction(i.AXIS_VIEW_BACK),l=i._isKeyDownForAction(i.AXIS_VIEW_LEFT),c=i._isKeyDownForAction(i.AXIS_VIEW_FRONT),u=i._isKeyDownForAction(i.AXIS_VIEW_TOP),h=i._isKeyDownForAction(i.AXIS_VIEW_BOTTOM);if(!(a||o||l||c||u||h))return;const p=e.aabb,A=d.getAABB3Diag(p);d.getAABB3Center(p,Fp);const f=Math.abs(A/Math.tan(t.cameraFlight.fitFOV*d.DEGTORAD)),I=1.1*A;Vp.orthoScale=I,a?(Vp.eye.set(d.addVec3(Fp,d.mulVec3Scalar(r.worldRight,f,Hp),jp)),Vp.look.set(Fp),Vp.up.set(r.worldUp)):o?(Vp.eye.set(d.addVec3(Fp,d.mulVec3Scalar(r.worldForward,f,Hp),jp)),Vp.look.set(Fp),Vp.up.set(r.worldUp)):l?(Vp.eye.set(d.addVec3(Fp,d.mulVec3Scalar(r.worldRight,-f,Hp),jp)),Vp.look.set(Fp),Vp.up.set(r.worldUp)):c?(Vp.eye.set(d.addVec3(Fp,d.mulVec3Scalar(r.worldForward,-f,Hp),jp)),Vp.look.set(Fp),Vp.up.set(r.worldUp)):u?(Vp.eye.set(d.addVec3(Fp,d.mulVec3Scalar(r.worldUp,f,Hp),jp)),Vp.look.set(Fp),Vp.up.set(d.normalizeVec3(d.mulVec3Scalar(r.worldForward,1,Up),Gp))):h&&(Vp.eye.set(d.addVec3(Fp,d.mulVec3Scalar(r.worldUp,-f,Hp),jp)),Vp.look.set(Fp),Vp.up.set(d.normalizeVec3(d.mulVec3Scalar(r.worldForward,-1,Up)))),!s.firstPerson&&s.followPointer&&t.pivotController.setPivotPos(Fp),t.cameraFlight.duration>0?t.cameraFlight.flyTo(Vp,(()=>{t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(Vp),t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class Qp{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.pivotController,o=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,c=!1;const u=this._scene.canvas.canvas,h=s=>{let n;s&&s.worldPos&&(n=s.worldPos);const i=s&&s.entity?s.entity.aabb:e.aabb;if(n){const s=e.camera;d.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})},p=e.tickify(this._canvasMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(l||c)return;const i=o.hasSubs("hover"),a=o.hasSubs("hoverEnter"),u=o.hasSubs("hoverOut"),h=o.hasSubs("hoverOff"),p=o.hasSubs("hoverSurface"),d=o.hasSubs("hoverSnapOrSurface");if(i||a||u||h||p||d)if(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=!0,r.schedulePickSurface=p,r.scheduleSnapOrPick=d,r.update(),r.pickResult){if(r.pickResult.entity){const t=r.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),o.fire("hoverEnter",r.pickResult,!0),this._lastPickedEntityId=t)}o.fire("hover",r.pickResult,!0),(r.pickResult.worldPos||r.pickResult.snappedWorldPos)&&o.fire("hoverSurface",r.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),o.fire("hoverOff",{canvasPos:r.pickCursorPos},!0)});u.addEventListener("mousemove",p),u.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(c=!0);if(1===t.which&&s.active&&s.pointerEnabled&&(n.mouseDownClientX=t.clientX,n.mouseDownClientY=t.clientY,n.mouseDownCursorX=n.pointerCanvasPos[0],n.mouseDownCursorY=n.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),1===t.which))){const t=r.pickResult;t&&t.worldPos?(a.setPivotPos(t.worldPos),a.startPivot()):(s.smartPivot?a.setCanvasPivotPos(n.pointerCanvasPos):a.setPivotPos(e.camera.look),a.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(c=!1),a.getPivoting()&&a.endPivot()}),u.addEventListener("mouseup",this._canvasMouseUpHandler=i=>{if(!s.active||!s.pointerEnabled)return;if(!(1===i.which))return;if(a.hidePivot(),Math.abs(i.clientX-n.mouseDownClientX)>3||Math.abs(i.clientY-n.mouseDownClientY)>3)return;const l=o.hasSubs("picked"),c=o.hasSubs("pickedNothing"),u=o.hasSubs("pickedSurface"),p=o.hasSubs("doublePicked"),A=o.hasSubs("doublePickedSurface"),f=o.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||p||A||f))return(l||c||u)&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=!0,r.schedulePickSurface=u,r.update(),r.pickResult?(o.fire("picked",r.pickResult,!0),r.pickedSurface&&o.fire("pickedSurface",r.pickResult,!0)):o.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=s.doublePickFlyTo,r.schedulePickSurface=u,r.update();const e=r.pickResult,i=r.pickedSurface;this._timeout=setTimeout((()=>{e?(o.fire("picked",e,!0),i&&(o.fire("pickedSurface",e,!0),!s.firstPerson&&s.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):o.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0),this._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=s.doublePickFlyTo||p||A,r.schedulePickSurface=r.schedulePickEntity&&A,r.update(),r.pickResult){if(o.fire("doublePicked",r.pickResult,!0),r.pickedSurface&&o.fire("doublePickedSurface",r.pickResult,!0),s.doublePickFlyTo&&(h(r.pickResult),!s.firstPerson&&s.followPointer)){const e=r.pickResult.entity.aabb,s=d.getAABB3Center(e);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(o.fire("doublePickedNothing",{canvasPos:n.pointerCanvasPos},!0),s.doublePickFlyTo&&(h(),!s.firstPerson&&s.followPointer)){const s=e.aabb,n=d.getAABB3Center(s);t.pivotController.setPivotPos(n),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 Wp{constructor(e,t,s,n,i){this._scene=e;const r=e.input,a=[],o=e.canvas.canvas;let l=!0;this._onSceneMouseMove=r.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=r.on("keydown",(t=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&n.mouseover&&(a[t]=!0,t===r.KEY_SHIFT&&(o.style.cursor="move"))})),this._onSceneKeyUp=r.on("keyup",(n=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(a[n]=!1,n===r.KEY_SHIFT&&(o.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(o=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const c=t.cameraControl,u=o.deltaTime/1e3;if(!s.planView){const e=c._isKeyDownForAction(c.ROTATE_Y_POS,a),n=c._isKeyDownForAction(c.ROTATE_Y_NEG,a),r=c._isKeyDownForAction(c.ROTATE_X_POS,a),o=c._isKeyDownForAction(c.ROTATE_X_NEG,a),l=u*s.keyboardRotationRate;(e||n||r||o)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),e?i.rotateDeltaY+=l:n&&(i.rotateDeltaY-=l),r?i.rotateDeltaX+=l:o&&(i.rotateDeltaX-=l),!s.firstPerson&&s.followPointer&&t.pivotController.startPivot())}if(!a[r.KEY_CTRL]&&!a[r.KEY_ALT]){const e=c._isKeyDownForAction(c.DOLLY_BACKWARDS,a),r=c._isKeyDownForAction(c.DOLLY_FORWARDS,a);if(e||r){const a=u*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),r?i.dollyDelta-=a:e&&(i.dollyDelta+=a),l&&(n.followPointerDirty=!0,l=!1)}}const h=c._isKeyDownForAction(c.PAN_FORWARDS,a),p=c._isKeyDownForAction(c.PAN_BACKWARDS,a),d=c._isKeyDownForAction(c.PAN_LEFT,a),A=c._isKeyDownForAction(c.PAN_RIGHT,a),f=c._isKeyDownForAction(c.PAN_UP,a),I=c._isKeyDownForAction(c.PAN_DOWN,a),m=(a[r.KEY_ALT]?.3:1)*u*s.keyboardPanRate;(h||p||d||A||f||I)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),I?i.panDeltaY+=m:f&&(i.panDeltaY+=-m),A?i.panDeltaX+=-m:d&&(i.panDeltaX+=m),p?i.panDeltaZ+=m:h&&(i.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 zp=d.vec3();class Kp{constructor(e,t,s,n,i){this._scene=e;const r=e.camera,a=t.pickController,o=t.pivotController,l=t.panController;let c=1,u=1,h=null;this._onTick=e.on("tick",(()=>{if(!s.active||!s.pointerEnabled)return;let t="default";if(Math.abs(i.dollyDelta)<.001&&(i.dollyDelta=0),Math.abs(i.rotateDeltaX)<.001&&(i.rotateDeltaX=0),Math.abs(i.rotateDeltaY)<.001&&(i.rotateDeltaY=0),0===i.rotateDeltaX&&0===i.rotateDeltaY||(i.dollyDelta=0),s.followPointer&&--c<=0&&(c=1,0!==i.dollyDelta)){if(0===i.rotateDeltaY&&0===i.rotateDeltaX&&s.followPointer&&n.followPointerDirty&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.pickResult&&a.pickResult.worldPos?h=a.pickResult.worldPos:(u=1,h=null),n.followPointerDirty=!1),h){const t=Math.abs(d.lenVec3(d.subVec3(h,e.camera.eye,zp)));u=t/s.dollyProximityThreshold}u{n.mouseover=!0}),r.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{n.mouseover=!1,r.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{Xp(e,r,n.pointerCanvasPos)}),r.addEventListener("mousedown",this._mouseDownHandler=e=>{s.active&&s.pointerEnabled&&(Xp(e,r,n.pointerCanvasPos),n.mouseover=!0)}),r.addEventListener("mouseup",this._mouseUpHandler=e=>{s.active&&s.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 Xp(e,t,s){if(e){const{x:n,y:i}=t.getBoundingClientRect();s[0]=e.clientX-n,s[1]=e.clientY-i}else e=window.event,s[0]=e.x,s[1]=e.y;return s}const qp=function(e,t){if(e){let s=e.target,n=0,i=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,s=s.offsetParent;t[0]=e.pageX-n,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class Jp{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.pivotController,o=d.vec2(),l=d.vec2(),c=d.vec2(),u=d.vec2(),h=[],p=this._scene.canvas.canvas;let A=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),p.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!s.active||!s.pointerEnabled)return;t.preventDefault();const i=t.touches,l=t.changedTouches;for(n.touchStartTime=Date.now(),1===i.length&&1===l.length&&(qp(i[0],o),s.followPointer&&(r.pickCursorPos=o,r.schedulePickSurface=!0,r.update(),s.planView||(r.picked&&r.pickedSurface&&r.pickResult&&r.pickResult.worldPos?(a.setPivotPos(r.pickResult.worldPos),!s.firstPerson&&a.startPivot()&&a.showPivot()):(s.smartPivot?a.setCanvasPivotPos(n.pointerCanvasPos):a.setPivotPos(e.camera.look),!s.firstPerson&&a.startPivot()&&a.showPivot()))));h.length{a.getPivoting()&&a.endPivot()}),p.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const a=e.canvas.boundary,o=a[2],p=a[3],I=t.touches;if(t.touches.length===A){if(1===A){qp(I[0],l),d.subVec2(l,h[0],u);const t=u[0],r=u[1];if(null!==n.longTouchTimeout&&(Math.abs(t)>s.longTapRadius||Math.abs(r)>s.longTapRadius)&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),s.planView){const n=e.camera;if("perspective"===n.projection){const a=Math.abs(e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=t*a/p*s.touchPanRate,i.panDeltaY+=r*a/p*s.touchPanRate}else i.panDeltaX+=.5*n.ortho.scale*(t/p)*s.touchPanRate,i.panDeltaY+=.5*n.ortho.scale*(r/p)*s.touchPanRate}else i.rotateDeltaY-=t/o*(1*s.dragRotationRate),i.rotateDeltaX+=r/p*(1.5*s.dragRotationRate)}else if(2===A){const t=I[0],a=I[1];qp(t,l),qp(a,c);const o=d.geometricMeanVec2(h[0],h[1]),u=d.geometricMeanVec2(l,c),A=d.vec2();d.subVec2(o,u,A);const f=A[0],m=A[1],y=e.camera,v=d.distVec2([t.pageX,t.pageY],[a.pageX,a.pageY]),w=(d.distVec2(h[0],h[1])-v)*s.touchDollyRate;if(i.dollyDelta=w,Math.abs(w)<1)if("perspective"===y.projection){const t=r.pickResult?r.pickResult.worldPos:e.center,n=Math.abs(d.lenVec3(d.subVec3(t,e.camera.eye,[])))*Math.tan(y.perspective.fov/2*Math.PI/180);i.panDeltaX-=f*n/p*s.touchPanRate,i.panDeltaY-=m*n/p*s.touchPanRate}else i.panDeltaX-=.5*y.ortho.scale*(f/p)*s.touchPanRate,i.panDeltaY-=.5*y.ortho.scale*(m/p)*s.touchPanRate;n.pointerCanvasPos=u}for(let e=0;e{let n;s&&s.worldPos&&(n=s.worldPos);const i=s?s.entity.aabb:e.aabb;if(n){const s=e.camera;d.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};p.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!s.active||!s.pointerEnabled)return;null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null);const i=e.touches,r=e.changedTouches;if(o=Date.now(),1===i.length&&1===r.length){u=o,Zp(i[0],c);const r=c[0],a=c[1],l=i[0].pageX,h=i[0].pageY;n.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(h)],canvasPos:[Math.round(r),Math.round(a)],event:e},!0),n.longTouchTimeout=null}),s.longTapTimeout)}else u=-1;for(;l.length{if(!s.active||!s.pointerEnabled)return;const t=Date.now(),i=e.touches,o=e.changedTouches,p=a.hasSubs("pickedSurface");null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),0===i.length&&1===o.length&&u>-1&&t-u<150&&(h>-1&&u-h<325?(Zp(o[0],r.pickCursorPos),r.schedulePickEntity=!0,r.schedulePickSurface=p,r.update(),r.pickResult?(r.pickResult.touchInput=!0,a.fire("doublePicked",r.pickResult),r.pickedSurface&&a.fire("doublePickedSurface",r.pickResult),s.doublePickFlyTo&&A(r.pickResult)):(a.fire("doublePickedNothing"),s.doublePickFlyTo&&A()),h=-1):d.distVec2(l[0],c)<4&&(Zp(o[0],r.pickCursorPos),r.schedulePickEntity=!0,r.schedulePickSurface=p,r.update(),r.pickResult?(r.pickResult.touchInput=!0,a.fire("picked",r.pickResult),r.pickedSurface&&a.fire("pickedSurface",r.pickResult)):a.fire("pickedNothing"),h=t),u=-1),l.length=i.length;for(let e=0,t=i.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 s=this.scene;this._controllers={cameraControl:this,pickController:new xp(this,this._configs),pivotController:new Np(s,this._configs),panController:new Pp(s),cameraFlight:new zh(this,{duration:.5})},this._handlers=[new Yp(this.scene,this._controllers,this._configs,this._states,this._updates),new Jp(this.scene,this._controllers,this._configs,this._states,this._updates),new Mp(this.scene,this._controllers,this._configs,this._states,this._updates),new kp(this.scene,this._controllers,this._configs,this._states,this._updates),new Qp(this.scene,this._controllers,this._configs,this._states,this._updates),new $p(this.scene,this._controllers,this._configs,this._states,this._updates),new Wp(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new Kp(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",g.isString(e)){const t=this.scene.input,s={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":s[this.PAN_LEFT]=[t.KEY_A],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_Z],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":s[this.PAN_LEFT]=[t.KEY_Q],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_W],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=s}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const s=this._keyMap[e];if(!s)return!1;t||(t=this.scene.input.keyDown);for(let e=0,n=s.length;e0?ad(t):null,a=s&&s.length>0?ad(s):null,o=e=>{if(!e)return;var t=!0;(a&&a[e.type]||r&&!r[e.type])&&(t=!1),t&&n.push(e.id);const s=e.children;if(s)for(var i=0,l=s.length;i * Copyright (c) 2022 Niklas von Hertzen diff --git a/dist/xeokit-sdk.min.es5.js b/dist/xeokit-sdk.min.es5.js index 1e80b7a698..b06ecd3313 100644 --- a/dist/xeokit-sdk.min.es5.js +++ b/dist/xeokit-sdk.min.es5.js @@ -14,7 +14,7 @@ var e,t=s().mark(HT),n=s().mark(UT),r=s().mark(qP);function i(e,t){var n=Object. /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT - **/var xf=null;function Mf(e,t){var n,r,i,a,s,o,l=3*e,u=3*t,c=Math.min(n=xf[l],r=xf[l+1],i=xf[l+2]),f=Math.min(a=xf[u],s=xf[u+1],o=xf[u+2]);if(c!==f)return c-f;var p=Math.max(n,r,i),A=Math.max(a,s,o);return p!==A?p-A:0}function Ff(e,t){for(var n=new Int32Array(e.length/3),r=0,i=n.length;r>t;n.sort(Mf);for(var o=new Int32Array(e.length),l=0,u=n.length;le[i+1]){var s=e[i];e[i]=e[i+1],e[i+1]=s}Hf=new Int32Array(e),t.sort(Uf);for(var o=new Int32Array(e.length),l=0,u=t.length;l0)for(var r=n._meshes,i=0,a=r.length;i0)for(var s=this._meshes,o=0,l=s.length;o1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._dtxEnabled=r.scene.dtxEnabled&&!1!==i.dtxEnabled,r._enableVertexWelding=!1,r._enableIndexBucketing=!1,r._vboBatchingLayerScratchMemory=Ja(),r._textureTranscoder=i.textureTranscoder||Bf(r.scene.viewer),r._maxGeometryBatchSize=i.maxGeometryBatchSize,r._aabb=$.collapseAABB3(),r._aabbDirty=!0,r._quantizationRanges={},r._vboInstancingLayers={},r._vboBatchingLayers={},r._dtxLayers={},r.layerList=[],r._entityList=[],r._geometries={},r._dtxBuckets={},r._textures={},r._textureSets={},r._transforms={},r._meshes={},r._entities={},r._scheduledMeshes={},r._meshesCfgsBeforeMeshCreation={},r.renderFlags=new ki,r.numGeometries=0,r.numPortions=0,r.numVisibleLayerPortions=0,r.numTransparentLayerPortions=0,r.numXRayedLayerPortions=0,r.numHighlightedLayerPortions=0,r.numSelectedLayerPortions=0,r.numEdgesLayerPortions=0,r.numPickableLayerPortions=0,r.numClippableLayerPortions=0,r.numCulledLayerPortions=0,r.numEntities=0,r._numTriangles=0,r._numLines=0,r._numPoints=0,r._edgeThreshold=i.edgeThreshold||10,r._origin=$.vec3(i.origin||[0,0,0]),r._position=$.vec3(i.position||[0,0,0]),r._rotation=$.vec3(i.rotation||[0,0,0]),r._quaternion=$.vec4(i.quaternion||[0,0,0,1]),r._conjugateQuaternion=$.vec4(i.quaternion||[0,0,0,1]),i.rotation&&$.eulerToQuaternion(r._rotation,"XYZ",r._quaternion),r._scale=$.vec3(i.scale||[1,1,1]),r._worldRotationMatrix=$.mat4(),r._worldRotationMatrixConjugate=$.mat4(),r._matrix=$.mat4(),r._matrixDirty=!0,r._rebuildMatrices(),r._worldNormalMatrix=$.mat4(),$.inverseMat4(r._matrix,r._worldNormalMatrix),$.transposeMat4(r._worldNormalMatrix),(i.matrix||i.position||i.rotation||i.scale||i.quaternion)&&(r._viewMatrix=$.mat4(),r._viewNormalMatrix=$.mat4(),r._viewMatrixDirty=!0,r._matrixNonIdentity=!0),r._opacity=1,r._colorize=[1,1,1],r._saoEnabled=!1!==i.saoEnabled,r._pbrEnabled=!1!==i.pbrEnabled,r._colorTextureEnabled=!1!==i.colorTextureEnabled,r._isModel=i.isModel,r._isModel&&r.scene._registerModel(w(r)),r._onCameraViewMatrix=r.scene.camera.on("matrix",(function(){r._viewMatrixDirty=!0})),r._meshesWithDirtyMatrices=[],r._numMeshesWithDirtyMatrices=0,r._onTick=r.scene.on("tick",(function(){for(;r._numMeshesWithDirtyMatrices>0;)r._meshesWithDirtyMatrices[--r._numMeshesWithDirtyMatrices]._updateMatrix()})),r._createDefaultTextureSet(),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.backfaces=i.backfaces,r}return P(n,[{key:"_meshMatrixDirty",value:function(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}},{key:"_createDefaultTextureSet",value:function(){var e=new mf({id:"defaultColorTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new mf({id:"defaultMetalRoughTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),n=new mf({id:"defaultNormalsTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),r=new mf({id:"defaultEmissiveTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new mf({id:"defaultOcclusionTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=n,this._textures.defaultEmissiveTexture=r,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new yf({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:n,emissiveTexture:r,occlusionTexture:i})}},{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||np),$.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,n=this._entityList.length;t0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var o=e.colors,l=new Uint8Array(o.length),u=0,c=o.length;u>24&255,i=n>>16&255,a=n>>8&255,s=255&n;switch(e.pickColor=new Uint8Array([s,a,i,r]),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),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 n=0,r=e.buckets.length;n>>0).toString(16)}},{key:"_getVBOInstancingLayer",value:function(e){var t=this,n=e.origin,r=e.textureSetId||"-",i=e.geometryId,a="".concat(Math.round(n[0]),".").concat(Math.round(n[1]),".").concat(Math.round(n[2]),".").concat(r,".").concat(i),s=this._vboInstancingLayers[a];if(s)return s;for(var o=e.textureSet,l=e.geometry;!s;)switch(l.primitive){case"triangles":case"surface":s=new qo({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!1});break;case"solid":s=new qo({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!0});break;case"lines":s=new xl({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0});break;case"points":s=new _u({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0})}return this._vboInstancingLayers[a]=s,this.layerList.push(s),s}},{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|=Me),this._pickable&&!1!==e.pickable&&(t|=He),this._culled&&!1!==e.culled&&(t|=Fe),this._clippable&&!1!==e.clippable&&(t|=Ue),this._collidable&&!1!==e.collidable&&(t|=Ge),this._edges&&!1!==e.edges&&(t|=Qe),this._xrayed&&!1!==e.xrayed&&(t|=ke),this._highlighted&&!1!==e.highlighted&&(t|=je),this._selected&&!1!==e.selected&&(t|=Ve),e.flags=t,this._createEntity(e)}else this.error("Config missing: meshIds")}},{key:"_createEntity",value:function(e){for(var t=[],n=0,r=e.meshIds.length;nt.sortId?1:0}));for(var s=0,o=this.layerList.length;s0&&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,n=this.layerList.length;t0)for(var a=0;a0&&(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 n=this.scene.selectedMaterial._state;n.fill&&(n.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),n.edges&&(n.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){var r=this.scene.highlightMaterial._state;r.fill&&(r.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),r.edges&&(r.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"drawColorOpaque",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n2&&void 0!==arguments[2]&&arguments[2],r=e.positionsCompressed||[],i=Ff(e.indices||[],t),a=Gf(e.edgeIndices||[]);function s(e,t){if(e>t){var n=e;e=t,t=n}function r(n,r){return n!==e?e-n:r!==t?t-r:0}for(var i=0,s=(a.length>>1)-1;i<=s;){var o=s+i>>1,l=r(a[2*o],a[2*o+1]);if(l>0)i=o+1;else{if(!(l<0))return o;s=o-1}}return-i-1}var o=new Int32Array(a.length/2);o.fill(0);var l=r.length/3;if(l>8*(1<p.maxNumPositions&&(p=f()),p.bucketNumber>8)return[e];-1===u[h]&&(u[h]=p.numPositions++,p.positionsCompressed.push(r[3*h]),p.positionsCompressed.push(r[3*h+1]),p.positionsCompressed.push(r[3*h+2])),-1===u[I]&&(u[I]=p.numPositions++,p.positionsCompressed.push(r[3*I]),p.positionsCompressed.push(r[3*I+1]),p.positionsCompressed.push(r[3*I+2])),-1===u[y]&&(u[y]=p.numPositions++,p.positionsCompressed.push(r[3*y]),p.positionsCompressed.push(r[3*y+1]),p.positionsCompressed.push(r[3*y+2])),p.indices.push(u[h]),p.indices.push(u[I]),p.indices.push(u[y]);var m=void 0;(m=s(h,I))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]])),(m=s(h,y))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]])),(m=s(I,y))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]]))}var w=t/8*2,g=t/8,E=2*r.length+(i.length+a.length)*w,T=0;return r.length,c.forEach((function(e){T+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*g,e.positionsCompressed.length})),T>E?[e]:(n&&kf(c,e),c)}({positionsCompressed:r,indices:i,edgeIndices:a},r.length/3>65536?16:8):s=[{positionsCompressed:r,indices:i,edgeIndices:a}];return s}var sp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e,i))._positions=i.positions||[],i.indices)r._indices=i.indices;else{r._indices=[];for(var a=0,s=r._positions.length/3-1;a1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"BCFViewpoints",e,i)).originatingSystem=i.originatingSystem||"xeokit.io",r.authoringTool=i.authoringTool||"xeokit.io",r}return P(n,[{key:"getViewpoint",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=this.viewer.scene,r=n.camera,i=n.realWorldOffset,a=!0===t.reverseClippingPlanes,s={},o=$.normalizeVec3($.subVec3(r.look,r.eye,$.vec3())),l=r.eye,u=r.up;r.yUp&&(o=dp(o),l=dp(l),u=dp(u));var c=pp($.addVec3(l,i));"ortho"===r.projection?s.orthogonal_camera={camera_view_point:c,camera_direction:pp(o),camera_up_vector:pp(u),view_to_world_scale:r.ortho.scale}:s.perspective_camera={camera_view_point:c,camera_direction:pp(o),camera_up_vector:pp(u),field_of_view:r.perspective.fov};var p=n.sectionPlanes;for(var A in p)if(p.hasOwnProperty(A)){var d=p[A];if(!d.active)continue;var v=d.pos,h=void 0;h=a?$.negateVec3(d.dir,$.vec3()):d.dir,r.yUp&&(v=dp(v),h=dp(h)),$.addVec3(v,i),v=pp(v),h=pp(h),s.clipping_planes||(s.clipping_planes=[]),s.clipping_planes.push({location:v,direction:h})}var I=n.lineSets;for(var y in I)if(I.hasOwnProperty(y)){var m=I[y];s.lines||(s.lines=[]);for(var w=m.positions,g=m.indices,E=0,T=g.length/2;E1&&void 0!==arguments[1]?arguments[1]:{};if(e){var r=this.viewer,i=r.scene,a=i.camera,s=!1!==n.rayCast,o=!1!==n.immediate,l=!1!==n.reset,u=i.realWorldOffset,c=!0===n.reverseClippingPlanes;if(i.clearSectionPlanes(),e.clipping_planes&&e.clipping_planes.length>0&&e.clipping_planes.forEach((function(e){var t=Ap(e.location,op),n=Ap(e.direction,op);c&&$.negateVec3(n),$.subVec3(t,u),a.yUp&&(t=vp(t),n=vp(n)),new aa(i,{pos:t,dir:n})})),i.clearLines(),e.lines&&e.lines.length>0){var f=[],p=[],A=0;e.lines.forEach((function(e){e.start_point&&e.end_point&&(f.push(e.start_point.x),f.push(e.start_point.y),f.push(e.start_point.z),f.push(e.end_point.x),f.push(e.end_point.y),f.push(e.end_point.z),p.push(A++),p.push(A++))})),new sp(i,{positions:f,indices:p,clippable:!1,collidable:!0})}if(i.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){var t=e.bitmap_type||"jpg",n=e.bitmap_data,r=Ap(e.location,lp),s=Ap(e.normal,up),o=Ap(e.up,cp),l=e.height||1;t&&n&&r&&s&&o&&(a.yUp&&(r=vp(r),s=vp(s),o=vp(o)),new Qa(i,{src:n,type:t,pos:r,normal:s,up:o,clippable:!1,collidable:!0,height:l}))})),l&&(i.setObjectsXRayed(i.xrayedObjectIds,!1),i.setObjectsHighlighted(i.highlightedObjectIds,!1),i.setObjectsSelected(i.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(i.setObjectsVisible(i.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.visible=!1}))}))):(i.setObjectsVisible(i.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.visible=!0}))})));var d=e.components.visibility.view_setup_hints;d&&(!1===d.spaces_visible&&i.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcSpace"),!0),void 0!==d.spaces_translucent&&i.setObjectsXRayed(r.metaScene.getObjectIDsByType("IfcSpace"),!0),d.space_boundaries_visible,!1===d.openings_visible&&i.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcOpening"),!0),d.space_boundaries_translucent,void 0!==d.openings_translucent&&i.setObjectsXRayed(r.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(i.setObjectsSelected(i.selectedObjectIds,!1),e.components.selection.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.selected=!0}))}))),e.components.translucency&&(i.setObjectsXRayed(i.xrayedObjectIds,!1),e.components.translucency.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.xrayed=!0}))}))),e.components.coloring&&e.components.coloring.forEach((function(e){var r=e.color,i=0,a=!1;8===r.length&&((i=parseInt(r.substring(0,2),16)/256)<=1&&i>=.95&&(i=1),r=r.substring(2),a=!0);var s=[parseInt(r.substring(0,2),16)/256,parseInt(r.substring(2,4),16)/256,parseInt(r.substring(4,6),16)/256];e.components.map((function(e){return t._withBCFComponent(n,e,(function(e){e.colorize=s,a&&(e.opacity=i)}))}))}))}if(e.perspective_camera||e.orthogonal_camera){var v,h,I,y;if(e.perspective_camera?(v=Ap(e.perspective_camera.camera_view_point,op),h=Ap(e.perspective_camera.camera_direction,op),I=Ap(e.perspective_camera.camera_up_vector,op),a.perspective.fov=e.perspective_camera.field_of_view,y="perspective"):(v=Ap(e.orthogonal_camera.camera_view_point,op),h=Ap(e.orthogonal_camera.camera_direction,op),I=Ap(e.orthogonal_camera.camera_up_vector,op),a.ortho.scale=e.orthogonal_camera.view_to_world_scale,y="ortho"),$.subVec3(v,u),a.yUp&&(v=vp(v),h=vp(h),I=vp(I)),s){var m=i.pick({pickSurface:!0,origin:v,direction:h});h=m?m.worldPos:$.addVec3(v,h,op)}else h=$.addVec3(v,h,op);o?(a.eye=v,a.look=h,a.up=I,a.projection=y):r.cameraFlight.flyTo({eye:v,look:h,up:I,duration:n.duration,projection:y})}}}},{key:"_withBCFComponent",value:function(e,t,n){var r=this.viewer,i=r.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){var a=t.authoring_tool_id,s=i.objects[a];if(s)return void n(s);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[a])return void i.withObjects(r.metaScene.getObjectIDsInSubtree(a),n)}if(t.ifc_guid){var o=t.ifc_guid,l=i.objects[o];if(l)return void n(l);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[o])return void i.withObjects(r.metaScene.getObjectIDsInSubtree(o),n);Object.keys(i.models).forEach((function(t){var a=$.globalizeObjectId(t,o),s=i.objects[a];s?n(s):e.updateCompositeObjects&&r.metaScene.metaObjects[a]&&i.withObjects(r.metaScene.getObjectIDsInSubtree(a),n)}))}}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this)}}]),n}();function pp(e){return{x:e[0],y:e[1],z:e[2]}}function Ap(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function dp(e){return new Float64Array([e[0],-e[2],e[1]])}function vp(e){return new Float64Array([e[0],e[2],-e[1]])}function hp(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 Ip=$.vec3(),yp=function(e,t,n,r){var i=e-n,a=t-r;return Math.sqrt(i*i+a*a)},mp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e.viewer.scene,i)).plugin=e,r._container=i.container,!r._container)throw"config missing: container";r._eventSubs={};var a=r.plugin.viewer.scene;r._originMarker=new qe(a,i.origin),r._targetMarker=new qe(a,i.target),r._originWorld=$.vec3(),r._targetWorld=$.vec3(),r._wp=new Float64Array(24),r._vp=new Float64Array(24),r._pp=new Float64Array(24),r._cp=new Float64Array(8),r._xAxisLabelCulled=!1,r._yAxisLabelCulled=!1,r._zAxisLabelCulled=!1,r._color=i.color||r.plugin.defaultColor;var s=i.onMouseOver?function(e){i.onMouseOver(e,w(r)),r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,o=i.onMouseLeave?function(e){i.onMouseLeave(e,w(r)),r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,l=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},u=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},c=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},f=i.onContextMenu?function(e){i.onContextMenu(e,w(r))}:null,p=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return r._originDot=new Ze(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._targetDot=new Ze(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._lengthWire=new Je(r._container,{color:r._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._xAxisWire=new Je(r._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._yAxisWire=new Je(r._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._zAxisWire=new Je(r._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._lengthLabel=new $e(r._container,{fillColor:r._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._xAxisLabel=new $e(r._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._yAxisLabel=new $e(r._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._zAxisLabel=new $e(r._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._wpDirty=!1,r._vpDirty=!1,r._cpDirty=!1,r._sectionPlanesDirty=!0,r._visible=!1,r._originVisible=!1,r._targetVisible=!1,r._wireVisible=!1,r._axisVisible=!1,r._xAxisVisible=!1,r._yAxisVisible=!1,r._zAxisVisible=!1,r._axisEnabled=!0,r._labelsVisible=!1,r._labelsOnWires=!1,r._clickable=!1,r._originMarker.on("worldPos",(function(e){r._originWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._targetMarker.on("worldPos",(function(e){r._targetWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._onViewMatrix=a.camera.on("viewMatrix",(function(){r._vpDirty=!0,r._needUpdate(0)})),r._onProjMatrix=a.camera.on("projMatrix",(function(){r._cpDirty=!0,r._needUpdate()})),r._onCanvasBoundary=a.canvas.on("boundary",(function(){r._cpDirty=!0,r._needUpdate(0)})),r._onMetricsUnits=a.metrics.on("units",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsScale=a.metrics.on("scale",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsOrigin=a.metrics.on("origin",(function(){r._cpDirty=!0,r._needUpdate()})),r._onSectionPlaneUpdated=a.on("sectionPlaneUpdated",(function(){r._sectionPlanesDirty=!0,r._needUpdate()})),r.approximate=i.approximate,r.visible=i.visible,r.originVisible=i.originVisible,r.targetVisible=i.targetVisible,r.wireVisible=i.wireVisible,r.axisVisible=i.axisVisible,r.xAxisVisible=i.xAxisVisible,r.yAxisVisible=i.yAxisVisible,r.zAxisVisible=i.zAxisVisible,r.labelsVisible=i.labelsVisible,r.labelsOnWires=i.labelsOnWires,r}return P(n,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._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._wp))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],n=this._targetMarker.viewPos[2];if(t>-.3||n>-.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 r=this._pp,i=this._cp,a=e.canvas.canvas.getBoundingClientRect(),s=this._container.getBoundingClientRect(),o=a.top-s.top,l=a.left-s.left,u=e.canvas.boundary,c=u[2],f=u[3],p=0,A=this.plugin.viewer.scene.metrics,d=A.scale,v=A.units,h=A.unitsInfo[v].abbrev,I=0,y=r.length;I1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e.viewer.scene)).pointerLens=i.pointerLens,r._active=!1,r._currentDistanceMeasurement=null,r._currentDistanceMeasurementInitState={wireVisible:null,axisVisible:null,xAxisVisible:null,yaxisVisible:null,zAxisVisible:null,targetVisible:null},r._initMarkerDiv(),r._onCameraControlHoverSnapOrSurface=null,r._onCameraControlHoverSnapOrSurfaceOff=null,r._onMouseDown=null,r._onMouseUp=null,r._onCanvasTouchStart=null,r._onCanvasTouchEnd=null,r._snapping=!1!==i.snapping,r._mouseState=0,r._attachPlugin(e,i),r}return P(n,[{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.margin="-200px -200px",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,n=this.scene,r=t.viewer.cameraControl,i=n.canvas.canvas;n.input;var a,s,o=!1,l=$.vec3(),u=$.vec2(),c=null;this._mouseState=0,this._onCameraControlHoverSnapOrSurface=r.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(function(t){var n=t.snappedCanvasPos||t.canvasPos;if(o=!0,l.set(t.worldPos),u.set(t.canvasPos),0===e._mouseState){var r=i.getBoundingClientRect(),a=window.pageXOffset||document.documentElement.scrollLeft,s=window.pageYOffset||document.documentElement.scrollTop,f=r.left+a,p=r.top+s;e._markerDiv.style.marginLeft="".concat(f+n[0]-5,"px"),e._markerDiv.style.marginTop="".concat(p+n[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"),c=t.entity}else e._markerDiv.style.marginLeft="-10000px",e._markerDiv.style.marginTop="-10000px";i.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.marginLeft="-10000px",e._markerDiv.style.marginTop="-10000px")})),i.addEventListener("mousedown",this._onMouseDown=function(e){1===e.which&&(a=e.clientX,s=e.clientY)}),i.addEventListener("mouseup",this._onMouseUp=function(n){1===n.which&&(n.clientX>a+20||n.clientXs+20||n.clientY1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"DistanceMeasurements",e))._pointerLens=i.pointerLens,r._container=i.container||document.body,r._defaultControl=null,r._measurements={},r.labelMinAxisLength=i.labelMinAxisLength,r.defaultVisible=!1!==i.defaultVisible,r.defaultOriginVisible=!1!==i.defaultOriginVisible,r.defaultTargetVisible=!1!==i.defaultTargetVisible,r.defaultWireVisible=!1!==i.defaultWireVisible,r.defaultLabelsVisible=!1!==i.defaultLabelsVisible,r.defaultAxisVisible=!1!==i.defaultAxisVisible,r.defaultXAxisVisible=!1!==i.defaultXAxisVisible,r.defaultYAxisVisible=!1!==i.defaultYAxisVisible,r.defaultZAxisVisible=!1!==i.defaultZAxisVisible,r.defaultColor=void 0!==i.defaultColor?i.defaultColor:"#00BBFF",r.zIndex=i.zIndex||1e4,r.defaultLabelsOnWires=!1!==i.defaultLabelsOnWires,r._onMouseOver=function(e,t){r.fire("mouseOver",{plugin:w(r),distanceMeasurement:t,measurement:t,event:e})},r._onMouseLeave=function(e,t){r.fire("mouseLeave",{plugin:w(r),distanceMeasurement:t,measurement:t,event:e})},r._onContextMenu=function(e,t){r.fire("contextMenu",{plugin:w(r),distanceMeasurement:t,measurement:t,event:e})},r}return P(n,[{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 gp(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 n=t.origin,r=t.target,i=new mp(this,{id:t.id,plugin:this,container:this._container,origin:{entity:n.entity,worldPos:n.worldPos},target:{entity:r.entity,worldPos:r.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[i.id]=i,i.on("destroyed",(function(){delete e._measurements[i.id]})),this.fire("measurementCreated",i),i}},{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,n=Object.entries(this.measurements);t1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,"FastNav",e))._hideColorTexture=!1!==i.hideColorTexture,r._hidePBR=!1!==i.hidePBR,r._hideSAO=!1!==i.hideSAO,r._hideEdges=!1!==i.hideEdges,r._hideTransparentObjects=!!i.hideTransparentObjects,r._scaleCanvasResolution=!!i.scaleCanvasResolution,r._scaleCanvasResolutionFactor=i.scaleCanvasResolutionFactor||.6,r._delayBeforeRestore=!1!==i.delayBeforeRestore,r._delayBeforeRestoreSeconds=i.delayBeforeRestoreSeconds||.5;var a=1e3*r._delayBeforeRestoreSeconds,s=!1,o=function(){a=1e3*r._delayBeforeRestoreSeconds,s||(e.scene._renderer.setColorTextureEnabled(!r._hideColorTexture),e.scene._renderer.setPBREnabled(!r._hidePBR),e.scene._renderer.setSAOEnabled(!r._hideSAO),e.scene._renderer.setTransparentEnabled(!r._hideTransparentObjects),e.scene._renderer.setEdgesEnabled(!r._hideEdges),r._scaleCanvasResolution?e.scene.canvas.resolutionScale=r._scaleCanvasResolutionFactor:e.scene.canvas.resolutionScale=1,s=!0)},l=function(){e.scene.canvas.resolutionScale=1,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};r._onCanvasBoundary=e.scene.canvas.on("boundary",o),r._onCameraMatrix=e.scene.camera.on("matrix",o),r._onSceneTick=e.scene.on("tick",(function(e){s&&(a-=e.deltaTime,(!r._delayBeforeRestore||a<=0)&&l())}));var u=!1;return r._onSceneMouseDown=e.scene.input.on("mousedown",(function(){u=!0})),r._onSceneMouseUp=e.scene.input.on("mouseup",(function(){u=!1})),r._onSceneMouseMove=e.scene.input.on("mousemove",(function(){u&&o()})),r}return P(n,[{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:"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),d(g(n.prototype),"destroy",this).call(this)}}]),n}(),bp=function(){function e(){b(this,e)}return P(e,[{key:"getMetaModel",value:function(e,t,n){le.loadJSON(e,(function(e){t(e)}),(function(e){n(e)}))}},{key:"getGLTF",value:function(e,t,n){le.loadArraybuffer(e,(function(e){t(e)}),(function(e){n(e)}))}},{key:"getGLB",value:function(e,t,n){le.loadArraybuffer(e,(function(e){t(e)}),(function(e){n(e)}))}},{key:"getArrayBuffer",value:function(e,t,n,r){!function(e,t,n,r){var i=function(){};n=n||i,r=r||i;var a=/^data:(.*?)(;base64)?,(.*)$/,s=t.match(a);if(s){var o=!!s[2],l=s[3];l=window.decodeURIComponent(l),o&&(l=window.atob(l));try{for(var u=new ArrayBuffer(l.length),c=new Uint8Array(u),f=0;f0&&void 0!==arguments[0]?arguments[0]:{};b(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 P(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 n=this._messages[this._locale];if(!n)return null;var r=Pp(e,n);return r?t?Cp(r,t):r:null}},{key:"translatePlurals",value:function(e,t,n){var r=this._messages[this._locale];if(!r)return null;var i=Pp(e,r);return(i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one)?(i=Cp(i,[t]),n&&(i=Cp(i,n)),i):null}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==n&&(this._events[e]=t||!0);var r=this._eventSubs[e];if(r)for(var i in r){if(r.hasOwnProperty(i))r[i].callback(t)}}},{key:"on",value:function(e,t){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new G),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});var n=this._eventSubs[e];n||(n={},this._eventSubs[e]=n);var r=this._eventSubIDMap.addItem();n[r]={callback:t},this._eventSubEvents[r]=e;var i=this._events[e];return void 0!==i&&t(i),r}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var n=this._eventSubs[t];n&&delete n[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function Pp(e,t){if(t[e])return t[e];for(var n=e.split("."),r=t,i=0,a=n.length;r&&i1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,n){return"{{"===e?"{":"}}"===e?"}":t[n]}))}var _p=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).t=i.t,r}return P(n,[{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 n=e-t,r=e+t;n<0&&(n=0),r>1&&(r=1);var i=this.getPoint(n),a=this.getPoint(r),s=$.subVec3(a,i,[]);return $.normalizeVec3(s,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,n=[];for(t=0;t<=e;t++)n.push(this.getPoint(t/e));return n}},{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,n,r=[],i=this.getPoint(0),a=0;for(r.push(0),n=1;n<=e;n++)t=this.getPoint(n/e),a+=$.lenVec3($.subVec3(t,i,[])),r.push(a),i=t;return this.cacheArcLengths=r,r}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var n,r=this._getLengths(),i=0,a=r.length;n=t||e*r[a-1];for(var s,o=0,l=a-1;o<=l;)if((s=r[i=Math.floor(o+(l-o)/2)]-n)<0)o=i+1;else{if(!(s>0)){l=i;break}l=i-1}if(r[i=l]===n)return i/(a-1);var u=r[i];return(i+(n-u)/(r[i+1]-u))/(a-1)}}]),n}(),Rp=function(e){h(n,_p);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).points=i.points,r.t=i.t,r}return P(n,[{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 n=(t.length-1)*e,r=Math.floor(n),i=n-r,a=t[0===r?r:r-1],s=t[r],o=t[r>t.length-2?t.length-1:r+1],l=t[r>t.length-3?t.length-1:r+2],u=$.vec3();return u[0]=$.catmullRomInterpolate(a[0],s[0],o[0],l[0],i),u[1]=$.catmullRomInterpolate(a[1],s[1],o[1],l[1],i),u[2]=$.catmullRomInterpolate(a[2],s[2],o[2],l[2],i),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}}}]),n}(),Bp=$.vec3(),Op=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._frames=[],r._eyeCurve=new Rp(w(r)),r._lookCurve=new Rp(w(r)),r._upCurve=new Rp(w(r)),i.frames&&(r.addFrames(i.frames),r.smoothFrameTimes(1)),r}return P(n,[{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,n,r){var i={t:e,eye:t.slice(0),look:n.slice(0),up:r.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}},{key:"addFrames",value:function(e){for(var t,n=0,r=e.length;n1?1:e,t.eye=this._eyeCurve.getPoint(e,Bp),t.look=this._lookCurve.getPoint(e,Bp),t.up=this._upCurve.getPoint(e,Bp)}},{key:"sampleFrame",value:function(e,t,n,r){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,n),this._upCurve.getPoint(e,r)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=$.vec3(),n=0;this._frames[0].t=0;for(var r=[],i=1,a=this._frames.length;i1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._look1=$.vec3(),r._eye1=$.vec3(),r._up1=$.vec3(),r._look2=$.vec3(),r._eye2=$.vec3(),r._up2=$.vec3(),r._orthoScale1=1,r._orthoScale2=1,r._flying=!1,r._flyEyeLookUp=!1,r._flyingEye=!1,r._flyingLook=!1,r._callback=null,r._callbackScope=null,r._time1=null,r._time2=null,r.easing=!1!==i.easing,r.duration=i.duration,r.fit=i.fit,r.fitFOV=i.fitFOV,r.trail=i.trail,r}return P(n,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,n){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=n;var r,i,a,s,o,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)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)i=e.eye,a=e.look,s=e.up;else if(e.eye)i=e.eye;else if(e.look)a=e.look;else{var c=e;if((le.isNumeric(c)||le.isString(c))&&(o=c,!(c=this.scene.components[o])))return this.error("Component not found: "+le.inQuotes(o)),void(t&&(n?t.call(n):t()));u||(r=c.aabb||this.scene.aabb)}var f=e.poi;if(r){if(r[3]=1;e>1&&(e=1);var r=this.easing?n._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?($.subVec3(i.eye,i.look,Mp),i.eye=$.lerpVec3(r,0,1,this._eye1,this._eye2,Lp),i.look=$.subVec3(Lp,Mp,Np)):this._flyingLook&&(i.look=$.lerpVec3(r,0,1,this._look1,this._look2,Np),i.up=$.lerpVec3(r,0,1,this._up1,this._up2,xp)):this._flyingEyeLookUp&&(i.eye=$.lerpVec3(r,0,1,this._eye1,this._eye2,Lp),i.look=$.lerpVec3(r,0,1,this._look1,this._look2,Np),i.up=$.lerpVec3(r,0,1,this._up1,this._up2,xp)),this._projection2){var a="ortho"===this._projection2?n._easeOutExpo(e,0,1,1):n._easeInCubic(e,0,1,1);i.customProjection.matrix=$.lerpMat4(a,0,1,this._projMatrix1,this._projMatrix2)}else i.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return i.ortho.scale=this._orthoScale2,void this.stop();he.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(),d(g(n.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,n,r){return n*(e/=r)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,n,r){return n*(1-Math.pow(2,-10*e/r))+t}}]),n}(),Hp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cameraFlightAnimation=new Fp(w(r)),r._t=0,r.state=n.SCRUBBING,r._playingFromT=0,r._playingToT=0,r._playingRate=i.playingRate||1,r._playingDir=1,r._lastTime=null,r.cameraPath=i.cameraPath,r._tick=r.scene.on("tick",r._updateT,w(r)),r}return P(n,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,r,i=performance.now(),a=this._lastTime?.001*(i-this._lastTime):0;if(this._lastTime=i,0!==a)switch(this.state){case n.SCRUBBING:return;case n.PLAYING:if(this._t+=this._playingRate*a,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=n.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case n.PLAYING_TO:r=this._t+this._playingRate*a*this._playingDir,(this._playingDir<0&&r<=this._playingToT||this._playingDir>0&&r>=this._playingToT)&&(r=this._playingToT,this.state=n.SCRUBBING,this.fire("stopped")),this._t=r,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(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=n.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=n.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var n=t.frames[e];n?this.playToT(n.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var r=this._cameraPath;if(r){var i=r.frames[e];i?(this.state=n.SCRUBBING,this._cameraFlightAnimation.flyTo(i,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=n.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=n.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=n.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),n}();Hp.STOPPED=0,Hp.SCRUBBING=1,Hp.PLAYING=2,Hp.PLAYING_TO=3;var Up=$.vec3(),Gp=$.vec3();$.vec3();var kp=$.vec3([0,-1,0]),jp=$.vec4([0,0,0,1]),Vp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._src=null,r._image=null,r._pos=$.vec3(),r._origin=$.vec3(),r._rtcPos=$.vec3(),r._dir=$.vec3(),r._size=1,r._imageSize=$.vec2(),r._texture=new Oa(w(r)),r._plane=new Zi(w(r),{geometry:new Rn(w(r),ja({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Ln(w(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0}),clippable:i.clippable}),r._grid=new Zi(w(r),{geometry:new Rn(w(r),ka({size:1,divisions:10})),material:new Ln(w(r),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:i.clippable}),r._node=new va(w(r),{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[r._plane,r._grid]}),r._gridVisible=!1,r.visible=!0,r.gridVisible=i.gridVisible,r.position=i.position,r.rotation=i.rotation,r.dir=i.dir,r.size=i.size,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{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 n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),Se(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,n=[-this._dir[0],-this._dir[1],-this._dir[2]];$.subVec3(t,this.position,Up);var r=-$.dotVec3(n,Up);$.normalizeVec3(n),$.mulVec3Scalar(n,r,Gp),$.vec3PairToQuaternion(kp,e,jp),this._node.quaternion=jp}}},{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(){d(g(n.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],n=this._imageSize[1];if(t>n){var r=n/t;this._node.scale=[e,1,e*r]}else{var i=t/n;this._node.scale=[e*i,1,e]}}}]),n}(),Qp=function(e){h(n,vn);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=w(r=t.call(this,e,i));r._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var s=r.scene.camera,o=r.scene.canvas;return r._onCameraViewMatrix=s.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=s.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=o.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new zt({type:"point",pos:$.vec3([1,1,1]),color:$.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(a._shadowViewMatrixDirty){a._shadowViewMatrix||(a._shadowViewMatrix=$.identityMat4());var e=a._state.pos,t=s.look,n=s.up;$.lookAtMat4v(e,t,n,a._shadowViewMatrix),a._shadowViewMatrixDirty=!1}return a._shadowViewMatrix},getShadowProjMatrix:function(){if(a._shadowProjMatrixDirty){a._shadowProjMatrix||(a._shadowProjMatrix=$.identityMat4());var e=a.scene.canvas.canvas;$.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,a._shadowProjMatrix),a._shadowProjMatrixDirty=!1}return a._shadowProjMatrix},getShadowRenderBuf:function(){return a._shadowRenderBuf||(a._shadowRenderBuf=new Gt(a.scene.canvas.canvas,a.scene.canvas.gl,{size:[1024,1024]})),a._shadowRenderBuf}}),r.pos=i.pos,r.color=i.color,r.intensity=i.intensity,r.constantAttenuation=i.constantAttenuation,r.linearAttenuation=i.linearAttenuation,r.quadraticAttenuation=i.quadraticAttenuation,r.castsShadow=i.castsShadow,r.scene._lightCreated(w(r)),r}return P(n,[{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),d(g(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}();function Wp(e){return 0==(e&e-1)}function zp(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var Kp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=(r=t.call(this,e,i)).scene.canvas.gl;return r._state=new zt({texture:new Da({gl:a,target:a.TEXTURE_CUBE_MAP}),flipY:r._checkFlipY(i.minFilter),encoding:r._checkEncoding(i.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),r._src=i.src,r._images=[],r._loadSrc(i.src),re.memory.textures++,r}return P(n,[{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,n=this.scene.canvas.gl;this._images=[];for(var r=!1,i=0,a=function(a){var s,o,l=new Image;l.onload=(s=l,o=a,function(){if(!r&&(s=function(e){if(!Wp(e.width)||!Wp(e.height)){var t=document.createElement("canvas");t.width=zp(e.width),t.height=zp(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(s),t._images[o]=s,6==++i)){var e=t._state.texture;e||(e=new Da({gl:n,target:n.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}),l.onerror=function(){r=!0},l.src=e[a]},s=0;s1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightsState.addReflectionMap(r._state),r.scene._reflectionMapCreated(w(r)),r}return P(n,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),n}(),Xp=function(e){h(n,Kp);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightMapCreated(w(r)),r}return P(n,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),n}(),qp=function(e){h(n,qe);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,{entity:i.entity,occludable:i.occludable,worldPos:i.worldPos}))._occluded=!1,r._visible=!0,r._src=null,r._image=null,r._pos=$.vec3(),r._origin=$.vec3(),r._rtcPos=$.vec3(),r._dir=$.vec3(),r._size=1,r._imageSize=$.vec2(),r._texture=new Oa(w(r),{src:i.src}),r._geometry=new Rn(w(r),{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]}),r._mesh=new Zi(w(r),{geometry:r._geometry,material:new Ln(w(r),{ambient:[.9,.3,.9],shininess:30,diffuseMap:r._texture,backfaces:!0}),scale:[1,1,1],position:i.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),r.visible=!0,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,r.size=i.size,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,d(g(n.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 n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.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],n=this._imageSize[1],r=n/t;this._geometry.positions=t>n?[e,e*r,0,-e,e*r,0,-e,-e*r,0,e,-e*r,0]:[e/r,e,0,-e/r,e,0,-e/r,-e,0,e/r,-e,0]}}]),n}(),Jp=function(){function e(t){b(this,e),this._eye=$.vec3(),this._look=$.vec3(),this._up=$.vec3(),this._projection={},t&&this.saveCamera(t)}return P(e,[{key:"saveCamera",value:function(e){var t=e.camera,n=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:n.fov,fovAxis:n.fovAxis,near:n.near,far:n.far};break;case"ortho":this._projection={projection:"ortho",scale:n.scale,near:n.near,far:n.far};break;case"frustum":this._projection={projection:"frustum",left:n.left,right:n.right,top:n.top,bottom:n.bottom,near:n.near,far:n.far};break;case"custom":this._projection={projection:"custom",matrix:n.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var n=e.camera,r=this._projection;function i(){switch(r.type){case"perspective":n.perspective.fov=r.fov,n.perspective.fovAxis=r.fovAxis,n.perspective.near=r.near,n.perspective.far=r.far;break;case"ortho":n.ortho.scale=r.scale,n.ortho.near=r.near,n.ortho.far=r.far;break;case"frustum":n.frustum.left=r.left,n.frustum.right=r.right,n.frustum.top=r.top,n.frustum.bottom=r.bottom,n.frustum.near=r.near,n.frustum.far=r.far;break;case"custom":n.customProjection.matrix=r.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:r.scale,projection:r.projection},(function(){i(),t()})):(n.eye=this._eye,n.look=this._look,n.up=this._up,i(),n.projection=r.projection)}}]),e}(),Zp=$.vec3(),$p=function(){function e(t){if(b(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 n=t.metaScene.scene;this.saveObjects(n,t)}}return P(e,[{key:"saveObjects",value:function(e,t,n){this.numObjects=0,this._mask=n?le.apply(n,{}):null;for(var r=!n||n.visible,i=!n||n.edges,a=!n||n.xrayed,s=!n||n.highlighted,o=!n||n.selected,l=!n||n.clippable,u=!n||n.pickable,c=!n||n.colorize,f=!n||n.opacity,p=t.metaObjects,A=e.objects,d=0,v=p.length;d1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.v3=i.v3,r.t=i.t,r}return P(n,[{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}}}]),n}(),rA=function(e){h(n,_p);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cachedLengths=[],r._dirty=!0,r._curves=[],r._t=0,r._dirtySubs=[],r._destroyedSubs=[],r.curves=i.curves||[],r.t=i.t,r}return P(n,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,n,r;for(e=e||[],n=0,r=this._curves.length;n1?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,n=e*this.length,r=this._getCurveLengths(),i=0;i=n){var a=1-(r[i]-n)/(t=this._curves[i]).length;return t.getPointAt(a)}i++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],n=0,r=this._curves.length;for(e=0;e1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.t=i.t,r}return P(n,[{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}}}]),n}(),aA=function(e){h(n,ip);var t=y(n);function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),t.call(this,e,r)}return P(n)}(),sA=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._skyboxMesh=new Zi(w(r),{geometry:new Rn(w(r),{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 Ln(w(r),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Oa(w(r),{src:i.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:i.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),r.size=i.size,r.active=i.active,r}return P(n,[{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}}]),n}(),oA=function(){function e(){b(this,e)}return P(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),lA=$.vec4(),uA=$.vec4(),cA=$.vec3(),fA=$.vec3(),pA=$.vec3(),AA=$.vec4(),dA=$.vec4(),vA=$.vec4(),hA=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"dollyToCanvasPos",value:function(e,t,n){var r=!1,i=this._scene.camera;if(e){var a=$.subVec3(e,i.eye,cA);r=$.lenVec3(a)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 Ln(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 n=this.getPivotPos();this._cameraOffset[2]+=$.distVec3(e.eye,n),t=$.inverseMat4(t);var r=$.transformVec3(t,this._cameraOffset),i=$.vec3();if($.subVec3(e.eye,n,i),$.addVec3(i,r),e.zUp){var a=i[1];i[1]=i[2],i[2]=a}this._radius=$.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}},{key:"_cameraLookingDownwards",value:function(){var e=this._scene.camera,t=$.normalizeVec3($.subVec3(e.look,e.eye,IA)),n=$.cross3Vec3(t,e.worldUp,yA);return $.sqLenVec3(n)<=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,n=Math.abs($.distVec3(this._scene.center,t.eye)),r=t.project.transposedMatrix,i=r.subarray(8,12),a=r.subarray(12),s=[0,0,-1,1],o=$.dotVec4(s,i)/$.dotVec4(s,a),l=wA;t.project.unproject(e,o,gA,EA,l);var u=$.normalizeVec3($.subVec3(l,t.eye,IA)),c=$.addVec3(t.eye,$.mulVec3Scalar(u,n,yA),mA);this.setPivotPos(c)}},{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 n=this._scene.camera,r=-e,i=-t;1===n.worldUp[2]&&(r=-r),this._azimuth+=.01*-r,this._polar+=.01*i,this._polar=$.clamp(this._polar,.001,Math.PI-.001);var a=[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===n.worldUp[2]){var s=a[1];a[1]=a[2],a[2]=s}var o=$.lenVec3($.subVec3(n.look,n.eye,$.vec3())),l=this.getPivotPos();$.addVec3(a,l);var u=$.lookAtMat4v(a,l,n.worldUp);u=$.inverseMat4(u);var c=$.transformVec3(u,this._cameraOffset);u[12]-=c[0],u[13]-=c[1],u[14]-=c[2];var f=[u[8],u[9],u[10]];n.eye=[u[12],u[13],u[14]],$.subVec3(n.eye,$.mulVec3Scalar(f,o),n.look),n.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}(),bA=function(){function e(t,n){b(this,e),this._scene=t.scene,this._cameraControl=t,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=n,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 P(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 n=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});n&&(n.snappedToEdge||n.snappedToVertex)?(this.snapPickResult=n,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var r=this.pickResult.canvasPos;if(r[0]===this.pickCursorPos[0]&&r[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 i=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(i[0]===this.pickCursorPos[0]&&i[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 yt;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}(),DA=$.vec2(),PA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s,o,l,u=n.pickController,c=0,f=0,p=0,A=0,d=!1,v=$.vec3(),h=!0,I=this._scene.canvas.canvas,y=[];function m(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];I.style.cursor="move",w(),e&&g()}function w(){c=i.pointerCanvasPos[0],f=i.pointerCanvasPos[1],p=i.pointerCanvasPos[0],A=i.pointerCanvasPos[1]}function g(){u.pickCursorPos=i.pointerCanvasPos,u.schedulePickSurface=!0,u.update(),u.picked&&u.pickedSurface&&u.pickResult&&u.pickResult.worldPos?(d=!0,v.set(u.pickResult.worldPos)):d=!1}document.addEventListener("keydown",this._documentKeyDownHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!0}}),document.addEventListener("keyup",this._documentKeyUpHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!1}}),I.addEventListener("mousedown",this._mouseDownHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:y[t.input.KEY_SHIFT]||r.planView?(s=!0,m()):(s=!0,m(!1));break;case 2:o=!0,m();break;case 3:l=!0,r.panRightClick&&m()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=function(){if(r.active&&r.pointerEnabled&&(s||o||l)){var e=t.canvas.boundary,n=e[2],u=e[3],p=i.pointerCanvasPos[0],A=i.pointerCanvasPos[1];if(y[t.input.KEY_SHIFT]||r.planView||!r.panRightClick&&o||r.panRightClick&&l){var h=p-c,I=A-f,m=t.camera;if("perspective"===m.projection){var w=Math.abs(d?$.lenVec3($.subVec3(v,t.camera.eye,[])):t.camera.eyeLookDist)*Math.tan(m.perspective.fov/2*Math.PI/180);a.panDeltaX+=1.5*h*w/u,a.panDeltaY+=1.5*I*w/u}else a.panDeltaX+=.5*m.ortho.scale*(h/u),a.panDeltaY+=.5*m.ortho.scale*(I/u)}else!s||o||l||r.planView||(r.firstPerson?(a.rotateDeltaY-=(p-c)/n*r.dragRotationRate/2,a.rotateDeltaX+=(A-f)/u*(r.dragRotationRate/4)):(a.rotateDeltaY-=(p-c)/n*(1.5*r.dragRotationRate),a.rotateDeltaX+=(A-f)/u*(1.5*r.dragRotationRate)));c=p,f=A}}),I.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){r.active&&r.pointerEnabled&&i.mouseover&&(h=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:case 2:case 3:s=!1,o=!1,l=!1}}),I.addEventListener("mouseup",this._mouseUpHandler=function(e){if(r.active&&r.pointerEnabled){if(3===e.which){!function(e,t){if(e){for(var n=e.target,r=0,i=0,a=0,s=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,a+=n.scrollLeft,s+=n.scrollTop,n=n.offsetParent;t[0]=e.pageX+a-r,t[1]=e.pageY+s-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,DA);var t=DA[0],i=DA[1];Math.abs(t-p)<3&&Math.abs(i-A)<3&&n.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:DA,event:e},!0)}I.style.removeProperty("cursor")}}),I.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var E=1/60,T=null;I.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled){var t=performance.now()/1e3,n=null!==T?t-T:0;T=t,n>.05&&(n=.05),n0?n.cameraFlight.flyTo(SA,(function(){n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot()})):(n.cameraFlight.jumpTo(SA),n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot())}}}))}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.input.off(this._onSceneKeyDown)}}]),e}(),LA=function(){function e(t,n,r,i,a){var s=this;b(this,e),this._scene=t;var o=n.pickController,l=n.pivotController,u=n.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;var c=!1,f=!1,p=this._scene.canvas.canvas,A=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e&&e.entity?e.entity.aabb:t.aabb;if(r){var a=t.camera;$.subVec3(a.eye,a.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})},d=t.tickify(this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!c&&!f){var n=u.hasSubs("hover"),a=u.hasSubs("hoverEnter"),l=u.hasSubs("hoverOut"),p=u.hasSubs("hoverOff"),A=u.hasSubs("hoverSurface"),d=u.hasSubs("hoverSnapOrSurface");if(n||a||l||p||A||d)if(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=A,o.scheduleSnapOrPick=d,o.update(),o.pickResult){if(o.pickResult.entity){var v=o.pickResult.entity.id;s._lastPickedEntityId!==v&&(void 0!==s._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),u.fire("hoverEnter",o.pickResult,!0),s._lastPickedEntityId=v)}u.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&u.fire("hoverSurface",o.pickResult,!0)}else void 0!==s._lastPickedEntityId&&(u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),s._lastPickedEntityId=void 0),u.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)}});p.addEventListener("mousemove",d),p.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(c=!0),3===e.which&&(f=!0),1===e.which&&r.active&&r.pointerEnabled&&(i.mouseDownClientX=e.clientX,i.mouseDownClientY=e.clientY,i.mouseDownCursorX=i.pointerCanvasPos[0],i.mouseDownCursorY=i.pointerCanvasPos[1],!r.firstPerson&&r.followPointer&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===e.which))){var n=o.pickResult;n&&n.worldPos?(l.setPivotPos(n.worldPos),l.startPivot()):(r.smartPivot?l.setCanvasPivotPos(i.pointerCanvasPos):l.setPivotPos(t.camera.look),l.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(c=!1),3===e.which&&(f=!1),l.getPivoting()&&l.endPivot()}),p.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(r.active&&r.pointerEnabled&&(1===e.which&&(l.hidePivot(),!(Math.abs(e.clientX-i.mouseDownClientX)>3||Math.abs(e.clientY-i.mouseDownClientY)>3)))){var a=u.hasSubs("picked"),c=u.hasSubs("pickedNothing"),f=u.hasSubs("pickedSurface"),p=u.hasSubs("doublePicked"),d=u.hasSubs("doublePickedSurface"),v=u.hasSubs("doublePickedNothing");if(!(r.doublePickFlyTo||p||d||v))return(a||c||f)&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=f,o.update(),o.pickResult?(u.fire("picked",o.pickResult,!0),o.pickedSurface&&u.fire("pickedSurface",o.pickResult,!0)):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0)),void(s._clicks=0);if(s._clicks++,1===s._clicks){o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo,o.schedulePickSurface=f,o.update();var h=o.pickResult,I=o.pickedSurface;s._timeout=setTimeout((function(){h?(u.fire("picked",h,!0),I&&(u.fire("pickedSurface",h,!0),!r.firstPerson&&r.followPointer&&(n.pivotController.setPivotPos(h.worldPos),n.pivotController.startPivot()&&n.pivotController.showPivot()))):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0),s._clicks=0}),r.doubleClickTimeFrame)}else{if(null!==s._timeout&&(window.clearTimeout(s._timeout),s._timeout=null),o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo||p||d,o.schedulePickSurface=o.schedulePickEntity&&d,o.update(),o.pickResult){if(u.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&u.fire("doublePickedSurface",o.pickResult,!0),r.doublePickFlyTo&&(A(o.pickResult),!r.firstPerson&&r.followPointer)){var y=o.pickResult.entity.aabb,m=$.getAABB3Center(y);n.pivotController.setPivotPos(m),n.pivotController.startPivot()&&n.pivotController.showPivot()}}else if(u.fire("doublePickedNothing",{canvasPos:i.pointerCanvasPos},!0),r.doublePickFlyTo&&(A(),!r.firstPerson&&r.followPointer)){var w=t.aabb,g=$.getAABB3Center(w);n.pivotController.setPivotPos(g),n.pivotController.startPivot()&&n.pivotController.showPivot()}s._clicks=0}}},!1)}return P(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}(),xA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.input,o=[],l=t.canvas.canvas,u=!0;this._onSceneMouseMove=s.on("mousemove",(function(){u=!0})),this._onSceneKeyDown=s.on("keydown",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover&&(o[e]=!0,e===s.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=s.on("keyup",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(o[e]=!1,e===s.KEY_SHIFT&&(l.style.cursor=null),n.pivotController.getPivoting()&&n.pivotController.endPivot())})),this._onTick=t.on("tick",(function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover){var l=n.cameraControl,c=e.deltaTime/1e3;if(!r.planView){var f=l._isKeyDownForAction(l.ROTATE_Y_POS,o),p=l._isKeyDownForAction(l.ROTATE_Y_NEG,o),A=l._isKeyDownForAction(l.ROTATE_X_POS,o),d=l._isKeyDownForAction(l.ROTATE_X_NEG,o),v=c*r.keyboardRotationRate;(f||p||A||d)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),f?a.rotateDeltaY+=v:p&&(a.rotateDeltaY-=v),A?a.rotateDeltaX+=v:d&&(a.rotateDeltaX-=v),!r.firstPerson&&r.followPointer&&n.pivotController.startPivot())}if(!o[s.KEY_CTRL]&&!o[s.KEY_ALT]){var h=l._isKeyDownForAction(l.DOLLY_BACKWARDS,o),I=l._isKeyDownForAction(l.DOLLY_FORWARDS,o);if(h||I){var y=c*r.keyboardDollyRate;!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),I?a.dollyDelta-=y:h&&(a.dollyDelta+=y),u&&(i.followPointerDirty=!0,u=!1)}}var m=l._isKeyDownForAction(l.PAN_FORWARDS,o),w=l._isKeyDownForAction(l.PAN_BACKWARDS,o),g=l._isKeyDownForAction(l.PAN_LEFT,o),E=l._isKeyDownForAction(l.PAN_RIGHT,o),T=l._isKeyDownForAction(l.PAN_UP,o),b=l._isKeyDownForAction(l.PAN_DOWN,o),D=(o[s.KEY_ALT]?.3:1)*c*r.keyboardPanRate;(m||w||g||E||T||b)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),b?a.panDeltaY+=D:T&&(a.panDeltaY+=-D),E?a.panDeltaX+=-D:g&&(a.panDeltaX+=D),w?a.panDeltaZ+=D:m&&(a.panDeltaZ+=-D))}}))}return P(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}(),MA=$.vec3(),FA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.camera,o=n.pickController,l=n.pivotController,u=n.panController,c=1,f=1,p=null;this._onTick=t.on("tick",(function(){if(r.active&&r.pointerEnabled){var e="default";if(Math.abs(a.dollyDelta)<.001&&(a.dollyDelta=0),Math.abs(a.rotateDeltaX)<.001&&(a.rotateDeltaX=0),Math.abs(a.rotateDeltaY)<.001&&(a.rotateDeltaY=0),0===a.rotateDeltaX&&0===a.rotateDeltaY||(a.dollyDelta=0),r.followPointer&&--c<=0&&(c=1,0!==a.dollyDelta)){if(0===a.rotateDeltaY&&0===a.rotateDeltaX&&r.followPointer&&i.followPointerDirty&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.pickResult&&o.pickResult.worldPos?p=o.pickResult.worldPos:(f=1,p=null),i.followPointerDirty=!1),p){var n=Math.abs($.lenVec3($.subVec3(p,t.camera.eye,MA)));f=n/r.dollyProximityThreshold}fr.longTapRadius||Math.abs(I)>r.longTapRadius)&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),r.planView){var y=t.camera;if("perspective"===y.projection){var m=Math.abs(t.camera.eyeLookDist)*Math.tan(y.perspective.fov/2*Math.PI/180);a.panDeltaX+=h*m/l*r.touchPanRate,a.panDeltaY+=I*m/l*r.touchPanRate}else a.panDeltaX+=.5*y.ortho.scale*(h/l)*r.touchPanRate,a.panDeltaY+=.5*y.ortho.scale*(I/l)*r.touchPanRate}else a.rotateDeltaY-=h/o*(1*r.dragRotationRate),a.rotateDeltaX+=I/l*(1.5*r.dragRotationRate)}else if(2===d){var w=A[0],g=A[1];GA(w,u),GA(g,c);var E=$.geometricMeanVec2(p[0],p[1]),T=$.geometricMeanVec2(u,c),b=$.vec2();$.subVec2(E,T,b);var D=b[0],P=b[1],C=t.camera,_=$.distVec2([w.pageX,w.pageY],[g.pageX,g.pageY]),R=($.distVec2(p[0],p[1])-_)*r.touchDollyRate;if(a.dollyDelta=R,Math.abs(R)<1)if("perspective"===C.projection){var B=s.pickResult?s.pickResult.worldPos:t.center,O=Math.abs($.lenVec3($.subVec3(B,t.camera.eye,[])))*Math.tan(C.perspective.fov/2*Math.PI/180);a.panDeltaX-=D*O/l*r.touchPanRate,a.panDeltaY-=P*O/l*r.touchPanRate}else a.panDeltaX-=.5*C.ortho.scale*(D/l)*r.touchPanRate,a.panDeltaY-=.5*C.ortho.scale*(P/l)*r.touchPanRate;i.pointerCanvasPos=T}for(var S=0;S-1&&t-f<150&&(p>-1&&f-p<325?(jA(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=s,o.update(),o.pickResult?(o.pickResult.touchInput=!0,l.fire("doublePicked",o.pickResult),o.pickedSurface&&l.fire("doublePickedSurface",o.pickResult),r.doublePickFlyTo&&d(o.pickResult)):(l.fire("doublePickedNothing"),r.doublePickFlyTo&&d()),p=-1):$.distVec2(u[0],c)<4&&(jA(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=s,o.update(),o.pickResult?(o.pickResult.touchInput=!0,l.fire("picked",o.pickResult),o.pickedSurface&&l.fire("pickedSurface",o.pickResult)):l.fire("pickedNothing"),p=t),f=-1),u.length=n.length;for(var A=0,v=n.length;A1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i)).PAN_LEFT=0,r.PAN_RIGHT=1,r.PAN_UP=2,r.PAN_DOWN=3,r.PAN_FORWARDS=4,r.PAN_BACKWARDS=5,r.ROTATE_X_POS=6,r.ROTATE_X_NEG=7,r.ROTATE_Y_POS=8,r.ROTATE_Y_NEG=9,r.DOLLY_FORWARDS=10,r.DOLLY_BACKWARDS=11,r.AXIS_VIEW_RIGHT=12,r.AXIS_VIEW_BACK=13,r.AXIS_VIEW_LEFT=14,r.AXIS_VIEW_FRONT=15,r.AXIS_VIEW_TOP=16,r.AXIS_VIEW_BOTTOM=17,r._keyMap={},r.scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},r._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},r._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},r._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};var a=r.scene;return r._controllers={cameraControl:w(r),pickController:new bA(w(r),r._configs),pivotController:new TA(a,r._configs),panController:new hA(a),cameraFlight:new Fp(w(r),{duration:.5})},r._handlers=[new HA(r.scene,r._controllers,r._configs,r._states,r._updates),new kA(r.scene,r._controllers,r._configs,r._states,r._updates),new PA(r.scene,r._controllers,r._configs,r._states,r._updates),new NA(r.scene,r._controllers,r._configs,r._states,r._updates),new LA(r.scene,r._controllers,r._configs,r._states,r._updates),new VA(r.scene,r._controllers,r._configs,r._states,r._updates),new xA(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cameraUpdater=new FA(r.scene,r._controllers,r._configs,r._states,r._updates),r.navMode=i.navMode,i.planView&&(r.planView=i.planView),r.constrainVertical=i.constrainVertical,i.keyboardLayout?r.keyboardLayout=i.keyboardLayout:r.keyMap=i.keyMap,r.doublePickFlyTo=i.doublePickFlyTo,r.panRightClick=i.panRightClick,r.active=i.active,r.followPointer=i.followPointer,r.rotationInertia=i.rotationInertia,r.keyboardPanRate=i.keyboardPanRate,r.touchPanRate=i.touchPanRate,r.keyboardRotationRate=i.keyboardRotationRate,r.dragRotationRate=i.dragRotationRate,r.touchDollyRate=i.touchDollyRate,r.dollyInertia=i.dollyInertia,r.dollyProximityThreshold=i.dollyProximityThreshold,r.dollyMinSpeed=i.dollyMinSpeed,r.panInertia=i.panInertia,r.pointerEnabled=!0,r.keyboardDollyRate=i.keyboardDollyRate,r.mouseWheelDollyRate=i.mouseWheelDollyRate,r}return P(n,[{key:"keyMap",get:function(){return this._keyMap},set:function(e){if(e=e||"qwerty",le.isString(e)){var t=this.scene.input,n={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":n[this.PAN_LEFT]=[t.KEY_A],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_Z],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":n[this.PAN_LEFT]=[t.KEY_Q],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_W],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=n}else{var r=e;this._keyMap=r}}},{key:"_isKeyDownForAction",value:function(e,t){var n=this._keyMap[e];if(!n)return!1;t||(t=this.scene.input.keyDown);for(var r=0,i=n.length;r0&&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(),d(g(n.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 n=this.metaScene,r=e.properties;if(e.propertySets)for(var i=0,a=e.propertySets.length;i0?qA(t):null,s=n&&n.length>0?qA(n):null;return function e(t){if(t){var n=!0;(s&&s[t.type]||a&&!a[t.type])&&(n=!1),n&&r.push(t.id);var i=t.children;if(i)for(var o=0,l=i.length;o>t;n.sort(Mf);for(var o=new Int32Array(e.length),l=0,u=n.length;le[i+1]){var s=e[i];e[i]=e[i+1],e[i+1]=s}Hf=new Int32Array(e),t.sort(Uf);for(var o=new Int32Array(e.length),l=0,u=t.length;l0)for(var r=n._meshes,i=0,a=r.length;i0)for(var s=this._meshes,o=0,l=s.length;o1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._dtxEnabled=r.scene.dtxEnabled&&!1!==i.dtxEnabled,r._enableVertexWelding=!1,r._enableIndexBucketing=!1,r._vboBatchingLayerScratchMemory=Ja(),r._textureTranscoder=i.textureTranscoder||Bf(r.scene.viewer),r._maxGeometryBatchSize=i.maxGeometryBatchSize,r._aabb=$.collapseAABB3(),r._aabbDirty=!0,r._quantizationRanges={},r._vboInstancingLayers={},r._vboBatchingLayers={},r._dtxLayers={},r.layerList=[],r._entityList=[],r._geometries={},r._dtxBuckets={},r._textures={},r._textureSets={},r._transforms={},r._meshes={},r._entities={},r._scheduledMeshes={},r._meshesCfgsBeforeMeshCreation={},r.renderFlags=new ki,r.numGeometries=0,r.numPortions=0,r.numVisibleLayerPortions=0,r.numTransparentLayerPortions=0,r.numXRayedLayerPortions=0,r.numHighlightedLayerPortions=0,r.numSelectedLayerPortions=0,r.numEdgesLayerPortions=0,r.numPickableLayerPortions=0,r.numClippableLayerPortions=0,r.numCulledLayerPortions=0,r.numEntities=0,r._numTriangles=0,r._numLines=0,r._numPoints=0,r._edgeThreshold=i.edgeThreshold||10,r._origin=$.vec3(i.origin||[0,0,0]),r._position=$.vec3(i.position||[0,0,0]),r._rotation=$.vec3(i.rotation||[0,0,0]),r._quaternion=$.vec4(i.quaternion||[0,0,0,1]),r._conjugateQuaternion=$.vec4(i.quaternion||[0,0,0,1]),i.rotation&&$.eulerToQuaternion(r._rotation,"XYZ",r._quaternion),r._scale=$.vec3(i.scale||[1,1,1]),r._worldRotationMatrix=$.mat4(),r._worldRotationMatrixConjugate=$.mat4(),r._matrix=$.mat4(),r._matrixDirty=!0,r._rebuildMatrices(),r._worldNormalMatrix=$.mat4(),$.inverseMat4(r._matrix,r._worldNormalMatrix),$.transposeMat4(r._worldNormalMatrix),(i.matrix||i.position||i.rotation||i.scale||i.quaternion)&&(r._viewMatrix=$.mat4(),r._viewNormalMatrix=$.mat4(),r._viewMatrixDirty=!0,r._matrixNonIdentity=!0),r._opacity=1,r._colorize=[1,1,1],r._saoEnabled=!1!==i.saoEnabled,r._pbrEnabled=!1!==i.pbrEnabled,r._colorTextureEnabled=!1!==i.colorTextureEnabled,r._isModel=i.isModel,r._isModel&&r.scene._registerModel(w(r)),r._onCameraViewMatrix=r.scene.camera.on("matrix",(function(){r._viewMatrixDirty=!0})),r._meshesWithDirtyMatrices=[],r._numMeshesWithDirtyMatrices=0,r._onTick=r.scene.on("tick",(function(){for(;r._numMeshesWithDirtyMatrices>0;)r._meshesWithDirtyMatrices[--r._numMeshesWithDirtyMatrices]._updateMatrix()})),r._createDefaultTextureSet(),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.backfaces=i.backfaces,r}return P(n,[{key:"_meshMatrixDirty",value:function(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}},{key:"_createDefaultTextureSet",value:function(){var e=new mf({id:"defaultColorTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new mf({id:"defaultMetalRoughTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),n=new mf({id:"defaultNormalsTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),r=new mf({id:"defaultEmissiveTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new mf({id:"defaultOcclusionTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=n,this._textures.defaultEmissiveTexture=r,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new yf({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:n,emissiveTexture:r,occlusionTexture:i})}},{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||np),$.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,n=this._entityList.length;t0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var o=e.colors,l=new Uint8Array(o.length),u=0,c=o.length;u>24&255,i=n>>16&255,a=n>>8&255,s=255&n;switch(e.pickColor=new Uint8Array([s,a,i,r]),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),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 n=0,r=e.buckets.length;n>>0).toString(16)}},{key:"_getVBOInstancingLayer",value:function(e){var t=this,n=e.origin,r=e.textureSetId||"-",i=e.geometryId,a="".concat(Math.round(n[0]),".").concat(Math.round(n[1]),".").concat(Math.round(n[2]),".").concat(r,".").concat(i),s=this._vboInstancingLayers[a];if(s)return s;for(var o=e.textureSet,l=e.geometry;!s;)switch(l.primitive){case"triangles":case"surface":s=new qo({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!1});break;case"solid":s=new qo({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!0});break;case"lines":s=new xl({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0});break;case"points":s=new _u({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0})}return this._vboInstancingLayers[a]=s,this.layerList.push(s),s}},{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|=Me),this._pickable&&!1!==e.pickable&&(t|=He),this._culled&&!1!==e.culled&&(t|=Fe),this._clippable&&!1!==e.clippable&&(t|=Ue),this._collidable&&!1!==e.collidable&&(t|=Ge),this._edges&&!1!==e.edges&&(t|=Qe),this._xrayed&&!1!==e.xrayed&&(t|=ke),this._highlighted&&!1!==e.highlighted&&(t|=je),this._selected&&!1!==e.selected&&(t|=Ve),e.flags=t,this._createEntity(e)}else this.error("Config missing: meshIds")}},{key:"_createEntity",value:function(e){for(var t=[],n=0,r=e.meshIds.length;nt.sortId?1:0}));for(var s=0,o=this.layerList.length;s0&&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,n=this.layerList.length;t0)for(var a=0;a0&&(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 n=this.scene.selectedMaterial._state;n.fill&&(n.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),n.edges&&(n.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){var r=this.scene.highlightMaterial._state;r.fill&&(r.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),r.edges&&(r.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"drawColorOpaque",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n2&&void 0!==arguments[2]&&arguments[2],r=e.positionsCompressed||[],i=Ff(e.indices||[],t),a=Gf(e.edgeIndices||[]);function s(e,t){if(e>t){var n=e;e=t,t=n}function r(n,r){return n!==e?e-n:r!==t?t-r:0}for(var i=0,s=(a.length>>1)-1;i<=s;){var o=s+i>>1,l=r(a[2*o],a[2*o+1]);if(l>0)i=o+1;else{if(!(l<0))return o;s=o-1}}return-i-1}var o=new Int32Array(a.length/2);o.fill(0);var l=r.length/3;if(l>8*(1<p.maxNumPositions&&(p=f()),p.bucketNumber>8)return[e];-1===u[h]&&(u[h]=p.numPositions++,p.positionsCompressed.push(r[3*h]),p.positionsCompressed.push(r[3*h+1]),p.positionsCompressed.push(r[3*h+2])),-1===u[I]&&(u[I]=p.numPositions++,p.positionsCompressed.push(r[3*I]),p.positionsCompressed.push(r[3*I+1]),p.positionsCompressed.push(r[3*I+2])),-1===u[y]&&(u[y]=p.numPositions++,p.positionsCompressed.push(r[3*y]),p.positionsCompressed.push(r[3*y+1]),p.positionsCompressed.push(r[3*y+2])),p.indices.push(u[h]),p.indices.push(u[I]),p.indices.push(u[y]);var m=void 0;(m=s(h,I))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]])),(m=s(h,y))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]])),(m=s(I,y))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]]))}var w=t/8*2,g=t/8,E=2*r.length+(i.length+a.length)*w,T=0;return r.length,c.forEach((function(e){T+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*g,e.positionsCompressed.length})),T>E?[e]:(n&&kf(c,e),c)}({positionsCompressed:r,indices:i,edgeIndices:a},r.length/3>65536?16:8):s=[{positionsCompressed:r,indices:i,edgeIndices:a}];return s}var sp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e,i))._positions=i.positions||[],i.indices)r._indices=i.indices;else{r._indices=[];for(var a=0,s=r._positions.length/3-1;a1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"BCFViewpoints",e,i)).originatingSystem=i.originatingSystem||"xeokit.io",r.authoringTool=i.authoringTool||"xeokit.io",r}return P(n,[{key:"getViewpoint",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=this.viewer.scene,r=n.camera,i=n.realWorldOffset,a=!0===t.reverseClippingPlanes,s={},o=$.normalizeVec3($.subVec3(r.look,r.eye,$.vec3())),l=r.eye,u=r.up;r.yUp&&(o=dp(o),l=dp(l),u=dp(u));var c=pp($.addVec3(l,i));"ortho"===r.projection?s.orthogonal_camera={camera_view_point:c,camera_direction:pp(o),camera_up_vector:pp(u),view_to_world_scale:r.ortho.scale}:s.perspective_camera={camera_view_point:c,camera_direction:pp(o),camera_up_vector:pp(u),field_of_view:r.perspective.fov};var p=n.sectionPlanes;for(var A in p)if(p.hasOwnProperty(A)){var d=p[A];if(!d.active)continue;var v=d.pos,h=void 0;h=a?$.negateVec3(d.dir,$.vec3()):d.dir,r.yUp&&(v=dp(v),h=dp(h)),$.addVec3(v,i),v=pp(v),h=pp(h),s.clipping_planes||(s.clipping_planes=[]),s.clipping_planes.push({location:v,direction:h})}var I=n.lineSets;for(var y in I)if(I.hasOwnProperty(y)){var m=I[y];s.lines||(s.lines=[]);for(var w=m.positions,g=m.indices,E=0,T=g.length/2;E1&&void 0!==arguments[1]?arguments[1]:{};if(e){var r=this.viewer,i=r.scene,a=i.camera,s=!1!==n.rayCast,o=!1!==n.immediate,l=!1!==n.reset,u=i.realWorldOffset,c=!0===n.reverseClippingPlanes;if(i.clearSectionPlanes(),e.clipping_planes&&e.clipping_planes.length>0&&e.clipping_planes.forEach((function(e){var t=Ap(e.location,op),n=Ap(e.direction,op);c&&$.negateVec3(n),$.subVec3(t,u),a.yUp&&(t=vp(t),n=vp(n)),new aa(i,{pos:t,dir:n})})),i.clearLines(),e.lines&&e.lines.length>0){var f=[],p=[],A=0;e.lines.forEach((function(e){e.start_point&&e.end_point&&(f.push(e.start_point.x),f.push(e.start_point.y),f.push(e.start_point.z),f.push(e.end_point.x),f.push(e.end_point.y),f.push(e.end_point.z),p.push(A++),p.push(A++))})),new sp(i,{positions:f,indices:p,clippable:!1,collidable:!0})}if(i.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){var t=e.bitmap_type||"jpg",n=e.bitmap_data,r=Ap(e.location,lp),s=Ap(e.normal,up),o=Ap(e.up,cp),l=e.height||1;t&&n&&r&&s&&o&&(a.yUp&&(r=vp(r),s=vp(s),o=vp(o)),new Qa(i,{src:n,type:t,pos:r,normal:s,up:o,clippable:!1,collidable:!0,height:l}))})),l&&(i.setObjectsXRayed(i.xrayedObjectIds,!1),i.setObjectsHighlighted(i.highlightedObjectIds,!1),i.setObjectsSelected(i.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(i.setObjectsVisible(i.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.visible=!1}))}))):(i.setObjectsVisible(i.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.visible=!0}))})));var d=e.components.visibility.view_setup_hints;d&&(!1===d.spaces_visible&&i.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcSpace"),!0),void 0!==d.spaces_translucent&&i.setObjectsXRayed(r.metaScene.getObjectIDsByType("IfcSpace"),!0),d.space_boundaries_visible,!1===d.openings_visible&&i.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcOpening"),!0),d.space_boundaries_translucent,void 0!==d.openings_translucent&&i.setObjectsXRayed(r.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(i.setObjectsSelected(i.selectedObjectIds,!1),e.components.selection.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.selected=!0}))}))),e.components.translucency&&(i.setObjectsXRayed(i.xrayedObjectIds,!1),e.components.translucency.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.xrayed=!0}))}))),e.components.coloring&&e.components.coloring.forEach((function(e){var r=e.color,i=0,a=!1;8===r.length&&((i=parseInt(r.substring(0,2),16)/256)<=1&&i>=.95&&(i=1),r=r.substring(2),a=!0);var s=[parseInt(r.substring(0,2),16)/256,parseInt(r.substring(2,4),16)/256,parseInt(r.substring(4,6),16)/256];e.components.map((function(e){return t._withBCFComponent(n,e,(function(e){e.colorize=s,a&&(e.opacity=i)}))}))}))}if(e.perspective_camera||e.orthogonal_camera){var v,h,I,y;if(e.perspective_camera?(v=Ap(e.perspective_camera.camera_view_point,op),h=Ap(e.perspective_camera.camera_direction,op),I=Ap(e.perspective_camera.camera_up_vector,op),a.perspective.fov=e.perspective_camera.field_of_view,y="perspective"):(v=Ap(e.orthogonal_camera.camera_view_point,op),h=Ap(e.orthogonal_camera.camera_direction,op),I=Ap(e.orthogonal_camera.camera_up_vector,op),a.ortho.scale=e.orthogonal_camera.view_to_world_scale,y="ortho"),$.subVec3(v,u),a.yUp&&(v=vp(v),h=vp(h),I=vp(I)),s){var m=i.pick({pickSurface:!0,origin:v,direction:h});h=m?m.worldPos:$.addVec3(v,h,op)}else h=$.addVec3(v,h,op);o?(a.eye=v,a.look=h,a.up=I,a.projection=y):r.cameraFlight.flyTo({eye:v,look:h,up:I,duration:n.duration,projection:y})}}}},{key:"_withBCFComponent",value:function(e,t,n){var r=this.viewer,i=r.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){var a=t.authoring_tool_id,s=i.objects[a];if(s)return void n(s);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[a])return void i.withObjects(r.metaScene.getObjectIDsInSubtree(a),n)}if(t.ifc_guid){var o=t.ifc_guid,l=i.objects[o];if(l)return void n(l);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[o])return void i.withObjects(r.metaScene.getObjectIDsInSubtree(o),n);Object.keys(i.models).forEach((function(t){var a=$.globalizeObjectId(t,o),s=i.objects[a];s?n(s):e.updateCompositeObjects&&r.metaScene.metaObjects[a]&&i.withObjects(r.metaScene.getObjectIDsInSubtree(a),n)}))}}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this)}}]),n}();function pp(e){return{x:e[0],y:e[1],z:e[2]}}function Ap(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function dp(e){return new Float64Array([e[0],-e[2],e[1]])}function vp(e){return new Float64Array([e[0],e[2],-e[1]])}function hp(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 Ip=$.vec3(),yp=function(e,t,n,r){var i=e-n,a=t-r;return Math.sqrt(i*i+a*a)},mp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e.viewer.scene,i)).plugin=e,r._container=i.container,!r._container)throw"config missing: container";r._eventSubs={};var a=r.plugin.viewer.scene;r._originMarker=new qe(a,i.origin),r._targetMarker=new qe(a,i.target),r._originWorld=$.vec3(),r._targetWorld=$.vec3(),r._wp=new Float64Array(24),r._vp=new Float64Array(24),r._pp=new Float64Array(24),r._cp=new Float64Array(8),r._xAxisLabelCulled=!1,r._yAxisLabelCulled=!1,r._zAxisLabelCulled=!1,r._color=i.color||r.plugin.defaultColor;var s=i.onMouseOver?function(e){i.onMouseOver(e,w(r)),r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,o=i.onMouseLeave?function(e){i.onMouseLeave(e,w(r)),r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,l=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},u=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},c=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},f=i.onContextMenu?function(e){i.onContextMenu(e,w(r))}:null,p=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return r._originDot=new Ze(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._targetDot=new Ze(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._lengthWire=new Je(r._container,{color:r._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._xAxisWire=new Je(r._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._yAxisWire=new Je(r._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._zAxisWire=new Je(r._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._lengthLabel=new $e(r._container,{fillColor:r._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._xAxisLabel=new $e(r._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._yAxisLabel=new $e(r._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._zAxisLabel=new $e(r._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._wpDirty=!1,r._vpDirty=!1,r._cpDirty=!1,r._sectionPlanesDirty=!0,r._visible=!1,r._originVisible=!1,r._targetVisible=!1,r._wireVisible=!1,r._axisVisible=!1,r._xAxisVisible=!1,r._yAxisVisible=!1,r._zAxisVisible=!1,r._axisEnabled=!0,r._labelsVisible=!1,r._labelsOnWires=!1,r._clickable=!1,r._originMarker.on("worldPos",(function(e){r._originWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._targetMarker.on("worldPos",(function(e){r._targetWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._onViewMatrix=a.camera.on("viewMatrix",(function(){r._vpDirty=!0,r._needUpdate(0)})),r._onProjMatrix=a.camera.on("projMatrix",(function(){r._cpDirty=!0,r._needUpdate()})),r._onCanvasBoundary=a.canvas.on("boundary",(function(){r._cpDirty=!0,r._needUpdate(0)})),r._onMetricsUnits=a.metrics.on("units",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsScale=a.metrics.on("scale",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsOrigin=a.metrics.on("origin",(function(){r._cpDirty=!0,r._needUpdate()})),r._onSectionPlaneUpdated=a.on("sectionPlaneUpdated",(function(){r._sectionPlanesDirty=!0,r._needUpdate()})),r.approximate=i.approximate,r.visible=i.visible,r.originVisible=i.originVisible,r.targetVisible=i.targetVisible,r.wireVisible=i.wireVisible,r.axisVisible=i.axisVisible,r.xAxisVisible=i.xAxisVisible,r.yAxisVisible=i.yAxisVisible,r.zAxisVisible=i.zAxisVisible,r.labelsVisible=i.labelsVisible,r.labelsOnWires=i.labelsOnWires,r}return P(n,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._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._wp))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],n=this._targetMarker.viewPos[2];if(t>-.3||n>-.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 r=this._pp,i=this._cp,a=e.canvas.canvas.getBoundingClientRect(),s=this._container.getBoundingClientRect(),o=a.top-s.top,l=a.left-s.left,u=e.canvas.boundary,c=u[2],f=u[3],p=0,A=this.plugin.viewer.scene.metrics,d=A.scale,v=A.units,h=A.unitsInfo[v].abbrev,I=0,y=r.length;I1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e.viewer.scene)).pointerLens=i.pointerLens,r._active=!1,r._currentDistanceMeasurement=null,r._currentDistanceMeasurementInitState={wireVisible:null,axisVisible:null,xAxisVisible:null,yaxisVisible:null,zAxisVisible:null,targetVisible:null},r._initMarkerDiv(),r._onCameraControlHoverSnapOrSurface=null,r._onCameraControlHoverSnapOrSurfaceOff=null,r._onMouseDown=null,r._onMouseUp=null,r._onCanvasTouchStart=null,r._onCanvasTouchEnd=null,r._snapping=!1!==i.snapping,r._mouseState=0,r._attachPlugin(e,i),r}return P(n,[{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.margin="-200px -200px",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,n=this.scene,r=t.viewer.cameraControl,i=n.canvas.canvas;n.input;var a,s,o=!1,l=$.vec3(),u=$.vec2(),c=null;this._mouseState=0,this._onCameraControlHoverSnapOrSurface=r.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(function(t){var n=t.snappedCanvasPos||t.canvasPos;if(o=!0,l.set(t.worldPos),u.set(t.canvasPos),0===e._mouseState){var r=i.getBoundingClientRect(),a=window.pageXOffset||document.documentElement.scrollLeft,s=window.pageYOffset||document.documentElement.scrollTop,f=r.left+a,p=r.top+s;e._markerDiv.style.marginLeft="".concat(f+n[0]-5,"px"),e._markerDiv.style.marginTop="".concat(p+n[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"),c=t.entity}else e._markerDiv.style.marginLeft="-10000px",e._markerDiv.style.marginTop="-10000px";i.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.marginLeft="-10000px",e._markerDiv.style.marginTop="-10000px")})),i.addEventListener("mousedown",this._onMouseDown=function(e){1===e.which&&(a=e.clientX,s=e.clientY)}),i.addEventListener("mouseup",this._onMouseUp=function(n){1===n.which&&(n.clientX>a+20||n.clientXs+20||n.clientY1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"DistanceMeasurements",e))._pointerLens=i.pointerLens,r._container=i.container||document.body,r._defaultControl=null,r._measurements={},r.labelMinAxisLength=i.labelMinAxisLength,r.defaultVisible=!1!==i.defaultVisible,r.defaultOriginVisible=!1!==i.defaultOriginVisible,r.defaultTargetVisible=!1!==i.defaultTargetVisible,r.defaultWireVisible=!1!==i.defaultWireVisible,r.defaultLabelsVisible=!1!==i.defaultLabelsVisible,r.defaultAxisVisible=!1!==i.defaultAxisVisible,r.defaultXAxisVisible=!1!==i.defaultXAxisVisible,r.defaultYAxisVisible=!1!==i.defaultYAxisVisible,r.defaultZAxisVisible=!1!==i.defaultZAxisVisible,r.defaultColor=void 0!==i.defaultColor?i.defaultColor:"#00BBFF",r.zIndex=i.zIndex||1e4,r.defaultLabelsOnWires=!1!==i.defaultLabelsOnWires,r._onMouseOver=function(e,t){r.fire("mouseOver",{plugin:w(r),distanceMeasurement:t,measurement:t,event:e})},r._onMouseLeave=function(e,t){r.fire("mouseLeave",{plugin:w(r),distanceMeasurement:t,measurement:t,event:e})},r._onContextMenu=function(e,t){r.fire("contextMenu",{plugin:w(r),distanceMeasurement:t,measurement:t,event:e})},r}return P(n,[{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 gp(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 n=t.origin,r=t.target,i=new mp(this,{id:t.id,plugin:this,container:this._container,origin:{entity:n.entity,worldPos:n.worldPos},target:{entity:r.entity,worldPos:r.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[i.id]=i,i.on("destroyed",(function(){delete e._measurements[i.id]})),this.fire("measurementCreated",i),i}},{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,n=Object.entries(this.measurements);t1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,"FastNav",e))._hideColorTexture=!1!==i.hideColorTexture,r._hidePBR=!1!==i.hidePBR,r._hideSAO=!1!==i.hideSAO,r._hideEdges=!1!==i.hideEdges,r._hideTransparentObjects=!!i.hideTransparentObjects,r._scaleCanvasResolution=!!i.scaleCanvasResolution,r._scaleCanvasResolutionFactor=i.scaleCanvasResolutionFactor||.6,r._delayBeforeRestore=!1!==i.delayBeforeRestore,r._delayBeforeRestoreSeconds=i.delayBeforeRestoreSeconds||.5;var a=1e3*r._delayBeforeRestoreSeconds,s=!1,o=function(){a=1e3*r._delayBeforeRestoreSeconds,s||(e.scene._renderer.setColorTextureEnabled(!r._hideColorTexture),e.scene._renderer.setPBREnabled(!r._hidePBR),e.scene._renderer.setSAOEnabled(!r._hideSAO),e.scene._renderer.setTransparentEnabled(!r._hideTransparentObjects),e.scene._renderer.setEdgesEnabled(!r._hideEdges),r._scaleCanvasResolution?e.scene.canvas.resolutionScale=r._scaleCanvasResolutionFactor:e.scene.canvas.resolutionScale=1,s=!0)},l=function(){e.scene.canvas.resolutionScale=1,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};r._onCanvasBoundary=e.scene.canvas.on("boundary",o),r._onCameraMatrix=e.scene.camera.on("matrix",o),r._onSceneTick=e.scene.on("tick",(function(e){s&&(a-=e.deltaTime,(!r._delayBeforeRestore||a<=0)&&l())}));var u=!1;return r._onSceneMouseDown=e.scene.input.on("mousedown",(function(){u=!0})),r._onSceneMouseUp=e.scene.input.on("mouseup",(function(){u=!1})),r._onSceneMouseMove=e.scene.input.on("mousemove",(function(){u&&o()})),r}return P(n,[{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:"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),d(g(n.prototype),"destroy",this).call(this)}}]),n}(),bp=function(){function e(){b(this,e)}return P(e,[{key:"getMetaModel",value:function(e,t,n){le.loadJSON(e,(function(e){t(e)}),(function(e){n(e)}))}},{key:"getGLTF",value:function(e,t,n){le.loadArraybuffer(e,(function(e){t(e)}),(function(e){n(e)}))}},{key:"getGLB",value:function(e,t,n){le.loadArraybuffer(e,(function(e){t(e)}),(function(e){n(e)}))}},{key:"getArrayBuffer",value:function(e,t,n,r){!function(e,t,n,r){var i=function(){};n=n||i,r=r||i;var a=/^data:(.*?)(;base64)?,(.*)$/,s=t.match(a);if(s){var o=!!s[2],l=s[3];l=window.decodeURIComponent(l),o&&(l=window.atob(l));try{for(var u=new ArrayBuffer(l.length),c=new Uint8Array(u),f=0;f0&&void 0!==arguments[0]?arguments[0]:{};b(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 P(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 n=this._messages[this._locale];if(!n)return null;var r=Pp(e,n);return r?t?Cp(r,t):r:null}},{key:"translatePlurals",value:function(e,t,n){var r=this._messages[this._locale];if(!r)return null;var i=Pp(e,r);return(i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one)?(i=Cp(i,[t]),n&&(i=Cp(i,n)),i):null}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==n&&(this._events[e]=t||!0);var r=this._eventSubs[e];if(r)for(var i in r){if(r.hasOwnProperty(i))r[i].callback(t)}}},{key:"on",value:function(e,t){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new G),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});var n=this._eventSubs[e];n||(n={},this._eventSubs[e]=n);var r=this._eventSubIDMap.addItem();n[r]={callback:t},this._eventSubEvents[r]=e;var i=this._events[e];return void 0!==i&&t(i),r}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var n=this._eventSubs[t];n&&delete n[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function Pp(e,t){if(t[e])return t[e];for(var n=e.split("."),r=t,i=0,a=n.length;r&&i1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,n){return"{{"===e?"{":"}}"===e?"}":t[n]}))}var _p=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).t=i.t,r}return P(n,[{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 n=e-t,r=e+t;n<0&&(n=0),r>1&&(r=1);var i=this.getPoint(n),a=this.getPoint(r),s=$.subVec3(a,i,[]);return $.normalizeVec3(s,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,n=[];for(t=0;t<=e;t++)n.push(this.getPoint(t/e));return n}},{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,n,r=[],i=this.getPoint(0),a=0;for(r.push(0),n=1;n<=e;n++)t=this.getPoint(n/e),a+=$.lenVec3($.subVec3(t,i,[])),r.push(a),i=t;return this.cacheArcLengths=r,r}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var n,r=this._getLengths(),i=0,a=r.length;n=t||e*r[a-1];for(var s,o=0,l=a-1;o<=l;)if((s=r[i=Math.floor(o+(l-o)/2)]-n)<0)o=i+1;else{if(!(s>0)){l=i;break}l=i-1}if(r[i=l]===n)return i/(a-1);var u=r[i];return(i+(n-u)/(r[i+1]-u))/(a-1)}}]),n}(),Rp=function(e){h(n,_p);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).points=i.points,r.t=i.t,r}return P(n,[{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 n=(t.length-1)*e,r=Math.floor(n),i=n-r,a=t[0===r?r:r-1],s=t[r],o=t[r>t.length-2?t.length-1:r+1],l=t[r>t.length-3?t.length-1:r+2],u=$.vec3();return u[0]=$.catmullRomInterpolate(a[0],s[0],o[0],l[0],i),u[1]=$.catmullRomInterpolate(a[1],s[1],o[1],l[1],i),u[2]=$.catmullRomInterpolate(a[2],s[2],o[2],l[2],i),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}}}]),n}(),Bp=$.vec3(),Op=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._frames=[],r._eyeCurve=new Rp(w(r)),r._lookCurve=new Rp(w(r)),r._upCurve=new Rp(w(r)),i.frames&&(r.addFrames(i.frames),r.smoothFrameTimes(1)),r}return P(n,[{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,n,r){var i={t:e,eye:t.slice(0),look:n.slice(0),up:r.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}},{key:"addFrames",value:function(e){for(var t,n=0,r=e.length;n1?1:e,t.eye=this._eyeCurve.getPoint(e,Bp),t.look=this._lookCurve.getPoint(e,Bp),t.up=this._upCurve.getPoint(e,Bp)}},{key:"sampleFrame",value:function(e,t,n,r){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,n),this._upCurve.getPoint(e,r)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=$.vec3(),n=0;this._frames[0].t=0;for(var r=[],i=1,a=this._frames.length;i1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._look1=$.vec3(),r._eye1=$.vec3(),r._up1=$.vec3(),r._look2=$.vec3(),r._eye2=$.vec3(),r._up2=$.vec3(),r._orthoScale1=1,r._orthoScale2=1,r._flying=!1,r._flyEyeLookUp=!1,r._flyingEye=!1,r._flyingLook=!1,r._callback=null,r._callbackScope=null,r._time1=null,r._time2=null,r.easing=!1!==i.easing,r.duration=i.duration,r.fit=i.fit,r.fitFOV=i.fitFOV,r.trail=i.trail,r}return P(n,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,n){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=n;var r,i,a,s,o,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)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)i=e.eye,a=e.look,s=e.up;else if(e.eye)i=e.eye;else if(e.look)a=e.look;else{var c=e;if((le.isNumeric(c)||le.isString(c))&&(o=c,!(c=this.scene.components[o])))return this.error("Component not found: "+le.inQuotes(o)),void(t&&(n?t.call(n):t()));u||(r=c.aabb||this.scene.aabb)}var f=e.poi;if(r){if(r[3]=1;e>1&&(e=1);var r=this.easing?n._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?($.subVec3(i.eye,i.look,Mp),i.eye=$.lerpVec3(r,0,1,this._eye1,this._eye2,Lp),i.look=$.subVec3(Lp,Mp,Np)):this._flyingLook&&(i.look=$.lerpVec3(r,0,1,this._look1,this._look2,Np),i.up=$.lerpVec3(r,0,1,this._up1,this._up2,xp)):this._flyingEyeLookUp&&(i.eye=$.lerpVec3(r,0,1,this._eye1,this._eye2,Lp),i.look=$.lerpVec3(r,0,1,this._look1,this._look2,Np),i.up=$.lerpVec3(r,0,1,this._up1,this._up2,xp)),this._projection2){var a="ortho"===this._projection2?n._easeOutExpo(e,0,1,1):n._easeInCubic(e,0,1,1);i.customProjection.matrix=$.lerpMat4(a,0,1,this._projMatrix1,this._projMatrix2)}else i.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return i.ortho.scale=this._orthoScale2,void this.stop();he.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(),d(g(n.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,n,r){return n*(e/=r)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,n,r){return n*(1-Math.pow(2,-10*e/r))+t}}]),n}(),Hp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cameraFlightAnimation=new Fp(w(r)),r._t=0,r.state=n.SCRUBBING,r._playingFromT=0,r._playingToT=0,r._playingRate=i.playingRate||1,r._playingDir=1,r._lastTime=null,r.cameraPath=i.cameraPath,r._tick=r.scene.on("tick",r._updateT,w(r)),r}return P(n,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,r,i=performance.now(),a=this._lastTime?.001*(i-this._lastTime):0;if(this._lastTime=i,0!==a)switch(this.state){case n.SCRUBBING:return;case n.PLAYING:if(this._t+=this._playingRate*a,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=n.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case n.PLAYING_TO:r=this._t+this._playingRate*a*this._playingDir,(this._playingDir<0&&r<=this._playingToT||this._playingDir>0&&r>=this._playingToT)&&(r=this._playingToT,this.state=n.SCRUBBING,this.fire("stopped")),this._t=r,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(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=n.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=n.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var n=t.frames[e];n?this.playToT(n.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var r=this._cameraPath;if(r){var i=r.frames[e];i?(this.state=n.SCRUBBING,this._cameraFlightAnimation.flyTo(i,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=n.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=n.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=n.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),n}();Hp.STOPPED=0,Hp.SCRUBBING=1,Hp.PLAYING=2,Hp.PLAYING_TO=3;var Up=$.vec3(),Gp=$.vec3();$.vec3();var kp=$.vec3([0,-1,0]),jp=$.vec4([0,0,0,1]),Vp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._src=null,r._image=null,r._pos=$.vec3(),r._origin=$.vec3(),r._rtcPos=$.vec3(),r._dir=$.vec3(),r._size=1,r._imageSize=$.vec2(),r._texture=new Oa(w(r)),r._plane=new Zi(w(r),{geometry:new Rn(w(r),ja({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Ln(w(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0}),clippable:i.clippable}),r._grid=new Zi(w(r),{geometry:new Rn(w(r),ka({size:1,divisions:10})),material:new Ln(w(r),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:i.clippable}),r._node=new va(w(r),{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[r._plane,r._grid]}),r._gridVisible=!1,r.visible=!0,r.gridVisible=i.gridVisible,r.position=i.position,r.rotation=i.rotation,r.dir=i.dir,r.size=i.size,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{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 n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),Se(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,n=[-this._dir[0],-this._dir[1],-this._dir[2]];$.subVec3(t,this.position,Up);var r=-$.dotVec3(n,Up);$.normalizeVec3(n),$.mulVec3Scalar(n,r,Gp),$.vec3PairToQuaternion(kp,e,jp),this._node.quaternion=jp}}},{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(){d(g(n.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],n=this._imageSize[1];if(t>n){var r=n/t;this._node.scale=[e,1,e*r]}else{var i=t/n;this._node.scale=[e*i,1,e]}}}]),n}(),Qp=function(e){h(n,vn);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=w(r=t.call(this,e,i));r._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var s=r.scene.camera,o=r.scene.canvas;return r._onCameraViewMatrix=s.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=s.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=o.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new zt({type:"point",pos:$.vec3([1,1,1]),color:$.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(a._shadowViewMatrixDirty){a._shadowViewMatrix||(a._shadowViewMatrix=$.identityMat4());var e=a._state.pos,t=s.look,n=s.up;$.lookAtMat4v(e,t,n,a._shadowViewMatrix),a._shadowViewMatrixDirty=!1}return a._shadowViewMatrix},getShadowProjMatrix:function(){if(a._shadowProjMatrixDirty){a._shadowProjMatrix||(a._shadowProjMatrix=$.identityMat4());var e=a.scene.canvas.canvas;$.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,a._shadowProjMatrix),a._shadowProjMatrixDirty=!1}return a._shadowProjMatrix},getShadowRenderBuf:function(){return a._shadowRenderBuf||(a._shadowRenderBuf=new Gt(a.scene.canvas.canvas,a.scene.canvas.gl,{size:[1024,1024]})),a._shadowRenderBuf}}),r.pos=i.pos,r.color=i.color,r.intensity=i.intensity,r.constantAttenuation=i.constantAttenuation,r.linearAttenuation=i.linearAttenuation,r.quadraticAttenuation=i.quadraticAttenuation,r.castsShadow=i.castsShadow,r.scene._lightCreated(w(r)),r}return P(n,[{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),d(g(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}();function Wp(e){return 0==(e&e-1)}function zp(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var Kp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=(r=t.call(this,e,i)).scene.canvas.gl;return r._state=new zt({texture:new Da({gl:a,target:a.TEXTURE_CUBE_MAP}),flipY:r._checkFlipY(i.minFilter),encoding:r._checkEncoding(i.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),r._src=i.src,r._images=[],r._loadSrc(i.src),re.memory.textures++,r}return P(n,[{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,n=this.scene.canvas.gl;this._images=[];for(var r=!1,i=0,a=function(a){var s,o,l=new Image;l.onload=(s=l,o=a,function(){if(!r&&(s=function(e){if(!Wp(e.width)||!Wp(e.height)){var t=document.createElement("canvas");t.width=zp(e.width),t.height=zp(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(s),t._images[o]=s,6==++i)){var e=t._state.texture;e||(e=new Da({gl:n,target:n.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}),l.onerror=function(){r=!0},l.src=e[a]},s=0;s1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightsState.addReflectionMap(r._state),r.scene._reflectionMapCreated(w(r)),r}return P(n,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),n}(),Xp=function(e){h(n,Kp);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightMapCreated(w(r)),r}return P(n,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),n}(),qp=function(e){h(n,qe);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,{entity:i.entity,occludable:i.occludable,worldPos:i.worldPos}))._occluded=!1,r._visible=!0,r._src=null,r._image=null,r._pos=$.vec3(),r._origin=$.vec3(),r._rtcPos=$.vec3(),r._dir=$.vec3(),r._size=1,r._imageSize=$.vec2(),r._texture=new Oa(w(r),{src:i.src}),r._geometry=new Rn(w(r),{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]}),r._mesh=new Zi(w(r),{geometry:r._geometry,material:new Ln(w(r),{ambient:[.9,.3,.9],shininess:30,diffuseMap:r._texture,backfaces:!0}),scale:[1,1,1],position:i.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),r.visible=!0,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,r.size=i.size,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,d(g(n.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 n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.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],n=this._imageSize[1],r=n/t;this._geometry.positions=t>n?[e,e*r,0,-e,e*r,0,-e,-e*r,0,e,-e*r,0]:[e/r,e,0,-e/r,e,0,-e/r,-e,0,e/r,-e,0]}}]),n}(),Jp=function(){function e(t){b(this,e),this._eye=$.vec3(),this._look=$.vec3(),this._up=$.vec3(),this._projection={},t&&this.saveCamera(t)}return P(e,[{key:"saveCamera",value:function(e){var t=e.camera,n=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:n.fov,fovAxis:n.fovAxis,near:n.near,far:n.far};break;case"ortho":this._projection={projection:"ortho",scale:n.scale,near:n.near,far:n.far};break;case"frustum":this._projection={projection:"frustum",left:n.left,right:n.right,top:n.top,bottom:n.bottom,near:n.near,far:n.far};break;case"custom":this._projection={projection:"custom",matrix:n.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var n=e.camera,r=this._projection;function i(){switch(r.type){case"perspective":n.perspective.fov=r.fov,n.perspective.fovAxis=r.fovAxis,n.perspective.near=r.near,n.perspective.far=r.far;break;case"ortho":n.ortho.scale=r.scale,n.ortho.near=r.near,n.ortho.far=r.far;break;case"frustum":n.frustum.left=r.left,n.frustum.right=r.right,n.frustum.top=r.top,n.frustum.bottom=r.bottom,n.frustum.near=r.near,n.frustum.far=r.far;break;case"custom":n.customProjection.matrix=r.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:r.scale,projection:r.projection},(function(){i(),t()})):(n.eye=this._eye,n.look=this._look,n.up=this._up,i(),n.projection=r.projection)}}]),e}(),Zp=$.vec3(),$p=function(){function e(t){if(b(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 n=t.metaScene.scene;this.saveObjects(n,t)}}return P(e,[{key:"saveObjects",value:function(e,t,n){this.numObjects=0,this._mask=n?le.apply(n,{}):null;for(var r=!n||n.visible,i=!n||n.edges,a=!n||n.xrayed,s=!n||n.highlighted,o=!n||n.selected,l=!n||n.clippable,u=!n||n.pickable,c=!n||n.colorize,f=!n||n.opacity,p=t.metaObjects,A=e.objects,d=0,v=p.length;d1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.v3=i.v3,r.t=i.t,r}return P(n,[{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}}}]),n}(),rA=function(e){h(n,_p);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cachedLengths=[],r._dirty=!0,r._curves=[],r._t=0,r._dirtySubs=[],r._destroyedSubs=[],r.curves=i.curves||[],r.t=i.t,r}return P(n,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,n,r;for(e=e||[],n=0,r=this._curves.length;n1?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,n=e*this.length,r=this._getCurveLengths(),i=0;i=n){var a=1-(r[i]-n)/(t=this._curves[i]).length;return t.getPointAt(a)}i++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],n=0,r=this._curves.length;for(e=0;e1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.t=i.t,r}return P(n,[{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}}}]),n}(),aA=function(e){h(n,ip);var t=y(n);function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),t.call(this,e,r)}return P(n)}(),sA=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._skyboxMesh=new Zi(w(r),{geometry:new Rn(w(r),{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 Ln(w(r),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Oa(w(r),{src:i.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:i.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),r.size=i.size,r.active=i.active,r}return P(n,[{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}}]),n}(),oA=function(){function e(){b(this,e)}return P(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),lA=$.vec4(),uA=$.vec4(),cA=$.vec3(),fA=$.vec3(),pA=$.vec3(),AA=$.vec4(),dA=$.vec4(),vA=$.vec4(),hA=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"dollyToCanvasPos",value:function(e,t,n){var r=!1,i=this._scene.camera;if(e){var a=$.subVec3(e,i.eye,cA);r=$.lenVec3(a)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 Ln(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 n=this.getPivotPos();this._cameraOffset[2]+=$.distVec3(e.eye,n),t=$.inverseMat4(t);var r=$.transformVec3(t,this._cameraOffset),i=$.vec3();if($.subVec3(e.eye,n,i),$.addVec3(i,r),e.zUp){var a=i[1];i[1]=i[2],i[2]=a}this._radius=$.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}},{key:"_cameraLookingDownwards",value:function(){var e=this._scene.camera,t=$.normalizeVec3($.subVec3(e.look,e.eye,IA)),n=$.cross3Vec3(t,e.worldUp,yA);return $.sqLenVec3(n)<=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,n=Math.abs($.distVec3(this._scene.center,t.eye)),r=t.project.transposedMatrix,i=r.subarray(8,12),a=r.subarray(12),s=[0,0,-1,1],o=$.dotVec4(s,i)/$.dotVec4(s,a),l=wA;t.project.unproject(e,o,gA,EA,l);var u=$.normalizeVec3($.subVec3(l,t.eye,IA)),c=$.addVec3(t.eye,$.mulVec3Scalar(u,n,yA),mA);this.setPivotPos(c)}},{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 n=this._scene.camera,r=-e,i=-t;1===n.worldUp[2]&&(r=-r),this._azimuth+=.01*-r,this._polar+=.01*i,this._polar=$.clamp(this._polar,.001,Math.PI-.001);var a=[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===n.worldUp[2]){var s=a[1];a[1]=a[2],a[2]=s}var o=$.lenVec3($.subVec3(n.look,n.eye,$.vec3())),l=this.getPivotPos();$.addVec3(a,l);var u=$.lookAtMat4v(a,l,n.worldUp);u=$.inverseMat4(u);var c=$.transformVec3(u,this._cameraOffset);u[12]-=c[0],u[13]-=c[1],u[14]-=c[2];var f=[u[8],u[9],u[10]];n.eye=[u[12],u[13],u[14]],$.subVec3(n.eye,$.mulVec3Scalar(f,o),n.look),n.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}(),bA=function(){function e(t,n){b(this,e),this._scene=t.scene,this._cameraControl=t,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=n,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 P(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 n=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});n&&(n.snappedToEdge||n.snappedToVertex)?(this.snapPickResult=n,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var r=this.pickResult.canvasPos;if(r[0]===this.pickCursorPos[0]&&r[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 i=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(i[0]===this.pickCursorPos[0]&&i[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 yt;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}(),DA=$.vec2(),PA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s,o,l,u=n.pickController,c=0,f=0,p=0,A=0,d=!1,v=$.vec3(),h=!0,I=this._scene.canvas.canvas,y=[];function m(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];I.style.cursor="move",w(),e&&g()}function w(){c=i.pointerCanvasPos[0],f=i.pointerCanvasPos[1],p=i.pointerCanvasPos[0],A=i.pointerCanvasPos[1]}function g(){u.pickCursorPos=i.pointerCanvasPos,u.schedulePickSurface=!0,u.update(),u.picked&&u.pickedSurface&&u.pickResult&&u.pickResult.worldPos?(d=!0,v.set(u.pickResult.worldPos)):d=!1}document.addEventListener("keydown",this._documentKeyDownHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!0}}),document.addEventListener("keyup",this._documentKeyUpHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!1}}),I.addEventListener("mousedown",this._mouseDownHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:y[t.input.KEY_SHIFT]||r.planView?(s=!0,m()):(s=!0,m(!1));break;case 2:o=!0,m();break;case 3:l=!0,r.panRightClick&&m()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=function(){if(r.active&&r.pointerEnabled&&(s||o||l)){var e=t.canvas.boundary,n=e[2],u=e[3],p=i.pointerCanvasPos[0],A=i.pointerCanvasPos[1];if(y[t.input.KEY_SHIFT]||r.planView||!r.panRightClick&&o||r.panRightClick&&l){var h=p-c,I=A-f,m=t.camera;if("perspective"===m.projection){var w=Math.abs(d?$.lenVec3($.subVec3(v,t.camera.eye,[])):t.camera.eyeLookDist)*Math.tan(m.perspective.fov/2*Math.PI/180);a.panDeltaX+=1.5*h*w/u,a.panDeltaY+=1.5*I*w/u}else a.panDeltaX+=.5*m.ortho.scale*(h/u),a.panDeltaY+=.5*m.ortho.scale*(I/u)}else!s||o||l||r.planView||(r.firstPerson?(a.rotateDeltaY-=(p-c)/n*r.dragRotationRate/2,a.rotateDeltaX+=(A-f)/u*(r.dragRotationRate/4)):(a.rotateDeltaY-=(p-c)/n*(1.5*r.dragRotationRate),a.rotateDeltaX+=(A-f)/u*(1.5*r.dragRotationRate)));c=p,f=A}}),I.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){r.active&&r.pointerEnabled&&i.mouseover&&(h=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:case 2:case 3:s=!1,o=!1,l=!1}}),I.addEventListener("mouseup",this._mouseUpHandler=function(e){if(r.active&&r.pointerEnabled){if(3===e.which){!function(e,t){if(e){for(var n=e.target,r=0,i=0,a=0,s=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,a+=n.scrollLeft,s+=n.scrollTop,n=n.offsetParent;t[0]=e.pageX+a-r,t[1]=e.pageY+s-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,DA);var t=DA[0],i=DA[1];Math.abs(t-p)<3&&Math.abs(i-A)<3&&n.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:DA,event:e},!0)}I.style.removeProperty("cursor")}}),I.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var E=1/60,T=null;I.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled){var t=performance.now()/1e3,n=null!==T?t-T:0;T=t,n>.05&&(n=.05),n0?n.cameraFlight.flyTo(SA,(function(){n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot()})):(n.cameraFlight.jumpTo(SA),n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot())}}}))}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.input.off(this._onSceneKeyDown)}}]),e}(),LA=function(){function e(t,n,r,i,a){var s=this;b(this,e),this._scene=t;var o=n.pickController,l=n.pivotController,u=n.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;var c=!1,f=!1,p=this._scene.canvas.canvas,A=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e&&e.entity?e.entity.aabb:t.aabb;if(r){var a=t.camera;$.subVec3(a.eye,a.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})},d=t.tickify(this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!c&&!f){var n=u.hasSubs("hover"),a=u.hasSubs("hoverEnter"),l=u.hasSubs("hoverOut"),p=u.hasSubs("hoverOff"),A=u.hasSubs("hoverSurface"),d=u.hasSubs("hoverSnapOrSurface");if(n||a||l||p||A||d)if(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=A,o.scheduleSnapOrPick=d,o.update(),o.pickResult){if(o.pickResult.entity){var v=o.pickResult.entity.id;s._lastPickedEntityId!==v&&(void 0!==s._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),u.fire("hoverEnter",o.pickResult,!0),s._lastPickedEntityId=v)}u.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&u.fire("hoverSurface",o.pickResult,!0)}else void 0!==s._lastPickedEntityId&&(u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),s._lastPickedEntityId=void 0),u.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)}});p.addEventListener("mousemove",d),p.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(c=!0),3===e.which&&(f=!0),1===e.which&&r.active&&r.pointerEnabled&&(i.mouseDownClientX=e.clientX,i.mouseDownClientY=e.clientY,i.mouseDownCursorX=i.pointerCanvasPos[0],i.mouseDownCursorY=i.pointerCanvasPos[1],!r.firstPerson&&r.followPointer&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===e.which))){var n=o.pickResult;n&&n.worldPos?(l.setPivotPos(n.worldPos),l.startPivot()):(r.smartPivot?l.setCanvasPivotPos(i.pointerCanvasPos):l.setPivotPos(t.camera.look),l.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(c=!1),3===e.which&&(f=!1),l.getPivoting()&&l.endPivot()}),p.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(r.active&&r.pointerEnabled&&(1===e.which&&(l.hidePivot(),!(Math.abs(e.clientX-i.mouseDownClientX)>3||Math.abs(e.clientY-i.mouseDownClientY)>3)))){var a=u.hasSubs("picked"),c=u.hasSubs("pickedNothing"),f=u.hasSubs("pickedSurface"),p=u.hasSubs("doublePicked"),d=u.hasSubs("doublePickedSurface"),v=u.hasSubs("doublePickedNothing");if(!(r.doublePickFlyTo||p||d||v))return(a||c||f)&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=f,o.update(),o.pickResult?(u.fire("picked",o.pickResult,!0),o.pickedSurface&&u.fire("pickedSurface",o.pickResult,!0)):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0)),void(s._clicks=0);if(s._clicks++,1===s._clicks){o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo,o.schedulePickSurface=f,o.update();var h=o.pickResult,I=o.pickedSurface;s._timeout=setTimeout((function(){h?(u.fire("picked",h,!0),I&&(u.fire("pickedSurface",h,!0),!r.firstPerson&&r.followPointer&&(n.pivotController.setPivotPos(h.worldPos),n.pivotController.startPivot()&&n.pivotController.showPivot()))):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0),s._clicks=0}),r.doubleClickTimeFrame)}else{if(null!==s._timeout&&(window.clearTimeout(s._timeout),s._timeout=null),o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo||p||d,o.schedulePickSurface=o.schedulePickEntity&&d,o.update(),o.pickResult){if(u.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&u.fire("doublePickedSurface",o.pickResult,!0),r.doublePickFlyTo&&(A(o.pickResult),!r.firstPerson&&r.followPointer)){var y=o.pickResult.entity.aabb,m=$.getAABB3Center(y);n.pivotController.setPivotPos(m),n.pivotController.startPivot()&&n.pivotController.showPivot()}}else if(u.fire("doublePickedNothing",{canvasPos:i.pointerCanvasPos},!0),r.doublePickFlyTo&&(A(),!r.firstPerson&&r.followPointer)){var w=t.aabb,g=$.getAABB3Center(w);n.pivotController.setPivotPos(g),n.pivotController.startPivot()&&n.pivotController.showPivot()}s._clicks=0}}},!1)}return P(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}(),xA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.input,o=[],l=t.canvas.canvas,u=!0;this._onSceneMouseMove=s.on("mousemove",(function(){u=!0})),this._onSceneKeyDown=s.on("keydown",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover&&(o[e]=!0,e===s.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=s.on("keyup",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(o[e]=!1,e===s.KEY_SHIFT&&(l.style.cursor=null),n.pivotController.getPivoting()&&n.pivotController.endPivot())})),this._onTick=t.on("tick",(function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover){var l=n.cameraControl,c=e.deltaTime/1e3;if(!r.planView){var f=l._isKeyDownForAction(l.ROTATE_Y_POS,o),p=l._isKeyDownForAction(l.ROTATE_Y_NEG,o),A=l._isKeyDownForAction(l.ROTATE_X_POS,o),d=l._isKeyDownForAction(l.ROTATE_X_NEG,o),v=c*r.keyboardRotationRate;(f||p||A||d)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),f?a.rotateDeltaY+=v:p&&(a.rotateDeltaY-=v),A?a.rotateDeltaX+=v:d&&(a.rotateDeltaX-=v),!r.firstPerson&&r.followPointer&&n.pivotController.startPivot())}if(!o[s.KEY_CTRL]&&!o[s.KEY_ALT]){var h=l._isKeyDownForAction(l.DOLLY_BACKWARDS,o),I=l._isKeyDownForAction(l.DOLLY_FORWARDS,o);if(h||I){var y=c*r.keyboardDollyRate;!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),I?a.dollyDelta-=y:h&&(a.dollyDelta+=y),u&&(i.followPointerDirty=!0,u=!1)}}var m=l._isKeyDownForAction(l.PAN_FORWARDS,o),w=l._isKeyDownForAction(l.PAN_BACKWARDS,o),g=l._isKeyDownForAction(l.PAN_LEFT,o),E=l._isKeyDownForAction(l.PAN_RIGHT,o),T=l._isKeyDownForAction(l.PAN_UP,o),b=l._isKeyDownForAction(l.PAN_DOWN,o),D=(o[s.KEY_ALT]?.3:1)*c*r.keyboardPanRate;(m||w||g||E||T||b)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),b?a.panDeltaY+=D:T&&(a.panDeltaY+=-D),E?a.panDeltaX+=-D:g&&(a.panDeltaX+=D),w?a.panDeltaZ+=D:m&&(a.panDeltaZ+=-D))}}))}return P(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}(),MA=$.vec3(),FA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.camera,o=n.pickController,l=n.pivotController,u=n.panController,c=1,f=1,p=null;this._onTick=t.on("tick",(function(){if(r.active&&r.pointerEnabled){var e="default";if(Math.abs(a.dollyDelta)<.001&&(a.dollyDelta=0),Math.abs(a.rotateDeltaX)<.001&&(a.rotateDeltaX=0),Math.abs(a.rotateDeltaY)<.001&&(a.rotateDeltaY=0),0===a.rotateDeltaX&&0===a.rotateDeltaY||(a.dollyDelta=0),r.followPointer&&--c<=0&&(c=1,0!==a.dollyDelta)){if(0===a.rotateDeltaY&&0===a.rotateDeltaX&&r.followPointer&&i.followPointerDirty&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.pickResult&&o.pickResult.worldPos?p=o.pickResult.worldPos:(f=1,p=null),i.followPointerDirty=!1),p){var n=Math.abs($.lenVec3($.subVec3(p,t.camera.eye,MA)));f=n/r.dollyProximityThreshold}fr.longTapRadius||Math.abs(I)>r.longTapRadius)&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),r.planView){var y=t.camera;if("perspective"===y.projection){var m=Math.abs(t.camera.eyeLookDist)*Math.tan(y.perspective.fov/2*Math.PI/180);a.panDeltaX+=h*m/l*r.touchPanRate,a.panDeltaY+=I*m/l*r.touchPanRate}else a.panDeltaX+=.5*y.ortho.scale*(h/l)*r.touchPanRate,a.panDeltaY+=.5*y.ortho.scale*(I/l)*r.touchPanRate}else a.rotateDeltaY-=h/o*(1*r.dragRotationRate),a.rotateDeltaX+=I/l*(1.5*r.dragRotationRate)}else if(2===d){var w=A[0],g=A[1];GA(w,u),GA(g,c);var E=$.geometricMeanVec2(p[0],p[1]),T=$.geometricMeanVec2(u,c),b=$.vec2();$.subVec2(E,T,b);var D=b[0],P=b[1],C=t.camera,_=$.distVec2([w.pageX,w.pageY],[g.pageX,g.pageY]),R=($.distVec2(p[0],p[1])-_)*r.touchDollyRate;if(a.dollyDelta=R,Math.abs(R)<1)if("perspective"===C.projection){var B=s.pickResult?s.pickResult.worldPos:t.center,O=Math.abs($.lenVec3($.subVec3(B,t.camera.eye,[])))*Math.tan(C.perspective.fov/2*Math.PI/180);a.panDeltaX-=D*O/l*r.touchPanRate,a.panDeltaY-=P*O/l*r.touchPanRate}else a.panDeltaX-=.5*C.ortho.scale*(D/l)*r.touchPanRate,a.panDeltaY-=.5*C.ortho.scale*(P/l)*r.touchPanRate;i.pointerCanvasPos=T}for(var S=0;S-1&&t-f<150&&(p>-1&&f-p<325?(jA(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=s,o.update(),o.pickResult?(o.pickResult.touchInput=!0,l.fire("doublePicked",o.pickResult),o.pickedSurface&&l.fire("doublePickedSurface",o.pickResult),r.doublePickFlyTo&&d(o.pickResult)):(l.fire("doublePickedNothing"),r.doublePickFlyTo&&d()),p=-1):$.distVec2(u[0],c)<4&&(jA(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=s,o.update(),o.pickResult?(o.pickResult.touchInput=!0,l.fire("picked",o.pickResult),o.pickedSurface&&l.fire("pickedSurface",o.pickResult)):l.fire("pickedNothing"),p=t),f=-1),u.length=n.length;for(var A=0,v=n.length;A1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i)).PAN_LEFT=0,r.PAN_RIGHT=1,r.PAN_UP=2,r.PAN_DOWN=3,r.PAN_FORWARDS=4,r.PAN_BACKWARDS=5,r.ROTATE_X_POS=6,r.ROTATE_X_NEG=7,r.ROTATE_Y_POS=8,r.ROTATE_Y_NEG=9,r.DOLLY_FORWARDS=10,r.DOLLY_BACKWARDS=11,r.AXIS_VIEW_RIGHT=12,r.AXIS_VIEW_BACK=13,r.AXIS_VIEW_LEFT=14,r.AXIS_VIEW_FRONT=15,r.AXIS_VIEW_TOP=16,r.AXIS_VIEW_BOTTOM=17,r._keyMap={},r.scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},r._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},r._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},r._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};var a=r.scene;return r._controllers={cameraControl:w(r),pickController:new bA(w(r),r._configs),pivotController:new TA(a,r._configs),panController:new hA(a),cameraFlight:new Fp(w(r),{duration:.5})},r._handlers=[new HA(r.scene,r._controllers,r._configs,r._states,r._updates),new kA(r.scene,r._controllers,r._configs,r._states,r._updates),new PA(r.scene,r._controllers,r._configs,r._states,r._updates),new NA(r.scene,r._controllers,r._configs,r._states,r._updates),new LA(r.scene,r._controllers,r._configs,r._states,r._updates),new VA(r.scene,r._controllers,r._configs,r._states,r._updates),new xA(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cameraUpdater=new FA(r.scene,r._controllers,r._configs,r._states,r._updates),r.navMode=i.navMode,i.planView&&(r.planView=i.planView),r.constrainVertical=i.constrainVertical,i.keyboardLayout?r.keyboardLayout=i.keyboardLayout:r.keyMap=i.keyMap,r.doublePickFlyTo=i.doublePickFlyTo,r.panRightClick=i.panRightClick,r.active=i.active,r.followPointer=i.followPointer,r.rotationInertia=i.rotationInertia,r.keyboardPanRate=i.keyboardPanRate,r.touchPanRate=i.touchPanRate,r.keyboardRotationRate=i.keyboardRotationRate,r.dragRotationRate=i.dragRotationRate,r.touchDollyRate=i.touchDollyRate,r.dollyInertia=i.dollyInertia,r.dollyProximityThreshold=i.dollyProximityThreshold,r.dollyMinSpeed=i.dollyMinSpeed,r.panInertia=i.panInertia,r.pointerEnabled=!0,r.keyboardDollyRate=i.keyboardDollyRate,r.mouseWheelDollyRate=i.mouseWheelDollyRate,r}return P(n,[{key:"keyMap",get:function(){return this._keyMap},set:function(e){if(e=e||"qwerty",le.isString(e)){var t=this.scene.input,n={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":n[this.PAN_LEFT]=[t.KEY_A],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_Z],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":n[this.PAN_LEFT]=[t.KEY_Q],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_W],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=n}else{var r=e;this._keyMap=r}}},{key:"_isKeyDownForAction",value:function(e,t){var n=this._keyMap[e];if(!n)return!1;t||(t=this.scene.input.keyDown);for(var r=0,i=n.length;r0&&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(),d(g(n.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 n=this.metaScene,r=e.properties;if(e.propertySets)for(var i=0,a=e.propertySets.length;i0?qA(t):null,s=n&&n.length>0?qA(n):null;return function e(t){if(t){var n=!0;(s&&s[t.type]||a&&!a[t.type])&&(n=!1),n&&r.push(t.id);var i=t.children;if(i)for(var o=0,l=i.length;o * Copyright (c) 2022 Niklas von Hertzen