@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 @@
14
14
  /**
15
15
  * @author https://github.com/tmarti, with support from https://tribia.com/
16
16
  * @license MIT
17
- **/let gc=null;function Ec(e,t){const s=3*e,n=3*t;let i,r,a,o,l,c;const u=Math.min(i=gc[s],r=gc[s+1],a=gc[s+2]),h=Math.min(o=gc[n],l=gc[n+1],c=gc[n+2]);if(u!==h)return u-h;const p=Math.max(i,r,a),d=Math.max(o,l,c);return p!==d?p-d:0}let Tc=null;function bc(e,t){let s=Tc[2*e]-Tc[2*t];return 0!==s?s:Tc[2*e+1]-Tc[2*t+1]}function Dc(e,t,s=!1){const n=e.positionsCompressed||[],i=function(e,t){const s=new Int32Array(e.length/3);for(let e=0,t=s.length;e<t;e++)s[e]=e;gc=new Int32Array(e.length);for(let s=0,n=e.length;s<n;s++)gc[s]=e[s]>>t;s.sort(Ec);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}Tc=new Int32Array(e),t.sort(bc);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 Pc=h.vec4(4),Cc=h.vec4(),_c=h.vec4(),Rc=h.vec3([1,0,0]),Bc=h.vec3([0,1,0]),Oc=h.vec3([0,0,1]);h.vec3(3),h.vec3(3);const Sc=h.identityMat4();class Nc{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=h.identityQuaternion(new Float32Array(4)),this._rotation=new Float32Array(3),this._position=new Float32Array(3),this._localMatrix=h.identityMat4(new Float32Array(16)),this._worldMatrix=h.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]),h.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]),h.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=h.identityMat4()),this._localMatrix.set(e||Sc),h.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=h.identityMat4()),h.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 Pc[0]=e[0],Pc[1]=e[1],Pc[2]=e[2],Pc[3]=t*h.DEGTORAD,h.angleAxisToQuaternion(Pc,Cc),h.mulQuaternions(this.quaternion,Cc,_c),this.quaternion=_c,this._setLocalMatrixDirty(),this._model.glRedraw(),this}rotateOnWorldAxis(e,t){return Pc[0]=e[0],Pc[1]=e[1],Pc[2]=e[2],Pc[3]=t*h.DEGTORAD,h.angleAxisToQuaternion(Pc,Cc),h.mulQuaternions(Cc,this.quaternion,Cc),this}rotateX(e){return this.rotate(Rc,e)}rotateY(e){return this.rotate(Bc,e)}rotateZ(e){return this.rotate(Oc,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)h.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 xc=h.vec3(),Lc=h.OBB3(),Mc=h.vec3([1,1,1]),Fc=h.vec3([0,0,0]),Hc=h.vec3([0,0,0]),Uc=h.identityQuaternion(),Gc=h.identityMat4(),jc=new Uint8Array([255,255,255]);class Vc extends O{constructor(e,t={}){super(e,t),this._dtxEnabled=this.scene.dtxEnabled&&!1!==t.dtxEnabled,this._enableVertexWelding=!1,this._enableIndexBucketing=!1,this._vboBatchingLayerScratchMemory=(Hn++,Fn),this._textureTranscoder=t.textureTranscoder||Ic(this.scene.viewer),this._maxGeometryBatchSize=t.maxGeometryBatchSize,this._aabb=h.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 Ns,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=h.vec3(t.origin||[0,0,0]),this._position=h.vec3(t.position||[0,0,0]),this._rotation=h.vec3(t.rotation||[0,0,0]),this._quaternion=h.vec4(t.quaternion||[0,0,0,1]),this._conjugateQuaternion=h.vec4(t.quaternion||[0,0,0,1]),t.rotation&&h.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._scale=h.vec3(t.scale||[1,1,1]),this._worldRotationMatrix=h.mat4(),this._worldRotationMatrixConjugate=h.mat4(),this._matrix=h.mat4(),this._matrixDirty=!0,this._rebuildMatrices(),this._worldNormalMatrix=h.mat4(),h.inverseMat4(this._matrix,this._worldNormalMatrix),h.transposeMat4(this._worldNormalMatrix),(t.matrix||t.position||t.rotation||t.scale||t.quaternion)&&(this._viewMatrix=h.mat4(),this._viewNormalMatrix=h.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 rc({id:"defaultColorTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new rc({id:"defaultMetalRoughTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),s=new rc({id:"defaultNormalsTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),n=new rc({id:"defaultEmissiveTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new rc({id:"defaultOcclusionTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=s,this._textures.defaultEmissiveTexture=n,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new ic({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:s,emissiveTexture:n,occlusionTexture:i})}get isPerformanceModel(){return!0}get transforms(){return this._transforms}get textures(){return this._textures}get textureSets(){return this._textureSets}get meshes(){return this._meshes}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),h.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),h.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||Gc),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),h.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),h.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),h.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),h.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0,this._aabbDirty=!0}_transformDirty(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}_sceneModelDirty(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(let e=0,t=this._entityList.length;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&&(h.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),h.inverseMat4(this._viewMatrix,this._viewNormalMatrix),h.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&&(h.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),h.inverseMat4(this._viewMatrix,this._viewNormalMatrix),h.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),h.inverseMat4(this._viewMatrix,this._viewNormalMatrix),h.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){h.collapseAABB3(this._aabb);for(let e=0,t=this._entityList.length;e<t;e++)h.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:Si(e.aabb,h.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=Si(e.positionsDecodeBoundary,h.mat4())),e.positions){const t=h.collapseAABB3();e.positionsDecodeMatrix=h.mat4(),h.expandAABB3Points3(t,e.positions),e.positionsCompressed=Oi(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=h.collapseAABB3();e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed),h.expandAABB3Points3(t,e.positionsCompressed),St.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}else if(e.buckets){const t=h.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?h.expandAABB3Points3(t,n.positions):n.positionsCompressed&&h.expandAABB3Points3(t,n.positionsCompressed)}e.positionsDecodeMatrix&&St.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=Dt(e.positions,e.indices,null,5):e.edgeIndices=Dt(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.uv){const t=St.getUVBounds(e.uv),s=St.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 mn({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?y.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new rc({id:t,texture:l})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let s,n,i,r,a;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(s=this._textures[e.colorTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(n=this._textures[e.metallicRoughnessTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(i=this._textures[e.normalsTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(r=this._textures[e.emissiveTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(a=this._textures[e.occlusionTextureId],!a)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else a=this._textures.defaultOcclusionTexture;const o=new ic({id:t,model:this,colorTexture:s,metallicRoughnessTexture:n,normalsTexture:i,emissiveTexture:r,occlusionTexture:a});return this._textureSets[t]=o,o}createTransform(e){if(void 0===e.id||null===e.id)return void this.error("[createTransform] SceneModel.createTransform() config missing: id");if(this._transforms[e.id])return void this.error(`[createTransform] SceneModel already has a transform with this ID: ${e.id}`);let t;if(this.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const s=new Nc({id:e.id,model:this,parentTransform:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[s.id]=s,s}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._scheduledMeshes[e.id])return this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`),!1;if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;const t=!!this._dtxEnabled&&("triangles"===e.primitive||"solid"===e.primitive||"surface"===e.primitive);if(e.origin=e.origin?h.addVec3(this._origin,e.origin,h.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){const t=e.scale||Mc,s=e.position||Fc,n=e.rotation||Hc;h.eulerToQuaternion(n,"XYZ",Uc),e.meshMatrix=h.composeMat4(s,Uc,t,h.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Si(e.positionsDecodeBoundary,h.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):jc,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=h.vec3(),s=[];Q(e.positions,s,t)&&(e.positions=s,e.origin=h.addVec3(e.origin,t,t))}if(e.positions){const t=h.collapseAABB3();e.positionsDecodeMatrix=h.mat4(),h.expandAABB3Points3(t,e.positions),e.positionsCompressed=Oi(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=h.collapseAABB3();h.expandAABB3Points3(t,e.positionsCompressed),St.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=h.collapseAABB3();for(let s=0,n=e.buckets.length;s<n;s++){const n=e.buckets[s];n.positions?h.expandAABB3Points3(t,n.positions):n.positionsCompressed&&h.expandAABB3Points3(t,n.positionsCompressed)}e.positionsDecodeMatrix&&St.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}e.meshMatrix&&(h.AABB3ToOBB3(e.aabb,Lc),h.transformOBB3(e.meshMatrix,Lc),h.OBB3ToAABB3(Lc,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=Dt(e.positions,e.indices,null,2):e.edgeIndices=Dt(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=kc(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=[];Q(e.positions,t,xc)&&(e.positions=t,e.origin=h.addVec3(e.origin,xc,h.vec3()))}if(e.positions){const t=h.collapseAABB3();e.meshMatrix&&(h.transformPositions3(e.meshMatrix,e.positions,e.positions),e.meshMatrix=null),h.expandAABB3Points3(t,e.positions),e.aabb=t}else{const t=h.collapseAABB3();h.expandAABB3Points3(t,e.positionsCompressed),St.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.meshMatrix&&(h.AABB3ToOBB3(e.aabb,Lc),h.transformOBB3(e.meshMatrix,Lc),h.OBB3ToAABB3(Lc,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=Dt(e.positions,e.indices,null,2):e.edgeIndices=Dt(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?h.addVec3(this._origin,e.origin,h.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||Mc,s=e.position||Fc,n=e.rotation||Hc;h.eulerToQuaternion(n,"XYZ",Uc),e.meshMatrix=h.composeMat4(s,Uc,t,h.mat4())}h.AABB3ToOBB3(e.geometry.aabb,Lc),h.transformOBB3(e.meshMatrix,Lc),e.aabb=h.OBB3ToAABB3(Lc,h.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])]):jc,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255;let t=this._dtxBuckets[e.geometryId];t||(t=kc(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])]):jc,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 Mn(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=h.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),t}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let s=0,n=e.buckets.length;s<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 nc(this,{layerIndex:0,origin:t});break;case"lines":i=new xo(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 Wi({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 ta({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:s,maxGeometryBatchSize:this._maxGeometryBatchSize});break;case"points":a=new ka({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 Mr({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0,solid:!1});break;case"solid":a=new Mr({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0,solid:!0});break;case"lines":a=new ga({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0});break;case"points":a=new fo({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0})}return this._vboInstancingLayers[r]=a,this.layerList.push(a),a}createEntity(e){if(void 0===e.id?e.id=h.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=h.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;this._visible&&!1!==e.visible&&(t|=z),this._pickable&&!1!==e.pickable&&(t|=Y),this._culled&&!1!==e.culled&&(t|=K),this._clippable&&!1!==e.clippable&&(t|=X),this._collidable&&!1!==e.collidable&&(t|=q),this._edges&&!1!==e.edges&&(t|=ee),this._xrayed&&!1!==e.xrayed&&(t|=J),this._highlighted&&!1!==e.highlighted&&(t|=Z),this._selected&&!1!==e.selected&&(t|=$),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let s=0,n=e.meshIds.length;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 ne(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!==Hn&&(Hn--,0===Hn&&Fn._clear()),super.destroy()}}function kc(e,t,s){let n,i,r,a;if(t||s?[n,i,r]=wc({positionsCompressed:e.positionsCompressed,indices:e.indices,edgeIndices:e.edgeIndices}):(n=e.positionsCompressed,i=e.indices,r=e.edgeIndices),s){a=Dc({positionsCompressed:n,indices:i,edgeIndices:r},n.length/3>65536?16:8)}else a=[{positionsCompressed:n,indices:i,edgeIndices:r}];return a}class Qc extends O{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e<t;e+=2)this._indices.push(e),this._indices.push(e+1)}this._sceneModel=new Vc(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 Wc=h.vec3(),zc=h.vec3(),Kc=h.vec3(),Yc=h.vec3();function Xc(e){return{x:e[0],y:e[1],z:e[2]}}function qc(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function Jc(e){return new Float64Array([e[0],-e[2],e[1]])}function Zc(e){return new Float64Array([e[0],e[2],-e[1]])}const $c=h.vec3(),eu=(e,t,s,n)=>{var i=e-s,r=t-n;return Math.sqrt(i*i+r*r)};class tu extends O{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._eventSubs={};var s=this.plugin.viewer.scene;this._originMarker=new ae(s,t.origin),this._targetMarker=new ae(s,t.target),this._originWorld=h.vec3(),this._targetWorld=h.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;const n=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,c=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new le(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._targetDot=new le(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._lengthWire=new oe(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._xAxisWire=new oe(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._yAxisWire=new oe(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._zAxisWire=new oe(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._lengthLabel=new ce(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._xAxisLabel=new ce(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._yAxisLabel=new ce(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._zAxisLabel=new ce(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._sectionPlanesDirty=!0,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,this._labelsVisible=!1,this._labelsOnWires=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=s.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=s.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=s.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=s.on("sectionPlaneUpdated",(()=>{this._sectionPlanesDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.labelsVisible=t.labelsVisible,this.labelsOnWires=t.labelsOnWires}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(h.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._wp))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}const t=this._originMarker.viewPos[2],s=this._targetMarker.viewPos[2];if(t>-.3||s>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){h.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var n=this._pp,i=this._cp,r=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var a=r.top-t.top,o=r.left-t.left,l=e.canvas.boundary,c=l[2],u=l[3],p=0;const s=this.plugin.viewer.scene.metrics,f=s.scale,I=s.units,m=s.unitsInfo[I].abbrev;for(var d=0,A=n.length;d<A;d+=4)i[p]=o+Math.floor((1+n[d+0]/n[d+3])*c/2),i[p+1]=a+Math.floor((1-n[d+1]/n[d+3])*u/2),p+=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(h.lenVec3(h.subVec3(this._targetWorld,this._originWorld,$c))),this._lengthLabel.setText(e+(this._length*f).toFixed(2)+m);const t=Math.abs(eu(i[0],i[1],i[2],i[3])),s=Math.abs(eu(i[2],i[3],i[4],i[5])),n=Math.abs(eu(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(h.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 su extends O{get active(){}set snapping(e){}get snapping(){return!0}activate(){}deactivate(){}reset(){}destroy(){}}class nu extends su{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=h.vec3(),a=h.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:h.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 iu{constructor(){}getMetaModel(e,t,s){y.loadJSON(e,(e=>{t(e)}),(function(e){s(e)}))}getGLTF(e,t,s){y.loadArraybuffer(e,(e=>{t(e)}),(function(e){s(e)}))}getGLB(e,t,s){y.loadArraybuffer(e,(e=>{t(e)}),(function(e){s(e)}))}getArrayBuffer(e,t,s,n){!function(e,t,s,n){var i=()=>{};s=s||i,n=n||i;const r=/^data:(.*?)(;base64)?,(.*)$/,a=t.match(r);if(a){const e=!!a[2];var o=a[3];o=window.decodeURIComponent(o),e&&(o=window.atob(o));try{const e=new ArrayBuffer(o.length),t=new Uint8Array(e);for(var l=0;l<o.length;l++)t[l]=o.charCodeAt(l);C.scheduleTask((function(){s(e)}))}catch(e){C.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 ru{constructor(e={}){this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=e.messages,this.locale=e.locale}set messages(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}loadMessages(e={}){for(let t in e)this._messages[t]=e[t];this.messages=this._messages}clearMessages(){this.messages={}}get locales(){return this._locales}set locale(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}get locale(){return this._locale}translate(e,t){const s=this._messages[this._locale];if(!s)return null;const n=au(e,s);return n?t?ou(n,t):n:null}translatePlurals(e,t,s){const n=this._messages[this._locale];if(!n)return null;let i=au(e,n);return i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one,i?(i=ou(i,[t]),s&&(i=ou(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const r=this._events[t];return void 0!==r&&s(r),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function au(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&e<t;e++){n=n[s[e]]}return n}function ou(e,t=[]){return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,s){return"{{"===e?"{":"}}"===e?"}":t[s]}))}class lu extends O{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=h.subVec3(r,i,[]);return h.normalizeVec3(a,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,s,n=[],i=this.getPoint(0),r=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),r+=h.lenVec3(h.subVec3(t,i,[])),n.push(r),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,r=n.length;s=t||e*n[r-1];for(var a,o=0,l=r-1;o<=l;)if((a=n[i=Math.floor(o+(l-o)/2)]-s)<0)o=i+1;else{if(!(a>0)){l=i;break}l=i-1}if(n[i=l]===s)return i/(r-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(r-1)}}class cu extends lu{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var s=(t.length-1)*e,n=Math.floor(s),i=s-n,r=t[0===n?n:n-1],a=t[n],o=t[n>t.length-2?t.length-1:n+1],l=t[n>t.length-3?t.length-1:n+2],c=h.vec3();return c[0]=h.catmullRomInterpolate(r[0],a[0],o[0],l[0],i),c[1]=h.catmullRomInterpolate(r[1],a[1],o[1],l[1],i),c[2]=h.catmullRomInterpolate(r[2],a[2],o[2],l[2],i),c}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const uu=h.vec3();const hu=h.vec3(),pu=h.vec3(),du=h.vec3(),Au=h.vec3(),fu=h.vec3();class Iu extends O{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=h.vec3(),this._eye1=h.vec3(),this._up1=h.vec3(),this._look2=h.vec3(),this._eye2=h.vec3(),this._up2=h.vec3(),this._orthoScale1=1,this._orthoScale2=1,this._flying=!1,this._flyEyeLookUp=!1,this._flyingEye=!1,this._flyingLook=!1,this._callback=null,this._callbackScope=null,this._time1=null,this._time2=null,this.easing=!1!==t.easing,this.duration=t.duration,this.fit=t.fit,this.fitFOV=t.fitFOV,this.trail=t.trail}flyTo(e,t,s){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=s;const n=this.scene.camera,i=!!e.projection&&e.projection!==n.projection;let r,a,o,l,c;if(this._eye1[0]=n.eye[0],this._eye1[1]=n.eye[1],this._eye1[2]=n.eye[2],this._look1[0]=n.look[0],this._look1[1]=n.look[1],this._look1[2]=n.look[2],this._up1[0]=n.up[0],this._up1[1]=n.up[1],this._up1[2]=n.up[2],this._orthoScale1=n.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)a=e.eye,o=e.look,l=e.up;else if(e.eye)a=e.eye;else if(e.look)o=e.look;else{let n=e;if((y.isNumeric(n)||y.isString(n))&&(c=n,n=this.scene.components[c],!n))return this.error("Component not found: "+y.inQuotes(c)),void(t&&(s?t.call(s):t()));i||(r=n.aabb||this.scene.aabb)}const u=e.poi;if(r){if(r[3]<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=h.getAABB3Center(r);this._look2=u||t;const s=h.subVec3(this._eye1,this._look1,hu),n=h.normalizeVec3(s),i=u?h.getAABB3DiagPoint(r,u):h.getAABB3Diag(r),a=e.fitFOV||this._fitFOV,o=Math.abs(i/Math.tan(a*h.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,C.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((y.isNumeric(t)||y.isString(t))&&(n=t,t=this.scene.components[n],!t))return void this.error("Component not found: "+y.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?h.getAABB3DiagPoint(s,o):h.getAABB3Diag(s);let n;r=o||h.getAABB3Center(s,r),this._trail?h.subVec3(t.look,r,fu):h.subVec3(t.eye,t.look,fu),h.normalizeVec3(fu);n=(void 0!==e.fit?e.fit:this._fit)?Math.abs(l/Math.tan((e.fitFOV||this._fitFOV)*h.DEGTORAD)):h.lenVec3(h.subVec3(t.eye,t.look,hu)),h.mulVec3Scalar(fu,n),t.eye=h.addVec3(r,fu,hu),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?Iu._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(h.subVec3(n.eye,n.look,fu),n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,du),n.look=h.subVec3(du,fu,pu)):this._flyingLook&&(n.look=h.lerpVec3(s,0,1,this._look1,this._look2,pu),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,Au)):this._flyingEyeLookUp&&(n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,du),n.look=h.lerpVec3(s,0,1,this._look1,this._look2,pu),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,Au)),this._projection2){const t="ortho"===this._projection2?Iu._easeOutExpo(e,0,1,1):Iu._easeInCubic(e,0,1,1);n.customProjection.matrix=h.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();C.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class mu extends O{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new Iu(this),this._t=0,this.state=mu.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case mu.SCRUBBING:return;case mu.PLAYING:if(this._t+=this._playingRate*i,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=mu.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case mu.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=mu.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=mu.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=mu.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=mu.SCRUBBING,this._cameraFlightAnimation.flyTo(n,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=mu.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=mu.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=mu.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}mu.STOPPED=0,mu.SCRUBBING=1,mu.PLAYING=2,mu.PLAYING_TO=3;const yu=h.vec3(),vu=h.vec3();h.vec3();const wu=h.vec3([0,-1,0]),gu=h.vec4([0,0,0,1]);function Eu(e){if(!Tu(e.width)||!Tu(e.height)){const t=document.createElement("canvas");t.width=bu(e.width),t.height=bu(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Tu(e){return 0==(e&e-1)}function bu(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Du extends O{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new $e({texture:new mn({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),A.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let r=0;r<e.length;r++){const a=new Image;a.onload=function(){let e=a;const o=r;return function(){if(!n&&(e=Eu(e),t._images[o]=e,i++,6===i)){let e=t._state.texture;e||(e=new mn({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(),A.memory.textures--,this._state.destroy()}}class Pu{constructor(e){this._eye=h.vec3(),this._look=h.vec3(),this._up=h.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 Cu=h.vec3();const _u=h.vec3();class Ru{constructor(){this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}saveObjects(e,t){this.numObjects=0,this._mask=t?y.apply(t,{}):null;const s=e.objects,n=!t||t.visible,i=!t||t.edges,r=!t||t.xrayed,a=!t||t.highlighted,o=!t||t.selected,l=!t||t.clippable,c=!t||t.pickable,u=!t||t.colorize,h=!t||t.opacity;for(let e in s)if(s.hasOwnProperty(e)){const t=s[e],p=this.numObjects;if(n&&(this.objectsVisible[p]=t.visible),i&&(this.objectsEdges[p]=t.edges),r&&(this.objectsXrayed[p]=t.xrayed),a&&(this.objectsHighlighted[p]=t.highlighted),o&&(this.objectsSelected[p]=t.selected),l&&(this.objectsClippable[p]=t.clippable),c&&(this.objectsPickable[p]=t.pickable),u){const e=t.colorize;e?(this.objectsColorize[3*p+0]=e[0],this.objectsColorize[3*p+1]=e[1],this.objectsColorize[3*p+2]=e[2],this.objectsHasColorize[p]=!0):this.objectsHasColorize[p]=!1}h&&(this.objectsOpacity[p]=t.opacity),this.numObjects++}}restoreObjects(e){const t=this._mask,s=!t||t.visible,n=!t||t.edges,i=!t||t.xrayed,r=!t||t.highlighted,a=!t||t.selected,o=!t||t.clippable,l=!t||t.pickable,c=!t||t.colorize,u=!t||t.opacity;var h=0;const p=e.objects;for(let e in p)if(p.hasOwnProperty(e)){const t=p[e];s&&(t.visible=this.objectsVisible[h]),n&&(t.edges=this.objectsEdges[h]),i&&(t.xrayed=this.objectsXrayed[h]),r&&(t.highlighted=this.objectsHighlighted[h]),a&&(t.selected=this.objectsSelected[h]),o&&(t.clippable=this.objectsClippable[h]),l&&(t.pickable=this.objectsPickable[h]),c&&(this.objectsHasColorize[h]?(_u[0]=this.objectsColorize[3*h+0],_u[1]=this.objectsColorize[3*h+1],_u[2]=this.objectsColorize[3*h+2],t.colorize=_u):t.colorize=null),u&&(t.opacity=this.objectsOpacity[h]),h++}}}class Bu extends O{constructor(e,t={}){super(e,t),this._skyboxMesh=new Qs(this,{geometry:new Lt(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new Gt(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Tn(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}const Ou=h.vec4(),Su=h.vec4(),Nu=h.vec3(),xu=h.vec3(),Lu=h.vec3(),Mu=h.vec4(),Fu=h.vec4(),Hu=h.vec4();class Uu{constructor(e){this._scene=e}dollyToCanvasPos(e,t,s){let n=!1;const i=this._scene.camera;if(e){const t=h.subVec3(e,i.eye,Nu);n=h.lenVec3(t)<s}if("perspective"===i.projection){i.ortho.scale=i.ortho.scale-s;const n=this._unproject(t,Mu),r=h.subVec3(n,i.eye,Hu),a=h.mulVec3Scalar(h.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=h.subVec3(e,i.eye,Nu),s=h.lenVec3(t),n=h.mulVec3Scalar(h.normalizeVec3(h.subVec3(i.look,i.eye,xu)),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,Mu);i.ortho.scale=i.ortho.scale-s,i.ortho._update();const n=this._unproject(t,Fu),r=h.subVec3(n,e,Hu),a=h.mulVec3Scalar(h.normalizeVec3(h.subVec3(i.look,i.eye,Nu)),-s,xu),o=h.addVec3(r,a,Lu);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=h.dotVec4(a,i)/h.dotVec4(a,r);return s.project.unproject(e,o,Ou,Su,t),t}destroy(){}}const Gu=h.vec3(),ju=h.vec3(),Vu=h.vec3(),ku=h.vec4(),Qu=h.vec4(),Wu=h.vec4();class zu{constructor(e,t){this._scene=e,this._configs=t,this._pivotWorldPos=h.vec3(),this._cameraOffset=h.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=h.vec3(),this._rtcPos=h.vec3(),this._pivotViewPos=h.vec4(),this._pivotProjPos=h.vec4(),this._pivotCanvasPos=h.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=h.vec3();h.decomposeMat4(h.inverseMat4(this._scene.viewer.camera.viewMatrix,h.mat4()),t,h.vec4(),h.vec3());const s=h.distVec3(t,e);let n=Math.tan(Math.PI/500)*s*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(n/=this._scene.camera.ortho.scale/2),k(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Pn(this._scene,Ks({radius:n})),this._pivotSphere=new Qs(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){h.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,h.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const s=t.boundary,n=s[2],i=s[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*n/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);let r=t._lastBoundingClientRect;if(!r||t._canvasSizeChanged){const e=t.canvas;r=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(r.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(r.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(k(this.getPivotPos(),this._rtcCenter,this._rtcPos),h.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new Gt(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=h.lookAtMat4v(e.eye,e.look,e.worldUp);h.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const s=this.getPivotPos();this._cameraOffset[2]+=h.distVec3(e.eye,s),t=h.inverseMat4(t);const n=h.transformVec3(t,this._cameraOffset),i=h.vec3();if(h.subVec3(e.eye,s,i),h.addVec3(i,n),e.zUp){const e=i[1];i[1]=i[2],i[2]=e}this._radius=h.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=h.normalizeVec3(h.subVec3(e.look,e.eye,Gu)),s=h.cross3Vec3(t,e.worldUp,ju);return h.sqLenVec3(s)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,s=Math.abs(h.distVec3(this._scene.center,t.eye)),n=t.project.transposedMatrix,i=n.subarray(8,12),r=n.subarray(12),a=[0,0,-1,1],o=h.dotVec4(a,i)/h.dotVec4(a,r),l=ku;t.project.unproject(e,o,Qu,Wu,l);const c=h.normalizeVec3(h.subVec3(l,t.eye,Gu)),u=h.addVec3(t.eye,h.mulVec3Scalar(c,s,ju),Vu);this.setPivotPos(u)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const s=this._scene.camera;var n=-e;const i=-t;1===s.worldUp[2]&&(n=-n),this._azimuth+=.01*-n,this._polar+=.01*i,this._polar=h.clamp(this._polar,.001,Math.PI-.001);const r=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===s.worldUp[2]){const e=r[1];r[1]=r[2],r[2]=e}const a=h.lenVec3(h.subVec3(s.look,s.eye,h.vec3())),o=this.getPivotPos();h.addVec3(r,o);let l=h.lookAtMat4v(r,o,s.worldUp);l=h.inverseMat4(l);const c=h.transformVec3(l,this._cameraOffset);l[12]-=c[0],l[13]-=c[1],l[14]-=c[2];const u=[l[8],l[9],l[10]];s.eye=[l[12],l[13],l[14]],h.subVec3(s.eye,h.mulVec3Scalar(u,a),s.look),s.up=[l[4],l[5],l[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class Ku{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=h.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;const e=`${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;if(this._lastHash===e)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;const t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&(e.snappedToEdge||e.snappedToVertex)?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const e=this.pickResult.canvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new De;e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}const Yu=h.vec2();class Xu{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController;let a,o,l,c=0,u=0,p=0,d=0,A=!1;const f=h.vec3();let I=!0;const m=this._scene.canvas.canvas,y=[];function v(e=!0){m.style.cursor="move",c=n.pointerCanvasPos[0],u=n.pointerCanvasPos[1],p=n.pointerCanvasPos[0],d=n.pointerCanvasPos[1],e&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),r.picked&&r.pickedSurface&&r.pickResult&&r.pickResult.worldPos?(A=!0,f.set(r.pickResult.worldPos)):A=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;y[n]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;y[n]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:y[e.input.KEY_SHIFT]||s.planView?(a=!0,v()):(a=!0,v(!1));break;case 2:o=!0,v();break;case 3:l=!0,s.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=()=>{if(!s.active||!s.pointerEnabled)return;if(!a&&!o&&!l)return;const t=e.canvas.boundary,r=t[2],p=t[3],d=n.pointerCanvasPos[0],I=n.pointerCanvasPos[1];if(y[e.input.KEY_SHIFT]||s.planView||!s.panRightClick&&o||s.panRightClick&&l){const t=d-c,s=I-u,n=e.camera;if("perspective"===n.projection){const r=Math.abs(A?h.lenVec3(h.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=1.5*t*r/p,i.panDeltaY+=1.5*s*r/p}else i.panDeltaX+=.5*n.ortho.scale*(t/p),i.panDeltaY+=.5*n.ortho.scale*(s/p)}else!a||o||l||s.planView||(s.firstPerson?(i.rotateDeltaY-=(d-c)/r*s.dragRotationRate/2,i.rotateDeltaX+=(I-u)/p*(s.dragRotationRate/4)):(i.rotateDeltaY-=(d-c)/r*(1.5*s.dragRotationRate),i.rotateDeltaX+=(I-u)/p*(1.5*s.dragRotationRate)));c=d,u=I}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{s.active&&s.pointerEnabled&&n.mouseover&&(I=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(s.active&&s.pointerEnabled)switch(e.which){case 1:case 2:case 3:a=!1,o=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(s.active&&s.pointerEnabled){if(3===e.which){!function(e,t){if(e){let s=e.target,n=0,i=0,r=0,a=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,r+=s.scrollLeft,a+=s.scrollTop,s=s.offsetParent;t[0]=e.pageX+r-n,t[1]=e.pageY+a-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Yu);const s=Yu[0],n=Yu[1];Math.abs(s-p)<3&&Math.abs(n-d)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Yu,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{s.active&&s.pointerEnabled});const w=1/60;let g=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=performance.now()/1e3;var r=null!==g?t-g:0;g=t,r>.05&&(r=.05),r<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 qu=h.vec3(),Ju=h.vec3(),Zu=h.vec3(),$u=h.vec3(),eh=h.vec3(),th={eye:h.vec3(),look:h.vec3(),up:h.vec3()};class sh{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),p=i._isKeyDownForAction(i.AXIS_VIEW_BOTTOM);if(!(a||o||l||c||u||p))return;const d=e.aabb,A=h.getAABB3Diag(d);h.getAABB3Center(d,qu);const f=Math.abs(A/Math.tan(t.cameraFlight.fitFOV*h.DEGTORAD)),I=1.1*A;th.orthoScale=I,a?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldRight,f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):o?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldForward,f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):l?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldRight,-f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):c?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldForward,-f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):u?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldUp,f,Ju),eh)),th.look.set(qu),th.up.set(h.normalizeVec3(h.mulVec3Scalar(r.worldForward,1,Zu),$u))):p&&(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldUp,-f,Ju),eh)),th.look.set(qu),th.up.set(h.normalizeVec3(h.mulVec3Scalar(r.worldForward,-1,Zu)))),!s.firstPerson&&s.followPointer&&t.pivotController.setPivotPos(qu),t.cameraFlight.duration>0?t.cameraFlight.flyTo(th,(()=>{t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(th),t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class nh{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.pivotController,o=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,c=!1;const u=this._scene.canvas.canvas,p=s=>{let n;s&&s.worldPos&&(n=s.worldPos);const i=s&&s.entity?s.entity.aabb:e.aabb;if(n){const s=e.camera;h.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})},d=e.tickify(this._canvasMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(l||c)return;const i=o.hasSubs("hover"),a=o.hasSubs("hoverEnter"),u=o.hasSubs("hoverOut"),h=o.hasSubs("hoverOff"),p=o.hasSubs("hoverSurface"),d=o.hasSubs("hoverSnapOrSurface");if(i||a||u||h||p||d)if(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=!0,r.schedulePickSurface=p,r.scheduleSnapOrPick=d,r.update(),r.pickResult){if(r.pickResult.entity){const t=r.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),o.fire("hoverEnter",r.pickResult,!0),this._lastPickedEntityId=t)}o.fire("hover",r.pickResult,!0),(r.pickResult.worldPos||r.pickResult.snappedWorldPos)&&o.fire("hoverSurface",r.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),o.fire("hoverOff",{canvasPos:r.pickCursorPos},!0)});u.addEventListener("mousemove",d),u.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(c=!0);if(1===t.which&&s.active&&s.pointerEnabled&&(n.mouseDownClientX=t.clientX,n.mouseDownClientY=t.clientY,n.mouseDownCursorX=n.pointerCanvasPos[0],n.mouseDownCursorY=n.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),1===t.which))){const t=r.pickResult;t&&t.worldPos?(a.setPivotPos(t.worldPos),a.startPivot()):(s.smartPivot?a.setCanvasPivotPos(n.pointerCanvasPos):a.setPivotPos(e.camera.look),a.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(c=!1),a.getPivoting()&&a.endPivot()}),u.addEventListener("mouseup",this._canvasMouseUpHandler=i=>{if(!s.active||!s.pointerEnabled)return;if(!(1===i.which))return;if(a.hidePivot(),Math.abs(i.clientX-n.mouseDownClientX)>3||Math.abs(i.clientY-n.mouseDownClientY)>3)return;const l=o.hasSubs("picked"),c=o.hasSubs("pickedNothing"),u=o.hasSubs("pickedSurface"),d=o.hasSubs("doublePicked"),A=o.hasSubs("doublePickedSurface"),f=o.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||d||A||f))return(l||c||u)&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=!0,r.schedulePickSurface=u,r.update(),r.pickResult?(o.fire("picked",r.pickResult,!0),r.pickedSurface&&o.fire("pickedSurface",r.pickResult,!0)):o.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=s.doublePickFlyTo,r.schedulePickSurface=u,r.update();const e=r.pickResult,i=r.pickedSurface;this._timeout=setTimeout((()=>{e?(o.fire("picked",e,!0),i&&(o.fire("pickedSurface",e,!0),!s.firstPerson&&s.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):o.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0),this._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=s.doublePickFlyTo||d||A,r.schedulePickSurface=r.schedulePickEntity&&A,r.update(),r.pickResult){if(o.fire("doublePicked",r.pickResult,!0),r.pickedSurface&&o.fire("doublePickedSurface",r.pickResult,!0),s.doublePickFlyTo&&(p(r.pickResult),!s.firstPerson&&s.followPointer)){const e=r.pickResult.entity.aabb,s=h.getAABB3Center(e);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(o.fire("doublePickedNothing",{canvasPos:n.pointerCanvasPos},!0),s.doublePickFlyTo&&(p(),!s.firstPerson&&s.followPointer)){const s=e.aabb,n=h.getAABB3Center(s);t.pivotController.setPivotPos(n),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class ih{constructor(e,t,s,n,i){this._scene=e;const r=e.input,a=[],o=e.canvas.canvas;let l=!0;this._onSceneMouseMove=r.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=r.on("keydown",(t=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&n.mouseover&&(a[t]=!0,t===r.KEY_SHIFT&&(o.style.cursor="move"))})),this._onSceneKeyUp=r.on("keyup",(n=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(a[n]=!1,n===r.KEY_SHIFT&&(o.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(o=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const c=t.cameraControl,u=o.deltaTime/1e3;if(!s.planView){const e=c._isKeyDownForAction(c.ROTATE_Y_POS,a),n=c._isKeyDownForAction(c.ROTATE_Y_NEG,a),r=c._isKeyDownForAction(c.ROTATE_X_POS,a),o=c._isKeyDownForAction(c.ROTATE_X_NEG,a),l=u*s.keyboardRotationRate;(e||n||r||o)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),e?i.rotateDeltaY+=l:n&&(i.rotateDeltaY-=l),r?i.rotateDeltaX+=l:o&&(i.rotateDeltaX-=l),!s.firstPerson&&s.followPointer&&t.pivotController.startPivot())}if(!a[r.KEY_CTRL]&&!a[r.KEY_ALT]){const e=c._isKeyDownForAction(c.DOLLY_BACKWARDS,a),r=c._isKeyDownForAction(c.DOLLY_FORWARDS,a);if(e||r){const a=u*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),r?i.dollyDelta-=a:e&&(i.dollyDelta+=a),l&&(n.followPointerDirty=!0,l=!1)}}const h=c._isKeyDownForAction(c.PAN_FORWARDS,a),p=c._isKeyDownForAction(c.PAN_BACKWARDS,a),d=c._isKeyDownForAction(c.PAN_LEFT,a),A=c._isKeyDownForAction(c.PAN_RIGHT,a),f=c._isKeyDownForAction(c.PAN_UP,a),I=c._isKeyDownForAction(c.PAN_DOWN,a),m=(a[r.KEY_ALT]?.3:1)*u*s.keyboardPanRate;(h||p||d||A||f||I)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),I?i.panDeltaY+=m:f&&(i.panDeltaY+=-m),A?i.panDeltaX+=-m:d&&(i.panDeltaX+=m),p?i.panDeltaZ+=m:h&&(i.panDeltaZ+=-m))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const rh=h.vec3();class ah{constructor(e,t,s,n,i){this._scene=e;const r=e.camera,a=t.pickController,o=t.pivotController,l=t.panController;let c=1,u=1,p=null;this._onTick=e.on("tick",(()=>{if(!s.active||!s.pointerEnabled)return;let t="default";if(Math.abs(i.dollyDelta)<.001&&(i.dollyDelta=0),Math.abs(i.rotateDeltaX)<.001&&(i.rotateDeltaX=0),Math.abs(i.rotateDeltaY)<.001&&(i.rotateDeltaY=0),0===i.rotateDeltaX&&0===i.rotateDeltaY||(i.dollyDelta=0),s.followPointer&&--c<=0&&(c=1,0!==i.dollyDelta)){if(0===i.rotateDeltaY&&0===i.rotateDeltaX&&s.followPointer&&n.followPointerDirty&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.pickResult&&a.pickResult.worldPos?p=a.pickResult.worldPos:(u=1,p=null),n.followPointerDirty=!1),p){const t=Math.abs(h.lenVec3(h.subVec3(p,e.camera.eye,rh)));u=t/s.dollyProximityThreshold}u<s.dollyMinSpeed&&(u=s.dollyMinSpeed)}const d=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=h.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!==d){if(t=d<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(p,n.pointerCanvasPos,-d)&&(n.followPointerDirty=!0)}else r.pan([0,0,d]),r.ortho.scale=r.ortho.scale-d;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(p,n.pointerCanvasPos,-d)&&(n.followPointerDirty=!0)}else r.ortho.scale=r.ortho.scale+d,r.zoom(d);else if(s.followPointer){l.dollyToCanvasPos(p,n.pointerCanvasPos,-d)&&(n.followPointerDirty=!0)}else r.ortho.scale=r.ortho.scale+d,r.zoom(d);i.dollyDelta*=s.dollyInertia}a.fireEvents(),document.body.style.cursor=t}))}destroy(){this._scene.off(this._onTick)}}class oh{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=>{lh(e,r,n.pointerCanvasPos)}),r.addEventListener("mousedown",this._mouseDownHandler=e=>{s.active&&s.pointerEnabled&&(lh(e,r,n.pointerCanvasPos),n.mouseover=!0)}),r.addEventListener("mouseup",this._mouseUpHandler=e=>{s.active&&s.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function lh(e,t,s){if(e){const{x:n,y:i}=t.getBoundingClientRect();s[0]=e.clientX-n,s[1]=e.clientY-i}else e=window.event,s[0]=e.x,s[1]=e.y;return s}const ch=function(e,t){if(e){let s=e.target,n=0,i=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,s=s.offsetParent;t[0]=e.pageX-n,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class uh{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.pivotController,o=h.vec2(),l=h.vec2(),c=h.vec2(),u=h.vec2(),p=[],d=this._scene.canvas.canvas;let A=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),d.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!s.active||!s.pointerEnabled)return;t.preventDefault();const i=t.touches,l=t.changedTouches;for(n.touchStartTime=Date.now(),1===i.length&&1===l.length&&(ch(i[0],o),s.followPointer&&(r.pickCursorPos=o,r.schedulePickSurface=!0,r.update(),s.planView||(r.picked&&r.pickedSurface&&r.pickResult&&r.pickResult.worldPos?(a.setPivotPos(r.pickResult.worldPos),!s.firstPerson&&a.startPivot()&&a.showPivot()):(s.smartPivot?a.setCanvasPivotPos(n.pointerCanvasPos):a.setPivotPos(e.camera.look),!s.firstPerson&&a.startPivot()&&a.showPivot()))));p.length<i.length;)p.push(h.vec2());for(let e=0,t=i.length;e<t;++e)ch(i[e],p[e]);A=i.length}),d.addEventListener("touchend",this._canvasTouchEndHandler=()=>{a.getPivoting()&&a.endPivot()}),d.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const a=e.canvas.boundary,o=a[2],d=a[3],I=t.touches;if(t.touches.length===A){if(1===A){ch(I[0],l),h.subVec2(l,p[0],u);const t=u[0],r=u[1];if(null!==n.longTouchTimeout&&(Math.abs(t)>s.longTapRadius||Math.abs(r)>s.longTapRadius)&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),s.planView){const n=e.camera;if("perspective"===n.projection){const a=Math.abs(e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=t*a/d*s.touchPanRate,i.panDeltaY+=r*a/d*s.touchPanRate}else i.panDeltaX+=.5*n.ortho.scale*(t/d)*s.touchPanRate,i.panDeltaY+=.5*n.ortho.scale*(r/d)*s.touchPanRate}else i.rotateDeltaY-=t/o*(1*s.dragRotationRate),i.rotateDeltaX+=r/d*(1.5*s.dragRotationRate)}else if(2===A){const t=I[0],a=I[1];ch(t,l),ch(a,c);const o=h.geometricMeanVec2(p[0],p[1]),u=h.geometricMeanVec2(l,c),A=h.vec2();h.subVec2(o,u,A);const f=A[0],m=A[1],y=e.camera,v=h.distVec2([t.pageX,t.pageY],[a.pageX,a.pageY]),w=(h.distVec2(p[0],p[1])-v)*s.touchDollyRate;if(i.dollyDelta=w,Math.abs(w)<1)if("perspective"===y.projection){const t=r.pickResult?r.pickResult.worldPos:e.center,n=Math.abs(h.lenVec3(h.subVec3(t,e.camera.eye,[])))*Math.tan(y.perspective.fov/2*Math.PI/180);i.panDeltaX-=f*n/d*s.touchPanRate,i.panDeltaY-=m*n/d*s.touchPanRate}else i.panDeltaX-=.5*y.ortho.scale*(f/d)*s.touchPanRate,i.panDeltaY-=.5*y.ortho.scale*(m/d)*s.touchPanRate;n.pointerCanvasPos=u}for(let e=0;e<A;++e)ch(I[e],p[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 hh=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 ph{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,p=-1;const d=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;h.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};d.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!s.active||!s.pointerEnabled)return;null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null);const i=e.touches,r=e.changedTouches;if(o=Date.now(),1===i.length&&1===r.length){u=o,hh(i[0],c);const r=c[0],a=c[1],l=i[0].pageX,h=i[0].pageY;n.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(h)],canvasPos:[Math.round(r),Math.round(a)],event:e},!0),n.longTouchTimeout=null}),s.longTapTimeout)}else u=-1;for(;l.length<i.length;)l.push(new Float32Array(2));for(let e=0,t=i.length;e<t;++e)hh(i[e],l[e]);l.length=i.length},{passive:!0}),d.addEventListener("touchend",this._canvasTouchEndHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=Date.now(),i=e.touches,o=e.changedTouches,d=a.hasSubs("pickedSurface");null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),0===i.length&&1===o.length&&u>-1&&t-u<150&&(p>-1&&u-p<325?(hh(o[0],r.pickCursorPos),r.schedulePickEntity=!0,r.schedulePickSurface=d,r.update(),r.pickResult?(r.pickResult.touchInput=!0,a.fire("doublePicked",r.pickResult),r.pickedSurface&&a.fire("doublePickedSurface",r.pickResult),s.doublePickFlyTo&&A(r.pickResult)):(a.fire("doublePickedNothing"),s.doublePickFlyTo&&A()),p=-1):h.distVec2(l[0],c)<4&&(hh(o[0],r.pickCursorPos),r.schedulePickEntity=!0,r.schedulePickSurface=d,r.update(),r.pickResult?(r.pickResult.touchInput=!0,a.fire("picked",r.pickResult),r.pickedSurface&&a.fire("pickedSurface",r.pickResult)):a.fire("pickedNothing"),p=t),u=-1),l.length=i.length;for(let e=0,t=i.length;e<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 dh extends O{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:h.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:h.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const s=this.scene;this._controllers={cameraControl:this,pickController:new Ku(this,this._configs),pivotController:new zu(s,this._configs),panController:new Uu(s),cameraFlight:new Iu(this,{duration:.5})},this._handlers=[new oh(this.scene,this._controllers,this._configs,this._states,this._updates),new uh(this.scene,this._controllers,this._configs,this._states,this._updates),new Xu(this.scene,this._controllers,this._configs,this._states,this._updates),new sh(this.scene,this._controllers,this._configs,this._states,this._updates),new nh(this.scene,this._controllers,this._configs,this._states,this._updates),new ph(this.scene,this._controllers,this._configs,this._states,this._updates),new ih(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new ah(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",y.isString(e)){const t=this.scene.input,s={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":s[this.PAN_LEFT]=[t.KEY_A],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_Z],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":s[this.PAN_LEFT]=[t.KEY_Q],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_W],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=s}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const s=this._keyMap[e];if(!s)return!1;t||(t=this.scene.input.keyDown);for(let e=0,n=s.length;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 Ah{constructor(e,t,s,n,i){this.name=e,this.type=s,this.value=t,this.valueType=n,this.description=i}}class fh{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 Ah(s.name,s.value,s.type,s.valueType,s.description))}}}}class Ih{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 mh{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 fh({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 Ih({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=h.globalizeObjectId(this.id,n.id),n.parent&&(n.parent=h.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(h.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=h.globalizeObjectId(this.id,n.id))}}}class yh{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 mh({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?vh(t):null,a=s&&s.length>0?vh(s):null,o=e=>{if(!e)return;var t=!0;(a&&a[e.type]||r&&!r[e.type])&&(t=!1),t&&n.push(e.id);const s=e.children;if(s)for(var i=0,l=s.length;i<l;i++)o(s[i])};return o(i),n}withMetaObjectsInSubtree(e,t){const s=this.metaObjects[e];s&&s.withMetaObjectsInSubtree(t)}}function vh(e){const t={};for(var s=0,n=e.length;s<n;s++)t[e[s]]=!0;return t}
17
+ **/let gc=null;function Ec(e,t){const s=3*e,n=3*t;let i,r,a,o,l,c;const u=Math.min(i=gc[s],r=gc[s+1],a=gc[s+2]),h=Math.min(o=gc[n],l=gc[n+1],c=gc[n+2]);if(u!==h)return u-h;const p=Math.max(i,r,a),d=Math.max(o,l,c);return p!==d?p-d:0}let Tc=null;function bc(e,t){let s=Tc[2*e]-Tc[2*t];return 0!==s?s:Tc[2*e+1]-Tc[2*t+1]}function Dc(e,t,s=!1){const n=e.positionsCompressed||[],i=function(e,t){const s=new Int32Array(e.length/3);for(let e=0,t=s.length;e<t;e++)s[e]=e;gc=new Int32Array(e.length);for(let s=0,n=e.length;s<n;s++)gc[s]=e[s]>>t;s.sort(Ec);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}Tc=new Int32Array(e),t.sort(bc);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 Pc=h.vec4(4),Cc=h.vec4(),_c=h.vec4(),Rc=h.vec3([1,0,0]),Bc=h.vec3([0,1,0]),Oc=h.vec3([0,0,1]);h.vec3(3),h.vec3(3);const Sc=h.identityMat4();class Nc{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=h.identityQuaternion(new Float32Array(4)),this._rotation=new Float32Array(3),this._position=new Float32Array(3),this._localMatrix=h.identityMat4(new Float32Array(16)),this._worldMatrix=h.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]),h.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]),h.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=h.identityMat4()),this._localMatrix.set(e||Sc),h.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=h.identityMat4()),h.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 Pc[0]=e[0],Pc[1]=e[1],Pc[2]=e[2],Pc[3]=t*h.DEGTORAD,h.angleAxisToQuaternion(Pc,Cc),h.mulQuaternions(this.quaternion,Cc,_c),this.quaternion=_c,this._setLocalMatrixDirty(),this._model.glRedraw(),this}rotateOnWorldAxis(e,t){return Pc[0]=e[0],Pc[1]=e[1],Pc[2]=e[2],Pc[3]=t*h.DEGTORAD,h.angleAxisToQuaternion(Pc,Cc),h.mulQuaternions(Cc,this.quaternion,Cc),this}rotateX(e){return this.rotate(Rc,e)}rotateY(e){return this.rotate(Bc,e)}rotateZ(e){return this.rotate(Oc,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)h.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 xc=h.vec3(),Lc=h.OBB3(),Mc=h.vec3([1,1,1]),Fc=h.vec3([0,0,0]),Hc=h.vec3([0,0,0]),Uc=h.identityQuaternion(),Gc=h.identityMat4(),jc=new Uint8Array([255,255,255]);class Vc extends O{constructor(e,t={}){super(e,t),this._dtxEnabled=this.scene.dtxEnabled&&!1!==t.dtxEnabled,this._enableVertexWelding=!1,this._enableIndexBucketing=!1,this._vboBatchingLayerScratchMemory=(Hn++,Fn),this._textureTranscoder=t.textureTranscoder||Ic(this.scene.viewer),this._maxGeometryBatchSize=t.maxGeometryBatchSize,this._aabb=h.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 Ns,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=h.vec3(t.origin||[0,0,0]),this._position=h.vec3(t.position||[0,0,0]),this._rotation=h.vec3(t.rotation||[0,0,0]),this._quaternion=h.vec4(t.quaternion||[0,0,0,1]),this._conjugateQuaternion=h.vec4(t.quaternion||[0,0,0,1]),t.rotation&&h.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._scale=h.vec3(t.scale||[1,1,1]),this._worldRotationMatrix=h.mat4(),this._worldRotationMatrixConjugate=h.mat4(),this._matrix=h.mat4(),this._matrixDirty=!0,this._rebuildMatrices(),this._worldNormalMatrix=h.mat4(),h.inverseMat4(this._matrix,this._worldNormalMatrix),h.transposeMat4(this._worldNormalMatrix),(t.matrix||t.position||t.rotation||t.scale||t.quaternion)&&(this._viewMatrix=h.mat4(),this._viewNormalMatrix=h.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 rc({id:"defaultColorTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new rc({id:"defaultMetalRoughTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),s=new rc({id:"defaultNormalsTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),n=new rc({id:"defaultEmissiveTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new rc({id:"defaultOcclusionTexture",texture:new mn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=s,this._textures.defaultEmissiveTexture=n,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new ic({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:s,emissiveTexture:n,occlusionTexture:i})}get isPerformanceModel(){return!0}get transforms(){return this._transforms}get textures(){return this._textures}get textureSets(){return this._textureSets}get meshes(){return this._meshes}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),h.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),h.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||Gc),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),h.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),h.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),h.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),h.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0,this._aabbDirty=!0}_transformDirty(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}_sceneModelDirty(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(let e=0,t=this._entityList.length;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&&(h.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),h.inverseMat4(this._viewMatrix,this._viewNormalMatrix),h.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&&(h.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),h.inverseMat4(this._viewMatrix,this._viewNormalMatrix),h.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),h.inverseMat4(this._viewMatrix,this._viewNormalMatrix),h.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){h.collapseAABB3(this._aabb);for(let e=0,t=this._entityList.length;e<t;e++)h.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:Si(e.aabb,h.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=Si(e.positionsDecodeBoundary,h.mat4())),e.positions){const t=h.collapseAABB3();e.positionsDecodeMatrix=h.mat4(),h.expandAABB3Points3(t,e.positions),e.positionsCompressed=Oi(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=h.collapseAABB3();e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed),h.expandAABB3Points3(t,e.positionsCompressed),St.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}else if(e.buckets){const t=h.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?h.expandAABB3Points3(t,n.positions):n.positionsCompressed&&h.expandAABB3Points3(t,n.positionsCompressed)}e.positionsDecodeMatrix&&St.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=Dt(e.positions,e.indices,null,5):e.edgeIndices=Dt(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.uv){const t=St.getUVBounds(e.uv),s=St.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 mn({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?y.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new rc({id:t,texture:l})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let s,n,i,r,a;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(s=this._textures[e.colorTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(n=this._textures[e.metallicRoughnessTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(i=this._textures[e.normalsTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(r=this._textures[e.emissiveTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(a=this._textures[e.occlusionTextureId],!a)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else a=this._textures.defaultOcclusionTexture;const o=new ic({id:t,model:this,colorTexture:s,metallicRoughnessTexture:n,normalsTexture:i,emissiveTexture:r,occlusionTexture:a});return this._textureSets[t]=o,o}createTransform(e){if(void 0===e.id||null===e.id)return void this.error("[createTransform] SceneModel.createTransform() config missing: id");if(this._transforms[e.id])return void this.error(`[createTransform] SceneModel already has a transform with this ID: ${e.id}`);let t;if(this.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const s=new Nc({id:e.id,model:this,parentTransform:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[s.id]=s,s}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._scheduledMeshes[e.id])return this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`),!1;if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;const t=!(!this._dtxEnabled||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||e.textureSetId);if(e.origin=e.origin?h.addVec3(this._origin,e.origin,h.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){const t=e.scale||Mc,s=e.position||Fc,n=e.rotation||Hc;h.eulerToQuaternion(n,"XYZ",Uc),e.meshMatrix=h.composeMat4(s,Uc,t,h.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Si(e.positionsDecodeBoundary,h.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):jc,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=h.vec3(),s=[];Q(e.positions,s,t)&&(e.positions=s,e.origin=h.addVec3(e.origin,t,t))}if(e.positions){const t=h.collapseAABB3();e.positionsDecodeMatrix=h.mat4(),h.expandAABB3Points3(t,e.positions),e.positionsCompressed=Oi(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=h.collapseAABB3();h.expandAABB3Points3(t,e.positionsCompressed),St.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=h.collapseAABB3();for(let s=0,n=e.buckets.length;s<n;s++){const n=e.buckets[s];n.positions?h.expandAABB3Points3(t,n.positions):n.positionsCompressed&&h.expandAABB3Points3(t,n.positionsCompressed)}e.positionsDecodeMatrix&&St.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}e.meshMatrix&&(h.AABB3ToOBB3(e.aabb,Lc),h.transformOBB3(e.meshMatrix,Lc),h.OBB3ToAABB3(Lc,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=Dt(e.positions,e.indices,null,2):e.edgeIndices=Dt(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=kc(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=[];Q(e.positions,t,xc)&&(e.positions=t,e.origin=h.addVec3(e.origin,xc,h.vec3()))}if(e.positions){const t=h.collapseAABB3();e.meshMatrix&&(h.transformPositions3(e.meshMatrix,e.positions,e.positions),e.meshMatrix=null),h.expandAABB3Points3(t,e.positions),e.aabb=t}else{const t=h.collapseAABB3();h.expandAABB3Points3(t,e.positionsCompressed),St.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.meshMatrix&&(h.AABB3ToOBB3(e.aabb,Lc),h.transformOBB3(e.meshMatrix,Lc),h.OBB3ToAABB3(Lc,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=Dt(e.positions,e.indices,null,2):e.edgeIndices=Dt(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?h.addVec3(this._origin,e.origin,h.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||Mc,s=e.position||Fc,n=e.rotation||Hc;h.eulerToQuaternion(n,"XYZ",Uc),e.meshMatrix=h.composeMat4(s,Uc,t,h.mat4())}h.AABB3ToOBB3(e.geometry.aabb,Lc),h.transformOBB3(e.meshMatrix,Lc),e.aabb=h.OBB3ToAABB3(Lc,h.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])]):jc,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255;let t=this._dtxBuckets[e.geometryId];t||(t=kc(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])]):jc,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 Mn(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=h.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),t}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let s=0,n=e.buckets.length;s<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 nc(this,{layerIndex:0,origin:t});break;case"lines":i=new xo(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 Wi({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 ta({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:s,maxGeometryBatchSize:this._maxGeometryBatchSize});break;case"points":a=new ka({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 Mr({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0,solid:!1});break;case"solid":a=new Mr({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0,solid:!0});break;case"lines":a=new ga({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0});break;case"points":a=new fo({model:t,textureSet:o,geometry:l,origin:s,layerIndex:0})}return this._vboInstancingLayers[r]=a,this.layerList.push(a),a}createEntity(e){if(void 0===e.id?e.id=h.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=h.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;this._visible&&!1!==e.visible&&(t|=z),this._pickable&&!1!==e.pickable&&(t|=Y),this._culled&&!1!==e.culled&&(t|=K),this._clippable&&!1!==e.clippable&&(t|=X),this._collidable&&!1!==e.collidable&&(t|=q),this._edges&&!1!==e.edges&&(t|=ee),this._xrayed&&!1!==e.xrayed&&(t|=J),this._highlighted&&!1!==e.highlighted&&(t|=Z),this._selected&&!1!==e.selected&&(t|=$),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let s=0,n=e.meshIds.length;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 ne(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!==Hn&&(Hn--,0===Hn&&Fn._clear()),super.destroy()}}function kc(e,t,s){let n,i,r,a;if(t||s?[n,i,r]=wc({positionsCompressed:e.positionsCompressed,indices:e.indices,edgeIndices:e.edgeIndices}):(n=e.positionsCompressed,i=e.indices,r=e.edgeIndices),s){a=Dc({positionsCompressed:n,indices:i,edgeIndices:r},n.length/3>65536?16:8)}else a=[{positionsCompressed:n,indices:i,edgeIndices:r}];return a}class Qc extends O{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e<t;e+=2)this._indices.push(e),this._indices.push(e+1)}this._sceneModel=new Vc(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 Wc=h.vec3(),zc=h.vec3(),Kc=h.vec3(),Yc=h.vec3();function Xc(e){return{x:e[0],y:e[1],z:e[2]}}function qc(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function Jc(e){return new Float64Array([e[0],-e[2],e[1]])}function Zc(e){return new Float64Array([e[0],e[2],-e[1]])}const $c=h.vec3(),eu=(e,t,s,n)=>{var i=e-s,r=t-n;return Math.sqrt(i*i+r*r)};class tu extends O{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._eventSubs={};var s=this.plugin.viewer.scene;this._originMarker=new ae(s,t.origin),this._targetMarker=new ae(s,t.target),this._originWorld=h.vec3(),this._targetWorld=h.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;const n=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,c=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new le(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._targetDot=new le(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._lengthWire=new oe(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._xAxisWire=new oe(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._yAxisWire=new oe(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._zAxisWire=new oe(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._lengthLabel=new ce(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._xAxisLabel=new ce(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._yAxisLabel=new ce(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._zAxisLabel=new ce(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:c,onMouseDown:r,onMouseUp:a,onMouseMove:o,onContextMenu:l}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._sectionPlanesDirty=!0,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,this._labelsVisible=!1,this._labelsOnWires=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=s.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=s.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=s.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=s.on("sectionPlaneUpdated",(()=>{this._sectionPlanesDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.labelsVisible=t.labelsVisible,this.labelsOnWires=t.labelsOnWires}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(h.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._wp))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}const t=this._originMarker.viewPos[2],s=this._targetMarker.viewPos[2];if(t>-.3||s>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){h.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var n=this._pp,i=this._cp,r=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var a=r.top-t.top,o=r.left-t.left,l=e.canvas.boundary,c=l[2],u=l[3],p=0;const s=this.plugin.viewer.scene.metrics,f=s.scale,I=s.units,m=s.unitsInfo[I].abbrev;for(var d=0,A=n.length;d<A;d+=4)i[p]=o+Math.floor((1+n[d+0]/n[d+3])*c/2),i[p+1]=a+Math.floor((1-n[d+1]/n[d+3])*u/2),p+=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(h.lenVec3(h.subVec3(this._targetWorld,this._originWorld,$c))),this._lengthLabel.setText(e+(this._length*f).toFixed(2)+m);const t=Math.abs(eu(i[0],i[1],i[2],i[3])),s=Math.abs(eu(i[2],i[3],i[4],i[5])),n=Math.abs(eu(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(h.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 su extends O{get active(){}set snapping(e){}get snapping(){return!0}activate(){}deactivate(){}reset(){}destroy(){}}class nu extends su{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=h.vec3(),a=h.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:h.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 iu{constructor(){}getMetaModel(e,t,s){y.loadJSON(e,(e=>{t(e)}),(function(e){s(e)}))}getGLTF(e,t,s){y.loadArraybuffer(e,(e=>{t(e)}),(function(e){s(e)}))}getGLB(e,t,s){y.loadArraybuffer(e,(e=>{t(e)}),(function(e){s(e)}))}getArrayBuffer(e,t,s,n){!function(e,t,s,n){var i=()=>{};s=s||i,n=n||i;const r=/^data:(.*?)(;base64)?,(.*)$/,a=t.match(r);if(a){const e=!!a[2];var o=a[3];o=window.decodeURIComponent(o),e&&(o=window.atob(o));try{const e=new ArrayBuffer(o.length),t=new Uint8Array(e);for(var l=0;l<o.length;l++)t[l]=o.charCodeAt(l);C.scheduleTask((function(){s(e)}))}catch(e){C.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 ru{constructor(e={}){this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=e.messages,this.locale=e.locale}set messages(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}loadMessages(e={}){for(let t in e)this._messages[t]=e[t];this.messages=this._messages}clearMessages(){this.messages={}}get locales(){return this._locales}set locale(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}get locale(){return this._locale}translate(e,t){const s=this._messages[this._locale];if(!s)return null;const n=au(e,s);return n?t?ou(n,t):n:null}translatePlurals(e,t,s){const n=this._messages[this._locale];if(!n)return null;let i=au(e,n);return i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one,i?(i=ou(i,[t]),s&&(i=ou(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const r=this._events[t];return void 0!==r&&s(r),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function au(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&e<t;e++){n=n[s[e]]}return n}function ou(e,t=[]){return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,s){return"{{"===e?"{":"}}"===e?"}":t[s]}))}class lu extends O{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=h.subVec3(r,i,[]);return h.normalizeVec3(a,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,s,n=[],i=this.getPoint(0),r=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),r+=h.lenVec3(h.subVec3(t,i,[])),n.push(r),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,r=n.length;s=t||e*n[r-1];for(var a,o=0,l=r-1;o<=l;)if((a=n[i=Math.floor(o+(l-o)/2)]-s)<0)o=i+1;else{if(!(a>0)){l=i;break}l=i-1}if(n[i=l]===s)return i/(r-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(r-1)}}class cu extends lu{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var s=(t.length-1)*e,n=Math.floor(s),i=s-n,r=t[0===n?n:n-1],a=t[n],o=t[n>t.length-2?t.length-1:n+1],l=t[n>t.length-3?t.length-1:n+2],c=h.vec3();return c[0]=h.catmullRomInterpolate(r[0],a[0],o[0],l[0],i),c[1]=h.catmullRomInterpolate(r[1],a[1],o[1],l[1],i),c[2]=h.catmullRomInterpolate(r[2],a[2],o[2],l[2],i),c}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const uu=h.vec3();const hu=h.vec3(),pu=h.vec3(),du=h.vec3(),Au=h.vec3(),fu=h.vec3();class Iu extends O{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=h.vec3(),this._eye1=h.vec3(),this._up1=h.vec3(),this._look2=h.vec3(),this._eye2=h.vec3(),this._up2=h.vec3(),this._orthoScale1=1,this._orthoScale2=1,this._flying=!1,this._flyEyeLookUp=!1,this._flyingEye=!1,this._flyingLook=!1,this._callback=null,this._callbackScope=null,this._time1=null,this._time2=null,this.easing=!1!==t.easing,this.duration=t.duration,this.fit=t.fit,this.fitFOV=t.fitFOV,this.trail=t.trail}flyTo(e,t,s){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=s;const n=this.scene.camera,i=!!e.projection&&e.projection!==n.projection;let r,a,o,l,c;if(this._eye1[0]=n.eye[0],this._eye1[1]=n.eye[1],this._eye1[2]=n.eye[2],this._look1[0]=n.look[0],this._look1[1]=n.look[1],this._look1[2]=n.look[2],this._up1[0]=n.up[0],this._up1[1]=n.up[1],this._up1[2]=n.up[2],this._orthoScale1=n.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)a=e.eye,o=e.look,l=e.up;else if(e.eye)a=e.eye;else if(e.look)o=e.look;else{let n=e;if((y.isNumeric(n)||y.isString(n))&&(c=n,n=this.scene.components[c],!n))return this.error("Component not found: "+y.inQuotes(c)),void(t&&(s?t.call(s):t()));i||(r=n.aabb||this.scene.aabb)}const u=e.poi;if(r){if(r[3]<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=h.getAABB3Center(r);this._look2=u||t;const s=h.subVec3(this._eye1,this._look1,hu),n=h.normalizeVec3(s),i=u?h.getAABB3DiagPoint(r,u):h.getAABB3Diag(r),a=e.fitFOV||this._fitFOV,o=Math.abs(i/Math.tan(a*h.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,C.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((y.isNumeric(t)||y.isString(t))&&(n=t,t=this.scene.components[n],!t))return void this.error("Component not found: "+y.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?h.getAABB3DiagPoint(s,o):h.getAABB3Diag(s);let n;r=o||h.getAABB3Center(s,r),this._trail?h.subVec3(t.look,r,fu):h.subVec3(t.eye,t.look,fu),h.normalizeVec3(fu);n=(void 0!==e.fit?e.fit:this._fit)?Math.abs(l/Math.tan((e.fitFOV||this._fitFOV)*h.DEGTORAD)):h.lenVec3(h.subVec3(t.eye,t.look,hu)),h.mulVec3Scalar(fu,n),t.eye=h.addVec3(r,fu,hu),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?Iu._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(h.subVec3(n.eye,n.look,fu),n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,du),n.look=h.subVec3(du,fu,pu)):this._flyingLook&&(n.look=h.lerpVec3(s,0,1,this._look1,this._look2,pu),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,Au)):this._flyingEyeLookUp&&(n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,du),n.look=h.lerpVec3(s,0,1,this._look1,this._look2,pu),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,Au)),this._projection2){const t="ortho"===this._projection2?Iu._easeOutExpo(e,0,1,1):Iu._easeInCubic(e,0,1,1);n.customProjection.matrix=h.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();C.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class mu extends O{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new Iu(this),this._t=0,this.state=mu.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case mu.SCRUBBING:return;case mu.PLAYING:if(this._t+=this._playingRate*i,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=mu.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case mu.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=mu.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=mu.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=mu.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=mu.SCRUBBING,this._cameraFlightAnimation.flyTo(n,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=mu.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=mu.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=mu.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}mu.STOPPED=0,mu.SCRUBBING=1,mu.PLAYING=2,mu.PLAYING_TO=3;const yu=h.vec3(),vu=h.vec3();h.vec3();const wu=h.vec3([0,-1,0]),gu=h.vec4([0,0,0,1]);function Eu(e){if(!Tu(e.width)||!Tu(e.height)){const t=document.createElement("canvas");t.width=bu(e.width),t.height=bu(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Tu(e){return 0==(e&e-1)}function bu(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Du extends O{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new $e({texture:new mn({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),A.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let r=0;r<e.length;r++){const a=new Image;a.onload=function(){let e=a;const o=r;return function(){if(!n&&(e=Eu(e),t._images[o]=e,i++,6===i)){let e=t._state.texture;e||(e=new mn({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(),A.memory.textures--,this._state.destroy()}}class Pu{constructor(e){this._eye=h.vec3(),this._look=h.vec3(),this._up=h.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 Cu=h.vec3();const _u=h.vec3();class Ru{constructor(){this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}saveObjects(e,t){this.numObjects=0,this._mask=t?y.apply(t,{}):null;const s=e.objects,n=!t||t.visible,i=!t||t.edges,r=!t||t.xrayed,a=!t||t.highlighted,o=!t||t.selected,l=!t||t.clippable,c=!t||t.pickable,u=!t||t.colorize,h=!t||t.opacity;for(let e in s)if(s.hasOwnProperty(e)){const t=s[e],p=this.numObjects;if(n&&(this.objectsVisible[p]=t.visible),i&&(this.objectsEdges[p]=t.edges),r&&(this.objectsXrayed[p]=t.xrayed),a&&(this.objectsHighlighted[p]=t.highlighted),o&&(this.objectsSelected[p]=t.selected),l&&(this.objectsClippable[p]=t.clippable),c&&(this.objectsPickable[p]=t.pickable),u){const e=t.colorize;e?(this.objectsColorize[3*p+0]=e[0],this.objectsColorize[3*p+1]=e[1],this.objectsColorize[3*p+2]=e[2],this.objectsHasColorize[p]=!0):this.objectsHasColorize[p]=!1}h&&(this.objectsOpacity[p]=t.opacity),this.numObjects++}}restoreObjects(e){const t=this._mask,s=!t||t.visible,n=!t||t.edges,i=!t||t.xrayed,r=!t||t.highlighted,a=!t||t.selected,o=!t||t.clippable,l=!t||t.pickable,c=!t||t.colorize,u=!t||t.opacity;var h=0;const p=e.objects;for(let e in p)if(p.hasOwnProperty(e)){const t=p[e];s&&(t.visible=this.objectsVisible[h]),n&&(t.edges=this.objectsEdges[h]),i&&(t.xrayed=this.objectsXrayed[h]),r&&(t.highlighted=this.objectsHighlighted[h]),a&&(t.selected=this.objectsSelected[h]),o&&(t.clippable=this.objectsClippable[h]),l&&(t.pickable=this.objectsPickable[h]),c&&(this.objectsHasColorize[h]?(_u[0]=this.objectsColorize[3*h+0],_u[1]=this.objectsColorize[3*h+1],_u[2]=this.objectsColorize[3*h+2],t.colorize=_u):t.colorize=null),u&&(t.opacity=this.objectsOpacity[h]),h++}}}class Bu extends O{constructor(e,t={}){super(e,t),this._skyboxMesh=new Qs(this,{geometry:new Lt(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new Gt(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Tn(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}const Ou=h.vec4(),Su=h.vec4(),Nu=h.vec3(),xu=h.vec3(),Lu=h.vec3(),Mu=h.vec4(),Fu=h.vec4(),Hu=h.vec4();class Uu{constructor(e){this._scene=e}dollyToCanvasPos(e,t,s){let n=!1;const i=this._scene.camera;if(e){const t=h.subVec3(e,i.eye,Nu);n=h.lenVec3(t)<s}if("perspective"===i.projection){i.ortho.scale=i.ortho.scale-s;const n=this._unproject(t,Mu),r=h.subVec3(n,i.eye,Hu),a=h.mulVec3Scalar(h.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=h.subVec3(e,i.eye,Nu),s=h.lenVec3(t),n=h.mulVec3Scalar(h.normalizeVec3(h.subVec3(i.look,i.eye,xu)),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,Mu);i.ortho.scale=i.ortho.scale-s,i.ortho._update();const n=this._unproject(t,Fu),r=h.subVec3(n,e,Hu),a=h.mulVec3Scalar(h.normalizeVec3(h.subVec3(i.look,i.eye,Nu)),-s,xu),o=h.addVec3(r,a,Lu);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=h.dotVec4(a,i)/h.dotVec4(a,r);return s.project.unproject(e,o,Ou,Su,t),t}destroy(){}}const Gu=h.vec3(),ju=h.vec3(),Vu=h.vec3(),ku=h.vec4(),Qu=h.vec4(),Wu=h.vec4();class zu{constructor(e,t){this._scene=e,this._configs=t,this._pivotWorldPos=h.vec3(),this._cameraOffset=h.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=h.vec3(),this._rtcPos=h.vec3(),this._pivotViewPos=h.vec4(),this._pivotProjPos=h.vec4(),this._pivotCanvasPos=h.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=h.vec3();h.decomposeMat4(h.inverseMat4(this._scene.viewer.camera.viewMatrix,h.mat4()),t,h.vec4(),h.vec3());const s=h.distVec3(t,e);let n=Math.tan(Math.PI/500)*s*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(n/=this._scene.camera.ortho.scale/2),k(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Pn(this._scene,Ks({radius:n})),this._pivotSphere=new Qs(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){h.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,h.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const s=t.boundary,n=s[2],i=s[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*n/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);let r=t._lastBoundingClientRect;if(!r||t._canvasSizeChanged){const e=t.canvas;r=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(r.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(r.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(k(this.getPivotPos(),this._rtcCenter,this._rtcPos),h.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new Gt(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=h.lookAtMat4v(e.eye,e.look,e.worldUp);h.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const s=this.getPivotPos();this._cameraOffset[2]+=h.distVec3(e.eye,s),t=h.inverseMat4(t);const n=h.transformVec3(t,this._cameraOffset),i=h.vec3();if(h.subVec3(e.eye,s,i),h.addVec3(i,n),e.zUp){const e=i[1];i[1]=i[2],i[2]=e}this._radius=h.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=h.normalizeVec3(h.subVec3(e.look,e.eye,Gu)),s=h.cross3Vec3(t,e.worldUp,ju);return h.sqLenVec3(s)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,s=Math.abs(h.distVec3(this._scene.center,t.eye)),n=t.project.transposedMatrix,i=n.subarray(8,12),r=n.subarray(12),a=[0,0,-1,1],o=h.dotVec4(a,i)/h.dotVec4(a,r),l=ku;t.project.unproject(e,o,Qu,Wu,l);const c=h.normalizeVec3(h.subVec3(l,t.eye,Gu)),u=h.addVec3(t.eye,h.mulVec3Scalar(c,s,ju),Vu);this.setPivotPos(u)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const s=this._scene.camera;var n=-e;const i=-t;1===s.worldUp[2]&&(n=-n),this._azimuth+=.01*-n,this._polar+=.01*i,this._polar=h.clamp(this._polar,.001,Math.PI-.001);const r=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===s.worldUp[2]){const e=r[1];r[1]=r[2],r[2]=e}const a=h.lenVec3(h.subVec3(s.look,s.eye,h.vec3())),o=this.getPivotPos();h.addVec3(r,o);let l=h.lookAtMat4v(r,o,s.worldUp);l=h.inverseMat4(l);const c=h.transformVec3(l,this._cameraOffset);l[12]-=c[0],l[13]-=c[1],l[14]-=c[2];const u=[l[8],l[9],l[10]];s.eye=[l[12],l[13],l[14]],h.subVec3(s.eye,h.mulVec3Scalar(u,a),s.look),s.up=[l[4],l[5],l[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class Ku{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=h.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;const e=`${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;if(this._lastHash===e)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;const t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&(e.snappedToEdge||e.snappedToVertex)?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const e=this.pickResult.canvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new De;e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}const Yu=h.vec2();class Xu{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController;let a,o,l,c=0,u=0,p=0,d=0,A=!1;const f=h.vec3();let I=!0;const m=this._scene.canvas.canvas,y=[];function v(e=!0){m.style.cursor="move",c=n.pointerCanvasPos[0],u=n.pointerCanvasPos[1],p=n.pointerCanvasPos[0],d=n.pointerCanvasPos[1],e&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),r.picked&&r.pickedSurface&&r.pickResult&&r.pickResult.worldPos?(A=!0,f.set(r.pickResult.worldPos)):A=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;y[n]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;y[n]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:y[e.input.KEY_SHIFT]||s.planView?(a=!0,v()):(a=!0,v(!1));break;case 2:o=!0,v();break;case 3:l=!0,s.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=()=>{if(!s.active||!s.pointerEnabled)return;if(!a&&!o&&!l)return;const t=e.canvas.boundary,r=t[2],p=t[3],d=n.pointerCanvasPos[0],I=n.pointerCanvasPos[1];if(y[e.input.KEY_SHIFT]||s.planView||!s.panRightClick&&o||s.panRightClick&&l){const t=d-c,s=I-u,n=e.camera;if("perspective"===n.projection){const r=Math.abs(A?h.lenVec3(h.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=1.5*t*r/p,i.panDeltaY+=1.5*s*r/p}else i.panDeltaX+=.5*n.ortho.scale*(t/p),i.panDeltaY+=.5*n.ortho.scale*(s/p)}else!a||o||l||s.planView||(s.firstPerson?(i.rotateDeltaY-=(d-c)/r*s.dragRotationRate/2,i.rotateDeltaX+=(I-u)/p*(s.dragRotationRate/4)):(i.rotateDeltaY-=(d-c)/r*(1.5*s.dragRotationRate),i.rotateDeltaX+=(I-u)/p*(1.5*s.dragRotationRate)));c=d,u=I}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{s.active&&s.pointerEnabled&&n.mouseover&&(I=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(s.active&&s.pointerEnabled)switch(e.which){case 1:case 2:case 3:a=!1,o=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(s.active&&s.pointerEnabled){if(3===e.which){!function(e,t){if(e){let s=e.target,n=0,i=0,r=0,a=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,r+=s.scrollLeft,a+=s.scrollTop,s=s.offsetParent;t[0]=e.pageX+r-n,t[1]=e.pageY+a-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Yu);const s=Yu[0],n=Yu[1];Math.abs(s-p)<3&&Math.abs(n-d)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Yu,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{s.active&&s.pointerEnabled});const w=1/60;let g=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=performance.now()/1e3;var r=null!==g?t-g:0;g=t,r>.05&&(r=.05),r<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 qu=h.vec3(),Ju=h.vec3(),Zu=h.vec3(),$u=h.vec3(),eh=h.vec3(),th={eye:h.vec3(),look:h.vec3(),up:h.vec3()};class sh{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),p=i._isKeyDownForAction(i.AXIS_VIEW_BOTTOM);if(!(a||o||l||c||u||p))return;const d=e.aabb,A=h.getAABB3Diag(d);h.getAABB3Center(d,qu);const f=Math.abs(A/Math.tan(t.cameraFlight.fitFOV*h.DEGTORAD)),I=1.1*A;th.orthoScale=I,a?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldRight,f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):o?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldForward,f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):l?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldRight,-f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):c?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldForward,-f,Ju),eh)),th.look.set(qu),th.up.set(r.worldUp)):u?(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldUp,f,Ju),eh)),th.look.set(qu),th.up.set(h.normalizeVec3(h.mulVec3Scalar(r.worldForward,1,Zu),$u))):p&&(th.eye.set(h.addVec3(qu,h.mulVec3Scalar(r.worldUp,-f,Ju),eh)),th.look.set(qu),th.up.set(h.normalizeVec3(h.mulVec3Scalar(r.worldForward,-1,Zu)))),!s.firstPerson&&s.followPointer&&t.pivotController.setPivotPos(qu),t.cameraFlight.duration>0?t.cameraFlight.flyTo(th,(()=>{t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(th),t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class nh{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.pivotController,o=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,c=!1;const u=this._scene.canvas.canvas,p=s=>{let n;s&&s.worldPos&&(n=s.worldPos);const i=s&&s.entity?s.entity.aabb:e.aabb;if(n){const s=e.camera;h.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})},d=e.tickify(this._canvasMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(l||c)return;const i=o.hasSubs("hover"),a=o.hasSubs("hoverEnter"),u=o.hasSubs("hoverOut"),h=o.hasSubs("hoverOff"),p=o.hasSubs("hoverSurface"),d=o.hasSubs("hoverSnapOrSurface");if(i||a||u||h||p||d)if(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=!0,r.schedulePickSurface=p,r.scheduleSnapOrPick=d,r.update(),r.pickResult){if(r.pickResult.entity){const t=r.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),o.fire("hoverEnter",r.pickResult,!0),this._lastPickedEntityId=t)}o.fire("hover",r.pickResult,!0),(r.pickResult.worldPos||r.pickResult.snappedWorldPos)&&o.fire("hoverSurface",r.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),o.fire("hoverOff",{canvasPos:r.pickCursorPos},!0)});u.addEventListener("mousemove",d),u.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(c=!0);if(1===t.which&&s.active&&s.pointerEnabled&&(n.mouseDownClientX=t.clientX,n.mouseDownClientY=t.clientY,n.mouseDownCursorX=n.pointerCanvasPos[0],n.mouseDownCursorY=n.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),1===t.which))){const t=r.pickResult;t&&t.worldPos?(a.setPivotPos(t.worldPos),a.startPivot()):(s.smartPivot?a.setCanvasPivotPos(n.pointerCanvasPos):a.setPivotPos(e.camera.look),a.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(c=!1),a.getPivoting()&&a.endPivot()}),u.addEventListener("mouseup",this._canvasMouseUpHandler=i=>{if(!s.active||!s.pointerEnabled)return;if(!(1===i.which))return;if(a.hidePivot(),Math.abs(i.clientX-n.mouseDownClientX)>3||Math.abs(i.clientY-n.mouseDownClientY)>3)return;const l=o.hasSubs("picked"),c=o.hasSubs("pickedNothing"),u=o.hasSubs("pickedSurface"),d=o.hasSubs("doublePicked"),A=o.hasSubs("doublePickedSurface"),f=o.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||d||A||f))return(l||c||u)&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=!0,r.schedulePickSurface=u,r.update(),r.pickResult?(o.fire("picked",r.pickResult,!0),r.pickedSurface&&o.fire("pickedSurface",r.pickResult,!0)):o.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=s.doublePickFlyTo,r.schedulePickSurface=u,r.update();const e=r.pickResult,i=r.pickedSurface;this._timeout=setTimeout((()=>{e?(o.fire("picked",e,!0),i&&(o.fire("pickedSurface",e,!0),!s.firstPerson&&s.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):o.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0),this._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),r.pickCursorPos=n.pointerCanvasPos,r.schedulePickEntity=s.doublePickFlyTo||d||A,r.schedulePickSurface=r.schedulePickEntity&&A,r.update(),r.pickResult){if(o.fire("doublePicked",r.pickResult,!0),r.pickedSurface&&o.fire("doublePickedSurface",r.pickResult,!0),s.doublePickFlyTo&&(p(r.pickResult),!s.firstPerson&&s.followPointer)){const e=r.pickResult.entity.aabb,s=h.getAABB3Center(e);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(o.fire("doublePickedNothing",{canvasPos:n.pointerCanvasPos},!0),s.doublePickFlyTo&&(p(),!s.firstPerson&&s.followPointer)){const s=e.aabb,n=h.getAABB3Center(s);t.pivotController.setPivotPos(n),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class ih{constructor(e,t,s,n,i){this._scene=e;const r=e.input,a=[],o=e.canvas.canvas;let l=!0;this._onSceneMouseMove=r.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=r.on("keydown",(t=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&n.mouseover&&(a[t]=!0,t===r.KEY_SHIFT&&(o.style.cursor="move"))})),this._onSceneKeyUp=r.on("keyup",(n=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(a[n]=!1,n===r.KEY_SHIFT&&(o.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(o=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const c=t.cameraControl,u=o.deltaTime/1e3;if(!s.planView){const e=c._isKeyDownForAction(c.ROTATE_Y_POS,a),n=c._isKeyDownForAction(c.ROTATE_Y_NEG,a),r=c._isKeyDownForAction(c.ROTATE_X_POS,a),o=c._isKeyDownForAction(c.ROTATE_X_NEG,a),l=u*s.keyboardRotationRate;(e||n||r||o)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),e?i.rotateDeltaY+=l:n&&(i.rotateDeltaY-=l),r?i.rotateDeltaX+=l:o&&(i.rotateDeltaX-=l),!s.firstPerson&&s.followPointer&&t.pivotController.startPivot())}if(!a[r.KEY_CTRL]&&!a[r.KEY_ALT]){const e=c._isKeyDownForAction(c.DOLLY_BACKWARDS,a),r=c._isKeyDownForAction(c.DOLLY_FORWARDS,a);if(e||r){const a=u*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),r?i.dollyDelta-=a:e&&(i.dollyDelta+=a),l&&(n.followPointerDirty=!0,l=!1)}}const h=c._isKeyDownForAction(c.PAN_FORWARDS,a),p=c._isKeyDownForAction(c.PAN_BACKWARDS,a),d=c._isKeyDownForAction(c.PAN_LEFT,a),A=c._isKeyDownForAction(c.PAN_RIGHT,a),f=c._isKeyDownForAction(c.PAN_UP,a),I=c._isKeyDownForAction(c.PAN_DOWN,a),m=(a[r.KEY_ALT]?.3:1)*u*s.keyboardPanRate;(h||p||d||A||f||I)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),I?i.panDeltaY+=m:f&&(i.panDeltaY+=-m),A?i.panDeltaX+=-m:d&&(i.panDeltaX+=m),p?i.panDeltaZ+=m:h&&(i.panDeltaZ+=-m))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const rh=h.vec3();class ah{constructor(e,t,s,n,i){this._scene=e;const r=e.camera,a=t.pickController,o=t.pivotController,l=t.panController;let c=1,u=1,p=null;this._onTick=e.on("tick",(()=>{if(!s.active||!s.pointerEnabled)return;let t="default";if(Math.abs(i.dollyDelta)<.001&&(i.dollyDelta=0),Math.abs(i.rotateDeltaX)<.001&&(i.rotateDeltaX=0),Math.abs(i.rotateDeltaY)<.001&&(i.rotateDeltaY=0),0===i.rotateDeltaX&&0===i.rotateDeltaY||(i.dollyDelta=0),s.followPointer&&--c<=0&&(c=1,0!==i.dollyDelta)){if(0===i.rotateDeltaY&&0===i.rotateDeltaX&&s.followPointer&&n.followPointerDirty&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.pickResult&&a.pickResult.worldPos?p=a.pickResult.worldPos:(u=1,p=null),n.followPointerDirty=!1),p){const t=Math.abs(h.lenVec3(h.subVec3(p,e.camera.eye,rh)));u=t/s.dollyProximityThreshold}u<s.dollyMinSpeed&&(u=s.dollyMinSpeed)}const d=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=h.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!==d){if(t=d<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(p,n.pointerCanvasPos,-d)&&(n.followPointerDirty=!0)}else r.pan([0,0,d]),r.ortho.scale=r.ortho.scale-d;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(p,n.pointerCanvasPos,-d)&&(n.followPointerDirty=!0)}else r.ortho.scale=r.ortho.scale+d,r.zoom(d);else if(s.followPointer){l.dollyToCanvasPos(p,n.pointerCanvasPos,-d)&&(n.followPointerDirty=!0)}else r.ortho.scale=r.ortho.scale+d,r.zoom(d);i.dollyDelta*=s.dollyInertia}a.fireEvents(),document.body.style.cursor=t}))}destroy(){this._scene.off(this._onTick)}}class oh{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=>{lh(e,r,n.pointerCanvasPos)}),r.addEventListener("mousedown",this._mouseDownHandler=e=>{s.active&&s.pointerEnabled&&(lh(e,r,n.pointerCanvasPos),n.mouseover=!0)}),r.addEventListener("mouseup",this._mouseUpHandler=e=>{s.active&&s.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function lh(e,t,s){if(e){const{x:n,y:i}=t.getBoundingClientRect();s[0]=e.clientX-n,s[1]=e.clientY-i}else e=window.event,s[0]=e.x,s[1]=e.y;return s}const ch=function(e,t){if(e){let s=e.target,n=0,i=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,s=s.offsetParent;t[0]=e.pageX-n,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class uh{constructor(e,t,s,n,i){this._scene=e;const r=t.pickController,a=t.pivotController,o=h.vec2(),l=h.vec2(),c=h.vec2(),u=h.vec2(),p=[],d=this._scene.canvas.canvas;let A=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),d.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!s.active||!s.pointerEnabled)return;t.preventDefault();const i=t.touches,l=t.changedTouches;for(n.touchStartTime=Date.now(),1===i.length&&1===l.length&&(ch(i[0],o),s.followPointer&&(r.pickCursorPos=o,r.schedulePickSurface=!0,r.update(),s.planView||(r.picked&&r.pickedSurface&&r.pickResult&&r.pickResult.worldPos?(a.setPivotPos(r.pickResult.worldPos),!s.firstPerson&&a.startPivot()&&a.showPivot()):(s.smartPivot?a.setCanvasPivotPos(n.pointerCanvasPos):a.setPivotPos(e.camera.look),!s.firstPerson&&a.startPivot()&&a.showPivot()))));p.length<i.length;)p.push(h.vec2());for(let e=0,t=i.length;e<t;++e)ch(i[e],p[e]);A=i.length}),d.addEventListener("touchend",this._canvasTouchEndHandler=()=>{a.getPivoting()&&a.endPivot()}),d.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const a=e.canvas.boundary,o=a[2],d=a[3],I=t.touches;if(t.touches.length===A){if(1===A){ch(I[0],l),h.subVec2(l,p[0],u);const t=u[0],r=u[1];if(null!==n.longTouchTimeout&&(Math.abs(t)>s.longTapRadius||Math.abs(r)>s.longTapRadius)&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),s.planView){const n=e.camera;if("perspective"===n.projection){const a=Math.abs(e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=t*a/d*s.touchPanRate,i.panDeltaY+=r*a/d*s.touchPanRate}else i.panDeltaX+=.5*n.ortho.scale*(t/d)*s.touchPanRate,i.panDeltaY+=.5*n.ortho.scale*(r/d)*s.touchPanRate}else i.rotateDeltaY-=t/o*(1*s.dragRotationRate),i.rotateDeltaX+=r/d*(1.5*s.dragRotationRate)}else if(2===A){const t=I[0],a=I[1];ch(t,l),ch(a,c);const o=h.geometricMeanVec2(p[0],p[1]),u=h.geometricMeanVec2(l,c),A=h.vec2();h.subVec2(o,u,A);const f=A[0],m=A[1],y=e.camera,v=h.distVec2([t.pageX,t.pageY],[a.pageX,a.pageY]),w=(h.distVec2(p[0],p[1])-v)*s.touchDollyRate;if(i.dollyDelta=w,Math.abs(w)<1)if("perspective"===y.projection){const t=r.pickResult?r.pickResult.worldPos:e.center,n=Math.abs(h.lenVec3(h.subVec3(t,e.camera.eye,[])))*Math.tan(y.perspective.fov/2*Math.PI/180);i.panDeltaX-=f*n/d*s.touchPanRate,i.panDeltaY-=m*n/d*s.touchPanRate}else i.panDeltaX-=.5*y.ortho.scale*(f/d)*s.touchPanRate,i.panDeltaY-=.5*y.ortho.scale*(m/d)*s.touchPanRate;n.pointerCanvasPos=u}for(let e=0;e<A;++e)ch(I[e],p[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 hh=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 ph{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,p=-1;const d=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;h.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};d.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!s.active||!s.pointerEnabled)return;null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null);const i=e.touches,r=e.changedTouches;if(o=Date.now(),1===i.length&&1===r.length){u=o,hh(i[0],c);const r=c[0],a=c[1],l=i[0].pageX,h=i[0].pageY;n.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(h)],canvasPos:[Math.round(r),Math.round(a)],event:e},!0),n.longTouchTimeout=null}),s.longTapTimeout)}else u=-1;for(;l.length<i.length;)l.push(new Float32Array(2));for(let e=0,t=i.length;e<t;++e)hh(i[e],l[e]);l.length=i.length},{passive:!0}),d.addEventListener("touchend",this._canvasTouchEndHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=Date.now(),i=e.touches,o=e.changedTouches,d=a.hasSubs("pickedSurface");null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),0===i.length&&1===o.length&&u>-1&&t-u<150&&(p>-1&&u-p<325?(hh(o[0],r.pickCursorPos),r.schedulePickEntity=!0,r.schedulePickSurface=d,r.update(),r.pickResult?(r.pickResult.touchInput=!0,a.fire("doublePicked",r.pickResult),r.pickedSurface&&a.fire("doublePickedSurface",r.pickResult),s.doublePickFlyTo&&A(r.pickResult)):(a.fire("doublePickedNothing"),s.doublePickFlyTo&&A()),p=-1):h.distVec2(l[0],c)<4&&(hh(o[0],r.pickCursorPos),r.schedulePickEntity=!0,r.schedulePickSurface=d,r.update(),r.pickResult?(r.pickResult.touchInput=!0,a.fire("picked",r.pickResult),r.pickedSurface&&a.fire("pickedSurface",r.pickResult)):a.fire("pickedNothing"),p=t),u=-1),l.length=i.length;for(let e=0,t=i.length;e<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 dh extends O{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:h.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:h.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const s=this.scene;this._controllers={cameraControl:this,pickController:new Ku(this,this._configs),pivotController:new zu(s,this._configs),panController:new Uu(s),cameraFlight:new Iu(this,{duration:.5})},this._handlers=[new oh(this.scene,this._controllers,this._configs,this._states,this._updates),new uh(this.scene,this._controllers,this._configs,this._states,this._updates),new Xu(this.scene,this._controllers,this._configs,this._states,this._updates),new sh(this.scene,this._controllers,this._configs,this._states,this._updates),new nh(this.scene,this._controllers,this._configs,this._states,this._updates),new ph(this.scene,this._controllers,this._configs,this._states,this._updates),new ih(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new ah(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",y.isString(e)){const t=this.scene.input,s={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":s[this.PAN_LEFT]=[t.KEY_A],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_Z],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":s[this.PAN_LEFT]=[t.KEY_Q],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_W],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=s}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const s=this._keyMap[e];if(!s)return!1;t||(t=this.scene.input.keyDown);for(let e=0,n=s.length;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 Ah{constructor(e,t,s,n,i){this.name=e,this.type=s,this.value=t,this.valueType=n,this.description=i}}class fh{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 Ah(s.name,s.value,s.type,s.valueType,s.description))}}}}class Ih{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 mh{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 fh({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 Ih({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=h.globalizeObjectId(this.id,n.id),n.parent&&(n.parent=h.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(h.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=h.globalizeObjectId(this.id,n.id))}}}class yh{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 mh({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?vh(t):null,a=s&&s.length>0?vh(s):null,o=e=>{if(!e)return;var t=!0;(a&&a[e.type]||r&&!r[e.type])&&(t=!1),t&&n.push(e.id);const s=e.children;if(s)for(var i=0,l=s.length;i<l;i++)o(s[i])};return o(i),n}withMetaObjectsInSubtree(e,t){const s=this.metaObjects[e];s&&s.withMetaObjectsInSubtree(t)}}function vh(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>