soonspacejs
Version:
soonspacejs 2.x
7 lines • 554 kB
JavaScript
import*as e from"three";import{Vector3 as t,Euler as n,Box3 as s,Scene as r,Quaternion as i,Object3D as o,MathUtils as a,CubeTextureLoader as l,HalfFloatType as c,EquirectangularReflectionMapping as h,Color as u,Texture as d,FileLoader as p,ImageLoader as m,TextureLoader as f,Vector2 as g,Matrix4 as y,BufferAttribute as v,BufferGeometry as w,Float32BufferAttribute as b,LineBasicMaterial as x,Line as T,Line3 as S,CurvePath as O,LineCurve as M,LineCurve3 as E,Bone as C,Uint16BufferAttribute as D,SkinnedMesh as P,Skeleton as I,AnimationClip as A,VectorKeyframeTrack as L,QuaternionKeyframeTrack as j,InterpolateLinear as _,InterpolateDiscrete as F,EventDispatcher as R,LoopPingPong as B,KeyframeTrack as U,BooleanKeyframeTrack as k,NumberKeyframeTrack as N,ColorKeyframeTrack as z,StringKeyframeTrack as G,NormalAnimationBlendMode as V,FogExp2 as H,Mesh as W,LineSegments as K,EdgesGeometry as q,MeshStandardMaterial as Y,OrthographicCamera as Q,PerspectiveCamera as X,InstancedMesh as Z,DynamicDrawUsage as J,SRGBColorSpace as $,NoToneMapping as ee,Vector4 as te,Frustum as ne,REVISION as se,WebGLRenderTarget as re,UnsignedByteType as ie,LinearMipmapLinearFilter as oe,ColorManagement as ae,DoubleSide as le,BackSide as ce,FrontSide as he,WebGLCoordinateSystem as ue,LinearSRGBColorSpace as de,RGBAIntegerFormat as pe,RGIntegerFormat as me,RedIntegerFormat as fe,UnsignedIntType as ge,UnsignedShortType as ye,UnsignedInt248Type as ve,UnsignedShort4444Type as we,UnsignedShort5551Type as be,PCFSoftShadowMap as xe,Spherical as Te,Sphere as Se,ShaderMaterial as Oe,LinearFilter as Me,RGBAFormat as Ee,DataTexture as Ce,NoColorSpace as De,RepeatWrapping as Pe,NearestFilter as Ie,RedFormat as Ae,FloatType as Le,DepthTexture as je,GLBufferAttribute as _e,InterleavedBufferAttribute as Fe,Raycaster as Re,BoxGeometry as Be,Sprite as Ue,MeshBasicMaterial as ke,CanvasTexture as Ne,SpriteMaterial as ze,Clock as Ge,PMREMGenerator as Ve,AnimationMixer as He,UVMapping as We,CubeTexture as Ke,ReinhardToneMapping as qe,CineonToneMapping as Ye,ACESFilmicToneMapping as Qe,AgXToneMapping as Xe,SphereGeometry as Ze,CircleGeometry as Je,PlaneGeometry as $e,ExtrudeGeometry as et,Shape as tt,Matrix3 as nt,Group as st,Box2 as rt,Triangle as it,ShapeGeometry as ot,Plane as at,VideoTexture as lt,MeshPhongMaterial as ct,AmbientLight as ht,DirectionalLight as ut,HemisphereLight as dt,SpotLight as pt,PointLight as mt,RectAreaLight as ft,Loader as gt,LoaderUtils as yt,ClampToEdgeWrapping as vt,PropertyBinding as wt,ShapeUtils as bt,Material as xt,PointsMaterial as Tt,Points as St,LoadingManager as Ot,GridHelper as Mt,AxesHelper as Et,Box3Helper as Ct,DirectionalLightHelper as Dt,HemisphereLightHelper as Pt,SpotLightHelper as It,PointLightHelper as At}from"three";import*as Lt from"three/examples/jsm/libs/tween.module.js";import jt,{Easing as _t,Tween as Ft}from"three/examples/jsm/libs/tween.module.js";import{RGBELoader as Rt}from"three/examples/jsm/loaders/RGBELoader.js";import{GLTFExporter as Bt}from"three/examples/jsm/exporters/GLTFExporter.js";import{Pass as Ut,EffectPass as kt,EffectComposer as Nt,RenderPass as zt,SMAAEffect as Gt,SMAAPreset as Vt,EdgeDetectionMode as Ht,ToneMappingEffect as Wt,ToneMappingMode as Kt,BloomEffect as qt,BlendFunction as Yt,OutlineEffect as Qt}from"postprocessing";import{RoomEnvironment as Xt}from"three/examples/jsm/environments/RoomEnvironment.js";import Zt from"three/examples/jsm/libs/stats.module.js";import{Sky as Jt}from"three/examples/jsm/objects/Sky.js";import{mergeGeometries as $t,deinterleaveGeometry as en}from"three/examples/jsm/utils/BufferGeometryUtils.js";import{WebGLAnimation as tn}from"three/src/renderers/webgl/WebGLAnimation.js";import{WebGLAttributes as nn}from"three/src/renderers/webgl/WebGLAttributes.js";import{WebGLBackground as sn}from"three/src/renderers/webgl/WebGLBackground.js";import{WebGLBindingStates as rn}from"three/src/renderers/webgl/WebGLBindingStates.js";import{WebGLBufferRenderer as on}from"three/src/renderers/webgl/WebGLBufferRenderer.js";import{WebGLCapabilities as an}from"three/src/renderers/webgl/WebGLCapabilities.js";import{WebGLClipping as ln}from"three/src/renderers/webgl/WebGLClipping.js";import{WebGLCubeMaps as cn}from"three/src/renderers/webgl/WebGLCubeMaps.js";import{WebGLCubeUVMaps as hn}from"three/src/renderers/webgl/WebGLCubeUVMaps.js";import{WebGLExtensions as un}from"three/src/renderers/webgl/WebGLExtensions.js";import{WebGLGeometries as dn}from"three/src/renderers/webgl/WebGLGeometries.js";import{WebGLIndexedBufferRenderer as pn}from"three/src/renderers/webgl/WebGLIndexedBufferRenderer.js";import{WebGLInfo as mn}from"three/src/renderers/webgl/WebGLInfo.js";import{WebGLMorphtargets as fn}from"three/src/renderers/webgl/WebGLMorphtargets.js";import{WebGLObjects as gn}from"three/src/renderers/webgl/WebGLObjects.js";import{WebGLPrograms as yn}from"three/src/renderers/webgl/WebGLPrograms.js";import{WebGLProperties as vn}from"three/src/renderers/webgl/WebGLProperties.js";import{WebGLRenderLists as wn}from"three/src/renderers/webgl/WebGLRenderLists.js";import{WebGLRenderStates as bn}from"three/src/renderers/webgl/WebGLRenderStates.js";import{WebGLShadowMap as xn}from"three/src/renderers/webgl/WebGLShadowMap.js";import{WebGLState as Tn}from"three/src/renderers/webgl/WebGLState.js";import{WebGLTextures as Sn}from"three/src/renderers/webgl/WebGLTextures.js";import{WebGLUniforms as On}from"three/src/renderers/webgl/WebGLUniforms.js";import{WebGLUtils as Mn}from"three/src/renderers/webgl/WebGLUtils.js";import{WebXRManager as En}from"three/src/renderers/webxr/WebXRManager.js";import{WebGLMaterials as Cn}from"three/src/renderers/webgl/WebGLMaterials.js";import{WebGLUniformsGroups as Dn}from"three/src/renderers/webgl/WebGLUniformsGroups.js";import{createCanvasElement as Pn,toNormalizedProjectionMatrix as In,toReversedProjectionMatrix as An,probeAsync as Ln,warnOnce as jn}from"three/src/utils.js";import"three/examples/jsm/postprocessing/Pass.js";import{WorkerPool as _n}from"three/examples/jsm/utils/WorkerPool.js";import{MeshBVH as Fn,computeBoundsTree as Rn,disposeBoundsTree as Bn,acceleratedRaycast as Un}from"three-mesh-bvh";import{RectAreaLightUniformsLib as kn}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";import{GLTFLoader as Nn}from"three/examples/jsm/loaders/GLTFLoader.js";import{STLLoader as zn}from"three/examples/jsm/loaders/STLLoader.js";import{TGALoader as Gn}from"three/examples/jsm/loaders/TGALoader.js";import{DRACOLoader as Vn}from"three/examples/jsm/loaders/DRACOLoader.js";import{KTX2Loader as Hn}from"three/examples/jsm/loaders/KTX2Loader.js";import{MeshoptDecoder as Wn}from"three/examples/jsm/libs/meshopt_decoder.module.js";import*as Kn from"three/examples/jsm/utils/SkeletonUtils.js";import*as qn from"three/examples/jsm/libs/fflate.module.js";import{NURBSCurve as Yn}from"three/examples/jsm/curves/NURBSCurve.js";import{RectAreaLightHelper as Qn}from"three/examples/jsm/helpers/RectAreaLightHelper.js";var Xn="soonspacejs",Zn="2.13.5";
/*!
* camera-controls
* https://github.com/yomotsu/camera-controls
* (c) 2017 @yomotsu
* Released under the MIT License.
*/const Jn=1,$n=2,es=4,ts=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768}),ns=0,ss=1,rs=-1;function is(e){return e.isPerspectiveCamera}function os(e){return e.isOrthographicCamera}const as=2*Math.PI,ls=Math.PI/2,cs=1e-5,hs=Math.PI/180;function us(e,t,n){return Math.max(t,Math.min(n,e))}function ds(e,t=cs){return Math.abs(e)<t}function ps(e,t,n=cs){return ds(e-t,n)}function ms(e,t){return Math.round(e/t)*t}function fs(e){return isFinite(e)?e:e<0?-Number.MAX_VALUE:Number.MAX_VALUE}function gs(e){return Math.abs(e)<Number.MAX_VALUE?e:e*(1/0)}function ys(e,t,n,s,r=1/0,i){const o=2/(s=Math.max(1e-4,s)),a=o*i,l=1/(1+a+.48*a*a+.235*a*a*a);let c=e-t;const h=t,u=r*s;c=us(c,-u,u),t=e-c;const d=(n.value+o*c)*i;n.value=(n.value-o*d)*l;let p=t+(c+d)*l;return h-e>0==p>h&&(p=h,n.value=(p-h)/i),p}function vs(e,t,n,s,r=1/0,i,o){const a=2/(s=Math.max(1e-4,s)),l=a*i,c=1/(1+l+.48*l*l+.235*l*l*l);let h=t.x,u=t.y,d=t.z,p=e.x-h,m=e.y-u,f=e.z-d;const g=h,y=u,v=d,w=r*s,b=p*p+m*m+f*f;if(b>w*w){const e=Math.sqrt(b);p=p/e*w,m=m/e*w,f=f/e*w}h=e.x-p,u=e.y-m,d=e.z-f;const x=(n.x+a*p)*i,T=(n.y+a*m)*i,S=(n.z+a*f)*i;n.x=(n.x-a*x)*c,n.y=(n.y-a*T)*c,n.z=(n.z-a*S)*c,o.x=h+(p+x)*c,o.y=u+(m+T)*c,o.z=d+(f+S)*c;const O=g-e.x,M=y-e.y,E=v-e.z;return O*(o.x-g)+M*(o.y-y)+E*(o.z-v)>0&&(o.x=g,o.y=y,o.z=v,n.x=(o.x-g)/i,n.y=(o.y-y)/i,n.z=(o.z-v)/i),o}function ws(e,t){t.set(0,0),e.forEach((e=>{t.x+=e.clientX,t.y+=e.clientY})),t.x/=e.length,t.y/=e.length}function bs(e,t){return!!os(e)&&(console.warn(`${t} is not supported in OrthographicCamera`),!0)}class xs{constructor(){this._listeners={}}addEventListener(e,t){const n=this._listeners;void 0===n[e]&&(n[e]=[]),-1===n[e].indexOf(t)&&n[e].push(t)}hasEventListener(e,t){const n=this._listeners;return void 0!==n[e]&&-1!==n[e].indexOf(t)}removeEventListener(e,t){const n=this._listeners[e];if(void 0!==n){const e=n.indexOf(t);-1!==e&&n.splice(e,1)}}removeAllEventListeners(e){e?Array.isArray(this._listeners[e])&&(this._listeners[e].length=0):this._listeners={}}dispatchEvent(e){const t=this._listeners[e.type];if(void 0!==t){e.target=this;const n=t.slice(0);for(let t=0,s=n.length;t<s;t++)n[t].call(this,e)}}}var Ts;const Ss=1/8,Os=/Mac/.test(null===(Ts=null===globalThis||void 0===globalThis?void 0:globalThis.navigator)||void 0===Ts?void 0:Ts.platform);let Ms,Es,Cs,Ds,Ps,Is,As,Ls,js,_s,Fs,Rs,Bs,Us,ks,Ns,zs,Gs,Vs,Hs,Ws,Ks,qs;class Ys extends xs{static install(e){Ms=e.THREE,Es=Object.freeze(new Ms.Vector3(0,0,0)),Cs=Object.freeze(new Ms.Vector3(0,1,0)),Ds=Object.freeze(new Ms.Vector3(0,0,1)),Ps=new Ms.Vector2,Is=new Ms.Vector3,As=new Ms.Vector3,Ls=new Ms.Vector3,js=new Ms.Vector3,_s=new Ms.Vector3,Fs=new Ms.Vector3,Rs=new Ms.Vector3,Bs=new Ms.Vector3,Us=new Ms.Vector3,ks=new Ms.Spherical,Ns=new Ms.Spherical,zs=new Ms.Box3,Gs=new Ms.Box3,Vs=new Ms.Sphere,Hs=new Ms.Quaternion,Ws=new Ms.Quaternion,Ks=new Ms.Matrix4,qs=new Ms.Raycaster}static get ACTION(){return ts}constructor(e,t){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.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=ts.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=ns,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new Ms.Vector3,this._focalOffsetVelocity=new Ms.Vector3,this._zoomVelocity={value:0},this._truckInternal=(e,t,n)=>{let s,r;if(is(this._camera)){const n=Is.copy(this._camera.position).sub(this._target),i=this._camera.getEffectiveFOV()*hs,o=n.length()*Math.tan(.5*i);s=this.truckSpeed*e*o/this._elementRect.height,r=this.truckSpeed*t*o/this._elementRect.height}else{if(!os(this._camera))return;{const n=this._camera;s=e*(n.right-n.left)/n.zoom/this._elementRect.width,r=t*(n.top-n.bottom)/n.zoom/this._elementRect.height}}this.verticalDragToForward?(n?this.setFocalOffset(this._focalOffsetEnd.x+s,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(s,0,!0),this.forward(-r,!0)):n?this.setFocalOffset(this._focalOffsetEnd.x+s,this._focalOffsetEnd.y+r,this._focalOffsetEnd.z,!0):this.truck(s,r,!0)},this._rotateInternal=(e,t)=>{const n=as*this.azimuthRotateSpeed*e/this._elementRect.height,s=as*this.polarRotateSpeed*t/this._elementRect.height;this.rotate(n,s,!0)},this._dollyInternal=(e,t,n)=>{const s=Math.pow(.95,-e*this.dollySpeed),r=this._sphericalEnd.radius,i=this._sphericalEnd.radius*s,o=us(i,this.minDistance,this.maxDistance),a=o-i;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(i,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(a,!0),this._dollyToNoClamp(o,!0)):this._dollyToNoClamp(o,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?i:o)-r,this._dollyControlCoord.set(t,n)),this._lastDollyDirection=Math.sign(-e)},this._zoomInternal=(e,t,n)=>{const s=Math.pow(.95,e*this.dollySpeed),r=this._zoom,i=this._zoom*s;this.zoomTo(i,!0),this.dollyToCursor&&(this._changedZoom+=i-r,this._dollyControlCoord.set(t,n))},void 0===Ms&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=e,this._yAxisUpSpace=(new Ms.Quaternion).setFromUnitVectors(this._camera.up,Cs),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=ts.NONE,this._target=new Ms.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new Ms.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=(new Ms.Spherical).setFromVector3(Is.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 Ms.Vector3,new Ms.Vector3,new Ms.Vector3,new Ms.Vector3],this._updateNearPlaneCorners(),this._boundary=new Ms.Box3(new Ms.Vector3(-1/0,-1/0,-1/0),new Ms.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 Ms.Vector2,this.mouseButtons={left:ts.ROTATE,middle:ts.DOLLY,right:ts.TRUCK,wheel:is(this._camera)?ts.DOLLY:os(this._camera)?ts.ZOOM:ts.NONE},this.touches={one:ts.TOUCH_ROTATE,two:is(this._camera)?ts.TOUCH_DOLLY_TRUCK:os(this._camera)?ts.TOUCH_ZOOM_TRUCK:ts.NONE,three:ts.TOUCH_TRUCK};const n=new Ms.Vector2,s=new Ms.Vector2,r=new Ms.Vector2,i=e=>{if(!this._enabled||!this._domElement)return;if(0!==this._interactiveArea.left||0!==this._interactiveArea.top||1!==this._interactiveArea.width||1!==this._interactiveArea.height){const t=this._domElement.getBoundingClientRect(),n=e.clientX/t.width,s=e.clientY/t.height;if(n<this._interactiveArea.left||n>this._interactiveArea.right||s<this._interactiveArea.top||s>this._interactiveArea.bottom)return}const t="mouse"!==e.pointerType?null:(e.buttons&Jn)===Jn?Jn:(e.buttons&es)===es?es:(e.buttons&$n)===$n?$n:null;if(null!==t){const e=this._findPointerByMouseButton(t);e&&this._disposePointer(e)}if((e.buttons&Jn)===Jn&&this._lockedPointer)return;const n={pointerId:e.pointerId,clientX:e.clientX,clientY:e.clientY,deltaX:0,deltaY:0,mouseButton:t};this._activePointers.push(n),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,u(e)},o=e=>{e.cancelable&&e.preventDefault();const t=e.pointerId,n=this._lockedPointer||this._findPointerById(t);if(n){if(n.clientX=e.clientX,n.clientY=e.clientY,n.deltaX=e.movementX,n.deltaY=e.movementY,this._state=0,"touch"===e.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&&(e.buttons&Jn)===Jn)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(e.buttons&es)===es&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(e.buttons&$n)===$n&&(this._state=this._state|this.mouseButtons.right);d()}},a=e=>{const t=this._findPointerById(e.pointerId);if(!t||t!==this._lockedPointer){if(t&&this._disposePointer(t),"touch"===e.pointerType)switch(this._activePointers.length){case 0:this._state=ts.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=ts.NONE;p()}};let l=-1;const c=e=>{if(!this._domElement)return;if(!this._enabled||this.mouseButtons.wheel===ts.NONE)return;if(0!==this._interactiveArea.left||0!==this._interactiveArea.top||1!==this._interactiveArea.width||1!==this._interactiveArea.height){const t=this._domElement.getBoundingClientRect(),n=e.clientX/t.width,s=e.clientY/t.height;if(n<this._interactiveArea.left||n>this._interactiveArea.right||s<this._interactiveArea.top||s>this._interactiveArea.bottom)return}if(e.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===ts.ROTATE||this.mouseButtons.wheel===ts.TRUCK){const e=performance.now();l-e<1e3&&this._getClientRect(this._elementRect),l=e}const t=Os?-1:-3,n=1===e.deltaMode?e.deltaY/t:e.deltaY/(10*t),s=this.dollyToCursor?(e.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,r=this.dollyToCursor?(e.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case ts.ROTATE:this._rotateInternal(e.deltaX,e.deltaY),this._isUserControllingRotate=!0;break;case ts.TRUCK:this._truckInternal(e.deltaX,e.deltaY,!1),this._isUserControllingTruck=!0;break;case ts.OFFSET:this._truckInternal(e.deltaX,e.deltaY,!0),this._isUserControllingOffset=!0;break;case ts.DOLLY:this._dollyInternal(-n,s,r),this._isUserControllingDolly=!0;break;case ts.ZOOM:this._zoomInternal(-n,s,r),this._isUserControllingZoom=!0}this.dispatchEvent({type:"control"})},h=e=>{if(this._domElement&&this._enabled){if(this.mouseButtons.right===Ys.ACTION.NONE){const t=e instanceof PointerEvent?e.pointerId:0,n=this._findPointerById(t);return n&&this._disposePointer(n),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),void this._domElement.ownerDocument.removeEventListener("pointerup",a)}e.preventDefault()}},u=e=>{if(!this._enabled)return;ws(this._activePointers,Ps),this._getClientRect(this._elementRect),n.copy(Ps),s.copy(Ps);if(this._activePointers.length>=2){const e=Ps.x-this._activePointers[1].clientX,t=Ps.y-this._activePointers[1].clientY,n=Math.sqrt(e*e+t*t);r.set(0,n);const i=.5*(this._activePointers[0].clientX+this._activePointers[1].clientX),o=.5*(this._activePointers[0].clientY+this._activePointers[1].clientY);s.set(i,o)}if(this._state=0,e)if("pointerType"in e&&"touch"===e.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||(e.buttons&Jn)!==Jn||(this._state=this._state|this.mouseButtons.left),(e.buttons&es)===es&&(this._state=this._state|this.mouseButtons.middle),(e.buttons&$n)===$n&&(this._state=this._state|this.mouseButtons.right);else this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);(this._state&ts.ROTATE)!==ts.ROTATE&&(this._state&ts.TOUCH_ROTATE)!==ts.TOUCH_ROTATE&&(this._state&ts.TOUCH_DOLLY_ROTATE)!==ts.TOUCH_DOLLY_ROTATE&&(this._state&ts.TOUCH_ZOOM_ROTATE)!==ts.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&ts.TRUCK)!==ts.TRUCK&&(this._state&ts.TOUCH_TRUCK)!==ts.TOUCH_TRUCK&&(this._state&ts.TOUCH_DOLLY_TRUCK)!==ts.TOUCH_DOLLY_TRUCK&&(this._state&ts.TOUCH_ZOOM_TRUCK)!==ts.TOUCH_ZOOM_TRUCK||(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),(this._state&ts.DOLLY)!==ts.DOLLY&&(this._state&ts.TOUCH_DOLLY)!==ts.TOUCH_DOLLY&&(this._state&ts.TOUCH_DOLLY_TRUCK)!==ts.TOUCH_DOLLY_TRUCK&&(this._state&ts.TOUCH_DOLLY_OFFSET)!==ts.TOUCH_DOLLY_OFFSET&&(this._state&ts.TOUCH_DOLLY_ROTATE)!==ts.TOUCH_DOLLY_ROTATE||(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),(this._state&ts.ZOOM)!==ts.ZOOM&&(this._state&ts.TOUCH_ZOOM)!==ts.TOUCH_ZOOM&&(this._state&ts.TOUCH_ZOOM_TRUCK)!==ts.TOUCH_ZOOM_TRUCK&&(this._state&ts.TOUCH_ZOOM_OFFSET)!==ts.TOUCH_ZOOM_OFFSET&&(this._state&ts.TOUCH_ZOOM_ROTATE)!==ts.TOUCH_ZOOM_ROTATE||(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),(this._state&ts.OFFSET)!==ts.OFFSET&&(this._state&ts.TOUCH_OFFSET)!==ts.TOUCH_OFFSET&&(this._state&ts.TOUCH_DOLLY_OFFSET)!==ts.TOUCH_DOLLY_OFFSET&&(this._state&ts.TOUCH_ZOOM_OFFSET)!==ts.TOUCH_ZOOM_OFFSET||(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},d=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,ws(this._activePointers,Ps);const e=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,t=e?-e.deltaX:s.x-Ps.x,i=e?-e.deltaY:s.y-Ps.y;if(s.copy(Ps),(this._state&ts.ROTATE)!==ts.ROTATE&&(this._state&ts.TOUCH_ROTATE)!==ts.TOUCH_ROTATE&&(this._state&ts.TOUCH_DOLLY_ROTATE)!==ts.TOUCH_DOLLY_ROTATE&&(this._state&ts.TOUCH_ZOOM_ROTATE)!==ts.TOUCH_ZOOM_ROTATE||(this._rotateInternal(t,i),this._isUserControllingRotate=!0),(this._state&ts.DOLLY)===ts.DOLLY||(this._state&ts.ZOOM)===ts.ZOOM){const e=this.dollyToCursor?(n.x-this._elementRect.x)/this._elementRect.width*2-1:0,t=this.dollyToCursor?(n.y-this._elementRect.y)/this._elementRect.height*-2+1:0,s=this.dollyDragInverted?-1:1;(this._state&ts.DOLLY)===ts.DOLLY?(this._dollyInternal(s*i*Ss,e,t),this._isUserControllingDolly=!0):(this._zoomInternal(s*i*Ss,e,t),this._isUserControllingZoom=!0)}if((this._state&ts.TOUCH_DOLLY)===ts.TOUCH_DOLLY||(this._state&ts.TOUCH_ZOOM)===ts.TOUCH_ZOOM||(this._state&ts.TOUCH_DOLLY_TRUCK)===ts.TOUCH_DOLLY_TRUCK||(this._state&ts.TOUCH_ZOOM_TRUCK)===ts.TOUCH_ZOOM_TRUCK||(this._state&ts.TOUCH_DOLLY_OFFSET)===ts.TOUCH_DOLLY_OFFSET||(this._state&ts.TOUCH_ZOOM_OFFSET)===ts.TOUCH_ZOOM_OFFSET||(this._state&ts.TOUCH_DOLLY_ROTATE)===ts.TOUCH_DOLLY_ROTATE||(this._state&ts.TOUCH_ZOOM_ROTATE)===ts.TOUCH_ZOOM_ROTATE){const e=Ps.x-this._activePointers[1].clientX,t=Ps.y-this._activePointers[1].clientY,n=Math.sqrt(e*e+t*t),i=r.y-n;r.set(0,n);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&ts.TOUCH_DOLLY)===ts.TOUCH_DOLLY||(this._state&ts.TOUCH_DOLLY_ROTATE)===ts.TOUCH_DOLLY_ROTATE||(this._state&ts.TOUCH_DOLLY_TRUCK)===ts.TOUCH_DOLLY_TRUCK||(this._state&ts.TOUCH_DOLLY_OFFSET)===ts.TOUCH_DOLLY_OFFSET?(this._dollyInternal(i*Ss,o,a),this._isUserControllingDolly=!0):(this._zoomInternal(i*Ss,o,a),this._isUserControllingZoom=!0)}(this._state&ts.TRUCK)!==ts.TRUCK&&(this._state&ts.TOUCH_TRUCK)!==ts.TOUCH_TRUCK&&(this._state&ts.TOUCH_DOLLY_TRUCK)!==ts.TOUCH_DOLLY_TRUCK&&(this._state&ts.TOUCH_ZOOM_TRUCK)!==ts.TOUCH_ZOOM_TRUCK||(this._truckInternal(t,i,!1),this._isUserControllingTruck=!0),(this._state&ts.OFFSET)!==ts.OFFSET&&(this._state&ts.TOUCH_OFFSET)!==ts.TOUCH_OFFSET&&(this._state&ts.TOUCH_DOLLY_OFFSET)!==ts.TOUCH_DOLLY_OFFSET&&(this._state&ts.TOUCH_ZOOM_OFFSET)!==ts.TOUCH_ZOOM_OFFSET||(this._truckInternal(t,i,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},p=()=>{ws(this._activePointers,Ps),s.copy(Ps),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",m),this._domElement.ownerDocument.addEventListener("pointerlockerror",f),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",a),u())},this.unlockPointer=()=>{var e,t,n;null!==this._lockedPointer&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),null===(e=this._domElement)||void 0===e||e.ownerDocument.exitPointerLock(),null===(t=this._domElement)||void 0===t||t.ownerDocument.removeEventListener("pointerlockchange",m),null===(n=this._domElement)||void 0===n||n.ownerDocument.removeEventListener("pointerlockerror",f),this.cancel()};const m=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},f=()=>{this.unlockPointer()};this._addAllEventListeners=e=>{this._domElement=e,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",i),this._domElement.addEventListener("pointercancel",a),this._domElement.addEventListener("wheel",c,{passive:!1}),this._domElement.addEventListener("contextmenu",h)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",i),this._domElement.removeEventListener("pointercancel",a),this._domElement.removeEventListener("wheel",c,{passive:!1}),this._domElement.removeEventListener("contextmenu",h),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.ownerDocument.removeEventListener("pointerlockchange",m),this._domElement.ownerDocument.removeEventListener("pointerlockerror",f))},this.cancel=()=>{this._state!==ts.NONE&&(this._state=ts.NONE,this._activePointers.length=0,p())},t&&this.connect(t),this.update(0)}get camera(){return this._camera}set camera(e){this._camera=e,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._domElement&&(e?(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(e){this._spherical.radius===e&&this._sphericalEnd.radius===e||(this._spherical.radius=e,this._sphericalEnd.radius=e,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(e){this._spherical.theta===e&&this._sphericalEnd.theta===e||(this._spherical.theta=e,this._sphericalEnd.theta=e,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(e){this._spherical.phi===e&&this._sphericalEnd.phi===e||(this._spherical.phi=e,this._sphericalEnd.phi=e,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(e){this._boundaryEnclosesCamera=e,this._needsUpdate=!0}set interactiveArea(e){this._interactiveArea.width=us(e.width,0,1),this._interactiveArea.height=us(e.height,0,1),this._interactiveArea.x=us(e.x,0,1-this._interactiveArea.width),this._interactiveArea.y=us(e.y,0,1-this._interactiveArea.height)}addEventListener(e,t){super.addEventListener(e,t)}removeEventListener(e,t){super.removeEventListener(e,t)}rotate(e,t,n=!1){return this.rotateTo(this._sphericalEnd.theta+e,this._sphericalEnd.phi+t,n)}rotateAzimuthTo(e,t=!1){return this.rotateTo(e,this._sphericalEnd.phi,t)}rotatePolarTo(e,t=!1){return this.rotateTo(this._sphericalEnd.theta,e,t)}rotateTo(e,t,n=!1){this._isUserControllingRotate=!1;const s=us(e,this.minAzimuthAngle,this.maxAzimuthAngle),r=us(t,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=s,this._sphericalEnd.phi=r,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,n||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const i=!n||ps(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&ps(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(i)}dolly(e,t=!1){return this.dollyTo(this._sphericalEnd.radius-e,t)}dollyTo(e,t=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=ns,this._changedDolly=0,this._dollyToNoClamp(us(e,this.minDistance,this.maxDistance),t)}_dollyToNoClamp(e,t=!1){const n=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const t=this._collisionTest(),s=ps(t,this._spherical.radius);if(!(n>e)&&s)return Promise.resolve();this._sphericalEnd.radius=Math.min(e,t)}else this._sphericalEnd.radius=e;this._needsUpdate=!0,t||(this._spherical.radius=this._sphericalEnd.radius);const s=!t||ps(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(s)}dollyInFixed(e,t=!1){this._targetEnd.add(this._getCameraDirection(js).multiplyScalar(e)),t||this._target.copy(this._targetEnd);const n=!t||ps(this._target.x,this._targetEnd.x,this.restThreshold)&&ps(this._target.y,this._targetEnd.y,this.restThreshold)&&ps(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}zoom(e,t=!1){return this.zoomTo(this._zoomEnd+e,t)}zoomTo(e,t=!1){this._isUserControllingZoom=!1,this._zoomEnd=us(e,this.minZoom,this.maxZoom),this._needsUpdate=!0,t||(this._zoom=this._zoomEnd);const n=!t||ps(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(n)}pan(e,t,n=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(e,t,n)}truck(e,t,n=!1){this._camera.updateMatrix(),_s.setFromMatrixColumn(this._camera.matrix,0),Fs.setFromMatrixColumn(this._camera.matrix,1),_s.multiplyScalar(e),Fs.multiplyScalar(-t);const s=Is.copy(_s).add(Fs),r=As.copy(this._targetEnd).add(s);return this.moveTo(r.x,r.y,r.z,n)}forward(e,t=!1){Is.setFromMatrixColumn(this._camera.matrix,0),Is.crossVectors(this._camera.up,Is),Is.multiplyScalar(e);const n=As.copy(this._targetEnd).add(Is);return this.moveTo(n.x,n.y,n.z,t)}elevate(e,t=!1){return Is.copy(this._camera.up).multiplyScalar(e),this.moveTo(this._targetEnd.x+Is.x,this._targetEnd.y+Is.y,this._targetEnd.z+Is.z,t)}moveTo(e,t,n,s=!1){this._isUserControllingTruck=!1;const r=Is.set(e,t,n).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,r,this.boundaryFriction),this._needsUpdate=!0,s||this._target.copy(this._targetEnd);const i=!s||ps(this._target.x,this._targetEnd.x,this.restThreshold)&&ps(this._target.y,this._targetEnd.y,this.restThreshold)&&ps(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(i)}lookInDirectionOf(e,t,n,s=!1){const r=Is.set(e,t,n).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(r.x,r.y,r.z,s)}fitToBox(e,t,{cover:n=!1,paddingLeft:s=0,paddingRight:r=0,paddingBottom:i=0,paddingTop:o=0}={}){const a=[],l=e.isBox3?zs.copy(e):zs.setFromObject(e);l.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const c=ms(this._sphericalEnd.theta,ls),h=ms(this._sphericalEnd.phi,ls);a.push(this.rotateTo(c,h,t));const u=Is.setFromSpherical(this._sphericalEnd).normalize(),d=Hs.setFromUnitVectors(u,Ds),p=ps(Math.abs(u.y),1);p&&d.multiply(Ws.setFromAxisAngle(Cs,c)),d.multiply(this._yAxisUpSpaceInverse);const m=Gs.makeEmpty();As.copy(l.min).applyQuaternion(d),m.expandByPoint(As),As.copy(l.min).setX(l.max.x).applyQuaternion(d),m.expandByPoint(As),As.copy(l.min).setY(l.max.y).applyQuaternion(d),m.expandByPoint(As),As.copy(l.max).setZ(l.min.z).applyQuaternion(d),m.expandByPoint(As),As.copy(l.min).setZ(l.max.z).applyQuaternion(d),m.expandByPoint(As),As.copy(l.max).setY(l.min.y).applyQuaternion(d),m.expandByPoint(As),As.copy(l.max).setX(l.min.x).applyQuaternion(d),m.expandByPoint(As),As.copy(l.max).applyQuaternion(d),m.expandByPoint(As),m.min.x-=s,m.min.y-=i,m.max.x+=r,m.max.y+=o,d.setFromUnitVectors(Ds,u),p&&d.premultiply(Ws.invert()),d.premultiply(this._yAxisUpSpace);const f=m.getSize(Is),g=m.getCenter(As).applyQuaternion(d);if(is(this._camera)){const e=this.getDistanceToFitBox(f.x,f.y,f.z,n);a.push(this.moveTo(g.x,g.y,g.z,t)),a.push(this.dollyTo(e,t)),a.push(this.setFocalOffset(0,0,0,t))}else if(os(this._camera)){const e=this._camera,s=e.right-e.left,r=e.top-e.bottom,i=n?Math.max(s/f.x,r/f.y):Math.min(s/f.x,r/f.y);a.push(this.moveTo(g.x,g.y,g.z,t)),a.push(this.zoomTo(i,t)),a.push(this.setFocalOffset(0,0,0,t))}return Promise.all(a)}fitToSphere(e,t){const n=[],s="isObject3D"in e?Ys.createBoundingSphere(e,Vs):Vs.copy(e);if(n.push(this.moveTo(s.center.x,s.center.y,s.center.z,t)),is(this._camera)){const e=this.getDistanceToFitSphere(s.radius);n.push(this.dollyTo(e,t))}else if(os(this._camera)){const e=this._camera.right-this._camera.left,r=this._camera.top-this._camera.bottom,i=2*s.radius,o=Math.min(e/i,r/i);n.push(this.zoomTo(o,t))}return n.push(this.setFocalOffset(0,0,0,t)),Promise.all(n)}setLookAt(e,t,n,s,r,i,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=ns,this._changedDolly=0;const a=As.set(s,r,i),l=Is.set(e,t,n);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 c=!o||ps(this._target.x,this._targetEnd.x,this.restThreshold)&&ps(this._target.y,this._targetEnd.y,this.restThreshold)&&ps(this._target.z,this._targetEnd.z,this.restThreshold)&&ps(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&ps(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&ps(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(c)}lerpLookAt(e,t,n,s,r,i,o,a,l,c,h,u,d,p=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=ns,this._changedDolly=0;const m=Is.set(s,r,i),f=As.set(e,t,n);ks.setFromVector3(f.sub(m).applyQuaternion(this._yAxisUpSpace));const g=Ls.set(c,h,u),y=As.set(o,a,l);Ns.setFromVector3(y.sub(g).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(m.lerp(g,d));const v=Ns.theta-ks.theta,w=Ns.phi-ks.phi,b=Ns.radius-ks.radius;this._sphericalEnd.set(ks.radius+b*d,ks.phi+w*d,ks.theta+v*d),this.normalizeRotations(),this._needsUpdate=!0,p||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const x=!p||ps(this._target.x,this._targetEnd.x,this.restThreshold)&&ps(this._target.y,this._targetEnd.y,this.restThreshold)&&ps(this._target.z,this._targetEnd.z,this.restThreshold)&&ps(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&ps(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&ps(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(x)}setPosition(e,t,n,s=!1){return this.setLookAt(e,t,n,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,s)}setTarget(e,t,n,s=!1){const r=this.getPosition(Is),i=this.setLookAt(r.x,r.y,r.z,e,t,n,s);return this._sphericalEnd.phi=us(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),i}setFocalOffset(e,t,n,s=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(e,t,n),this._needsUpdate=!0,s||this._focalOffset.copy(this._focalOffsetEnd);const r=!s||ps(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&ps(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&ps(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}setOrbitPoint(e,t,n){this._camera.updateMatrixWorld(),_s.setFromMatrixColumn(this._camera.matrixWorldInverse,0),Fs.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Rs.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const s=Is.set(e,t,n),r=s.distanceTo(this._camera.position),i=s.sub(this._camera.position);_s.multiplyScalar(i.x),Fs.multiplyScalar(i.y),Rs.multiplyScalar(i.z),Is.copy(_s).add(Fs).add(Rs),Is.z=Is.z+r,this.dollyTo(r,!1),this.setFocalOffset(-Is.x,Is.y,-Is.z,!1),this.moveTo(e,t,n,!1)}setBoundary(e){if(!e)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(e),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(e,t,n,s){null!==e?(this._viewport=this._viewport||new Ms.Vector4,"number"==typeof e?this._viewport.set(e,t,n,s):this._viewport.copy(e)):this._viewport=null}getDistanceToFitBox(e,t,n,s=!1){if(bs(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const r=e/t,i=this._camera.getEffectiveFOV()*hs,o=this._camera.aspect;return.5*((s?r>o:r<o)?t:e/o)/Math.tan(.5*i)+.5*n}getDistanceToFitSphere(e){if(bs(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const t=this._camera.getEffectiveFOV()*hs,n=2*Math.atan(Math.tan(.5*t)*this._camera.aspect),s=1<this._camera.aspect?t:n;return e/Math.sin(.5*s)}getTarget(e,t=!0){return(e&&e.isVector3?e:new Ms.Vector3).copy(t?this._targetEnd:this._target)}getPosition(e,t=!0){return(e&&e.isVector3?e:new Ms.Vector3).setFromSpherical(t?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(t?this._targetEnd:this._target)}getSpherical(e,t=!0){return(e||new Ms.Spherical).copy(t?this._sphericalEnd:this._spherical)}getFocalOffset(e,t=!0){return(e&&e.isVector3?e:new Ms.Vector3).copy(t?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%as,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=as),this._spherical.theta+=as*Math.round((this._sphericalEnd.theta-this._spherical.theta)/as)}stop(){this._focalOffset.copy(this._focalOffsetEnd),this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd),this._zoom=this._zoomEnd}reset(e=!1){if(!ps(this._camera.up.x,this._cameraUp0.x)||!ps(this._camera.up.y,this._cameraUp0.y)||!ps(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const e=this.getPosition(Is);this.updateCameraUp(),this.setPosition(e.x,e.y,e.z)}const t=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,e),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,e),this.zoomTo(this._zoom0,e)];return Promise.all(t)}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,Cs),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const e=Is.subVectors(this._target,this._camera.position).normalize(),t=As.crossVectors(e,this._camera.up);this._camera.up.crossVectors(t,e).normalize(),this._camera.updateMatrixWorld();const n=this.getPosition(Is);this.updateCameraUp(),this.setPosition(n.x,n.y,n.z)}update(e){const t=this._sphericalEnd.theta-this._spherical.theta,n=this._sphericalEnd.phi-this._spherical.phi,s=this._sphericalEnd.radius-this._spherical.radius,r=Bs.subVectors(this._targetEnd,this._target),i=Us.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(ds(t))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const t=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=ys(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,t,1/0,e),this._needsUpdate=!0}if(ds(n))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const t=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=ys(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,t,1/0,e),this._needsUpdate=!0}if(ds(s))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const t=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=ys(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,t,this.maxSpeed,e),this._needsUpdate=!0}if(ds(r.x)&&ds(r.y)&&ds(r.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const t=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;vs(this._target,this._targetEnd,this._targetVelocity,t,this.maxSpeed,e,this._target),this._needsUpdate=!0}if(ds(i.x)&&ds(i.y)&&ds(i.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const t=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;vs(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,t,this.maxSpeed,e,this._focalOffset),this._needsUpdate=!0}if(ds(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const t=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=ys(this._zoom,this._zoomEnd,this._zoomVelocity,t,1/0,e)}if(this.dollyToCursor)if(is(this._camera)&&0!==this._changedDolly){const e=this._spherical.radius-this._lastDistance,t=this._camera,n=this._getCameraDirection(js),s=Is.copy(n).cross(t.up).normalize();0===s.lengthSq()&&(s.x=1);const r=As.crossVectors(s,n),i=this._sphericalEnd.radius*Math.tan(t.getEffectiveFOV()*hs*.5),o=(this._sphericalEnd.radius-e-this._sphericalEnd.radius)/this._sphericalEnd.radius,a=Ls.copy(this._targetEnd).add(s.multiplyScalar(this._dollyControlCoord.x*i*t.aspect)).add(r.multiplyScalar(this._dollyControlCoord.y*i)),l=Is.copy(this._targetEnd).lerp(a,o),c=this._lastDollyDirection===ss&&this._spherical.radius<=this.minDistance,h=this._lastDollyDirection===rs&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(c||h)){this._sphericalEnd.radius-=e,this._spherical.radius-=e;const t=As.copy(n).multiplyScalar(-e);l.add(t)}this._boundary.clampPoint(l,l);const u=As.subVectors(l,this._targetEnd);this._targetEnd.copy(l),this._target.add(u),this._changedDolly-=e,ds(this._changedDolly)&&(this._changedDolly=0)}else if(os(this._camera)&&0!==this._changedZoom){const e=this._zoom-this._lastZoom,t=this._camera,n=Is.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(t.near+t.far)/(t.near-t.far)).unproject(t),s=As.set(0,0,-1).applyQuaternion(t.quaternion),r=Ls.copy(n).add(s.multiplyScalar(-n.dot(t.up))),i=-(this._zoom-e-this._zoom)/this._zoom,o=this._getCameraDirection(js),a=this._targetEnd.dot(o),l=Is.copy(this._targetEnd).lerp(r,i),c=l.dot(o),h=o.multiplyScalar(c-a);l.sub(h),this._boundary.clampPoint(l,l);const u=As.subVectors(l,this._targetEnd);this._targetEnd.copy(l),this._target.add(u),this._changedZoom-=e,ds(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);(!ds(this._focalOffset.x)||!ds(this._focalOffset.y)||!ds(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),_s.setFromMatrixColumn(this._camera.matrix,0),Fs.setFromMatrixColumn(this._camera.matrix,1),Rs.setFromMatrixColumn(this._camera.matrix,2),_s.multiplyScalar(this._focalOffset.x),Fs.multiplyScalar(-this._focalOffset.y),Rs.multiplyScalar(this._focalOffset.z),Is.copy(_s).add(Fs).add(Rs),this._camera.position.add(Is)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),Is.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"}),ds(t,this.restThreshold)&&ds(n,this.restThreshold)&&ds(s,this.restThreshold)&&ds(r.x,this.restThreshold)&&ds(r.y,this.restThreshold)&&ds(r.z,this.restThreshold)&&ds(i.x,this.restThreshold)&&ds(i.y,this.restThreshold)&&ds(i.z,this.restThreshold)&&ds(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:fs(this.maxDistance),minZoom:this.minZoom,maxZoom:fs(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:fs(this.maxPolarAngle),minAzimuthAngle:fs(this.minAzimuthAngle),maxAzimuthAngle:fs(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,verticalDragToForward:this.verticalDragToForward,target:this._targetEnd.toArray(),position:Is.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(e,t=!1){const n=JSON.parse(e);this.enabled=n.enabled,this.minDistance=n.minDistance,this.maxDistance=gs(n.maxDistance),this.minZoom=n.minZoom,this.maxZoom=gs(n.maxZoom),this.minPolarAngle=n.minPolarAngle,this.maxPolarAngle=gs(n.maxPolarAngle),this.minAzimuthAngle=gs(n.minAzimuthAngle),this.maxAzimuthAngle=gs(n.maxAzimuthAngle),this.smoothTime=n.smoothTime,this.draggingSmoothTime=n.draggingSmoothTime,this.dollySpeed=n.dollySpeed,this.truckSpeed=n.truckSpeed,this.dollyToCursor=n.dollyToCursor,this.verticalDragToForward=n.verticalDragToForward,this._target0.fromArray(n.target0),this._position0.fromArray(n.position0),this._zoom0=n.zoom0,this._focalOffset0.fromArray(n.focalOffset0),this.moveTo(n.target[0],n.target[1],n.target[2],t),ks.setFromVector3(Is.fromArray(n.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(ks.theta,ks.phi,t),this.dollyTo(ks.radius,t),this.zoomTo(n.zoom,t),this.setFocalOffset(n.focalOffset[0],n.focalOffset[1],n.focalOffset[2],t),this._needsUpdate=!0}connect(e){this._domElement?console.warn("camera-controls is already connected."):(e.setAttribute("data-camera-controls-version","2.9.0"),this._addAllEventListeners(e),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(e){return e.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(e){return this._getTargetDirection(e).negate()}_findPointerById(e){return this._activePointers.find((t=>t.pointerId===e))}_findPointerByMouseButton(e){return this._activePointers.find((t=>t.mouseButton===e))}_disposePointer(e){this._activePointers.splice(this._activePointers.indexOf(e),1)}_encloseToBoundary(e,t,n){const s=t.lengthSq();if(0===s)return e;const r=As.copy(t).add(e),i=this._boundary.clampPoint(r,Ls).sub(r),o=i.lengthSq();if(0===o)return e.add(t);if(o===s)return e;if(0===n)return e.add(t).add(i);{const s=1+n*o/t.dot(i);return e.add(As.copy(t).multiplyScalar(s)).add(i.multiplyScalar(1-n))}}_updateNearPlaneCorners(){if(is(this._camera)){const e=this._camera,t=e.near,n=e.getEffectiveFOV()*hs,s=Math.tan(.5*n)*t,r=s*e.aspect;this._nearPlaneCorners[0].set(-r,-s,0),this._nearPlaneCorners[1].set(r,-s,0),this._nearPlaneCorners[2].set(r,s,0),this._nearPlaneCorners[3].set(-r,s,0)}else if(os(this._camera)){const e=this._camera,t=1/e.zoom,n=e.left*t,s=e.right*t,r=e.top*t,i=e.bottom*t;this._nearPlaneCorners[0].set(n,r,0),this._nearPlaneCorners[1].set(s,r,0),this._nearPlaneCorners[2].set(s,i,0),this._nearPlaneCorners[3].set(n,i,0)}}_collisionTest(){let e=1/0;if(!(this.colliderMeshes.length>=1))return e;if(bs(this._camera,"_collisionTest"))return e;const t=this._getTargetDirection(js);Ks.lookAt(Es,t,this._camera.up);for(let n=0;n<4;n++){const s=As.copy(this._nearPlaneCorners[n]);s.applyMatrix4(Ks);const r=Ls.addVectors(this._target,s);qs.set(r,t),qs.far=this._spherical.radius+1;const i=qs.intersectObjects(this.colliderMeshes);0!==i.length&&i[0].distance<e&&(e=i[0].distance)}return e}_getClientRect(e){if(!this._domElement)return;const t=this._domElement.getBoundingClientRect();return e.x=t.left,e.y=t.top,this._viewport?(e.x+=this._viewport.x,e.y+=t.height-this._viewport.w-this._viewport.y,e.width=this._viewport.z,e.height=this._viewport.w):(e.width=t.width,e.height=t.height),e}_createOnRestPromise(e){return e?Promise.resolve():(this._hasRested=!1,t