@thatopen/components 3.1.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -92
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +5 -12
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +58 -58
package/dist/index.min.mjs
CHANGED
|
@@ -4,7 +4,7 @@ var t=Object.defineProperty,e=(e,i,s)=>(((e,i,s)=>{i in e?t(e,i,{enumerable:!0,c
|
|
|
4
4
|
* https://github.com/yomotsu/camera-controls
|
|
5
5
|
* (c) 2017 @yomotsu
|
|
6
6
|
* Released under the MIT License.
|
|
7
|
-
*/const qe=1,Ge=2,Qe=4,Ke=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,SCREEN_PAN:4,OFFSET:8,DOLLY:16,ZOOM:32,TOUCH_ROTATE:64,TOUCH_TRUCK:128,TOUCH_SCREEN_PAN:256,TOUCH_OFFSET:512,TOUCH_DOLLY:1024,TOUCH_ZOOM:2048,TOUCH_DOLLY_TRUCK:4096,TOUCH_DOLLY_SCREEN_PAN:8192,TOUCH_DOLLY_OFFSET:16384,TOUCH_DOLLY_ROTATE:32768,TOUCH_ZOOM_TRUCK:65536,TOUCH_ZOOM_OFFSET:131072,TOUCH_ZOOM_SCREEN_PAN:262144,TOUCH_ZOOM_ROTATE:524288}),Je=0,ti=1,ei=-1;function ii(t){return t.isPerspectiveCamera}function si(t){return t.isOrthographicCamera}const ni=2*Math.PI,ri=Math.PI/2,oi=Math.PI/180;function ai(t,e,i){return Math.max(e,Math.min(i,t))}function li(t,e=1e-5){return Math.abs(t)<e}function hi(t,e,i=1e-5){return li(t-e,i)}function ci(t,e){return Math.round(t/e)*e}function di(t){return isFinite(t)?t:t<0?-Number.MAX_VALUE:Number.MAX_VALUE}function ui(t){return Math.abs(t)<Number.MAX_VALUE?t:t*(1/0)}function pi(t,e,i,s,n=1/0,r){const o=2/(s=Math.max(1e-4,s)),a=o*r,l=1/(1+a+.48*a*a+.235*a*a*a);let h=t-e;const c=e,d=n*s;h=ai(h,-d,d),e=t-h;const u=(i.value+o*h)*r;i.value=(i.value-o*u)*l;let p=e+(h+u)*l;return c-t>0==p>c&&(p=c,i.value=(p-c)/r),p}function fi(t,e,i,s,n=1/0,r,o){const a=2/(s=Math.max(1e-4,s)),l=a*r,h=1/(1+l+.48*l*l+.235*l*l*l);let c=e.x,d=e.y,u=e.z,p=t.x-c,f=t.y-d,m=t.z-u;const g=c,_=d,y=u,w=n*s,v=p*p+f*f+m*m;if(v>w*w){const t=Math.sqrt(v);p=p/t*w,f=f/t*w,m=m/t*w}c=t.x-p,d=t.y-f,u=t.z-m;const b=(i.x+a*p)*r,x=(i.y+a*f)*r,E=(i.z+a*m)*r;i.x=(i.x-a*b)*h,i.y=(i.y-a*x)*h,i.z=(i.z-a*E)*h,o.x=c+(p+b)*h,o.y=d+(f+x)*h,o.z=u+(m+E)*h;const T=g-t.x,C=_-t.y,S=y-t.z;return T*(o.x-g)+C*(o.y-_)+S*(o.z-y)>0&&(o.x=g,o.y=_,o.z=y,i.x=(o.x-g)/r,i.y=(o.y-_)/r,i.z=(o.z-y)/r),o}function mi(t,e){e.set(0,0),t.forEach(t=>{e.x+=t.clientX,e.y+=t.clientY}),e.x/=t.length,e.y/=t.length}function gi(t,e){return!!si(t)&&(console.warn(`${e} is not supported in OrthographicCamera`),!0)}class _i{constructor(){this._listeners={}}addEventListener(t,e){const i=this._listeners;void 0===i[t]&&(i[t]=[]),-1===i[t].indexOf(e)&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return void 0!==i[t]&&-1!==i[t].indexOf(e)}removeEventListener(t,e){const i=this._listeners[t];if(void 0!==i){const t=i.indexOf(e);-1!==t&&i.splice(t,1)}}removeAllEventListeners(t){t?Array.isArray(this._listeners[t])&&(this._listeners[t].length=0):this._listeners={}}dispatchEvent(t){const e=this._listeners[t.type];if(void 0!==e){t.target=this;const i=e.slice(0);for(let e=0,s=i.length;e<s;e++)i[e].call(this,t)}}}var yi;const wi=1/8,vi=/Mac/.test(null===(yi=null===globalThis||void 0===globalThis?void 0:globalThis.navigator)||void 0===yi?void 0:yi.platform);let bi,xi,Ei,Ti,Ci,Si,Ai,Oi,Pi,Ii,ki,Di,zi,Mi,Bi,Ni,Ui,Li,Ri,Fi,Vi,ji,Zi;class Hi extends _i{static install(t){bi=t.THREE,xi=Object.freeze(new bi.Vector3(0,0,0)),Ei=Object.freeze(new bi.Vector3(0,1,0)),Ti=Object.freeze(new bi.Vector3(0,0,1)),Ci=new bi.Vector2,Si=new bi.Vector3,Ai=new bi.Vector3,Oi=new bi.Vector3,Pi=new bi.Vector3,Ii=new bi.Vector3,ki=new bi.Vector3,Di=new bi.Vector3,zi=new bi.Vector3,Mi=new bi.Vector3,Bi=new bi.Spherical,Ni=new bi.Spherical,Ui=new bi.Box3,Li=new bi.Box3,Ri=new bi.Sphere,Fi=new bi.Quaternion,Vi=new bi.Quaternion,ji=new bi.Matrix4,Zi=new bi.Raycaster}static get ACTION(){return Ke}set verticalDragToForward(t){console.warn("camera-controls: `verticalDragToForward` was removed. Use `mouseButtons.left = CameraControls.ACTION.SCREEN_PAN` instead.")}constructor(t,e){super(),this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=Number.EPSILON,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.dollyDragInverted=!1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=Ke.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Je,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new bi.Vector3,this._focalOffsetVelocity=new bi.Vector3,this._zoomVelocity={value:0},this._truckInternal=(t,e,i,s)=>{let n,r;if(ii(this._camera)){const i=Si.copy(this._camera.position).sub(this._target),s=this._camera.getEffectiveFOV()*oi,o=i.length()*Math.tan(.5*s);n=this.truckSpeed*t*o/this._elementRect.height,r=this.truckSpeed*e*o/this._elementRect.height}else{if(!si(this._camera))return;{const i=this._camera;n=this.truckSpeed*t*(i.right-i.left)/i.zoom/this._elementRect.width,r=this.truckSpeed*e*(i.top-i.bottom)/i.zoom/this._elementRect.height}}s?(i?this.setFocalOffset(this._focalOffsetEnd.x+n,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(n,0,!0),this.forward(-r,!0)):i?this.setFocalOffset(this._focalOffsetEnd.x+n,this._focalOffsetEnd.y+r,this._focalOffsetEnd.z,!0):this.truck(n,r,!0)},this._rotateInternal=(t,e)=>{const i=ni*this.azimuthRotateSpeed*t/this._elementRect.height,s=ni*this.polarRotateSpeed*e/this._elementRect.height;this.rotate(i,s,!0)},this._dollyInternal=(t,e,i)=>{const s=Math.pow(.95,-t*this.dollySpeed),n=this._sphericalEnd.radius,r=this._sphericalEnd.radius*s,o=ai(r,this.minDistance,this.maxDistance),a=o-r;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(r,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(a,!0),this._dollyToNoClamp(o,!0)):this._dollyToNoClamp(o,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?r:o)-n,this._dollyControlCoord.set(e,i)),this._lastDollyDirection=Math.sign(-t)},this._zoomInternal=(t,e,i)=>{const s=Math.pow(.95,t*this.dollySpeed),n=this._zoom,r=this._zoom*s;this.zoomTo(r,!0),this.dollyToCursor&&(this._changedZoom+=r-n,this._dollyControlCoord.set(e,i))},void 0===bi&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=t,this._yAxisUpSpace=(new bi.Quaternion).setFromUnitVectors(this._camera.up,Ei),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=Ke.NONE,this._target=new bi.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new bi.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=(new bi.Spherical).setFromVector3(Si.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new bi.Vector3,new bi.Vector3,new bi.Vector3,new bi.Vector3],this._updateNearPlaneCorners(),this._boundary=new bi.Box3(new bi.Vector3(-1/0,-1/0,-1/0),new bi.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new bi.Vector2,this.mouseButtons={left:Ke.ROTATE,middle:Ke.DOLLY,right:Ke.TRUCK,wheel:ii(this._camera)?Ke.DOLLY:si(this._camera)?Ke.ZOOM:Ke.NONE},this.touches={one:Ke.TOUCH_ROTATE,two:ii(this._camera)?Ke.TOUCH_DOLLY_TRUCK:si(this._camera)?Ke.TOUCH_ZOOM_TRUCK:Ke.NONE,three:Ke.TOUCH_TRUCK};const i=new bi.Vector2,s=new bi.Vector2,n=new bi.Vector2,r=t=>{if(!this._enabled||!this._domElement)return;if(0!==this._interactiveArea.left||0!==this._interactiveArea.top||1!==this._interactiveArea.width||1!==this._interactiveArea.height){const e=this._domElement.getBoundingClientRect(),i=t.clientX/e.width,s=t.clientY/e.height;if(i<this._interactiveArea.left||i>this._interactiveArea.right||s<this._interactiveArea.top||s>this._interactiveArea.bottom)return}const e="mouse"!==t.pointerType?null:(t.buttons&qe)===qe?qe:(t.buttons&Qe)===Qe?Qe:(t.buttons&Ge)===Ge?Ge:null;if(null!==e){const t=this._findPointerByMouseButton(e);t&&this._disposePointer(t)}if((t.buttons&qe)===qe&&this._lockedPointer)return;const i={pointerId:t.pointerId,clientX:t.clientX,clientY:t.clientY,deltaX:0,deltaY:0,mouseButton:e};this._activePointers.push(i),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",a),this._isDragging=!0,d(t)},o=t=>{t.cancelable&&t.preventDefault();const e=t.pointerId,i=this._lockedPointer||this._findPointerById(e);if(i){if(i.clientX=t.clientX,i.clientY=t.clientY,i.deltaX=t.movementX,i.deltaY=t.movementY,this._state=0,"touch"===t.pointerType)switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(t.buttons&qe)===qe)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(t.buttons&Qe)===Qe&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(t.buttons&Ge)===Ge&&(this._state=this._state|this.mouseButtons.right);u()}},a=t=>{const e=this._findPointerById(t.pointerId);if(!e||e!==this._lockedPointer){if(e&&this._disposePointer(e),"touch"===t.pointerType)switch(this._activePointers.length){case 0:this._state=Ke.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else this._state=Ke.NONE;p()}};let l=-1;const h=t=>{if(!this._domElement)return;if(!this._enabled||this.mouseButtons.wheel===Ke.NONE)return;if(0!==this._interactiveArea.left||0!==this._interactiveArea.top||1!==this._interactiveArea.width||1!==this._interactiveArea.height){const e=this._domElement.getBoundingClientRect(),i=t.clientX/e.width,s=t.clientY/e.height;if(i<this._interactiveArea.left||i>this._interactiveArea.right||s<this._interactiveArea.top||s>this._interactiveArea.bottom)return}if(t.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===Ke.ROTATE||this.mouseButtons.wheel===Ke.TRUCK){const t=performance.now();l-t<1e3&&this._getClientRect(this._elementRect),l=t}const e=vi?-1:-3,i=1===t.deltaMode||t.ctrlKey?t.deltaY/e:t.deltaY/(10*e),s=this.dollyToCursor?(t.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,n=this.dollyToCursor?(t.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case Ke.ROTATE:this._rotateInternal(t.deltaX,t.deltaY),this._isUserControllingRotate=!0;break;case Ke.TRUCK:this._truckInternal(t.deltaX,t.deltaY,!1,!1),this._isUserControllingTruck=!0;break;case Ke.SCREEN_PAN:this._truckInternal(t.deltaX,t.deltaY,!1,!0),this._isUserControllingTruck=!0;break;case Ke.OFFSET:this._truckInternal(t.deltaX,t.deltaY,!0,!1),this._isUserControllingOffset=!0;break;case Ke.DOLLY:this._dollyInternal(-i,s,n),this._isUserControllingDolly=!0;break;case Ke.ZOOM:this._zoomInternal(-i,s,n),this._isUserControllingZoom=!0}this.dispatchEvent({type:"control"})},c=t=>{if(this._domElement&&this._enabled){if(this.mouseButtons.right===Hi.ACTION.NONE){const e=t instanceof PointerEvent?t.pointerId:0,i=this._findPointerById(e);return i&&this._disposePointer(i),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),void this._domElement.ownerDocument.removeEventListener("pointerup",a)}t.preventDefault()}},d=t=>{if(!this._enabled)return;mi(this._activePointers,Ci),this._getClientRect(this._elementRect),i.copy(Ci),s.copy(Ci);if(this._activePointers.length>=2){const t=Ci.x-this._activePointers[1].clientX,e=Ci.y-this._activePointers[1].clientY,i=Math.sqrt(t*t+e*e);n.set(0,i);const r=.5*(this._activePointers[0].clientX+this._activePointers[1].clientX),o=.5*(this._activePointers[0].clientY+this._activePointers[1].clientY);s.set(r,o)}if(this._state=0,t)if("pointerType"in t&&"touch"===t.pointerType)switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else this._lockedPointer||(t.buttons&qe)!==qe||(this._state=this._state|this.mouseButtons.left),(t.buttons&Qe)===Qe&&(this._state=this._state|this.mouseButtons.middle),(t.buttons&Ge)===Ge&&(this._state=this._state|this.mouseButtons.right);else this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);(this._state&Ke.ROTATE)!==Ke.ROTATE&&(this._state&Ke.TOUCH_ROTATE)!==Ke.TOUCH_ROTATE&&(this._state&Ke.TOUCH_DOLLY_ROTATE)!==Ke.TOUCH_DOLLY_ROTATE&&(this._state&Ke.TOUCH_ZOOM_ROTATE)!==Ke.TOUCH_ZOOM_ROTATE||(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),(this._state&Ke.TRUCK)!==Ke.TRUCK&&(this._state&Ke.SCREEN_PAN)!==Ke.SCREEN_PAN&&(this._state&Ke.TOUCH_TRUCK)!==Ke.TOUCH_TRUCK&&(this._state&Ke.TOUCH_SCREEN_PAN)!==Ke.TOUCH_SCREEN_PAN&&(this._state&Ke.TOUCH_DOLLY_TRUCK)!==Ke.TOUCH_DOLLY_TRUCK&&(this._state&Ke.TOUCH_DOLLY_SCREEN_PAN)!==Ke.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Ke.TOUCH_ZOOM_TRUCK)!==Ke.TOUCH_ZOOM_TRUCK&&(this._state&Ke.TOUCH_ZOOM_SCREEN_PAN)!==Ke.TOUCH_DOLLY_SCREEN_PAN||(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),(this._state&Ke.DOLLY)!==Ke.DOLLY&&(this._state&Ke.TOUCH_DOLLY)!==Ke.TOUCH_DOLLY&&(this._state&Ke.TOUCH_DOLLY_TRUCK)!==Ke.TOUCH_DOLLY_TRUCK&&(this._state&Ke.TOUCH_DOLLY_SCREEN_PAN)!==Ke.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Ke.TOUCH_DOLLY_OFFSET)!==Ke.TOUCH_DOLLY_OFFSET&&(this._state&Ke.TOUCH_DOLLY_ROTATE)!==Ke.TOUCH_DOLLY_ROTATE||(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),(this._state&Ke.ZOOM)!==Ke.ZOOM&&(this._state&Ke.TOUCH_ZOOM)!==Ke.TOUCH_ZOOM&&(this._state&Ke.TOUCH_ZOOM_TRUCK)!==Ke.TOUCH_ZOOM_TRUCK&&(this._state&Ke.TOUCH_ZOOM_SCREEN_PAN)!==Ke.TOUCH_ZOOM_SCREEN_PAN&&(this._state&Ke.TOUCH_ZOOM_OFFSET)!==Ke.TOUCH_ZOOM_OFFSET&&(this._state&Ke.TOUCH_ZOOM_ROTATE)!==Ke.TOUCH_ZOOM_ROTATE||(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),(this._state&Ke.OFFSET)!==Ke.OFFSET&&(this._state&Ke.TOUCH_OFFSET)!==Ke.TOUCH_OFFSET&&(this._state&Ke.TOUCH_DOLLY_OFFSET)!==Ke.TOUCH_DOLLY_OFFSET&&(this._state&Ke.TOUCH_ZOOM_OFFSET)!==Ke.TOUCH_ZOOM_OFFSET||(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},u=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,mi(this._activePointers,Ci);const t=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,e=t?-t.deltaX:s.x-Ci.x,r=t?-t.deltaY:s.y-Ci.y;if(s.copy(Ci),(this._state&Ke.ROTATE)!==Ke.ROTATE&&(this._state&Ke.TOUCH_ROTATE)!==Ke.TOUCH_ROTATE&&(this._state&Ke.TOUCH_DOLLY_ROTATE)!==Ke.TOUCH_DOLLY_ROTATE&&(this._state&Ke.TOUCH_ZOOM_ROTATE)!==Ke.TOUCH_ZOOM_ROTATE||(this._rotateInternal(e,r),this._isUserControllingRotate=!0),(this._state&Ke.DOLLY)===Ke.DOLLY||(this._state&Ke.ZOOM)===Ke.ZOOM){const t=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,e=this.dollyToCursor?(i.y-this._elementRect.y)/this._elementRect.height*-2+1:0,s=this.dollyDragInverted?-1:1;(this._state&Ke.DOLLY)===Ke.DOLLY?(this._dollyInternal(s*r*wi,t,e),this._isUserControllingDolly=!0):(this._zoomInternal(s*r*wi,t,e),this._isUserControllingZoom=!0)}if((this._state&Ke.TOUCH_DOLLY)===Ke.TOUCH_DOLLY||(this._state&Ke.TOUCH_ZOOM)===Ke.TOUCH_ZOOM||(this._state&Ke.TOUCH_DOLLY_TRUCK)===Ke.TOUCH_DOLLY_TRUCK||(this._state&Ke.TOUCH_ZOOM_TRUCK)===Ke.TOUCH_ZOOM_TRUCK||(this._state&Ke.TOUCH_DOLLY_SCREEN_PAN)===Ke.TOUCH_DOLLY_SCREEN_PAN||(this._state&Ke.TOUCH_ZOOM_SCREEN_PAN)===Ke.TOUCH_ZOOM_SCREEN_PAN||(this._state&Ke.TOUCH_DOLLY_OFFSET)===Ke.TOUCH_DOLLY_OFFSET||(this._state&Ke.TOUCH_ZOOM_OFFSET)===Ke.TOUCH_ZOOM_OFFSET||(this._state&Ke.TOUCH_DOLLY_ROTATE)===Ke.TOUCH_DOLLY_ROTATE||(this._state&Ke.TOUCH_ZOOM_ROTATE)===Ke.TOUCH_ZOOM_ROTATE){const t=Ci.x-this._activePointers[1].clientX,e=Ci.y-this._activePointers[1].clientY,i=Math.sqrt(t*t+e*e),r=n.y-i;n.set(0,i);const o=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,a=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&Ke.TOUCH_DOLLY)===Ke.TOUCH_DOLLY||(this._state&Ke.TOUCH_DOLLY_ROTATE)===Ke.TOUCH_DOLLY_ROTATE||(this._state&Ke.TOUCH_DOLLY_TRUCK)===Ke.TOUCH_DOLLY_TRUCK||(this._state&Ke.TOUCH_DOLLY_SCREEN_PAN)===Ke.TOUCH_DOLLY_SCREEN_PAN||(this._state&Ke.TOUCH_DOLLY_OFFSET)===Ke.TOUCH_DOLLY_OFFSET?(this._dollyInternal(r*wi,o,a),this._isUserControllingDolly=!0):(this._zoomInternal(r*wi,o,a),this._isUserControllingZoom=!0)}(this._state&Ke.TRUCK)!==Ke.TRUCK&&(this._state&Ke.TOUCH_TRUCK)!==Ke.TOUCH_TRUCK&&(this._state&Ke.TOUCH_DOLLY_TRUCK)!==Ke.TOUCH_DOLLY_TRUCK&&(this._state&Ke.TOUCH_ZOOM_TRUCK)!==Ke.TOUCH_ZOOM_TRUCK||(this._truckInternal(e,r,!1,!1),this._isUserControllingTruck=!0),(this._state&Ke.SCREEN_PAN)!==Ke.SCREEN_PAN&&(this._state&Ke.TOUCH_SCREEN_PAN)!==Ke.TOUCH_SCREEN_PAN&&(this._state&Ke.TOUCH_DOLLY_SCREEN_PAN)!==Ke.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Ke.TOUCH_ZOOM_SCREEN_PAN)!==Ke.TOUCH_ZOOM_SCREEN_PAN||(this._truckInternal(e,r,!1,!0),this._isUserControllingTruck=!0),(this._state&Ke.OFFSET)!==Ke.OFFSET&&(this._state&Ke.TOUCH_OFFSET)!==Ke.TOUCH_OFFSET&&(this._state&Ke.TOUCH_DOLLY_OFFSET)!==Ke.TOUCH_DOLLY_OFFSET&&(this._state&Ke.TOUCH_ZOOM_OFFSET)!==Ke.TOUCH_ZOOM_OFFSET||(this._truckInternal(e,r,!0,!1),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},p=()=>{mi(this._activePointers,Ci),s.copy(Ci),this._dragNeedsUpdate=!1,(0===this._activePointers.length||1===this._activePointers.length&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),0===this._activePointers.length&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{this._enabled&&this._domElement&&(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",f),this._domElement.ownerDocument.addEventListener("pointerlockerror",m),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",a),d())},this.unlockPointer=()=>{var t,e,i;null!==this._lockedPointer&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),null===(t=this._domElement)||void 0===t||t.ownerDocument.exitPointerLock(),null===(e=this._domElement)||void 0===e||e.ownerDocument.removeEventListener("pointerlockchange",f),null===(i=this._domElement)||void 0===i||i.ownerDocument.removeEventListener("pointerlockerror",m),this.cancel()};const f=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},m=()=>{this.unlockPointer()};this._addAllEventListeners=t=>{this._domElement=t,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",r),this._domElement.addEventListener("pointercancel",a),this._domElement.addEventListener("wheel",h,{passive:!1}),this._domElement.addEventListener("contextmenu",c)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",r),this._domElement.removeEventListener("pointercancel",a),this._domElement.removeEventListener("wheel",h,{passive:!1}),this._domElement.removeEventListener("contextmenu",c),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.ownerDocument.removeEventListener("pointerlockchange",f),this._domElement.ownerDocument.removeEventListener("pointerlockerror",m))},this.cancel=()=>{this._state!==Ke.NONE&&(this._state=Ke.NONE,this._activePointers.length=0,p())},e&&this.connect(e),this.update(0)}get camera(){return this._camera}set camera(t){this._camera=t,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this._domElement&&(t?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(t){this._spherical.radius===t&&this._sphericalEnd.radius===t||(this._spherical.radius=t,this._sphericalEnd.radius=t,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(t){this._spherical.theta===t&&this._sphericalEnd.theta===t||(this._spherical.theta=t,this._sphericalEnd.theta=t,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(t){this._spherical.phi===t&&this._sphericalEnd.phi===t||(this._spherical.phi=t,this._sphericalEnd.phi=t,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(t){this._boundaryEnclosesCamera=t,this._needsUpdate=!0}set interactiveArea(t){this._interactiveArea.width=ai(t.width,0,1),this._interactiveArea.height=ai(t.height,0,1),this._interactiveArea.x=ai(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=ai(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,i=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,i)}rotateAzimuthTo(t,e=!1){return this.rotateTo(t,this._sphericalEnd.phi,e)}rotatePolarTo(t,e=!1){return this.rotateTo(this._sphericalEnd.theta,t,e)}rotateTo(t,e,i=!1){this._isUserControllingRotate=!1;const s=ai(t,this.minAzimuthAngle,this.maxAzimuthAngle),n=ai(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=s,this._sphericalEnd.phi=n,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,i||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const r=!i||hi(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&hi(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(r)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Je,this._changedDolly=0,this._dollyToNoClamp(ai(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const i=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const e=this._collisionTest(),s=hi(e,this._spherical.radius);if(!(i>t)&&s)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,e)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const s=!e||hi(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(s)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(Pi).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const i=!e||hi(this._target.x,this._targetEnd.x,this.restThreshold)&&hi(this._target.y,this._targetEnd.y,this.restThreshold)&&hi(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(i)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=ai(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const i=!e||hi(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(i)}pan(t,e,i=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,i)}truck(t,e,i=!1){this._camera.updateMatrix(),Ii.setFromMatrixColumn(this._camera.matrix,0),ki.setFromMatrixColumn(this._camera.matrix,1),Ii.multiplyScalar(t),ki.multiplyScalar(-e);const s=Si.copy(Ii).add(ki),n=Ai.copy(this._targetEnd).add(s);return this.moveTo(n.x,n.y,n.z,i)}forward(t,e=!1){Si.setFromMatrixColumn(this._camera.matrix,0),Si.crossVectors(this._camera.up,Si),Si.multiplyScalar(t);const i=Ai.copy(this._targetEnd).add(Si);return this.moveTo(i.x,i.y,i.z,e)}elevate(t,e=!1){return Si.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+Si.x,this._targetEnd.y+Si.y,this._targetEnd.z+Si.z,e)}moveTo(t,e,i,s=!1){this._isUserControllingTruck=!1;const n=Si.set(t,e,i).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,n,this.boundaryFriction),this._needsUpdate=!0,s||this._target.copy(this._targetEnd);const r=!s||hi(this._target.x,this._targetEnd.x,this.restThreshold)&&hi(this._target.y,this._targetEnd.y,this.restThreshold)&&hi(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(t,e,i,s=!1){const n=Si.set(t,e,i).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(n.x,n.y,n.z,s)}fitToBox(t,e,{cover:i=!1,paddingLeft:s=0,paddingRight:n=0,paddingBottom:r=0,paddingTop:o=0}={}){const a=[],l=t.isBox3?Ui.copy(t):Ui.setFromObject(t);l.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const h=ci(this._sphericalEnd.theta,ri),c=ci(this._sphericalEnd.phi,ri);a.push(this.rotateTo(h,c,e));const d=Si.setFromSpherical(this._sphericalEnd).normalize(),u=Fi.setFromUnitVectors(d,Ti),p=hi(Math.abs(d.y),1);p&&u.multiply(Vi.setFromAxisAngle(Ei,h)),u.multiply(this._yAxisUpSpaceInverse);const f=Li.makeEmpty();Ai.copy(l.min).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.min).setX(l.max.x).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.min).setY(l.max.y).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.max).setZ(l.min.z).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.min).setZ(l.max.z).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.max).setY(l.min.y).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.max).setX(l.min.x).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.max).applyQuaternion(u),f.expandByPoint(Ai),f.min.x-=s,f.min.y-=r,f.max.x+=n,f.max.y+=o,u.setFromUnitVectors(Ti,d),p&&u.premultiply(Vi.invert()),u.premultiply(this._yAxisUpSpace);const m=f.getSize(Si),g=f.getCenter(Ai).applyQuaternion(u);if(ii(this._camera)){const t=this.getDistanceToFitBox(m.x,m.y,m.z,i);a.push(this.moveTo(g.x,g.y,g.z,e)),a.push(this.dollyTo(t,e)),a.push(this.setFocalOffset(0,0,0,e))}else if(si(this._camera)){const t=this._camera,s=t.right-t.left,n=t.top-t.bottom,r=i?Math.max(s/m.x,n/m.y):Math.min(s/m.x,n/m.y);a.push(this.moveTo(g.x,g.y,g.z,e)),a.push(this.zoomTo(r,e)),a.push(this.setFocalOffset(0,0,0,e))}return Promise.all(a)}fitToSphere(t,e){const i=[],s="isObject3D"in t?Hi.createBoundingSphere(t,Ri):Ri.copy(t);if(i.push(this.moveTo(s.center.x,s.center.y,s.center.z,e)),ii(this._camera)){const t=this.getDistanceToFitSphere(s.radius);i.push(this.dollyTo(t,e))}else if(si(this._camera)){const t=this._camera.right-this._camera.left,n=this._camera.top-this._camera.bottom,r=2*s.radius,o=Math.min(t/r,n/r);i.push(this.zoomTo(o,e))}return i.push(this.setFocalOffset(0,0,0,e)),Promise.all(i)}setLookAt(t,e,i,s,n,r,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Je,this._changedDolly=0;const a=Ai.set(s,n,r),l=Si.set(t,e,i);this._targetEnd.copy(a),this._sphericalEnd.setFromVector3(l.sub(a).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const h=!o||hi(this._target.x,this._targetEnd.x,this.restThreshold)&&hi(this._target.y,this._targetEnd.y,this.restThreshold)&&hi(this._target.z,this._targetEnd.z,this.restThreshold)&&hi(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&hi(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&hi(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(h)}lerpLookAt(t,e,i,s,n,r,o,a,l,h,c,d,u,p=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Je,this._changedDolly=0;const f=Si.set(s,n,r),m=Ai.set(t,e,i);Bi.setFromVector3(m.sub(f).applyQuaternion(this._yAxisUpSpace));const g=Oi.set(h,c,d),_=Ai.set(o,a,l);Ni.setFromVector3(_.sub(g).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(f.lerp(g,u));const y=Ni.theta-Bi.theta,w=Ni.phi-Bi.phi,v=Ni.radius-Bi.radius;this._sphericalEnd.set(Bi.radius+v*u,Bi.phi+w*u,Bi.theta+y*u),this.normalizeRotations(),this._needsUpdate=!0,p||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const b=!p||hi(this._target.x,this._targetEnd.x,this.restThreshold)&&hi(this._target.y,this._targetEnd.y,this.restThreshold)&&hi(this._target.z,this._targetEnd.z,this.restThreshold)&&hi(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&hi(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&hi(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(b)}setPosition(t,e,i,s=!1){return this.setLookAt(t,e,i,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,s)}setTarget(t,e,i,s=!1){const n=this.getPosition(Si),r=this.setLookAt(n.x,n.y,n.z,t,e,i,s);return this._sphericalEnd.phi=ai(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),r}setFocalOffset(t,e,i,s=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,i),this._needsUpdate=!0,s||this._focalOffset.copy(this._focalOffsetEnd);const n=!s||hi(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&hi(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&hi(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}setOrbitPoint(t,e,i){this._camera.updateMatrixWorld(),Ii.setFromMatrixColumn(this._camera.matrixWorldInverse,0),ki.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Di.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const s=Si.set(t,e,i),n=s.distanceTo(this._camera.position),r=s.sub(this._camera.position);Ii.multiplyScalar(r.x),ki.multiplyScalar(r.y),Di.multiplyScalar(r.z),Si.copy(Ii).add(ki).add(Di),Si.z=Si.z+n,this.dollyTo(n,!1),this.setFocalOffset(-Si.x,Si.y,-Si.z,!1),this.moveTo(t,e,i,!1)}setBoundary(t){if(!t)return this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),void(this._needsUpdate=!0);this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,i,s){null!==t?(this._viewport=this._viewport||new bi.Vector4,"number"==typeof t?this._viewport.set(t,e,i,s):this._viewport.copy(t)):this._viewport=null}getDistanceToFitBox(t,e,i,s=!1){if(gi(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const n=t/e,r=this._camera.getEffectiveFOV()*oi,o=this._camera.aspect;return.5*((s?n>o:n<o)?e:t/o)/Math.tan(.5*r)+.5*i}getDistanceToFitSphere(t){if(gi(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*oi,i=2*Math.atan(Math.tan(.5*e)*this._camera.aspect),s=1<this._camera.aspect?e:i;return t/Math.sin(.5*s)}getTarget(t,e=!0){return(t&&t.isVector3?t:new bi.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new bi.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new bi.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new bi.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%ni,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=ni),this._spherical.theta+=ni*Math.round((this._sphericalEnd.theta-this._spherical.theta)/ni)}stop(){this._focalOffset.copy(this._focalOffsetEnd),this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd),this._zoom=this._zoomEnd}reset(t=!1){if(!hi(this._camera.up.x,this._cameraUp0.x)||!hi(this._camera.up.y,this._cameraUp0.y)||!hi(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const t=this.getPosition(Si);this.updateCameraUp(),this.setPosition(t.x,t.y,t.z)}const e=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,t),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,t),this.zoomTo(this._zoom0,t)];return Promise.all(e)}saveState(){this._cameraUp0.copy(this._camera.up),this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,Ei),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=Si.subVectors(this._target,this._camera.position).normalize(),e=Ai.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const i=this.getPosition(Si);this.updateCameraUp(),this.setPosition(i.x,i.y,i.z)}update(t){const e=this._sphericalEnd.theta-this._spherical.theta,i=this._sphericalEnd.phi-this._spherical.phi,s=this._sphericalEnd.radius-this._spherical.radius,n=zi.subVectors(this._targetEnd,this._target),r=Mi.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(li(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=pi(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,e,1/0,t),this._needsUpdate=!0}if(li(i))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=pi(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,e,1/0,t),this._needsUpdate=!0}if(li(s))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const e=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=pi(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,e,this.maxSpeed,t),this._needsUpdate=!0}if(li(n.x)&&li(n.y)&&li(n.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const e=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;fi(this._target,this._targetEnd,this._targetVelocity,e,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(li(r.x)&&li(r.y)&&li(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const e=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;fi(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,e,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(li(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const e=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=pi(this._zoom,this._zoomEnd,this._zoomVelocity,e,1/0,t)}if(this.dollyToCursor)if(ii(this._camera)&&0!==this._changedDolly){const t=this._spherical.radius-this._lastDistance,e=this._camera,i=this._getCameraDirection(Pi),s=Si.copy(i).cross(e.up).normalize();0===s.lengthSq()&&(s.x=1);const n=Ai.crossVectors(s,i),r=this._sphericalEnd.radius*Math.tan(e.getEffectiveFOV()*oi*.5),o=(this._sphericalEnd.radius-t-this._sphericalEnd.radius)/this._sphericalEnd.radius,a=Oi.copy(this._targetEnd).add(s.multiplyScalar(this._dollyControlCoord.x*r*e.aspect)).add(n.multiplyScalar(this._dollyControlCoord.y*r)),l=Si.copy(this._targetEnd).lerp(a,o),h=this._lastDollyDirection===ti&&this._spherical.radius<=this.minDistance,c=this._lastDollyDirection===ei&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(h||c)){this._sphericalEnd.radius-=t,this._spherical.radius-=t;const e=Ai.copy(i).multiplyScalar(-t);l.add(e)}this._boundary.clampPoint(l,l);const d=Ai.subVectors(l,this._targetEnd);this._targetEnd.copy(l),this._target.add(d),this._changedDolly-=t,li(this._changedDolly)&&(this._changedDolly=0)}else if(si(this._camera)&&0!==this._changedZoom){const t=this._zoom-this._lastZoom,e=this._camera,i=Si.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(e.near+e.far)/(e.near-e.far)).unproject(e),s=Ai.set(0,0,-1).applyQuaternion(e.quaternion),n=Oi.copy(i).add(s.multiplyScalar(-i.dot(e.up))),r=-(this._zoom-t-this._zoom)/this._zoom,o=this._getCameraDirection(Pi),a=this._targetEnd.dot(o),l=Si.copy(this._targetEnd).lerp(n,r),h=l.dot(o),c=o.multiplyScalar(h-a);l.sub(c),this._boundary.clampPoint(l,l);const d=Ai.subVectors(l,this._targetEnd);this._targetEnd.copy(l),this._target.add(d),this._changedZoom-=t,li(this._changedZoom)&&(this._changedZoom=0)}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0),this._dragNeedsUpdate=!0;const a=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,a),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target);(!li(this._focalOffset.x)||!li(this._focalOffset.y)||!li(this._focalOffset.z))&&(Ii.setFromMatrixColumn(this._camera.matrix,0),ki.setFromMatrixColumn(this._camera.matrix,1),Di.setFromMatrixColumn(this._camera.matrix,2),Ii.multiplyScalar(this._focalOffset.x),ki.multiplyScalar(-this._focalOffset.y),Di.multiplyScalar(this._focalOffset.z),Si.copy(Ii).add(ki).add(Di),this._camera.position.add(Si),this._camera.updateMatrixWorld()),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),Si.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const l=this._needsUpdate;return l&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):l?(this.dispatchEvent({type:"update"}),li(e,this.restThreshold)&&li(i,this.restThreshold)&&li(s,this.restThreshold)&&li(n.x,this.restThreshold)&&li(n.y,this.restThreshold)&&li(n.z,this.restThreshold)&&li(r.x,this.restThreshold)&&li(r.y,this.restThreshold)&&li(r.z,this.restThreshold)&&li(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!l&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=l,this._needsUpdate=!1,l}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:di(this.maxDistance),minZoom:this.minZoom,maxZoom:di(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:di(this.maxPolarAngle),minAzimuthAngle:di(this.minAzimuthAngle),maxAzimuthAngle:di(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,target:this._targetEnd.toArray(),position:Si.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(t,e=!1){const i=JSON.parse(t);this.enabled=i.enabled,this.minDistance=i.minDistance,this.maxDistance=ui(i.maxDistance),this.minZoom=i.minZoom,this.maxZoom=ui(i.maxZoom),this.minPolarAngle=i.minPolarAngle,this.maxPolarAngle=ui(i.maxPolarAngle),this.minAzimuthAngle=ui(i.minAzimuthAngle),this.maxAzimuthAngle=ui(i.maxAzimuthAngle),this.smoothTime=i.smoothTime,this.draggingSmoothTime=i.draggingSmoothTime,this.dollySpeed=i.dollySpeed,this.truckSpeed=i.truckSpeed,this.dollyToCursor=i.dollyToCursor,this._target0.fromArray(i.target0),this._position0.fromArray(i.position0),this._zoom0=i.zoom0,this._focalOffset0.fromArray(i.focalOffset0),this.moveTo(i.target[0],i.target[1],i.target[2],e),Bi.setFromVector3(Si.fromArray(i.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(Bi.theta,Bi.phi,e),this.dollyTo(Bi.radius,e),this.zoomTo(i.zoom,e),this.setFocalOffset(i.focalOffset[0],i.focalOffset[1],i.focalOffset[2],e),this._needsUpdate=!0}connect(t){this._domElement?console.warn("camera-controls is already connected."):(t.setAttribute("data-camera-controls-version","2.10.1"),this._addAllEventListeners(t),this._getClientRect(this._elementRect))}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement.removeAttribute("data-camera-controls-version"),this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(t){return t.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(t){return this._getTargetDirection(t).negate()}_findPointerById(t){return this._activePointers.find(e=>e.pointerId===t)}_findPointerByMouseButton(t){return this._activePointers.find(e=>e.mouseButton===t)}_disposePointer(t){this._activePointers.splice(this._activePointers.indexOf(t),1)}_encloseToBoundary(t,e,i){const s=e.lengthSq();if(0===s)return t;const n=Ai.copy(e).add(t),r=this._boundary.clampPoint(n,Oi).sub(n),o=r.lengthSq();if(0===o)return t.add(e);if(o===s)return t;if(0===i)return t.add(e).add(r);{const s=1+i*o/e.dot(r);return t.add(Ai.copy(e).multiplyScalar(s)).add(r.multiplyScalar(1-i))}}_updateNearPlaneCorners(){if(ii(this._camera)){const t=this._camera,e=t.near,i=t.getEffectiveFOV()*oi,s=Math.tan(.5*i)*e,n=s*t.aspect;this._nearPlaneCorners[0].set(-n,-s,0),this._nearPlaneCorners[1].set(n,-s,0),this._nearPlaneCorners[2].set(n,s,0),this._nearPlaneCorners[3].set(-n,s,0)}else if(si(this._camera)){const t=this._camera,e=1/t.zoom,i=t.left*e,s=t.right*e,n=t.top*e,r=t.bottom*e;this._nearPlaneCorners[0].set(i,n,0),this._nearPlaneCorners[1].set(s,n,0),this._nearPlaneCorners[2].set(s,r,0),this._nearPlaneCorners[3].set(i,r,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1))return t;if(gi(this._camera,"_collisionTest"))return t;const e=this._getTargetDirection(Pi);ji.lookAt(xi,e,this._camera.up);for(let i=0;i<4;i++){const s=Ai.copy(this._nearPlaneCorners[i]);s.applyMatrix4(ji);const n=Oi.addVectors(this._target,s);Zi.set(n,e),Zi.far=this._spherical.radius+1;const r=Zi.intersectObjects(this.colliderMeshes);0!==r.length&&r[0].distance<t&&(t=r[0].distance)}return t}_getClientRect(t){if(!this._domElement)return;const e=this._domElement.getBoundingClientRect();return t.x=e.left,t.y=e.top,this._viewport?(t.x+=this._viewport.x,t.y+=e.height-this._viewport.w-this._viewport.y,t.width=this._viewport.z,t.height=this._viewport.w):(t.width=e.width,t.height=e.height),t}_createOnRestPromise(t){return t?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(t=>{const e=()=>{this.removeEventListener("rest",e),t()};this.addEventListener("rest",e)}))}_addAllEventListeners(t){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(t){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(t){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(t,e=new bi.Sphere){const i=e,s=i.center;Ui.makeEmpty(),t.traverseVisible(t=>{t.isMesh&&Ui.expandByObject(t)}),Ui.getCenter(s);let n=0;return t.traverseVisible(t=>{if(!t.isMesh)return;const e=t;if(!e.geometry)return;const i=e.geometry.clone();i.applyMatrix4(e.matrixWorld);const r=i.attributes.position;for(let t=0,e=r.count;t<e;t++)Si.fromBufferAttribute(r,t),n=Math.max(n,s.distanceToSquared(Si))}),i.radius=Math.sqrt(n),i}}class $i extends j{constructor(t){super(t),e(this,"onBeforeUpdate",new U),e(this,"onAfterUpdate",new U),e(this,"onAspectUpdated",new U),e(this,"onDisposed",new U),e(this,"three"),e(this,"_allControls",new Map),e(this,"updateAspect",()=>{var t;if(this.currentWorld&&this.currentWorld.renderer)if(this.three instanceof r.OrthographicCamera)this.onAspectUpdated.trigger();else if(null==(t=this.currentWorld.renderer)?void 0:t.isResizeable()){const t=this.currentWorld.renderer.getSize();this.three.aspect=t.width/t.height,this.three.updateProjectionMatrix(),this.onAspectUpdated.trigger()}}),this.three=this.setupCamera(),this.setupEvents(!0),this.worlds.onItemSet.add(({value:t})=>{const e=this.newCameraControls();this._allControls.set(t.uuid,e)}),this.worlds.onBeforeDelete.add(({value:t})=>{const e=this._allControls.get(t.uuid);e&&(e.dispose(),this._allControls.delete(t.uuid))})}get controls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");const t=this._allControls.get(this.currentWorld.uuid);if(!t)throw new Error("Controls not found!");return t}get enabled(){return null!==this.currentWorld&&this.controls.enabled}set enabled(t){null!==this.currentWorld&&(this.controls.enabled=t)}set currentWorld(t){if(super.currentWorld=t,!t)return;this.worlds.get(t.uuid)||this.worlds.set(t.uuid,t)}get currentWorld(){return this._currentWorld}dispose(){this.setupEvents(!1),this.onAspectUpdated.reset(),this.onBeforeUpdate.reset(),this.onAfterUpdate.reset(),this.three.removeFromParent(),this.onDisposed.trigger(),this.onDisposed.reset();for(const[t,e]of this._allControls)e.dispose();this.worlds.clear()}async fitToItems(t){const e=await this.getItemsBounding(t);await this.controls.fitToSphere(e,!0)}async setOrbitToItems(t){const e=await this.getItemsBounding(t);this.controls.setOrbitPoint(e.center.x,e.center.y,e.center.z)}update(t){this.enabled&&(this.onBeforeUpdate.trigger(this),this.controls.update(t),this.onAfterUpdate.trigger(this))}async getItemsBounding(t){const e=this.components.get(Ae),i=this.components.get(Me);i.list.clear();const s=new r.Sphere;if(t)await i.addFromModelIdMap(t);else for(const[,t]of e.list)i.list.add(t.box);return i.get().getBoundingSphere(s),i.list.clear(),s}setupCamera(){const t=window.innerWidth/window.innerHeight,e=new r.PerspectiveCamera(60,t,1,1e3);return e.position.set(50,50,50),e.lookAt(new r.Vector3(0,0,0)),e}newCameraControls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");if(!this.currentWorld.renderer)throw new Error("This camera needs a renderer to work!");Hi.install({THREE:$i.getSubsetOfThree()});const{domElement:t}=this.currentWorld.renderer.three,e=new Hi(this.three,t);return e.smoothTime=.2,e.dollyToCursor=!0,e.infinityDolly=!0,e.minDistance=6,e}setupEvents(t){t?window.addEventListener("resize",this.updateAspect):window.removeEventListener("resize",this.updateAspect)}static getSubsetOfThree(){return{MOUSE:r.MOUSE,Vector2:r.Vector2,Vector3:r.Vector3,Vector4:r.Vector4,Quaternion:r.Quaternion,Matrix4:r.Matrix4,Spherical:r.Spherical,Box3:r.Box3,Sphere:r.Sphere,Raycaster:r.Raycaster,MathUtils:r.MathUtils}}}const Wi=class t extends F{constructor(i){super(i),e(this,"onAfterUpdate",new U),e(this,"onBeforeUpdate",new U),e(this,"onDisposed",new U),e(this,"list",new we),e(this,"enabled",!0),i.add(t.uuid,this)}create(){const t=new Ze(this.components),e=t.uuid;if(this.list.has(e))throw new Error("There is already a world with this name!");return this.list.set(e,t),t}delete(t){if(!this.list.has(t.uuid))throw new Error("The provided world is not found in the list!");this.list.delete(t.uuid),t.dispose()}dispose(){this.enabled=!1;for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}update(t){if(this.enabled)for(const[e,i]of this.list)i.update(t)}};e(Wi,"uuid","fdb61dc4-2ec1-4966-b83d-54ea795fad4a");let Yi=Wi;class Xi extends xe{constructor(){super(...arguments),e(this,"_config",{visible:{value:!0,type:"Boolean"},color:{value:new r.Color,type:"Color"},primarySize:{type:"Number",interpolable:!0,value:1,min:0,max:1e3},secondarySize:{type:"Number",interpolable:!0,value:10,min:0,max:1e3},distance:{type:"Number",interpolable:!0,value:500,min:0,max:500}})}get visible(){return this._config.visible.value}set visible(t){this._config.visible.value=t,this._component.visible=t}get color(){return this._config.color.value}set color(t){this._config.color.value=t,this._component.material.uniforms.uColor.value=t,this._component.material.uniformsNeedUpdate=!0}get primarySize(){return this._config.primarySize.value}set primarySize(t){this._config.primarySize.value=t,this._component.material.uniforms.uSize1.value=t,this._component.material.uniformsNeedUpdate=!0}get secondarySize(){return this._config.secondarySize.value}set secondarySize(t){this._config.secondarySize.value=t,this._component.material.uniforms.uSize2.value=t,this._component.material.uniformsNeedUpdate=!0}get distance(){return this._config.distance.value}set distance(t){this._config.distance.value=t,this._component.material.uniforms.uDistance.value=t,this._component.material.uniformsNeedUpdate=!0}}class qi{constructor(t,i){e(this,"onDisposed",new U),e(this,"onSetup",new U),e(this,"isSetup",!1),e(this,"world"),e(this,"components"),e(this,"config"),e(this,"_defaultConfig",{visible:!0,color:new r.Color(12303291),primarySize:1,secondarySize:10,distance:500}),e(this,"three"),e(this,"_fade",3),e(this,"updateZoom",()=>{this.world.camera instanceof $i&&(this.material.uniforms.uZoom.value=this.world.camera.three.zoom)}),this.world=i;const{color:s,primarySize:n,secondarySize:o,distance:a}=this._defaultConfig;this.components=t,this.config=new Xi(this,this.components,"Grid");const l=new r.PlaneGeometry(2,2,1,1),h=new r.ShaderMaterial({side:r.DoubleSide,uniforms:{uSize1:{value:n},uSize2:{value:o},uColor:{value:s},uDistance:{value:a},uFade:{value:this._fade},uZoom:{value:1}},transparent:!0,vertexShader:"\n \n varying vec3 worldPosition;\n \n uniform float uDistance;\n \n void main() {\n \n vec3 pos = position.xzy * uDistance;\n pos.xz += cameraPosition.xz;\n \n worldPosition = pos;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);\n \n }\n ",fragmentShader:"\n \n varying vec3 worldPosition;\n \n uniform float uZoom;\n uniform float uFade;\n uniform float uSize1;\n uniform float uSize2;\n uniform vec3 uColor;\n uniform float uDistance;\n \n \n \n float getGrid(float size) {\n \n vec2 r = worldPosition.xz / size;\n \n \n vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n float line = min(grid.x, grid.y);\n \n \n return 1.0 - min(line, 1.0);\n }\n \n void main() {\n \n \n float d = 1.0 - min(distance(cameraPosition.xz, worldPosition.xz) / uDistance, 1.0);\n \n float g1 = getGrid(uSize1);\n float g2 = getGrid(uSize2);\n \n // Ortho camera fades the grid away when zooming out\n float minZoom = step(0.2, uZoom);\n float zoomFactor = pow(min(uZoom, 1.), 2.) * minZoom;\n \n gl_FragColor = vec4(uColor.rgb, mix(g2, g1, g1) * pow(d, uFade));\n gl_FragColor.a = mix(0.5 * gl_FragColor.a, gl_FragColor.a, g2) * zoomFactor;\n \n if ( gl_FragColor.a <= 0.0 ) discard;\n \n \n }\n \n ",extensions:{derivatives:!0}});this.three=new r.Mesh(l,h),this.three.frustumCulled=!1,i.scene.three.add(this.three),this.setupEvents(!0)}get visible(){return this.three.visible}set visible(t){if(this.three.visible=t,t){this.world.scene.three.add(this.three)}else this.three.removeFromParent()}get material(){return this.three.material}get fade(){return 3===this._fade}set fade(t){this._fade=t?3:0,this.material.uniforms.uFade.value=this._fade}setup(t){const e={...this._defaultConfig,...t};this.config.visible=!0,this.config.color=e.color,this.config.primarySize=e.primarySize,this.config.secondarySize=e.secondarySize,this.config.distance=e.distance,this.isSetup=!0,this.onSetup.trigger()}dispose(){this.setupEvents(!1);this.components.get(Te).list.delete(this.config.uuid);this.components.get($).destroy(this.three),this.onDisposed.trigger(),this.onDisposed.reset(),this.world=null,this.components=null}setupEvents(t){if(this.world.isDisposing)return;if(!(this.world.camera instanceof $i))return;const e=this.world.camera.controls;t?e.addEventListener("update",this.updateZoom):e.removeEventListener("update",this.updateZoom)}}const Gi=class t extends F{constructor(i){super(i),e(this,"list",new Map),e(this,"onDisposed",new U),e(this,"enabled",!0),i.add(t.uuid,this)}create(t){if(this.list.has(t.uuid))throw new Error("This world already has a grid!");const e=new qi(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}};e(Gi,"uuid","d1e814d5-b81c-4452-87a2-f039375e0489");let Qi=Gi;const Ki=1.25,Ji=65535,ts=Math.pow(2,-24),es=Symbol("SKIP_GENERATION");function is(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}function ss(t,e){if(!t.index){const i=t.attributes.position.count,s=function(t,e=ArrayBuffer){return t>65535?new Uint32Array(new e(4*t)):new Uint16Array(new e(2*t))}(i,e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);t.setIndex(new o(s,1));for(let t=0;t<i;t++)s[t]=t}}function ns(t){const e=is(t),i=t.drawRange,s=i.start/3,n=(i.start+i.count)/3,r=Math.max(0,s),o=Math.min(e,n)-r;return[{offset:Math.floor(r),count:Math.floor(o)}]}function rs(t){if(!t.groups||!t.groups.length)return ns(t);const e=[],i=new Set,s=t.drawRange,n=s.start/3,r=(s.start+s.count)/3;for(const e of t.groups){const t=e.start/3,s=(e.start+e.count)/3;i.add(Math.max(n,t)),i.add(Math.min(r,s))}const o=Array.from(i.values()).sort((t,e)=>t-e);for(let t=0;t<o.length-1;t++){const i=o[t],s=o[t+1];e.push({offset:Math.floor(i),count:Math.floor(s-i)})}return e}function os(t,e,i){return i.min.x=e[t],i.min.y=e[t+1],i.min.z=e[t+2],i.max.x=e[t+3],i.max.y=e[t+4],i.max.z=e[t+5],i}function as(t){let e=-1,i=-1/0;for(let s=0;s<3;s++){const n=t[s+3]-t[s];n>i&&(i=n,e=s)}return e}function ls(t,e){e.set(t)}function hs(t,e,i){let s,n;for(let r=0;r<3;r++){const o=r+3;s=t[r],n=e[r],i[r]=s<n?s:n,s=t[o],n=e[o],i[o]=s>n?s:n}}function cs(t,e,i){for(let s=0;s<3;s++){const n=e[t+2*s],r=e[t+2*s+1],o=n-r,a=n+r;o<i[s]&&(i[s]=o),a>i[s+3]&&(i[s+3]=a)}}function ds(t){const e=t[3]-t[0],i=t[4]-t[1],s=t[5]-t[2];return 2*(e*i+i*s+s*e)}function us(t,e,i,s,n=null){let r=1/0,o=1/0,a=1/0,l=-1/0,h=-1/0,c=-1/0,d=1/0,u=1/0,p=1/0,f=-1/0,m=-1/0,g=-1/0;const _=null!==n;for(let s=6*e,n=6*(e+i);s<n;s+=6){const e=t[s+0],i=t[s+1],n=e-i,y=e+i;n<r&&(r=n),y>l&&(l=y),_&&e<d&&(d=e),_&&e>f&&(f=e);const w=t[s+2],v=t[s+3],b=w-v,x=w+v;b<o&&(o=b),x>h&&(h=x),_&&w<u&&(u=w),_&&w>m&&(m=w);const E=t[s+4],T=t[s+5],C=E-T,S=E+T;C<a&&(a=C),S>c&&(c=S),_&&E<p&&(p=E),_&&E>g&&(g=E)}s[0]=r,s[1]=o,s[2]=a,s[3]=l,s[4]=h,s[5]=c,_&&(n[0]=d,n[1]=u,n[2]=p,n[3]=f,n[4]=m,n[5]=g)}const ps=32,fs=(t,e)=>t.candidate-e.candidate,ms=new Array(ps).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),gs=new Float32Array(6);class _s{constructor(){}}function ys(t,e,i,s,n,r){let o=s,a=s+n-1;const l=r.pos,h=2*r.axis;for(;;){for(;o<=a&&i[6*o+h]<l;)o++;for(;o<=a&&i[6*a+h]>=l;)a--;if(!(o<a))return o;for(let t=0;t<3;t++){let i=e[3*o+t];e[3*o+t]=e[3*a+t],e[3*a+t]=i}for(let t=0;t<6;t++){let e=i[6*o+t];i[6*o+t]=i[6*a+t],i[6*a+t]=e}o++,a--}}function ws(t,e,i,s,n,r){let o=s,a=s+n-1;const l=r.pos,h=2*r.axis;for(;;){for(;o<=a&&i[6*o+h]<l;)o++;for(;o<=a&&i[6*a+h]>=l;)a--;if(!(o<a))return o;{let e=t[o];t[o]=t[a],t[a]=e;for(let t=0;t<6;t++){let e=i[6*o+t];i[6*o+t]=i[6*a+t],i[6*a+t]=e}o++,a--}}}function vs(t,e){const i=t.geometry,s=i.index?i.index.array:null,n=e.maxDepth,r=e.verbose,o=e.maxLeafTris,a=e.strategy,l=e.onProgress,h=is(i),c=t._indirectBuffer;let d=!1;const u=new Float32Array(6),p=new Float32Array(6),f=function(t,e){var i;(i=e)[0]=i[1]=i[2]=1/0,i[3]=i[4]=i[5]=-1/0;const s=t.attributes.position,n=t.index?t.index.array:null,r=is(t),o=new Float32Array(6*r),a=s.normalized,l=s.array,h=s.offset||0;let c=3;s.isInterleavedBufferAttribute&&(c=s.data.stride);const d=["getX","getY","getZ"];for(let t=0;t<r;t++){const i=3*t,r=6*t;let u=i+0,p=i+1,f=i+2;n&&(u=n[u],p=n[p],f=n[f]),a||(u=u*c+h,p=p*c+h,f=f*c+h);for(let t=0;t<3;t++){let i,n,h;a?(i=s[d[t]](u),n=s[d[t]](p),h=s[d[t]](f)):(i=l[u+t],n=l[p+t],h=l[f+t]);let c=i;n<c&&(c=n),h<c&&(c=h);let m=i;n>m&&(m=n),h>m&&(m=h);const g=(m-c)/2,_=2*t;o[r+_+0]=c+g,o[r+_+1]=g+(Math.abs(c)+g)*ts,c<e[t]&&(e[t]=c),m>e[t+3]&&(e[t+3]=m)}}return o}(i,u),m=e.indirect?ws:ys,g=[],_=e.indirect?ns(i):rs(i);if(1===_.length){const t=_[0],e=new _s;e.boundingData=u,function(t,e,i,s){let n=1/0,r=1/0,o=1/0,a=-1/0,l=-1/0,h=-1/0;for(let s=6*e,c=6*(e+i);s<c;s+=6){const e=t[s+0];e<n&&(n=e),e>a&&(a=e);const i=t[s+2];i<r&&(r=i),i>l&&(l=i);const c=t[s+4];c<o&&(o=c),c>h&&(h=c)}s[0]=n,s[1]=r,s[2]=o,s[3]=a,s[4]=l,s[5]=h}(f,t.offset,t.count,p),w(e,t.offset,t.count,p),g.push(e)}else for(let t of _){const e=new _s;e.boundingData=new Float32Array(6),us(f,t.offset,t.count,e.boundingData,p),w(e,t.offset,t.count,p),g.push(e)}return g;function y(t){l&&l(t/h)}function w(t,e,l,h=null,u=0){if(!d&&u>=n&&(d=!0,r&&(console.warn(`MeshBVH: Max depth of ${n} reached when generating BVH. Consider increasing maxDepth.`),console.warn(i))),l<=o||u>=n)return y(e+l),t.offset=e,t.count=l,t;const g=function(t,e,i,s,n,r){let o=-1,a=0;if(0===r)o=as(e),-1!==o&&(a=(e[o]+e[o+3])/2);else if(1===r)o=as(t),-1!==o&&(a=function(t,e,i,s){let n=0;for(let r=e,o=e+i;r<o;r++)n+=t[6*r+2*s];return n/i}(i,s,n,o));else if(2===r){const r=ds(t);let l=Ki*n;const h=6*s,c=6*(s+n);for(let t=0;t<3;t++){const s=e[t],d=(e[t+3]-s)/ps;if(n<8){const e=[...ms];e.length=n;let s=0;for(let n=h;n<c;n+=6,s++){const r=e[s];r.candidate=i[n+2*t],r.count=0;const{bounds:o,leftCacheBounds:a,rightCacheBounds:l}=r;for(let t=0;t<3;t++)l[t]=1/0,l[t+3]=-1/0,a[t]=1/0,a[t+3]=-1/0,o[t]=1/0,o[t+3]=-1/0;cs(n,i,o)}e.sort(fs);let d=n;for(let t=0;t<d;t++){const i=e[t];for(;t+1<d&&e[t+1].candidate===i.candidate;)e.splice(t+1,1),d--}for(let s=h;s<c;s+=6){const n=i[s+2*t];for(let t=0;t<d;t++){const r=e[t];n>=r.candidate?cs(s,i,r.rightCacheBounds):(cs(s,i,r.leftCacheBounds),r.count++)}}for(let i=0;i<d;i++){const s=e[i],h=s.count,c=n-s.count,d=s.leftCacheBounds,u=s.rightCacheBounds;let p=0;0!==h&&(p=ds(d)/r);let f=0;0!==c&&(f=ds(u)/r);const m=1+Ki*(p*h+f*c);m<l&&(o=t,l=m,a=s.candidate)}}else{for(let t=0;t<ps;t++){const e=ms[t];e.count=0,e.candidate=s+d+t*d;const i=e.bounds;for(let t=0;t<3;t++)i[t]=1/0,i[t+3]=-1/0}for(let e=h;e<c;e+=6){let n=~~((i[e+2*t]-s)/d);n>=ps&&(n=31);const r=ms[n];r.count++,cs(e,i,r.bounds)}const e=ms[31];ls(e.bounds,e.rightCacheBounds);for(let t=30;t>=0;t--){const e=ms[t],i=ms[t+1];hs(e.bounds,i.rightCacheBounds,e.rightCacheBounds)}let u=0;for(let e=0;e<31;e++){const i=ms[e],s=i.count,h=i.bounds,c=ms[e+1].rightCacheBounds;0!==s&&(0===u?ls(h,gs):hs(h,gs,gs)),u+=s;let d=0,p=0;0!==u&&(d=ds(gs)/r);const f=n-u;0!==f&&(p=ds(c)/r);const m=1+Ki*(d*u+p*f);m<l&&(o=t,l=m,a=i.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${r} used.`);return{axis:o,pos:a}}(t.boundingData,h,f,e,l,a);if(-1===g.axis)return y(e+l),t.offset=e,t.count=l,t;const _=m(c,s,f,e,l,g);if(_===e||_===e+l)y(e+l),t.offset=e,t.count=l;else{t.splitAxis=g.axis;const i=new _s,s=e,n=_-e;t.left=i,i.boundingData=new Float32Array(6),us(f,s,n,i.boundingData,p),w(i,s,n,p,u+1);const r=new _s,o=_,a=l-n;t.right=r,r.boundingData=new Float32Array(6),us(f,o,a,r.boundingData,p),w(r,o,a,p,u+1)}return t}}function bs(t,e){const i=t.geometry;e.indirect&&(t._indirectBuffer=function(t,e){const i=(t.index?t.index.count:t.attributes.position.count)/3,s=i>65536,n=s?4:2,r=e?new SharedArrayBuffer(i*n):new ArrayBuffer(i*n),o=s?new Uint32Array(r):new Uint16Array(r);for(let t=0,e=o.length;t<e;t++)o[t]=t;return o}(i,e.useSharedArrayBuffer),function(t){if(0===t.groups.length)return!1;const e=is(t),i=rs(t).sort((t,e)=>t.offset-e.offset),s=i[i.length-1];s.count=Math.min(e-s.offset,s.count);let n=0;return i.forEach(({count:t})=>n+=t),e!==n}(i)&&!e.verbose&&console.warn('MeshBVH: Provided geometry contains groups that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),t._indirectBuffer||ss(i,e);const s=vs(t,e);let n,r,o;const a=[],l=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;for(let t=0;t<s.length;t++){const e=s[t];const i=new l(32*h(e));n=new Float32Array(i),r=new Uint32Array(i),o=new Uint16Array(i),c(0,e),a.push(i)}return void(t._roots=a);function h(t){return t.count?1:1+h(t.left)+h(t.right)}function c(t,e){const i=t/4,s=t/2,a=!!e.count,l=e.boundingData;for(let t=0;t<6;t++)n[i+t]=l[t];if(a){const n=e.offset,a=e.count;return r[i+6]=n,o[s+14]=a,o[s+15]=Ji,t+32}{const s=e.left,n=e.right,o=e.splitAxis;let a;if(a=c(t+32,s),a/4>Math.pow(2,32))throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return r[i+6]=a/4,a=c(a,n),r[i+7]=o,a}}}class xs{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const r=t[n][e];i=r<i?r:i,s=r>s?r:s}this.min=i,this.max=s}setFromPoints(t,e){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const r=e[n],o=t.dot(r);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(t){return this.min>t.max||t.min>this.max}}xs.prototype.setFromBox=function(){const t=new a;return function(e,i){const s=i.min,n=i.max;let r=1/0,o=-1/0;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let l=0;l<=1;l++){t.x=s.x*i+n.x*(1-i),t.y=s.y*a+n.y*(1-a),t.z=s.z*l+n.z*(1-l);const h=e.dot(t);r=Math.min(h,r),o=Math.max(h,o)}this.min=r,this.max=o}}();const Es=function(){const t=new a,e=new a,i=new a;return function(s,n,r){const o=s.start,a=t,l=n.start,h=e;i.subVectors(o,l),t.subVectors(s.end,s.start),e.subVectors(n.end,n.start);const c=i.dot(h),d=h.dot(a),u=h.dot(h),p=i.dot(a),f=a.dot(a)*u-d*d;let m,g;m=0!==f?(c*d-p*u)/f:0,g=(c+m*d)/u,r.x=m,r.y=g}}(),Ts=function(){const t=new c,e=new a,i=new a;return function(s,n,r,o){Es(s,n,t);let a=t.x,l=t.y;if(a>=0&&a<=1&&l>=0&&l<=1)return s.at(a,r),void n.at(l,o);if(a>=0&&a<=1)return l<0?n.at(0,o):n.at(1,o),void s.closestPointToPoint(o,!0,r);if(l>=0&&l<=1)return a<0?s.at(0,r):s.at(1,r),void n.closestPointToPoint(r,!0,o);{let t,h;t=a<0?s.start:s.end,h=l<0?n.start:n.end;const c=e,d=i;return s.closestPointToPoint(h,!0,e),n.closestPointToPoint(t,!0,i),c.distanceToSquared(h)<=d.distanceToSquared(t)?(r.copy(c),void o.copy(h)):(r.copy(t),void o.copy(d))}}}(),Cs=function(){const t=new a,e=new a,i=new l,s=new h;return function(n,r){const{radius:o,center:a}=n,{a:l,b:h,c:c}=r;s.start=l,s.end=h;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;s.start=l,s.end=c;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;s.start=h,s.end=c;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;const d=r.getPlane(i);if(Math.abs(d.distanceToPoint(a))<=o){const t=d.projectPoint(a,e);if(r.containsPoint(t))return!0}return!1}}();function Ss(t){return Math.abs(t)<1e-15}class As extends d{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new a),this.satBounds=new Array(4).fill().map(()=>new xs),this.points=[this.a,this.b,this.c],this.sphere=new u,this.plane=new l,this.needsUpdate=!0}intersectsSphere(t){return Cs(t,this)}update(){const t=this.a,e=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,o=n[0],a=r[0];this.getNormal(o),a.setFromPoints(o,s);const l=n[1],h=r[1];l.subVectors(t,e),h.setFromPoints(l,s);const c=n[2],d=r[2];c.subVectors(e,i),d.setFromPoints(c,s);const u=n[3],p=r[3];u.subVectors(i,t),p.setFromPoints(u,s),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}As.prototype.closestPointToSegment=function(){const t=new a,e=new a,i=new h;return function(s,n=null,r=null){const{start:o,end:a}=s,l=this.points;let h,c=1/0;for(let o=0;o<3;o++){const a=(o+1)%3;i.start.copy(l[o]),i.end.copy(l[a]),Ts(i,s,t,e),h=t.distanceToSquared(e),h<c&&(c=h,n&&n.copy(t),r&&r.copy(e))}return this.closestPointToPoint(o,t),h=o.distanceToSquared(t),h<c&&(c=h,n&&n.copy(t),r&&r.copy(o)),this.closestPointToPoint(a,t),h=a.distanceToSquared(t),h<c&&(c=h,n&&n.copy(t),r&&r.copy(a)),Math.sqrt(c)}}(),As.prototype.intersectsTriangle=function(){const t=new As,e=new Array(3),i=new Array(3),s=new xs,n=new xs,r=new a,o=new a,l=new a,c=new a,d=new a,u=new h,p=new h,f=new h,m=new a;function g(t,e,i){const s=t.points;let n=0,r=-1;for(let t=0;t<3;t++){const{start:a,end:l}=u;a.copy(s[t]),l.copy(s[(t+1)%3]),u.delta(o);const h=Ss(e.distanceToPoint(a));if(Ss(e.normal.dot(o))&&h){i.copy(u),n=2;break}const c=e.intersectLine(u,m);if(!c&&h&&m.copy(a),(c||h)&&!Ss(m.distanceTo(l))){if(n<=1){(1===n?i.start:i.end).copy(m),h&&(r=n)}else if(n>=2){(1===r?i.start:i.end).copy(m),n=2;break}if(n++,2===n&&-1===r)break}}return n}return function(o,a=null,h=!1){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(t.copy(o),t.update(),o=t);const u=this.plane,m=o.plane;if(Math.abs(u.normal.dot(m.normal))>1-1e-10){const t=this.satBounds,l=this.satAxes;i[0]=o.a,i[1]=o.b,i[2]=o.c;for(let e=0;e<4;e++){const n=t[e],r=l[e];if(s.setFromPoints(r,i),n.isSeparated(s))return!1}const c=o.satBounds,d=o.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let t=0;t<4;t++){const i=c[t],n=d[t];if(s.setFromPoints(n,e),i.isSeparated(s))return!1}for(let t=0;t<4;t++){const o=l[t];for(let t=0;t<4;t++){const a=d[t];if(r.crossVectors(o,a),s.setFromPoints(r,e),n.setFromPoints(r,i),s.isSeparated(n))return!1}}return a&&(h||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),a.start.set(0,0,0),a.end.set(0,0,0)),!0}{const t=g(this,m,p);if(1===t&&o.containsPoint(p.end))return a&&(a.start.copy(p.end),a.end.copy(p.end)),!0;if(2!==t)return!1;const e=g(o,u,f);if(1===e&&this.containsPoint(f.end))return a&&(a.start.copy(f.end),a.end.copy(f.end)),!0;if(2!==e)return!1;if(p.delta(l),f.delta(c),l.dot(c)<0){let t=f.start;f.start=f.end,f.end=t}const i=p.start.dot(l),s=p.end.dot(l),n=f.start.dot(l),r=f.end.dot(l);return(i===r||n===s||s<n!==i<r)&&(a&&(d.subVectors(p.start,f.start),d.dot(l)>0?a.start.copy(p.start):a.start.copy(f.start),d.subVectors(p.end,f.end),d.dot(l)<0?a.end.copy(p.end):a.end.copy(f.end)),!0)}}}(),As.prototype.distanceToPoint=function(){const t=new a;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),As.prototype.distanceToTriangle=function(){const t=new a,e=new a,i=["a","b","c"],s=new h,n=new h;return function(r,o=null,a=null){const l=o||a?s:null;if(this.intersectsTriangle(r,l))return(o||a)&&(o&&l.getCenter(o),a&&l.getCenter(a)),0;let h=1/0;for(let e=0;e<3;e++){let s;const n=i[e],l=r[n];this.closestPointToPoint(l,t),s=l.distanceToSquared(t),s<h&&(h=s,o&&o.copy(t),a&&a.copy(l));const c=this[n];r.closestPointToPoint(c,t),s=c.distanceToSquared(t),s<h&&(h=s,o&&o.copy(c),a&&a.copy(t))}for(let l=0;l<3;l++){const c=i[l],d=i[(l+1)%3];s.set(this[c],this[d]);for(let l=0;l<3;l++){const c=i[l],d=i[(l+1)%3];n.set(r[c],r[d]),Ts(s,n,t,e);const u=t.distanceToSquared(e);u<h&&(h=u,o&&o.copy(t),a&&a.copy(e))}}return Math.sqrt(h)}}();class Os{constructor(t,e,i){this.isOrientedBox=!0,this.min=new a,this.max=new a,this.matrix=new p,this.invMatrix=new p,this.points=new Array(8).fill().map(()=>new a),this.satAxes=new Array(3).fill().map(()=>new a),this.satBounds=new Array(3).fill().map(()=>new xs),this.alignedSatBounds=new Array(3).fill().map(()=>new xs),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Os.prototype.update=function(){return function(){const t=this.matrix,e=this.min,i=this.max,s=this.points;for(let n=0;n<=1;n++)for(let r=0;r<=1;r++)for(let o=0;o<=1;o++){const a=s[1*n|2*r|4*o];a.x=n?i.x:e.x,a.y=r?i.y:e.y,a.z=o?i.z:e.z,a.applyMatrix4(t)}const n=this.satBounds,r=this.satAxes,o=s[0];for(let t=0;t<3;t++){const e=r[t],i=n[t],a=s[1<<t];e.subVectors(o,a),i.setFromPoints(e,s)}const a=this.alignedSatBounds;a[0].setFromPointsField(s,"x"),a[1].setFromPointsField(s,"y"),a[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),Os.prototype.intersectsBox=function(){const t=new xs;return function(e){this.needsUpdate&&this.update();const i=e.min,s=e.max,n=this.satBounds,r=this.satAxes,o=this.alignedSatBounds;if(t.min=i.x,t.max=s.x,o[0].isSeparated(t))return!1;if(t.min=i.y,t.max=s.y,o[1].isSeparated(t))return!1;if(t.min=i.z,t.max=s.z,o[2].isSeparated(t))return!1;for(let i=0;i<3;i++){const s=r[i],o=n[i];if(t.setFromBox(s,e),o.isSeparated(t))return!1}return!0}}(),Os.prototype.intersectsTriangle=function(){const t=new As,e=new Array(3),i=new xs,s=new xs,n=new a;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(t.copy(r),t.update(),r=t);const o=this.satBounds,a=this.satAxes;e[0]=r.a,e[1]=r.b,e[2]=r.c;for(let t=0;t<3;t++){const s=o[t],n=a[t];if(i.setFromPoints(n,e),s.isSeparated(i))return!1}const l=r.satBounds,h=r.satAxes,c=this.points;for(let t=0;t<3;t++){const e=l[t],s=h[t];if(i.setFromPoints(s,c),e.isSeparated(i))return!1}for(let t=0;t<3;t++){const r=a[t];for(let t=0;t<4;t++){const o=h[t];if(n.crossVectors(r,o),i.setFromPoints(n,e),s.setFromPoints(n,c),i.isSeparated(s))return!1}}return!0}}(),Os.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),Os.prototype.distanceToPoint=function(){const t=new a;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),Os.prototype.distanceToBox=function(){const t=["x","y","z"],e=new Array(12).fill().map(()=>new h),i=new Array(12).fill().map(()=>new h),s=new a,n=new a;return function(r,o=0,a=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(a||l)&&(r.getCenter(n),this.closestPointToPoint(n,s),r.closestPointToPoint(s,n),a&&a.copy(s),l&&l.copy(n)),0;const h=o*o,c=r.min,d=r.max,u=this.points;let p=1/0;for(let t=0;t<8;t++){const e=u[t];n.copy(e).clamp(c,d);const i=e.distanceToSquared(n);if(i<p&&(p=i,a&&a.copy(e),l&&l.copy(n),i<h))return Math.sqrt(i)}let f=0;for(let s=0;s<3;s++)for(let n=0;n<=1;n++)for(let r=0;r<=1;r++){const o=(s+1)%3,a=(s+2)%3,l=1<<s|n<<o|r<<a,h=u[n<<o|r<<a],p=u[l];e[f].set(h,p);const m=t[s],g=t[o],_=t[a],y=i[f],w=y.start,v=y.end;w[m]=c[m],w[g]=n?c[g]:d[g],w[_]=r?c[_]:d[g],v[m]=d[m],v[g]=n?c[g]:d[g],v[_]=r?c[_]:d[g],f++}for(let t=0;t<=1;t++)for(let e=0;e<=1;e++)for(let i=0;i<=1;i++){n.x=t?d.x:c.x,n.y=e?d.y:c.y,n.z=i?d.z:c.z,this.closestPointToPoint(n,s);const r=n.distanceToSquared(s);if(r<p&&(p=r,a&&a.copy(s),l&&l.copy(n),r<h))return Math.sqrt(r)}for(let t=0;t<12;t++){const r=e[t];for(let t=0;t<12;t++){const e=i[t];Ts(r,e,s,n);const o=s.distanceToSquared(n);if(o<p&&(p=o,a&&a.copy(s),l&&l.copy(n),o<h))return Math.sqrt(o)}}return Math.sqrt(p)}}();class Ps{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return 0===t.length?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Is extends Ps{constructor(){super(()=>new As)}}const ks=new Is;function Ds(t,e){return 65535===e[t+15]}function zs(t,e){return e[t+6]}function Ms(t,e){return e[t+14]}function Bs(t){return t+8}function Ns(t,e){return e[t+6]}function Us(t,e){return e[t+7]}function Ls(t){return t}const Rs=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==t.length&&this.setBuffer(t.pop())}}};let Fs,Vs;const js=[],Zs=new Ps(()=>new f);function Hs(t,e,i,s,n,r){Fs=Zs.getPrimitive(),Vs=Zs.getPrimitive(),js.push(Fs,Vs),Rs.setBuffer(t._roots[e]);const o=$s(0,t.geometry,i,s,n,r);Rs.clearBuffer(),Zs.releasePrimitive(Fs),Zs.releasePrimitive(Vs),js.pop(),js.pop();const a=js.length;return a>0&&(Vs=js[a-1],Fs=js[a-2]),o}function $s(t,e,i,s,n=null,r=0,o=0){const{float32Array:a,uint16Array:l,uint32Array:h}=Rs;let c=2*t;if(Ds(c,l)){const e=zs(t,h),i=Ms(c,l);return os(t,a,Fs),s(e,i,!1,o,r+t,Fs)}{let c=function(t){const{uint16Array:e,uint32Array:i}=Rs;let s=2*t;for(;!Ds(s,e);)s=2*(t=Bs(t));return zs(t,i)},d=function(t){const{uint16Array:e,uint32Array:i}=Rs;let s=2*t;for(;!Ds(s,e);)s=2*(t=Ns(t,i));return zs(t,i)+Ms(s,e)};const u=Bs(t),p=Ns(t,h);let f,m,g,_,y=u,w=p;if(n&&(g=Fs,_=Vs,os(y,a,g),os(w,a,_),f=n(g),m=n(_),m<f)){y=p,w=u;const t=f;f=m,m=t,g=_}g||(g=Fs,os(y,a,g));const v=i(g,Ds(2*y,l),f,o+1,r+y);let b;if(2===v){const t=c(y);b=s(t,d(y)-t,!0,o+1,r+y,g)}else b=v&&$s(y,e,i,s,n,r,o+1);if(b)return!0;_=Vs,os(w,a,_);const x=i(_,Ds(2*w,l),m,o+1,r+w);let E;if(2===x){const t=c(w);E=s(t,d(w)-t,!0,o+1,r+w,_)}else E=x&&$s(w,e,i,s,n,r,o+1);return!!E}}const Ws=new a,Ys=new a;const Xs=new a,qs=new a,Gs=new a,Qs=new c,Ks=new c,Js=new c,tn=new a,en=new a,sn=new a,nn=new a;function rn(t,e,i,s,n,r,o,l,h){Xs.fromBufferAttribute(e,r),qs.fromBufferAttribute(e,o),Gs.fromBufferAttribute(e,l);const u=function(t,e,i,s,n,r){let o;return o=r===m?t.intersectTriangle(s,i,e,!0,n):t.intersectTriangle(e,i,s,r!==g,n),null===o?null:{distance:t.origin.distanceTo(n),point:n.clone()}}(t,Xs,qs,Gs,nn,h);if(u){s&&(Qs.fromBufferAttribute(s,r),Ks.fromBufferAttribute(s,o),Js.fromBufferAttribute(s,l),u.uv=d.getInterpolation(nn,Xs,qs,Gs,Qs,Ks,Js,new c)),n&&(Qs.fromBufferAttribute(n,r),Ks.fromBufferAttribute(n,o),Js.fromBufferAttribute(n,l),u.uv1=d.getInterpolation(nn,Xs,qs,Gs,Qs,Ks,Js,new c)),i&&(tn.fromBufferAttribute(i,r),en.fromBufferAttribute(i,o),sn.fromBufferAttribute(i,l),u.normal=d.getInterpolation(nn,Xs,qs,Gs,tn,en,sn,new a),u.normal.dot(t.direction)>0&&u.normal.multiplyScalar(-1));const e={a:r,b:o,c:l,normal:new a,materialIndex:0};d.getNormal(Xs,qs,Gs,e.normal),u.face=e,u.faceIndex=r}return u}function on(t,e,i,s,n){const r=3*s;let o=r+0,a=r+1,l=r+2;const h=t.index;t.index&&(o=h.getX(o),a=h.getX(a),l=h.getX(l));const{position:c,normal:d,uv:u,uv1:p}=t.attributes,f=rn(i,c,d,u,p,o,a,l,e);return f?(f.faceIndex=s,n&&n.push(f),f):null}function an(t,e,i,s){const n=t.a,r=t.b,o=t.c;let a=e,l=e+1,h=e+2;i&&(a=i.getX(a),l=i.getX(l),h=i.getX(h)),n.x=s.getX(a),n.y=s.getY(a),n.z=s.getZ(a),r.x=s.getX(l),r.y=s.getY(l),r.z=s.getZ(l),o.x=s.getX(h),o.y=s.getY(h),o.z=s.getZ(h)}function ln(t,e,i,s,n,r,o){const{geometry:a}=i,{index:l}=a,h=a.attributes.position;for(let i=t,a=e+t;i<a;i++){let t;if(t=i,an(o,3*t,l,h),o.needsUpdate=!0,s(o,t,n,r))return!0}return!1}function hn(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const i=t.geometry,s=i.index?i.index.array:null,n=i.attributes.position;let r,o,a,l,h=0;const c=t._roots;for(let t=0,e=c.length;t<e;t++)r=c[t],o=new Uint32Array(r),a=new Uint16Array(r),l=new Float32Array(r),d(0,h),h+=r.byteLength;function d(t,i,r=!1){const h=2*t;if(a[h+15]===Ji){const e=o[t+6];let i=1/0,r=1/0,c=1/0,d=-1/0,u=-1/0,p=-1/0;for(let t=3*e,o=3*(e+a[h+14]);t<o;t++){let e=s[t];const o=n.getX(e),a=n.getY(e),l=n.getZ(e);o<i&&(i=o),o>d&&(d=o),a<r&&(r=a),a>u&&(u=a),l<c&&(c=l),l>p&&(p=l)}return(l[t+0]!==i||l[t+1]!==r||l[t+2]!==c||l[t+3]!==d||l[t+4]!==u||l[t+5]!==p)&&(l[t+0]=i,l[t+1]=r,l[t+2]=c,l[t+3]=d,l[t+4]=u,l[t+5]=p,!0)}{const s=t+8,n=o[t+6],a=s+i,h=n+i;let c=r,u=!1,p=!1;e?c||(u=e.has(a),p=e.has(h),c=!u&&!p):(u=!0,p=!0);const f=c||p;let m=!1;(c||u)&&(m=d(s,i,c));let g=!1;f&&(g=d(n,i,c));const _=m||g;if(_)for(let e=0;e<3;e++){const i=s+e,r=n+e,o=l[i],a=l[i+3],h=l[r],c=l[r+3];l[t+e]=o<h?o:h,l[t+e+3]=a>c?a:c}return _}}}const cn=new f;function dn(t,e,i,s){return os(t,e,cn),i.intersectBox(cn,s)}function un(t,e,i,s,n,r,o){const{geometry:a}=i,{index:l}=a,h=a.attributes.position;for(let a=t,c=e+t;a<c;a++){let t;if(t=i.resolveTriangleIndex(a),an(o,3*t,l,h),o.needsUpdate=!0,s(o,t,n,r))return!0}return!1}const pn=new a;function fn(t,e,i,s,n){Rs.setBuffer(t._roots[e]),mn(0,t,i,s,n),Rs.clearBuffer()}function mn(t,e,i,s,n){const{float32Array:r,uint16Array:o,uint32Array:a}=Rs,l=2*t;if(Ds(l,o)){!function(t,e,i,s,n,r){const{geometry:o,_indirectBuffer:a}=t;for(let t=s,a=s+n;t<a;t++)on(o,e,i,t,r)}(e,i,s,zs(t,a),Ms(l,o),n)}else{const o=Bs(t);dn(o,r,s,pn)&&mn(o,e,i,s,n);const l=Ns(t,a);dn(l,r,s,pn)&&mn(l,e,i,s,n)}}const gn=new a,_n=["x","y","z"];function yn(t,e,i,s){Rs.setBuffer(t._roots[e]);const n=wn(0,t,i,s);return Rs.clearBuffer(),n}function wn(t,e,i,s){const{float32Array:n,uint16Array:r,uint32Array:o}=Rs;let a=2*t;if(Ds(a,r)){return function(t,e,i,s,n){const{geometry:r,_indirectBuffer:o}=t;let a=1/0,l=null;for(let t=s,o=s+n;t<o;t++){let s;s=on(r,e,i,t),s&&s.distance<a&&(l=s,a=s.distance)}return l}(e,i,s,zs(t,o),Ms(a,r))}{const r=Us(t,o),a=_n[r],l=s.direction[a]>=0;let h,c;l?(h=Bs(t),c=Ns(t,o)):(h=Ns(t,o),c=Bs(t));const d=dn(h,n,s,gn)?wn(h,e,i,s):null;if(d){const t=d.point[a];if(l?t<=n[c+r]:t>=n[c+r+3])return d}const u=dn(c,n,s,gn)?wn(c,e,i,s):null;return d&&u?d.distance<=u.distance?d:u:d||u||null}}const vn=new f,bn=new As,xn=new As,En=new p,Tn=new Os,Cn=new Os;function Sn(t,e,i,s){Rs.setBuffer(t._roots[e]);const n=An(0,t,i,s);return Rs.clearBuffer(),n}function An(t,e,i,s,n=null){const{float32Array:r,uint16Array:o,uint32Array:a}=Rs;let l=2*t;null===n&&(i.boundingBox||i.computeBoundingBox(),Tn.set(i.boundingBox.min,i.boundingBox.max,s),n=Tn);if(!Ds(l,o)){const o=t+8,l=a[t+6];os(o,r,vn);if(n.intersectsBox(vn)&&An(o,e,i,s,n))return!0;os(l,r,vn);return!!(n.intersectsBox(vn)&&An(l,e,i,s,n))}{const n=e.geometry,h=n.index,c=n.attributes.position,d=i.index,u=i.attributes.position,p=zs(t,a),f=Ms(l,o);if(En.copy(s).invert(),i.boundsTree){os(t,r,Cn),Cn.matrix.copy(En),Cn.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:t=>Cn.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(s),t.b.applyMatrix4(s),t.c.applyMatrix4(s),t.needsUpdate=!0;for(let e=3*p,i=3*(f+p);e<i;e+=3)if(an(xn,e,h,c),xn.needsUpdate=!0,t.intersectsTriangle(xn))return!0;return!1}})}for(let t=3*p,e=3*(f+p);t<e;t+=3){an(bn,t,h,c),bn.a.applyMatrix4(En),bn.b.applyMatrix4(En),bn.c.applyMatrix4(En),bn.needsUpdate=!0;for(let t=0,e=d.count;t<e;t+=3)if(an(xn,t,d,u),xn.needsUpdate=!0,bn.intersectsTriangle(xn))return!0}}}const On=new p,Pn=new Os,In=new Os,kn=new a,Dn=new a,zn=new a,Mn=new a;function Bn(t,e,i,s={},n={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Pn.set(e.boundingBox.min,e.boundingBox.max,i),Pn.needsUpdate=!0;const a=t.geometry,l=a.attributes.position,h=a.index,c=e.attributes.position,d=e.index,u=ks.getPrimitive(),p=ks.getPrimitive();let f=kn,m=Dn,g=null,_=null;n&&(g=zn,_=Mn);let y=1/0,w=null,v=null;return On.copy(i).invert(),In.matrix.copy(On),t.shapecast({boundsTraverseOrder:t=>Pn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o&&(e&&(In.min.copy(t.min),In.max.copy(t.max),In.needsUpdate=!0),!0),intersectsRange:(t,s)=>{if(e.boundsTree){return e.boundsTree.shapecast({boundsTraverseOrder:t=>In.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o,intersectsRange:(e,n)=>{for(let o=e,a=e+n;o<a;o++){an(p,3*o,d,c),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=t,i=t+s;e<i;e++){an(u,3*e,h,l),u.needsUpdate=!0;const t=u.distanceToTriangle(p,f,g);if(t<y&&(m.copy(f),_&&_.copy(g),y=t,w=e,v=o),t<r)return!0}}}})}for(let n=0,o=is(e);n<o;n++){an(p,3*n,d,c),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=t,i=t+s;e<i;e++){an(u,3*e,h,l),u.needsUpdate=!0;const t=u.distanceToTriangle(p,f,g);if(t<y&&(m.copy(f),_&&_.copy(g),y=t,w=e,v=n),t<r)return!0}}}}),ks.releasePrimitive(u),ks.releasePrimitive(p),y===1/0?null:(s.point?s.point.copy(m):s.point=m.clone(),s.distance=y,s.faceIndex=w,n&&(n.point?n.point.copy(_):n.point=_.clone(),n.point.applyMatrix4(On),m.applyMatrix4(On),n.distance=m.sub(n.point).length(),n.faceIndex=v),s)}function Nn(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const i=t.geometry,s=i.index?i.index.array:null,n=i.attributes.position;let r,o,a,l,h=0;const c=t._roots;for(let t=0,e=c.length;t<e;t++)r=c[t],o=new Uint32Array(r),a=new Uint16Array(r),l=new Float32Array(r),d(0,h),h+=r.byteLength;function d(i,r,h=!1){const c=2*i;if(a[c+15]===Ji){const e=o[i+6];let r=1/0,h=1/0,d=1/0,u=-1/0,p=-1/0,f=-1/0;for(let i=e,o=e+a[c+14];i<o;i++){const e=3*t.resolveTriangleIndex(i);for(let t=0;t<3;t++){let i=e+t;i=s?s[i]:i;const o=n.getX(i),a=n.getY(i),l=n.getZ(i);o<r&&(r=o),o>u&&(u=o),a<h&&(h=a),a>p&&(p=a),l<d&&(d=l),l>f&&(f=l)}}return(l[i+0]!==r||l[i+1]!==h||l[i+2]!==d||l[i+3]!==u||l[i+4]!==p||l[i+5]!==f)&&(l[i+0]=r,l[i+1]=h,l[i+2]=d,l[i+3]=u,l[i+4]=p,l[i+5]=f,!0)}{const t=i+8,s=o[i+6],n=t+r,a=s+r;let c=h,u=!1,p=!1;e?c||(u=e.has(n),p=e.has(a),c=!u&&!p):(u=!0,p=!0);const f=c||p;let m=!1;(c||u)&&(m=d(t,r,c));let g=!1;f&&(g=d(s,r,c));const _=m||g;if(_)for(let e=0;e<3;e++){const n=t+e,r=s+e,o=l[n],a=l[n+3],h=l[r],c=l[r+3];l[i+e]=o<h?o:h,l[i+e+3]=a>c?a:c}return _}}}const Un=new a;function Ln(t,e,i,s,n){Rs.setBuffer(t._roots[e]),Rn(0,t,i,s,n),Rs.clearBuffer()}function Rn(t,e,i,s,n){const{float32Array:r,uint16Array:o,uint32Array:a}=Rs,l=2*t;if(Ds(l,o)){!function(t,e,i,s,n,r){const{geometry:o,_indirectBuffer:a}=t;for(let t=s,l=s+n;t<l;t++)on(o,e,i,a?a[t]:t,r)}(e,i,s,zs(t,a),Ms(l,o),n)}else{const o=Bs(t);dn(o,r,s,Un)&&Rn(o,e,i,s,n);const l=Ns(t,a);dn(l,r,s,Un)&&Rn(l,e,i,s,n)}}const Fn=new a,Vn=["x","y","z"];function jn(t,e,i,s){Rs.setBuffer(t._roots[e]);const n=Zn(0,t,i,s);return Rs.clearBuffer(),n}function Zn(t,e,i,s){const{float32Array:n,uint16Array:r,uint32Array:o}=Rs;let a=2*t;if(Ds(a,r)){return function(t,e,i,s,n){const{geometry:r,_indirectBuffer:o}=t;let a=1/0,l=null;for(let t=s,h=s+n;t<h;t++){let s;s=on(r,e,i,o?o[t]:t),s&&s.distance<a&&(l=s,a=s.distance)}return l}(e,i,s,zs(t,o),Ms(a,r))}{const r=Us(t,o),a=Vn[r],l=s.direction[a]>=0;let h,c;l?(h=Bs(t),c=Ns(t,o)):(h=Ns(t,o),c=Bs(t));const d=dn(h,n,s,Fn)?Zn(h,e,i,s):null;if(d){const t=d.point[a];if(l?t<=n[c+r]:t>=n[c+r+3])return d}const u=dn(c,n,s,Fn)?Zn(c,e,i,s):null;return d&&u?d.distance<=u.distance?d:u:d||u||null}}const Hn=new f,$n=new As,Wn=new As,Yn=new p,Xn=new Os,qn=new Os;function Gn(t,e,i,s){Rs.setBuffer(t._roots[e]);const n=Qn(0,t,i,s);return Rs.clearBuffer(),n}function Qn(t,e,i,s,n=null){const{float32Array:r,uint16Array:o,uint32Array:a}=Rs;let l=2*t;null===n&&(i.boundingBox||i.computeBoundingBox(),Xn.set(i.boundingBox.min,i.boundingBox.max,s),n=Xn);if(!Ds(l,o)){const o=t+8,l=a[t+6];os(o,r,Hn);if(n.intersectsBox(Hn)&&Qn(o,e,i,s,n))return!0;os(l,r,Hn);return!!(n.intersectsBox(Hn)&&Qn(l,e,i,s,n))}{const n=e.geometry,h=n.index,c=n.attributes.position,d=i.index,u=i.attributes.position,p=zs(t,a),f=Ms(l,o);if(Yn.copy(s).invert(),i.boundsTree){os(t,r,qn),qn.matrix.copy(Yn),qn.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:t=>qn.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(s),t.b.applyMatrix4(s),t.c.applyMatrix4(s),t.needsUpdate=!0;for(let i=p,s=f+p;i<s;i++)if(an(Wn,3*e.resolveTriangleIndex(i),h,c),Wn.needsUpdate=!0,t.intersectsTriangle(Wn))return!0;return!1}})}for(let t=p,i=f+p;t<i;t++){const i=e.resolveTriangleIndex(t);an($n,3*i,h,c),$n.a.applyMatrix4(Yn),$n.b.applyMatrix4(Yn),$n.c.applyMatrix4(Yn),$n.needsUpdate=!0;for(let t=0,e=d.count;t<e;t+=3)if(an(Wn,t,d,u),Wn.needsUpdate=!0,$n.intersectsTriangle(Wn))return!0}}}const Kn=new p,Jn=new Os,tr=new Os,er=new a,ir=new a,sr=new a,nr=new a;function rr(t,e,i,s={},n={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Jn.set(e.boundingBox.min,e.boundingBox.max,i),Jn.needsUpdate=!0;const a=t.geometry,l=a.attributes.position,h=a.index,c=e.attributes.position,d=e.index,u=ks.getPrimitive(),p=ks.getPrimitive();let f=er,m=ir,g=null,_=null;n&&(g=sr,_=nr);let y=1/0,w=null,v=null;return Kn.copy(i).invert(),tr.matrix.copy(Kn),t.shapecast({boundsTraverseOrder:t=>Jn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o&&(e&&(tr.min.copy(t.min),tr.max.copy(t.max),tr.needsUpdate=!0),!0),intersectsRange:(s,n)=>{if(e.boundsTree){const a=e.boundsTree;return a.shapecast({boundsTraverseOrder:t=>tr.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o,intersectsRange:(e,o)=>{for(let b=e,x=e+o;b<x;b++){const e=a.resolveTriangleIndex(b);an(p,3*e,d,c),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=s,i=s+n;e<i;e++){const i=t.resolveTriangleIndex(e);an(u,3*i,h,l),u.needsUpdate=!0;const s=u.distanceToTriangle(p,f,g);if(s<y&&(m.copy(f),_&&_.copy(g),y=s,w=e,v=b),s<r)return!0}}}})}for(let o=0,a=is(e);o<a;o++){an(p,3*o,d,c),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=s,i=s+n;e<i;e++){const i=t.resolveTriangleIndex(e);an(u,3*i,h,l),u.needsUpdate=!0;const s=u.distanceToTriangle(p,f,g);if(s<y&&(m.copy(f),_&&_.copy(g),y=s,w=e,v=o),s<r)return!0}}}}),ks.releasePrimitive(u),ks.releasePrimitive(p),y===1/0?null:(s.point?s.point.copy(m):s.point=m.clone(),s.distance=y,s.faceIndex=w,n&&(n.point?n.point.copy(_):n.point=_.clone(),n.point.applyMatrix4(Kn),m.applyMatrix4(Kn),n.distance=m.sub(n.point).length(),n.faceIndex=v),s)}const or=new Rs.constructor,ar=new Rs.constructor,lr=new Ps(()=>new f),hr=new f,cr=new f,dr=new f,ur=new f;let pr=!1;function fr(t,e,i,s,n,r=0,o=0,a=0,l=0,h=null,c=!1){let d,u;c?(d=ar,u=or):(d=or,u=ar);const p=d.float32Array,f=d.uint32Array,m=d.uint16Array,g=u.float32Array,_=u.uint32Array,y=u.uint16Array,w=2*e,v=Ds(2*t,m),b=Ds(w,y);let x=!1;if(b&&v)x=c?n(zs(e,_),Ms(2*e,y),zs(t,f),Ms(2*t,m),l,o+e,a,r+t):n(zs(t,f),Ms(2*t,m),zs(e,_),Ms(2*e,y),a,r+t,l,o+e);else if(b){const h=lr.getPrimitive();os(e,g,h),h.applyMatrix4(i);const d=Bs(t),u=Ns(t,f);os(d,p,hr),os(u,p,cr);const m=h.intersectsBox(hr),_=h.intersectsBox(cr);x=m&&fr(e,d,s,i,n,o,r,l,a+1,h,!c)||_&&fr(e,u,s,i,n,o,r,l,a+1,h,!c),lr.releasePrimitive(h)}else{const d=Bs(e),u=Ns(e,_);os(d,g,dr),os(u,g,ur);const m=h.intersectsBox(dr),y=h.intersectsBox(ur);if(m&&y)x=fr(t,d,i,s,n,r,o,a,l+1,h,c)||fr(t,u,i,s,n,r,o,a,l+1,h,c);else if(m)if(v)x=fr(t,d,i,s,n,r,o,a,l+1,h,c);else{const e=lr.getPrimitive();e.copy(dr).applyMatrix4(i);const h=Bs(t),u=Ns(t,f);os(h,p,hr),os(u,p,cr);const m=e.intersectsBox(hr),g=e.intersectsBox(cr);x=m&&fr(d,h,s,i,n,o,r,l,a+1,e,!c)||g&&fr(d,u,s,i,n,o,r,l,a+1,e,!c),lr.releasePrimitive(e)}else if(y)if(v)x=fr(t,u,i,s,n,r,o,a,l+1,h,c);else{const e=lr.getPrimitive();e.copy(ur).applyMatrix4(i);const h=Bs(t),d=Ns(t,f);os(h,p,hr),os(d,p,cr);const m=e.intersectsBox(hr),g=e.intersectsBox(cr);x=m&&fr(u,h,s,i,n,o,r,l,a+1,e,!c)||g&&fr(u,d,s,i,n,o,r,l,a+1,e,!c),lr.releasePrimitive(e)}}return x}const mr=new Os,gr=new f;class _r{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,s=t._roots,n=t._indirectBuffer,r=i.getIndex();let o;return o=e.cloneBuffers?{roots:s.map(t=>t.slice()),index:r.array.slice(),indirectBuffer:n?n.slice():null}:{roots:s,index:r.array,indirectBuffer:n},o}static deserialize(t,e,i={}){i={setIndex:!0,indirect:Boolean(t.indirectBuffer),...i};const{index:s,roots:n,indirectBuffer:r}=t,a=new _r(e,{...i,[es]:!0});if(a._roots=n,a._indirectBuffer=r||null,i.setIndex){const i=e.getIndex();if(null===i){const i=new o(t.index,1,!1);e.setIndex(i)}else i.array!==s&&(i.array.set(s),i.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(!t.isBufferGeometry)throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.");if((e=Object.assign({strategy:0,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[es]:!1},e)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[es]||(bs(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new f)));const{_indirectBuffer:i}=this;this.resolveTriangleIndex=e.indirect?t=>i[t]:t=>t}refit(t=null){return(this.indirect?Nn:hn)(this,t)}traverse(t,e=0){const i=this._roots[e],s=new Uint32Array(i),n=new Uint16Array(i);!function e(r,o=0){const a=2*r,l=n[a+15]===Ji;if(l){const e=s[r+6],h=n[a+14];t(o,l,new Float32Array(i,4*r,6),e,h)}else{const n=r+8,a=s[r+6],h=s[r+7];t(o,l,new Float32Array(i,4*r,6),h)||(e(n,o+1),e(a,o+1))}}(0)}raycast(t,e=_){const i=this._roots,s=this.geometry,n=[],r=e.isMaterial,o=Array.isArray(e),a=s.groups,l=r?e.side:e,h=this.indirect?Ln:fn;for(let s=0,r=i.length;s<r;s++){const i=o?e[a[s].materialIndex].side:l,r=n.length;if(h(this,s,i,t,n),o){const t=a[s].materialIndex;for(let e=r,i=n.length;e<i;e++)n[e].face.materialIndex=t}}return n}raycastFirst(t,e=_){const i=this._roots,s=this.geometry,n=e.isMaterial,r=Array.isArray(e);let o=null;const a=s.groups,l=n?e.side:e,h=this.indirect?jn:yn;for(let s=0,n=i.length;s<n;s++){const i=h(this,s,r?e[a[s].materialIndex].side:l,t);null!=i&&(null==o||i.distance<o.distance)&&(o=i,r&&(i.face.materialIndex=a[s].materialIndex))}return o}intersectsGeometry(t,e){let i=!1;const s=this._roots,n=this.indirect?Gn:Sn;for(let r=0,o=s.length;r<o&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=ks.getPrimitive(),i=this.indirect?un:ln;let{boundsTraverseOrder:s,intersectsBounds:n,intersectsRange:r,intersectsTriangle:o}=t;if(r&&o){const t=r;r=(s,n,r,a,l)=>!!t(s,n,r,a,l)||i(s,n,this,o,r,a,e)}else r||(r=o?(t,s,n,r)=>i(t,s,this,o,n,r,e):(t,e,i)=>i);let a=!1,l=0;const h=this._roots;for(let t=0,e=h.length;t<e;t++){const e=h[t];if(a=Hs(this,t,n,r,s,l),a)break;l+=e.byteLength}return ks.releasePrimitive(e),a}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=ks.getPrimitive(),o=this.geometry.index,a=this.geometry.attributes.position,l=this.indirect?t=>{const e=this.resolveTriangleIndex(t);an(r,3*e,o,a)}:t=>{an(r,3*t,o,a)},h=ks.getPrimitive(),c=t.geometry.index,d=t.geometry.attributes.position,u=t.indirect?e=>{const i=t.resolveTriangleIndex(e);an(h,3*i,c,d)}:t=>{an(h,3*t,c,d)};if(n){const t=(t,i,s,o,a,c,d,p)=>{for(let f=s,m=s+o;f<m;f++){u(f),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let e=t,s=t+i;e<s;e++)if(l(e),r.needsUpdate=!0,n(r,h,e,f,a,c,d,p))return!0}return!1};if(s){const e=s;s=function(i,s,n,r,o,a,l,h){return!!e(i,s,n,r,o,a,l,h)||t(i,s,n,r,o,a,l,h)}}else s=t}return function(t,e,i,s){if(pr)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");pr=!0;const n=t._roots,r=e._roots;let o,a=0,l=0;const h=(new p).copy(i).invert();for(let t=0,e=n.length;t<e;t++){or.setBuffer(n[t]),l=0;const e=lr.getPrimitive();os(Ls(0),or.float32Array,e),e.applyMatrix4(h);for(let n=0,c=r.length;n<c&&(ar.setBuffer(r[t]),o=fr(0,0,i,h,s,a,l,0,0,e),ar.clearBuffer(),l+=r[n].length,!o);n++);if(lr.releasePrimitive(e),or.clearBuffer(),a+=n[t].length,o)break}return pr=!1,o}(this,t,e,s)}intersectsBox(t,e){return mr.set(t.min,t.max,e),mr.needsUpdate=!0,this.shapecast({intersectsBounds:t=>mr.intersectsBox(t),intersectsTriangle:t=>mr.intersectsTriangle(t)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},s={},n=0,r=1/0){return(this.indirect?rr:Bn)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return function(t,e,i={},s=0,n=1/0){const r=s*s,o=n*n;let a=1/0,l=null;if(t.shapecast({boundsTraverseOrder:t=>(Ws.copy(e).clamp(t.min,t.max),Ws.distanceToSquared(e)),intersectsBounds:(t,e,i)=>i<a&&i<o,intersectsTriangle:(t,i)=>{t.closestPointToPoint(e,Ws);const s=e.distanceToSquared(Ws);return s<a&&(Ys.copy(Ws),a=s,l=i),s<r}}),a===1/0)return null;const h=Math.sqrt(a);return i.point?i.point.copy(Ys):i.point=Ys.clone(),i.distance=h,i.faceIndex=l,i}(this,t,e,i,s)}getBoundingBox(t){t.makeEmpty();return this._roots.forEach(e=>{os(0,new Float32Array(e),gr),t.union(gr)}),t}}function yr(t,e,i){return null===t?null:(t.point.applyMatrix4(e.matrixWorld),t.distance=t.point.distanceTo(i.ray.origin),t.object=e,t.distance<i.near||t.distance>i.far?null:t)}const wr=new y,vr=new p,br=w.prototype.raycast;function xr(t,e){if(this.geometry.boundsTree){if(void 0===this.material)return;vr.copy(this.matrixWorld).invert(),wr.copy(t.ray).applyMatrix4(vr);const i=this.geometry.boundsTree;if(!0===t.firstHitOnly){const s=yr(i.raycastFirst(wr,this.material),this,t);s&&e.push(s)}else{const s=i.raycast(wr,this.material);for(let i=0,n=s.length;i<n;i++){const n=yr(s[i],this,t);n&&e.push(n)}}}else br.call(this,t,e)}function Er(t){return this.boundsTree=new _r(this,t),this.boundsTree}function Tr(){this.boundsTree=null}const Cr=class t{constructor(){e(this,"onDisposed",new U),e(this,"list",new Map),e(this,"enabled",!1),e(this,"_clock"),e(this,"onInit",new U),e(this,"update",()=>{if(!this.enabled)return;const t=this._clock.getDelta();for(const[e,i]of this.list)i.enabled&&i.isUpdateable()&&i.update(t);requestAnimationFrame(this.update)}),this._clock=new r.Clock,t.setupBVH()}add(t,e){if(this.list.has(t))throw new Error("You're trying to add a component that already exists in the components instance. Use Components.get() instead.");q.validate(t),this.list.set(t,e)}get(t){const e=t.uuid;if(!this.list.has(e)){const i=new t(this);return i.isDisposeable()&&i.onDisposed.add(()=>this.list.delete(e)),this.list.has(e)||this.add(e,i),i}return this.list.get(e)}init(){this.enabled=!0;for(const[t,e]of this.list.entries())e.enabled=!0;this._clock.start(),this.update(),this.onInit.trigger()}dispose(){let t;this.enabled=!1;for(const[e,i]of this.list)i.enabled=!1,e!==Ae.uuid?i.isDisposeable()&&i.dispose():t=i;null==t||t.dispose(),this._clock.stop(),this.onDisposed.trigger()}static setupBVH(){r.BufferGeometry.prototype.computeBoundsTree=Er,r.BufferGeometry.prototype.disposeBoundsTree=Tr,r.Mesh.prototype.raycast=xr}};e(Cr,"release","2.4.3");let Sr=Cr;class Ar{constructor(t){e(this,"enabled",!1),e(this,"id","FirstPerson"),this.camera=t}set(t){if(this.enabled=t,t){if("Perspective"!==this.camera.projection.current)return void this.camera.set("Orbit");this.setupFirstPersonCamera()}}setupFirstPersonCamera(){const t=this.camera.controls,e=new r.Vector3;t.distance--,t.getPosition(e),t.minDistance=1,t.maxDistance=1,t.distance=1,t.moveTo(e.x,e.y,e.z),t.truckSpeed=50,t.mouseButtons.wheel=Hi.ACTION.DOLLY,t.touches.two=Hi.ACTION.TOUCH_ZOOM_TRUCK}}class Or{constructor(t){e(this,"enabled",!0),e(this,"id","Orbit"),this.camera=t,this.activateOrbitControls()}set(t){this.enabled=t,t&&this.activateOrbitControls()}activateOrbitControls(){const t=this.camera.controls;t.minDistance=1,t.maxDistance=300;const e=new r.Vector3;t.getPosition(e);const i=e.length();t.distance=i,t.truckSpeed=2;const{rotation:s}=this.camera.three,n=new r.Vector3(0,0,-1).applyEuler(s),o=e.addScaledVector(n,i);t.moveTo(o.x,o.y,o.z)}}class Pr{constructor(t){e(this,"enabled",!1),e(this,"id","Plan"),e(this,"mouseAction1"),e(this,"mouseAction2"),e(this,"mouseInitialized",!1),e(this,"defaultAzimuthSpeed"),e(this,"defaultPolarSpeed"),this.camera=t,this.defaultAzimuthSpeed=t.controls.azimuthRotateSpeed,this.defaultPolarSpeed=t.controls.polarRotateSpeed}set(t){this.enabled=t;const e=this.camera.controls;e.azimuthRotateSpeed=t?0:this.defaultAzimuthSpeed,e.polarRotateSpeed=t?0:this.defaultPolarSpeed,this.mouseInitialized||(this.mouseAction1=e.touches.one,this.mouseAction2=e.touches.two,this.mouseInitialized=!0),t?(e.mouseButtons.left=Hi.ACTION.TRUCK,e.touches.one=Hi.ACTION.TOUCH_TRUCK,e.touches.two=Hi.ACTION.TOUCH_ZOOM):(e.mouseButtons.left=Hi.ACTION.ROTATE,e.touches.one=this.mouseAction1,e.touches.two=this.mouseAction2)}}class Ir{constructor(t){e(this,"onChanged",new U),e(this,"current","Perspective"),e(this,"camera"),e(this,"matchOrthoDistanceEnabled",!1),e(this,"_component"),e(this,"_previousDistance",-1),this._component=t,this.camera=t.three}async set(t){this.current!==t&&("Orthographic"===t?this.setOrthoCamera():await this.setPerspectiveCamera(),this.onChanged.trigger(this.camera))}async toggle(){const t="Perspective"===this.current?"Orthographic":"Perspective";await this.set(t)}setOrthoCamera(){if(null===this._component.mode)return;if("FirstPerson"===this._component.mode.id)return;this._previousDistance=this._component.controls.distance,this._component.controls.distance=200;const t=this.getPerspectiveDims();if(!t)return;const{width:e,height:i}=t;this.setupOrthoCamera(i,e),this.camera=this._component.threeOrtho,this.current="Orthographic"}getPerspectiveDims(){const t=this._component.currentWorld;if(!t||!t.renderer)return null;const e=new r.Vector3;this._component.threePersp.getWorldDirection(e);const i=new r.Vector3;this._component.controls.getTarget(i);const s=i.clone().sub(this._component.threePersp.position).dot(e),n=t.renderer.getSize(),o=n.x/n.y,a=this._component.threePersp,l=2*s*Math.atan(a.fov*(Math.PI/180)/2);return{width:l*o,height:l}}setupOrthoCamera(t,e){this._component.controls.mouseButtons.wheel=Hi.ACTION.ZOOM,this._component.controls.mouseButtons.middle=Hi.ACTION.ZOOM;const i=this._component.threePersp,s=this._component.threeOrtho;s.zoom=1,s.left=e/-2,s.right=e/2,s.top=t/2,s.bottom=t/-2,s.updateProjectionMatrix(),s.position.copy(i.position),s.quaternion.copy(i.quaternion),this._component.controls.camera=s}getDistance(){const t=this._component.threePersp,e=this._component.threeOrtho;return(e.top-e.bottom)/e.zoom/(2*Math.atan(t.fov*(Math.PI/180)/2))}async setPerspectiveCamera(){this._component.controls.mouseButtons.wheel=Hi.ACTION.DOLLY,this._component.controls.mouseButtons.middle=Hi.ACTION.DOLLY;const t=this._component.threePersp,e=this._component.threeOrtho;t.position.copy(e.position),t.quaternion.copy(e.quaternion),this._component.controls.mouseButtons.wheel=Hi.ACTION.DOLLY,this.matchOrthoDistanceEnabled?this._component.controls.distance=this.getDistance():this._component.controls.distance=this._previousDistance,await this._component.controls.zoomTo(1),t.updateProjectionMatrix(),this._component.controls.camera=t,this.camera=t,this.current="Perspective"}}class kr extends $i{constructor(t){super(t),e(this,"projection"),e(this,"threeOrtho"),e(this,"threePersp"),e(this,"_userInputButtons",{}),e(this,"_frustumSize",50),e(this,"_navigationModes",new Map),e(this,"_mode",null),e(this,"previousSize",null),this.threePersp=this.three,this.threeOrtho=this.newOrthoCamera(),this.projection=new Ir(this),this.onAspectUpdated.add(()=>{this.setOrthoPerspCameraAspect()}),this.projection.onChanged.add(t=>{this.three=t,this.updateAspect()}),this.worlds.onItemSet.add(()=>{this._navigationModes.clear(),this._navigationModes.set("Orbit",new Or(this)),this._navigationModes.set("FirstPerson",new Ar(this)),this._navigationModes.set("Plan",new Pr(this)),this._mode=this._navigationModes.get("Orbit"),this.mode.set(!0,{preventTargetAdjustment:!0}),this.currentWorld&&this.currentWorld.renderer&&(this.previousSize=this.currentWorld.renderer.getSize().clone())}),this.worlds.onItemDeleted.add(()=>{this._navigationModes.clear()})}get mode(){if(!this._mode)throw new Error("Mode not found, camera not initialized");return this._mode}dispose(){super.dispose(),this.threeOrtho.removeFromParent()}set(t){if(null!==this.mode&&this.mode.id!==t){if(this.mode.set(!1),!this._navigationModes.has(t))throw new Error("The specified mode does not exist!");this._mode=this._navigationModes.get(t),this.mode.set(!0)}}async fit(t,e=1.5){if(!this.enabled)return;const i=Number.MAX_VALUE,s=Number.MIN_VALUE,n=new r.Vector3(i,i,i),o=new r.Vector3(s,s,s);for(const e of t){const t=(new r.Box3).setFromObject(e);t.min.x<n.x&&(n.x=t.min.x),t.min.y<n.y&&(n.y=t.min.y),t.min.z<n.z&&(n.z=t.min.z),t.max.x>o.x&&(o.x=t.max.x),t.max.y>o.y&&(o.y=t.max.y),t.max.z>o.z&&(o.z=t.max.z)}const a=new r.Box3(n,o),l=this.components.get(Ae);if(l.initialized)for(const[,t]of l.list){const e=t.box;e.min.x<n.x&&(n.x=e.min.x),e.min.y<n.y&&(n.y=e.min.y),e.min.z<n.z&&(n.z=e.min.z),e.max.x>o.x&&(o.x=e.max.x),e.max.y>o.y&&(o.y=e.max.y),e.max.z>o.z&&(o.z=e.max.z)}const h=new r.Vector3;a.getSize(h);const c=new r.Vector3;a.getCenter(c);const d=Math.max(h.x,h.y,h.z)*e,u=new r.Sphere(c,d);await this.controls.fitToSphere(u,!0)}setUserInput(t){t?this.enableUserInput():this.disableUserInput()}disableUserInput(){this._userInputButtons.left=this.controls.mouseButtons.left,this._userInputButtons.right=this.controls.mouseButtons.right,this._userInputButtons.middle=this.controls.mouseButtons.middle,this._userInputButtons.wheel=this.controls.mouseButtons.wheel,this.controls.mouseButtons.left=0,this.controls.mouseButtons.right=0,this.controls.mouseButtons.middle=0,this.controls.mouseButtons.wheel=0}enableUserInput(){0!==Object.keys(this._userInputButtons).length&&(this.controls.mouseButtons.left=this._userInputButtons.left,this.controls.mouseButtons.right=this._userInputButtons.right,this.controls.mouseButtons.middle=this._userInputButtons.middle,this.controls.mouseButtons.wheel=this._userInputButtons.wheel)}newOrthoCamera(){const t=window.innerWidth/window.innerHeight;return new r.OrthographicCamera(this._frustumSize*t/-2,this._frustumSize*t/2,this._frustumSize/2,this._frustumSize/-2,.1,1e3)}setOrthoPerspCameraAspect(){if(!this.currentWorld||!this.currentWorld.renderer)return;if(!this.previousSize)return;const t=this.currentWorld.renderer.getSize(),e=this.threeOrtho.top,i=this.threeOrtho.right,s=e*(t.y/this.previousSize.y),n=i*(t.x/this.previousSize.x);this.threeOrtho.left=-n,this.threeOrtho.right=n,this.threeOrtho.top=s,this.threeOrtho.bottom=-s,this.threeOrtho.updateProjectionMatrix(),this.previousSize.copy(t)}}function Dr(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var zr={exports:{}};
|
|
7
|
+
*/const qe=1,Ge=2,Qe=4,Ke=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,SCREEN_PAN:4,OFFSET:8,DOLLY:16,ZOOM:32,TOUCH_ROTATE:64,TOUCH_TRUCK:128,TOUCH_SCREEN_PAN:256,TOUCH_OFFSET:512,TOUCH_DOLLY:1024,TOUCH_ZOOM:2048,TOUCH_DOLLY_TRUCK:4096,TOUCH_DOLLY_SCREEN_PAN:8192,TOUCH_DOLLY_OFFSET:16384,TOUCH_DOLLY_ROTATE:32768,TOUCH_ZOOM_TRUCK:65536,TOUCH_ZOOM_OFFSET:131072,TOUCH_ZOOM_SCREEN_PAN:262144,TOUCH_ZOOM_ROTATE:524288}),Je=0,ti=1,ei=-1;function ii(t){return t.isPerspectiveCamera}function si(t){return t.isOrthographicCamera}const ni=2*Math.PI,ri=Math.PI/2,oi=Math.PI/180;function ai(t,e,i){return Math.max(e,Math.min(i,t))}function li(t,e=1e-5){return Math.abs(t)<e}function hi(t,e,i=1e-5){return li(t-e,i)}function ci(t,e){return Math.round(t/e)*e}function di(t){return isFinite(t)?t:t<0?-Number.MAX_VALUE:Number.MAX_VALUE}function ui(t){return Math.abs(t)<Number.MAX_VALUE?t:t*(1/0)}function pi(t,e,i,s,n=1/0,r){const o=2/(s=Math.max(1e-4,s)),a=o*r,l=1/(1+a+.48*a*a+.235*a*a*a);let h=t-e;const c=e,d=n*s;h=ai(h,-d,d),e=t-h;const u=(i.value+o*h)*r;i.value=(i.value-o*u)*l;let p=e+(h+u)*l;return c-t>0==p>c&&(p=c,i.value=(p-c)/r),p}function fi(t,e,i,s,n=1/0,r,o){const a=2/(s=Math.max(1e-4,s)),l=a*r,h=1/(1+l+.48*l*l+.235*l*l*l);let c=e.x,d=e.y,u=e.z,p=t.x-c,f=t.y-d,m=t.z-u;const g=c,_=d,y=u,w=n*s,v=p*p+f*f+m*m;if(v>w*w){const t=Math.sqrt(v);p=p/t*w,f=f/t*w,m=m/t*w}c=t.x-p,d=t.y-f,u=t.z-m;const b=(i.x+a*p)*r,x=(i.y+a*f)*r,E=(i.z+a*m)*r;i.x=(i.x-a*b)*h,i.y=(i.y-a*x)*h,i.z=(i.z-a*E)*h,o.x=c+(p+b)*h,o.y=d+(f+x)*h,o.z=u+(m+E)*h;const T=g-t.x,C=_-t.y,S=y-t.z;return T*(o.x-g)+C*(o.y-_)+S*(o.z-y)>0&&(o.x=g,o.y=_,o.z=y,i.x=(o.x-g)/r,i.y=(o.y-_)/r,i.z=(o.z-y)/r),o}function mi(t,e){e.set(0,0),t.forEach(t=>{e.x+=t.clientX,e.y+=t.clientY}),e.x/=t.length,e.y/=t.length}function gi(t,e){return!!si(t)&&(console.warn(`${e} is not supported in OrthographicCamera`),!0)}class _i{constructor(){this._listeners={}}addEventListener(t,e){const i=this._listeners;void 0===i[t]&&(i[t]=[]),-1===i[t].indexOf(e)&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return void 0!==i[t]&&-1!==i[t].indexOf(e)}removeEventListener(t,e){const i=this._listeners[t];if(void 0!==i){const t=i.indexOf(e);-1!==t&&i.splice(t,1)}}removeAllEventListeners(t){t?Array.isArray(this._listeners[t])&&(this._listeners[t].length=0):this._listeners={}}dispatchEvent(t){const e=this._listeners[t.type];if(void 0!==e){t.target=this;const i=e.slice(0);for(let e=0,s=i.length;e<s;e++)i[e].call(this,t)}}}var yi;const wi=1/8,vi=/Mac/.test(null===(yi=null===globalThis||void 0===globalThis?void 0:globalThis.navigator)||void 0===yi?void 0:yi.platform);let bi,xi,Ei,Ti,Ci,Si,Ai,Oi,Pi,Ii,ki,Di,zi,Mi,Bi,Ni,Ui,Li,Ri,Fi,Vi,ji,Zi;class Hi extends _i{static install(t){bi=t.THREE,xi=Object.freeze(new bi.Vector3(0,0,0)),Ei=Object.freeze(new bi.Vector3(0,1,0)),Ti=Object.freeze(new bi.Vector3(0,0,1)),Ci=new bi.Vector2,Si=new bi.Vector3,Ai=new bi.Vector3,Oi=new bi.Vector3,Pi=new bi.Vector3,Ii=new bi.Vector3,ki=new bi.Vector3,Di=new bi.Vector3,zi=new bi.Vector3,Mi=new bi.Vector3,Bi=new bi.Spherical,Ni=new bi.Spherical,Ui=new bi.Box3,Li=new bi.Box3,Ri=new bi.Sphere,Fi=new bi.Quaternion,Vi=new bi.Quaternion,ji=new bi.Matrix4,Zi=new bi.Raycaster}static get ACTION(){return Ke}set verticalDragToForward(t){console.warn("camera-controls: `verticalDragToForward` was removed. Use `mouseButtons.left = CameraControls.ACTION.SCREEN_PAN` instead.")}constructor(t,e){super(),this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=Number.EPSILON,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.dollyDragInverted=!1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=Ke.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Je,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new bi.Vector3,this._focalOffsetVelocity=new bi.Vector3,this._zoomVelocity={value:0},this._truckInternal=(t,e,i,s)=>{let n,r;if(ii(this._camera)){const i=Si.copy(this._camera.position).sub(this._target),s=this._camera.getEffectiveFOV()*oi,o=i.length()*Math.tan(.5*s);n=this.truckSpeed*t*o/this._elementRect.height,r=this.truckSpeed*e*o/this._elementRect.height}else{if(!si(this._camera))return;{const i=this._camera;n=this.truckSpeed*t*(i.right-i.left)/i.zoom/this._elementRect.width,r=this.truckSpeed*e*(i.top-i.bottom)/i.zoom/this._elementRect.height}}s?(i?this.setFocalOffset(this._focalOffsetEnd.x+n,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(n,0,!0),this.forward(-r,!0)):i?this.setFocalOffset(this._focalOffsetEnd.x+n,this._focalOffsetEnd.y+r,this._focalOffsetEnd.z,!0):this.truck(n,r,!0)},this._rotateInternal=(t,e)=>{const i=ni*this.azimuthRotateSpeed*t/this._elementRect.height,s=ni*this.polarRotateSpeed*e/this._elementRect.height;this.rotate(i,s,!0)},this._dollyInternal=(t,e,i)=>{const s=Math.pow(.95,-t*this.dollySpeed),n=this._sphericalEnd.radius,r=this._sphericalEnd.radius*s,o=ai(r,this.minDistance,this.maxDistance),a=o-r;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(r,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(a,!0),this._dollyToNoClamp(o,!0)):this._dollyToNoClamp(o,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?r:o)-n,this._dollyControlCoord.set(e,i)),this._lastDollyDirection=Math.sign(-t)},this._zoomInternal=(t,e,i)=>{const s=Math.pow(.95,t*this.dollySpeed),n=this._zoom,r=this._zoom*s;this.zoomTo(r,!0),this.dollyToCursor&&(this._changedZoom+=r-n,this._dollyControlCoord.set(e,i))},void 0===bi&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=t,this._yAxisUpSpace=(new bi.Quaternion).setFromUnitVectors(this._camera.up,Ei),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=Ke.NONE,this._target=new bi.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new bi.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=(new bi.Spherical).setFromVector3(Si.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new bi.Vector3,new bi.Vector3,new bi.Vector3,new bi.Vector3],this._updateNearPlaneCorners(),this._boundary=new bi.Box3(new bi.Vector3(-1/0,-1/0,-1/0),new bi.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new bi.Vector2,this.mouseButtons={left:Ke.ROTATE,middle:Ke.DOLLY,right:Ke.TRUCK,wheel:ii(this._camera)?Ke.DOLLY:si(this._camera)?Ke.ZOOM:Ke.NONE},this.touches={one:Ke.TOUCH_ROTATE,two:ii(this._camera)?Ke.TOUCH_DOLLY_TRUCK:si(this._camera)?Ke.TOUCH_ZOOM_TRUCK:Ke.NONE,three:Ke.TOUCH_TRUCK};const i=new bi.Vector2,s=new bi.Vector2,n=new bi.Vector2,r=t=>{if(!this._enabled||!this._domElement)return;if(0!==this._interactiveArea.left||0!==this._interactiveArea.top||1!==this._interactiveArea.width||1!==this._interactiveArea.height){const e=this._domElement.getBoundingClientRect(),i=t.clientX/e.width,s=t.clientY/e.height;if(i<this._interactiveArea.left||i>this._interactiveArea.right||s<this._interactiveArea.top||s>this._interactiveArea.bottom)return}const e="mouse"!==t.pointerType?null:(t.buttons&qe)===qe?qe:(t.buttons&Qe)===Qe?Qe:(t.buttons&Ge)===Ge?Ge:null;if(null!==e){const t=this._findPointerByMouseButton(e);t&&this._disposePointer(t)}if((t.buttons&qe)===qe&&this._lockedPointer)return;const i={pointerId:t.pointerId,clientX:t.clientX,clientY:t.clientY,deltaX:0,deltaY:0,mouseButton:e};this._activePointers.push(i),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",a),this._isDragging=!0,d(t)},o=t=>{t.cancelable&&t.preventDefault();const e=t.pointerId,i=this._lockedPointer||this._findPointerById(e);if(i){if(i.clientX=t.clientX,i.clientY=t.clientY,i.deltaX=t.movementX,i.deltaY=t.movementY,this._state=0,"touch"===t.pointerType)switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(t.buttons&qe)===qe)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(t.buttons&Qe)===Qe&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(t.buttons&Ge)===Ge&&(this._state=this._state|this.mouseButtons.right);u()}},a=t=>{const e=this._findPointerById(t.pointerId);if(!e||e!==this._lockedPointer){if(e&&this._disposePointer(e),"touch"===t.pointerType)switch(this._activePointers.length){case 0:this._state=Ke.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else this._state=Ke.NONE;p()}};let l=-1;const h=t=>{if(!this._domElement)return;if(!this._enabled||this.mouseButtons.wheel===Ke.NONE)return;if(0!==this._interactiveArea.left||0!==this._interactiveArea.top||1!==this._interactiveArea.width||1!==this._interactiveArea.height){const e=this._domElement.getBoundingClientRect(),i=t.clientX/e.width,s=t.clientY/e.height;if(i<this._interactiveArea.left||i>this._interactiveArea.right||s<this._interactiveArea.top||s>this._interactiveArea.bottom)return}if(t.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===Ke.ROTATE||this.mouseButtons.wheel===Ke.TRUCK){const t=performance.now();l-t<1e3&&this._getClientRect(this._elementRect),l=t}const e=vi?-1:-3,i=1===t.deltaMode||t.ctrlKey?t.deltaY/e:t.deltaY/(10*e),s=this.dollyToCursor?(t.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,n=this.dollyToCursor?(t.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case Ke.ROTATE:this._rotateInternal(t.deltaX,t.deltaY),this._isUserControllingRotate=!0;break;case Ke.TRUCK:this._truckInternal(t.deltaX,t.deltaY,!1,!1),this._isUserControllingTruck=!0;break;case Ke.SCREEN_PAN:this._truckInternal(t.deltaX,t.deltaY,!1,!0),this._isUserControllingTruck=!0;break;case Ke.OFFSET:this._truckInternal(t.deltaX,t.deltaY,!0,!1),this._isUserControllingOffset=!0;break;case Ke.DOLLY:this._dollyInternal(-i,s,n),this._isUserControllingDolly=!0;break;case Ke.ZOOM:this._zoomInternal(-i,s,n),this._isUserControllingZoom=!0}this.dispatchEvent({type:"control"})},c=t=>{if(this._domElement&&this._enabled){if(this.mouseButtons.right===Hi.ACTION.NONE){const e=t instanceof PointerEvent?t.pointerId:0,i=this._findPointerById(e);return i&&this._disposePointer(i),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),void this._domElement.ownerDocument.removeEventListener("pointerup",a)}t.preventDefault()}},d=t=>{if(!this._enabled)return;mi(this._activePointers,Ci),this._getClientRect(this._elementRect),i.copy(Ci),s.copy(Ci);if(this._activePointers.length>=2){const t=Ci.x-this._activePointers[1].clientX,e=Ci.y-this._activePointers[1].clientY,i=Math.sqrt(t*t+e*e);n.set(0,i);const r=.5*(this._activePointers[0].clientX+this._activePointers[1].clientX),o=.5*(this._activePointers[0].clientY+this._activePointers[1].clientY);s.set(r,o)}if(this._state=0,t)if("pointerType"in t&&"touch"===t.pointerType)switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else this._lockedPointer||(t.buttons&qe)!==qe||(this._state=this._state|this.mouseButtons.left),(t.buttons&Qe)===Qe&&(this._state=this._state|this.mouseButtons.middle),(t.buttons&Ge)===Ge&&(this._state=this._state|this.mouseButtons.right);else this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);(this._state&Ke.ROTATE)!==Ke.ROTATE&&(this._state&Ke.TOUCH_ROTATE)!==Ke.TOUCH_ROTATE&&(this._state&Ke.TOUCH_DOLLY_ROTATE)!==Ke.TOUCH_DOLLY_ROTATE&&(this._state&Ke.TOUCH_ZOOM_ROTATE)!==Ke.TOUCH_ZOOM_ROTATE||(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),(this._state&Ke.TRUCK)!==Ke.TRUCK&&(this._state&Ke.SCREEN_PAN)!==Ke.SCREEN_PAN&&(this._state&Ke.TOUCH_TRUCK)!==Ke.TOUCH_TRUCK&&(this._state&Ke.TOUCH_SCREEN_PAN)!==Ke.TOUCH_SCREEN_PAN&&(this._state&Ke.TOUCH_DOLLY_TRUCK)!==Ke.TOUCH_DOLLY_TRUCK&&(this._state&Ke.TOUCH_DOLLY_SCREEN_PAN)!==Ke.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Ke.TOUCH_ZOOM_TRUCK)!==Ke.TOUCH_ZOOM_TRUCK&&(this._state&Ke.TOUCH_ZOOM_SCREEN_PAN)!==Ke.TOUCH_DOLLY_SCREEN_PAN||(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),(this._state&Ke.DOLLY)!==Ke.DOLLY&&(this._state&Ke.TOUCH_DOLLY)!==Ke.TOUCH_DOLLY&&(this._state&Ke.TOUCH_DOLLY_TRUCK)!==Ke.TOUCH_DOLLY_TRUCK&&(this._state&Ke.TOUCH_DOLLY_SCREEN_PAN)!==Ke.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Ke.TOUCH_DOLLY_OFFSET)!==Ke.TOUCH_DOLLY_OFFSET&&(this._state&Ke.TOUCH_DOLLY_ROTATE)!==Ke.TOUCH_DOLLY_ROTATE||(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),(this._state&Ke.ZOOM)!==Ke.ZOOM&&(this._state&Ke.TOUCH_ZOOM)!==Ke.TOUCH_ZOOM&&(this._state&Ke.TOUCH_ZOOM_TRUCK)!==Ke.TOUCH_ZOOM_TRUCK&&(this._state&Ke.TOUCH_ZOOM_SCREEN_PAN)!==Ke.TOUCH_ZOOM_SCREEN_PAN&&(this._state&Ke.TOUCH_ZOOM_OFFSET)!==Ke.TOUCH_ZOOM_OFFSET&&(this._state&Ke.TOUCH_ZOOM_ROTATE)!==Ke.TOUCH_ZOOM_ROTATE||(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),(this._state&Ke.OFFSET)!==Ke.OFFSET&&(this._state&Ke.TOUCH_OFFSET)!==Ke.TOUCH_OFFSET&&(this._state&Ke.TOUCH_DOLLY_OFFSET)!==Ke.TOUCH_DOLLY_OFFSET&&(this._state&Ke.TOUCH_ZOOM_OFFSET)!==Ke.TOUCH_ZOOM_OFFSET||(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},u=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,mi(this._activePointers,Ci);const t=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,e=t?-t.deltaX:s.x-Ci.x,r=t?-t.deltaY:s.y-Ci.y;if(s.copy(Ci),(this._state&Ke.ROTATE)!==Ke.ROTATE&&(this._state&Ke.TOUCH_ROTATE)!==Ke.TOUCH_ROTATE&&(this._state&Ke.TOUCH_DOLLY_ROTATE)!==Ke.TOUCH_DOLLY_ROTATE&&(this._state&Ke.TOUCH_ZOOM_ROTATE)!==Ke.TOUCH_ZOOM_ROTATE||(this._rotateInternal(e,r),this._isUserControllingRotate=!0),(this._state&Ke.DOLLY)===Ke.DOLLY||(this._state&Ke.ZOOM)===Ke.ZOOM){const t=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,e=this.dollyToCursor?(i.y-this._elementRect.y)/this._elementRect.height*-2+1:0,s=this.dollyDragInverted?-1:1;(this._state&Ke.DOLLY)===Ke.DOLLY?(this._dollyInternal(s*r*wi,t,e),this._isUserControllingDolly=!0):(this._zoomInternal(s*r*wi,t,e),this._isUserControllingZoom=!0)}if((this._state&Ke.TOUCH_DOLLY)===Ke.TOUCH_DOLLY||(this._state&Ke.TOUCH_ZOOM)===Ke.TOUCH_ZOOM||(this._state&Ke.TOUCH_DOLLY_TRUCK)===Ke.TOUCH_DOLLY_TRUCK||(this._state&Ke.TOUCH_ZOOM_TRUCK)===Ke.TOUCH_ZOOM_TRUCK||(this._state&Ke.TOUCH_DOLLY_SCREEN_PAN)===Ke.TOUCH_DOLLY_SCREEN_PAN||(this._state&Ke.TOUCH_ZOOM_SCREEN_PAN)===Ke.TOUCH_ZOOM_SCREEN_PAN||(this._state&Ke.TOUCH_DOLLY_OFFSET)===Ke.TOUCH_DOLLY_OFFSET||(this._state&Ke.TOUCH_ZOOM_OFFSET)===Ke.TOUCH_ZOOM_OFFSET||(this._state&Ke.TOUCH_DOLLY_ROTATE)===Ke.TOUCH_DOLLY_ROTATE||(this._state&Ke.TOUCH_ZOOM_ROTATE)===Ke.TOUCH_ZOOM_ROTATE){const t=Ci.x-this._activePointers[1].clientX,e=Ci.y-this._activePointers[1].clientY,i=Math.sqrt(t*t+e*e),r=n.y-i;n.set(0,i);const o=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,a=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&Ke.TOUCH_DOLLY)===Ke.TOUCH_DOLLY||(this._state&Ke.TOUCH_DOLLY_ROTATE)===Ke.TOUCH_DOLLY_ROTATE||(this._state&Ke.TOUCH_DOLLY_TRUCK)===Ke.TOUCH_DOLLY_TRUCK||(this._state&Ke.TOUCH_DOLLY_SCREEN_PAN)===Ke.TOUCH_DOLLY_SCREEN_PAN||(this._state&Ke.TOUCH_DOLLY_OFFSET)===Ke.TOUCH_DOLLY_OFFSET?(this._dollyInternal(r*wi,o,a),this._isUserControllingDolly=!0):(this._zoomInternal(r*wi,o,a),this._isUserControllingZoom=!0)}(this._state&Ke.TRUCK)!==Ke.TRUCK&&(this._state&Ke.TOUCH_TRUCK)!==Ke.TOUCH_TRUCK&&(this._state&Ke.TOUCH_DOLLY_TRUCK)!==Ke.TOUCH_DOLLY_TRUCK&&(this._state&Ke.TOUCH_ZOOM_TRUCK)!==Ke.TOUCH_ZOOM_TRUCK||(this._truckInternal(e,r,!1,!1),this._isUserControllingTruck=!0),(this._state&Ke.SCREEN_PAN)!==Ke.SCREEN_PAN&&(this._state&Ke.TOUCH_SCREEN_PAN)!==Ke.TOUCH_SCREEN_PAN&&(this._state&Ke.TOUCH_DOLLY_SCREEN_PAN)!==Ke.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Ke.TOUCH_ZOOM_SCREEN_PAN)!==Ke.TOUCH_ZOOM_SCREEN_PAN||(this._truckInternal(e,r,!1,!0),this._isUserControllingTruck=!0),(this._state&Ke.OFFSET)!==Ke.OFFSET&&(this._state&Ke.TOUCH_OFFSET)!==Ke.TOUCH_OFFSET&&(this._state&Ke.TOUCH_DOLLY_OFFSET)!==Ke.TOUCH_DOLLY_OFFSET&&(this._state&Ke.TOUCH_ZOOM_OFFSET)!==Ke.TOUCH_ZOOM_OFFSET||(this._truckInternal(e,r,!0,!1),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},p=()=>{mi(this._activePointers,Ci),s.copy(Ci),this._dragNeedsUpdate=!1,(0===this._activePointers.length||1===this._activePointers.length&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),0===this._activePointers.length&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{this._enabled&&this._domElement&&(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",f),this._domElement.ownerDocument.addEventListener("pointerlockerror",m),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",a),d())},this.unlockPointer=()=>{var t,e,i;null!==this._lockedPointer&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),null===(t=this._domElement)||void 0===t||t.ownerDocument.exitPointerLock(),null===(e=this._domElement)||void 0===e||e.ownerDocument.removeEventListener("pointerlockchange",f),null===(i=this._domElement)||void 0===i||i.ownerDocument.removeEventListener("pointerlockerror",m),this.cancel()};const f=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},m=()=>{this.unlockPointer()};this._addAllEventListeners=t=>{this._domElement=t,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",r),this._domElement.addEventListener("pointercancel",a),this._domElement.addEventListener("wheel",h,{passive:!1}),this._domElement.addEventListener("contextmenu",c)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",r),this._domElement.removeEventListener("pointercancel",a),this._domElement.removeEventListener("wheel",h,{passive:!1}),this._domElement.removeEventListener("contextmenu",c),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.ownerDocument.removeEventListener("pointerlockchange",f),this._domElement.ownerDocument.removeEventListener("pointerlockerror",m))},this.cancel=()=>{this._state!==Ke.NONE&&(this._state=Ke.NONE,this._activePointers.length=0,p())},e&&this.connect(e),this.update(0)}get camera(){return this._camera}set camera(t){this._camera=t,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this._domElement&&(t?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(t){this._spherical.radius===t&&this._sphericalEnd.radius===t||(this._spherical.radius=t,this._sphericalEnd.radius=t,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(t){this._spherical.theta===t&&this._sphericalEnd.theta===t||(this._spherical.theta=t,this._sphericalEnd.theta=t,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(t){this._spherical.phi===t&&this._sphericalEnd.phi===t||(this._spherical.phi=t,this._sphericalEnd.phi=t,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(t){this._boundaryEnclosesCamera=t,this._needsUpdate=!0}set interactiveArea(t){this._interactiveArea.width=ai(t.width,0,1),this._interactiveArea.height=ai(t.height,0,1),this._interactiveArea.x=ai(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=ai(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,i=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,i)}rotateAzimuthTo(t,e=!1){return this.rotateTo(t,this._sphericalEnd.phi,e)}rotatePolarTo(t,e=!1){return this.rotateTo(this._sphericalEnd.theta,t,e)}rotateTo(t,e,i=!1){this._isUserControllingRotate=!1;const s=ai(t,this.minAzimuthAngle,this.maxAzimuthAngle),n=ai(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=s,this._sphericalEnd.phi=n,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,i||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const r=!i||hi(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&hi(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(r)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Je,this._changedDolly=0,this._dollyToNoClamp(ai(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const i=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const e=this._collisionTest(),s=hi(e,this._spherical.radius);if(!(i>t)&&s)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,e)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const s=!e||hi(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(s)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(Pi).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const i=!e||hi(this._target.x,this._targetEnd.x,this.restThreshold)&&hi(this._target.y,this._targetEnd.y,this.restThreshold)&&hi(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(i)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=ai(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const i=!e||hi(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(i)}pan(t,e,i=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,i)}truck(t,e,i=!1){this._camera.updateMatrix(),Ii.setFromMatrixColumn(this._camera.matrix,0),ki.setFromMatrixColumn(this._camera.matrix,1),Ii.multiplyScalar(t),ki.multiplyScalar(-e);const s=Si.copy(Ii).add(ki),n=Ai.copy(this._targetEnd).add(s);return this.moveTo(n.x,n.y,n.z,i)}forward(t,e=!1){Si.setFromMatrixColumn(this._camera.matrix,0),Si.crossVectors(this._camera.up,Si),Si.multiplyScalar(t);const i=Ai.copy(this._targetEnd).add(Si);return this.moveTo(i.x,i.y,i.z,e)}elevate(t,e=!1){return Si.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+Si.x,this._targetEnd.y+Si.y,this._targetEnd.z+Si.z,e)}moveTo(t,e,i,s=!1){this._isUserControllingTruck=!1;const n=Si.set(t,e,i).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,n,this.boundaryFriction),this._needsUpdate=!0,s||this._target.copy(this._targetEnd);const r=!s||hi(this._target.x,this._targetEnd.x,this.restThreshold)&&hi(this._target.y,this._targetEnd.y,this.restThreshold)&&hi(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(t,e,i,s=!1){const n=Si.set(t,e,i).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(n.x,n.y,n.z,s)}fitToBox(t,e,{cover:i=!1,paddingLeft:s=0,paddingRight:n=0,paddingBottom:r=0,paddingTop:o=0}={}){const a=[],l=t.isBox3?Ui.copy(t):Ui.setFromObject(t);l.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const h=ci(this._sphericalEnd.theta,ri),c=ci(this._sphericalEnd.phi,ri);a.push(this.rotateTo(h,c,e));const d=Si.setFromSpherical(this._sphericalEnd).normalize(),u=Fi.setFromUnitVectors(d,Ti),p=hi(Math.abs(d.y),1);p&&u.multiply(Vi.setFromAxisAngle(Ei,h)),u.multiply(this._yAxisUpSpaceInverse);const f=Li.makeEmpty();Ai.copy(l.min).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.min).setX(l.max.x).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.min).setY(l.max.y).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.max).setZ(l.min.z).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.min).setZ(l.max.z).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.max).setY(l.min.y).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.max).setX(l.min.x).applyQuaternion(u),f.expandByPoint(Ai),Ai.copy(l.max).applyQuaternion(u),f.expandByPoint(Ai),f.min.x-=s,f.min.y-=r,f.max.x+=n,f.max.y+=o,u.setFromUnitVectors(Ti,d),p&&u.premultiply(Vi.invert()),u.premultiply(this._yAxisUpSpace);const m=f.getSize(Si),g=f.getCenter(Ai).applyQuaternion(u);if(ii(this._camera)){const t=this.getDistanceToFitBox(m.x,m.y,m.z,i);a.push(this.moveTo(g.x,g.y,g.z,e)),a.push(this.dollyTo(t,e)),a.push(this.setFocalOffset(0,0,0,e))}else if(si(this._camera)){const t=this._camera,s=t.right-t.left,n=t.top-t.bottom,r=i?Math.max(s/m.x,n/m.y):Math.min(s/m.x,n/m.y);a.push(this.moveTo(g.x,g.y,g.z,e)),a.push(this.zoomTo(r,e)),a.push(this.setFocalOffset(0,0,0,e))}return Promise.all(a)}fitToSphere(t,e){const i=[],s="isObject3D"in t?Hi.createBoundingSphere(t,Ri):Ri.copy(t);if(i.push(this.moveTo(s.center.x,s.center.y,s.center.z,e)),ii(this._camera)){const t=this.getDistanceToFitSphere(s.radius);i.push(this.dollyTo(t,e))}else if(si(this._camera)){const t=this._camera.right-this._camera.left,n=this._camera.top-this._camera.bottom,r=2*s.radius,o=Math.min(t/r,n/r);i.push(this.zoomTo(o,e))}return i.push(this.setFocalOffset(0,0,0,e)),Promise.all(i)}setLookAt(t,e,i,s,n,r,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Je,this._changedDolly=0;const a=Ai.set(s,n,r),l=Si.set(t,e,i);this._targetEnd.copy(a),this._sphericalEnd.setFromVector3(l.sub(a).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const h=!o||hi(this._target.x,this._targetEnd.x,this.restThreshold)&&hi(this._target.y,this._targetEnd.y,this.restThreshold)&&hi(this._target.z,this._targetEnd.z,this.restThreshold)&&hi(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&hi(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&hi(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(h)}lerpLookAt(t,e,i,s,n,r,o,a,l,h,c,d,u,p=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Je,this._changedDolly=0;const f=Si.set(s,n,r),m=Ai.set(t,e,i);Bi.setFromVector3(m.sub(f).applyQuaternion(this._yAxisUpSpace));const g=Oi.set(h,c,d),_=Ai.set(o,a,l);Ni.setFromVector3(_.sub(g).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(f.lerp(g,u));const y=Ni.theta-Bi.theta,w=Ni.phi-Bi.phi,v=Ni.radius-Bi.radius;this._sphericalEnd.set(Bi.radius+v*u,Bi.phi+w*u,Bi.theta+y*u),this.normalizeRotations(),this._needsUpdate=!0,p||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const b=!p||hi(this._target.x,this._targetEnd.x,this.restThreshold)&&hi(this._target.y,this._targetEnd.y,this.restThreshold)&&hi(this._target.z,this._targetEnd.z,this.restThreshold)&&hi(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&hi(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&hi(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(b)}setPosition(t,e,i,s=!1){return this.setLookAt(t,e,i,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,s)}setTarget(t,e,i,s=!1){const n=this.getPosition(Si),r=this.setLookAt(n.x,n.y,n.z,t,e,i,s);return this._sphericalEnd.phi=ai(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),r}setFocalOffset(t,e,i,s=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,i),this._needsUpdate=!0,s||this._focalOffset.copy(this._focalOffsetEnd);const n=!s||hi(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&hi(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&hi(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}setOrbitPoint(t,e,i){this._camera.updateMatrixWorld(),Ii.setFromMatrixColumn(this._camera.matrixWorldInverse,0),ki.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Di.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const s=Si.set(t,e,i),n=s.distanceTo(this._camera.position),r=s.sub(this._camera.position);Ii.multiplyScalar(r.x),ki.multiplyScalar(r.y),Di.multiplyScalar(r.z),Si.copy(Ii).add(ki).add(Di),Si.z=Si.z+n,this.dollyTo(n,!1),this.setFocalOffset(-Si.x,Si.y,-Si.z,!1),this.moveTo(t,e,i,!1)}setBoundary(t){if(!t)return this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),void(this._needsUpdate=!0);this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,i,s){null!==t?(this._viewport=this._viewport||new bi.Vector4,"number"==typeof t?this._viewport.set(t,e,i,s):this._viewport.copy(t)):this._viewport=null}getDistanceToFitBox(t,e,i,s=!1){if(gi(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const n=t/e,r=this._camera.getEffectiveFOV()*oi,o=this._camera.aspect;return.5*((s?n>o:n<o)?e:t/o)/Math.tan(.5*r)+.5*i}getDistanceToFitSphere(t){if(gi(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*oi,i=2*Math.atan(Math.tan(.5*e)*this._camera.aspect),s=1<this._camera.aspect?e:i;return t/Math.sin(.5*s)}getTarget(t,e=!0){return(t&&t.isVector3?t:new bi.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new bi.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new bi.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new bi.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%ni,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=ni),this._spherical.theta+=ni*Math.round((this._sphericalEnd.theta-this._spherical.theta)/ni)}stop(){this._focalOffset.copy(this._focalOffsetEnd),this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd),this._zoom=this._zoomEnd}reset(t=!1){if(!hi(this._camera.up.x,this._cameraUp0.x)||!hi(this._camera.up.y,this._cameraUp0.y)||!hi(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const t=this.getPosition(Si);this.updateCameraUp(),this.setPosition(t.x,t.y,t.z)}const e=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,t),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,t),this.zoomTo(this._zoom0,t)];return Promise.all(e)}saveState(){this._cameraUp0.copy(this._camera.up),this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,Ei),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=Si.subVectors(this._target,this._camera.position).normalize(),e=Ai.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const i=this.getPosition(Si);this.updateCameraUp(),this.setPosition(i.x,i.y,i.z)}update(t){const e=this._sphericalEnd.theta-this._spherical.theta,i=this._sphericalEnd.phi-this._spherical.phi,s=this._sphericalEnd.radius-this._spherical.radius,n=zi.subVectors(this._targetEnd,this._target),r=Mi.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(li(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=pi(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,e,1/0,t),this._needsUpdate=!0}if(li(i))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=pi(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,e,1/0,t),this._needsUpdate=!0}if(li(s))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const e=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=pi(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,e,this.maxSpeed,t),this._needsUpdate=!0}if(li(n.x)&&li(n.y)&&li(n.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const e=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;fi(this._target,this._targetEnd,this._targetVelocity,e,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(li(r.x)&&li(r.y)&&li(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const e=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;fi(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,e,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(li(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const e=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=pi(this._zoom,this._zoomEnd,this._zoomVelocity,e,1/0,t)}if(this.dollyToCursor)if(ii(this._camera)&&0!==this._changedDolly){const t=this._spherical.radius-this._lastDistance,e=this._camera,i=this._getCameraDirection(Pi),s=Si.copy(i).cross(e.up).normalize();0===s.lengthSq()&&(s.x=1);const n=Ai.crossVectors(s,i),r=this._sphericalEnd.radius*Math.tan(e.getEffectiveFOV()*oi*.5),o=(this._sphericalEnd.radius-t-this._sphericalEnd.radius)/this._sphericalEnd.radius,a=Oi.copy(this._targetEnd).add(s.multiplyScalar(this._dollyControlCoord.x*r*e.aspect)).add(n.multiplyScalar(this._dollyControlCoord.y*r)),l=Si.copy(this._targetEnd).lerp(a,o),h=this._lastDollyDirection===ti&&this._spherical.radius<=this.minDistance,c=this._lastDollyDirection===ei&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(h||c)){this._sphericalEnd.radius-=t,this._spherical.radius-=t;const e=Ai.copy(i).multiplyScalar(-t);l.add(e)}this._boundary.clampPoint(l,l);const d=Ai.subVectors(l,this._targetEnd);this._targetEnd.copy(l),this._target.add(d),this._changedDolly-=t,li(this._changedDolly)&&(this._changedDolly=0)}else if(si(this._camera)&&0!==this._changedZoom){const t=this._zoom-this._lastZoom,e=this._camera,i=Si.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(e.near+e.far)/(e.near-e.far)).unproject(e),s=Ai.set(0,0,-1).applyQuaternion(e.quaternion),n=Oi.copy(i).add(s.multiplyScalar(-i.dot(e.up))),r=-(this._zoom-t-this._zoom)/this._zoom,o=this._getCameraDirection(Pi),a=this._targetEnd.dot(o),l=Si.copy(this._targetEnd).lerp(n,r),h=l.dot(o),c=o.multiplyScalar(h-a);l.sub(c),this._boundary.clampPoint(l,l);const d=Ai.subVectors(l,this._targetEnd);this._targetEnd.copy(l),this._target.add(d),this._changedZoom-=t,li(this._changedZoom)&&(this._changedZoom=0)}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0),this._dragNeedsUpdate=!0;const a=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,a),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target);(!li(this._focalOffset.x)||!li(this._focalOffset.y)||!li(this._focalOffset.z))&&(Ii.setFromMatrixColumn(this._camera.matrix,0),ki.setFromMatrixColumn(this._camera.matrix,1),Di.setFromMatrixColumn(this._camera.matrix,2),Ii.multiplyScalar(this._focalOffset.x),ki.multiplyScalar(-this._focalOffset.y),Di.multiplyScalar(this._focalOffset.z),Si.copy(Ii).add(ki).add(Di),this._camera.position.add(Si),this._camera.updateMatrixWorld()),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),Si.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const l=this._needsUpdate;return l&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):l?(this.dispatchEvent({type:"update"}),li(e,this.restThreshold)&&li(i,this.restThreshold)&&li(s,this.restThreshold)&&li(n.x,this.restThreshold)&&li(n.y,this.restThreshold)&&li(n.z,this.restThreshold)&&li(r.x,this.restThreshold)&&li(r.y,this.restThreshold)&&li(r.z,this.restThreshold)&&li(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!l&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=l,this._needsUpdate=!1,l}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:di(this.maxDistance),minZoom:this.minZoom,maxZoom:di(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:di(this.maxPolarAngle),minAzimuthAngle:di(this.minAzimuthAngle),maxAzimuthAngle:di(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,target:this._targetEnd.toArray(),position:Si.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(t,e=!1){const i=JSON.parse(t);this.enabled=i.enabled,this.minDistance=i.minDistance,this.maxDistance=ui(i.maxDistance),this.minZoom=i.minZoom,this.maxZoom=ui(i.maxZoom),this.minPolarAngle=i.minPolarAngle,this.maxPolarAngle=ui(i.maxPolarAngle),this.minAzimuthAngle=ui(i.minAzimuthAngle),this.maxAzimuthAngle=ui(i.maxAzimuthAngle),this.smoothTime=i.smoothTime,this.draggingSmoothTime=i.draggingSmoothTime,this.dollySpeed=i.dollySpeed,this.truckSpeed=i.truckSpeed,this.dollyToCursor=i.dollyToCursor,this._target0.fromArray(i.target0),this._position0.fromArray(i.position0),this._zoom0=i.zoom0,this._focalOffset0.fromArray(i.focalOffset0),this.moveTo(i.target[0],i.target[1],i.target[2],e),Bi.setFromVector3(Si.fromArray(i.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(Bi.theta,Bi.phi,e),this.dollyTo(Bi.radius,e),this.zoomTo(i.zoom,e),this.setFocalOffset(i.focalOffset[0],i.focalOffset[1],i.focalOffset[2],e),this._needsUpdate=!0}connect(t){this._domElement?console.warn("camera-controls is already connected."):(t.setAttribute("data-camera-controls-version","2.10.1"),this._addAllEventListeners(t),this._getClientRect(this._elementRect))}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement.removeAttribute("data-camera-controls-version"),this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(t){return t.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(t){return this._getTargetDirection(t).negate()}_findPointerById(t){return this._activePointers.find(e=>e.pointerId===t)}_findPointerByMouseButton(t){return this._activePointers.find(e=>e.mouseButton===t)}_disposePointer(t){this._activePointers.splice(this._activePointers.indexOf(t),1)}_encloseToBoundary(t,e,i){const s=e.lengthSq();if(0===s)return t;const n=Ai.copy(e).add(t),r=this._boundary.clampPoint(n,Oi).sub(n),o=r.lengthSq();if(0===o)return t.add(e);if(o===s)return t;if(0===i)return t.add(e).add(r);{const s=1+i*o/e.dot(r);return t.add(Ai.copy(e).multiplyScalar(s)).add(r.multiplyScalar(1-i))}}_updateNearPlaneCorners(){if(ii(this._camera)){const t=this._camera,e=t.near,i=t.getEffectiveFOV()*oi,s=Math.tan(.5*i)*e,n=s*t.aspect;this._nearPlaneCorners[0].set(-n,-s,0),this._nearPlaneCorners[1].set(n,-s,0),this._nearPlaneCorners[2].set(n,s,0),this._nearPlaneCorners[3].set(-n,s,0)}else if(si(this._camera)){const t=this._camera,e=1/t.zoom,i=t.left*e,s=t.right*e,n=t.top*e,r=t.bottom*e;this._nearPlaneCorners[0].set(i,n,0),this._nearPlaneCorners[1].set(s,n,0),this._nearPlaneCorners[2].set(s,r,0),this._nearPlaneCorners[3].set(i,r,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1))return t;if(gi(this._camera,"_collisionTest"))return t;const e=this._getTargetDirection(Pi);ji.lookAt(xi,e,this._camera.up);for(let i=0;i<4;i++){const s=Ai.copy(this._nearPlaneCorners[i]);s.applyMatrix4(ji);const n=Oi.addVectors(this._target,s);Zi.set(n,e),Zi.far=this._spherical.radius+1;const r=Zi.intersectObjects(this.colliderMeshes);0!==r.length&&r[0].distance<t&&(t=r[0].distance)}return t}_getClientRect(t){if(!this._domElement)return;const e=this._domElement.getBoundingClientRect();return t.x=e.left,t.y=e.top,this._viewport?(t.x+=this._viewport.x,t.y+=e.height-this._viewport.w-this._viewport.y,t.width=this._viewport.z,t.height=this._viewport.w):(t.width=e.width,t.height=e.height),t}_createOnRestPromise(t){return t?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(t=>{const e=()=>{this.removeEventListener("rest",e),t()};this.addEventListener("rest",e)}))}_addAllEventListeners(t){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(t){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(t){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(t,e=new bi.Sphere){const i=e,s=i.center;Ui.makeEmpty(),t.traverseVisible(t=>{t.isMesh&&Ui.expandByObject(t)}),Ui.getCenter(s);let n=0;return t.traverseVisible(t=>{if(!t.isMesh)return;const e=t;if(!e.geometry)return;const i=e.geometry.clone();i.applyMatrix4(e.matrixWorld);const r=i.attributes.position;for(let t=0,e=r.count;t<e;t++)Si.fromBufferAttribute(r,t),n=Math.max(n,s.distanceToSquared(Si))}),i.radius=Math.sqrt(n),i}}class $i extends j{constructor(t){super(t),e(this,"onBeforeUpdate",new U),e(this,"onAfterUpdate",new U),e(this,"onAspectUpdated",new U),e(this,"onDisposed",new U),e(this,"three"),e(this,"_allControls",new Map),e(this,"updateAspect",()=>{var t;if(this.currentWorld&&this.currentWorld.renderer)if(this.three instanceof r.OrthographicCamera)this.onAspectUpdated.trigger();else if(null==(t=this.currentWorld.renderer)?void 0:t.isResizeable()){const t=this.currentWorld.renderer.getSize();this.three.aspect=t.width/t.height,this.three.updateProjectionMatrix(),this.onAspectUpdated.trigger()}}),this.three=this.setupCamera(),this.setupEvents(!0),this.worlds.onItemSet.add(({value:t})=>{const e=this.newCameraControls();this._allControls.set(t.uuid,e)}),this.worlds.onBeforeDelete.add(({value:t})=>{const e=this._allControls.get(t.uuid);e&&(e.dispose(),this._allControls.delete(t.uuid))})}get controls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");const t=this._allControls.get(this.currentWorld.uuid);if(!t)throw new Error("Controls not found!");return t}get enabled(){return null!==this.currentWorld&&this.controls.enabled}set enabled(t){null!==this.currentWorld&&(this.controls.enabled=t)}set currentWorld(t){if(super.currentWorld=t,!t)return;this.worlds.get(t.uuid)||this.worlds.set(t.uuid,t)}get currentWorld(){return this._currentWorld}dispose(){this.setupEvents(!1),this.onAspectUpdated.reset(),this.onBeforeUpdate.reset(),this.onAfterUpdate.reset(),this.three.removeFromParent(),this.onDisposed.trigger(),this.onDisposed.reset();for(const[t,e]of this._allControls)e.dispose();this.worlds.clear()}async fitToItems(t){const e=await this.getItemsBounding(t);await this.controls.fitToSphere(e,!0)}async setOrbitToItems(t){const e=await this.getItemsBounding(t);this.controls.setOrbitPoint(e.center.x,e.center.y,e.center.z)}update(t){this.enabled&&(this.onBeforeUpdate.trigger(this),this.controls.update(t),this.onAfterUpdate.trigger(this))}async getItemsBounding(t){const e=this.components.get(Ae),i=this.components.get(Me);i.list.clear();const s=new r.Sphere;if(t)await i.addFromModelIdMap(t);else for(const[,t]of e.list)i.list.add(t.box);return i.get().getBoundingSphere(s),i.list.clear(),s}setupCamera(){const t=window.innerWidth/window.innerHeight,e=new r.PerspectiveCamera(60,t,1,1e3);return e.position.set(50,50,50),e.lookAt(new r.Vector3(0,0,0)),e}newCameraControls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");if(!this.currentWorld.renderer)throw new Error("This camera needs a renderer to work!");Hi.install({THREE:$i.getSubsetOfThree()});const{domElement:t}=this.currentWorld.renderer.three,e=new Hi(this.three,t);return e.smoothTime=.2,e.dollyToCursor=!0,e.infinityDolly=!0,e.minDistance=6,e}setupEvents(t){t?window.addEventListener("resize",this.updateAspect):window.removeEventListener("resize",this.updateAspect)}static getSubsetOfThree(){return{MOUSE:r.MOUSE,Vector2:r.Vector2,Vector3:r.Vector3,Vector4:r.Vector4,Quaternion:r.Quaternion,Matrix4:r.Matrix4,Spherical:r.Spherical,Box3:r.Box3,Sphere:r.Sphere,Raycaster:r.Raycaster,MathUtils:r.MathUtils}}}const Wi=class t extends F{constructor(i){super(i),e(this,"onAfterUpdate",new U),e(this,"onBeforeUpdate",new U),e(this,"onDisposed",new U),e(this,"list",new we),e(this,"enabled",!0),i.add(t.uuid,this)}create(){const t=new Ze(this.components),e=t.uuid;if(this.list.has(e))throw new Error("There is already a world with this name!");return this.list.set(e,t),t}delete(t){if(!this.list.has(t.uuid))throw new Error("The provided world is not found in the list!");this.list.delete(t.uuid),t.dispose()}dispose(){this.enabled=!1;for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}update(t){if(this.enabled)for(const[e,i]of this.list)i.update(t)}};e(Wi,"uuid","fdb61dc4-2ec1-4966-b83d-54ea795fad4a");let Yi=Wi;class Xi extends xe{constructor(){super(...arguments),e(this,"_config",{visible:{value:!0,type:"Boolean"},color:{value:new r.Color,type:"Color"},primarySize:{type:"Number",interpolable:!0,value:1,min:0,max:1e3},secondarySize:{type:"Number",interpolable:!0,value:10,min:0,max:1e3},distance:{type:"Number",interpolable:!0,value:500,min:0,max:500}})}get visible(){return this._config.visible.value}set visible(t){this._config.visible.value=t,this._component.visible=t}get color(){return this._config.color.value}set color(t){this._config.color.value=t,this._component.material.uniforms.uColor.value=t,this._component.material.uniformsNeedUpdate=!0}get primarySize(){return this._config.primarySize.value}set primarySize(t){this._config.primarySize.value=t,this._component.material.uniforms.uSize1.value=t,this._component.material.uniformsNeedUpdate=!0}get secondarySize(){return this._config.secondarySize.value}set secondarySize(t){this._config.secondarySize.value=t,this._component.material.uniforms.uSize2.value=t,this._component.material.uniformsNeedUpdate=!0}get distance(){return this._config.distance.value}set distance(t){this._config.distance.value=t,this._component.material.uniforms.uDistance.value=t,this._component.material.uniformsNeedUpdate=!0}}class qi{constructor(t,i){e(this,"onDisposed",new U),e(this,"onSetup",new U),e(this,"isSetup",!1),e(this,"world"),e(this,"components"),e(this,"config"),e(this,"_defaultConfig",{visible:!0,color:new r.Color(12303291),primarySize:1,secondarySize:10,distance:500}),e(this,"three"),e(this,"_fade",3),e(this,"updateZoom",()=>{this.world.camera instanceof $i&&(this.material.uniforms.uZoom.value=this.world.camera.three.zoom)}),this.world=i;const{color:s,primarySize:n,secondarySize:o,distance:a}=this._defaultConfig;this.components=t,this.config=new Xi(this,this.components,"Grid");const l=new r.PlaneGeometry(2,2,1,1),h=new r.ShaderMaterial({side:r.DoubleSide,uniforms:{uSize1:{value:n},uSize2:{value:o},uColor:{value:s},uDistance:{value:a},uFade:{value:this._fade},uZoom:{value:1}},transparent:!0,vertexShader:"\n \n varying vec3 worldPosition;\n \n uniform float uDistance;\n \n void main() {\n \n vec3 pos = position.xzy * uDistance;\n pos.xz += cameraPosition.xz;\n \n worldPosition = pos;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);\n \n }\n ",fragmentShader:"\n \n varying vec3 worldPosition;\n \n uniform float uZoom;\n uniform float uFade;\n uniform float uSize1;\n uniform float uSize2;\n uniform vec3 uColor;\n uniform float uDistance;\n \n \n \n float getGrid(float size) {\n \n vec2 r = worldPosition.xz / size;\n \n \n vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n float line = min(grid.x, grid.y);\n \n \n return 1.0 - min(line, 1.0);\n }\n \n void main() {\n \n \n float d = 1.0 - min(distance(cameraPosition.xz, worldPosition.xz) / uDistance, 1.0);\n \n float g1 = getGrid(uSize1);\n float g2 = getGrid(uSize2);\n \n // Ortho camera fades the grid away when zooming out\n float minZoom = step(0.2, uZoom);\n float zoomFactor = pow(min(uZoom, 1.), 2.) * minZoom;\n \n gl_FragColor = vec4(uColor.rgb, mix(g2, g1, g1) * pow(d, uFade));\n gl_FragColor.a = mix(0.5 * gl_FragColor.a, gl_FragColor.a, g2) * zoomFactor;\n \n if ( gl_FragColor.a <= 0.0 ) discard;\n \n \n }\n \n ",extensions:{derivatives:!0}});this.three=new r.Mesh(l,h),this.three.frustumCulled=!1,i.scene.three.add(this.three),this.setupEvents(!0)}get visible(){return this.three.visible}set visible(t){if(this.three.visible=t,t){this.world.scene.three.add(this.three)}else this.three.removeFromParent()}get material(){return this.three.material}get fade(){return 3===this._fade}set fade(t){this._fade=t?3:0,this.material.uniforms.uFade.value=this._fade}setup(t){const e={...this._defaultConfig,...t};this.config.visible=!0,this.config.color=e.color,this.config.primarySize=e.primarySize,this.config.secondarySize=e.secondarySize,this.config.distance=e.distance,this.isSetup=!0,this.onSetup.trigger()}dispose(){this.setupEvents(!1);this.components.get(Te).list.delete(this.config.uuid);this.components.get($).destroy(this.three),this.onDisposed.trigger(),this.onDisposed.reset(),this.world=null,this.components=null}setupEvents(t){if(this.world.isDisposing)return;if(!(this.world.camera instanceof $i))return;const e=this.world.camera.controls;t?e.addEventListener("update",this.updateZoom):e.removeEventListener("update",this.updateZoom)}}const Gi=class t extends F{constructor(i){super(i),e(this,"list",new Map),e(this,"onDisposed",new U),e(this,"enabled",!0),i.add(t.uuid,this)}create(t){if(this.list.has(t.uuid))throw new Error("This world already has a grid!");const e=new qi(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}};e(Gi,"uuid","d1e814d5-b81c-4452-87a2-f039375e0489");let Qi=Gi;const Ki=1.25,Ji=65535,ts=Math.pow(2,-24),es=Symbol("SKIP_GENERATION");function is(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}function ss(t,e){if(!t.index){const i=t.attributes.position.count,s=function(t,e=ArrayBuffer){return t>65535?new Uint32Array(new e(4*t)):new Uint16Array(new e(2*t))}(i,e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);t.setIndex(new o(s,1));for(let t=0;t<i;t++)s[t]=t}}function ns(t){const e=is(t),i=t.drawRange,s=i.start/3,n=(i.start+i.count)/3,r=Math.max(0,s),o=Math.min(e,n)-r;return[{offset:Math.floor(r),count:Math.floor(o)}]}function rs(t){if(!t.groups||!t.groups.length)return ns(t);const e=[],i=new Set,s=t.drawRange,n=s.start/3,r=(s.start+s.count)/3;for(const e of t.groups){const t=e.start/3,s=(e.start+e.count)/3;i.add(Math.max(n,t)),i.add(Math.min(r,s))}const o=Array.from(i.values()).sort((t,e)=>t-e);for(let t=0;t<o.length-1;t++){const i=o[t],s=o[t+1];e.push({offset:Math.floor(i),count:Math.floor(s-i)})}return e}function os(t,e,i){return i.min.x=e[t],i.min.y=e[t+1],i.min.z=e[t+2],i.max.x=e[t+3],i.max.y=e[t+4],i.max.z=e[t+5],i}function as(t){let e=-1,i=-1/0;for(let s=0;s<3;s++){const n=t[s+3]-t[s];n>i&&(i=n,e=s)}return e}function ls(t,e){e.set(t)}function hs(t,e,i){let s,n;for(let r=0;r<3;r++){const o=r+3;s=t[r],n=e[r],i[r]=s<n?s:n,s=t[o],n=e[o],i[o]=s>n?s:n}}function cs(t,e,i){for(let s=0;s<3;s++){const n=e[t+2*s],r=e[t+2*s+1],o=n-r,a=n+r;o<i[s]&&(i[s]=o),a>i[s+3]&&(i[s+3]=a)}}function ds(t){const e=t[3]-t[0],i=t[4]-t[1],s=t[5]-t[2];return 2*(e*i+i*s+s*e)}function us(t,e,i,s,n=null){let r=1/0,o=1/0,a=1/0,l=-1/0,h=-1/0,c=-1/0,d=1/0,u=1/0,p=1/0,f=-1/0,m=-1/0,g=-1/0;const _=null!==n;for(let s=6*e,n=6*(e+i);s<n;s+=6){const e=t[s+0],i=t[s+1],n=e-i,y=e+i;n<r&&(r=n),y>l&&(l=y),_&&e<d&&(d=e),_&&e>f&&(f=e);const w=t[s+2],v=t[s+3],b=w-v,x=w+v;b<o&&(o=b),x>h&&(h=x),_&&w<u&&(u=w),_&&w>m&&(m=w);const E=t[s+4],T=t[s+5],C=E-T,S=E+T;C<a&&(a=C),S>c&&(c=S),_&&E<p&&(p=E),_&&E>g&&(g=E)}s[0]=r,s[1]=o,s[2]=a,s[3]=l,s[4]=h,s[5]=c,_&&(n[0]=d,n[1]=u,n[2]=p,n[3]=f,n[4]=m,n[5]=g)}const ps=32,fs=(t,e)=>t.candidate-e.candidate,ms=new Array(ps).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),gs=new Float32Array(6);class _s{constructor(){}}function ys(t,e,i,s,n,r){let o=s,a=s+n-1;const l=r.pos,h=2*r.axis;for(;;){for(;o<=a&&i[6*o+h]<l;)o++;for(;o<=a&&i[6*a+h]>=l;)a--;if(!(o<a))return o;for(let t=0;t<3;t++){let i=e[3*o+t];e[3*o+t]=e[3*a+t],e[3*a+t]=i}for(let t=0;t<6;t++){let e=i[6*o+t];i[6*o+t]=i[6*a+t],i[6*a+t]=e}o++,a--}}function ws(t,e,i,s,n,r){let o=s,a=s+n-1;const l=r.pos,h=2*r.axis;for(;;){for(;o<=a&&i[6*o+h]<l;)o++;for(;o<=a&&i[6*a+h]>=l;)a--;if(!(o<a))return o;{let e=t[o];t[o]=t[a],t[a]=e;for(let t=0;t<6;t++){let e=i[6*o+t];i[6*o+t]=i[6*a+t],i[6*a+t]=e}o++,a--}}}function vs(t,e){const i=t.geometry,s=i.index?i.index.array:null,n=e.maxDepth,r=e.verbose,o=e.maxLeafTris,a=e.strategy,l=e.onProgress,h=is(i),c=t._indirectBuffer;let d=!1;const u=new Float32Array(6),p=new Float32Array(6),f=function(t,e){var i;(i=e)[0]=i[1]=i[2]=1/0,i[3]=i[4]=i[5]=-1/0;const s=t.attributes.position,n=t.index?t.index.array:null,r=is(t),o=new Float32Array(6*r),a=s.normalized,l=s.array,h=s.offset||0;let c=3;s.isInterleavedBufferAttribute&&(c=s.data.stride);const d=["getX","getY","getZ"];for(let t=0;t<r;t++){const i=3*t,r=6*t;let u=i+0,p=i+1,f=i+2;n&&(u=n[u],p=n[p],f=n[f]),a||(u=u*c+h,p=p*c+h,f=f*c+h);for(let t=0;t<3;t++){let i,n,h;a?(i=s[d[t]](u),n=s[d[t]](p),h=s[d[t]](f)):(i=l[u+t],n=l[p+t],h=l[f+t]);let c=i;n<c&&(c=n),h<c&&(c=h);let m=i;n>m&&(m=n),h>m&&(m=h);const g=(m-c)/2,_=2*t;o[r+_+0]=c+g,o[r+_+1]=g+(Math.abs(c)+g)*ts,c<e[t]&&(e[t]=c),m>e[t+3]&&(e[t+3]=m)}}return o}(i,u),m=e.indirect?ws:ys,g=[],_=e.indirect?ns(i):rs(i);if(1===_.length){const t=_[0],e=new _s;e.boundingData=u,function(t,e,i,s){let n=1/0,r=1/0,o=1/0,a=-1/0,l=-1/0,h=-1/0;for(let s=6*e,c=6*(e+i);s<c;s+=6){const e=t[s+0];e<n&&(n=e),e>a&&(a=e);const i=t[s+2];i<r&&(r=i),i>l&&(l=i);const c=t[s+4];c<o&&(o=c),c>h&&(h=c)}s[0]=n,s[1]=r,s[2]=o,s[3]=a,s[4]=l,s[5]=h}(f,t.offset,t.count,p),w(e,t.offset,t.count,p),g.push(e)}else for(let t of _){const e=new _s;e.boundingData=new Float32Array(6),us(f,t.offset,t.count,e.boundingData,p),w(e,t.offset,t.count,p),g.push(e)}return g;function y(t){l&&l(t/h)}function w(t,e,l,h=null,u=0){if(!d&&u>=n&&(d=!0,r&&(console.warn(`MeshBVH: Max depth of ${n} reached when generating BVH. Consider increasing maxDepth.`),console.warn(i))),l<=o||u>=n)return y(e+l),t.offset=e,t.count=l,t;const g=function(t,e,i,s,n,r){let o=-1,a=0;if(0===r)o=as(e),-1!==o&&(a=(e[o]+e[o+3])/2);else if(1===r)o=as(t),-1!==o&&(a=function(t,e,i,s){let n=0;for(let r=e,o=e+i;r<o;r++)n+=t[6*r+2*s];return n/i}(i,s,n,o));else if(2===r){const r=ds(t);let l=Ki*n;const h=6*s,c=6*(s+n);for(let t=0;t<3;t++){const s=e[t],d=(e[t+3]-s)/ps;if(n<8){const e=[...ms];e.length=n;let s=0;for(let n=h;n<c;n+=6,s++){const r=e[s];r.candidate=i[n+2*t],r.count=0;const{bounds:o,leftCacheBounds:a,rightCacheBounds:l}=r;for(let t=0;t<3;t++)l[t]=1/0,l[t+3]=-1/0,a[t]=1/0,a[t+3]=-1/0,o[t]=1/0,o[t+3]=-1/0;cs(n,i,o)}e.sort(fs);let d=n;for(let t=0;t<d;t++){const i=e[t];for(;t+1<d&&e[t+1].candidate===i.candidate;)e.splice(t+1,1),d--}for(let s=h;s<c;s+=6){const n=i[s+2*t];for(let t=0;t<d;t++){const r=e[t];n>=r.candidate?cs(s,i,r.rightCacheBounds):(cs(s,i,r.leftCacheBounds),r.count++)}}for(let i=0;i<d;i++){const s=e[i],h=s.count,c=n-s.count,d=s.leftCacheBounds,u=s.rightCacheBounds;let p=0;0!==h&&(p=ds(d)/r);let f=0;0!==c&&(f=ds(u)/r);const m=1+Ki*(p*h+f*c);m<l&&(o=t,l=m,a=s.candidate)}}else{for(let t=0;t<ps;t++){const e=ms[t];e.count=0,e.candidate=s+d+t*d;const i=e.bounds;for(let t=0;t<3;t++)i[t]=1/0,i[t+3]=-1/0}for(let e=h;e<c;e+=6){let n=~~((i[e+2*t]-s)/d);n>=ps&&(n=31);const r=ms[n];r.count++,cs(e,i,r.bounds)}const e=ms[31];ls(e.bounds,e.rightCacheBounds);for(let t=30;t>=0;t--){const e=ms[t],i=ms[t+1];hs(e.bounds,i.rightCacheBounds,e.rightCacheBounds)}let u=0;for(let e=0;e<31;e++){const i=ms[e],s=i.count,h=i.bounds,c=ms[e+1].rightCacheBounds;0!==s&&(0===u?ls(h,gs):hs(h,gs,gs)),u+=s;let d=0,p=0;0!==u&&(d=ds(gs)/r);const f=n-u;0!==f&&(p=ds(c)/r);const m=1+Ki*(d*u+p*f);m<l&&(o=t,l=m,a=i.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${r} used.`);return{axis:o,pos:a}}(t.boundingData,h,f,e,l,a);if(-1===g.axis)return y(e+l),t.offset=e,t.count=l,t;const _=m(c,s,f,e,l,g);if(_===e||_===e+l)y(e+l),t.offset=e,t.count=l;else{t.splitAxis=g.axis;const i=new _s,s=e,n=_-e;t.left=i,i.boundingData=new Float32Array(6),us(f,s,n,i.boundingData,p),w(i,s,n,p,u+1);const r=new _s,o=_,a=l-n;t.right=r,r.boundingData=new Float32Array(6),us(f,o,a,r.boundingData,p),w(r,o,a,p,u+1)}return t}}function bs(t,e){const i=t.geometry;e.indirect&&(t._indirectBuffer=function(t,e){const i=(t.index?t.index.count:t.attributes.position.count)/3,s=i>65536,n=s?4:2,r=e?new SharedArrayBuffer(i*n):new ArrayBuffer(i*n),o=s?new Uint32Array(r):new Uint16Array(r);for(let t=0,e=o.length;t<e;t++)o[t]=t;return o}(i,e.useSharedArrayBuffer),function(t){if(0===t.groups.length)return!1;const e=is(t),i=rs(t).sort((t,e)=>t.offset-e.offset),s=i[i.length-1];s.count=Math.min(e-s.offset,s.count);let n=0;return i.forEach(({count:t})=>n+=t),e!==n}(i)&&!e.verbose&&console.warn('MeshBVH: Provided geometry contains groups that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),t._indirectBuffer||ss(i,e);const s=vs(t,e);let n,r,o;const a=[],l=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;for(let t=0;t<s.length;t++){const e=s[t];const i=new l(32*h(e));n=new Float32Array(i),r=new Uint32Array(i),o=new Uint16Array(i),c(0,e),a.push(i)}return void(t._roots=a);function h(t){return t.count?1:1+h(t.left)+h(t.right)}function c(t,e){const i=t/4,s=t/2,a=!!e.count,l=e.boundingData;for(let t=0;t<6;t++)n[i+t]=l[t];if(a){const n=e.offset,a=e.count;return r[i+6]=n,o[s+14]=a,o[s+15]=Ji,t+32}{const s=e.left,n=e.right,o=e.splitAxis;let a;if(a=c(t+32,s),a/4>Math.pow(2,32))throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return r[i+6]=a/4,a=c(a,n),r[i+7]=o,a}}}class xs{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const r=t[n][e];i=r<i?r:i,s=r>s?r:s}this.min=i,this.max=s}setFromPoints(t,e){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const r=e[n],o=t.dot(r);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(t){return this.min>t.max||t.min>this.max}}xs.prototype.setFromBox=function(){const t=new a;return function(e,i){const s=i.min,n=i.max;let r=1/0,o=-1/0;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let l=0;l<=1;l++){t.x=s.x*i+n.x*(1-i),t.y=s.y*a+n.y*(1-a),t.z=s.z*l+n.z*(1-l);const h=e.dot(t);r=Math.min(h,r),o=Math.max(h,o)}this.min=r,this.max=o}}();const Es=function(){const t=new a,e=new a,i=new a;return function(s,n,r){const o=s.start,a=t,l=n.start,h=e;i.subVectors(o,l),t.subVectors(s.end,s.start),e.subVectors(n.end,n.start);const c=i.dot(h),d=h.dot(a),u=h.dot(h),p=i.dot(a),f=a.dot(a)*u-d*d;let m,g;m=0!==f?(c*d-p*u)/f:0,g=(c+m*d)/u,r.x=m,r.y=g}}(),Ts=function(){const t=new c,e=new a,i=new a;return function(s,n,r,o){Es(s,n,t);let a=t.x,l=t.y;if(a>=0&&a<=1&&l>=0&&l<=1)return s.at(a,r),void n.at(l,o);if(a>=0&&a<=1)return l<0?n.at(0,o):n.at(1,o),void s.closestPointToPoint(o,!0,r);if(l>=0&&l<=1)return a<0?s.at(0,r):s.at(1,r),void n.closestPointToPoint(r,!0,o);{let t,h;t=a<0?s.start:s.end,h=l<0?n.start:n.end;const c=e,d=i;return s.closestPointToPoint(h,!0,e),n.closestPointToPoint(t,!0,i),c.distanceToSquared(h)<=d.distanceToSquared(t)?(r.copy(c),void o.copy(h)):(r.copy(t),void o.copy(d))}}}(),Cs=function(){const t=new a,e=new a,i=new l,s=new h;return function(n,r){const{radius:o,center:a}=n,{a:l,b:h,c:c}=r;s.start=l,s.end=h;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;s.start=l,s.end=c;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;s.start=h,s.end=c;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;const d=r.getPlane(i);if(Math.abs(d.distanceToPoint(a))<=o){const t=d.projectPoint(a,e);if(r.containsPoint(t))return!0}return!1}}();function Ss(t){return Math.abs(t)<1e-15}class As extends d{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new a),this.satBounds=new Array(4).fill().map(()=>new xs),this.points=[this.a,this.b,this.c],this.sphere=new u,this.plane=new l,this.needsUpdate=!0}intersectsSphere(t){return Cs(t,this)}update(){const t=this.a,e=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,o=n[0],a=r[0];this.getNormal(o),a.setFromPoints(o,s);const l=n[1],h=r[1];l.subVectors(t,e),h.setFromPoints(l,s);const c=n[2],d=r[2];c.subVectors(e,i),d.setFromPoints(c,s);const u=n[3],p=r[3];u.subVectors(i,t),p.setFromPoints(u,s),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}As.prototype.closestPointToSegment=function(){const t=new a,e=new a,i=new h;return function(s,n=null,r=null){const{start:o,end:a}=s,l=this.points;let h,c=1/0;for(let o=0;o<3;o++){const a=(o+1)%3;i.start.copy(l[o]),i.end.copy(l[a]),Ts(i,s,t,e),h=t.distanceToSquared(e),h<c&&(c=h,n&&n.copy(t),r&&r.copy(e))}return this.closestPointToPoint(o,t),h=o.distanceToSquared(t),h<c&&(c=h,n&&n.copy(t),r&&r.copy(o)),this.closestPointToPoint(a,t),h=a.distanceToSquared(t),h<c&&(c=h,n&&n.copy(t),r&&r.copy(a)),Math.sqrt(c)}}(),As.prototype.intersectsTriangle=function(){const t=new As,e=new Array(3),i=new Array(3),s=new xs,n=new xs,r=new a,o=new a,l=new a,c=new a,d=new a,u=new h,p=new h,f=new h,m=new a;function g(t,e,i){const s=t.points;let n=0,r=-1;for(let t=0;t<3;t++){const{start:a,end:l}=u;a.copy(s[t]),l.copy(s[(t+1)%3]),u.delta(o);const h=Ss(e.distanceToPoint(a));if(Ss(e.normal.dot(o))&&h){i.copy(u),n=2;break}const c=e.intersectLine(u,m);if(!c&&h&&m.copy(a),(c||h)&&!Ss(m.distanceTo(l))){if(n<=1){(1===n?i.start:i.end).copy(m),h&&(r=n)}else if(n>=2){(1===r?i.start:i.end).copy(m),n=2;break}if(n++,2===n&&-1===r)break}}return n}return function(o,a=null,h=!1){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(t.copy(o),t.update(),o=t);const u=this.plane,m=o.plane;if(Math.abs(u.normal.dot(m.normal))>1-1e-10){const t=this.satBounds,l=this.satAxes;i[0]=o.a,i[1]=o.b,i[2]=o.c;for(let e=0;e<4;e++){const n=t[e],r=l[e];if(s.setFromPoints(r,i),n.isSeparated(s))return!1}const c=o.satBounds,d=o.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let t=0;t<4;t++){const i=c[t],n=d[t];if(s.setFromPoints(n,e),i.isSeparated(s))return!1}for(let t=0;t<4;t++){const o=l[t];for(let t=0;t<4;t++){const a=d[t];if(r.crossVectors(o,a),s.setFromPoints(r,e),n.setFromPoints(r,i),s.isSeparated(n))return!1}}return a&&(h||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),a.start.set(0,0,0),a.end.set(0,0,0)),!0}{const t=g(this,m,p);if(1===t&&o.containsPoint(p.end))return a&&(a.start.copy(p.end),a.end.copy(p.end)),!0;if(2!==t)return!1;const e=g(o,u,f);if(1===e&&this.containsPoint(f.end))return a&&(a.start.copy(f.end),a.end.copy(f.end)),!0;if(2!==e)return!1;if(p.delta(l),f.delta(c),l.dot(c)<0){let t=f.start;f.start=f.end,f.end=t}const i=p.start.dot(l),s=p.end.dot(l),n=f.start.dot(l),r=f.end.dot(l);return(i===r||n===s||s<n!==i<r)&&(a&&(d.subVectors(p.start,f.start),d.dot(l)>0?a.start.copy(p.start):a.start.copy(f.start),d.subVectors(p.end,f.end),d.dot(l)<0?a.end.copy(p.end):a.end.copy(f.end)),!0)}}}(),As.prototype.distanceToPoint=function(){const t=new a;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),As.prototype.distanceToTriangle=function(){const t=new a,e=new a,i=["a","b","c"],s=new h,n=new h;return function(r,o=null,a=null){const l=o||a?s:null;if(this.intersectsTriangle(r,l))return(o||a)&&(o&&l.getCenter(o),a&&l.getCenter(a)),0;let h=1/0;for(let e=0;e<3;e++){let s;const n=i[e],l=r[n];this.closestPointToPoint(l,t),s=l.distanceToSquared(t),s<h&&(h=s,o&&o.copy(t),a&&a.copy(l));const c=this[n];r.closestPointToPoint(c,t),s=c.distanceToSquared(t),s<h&&(h=s,o&&o.copy(c),a&&a.copy(t))}for(let l=0;l<3;l++){const c=i[l],d=i[(l+1)%3];s.set(this[c],this[d]);for(let l=0;l<3;l++){const c=i[l],d=i[(l+1)%3];n.set(r[c],r[d]),Ts(s,n,t,e);const u=t.distanceToSquared(e);u<h&&(h=u,o&&o.copy(t),a&&a.copy(e))}}return Math.sqrt(h)}}();class Os{constructor(t,e,i){this.isOrientedBox=!0,this.min=new a,this.max=new a,this.matrix=new p,this.invMatrix=new p,this.points=new Array(8).fill().map(()=>new a),this.satAxes=new Array(3).fill().map(()=>new a),this.satBounds=new Array(3).fill().map(()=>new xs),this.alignedSatBounds=new Array(3).fill().map(()=>new xs),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Os.prototype.update=function(){return function(){const t=this.matrix,e=this.min,i=this.max,s=this.points;for(let n=0;n<=1;n++)for(let r=0;r<=1;r++)for(let o=0;o<=1;o++){const a=s[1*n|2*r|4*o];a.x=n?i.x:e.x,a.y=r?i.y:e.y,a.z=o?i.z:e.z,a.applyMatrix4(t)}const n=this.satBounds,r=this.satAxes,o=s[0];for(let t=0;t<3;t++){const e=r[t],i=n[t],a=s[1<<t];e.subVectors(o,a),i.setFromPoints(e,s)}const a=this.alignedSatBounds;a[0].setFromPointsField(s,"x"),a[1].setFromPointsField(s,"y"),a[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),Os.prototype.intersectsBox=function(){const t=new xs;return function(e){this.needsUpdate&&this.update();const i=e.min,s=e.max,n=this.satBounds,r=this.satAxes,o=this.alignedSatBounds;if(t.min=i.x,t.max=s.x,o[0].isSeparated(t))return!1;if(t.min=i.y,t.max=s.y,o[1].isSeparated(t))return!1;if(t.min=i.z,t.max=s.z,o[2].isSeparated(t))return!1;for(let i=0;i<3;i++){const s=r[i],o=n[i];if(t.setFromBox(s,e),o.isSeparated(t))return!1}return!0}}(),Os.prototype.intersectsTriangle=function(){const t=new As,e=new Array(3),i=new xs,s=new xs,n=new a;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(t.copy(r),t.update(),r=t);const o=this.satBounds,a=this.satAxes;e[0]=r.a,e[1]=r.b,e[2]=r.c;for(let t=0;t<3;t++){const s=o[t],n=a[t];if(i.setFromPoints(n,e),s.isSeparated(i))return!1}const l=r.satBounds,h=r.satAxes,c=this.points;for(let t=0;t<3;t++){const e=l[t],s=h[t];if(i.setFromPoints(s,c),e.isSeparated(i))return!1}for(let t=0;t<3;t++){const r=a[t];for(let t=0;t<4;t++){const o=h[t];if(n.crossVectors(r,o),i.setFromPoints(n,e),s.setFromPoints(n,c),i.isSeparated(s))return!1}}return!0}}(),Os.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),Os.prototype.distanceToPoint=function(){const t=new a;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),Os.prototype.distanceToBox=function(){const t=["x","y","z"],e=new Array(12).fill().map(()=>new h),i=new Array(12).fill().map(()=>new h),s=new a,n=new a;return function(r,o=0,a=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(a||l)&&(r.getCenter(n),this.closestPointToPoint(n,s),r.closestPointToPoint(s,n),a&&a.copy(s),l&&l.copy(n)),0;const h=o*o,c=r.min,d=r.max,u=this.points;let p=1/0;for(let t=0;t<8;t++){const e=u[t];n.copy(e).clamp(c,d);const i=e.distanceToSquared(n);if(i<p&&(p=i,a&&a.copy(e),l&&l.copy(n),i<h))return Math.sqrt(i)}let f=0;for(let s=0;s<3;s++)for(let n=0;n<=1;n++)for(let r=0;r<=1;r++){const o=(s+1)%3,a=(s+2)%3,l=1<<s|n<<o|r<<a,h=u[n<<o|r<<a],p=u[l];e[f].set(h,p);const m=t[s],g=t[o],_=t[a],y=i[f],w=y.start,v=y.end;w[m]=c[m],w[g]=n?c[g]:d[g],w[_]=r?c[_]:d[g],v[m]=d[m],v[g]=n?c[g]:d[g],v[_]=r?c[_]:d[g],f++}for(let t=0;t<=1;t++)for(let e=0;e<=1;e++)for(let i=0;i<=1;i++){n.x=t?d.x:c.x,n.y=e?d.y:c.y,n.z=i?d.z:c.z,this.closestPointToPoint(n,s);const r=n.distanceToSquared(s);if(r<p&&(p=r,a&&a.copy(s),l&&l.copy(n),r<h))return Math.sqrt(r)}for(let t=0;t<12;t++){const r=e[t];for(let t=0;t<12;t++){const e=i[t];Ts(r,e,s,n);const o=s.distanceToSquared(n);if(o<p&&(p=o,a&&a.copy(s),l&&l.copy(n),o<h))return Math.sqrt(o)}}return Math.sqrt(p)}}();class Ps{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return 0===t.length?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Is extends Ps{constructor(){super(()=>new As)}}const ks=new Is;function Ds(t,e){return 65535===e[t+15]}function zs(t,e){return e[t+6]}function Ms(t,e){return e[t+14]}function Bs(t){return t+8}function Ns(t,e){return e[t+6]}function Us(t,e){return e[t+7]}function Ls(t){return t}const Rs=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==t.length&&this.setBuffer(t.pop())}}};let Fs,Vs;const js=[],Zs=new Ps(()=>new f);function Hs(t,e,i,s,n,r){Fs=Zs.getPrimitive(),Vs=Zs.getPrimitive(),js.push(Fs,Vs),Rs.setBuffer(t._roots[e]);const o=$s(0,t.geometry,i,s,n,r);Rs.clearBuffer(),Zs.releasePrimitive(Fs),Zs.releasePrimitive(Vs),js.pop(),js.pop();const a=js.length;return a>0&&(Vs=js[a-1],Fs=js[a-2]),o}function $s(t,e,i,s,n=null,r=0,o=0){const{float32Array:a,uint16Array:l,uint32Array:h}=Rs;let c=2*t;if(Ds(c,l)){const e=zs(t,h),i=Ms(c,l);return os(t,a,Fs),s(e,i,!1,o,r+t,Fs)}{let c=function(t){const{uint16Array:e,uint32Array:i}=Rs;let s=2*t;for(;!Ds(s,e);)s=2*(t=Bs(t));return zs(t,i)},d=function(t){const{uint16Array:e,uint32Array:i}=Rs;let s=2*t;for(;!Ds(s,e);)s=2*(t=Ns(t,i));return zs(t,i)+Ms(s,e)};const u=Bs(t),p=Ns(t,h);let f,m,g,_,y=u,w=p;if(n&&(g=Fs,_=Vs,os(y,a,g),os(w,a,_),f=n(g),m=n(_),m<f)){y=p,w=u;const t=f;f=m,m=t,g=_}g||(g=Fs,os(y,a,g));const v=i(g,Ds(2*y,l),f,o+1,r+y);let b;if(2===v){const t=c(y);b=s(t,d(y)-t,!0,o+1,r+y,g)}else b=v&&$s(y,e,i,s,n,r,o+1);if(b)return!0;_=Vs,os(w,a,_);const x=i(_,Ds(2*w,l),m,o+1,r+w);let E;if(2===x){const t=c(w);E=s(t,d(w)-t,!0,o+1,r+w,_)}else E=x&&$s(w,e,i,s,n,r,o+1);return!!E}}const Ws=new a,Ys=new a;const Xs=new a,qs=new a,Gs=new a,Qs=new c,Ks=new c,Js=new c,tn=new a,en=new a,sn=new a,nn=new a;function rn(t,e,i,s,n,r,o,l,h){Xs.fromBufferAttribute(e,r),qs.fromBufferAttribute(e,o),Gs.fromBufferAttribute(e,l);const u=function(t,e,i,s,n,r){let o;return o=r===m?t.intersectTriangle(s,i,e,!0,n):t.intersectTriangle(e,i,s,r!==g,n),null===o?null:{distance:t.origin.distanceTo(n),point:n.clone()}}(t,Xs,qs,Gs,nn,h);if(u){s&&(Qs.fromBufferAttribute(s,r),Ks.fromBufferAttribute(s,o),Js.fromBufferAttribute(s,l),u.uv=d.getInterpolation(nn,Xs,qs,Gs,Qs,Ks,Js,new c)),n&&(Qs.fromBufferAttribute(n,r),Ks.fromBufferAttribute(n,o),Js.fromBufferAttribute(n,l),u.uv1=d.getInterpolation(nn,Xs,qs,Gs,Qs,Ks,Js,new c)),i&&(tn.fromBufferAttribute(i,r),en.fromBufferAttribute(i,o),sn.fromBufferAttribute(i,l),u.normal=d.getInterpolation(nn,Xs,qs,Gs,tn,en,sn,new a),u.normal.dot(t.direction)>0&&u.normal.multiplyScalar(-1));const e={a:r,b:o,c:l,normal:new a,materialIndex:0};d.getNormal(Xs,qs,Gs,e.normal),u.face=e,u.faceIndex=r}return u}function on(t,e,i,s,n){const r=3*s;let o=r+0,a=r+1,l=r+2;const h=t.index;t.index&&(o=h.getX(o),a=h.getX(a),l=h.getX(l));const{position:c,normal:d,uv:u,uv1:p}=t.attributes,f=rn(i,c,d,u,p,o,a,l,e);return f?(f.faceIndex=s,n&&n.push(f),f):null}function an(t,e,i,s){const n=t.a,r=t.b,o=t.c;let a=e,l=e+1,h=e+2;i&&(a=i.getX(a),l=i.getX(l),h=i.getX(h)),n.x=s.getX(a),n.y=s.getY(a),n.z=s.getZ(a),r.x=s.getX(l),r.y=s.getY(l),r.z=s.getZ(l),o.x=s.getX(h),o.y=s.getY(h),o.z=s.getZ(h)}function ln(t,e,i,s,n,r,o){const{geometry:a}=i,{index:l}=a,h=a.attributes.position;for(let i=t,a=e+t;i<a;i++){let t;if(t=i,an(o,3*t,l,h),o.needsUpdate=!0,s(o,t,n,r))return!0}return!1}function hn(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const i=t.geometry,s=i.index?i.index.array:null,n=i.attributes.position;let r,o,a,l,h=0;const c=t._roots;for(let t=0,e=c.length;t<e;t++)r=c[t],o=new Uint32Array(r),a=new Uint16Array(r),l=new Float32Array(r),d(0,h),h+=r.byteLength;function d(t,i,r=!1){const h=2*t;if(a[h+15]===Ji){const e=o[t+6];let i=1/0,r=1/0,c=1/0,d=-1/0,u=-1/0,p=-1/0;for(let t=3*e,o=3*(e+a[h+14]);t<o;t++){let e=s[t];const o=n.getX(e),a=n.getY(e),l=n.getZ(e);o<i&&(i=o),o>d&&(d=o),a<r&&(r=a),a>u&&(u=a),l<c&&(c=l),l>p&&(p=l)}return(l[t+0]!==i||l[t+1]!==r||l[t+2]!==c||l[t+3]!==d||l[t+4]!==u||l[t+5]!==p)&&(l[t+0]=i,l[t+1]=r,l[t+2]=c,l[t+3]=d,l[t+4]=u,l[t+5]=p,!0)}{const s=t+8,n=o[t+6],a=s+i,h=n+i;let c=r,u=!1,p=!1;e?c||(u=e.has(a),p=e.has(h),c=!u&&!p):(u=!0,p=!0);const f=c||p;let m=!1;(c||u)&&(m=d(s,i,c));let g=!1;f&&(g=d(n,i,c));const _=m||g;if(_)for(let e=0;e<3;e++){const i=s+e,r=n+e,o=l[i],a=l[i+3],h=l[r],c=l[r+3];l[t+e]=o<h?o:h,l[t+e+3]=a>c?a:c}return _}}}const cn=new f;function dn(t,e,i,s){return os(t,e,cn),i.intersectBox(cn,s)}function un(t,e,i,s,n,r,o){const{geometry:a}=i,{index:l}=a,h=a.attributes.position;for(let a=t,c=e+t;a<c;a++){let t;if(t=i.resolveTriangleIndex(a),an(o,3*t,l,h),o.needsUpdate=!0,s(o,t,n,r))return!0}return!1}const pn=new a;function fn(t,e,i,s,n){Rs.setBuffer(t._roots[e]),mn(0,t,i,s,n),Rs.clearBuffer()}function mn(t,e,i,s,n){const{float32Array:r,uint16Array:o,uint32Array:a}=Rs,l=2*t;if(Ds(l,o)){!function(t,e,i,s,n,r){const{geometry:o,_indirectBuffer:a}=t;for(let t=s,a=s+n;t<a;t++)on(o,e,i,t,r)}(e,i,s,zs(t,a),Ms(l,o),n)}else{const o=Bs(t);dn(o,r,s,pn)&&mn(o,e,i,s,n);const l=Ns(t,a);dn(l,r,s,pn)&&mn(l,e,i,s,n)}}const gn=new a,_n=["x","y","z"];function yn(t,e,i,s){Rs.setBuffer(t._roots[e]);const n=wn(0,t,i,s);return Rs.clearBuffer(),n}function wn(t,e,i,s){const{float32Array:n,uint16Array:r,uint32Array:o}=Rs;let a=2*t;if(Ds(a,r)){return function(t,e,i,s,n){const{geometry:r,_indirectBuffer:o}=t;let a=1/0,l=null;for(let t=s,o=s+n;t<o;t++){let s;s=on(r,e,i,t),s&&s.distance<a&&(l=s,a=s.distance)}return l}(e,i,s,zs(t,o),Ms(a,r))}{const r=Us(t,o),a=_n[r],l=s.direction[a]>=0;let h,c;l?(h=Bs(t),c=Ns(t,o)):(h=Ns(t,o),c=Bs(t));const d=dn(h,n,s,gn)?wn(h,e,i,s):null;if(d){const t=d.point[a];if(l?t<=n[c+r]:t>=n[c+r+3])return d}const u=dn(c,n,s,gn)?wn(c,e,i,s):null;return d&&u?d.distance<=u.distance?d:u:d||u||null}}const vn=new f,bn=new As,xn=new As,En=new p,Tn=new Os,Cn=new Os;function Sn(t,e,i,s){Rs.setBuffer(t._roots[e]);const n=An(0,t,i,s);return Rs.clearBuffer(),n}function An(t,e,i,s,n=null){const{float32Array:r,uint16Array:o,uint32Array:a}=Rs;let l=2*t;null===n&&(i.boundingBox||i.computeBoundingBox(),Tn.set(i.boundingBox.min,i.boundingBox.max,s),n=Tn);if(!Ds(l,o)){const o=t+8,l=a[t+6];os(o,r,vn);if(n.intersectsBox(vn)&&An(o,e,i,s,n))return!0;os(l,r,vn);return!!(n.intersectsBox(vn)&&An(l,e,i,s,n))}{const n=e.geometry,h=n.index,c=n.attributes.position,d=i.index,u=i.attributes.position,p=zs(t,a),f=Ms(l,o);if(En.copy(s).invert(),i.boundsTree){os(t,r,Cn),Cn.matrix.copy(En),Cn.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:t=>Cn.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(s),t.b.applyMatrix4(s),t.c.applyMatrix4(s),t.needsUpdate=!0;for(let e=3*p,i=3*(f+p);e<i;e+=3)if(an(xn,e,h,c),xn.needsUpdate=!0,t.intersectsTriangle(xn))return!0;return!1}})}for(let t=3*p,e=3*(f+p);t<e;t+=3){an(bn,t,h,c),bn.a.applyMatrix4(En),bn.b.applyMatrix4(En),bn.c.applyMatrix4(En),bn.needsUpdate=!0;for(let t=0,e=d.count;t<e;t+=3)if(an(xn,t,d,u),xn.needsUpdate=!0,bn.intersectsTriangle(xn))return!0}}}const On=new p,Pn=new Os,In=new Os,kn=new a,Dn=new a,zn=new a,Mn=new a;function Bn(t,e,i,s={},n={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Pn.set(e.boundingBox.min,e.boundingBox.max,i),Pn.needsUpdate=!0;const a=t.geometry,l=a.attributes.position,h=a.index,c=e.attributes.position,d=e.index,u=ks.getPrimitive(),p=ks.getPrimitive();let f=kn,m=Dn,g=null,_=null;n&&(g=zn,_=Mn);let y=1/0,w=null,v=null;return On.copy(i).invert(),In.matrix.copy(On),t.shapecast({boundsTraverseOrder:t=>Pn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o&&(e&&(In.min.copy(t.min),In.max.copy(t.max),In.needsUpdate=!0),!0),intersectsRange:(t,s)=>{if(e.boundsTree){return e.boundsTree.shapecast({boundsTraverseOrder:t=>In.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o,intersectsRange:(e,n)=>{for(let o=e,a=e+n;o<a;o++){an(p,3*o,d,c),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=t,i=t+s;e<i;e++){an(u,3*e,h,l),u.needsUpdate=!0;const t=u.distanceToTriangle(p,f,g);if(t<y&&(m.copy(f),_&&_.copy(g),y=t,w=e,v=o),t<r)return!0}}}})}for(let n=0,o=is(e);n<o;n++){an(p,3*n,d,c),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=t,i=t+s;e<i;e++){an(u,3*e,h,l),u.needsUpdate=!0;const t=u.distanceToTriangle(p,f,g);if(t<y&&(m.copy(f),_&&_.copy(g),y=t,w=e,v=n),t<r)return!0}}}}),ks.releasePrimitive(u),ks.releasePrimitive(p),y===1/0?null:(s.point?s.point.copy(m):s.point=m.clone(),s.distance=y,s.faceIndex=w,n&&(n.point?n.point.copy(_):n.point=_.clone(),n.point.applyMatrix4(On),m.applyMatrix4(On),n.distance=m.sub(n.point).length(),n.faceIndex=v),s)}function Nn(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const i=t.geometry,s=i.index?i.index.array:null,n=i.attributes.position;let r,o,a,l,h=0;const c=t._roots;for(let t=0,e=c.length;t<e;t++)r=c[t],o=new Uint32Array(r),a=new Uint16Array(r),l=new Float32Array(r),d(0,h),h+=r.byteLength;function d(i,r,h=!1){const c=2*i;if(a[c+15]===Ji){const e=o[i+6];let r=1/0,h=1/0,d=1/0,u=-1/0,p=-1/0,f=-1/0;for(let i=e,o=e+a[c+14];i<o;i++){const e=3*t.resolveTriangleIndex(i);for(let t=0;t<3;t++){let i=e+t;i=s?s[i]:i;const o=n.getX(i),a=n.getY(i),l=n.getZ(i);o<r&&(r=o),o>u&&(u=o),a<h&&(h=a),a>p&&(p=a),l<d&&(d=l),l>f&&(f=l)}}return(l[i+0]!==r||l[i+1]!==h||l[i+2]!==d||l[i+3]!==u||l[i+4]!==p||l[i+5]!==f)&&(l[i+0]=r,l[i+1]=h,l[i+2]=d,l[i+3]=u,l[i+4]=p,l[i+5]=f,!0)}{const t=i+8,s=o[i+6],n=t+r,a=s+r;let c=h,u=!1,p=!1;e?c||(u=e.has(n),p=e.has(a),c=!u&&!p):(u=!0,p=!0);const f=c||p;let m=!1;(c||u)&&(m=d(t,r,c));let g=!1;f&&(g=d(s,r,c));const _=m||g;if(_)for(let e=0;e<3;e++){const n=t+e,r=s+e,o=l[n],a=l[n+3],h=l[r],c=l[r+3];l[i+e]=o<h?o:h,l[i+e+3]=a>c?a:c}return _}}}const Un=new a;function Ln(t,e,i,s,n){Rs.setBuffer(t._roots[e]),Rn(0,t,i,s,n),Rs.clearBuffer()}function Rn(t,e,i,s,n){const{float32Array:r,uint16Array:o,uint32Array:a}=Rs,l=2*t;if(Ds(l,o)){!function(t,e,i,s,n,r){const{geometry:o,_indirectBuffer:a}=t;for(let t=s,l=s+n;t<l;t++)on(o,e,i,a?a[t]:t,r)}(e,i,s,zs(t,a),Ms(l,o),n)}else{const o=Bs(t);dn(o,r,s,Un)&&Rn(o,e,i,s,n);const l=Ns(t,a);dn(l,r,s,Un)&&Rn(l,e,i,s,n)}}const Fn=new a,Vn=["x","y","z"];function jn(t,e,i,s){Rs.setBuffer(t._roots[e]);const n=Zn(0,t,i,s);return Rs.clearBuffer(),n}function Zn(t,e,i,s){const{float32Array:n,uint16Array:r,uint32Array:o}=Rs;let a=2*t;if(Ds(a,r)){return function(t,e,i,s,n){const{geometry:r,_indirectBuffer:o}=t;let a=1/0,l=null;for(let t=s,h=s+n;t<h;t++){let s;s=on(r,e,i,o?o[t]:t),s&&s.distance<a&&(l=s,a=s.distance)}return l}(e,i,s,zs(t,o),Ms(a,r))}{const r=Us(t,o),a=Vn[r],l=s.direction[a]>=0;let h,c;l?(h=Bs(t),c=Ns(t,o)):(h=Ns(t,o),c=Bs(t));const d=dn(h,n,s,Fn)?Zn(h,e,i,s):null;if(d){const t=d.point[a];if(l?t<=n[c+r]:t>=n[c+r+3])return d}const u=dn(c,n,s,Fn)?Zn(c,e,i,s):null;return d&&u?d.distance<=u.distance?d:u:d||u||null}}const Hn=new f,$n=new As,Wn=new As,Yn=new p,Xn=new Os,qn=new Os;function Gn(t,e,i,s){Rs.setBuffer(t._roots[e]);const n=Qn(0,t,i,s);return Rs.clearBuffer(),n}function Qn(t,e,i,s,n=null){const{float32Array:r,uint16Array:o,uint32Array:a}=Rs;let l=2*t;null===n&&(i.boundingBox||i.computeBoundingBox(),Xn.set(i.boundingBox.min,i.boundingBox.max,s),n=Xn);if(!Ds(l,o)){const o=t+8,l=a[t+6];os(o,r,Hn);if(n.intersectsBox(Hn)&&Qn(o,e,i,s,n))return!0;os(l,r,Hn);return!!(n.intersectsBox(Hn)&&Qn(l,e,i,s,n))}{const n=e.geometry,h=n.index,c=n.attributes.position,d=i.index,u=i.attributes.position,p=zs(t,a),f=Ms(l,o);if(Yn.copy(s).invert(),i.boundsTree){os(t,r,qn),qn.matrix.copy(Yn),qn.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:t=>qn.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(s),t.b.applyMatrix4(s),t.c.applyMatrix4(s),t.needsUpdate=!0;for(let i=p,s=f+p;i<s;i++)if(an(Wn,3*e.resolveTriangleIndex(i),h,c),Wn.needsUpdate=!0,t.intersectsTriangle(Wn))return!0;return!1}})}for(let t=p,i=f+p;t<i;t++){const i=e.resolveTriangleIndex(t);an($n,3*i,h,c),$n.a.applyMatrix4(Yn),$n.b.applyMatrix4(Yn),$n.c.applyMatrix4(Yn),$n.needsUpdate=!0;for(let t=0,e=d.count;t<e;t+=3)if(an(Wn,t,d,u),Wn.needsUpdate=!0,$n.intersectsTriangle(Wn))return!0}}}const Kn=new p,Jn=new Os,tr=new Os,er=new a,ir=new a,sr=new a,nr=new a;function rr(t,e,i,s={},n={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Jn.set(e.boundingBox.min,e.boundingBox.max,i),Jn.needsUpdate=!0;const a=t.geometry,l=a.attributes.position,h=a.index,c=e.attributes.position,d=e.index,u=ks.getPrimitive(),p=ks.getPrimitive();let f=er,m=ir,g=null,_=null;n&&(g=sr,_=nr);let y=1/0,w=null,v=null;return Kn.copy(i).invert(),tr.matrix.copy(Kn),t.shapecast({boundsTraverseOrder:t=>Jn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o&&(e&&(tr.min.copy(t.min),tr.max.copy(t.max),tr.needsUpdate=!0),!0),intersectsRange:(s,n)=>{if(e.boundsTree){const a=e.boundsTree;return a.shapecast({boundsTraverseOrder:t=>tr.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o,intersectsRange:(e,o)=>{for(let b=e,x=e+o;b<x;b++){const e=a.resolveTriangleIndex(b);an(p,3*e,d,c),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=s,i=s+n;e<i;e++){const i=t.resolveTriangleIndex(e);an(u,3*i,h,l),u.needsUpdate=!0;const s=u.distanceToTriangle(p,f,g);if(s<y&&(m.copy(f),_&&_.copy(g),y=s,w=e,v=b),s<r)return!0}}}})}for(let o=0,a=is(e);o<a;o++){an(p,3*o,d,c),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=s,i=s+n;e<i;e++){const i=t.resolveTriangleIndex(e);an(u,3*i,h,l),u.needsUpdate=!0;const s=u.distanceToTriangle(p,f,g);if(s<y&&(m.copy(f),_&&_.copy(g),y=s,w=e,v=o),s<r)return!0}}}}),ks.releasePrimitive(u),ks.releasePrimitive(p),y===1/0?null:(s.point?s.point.copy(m):s.point=m.clone(),s.distance=y,s.faceIndex=w,n&&(n.point?n.point.copy(_):n.point=_.clone(),n.point.applyMatrix4(Kn),m.applyMatrix4(Kn),n.distance=m.sub(n.point).length(),n.faceIndex=v),s)}const or=new Rs.constructor,ar=new Rs.constructor,lr=new Ps(()=>new f),hr=new f,cr=new f,dr=new f,ur=new f;let pr=!1;function fr(t,e,i,s,n,r=0,o=0,a=0,l=0,h=null,c=!1){let d,u;c?(d=ar,u=or):(d=or,u=ar);const p=d.float32Array,f=d.uint32Array,m=d.uint16Array,g=u.float32Array,_=u.uint32Array,y=u.uint16Array,w=2*e,v=Ds(2*t,m),b=Ds(w,y);let x=!1;if(b&&v)x=c?n(zs(e,_),Ms(2*e,y),zs(t,f),Ms(2*t,m),l,o+e,a,r+t):n(zs(t,f),Ms(2*t,m),zs(e,_),Ms(2*e,y),a,r+t,l,o+e);else if(b){const h=lr.getPrimitive();os(e,g,h),h.applyMatrix4(i);const d=Bs(t),u=Ns(t,f);os(d,p,hr),os(u,p,cr);const m=h.intersectsBox(hr),_=h.intersectsBox(cr);x=m&&fr(e,d,s,i,n,o,r,l,a+1,h,!c)||_&&fr(e,u,s,i,n,o,r,l,a+1,h,!c),lr.releasePrimitive(h)}else{const d=Bs(e),u=Ns(e,_);os(d,g,dr),os(u,g,ur);const m=h.intersectsBox(dr),y=h.intersectsBox(ur);if(m&&y)x=fr(t,d,i,s,n,r,o,a,l+1,h,c)||fr(t,u,i,s,n,r,o,a,l+1,h,c);else if(m)if(v)x=fr(t,d,i,s,n,r,o,a,l+1,h,c);else{const e=lr.getPrimitive();e.copy(dr).applyMatrix4(i);const h=Bs(t),u=Ns(t,f);os(h,p,hr),os(u,p,cr);const m=e.intersectsBox(hr),g=e.intersectsBox(cr);x=m&&fr(d,h,s,i,n,o,r,l,a+1,e,!c)||g&&fr(d,u,s,i,n,o,r,l,a+1,e,!c),lr.releasePrimitive(e)}else if(y)if(v)x=fr(t,u,i,s,n,r,o,a,l+1,h,c);else{const e=lr.getPrimitive();e.copy(ur).applyMatrix4(i);const h=Bs(t),d=Ns(t,f);os(h,p,hr),os(d,p,cr);const m=e.intersectsBox(hr),g=e.intersectsBox(cr);x=m&&fr(u,h,s,i,n,o,r,l,a+1,e,!c)||g&&fr(u,d,s,i,n,o,r,l,a+1,e,!c),lr.releasePrimitive(e)}}return x}const mr=new Os,gr=new f;class _r{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,s=t._roots,n=t._indirectBuffer,r=i.getIndex();let o;return o=e.cloneBuffers?{roots:s.map(t=>t.slice()),index:r.array.slice(),indirectBuffer:n?n.slice():null}:{roots:s,index:r.array,indirectBuffer:n},o}static deserialize(t,e,i={}){i={setIndex:!0,indirect:Boolean(t.indirectBuffer),...i};const{index:s,roots:n,indirectBuffer:r}=t,a=new _r(e,{...i,[es]:!0});if(a._roots=n,a._indirectBuffer=r||null,i.setIndex){const i=e.getIndex();if(null===i){const i=new o(t.index,1,!1);e.setIndex(i)}else i.array!==s&&(i.array.set(s),i.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(!t.isBufferGeometry)throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.");if((e=Object.assign({strategy:0,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[es]:!1},e)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[es]||(bs(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new f)));const{_indirectBuffer:i}=this;this.resolveTriangleIndex=e.indirect?t=>i[t]:t=>t}refit(t=null){return(this.indirect?Nn:hn)(this,t)}traverse(t,e=0){const i=this._roots[e],s=new Uint32Array(i),n=new Uint16Array(i);!function e(r,o=0){const a=2*r,l=n[a+15]===Ji;if(l){const e=s[r+6],h=n[a+14];t(o,l,new Float32Array(i,4*r,6),e,h)}else{const n=r+8,a=s[r+6],h=s[r+7];t(o,l,new Float32Array(i,4*r,6),h)||(e(n,o+1),e(a,o+1))}}(0)}raycast(t,e=_){const i=this._roots,s=this.geometry,n=[],r=e.isMaterial,o=Array.isArray(e),a=s.groups,l=r?e.side:e,h=this.indirect?Ln:fn;for(let s=0,r=i.length;s<r;s++){const i=o?e[a[s].materialIndex].side:l,r=n.length;if(h(this,s,i,t,n),o){const t=a[s].materialIndex;for(let e=r,i=n.length;e<i;e++)n[e].face.materialIndex=t}}return n}raycastFirst(t,e=_){const i=this._roots,s=this.geometry,n=e.isMaterial,r=Array.isArray(e);let o=null;const a=s.groups,l=n?e.side:e,h=this.indirect?jn:yn;for(let s=0,n=i.length;s<n;s++){const i=h(this,s,r?e[a[s].materialIndex].side:l,t);null!=i&&(null==o||i.distance<o.distance)&&(o=i,r&&(i.face.materialIndex=a[s].materialIndex))}return o}intersectsGeometry(t,e){let i=!1;const s=this._roots,n=this.indirect?Gn:Sn;for(let r=0,o=s.length;r<o&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=ks.getPrimitive(),i=this.indirect?un:ln;let{boundsTraverseOrder:s,intersectsBounds:n,intersectsRange:r,intersectsTriangle:o}=t;if(r&&o){const t=r;r=(s,n,r,a,l)=>!!t(s,n,r,a,l)||i(s,n,this,o,r,a,e)}else r||(r=o?(t,s,n,r)=>i(t,s,this,o,n,r,e):(t,e,i)=>i);let a=!1,l=0;const h=this._roots;for(let t=0,e=h.length;t<e;t++){const e=h[t];if(a=Hs(this,t,n,r,s,l),a)break;l+=e.byteLength}return ks.releasePrimitive(e),a}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=ks.getPrimitive(),o=this.geometry.index,a=this.geometry.attributes.position,l=this.indirect?t=>{const e=this.resolveTriangleIndex(t);an(r,3*e,o,a)}:t=>{an(r,3*t,o,a)},h=ks.getPrimitive(),c=t.geometry.index,d=t.geometry.attributes.position,u=t.indirect?e=>{const i=t.resolveTriangleIndex(e);an(h,3*i,c,d)}:t=>{an(h,3*t,c,d)};if(n){const t=(t,i,s,o,a,c,d,p)=>{for(let f=s,m=s+o;f<m;f++){u(f),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let e=t,s=t+i;e<s;e++)if(l(e),r.needsUpdate=!0,n(r,h,e,f,a,c,d,p))return!0}return!1};if(s){const e=s;s=function(i,s,n,r,o,a,l,h){return!!e(i,s,n,r,o,a,l,h)||t(i,s,n,r,o,a,l,h)}}else s=t}return function(t,e,i,s){if(pr)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");pr=!0;const n=t._roots,r=e._roots;let o,a=0,l=0;const h=(new p).copy(i).invert();for(let t=0,e=n.length;t<e;t++){or.setBuffer(n[t]),l=0;const e=lr.getPrimitive();os(Ls(0),or.float32Array,e),e.applyMatrix4(h);for(let n=0,c=r.length;n<c&&(ar.setBuffer(r[t]),o=fr(0,0,i,h,s,a,l,0,0,e),ar.clearBuffer(),l+=r[n].length,!o);n++);if(lr.releasePrimitive(e),or.clearBuffer(),a+=n[t].length,o)break}return pr=!1,o}(this,t,e,s)}intersectsBox(t,e){return mr.set(t.min,t.max,e),mr.needsUpdate=!0,this.shapecast({intersectsBounds:t=>mr.intersectsBox(t),intersectsTriangle:t=>mr.intersectsTriangle(t)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},s={},n=0,r=1/0){return(this.indirect?rr:Bn)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return function(t,e,i={},s=0,n=1/0){const r=s*s,o=n*n;let a=1/0,l=null;if(t.shapecast({boundsTraverseOrder:t=>(Ws.copy(e).clamp(t.min,t.max),Ws.distanceToSquared(e)),intersectsBounds:(t,e,i)=>i<a&&i<o,intersectsTriangle:(t,i)=>{t.closestPointToPoint(e,Ws);const s=e.distanceToSquared(Ws);return s<a&&(Ys.copy(Ws),a=s,l=i),s<r}}),a===1/0)return null;const h=Math.sqrt(a);return i.point?i.point.copy(Ys):i.point=Ys.clone(),i.distance=h,i.faceIndex=l,i}(this,t,e,i,s)}getBoundingBox(t){t.makeEmpty();return this._roots.forEach(e=>{os(0,new Float32Array(e),gr),t.union(gr)}),t}}function yr(t,e,i){return null===t?null:(t.point.applyMatrix4(e.matrixWorld),t.distance=t.point.distanceTo(i.ray.origin),t.object=e,t.distance<i.near||t.distance>i.far?null:t)}const wr=new y,vr=new p,br=w.prototype.raycast;function xr(t,e){if(this.geometry.boundsTree){if(void 0===this.material)return;vr.copy(this.matrixWorld).invert(),wr.copy(t.ray).applyMatrix4(vr);const i=this.geometry.boundsTree;if(!0===t.firstHitOnly){const s=yr(i.raycastFirst(wr,this.material),this,t);s&&e.push(s)}else{const s=i.raycast(wr,this.material);for(let i=0,n=s.length;i<n;i++){const n=yr(s[i],this,t);n&&e.push(n)}}}else br.call(this,t,e)}function Er(t){return this.boundsTree=new _r(this,t),this.boundsTree}function Tr(){this.boundsTree=null}const Cr=class t{constructor(){e(this,"onDisposed",new U),e(this,"list",new s),e(this,"enabled",!1),e(this,"_clock"),e(this,"onInit",new U),e(this,"update",()=>{if(!this.enabled)return;const t=this._clock.getDelta();for(const[e,i]of this.list)i.enabled&&i.isUpdateable()&&i.update(t);requestAnimationFrame(this.update)}),this._clock=new r.Clock,t.setupBVH()}add(t,e){if(this.list.has(t))throw new Error("You're trying to add a component that already exists in the components instance. Use Components.get() instead.");q.validate(t),this.list.set(t,e)}get(t){const e=t.uuid;if(!this.list.has(e)){const i=new t(this);return i.isDisposeable()&&i.onDisposed.add(()=>this.list.delete(e)),this.list.has(e)||this.add(e,i),i}return this.list.get(e)}init(){this.enabled=!0;for(const[t,e]of this.list.entries())e.enabled=!0;this._clock.start(),this.update(),this.onInit.trigger()}dispose(){let t;this.enabled=!1;for(const[e,i]of this.list)i.enabled=!1,e!==Ae.uuid?i.isDisposeable()&&i.dispose():t=i;null==t||t.dispose(),this._clock.stop(),this.onDisposed.trigger()}static setupBVH(){r.BufferGeometry.prototype.computeBoundsTree=Er,r.BufferGeometry.prototype.disposeBoundsTree=Tr,r.Mesh.prototype.raycast=xr}};e(Cr,"release","2.4.3");let Sr=Cr;class Ar{constructor(t){e(this,"enabled",!1),e(this,"id","FirstPerson"),this.camera=t}set(t){if(this.enabled=t,t){if("Perspective"!==this.camera.projection.current)return void this.camera.set("Orbit");this.setupFirstPersonCamera()}}setupFirstPersonCamera(){const t=this.camera.controls,e=new r.Vector3;t.distance--,t.getPosition(e),t.minDistance=1,t.maxDistance=1,t.distance=1,t.moveTo(e.x,e.y,e.z),t.truckSpeed=50,t.mouseButtons.wheel=Hi.ACTION.DOLLY,t.touches.two=Hi.ACTION.TOUCH_ZOOM_TRUCK}}class Or{constructor(t){e(this,"enabled",!0),e(this,"id","Orbit"),this.camera=t,this.activateOrbitControls()}set(t){this.enabled=t,t&&this.activateOrbitControls()}activateOrbitControls(){const t=this.camera.controls;t.minDistance=1,t.maxDistance=300;const e=new r.Vector3;t.getPosition(e);const i=e.length();t.distance=i,t.truckSpeed=2;const{rotation:s}=this.camera.three,n=new r.Vector3(0,0,-1).applyEuler(s),o=e.addScaledVector(n,i);t.moveTo(o.x,o.y,o.z)}}class Pr{constructor(t){e(this,"enabled",!1),e(this,"id","Plan"),e(this,"mouseAction1"),e(this,"mouseAction2"),e(this,"mouseInitialized",!1),e(this,"defaultAzimuthSpeed"),e(this,"defaultPolarSpeed"),this.camera=t,this.defaultAzimuthSpeed=t.controls.azimuthRotateSpeed,this.defaultPolarSpeed=t.controls.polarRotateSpeed}set(t){this.enabled=t;const e=this.camera.controls;e.azimuthRotateSpeed=t?0:this.defaultAzimuthSpeed,e.polarRotateSpeed=t?0:this.defaultPolarSpeed,this.mouseInitialized||(this.mouseAction1=e.touches.one,this.mouseAction2=e.touches.two,this.mouseInitialized=!0),t?(e.mouseButtons.left=Hi.ACTION.TRUCK,e.touches.one=Hi.ACTION.TOUCH_TRUCK,e.touches.two=Hi.ACTION.TOUCH_ZOOM):(e.mouseButtons.left=Hi.ACTION.ROTATE,e.touches.one=this.mouseAction1,e.touches.two=this.mouseAction2)}}class Ir{constructor(t){e(this,"onChanged",new U),e(this,"current","Perspective"),e(this,"camera"),e(this,"matchOrthoDistanceEnabled",!1),e(this,"_component"),e(this,"_previousDistance",-1),this._component=t,this.camera=t.three}async set(t){this.current!==t&&("Orthographic"===t?this.setOrthoCamera():await this.setPerspectiveCamera(),this.onChanged.trigger(this.camera))}async toggle(){const t="Perspective"===this.current?"Orthographic":"Perspective";await this.set(t)}setOrthoCamera(){if(null===this._component.mode)return;if("FirstPerson"===this._component.mode.id)return;this._previousDistance=this._component.controls.distance,this._component.controls.distance=200;const t=this.getPerspectiveDims();if(!t)return;const{width:e,height:i}=t;this.setupOrthoCamera(i,e),this.camera=this._component.threeOrtho,this.current="Orthographic"}getPerspectiveDims(){const t=this._component.currentWorld;if(!t||!t.renderer)return null;const e=new r.Vector3;this._component.threePersp.getWorldDirection(e);const i=new r.Vector3;this._component.controls.getTarget(i);const s=i.clone().sub(this._component.threePersp.position).dot(e),n=t.renderer.getSize(),o=n.x/n.y,a=this._component.threePersp,l=2*s*Math.atan(a.fov*(Math.PI/180)/2);return{width:l*o,height:l}}setupOrthoCamera(t,e){this._component.controls.mouseButtons.wheel=Hi.ACTION.ZOOM,this._component.controls.mouseButtons.middle=Hi.ACTION.ZOOM;const i=this._component.threePersp,s=this._component.threeOrtho;s.zoom=1,s.left=e/-2,s.right=e/2,s.top=t/2,s.bottom=t/-2,s.updateProjectionMatrix(),s.position.copy(i.position),s.quaternion.copy(i.quaternion),this._component.controls.camera=s}getDistance(){const t=this._component.threePersp,e=this._component.threeOrtho;return(e.top-e.bottom)/e.zoom/(2*Math.atan(t.fov*(Math.PI/180)/2))}async setPerspectiveCamera(){this._component.controls.mouseButtons.wheel=Hi.ACTION.DOLLY,this._component.controls.mouseButtons.middle=Hi.ACTION.DOLLY;const t=this._component.threePersp,e=this._component.threeOrtho;t.position.copy(e.position),t.quaternion.copy(e.quaternion),this._component.controls.mouseButtons.wheel=Hi.ACTION.DOLLY,this.matchOrthoDistanceEnabled?this._component.controls.distance=this.getDistance():this._component.controls.distance=this._previousDistance,await this._component.controls.zoomTo(1),t.updateProjectionMatrix(),this._component.controls.camera=t,this.camera=t,this.current="Perspective"}}class kr extends $i{constructor(t){super(t),e(this,"projection"),e(this,"threeOrtho"),e(this,"threePersp"),e(this,"_userInputButtons",{}),e(this,"_frustumSize",50),e(this,"_navigationModes",new Map),e(this,"_mode",null),e(this,"previousSize",null),this.threePersp=this.three,this.threeOrtho=this.newOrthoCamera(),this.projection=new Ir(this),this.onAspectUpdated.add(()=>{this.setOrthoPerspCameraAspect()}),this.projection.onChanged.add(t=>{this.three=t,this.updateAspect()}),this.worlds.onItemSet.add(()=>{this._navigationModes.clear(),this._navigationModes.set("Orbit",new Or(this)),this._navigationModes.set("FirstPerson",new Ar(this)),this._navigationModes.set("Plan",new Pr(this)),this._mode=this._navigationModes.get("Orbit"),this.mode.set(!0,{preventTargetAdjustment:!0}),this.currentWorld&&this.currentWorld.renderer&&(this.previousSize=this.currentWorld.renderer.getSize().clone())}),this.worlds.onItemDeleted.add(()=>{this._navigationModes.clear()})}get mode(){if(!this._mode)throw new Error("Mode not found, camera not initialized");return this._mode}dispose(){super.dispose(),this.threeOrtho.removeFromParent()}set(t){if(null!==this.mode&&this.mode.id!==t){if(this.mode.set(!1),!this._navigationModes.has(t))throw new Error("The specified mode does not exist!");this._mode=this._navigationModes.get(t),this.mode.set(!0)}}async fit(t,e=1.5){if(!this.enabled)return;const i=Number.MAX_VALUE,s=Number.MIN_VALUE,n=new r.Vector3(i,i,i),o=new r.Vector3(s,s,s);for(const e of t){const t=(new r.Box3).setFromObject(e);t.min.x<n.x&&(n.x=t.min.x),t.min.y<n.y&&(n.y=t.min.y),t.min.z<n.z&&(n.z=t.min.z),t.max.x>o.x&&(o.x=t.max.x),t.max.y>o.y&&(o.y=t.max.y),t.max.z>o.z&&(o.z=t.max.z)}const a=new r.Box3(n,o),l=this.components.get(Ae);if(l.initialized)for(const[,t]of l.list){const e=t.box;e.min.x<n.x&&(n.x=e.min.x),e.min.y<n.y&&(n.y=e.min.y),e.min.z<n.z&&(n.z=e.min.z),e.max.x>o.x&&(o.x=e.max.x),e.max.y>o.y&&(o.y=e.max.y),e.max.z>o.z&&(o.z=e.max.z)}const h=new r.Vector3;a.getSize(h);const c=new r.Vector3;a.getCenter(c);const d=Math.max(h.x,h.y,h.z)*e,u=new r.Sphere(c,d);await this.controls.fitToSphere(u,!0)}setUserInput(t){t?this.enableUserInput():this.disableUserInput()}disableUserInput(){this._userInputButtons.left=this.controls.mouseButtons.left,this._userInputButtons.right=this.controls.mouseButtons.right,this._userInputButtons.middle=this.controls.mouseButtons.middle,this._userInputButtons.wheel=this.controls.mouseButtons.wheel,this.controls.mouseButtons.left=0,this.controls.mouseButtons.right=0,this.controls.mouseButtons.middle=0,this.controls.mouseButtons.wheel=0}enableUserInput(){0!==Object.keys(this._userInputButtons).length&&(this.controls.mouseButtons.left=this._userInputButtons.left,this.controls.mouseButtons.right=this._userInputButtons.right,this.controls.mouseButtons.middle=this._userInputButtons.middle,this.controls.mouseButtons.wheel=this._userInputButtons.wheel)}newOrthoCamera(){const t=window.innerWidth/window.innerHeight;return new r.OrthographicCamera(this._frustumSize*t/-2,this._frustumSize*t/2,this._frustumSize/2,this._frustumSize/-2,.1,1e3)}setOrthoPerspCameraAspect(){if(!this.currentWorld||!this.currentWorld.renderer)return;if(!this.previousSize)return;const t=this.currentWorld.renderer.getSize(),e=this.threeOrtho.top,i=this.threeOrtho.right,s=e*(t.y/this.previousSize.y),n=i*(t.x/this.previousSize.x);this.threeOrtho.left=-n,this.threeOrtho.right=n,this.threeOrtho.top=s,this.threeOrtho.bottom=-s,this.threeOrtho.updateProjectionMatrix(),this.previousSize.copy(t)}}function Dr(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var zr={exports:{}};
|
|
8
8
|
/*!
|
|
9
9
|
|
|
10
10
|
JSZip v3.10.1 - A JavaScript class for generating and reading zip files
|
package/dist/index.mjs
CHANGED
|
@@ -11410,7 +11410,7 @@ const _Components = class _Components {
|
|
|
11410
11410
|
* The list of components created in this app.
|
|
11411
11411
|
* The keys are UUIDs and the values are instances of the components.
|
|
11412
11412
|
*/
|
|
11413
|
-
__publicField(this, "list",
|
|
11413
|
+
__publicField(this, "list", new DataMap$1());
|
|
11414
11414
|
/**
|
|
11415
11415
|
* If disabled, the animation loop will be stopped.
|
|
11416
11416
|
* Default value is false.
|