diff --git a/dist/xeokit-sdk.cjs.js b/dist/xeokit-sdk.cjs.js index 8749583dc..97e049a61 100644 --- a/dist/xeokit-sdk.cjs.js +++ b/dist/xeokit-sdk.cjs.js @@ -97161,7 +97161,7 @@ class MousePickHandler { this._timeout = setTimeout(() => { - if (firstClickPickResult) { + if (firstClickPickResult && firstClickPickResult.worldPos) { cameraControl.fire("picked", firstClickPickResult, true); diff --git a/dist/xeokit-sdk.es.js b/dist/xeokit-sdk.es.js index 3dd50f2b4..ba7f4dbe8 100644 --- a/dist/xeokit-sdk.es.js +++ b/dist/xeokit-sdk.es.js @@ -97157,7 +97157,7 @@ class MousePickHandler { this._timeout = setTimeout(() => { - if (firstClickPickResult) { + if (firstClickPickResult && firstClickPickResult.worldPos) { cameraControl.fire("picked", firstClickPickResult, true); diff --git a/dist/xeokit-sdk.es5.js b/dist/xeokit-sdk.es5.js index f49dc33e2..9cb593b12 100644 --- a/dist/xeokit-sdk.es5.js +++ b/dist/xeokit-sdk.es5.js @@ -22875,7 +22875,7 @@ states.mouseDownClientX=e.clientX;states.mouseDownClientY=e.clientY;states.mouse var pickResult=pickController.pickResult;if(pickResult&&pickResult.worldPos){pivotController.setPivotPos(pickResult.worldPos);pivotController.startPivot();}else{if(configs.smartPivot){pivotController.setCanvasPivotPos(states.pointerCanvasPos);}else{pivotController.setPivotPos(scene.camera.look);}pivotController.startPivot();}}}});document.addEventListener('mouseup',this._documentMouseUpHandler=function(e){if(e.which===1){leftDown=false;}if(e.which===3){rightDown=false;}if(pivotController.getPivoting()){pivotController.endPivot();}});canvas.addEventListener('mouseup',this._canvasMouseUpHandler=function(e){if(!(configs.active&&configs.pointerEnabled)){return;}var leftButtonUp=e.which===1;if(!leftButtonUp){return;}// Left mouse button up to possibly pick or double-pick pivotController.hidePivot();if(Math.abs(e.clientX-states.mouseDownClientX)>3||Math.abs(e.clientY-states.mouseDownClientY)>3){return;}var pickedSubs=cameraControl.hasSubs("picked");var pickedNothingSubs=cameraControl.hasSubs("pickedNothing");var pickedSurfaceSubs=cameraControl.hasSubs("pickedSurface");var doublePickedSubs=cameraControl.hasSubs("doublePicked");var doublePickedSurfaceSubs=cameraControl.hasSubs("doublePickedSurface");var doublePickedNothingSubs=cameraControl.hasSubs("doublePickedNothing");if(!configs.doublePickFlyTo&&!doublePickedSubs&&!doublePickedSurfaceSubs&&!doublePickedNothingSubs){// Avoid the single/double click differentiation timeout if(pickedSubs||pickedNothingSubs||pickedSurfaceSubs){pickController.pickCursorPos=states.pointerCanvasPos;pickController.schedulePickEntity=true;pickController.schedulePickSurface=pickedSurfaceSubs;pickController.update();if(pickController.pickResult){cameraControl.fire("picked",pickController.pickResult,true);if(pickController.pickedSurface){cameraControl.fire("pickedSurface",pickController.pickResult,true);}}else{cameraControl.fire("pickedNothing",{canvasPos:states.pointerCanvasPos},true);}}_this113._clicks=0;return;}_this113._clicks++;if(_this113._clicks===1){// First click -pickController.pickCursorPos=states.pointerCanvasPos;pickController.schedulePickEntity=configs.doublePickFlyTo;pickController.schedulePickSurface=pickedSurfaceSubs;pickController.update();var firstClickPickResult=pickController.pickResult;var firstClickPickSurface=pickController.pickedSurface;_this113._timeout=setTimeout(function(){if(firstClickPickResult){cameraControl.fire("picked",firstClickPickResult,true);if(firstClickPickSurface){cameraControl.fire("pickedSurface",firstClickPickResult,true);if(!configs.firstPerson&&configs.followPointer){controllers.pivotController.setPivotPos(firstClickPickResult.worldPos);if(controllers.pivotController.startPivot()){controllers.pivotController.showPivot();}}}}else{cameraControl.fire("pickedNothing",{canvasPos:states.pointerCanvasPos},true);}_this113._clicks=0;},configs.doubleClickTimeFrame);}else{// Second click +pickController.pickCursorPos=states.pointerCanvasPos;pickController.schedulePickEntity=configs.doublePickFlyTo;pickController.schedulePickSurface=pickedSurfaceSubs;pickController.update();var firstClickPickResult=pickController.pickResult;var firstClickPickSurface=pickController.pickedSurface;_this113._timeout=setTimeout(function(){if(firstClickPickResult&&firstClickPickResult.worldPos){cameraControl.fire("picked",firstClickPickResult,true);if(firstClickPickSurface){cameraControl.fire("pickedSurface",firstClickPickResult,true);if(!configs.firstPerson&&configs.followPointer){controllers.pivotController.setPivotPos(firstClickPickResult.worldPos);if(controllers.pivotController.startPivot()){controllers.pivotController.showPivot();}}}}else{cameraControl.fire("pickedNothing",{canvasPos:states.pointerCanvasPos},true);}_this113._clicks=0;},configs.doubleClickTimeFrame);}else{// Second click if(_this113._timeout!==null){window.clearTimeout(_this113._timeout);_this113._timeout=null;}pickController.pickCursorPos=states.pointerCanvasPos;pickController.schedulePickEntity=configs.doublePickFlyTo||doublePickedSubs||doublePickedSurfaceSubs;pickController.schedulePickSurface=pickController.schedulePickEntity&&doublePickedSurfaceSubs;pickController.update();if(pickController.pickResult){cameraControl.fire("doublePicked",pickController.pickResult,true);if(pickController.pickedSurface){cameraControl.fire("doublePickedSurface",pickController.pickResult,true);}if(configs.doublePickFlyTo){flyCameraTo(pickController.pickResult);if(!configs.firstPerson&&configs.followPointer){var pickedEntityAABB=pickController.pickResult.entity.aabb;var pickedEntityCenterPos=math.getAABB3Center(pickedEntityAABB);controllers.pivotController.setPivotPos(pickedEntityCenterPos);if(controllers.pivotController.startPivot()){controllers.pivotController.showPivot();}}}}else{cameraControl.fire("doublePickedNothing",{canvasPos:states.pointerCanvasPos},true);if(configs.doublePickFlyTo){flyCameraTo();if(!configs.firstPerson&&configs.followPointer){var sceneAABB=scene.aabb;var sceneCenterPos=math.getAABB3Center(sceneAABB);controllers.pivotController.setPivotPos(sceneCenterPos);if(controllers.pivotController.startPivot()){controllers.pivotController.showPivot();}}}}_this113._clicks=0;}},false);}_createClass(MousePickHandler,[{key:"reset",value:function reset(){this._clicks=0;this._lastPickedEntityId=null;if(this._timeout){window.clearTimeout(this._timeout);this._timeout=null;}}},{key:"destroy",value:function destroy(){var canvas=this._scene.canvas.canvas;canvas.removeEventListener("mousemove",this._canvasMouseMoveHandler);canvas.removeEventListener("mousedown",this._canvasMouseDownHandler);document.removeEventListener("mouseup",this._documentMouseUpHandler);canvas.removeEventListener("mouseup",this._canvasMouseUpHandler);if(this._timeout){window.clearTimeout(this._timeout);this._timeout=null;}}}]);return MousePickHandler;}();/** * @private */var KeyboardPanRotateDollyHandler=/*#__PURE__*/function(){function KeyboardPanRotateDollyHandler(scene,controllers,configs,states,updates){_classCallCheck(this,KeyboardPanRotateDollyHandler);this._scene=scene;var input=scene.input;var keyDownMap=[];var canvas=scene.canvas.canvas;var mouseMovedSinceLastKeyboardDolly=true;this._onSceneMouseMove=input.on("mousemove",function(){mouseMovedSinceLastKeyboardDolly=true;});this._onSceneKeyDown=input.on("keydown",function(keyCode){if(!(configs.active&&configs.pointerEnabled)||!scene.input.keyboardEnabled){return;}if(configs.keyboardEnabledOnlyIfMouseover&&!states.mouseover){return;}keyDownMap[keyCode]=true;if(keyCode===input.KEY_SHIFT){canvas.style.cursor="move";}});this._onSceneKeyUp=input.on("keyup",function(keyCode){if(!(configs.active&&configs.pointerEnabled)||!scene.input.keyboardEnabled){return;}keyDownMap[keyCode]=false;if(keyCode===input.KEY_SHIFT){canvas.style.cursor=null;}if(controllers.pivotController.getPivoting()){controllers.pivotController.endPivot();}});this._onTick=scene.on("tick",function(e){if(!(configs.active&&configs.pointerEnabled)||!scene.input.keyboardEnabled){return;}if(configs.keyboardEnabledOnlyIfMouseover&&!states.mouseover){return;}var cameraControl=controllers.cameraControl;var elapsedSecs=e.deltaTime/1000.0;//------------------------------------------------------------------------------------------------- diff --git a/dist/xeokit-sdk.min.cjs.js b/dist/xeokit-sdk.min.cjs.js index 5ef07d540..861aca4d7 100644 --- a/dist/xeokit-sdk.min.cjs.js +++ b/dist/xeokit-sdk.min.cjs.js @@ -14,7 +14,7 @@ /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT - **/let DA=null;function SA(e,t){const i=3*e,s=3*t;let r,o,n,a,l,A;const h=Math.min(r=DA[i],o=DA[i+1],n=DA[i+2]),c=Math.min(a=DA[s],l=DA[s+1],A=DA[s+2]);if(h!==c)return h-c;const u=Math.max(r,o,n),d=Math.max(a,l,A);return u!==d?u-d:0}let TA=null;function LA(e,t){let i=TA[2*e]-TA[2*t];return 0!==i?i:TA[2*e+1]-TA[2*t+1]}function RA(e,t,i=!1){const s=e.positionsCompressed||[],r=function(e,t){const i=new Int32Array(e.length/3);for(let e=0,t=i.length;e>t;i.sort(SA);const s=new Int32Array(e.length);for(let t=0,r=i.length;te[t+1]){let i=e[t];e[t]=e[t+1],e[t+1]=i}TA=new Int32Array(e),t.sort(LA);const i=new Int32Array(e.length);for(let s=0,r=t.length;st){let i=e;e=t,t=i}function i(i,s){return i!==e?e-i:s!==t?t-s:0}let s=0,r=(o.length>>1)-1;for(;s<=r;){const e=r+s>>1,t=i(o[2*e],o[2*e+1]);if(t>0)s=e+1;else{if(!(t<0))return e;r=e-1}}return-s-1}const a=new Int32Array(o.length/2);a.fill(0);const l=s.length/3;if(l>8*(1<u.maxNumPositions&&(u=c()),u.bucketNumber>8)return[e];let p;-1===A[l]&&(A[l]=u.numPositions++,u.positionsCompressed.push(s[3*l]),u.positionsCompressed.push(s[3*l+1]),u.positionsCompressed.push(s[3*l+2])),-1===A[h]&&(A[h]=u.numPositions++,u.positionsCompressed.push(s[3*h]),u.positionsCompressed.push(s[3*h+1]),u.positionsCompressed.push(s[3*h+2])),-1===A[d]&&(A[d]=u.numPositions++,u.positionsCompressed.push(s[3*d]),u.positionsCompressed.push(s[3*d+1]),u.positionsCompressed.push(s[3*d+2])),u.indices.push(A[l]),u.indices.push(A[h]),u.indices.push(A[d]),(p=n(l,h))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(l,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(h,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]]))}const d=t/8*2,p=t/8,f=2*s.length+(r.length+o.length)*d;let g=0,m=-s.length/3;return h.forEach((e=>{g+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*p,m+=e.positionsCompressed.length/3})),g>f?[e]:(i&&function(e,t){const i={},s={};let r=0;e.forEach((e=>{const t=e.indices,o=e.edgeIndices,n=e.positionsCompressed;for(let e=0,s=t.length;e0){const e=t._meshes;for(let t=0,i=e.length;t0){const e=this._meshes;for(let t=0,i=e.length;t{this._viewMatrixDirty=!0})),this._meshesWithDirtyMatrices=[],this._numMeshesWithDirtyMatrices=0,this._onTick=this.scene.on("tick",(()=>{for(;this._numMeshesWithDirtyMatrices>0;)this._meshesWithDirtyMatrices[--this._numMeshesWithDirtyMatrices]._updateMatrix()})),this._createDefaultTextureSet(),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.backfaces=t.backfaces}_meshMatrixDirty(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}_createDefaultTextureSet(){const e=new fA({id:"defaultColorTexture",texture:new Ps({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new fA({id:"defaultMetalRoughTexture",texture:new Ps({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),i=new fA({id:"defaultNormalsTexture",texture:new Ps({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),s=new fA({id:"defaultEmissiveTexture",texture:new Ps({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),r=new fA({id:"defaultOcclusionTexture",texture:new Ps({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=i,this._textures.defaultEmissiveTexture=s,this._textures.defaultOcclusionTexture=r,this._textureSets.defaultTextureSet=new pA({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:i,emissiveTexture:s,occlusionTexture:r})}get isPerformanceModel(){return!0}get transforms(){return this._transforms}get textures(){return this._textures}get textureSets(){return this._textureSets}get meshes(){return this._meshes}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),c.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),c.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||YA),c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),c.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),c.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),c.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),c.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0,this._aabbDirty=!0}_transformDirty(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}_sceneModelDirty(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(let e=0,t=this._entityList.length;e0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,i=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,i=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,i=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,i=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,i=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,i=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,i=new Uint8Array(t.length);for(let e=0,s=t.length;e{l.setImage(A,{minFilter:i,magFilter:s,wrapS:r,wrapT:o,wrapR:n,flipY:e.flipY,encoding:a}),this.glRedraw()},A.src=e.src;break;default:this._textureTranscoder?_.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new fA({id:t,texture:l})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let i,s,r,o,n;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(i=this._textures[e.colorTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(s=this._textures[e.metallicRoughnessTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(r=this._textures[e.normalsTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(o=this._textures[e.emissiveTextureId],!o)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else o=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(n=this._textures[e.occlusionTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultOcclusionTexture;const a=new pA({id:t,model:this,colorTexture:i,metallicRoughnessTexture:s,normalsTexture:r,emissiveTexture:o,occlusionTexture:n});return this._textureSets[t]=a,a}createTransform(e){if(void 0===e.id||null===e.id)return void this.error("[createTransform] SceneModel.createTransform() config missing: id");if(this._transforms[e.id])return void this.error(`[createTransform] SceneModel already has a transform with this ID: ${e.id}`);let t;if(e.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const i=new jA({id:e.id,model:this,parent:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[i.id]=i,i}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._meshes[e.id])return this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`),!1;if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!(e.buckets||e.indices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)){const t=(e.positions||e.positionsCompressed).length/3;e.indices=this._createDefaultIndices(t)}if(!e.buckets&&!e.indices&&"points"!==e.primitive)return e.indices=this._createDefaultIndices(numIndices),this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;const t=!(!this._dtxEnabled||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||e.textureSetId);if(e.origin=e.origin?c.addVec3(this._origin,e.origin,c.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position||e.quaternion){const t=e.scale||KA,i=e.position||XA;e.rotation?(c.eulerToQuaternion(e.rotation,"XYZ",WA),e.meshMatrix=c.composeMat4(i,WA,t,c.mat4())):e.meshMatrix=c.composeMat4(i,e.quaternion||JA,t,c.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Vr(e.positionsDecodeBoundary,c.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):ZA,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=c.vec3(),i=[];K(e.positions,i,t)&&(e.positions=i,e.origin=c.addVec3(e.origin,t,t))}if(e.positions){const t=c.collapseAABB3();e.positionsDecodeMatrix=c.mat4(),c.expandAABB3Points3(t,e.positions),e.positionsCompressed=Qr(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=c.collapseAABB3();c.expandAABB3Points3(t,e.positionsCompressed),Qt.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=c.collapseAABB3();for(let i=0,s=e.buckets.length;i>24&255,r=i>>16&255,o=i>>8&255,n=255&i;switch(e.pickColor=new Uint8Array([n,o,r,s]),e.solid="solid"===e.primitive,t.origin=c.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),this._meshes[e.id]=t,this._unusedMeshes[e.id]=t,this._meshList.push(t),t}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let i=0,s=e.buckets.length;i>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,i=e.origin,s=e.textureSetId||"-",r=e.geometryId,o=`${Math.round(i[0])}.${Math.round(i[1])}.${Math.round(i[2])}.${s}.${r}`;let n=this._vboInstancingLayers[o];if(n)return n;let a=e.textureSet;const l=e.geometry;for(;!n;)switch(l.primitive){case"triangles":case"surface":n=new Wo({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!1});break;case"solid":n=new Wo({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!0});break;case"lines":n=new Sn({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0});break;case"points":n=new Pa({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0})}return this._vboInstancingLayers[o]=n,this.layerList.push(n),n}createEntity(e){if(void 0===e.id?e.id=c.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=c.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;this._visible&&!1!==e.visible&&(t|=J),this._pickable&&!1!==e.pickable&&(t|=Z),this._culled&&!1!==e.culled&&(t|=Y),this._clippable&&!1!==e.clippable&&(t|=q),this._collidable&&!1!==e.collidable&&(t|=$),this._edges&&!1!==e.edges&&(t|=se),this._xrayed&&!1!==e.xrayed&&(t|=ee),this._highlighted&&!1!==e.highlighted&&(t|=te),this._selected&&!1!==e.selected&&(t|=ie),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let i=0,s=e.meshIds.length;ie.sortIdt.sortId?1:0));for(let e=0,t=this.layerList.length;e0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,i=this.layerList.length;t0){const t=`${this.id}-dummyEntityForUnusedMeshes`;this.warn(`Creating dummy SceneModelEntity "${t}" for unused SceneMeshes: [${e.join(",")}]`),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}_getActiveSectionPlanesForLayer(e){const t=this.renderFlags,i=this.scene._sectionPlanesState.sectionPlanes,s=i.length,r=e.layerIndex*s;if(s>0)for(let e=0;e0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}drawColorOpaque(e,t){const i=this.renderFlags;for(let t=0,s=i.visibleLayers.length;t65536?16:8)}else n=[{positionsCompressed:s,indices:r,edgeIndices:o}];return n}class eh extends D{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e{var r=e-i,o=t-s;return Math.sqrt(r*r+o*o)};class ch extends D{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._eventSubs={};var i=this.plugin.viewer.scene;this._originWorld=c.vec3(),this._targetWorld=c.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;const s=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,r=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},n=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,A=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new ue(i,t.origin,this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._targetDot=new ue(i,t.target,this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthWire=new fe(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisWire=new fe(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisWire=new fe(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisWire=new fe(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthLabel=new ge(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisLabel=new ge(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisLabel=new ge(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisLabel=new ge(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._measurementOrientation="Horizontal",this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._sectionPlanesDirty=!0,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,this._xLabelEnabled=!1,this._yLabelEnabled=!1,this._zLabelEnabled=!1,this._lengthLabelEnabled=!1,this._labelsVisible=!1,this._labelsOnWires=!1,this._clickable=!1,this._originDot.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetDot.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=i.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=i.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=i.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=i.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=i.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=i.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=i.on("sectionPlaneUpdated",(()=>{this._sectionPlanesDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.xLabelEnabled=t.xLabelEnabled,this.yLabelEnabled=t.yLabelEnabled,this.zLabelEnabled=t.zLabelEnabled,this.lengthLabelEnabled=t.lengthLabelEnabled,this.labelsVisible=t.labelsVisible,this.labelsOnWires=t.labelsOnWires,this.useRotationAdjustment=t.useRotationAdjustment}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._measurementOrientation=function(e,t,i){return Math.abs(t[1]-e[1])>i?"Vertical":"Horizontal"}(this._originWorld,this._targetWorld,0),"Vertical"===this._measurementOrientation&&this.useRotationAdjustment?(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._originWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._originWorld[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._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1),this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(c.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._originWorld)||this._isSliced(this._targetWorld))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}const t=this._originDot.viewPos[2],i=this._targetDot.viewPos[2];if(t>-.3||i>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){c.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var s=this._pp,r=this._cp,o=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var n=o.top-t.top,a=o.left-t.left,l=e.canvas.boundary,A=l[2],h=l[3],u=0;const i=this.plugin.viewer.scene.metrics,f=i.scale,g=i.units,m=i.unitsInfo[g].abbrev;for(var d=0,p=s.length;de.offsetTop+(e.offsetParent&&e.offsetParent!==s.parentNode&&h(e.offsetParent)),u=e=>e.offsetLeft+(e.offsetParent&&e.offsetParent!==s.parentNode&&u(e.offsetParent)),d=c.vec2();this._onCameraControlHoverSnapOrSurface=i.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(e=>{const t=e.snappedCanvasPos||e.canvasPos;r=!0,o.set(e.worldPos),n.set(e.canvasPos),0===this._mouseState?(this._canvasToPagePos?(this._canvasToPagePos(s,t,d),this._markerDiv.style.left=d[0]-5+"px",this._markerDiv.style.top=d[1]-5+"px"):(this._markerDiv.style.left=u(s)+t[0]-5+"px",this._markerDiv.style.top=h(s)+t[1]-5+"px"),this._markerDiv.style.background="pink",e.snappedToVertex||e.snappedToEdge?(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos,this.pointerLens.snapped=!0),this._markerDiv.style.background="greenyellow",this._markerDiv.style.border="2px solid green"):(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.canvasPos,this.pointerLens.snapped=!1),this._markerDiv.style.background="pink",this._markerDiv.style.border="2px solid red"),A=e.entity):(this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px"),s.style.cursor="pointer",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=this._currentDistanceMeasurementInitState.wireVisible,this._currentDistanceMeasurement.axisVisible=this._currentDistanceMeasurementInitState.axisVisible&&this.distanceMeasurementsPlugin.defaultAxisVisible,this._currentDistanceMeasurement.xAxisVisible=this._currentDistanceMeasurementInitState.xAxisVisible&&this.distanceMeasurementsPlugin.defaultXAxisVisible,this._currentDistanceMeasurement.yAxisVisible=this._currentDistanceMeasurementInitState.yAxisVisible&&this.distanceMeasurementsPlugin.defaultYAxisVisible,this._currentDistanceMeasurement.zAxisVisible=this._currentDistanceMeasurementInitState.zAxisVisible&&this.distanceMeasurementsPlugin.defaultZAxisVisible,this._currentDistanceMeasurement.targetVisible=this._currentDistanceMeasurementInitState.targetVisible,this._currentDistanceMeasurement.target.worldPos=o.slice(),this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px")})),s.addEventListener("mousedown",this._onMouseDown=e=>{1===e.which&&(a=e.clientX,l=e.clientY)}),s.addEventListener("mouseup",this._onMouseUp=t=>{1===t.which&&(t.clientX>a+20||t.clientXl+20||t.clientY{this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos),r=!1,this._markerDiv.style.left="-100px",this._markerDiv.style.top="-100px",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.axisVisible=!1),s.style.cursor="default"})),this._active=!0}deactivate(){if(!this._active)return;this.fire("activated",!1),this.pointerLens&&(this.pointerLens.visible=!1);const e=this.scene.canvas.canvas;e.removeEventListener("mousedown",this._onMouseDown),e.removeEventListener("mouseup",this._onMouseUp);const t=this.distanceMeasurementsPlugin.viewer.cameraControl;t.off(this._onCameraControlHoverSnapOrSurface),t.off(this._onCameraControlHoverSnapOrSurfaceOff),this._active=!1}reset(){this._active&&(this._destroyMarkerDiv(),this._initMarkerDiv(),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null),this._mouseState=0)}get currentMeasurement(){return this._currentDistanceMeasurement}destroy(){this.deactivate(),super.destroy()}}class ph extends D{constructor(e,t,i,s){const r=e.plugin.viewer;super(r.scene);const o=pe({viewer:r,handleMouseEvents:i,handleTouchEvents:s,pointerLens:t.pointerLens,dots:[e.origin,e.target],ray2WorldPos:(e,i,s)=>{const o=e=>{const t=r.scene.pick({canvasPos:s,snapToEdge:e,snapToVertex:e,pickSurface:!0});return t&&t.worldPos?t.worldPos:e&&o(!1)};return o(!!t.snapping)},onEnd:(e,t)=>{const i=!c.compareVec3(e,t.worldPos);return i&&this.fire("edited"),i}}),n=e.on("destroyed",o);this._deactivate=function(){e.off("destroyed",n),o()}}deactivate(){this._deactivate(),super.destroy()}}class fh{constructor(e={}){this.cacheBuster=!1!==e.cacheBuster}_cacheBusterURL(e){if(!this.cacheBuster)return e;const t=(new Date).getTime();return e.indexOf("?")>-1?e+"&_="+t:e+"?_="+t}getMetaModel(e,t,i){_.loadJSON(this._cacheBusterURL(e),(e=>{t(e)}),(function(e){i(e)}))}getGLTF(e,t,i){_.loadArraybuffer(this._cacheBusterURL(e),(e=>{t(e)}),(function(e){i(e)}))}getGLB(e,t,i){_.loadArraybuffer(this._cacheBusterURL(e),(e=>{t(e)}),(function(e){i(e)}))}getArrayBuffer(e,t,i,s){!function(e,t,i,s){var r=()=>{};i=i||r,s=s||r;const o=/^data:(.*?)(;base64)?,(.*)$/,n=t.match(o);if(n){const e=!!n[2];var a=n[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),t=new Uint8Array(e);for(var l=0;l{i(e)}),(function(e){s(e)}))}}class gh{constructor(e={}){this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=e.messages,this.locale=e.locale}set messages(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}loadMessages(e={}){for(let t in e)this._messages[t]=e[t];this.messages=this._messages}clearMessages(){this.messages={}}get locales(){return this._locales}set locale(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}get locale(){return this._locale}translate(e,t){const i=this._messages[this._locale];if(!i)return null;const s=mh(e,i);return s?t?_h(s,t):s:null}translatePlurals(e,t,i){const s=this._messages[this._locale];if(!s)return null;let r=mh(e,s);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=_h(r,[t]),i&&(r=_h(r,i)),r):null}fire(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);const s=this._eventSubs[e];if(s)for(const e in s)if(s.hasOwnProperty(e)){s[e].callback(t)}}on(t,i){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let s=this._eventSubs[t];s||(s={},this._eventSubs[t]=s);const r=this._eventSubIDMap.addItem();s[r]={callback:i},this._eventSubEvents[r]=t;const o=this._events[t];return void 0!==o&&i(o),r}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}function mh(e,t){if(t[e])return t[e];const i=e.split(".");let s=t;for(let e=0,t=i.length;s&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,s=e+t;i<0&&(i=0),s>1&&(s=1);var r=this.getPoint(i),o=this.getPoint(s),n=c.subVec3(o,r,[]);return c.normalizeVec3(n,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,s=[],r=this.getPoint(0),o=0;for(s.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),o+=c.lenVec3(c.subVec3(t,r,[])),s.push(o),r=t;return this.cacheArcLengths=s,s}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var i,s=this._getLengths(),r=0,o=s.length;i=t||e*s[o-1];for(var n,a=0,l=o-1;a<=l;)if((n=s[r=Math.floor(a+(l-a)/2)]-i)<0)a=r+1;else{if(!(n>0)){l=r;break}l=r-1}if(s[r=l]===i)return r/(o-1);var A=s[r];return(r+(i-A)/(s[r+1]-A))/(o-1)}}class bh extends vh{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,s=Math.floor(i),r=i-s,o=t[0===s?s:s-1],n=t[s],a=t[s>t.length-2?t.length-1:s+1],l=t[s>t.length-3?t.length-1:s+2],A=c.vec3();return A[0]=c.catmullRomInterpolate(o[0],n[0],a[0],l[0],r),A[1]=c.catmullRomInterpolate(o[1],n[1],a[1],l[1],r),A[2]=c.catmullRomInterpolate(o[2],n[2],a[2],l[2],r),A}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const yh=c.vec3();const xh=c.vec3(),Bh=c.vec3(),wh=c.vec3(),Ph=c.vec3(),Ch=c.vec3();class Mh extends D{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=c.vec3(),this._eye1=c.vec3(),this._up1=c.vec3(),this._look2=c.vec3(),this._eye2=c.vec3(),this._up2=c.vec3(),this._orthoScale1=1,this._orthoScale2=1,this._flying=!1,this._flyEyeLookUp=!1,this._flyingEye=!1,this._flyingLook=!1,this._callback=null,this._callbackScope=null,this._time1=null,this._time2=null,this.easing=!1!==t.easing,this.duration=t.duration,this.fit=t.fit,this.fitFOV=t.fitFOV,this.trail=t.trail}flyTo(e,t,i){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=i;const s=this.scene.camera,r=!!e.projection&&e.projection!==s.projection;let o,n,a,l,A;if(this._eye1[0]=s.eye[0],this._eye1[1]=s.eye[1],this._eye1[2]=s.eye[2],this._look1[0]=s.look[0],this._look1[1]=s.look[1],this._look1[2]=s.look[2],this._up1[0]=s.up[0],this._up1[1]=s.up[1],this._up1[2]=s.up[2],this._orthoScale1=s.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)o=e.aabb;else if(6===e.length)o=e;else if(e.eye&&e.look||e.up)n=e.eye,a=e.look,l=e.up;else if(e.eye)n=e.eye;else if(e.look)a=e.look;else{let s=e;if((_.isNumeric(s)||_.isString(s))&&(A=s,s=this.scene.components[A],!s))return this.error("Component not found: "+_.inQuotes(A)),void(t&&(i?t.call(i):t()));r||(o=s.aabb||this.scene.aabb)}const h=e.poi;if(o){if(o[3]=1;e>1&&(e=1);const i=this.easing?Mh._ease(e,0,1,1):e,s=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(c.subVec3(s.eye,s.look,Ch),s.eye=c.lerpVec3(i,0,1,this._eye1,this._eye2,wh),s.look=c.subVec3(wh,Ch,Bh)):this._flyingLook&&(s.look=c.lerpVec3(i,0,1,this._look1,this._look2,Bh),s.up=c.lerpVec3(i,0,1,this._up1,this._up2,Ph)):this._flyingEyeLookUp&&(s.eye=c.lerpVec3(i,0,1,this._eye1,this._eye2,wh),s.look=c.lerpVec3(i,0,1,this._look1,this._look2,Bh),s.up=c.lerpVec3(i,0,1,this._up1,this._up2,Ph)),this._projection2){const t="ortho"===this._projection2?Mh._easeOutExpo(e,0,1,1):Mh._easeInCubic(e,0,1,1);s.customProjection.matrix=c.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else s.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return s.ortho.scale=this._orthoScale2,void this.stop();M.scheduleTask(this._update,this)}static _ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}static _easeInCubic(e,t,i,s){return i*(e/=s)*e*e+t}static _easeOutExpo(e,t,i,s){return i*(1-Math.pow(2,-10*e/s))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class Eh extends D{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new Mh(this),this._t=0,this.state=Eh.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,i;const s=performance.now(),r=this._lastTime?.001*(s-this._lastTime):0;if(this._lastTime=s,0!==r)switch(this.state){case Eh.SCRUBBING:return;case Eh.PLAYING:if(this._t+=this._playingRate*r,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=Eh.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case Eh.PLAYING_TO:i=this._t+this._playingRate*r*this._playingDir,(this._playingDir<0&&i<=this._playingToT||this._playingDir>0&&i>=this._playingToT)&&(i=this._playingToT,this.state=Eh.SCRUBBING,this.fire("stopped")),this._t=i,e.loadFrame(this._t)}}_ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=Eh.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=Eh.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const i=this._cameraPath;if(!i)return;const s=i.frames[e];s?(this.state=Eh.SCRUBBING,this._cameraFlightAnimation.flyTo(s,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=Eh.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=Eh.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=Eh.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}Eh.STOPPED=0,Eh.SCRUBBING=1,Eh.PLAYING=2,Eh.PLAYING_TO=3;const Fh=c.vec3(),Ih=c.vec3();c.vec3();const Dh=c.vec3([0,-1,0]),Sh=c.vec4([0,0,0,1]);function Th(e){if(!Lh(e.width)||!Lh(e.height)){const t=document.createElement("canvas");t.width=Rh(e.width),t.height=Rh(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Lh(e){return 0==(e&e-1)}function Rh(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Uh extends D{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const i=this.scene.canvas.gl;this._state=new at({texture:new Ps({gl:i,target:i.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),p.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,i=this.scene.canvas.gl;this._images=[];let s=!1,r=0;for(let o=0;o{r(),t()})):(i.eye=this._eye,i.look=this._look,i.up=this._up,r(),i.projection=s.projection)}}const Oh=c.vec3();const Nh=c.vec3();class Qh{constructor(){this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}saveObjects(e,t){this.numObjects=0,this._mask=t?_.apply(t,{}):null;const i=e.objects,s=!t||t.visible,r=!t||t.edges,o=!t||t.xrayed,n=!t||t.highlighted,a=!t||t.selected,l=!t||t.clippable,A=!t||t.pickable,h=!t||t.colorize,c=!t||t.opacity;for(let e in i)if(i.hasOwnProperty(e)){const t=i[e],u=this.numObjects;if(s&&(this.objectsVisible[u]=t.visible),r&&(this.objectsEdges[u]=t.edges),o&&(this.objectsXrayed[u]=t.xrayed),n&&(this.objectsHighlighted[u]=t.highlighted),a&&(this.objectsSelected[u]=t.selected),l&&(this.objectsClippable[u]=t.clippable),A&&(this.objectsPickable[u]=t.pickable),h){const e=t.colorize;e?(this.objectsColorize[3*u+0]=e[0],this.objectsColorize[3*u+1]=e[1],this.objectsColorize[3*u+2]=e[2],this.objectsHasColorize[u]=!0):this.objectsHasColorize[u]=!1}c&&(this.objectsOpacity[u]=t.opacity),this.numObjects++}}restoreObjects(e){const t=this._mask,i=!t||t.visible,s=!t||t.edges,r=!t||t.xrayed,o=!t||t.highlighted,n=!t||t.selected,a=!t||t.clippable,l=!t||t.pickable,A=!t||t.colorize,h=!t||t.opacity;var c=0;const u=e.objects;for(let e in u)if(u.hasOwnProperty(e)){const t=u[e];i&&(t.visible=this.objectsVisible[c]),s&&(t.edges=this.objectsEdges[c]),r&&(t.xrayed=this.objectsXrayed[c]),o&&(t.highlighted=this.objectsHighlighted[c]),n&&(t.selected=this.objectsSelected[c]),a&&(t.clippable=this.objectsClippable[c]),l&&(t.pickable=this.objectsPickable[c]),A&&(this.objectsHasColorize[c]?(Nh[0]=this.objectsColorize[3*c+0],Nh[1]=this.objectsColorize[3*c+1],Nh[2]=this.objectsColorize[3*c+2],t.colorize=Nh):t.colorize=null),h&&(t.opacity=this.objectsOpacity[c]),c++}}}class Vh extends D{constructor(e,t={}){super(e,t),this._skyboxMesh=new $i(this,{geometry:new jt(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new Xt(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Ds(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}const Hh=c.vec4(),jh=c.vec4(),Gh=c.vec3(),zh=c.vec3(),Wh=c.vec3(),Kh=c.vec4(),Xh=c.vec4(),Jh=c.vec4();class Yh{constructor(e){this._scene=e}dollyToCanvasPos(e,t,i){let s=!1;const r=this._scene.camera;if(e){const t=c.subVec3(e,r.eye,Gh);s=c.lenVec3(t){this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=c.vec3();c.decomposeMat4(c.inverseMat4(this._scene.viewer.camera.viewMatrix,c.mat4()),t,c.vec4(),c.vec3());const i=c.distVec3(t,e);let s=Math.tan(Math.PI/500)*i*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(s/=this._scene.camera.ortho.scale/2),W(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Ls(this._scene,is({radius:s})),this._pivotSphere=new $i(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){c.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,c.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const i=t.boundary,s=i[2],r=i[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*s/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*r/2);let o=t._lastBoundingClientRect;if(!o||t._canvasSizeChanged){const e=t.canvas;o=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(o.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(o.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(W(this.getPivotPos(),this._rtcCenter,this._rtcPos),c.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new Xt(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=c.lookAtMat4v(e.eye,e.look,e.worldUp);c.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const i=this.getPivotPos();this._cameraOffset[2]+=c.distVec3(e.eye,i),t=c.inverseMat4(t);const s=c.transformVec3(t,this._cameraOffset),r=c.vec3();if(c.subVec3(e.eye,i,r),c.addVec3(r,s),e.zUp){const e=r[1];r[1]=r[2],r[2]=e}this._radius=c.lenVec3(r),this._polar=Math.acos(r[1]/this._radius),this._azimuth=Math.atan2(r[0],r[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=c.normalizeVec3(c.subVec3(e.look,e.eye,Zh)),i=c.cross3Vec3(t,e.worldUp,qh);return c.sqLenVec3(i)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,i=Math.abs(c.distVec3(this._scene.center,t.eye)),s=t.project.transposedMatrix,r=s.subarray(8,12),o=s.subarray(12),n=[0,0,-1,1],a=c.dotVec4(n,r)/c.dotVec4(n,o),l=ec;t.project.unproject(e,a,tc,ic,l);const A=c.normalizeVec3(c.subVec3(l,t.eye,Zh)),h=c.addVec3(t.eye,c.mulVec3Scalar(A,i,qh),$h);this.setPivotPos(h)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const i=this._scene.camera;var s=-e;const r=-t;1===i.worldUp[2]&&(s=-s),this._azimuth+=.01*-s,this._polar+=.01*r,this._polar=c.clamp(this._polar,.001,Math.PI-.001);const o=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===i.worldUp[2]){const e=o[1];o[1]=o[2],o[2]=e}const n=c.lenVec3(c.subVec3(i.look,i.eye,c.vec3())),a=this.getPivotPos();c.addVec3(o,a);let l=c.lookAtMat4v(o,a,i.worldUp);l=c.inverseMat4(l);const A=c.transformVec3(l,this._cameraOffset);l[12]-=A[0],l[13]-=A[1],l[14]-=A[2];const h=[l[8],l[9],l[10]];i.eye=[l[12],l[13],l[14]],c.subVec3(i.eye,c.mulVec3Scalar(h,n),i.look),i.up=[l[4],l[5],l[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class rc{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=c.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;const e=`${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;if(this._lastHash===e)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;const t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&(e.snappedToEdge||e.snappedToVertex)?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const e=this.pickResult.canvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new Te;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}const oc=c.vec2();class nc{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController;let n,a,l,A=0,h=0,u=0,d=0,p=!1;const f=c.vec3();let g=!0;const m=this._scene.canvas.canvas,_=[];function v(e=!0){m.style.cursor="move",A=s.pointerCanvasPos[0],h=s.pointerCanvasPos[1],u=s.pointerCanvasPos[0],d=s.pointerCanvasPos[1],e&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(p=!0,f.set(o.pickResult.worldPos)):p=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(i.active&&i.pointerEnabled)switch(t.which){case 1:_[e.input.KEY_SHIFT]||i.planView?(n=!0,v()):(n=!0,v(!1));break;case 2:a=!0,v();break;case 3:l=!0,i.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(!n&&!a&&!l)return;const o=e.canvas.boundary,u=o[2],d=o[3],g=s.pointerCanvasPos[0],m=s.pointerCanvasPos[1],v=_[e.input.KEY_SHIFT]||i.planView||!i.panRightClick&&a||i.panRightClick&&l,b=document.pointerLockElement?t.movementX:g-A,y=document.pointerLockElement?t.movementY:m-h;if(v){const t=e.camera;if("perspective"===t.projection){const i=Math.abs(p?c.lenVec3(c.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(t.perspective.fov/2*Math.PI/180);r.panDeltaX+=1.5*b*i/d,r.panDeltaY+=1.5*y*i/d}else r.panDeltaX+=.5*t.ortho.scale*(b/d),r.panDeltaY+=.5*t.ortho.scale*(y/d)}else!n||a||l||i.planView||(i.firstPerson?(r.rotateDeltaY-=b/u*i.dragRotationRate/2,r.rotateDeltaX+=y/d*(i.dragRotationRate/4)):(r.rotateDeltaY-=b/u*(1.5*i.dragRotationRate),r.rotateDeltaX+=y/d*(1.5*i.dragRotationRate)));A=g,h=m}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{i.active&&i.pointerEnabled&&s.mouseover&&(g=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(i.active&&i.pointerEnabled)switch(e.which){case 1:case 2:case 3:n=!1,a=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(i.active&&i.pointerEnabled){if(3===e.which){!function(e,t){if(e){let i=e.target,s=0,r=0,o=0,n=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,o+=i.scrollLeft,n+=i.scrollTop,i=i.offsetParent;t[0]=e.pageX+o-s,t[1]=e.pageY+n-r}else e=window.event,t[0]=e.x,t[1]=e.y}(e,oc);const i=oc[0],s=oc[1];Math.abs(i-u)<3&&Math.abs(s-d)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:oc,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{i.active&&i.pointerEnabled});const b=1/60;let y=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!i.active||!i.pointerEnabled)return;const t=performance.now()/1e3;var o=null!==y?t-y:0;y=t,o>.05&&(o=.05),o{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(i.keyboardEnabledOnlyIfMouseover&&!s.mouseover)return;const n=r._isKeyDownForAction(r.AXIS_VIEW_RIGHT),a=r._isKeyDownForAction(r.AXIS_VIEW_BACK),l=r._isKeyDownForAction(r.AXIS_VIEW_LEFT),A=r._isKeyDownForAction(r.AXIS_VIEW_FRONT),h=r._isKeyDownForAction(r.AXIS_VIEW_TOP),u=r._isKeyDownForAction(r.AXIS_VIEW_BOTTOM);if(!(n||a||l||A||h||u))return;const d=e.aabb,p=c.getAABB3Diag(d);c.getAABB3Center(d,ac);const f=Math.abs(p/Math.tan(t.cameraFlight.fitFOV*c.DEGTORAD)),g=1.1*p;uc.orthoScale=g,n?(uc.eye.set(c.addVec3(ac,c.mulVec3Scalar(o.worldRight,f,lc),cc)),uc.look.set(ac),uc.up.set(o.worldUp)):a?(uc.eye.set(c.addVec3(ac,c.mulVec3Scalar(o.worldForward,f,lc),cc)),uc.look.set(ac),uc.up.set(o.worldUp)):l?(uc.eye.set(c.addVec3(ac,c.mulVec3Scalar(o.worldRight,-f,lc),cc)),uc.look.set(ac),uc.up.set(o.worldUp)):A?(uc.eye.set(c.addVec3(ac,c.mulVec3Scalar(o.worldForward,-f,lc),cc)),uc.look.set(ac),uc.up.set(o.worldUp)):h?(uc.eye.set(c.addVec3(ac,c.mulVec3Scalar(o.worldUp,f,lc),cc)),uc.look.set(ac),uc.up.set(c.normalizeVec3(c.mulVec3Scalar(o.worldForward,1,Ac),hc))):u&&(uc.eye.set(c.addVec3(ac,c.mulVec3Scalar(o.worldUp,-f,lc),cc)),uc.look.set(ac),uc.up.set(c.normalizeVec3(c.mulVec3Scalar(o.worldForward,-1,Ac)))),!i.firstPerson&&i.followPointer&&t.pivotController.setPivotPos(ac),t.cameraFlight.duration>0?t.cameraFlight.flyTo(uc,(()=>{t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(uc),t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class pc{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,A=!1;const h=this._scene.canvas.canvas,u=i=>{let s;i&&i.worldPos&&(s=i.worldPos);const r=i&&i.entity?i.entity.aabb:e.aabb;if(s){const i=e.camera;c.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})},d=e.tickify(this._canvasMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(l||A)return;if(a.hasSubs("rayMove")){const t=c.vec3(),i=c.vec3();c.canvasPosToWorldRay(e.canvas.canvas,e.camera.viewMatrix,e.camera.projMatrix,e.camera.projection,s.pointerCanvasPos,t,i),a.fire("rayMove",{canvasPos:s.pointerCanvasPos,ray:{origin:t,direction:i,canvasPos:s.pointerCanvasPos}},!0)}const r=a.hasSubs("hover"),n=a.hasSubs("hoverEnter"),h=a.hasSubs("hoverOut"),u=a.hasSubs("hoverOff"),d=a.hasSubs("hoverSurface"),p=a.hasSubs("hoverSnapOrSurface");if(r||n||h||u||d||p)if(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=d,o.scheduleSnapOrPick=p,o.update(),o.pickResult){if(o.pickResult.entity){const t=o.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),a.fire("hoverEnter",o.pickResult,!0),this._lastPickedEntityId=t)}a.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&a.fire("hoverSurface",o.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),a.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)});h.addEventListener("mousemove",d),h.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(A=!0);if(1===t.which&&i.active&&i.pointerEnabled&&(s.mouseDownClientX=t.clientX,s.mouseDownClientY=t.clientY,s.mouseDownCursorX=s.pointerCanvasPos[0],s.mouseDownCursorY=s.pointerCanvasPos[1],!i.firstPerson&&i.followPointer&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===t.which))){const t=o.pickResult;t&&t.worldPos?(n.setPivotPos(t.worldPos),n.startPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),n.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(A=!1),n.getPivoting()&&n.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=r=>{if(!i.active||!i.pointerEnabled)return;if(!(1===r.which))return;if(n.hidePivot(),Math.abs(r.clientX-s.mouseDownClientX)>3||Math.abs(r.clientY-s.mouseDownClientY)>3)return;const l=a.hasSubs("picked"),A=a.hasSubs("pickedNothing"),h=a.hasSubs("pickedSurface"),d=a.hasSubs("doublePicked"),p=a.hasSubs("doublePickedSurface"),f=a.hasSubs("doublePickedNothing");if(!(i.doublePickFlyTo||d||p||f))return(l||A||h)&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=h,o.update(),o.pickResult?(a.fire("picked",o.pickResult,!0),o.pickedSurface&&a.fire("pickedSurface",o.pickResult,!0)):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo,o.schedulePickSurface=h,o.update();const e=o.pickResult,r=o.pickedSurface;this._timeout=setTimeout((()=>{e?(a.fire("picked",e,!0),r&&(a.fire("pickedSurface",e,!0),!i.firstPerson&&i.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0),this._clicks=0}),i.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo||d||p,o.schedulePickSurface=o.schedulePickEntity&&p,o.update(),o.pickResult){if(a.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&a.fire("doublePickedSurface",o.pickResult,!0),i.doublePickFlyTo&&(u(o.pickResult),!i.firstPerson&&i.followPointer)){const e=o.pickResult.entity.aabb,i=c.getAABB3Center(e);t.pivotController.setPivotPos(i),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(a.fire("doublePickedNothing",{canvasPos:s.pointerCanvasPos},!0),i.doublePickFlyTo&&(u(),!i.firstPerson&&i.followPointer)){const i=e.aabb,s=c.getAABB3Center(i);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class fc{constructor(e,t,i,s,r){this._scene=e;const o=e.input,n=[],a=e.canvas.canvas;let l=!0;this._onSceneMouseMove=o.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=o.on("keydown",(t=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&(i.keyboardEnabledOnlyIfMouseover&&!s.mouseover||(n[t]=!0,t===o.KEY_SHIFT&&(a.style.cursor="move")))})),this._onSceneKeyUp=o.on("keyup",(s=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&(n[s]=!1,s===o.KEY_SHIFT&&(a.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(a=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(i.keyboardEnabledOnlyIfMouseover&&!s.mouseover)return;const A=t.cameraControl,h=a.deltaTime/1e3;if(!i.planView){const e=A._isKeyDownForAction(A.ROTATE_Y_POS,n),s=A._isKeyDownForAction(A.ROTATE_Y_NEG,n),o=A._isKeyDownForAction(A.ROTATE_X_POS,n),a=A._isKeyDownForAction(A.ROTATE_X_NEG,n),l=h*i.keyboardRotationRate;(e||s||o||a)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),e?r.rotateDeltaY+=l:s&&(r.rotateDeltaY-=l),o?r.rotateDeltaX+=l:a&&(r.rotateDeltaX-=l),!i.firstPerson&&i.followPointer&&t.pivotController.startPivot())}if(!n[o.KEY_CTRL]&&!n[o.KEY_ALT]){const e=A._isKeyDownForAction(A.DOLLY_BACKWARDS,n),o=A._isKeyDownForAction(A.DOLLY_FORWARDS,n);if(e||o){const n=h*i.keyboardDollyRate;!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),o?r.dollyDelta-=n:e&&(r.dollyDelta+=n),l&&(s.followPointerDirty=!0,l=!1)}}const c=A._isKeyDownForAction(A.PAN_FORWARDS,n),u=A._isKeyDownForAction(A.PAN_BACKWARDS,n),d=A._isKeyDownForAction(A.PAN_LEFT,n),p=A._isKeyDownForAction(A.PAN_RIGHT,n),f=A._isKeyDownForAction(A.PAN_UP,n),g=A._isKeyDownForAction(A.PAN_DOWN,n),m=(n[o.KEY_ALT]?.3:1)*h*i.keyboardPanRate;(c||u||d||p||f||g)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),g?r.panDeltaY+=m:f&&(r.panDeltaY+=-m),p?r.panDeltaX+=-m:d&&(r.panDeltaX+=m),u?r.panDeltaZ+=m:c&&(r.panDeltaZ+=-m))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const gc=c.vec3();class mc{constructor(e,t,i,s,r){this._scene=e;const o=e.camera,n=t.pickController,a=t.pivotController,l=t.panController;let A=1,h=1,u=null;this._onTick=e.on("tick",(()=>{if(!i.active||!i.pointerEnabled)return;let t="default";if(Math.abs(r.dollyDelta)<.001&&(r.dollyDelta=0),Math.abs(r.rotateDeltaX)<.001&&(r.rotateDeltaX=0),Math.abs(r.rotateDeltaY)<.001&&(r.rotateDeltaY=0),0===r.rotateDeltaX&&0===r.rotateDeltaY||(r.dollyDelta=0),i.followPointer){if(--A<=0&&(A=1,0!==r.dollyDelta)){if(0===r.rotateDeltaY&&0===r.rotateDeltaX&&i.followPointer&&s.followPointerDirty&&(n.pickCursorPos=s.pointerCanvasPos,n.schedulePickSurface=!0,n.update(),n.pickResult&&n.pickResult.worldPos?u=n.pickResult.worldPos:(h=1,u=null),s.followPointerDirty=!1),u){const t=Math.abs(c.lenVec3(c.subVec3(u,e.camera.eye,gc)));h=t/i.dollyProximityThreshold}h{s.mouseover=!0}),o.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{s.mouseover=!1,o.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{vc(e,o,s.pointerCanvasPos)}),o.addEventListener("mousedown",this._mouseDownHandler=e=>{i.active&&i.pointerEnabled&&(vc(e,o,s.pointerCanvasPos),s.mouseover=!0)}),o.addEventListener("mouseup",this._mouseUpHandler=e=>{i.active&&i.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function vc(e,t,i){if(e){const{left:s,top:r}=t.getBoundingClientRect();i[0]=e.clientX-s,i[1]=e.clientY-r}else e=window.event,i[0]=e.x,i[1]=e.y;return i}const bc=function(e,t){if(e){let i=e.target,s=0,r=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;t[0]=e.pageX-s,t[1]=e.pageY-r}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class yc{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=c.vec2(),l=c.vec2(),A=c.vec2(),h=c.vec2(),u=[],d=this._scene.canvas.canvas;let p=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),d.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!i.active||!i.pointerEnabled)return;t.preventDefault();const r=t.touches,l=t.changedTouches;for(s.touchStartTime=Date.now(),1===r.length&&1===l.length&&(bc(r[0],a),i.followPointer&&(o.pickCursorPos=a,o.schedulePickSurface=!0,o.update(),i.planView||(o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(n.setPivotPos(o.pickResult.worldPos),!i.firstPerson&&n.startPivot()&&n.showPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),!i.firstPerson&&n.startPivot()&&n.showPivot()))));u.length{n.getPivoting()&&n.endPivot()}),d.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const n=e.canvas.boundary,a=n[2],d=n[3],g=t.touches;if(t.touches.length===p){if(1===p){bc(g[0],l),c.subVec2(l,u[0],h);const t=h[0],o=h[1];if(null!==s.longTouchTimeout&&(Math.abs(t)>i.longTapRadius||Math.abs(o)>i.longTapRadius)&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),i.planView){const s=e.camera;if("perspective"===s.projection){const n=Math.abs(e.camera.eyeLookDist)*Math.tan(s.perspective.fov/2*Math.PI/180);r.panDeltaX+=t*n/d*i.touchPanRate,r.panDeltaY+=o*n/d*i.touchPanRate}else r.panDeltaX+=.5*s.ortho.scale*(t/d)*i.touchPanRate,r.panDeltaY+=.5*s.ortho.scale*(o/d)*i.touchPanRate}else r.rotateDeltaY-=t/a*(1*i.dragRotationRate),r.rotateDeltaX+=o/d*(1.5*i.dragRotationRate)}else if(2===p){const t=g[0],n=g[1];bc(t,l),bc(n,A);const a=c.geometricMeanVec2(u[0],u[1]),h=c.geometricMeanVec2(l,A),p=c.vec2();c.subVec2(a,h,p);const f=p[0],m=p[1],_=e.camera,v=c.distVec2([t.pageX,t.pageY],[n.pageX,n.pageY]),b=(c.distVec2(u[0],u[1])-v)*i.touchDollyRate;if(r.dollyDelta=b,Math.abs(b)<1)if("perspective"===_.projection){const t=o.pickResult?o.pickResult.worldPos:e.center,s=Math.abs(c.lenVec3(c.subVec3(t,e.camera.eye,[])))*Math.tan(_.perspective.fov/2*Math.PI/180);r.panDeltaX-=f*s/d*i.touchPanRate,r.panDeltaY-=m*s/d*i.touchPanRate}else r.panDeltaX-=.5*_.ortho.scale*(f/d)*i.touchPanRate,r.panDeltaY-=.5*_.ortho.scale*(m/d)*i.touchPanRate;s.pointerCanvasPos=h}for(let e=0;e{let s;i&&i.worldPos&&(s=i.worldPos);const r=i?i.entity.aabb:e.aabb;if(s){const i=e.camera;c.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})};d.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!i.active||!i.pointerEnabled)return;null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null);const r=e.touches,o=e.changedTouches;if(a=Date.now(),1===r.length&&1===o.length){h=a,xc(r[0],A);const o=A[0],n=A[1],l=r[0].pageX,c=r[0].pageY;s.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(c)],canvasPos:[Math.round(o),Math.round(n)],event:e},!0),s.longTouchTimeout=null}),i.longTapTimeout)}else h=-1;for(;l.length{if(!i.active||!i.pointerEnabled)return;const t=Date.now(),r=e.touches,a=e.changedTouches,d=n.hasSubs("pickedSurface");null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),0===r.length&&1===a.length&&h>-1&&t-h<150&&(u>-1&&h-u<325?(xc(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=d,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("doublePicked",o.pickResult),o.pickedSurface&&n.fire("doublePickedSurface",o.pickResult),i.doublePickFlyTo&&p(o.pickResult)):(n.fire("doublePickedNothing"),i.doublePickFlyTo&&p()),u=-1):c.distVec2(l[0],A)<4&&(xc(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=d,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("picked",o.pickResult),o.pickedSurface&&n.fire("pickedSurface",o.pickResult)):n.fire("pickedNothing"),u=t),h=-1),l.length=r.length;for(let e=0,t=r.length;e{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,keyboardEnabledOnlyIfMouseover:!0,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:c.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:c.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const i=this.scene;this._controllers={cameraControl:this,pickController:new rc(this,this._configs),pivotController:new sc(i,this._configs),panController:new Yh(i),cameraFlight:new Mh(this,{duration:.5})},this._handlers=[new _c(this.scene,this._controllers,this._configs,this._states,this._updates),new yc(this.scene,this._controllers,this._configs,this._states,this._updates),new nc(this.scene,this._controllers,this._configs,this._states,this._updates),new dc(this.scene,this._controllers,this._configs,this._states,this._updates),new pc(this.scene,this._controllers,this._configs,this._states,this._updates),new Bc(this.scene,this._controllers,this._configs,this._states,this._updates),new fc(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new mc(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",_.isString(e)){const t=this.scene.input,i={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":i[this.PAN_LEFT]=[t.KEY_A],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_Z],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":i[this.PAN_LEFT]=[t.KEY_Q],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_W],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=i}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const i=this._keyMap[e];if(!i)return!1;t||(t=this.scene.input.keyDown);for(let e=0,s=i.length;e0&&console.error(`[MetaModel._decompressProperties] Properties not found: ${i}`)}finalize(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";const e=this.metaScene;for(let t in e.metaObjects){const i=e.metaObjects[t];if(i.children&&(i.children=[]),i.propertySets&&(i.propertySets=[]),i.propertySetIds)for(let t=0,s=i.propertySetIds.length;t0?Ic(t):null,n=i&&i.length>0?Ic(i):null,a=e=>{if(!e)return;var t=!0;(n&&n[e.type]||o&&!o[e.type])&&(t=!1),t&&s.push(e.id);const i=e.children;if(i)for(var r=0,l=i.length;r>t;i.sort(SA);const s=new Int32Array(e.length);for(let t=0,r=i.length;te[t+1]){let i=e[t];e[t]=e[t+1],e[t+1]=i}TA=new Int32Array(e),t.sort(LA);const i=new Int32Array(e.length);for(let s=0,r=t.length;st){let i=e;e=t,t=i}function i(i,s){return i!==e?e-i:s!==t?t-s:0}let s=0,r=(o.length>>1)-1;for(;s<=r;){const e=r+s>>1,t=i(o[2*e],o[2*e+1]);if(t>0)s=e+1;else{if(!(t<0))return e;r=e-1}}return-s-1}const a=new Int32Array(o.length/2);a.fill(0);const l=s.length/3;if(l>8*(1<u.maxNumPositions&&(u=c()),u.bucketNumber>8)return[e];let p;-1===A[l]&&(A[l]=u.numPositions++,u.positionsCompressed.push(s[3*l]),u.positionsCompressed.push(s[3*l+1]),u.positionsCompressed.push(s[3*l+2])),-1===A[h]&&(A[h]=u.numPositions++,u.positionsCompressed.push(s[3*h]),u.positionsCompressed.push(s[3*h+1]),u.positionsCompressed.push(s[3*h+2])),-1===A[d]&&(A[d]=u.numPositions++,u.positionsCompressed.push(s[3*d]),u.positionsCompressed.push(s[3*d+1]),u.positionsCompressed.push(s[3*d+2])),u.indices.push(A[l]),u.indices.push(A[h]),u.indices.push(A[d]),(p=n(l,h))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(l,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(h,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]]))}const d=t/8*2,p=t/8,f=2*s.length+(r.length+o.length)*d;let g=0,m=-s.length/3;return h.forEach((e=>{g+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*p,m+=e.positionsCompressed.length/3})),g>f?[e]:(i&&function(e,t){const i={},s={};let r=0;e.forEach((e=>{const t=e.indices,o=e.edgeIndices,n=e.positionsCompressed;for(let e=0,s=t.length;e0){const e=t._meshes;for(let t=0,i=e.length;t0){const e=this._meshes;for(let t=0,i=e.length;t{this._viewMatrixDirty=!0})),this._meshesWithDirtyMatrices=[],this._numMeshesWithDirtyMatrices=0,this._onTick=this.scene.on("tick",(()=>{for(;this._numMeshesWithDirtyMatrices>0;)this._meshesWithDirtyMatrices[--this._numMeshesWithDirtyMatrices]._updateMatrix()})),this._createDefaultTextureSet(),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.backfaces=t.backfaces}_meshMatrixDirty(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}_createDefaultTextureSet(){const e=new fA({id:"defaultColorTexture",texture:new Ps({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new fA({id:"defaultMetalRoughTexture",texture:new Ps({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),i=new fA({id:"defaultNormalsTexture",texture:new Ps({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),s=new fA({id:"defaultEmissiveTexture",texture:new Ps({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),r=new fA({id:"defaultOcclusionTexture",texture:new Ps({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=i,this._textures.defaultEmissiveTexture=s,this._textures.defaultOcclusionTexture=r,this._textureSets.defaultTextureSet=new pA({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:i,emissiveTexture:s,occlusionTexture:r})}get isPerformanceModel(){return!0}get transforms(){return this._transforms}get textures(){return this._textures}get textureSets(){return this._textureSets}get meshes(){return this._meshes}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),c.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),c.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||YA),c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),c.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),c.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),c.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),c.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),c.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0,this._aabbDirty=!0}_transformDirty(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}_sceneModelDirty(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(let e=0,t=this._entityList.length;e0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,i=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,i=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,i=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,i=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,i=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,i=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,i=new Uint8Array(t.length);for(let e=0,s=t.length;e{l.setImage(A,{minFilter:i,magFilter:s,wrapS:r,wrapT:o,wrapR:n,flipY:e.flipY,encoding:a}),this.glRedraw()},A.src=e.src;break;default:this._textureTranscoder?_.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new fA({id:t,texture:l})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let i,s,r,o,n;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(i=this._textures[e.colorTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(s=this._textures[e.metallicRoughnessTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(r=this._textures[e.normalsTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(o=this._textures[e.emissiveTextureId],!o)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else o=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(n=this._textures[e.occlusionTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultOcclusionTexture;const a=new pA({id:t,model:this,colorTexture:i,metallicRoughnessTexture:s,normalsTexture:r,emissiveTexture:o,occlusionTexture:n});return this._textureSets[t]=a,a}createTransform(e){if(void 0===e.id||null===e.id)return void this.error("[createTransform] SceneModel.createTransform() config missing: id");if(this._transforms[e.id])return void this.error(`[createTransform] SceneModel already has a transform with this ID: ${e.id}`);let t;if(e.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const i=new jA({id:e.id,model:this,parent:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[i.id]=i,i}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._meshes[e.id])return this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`),!1;if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!(e.buckets||e.indices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)){const t=(e.positions||e.positionsCompressed).length/3;e.indices=this._createDefaultIndices(t)}if(!e.buckets&&!e.indices&&"points"!==e.primitive)return e.indices=this._createDefaultIndices(numIndices),this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;const t=!(!this._dtxEnabled||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||e.textureSetId);if(e.origin=e.origin?c.addVec3(this._origin,e.origin,c.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position||e.quaternion){const t=e.scale||KA,i=e.position||XA;e.rotation?(c.eulerToQuaternion(e.rotation,"XYZ",WA),e.meshMatrix=c.composeMat4(i,WA,t,c.mat4())):e.meshMatrix=c.composeMat4(i,e.quaternion||JA,t,c.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Vr(e.positionsDecodeBoundary,c.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):ZA,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=c.vec3(),i=[];K(e.positions,i,t)&&(e.positions=i,e.origin=c.addVec3(e.origin,t,t))}if(e.positions){const t=c.collapseAABB3();e.positionsDecodeMatrix=c.mat4(),c.expandAABB3Points3(t,e.positions),e.positionsCompressed=Qr(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=c.collapseAABB3();c.expandAABB3Points3(t,e.positionsCompressed),Qt.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=c.collapseAABB3();for(let i=0,s=e.buckets.length;i>24&255,r=i>>16&255,o=i>>8&255,n=255&i;switch(e.pickColor=new Uint8Array([n,o,r,s]),e.solid="solid"===e.primitive,t.origin=c.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),this._meshes[e.id]=t,this._unusedMeshes[e.id]=t,this._meshList.push(t),t}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let i=0,s=e.buckets.length;i>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,i=e.origin,s=e.textureSetId||"-",r=e.geometryId,o=`${Math.round(i[0])}.${Math.round(i[1])}.${Math.round(i[2])}.${s}.${r}`;let n=this._vboInstancingLayers[o];if(n)return n;let a=e.textureSet;const l=e.geometry;for(;!n;)switch(l.primitive){case"triangles":case"surface":n=new Wo({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!1});break;case"solid":n=new Wo({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!0});break;case"lines":n=new Sn({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0});break;case"points":n=new Pa({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0})}return this._vboInstancingLayers[o]=n,this.layerList.push(n),n}createEntity(e){if(void 0===e.id?e.id=c.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=c.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;this._visible&&!1!==e.visible&&(t|=J),this._pickable&&!1!==e.pickable&&(t|=Z),this._culled&&!1!==e.culled&&(t|=Y),this._clippable&&!1!==e.clippable&&(t|=q),this._collidable&&!1!==e.collidable&&(t|=$),this._edges&&!1!==e.edges&&(t|=se),this._xrayed&&!1!==e.xrayed&&(t|=ee),this._highlighted&&!1!==e.highlighted&&(t|=te),this._selected&&!1!==e.selected&&(t|=ie),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let i=0,s=e.meshIds.length;ie.sortIdt.sortId?1:0));for(let e=0,t=this.layerList.length;e0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,i=this.layerList.length;t0){const t=`${this.id}-dummyEntityForUnusedMeshes`;this.warn(`Creating dummy SceneModelEntity "${t}" for unused SceneMeshes: [${e.join(",")}]`),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}_getActiveSectionPlanesForLayer(e){const t=this.renderFlags,i=this.scene._sectionPlanesState.sectionPlanes,s=i.length,r=e.layerIndex*s;if(s>0)for(let e=0;e0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}drawColorOpaque(e,t){const i=this.renderFlags;for(let t=0,s=i.visibleLayers.length;t65536?16:8)}else n=[{positionsCompressed:s,indices:r,edgeIndices:o}];return n}class eh extends D{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e{var r=e-i,o=t-s;return Math.sqrt(r*r+o*o)};class ch extends D{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._eventSubs={};var i=this.plugin.viewer.scene;this._originWorld=c.vec3(),this._targetWorld=c.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;const s=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,r=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},n=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,A=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new ue(i,t.origin,this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._targetDot=new ue(i,t.target,this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthWire=new fe(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisWire=new fe(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisWire=new fe(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisWire=new fe(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthLabel=new ge(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisLabel=new ge(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisLabel=new ge(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisLabel=new ge(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._measurementOrientation="Horizontal",this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._sectionPlanesDirty=!0,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,this._xLabelEnabled=!1,this._yLabelEnabled=!1,this._zLabelEnabled=!1,this._lengthLabelEnabled=!1,this._labelsVisible=!1,this._labelsOnWires=!1,this._clickable=!1,this._originDot.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetDot.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=i.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=i.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=i.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=i.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=i.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=i.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=i.on("sectionPlaneUpdated",(()=>{this._sectionPlanesDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.xLabelEnabled=t.xLabelEnabled,this.yLabelEnabled=t.yLabelEnabled,this.zLabelEnabled=t.zLabelEnabled,this.lengthLabelEnabled=t.lengthLabelEnabled,this.labelsVisible=t.labelsVisible,this.labelsOnWires=t.labelsOnWires,this.useRotationAdjustment=t.useRotationAdjustment}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._measurementOrientation=function(e,t,i){return Math.abs(t[1]-e[1])>i?"Vertical":"Horizontal"}(this._originWorld,this._targetWorld,0),"Vertical"===this._measurementOrientation&&this.useRotationAdjustment?(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._originWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._originWorld[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._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1),this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(c.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._originWorld)||this._isSliced(this._targetWorld))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}const t=this._originDot.viewPos[2],i=this._targetDot.viewPos[2];if(t>-.3||i>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){c.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var s=this._pp,r=this._cp,o=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var n=o.top-t.top,a=o.left-t.left,l=e.canvas.boundary,A=l[2],h=l[3],u=0;const i=this.plugin.viewer.scene.metrics,f=i.scale,g=i.units,m=i.unitsInfo[g].abbrev;for(var d=0,p=s.length;de.offsetTop+(e.offsetParent&&e.offsetParent!==s.parentNode&&h(e.offsetParent)),u=e=>e.offsetLeft+(e.offsetParent&&e.offsetParent!==s.parentNode&&u(e.offsetParent)),d=c.vec2();this._onCameraControlHoverSnapOrSurface=i.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(e=>{const t=e.snappedCanvasPos||e.canvasPos;r=!0,o.set(e.worldPos),n.set(e.canvasPos),0===this._mouseState?(this._canvasToPagePos?(this._canvasToPagePos(s,t,d),this._markerDiv.style.left=d[0]-5+"px",this._markerDiv.style.top=d[1]-5+"px"):(this._markerDiv.style.left=u(s)+t[0]-5+"px",this._markerDiv.style.top=h(s)+t[1]-5+"px"),this._markerDiv.style.background="pink",e.snappedToVertex||e.snappedToEdge?(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos,this.pointerLens.snapped=!0),this._markerDiv.style.background="greenyellow",this._markerDiv.style.border="2px solid green"):(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.canvasPos,this.pointerLens.snapped=!1),this._markerDiv.style.background="pink",this._markerDiv.style.border="2px solid red"),A=e.entity):(this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px"),s.style.cursor="pointer",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=this._currentDistanceMeasurementInitState.wireVisible,this._currentDistanceMeasurement.axisVisible=this._currentDistanceMeasurementInitState.axisVisible&&this.distanceMeasurementsPlugin.defaultAxisVisible,this._currentDistanceMeasurement.xAxisVisible=this._currentDistanceMeasurementInitState.xAxisVisible&&this.distanceMeasurementsPlugin.defaultXAxisVisible,this._currentDistanceMeasurement.yAxisVisible=this._currentDistanceMeasurementInitState.yAxisVisible&&this.distanceMeasurementsPlugin.defaultYAxisVisible,this._currentDistanceMeasurement.zAxisVisible=this._currentDistanceMeasurementInitState.zAxisVisible&&this.distanceMeasurementsPlugin.defaultZAxisVisible,this._currentDistanceMeasurement.targetVisible=this._currentDistanceMeasurementInitState.targetVisible,this._currentDistanceMeasurement.target.worldPos=o.slice(),this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px")})),s.addEventListener("mousedown",this._onMouseDown=e=>{1===e.which&&(a=e.clientX,l=e.clientY)}),s.addEventListener("mouseup",this._onMouseUp=t=>{1===t.which&&(t.clientX>a+20||t.clientXl+20||t.clientY{this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos),r=!1,this._markerDiv.style.left="-100px",this._markerDiv.style.top="-100px",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.axisVisible=!1),s.style.cursor="default"})),this._active=!0}deactivate(){if(!this._active)return;this.fire("activated",!1),this.pointerLens&&(this.pointerLens.visible=!1);const e=this.scene.canvas.canvas;e.removeEventListener("mousedown",this._onMouseDown),e.removeEventListener("mouseup",this._onMouseUp);const t=this.distanceMeasurementsPlugin.viewer.cameraControl;t.off(this._onCameraControlHoverSnapOrSurface),t.off(this._onCameraControlHoverSnapOrSurfaceOff),this._active=!1}reset(){this._active&&(this._destroyMarkerDiv(),this._initMarkerDiv(),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null),this._mouseState=0)}get currentMeasurement(){return this._currentDistanceMeasurement}destroy(){this.deactivate(),super.destroy()}}class ph extends D{constructor(e,t,i,s){const r=e.plugin.viewer;super(r.scene);const o=pe({viewer:r,handleMouseEvents:i,handleTouchEvents:s,pointerLens:t.pointerLens,dots:[e.origin,e.target],ray2WorldPos:(e,i,s)=>{const o=e=>{const t=r.scene.pick({canvasPos:s,snapToEdge:e,snapToVertex:e,pickSurface:!0});return t&&t.worldPos?t.worldPos:e&&o(!1)};return o(!!t.snapping)},onEnd:(e,t)=>{const i=!c.compareVec3(e,t.worldPos);return i&&this.fire("edited"),i}}),n=e.on("destroyed",o);this._deactivate=function(){e.off("destroyed",n),o()}}deactivate(){this._deactivate(),super.destroy()}}class fh{constructor(e={}){this.cacheBuster=!1!==e.cacheBuster}_cacheBusterURL(e){if(!this.cacheBuster)return e;const t=(new Date).getTime();return e.indexOf("?")>-1?e+"&_="+t:e+"?_="+t}getMetaModel(e,t,i){_.loadJSON(this._cacheBusterURL(e),(e=>{t(e)}),(function(e){i(e)}))}getGLTF(e,t,i){_.loadArraybuffer(this._cacheBusterURL(e),(e=>{t(e)}),(function(e){i(e)}))}getGLB(e,t,i){_.loadArraybuffer(this._cacheBusterURL(e),(e=>{t(e)}),(function(e){i(e)}))}getArrayBuffer(e,t,i,s){!function(e,t,i,s){var r=()=>{};i=i||r,s=s||r;const o=/^data:(.*?)(;base64)?,(.*)$/,n=t.match(o);if(n){const e=!!n[2];var a=n[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),t=new Uint8Array(e);for(var l=0;l{i(e)}),(function(e){s(e)}))}}class gh{constructor(e={}){this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=e.messages,this.locale=e.locale}set messages(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}loadMessages(e={}){for(let t in e)this._messages[t]=e[t];this.messages=this._messages}clearMessages(){this.messages={}}get locales(){return this._locales}set locale(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}get locale(){return this._locale}translate(e,t){const i=this._messages[this._locale];if(!i)return null;const s=mh(e,i);return s?t?_h(s,t):s:null}translatePlurals(e,t,i){const s=this._messages[this._locale];if(!s)return null;let r=mh(e,s);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=_h(r,[t]),i&&(r=_h(r,i)),r):null}fire(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);const s=this._eventSubs[e];if(s)for(const e in s)if(s.hasOwnProperty(e)){s[e].callback(t)}}on(t,i){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let s=this._eventSubs[t];s||(s={},this._eventSubs[t]=s);const r=this._eventSubIDMap.addItem();s[r]={callback:i},this._eventSubEvents[r]=t;const o=this._events[t];return void 0!==o&&i(o),r}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}function mh(e,t){if(t[e])return t[e];const i=e.split(".");let s=t;for(let e=0,t=i.length;s&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,s=e+t;i<0&&(i=0),s>1&&(s=1);var r=this.getPoint(i),o=this.getPoint(s),n=c.subVec3(o,r,[]);return c.normalizeVec3(n,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,s=[],r=this.getPoint(0),o=0;for(s.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),o+=c.lenVec3(c.subVec3(t,r,[])),s.push(o),r=t;return this.cacheArcLengths=s,s}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var i,s=this._getLengths(),r=0,o=s.length;i=t||e*s[o-1];for(var n,a=0,l=o-1;a<=l;)if((n=s[r=Math.floor(a+(l-a)/2)]-i)<0)a=r+1;else{if(!(n>0)){l=r;break}l=r-1}if(s[r=l]===i)return r/(o-1);var A=s[r];return(r+(i-A)/(s[r+1]-A))/(o-1)}}class bh extends vh{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,s=Math.floor(i),r=i-s,o=t[0===s?s:s-1],n=t[s],a=t[s>t.length-2?t.length-1:s+1],l=t[s>t.length-3?t.length-1:s+2],A=c.vec3();return A[0]=c.catmullRomInterpolate(o[0],n[0],a[0],l[0],r),A[1]=c.catmullRomInterpolate(o[1],n[1],a[1],l[1],r),A[2]=c.catmullRomInterpolate(o[2],n[2],a[2],l[2],r),A}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const yh=c.vec3();const xh=c.vec3(),Bh=c.vec3(),wh=c.vec3(),Ph=c.vec3(),Ch=c.vec3();class Mh extends D{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=c.vec3(),this._eye1=c.vec3(),this._up1=c.vec3(),this._look2=c.vec3(),this._eye2=c.vec3(),this._up2=c.vec3(),this._orthoScale1=1,this._orthoScale2=1,this._flying=!1,this._flyEyeLookUp=!1,this._flyingEye=!1,this._flyingLook=!1,this._callback=null,this._callbackScope=null,this._time1=null,this._time2=null,this.easing=!1!==t.easing,this.duration=t.duration,this.fit=t.fit,this.fitFOV=t.fitFOV,this.trail=t.trail}flyTo(e,t,i){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=i;const s=this.scene.camera,r=!!e.projection&&e.projection!==s.projection;let o,n,a,l,A;if(this._eye1[0]=s.eye[0],this._eye1[1]=s.eye[1],this._eye1[2]=s.eye[2],this._look1[0]=s.look[0],this._look1[1]=s.look[1],this._look1[2]=s.look[2],this._up1[0]=s.up[0],this._up1[1]=s.up[1],this._up1[2]=s.up[2],this._orthoScale1=s.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)o=e.aabb;else if(6===e.length)o=e;else if(e.eye&&e.look||e.up)n=e.eye,a=e.look,l=e.up;else if(e.eye)n=e.eye;else if(e.look)a=e.look;else{let s=e;if((_.isNumeric(s)||_.isString(s))&&(A=s,s=this.scene.components[A],!s))return this.error("Component not found: "+_.inQuotes(A)),void(t&&(i?t.call(i):t()));r||(o=s.aabb||this.scene.aabb)}const h=e.poi;if(o){if(o[3]=1;e>1&&(e=1);const i=this.easing?Mh._ease(e,0,1,1):e,s=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(c.subVec3(s.eye,s.look,Ch),s.eye=c.lerpVec3(i,0,1,this._eye1,this._eye2,wh),s.look=c.subVec3(wh,Ch,Bh)):this._flyingLook&&(s.look=c.lerpVec3(i,0,1,this._look1,this._look2,Bh),s.up=c.lerpVec3(i,0,1,this._up1,this._up2,Ph)):this._flyingEyeLookUp&&(s.eye=c.lerpVec3(i,0,1,this._eye1,this._eye2,wh),s.look=c.lerpVec3(i,0,1,this._look1,this._look2,Bh),s.up=c.lerpVec3(i,0,1,this._up1,this._up2,Ph)),this._projection2){const t="ortho"===this._projection2?Mh._easeOutExpo(e,0,1,1):Mh._easeInCubic(e,0,1,1);s.customProjection.matrix=c.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else s.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return s.ortho.scale=this._orthoScale2,void this.stop();M.scheduleTask(this._update,this)}static _ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}static _easeInCubic(e,t,i,s){return i*(e/=s)*e*e+t}static _easeOutExpo(e,t,i,s){return i*(1-Math.pow(2,-10*e/s))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class Eh extends D{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new Mh(this),this._t=0,this.state=Eh.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,i;const s=performance.now(),r=this._lastTime?.001*(s-this._lastTime):0;if(this._lastTime=s,0!==r)switch(this.state){case Eh.SCRUBBING:return;case Eh.PLAYING:if(this._t+=this._playingRate*r,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=Eh.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case Eh.PLAYING_TO:i=this._t+this._playingRate*r*this._playingDir,(this._playingDir<0&&i<=this._playingToT||this._playingDir>0&&i>=this._playingToT)&&(i=this._playingToT,this.state=Eh.SCRUBBING,this.fire("stopped")),this._t=i,e.loadFrame(this._t)}}_ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=Eh.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=Eh.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const i=this._cameraPath;if(!i)return;const s=i.frames[e];s?(this.state=Eh.SCRUBBING,this._cameraFlightAnimation.flyTo(s,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=Eh.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=Eh.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=Eh.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}Eh.STOPPED=0,Eh.SCRUBBING=1,Eh.PLAYING=2,Eh.PLAYING_TO=3;const Fh=c.vec3(),Ih=c.vec3();c.vec3();const Dh=c.vec3([0,-1,0]),Sh=c.vec4([0,0,0,1]);function Th(e){if(!Lh(e.width)||!Lh(e.height)){const t=document.createElement("canvas");t.width=Rh(e.width),t.height=Rh(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Lh(e){return 0==(e&e-1)}function Rh(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Uh extends D{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const i=this.scene.canvas.gl;this._state=new at({texture:new Ps({gl:i,target:i.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),p.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,i=this.scene.canvas.gl;this._images=[];let s=!1,r=0;for(let o=0;o{r(),t()})):(i.eye=this._eye,i.look=this._look,i.up=this._up,r(),i.projection=s.projection)}}const Oh=c.vec3();const Nh=c.vec3();class Qh{constructor(){this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}saveObjects(e,t){this.numObjects=0,this._mask=t?_.apply(t,{}):null;const i=e.objects,s=!t||t.visible,r=!t||t.edges,o=!t||t.xrayed,n=!t||t.highlighted,a=!t||t.selected,l=!t||t.clippable,A=!t||t.pickable,h=!t||t.colorize,c=!t||t.opacity;for(let e in i)if(i.hasOwnProperty(e)){const t=i[e],u=this.numObjects;if(s&&(this.objectsVisible[u]=t.visible),r&&(this.objectsEdges[u]=t.edges),o&&(this.objectsXrayed[u]=t.xrayed),n&&(this.objectsHighlighted[u]=t.highlighted),a&&(this.objectsSelected[u]=t.selected),l&&(this.objectsClippable[u]=t.clippable),A&&(this.objectsPickable[u]=t.pickable),h){const e=t.colorize;e?(this.objectsColorize[3*u+0]=e[0],this.objectsColorize[3*u+1]=e[1],this.objectsColorize[3*u+2]=e[2],this.objectsHasColorize[u]=!0):this.objectsHasColorize[u]=!1}c&&(this.objectsOpacity[u]=t.opacity),this.numObjects++}}restoreObjects(e){const t=this._mask,i=!t||t.visible,s=!t||t.edges,r=!t||t.xrayed,o=!t||t.highlighted,n=!t||t.selected,a=!t||t.clippable,l=!t||t.pickable,A=!t||t.colorize,h=!t||t.opacity;var c=0;const u=e.objects;for(let e in u)if(u.hasOwnProperty(e)){const t=u[e];i&&(t.visible=this.objectsVisible[c]),s&&(t.edges=this.objectsEdges[c]),r&&(t.xrayed=this.objectsXrayed[c]),o&&(t.highlighted=this.objectsHighlighted[c]),n&&(t.selected=this.objectsSelected[c]),a&&(t.clippable=this.objectsClippable[c]),l&&(t.pickable=this.objectsPickable[c]),A&&(this.objectsHasColorize[c]?(Nh[0]=this.objectsColorize[3*c+0],Nh[1]=this.objectsColorize[3*c+1],Nh[2]=this.objectsColorize[3*c+2],t.colorize=Nh):t.colorize=null),h&&(t.opacity=this.objectsOpacity[c]),c++}}}class Vh extends D{constructor(e,t={}){super(e,t),this._skyboxMesh=new $i(this,{geometry:new jt(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new Xt(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Ds(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}const Hh=c.vec4(),jh=c.vec4(),Gh=c.vec3(),zh=c.vec3(),Wh=c.vec3(),Kh=c.vec4(),Xh=c.vec4(),Jh=c.vec4();class Yh{constructor(e){this._scene=e}dollyToCanvasPos(e,t,i){let s=!1;const r=this._scene.camera;if(e){const t=c.subVec3(e,r.eye,Gh);s=c.lenVec3(t){this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=c.vec3();c.decomposeMat4(c.inverseMat4(this._scene.viewer.camera.viewMatrix,c.mat4()),t,c.vec4(),c.vec3());const i=c.distVec3(t,e);let s=Math.tan(Math.PI/500)*i*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(s/=this._scene.camera.ortho.scale/2),W(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Ls(this._scene,is({radius:s})),this._pivotSphere=new $i(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){c.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,c.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const i=t.boundary,s=i[2],r=i[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*s/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*r/2);let o=t._lastBoundingClientRect;if(!o||t._canvasSizeChanged){const e=t.canvas;o=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(o.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(o.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(W(this.getPivotPos(),this._rtcCenter,this._rtcPos),c.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new Xt(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=c.lookAtMat4v(e.eye,e.look,e.worldUp);c.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const i=this.getPivotPos();this._cameraOffset[2]+=c.distVec3(e.eye,i),t=c.inverseMat4(t);const s=c.transformVec3(t,this._cameraOffset),r=c.vec3();if(c.subVec3(e.eye,i,r),c.addVec3(r,s),e.zUp){const e=r[1];r[1]=r[2],r[2]=e}this._radius=c.lenVec3(r),this._polar=Math.acos(r[1]/this._radius),this._azimuth=Math.atan2(r[0],r[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=c.normalizeVec3(c.subVec3(e.look,e.eye,Zh)),i=c.cross3Vec3(t,e.worldUp,qh);return c.sqLenVec3(i)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,i=Math.abs(c.distVec3(this._scene.center,t.eye)),s=t.project.transposedMatrix,r=s.subarray(8,12),o=s.subarray(12),n=[0,0,-1,1],a=c.dotVec4(n,r)/c.dotVec4(n,o),l=ec;t.project.unproject(e,a,tc,ic,l);const A=c.normalizeVec3(c.subVec3(l,t.eye,Zh)),h=c.addVec3(t.eye,c.mulVec3Scalar(A,i,qh),$h);this.setPivotPos(h)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const i=this._scene.camera;var s=-e;const r=-t;1===i.worldUp[2]&&(s=-s),this._azimuth+=.01*-s,this._polar+=.01*r,this._polar=c.clamp(this._polar,.001,Math.PI-.001);const o=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===i.worldUp[2]){const e=o[1];o[1]=o[2],o[2]=e}const n=c.lenVec3(c.subVec3(i.look,i.eye,c.vec3())),a=this.getPivotPos();c.addVec3(o,a);let l=c.lookAtMat4v(o,a,i.worldUp);l=c.inverseMat4(l);const A=c.transformVec3(l,this._cameraOffset);l[12]-=A[0],l[13]-=A[1],l[14]-=A[2];const h=[l[8],l[9],l[10]];i.eye=[l[12],l[13],l[14]],c.subVec3(i.eye,c.mulVec3Scalar(h,n),i.look),i.up=[l[4],l[5],l[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class rc{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=c.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;const e=`${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;if(this._lastHash===e)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;const t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&(e.snappedToEdge||e.snappedToVertex)?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const e=this.pickResult.canvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new Te;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}const oc=c.vec2();class nc{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController;let n,a,l,A=0,h=0,u=0,d=0,p=!1;const f=c.vec3();let g=!0;const m=this._scene.canvas.canvas,_=[];function v(e=!0){m.style.cursor="move",A=s.pointerCanvasPos[0],h=s.pointerCanvasPos[1],u=s.pointerCanvasPos[0],d=s.pointerCanvasPos[1],e&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(p=!0,f.set(o.pickResult.worldPos)):p=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(i.active&&i.pointerEnabled)switch(t.which){case 1:_[e.input.KEY_SHIFT]||i.planView?(n=!0,v()):(n=!0,v(!1));break;case 2:a=!0,v();break;case 3:l=!0,i.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(!n&&!a&&!l)return;const o=e.canvas.boundary,u=o[2],d=o[3],g=s.pointerCanvasPos[0],m=s.pointerCanvasPos[1],v=_[e.input.KEY_SHIFT]||i.planView||!i.panRightClick&&a||i.panRightClick&&l,b=document.pointerLockElement?t.movementX:g-A,y=document.pointerLockElement?t.movementY:m-h;if(v){const t=e.camera;if("perspective"===t.projection){const i=Math.abs(p?c.lenVec3(c.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(t.perspective.fov/2*Math.PI/180);r.panDeltaX+=1.5*b*i/d,r.panDeltaY+=1.5*y*i/d}else r.panDeltaX+=.5*t.ortho.scale*(b/d),r.panDeltaY+=.5*t.ortho.scale*(y/d)}else!n||a||l||i.planView||(i.firstPerson?(r.rotateDeltaY-=b/u*i.dragRotationRate/2,r.rotateDeltaX+=y/d*(i.dragRotationRate/4)):(r.rotateDeltaY-=b/u*(1.5*i.dragRotationRate),r.rotateDeltaX+=y/d*(1.5*i.dragRotationRate)));A=g,h=m}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{i.active&&i.pointerEnabled&&s.mouseover&&(g=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(i.active&&i.pointerEnabled)switch(e.which){case 1:case 2:case 3:n=!1,a=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(i.active&&i.pointerEnabled){if(3===e.which){!function(e,t){if(e){let i=e.target,s=0,r=0,o=0,n=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,o+=i.scrollLeft,n+=i.scrollTop,i=i.offsetParent;t[0]=e.pageX+o-s,t[1]=e.pageY+n-r}else e=window.event,t[0]=e.x,t[1]=e.y}(e,oc);const i=oc[0],s=oc[1];Math.abs(i-u)<3&&Math.abs(s-d)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:oc,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{i.active&&i.pointerEnabled});const b=1/60;let y=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!i.active||!i.pointerEnabled)return;const t=performance.now()/1e3;var o=null!==y?t-y:0;y=t,o>.05&&(o=.05),o{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(i.keyboardEnabledOnlyIfMouseover&&!s.mouseover)return;const n=r._isKeyDownForAction(r.AXIS_VIEW_RIGHT),a=r._isKeyDownForAction(r.AXIS_VIEW_BACK),l=r._isKeyDownForAction(r.AXIS_VIEW_LEFT),A=r._isKeyDownForAction(r.AXIS_VIEW_FRONT),h=r._isKeyDownForAction(r.AXIS_VIEW_TOP),u=r._isKeyDownForAction(r.AXIS_VIEW_BOTTOM);if(!(n||a||l||A||h||u))return;const d=e.aabb,p=c.getAABB3Diag(d);c.getAABB3Center(d,ac);const f=Math.abs(p/Math.tan(t.cameraFlight.fitFOV*c.DEGTORAD)),g=1.1*p;uc.orthoScale=g,n?(uc.eye.set(c.addVec3(ac,c.mulVec3Scalar(o.worldRight,f,lc),cc)),uc.look.set(ac),uc.up.set(o.worldUp)):a?(uc.eye.set(c.addVec3(ac,c.mulVec3Scalar(o.worldForward,f,lc),cc)),uc.look.set(ac),uc.up.set(o.worldUp)):l?(uc.eye.set(c.addVec3(ac,c.mulVec3Scalar(o.worldRight,-f,lc),cc)),uc.look.set(ac),uc.up.set(o.worldUp)):A?(uc.eye.set(c.addVec3(ac,c.mulVec3Scalar(o.worldForward,-f,lc),cc)),uc.look.set(ac),uc.up.set(o.worldUp)):h?(uc.eye.set(c.addVec3(ac,c.mulVec3Scalar(o.worldUp,f,lc),cc)),uc.look.set(ac),uc.up.set(c.normalizeVec3(c.mulVec3Scalar(o.worldForward,1,Ac),hc))):u&&(uc.eye.set(c.addVec3(ac,c.mulVec3Scalar(o.worldUp,-f,lc),cc)),uc.look.set(ac),uc.up.set(c.normalizeVec3(c.mulVec3Scalar(o.worldForward,-1,Ac)))),!i.firstPerson&&i.followPointer&&t.pivotController.setPivotPos(ac),t.cameraFlight.duration>0?t.cameraFlight.flyTo(uc,(()=>{t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(uc),t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class pc{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,A=!1;const h=this._scene.canvas.canvas,u=i=>{let s;i&&i.worldPos&&(s=i.worldPos);const r=i&&i.entity?i.entity.aabb:e.aabb;if(s){const i=e.camera;c.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})},d=e.tickify(this._canvasMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(l||A)return;if(a.hasSubs("rayMove")){const t=c.vec3(),i=c.vec3();c.canvasPosToWorldRay(e.canvas.canvas,e.camera.viewMatrix,e.camera.projMatrix,e.camera.projection,s.pointerCanvasPos,t,i),a.fire("rayMove",{canvasPos:s.pointerCanvasPos,ray:{origin:t,direction:i,canvasPos:s.pointerCanvasPos}},!0)}const r=a.hasSubs("hover"),n=a.hasSubs("hoverEnter"),h=a.hasSubs("hoverOut"),u=a.hasSubs("hoverOff"),d=a.hasSubs("hoverSurface"),p=a.hasSubs("hoverSnapOrSurface");if(r||n||h||u||d||p)if(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=d,o.scheduleSnapOrPick=p,o.update(),o.pickResult){if(o.pickResult.entity){const t=o.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),a.fire("hoverEnter",o.pickResult,!0),this._lastPickedEntityId=t)}a.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&a.fire("hoverSurface",o.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),a.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)});h.addEventListener("mousemove",d),h.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(A=!0);if(1===t.which&&i.active&&i.pointerEnabled&&(s.mouseDownClientX=t.clientX,s.mouseDownClientY=t.clientY,s.mouseDownCursorX=s.pointerCanvasPos[0],s.mouseDownCursorY=s.pointerCanvasPos[1],!i.firstPerson&&i.followPointer&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===t.which))){const t=o.pickResult;t&&t.worldPos?(n.setPivotPos(t.worldPos),n.startPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),n.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(A=!1),n.getPivoting()&&n.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=r=>{if(!i.active||!i.pointerEnabled)return;if(!(1===r.which))return;if(n.hidePivot(),Math.abs(r.clientX-s.mouseDownClientX)>3||Math.abs(r.clientY-s.mouseDownClientY)>3)return;const l=a.hasSubs("picked"),A=a.hasSubs("pickedNothing"),h=a.hasSubs("pickedSurface"),d=a.hasSubs("doublePicked"),p=a.hasSubs("doublePickedSurface"),f=a.hasSubs("doublePickedNothing");if(!(i.doublePickFlyTo||d||p||f))return(l||A||h)&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=h,o.update(),o.pickResult?(a.fire("picked",o.pickResult,!0),o.pickedSurface&&a.fire("pickedSurface",o.pickResult,!0)):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo,o.schedulePickSurface=h,o.update();const e=o.pickResult,r=o.pickedSurface;this._timeout=setTimeout((()=>{e&&e.worldPos?(a.fire("picked",e,!0),r&&(a.fire("pickedSurface",e,!0),!i.firstPerson&&i.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0),this._clicks=0}),i.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo||d||p,o.schedulePickSurface=o.schedulePickEntity&&p,o.update(),o.pickResult){if(a.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&a.fire("doublePickedSurface",o.pickResult,!0),i.doublePickFlyTo&&(u(o.pickResult),!i.firstPerson&&i.followPointer)){const e=o.pickResult.entity.aabb,i=c.getAABB3Center(e);t.pivotController.setPivotPos(i),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(a.fire("doublePickedNothing",{canvasPos:s.pointerCanvasPos},!0),i.doublePickFlyTo&&(u(),!i.firstPerson&&i.followPointer)){const i=e.aabb,s=c.getAABB3Center(i);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class fc{constructor(e,t,i,s,r){this._scene=e;const o=e.input,n=[],a=e.canvas.canvas;let l=!0;this._onSceneMouseMove=o.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=o.on("keydown",(t=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&(i.keyboardEnabledOnlyIfMouseover&&!s.mouseover||(n[t]=!0,t===o.KEY_SHIFT&&(a.style.cursor="move")))})),this._onSceneKeyUp=o.on("keyup",(s=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&(n[s]=!1,s===o.KEY_SHIFT&&(a.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(a=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(i.keyboardEnabledOnlyIfMouseover&&!s.mouseover)return;const A=t.cameraControl,h=a.deltaTime/1e3;if(!i.planView){const e=A._isKeyDownForAction(A.ROTATE_Y_POS,n),s=A._isKeyDownForAction(A.ROTATE_Y_NEG,n),o=A._isKeyDownForAction(A.ROTATE_X_POS,n),a=A._isKeyDownForAction(A.ROTATE_X_NEG,n),l=h*i.keyboardRotationRate;(e||s||o||a)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),e?r.rotateDeltaY+=l:s&&(r.rotateDeltaY-=l),o?r.rotateDeltaX+=l:a&&(r.rotateDeltaX-=l),!i.firstPerson&&i.followPointer&&t.pivotController.startPivot())}if(!n[o.KEY_CTRL]&&!n[o.KEY_ALT]){const e=A._isKeyDownForAction(A.DOLLY_BACKWARDS,n),o=A._isKeyDownForAction(A.DOLLY_FORWARDS,n);if(e||o){const n=h*i.keyboardDollyRate;!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),o?r.dollyDelta-=n:e&&(r.dollyDelta+=n),l&&(s.followPointerDirty=!0,l=!1)}}const c=A._isKeyDownForAction(A.PAN_FORWARDS,n),u=A._isKeyDownForAction(A.PAN_BACKWARDS,n),d=A._isKeyDownForAction(A.PAN_LEFT,n),p=A._isKeyDownForAction(A.PAN_RIGHT,n),f=A._isKeyDownForAction(A.PAN_UP,n),g=A._isKeyDownForAction(A.PAN_DOWN,n),m=(n[o.KEY_ALT]?.3:1)*h*i.keyboardPanRate;(c||u||d||p||f||g)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),g?r.panDeltaY+=m:f&&(r.panDeltaY+=-m),p?r.panDeltaX+=-m:d&&(r.panDeltaX+=m),u?r.panDeltaZ+=m:c&&(r.panDeltaZ+=-m))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const gc=c.vec3();class mc{constructor(e,t,i,s,r){this._scene=e;const o=e.camera,n=t.pickController,a=t.pivotController,l=t.panController;let A=1,h=1,u=null;this._onTick=e.on("tick",(()=>{if(!i.active||!i.pointerEnabled)return;let t="default";if(Math.abs(r.dollyDelta)<.001&&(r.dollyDelta=0),Math.abs(r.rotateDeltaX)<.001&&(r.rotateDeltaX=0),Math.abs(r.rotateDeltaY)<.001&&(r.rotateDeltaY=0),0===r.rotateDeltaX&&0===r.rotateDeltaY||(r.dollyDelta=0),i.followPointer){if(--A<=0&&(A=1,0!==r.dollyDelta)){if(0===r.rotateDeltaY&&0===r.rotateDeltaX&&i.followPointer&&s.followPointerDirty&&(n.pickCursorPos=s.pointerCanvasPos,n.schedulePickSurface=!0,n.update(),n.pickResult&&n.pickResult.worldPos?u=n.pickResult.worldPos:(h=1,u=null),s.followPointerDirty=!1),u){const t=Math.abs(c.lenVec3(c.subVec3(u,e.camera.eye,gc)));h=t/i.dollyProximityThreshold}h{s.mouseover=!0}),o.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{s.mouseover=!1,o.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{vc(e,o,s.pointerCanvasPos)}),o.addEventListener("mousedown",this._mouseDownHandler=e=>{i.active&&i.pointerEnabled&&(vc(e,o,s.pointerCanvasPos),s.mouseover=!0)}),o.addEventListener("mouseup",this._mouseUpHandler=e=>{i.active&&i.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function vc(e,t,i){if(e){const{left:s,top:r}=t.getBoundingClientRect();i[0]=e.clientX-s,i[1]=e.clientY-r}else e=window.event,i[0]=e.x,i[1]=e.y;return i}const bc=function(e,t){if(e){let i=e.target,s=0,r=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;t[0]=e.pageX-s,t[1]=e.pageY-r}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class yc{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=c.vec2(),l=c.vec2(),A=c.vec2(),h=c.vec2(),u=[],d=this._scene.canvas.canvas;let p=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),d.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!i.active||!i.pointerEnabled)return;t.preventDefault();const r=t.touches,l=t.changedTouches;for(s.touchStartTime=Date.now(),1===r.length&&1===l.length&&(bc(r[0],a),i.followPointer&&(o.pickCursorPos=a,o.schedulePickSurface=!0,o.update(),i.planView||(o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(n.setPivotPos(o.pickResult.worldPos),!i.firstPerson&&n.startPivot()&&n.showPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),!i.firstPerson&&n.startPivot()&&n.showPivot()))));u.length{n.getPivoting()&&n.endPivot()}),d.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const n=e.canvas.boundary,a=n[2],d=n[3],g=t.touches;if(t.touches.length===p){if(1===p){bc(g[0],l),c.subVec2(l,u[0],h);const t=h[0],o=h[1];if(null!==s.longTouchTimeout&&(Math.abs(t)>i.longTapRadius||Math.abs(o)>i.longTapRadius)&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),i.planView){const s=e.camera;if("perspective"===s.projection){const n=Math.abs(e.camera.eyeLookDist)*Math.tan(s.perspective.fov/2*Math.PI/180);r.panDeltaX+=t*n/d*i.touchPanRate,r.panDeltaY+=o*n/d*i.touchPanRate}else r.panDeltaX+=.5*s.ortho.scale*(t/d)*i.touchPanRate,r.panDeltaY+=.5*s.ortho.scale*(o/d)*i.touchPanRate}else r.rotateDeltaY-=t/a*(1*i.dragRotationRate),r.rotateDeltaX+=o/d*(1.5*i.dragRotationRate)}else if(2===p){const t=g[0],n=g[1];bc(t,l),bc(n,A);const a=c.geometricMeanVec2(u[0],u[1]),h=c.geometricMeanVec2(l,A),p=c.vec2();c.subVec2(a,h,p);const f=p[0],m=p[1],_=e.camera,v=c.distVec2([t.pageX,t.pageY],[n.pageX,n.pageY]),b=(c.distVec2(u[0],u[1])-v)*i.touchDollyRate;if(r.dollyDelta=b,Math.abs(b)<1)if("perspective"===_.projection){const t=o.pickResult?o.pickResult.worldPos:e.center,s=Math.abs(c.lenVec3(c.subVec3(t,e.camera.eye,[])))*Math.tan(_.perspective.fov/2*Math.PI/180);r.panDeltaX-=f*s/d*i.touchPanRate,r.panDeltaY-=m*s/d*i.touchPanRate}else r.panDeltaX-=.5*_.ortho.scale*(f/d)*i.touchPanRate,r.panDeltaY-=.5*_.ortho.scale*(m/d)*i.touchPanRate;s.pointerCanvasPos=h}for(let e=0;e{let s;i&&i.worldPos&&(s=i.worldPos);const r=i?i.entity.aabb:e.aabb;if(s){const i=e.camera;c.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})};d.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!i.active||!i.pointerEnabled)return;null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null);const r=e.touches,o=e.changedTouches;if(a=Date.now(),1===r.length&&1===o.length){h=a,xc(r[0],A);const o=A[0],n=A[1],l=r[0].pageX,c=r[0].pageY;s.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(c)],canvasPos:[Math.round(o),Math.round(n)],event:e},!0),s.longTouchTimeout=null}),i.longTapTimeout)}else h=-1;for(;l.length{if(!i.active||!i.pointerEnabled)return;const t=Date.now(),r=e.touches,a=e.changedTouches,d=n.hasSubs("pickedSurface");null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),0===r.length&&1===a.length&&h>-1&&t-h<150&&(u>-1&&h-u<325?(xc(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=d,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("doublePicked",o.pickResult),o.pickedSurface&&n.fire("doublePickedSurface",o.pickResult),i.doublePickFlyTo&&p(o.pickResult)):(n.fire("doublePickedNothing"),i.doublePickFlyTo&&p()),u=-1):c.distVec2(l[0],A)<4&&(xc(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=d,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("picked",o.pickResult),o.pickedSurface&&n.fire("pickedSurface",o.pickResult)):n.fire("pickedNothing"),u=t),h=-1),l.length=r.length;for(let e=0,t=r.length;e{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,keyboardEnabledOnlyIfMouseover:!0,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:c.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:c.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const i=this.scene;this._controllers={cameraControl:this,pickController:new rc(this,this._configs),pivotController:new sc(i,this._configs),panController:new Yh(i),cameraFlight:new Mh(this,{duration:.5})},this._handlers=[new _c(this.scene,this._controllers,this._configs,this._states,this._updates),new yc(this.scene,this._controllers,this._configs,this._states,this._updates),new nc(this.scene,this._controllers,this._configs,this._states,this._updates),new dc(this.scene,this._controllers,this._configs,this._states,this._updates),new pc(this.scene,this._controllers,this._configs,this._states,this._updates),new Bc(this.scene,this._controllers,this._configs,this._states,this._updates),new fc(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new mc(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",_.isString(e)){const t=this.scene.input,i={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":i[this.PAN_LEFT]=[t.KEY_A],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_Z],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":i[this.PAN_LEFT]=[t.KEY_Q],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_W],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=i}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const i=this._keyMap[e];if(!i)return!1;t||(t=this.scene.input.keyDown);for(let e=0,s=i.length;e0&&console.error(`[MetaModel._decompressProperties] Properties not found: ${i}`)}finalize(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";const e=this.metaScene;for(let t in e.metaObjects){const i=e.metaObjects[t];if(i.children&&(i.children=[]),i.propertySets&&(i.propertySets=[]),i.propertySetIds)for(let t=0,s=i.propertySetIds.length;t0?Ic(t):null,n=i&&i.length>0?Ic(i):null,a=e=>{if(!e)return;var t=!0;(n&&n[e.type]||o&&!o[e.type])&&(t=!1),t&&s.push(e.id);const i=e.children;if(i)for(var r=0,l=i.length;r * Copyright (c) 2022 Niklas von Hertzen diff --git a/dist/xeokit-sdk.min.es.js b/dist/xeokit-sdk.min.es.js index 79d9f8f16..8f9eeb0d6 100644 --- a/dist/xeokit-sdk.min.es.js +++ b/dist/xeokit-sdk.min.es.js @@ -14,7 +14,7 @@ class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){ /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT - **/let lc=null;function Ac(e,t){const i=3*e,s=3*t;let r,o,n,a,l,A;const h=Math.min(r=lc[i],o=lc[i+1],n=lc[i+2]),c=Math.min(a=lc[s],l=lc[s+1],A=lc[s+2]);if(h!==c)return h-c;const u=Math.max(r,o,n),d=Math.max(a,l,A);return u!==d?u-d:0}let hc=null;function cc(e,t){let i=hc[2*e]-hc[2*t];return 0!==i?i:hc[2*e+1]-hc[2*t+1]}function uc(e,t,i=!1){const s=e.positionsCompressed||[],r=function(e,t){const i=new Int32Array(e.length/3);for(let e=0,t=i.length;e>t;i.sort(Ac);const s=new Int32Array(e.length);for(let t=0,r=i.length;te[t+1]){let i=e[t];e[t]=e[t+1],e[t+1]=i}hc=new Int32Array(e),t.sort(cc);const i=new Int32Array(e.length);for(let s=0,r=t.length;st){let i=e;e=t,t=i}function i(i,s){return i!==e?e-i:s!==t?t-s:0}let s=0,r=(o.length>>1)-1;for(;s<=r;){const e=r+s>>1,t=i(o[2*e],o[2*e+1]);if(t>0)s=e+1;else{if(!(t<0))return e;r=e-1}}return-s-1}const a=new Int32Array(o.length/2);a.fill(0);const l=s.length/3;if(l>8*(1<u.maxNumPositions&&(u=c()),u.bucketNumber>8)return[e];let p;-1===A[l]&&(A[l]=u.numPositions++,u.positionsCompressed.push(s[3*l]),u.positionsCompressed.push(s[3*l+1]),u.positionsCompressed.push(s[3*l+2])),-1===A[h]&&(A[h]=u.numPositions++,u.positionsCompressed.push(s[3*h]),u.positionsCompressed.push(s[3*h+1]),u.positionsCompressed.push(s[3*h+2])),-1===A[d]&&(A[d]=u.numPositions++,u.positionsCompressed.push(s[3*d]),u.positionsCompressed.push(s[3*d+1]),u.positionsCompressed.push(s[3*d+2])),u.indices.push(A[l]),u.indices.push(A[h]),u.indices.push(A[d]),(p=n(l,h))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(l,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(h,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]]))}const d=t/8*2,p=t/8,f=2*s.length+(r.length+o.length)*d;let g=0,m=-s.length/3;return h.forEach((e=>{g+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*p,m+=e.positionsCompressed.length/3})),g>f?[e]:(i&&function(e,t){const i={},s={};let r=0;e.forEach((e=>{const t=e.indices,o=e.edgeIndices,n=e.positionsCompressed;for(let e=0,s=t.length;e0){const e=t._meshes;for(let t=0,i=e.length;t0){const e=this._meshes;for(let t=0,i=e.length;t{this._viewMatrixDirty=!0})),this._meshesWithDirtyMatrices=[],this._numMeshesWithDirtyMatrices=0,this._onTick=this.scene.on("tick",(()=>{for(;this._numMeshesWithDirtyMatrices>0;)this._meshesWithDirtyMatrices[--this._numMeshesWithDirtyMatrices]._updateMatrix()})),this._createDefaultTextureSet(),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.backfaces=t.backfaces}_meshMatrixDirty(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}_createDefaultTextureSet(){const e=new Wh({id:"defaultColorTexture",texture:new Yr({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Wh({id:"defaultMetalRoughTexture",texture:new Yr({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),i=new Wh({id:"defaultNormalsTexture",texture:new Yr({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),s=new Wh({id:"defaultEmissiveTexture",texture:new Yr({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),r=new Wh({id:"defaultOcclusionTexture",texture:new Yr({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=i,this._textures.defaultEmissiveTexture=s,this._textures.defaultOcclusionTexture=r,this._textureSets.defaultTextureSet=new zh({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:i,emissiveTexture:s,occlusionTexture:r})}get isPerformanceModel(){return!0}get transforms(){return this._transforms}get textures(){return this._textures}get textureSets(){return this._textureSets}get meshes(){return this._meshes}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),d.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),d.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||Mc),d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),d.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),d.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),d.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),d.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0,this._aabbDirty=!0}_transformDirty(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}_sceneModelDirty(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(let e=0,t=this._entityList.length;e0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,i=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,i=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,i=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,i=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,i=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,i=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,i=new Uint8Array(t.length);for(let e=0,s=t.length;e{l.setImage(A,{minFilter:i,magFilter:s,wrapS:r,wrapT:o,wrapR:n,flipY:e.flipY,encoding:a}),this.glRedraw()},A.src=e.src;break;default:this._textureTranscoder?y.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new Wh({id:t,texture:l})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let i,s,r,o,n;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(i=this._textures[e.colorTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(s=this._textures[e.metallicRoughnessTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(r=this._textures[e.normalsTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(o=this._textures[e.emissiveTextureId],!o)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else o=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(n=this._textures[e.occlusionTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultOcclusionTexture;const a=new zh({id:t,model:this,colorTexture:i,metallicRoughnessTexture:s,normalsTexture:r,emissiveTexture:o,occlusionTexture:n});return this._textureSets[t]=a,a}createTransform(e){if(void 0===e.id||null===e.id)return void this.error("[createTransform] SceneModel.createTransform() config missing: id");if(this._transforms[e.id])return void this.error(`[createTransform] SceneModel already has a transform with this ID: ${e.id}`);let t;if(e.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const i=new bc({id:e.id,model:this,parent:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[i.id]=i,i}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._meshes[e.id])return this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`),!1;if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!(e.buckets||e.indices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)){const t=(e.positions||e.positionsCompressed).length/3;e.indices=this._createDefaultIndices(t)}if(!e.buckets&&!e.indices&&"points"!==e.primitive)return e.indices=this._createDefaultIndices(numIndices),this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;const t=!(!this._dtxEnabled||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||e.textureSetId);if(e.origin=e.origin?d.addVec3(this._origin,e.origin,d.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position||e.quaternion){const t=e.scale||xc,i=e.position||Pc;e.rotation?(d.eulerToQuaternion(e.rotation,"XYZ",wc),e.meshMatrix=d.composeMat4(i,wc,t,d.mat4())):e.meshMatrix=d.composeMat4(i,e.quaternion||Cc,t,d.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=bn(e.positionsDecodeBoundary,d.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):Ec,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=d.vec3(),i=[];Z(e.positions,i,t)&&(e.positions=i,e.origin=d.addVec3(e.origin,t,t))}if(e.positions){const t=d.collapseAABB3();e.positionsDecodeMatrix=d.mat4(),d.expandAABB3Points3(t,e.positions),e.positionsCompressed=vn(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=d.collapseAABB3();d.expandAABB3Points3(t,e.positionsCompressed),Yt.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=d.collapseAABB3();for(let i=0,s=e.buckets.length;i>24&255,r=i>>16&255,o=i>>8&255,n=255&i;switch(e.pickColor=new Uint8Array([n,o,r,s]),e.solid="solid"===e.primitive,t.origin=d.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),this._meshes[e.id]=t,this._unusedMeshes[e.id]=t,this._meshList.push(t),t}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let i=0,s=e.buckets.length;i>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,i=e.origin,s=e.textureSetId||"-",r=e.geometryId,o=`${Math.round(i[0])}.${Math.round(i[1])}.${Math.round(i[2])}.${s}.${r}`;let n=this._vboInstancingLayers[o];if(n)return n;let a=e.textureSet;const l=e.geometry;for(;!n;)switch(l.primitive){case"triangles":case"surface":n=new xa({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!1});break;case"solid":n=new xa({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!0});break;case"lines":n=new Al({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0});break;case"points":n=new iA({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0})}return this._vboInstancingLayers[o]=n,this.layerList.push(n),n}createEntity(e){if(void 0===e.id?e.id=d.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=d.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;this._visible&&!1!==e.visible&&(t|=ee),this._pickable&&!1!==e.pickable&&(t|=ie),this._culled&&!1!==e.culled&&(t|=te),this._clippable&&!1!==e.clippable&&(t|=se),this._collidable&&!1!==e.collidable&&(t|=re),this._edges&&!1!==e.edges&&(t|=le),this._xrayed&&!1!==e.xrayed&&(t|=oe),this._highlighted&&!1!==e.highlighted&&(t|=ne),this._selected&&!1!==e.selected&&(t|=ae),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let i=0,s=e.meshIds.length;ie.sortIdt.sortId?1:0));for(let e=0,t=this.layerList.length;e0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,i=this.layerList.length;t0){const t=`${this.id}-dummyEntityForUnusedMeshes`;this.warn(`Creating dummy SceneModelEntity "${t}" for unused SceneMeshes: [${e.join(",")}]`),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}_getActiveSectionPlanesForLayer(e){const t=this.renderFlags,i=this.scene._sectionPlanesState.sectionPlanes,s=i.length,r=e.layerIndex*s;if(s>0)for(let e=0;e0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}drawColorOpaque(e,t){const i=this.renderFlags;for(let t=0,s=i.visibleLayers.length;t65536?16:8)}else n=[{positionsCompressed:s,indices:r,edgeIndices:o}];return n}class Dc extends L{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;ep.has(e.id)||g.has(e.id)||f.has(e.id))).reduce(((e,i)=>{let s,r=function(e){let t="";return t+=Math.round(255*e[0]).toString(16).padStart(2,"0"),t+=Math.round(255*e[1]).toString(16).padStart(2,"0"),t+=Math.round(255*e[2]).toString(16).padStart(2,"0"),t}(i.colorize);i.xrayed?(s=0===t.xrayMaterial.fillAlpha&&0!==t.xrayMaterial.edgeAlpha?.1:t.xrayMaterial.fillAlpha,s=Math.round(255*s).toString(16).padStart(2,"0"),r=s+r):p.has(i.id)&&(s=Math.round(255*i.opacity).toString(16).padStart(2,"0"),r=s+r),e[r]||(e[r]=[]);const o=i.id,n=i.originalSystemId,a={ifc_guid:n,originating_system:this.originatingSystem};return n!==o&&(a.authoring_tool_id=o),e[r].push(a),e}),{}),_=Object.entries(m).map((([e,t])=>({color:e,components:t})));o.components.coloring=_;const v=t.objectIds,b=t.visibleObjects,y=t.visibleObjectIds,B=v.filter((e=>!b[e])),w=t.selectedObjectIds;return e.defaultInvisible||y.length0&&e.clipping_planes.forEach((function(e){let t=Oc(e.location,Sc),i=Oc(e.direction,Sc);A&&d.negateVec3(i),d.subVec3(t,l),r.yUp&&(t=Qc(t),i=Qc(i)),new Ir(s,{pos:t,dir:i})})),s.clearLines(),e.lines&&e.lines.length>0){const t=[],i=[];let r=0;e.lines.forEach((e=>{e.start_point&&e.end_point&&(t.push(e.start_point.x),t.push(e.start_point.y),t.push(e.start_point.z),t.push(e.end_point.x),t.push(e.end_point.y),t.push(e.end_point.z),i.push(r++),i.push(r++))})),new Dc(s,{positions:t,indices:i,clippable:!1,collidable:!0})}if(s.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){const t=e.bitmap_type||"jpg",i=e.bitmap_data;let o=Oc(e.location,Tc),n=Oc(e.normal,Lc),a=Oc(e.up,Rc),l=e.height||1;t&&i&&o&&n&&a&&(r.yUp&&(o=Qc(o),n=Qc(n),a=Qc(a)),new vo(s,{src:i,type:t,pos:o,normal:n,up:a,clippable:!1,collidable:!0,height:l}))})),a&&(s.setObjectsXRayed(s.xrayedObjectIds,!1),s.setObjectsHighlighted(s.highlightedObjectIds,!1),s.setObjectsSelected(s.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(s.setObjectsVisible(s.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!1))))):(s.setObjectsVisible(s.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!0)))));const r=e.components.visibility.view_setup_hints;r&&(!1===r.spaces_visible&&s.setObjectsVisible(i.metaScene.getObjectIDsByType("IfcSpace"),!1),void 0!==r.spaces_translucent&&s.setObjectsXRayed(i.metaScene.getObjectIDsByType("IfcSpace"),!0),r.space_boundaries_visible,!1===r.openings_visible&&s.setObjectsVisible(i.metaScene.getObjectIDsByType("IfcOpening"),!0),r.space_boundaries_translucent,void 0!==r.openings_translucent&&s.setObjectsXRayed(i.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(s.setObjectsSelected(s.selectedObjectIds,!1),e.components.selection.forEach((e=>this._withBCFComponent(t,e,(e=>e.selected=!0))))),e.components.translucency&&(s.setObjectsXRayed(s.xrayedObjectIds,!1),e.components.translucency.forEach((e=>this._withBCFComponent(t,e,(e=>e.xrayed=!0))))),e.components.coloring&&e.components.coloring.forEach((e=>{let i=e.color,s=0,r=!1;8===i.length&&(s=parseInt(i.substring(0,2),16)/256,s<=1&&s>=.95&&(s=1),i=i.substring(2),r=!0);const o=[parseInt(i.substring(0,2),16)/256,parseInt(i.substring(2,4),16)/256,parseInt(i.substring(4,6),16)/256];e.components.map((e=>this._withBCFComponent(t,e,(e=>{e.colorize=o,r&&(e.opacity=s)}))))}))}if(e.perspective_camera||e.orthogonal_camera){let a,A,h,c;if(e.perspective_camera?(a=Oc(e.perspective_camera.camera_view_point,Sc),A=Oc(e.perspective_camera.camera_direction,Sc),h=Oc(e.perspective_camera.camera_up_vector,Sc),r.perspective.fov=e.perspective_camera.field_of_view,c="perspective"):(a=Oc(e.orthogonal_camera.camera_view_point,Sc),A=Oc(e.orthogonal_camera.camera_direction,Sc),h=Oc(e.orthogonal_camera.camera_up_vector,Sc),r.ortho.scale=e.orthogonal_camera.view_to_world_scale,c="ortho"),d.subVec3(a,l),r.yUp&&(a=Qc(a),A=Qc(A),h=Qc(h)),o){const e=s.pick({pickSurface:!0,origin:a,direction:A});A=e?e.worldPos:d.addVec3(a,A,Sc)}else A=d.addVec3(a,A,Sc);n?(r.eye=a,r.look=A,r.up=h,r.projection=c):i.cameraFlight.flyTo({eye:a,look:A,up:h,duration:t.duration,projection:c})}}_withBCFComponent(e,t,i){const s=this.viewer,r=s.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){const o=t.authoring_tool_id,n=r.objects[o];if(n)return void i(n);if(e.updateCompositeObjects){if(s.metaScene.metaObjects[o])return void r.withObjects(s.metaScene.getObjectIDsInSubtree(o),i)}}if(t.ifc_guid){const o=t.ifc_guid,n=r.objects[o];if(n)return void i(n);if(e.updateCompositeObjects){if(s.metaScene.metaObjects[o])return void r.withObjects(s.metaScene.getObjectIDsInSubtree(o),i)}Object.keys(r.models).forEach((t=>{const n=d.globalizeObjectId(t,o),a=r.objects[n];if(a)i(a);else if(e.updateCompositeObjects){s.metaScene.metaObjects[n]&&r.withObjects(s.metaScene.getObjectIDsInSubtree(n),i)}}))}}destroy(){super.destroy()}}function kc(e){return{x:e[0],y:e[1],z:e[2]}}function Oc(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function Nc(e){return new Float64Array([e[0],-e[2],e[1]])}function Qc(e){return new Float64Array([e[0],e[2],-e[1]])}const Vc=d.vec3(),Hc=(e,t,i,s)=>{var r=e-i,o=t-s;return Math.sqrt(r*r+o*o)};class jc extends L{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._eventSubs={};var i=this.plugin.viewer.scene;this._originWorld=d.vec3(),this._targetWorld=d.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;const s=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,r=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},n=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,A=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new me(i,t.origin,this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._targetDot=new me(i,t.target,this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthWire=new be(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisWire=new be(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisWire=new be(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisWire=new be(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthLabel=new ye(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisLabel=new ye(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisLabel=new ye(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisLabel=new ye(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._measurementOrientation="Horizontal",this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._sectionPlanesDirty=!0,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,this._xLabelEnabled=!1,this._yLabelEnabled=!1,this._zLabelEnabled=!1,this._lengthLabelEnabled=!1,this._labelsVisible=!1,this._labelsOnWires=!1,this._clickable=!1,this._originDot.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetDot.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=i.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=i.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=i.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=i.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=i.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=i.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=i.on("sectionPlaneUpdated",(()=>{this._sectionPlanesDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.xLabelEnabled=t.xLabelEnabled,this.yLabelEnabled=t.yLabelEnabled,this.zLabelEnabled=t.zLabelEnabled,this.lengthLabelEnabled=t.lengthLabelEnabled,this.labelsVisible=t.labelsVisible,this.labelsOnWires=t.labelsOnWires,this.useRotationAdjustment=t.useRotationAdjustment}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._measurementOrientation=function(e,t,i){return Math.abs(t[1]-e[1])>i?"Vertical":"Horizontal"}(this._originWorld,this._targetWorld,0),"Vertical"===this._measurementOrientation&&this.useRotationAdjustment?(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._originWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._originWorld[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._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1),this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(d.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._originWorld)||this._isSliced(this._targetWorld))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}const t=this._originDot.viewPos[2],i=this._targetDot.viewPos[2];if(t>-.3||i>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){d.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var s=this._pp,r=this._cp,o=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var n=o.top-t.top,a=o.left-t.left,l=e.canvas.boundary,A=l[2],h=l[3],c=0;const i=this.plugin.viewer.scene.metrics,f=i.scale,g=i.units,m=i.unitsInfo[g].abbrev;for(var u=0,p=s.length;ue.offsetTop+(e.offsetParent&&e.offsetParent!==s.parentNode&&h(e.offsetParent)),c=e=>e.offsetLeft+(e.offsetParent&&e.offsetParent!==s.parentNode&&c(e.offsetParent)),u=d.vec2();this._onCameraControlHoverSnapOrSurface=i.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(e=>{const t=e.snappedCanvasPos||e.canvasPos;r=!0,o.set(e.worldPos),n.set(e.canvasPos),0===this._mouseState?(this._canvasToPagePos?(this._canvasToPagePos(s,t,u),this._markerDiv.style.left=u[0]-5+"px",this._markerDiv.style.top=u[1]-5+"px"):(this._markerDiv.style.left=c(s)+t[0]-5+"px",this._markerDiv.style.top=h(s)+t[1]-5+"px"),this._markerDiv.style.background="pink",e.snappedToVertex||e.snappedToEdge?(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos,this.pointerLens.snapped=!0),this._markerDiv.style.background="greenyellow",this._markerDiv.style.border="2px solid green"):(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.canvasPos,this.pointerLens.snapped=!1),this._markerDiv.style.background="pink",this._markerDiv.style.border="2px solid red"),A=e.entity):(this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px"),s.style.cursor="pointer",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=this._currentDistanceMeasurementInitState.wireVisible,this._currentDistanceMeasurement.axisVisible=this._currentDistanceMeasurementInitState.axisVisible&&this.distanceMeasurementsPlugin.defaultAxisVisible,this._currentDistanceMeasurement.xAxisVisible=this._currentDistanceMeasurementInitState.xAxisVisible&&this.distanceMeasurementsPlugin.defaultXAxisVisible,this._currentDistanceMeasurement.yAxisVisible=this._currentDistanceMeasurementInitState.yAxisVisible&&this.distanceMeasurementsPlugin.defaultYAxisVisible,this._currentDistanceMeasurement.zAxisVisible=this._currentDistanceMeasurementInitState.zAxisVisible&&this.distanceMeasurementsPlugin.defaultZAxisVisible,this._currentDistanceMeasurement.targetVisible=this._currentDistanceMeasurementInitState.targetVisible,this._currentDistanceMeasurement.target.worldPos=o.slice(),this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px")})),s.addEventListener("mousedown",this._onMouseDown=e=>{1===e.which&&(a=e.clientX,l=e.clientY)}),s.addEventListener("mouseup",this._onMouseUp=t=>{1===t.which&&(t.clientX>a+20||t.clientXl+20||t.clientY{this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos),r=!1,this._markerDiv.style.left="-100px",this._markerDiv.style.top="-100px",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.axisVisible=!1),s.style.cursor="default"})),this._active=!0}deactivate(){if(!this._active)return;this.fire("activated",!1),this.pointerLens&&(this.pointerLens.visible=!1);const e=this.scene.canvas.canvas;e.removeEventListener("mousedown",this._onMouseDown),e.removeEventListener("mouseup",this._onMouseUp);const t=this.distanceMeasurementsPlugin.viewer.cameraControl;t.off(this._onCameraControlHoverSnapOrSurface),t.off(this._onCameraControlHoverSnapOrSurfaceOff),this._active=!1}reset(){this._active&&(this._destroyMarkerDiv(),this._initMarkerDiv(),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null),this._mouseState=0)}get currentMeasurement(){return this._currentDistanceMeasurement}destroy(){this.deactivate(),super.destroy()}}class Wc extends z{constructor(e,t={}){super("DistanceMeasurements",e),this._pointerLens=t.pointerLens,this._container=t.container||document.body,this._defaultControl=null,this._measurements={},this.labelMinAxisLength=t.labelMinAxisLength,this.defaultVisible=!1!==t.defaultVisible,this.defaultOriginVisible=!1!==t.defaultOriginVisible,this.defaultTargetVisible=!1!==t.defaultTargetVisible,this.defaultWireVisible=!1!==t.defaultWireVisible,this.defaultXLabelEnabled=!1!==t.defaultXLabelEnabled,this.defaultYLabelEnabled=!1!==t.defaultYLabelEnabled,this.defaultZLabelEnabled=!1!==t.defaultZLabelEnabled,this.defaultLengthLabelEnabled=!1!==t.defaultLengthLabelEnabled,this.defaultLabelsVisible=!1!==t.defaultLabelsVisible,this.defaultAxisVisible=!1!==t.defaultAxisVisible,this.defaultXAxisVisible=!1!==t.defaultXAxisVisible,this.defaultYAxisVisible=!1!==t.defaultYAxisVisible,this.defaultZAxisVisible=!1!==t.defaultZAxisVisible,this.defaultColor=void 0!==t.defaultColor?t.defaultColor:"#00BBFF",this.zIndex=t.zIndex||1e4,this.defaultLabelsOnWires=!1!==t.defaultLabelsOnWires,this.useRotationAdjustment=void 0!==t.useRotationAdjustment&&!1!==t.useRotationAdjustment,this._onMouseOver=(e,t)=>{this.fire("mouseOver",{plugin:this,distanceMeasurement:t,measurement:t,event:e})},this._onMouseLeave=(e,t)=>{this.fire("mouseLeave",{plugin:this,distanceMeasurement:t,measurement:t,event:e})},this._onContextMenu=(e,t)=>{this.fire("contextMenu",{plugin:this,distanceMeasurement:t,measurement:t,event:e})}}getContainerElement(){return this._container}send(e,t){}get pointerLens(){return this._pointerLens}get control(){return this._defaultControl||(this._defaultControl=new zc(this,{})),this._defaultControl}get measurements(){return this._measurements}set labelMinAxisLength(e){e<1&&(this.error("labelMinAxisLength must be >= 1; defaulting to 25"),e=25),this._labelMinAxisLength=e||25}get labelMinAxisLength(){return this._labelMinAxisLength}set useRotationAdjustment(e){e=void 0!==e&&Boolean(e),this._useRotationAdjustment=e}get useRotationAdjustment(){return this._useRotationAdjustment}createMeasurement(e={}){this.viewer.scene.components[e.id]&&(this.error("Viewer scene component with this ID already exists: "+e.id),delete e.id);const t=e.origin,i=e.target,s=new jc(this,{id:e.id,plugin:this,container:this._container,origin:{entity:t.entity,worldPos:t.worldPos},target:{entity:i.entity,worldPos:i.worldPos},visible:e.visible,wireVisible:e.wireVisible,axisVisible:!1!==e.axisVisible&&!1!==this.defaultAxisVisible,xAxisVisible:!1!==e.xAxisVisible&&!1!==this.defaultXAxisVisible,yAxisVisible:!1!==e.yAxisVisible&&!1!==this.defaultYAxisVisible,zAxisVisible:!1!==e.zAxisVisible&&!1!==this.defaultZAxisVisible,xLabelEnabled:!1!==e.xLabelEnabled&&!1!==this.defaultXLabelEnabled,yLabelEnabled:!1!==e.yLabelEnabled&&!1!==this.defaultYLabelEnabled,zLabelEnabled:!1!==e.zLabelEnabled&&!1!==this.defaultZLabelEnabled,lengthLabelEnabled:!1!==e.lengthLabelEnabled&&!1!==this.defaultLengthLabelEnabled,labelsVisible:!1!==e.labelsVisible&&!1!==this.defaultLabelsVisible,useRotationAdjustment:this.useRotationAdjustment,originVisible:e.originVisible,targetVisible:e.targetVisible,color:e.color,labelsOnWires:!1!==e.labelsOnWires&&!1!==this.defaultLabelsOnWires,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[s.id]=s,s.clickable=!0,s.on("destroyed",(()=>{delete this._measurements[s.id]})),this.fire("measurementCreated",s),s}destroyMeasurement(e){const t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("DistanceMeasurement not found: "+e)}setLabelsShown(e){for(const[t,i]of Object.entries(this.measurements))i.labelShown=e}setAxisVisible(e){for(const[t,i]of Object.entries(this.measurements))i.axisVisible=e;this.defaultAxisVisible=e}getAxisVisible(){return this.defaultAxisVisible}clear(){const e=Object.keys(this._measurements);for(var t=0,i=e.length;t{this.plugin.viewer.cameraControl.active=!1},c=()=>{this.plugin.viewer.cameraControl.active=!0},u=()=>{o&&(clearTimeout(o),o=null),this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null),c(),this._touchState=0};i.addEventListener("touchstart",this._onCanvasTouchStart=i=>{const l=i.touches.length;if(1!==l)return void(o&&(clearTimeout(o),o=null));const c=i.touches[0],p=c.clientX,f=c.clientY;switch(n.set([p,f]),a.set([p,f]),this._touchState){case 0:if(1!==l&&null!==o)return void u();const i=t.pick({canvasPos:a,snapping:this._snapping,snapToEdge:this._snapping});if(i&&i.snapped)s.set(i.worldPos),this.pointerCircle.start(i.snappedCanvasPos);else{const e=t.pick({canvasPos:a,pickSurface:!0});if(!e||!e.worldPos)return;s.set(e.worldPos),this.pointerCircle.start(e.canvasPos)}o=setTimeout((()=>{1!==l||a[0]>n[0]+r||a[0]n[1]+r||a[1]{if(o=null,1!==l||a[0]>n[0]+r||a[0]n[1]+r||a[1]{this.pointerCircle.stop();const r=i.touches.length;if(1!==r||1!==i.changedTouches.length)return void(o&&(clearTimeout(o),o=null));const n=i.touches[0],l=n.clientX,h=n.clientY;if(n.identifier!==A)return;let c,u;switch(a.set([l,h]),this._touchState){case 2:this.pointerLens&&(this.pointerLens.canvasPos=a),c=t.pick({canvasPos:a,snapToVertex:this._snapping,snapToEdge:this._snapping}),c&&c.snapped?(this.pointerLens&&(this.pointerLens.snappedCanvasPos=c.snappedCanvasPos,this.pointerLens.snapped=!0),s.set(c.worldPos),this._currentDistanceMeasurement?this._currentDistanceMeasurement.origin.worldPos=c.worldPos:(this._currentDistanceMeasurement=e.createMeasurement({id:d.createUUID(),origin:{worldPos:c.worldPos,entity:c.entity},target:{worldPos:c.worldPos,entity:c.entity}}),this._currentDistanceMeasurement.labelsVisible=!1,this._currentDistanceMeasurement.xAxisVisible=!1,this._currentDistanceMeasurement.yAxisVisible=!1,this._currentDistanceMeasurement.zAxisVisible=!1,this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.originVisible=!0,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.clickable=!1),this.distanceMeasurementsPlugin.fire("measurementStart",this._currentDistanceMeasurement)):(u=t.pick({canvasPos:a,pickSurface:!0}),u&&u.worldPos?(this.pointerLens&&(this.pointerLens.cursorPos=u.canvasPos,this.pointerLens.snapped=!1),s.set(u.worldPos),this._currentDistanceMeasurement?this._currentDistanceMeasurement.origin.worldPos=u.worldPos:(this._currentDistanceMeasurement=e.createMeasurement({id:d.createUUID(),origin:{worldPos:u.worldPos,entity:u.entity},target:{worldPos:u.worldPos,entity:u.entity}}),this._currentDistanceMeasurement.labelsVisible=!1,this._currentDistanceMeasurement.xAxisVisible=!1,this._currentDistanceMeasurement.yAxisVisible=!1,this._currentDistanceMeasurement.zAxisVisible=!1,this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.originVisible=!0,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.clickable=!1),this.distanceMeasurementsPlugin.fire("measurementStart",this._currentDistanceMeasurement)):this.pointerLens&&(this.pointerLens.cursorPos=null,this.pointerLens.snapped=!1)),this._touchState=2;break;case 5:if(1!==r&&null!==o)return clearTimeout(o),o=null,this.pointerLens&&(this.pointerLens.visible=!1),void(this._touchState=7);this.pointerLens&&(this.pointerLens.canvasPos=a),c=t.pick({canvasPos:a,snapToVertex:this._snapping,snapToEdge:this._snapping}),c&&c.worldPos?(this.pointerLens&&(this.pointerLens.cursorPos=c.snappedCanvasPos,this.pointerLens.snapped=!0),this._currentDistanceMeasurement.target.worldPos=c.worldPos,this._currentDistanceMeasurement.target.entity=c.entity,this._currentDistanceMeasurement.targetVisible=!0,this._currentDistanceMeasurement.wireVisible=!0,this._currentDistanceMeasurement.labelsVisible=!0):(u=t.pick({canvasPos:a,pickSurface:!0}),u&&u.worldPos&&(this.pointerLens&&(this.pointerLens.cursorPos=u.canvasPos,this.pointerLens.snapped=!1),this._currentDistanceMeasurement.target.worldPos=u.worldPos,this._currentDistanceMeasurement.target.entity=u.entity,this._currentDistanceMeasurement.targetVisible=!0,this._currentDistanceMeasurement.wireVisible=!0,this._currentDistanceMeasurement.labelsVisible=!0)),this._touchState=5}}),{passive:!0}),i.addEventListener("touchend",this._onCanvasTouchEnd=i=>{this.pointerCircle.stop();const s=i.changedTouches.length;if(1!==s)return;const h=i.changedTouches[0],u=h.clientX,p=h.clientY;if(h.identifier===A)switch(o&&(clearTimeout(o),o=null),l.set([u,p]),this._touchState){case 1:{if(1!==s||u>n[0]+r||un[1]+r||pn[0]+r||un[1]+r||p{const o=e=>{const t=r.scene.pick({canvasPos:s,snapToEdge:e,snapToVertex:e,pickSurface:!0});return t&&t.worldPos?t.worldPos:e&&o(!1)};return o(!!t.snapping)},onEnd:(e,t)=>{const i=!d.compareVec3(e,t.worldPos);return i&&this.fire("edited"),i}}),n=e.on("destroyed",o);this._deactivate=function(){e.off("destroyed",n),o()}}deactivate(){this._deactivate(),super.destroy()}}class Jc extends Xc{constructor(e,t){super(e,t,!0,!1)}}class Yc extends Xc{constructor(e,t){super(e,t,!1,!0)}}class Zc extends z{constructor(e,t={}){super("FastNav",e),this._hideColorTexture=!1!==t.hideColorTexture,this._hidePBR=!1!==t.hidePBR,this._hideSAO=!1!==t.hideSAO,this._hideEdges=!1!==t.hideEdges,this._hideTransparentObjects=!!t.hideTransparentObjects,this._scaleCanvasResolution=!!t.scaleCanvasResolution,this._defaultScaleCanvasResolutionFactor=t.defaultScaleCanvasResolutionFactor||1,this._scaleCanvasResolutionFactor=t.scaleCanvasResolutionFactor||.6,this._delayBeforeRestore=!1!==t.delayBeforeRestore,this._delayBeforeRestoreSeconds=t.delayBeforeRestoreSeconds||.5;let i=1e3*this._delayBeforeRestoreSeconds,s=!1;const r=()=>{i=1e3*this._delayBeforeRestoreSeconds,s||(e.scene._renderer.setColorTextureEnabled(!this._hideColorTexture),e.scene._renderer.setPBREnabled(!this._hidePBR),e.scene._renderer.setSAOEnabled(!this._hideSAO),e.scene._renderer.setTransparentEnabled(!this._hideTransparentObjects),e.scene._renderer.setEdgesEnabled(!this._hideEdges),this._scaleCanvasResolution?e.scene.canvas.resolutionScale=this._scaleCanvasResolutionFactor:e.scene.canvas.resolutionScale=this._defaultScaleCanvasResolutionFactor,s=!0)},o=()=>{e.scene.canvas.resolutionScale=this._defaultScaleCanvasResolutionFactor,e.scene._renderer.setEdgesEnabled(!0),e.scene._renderer.setColorTextureEnabled(!0),e.scene._renderer.setPBREnabled(!0),e.scene._renderer.setSAOEnabled(!0),e.scene._renderer.setTransparentEnabled(!0),s=!1};this._onCanvasBoundary=e.scene.canvas.on("boundary",r),this._onCameraMatrix=e.scene.camera.on("matrix",r),this._onSceneTick=e.scene.on("tick",(e=>{s&&(i-=e.deltaTime,(!this._delayBeforeRestore||i<=0)&&o())}));let n=!1;this._onSceneMouseDown=e.scene.input.on("mousedown",(()=>{n=!0})),this._onSceneMouseUp=e.scene.input.on("mouseup",(()=>{n=!1})),this._onSceneMouseMove=e.scene.input.on("mousemove",(()=>{n&&r()}))}get hideColorTexture(){return this._hideColorTexture}set hideColorTexture(e){this._hideColorTexture=e}get hidePBR(){return this._hidePBR}set hidePBR(e){this._hidePBR=e}get hideSAO(){return this._hideSAO}set hideSAO(e){this._hideSAO=e}get hideEdges(){return this._hideEdges}set hideEdges(e){this._hideEdges=e}get hideTransparentObjects(){return this._hideTransparentObjects}set hideTransparentObjects(e){this._hideTransparentObjects=!1!==e}get scaleCanvasResolution(){return this._scaleCanvasResolution}set scaleCanvasResolution(e){this._scaleCanvasResolution=e}get defaultScaleCanvasResolutionFactor(){return this._defaultScaleCanvasResolutionFactor}set defaultScaleCanvasResolutionFactor(e){this._defaultScaleCanvasResolutionFactor=e||1}get scaleCanvasResolutionFactor(){return this._scaleCanvasResolutionFactor}set scaleCanvasResolutionFactor(e){this._scaleCanvasResolutionFactor=e||.6}get delayBeforeRestore(){return this._delayBeforeRestore}set delayBeforeRestore(e){this._delayBeforeRestore=e}get delayBeforeRestoreSeconds(){return this._delayBeforeRestoreSeconds}set delayBeforeRestoreSeconds(e){this._delayBeforeRestoreSeconds=null!=e?e:.5}send(e,t){}destroy(){this.viewer.scene.camera.off(this._onCameraMatrix),this.viewer.scene.canvas.off(this._onCanvasBoundary),this.viewer.scene.input.off(this._onSceneMouseDown),this.viewer.scene.input.off(this._onSceneMouseUp),this.viewer.scene.input.off(this._onSceneMouseMove),this.viewer.scene.off(this._onSceneTick),super.destroy()}}class qc{constructor(e={}){this.cacheBuster=!1!==e.cacheBuster}_cacheBusterURL(e){if(!this.cacheBuster)return e;const t=(new Date).getTime();return e.indexOf("?")>-1?e+"&_="+t:e+"?_="+t}getMetaModel(e,t,i){y.loadJSON(this._cacheBusterURL(e),(e=>{t(e)}),(function(e){i(e)}))}getGLTF(e,t,i){y.loadArraybuffer(this._cacheBusterURL(e),(e=>{t(e)}),(function(e){i(e)}))}getGLB(e,t,i){y.loadArraybuffer(this._cacheBusterURL(e),(e=>{t(e)}),(function(e){i(e)}))}getArrayBuffer(e,t,i,s){!function(e,t,i,s){var r=()=>{};i=i||r,s=s||r;const o=/^data:(.*?)(;base64)?,(.*)$/,n=t.match(o);if(n){const e=!!n[2];var a=n[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),t=new Uint8Array(e);for(var l=0;l{i(e)}),(function(e){s(e)}))}}class $c{constructor(e={}){this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=e.messages,this.locale=e.locale}set messages(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}loadMessages(e={}){for(let t in e)this._messages[t]=e[t];this.messages=this._messages}clearMessages(){this.messages={}}get locales(){return this._locales}set locale(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}get locale(){return this._locale}translate(e,t){const i=this._messages[this._locale];if(!i)return null;const s=eu(e,i);return s?t?tu(s,t):s:null}translatePlurals(e,t,i){const s=this._messages[this._locale];if(!s)return null;let r=eu(e,s);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=tu(r,[t]),i&&(r=tu(r,i)),r):null}fire(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);const s=this._eventSubs[e];if(s)for(const e in s)if(s.hasOwnProperty(e)){s[e].callback(t)}}on(t,i){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let s=this._eventSubs[t];s||(s={},this._eventSubs[t]=s);const r=this._eventSubIDMap.addItem();s[r]={callback:i},this._eventSubEvents[r]=t;const o=this._events[t];return void 0!==o&&i(o),r}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}function eu(e,t){if(t[e])return t[e];const i=e.split(".");let s=t;for(let e=0,t=i.length;s&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,s=e+t;i<0&&(i=0),s>1&&(s=1);var r=this.getPoint(i),o=this.getPoint(s),n=d.subVec3(o,r,[]);return d.normalizeVec3(n,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,s=[],r=this.getPoint(0),o=0;for(s.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),o+=d.lenVec3(d.subVec3(t,r,[])),s.push(o),r=t;return this.cacheArcLengths=s,s}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var i,s=this._getLengths(),r=0,o=s.length;i=t||e*s[o-1];for(var n,a=0,l=o-1;a<=l;)if((n=s[r=Math.floor(a+(l-a)/2)]-i)<0)a=r+1;else{if(!(n>0)){l=r;break}l=r-1}if(s[r=l]===i)return r/(o-1);var A=s[r];return(r+(i-A)/(s[r+1]-A))/(o-1)}}class su extends iu{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,s=Math.floor(i),r=i-s,o=t[0===s?s:s-1],n=t[s],a=t[s>t.length-2?t.length-1:s+1],l=t[s>t.length-3?t.length-1:s+2],A=d.vec3();return A[0]=d.catmullRomInterpolate(o[0],n[0],a[0],l[0],r),A[1]=d.catmullRomInterpolate(o[1],n[1],a[1],l[1],r),A[2]=d.catmullRomInterpolate(o[2],n[2],a[2],l[2],r),A}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const ru=d.vec3();class ou extends L{get type(){return"CameraPath"}constructor(e,t={}){super(e,t),this._frames=[],this._eyeCurve=new su(this),this._lookCurve=new su(this),this._upCurve=new su(this),t.frames&&(this.addFrames(t.frames),this.smoothFrameTimes(1))}get frames(){return this._frames}get eyeCurve(){return this._eyeCurve}get lookCurve(){return this._lookCurve}get upCurve(){return this._upCurve}saveFrame(e){const t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}addFrame(e,t,i,s){const r={t:e,eye:t.slice(0),look:i.slice(0),up:s.slice(0)};this._frames.push(r),this._eyeCurve.points.push(r.eye),this._lookCurve.points.push(r.look),this._upCurve.points.push(r.up)}addFrames(e){let t;for(let i=0,s=e.length;i1?1:e,t.eye=this._eyeCurve.getPoint(e,ru),t.look=this._lookCurve.getPoint(e,ru),t.up=this._upCurve.getPoint(e,ru)}sampleFrame(e,t,i,s){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,i),this._upCurve.getPoint(e,s)}smoothFrameTimes(e){if(0===this._frames.length)return;const t=d.vec3();var i=0;this._frames[0].t=0;const s=[];for(let e=1,o=this._frames.length;e=1;e>1&&(e=1);const i=this.easing?cu._ease(e,0,1,1):e,s=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(d.subVec3(s.eye,s.look,hu),s.eye=d.lerpVec3(i,0,1,this._eye1,this._eye2,lu),s.look=d.subVec3(lu,hu,au)):this._flyingLook&&(s.look=d.lerpVec3(i,0,1,this._look1,this._look2,au),s.up=d.lerpVec3(i,0,1,this._up1,this._up2,Au)):this._flyingEyeLookUp&&(s.eye=d.lerpVec3(i,0,1,this._eye1,this._eye2,lu),s.look=d.lerpVec3(i,0,1,this._look1,this._look2,au),s.up=d.lerpVec3(i,0,1,this._up1,this._up2,Au)),this._projection2){const t="ortho"===this._projection2?cu._easeOutExpo(e,0,1,1):cu._easeInCubic(e,0,1,1);s.customProjection.matrix=d.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else s.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return s.ortho.scale=this._orthoScale2,void this.stop();I.scheduleTask(this._update,this)}static _ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}static _easeInCubic(e,t,i,s){return i*(e/=s)*e*e+t}static _easeOutExpo(e,t,i,s){return i*(1-Math.pow(2,-10*e/s))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class uu extends L{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new cu(this),this._t=0,this.state=uu.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,i;const s=performance.now(),r=this._lastTime?.001*(s-this._lastTime):0;if(this._lastTime=s,0!==r)switch(this.state){case uu.SCRUBBING:return;case uu.PLAYING:if(this._t+=this._playingRate*r,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=uu.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case uu.PLAYING_TO:i=this._t+this._playingRate*r*this._playingDir,(this._playingDir<0&&i<=this._playingToT||this._playingDir>0&&i>=this._playingToT)&&(i=this._playingToT,this.state=uu.SCRUBBING,this.fire("stopped")),this._t=i,e.loadFrame(this._t)}}_ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=uu.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=uu.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const i=this._cameraPath;if(!i)return;const s=i.frames[e];s?(this.state=uu.SCRUBBING,this._cameraFlightAnimation.flyTo(s,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=uu.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=uu.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=uu.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}uu.STOPPED=0,uu.SCRUBBING=1,uu.PLAYING=2,uu.PLAYING_TO=3;const du=d.vec3(),pu=d.vec3();d.vec3();const fu=d.vec3([0,-1,0]),gu=d.vec4([0,0,0,1]);class mu extends L{constructor(e,t={}){super(e,t),this._src=null,this._image=null,this._pos=d.vec3(),this._origin=d.vec3(),this._rtcPos=d.vec3(),this._dir=d.vec3(),this._size=1,this._imageSize=d.vec2(),this._texture=new io(this),this._plane=new wr(this,{geometry:new $t(this,po({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new ri(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0}),clippable:t.clippable}),this._grid=new wr(this,{geometry:new $t(this,uo({size:1,divisions:10})),material:new ri(this,{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:t.clippable}),this._node=new Qr(this,{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[this._plane,this._grid]}),this._gridVisible=!1,this.visible=!0,this.gridVisible=t.gridVisible,this.position=t.position,this.rotation=t.rotation,this.dir=t.dir,this.size=t.size,this.collidable=t.collidable,this.clippable=t.clippable,this.pickable=t.pickable,this.opacity=t.opacity,t.image?this.image=t.image:this.src=t.src}set visible(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}get visible(){return this._plane.visible}set gridVisible(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}get gridVisible(){return this._gridVisible}set image(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}get image(){return this._image}set src(e){if(this._src=e,this._src){this._image=null;const e=new Image;e.onload=()=>{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set position(e){this._pos.set(e||[0,0,0]),Y(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}get position(){return this._pos}set rotation(e){this._node.rotation=e}get rotation(){return this._node.rotation}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set dir(e){if(this._dir.set(e||[0,0,-1]),e){const t=this.scene.center,i=[-this._dir[0],-this._dir[1],-this._dir[2]];d.subVec3(t,this.position,du);const s=-d.dotVec3(i,du);d.normalizeVec3(i),d.mulVec3Scalar(i,s,pu),d.vec3PairToQuaternion(fu,e,gu),this._node.quaternion=gu}}get dir(){return this._dir}set collidable(e){this._node.collidable=!1!==e}get collidable(){return this._node.collidable}set clippable(e){this._node.clippable=!1!==e}get clippable(){return this._node.clippable}set pickable(e){this._node.pickable=!1!==e}get pickable(){return this._node.pickable}set opacity(e){this._node.opacity=e}get opacity(){return this._node.opacity}destroy(){super.destroy()}_updatePlaneSizeFromImage(){const e=this._size,t=this._imageSize[0],i=this._imageSize[1];if(t>i){const s=i/t;this._node.scale=[e,1,e*s]}else{const s=t/i;this._node.scale=[e*s,1,e]}}}class _u extends Nt{get type(){return"PointLight"}constructor(e,t={}){super(e,t);const i=this;this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const s=this.scene.camera,r=this.scene.canvas;this._onCameraViewMatrix=s.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=r.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new mt({type:"point",pos:d.vec3([1,1,1]),color:d.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(i._shadowViewMatrixDirty){i._shadowViewMatrix||(i._shadowViewMatrix=d.identityMat4());const e=i._state.pos,t=s.look,r=s.up;d.lookAtMat4v(e,t,r,i._shadowViewMatrix),i._shadowViewMatrixDirty=!1}return i._shadowViewMatrix},getShadowProjMatrix:()=>{if(i._shadowProjMatrixDirty){i._shadowProjMatrix||(i._shadowProjMatrix=d.identityMat4());const e=i.scene.canvas.canvas;d.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,i._shadowProjMatrix),i._shadowProjMatrixDirty=!1}return i._shadowProjMatrix},getShadowRenderBuf:()=>(i._shadowRenderBuf||(i._shadowRenderBuf=new ct(i.scene.canvas.canvas,i.scene.canvas.gl,{size:[1024,1024]})),i._shadowRenderBuf)}),this.pos=t.pos,this.color=t.color,this.intensity=t.intensity,this.constantAttenuation=t.constantAttenuation,this.linearAttenuation=t.linearAttenuation,this.quadraticAttenuation=t.quadraticAttenuation,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set pos(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get pos(){return this._state.pos}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set constantAttenuation(e){this._state.attenuation[0]=e||0,this.glRedraw()}get constantAttenuation(){return this._state.attenuation[0]}set linearAttenuation(e){this._state.attenuation[1]=e||0,this.glRedraw()}get linearAttenuation(){return this._state.attenuation[1]}set quadraticAttenuation(e){this._state.attenuation[2]=e||0,this.glRedraw()}get quadraticAttenuation(){return this._state.attenuation[2]}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}function vu(e){if(!bu(e.width)||!bu(e.height)){const t=document.createElement("canvas");t.width=yu(e.width),t.height=yu(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function bu(e){return 0==(e&e-1)}function yu(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Bu extends L{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const i=this.scene.canvas.gl;this._state=new mt({texture:new Yr({gl:i,target:i.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),m.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,i=this.scene.canvas.gl;this._images=[];let s=!1,r=0;for(let o=0;o{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set collidable(e){this._mesh.collidable=!1!==e}get collidable(){return this._mesh.collidable}set clippable(e){this._mesh.clippable=!1!==e}get clippable(){return this._mesh.clippable}set pickable(e){this._mesh.pickable=!1!==e}get pickable(){return this._mesh.pickable}set opacity(e){this._mesh.opacity=e}get opacity(){return this._mesh.opacity}_updatePlaneSizeFromImage(){const e=.5*this._size,t=this._imageSize[0],i=this._imageSize[1],s=i/t;this._geometry.positions=t>i?[e,e*s,0,-e,e*s,0,-e,-e*s,0,e,-e*s,0]:[e/s,e,0,-e/s,e,0,-e/s,-e,0,e/s,-e,0]}}class Cu{constructor(e){this._eye=d.vec3(),this._look=d.vec3(),this._up=d.vec3(),this._projection={},e&&this.saveCamera(e)}saveCamera(e){const t=e.camera,i=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:i.fov,fovAxis:i.fovAxis,near:i.near,far:i.far};break;case"ortho":this._projection={projection:"ortho",scale:i.scale,near:i.near,far:i.far};break;case"frustum":this._projection={projection:"frustum",left:i.left,right:i.right,top:i.top,bottom:i.bottom,near:i.near,far:i.far};break;case"custom":this._projection={projection:"custom",matrix:i.matrix.slice()}}}restoreCamera(e,t){const i=e.camera,s=this._projection;function r(){switch(s.type){case"perspective":i.perspective.fov=s.fov,i.perspective.fovAxis=s.fovAxis,i.perspective.near=s.near,i.perspective.far=s.far;break;case"ortho":i.ortho.scale=s.scale,i.ortho.near=s.near,i.ortho.far=s.far;break;case"frustum":i.frustum.left=s.left,i.frustum.right=s.right,i.frustum.top=s.top,i.frustum.bottom=s.bottom,i.frustum.near=s.near,i.frustum.far=s.far;break;case"custom":i.customProjection.matrix=s.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:s.scale,projection:s.projection},(()=>{r(),t()})):(i.eye=this._eye,i.look=this._look,i.up=this._up,r(),i.projection=s.projection)}}const Mu=d.vec3();class Eu{constructor(e){if(this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,e){const t=e.metaScene.scene;this.saveObjects(t,e)}}saveObjects(e,t,i){this.numObjects=0,this._mask=i?y.apply(i,{}):null;const s=!i||i.visible,r=!i||i.edges,o=!i||i.xrayed,n=!i||i.highlighted,a=!i||i.selected,l=!i||i.clippable,A=!i||i.pickable,h=!i||i.colorize,c=!i||i.opacity,u=t.metaObjects,d=e.objects;for(let e=0,t=u.length;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=d.vec3();return t[0]=d.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=d.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=d.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}class Su extends iu{constructor(e,t={}){super(e,t),this._cachedLengths=[],this._dirty=!0,this._curves=[],this._t=0,this._dirtySubs=[],this._destroyedSubs=[],this.curves=t.curves||[],this.t=t.t}addCurve(e){this._curves.push(e),this._dirty=!0}set curves(e){var t,i,s;for(e=e||[],i=0,s=this._curves.length;i1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}get length(){var e=this._getCurveLengths();return e[e.length-1]}getPoint(e){for(var t,i=e*this.length,s=this._getCurveLengths(),r=0;r=i){var o=1-(s[r]-i)/(t=this._curves[r]).length;return t.getPointAt(o)}r++}return null}_getCurveLengths(){if(!this._dirty)return this._cachedLengths;var e,t=[],i=0,s=this._curves.length;for(e=0;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=d.vec3();return t[0]=d.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=d.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=d.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}class Lu extends Fc{constructor(e,t={}){super(e,t)}}class Ru extends L{constructor(e,t={}){super(e,t),this._skyboxMesh=new wr(this,{geometry:new $t(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new ri(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new io(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}class Uu{transcode(e,t,i={}){}destroy(){}}const ku=d.vec4(),Ou=d.vec4(),Nu=d.vec3(),Qu=d.vec3(),Vu=d.vec3(),Hu=d.vec4(),ju=d.vec4(),Gu=d.vec4();class zu{constructor(e){this._scene=e}dollyToCanvasPos(e,t,i){let s=!1;const r=this._scene.camera;if(e){const t=d.subVec3(e,r.eye,Nu);s=d.lenVec3(t){this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=d.vec3();d.decomposeMat4(d.inverseMat4(this._scene.viewer.camera.viewMatrix,d.mat4()),t,d.vec4(),d.vec3());const i=d.distVec3(t,e);let s=Math.tan(Math.PI/500)*i*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(s/=this._scene.camera.ortho.scale/2),Y(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new no(this._scene,Cr({radius:s})),this._pivotSphere=new wr(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){d.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,d.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const i=t.boundary,s=i[2],r=i[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*s/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*r/2);let o=t._lastBoundingClientRect;if(!o||t._canvasSizeChanged){const e=t.canvas;o=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(o.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(o.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(Y(this.getPivotPos(),this._rtcCenter,this._rtcPos),d.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new ri(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=d.lookAtMat4v(e.eye,e.look,e.worldUp);d.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const i=this.getPivotPos();this._cameraOffset[2]+=d.distVec3(e.eye,i),t=d.inverseMat4(t);const s=d.transformVec3(t,this._cameraOffset),r=d.vec3();if(d.subVec3(e.eye,i,r),d.addVec3(r,s),e.zUp){const e=r[1];r[1]=r[2],r[2]=e}this._radius=d.lenVec3(r),this._polar=Math.acos(r[1]/this._radius),this._azimuth=Math.atan2(r[0],r[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=d.normalizeVec3(d.subVec3(e.look,e.eye,Wu)),i=d.cross3Vec3(t,e.worldUp,Ku);return d.sqLenVec3(i)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,i=Math.abs(d.distVec3(this._scene.center,t.eye)),s=t.project.transposedMatrix,r=s.subarray(8,12),o=s.subarray(12),n=[0,0,-1,1],a=d.dotVec4(n,r)/d.dotVec4(n,o),l=Ju;t.project.unproject(e,a,Yu,Zu,l);const A=d.normalizeVec3(d.subVec3(l,t.eye,Wu)),h=d.addVec3(t.eye,d.mulVec3Scalar(A,i,Ku),Xu);this.setPivotPos(h)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const i=this._scene.camera;var s=-e;const r=-t;1===i.worldUp[2]&&(s=-s),this._azimuth+=.01*-s,this._polar+=.01*r,this._polar=d.clamp(this._polar,.001,Math.PI-.001);const o=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===i.worldUp[2]){const e=o[1];o[1]=o[2],o[2]=e}const n=d.lenVec3(d.subVec3(i.look,i.eye,d.vec3())),a=this.getPivotPos();d.addVec3(o,a);let l=d.lookAtMat4v(o,a,i.worldUp);l=d.inverseMat4(l);const A=d.transformVec3(l,this._cameraOffset);l[12]-=A[0],l[13]-=A[1],l[14]-=A[2];const h=[l[8],l[9],l[10]];i.eye=[l[12],l[13],l[14]],d.subVec3(i.eye,d.mulVec3Scalar(h,n),i.look),i.up=[l[4],l[5],l[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class $u{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=d.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;const e=`${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;if(this._lastHash===e)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;const t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&(e.snappedToEdge||e.snappedToVertex)?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const e=this.pickResult.canvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new je;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}const ed=d.vec2();class td{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController;let n,a,l,A=0,h=0,c=0,u=0,p=!1;const f=d.vec3();let g=!0;const m=this._scene.canvas.canvas,_=[];function v(e=!0){m.style.cursor="move",A=s.pointerCanvasPos[0],h=s.pointerCanvasPos[1],c=s.pointerCanvasPos[0],u=s.pointerCanvasPos[1],e&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(p=!0,f.set(o.pickResult.worldPos)):p=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(i.active&&i.pointerEnabled)switch(t.which){case 1:_[e.input.KEY_SHIFT]||i.planView?(n=!0,v()):(n=!0,v(!1));break;case 2:a=!0,v();break;case 3:l=!0,i.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(!n&&!a&&!l)return;const o=e.canvas.boundary,c=o[2],u=o[3],g=s.pointerCanvasPos[0],m=s.pointerCanvasPos[1],v=_[e.input.KEY_SHIFT]||i.planView||!i.panRightClick&&a||i.panRightClick&&l,b=document.pointerLockElement?t.movementX:g-A,y=document.pointerLockElement?t.movementY:m-h;if(v){const t=e.camera;if("perspective"===t.projection){const i=Math.abs(p?d.lenVec3(d.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(t.perspective.fov/2*Math.PI/180);r.panDeltaX+=1.5*b*i/u,r.panDeltaY+=1.5*y*i/u}else r.panDeltaX+=.5*t.ortho.scale*(b/u),r.panDeltaY+=.5*t.ortho.scale*(y/u)}else!n||a||l||i.planView||(i.firstPerson?(r.rotateDeltaY-=b/c*i.dragRotationRate/2,r.rotateDeltaX+=y/u*(i.dragRotationRate/4)):(r.rotateDeltaY-=b/c*(1.5*i.dragRotationRate),r.rotateDeltaX+=y/u*(1.5*i.dragRotationRate)));A=g,h=m}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{i.active&&i.pointerEnabled&&s.mouseover&&(g=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(i.active&&i.pointerEnabled)switch(e.which){case 1:case 2:case 3:n=!1,a=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(i.active&&i.pointerEnabled){if(3===e.which){!function(e,t){if(e){let i=e.target,s=0,r=0,o=0,n=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,o+=i.scrollLeft,n+=i.scrollTop,i=i.offsetParent;t[0]=e.pageX+o-s,t[1]=e.pageY+n-r}else e=window.event,t[0]=e.x,t[1]=e.y}(e,ed);const i=ed[0],s=ed[1];Math.abs(i-c)<3&&Math.abs(s-u)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:ed,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{i.active&&i.pointerEnabled});const b=1/60;let y=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!i.active||!i.pointerEnabled)return;const t=performance.now()/1e3;var o=null!==y?t-y:0;y=t,o>.05&&(o=.05),o{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(i.keyboardEnabledOnlyIfMouseover&&!s.mouseover)return;const n=r._isKeyDownForAction(r.AXIS_VIEW_RIGHT),a=r._isKeyDownForAction(r.AXIS_VIEW_BACK),l=r._isKeyDownForAction(r.AXIS_VIEW_LEFT),A=r._isKeyDownForAction(r.AXIS_VIEW_FRONT),h=r._isKeyDownForAction(r.AXIS_VIEW_TOP),c=r._isKeyDownForAction(r.AXIS_VIEW_BOTTOM);if(!(n||a||l||A||h||c))return;const u=e.aabb,p=d.getAABB3Diag(u);d.getAABB3Center(u,id);const f=Math.abs(p/Math.tan(t.cameraFlight.fitFOV*d.DEGTORAD)),g=1.1*p;ad.orthoScale=g,n?(ad.eye.set(d.addVec3(id,d.mulVec3Scalar(o.worldRight,f,sd),nd)),ad.look.set(id),ad.up.set(o.worldUp)):a?(ad.eye.set(d.addVec3(id,d.mulVec3Scalar(o.worldForward,f,sd),nd)),ad.look.set(id),ad.up.set(o.worldUp)):l?(ad.eye.set(d.addVec3(id,d.mulVec3Scalar(o.worldRight,-f,sd),nd)),ad.look.set(id),ad.up.set(o.worldUp)):A?(ad.eye.set(d.addVec3(id,d.mulVec3Scalar(o.worldForward,-f,sd),nd)),ad.look.set(id),ad.up.set(o.worldUp)):h?(ad.eye.set(d.addVec3(id,d.mulVec3Scalar(o.worldUp,f,sd),nd)),ad.look.set(id),ad.up.set(d.normalizeVec3(d.mulVec3Scalar(o.worldForward,1,rd),od))):c&&(ad.eye.set(d.addVec3(id,d.mulVec3Scalar(o.worldUp,-f,sd),nd)),ad.look.set(id),ad.up.set(d.normalizeVec3(d.mulVec3Scalar(o.worldForward,-1,rd)))),!i.firstPerson&&i.followPointer&&t.pivotController.setPivotPos(id),t.cameraFlight.duration>0?t.cameraFlight.flyTo(ad,(()=>{t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(ad),t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class Ad{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,A=!1;const h=this._scene.canvas.canvas,c=i=>{let s;i&&i.worldPos&&(s=i.worldPos);const r=i&&i.entity?i.entity.aabb:e.aabb;if(s){const i=e.camera;d.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})},u=e.tickify(this._canvasMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(l||A)return;if(a.hasSubs("rayMove")){const t=d.vec3(),i=d.vec3();d.canvasPosToWorldRay(e.canvas.canvas,e.camera.viewMatrix,e.camera.projMatrix,e.camera.projection,s.pointerCanvasPos,t,i),a.fire("rayMove",{canvasPos:s.pointerCanvasPos,ray:{origin:t,direction:i,canvasPos:s.pointerCanvasPos}},!0)}const r=a.hasSubs("hover"),n=a.hasSubs("hoverEnter"),h=a.hasSubs("hoverOut"),c=a.hasSubs("hoverOff"),u=a.hasSubs("hoverSurface"),p=a.hasSubs("hoverSnapOrSurface");if(r||n||h||c||u||p)if(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=u,o.scheduleSnapOrPick=p,o.update(),o.pickResult){if(o.pickResult.entity){const t=o.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),a.fire("hoverEnter",o.pickResult,!0),this._lastPickedEntityId=t)}a.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&a.fire("hoverSurface",o.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),a.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)});h.addEventListener("mousemove",u),h.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(A=!0);if(1===t.which&&i.active&&i.pointerEnabled&&(s.mouseDownClientX=t.clientX,s.mouseDownClientY=t.clientY,s.mouseDownCursorX=s.pointerCanvasPos[0],s.mouseDownCursorY=s.pointerCanvasPos[1],!i.firstPerson&&i.followPointer&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===t.which))){const t=o.pickResult;t&&t.worldPos?(n.setPivotPos(t.worldPos),n.startPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),n.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(A=!1),n.getPivoting()&&n.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=r=>{if(!i.active||!i.pointerEnabled)return;if(!(1===r.which))return;if(n.hidePivot(),Math.abs(r.clientX-s.mouseDownClientX)>3||Math.abs(r.clientY-s.mouseDownClientY)>3)return;const l=a.hasSubs("picked"),A=a.hasSubs("pickedNothing"),h=a.hasSubs("pickedSurface"),u=a.hasSubs("doublePicked"),p=a.hasSubs("doublePickedSurface"),f=a.hasSubs("doublePickedNothing");if(!(i.doublePickFlyTo||u||p||f))return(l||A||h)&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=h,o.update(),o.pickResult?(a.fire("picked",o.pickResult,!0),o.pickedSurface&&a.fire("pickedSurface",o.pickResult,!0)):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo,o.schedulePickSurface=h,o.update();const e=o.pickResult,r=o.pickedSurface;this._timeout=setTimeout((()=>{e?(a.fire("picked",e,!0),r&&(a.fire("pickedSurface",e,!0),!i.firstPerson&&i.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0),this._clicks=0}),i.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo||u||p,o.schedulePickSurface=o.schedulePickEntity&&p,o.update(),o.pickResult){if(a.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&a.fire("doublePickedSurface",o.pickResult,!0),i.doublePickFlyTo&&(c(o.pickResult),!i.firstPerson&&i.followPointer)){const e=o.pickResult.entity.aabb,i=d.getAABB3Center(e);t.pivotController.setPivotPos(i),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(a.fire("doublePickedNothing",{canvasPos:s.pointerCanvasPos},!0),i.doublePickFlyTo&&(c(),!i.firstPerson&&i.followPointer)){const i=e.aabb,s=d.getAABB3Center(i);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class hd{constructor(e,t,i,s,r){this._scene=e;const o=e.input,n=[],a=e.canvas.canvas;let l=!0;this._onSceneMouseMove=o.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=o.on("keydown",(t=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&(i.keyboardEnabledOnlyIfMouseover&&!s.mouseover||(n[t]=!0,t===o.KEY_SHIFT&&(a.style.cursor="move")))})),this._onSceneKeyUp=o.on("keyup",(s=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&(n[s]=!1,s===o.KEY_SHIFT&&(a.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(a=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(i.keyboardEnabledOnlyIfMouseover&&!s.mouseover)return;const A=t.cameraControl,h=a.deltaTime/1e3;if(!i.planView){const e=A._isKeyDownForAction(A.ROTATE_Y_POS,n),s=A._isKeyDownForAction(A.ROTATE_Y_NEG,n),o=A._isKeyDownForAction(A.ROTATE_X_POS,n),a=A._isKeyDownForAction(A.ROTATE_X_NEG,n),l=h*i.keyboardRotationRate;(e||s||o||a)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),e?r.rotateDeltaY+=l:s&&(r.rotateDeltaY-=l),o?r.rotateDeltaX+=l:a&&(r.rotateDeltaX-=l),!i.firstPerson&&i.followPointer&&t.pivotController.startPivot())}if(!n[o.KEY_CTRL]&&!n[o.KEY_ALT]){const e=A._isKeyDownForAction(A.DOLLY_BACKWARDS,n),o=A._isKeyDownForAction(A.DOLLY_FORWARDS,n);if(e||o){const n=h*i.keyboardDollyRate;!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),o?r.dollyDelta-=n:e&&(r.dollyDelta+=n),l&&(s.followPointerDirty=!0,l=!1)}}const c=A._isKeyDownForAction(A.PAN_FORWARDS,n),u=A._isKeyDownForAction(A.PAN_BACKWARDS,n),d=A._isKeyDownForAction(A.PAN_LEFT,n),p=A._isKeyDownForAction(A.PAN_RIGHT,n),f=A._isKeyDownForAction(A.PAN_UP,n),g=A._isKeyDownForAction(A.PAN_DOWN,n),m=(n[o.KEY_ALT]?.3:1)*h*i.keyboardPanRate;(c||u||d||p||f||g)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),g?r.panDeltaY+=m:f&&(r.panDeltaY+=-m),p?r.panDeltaX+=-m:d&&(r.panDeltaX+=m),u?r.panDeltaZ+=m:c&&(r.panDeltaZ+=-m))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const cd=d.vec3();class ud{constructor(e,t,i,s,r){this._scene=e;const o=e.camera,n=t.pickController,a=t.pivotController,l=t.panController;let A=1,h=1,c=null;this._onTick=e.on("tick",(()=>{if(!i.active||!i.pointerEnabled)return;let t="default";if(Math.abs(r.dollyDelta)<.001&&(r.dollyDelta=0),Math.abs(r.rotateDeltaX)<.001&&(r.rotateDeltaX=0),Math.abs(r.rotateDeltaY)<.001&&(r.rotateDeltaY=0),0===r.rotateDeltaX&&0===r.rotateDeltaY||(r.dollyDelta=0),i.followPointer){if(--A<=0&&(A=1,0!==r.dollyDelta)){if(0===r.rotateDeltaY&&0===r.rotateDeltaX&&i.followPointer&&s.followPointerDirty&&(n.pickCursorPos=s.pointerCanvasPos,n.schedulePickSurface=!0,n.update(),n.pickResult&&n.pickResult.worldPos?c=n.pickResult.worldPos:(h=1,c=null),s.followPointerDirty=!1),c){const t=Math.abs(d.lenVec3(d.subVec3(c,e.camera.eye,cd)));h=t/i.dollyProximityThreshold}h{s.mouseover=!0}),o.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{s.mouseover=!1,o.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{pd(e,o,s.pointerCanvasPos)}),o.addEventListener("mousedown",this._mouseDownHandler=e=>{i.active&&i.pointerEnabled&&(pd(e,o,s.pointerCanvasPos),s.mouseover=!0)}),o.addEventListener("mouseup",this._mouseUpHandler=e=>{i.active&&i.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function pd(e,t,i){if(e){const{left:s,top:r}=t.getBoundingClientRect();i[0]=e.clientX-s,i[1]=e.clientY-r}else e=window.event,i[0]=e.x,i[1]=e.y;return i}const fd=function(e,t){if(e){let i=e.target,s=0,r=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;t[0]=e.pageX-s,t[1]=e.pageY-r}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class gd{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=d.vec2(),l=d.vec2(),A=d.vec2(),h=d.vec2(),c=[],u=this._scene.canvas.canvas;let p=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),u.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!i.active||!i.pointerEnabled)return;t.preventDefault();const r=t.touches,l=t.changedTouches;for(s.touchStartTime=Date.now(),1===r.length&&1===l.length&&(fd(r[0],a),i.followPointer&&(o.pickCursorPos=a,o.schedulePickSurface=!0,o.update(),i.planView||(o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(n.setPivotPos(o.pickResult.worldPos),!i.firstPerson&&n.startPivot()&&n.showPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),!i.firstPerson&&n.startPivot()&&n.showPivot()))));c.length{n.getPivoting()&&n.endPivot()}),u.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const n=e.canvas.boundary,a=n[2],u=n[3],g=t.touches;if(t.touches.length===p){if(1===p){fd(g[0],l),d.subVec2(l,c[0],h);const t=h[0],o=h[1];if(null!==s.longTouchTimeout&&(Math.abs(t)>i.longTapRadius||Math.abs(o)>i.longTapRadius)&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),i.planView){const s=e.camera;if("perspective"===s.projection){const n=Math.abs(e.camera.eyeLookDist)*Math.tan(s.perspective.fov/2*Math.PI/180);r.panDeltaX+=t*n/u*i.touchPanRate,r.panDeltaY+=o*n/u*i.touchPanRate}else r.panDeltaX+=.5*s.ortho.scale*(t/u)*i.touchPanRate,r.panDeltaY+=.5*s.ortho.scale*(o/u)*i.touchPanRate}else r.rotateDeltaY-=t/a*(1*i.dragRotationRate),r.rotateDeltaX+=o/u*(1.5*i.dragRotationRate)}else if(2===p){const t=g[0],n=g[1];fd(t,l),fd(n,A);const a=d.geometricMeanVec2(c[0],c[1]),h=d.geometricMeanVec2(l,A),p=d.vec2();d.subVec2(a,h,p);const f=p[0],m=p[1],_=e.camera,v=d.distVec2([t.pageX,t.pageY],[n.pageX,n.pageY]),b=(d.distVec2(c[0],c[1])-v)*i.touchDollyRate;if(r.dollyDelta=b,Math.abs(b)<1)if("perspective"===_.projection){const t=o.pickResult?o.pickResult.worldPos:e.center,s=Math.abs(d.lenVec3(d.subVec3(t,e.camera.eye,[])))*Math.tan(_.perspective.fov/2*Math.PI/180);r.panDeltaX-=f*s/u*i.touchPanRate,r.panDeltaY-=m*s/u*i.touchPanRate}else r.panDeltaX-=.5*_.ortho.scale*(f/u)*i.touchPanRate,r.panDeltaY-=.5*_.ortho.scale*(m/u)*i.touchPanRate;s.pointerCanvasPos=h}for(let e=0;e{let s;i&&i.worldPos&&(s=i.worldPos);const r=i?i.entity.aabb:e.aabb;if(s){const i=e.camera;d.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})};u.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!i.active||!i.pointerEnabled)return;null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null);const r=e.touches,o=e.changedTouches;if(a=Date.now(),1===r.length&&1===o.length){h=a,md(r[0],A);const o=A[0],n=A[1],l=r[0].pageX,c=r[0].pageY;s.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(c)],canvasPos:[Math.round(o),Math.round(n)],event:e},!0),s.longTouchTimeout=null}),i.longTapTimeout)}else h=-1;for(;l.length{if(!i.active||!i.pointerEnabled)return;const t=Date.now(),r=e.touches,a=e.changedTouches,u=n.hasSubs("pickedSurface");null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),0===r.length&&1===a.length&&h>-1&&t-h<150&&(c>-1&&h-c<325?(md(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=u,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("doublePicked",o.pickResult),o.pickedSurface&&n.fire("doublePickedSurface",o.pickResult),i.doublePickFlyTo&&p(o.pickResult)):(n.fire("doublePickedNothing"),i.doublePickFlyTo&&p()),c=-1):d.distVec2(l[0],A)<4&&(md(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=u,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("picked",o.pickResult),o.pickedSurface&&n.fire("pickedSurface",o.pickResult)):n.fire("pickedNothing"),c=t),h=-1),l.length=r.length;for(let e=0,t=r.length;e{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,keyboardEnabledOnlyIfMouseover:!0,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:d.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:d.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const i=this.scene;this._controllers={cameraControl:this,pickController:new $u(this,this._configs),pivotController:new qu(i,this._configs),panController:new zu(i),cameraFlight:new cu(this,{duration:.5})},this._handlers=[new dd(this.scene,this._controllers,this._configs,this._states,this._updates),new gd(this.scene,this._controllers,this._configs,this._states,this._updates),new td(this.scene,this._controllers,this._configs,this._states,this._updates),new ld(this.scene,this._controllers,this._configs,this._states,this._updates),new Ad(this.scene,this._controllers,this._configs,this._states,this._updates),new _d(this.scene,this._controllers,this._configs,this._states,this._updates),new hd(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new ud(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",y.isString(e)){const t=this.scene.input,i={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":i[this.PAN_LEFT]=[t.KEY_A],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_Z],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":i[this.PAN_LEFT]=[t.KEY_Q],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_W],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=i}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const i=this._keyMap[e];if(!i)return!1;t||(t=this.scene.input.keyDown);for(let e=0,s=i.length;e0&&console.error(`[MetaModel._decompressProperties] Properties not found: ${i}`)}finalize(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";const e=this.metaScene;for(let t in e.metaObjects){const i=e.metaObjects[t];if(i.children&&(i.children=[]),i.propertySets&&(i.propertySets=[]),i.propertySetIds)for(let t=0,s=i.propertySetIds.length;t0?Pd(t):null,n=i&&i.length>0?Pd(i):null,a=e=>{if(!e)return;var t=!0;(n&&n[e.type]||o&&!o[e.type])&&(t=!1),t&&s.push(e.id);const i=e.children;if(i)for(var r=0,l=i.length;r>t;i.sort(Ac);const s=new Int32Array(e.length);for(let t=0,r=i.length;te[t+1]){let i=e[t];e[t]=e[t+1],e[t+1]=i}hc=new Int32Array(e),t.sort(cc);const i=new Int32Array(e.length);for(let s=0,r=t.length;st){let i=e;e=t,t=i}function i(i,s){return i!==e?e-i:s!==t?t-s:0}let s=0,r=(o.length>>1)-1;for(;s<=r;){const e=r+s>>1,t=i(o[2*e],o[2*e+1]);if(t>0)s=e+1;else{if(!(t<0))return e;r=e-1}}return-s-1}const a=new Int32Array(o.length/2);a.fill(0);const l=s.length/3;if(l>8*(1<u.maxNumPositions&&(u=c()),u.bucketNumber>8)return[e];let p;-1===A[l]&&(A[l]=u.numPositions++,u.positionsCompressed.push(s[3*l]),u.positionsCompressed.push(s[3*l+1]),u.positionsCompressed.push(s[3*l+2])),-1===A[h]&&(A[h]=u.numPositions++,u.positionsCompressed.push(s[3*h]),u.positionsCompressed.push(s[3*h+1]),u.positionsCompressed.push(s[3*h+2])),-1===A[d]&&(A[d]=u.numPositions++,u.positionsCompressed.push(s[3*d]),u.positionsCompressed.push(s[3*d+1]),u.positionsCompressed.push(s[3*d+2])),u.indices.push(A[l]),u.indices.push(A[h]),u.indices.push(A[d]),(p=n(l,h))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(l,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]])),(p=n(h,d))>=0&&0===a[p]&&(a[p]=1,u.edgeIndices.push(A[o[2*p]]),u.edgeIndices.push(A[o[2*p+1]]))}const d=t/8*2,p=t/8,f=2*s.length+(r.length+o.length)*d;let g=0,m=-s.length/3;return h.forEach((e=>{g+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*p,m+=e.positionsCompressed.length/3})),g>f?[e]:(i&&function(e,t){const i={},s={};let r=0;e.forEach((e=>{const t=e.indices,o=e.edgeIndices,n=e.positionsCompressed;for(let e=0,s=t.length;e0){const e=t._meshes;for(let t=0,i=e.length;t0){const e=this._meshes;for(let t=0,i=e.length;t{this._viewMatrixDirty=!0})),this._meshesWithDirtyMatrices=[],this._numMeshesWithDirtyMatrices=0,this._onTick=this.scene.on("tick",(()=>{for(;this._numMeshesWithDirtyMatrices>0;)this._meshesWithDirtyMatrices[--this._numMeshesWithDirtyMatrices]._updateMatrix()})),this._createDefaultTextureSet(),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.backfaces=t.backfaces}_meshMatrixDirty(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}_createDefaultTextureSet(){const e=new Wh({id:"defaultColorTexture",texture:new Yr({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Wh({id:"defaultMetalRoughTexture",texture:new Yr({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),i=new Wh({id:"defaultNormalsTexture",texture:new Yr({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),s=new Wh({id:"defaultEmissiveTexture",texture:new Yr({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),r=new Wh({id:"defaultOcclusionTexture",texture:new Yr({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=i,this._textures.defaultEmissiveTexture=s,this._textures.defaultOcclusionTexture=r,this._textureSets.defaultTextureSet=new zh({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:i,emissiveTexture:s,occlusionTexture:r})}get isPerformanceModel(){return!0}get transforms(){return this._transforms}get textures(){return this._textures}get textureSets(){return this._textureSets}get meshes(){return this._meshes}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),d.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),d.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||Mc),d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),d.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),d.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),d.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),d.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),d.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0,this._aabbDirty=!0}_transformDirty(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}_sceneModelDirty(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(let e=0,t=this._entityList.length;e0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,i=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,i=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,i=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,i=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,i=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,i=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,i=new Uint8Array(t.length);for(let e=0,s=t.length;e{l.setImage(A,{minFilter:i,magFilter:s,wrapS:r,wrapT:o,wrapR:n,flipY:e.flipY,encoding:a}),this.glRedraw()},A.src=e.src;break;default:this._textureTranscoder?y.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,l).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new Wh({id:t,texture:l})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let i,s,r,o,n;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(i=this._textures[e.colorTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(s=this._textures[e.metallicRoughnessTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(r=this._textures[e.normalsTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(o=this._textures[e.emissiveTextureId],!o)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else o=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(n=this._textures[e.occlusionTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultOcclusionTexture;const a=new zh({id:t,model:this,colorTexture:i,metallicRoughnessTexture:s,normalsTexture:r,emissiveTexture:o,occlusionTexture:n});return this._textureSets[t]=a,a}createTransform(e){if(void 0===e.id||null===e.id)return void this.error("[createTransform] SceneModel.createTransform() config missing: id");if(this._transforms[e.id])return void this.error(`[createTransform] SceneModel already has a transform with this ID: ${e.id}`);let t;if(e.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const i=new bc({id:e.id,model:this,parent:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[i.id]=i,i}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._meshes[e.id])return this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`),!1;if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!(e.buckets||e.indices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)){const t=(e.positions||e.positionsCompressed).length/3;e.indices=this._createDefaultIndices(t)}if(!e.buckets&&!e.indices&&"points"!==e.primitive)return e.indices=this._createDefaultIndices(numIndices),this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;const t=!(!this._dtxEnabled||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||e.textureSetId);if(e.origin=e.origin?d.addVec3(this._origin,e.origin,d.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position||e.quaternion){const t=e.scale||xc,i=e.position||Pc;e.rotation?(d.eulerToQuaternion(e.rotation,"XYZ",wc),e.meshMatrix=d.composeMat4(i,wc,t,d.mat4())):e.meshMatrix=d.composeMat4(i,e.quaternion||Cc,t,d.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=bn(e.positionsDecodeBoundary,d.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):Ec,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=d.vec3(),i=[];Z(e.positions,i,t)&&(e.positions=i,e.origin=d.addVec3(e.origin,t,t))}if(e.positions){const t=d.collapseAABB3();e.positionsDecodeMatrix=d.mat4(),d.expandAABB3Points3(t,e.positions),e.positionsCompressed=vn(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=d.collapseAABB3();d.expandAABB3Points3(t,e.positionsCompressed),Yt.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.buckets){const t=d.collapseAABB3();for(let i=0,s=e.buckets.length;i>24&255,r=i>>16&255,o=i>>8&255,n=255&i;switch(e.pickColor=new Uint8Array([n,o,r,s]),e.solid="solid"===e.primitive,t.origin=d.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),this._meshes[e.id]=t,this._unusedMeshes[e.id]=t,this._meshList.push(t),t}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let i=0,s=e.buckets.length;i>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,i=e.origin,s=e.textureSetId||"-",r=e.geometryId,o=`${Math.round(i[0])}.${Math.round(i[1])}.${Math.round(i[2])}.${s}.${r}`;let n=this._vboInstancingLayers[o];if(n)return n;let a=e.textureSet;const l=e.geometry;for(;!n;)switch(l.primitive){case"triangles":case"surface":n=new xa({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!1});break;case"solid":n=new xa({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!0});break;case"lines":n=new Al({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0});break;case"points":n=new iA({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0})}return this._vboInstancingLayers[o]=n,this.layerList.push(n),n}createEntity(e){if(void 0===e.id?e.id=d.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=d.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;this._visible&&!1!==e.visible&&(t|=ee),this._pickable&&!1!==e.pickable&&(t|=ie),this._culled&&!1!==e.culled&&(t|=te),this._clippable&&!1!==e.clippable&&(t|=se),this._collidable&&!1!==e.collidable&&(t|=re),this._edges&&!1!==e.edges&&(t|=le),this._xrayed&&!1!==e.xrayed&&(t|=oe),this._highlighted&&!1!==e.highlighted&&(t|=ne),this._selected&&!1!==e.selected&&(t|=ae),e.flags=t,this._createEntity(e)}_createEntity(e){let t=[];for(let i=0,s=e.meshIds.length;ie.sortIdt.sortId?1:0));for(let e=0,t=this.layerList.length;e0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,i=this.layerList.length;t0){const t=`${this.id}-dummyEntityForUnusedMeshes`;this.warn(`Creating dummy SceneModelEntity "${t}" for unused SceneMeshes: [${e.join(",")}]`),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}_getActiveSectionPlanesForLayer(e){const t=this.renderFlags,i=this.scene._sectionPlanesState.sectionPlanes,s=i.length,r=e.layerIndex*s;if(s>0)for(let e=0;e0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}drawColorOpaque(e,t){const i=this.renderFlags;for(let t=0,s=i.visibleLayers.length;t65536?16:8)}else n=[{positionsCompressed:s,indices:r,edgeIndices:o}];return n}class Dc extends L{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;ep.has(e.id)||g.has(e.id)||f.has(e.id))).reduce(((e,i)=>{let s,r=function(e){let t="";return t+=Math.round(255*e[0]).toString(16).padStart(2,"0"),t+=Math.round(255*e[1]).toString(16).padStart(2,"0"),t+=Math.round(255*e[2]).toString(16).padStart(2,"0"),t}(i.colorize);i.xrayed?(s=0===t.xrayMaterial.fillAlpha&&0!==t.xrayMaterial.edgeAlpha?.1:t.xrayMaterial.fillAlpha,s=Math.round(255*s).toString(16).padStart(2,"0"),r=s+r):p.has(i.id)&&(s=Math.round(255*i.opacity).toString(16).padStart(2,"0"),r=s+r),e[r]||(e[r]=[]);const o=i.id,n=i.originalSystemId,a={ifc_guid:n,originating_system:this.originatingSystem};return n!==o&&(a.authoring_tool_id=o),e[r].push(a),e}),{}),_=Object.entries(m).map((([e,t])=>({color:e,components:t})));o.components.coloring=_;const v=t.objectIds,b=t.visibleObjects,y=t.visibleObjectIds,B=v.filter((e=>!b[e])),w=t.selectedObjectIds;return e.defaultInvisible||y.length0&&e.clipping_planes.forEach((function(e){let t=Oc(e.location,Sc),i=Oc(e.direction,Sc);A&&d.negateVec3(i),d.subVec3(t,l),r.yUp&&(t=Qc(t),i=Qc(i)),new Ir(s,{pos:t,dir:i})})),s.clearLines(),e.lines&&e.lines.length>0){const t=[],i=[];let r=0;e.lines.forEach((e=>{e.start_point&&e.end_point&&(t.push(e.start_point.x),t.push(e.start_point.y),t.push(e.start_point.z),t.push(e.end_point.x),t.push(e.end_point.y),t.push(e.end_point.z),i.push(r++),i.push(r++))})),new Dc(s,{positions:t,indices:i,clippable:!1,collidable:!0})}if(s.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){const t=e.bitmap_type||"jpg",i=e.bitmap_data;let o=Oc(e.location,Tc),n=Oc(e.normal,Lc),a=Oc(e.up,Rc),l=e.height||1;t&&i&&o&&n&&a&&(r.yUp&&(o=Qc(o),n=Qc(n),a=Qc(a)),new vo(s,{src:i,type:t,pos:o,normal:n,up:a,clippable:!1,collidable:!0,height:l}))})),a&&(s.setObjectsXRayed(s.xrayedObjectIds,!1),s.setObjectsHighlighted(s.highlightedObjectIds,!1),s.setObjectsSelected(s.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(s.setObjectsVisible(s.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!1))))):(s.setObjectsVisible(s.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!0)))));const r=e.components.visibility.view_setup_hints;r&&(!1===r.spaces_visible&&s.setObjectsVisible(i.metaScene.getObjectIDsByType("IfcSpace"),!1),void 0!==r.spaces_translucent&&s.setObjectsXRayed(i.metaScene.getObjectIDsByType("IfcSpace"),!0),r.space_boundaries_visible,!1===r.openings_visible&&s.setObjectsVisible(i.metaScene.getObjectIDsByType("IfcOpening"),!0),r.space_boundaries_translucent,void 0!==r.openings_translucent&&s.setObjectsXRayed(i.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(s.setObjectsSelected(s.selectedObjectIds,!1),e.components.selection.forEach((e=>this._withBCFComponent(t,e,(e=>e.selected=!0))))),e.components.translucency&&(s.setObjectsXRayed(s.xrayedObjectIds,!1),e.components.translucency.forEach((e=>this._withBCFComponent(t,e,(e=>e.xrayed=!0))))),e.components.coloring&&e.components.coloring.forEach((e=>{let i=e.color,s=0,r=!1;8===i.length&&(s=parseInt(i.substring(0,2),16)/256,s<=1&&s>=.95&&(s=1),i=i.substring(2),r=!0);const o=[parseInt(i.substring(0,2),16)/256,parseInt(i.substring(2,4),16)/256,parseInt(i.substring(4,6),16)/256];e.components.map((e=>this._withBCFComponent(t,e,(e=>{e.colorize=o,r&&(e.opacity=s)}))))}))}if(e.perspective_camera||e.orthogonal_camera){let a,A,h,c;if(e.perspective_camera?(a=Oc(e.perspective_camera.camera_view_point,Sc),A=Oc(e.perspective_camera.camera_direction,Sc),h=Oc(e.perspective_camera.camera_up_vector,Sc),r.perspective.fov=e.perspective_camera.field_of_view,c="perspective"):(a=Oc(e.orthogonal_camera.camera_view_point,Sc),A=Oc(e.orthogonal_camera.camera_direction,Sc),h=Oc(e.orthogonal_camera.camera_up_vector,Sc),r.ortho.scale=e.orthogonal_camera.view_to_world_scale,c="ortho"),d.subVec3(a,l),r.yUp&&(a=Qc(a),A=Qc(A),h=Qc(h)),o){const e=s.pick({pickSurface:!0,origin:a,direction:A});A=e?e.worldPos:d.addVec3(a,A,Sc)}else A=d.addVec3(a,A,Sc);n?(r.eye=a,r.look=A,r.up=h,r.projection=c):i.cameraFlight.flyTo({eye:a,look:A,up:h,duration:t.duration,projection:c})}}_withBCFComponent(e,t,i){const s=this.viewer,r=s.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){const o=t.authoring_tool_id,n=r.objects[o];if(n)return void i(n);if(e.updateCompositeObjects){if(s.metaScene.metaObjects[o])return void r.withObjects(s.metaScene.getObjectIDsInSubtree(o),i)}}if(t.ifc_guid){const o=t.ifc_guid,n=r.objects[o];if(n)return void i(n);if(e.updateCompositeObjects){if(s.metaScene.metaObjects[o])return void r.withObjects(s.metaScene.getObjectIDsInSubtree(o),i)}Object.keys(r.models).forEach((t=>{const n=d.globalizeObjectId(t,o),a=r.objects[n];if(a)i(a);else if(e.updateCompositeObjects){s.metaScene.metaObjects[n]&&r.withObjects(s.metaScene.getObjectIDsInSubtree(n),i)}}))}}destroy(){super.destroy()}}function kc(e){return{x:e[0],y:e[1],z:e[2]}}function Oc(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function Nc(e){return new Float64Array([e[0],-e[2],e[1]])}function Qc(e){return new Float64Array([e[0],e[2],-e[1]])}const Vc=d.vec3(),Hc=(e,t,i,s)=>{var r=e-i,o=t-s;return Math.sqrt(r*r+o*o)};class jc extends L{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._eventSubs={};var i=this.plugin.viewer.scene;this._originWorld=d.vec3(),this._targetWorld=d.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;const s=t.onMouseOver?e=>{t.onMouseOver(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,r=t.onMouseLeave?e=>{t.onMouseLeave(e,this),this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseleave",e))}:null,o=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousedown",e))},n=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseup",e))},a=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},l=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,A=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new me(i,t.origin,this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._targetDot=new me(i,t.target,this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthWire=new be(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisWire=new be(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisWire=new be(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisWire=new be(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._lengthLabel=new ye(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._xAxisLabel=new ye(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._yAxisLabel=new ye(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._zAxisLabel=new ye(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:r,onMouseWheel:A,onMouseDown:o,onMouseUp:n,onMouseMove:a,onContextMenu:l}),this._measurementOrientation="Horizontal",this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._sectionPlanesDirty=!0,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,this._xLabelEnabled=!1,this._yLabelEnabled=!1,this._zLabelEnabled=!1,this._lengthLabelEnabled=!1,this._labelsVisible=!1,this._labelsOnWires=!1,this._clickable=!1,this._originDot.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetDot.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=i.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=i.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=i.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this._onMetricsUnits=i.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=i.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=i.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onSectionPlaneUpdated=i.on("sectionPlaneUpdated",(()=>{this._sectionPlanesDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.xLabelEnabled=t.xLabelEnabled,this.yLabelEnabled=t.yLabelEnabled,this.zLabelEnabled=t.zLabelEnabled,this.lengthLabelEnabled=t.lengthLabelEnabled,this.labelsVisible=t.labelsVisible,this.labelsOnWires=t.labelsOnWires,this.useRotationAdjustment=t.useRotationAdjustment}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._measurementOrientation=function(e,t,i){return Math.abs(t[1]-e[1])>i?"Vertical":"Horizontal"}(this._originWorld,this._targetWorld,0),"Vertical"===this._measurementOrientation&&this.useRotationAdjustment?(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._originWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._originWorld[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._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=1),this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(d.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._originWorld)||this._isSliced(this._targetWorld))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}const t=this._originDot.viewPos[2],i=this._targetDot.viewPos[2];if(t>-.3||i>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){d.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var s=this._pp,r=this._cp,o=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var n=o.top-t.top,a=o.left-t.left,l=e.canvas.boundary,A=l[2],h=l[3],c=0;const i=this.plugin.viewer.scene.metrics,f=i.scale,g=i.units,m=i.unitsInfo[g].abbrev;for(var u=0,p=s.length;ue.offsetTop+(e.offsetParent&&e.offsetParent!==s.parentNode&&h(e.offsetParent)),c=e=>e.offsetLeft+(e.offsetParent&&e.offsetParent!==s.parentNode&&c(e.offsetParent)),u=d.vec2();this._onCameraControlHoverSnapOrSurface=i.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(e=>{const t=e.snappedCanvasPos||e.canvasPos;r=!0,o.set(e.worldPos),n.set(e.canvasPos),0===this._mouseState?(this._canvasToPagePos?(this._canvasToPagePos(s,t,u),this._markerDiv.style.left=u[0]-5+"px",this._markerDiv.style.top=u[1]-5+"px"):(this._markerDiv.style.left=c(s)+t[0]-5+"px",this._markerDiv.style.top=h(s)+t[1]-5+"px"),this._markerDiv.style.background="pink",e.snappedToVertex||e.snappedToEdge?(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos,this.pointerLens.snapped=!0),this._markerDiv.style.background="greenyellow",this._markerDiv.style.border="2px solid green"):(this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.canvasPos,this.pointerLens.snapped=!1),this._markerDiv.style.background="pink",this._markerDiv.style.border="2px solid red"),A=e.entity):(this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px"),s.style.cursor="pointer",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=this._currentDistanceMeasurementInitState.wireVisible,this._currentDistanceMeasurement.axisVisible=this._currentDistanceMeasurementInitState.axisVisible&&this.distanceMeasurementsPlugin.defaultAxisVisible,this._currentDistanceMeasurement.xAxisVisible=this._currentDistanceMeasurementInitState.xAxisVisible&&this.distanceMeasurementsPlugin.defaultXAxisVisible,this._currentDistanceMeasurement.yAxisVisible=this._currentDistanceMeasurementInitState.yAxisVisible&&this.distanceMeasurementsPlugin.defaultYAxisVisible,this._currentDistanceMeasurement.zAxisVisible=this._currentDistanceMeasurementInitState.zAxisVisible&&this.distanceMeasurementsPlugin.defaultZAxisVisible,this._currentDistanceMeasurement.targetVisible=this._currentDistanceMeasurementInitState.targetVisible,this._currentDistanceMeasurement.target.worldPos=o.slice(),this._markerDiv.style.left="-10000px",this._markerDiv.style.top="-10000px")})),s.addEventListener("mousedown",this._onMouseDown=e=>{1===e.which&&(a=e.clientX,l=e.clientY)}),s.addEventListener("mouseup",this._onMouseUp=t=>{1===t.which&&(t.clientX>a+20||t.clientXl+20||t.clientY{this.pointerLens&&(this.pointerLens.visible=!0,this.pointerLens.canvasPos=e.canvasPos,this.pointerLens.snappedCanvasPos=e.snappedCanvasPos||e.canvasPos),r=!1,this._markerDiv.style.left="-100px",this._markerDiv.style.top="-100px",this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.axisVisible=!1),s.style.cursor="default"})),this._active=!0}deactivate(){if(!this._active)return;this.fire("activated",!1),this.pointerLens&&(this.pointerLens.visible=!1);const e=this.scene.canvas.canvas;e.removeEventListener("mousedown",this._onMouseDown),e.removeEventListener("mouseup",this._onMouseUp);const t=this.distanceMeasurementsPlugin.viewer.cameraControl;t.off(this._onCameraControlHoverSnapOrSurface),t.off(this._onCameraControlHoverSnapOrSurfaceOff),this._active=!1}reset(){this._active&&(this._destroyMarkerDiv(),this._initMarkerDiv(),this._currentDistanceMeasurement&&(this.distanceMeasurementsPlugin.fire("measurementCancel",this._currentDistanceMeasurement),this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null),this._mouseState=0)}get currentMeasurement(){return this._currentDistanceMeasurement}destroy(){this.deactivate(),super.destroy()}}class Wc extends z{constructor(e,t={}){super("DistanceMeasurements",e),this._pointerLens=t.pointerLens,this._container=t.container||document.body,this._defaultControl=null,this._measurements={},this.labelMinAxisLength=t.labelMinAxisLength,this.defaultVisible=!1!==t.defaultVisible,this.defaultOriginVisible=!1!==t.defaultOriginVisible,this.defaultTargetVisible=!1!==t.defaultTargetVisible,this.defaultWireVisible=!1!==t.defaultWireVisible,this.defaultXLabelEnabled=!1!==t.defaultXLabelEnabled,this.defaultYLabelEnabled=!1!==t.defaultYLabelEnabled,this.defaultZLabelEnabled=!1!==t.defaultZLabelEnabled,this.defaultLengthLabelEnabled=!1!==t.defaultLengthLabelEnabled,this.defaultLabelsVisible=!1!==t.defaultLabelsVisible,this.defaultAxisVisible=!1!==t.defaultAxisVisible,this.defaultXAxisVisible=!1!==t.defaultXAxisVisible,this.defaultYAxisVisible=!1!==t.defaultYAxisVisible,this.defaultZAxisVisible=!1!==t.defaultZAxisVisible,this.defaultColor=void 0!==t.defaultColor?t.defaultColor:"#00BBFF",this.zIndex=t.zIndex||1e4,this.defaultLabelsOnWires=!1!==t.defaultLabelsOnWires,this.useRotationAdjustment=void 0!==t.useRotationAdjustment&&!1!==t.useRotationAdjustment,this._onMouseOver=(e,t)=>{this.fire("mouseOver",{plugin:this,distanceMeasurement:t,measurement:t,event:e})},this._onMouseLeave=(e,t)=>{this.fire("mouseLeave",{plugin:this,distanceMeasurement:t,measurement:t,event:e})},this._onContextMenu=(e,t)=>{this.fire("contextMenu",{plugin:this,distanceMeasurement:t,measurement:t,event:e})}}getContainerElement(){return this._container}send(e,t){}get pointerLens(){return this._pointerLens}get control(){return this._defaultControl||(this._defaultControl=new zc(this,{})),this._defaultControl}get measurements(){return this._measurements}set labelMinAxisLength(e){e<1&&(this.error("labelMinAxisLength must be >= 1; defaulting to 25"),e=25),this._labelMinAxisLength=e||25}get labelMinAxisLength(){return this._labelMinAxisLength}set useRotationAdjustment(e){e=void 0!==e&&Boolean(e),this._useRotationAdjustment=e}get useRotationAdjustment(){return this._useRotationAdjustment}createMeasurement(e={}){this.viewer.scene.components[e.id]&&(this.error("Viewer scene component with this ID already exists: "+e.id),delete e.id);const t=e.origin,i=e.target,s=new jc(this,{id:e.id,plugin:this,container:this._container,origin:{entity:t.entity,worldPos:t.worldPos},target:{entity:i.entity,worldPos:i.worldPos},visible:e.visible,wireVisible:e.wireVisible,axisVisible:!1!==e.axisVisible&&!1!==this.defaultAxisVisible,xAxisVisible:!1!==e.xAxisVisible&&!1!==this.defaultXAxisVisible,yAxisVisible:!1!==e.yAxisVisible&&!1!==this.defaultYAxisVisible,zAxisVisible:!1!==e.zAxisVisible&&!1!==this.defaultZAxisVisible,xLabelEnabled:!1!==e.xLabelEnabled&&!1!==this.defaultXLabelEnabled,yLabelEnabled:!1!==e.yLabelEnabled&&!1!==this.defaultYLabelEnabled,zLabelEnabled:!1!==e.zLabelEnabled&&!1!==this.defaultZLabelEnabled,lengthLabelEnabled:!1!==e.lengthLabelEnabled&&!1!==this.defaultLengthLabelEnabled,labelsVisible:!1!==e.labelsVisible&&!1!==this.defaultLabelsVisible,useRotationAdjustment:this.useRotationAdjustment,originVisible:e.originVisible,targetVisible:e.targetVisible,color:e.color,labelsOnWires:!1!==e.labelsOnWires&&!1!==this.defaultLabelsOnWires,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[s.id]=s,s.clickable=!0,s.on("destroyed",(()=>{delete this._measurements[s.id]})),this.fire("measurementCreated",s),s}destroyMeasurement(e){const t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("DistanceMeasurement not found: "+e)}setLabelsShown(e){for(const[t,i]of Object.entries(this.measurements))i.labelShown=e}setAxisVisible(e){for(const[t,i]of Object.entries(this.measurements))i.axisVisible=e;this.defaultAxisVisible=e}getAxisVisible(){return this.defaultAxisVisible}clear(){const e=Object.keys(this._measurements);for(var t=0,i=e.length;t{this.plugin.viewer.cameraControl.active=!1},c=()=>{this.plugin.viewer.cameraControl.active=!0},u=()=>{o&&(clearTimeout(o),o=null),this._currentDistanceMeasurement&&(this._currentDistanceMeasurement.destroy(),this._currentDistanceMeasurement=null),c(),this._touchState=0};i.addEventListener("touchstart",this._onCanvasTouchStart=i=>{const l=i.touches.length;if(1!==l)return void(o&&(clearTimeout(o),o=null));const c=i.touches[0],p=c.clientX,f=c.clientY;switch(n.set([p,f]),a.set([p,f]),this._touchState){case 0:if(1!==l&&null!==o)return void u();const i=t.pick({canvasPos:a,snapping:this._snapping,snapToEdge:this._snapping});if(i&&i.snapped)s.set(i.worldPos),this.pointerCircle.start(i.snappedCanvasPos);else{const e=t.pick({canvasPos:a,pickSurface:!0});if(!e||!e.worldPos)return;s.set(e.worldPos),this.pointerCircle.start(e.canvasPos)}o=setTimeout((()=>{1!==l||a[0]>n[0]+r||a[0]n[1]+r||a[1]{if(o=null,1!==l||a[0]>n[0]+r||a[0]n[1]+r||a[1]{this.pointerCircle.stop();const r=i.touches.length;if(1!==r||1!==i.changedTouches.length)return void(o&&(clearTimeout(o),o=null));const n=i.touches[0],l=n.clientX,h=n.clientY;if(n.identifier!==A)return;let c,u;switch(a.set([l,h]),this._touchState){case 2:this.pointerLens&&(this.pointerLens.canvasPos=a),c=t.pick({canvasPos:a,snapToVertex:this._snapping,snapToEdge:this._snapping}),c&&c.snapped?(this.pointerLens&&(this.pointerLens.snappedCanvasPos=c.snappedCanvasPos,this.pointerLens.snapped=!0),s.set(c.worldPos),this._currentDistanceMeasurement?this._currentDistanceMeasurement.origin.worldPos=c.worldPos:(this._currentDistanceMeasurement=e.createMeasurement({id:d.createUUID(),origin:{worldPos:c.worldPos,entity:c.entity},target:{worldPos:c.worldPos,entity:c.entity}}),this._currentDistanceMeasurement.labelsVisible=!1,this._currentDistanceMeasurement.xAxisVisible=!1,this._currentDistanceMeasurement.yAxisVisible=!1,this._currentDistanceMeasurement.zAxisVisible=!1,this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.originVisible=!0,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.clickable=!1),this.distanceMeasurementsPlugin.fire("measurementStart",this._currentDistanceMeasurement)):(u=t.pick({canvasPos:a,pickSurface:!0}),u&&u.worldPos?(this.pointerLens&&(this.pointerLens.cursorPos=u.canvasPos,this.pointerLens.snapped=!1),s.set(u.worldPos),this._currentDistanceMeasurement?this._currentDistanceMeasurement.origin.worldPos=u.worldPos:(this._currentDistanceMeasurement=e.createMeasurement({id:d.createUUID(),origin:{worldPos:u.worldPos,entity:u.entity},target:{worldPos:u.worldPos,entity:u.entity}}),this._currentDistanceMeasurement.labelsVisible=!1,this._currentDistanceMeasurement.xAxisVisible=!1,this._currentDistanceMeasurement.yAxisVisible=!1,this._currentDistanceMeasurement.zAxisVisible=!1,this._currentDistanceMeasurement.wireVisible=!1,this._currentDistanceMeasurement.originVisible=!0,this._currentDistanceMeasurement.targetVisible=!1,this._currentDistanceMeasurement.clickable=!1),this.distanceMeasurementsPlugin.fire("measurementStart",this._currentDistanceMeasurement)):this.pointerLens&&(this.pointerLens.cursorPos=null,this.pointerLens.snapped=!1)),this._touchState=2;break;case 5:if(1!==r&&null!==o)return clearTimeout(o),o=null,this.pointerLens&&(this.pointerLens.visible=!1),void(this._touchState=7);this.pointerLens&&(this.pointerLens.canvasPos=a),c=t.pick({canvasPos:a,snapToVertex:this._snapping,snapToEdge:this._snapping}),c&&c.worldPos?(this.pointerLens&&(this.pointerLens.cursorPos=c.snappedCanvasPos,this.pointerLens.snapped=!0),this._currentDistanceMeasurement.target.worldPos=c.worldPos,this._currentDistanceMeasurement.target.entity=c.entity,this._currentDistanceMeasurement.targetVisible=!0,this._currentDistanceMeasurement.wireVisible=!0,this._currentDistanceMeasurement.labelsVisible=!0):(u=t.pick({canvasPos:a,pickSurface:!0}),u&&u.worldPos&&(this.pointerLens&&(this.pointerLens.cursorPos=u.canvasPos,this.pointerLens.snapped=!1),this._currentDistanceMeasurement.target.worldPos=u.worldPos,this._currentDistanceMeasurement.target.entity=u.entity,this._currentDistanceMeasurement.targetVisible=!0,this._currentDistanceMeasurement.wireVisible=!0,this._currentDistanceMeasurement.labelsVisible=!0)),this._touchState=5}}),{passive:!0}),i.addEventListener("touchend",this._onCanvasTouchEnd=i=>{this.pointerCircle.stop();const s=i.changedTouches.length;if(1!==s)return;const h=i.changedTouches[0],u=h.clientX,p=h.clientY;if(h.identifier===A)switch(o&&(clearTimeout(o),o=null),l.set([u,p]),this._touchState){case 1:{if(1!==s||u>n[0]+r||un[1]+r||pn[0]+r||un[1]+r||p{const o=e=>{const t=r.scene.pick({canvasPos:s,snapToEdge:e,snapToVertex:e,pickSurface:!0});return t&&t.worldPos?t.worldPos:e&&o(!1)};return o(!!t.snapping)},onEnd:(e,t)=>{const i=!d.compareVec3(e,t.worldPos);return i&&this.fire("edited"),i}}),n=e.on("destroyed",o);this._deactivate=function(){e.off("destroyed",n),o()}}deactivate(){this._deactivate(),super.destroy()}}class Jc extends Xc{constructor(e,t){super(e,t,!0,!1)}}class Yc extends Xc{constructor(e,t){super(e,t,!1,!0)}}class Zc extends z{constructor(e,t={}){super("FastNav",e),this._hideColorTexture=!1!==t.hideColorTexture,this._hidePBR=!1!==t.hidePBR,this._hideSAO=!1!==t.hideSAO,this._hideEdges=!1!==t.hideEdges,this._hideTransparentObjects=!!t.hideTransparentObjects,this._scaleCanvasResolution=!!t.scaleCanvasResolution,this._defaultScaleCanvasResolutionFactor=t.defaultScaleCanvasResolutionFactor||1,this._scaleCanvasResolutionFactor=t.scaleCanvasResolutionFactor||.6,this._delayBeforeRestore=!1!==t.delayBeforeRestore,this._delayBeforeRestoreSeconds=t.delayBeforeRestoreSeconds||.5;let i=1e3*this._delayBeforeRestoreSeconds,s=!1;const r=()=>{i=1e3*this._delayBeforeRestoreSeconds,s||(e.scene._renderer.setColorTextureEnabled(!this._hideColorTexture),e.scene._renderer.setPBREnabled(!this._hidePBR),e.scene._renderer.setSAOEnabled(!this._hideSAO),e.scene._renderer.setTransparentEnabled(!this._hideTransparentObjects),e.scene._renderer.setEdgesEnabled(!this._hideEdges),this._scaleCanvasResolution?e.scene.canvas.resolutionScale=this._scaleCanvasResolutionFactor:e.scene.canvas.resolutionScale=this._defaultScaleCanvasResolutionFactor,s=!0)},o=()=>{e.scene.canvas.resolutionScale=this._defaultScaleCanvasResolutionFactor,e.scene._renderer.setEdgesEnabled(!0),e.scene._renderer.setColorTextureEnabled(!0),e.scene._renderer.setPBREnabled(!0),e.scene._renderer.setSAOEnabled(!0),e.scene._renderer.setTransparentEnabled(!0),s=!1};this._onCanvasBoundary=e.scene.canvas.on("boundary",r),this._onCameraMatrix=e.scene.camera.on("matrix",r),this._onSceneTick=e.scene.on("tick",(e=>{s&&(i-=e.deltaTime,(!this._delayBeforeRestore||i<=0)&&o())}));let n=!1;this._onSceneMouseDown=e.scene.input.on("mousedown",(()=>{n=!0})),this._onSceneMouseUp=e.scene.input.on("mouseup",(()=>{n=!1})),this._onSceneMouseMove=e.scene.input.on("mousemove",(()=>{n&&r()}))}get hideColorTexture(){return this._hideColorTexture}set hideColorTexture(e){this._hideColorTexture=e}get hidePBR(){return this._hidePBR}set hidePBR(e){this._hidePBR=e}get hideSAO(){return this._hideSAO}set hideSAO(e){this._hideSAO=e}get hideEdges(){return this._hideEdges}set hideEdges(e){this._hideEdges=e}get hideTransparentObjects(){return this._hideTransparentObjects}set hideTransparentObjects(e){this._hideTransparentObjects=!1!==e}get scaleCanvasResolution(){return this._scaleCanvasResolution}set scaleCanvasResolution(e){this._scaleCanvasResolution=e}get defaultScaleCanvasResolutionFactor(){return this._defaultScaleCanvasResolutionFactor}set defaultScaleCanvasResolutionFactor(e){this._defaultScaleCanvasResolutionFactor=e||1}get scaleCanvasResolutionFactor(){return this._scaleCanvasResolutionFactor}set scaleCanvasResolutionFactor(e){this._scaleCanvasResolutionFactor=e||.6}get delayBeforeRestore(){return this._delayBeforeRestore}set delayBeforeRestore(e){this._delayBeforeRestore=e}get delayBeforeRestoreSeconds(){return this._delayBeforeRestoreSeconds}set delayBeforeRestoreSeconds(e){this._delayBeforeRestoreSeconds=null!=e?e:.5}send(e,t){}destroy(){this.viewer.scene.camera.off(this._onCameraMatrix),this.viewer.scene.canvas.off(this._onCanvasBoundary),this.viewer.scene.input.off(this._onSceneMouseDown),this.viewer.scene.input.off(this._onSceneMouseUp),this.viewer.scene.input.off(this._onSceneMouseMove),this.viewer.scene.off(this._onSceneTick),super.destroy()}}class qc{constructor(e={}){this.cacheBuster=!1!==e.cacheBuster}_cacheBusterURL(e){if(!this.cacheBuster)return e;const t=(new Date).getTime();return e.indexOf("?")>-1?e+"&_="+t:e+"?_="+t}getMetaModel(e,t,i){y.loadJSON(this._cacheBusterURL(e),(e=>{t(e)}),(function(e){i(e)}))}getGLTF(e,t,i){y.loadArraybuffer(this._cacheBusterURL(e),(e=>{t(e)}),(function(e){i(e)}))}getGLB(e,t,i){y.loadArraybuffer(this._cacheBusterURL(e),(e=>{t(e)}),(function(e){i(e)}))}getArrayBuffer(e,t,i,s){!function(e,t,i,s){var r=()=>{};i=i||r,s=s||r;const o=/^data:(.*?)(;base64)?,(.*)$/,n=t.match(o);if(n){const e=!!n[2];var a=n[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),t=new Uint8Array(e);for(var l=0;l{i(e)}),(function(e){s(e)}))}}class $c{constructor(e={}){this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=e.messages,this.locale=e.locale}set messages(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}loadMessages(e={}){for(let t in e)this._messages[t]=e[t];this.messages=this._messages}clearMessages(){this.messages={}}get locales(){return this._locales}set locale(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}get locale(){return this._locale}translate(e,t){const i=this._messages[this._locale];if(!i)return null;const s=eu(e,i);return s?t?tu(s,t):s:null}translatePlurals(e,t,i){const s=this._messages[this._locale];if(!s)return null;let r=eu(e,s);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=tu(r,[t]),i&&(r=tu(r,i)),r):null}fire(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);const s=this._eventSubs[e];if(s)for(const e in s)if(s.hasOwnProperty(e)){s[e].callback(t)}}on(t,i){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let s=this._eventSubs[t];s||(s={},this._eventSubs[t]=s);const r=this._eventSubIDMap.addItem();s[r]={callback:i},this._eventSubEvents[r]=t;const o=this._events[t];return void 0!==o&&i(o),r}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}function eu(e,t){if(t[e])return t[e];const i=e.split(".");let s=t;for(let e=0,t=i.length;s&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,s=e+t;i<0&&(i=0),s>1&&(s=1);var r=this.getPoint(i),o=this.getPoint(s),n=d.subVec3(o,r,[]);return d.normalizeVec3(n,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,s=[],r=this.getPoint(0),o=0;for(s.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),o+=d.lenVec3(d.subVec3(t,r,[])),s.push(o),r=t;return this.cacheArcLengths=s,s}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var i,s=this._getLengths(),r=0,o=s.length;i=t||e*s[o-1];for(var n,a=0,l=o-1;a<=l;)if((n=s[r=Math.floor(a+(l-a)/2)]-i)<0)a=r+1;else{if(!(n>0)){l=r;break}l=r-1}if(s[r=l]===i)return r/(o-1);var A=s[r];return(r+(i-A)/(s[r+1]-A))/(o-1)}}class su extends iu{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,s=Math.floor(i),r=i-s,o=t[0===s?s:s-1],n=t[s],a=t[s>t.length-2?t.length-1:s+1],l=t[s>t.length-3?t.length-1:s+2],A=d.vec3();return A[0]=d.catmullRomInterpolate(o[0],n[0],a[0],l[0],r),A[1]=d.catmullRomInterpolate(o[1],n[1],a[1],l[1],r),A[2]=d.catmullRomInterpolate(o[2],n[2],a[2],l[2],r),A}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const ru=d.vec3();class ou extends L{get type(){return"CameraPath"}constructor(e,t={}){super(e,t),this._frames=[],this._eyeCurve=new su(this),this._lookCurve=new su(this),this._upCurve=new su(this),t.frames&&(this.addFrames(t.frames),this.smoothFrameTimes(1))}get frames(){return this._frames}get eyeCurve(){return this._eyeCurve}get lookCurve(){return this._lookCurve}get upCurve(){return this._upCurve}saveFrame(e){const t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}addFrame(e,t,i,s){const r={t:e,eye:t.slice(0),look:i.slice(0),up:s.slice(0)};this._frames.push(r),this._eyeCurve.points.push(r.eye),this._lookCurve.points.push(r.look),this._upCurve.points.push(r.up)}addFrames(e){let t;for(let i=0,s=e.length;i1?1:e,t.eye=this._eyeCurve.getPoint(e,ru),t.look=this._lookCurve.getPoint(e,ru),t.up=this._upCurve.getPoint(e,ru)}sampleFrame(e,t,i,s){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,i),this._upCurve.getPoint(e,s)}smoothFrameTimes(e){if(0===this._frames.length)return;const t=d.vec3();var i=0;this._frames[0].t=0;const s=[];for(let e=1,o=this._frames.length;e=1;e>1&&(e=1);const i=this.easing?cu._ease(e,0,1,1):e,s=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(d.subVec3(s.eye,s.look,hu),s.eye=d.lerpVec3(i,0,1,this._eye1,this._eye2,lu),s.look=d.subVec3(lu,hu,au)):this._flyingLook&&(s.look=d.lerpVec3(i,0,1,this._look1,this._look2,au),s.up=d.lerpVec3(i,0,1,this._up1,this._up2,Au)):this._flyingEyeLookUp&&(s.eye=d.lerpVec3(i,0,1,this._eye1,this._eye2,lu),s.look=d.lerpVec3(i,0,1,this._look1,this._look2,au),s.up=d.lerpVec3(i,0,1,this._up1,this._up2,Au)),this._projection2){const t="ortho"===this._projection2?cu._easeOutExpo(e,0,1,1):cu._easeInCubic(e,0,1,1);s.customProjection.matrix=d.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else s.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return s.ortho.scale=this._orthoScale2,void this.stop();I.scheduleTask(this._update,this)}static _ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}static _easeInCubic(e,t,i,s){return i*(e/=s)*e*e+t}static _easeOutExpo(e,t,i,s){return i*(1-Math.pow(2,-10*e/s))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class uu extends L{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new cu(this),this._t=0,this.state=uu.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,i;const s=performance.now(),r=this._lastTime?.001*(s-this._lastTime):0;if(this._lastTime=s,0!==r)switch(this.state){case uu.SCRUBBING:return;case uu.PLAYING:if(this._t+=this._playingRate*r,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=uu.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case uu.PLAYING_TO:i=this._t+this._playingRate*r*this._playingDir,(this._playingDir<0&&i<=this._playingToT||this._playingDir>0&&i>=this._playingToT)&&(i=this._playingToT,this.state=uu.SCRUBBING,this.fire("stopped")),this._t=i,e.loadFrame(this._t)}}_ease(e,t,i,s){return-i*(e/=s)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=uu.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=uu.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const i=this._cameraPath;if(!i)return;const s=i.frames[e];s?(this.state=uu.SCRUBBING,this._cameraFlightAnimation.flyTo(s,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=uu.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=uu.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=uu.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}uu.STOPPED=0,uu.SCRUBBING=1,uu.PLAYING=2,uu.PLAYING_TO=3;const du=d.vec3(),pu=d.vec3();d.vec3();const fu=d.vec3([0,-1,0]),gu=d.vec4([0,0,0,1]);class mu extends L{constructor(e,t={}){super(e,t),this._src=null,this._image=null,this._pos=d.vec3(),this._origin=d.vec3(),this._rtcPos=d.vec3(),this._dir=d.vec3(),this._size=1,this._imageSize=d.vec2(),this._texture=new io(this),this._plane=new wr(this,{geometry:new $t(this,po({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new ri(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0}),clippable:t.clippable}),this._grid=new wr(this,{geometry:new $t(this,uo({size:1,divisions:10})),material:new ri(this,{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:t.clippable}),this._node=new Qr(this,{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[this._plane,this._grid]}),this._gridVisible=!1,this.visible=!0,this.gridVisible=t.gridVisible,this.position=t.position,this.rotation=t.rotation,this.dir=t.dir,this.size=t.size,this.collidable=t.collidable,this.clippable=t.clippable,this.pickable=t.pickable,this.opacity=t.opacity,t.image?this.image=t.image:this.src=t.src}set visible(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}get visible(){return this._plane.visible}set gridVisible(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}get gridVisible(){return this._gridVisible}set image(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}get image(){return this._image}set src(e){if(this._src=e,this._src){this._image=null;const e=new Image;e.onload=()=>{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set position(e){this._pos.set(e||[0,0,0]),Y(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}get position(){return this._pos}set rotation(e){this._node.rotation=e}get rotation(){return this._node.rotation}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set dir(e){if(this._dir.set(e||[0,0,-1]),e){const t=this.scene.center,i=[-this._dir[0],-this._dir[1],-this._dir[2]];d.subVec3(t,this.position,du);const s=-d.dotVec3(i,du);d.normalizeVec3(i),d.mulVec3Scalar(i,s,pu),d.vec3PairToQuaternion(fu,e,gu),this._node.quaternion=gu}}get dir(){return this._dir}set collidable(e){this._node.collidable=!1!==e}get collidable(){return this._node.collidable}set clippable(e){this._node.clippable=!1!==e}get clippable(){return this._node.clippable}set pickable(e){this._node.pickable=!1!==e}get pickable(){return this._node.pickable}set opacity(e){this._node.opacity=e}get opacity(){return this._node.opacity}destroy(){super.destroy()}_updatePlaneSizeFromImage(){const e=this._size,t=this._imageSize[0],i=this._imageSize[1];if(t>i){const s=i/t;this._node.scale=[e,1,e*s]}else{const s=t/i;this._node.scale=[e*s,1,e]}}}class _u extends Nt{get type(){return"PointLight"}constructor(e,t={}){super(e,t);const i=this;this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const s=this.scene.camera,r=this.scene.canvas;this._onCameraViewMatrix=s.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=r.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new mt({type:"point",pos:d.vec3([1,1,1]),color:d.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(i._shadowViewMatrixDirty){i._shadowViewMatrix||(i._shadowViewMatrix=d.identityMat4());const e=i._state.pos,t=s.look,r=s.up;d.lookAtMat4v(e,t,r,i._shadowViewMatrix),i._shadowViewMatrixDirty=!1}return i._shadowViewMatrix},getShadowProjMatrix:()=>{if(i._shadowProjMatrixDirty){i._shadowProjMatrix||(i._shadowProjMatrix=d.identityMat4());const e=i.scene.canvas.canvas;d.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,i._shadowProjMatrix),i._shadowProjMatrixDirty=!1}return i._shadowProjMatrix},getShadowRenderBuf:()=>(i._shadowRenderBuf||(i._shadowRenderBuf=new ct(i.scene.canvas.canvas,i.scene.canvas.gl,{size:[1024,1024]})),i._shadowRenderBuf)}),this.pos=t.pos,this.color=t.color,this.intensity=t.intensity,this.constantAttenuation=t.constantAttenuation,this.linearAttenuation=t.linearAttenuation,this.quadraticAttenuation=t.quadraticAttenuation,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set pos(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get pos(){return this._state.pos}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set constantAttenuation(e){this._state.attenuation[0]=e||0,this.glRedraw()}get constantAttenuation(){return this._state.attenuation[0]}set linearAttenuation(e){this._state.attenuation[1]=e||0,this.glRedraw()}get linearAttenuation(){return this._state.attenuation[1]}set quadraticAttenuation(e){this._state.attenuation[2]=e||0,this.glRedraw()}get quadraticAttenuation(){return this._state.attenuation[2]}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}function vu(e){if(!bu(e.width)||!bu(e.height)){const t=document.createElement("canvas");t.width=yu(e.width),t.height=yu(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function bu(e){return 0==(e&e-1)}function yu(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Bu extends L{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const i=this.scene.canvas.gl;this._state=new mt({texture:new Yr({gl:i,target:i.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),m.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,i=this.scene.canvas.gl;this._images=[];let s=!1,r=0;for(let o=0;o{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set collidable(e){this._mesh.collidable=!1!==e}get collidable(){return this._mesh.collidable}set clippable(e){this._mesh.clippable=!1!==e}get clippable(){return this._mesh.clippable}set pickable(e){this._mesh.pickable=!1!==e}get pickable(){return this._mesh.pickable}set opacity(e){this._mesh.opacity=e}get opacity(){return this._mesh.opacity}_updatePlaneSizeFromImage(){const e=.5*this._size,t=this._imageSize[0],i=this._imageSize[1],s=i/t;this._geometry.positions=t>i?[e,e*s,0,-e,e*s,0,-e,-e*s,0,e,-e*s,0]:[e/s,e,0,-e/s,e,0,-e/s,-e,0,e/s,-e,0]}}class Cu{constructor(e){this._eye=d.vec3(),this._look=d.vec3(),this._up=d.vec3(),this._projection={},e&&this.saveCamera(e)}saveCamera(e){const t=e.camera,i=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:i.fov,fovAxis:i.fovAxis,near:i.near,far:i.far};break;case"ortho":this._projection={projection:"ortho",scale:i.scale,near:i.near,far:i.far};break;case"frustum":this._projection={projection:"frustum",left:i.left,right:i.right,top:i.top,bottom:i.bottom,near:i.near,far:i.far};break;case"custom":this._projection={projection:"custom",matrix:i.matrix.slice()}}}restoreCamera(e,t){const i=e.camera,s=this._projection;function r(){switch(s.type){case"perspective":i.perspective.fov=s.fov,i.perspective.fovAxis=s.fovAxis,i.perspective.near=s.near,i.perspective.far=s.far;break;case"ortho":i.ortho.scale=s.scale,i.ortho.near=s.near,i.ortho.far=s.far;break;case"frustum":i.frustum.left=s.left,i.frustum.right=s.right,i.frustum.top=s.top,i.frustum.bottom=s.bottom,i.frustum.near=s.near,i.frustum.far=s.far;break;case"custom":i.customProjection.matrix=s.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:s.scale,projection:s.projection},(()=>{r(),t()})):(i.eye=this._eye,i.look=this._look,i.up=this._up,r(),i.projection=s.projection)}}const Mu=d.vec3();class Eu{constructor(e){if(this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,e){const t=e.metaScene.scene;this.saveObjects(t,e)}}saveObjects(e,t,i){this.numObjects=0,this._mask=i?y.apply(i,{}):null;const s=!i||i.visible,r=!i||i.edges,o=!i||i.xrayed,n=!i||i.highlighted,a=!i||i.selected,l=!i||i.clippable,A=!i||i.pickable,h=!i||i.colorize,c=!i||i.opacity,u=t.metaObjects,d=e.objects;for(let e=0,t=u.length;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=d.vec3();return t[0]=d.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=d.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=d.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}class Su extends iu{constructor(e,t={}){super(e,t),this._cachedLengths=[],this._dirty=!0,this._curves=[],this._t=0,this._dirtySubs=[],this._destroyedSubs=[],this.curves=t.curves||[],this.t=t.t}addCurve(e){this._curves.push(e),this._dirty=!0}set curves(e){var t,i,s;for(e=e||[],i=0,s=this._curves.length;i1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}get length(){var e=this._getCurveLengths();return e[e.length-1]}getPoint(e){for(var t,i=e*this.length,s=this._getCurveLengths(),r=0;r=i){var o=1-(s[r]-i)/(t=this._curves[r]).length;return t.getPointAt(o)}r++}return null}_getCurveLengths(){if(!this._dirty)return this._cachedLengths;var e,t=[],i=0,s=this._curves.length;for(e=0;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=d.vec3();return t[0]=d.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=d.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=d.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}class Lu extends Fc{constructor(e,t={}){super(e,t)}}class Ru extends L{constructor(e,t={}){super(e,t),this._skyboxMesh=new wr(this,{geometry:new $t(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new ri(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new io(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}class Uu{transcode(e,t,i={}){}destroy(){}}const ku=d.vec4(),Ou=d.vec4(),Nu=d.vec3(),Qu=d.vec3(),Vu=d.vec3(),Hu=d.vec4(),ju=d.vec4(),Gu=d.vec4();class zu{constructor(e){this._scene=e}dollyToCanvasPos(e,t,i){let s=!1;const r=this._scene.camera;if(e){const t=d.subVec3(e,r.eye,Nu);s=d.lenVec3(t){this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=d.vec3();d.decomposeMat4(d.inverseMat4(this._scene.viewer.camera.viewMatrix,d.mat4()),t,d.vec4(),d.vec3());const i=d.distVec3(t,e);let s=Math.tan(Math.PI/500)*i*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(s/=this._scene.camera.ortho.scale/2),Y(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new no(this._scene,Cr({radius:s})),this._pivotSphere=new wr(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){d.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,d.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const i=t.boundary,s=i[2],r=i[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*s/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*r/2);let o=t._lastBoundingClientRect;if(!o||t._canvasSizeChanged){const e=t.canvas;o=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(o.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(o.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(Y(this.getPivotPos(),this._rtcCenter,this._rtcPos),d.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new ri(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=d.lookAtMat4v(e.eye,e.look,e.worldUp);d.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const i=this.getPivotPos();this._cameraOffset[2]+=d.distVec3(e.eye,i),t=d.inverseMat4(t);const s=d.transformVec3(t,this._cameraOffset),r=d.vec3();if(d.subVec3(e.eye,i,r),d.addVec3(r,s),e.zUp){const e=r[1];r[1]=r[2],r[2]=e}this._radius=d.lenVec3(r),this._polar=Math.acos(r[1]/this._radius),this._azimuth=Math.atan2(r[0],r[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=d.normalizeVec3(d.subVec3(e.look,e.eye,Wu)),i=d.cross3Vec3(t,e.worldUp,Ku);return d.sqLenVec3(i)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,i=Math.abs(d.distVec3(this._scene.center,t.eye)),s=t.project.transposedMatrix,r=s.subarray(8,12),o=s.subarray(12),n=[0,0,-1,1],a=d.dotVec4(n,r)/d.dotVec4(n,o),l=Ju;t.project.unproject(e,a,Yu,Zu,l);const A=d.normalizeVec3(d.subVec3(l,t.eye,Wu)),h=d.addVec3(t.eye,d.mulVec3Scalar(A,i,Ku),Xu);this.setPivotPos(h)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const i=this._scene.camera;var s=-e;const r=-t;1===i.worldUp[2]&&(s=-s),this._azimuth+=.01*-s,this._polar+=.01*r,this._polar=d.clamp(this._polar,.001,Math.PI-.001);const o=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===i.worldUp[2]){const e=o[1];o[1]=o[2],o[2]=e}const n=d.lenVec3(d.subVec3(i.look,i.eye,d.vec3())),a=this.getPivotPos();d.addVec3(o,a);let l=d.lookAtMat4v(o,a,i.worldUp);l=d.inverseMat4(l);const A=d.transformVec3(l,this._cameraOffset);l[12]-=A[0],l[13]-=A[1],l[14]-=A[2];const h=[l[8],l[9],l[10]];i.eye=[l[12],l[13],l[14]],d.subVec3(i.eye,d.mulVec3Scalar(h,n),i.look),i.up=[l[4],l[5],l[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class $u{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=d.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;const e=`${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;if(this._lastHash===e)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;const t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&(e.snappedToEdge||e.snappedToVertex)?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const e=this.pickResult.canvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new je;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}const ed=d.vec2();class td{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController;let n,a,l,A=0,h=0,c=0,u=0,p=!1;const f=d.vec3();let g=!0;const m=this._scene.canvas.canvas,_=[];function v(e=!0){m.style.cursor="move",A=s.pointerCanvasPos[0],h=s.pointerCanvasPos[1],c=s.pointerCanvasPos[0],u=s.pointerCanvasPos[1],e&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(p=!0,f.set(o.pickResult.worldPos)):p=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;const s=t.keyCode;_[s]=!1}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(i.active&&i.pointerEnabled)switch(t.which){case 1:_[e.input.KEY_SHIFT]||i.planView?(n=!0,v()):(n=!0,v(!1));break;case 2:a=!0,v();break;case 3:l=!0,i.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(!n&&!a&&!l)return;const o=e.canvas.boundary,c=o[2],u=o[3],g=s.pointerCanvasPos[0],m=s.pointerCanvasPos[1],v=_[e.input.KEY_SHIFT]||i.planView||!i.panRightClick&&a||i.panRightClick&&l,b=document.pointerLockElement?t.movementX:g-A,y=document.pointerLockElement?t.movementY:m-h;if(v){const t=e.camera;if("perspective"===t.projection){const i=Math.abs(p?d.lenVec3(d.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(t.perspective.fov/2*Math.PI/180);r.panDeltaX+=1.5*b*i/u,r.panDeltaY+=1.5*y*i/u}else r.panDeltaX+=.5*t.ortho.scale*(b/u),r.panDeltaY+=.5*t.ortho.scale*(y/u)}else!n||a||l||i.planView||(i.firstPerson?(r.rotateDeltaY-=b/c*i.dragRotationRate/2,r.rotateDeltaX+=y/u*(i.dragRotationRate/4)):(r.rotateDeltaY-=b/c*(1.5*i.dragRotationRate),r.rotateDeltaX+=y/u*(1.5*i.dragRotationRate)));A=g,h=m}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{i.active&&i.pointerEnabled&&s.mouseover&&(g=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(i.active&&i.pointerEnabled)switch(e.which){case 1:case 2:case 3:n=!1,a=!1,l=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(i.active&&i.pointerEnabled){if(3===e.which){!function(e,t){if(e){let i=e.target,s=0,r=0,o=0,n=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,o+=i.scrollLeft,n+=i.scrollTop,i=i.offsetParent;t[0]=e.pageX+o-s,t[1]=e.pageY+n-r}else e=window.event,t[0]=e.x,t[1]=e.y}(e,ed);const i=ed[0],s=ed[1];Math.abs(i-c)<3&&Math.abs(s-u)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:ed,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{i.active&&i.pointerEnabled});const b=1/60;let y=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!i.active||!i.pointerEnabled)return;const t=performance.now()/1e3;var o=null!==y?t-y:0;y=t,o>.05&&(o=.05),o{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(i.keyboardEnabledOnlyIfMouseover&&!s.mouseover)return;const n=r._isKeyDownForAction(r.AXIS_VIEW_RIGHT),a=r._isKeyDownForAction(r.AXIS_VIEW_BACK),l=r._isKeyDownForAction(r.AXIS_VIEW_LEFT),A=r._isKeyDownForAction(r.AXIS_VIEW_FRONT),h=r._isKeyDownForAction(r.AXIS_VIEW_TOP),c=r._isKeyDownForAction(r.AXIS_VIEW_BOTTOM);if(!(n||a||l||A||h||c))return;const u=e.aabb,p=d.getAABB3Diag(u);d.getAABB3Center(u,id);const f=Math.abs(p/Math.tan(t.cameraFlight.fitFOV*d.DEGTORAD)),g=1.1*p;ad.orthoScale=g,n?(ad.eye.set(d.addVec3(id,d.mulVec3Scalar(o.worldRight,f,sd),nd)),ad.look.set(id),ad.up.set(o.worldUp)):a?(ad.eye.set(d.addVec3(id,d.mulVec3Scalar(o.worldForward,f,sd),nd)),ad.look.set(id),ad.up.set(o.worldUp)):l?(ad.eye.set(d.addVec3(id,d.mulVec3Scalar(o.worldRight,-f,sd),nd)),ad.look.set(id),ad.up.set(o.worldUp)):A?(ad.eye.set(d.addVec3(id,d.mulVec3Scalar(o.worldForward,-f,sd),nd)),ad.look.set(id),ad.up.set(o.worldUp)):h?(ad.eye.set(d.addVec3(id,d.mulVec3Scalar(o.worldUp,f,sd),nd)),ad.look.set(id),ad.up.set(d.normalizeVec3(d.mulVec3Scalar(o.worldForward,1,rd),od))):c&&(ad.eye.set(d.addVec3(id,d.mulVec3Scalar(o.worldUp,-f,sd),nd)),ad.look.set(id),ad.up.set(d.normalizeVec3(d.mulVec3Scalar(o.worldForward,-1,rd)))),!i.firstPerson&&i.followPointer&&t.pivotController.setPivotPos(id),t.cameraFlight.duration>0?t.cameraFlight.flyTo(ad,(()=>{t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(ad),t.pivotController.getPivoting()&&i.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class Ad{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let l=!1,A=!1;const h=this._scene.canvas.canvas,c=i=>{let s;i&&i.worldPos&&(s=i.worldPos);const r=i&&i.entity?i.entity.aabb:e.aabb;if(s){const i=e.camera;d.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})},u=e.tickify(this._canvasMouseMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(l||A)return;if(a.hasSubs("rayMove")){const t=d.vec3(),i=d.vec3();d.canvasPosToWorldRay(e.canvas.canvas,e.camera.viewMatrix,e.camera.projMatrix,e.camera.projection,s.pointerCanvasPos,t,i),a.fire("rayMove",{canvasPos:s.pointerCanvasPos,ray:{origin:t,direction:i,canvasPos:s.pointerCanvasPos}},!0)}const r=a.hasSubs("hover"),n=a.hasSubs("hoverEnter"),h=a.hasSubs("hoverOut"),c=a.hasSubs("hoverOff"),u=a.hasSubs("hoverSurface"),p=a.hasSubs("hoverSnapOrSurface");if(r||n||h||c||u||p)if(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=u,o.scheduleSnapOrPick=p,o.update(),o.pickResult){if(o.pickResult.entity){const t=o.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),a.fire("hoverEnter",o.pickResult,!0),this._lastPickedEntityId=t)}a.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&a.fire("hoverSurface",o.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(a.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),a.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)});h.addEventListener("mousemove",u),h.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(l=!0),3===t.which&&(A=!0);if(1===t.which&&i.active&&i.pointerEnabled&&(s.mouseDownClientX=t.clientX,s.mouseDownClientY=t.clientY,s.mouseDownCursorX=s.pointerCanvasPos[0],s.mouseDownCursorY=s.pointerCanvasPos[1],!i.firstPerson&&i.followPointer&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===t.which))){const t=o.pickResult;t&&t.worldPos?(n.setPivotPos(t.worldPos),n.startPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),n.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(l=!1),3===e.which&&(A=!1),n.getPivoting()&&n.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=r=>{if(!i.active||!i.pointerEnabled)return;if(!(1===r.which))return;if(n.hidePivot(),Math.abs(r.clientX-s.mouseDownClientX)>3||Math.abs(r.clientY-s.mouseDownClientY)>3)return;const l=a.hasSubs("picked"),A=a.hasSubs("pickedNothing"),h=a.hasSubs("pickedSurface"),u=a.hasSubs("doublePicked"),p=a.hasSubs("doublePickedSurface"),f=a.hasSubs("doublePickedNothing");if(!(i.doublePickFlyTo||u||p||f))return(l||A||h)&&(o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=h,o.update(),o.pickResult?(a.fire("picked",o.pickResult,!0),o.pickedSurface&&a.fire("pickedSurface",o.pickResult,!0)):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo,o.schedulePickSurface=h,o.update();const e=o.pickResult,r=o.pickedSurface;this._timeout=setTimeout((()=>{e&&e.worldPos?(a.fire("picked",e,!0),r&&(a.fire("pickedSurface",e,!0),!i.firstPerson&&i.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):a.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0),this._clicks=0}),i.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),o.pickCursorPos=s.pointerCanvasPos,o.schedulePickEntity=i.doublePickFlyTo||u||p,o.schedulePickSurface=o.schedulePickEntity&&p,o.update(),o.pickResult){if(a.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&a.fire("doublePickedSurface",o.pickResult,!0),i.doublePickFlyTo&&(c(o.pickResult),!i.firstPerson&&i.followPointer)){const e=o.pickResult.entity.aabb,i=d.getAABB3Center(e);t.pivotController.setPivotPos(i),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(a.fire("doublePickedNothing",{canvasPos:s.pointerCanvasPos},!0),i.doublePickFlyTo&&(c(),!i.firstPerson&&i.followPointer)){const i=e.aabb,s=d.getAABB3Center(i);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class hd{constructor(e,t,i,s,r){this._scene=e;const o=e.input,n=[],a=e.canvas.canvas;let l=!0;this._onSceneMouseMove=o.on("mousemove",(()=>{l=!0})),this._onSceneKeyDown=o.on("keydown",(t=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&(i.keyboardEnabledOnlyIfMouseover&&!s.mouseover||(n[t]=!0,t===o.KEY_SHIFT&&(a.style.cursor="move")))})),this._onSceneKeyUp=o.on("keyup",(s=>{i.active&&i.pointerEnabled&&e.input.keyboardEnabled&&(n[s]=!1,s===o.KEY_SHIFT&&(a.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(a=>{if(!i.active||!i.pointerEnabled||!e.input.keyboardEnabled)return;if(i.keyboardEnabledOnlyIfMouseover&&!s.mouseover)return;const A=t.cameraControl,h=a.deltaTime/1e3;if(!i.planView){const e=A._isKeyDownForAction(A.ROTATE_Y_POS,n),s=A._isKeyDownForAction(A.ROTATE_Y_NEG,n),o=A._isKeyDownForAction(A.ROTATE_X_POS,n),a=A._isKeyDownForAction(A.ROTATE_X_NEG,n),l=h*i.keyboardRotationRate;(e||s||o||a)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),e?r.rotateDeltaY+=l:s&&(r.rotateDeltaY-=l),o?r.rotateDeltaX+=l:a&&(r.rotateDeltaX-=l),!i.firstPerson&&i.followPointer&&t.pivotController.startPivot())}if(!n[o.KEY_CTRL]&&!n[o.KEY_ALT]){const e=A._isKeyDownForAction(A.DOLLY_BACKWARDS,n),o=A._isKeyDownForAction(A.DOLLY_FORWARDS,n);if(e||o){const n=h*i.keyboardDollyRate;!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),o?r.dollyDelta-=n:e&&(r.dollyDelta+=n),l&&(s.followPointerDirty=!0,l=!1)}}const c=A._isKeyDownForAction(A.PAN_FORWARDS,n),u=A._isKeyDownForAction(A.PAN_BACKWARDS,n),d=A._isKeyDownForAction(A.PAN_LEFT,n),p=A._isKeyDownForAction(A.PAN_RIGHT,n),f=A._isKeyDownForAction(A.PAN_UP,n),g=A._isKeyDownForAction(A.PAN_DOWN,n),m=(n[o.KEY_ALT]?.3:1)*h*i.keyboardPanRate;(c||u||d||p||f||g)&&(!i.firstPerson&&i.followPointer&&t.pivotController.startPivot(),g?r.panDeltaY+=m:f&&(r.panDeltaY+=-m),p?r.panDeltaX+=-m:d&&(r.panDeltaX+=m),u?r.panDeltaZ+=m:c&&(r.panDeltaZ+=-m))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const cd=d.vec3();class ud{constructor(e,t,i,s,r){this._scene=e;const o=e.camera,n=t.pickController,a=t.pivotController,l=t.panController;let A=1,h=1,c=null;this._onTick=e.on("tick",(()=>{if(!i.active||!i.pointerEnabled)return;let t="default";if(Math.abs(r.dollyDelta)<.001&&(r.dollyDelta=0),Math.abs(r.rotateDeltaX)<.001&&(r.rotateDeltaX=0),Math.abs(r.rotateDeltaY)<.001&&(r.rotateDeltaY=0),0===r.rotateDeltaX&&0===r.rotateDeltaY||(r.dollyDelta=0),i.followPointer){if(--A<=0&&(A=1,0!==r.dollyDelta)){if(0===r.rotateDeltaY&&0===r.rotateDeltaX&&i.followPointer&&s.followPointerDirty&&(n.pickCursorPos=s.pointerCanvasPos,n.schedulePickSurface=!0,n.update(),n.pickResult&&n.pickResult.worldPos?c=n.pickResult.worldPos:(h=1,c=null),s.followPointerDirty=!1),c){const t=Math.abs(d.lenVec3(d.subVec3(c,e.camera.eye,cd)));h=t/i.dollyProximityThreshold}h{s.mouseover=!0}),o.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{s.mouseover=!1,o.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{pd(e,o,s.pointerCanvasPos)}),o.addEventListener("mousedown",this._mouseDownHandler=e=>{i.active&&i.pointerEnabled&&(pd(e,o,s.pointerCanvasPos),s.mouseover=!0)}),o.addEventListener("mouseup",this._mouseUpHandler=e=>{i.active&&i.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function pd(e,t,i){if(e){const{left:s,top:r}=t.getBoundingClientRect();i[0]=e.clientX-s,i[1]=e.clientY-r}else e=window.event,i[0]=e.x,i[1]=e.y;return i}const fd=function(e,t){if(e){let i=e.target,s=0,r=0;for(;i.offsetParent;)s+=i.offsetLeft,r+=i.offsetTop,i=i.offsetParent;t[0]=e.pageX-s,t[1]=e.pageY-r}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class gd{constructor(e,t,i,s,r){this._scene=e;const o=t.pickController,n=t.pivotController,a=d.vec2(),l=d.vec2(),A=d.vec2(),h=d.vec2(),c=[],u=this._scene.canvas.canvas;let p=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),u.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!i.active||!i.pointerEnabled)return;t.preventDefault();const r=t.touches,l=t.changedTouches;for(s.touchStartTime=Date.now(),1===r.length&&1===l.length&&(fd(r[0],a),i.followPointer&&(o.pickCursorPos=a,o.schedulePickSurface=!0,o.update(),i.planView||(o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(n.setPivotPos(o.pickResult.worldPos),!i.firstPerson&&n.startPivot()&&n.showPivot()):(i.smartPivot?n.setCanvasPivotPos(s.pointerCanvasPos):n.setPivotPos(e.camera.look),!i.firstPerson&&n.startPivot()&&n.showPivot()))));c.length{n.getPivoting()&&n.endPivot()}),u.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!i.active||!i.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const n=e.canvas.boundary,a=n[2],u=n[3],g=t.touches;if(t.touches.length===p){if(1===p){fd(g[0],l),d.subVec2(l,c[0],h);const t=h[0],o=h[1];if(null!==s.longTouchTimeout&&(Math.abs(t)>i.longTapRadius||Math.abs(o)>i.longTapRadius)&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),i.planView){const s=e.camera;if("perspective"===s.projection){const n=Math.abs(e.camera.eyeLookDist)*Math.tan(s.perspective.fov/2*Math.PI/180);r.panDeltaX+=t*n/u*i.touchPanRate,r.panDeltaY+=o*n/u*i.touchPanRate}else r.panDeltaX+=.5*s.ortho.scale*(t/u)*i.touchPanRate,r.panDeltaY+=.5*s.ortho.scale*(o/u)*i.touchPanRate}else r.rotateDeltaY-=t/a*(1*i.dragRotationRate),r.rotateDeltaX+=o/u*(1.5*i.dragRotationRate)}else if(2===p){const t=g[0],n=g[1];fd(t,l),fd(n,A);const a=d.geometricMeanVec2(c[0],c[1]),h=d.geometricMeanVec2(l,A),p=d.vec2();d.subVec2(a,h,p);const f=p[0],m=p[1],_=e.camera,v=d.distVec2([t.pageX,t.pageY],[n.pageX,n.pageY]),b=(d.distVec2(c[0],c[1])-v)*i.touchDollyRate;if(r.dollyDelta=b,Math.abs(b)<1)if("perspective"===_.projection){const t=o.pickResult?o.pickResult.worldPos:e.center,s=Math.abs(d.lenVec3(d.subVec3(t,e.camera.eye,[])))*Math.tan(_.perspective.fov/2*Math.PI/180);r.panDeltaX-=f*s/u*i.touchPanRate,r.panDeltaY-=m*s/u*i.touchPanRate}else r.panDeltaX-=.5*_.ortho.scale*(f/u)*i.touchPanRate,r.panDeltaY-=.5*_.ortho.scale*(m/u)*i.touchPanRate;s.pointerCanvasPos=h}for(let e=0;e{let s;i&&i.worldPos&&(s=i.worldPos);const r=i?i.entity.aabb:e.aabb;if(s){const i=e.camera;d.subVec3(i.eye,i.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})};u.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!i.active||!i.pointerEnabled)return;null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null);const r=e.touches,o=e.changedTouches;if(a=Date.now(),1===r.length&&1===o.length){h=a,md(r[0],A);const o=A[0],n=A[1],l=r[0].pageX,c=r[0].pageY;s.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(l),Math.round(c)],canvasPos:[Math.round(o),Math.round(n)],event:e},!0),s.longTouchTimeout=null}),i.longTapTimeout)}else h=-1;for(;l.length{if(!i.active||!i.pointerEnabled)return;const t=Date.now(),r=e.touches,a=e.changedTouches,u=n.hasSubs("pickedSurface");null!==s.longTouchTimeout&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),0===r.length&&1===a.length&&h>-1&&t-h<150&&(c>-1&&h-c<325?(md(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=u,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("doublePicked",o.pickResult),o.pickedSurface&&n.fire("doublePickedSurface",o.pickResult),i.doublePickFlyTo&&p(o.pickResult)):(n.fire("doublePickedNothing"),i.doublePickFlyTo&&p()),c=-1):d.distVec2(l[0],A)<4&&(md(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=u,o.update(),o.pickResult?(o.pickResult.touchInput=!0,n.fire("picked",o.pickResult),o.pickedSurface&&n.fire("pickedSurface",o.pickResult)):n.fire("pickedNothing"),c=t),h=-1),l.length=r.length;for(let e=0,t=r.length;e{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,keyboardEnabledOnlyIfMouseover:!0,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:d.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:d.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const i=this.scene;this._controllers={cameraControl:this,pickController:new $u(this,this._configs),pivotController:new qu(i,this._configs),panController:new zu(i),cameraFlight:new cu(this,{duration:.5})},this._handlers=[new dd(this.scene,this._controllers,this._configs,this._states,this._updates),new gd(this.scene,this._controllers,this._configs,this._states,this._updates),new td(this.scene,this._controllers,this._configs,this._states,this._updates),new ld(this.scene,this._controllers,this._configs,this._states,this._updates),new Ad(this.scene,this._controllers,this._configs,this._states,this._updates),new _d(this.scene,this._controllers,this._configs,this._states,this._updates),new hd(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new ud(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",y.isString(e)){const t=this.scene.input,i={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":i[this.PAN_LEFT]=[t.KEY_A],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_Z],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":i[this.PAN_LEFT]=[t.KEY_Q],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_W],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=i}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const i=this._keyMap[e];if(!i)return!1;t||(t=this.scene.input.keyDown);for(let e=0,s=i.length;e0&&console.error(`[MetaModel._decompressProperties] Properties not found: ${i}`)}finalize(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";const e=this.metaScene;for(let t in e.metaObjects){const i=e.metaObjects[t];if(i.children&&(i.children=[]),i.propertySets&&(i.propertySets=[]),i.propertySetIds)for(let t=0,s=i.propertySetIds.length;t0?Pd(t):null,n=i&&i.length>0?Pd(i):null,a=e=>{if(!e)return;var t=!0;(n&&n[e.type]||o&&!o[e.type])&&(t=!1),t&&s.push(e.id);const i=e.children;if(i)for(var r=0,l=i.length;r * Copyright (c) 2022 Niklas von Hertzen diff --git a/dist/xeokit-sdk.min.es5.js b/dist/xeokit-sdk.min.es5.js index f6ea2228a..7f93d66e6 100644 --- a/dist/xeokit-sdk.min.es5.js +++ b/dist/xeokit-sdk.min.es5.js @@ -14,7 +14,7 @@ var e,t=a().mark(Ax),i=a().mark(cx),r=a().mark(wM);function s(e,t){var i=Object. /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT - **/var ih=null;function rh(e,t){var i,r,s,n,o,a,l=3*e,u=3*t,A=Math.min(i=ih[l],r=ih[l+1],s=ih[l+2]),c=Math.min(n=ih[u],o=ih[u+1],a=ih[u+2]);if(A!==c)return A-c;var h=Math.max(i,r,s),d=Math.max(n,o,a);return h!==d?h-d:0}function sh(e,t){for(var i=new Int32Array(e.length/3),r=0,s=i.length;r>t;i.sort(rh);for(var a=new Int32Array(e.length),l=0,u=i.length;le[s+1]){var o=e[s];e[s]=e[s+1],e[s+1]=o}nh=new Int32Array(e),t.sort(oh);for(var a=new Int32Array(e.length),l=0,u=t.length;l0)for(var r=i._meshes,s=0,n=r.length;s0)for(var o=this._meshes,a=0,l=o.length;a1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).renderOrder=s.renderOrder||0,r._dtxEnabled=r.scene.dtxEnabled&&!1!==s.dtxEnabled,r._enableVertexWelding=!1,r._enableIndexBucketing=!1,r._vboBatchingLayerScratchMemory=yo(),r._textureTranscoder=s.textureTranscoder||Zc(r.scene.viewer),r._maxGeometryBatchSize=s.maxGeometryBatchSize,r._aabb=re.collapseAABB3(),r._aabbDirty=!0,r._quantizationRanges={},r._vboInstancingLayers={},r._vboBatchingLayers={},r._dtxLayers={},r._meshList=[],r.layerList=[],r._entityList=[],r._geometries={},r._dtxBuckets={},r._textures={},r._textureSets={},r._transforms={},r._meshes={},r._unusedMeshes={},r._entities={},r.renderFlags=new on,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=s.edgeThreshold||10,r._origin=re.vec3(s.origin||[0,0,0]),r._position=re.vec3(s.position||[0,0,0]),r._rotation=re.vec3(s.rotation||[0,0,0]),r._quaternion=re.vec4(s.quaternion||[0,0,0,1]),r._conjugateQuaternion=re.vec4(s.quaternion||[0,0,0,1]),s.rotation&&re.eulerToQuaternion(r._rotation,"XYZ",r._quaternion),r._scale=re.vec3(s.scale||[1,1,1]),r._worldRotationMatrix=re.mat4(),r._worldRotationMatrixConjugate=re.mat4(),r._matrix=re.mat4(),r._matrixDirty=!0,r._rebuildMatrices(),r._worldNormalMatrix=re.mat4(),re.inverseMat4(r._matrix,r._worldNormalMatrix),re.transposeMat4(r._worldNormalMatrix),(s.matrix||s.position||s.rotation||s.scale||s.quaternion)&&(r._viewMatrix=re.mat4(),r._viewNormalMatrix=re.mat4(),r._viewMatrixDirty=!0,r._matrixNonIdentity=!0),r._opacity=1,r._colorize=[1,1,1],r._saoEnabled=!1!==s.saoEnabled,r._pbrEnabled=!1!==s.pbrEnabled,r._colorTextureEnabled=!1!==s.colorTextureEnabled,r._isModel=s.isModel,r._isModel&&r.scene._registerModel(b(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=s.visible,r.culled=s.culled,r.pickable=s.pickable,r.clippable=s.clippable,r.collidable=s.collidable,r.castsShadow=s.castsShadow,r.receivesShadow=s.receivesShadow,r.xrayed=s.xrayed,r.highlighted=s.highlighted,r.selected=s.selected,r.edges=s.edges,r.colorize=s.colorize,r.opacity=s.opacity,r.backfaces=s.backfaces,r}return C(i,[{key:"_meshMatrixDirty",value:function(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}},{key:"_createDefaultTextureSet",value:function(){var e=new Qc({id:"defaultColorTexture",texture:new Gn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Qc({id:"defaultMetalRoughTexture",texture:new Gn({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),i=new Qc({id:"defaultNormalsTexture",texture:new Gn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),r=new Qc({id:"defaultEmissiveTexture",texture:new Gn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),s=new Qc({id:"defaultOcclusionTexture",texture:new Gn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=i,this._textures.defaultEmissiveTexture=r,this._textures.defaultOcclusionTexture=s,this._textureSets.defaultTextureSet=new Nc({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:i,emissiveTexture:r,occlusionTexture:s})}},{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]),re.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]),re.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||Bh),re.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),re.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),re.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),re.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&&(re.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),re.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),re.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),re.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}},{key:"rotationMatrixConjugate",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}},{key:"_setWorldMatrixDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0}},{key:"_transformDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}},{key:"_sceneModelDirty",value:function(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(var e=0,t=this._entityList.length;e0},set:function(e){e=!1!==e,this._visible=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._selected=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._edges=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,i=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var l=e.colors,u=new Uint8Array(l.length),A=0,c=l.length;A>24&255,s=i>>16&255,n=i>>8&255,o=255&i;switch(e.pickColor=new Uint8Array([o,n,s,r]),e.solid="solid"===e.primitive,t.origin=re.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),this._meshes[e.id]=t,this._unusedMeshes[e.id]=t,this._meshList.push(t),t}},{key:"_getNumPrimitives",value:function(e){var t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(var i=0,r=e.buckets.length;i>>0).toString(16)}},{key:"_getVBOInstancingLayer",value:function(e){var t=this,i=e.origin,r=e.textureSetId||"-",s=e.geometryId,n="".concat(Math.round(i[0]),".").concat(Math.round(i[1]),".").concat(Math.round(i[2]),".").concat(r,".").concat(s),o=this._vboInstancingLayers[n];if(o)return o;for(var a=e.textureSet,l=e.geometry;!o;)switch(l.primitive){case"triangles":case"surface":o=new ml({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!1});break;case"solid":o=new ml({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!0});break;case"lines":o=new ru({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0});break;case"points":o=new Ju({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0})}return this._vboInstancingLayers[n]=o,this.layerList.push(o),o}},{key:"createEntity",value:function(e){if(void 0===e.id?e.id=re.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=re.createUUID()),void 0!==e.meshIds){var t=0;this._visible&&!1!==e.visible&&(t|=We),this._pickable&&!1!==e.pickable&&(t|=Xe),this._culled&&!1!==e.culled&&(t|=Ke),this._clippable&&!1!==e.clippable&&(t|=Ye),this._collidable&&!1!==e.collidable&&(t|=Je),this._edges&&!1!==e.edges&&(t|=et),this._xrayed&&!1!==e.xrayed&&(t|=Ze),this._highlighted&&!1!==e.highlighted&&(t|=qe),this._selected&&!1!==e.selected&&(t|=$e),e.flags=t,this._createEntity(e)}else this.error("Config missing: meshIds")}},{key:"_createEntity",value:function(e){for(var t=[],i=0,r=e.meshIds.length;it.sortId?1:0}));for(var o=0,a=this.layerList.length;o0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}},{key:"_updateRenderFlagsVisibleLayers",value:function(){var e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(var t=0,i=this.layerList.length;t0){var t="".concat(this.id,"-dummyEntityForUnusedMeshes");this.warn('Creating dummy SceneModelEntity "'.concat(t,'" for unused SceneMeshes: [').concat(e.join(","),"]")),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}},{key:"_getActiveSectionPlanesForLayer",value:function(e){var t=this.renderFlags,i=this.scene._sectionPlanesState.sectionPlanes,r=i.length,s=e.layerIndex*r;if(r>0)for(var n=0;n0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){var t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0)this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0));if(this.numSelectedLayerPortions>0){var i=this.scene.selectedMaterial._state;i.fill&&(i.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),i.edges&&(i.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){var 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,t){for(var i=this.renderFlags,r=0,s=i.visibleLayers.length;r2&&void 0!==arguments[2]&&arguments[2],r=e.positionsCompressed||[],s=sh(e.indices||[],t),n=ah(e.edgeIndices||[]);function o(e,t){if(e>t){var i=e;e=t,t=i}function r(i,r){return i!==e?e-i:r!==t?t-r:0}for(var s=0,o=(n.length>>1)-1;s<=o;){var a=o+s>>1,l=r(n[2*a],n[2*a+1]);if(l>0)s=a+1;else{if(!(l<0))return a;o=a-1}}return-s-1}var a=new Int32Array(n.length/2);a.fill(0);var l=r.length/3;if(l>8*(1<h.maxNumPositions&&(h=c()),h.bucketNumber>8)return[e];-1===u[v]&&(u[v]=h.numPositions++,h.positionsCompressed.push(r[3*v]),h.positionsCompressed.push(r[3*v+1]),h.positionsCompressed.push(r[3*v+2])),-1===u[g]&&(u[g]=h.numPositions++,h.positionsCompressed.push(r[3*g]),h.positionsCompressed.push(r[3*g+1]),h.positionsCompressed.push(r[3*g+2])),-1===u[m]&&(u[m]=h.numPositions++,h.positionsCompressed.push(r[3*m]),h.positionsCompressed.push(r[3*m+1]),h.positionsCompressed.push(r[3*m+2])),h.indices.push(u[v]),h.indices.push(u[g]),h.indices.push(u[m]);var _=void 0;(_=o(v,g))>=0&&0===a[_]&&(a[_]=1,h.edgeIndices.push(u[n[2*_]]),h.edgeIndices.push(u[n[2*_+1]])),(_=o(v,m))>=0&&0===a[_]&&(a[_]=1,h.edgeIndices.push(u[n[2*_]]),h.edgeIndices.push(u[n[2*_+1]])),(_=o(g,m))>=0&&0===a[_]&&(a[_]=1,h.edgeIndices.push(u[n[2*_]]),h.edgeIndices.push(u[n[2*_+1]]))}var y=t/8*2,b=t/8,w=2*r.length+(s.length+n.length)*y,B=0;return r.length,A.forEach((function(e){B+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*b,e.positionsCompressed.length})),B>w?[e]:(i&&lh(A,e),A)}({positionsCompressed:r,indices:s,edgeIndices:n},r.length/3>65536?16:8):o=[{positionsCompressed:r,indices:s,edgeIndices:n}];return o}var Mh=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(r=t.call(this,e,s))._positions=s.positions||[],s.indices)r._indices=s.indices;else{r._indices=[];for(var n=0,o=r._positions.length/3-1;n1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,"BCFViewpoints",e,s)).originatingSystem=s.originatingSystem||"xeokit.io",r.authoringTool=s.authoringTool||"xeokit.io",r}return C(i,[{key:"getViewpoint",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=this.viewer.scene,r=i.camera,s=i.realWorldOffset,n=!0===t.reverseClippingPlanes,o={},a=re.normalizeVec3(re.subVec3(r.look,r.eye,re.vec3())),l=r.eye,u=r.up;r.yUp&&(a=Lh(a),l=Lh(l),u=Lh(u));var A=Sh(re.addVec3(l,s));"ortho"===r.projection?o.orthogonal_camera={camera_view_point:A,camera_direction:Sh(a),camera_up_vector:Sh(u),view_to_world_scale:r.ortho.scale}:o.perspective_camera={camera_view_point:A,camera_direction:Sh(a),camera_up_vector:Sh(u),field_of_view:r.perspective.fov};var h=i.sectionPlanes;for(var d in h)if(h.hasOwnProperty(d)){var p=h[d];if(!p.active)continue;var f=p.pos,v=void 0;v=n?re.negateVec3(p.dir,re.vec3()):p.dir,r.yUp&&(f=Lh(f),v=Lh(v)),re.addVec3(f,s),f=Sh(f),v=Sh(v),o.clipping_planes||(o.clipping_planes=[]),o.clipping_planes.push({location:f,direction:v})}var g=i.lineSets;for(var m in g)if(g.hasOwnProperty(m)){var _=g[m];o.lines||(o.lines=[]);for(var y=_.positions,b=_.indices,w=0,B=b.length/2;w1&&void 0!==arguments[1]?arguments[1]:{};if(e){var r=this.viewer,s=r.scene,n=s.camera,o=!1!==i.rayCast,a=!1!==i.immediate,l=!1!==i.reset,u=s.realWorldOffset,A=!0===i.reverseClippingPlanes;if(s.clearSectionPlanes(),e.clipping_planes&&e.clipping_planes.length>0&&e.clipping_planes.forEach((function(e){var t=Th(e.location,Eh),i=Th(e.direction,Eh);A&&re.negateVec3(i),re.subVec3(t,u),n.yUp&&(t=Rh(t),i=Rh(i)),new xn(s,{pos:t,dir:i})})),s.clearLines(),e.lines&&e.lines.length>0){var c=[],h=[],d=0;e.lines.forEach((function(e){e.start_point&&e.end_point&&(c.push(e.start_point.x),c.push(e.start_point.y),c.push(e.start_point.z),c.push(e.end_point.x),c.push(e.end_point.y),c.push(e.end_point.z),h.push(d++),h.push(d++))})),new Mh(s,{positions:c,indices:h,clippable:!1,collidable:!0})}if(s.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){var t=e.bitmap_type||"jpg",i=e.bitmap_data,r=Th(e.location,Fh),o=Th(e.normal,kh),a=Th(e.up,Ih),l=e.height||1;t&&i&&r&&o&&a&&(n.yUp&&(r=Rh(r),o=Rh(o),a=Rh(a)),new ho(s,{src:i,type:t,pos:r,normal:o,up:a,clippable:!1,collidable:!0,height:l}))})),l&&(s.setObjectsXRayed(s.xrayedObjectIds,!1),s.setObjectsHighlighted(s.highlightedObjectIds,!1),s.setObjectsSelected(s.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(s.setObjectsVisible(s.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.visible=!1}))}))):(s.setObjectsVisible(s.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.visible=!0}))})));var p=e.components.visibility.view_setup_hints;p&&(!1===p.spaces_visible&&s.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcSpace"),!1),void 0!==p.spaces_translucent&&s.setObjectsXRayed(r.metaScene.getObjectIDsByType("IfcSpace"),!0),p.space_boundaries_visible,!1===p.openings_visible&&s.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcOpening"),!0),p.space_boundaries_translucent,void 0!==p.openings_translucent&&s.setObjectsXRayed(r.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(s.setObjectsSelected(s.selectedObjectIds,!1),e.components.selection.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.selected=!0}))}))),e.components.translucency&&(s.setObjectsXRayed(s.xrayedObjectIds,!1),e.components.translucency.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.xrayed=!0}))}))),e.components.coloring&&e.components.coloring.forEach((function(e){var r=e.color,s=0,n=!1;8===r.length&&((s=parseInt(r.substring(0,2),16)/256)<=1&&s>=.95&&(s=1),r=r.substring(2),n=!0);var o=[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(i,e,(function(e){e.colorize=o,n&&(e.opacity=s)}))}))}))}if(e.perspective_camera||e.orthogonal_camera){var f,v,g,m;if(e.perspective_camera?(f=Th(e.perspective_camera.camera_view_point,Eh),v=Th(e.perspective_camera.camera_direction,Eh),g=Th(e.perspective_camera.camera_up_vector,Eh),n.perspective.fov=e.perspective_camera.field_of_view,m="perspective"):(f=Th(e.orthogonal_camera.camera_view_point,Eh),v=Th(e.orthogonal_camera.camera_direction,Eh),g=Th(e.orthogonal_camera.camera_up_vector,Eh),n.ortho.scale=e.orthogonal_camera.view_to_world_scale,m="ortho"),re.subVec3(f,u),n.yUp&&(f=Rh(f),v=Rh(v),g=Rh(g)),o){var _=s.pick({pickSurface:!0,origin:f,direction:v});v=_?_.worldPos:re.addVec3(f,v,Eh)}else v=re.addVec3(f,v,Eh);a?(n.eye=f,n.look=v,n.up=g,n.projection=m):r.cameraFlight.flyTo({eye:f,look:v,up:g,duration:i.duration,projection:m})}}}},{key:"_withBCFComponent",value:function(e,t,i){var r=this.viewer,s=r.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){var n=t.authoring_tool_id,o=s.objects[n];if(o)return void i(o);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[n])return void s.withObjects(r.metaScene.getObjectIDsInSubtree(n),i)}if(t.ifc_guid){var a=t.ifc_guid,l=s.objects[a];if(l)return void i(l);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[a])return void s.withObjects(r.metaScene.getObjectIDsInSubtree(a),i);Object.keys(s.models).forEach((function(t){var n=re.globalizeObjectId(t,a),o=s.objects[n];o?i(o):e.updateCompositeObjects&&r.metaScene.metaObjects[n]&&s.withObjects(r.metaScene.getObjectIDsInSubtree(n),i)}))}}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this)}}]),i}();function Sh(e){return{x:e[0],y:e[1],z:e[2]}}function Th(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function Lh(e){return new Float64Array([e[0],-e[2],e[1]])}function Rh(e){return new Float64Array([e[0],e[2],-e[1]])}function Uh(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 Oh=re.vec3(),Nh=function(e,t,i,r){var s=e-i,n=t-r;return Math.sqrt(s*s+n*n)};var Qh=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(r=t.call(this,e.viewer.scene,s)).plugin=e,r._container=s.container,!r._container)throw"config missing: container";r._eventSubs={};var n=r.plugin.viewer.scene;r._originWorld=re.vec3(),r._targetWorld=re.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=s.color||r.plugin.defaultColor;var o=s.onMouseOver?function(e){s.onMouseOver(e,b(r)),r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,a=s.onMouseLeave?function(e){s.onMouseLeave(e,b(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))},A=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},c=s.onContextMenu?function(e){s.onContextMenu(e,b(r))}:null,h=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return r._originDot=new ut(n,s.origin,r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._targetDot=new ut(n,s.target,r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._lengthWire=new ht(r._container,{color:r._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._xAxisWire=new ht(r._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._yAxisWire=new ht(r._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._zAxisWire=new ht(r._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._lengthLabel=new dt(r._container,{fillColor:r._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._xAxisLabel=new dt(r._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._yAxisLabel=new dt(r._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._zAxisLabel=new dt(r._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._measurementOrientation="Horizontal",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._xLabelEnabled=!1,r._yLabelEnabled=!1,r._zLabelEnabled=!1,r._lengthLabelEnabled=!1,r._labelsVisible=!1,r._labelsOnWires=!1,r._clickable=!1,r._originDot.on("worldPos",(function(e){r._originWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._targetDot.on("worldPos",(function(e){r._targetWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._onViewMatrix=n.camera.on("viewMatrix",(function(){r._vpDirty=!0,r._needUpdate(0)})),r._onProjMatrix=n.camera.on("projMatrix",(function(){r._cpDirty=!0,r._needUpdate()})),r._onCanvasBoundary=n.canvas.on("boundary",(function(){r._cpDirty=!0,r._needUpdate(0)})),r._onMetricsUnits=n.metrics.on("units",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsScale=n.metrics.on("scale",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsOrigin=n.metrics.on("origin",(function(){r._cpDirty=!0,r._needUpdate()})),r._onSectionPlaneUpdated=n.on("sectionPlaneUpdated",(function(){r._sectionPlanesDirty=!0,r._needUpdate()})),r.approximate=s.approximate,r.visible=s.visible,r.originVisible=s.originVisible,r.targetVisible=s.targetVisible,r.wireVisible=s.wireVisible,r.axisVisible=s.axisVisible,r.xAxisVisible=s.xAxisVisible,r.yAxisVisible=s.yAxisVisible,r.zAxisVisible=s.zAxisVisible,r.xLabelEnabled=s.xLabelEnabled,r.yLabelEnabled=s.yLabelEnabled,r.zLabelEnabled=s.zLabelEnabled,r.lengthLabelEnabled=s.lengthLabelEnabled,r.labelsVisible=s.labelsVisible,r.labelsOnWires=s.labelsOnWires,r.useRotationAdjustment=s.useRotationAdjustment,r}return C(i,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;if(this._wpDirty&&(this._measurementOrientation=function(e,t,i){return Math.abs(t[1]-e[1])>i?"Vertical":"Horizontal"}(this._originWorld,this._targetWorld,0),"Vertical"===this._measurementOrientation&&this.useRotationAdjustment?(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._originWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._originWorld[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._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&&(re.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._originWorld)||this._isSliced(this._targetWorld))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}var t=this._originDot.viewPos[2],i=this._targetDot.viewPos[2];if(t>-.3||i>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){re.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var r=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect(),o=this._container.getBoundingClientRect(),a=n.top-o.top,l=n.left-o.left,u=e.canvas.boundary,A=u[2],c=u[3],h=0,d=this.plugin.viewer.scene.metrics,p=d.scale,f=d.units,v=d.unitsInfo[f].abbrev,g=0,m=r.length;g1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e.viewer.scene))._canvasToPagePos=s.canvasToPagePos,r.pointerLens=s.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!==s.snapping,r._mouseState=0,r._attachPlugin(e,s),r}return C(i,[{key:"_initMarkerDiv",value:function(){var e=document.createElement("div");e.setAttribute("id","myMarkerDiv");var t=this.scene.canvas.canvas;t.parentNode.insertBefore(e,t),e.style.background="black",e.style.border="2px solid blue",e.style.borderRadius="10px",e.style.width="5px",e.style.height="5px",e.style.top="-200px",e.style.left="-200px",e.style.margin="0 0",e.style.zIndex="100",e.style.position="absolute",e.style.pointerEvents="none",this._markerDiv=e}},{key:"_destroyMarkerDiv",value:function(){if(this._markerDiv){var e=document.getElementById("myMarkerDiv");e.parentNode.removeChild(e),this._markerDiv=null}}},{key:"_attachPlugin",value:function(e){this.distanceMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){this._markerDiv||this._initMarkerDiv(),this.fire("activated",!0);var t=this.distanceMeasurementsPlugin,i=this.scene,r=t.viewer.cameraControl,s=i.canvas.canvas;i.input;var n,o,a=!1,l=re.vec3(),u=re.vec2(),A=null;this._mouseState=0;var c=function e(t){return t.offsetTop+(t.offsetParent&&t.offsetParent!==s.parentNode&&e(t.offsetParent))},h=function e(t){return t.offsetLeft+(t.offsetParent&&t.offsetParent!==s.parentNode&&e(t.offsetParent))},d=re.vec2();this._onCameraControlHoverSnapOrSurface=r.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(function(t){var i=t.snappedCanvasPos||t.canvasPos;a=!0,l.set(t.worldPos),u.set(t.canvasPos),0===e._mouseState?(e._canvasToPagePos?(e._canvasToPagePos(s,i,d),e._markerDiv.style.left="".concat(d[0]-5,"px"),e._markerDiv.style.top="".concat(d[1]-5,"px")):(e._markerDiv.style.left="".concat(h(s)+i[0]-5,"px"),e._markerDiv.style.top="".concat(c(s)+i[1]-5,"px")),e._markerDiv.style.background="pink",t.snappedToVertex||t.snappedToEdge?(e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.snappedCanvasPos||t.canvasPos,e.pointerLens.snapped=!0),e._markerDiv.style.background="greenyellow",e._markerDiv.style.border="2px solid green"):(e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.canvasPos,e.pointerLens.snapped=!1),e._markerDiv.style.background="pink",e._markerDiv.style.border="2px solid red"),A=t.entity):(e._markerDiv.style.left="-10000px",e._markerDiv.style.top="-10000px"),s.style.cursor="pointer",e._currentDistanceMeasurement&&(e._currentDistanceMeasurement.wireVisible=e._currentDistanceMeasurementInitState.wireVisible,e._currentDistanceMeasurement.axisVisible=e._currentDistanceMeasurementInitState.axisVisible&&e.distanceMeasurementsPlugin.defaultAxisVisible,e._currentDistanceMeasurement.xAxisVisible=e._currentDistanceMeasurementInitState.xAxisVisible&&e.distanceMeasurementsPlugin.defaultXAxisVisible,e._currentDistanceMeasurement.yAxisVisible=e._currentDistanceMeasurementInitState.yAxisVisible&&e.distanceMeasurementsPlugin.defaultYAxisVisible,e._currentDistanceMeasurement.zAxisVisible=e._currentDistanceMeasurementInitState.zAxisVisible&&e.distanceMeasurementsPlugin.defaultZAxisVisible,e._currentDistanceMeasurement.targetVisible=e._currentDistanceMeasurementInitState.targetVisible,e._currentDistanceMeasurement.target.worldPos=l.slice(),e._markerDiv.style.left="-10000px",e._markerDiv.style.top="-10000px")})),s.addEventListener("mousedown",this._onMouseDown=function(e){1===e.which&&(n=e.clientX,o=e.clientY)}),s.addEventListener("mouseup",this._onMouseUp=function(i){1===i.which&&(i.clientX>n+20||i.clientXo+20||i.clientY1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,"DistanceMeasurements",e))._pointerLens=s.pointerLens,r._container=s.container||document.body,r._defaultControl=null,r._measurements={},r.labelMinAxisLength=s.labelMinAxisLength,r.defaultVisible=!1!==s.defaultVisible,r.defaultOriginVisible=!1!==s.defaultOriginVisible,r.defaultTargetVisible=!1!==s.defaultTargetVisible,r.defaultWireVisible=!1!==s.defaultWireVisible,r.defaultXLabelEnabled=!1!==s.defaultXLabelEnabled,r.defaultYLabelEnabled=!1!==s.defaultYLabelEnabled,r.defaultZLabelEnabled=!1!==s.defaultZLabelEnabled,r.defaultLengthLabelEnabled=!1!==s.defaultLengthLabelEnabled,r.defaultLabelsVisible=!1!==s.defaultLabelsVisible,r.defaultAxisVisible=!1!==s.defaultAxisVisible,r.defaultXAxisVisible=!1!==s.defaultXAxisVisible,r.defaultYAxisVisible=!1!==s.defaultYAxisVisible,r.defaultZAxisVisible=!1!==s.defaultZAxisVisible,r.defaultColor=void 0!==s.defaultColor?s.defaultColor:"#00BBFF",r.zIndex=s.zIndex||1e4,r.defaultLabelsOnWires=!1!==s.defaultLabelsOnWires,r.useRotationAdjustment=void 0!==s.useRotationAdjustment&&!1!==s.useRotationAdjustment,r._onMouseOver=function(e,t){r.fire("mouseOver",{plugin:b(r),distanceMeasurement:t,measurement:t,event:e})},r._onMouseLeave=function(e,t){r.fire("mouseLeave",{plugin:b(r),distanceMeasurement:t,measurement:t,event:e})},r._onContextMenu=function(e,t){r.fire("contextMenu",{plugin:b(r),distanceMeasurement:t,measurement:t,event:e})},r}return C(i,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){}},{key:"pointerLens",get:function(){return this._pointerLens}},{key:"control",get:function(){return this._defaultControl||(this._defaultControl=new Hh(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:"useRotationAdjustment",get:function(){return this._useRotationAdjustment},set:function(e){e=void 0!==e&&Boolean(e),this._useRotationAdjustment=e}},{key:"createMeasurement",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.viewer.scene.components[t.id]&&(this.error("Viewer scene component with this ID already exists: "+t.id),delete t.id);var i=t.origin,r=t.target,s=new Qh(this,{id:t.id,plugin:this,container:this._container,origin:{entity:i.entity,worldPos:i.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,xLabelEnabled:!1!==t.xLabelEnabled&&!1!==this.defaultXLabelEnabled,yLabelEnabled:!1!==t.yLabelEnabled&&!1!==this.defaultYLabelEnabled,zLabelEnabled:!1!==t.zLabelEnabled&&!1!==this.defaultZLabelEnabled,lengthLabelEnabled:!1!==t.lengthLabelEnabled&&!1!==this.defaultLengthLabelEnabled,labelsVisible:!1!==t.labelsVisible&&!1!==this.defaultLabelsVisible,useRotationAdjustment:this.useRotationAdjustment,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[s.id]=s,s.clickable=!0,s.on("destroyed",(function(){delete e._measurements[s.id]})),this.fire("measurementCreated",s),s}},{key:"destroyMeasurement",value:function(e){var t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("DistanceMeasurement not found: "+e)}},{key:"setLabelsShown",value:function(e){for(var t=0,i=Object.entries(this.measurements);t1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(r=t.call(this,e.viewer.scene)).pointerLens=s.pointerLens,r.pointerCircle=new Re(e.viewer),r._active=!1;var n=document.createElement("div"),o=r.scene.canvas.canvas;return o.parentNode.insertBefore(n,o),n.style.background="black",n.style.border="2px solid blue",n.style.borderRadius="10px",n.style.width="5px",n.style.height="5px",n.style.margin="-200px -200px",n.style.zIndex="100",n.style.position="absolute",n.style.pointerEvents="none",r.markerDiv=n,r._currentDistanceMeasurement=null,r._currentDistanceMeasurementInitState={wireVisible:null,axisVisible:null,xAxisVisible:null,yaxisVisible:null,zAxisVisible:null,targetVisible:null},r._onCanvasTouchStart=null,r._onCanvasTouchEnd=null,r._longTouchTimeoutMs=300,r._snapping=!1!==s.snapping,r._touchState=0,r._attachPlugin(e,s),r}return C(i,[{key:"_attachPlugin",value:function(e){this.distanceMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){var t=this.plugin,i=this.scene,r=i.canvas.canvas;t.pointerLens;var s=re.vec3(),n=20,o=null;this._touchState=0;var a=re.vec2(),l=re.vec2(),u=re.vec2(),A=null,c=function(){e.plugin.viewer.cameraControl.active=!1},h=function(){e.plugin.viewer.cameraControl.active=!0};r.addEventListener("touchstart",this._onCanvasTouchStart=function(r){var u=r.touches.length;if(1===u){var d=r.touches[0],p=d.clientX,f=d.clientY;switch(a.set([p,f]),l.set([p,f]),e._touchState){case 0:if(1!==u&&null!==o)return o&&(clearTimeout(o),o=null),e._currentDistanceMeasurement&&(e._currentDistanceMeasurement.destroy(),e._currentDistanceMeasurement=null),h(),void(e._touchState=0);var v=i.pick({canvasPos:l,snapping:e._snapping,snapToEdge:e._snapping});if(v&&v.snapped)s.set(v.worldPos),e.pointerCircle.start(v.snappedCanvasPos);else{var g=i.pick({canvasPos:l,pickSurface:!0});if(!g||!g.worldPos)return;s.set(g.worldPos),e.pointerCircle.start(g.canvasPos)}o=setTimeout((function(){1!==u||l[0]>a[0]+n||l[0]a[1]+n||l[1]a[0]+n||l[0]a[1]+n||l[1]a[0]+n||da[1]+n||pa[0]+n||da[1]+n||p1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(r=t.call(this,"FastNav",e))._hideColorTexture=!1!==s.hideColorTexture,r._hidePBR=!1!==s.hidePBR,r._hideSAO=!1!==s.hideSAO,r._hideEdges=!1!==s.hideEdges,r._hideTransparentObjects=!!s.hideTransparentObjects,r._scaleCanvasResolution=!!s.scaleCanvasResolution,r._defaultScaleCanvasResolutionFactor=s.defaultScaleCanvasResolutionFactor||1,r._scaleCanvasResolutionFactor=s.scaleCanvasResolutionFactor||.6,r._delayBeforeRestore=!1!==s.delayBeforeRestore,r._delayBeforeRestoreSeconds=s.delayBeforeRestoreSeconds||.5;var n=1e3*r._delayBeforeRestoreSeconds,o=!1,a=function(){n=1e3*r._delayBeforeRestoreSeconds,o||(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=r._defaultScaleCanvasResolutionFactor,o=!0)},l=function(){e.scene.canvas.resolutionScale=r._defaultScaleCanvasResolutionFactor,e.scene._renderer.setEdgesEnabled(!0),e.scene._renderer.setColorTextureEnabled(!0),e.scene._renderer.setPBREnabled(!0),e.scene._renderer.setSAOEnabled(!0),e.scene._renderer.setTransparentEnabled(!0),o=!1};r._onCanvasBoundary=e.scene.canvas.on("boundary",a),r._onCameraMatrix=e.scene.camera.on("matrix",a),r._onSceneTick=e.scene.on("tick",(function(e){o&&(n-=e.deltaTime,(!r._delayBeforeRestore||n<=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&&a()})),r}return C(i,[{key:"hideColorTexture",get:function(){return this._hideColorTexture},set:function(e){this._hideColorTexture=e}},{key:"hidePBR",get:function(){return this._hidePBR},set:function(e){this._hidePBR=e}},{key:"hideSAO",get:function(){return this._hideSAO},set:function(e){this._hideSAO=e}},{key:"hideEdges",get:function(){return this._hideEdges},set:function(e){this._hideEdges=e}},{key:"hideTransparentObjects",get:function(){return this._hideTransparentObjects},set:function(e){this._hideTransparentObjects=!1!==e}},{key:"scaleCanvasResolution",get:function(){return this._scaleCanvasResolution},set:function(e){this._scaleCanvasResolution=e}},{key:"defaultScaleCanvasResolutionFactor",get:function(){return this._defaultScaleCanvasResolutionFactor},set:function(e){this._defaultScaleCanvasResolutionFactor=e||1}},{key:"scaleCanvasResolutionFactor",get:function(){return this._scaleCanvasResolutionFactor},set:function(e){this._scaleCanvasResolutionFactor=e||.6}},{key:"delayBeforeRestore",get:function(){return this._delayBeforeRestore},set:function(e){this._delayBeforeRestore=e}},{key:"delayBeforeRestoreSeconds",get:function(){return this._delayBeforeRestoreSeconds},set:function(e){this._delayBeforeRestoreSeconds=null!=e?e:.5}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.scene.camera.off(this._onCameraMatrix),this.viewer.scene.canvas.off(this._onCanvasBoundary),this.viewer.scene.input.off(this._onSceneMouseDown),this.viewer.scene.input.off(this._onSceneMouseUp),this.viewer.scene.input.off(this._onSceneMouseMove),this.viewer.scene.off(this._onSceneTick),f(w(i.prototype),"destroy",this).call(this)}}]),i}(),Yh=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};x(this,e),this.cacheBuster=!1!==t.cacheBuster}return C(e,[{key:"_cacheBusterURL",value:function(e){if(!this.cacheBuster)return e;var t=(new Date).getTime();return e.indexOf("?")>-1?e+"&_="+t:e+"?_="+t}},{key:"getMetaModel",value:function(e,t,i){he.loadJSON(this._cacheBusterURL(e),(function(e){t(e)}),(function(e){i(e)}))}},{key:"getGLTF",value:function(e,t,i){he.loadArraybuffer(this._cacheBusterURL(e),(function(e){t(e)}),(function(e){i(e)}))}},{key:"getGLB",value:function(e,t,i){he.loadArraybuffer(this._cacheBusterURL(e),(function(e){t(e)}),(function(e){i(e)}))}},{key:"getArrayBuffer",value:function(e,t,i,r){!function(e,t,i,r){var s=function(){};i=i||s,r=r||s;var n=/^data:(.*?)(;base64)?,(.*)$/,o=t.match(n);if(o){var a=!!o[2],l=o[3];l=window.decodeURIComponent(l),a&&(l=window.atob(l));try{for(var u=new ArrayBuffer(l.length),A=new Uint8Array(u),c=0;c0&&void 0!==arguments[0]?arguments[0]:{};x(this,e),this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=t.messages,this.locale=t.locale}return C(e,[{key:"messages",set:function(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}},{key:"loadMessages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var t in e)this._messages[t]=e[t];this.messages=this._messages}},{key:"clearMessages",value:function(){this.messages={}}},{key:"locales",get:function(){return this._locales}},{key:"locale",get:function(){return this._locale},set:function(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}},{key:"translate",value:function(e,t){var i=this._messages[this._locale];if(!i)return null;var r=Zh(e,i);return r?t?qh(r,t):r:null}},{key:"translatePlurals",value:function(e,t,i){var r=this._messages[this._locale];if(!r)return null;var s=Zh(e,r);return(s=0===(t=parseInt(""+t,10))?s.zero:t>1?s.other:s.one)?(s=qh(s,[t]),i&&(s=qh(s,i)),s):null}},{key:"fire",value:function(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);var r=this._eventSubs[e];if(r)for(var s in r){if(r.hasOwnProperty(s))r[s].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 i=this._eventSubs[e];i||(i={},this._eventSubs[e]=i);var r=this._eventSubIDMap.addItem();i[r]={callback:t},this._eventSubEvents[r]=e;var s=this._events[e];return void 0!==s&&t(s),r}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function Zh(e,t){if(t[e])return t[e];for(var i=e.split("."),r=t,s=0,n=i.length;r&&s1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,i){return"{{"===e?"{":"}}"===e?"}":t[i]}))}var $h=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).t=s.t,r}return C(i,[{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"tangent",get:function(){return this.getTangent(this._t)}},{key:"length",get:function(){var e=this._getLengths();return e[e.length-1]}},{key:"getTangent",value:function(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,r=e+t;i<0&&(i=0),r>1&&(r=1);var s=this.getPoint(i),n=this.getPoint(r),o=re.subVec3(n,s,[]);return re.normalizeVec3(o,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}},{key:"_getLengths",value:function(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,r=[],s=this.getPoint(0),n=0;for(r.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),n+=re.lenVec3(re.subVec3(t,s,[])),r.push(n),s=t;return this.cacheArcLengths=r,r}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var i,r=this._getLengths(),s=0,n=r.length;i=t||e*r[n-1];for(var o,a=0,l=n-1;a<=l;)if((o=r[s=Math.floor(a+(l-a)/2)]-i)<0)a=s+1;else{if(!(o>0)){l=s;break}l=s-1}if(r[s=l]===i)return s/(n-1);var u=r[s];return(s+(i-u)/(r[s+1]-u))/(n-1)}}]),i}(),ed=function(e){g(i,$h);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).points=s.points,r.t=s.t,r}return C(i,[{key:"points",get:function(){return this._points},set:function(e){this._points=e||[]}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,r=Math.floor(i),s=i-r,n=t[0===r?r:r-1],o=t[r],a=t[r>t.length-2?t.length-1:r+1],l=t[r>t.length-3?t.length-1:r+2],u=re.vec3();return u[0]=re.catmullRomInterpolate(n[0],o[0],a[0],l[0],s),u[1]=re.catmullRomInterpolate(n[1],o[1],a[1],l[1],s),u[2]=re.catmullRomInterpolate(n[2],o[2],a[2],l[2],s),u}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}},{key:"getJSON",value:function(){return{points:points,t:this._t}}}]),i}(),td=re.vec3(),id=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s))._frames=[],r._eyeCurve=new ed(b(r)),r._lookCurve=new ed(b(r)),r._upCurve=new ed(b(r)),s.frames&&(r.addFrames(s.frames),r.smoothFrameTimes(1)),r}return C(i,[{key:"type",get:function(){return"CameraPath"}},{key:"frames",get:function(){return this._frames}},{key:"eyeCurve",get:function(){return this._eyeCurve}},{key:"lookCurve",get:function(){return this._lookCurve}},{key:"upCurve",get:function(){return this._upCurve}},{key:"saveFrame",value:function(e){var t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}},{key:"addFrame",value:function(e,t,i,r){var s={t:e,eye:t.slice(0),look:i.slice(0),up:r.slice(0)};this._frames.push(s),this._eyeCurve.points.push(s.eye),this._lookCurve.points.push(s.look),this._upCurve.points.push(s.up)}},{key:"addFrames",value:function(e){for(var t,i=0,r=e.length;i1?1:e,t.eye=this._eyeCurve.getPoint(e,td),t.look=this._lookCurve.getPoint(e,td),t.up=this._upCurve.getPoint(e,td)}},{key:"sampleFrame",value:function(e,t,i,r){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,i),this._upCurve.getPoint(e,r)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=re.vec3(),i=0;this._frames[0].t=0;for(var r=[],s=1,n=this._frames.length;s1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s))._look1=re.vec3(),r._eye1=re.vec3(),r._up1=re.vec3(),r._look2=re.vec3(),r._eye2=re.vec3(),r._up2=re.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!==s.easing,r.duration=s.duration,r.fit=s.fit,r.fitFOV=s.fitFOV,r.trail=s.trail,r}return C(i,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,i){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=i;var r,s,n,o,a,l=this.scene.camera,u=!!e.projection&&e.projection!==l.projection;if(this._eye1[0]=l.eye[0],this._eye1[1]=l.eye[1],this._eye1[2]=l.eye[2],this._look1[0]=l.look[0],this._look1[1]=l.look[1],this._look1[2]=l.look[2],this._up1[0]=l.up[0],this._up1[1]=l.up[1],this._up1[2]=l.up[2],this._orthoScale1=l.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)s=e.eye,n=e.look,o=e.up;else if(e.eye)s=e.eye;else if(e.look)n=e.look;else{var A=e;if((he.isNumeric(A)||he.isString(A))&&(a=A,!(A=this.scene.components[a])))return this.error("Component not found: "+he.inQuotes(a)),void(t&&(i?t.call(i):t()));u||(r=A.aabb||this.scene.aabb)}var c=e.poi;if(r){if(r[3]=1;e>1&&(e=1);var r=this.easing?i._ease(e,0,1,1):e,s=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(re.subVec3(s.eye,s.look,ad),s.eye=re.lerpVec3(r,0,1,this._eye1,this._eye2,nd),s.look=re.subVec3(nd,ad,sd)):this._flyingLook&&(s.look=re.lerpVec3(r,0,1,this._look1,this._look2,sd),s.up=re.lerpVec3(r,0,1,this._up1,this._up2,od)):this._flyingEyeLookUp&&(s.eye=re.lerpVec3(r,0,1,this._eye1,this._eye2,nd),s.look=re.lerpVec3(r,0,1,this._look1,this._look2,sd),s.up=re.lerpVec3(r,0,1,this._up1,this._up2,od)),this._projection2){var n="ortho"===this._projection2?i._easeOutExpo(e,0,1,1):i._easeInCubic(e,0,1,1);s.customProjection.matrix=re.lerpMat4(n,0,1,this._projMatrix1,this._projMatrix2)}else s.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return s.ortho.scale=this._orthoScale2,void this.stop();Be.scheduleTask(this._update,this)}}},{key:"stop",value:function(){if(this._flying){this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);var e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}}},{key:"cancel",value:function(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}},{key:"duration",get:function(){return this._duration/1e3},set:function(e){this._duration=e?1e3*e:500,this.stop()}},{key:"fit",get:function(){return this._fit},set:function(e){this._fit=!1!==e}},{key:"fitFOV",get:function(){return this._fitFOV},set:function(e){this._fitFOV=e||45}},{key:"trail",get:function(){return this._trail},set:function(e){this._trail=!!e}},{key:"destroy",value:function(){this.stop(),f(w(i.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,i,r){return-i*(e/=r)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,i,r){return i*(e/=r)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,i,r){return i*(1-Math.pow(2,-10*e/r))+t}}]),i}(),ud=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s))._cameraFlightAnimation=new ld(b(r)),r._t=0,r.state=i.SCRUBBING,r._playingFromT=0,r._playingToT=0,r._playingRate=s.playingRate||1,r._playingDir=1,r._lastTime=null,r.cameraPath=s.cameraPath,r._tick=r.scene.on("tick",r._updateT,b(r)),r}return C(i,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,r,s=performance.now(),n=this._lastTime?.001*(s-this._lastTime):0;if(this._lastTime=s,0!==n)switch(this.state){case i.SCRUBBING:return;case i.PLAYING:if(this._t+=this._playingRate*n,0===(t=this._cameraPath.frames.length)||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=i.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case i.PLAYING_TO:r=this._t+this._playingRate*n*this._playingDir,(this._playingDir<0&&r<=this._playingToT||this._playingDir>0&&r>=this._playingToT)&&(r=this._playingToT,this.state=i.SCRUBBING,this.fire("stopped")),this._t=r,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,i,r){return-i*(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=i.PLAYING)}},{key:"playToT",value:function(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=i.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var r=this._cameraPath;if(r){var s=r.frames[e];s?(this.state=i.SCRUBBING,this._cameraFlightAnimation.flyTo(s,t)):this.error("flyToFrame - frame index out of range: "+e)}}},{key:"scrubToT",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=i.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=i.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=i.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),i}();ud.STOPPED=0,ud.SCRUBBING=1,ud.PLAYING=2,ud.PLAYING_TO=3;var Ad=re.vec3(),cd=re.vec3();re.vec3();var hd=re.vec3([0,-1,0]),dd=re.vec4([0,0,0,1]),pd=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s))._src=null,r._image=null,r._pos=re.vec3(),r._origin=re.vec3(),r._rtcPos=re.vec3(),r._dir=re.vec3(),r._size=1,r._imageSize=re.vec2(),r._texture=new Jn(b(r)),r._plane=new gn(b(r),{geometry:new Wi(b(r),ao({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Zi(b(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0}),clippable:s.clippable}),r._grid=new gn(b(r),{geometry:new Wi(b(r),oo({size:1,divisions:10})),material:new Zi(b(r),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:s.clippable}),r._node=new Tn(b(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=s.gridVisible,r.position=s.position,r.rotation=s.rotation,r.dir=s.dir,r.size=s.size,r.collidable=s.collidable,r.clippable=s.clippable,r.pickable=s.pickable,r.opacity=s.opacity,s.image?r.image=s.image:r.src=s.src,r}return C(i,[{key:"visible",get:function(){return this._plane.visible},set:function(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}},{key:"gridVisible",get:function(){return this._gridVisible},set:function(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var i=new Image;i.onload=function(){t._texture.image=i,t._imageSize[0]=i.width,t._imageSize[1]=i.height,t._updatePlaneSizeFromImage()},i.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),He(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}},{key:"rotation",get:function(){return this._node.rotation},set:function(e){this._node.rotation=e}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"dir",get:function(){return this._dir},set:function(e){if(this._dir.set(e||[0,0,-1]),e){var t=this.scene.center,i=[-this._dir[0],-this._dir[1],-this._dir[2]];re.subVec3(t,this.position,Ad);var r=-re.dotVec3(i,Ad);re.normalizeVec3(i),re.mulVec3Scalar(i,r,cd),re.vec3PairToQuaternion(hd,e,dd),this._node.quaternion=dd}}},{key:"collidable",get:function(){return this._node.collidable},set:function(e){this._node.collidable=!1!==e}},{key:"clippable",get:function(){return this._node.clippable},set:function(e){this._node.clippable=!1!==e}},{key:"pickable",get:function(){return this._node.pickable},set:function(e){this._node.pickable=!1!==e}},{key:"opacity",get:function(){return this._node.opacity},set:function(e){this._node.opacity=e}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],i=this._imageSize[1];if(t>i){var r=i/t;this._node.scale=[e,1,e*r]}else{var s=t/i;this._node.scale=[e*s,1,e]}}}]),i}(),fd=function(e){g(i,Di);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i);var n=b(r=t.call(this,e,s));r._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var o=r.scene.camera,a=r.scene.canvas;return r._onCameraViewMatrix=o.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=o.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=a.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new Ai({type:"point",pos:re.vec3([1,1,1]),color:re.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:s.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(n._shadowViewMatrixDirty){n._shadowViewMatrix||(n._shadowViewMatrix=re.identityMat4());var e=n._state.pos,t=o.look,i=o.up;re.lookAtMat4v(e,t,i,n._shadowViewMatrix),n._shadowViewMatrixDirty=!1}return n._shadowViewMatrix},getShadowProjMatrix:function(){if(n._shadowProjMatrixDirty){n._shadowProjMatrix||(n._shadowProjMatrix=re.identityMat4());var e=n.scene.canvas.canvas;re.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,n._shadowProjMatrix),n._shadowProjMatrixDirty=!1}return n._shadowProjMatrix},getShadowRenderBuf:function(){return n._shadowRenderBuf||(n._shadowRenderBuf=new si(n.scene.canvas.canvas,n.scene.canvas.gl,{size:[1024,1024]})),n._shadowRenderBuf}}),r.pos=s.pos,r.color=s.color,r.intensity=s.intensity,r.constantAttenuation=s.constantAttenuation,r.linearAttenuation=s.linearAttenuation,r.quadraticAttenuation=s.quadraticAttenuation,r.castsShadow=s.castsShadow,r.scene._lightCreated(b(r)),r}return C(i,[{key:"type",get:function(){return"PointLight"}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"constantAttenuation",get:function(){return this._state.attenuation[0]},set:function(e){this._state.attenuation[0]=e||0,this.glRedraw()}},{key:"linearAttenuation",get:function(){return this._state.attenuation[1]},set:function(e){this._state.attenuation[1]=e||0,this.glRedraw()}},{key:"quadraticAttenuation",get:function(){return this._state.attenuation[2]},set:function(e){this._state.attenuation[2]=e||0,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),f(w(i.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),i}();function vd(e){return 0==(e&e-1)}function gd(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var md=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i);var n=(r=t.call(this,e,s)).scene.canvas.gl;return r._state=new Ai({texture:new Gn({gl:n,target:n.TEXTURE_CUBE_MAP}),flipY:r._checkFlipY(s.minFilter),encoding:r._checkEncoding(s.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),r._src=s.src,r._images=[],r._loadSrc(s.src),ae.memory.textures++,r}return C(i,[{key:"type",get:function(){return"CubeTexture"}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}},{key:"_loadSrc",value:function(e){var t=this,i=this.scene.canvas.gl;this._images=[];for(var r=!1,s=0,n=function(n){var o,a,l=new Image;l.onload=(o=l,a=n,function(){if(!r&&(o=function(e){if(!vd(e.width)||!vd(e.height)){var t=document.createElement("canvas");t.width=gd(e.width),t.height=gd(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(o),t._images[a]=o,6==++s)){var e=t._state.texture;e||(e=new Gn({gl:i,target:i.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}),l.onerror=function(){r=!0},l.src=e[n]},o=0;o1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).scene._lightsState.addReflectionMap(r._state),r.scene._reflectionMapCreated(b(r)),r}return C(i,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),i}(),yd=function(e){g(i,md);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).scene._lightMapCreated(b(r)),r}return C(i,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),i}(),bd=function(e){g(i,ot);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,{entity:s.entity,occludable:s.occludable,worldPos:s.worldPos}))._occluded=!1,r._visible=!0,r._src=null,r._image=null,r._pos=re.vec3(),r._origin=re.vec3(),r._rtcPos=re.vec3(),r._dir=re.vec3(),r._size=1,r._imageSize=re.vec2(),r._texture=new Jn(b(r),{src:s.src}),r._geometry=new Wi(b(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 gn(b(r),{geometry:r._geometry,material:new Zi(b(r),{ambient:[.9,.3,.9],shininess:30,diffuseMap:r._texture,backfaces:!0}),scale:[1,1,1],position:s.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),r.visible=!0,r.collidable=s.collidable,r.clippable=s.clippable,r.pickable=s.pickable,r.opacity=s.opacity,r.size=s.size,s.image?r.image=s.image:r.src=s.src,r}return C(i,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,f(w(i.prototype),"_setVisible",this).call(this,e)}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var i=new Image;i.onload=function(){t._texture.image=i,t._imageSize[0]=i.width,t._imageSize[1]=i.height,t._updatePlaneSizeFromImage()},i.src=this._src}}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"collidable",get:function(){return this._mesh.collidable},set:function(e){this._mesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._mesh.clippable},set:function(e){this._mesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._mesh.pickable},set:function(e){this._mesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._mesh.opacity},set:function(e){this._mesh.opacity=e}},{key:"_updatePlaneSizeFromImage",value:function(){var e=.5*this._size,t=this._imageSize[0],i=this._imageSize[1],r=i/t;this._geometry.positions=t>i?[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]}}]),i}(),wd=function(){function e(t){x(this,e),this._eye=re.vec3(),this._look=re.vec3(),this._up=re.vec3(),this._projection={},t&&this.saveCamera(t)}return C(e,[{key:"saveCamera",value:function(e){var t=e.camera,i=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:i.fov,fovAxis:i.fovAxis,near:i.near,far:i.far};break;case"ortho":this._projection={projection:"ortho",scale:i.scale,near:i.near,far:i.far};break;case"frustum":this._projection={projection:"frustum",left:i.left,right:i.right,top:i.top,bottom:i.bottom,near:i.near,far:i.far};break;case"custom":this._projection={projection:"custom",matrix:i.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var i=e.camera,r=this._projection;function s(){switch(r.type){case"perspective":i.perspective.fov=r.fov,i.perspective.fovAxis=r.fovAxis,i.perspective.near=r.near,i.perspective.far=r.far;break;case"ortho":i.ortho.scale=r.scale,i.ortho.near=r.near,i.ortho.far=r.far;break;case"frustum":i.frustum.left=r.left,i.frustum.right=r.right,i.frustum.top=r.top,i.frustum.bottom=r.bottom,i.frustum.near=r.near,i.frustum.far=r.far;break;case"custom":i.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(){s(),t()})):(i.eye=this._eye,i.look=this._look,i.up=this._up,s(),i.projection=r.projection)}}]),e}(),Bd=re.vec3(),xd=function(){function e(t){if(x(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,t){var i=t.metaScene.scene;this.saveObjects(i,t)}}return C(e,[{key:"saveObjects",value:function(e,t,i){this.numObjects=0,this._mask=i?he.apply(i,{}):null;for(var r=!i||i.visible,s=!i||i.edges,n=!i||i.xrayed,o=!i||i.highlighted,a=!i||i.selected,l=!i||i.clippable,u=!i||i.pickable,A=!i||i.colorize,c=!i||i.opacity,h=t.metaObjects,d=e.objects,p=0,f=h.length;p1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).v0=s.v0,r.v1=s.v1,r.v2=s.v2,r.v3=s.v3,r.t=s.t,r}return C(i,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||re.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||re.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||re.vec3([0,0,0])}},{key:"v3",get:function(){return this._v3},set:function(e){this.fire("v3",this._v3=e||re.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=re.vec3();return t[0]=re.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=re.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=re.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}]),i}(),Ed=function(e){g(i,$h);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s))._cachedLengths=[],r._dirty=!0,r._curves=[],r._t=0,r._dirtySubs=[],r._destroyedSubs=[],r.curves=s.curves||[],r.t=s.t,r}return C(i,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,i,r;for(e=e||[],i=0,r=this._curves.length;i1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"length",get:function(){var e=this._getCurveLengths();return e[e.length-1]}},{key:"getPoint",value:function(e){for(var t,i=e*this.length,r=this._getCurveLengths(),s=0;s=i){var n=1-(r[s]-i)/(t=this._curves[s]).length;return t.getPointAt(n)}s++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],i=0,r=this._curves.length;for(e=0;e1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).v0=s.v0,r.v1=s.v1,r.v2=s.v2,r.t=s.t,r}return C(i,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||re.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||re.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||re.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=re.vec3();return t[0]=re.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=re.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=re.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}]),i}(),kd=function(e){g(i,Ph);var t=_(i);function i(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),t.call(this,e,r)}return C(i)}(),Id=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s))._skyboxMesh=new gn(b(r),{geometry:new Wi(b(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 Zi(b(r),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Jn(b(r),{src:s.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:s.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),r.size=s.size,r.active=s.active,r}return C(i,[{key:"size",get:function(){return this._size},set:function(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}},{key:"active",get:function(){return this._skyboxMesh.visible},set:function(e){this._skyboxMesh.visible=e}}]),i}(),Dd=function(){function e(){x(this,e)}return C(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),Sd=re.vec4(),Td=re.vec4(),Ld=re.vec3(),Rd=re.vec3(),Ud=re.vec3(),Od=re.vec4(),Nd=re.vec4(),Qd=re.vec4(),Vd=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"dollyToCanvasPos",value:function(e,t,i){var r=!1,s=this._scene.camera;if(e){var n=re.subVec3(e,s.eye,Ld);r=re.lenVec3(n)0&&void 0!==arguments[0]?arguments[0]:{};this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);var t=e.color||[1,0,0];this._pivotSphereMaterial=new Zi(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=re.lookAtMat4v(e.eye,e.look,e.worldUp);re.transformPoint3(t,this.getPivotPos(),this._cameraOffset);var i=this.getPivotPos();this._cameraOffset[2]+=re.distVec3(e.eye,i),t=re.inverseMat4(t);var r=re.transformVec3(t,this._cameraOffset),s=re.vec3();if(re.subVec3(e.eye,i,s),re.addVec3(s,r),e.zUp){var n=s[1];s[1]=s[2],s[2]=n}this._radius=re.lenVec3(s),this._polar=Math.acos(s[1]/this._radius),this._azimuth=Math.atan2(s[0],s[2]),this._pivoting=!0}},{key:"_cameraLookingDownwards",value:function(){var e=this._scene.camera,t=re.normalizeVec3(re.subVec3(e.look,e.eye,Hd)),i=re.cross3Vec3(t,e.worldUp,jd);return re.sqLenVec3(i)<=1e-4}},{key:"getPivoting",value:function(){return this._pivoting}},{key:"setPivotPos",value:function(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}},{key:"setCanvasPivotPos",value:function(e){var t=this._scene.camera,i=Math.abs(re.distVec3(this._scene.center,t.eye)),r=t.project.transposedMatrix,s=r.subarray(8,12),n=r.subarray(12),o=[0,0,-1,1],a=re.dotVec4(o,s)/re.dotVec4(o,n),l=zd;t.project.unproject(e,a,Wd,Kd,l);var u=re.normalizeVec3(re.subVec3(l,t.eye,Hd)),A=re.addVec3(t.eye,re.mulVec3Scalar(u,i,jd),Gd);this.setPivotPos(A)}},{key:"getPivotPos",value:function(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}},{key:"continuePivot",value:function(e,t){if(this._pivoting&&(0!==e||0!==t)){var i=this._scene.camera,r=-e,s=-t;1===i.worldUp[2]&&(r=-r),this._azimuth+=.01*-r,this._polar+=.01*s,this._polar=re.clamp(this._polar,.001,Math.PI-.001);var n=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===i.worldUp[2]){var o=n[1];n[1]=n[2],n[2]=o}var a=re.lenVec3(re.subVec3(i.look,i.eye,re.vec3())),l=this.getPivotPos();re.addVec3(n,l);var u=re.lookAtMat4v(n,l,i.worldUp);u=re.inverseMat4(u);var A=re.transformVec3(u,this._cameraOffset);u[12]-=A[0],u[13]-=A[1],u[14]-=A[2];var c=[u[8],u[9],u[10]];i.eye=[u[12],u[13],u[14]],re.subVec3(i.eye,re.mulVec3Scalar(c,a),i.look),i.up=[u[4],u[5],u[6]],this.showPivot()}}},{key:"showPivot",value:function(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}},{key:"hidePivot",value:function(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}},{key:"endPivot",value:function(){this._pivoting=!1}},{key:"destroy",value:function(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}]),e}(),Yd=function(){function e(t,i){x(this,e),this._scene=t.scene,this._cameraControl=t,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=i,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=re.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}return C(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){var e="".concat(~~this.pickCursorPos[0],"-").concat(~~this.pickCursorPos[1],"-").concat(this.scheduleSnapOrPick,"-").concat(this.schedulePickSurface,"-").concat(this.schedulePickEntity);if(this._lastHash!==e){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;var t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var i=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});i&&(i.snappedToEdge||i.snappedToVertex)?(this.snapPickResult=i,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var 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 s=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(s[0]===this.pickCursorPos[0]&&s[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 Rt;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var t=this.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=t)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}]),e}(),Jd=re.vec2(),Zd=function(){function e(t,i,r,s,n){x(this,e),this._scene=t;var o,a,l,u=i.pickController,A=0,c=0,h=0,d=0,p=!1,f=re.vec3(),v=!0,g=this._scene.canvas.canvas,m=[];function _(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];g.style.cursor="move",y(),e&&b()}function y(){A=s.pointerCanvasPos[0],c=s.pointerCanvasPos[1],h=s.pointerCanvasPos[0],d=s.pointerCanvasPos[1]}function b(){u.pickCursorPos=s.pointerCanvasPos,u.schedulePickSurface=!0,u.update(),u.picked&&u.pickedSurface&&u.pickResult&&u.pickResult.worldPos?(p=!0,f.set(u.pickResult.worldPos)):p=!1}document.addEventListener("keydown",this._documentKeyDownHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var i=e.keyCode;m[i]=!0}}),document.addEventListener("keyup",this._documentKeyUpHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var i=e.keyCode;m[i]=!1}}),g.addEventListener("mousedown",this._mouseDownHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:m[t.input.KEY_SHIFT]||r.planView?(o=!0,_()):(o=!0,_(!1));break;case 2:a=!0,_();break;case 3:l=!0,r.panRightClick&&_()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&(o||a||l)){var i=t.canvas.boundary,u=i[2],h=i[3],d=s.pointerCanvasPos[0],v=s.pointerCanvasPos[1],g=m[t.input.KEY_SHIFT]||r.planView||!r.panRightClick&&a||r.panRightClick&&l,_=document.pointerLockElement?e.movementX:d-A,y=document.pointerLockElement?e.movementY:v-c;if(g){var b=t.camera;if("perspective"===b.projection){var w=Math.abs(p?re.lenVec3(re.subVec3(f,t.camera.eye,[])):t.camera.eyeLookDist)*Math.tan(b.perspective.fov/2*Math.PI/180);n.panDeltaX+=1.5*_*w/h,n.panDeltaY+=1.5*y*w/h}else n.panDeltaX+=.5*b.ortho.scale*(_/h),n.panDeltaY+=.5*b.ortho.scale*(y/h)}else!o||a||l||r.planView||(r.firstPerson?(n.rotateDeltaY-=_/u*r.dragRotationRate/2,n.rotateDeltaX+=y/h*(r.dragRotationRate/4)):(n.rotateDeltaY-=_/u*(1.5*r.dragRotationRate),n.rotateDeltaX+=y/h*(1.5*r.dragRotationRate)));A=d,c=v}}),g.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){r.active&&r.pointerEnabled&&s.mouseover&&(v=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:case 2:case 3:o=!1,a=!1,l=!1}}),g.addEventListener("mouseup",this._mouseUpHandler=function(e){if(r.active&&r.pointerEnabled){if(3===e.which){!function(e,t){if(e){for(var i=e.target,r=0,s=0,n=0,o=0;i.offsetParent;)r+=i.offsetLeft,s+=i.offsetTop,n+=i.scrollLeft,o+=i.scrollTop,i=i.offsetParent;t[0]=e.pageX+n-r,t[1]=e.pageY+o-s}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Jd);var t=Jd[0],s=Jd[1];Math.abs(t-h)<3&&Math.abs(s-d)<3&&i.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Jd,event:e},!0)}g.style.removeProperty("cursor")}}),g.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var w=1/60,B=null;g.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled){var t=performance.now()/1e3,i=null!==B?t-B:0;B=t,i>.05&&(i=.05),i0?i.cameraFlight.flyTo(rp,(function(){i.pivotController.getPivoting()&&r.followPointer&&i.pivotController.showPivot()})):(i.cameraFlight.jumpTo(rp),i.pivotController.getPivoting()&&r.followPointer&&i.pivotController.showPivot())}}}))}return C(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.input.off(this._onSceneKeyDown)}}]),e}(),np=function(){function e(t,i,r,s,n){var o=this;x(this,e),this._scene=t;var a=i.pickController,l=i.pivotController,u=i.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;var A=!1,c=!1,h=this._scene.canvas.canvas,d=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var s=e&&e.entity?e.entity.aabb:t.aabb;if(r){var n=t.camera;re.subVec3(n.eye,n.look,[]),i.cameraFlight.flyTo({aabb:s})}else i.cameraFlight.flyTo({aabb:s})},p=t.tickify(this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!A&&!c){if(u.hasSubs("rayMove")){var i=re.vec3(),n=re.vec3();re.canvasPosToWorldRay(t.canvas.canvas,t.camera.viewMatrix,t.camera.projMatrix,t.camera.projection,s.pointerCanvasPos,i,n),u.fire("rayMove",{canvasPos:s.pointerCanvasPos,ray:{origin:i,direction:n,canvasPos:s.pointerCanvasPos}},!0)}var l=u.hasSubs("hover"),h=u.hasSubs("hoverEnter"),d=u.hasSubs("hoverOut"),p=u.hasSubs("hoverOff"),f=u.hasSubs("hoverSurface"),v=u.hasSubs("hoverSnapOrSurface");if(l||h||d||p||f||v)if(a.pickCursorPos=s.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=f,a.scheduleSnapOrPick=v,a.update(),a.pickResult){if(a.pickResult.entity){var g=a.pickResult.entity.id;o._lastPickedEntityId!==g&&(void 0!==o._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[o._lastPickedEntityId]},!0),u.fire("hoverEnter",a.pickResult,!0),o._lastPickedEntityId=g)}u.fire("hover",a.pickResult,!0),(a.pickResult.worldPos||a.pickResult.snappedWorldPos)&&u.fire("hoverSurface",a.pickResult,!0)}else void 0!==o._lastPickedEntityId&&(u.fire("hoverOut",{entity:t.objects[o._lastPickedEntityId]},!0),o._lastPickedEntityId=void 0),u.fire("hoverOff",{canvasPos:a.pickCursorPos},!0)}});h.addEventListener("mousemove",p),h.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(A=!0),3===e.which&&(c=!0),1===e.which&&r.active&&r.pointerEnabled&&(s.mouseDownClientX=e.clientX,s.mouseDownClientY=e.clientY,s.mouseDownCursorX=s.pointerCanvasPos[0],s.mouseDownCursorY=s.pointerCanvasPos[1],!r.firstPerson&&r.followPointer&&(a.pickCursorPos=s.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),1===e.which))){var i=a.pickResult;i&&i.worldPos?(l.setPivotPos(i.worldPos),l.startPivot()):(r.smartPivot?l.setCanvasPivotPos(s.pointerCanvasPos):l.setPivotPos(t.camera.look),l.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(A=!1),3===e.which&&(c=!1),l.getPivoting()&&l.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(r.active&&r.pointerEnabled&&(1===e.which&&(l.hidePivot(),!(Math.abs(e.clientX-s.mouseDownClientX)>3||Math.abs(e.clientY-s.mouseDownClientY)>3)))){var n=u.hasSubs("picked"),A=u.hasSubs("pickedNothing"),c=u.hasSubs("pickedSurface"),h=u.hasSubs("doublePicked"),p=u.hasSubs("doublePickedSurface"),f=u.hasSubs("doublePickedNothing");if(!(r.doublePickFlyTo||h||p||f))return(n||A||c)&&(a.pickCursorPos=s.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=c,a.update(),a.pickResult?(u.fire("picked",a.pickResult,!0),a.pickedSurface&&u.fire("pickedSurface",a.pickResult,!0)):u.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0)),void(o._clicks=0);if(o._clicks++,1===o._clicks){a.pickCursorPos=s.pointerCanvasPos,a.schedulePickEntity=r.doublePickFlyTo,a.schedulePickSurface=c,a.update();var v=a.pickResult,g=a.pickedSurface;o._timeout=setTimeout((function(){v?(u.fire("picked",v,!0),g&&(u.fire("pickedSurface",v,!0),!r.firstPerson&&r.followPointer&&(i.pivotController.setPivotPos(v.worldPos),i.pivotController.startPivot()&&i.pivotController.showPivot()))):u.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0),o._clicks=0}),r.doubleClickTimeFrame)}else{if(null!==o._timeout&&(window.clearTimeout(o._timeout),o._timeout=null),a.pickCursorPos=s.pointerCanvasPos,a.schedulePickEntity=r.doublePickFlyTo||h||p,a.schedulePickSurface=a.schedulePickEntity&&p,a.update(),a.pickResult){if(u.fire("doublePicked",a.pickResult,!0),a.pickedSurface&&u.fire("doublePickedSurface",a.pickResult,!0),r.doublePickFlyTo&&(d(a.pickResult),!r.firstPerson&&r.followPointer)){var m=a.pickResult.entity.aabb,_=re.getAABB3Center(m);i.pivotController.setPivotPos(_),i.pivotController.startPivot()&&i.pivotController.showPivot()}}else if(u.fire("doublePickedNothing",{canvasPos:s.pointerCanvasPos},!0),r.doublePickFlyTo&&(d(),!r.firstPerson&&r.followPointer)){var y=t.aabb,b=re.getAABB3Center(y);i.pivotController.setPivotPos(b),i.pivotController.startPivot()&&i.pivotController.showPivot()}o._clicks=0}}},!1)}return C(e,[{key:"reset",value:function(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}]),e}(),op=function(){function e(t,i,r,s,n){x(this,e),this._scene=t;var o=t.input,a=[],l=t.canvas.canvas,u=!0;this._onSceneMouseMove=o.on("mousemove",(function(){u=!0})),this._onSceneKeyDown=o.on("keydown",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(r.keyboardEnabledOnlyIfMouseover&&!s.mouseover||(a[e]=!0,e===o.KEY_SHIFT&&(l.style.cursor="move")))})),this._onSceneKeyUp=o.on("keyup",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(a[e]=!1,e===o.KEY_SHIFT&&(l.style.cursor=null),i.pivotController.getPivoting()&&i.pivotController.endPivot())})),this._onTick=t.on("tick",(function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(!r.keyboardEnabledOnlyIfMouseover||s.mouseover)){var l=i.cameraControl,A=e.deltaTime/1e3;if(!r.planView){var c=l._isKeyDownForAction(l.ROTATE_Y_POS,a),h=l._isKeyDownForAction(l.ROTATE_Y_NEG,a),d=l._isKeyDownForAction(l.ROTATE_X_POS,a),p=l._isKeyDownForAction(l.ROTATE_X_NEG,a),f=A*r.keyboardRotationRate;(c||h||d||p)&&(!r.firstPerson&&r.followPointer&&i.pivotController.startPivot(),c?n.rotateDeltaY+=f:h&&(n.rotateDeltaY-=f),d?n.rotateDeltaX+=f:p&&(n.rotateDeltaX-=f),!r.firstPerson&&r.followPointer&&i.pivotController.startPivot())}if(!a[o.KEY_CTRL]&&!a[o.KEY_ALT]){var v=l._isKeyDownForAction(l.DOLLY_BACKWARDS,a),g=l._isKeyDownForAction(l.DOLLY_FORWARDS,a);if(v||g){var m=A*r.keyboardDollyRate;!r.firstPerson&&r.followPointer&&i.pivotController.startPivot(),g?n.dollyDelta-=m:v&&(n.dollyDelta+=m),u&&(s.followPointerDirty=!0,u=!1)}}var _=l._isKeyDownForAction(l.PAN_FORWARDS,a),y=l._isKeyDownForAction(l.PAN_BACKWARDS,a),b=l._isKeyDownForAction(l.PAN_LEFT,a),w=l._isKeyDownForAction(l.PAN_RIGHT,a),B=l._isKeyDownForAction(l.PAN_UP,a),x=l._isKeyDownForAction(l.PAN_DOWN,a),P=(a[o.KEY_ALT]?.3:1)*A*r.keyboardPanRate;(_||y||b||w||B||x)&&(!r.firstPerson&&r.followPointer&&i.pivotController.startPivot(),x?n.panDeltaY+=P:B&&(n.panDeltaY+=-P),w?n.panDeltaX+=-P:b&&(n.panDeltaX+=P),y?n.panDeltaZ+=P:_&&(n.panDeltaZ+=-P))}}))}return C(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}]),e}(),ap=re.vec3(),lp=function(){function e(t,i,r,s,n){x(this,e),this._scene=t;var o=t.camera,a=i.pickController,l=i.pivotController,u=i.panController,A=1,c=1,h=null;this._onTick=t.on("tick",(function(){if(r.active&&r.pointerEnabled){var e="default";if(Math.abs(n.dollyDelta)<.001&&(n.dollyDelta=0),Math.abs(n.rotateDeltaX)<.001&&(n.rotateDeltaX=0),Math.abs(n.rotateDeltaY)<.001&&(n.rotateDeltaY=0),0===n.rotateDeltaX&&0===n.rotateDeltaY||(n.dollyDelta=0),r.followPointer){if(--A<=0&&(A=1,0!==n.dollyDelta)){if(0===n.rotateDeltaY&&0===n.rotateDeltaX&&r.followPointer&&s.followPointerDirty&&(a.pickCursorPos=s.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.pickResult&&a.pickResult.worldPos?h=a.pickResult.worldPos:(c=1,h=null),s.followPointerDirty=!1),h){var i=Math.abs(re.lenVec3(re.subVec3(h,t.camera.eye,ap)));c=i/r.dollyProximityThreshold}cr.longTapRadius||Math.abs(g)>r.longTapRadius)&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),r.planView){var m=t.camera;if("perspective"===m.projection){var _=Math.abs(t.camera.eyeLookDist)*Math.tan(m.perspective.fov/2*Math.PI/180);n.panDeltaX+=v*_/l*r.touchPanRate,n.panDeltaY+=g*_/l*r.touchPanRate}else n.panDeltaX+=.5*m.ortho.scale*(v/l)*r.touchPanRate,n.panDeltaY+=.5*m.ortho.scale*(g/l)*r.touchPanRate}else n.rotateDeltaY-=v/a*(1*r.dragRotationRate),n.rotateDeltaX+=g/l*(1.5*r.dragRotationRate)}else if(2===p){var y=d[0],b=d[1];cp(y,u),cp(b,A);var w=re.geometricMeanVec2(h[0],h[1]),B=re.geometricMeanVec2(u,A),x=re.vec2();re.subVec2(w,B,x);var P=x[0],C=x[1],M=t.camera,E=re.distVec2([y.pageX,y.pageY],[b.pageX,b.pageY]),F=(re.distVec2(h[0],h[1])-E)*r.touchDollyRate;if(n.dollyDelta=F,Math.abs(F)<1)if("perspective"===M.projection){var k=o.pickResult?o.pickResult.worldPos:t.center,I=Math.abs(re.lenVec3(re.subVec3(k,t.camera.eye,[])))*Math.tan(M.perspective.fov/2*Math.PI/180);n.panDeltaX-=P*I/l*r.touchPanRate,n.panDeltaY-=C*I/l*r.touchPanRate}else n.panDeltaX-=.5*M.ortho.scale*(P/l)*r.touchPanRate,n.panDeltaY-=.5*M.ortho.scale*(C/l)*r.touchPanRate;s.pointerCanvasPos=B}for(var D=0;D-1&&t-c<150&&(h>-1&&c-h<325?(dp(n[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=o,a.update(),a.pickResult?(a.pickResult.touchInput=!0,l.fire("doublePicked",a.pickResult),a.pickedSurface&&l.fire("doublePickedSurface",a.pickResult),r.doublePickFlyTo&&p(a.pickResult)):(l.fire("doublePickedNothing"),r.doublePickFlyTo&&p()),h=-1):re.distVec2(u[0],A)<4&&(dp(n[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=o,a.update(),a.pickResult?(a.pickResult.touchInput=!0,l.fire("picked",a.pickResult),a.pickedSurface&&l.fire("pickedSurface",a.pickResult)):l.fire("pickedNothing"),h=t),c=-1),u.length=i.length;for(var d=0,f=i.length;d1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(r=t.call(this,e,s)).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,keyboardEnabledOnlyIfMouseover:!0,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:re.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:re.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},r._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};var n=r.scene;return r._controllers={cameraControl:b(r),pickController:new Yd(b(r),r._configs),pivotController:new Xd(n,r._configs),panController:new Vd(n),cameraFlight:new ld(b(r),{duration:.5})},r._handlers=[new up(r.scene,r._controllers,r._configs,r._states,r._updates),new hp(r.scene,r._controllers,r._configs,r._states,r._updates),new Zd(r.scene,r._controllers,r._configs,r._states,r._updates),new sp(r.scene,r._controllers,r._configs,r._states,r._updates),new np(r.scene,r._controllers,r._configs,r._states,r._updates),new pp(r.scene,r._controllers,r._configs,r._states,r._updates),new op(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cameraUpdater=new lp(r.scene,r._controllers,r._configs,r._states,r._updates),r.navMode=s.navMode,s.planView&&(r.planView=s.planView),r.constrainVertical=s.constrainVertical,s.keyboardLayout?r.keyboardLayout=s.keyboardLayout:r.keyMap=s.keyMap,r.doublePickFlyTo=s.doublePickFlyTo,r.panRightClick=s.panRightClick,r.active=s.active,r.followPointer=s.followPointer,r.rotationInertia=s.rotationInertia,r.keyboardPanRate=s.keyboardPanRate,r.touchPanRate=s.touchPanRate,r.keyboardRotationRate=s.keyboardRotationRate,r.dragRotationRate=s.dragRotationRate,r.touchDollyRate=s.touchDollyRate,r.dollyInertia=s.dollyInertia,r.dollyProximityThreshold=s.dollyProximityThreshold,r.dollyMinSpeed=s.dollyMinSpeed,r.panInertia=s.panInertia,r.pointerEnabled=!0,r.keyboardDollyRate=s.keyboardDollyRate,r.mouseWheelDollyRate=s.mouseWheelDollyRate,r}return C(i,[{key:"keyMap",get:function(){return this._keyMap},set:function(e){if(e=e||"qwerty",he.isString(e)){var t=this.scene.input,i={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":i[this.PAN_LEFT]=[t.KEY_A],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_Z],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":i[this.PAN_LEFT]=[t.KEY_Q],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_W],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=i}else{var r=e;this._keyMap=r}}},{key:"_isKeyDownForAction",value:function(e,t){var i=this._keyMap[e];if(!i)return!1;t||(t=this.scene.input.keyDown);for(var r=0,s=i.length;r0&&void 0!==arguments[0]?arguments[0]:{};this._controllers.pivotController.enablePivotSphere(e)}},{key:"disablePivotSphere",value:function(){this._controllers.pivotController.disablePivotSphere()}},{key:"smartPivot",get:function(){return this._configs.smartPivot},set:function(e){this._configs.smartPivot=!1!==e}},{key:"doubleClickTimeFrame",get:function(){return this._configs.doubleClickTimeFrame},set:function(e){this._configs.doubleClickTimeFrame=null!=e?e:250}},{key:"destroy",value:function(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),f(w(i.prototype),"destroy",this).call(this)}},{key:"_destroyHandlers",value:function(){for(var e=0,t=this._handlers.length;e1&&void 0!==arguments[1]?arguments[1]:{};if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);var i=this.metaScene,r=e.properties;if(r)for(var s=0,n=r.length;s0&&console.error("[MetaModel._decompressProperties] Properties not found: ".concat(i))}},{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 i=e.metaObjects[t];if(i.children&&(i.children=[]),i.propertySets&&(i.propertySets=[]),i.propertySetIds)for(var r=0,s=i.propertySetIds.length;r0?bp(t):null,o=i&&i.length>0?bp(i):null;return function e(t){if(t){var i=!0;(o&&o[t.type]||n&&!n[t.type])&&(i=!1),i&&r.push(t.id);var s=t.children;if(s)for(var a=0,l=s.length;a>t;i.sort(rh);for(var a=new Int32Array(e.length),l=0,u=i.length;le[s+1]){var o=e[s];e[s]=e[s+1],e[s+1]=o}nh=new Int32Array(e),t.sort(oh);for(var a=new Int32Array(e.length),l=0,u=t.length;l0)for(var r=i._meshes,s=0,n=r.length;s0)for(var o=this._meshes,a=0,l=o.length;a1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).renderOrder=s.renderOrder||0,r._dtxEnabled=r.scene.dtxEnabled&&!1!==s.dtxEnabled,r._enableVertexWelding=!1,r._enableIndexBucketing=!1,r._vboBatchingLayerScratchMemory=yo(),r._textureTranscoder=s.textureTranscoder||Zc(r.scene.viewer),r._maxGeometryBatchSize=s.maxGeometryBatchSize,r._aabb=re.collapseAABB3(),r._aabbDirty=!0,r._quantizationRanges={},r._vboInstancingLayers={},r._vboBatchingLayers={},r._dtxLayers={},r._meshList=[],r.layerList=[],r._entityList=[],r._geometries={},r._dtxBuckets={},r._textures={},r._textureSets={},r._transforms={},r._meshes={},r._unusedMeshes={},r._entities={},r.renderFlags=new on,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=s.edgeThreshold||10,r._origin=re.vec3(s.origin||[0,0,0]),r._position=re.vec3(s.position||[0,0,0]),r._rotation=re.vec3(s.rotation||[0,0,0]),r._quaternion=re.vec4(s.quaternion||[0,0,0,1]),r._conjugateQuaternion=re.vec4(s.quaternion||[0,0,0,1]),s.rotation&&re.eulerToQuaternion(r._rotation,"XYZ",r._quaternion),r._scale=re.vec3(s.scale||[1,1,1]),r._worldRotationMatrix=re.mat4(),r._worldRotationMatrixConjugate=re.mat4(),r._matrix=re.mat4(),r._matrixDirty=!0,r._rebuildMatrices(),r._worldNormalMatrix=re.mat4(),re.inverseMat4(r._matrix,r._worldNormalMatrix),re.transposeMat4(r._worldNormalMatrix),(s.matrix||s.position||s.rotation||s.scale||s.quaternion)&&(r._viewMatrix=re.mat4(),r._viewNormalMatrix=re.mat4(),r._viewMatrixDirty=!0,r._matrixNonIdentity=!0),r._opacity=1,r._colorize=[1,1,1],r._saoEnabled=!1!==s.saoEnabled,r._pbrEnabled=!1!==s.pbrEnabled,r._colorTextureEnabled=!1!==s.colorTextureEnabled,r._isModel=s.isModel,r._isModel&&r.scene._registerModel(b(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=s.visible,r.culled=s.culled,r.pickable=s.pickable,r.clippable=s.clippable,r.collidable=s.collidable,r.castsShadow=s.castsShadow,r.receivesShadow=s.receivesShadow,r.xrayed=s.xrayed,r.highlighted=s.highlighted,r.selected=s.selected,r.edges=s.edges,r.colorize=s.colorize,r.opacity=s.opacity,r.backfaces=s.backfaces,r}return C(i,[{key:"_meshMatrixDirty",value:function(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}},{key:"_createDefaultTextureSet",value:function(){var e=new Qc({id:"defaultColorTexture",texture:new Gn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Qc({id:"defaultMetalRoughTexture",texture:new Gn({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),i=new Qc({id:"defaultNormalsTexture",texture:new Gn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),r=new Qc({id:"defaultEmissiveTexture",texture:new Gn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),s=new Qc({id:"defaultOcclusionTexture",texture:new Gn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=i,this._textures.defaultEmissiveTexture=r,this._textures.defaultOcclusionTexture=s,this._textureSets.defaultTextureSet=new Nc({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:i,emissiveTexture:r,occlusionTexture:s})}},{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]),re.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]),re.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||Bh),re.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),re.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),re.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),re.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&&(re.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),re.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),re.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),re.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}},{key:"rotationMatrixConjugate",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}},{key:"_setWorldMatrixDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0}},{key:"_transformDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}},{key:"_sceneModelDirty",value:function(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(var e=0,t=this._entityList.length;e0},set:function(e){e=!1!==e,this._visible=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._selected=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!!e,this._edges=e;for(var t=0,i=this._entityList.length;t0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,i=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var l=e.colors,u=new Uint8Array(l.length),A=0,c=l.length;A>24&255,s=i>>16&255,n=i>>8&255,o=255&i;switch(e.pickColor=new Uint8Array([o,n,s,r]),e.solid="solid"===e.primitive,t.origin=re.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(t,e),this._meshes[e.id]=t,this._unusedMeshes[e.id]=t,this._meshList.push(t),t}},{key:"_getNumPrimitives",value:function(e){var t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(var i=0,r=e.buckets.length;i>>0).toString(16)}},{key:"_getVBOInstancingLayer",value:function(e){var t=this,i=e.origin,r=e.textureSetId||"-",s=e.geometryId,n="".concat(Math.round(i[0]),".").concat(Math.round(i[1]),".").concat(Math.round(i[2]),".").concat(r,".").concat(s),o=this._vboInstancingLayers[n];if(o)return o;for(var a=e.textureSet,l=e.geometry;!o;)switch(l.primitive){case"triangles":case"surface":o=new ml({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!1});break;case"solid":o=new ml({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0,solid:!0});break;case"lines":o=new ru({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0});break;case"points":o=new Ju({model:t,textureSet:a,geometry:l,origin:i,layerIndex:0})}return this._vboInstancingLayers[n]=o,this.layerList.push(o),o}},{key:"createEntity",value:function(e){if(void 0===e.id?e.id=re.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=re.createUUID()),void 0!==e.meshIds){var t=0;this._visible&&!1!==e.visible&&(t|=We),this._pickable&&!1!==e.pickable&&(t|=Xe),this._culled&&!1!==e.culled&&(t|=Ke),this._clippable&&!1!==e.clippable&&(t|=Ye),this._collidable&&!1!==e.collidable&&(t|=Je),this._edges&&!1!==e.edges&&(t|=et),this._xrayed&&!1!==e.xrayed&&(t|=Ze),this._highlighted&&!1!==e.highlighted&&(t|=qe),this._selected&&!1!==e.selected&&(t|=$e),e.flags=t,this._createEntity(e)}else this.error("Config missing: meshIds")}},{key:"_createEntity",value:function(e){for(var t=[],i=0,r=e.meshIds.length;it.sortId?1:0}));for(var o=0,a=this.layerList.length;o0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}},{key:"_updateRenderFlagsVisibleLayers",value:function(){var e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(var t=0,i=this.layerList.length;t0){var t="".concat(this.id,"-dummyEntityForUnusedMeshes");this.warn('Creating dummy SceneModelEntity "'.concat(t,'" for unused SceneMeshes: [').concat(e.join(","),"]")),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}},{key:"_getActiveSectionPlanesForLayer",value:function(e){var t=this.renderFlags,i=this.scene._sectionPlanesState.sectionPlanes,r=i.length,s=e.layerIndex*r;if(r>0)for(var n=0;n0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){var t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0)this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0));if(this.numSelectedLayerPortions>0){var i=this.scene.selectedMaterial._state;i.fill&&(i.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),i.edges&&(i.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){var 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,t){for(var i=this.renderFlags,r=0,s=i.visibleLayers.length;r2&&void 0!==arguments[2]&&arguments[2],r=e.positionsCompressed||[],s=sh(e.indices||[],t),n=ah(e.edgeIndices||[]);function o(e,t){if(e>t){var i=e;e=t,t=i}function r(i,r){return i!==e?e-i:r!==t?t-r:0}for(var s=0,o=(n.length>>1)-1;s<=o;){var a=o+s>>1,l=r(n[2*a],n[2*a+1]);if(l>0)s=a+1;else{if(!(l<0))return a;o=a-1}}return-s-1}var a=new Int32Array(n.length/2);a.fill(0);var l=r.length/3;if(l>8*(1<h.maxNumPositions&&(h=c()),h.bucketNumber>8)return[e];-1===u[v]&&(u[v]=h.numPositions++,h.positionsCompressed.push(r[3*v]),h.positionsCompressed.push(r[3*v+1]),h.positionsCompressed.push(r[3*v+2])),-1===u[g]&&(u[g]=h.numPositions++,h.positionsCompressed.push(r[3*g]),h.positionsCompressed.push(r[3*g+1]),h.positionsCompressed.push(r[3*g+2])),-1===u[m]&&(u[m]=h.numPositions++,h.positionsCompressed.push(r[3*m]),h.positionsCompressed.push(r[3*m+1]),h.positionsCompressed.push(r[3*m+2])),h.indices.push(u[v]),h.indices.push(u[g]),h.indices.push(u[m]);var _=void 0;(_=o(v,g))>=0&&0===a[_]&&(a[_]=1,h.edgeIndices.push(u[n[2*_]]),h.edgeIndices.push(u[n[2*_+1]])),(_=o(v,m))>=0&&0===a[_]&&(a[_]=1,h.edgeIndices.push(u[n[2*_]]),h.edgeIndices.push(u[n[2*_+1]])),(_=o(g,m))>=0&&0===a[_]&&(a[_]=1,h.edgeIndices.push(u[n[2*_]]),h.edgeIndices.push(u[n[2*_+1]]))}var y=t/8*2,b=t/8,w=2*r.length+(s.length+n.length)*y,B=0;return r.length,A.forEach((function(e){B+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*b,e.positionsCompressed.length})),B>w?[e]:(i&&lh(A,e),A)}({positionsCompressed:r,indices:s,edgeIndices:n},r.length/3>65536?16:8):o=[{positionsCompressed:r,indices:s,edgeIndices:n}];return o}var Mh=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(r=t.call(this,e,s))._positions=s.positions||[],s.indices)r._indices=s.indices;else{r._indices=[];for(var n=0,o=r._positions.length/3-1;n1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,"BCFViewpoints",e,s)).originatingSystem=s.originatingSystem||"xeokit.io",r.authoringTool=s.authoringTool||"xeokit.io",r}return C(i,[{key:"getViewpoint",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=this.viewer.scene,r=i.camera,s=i.realWorldOffset,n=!0===t.reverseClippingPlanes,o={},a=re.normalizeVec3(re.subVec3(r.look,r.eye,re.vec3())),l=r.eye,u=r.up;r.yUp&&(a=Lh(a),l=Lh(l),u=Lh(u));var A=Sh(re.addVec3(l,s));"ortho"===r.projection?o.orthogonal_camera={camera_view_point:A,camera_direction:Sh(a),camera_up_vector:Sh(u),view_to_world_scale:r.ortho.scale}:o.perspective_camera={camera_view_point:A,camera_direction:Sh(a),camera_up_vector:Sh(u),field_of_view:r.perspective.fov};var h=i.sectionPlanes;for(var d in h)if(h.hasOwnProperty(d)){var p=h[d];if(!p.active)continue;var f=p.pos,v=void 0;v=n?re.negateVec3(p.dir,re.vec3()):p.dir,r.yUp&&(f=Lh(f),v=Lh(v)),re.addVec3(f,s),f=Sh(f),v=Sh(v),o.clipping_planes||(o.clipping_planes=[]),o.clipping_planes.push({location:f,direction:v})}var g=i.lineSets;for(var m in g)if(g.hasOwnProperty(m)){var _=g[m];o.lines||(o.lines=[]);for(var y=_.positions,b=_.indices,w=0,B=b.length/2;w1&&void 0!==arguments[1]?arguments[1]:{};if(e){var r=this.viewer,s=r.scene,n=s.camera,o=!1!==i.rayCast,a=!1!==i.immediate,l=!1!==i.reset,u=s.realWorldOffset,A=!0===i.reverseClippingPlanes;if(s.clearSectionPlanes(),e.clipping_planes&&e.clipping_planes.length>0&&e.clipping_planes.forEach((function(e){var t=Th(e.location,Eh),i=Th(e.direction,Eh);A&&re.negateVec3(i),re.subVec3(t,u),n.yUp&&(t=Rh(t),i=Rh(i)),new xn(s,{pos:t,dir:i})})),s.clearLines(),e.lines&&e.lines.length>0){var c=[],h=[],d=0;e.lines.forEach((function(e){e.start_point&&e.end_point&&(c.push(e.start_point.x),c.push(e.start_point.y),c.push(e.start_point.z),c.push(e.end_point.x),c.push(e.end_point.y),c.push(e.end_point.z),h.push(d++),h.push(d++))})),new Mh(s,{positions:c,indices:h,clippable:!1,collidable:!0})}if(s.clearBitmaps(),e.bitmaps&&e.bitmaps.length>0&&e.bitmaps.forEach((function(e){var t=e.bitmap_type||"jpg",i=e.bitmap_data,r=Th(e.location,Fh),o=Th(e.normal,kh),a=Th(e.up,Ih),l=e.height||1;t&&i&&r&&o&&a&&(n.yUp&&(r=Rh(r),o=Rh(o),a=Rh(a)),new ho(s,{src:i,type:t,pos:r,normal:o,up:a,clippable:!1,collidable:!0,height:l}))})),l&&(s.setObjectsXRayed(s.xrayedObjectIds,!1),s.setObjectsHighlighted(s.highlightedObjectIds,!1),s.setObjectsSelected(s.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(s.setObjectsVisible(s.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.visible=!1}))}))):(s.setObjectsVisible(s.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.visible=!0}))})));var p=e.components.visibility.view_setup_hints;p&&(!1===p.spaces_visible&&s.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcSpace"),!1),void 0!==p.spaces_translucent&&s.setObjectsXRayed(r.metaScene.getObjectIDsByType("IfcSpace"),!0),p.space_boundaries_visible,!1===p.openings_visible&&s.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcOpening"),!0),p.space_boundaries_translucent,void 0!==p.openings_translucent&&s.setObjectsXRayed(r.metaScene.getObjectIDsByType("IfcOpening"),!0))}e.components.selection&&(s.setObjectsSelected(s.selectedObjectIds,!1),e.components.selection.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.selected=!0}))}))),e.components.translucency&&(s.setObjectsXRayed(s.xrayedObjectIds,!1),e.components.translucency.forEach((function(e){return t._withBCFComponent(i,e,(function(e){return e.xrayed=!0}))}))),e.components.coloring&&e.components.coloring.forEach((function(e){var r=e.color,s=0,n=!1;8===r.length&&((s=parseInt(r.substring(0,2),16)/256)<=1&&s>=.95&&(s=1),r=r.substring(2),n=!0);var o=[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(i,e,(function(e){e.colorize=o,n&&(e.opacity=s)}))}))}))}if(e.perspective_camera||e.orthogonal_camera){var f,v,g,m;if(e.perspective_camera?(f=Th(e.perspective_camera.camera_view_point,Eh),v=Th(e.perspective_camera.camera_direction,Eh),g=Th(e.perspective_camera.camera_up_vector,Eh),n.perspective.fov=e.perspective_camera.field_of_view,m="perspective"):(f=Th(e.orthogonal_camera.camera_view_point,Eh),v=Th(e.orthogonal_camera.camera_direction,Eh),g=Th(e.orthogonal_camera.camera_up_vector,Eh),n.ortho.scale=e.orthogonal_camera.view_to_world_scale,m="ortho"),re.subVec3(f,u),n.yUp&&(f=Rh(f),v=Rh(v),g=Rh(g)),o){var _=s.pick({pickSurface:!0,origin:f,direction:v});v=_?_.worldPos:re.addVec3(f,v,Eh)}else v=re.addVec3(f,v,Eh);a?(n.eye=f,n.look=v,n.up=g,n.projection=m):r.cameraFlight.flyTo({eye:f,look:v,up:g,duration:i.duration,projection:m})}}}},{key:"_withBCFComponent",value:function(e,t,i){var r=this.viewer,s=r.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){var n=t.authoring_tool_id,o=s.objects[n];if(o)return void i(o);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[n])return void s.withObjects(r.metaScene.getObjectIDsInSubtree(n),i)}if(t.ifc_guid){var a=t.ifc_guid,l=s.objects[a];if(l)return void i(l);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[a])return void s.withObjects(r.metaScene.getObjectIDsInSubtree(a),i);Object.keys(s.models).forEach((function(t){var n=re.globalizeObjectId(t,a),o=s.objects[n];o?i(o):e.updateCompositeObjects&&r.metaScene.metaObjects[n]&&s.withObjects(r.metaScene.getObjectIDsInSubtree(n),i)}))}}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this)}}]),i}();function Sh(e){return{x:e[0],y:e[1],z:e[2]}}function Th(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function Lh(e){return new Float64Array([e[0],-e[2],e[1]])}function Rh(e){return new Float64Array([e[0],e[2],-e[1]])}function Uh(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 Oh=re.vec3(),Nh=function(e,t,i,r){var s=e-i,n=t-r;return Math.sqrt(s*s+n*n)};var Qh=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,i),(r=t.call(this,e.viewer.scene,s)).plugin=e,r._container=s.container,!r._container)throw"config missing: container";r._eventSubs={};var n=r.plugin.viewer.scene;r._originWorld=re.vec3(),r._targetWorld=re.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=s.color||r.plugin.defaultColor;var o=s.onMouseOver?function(e){s.onMouseOver(e,b(r)),r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mouseover",e))}:null,a=s.onMouseLeave?function(e){s.onMouseLeave(e,b(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))},A=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent("mousemove",e))},c=s.onContextMenu?function(e){s.onContextMenu(e,b(r))}:null,h=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return r._originDot=new ut(n,s.origin,r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._targetDot=new ut(n,s.target,r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._lengthWire=new ht(r._container,{color:r._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._xAxisWire=new ht(r._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._yAxisWire=new ht(r._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._zAxisWire=new ht(r._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._lengthLabel=new dt(r._container,{fillColor:r._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._xAxisLabel=new dt(r._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._yAxisLabel=new dt(r._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._zAxisLabel=new dt(r._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:o,onMouseLeave:a,onMouseWheel:h,onMouseDown:l,onMouseUp:u,onMouseMove:A,onContextMenu:c}),r._measurementOrientation="Horizontal",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._xLabelEnabled=!1,r._yLabelEnabled=!1,r._zLabelEnabled=!1,r._lengthLabelEnabled=!1,r._labelsVisible=!1,r._labelsOnWires=!1,r._clickable=!1,r._originDot.on("worldPos",(function(e){r._originWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._targetDot.on("worldPos",(function(e){r._targetWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._onViewMatrix=n.camera.on("viewMatrix",(function(){r._vpDirty=!0,r._needUpdate(0)})),r._onProjMatrix=n.camera.on("projMatrix",(function(){r._cpDirty=!0,r._needUpdate()})),r._onCanvasBoundary=n.canvas.on("boundary",(function(){r._cpDirty=!0,r._needUpdate(0)})),r._onMetricsUnits=n.metrics.on("units",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsScale=n.metrics.on("scale",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsOrigin=n.metrics.on("origin",(function(){r._cpDirty=!0,r._needUpdate()})),r._onSectionPlaneUpdated=n.on("sectionPlaneUpdated",(function(){r._sectionPlanesDirty=!0,r._needUpdate()})),r.approximate=s.approximate,r.visible=s.visible,r.originVisible=s.originVisible,r.targetVisible=s.targetVisible,r.wireVisible=s.wireVisible,r.axisVisible=s.axisVisible,r.xAxisVisible=s.xAxisVisible,r.yAxisVisible=s.yAxisVisible,r.zAxisVisible=s.zAxisVisible,r.xLabelEnabled=s.xLabelEnabled,r.yLabelEnabled=s.yLabelEnabled,r.zLabelEnabled=s.zLabelEnabled,r.lengthLabelEnabled=s.lengthLabelEnabled,r.labelsVisible=s.labelsVisible,r.labelsOnWires=s.labelsOnWires,r.useRotationAdjustment=s.useRotationAdjustment,r}return C(i,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;if(this._wpDirty&&(this._measurementOrientation=function(e,t,i){return Math.abs(t[1]-e[1])>i?"Vertical":"Horizontal"}(this._originWorld,this._targetWorld,0),"Vertical"===this._measurementOrientation&&this.useRotationAdjustment?(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._originWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._originWorld[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._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&&(re.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0),this._sectionPlanesDirty){if(this._isSliced(this._originWorld)||this._isSliced(this._targetWorld))return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setCulled(!0),this._yAxisWire.setCulled(!0),this._zAxisWire.setCulled(!0),this._lengthWire.setCulled(!0),this._originDot.setCulled(!0),void this._targetDot.setCulled(!0);this._xAxisLabel.setCulled(!1),this._yAxisLabel.setCulled(!1),this._zAxisLabel.setCulled(!1),this._lengthLabel.setCulled(!1),this._xAxisWire.setCulled(!1),this._yAxisWire.setCulled(!1),this._zAxisWire.setCulled(!1),this._lengthWire.setCulled(!1),this._originDot.setCulled(!1),this._targetDot.setCulled(!1),this._sectionPlanesDirty=!0}var t=this._originDot.viewPos[2],i=this._targetDot.viewPos[2];if(t>-.3||i>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){re.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var r=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect(),o=this._container.getBoundingClientRect(),a=n.top-o.top,l=n.left-o.left,u=e.canvas.boundary,A=u[2],c=u[3],h=0,d=this.plugin.viewer.scene.metrics,p=d.scale,f=d.units,v=d.unitsInfo[f].abbrev,g=0,m=r.length;g1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e.viewer.scene))._canvasToPagePos=s.canvasToPagePos,r.pointerLens=s.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!==s.snapping,r._mouseState=0,r._attachPlugin(e,s),r}return C(i,[{key:"_initMarkerDiv",value:function(){var e=document.createElement("div");e.setAttribute("id","myMarkerDiv");var t=this.scene.canvas.canvas;t.parentNode.insertBefore(e,t),e.style.background="black",e.style.border="2px solid blue",e.style.borderRadius="10px",e.style.width="5px",e.style.height="5px",e.style.top="-200px",e.style.left="-200px",e.style.margin="0 0",e.style.zIndex="100",e.style.position="absolute",e.style.pointerEvents="none",this._markerDiv=e}},{key:"_destroyMarkerDiv",value:function(){if(this._markerDiv){var e=document.getElementById("myMarkerDiv");e.parentNode.removeChild(e),this._markerDiv=null}}},{key:"_attachPlugin",value:function(e){this.distanceMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){this._markerDiv||this._initMarkerDiv(),this.fire("activated",!0);var t=this.distanceMeasurementsPlugin,i=this.scene,r=t.viewer.cameraControl,s=i.canvas.canvas;i.input;var n,o,a=!1,l=re.vec3(),u=re.vec2(),A=null;this._mouseState=0;var c=function e(t){return t.offsetTop+(t.offsetParent&&t.offsetParent!==s.parentNode&&e(t.offsetParent))},h=function e(t){return t.offsetLeft+(t.offsetParent&&t.offsetParent!==s.parentNode&&e(t.offsetParent))},d=re.vec2();this._onCameraControlHoverSnapOrSurface=r.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",(function(t){var i=t.snappedCanvasPos||t.canvasPos;a=!0,l.set(t.worldPos),u.set(t.canvasPos),0===e._mouseState?(e._canvasToPagePos?(e._canvasToPagePos(s,i,d),e._markerDiv.style.left="".concat(d[0]-5,"px"),e._markerDiv.style.top="".concat(d[1]-5,"px")):(e._markerDiv.style.left="".concat(h(s)+i[0]-5,"px"),e._markerDiv.style.top="".concat(c(s)+i[1]-5,"px")),e._markerDiv.style.background="pink",t.snappedToVertex||t.snappedToEdge?(e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.snappedCanvasPos||t.canvasPos,e.pointerLens.snapped=!0),e._markerDiv.style.background="greenyellow",e._markerDiv.style.border="2px solid green"):(e.pointerLens&&(e.pointerLens.visible=!0,e.pointerLens.canvasPos=t.canvasPos,e.pointerLens.snappedCanvasPos=t.canvasPos,e.pointerLens.snapped=!1),e._markerDiv.style.background="pink",e._markerDiv.style.border="2px solid red"),A=t.entity):(e._markerDiv.style.left="-10000px",e._markerDiv.style.top="-10000px"),s.style.cursor="pointer",e._currentDistanceMeasurement&&(e._currentDistanceMeasurement.wireVisible=e._currentDistanceMeasurementInitState.wireVisible,e._currentDistanceMeasurement.axisVisible=e._currentDistanceMeasurementInitState.axisVisible&&e.distanceMeasurementsPlugin.defaultAxisVisible,e._currentDistanceMeasurement.xAxisVisible=e._currentDistanceMeasurementInitState.xAxisVisible&&e.distanceMeasurementsPlugin.defaultXAxisVisible,e._currentDistanceMeasurement.yAxisVisible=e._currentDistanceMeasurementInitState.yAxisVisible&&e.distanceMeasurementsPlugin.defaultYAxisVisible,e._currentDistanceMeasurement.zAxisVisible=e._currentDistanceMeasurementInitState.zAxisVisible&&e.distanceMeasurementsPlugin.defaultZAxisVisible,e._currentDistanceMeasurement.targetVisible=e._currentDistanceMeasurementInitState.targetVisible,e._currentDistanceMeasurement.target.worldPos=l.slice(),e._markerDiv.style.left="-10000px",e._markerDiv.style.top="-10000px")})),s.addEventListener("mousedown",this._onMouseDown=function(e){1===e.which&&(n=e.clientX,o=e.clientY)}),s.addEventListener("mouseup",this._onMouseUp=function(i){1===i.which&&(i.clientX>n+20||i.clientXo+20||i.clientY1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,"DistanceMeasurements",e))._pointerLens=s.pointerLens,r._container=s.container||document.body,r._defaultControl=null,r._measurements={},r.labelMinAxisLength=s.labelMinAxisLength,r.defaultVisible=!1!==s.defaultVisible,r.defaultOriginVisible=!1!==s.defaultOriginVisible,r.defaultTargetVisible=!1!==s.defaultTargetVisible,r.defaultWireVisible=!1!==s.defaultWireVisible,r.defaultXLabelEnabled=!1!==s.defaultXLabelEnabled,r.defaultYLabelEnabled=!1!==s.defaultYLabelEnabled,r.defaultZLabelEnabled=!1!==s.defaultZLabelEnabled,r.defaultLengthLabelEnabled=!1!==s.defaultLengthLabelEnabled,r.defaultLabelsVisible=!1!==s.defaultLabelsVisible,r.defaultAxisVisible=!1!==s.defaultAxisVisible,r.defaultXAxisVisible=!1!==s.defaultXAxisVisible,r.defaultYAxisVisible=!1!==s.defaultYAxisVisible,r.defaultZAxisVisible=!1!==s.defaultZAxisVisible,r.defaultColor=void 0!==s.defaultColor?s.defaultColor:"#00BBFF",r.zIndex=s.zIndex||1e4,r.defaultLabelsOnWires=!1!==s.defaultLabelsOnWires,r.useRotationAdjustment=void 0!==s.useRotationAdjustment&&!1!==s.useRotationAdjustment,r._onMouseOver=function(e,t){r.fire("mouseOver",{plugin:b(r),distanceMeasurement:t,measurement:t,event:e})},r._onMouseLeave=function(e,t){r.fire("mouseLeave",{plugin:b(r),distanceMeasurement:t,measurement:t,event:e})},r._onContextMenu=function(e,t){r.fire("contextMenu",{plugin:b(r),distanceMeasurement:t,measurement:t,event:e})},r}return C(i,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){}},{key:"pointerLens",get:function(){return this._pointerLens}},{key:"control",get:function(){return this._defaultControl||(this._defaultControl=new Hh(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:"useRotationAdjustment",get:function(){return this._useRotationAdjustment},set:function(e){e=void 0!==e&&Boolean(e),this._useRotationAdjustment=e}},{key:"createMeasurement",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.viewer.scene.components[t.id]&&(this.error("Viewer scene component with this ID already exists: "+t.id),delete t.id);var i=t.origin,r=t.target,s=new Qh(this,{id:t.id,plugin:this,container:this._container,origin:{entity:i.entity,worldPos:i.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,xLabelEnabled:!1!==t.xLabelEnabled&&!1!==this.defaultXLabelEnabled,yLabelEnabled:!1!==t.yLabelEnabled&&!1!==this.defaultYLabelEnabled,zLabelEnabled:!1!==t.zLabelEnabled&&!1!==this.defaultZLabelEnabled,lengthLabelEnabled:!1!==t.lengthLabelEnabled&&!1!==this.defaultLengthLabelEnabled,labelsVisible:!1!==t.labelsVisible&&!1!==this.defaultLabelsVisible,useRotationAdjustment:this.useRotationAdjustment,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[s.id]=s,s.clickable=!0,s.on("destroyed",(function(){delete e._measurements[s.id]})),this.fire("measurementCreated",s),s}},{key:"destroyMeasurement",value:function(e){var t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("DistanceMeasurement not found: "+e)}},{key:"setLabelsShown",value:function(e){for(var t=0,i=Object.entries(this.measurements);t1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(r=t.call(this,e.viewer.scene)).pointerLens=s.pointerLens,r.pointerCircle=new Re(e.viewer),r._active=!1;var n=document.createElement("div"),o=r.scene.canvas.canvas;return o.parentNode.insertBefore(n,o),n.style.background="black",n.style.border="2px solid blue",n.style.borderRadius="10px",n.style.width="5px",n.style.height="5px",n.style.margin="-200px -200px",n.style.zIndex="100",n.style.position="absolute",n.style.pointerEvents="none",r.markerDiv=n,r._currentDistanceMeasurement=null,r._currentDistanceMeasurementInitState={wireVisible:null,axisVisible:null,xAxisVisible:null,yaxisVisible:null,zAxisVisible:null,targetVisible:null},r._onCanvasTouchStart=null,r._onCanvasTouchEnd=null,r._longTouchTimeoutMs=300,r._snapping=!1!==s.snapping,r._touchState=0,r._attachPlugin(e,s),r}return C(i,[{key:"_attachPlugin",value:function(e){this.distanceMeasurementsPlugin=e,this.plugin=e}},{key:"active",get:function(){return this._active}},{key:"snapping",get:function(){return this._snapping},set:function(e){e!==this._snapping?(this._snapping=e,this.deactivate(),this.activate()):this._snapping=e}},{key:"activate",value:function(){var e=this;if(!this._active){var t=this.plugin,i=this.scene,r=i.canvas.canvas;t.pointerLens;var s=re.vec3(),n=20,o=null;this._touchState=0;var a=re.vec2(),l=re.vec2(),u=re.vec2(),A=null,c=function(){e.plugin.viewer.cameraControl.active=!1},h=function(){e.plugin.viewer.cameraControl.active=!0};r.addEventListener("touchstart",this._onCanvasTouchStart=function(r){var u=r.touches.length;if(1===u){var d=r.touches[0],p=d.clientX,f=d.clientY;switch(a.set([p,f]),l.set([p,f]),e._touchState){case 0:if(1!==u&&null!==o)return o&&(clearTimeout(o),o=null),e._currentDistanceMeasurement&&(e._currentDistanceMeasurement.destroy(),e._currentDistanceMeasurement=null),h(),void(e._touchState=0);var v=i.pick({canvasPos:l,snapping:e._snapping,snapToEdge:e._snapping});if(v&&v.snapped)s.set(v.worldPos),e.pointerCircle.start(v.snappedCanvasPos);else{var g=i.pick({canvasPos:l,pickSurface:!0});if(!g||!g.worldPos)return;s.set(g.worldPos),e.pointerCircle.start(g.canvasPos)}o=setTimeout((function(){1!==u||l[0]>a[0]+n||l[0]a[1]+n||l[1]a[0]+n||l[0]a[1]+n||l[1]a[0]+n||da[1]+n||pa[0]+n||da[1]+n||p1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(r=t.call(this,"FastNav",e))._hideColorTexture=!1!==s.hideColorTexture,r._hidePBR=!1!==s.hidePBR,r._hideSAO=!1!==s.hideSAO,r._hideEdges=!1!==s.hideEdges,r._hideTransparentObjects=!!s.hideTransparentObjects,r._scaleCanvasResolution=!!s.scaleCanvasResolution,r._defaultScaleCanvasResolutionFactor=s.defaultScaleCanvasResolutionFactor||1,r._scaleCanvasResolutionFactor=s.scaleCanvasResolutionFactor||.6,r._delayBeforeRestore=!1!==s.delayBeforeRestore,r._delayBeforeRestoreSeconds=s.delayBeforeRestoreSeconds||.5;var n=1e3*r._delayBeforeRestoreSeconds,o=!1,a=function(){n=1e3*r._delayBeforeRestoreSeconds,o||(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=r._defaultScaleCanvasResolutionFactor,o=!0)},l=function(){e.scene.canvas.resolutionScale=r._defaultScaleCanvasResolutionFactor,e.scene._renderer.setEdgesEnabled(!0),e.scene._renderer.setColorTextureEnabled(!0),e.scene._renderer.setPBREnabled(!0),e.scene._renderer.setSAOEnabled(!0),e.scene._renderer.setTransparentEnabled(!0),o=!1};r._onCanvasBoundary=e.scene.canvas.on("boundary",a),r._onCameraMatrix=e.scene.camera.on("matrix",a),r._onSceneTick=e.scene.on("tick",(function(e){o&&(n-=e.deltaTime,(!r._delayBeforeRestore||n<=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&&a()})),r}return C(i,[{key:"hideColorTexture",get:function(){return this._hideColorTexture},set:function(e){this._hideColorTexture=e}},{key:"hidePBR",get:function(){return this._hidePBR},set:function(e){this._hidePBR=e}},{key:"hideSAO",get:function(){return this._hideSAO},set:function(e){this._hideSAO=e}},{key:"hideEdges",get:function(){return this._hideEdges},set:function(e){this._hideEdges=e}},{key:"hideTransparentObjects",get:function(){return this._hideTransparentObjects},set:function(e){this._hideTransparentObjects=!1!==e}},{key:"scaleCanvasResolution",get:function(){return this._scaleCanvasResolution},set:function(e){this._scaleCanvasResolution=e}},{key:"defaultScaleCanvasResolutionFactor",get:function(){return this._defaultScaleCanvasResolutionFactor},set:function(e){this._defaultScaleCanvasResolutionFactor=e||1}},{key:"scaleCanvasResolutionFactor",get:function(){return this._scaleCanvasResolutionFactor},set:function(e){this._scaleCanvasResolutionFactor=e||.6}},{key:"delayBeforeRestore",get:function(){return this._delayBeforeRestore},set:function(e){this._delayBeforeRestore=e}},{key:"delayBeforeRestoreSeconds",get:function(){return this._delayBeforeRestoreSeconds},set:function(e){this._delayBeforeRestoreSeconds=null!=e?e:.5}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.scene.camera.off(this._onCameraMatrix),this.viewer.scene.canvas.off(this._onCanvasBoundary),this.viewer.scene.input.off(this._onSceneMouseDown),this.viewer.scene.input.off(this._onSceneMouseUp),this.viewer.scene.input.off(this._onSceneMouseMove),this.viewer.scene.off(this._onSceneTick),f(w(i.prototype),"destroy",this).call(this)}}]),i}(),Yh=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};x(this,e),this.cacheBuster=!1!==t.cacheBuster}return C(e,[{key:"_cacheBusterURL",value:function(e){if(!this.cacheBuster)return e;var t=(new Date).getTime();return e.indexOf("?")>-1?e+"&_="+t:e+"?_="+t}},{key:"getMetaModel",value:function(e,t,i){he.loadJSON(this._cacheBusterURL(e),(function(e){t(e)}),(function(e){i(e)}))}},{key:"getGLTF",value:function(e,t,i){he.loadArraybuffer(this._cacheBusterURL(e),(function(e){t(e)}),(function(e){i(e)}))}},{key:"getGLB",value:function(e,t,i){he.loadArraybuffer(this._cacheBusterURL(e),(function(e){t(e)}),(function(e){i(e)}))}},{key:"getArrayBuffer",value:function(e,t,i,r){!function(e,t,i,r){var s=function(){};i=i||s,r=r||s;var n=/^data:(.*?)(;base64)?,(.*)$/,o=t.match(n);if(o){var a=!!o[2],l=o[3];l=window.decodeURIComponent(l),a&&(l=window.atob(l));try{for(var u=new ArrayBuffer(l.length),A=new Uint8Array(u),c=0;c0&&void 0!==arguments[0]?arguments[0]:{};x(this,e),this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=t.messages,this.locale=t.locale}return C(e,[{key:"messages",set:function(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}},{key:"loadMessages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var t in e)this._messages[t]=e[t];this.messages=this._messages}},{key:"clearMessages",value:function(){this.messages={}}},{key:"locales",get:function(){return this._locales}},{key:"locale",get:function(){return this._locale},set:function(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}},{key:"translate",value:function(e,t){var i=this._messages[this._locale];if(!i)return null;var r=Zh(e,i);return r?t?qh(r,t):r:null}},{key:"translatePlurals",value:function(e,t,i){var r=this._messages[this._locale];if(!r)return null;var s=Zh(e,r);return(s=0===(t=parseInt(""+t,10))?s.zero:t>1?s.other:s.one)?(s=qh(s,[t]),i&&(s=qh(s,i)),s):null}},{key:"fire",value:function(e,t,i){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==i&&(this._events[e]=t||!0);var r=this._eventSubs[e];if(r)for(var s in r){if(r.hasOwnProperty(s))r[s].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 i=this._eventSubs[e];i||(i={},this._eventSubs[e]=i);var r=this._eventSubIDMap.addItem();i[r]={callback:t},this._eventSubEvents[r]=e;var s=this._events[e];return void 0!==s&&t(s),r}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var i=this._eventSubs[t];i&&delete i[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function Zh(e,t){if(t[e])return t[e];for(var i=e.split("."),r=t,s=0,n=i.length;r&&s1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,i){return"{{"===e?"{":"}}"===e?"}":t[i]}))}var $h=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).t=s.t,r}return C(i,[{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"tangent",get:function(){return this.getTangent(this._t)}},{key:"length",get:function(){var e=this._getLengths();return e[e.length-1]}},{key:"getTangent",value:function(e){var t=1e-4;void 0===e&&(e=this._t);var i=e-t,r=e+t;i<0&&(i=0),r>1&&(r=1);var s=this.getPoint(i),n=this.getPoint(r),o=re.subVec3(n,s,[]);return re.normalizeVec3(o,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,i=[];for(t=0;t<=e;t++)i.push(this.getPoint(t/e));return i}},{key:"_getLengths",value:function(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,i,r=[],s=this.getPoint(0),n=0;for(r.push(0),i=1;i<=e;i++)t=this.getPoint(i/e),n+=re.lenVec3(re.subVec3(t,s,[])),r.push(n),s=t;return this.cacheArcLengths=r,r}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var i,r=this._getLengths(),s=0,n=r.length;i=t||e*r[n-1];for(var o,a=0,l=n-1;a<=l;)if((o=r[s=Math.floor(a+(l-a)/2)]-i)<0)a=s+1;else{if(!(o>0)){l=s;break}l=s-1}if(r[s=l]===i)return s/(n-1);var u=r[s];return(s+(i-u)/(r[s+1]-u))/(n-1)}}]),i}(),ed=function(e){g(i,$h);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).points=s.points,r.t=s.t,r}return C(i,[{key:"points",get:function(){return this._points},set:function(e){this._points=e||[]}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=this.points;if(!(t.length<3)){var i=(t.length-1)*e,r=Math.floor(i),s=i-r,n=t[0===r?r:r-1],o=t[r],a=t[r>t.length-2?t.length-1:r+1],l=t[r>t.length-3?t.length-1:r+2],u=re.vec3();return u[0]=re.catmullRomInterpolate(n[0],o[0],a[0],l[0],s),u[1]=re.catmullRomInterpolate(n[1],o[1],a[1],l[1],s),u[2]=re.catmullRomInterpolate(n[2],o[2],a[2],l[2],s),u}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}},{key:"getJSON",value:function(){return{points:points,t:this._t}}}]),i}(),td=re.vec3(),id=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s))._frames=[],r._eyeCurve=new ed(b(r)),r._lookCurve=new ed(b(r)),r._upCurve=new ed(b(r)),s.frames&&(r.addFrames(s.frames),r.smoothFrameTimes(1)),r}return C(i,[{key:"type",get:function(){return"CameraPath"}},{key:"frames",get:function(){return this._frames}},{key:"eyeCurve",get:function(){return this._eyeCurve}},{key:"lookCurve",get:function(){return this._lookCurve}},{key:"upCurve",get:function(){return this._upCurve}},{key:"saveFrame",value:function(e){var t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}},{key:"addFrame",value:function(e,t,i,r){var s={t:e,eye:t.slice(0),look:i.slice(0),up:r.slice(0)};this._frames.push(s),this._eyeCurve.points.push(s.eye),this._lookCurve.points.push(s.look),this._upCurve.points.push(s.up)}},{key:"addFrames",value:function(e){for(var t,i=0,r=e.length;i1?1:e,t.eye=this._eyeCurve.getPoint(e,td),t.look=this._lookCurve.getPoint(e,td),t.up=this._upCurve.getPoint(e,td)}},{key:"sampleFrame",value:function(e,t,i,r){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,i),this._upCurve.getPoint(e,r)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=re.vec3(),i=0;this._frames[0].t=0;for(var r=[],s=1,n=this._frames.length;s1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s))._look1=re.vec3(),r._eye1=re.vec3(),r._up1=re.vec3(),r._look2=re.vec3(),r._eye2=re.vec3(),r._up2=re.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!==s.easing,r.duration=s.duration,r.fit=s.fit,r.fitFOV=s.fitFOV,r.trail=s.trail,r}return C(i,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,i){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=i;var r,s,n,o,a,l=this.scene.camera,u=!!e.projection&&e.projection!==l.projection;if(this._eye1[0]=l.eye[0],this._eye1[1]=l.eye[1],this._eye1[2]=l.eye[2],this._look1[0]=l.look[0],this._look1[1]=l.look[1],this._look1[2]=l.look[2],this._up1[0]=l.up[0],this._up1[1]=l.up[1],this._up1[2]=l.up[2],this._orthoScale1=l.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)s=e.eye,n=e.look,o=e.up;else if(e.eye)s=e.eye;else if(e.look)n=e.look;else{var A=e;if((he.isNumeric(A)||he.isString(A))&&(a=A,!(A=this.scene.components[a])))return this.error("Component not found: "+he.inQuotes(a)),void(t&&(i?t.call(i):t()));u||(r=A.aabb||this.scene.aabb)}var c=e.poi;if(r){if(r[3]=1;e>1&&(e=1);var r=this.easing?i._ease(e,0,1,1):e,s=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(re.subVec3(s.eye,s.look,ad),s.eye=re.lerpVec3(r,0,1,this._eye1,this._eye2,nd),s.look=re.subVec3(nd,ad,sd)):this._flyingLook&&(s.look=re.lerpVec3(r,0,1,this._look1,this._look2,sd),s.up=re.lerpVec3(r,0,1,this._up1,this._up2,od)):this._flyingEyeLookUp&&(s.eye=re.lerpVec3(r,0,1,this._eye1,this._eye2,nd),s.look=re.lerpVec3(r,0,1,this._look1,this._look2,sd),s.up=re.lerpVec3(r,0,1,this._up1,this._up2,od)),this._projection2){var n="ortho"===this._projection2?i._easeOutExpo(e,0,1,1):i._easeInCubic(e,0,1,1);s.customProjection.matrix=re.lerpMat4(n,0,1,this._projMatrix1,this._projMatrix2)}else s.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return s.ortho.scale=this._orthoScale2,void this.stop();Be.scheduleTask(this._update,this)}}},{key:"stop",value:function(){if(this._flying){this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);var e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}}},{key:"cancel",value:function(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}},{key:"duration",get:function(){return this._duration/1e3},set:function(e){this._duration=e?1e3*e:500,this.stop()}},{key:"fit",get:function(){return this._fit},set:function(e){this._fit=!1!==e}},{key:"fitFOV",get:function(){return this._fitFOV},set:function(e){this._fitFOV=e||45}},{key:"trail",get:function(){return this._trail},set:function(e){this._trail=!!e}},{key:"destroy",value:function(){this.stop(),f(w(i.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,i,r){return-i*(e/=r)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,i,r){return i*(e/=r)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,i,r){return i*(1-Math.pow(2,-10*e/r))+t}}]),i}(),ud=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s))._cameraFlightAnimation=new ld(b(r)),r._t=0,r.state=i.SCRUBBING,r._playingFromT=0,r._playingToT=0,r._playingRate=s.playingRate||1,r._playingDir=1,r._lastTime=null,r.cameraPath=s.cameraPath,r._tick=r.scene.on("tick",r._updateT,b(r)),r}return C(i,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,r,s=performance.now(),n=this._lastTime?.001*(s-this._lastTime):0;if(this._lastTime=s,0!==n)switch(this.state){case i.SCRUBBING:return;case i.PLAYING:if(this._t+=this._playingRate*n,0===(t=this._cameraPath.frames.length)||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=i.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case i.PLAYING_TO:r=this._t+this._playingRate*n*this._playingDir,(this._playingDir<0&&r<=this._playingToT||this._playingDir>0&&r>=this._playingToT)&&(r=this._playingToT,this.state=i.SCRUBBING,this.fire("stopped")),this._t=r,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,i,r){return-i*(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=i.PLAYING)}},{key:"playToT",value:function(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=i.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var i=t.frames[e];i?this.playToT(i.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var r=this._cameraPath;if(r){var s=r.frames[e];s?(this.state=i.SCRUBBING,this._cameraFlightAnimation.flyTo(s,t)):this.error("flyToFrame - frame index out of range: "+e)}}},{key:"scrubToT",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=i.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=i.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=i.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),i}();ud.STOPPED=0,ud.SCRUBBING=1,ud.PLAYING=2,ud.PLAYING_TO=3;var Ad=re.vec3(),cd=re.vec3();re.vec3();var hd=re.vec3([0,-1,0]),dd=re.vec4([0,0,0,1]),pd=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s))._src=null,r._image=null,r._pos=re.vec3(),r._origin=re.vec3(),r._rtcPos=re.vec3(),r._dir=re.vec3(),r._size=1,r._imageSize=re.vec2(),r._texture=new Jn(b(r)),r._plane=new gn(b(r),{geometry:new Wi(b(r),ao({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Zi(b(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0}),clippable:s.clippable}),r._grid=new gn(b(r),{geometry:new Wi(b(r),oo({size:1,divisions:10})),material:new Zi(b(r),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:s.clippable}),r._node=new Tn(b(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=s.gridVisible,r.position=s.position,r.rotation=s.rotation,r.dir=s.dir,r.size=s.size,r.collidable=s.collidable,r.clippable=s.clippable,r.pickable=s.pickable,r.opacity=s.opacity,s.image?r.image=s.image:r.src=s.src,r}return C(i,[{key:"visible",get:function(){return this._plane.visible},set:function(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}},{key:"gridVisible",get:function(){return this._gridVisible},set:function(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var i=new Image;i.onload=function(){t._texture.image=i,t._imageSize[0]=i.width,t._imageSize[1]=i.height,t._updatePlaneSizeFromImage()},i.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),He(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}},{key:"rotation",get:function(){return this._node.rotation},set:function(e){this._node.rotation=e}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"dir",get:function(){return this._dir},set:function(e){if(this._dir.set(e||[0,0,-1]),e){var t=this.scene.center,i=[-this._dir[0],-this._dir[1],-this._dir[2]];re.subVec3(t,this.position,Ad);var r=-re.dotVec3(i,Ad);re.normalizeVec3(i),re.mulVec3Scalar(i,r,cd),re.vec3PairToQuaternion(hd,e,dd),this._node.quaternion=dd}}},{key:"collidable",get:function(){return this._node.collidable},set:function(e){this._node.collidable=!1!==e}},{key:"clippable",get:function(){return this._node.clippable},set:function(e){this._node.clippable=!1!==e}},{key:"pickable",get:function(){return this._node.pickable},set:function(e){this._node.pickable=!1!==e}},{key:"opacity",get:function(){return this._node.opacity},set:function(e){this._node.opacity=e}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],i=this._imageSize[1];if(t>i){var r=i/t;this._node.scale=[e,1,e*r]}else{var s=t/i;this._node.scale=[e*s,1,e]}}}]),i}(),fd=function(e){g(i,Di);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i);var n=b(r=t.call(this,e,s));r._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var o=r.scene.camera,a=r.scene.canvas;return r._onCameraViewMatrix=o.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=o.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=a.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new Ai({type:"point",pos:re.vec3([1,1,1]),color:re.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:s.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(n._shadowViewMatrixDirty){n._shadowViewMatrix||(n._shadowViewMatrix=re.identityMat4());var e=n._state.pos,t=o.look,i=o.up;re.lookAtMat4v(e,t,i,n._shadowViewMatrix),n._shadowViewMatrixDirty=!1}return n._shadowViewMatrix},getShadowProjMatrix:function(){if(n._shadowProjMatrixDirty){n._shadowProjMatrix||(n._shadowProjMatrix=re.identityMat4());var e=n.scene.canvas.canvas;re.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,n._shadowProjMatrix),n._shadowProjMatrixDirty=!1}return n._shadowProjMatrix},getShadowRenderBuf:function(){return n._shadowRenderBuf||(n._shadowRenderBuf=new si(n.scene.canvas.canvas,n.scene.canvas.gl,{size:[1024,1024]})),n._shadowRenderBuf}}),r.pos=s.pos,r.color=s.color,r.intensity=s.intensity,r.constantAttenuation=s.constantAttenuation,r.linearAttenuation=s.linearAttenuation,r.quadraticAttenuation=s.quadraticAttenuation,r.castsShadow=s.castsShadow,r.scene._lightCreated(b(r)),r}return C(i,[{key:"type",get:function(){return"PointLight"}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"constantAttenuation",get:function(){return this._state.attenuation[0]},set:function(e){this._state.attenuation[0]=e||0,this.glRedraw()}},{key:"linearAttenuation",get:function(){return this._state.attenuation[1]},set:function(e){this._state.attenuation[1]=e||0,this.glRedraw()}},{key:"quadraticAttenuation",get:function(){return this._state.attenuation[2]},set:function(e){this._state.attenuation[2]=e||0,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),f(w(i.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),i}();function vd(e){return 0==(e&e-1)}function gd(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var md=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,i);var n=(r=t.call(this,e,s)).scene.canvas.gl;return r._state=new Ai({texture:new Gn({gl:n,target:n.TEXTURE_CUBE_MAP}),flipY:r._checkFlipY(s.minFilter),encoding:r._checkEncoding(s.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),r._src=s.src,r._images=[],r._loadSrc(s.src),ae.memory.textures++,r}return C(i,[{key:"type",get:function(){return"CubeTexture"}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}},{key:"_loadSrc",value:function(e){var t=this,i=this.scene.canvas.gl;this._images=[];for(var r=!1,s=0,n=function(n){var o,a,l=new Image;l.onload=(o=l,a=n,function(){if(!r&&(o=function(e){if(!vd(e.width)||!vd(e.height)){var t=document.createElement("canvas");t.width=gd(e.width),t.height=gd(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(o),t._images[a]=o,6==++s)){var e=t._state.texture;e||(e=new Gn({gl:i,target:i.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}),l.onerror=function(){r=!0},l.src=e[n]},o=0;o1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).scene._lightsState.addReflectionMap(r._state),r.scene._reflectionMapCreated(b(r)),r}return C(i,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),i}(),yd=function(e){g(i,md);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).scene._lightMapCreated(b(r)),r}return C(i,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){f(w(i.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),i}(),bd=function(e){g(i,ot);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,{entity:s.entity,occludable:s.occludable,worldPos:s.worldPos}))._occluded=!1,r._visible=!0,r._src=null,r._image=null,r._pos=re.vec3(),r._origin=re.vec3(),r._rtcPos=re.vec3(),r._dir=re.vec3(),r._size=1,r._imageSize=re.vec2(),r._texture=new Jn(b(r),{src:s.src}),r._geometry=new Wi(b(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 gn(b(r),{geometry:r._geometry,material:new Zi(b(r),{ambient:[.9,.3,.9],shininess:30,diffuseMap:r._texture,backfaces:!0}),scale:[1,1,1],position:s.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),r.visible=!0,r.collidable=s.collidable,r.clippable=s.clippable,r.pickable=s.pickable,r.opacity=s.opacity,r.size=s.size,s.image?r.image=s.image:r.src=s.src,r}return C(i,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,f(w(i.prototype),"_setVisible",this).call(this,e)}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var i=new Image;i.onload=function(){t._texture.image=i,t._imageSize[0]=i.width,t._imageSize[1]=i.height,t._updatePlaneSizeFromImage()},i.src=this._src}}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"collidable",get:function(){return this._mesh.collidable},set:function(e){this._mesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._mesh.clippable},set:function(e){this._mesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._mesh.pickable},set:function(e){this._mesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._mesh.opacity},set:function(e){this._mesh.opacity=e}},{key:"_updatePlaneSizeFromImage",value:function(){var e=.5*this._size,t=this._imageSize[0],i=this._imageSize[1],r=i/t;this._geometry.positions=t>i?[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]}}]),i}(),wd=function(){function e(t){x(this,e),this._eye=re.vec3(),this._look=re.vec3(),this._up=re.vec3(),this._projection={},t&&this.saveCamera(t)}return C(e,[{key:"saveCamera",value:function(e){var t=e.camera,i=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:i.fov,fovAxis:i.fovAxis,near:i.near,far:i.far};break;case"ortho":this._projection={projection:"ortho",scale:i.scale,near:i.near,far:i.far};break;case"frustum":this._projection={projection:"frustum",left:i.left,right:i.right,top:i.top,bottom:i.bottom,near:i.near,far:i.far};break;case"custom":this._projection={projection:"custom",matrix:i.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var i=e.camera,r=this._projection;function s(){switch(r.type){case"perspective":i.perspective.fov=r.fov,i.perspective.fovAxis=r.fovAxis,i.perspective.near=r.near,i.perspective.far=r.far;break;case"ortho":i.ortho.scale=r.scale,i.ortho.near=r.near,i.ortho.far=r.far;break;case"frustum":i.frustum.left=r.left,i.frustum.right=r.right,i.frustum.top=r.top,i.frustum.bottom=r.bottom,i.frustum.near=r.near,i.frustum.far=r.far;break;case"custom":i.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(){s(),t()})):(i.eye=this._eye,i.look=this._look,i.up=this._up,s(),i.projection=r.projection)}}]),e}(),Bd=re.vec3(),xd=function(){function e(t){if(x(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,t){var i=t.metaScene.scene;this.saveObjects(i,t)}}return C(e,[{key:"saveObjects",value:function(e,t,i){this.numObjects=0,this._mask=i?he.apply(i,{}):null;for(var r=!i||i.visible,s=!i||i.edges,n=!i||i.xrayed,o=!i||i.highlighted,a=!i||i.selected,l=!i||i.clippable,u=!i||i.pickable,A=!i||i.colorize,c=!i||i.opacity,h=t.metaObjects,d=e.objects,p=0,f=h.length;p1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).v0=s.v0,r.v1=s.v1,r.v2=s.v2,r.v3=s.v3,r.t=s.t,r}return C(i,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||re.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||re.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||re.vec3([0,0,0])}},{key:"v3",get:function(){return this._v3},set:function(e){this.fire("v3",this._v3=e||re.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=re.vec3();return t[0]=re.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=re.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=re.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}]),i}(),Ed=function(e){g(i,$h);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s))._cachedLengths=[],r._dirty=!0,r._curves=[],r._t=0,r._dirtySubs=[],r._destroyedSubs=[],r.curves=s.curves||[],r.t=s.t,r}return C(i,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,i,r;for(e=e||[],i=0,r=this._curves.length;i1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"length",get:function(){var e=this._getCurveLengths();return e[e.length-1]}},{key:"getPoint",value:function(e){for(var t,i=e*this.length,r=this._getCurveLengths(),s=0;s=i){var n=1-(r[s]-i)/(t=this._curves[s]).length;return t.getPointAt(n)}s++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],i=0,r=this._curves.length;for(e=0;e1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s)).v0=s.v0,r.v1=s.v1,r.v2=s.v2,r.t=s.t,r}return C(i,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||re.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||re.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||re.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=re.vec3();return t[0]=re.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=re.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=re.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}]),i}(),kd=function(e){g(i,Ph);var t=_(i);function i(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),t.call(this,e,r)}return C(i)}(),Id=function(e){g(i,Ce);var t=_(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,i),(r=t.call(this,e,s))._skyboxMesh=new gn(b(r),{geometry:new Wi(b(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 Zi(b(r),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Jn(b(r),{src:s.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:s.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),r.size=s.size,r.active=s.active,r}return C(i,[{key:"size",get:function(){return this._size},set:function(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}},{key:"active",get:function(){return this._skyboxMesh.visible},set:function(e){this._skyboxMesh.visible=e}}]),i}(),Dd=function(){function e(){x(this,e)}return C(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),Sd=re.vec4(),Td=re.vec4(),Ld=re.vec3(),Rd=re.vec3(),Ud=re.vec3(),Od=re.vec4(),Nd=re.vec4(),Qd=re.vec4(),Vd=function(){function e(t){x(this,e),this._scene=t}return C(e,[{key:"dollyToCanvasPos",value:function(e,t,i){var r=!1,s=this._scene.camera;if(e){var n=re.subVec3(e,s.eye,Ld);r=re.lenVec3(n)0&&void 0!==arguments[0]?arguments[0]:{};this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);var t=e.color||[1,0,0];this._pivotSphereMaterial=new Zi(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=re.lookAtMat4v(e.eye,e.look,e.worldUp);re.transformPoint3(t,this.getPivotPos(),this._cameraOffset);var i=this.getPivotPos();this._cameraOffset[2]+=re.distVec3(e.eye,i),t=re.inverseMat4(t);var r=re.transformVec3(t,this._cameraOffset),s=re.vec3();if(re.subVec3(e.eye,i,s),re.addVec3(s,r),e.zUp){var n=s[1];s[1]=s[2],s[2]=n}this._radius=re.lenVec3(s),this._polar=Math.acos(s[1]/this._radius),this._azimuth=Math.atan2(s[0],s[2]),this._pivoting=!0}},{key:"_cameraLookingDownwards",value:function(){var e=this._scene.camera,t=re.normalizeVec3(re.subVec3(e.look,e.eye,Hd)),i=re.cross3Vec3(t,e.worldUp,jd);return re.sqLenVec3(i)<=1e-4}},{key:"getPivoting",value:function(){return this._pivoting}},{key:"setPivotPos",value:function(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}},{key:"setCanvasPivotPos",value:function(e){var t=this._scene.camera,i=Math.abs(re.distVec3(this._scene.center,t.eye)),r=t.project.transposedMatrix,s=r.subarray(8,12),n=r.subarray(12),o=[0,0,-1,1],a=re.dotVec4(o,s)/re.dotVec4(o,n),l=zd;t.project.unproject(e,a,Wd,Kd,l);var u=re.normalizeVec3(re.subVec3(l,t.eye,Hd)),A=re.addVec3(t.eye,re.mulVec3Scalar(u,i,jd),Gd);this.setPivotPos(A)}},{key:"getPivotPos",value:function(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}},{key:"continuePivot",value:function(e,t){if(this._pivoting&&(0!==e||0!==t)){var i=this._scene.camera,r=-e,s=-t;1===i.worldUp[2]&&(r=-r),this._azimuth+=.01*-r,this._polar+=.01*s,this._polar=re.clamp(this._polar,.001,Math.PI-.001);var n=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===i.worldUp[2]){var o=n[1];n[1]=n[2],n[2]=o}var a=re.lenVec3(re.subVec3(i.look,i.eye,re.vec3())),l=this.getPivotPos();re.addVec3(n,l);var u=re.lookAtMat4v(n,l,i.worldUp);u=re.inverseMat4(u);var A=re.transformVec3(u,this._cameraOffset);u[12]-=A[0],u[13]-=A[1],u[14]-=A[2];var c=[u[8],u[9],u[10]];i.eye=[u[12],u[13],u[14]],re.subVec3(i.eye,re.mulVec3Scalar(c,a),i.look),i.up=[u[4],u[5],u[6]],this.showPivot()}}},{key:"showPivot",value:function(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}},{key:"hidePivot",value:function(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}},{key:"endPivot",value:function(){this._pivoting=!1}},{key:"destroy",value:function(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}]),e}(),Yd=function(){function e(t,i){x(this,e),this._scene=t.scene,this._cameraControl=t,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=i,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=re.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}return C(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){var e="".concat(~~this.pickCursorPos[0],"-").concat(~~this.pickCursorPos[1],"-").concat(this.scheduleSnapOrPick,"-").concat(this.schedulePickSurface,"-").concat(this.schedulePickEntity);if(this._lastHash!==e){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;var t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var i=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});i&&(i.snappedToEdge||i.snappedToVertex)?(this.snapPickResult=i,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var 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 s=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(s[0]===this.pickCursorPos[0]&&s[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 Rt;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var t=this.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=t)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}]),e}(),Jd=re.vec2(),Zd=function(){function e(t,i,r,s,n){x(this,e),this._scene=t;var o,a,l,u=i.pickController,A=0,c=0,h=0,d=0,p=!1,f=re.vec3(),v=!0,g=this._scene.canvas.canvas,m=[];function _(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];g.style.cursor="move",y(),e&&b()}function y(){A=s.pointerCanvasPos[0],c=s.pointerCanvasPos[1],h=s.pointerCanvasPos[0],d=s.pointerCanvasPos[1]}function b(){u.pickCursorPos=s.pointerCanvasPos,u.schedulePickSurface=!0,u.update(),u.picked&&u.pickedSurface&&u.pickResult&&u.pickResult.worldPos?(p=!0,f.set(u.pickResult.worldPos)):p=!1}document.addEventListener("keydown",this._documentKeyDownHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var i=e.keyCode;m[i]=!0}}),document.addEventListener("keyup",this._documentKeyUpHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var i=e.keyCode;m[i]=!1}}),g.addEventListener("mousedown",this._mouseDownHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:m[t.input.KEY_SHIFT]||r.planView?(o=!0,_()):(o=!0,_(!1));break;case 2:a=!0,_();break;case 3:l=!0,r.panRightClick&&_()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&(o||a||l)){var i=t.canvas.boundary,u=i[2],h=i[3],d=s.pointerCanvasPos[0],v=s.pointerCanvasPos[1],g=m[t.input.KEY_SHIFT]||r.planView||!r.panRightClick&&a||r.panRightClick&&l,_=document.pointerLockElement?e.movementX:d-A,y=document.pointerLockElement?e.movementY:v-c;if(g){var b=t.camera;if("perspective"===b.projection){var w=Math.abs(p?re.lenVec3(re.subVec3(f,t.camera.eye,[])):t.camera.eyeLookDist)*Math.tan(b.perspective.fov/2*Math.PI/180);n.panDeltaX+=1.5*_*w/h,n.panDeltaY+=1.5*y*w/h}else n.panDeltaX+=.5*b.ortho.scale*(_/h),n.panDeltaY+=.5*b.ortho.scale*(y/h)}else!o||a||l||r.planView||(r.firstPerson?(n.rotateDeltaY-=_/u*r.dragRotationRate/2,n.rotateDeltaX+=y/h*(r.dragRotationRate/4)):(n.rotateDeltaY-=_/u*(1.5*r.dragRotationRate),n.rotateDeltaX+=y/h*(1.5*r.dragRotationRate)));A=d,c=v}}),g.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){r.active&&r.pointerEnabled&&s.mouseover&&(v=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:case 2:case 3:o=!1,a=!1,l=!1}}),g.addEventListener("mouseup",this._mouseUpHandler=function(e){if(r.active&&r.pointerEnabled){if(3===e.which){!function(e,t){if(e){for(var i=e.target,r=0,s=0,n=0,o=0;i.offsetParent;)r+=i.offsetLeft,s+=i.offsetTop,n+=i.scrollLeft,o+=i.scrollTop,i=i.offsetParent;t[0]=e.pageX+n-r,t[1]=e.pageY+o-s}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Jd);var t=Jd[0],s=Jd[1];Math.abs(t-h)<3&&Math.abs(s-d)<3&&i.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Jd,event:e},!0)}g.style.removeProperty("cursor")}}),g.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var w=1/60,B=null;g.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled){var t=performance.now()/1e3,i=null!==B?t-B:0;B=t,i>.05&&(i=.05),i0?i.cameraFlight.flyTo(rp,(function(){i.pivotController.getPivoting()&&r.followPointer&&i.pivotController.showPivot()})):(i.cameraFlight.jumpTo(rp),i.pivotController.getPivoting()&&r.followPointer&&i.pivotController.showPivot())}}}))}return C(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.input.off(this._onSceneKeyDown)}}]),e}(),np=function(){function e(t,i,r,s,n){var o=this;x(this,e),this._scene=t;var a=i.pickController,l=i.pivotController,u=i.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;var A=!1,c=!1,h=this._scene.canvas.canvas,d=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var s=e&&e.entity?e.entity.aabb:t.aabb;if(r){var n=t.camera;re.subVec3(n.eye,n.look,[]),i.cameraFlight.flyTo({aabb:s})}else i.cameraFlight.flyTo({aabb:s})},p=t.tickify(this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!A&&!c){if(u.hasSubs("rayMove")){var i=re.vec3(),n=re.vec3();re.canvasPosToWorldRay(t.canvas.canvas,t.camera.viewMatrix,t.camera.projMatrix,t.camera.projection,s.pointerCanvasPos,i,n),u.fire("rayMove",{canvasPos:s.pointerCanvasPos,ray:{origin:i,direction:n,canvasPos:s.pointerCanvasPos}},!0)}var l=u.hasSubs("hover"),h=u.hasSubs("hoverEnter"),d=u.hasSubs("hoverOut"),p=u.hasSubs("hoverOff"),f=u.hasSubs("hoverSurface"),v=u.hasSubs("hoverSnapOrSurface");if(l||h||d||p||f||v)if(a.pickCursorPos=s.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=f,a.scheduleSnapOrPick=v,a.update(),a.pickResult){if(a.pickResult.entity){var g=a.pickResult.entity.id;o._lastPickedEntityId!==g&&(void 0!==o._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[o._lastPickedEntityId]},!0),u.fire("hoverEnter",a.pickResult,!0),o._lastPickedEntityId=g)}u.fire("hover",a.pickResult,!0),(a.pickResult.worldPos||a.pickResult.snappedWorldPos)&&u.fire("hoverSurface",a.pickResult,!0)}else void 0!==o._lastPickedEntityId&&(u.fire("hoverOut",{entity:t.objects[o._lastPickedEntityId]},!0),o._lastPickedEntityId=void 0),u.fire("hoverOff",{canvasPos:a.pickCursorPos},!0)}});h.addEventListener("mousemove",p),h.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(A=!0),3===e.which&&(c=!0),1===e.which&&r.active&&r.pointerEnabled&&(s.mouseDownClientX=e.clientX,s.mouseDownClientY=e.clientY,s.mouseDownCursorX=s.pointerCanvasPos[0],s.mouseDownCursorY=s.pointerCanvasPos[1],!r.firstPerson&&r.followPointer&&(a.pickCursorPos=s.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),1===e.which))){var i=a.pickResult;i&&i.worldPos?(l.setPivotPos(i.worldPos),l.startPivot()):(r.smartPivot?l.setCanvasPivotPos(s.pointerCanvasPos):l.setPivotPos(t.camera.look),l.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(A=!1),3===e.which&&(c=!1),l.getPivoting()&&l.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(r.active&&r.pointerEnabled&&(1===e.which&&(l.hidePivot(),!(Math.abs(e.clientX-s.mouseDownClientX)>3||Math.abs(e.clientY-s.mouseDownClientY)>3)))){var n=u.hasSubs("picked"),A=u.hasSubs("pickedNothing"),c=u.hasSubs("pickedSurface"),h=u.hasSubs("doublePicked"),p=u.hasSubs("doublePickedSurface"),f=u.hasSubs("doublePickedNothing");if(!(r.doublePickFlyTo||h||p||f))return(n||A||c)&&(a.pickCursorPos=s.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=c,a.update(),a.pickResult?(u.fire("picked",a.pickResult,!0),a.pickedSurface&&u.fire("pickedSurface",a.pickResult,!0)):u.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0)),void(o._clicks=0);if(o._clicks++,1===o._clicks){a.pickCursorPos=s.pointerCanvasPos,a.schedulePickEntity=r.doublePickFlyTo,a.schedulePickSurface=c,a.update();var v=a.pickResult,g=a.pickedSurface;o._timeout=setTimeout((function(){v&&v.worldPos?(u.fire("picked",v,!0),g&&(u.fire("pickedSurface",v,!0),!r.firstPerson&&r.followPointer&&(i.pivotController.setPivotPos(v.worldPos),i.pivotController.startPivot()&&i.pivotController.showPivot()))):u.fire("pickedNothing",{canvasPos:s.pointerCanvasPos},!0),o._clicks=0}),r.doubleClickTimeFrame)}else{if(null!==o._timeout&&(window.clearTimeout(o._timeout),o._timeout=null),a.pickCursorPos=s.pointerCanvasPos,a.schedulePickEntity=r.doublePickFlyTo||h||p,a.schedulePickSurface=a.schedulePickEntity&&p,a.update(),a.pickResult){if(u.fire("doublePicked",a.pickResult,!0),a.pickedSurface&&u.fire("doublePickedSurface",a.pickResult,!0),r.doublePickFlyTo&&(d(a.pickResult),!r.firstPerson&&r.followPointer)){var m=a.pickResult.entity.aabb,_=re.getAABB3Center(m);i.pivotController.setPivotPos(_),i.pivotController.startPivot()&&i.pivotController.showPivot()}}else if(u.fire("doublePickedNothing",{canvasPos:s.pointerCanvasPos},!0),r.doublePickFlyTo&&(d(),!r.firstPerson&&r.followPointer)){var y=t.aabb,b=re.getAABB3Center(y);i.pivotController.setPivotPos(b),i.pivotController.startPivot()&&i.pivotController.showPivot()}o._clicks=0}}},!1)}return C(e,[{key:"reset",value:function(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}]),e}(),op=function(){function e(t,i,r,s,n){x(this,e),this._scene=t;var o=t.input,a=[],l=t.canvas.canvas,u=!0;this._onSceneMouseMove=o.on("mousemove",(function(){u=!0})),this._onSceneKeyDown=o.on("keydown",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(r.keyboardEnabledOnlyIfMouseover&&!s.mouseover||(a[e]=!0,e===o.KEY_SHIFT&&(l.style.cursor="move")))})),this._onSceneKeyUp=o.on("keyup",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(a[e]=!1,e===o.KEY_SHIFT&&(l.style.cursor=null),i.pivotController.getPivoting()&&i.pivotController.endPivot())})),this._onTick=t.on("tick",(function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(!r.keyboardEnabledOnlyIfMouseover||s.mouseover)){var l=i.cameraControl,A=e.deltaTime/1e3;if(!r.planView){var c=l._isKeyDownForAction(l.ROTATE_Y_POS,a),h=l._isKeyDownForAction(l.ROTATE_Y_NEG,a),d=l._isKeyDownForAction(l.ROTATE_X_POS,a),p=l._isKeyDownForAction(l.ROTATE_X_NEG,a),f=A*r.keyboardRotationRate;(c||h||d||p)&&(!r.firstPerson&&r.followPointer&&i.pivotController.startPivot(),c?n.rotateDeltaY+=f:h&&(n.rotateDeltaY-=f),d?n.rotateDeltaX+=f:p&&(n.rotateDeltaX-=f),!r.firstPerson&&r.followPointer&&i.pivotController.startPivot())}if(!a[o.KEY_CTRL]&&!a[o.KEY_ALT]){var v=l._isKeyDownForAction(l.DOLLY_BACKWARDS,a),g=l._isKeyDownForAction(l.DOLLY_FORWARDS,a);if(v||g){var m=A*r.keyboardDollyRate;!r.firstPerson&&r.followPointer&&i.pivotController.startPivot(),g?n.dollyDelta-=m:v&&(n.dollyDelta+=m),u&&(s.followPointerDirty=!0,u=!1)}}var _=l._isKeyDownForAction(l.PAN_FORWARDS,a),y=l._isKeyDownForAction(l.PAN_BACKWARDS,a),b=l._isKeyDownForAction(l.PAN_LEFT,a),w=l._isKeyDownForAction(l.PAN_RIGHT,a),B=l._isKeyDownForAction(l.PAN_UP,a),x=l._isKeyDownForAction(l.PAN_DOWN,a),P=(a[o.KEY_ALT]?.3:1)*A*r.keyboardPanRate;(_||y||b||w||B||x)&&(!r.firstPerson&&r.followPointer&&i.pivotController.startPivot(),x?n.panDeltaY+=P:B&&(n.panDeltaY+=-P),w?n.panDeltaX+=-P:b&&(n.panDeltaX+=P),y?n.panDeltaZ+=P:_&&(n.panDeltaZ+=-P))}}))}return C(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}]),e}(),ap=re.vec3(),lp=function(){function e(t,i,r,s,n){x(this,e),this._scene=t;var o=t.camera,a=i.pickController,l=i.pivotController,u=i.panController,A=1,c=1,h=null;this._onTick=t.on("tick",(function(){if(r.active&&r.pointerEnabled){var e="default";if(Math.abs(n.dollyDelta)<.001&&(n.dollyDelta=0),Math.abs(n.rotateDeltaX)<.001&&(n.rotateDeltaX=0),Math.abs(n.rotateDeltaY)<.001&&(n.rotateDeltaY=0),0===n.rotateDeltaX&&0===n.rotateDeltaY||(n.dollyDelta=0),r.followPointer){if(--A<=0&&(A=1,0!==n.dollyDelta)){if(0===n.rotateDeltaY&&0===n.rotateDeltaX&&r.followPointer&&s.followPointerDirty&&(a.pickCursorPos=s.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.pickResult&&a.pickResult.worldPos?h=a.pickResult.worldPos:(c=1,h=null),s.followPointerDirty=!1),h){var i=Math.abs(re.lenVec3(re.subVec3(h,t.camera.eye,ap)));c=i/r.dollyProximityThreshold}cr.longTapRadius||Math.abs(g)>r.longTapRadius)&&(clearTimeout(s.longTouchTimeout),s.longTouchTimeout=null),r.planView){var m=t.camera;if("perspective"===m.projection){var _=Math.abs(t.camera.eyeLookDist)*Math.tan(m.perspective.fov/2*Math.PI/180);n.panDeltaX+=v*_/l*r.touchPanRate,n.panDeltaY+=g*_/l*r.touchPanRate}else n.panDeltaX+=.5*m.ortho.scale*(v/l)*r.touchPanRate,n.panDeltaY+=.5*m.ortho.scale*(g/l)*r.touchPanRate}else n.rotateDeltaY-=v/a*(1*r.dragRotationRate),n.rotateDeltaX+=g/l*(1.5*r.dragRotationRate)}else if(2===p){var y=d[0],b=d[1];cp(y,u),cp(b,A);var w=re.geometricMeanVec2(h[0],h[1]),B=re.geometricMeanVec2(u,A),x=re.vec2();re.subVec2(w,B,x);var P=x[0],C=x[1],M=t.camera,E=re.distVec2([y.pageX,y.pageY],[b.pageX,b.pageY]),F=(re.distVec2(h[0],h[1])-E)*r.touchDollyRate;if(n.dollyDelta=F,Math.abs(F)<1)if("perspective"===M.projection){var k=o.pickResult?o.pickResult.worldPos:t.center,I=Math.abs(re.lenVec3(re.subVec3(k,t.camera.eye,[])))*Math.tan(M.perspective.fov/2*Math.PI/180);n.panDeltaX-=P*I/l*r.touchPanRate,n.panDeltaY-=C*I/l*r.touchPanRate}else n.panDeltaX-=.5*M.ortho.scale*(P/l)*r.touchPanRate,n.panDeltaY-=.5*M.ortho.scale*(C/l)*r.touchPanRate;s.pointerCanvasPos=B}for(var D=0;D-1&&t-c<150&&(h>-1&&c-h<325?(dp(n[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=o,a.update(),a.pickResult?(a.pickResult.touchInput=!0,l.fire("doublePicked",a.pickResult),a.pickedSurface&&l.fire("doublePickedSurface",a.pickResult),r.doublePickFlyTo&&p(a.pickResult)):(l.fire("doublePickedNothing"),r.doublePickFlyTo&&p()),h=-1):re.distVec2(u[0],A)<4&&(dp(n[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=o,a.update(),a.pickResult?(a.pickResult.touchInput=!0,l.fire("picked",a.pickResult),a.pickedSurface&&l.fire("pickedSurface",a.pickResult)):l.fire("pickedNothing"),h=t),c=-1),u.length=i.length;for(var d=0,f=i.length;d1&&void 0!==arguments[1]?arguments[1]:{};x(this,i),(r=t.call(this,e,s)).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,keyboardEnabledOnlyIfMouseover:!0,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:re.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:re.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},r._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};var n=r.scene;return r._controllers={cameraControl:b(r),pickController:new Yd(b(r),r._configs),pivotController:new Xd(n,r._configs),panController:new Vd(n),cameraFlight:new ld(b(r),{duration:.5})},r._handlers=[new up(r.scene,r._controllers,r._configs,r._states,r._updates),new hp(r.scene,r._controllers,r._configs,r._states,r._updates),new Zd(r.scene,r._controllers,r._configs,r._states,r._updates),new sp(r.scene,r._controllers,r._configs,r._states,r._updates),new np(r.scene,r._controllers,r._configs,r._states,r._updates),new pp(r.scene,r._controllers,r._configs,r._states,r._updates),new op(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cameraUpdater=new lp(r.scene,r._controllers,r._configs,r._states,r._updates),r.navMode=s.navMode,s.planView&&(r.planView=s.planView),r.constrainVertical=s.constrainVertical,s.keyboardLayout?r.keyboardLayout=s.keyboardLayout:r.keyMap=s.keyMap,r.doublePickFlyTo=s.doublePickFlyTo,r.panRightClick=s.panRightClick,r.active=s.active,r.followPointer=s.followPointer,r.rotationInertia=s.rotationInertia,r.keyboardPanRate=s.keyboardPanRate,r.touchPanRate=s.touchPanRate,r.keyboardRotationRate=s.keyboardRotationRate,r.dragRotationRate=s.dragRotationRate,r.touchDollyRate=s.touchDollyRate,r.dollyInertia=s.dollyInertia,r.dollyProximityThreshold=s.dollyProximityThreshold,r.dollyMinSpeed=s.dollyMinSpeed,r.panInertia=s.panInertia,r.pointerEnabled=!0,r.keyboardDollyRate=s.keyboardDollyRate,r.mouseWheelDollyRate=s.mouseWheelDollyRate,r}return C(i,[{key:"keyMap",get:function(){return this._keyMap},set:function(e){if(e=e||"qwerty",he.isString(e)){var t=this.scene.input,i={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":i[this.PAN_LEFT]=[t.KEY_A],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_Z],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":i[this.PAN_LEFT]=[t.KEY_Q],i[this.PAN_RIGHT]=[t.KEY_D],i[this.PAN_UP]=[t.KEY_W],i[this.PAN_DOWN]=[t.KEY_X],i[this.PAN_BACKWARDS]=[],i[this.PAN_FORWARDS]=[],i[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],i[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],i[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],i[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],i[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],i[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],i[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],i[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],i[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],i[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],i[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],i[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=i}else{var r=e;this._keyMap=r}}},{key:"_isKeyDownForAction",value:function(e,t){var i=this._keyMap[e];if(!i)return!1;t||(t=this.scene.input.keyDown);for(var r=0,s=i.length;r0&&void 0!==arguments[0]?arguments[0]:{};this._controllers.pivotController.enablePivotSphere(e)}},{key:"disablePivotSphere",value:function(){this._controllers.pivotController.disablePivotSphere()}},{key:"smartPivot",get:function(){return this._configs.smartPivot},set:function(e){this._configs.smartPivot=!1!==e}},{key:"doubleClickTimeFrame",get:function(){return this._configs.doubleClickTimeFrame},set:function(e){this._configs.doubleClickTimeFrame=null!=e?e:250}},{key:"destroy",value:function(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),f(w(i.prototype),"destroy",this).call(this)}},{key:"_destroyHandlers",value:function(){for(var e=0,t=this._handlers.length;e1&&void 0!==arguments[1]?arguments[1]:{};if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);var i=this.metaScene,r=e.properties;if(r)for(var s=0,n=r.length;s0&&console.error("[MetaModel._decompressProperties] Properties not found: ".concat(i))}},{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 i=e.metaObjects[t];if(i.children&&(i.children=[]),i.propertySets&&(i.propertySets=[]),i.propertySetIds)for(var r=0,s=i.propertySetIds.length;r0?bp(t):null,o=i&&i.length>0?bp(i):null;return function e(t){if(t){var i=!0;(o&&o[t.type]||n&&!n[t.type])&&(i=!1),i&&r.push(t.id);var s=t.children;if(s)for(var a=0,l=s.length;a * Copyright (c) 2022 Niklas von Hertzen