@xeokit/xeokit-sdk 2.5.2-beta-21 → 2.5.2-beta-22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){
14
14
  /**
15
15
  * @author https://github.com/tmarti, with support from https://tribia.com/
16
16
  * @license MIT
17
- **/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;e++)s[e]=e;Ku=new Int32Array(e.length);for(let s=0,n=e.length;s<n;s++)Ku[s]=e[s]>>t;s.sort(Yu);const n=new Int32Array(e.length);for(let t=0,i=s.length;t<i;t++)n[3*t+0]=e[3*s[t]+0],n[3*t+1]=e[3*s[t]+1],n[3*t+2]=e[3*s[t]+2];return n}(e.indices||[],t),r=function(e){if(0===(e||[]).length)return[];let t=new Int32Array(e.length/2);for(let e=0,s=t.length;e<s;e++)t[e]=e;for(let t=0,s=e.length;t<s;t+=2)if(e[t]>e[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;n<i;n++)s[2*n+0]=e[2*t[n]+0],s[2*n+1]=e[2*t[n]+1];return s}(e.edgeIndices||[]);function a(e,t){if(e>t){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<<t))return[e];const c=new Int32Array(l);c.fill(-1);const u=[];function h(){c.fill(-1);const e={positionsCompressed:[],indices:[],edgeIndices:[],maxNumPositions:(1<<t)-t,numPositions:0,bucketNumber:u.length};return u.push(e),e}let p=h();for(let t=0,s=i.length;t<s;t+=3){let s=0;const l=i[t],u=i[t+1],d=i[t+2];if(-1===c[l]&&s++,-1===c[u]&&s++,-1===c[d]&&s++,s+p.numPositions>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;e<n;e+=3){const n=a[3*t[e]]+"_"+a[3*t[e]+1]+"_"+a[3*t[e]+2]+"/"+a[3*t[e+1]]+"_"+a[3*t[e+1]+1]+"_"+a[3*t[e+1]+2]+"/"+a[3*t[e+2]]+"_"+a[3*t[e+2]+1]+"_"+a[3*t[e+2]+2];s[n]=!0}i+=e.edgeIndices.length/2;for(let e=0,t=r.length;e<t;e+=2){const t=a[3*r[e]]+"_"+a[3*r[e]+1]+"_"+a[3*r[e]+2]+"/"+a[3*r[e+1]]+"_"+a[3*r[e+1]+1]+"_"+a[3*r[e+1]+2]+"/";n[t]=!0}}));{const e=t.indices;t.edgeIndices;const n=t.positionsCompressed;for(let t=0,i=e.length;t<i;t+=3){const i=n[3*e[t]]+"_"+n[3*e[t]+1]+"_"+n[3*e[t]+2]+"/"+n[3*e[t+1]]+"_"+n[3*e[t+1]+1]+"_"+n[3*e[t+1]+2]+"/"+n[3*e[t+2]]+"_"+n[3*e[t+2]+1]+"_"+n[3*e[t+2]+2];if(!(i in s))throw console.log("Not found "+i),"Ohhhh!"}}}(u,e),u)}const Zu=d.vec4(4),$u=d.vec4(),eh=d.vec4(),th=d.vec3([1,0,0]),sh=d.vec3([0,1,0]),nh=d.vec3([0,0,1]);d.vec3(3),d.vec3(3);const ih=d.identityMat4();class rh{constructor(e){this._model=e.model,this.id=e.id,this._parentTransform=e.parent,this._childTransforms=[],this._meshes=[],this._scale=new Float32Array([1,1,1]),this._quaternion=d.identityQuaternion(new Float32Array(4)),this._rotation=new Float32Array(3),this._position=new Float32Array(3),this._localMatrix=d.identityMat4(new Float32Array(16)),this._worldMatrix=d.identityMat4(new Float32Array(16)),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,e.matrix?this.matrix=e.matrix:(this.scale=e.scale,this.position=e.position,e.quaternion||(this.rotation=e.rotation)),e.parent&&e.parent._addChildTransform(this)}_addChildTransform(e){this._childTransforms.push(e),e._parentTransform=this,e._setWorldMatrixDirty(),e._setAABBDirty()}_addMesh(e){this._meshes.push(e),e.transform=this}get parentTransform(){return this._parentTransform}get meshes(){return this._meshes}set position(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._model.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),d.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._model.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._setLocalMatrixDirty(),this._model.glRedraw()}get quaternion(){return this._quaternion}set scale(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._model.glRedraw()}get scale(){return this._scale}set matrix(e){this._localMatrix||(this._localMatrix=d.identityMat4()),this._localMatrix.set(e||ih),d.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._transformDirty(),this._model.glRedraw()}get matrix(){return this._localMatrixDirty&&(this._localMatrix||(this._localMatrix=d.identityMat4()),d.composeMat4(this._position,this._quaternion,this._scale,this._localMatrix),this._localMatrixDirty=!1),this._localMatrix}get worldMatrix(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}rotate(e,t){return Zu[0]=e[0],Zu[1]=e[1],Zu[2]=e[2],Zu[3]=t*d.DEGTORAD,d.angleAxisToQuaternion(Zu,$u),d.mulQuaternions(this.quaternion,$u,eh),this.quaternion=eh,this._setLocalMatrixDirty(),this._model.glRedraw(),this}rotateOnWorldAxis(e,t){return Zu[0]=e[0],Zu[1]=e[1],Zu[2]=e[2],Zu[3]=t*d.DEGTORAD,d.angleAxisToQuaternion(Zu,$u),d.mulQuaternions($u,this.quaternion,$u),this}rotateX(e){return this.rotate(th,e)}rotateY(e){return this.rotate(sh,e)}rotateZ(e){return this.rotate(nh,e)}translate(e){return this._position[0]+=e[0],this._position[1]+=e[1],this._position[2]+=e[2],this._setLocalMatrixDirty(),this._model.glRedraw(),this}translateX(e){return this._position[0]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}translateY(e){return this._position[1]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}translateZ(e){return this._position[2]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}_setLocalMatrixDirty(){this._localMatrixDirty=!0,this._transformDirty()}_transformDirty(){this._worldMatrixDirty=!0;for(let e=0,t=this._childTransforms.length;e<t;e++){const t=this._childTransforms[e];if(t._transformDirty(),t._meshes&&t._meshes.length>0){const e=t._meshes;for(let t=0,s=e.length;t<s;t++)e[t]._transformDirty()}}if(this._meshes&&this._meshes.length>0){const e=this._meshes;for(let t=0,s=e.length;t<s;t++)e[t]._transformDirty()}}_buildWorldMatrix(){const e=this.matrix;if(this._parentTransform)d.mulMat4(this._parentTransform.worldMatrix,e,this._worldMatrix);else for(let t=0,s=e.length;t<s;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}_setSubtreeAABBsDirty(e){if(e._aabbDirty=!0,e._childTransforms)for(let t=0,s=e._childTransforms.length;t<s;t++)this._setSubtreeAABBsDirty(e._childTransforms[t])}}const ah=d.vec3(),oh=d.OBB3(),lh=d.vec3([1,1,1]),ch=d.vec3([0,0,0]),uh=d.vec3([0,0,0]),hh=d.identityQuaternion(),ph=d.identityMat4(),dh=new Uint8Array([255,255,255]);class Ah extends x{constructor(e,t={}){super(e,t),this._dtxEnabled=this.scene.dtxEnabled&&!1!==t.dtxEnabled,this._enableVertexWelding=!1,this._enableIndexBucketing=!1,this._vboBatchingLayerScratchMemory=(ur++,cr),this._textureTranscoder=t.textureTranscoder||Vu(this.scene.viewer),this._maxGeometryBatchSize=t.maxGeometryBatchSize,this._aabb=d.collapseAABB3(),this._aabbDirty=!0,this._quantizationRanges={},this._vboInstancingLayers={},this._vboBatchingLayers={},this._dtxLayers={},this.layerList=[],this._entityList=[],this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._transforms={},this._meshes={},this._entities={},this._scheduledMeshes={},this._meshesCfgsBeforeMeshCreation={},this.renderFlags=new ti,this.numGeometries=0,this.numPortions=0,this.numVisibleLayerPortions=0,this.numTransparentLayerPortions=0,this.numXRayedLayerPortions=0,this.numHighlightedLayerPortions=0,this.numSelectedLayerPortions=0,this.numEdgesLayerPortions=0,this.numPickableLayerPortions=0,this.numClippableLayerPortions=0,this.numCulledLayerPortions=0,this.numEntities=0,this._numTriangles=0,this._numLines=0,this._numPoints=0,this._edgeThreshold=t.edgeThreshold||10,this._origin=d.vec3(t.origin||[0,0,0]),this._position=d.vec3(t.position||[0,0,0]),this._rotation=d.vec3(t.rotation||[0,0,0]),this._quaternion=d.vec4(t.quaternion||[0,0,0,1]),this._conjugateQuaternion=d.vec4(t.quaternion||[0,0,0,1]),t.rotation&&d.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._scale=d.vec3(t.scale||[1,1,1]),this._worldRotationMatrix=d.mat4(),this._worldRotationMatrixConjugate=d.mat4(),this._matrix=d.mat4(),this._matrixDirty=!0,this._rebuildMatrices(),this._worldNormalMatrix=d.mat4(),d.inverseMat4(this._matrix,this._worldNormalMatrix),d.transposeMat4(this._worldNormalMatrix),(t.matrix||t.position||t.rotation||t.scale||t.quaternion)&&(this._viewMatrix=d.mat4(),this._viewNormalMatrix=d.mat4(),this._viewMatrixDirty=!0,this._matrixNonIdentity=!0),this._opacity=1,this._colorize=[1,1,1],this._saoEnabled=!1!==t.saoEnabled,this._pbrEnabled=!1!==t.pbrEnabled,this._colorTextureEnabled=!1!==t.colorTextureEnabled,this._isModel=t.isModel,this._isModel&&this.scene._registerModel(this),this._onCameraViewMatrix=this.scene.camera.on("matrix",(()=>{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;e<t;e++)this._entityList[e]._sceneModelDirty()}get worldMatrix(){return this.matrix}get worldNormalMatrix(){return this._worldNormalMatrix}get viewMatrix(){return this._viewMatrix?(this._matrixDirty&&(this._rebuildMatrices(),this._viewMatrixDirty=!0),this._viewMatrixDirty&&(d.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),d.inverseMat4(this._viewMatrix,this._viewNormalMatrix),d.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),this._viewMatrix):this.scene.camera.viewMatrix}get viewNormalMatrix(){return this._viewNormalMatrix?(this._matrixDirty&&(this._rebuildMatrices(),this._viewMatrixDirty=!0),this._viewMatrixDirty&&(d.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),d.inverseMat4(this._viewMatrix,this._viewNormalMatrix),d.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),d.inverseMat4(this._viewMatrix,this._viewNormalMatrix),d.transposeMat4(this._viewNormalMatrix),this._viewNormalMatrix):this.scene.camera.viewNormalMatrix}get backfaces(){return this._backfaces}set backfaces(e){e=!!e,this._backfaces=e,this.glRedraw()}get entityList(){return this._entityList}get isEntity(){return!0}get isModel(){return this._isModel}get isObject(){return!1}get aabb(){if(this._aabbDirty){d.collapseAABB3(this._aabb);for(let e=0,t=this._entityList.length;e<t;e++)d.expandAABB3(this._aabb,this._entityList[e].aabb);this._aabbDirty=!1}return this._aabb}get numTriangles(){return this._numTriangles}get numLines(){return this._numLines}get numPoints(){return this._numPoints}get visible(){return this.numVisibleLayerPortions>0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].visible=e;this.glRedraw()}get xrayed(){return this.numXRayedLayerPortions>0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].xrayed=e;this.glRedraw()}get highlighted(){return this.numHighlightedLayerPortions>0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].highlighted=e;this.glRedraw()}get selected(){return this.numSelectedLayerPortions>0}set selected(e){e=!!e,this._selected=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].selected=e;this.glRedraw()}get edges(){return this.numEdgesLayerPortions>0}set edges(e){e=!!e,this._edges=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].edges=e;this.glRedraw()}get culled(){return this._culled}set culled(e){e=!!e,this._culled=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].culled=e;this.glRedraw()}get clippable(){return this._clippable}set clippable(e){e=!1!==e,this._clippable=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].clippable=e;this.glRedraw()}get collidable(){return this._collidable}set collidable(e){e=!1!==e,this._collidable=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].collidable=e}get pickable(){return this.numPickableLayerPortions>0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].pickable=e}get colorize(){return this._colorize}set colorize(e){this._colorize=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].colorize=e}get opacity(){return this._opacity}set opacity(e){this._opacity=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].opacity=e}get castsShadow(){return this._castsShadow}set castsShadow(e){(e=!1!==e)!==this._castsShadow&&(this._castsShadow=e,this.glRedraw())}get receivesShadow(){return this._receivesShadow}set receivesShadow(e){(e=!1!==e)!==this._receivesShadow&&(this._receivesShadow=e,this.glRedraw())}get saoEnabled(){return this._saoEnabled}get pbrEnabled(){return this._pbrEnabled}get colorTextureEnabled(){return this._colorTextureEnabled}get isDrawable(){return!0}get isStateSortable(){return!1}get xrayMaterial(){return this.scene.xrayMaterial}get highlightMaterial(){return this.scene.highlightMaterial}get selectedMaterial(){return this.scene.selectedMaterial}get edgeMaterial(){return this.scene.edgeMaterial}getPickViewMatrix(e){return this._viewMatrix?this._viewMatrix:e}createQuantizationRange(e){void 0!==e.id&&null!==e.id?e.aabb?this.error("[createQuantizationRange] Config missing: aabb"):this._quantizationRanges[e.id]?this.error("[createQuantizationRange] QuantizationRange already created: "+e.id):this._quantizationRanges[e.id]={id:e.id,aabb:e.aabb,matrix:ia(e.aabb,d.mat4())}:this.error("[createQuantizationRange] Config missing: id")}createGeometry(e){if(void 0!==e.id&&null!==e.id)if(this._geometries[e.id])this.error("[createGeometry] Geometry already created: "+e.id);else 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){if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("[createGeometry] Param expected: `positions`, `positionsCompressed' or 'buckets"),null;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("[createGeometry] Param expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.positionsDecodeMatrix&&e.positionsDecodeBoundary)return this.error("[createGeometry] Only one of these params expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("[createGeometry] Param expected: `uvDecodeMatrix` (required for `uvCompressed')"),null;if(!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error(`[createGeometry] Param expected: indices (required for '${e.primitive}' primitive type)`),null;if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=ia(e.positionsDecodeBoundary,d.mat4())),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();e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed),d.expandAABB3Points3(t,e.positionsCompressed),Ut.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}else if(e.buckets){const t=d.collapseAABB3();this._dtxBuckets[e.id]=e.buckets;for(let s=0,n=e.buckets.length;s<n;s++){const n=e.buckets[s];n.positions?d.expandAABB3Points3(t,n.positions):n.positionsCompressed&&d.expandAABB3Points3(t,n.positionsCompressed)}e.positionsDecodeMatrix&&Ut.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.colorsCompressed&&e.colorsCompressed.length>0)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<n;e++)s[e]=255*t[e];e.colorsCompressed=s}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=St(e.positions,e.indices,null,5):e.edgeIndices=St(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.uv){const t=Ut.getUVBounds(e.uv),s=Ut.compressUVs(e.uv,t.min,t.max);e.uvCompressed=s.quantized,e.uvDecodeMatrix=s.decodeMatrix}else e.uvCompressed&&(e.uvCompressed=new Uint16Array(e.uvCompressed),e.uvDecodeMatrix=new Float64Array(e.uvDecodeMatrix));e.normals&&(e.normals=null),this._geometries[e.id]=e,this._numTriangles+=e.indices?Math.round(e.indices.length/3):0,this.numGeometries++}else this.error(`[createGeometry] Unsupported value for 'primitive': '${e.primitive}' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'.`);else this.error("[createGeometry] Config missing: id")}createTexture(e){const t=e.id;if(null==t)return void this.error("[createTexture] Config missing: id");if(this._textures[t])return void this.error("[createTexture] Texture already created: "+t);if(!e.src&&!e.image&&!e.buffers)return this.error("[createTexture] Param expected: `src`, `image' or 'buffers'"),null;let s=e.minFilter||1008;1006!==s&&1007!==s&&1008!==s&&1005!==s&&1004!==s&&(this.error("[createTexture] Unsupported value for 'minFilter' - \n supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, \n NearestMipMapLinearFilter and LinearMipmapLinearFilter. Defaulting to LinearMipmapLinearFilter."),s=1008);let n=e.magFilter||1006;1006!==n&&1003!==n&&(this.error("[createTexture] Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),n=1006);let i=e.wrapS||1e3;1001!==i&&1002!==i&&1e3!==i&&(this.error("[createTexture] Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),i=1e3);let r=e.wrapT||1e3;1001!==r&&1002!==r&&1e3!==r&&(this.error("[createTexture] Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),r=1e3);let a=e.wrapR||1e3;1001!==a&&1002!==a&&1e3!==a&&(this.error("[createTexture] Unsupported value for 'wrapR' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),a=1e3);let o=e.encoding||3e3;3e3!==o&&3001!==o&&(this.error("[createTexture] Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),o=3e3);const l=new Ui({gl:this.scene.canvas.gl,minFilter:s,magFilter:n,wrapS:i,wrapT:r,wrapR:a,encoding:o});if(e.preloadColor&&l.setPreloadColor(e.preloadColor),e.image){const t=e.image;t.crossOrigin="Anonymous",l.setImage(t,{minFilter:s,magFilter:n,wrapS:i,wrapT:r,wrapR:a,flipY:e.flipY,encoding:o})}else if(e.src){const t=e.src.split(".").pop();switch(t){case"jpeg":case"jpg":case"png":case"gif":const c=new Image;c.onload=()=>{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<n;s++){const n=e.buckets[s];n.positions?d.expandAABB3Points3(t,n.positions):n.positionsCompressed&&d.expandAABB3Points3(t,n.positionsCompressed)}e.positionsDecodeMatrix&&Ut.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}e.meshMatrix&&(d.AABB3ToOBB3(e.aabb,oh),d.transformOBB3(e.meshMatrix,oh),d.OBB3ToAABB3(oh,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=St(e.positions,e.indices,null,2):e.edgeIndices=St(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=fh(e,this._enableVertexWelding&&this._enableIndexBucketing))}else{if(e.type=1,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):[255,255,255],e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.positions){const t=[];Y(e.positions,t,ah)&&(e.positions=t,e.origin=d.addVec3(e.origin,ah,d.vec3()))}if(e.positions){const t=d.collapseAABB3();e.meshMatrix&&(d.transformPositions3(e.meshMatrix,e.positions,e.positions),e.meshMatrix=null),d.expandAABB3Points3(t,e.positions),e.aabb=t}else{const t=d.collapseAABB3();d.expandAABB3Points3(t,e.positionsCompressed),Ut.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.meshMatrix&&(d.AABB3ToOBB3(e.aabb,oh),d.transformOBB3(e.meshMatrix,oh),d.OBB3ToAABB3(oh,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=St(e.positions,e.indices,null,2):e.edgeIndices=St(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId],!e.textureSet))return this.error(`[createMesh] Texture set not found: ${e.textureSetId} - ensure that you create it first with createTextureSet()`),!1}}else{if(e.positions||e.positionsCompressed||e.indices||e.edgeIndices||e.normals||e.normalsCompressed||e.uv||e.uvCompressed||e.positionsDecodeMatrix)return this.error("Mesh geometry parameters not expected when instancing a geometry (not expected: positions, positionsCompressed, indices, edgeIndices, normals, normalsCompressed, uv, uvCompressed, positionsDecodeMatrix)"),!1;if(e.geometry=this._geometries[e.geometryId],!e.geometry)return this.error(`[createMesh] Geometry not found: ${e.geometryId} - ensure that you create it first with createGeometry()`),!1;if(e.origin=e.origin?d.addVec3(this._origin,e.origin,d.vec3()):this._origin,e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.transformId){if(e.transform=this._transforms[e.transformId],!e.transform)return this.error(`[createMesh] Transform not found: ${e.transformId} - ensure that you create it first with createTransform()`),!1;e.aabb=e.geometry.aabb}else{if(e.matrix)e.meshMatrix=e.matrix.slice();else{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())}d.AABB3ToOBB3(e.geometry.aabb,oh),d.transformOBB3(e.meshMatrix,oh),e.aabb=d.OBB3ToAABB3(oh,d.AABB3())}if(!!this._dtxEnabled&&("triangles"===e.geometry.primitive||"solid"===e.geometry.primitive||"surface"===e.geometry.primitive)){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;let t=this._dtxBuckets[e.geometryId];t||(t=fh(e.geometry,this._enableVertexWelding,this._enableIndexBucketing),this._dtxBuckets[e.geometryId]=t),e.buckets=t}else e.type=0,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.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId])}return e.numPrimitives=this._getNumPrimitives(e),this._meshesCfgsBeforeMeshCreation[e.id]=e,!0}_createMesh(e){const t=new lr(this,e.id,e.color,e.opacity,e.transform,e.textureSet);t.pickId=this.scene._renderer.getPickID(t);const s=t.pickId,n=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<n;s++)t+=e.buckets[s].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/3);case"points":switch(e.type){case 2:for(let s=0,n=e.buckets.length;s<n;s++)t+=e.buckets[s].positionsCompressed.length;break;case 1:t+=e.positions?e.positions.length:e.positionsCompressed.length;break;case 0:const s=e.geometry;t+=s.positions?s.positions.length:s.positionsCompressed.length}return Math.round(t);case"lines":case"line-strip":switch(e.type){case 2:for(let s=0,n=e.buckets.length;s<n;s++)t+=e.buckets[s].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/2)}return 0}_getDTXLayer(e){const t=e.origin,s=e.geometry?e.geometry.primitive:e.primitive,n=`.${s}.${Math.round(t[0])}.${Math.round(t[1])}.${Math.round(t[2])}`;let i=this._dtxLayers[n];if(i){if(i.canCreatePortion(e))return i;i.finalize(),delete this._dtxLayers[n],i=null}switch(s){case"triangles":case"solid":case"surface":i=new Ru(this,{layerIndex:0,origin:t});break;case"lines":i=new ac(this,{layerIndex:0,origin:t});break;default:return}return this._dtxLayers[n]=i,this.layerList.push(i),i}_getVBOBatchingLayer(e){const t=this,s=e.origin,n=e.positionsDecodeMatrix||e.positionsDecodeBoundary?this._createHashStringFromMatrix(e.positionsDecodeMatrix||e.positionsDecodeBoundary):"-",i=e.textureSetId||"-",r=`${Math.round(s[0])}.${Math.round(s[1])}.${Math.round(s[2])}.${e.primitive}.${n}.${i}`;let a=this._vboBatchingLayers[r];if(a)return a;let o=e.textureSet;for(;!a;){switch(e.primitive){case"triangles":case"solid":case"surface":a=new ma({model:t,textureSet:o,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:s,maxGeometryBatchSize:this._maxGeometryBatchSize,solid:"solid"===e.primitive,autoNormals:!0});break;case"lines":a=new _o({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:s,maxGeometryBatchSize:this._maxGeometryBatchSize});break;case"points":a=new Il({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:s,maxGeometryBatchSize:this._maxGeometryBatchSize})}const n=e.positionsCompressed?e.positionsCompressed.length:e.positions.length;("points"===e.primitive?a.canCreatePortion(n):a.canCreatePortion(n,e.indices.length))||(a.finalize(),delete this._vboBatchingLayers[r],a=null)}return this._vboBatchingLayers[r]=a,this.layerList.push(a),a}_createHashStringFromMatrix(e){const t=e.join("");let s=0;for(let e=0;e<t.length;e++){s=(s<<5)-s+t.charCodeAt(e),s|=0}return(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;s<n;s++){const n=e.meshIds[s];let i=this._meshes[n];if(!i){let t=this._meshesCfgsBeforeMeshCreation[n];if(!t){this.error(`Mesh with this ID not found: "${n}" - ignoring this mesh`);continue}i=this._createMesh(t),this._meshes[e.id]=i}i.parent?this.error(`Mesh with ID "${n}" already belongs to object with ID "${i.parent.id}" - ignoring this mesh`):t.push(i)}const s=new le(this,e.isObject,e.id,t,e.flags,!0);this._entityList.push(s),this._entities[e.id]=s,this.numEntities++}finalize(){if(!this.destroyed){for(let e=0,t=this.layerList.length;e<t;e++){this.layerList[e].finalize()}this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._dtxLayers={},this._vboInstancingLayers={},this._vboBatchingLayers={};for(let e=0,t=this._entityList.length;e<t;e++){this._entityList[e]._finalize()}for(let e=0,t=this._entityList.length;e<t;e++){this._entityList[e]._finalize2()}this.layerList.sort(((e,t)=>e.sortId<t.sortId?-1:e.sortId>t.sortId?1:0));for(let e=0,t=this.layerList.length;e<t;e++){this.layerList[e].layerIndex=e}this.glRedraw(),this.scene._aabbDirty=!0,this._viewMatrixDirty=!0,this._matrixDirty=!0,this._aabbDirty=!0,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.position=this._position}}stateSortCompare(e,t){}rebuildRenderFlags(){this.renderFlags.reset(),this._updateRenderFlagsVisibleLayers(),this.renderFlags.numLayers>0&&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;t<s;t++){const s=this.layerList[t];this._getActiveSectionPlanesForLayer(s)&&(e.visibleLayers[e.numVisibleLayers++]=t)}}_getActiveSectionPlanesForLayer(e){const t=this.renderFlags,s=this.scene._sectionPlanesState.sectionPlanes,n=s.length,i=e.layerIndex*n;if(n>0)for(let e=0;e<n;e++){s[e].active?(t.sectionPlanesActivePerLayer[i+e]=!0,t.sectioned=!0):t.sectionPlanesActivePerLayer[i+e]=!1}return!0}_updateRenderFlags(){if(0===this.numVisibleLayerPortions)return;if(this.numCulledLayerPortions===this.numPortions)return;const e=this.renderFlags;if(e.colorOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(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.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(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;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawColorOpaque(t,e)}}drawColorTransparent(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawColorTransparent(t,e)}}drawDepth(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawDepth(t,e)}}drawNormals(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawNormals(t,e)}}drawSilhouetteXRayed(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawSilhouetteXRayed(t,e)}}drawSilhouetteHighlighted(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawSilhouetteHighlighted(t,e)}}drawSilhouetteSelected(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawSilhouetteSelected(t,e)}}drawEdgesColorOpaque(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawEdgesColorOpaque(t,e)}}drawEdgesColorTransparent(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawEdgesColorTransparent(t,e)}}drawEdgesXRayed(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawEdgesXRayed(t,e)}}drawEdgesHighlighted(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawEdgesHighlighted(t,e)}}drawEdgesSelected(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawEdgesSelected(t,e)}}drawOcclusion(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawOcclusion(t,e)}}drawShadow(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawShadow(t,e)}}setPickMatrices(e,t){if(0===this._numVisibleLayerPortions)return;const s=this.renderFlags;for(let n=0,i=s.visibleLayers.length;n<i;n++){const i=s.visibleLayers[n],r=this.layerList[i];r.setPickMatrices&&r.setPickMatrices(e,t)}}drawPickMesh(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawPickMesh(t,e)}}drawPickDepths(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawPickDepths(t,e)}}drawPickNormals(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawPickNormals(t,e)}}drawSnapInit(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s],i=this.layerList[n];i.drawSnapInit&&(e.snapPickOrigin=[0,0,0],e.snapPickCoordinateScale=[1,1,1],e.snapPickLayerNumber++,i.drawSnapInit(t,e),e.snapPickLayerParams[e.snapPickLayerNumber]={origin:e.snapPickOrigin.slice(),coordinateScale:e.snapPickCoordinateScale.slice()})}}drawSnap(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s],i=this.layerList[n];i.drawSnap&&(e.snapPickOrigin=[0,0,0],e.snapPickCoordinateScale=[1,1,1],e.snapPickLayerNumber++,i.drawSnap(t,e),e.snapPickLayerParams[e.snapPickLayerNumber]={origin:e.snapPickOrigin.slice(),coordinateScale:e.snapPickCoordinateScale.slice()})}}destroy(){for(let e in this._vboBatchingLayers)this._vboBatchingLayers.hasOwnProperty(e)&&this._vboBatchingLayers[e].destroy();this._vboBatchingLayers={};for(let e in this._vboInstancingLayers)this._vboInstancingLayers.hasOwnProperty(e)&&this._vboInstancingLayers[e].destroy();this._vboInstancingLayers={},this.scene.camera.off(this._onCameraViewMatrix),this.scene.off(this._onTick);for(let e=0,t=this.layerList.length;e<t;e++)this.layerList[e].destroy();this.layerList=[];for(let e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._destroy();this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this.scene._aabbDirty=!0,this._isModel&&this.scene._deregisterModel(this),0!==ur&&(ur--,0===ur&&cr._clear()),super.destroy()}}function fh(e,t,s){let n,i,r,a;if(t||s?[n,i,r]=zu({positionsCompressed:e.positionsCompressed,indices:e.indices,edgeIndices:e.edgeIndices}):(n=e.positionsCompressed,i=e.indices,r=e.edgeIndices),s){a=Ju({positionsCompressed:n,indices:i,edgeIndices:r},n.length/3>65536?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;e<t;e+=2)this._indices.push(e),this._indices.push(e+1)}this._sceneModel=new Ah(this,{isModel:!1}),this._sceneModel.createMesh({id:"linesMesh",primitive:"lines",positions:this._positions,indices:this._indices}),this._sceneModel.createEntity({meshIds:["linesMesh"],visible:t.visible,clippable:t.clippable,collidable:t.collidable}),this._sceneModel.finalize(),this.scene._lineSetCreated(this)}set visible(e){this._sceneModel.visible=e}get visible(){return this._sceneModel.visible}get positions(){return this._positions}get indices(){return this._indices}destroy(){super.destroy(),this.scene._lineSetDestroyed(this)}}const mh=d.vec3(),yh=d.vec3(),vh=d.vec3(),wh=d.vec3();class gh extends Q{constructor(e,t={}){super("BCFViewpoints",e,t),this.originatingSystem=t.originatingSystem||"xeokit.io",this.authoringTool=t.authoringTool||"xeokit.io"}getViewpoint(e={}){const t=this.viewer.scene,s=t.camera,n=t.realWorldOffset,i=!0===e.reverseClippingPlanes;let r={},a=d.normalizeVec3(d.subVec3(s.look,s.eye,d.vec3())),o=s.eye,l=s.up;s.yUp&&(a=bh(a),o=bh(o),l=bh(l));const c=Eh(d.addVec3(o,n));"ortho"===s.projection?r.orthogonal_camera={camera_view_point:c,camera_direction:Eh(a),camera_up_vector:Eh(l),view_to_world_scale:s.ortho.scale}:r.perspective_camera={camera_view_point:c,camera_direction:Eh(a),camera_up_vector:Eh(l),field_of_view:s.perspective.fov};const u=t.sectionPlanes;for(let e in u)if(u.hasOwnProperty(e)){let t=u[e];if(!t.active)continue;let a,o=t.pos;a=i?d.negateVec3(t.dir,d.vec3()):t.dir,s.yUp&&(o=bh(o),a=bh(a)),d.addVec3(o,n),o=Eh(o),a=Eh(a),r.clipping_planes||(r.clipping_planes=[]),r.clipping_planes.push({location:o,direction:a})}const h=t.lineSets;for(let e in h)if(h.hasOwnProperty(e)){const t=h[e];r.lines||(r.lines=[]);const s=t.positions,n=t.indices;for(let e=0,t=n.length/2;e<t;e++){const t=n[2*e],i=n[2*e+1];r.lines.push({start_point:{x:s[3*t+0],y:s[3*t+1],z:s[3*t+2]},end_point:{x:s[3*i+0],y:s[3*i+1],z:s[3*i+2]}})}}const p=t.bitmaps;for(let e in p)if(p.hasOwnProperty(e)){let t=p[e],i=t.pos,a=t.normal,o=t.up;s.yUp&&(i=bh(i),a=bh(a),o=bh(o)),d.addVec3(i,n),r.bitmaps||(r.bitmaps=[]),r.bitmaps.push({bitmap_type:t.type,bitmap_data:t.imageData,location:Eh(i),normal:Eh(a),up:Eh(o),height:t.height})}r.components={visibility:{view_setup_hints:{spaces_visible:!!e.spacesVisible,space_boundaries_visible:!!e.spaceBoundariesVisible,openings_visible:!!e.openingsVisible,spaces_translucent:!!e.spaces_translucent,space_boundaries_translucent:!!e.space_boundaries_translucent,openings_translucent:!!e.openings_translucent}}};const A=new Set(t.opacityObjectIds),f=new Set(t.xrayedObjectIds),I=new Set(t.colorizedObjectIds),m=Object.values(t.objects).filter((e=>A.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.length<E.length?(r.components.visibility.exceptions=this._createBCFComponents(g),r.components.visibility.default_visibility=!1):(r.components.visibility.exceptions=this._createBCFComponents(E),r.components.visibility.default_visibility=!0),r.components.selection=this._createBCFComponents(T),r.components.translucency=this._createBCFComponents(t.xrayedObjectIds),!1!==e.snapshot&&(r.snapshot={snapshot_type:"png",snapshot_data:this.viewer.getSnapshot({format:"png"})}),r}_createBCFComponents(e){const t=this.viewer.scene,s=[];for(let n=0,i=e.length;n<i;n++){const i=e[n],r=t.objects[i];if(r){const e={ifc_guid:r.originalSystemId,originating_system:this.originatingSystem};r.originalSystemId!==i&&(e.authoring_tool_id=i),s.push(e)}}return s}setViewpoint(e,t={}){if(!e)return;const s=this.viewer,n=s.scene,i=n.camera,r=!1!==t.rayCast,a=!1!==t.immediate,o=!1!==t.reset,l=n.realWorldOffset,c=!0===t.reverseClippingPlanes;if(n.clearSectionPlanes(),e.clipping_planes&&e.clipping_planes.length>0&&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<A;p+=4)i[h]=o+Math.floor((1+n[p+0]/n[p+3])*c/2),i[h+1]=a+Math.floor((1-n[p+1]/n[p+3])*u/2),h+=2;if(this._originDot.setPos(i[0],i[1]),this._targetDot.setPos(i[6],i[7]),this._lengthWire.setStartAndEnd(i[0],i[1],i[6],i[7]),this._xAxisWire.setStartAndEnd(i[0],i[1],i[2],i[3]),this._yAxisWire.setStartAndEnd(i[2],i[3],i[4],i[5]),this._zAxisWire.setStartAndEnd(i[4],i[5],i[6],i[7]),this.labelsVisible){if(this._lengthLabel.setPosOnWire(i[0],i[1],i[6],i[7]),this.labelsOnWires)this._xAxisLabel.setPosOnWire(i[0],i[1],i[2],i[3]),this._yAxisLabel.setPosOnWire(i[2],i[3],i[4],i[5]),this._zAxisLabel.setPosOnWire(i[4],i[5],i[6],i[7]);else{const e=35;let t=e;this._xAxisLabel.setPosOnWire(i[0],i[1]+t,i[6],i[7]+t),t+=e,this._yAxisLabel.setPosOnWire(i[0],i[1]+t,i[6],i[7]+t),t+=e,this._zAxisLabel.setPosOnWire(i[0],i[1]+t,i[6],i[7]+t)}const e=this._approximate?" ~ ":" = ";this._length=Math.abs(d.lenVec3(d.subVec3(this._targetWorld,this._originWorld,Ph))),this._lengthLabel.setText(e+(this._length*f).toFixed(2)+m);const t=Math.abs(Ch(i[0],i[1],i[2],i[3])),s=Math.abs(Ch(i[2],i[3],i[4],i[5])),n=Math.abs(Ch(i[4],i[5],i[6],i[7])),r=this.plugin.labelMinAxisLength;this.labelsOnWires?(this._xAxisLabelCulled=t<r,this._yAxisLabelCulled=s<r,this._zAxisLabelCulled=n<r):(this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1),this._xAxisLabelCulled?this._xAxisLabel.setCulled(!0):(this._xAxisLabel.setText(e+Math.abs((this._targetWorld[0]-this._originWorld[0])*f).toFixed(2)+m),this._xAxisLabel.setCulled(!this.axisVisible)),this._yAxisLabelCulled?this._yAxisLabel.setCulled(!0):(this._yAxisLabel.setText(e+Math.abs((this._targetWorld[1]-this._originWorld[1])*f).toFixed(2)+m),this._yAxisLabel.setCulled(!this.axisVisible)),this._zAxisLabelCulled?this._zAxisLabel.setCulled(!0):(this._zAxisLabel.setText(e+Math.abs((this._targetWorld[2]-this._originWorld[2])*f).toFixed(2)+m),this._zAxisLabel.setCulled(!this.axisVisible))}else this._lengthLabel.setCulled(!0),this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0);this._originDot.setVisible(this._visible&&this._originVisible),this._targetDot.setVisible(this._visible&&this._targetVisible),this._xAxisWire.setVisible(this.axisVisible&&this.xAxisVisible),this._yAxisWire.setVisible(this.axisVisible&&this.yAxisVisible),this._zAxisWire.setVisible(this.axisVisible&&this.zAxisVisible),this._lengthWire.setVisible(this.wireVisible),this._lengthLabel.setCulled(!this.wireVisible),this._cpDirty=!1}}_isSliced(e){const t=this.scene._sectionPlanesState.sectionPlanes;for(let s=0,n=t.length;s<n;s++){const n=t[s];if(d.planeClipsPositions3(n.pos,n.dir,e,4))return!0}return!1}set approximate(e){e=!1!==e,this._approximate!==e&&(this._approximate=e,this._cpDirty=!0,this._needUpdate(0))}get approximate(){return this._approximate}get origin(){return this._originMarker}get target(){return this._targetMarker}get length(){this._update();const e=this.plugin.viewer.scene.metrics.scale;return this._length*e}get color(){return this._color}set color(e){this._color=e,this._originDot.setFillColor(e),this._targetDot.setFillColor(e),this._lengthWire.setColor(e),this._lengthLabel.setFillColor(e)}set visible(e){e=void 0!==e?Boolean(e):this.plugin.defaultVisible,this._visible=e,this._originDot.setVisible(this._visible&&this._originVisible),this._targetDot.setVisible(this._visible&&this._targetVisible),this._lengthWire.setVisible(this._visible&&this._wireVisible),this._lengthLabel.setVisible(this._visible&&this._wireVisible);const t=this._visible&&this._axisVisible&&this._xAxisVisible,s=this._visible&&this._axisVisible&&this._yAxisVisible,n=this._visible&&this._axisVisible&&this._zAxisVisible;this._xAxisWire.setVisible(t),this._yAxisWire.setVisible(s),this._zAxisWire.setVisible(n),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled),this._yAxisLabel.setVisible(s&&!this._yAxisLabelCulled),this._zAxisLabel.setVisible(n&&!this._zAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}get visible(){return this._visible}set originVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultOriginVisible,this._originVisible=e,this._originDot.setVisible(this._visible&&this._originVisible)}get originVisible(){return this._originVisible}set targetVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultTargetVisible,this._targetVisible=e,this._targetDot.setVisible(this._visible&&this._targetVisible)}get targetVisible(){return this._targetVisible}set axisEnabled(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._axisEnabled=e;var t=this._visible&&this._axisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t&&this._xAxisVisible),this._yAxisWire.setVisible(t&&this._yAxisVisible),this._zAxisWire.setVisible(t&&this._zAxisVisible),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled&&this._xAxisVisible),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled&&this._xAxisVisible),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled&&this._xAxisVisible),this._cpDirty=!0,this._needUpdate()}get axisEnabled(){return this._axisEnabled}set axisVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._axisVisible=e;var t=this._visible&&this._axisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t&&this._xAxisVisible),this._yAxisWire.setVisible(t&&this._yAxisVisible),this._zAxisWire.setVisible(t&&this._zAxisVisible),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled&&this._xAxisVisible),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled&&this._yAxisVisible),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled&&this._zAxisVisible),this._cpDirty=!0,this._needUpdate()}get axisVisible(){return this._axisVisible}set xAxisVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._xAxisVisible=e;const t=this._visible&&this._axisVisible&&this._xAxisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}get xAxisVisible(){return this._xAxisVisible}set yAxisVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._yAxisVisible=e;const t=this._visible&&this._axisVisible&&this._yAxisVisible&&this._axisEnabled;this._yAxisWire.setVisible(t),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}get yAxisVisible(){return this._yAxisVisible}set zAxisVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._zAxisVisible=e;const t=this._visible&&this._axisVisible&&this._zAxisVisible&&this._axisEnabled;this._zAxisWire.setVisible(t),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}get zAxisVisible(){return this._zAxisVisible}set wireVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultWireVisible,this._wireVisible=e;var t=this._visible&&this._wireVisible;this._lengthLabel.setVisible(t),this._lengthWire.setVisible(t)}get wireVisible(){return this._wireVisible}set labelsVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultLabelsVisible,this._labelsVisible=e;var t=this._visible&&this._labelsVisible;this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled&&this._clickable&&this._axisEnabled),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled&&this._clickable&&this._axisEnabled),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled&&this._clickable&&this._axisEnabled),this._lengthLabel.setVisible(t),this._cpDirty=!0,this._needUpdate()}get labelsVisible(){return this._labelsVisible}set labelsOnWires(e){e=void 0!==e?Boolean(e):this.plugin.defaultLabelsOnWires,this._labelsOnWires=e}get labelsOnWires(){return this._labelsOnWires}setHighlighted(e){this._originDot.setHighlighted(e),this._targetDot.setHighlighted(e),this._xAxisWire.setHighlighted(e),this._yAxisWire.setHighlighted(e),this._zAxisWire.setHighlighted(e),this._xAxisLabel.setHighlighted(e),this._yAxisLabel.setHighlighted(e),this._zAxisLabel.setHighlighted(e),this._lengthWire.setHighlighted(e),this._lengthLabel.setHighlighted(e)}set clickable(e){e=!!e,this._clickable=e,this._originDot.setClickable(this._clickable),this._targetDot.setClickable(this._clickable),this._xAxisWire.setClickable(this._clickable),this._yAxisWire.setClickable(this._clickable),this._zAxisWire.setClickable(this._clickable),this._lengthWire.setClickable(this._clickable),this._xAxisLabel.setClickable(this._clickable),this._yAxisLabel.setClickable(this._clickable),this._zAxisLabel.setClickable(this._clickable),this._lengthLabel.setClickable(this._clickable)}get clickable(){return this._clickable}destroy(){const e=this.plugin.viewer.scene,t=e.metrics;this._onViewMatrix&&e.camera.off(this._onViewMatrix),this._onProjMatrix&&e.camera.off(this._onProjMatrix),this._onCanvasBoundary&&e.canvas.off(this._onCanvasBoundary),this._onMetricsUnits&&t.off(this._onMetricsUnits),this._onMetricsScale&&t.off(this._onMetricsScale),this._onMetricsOrigin&&t.off(this._onMetricsOrigin),this._onSectionPlaneUpdated&&e.off(this._onSectionPlaneUpdated),this._originDot.destroy(),this._targetDot.destroy(),this._xAxisWire.destroy(),this._yAxisWire.destroy(),this._zAxisWire.destroy(),this._lengthLabel.destroy(),this._xAxisLabel.destroy(),this._yAxisLabel.destroy(),this._zAxisLabel.destroy(),this._lengthWire.destroy(),super.destroy()}}class Rh extends x{get active(){}set snapping(e){}get snapping(){return!0}activate(){}deactivate(){}reset(){}destroy(){}}class Bh extends Rh{constructor(e,t={}){super(e.viewer.scene),this.pointerLens=t.pointerLens,this._active=!1,this._currentDistanceMeasurement=null,this._currentDistanceMeasurementInitState={wireVisible:null,axisVisible:null,xAxisVisible:null,yaxisVisible:null,zAxisVisible:null,targetVisible:null},this._initMarkerDiv(),this._onCameraControlHoverSnapOrSurface=null,this._onCameraControlHoverSnapOrSurfaceOff=null,this._onMouseDown=null,this._onMouseUp=null,this._onCanvasTouchStart=null,this._onCanvasTouchEnd=null,this._snapping=!1!==t.snapping,this._mouseState=0,this._attachPlugin(e,t)}_initMarkerDiv(){const e=document.createElement("div");e.setAttribute("id","myMarkerDiv");const 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}_destroyMarkerDiv(){if(this._markerDiv){const e=document.getElementById("myMarkerDiv");e.parentNode.removeChild(e),this._markerDiv=null}}_attachPlugin(e,t={}){this.distanceMeasurementsPlugin=e,this.plugin=e}get active(){return this._active}set snapping(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}get snapping(){return this._snapping}activate(){if(this._active)return;this._markerDiv||this._initMarkerDiv(),this.fire("activated",!0);const e=this.distanceMeasurementsPlugin,t=this.scene,s=e.viewer.cameraControl,n=t.canvas.canvas;t.input;let i=!1;const r=d.vec3(),a=d.vec2();let o,l;let c=null;this._mouseState=0,this._onCameraControlHoverSnapOrSurface=s.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(e=>{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.clientX<o-20||t.clientY>l+20||t.clientY<l-20||(this._currentDistanceMeasurement?i?(this._currentDistanceMeasurement.target.entity=c,c=null,this._currentDistanceMeasurement.clickable=!0,this.distanceMeasurementsPlugin.fire("measurementEnd",this._currentDistanceMeasurement),this._currentDistanceMeasurement=null):(this._currentDistanceMeasurement.destroy(),this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement=null,c=null):i&&(this._currentDistanceMeasurement=e.createMeasurement({id:d.createUUID(),origin:{worldPos:r.slice()},target:{worldPos:r.slice()},approximate:!0}),this._currentDistanceMeasurementInitState.axisVisible=this._currentDistanceMeasurement.axisVisible&&this.distanceMeasurementsPlugin.defaultAxisVisible,this._currentDistanceMeasurementInitState.xAxisVisible=this._currentDistanceMeasurement.xAxisVisible&&this.distanceMeasurementsPlugin.defaultXAxisVisible,this._currentDistanceMeasurementInitState.yAxisVisible=this._currentDistanceMeasurement.yAxisVisible&&this.distanceMeasurementsPlugin.defaultYAxisVisible,this._currentDistanceMeasurementInitState.zAxisVisible=this._currentDistanceMeasurement.zAxisVisible&&this.distanceMeasurementsPlugin.defaultZAxisVisible,this._currentDistanceMeasurementInitState.wireVisible=this._currentDistanceMeasurement.wireVisible,this._currentDistanceMeasurementInitState.targetVisible=this._currentDistanceMeasurement.targetVisible,this._currentDistanceMeasurement.clickable=!1,this._currentDistanceMeasurement.origin.entity=c,c=null,this.fire("measurementStart",this._currentDistanceMeasurement))))}),this._onCameraControlHoverSnapOrSurfaceOff=s.on(this._snapping?"hoverSnapOrSurfaceOff":"hoverOff",(e=>{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;t++)this.destroyMeasurement(e[t])}destroy(){this.clear(),super.destroy()}}class Sh extends Q{constructor(e,t={}){super("FastNav",e),this._hideColorTexture=!1!==t.hideColorTexture,this._hidePBR=!1!==t.hidePBR,this._hideSAO=!1!==t.hideSAO,this._hideEdges=!1!==t.hideEdges,this._hideTransparentObjects=!!t.hideTransparentObjects,this._scaleCanvasResolution=!!t.scaleCanvasResolution,this._scaleCanvasResolutionFactor=t.scaleCanvasResolutionFactor||.6,this._delayBeforeRestore=!1!==t.delayBeforeRestore,this._delayBeforeRestoreSeconds=t.delayBeforeRestoreSeconds||.5;let s=1e3*this._delayBeforeRestoreSeconds,n=!1;const i=()=>{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<o.length;l++)t[l]=o.charCodeAt(l);B.scheduleTask((function(){s(e)}))}catch(e){B.scheduleTask((function(){n(e)}))}}else{const i=function(e){var t=e.lastIndexOf("/");return 0!==t?e.substring(0,t+1):""}(e),r=i+t,a=new XMLHttpRequest;a.open("GET",r,!0),a.responseType="arraybuffer",a.onreadystatechange=function(){4===a.readyState&&(200===a.status?s(a.response):n("loadArrayBuffer error : "+a.response))},a.send(null)}}(e,t,(e=>{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&&e<t;e++){n=n[s[e]]}return n}function Mh(e,t=[]){return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,s){return"{{"===e?"{":"}}"===e?"}":t[s]}))}class Fh extends x{constructor(e,t={}){super(e,t),this.t=t.t}set t(e){e=e||0,this._t=e<0?0:e>1?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;s<n;s++)t=e[s],this.addFrame(t.t||0,t.eye,t.look,t.up)}loadFrame(e){const t=this.scene.camera;e=(e/=this._frames[this._frames.length-1].t-this._frames[0].t)<0?0:e>1?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<r;e++){var i=d.lenVec3(d.subVec3(this._frames[e].eye,this._frames[e-1].eye,t));n[e]=i,s+=i}for(let t=1,i=this._frames.length;t<i;t++){const i=n[t]/s*e;this._frames[t].t=this._frames[t-1].t+i}}clearFrames(){this._frames=[],this._eyeCurve.points=[],this._lookCurve.points=[],this._upCurve.points=[]}}const jh=d.vec3(),Vh=d.vec3(),kh=d.vec3(),Qh=d.vec3(),Wh=d.vec3();class zh extends x{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=d.vec3(),this._eye1=d.vec3(),this._up1=d.vec3(),this._look2=d.vec3(),this._eye2=d.vec3(),this._up2=d.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((g.isNumeric(n)||g.isString(n))&&(c=n,n=this.scene.components[c],!n))return this.error("Component not found: "+g.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]<r[0]||r[4]<r[1]||r[5]<r[2])return;if(r[3]===r[0]&&r[4]===r[1]&&r[5]===r[2])return;r=r.slice();const t=d.getAABB3Center(r);this._look2=u||t;const s=d.subVec3(this._eye1,this._look1,jh),n=d.normalizeVec3(s),i=u?d.getAABB3DiagPoint(r,u):d.getAABB3Diag(r),a=e.fitFOV||this._fitFOV,o=Math.abs(i/Math.tan(a*d.DEGTORAD));this._orthoScale2=1.1*i,this._eye2[0]=this._look2[0]+n[0]*o,this._eye2[1]=this._look2[1]+n[1]*o,this._eye2[2]=this._look2[2]+n[2]*o,this._up2[0]=this._up1[0],this._up2[1]=this._up1[1],this._up2[2]=this._up1[2],this._flyingEyeLookUp=!0}else(a||o||l)&&(this._flyingEyeLookUp=!!a&&!!o&&!!l,this._flyingEye=!!a&&!o,this._flyingLook=!!o&&!a,a&&(this._eye2[0]=a[0],this._eye2[1]=a[1],this._eye2[2]=a[2]),o&&(this._look2[0]=o[0],this._look2[1]=o[1],this._look2[2]=o[2]),l&&(this._up2[0]=l[0],this._up2[1]=l[1],this._up2[2]=l[2]));i?("ortho"===e.projection&&"ortho"!==n.projection&&(this._projection2="ortho",this._projMatrix1=n.projMatrix.slice(),this._projMatrix2=n.ortho.matrix.slice(),n.projection="customProjection"),"perspective"===e.projection&&"perspective"!==n.projection&&(this._projection2="perspective",this._projMatrix1=n.projMatrix.slice(),this._projMatrix2=n.perspective.matrix.slice(),n.projection="customProjection")):this._projection2=null,this.fire("started",e,!0),this._time1=Date.now(),this._time2=this._time1+(e.duration?1e3*e.duration:this._duration),this._flying=!0,B.scheduleTask(this._update,this)}jumpTo(e){this._jumpTo(e)}_jumpTo(e){this._flying&&this.stop();const t=this.scene.camera;var s,n,i,r,a;if(e.aabb)s=e.aabb;else if(6===e.length)s=e;else if(e.eye||e.look||e.up)i=e.eye,r=e.look,a=e.up;else{let t=e;if((g.isNumeric(t)||g.isString(t))&&(n=t,t=this.scene.components[n],!t))return void this.error("Component not found: "+g.inQuotes(n));s=t.aabb||this.scene.aabb}const o=e.poi;if(s){if(s[3]<=s[0]||s[4]<=s[1]||s[5]<=s[2])return;var l=o?d.getAABB3DiagPoint(s,o):d.getAABB3Diag(s);let n;r=o||d.getAABB3Center(s,r),this._trail?d.subVec3(t.look,r,Wh):d.subVec3(t.eye,t.look,Wh),d.normalizeVec3(Wh);n=(void 0!==e.fit?e.fit:this._fit)?Math.abs(l/Math.tan((e.fitFOV||this._fitFOV)*d.DEGTORAD)):d.lenVec3(d.subVec3(t.eye,t.look,jh)),d.mulVec3Scalar(Wh,n),t.eye=d.addVec3(r,Wh,jh),t.look=r,this.scene.camera.ortho.scale=1.1*l}else(i||r||a)&&(i&&(t.eye=i),r&&(t.look=r),a&&(t.up=a));e.projection&&(t.projection=e.projection)}_update(){if(!this._flying)return;let e=(Date.now()-this._time1)/(this._time2-this._time1);const t=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<e.length;r++){const a=new Image;a.onload=function(){let e=a;const o=r;return function(){if(!n&&(e=ep(e),t._images[o]=e,i++,6===i)){let e=t._state.texture;e||(e=new Ui({gl:s,target:s.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}}(),a.onerror=function(){n=!0},a.src=e[r]}}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),m.memory.textures--,this._state.destroy()}}class ip extends np{get type(){return"ReflectionMap"}constructor(e,t={}){super(e,t),this.scene._lightsState.addReflectionMap(this._state),this.scene._reflectionMapCreated(this)}destroy(){super.destroy(),this.scene._reflectionMapDestroyed(this)}}class rp extends np{get type(){return"LightMap"}constructor(e,t={}){super(e,t),this.scene._lightMapCreated(this)}destroy(){super.destroy(),this.scene._lightMapDestroyed(this)}}class ap extends he{constructor(e,t={}){super(e,{entity:t.entity,occludable:t.occludable,worldPos:t.worldPos}),this._occluded=!1,this._visible=!0,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,{src:t.src}),this._geometry=new Vt(this,{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]}),this._mesh=new pi(this,{geometry:this._geometry,material:new Kt(this,{ambient:[.9,.3,.9],shininess:30,diffuseMap:this._texture,backfaces:!0}),scale:[1,1,1],position:t.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),this.visible=!0,this.collidable=t.collidable,this.clippable=t.clippable,this.pickable=t.pickable,this.opacity=t.opacity,this.size=t.size,t.image?this.image=t.image:this.src=t.src}_setVisible(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,super._setVisible(e)}set visible(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}get visible(){return this._visible}set image(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)}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 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;e<t;e++){const t=d[p[e].id];if(t){if(n&&(this.objectsVisible[e]=t.visible),i&&(this.objectsEdges[e]=t.edges),r&&(this.objectsXrayed[e]=t.xrayed),a&&(this.objectsHighlighted[e]=t.highlighted),o&&(this.objectsSelected[e]=t.selected),l&&(this.objectsClippable[e]=t.clippable),c&&(this.objectsPickable[e]=t.pickable),u){const s=t.colorize;this.objectsColorize[3*e+0]=s[0],this.objectsColorize[3*e+1]=s[1],this.objectsColorize[3*e+2]=s[2]}h&&(this.objectsOpacity[e]=t.opacity),this.numObjects++}}}restoreObjects(e,t){const s=this._mask,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;e<t;e++){const t=d[p[e].id];t&&(n&&(t.visible=this.objectsVisible[e]),i&&(t.edges=this.objectsEdges[e]),r&&(t.xrayed=this.objectsXrayed[e]),a&&(t.highlighted=this.objectsHighlighted[e]),o&&(t.selected=this.objectsSelected[e]),l&&(t.clippable=this.objectsClippable[e]),c&&(t.pickable=this.objectsPickable[e]),u&&(lp[0]=this.objectsColorize[3*e+0],lp[1]=this.objectsColorize[3*e+1],lp[2]=this.objectsColorize[3*e+2],t.colorize=lp),h&&(t.opacity=this.objectsOpacity[e]))}}}const up=d.vec3();class hp{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?g.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]?(up[0]=this.objectsColorize[3*h+0],up[1]=this.objectsColorize[3*h+1],up[2]=this.objectsColorize[3*h+2],t.colorize=up):t.colorize=null),u&&(t.opacity=this.objectsOpacity[h]),h++}}}class pp extends Fh{constructor(e,t={}){super(e,t),this.v0=t.v0,this.v1=t.v1,this.v2=t.v2,this.v3=t.v3,this.t=t.t}set v0(e){this._v0=e||d.vec3([0,0,0])}get v0(){return this._v0}set v1(e){this._v1=e||d.vec3([0,0,0])}get v1(){return this._v1}set v2(e){this._v2=e||d.vec3([0,0,0])}get v2(){return this._v2}set v3(e){this.fire("v3",this._v3=e||d.vec3([0,0,0]))}get v3(){return this._v3}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=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;s<n;s++)(t=this._curves[s]).off(this._dirtySubs[s]),t.off(this._destroyedSubs[s]);this._curves=[],this._dirtySubs=[],this._destroyedSubs=[];var i=this;function r(){i._dirty=!0}function a(){var e=this.id;for(s=0,n=i._curves.length;s<n;s++)if(i._curves[s].id===e)return i._curves=i._curves.slice(s,s+1),i._dirtySubs=i._dirtySubs.slice(s,s+1),i._destroyedSubs=i._destroyedSubs.slice(s,s+1),void(i._dirty=!0)}for(s=0,n=e.length;s<n;s++){if(t=e[s],g.isNumeric(t)||g.isString(t)){var o=t;if(!(t=this.scene.components[o])){this.error("Component not found: "+_inQuotes(o));continue}}var l=t.type;"xeokit.SplineCurve"===l||"xeokit.Path"===l||"xeokit.CubicBezierCurve"===l||"xeokit.QuadraticBezierCurve"===l?(this._curves.push(t),this._dirtySubs.push(t.on("dirty",r)),this._destroyedSubs.push(t.once("destroyed",a))):this.error("Component "+_inQuotes(t.id)+" is not a xeokit.SplineCurve, xeokit.Path or xeokit.QuadraticBezierCurve")}this._dirty=!0}get curves(){return this._curves}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)}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<n.length;){if(n[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;e<n;e++)s+=this._curves[e].length,t.push(s);return this._cachedLengths=t,this._dirty=!1,t}_getJSON(){for(var e=[],t=0,s=this._curves.length;t<s;t++)e.push(this._curves[t].id);return{curves:e,t:this._t}}destroy(){var e,t,s;for(super.destroy(),e=0,t=this._curves.length;e<t;e++)(s=this._curves[e]).off(this._dirtySubs[e]),s.off(this._destroyedSubs[e])}}class Ap extends Fh{constructor(e,t={}){super(e,t),this.v0=t.v0,this.v1=t.v1,this.v2=t.v2,this.t=t.t}set v0(e){this._v0=e||d.vec3([0,0,0])}get v0(){return this._v0}set v1(e){this._v1=e||d.vec3([0,0,0])}get v1(){return this._v1}set v2(e){this._v2=e||d.vec3([0,0,0])}get v2(){return this._v2}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=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)<s}if("perspective"===i.projection){i.ortho.scale=i.ortho.scale-s;const n=this._unproject(t,Tp),r=d.subVec3(n,i.eye,Dp),a=d.mulVec3Scalar(d.normalizeVec3(r),-s,[]);if(i.eye=[i.eye[0]-a[0],i.eye[1]-a[1],i.eye[2]-a[2]],i.look=[i.look[0]-a[0],i.look[1]-a[1],i.look[2]-a[2]],e){const t=d.subVec3(e,i.eye,wp),s=d.lenVec3(t),n=d.mulVec3Scalar(d.normalizeVec3(d.subVec3(i.look,i.eye,gp)),s);i.look=[i.eye[0]+n[0],i.eye[1]+n[1],i.eye[2]+n[2]]}}else if("ortho"===i.projection){const e=this._unproject(t,Tp);i.ortho.scale=i.ortho.scale-s,i.ortho._update();const n=this._unproject(t,bp),r=d.subVec3(n,e,Dp),a=d.mulVec3Scalar(d.normalizeVec3(d.subVec3(i.look,i.eye,wp)),-s,gp),o=d.addVec3(r,a,Ep);i.eye=[i.eye[0]-o[0],i.eye[1]-o[1],i.eye[2]-o[2]],i.look=[i.look[0]-o[0],i.look[1]-o[1],i.look[2]-o[2]]}return n}_unproject(e,t){const s=this._scene.camera,n=s.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);return s.project.unproject(e,o,yp,vp,t),t}destroy(){}}const Cp=d.vec3(),_p=d.vec3(),Rp=d.vec3(),Bp=d.vec4(),Op=d.vec4(),Sp=d.vec4();class Np{constructor(e,t){this._scene=e,this._configs=t,this._pivotWorldPos=d.vec3(),this._cameraOffset=d.vec3(),this._azimuth=0,this._polar=0,this._radius=0,this._pivotPosSet=!1,this._pivoting=!1,this._shown=!1,this._pivotSphereEnabled=!1,this._pivotSphere=null,this._pivotSphereSize=1,this._pivotSphereGeometry=null,this._pivotSphereMaterial=null,this._rtcCenter=d.vec3(),this._rtcPos=d.vec3(),this._pivotViewPos=d.vec4(),this._pivotProjPos=d.vec4(),this._pivotCanvasPos=d.vec2(),this._cameraDirty=!0,this._onViewMatrix=this._scene.camera.on("viewMatrix",(()=>{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<w&&(r=w);const a=Math.max(-1,Math.min(1,40*-e.deltaY));if(0===a)return;const o=a/Math.abs(a);i.dollyDelta+=-o*r*s.mouseWheelDollyRate,I&&(n.followPointerDirty=!0,I=!1)},{passive:!0})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("keydown",this._documentKeyDownHandler),document.removeEventListener("keyup",this._documentKeyUpHandler),e.removeEventListener("mousedown",this._mouseDownHandler),document.removeEventListener("mousemove",this._documentMouseMoveHandler),e.removeEventListener("mousemove",this._canvasMouseMoveHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._mouseUpHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("wheel",this._mouseWheelHandler)}}const Fp=d.vec3(),Hp=d.vec3(),Up=d.vec3(),Gp=d.vec3(),jp=d.vec3(),Vp={eye:d.vec3(),look:d.vec3(),up:d.vec3()};class kp{constructor(e,t,s,n){this._scene=e;const i=t.cameraControl,r=e.camera;this._onSceneKeyDown=e.input.on("keydown",(()=>{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<s.dollyMinSpeed&&(u=s.dollyMinSpeed)}const p=i.dollyDelta*u;if(0===i.rotateDeltaY&&0===i.rotateDeltaX||(!s.firstPerson&&s.followPointer&&o.getPivoting()?(o.continuePivot(i.rotateDeltaY,i.rotateDeltaX),o.showPivot()):(0!==i.rotateDeltaX&&(s.firstPerson?r.pitch(-i.rotateDeltaX):r.orbitPitch(i.rotateDeltaX)),0!==i.rotateDeltaY&&(s.firstPerson?r.yaw(i.rotateDeltaY):r.orbitYaw(i.rotateDeltaY))),i.rotateDeltaX*=s.rotationInertia,i.rotateDeltaY*=s.rotationInertia,t="grabbing"),Math.abs(i.panDeltaX)<.001&&(i.panDeltaX=0),Math.abs(i.panDeltaY)<.001&&(i.panDeltaY=0),Math.abs(i.panDeltaZ)<.001&&(i.panDeltaZ=0),0!==i.panDeltaX||0!==i.panDeltaY||0!==i.panDeltaZ){const e=d.vec3();let n,a;if(e[0]=i.panDeltaX,e[1]=i.panDeltaY,e[2]=i.panDeltaZ,s.constrainVertical){r.xUp?(n=r.eye[0],a=r.look[0]):r.yUp?(n=r.eye[1],a=r.look[1]):r.zUp&&(n=r.eye[2],a=r.look[2]),r.pan(e);const t=r.eye,s=r.look;r.xUp?(t[0]=n,s[0]=a):r.yUp?(t[1]=n,s[1]=a):r.zUp&&(t[2]=n,s[2]=a),r.eye=t,r.look=s}else r.pan(e);t="grabbing"}if(i.panDeltaX*=s.panInertia,i.panDeltaY*=s.panInertia,i.panDeltaZ*=s.panInertia,0!==p){if(t=p<0?"zoom-in":"zoom-out",s.firstPerson){let e,t;if(s.constrainVertical&&(r.xUp?(e=r.eye[0],t=r.look[0]):r.yUp?(e=r.eye[1],t=r.look[1]):r.zUp&&(e=r.eye[2],t=r.look[2])),s.followPointer){l.dollyToCanvasPos(h,n.pointerCanvasPos,-p)&&(n.followPointerDirty=!0)}else r.pan([0,0,p]),r.ortho.scale=r.ortho.scale-p;if(s.constrainVertical){const s=r.eye,n=r.look;r.xUp?(s[0]=e,n[0]=t):r.yUp?(s[1]=e,n[1]=t):r.zUp&&(s[2]=e,n[2]=t),r.eye=s,r.look=n}}else if(s.planView)if(s.followPointer){l.dollyToCanvasPos(h,n.pointerCanvasPos,-p)&&(n.followPointerDirty=!0)}else r.ortho.scale=r.ortho.scale+p,r.zoom(p);else if(s.followPointer){l.dollyToCanvasPos(h,n.pointerCanvasPos,-p)&&(n.followPointerDirty=!0)}else r.ortho.scale=r.ortho.scale+p,r.zoom(p);i.dollyDelta*=s.dollyInertia}a.fireEvents(),document.body.style.cursor=t}))}destroy(){this._scene.off(this._onTick)}}class Yp{constructor(e,t,s,n,i){this._scene=e;const r=this._scene.canvas.canvas;r.addEventListener("mouseenter",this._mouseEnterHandler=()=>{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<i.length;)h.push(d.vec2());for(let e=0,t=i.length;e<t;++e)qp(i[e],h[e]);A=i.length}),p.addEventListener("touchend",this._canvasTouchEndHandler=()=>{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<A;++e)qp(I[e],h[e])}})}reset(){}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler),e.removeEventListener("touchmove",this._canvasTouchMoveHandler),this._scene.off(this._onTick)}}const Zp=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 $p{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.cameraControl;let o;const l=[],c=new Float32Array(2);let u=-1,h=-1;const p=this._scene.canvas.canvas,A=s=>{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<i.length;)l.push(new Float32Array(2));for(let e=0,t=i.length;e<t;++e)Zp(i[e],l[e]);l.length=i.length},{passive:!0}),p.addEventListener("touchend",this._canvasTouchEndHandler=e=>{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<t;++e)l[e][0]=i[e].pageX,l[e][1]=i[e].pageY},{passive:!0})}reset(){}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler)}}class ed extends x{constructor(e,t={}){super(e,t),this.PAN_LEFT=0,this.PAN_RIGHT=1,this.PAN_UP=2,this.PAN_DOWN=3,this.PAN_FORWARDS=4,this.PAN_BACKWARDS=5,this.ROTATE_X_POS=6,this.ROTATE_X_NEG=7,this.ROTATE_Y_POS=8,this.ROTATE_Y_NEG=9,this.DOLLY_FORWARDS=10,this.DOLLY_BACKWARDS=11,this.AXIS_VIEW_RIGHT=12,this.AXIS_VIEW_BACK=13,this.AXIS_VIEW_LEFT=14,this.AXIS_VIEW_FRONT=15,this.AXIS_VIEW_TOP=16,this.AXIS_VIEW_BOTTOM=17,this._keyMap={},this.scene.canvas.canvas.oncontextmenu=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;e<n;e++){if(t[s[e]])return!0}return!1}set pivotElement(e){this._controllers.pivotController.setPivotElement(e)}set active(e){e=!1!==e,this._configs.active=e,this._handlers[1]._active=e,this._handlers[5]._active=e}get active(){return this._configs.active}set snapToVertex(e){this._configs.snapToVertex=!!e}get snapToVertex(){return this._configs.snapToVertex}set snapToEdge(e){this._configs.snapToEdge=!!e}get snapToEdge(){return this._configs.snapToEdge}set snapRadius(e){e=e||30,this._configs.snapRadius=e}get snapRadius(){return this._configs.snapRadius}set navMode(e){"firstPerson"!==(e=e||"orbit")&&"orbit"!==e&&"planView"!==e&&(this.error("Unsupported value for navMode: "+e+" - supported values are 'orbit', 'firstPerson' and 'planView' - defaulting to 'orbit'"),e="orbit"),this._configs.firstPerson="firstPerson"===e,this._configs.planView="planView"===e,(this._configs.firstPerson||this._configs.planView)&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this._configs.navMode=e}get navMode(){return this._configs.navMode}set pointerEnabled(e){this._reset(),this._configs.pointerEnabled=!!e}_reset(){for(let e=0,t=this._handlers.length;e<t;e++){const t=this._handlers[e];t.reset&&t.reset()}this._updates.panDeltaX=0,this._updates.panDeltaY=0,this._updates.rotateDeltaX=0,this._updates.rotateDeltaY=0,this._updates.dolyDelta=0}get pointerEnabled(){return this._configs.pointerEnabled}set followPointer(e){this._configs.followPointer=!1!==e}get followPointer(){return this._configs.followPointer}set pivotPos(e){this._controllers.pivotController.setPivotPos(e)}get pivotPos(){return this._controllers.pivotController.getPivotPos()}set dollyToPointer(e){this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer=e}get dollyToPointer(){return this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer}set panToPointer(e){this.warn("panToPointer property is deprecated - replaced with followPointer")}get panToPointer(){return this.warn("panToPointer property is deprecated - replaced with followPointer"),!1}set planView(e){this._configs.planView=!!e,this._configs.firstPerson=!1,this._configs.planView&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this.warn("planView property is deprecated - replaced with navMode")}get planView(){return this.warn("planView property is deprecated - replaced with navMode"),this._configs.planView}set firstPerson(e){this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson=!!e,this._configs.planView=!1,this._configs.firstPerson&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot())}get firstPerson(){return this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson}set constrainVertical(e){this._configs.constrainVertical=!!e}get constrainVertical(){return this._configs.constrainVertical}set doublePickFlyTo(e){this._configs.doublePickFlyTo=!1!==e}get doublePickFlyTo(){return this._configs.doublePickFlyTo}set panRightClick(e){this._configs.panRightClick=!1!==e}get panRightClick(){return this._configs.panRightClick}set rotationInertia(e){this._configs.rotationInertia=null!=e?e:0}get rotationInertia(){return this._configs.rotationInertia}set keyboardPanRate(e){this._configs.keyboardPanRate=null!=e?e:5}set touchPanRate(e){this._configs.touchPanRate=null!=e?e:1}get touchPanRate(){return this._configs.touchPanRate}get keyboardPanRate(){return this._configs.keyboardPanRate}set keyboardRotationRate(e){this._configs.keyboardRotationRate=null!=e?e:90}get keyboardRotationRate(){return this._configs.keyboardRotationRate}set dragRotationRate(e){this._configs.dragRotationRate=null!=e?e:360}get dragRotationRate(){return this._configs.dragRotationRate}set keyboardDollyRate(e){this._configs.keyboardDollyRate=null!=e?e:15}get keyboardDollyRate(){return this._configs.keyboardDollyRate}set touchDollyRate(e){this._configs.touchDollyRate=null!=e?e:.2}get touchDollyRate(){return this._configs.touchDollyRate}set mouseWheelDollyRate(e){this._configs.mouseWheelDollyRate=null!=e?e:100}get mouseWheelDollyRate(){return this._configs.mouseWheelDollyRate}set dollyInertia(e){this._configs.dollyInertia=null!=e?e:0}get dollyInertia(){return this._configs.dollyInertia}set dollyProximityThreshold(e){this._configs.dollyProximityThreshold=null!=e?e:35}get dollyProximityThreshold(){return this._configs.dollyProximityThreshold}set dollyMinSpeed(e){this._configs.dollyMinSpeed=null!=e?e:.04}get dollyMinSpeed(){return this._configs.dollyMinSpeed}set panInertia(e){this._configs.panInertia=null!=e?e:.5}get panInertia(){return this._configs.panInertia}set keyboardLayout(e){"qwerty"!==(e=e||"qwerty")&&"azerty"!==e&&(this.error("Unsupported value for keyboardLayout - defaulting to 'qwerty'"),e="qwerty"),this._configs.keyboardLayout=e,this.keyMap=this._configs.keyboardLayout}get keyboardLayout(){return this._configs.keyboardLayout}enablePivotSphere(e={}){this._controllers.pivotController.enablePivotSphere(e)}disablePivotSphere(){this._controllers.pivotController.disablePivotSphere()}set smartPivot(e){this._configs.smartPivot=!1!==e}get smartPivot(){return this._configs.smartPivot}set doubleClickTimeFrame(e){this._configs.doubleClickTimeFrame=null!=e?e:250}get doubleClickTimeFrame(){return this._configs.doubleClickTimeFrame}destroy(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),super.destroy()}_destroyHandlers(){for(let e=0,t=this._handlers.length;e<t;e++){const t=this._handlers[e];t.destroy&&t.destroy()}}_destroyControllers(){for(let e=0,t=this._controllers.length;e<t;e++){const t=this._controllers[e];t.destroy&&t.destroy()}}}class td{constructor(e,t,s,n,i){this.name=e,this.type=s,this.value=t,this.valueType=n,this.description=i}}class sd{constructor(e){if(this.id=e.id,this.originalSystemId=e.originalSystemId,this.metaModels=[],this.name=e.name,this.type=e.type,this.properties=[],e.properties){const t=e.properties;for(let e=0,s=t.length;e<s;e++){const s=t[e];this.properties.push(new td(s.name,s.value,s.type,s.valueType,s.description))}}}}class nd{constructor(e){this.metaModels=[],this.id=e.id,this.parentId=e.parentId,this.parent=null,this.originalSystemId=e.originalSystemId,this.name=e.name,this.type=e.type,this.propertySetIds=e.propertySetIds,this.propertySets=[],this.attributes=e.attributes||{},void 0!==e.external&&null!==e.external&&(this.external=e.external)}get metaModel(){return 1==this.metaModels.length?this.metaModels[0]:null}getObjectIDsInSubtree(){const e=[];return function t(s){if(!s)return;e.push(s.id);const n=s.children;if(n)for(var i=0,r=n.length;i<r;i++)t(n[i])}(this),e}withMetaObjectsInSubtree(e){!function t(s){if(!s)return;e(s);const n=s.children;if(n)for(var i=0,r=n.length;i<r;i++)t(n[i])}(this)}getObjectIDsInSubtreeByType(e){const t={};for(var s=0,n=e.length;s<n;s++)t[e[s]]=e[s];const i=[];return function e(s){if(!s)return;t[s.type]&&i.push(s.id);const n=s.children;if(n)for(var r=0,a=n.length;r<a;r++)e(n[r])}(this),i}getJSON(){var e={id:this.id,type:this.type,name:this.name};return this.parent&&(e.parent=this.parent.id),e}}class id{constructor(e){this.id=e.id,this.projectId=e.projectId,this.revisionId=e.revisionId,this.author=e.author,this.createdAt=e.createdAt,this.creatingApplication=e.creatingApplication,this.schema=e.schema,this.metaScene=e.metaScene,this.propertySets=[],this.rootMetaObjects=[],this.metaObjects=[],this.graph=e.graph||{},this.metaScene.metaModels[this.id]=this,this.finalized=!1}get rootMetaObject(){return 1==this.rootMetaObjects.length?this.rootMetaObjects[0]:null}loadData(e,t={}){if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);const s=this.metaScene,n=e.properties;if(e.propertySets)for(let t=0,i=e.propertySets.length;t<i;t++){const i=e.propertySets[t];let r=s.propertySets[i.id];r||(n&&this._decompressProperties(n,i.properties),r=new sd({id:i.id,originalSystemId:i.originalSystemId||i.id,type:i.type,name:i.name,properties:i.properties}),s.propertySets[r.id]=r),r.metaModels.push(this),this.propertySets.push(r)}if(e.metaObjects)for(let t=0,n=e.metaObjects.length;t<n;t++){const n=e.metaObjects[t],i=n.id;let r=s.metaObjects[i];if(!r){const e=n.type,t=n.originalSystemId,s=n.propertySets||n.propertySetIds;r=new nd({id:i,originalSystemId:t,parentId:n.parent,type:e,name:n.name,attributes:n.attributes,propertySetIds:s,external:n.external}),this.metaScene.metaObjects[i]=r,r.metaModels=[]}this.metaObjects.push(r),n.parent||(this.rootMetaObjects.push(r),s.rootMetaObjects[i]=r)}}_decompressProperties(e,t){for(let s=0,n=t.length;s<n;s++){const n=t[s];if(Number.isInteger(n)){const i=e[n];i&&(t[s]=i)}}}finalize(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";const e=this.metaScene;for(let t in e.metaObjects){const s=e.metaObjects[t];if(s.children&&(s.children=[]),s.propertySets&&(s.propertySets=[]),s.propertySetIds)for(let t=0,n=s.propertySetIds.length;t<n;t++){const n=s.propertySetIds[t],i=e.propertySets[n];s.propertySets.push(i)}}for(let t in e.metaObjects){const s=e.metaObjects[t];if(s.parentId){const t=e.metaObjects[s.parentId];t&&(s.parent=t,(t.children||(t.children=[])).push(s))}}for(let t in e.metaObjects){e.metaObjects[t].metaModels=[]}for(let t in e.metaModels){const s=e.metaModels[t];for(let e=0,t=s.metaObjects.length;e<t;e++){s.metaObjects[e].metaModels.push(s)}}e.metaObjectsByType={};for(let t in e.metaObjects){const s=e.metaObjects[t],n=s.type;(e.metaObjectsByType[n]||(e.metaObjectsByType[n]={}))[t]=s}this.finalized=!0,this.metaScene.fire("metaModelCreated",this.id)}getJSON(){const e={id:this.id,projectId:this.projectId,author:this.author,createdAt:this.createdAt,schema:this.schema,creatingApplication:this.creatingApplication,metaObjects:[],propertySets:[]};for(let t=0,s=this.metaObjects.length;t<s;t++){const s=this.metaObjects[t],n={id:s.id,originalSystemId:s.originalSystemId,extId:s.extId,type:s.type,name:s.name};s.parent&&(n.parent=s.parent.id),s.attributes&&(n.attributes=s.attributes),s.propertySetIds&&(n.propertySetIds=s.propertySetIds),e.metaObjects.push(n)}for(let t=0,s=this.propertySets.length;t<s;t++){const s=this.propertySets[t],n={id:s.id,originalSystemId:s.originalSystemId,extId:s.extId,type:s.type,name:s.name,propertyies:[]};for(let e=0,t=s.properties.length;e<t;e++){const t=s.properties[e],i={id:t.id,description:t.description,type:t.type,name:t.name,value:t.value,valueType:t.valueType};n.properties.push(i)}e.propertySets.push(n)}return e}_globalizeIDs(e,t){const s=!!t.globalizeObjectIds;if(e.metaObjects)for(let t=0,n=e.metaObjects.length;t<n;t++){const n=e.metaObjects[t];if(n.originalSystemId=n.id,n.parent&&(n.originalParentSystemId=n.parent),s&&(n.id=d.globalizeObjectId(this.id,n.id),n.parent&&(n.parent=d.globalizeObjectId(this.id,n.parent))),s){const e=n.propertySetIds;if(e){const t=[];for(let s=0,n=e.length;s<n;s++)t.push(d.globalizeObjectId(this.id,e[s]));n.propertySetIds=t,n.originalSystemPropertySetIds=e}}else n.originalSystemPropertySetIds=n.propertySetIds}if(e.propertySets)for(let t=0,n=e.propertySets.length;t<n;t++){const n=e.propertySets[t];n.originalSystemId=n.id,s&&(n.id=d.globalizeObjectId(this.id,n.id))}}}class rd{constructor(e,t){this.viewer=e,this.scene=t,this.metaModels={},this.propertySets={},this.metaObjects={},this.metaObjectsByType={},this.rootMetaObjects={},this._eventSubs={}}on(e,t){let s=this._eventSubs[e];s||(s=[],this._eventSubs[e]=s),s.push(t)}fire(e,t){const s=this._eventSubs[e];if(s)for(let e=0,n=s.length;e<n;e++)s[e](t)}off(e){}createMetaModel(e,t,s={}){const n=new id({metaScene:this,id:e,projectId:t.projectId||"none",revisionId:t.revisionId||"none",author:t.author||"none",createdAt:t.createdAt||"none",creatingApplication:t.creatingApplication||"none",schema:t.schema||"none",propertySets:[]});return n.loadData(t),n.finalize(),n}destroyMetaModel(e){const t=this.metaModels[e];if(t){if(t.propertySets)for(let s=0,n=t.propertySets.length;s<n;s++){const n=t.propertySets[s];if(1===n.metaModels.length&&n.metaModels[0].id===e)delete this.propertySets[n.id];else{const t=[];for(let s=0,i=n.metaModels.length;s<i;s++)n.metaModels[s].id!==e&&t.push(n.metaModels[s]);n.metaModels=t}}if(t.metaObjects)for(let s=0,n=t.metaObjects.length;s<n;s++){const n=t.metaObjects[s];n.type;const i=n.id;1===n.metaModels.length&&n.metaModels[0].id===e&&(delete this.metaObjects[i],n.parent||delete this.rootMetaObjects[i])}for(let e in this.metaObjects){const t=this.metaObjects[e];if(t.children&&(t.children=[]),t.propertySets&&(t.propertySets=[]),t.propertySetIds)for(let e=0,s=t.propertySetIds.length;e<s;e++){const s=t.propertySetIds[e],n=this.propertySets[s];t.propertySets.push(n)}}this.metaObjectsByType={};for(let e in this.metaObjects){const t=this.metaObjects[e],s=t.type;t.children&&(t.children=null),(this.metaObjectsByType[s]||(this.metaObjectsByType[s]={}))[e]=t}for(let e in this.metaObjects){const t=this.metaObjects[e];if(t.parentId){const e=this.metaObjects[t.parentId];e&&(t.parent=e,(e.children||(e.children=[])).push(t))}}delete this.metaModels[e];for(let e in this.metaObjects){this.metaObjects[e].metaModels=[]}for(let e in this.metaModels){const t=this.metaModels[e];for(let e=0,s=t.metaObjects.length;e<s;e++){t.metaObjects[e].metaModels.push(t)}}this.fire("metaModelDestroyed",e)}}getObjectIDsByType(e){const t=this.metaObjectsByType[e];return t?Object.keys(t):[]}getObjectIDsInSubtree(e,t,s){const n=[],i=this.metaObjects[e],r=t&&t.length>0?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<l;i++)o(s[i])};return o(i),n}withMetaObjectsInSubtree(e,t){const s=this.metaObjects[e];s&&s.withMetaObjectsInSubtree(t)}}function ad(e){const t={};for(var s=0,n=e.length;s<n;s++)t[e[s]]=!0;return t}
17
+ **/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;e++)s[e]=e;Ku=new Int32Array(e.length);for(let s=0,n=e.length;s<n;s++)Ku[s]=e[s]>>t;s.sort(Yu);const n=new Int32Array(e.length);for(let t=0,i=s.length;t<i;t++)n[3*t+0]=e[3*s[t]+0],n[3*t+1]=e[3*s[t]+1],n[3*t+2]=e[3*s[t]+2];return n}(e.indices||[],t),r=function(e){if(0===(e||[]).length)return[];let t=new Int32Array(e.length/2);for(let e=0,s=t.length;e<s;e++)t[e]=e;for(let t=0,s=e.length;t<s;t+=2)if(e[t]>e[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;n<i;n++)s[2*n+0]=e[2*t[n]+0],s[2*n+1]=e[2*t[n]+1];return s}(e.edgeIndices||[]);function a(e,t){if(e>t){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<<t))return[e];const c=new Int32Array(l);c.fill(-1);const u=[];function h(){c.fill(-1);const e={positionsCompressed:[],indices:[],edgeIndices:[],maxNumPositions:(1<<t)-t,numPositions:0,bucketNumber:u.length};return u.push(e),e}let p=h();for(let t=0,s=i.length;t<s;t+=3){let s=0;const l=i[t],u=i[t+1],d=i[t+2];if(-1===c[l]&&s++,-1===c[u]&&s++,-1===c[d]&&s++,s+p.numPositions>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;e<n;e+=3){const n=a[3*t[e]]+"_"+a[3*t[e]+1]+"_"+a[3*t[e]+2]+"/"+a[3*t[e+1]]+"_"+a[3*t[e+1]+1]+"_"+a[3*t[e+1]+2]+"/"+a[3*t[e+2]]+"_"+a[3*t[e+2]+1]+"_"+a[3*t[e+2]+2];s[n]=!0}i+=e.edgeIndices.length/2;for(let e=0,t=r.length;e<t;e+=2){const t=a[3*r[e]]+"_"+a[3*r[e]+1]+"_"+a[3*r[e]+2]+"/"+a[3*r[e+1]]+"_"+a[3*r[e+1]+1]+"_"+a[3*r[e+1]+2]+"/";n[t]=!0}}));{const e=t.indices;t.edgeIndices;const n=t.positionsCompressed;for(let t=0,i=e.length;t<i;t+=3){const i=n[3*e[t]]+"_"+n[3*e[t]+1]+"_"+n[3*e[t]+2]+"/"+n[3*e[t+1]]+"_"+n[3*e[t+1]+1]+"_"+n[3*e[t+1]+2]+"/"+n[3*e[t+2]]+"_"+n[3*e[t+2]+1]+"_"+n[3*e[t+2]+2];if(!(i in s))throw console.log("Not found "+i),"Ohhhh!"}}}(u,e),u)}const Zu=d.vec4(4),$u=d.vec4(),eh=d.vec4(),th=d.vec3([1,0,0]),sh=d.vec3([0,1,0]),nh=d.vec3([0,0,1]);d.vec3(3),d.vec3(3);const ih=d.identityMat4();class rh{constructor(e){this._model=e.model,this.id=e.id,this._parentTransform=e.parent,this._childTransforms=[],this._meshes=[],this._scale=new Float32Array([1,1,1]),this._quaternion=d.identityQuaternion(new Float32Array(4)),this._rotation=new Float32Array(3),this._position=new Float32Array(3),this._localMatrix=d.identityMat4(new Float32Array(16)),this._worldMatrix=d.identityMat4(new Float32Array(16)),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,e.matrix?this.matrix=e.matrix:(this.scale=e.scale,this.position=e.position,e.quaternion||(this.rotation=e.rotation)),e.parent&&e.parent._addChildTransform(this)}_addChildTransform(e){this._childTransforms.push(e),e._parentTransform=this,e._setWorldMatrixDirty(),e._setAABBDirty()}_addMesh(e){this._meshes.push(e),e.transform=this}get parentTransform(){return this._parentTransform}get meshes(){return this._meshes}set position(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._model.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),d.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._model.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._setLocalMatrixDirty(),this._model.glRedraw()}get quaternion(){return this._quaternion}set scale(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._model.glRedraw()}get scale(){return this._scale}set matrix(e){this._localMatrix||(this._localMatrix=d.identityMat4()),this._localMatrix.set(e||ih),d.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._transformDirty(),this._model.glRedraw()}get matrix(){return this._localMatrixDirty&&(this._localMatrix||(this._localMatrix=d.identityMat4()),d.composeMat4(this._position,this._quaternion,this._scale,this._localMatrix),this._localMatrixDirty=!1),this._localMatrix}get worldMatrix(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}rotate(e,t){return Zu[0]=e[0],Zu[1]=e[1],Zu[2]=e[2],Zu[3]=t*d.DEGTORAD,d.angleAxisToQuaternion(Zu,$u),d.mulQuaternions(this.quaternion,$u,eh),this.quaternion=eh,this._setLocalMatrixDirty(),this._model.glRedraw(),this}rotateOnWorldAxis(e,t){return Zu[0]=e[0],Zu[1]=e[1],Zu[2]=e[2],Zu[3]=t*d.DEGTORAD,d.angleAxisToQuaternion(Zu,$u),d.mulQuaternions($u,this.quaternion,$u),this}rotateX(e){return this.rotate(th,e)}rotateY(e){return this.rotate(sh,e)}rotateZ(e){return this.rotate(nh,e)}translate(e){return this._position[0]+=e[0],this._position[1]+=e[1],this._position[2]+=e[2],this._setLocalMatrixDirty(),this._model.glRedraw(),this}translateX(e){return this._position[0]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}translateY(e){return this._position[1]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}translateZ(e){return this._position[2]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}_setLocalMatrixDirty(){this._localMatrixDirty=!0,this._transformDirty()}_transformDirty(){this._worldMatrixDirty=!0;for(let e=0,t=this._childTransforms.length;e<t;e++){const t=this._childTransforms[e];if(t._transformDirty(),t._meshes&&t._meshes.length>0){const e=t._meshes;for(let t=0,s=e.length;t<s;t++)e[t]._transformDirty()}}if(this._meshes&&this._meshes.length>0){const e=this._meshes;for(let t=0,s=e.length;t<s;t++)e[t]._transformDirty()}}_buildWorldMatrix(){const e=this.matrix;if(this._parentTransform)d.mulMat4(this._parentTransform.worldMatrix,e,this._worldMatrix);else for(let t=0,s=e.length;t<s;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}_setSubtreeAABBsDirty(e){if(e._aabbDirty=!0,e._childTransforms)for(let t=0,s=e._childTransforms.length;t<s;t++)this._setSubtreeAABBsDirty(e._childTransforms[t])}}const ah=d.vec3(),oh=d.OBB3(),lh=d.vec3([1,1,1]),ch=d.vec3([0,0,0]),uh=d.vec3([0,0,0]),hh=d.identityQuaternion(),ph=d.identityMat4(),dh=new Uint8Array([255,255,255]);class Ah extends x{constructor(e,t={}){super(e,t),this._dtxEnabled=this.scene.dtxEnabled&&!1!==t.dtxEnabled,this._enableVertexWelding=!1,this._enableIndexBucketing=!1,this._vboBatchingLayerScratchMemory=(ur++,cr),this._textureTranscoder=t.textureTranscoder||Vu(this.scene.viewer),this._maxGeometryBatchSize=t.maxGeometryBatchSize,this._aabb=d.collapseAABB3(),this._aabbDirty=!0,this._quantizationRanges={},this._vboInstancingLayers={},this._vboBatchingLayers={},this._dtxLayers={},this.layerList=[],this._entityList=[],this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._transforms={},this._meshes={},this._entities={},this._scheduledMeshes={},this._meshesCfgsBeforeMeshCreation={},this.renderFlags=new ti,this.numGeometries=0,this.numPortions=0,this.numVisibleLayerPortions=0,this.numTransparentLayerPortions=0,this.numXRayedLayerPortions=0,this.numHighlightedLayerPortions=0,this.numSelectedLayerPortions=0,this.numEdgesLayerPortions=0,this.numPickableLayerPortions=0,this.numClippableLayerPortions=0,this.numCulledLayerPortions=0,this.numEntities=0,this._numTriangles=0,this._numLines=0,this._numPoints=0,this._edgeThreshold=t.edgeThreshold||10,this._origin=d.vec3(t.origin||[0,0,0]),this._position=d.vec3(t.position||[0,0,0]),this._rotation=d.vec3(t.rotation||[0,0,0]),this._quaternion=d.vec4(t.quaternion||[0,0,0,1]),this._conjugateQuaternion=d.vec4(t.quaternion||[0,0,0,1]),t.rotation&&d.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._scale=d.vec3(t.scale||[1,1,1]),this._worldRotationMatrix=d.mat4(),this._worldRotationMatrixConjugate=d.mat4(),this._matrix=d.mat4(),this._matrixDirty=!0,this._rebuildMatrices(),this._worldNormalMatrix=d.mat4(),d.inverseMat4(this._matrix,this._worldNormalMatrix),d.transposeMat4(this._worldNormalMatrix),(t.matrix||t.position||t.rotation||t.scale||t.quaternion)&&(this._viewMatrix=d.mat4(),this._viewNormalMatrix=d.mat4(),this._viewMatrixDirty=!0,this._matrixNonIdentity=!0),this._opacity=1,this._colorize=[1,1,1],this._saoEnabled=!1!==t.saoEnabled,this._pbrEnabled=!1!==t.pbrEnabled,this._colorTextureEnabled=!1!==t.colorTextureEnabled,this._isModel=t.isModel,this._isModel&&this.scene._registerModel(this),this._onCameraViewMatrix=this.scene.camera.on("matrix",(()=>{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;e<t;e++)this._entityList[e]._sceneModelDirty()}get worldMatrix(){return this.matrix}get worldNormalMatrix(){return this._worldNormalMatrix}get viewMatrix(){return this._viewMatrix?(this._matrixDirty&&(this._rebuildMatrices(),this._viewMatrixDirty=!0),this._viewMatrixDirty&&(d.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),d.inverseMat4(this._viewMatrix,this._viewNormalMatrix),d.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),this._viewMatrix):this.scene.camera.viewMatrix}get viewNormalMatrix(){return this._viewNormalMatrix?(this._matrixDirty&&(this._rebuildMatrices(),this._viewMatrixDirty=!0),this._viewMatrixDirty&&(d.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),d.inverseMat4(this._viewMatrix,this._viewNormalMatrix),d.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),d.inverseMat4(this._viewMatrix,this._viewNormalMatrix),d.transposeMat4(this._viewNormalMatrix),this._viewNormalMatrix):this.scene.camera.viewNormalMatrix}get backfaces(){return this._backfaces}set backfaces(e){e=!!e,this._backfaces=e,this.glRedraw()}get entityList(){return this._entityList}get isEntity(){return!0}get isModel(){return this._isModel}get isObject(){return!1}get aabb(){if(this._aabbDirty){d.collapseAABB3(this._aabb);for(let e=0,t=this._entityList.length;e<t;e++)d.expandAABB3(this._aabb,this._entityList[e].aabb);this._aabbDirty=!1}return this._aabb}get numTriangles(){return this._numTriangles}get numLines(){return this._numLines}get numPoints(){return this._numPoints}get visible(){return this.numVisibleLayerPortions>0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].visible=e;this.glRedraw()}get xrayed(){return this.numXRayedLayerPortions>0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].xrayed=e;this.glRedraw()}get highlighted(){return this.numHighlightedLayerPortions>0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].highlighted=e;this.glRedraw()}get selected(){return this.numSelectedLayerPortions>0}set selected(e){e=!!e,this._selected=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].selected=e;this.glRedraw()}get edges(){return this.numEdgesLayerPortions>0}set edges(e){e=!!e,this._edges=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].edges=e;this.glRedraw()}get culled(){return this._culled}set culled(e){e=!!e,this._culled=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].culled=e;this.glRedraw()}get clippable(){return this._clippable}set clippable(e){e=!1!==e,this._clippable=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].clippable=e;this.glRedraw()}get collidable(){return this._collidable}set collidable(e){e=!1!==e,this._collidable=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].collidable=e}get pickable(){return this.numPickableLayerPortions>0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].pickable=e}get colorize(){return this._colorize}set colorize(e){this._colorize=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].colorize=e}get opacity(){return this._opacity}set opacity(e){this._opacity=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].opacity=e}get castsShadow(){return this._castsShadow}set castsShadow(e){(e=!1!==e)!==this._castsShadow&&(this._castsShadow=e,this.glRedraw())}get receivesShadow(){return this._receivesShadow}set receivesShadow(e){(e=!1!==e)!==this._receivesShadow&&(this._receivesShadow=e,this.glRedraw())}get saoEnabled(){return this._saoEnabled}get pbrEnabled(){return this._pbrEnabled}get colorTextureEnabled(){return this._colorTextureEnabled}get isDrawable(){return!0}get isStateSortable(){return!1}get xrayMaterial(){return this.scene.xrayMaterial}get highlightMaterial(){return this.scene.highlightMaterial}get selectedMaterial(){return this.scene.selectedMaterial}get edgeMaterial(){return this.scene.edgeMaterial}getPickViewMatrix(e){return this._viewMatrix?this._viewMatrix:e}createQuantizationRange(e){void 0!==e.id&&null!==e.id?e.aabb?this.error("[createQuantizationRange] Config missing: aabb"):this._quantizationRanges[e.id]?this.error("[createQuantizationRange] QuantizationRange already created: "+e.id):this._quantizationRanges[e.id]={id:e.id,aabb:e.aabb,matrix:ia(e.aabb,d.mat4())}:this.error("[createQuantizationRange] Config missing: id")}createGeometry(e){if(void 0!==e.id&&null!==e.id)if(this._geometries[e.id])this.error("[createGeometry] Geometry already created: "+e.id);else 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){if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("[createGeometry] Param expected: `positions`, `positionsCompressed' or 'buckets"),null;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("[createGeometry] Param expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.positionsDecodeMatrix&&e.positionsDecodeBoundary)return this.error("[createGeometry] Only one of these params expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("[createGeometry] Param expected: `uvDecodeMatrix` (required for `uvCompressed')"),null;if(!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error(`[createGeometry] Param expected: indices (required for '${e.primitive}' primitive type)`),null;if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=ia(e.positionsDecodeBoundary,d.mat4())),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();e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed),d.expandAABB3Points3(t,e.positionsCompressed),Ut.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}else if(e.buckets){const t=d.collapseAABB3();this._dtxBuckets[e.id]=e.buckets;for(let s=0,n=e.buckets.length;s<n;s++){const n=e.buckets[s];n.positions?d.expandAABB3Points3(t,n.positions):n.positionsCompressed&&d.expandAABB3Points3(t,n.positionsCompressed)}e.positionsDecodeMatrix&&Ut.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.colorsCompressed&&e.colorsCompressed.length>0)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<n;e++)s[e]=255*t[e];e.colorsCompressed=s}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=St(e.positions,e.indices,null,5):e.edgeIndices=St(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.uv){const t=Ut.getUVBounds(e.uv),s=Ut.compressUVs(e.uv,t.min,t.max);e.uvCompressed=s.quantized,e.uvDecodeMatrix=s.decodeMatrix}else e.uvCompressed&&(e.uvCompressed=new Uint16Array(e.uvCompressed),e.uvDecodeMatrix=new Float64Array(e.uvDecodeMatrix));e.normals&&(e.normals=null),this._geometries[e.id]=e,this._numTriangles+=e.indices?Math.round(e.indices.length/3):0,this.numGeometries++}else this.error(`[createGeometry] Unsupported value for 'primitive': '${e.primitive}' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'.`);else this.error("[createGeometry] Config missing: id")}createTexture(e){const t=e.id;if(null==t)return void this.error("[createTexture] Config missing: id");if(this._textures[t])return void this.error("[createTexture] Texture already created: "+t);if(!e.src&&!e.image&&!e.buffers)return this.error("[createTexture] Param expected: `src`, `image' or 'buffers'"),null;let s=e.minFilter||1008;1006!==s&&1007!==s&&1008!==s&&1005!==s&&1004!==s&&(this.error("[createTexture] Unsupported value for 'minFilter' - \n supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, \n NearestMipMapLinearFilter and LinearMipmapLinearFilter. Defaulting to LinearMipmapLinearFilter."),s=1008);let n=e.magFilter||1006;1006!==n&&1003!==n&&(this.error("[createTexture] Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),n=1006);let i=e.wrapS||1e3;1001!==i&&1002!==i&&1e3!==i&&(this.error("[createTexture] Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),i=1e3);let r=e.wrapT||1e3;1001!==r&&1002!==r&&1e3!==r&&(this.error("[createTexture] Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),r=1e3);let a=e.wrapR||1e3;1001!==a&&1002!==a&&1e3!==a&&(this.error("[createTexture] Unsupported value for 'wrapR' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),a=1e3);let o=e.encoding||3e3;3e3!==o&&3001!==o&&(this.error("[createTexture] Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),o=3e3);const l=new Ui({gl:this.scene.canvas.gl,minFilter:s,magFilter:n,wrapS:i,wrapT:r,wrapR:a,encoding:o});if(e.preloadColor&&l.setPreloadColor(e.preloadColor),e.image){const t=e.image;t.crossOrigin="Anonymous",l.setImage(t,{minFilter:s,magFilter:n,wrapS:i,wrapT:r,wrapR:a,flipY:e.flipY,encoding:o})}else if(e.src){const t=e.src.split(".").pop();switch(t){case"jpeg":case"jpg":case"png":case"gif":const c=new Image;c.onload=()=>{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<n;s++){const n=e.buckets[s];n.positions?d.expandAABB3Points3(t,n.positions):n.positionsCompressed&&d.expandAABB3Points3(t,n.positionsCompressed)}e.positionsDecodeMatrix&&Ut.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}e.meshMatrix&&(d.AABB3ToOBB3(e.aabb,oh),d.transformOBB3(e.meshMatrix,oh),d.OBB3ToAABB3(oh,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=St(e.positions,e.indices,null,2):e.edgeIndices=St(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=fh(e,this._enableVertexWelding&&this._enableIndexBucketing))}else{if(e.type=1,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):[255,255,255],e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.positions){const t=[];Y(e.positions,t,ah)&&(e.positions=t,e.origin=d.addVec3(e.origin,ah,d.vec3()))}if(e.positions){const t=d.collapseAABB3();e.meshMatrix&&(d.transformPositions3(e.meshMatrix,e.positions,e.positions),e.meshMatrix=null),d.expandAABB3Points3(t,e.positions),e.aabb=t}else{const t=d.collapseAABB3();d.expandAABB3Points3(t,e.positionsCompressed),Ut.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.meshMatrix&&(d.AABB3ToOBB3(e.aabb,oh),d.transformOBB3(e.meshMatrix,oh),d.OBB3ToAABB3(oh,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=St(e.positions,e.indices,null,2):e.edgeIndices=St(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId],!e.textureSet))return this.error(`[createMesh] Texture set not found: ${e.textureSetId} - ensure that you create it first with createTextureSet()`),!1}}else{if(e.positions||e.positionsCompressed||e.indices||e.edgeIndices||e.normals||e.normalsCompressed||e.uv||e.uvCompressed||e.positionsDecodeMatrix)return this.error("Mesh geometry parameters not expected when instancing a geometry (not expected: positions, positionsCompressed, indices, edgeIndices, normals, normalsCompressed, uv, uvCompressed, positionsDecodeMatrix)"),!1;if(e.geometry=this._geometries[e.geometryId],!e.geometry)return this.error(`[createMesh] Geometry not found: ${e.geometryId} - ensure that you create it first with createGeometry()`),!1;if(e.origin=e.origin?d.addVec3(this._origin,e.origin,d.vec3()):this._origin,e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.transformId){if(e.transform=this._transforms[e.transformId],!e.transform)return this.error(`[createMesh] Transform not found: ${e.transformId} - ensure that you create it first with createTransform()`),!1;e.aabb=e.geometry.aabb}else{if(e.matrix)e.meshMatrix=e.matrix.slice();else{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())}d.AABB3ToOBB3(e.geometry.aabb,oh),d.transformOBB3(e.meshMatrix,oh),e.aabb=d.OBB3ToAABB3(oh,d.AABB3())}if(!(!this._dtxEnabled||"triangles"!==e.geometry.primitive&&"solid"!==e.geometry.primitive&&"surface"!==e.geometry.primitive||e.textureSetId)){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;let t=this._dtxBuckets[e.geometryId];t||(t=fh(e.geometry,this._enableVertexWelding,this._enableIndexBucketing),this._dtxBuckets[e.geometryId]=t),e.buckets=t}else e.type=0,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.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId])}return e.numPrimitives=this._getNumPrimitives(e),this._meshesCfgsBeforeMeshCreation[e.id]=e,!0}_createMesh(e){const t=new lr(this,e.id,e.color,e.opacity,e.transform,e.textureSet);t.pickId=this.scene._renderer.getPickID(t);const s=t.pickId,n=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<n;s++)t+=e.buckets[s].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/3);case"points":switch(e.type){case 2:for(let s=0,n=e.buckets.length;s<n;s++)t+=e.buckets[s].positionsCompressed.length;break;case 1:t+=e.positions?e.positions.length:e.positionsCompressed.length;break;case 0:const s=e.geometry;t+=s.positions?s.positions.length:s.positionsCompressed.length}return Math.round(t);case"lines":case"line-strip":switch(e.type){case 2:for(let s=0,n=e.buckets.length;s<n;s++)t+=e.buckets[s].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/2)}return 0}_getDTXLayer(e){const t=e.origin,s=e.geometry?e.geometry.primitive:e.primitive,n=`.${s}.${Math.round(t[0])}.${Math.round(t[1])}.${Math.round(t[2])}`;let i=this._dtxLayers[n];if(i){if(i.canCreatePortion(e))return i;i.finalize(),delete this._dtxLayers[n],i=null}switch(s){case"triangles":case"solid":case"surface":i=new Ru(this,{layerIndex:0,origin:t});break;case"lines":i=new ac(this,{layerIndex:0,origin:t});break;default:return}return this._dtxLayers[n]=i,this.layerList.push(i),i}_getVBOBatchingLayer(e){const t=this,s=e.origin,n=e.positionsDecodeMatrix||e.positionsDecodeBoundary?this._createHashStringFromMatrix(e.positionsDecodeMatrix||e.positionsDecodeBoundary):"-",i=e.textureSetId||"-",r=`${Math.round(s[0])}.${Math.round(s[1])}.${Math.round(s[2])}.${e.primitive}.${n}.${i}`;let a=this._vboBatchingLayers[r];if(a)return a;let o=e.textureSet;for(;!a;){switch(e.primitive){case"triangles":case"solid":case"surface":a=new ma({model:t,textureSet:o,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:s,maxGeometryBatchSize:this._maxGeometryBatchSize,solid:"solid"===e.primitive,autoNormals:!0});break;case"lines":a=new _o({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:s,maxGeometryBatchSize:this._maxGeometryBatchSize});break;case"points":a=new Il({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:s,maxGeometryBatchSize:this._maxGeometryBatchSize})}const n=e.positionsCompressed?e.positionsCompressed.length:e.positions.length;("points"===e.primitive?a.canCreatePortion(n):a.canCreatePortion(n,e.indices.length))||(a.finalize(),delete this._vboBatchingLayers[r],a=null)}return this._vboBatchingLayers[r]=a,this.layerList.push(a),a}_createHashStringFromMatrix(e){const t=e.join("");let s=0;for(let e=0;e<t.length;e++){s=(s<<5)-s+t.charCodeAt(e),s|=0}return(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;s<n;s++){const n=e.meshIds[s];let i=this._meshes[n];if(!i){let t=this._meshesCfgsBeforeMeshCreation[n];if(!t){this.error(`Mesh with this ID not found: "${n}" - ignoring this mesh`);continue}i=this._createMesh(t),this._meshes[e.id]=i}i.parent?this.error(`Mesh with ID "${n}" already belongs to object with ID "${i.parent.id}" - ignoring this mesh`):t.push(i)}const s=new le(this,e.isObject,e.id,t,e.flags,!0);this._entityList.push(s),this._entities[e.id]=s,this.numEntities++}finalize(){if(!this.destroyed){for(let e=0,t=this.layerList.length;e<t;e++){this.layerList[e].finalize()}this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._dtxLayers={},this._vboInstancingLayers={},this._vboBatchingLayers={};for(let e=0,t=this._entityList.length;e<t;e++){this._entityList[e]._finalize()}for(let e=0,t=this._entityList.length;e<t;e++){this._entityList[e]._finalize2()}this.layerList.sort(((e,t)=>e.sortId<t.sortId?-1:e.sortId>t.sortId?1:0));for(let e=0,t=this.layerList.length;e<t;e++){this.layerList[e].layerIndex=e}this.glRedraw(),this.scene._aabbDirty=!0,this._viewMatrixDirty=!0,this._matrixDirty=!0,this._aabbDirty=!0,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.position=this._position}}stateSortCompare(e,t){}rebuildRenderFlags(){this.renderFlags.reset(),this._updateRenderFlagsVisibleLayers(),this.renderFlags.numLayers>0&&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;t<s;t++){const s=this.layerList[t];this._getActiveSectionPlanesForLayer(s)&&(e.visibleLayers[e.numVisibleLayers++]=t)}}_getActiveSectionPlanesForLayer(e){const t=this.renderFlags,s=this.scene._sectionPlanesState.sectionPlanes,n=s.length,i=e.layerIndex*n;if(n>0)for(let e=0;e<n;e++){s[e].active?(t.sectionPlanesActivePerLayer[i+e]=!0,t.sectioned=!0):t.sectionPlanesActivePerLayer[i+e]=!1}return!0}_updateRenderFlags(){if(0===this.numVisibleLayerPortions)return;if(this.numCulledLayerPortions===this.numPortions)return;const e=this.renderFlags;if(e.colorOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(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.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(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;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawColorOpaque(t,e)}}drawColorTransparent(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawColorTransparent(t,e)}}drawDepth(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawDepth(t,e)}}drawNormals(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawNormals(t,e)}}drawSilhouetteXRayed(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawSilhouetteXRayed(t,e)}}drawSilhouetteHighlighted(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawSilhouetteHighlighted(t,e)}}drawSilhouetteSelected(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawSilhouetteSelected(t,e)}}drawEdgesColorOpaque(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawEdgesColorOpaque(t,e)}}drawEdgesColorTransparent(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawEdgesColorTransparent(t,e)}}drawEdgesXRayed(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawEdgesXRayed(t,e)}}drawEdgesHighlighted(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawEdgesHighlighted(t,e)}}drawEdgesSelected(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawEdgesSelected(t,e)}}drawOcclusion(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawOcclusion(t,e)}}drawShadow(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawShadow(t,e)}}setPickMatrices(e,t){if(0===this._numVisibleLayerPortions)return;const s=this.renderFlags;for(let n=0,i=s.visibleLayers.length;n<i;n++){const i=s.visibleLayers[n],r=this.layerList[i];r.setPickMatrices&&r.setPickMatrices(e,t)}}drawPickMesh(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawPickMesh(t,e)}}drawPickDepths(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawPickDepths(t,e)}}drawPickNormals(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s];this.layerList[n].drawPickNormals(t,e)}}drawSnapInit(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s],i=this.layerList[n];i.drawSnapInit&&(e.snapPickOrigin=[0,0,0],e.snapPickCoordinateScale=[1,1,1],e.snapPickLayerNumber++,i.drawSnapInit(t,e),e.snapPickLayerParams[e.snapPickLayerNumber]={origin:e.snapPickOrigin.slice(),coordinateScale:e.snapPickCoordinateScale.slice()})}}drawSnap(e){if(0===this.numVisibleLayerPortions)return;const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s<n;s++){const n=t.visibleLayers[s],i=this.layerList[n];i.drawSnap&&(e.snapPickOrigin=[0,0,0],e.snapPickCoordinateScale=[1,1,1],e.snapPickLayerNumber++,i.drawSnap(t,e),e.snapPickLayerParams[e.snapPickLayerNumber]={origin:e.snapPickOrigin.slice(),coordinateScale:e.snapPickCoordinateScale.slice()})}}destroy(){for(let e in this._vboBatchingLayers)this._vboBatchingLayers.hasOwnProperty(e)&&this._vboBatchingLayers[e].destroy();this._vboBatchingLayers={};for(let e in this._vboInstancingLayers)this._vboInstancingLayers.hasOwnProperty(e)&&this._vboInstancingLayers[e].destroy();this._vboInstancingLayers={},this.scene.camera.off(this._onCameraViewMatrix),this.scene.off(this._onTick);for(let e=0,t=this.layerList.length;e<t;e++)this.layerList[e].destroy();this.layerList=[];for(let e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._destroy();this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this.scene._aabbDirty=!0,this._isModel&&this.scene._deregisterModel(this),0!==ur&&(ur--,0===ur&&cr._clear()),super.destroy()}}function fh(e,t,s){let n,i,r,a;if(t||s?[n,i,r]=zu({positionsCompressed:e.positionsCompressed,indices:e.indices,edgeIndices:e.edgeIndices}):(n=e.positionsCompressed,i=e.indices,r=e.edgeIndices),s){a=Ju({positionsCompressed:n,indices:i,edgeIndices:r},n.length/3>65536?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;e<t;e+=2)this._indices.push(e),this._indices.push(e+1)}this._sceneModel=new Ah(this,{isModel:!1}),this._sceneModel.createMesh({id:"linesMesh",primitive:"lines",positions:this._positions,indices:this._indices}),this._sceneModel.createEntity({meshIds:["linesMesh"],visible:t.visible,clippable:t.clippable,collidable:t.collidable}),this._sceneModel.finalize(),this.scene._lineSetCreated(this)}set visible(e){this._sceneModel.visible=e}get visible(){return this._sceneModel.visible}get positions(){return this._positions}get indices(){return this._indices}destroy(){super.destroy(),this.scene._lineSetDestroyed(this)}}const mh=d.vec3(),yh=d.vec3(),vh=d.vec3(),wh=d.vec3();class gh extends Q{constructor(e,t={}){super("BCFViewpoints",e,t),this.originatingSystem=t.originatingSystem||"xeokit.io",this.authoringTool=t.authoringTool||"xeokit.io"}getViewpoint(e={}){const t=this.viewer.scene,s=t.camera,n=t.realWorldOffset,i=!0===e.reverseClippingPlanes;let r={},a=d.normalizeVec3(d.subVec3(s.look,s.eye,d.vec3())),o=s.eye,l=s.up;s.yUp&&(a=bh(a),o=bh(o),l=bh(l));const c=Eh(d.addVec3(o,n));"ortho"===s.projection?r.orthogonal_camera={camera_view_point:c,camera_direction:Eh(a),camera_up_vector:Eh(l),view_to_world_scale:s.ortho.scale}:r.perspective_camera={camera_view_point:c,camera_direction:Eh(a),camera_up_vector:Eh(l),field_of_view:s.perspective.fov};const u=t.sectionPlanes;for(let e in u)if(u.hasOwnProperty(e)){let t=u[e];if(!t.active)continue;let a,o=t.pos;a=i?d.negateVec3(t.dir,d.vec3()):t.dir,s.yUp&&(o=bh(o),a=bh(a)),d.addVec3(o,n),o=Eh(o),a=Eh(a),r.clipping_planes||(r.clipping_planes=[]),r.clipping_planes.push({location:o,direction:a})}const h=t.lineSets;for(let e in h)if(h.hasOwnProperty(e)){const t=h[e];r.lines||(r.lines=[]);const s=t.positions,n=t.indices;for(let e=0,t=n.length/2;e<t;e++){const t=n[2*e],i=n[2*e+1];r.lines.push({start_point:{x:s[3*t+0],y:s[3*t+1],z:s[3*t+2]},end_point:{x:s[3*i+0],y:s[3*i+1],z:s[3*i+2]}})}}const p=t.bitmaps;for(let e in p)if(p.hasOwnProperty(e)){let t=p[e],i=t.pos,a=t.normal,o=t.up;s.yUp&&(i=bh(i),a=bh(a),o=bh(o)),d.addVec3(i,n),r.bitmaps||(r.bitmaps=[]),r.bitmaps.push({bitmap_type:t.type,bitmap_data:t.imageData,location:Eh(i),normal:Eh(a),up:Eh(o),height:t.height})}r.components={visibility:{view_setup_hints:{spaces_visible:!!e.spacesVisible,space_boundaries_visible:!!e.spaceBoundariesVisible,openings_visible:!!e.openingsVisible,spaces_translucent:!!e.spaces_translucent,space_boundaries_translucent:!!e.space_boundaries_translucent,openings_translucent:!!e.openings_translucent}}};const A=new Set(t.opacityObjectIds),f=new Set(t.xrayedObjectIds),I=new Set(t.colorizedObjectIds),m=Object.values(t.objects).filter((e=>A.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.length<E.length?(r.components.visibility.exceptions=this._createBCFComponents(g),r.components.visibility.default_visibility=!1):(r.components.visibility.exceptions=this._createBCFComponents(E),r.components.visibility.default_visibility=!0),r.components.selection=this._createBCFComponents(T),r.components.translucency=this._createBCFComponents(t.xrayedObjectIds),!1!==e.snapshot&&(r.snapshot={snapshot_type:"png",snapshot_data:this.viewer.getSnapshot({format:"png"})}),r}_createBCFComponents(e){const t=this.viewer.scene,s=[];for(let n=0,i=e.length;n<i;n++){const i=e[n],r=t.objects[i];if(r){const e={ifc_guid:r.originalSystemId,originating_system:this.originatingSystem};r.originalSystemId!==i&&(e.authoring_tool_id=i),s.push(e)}}return s}setViewpoint(e,t={}){if(!e)return;const s=this.viewer,n=s.scene,i=n.camera,r=!1!==t.rayCast,a=!1!==t.immediate,o=!1!==t.reset,l=n.realWorldOffset,c=!0===t.reverseClippingPlanes;if(n.clearSectionPlanes(),e.clipping_planes&&e.clipping_planes.length>0&&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<A;p+=4)i[h]=o+Math.floor((1+n[p+0]/n[p+3])*c/2),i[h+1]=a+Math.floor((1-n[p+1]/n[p+3])*u/2),h+=2;if(this._originDot.setPos(i[0],i[1]),this._targetDot.setPos(i[6],i[7]),this._lengthWire.setStartAndEnd(i[0],i[1],i[6],i[7]),this._xAxisWire.setStartAndEnd(i[0],i[1],i[2],i[3]),this._yAxisWire.setStartAndEnd(i[2],i[3],i[4],i[5]),this._zAxisWire.setStartAndEnd(i[4],i[5],i[6],i[7]),this.labelsVisible){if(this._lengthLabel.setPosOnWire(i[0],i[1],i[6],i[7]),this.labelsOnWires)this._xAxisLabel.setPosOnWire(i[0],i[1],i[2],i[3]),this._yAxisLabel.setPosOnWire(i[2],i[3],i[4],i[5]),this._zAxisLabel.setPosOnWire(i[4],i[5],i[6],i[7]);else{const e=35;let t=e;this._xAxisLabel.setPosOnWire(i[0],i[1]+t,i[6],i[7]+t),t+=e,this._yAxisLabel.setPosOnWire(i[0],i[1]+t,i[6],i[7]+t),t+=e,this._zAxisLabel.setPosOnWire(i[0],i[1]+t,i[6],i[7]+t)}const e=this._approximate?" ~ ":" = ";this._length=Math.abs(d.lenVec3(d.subVec3(this._targetWorld,this._originWorld,Ph))),this._lengthLabel.setText(e+(this._length*f).toFixed(2)+m);const t=Math.abs(Ch(i[0],i[1],i[2],i[3])),s=Math.abs(Ch(i[2],i[3],i[4],i[5])),n=Math.abs(Ch(i[4],i[5],i[6],i[7])),r=this.plugin.labelMinAxisLength;this.labelsOnWires?(this._xAxisLabelCulled=t<r,this._yAxisLabelCulled=s<r,this._zAxisLabelCulled=n<r):(this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1),this._xAxisLabelCulled?this._xAxisLabel.setCulled(!0):(this._xAxisLabel.setText(e+Math.abs((this._targetWorld[0]-this._originWorld[0])*f).toFixed(2)+m),this._xAxisLabel.setCulled(!this.axisVisible)),this._yAxisLabelCulled?this._yAxisLabel.setCulled(!0):(this._yAxisLabel.setText(e+Math.abs((this._targetWorld[1]-this._originWorld[1])*f).toFixed(2)+m),this._yAxisLabel.setCulled(!this.axisVisible)),this._zAxisLabelCulled?this._zAxisLabel.setCulled(!0):(this._zAxisLabel.setText(e+Math.abs((this._targetWorld[2]-this._originWorld[2])*f).toFixed(2)+m),this._zAxisLabel.setCulled(!this.axisVisible))}else this._lengthLabel.setCulled(!0),this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0);this._originDot.setVisible(this._visible&&this._originVisible),this._targetDot.setVisible(this._visible&&this._targetVisible),this._xAxisWire.setVisible(this.axisVisible&&this.xAxisVisible),this._yAxisWire.setVisible(this.axisVisible&&this.yAxisVisible),this._zAxisWire.setVisible(this.axisVisible&&this.zAxisVisible),this._lengthWire.setVisible(this.wireVisible),this._lengthLabel.setCulled(!this.wireVisible),this._cpDirty=!1}}_isSliced(e){const t=this.scene._sectionPlanesState.sectionPlanes;for(let s=0,n=t.length;s<n;s++){const n=t[s];if(d.planeClipsPositions3(n.pos,n.dir,e,4))return!0}return!1}set approximate(e){e=!1!==e,this._approximate!==e&&(this._approximate=e,this._cpDirty=!0,this._needUpdate(0))}get approximate(){return this._approximate}get origin(){return this._originMarker}get target(){return this._targetMarker}get length(){this._update();const e=this.plugin.viewer.scene.metrics.scale;return this._length*e}get color(){return this._color}set color(e){this._color=e,this._originDot.setFillColor(e),this._targetDot.setFillColor(e),this._lengthWire.setColor(e),this._lengthLabel.setFillColor(e)}set visible(e){e=void 0!==e?Boolean(e):this.plugin.defaultVisible,this._visible=e,this._originDot.setVisible(this._visible&&this._originVisible),this._targetDot.setVisible(this._visible&&this._targetVisible),this._lengthWire.setVisible(this._visible&&this._wireVisible),this._lengthLabel.setVisible(this._visible&&this._wireVisible);const t=this._visible&&this._axisVisible&&this._xAxisVisible,s=this._visible&&this._axisVisible&&this._yAxisVisible,n=this._visible&&this._axisVisible&&this._zAxisVisible;this._xAxisWire.setVisible(t),this._yAxisWire.setVisible(s),this._zAxisWire.setVisible(n),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled),this._yAxisLabel.setVisible(s&&!this._yAxisLabelCulled),this._zAxisLabel.setVisible(n&&!this._zAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}get visible(){return this._visible}set originVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultOriginVisible,this._originVisible=e,this._originDot.setVisible(this._visible&&this._originVisible)}get originVisible(){return this._originVisible}set targetVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultTargetVisible,this._targetVisible=e,this._targetDot.setVisible(this._visible&&this._targetVisible)}get targetVisible(){return this._targetVisible}set axisEnabled(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._axisEnabled=e;var t=this._visible&&this._axisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t&&this._xAxisVisible),this._yAxisWire.setVisible(t&&this._yAxisVisible),this._zAxisWire.setVisible(t&&this._zAxisVisible),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled&&this._xAxisVisible),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled&&this._xAxisVisible),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled&&this._xAxisVisible),this._cpDirty=!0,this._needUpdate()}get axisEnabled(){return this._axisEnabled}set axisVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._axisVisible=e;var t=this._visible&&this._axisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t&&this._xAxisVisible),this._yAxisWire.setVisible(t&&this._yAxisVisible),this._zAxisWire.setVisible(t&&this._zAxisVisible),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled&&this._xAxisVisible),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled&&this._yAxisVisible),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled&&this._zAxisVisible),this._cpDirty=!0,this._needUpdate()}get axisVisible(){return this._axisVisible}set xAxisVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._xAxisVisible=e;const t=this._visible&&this._axisVisible&&this._xAxisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}get xAxisVisible(){return this._xAxisVisible}set yAxisVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._yAxisVisible=e;const t=this._visible&&this._axisVisible&&this._yAxisVisible&&this._axisEnabled;this._yAxisWire.setVisible(t),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}get yAxisVisible(){return this._yAxisVisible}set zAxisVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._zAxisVisible=e;const t=this._visible&&this._axisVisible&&this._zAxisVisible&&this._axisEnabled;this._zAxisWire.setVisible(t),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}get zAxisVisible(){return this._zAxisVisible}set wireVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultWireVisible,this._wireVisible=e;var t=this._visible&&this._wireVisible;this._lengthLabel.setVisible(t),this._lengthWire.setVisible(t)}get wireVisible(){return this._wireVisible}set labelsVisible(e){e=void 0!==e?Boolean(e):this.plugin.defaultLabelsVisible,this._labelsVisible=e;var t=this._visible&&this._labelsVisible;this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled&&this._clickable&&this._axisEnabled),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled&&this._clickable&&this._axisEnabled),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled&&this._clickable&&this._axisEnabled),this._lengthLabel.setVisible(t),this._cpDirty=!0,this._needUpdate()}get labelsVisible(){return this._labelsVisible}set labelsOnWires(e){e=void 0!==e?Boolean(e):this.plugin.defaultLabelsOnWires,this._labelsOnWires=e}get labelsOnWires(){return this._labelsOnWires}setHighlighted(e){this._originDot.setHighlighted(e),this._targetDot.setHighlighted(e),this._xAxisWire.setHighlighted(e),this._yAxisWire.setHighlighted(e),this._zAxisWire.setHighlighted(e),this._xAxisLabel.setHighlighted(e),this._yAxisLabel.setHighlighted(e),this._zAxisLabel.setHighlighted(e),this._lengthWire.setHighlighted(e),this._lengthLabel.setHighlighted(e)}set clickable(e){e=!!e,this._clickable=e,this._originDot.setClickable(this._clickable),this._targetDot.setClickable(this._clickable),this._xAxisWire.setClickable(this._clickable),this._yAxisWire.setClickable(this._clickable),this._zAxisWire.setClickable(this._clickable),this._lengthWire.setClickable(this._clickable),this._xAxisLabel.setClickable(this._clickable),this._yAxisLabel.setClickable(this._clickable),this._zAxisLabel.setClickable(this._clickable),this._lengthLabel.setClickable(this._clickable)}get clickable(){return this._clickable}destroy(){const e=this.plugin.viewer.scene,t=e.metrics;this._onViewMatrix&&e.camera.off(this._onViewMatrix),this._onProjMatrix&&e.camera.off(this._onProjMatrix),this._onCanvasBoundary&&e.canvas.off(this._onCanvasBoundary),this._onMetricsUnits&&t.off(this._onMetricsUnits),this._onMetricsScale&&t.off(this._onMetricsScale),this._onMetricsOrigin&&t.off(this._onMetricsOrigin),this._onSectionPlaneUpdated&&e.off(this._onSectionPlaneUpdated),this._originDot.destroy(),this._targetDot.destroy(),this._xAxisWire.destroy(),this._yAxisWire.destroy(),this._zAxisWire.destroy(),this._lengthLabel.destroy(),this._xAxisLabel.destroy(),this._yAxisLabel.destroy(),this._zAxisLabel.destroy(),this._lengthWire.destroy(),super.destroy()}}class Rh extends x{get active(){}set snapping(e){}get snapping(){return!0}activate(){}deactivate(){}reset(){}destroy(){}}class Bh extends Rh{constructor(e,t={}){super(e.viewer.scene),this.pointerLens=t.pointerLens,this._active=!1,this._currentDistanceMeasurement=null,this._currentDistanceMeasurementInitState={wireVisible:null,axisVisible:null,xAxisVisible:null,yaxisVisible:null,zAxisVisible:null,targetVisible:null},this._initMarkerDiv(),this._onCameraControlHoverSnapOrSurface=null,this._onCameraControlHoverSnapOrSurfaceOff=null,this._onMouseDown=null,this._onMouseUp=null,this._onCanvasTouchStart=null,this._onCanvasTouchEnd=null,this._snapping=!1!==t.snapping,this._mouseState=0,this._attachPlugin(e,t)}_initMarkerDiv(){const e=document.createElement("div");e.setAttribute("id","myMarkerDiv");const 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}_destroyMarkerDiv(){if(this._markerDiv){const e=document.getElementById("myMarkerDiv");e.parentNode.removeChild(e),this._markerDiv=null}}_attachPlugin(e,t={}){this.distanceMeasurementsPlugin=e,this.plugin=e}get active(){return this._active}set snapping(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}get snapping(){return this._snapping}activate(){if(this._active)return;this._markerDiv||this._initMarkerDiv(),this.fire("activated",!0);const e=this.distanceMeasurementsPlugin,t=this.scene,s=e.viewer.cameraControl,n=t.canvas.canvas;t.input;let i=!1;const r=d.vec3(),a=d.vec2();let o,l;let c=null;this._mouseState=0,this._onCameraControlHoverSnapOrSurface=s.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(e=>{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.clientX<o-20||t.clientY>l+20||t.clientY<l-20||(this._currentDistanceMeasurement?i?(this._currentDistanceMeasurement.target.entity=c,c=null,this._currentDistanceMeasurement.clickable=!0,this.distanceMeasurementsPlugin.fire("measurementEnd",this._currentDistanceMeasurement),this._currentDistanceMeasurement=null):(this._currentDistanceMeasurement.destroy(),this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement=null,c=null):i&&(this._currentDistanceMeasurement=e.createMeasurement({id:d.createUUID(),origin:{worldPos:r.slice()},target:{worldPos:r.slice()},approximate:!0}),this._currentDistanceMeasurementInitState.axisVisible=this._currentDistanceMeasurement.axisVisible&&this.distanceMeasurementsPlugin.defaultAxisVisible,this._currentDistanceMeasurementInitState.xAxisVisible=this._currentDistanceMeasurement.xAxisVisible&&this.distanceMeasurementsPlugin.defaultXAxisVisible,this._currentDistanceMeasurementInitState.yAxisVisible=this._currentDistanceMeasurement.yAxisVisible&&this.distanceMeasurementsPlugin.defaultYAxisVisible,this._currentDistanceMeasurementInitState.zAxisVisible=this._currentDistanceMeasurement.zAxisVisible&&this.distanceMeasurementsPlugin.defaultZAxisVisible,this._currentDistanceMeasurementInitState.wireVisible=this._currentDistanceMeasurement.wireVisible,this._currentDistanceMeasurementInitState.targetVisible=this._currentDistanceMeasurement.targetVisible,this._currentDistanceMeasurement.clickable=!1,this._currentDistanceMeasurement.origin.entity=c,c=null,this.fire("measurementStart",this._currentDistanceMeasurement))))}),this._onCameraControlHoverSnapOrSurfaceOff=s.on(this._snapping?"hoverSnapOrSurfaceOff":"hoverOff",(e=>{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;t++)this.destroyMeasurement(e[t])}destroy(){this.clear(),super.destroy()}}class Sh extends Q{constructor(e,t={}){super("FastNav",e),this._hideColorTexture=!1!==t.hideColorTexture,this._hidePBR=!1!==t.hidePBR,this._hideSAO=!1!==t.hideSAO,this._hideEdges=!1!==t.hideEdges,this._hideTransparentObjects=!!t.hideTransparentObjects,this._scaleCanvasResolution=!!t.scaleCanvasResolution,this._scaleCanvasResolutionFactor=t.scaleCanvasResolutionFactor||.6,this._delayBeforeRestore=!1!==t.delayBeforeRestore,this._delayBeforeRestoreSeconds=t.delayBeforeRestoreSeconds||.5;let s=1e3*this._delayBeforeRestoreSeconds,n=!1;const i=()=>{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<o.length;l++)t[l]=o.charCodeAt(l);B.scheduleTask((function(){s(e)}))}catch(e){B.scheduleTask((function(){n(e)}))}}else{const i=function(e){var t=e.lastIndexOf("/");return 0!==t?e.substring(0,t+1):""}(e),r=i+t,a=new XMLHttpRequest;a.open("GET",r,!0),a.responseType="arraybuffer",a.onreadystatechange=function(){4===a.readyState&&(200===a.status?s(a.response):n("loadArrayBuffer error : "+a.response))},a.send(null)}}(e,t,(e=>{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&&e<t;e++){n=n[s[e]]}return n}function Mh(e,t=[]){return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,s){return"{{"===e?"{":"}}"===e?"}":t[s]}))}class Fh extends x{constructor(e,t={}){super(e,t),this.t=t.t}set t(e){e=e||0,this._t=e<0?0:e>1?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;s<n;s++)t=e[s],this.addFrame(t.t||0,t.eye,t.look,t.up)}loadFrame(e){const t=this.scene.camera;e=(e/=this._frames[this._frames.length-1].t-this._frames[0].t)<0?0:e>1?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<r;e++){var i=d.lenVec3(d.subVec3(this._frames[e].eye,this._frames[e-1].eye,t));n[e]=i,s+=i}for(let t=1,i=this._frames.length;t<i;t++){const i=n[t]/s*e;this._frames[t].t=this._frames[t-1].t+i}}clearFrames(){this._frames=[],this._eyeCurve.points=[],this._lookCurve.points=[],this._upCurve.points=[]}}const jh=d.vec3(),Vh=d.vec3(),kh=d.vec3(),Qh=d.vec3(),Wh=d.vec3();class zh extends x{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=d.vec3(),this._eye1=d.vec3(),this._up1=d.vec3(),this._look2=d.vec3(),this._eye2=d.vec3(),this._up2=d.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((g.isNumeric(n)||g.isString(n))&&(c=n,n=this.scene.components[c],!n))return this.error("Component not found: "+g.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]<r[0]||r[4]<r[1]||r[5]<r[2])return;if(r[3]===r[0]&&r[4]===r[1]&&r[5]===r[2])return;r=r.slice();const t=d.getAABB3Center(r);this._look2=u||t;const s=d.subVec3(this._eye1,this._look1,jh),n=d.normalizeVec3(s),i=u?d.getAABB3DiagPoint(r,u):d.getAABB3Diag(r),a=e.fitFOV||this._fitFOV,o=Math.abs(i/Math.tan(a*d.DEGTORAD));this._orthoScale2=1.1*i,this._eye2[0]=this._look2[0]+n[0]*o,this._eye2[1]=this._look2[1]+n[1]*o,this._eye2[2]=this._look2[2]+n[2]*o,this._up2[0]=this._up1[0],this._up2[1]=this._up1[1],this._up2[2]=this._up1[2],this._flyingEyeLookUp=!0}else(a||o||l)&&(this._flyingEyeLookUp=!!a&&!!o&&!!l,this._flyingEye=!!a&&!o,this._flyingLook=!!o&&!a,a&&(this._eye2[0]=a[0],this._eye2[1]=a[1],this._eye2[2]=a[2]),o&&(this._look2[0]=o[0],this._look2[1]=o[1],this._look2[2]=o[2]),l&&(this._up2[0]=l[0],this._up2[1]=l[1],this._up2[2]=l[2]));i?("ortho"===e.projection&&"ortho"!==n.projection&&(this._projection2="ortho",this._projMatrix1=n.projMatrix.slice(),this._projMatrix2=n.ortho.matrix.slice(),n.projection="customProjection"),"perspective"===e.projection&&"perspective"!==n.projection&&(this._projection2="perspective",this._projMatrix1=n.projMatrix.slice(),this._projMatrix2=n.perspective.matrix.slice(),n.projection="customProjection")):this._projection2=null,this.fire("started",e,!0),this._time1=Date.now(),this._time2=this._time1+(e.duration?1e3*e.duration:this._duration),this._flying=!0,B.scheduleTask(this._update,this)}jumpTo(e){this._jumpTo(e)}_jumpTo(e){this._flying&&this.stop();const t=this.scene.camera;var s,n,i,r,a;if(e.aabb)s=e.aabb;else if(6===e.length)s=e;else if(e.eye||e.look||e.up)i=e.eye,r=e.look,a=e.up;else{let t=e;if((g.isNumeric(t)||g.isString(t))&&(n=t,t=this.scene.components[n],!t))return void this.error("Component not found: "+g.inQuotes(n));s=t.aabb||this.scene.aabb}const o=e.poi;if(s){if(s[3]<=s[0]||s[4]<=s[1]||s[5]<=s[2])return;var l=o?d.getAABB3DiagPoint(s,o):d.getAABB3Diag(s);let n;r=o||d.getAABB3Center(s,r),this._trail?d.subVec3(t.look,r,Wh):d.subVec3(t.eye,t.look,Wh),d.normalizeVec3(Wh);n=(void 0!==e.fit?e.fit:this._fit)?Math.abs(l/Math.tan((e.fitFOV||this._fitFOV)*d.DEGTORAD)):d.lenVec3(d.subVec3(t.eye,t.look,jh)),d.mulVec3Scalar(Wh,n),t.eye=d.addVec3(r,Wh,jh),t.look=r,this.scene.camera.ortho.scale=1.1*l}else(i||r||a)&&(i&&(t.eye=i),r&&(t.look=r),a&&(t.up=a));e.projection&&(t.projection=e.projection)}_update(){if(!this._flying)return;let e=(Date.now()-this._time1)/(this._time2-this._time1);const t=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<e.length;r++){const a=new Image;a.onload=function(){let e=a;const o=r;return function(){if(!n&&(e=ep(e),t._images[o]=e,i++,6===i)){let e=t._state.texture;e||(e=new Ui({gl:s,target:s.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}}(),a.onerror=function(){n=!0},a.src=e[r]}}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),m.memory.textures--,this._state.destroy()}}class ip extends np{get type(){return"ReflectionMap"}constructor(e,t={}){super(e,t),this.scene._lightsState.addReflectionMap(this._state),this.scene._reflectionMapCreated(this)}destroy(){super.destroy(),this.scene._reflectionMapDestroyed(this)}}class rp extends np{get type(){return"LightMap"}constructor(e,t={}){super(e,t),this.scene._lightMapCreated(this)}destroy(){super.destroy(),this.scene._lightMapDestroyed(this)}}class ap extends he{constructor(e,t={}){super(e,{entity:t.entity,occludable:t.occludable,worldPos:t.worldPos}),this._occluded=!1,this._visible=!0,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,{src:t.src}),this._geometry=new Vt(this,{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]}),this._mesh=new pi(this,{geometry:this._geometry,material:new Kt(this,{ambient:[.9,.3,.9],shininess:30,diffuseMap:this._texture,backfaces:!0}),scale:[1,1,1],position:t.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),this.visible=!0,this.collidable=t.collidable,this.clippable=t.clippable,this.pickable=t.pickable,this.opacity=t.opacity,this.size=t.size,t.image?this.image=t.image:this.src=t.src}_setVisible(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,super._setVisible(e)}set visible(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}get visible(){return this._visible}set image(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)}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 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;e<t;e++){const t=d[p[e].id];if(t){if(n&&(this.objectsVisible[e]=t.visible),i&&(this.objectsEdges[e]=t.edges),r&&(this.objectsXrayed[e]=t.xrayed),a&&(this.objectsHighlighted[e]=t.highlighted),o&&(this.objectsSelected[e]=t.selected),l&&(this.objectsClippable[e]=t.clippable),c&&(this.objectsPickable[e]=t.pickable),u){const s=t.colorize;this.objectsColorize[3*e+0]=s[0],this.objectsColorize[3*e+1]=s[1],this.objectsColorize[3*e+2]=s[2]}h&&(this.objectsOpacity[e]=t.opacity),this.numObjects++}}}restoreObjects(e,t){const s=this._mask,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;e<t;e++){const t=d[p[e].id];t&&(n&&(t.visible=this.objectsVisible[e]),i&&(t.edges=this.objectsEdges[e]),r&&(t.xrayed=this.objectsXrayed[e]),a&&(t.highlighted=this.objectsHighlighted[e]),o&&(t.selected=this.objectsSelected[e]),l&&(t.clippable=this.objectsClippable[e]),c&&(t.pickable=this.objectsPickable[e]),u&&(lp[0]=this.objectsColorize[3*e+0],lp[1]=this.objectsColorize[3*e+1],lp[2]=this.objectsColorize[3*e+2],t.colorize=lp),h&&(t.opacity=this.objectsOpacity[e]))}}}const up=d.vec3();class hp{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?g.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]?(up[0]=this.objectsColorize[3*h+0],up[1]=this.objectsColorize[3*h+1],up[2]=this.objectsColorize[3*h+2],t.colorize=up):t.colorize=null),u&&(t.opacity=this.objectsOpacity[h]),h++}}}class pp extends Fh{constructor(e,t={}){super(e,t),this.v0=t.v0,this.v1=t.v1,this.v2=t.v2,this.v3=t.v3,this.t=t.t}set v0(e){this._v0=e||d.vec3([0,0,0])}get v0(){return this._v0}set v1(e){this._v1=e||d.vec3([0,0,0])}get v1(){return this._v1}set v2(e){this._v2=e||d.vec3([0,0,0])}get v2(){return this._v2}set v3(e){this.fire("v3",this._v3=e||d.vec3([0,0,0]))}get v3(){return this._v3}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=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;s<n;s++)(t=this._curves[s]).off(this._dirtySubs[s]),t.off(this._destroyedSubs[s]);this._curves=[],this._dirtySubs=[],this._destroyedSubs=[];var i=this;function r(){i._dirty=!0}function a(){var e=this.id;for(s=0,n=i._curves.length;s<n;s++)if(i._curves[s].id===e)return i._curves=i._curves.slice(s,s+1),i._dirtySubs=i._dirtySubs.slice(s,s+1),i._destroyedSubs=i._destroyedSubs.slice(s,s+1),void(i._dirty=!0)}for(s=0,n=e.length;s<n;s++){if(t=e[s],g.isNumeric(t)||g.isString(t)){var o=t;if(!(t=this.scene.components[o])){this.error("Component not found: "+_inQuotes(o));continue}}var l=t.type;"xeokit.SplineCurve"===l||"xeokit.Path"===l||"xeokit.CubicBezierCurve"===l||"xeokit.QuadraticBezierCurve"===l?(this._curves.push(t),this._dirtySubs.push(t.on("dirty",r)),this._destroyedSubs.push(t.once("destroyed",a))):this.error("Component "+_inQuotes(t.id)+" is not a xeokit.SplineCurve, xeokit.Path or xeokit.QuadraticBezierCurve")}this._dirty=!0}get curves(){return this._curves}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)}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<n.length;){if(n[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;e<n;e++)s+=this._curves[e].length,t.push(s);return this._cachedLengths=t,this._dirty=!1,t}_getJSON(){for(var e=[],t=0,s=this._curves.length;t<s;t++)e.push(this._curves[t].id);return{curves:e,t:this._t}}destroy(){var e,t,s;for(super.destroy(),e=0,t=this._curves.length;e<t;e++)(s=this._curves[e]).off(this._dirtySubs[e]),s.off(this._destroyedSubs[e])}}class Ap extends Fh{constructor(e,t={}){super(e,t),this.v0=t.v0,this.v1=t.v1,this.v2=t.v2,this.t=t.t}set v0(e){this._v0=e||d.vec3([0,0,0])}get v0(){return this._v0}set v1(e){this._v1=e||d.vec3([0,0,0])}get v1(){return this._v1}set v2(e){this._v2=e||d.vec3([0,0,0])}get v2(){return this._v2}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=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)<s}if("perspective"===i.projection){i.ortho.scale=i.ortho.scale-s;const n=this._unproject(t,Tp),r=d.subVec3(n,i.eye,Dp),a=d.mulVec3Scalar(d.normalizeVec3(r),-s,[]);if(i.eye=[i.eye[0]-a[0],i.eye[1]-a[1],i.eye[2]-a[2]],i.look=[i.look[0]-a[0],i.look[1]-a[1],i.look[2]-a[2]],e){const t=d.subVec3(e,i.eye,wp),s=d.lenVec3(t),n=d.mulVec3Scalar(d.normalizeVec3(d.subVec3(i.look,i.eye,gp)),s);i.look=[i.eye[0]+n[0],i.eye[1]+n[1],i.eye[2]+n[2]]}}else if("ortho"===i.projection){const e=this._unproject(t,Tp);i.ortho.scale=i.ortho.scale-s,i.ortho._update();const n=this._unproject(t,bp),r=d.subVec3(n,e,Dp),a=d.mulVec3Scalar(d.normalizeVec3(d.subVec3(i.look,i.eye,wp)),-s,gp),o=d.addVec3(r,a,Ep);i.eye=[i.eye[0]-o[0],i.eye[1]-o[1],i.eye[2]-o[2]],i.look=[i.look[0]-o[0],i.look[1]-o[1],i.look[2]-o[2]]}return n}_unproject(e,t){const s=this._scene.camera,n=s.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);return s.project.unproject(e,o,yp,vp,t),t}destroy(){}}const Cp=d.vec3(),_p=d.vec3(),Rp=d.vec3(),Bp=d.vec4(),Op=d.vec4(),Sp=d.vec4();class Np{constructor(e,t){this._scene=e,this._configs=t,this._pivotWorldPos=d.vec3(),this._cameraOffset=d.vec3(),this._azimuth=0,this._polar=0,this._radius=0,this._pivotPosSet=!1,this._pivoting=!1,this._shown=!1,this._pivotSphereEnabled=!1,this._pivotSphere=null,this._pivotSphereSize=1,this._pivotSphereGeometry=null,this._pivotSphereMaterial=null,this._rtcCenter=d.vec3(),this._rtcPos=d.vec3(),this._pivotViewPos=d.vec4(),this._pivotProjPos=d.vec4(),this._pivotCanvasPos=d.vec2(),this._cameraDirty=!0,this._onViewMatrix=this._scene.camera.on("viewMatrix",(()=>{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<w&&(r=w);const a=Math.max(-1,Math.min(1,40*-e.deltaY));if(0===a)return;const o=a/Math.abs(a);i.dollyDelta+=-o*r*s.mouseWheelDollyRate,I&&(n.followPointerDirty=!0,I=!1)},{passive:!0})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("keydown",this._documentKeyDownHandler),document.removeEventListener("keyup",this._documentKeyUpHandler),e.removeEventListener("mousedown",this._mouseDownHandler),document.removeEventListener("mousemove",this._documentMouseMoveHandler),e.removeEventListener("mousemove",this._canvasMouseMoveHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._mouseUpHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("wheel",this._mouseWheelHandler)}}const Fp=d.vec3(),Hp=d.vec3(),Up=d.vec3(),Gp=d.vec3(),jp=d.vec3(),Vp={eye:d.vec3(),look:d.vec3(),up:d.vec3()};class kp{constructor(e,t,s,n){this._scene=e;const i=t.cameraControl,r=e.camera;this._onSceneKeyDown=e.input.on("keydown",(()=>{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<s.dollyMinSpeed&&(u=s.dollyMinSpeed)}const p=i.dollyDelta*u;if(0===i.rotateDeltaY&&0===i.rotateDeltaX||(!s.firstPerson&&s.followPointer&&o.getPivoting()?(o.continuePivot(i.rotateDeltaY,i.rotateDeltaX),o.showPivot()):(0!==i.rotateDeltaX&&(s.firstPerson?r.pitch(-i.rotateDeltaX):r.orbitPitch(i.rotateDeltaX)),0!==i.rotateDeltaY&&(s.firstPerson?r.yaw(i.rotateDeltaY):r.orbitYaw(i.rotateDeltaY))),i.rotateDeltaX*=s.rotationInertia,i.rotateDeltaY*=s.rotationInertia,t="grabbing"),Math.abs(i.panDeltaX)<.001&&(i.panDeltaX=0),Math.abs(i.panDeltaY)<.001&&(i.panDeltaY=0),Math.abs(i.panDeltaZ)<.001&&(i.panDeltaZ=0),0!==i.panDeltaX||0!==i.panDeltaY||0!==i.panDeltaZ){const e=d.vec3();let n,a;if(e[0]=i.panDeltaX,e[1]=i.panDeltaY,e[2]=i.panDeltaZ,s.constrainVertical){r.xUp?(n=r.eye[0],a=r.look[0]):r.yUp?(n=r.eye[1],a=r.look[1]):r.zUp&&(n=r.eye[2],a=r.look[2]),r.pan(e);const t=r.eye,s=r.look;r.xUp?(t[0]=n,s[0]=a):r.yUp?(t[1]=n,s[1]=a):r.zUp&&(t[2]=n,s[2]=a),r.eye=t,r.look=s}else r.pan(e);t="grabbing"}if(i.panDeltaX*=s.panInertia,i.panDeltaY*=s.panInertia,i.panDeltaZ*=s.panInertia,0!==p){if(t=p<0?"zoom-in":"zoom-out",s.firstPerson){let e,t;if(s.constrainVertical&&(r.xUp?(e=r.eye[0],t=r.look[0]):r.yUp?(e=r.eye[1],t=r.look[1]):r.zUp&&(e=r.eye[2],t=r.look[2])),s.followPointer){l.dollyToCanvasPos(h,n.pointerCanvasPos,-p)&&(n.followPointerDirty=!0)}else r.pan([0,0,p]),r.ortho.scale=r.ortho.scale-p;if(s.constrainVertical){const s=r.eye,n=r.look;r.xUp?(s[0]=e,n[0]=t):r.yUp?(s[1]=e,n[1]=t):r.zUp&&(s[2]=e,n[2]=t),r.eye=s,r.look=n}}else if(s.planView)if(s.followPointer){l.dollyToCanvasPos(h,n.pointerCanvasPos,-p)&&(n.followPointerDirty=!0)}else r.ortho.scale=r.ortho.scale+p,r.zoom(p);else if(s.followPointer){l.dollyToCanvasPos(h,n.pointerCanvasPos,-p)&&(n.followPointerDirty=!0)}else r.ortho.scale=r.ortho.scale+p,r.zoom(p);i.dollyDelta*=s.dollyInertia}a.fireEvents(),document.body.style.cursor=t}))}destroy(){this._scene.off(this._onTick)}}class Yp{constructor(e,t,s,n,i){this._scene=e;const r=this._scene.canvas.canvas;r.addEventListener("mouseenter",this._mouseEnterHandler=()=>{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<i.length;)h.push(d.vec2());for(let e=0,t=i.length;e<t;++e)qp(i[e],h[e]);A=i.length}),p.addEventListener("touchend",this._canvasTouchEndHandler=()=>{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<A;++e)qp(I[e],h[e])}})}reset(){}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler),e.removeEventListener("touchmove",this._canvasTouchMoveHandler),this._scene.off(this._onTick)}}const Zp=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 $p{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.cameraControl;let o;const l=[],c=new Float32Array(2);let u=-1,h=-1;const p=this._scene.canvas.canvas,A=s=>{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<i.length;)l.push(new Float32Array(2));for(let e=0,t=i.length;e<t;++e)Zp(i[e],l[e]);l.length=i.length},{passive:!0}),p.addEventListener("touchend",this._canvasTouchEndHandler=e=>{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<t;++e)l[e][0]=i[e].pageX,l[e][1]=i[e].pageY},{passive:!0})}reset(){}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler)}}class ed extends x{constructor(e,t={}){super(e,t),this.PAN_LEFT=0,this.PAN_RIGHT=1,this.PAN_UP=2,this.PAN_DOWN=3,this.PAN_FORWARDS=4,this.PAN_BACKWARDS=5,this.ROTATE_X_POS=6,this.ROTATE_X_NEG=7,this.ROTATE_Y_POS=8,this.ROTATE_Y_NEG=9,this.DOLLY_FORWARDS=10,this.DOLLY_BACKWARDS=11,this.AXIS_VIEW_RIGHT=12,this.AXIS_VIEW_BACK=13,this.AXIS_VIEW_LEFT=14,this.AXIS_VIEW_FRONT=15,this.AXIS_VIEW_TOP=16,this.AXIS_VIEW_BOTTOM=17,this._keyMap={},this.scene.canvas.canvas.oncontextmenu=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;e<n;e++){if(t[s[e]])return!0}return!1}set pivotElement(e){this._controllers.pivotController.setPivotElement(e)}set active(e){e=!1!==e,this._configs.active=e,this._handlers[1]._active=e,this._handlers[5]._active=e}get active(){return this._configs.active}set snapToVertex(e){this._configs.snapToVertex=!!e}get snapToVertex(){return this._configs.snapToVertex}set snapToEdge(e){this._configs.snapToEdge=!!e}get snapToEdge(){return this._configs.snapToEdge}set snapRadius(e){e=e||30,this._configs.snapRadius=e}get snapRadius(){return this._configs.snapRadius}set navMode(e){"firstPerson"!==(e=e||"orbit")&&"orbit"!==e&&"planView"!==e&&(this.error("Unsupported value for navMode: "+e+" - supported values are 'orbit', 'firstPerson' and 'planView' - defaulting to 'orbit'"),e="orbit"),this._configs.firstPerson="firstPerson"===e,this._configs.planView="planView"===e,(this._configs.firstPerson||this._configs.planView)&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this._configs.navMode=e}get navMode(){return this._configs.navMode}set pointerEnabled(e){this._reset(),this._configs.pointerEnabled=!!e}_reset(){for(let e=0,t=this._handlers.length;e<t;e++){const t=this._handlers[e];t.reset&&t.reset()}this._updates.panDeltaX=0,this._updates.panDeltaY=0,this._updates.rotateDeltaX=0,this._updates.rotateDeltaY=0,this._updates.dolyDelta=0}get pointerEnabled(){return this._configs.pointerEnabled}set followPointer(e){this._configs.followPointer=!1!==e}get followPointer(){return this._configs.followPointer}set pivotPos(e){this._controllers.pivotController.setPivotPos(e)}get pivotPos(){return this._controllers.pivotController.getPivotPos()}set dollyToPointer(e){this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer=e}get dollyToPointer(){return this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer}set panToPointer(e){this.warn("panToPointer property is deprecated - replaced with followPointer")}get panToPointer(){return this.warn("panToPointer property is deprecated - replaced with followPointer"),!1}set planView(e){this._configs.planView=!!e,this._configs.firstPerson=!1,this._configs.planView&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this.warn("planView property is deprecated - replaced with navMode")}get planView(){return this.warn("planView property is deprecated - replaced with navMode"),this._configs.planView}set firstPerson(e){this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson=!!e,this._configs.planView=!1,this._configs.firstPerson&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot())}get firstPerson(){return this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson}set constrainVertical(e){this._configs.constrainVertical=!!e}get constrainVertical(){return this._configs.constrainVertical}set doublePickFlyTo(e){this._configs.doublePickFlyTo=!1!==e}get doublePickFlyTo(){return this._configs.doublePickFlyTo}set panRightClick(e){this._configs.panRightClick=!1!==e}get panRightClick(){return this._configs.panRightClick}set rotationInertia(e){this._configs.rotationInertia=null!=e?e:0}get rotationInertia(){return this._configs.rotationInertia}set keyboardPanRate(e){this._configs.keyboardPanRate=null!=e?e:5}set touchPanRate(e){this._configs.touchPanRate=null!=e?e:1}get touchPanRate(){return this._configs.touchPanRate}get keyboardPanRate(){return this._configs.keyboardPanRate}set keyboardRotationRate(e){this._configs.keyboardRotationRate=null!=e?e:90}get keyboardRotationRate(){return this._configs.keyboardRotationRate}set dragRotationRate(e){this._configs.dragRotationRate=null!=e?e:360}get dragRotationRate(){return this._configs.dragRotationRate}set keyboardDollyRate(e){this._configs.keyboardDollyRate=null!=e?e:15}get keyboardDollyRate(){return this._configs.keyboardDollyRate}set touchDollyRate(e){this._configs.touchDollyRate=null!=e?e:.2}get touchDollyRate(){return this._configs.touchDollyRate}set mouseWheelDollyRate(e){this._configs.mouseWheelDollyRate=null!=e?e:100}get mouseWheelDollyRate(){return this._configs.mouseWheelDollyRate}set dollyInertia(e){this._configs.dollyInertia=null!=e?e:0}get dollyInertia(){return this._configs.dollyInertia}set dollyProximityThreshold(e){this._configs.dollyProximityThreshold=null!=e?e:35}get dollyProximityThreshold(){return this._configs.dollyProximityThreshold}set dollyMinSpeed(e){this._configs.dollyMinSpeed=null!=e?e:.04}get dollyMinSpeed(){return this._configs.dollyMinSpeed}set panInertia(e){this._configs.panInertia=null!=e?e:.5}get panInertia(){return this._configs.panInertia}set keyboardLayout(e){"qwerty"!==(e=e||"qwerty")&&"azerty"!==e&&(this.error("Unsupported value for keyboardLayout - defaulting to 'qwerty'"),e="qwerty"),this._configs.keyboardLayout=e,this.keyMap=this._configs.keyboardLayout}get keyboardLayout(){return this._configs.keyboardLayout}enablePivotSphere(e={}){this._controllers.pivotController.enablePivotSphere(e)}disablePivotSphere(){this._controllers.pivotController.disablePivotSphere()}set smartPivot(e){this._configs.smartPivot=!1!==e}get smartPivot(){return this._configs.smartPivot}set doubleClickTimeFrame(e){this._configs.doubleClickTimeFrame=null!=e?e:250}get doubleClickTimeFrame(){return this._configs.doubleClickTimeFrame}destroy(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),super.destroy()}_destroyHandlers(){for(let e=0,t=this._handlers.length;e<t;e++){const t=this._handlers[e];t.destroy&&t.destroy()}}_destroyControllers(){for(let e=0,t=this._controllers.length;e<t;e++){const t=this._controllers[e];t.destroy&&t.destroy()}}}class td{constructor(e,t,s,n,i){this.name=e,this.type=s,this.value=t,this.valueType=n,this.description=i}}class sd{constructor(e){if(this.id=e.id,this.originalSystemId=e.originalSystemId,this.metaModels=[],this.name=e.name,this.type=e.type,this.properties=[],e.properties){const t=e.properties;for(let e=0,s=t.length;e<s;e++){const s=t[e];this.properties.push(new td(s.name,s.value,s.type,s.valueType,s.description))}}}}class nd{constructor(e){this.metaModels=[],this.id=e.id,this.parentId=e.parentId,this.parent=null,this.originalSystemId=e.originalSystemId,this.name=e.name,this.type=e.type,this.propertySetIds=e.propertySetIds,this.propertySets=[],this.attributes=e.attributes||{},void 0!==e.external&&null!==e.external&&(this.external=e.external)}get metaModel(){return 1==this.metaModels.length?this.metaModels[0]:null}getObjectIDsInSubtree(){const e=[];return function t(s){if(!s)return;e.push(s.id);const n=s.children;if(n)for(var i=0,r=n.length;i<r;i++)t(n[i])}(this),e}withMetaObjectsInSubtree(e){!function t(s){if(!s)return;e(s);const n=s.children;if(n)for(var i=0,r=n.length;i<r;i++)t(n[i])}(this)}getObjectIDsInSubtreeByType(e){const t={};for(var s=0,n=e.length;s<n;s++)t[e[s]]=e[s];const i=[];return function e(s){if(!s)return;t[s.type]&&i.push(s.id);const n=s.children;if(n)for(var r=0,a=n.length;r<a;r++)e(n[r])}(this),i}getJSON(){var e={id:this.id,type:this.type,name:this.name};return this.parent&&(e.parent=this.parent.id),e}}class id{constructor(e){this.id=e.id,this.projectId=e.projectId,this.revisionId=e.revisionId,this.author=e.author,this.createdAt=e.createdAt,this.creatingApplication=e.creatingApplication,this.schema=e.schema,this.metaScene=e.metaScene,this.propertySets=[],this.rootMetaObjects=[],this.metaObjects=[],this.graph=e.graph||{},this.metaScene.metaModels[this.id]=this,this.finalized=!1}get rootMetaObject(){return 1==this.rootMetaObjects.length?this.rootMetaObjects[0]:null}loadData(e,t={}){if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);const s=this.metaScene,n=e.properties;if(e.propertySets)for(let t=0,i=e.propertySets.length;t<i;t++){const i=e.propertySets[t];let r=s.propertySets[i.id];r||(n&&this._decompressProperties(n,i.properties),r=new sd({id:i.id,originalSystemId:i.originalSystemId||i.id,type:i.type,name:i.name,properties:i.properties}),s.propertySets[r.id]=r),r.metaModels.push(this),this.propertySets.push(r)}if(e.metaObjects)for(let t=0,n=e.metaObjects.length;t<n;t++){const n=e.metaObjects[t],i=n.id;let r=s.metaObjects[i];if(!r){const e=n.type,t=n.originalSystemId,s=n.propertySets||n.propertySetIds;r=new nd({id:i,originalSystemId:t,parentId:n.parent,type:e,name:n.name,attributes:n.attributes,propertySetIds:s,external:n.external}),this.metaScene.metaObjects[i]=r,r.metaModels=[]}this.metaObjects.push(r),n.parent||(this.rootMetaObjects.push(r),s.rootMetaObjects[i]=r)}}_decompressProperties(e,t){for(let s=0,n=t.length;s<n;s++){const n=t[s];if(Number.isInteger(n)){const i=e[n];i&&(t[s]=i)}}}finalize(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";const e=this.metaScene;for(let t in e.metaObjects){const s=e.metaObjects[t];if(s.children&&(s.children=[]),s.propertySets&&(s.propertySets=[]),s.propertySetIds)for(let t=0,n=s.propertySetIds.length;t<n;t++){const n=s.propertySetIds[t],i=e.propertySets[n];s.propertySets.push(i)}}for(let t in e.metaObjects){const s=e.metaObjects[t];if(s.parentId){const t=e.metaObjects[s.parentId];t&&(s.parent=t,(t.children||(t.children=[])).push(s))}}for(let t in e.metaObjects){e.metaObjects[t].metaModels=[]}for(let t in e.metaModels){const s=e.metaModels[t];for(let e=0,t=s.metaObjects.length;e<t;e++){s.metaObjects[e].metaModels.push(s)}}e.metaObjectsByType={};for(let t in e.metaObjects){const s=e.metaObjects[t],n=s.type;(e.metaObjectsByType[n]||(e.metaObjectsByType[n]={}))[t]=s}this.finalized=!0,this.metaScene.fire("metaModelCreated",this.id)}getJSON(){const e={id:this.id,projectId:this.projectId,author:this.author,createdAt:this.createdAt,schema:this.schema,creatingApplication:this.creatingApplication,metaObjects:[],propertySets:[]};for(let t=0,s=this.metaObjects.length;t<s;t++){const s=this.metaObjects[t],n={id:s.id,originalSystemId:s.originalSystemId,extId:s.extId,type:s.type,name:s.name};s.parent&&(n.parent=s.parent.id),s.attributes&&(n.attributes=s.attributes),s.propertySetIds&&(n.propertySetIds=s.propertySetIds),e.metaObjects.push(n)}for(let t=0,s=this.propertySets.length;t<s;t++){const s=this.propertySets[t],n={id:s.id,originalSystemId:s.originalSystemId,extId:s.extId,type:s.type,name:s.name,propertyies:[]};for(let e=0,t=s.properties.length;e<t;e++){const t=s.properties[e],i={id:t.id,description:t.description,type:t.type,name:t.name,value:t.value,valueType:t.valueType};n.properties.push(i)}e.propertySets.push(n)}return e}_globalizeIDs(e,t){const s=!!t.globalizeObjectIds;if(e.metaObjects)for(let t=0,n=e.metaObjects.length;t<n;t++){const n=e.metaObjects[t];if(n.originalSystemId=n.id,n.parent&&(n.originalParentSystemId=n.parent),s&&(n.id=d.globalizeObjectId(this.id,n.id),n.parent&&(n.parent=d.globalizeObjectId(this.id,n.parent))),s){const e=n.propertySetIds;if(e){const t=[];for(let s=0,n=e.length;s<n;s++)t.push(d.globalizeObjectId(this.id,e[s]));n.propertySetIds=t,n.originalSystemPropertySetIds=e}}else n.originalSystemPropertySetIds=n.propertySetIds}if(e.propertySets)for(let t=0,n=e.propertySets.length;t<n;t++){const n=e.propertySets[t];n.originalSystemId=n.id,s&&(n.id=d.globalizeObjectId(this.id,n.id))}}}class rd{constructor(e,t){this.viewer=e,this.scene=t,this.metaModels={},this.propertySets={},this.metaObjects={},this.metaObjectsByType={},this.rootMetaObjects={},this._eventSubs={}}on(e,t){let s=this._eventSubs[e];s||(s=[],this._eventSubs[e]=s),s.push(t)}fire(e,t){const s=this._eventSubs[e];if(s)for(let e=0,n=s.length;e<n;e++)s[e](t)}off(e){}createMetaModel(e,t,s={}){const n=new id({metaScene:this,id:e,projectId:t.projectId||"none",revisionId:t.revisionId||"none",author:t.author||"none",createdAt:t.createdAt||"none",creatingApplication:t.creatingApplication||"none",schema:t.schema||"none",propertySets:[]});return n.loadData(t),n.finalize(),n}destroyMetaModel(e){const t=this.metaModels[e];if(t){if(t.propertySets)for(let s=0,n=t.propertySets.length;s<n;s++){const n=t.propertySets[s];if(1===n.metaModels.length&&n.metaModels[0].id===e)delete this.propertySets[n.id];else{const t=[];for(let s=0,i=n.metaModels.length;s<i;s++)n.metaModels[s].id!==e&&t.push(n.metaModels[s]);n.metaModels=t}}if(t.metaObjects)for(let s=0,n=t.metaObjects.length;s<n;s++){const n=t.metaObjects[s];n.type;const i=n.id;1===n.metaModels.length&&n.metaModels[0].id===e&&(delete this.metaObjects[i],n.parent||delete this.rootMetaObjects[i])}for(let e in this.metaObjects){const t=this.metaObjects[e];if(t.children&&(t.children=[]),t.propertySets&&(t.propertySets=[]),t.propertySetIds)for(let e=0,s=t.propertySetIds.length;e<s;e++){const s=t.propertySetIds[e],n=this.propertySets[s];t.propertySets.push(n)}}this.metaObjectsByType={};for(let e in this.metaObjects){const t=this.metaObjects[e],s=t.type;t.children&&(t.children=null),(this.metaObjectsByType[s]||(this.metaObjectsByType[s]={}))[e]=t}for(let e in this.metaObjects){const t=this.metaObjects[e];if(t.parentId){const e=this.metaObjects[t.parentId];e&&(t.parent=e,(e.children||(e.children=[])).push(t))}}delete this.metaModels[e];for(let e in this.metaObjects){this.metaObjects[e].metaModels=[]}for(let e in this.metaModels){const t=this.metaModels[e];for(let e=0,s=t.metaObjects.length;e<s;e++){t.metaObjects[e].metaModels.push(t)}}this.fire("metaModelDestroyed",e)}}getObjectIDsByType(e){const t=this.metaObjectsByType[e];return t?Object.keys(t):[]}getObjectIDsInSubtree(e,t,s){const n=[],i=this.metaObjects[e],r=t&&t.length>0?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<l;i++)o(s[i])};return o(i),n}withMetaObjectsInSubtree(e,t){const s=this.metaObjects[e];s&&s.withMetaObjectsInSubtree(t)}}function ad(e){const t={};for(var s=0,n=e.length;s<n;s++)t[e[s]]=!0;return t}
18
18
  /*!
19
19
  * html2canvas 1.4.1 <https://html2canvas.hertzen.com>
20
20
  * Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>