@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 @@ var e,t=s().mark(HT),n=s().mark(UT),r=s().mark(qP);function i(e,t){var n=Object.
14
14
  /**
15
15
  * @author https://github.com/tmarti, with support from https://tribia.com/
16
16
  * @license MIT
17
- **/var xf=null;function Mf(e,t){var n,r,i,a,s,o,l=3*e,u=3*t,c=Math.min(n=xf[l],r=xf[l+1],i=xf[l+2]),f=Math.min(a=xf[u],s=xf[u+1],o=xf[u+2]);if(c!==f)return c-f;var p=Math.max(n,r,i),A=Math.max(a,s,o);return p!==A?p-A:0}function Ff(e,t){for(var n=new Int32Array(e.length/3),r=0,i=n.length;r<i;r++)n[r]=r;xf=new Int32Array(e.length);for(var a=0,s=e.length;a<s;a++)xf[a]=e[a]>>t;n.sort(Mf);for(var o=new Int32Array(e.length),l=0,u=n.length;l<u;l++)o[3*l+0]=e[3*n[l]+0],o[3*l+1]=e[3*n[l]+1],o[3*l+2]=e[3*n[l]+2];return o}var Hf=null;function Uf(e,t){var n=Hf[2*e]-Hf[2*t];return 0!==n?n:Hf[2*e+1]-Hf[2*t+1]}function Gf(e){if(0===(e||[]).length)return[];for(var t=new Int32Array(e.length/2),n=0,r=t.length;n<r;n++)t[n]=n;for(var i=0,a=e.length;i<a;i+=2)if(e[i]>e[i+1]){var s=e[i];e[i]=e[i+1],e[i+1]=s}Hf=new Int32Array(e),t.sort(Uf);for(var o=new Int32Array(e.length),l=0,u=t.length;l<u;l++)o[2*l+0]=e[2*t[l]+0],o[2*l+1]=e[2*t[l]+1];return o}function kf(e,t){var n={},r={};e.forEach((function(e){for(var t=e.indices,i=e.edgeIndices,a=e.positionsCompressed,s=0,o=t.length;s<o;s+=3){var l=a[3*t[s]]+"_"+a[3*t[s]+1]+"_"+a[3*t[s]+2]+"/"+a[3*t[s+1]]+"_"+a[3*t[s+1]+1]+"_"+a[3*t[s+1]+2]+"/"+a[3*t[s+2]]+"_"+a[3*t[s+2]+1]+"_"+a[3*t[s+2]+2];n[l]=!0}e.edgeIndices.length/2;for(var u=0,c=i.length;u<c;u+=2){var f=a[3*i[u]]+"_"+a[3*i[u]+1]+"_"+a[3*i[u]+2]+"/"+a[3*i[u+1]]+"_"+a[3*i[u+1]+1]+"_"+a[3*i[u+1]+2]+"/";r[f]=!0}}));var i=t.indices;t.edgeIndices;for(var a=t.positionsCompressed,s=0,o=i.length;s<o;s+=3){var l=a[3*i[s]]+"_"+a[3*i[s]+1]+"_"+a[3*i[s]+2]+"/"+a[3*i[s+1]]+"_"+a[3*i[s+1]+1]+"_"+a[3*i[s+1]+2]+"/"+a[3*i[s+2]]+"_"+a[3*i[s+2]+1]+"_"+a[3*i[s+2]+2];if(!(l in n))throw console.log("Not found "+l),"Ohhhh!"}}var jf=$.vec4(4),Vf=$.vec4(),Qf=$.vec4(),Wf=$.vec3([1,0,0]),zf=$.vec3([0,1,0]),Kf=$.vec3([0,0,1]);$.vec3(3),$.vec3(3);var Yf=$.identityMat4(),Xf=function(){function e(t){b(this,e),this._model=t.model,this.id=t.id,this._parentTransform=t.parent,this._childTransforms=[],this._meshes=[],this._scale=new Float32Array([1,1,1]),this._quaternion=$.identityQuaternion(new Float32Array(4)),this._rotation=new Float32Array(3),this._position=new Float32Array(3),this._localMatrix=$.identityMat4(new Float32Array(16)),this._worldMatrix=$.identityMat4(new Float32Array(16)),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,t.matrix?this.matrix=t.matrix:(this.scale=t.scale,this.position=t.position,t.quaternion||(this.rotation=t.rotation)),t.parent&&t.parent._addChildTransform(this)}return P(e,[{key:"_addChildTransform",value:function(e){this._childTransforms.push(e),e._parentTransform=this,e._setWorldMatrixDirty(),e._setAABBDirty()}},{key:"_addMesh",value:function(e){this._meshes.push(e),e.transform=this}},{key:"parentTransform",get:function(){return this._parentTransform}},{key:"meshes",get:function(){return this._meshes}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._model.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),$.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._model.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),$.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._model.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._model.glRedraw()}},{key:"matrix",get:function(){return this._localMatrixDirty&&(this._localMatrix||(this._localMatrix=$.identityMat4()),$.composeMat4(this._position,this._quaternion,this._scale,this._localMatrix),this._localMatrixDirty=!1),this._localMatrix},set:function(e){this._localMatrix||(this._localMatrix=$.identityMat4()),this._localMatrix.set(e||Yf),$.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._transformDirty(),this._model.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"rotate",value:function(e,t){return jf[0]=e[0],jf[1]=e[1],jf[2]=e[2],jf[3]=t*$.DEGTORAD,$.angleAxisToQuaternion(jf,Vf),$.mulQuaternions(this.quaternion,Vf,Qf),this.quaternion=Qf,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return jf[0]=e[0],jf[1]=e[1],jf[2]=e[2],jf[3]=t*$.DEGTORAD,$.angleAxisToQuaternion(jf,Vf),$.mulQuaternions(Vf,this.quaternion,Vf),this}},{key:"rotateX",value:function(e){return this.rotate(Wf,e)}},{key:"rotateY",value:function(e){return this.rotate(zf,e)}},{key:"rotateZ",value:function(e){return this.rotate(Kf,e)}},{key:"translate",value:function(e){return this._position[0]+=e[0],this._position[1]+=e[1],this._position[2]+=e[2],this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateX",value:function(e){return this._position[0]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateY",value:function(e){return this._position[1]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateZ",value:function(e){return this._position[2]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._transformDirty()}},{key:"_transformDirty",value:function(){this._worldMatrixDirty=!0;for(var e=0,t=this._childTransforms.length;e<t;e++){var n=this._childTransforms[e];if(n._transformDirty(),n._meshes&&n._meshes.length>0)for(var r=n._meshes,i=0,a=r.length;i<a;i++)r[i]._transformDirty()}if(this._meshes&&this._meshes.length>0)for(var s=this._meshes,o=0,l=s.length;o<l;o++)s[o]._transformDirty()}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentTransform)$.mulMat4(this._parentTransform.worldMatrix,e,this._worldMatrix);else for(var t=0,n=e.length;t<n;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}},{key:"_setSubtreeAABBsDirty",value:function(e){if(e._aabbDirty=!0,e._childTransforms)for(var t=0,n=e._childTransforms.length;t<n;t++)this._setSubtreeAABBsDirty(e._childTransforms[t])}}]),e}(),qf=$.vec3(),Jf=$.OBB3(),Zf=$.vec3([1,1,1]),$f=$.vec3([0,0,0]),ep=$.vec3([0,0,0]),tp=$.identityQuaternion(),np=$.identityMat4(),rp=new Uint8Array([255,255,255]),ip=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._dtxEnabled=r.scene.dtxEnabled&&!1!==i.dtxEnabled,r._enableVertexWelding=!1,r._enableIndexBucketing=!1,r._vboBatchingLayerScratchMemory=Ja(),r._textureTranscoder=i.textureTranscoder||Bf(r.scene.viewer),r._maxGeometryBatchSize=i.maxGeometryBatchSize,r._aabb=$.collapseAABB3(),r._aabbDirty=!0,r._quantizationRanges={},r._vboInstancingLayers={},r._vboBatchingLayers={},r._dtxLayers={},r.layerList=[],r._entityList=[],r._geometries={},r._dtxBuckets={},r._textures={},r._textureSets={},r._transforms={},r._meshes={},r._entities={},r._scheduledMeshes={},r._meshesCfgsBeforeMeshCreation={},r.renderFlags=new ki,r.numGeometries=0,r.numPortions=0,r.numVisibleLayerPortions=0,r.numTransparentLayerPortions=0,r.numXRayedLayerPortions=0,r.numHighlightedLayerPortions=0,r.numSelectedLayerPortions=0,r.numEdgesLayerPortions=0,r.numPickableLayerPortions=0,r.numClippableLayerPortions=0,r.numCulledLayerPortions=0,r.numEntities=0,r._numTriangles=0,r._numLines=0,r._numPoints=0,r._edgeThreshold=i.edgeThreshold||10,r._origin=$.vec3(i.origin||[0,0,0]),r._position=$.vec3(i.position||[0,0,0]),r._rotation=$.vec3(i.rotation||[0,0,0]),r._quaternion=$.vec4(i.quaternion||[0,0,0,1]),r._conjugateQuaternion=$.vec4(i.quaternion||[0,0,0,1]),i.rotation&&$.eulerToQuaternion(r._rotation,"XYZ",r._quaternion),r._scale=$.vec3(i.scale||[1,1,1]),r._worldRotationMatrix=$.mat4(),r._worldRotationMatrixConjugate=$.mat4(),r._matrix=$.mat4(),r._matrixDirty=!0,r._rebuildMatrices(),r._worldNormalMatrix=$.mat4(),$.inverseMat4(r._matrix,r._worldNormalMatrix),$.transposeMat4(r._worldNormalMatrix),(i.matrix||i.position||i.rotation||i.scale||i.quaternion)&&(r._viewMatrix=$.mat4(),r._viewNormalMatrix=$.mat4(),r._viewMatrixDirty=!0,r._matrixNonIdentity=!0),r._opacity=1,r._colorize=[1,1,1],r._saoEnabled=!1!==i.saoEnabled,r._pbrEnabled=!1!==i.pbrEnabled,r._colorTextureEnabled=!1!==i.colorTextureEnabled,r._isModel=i.isModel,r._isModel&&r.scene._registerModel(w(r)),r._onCameraViewMatrix=r.scene.camera.on("matrix",(function(){r._viewMatrixDirty=!0})),r._meshesWithDirtyMatrices=[],r._numMeshesWithDirtyMatrices=0,r._onTick=r.scene.on("tick",(function(){for(;r._numMeshesWithDirtyMatrices>0;)r._meshesWithDirtyMatrices[--r._numMeshesWithDirtyMatrices]._updateMatrix()})),r._createDefaultTextureSet(),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.backfaces=i.backfaces,r}return P(n,[{key:"_meshMatrixDirty",value:function(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}},{key:"_createDefaultTextureSet",value:function(){var e=new mf({id:"defaultColorTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new mf({id:"defaultMetalRoughTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),n=new mf({id:"defaultNormalsTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),r=new mf({id:"defaultEmissiveTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new mf({id:"defaultOcclusionTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=n,this._textures.defaultEmissiveTexture=r,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new yf({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:n,emissiveTexture:r,occlusionTexture:i})}},{key:"isPerformanceModel",get:function(){return!0}},{key:"transforms",get:function(){return this._transforms}},{key:"textures",get:function(){return this._textures}},{key:"textureSets",get:function(){return this._textureSets}},{key:"meshes",get:function(){return this._meshes}},{key:"objects",get:function(){return this._entities}},{key:"origin",get:function(){return this._origin}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),$.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),$.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){}},{key:"matrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix},set:function(e){this._matrix.set(e||np),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),$.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),$.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"rotationMatrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}},{key:"_rebuildMatrices",value:function(){this._matrixDirty&&($.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),$.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),$.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}},{key:"rotationMatrixConjugate",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}},{key:"_setWorldMatrixDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0}},{key:"_transformDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}},{key:"_sceneModelDirty",value:function(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(var e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._sceneModelDirty()}},{key:"worldMatrix",get:function(){return this.matrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrix}},{key:"viewMatrix",get:function(){return this._viewMatrix?(this._matrixDirty&&(this._rebuildMatrices(),this._viewMatrixDirty=!0),this._viewMatrixDirty&&($.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),$.inverseMat4(this._viewMatrix,this._viewNormalMatrix),$.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),this._viewMatrix):this.scene.camera.viewMatrix}},{key:"viewNormalMatrix",get:function(){return this._viewNormalMatrix?(this._matrixDirty&&(this._rebuildMatrices(),this._viewMatrixDirty=!0),this._viewMatrixDirty&&($.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),$.inverseMat4(this._viewMatrix,this._viewNormalMatrix),$.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),$.inverseMat4(this._viewMatrix,this._viewNormalMatrix),$.transposeMat4(this._viewNormalMatrix),this._viewNormalMatrix):this.scene.camera.viewNormalMatrix}},{key:"backfaces",get:function(){return this._backfaces},set:function(e){e=!!e,this._backfaces=e,this.glRedraw()}},{key:"entityList",get:function(){return this._entityList}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return!1}},{key:"aabb",get:function(){if(this._aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._entityList.length;e<t;e++)$.expandAABB3(this._aabb,this._entityList[e].aabb);this._aabbDirty=!1}return this._aabb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"numLines",get:function(){return this._numLines}},{key:"numPoints",get:function(){return this._numPoints}},{key:"visible",get:function(){return this.numVisibleLayerPortions>0},set:function(e){e=!1!==e,this._visible=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].visible=e;this.glRedraw()}},{key:"xrayed",get:function(){return this.numXRayedLayerPortions>0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].xrayed=e;this.glRedraw()}},{key:"highlighted",get:function(){return this.numHighlightedLayerPortions>0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].highlighted=e;this.glRedraw()}},{key:"selected",get:function(){return this.numSelectedLayerPortions>0},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].selected=e;this.glRedraw()}},{key:"edges",get:function(){return this.numEdgesLayerPortions>0},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].edges=e;this.glRedraw()}},{key:"culled",get:function(){return this._culled},set:function(e){e=!!e,this._culled=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].culled=e;this.glRedraw()}},{key:"clippable",get:function(){return this._clippable},set:function(e){e=!1!==e,this._clippable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].clippable=e;this.glRedraw()}},{key:"collidable",get:function(){return this._collidable},set:function(e){e=!1!==e,this._collidable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].collidable=e}},{key:"pickable",get:function(){return this.numPickableLayerPortions>0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].pickable=e}},{key:"colorize",get:function(){return this._colorize},set:function(e){this._colorize=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].colorize=e}},{key:"opacity",get:function(){return this._opacity},set:function(e){this._opacity=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].opacity=e}},{key:"castsShadow",get:function(){return this._castsShadow},set:function(e){(e=!1!==e)!==this._castsShadow&&(this._castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._receivesShadow},set:function(e){(e=!1!==e)!==this._receivesShadow&&(this._receivesShadow=e,this.glRedraw())}},{key:"saoEnabled",get:function(){return this._saoEnabled}},{key:"pbrEnabled",get:function(){return this._pbrEnabled}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!1}},{key:"xrayMaterial",get:function(){return this.scene.xrayMaterial}},{key:"highlightMaterial",get:function(){return this.scene.highlightMaterial}},{key:"selectedMaterial",get:function(){return this.scene.selectedMaterial}},{key:"edgeMaterial",get:function(){return this.scene.edgeMaterial}},{key:"getPickViewMatrix",value:function(e){return this._viewMatrix?this._viewMatrix:e}},{key:"createQuantizationRange",value:function(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:Ws(e.aabb,$.mat4())}:this.error("[createQuantizationRange] Config missing: id")}},{key:"createGeometry",value:function(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 '".concat(e.primitive,"' primitive type)")),null;if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Ws(e.positionsDecodeBoundary,$.mat4())),e.positions){var t=$.collapseAABB3();e.positionsDecodeMatrix=$.mat4(),$.expandAABB3Points3(t,e.positions),e.positionsCompressed=Qs(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){var n=$.collapseAABB3();e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed),$.expandAABB3Points3(n,e.positionsCompressed),Pn.decompressAABB(n,e.positionsDecodeMatrix),e.aabb=n}else if(e.buckets){var r=$.collapseAABB3();this._dtxBuckets[e.id]=e.buckets;for(var i=0,a=e.buckets.length;i<a;i++){var s=e.buckets[i];s.positions?$.expandAABB3Points3(r,s.positions):s.positionsCompressed&&$.expandAABB3Points3(r,s.positionsCompressed)}e.positionsDecodeMatrix&&Pn.decompressAABB(r,e.positionsDecodeMatrix),e.aabb=r}if(e.colorsCompressed&&e.colorsCompressed.length>0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var o=e.colors,l=new Uint8Array(o.length),u=0,c=o.length;u<c;u++)l[u]=255*o[u];e.colorsCompressed=l}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=mn(e.positions,e.indices,null,5):e.edgeIndices=mn(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.uv){var f=Pn.getUVBounds(e.uv),p=Pn.compressUVs(e.uv,f.min,f.max);e.uvCompressed=p.quantized,e.uvDecodeMatrix=p.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': '".concat(e.primitive,"' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'."));else this.error("[createGeometry] Config missing: id")}},{key:"createTexture",value:function(e){var t=this,n=e.id;if(null!=n)if(this._textures[n])this.error("[createTexture] Texture already created: "+n);else{if(!e.src&&!e.image&&!e.buffers)return this.error("[createTexture] Param expected: `src`, `image' or 'buffers'"),null;var r=e.minFilter||1008;1006!==r&&1007!==r&&1008!==r&&1005!==r&&1004!==r&&(this.error("[createTexture] Unsupported value for 'minFilter' - \n supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, \n NearestMipMapLinearFilter and LinearMipmapLinearFilter. Defaulting to LinearMipmapLinearFilter."),r=1008);var i=e.magFilter||1006;1006!==i&&1003!==i&&(this.error("[createTexture] Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),i=1006);var a=e.wrapS||1e3;1001!==a&&1002!==a&&1e3!==a&&(this.error("[createTexture] Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),a=1e3);var s=e.wrapT||1e3;1001!==s&&1002!==s&&1e3!==s&&(this.error("[createTexture] Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),s=1e3);var o=e.wrapR||1e3;1001!==o&&1002!==o&&1e3!==o&&(this.error("[createTexture] Unsupported value for 'wrapR' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),o=1e3);var l=e.encoding||3e3;3e3!==l&&3001!==l&&(this.error("[createTexture] Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),l=3e3);var u=new Da({gl:this.scene.canvas.gl,minFilter:r,magFilter:i,wrapS:a,wrapT:s,wrapR:o,encoding:l});if(e.preloadColor&&u.setPreloadColor(e.preloadColor),e.image){var c=e.image;c.crossOrigin="Anonymous",u.setImage(c,{minFilter:r,magFilter:i,wrapS:a,wrapT:s,wrapR:o,flipY:e.flipY,encoding:l})}else if(e.src){var f=e.src.split(".").pop();switch(f){case"jpeg":case"jpg":case"png":case"gif":var p=new Image;p.onload=function(){u.setImage(p,{minFilter:r,magFilter:i,wrapS:a,wrapT:s,wrapR:o,flipY:e.flipY,encoding:l}),t.glRedraw()},p.src=e.src;break;default:this._textureTranscoder?le.loadArraybuffer(e.src,(function(e){e.byteLength?t._textureTranscoder.transcode([e],u).then((function(){t.glRedraw()})):t.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error("[createTexture] Can't create texture from 'src': ".concat(e))})):this.error("[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('".concat(f,"')"))}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,u).then((function(){t.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[n]=new mf({id:n,texture:u})}else this.error("[createTexture] Config missing: id")}},{key:"createTextureSet",value:function(e){var t=e.id;if(null!=t){if(!this._textureSets[t]){var n,r,i,a,s;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(!(n=this._textures[e.colorTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.colorTextureId," - ensure that you create it first with createTexture()"))}else n=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(!(r=this._textures[e.metallicRoughnessTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.metallicRoughnessTextureId," - ensure that you create it first with createTexture()"))}else r=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(!(i=this._textures[e.normalsTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.normalsTextureId," - ensure that you create it first with createTexture()"))}else i=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(!(a=this._textures[e.emissiveTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.emissiveTextureId," - ensure that you create it first with createTexture()"))}else a=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(!(s=this._textures[e.occlusionTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.occlusionTextureId," - ensure that you create it first with createTexture()"))}else s=this._textures.defaultOcclusionTexture;var o=new yf({id:t,model:this,colorTexture:n,metallicRoughnessTexture:r,normalsTexture:i,emissiveTexture:a,occlusionTexture:s});return this._textureSets[t]=o,o}this.error("[createTextureSet] Texture set already created: ".concat(t))}else this.error("[createTextureSet] Config missing: id")}},{key:"createTransform",value:function(e){if(void 0!==e.id&&null!==e.id)if(this._transforms[e.id])this.error("[createTransform] SceneModel already has a transform with this ID: ".concat(e.id));else{var t;if(!this.parentTransformId||(t=this._transforms[e.parentTransformId])){var n=new Xf({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[n.id]=n,n}this.error("[createTransform] SceneModel.createTransform() config missing: id")}else this.error("[createTransform] SceneModel.createTransform() config missing: id")}},{key:"createMesh",value:function(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: ".concat(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': '".concat(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 '".concat(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;var t=!!this._dtxEnabled&&("triangles"===e.primitive||"solid"===e.primitive||"surface"===e.primitive);if(e.origin=e.origin?$.addVec3(this._origin,e.origin,$.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){var n=e.scale||Zf,r=e.position||$f,i=e.rotation||ep;$.eulerToQuaternion(i,"XYZ",tp),e.meshMatrix=$.composeMat4(r,tp,n,$.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Ws(e.positionsDecodeBoundary,$.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])]):rp,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){var a=$.vec3(),s=[];Ne(e.positions,s,a)&&(e.positions=s,e.origin=$.addVec3(e.origin,a,a))}if(e.positions){var o=$.collapseAABB3();e.positionsDecodeMatrix=$.mat4(),$.expandAABB3Points3(o,e.positions),e.positionsCompressed=Qs(e.positions,o,e.positionsDecodeMatrix),e.aabb=o}else if(e.positionsCompressed){var l=$.collapseAABB3();$.expandAABB3Points3(l,e.positionsCompressed),Pn.decompressAABB(l,e.positionsDecodeMatrix),e.aabb=l}if(e.buckets){for(var u=$.collapseAABB3(),c=0,f=e.buckets.length;c<f;c++){var p=e.buckets[c];p.positions?$.expandAABB3Points3(u,p.positions):p.positionsCompressed&&$.expandAABB3Points3(u,p.positionsCompressed)}e.positionsDecodeMatrix&&Pn.decompressAABB(u,e.positionsDecodeMatrix),e.aabb=u}e.meshMatrix&&($.AABB3ToOBB3(e.aabb,Jf),$.transformOBB3(e.meshMatrix,Jf),$.OBB3ToAABB3(Jf,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=mn(e.positions,e.indices,null,2):e.edgeIndices=mn(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=ap(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){var A=[];Ne(e.positions,A,qf)&&(e.positions=A,e.origin=$.addVec3(e.origin,qf,$.vec3()))}if(e.positions){var d=$.collapseAABB3();e.meshMatrix&&($.transformPositions3(e.meshMatrix,e.positions,e.positions),e.meshMatrix=null),$.expandAABB3Points3(d,e.positions),e.aabb=d}else{var v=$.collapseAABB3();$.expandAABB3Points3(v,e.positionsCompressed),Pn.decompressAABB(v,e.positionsDecodeMatrix),e.aabb=v}if(e.meshMatrix&&($.AABB3ToOBB3(e.aabb,Jf),$.transformOBB3(e.meshMatrix,Jf),$.OBB3ToAABB3(Jf,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=mn(e.positions,e.indices,null,2):e.edgeIndices=mn(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: ".concat(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: ".concat(e.geometryId," - ensure that you create it first with createGeometry()")),!1;if(e.origin=e.origin?$.addVec3(this._origin,e.origin,$.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: ".concat(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{var h=e.scale||Zf,I=e.position||$f,y=e.rotation||ep;$.eulerToQuaternion(y,"XYZ",tp),e.meshMatrix=$.composeMat4(I,tp,h,$.mat4())}$.AABB3ToOBB3(e.geometry.aabb,Jf),$.transformOBB3(e.meshMatrix,Jf),e.aabb=$.OBB3ToAABB3(Jf,$.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])]):rp,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255;var m=this._dtxBuckets[e.geometryId];m||(m=ap(e.geometry,this._enableVertexWelding,this._enableIndexBucketing),this._dtxBuckets[e.geometryId]=m),e.buckets=m}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])]):rp,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}},{key:"_createMesh",value:function(e){var t=new Ya(this,e.id,e.color,e.opacity,e.transform,e.textureSet);t.pickId=this.scene._renderer.getPickID(t);var n=t.pickId,r=n>>24&255,i=n>>16&255,a=n>>8&255,s=255&n;switch(e.pickColor=new Uint8Array([s,a,i,r]),e.solid="solid"===e.primitive,t.origin=$.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),t}},{key:"_getNumPrimitives",value:function(e){var t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(var n=0,r=e.buckets.length;n<r;n++)t+=e.buckets[n].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(var i=0,a=e.buckets.length;i<a;i++)t+=e.buckets[i].positionsCompressed.length;break;case 1:t+=e.positions?e.positions.length:e.positionsCompressed.length;break;case 0:var 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(var o=0,l=e.buckets.length;o<l;o++)t+=e.buckets[o].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/2)}return 0}},{key:"_getDTXLayer",value:function(e){var t=e.origin,n=e.geometry?e.geometry.primitive:e.primitive,r=".".concat(n,".").concat(Math.round(t[0]),".").concat(Math.round(t[1]),".").concat(Math.round(t[2])),i=this._dtxLayers[r];if(i){if(i.canCreatePortion(e))return i;i.finalize(),delete this._dtxLayers[r],i=null}switch(n){case"triangles":case"solid":case"surface":i=new If(this,{layerIndex:0,origin:t});break;case"lines":i=new Ku(this,{layerIndex:0,origin:t});break;default:return}return this._dtxLayers[r]=i,this.layerList.push(i),i}},{key:"_getVBOBatchingLayer",value:function(e){var t=this,n=e.origin,r=e.positionsDecodeMatrix||e.positionsDecodeBoundary?this._createHashStringFromMatrix(e.positionsDecodeMatrix||e.positionsDecodeBoundary):"-",i=e.textureSetId||"-",a="".concat(Math.round(n[0]),".").concat(Math.round(n[1]),".").concat(Math.round(n[2]),".").concat(e.primitive,".").concat(r,".").concat(i),s=this._vboBatchingLayers[a];if(s)return s;for(var o=e.textureSet;!s;){switch(e.primitive){case"triangles":case"solid":case"surface":s=new io({model:t,textureSet:o,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize,solid:"solid"===e.primitive,autoNormals:!0});break;case"lines":s=new vl({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize});break;case"points":s=new ru({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize})}var l=e.positionsCompressed?e.positionsCompressed.length:e.positions.length;("points"===e.primitive?s.canCreatePortion(l):s.canCreatePortion(l,e.indices.length))||(s.finalize(),delete this._vboBatchingLayers[a],s=null)}return this._vboBatchingLayers[a]=s,this.layerList.push(s),s}},{key:"_createHashStringFromMatrix",value:function(e){for(var t=e.join(""),n=0,r=0;r<t.length;r++){n=(n<<5)-n+t.charCodeAt(r),n|=0}return(n>>>0).toString(16)}},{key:"_getVBOInstancingLayer",value:function(e){var t=this,n=e.origin,r=e.textureSetId||"-",i=e.geometryId,a="".concat(Math.round(n[0]),".").concat(Math.round(n[1]),".").concat(Math.round(n[2]),".").concat(r,".").concat(i),s=this._vboInstancingLayers[a];if(s)return s;for(var o=e.textureSet,l=e.geometry;!s;)switch(l.primitive){case"triangles":case"surface":s=new qo({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!1});break;case"solid":s=new qo({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!0});break;case"lines":s=new xl({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0});break;case"points":s=new _u({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0})}return this._vboInstancingLayers[a]=s,this.layerList.push(s),s}},{key:"createEntity",value:function(e){if(void 0===e.id?e.id=$.createUUID():this.scene.components[e.id]&&(this.error("Scene already has a Component with this ID: ".concat(e.id," - will assign random ID")),e.id=$.createUUID()),void 0!==e.meshIds){var t=0;this._visible&&!1!==e.visible&&(t|=Me),this._pickable&&!1!==e.pickable&&(t|=He),this._culled&&!1!==e.culled&&(t|=Fe),this._clippable&&!1!==e.clippable&&(t|=Ue),this._collidable&&!1!==e.collidable&&(t|=Ge),this._edges&&!1!==e.edges&&(t|=Qe),this._xrayed&&!1!==e.xrayed&&(t|=ke),this._highlighted&&!1!==e.highlighted&&(t|=je),this._selected&&!1!==e.selected&&(t|=Ve),e.flags=t,this._createEntity(e)}else this.error("Config missing: meshIds")}},{key:"_createEntity",value:function(e){for(var t=[],n=0,r=e.meshIds.length;n<r;n++){var i=e.meshIds[n],a=this._meshes[i];if(!a){var s=this._meshesCfgsBeforeMeshCreation[i];if(!s){this.error('Mesh with this ID not found: "'.concat(i,'" - ignoring this mesh'));continue}a=this._createMesh(s),this._meshes[e.id]=a}a.parent?this.error('Mesh with ID "'.concat(i,'" already belongs to object with ID "').concat(a.parent.id,'" - ignoring this mesh')):t.push(a)}var o=new Ke(this,e.isObject,e.id,t,e.flags,!0);this._entityList.push(o),this._entities[e.id]=o,this.numEntities++}},{key:"finalize",value:function(){if(!this.destroyed){for(var 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(var n=0,r=this._entityList.length;n<r;n++){this._entityList[n]._finalize()}for(var i=0,a=this._entityList.length;i<a;i++){this._entityList[i]._finalize2()}this.layerList.sort((function(e,t){return e.sortId<t.sortId?-1:e.sortId>t.sortId?1:0}));for(var s=0,o=this.layerList.length;s<o;s++){this.layerList[s].layerIndex=s}this.glRedraw(),this.scene._aabbDirty=!0,this._viewMatrixDirty=!0,this._matrixDirty=!0,this._aabbDirty=!0,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.position=this._position}}},{key:"stateSortCompare",value:function(e,t){}},{key:"rebuildRenderFlags",value:function(){this.renderFlags.reset(),this._updateRenderFlagsVisibleLayers(),this.renderFlags.numLayers>0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}},{key:"_updateRenderFlagsVisibleLayers",value:function(){var e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(var t=0,n=this.layerList.length;t<n;t++){var r=this.layerList[t];this._getActiveSectionPlanesForLayer(r)&&(e.visibleLayers[e.numVisibleLayers++]=t)}}},{key:"_getActiveSectionPlanesForLayer",value:function(e){var t=this.renderFlags,n=this.scene._sectionPlanesState.sectionPlanes,r=n.length,i=e.layerIndex*r;if(r>0)for(var a=0;a<r;a++){n[a].active?(t.sectionPlanesActivePerLayer[i+a]=!0,t.sectioned=!0):t.sectionPlanesActivePerLayer[i+a]=!1}return!0}},{key:"_updateRenderFlags",value:function(){if(0!==this.numVisibleLayerPortions&&this.numCulledLayerPortions!==this.numPortions){var e=this.renderFlags;if(e.colorOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){var t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0)this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(e.edgesTransparent=!0));if(this.numSelectedLayerPortions>0){var n=this.scene.selectedMaterial._state;n.fill&&(n.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),n.edges&&(n.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){var r=this.scene.highlightMaterial._state;r.fill&&(r.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),r.edges&&(r.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"drawColorOpaque",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawColorOpaque(t,e)}}},{key:"drawColorTransparent",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawColorTransparent(t,e)}}},{key:"drawDepth",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawDepth(t,e)}}},{key:"drawNormals",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawNormals(t,e)}}},{key:"drawSilhouetteXRayed",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawSilhouetteXRayed(t,e)}}},{key:"drawSilhouetteHighlighted",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawSilhouetteHighlighted(t,e)}}},{key:"drawSilhouetteSelected",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawSilhouetteSelected(t,e)}}},{key:"drawEdgesColorOpaque",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesColorOpaque(t,e)}}},{key:"drawEdgesColorTransparent",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesColorTransparent(t,e)}}},{key:"drawEdgesXRayed",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesXRayed(t,e)}}},{key:"drawEdgesHighlighted",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesHighlighted(t,e)}}},{key:"drawEdgesSelected",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesSelected(t,e)}}},{key:"drawOcclusion",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawOcclusion(t,e)}}},{key:"drawShadow",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawShadow(t,e)}}},{key:"setPickMatrices",value:function(e,t){if(0!==this._numVisibleLayerPortions)for(var n=this.renderFlags,r=0,i=n.visibleLayers.length;r<i;r++){var a=n.visibleLayers[r],s=this.layerList[a];s.setPickMatrices&&s.setPickMatrices(e,t)}}},{key:"drawPickMesh",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawPickMesh(t,e)}}},{key:"drawPickDepths",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawPickDepths(t,e)}}},{key:"drawPickNormals",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawPickNormals(t,e)}}},{key:"drawSnapInit",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n],a=this.layerList[i];a.drawSnapInit&&(e.snapPickOrigin=[0,0,0],e.snapPickCoordinateScale=[1,1,1],e.snapPickLayerNumber++,a.drawSnapInit(t,e),e.snapPickLayerParams[e.snapPickLayerNumber]={origin:e.snapPickOrigin.slice(),coordinateScale:e.snapPickCoordinateScale.slice()})}}},{key:"drawSnap",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n],a=this.layerList[i];a.drawSnap&&(e.snapPickOrigin=[0,0,0],e.snapPickCoordinateScale=[1,1,1],e.snapPickLayerNumber++,a.drawSnap(t,e),e.snapPickLayerParams[e.snapPickLayerNumber]={origin:e.snapPickOrigin.slice(),coordinateScale:e.snapPickCoordinateScale.slice()})}}},{key:"destroy",value:function(){for(var e in this._vboBatchingLayers)this._vboBatchingLayers.hasOwnProperty(e)&&this._vboBatchingLayers[e].destroy();for(var t in this._vboBatchingLayers={},this._vboInstancingLayers)this._vboInstancingLayers.hasOwnProperty(t)&&this._vboInstancingLayers[t].destroy();this._vboInstancingLayers={},this.scene.camera.off(this._onCameraViewMatrix),this.scene.off(this._onTick);for(var r=0,i=this.layerList.length;r<i;r++)this.layerList[r].destroy();this.layerList=[];for(var a=0,s=this._entityList.length;a<s;a++)this._entityList[a]._destroy();this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this.scene._aabbDirty=!0,this._isModel&&this.scene._deregisterModel(this),0!==qa&&0==--qa&&Xa._clear(),d(g(n.prototype),"destroy",this).call(this)}}]),n}();function ap(e,t,n){var r,i,a,s;if(t||n){var o=f(Lf({positionsCompressed:e.positionsCompressed,indices:e.indices,edgeIndices:e.edgeIndices}),3);r=o[0],i=o[1],a=o[2]}else r=e.positionsCompressed,i=e.indices,a=e.edgeIndices;n?s=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=e.positionsCompressed||[],i=Ff(e.indices||[],t),a=Gf(e.edgeIndices||[]);function s(e,t){if(e>t){var n=e;e=t,t=n}function r(n,r){return n!==e?e-n:r!==t?t-r:0}for(var i=0,s=(a.length>>1)-1;i<=s;){var o=s+i>>1,l=r(a[2*o],a[2*o+1]);if(l>0)i=o+1;else{if(!(l<0))return o;s=o-1}}return-i-1}var o=new Int32Array(a.length/2);o.fill(0);var l=r.length/3;if(l>8*(1<<t))return[e];var u=new Int32Array(l);u.fill(-1);var c=[];function f(){u.fill(-1);var e={positionsCompressed:[],indices:[],edgeIndices:[],maxNumPositions:(1<<t)-t,numPositions:0,bucketNumber:c.length};return c.push(e),e}for(var p=f(),A=0,d=i.length;A<d;A+=3){var v=0,h=i[A],I=i[A+1],y=i[A+2];if(-1===u[h]&&v++,-1===u[I]&&v++,-1===u[y]&&v++,v+p.numPositions>p.maxNumPositions&&(p=f()),p.bucketNumber>8)return[e];-1===u[h]&&(u[h]=p.numPositions++,p.positionsCompressed.push(r[3*h]),p.positionsCompressed.push(r[3*h+1]),p.positionsCompressed.push(r[3*h+2])),-1===u[I]&&(u[I]=p.numPositions++,p.positionsCompressed.push(r[3*I]),p.positionsCompressed.push(r[3*I+1]),p.positionsCompressed.push(r[3*I+2])),-1===u[y]&&(u[y]=p.numPositions++,p.positionsCompressed.push(r[3*y]),p.positionsCompressed.push(r[3*y+1]),p.positionsCompressed.push(r[3*y+2])),p.indices.push(u[h]),p.indices.push(u[I]),p.indices.push(u[y]);var m=void 0;(m=s(h,I))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]])),(m=s(h,y))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]])),(m=s(I,y))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]]))}var w=t/8*2,g=t/8,E=2*r.length+(i.length+a.length)*w,T=0;return r.length,c.forEach((function(e){T+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*g,e.positionsCompressed.length})),T>E?[e]:(n&&kf(c,e),c)}({positionsCompressed:r,indices:i,edgeIndices:a},r.length/3>65536?16:8):s=[{positionsCompressed:r,indices:i,edgeIndices:a}];return s}var sp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e,i))._positions=i.positions||[],i.indices)r._indices=i.indices;else{r._indices=[];for(var a=0,s=r._positions.length/3-1;a<s;a+=2)r._indices.push(a),r._indices.push(a+1)}return r._sceneModel=new ip(w(r),{isModel:!1}),r._sceneModel.createMesh({id:"linesMesh",primitive:"lines",positions:r._positions,indices:r._indices}),r._sceneModel.createEntity({meshIds:["linesMesh"],visible:i.visible,clippable:i.clippable,collidable:i.collidable}),r._sceneModel.finalize(),r.scene._lineSetCreated(w(r)),r}return P(n,[{key:"visible",get:function(){return this._sceneModel.visible},set:function(e){this._sceneModel.visible=e}},{key:"positions",get:function(){return this._positions}},{key:"indices",get:function(){return this._indices}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene._lineSetDestroyed(this)}}]),n}(),op=$.vec3(),lp=$.vec3(),up=$.vec3(),cp=$.vec3(),fp=function(e){h(n,Re);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"BCFViewpoints",e,i)).originatingSystem=i.originatingSystem||"xeokit.io",r.authoringTool=i.authoringTool||"xeokit.io",r}return P(n,[{key:"getViewpoint",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=this.viewer.scene,r=n.camera,i=n.realWorldOffset,a=!0===t.reverseClippingPlanes,s={},o=$.normalizeVec3($.subVec3(r.look,r.eye,$.vec3())),l=r.eye,u=r.up;r.yUp&&(o=dp(o),l=dp(l),u=dp(u));var c=pp($.addVec3(l,i));"ortho"===r.projection?s.orthogonal_camera={camera_view_point:c,camera_direction:pp(o),camera_up_vector:pp(u),view_to_world_scale:r.ortho.scale}:s.perspective_camera={camera_view_point:c,camera_direction:pp(o),camera_up_vector:pp(u),field_of_view:r.perspective.fov};var p=n.sectionPlanes;for(var A in p)if(p.hasOwnProperty(A)){var d=p[A];if(!d.active)continue;var v=d.pos,h=void 0;h=a?$.negateVec3(d.dir,$.vec3()):d.dir,r.yUp&&(v=dp(v),h=dp(h)),$.addVec3(v,i),v=pp(v),h=pp(h),s.clipping_planes||(s.clipping_planes=[]),s.clipping_planes.push({location:v,direction:h})}var I=n.lineSets;for(var y in I)if(I.hasOwnProperty(y)){var m=I[y];s.lines||(s.lines=[]);for(var w=m.positions,g=m.indices,E=0,T=g.length/2;E<T;E++){var b=g[2*E],D=g[2*E+1];s.lines.push({start_point:{x:w[3*b+0],y:w[3*b+1],z:w[3*b+2]},end_point:{x:w[3*D+0],y:w[3*D+1],z:w[3*D+2]}})}}var P=n.bitmaps;for(var C in P)if(P.hasOwnProperty(C)){var _=P[C],R=_.pos,B=_.normal,O=_.up;r.yUp&&(R=dp(R),B=dp(B),O=dp(O)),$.addVec3(R,i),s.bitmaps||(s.bitmaps=[]),s.bitmaps.push({bitmap_type:_.type,bitmap_data:_.imageData,location:pp(R),normal:pp(B),up:pp(O),height:_.height})}s.components={visibility:{view_setup_hints:{spaces_visible:!!t.spacesVisible,space_boundaries_visible:!!t.spaceBoundariesVisible,openings_visible:!!t.openingsVisible,spaces_translucent:!!t.spaces_translucent,space_boundaries_translucent:!!t.space_boundaries_translucent,openings_translucent:!!t.openings_translucent}}};var S=new Set(n.opacityObjectIds),N=new Set(n.xrayedObjectIds),L=new Set(n.colorizedObjectIds),x=Object.values(n.objects).filter((function(e){return S.has(e.id)||L.has(e.id)||N.has(e.id)})).reduce((function(t,r){var i,a=hp(r.colorize);r.xrayed?(i=0===n.xrayMaterial.fillAlpha&&0!==n.xrayMaterial.edgeAlpha?.1:n.xrayMaterial.fillAlpha,a=(i=Math.round(255*i).toString(16).padStart(2,"0"))+a):S.has(r.id)&&(a=(i=Math.round(255*r.opacity).toString(16).padStart(2,"0"))+a),t[a]||(t[a]=[]);var s=r.id,o=r.originalSystemId,l={ifc_guid:o,originating_system:e.originatingSystem};return o!==s&&(l.authoring_tool_id=s),t[a].push(l),t}),{}),M=Object.entries(x).map((function(e){var t=f(e,2);return{color:t[0],components:t[1]}}));s.components.coloring=M;var F=n.objectIds,H=n.visibleObjects,U=n.visibleObjectIds,G=F.filter((function(e){return!H[e]})),k=n.selectedObjectIds;return t.defaultInvisible||U.length<G.length?(s.components.visibility.exceptions=this._createBCFComponents(U),s.components.visibility.default_visibility=!1):(s.components.visibility.exceptions=this._createBCFComponents(G),s.components.visibility.default_visibility=!0),s.components.selection=this._createBCFComponents(k),s.components.translucency=this._createBCFComponents(n.xrayedObjectIds),!1!==t.snapshot&&(s.snapshot={snapshot_type:"png",snapshot_data:this.viewer.getSnapshot({format:"png"})}),s}},{key:"_createBCFComponents",value:function(e){for(var t=this.viewer.scene,n=[],r=0,i=e.length;r<i;r++){var a=e[r],s=t.objects[a];if(s){var o={ifc_guid:s.originalSystemId,originating_system:this.originatingSystem};s.originalSystemId!==a&&(o.authoring_tool_id=a),n.push(o)}}return n}},{key:"setViewpoint",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e){var r=this.viewer,i=r.scene,a=i.camera,s=!1!==n.rayCast,o=!1!==n.immediate,l=!1!==n.reset,u=i.realWorldOffset,c=!0===n.reverseClippingPlanes;if(i.clearSectionPlanes(),e.clipping_planes&&e.clipping_planes.length>0&&e.clipping_planes.forEach((function(e){var t=Ap(e.location,op),n=Ap(e.direction,op);c&&$.negateVec3(n),$.subVec3(t,u),a.yUp&&(t=vp(t),n=vp(n)),new aa(i,{pos:t,dir:n})})),i.clearLines(),e.lines&&e.lines.length>0){var f=[],p=[],A=0;e.lines.forEach((function(e){e.start_point&&e.end_point&&(f.push(e.start_point.x),f.push(e.start_point.y),f.push(e.start_point.z),f.push(e.end_point.x),f.push(e.end_point.y),f.push(e.end_point.z),p.push(A++),p.push(A++))})),new sp(i,{positions:f,indices:p,clippable:!1,collidable:!0})}if(i.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){var t=e.bitmap_type||"jpg",n=e.bitmap_data,r=Ap(e.location,lp),s=Ap(e.normal,up),o=Ap(e.up,cp),l=e.height||1;t&&n&&r&&s&&o&&(a.yUp&&(r=vp(r),s=vp(s),o=vp(o)),new Qa(i,{src:n,type:t,pos:r,normal:s,up:o,clippable:!1,collidable:!0,height:l}))})),l&&(i.setObjectsXRayed(i.xrayedObjectIds,!1),i.setObjectsHighlighted(i.highlightedObjectIds,!1),i.setObjectsSelected(i.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(i.setObjectsVisible(i.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.visible=!1}))}))):(i.setObjectsVisible(i.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.visible=!0}))})));var d=e.components.visibility.view_setup_hints;d&&(!1===d.spaces_visible&&i.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcSpace"),!0),void 0!==d.spaces_translucent&&i.setObjectsXRayed(r.metaScene.getObjectIDsByType("IfcSpace"),!0),d.space_boundaries_visible,!1===d.openings_visible&&i.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcOpening"),!0),d.space_boundaries_translucent,void 0!==d.openings_translucent&&i.setObjectsXRayed(r.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(i.setObjectsSelected(i.selectedObjectIds,!1),e.components.selection.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.selected=!0}))}))),e.components.translucency&&(i.setObjectsXRayed(i.xrayedObjectIds,!1),e.components.translucency.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.xrayed=!0}))}))),e.components.coloring&&e.components.coloring.forEach((function(e){var r=e.color,i=0,a=!1;8===r.length&&((i=parseInt(r.substring(0,2),16)/256)<=1&&i>=.95&&(i=1),r=r.substring(2),a=!0);var s=[parseInt(r.substring(0,2),16)/256,parseInt(r.substring(2,4),16)/256,parseInt(r.substring(4,6),16)/256];e.components.map((function(e){return t._withBCFComponent(n,e,(function(e){e.colorize=s,a&&(e.opacity=i)}))}))}))}if(e.perspective_camera||e.orthogonal_camera){var v,h,I,y;if(e.perspective_camera?(v=Ap(e.perspective_camera.camera_view_point,op),h=Ap(e.perspective_camera.camera_direction,op),I=Ap(e.perspective_camera.camera_up_vector,op),a.perspective.fov=e.perspective_camera.field_of_view,y="perspective"):(v=Ap(e.orthogonal_camera.camera_view_point,op),h=Ap(e.orthogonal_camera.camera_direction,op),I=Ap(e.orthogonal_camera.camera_up_vector,op),a.ortho.scale=e.orthogonal_camera.view_to_world_scale,y="ortho"),$.subVec3(v,u),a.yUp&&(v=vp(v),h=vp(h),I=vp(I)),s){var m=i.pick({pickSurface:!0,origin:v,direction:h});h=m?m.worldPos:$.addVec3(v,h,op)}else h=$.addVec3(v,h,op);o?(a.eye=v,a.look=h,a.up=I,a.projection=y):r.cameraFlight.flyTo({eye:v,look:h,up:I,duration:n.duration,projection:y})}}}},{key:"_withBCFComponent",value:function(e,t,n){var r=this.viewer,i=r.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){var a=t.authoring_tool_id,s=i.objects[a];if(s)return void n(s);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[a])return void i.withObjects(r.metaScene.getObjectIDsInSubtree(a),n)}if(t.ifc_guid){var o=t.ifc_guid,l=i.objects[o];if(l)return void n(l);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[o])return void i.withObjects(r.metaScene.getObjectIDsInSubtree(o),n);Object.keys(i.models).forEach((function(t){var a=$.globalizeObjectId(t,o),s=i.objects[a];s?n(s):e.updateCompositeObjects&&r.metaScene.metaObjects[a]&&i.withObjects(r.metaScene.getObjectIDsInSubtree(a),n)}))}}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this)}}]),n}();function pp(e){return{x:e[0],y:e[1],z:e[2]}}function Ap(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function dp(e){return new Float64Array([e[0],-e[2],e[1]])}function vp(e){return new Float64Array([e[0],e[2],-e[1]])}function hp(e){var t="";return t+=Math.round(255*e[0]).toString(16).padStart(2,"0"),t+=Math.round(255*e[1]).toString(16).padStart(2,"0"),t+=Math.round(255*e[2]).toString(16).padStart(2,"0")}var Ip=$.vec3(),yp=function(e,t,n,r){var i=e-n,a=t-r;return Math.sqrt(i*i+a*a)},mp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e.viewer.scene,i)).plugin=e,r._container=i.container,!r._container)throw"config missing: container";r._eventSubs={};var a=r.plugin.viewer.scene;r._originMarker=new qe(a,i.origin),r._targetMarker=new qe(a,i.target),r._originWorld=$.vec3(),r._targetWorld=$.vec3(),r._wp=new Float64Array(24),r._vp=new Float64Array(24),r._pp=new Float64Array(24),r._cp=new Float64Array(8),r._xAxisLabelCulled=!1,r._yAxisLabelCulled=!1,r._zAxisLabelCulled=!1,r._color=i.color||r.plugin.defaultColor;var s=i.onMouseOver?function(e){i.onMouseOver(e,w(r)),r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,o=i.onMouseLeave?function(e){i.onMouseLeave(e,w(r)),r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,l=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},u=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},c=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},f=i.onContextMenu?function(e){i.onContextMenu(e,w(r))}:null,p=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return r._originDot=new Ze(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._targetDot=new Ze(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._lengthWire=new Je(r._container,{color:r._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._xAxisWire=new Je(r._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._yAxisWire=new Je(r._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._zAxisWire=new Je(r._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._lengthLabel=new $e(r._container,{fillColor:r._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._xAxisLabel=new $e(r._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._yAxisLabel=new $e(r._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._zAxisLabel=new $e(r._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._wpDirty=!1,r._vpDirty=!1,r._cpDirty=!1,r._sectionPlanesDirty=!0,r._visible=!1,r._originVisible=!1,r._targetVisible=!1,r._wireVisible=!1,r._axisVisible=!1,r._xAxisVisible=!1,r._yAxisVisible=!1,r._zAxisVisible=!1,r._axisEnabled=!0,r._labelsVisible=!1,r._labelsOnWires=!1,r._clickable=!1,r._originMarker.on("worldPos",(function(e){r._originWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._targetMarker.on("worldPos",(function(e){r._targetWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._onViewMatrix=a.camera.on("viewMatrix",(function(){r._vpDirty=!0,r._needUpdate(0)})),r._onProjMatrix=a.camera.on("projMatrix",(function(){r._cpDirty=!0,r._needUpdate()})),r._onCanvasBoundary=a.canvas.on("boundary",(function(){r._cpDirty=!0,r._needUpdate(0)})),r._onMetricsUnits=a.metrics.on("units",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsScale=a.metrics.on("scale",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsOrigin=a.metrics.on("origin",(function(){r._cpDirty=!0,r._needUpdate()})),r._onSectionPlaneUpdated=a.on("sectionPlaneUpdated",(function(){r._sectionPlanesDirty=!0,r._needUpdate()})),r.approximate=i.approximate,r.visible=i.visible,r.originVisible=i.originVisible,r.targetVisible=i.targetVisible,r.wireVisible=i.wireVisible,r.axisVisible=i.axisVisible,r.xAxisVisible=i.xAxisVisible,r.yAxisVisible=i.yAxisVisible,r.zAxisVisible=i.zAxisVisible,r.labelsVisible=i.labelsVisible,r.labelsOnWires=i.labelsOnWires,r}return P(n,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&($.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._wp))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}var t=this._originMarker.viewPos[2],n=this._targetMarker.viewPos[2];if(t>-.3||n>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){$.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var r=this._pp,i=this._cp,a=e.canvas.canvas.getBoundingClientRect(),s=this._container.getBoundingClientRect(),o=a.top-s.top,l=a.left-s.left,u=e.canvas.boundary,c=u[2],f=u[3],p=0,A=this.plugin.viewer.scene.metrics,d=A.scale,v=A.units,h=A.unitsInfo[v].abbrev,I=0,y=r.length;I<y;I+=4)i[p]=l+Math.floor((1+r[I+0]/r[I+3])*c/2),i[p+1]=o+Math.floor((1-r[I+1]/r[I+3])*f/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{var m=35;this._xAxisLabel.setPosOnWire(i[0],i[1]+m,i[6],i[7]+m),m+=35,this._yAxisLabel.setPosOnWire(i[0],i[1]+m,i[6],i[7]+m),m+=35,this._zAxisLabel.setPosOnWire(i[0],i[1]+m,i[6],i[7]+m)}var w=this._approximate?" ~ ":" = ";this._length=Math.abs($.lenVec3($.subVec3(this._targetWorld,this._originWorld,Ip))),this._lengthLabel.setText(w+(this._length*d).toFixed(2)+h);var g=Math.abs(yp(i[0],i[1],i[2],i[3])),E=Math.abs(yp(i[2],i[3],i[4],i[5])),T=Math.abs(yp(i[4],i[5],i[6],i[7])),b=this.plugin.labelMinAxisLength;this.labelsOnWires?(this._xAxisLabelCulled=g<b,this._yAxisLabelCulled=E<b,this._zAxisLabelCulled=T<b):(this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1),this._xAxisLabelCulled?this._xAxisLabel.setCulled(!0):(this._xAxisLabel.setText(w+Math.abs((this._targetWorld[0]-this._originWorld[0])*d).toFixed(2)+h),this._xAxisLabel.setCulled(!this.axisVisible)),this._yAxisLabelCulled?this._yAxisLabel.setCulled(!0):(this._yAxisLabel.setText(w+Math.abs((this._targetWorld[1]-this._originWorld[1])*d).toFixed(2)+h),this._yAxisLabel.setCulled(!this.axisVisible)),this._zAxisLabelCulled?this._zAxisLabel.setCulled(!0):(this._zAxisLabel.setText(w+Math.abs((this._targetWorld[2]-this._originWorld[2])*d).toFixed(2)+h),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}}}},{key:"_isSliced",value:function(e){for(var t=this.scene._sectionPlanesState.sectionPlanes,n=0,r=t.length;n<r;n++){var i=t[n];if($.planeClipsPositions3(i.pos,i.dir,e,4))return!0}return!1}},{key:"approximate",get:function(){return this._approximate},set:function(e){e=!1!==e,this._approximate!==e&&(this._approximate=e,this._cpDirty=!0,this._needUpdate(0))}},{key:"origin",get:function(){return this._originMarker}},{key:"target",get:function(){return this._targetMarker}},{key:"length",get:function(){this._update();var e=this.plugin.viewer.scene.metrics.scale;return this._length*e}},{key:"color",get:function(){return this._color},set:function(e){this._color=e,this._originDot.setFillColor(e),this._targetDot.setFillColor(e),this._lengthWire.setColor(e),this._lengthLabel.setFillColor(e)}},{key:"visible",get:function(){return this._visible},set:function(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);var t=this._visible&&this._axisVisible&&this._xAxisVisible,n=this._visible&&this._axisVisible&&this._yAxisVisible,r=this._visible&&this._axisVisible&&this._zAxisVisible;this._xAxisWire.setVisible(t),this._yAxisWire.setVisible(n),this._zAxisWire.setVisible(r),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled),this._yAxisLabel.setVisible(n&&!this._yAxisLabelCulled),this._zAxisLabel.setVisible(r&&!this._zAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"originVisible",get:function(){return this._originVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultOriginVisible,this._originVisible=e,this._originDot.setVisible(this._visible&&this._originVisible)}},{key:"targetVisible",get:function(){return this._targetVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultTargetVisible,this._targetVisible=e,this._targetDot.setVisible(this._visible&&this._targetVisible)}},{key:"axisEnabled",get:function(){return this._axisEnabled},set:function(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()}},{key:"axisVisible",get:function(){return this._axisVisible},set:function(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()}},{key:"xAxisVisible",get:function(){return this._xAxisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._xAxisVisible=e;var t=this._visible&&this._axisVisible&&this._xAxisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"yAxisVisible",get:function(){return this._yAxisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._yAxisVisible=e;var t=this._visible&&this._axisVisible&&this._yAxisVisible&&this._axisEnabled;this._yAxisWire.setVisible(t),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"zAxisVisible",get:function(){return this._zAxisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._zAxisVisible=e;var t=this._visible&&this._axisVisible&&this._zAxisVisible&&this._axisEnabled;this._zAxisWire.setVisible(t),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"wireVisible",get:function(){return this._wireVisible},set:function(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)}},{key:"labelsVisible",get:function(){return this._labelsVisible},set:function(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()}},{key:"labelsOnWires",get:function(){return this._labelsOnWires},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultLabelsOnWires,this._labelsOnWires=e}},{key:"setHighlighted",value:function(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)}},{key:"clickable",get:function(){return this._clickable},set:function(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)}},{key:"destroy",value:function(){var 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(),d(g(n.prototype),"destroy",this).call(this)}}]),n}(),wp=function(e){h(n,me);var t=y(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"active",get:function(){}},{key:"snapping",get:function(){return!0},set:function(e){}},{key:"activate",value:function(){}},{key:"deactivate",value:function(){}},{key:"reset",value:function(){}},{key:"destroy",value:function(){}}]),n}(),gp=function(e){h(n,wp);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e.viewer.scene)).pointerLens=i.pointerLens,r._active=!1,r._currentDistanceMeasurement=null,r._currentDistanceMeasurementInitState={wireVisible:null,axisVisible:null,xAxisVisible:null,yaxisVisible:null,zAxisVisible:null,targetVisible:null},r._initMarkerDiv(),r._onCameraControlHoverSnapOrSurface=null,r._onCameraControlHoverSnapOrSurfaceOff=null,r._onMouseDown=null,r._onMouseUp=null,r._onCanvasTouchStart=null,r._onCanvasTouchEnd=null,r._snapping=!1!==i.snapping,r._mouseState=0,r._attachPlugin(e,i),r}return P(n,[{key:"_initMarkerDiv",value:function(){var e=document.createElement("div");e.setAttribute("id","myMarkerDiv");var t=this.scene.canvas.canvas;t.parentNode.insertBefore(e,t),e.style.background="black",e.style.border="2px solid blue",e.style.borderRadius="10px",e.style.width="5px",e.style.height="5px",e.style.margin="-200px -200px",e.style.zIndex="100",e.style.position="absolute",e.style.pointerEvents="none",this._markerDiv=e}},{key:"_destroyMarkerDiv",value:function(){if(this._markerDiv){var e=document.getElementById("myMarkerDiv");e.parentNode.removeChild(e),this._markerDiv=null}}},{key:"_attachPlugin",value:function(e){this.distanceMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){this._markerDiv||this._initMarkerDiv(),this.fire("activated",!0);var t=this.distanceMeasurementsPlugin,n=this.scene,r=t.viewer.cameraControl,i=n.canvas.canvas;n.input;var a,s,o=!1,l=$.vec3(),u=$.vec2(),c=null;this._mouseState=0,this._onCameraControlHoverSnapOrSurface=r.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(function(t){var n=t.snappedCanvasPos||t.canvasPos;if(o=!0,l.set(t.worldPos),u.set(t.canvasPos),0===e._mouseState){var r=i.getBoundingClientRect(),a=window.pageXOffset||document.documentElement.scrollLeft,s=window.pageYOffset||document.documentElement.scrollTop,f=r.left+a,p=r.top+s;e._markerDiv.style.marginLeft="".concat(f+n[0]-5,"px"),e._markerDiv.style.marginTop="".concat(p+n[1]-5,"px"),e._markerDiv.style.background="pink",t.snappedToVertex||t.snappedToEdge?(e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.snappedCanvasPos||t.canvasPos,e.pointerLens.snapped=!0),e._markerDiv.style.background="greenyellow",e._markerDiv.style.border="2px solid green"):(e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.canvasPos,e.pointerLens.snapped=!1),e._markerDiv.style.background="pink",e._markerDiv.style.border="2px solid red"),c=t.entity}else e._markerDiv.style.marginLeft="-10000px",e._markerDiv.style.marginTop="-10000px";i.style.cursor="pointer",e._currentDistanceMeasurement&&(e._currentDistanceMeasurement.wireVisible=e._currentDistanceMeasurementInitState.wireVisible,e._currentDistanceMeasurement.axisVisible=e._currentDistanceMeasurementInitState.axisVisible&&e.distanceMeasurementsPlugin.defaultAxisVisible,e._currentDistanceMeasurement.xAxisVisible=e._currentDistanceMeasurementInitState.xAxisVisible&&e.distanceMeasurementsPlugin.defaultXAxisVisible,e._currentDistanceMeasurement.yAxisVisible=e._currentDistanceMeasurementInitState.yAxisVisible&&e.distanceMeasurementsPlugin.defaultYAxisVisible,e._currentDistanceMeasurement.zAxisVisible=e._currentDistanceMeasurementInitState.zAxisVisible&&e.distanceMeasurementsPlugin.defaultZAxisVisible,e._currentDistanceMeasurement.targetVisible=e._currentDistanceMeasurementInitState.targetVisible,e._currentDistanceMeasurement.target.worldPos=l.slice(),e._markerDiv.style.marginLeft="-10000px",e._markerDiv.style.marginTop="-10000px")})),i.addEventListener("mousedown",this._onMouseDown=function(e){1===e.which&&(a=e.clientX,s=e.clientY)}),i.addEventListener("mouseup",this._onMouseUp=function(n){1===n.which&&(n.clientX>a+20||n.clientX<a-20||n.clientY>s+20||n.clientY<s-20||(e._currentDistanceMeasurement?o?(e._currentDistanceMeasurement.target.entity=c,c=null,e._currentDistanceMeasurement.clickable=!0,e.distanceMeasurementsPlugin.fire("measurementEnd",e._currentDistanceMeasurement),e._currentDistanceMeasurement=null):(e._currentDistanceMeasurement.destroy(),e.distanceMeasurementsPlugin.fire("measurementCancel",e._currentDistanceMeasurement),e._currentDistanceMeasurement=null,c=null):o&&(e._currentDistanceMeasurement=t.createMeasurement({id:$.createUUID(),origin:{worldPos:l.slice()},target:{worldPos:l.slice()},approximate:!0}),e._currentDistanceMeasurementInitState.axisVisible=e._currentDistanceMeasurement.axisVisible&&e.distanceMeasurementsPlugin.defaultAxisVisible,e._currentDistanceMeasurementInitState.xAxisVisible=e._currentDistanceMeasurement.xAxisVisible&&e.distanceMeasurementsPlugin.defaultXAxisVisible,e._currentDistanceMeasurementInitState.yAxisVisible=e._currentDistanceMeasurement.yAxisVisible&&e.distanceMeasurementsPlugin.defaultYAxisVisible,e._currentDistanceMeasurementInitState.zAxisVisible=e._currentDistanceMeasurement.zAxisVisible&&e.distanceMeasurementsPlugin.defaultZAxisVisible,e._currentDistanceMeasurementInitState.wireVisible=e._currentDistanceMeasurement.wireVisible,e._currentDistanceMeasurementInitState.targetVisible=e._currentDistanceMeasurement.targetVisible,e._currentDistanceMeasurement.clickable=!1,e._currentDistanceMeasurement.origin.entity=c,c=null,e.fire("measurementStart",e._currentDistanceMeasurement))))}),this._onCameraControlHoverSnapOrSurfaceOff=r.on(this._snapping?"hoverSnapOrSurfaceOff":"hoverOff",(function(t){e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.snappedCanvasPos||t.canvasPos),o=!1,e._markerDiv.style.marginLeft="-100px",e._markerDiv.style.marginTop="-100px",e._currentDistanceMeasurement&&(e._currentDistanceMeasurement.wireVisible=!1,e._currentDistanceMeasurement.targetVisible=!1,e._currentDistanceMeasurement.axisVisible=!1),i.style.cursor="default"})),this._active=!0}}},{key:"deactivate",value:function(){if(this._active){this.fire("activated",!1),this.pointerLens&&(this.pointerLens.visible=!1),this._markerDiv&&this._destroyMarkerDiv(),this.reset();var e=this.scene.canvas.canvas;e.removeEventListener("mousedown",this._onMouseDown),e.removeEventListener("mouseup",this._onMouseUp);var 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}}},{key:"reset",value:function(){this._active&&(this._destroyMarkerDiv(),this._initMarkerDiv(),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null))}},{key:"destroy",value:function(){this.deactivate(),d(g(n.prototype),"destroy",this).call(this)}}]),n}(),Ep=function(e){h(n,Re);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"DistanceMeasurements",e))._pointerLens=i.pointerLens,r._container=i.container||document.body,r._defaultControl=null,r._measurements={},r.labelMinAxisLength=i.labelMinAxisLength,r.defaultVisible=!1!==i.defaultVisible,r.defaultOriginVisible=!1!==i.defaultOriginVisible,r.defaultTargetVisible=!1!==i.defaultTargetVisible,r.defaultWireVisible=!1!==i.defaultWireVisible,r.defaultLabelsVisible=!1!==i.defaultLabelsVisible,r.defaultAxisVisible=!1!==i.defaultAxisVisible,r.defaultXAxisVisible=!1!==i.defaultXAxisVisible,r.defaultYAxisVisible=!1!==i.defaultYAxisVisible,r.defaultZAxisVisible=!1!==i.defaultZAxisVisible,r.defaultColor=void 0!==i.defaultColor?i.defaultColor:"#00BBFF",r.zIndex=i.zIndex||1e4,r.defaultLabelsOnWires=!1!==i.defaultLabelsOnWires,r._onMouseOver=function(e,t){r.fire("mouseOver",{plugin:w(r),distanceMeasurement:t,measurement:t,event:e})},r._onMouseLeave=function(e,t){r.fire("mouseLeave",{plugin:w(r),distanceMeasurement:t,measurement:t,event:e})},r._onContextMenu=function(e,t){r.fire("contextMenu",{plugin:w(r),distanceMeasurement:t,measurement:t,event:e})},r}return P(n,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){}},{key:"pointerLens",get:function(){return this._pointerLens}},{key:"control",get:function(){return this._defaultControl||(this._defaultControl=new gp(this,{})),this._defaultControl}},{key:"measurements",get:function(){return this._measurements}},{key:"labelMinAxisLength",get:function(){return this._labelMinAxisLength},set:function(e){e<1&&(this.error("labelMinAxisLength must be >= 1; defaulting to 25"),e=25),this._labelMinAxisLength=e||25}},{key:"createMeasurement",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.viewer.scene.components[t.id]&&(this.error("Viewer scene component with this ID already exists: "+t.id),delete t.id);var n=t.origin,r=t.target,i=new mp(this,{id:t.id,plugin:this,container:this._container,origin:{entity:n.entity,worldPos:n.worldPos},target:{entity:r.entity,worldPos:r.worldPos},visible:t.visible,wireVisible:t.wireVisible,axisVisible:!1!==t.axisVisible&&!1!==this.defaultAxisVisible,xAxisVisible:!1!==t.xAxisVisible&&!1!==this.defaultXAxisVisible,yAxisVisible:!1!==t.yAxisVisible&&!1!==this.defaultYAxisVisible,zAxisVisible:!1!==t.zAxisVisible&&!1!==this.defaultZAxisVisible,labelsVisible:!1!==t.labelsVisible&&!1!==this.defaultLabelsVisible,originVisible:t.originVisible,targetVisible:t.targetVisible,color:t.color,labelsOnWires:!1!==t.labelsOnWires&&!1!==this.defaultLabelsOnWires,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[i.id]=i,i.on("destroyed",(function(){delete e._measurements[i.id]})),this.fire("measurementCreated",i),i}},{key:"destroyMeasurement",value:function(e){var t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("DistanceMeasurement not found: "+e)}},{key:"setLabelsShown",value:function(e){for(var t=0,n=Object.entries(this.measurements);t<n.length;t++){var r=f(n[t],2);r[0];r[1].labelShown=e}}},{key:"setAxisVisible",value:function(e){for(var t=0,n=Object.entries(this.measurements);t<n.length;t++){var r=f(n[t],2);r[0];r[1].axisVisible=e}this.defaultAxisVisible=e}},{key:"getAxisVisible",value:function(){return this.defaultAxisVisible}},{key:"clear",value:function(){for(var e=Object.keys(this._measurements),t=0,n=e.length;t<n;t++)this.destroyMeasurement(e[t])}},{key:"destroy",value:function(){this.clear(),d(g(n.prototype),"destroy",this).call(this)}}]),n}(),Tp=function(e){h(n,Re);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,"FastNav",e))._hideColorTexture=!1!==i.hideColorTexture,r._hidePBR=!1!==i.hidePBR,r._hideSAO=!1!==i.hideSAO,r._hideEdges=!1!==i.hideEdges,r._hideTransparentObjects=!!i.hideTransparentObjects,r._scaleCanvasResolution=!!i.scaleCanvasResolution,r._scaleCanvasResolutionFactor=i.scaleCanvasResolutionFactor||.6,r._delayBeforeRestore=!1!==i.delayBeforeRestore,r._delayBeforeRestoreSeconds=i.delayBeforeRestoreSeconds||.5;var a=1e3*r._delayBeforeRestoreSeconds,s=!1,o=function(){a=1e3*r._delayBeforeRestoreSeconds,s||(e.scene._renderer.setColorTextureEnabled(!r._hideColorTexture),e.scene._renderer.setPBREnabled(!r._hidePBR),e.scene._renderer.setSAOEnabled(!r._hideSAO),e.scene._renderer.setTransparentEnabled(!r._hideTransparentObjects),e.scene._renderer.setEdgesEnabled(!r._hideEdges),r._scaleCanvasResolution?e.scene.canvas.resolutionScale=r._scaleCanvasResolutionFactor:e.scene.canvas.resolutionScale=1,s=!0)},l=function(){e.scene.canvas.resolutionScale=1,e.scene._renderer.setEdgesEnabled(!0),e.scene._renderer.setColorTextureEnabled(!0),e.scene._renderer.setPBREnabled(!0),e.scene._renderer.setSAOEnabled(!0),e.scene._renderer.setTransparentEnabled(!0),s=!1};r._onCanvasBoundary=e.scene.canvas.on("boundary",o),r._onCameraMatrix=e.scene.camera.on("matrix",o),r._onSceneTick=e.scene.on("tick",(function(e){s&&(a-=e.deltaTime,(!r._delayBeforeRestore||a<=0)&&l())}));var u=!1;return r._onSceneMouseDown=e.scene.input.on("mousedown",(function(){u=!0})),r._onSceneMouseUp=e.scene.input.on("mouseup",(function(){u=!1})),r._onSceneMouseMove=e.scene.input.on("mousemove",(function(){u&&o()})),r}return P(n,[{key:"hideColorTexture",get:function(){return this._hideColorTexture},set:function(e){this._hideColorTexture=e}},{key:"hidePBR",get:function(){return this._hidePBR},set:function(e){this._hidePBR=e}},{key:"hideSAO",get:function(){return this._hideSAO},set:function(e){this._hideSAO=e}},{key:"hideEdges",get:function(){return this._hideEdges},set:function(e){this._hideEdges=e}},{key:"hideTransparentObjects",get:function(){return this._hideTransparentObjects},set:function(e){this._hideTransparentObjects=!1!==e}},{key:"scaleCanvasResolution",get:function(){return this._scaleCanvasResolution},set:function(e){this._scaleCanvasResolution=e}},{key:"scaleCanvasResolutionFactor",get:function(){return this._scaleCanvasResolutionFactor},set:function(e){this._scaleCanvasResolutionFactor=e||.6}},{key:"delayBeforeRestore",get:function(){return this._delayBeforeRestore},set:function(e){this._delayBeforeRestore=e}},{key:"delayBeforeRestoreSeconds",get:function(){return this._delayBeforeRestoreSeconds},set:function(e){this._delayBeforeRestoreSeconds=null!=e?e:.5}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.scene.camera.off(this._onCameraMatrix),this.viewer.scene.canvas.off(this._onCanvasBoundary),this.viewer.scene.input.off(this._onSceneMouseDown),this.viewer.scene.input.off(this._onSceneMouseUp),this.viewer.scene.input.off(this._onSceneMouseMove),this.viewer.scene.off(this._onSceneTick),d(g(n.prototype),"destroy",this).call(this)}}]),n}(),bp=function(){function e(){b(this,e)}return P(e,[{key:"getMetaModel",value:function(e,t,n){le.loadJSON(e,(function(e){t(e)}),(function(e){n(e)}))}},{key:"getGLTF",value:function(e,t,n){le.loadArraybuffer(e,(function(e){t(e)}),(function(e){n(e)}))}},{key:"getGLB",value:function(e,t,n){le.loadArraybuffer(e,(function(e){t(e)}),(function(e){n(e)}))}},{key:"getArrayBuffer",value:function(e,t,n,r){!function(e,t,n,r){var i=function(){};n=n||i,r=r||i;var a=/^data:(.*?)(;base64)?,(.*)$/,s=t.match(a);if(s){var o=!!s[2],l=s[3];l=window.decodeURIComponent(l),o&&(l=window.atob(l));try{for(var u=new ArrayBuffer(l.length),c=new Uint8Array(u),f=0;f<l.length;f++)c[f]=l.charCodeAt(f);he.scheduleTask((function(){n(u)}))}catch(e){he.scheduleTask((function(){r(e)}))}}else{var p=function(e){var t=e.lastIndexOf("/");return 0!==t?e.substring(0,t+1):""}(e),A=p+t,d=new XMLHttpRequest;d.open("GET",A,!0),d.responseType="arraybuffer",d.onreadystatechange=function(){4===d.readyState&&(200===d.status?n(d.response):r("loadArrayBuffer error : "+d.response))},d.send(null)}}(e,t,(function(e){n(e)}),(function(e){r(e)}))}}]),e}();var Dp=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b(this,e),this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=t.messages,this.locale=t.locale}return P(e,[{key:"messages",set:function(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}},{key:"loadMessages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var t in e)this._messages[t]=e[t];this.messages=this._messages}},{key:"clearMessages",value:function(){this.messages={}}},{key:"locales",get:function(){return this._locales}},{key:"locale",get:function(){return this._locale},set:function(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}},{key:"translate",value:function(e,t){var n=this._messages[this._locale];if(!n)return null;var r=Pp(e,n);return r?t?Cp(r,t):r:null}},{key:"translatePlurals",value:function(e,t,n){var r=this._messages[this._locale];if(!r)return null;var i=Pp(e,r);return(i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one)?(i=Cp(i,[t]),n&&(i=Cp(i,n)),i):null}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==n&&(this._events[e]=t||!0);var r=this._eventSubs[e];if(r)for(var i in r){if(r.hasOwnProperty(i))r[i].callback(t)}}},{key:"on",value:function(e,t){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new G),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});var n=this._eventSubs[e];n||(n={},this._eventSubs[e]=n);var r=this._eventSubIDMap.addItem();n[r]={callback:t},this._eventSubEvents[r]=e;var i=this._events[e];return void 0!==i&&t(i),r}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var n=this._eventSubs[t];n&&delete n[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function Pp(e,t){if(t[e])return t[e];for(var n=e.split("."),r=t,i=0,a=n.length;r&&i<a;i++){r=r[n[i]]}return r}function Cp(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,n){return"{{"===e?"{":"}}"===e?"}":t[n]}))}var _p=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).t=i.t,r}return P(n,[{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"tangent",get:function(){return this.getTangent(this._t)}},{key:"length",get:function(){var e=this._getLengths();return e[e.length-1]}},{key:"getTangent",value:function(e){var t=1e-4;void 0===e&&(e=this._t);var n=e-t,r=e+t;n<0&&(n=0),r>1&&(r=1);var i=this.getPoint(n),a=this.getPoint(r),s=$.subVec3(a,i,[]);return $.normalizeVec3(s,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,n=[];for(t=0;t<=e;t++)n.push(this.getPoint(t/e));return n}},{key:"_getLengths",value:function(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,n,r=[],i=this.getPoint(0),a=0;for(r.push(0),n=1;n<=e;n++)t=this.getPoint(n/e),a+=$.lenVec3($.subVec3(t,i,[])),r.push(a),i=t;return this.cacheArcLengths=r,r}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var n,r=this._getLengths(),i=0,a=r.length;n=t||e*r[a-1];for(var s,o=0,l=a-1;o<=l;)if((s=r[i=Math.floor(o+(l-o)/2)]-n)<0)o=i+1;else{if(!(s>0)){l=i;break}l=i-1}if(r[i=l]===n)return i/(a-1);var u=r[i];return(i+(n-u)/(r[i+1]-u))/(a-1)}}]),n}(),Rp=function(e){h(n,_p);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).points=i.points,r.t=i.t,r}return P(n,[{key:"points",get:function(){return this._points},set:function(e){this._points=e||[]}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=this.points;if(!(t.length<3)){var n=(t.length-1)*e,r=Math.floor(n),i=n-r,a=t[0===r?r:r-1],s=t[r],o=t[r>t.length-2?t.length-1:r+1],l=t[r>t.length-3?t.length-1:r+2],u=$.vec3();return u[0]=$.catmullRomInterpolate(a[0],s[0],o[0],l[0],i),u[1]=$.catmullRomInterpolate(a[1],s[1],o[1],l[1],i),u[2]=$.catmullRomInterpolate(a[2],s[2],o[2],l[2],i),u}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}},{key:"getJSON",value:function(){return{points:points,t:this._t}}}]),n}(),Bp=$.vec3(),Op=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._frames=[],r._eyeCurve=new Rp(w(r)),r._lookCurve=new Rp(w(r)),r._upCurve=new Rp(w(r)),i.frames&&(r.addFrames(i.frames),r.smoothFrameTimes(1)),r}return P(n,[{key:"type",get:function(){return"CameraPath"}},{key:"frames",get:function(){return this._frames}},{key:"eyeCurve",get:function(){return this._eyeCurve}},{key:"lookCurve",get:function(){return this._lookCurve}},{key:"upCurve",get:function(){return this._upCurve}},{key:"saveFrame",value:function(e){var t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}},{key:"addFrame",value:function(e,t,n,r){var i={t:e,eye:t.slice(0),look:n.slice(0),up:r.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}},{key:"addFrames",value:function(e){for(var t,n=0,r=e.length;n<r;n++)t=e[n],this.addFrame(t.t||0,t.eye,t.look,t.up)}},{key:"loadFrame",value:function(e){var t=this.scene.camera;e=(e/=this._frames[this._frames.length-1].t-this._frames[0].t)<0?0:e>1?1:e,t.eye=this._eyeCurve.getPoint(e,Bp),t.look=this._lookCurve.getPoint(e,Bp),t.up=this._upCurve.getPoint(e,Bp)}},{key:"sampleFrame",value:function(e,t,n,r){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,n),this._upCurve.getPoint(e,r)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=$.vec3(),n=0;this._frames[0].t=0;for(var r=[],i=1,a=this._frames.length;i<a;i++){var s=$.lenVec3($.subVec3(this._frames[i].eye,this._frames[i-1].eye,t));r[i]=s,n+=s}for(var o=1,l=this._frames.length;o<l;o++){var u=r[o]/n*e;this._frames[o].t=this._frames[o-1].t+u}}}},{key:"clearFrames",value:function(){this._frames=[],this._eyeCurve.points=[],this._lookCurve.points=[],this._upCurve.points=[]}}]),n}(),Sp=$.vec3(),Np=$.vec3(),Lp=$.vec3(),xp=$.vec3(),Mp=$.vec3(),Fp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._look1=$.vec3(),r._eye1=$.vec3(),r._up1=$.vec3(),r._look2=$.vec3(),r._eye2=$.vec3(),r._up2=$.vec3(),r._orthoScale1=1,r._orthoScale2=1,r._flying=!1,r._flyEyeLookUp=!1,r._flyingEye=!1,r._flyingLook=!1,r._callback=null,r._callbackScope=null,r._time1=null,r._time2=null,r.easing=!1!==i.easing,r.duration=i.duration,r.fit=i.fit,r.fitFOV=i.fitFOV,r.trail=i.trail,r}return P(n,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,n){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=n;var r,i,a,s,o,l=this.scene.camera,u=!!e.projection&&e.projection!==l.projection;if(this._eye1[0]=l.eye[0],this._eye1[1]=l.eye[1],this._eye1[2]=l.eye[2],this._look1[0]=l.look[0],this._look1[1]=l.look[1],this._look1[2]=l.look[2],this._up1[0]=l.up[0],this._up1[1]=l.up[1],this._up1[2]=l.up[2],this._orthoScale1=l.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)i=e.eye,a=e.look,s=e.up;else if(e.eye)i=e.eye;else if(e.look)a=e.look;else{var c=e;if((le.isNumeric(c)||le.isString(c))&&(o=c,!(c=this.scene.components[o])))return this.error("Component not found: "+le.inQuotes(o)),void(t&&(n?t.call(n):t()));u||(r=c.aabb||this.scene.aabb)}var f=e.poi;if(r){if(r[3]<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();var p=$.getAABB3Center(r);this._look2=f||p;var A=$.subVec3(this._eye1,this._look1,Sp),d=$.normalizeVec3(A),v=f?$.getAABB3DiagPoint(r,f):$.getAABB3Diag(r),h=e.fitFOV||this._fitFOV,I=Math.abs(v/Math.tan(h*$.DEGTORAD));this._orthoScale2=1.1*v,this._eye2[0]=this._look2[0]+d[0]*I,this._eye2[1]=this._look2[1]+d[1]*I,this._eye2[2]=this._look2[2]+d[2]*I,this._up2[0]=this._up1[0],this._up2[1]=this._up1[1],this._up2[2]=this._up1[2],this._flyingEyeLookUp=!0}else(i||a||s)&&(this._flyingEyeLookUp=!!i&&!!a&&!!s,this._flyingEye=!!i&&!a,this._flyingLook=!!a&&!i,i&&(this._eye2[0]=i[0],this._eye2[1]=i[1],this._eye2[2]=i[2]),a&&(this._look2[0]=a[0],this._look2[1]=a[1],this._look2[2]=a[2]),s&&(this._up2[0]=s[0],this._up2[1]=s[1],this._up2[2]=s[2]));u?("ortho"===e.projection&&"ortho"!==l.projection&&(this._projection2="ortho",this._projMatrix1=l.projMatrix.slice(),this._projMatrix2=l.ortho.matrix.slice(),l.projection="customProjection"),"perspective"===e.projection&&"perspective"!==l.projection&&(this._projection2="perspective",this._projMatrix1=l.projMatrix.slice(),this._projMatrix2=l.perspective.matrix.slice(),l.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,he.scheduleTask(this._update,this)}},{key:"jumpTo",value:function(e){this._jumpTo(e)}},{key:"_jumpTo",value:function(e){this._flying&&this.stop();var t,n,r,i,a,s=this.scene.camera;if(e.aabb)t=e.aabb;else if(6===e.length)t=e;else if(e.eye||e.look||e.up)r=e.eye,i=e.look,a=e.up;else{var o=e;if((le.isNumeric(o)||le.isString(o))&&(n=o,!(o=this.scene.components[n])))return void this.error("Component not found: "+le.inQuotes(n));t=o.aabb||this.scene.aabb}var l=e.poi;if(t){if(t[3]<=t[0]||t[4]<=t[1]||t[5]<=t[2])return;var u,c=l?$.getAABB3DiagPoint(t,l):$.getAABB3Diag(t);i=l||$.getAABB3Center(t,i),this._trail?$.subVec3(s.look,i,Mp):$.subVec3(s.eye,s.look,Mp),$.normalizeVec3(Mp),u=(void 0!==e.fit?e.fit:this._fit)?Math.abs(c/Math.tan((e.fitFOV||this._fitFOV)*$.DEGTORAD)):$.lenVec3($.subVec3(s.eye,s.look,Sp)),$.mulVec3Scalar(Mp,u),s.eye=$.addVec3(i,Mp,Sp),s.look=i,this.scene.camera.ortho.scale=1.1*c}else(r||i||a)&&(r&&(s.eye=r),i&&(s.look=i),a&&(s.up=a));e.projection&&(s.projection=e.projection)}},{key:"_update",value:function(){if(this._flying){var e=(Date.now()-this._time1)/(this._time2-this._time1),t=e>=1;e>1&&(e=1);var r=this.easing?n._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?($.subVec3(i.eye,i.look,Mp),i.eye=$.lerpVec3(r,0,1,this._eye1,this._eye2,Lp),i.look=$.subVec3(Lp,Mp,Np)):this._flyingLook&&(i.look=$.lerpVec3(r,0,1,this._look1,this._look2,Np),i.up=$.lerpVec3(r,0,1,this._up1,this._up2,xp)):this._flyingEyeLookUp&&(i.eye=$.lerpVec3(r,0,1,this._eye1,this._eye2,Lp),i.look=$.lerpVec3(r,0,1,this._look1,this._look2,Np),i.up=$.lerpVec3(r,0,1,this._up1,this._up2,xp)),this._projection2){var a="ortho"===this._projection2?n._easeOutExpo(e,0,1,1):n._easeInCubic(e,0,1,1);i.customProjection.matrix=$.lerpMat4(a,0,1,this._projMatrix1,this._projMatrix2)}else i.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return i.ortho.scale=this._orthoScale2,void this.stop();he.scheduleTask(this._update,this)}}},{key:"stop",value:function(){if(this._flying){this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);var e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}}},{key:"cancel",value:function(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}},{key:"duration",get:function(){return this._duration/1e3},set:function(e){this._duration=e?1e3*e:500,this.stop()}},{key:"fit",get:function(){return this._fit},set:function(e){this._fit=!1!==e}},{key:"fitFOV",get:function(){return this._fitFOV},set:function(e){this._fitFOV=e||45}},{key:"trail",get:function(){return this._trail},set:function(e){this._trail=!!e}},{key:"destroy",value:function(){this.stop(),d(g(n.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,n,r){return n*(e/=r)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,n,r){return n*(1-Math.pow(2,-10*e/r))+t}}]),n}(),Hp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cameraFlightAnimation=new Fp(w(r)),r._t=0,r.state=n.SCRUBBING,r._playingFromT=0,r._playingToT=0,r._playingRate=i.playingRate||1,r._playingDir=1,r._lastTime=null,r.cameraPath=i.cameraPath,r._tick=r.scene.on("tick",r._updateT,w(r)),r}return P(n,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,r,i=performance.now(),a=this._lastTime?.001*(i-this._lastTime):0;if(this._lastTime=i,0!==a)switch(this.state){case n.SCRUBBING:return;case n.PLAYING:if(this._t+=this._playingRate*a,0===(t=this._cameraPath.frames.length)||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=n.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case n.PLAYING_TO:r=this._t+this._playingRate*a*this._playingDir,(this._playingDir<0&&r<=this._playingToT||this._playingDir>0&&r>=this._playingToT)&&(r=this._playingToT,this.state=n.SCRUBBING,this.fire("stopped")),this._t=r,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"cameraPath",get:function(){return this._cameraPath},set:function(e){this._cameraPath=e}},{key:"rate",get:function(){return this._playingRate},set:function(e){this._playingRate=e}},{key:"play",value:function(){this._cameraPath&&(this._lastTime=null,this.state=n.PLAYING)}},{key:"playToT",value:function(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=n.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var n=t.frames[e];n?this.playToT(n.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var r=this._cameraPath;if(r){var i=r.frames[e];i?(this.state=n.SCRUBBING,this._cameraFlightAnimation.flyTo(i,t)):this.error("flyToFrame - frame index out of range: "+e)}}},{key:"scrubToT",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=n.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=n.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=n.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),n}();Hp.STOPPED=0,Hp.SCRUBBING=1,Hp.PLAYING=2,Hp.PLAYING_TO=3;var Up=$.vec3(),Gp=$.vec3();$.vec3();var kp=$.vec3([0,-1,0]),jp=$.vec4([0,0,0,1]),Vp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._src=null,r._image=null,r._pos=$.vec3(),r._origin=$.vec3(),r._rtcPos=$.vec3(),r._dir=$.vec3(),r._size=1,r._imageSize=$.vec2(),r._texture=new Oa(w(r)),r._plane=new Zi(w(r),{geometry:new Rn(w(r),ja({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Ln(w(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0}),clippable:i.clippable}),r._grid=new Zi(w(r),{geometry:new Rn(w(r),ka({size:1,divisions:10})),material:new Ln(w(r),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:i.clippable}),r._node=new va(w(r),{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[r._plane,r._grid]}),r._gridVisible=!1,r.visible=!0,r.gridVisible=i.gridVisible,r.position=i.position,r.rotation=i.rotation,r.dir=i.dir,r.size=i.size,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"visible",get:function(){return this._plane.visible},set:function(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}},{key:"gridVisible",get:function(){return this._gridVisible},set:function(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),Se(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}},{key:"rotation",get:function(){return this._node.rotation},set:function(e){this._node.rotation=e}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"dir",get:function(){return this._dir},set:function(e){if(this._dir.set(e||[0,0,-1]),e){var t=this.scene.center,n=[-this._dir[0],-this._dir[1],-this._dir[2]];$.subVec3(t,this.position,Up);var r=-$.dotVec3(n,Up);$.normalizeVec3(n),$.mulVec3Scalar(n,r,Gp),$.vec3PairToQuaternion(kp,e,jp),this._node.quaternion=jp}}},{key:"collidable",get:function(){return this._node.collidable},set:function(e){this._node.collidable=!1!==e}},{key:"clippable",get:function(){return this._node.clippable},set:function(e){this._node.clippable=!1!==e}},{key:"pickable",get:function(){return this._node.pickable},set:function(e){this._node.pickable=!1!==e}},{key:"opacity",get:function(){return this._node.opacity},set:function(e){this._node.opacity=e}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],n=this._imageSize[1];if(t>n){var r=n/t;this._node.scale=[e,1,e*r]}else{var i=t/n;this._node.scale=[e*i,1,e]}}}]),n}(),Qp=function(e){h(n,vn);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=w(r=t.call(this,e,i));r._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var s=r.scene.camera,o=r.scene.canvas;return r._onCameraViewMatrix=s.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=s.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=o.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new zt({type:"point",pos:$.vec3([1,1,1]),color:$.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(a._shadowViewMatrixDirty){a._shadowViewMatrix||(a._shadowViewMatrix=$.identityMat4());var e=a._state.pos,t=s.look,n=s.up;$.lookAtMat4v(e,t,n,a._shadowViewMatrix),a._shadowViewMatrixDirty=!1}return a._shadowViewMatrix},getShadowProjMatrix:function(){if(a._shadowProjMatrixDirty){a._shadowProjMatrix||(a._shadowProjMatrix=$.identityMat4());var e=a.scene.canvas.canvas;$.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,a._shadowProjMatrix),a._shadowProjMatrixDirty=!1}return a._shadowProjMatrix},getShadowRenderBuf:function(){return a._shadowRenderBuf||(a._shadowRenderBuf=new Gt(a.scene.canvas.canvas,a.scene.canvas.gl,{size:[1024,1024]})),a._shadowRenderBuf}}),r.pos=i.pos,r.color=i.color,r.intensity=i.intensity,r.constantAttenuation=i.constantAttenuation,r.linearAttenuation=i.linearAttenuation,r.quadraticAttenuation=i.quadraticAttenuation,r.castsShadow=i.castsShadow,r.scene._lightCreated(w(r)),r}return P(n,[{key:"type",get:function(){return"PointLight"}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"constantAttenuation",get:function(){return this._state.attenuation[0]},set:function(e){this._state.attenuation[0]=e||0,this.glRedraw()}},{key:"linearAttenuation",get:function(){return this._state.attenuation[1]},set:function(e){this._state.attenuation[1]=e||0,this.glRedraw()}},{key:"quadraticAttenuation",get:function(){return this._state.attenuation[2]},set:function(e){this._state.attenuation[2]=e||0,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),d(g(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}();function Wp(e){return 0==(e&e-1)}function zp(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var Kp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=(r=t.call(this,e,i)).scene.canvas.gl;return r._state=new zt({texture:new Da({gl:a,target:a.TEXTURE_CUBE_MAP}),flipY:r._checkFlipY(i.minFilter),encoding:r._checkEncoding(i.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),r._src=i.src,r._images=[],r._loadSrc(i.src),re.memory.textures++,r}return P(n,[{key:"type",get:function(){return"CubeTexture"}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}},{key:"_loadSrc",value:function(e){var t=this,n=this.scene.canvas.gl;this._images=[];for(var r=!1,i=0,a=function(a){var s,o,l=new Image;l.onload=(s=l,o=a,function(){if(!r&&(s=function(e){if(!Wp(e.width)||!Wp(e.height)){var t=document.createElement("canvas");t.width=zp(e.width),t.height=zp(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(s),t._images[o]=s,6==++i)){var e=t._state.texture;e||(e=new Da({gl:n,target:n.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}),l.onerror=function(){r=!0},l.src=e[a]},s=0;s<e.length;s++)a(s)}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),re.memory.textures--,this._state.destroy()}}]),n}(),Yp=function(e){h(n,Kp);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightsState.addReflectionMap(r._state),r.scene._reflectionMapCreated(w(r)),r}return P(n,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),n}(),Xp=function(e){h(n,Kp);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightMapCreated(w(r)),r}return P(n,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),n}(),qp=function(e){h(n,qe);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,{entity:i.entity,occludable:i.occludable,worldPos:i.worldPos}))._occluded=!1,r._visible=!0,r._src=null,r._image=null,r._pos=$.vec3(),r._origin=$.vec3(),r._rtcPos=$.vec3(),r._dir=$.vec3(),r._size=1,r._imageSize=$.vec2(),r._texture=new Oa(w(r),{src:i.src}),r._geometry=new Rn(w(r),{primitive:"triangles",positions:[3,3,0,-3,3,0,-3,-3,0,3,-3,0],normals:[-1,0,0,-1,0,0,-1,0,0,-1,0,0],uv:[1,-1,0,-1,0,0,1,0],indices:[0,1,2,0,2,3]}),r._mesh=new Zi(w(r),{geometry:r._geometry,material:new Ln(w(r),{ambient:[.9,.3,.9],shininess:30,diffuseMap:r._texture,backfaces:!0}),scale:[1,1,1],position:i.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),r.visible=!0,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,r.size=i.size,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,d(g(n.prototype),"_setVisible",this).call(this,e)}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"collidable",get:function(){return this._mesh.collidable},set:function(e){this._mesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._mesh.clippable},set:function(e){this._mesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._mesh.pickable},set:function(e){this._mesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._mesh.opacity},set:function(e){this._mesh.opacity=e}},{key:"_updatePlaneSizeFromImage",value:function(){var e=.5*this._size,t=this._imageSize[0],n=this._imageSize[1],r=n/t;this._geometry.positions=t>n?[e,e*r,0,-e,e*r,0,-e,-e*r,0,e,-e*r,0]:[e/r,e,0,-e/r,e,0,-e/r,-e,0,e/r,-e,0]}}]),n}(),Jp=function(){function e(t){b(this,e),this._eye=$.vec3(),this._look=$.vec3(),this._up=$.vec3(),this._projection={},t&&this.saveCamera(t)}return P(e,[{key:"saveCamera",value:function(e){var t=e.camera,n=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:n.fov,fovAxis:n.fovAxis,near:n.near,far:n.far};break;case"ortho":this._projection={projection:"ortho",scale:n.scale,near:n.near,far:n.far};break;case"frustum":this._projection={projection:"frustum",left:n.left,right:n.right,top:n.top,bottom:n.bottom,near:n.near,far:n.far};break;case"custom":this._projection={projection:"custom",matrix:n.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var n=e.camera,r=this._projection;function i(){switch(r.type){case"perspective":n.perspective.fov=r.fov,n.perspective.fovAxis=r.fovAxis,n.perspective.near=r.near,n.perspective.far=r.far;break;case"ortho":n.ortho.scale=r.scale,n.ortho.near=r.near,n.ortho.far=r.far;break;case"frustum":n.frustum.left=r.left,n.frustum.right=r.right,n.frustum.top=r.top,n.frustum.bottom=r.bottom,n.frustum.near=r.near,n.frustum.far=r.far;break;case"custom":n.customProjection.matrix=r.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:r.scale,projection:r.projection},(function(){i(),t()})):(n.eye=this._eye,n.look=this._look,n.up=this._up,i(),n.projection=r.projection)}}]),e}(),Zp=$.vec3(),$p=function(){function e(t){if(b(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,t){var n=t.metaScene.scene;this.saveObjects(n,t)}}return P(e,[{key:"saveObjects",value:function(e,t,n){this.numObjects=0,this._mask=n?le.apply(n,{}):null;for(var r=!n||n.visible,i=!n||n.edges,a=!n||n.xrayed,s=!n||n.highlighted,o=!n||n.selected,l=!n||n.clippable,u=!n||n.pickable,c=!n||n.colorize,f=!n||n.opacity,p=t.metaObjects,A=e.objects,d=0,v=p.length;d<v;d++){var h=A[p[d].id];if(h){if(r&&(this.objectsVisible[d]=h.visible),i&&(this.objectsEdges[d]=h.edges),a&&(this.objectsXrayed[d]=h.xrayed),s&&(this.objectsHighlighted[d]=h.highlighted),o&&(this.objectsSelected[d]=h.selected),l&&(this.objectsClippable[d]=h.clippable),u&&(this.objectsPickable[d]=h.pickable),c){var I=h.colorize;this.objectsColorize[3*d+0]=I[0],this.objectsColorize[3*d+1]=I[1],this.objectsColorize[3*d+2]=I[2]}f&&(this.objectsOpacity[d]=h.opacity),this.numObjects++}}}},{key:"restoreObjects",value:function(e,t){for(var n=this._mask,r=!n||n.visible,i=!n||n.edges,a=!n||n.xrayed,s=!n||n.highlighted,o=!n||n.selected,l=!n||n.clippable,u=!n||n.pickable,c=!n||n.colorize,f=!n||n.opacity,p=t.metaObjects,A=e.objects,d=0,v=p.length;d<v;d++){var h=A[p[d].id];h&&(r&&(h.visible=this.objectsVisible[d]),i&&(h.edges=this.objectsEdges[d]),a&&(h.xrayed=this.objectsXrayed[d]),s&&(h.highlighted=this.objectsHighlighted[d]),o&&(h.selected=this.objectsSelected[d]),l&&(h.clippable=this.objectsClippable[d]),u&&(h.pickable=this.objectsPickable[d]),c&&(Zp[0]=this.objectsColorize[3*d+0],Zp[1]=this.objectsColorize[3*d+1],Zp[2]=this.objectsColorize[3*d+2],h.colorize=Zp),f&&(h.opacity=this.objectsOpacity[d]))}}}]),e}(),eA=$.vec3(),tA=function(){function e(){b(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}return P(e,[{key:"saveObjects",value:function(e,t){this.numObjects=0,this._mask=t?le.apply(t,{}):null;var n=e.objects,r=!t||t.visible,i=!t||t.edges,a=!t||t.xrayed,s=!t||t.highlighted,o=!t||t.selected,l=!t||t.clippable,u=!t||t.pickable,c=!t||t.colorize,f=!t||t.opacity;for(var p in n)if(n.hasOwnProperty(p)){var A=n[p],d=this.numObjects;if(r&&(this.objectsVisible[d]=A.visible),i&&(this.objectsEdges[d]=A.edges),a&&(this.objectsXrayed[d]=A.xrayed),s&&(this.objectsHighlighted[d]=A.highlighted),o&&(this.objectsSelected[d]=A.selected),l&&(this.objectsClippable[d]=A.clippable),u&&(this.objectsPickable[d]=A.pickable),c){var v=A.colorize;v?(this.objectsColorize[3*d+0]=v[0],this.objectsColorize[3*d+1]=v[1],this.objectsColorize[3*d+2]=v[2],this.objectsHasColorize[d]=!0):this.objectsHasColorize[d]=!1}f&&(this.objectsOpacity[d]=A.opacity),this.numObjects++}}},{key:"restoreObjects",value:function(e){var t=this._mask,n=!t||t.visible,r=!t||t.edges,i=!t||t.xrayed,a=!t||t.highlighted,s=!t||t.selected,o=!t||t.clippable,l=!t||t.pickable,u=!t||t.colorize,c=!t||t.opacity,f=0,p=e.objects;for(var A in p)if(p.hasOwnProperty(A)){var d=p[A];n&&(d.visible=this.objectsVisible[f]),r&&(d.edges=this.objectsEdges[f]),i&&(d.xrayed=this.objectsXrayed[f]),a&&(d.highlighted=this.objectsHighlighted[f]),s&&(d.selected=this.objectsSelected[f]),o&&(d.clippable=this.objectsClippable[f]),l&&(d.pickable=this.objectsPickable[f]),u&&(this.objectsHasColorize[f]?(eA[0]=this.objectsColorize[3*f+0],eA[1]=this.objectsColorize[3*f+1],eA[2]=this.objectsColorize[3*f+2],d.colorize=eA):d.colorize=null),c&&(d.opacity=this.objectsOpacity[f]),f++}}}]),e}(),nA=function(e){h(n,_p);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.v3=i.v3,r.t=i.t,r}return P(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||$.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||$.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||$.vec3([0,0,0])}},{key:"v3",get:function(){return this._v3},set:function(e){this.fire("v3",this._v3=e||$.vec3([0,0,0]))}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=$.vec3();return t[0]=$.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=$.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=$.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}]),n}(),rA=function(e){h(n,_p);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cachedLengths=[],r._dirty=!0,r._curves=[],r._t=0,r._dirtySubs=[],r._destroyedSubs=[],r.curves=i.curves||[],r.t=i.t,r}return P(n,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,n,r;for(e=e||[],n=0,r=this._curves.length;n<r;n++)(t=this._curves[n]).off(this._dirtySubs[n]),t.off(this._destroyedSubs[n]);this._curves=[],this._dirtySubs=[],this._destroyedSubs=[];var i=this;function a(){i._dirty=!0}function s(){var e=this.id;for(n=0,r=i._curves.length;n<r;n++)if(i._curves[n].id===e)return i._curves=i._curves.slice(n,n+1),i._dirtySubs=i._dirtySubs.slice(n,n+1),i._destroyedSubs=i._destroyedSubs.slice(n,n+1),void(i._dirty=!0)}for(n=0,r=e.length;n<r;n++){if(t=e[n],le.isNumeric(t)||le.isString(t)){var o=t;if(!(t=this.scene.components[o])){this.error("Component not found: "+_inQuotes(o));continue}}var l=t.type;"xeokit.SplineCurve"===l||"xeokit.Path"===l||"xeokit.CubicBezierCurve"===l||"xeokit.QuadraticBezierCurve"===l?(this._curves.push(t),this._dirtySubs.push(t.on("dirty",a)),this._destroyedSubs.push(t.once("destroyed",s))):this.error("Component "+_inQuotes(t.id)+" is not a xeokit.SplineCurve, xeokit.Path or xeokit.QuadraticBezierCurve")}this._dirty=!0}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"length",get:function(){var e=this._getCurveLengths();return e[e.length-1]}},{key:"getPoint",value:function(e){for(var t,n=e*this.length,r=this._getCurveLengths(),i=0;i<r.length;){if(r[i]>=n){var a=1-(r[i]-n)/(t=this._curves[i]).length;return t.getPointAt(a)}i++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],n=0,r=this._curves.length;for(e=0;e<r;e++)n+=this._curves[e].length,t.push(n);return this._cachedLengths=t,this._dirty=!1,t}},{key:"_getJSON",value:function(){for(var e=[],t=0,n=this._curves.length;t<n;t++)e.push(this._curves[t].id);return{curves:e,t:this._t}}},{key:"destroy",value:function(){var e,t,r;for(d(g(n.prototype),"destroy",this).call(this),e=0,t=this._curves.length;e<t;e++)(r=this._curves[e]).off(this._dirtySubs[e]),r.off(this._destroyedSubs[e])}}]),n}(),iA=function(e){h(n,_p);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.t=i.t,r}return P(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||$.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||$.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||$.vec3([0,0,0])}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=$.vec3();return t[0]=$.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=$.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=$.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}]),n}(),aA=function(e){h(n,ip);var t=y(n);function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),t.call(this,e,r)}return P(n)}(),sA=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._skyboxMesh=new Zi(w(r),{geometry:new Rn(w(r),{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new Ln(w(r),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Oa(w(r),{src:i.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:i.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),r.size=i.size,r.active=i.active,r}return P(n,[{key:"size",get:function(){return this._size},set:function(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}},{key:"active",get:function(){return this._skyboxMesh.visible},set:function(e){this._skyboxMesh.visible=e}}]),n}(),oA=function(){function e(){b(this,e)}return P(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),lA=$.vec4(),uA=$.vec4(),cA=$.vec3(),fA=$.vec3(),pA=$.vec3(),AA=$.vec4(),dA=$.vec4(),vA=$.vec4(),hA=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"dollyToCanvasPos",value:function(e,t,n){var r=!1,i=this._scene.camera;if(e){var a=$.subVec3(e,i.eye,cA);r=$.lenVec3(a)<n}if("perspective"===i.projection){i.ortho.scale=i.ortho.scale-n;var s=this._unproject(t,AA),o=$.subVec3(s,i.eye,vA),l=$.mulVec3Scalar($.normalizeVec3(o),-n,[]);if(i.eye=[i.eye[0]-l[0],i.eye[1]-l[1],i.eye[2]-l[2]],i.look=[i.look[0]-l[0],i.look[1]-l[1],i.look[2]-l[2]],e){var u=$.subVec3(e,i.eye,cA),c=$.lenVec3(u),f=$.mulVec3Scalar($.normalizeVec3($.subVec3(i.look,i.eye,fA)),c);i.look=[i.eye[0]+f[0],i.eye[1]+f[1],i.eye[2]+f[2]]}}else if("ortho"===i.projection){var p=this._unproject(t,AA);i.ortho.scale=i.ortho.scale-n,i.ortho._update();var A=this._unproject(t,dA),d=$.subVec3(A,p,vA),v=$.mulVec3Scalar($.normalizeVec3($.subVec3(i.look,i.eye,cA)),-n,fA),h=$.addVec3(d,v,pA);i.eye=[i.eye[0]-h[0],i.eye[1]-h[1],i.eye[2]-h[2]],i.look=[i.look[0]-h[0],i.look[1]-h[1],i.look[2]-h[2]]}return r}},{key:"_unproject",value:function(e,t){var n=this._scene.camera,r=n.project.transposedMatrix,i=r.subarray(8,12),a=r.subarray(12),s=[0,0,-1,1],o=$.dotVec4(s,i)/$.dotVec4(s,a);return n.project.unproject(e,o,lA,uA,t),t}},{key:"destroy",value:function(){}}]),e}(),IA=$.vec3(),yA=$.vec3(),mA=$.vec3(),wA=$.vec4(),gA=$.vec4(),EA=$.vec4(),TA=function(){function e(t,n){var r=this;b(this,e),this._scene=t,this._configs=n,this._pivotWorldPos=$.vec3(),this._cameraOffset=$.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=$.vec3(),this._rtcPos=$.vec3(),this._pivotViewPos=$.vec4(),this._pivotProjPos=$.vec4(),this._pivotCanvasPos=$.vec2(),this._cameraDirty=!0,this._onViewMatrix=this._scene.camera.on("viewMatrix",(function(){r._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(function(){r._cameraDirty=!0})),this._onTick=this._scene.on("tick",(function(){r.updatePivotElement(),r.updatePivotSphere()}))}return P(e,[{key:"createPivotSphere",value:function(){var e=this.getPivotPos(),t=$.vec3();$.decomposeMat4($.inverseMat4(this._scene.viewer.camera.viewMatrix,$.mat4()),t,$.vec4(),$.vec3());var n=$.distVec3(t,e),r=Math.tan(Math.PI/500)*n*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(r/=this._scene.camera.ortho.scale/2),Se(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new xa(this._scene,ta({radius:r})),this._pivotSphere=new Zi(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}},{key:"destroyPivotSphere",value:function(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}},{key:"updatePivotElement",value:function(){var e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){$.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,$.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);var n=t.boundary,r=n[2],i=n[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*r/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);var a=t._lastBoundingClientRect;if(!a||t._canvasSizeChanged){var s=t.canvas;a=t._lastBoundingClientRect=s.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(a.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(a.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}},{key:"updatePivotSphere",value:function(){this._pivoting&&this._pivotSphere&&(Se(this.getPivotPos(),this._rtcCenter,this._rtcPos),$.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}},{key:"setPivotElement",value:function(e){this._pivotElement=e}},{key:"enablePivotSphere",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);var t=e.color||[1,0,0];this._pivotSphereMaterial=new Ln(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}},{key:"disablePivotSphere",value:function(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}},{key:"startPivot",value:function(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;var e=this._scene.camera,t=$.lookAtMat4v(e.eye,e.look,e.worldUp);$.transformPoint3(t,this.getPivotPos(),this._cameraOffset);var n=this.getPivotPos();this._cameraOffset[2]+=$.distVec3(e.eye,n),t=$.inverseMat4(t);var r=$.transformVec3(t,this._cameraOffset),i=$.vec3();if($.subVec3(e.eye,n,i),$.addVec3(i,r),e.zUp){var a=i[1];i[1]=i[2],i[2]=a}this._radius=$.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}},{key:"_cameraLookingDownwards",value:function(){var e=this._scene.camera,t=$.normalizeVec3($.subVec3(e.look,e.eye,IA)),n=$.cross3Vec3(t,e.worldUp,yA);return $.sqLenVec3(n)<=1e-4}},{key:"getPivoting",value:function(){return this._pivoting}},{key:"setPivotPos",value:function(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}},{key:"setCanvasPivotPos",value:function(e){var t=this._scene.camera,n=Math.abs($.distVec3(this._scene.center,t.eye)),r=t.project.transposedMatrix,i=r.subarray(8,12),a=r.subarray(12),s=[0,0,-1,1],o=$.dotVec4(s,i)/$.dotVec4(s,a),l=wA;t.project.unproject(e,o,gA,EA,l);var u=$.normalizeVec3($.subVec3(l,t.eye,IA)),c=$.addVec3(t.eye,$.mulVec3Scalar(u,n,yA),mA);this.setPivotPos(c)}},{key:"getPivotPos",value:function(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}},{key:"continuePivot",value:function(e,t){if(this._pivoting&&(0!==e||0!==t)){var n=this._scene.camera,r=-e,i=-t;1===n.worldUp[2]&&(r=-r),this._azimuth+=.01*-r,this._polar+=.01*i,this._polar=$.clamp(this._polar,.001,Math.PI-.001);var a=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===n.worldUp[2]){var s=a[1];a[1]=a[2],a[2]=s}var o=$.lenVec3($.subVec3(n.look,n.eye,$.vec3())),l=this.getPivotPos();$.addVec3(a,l);var u=$.lookAtMat4v(a,l,n.worldUp);u=$.inverseMat4(u);var c=$.transformVec3(u,this._cameraOffset);u[12]-=c[0],u[13]-=c[1],u[14]-=c[2];var f=[u[8],u[9],u[10]];n.eye=[u[12],u[13],u[14]],$.subVec3(n.eye,$.mulVec3Scalar(f,o),n.look),n.up=[u[4],u[5],u[6]],this.showPivot()}}},{key:"showPivot",value:function(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}},{key:"hidePivot",value:function(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}},{key:"endPivot",value:function(){this._pivoting=!1}},{key:"destroy",value:function(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}]),e}(),bA=function(){function e(t,n){b(this,e),this._scene=t.scene,this._cameraControl=t,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=n,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=$.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}return P(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){var e="".concat(~~this.pickCursorPos[0],"-").concat(~~this.pickCursorPos[1],"-").concat(this.scheduleSnapOrPick,"-").concat(this.schedulePickSurface,"-").concat(this.schedulePickEntity);if(this._lastHash!==e){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;var t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var n=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});n&&(n.snappedToEdge||n.snappedToVertex)?(this.snapPickResult=n,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var r=this.pickResult.canvasPos;if(r[0]===this.pickCursorPos[0]&&r[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){var i=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(i[0]===this.pickCursorPos[0]&&i[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}}}},{key:"fireEvents",value:function(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){var e=new yt;e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var t=this.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=t)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}]),e}(),DA=$.vec2(),PA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s,o,l,u=n.pickController,c=0,f=0,p=0,A=0,d=!1,v=$.vec3(),h=!0,I=this._scene.canvas.canvas,y=[];function m(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];I.style.cursor="move",w(),e&&g()}function w(){c=i.pointerCanvasPos[0],f=i.pointerCanvasPos[1],p=i.pointerCanvasPos[0],A=i.pointerCanvasPos[1]}function g(){u.pickCursorPos=i.pointerCanvasPos,u.schedulePickSurface=!0,u.update(),u.picked&&u.pickedSurface&&u.pickResult&&u.pickResult.worldPos?(d=!0,v.set(u.pickResult.worldPos)):d=!1}document.addEventListener("keydown",this._documentKeyDownHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!0}}),document.addEventListener("keyup",this._documentKeyUpHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!1}}),I.addEventListener("mousedown",this._mouseDownHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:y[t.input.KEY_SHIFT]||r.planView?(s=!0,m()):(s=!0,m(!1));break;case 2:o=!0,m();break;case 3:l=!0,r.panRightClick&&m()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=function(){if(r.active&&r.pointerEnabled&&(s||o||l)){var e=t.canvas.boundary,n=e[2],u=e[3],p=i.pointerCanvasPos[0],A=i.pointerCanvasPos[1];if(y[t.input.KEY_SHIFT]||r.planView||!r.panRightClick&&o||r.panRightClick&&l){var h=p-c,I=A-f,m=t.camera;if("perspective"===m.projection){var w=Math.abs(d?$.lenVec3($.subVec3(v,t.camera.eye,[])):t.camera.eyeLookDist)*Math.tan(m.perspective.fov/2*Math.PI/180);a.panDeltaX+=1.5*h*w/u,a.panDeltaY+=1.5*I*w/u}else a.panDeltaX+=.5*m.ortho.scale*(h/u),a.panDeltaY+=.5*m.ortho.scale*(I/u)}else!s||o||l||r.planView||(r.firstPerson?(a.rotateDeltaY-=(p-c)/n*r.dragRotationRate/2,a.rotateDeltaX+=(A-f)/u*(r.dragRotationRate/4)):(a.rotateDeltaY-=(p-c)/n*(1.5*r.dragRotationRate),a.rotateDeltaX+=(A-f)/u*(1.5*r.dragRotationRate)));c=p,f=A}}),I.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){r.active&&r.pointerEnabled&&i.mouseover&&(h=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:case 2:case 3:s=!1,o=!1,l=!1}}),I.addEventListener("mouseup",this._mouseUpHandler=function(e){if(r.active&&r.pointerEnabled){if(3===e.which){!function(e,t){if(e){for(var n=e.target,r=0,i=0,a=0,s=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,a+=n.scrollLeft,s+=n.scrollTop,n=n.offsetParent;t[0]=e.pageX+a-r,t[1]=e.pageY+s-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,DA);var t=DA[0],i=DA[1];Math.abs(t-p)<3&&Math.abs(i-A)<3&&n.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:DA,event:e},!0)}I.style.removeProperty("cursor")}}),I.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var E=1/60,T=null;I.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled){var t=performance.now()/1e3,n=null!==T?t-T:0;T=t,n>.05&&(n=.05),n<E&&(n=E);var s=Math.max(-1,Math.min(1,40*-e.deltaY));if(0!==s){var o=s/Math.abs(s);a.dollyDelta+=-o*n*r.mouseWheelDollyRate,h&&(i.followPointerDirty=!0,h=!1)}}},{passive:!0})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var 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)}}]),e}(),CA=$.vec3(),_A=$.vec3(),RA=$.vec3(),BA=$.vec3(),OA=$.vec3(),SA={eye:$.vec3(),look:$.vec3(),up:$.vec3()},NA=function(){function e(t,n,r,i){b(this,e),this._scene=t;var a=n.cameraControl,s=t.camera;this._onSceneKeyDown=t.input.on("keydown",(function(){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover){var e=a._isKeyDownForAction(a.AXIS_VIEW_RIGHT),o=a._isKeyDownForAction(a.AXIS_VIEW_BACK),l=a._isKeyDownForAction(a.AXIS_VIEW_LEFT),u=a._isKeyDownForAction(a.AXIS_VIEW_FRONT),c=a._isKeyDownForAction(a.AXIS_VIEW_TOP),f=a._isKeyDownForAction(a.AXIS_VIEW_BOTTOM);if(e||o||l||u||c||f){var p=t.aabb,A=$.getAABB3Diag(p);$.getAABB3Center(p,CA);var d=Math.abs(A/Math.tan(n.cameraFlight.fitFOV*$.DEGTORAD)),v=1.1*A;SA.orthoScale=v,e?(SA.eye.set($.addVec3(CA,$.mulVec3Scalar(s.worldRight,d,_A),OA)),SA.look.set(CA),SA.up.set(s.worldUp)):o?(SA.eye.set($.addVec3(CA,$.mulVec3Scalar(s.worldForward,d,_A),OA)),SA.look.set(CA),SA.up.set(s.worldUp)):l?(SA.eye.set($.addVec3(CA,$.mulVec3Scalar(s.worldRight,-d,_A),OA)),SA.look.set(CA),SA.up.set(s.worldUp)):u?(SA.eye.set($.addVec3(CA,$.mulVec3Scalar(s.worldForward,-d,_A),OA)),SA.look.set(CA),SA.up.set(s.worldUp)):c?(SA.eye.set($.addVec3(CA,$.mulVec3Scalar(s.worldUp,d,_A),OA)),SA.look.set(CA),SA.up.set($.normalizeVec3($.mulVec3Scalar(s.worldForward,1,RA),BA))):f&&(SA.eye.set($.addVec3(CA,$.mulVec3Scalar(s.worldUp,-d,_A),OA)),SA.look.set(CA),SA.up.set($.normalizeVec3($.mulVec3Scalar(s.worldForward,-1,RA)))),!r.firstPerson&&r.followPointer&&n.pivotController.setPivotPos(CA),n.cameraFlight.duration>0?n.cameraFlight.flyTo(SA,(function(){n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot()})):(n.cameraFlight.jumpTo(SA),n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot())}}}))}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.input.off(this._onSceneKeyDown)}}]),e}(),LA=function(){function e(t,n,r,i,a){var s=this;b(this,e),this._scene=t;var o=n.pickController,l=n.pivotController,u=n.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;var c=!1,f=!1,p=this._scene.canvas.canvas,A=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e&&e.entity?e.entity.aabb:t.aabb;if(r){var a=t.camera;$.subVec3(a.eye,a.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})},d=t.tickify(this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!c&&!f){var n=u.hasSubs("hover"),a=u.hasSubs("hoverEnter"),l=u.hasSubs("hoverOut"),p=u.hasSubs("hoverOff"),A=u.hasSubs("hoverSurface"),d=u.hasSubs("hoverSnapOrSurface");if(n||a||l||p||A||d)if(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=A,o.scheduleSnapOrPick=d,o.update(),o.pickResult){if(o.pickResult.entity){var v=o.pickResult.entity.id;s._lastPickedEntityId!==v&&(void 0!==s._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),u.fire("hoverEnter",o.pickResult,!0),s._lastPickedEntityId=v)}u.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&u.fire("hoverSurface",o.pickResult,!0)}else void 0!==s._lastPickedEntityId&&(u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),s._lastPickedEntityId=void 0),u.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)}});p.addEventListener("mousemove",d),p.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(c=!0),3===e.which&&(f=!0),1===e.which&&r.active&&r.pointerEnabled&&(i.mouseDownClientX=e.clientX,i.mouseDownClientY=e.clientY,i.mouseDownCursorX=i.pointerCanvasPos[0],i.mouseDownCursorY=i.pointerCanvasPos[1],!r.firstPerson&&r.followPointer&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===e.which))){var n=o.pickResult;n&&n.worldPos?(l.setPivotPos(n.worldPos),l.startPivot()):(r.smartPivot?l.setCanvasPivotPos(i.pointerCanvasPos):l.setPivotPos(t.camera.look),l.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(c=!1),3===e.which&&(f=!1),l.getPivoting()&&l.endPivot()}),p.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(r.active&&r.pointerEnabled&&(1===e.which&&(l.hidePivot(),!(Math.abs(e.clientX-i.mouseDownClientX)>3||Math.abs(e.clientY-i.mouseDownClientY)>3)))){var a=u.hasSubs("picked"),c=u.hasSubs("pickedNothing"),f=u.hasSubs("pickedSurface"),p=u.hasSubs("doublePicked"),d=u.hasSubs("doublePickedSurface"),v=u.hasSubs("doublePickedNothing");if(!(r.doublePickFlyTo||p||d||v))return(a||c||f)&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=f,o.update(),o.pickResult?(u.fire("picked",o.pickResult,!0),o.pickedSurface&&u.fire("pickedSurface",o.pickResult,!0)):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0)),void(s._clicks=0);if(s._clicks++,1===s._clicks){o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo,o.schedulePickSurface=f,o.update();var h=o.pickResult,I=o.pickedSurface;s._timeout=setTimeout((function(){h?(u.fire("picked",h,!0),I&&(u.fire("pickedSurface",h,!0),!r.firstPerson&&r.followPointer&&(n.pivotController.setPivotPos(h.worldPos),n.pivotController.startPivot()&&n.pivotController.showPivot()))):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0),s._clicks=0}),r.doubleClickTimeFrame)}else{if(null!==s._timeout&&(window.clearTimeout(s._timeout),s._timeout=null),o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo||p||d,o.schedulePickSurface=o.schedulePickEntity&&d,o.update(),o.pickResult){if(u.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&u.fire("doublePickedSurface",o.pickResult,!0),r.doublePickFlyTo&&(A(o.pickResult),!r.firstPerson&&r.followPointer)){var y=o.pickResult.entity.aabb,m=$.getAABB3Center(y);n.pivotController.setPivotPos(m),n.pivotController.startPivot()&&n.pivotController.showPivot()}}else if(u.fire("doublePickedNothing",{canvasPos:i.pointerCanvasPos},!0),r.doublePickFlyTo&&(A(),!r.firstPerson&&r.followPointer)){var w=t.aabb,g=$.getAABB3Center(w);n.pivotController.setPivotPos(g),n.pivotController.startPivot()&&n.pivotController.showPivot()}s._clicks=0}}},!1)}return P(e,[{key:"reset",value:function(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}]),e}(),xA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.input,o=[],l=t.canvas.canvas,u=!0;this._onSceneMouseMove=s.on("mousemove",(function(){u=!0})),this._onSceneKeyDown=s.on("keydown",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover&&(o[e]=!0,e===s.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=s.on("keyup",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(o[e]=!1,e===s.KEY_SHIFT&&(l.style.cursor=null),n.pivotController.getPivoting()&&n.pivotController.endPivot())})),this._onTick=t.on("tick",(function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover){var l=n.cameraControl,c=e.deltaTime/1e3;if(!r.planView){var f=l._isKeyDownForAction(l.ROTATE_Y_POS,o),p=l._isKeyDownForAction(l.ROTATE_Y_NEG,o),A=l._isKeyDownForAction(l.ROTATE_X_POS,o),d=l._isKeyDownForAction(l.ROTATE_X_NEG,o),v=c*r.keyboardRotationRate;(f||p||A||d)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),f?a.rotateDeltaY+=v:p&&(a.rotateDeltaY-=v),A?a.rotateDeltaX+=v:d&&(a.rotateDeltaX-=v),!r.firstPerson&&r.followPointer&&n.pivotController.startPivot())}if(!o[s.KEY_CTRL]&&!o[s.KEY_ALT]){var h=l._isKeyDownForAction(l.DOLLY_BACKWARDS,o),I=l._isKeyDownForAction(l.DOLLY_FORWARDS,o);if(h||I){var y=c*r.keyboardDollyRate;!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),I?a.dollyDelta-=y:h&&(a.dollyDelta+=y),u&&(i.followPointerDirty=!0,u=!1)}}var m=l._isKeyDownForAction(l.PAN_FORWARDS,o),w=l._isKeyDownForAction(l.PAN_BACKWARDS,o),g=l._isKeyDownForAction(l.PAN_LEFT,o),E=l._isKeyDownForAction(l.PAN_RIGHT,o),T=l._isKeyDownForAction(l.PAN_UP,o),b=l._isKeyDownForAction(l.PAN_DOWN,o),D=(o[s.KEY_ALT]?.3:1)*c*r.keyboardPanRate;(m||w||g||E||T||b)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),b?a.panDeltaY+=D:T&&(a.panDeltaY+=-D),E?a.panDeltaX+=-D:g&&(a.panDeltaX+=D),w?a.panDeltaZ+=D:m&&(a.panDeltaZ+=-D))}}))}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}]),e}(),MA=$.vec3(),FA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.camera,o=n.pickController,l=n.pivotController,u=n.panController,c=1,f=1,p=null;this._onTick=t.on("tick",(function(){if(r.active&&r.pointerEnabled){var e="default";if(Math.abs(a.dollyDelta)<.001&&(a.dollyDelta=0),Math.abs(a.rotateDeltaX)<.001&&(a.rotateDeltaX=0),Math.abs(a.rotateDeltaY)<.001&&(a.rotateDeltaY=0),0===a.rotateDeltaX&&0===a.rotateDeltaY||(a.dollyDelta=0),r.followPointer&&--c<=0&&(c=1,0!==a.dollyDelta)){if(0===a.rotateDeltaY&&0===a.rotateDeltaX&&r.followPointer&&i.followPointerDirty&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.pickResult&&o.pickResult.worldPos?p=o.pickResult.worldPos:(f=1,p=null),i.followPointerDirty=!1),p){var n=Math.abs($.lenVec3($.subVec3(p,t.camera.eye,MA)));f=n/r.dollyProximityThreshold}f<r.dollyMinSpeed&&(f=r.dollyMinSpeed)}var A=a.dollyDelta*f;if(0===a.rotateDeltaY&&0===a.rotateDeltaX||(!r.firstPerson&&r.followPointer&&l.getPivoting()?(l.continuePivot(a.rotateDeltaY,a.rotateDeltaX),l.showPivot()):(0!==a.rotateDeltaX&&(r.firstPerson?s.pitch(-a.rotateDeltaX):s.orbitPitch(a.rotateDeltaX)),0!==a.rotateDeltaY&&(r.firstPerson?s.yaw(a.rotateDeltaY):s.orbitYaw(a.rotateDeltaY))),a.rotateDeltaX*=r.rotationInertia,a.rotateDeltaY*=r.rotationInertia,e="grabbing"),Math.abs(a.panDeltaX)<.001&&(a.panDeltaX=0),Math.abs(a.panDeltaY)<.001&&(a.panDeltaY=0),Math.abs(a.panDeltaZ)<.001&&(a.panDeltaZ=0),0!==a.panDeltaX||0!==a.panDeltaY||0!==a.panDeltaZ){var d,v,h=$.vec3();if(h[0]=a.panDeltaX,h[1]=a.panDeltaY,h[2]=a.panDeltaZ,r.constrainVertical){s.xUp?(d=s.eye[0],v=s.look[0]):s.yUp?(d=s.eye[1],v=s.look[1]):s.zUp&&(d=s.eye[2],v=s.look[2]),s.pan(h);var I=s.eye,y=s.look;s.xUp?(I[0]=d,y[0]=v):s.yUp?(I[1]=d,y[1]=v):s.zUp&&(I[2]=d,y[2]=v),s.eye=I,s.look=y}else s.pan(h);e="grabbing"}if(a.panDeltaX*=r.panInertia,a.panDeltaY*=r.panInertia,a.panDeltaZ*=r.panInertia,0!==A){if(e=A<0?"zoom-in":"zoom-out",r.firstPerson){var m,w;if(r.constrainVertical&&(s.xUp?(m=s.eye[0],w=s.look[0]):s.yUp?(m=s.eye[1],w=s.look[1]):s.zUp&&(m=s.eye[2],w=s.look[2])),r.followPointer)u.dollyToCanvasPos(p,i.pointerCanvasPos,-A)&&(i.followPointerDirty=!0);else s.pan([0,0,A]),s.ortho.scale=s.ortho.scale-A;if(r.constrainVertical){var g=s.eye,E=s.look;s.xUp?(g[0]=m,E[0]=w):s.yUp?(g[1]=m,E[1]=w):s.zUp&&(g[2]=m,E[2]=w),s.eye=g,s.look=E}}else if(r.planView){if(r.followPointer)u.dollyToCanvasPos(p,i.pointerCanvasPos,-A)&&(i.followPointerDirty=!0);else s.ortho.scale=s.ortho.scale+A,s.zoom(A)}else{if(r.followPointer)u.dollyToCanvasPos(p,i.pointerCanvasPos,-A)&&(i.followPointerDirty=!0);else s.ortho.scale=s.ortho.scale+A,s.zoom(A)}a.dollyDelta*=r.dollyInertia}o.fireEvents(),document.body.style.cursor=e}}))}return P(e,[{key:"destroy",value:function(){this._scene.off(this._onTick)}}]),e}(),HA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=this._scene.canvas.canvas;s.addEventListener("mouseenter",this._mouseEnterHandler=function(){i.mouseover=!0}),s.addEventListener("mouseleave",this._mouseLeaveHandler=function(){i.mouseover=!1,s.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=function(e){UA(e,s,i.pointerCanvasPos)}),s.addEventListener("mousedown",this._mouseDownHandler=function(e){r.active&&r.pointerEnabled&&(UA(e,s,i.pointerCanvasPos),i.mouseover=!0)}),s.addEventListener("mouseup",this._mouseUpHandler=function(e){r.active&&r.pointerEnabled})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var 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)}}]),e}();function UA(e,t,n){if(e){var r=t.getBoundingClientRect(),i=r.x,a=r.y;n[0]=e.clientX-i,n[1]=e.clientY-a}else e=window.event,n[0]=e.x,n[1]=e.y;return n}var GA=function(e,t){if(e){for(var n=e.target,r=0,i=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;t[0]=e.pageX-r,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t},kA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=n.pickController,o=n.pivotController,l=$.vec2(),u=$.vec2(),c=$.vec2(),f=$.vec2(),p=[],A=this._scene.canvas.canvas,d=0,v=!1;this._onTick=t.on("tick",(function(){v=!1})),A.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){if(r.active&&r.pointerEnabled){e.preventDefault();var n=e.touches,a=e.changedTouches;for(i.touchStartTime=Date.now(),1===n.length&&1===a.length&&(GA(n[0],l),r.followPointer&&(s.pickCursorPos=l,s.schedulePickSurface=!0,s.update(),r.planView||(s.picked&&s.pickedSurface&&s.pickResult&&s.pickResult.worldPos?(o.setPivotPos(s.pickResult.worldPos),!r.firstPerson&&o.startPivot()&&o.showPivot()):(r.smartPivot?o.setCanvasPivotPos(i.pointerCanvasPos):o.setPivotPos(t.camera.look),!r.firstPerson&&o.startPivot()&&o.showPivot()))));p.length<n.length;)p.push($.vec2());for(var u=0,c=n.length;u<c;++u)GA(n[u],p[u]);d=n.length}}),A.addEventListener("touchend",this._canvasTouchEndHandler=function(){o.getPivoting()&&o.endPivot()}),A.addEventListener("touchmove",this._canvasTouchMoveHandler=function(e){if(r.active&&r.pointerEnabled&&(e.stopPropagation(),e.preventDefault(),!v)){v=!0;var n=t.canvas.boundary,o=n[2],l=n[3],A=e.touches;if(e.touches.length===d){if(1===d){GA(A[0],u),$.subVec2(u,p[0],f);var h=f[0],I=f[1];if(null!==i.longTouchTimeout&&(Math.abs(h)>r.longTapRadius||Math.abs(I)>r.longTapRadius)&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),r.planView){var y=t.camera;if("perspective"===y.projection){var m=Math.abs(t.camera.eyeLookDist)*Math.tan(y.perspective.fov/2*Math.PI/180);a.panDeltaX+=h*m/l*r.touchPanRate,a.panDeltaY+=I*m/l*r.touchPanRate}else a.panDeltaX+=.5*y.ortho.scale*(h/l)*r.touchPanRate,a.panDeltaY+=.5*y.ortho.scale*(I/l)*r.touchPanRate}else a.rotateDeltaY-=h/o*(1*r.dragRotationRate),a.rotateDeltaX+=I/l*(1.5*r.dragRotationRate)}else if(2===d){var w=A[0],g=A[1];GA(w,u),GA(g,c);var E=$.geometricMeanVec2(p[0],p[1]),T=$.geometricMeanVec2(u,c),b=$.vec2();$.subVec2(E,T,b);var D=b[0],P=b[1],C=t.camera,_=$.distVec2([w.pageX,w.pageY],[g.pageX,g.pageY]),R=($.distVec2(p[0],p[1])-_)*r.touchDollyRate;if(a.dollyDelta=R,Math.abs(R)<1)if("perspective"===C.projection){var B=s.pickResult?s.pickResult.worldPos:t.center,O=Math.abs($.lenVec3($.subVec3(B,t.camera.eye,[])))*Math.tan(C.perspective.fov/2*Math.PI/180);a.panDeltaX-=D*O/l*r.touchPanRate,a.panDeltaY-=P*O/l*r.touchPanRate}else a.panDeltaX-=.5*C.ortho.scale*(D/l)*r.touchPanRate,a.panDeltaY-=.5*C.ortho.scale*(P/l)*r.touchPanRate;i.pointerCanvasPos=T}for(var S=0;S<d;++S)GA(A[S],p[S])}}})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var 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)}}]),e}(),jA=function(e,t){if(e){for(var n=e.target,r=0,i=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;t[0]=e.pageX-r,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t},VA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s,o=n.pickController,l=n.cameraControl,u=[],c=new Float32Array(2),f=-1,p=-1,A=this._scene.canvas.canvas,d=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e?e.entity.aabb:t.aabb;if(r){var a=t.camera;$.subVec3(a.eye,a.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})};A.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){if(r.active&&r.pointerEnabled){null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null);var t=e.touches,a=e.changedTouches;if(s=Date.now(),1===t.length&&1===a.length){f=s,jA(t[0],c);var o=c[0],l=c[1],p=t[0].pageX,A=t[0].pageY;i.longTouchTimeout=setTimeout((function(){n.cameraControl.fire("rightClick",{pagePos:[Math.round(p),Math.round(A)],canvasPos:[Math.round(o),Math.round(l)],event:e},!0),i.longTouchTimeout=null}),r.longTapTimeout)}else f=-1;for(;u.length<t.length;)u.push(new Float32Array(2));for(var d=0,v=t.length;d<v;++d)jA(t[d],u[d]);u.length=t.length}},{passive:!0}),A.addEventListener("touchend",this._canvasTouchEndHandler=function(e){if(r.active&&r.pointerEnabled){var t=Date.now(),n=e.touches,a=e.changedTouches,s=l.hasSubs("pickedSurface");null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),0===n.length&&1===a.length&&f>-1&&t-f<150&&(p>-1&&f-p<325?(jA(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=s,o.update(),o.pickResult?(o.pickResult.touchInput=!0,l.fire("doublePicked",o.pickResult),o.pickedSurface&&l.fire("doublePickedSurface",o.pickResult),r.doublePickFlyTo&&d(o.pickResult)):(l.fire("doublePickedNothing"),r.doublePickFlyTo&&d()),p=-1):$.distVec2(u[0],c)<4&&(jA(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=s,o.update(),o.pickResult?(o.pickResult.touchInput=!0,l.fire("picked",o.pickResult),o.pickedSurface&&l.fire("pickedSurface",o.pickResult)):l.fire("pickedNothing"),p=t),f=-1),u.length=n.length;for(var A=0,v=n.length;A<v;++A)u[A][0]=n[A].pageX,u[A][1]=n[A].pageY}},{passive:!0})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler)}}]),e}(),QA=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i)).PAN_LEFT=0,r.PAN_RIGHT=1,r.PAN_UP=2,r.PAN_DOWN=3,r.PAN_FORWARDS=4,r.PAN_BACKWARDS=5,r.ROTATE_X_POS=6,r.ROTATE_X_NEG=7,r.ROTATE_Y_POS=8,r.ROTATE_Y_NEG=9,r.DOLLY_FORWARDS=10,r.DOLLY_BACKWARDS=11,r.AXIS_VIEW_RIGHT=12,r.AXIS_VIEW_BACK=13,r.AXIS_VIEW_LEFT=14,r.AXIS_VIEW_FRONT=15,r.AXIS_VIEW_TOP=16,r.AXIS_VIEW_BOTTOM=17,r._keyMap={},r.scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},r._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},r._states={pointerCanvasPos:$.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:$.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},r._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};var a=r.scene;return r._controllers={cameraControl:w(r),pickController:new bA(w(r),r._configs),pivotController:new TA(a,r._configs),panController:new hA(a),cameraFlight:new Fp(w(r),{duration:.5})},r._handlers=[new HA(r.scene,r._controllers,r._configs,r._states,r._updates),new kA(r.scene,r._controllers,r._configs,r._states,r._updates),new PA(r.scene,r._controllers,r._configs,r._states,r._updates),new NA(r.scene,r._controllers,r._configs,r._states,r._updates),new LA(r.scene,r._controllers,r._configs,r._states,r._updates),new VA(r.scene,r._controllers,r._configs,r._states,r._updates),new xA(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cameraUpdater=new FA(r.scene,r._controllers,r._configs,r._states,r._updates),r.navMode=i.navMode,i.planView&&(r.planView=i.planView),r.constrainVertical=i.constrainVertical,i.keyboardLayout?r.keyboardLayout=i.keyboardLayout:r.keyMap=i.keyMap,r.doublePickFlyTo=i.doublePickFlyTo,r.panRightClick=i.panRightClick,r.active=i.active,r.followPointer=i.followPointer,r.rotationInertia=i.rotationInertia,r.keyboardPanRate=i.keyboardPanRate,r.touchPanRate=i.touchPanRate,r.keyboardRotationRate=i.keyboardRotationRate,r.dragRotationRate=i.dragRotationRate,r.touchDollyRate=i.touchDollyRate,r.dollyInertia=i.dollyInertia,r.dollyProximityThreshold=i.dollyProximityThreshold,r.dollyMinSpeed=i.dollyMinSpeed,r.panInertia=i.panInertia,r.pointerEnabled=!0,r.keyboardDollyRate=i.keyboardDollyRate,r.mouseWheelDollyRate=i.mouseWheelDollyRate,r}return P(n,[{key:"keyMap",get:function(){return this._keyMap},set:function(e){if(e=e||"qwerty",le.isString(e)){var t=this.scene.input,n={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":n[this.PAN_LEFT]=[t.KEY_A],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_Z],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":n[this.PAN_LEFT]=[t.KEY_Q],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_W],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=n}else{var r=e;this._keyMap=r}}},{key:"_isKeyDownForAction",value:function(e,t){var n=this._keyMap[e];if(!n)return!1;t||(t=this.scene.input.keyDown);for(var r=0,i=n.length;r<i;r++){if(t[n[r]])return!0}return!1}},{key:"pivotElement",set:function(e){this._controllers.pivotController.setPivotElement(e)}},{key:"active",get:function(){return this._configs.active},set:function(e){e=!1!==e,this._configs.active=e,this._handlers[1]._active=e,this._handlers[5]._active=e}},{key:"snapToVertex",get:function(){return this._configs.snapToVertex},set:function(e){this._configs.snapToVertex=!!e}},{key:"snapToEdge",get:function(){return this._configs.snapToEdge},set:function(e){this._configs.snapToEdge=!!e}},{key:"snapRadius",get:function(){return this._configs.snapRadius},set:function(e){e=e||30,this._configs.snapRadius=e}},{key:"navMode",get:function(){return this._configs.navMode},set:function(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}},{key:"pointerEnabled",get:function(){return this._configs.pointerEnabled},set:function(e){this._reset(),this._configs.pointerEnabled=!!e}},{key:"_reset",value:function(){for(var e=0,t=this._handlers.length;e<t;e++){var n=this._handlers[e];n.reset&&n.reset()}this._updates.panDeltaX=0,this._updates.panDeltaY=0,this._updates.rotateDeltaX=0,this._updates.rotateDeltaY=0,this._updates.dolyDelta=0}},{key:"followPointer",get:function(){return this._configs.followPointer},set:function(e){this._configs.followPointer=!1!==e}},{key:"pivotPos",get:function(){return this._controllers.pivotController.getPivotPos()},set:function(e){this._controllers.pivotController.setPivotPos(e)}},{key:"dollyToPointer",get:function(){return this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer},set:function(e){this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer=e}},{key:"panToPointer",get:function(){return this.warn("panToPointer property is deprecated - replaced with followPointer"),!1},set:function(e){this.warn("panToPointer property is deprecated - replaced with followPointer")}},{key:"planView",get:function(){return this.warn("planView property is deprecated - replaced with navMode"),this._configs.planView},set:function(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")}},{key:"firstPerson",get:function(){return this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson},set:function(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())}},{key:"constrainVertical",get:function(){return this._configs.constrainVertical},set:function(e){this._configs.constrainVertical=!!e}},{key:"doublePickFlyTo",get:function(){return this._configs.doublePickFlyTo},set:function(e){this._configs.doublePickFlyTo=!1!==e}},{key:"panRightClick",get:function(){return this._configs.panRightClick},set:function(e){this._configs.panRightClick=!1!==e}},{key:"rotationInertia",get:function(){return this._configs.rotationInertia},set:function(e){this._configs.rotationInertia=null!=e?e:0}},{key:"keyboardPanRate",get:function(){return this._configs.keyboardPanRate},set:function(e){this._configs.keyboardPanRate=null!=e?e:5}},{key:"touchPanRate",get:function(){return this._configs.touchPanRate},set:function(e){this._configs.touchPanRate=null!=e?e:1}},{key:"keyboardRotationRate",get:function(){return this._configs.keyboardRotationRate},set:function(e){this._configs.keyboardRotationRate=null!=e?e:90}},{key:"dragRotationRate",get:function(){return this._configs.dragRotationRate},set:function(e){this._configs.dragRotationRate=null!=e?e:360}},{key:"keyboardDollyRate",get:function(){return this._configs.keyboardDollyRate},set:function(e){this._configs.keyboardDollyRate=null!=e?e:15}},{key:"touchDollyRate",get:function(){return this._configs.touchDollyRate},set:function(e){this._configs.touchDollyRate=null!=e?e:.2}},{key:"mouseWheelDollyRate",get:function(){return this._configs.mouseWheelDollyRate},set:function(e){this._configs.mouseWheelDollyRate=null!=e?e:100}},{key:"dollyInertia",get:function(){return this._configs.dollyInertia},set:function(e){this._configs.dollyInertia=null!=e?e:0}},{key:"dollyProximityThreshold",get:function(){return this._configs.dollyProximityThreshold},set:function(e){this._configs.dollyProximityThreshold=null!=e?e:35}},{key:"dollyMinSpeed",get:function(){return this._configs.dollyMinSpeed},set:function(e){this._configs.dollyMinSpeed=null!=e?e:.04}},{key:"panInertia",get:function(){return this._configs.panInertia},set:function(e){this._configs.panInertia=null!=e?e:.5}},{key:"keyboardLayout",get:function(){return this._configs.keyboardLayout},set:function(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}},{key:"enablePivotSphere",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._controllers.pivotController.enablePivotSphere(e)}},{key:"disablePivotSphere",value:function(){this._controllers.pivotController.disablePivotSphere()}},{key:"smartPivot",get:function(){return this._configs.smartPivot},set:function(e){this._configs.smartPivot=!1!==e}},{key:"doubleClickTimeFrame",get:function(){return this._configs.doubleClickTimeFrame},set:function(e){this._configs.doubleClickTimeFrame=null!=e?e:250}},{key:"destroy",value:function(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),d(g(n.prototype),"destroy",this).call(this)}},{key:"_destroyHandlers",value:function(){for(var e=0,t=this._handlers.length;e<t;e++){var n=this._handlers[e];n.destroy&&n.destroy()}}},{key:"_destroyControllers",value:function(){for(var e=0,t=this._controllers.length;e<t;e++){var n=this._controllers[e];n.destroy&&n.destroy()}}}]),n}(),WA=P((function e(t,n,r,i,a){b(this,e),this.name=t,this.type=r,this.value=n,this.valueType=i,this.description=a})),zA=P((function e(t){if(b(this,e),this.id=t.id,this.originalSystemId=t.originalSystemId,this.metaModels=[],this.name=t.name,this.type=t.type,this.properties=[],t.properties)for(var n=t.properties,r=0,i=n.length;r<i;r++){var a=n[r];this.properties.push(new WA(a.name,a.value,a.type,a.valueType,a.description))}})),KA=function(){function e(t){b(this,e),this.metaModels=[],this.id=t.id,this.parentId=t.parentId,this.parent=null,this.originalSystemId=t.originalSystemId,this.name=t.name,this.type=t.type,this.propertySetIds=t.propertySetIds,this.propertySets=[],this.attributes=t.attributes||{},void 0!==t.external&&null!==t.external&&(this.external=t.external)}return P(e,[{key:"metaModel",get:function(){return 1==this.metaModels.length?this.metaModels[0]:null}},{key:"getObjectIDsInSubtree",value:function(){var e=[];return function t(n){if(n){e.push(n.id);var r=n.children;if(r)for(var i=0,a=r.length;i<a;i++)t(r[i])}}(this),e}},{key:"withMetaObjectsInSubtree",value:function(e){!function t(n){if(n){e(n);var r=n.children;if(r)for(var i=0,a=r.length;i<a;i++)t(r[i])}}(this)}},{key:"getObjectIDsInSubtreeByType",value:function(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=e[n];var i=[];return function e(n){if(n){t[n.type]&&i.push(n.id);var r=n.children;if(r)for(var a=0,s=r.length;a<s;a++)e(r[a])}}(this),i}},{key:"getJSON",value:function(){var e={id:this.id,type:this.type,name:this.name};return this.parent&&(e.parent=this.parent.id),e}}]),e}(),YA=function(){function e(t){b(this,e),this.id=t.id,this.projectId=t.projectId,this.revisionId=t.revisionId,this.author=t.author,this.createdAt=t.createdAt,this.creatingApplication=t.creatingApplication,this.schema=t.schema,this.metaScene=t.metaScene,this.propertySets=[],this.rootMetaObjects=[],this.metaObjects=[],this.graph=t.graph||{},this.metaScene.metaModels[this.id]=this,this.finalized=!1}return P(e,[{key:"rootMetaObject",get:function(){return 1==this.rootMetaObjects.length?this.rootMetaObjects[0]:null}},{key:"loadData",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);var n=this.metaScene,r=e.properties;if(e.propertySets)for(var i=0,a=e.propertySets.length;i<a;i++){var s=e.propertySets[i],o=n.propertySets[s.id];o||(r&&this._decompressProperties(r,s.properties),o=new zA({id:s.id,originalSystemId:s.originalSystemId||s.id,type:s.type,name:s.name,properties:s.properties}),n.propertySets[o.id]=o),o.metaModels.push(this),this.propertySets.push(o)}if(e.metaObjects)for(var l=0,u=e.metaObjects.length;l<u;l++){var c=e.metaObjects[l],f=c.id,p=n.metaObjects[f];if(!p){var A=c.type,d=c.originalSystemId,v=c.propertySets||c.propertySetIds;p=new KA({id:f,originalSystemId:d,parentId:c.parent,type:A,name:c.name,attributes:c.attributes,propertySetIds:v,external:c.external}),this.metaScene.metaObjects[f]=p,p.metaModels=[]}this.metaObjects.push(p),c.parent||(this.rootMetaObjects.push(p),n.rootMetaObjects[f]=p)}}},{key:"_decompressProperties",value:function(e,t){for(var n=0,r=t.length;n<r;n++){var i=t[n];if(Number.isInteger(i)){var a=e[i];a&&(t[n]=a)}}}},{key:"finalize",value:function(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";var e=this.metaScene;for(var t in e.metaObjects){var n=e.metaObjects[t];if(n.children&&(n.children=[]),n.propertySets&&(n.propertySets=[]),n.propertySetIds)for(var r=0,i=n.propertySetIds.length;r<i;r++){var a=n.propertySetIds[r],s=e.propertySets[a];n.propertySets.push(s)}}for(var o in e.metaObjects){var l=e.metaObjects[o];if(l.parentId){var u=e.metaObjects[l.parentId];u&&(l.parent=u,(u.children||(u.children=[])).push(l))}}for(var c in e.metaObjects){e.metaObjects[c].metaModels=[]}for(var f in e.metaModels)for(var p=e.metaModels[f],A=0,d=p.metaObjects.length;A<d;A++){p.metaObjects[A].metaModels.push(p)}for(var v in e.metaObjectsByType={},e.metaObjects){var h=e.metaObjects[v],I=h.type;(e.metaObjectsByType[I]||(e.metaObjectsByType[I]={}))[v]=h}this.finalized=!0,this.metaScene.fire("metaModelCreated",this.id)}},{key:"getJSON",value:function(){for(var e={id:this.id,projectId:this.projectId,author:this.author,createdAt:this.createdAt,schema:this.schema,creatingApplication:this.creatingApplication,metaObjects:[],propertySets:[]},t=0,n=this.metaObjects.length;t<n;t++){var r=this.metaObjects[t],i={id:r.id,originalSystemId:r.originalSystemId,extId:r.extId,type:r.type,name:r.name};r.parent&&(i.parent=r.parent.id),r.attributes&&(i.attributes=r.attributes),r.propertySetIds&&(i.propertySetIds=r.propertySetIds),e.metaObjects.push(i)}for(var a=0,s=this.propertySets.length;a<s;a++){for(var o=this.propertySets[a],l={id:o.id,originalSystemId:o.originalSystemId,extId:o.extId,type:o.type,name:o.name,propertyies:[]},u=0,c=o.properties.length;u<c;u++){var f=o.properties[u],p={id:f.id,description:f.description,type:f.type,name:f.name,value:f.value,valueType:f.valueType};l.properties.push(p)}e.propertySets.push(l)}return e}},{key:"_globalizeIDs",value:function(e,t){var n=!!t.globalizeObjectIds;if(e.metaObjects)for(var r=0,i=e.metaObjects.length;r<i;r++){var a=e.metaObjects[r];if(a.originalSystemId=a.id,a.parent&&(a.originalParentSystemId=a.parent),n&&(a.id=$.globalizeObjectId(this.id,a.id),a.parent&&(a.parent=$.globalizeObjectId(this.id,a.parent))),n){var s=a.propertySetIds;if(s){for(var o=[],l=0,u=s.length;l<u;l++)o.push($.globalizeObjectId(this.id,s[l]));a.propertySetIds=o,a.originalSystemPropertySetIds=s}}else a.originalSystemPropertySetIds=a.propertySetIds}if(e.propertySets)for(var c=0,f=e.propertySets.length;c<f;c++){var p=e.propertySets[c];p.originalSystemId=p.id,n&&(p.id=$.globalizeObjectId(this.id,p.id))}}}]),e}(),XA=function(){function e(t,n){b(this,e),this.viewer=t,this.scene=n,this.metaModels={},this.propertySets={},this.metaObjects={},this.metaObjectsByType={},this.rootMetaObjects={},this._eventSubs={}}return P(e,[{key:"on",value:function(e,t){var n=this._eventSubs[e];n||(n=[],this._eventSubs[e]=n),n.push(t)}},{key:"fire",value:function(e,t){var n=this._eventSubs[e];if(n)for(var r=0,i=n.length;r<i;r++)n[r](t)}},{key:"off",value:function(e){}},{key:"createMetaModel",value:function(e,t){var n=new YA({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}},{key:"destroyMetaModel",value:function(e){var t=this.metaModels[e];if(t){if(t.propertySets)for(var n=0,r=t.propertySets.length;n<r;n++){var i=t.propertySets[n];if(1===i.metaModels.length&&i.metaModels[0].id===e)delete this.propertySets[i.id];else{for(var a=[],s=0,o=i.metaModels.length;s<o;s++)i.metaModels[s].id!==e&&a.push(i.metaModels[s]);i.metaModels=a}}if(t.metaObjects)for(var l=0,u=t.metaObjects.length;l<u;l++){var c=t.metaObjects[l];c.type;var f=c.id;1===c.metaModels.length&&c.metaModels[0].id===e&&(delete this.metaObjects[f],c.parent||delete this.rootMetaObjects[f])}for(var p in this.metaObjects){var A=this.metaObjects[p];if(A.children&&(A.children=[]),A.propertySets&&(A.propertySets=[]),A.propertySetIds)for(var d=0,v=A.propertySetIds.length;d<v;d++){var h=A.propertySetIds[d],I=this.propertySets[h];A.propertySets.push(I)}}for(var y in this.metaObjectsByType={},this.metaObjects){var m=this.metaObjects[y],w=m.type;m.children&&(m.children=null),(this.metaObjectsByType[w]||(this.metaObjectsByType[w]={}))[y]=m}for(var g in this.metaObjects){var E=this.metaObjects[g];if(E.parentId){var T=this.metaObjects[E.parentId];T&&(E.parent=T,(T.children||(T.children=[])).push(E))}}for(var b in delete this.metaModels[e],this.metaObjects){this.metaObjects[b].metaModels=[]}for(var D in this.metaModels)for(var P=this.metaModels[D],C=0,_=P.metaObjects.length;C<_;C++){P.metaObjects[C].metaModels.push(P)}this.fire("metaModelDestroyed",e)}}},{key:"getObjectIDsByType",value:function(e){var t=this.metaObjectsByType[e];return t?Object.keys(t):[]}},{key:"getObjectIDsInSubtree",value:function(e,t,n){var r=[],i=this.metaObjects[e],a=t&&t.length>0?qA(t):null,s=n&&n.length>0?qA(n):null;return function e(t){if(t){var n=!0;(s&&s[t.type]||a&&!a[t.type])&&(n=!1),n&&r.push(t.id);var i=t.children;if(i)for(var o=0,l=i.length;o<l;o++)e(i[o])}}(i),r}},{key:"withMetaObjectsInSubtree",value:function(e,t){var n=this.metaObjects[e];n&&n.withMetaObjectsInSubtree(t)}}]),e}();function qA(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=!0;return t}
17
+ **/var xf=null;function Mf(e,t){var n,r,i,a,s,o,l=3*e,u=3*t,c=Math.min(n=xf[l],r=xf[l+1],i=xf[l+2]),f=Math.min(a=xf[u],s=xf[u+1],o=xf[u+2]);if(c!==f)return c-f;var p=Math.max(n,r,i),A=Math.max(a,s,o);return p!==A?p-A:0}function Ff(e,t){for(var n=new Int32Array(e.length/3),r=0,i=n.length;r<i;r++)n[r]=r;xf=new Int32Array(e.length);for(var a=0,s=e.length;a<s;a++)xf[a]=e[a]>>t;n.sort(Mf);for(var o=new Int32Array(e.length),l=0,u=n.length;l<u;l++)o[3*l+0]=e[3*n[l]+0],o[3*l+1]=e[3*n[l]+1],o[3*l+2]=e[3*n[l]+2];return o}var Hf=null;function Uf(e,t){var n=Hf[2*e]-Hf[2*t];return 0!==n?n:Hf[2*e+1]-Hf[2*t+1]}function Gf(e){if(0===(e||[]).length)return[];for(var t=new Int32Array(e.length/2),n=0,r=t.length;n<r;n++)t[n]=n;for(var i=0,a=e.length;i<a;i+=2)if(e[i]>e[i+1]){var s=e[i];e[i]=e[i+1],e[i+1]=s}Hf=new Int32Array(e),t.sort(Uf);for(var o=new Int32Array(e.length),l=0,u=t.length;l<u;l++)o[2*l+0]=e[2*t[l]+0],o[2*l+1]=e[2*t[l]+1];return o}function kf(e,t){var n={},r={};e.forEach((function(e){for(var t=e.indices,i=e.edgeIndices,a=e.positionsCompressed,s=0,o=t.length;s<o;s+=3){var l=a[3*t[s]]+"_"+a[3*t[s]+1]+"_"+a[3*t[s]+2]+"/"+a[3*t[s+1]]+"_"+a[3*t[s+1]+1]+"_"+a[3*t[s+1]+2]+"/"+a[3*t[s+2]]+"_"+a[3*t[s+2]+1]+"_"+a[3*t[s+2]+2];n[l]=!0}e.edgeIndices.length/2;for(var u=0,c=i.length;u<c;u+=2){var f=a[3*i[u]]+"_"+a[3*i[u]+1]+"_"+a[3*i[u]+2]+"/"+a[3*i[u+1]]+"_"+a[3*i[u+1]+1]+"_"+a[3*i[u+1]+2]+"/";r[f]=!0}}));var i=t.indices;t.edgeIndices;for(var a=t.positionsCompressed,s=0,o=i.length;s<o;s+=3){var l=a[3*i[s]]+"_"+a[3*i[s]+1]+"_"+a[3*i[s]+2]+"/"+a[3*i[s+1]]+"_"+a[3*i[s+1]+1]+"_"+a[3*i[s+1]+2]+"/"+a[3*i[s+2]]+"_"+a[3*i[s+2]+1]+"_"+a[3*i[s+2]+2];if(!(l in n))throw console.log("Not found "+l),"Ohhhh!"}}var jf=$.vec4(4),Vf=$.vec4(),Qf=$.vec4(),Wf=$.vec3([1,0,0]),zf=$.vec3([0,1,0]),Kf=$.vec3([0,0,1]);$.vec3(3),$.vec3(3);var Yf=$.identityMat4(),Xf=function(){function e(t){b(this,e),this._model=t.model,this.id=t.id,this._parentTransform=t.parent,this._childTransforms=[],this._meshes=[],this._scale=new Float32Array([1,1,1]),this._quaternion=$.identityQuaternion(new Float32Array(4)),this._rotation=new Float32Array(3),this._position=new Float32Array(3),this._localMatrix=$.identityMat4(new Float32Array(16)),this._worldMatrix=$.identityMat4(new Float32Array(16)),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,t.matrix?this.matrix=t.matrix:(this.scale=t.scale,this.position=t.position,t.quaternion||(this.rotation=t.rotation)),t.parent&&t.parent._addChildTransform(this)}return P(e,[{key:"_addChildTransform",value:function(e){this._childTransforms.push(e),e._parentTransform=this,e._setWorldMatrixDirty(),e._setAABBDirty()}},{key:"_addMesh",value:function(e){this._meshes.push(e),e.transform=this}},{key:"parentTransform",get:function(){return this._parentTransform}},{key:"meshes",get:function(){return this._meshes}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._model.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),$.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._model.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),$.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._model.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._model.glRedraw()}},{key:"matrix",get:function(){return this._localMatrixDirty&&(this._localMatrix||(this._localMatrix=$.identityMat4()),$.composeMat4(this._position,this._quaternion,this._scale,this._localMatrix),this._localMatrixDirty=!1),this._localMatrix},set:function(e){this._localMatrix||(this._localMatrix=$.identityMat4()),this._localMatrix.set(e||Yf),$.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._transformDirty(),this._model.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"rotate",value:function(e,t){return jf[0]=e[0],jf[1]=e[1],jf[2]=e[2],jf[3]=t*$.DEGTORAD,$.angleAxisToQuaternion(jf,Vf),$.mulQuaternions(this.quaternion,Vf,Qf),this.quaternion=Qf,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return jf[0]=e[0],jf[1]=e[1],jf[2]=e[2],jf[3]=t*$.DEGTORAD,$.angleAxisToQuaternion(jf,Vf),$.mulQuaternions(Vf,this.quaternion,Vf),this}},{key:"rotateX",value:function(e){return this.rotate(Wf,e)}},{key:"rotateY",value:function(e){return this.rotate(zf,e)}},{key:"rotateZ",value:function(e){return this.rotate(Kf,e)}},{key:"translate",value:function(e){return this._position[0]+=e[0],this._position[1]+=e[1],this._position[2]+=e[2],this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateX",value:function(e){return this._position[0]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateY",value:function(e){return this._position[1]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateZ",value:function(e){return this._position[2]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._transformDirty()}},{key:"_transformDirty",value:function(){this._worldMatrixDirty=!0;for(var e=0,t=this._childTransforms.length;e<t;e++){var n=this._childTransforms[e];if(n._transformDirty(),n._meshes&&n._meshes.length>0)for(var r=n._meshes,i=0,a=r.length;i<a;i++)r[i]._transformDirty()}if(this._meshes&&this._meshes.length>0)for(var s=this._meshes,o=0,l=s.length;o<l;o++)s[o]._transformDirty()}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentTransform)$.mulMat4(this._parentTransform.worldMatrix,e,this._worldMatrix);else for(var t=0,n=e.length;t<n;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}},{key:"_setSubtreeAABBsDirty",value:function(e){if(e._aabbDirty=!0,e._childTransforms)for(var t=0,n=e._childTransforms.length;t<n;t++)this._setSubtreeAABBsDirty(e._childTransforms[t])}}]),e}(),qf=$.vec3(),Jf=$.OBB3(),Zf=$.vec3([1,1,1]),$f=$.vec3([0,0,0]),ep=$.vec3([0,0,0]),tp=$.identityQuaternion(),np=$.identityMat4(),rp=new Uint8Array([255,255,255]),ip=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._dtxEnabled=r.scene.dtxEnabled&&!1!==i.dtxEnabled,r._enableVertexWelding=!1,r._enableIndexBucketing=!1,r._vboBatchingLayerScratchMemory=Ja(),r._textureTranscoder=i.textureTranscoder||Bf(r.scene.viewer),r._maxGeometryBatchSize=i.maxGeometryBatchSize,r._aabb=$.collapseAABB3(),r._aabbDirty=!0,r._quantizationRanges={},r._vboInstancingLayers={},r._vboBatchingLayers={},r._dtxLayers={},r.layerList=[],r._entityList=[],r._geometries={},r._dtxBuckets={},r._textures={},r._textureSets={},r._transforms={},r._meshes={},r._entities={},r._scheduledMeshes={},r._meshesCfgsBeforeMeshCreation={},r.renderFlags=new ki,r.numGeometries=0,r.numPortions=0,r.numVisibleLayerPortions=0,r.numTransparentLayerPortions=0,r.numXRayedLayerPortions=0,r.numHighlightedLayerPortions=0,r.numSelectedLayerPortions=0,r.numEdgesLayerPortions=0,r.numPickableLayerPortions=0,r.numClippableLayerPortions=0,r.numCulledLayerPortions=0,r.numEntities=0,r._numTriangles=0,r._numLines=0,r._numPoints=0,r._edgeThreshold=i.edgeThreshold||10,r._origin=$.vec3(i.origin||[0,0,0]),r._position=$.vec3(i.position||[0,0,0]),r._rotation=$.vec3(i.rotation||[0,0,0]),r._quaternion=$.vec4(i.quaternion||[0,0,0,1]),r._conjugateQuaternion=$.vec4(i.quaternion||[0,0,0,1]),i.rotation&&$.eulerToQuaternion(r._rotation,"XYZ",r._quaternion),r._scale=$.vec3(i.scale||[1,1,1]),r._worldRotationMatrix=$.mat4(),r._worldRotationMatrixConjugate=$.mat4(),r._matrix=$.mat4(),r._matrixDirty=!0,r._rebuildMatrices(),r._worldNormalMatrix=$.mat4(),$.inverseMat4(r._matrix,r._worldNormalMatrix),$.transposeMat4(r._worldNormalMatrix),(i.matrix||i.position||i.rotation||i.scale||i.quaternion)&&(r._viewMatrix=$.mat4(),r._viewNormalMatrix=$.mat4(),r._viewMatrixDirty=!0,r._matrixNonIdentity=!0),r._opacity=1,r._colorize=[1,1,1],r._saoEnabled=!1!==i.saoEnabled,r._pbrEnabled=!1!==i.pbrEnabled,r._colorTextureEnabled=!1!==i.colorTextureEnabled,r._isModel=i.isModel,r._isModel&&r.scene._registerModel(w(r)),r._onCameraViewMatrix=r.scene.camera.on("matrix",(function(){r._viewMatrixDirty=!0})),r._meshesWithDirtyMatrices=[],r._numMeshesWithDirtyMatrices=0,r._onTick=r.scene.on("tick",(function(){for(;r._numMeshesWithDirtyMatrices>0;)r._meshesWithDirtyMatrices[--r._numMeshesWithDirtyMatrices]._updateMatrix()})),r._createDefaultTextureSet(),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.backfaces=i.backfaces,r}return P(n,[{key:"_meshMatrixDirty",value:function(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}},{key:"_createDefaultTextureSet",value:function(){var e=new mf({id:"defaultColorTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new mf({id:"defaultMetalRoughTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),n=new mf({id:"defaultNormalsTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),r=new mf({id:"defaultEmissiveTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new mf({id:"defaultOcclusionTexture",texture:new Da({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=n,this._textures.defaultEmissiveTexture=r,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new yf({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:n,emissiveTexture:r,occlusionTexture:i})}},{key:"isPerformanceModel",get:function(){return!0}},{key:"transforms",get:function(){return this._transforms}},{key:"textures",get:function(){return this._textures}},{key:"textureSets",get:function(){return this._textureSets}},{key:"meshes",get:function(){return this._meshes}},{key:"objects",get:function(){return this._entities}},{key:"origin",get:function(){return this._origin}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),$.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),$.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){}},{key:"matrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix},set:function(e){this._matrix.set(e||np),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),$.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),$.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"rotationMatrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}},{key:"_rebuildMatrices",value:function(){this._matrixDirty&&($.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),$.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),$.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}},{key:"rotationMatrixConjugate",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}},{key:"_setWorldMatrixDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0}},{key:"_transformDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}},{key:"_sceneModelDirty",value:function(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(var e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._sceneModelDirty()}},{key:"worldMatrix",get:function(){return this.matrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrix}},{key:"viewMatrix",get:function(){return this._viewMatrix?(this._matrixDirty&&(this._rebuildMatrices(),this._viewMatrixDirty=!0),this._viewMatrixDirty&&($.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),$.inverseMat4(this._viewMatrix,this._viewNormalMatrix),$.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),this._viewMatrix):this.scene.camera.viewMatrix}},{key:"viewNormalMatrix",get:function(){return this._viewNormalMatrix?(this._matrixDirty&&(this._rebuildMatrices(),this._viewMatrixDirty=!0),this._viewMatrixDirty&&($.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),$.inverseMat4(this._viewMatrix,this._viewNormalMatrix),$.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),$.inverseMat4(this._viewMatrix,this._viewNormalMatrix),$.transposeMat4(this._viewNormalMatrix),this._viewNormalMatrix):this.scene.camera.viewNormalMatrix}},{key:"backfaces",get:function(){return this._backfaces},set:function(e){e=!!e,this._backfaces=e,this.glRedraw()}},{key:"entityList",get:function(){return this._entityList}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return!1}},{key:"aabb",get:function(){if(this._aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._entityList.length;e<t;e++)$.expandAABB3(this._aabb,this._entityList[e].aabb);this._aabbDirty=!1}return this._aabb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"numLines",get:function(){return this._numLines}},{key:"numPoints",get:function(){return this._numPoints}},{key:"visible",get:function(){return this.numVisibleLayerPortions>0},set:function(e){e=!1!==e,this._visible=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].visible=e;this.glRedraw()}},{key:"xrayed",get:function(){return this.numXRayedLayerPortions>0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].xrayed=e;this.glRedraw()}},{key:"highlighted",get:function(){return this.numHighlightedLayerPortions>0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].highlighted=e;this.glRedraw()}},{key:"selected",get:function(){return this.numSelectedLayerPortions>0},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].selected=e;this.glRedraw()}},{key:"edges",get:function(){return this.numEdgesLayerPortions>0},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].edges=e;this.glRedraw()}},{key:"culled",get:function(){return this._culled},set:function(e){e=!!e,this._culled=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].culled=e;this.glRedraw()}},{key:"clippable",get:function(){return this._clippable},set:function(e){e=!1!==e,this._clippable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].clippable=e;this.glRedraw()}},{key:"collidable",get:function(){return this._collidable},set:function(e){e=!1!==e,this._collidable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].collidable=e}},{key:"pickable",get:function(){return this.numPickableLayerPortions>0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].pickable=e}},{key:"colorize",get:function(){return this._colorize},set:function(e){this._colorize=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].colorize=e}},{key:"opacity",get:function(){return this._opacity},set:function(e){this._opacity=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].opacity=e}},{key:"castsShadow",get:function(){return this._castsShadow},set:function(e){(e=!1!==e)!==this._castsShadow&&(this._castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._receivesShadow},set:function(e){(e=!1!==e)!==this._receivesShadow&&(this._receivesShadow=e,this.glRedraw())}},{key:"saoEnabled",get:function(){return this._saoEnabled}},{key:"pbrEnabled",get:function(){return this._pbrEnabled}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!1}},{key:"xrayMaterial",get:function(){return this.scene.xrayMaterial}},{key:"highlightMaterial",get:function(){return this.scene.highlightMaterial}},{key:"selectedMaterial",get:function(){return this.scene.selectedMaterial}},{key:"edgeMaterial",get:function(){return this.scene.edgeMaterial}},{key:"getPickViewMatrix",value:function(e){return this._viewMatrix?this._viewMatrix:e}},{key:"createQuantizationRange",value:function(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:Ws(e.aabb,$.mat4())}:this.error("[createQuantizationRange] Config missing: id")}},{key:"createGeometry",value:function(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 '".concat(e.primitive,"' primitive type)")),null;if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Ws(e.positionsDecodeBoundary,$.mat4())),e.positions){var t=$.collapseAABB3();e.positionsDecodeMatrix=$.mat4(),$.expandAABB3Points3(t,e.positions),e.positionsCompressed=Qs(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){var n=$.collapseAABB3();e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed),$.expandAABB3Points3(n,e.positionsCompressed),Pn.decompressAABB(n,e.positionsDecodeMatrix),e.aabb=n}else if(e.buckets){var r=$.collapseAABB3();this._dtxBuckets[e.id]=e.buckets;for(var i=0,a=e.buckets.length;i<a;i++){var s=e.buckets[i];s.positions?$.expandAABB3Points3(r,s.positions):s.positionsCompressed&&$.expandAABB3Points3(r,s.positionsCompressed)}e.positionsDecodeMatrix&&Pn.decompressAABB(r,e.positionsDecodeMatrix),e.aabb=r}if(e.colorsCompressed&&e.colorsCompressed.length>0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var o=e.colors,l=new Uint8Array(o.length),u=0,c=o.length;u<c;u++)l[u]=255*o[u];e.colorsCompressed=l}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=mn(e.positions,e.indices,null,5):e.edgeIndices=mn(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.uv){var f=Pn.getUVBounds(e.uv),p=Pn.compressUVs(e.uv,f.min,f.max);e.uvCompressed=p.quantized,e.uvDecodeMatrix=p.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': '".concat(e.primitive,"' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'."));else this.error("[createGeometry] Config missing: id")}},{key:"createTexture",value:function(e){var t=this,n=e.id;if(null!=n)if(this._textures[n])this.error("[createTexture] Texture already created: "+n);else{if(!e.src&&!e.image&&!e.buffers)return this.error("[createTexture] Param expected: `src`, `image' or 'buffers'"),null;var r=e.minFilter||1008;1006!==r&&1007!==r&&1008!==r&&1005!==r&&1004!==r&&(this.error("[createTexture] Unsupported value for 'minFilter' - \n supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, \n NearestMipMapLinearFilter and LinearMipmapLinearFilter. Defaulting to LinearMipmapLinearFilter."),r=1008);var i=e.magFilter||1006;1006!==i&&1003!==i&&(this.error("[createTexture] Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),i=1006);var a=e.wrapS||1e3;1001!==a&&1002!==a&&1e3!==a&&(this.error("[createTexture] Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),a=1e3);var s=e.wrapT||1e3;1001!==s&&1002!==s&&1e3!==s&&(this.error("[createTexture] Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),s=1e3);var o=e.wrapR||1e3;1001!==o&&1002!==o&&1e3!==o&&(this.error("[createTexture] Unsupported value for 'wrapR' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),o=1e3);var l=e.encoding||3e3;3e3!==l&&3001!==l&&(this.error("[createTexture] Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),l=3e3);var u=new Da({gl:this.scene.canvas.gl,minFilter:r,magFilter:i,wrapS:a,wrapT:s,wrapR:o,encoding:l});if(e.preloadColor&&u.setPreloadColor(e.preloadColor),e.image){var c=e.image;c.crossOrigin="Anonymous",u.setImage(c,{minFilter:r,magFilter:i,wrapS:a,wrapT:s,wrapR:o,flipY:e.flipY,encoding:l})}else if(e.src){var f=e.src.split(".").pop();switch(f){case"jpeg":case"jpg":case"png":case"gif":var p=new Image;p.onload=function(){u.setImage(p,{minFilter:r,magFilter:i,wrapS:a,wrapT:s,wrapR:o,flipY:e.flipY,encoding:l}),t.glRedraw()},p.src=e.src;break;default:this._textureTranscoder?le.loadArraybuffer(e.src,(function(e){e.byteLength?t._textureTranscoder.transcode([e],u).then((function(){t.glRedraw()})):t.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error("[createTexture] Can't create texture from 'src': ".concat(e))})):this.error("[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('".concat(f,"')"))}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,u).then((function(){t.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[n]=new mf({id:n,texture:u})}else this.error("[createTexture] Config missing: id")}},{key:"createTextureSet",value:function(e){var t=e.id;if(null!=t){if(!this._textureSets[t]){var n,r,i,a,s;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(!(n=this._textures[e.colorTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.colorTextureId," - ensure that you create it first with createTexture()"))}else n=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(!(r=this._textures[e.metallicRoughnessTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.metallicRoughnessTextureId," - ensure that you create it first with createTexture()"))}else r=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(!(i=this._textures[e.normalsTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.normalsTextureId," - ensure that you create it first with createTexture()"))}else i=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(!(a=this._textures[e.emissiveTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.emissiveTextureId," - ensure that you create it first with createTexture()"))}else a=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(!(s=this._textures[e.occlusionTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.occlusionTextureId," - ensure that you create it first with createTexture()"))}else s=this._textures.defaultOcclusionTexture;var o=new yf({id:t,model:this,colorTexture:n,metallicRoughnessTexture:r,normalsTexture:i,emissiveTexture:a,occlusionTexture:s});return this._textureSets[t]=o,o}this.error("[createTextureSet] Texture set already created: ".concat(t))}else this.error("[createTextureSet] Config missing: id")}},{key:"createTransform",value:function(e){if(void 0!==e.id&&null!==e.id)if(this._transforms[e.id])this.error("[createTransform] SceneModel already has a transform with this ID: ".concat(e.id));else{var t;if(!this.parentTransformId||(t=this._transforms[e.parentTransformId])){var n=new Xf({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[n.id]=n,n}this.error("[createTransform] SceneModel.createTransform() config missing: id")}else this.error("[createTransform] SceneModel.createTransform() config missing: id")}},{key:"createMesh",value:function(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: ".concat(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': '".concat(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 '".concat(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;var t=!(!this._dtxEnabled||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||e.textureSetId);if(e.origin=e.origin?$.addVec3(this._origin,e.origin,$.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){var n=e.scale||Zf,r=e.position||$f,i=e.rotation||ep;$.eulerToQuaternion(i,"XYZ",tp),e.meshMatrix=$.composeMat4(r,tp,n,$.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Ws(e.positionsDecodeBoundary,$.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])]):rp,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){var a=$.vec3(),s=[];Ne(e.positions,s,a)&&(e.positions=s,e.origin=$.addVec3(e.origin,a,a))}if(e.positions){var o=$.collapseAABB3();e.positionsDecodeMatrix=$.mat4(),$.expandAABB3Points3(o,e.positions),e.positionsCompressed=Qs(e.positions,o,e.positionsDecodeMatrix),e.aabb=o}else if(e.positionsCompressed){var l=$.collapseAABB3();$.expandAABB3Points3(l,e.positionsCompressed),Pn.decompressAABB(l,e.positionsDecodeMatrix),e.aabb=l}if(e.buckets){for(var u=$.collapseAABB3(),c=0,f=e.buckets.length;c<f;c++){var p=e.buckets[c];p.positions?$.expandAABB3Points3(u,p.positions):p.positionsCompressed&&$.expandAABB3Points3(u,p.positionsCompressed)}e.positionsDecodeMatrix&&Pn.decompressAABB(u,e.positionsDecodeMatrix),e.aabb=u}e.meshMatrix&&($.AABB3ToOBB3(e.aabb,Jf),$.transformOBB3(e.meshMatrix,Jf),$.OBB3ToAABB3(Jf,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=mn(e.positions,e.indices,null,2):e.edgeIndices=mn(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=ap(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){var A=[];Ne(e.positions,A,qf)&&(e.positions=A,e.origin=$.addVec3(e.origin,qf,$.vec3()))}if(e.positions){var d=$.collapseAABB3();e.meshMatrix&&($.transformPositions3(e.meshMatrix,e.positions,e.positions),e.meshMatrix=null),$.expandAABB3Points3(d,e.positions),e.aabb=d}else{var v=$.collapseAABB3();$.expandAABB3Points3(v,e.positionsCompressed),Pn.decompressAABB(v,e.positionsDecodeMatrix),e.aabb=v}if(e.meshMatrix&&($.AABB3ToOBB3(e.aabb,Jf),$.transformOBB3(e.meshMatrix,Jf),$.OBB3ToAABB3(Jf,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=mn(e.positions,e.indices,null,2):e.edgeIndices=mn(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: ".concat(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: ".concat(e.geometryId," - ensure that you create it first with createGeometry()")),!1;if(e.origin=e.origin?$.addVec3(this._origin,e.origin,$.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: ".concat(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{var h=e.scale||Zf,I=e.position||$f,y=e.rotation||ep;$.eulerToQuaternion(y,"XYZ",tp),e.meshMatrix=$.composeMat4(I,tp,h,$.mat4())}$.AABB3ToOBB3(e.geometry.aabb,Jf),$.transformOBB3(e.meshMatrix,Jf),e.aabb=$.OBB3ToAABB3(Jf,$.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])]):rp,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255;var m=this._dtxBuckets[e.geometryId];m||(m=ap(e.geometry,this._enableVertexWelding,this._enableIndexBucketing),this._dtxBuckets[e.geometryId]=m),e.buckets=m}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])]):rp,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}},{key:"_createMesh",value:function(e){var t=new Ya(this,e.id,e.color,e.opacity,e.transform,e.textureSet);t.pickId=this.scene._renderer.getPickID(t);var n=t.pickId,r=n>>24&255,i=n>>16&255,a=n>>8&255,s=255&n;switch(e.pickColor=new Uint8Array([s,a,i,r]),e.solid="solid"===e.primitive,t.origin=$.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),t}},{key:"_getNumPrimitives",value:function(e){var t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(var n=0,r=e.buckets.length;n<r;n++)t+=e.buckets[n].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(var i=0,a=e.buckets.length;i<a;i++)t+=e.buckets[i].positionsCompressed.length;break;case 1:t+=e.positions?e.positions.length:e.positionsCompressed.length;break;case 0:var 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(var o=0,l=e.buckets.length;o<l;o++)t+=e.buckets[o].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/2)}return 0}},{key:"_getDTXLayer",value:function(e){var t=e.origin,n=e.geometry?e.geometry.primitive:e.primitive,r=".".concat(n,".").concat(Math.round(t[0]),".").concat(Math.round(t[1]),".").concat(Math.round(t[2])),i=this._dtxLayers[r];if(i){if(i.canCreatePortion(e))return i;i.finalize(),delete this._dtxLayers[r],i=null}switch(n){case"triangles":case"solid":case"surface":i=new If(this,{layerIndex:0,origin:t});break;case"lines":i=new Ku(this,{layerIndex:0,origin:t});break;default:return}return this._dtxLayers[r]=i,this.layerList.push(i),i}},{key:"_getVBOBatchingLayer",value:function(e){var t=this,n=e.origin,r=e.positionsDecodeMatrix||e.positionsDecodeBoundary?this._createHashStringFromMatrix(e.positionsDecodeMatrix||e.positionsDecodeBoundary):"-",i=e.textureSetId||"-",a="".concat(Math.round(n[0]),".").concat(Math.round(n[1]),".").concat(Math.round(n[2]),".").concat(e.primitive,".").concat(r,".").concat(i),s=this._vboBatchingLayers[a];if(s)return s;for(var o=e.textureSet;!s;){switch(e.primitive){case"triangles":case"solid":case"surface":s=new io({model:t,textureSet:o,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize,solid:"solid"===e.primitive,autoNormals:!0});break;case"lines":s=new vl({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize});break;case"points":s=new ru({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize})}var l=e.positionsCompressed?e.positionsCompressed.length:e.positions.length;("points"===e.primitive?s.canCreatePortion(l):s.canCreatePortion(l,e.indices.length))||(s.finalize(),delete this._vboBatchingLayers[a],s=null)}return this._vboBatchingLayers[a]=s,this.layerList.push(s),s}},{key:"_createHashStringFromMatrix",value:function(e){for(var t=e.join(""),n=0,r=0;r<t.length;r++){n=(n<<5)-n+t.charCodeAt(r),n|=0}return(n>>>0).toString(16)}},{key:"_getVBOInstancingLayer",value:function(e){var t=this,n=e.origin,r=e.textureSetId||"-",i=e.geometryId,a="".concat(Math.round(n[0]),".").concat(Math.round(n[1]),".").concat(Math.round(n[2]),".").concat(r,".").concat(i),s=this._vboInstancingLayers[a];if(s)return s;for(var o=e.textureSet,l=e.geometry;!s;)switch(l.primitive){case"triangles":case"surface":s=new qo({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!1});break;case"solid":s=new qo({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!0});break;case"lines":s=new xl({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0});break;case"points":s=new _u({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0})}return this._vboInstancingLayers[a]=s,this.layerList.push(s),s}},{key:"createEntity",value:function(e){if(void 0===e.id?e.id=$.createUUID():this.scene.components[e.id]&&(this.error("Scene already has a Component with this ID: ".concat(e.id," - will assign random ID")),e.id=$.createUUID()),void 0!==e.meshIds){var t=0;this._visible&&!1!==e.visible&&(t|=Me),this._pickable&&!1!==e.pickable&&(t|=He),this._culled&&!1!==e.culled&&(t|=Fe),this._clippable&&!1!==e.clippable&&(t|=Ue),this._collidable&&!1!==e.collidable&&(t|=Ge),this._edges&&!1!==e.edges&&(t|=Qe),this._xrayed&&!1!==e.xrayed&&(t|=ke),this._highlighted&&!1!==e.highlighted&&(t|=je),this._selected&&!1!==e.selected&&(t|=Ve),e.flags=t,this._createEntity(e)}else this.error("Config missing: meshIds")}},{key:"_createEntity",value:function(e){for(var t=[],n=0,r=e.meshIds.length;n<r;n++){var i=e.meshIds[n],a=this._meshes[i];if(!a){var s=this._meshesCfgsBeforeMeshCreation[i];if(!s){this.error('Mesh with this ID not found: "'.concat(i,'" - ignoring this mesh'));continue}a=this._createMesh(s),this._meshes[e.id]=a}a.parent?this.error('Mesh with ID "'.concat(i,'" already belongs to object with ID "').concat(a.parent.id,'" - ignoring this mesh')):t.push(a)}var o=new Ke(this,e.isObject,e.id,t,e.flags,!0);this._entityList.push(o),this._entities[e.id]=o,this.numEntities++}},{key:"finalize",value:function(){if(!this.destroyed){for(var 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(var n=0,r=this._entityList.length;n<r;n++){this._entityList[n]._finalize()}for(var i=0,a=this._entityList.length;i<a;i++){this._entityList[i]._finalize2()}this.layerList.sort((function(e,t){return e.sortId<t.sortId?-1:e.sortId>t.sortId?1:0}));for(var s=0,o=this.layerList.length;s<o;s++){this.layerList[s].layerIndex=s}this.glRedraw(),this.scene._aabbDirty=!0,this._viewMatrixDirty=!0,this._matrixDirty=!0,this._aabbDirty=!0,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.position=this._position}}},{key:"stateSortCompare",value:function(e,t){}},{key:"rebuildRenderFlags",value:function(){this.renderFlags.reset(),this._updateRenderFlagsVisibleLayers(),this.renderFlags.numLayers>0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}},{key:"_updateRenderFlagsVisibleLayers",value:function(){var e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(var t=0,n=this.layerList.length;t<n;t++){var r=this.layerList[t];this._getActiveSectionPlanesForLayer(r)&&(e.visibleLayers[e.numVisibleLayers++]=t)}}},{key:"_getActiveSectionPlanesForLayer",value:function(e){var t=this.renderFlags,n=this.scene._sectionPlanesState.sectionPlanes,r=n.length,i=e.layerIndex*r;if(r>0)for(var a=0;a<r;a++){n[a].active?(t.sectionPlanesActivePerLayer[i+a]=!0,t.sectioned=!0):t.sectionPlanesActivePerLayer[i+a]=!1}return!0}},{key:"_updateRenderFlags",value:function(){if(0!==this.numVisibleLayerPortions&&this.numCulledLayerPortions!==this.numPortions){var e=this.renderFlags;if(e.colorOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){var t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0)this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(e.edgesTransparent=!0));if(this.numSelectedLayerPortions>0){var n=this.scene.selectedMaterial._state;n.fill&&(n.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),n.edges&&(n.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){var r=this.scene.highlightMaterial._state;r.fill&&(r.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),r.edges&&(r.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"drawColorOpaque",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawColorOpaque(t,e)}}},{key:"drawColorTransparent",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawColorTransparent(t,e)}}},{key:"drawDepth",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawDepth(t,e)}}},{key:"drawNormals",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawNormals(t,e)}}},{key:"drawSilhouetteXRayed",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawSilhouetteXRayed(t,e)}}},{key:"drawSilhouetteHighlighted",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawSilhouetteHighlighted(t,e)}}},{key:"drawSilhouetteSelected",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawSilhouetteSelected(t,e)}}},{key:"drawEdgesColorOpaque",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesColorOpaque(t,e)}}},{key:"drawEdgesColorTransparent",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesColorTransparent(t,e)}}},{key:"drawEdgesXRayed",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesXRayed(t,e)}}},{key:"drawEdgesHighlighted",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesHighlighted(t,e)}}},{key:"drawEdgesSelected",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesSelected(t,e)}}},{key:"drawOcclusion",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawOcclusion(t,e)}}},{key:"drawShadow",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawShadow(t,e)}}},{key:"setPickMatrices",value:function(e,t){if(0!==this._numVisibleLayerPortions)for(var n=this.renderFlags,r=0,i=n.visibleLayers.length;r<i;r++){var a=n.visibleLayers[r],s=this.layerList[a];s.setPickMatrices&&s.setPickMatrices(e,t)}}},{key:"drawPickMesh",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawPickMesh(t,e)}}},{key:"drawPickDepths",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawPickDepths(t,e)}}},{key:"drawPickNormals",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawPickNormals(t,e)}}},{key:"drawSnapInit",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n],a=this.layerList[i];a.drawSnapInit&&(e.snapPickOrigin=[0,0,0],e.snapPickCoordinateScale=[1,1,1],e.snapPickLayerNumber++,a.drawSnapInit(t,e),e.snapPickLayerParams[e.snapPickLayerNumber]={origin:e.snapPickOrigin.slice(),coordinateScale:e.snapPickCoordinateScale.slice()})}}},{key:"drawSnap",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n],a=this.layerList[i];a.drawSnap&&(e.snapPickOrigin=[0,0,0],e.snapPickCoordinateScale=[1,1,1],e.snapPickLayerNumber++,a.drawSnap(t,e),e.snapPickLayerParams[e.snapPickLayerNumber]={origin:e.snapPickOrigin.slice(),coordinateScale:e.snapPickCoordinateScale.slice()})}}},{key:"destroy",value:function(){for(var e in this._vboBatchingLayers)this._vboBatchingLayers.hasOwnProperty(e)&&this._vboBatchingLayers[e].destroy();for(var t in this._vboBatchingLayers={},this._vboInstancingLayers)this._vboInstancingLayers.hasOwnProperty(t)&&this._vboInstancingLayers[t].destroy();this._vboInstancingLayers={},this.scene.camera.off(this._onCameraViewMatrix),this.scene.off(this._onTick);for(var r=0,i=this.layerList.length;r<i;r++)this.layerList[r].destroy();this.layerList=[];for(var a=0,s=this._entityList.length;a<s;a++)this._entityList[a]._destroy();this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this.scene._aabbDirty=!0,this._isModel&&this.scene._deregisterModel(this),0!==qa&&0==--qa&&Xa._clear(),d(g(n.prototype),"destroy",this).call(this)}}]),n}();function ap(e,t,n){var r,i,a,s;if(t||n){var o=f(Lf({positionsCompressed:e.positionsCompressed,indices:e.indices,edgeIndices:e.edgeIndices}),3);r=o[0],i=o[1],a=o[2]}else r=e.positionsCompressed,i=e.indices,a=e.edgeIndices;n?s=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=e.positionsCompressed||[],i=Ff(e.indices||[],t),a=Gf(e.edgeIndices||[]);function s(e,t){if(e>t){var n=e;e=t,t=n}function r(n,r){return n!==e?e-n:r!==t?t-r:0}for(var i=0,s=(a.length>>1)-1;i<=s;){var o=s+i>>1,l=r(a[2*o],a[2*o+1]);if(l>0)i=o+1;else{if(!(l<0))return o;s=o-1}}return-i-1}var o=new Int32Array(a.length/2);o.fill(0);var l=r.length/3;if(l>8*(1<<t))return[e];var u=new Int32Array(l);u.fill(-1);var c=[];function f(){u.fill(-1);var e={positionsCompressed:[],indices:[],edgeIndices:[],maxNumPositions:(1<<t)-t,numPositions:0,bucketNumber:c.length};return c.push(e),e}for(var p=f(),A=0,d=i.length;A<d;A+=3){var v=0,h=i[A],I=i[A+1],y=i[A+2];if(-1===u[h]&&v++,-1===u[I]&&v++,-1===u[y]&&v++,v+p.numPositions>p.maxNumPositions&&(p=f()),p.bucketNumber>8)return[e];-1===u[h]&&(u[h]=p.numPositions++,p.positionsCompressed.push(r[3*h]),p.positionsCompressed.push(r[3*h+1]),p.positionsCompressed.push(r[3*h+2])),-1===u[I]&&(u[I]=p.numPositions++,p.positionsCompressed.push(r[3*I]),p.positionsCompressed.push(r[3*I+1]),p.positionsCompressed.push(r[3*I+2])),-1===u[y]&&(u[y]=p.numPositions++,p.positionsCompressed.push(r[3*y]),p.positionsCompressed.push(r[3*y+1]),p.positionsCompressed.push(r[3*y+2])),p.indices.push(u[h]),p.indices.push(u[I]),p.indices.push(u[y]);var m=void 0;(m=s(h,I))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]])),(m=s(h,y))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]])),(m=s(I,y))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]]))}var w=t/8*2,g=t/8,E=2*r.length+(i.length+a.length)*w,T=0;return r.length,c.forEach((function(e){T+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*g,e.positionsCompressed.length})),T>E?[e]:(n&&kf(c,e),c)}({positionsCompressed:r,indices:i,edgeIndices:a},r.length/3>65536?16:8):s=[{positionsCompressed:r,indices:i,edgeIndices:a}];return s}var sp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e,i))._positions=i.positions||[],i.indices)r._indices=i.indices;else{r._indices=[];for(var a=0,s=r._positions.length/3-1;a<s;a+=2)r._indices.push(a),r._indices.push(a+1)}return r._sceneModel=new ip(w(r),{isModel:!1}),r._sceneModel.createMesh({id:"linesMesh",primitive:"lines",positions:r._positions,indices:r._indices}),r._sceneModel.createEntity({meshIds:["linesMesh"],visible:i.visible,clippable:i.clippable,collidable:i.collidable}),r._sceneModel.finalize(),r.scene._lineSetCreated(w(r)),r}return P(n,[{key:"visible",get:function(){return this._sceneModel.visible},set:function(e){this._sceneModel.visible=e}},{key:"positions",get:function(){return this._positions}},{key:"indices",get:function(){return this._indices}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene._lineSetDestroyed(this)}}]),n}(),op=$.vec3(),lp=$.vec3(),up=$.vec3(),cp=$.vec3(),fp=function(e){h(n,Re);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"BCFViewpoints",e,i)).originatingSystem=i.originatingSystem||"xeokit.io",r.authoringTool=i.authoringTool||"xeokit.io",r}return P(n,[{key:"getViewpoint",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=this.viewer.scene,r=n.camera,i=n.realWorldOffset,a=!0===t.reverseClippingPlanes,s={},o=$.normalizeVec3($.subVec3(r.look,r.eye,$.vec3())),l=r.eye,u=r.up;r.yUp&&(o=dp(o),l=dp(l),u=dp(u));var c=pp($.addVec3(l,i));"ortho"===r.projection?s.orthogonal_camera={camera_view_point:c,camera_direction:pp(o),camera_up_vector:pp(u),view_to_world_scale:r.ortho.scale}:s.perspective_camera={camera_view_point:c,camera_direction:pp(o),camera_up_vector:pp(u),field_of_view:r.perspective.fov};var p=n.sectionPlanes;for(var A in p)if(p.hasOwnProperty(A)){var d=p[A];if(!d.active)continue;var v=d.pos,h=void 0;h=a?$.negateVec3(d.dir,$.vec3()):d.dir,r.yUp&&(v=dp(v),h=dp(h)),$.addVec3(v,i),v=pp(v),h=pp(h),s.clipping_planes||(s.clipping_planes=[]),s.clipping_planes.push({location:v,direction:h})}var I=n.lineSets;for(var y in I)if(I.hasOwnProperty(y)){var m=I[y];s.lines||(s.lines=[]);for(var w=m.positions,g=m.indices,E=0,T=g.length/2;E<T;E++){var b=g[2*E],D=g[2*E+1];s.lines.push({start_point:{x:w[3*b+0],y:w[3*b+1],z:w[3*b+2]},end_point:{x:w[3*D+0],y:w[3*D+1],z:w[3*D+2]}})}}var P=n.bitmaps;for(var C in P)if(P.hasOwnProperty(C)){var _=P[C],R=_.pos,B=_.normal,O=_.up;r.yUp&&(R=dp(R),B=dp(B),O=dp(O)),$.addVec3(R,i),s.bitmaps||(s.bitmaps=[]),s.bitmaps.push({bitmap_type:_.type,bitmap_data:_.imageData,location:pp(R),normal:pp(B),up:pp(O),height:_.height})}s.components={visibility:{view_setup_hints:{spaces_visible:!!t.spacesVisible,space_boundaries_visible:!!t.spaceBoundariesVisible,openings_visible:!!t.openingsVisible,spaces_translucent:!!t.spaces_translucent,space_boundaries_translucent:!!t.space_boundaries_translucent,openings_translucent:!!t.openings_translucent}}};var S=new Set(n.opacityObjectIds),N=new Set(n.xrayedObjectIds),L=new Set(n.colorizedObjectIds),x=Object.values(n.objects).filter((function(e){return S.has(e.id)||L.has(e.id)||N.has(e.id)})).reduce((function(t,r){var i,a=hp(r.colorize);r.xrayed?(i=0===n.xrayMaterial.fillAlpha&&0!==n.xrayMaterial.edgeAlpha?.1:n.xrayMaterial.fillAlpha,a=(i=Math.round(255*i).toString(16).padStart(2,"0"))+a):S.has(r.id)&&(a=(i=Math.round(255*r.opacity).toString(16).padStart(2,"0"))+a),t[a]||(t[a]=[]);var s=r.id,o=r.originalSystemId,l={ifc_guid:o,originating_system:e.originatingSystem};return o!==s&&(l.authoring_tool_id=s),t[a].push(l),t}),{}),M=Object.entries(x).map((function(e){var t=f(e,2);return{color:t[0],components:t[1]}}));s.components.coloring=M;var F=n.objectIds,H=n.visibleObjects,U=n.visibleObjectIds,G=F.filter((function(e){return!H[e]})),k=n.selectedObjectIds;return t.defaultInvisible||U.length<G.length?(s.components.visibility.exceptions=this._createBCFComponents(U),s.components.visibility.default_visibility=!1):(s.components.visibility.exceptions=this._createBCFComponents(G),s.components.visibility.default_visibility=!0),s.components.selection=this._createBCFComponents(k),s.components.translucency=this._createBCFComponents(n.xrayedObjectIds),!1!==t.snapshot&&(s.snapshot={snapshot_type:"png",snapshot_data:this.viewer.getSnapshot({format:"png"})}),s}},{key:"_createBCFComponents",value:function(e){for(var t=this.viewer.scene,n=[],r=0,i=e.length;r<i;r++){var a=e[r],s=t.objects[a];if(s){var o={ifc_guid:s.originalSystemId,originating_system:this.originatingSystem};s.originalSystemId!==a&&(o.authoring_tool_id=a),n.push(o)}}return n}},{key:"setViewpoint",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e){var r=this.viewer,i=r.scene,a=i.camera,s=!1!==n.rayCast,o=!1!==n.immediate,l=!1!==n.reset,u=i.realWorldOffset,c=!0===n.reverseClippingPlanes;if(i.clearSectionPlanes(),e.clipping_planes&&e.clipping_planes.length>0&&e.clipping_planes.forEach((function(e){var t=Ap(e.location,op),n=Ap(e.direction,op);c&&$.negateVec3(n),$.subVec3(t,u),a.yUp&&(t=vp(t),n=vp(n)),new aa(i,{pos:t,dir:n})})),i.clearLines(),e.lines&&e.lines.length>0){var f=[],p=[],A=0;e.lines.forEach((function(e){e.start_point&&e.end_point&&(f.push(e.start_point.x),f.push(e.start_point.y),f.push(e.start_point.z),f.push(e.end_point.x),f.push(e.end_point.y),f.push(e.end_point.z),p.push(A++),p.push(A++))})),new sp(i,{positions:f,indices:p,clippable:!1,collidable:!0})}if(i.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){var t=e.bitmap_type||"jpg",n=e.bitmap_data,r=Ap(e.location,lp),s=Ap(e.normal,up),o=Ap(e.up,cp),l=e.height||1;t&&n&&r&&s&&o&&(a.yUp&&(r=vp(r),s=vp(s),o=vp(o)),new Qa(i,{src:n,type:t,pos:r,normal:s,up:o,clippable:!1,collidable:!0,height:l}))})),l&&(i.setObjectsXRayed(i.xrayedObjectIds,!1),i.setObjectsHighlighted(i.highlightedObjectIds,!1),i.setObjectsSelected(i.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(i.setObjectsVisible(i.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.visible=!1}))}))):(i.setObjectsVisible(i.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.visible=!0}))})));var d=e.components.visibility.view_setup_hints;d&&(!1===d.spaces_visible&&i.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcSpace"),!0),void 0!==d.spaces_translucent&&i.setObjectsXRayed(r.metaScene.getObjectIDsByType("IfcSpace"),!0),d.space_boundaries_visible,!1===d.openings_visible&&i.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcOpening"),!0),d.space_boundaries_translucent,void 0!==d.openings_translucent&&i.setObjectsXRayed(r.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(i.setObjectsSelected(i.selectedObjectIds,!1),e.components.selection.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.selected=!0}))}))),e.components.translucency&&(i.setObjectsXRayed(i.xrayedObjectIds,!1),e.components.translucency.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.xrayed=!0}))}))),e.components.coloring&&e.components.coloring.forEach((function(e){var r=e.color,i=0,a=!1;8===r.length&&((i=parseInt(r.substring(0,2),16)/256)<=1&&i>=.95&&(i=1),r=r.substring(2),a=!0);var s=[parseInt(r.substring(0,2),16)/256,parseInt(r.substring(2,4),16)/256,parseInt(r.substring(4,6),16)/256];e.components.map((function(e){return t._withBCFComponent(n,e,(function(e){e.colorize=s,a&&(e.opacity=i)}))}))}))}if(e.perspective_camera||e.orthogonal_camera){var v,h,I,y;if(e.perspective_camera?(v=Ap(e.perspective_camera.camera_view_point,op),h=Ap(e.perspective_camera.camera_direction,op),I=Ap(e.perspective_camera.camera_up_vector,op),a.perspective.fov=e.perspective_camera.field_of_view,y="perspective"):(v=Ap(e.orthogonal_camera.camera_view_point,op),h=Ap(e.orthogonal_camera.camera_direction,op),I=Ap(e.orthogonal_camera.camera_up_vector,op),a.ortho.scale=e.orthogonal_camera.view_to_world_scale,y="ortho"),$.subVec3(v,u),a.yUp&&(v=vp(v),h=vp(h),I=vp(I)),s){var m=i.pick({pickSurface:!0,origin:v,direction:h});h=m?m.worldPos:$.addVec3(v,h,op)}else h=$.addVec3(v,h,op);o?(a.eye=v,a.look=h,a.up=I,a.projection=y):r.cameraFlight.flyTo({eye:v,look:h,up:I,duration:n.duration,projection:y})}}}},{key:"_withBCFComponent",value:function(e,t,n){var r=this.viewer,i=r.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){var a=t.authoring_tool_id,s=i.objects[a];if(s)return void n(s);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[a])return void i.withObjects(r.metaScene.getObjectIDsInSubtree(a),n)}if(t.ifc_guid){var o=t.ifc_guid,l=i.objects[o];if(l)return void n(l);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[o])return void i.withObjects(r.metaScene.getObjectIDsInSubtree(o),n);Object.keys(i.models).forEach((function(t){var a=$.globalizeObjectId(t,o),s=i.objects[a];s?n(s):e.updateCompositeObjects&&r.metaScene.metaObjects[a]&&i.withObjects(r.metaScene.getObjectIDsInSubtree(a),n)}))}}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this)}}]),n}();function pp(e){return{x:e[0],y:e[1],z:e[2]}}function Ap(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function dp(e){return new Float64Array([e[0],-e[2],e[1]])}function vp(e){return new Float64Array([e[0],e[2],-e[1]])}function hp(e){var t="";return t+=Math.round(255*e[0]).toString(16).padStart(2,"0"),t+=Math.round(255*e[1]).toString(16).padStart(2,"0"),t+=Math.round(255*e[2]).toString(16).padStart(2,"0")}var Ip=$.vec3(),yp=function(e,t,n,r){var i=e-n,a=t-r;return Math.sqrt(i*i+a*a)},mp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e.viewer.scene,i)).plugin=e,r._container=i.container,!r._container)throw"config missing: container";r._eventSubs={};var a=r.plugin.viewer.scene;r._originMarker=new qe(a,i.origin),r._targetMarker=new qe(a,i.target),r._originWorld=$.vec3(),r._targetWorld=$.vec3(),r._wp=new Float64Array(24),r._vp=new Float64Array(24),r._pp=new Float64Array(24),r._cp=new Float64Array(8),r._xAxisLabelCulled=!1,r._yAxisLabelCulled=!1,r._zAxisLabelCulled=!1,r._color=i.color||r.plugin.defaultColor;var s=i.onMouseOver?function(e){i.onMouseOver(e,w(r)),r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,o=i.onMouseLeave?function(e){i.onMouseLeave(e,w(r)),r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,l=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},u=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},c=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},f=i.onContextMenu?function(e){i.onContextMenu(e,w(r))}:null,p=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return r._originDot=new Ze(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._targetDot=new Ze(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._lengthWire=new Je(r._container,{color:r._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._xAxisWire=new Je(r._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._yAxisWire=new Je(r._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._zAxisWire=new Je(r._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._lengthLabel=new $e(r._container,{fillColor:r._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._xAxisLabel=new $e(r._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._yAxisLabel=new $e(r._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._zAxisLabel=new $e(r._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:p,onMouseDown:l,onMouseUp:u,onMouseMove:c,onContextMenu:f}),r._wpDirty=!1,r._vpDirty=!1,r._cpDirty=!1,r._sectionPlanesDirty=!0,r._visible=!1,r._originVisible=!1,r._targetVisible=!1,r._wireVisible=!1,r._axisVisible=!1,r._xAxisVisible=!1,r._yAxisVisible=!1,r._zAxisVisible=!1,r._axisEnabled=!0,r._labelsVisible=!1,r._labelsOnWires=!1,r._clickable=!1,r._originMarker.on("worldPos",(function(e){r._originWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._targetMarker.on("worldPos",(function(e){r._targetWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._onViewMatrix=a.camera.on("viewMatrix",(function(){r._vpDirty=!0,r._needUpdate(0)})),r._onProjMatrix=a.camera.on("projMatrix",(function(){r._cpDirty=!0,r._needUpdate()})),r._onCanvasBoundary=a.canvas.on("boundary",(function(){r._cpDirty=!0,r._needUpdate(0)})),r._onMetricsUnits=a.metrics.on("units",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsScale=a.metrics.on("scale",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsOrigin=a.metrics.on("origin",(function(){r._cpDirty=!0,r._needUpdate()})),r._onSectionPlaneUpdated=a.on("sectionPlaneUpdated",(function(){r._sectionPlanesDirty=!0,r._needUpdate()})),r.approximate=i.approximate,r.visible=i.visible,r.originVisible=i.originVisible,r.targetVisible=i.targetVisible,r.wireVisible=i.wireVisible,r.axisVisible=i.axisVisible,r.xAxisVisible=i.xAxisVisible,r.yAxisVisible=i.yAxisVisible,r.zAxisVisible=i.zAxisVisible,r.labelsVisible=i.labelsVisible,r.labelsOnWires=i.labelsOnWires,r}return P(n,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&($.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._wp))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}var t=this._originMarker.viewPos[2],n=this._targetMarker.viewPos[2];if(t>-.3||n>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){$.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var r=this._pp,i=this._cp,a=e.canvas.canvas.getBoundingClientRect(),s=this._container.getBoundingClientRect(),o=a.top-s.top,l=a.left-s.left,u=e.canvas.boundary,c=u[2],f=u[3],p=0,A=this.plugin.viewer.scene.metrics,d=A.scale,v=A.units,h=A.unitsInfo[v].abbrev,I=0,y=r.length;I<y;I+=4)i[p]=l+Math.floor((1+r[I+0]/r[I+3])*c/2),i[p+1]=o+Math.floor((1-r[I+1]/r[I+3])*f/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{var m=35;this._xAxisLabel.setPosOnWire(i[0],i[1]+m,i[6],i[7]+m),m+=35,this._yAxisLabel.setPosOnWire(i[0],i[1]+m,i[6],i[7]+m),m+=35,this._zAxisLabel.setPosOnWire(i[0],i[1]+m,i[6],i[7]+m)}var w=this._approximate?" ~ ":" = ";this._length=Math.abs($.lenVec3($.subVec3(this._targetWorld,this._originWorld,Ip))),this._lengthLabel.setText(w+(this._length*d).toFixed(2)+h);var g=Math.abs(yp(i[0],i[1],i[2],i[3])),E=Math.abs(yp(i[2],i[3],i[4],i[5])),T=Math.abs(yp(i[4],i[5],i[6],i[7])),b=this.plugin.labelMinAxisLength;this.labelsOnWires?(this._xAxisLabelCulled=g<b,this._yAxisLabelCulled=E<b,this._zAxisLabelCulled=T<b):(this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1),this._xAxisLabelCulled?this._xAxisLabel.setCulled(!0):(this._xAxisLabel.setText(w+Math.abs((this._targetWorld[0]-this._originWorld[0])*d).toFixed(2)+h),this._xAxisLabel.setCulled(!this.axisVisible)),this._yAxisLabelCulled?this._yAxisLabel.setCulled(!0):(this._yAxisLabel.setText(w+Math.abs((this._targetWorld[1]-this._originWorld[1])*d).toFixed(2)+h),this._yAxisLabel.setCulled(!this.axisVisible)),this._zAxisLabelCulled?this._zAxisLabel.setCulled(!0):(this._zAxisLabel.setText(w+Math.abs((this._targetWorld[2]-this._originWorld[2])*d).toFixed(2)+h),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}}}},{key:"_isSliced",value:function(e){for(var t=this.scene._sectionPlanesState.sectionPlanes,n=0,r=t.length;n<r;n++){var i=t[n];if($.planeClipsPositions3(i.pos,i.dir,e,4))return!0}return!1}},{key:"approximate",get:function(){return this._approximate},set:function(e){e=!1!==e,this._approximate!==e&&(this._approximate=e,this._cpDirty=!0,this._needUpdate(0))}},{key:"origin",get:function(){return this._originMarker}},{key:"target",get:function(){return this._targetMarker}},{key:"length",get:function(){this._update();var e=this.plugin.viewer.scene.metrics.scale;return this._length*e}},{key:"color",get:function(){return this._color},set:function(e){this._color=e,this._originDot.setFillColor(e),this._targetDot.setFillColor(e),this._lengthWire.setColor(e),this._lengthLabel.setFillColor(e)}},{key:"visible",get:function(){return this._visible},set:function(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);var t=this._visible&&this._axisVisible&&this._xAxisVisible,n=this._visible&&this._axisVisible&&this._yAxisVisible,r=this._visible&&this._axisVisible&&this._zAxisVisible;this._xAxisWire.setVisible(t),this._yAxisWire.setVisible(n),this._zAxisWire.setVisible(r),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled),this._yAxisLabel.setVisible(n&&!this._yAxisLabelCulled),this._zAxisLabel.setVisible(r&&!this._zAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"originVisible",get:function(){return this._originVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultOriginVisible,this._originVisible=e,this._originDot.setVisible(this._visible&&this._originVisible)}},{key:"targetVisible",get:function(){return this._targetVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultTargetVisible,this._targetVisible=e,this._targetDot.setVisible(this._visible&&this._targetVisible)}},{key:"axisEnabled",get:function(){return this._axisEnabled},set:function(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()}},{key:"axisVisible",get:function(){return this._axisVisible},set:function(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()}},{key:"xAxisVisible",get:function(){return this._xAxisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._xAxisVisible=e;var t=this._visible&&this._axisVisible&&this._xAxisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"yAxisVisible",get:function(){return this._yAxisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._yAxisVisible=e;var t=this._visible&&this._axisVisible&&this._yAxisVisible&&this._axisEnabled;this._yAxisWire.setVisible(t),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"zAxisVisible",get:function(){return this._zAxisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._zAxisVisible=e;var t=this._visible&&this._axisVisible&&this._zAxisVisible&&this._axisEnabled;this._zAxisWire.setVisible(t),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"wireVisible",get:function(){return this._wireVisible},set:function(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)}},{key:"labelsVisible",get:function(){return this._labelsVisible},set:function(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()}},{key:"labelsOnWires",get:function(){return this._labelsOnWires},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultLabelsOnWires,this._labelsOnWires=e}},{key:"setHighlighted",value:function(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)}},{key:"clickable",get:function(){return this._clickable},set:function(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)}},{key:"destroy",value:function(){var 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(),d(g(n.prototype),"destroy",this).call(this)}}]),n}(),wp=function(e){h(n,me);var t=y(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"active",get:function(){}},{key:"snapping",get:function(){return!0},set:function(e){}},{key:"activate",value:function(){}},{key:"deactivate",value:function(){}},{key:"reset",value:function(){}},{key:"destroy",value:function(){}}]),n}(),gp=function(e){h(n,wp);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e.viewer.scene)).pointerLens=i.pointerLens,r._active=!1,r._currentDistanceMeasurement=null,r._currentDistanceMeasurementInitState={wireVisible:null,axisVisible:null,xAxisVisible:null,yaxisVisible:null,zAxisVisible:null,targetVisible:null},r._initMarkerDiv(),r._onCameraControlHoverSnapOrSurface=null,r._onCameraControlHoverSnapOrSurfaceOff=null,r._onMouseDown=null,r._onMouseUp=null,r._onCanvasTouchStart=null,r._onCanvasTouchEnd=null,r._snapping=!1!==i.snapping,r._mouseState=0,r._attachPlugin(e,i),r}return P(n,[{key:"_initMarkerDiv",value:function(){var e=document.createElement("div");e.setAttribute("id","myMarkerDiv");var t=this.scene.canvas.canvas;t.parentNode.insertBefore(e,t),e.style.background="black",e.style.border="2px solid blue",e.style.borderRadius="10px",e.style.width="5px",e.style.height="5px",e.style.margin="-200px -200px",e.style.zIndex="100",e.style.position="absolute",e.style.pointerEvents="none",this._markerDiv=e}},{key:"_destroyMarkerDiv",value:function(){if(this._markerDiv){var e=document.getElementById("myMarkerDiv");e.parentNode.removeChild(e),this._markerDiv=null}}},{key:"_attachPlugin",value:function(e){this.distanceMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){this._markerDiv||this._initMarkerDiv(),this.fire("activated",!0);var t=this.distanceMeasurementsPlugin,n=this.scene,r=t.viewer.cameraControl,i=n.canvas.canvas;n.input;var a,s,o=!1,l=$.vec3(),u=$.vec2(),c=null;this._mouseState=0,this._onCameraControlHoverSnapOrSurface=r.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(function(t){var n=t.snappedCanvasPos||t.canvasPos;if(o=!0,l.set(t.worldPos),u.set(t.canvasPos),0===e._mouseState){var r=i.getBoundingClientRect(),a=window.pageXOffset||document.documentElement.scrollLeft,s=window.pageYOffset||document.documentElement.scrollTop,f=r.left+a,p=r.top+s;e._markerDiv.style.marginLeft="".concat(f+n[0]-5,"px"),e._markerDiv.style.marginTop="".concat(p+n[1]-5,"px"),e._markerDiv.style.background="pink",t.snappedToVertex||t.snappedToEdge?(e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.snappedCanvasPos||t.canvasPos,e.pointerLens.snapped=!0),e._markerDiv.style.background="greenyellow",e._markerDiv.style.border="2px solid green"):(e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.canvasPos,e.pointerLens.snapped=!1),e._markerDiv.style.background="pink",e._markerDiv.style.border="2px solid red"),c=t.entity}else e._markerDiv.style.marginLeft="-10000px",e._markerDiv.style.marginTop="-10000px";i.style.cursor="pointer",e._currentDistanceMeasurement&&(e._currentDistanceMeasurement.wireVisible=e._currentDistanceMeasurementInitState.wireVisible,e._currentDistanceMeasurement.axisVisible=e._currentDistanceMeasurementInitState.axisVisible&&e.distanceMeasurementsPlugin.defaultAxisVisible,e._currentDistanceMeasurement.xAxisVisible=e._currentDistanceMeasurementInitState.xAxisVisible&&e.distanceMeasurementsPlugin.defaultXAxisVisible,e._currentDistanceMeasurement.yAxisVisible=e._currentDistanceMeasurementInitState.yAxisVisible&&e.distanceMeasurementsPlugin.defaultYAxisVisible,e._currentDistanceMeasurement.zAxisVisible=e._currentDistanceMeasurementInitState.zAxisVisible&&e.distanceMeasurementsPlugin.defaultZAxisVisible,e._currentDistanceMeasurement.targetVisible=e._currentDistanceMeasurementInitState.targetVisible,e._currentDistanceMeasurement.target.worldPos=l.slice(),e._markerDiv.style.marginLeft="-10000px",e._markerDiv.style.marginTop="-10000px")})),i.addEventListener("mousedown",this._onMouseDown=function(e){1===e.which&&(a=e.clientX,s=e.clientY)}),i.addEventListener("mouseup",this._onMouseUp=function(n){1===n.which&&(n.clientX>a+20||n.clientX<a-20||n.clientY>s+20||n.clientY<s-20||(e._currentDistanceMeasurement?o?(e._currentDistanceMeasurement.target.entity=c,c=null,e._currentDistanceMeasurement.clickable=!0,e.distanceMeasurementsPlugin.fire("measurementEnd",e._currentDistanceMeasurement),e._currentDistanceMeasurement=null):(e._currentDistanceMeasurement.destroy(),e.distanceMeasurementsPlugin.fire("measurementCancel",e._currentDistanceMeasurement),e._currentDistanceMeasurement=null,c=null):o&&(e._currentDistanceMeasurement=t.createMeasurement({id:$.createUUID(),origin:{worldPos:l.slice()},target:{worldPos:l.slice()},approximate:!0}),e._currentDistanceMeasurementInitState.axisVisible=e._currentDistanceMeasurement.axisVisible&&e.distanceMeasurementsPlugin.defaultAxisVisible,e._currentDistanceMeasurementInitState.xAxisVisible=e._currentDistanceMeasurement.xAxisVisible&&e.distanceMeasurementsPlugin.defaultXAxisVisible,e._currentDistanceMeasurementInitState.yAxisVisible=e._currentDistanceMeasurement.yAxisVisible&&e.distanceMeasurementsPlugin.defaultYAxisVisible,e._currentDistanceMeasurementInitState.zAxisVisible=e._currentDistanceMeasurement.zAxisVisible&&e.distanceMeasurementsPlugin.defaultZAxisVisible,e._currentDistanceMeasurementInitState.wireVisible=e._currentDistanceMeasurement.wireVisible,e._currentDistanceMeasurementInitState.targetVisible=e._currentDistanceMeasurement.targetVisible,e._currentDistanceMeasurement.clickable=!1,e._currentDistanceMeasurement.origin.entity=c,c=null,e.fire("measurementStart",e._currentDistanceMeasurement))))}),this._onCameraControlHoverSnapOrSurfaceOff=r.on(this._snapping?"hoverSnapOrSurfaceOff":"hoverOff",(function(t){e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.snappedCanvasPos||t.canvasPos),o=!1,e._markerDiv.style.marginLeft="-100px",e._markerDiv.style.marginTop="-100px",e._currentDistanceMeasurement&&(e._currentDistanceMeasurement.wireVisible=!1,e._currentDistanceMeasurement.targetVisible=!1,e._currentDistanceMeasurement.axisVisible=!1),i.style.cursor="default"})),this._active=!0}}},{key:"deactivate",value:function(){if(this._active){this.fire("activated",!1),this.pointerLens&&(this.pointerLens.visible=!1),this._markerDiv&&this._destroyMarkerDiv(),this.reset();var e=this.scene.canvas.canvas;e.removeEventListener("mousedown",this._onMouseDown),e.removeEventListener("mouseup",this._onMouseUp);var 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}}},{key:"reset",value:function(){this._active&&(this._destroyMarkerDiv(),this._initMarkerDiv(),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null))}},{key:"destroy",value:function(){this.deactivate(),d(g(n.prototype),"destroy",this).call(this)}}]),n}(),Ep=function(e){h(n,Re);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"DistanceMeasurements",e))._pointerLens=i.pointerLens,r._container=i.container||document.body,r._defaultControl=null,r._measurements={},r.labelMinAxisLength=i.labelMinAxisLength,r.defaultVisible=!1!==i.defaultVisible,r.defaultOriginVisible=!1!==i.defaultOriginVisible,r.defaultTargetVisible=!1!==i.defaultTargetVisible,r.defaultWireVisible=!1!==i.defaultWireVisible,r.defaultLabelsVisible=!1!==i.defaultLabelsVisible,r.defaultAxisVisible=!1!==i.defaultAxisVisible,r.defaultXAxisVisible=!1!==i.defaultXAxisVisible,r.defaultYAxisVisible=!1!==i.defaultYAxisVisible,r.defaultZAxisVisible=!1!==i.defaultZAxisVisible,r.defaultColor=void 0!==i.defaultColor?i.defaultColor:"#00BBFF",r.zIndex=i.zIndex||1e4,r.defaultLabelsOnWires=!1!==i.defaultLabelsOnWires,r._onMouseOver=function(e,t){r.fire("mouseOver",{plugin:w(r),distanceMeasurement:t,measurement:t,event:e})},r._onMouseLeave=function(e,t){r.fire("mouseLeave",{plugin:w(r),distanceMeasurement:t,measurement:t,event:e})},r._onContextMenu=function(e,t){r.fire("contextMenu",{plugin:w(r),distanceMeasurement:t,measurement:t,event:e})},r}return P(n,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){}},{key:"pointerLens",get:function(){return this._pointerLens}},{key:"control",get:function(){return this._defaultControl||(this._defaultControl=new gp(this,{})),this._defaultControl}},{key:"measurements",get:function(){return this._measurements}},{key:"labelMinAxisLength",get:function(){return this._labelMinAxisLength},set:function(e){e<1&&(this.error("labelMinAxisLength must be >= 1; defaulting to 25"),e=25),this._labelMinAxisLength=e||25}},{key:"createMeasurement",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.viewer.scene.components[t.id]&&(this.error("Viewer scene component with this ID already exists: "+t.id),delete t.id);var n=t.origin,r=t.target,i=new mp(this,{id:t.id,plugin:this,container:this._container,origin:{entity:n.entity,worldPos:n.worldPos},target:{entity:r.entity,worldPos:r.worldPos},visible:t.visible,wireVisible:t.wireVisible,axisVisible:!1!==t.axisVisible&&!1!==this.defaultAxisVisible,xAxisVisible:!1!==t.xAxisVisible&&!1!==this.defaultXAxisVisible,yAxisVisible:!1!==t.yAxisVisible&&!1!==this.defaultYAxisVisible,zAxisVisible:!1!==t.zAxisVisible&&!1!==this.defaultZAxisVisible,labelsVisible:!1!==t.labelsVisible&&!1!==this.defaultLabelsVisible,originVisible:t.originVisible,targetVisible:t.targetVisible,color:t.color,labelsOnWires:!1!==t.labelsOnWires&&!1!==this.defaultLabelsOnWires,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[i.id]=i,i.on("destroyed",(function(){delete e._measurements[i.id]})),this.fire("measurementCreated",i),i}},{key:"destroyMeasurement",value:function(e){var t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("DistanceMeasurement not found: "+e)}},{key:"setLabelsShown",value:function(e){for(var t=0,n=Object.entries(this.measurements);t<n.length;t++){var r=f(n[t],2);r[0];r[1].labelShown=e}}},{key:"setAxisVisible",value:function(e){for(var t=0,n=Object.entries(this.measurements);t<n.length;t++){var r=f(n[t],2);r[0];r[1].axisVisible=e}this.defaultAxisVisible=e}},{key:"getAxisVisible",value:function(){return this.defaultAxisVisible}},{key:"clear",value:function(){for(var e=Object.keys(this._measurements),t=0,n=e.length;t<n;t++)this.destroyMeasurement(e[t])}},{key:"destroy",value:function(){this.clear(),d(g(n.prototype),"destroy",this).call(this)}}]),n}(),Tp=function(e){h(n,Re);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,"FastNav",e))._hideColorTexture=!1!==i.hideColorTexture,r._hidePBR=!1!==i.hidePBR,r._hideSAO=!1!==i.hideSAO,r._hideEdges=!1!==i.hideEdges,r._hideTransparentObjects=!!i.hideTransparentObjects,r._scaleCanvasResolution=!!i.scaleCanvasResolution,r._scaleCanvasResolutionFactor=i.scaleCanvasResolutionFactor||.6,r._delayBeforeRestore=!1!==i.delayBeforeRestore,r._delayBeforeRestoreSeconds=i.delayBeforeRestoreSeconds||.5;var a=1e3*r._delayBeforeRestoreSeconds,s=!1,o=function(){a=1e3*r._delayBeforeRestoreSeconds,s||(e.scene._renderer.setColorTextureEnabled(!r._hideColorTexture),e.scene._renderer.setPBREnabled(!r._hidePBR),e.scene._renderer.setSAOEnabled(!r._hideSAO),e.scene._renderer.setTransparentEnabled(!r._hideTransparentObjects),e.scene._renderer.setEdgesEnabled(!r._hideEdges),r._scaleCanvasResolution?e.scene.canvas.resolutionScale=r._scaleCanvasResolutionFactor:e.scene.canvas.resolutionScale=1,s=!0)},l=function(){e.scene.canvas.resolutionScale=1,e.scene._renderer.setEdgesEnabled(!0),e.scene._renderer.setColorTextureEnabled(!0),e.scene._renderer.setPBREnabled(!0),e.scene._renderer.setSAOEnabled(!0),e.scene._renderer.setTransparentEnabled(!0),s=!1};r._onCanvasBoundary=e.scene.canvas.on("boundary",o),r._onCameraMatrix=e.scene.camera.on("matrix",o),r._onSceneTick=e.scene.on("tick",(function(e){s&&(a-=e.deltaTime,(!r._delayBeforeRestore||a<=0)&&l())}));var u=!1;return r._onSceneMouseDown=e.scene.input.on("mousedown",(function(){u=!0})),r._onSceneMouseUp=e.scene.input.on("mouseup",(function(){u=!1})),r._onSceneMouseMove=e.scene.input.on("mousemove",(function(){u&&o()})),r}return P(n,[{key:"hideColorTexture",get:function(){return this._hideColorTexture},set:function(e){this._hideColorTexture=e}},{key:"hidePBR",get:function(){return this._hidePBR},set:function(e){this._hidePBR=e}},{key:"hideSAO",get:function(){return this._hideSAO},set:function(e){this._hideSAO=e}},{key:"hideEdges",get:function(){return this._hideEdges},set:function(e){this._hideEdges=e}},{key:"hideTransparentObjects",get:function(){return this._hideTransparentObjects},set:function(e){this._hideTransparentObjects=!1!==e}},{key:"scaleCanvasResolution",get:function(){return this._scaleCanvasResolution},set:function(e){this._scaleCanvasResolution=e}},{key:"scaleCanvasResolutionFactor",get:function(){return this._scaleCanvasResolutionFactor},set:function(e){this._scaleCanvasResolutionFactor=e||.6}},{key:"delayBeforeRestore",get:function(){return this._delayBeforeRestore},set:function(e){this._delayBeforeRestore=e}},{key:"delayBeforeRestoreSeconds",get:function(){return this._delayBeforeRestoreSeconds},set:function(e){this._delayBeforeRestoreSeconds=null!=e?e:.5}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.scene.camera.off(this._onCameraMatrix),this.viewer.scene.canvas.off(this._onCanvasBoundary),this.viewer.scene.input.off(this._onSceneMouseDown),this.viewer.scene.input.off(this._onSceneMouseUp),this.viewer.scene.input.off(this._onSceneMouseMove),this.viewer.scene.off(this._onSceneTick),d(g(n.prototype),"destroy",this).call(this)}}]),n}(),bp=function(){function e(){b(this,e)}return P(e,[{key:"getMetaModel",value:function(e,t,n){le.loadJSON(e,(function(e){t(e)}),(function(e){n(e)}))}},{key:"getGLTF",value:function(e,t,n){le.loadArraybuffer(e,(function(e){t(e)}),(function(e){n(e)}))}},{key:"getGLB",value:function(e,t,n){le.loadArraybuffer(e,(function(e){t(e)}),(function(e){n(e)}))}},{key:"getArrayBuffer",value:function(e,t,n,r){!function(e,t,n,r){var i=function(){};n=n||i,r=r||i;var a=/^data:(.*?)(;base64)?,(.*)$/,s=t.match(a);if(s){var o=!!s[2],l=s[3];l=window.decodeURIComponent(l),o&&(l=window.atob(l));try{for(var u=new ArrayBuffer(l.length),c=new Uint8Array(u),f=0;f<l.length;f++)c[f]=l.charCodeAt(f);he.scheduleTask((function(){n(u)}))}catch(e){he.scheduleTask((function(){r(e)}))}}else{var p=function(e){var t=e.lastIndexOf("/");return 0!==t?e.substring(0,t+1):""}(e),A=p+t,d=new XMLHttpRequest;d.open("GET",A,!0),d.responseType="arraybuffer",d.onreadystatechange=function(){4===d.readyState&&(200===d.status?n(d.response):r("loadArrayBuffer error : "+d.response))},d.send(null)}}(e,t,(function(e){n(e)}),(function(e){r(e)}))}}]),e}();var Dp=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b(this,e),this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=t.messages,this.locale=t.locale}return P(e,[{key:"messages",set:function(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}},{key:"loadMessages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var t in e)this._messages[t]=e[t];this.messages=this._messages}},{key:"clearMessages",value:function(){this.messages={}}},{key:"locales",get:function(){return this._locales}},{key:"locale",get:function(){return this._locale},set:function(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}},{key:"translate",value:function(e,t){var n=this._messages[this._locale];if(!n)return null;var r=Pp(e,n);return r?t?Cp(r,t):r:null}},{key:"translatePlurals",value:function(e,t,n){var r=this._messages[this._locale];if(!r)return null;var i=Pp(e,r);return(i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one)?(i=Cp(i,[t]),n&&(i=Cp(i,n)),i):null}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==n&&(this._events[e]=t||!0);var r=this._eventSubs[e];if(r)for(var i in r){if(r.hasOwnProperty(i))r[i].callback(t)}}},{key:"on",value:function(e,t){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new G),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});var n=this._eventSubs[e];n||(n={},this._eventSubs[e]=n);var r=this._eventSubIDMap.addItem();n[r]={callback:t},this._eventSubEvents[r]=e;var i=this._events[e];return void 0!==i&&t(i),r}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var n=this._eventSubs[t];n&&delete n[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function Pp(e,t){if(t[e])return t[e];for(var n=e.split("."),r=t,i=0,a=n.length;r&&i<a;i++){r=r[n[i]]}return r}function Cp(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,n){return"{{"===e?"{":"}}"===e?"}":t[n]}))}var _p=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).t=i.t,r}return P(n,[{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"tangent",get:function(){return this.getTangent(this._t)}},{key:"length",get:function(){var e=this._getLengths();return e[e.length-1]}},{key:"getTangent",value:function(e){var t=1e-4;void 0===e&&(e=this._t);var n=e-t,r=e+t;n<0&&(n=0),r>1&&(r=1);var i=this.getPoint(n),a=this.getPoint(r),s=$.subVec3(a,i,[]);return $.normalizeVec3(s,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,n=[];for(t=0;t<=e;t++)n.push(this.getPoint(t/e));return n}},{key:"_getLengths",value:function(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,n,r=[],i=this.getPoint(0),a=0;for(r.push(0),n=1;n<=e;n++)t=this.getPoint(n/e),a+=$.lenVec3($.subVec3(t,i,[])),r.push(a),i=t;return this.cacheArcLengths=r,r}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var n,r=this._getLengths(),i=0,a=r.length;n=t||e*r[a-1];for(var s,o=0,l=a-1;o<=l;)if((s=r[i=Math.floor(o+(l-o)/2)]-n)<0)o=i+1;else{if(!(s>0)){l=i;break}l=i-1}if(r[i=l]===n)return i/(a-1);var u=r[i];return(i+(n-u)/(r[i+1]-u))/(a-1)}}]),n}(),Rp=function(e){h(n,_p);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).points=i.points,r.t=i.t,r}return P(n,[{key:"points",get:function(){return this._points},set:function(e){this._points=e||[]}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=this.points;if(!(t.length<3)){var n=(t.length-1)*e,r=Math.floor(n),i=n-r,a=t[0===r?r:r-1],s=t[r],o=t[r>t.length-2?t.length-1:r+1],l=t[r>t.length-3?t.length-1:r+2],u=$.vec3();return u[0]=$.catmullRomInterpolate(a[0],s[0],o[0],l[0],i),u[1]=$.catmullRomInterpolate(a[1],s[1],o[1],l[1],i),u[2]=$.catmullRomInterpolate(a[2],s[2],o[2],l[2],i),u}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}},{key:"getJSON",value:function(){return{points:points,t:this._t}}}]),n}(),Bp=$.vec3(),Op=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._frames=[],r._eyeCurve=new Rp(w(r)),r._lookCurve=new Rp(w(r)),r._upCurve=new Rp(w(r)),i.frames&&(r.addFrames(i.frames),r.smoothFrameTimes(1)),r}return P(n,[{key:"type",get:function(){return"CameraPath"}},{key:"frames",get:function(){return this._frames}},{key:"eyeCurve",get:function(){return this._eyeCurve}},{key:"lookCurve",get:function(){return this._lookCurve}},{key:"upCurve",get:function(){return this._upCurve}},{key:"saveFrame",value:function(e){var t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}},{key:"addFrame",value:function(e,t,n,r){var i={t:e,eye:t.slice(0),look:n.slice(0),up:r.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}},{key:"addFrames",value:function(e){for(var t,n=0,r=e.length;n<r;n++)t=e[n],this.addFrame(t.t||0,t.eye,t.look,t.up)}},{key:"loadFrame",value:function(e){var t=this.scene.camera;e=(e/=this._frames[this._frames.length-1].t-this._frames[0].t)<0?0:e>1?1:e,t.eye=this._eyeCurve.getPoint(e,Bp),t.look=this._lookCurve.getPoint(e,Bp),t.up=this._upCurve.getPoint(e,Bp)}},{key:"sampleFrame",value:function(e,t,n,r){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,n),this._upCurve.getPoint(e,r)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=$.vec3(),n=0;this._frames[0].t=0;for(var r=[],i=1,a=this._frames.length;i<a;i++){var s=$.lenVec3($.subVec3(this._frames[i].eye,this._frames[i-1].eye,t));r[i]=s,n+=s}for(var o=1,l=this._frames.length;o<l;o++){var u=r[o]/n*e;this._frames[o].t=this._frames[o-1].t+u}}}},{key:"clearFrames",value:function(){this._frames=[],this._eyeCurve.points=[],this._lookCurve.points=[],this._upCurve.points=[]}}]),n}(),Sp=$.vec3(),Np=$.vec3(),Lp=$.vec3(),xp=$.vec3(),Mp=$.vec3(),Fp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._look1=$.vec3(),r._eye1=$.vec3(),r._up1=$.vec3(),r._look2=$.vec3(),r._eye2=$.vec3(),r._up2=$.vec3(),r._orthoScale1=1,r._orthoScale2=1,r._flying=!1,r._flyEyeLookUp=!1,r._flyingEye=!1,r._flyingLook=!1,r._callback=null,r._callbackScope=null,r._time1=null,r._time2=null,r.easing=!1!==i.easing,r.duration=i.duration,r.fit=i.fit,r.fitFOV=i.fitFOV,r.trail=i.trail,r}return P(n,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,n){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=n;var r,i,a,s,o,l=this.scene.camera,u=!!e.projection&&e.projection!==l.projection;if(this._eye1[0]=l.eye[0],this._eye1[1]=l.eye[1],this._eye1[2]=l.eye[2],this._look1[0]=l.look[0],this._look1[1]=l.look[1],this._look1[2]=l.look[2],this._up1[0]=l.up[0],this._up1[1]=l.up[1],this._up1[2]=l.up[2],this._orthoScale1=l.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)i=e.eye,a=e.look,s=e.up;else if(e.eye)i=e.eye;else if(e.look)a=e.look;else{var c=e;if((le.isNumeric(c)||le.isString(c))&&(o=c,!(c=this.scene.components[o])))return this.error("Component not found: "+le.inQuotes(o)),void(t&&(n?t.call(n):t()));u||(r=c.aabb||this.scene.aabb)}var f=e.poi;if(r){if(r[3]<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();var p=$.getAABB3Center(r);this._look2=f||p;var A=$.subVec3(this._eye1,this._look1,Sp),d=$.normalizeVec3(A),v=f?$.getAABB3DiagPoint(r,f):$.getAABB3Diag(r),h=e.fitFOV||this._fitFOV,I=Math.abs(v/Math.tan(h*$.DEGTORAD));this._orthoScale2=1.1*v,this._eye2[0]=this._look2[0]+d[0]*I,this._eye2[1]=this._look2[1]+d[1]*I,this._eye2[2]=this._look2[2]+d[2]*I,this._up2[0]=this._up1[0],this._up2[1]=this._up1[1],this._up2[2]=this._up1[2],this._flyingEyeLookUp=!0}else(i||a||s)&&(this._flyingEyeLookUp=!!i&&!!a&&!!s,this._flyingEye=!!i&&!a,this._flyingLook=!!a&&!i,i&&(this._eye2[0]=i[0],this._eye2[1]=i[1],this._eye2[2]=i[2]),a&&(this._look2[0]=a[0],this._look2[1]=a[1],this._look2[2]=a[2]),s&&(this._up2[0]=s[0],this._up2[1]=s[1],this._up2[2]=s[2]));u?("ortho"===e.projection&&"ortho"!==l.projection&&(this._projection2="ortho",this._projMatrix1=l.projMatrix.slice(),this._projMatrix2=l.ortho.matrix.slice(),l.projection="customProjection"),"perspective"===e.projection&&"perspective"!==l.projection&&(this._projection2="perspective",this._projMatrix1=l.projMatrix.slice(),this._projMatrix2=l.perspective.matrix.slice(),l.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,he.scheduleTask(this._update,this)}},{key:"jumpTo",value:function(e){this._jumpTo(e)}},{key:"_jumpTo",value:function(e){this._flying&&this.stop();var t,n,r,i,a,s=this.scene.camera;if(e.aabb)t=e.aabb;else if(6===e.length)t=e;else if(e.eye||e.look||e.up)r=e.eye,i=e.look,a=e.up;else{var o=e;if((le.isNumeric(o)||le.isString(o))&&(n=o,!(o=this.scene.components[n])))return void this.error("Component not found: "+le.inQuotes(n));t=o.aabb||this.scene.aabb}var l=e.poi;if(t){if(t[3]<=t[0]||t[4]<=t[1]||t[5]<=t[2])return;var u,c=l?$.getAABB3DiagPoint(t,l):$.getAABB3Diag(t);i=l||$.getAABB3Center(t,i),this._trail?$.subVec3(s.look,i,Mp):$.subVec3(s.eye,s.look,Mp),$.normalizeVec3(Mp),u=(void 0!==e.fit?e.fit:this._fit)?Math.abs(c/Math.tan((e.fitFOV||this._fitFOV)*$.DEGTORAD)):$.lenVec3($.subVec3(s.eye,s.look,Sp)),$.mulVec3Scalar(Mp,u),s.eye=$.addVec3(i,Mp,Sp),s.look=i,this.scene.camera.ortho.scale=1.1*c}else(r||i||a)&&(r&&(s.eye=r),i&&(s.look=i),a&&(s.up=a));e.projection&&(s.projection=e.projection)}},{key:"_update",value:function(){if(this._flying){var e=(Date.now()-this._time1)/(this._time2-this._time1),t=e>=1;e>1&&(e=1);var r=this.easing?n._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?($.subVec3(i.eye,i.look,Mp),i.eye=$.lerpVec3(r,0,1,this._eye1,this._eye2,Lp),i.look=$.subVec3(Lp,Mp,Np)):this._flyingLook&&(i.look=$.lerpVec3(r,0,1,this._look1,this._look2,Np),i.up=$.lerpVec3(r,0,1,this._up1,this._up2,xp)):this._flyingEyeLookUp&&(i.eye=$.lerpVec3(r,0,1,this._eye1,this._eye2,Lp),i.look=$.lerpVec3(r,0,1,this._look1,this._look2,Np),i.up=$.lerpVec3(r,0,1,this._up1,this._up2,xp)),this._projection2){var a="ortho"===this._projection2?n._easeOutExpo(e,0,1,1):n._easeInCubic(e,0,1,1);i.customProjection.matrix=$.lerpMat4(a,0,1,this._projMatrix1,this._projMatrix2)}else i.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return i.ortho.scale=this._orthoScale2,void this.stop();he.scheduleTask(this._update,this)}}},{key:"stop",value:function(){if(this._flying){this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);var e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}}},{key:"cancel",value:function(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}},{key:"duration",get:function(){return this._duration/1e3},set:function(e){this._duration=e?1e3*e:500,this.stop()}},{key:"fit",get:function(){return this._fit},set:function(e){this._fit=!1!==e}},{key:"fitFOV",get:function(){return this._fitFOV},set:function(e){this._fitFOV=e||45}},{key:"trail",get:function(){return this._trail},set:function(e){this._trail=!!e}},{key:"destroy",value:function(){this.stop(),d(g(n.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,n,r){return n*(e/=r)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,n,r){return n*(1-Math.pow(2,-10*e/r))+t}}]),n}(),Hp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cameraFlightAnimation=new Fp(w(r)),r._t=0,r.state=n.SCRUBBING,r._playingFromT=0,r._playingToT=0,r._playingRate=i.playingRate||1,r._playingDir=1,r._lastTime=null,r.cameraPath=i.cameraPath,r._tick=r.scene.on("tick",r._updateT,w(r)),r}return P(n,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,r,i=performance.now(),a=this._lastTime?.001*(i-this._lastTime):0;if(this._lastTime=i,0!==a)switch(this.state){case n.SCRUBBING:return;case n.PLAYING:if(this._t+=this._playingRate*a,0===(t=this._cameraPath.frames.length)||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=n.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case n.PLAYING_TO:r=this._t+this._playingRate*a*this._playingDir,(this._playingDir<0&&r<=this._playingToT||this._playingDir>0&&r>=this._playingToT)&&(r=this._playingToT,this.state=n.SCRUBBING,this.fire("stopped")),this._t=r,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"cameraPath",get:function(){return this._cameraPath},set:function(e){this._cameraPath=e}},{key:"rate",get:function(){return this._playingRate},set:function(e){this._playingRate=e}},{key:"play",value:function(){this._cameraPath&&(this._lastTime=null,this.state=n.PLAYING)}},{key:"playToT",value:function(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=n.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var n=t.frames[e];n?this.playToT(n.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var r=this._cameraPath;if(r){var i=r.frames[e];i?(this.state=n.SCRUBBING,this._cameraFlightAnimation.flyTo(i,t)):this.error("flyToFrame - frame index out of range: "+e)}}},{key:"scrubToT",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=n.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=n.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=n.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),n}();Hp.STOPPED=0,Hp.SCRUBBING=1,Hp.PLAYING=2,Hp.PLAYING_TO=3;var Up=$.vec3(),Gp=$.vec3();$.vec3();var kp=$.vec3([0,-1,0]),jp=$.vec4([0,0,0,1]),Vp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._src=null,r._image=null,r._pos=$.vec3(),r._origin=$.vec3(),r._rtcPos=$.vec3(),r._dir=$.vec3(),r._size=1,r._imageSize=$.vec2(),r._texture=new Oa(w(r)),r._plane=new Zi(w(r),{geometry:new Rn(w(r),ja({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Ln(w(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0}),clippable:i.clippable}),r._grid=new Zi(w(r),{geometry:new Rn(w(r),ka({size:1,divisions:10})),material:new Ln(w(r),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:i.clippable}),r._node=new va(w(r),{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[r._plane,r._grid]}),r._gridVisible=!1,r.visible=!0,r.gridVisible=i.gridVisible,r.position=i.position,r.rotation=i.rotation,r.dir=i.dir,r.size=i.size,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"visible",get:function(){return this._plane.visible},set:function(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}},{key:"gridVisible",get:function(){return this._gridVisible},set:function(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),Se(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}},{key:"rotation",get:function(){return this._node.rotation},set:function(e){this._node.rotation=e}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"dir",get:function(){return this._dir},set:function(e){if(this._dir.set(e||[0,0,-1]),e){var t=this.scene.center,n=[-this._dir[0],-this._dir[1],-this._dir[2]];$.subVec3(t,this.position,Up);var r=-$.dotVec3(n,Up);$.normalizeVec3(n),$.mulVec3Scalar(n,r,Gp),$.vec3PairToQuaternion(kp,e,jp),this._node.quaternion=jp}}},{key:"collidable",get:function(){return this._node.collidable},set:function(e){this._node.collidable=!1!==e}},{key:"clippable",get:function(){return this._node.clippable},set:function(e){this._node.clippable=!1!==e}},{key:"pickable",get:function(){return this._node.pickable},set:function(e){this._node.pickable=!1!==e}},{key:"opacity",get:function(){return this._node.opacity},set:function(e){this._node.opacity=e}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],n=this._imageSize[1];if(t>n){var r=n/t;this._node.scale=[e,1,e*r]}else{var i=t/n;this._node.scale=[e*i,1,e]}}}]),n}(),Qp=function(e){h(n,vn);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=w(r=t.call(this,e,i));r._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var s=r.scene.camera,o=r.scene.canvas;return r._onCameraViewMatrix=s.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=s.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=o.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new zt({type:"point",pos:$.vec3([1,1,1]),color:$.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(a._shadowViewMatrixDirty){a._shadowViewMatrix||(a._shadowViewMatrix=$.identityMat4());var e=a._state.pos,t=s.look,n=s.up;$.lookAtMat4v(e,t,n,a._shadowViewMatrix),a._shadowViewMatrixDirty=!1}return a._shadowViewMatrix},getShadowProjMatrix:function(){if(a._shadowProjMatrixDirty){a._shadowProjMatrix||(a._shadowProjMatrix=$.identityMat4());var e=a.scene.canvas.canvas;$.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,a._shadowProjMatrix),a._shadowProjMatrixDirty=!1}return a._shadowProjMatrix},getShadowRenderBuf:function(){return a._shadowRenderBuf||(a._shadowRenderBuf=new Gt(a.scene.canvas.canvas,a.scene.canvas.gl,{size:[1024,1024]})),a._shadowRenderBuf}}),r.pos=i.pos,r.color=i.color,r.intensity=i.intensity,r.constantAttenuation=i.constantAttenuation,r.linearAttenuation=i.linearAttenuation,r.quadraticAttenuation=i.quadraticAttenuation,r.castsShadow=i.castsShadow,r.scene._lightCreated(w(r)),r}return P(n,[{key:"type",get:function(){return"PointLight"}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"constantAttenuation",get:function(){return this._state.attenuation[0]},set:function(e){this._state.attenuation[0]=e||0,this.glRedraw()}},{key:"linearAttenuation",get:function(){return this._state.attenuation[1]},set:function(e){this._state.attenuation[1]=e||0,this.glRedraw()}},{key:"quadraticAttenuation",get:function(){return this._state.attenuation[2]},set:function(e){this._state.attenuation[2]=e||0,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),d(g(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}();function Wp(e){return 0==(e&e-1)}function zp(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var Kp=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=(r=t.call(this,e,i)).scene.canvas.gl;return r._state=new zt({texture:new Da({gl:a,target:a.TEXTURE_CUBE_MAP}),flipY:r._checkFlipY(i.minFilter),encoding:r._checkEncoding(i.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),r._src=i.src,r._images=[],r._loadSrc(i.src),re.memory.textures++,r}return P(n,[{key:"type",get:function(){return"CubeTexture"}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}},{key:"_loadSrc",value:function(e){var t=this,n=this.scene.canvas.gl;this._images=[];for(var r=!1,i=0,a=function(a){var s,o,l=new Image;l.onload=(s=l,o=a,function(){if(!r&&(s=function(e){if(!Wp(e.width)||!Wp(e.height)){var t=document.createElement("canvas");t.width=zp(e.width),t.height=zp(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(s),t._images[o]=s,6==++i)){var e=t._state.texture;e||(e=new Da({gl:n,target:n.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}),l.onerror=function(){r=!0},l.src=e[a]},s=0;s<e.length;s++)a(s)}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),re.memory.textures--,this._state.destroy()}}]),n}(),Yp=function(e){h(n,Kp);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightsState.addReflectionMap(r._state),r.scene._reflectionMapCreated(w(r)),r}return P(n,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),n}(),Xp=function(e){h(n,Kp);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightMapCreated(w(r)),r}return P(n,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){d(g(n.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),n}(),qp=function(e){h(n,qe);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,{entity:i.entity,occludable:i.occludable,worldPos:i.worldPos}))._occluded=!1,r._visible=!0,r._src=null,r._image=null,r._pos=$.vec3(),r._origin=$.vec3(),r._rtcPos=$.vec3(),r._dir=$.vec3(),r._size=1,r._imageSize=$.vec2(),r._texture=new Oa(w(r),{src:i.src}),r._geometry=new Rn(w(r),{primitive:"triangles",positions:[3,3,0,-3,3,0,-3,-3,0,3,-3,0],normals:[-1,0,0,-1,0,0,-1,0,0,-1,0,0],uv:[1,-1,0,-1,0,0,1,0],indices:[0,1,2,0,2,3]}),r._mesh=new Zi(w(r),{geometry:r._geometry,material:new Ln(w(r),{ambient:[.9,.3,.9],shininess:30,diffuseMap:r._texture,backfaces:!0}),scale:[1,1,1],position:i.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),r.visible=!0,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,r.size=i.size,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,d(g(n.prototype),"_setVisible",this).call(this,e)}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"collidable",get:function(){return this._mesh.collidable},set:function(e){this._mesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._mesh.clippable},set:function(e){this._mesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._mesh.pickable},set:function(e){this._mesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._mesh.opacity},set:function(e){this._mesh.opacity=e}},{key:"_updatePlaneSizeFromImage",value:function(){var e=.5*this._size,t=this._imageSize[0],n=this._imageSize[1],r=n/t;this._geometry.positions=t>n?[e,e*r,0,-e,e*r,0,-e,-e*r,0,e,-e*r,0]:[e/r,e,0,-e/r,e,0,-e/r,-e,0,e/r,-e,0]}}]),n}(),Jp=function(){function e(t){b(this,e),this._eye=$.vec3(),this._look=$.vec3(),this._up=$.vec3(),this._projection={},t&&this.saveCamera(t)}return P(e,[{key:"saveCamera",value:function(e){var t=e.camera,n=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:n.fov,fovAxis:n.fovAxis,near:n.near,far:n.far};break;case"ortho":this._projection={projection:"ortho",scale:n.scale,near:n.near,far:n.far};break;case"frustum":this._projection={projection:"frustum",left:n.left,right:n.right,top:n.top,bottom:n.bottom,near:n.near,far:n.far};break;case"custom":this._projection={projection:"custom",matrix:n.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var n=e.camera,r=this._projection;function i(){switch(r.type){case"perspective":n.perspective.fov=r.fov,n.perspective.fovAxis=r.fovAxis,n.perspective.near=r.near,n.perspective.far=r.far;break;case"ortho":n.ortho.scale=r.scale,n.ortho.near=r.near,n.ortho.far=r.far;break;case"frustum":n.frustum.left=r.left,n.frustum.right=r.right,n.frustum.top=r.top,n.frustum.bottom=r.bottom,n.frustum.near=r.near,n.frustum.far=r.far;break;case"custom":n.customProjection.matrix=r.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:r.scale,projection:r.projection},(function(){i(),t()})):(n.eye=this._eye,n.look=this._look,n.up=this._up,i(),n.projection=r.projection)}}]),e}(),Zp=$.vec3(),$p=function(){function e(t){if(b(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,t){var n=t.metaScene.scene;this.saveObjects(n,t)}}return P(e,[{key:"saveObjects",value:function(e,t,n){this.numObjects=0,this._mask=n?le.apply(n,{}):null;for(var r=!n||n.visible,i=!n||n.edges,a=!n||n.xrayed,s=!n||n.highlighted,o=!n||n.selected,l=!n||n.clippable,u=!n||n.pickable,c=!n||n.colorize,f=!n||n.opacity,p=t.metaObjects,A=e.objects,d=0,v=p.length;d<v;d++){var h=A[p[d].id];if(h){if(r&&(this.objectsVisible[d]=h.visible),i&&(this.objectsEdges[d]=h.edges),a&&(this.objectsXrayed[d]=h.xrayed),s&&(this.objectsHighlighted[d]=h.highlighted),o&&(this.objectsSelected[d]=h.selected),l&&(this.objectsClippable[d]=h.clippable),u&&(this.objectsPickable[d]=h.pickable),c){var I=h.colorize;this.objectsColorize[3*d+0]=I[0],this.objectsColorize[3*d+1]=I[1],this.objectsColorize[3*d+2]=I[2]}f&&(this.objectsOpacity[d]=h.opacity),this.numObjects++}}}},{key:"restoreObjects",value:function(e,t){for(var n=this._mask,r=!n||n.visible,i=!n||n.edges,a=!n||n.xrayed,s=!n||n.highlighted,o=!n||n.selected,l=!n||n.clippable,u=!n||n.pickable,c=!n||n.colorize,f=!n||n.opacity,p=t.metaObjects,A=e.objects,d=0,v=p.length;d<v;d++){var h=A[p[d].id];h&&(r&&(h.visible=this.objectsVisible[d]),i&&(h.edges=this.objectsEdges[d]),a&&(h.xrayed=this.objectsXrayed[d]),s&&(h.highlighted=this.objectsHighlighted[d]),o&&(h.selected=this.objectsSelected[d]),l&&(h.clippable=this.objectsClippable[d]),u&&(h.pickable=this.objectsPickable[d]),c&&(Zp[0]=this.objectsColorize[3*d+0],Zp[1]=this.objectsColorize[3*d+1],Zp[2]=this.objectsColorize[3*d+2],h.colorize=Zp),f&&(h.opacity=this.objectsOpacity[d]))}}}]),e}(),eA=$.vec3(),tA=function(){function e(){b(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}return P(e,[{key:"saveObjects",value:function(e,t){this.numObjects=0,this._mask=t?le.apply(t,{}):null;var n=e.objects,r=!t||t.visible,i=!t||t.edges,a=!t||t.xrayed,s=!t||t.highlighted,o=!t||t.selected,l=!t||t.clippable,u=!t||t.pickable,c=!t||t.colorize,f=!t||t.opacity;for(var p in n)if(n.hasOwnProperty(p)){var A=n[p],d=this.numObjects;if(r&&(this.objectsVisible[d]=A.visible),i&&(this.objectsEdges[d]=A.edges),a&&(this.objectsXrayed[d]=A.xrayed),s&&(this.objectsHighlighted[d]=A.highlighted),o&&(this.objectsSelected[d]=A.selected),l&&(this.objectsClippable[d]=A.clippable),u&&(this.objectsPickable[d]=A.pickable),c){var v=A.colorize;v?(this.objectsColorize[3*d+0]=v[0],this.objectsColorize[3*d+1]=v[1],this.objectsColorize[3*d+2]=v[2],this.objectsHasColorize[d]=!0):this.objectsHasColorize[d]=!1}f&&(this.objectsOpacity[d]=A.opacity),this.numObjects++}}},{key:"restoreObjects",value:function(e){var t=this._mask,n=!t||t.visible,r=!t||t.edges,i=!t||t.xrayed,a=!t||t.highlighted,s=!t||t.selected,o=!t||t.clippable,l=!t||t.pickable,u=!t||t.colorize,c=!t||t.opacity,f=0,p=e.objects;for(var A in p)if(p.hasOwnProperty(A)){var d=p[A];n&&(d.visible=this.objectsVisible[f]),r&&(d.edges=this.objectsEdges[f]),i&&(d.xrayed=this.objectsXrayed[f]),a&&(d.highlighted=this.objectsHighlighted[f]),s&&(d.selected=this.objectsSelected[f]),o&&(d.clippable=this.objectsClippable[f]),l&&(d.pickable=this.objectsPickable[f]),u&&(this.objectsHasColorize[f]?(eA[0]=this.objectsColorize[3*f+0],eA[1]=this.objectsColorize[3*f+1],eA[2]=this.objectsColorize[3*f+2],d.colorize=eA):d.colorize=null),c&&(d.opacity=this.objectsOpacity[f]),f++}}}]),e}(),nA=function(e){h(n,_p);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.v3=i.v3,r.t=i.t,r}return P(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||$.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||$.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||$.vec3([0,0,0])}},{key:"v3",get:function(){return this._v3},set:function(e){this.fire("v3",this._v3=e||$.vec3([0,0,0]))}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=$.vec3();return t[0]=$.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=$.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=$.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}]),n}(),rA=function(e){h(n,_p);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cachedLengths=[],r._dirty=!0,r._curves=[],r._t=0,r._dirtySubs=[],r._destroyedSubs=[],r.curves=i.curves||[],r.t=i.t,r}return P(n,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,n,r;for(e=e||[],n=0,r=this._curves.length;n<r;n++)(t=this._curves[n]).off(this._dirtySubs[n]),t.off(this._destroyedSubs[n]);this._curves=[],this._dirtySubs=[],this._destroyedSubs=[];var i=this;function a(){i._dirty=!0}function s(){var e=this.id;for(n=0,r=i._curves.length;n<r;n++)if(i._curves[n].id===e)return i._curves=i._curves.slice(n,n+1),i._dirtySubs=i._dirtySubs.slice(n,n+1),i._destroyedSubs=i._destroyedSubs.slice(n,n+1),void(i._dirty=!0)}for(n=0,r=e.length;n<r;n++){if(t=e[n],le.isNumeric(t)||le.isString(t)){var o=t;if(!(t=this.scene.components[o])){this.error("Component not found: "+_inQuotes(o));continue}}var l=t.type;"xeokit.SplineCurve"===l||"xeokit.Path"===l||"xeokit.CubicBezierCurve"===l||"xeokit.QuadraticBezierCurve"===l?(this._curves.push(t),this._dirtySubs.push(t.on("dirty",a)),this._destroyedSubs.push(t.once("destroyed",s))):this.error("Component "+_inQuotes(t.id)+" is not a xeokit.SplineCurve, xeokit.Path or xeokit.QuadraticBezierCurve")}this._dirty=!0}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"length",get:function(){var e=this._getCurveLengths();return e[e.length-1]}},{key:"getPoint",value:function(e){for(var t,n=e*this.length,r=this._getCurveLengths(),i=0;i<r.length;){if(r[i]>=n){var a=1-(r[i]-n)/(t=this._curves[i]).length;return t.getPointAt(a)}i++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],n=0,r=this._curves.length;for(e=0;e<r;e++)n+=this._curves[e].length,t.push(n);return this._cachedLengths=t,this._dirty=!1,t}},{key:"_getJSON",value:function(){for(var e=[],t=0,n=this._curves.length;t<n;t++)e.push(this._curves[t].id);return{curves:e,t:this._t}}},{key:"destroy",value:function(){var e,t,r;for(d(g(n.prototype),"destroy",this).call(this),e=0,t=this._curves.length;e<t;e++)(r=this._curves[e]).off(this._dirtySubs[e]),r.off(this._destroyedSubs[e])}}]),n}(),iA=function(e){h(n,_p);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.t=i.t,r}return P(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||$.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||$.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||$.vec3([0,0,0])}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=$.vec3();return t[0]=$.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=$.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=$.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}]),n}(),aA=function(e){h(n,ip);var t=y(n);function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),t.call(this,e,r)}return P(n)}(),sA=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._skyboxMesh=new Zi(w(r),{geometry:new Rn(w(r),{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new Ln(w(r),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Oa(w(r),{src:i.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:i.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),r.size=i.size,r.active=i.active,r}return P(n,[{key:"size",get:function(){return this._size},set:function(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}},{key:"active",get:function(){return this._skyboxMesh.visible},set:function(e){this._skyboxMesh.visible=e}}]),n}(),oA=function(){function e(){b(this,e)}return P(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),lA=$.vec4(),uA=$.vec4(),cA=$.vec3(),fA=$.vec3(),pA=$.vec3(),AA=$.vec4(),dA=$.vec4(),vA=$.vec4(),hA=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"dollyToCanvasPos",value:function(e,t,n){var r=!1,i=this._scene.camera;if(e){var a=$.subVec3(e,i.eye,cA);r=$.lenVec3(a)<n}if("perspective"===i.projection){i.ortho.scale=i.ortho.scale-n;var s=this._unproject(t,AA),o=$.subVec3(s,i.eye,vA),l=$.mulVec3Scalar($.normalizeVec3(o),-n,[]);if(i.eye=[i.eye[0]-l[0],i.eye[1]-l[1],i.eye[2]-l[2]],i.look=[i.look[0]-l[0],i.look[1]-l[1],i.look[2]-l[2]],e){var u=$.subVec3(e,i.eye,cA),c=$.lenVec3(u),f=$.mulVec3Scalar($.normalizeVec3($.subVec3(i.look,i.eye,fA)),c);i.look=[i.eye[0]+f[0],i.eye[1]+f[1],i.eye[2]+f[2]]}}else if("ortho"===i.projection){var p=this._unproject(t,AA);i.ortho.scale=i.ortho.scale-n,i.ortho._update();var A=this._unproject(t,dA),d=$.subVec3(A,p,vA),v=$.mulVec3Scalar($.normalizeVec3($.subVec3(i.look,i.eye,cA)),-n,fA),h=$.addVec3(d,v,pA);i.eye=[i.eye[0]-h[0],i.eye[1]-h[1],i.eye[2]-h[2]],i.look=[i.look[0]-h[0],i.look[1]-h[1],i.look[2]-h[2]]}return r}},{key:"_unproject",value:function(e,t){var n=this._scene.camera,r=n.project.transposedMatrix,i=r.subarray(8,12),a=r.subarray(12),s=[0,0,-1,1],o=$.dotVec4(s,i)/$.dotVec4(s,a);return n.project.unproject(e,o,lA,uA,t),t}},{key:"destroy",value:function(){}}]),e}(),IA=$.vec3(),yA=$.vec3(),mA=$.vec3(),wA=$.vec4(),gA=$.vec4(),EA=$.vec4(),TA=function(){function e(t,n){var r=this;b(this,e),this._scene=t,this._configs=n,this._pivotWorldPos=$.vec3(),this._cameraOffset=$.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=$.vec3(),this._rtcPos=$.vec3(),this._pivotViewPos=$.vec4(),this._pivotProjPos=$.vec4(),this._pivotCanvasPos=$.vec2(),this._cameraDirty=!0,this._onViewMatrix=this._scene.camera.on("viewMatrix",(function(){r._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(function(){r._cameraDirty=!0})),this._onTick=this._scene.on("tick",(function(){r.updatePivotElement(),r.updatePivotSphere()}))}return P(e,[{key:"createPivotSphere",value:function(){var e=this.getPivotPos(),t=$.vec3();$.decomposeMat4($.inverseMat4(this._scene.viewer.camera.viewMatrix,$.mat4()),t,$.vec4(),$.vec3());var n=$.distVec3(t,e),r=Math.tan(Math.PI/500)*n*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(r/=this._scene.camera.ortho.scale/2),Se(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new xa(this._scene,ta({radius:r})),this._pivotSphere=new Zi(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}},{key:"destroyPivotSphere",value:function(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}},{key:"updatePivotElement",value:function(){var e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){$.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,$.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);var n=t.boundary,r=n[2],i=n[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*r/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);var a=t._lastBoundingClientRect;if(!a||t._canvasSizeChanged){var s=t.canvas;a=t._lastBoundingClientRect=s.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(a.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(a.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}},{key:"updatePivotSphere",value:function(){this._pivoting&&this._pivotSphere&&(Se(this.getPivotPos(),this._rtcCenter,this._rtcPos),$.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}},{key:"setPivotElement",value:function(e){this._pivotElement=e}},{key:"enablePivotSphere",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);var t=e.color||[1,0,0];this._pivotSphereMaterial=new Ln(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}},{key:"disablePivotSphere",value:function(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}},{key:"startPivot",value:function(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;var e=this._scene.camera,t=$.lookAtMat4v(e.eye,e.look,e.worldUp);$.transformPoint3(t,this.getPivotPos(),this._cameraOffset);var n=this.getPivotPos();this._cameraOffset[2]+=$.distVec3(e.eye,n),t=$.inverseMat4(t);var r=$.transformVec3(t,this._cameraOffset),i=$.vec3();if($.subVec3(e.eye,n,i),$.addVec3(i,r),e.zUp){var a=i[1];i[1]=i[2],i[2]=a}this._radius=$.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}},{key:"_cameraLookingDownwards",value:function(){var e=this._scene.camera,t=$.normalizeVec3($.subVec3(e.look,e.eye,IA)),n=$.cross3Vec3(t,e.worldUp,yA);return $.sqLenVec3(n)<=1e-4}},{key:"getPivoting",value:function(){return this._pivoting}},{key:"setPivotPos",value:function(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}},{key:"setCanvasPivotPos",value:function(e){var t=this._scene.camera,n=Math.abs($.distVec3(this._scene.center,t.eye)),r=t.project.transposedMatrix,i=r.subarray(8,12),a=r.subarray(12),s=[0,0,-1,1],o=$.dotVec4(s,i)/$.dotVec4(s,a),l=wA;t.project.unproject(e,o,gA,EA,l);var u=$.normalizeVec3($.subVec3(l,t.eye,IA)),c=$.addVec3(t.eye,$.mulVec3Scalar(u,n,yA),mA);this.setPivotPos(c)}},{key:"getPivotPos",value:function(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}},{key:"continuePivot",value:function(e,t){if(this._pivoting&&(0!==e||0!==t)){var n=this._scene.camera,r=-e,i=-t;1===n.worldUp[2]&&(r=-r),this._azimuth+=.01*-r,this._polar+=.01*i,this._polar=$.clamp(this._polar,.001,Math.PI-.001);var a=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===n.worldUp[2]){var s=a[1];a[1]=a[2],a[2]=s}var o=$.lenVec3($.subVec3(n.look,n.eye,$.vec3())),l=this.getPivotPos();$.addVec3(a,l);var u=$.lookAtMat4v(a,l,n.worldUp);u=$.inverseMat4(u);var c=$.transformVec3(u,this._cameraOffset);u[12]-=c[0],u[13]-=c[1],u[14]-=c[2];var f=[u[8],u[9],u[10]];n.eye=[u[12],u[13],u[14]],$.subVec3(n.eye,$.mulVec3Scalar(f,o),n.look),n.up=[u[4],u[5],u[6]],this.showPivot()}}},{key:"showPivot",value:function(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}},{key:"hidePivot",value:function(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}},{key:"endPivot",value:function(){this._pivoting=!1}},{key:"destroy",value:function(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}]),e}(),bA=function(){function e(t,n){b(this,e),this._scene=t.scene,this._cameraControl=t,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=n,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=$.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}return P(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){var e="".concat(~~this.pickCursorPos[0],"-").concat(~~this.pickCursorPos[1],"-").concat(this.scheduleSnapOrPick,"-").concat(this.schedulePickSurface,"-").concat(this.schedulePickEntity);if(this._lastHash!==e){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;var t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var n=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});n&&(n.snappedToEdge||n.snappedToVertex)?(this.snapPickResult=n,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var r=this.pickResult.canvasPos;if(r[0]===this.pickCursorPos[0]&&r[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){var i=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(i[0]===this.pickCursorPos[0]&&i[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}}}},{key:"fireEvents",value:function(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){var e=new yt;e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var t=this.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=t)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}]),e}(),DA=$.vec2(),PA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s,o,l,u=n.pickController,c=0,f=0,p=0,A=0,d=!1,v=$.vec3(),h=!0,I=this._scene.canvas.canvas,y=[];function m(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];I.style.cursor="move",w(),e&&g()}function w(){c=i.pointerCanvasPos[0],f=i.pointerCanvasPos[1],p=i.pointerCanvasPos[0],A=i.pointerCanvasPos[1]}function g(){u.pickCursorPos=i.pointerCanvasPos,u.schedulePickSurface=!0,u.update(),u.picked&&u.pickedSurface&&u.pickResult&&u.pickResult.worldPos?(d=!0,v.set(u.pickResult.worldPos)):d=!1}document.addEventListener("keydown",this._documentKeyDownHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!0}}),document.addEventListener("keyup",this._documentKeyUpHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!1}}),I.addEventListener("mousedown",this._mouseDownHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:y[t.input.KEY_SHIFT]||r.planView?(s=!0,m()):(s=!0,m(!1));break;case 2:o=!0,m();break;case 3:l=!0,r.panRightClick&&m()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=function(){if(r.active&&r.pointerEnabled&&(s||o||l)){var e=t.canvas.boundary,n=e[2],u=e[3],p=i.pointerCanvasPos[0],A=i.pointerCanvasPos[1];if(y[t.input.KEY_SHIFT]||r.planView||!r.panRightClick&&o||r.panRightClick&&l){var h=p-c,I=A-f,m=t.camera;if("perspective"===m.projection){var w=Math.abs(d?$.lenVec3($.subVec3(v,t.camera.eye,[])):t.camera.eyeLookDist)*Math.tan(m.perspective.fov/2*Math.PI/180);a.panDeltaX+=1.5*h*w/u,a.panDeltaY+=1.5*I*w/u}else a.panDeltaX+=.5*m.ortho.scale*(h/u),a.panDeltaY+=.5*m.ortho.scale*(I/u)}else!s||o||l||r.planView||(r.firstPerson?(a.rotateDeltaY-=(p-c)/n*r.dragRotationRate/2,a.rotateDeltaX+=(A-f)/u*(r.dragRotationRate/4)):(a.rotateDeltaY-=(p-c)/n*(1.5*r.dragRotationRate),a.rotateDeltaX+=(A-f)/u*(1.5*r.dragRotationRate)));c=p,f=A}}),I.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){r.active&&r.pointerEnabled&&i.mouseover&&(h=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:case 2:case 3:s=!1,o=!1,l=!1}}),I.addEventListener("mouseup",this._mouseUpHandler=function(e){if(r.active&&r.pointerEnabled){if(3===e.which){!function(e,t){if(e){for(var n=e.target,r=0,i=0,a=0,s=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,a+=n.scrollLeft,s+=n.scrollTop,n=n.offsetParent;t[0]=e.pageX+a-r,t[1]=e.pageY+s-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,DA);var t=DA[0],i=DA[1];Math.abs(t-p)<3&&Math.abs(i-A)<3&&n.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:DA,event:e},!0)}I.style.removeProperty("cursor")}}),I.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var E=1/60,T=null;I.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled){var t=performance.now()/1e3,n=null!==T?t-T:0;T=t,n>.05&&(n=.05),n<E&&(n=E);var s=Math.max(-1,Math.min(1,40*-e.deltaY));if(0!==s){var o=s/Math.abs(s);a.dollyDelta+=-o*n*r.mouseWheelDollyRate,h&&(i.followPointerDirty=!0,h=!1)}}},{passive:!0})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var 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)}}]),e}(),CA=$.vec3(),_A=$.vec3(),RA=$.vec3(),BA=$.vec3(),OA=$.vec3(),SA={eye:$.vec3(),look:$.vec3(),up:$.vec3()},NA=function(){function e(t,n,r,i){b(this,e),this._scene=t;var a=n.cameraControl,s=t.camera;this._onSceneKeyDown=t.input.on("keydown",(function(){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover){var e=a._isKeyDownForAction(a.AXIS_VIEW_RIGHT),o=a._isKeyDownForAction(a.AXIS_VIEW_BACK),l=a._isKeyDownForAction(a.AXIS_VIEW_LEFT),u=a._isKeyDownForAction(a.AXIS_VIEW_FRONT),c=a._isKeyDownForAction(a.AXIS_VIEW_TOP),f=a._isKeyDownForAction(a.AXIS_VIEW_BOTTOM);if(e||o||l||u||c||f){var p=t.aabb,A=$.getAABB3Diag(p);$.getAABB3Center(p,CA);var d=Math.abs(A/Math.tan(n.cameraFlight.fitFOV*$.DEGTORAD)),v=1.1*A;SA.orthoScale=v,e?(SA.eye.set($.addVec3(CA,$.mulVec3Scalar(s.worldRight,d,_A),OA)),SA.look.set(CA),SA.up.set(s.worldUp)):o?(SA.eye.set($.addVec3(CA,$.mulVec3Scalar(s.worldForward,d,_A),OA)),SA.look.set(CA),SA.up.set(s.worldUp)):l?(SA.eye.set($.addVec3(CA,$.mulVec3Scalar(s.worldRight,-d,_A),OA)),SA.look.set(CA),SA.up.set(s.worldUp)):u?(SA.eye.set($.addVec3(CA,$.mulVec3Scalar(s.worldForward,-d,_A),OA)),SA.look.set(CA),SA.up.set(s.worldUp)):c?(SA.eye.set($.addVec3(CA,$.mulVec3Scalar(s.worldUp,d,_A),OA)),SA.look.set(CA),SA.up.set($.normalizeVec3($.mulVec3Scalar(s.worldForward,1,RA),BA))):f&&(SA.eye.set($.addVec3(CA,$.mulVec3Scalar(s.worldUp,-d,_A),OA)),SA.look.set(CA),SA.up.set($.normalizeVec3($.mulVec3Scalar(s.worldForward,-1,RA)))),!r.firstPerson&&r.followPointer&&n.pivotController.setPivotPos(CA),n.cameraFlight.duration>0?n.cameraFlight.flyTo(SA,(function(){n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot()})):(n.cameraFlight.jumpTo(SA),n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot())}}}))}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.input.off(this._onSceneKeyDown)}}]),e}(),LA=function(){function e(t,n,r,i,a){var s=this;b(this,e),this._scene=t;var o=n.pickController,l=n.pivotController,u=n.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;var c=!1,f=!1,p=this._scene.canvas.canvas,A=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e&&e.entity?e.entity.aabb:t.aabb;if(r){var a=t.camera;$.subVec3(a.eye,a.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})},d=t.tickify(this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!c&&!f){var n=u.hasSubs("hover"),a=u.hasSubs("hoverEnter"),l=u.hasSubs("hoverOut"),p=u.hasSubs("hoverOff"),A=u.hasSubs("hoverSurface"),d=u.hasSubs("hoverSnapOrSurface");if(n||a||l||p||A||d)if(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=A,o.scheduleSnapOrPick=d,o.update(),o.pickResult){if(o.pickResult.entity){var v=o.pickResult.entity.id;s._lastPickedEntityId!==v&&(void 0!==s._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),u.fire("hoverEnter",o.pickResult,!0),s._lastPickedEntityId=v)}u.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&u.fire("hoverSurface",o.pickResult,!0)}else void 0!==s._lastPickedEntityId&&(u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),s._lastPickedEntityId=void 0),u.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)}});p.addEventListener("mousemove",d),p.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(c=!0),3===e.which&&(f=!0),1===e.which&&r.active&&r.pointerEnabled&&(i.mouseDownClientX=e.clientX,i.mouseDownClientY=e.clientY,i.mouseDownCursorX=i.pointerCanvasPos[0],i.mouseDownCursorY=i.pointerCanvasPos[1],!r.firstPerson&&r.followPointer&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===e.which))){var n=o.pickResult;n&&n.worldPos?(l.setPivotPos(n.worldPos),l.startPivot()):(r.smartPivot?l.setCanvasPivotPos(i.pointerCanvasPos):l.setPivotPos(t.camera.look),l.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(c=!1),3===e.which&&(f=!1),l.getPivoting()&&l.endPivot()}),p.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(r.active&&r.pointerEnabled&&(1===e.which&&(l.hidePivot(),!(Math.abs(e.clientX-i.mouseDownClientX)>3||Math.abs(e.clientY-i.mouseDownClientY)>3)))){var a=u.hasSubs("picked"),c=u.hasSubs("pickedNothing"),f=u.hasSubs("pickedSurface"),p=u.hasSubs("doublePicked"),d=u.hasSubs("doublePickedSurface"),v=u.hasSubs("doublePickedNothing");if(!(r.doublePickFlyTo||p||d||v))return(a||c||f)&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=f,o.update(),o.pickResult?(u.fire("picked",o.pickResult,!0),o.pickedSurface&&u.fire("pickedSurface",o.pickResult,!0)):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0)),void(s._clicks=0);if(s._clicks++,1===s._clicks){o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo,o.schedulePickSurface=f,o.update();var h=o.pickResult,I=o.pickedSurface;s._timeout=setTimeout((function(){h?(u.fire("picked",h,!0),I&&(u.fire("pickedSurface",h,!0),!r.firstPerson&&r.followPointer&&(n.pivotController.setPivotPos(h.worldPos),n.pivotController.startPivot()&&n.pivotController.showPivot()))):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0),s._clicks=0}),r.doubleClickTimeFrame)}else{if(null!==s._timeout&&(window.clearTimeout(s._timeout),s._timeout=null),o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo||p||d,o.schedulePickSurface=o.schedulePickEntity&&d,o.update(),o.pickResult){if(u.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&u.fire("doublePickedSurface",o.pickResult,!0),r.doublePickFlyTo&&(A(o.pickResult),!r.firstPerson&&r.followPointer)){var y=o.pickResult.entity.aabb,m=$.getAABB3Center(y);n.pivotController.setPivotPos(m),n.pivotController.startPivot()&&n.pivotController.showPivot()}}else if(u.fire("doublePickedNothing",{canvasPos:i.pointerCanvasPos},!0),r.doublePickFlyTo&&(A(),!r.firstPerson&&r.followPointer)){var w=t.aabb,g=$.getAABB3Center(w);n.pivotController.setPivotPos(g),n.pivotController.startPivot()&&n.pivotController.showPivot()}s._clicks=0}}},!1)}return P(e,[{key:"reset",value:function(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}]),e}(),xA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.input,o=[],l=t.canvas.canvas,u=!0;this._onSceneMouseMove=s.on("mousemove",(function(){u=!0})),this._onSceneKeyDown=s.on("keydown",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover&&(o[e]=!0,e===s.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=s.on("keyup",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(o[e]=!1,e===s.KEY_SHIFT&&(l.style.cursor=null),n.pivotController.getPivoting()&&n.pivotController.endPivot())})),this._onTick=t.on("tick",(function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover){var l=n.cameraControl,c=e.deltaTime/1e3;if(!r.planView){var f=l._isKeyDownForAction(l.ROTATE_Y_POS,o),p=l._isKeyDownForAction(l.ROTATE_Y_NEG,o),A=l._isKeyDownForAction(l.ROTATE_X_POS,o),d=l._isKeyDownForAction(l.ROTATE_X_NEG,o),v=c*r.keyboardRotationRate;(f||p||A||d)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),f?a.rotateDeltaY+=v:p&&(a.rotateDeltaY-=v),A?a.rotateDeltaX+=v:d&&(a.rotateDeltaX-=v),!r.firstPerson&&r.followPointer&&n.pivotController.startPivot())}if(!o[s.KEY_CTRL]&&!o[s.KEY_ALT]){var h=l._isKeyDownForAction(l.DOLLY_BACKWARDS,o),I=l._isKeyDownForAction(l.DOLLY_FORWARDS,o);if(h||I){var y=c*r.keyboardDollyRate;!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),I?a.dollyDelta-=y:h&&(a.dollyDelta+=y),u&&(i.followPointerDirty=!0,u=!1)}}var m=l._isKeyDownForAction(l.PAN_FORWARDS,o),w=l._isKeyDownForAction(l.PAN_BACKWARDS,o),g=l._isKeyDownForAction(l.PAN_LEFT,o),E=l._isKeyDownForAction(l.PAN_RIGHT,o),T=l._isKeyDownForAction(l.PAN_UP,o),b=l._isKeyDownForAction(l.PAN_DOWN,o),D=(o[s.KEY_ALT]?.3:1)*c*r.keyboardPanRate;(m||w||g||E||T||b)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),b?a.panDeltaY+=D:T&&(a.panDeltaY+=-D),E?a.panDeltaX+=-D:g&&(a.panDeltaX+=D),w?a.panDeltaZ+=D:m&&(a.panDeltaZ+=-D))}}))}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}]),e}(),MA=$.vec3(),FA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.camera,o=n.pickController,l=n.pivotController,u=n.panController,c=1,f=1,p=null;this._onTick=t.on("tick",(function(){if(r.active&&r.pointerEnabled){var e="default";if(Math.abs(a.dollyDelta)<.001&&(a.dollyDelta=0),Math.abs(a.rotateDeltaX)<.001&&(a.rotateDeltaX=0),Math.abs(a.rotateDeltaY)<.001&&(a.rotateDeltaY=0),0===a.rotateDeltaX&&0===a.rotateDeltaY||(a.dollyDelta=0),r.followPointer&&--c<=0&&(c=1,0!==a.dollyDelta)){if(0===a.rotateDeltaY&&0===a.rotateDeltaX&&r.followPointer&&i.followPointerDirty&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.pickResult&&o.pickResult.worldPos?p=o.pickResult.worldPos:(f=1,p=null),i.followPointerDirty=!1),p){var n=Math.abs($.lenVec3($.subVec3(p,t.camera.eye,MA)));f=n/r.dollyProximityThreshold}f<r.dollyMinSpeed&&(f=r.dollyMinSpeed)}var A=a.dollyDelta*f;if(0===a.rotateDeltaY&&0===a.rotateDeltaX||(!r.firstPerson&&r.followPointer&&l.getPivoting()?(l.continuePivot(a.rotateDeltaY,a.rotateDeltaX),l.showPivot()):(0!==a.rotateDeltaX&&(r.firstPerson?s.pitch(-a.rotateDeltaX):s.orbitPitch(a.rotateDeltaX)),0!==a.rotateDeltaY&&(r.firstPerson?s.yaw(a.rotateDeltaY):s.orbitYaw(a.rotateDeltaY))),a.rotateDeltaX*=r.rotationInertia,a.rotateDeltaY*=r.rotationInertia,e="grabbing"),Math.abs(a.panDeltaX)<.001&&(a.panDeltaX=0),Math.abs(a.panDeltaY)<.001&&(a.panDeltaY=0),Math.abs(a.panDeltaZ)<.001&&(a.panDeltaZ=0),0!==a.panDeltaX||0!==a.panDeltaY||0!==a.panDeltaZ){var d,v,h=$.vec3();if(h[0]=a.panDeltaX,h[1]=a.panDeltaY,h[2]=a.panDeltaZ,r.constrainVertical){s.xUp?(d=s.eye[0],v=s.look[0]):s.yUp?(d=s.eye[1],v=s.look[1]):s.zUp&&(d=s.eye[2],v=s.look[2]),s.pan(h);var I=s.eye,y=s.look;s.xUp?(I[0]=d,y[0]=v):s.yUp?(I[1]=d,y[1]=v):s.zUp&&(I[2]=d,y[2]=v),s.eye=I,s.look=y}else s.pan(h);e="grabbing"}if(a.panDeltaX*=r.panInertia,a.panDeltaY*=r.panInertia,a.panDeltaZ*=r.panInertia,0!==A){if(e=A<0?"zoom-in":"zoom-out",r.firstPerson){var m,w;if(r.constrainVertical&&(s.xUp?(m=s.eye[0],w=s.look[0]):s.yUp?(m=s.eye[1],w=s.look[1]):s.zUp&&(m=s.eye[2],w=s.look[2])),r.followPointer)u.dollyToCanvasPos(p,i.pointerCanvasPos,-A)&&(i.followPointerDirty=!0);else s.pan([0,0,A]),s.ortho.scale=s.ortho.scale-A;if(r.constrainVertical){var g=s.eye,E=s.look;s.xUp?(g[0]=m,E[0]=w):s.yUp?(g[1]=m,E[1]=w):s.zUp&&(g[2]=m,E[2]=w),s.eye=g,s.look=E}}else if(r.planView){if(r.followPointer)u.dollyToCanvasPos(p,i.pointerCanvasPos,-A)&&(i.followPointerDirty=!0);else s.ortho.scale=s.ortho.scale+A,s.zoom(A)}else{if(r.followPointer)u.dollyToCanvasPos(p,i.pointerCanvasPos,-A)&&(i.followPointerDirty=!0);else s.ortho.scale=s.ortho.scale+A,s.zoom(A)}a.dollyDelta*=r.dollyInertia}o.fireEvents(),document.body.style.cursor=e}}))}return P(e,[{key:"destroy",value:function(){this._scene.off(this._onTick)}}]),e}(),HA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=this._scene.canvas.canvas;s.addEventListener("mouseenter",this._mouseEnterHandler=function(){i.mouseover=!0}),s.addEventListener("mouseleave",this._mouseLeaveHandler=function(){i.mouseover=!1,s.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=function(e){UA(e,s,i.pointerCanvasPos)}),s.addEventListener("mousedown",this._mouseDownHandler=function(e){r.active&&r.pointerEnabled&&(UA(e,s,i.pointerCanvasPos),i.mouseover=!0)}),s.addEventListener("mouseup",this._mouseUpHandler=function(e){r.active&&r.pointerEnabled})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var 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)}}]),e}();function UA(e,t,n){if(e){var r=t.getBoundingClientRect(),i=r.x,a=r.y;n[0]=e.clientX-i,n[1]=e.clientY-a}else e=window.event,n[0]=e.x,n[1]=e.y;return n}var GA=function(e,t){if(e){for(var n=e.target,r=0,i=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;t[0]=e.pageX-r,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t},kA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=n.pickController,o=n.pivotController,l=$.vec2(),u=$.vec2(),c=$.vec2(),f=$.vec2(),p=[],A=this._scene.canvas.canvas,d=0,v=!1;this._onTick=t.on("tick",(function(){v=!1})),A.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){if(r.active&&r.pointerEnabled){e.preventDefault();var n=e.touches,a=e.changedTouches;for(i.touchStartTime=Date.now(),1===n.length&&1===a.length&&(GA(n[0],l),r.followPointer&&(s.pickCursorPos=l,s.schedulePickSurface=!0,s.update(),r.planView||(s.picked&&s.pickedSurface&&s.pickResult&&s.pickResult.worldPos?(o.setPivotPos(s.pickResult.worldPos),!r.firstPerson&&o.startPivot()&&o.showPivot()):(r.smartPivot?o.setCanvasPivotPos(i.pointerCanvasPos):o.setPivotPos(t.camera.look),!r.firstPerson&&o.startPivot()&&o.showPivot()))));p.length<n.length;)p.push($.vec2());for(var u=0,c=n.length;u<c;++u)GA(n[u],p[u]);d=n.length}}),A.addEventListener("touchend",this._canvasTouchEndHandler=function(){o.getPivoting()&&o.endPivot()}),A.addEventListener("touchmove",this._canvasTouchMoveHandler=function(e){if(r.active&&r.pointerEnabled&&(e.stopPropagation(),e.preventDefault(),!v)){v=!0;var n=t.canvas.boundary,o=n[2],l=n[3],A=e.touches;if(e.touches.length===d){if(1===d){GA(A[0],u),$.subVec2(u,p[0],f);var h=f[0],I=f[1];if(null!==i.longTouchTimeout&&(Math.abs(h)>r.longTapRadius||Math.abs(I)>r.longTapRadius)&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),r.planView){var y=t.camera;if("perspective"===y.projection){var m=Math.abs(t.camera.eyeLookDist)*Math.tan(y.perspective.fov/2*Math.PI/180);a.panDeltaX+=h*m/l*r.touchPanRate,a.panDeltaY+=I*m/l*r.touchPanRate}else a.panDeltaX+=.5*y.ortho.scale*(h/l)*r.touchPanRate,a.panDeltaY+=.5*y.ortho.scale*(I/l)*r.touchPanRate}else a.rotateDeltaY-=h/o*(1*r.dragRotationRate),a.rotateDeltaX+=I/l*(1.5*r.dragRotationRate)}else if(2===d){var w=A[0],g=A[1];GA(w,u),GA(g,c);var E=$.geometricMeanVec2(p[0],p[1]),T=$.geometricMeanVec2(u,c),b=$.vec2();$.subVec2(E,T,b);var D=b[0],P=b[1],C=t.camera,_=$.distVec2([w.pageX,w.pageY],[g.pageX,g.pageY]),R=($.distVec2(p[0],p[1])-_)*r.touchDollyRate;if(a.dollyDelta=R,Math.abs(R)<1)if("perspective"===C.projection){var B=s.pickResult?s.pickResult.worldPos:t.center,O=Math.abs($.lenVec3($.subVec3(B,t.camera.eye,[])))*Math.tan(C.perspective.fov/2*Math.PI/180);a.panDeltaX-=D*O/l*r.touchPanRate,a.panDeltaY-=P*O/l*r.touchPanRate}else a.panDeltaX-=.5*C.ortho.scale*(D/l)*r.touchPanRate,a.panDeltaY-=.5*C.ortho.scale*(P/l)*r.touchPanRate;i.pointerCanvasPos=T}for(var S=0;S<d;++S)GA(A[S],p[S])}}})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var 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)}}]),e}(),jA=function(e,t){if(e){for(var n=e.target,r=0,i=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;t[0]=e.pageX-r,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t},VA=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s,o=n.pickController,l=n.cameraControl,u=[],c=new Float32Array(2),f=-1,p=-1,A=this._scene.canvas.canvas,d=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e?e.entity.aabb:t.aabb;if(r){var a=t.camera;$.subVec3(a.eye,a.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})};A.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){if(r.active&&r.pointerEnabled){null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null);var t=e.touches,a=e.changedTouches;if(s=Date.now(),1===t.length&&1===a.length){f=s,jA(t[0],c);var o=c[0],l=c[1],p=t[0].pageX,A=t[0].pageY;i.longTouchTimeout=setTimeout((function(){n.cameraControl.fire("rightClick",{pagePos:[Math.round(p),Math.round(A)],canvasPos:[Math.round(o),Math.round(l)],event:e},!0),i.longTouchTimeout=null}),r.longTapTimeout)}else f=-1;for(;u.length<t.length;)u.push(new Float32Array(2));for(var d=0,v=t.length;d<v;++d)jA(t[d],u[d]);u.length=t.length}},{passive:!0}),A.addEventListener("touchend",this._canvasTouchEndHandler=function(e){if(r.active&&r.pointerEnabled){var t=Date.now(),n=e.touches,a=e.changedTouches,s=l.hasSubs("pickedSurface");null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),0===n.length&&1===a.length&&f>-1&&t-f<150&&(p>-1&&f-p<325?(jA(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=s,o.update(),o.pickResult?(o.pickResult.touchInput=!0,l.fire("doublePicked",o.pickResult),o.pickedSurface&&l.fire("doublePickedSurface",o.pickResult),r.doublePickFlyTo&&d(o.pickResult)):(l.fire("doublePickedNothing"),r.doublePickFlyTo&&d()),p=-1):$.distVec2(u[0],c)<4&&(jA(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=s,o.update(),o.pickResult?(o.pickResult.touchInput=!0,l.fire("picked",o.pickResult),o.pickedSurface&&l.fire("pickedSurface",o.pickResult)):l.fire("pickedNothing"),p=t),f=-1),u.length=n.length;for(var A=0,v=n.length;A<v;++A)u[A][0]=n[A].pageX,u[A][1]=n[A].pageY}},{passive:!0})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler)}}]),e}(),QA=function(e){h(n,me);var t=y(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i)).PAN_LEFT=0,r.PAN_RIGHT=1,r.PAN_UP=2,r.PAN_DOWN=3,r.PAN_FORWARDS=4,r.PAN_BACKWARDS=5,r.ROTATE_X_POS=6,r.ROTATE_X_NEG=7,r.ROTATE_Y_POS=8,r.ROTATE_Y_NEG=9,r.DOLLY_FORWARDS=10,r.DOLLY_BACKWARDS=11,r.AXIS_VIEW_RIGHT=12,r.AXIS_VIEW_BACK=13,r.AXIS_VIEW_LEFT=14,r.AXIS_VIEW_FRONT=15,r.AXIS_VIEW_TOP=16,r.AXIS_VIEW_BOTTOM=17,r._keyMap={},r.scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},r._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},r._states={pointerCanvasPos:$.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:$.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},r._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};var a=r.scene;return r._controllers={cameraControl:w(r),pickController:new bA(w(r),r._configs),pivotController:new TA(a,r._configs),panController:new hA(a),cameraFlight:new Fp(w(r),{duration:.5})},r._handlers=[new HA(r.scene,r._controllers,r._configs,r._states,r._updates),new kA(r.scene,r._controllers,r._configs,r._states,r._updates),new PA(r.scene,r._controllers,r._configs,r._states,r._updates),new NA(r.scene,r._controllers,r._configs,r._states,r._updates),new LA(r.scene,r._controllers,r._configs,r._states,r._updates),new VA(r.scene,r._controllers,r._configs,r._states,r._updates),new xA(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cameraUpdater=new FA(r.scene,r._controllers,r._configs,r._states,r._updates),r.navMode=i.navMode,i.planView&&(r.planView=i.planView),r.constrainVertical=i.constrainVertical,i.keyboardLayout?r.keyboardLayout=i.keyboardLayout:r.keyMap=i.keyMap,r.doublePickFlyTo=i.doublePickFlyTo,r.panRightClick=i.panRightClick,r.active=i.active,r.followPointer=i.followPointer,r.rotationInertia=i.rotationInertia,r.keyboardPanRate=i.keyboardPanRate,r.touchPanRate=i.touchPanRate,r.keyboardRotationRate=i.keyboardRotationRate,r.dragRotationRate=i.dragRotationRate,r.touchDollyRate=i.touchDollyRate,r.dollyInertia=i.dollyInertia,r.dollyProximityThreshold=i.dollyProximityThreshold,r.dollyMinSpeed=i.dollyMinSpeed,r.panInertia=i.panInertia,r.pointerEnabled=!0,r.keyboardDollyRate=i.keyboardDollyRate,r.mouseWheelDollyRate=i.mouseWheelDollyRate,r}return P(n,[{key:"keyMap",get:function(){return this._keyMap},set:function(e){if(e=e||"qwerty",le.isString(e)){var t=this.scene.input,n={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":n[this.PAN_LEFT]=[t.KEY_A],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_Z],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":n[this.PAN_LEFT]=[t.KEY_Q],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_W],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=n}else{var r=e;this._keyMap=r}}},{key:"_isKeyDownForAction",value:function(e,t){var n=this._keyMap[e];if(!n)return!1;t||(t=this.scene.input.keyDown);for(var r=0,i=n.length;r<i;r++){if(t[n[r]])return!0}return!1}},{key:"pivotElement",set:function(e){this._controllers.pivotController.setPivotElement(e)}},{key:"active",get:function(){return this._configs.active},set:function(e){e=!1!==e,this._configs.active=e,this._handlers[1]._active=e,this._handlers[5]._active=e}},{key:"snapToVertex",get:function(){return this._configs.snapToVertex},set:function(e){this._configs.snapToVertex=!!e}},{key:"snapToEdge",get:function(){return this._configs.snapToEdge},set:function(e){this._configs.snapToEdge=!!e}},{key:"snapRadius",get:function(){return this._configs.snapRadius},set:function(e){e=e||30,this._configs.snapRadius=e}},{key:"navMode",get:function(){return this._configs.navMode},set:function(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}},{key:"pointerEnabled",get:function(){return this._configs.pointerEnabled},set:function(e){this._reset(),this._configs.pointerEnabled=!!e}},{key:"_reset",value:function(){for(var e=0,t=this._handlers.length;e<t;e++){var n=this._handlers[e];n.reset&&n.reset()}this._updates.panDeltaX=0,this._updates.panDeltaY=0,this._updates.rotateDeltaX=0,this._updates.rotateDeltaY=0,this._updates.dolyDelta=0}},{key:"followPointer",get:function(){return this._configs.followPointer},set:function(e){this._configs.followPointer=!1!==e}},{key:"pivotPos",get:function(){return this._controllers.pivotController.getPivotPos()},set:function(e){this._controllers.pivotController.setPivotPos(e)}},{key:"dollyToPointer",get:function(){return this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer},set:function(e){this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer=e}},{key:"panToPointer",get:function(){return this.warn("panToPointer property is deprecated - replaced with followPointer"),!1},set:function(e){this.warn("panToPointer property is deprecated - replaced with followPointer")}},{key:"planView",get:function(){return this.warn("planView property is deprecated - replaced with navMode"),this._configs.planView},set:function(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")}},{key:"firstPerson",get:function(){return this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson},set:function(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())}},{key:"constrainVertical",get:function(){return this._configs.constrainVertical},set:function(e){this._configs.constrainVertical=!!e}},{key:"doublePickFlyTo",get:function(){return this._configs.doublePickFlyTo},set:function(e){this._configs.doublePickFlyTo=!1!==e}},{key:"panRightClick",get:function(){return this._configs.panRightClick},set:function(e){this._configs.panRightClick=!1!==e}},{key:"rotationInertia",get:function(){return this._configs.rotationInertia},set:function(e){this._configs.rotationInertia=null!=e?e:0}},{key:"keyboardPanRate",get:function(){return this._configs.keyboardPanRate},set:function(e){this._configs.keyboardPanRate=null!=e?e:5}},{key:"touchPanRate",get:function(){return this._configs.touchPanRate},set:function(e){this._configs.touchPanRate=null!=e?e:1}},{key:"keyboardRotationRate",get:function(){return this._configs.keyboardRotationRate},set:function(e){this._configs.keyboardRotationRate=null!=e?e:90}},{key:"dragRotationRate",get:function(){return this._configs.dragRotationRate},set:function(e){this._configs.dragRotationRate=null!=e?e:360}},{key:"keyboardDollyRate",get:function(){return this._configs.keyboardDollyRate},set:function(e){this._configs.keyboardDollyRate=null!=e?e:15}},{key:"touchDollyRate",get:function(){return this._configs.touchDollyRate},set:function(e){this._configs.touchDollyRate=null!=e?e:.2}},{key:"mouseWheelDollyRate",get:function(){return this._configs.mouseWheelDollyRate},set:function(e){this._configs.mouseWheelDollyRate=null!=e?e:100}},{key:"dollyInertia",get:function(){return this._configs.dollyInertia},set:function(e){this._configs.dollyInertia=null!=e?e:0}},{key:"dollyProximityThreshold",get:function(){return this._configs.dollyProximityThreshold},set:function(e){this._configs.dollyProximityThreshold=null!=e?e:35}},{key:"dollyMinSpeed",get:function(){return this._configs.dollyMinSpeed},set:function(e){this._configs.dollyMinSpeed=null!=e?e:.04}},{key:"panInertia",get:function(){return this._configs.panInertia},set:function(e){this._configs.panInertia=null!=e?e:.5}},{key:"keyboardLayout",get:function(){return this._configs.keyboardLayout},set:function(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}},{key:"enablePivotSphere",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._controllers.pivotController.enablePivotSphere(e)}},{key:"disablePivotSphere",value:function(){this._controllers.pivotController.disablePivotSphere()}},{key:"smartPivot",get:function(){return this._configs.smartPivot},set:function(e){this._configs.smartPivot=!1!==e}},{key:"doubleClickTimeFrame",get:function(){return this._configs.doubleClickTimeFrame},set:function(e){this._configs.doubleClickTimeFrame=null!=e?e:250}},{key:"destroy",value:function(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),d(g(n.prototype),"destroy",this).call(this)}},{key:"_destroyHandlers",value:function(){for(var e=0,t=this._handlers.length;e<t;e++){var n=this._handlers[e];n.destroy&&n.destroy()}}},{key:"_destroyControllers",value:function(){for(var e=0,t=this._controllers.length;e<t;e++){var n=this._controllers[e];n.destroy&&n.destroy()}}}]),n}(),WA=P((function e(t,n,r,i,a){b(this,e),this.name=t,this.type=r,this.value=n,this.valueType=i,this.description=a})),zA=P((function e(t){if(b(this,e),this.id=t.id,this.originalSystemId=t.originalSystemId,this.metaModels=[],this.name=t.name,this.type=t.type,this.properties=[],t.properties)for(var n=t.properties,r=0,i=n.length;r<i;r++){var a=n[r];this.properties.push(new WA(a.name,a.value,a.type,a.valueType,a.description))}})),KA=function(){function e(t){b(this,e),this.metaModels=[],this.id=t.id,this.parentId=t.parentId,this.parent=null,this.originalSystemId=t.originalSystemId,this.name=t.name,this.type=t.type,this.propertySetIds=t.propertySetIds,this.propertySets=[],this.attributes=t.attributes||{},void 0!==t.external&&null!==t.external&&(this.external=t.external)}return P(e,[{key:"metaModel",get:function(){return 1==this.metaModels.length?this.metaModels[0]:null}},{key:"getObjectIDsInSubtree",value:function(){var e=[];return function t(n){if(n){e.push(n.id);var r=n.children;if(r)for(var i=0,a=r.length;i<a;i++)t(r[i])}}(this),e}},{key:"withMetaObjectsInSubtree",value:function(e){!function t(n){if(n){e(n);var r=n.children;if(r)for(var i=0,a=r.length;i<a;i++)t(r[i])}}(this)}},{key:"getObjectIDsInSubtreeByType",value:function(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=e[n];var i=[];return function e(n){if(n){t[n.type]&&i.push(n.id);var r=n.children;if(r)for(var a=0,s=r.length;a<s;a++)e(r[a])}}(this),i}},{key:"getJSON",value:function(){var e={id:this.id,type:this.type,name:this.name};return this.parent&&(e.parent=this.parent.id),e}}]),e}(),YA=function(){function e(t){b(this,e),this.id=t.id,this.projectId=t.projectId,this.revisionId=t.revisionId,this.author=t.author,this.createdAt=t.createdAt,this.creatingApplication=t.creatingApplication,this.schema=t.schema,this.metaScene=t.metaScene,this.propertySets=[],this.rootMetaObjects=[],this.metaObjects=[],this.graph=t.graph||{},this.metaScene.metaModels[this.id]=this,this.finalized=!1}return P(e,[{key:"rootMetaObject",get:function(){return 1==this.rootMetaObjects.length?this.rootMetaObjects[0]:null}},{key:"loadData",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);var n=this.metaScene,r=e.properties;if(e.propertySets)for(var i=0,a=e.propertySets.length;i<a;i++){var s=e.propertySets[i],o=n.propertySets[s.id];o||(r&&this._decompressProperties(r,s.properties),o=new zA({id:s.id,originalSystemId:s.originalSystemId||s.id,type:s.type,name:s.name,properties:s.properties}),n.propertySets[o.id]=o),o.metaModels.push(this),this.propertySets.push(o)}if(e.metaObjects)for(var l=0,u=e.metaObjects.length;l<u;l++){var c=e.metaObjects[l],f=c.id,p=n.metaObjects[f];if(!p){var A=c.type,d=c.originalSystemId,v=c.propertySets||c.propertySetIds;p=new KA({id:f,originalSystemId:d,parentId:c.parent,type:A,name:c.name,attributes:c.attributes,propertySetIds:v,external:c.external}),this.metaScene.metaObjects[f]=p,p.metaModels=[]}this.metaObjects.push(p),c.parent||(this.rootMetaObjects.push(p),n.rootMetaObjects[f]=p)}}},{key:"_decompressProperties",value:function(e,t){for(var n=0,r=t.length;n<r;n++){var i=t[n];if(Number.isInteger(i)){var a=e[i];a&&(t[n]=a)}}}},{key:"finalize",value:function(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";var e=this.metaScene;for(var t in e.metaObjects){var n=e.metaObjects[t];if(n.children&&(n.children=[]),n.propertySets&&(n.propertySets=[]),n.propertySetIds)for(var r=0,i=n.propertySetIds.length;r<i;r++){var a=n.propertySetIds[r],s=e.propertySets[a];n.propertySets.push(s)}}for(var o in e.metaObjects){var l=e.metaObjects[o];if(l.parentId){var u=e.metaObjects[l.parentId];u&&(l.parent=u,(u.children||(u.children=[])).push(l))}}for(var c in e.metaObjects){e.metaObjects[c].metaModels=[]}for(var f in e.metaModels)for(var p=e.metaModels[f],A=0,d=p.metaObjects.length;A<d;A++){p.metaObjects[A].metaModels.push(p)}for(var v in e.metaObjectsByType={},e.metaObjects){var h=e.metaObjects[v],I=h.type;(e.metaObjectsByType[I]||(e.metaObjectsByType[I]={}))[v]=h}this.finalized=!0,this.metaScene.fire("metaModelCreated",this.id)}},{key:"getJSON",value:function(){for(var e={id:this.id,projectId:this.projectId,author:this.author,createdAt:this.createdAt,schema:this.schema,creatingApplication:this.creatingApplication,metaObjects:[],propertySets:[]},t=0,n=this.metaObjects.length;t<n;t++){var r=this.metaObjects[t],i={id:r.id,originalSystemId:r.originalSystemId,extId:r.extId,type:r.type,name:r.name};r.parent&&(i.parent=r.parent.id),r.attributes&&(i.attributes=r.attributes),r.propertySetIds&&(i.propertySetIds=r.propertySetIds),e.metaObjects.push(i)}for(var a=0,s=this.propertySets.length;a<s;a++){for(var o=this.propertySets[a],l={id:o.id,originalSystemId:o.originalSystemId,extId:o.extId,type:o.type,name:o.name,propertyies:[]},u=0,c=o.properties.length;u<c;u++){var f=o.properties[u],p={id:f.id,description:f.description,type:f.type,name:f.name,value:f.value,valueType:f.valueType};l.properties.push(p)}e.propertySets.push(l)}return e}},{key:"_globalizeIDs",value:function(e,t){var n=!!t.globalizeObjectIds;if(e.metaObjects)for(var r=0,i=e.metaObjects.length;r<i;r++){var a=e.metaObjects[r];if(a.originalSystemId=a.id,a.parent&&(a.originalParentSystemId=a.parent),n&&(a.id=$.globalizeObjectId(this.id,a.id),a.parent&&(a.parent=$.globalizeObjectId(this.id,a.parent))),n){var s=a.propertySetIds;if(s){for(var o=[],l=0,u=s.length;l<u;l++)o.push($.globalizeObjectId(this.id,s[l]));a.propertySetIds=o,a.originalSystemPropertySetIds=s}}else a.originalSystemPropertySetIds=a.propertySetIds}if(e.propertySets)for(var c=0,f=e.propertySets.length;c<f;c++){var p=e.propertySets[c];p.originalSystemId=p.id,n&&(p.id=$.globalizeObjectId(this.id,p.id))}}}]),e}(),XA=function(){function e(t,n){b(this,e),this.viewer=t,this.scene=n,this.metaModels={},this.propertySets={},this.metaObjects={},this.metaObjectsByType={},this.rootMetaObjects={},this._eventSubs={}}return P(e,[{key:"on",value:function(e,t){var n=this._eventSubs[e];n||(n=[],this._eventSubs[e]=n),n.push(t)}},{key:"fire",value:function(e,t){var n=this._eventSubs[e];if(n)for(var r=0,i=n.length;r<i;r++)n[r](t)}},{key:"off",value:function(e){}},{key:"createMetaModel",value:function(e,t){var n=new YA({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}},{key:"destroyMetaModel",value:function(e){var t=this.metaModels[e];if(t){if(t.propertySets)for(var n=0,r=t.propertySets.length;n<r;n++){var i=t.propertySets[n];if(1===i.metaModels.length&&i.metaModels[0].id===e)delete this.propertySets[i.id];else{for(var a=[],s=0,o=i.metaModels.length;s<o;s++)i.metaModels[s].id!==e&&a.push(i.metaModels[s]);i.metaModels=a}}if(t.metaObjects)for(var l=0,u=t.metaObjects.length;l<u;l++){var c=t.metaObjects[l];c.type;var f=c.id;1===c.metaModels.length&&c.metaModels[0].id===e&&(delete this.metaObjects[f],c.parent||delete this.rootMetaObjects[f])}for(var p in this.metaObjects){var A=this.metaObjects[p];if(A.children&&(A.children=[]),A.propertySets&&(A.propertySets=[]),A.propertySetIds)for(var d=0,v=A.propertySetIds.length;d<v;d++){var h=A.propertySetIds[d],I=this.propertySets[h];A.propertySets.push(I)}}for(var y in this.metaObjectsByType={},this.metaObjects){var m=this.metaObjects[y],w=m.type;m.children&&(m.children=null),(this.metaObjectsByType[w]||(this.metaObjectsByType[w]={}))[y]=m}for(var g in this.metaObjects){var E=this.metaObjects[g];if(E.parentId){var T=this.metaObjects[E.parentId];T&&(E.parent=T,(T.children||(T.children=[])).push(E))}}for(var b in delete this.metaModels[e],this.metaObjects){this.metaObjects[b].metaModels=[]}for(var D in this.metaModels)for(var P=this.metaModels[D],C=0,_=P.metaObjects.length;C<_;C++){P.metaObjects[C].metaModels.push(P)}this.fire("metaModelDestroyed",e)}}},{key:"getObjectIDsByType",value:function(e){var t=this.metaObjectsByType[e];return t?Object.keys(t):[]}},{key:"getObjectIDsInSubtree",value:function(e,t,n){var r=[],i=this.metaObjects[e],a=t&&t.length>0?qA(t):null,s=n&&n.length>0?qA(n):null;return function e(t){if(t){var n=!0;(s&&s[t.type]||a&&!a[t.type])&&(n=!1),n&&r.push(t.id);var i=t.children;if(i)for(var o=0,l=i.length;o<l;o++)e(i[o])}}(i),r}},{key:"withMetaObjectsInSubtree",value:function(e,t){var n=this.metaObjects[e];n&&n.withMetaObjectsInSubtree(t)}}]),e}();function qA(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=!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>