gl-draw 0.10.39 → 0.10.41

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.
@@ -27,7 +27,12 @@ export default class {
27
27
  constructor(options: Options);
28
28
  setSize(width: number, height: number): void;
29
29
  addCamera2(): THREE.PerspectiveCamera;
30
- syncCamera: THREE.PerspectiveCamera | null;
30
+ syncCamera: THREE.PerspectiveCamera | {
31
+ fov: number;
32
+ viewMatrix: any;
33
+ inverseViewMatrix: any;
34
+ type?: string;
35
+ } | null;
31
36
  sync(): void;
32
37
  setGui(gui: GUI): void;
33
38
  }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var ge=Object.defineProperty,ye=Object.defineProperties;var Ee=Object.getOwnPropertyDescriptors;var Qt=Object.getOwnPropertySymbols;var Ce=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable;var jt=(d,t,e)=>t in d?ge(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,it=(d,t)=>{for(var e in t||(t={}))Ce.call(t,e)&&jt(d,e,t[e]);if(Qt)for(var e of Qt(t))Te.call(t,e)&&jt(d,e,t[e]);return d},zt=(d,t)=>ye(d,Ee(t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("three"),Oe=require("@tweenjs/tween.js"),pe=require("./events.js"),we=require("deepmerge"),ve=require("stats-gl"),xe=require("lil-gui"),Pe=require("./colorCorrection.js"),be=require("./disposeMesh.js");require("idb-keyval");require("esus-lite");require("d3-geo");require("d3-geo-projection");const Se=require("three/examples/jsm/helpers/RectAreaLightHelper"),Me=require("three/examples/jsm/renderers/CSS3DRenderer"),De=require("three/examples/jsm/renderers/CSS2DRenderer"),qt=require("three/examples/jsm/postprocessing/EffectComposer"),Ae=require("three/examples/jsm/postprocessing/RenderPass"),Le=require("three/examples/jsm/postprocessing/Pass"),Ue=require("three/examples/jsm/postprocessing/OutputPass"),Re=require("three/examples/jsm/postprocessing/ShaderPass"),ze=require("three/examples/jsm/postprocessing/UnrealBloomPass"),Ie=require("./isPlainObject.js"),Fe=require("./BaseObject.js");function _e(d){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(d){for(const e in d)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(d,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>d[e]})}}return t.default=d,Object.freeze(t)}const b=_e(n),Wt=_e(Oe),R={LEFT:1,RIGHT:2,MIDDLE:4},h=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}),ot={NONE:0,IN:1,OUT:-1};function q(d){return d.isPerspectiveCamera}function j(d){return d.isOrthographicCamera}const rt=Math.PI*2,Kt=Math.PI/2,ue=1e-5,ht=Math.PI/180;function B(d,t,e){return Math.max(t,Math.min(e,d))}function L(d,t=ue){return Math.abs(d)<t}function M(d,t,e=ue){return L(d-t,e)}function $t(d,t){return Math.round(d/t)*t}function lt(d){return isFinite(d)?d:d<0?-Number.MAX_VALUE:Number.MAX_VALUE}function ct(d){return Math.abs(d)<Number.MAX_VALUE?d:d*(1/0)}function Ot(d,t,e,s,o=1/0,r){s=Math.max(1e-4,s);const i=2/s,a=i*r,l=1/(1+a+.48*a*a+.235*a*a*a);let m=d-t;const E=t,_=o*s;m=B(m,-_,_),t=d-m;const C=(e.value+i*m)*r;e.value=(e.value-i*C)*l;let y=t+(m+C)*l;return E-d>0==y>E&&(y=E,e.value=(y-E)/r),y}function Jt(d,t,e,s,o=1/0,r,i){s=Math.max(1e-4,s);const a=2/s,l=a*r,m=1/(1+l+.48*l*l+.235*l*l*l);let E=t.x,_=t.y,C=t.z,y=d.x-E,P=d.y-_,u=d.z-C;const w=E,c=_,p=C,f=o*s,g=f*f,v=y*y+P*P+u*u;if(v>g){const I=Math.sqrt(v);y=y/I*f,P=P/I*f,u=u/I*f}E=d.x-y,_=d.y-P,C=d.z-u;const T=(e.x+a*y)*r,A=(e.y+a*P)*r,z=(e.z+a*u)*r;e.x=(e.x-a*T)*m,e.y=(e.y-a*A)*m,e.z=(e.z-a*z)*m,i.x=E+(y+T)*m,i.y=_+(P+A)*m,i.z=C+(u+z)*m;const tt=w-d.x,et=c-d.y,Lt=p-d.z,Ut=i.x-w,Rt=i.y-c,V=i.z-p;return tt*Ut+et*Rt+Lt*V>0&&(i.x=w,i.y=c,i.z=p,e.x=(i.x-w)/r,e.y=(i.y-c)/r,e.z=(i.z-p)/r),i}function It(d,t){t.set(0,0),d.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=d.length,t.y/=d.length}function Ft(d,t){return j(d)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}class He{constructor(){this._listeners={}}addEventListener(t,e){const s=this._listeners;s[t]===void 0&&(s[t]=[]),s[t].indexOf(e)===-1&&s[t].push(e)}hasEventListener(t,e){const s=this._listeners;return s[t]!==void 0&&s[t].indexOf(e)!==-1}removeEventListener(t,e){const o=this._listeners[t];if(o!==void 0){const r=o.indexOf(e);r!==-1&&o.splice(r,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const s=this._listeners[t.type];if(s!==void 0){t.target=this;const o=s.slice(0);for(let r=0,i=o.length;r<i;r++)o[r].call(this,t)}}}const wt=1/8,Ye=/Mac/.test(navigator.platform);let O,te,vt,Ht,Y,x,S,nt,dt,N,G,W,ee,se,k,mt,at,ie,Yt,oe,kt,Vt,xt;class J extends He{static install(t){O=t.THREE,te=Object.freeze(new O.Vector3(0,0,0)),vt=Object.freeze(new O.Vector3(0,1,0)),Ht=Object.freeze(new O.Vector3(0,0,1)),Y=new O.Vector2,x=new O.Vector3,S=new O.Vector3,nt=new O.Vector3,dt=new O.Vector3,N=new O.Vector3,G=new O.Vector3,W=new O.Vector3,ee=new O.Vector3,se=new O.Vector3,k=new O.Spherical,mt=new O.Spherical,at=new O.Box3,ie=new O.Box3,Yt=new O.Sphere,oe=new O.Quaternion,kt=new O.Quaternion,Vt=new O.Matrix4,xt=new O.Raycaster}static get ACTION(){return h}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.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=h.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=ot.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new O.Vector3,this._focalOffsetVelocity=new O.Vector3,this._zoomVelocity={value:0},this._truckInternal=(c,p,f)=>{let g,v;if(q(this._camera)){const T=x.copy(this._camera.position).sub(this._target),A=this._camera.getEffectiveFOV()*ht,z=T.length()*Math.tan(A*.5);g=this.truckSpeed*c*z/this._elementRect.height,v=this.truckSpeed*p*z/this._elementRect.height}else if(j(this._camera)){const T=this._camera;g=c*(T.right-T.left)/T.zoom/this._elementRect.width,v=p*(T.top-T.bottom)/T.zoom/this._elementRect.height}else return;this.verticalDragToForward?(f?this.setFocalOffset(this._focalOffsetEnd.x+g,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(g,0,!0),this.forward(-v,!0)):f?this.setFocalOffset(this._focalOffsetEnd.x+g,this._focalOffsetEnd.y+v,this._focalOffsetEnd.z,!0):this.truck(g,v,!0)},this._rotateInternal=(c,p)=>{const f=rt*this.azimuthRotateSpeed*c/this._elementRect.height,g=rt*this.polarRotateSpeed*p/this._elementRect.height;this.rotate(f,g,!0)},this._dollyInternal=(c,p,f)=>{const g=Math.pow(.95,-c*this.dollySpeed),v=this._sphericalEnd.radius,T=this._sphericalEnd.radius*g,A=B(T,this.minDistance,this.maxDistance),z=A-T;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(T,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(z,!0),this._dollyToNoClamp(A,!0)):this._dollyToNoClamp(A,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?T:A)-v,this._dollyControlCoord.set(p,f)),this._lastDollyDirection=Math.sign(-c)},this._zoomInternal=(c,p,f)=>{const g=Math.pow(.95,c*this.dollySpeed),v=this._zoom,T=this._zoom*g;this.zoomTo(T,!0),this.dollyToCursor&&(this._changedZoom+=T-v,this._dollyControlCoord.set(p,f))},typeof O=="undefined"&&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 O.Quaternion().setFromUnitVectors(this._camera.up,vt),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=h.NONE,this._target=new O.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new O.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new O.Spherical().setFromVector3(x.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 O.Vector3,new O.Vector3,new O.Vector3,new O.Vector3],this._updateNearPlaneCorners(),this._boundary=new O.Box3(new O.Vector3(-1/0,-1/0,-1/0),new O.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 O.Vector2,this.mouseButtons={left:h.ROTATE,middle:h.DOLLY,right:h.TRUCK,wheel:q(this._camera)?h.DOLLY:j(this._camera)?h.ZOOM:h.NONE},this.touches={one:h.TOUCH_ROTATE,two:q(this._camera)?h.TOUCH_DOLLY_TRUCK:j(this._camera)?h.TOUCH_ZOOM_TRUCK:h.NONE,three:h.TOUCH_TRUCK};const s=new O.Vector2,o=new O.Vector2,r=new O.Vector2,i=c=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const g=this._domElement.getBoundingClientRect(),v=(c.clientX-g.left)/(g.right-g.left),T=(c.clientY-g.top)/(g.bottom-g.top);if(v<this._interactiveArea.left||v>this._interactiveArea.right||T<this._interactiveArea.top||T>this._interactiveArea.bottom)return}const p=c.pointerType!=="mouse"?null:(c.buttons&R.LEFT)===R.LEFT?R.LEFT:(c.buttons&R.MIDDLE)===R.MIDDLE?R.MIDDLE:(c.buttons&R.RIGHT)===R.RIGHT?R.RIGHT:null;if(p!==null){const g=this._findPointerByMouseButton(p);g&&this._disposePointer(g)}if((c.buttons&R.LEFT)===R.LEFT&&this._lockedPointer)return;const f={pointerId:c.pointerId,clientX:c.clientX,clientY:c.clientY,deltaX:0,deltaY:0,mouseButton:p};this._activePointers.push(f),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),this._isDragging=!0,C(c)},a=c=>{c.cancelable&&c.preventDefault();const p=c.pointerId,f=this._lockedPointer||this._findPointerById(p);if(f){if(f.clientX=c.clientX,f.clientY=c.clientY,f.deltaX=c.movementX,f.deltaY=c.movementY,this._state=0,c.pointerType==="touch")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;break}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(c.buttons&R.LEFT)===R.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(c.buttons&R.MIDDLE)===R.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(c.buttons&R.RIGHT)===R.RIGHT&&(this._state=this._state|this.mouseButtons.right);y()}},l=c=>{const p=this._findPointerById(c.pointerId);if(!(p&&p===this._lockedPointer)){if(p&&this._disposePointer(p),c.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=h.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;break}else this._state=h.NONE;P()}};let m=-1;const E=c=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===h.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const T=this._domElement.getBoundingClientRect(),A=(c.clientX-T.left)/(T.right-T.left),z=(c.clientY-T.top)/(T.bottom-T.top);if(A<this._interactiveArea.left||A>this._interactiveArea.right||z<this._interactiveArea.top||z>this._interactiveArea.bottom)return}if(c.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===h.ROTATE||this.mouseButtons.wheel===h.TRUCK){const T=performance.now();m-T<1e3&&this._getClientRect(this._elementRect),m=T}const p=Ye?-1:-3,f=c.deltaMode===1?c.deltaY/p:c.deltaY/(p*10),g=this.dollyToCursor?(c.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,v=this.dollyToCursor?(c.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case h.ROTATE:{this._rotateInternal(c.deltaX,c.deltaY),this._isUserControllingRotate=!0;break}case h.TRUCK:{this._truckInternal(c.deltaX,c.deltaY,!1),this._isUserControllingTruck=!0;break}case h.OFFSET:{this._truckInternal(c.deltaX,c.deltaY,!0),this._isUserControllingOffset=!0;break}case h.DOLLY:{this._dollyInternal(-f,g,v),this._isUserControllingDolly=!0;break}case h.ZOOM:{this._zoomInternal(-f,g,v),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},_=c=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===J.ACTION.NONE){const p=c instanceof PointerEvent?c.pointerId:0,f=this._findPointerById(p);f&&this._disposePointer(f),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l);return}c.preventDefault()}},C=c=>{if(!this._enabled)return;if(It(this._activePointers,Y),this._getClientRect(this._elementRect),s.copy(Y),o.copy(Y),this._activePointers.length>=2){const f=Y.x-this._activePointers[1].clientX,g=Y.y-this._activePointers[1].clientY,v=Math.sqrt(f*f+g*g);r.set(0,v);const T=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,A=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;o.set(T,A)}if(this._state=0,!c)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in c&&c.pointerType==="touch")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;break}else!this._lockedPointer&&(c.buttons&R.LEFT)===R.LEFT&&(this._state=this._state|this.mouseButtons.left),(c.buttons&R.MIDDLE)===R.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(c.buttons&R.RIGHT)===R.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&h.ROTATE)===h.ROTATE||(this._state&h.TOUCH_ROTATE)===h.TOUCH_ROTATE||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_ZOOM_ROTATE)===h.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&h.TRUCK)===h.TRUCK||(this._state&h.TOUCH_TRUCK)===h.TOUCH_TRUCK||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&h.DOLLY)===h.DOLLY||(this._state&h.TOUCH_DOLLY)===h.TOUCH_DOLLY||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&h.ZOOM)===h.ZOOM||(this._state&h.TOUCH_ZOOM)===h.TOUCH_ZOOM||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&h.OFFSET)===h.OFFSET||(this._state&h.TOUCH_OFFSET)===h.TOUCH_OFFSET||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},y=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,It(this._activePointers,Y);const p=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,f=p?-p.deltaX:o.x-Y.x,g=p?-p.deltaY:o.y-Y.y;if(o.copy(Y),((this._state&h.ROTATE)===h.ROTATE||(this._state&h.TOUCH_ROTATE)===h.TOUCH_ROTATE||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(f,g),this._isUserControllingRotate=!0),(this._state&h.DOLLY)===h.DOLLY||(this._state&h.ZOOM)===h.ZOOM){const v=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,T=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,A=this.dollyDragInverted?-1:1;(this._state&h.DOLLY)===h.DOLLY?(this._dollyInternal(A*g*wt,v,T),this._isUserControllingDolly=!0):(this._zoomInternal(A*g*wt,v,T),this._isUserControllingZoom=!0)}if((this._state&h.TOUCH_DOLLY)===h.TOUCH_DOLLY||(this._state&h.TOUCH_ZOOM)===h.TOUCH_ZOOM||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE){const v=Y.x-this._activePointers[1].clientX,T=Y.y-this._activePointers[1].clientY,A=Math.sqrt(v*v+T*T),z=r.y-A;r.set(0,A);const tt=this.dollyToCursor?(o.x-this._elementRect.x)/this._elementRect.width*2-1:0,et=this.dollyToCursor?(o.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&h.TOUCH_DOLLY)===h.TOUCH_DOLLY||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET?(this._dollyInternal(z*wt,tt,et),this._isUserControllingDolly=!0):(this._zoomInternal(z*wt,tt,et),this._isUserControllingZoom=!0)}((this._state&h.TRUCK)===h.TRUCK||(this._state&h.TOUCH_TRUCK)===h.TOUCH_TRUCK||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(f,g,!1),this._isUserControllingTruck=!0),((this._state&h.OFFSET)===h.OFFSET||(this._state&h.TOUCH_OFFSET)===h.TOUCH_OFFSET||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(f,g,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},P=()=>{It(this._activePointers,Y),o.copy(Y),this._dragNeedsUpdate=!1,(this._activePointers.length===0||this._activePointers.length===1&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),this._activePointers.length===0&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),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",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",u),this._domElement.ownerDocument.addEventListener("pointerlockerror",w),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),C())},this.unlockPointer=()=>{var c,p,f;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(c=this._domElement)===null||c===void 0||c.ownerDocument.exitPointerLock(),(p=this._domElement)===null||p===void 0||p.ownerDocument.removeEventListener("pointerlockchange",u),(f=this._domElement)===null||f===void 0||f.ownerDocument.removeEventListener("pointerlockerror",w),this.cancel()};const u=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},w=()=>{this.unlockPointer()};this._addAllEventListeners=c=>{this._domElement=c,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",i),this._domElement.addEventListener("pointercancel",l),this._domElement.addEventListener("wheel",E,{passive:!1}),this._domElement.addEventListener("contextmenu",_)},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",l),this._domElement.removeEventListener("wheel",E,{passive:!1}),this._domElement.removeEventListener("contextmenu",_),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.removeEventListener("pointerlockchange",u),this._domElement.ownerDocument.removeEventListener("pointerlockerror",w))},this.cancel=()=>{this._state!==h.NONE&&(this._state=h.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=B(t.width,0,1),this._interactiveArea.height=B(t.height,0,1),this._interactiveArea.x=B(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=B(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,s=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,s)}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,s=!1){this._isUserControllingRotate=!1;const o=B(t,this.minAzimuthAngle,this.maxAzimuthAngle),r=B(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=o,this._sphericalEnd.phi=r,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const i=!s||M(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&M(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(i)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=ot.NONE,this._changedDolly=0,this._dollyToNoClamp(B(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const i=this._collisionTest(),a=M(i,this._spherical.radius);if(!(s>t)&&a)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,i)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const r=!e||M(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(r)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(dt).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const s=!e||M(this._target.x,this._targetEnd.x,this.restThreshold)&&M(this._target.y,this._targetEnd.y,this.restThreshold)&&M(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=B(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const s=!e||M(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(s)}pan(t,e,s=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,s)}truck(t,e,s=!1){this._camera.updateMatrix(),N.setFromMatrixColumn(this._camera.matrix,0),G.setFromMatrixColumn(this._camera.matrix,1),N.multiplyScalar(t),G.multiplyScalar(-e);const o=x.copy(N).add(G),r=S.copy(this._targetEnd).add(o);return this.moveTo(r.x,r.y,r.z,s)}forward(t,e=!1){x.setFromMatrixColumn(this._camera.matrix,0),x.crossVectors(this._camera.up,x),x.multiplyScalar(t);const s=S.copy(this._targetEnd).add(x);return this.moveTo(s.x,s.y,s.z,e)}elevate(t,e=!1){return x.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+x.x,this._targetEnd.y+x.y,this._targetEnd.z+x.z,e)}moveTo(t,e,s,o=!1){this._isUserControllingTruck=!1;const r=x.set(t,e,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,r,this.boundaryFriction),this._needsUpdate=!0,o||this._target.copy(this._targetEnd);const i=!o||M(this._target.x,this._targetEnd.x,this.restThreshold)&&M(this._target.y,this._targetEnd.y,this.restThreshold)&&M(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(i)}lookInDirectionOf(t,e,s,o=!1){const a=x.set(t,e,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(a.x,a.y,a.z,o)}fitToBox(t,e,{cover:s=!1,paddingLeft:o=0,paddingRight:r=0,paddingBottom:i=0,paddingTop:a=0}={}){const l=[],m=t.isBox3?at.copy(t):at.setFromObject(t);m.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const E=$t(this._sphericalEnd.theta,Kt),_=$t(this._sphericalEnd.phi,Kt);l.push(this.rotateTo(E,_,e));const C=x.setFromSpherical(this._sphericalEnd).normalize(),y=oe.setFromUnitVectors(C,Ht),P=M(Math.abs(C.y),1);P&&y.multiply(kt.setFromAxisAngle(vt,E)),y.multiply(this._yAxisUpSpaceInverse);const u=ie.makeEmpty();S.copy(m.min).applyQuaternion(y),u.expandByPoint(S),S.copy(m.min).setX(m.max.x).applyQuaternion(y),u.expandByPoint(S),S.copy(m.min).setY(m.max.y).applyQuaternion(y),u.expandByPoint(S),S.copy(m.max).setZ(m.min.z).applyQuaternion(y),u.expandByPoint(S),S.copy(m.min).setZ(m.max.z).applyQuaternion(y),u.expandByPoint(S),S.copy(m.max).setY(m.min.y).applyQuaternion(y),u.expandByPoint(S),S.copy(m.max).setX(m.min.x).applyQuaternion(y),u.expandByPoint(S),S.copy(m.max).applyQuaternion(y),u.expandByPoint(S),u.min.x-=o,u.min.y-=i,u.max.x+=r,u.max.y+=a,y.setFromUnitVectors(Ht,C),P&&y.premultiply(kt.invert()),y.premultiply(this._yAxisUpSpace);const w=u.getSize(x),c=u.getCenter(S).applyQuaternion(y);if(q(this._camera)){const p=this.getDistanceToFitBox(w.x,w.y,w.z,s);l.push(this.moveTo(c.x,c.y,c.z,e)),l.push(this.dollyTo(p,e)),l.push(this.setFocalOffset(0,0,0,e))}else if(j(this._camera)){const p=this._camera,f=p.right-p.left,g=p.top-p.bottom,v=s?Math.max(f/w.x,g/w.y):Math.min(f/w.x,g/w.y);l.push(this.moveTo(c.x,c.y,c.z,e)),l.push(this.zoomTo(v,e)),l.push(this.setFocalOffset(0,0,0,e))}return Promise.all(l)}fitToSphere(t,e){const s=[],r="isObject3D"in t?J.createBoundingSphere(t,Yt):Yt.copy(t);if(s.push(this.moveTo(r.center.x,r.center.y,r.center.z,e)),q(this._camera)){const i=this.getDistanceToFitSphere(r.radius);s.push(this.dollyTo(i,e))}else if(j(this._camera)){const i=this._camera.right-this._camera.left,a=this._camera.top-this._camera.bottom,l=2*r.radius,m=Math.min(i/l,a/l);s.push(this.zoomTo(m,e))}return s.push(this.setFocalOffset(0,0,0,e)),Promise.all(s)}setLookAt(t,e,s,o,r,i,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=ot.NONE,this._changedDolly=0;const l=S.set(o,r,i),m=x.set(t,e,s);this._targetEnd.copy(l),this._sphericalEnd.setFromVector3(m.sub(l).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,a||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const E=!a||M(this._target.x,this._targetEnd.x,this.restThreshold)&&M(this._target.y,this._targetEnd.y,this.restThreshold)&&M(this._target.z,this._targetEnd.z,this.restThreshold)&&M(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&M(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&M(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(E)}lerpLookAt(t,e,s,o,r,i,a,l,m,E,_,C,y,P=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=ot.NONE,this._changedDolly=0;const u=x.set(o,r,i),w=S.set(t,e,s);k.setFromVector3(w.sub(u).applyQuaternion(this._yAxisUpSpace));const c=nt.set(E,_,C),p=S.set(a,l,m);mt.setFromVector3(p.sub(c).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(u.lerp(c,y));const f=mt.theta-k.theta,g=mt.phi-k.phi,v=mt.radius-k.radius;this._sphericalEnd.set(k.radius+v*y,k.phi+g*y,k.theta+f*y),this.normalizeRotations(),this._needsUpdate=!0,P||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const T=!P||M(this._target.x,this._targetEnd.x,this.restThreshold)&&M(this._target.y,this._targetEnd.y,this.restThreshold)&&M(this._target.z,this._targetEnd.z,this.restThreshold)&&M(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&M(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&M(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(T)}setPosition(t,e,s,o=!1){return this.setLookAt(t,e,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,o)}setTarget(t,e,s,o=!1){const r=this.getPosition(x),i=this.setLookAt(r.x,r.y,r.z,t,e,s,o);return this._sphericalEnd.phi=B(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),i}setFocalOffset(t,e,s,o=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,s),this._needsUpdate=!0,o||this._focalOffset.copy(this._focalOffsetEnd);const r=!o||M(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&M(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&M(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}setOrbitPoint(t,e,s){this._camera.updateMatrixWorld(),N.setFromMatrixColumn(this._camera.matrixWorldInverse,0),G.setFromMatrixColumn(this._camera.matrixWorldInverse,1),W.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const o=x.set(t,e,s),r=o.distanceTo(this._camera.position),i=o.sub(this._camera.position);N.multiplyScalar(i.x),G.multiplyScalar(i.y),W.multiplyScalar(i.z),x.copy(N).add(G).add(W),x.z=x.z+r,this.dollyTo(r,!1),this.setFocalOffset(-x.x,x.y,-x.z,!1),this.moveTo(t,e,s,!1)}setBoundary(t){if(!t){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,s,o){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new O.Vector4,typeof t=="number"?this._viewport.set(t,e,s,o):this._viewport.copy(t)}getDistanceToFitBox(t,e,s,o=!1){if(Ft(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const r=t/e,i=this._camera.getEffectiveFOV()*ht,a=this._camera.aspect;return((o?r>a:r<a)?e:t/a)*.5/Math.tan(i*.5)+s*.5}getDistanceToFitSphere(t){if(Ft(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*ht,s=Math.atan(Math.tan(e*.5)*this._camera.aspect)*2,o=1<this._camera.aspect?e:s;return t/Math.sin(o*.5)}getTarget(t,e=!0){return(t&&t.isVector3?t:new O.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new O.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new O.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new O.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%rt,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=rt),this._spherical.theta+=rt*Math.round((this._sphericalEnd.theta-this._spherical.theta)/rt)}reset(t=!1){if(!M(this._camera.up.x,this._cameraUp0.x)||!M(this._camera.up.y,this._cameraUp0.y)||!M(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(x);this.updateCameraUp(),this.setPosition(s.x,s.y,s.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,vt),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=x.subVectors(this._target,this._camera.position).normalize(),e=S.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const s=this.getPosition(x);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}update(t){const e=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,o=this._sphericalEnd.radius-this._spherical.radius,r=ee.subVectors(this._targetEnd,this._target),i=se.subVectors(this._focalOffsetEnd,this._focalOffset),a=this._zoomEnd-this._zoom;if(L(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const _=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Ot(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,_,1/0,t),this._needsUpdate=!0}if(L(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const _=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Ot(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,_,1/0,t),this._needsUpdate=!0}if(L(o))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const _=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Ot(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,_,this.maxSpeed,t),this._needsUpdate=!0}if(L(r.x)&&L(r.y)&&L(r.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const _=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Jt(this._target,this._targetEnd,this._targetVelocity,_,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(L(i.x)&&L(i.y)&&L(i.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const _=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Jt(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,_,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(L(a))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const _=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Ot(this._zoom,this._zoomEnd,this._zoomVelocity,_,1/0,t)}if(this.dollyToCursor){if(q(this._camera)&&this._changedDolly!==0){const _=this._spherical.radius-this._lastDistance,C=this._camera,y=this._getCameraDirection(dt),P=x.copy(y).cross(C.up).normalize();P.lengthSq()===0&&(P.x=1);const u=S.crossVectors(P,y),w=this._sphericalEnd.radius*Math.tan(C.getEffectiveFOV()*ht*.5),p=(this._sphericalEnd.radius-_-this._sphericalEnd.radius)/this._sphericalEnd.radius,f=nt.copy(this._targetEnd).add(P.multiplyScalar(this._dollyControlCoord.x*w*C.aspect)).add(u.multiplyScalar(this._dollyControlCoord.y*w)),g=x.copy(this._targetEnd).lerp(f,p),v=this._lastDollyDirection===ot.IN&&this._spherical.radius<=this.minDistance,T=this._lastDollyDirection===ot.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(v||T)){this._sphericalEnd.radius-=_,this._spherical.radius-=_;const z=S.copy(y).multiplyScalar(-_);g.add(z)}this._boundary.clampPoint(g,g);const A=S.subVectors(g,this._targetEnd);this._targetEnd.copy(g),this._target.add(A),this._changedDolly-=_,L(this._changedDolly)&&(this._changedDolly=0)}else if(j(this._camera)&&this._changedZoom!==0){const _=this._zoom-this._lastZoom,C=this._camera,y=x.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(C.near+C.far)/(C.near-C.far)).unproject(C),P=S.set(0,0,-1).applyQuaternion(C.quaternion),u=nt.copy(y).add(P.multiplyScalar(-y.dot(C.up))),c=-(this._zoom-_-this._zoom)/this._zoom,p=this._getCameraDirection(dt),f=this._targetEnd.dot(p),g=x.copy(this._targetEnd).lerp(u,c),v=g.dot(p),T=p.multiplyScalar(v-f);g.sub(T),this._boundary.clampPoint(g,g);const A=S.subVectors(g,this._targetEnd);this._targetEnd.copy(g),this._target.add(A),this._changedZoom-=_,L(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 l=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,l),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!L(this._focalOffset.x)||!L(this._focalOffset.y)||!L(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),N.setFromMatrixColumn(this._camera.matrix,0),G.setFromMatrixColumn(this._camera.matrix,1),W.setFromMatrixColumn(this._camera.matrix,2),N.multiplyScalar(this._focalOffset.x),G.multiplyScalar(-this._focalOffset.y),W.multiplyScalar(this._focalOffset.z),x.copy(N).add(G).add(W),this._camera.position.add(x)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),x.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const E=this._needsUpdate;return E&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):E?(this.dispatchEvent({type:"update"}),L(e,this.restThreshold)&&L(s,this.restThreshold)&&L(o,this.restThreshold)&&L(r.x,this.restThreshold)&&L(r.y,this.restThreshold)&&L(r.z,this.restThreshold)&&L(i.x,this.restThreshold)&&L(i.y,this.restThreshold)&&L(i.z,this.restThreshold)&&L(a,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!E&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=E,this._needsUpdate=!1,E}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:lt(this.maxDistance),minZoom:this.minZoom,maxZoom:lt(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:lt(this.maxPolarAngle),minAzimuthAngle:lt(this.minAzimuthAngle),maxAzimuthAngle:lt(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:x.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 s=JSON.parse(t);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=ct(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=ct(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=ct(s.maxPolarAngle),this.minAzimuthAngle=ct(s.minAzimuthAngle),this.maxAzimuthAngle=ct(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this.verticalDragToForward=s.verticalDragToForward,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],e),k.setFromVector3(x.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(k.theta,k.phi,e),this.dollyTo(k.radius,e),this.zoomTo(s.zoom,e),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],e),this._needsUpdate=!0}connect(t){if(this._domElement){console.warn("camera-controls is already connected.");return}this._addAllEventListeners(t),this._getClientRect(this._elementRect)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(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,s){const o=e.lengthSq();if(o===0)return t;const r=S.copy(e).add(t),a=this._boundary.clampPoint(r,nt).sub(r),l=a.lengthSq();if(l===0)return t.add(e);if(l===o)return t;if(s===0)return t.add(e).add(a);{const m=1+s*l/e.dot(a);return t.add(S.copy(e).multiplyScalar(m)).add(a.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(q(this._camera)){const t=this._camera,e=t.near,s=t.getEffectiveFOV()*ht,o=Math.tan(s*.5)*e,r=o*t.aspect;this._nearPlaneCorners[0].set(-r,-o,0),this._nearPlaneCorners[1].set(r,-o,0),this._nearPlaneCorners[2].set(r,o,0),this._nearPlaneCorners[3].set(-r,o,0)}else if(j(this._camera)){const t=this._camera,e=1/t.zoom,s=t.left*e,o=t.right*e,r=t.top*e,i=t.bottom*e;this._nearPlaneCorners[0].set(s,r,0),this._nearPlaneCorners[1].set(o,r,0),this._nearPlaneCorners[2].set(o,i,0),this._nearPlaneCorners[3].set(s,i,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||Ft(this._camera,"_collisionTest"))return t;const s=this._getTargetDirection(dt);Vt.lookAt(te,s,this._camera.up);for(let o=0;o<4;o++){const r=S.copy(this._nearPlaneCorners[o]);r.applyMatrix4(Vt);const i=nt.addVectors(this._target,r);xt.set(i,s),xt.far=this._spherical.radius+1;const a=xt.intersectObjects(this.colliderMeshes);a.length!==0&&a[0].distance<t&&(t=a[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(e=>{const s=()=>{this.removeEventListener("rest",s),e()};this.addEventListener("rest",s)}))}_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 O.Sphere){const s=e,o=s.center;at.makeEmpty(),t.traverseVisible(i=>{i.isMesh&&at.expandByObject(i)}),at.getCenter(o);let r=0;return t.traverseVisible(i=>{if(!i.isMesh)return;const a=i,l=a.geometry.clone();l.applyMatrix4(a.matrixWorld);const E=l.attributes.position;for(let _=0,C=E.count;_<C;_++)x.fromBufferAttribute(E,_),r=Math.max(r,o.distanceToSquared(x))}),s.radius=Math.sqrt(r),s}}const ke={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:Pe.ColorSpace.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1,physicallyCorrectLights:!1};class Ve{constructor(t){this.options=t;const{width:e,height:s,rendererParams:o}=t,{canvas:r,context:i,alpha:a,devicePixelRatio:l,antialias:m,powerPreference:E,toneMappingExposure:_,outputColorSpace:C,logarithmicDepthBuffer:y,preserveDrawingBuffer:P,stencil:u,depth:w,physicallyCorrectLights:c}=o,p=new b.WebGLRenderer({canvas:r,context:i,alpha:a,antialias:m,powerPreference:E,logarithmicDepthBuffer:y,preserveDrawingBuffer:P,stencil:u,depth:w});p.setSize(e,s),p.setPixelRatio(l),p.toneMappingExposure=_,p.outputColorSpace=C,+b.REVISION<155&&(p.useLegacyLights=c),this.renderer=p}setSize(t,e){this.renderer.setSize(t,e)}setPixelRatio(t){this.renderer.setPixelRatio(t)}render(t){const{scene:e,camera:s}=this.options;this.renderer.render(e,t||s)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}const Ze={antialias:!0,devicePixelRatio:window.devicePixelRatio};class Be{constructor(t){this.options=t;const{width:e,height:s,rendererParams:o,renderer:r}=t,{devicePixelRatio:i,antialias:a}=o,l=new r({antialias:a});l.setSize(e,s),l.setPixelRatio(i),this.renderer=l}setSize(t,e){this.renderer.setSize(t,e)}render(t){const{scene:e,camera:s}=this.options;this.renderer.render(e,t||s)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}class Gt{constructor(t){this.guiParams={},t&&(this.guiParams=t)}showGui(t){t&&Object.keys(this.guiParams).forEach(e=>{const s=t.addFolder(e),o=this.guiParams[e];Object.keys(o).forEach(r=>{const{min:i,max:a,step:l,name:m,paramMap:E,items:_,value:C,target:y}=o[r],P=r.toLowerCase().indexOf("color")>-1;let u;const w=typeof C=="undefined"&&y,c=w?y():o[r],p=w?r:"value";_?u=s.add(c,p,_):P?u=s.addColor(c,p):u=s.add(c,p),u=u.name(m||r),typeof i!="undefined"&&(u=u.min(i)),typeof a!="undefined"&&(u=u.max(a)),typeof l!="undefined"&&(u=u.step(l)),u=u.onChange(()=>{this.setTargetValue(e,r,c[p],E)}),w&&u.listen()})})}setTargetValue(t,e,s,o){const{onChange:r,target:i,value:a}=this.guiParams[t][e],l=e.toLowerCase().indexOf("color")>-1;if(i&&!(typeof a=="undefined"&&i)){let E=i();Array.isArray(E)||(E=[E]),E.forEach(_=>{if(_)if(l)try{_[o||e].set(s)}catch(C){e!=="color"&&!o&&console.warn(`${e} is not a color,set paramMap`)}else _[o||e]=s})}r&&r(s)}setTargetValueByParams(){Object.keys(this.guiParams).forEach(t=>{Object.keys(this.guiParams[t]).forEach(e=>{const s=this.guiParams[t][e];typeof s.value!="undefined"&&this.setTargetValue(t,e,s.value,s.paramMap)})})}}const Ne={fov:45,near:1,far:1e3,up:new b.Vector3(0,1,0)};class Ge{constructor(t){this.customCamera=!1,this.syncCamera=null,this.options=t;const{width:e,height:s,cameraParams:o}=t;if(o instanceof b.Camera)this.camera=o,this.customCamera=!0;else{const{fov:r,far:i,near:a,up:l}=o,m=new b.PerspectiveCamera(r,e/s,a,i);m.position.set(0,0,400),m.lookAt(0,0,0),m.up=l,this.camera=m}}setSize(t,e){this.camera instanceof b.PerspectiveCamera&&(this.camera.aspect=t/e),this.camera.updateProjectionMatrix(),this.camera2&&(this.camera2.aspect=t/e,this.camera2.updateProjectionMatrix())}addCamera2(){const t=new b.PerspectiveCamera(this.camera.fov,this.camera.aspect,this.camera.near,this.camera.far);return t.position.copy(this.camera.position),this.camera2=t,t}sync(){this.syncCamera&&!(this.camera.matrixWorld.equals(this.syncCamera.matrixWorld)&&this.camera.far===this.syncCamera.far&&this.camera.near===this.syncCamera.near&&this.camera.fov===this.syncCamera.fov&&this.camera.aspect===this.syncCamera.aspect)&&this.camera.copy(this.syncCamera)}setGui(t){const e=new Gt({camera:zt(it({},this.options.cameraControls?{}:{x:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},y:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},z:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position}}),{near:{min:0,max:1e3,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}},far:{min:0,max:2e4,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}})});this.camera instanceof b.PerspectiveCamera&&(e.guiParams.camera.fov={min:0,max:90,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}),e.showGui(t)}}const Xe={background:null,addCamera:!0};class Qe{constructor(t){this.overrideMaterial=!1,this.options=t;const{camera:e,sceneParams:s}=t,{background:o,addCamera:r}=s,i=new b.Scene;o&&(i.background=o),r&&i.add(e),this.scene=i}dispose(){var t;(t=this.scene)==null||t.traverse(e=>{be.disposeMesh(e)})}}class je{constructor(t){this.helpers={},this.options=t}add(t){const e=t.uuid,{scene:s}=this.options;let o=this.helpers[e];if(o===void 0){if(t.isScene)o=new b.AxesHelper(100);else if(t.isCamera)o=new b.CameraHelper(t);else if(t.isPointLight)o=new b.PointLightHelper(t,1);else if(t.isDirectionalLight)o=new b.DirectionalLightHelper(t,1);else if(t.isSpotLight)o=new b.SpotLightHelper(t);else if(t.isHemisphereLight)o=new b.HemisphereLightHelper(t,10);else if(t.isRectAreaLight)o=new Se.RectAreaLightHelper(t);else{const r=new b.Box3;if(r.setFromObject(t,!0),r.isEmpty()===!1){o=new b.Box3Helper(r);const i=o.material;i.userData.object=t,i.depthTest=!1,i.transparent=!0}else return}s.add(o),this.helpers[e]=o}}remove(t){var o;const e=t.uuid,{scene:s}=this.options;if(this.helpers[e]!==void 0){const r=this.helpers[e];s.remove(r),delete this.helpers[e],(o=r.dispose)==null||o.call(r)}}removeAll(){Object.keys(this.helpers).forEach(t=>{this.remove({uuid:t})}),this.helpers={}}removeAllExcludeScene(){Object.keys(this.helpers).forEach(t=>{this.helpers[t]instanceof b.AxesHelper||this.remove({uuid:t})})}update(){Object.values(this.helpers).forEach(t=>{if(t.update&&t.update(),t instanceof b.Box3Helper){const e=t.material,{object:s}=e.userData;s&&t.box.setFromObject(s,!0)}})}dispose(){this.helpers={}}}class qe{constructor(t){this.autoRotateSpeed=0,this.options=t;const{camera:e,controlsParams:s,customControl:o}=t,{domElement:r}=s;if(o){const i=new o(e,r);i.enableDamping=!0,i.dampingFactor=.063,i.autoRotate=!1,i.autoRotateSpeed=-60,i.enableZoom=!0,i.zoomSpeed=.2,this.controls=i}else J.install({THREE:b}),this.cameraControls=new J(e,r)}addCameraControls2(t){const{controlsParams:e}=this.options,{domElement:s}=e;this.cameraControls2=new J(t,s),this.cameraControls2.addEventListener("update",()=>{this.cameraControls.enabled=!1}),this.cameraControls2.addEventListener("sleep",()=>{this.cameraControls.enabled=!0})}enable(){this.controls?this.controls.enabled=!0:this.cameraControls&&(this.cameraControls.enabled=!0,this.cameraControls2&&(this.cameraControls2.enabled=!0))}disable(){this.controls?this.controls.enabled=!1:this.cameraControls&&(this.cameraControls.enabled=!1,this.cameraControls2&&(this.cameraControls2.enabled=!1))}update(t){var e,s,o;(e=this.controls)==null||e.update(),(s=this.cameraControls)==null||s.update(t),(o=this.cameraControls2)==null||o.update(t),this.autoRotateSpeed&&this.cameraControls&&(this.cameraControls.azimuthAngle+=this.autoRotateSpeed*t*b.MathUtils.DEG2RAD)}dispose(){var t,e,s;(t=this.controls)==null||t.dispose(),(e=this.cameraControls)==null||e.dispose(),(s=this.cameraControls2)==null||s.dispose()}}const K=new n.Raycaster,F=new n.Vector3,Q=new n.Vector3,U=new n.Quaternion,re={X:new n.Vector3(1,0,0),Y:new n.Vector3(0,1,0),Z:new n.Vector3(0,0,1)},Zt={type:"change"},ne={type:"mouseDown",mode:null},ae={type:"mouseUp",mode:null},he={type:"objectChange"};class We extends n.Controls{constructor(t,e=null){super(void 0,e);const s=new ss(this);this._root=s;const o=new is;this._gizmo=o,s.add(o);const r=new os;this._plane=r,s.add(r);const i=this;function a(f,g){let v=g;Object.defineProperty(i,f,{get:function(){return v!==void 0?v:g},set:function(T){v!==T&&(v=T,r[f]=T,o[f]=T,i.dispatchEvent({type:f+"-changed",value:T}),i.dispatchEvent(Zt))}}),i[f]=g,r[f]=g,o[f]=g}a("camera",t),a("object",void 0),a("enabled",!0),a("axis",null),a("mode","translate"),a("translationSnap",null),a("rotationSnap",null),a("scaleSnap",null),a("space","world"),a("size",1),a("dragging",!1),a("showX",!0),a("showY",!0),a("showZ",!0);const l=new n.Vector3,m=new n.Vector3,E=new n.Quaternion,_=new n.Quaternion,C=new n.Vector3,y=new n.Quaternion,P=new n.Vector3,u=new n.Vector3,w=new n.Vector3,c=0,p=new n.Vector3;a("worldPosition",l),a("worldPositionStart",m),a("worldQuaternion",E),a("worldQuaternionStart",_),a("cameraPosition",C),a("cameraQuaternion",y),a("pointStart",P),a("pointEnd",u),a("rotationAxis",w),a("rotationAngle",c),a("eye",p),this._offset=new n.Vector3,this._startNorm=new n.Vector3,this._endNorm=new n.Vector3,this._cameraScale=new n.Vector3,this._parentPosition=new n.Vector3,this._parentQuaternion=new n.Quaternion,this._parentQuaternionInv=new n.Quaternion,this._parentScale=new n.Vector3,this._worldScaleStart=new n.Vector3,this._worldQuaternionInv=new n.Quaternion,this._worldScale=new n.Vector3,this._positionStart=new n.Vector3,this._quaternionStart=new n.Quaternion,this._scaleStart=new n.Vector3,this._getPointer=Ke.bind(this),this._onPointerDown=Je.bind(this),this._onPointerHover=$e.bind(this),this._onPointerMove=ts.bind(this),this._onPointerUp=es.bind(this),e!==null&&this.connect()}connect(){this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="auto"}getHelper(){return this._root}pointerHover(t){if(this.object===void 0||this.dragging===!0)return;t!==null&&K.setFromCamera(t,this.camera);const e=Bt(this._gizmo.picker[this.mode],K);e?this.axis=e.object.name:this.axis=null}pointerDown(t){if(!(this.object===void 0||this.dragging===!0||t!=null&&t.button!==0)&&this.axis!==null){t!==null&&K.setFromCamera(t,this.camera);const e=Bt(this._plane,K,!0);e&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(e.point).sub(this.worldPositionStart)),this.dragging=!0,ne.mode=this.mode,this.dispatchEvent(ne)}}pointerMove(t){const e=this.axis,s=this.mode,o=this.object;let r=this.space;if(s==="scale"?r="local":(e==="E"||e==="XYZE"||e==="XYZ")&&(r="world"),o===void 0||e===null||this.dragging===!1||t!==null&&t.button!==-1)return;t!==null&&K.setFromCamera(t,this.camera);const i=Bt(this._plane,K,!0);if(i){if(this.pointEnd.copy(i.point).sub(this.worldPositionStart),s==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),r==="local"&&e!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),e.indexOf("X")===-1&&(this._offset.x=0),e.indexOf("Y")===-1&&(this._offset.y=0),e.indexOf("Z")===-1&&(this._offset.z=0),r==="local"&&e!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),o.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(r==="local"&&(o.position.applyQuaternion(U.copy(this._quaternionStart).invert()),e.search("X")!==-1&&(o.position.x=Math.round(o.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(o.position.y=Math.round(o.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(o.position.z=Math.round(o.position.z/this.translationSnap)*this.translationSnap),o.position.applyQuaternion(this._quaternionStart)),r==="world"&&(o.parent&&o.position.add(F.setFromMatrixPosition(o.parent.matrixWorld)),e.search("X")!==-1&&(o.position.x=Math.round(o.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(o.position.y=Math.round(o.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(o.position.z=Math.round(o.position.z/this.translationSnap)*this.translationSnap),o.parent&&o.position.sub(F.setFromMatrixPosition(o.parent.matrixWorld))));else if(s==="scale"){if(e.search("XYZ")!==-1){let a=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(a*=-1),Q.set(a,a,a)}else F.copy(this.pointStart),Q.copy(this.pointEnd),F.applyQuaternion(this._worldQuaternionInv),Q.applyQuaternion(this._worldQuaternionInv),Q.divide(F),e.search("X")===-1&&(Q.x=1),e.search("Y")===-1&&(Q.y=1),e.search("Z")===-1&&(Q.z=1);o.scale.copy(this._scaleStart).multiply(Q),this.scaleSnap&&(e.search("X")!==-1&&(o.scale.x=Math.round(o.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Y")!==-1&&(o.scale.y=Math.round(o.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Z")!==-1&&(o.scale.z=Math.round(o.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(s==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const a=20/this.worldPosition.distanceTo(F.setFromMatrixPosition(this.camera.matrixWorld));let l=!1;e==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(F.copy(this.rotationAxis).cross(this.eye))*a):(e==="X"||e==="Y"||e==="Z")&&(this.rotationAxis.copy(re[e]),F.copy(re[e]),r==="local"&&F.applyQuaternion(this.worldQuaternion),F.cross(this.eye),F.length()===0?l=!0:this.rotationAngle=this._offset.dot(F.normalize())*a),(e==="E"||l)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),r==="local"&&e!=="E"&&e!=="XYZE"?(o.quaternion.copy(this._quaternionStart),o.quaternion.multiply(U.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),o.quaternion.copy(U.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),o.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(Zt),this.dispatchEvent(he)}}pointerUp(t){t!==null&&t.button!==0||(this.dragging&&this.axis!==null&&(ae.mode=this.mode,this.dispatchEvent(ae)),this.dragging=!1,this.axis=null)}dispose(){this.disconnect(),this._root.dispose()}attach(t){return this.object=t,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this._root.visible=!1,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(Zt),this.dispatchEvent(he),this.pointStart.copy(this.pointEnd))}getRaycaster(){return K}getMode(){return this.mode}setMode(t){this.mode=t}setTranslationSnap(t){this.translationSnap=t}setRotationSnap(t){this.rotationSnap=t}setScaleSnap(t){this.scaleSnap=t}setSize(t){this.size=t}setSpace(t){this.space=t}}function Ke(d){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:d.button};{const t=this.domElement.getBoundingClientRect();return{x:(d.clientX-t.left)/t.width*2-1,y:-(d.clientY-t.top)/t.height*2+1,button:d.button}}}function $e(d){if(this.enabled)switch(d.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(d));break}}function Je(d){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(d.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(d)),this.pointerDown(this._getPointer(d)))}function ts(d){this.enabled&&this.pointerMove(this._getPointer(d))}function es(d){this.enabled&&(this.domElement.releasePointerCapture(d.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(d)))}function Bt(d,t,e){const s=t.intersectObject(d,!0);for(let o=0;o<s.length;o++)if(s[o].object.visible||e)return s[o];return!1}const Pt=new n.Euler,D=new n.Vector3(0,1,0),le=new n.Vector3(0,0,0),ce=new n.Matrix4,bt=new n.Quaternion,Mt=new n.Quaternion,X=new n.Vector3,de=new n.Matrix4,ft=new n.Vector3(1,0,0),$=new n.Vector3(0,1,0),gt=new n.Vector3(0,0,1),St=new n.Vector3,pt=new n.Vector3,_t=new n.Vector3;class ss extends n.Object3D{constructor(t){super(),this.isTransformControlsRoot=!0,this.controls=t,this.visible=!1}updateMatrixWorld(t){const e=this.controls;e.object!==void 0&&(e.object.updateMatrixWorld(),e.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):e.object.parent.matrixWorld.decompose(e._parentPosition,e._parentQuaternion,e._parentScale),e.object.matrixWorld.decompose(e.worldPosition,e.worldQuaternion,e._worldScale),e._parentQuaternionInv.copy(e._parentQuaternion).invert(),e._worldQuaternionInv.copy(e.worldQuaternion).invert()),e.camera.updateMatrixWorld(),e.camera.matrixWorld.decompose(e.cameraPosition,e.cameraQuaternion,e._cameraScale),e.camera.isOrthographicCamera?e.camera.getWorldDirection(e.eye).negate():e.eye.copy(e.cameraPosition).sub(e.worldPosition).normalize(),super.updateMatrixWorld(t)}dispose(){this.traverse(function(t){t.geometry&&t.geometry.dispose(),t.material&&t.material.dispose()})}}class is extends n.Object3D{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const t=new n.MeshBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),e=new n.LineBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),s=t.clone();s.opacity=.15;const o=e.clone();o.opacity=.5;const r=t.clone();r.color.setHex(16711680);const i=t.clone();i.color.setHex(65280);const a=t.clone();a.color.setHex(255);const l=t.clone();l.color.setHex(16711680),l.opacity=.5;const m=t.clone();m.color.setHex(65280),m.opacity=.5;const E=t.clone();E.color.setHex(255),E.opacity=.5;const _=t.clone();_.opacity=.25;const C=t.clone();C.color.setHex(16776960),C.opacity=.25,t.clone().color.setHex(16776960);const P=t.clone();P.color.setHex(7895160);const u=new n.CylinderGeometry(0,.04,.1,12);u.translate(0,.05,0);const w=new n.BoxGeometry(.08,.08,.08);w.translate(0,.04,0);const c=new n.BufferGeometry;c.setAttribute("position",new n.Float32BufferAttribute([0,0,0,1,0,0],3));const p=new n.CylinderGeometry(.0075,.0075,.5,3);p.translate(0,.25,0);function f(I,yt){const Z=new n.TorusGeometry(I,.0075,3,64,yt*Math.PI*2);return Z.rotateY(Math.PI/2),Z.rotateX(Math.PI/2),Z}function g(){const I=new n.BufferGeometry;return I.setAttribute("position",new n.Float32BufferAttribute([0,0,0,1,1,1],3)),I}const v={X:[[new n.Mesh(u,r),[.5,0,0],[0,0,-Math.PI/2]],[new n.Mesh(u,r),[-.5,0,0],[0,0,Math.PI/2]],[new n.Mesh(p,r),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new n.Mesh(u,i),[0,.5,0]],[new n.Mesh(u,i),[0,-.5,0],[Math.PI,0,0]],[new n.Mesh(p,i)]],Z:[[new n.Mesh(u,a),[0,0,.5],[Math.PI/2,0,0]],[new n.Mesh(u,a),[0,0,-.5],[-Math.PI/2,0,0]],[new n.Mesh(p,a),null,[Math.PI/2,0,0]]],XYZ:[[new n.Mesh(new n.OctahedronGeometry(.1,0),_.clone()),[0,0,0]]],XY:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),E.clone()),[.15,.15,0]]],YZ:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),l.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),m.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},T={X:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[.3,0,0],[0,0,-Math.PI/2]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,.3,0]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,-.3,0],[0,0,Math.PI]]],Z:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,0,.3],[Math.PI/2,0,0]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new n.Mesh(new n.OctahedronGeometry(.2,0),s)]],XY:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),s),[.15,.15,0]]],YZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),s),[.15,0,.15],[-Math.PI/2,0,0]]]},A={START:[[new n.Mesh(new n.OctahedronGeometry(.01,2),o),null,null,null,"helper"]],END:[[new n.Mesh(new n.OctahedronGeometry(.01,2),o),null,null,null,"helper"]],DELTA:[[new n.Line(g(),o),null,null,null,"helper"]],X:[[new n.Line(c,o.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new n.Line(c,o.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new n.Line(c,o.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},z={XYZE:[[new n.Mesh(f(.5,1),P),null,[0,Math.PI/2,0]]],X:[[new n.Mesh(f(.5,.5),r)]],Y:[[new n.Mesh(f(.5,.5),i),null,[0,0,-Math.PI/2]]],Z:[[new n.Mesh(f(.5,.5),a),null,[0,Math.PI/2,0]]],E:[[new n.Mesh(f(.75,1),C),null,[0,Math.PI/2,0]]]},tt={AXIS:[[new n.Line(c,o.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},et={XYZE:[[new n.Mesh(new n.SphereGeometry(.25,10,8),s)]],X:[[new n.Mesh(new n.TorusGeometry(.5,.1,4,24),s),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new n.Mesh(new n.TorusGeometry(.5,.1,4,24),s),[0,0,0],[Math.PI/2,0,0]]],Z:[[new n.Mesh(new n.TorusGeometry(.5,.1,4,24),s),[0,0,0],[0,0,-Math.PI/2]]],E:[[new n.Mesh(new n.TorusGeometry(.75,.1,2,24),s)]]},Lt={X:[[new n.Mesh(w,r),[.5,0,0],[0,0,-Math.PI/2]],[new n.Mesh(p,r),[0,0,0],[0,0,-Math.PI/2]],[new n.Mesh(w,r),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new n.Mesh(w,i),[0,.5,0]],[new n.Mesh(p,i)],[new n.Mesh(w,i),[0,-.5,0],[0,0,Math.PI]]],Z:[[new n.Mesh(w,a),[0,0,.5],[Math.PI/2,0,0]],[new n.Mesh(p,a),[0,0,0],[Math.PI/2,0,0]],[new n.Mesh(w,a),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),E),[.15,.15,0]]],YZ:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),l),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),m),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new n.Mesh(new n.BoxGeometry(.1,.1,.1),_.clone())]]},Ut={X:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[.3,0,0],[0,0,-Math.PI/2]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,.3,0]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,-.3,0],[0,0,Math.PI]]],Z:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,0,.3],[Math.PI/2,0,0]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),s),[.15,.15,0]]],YZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),s),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.2),s),[0,0,0]]]},Rt={X:[[new n.Line(c,o.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new n.Line(c,o.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new n.Line(c,o.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function V(I){const yt=new n.Object3D;for(const Z in I)for(let st=I[Z].length;st--;){const H=I[Z][st][0].clone(),Et=I[Z][st][1],Ct=I[Z][st][2],Tt=I[Z][st][3],fe=I[Z][st][4];H.name=Z,H.tag=fe,Et&&H.position.set(Et[0],Et[1],Et[2]),Ct&&H.rotation.set(Ct[0],Ct[1],Ct[2]),Tt&&H.scale.set(Tt[0],Tt[1],Tt[2]),H.updateMatrix();const Xt=H.geometry.clone();Xt.applyMatrix4(H.matrix),H.geometry=Xt,H.renderOrder=1/0,H.position.set(0,0,0),H.rotation.set(0,0,0),H.scale.set(1,1,1),yt.add(H)}return yt}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=V(v)),this.add(this.gizmo.rotate=V(z)),this.add(this.gizmo.scale=V(Lt)),this.add(this.picker.translate=V(T)),this.add(this.picker.rotate=V(et)),this.add(this.picker.scale=V(Ut)),this.add(this.helper.translate=V(A)),this.add(this.helper.rotate=V(tt)),this.add(this.helper.scale=V(Rt)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(t){const s=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:Mt;this.gizmo.translate.visible=this.mode==="translate",this.gizmo.rotate.visible=this.mode==="rotate",this.gizmo.scale.visible=this.mode==="scale",this.helper.translate.visible=this.mode==="translate",this.helper.rotate.visible=this.mode==="rotate",this.helper.scale.visible=this.mode==="scale";let o=[];o=o.concat(this.picker[this.mode].children),o=o.concat(this.gizmo[this.mode].children),o=o.concat(this.helper[this.mode].children);for(let r=0;r<o.length;r++){const i=o[r];i.visible=!0,i.rotation.set(0,0,0),i.position.copy(this.worldPosition);let a;if(this.camera.isOrthographicCamera?a=(this.camera.top-this.camera.bottom)/this.camera.zoom:a=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),i.scale.set(1,1,1).multiplyScalar(a*this.size/4),i.tag==="helper"){i.visible=!1,i.name==="AXIS"?(i.visible=!!this.axis,this.axis==="X"&&(U.setFromEuler(Pt.set(0,0,0)),i.quaternion.copy(s).multiply(U),Math.abs(D.copy(ft).applyQuaternion(s).dot(this.eye))>.9&&(i.visible=!1)),this.axis==="Y"&&(U.setFromEuler(Pt.set(0,0,Math.PI/2)),i.quaternion.copy(s).multiply(U),Math.abs(D.copy($).applyQuaternion(s).dot(this.eye))>.9&&(i.visible=!1)),this.axis==="Z"&&(U.setFromEuler(Pt.set(0,Math.PI/2,0)),i.quaternion.copy(s).multiply(U),Math.abs(D.copy(gt).applyQuaternion(s).dot(this.eye))>.9&&(i.visible=!1)),this.axis==="XYZE"&&(U.setFromEuler(Pt.set(0,Math.PI/2,0)),D.copy(this.rotationAxis),i.quaternion.setFromRotationMatrix(ce.lookAt(le,D,$)),i.quaternion.multiply(U),i.visible=this.dragging),this.axis==="E"&&(i.visible=!1)):i.name==="START"?(i.position.copy(this.worldPositionStart),i.visible=this.dragging):i.name==="END"?(i.position.copy(this.worldPosition),i.visible=this.dragging):i.name==="DELTA"?(i.position.copy(this.worldPositionStart),i.quaternion.copy(this.worldQuaternionStart),F.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),F.applyQuaternion(this.worldQuaternionStart.clone().invert()),i.scale.copy(F),i.visible=this.dragging):(i.quaternion.copy(s),this.dragging?i.position.copy(this.worldPositionStart):i.position.copy(this.worldPosition),this.axis&&(i.visible=this.axis.search(i.name)!==-1));continue}i.quaternion.copy(s),this.mode==="translate"||this.mode==="scale"?(i.name==="X"&&Math.abs(D.copy(ft).applyQuaternion(s).dot(this.eye))>.99&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="Y"&&Math.abs(D.copy($).applyQuaternion(s).dot(this.eye))>.99&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="Z"&&Math.abs(D.copy(gt).applyQuaternion(s).dot(this.eye))>.99&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="XY"&&Math.abs(D.copy(gt).applyQuaternion(s).dot(this.eye))<.2&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="YZ"&&Math.abs(D.copy(ft).applyQuaternion(s).dot(this.eye))<.2&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="XZ"&&Math.abs(D.copy($).applyQuaternion(s).dot(this.eye))<.2&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1)):this.mode==="rotate"&&(bt.copy(s),D.copy(this.eye).applyQuaternion(U.copy(s).invert()),i.name.search("E")!==-1&&i.quaternion.setFromRotationMatrix(ce.lookAt(this.eye,le,$)),i.name==="X"&&(U.setFromAxisAngle(ft,Math.atan2(-D.y,D.z)),U.multiplyQuaternions(bt,U),i.quaternion.copy(U)),i.name==="Y"&&(U.setFromAxisAngle($,Math.atan2(D.x,D.z)),U.multiplyQuaternions(bt,U),i.quaternion.copy(U)),i.name==="Z"&&(U.setFromAxisAngle(gt,Math.atan2(D.y,D.x)),U.multiplyQuaternions(bt,U),i.quaternion.copy(U))),i.visible=i.visible&&(i.name.indexOf("X")===-1||this.showX),i.visible=i.visible&&(i.name.indexOf("Y")===-1||this.showY),i.visible=i.visible&&(i.name.indexOf("Z")===-1||this.showZ),i.visible=i.visible&&(i.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),i.material._color=i.material._color||i.material.color.clone(),i.material._opacity=i.material._opacity||i.material.opacity,i.material.color.copy(i.material._color),i.material.opacity=i.material._opacity,this.enabled&&this.axis&&(i.name===this.axis||this.axis.split("").some(function(l){return i.name===l}))&&(i.material.color.setHex(16776960),i.material.opacity=1)}super.updateMatrixWorld(t)}}class os extends n.Mesh{constructor(){super(new n.PlaneGeometry(1e5,1e5,2,2),new n.MeshBasicMaterial({visible:!1,wireframe:!0,side:n.DoubleSide,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(t){let e=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(e="local"),St.copy(ft).applyQuaternion(e==="local"?this.worldQuaternion:Mt),pt.copy($).applyQuaternion(e==="local"?this.worldQuaternion:Mt),_t.copy(gt).applyQuaternion(e==="local"?this.worldQuaternion:Mt),D.copy(pt),this.mode){case"translate":case"scale":switch(this.axis){case"X":D.copy(this.eye).cross(St),X.copy(St).cross(D);break;case"Y":D.copy(this.eye).cross(pt),X.copy(pt).cross(D);break;case"Z":D.copy(this.eye).cross(_t),X.copy(_t).cross(D);break;case"XY":X.copy(_t);break;case"YZ":X.copy(St);break;case"XZ":D.copy(_t),X.copy(pt);break;case"XYZ":case"E":X.set(0,0,0);break}break;case"rotate":default:X.set(0,0,0)}X.length()===0?this.quaternion.copy(this.cameraQuaternion):(de.lookAt(F.set(0,0,0),X,D),this.quaternion.setFromRotationMatrix(de)),super.updateMatrixWorld(t)}}class rs{constructor(t){this.event=new pe.eventsExports.EventEmitter;const{renderer:e,scene:s,camera:o}=t,r=new We(o,e.domElement);if(r.getHelper){const i=r.getHelper();s.add(i)}else r instanceof b.Object3D&&s.add(r);this.controls=r,this.addEvent()}get detach(){return this.controls.detach.bind(this.controls)}get attach(){return this.controls.attach.bind(this.controls)}addEvent(){let t=null,e=null,s=null;const o=this.controls;o.addEventListener("change",()=>{const r=o.object;r!==void 0&&this.event.emit("change",r)}),o.addEventListener("mouseDown",()=>{const r=o.object;t=r.position.clone(),e=r.rotation.clone(),s=r.scale.clone(),this.event.emit("mouseDown",r)}),o.addEventListener("mouseUp",()=>{const r=o.object;if(r!==void 0)switch(o.getMode()){case"translate":t.equals(r.position)||this.event.emit("translate",r,r.position,t);break;case"rotate":e.equals(r.rotation)||this.event.emit("rotate",r,r.rotation,e);break;case"scale":s.equals(r.scale)||this.event.emit("scale",r,r.scale,s);break}this.event.emit("mouseUp")})}dispose(){var t;this.event.removeAllListeners(),(t=this.controls)==null||t.dispose()}}const me={zIndex:"auto"};class ns{constructor(t){this.container=t}addRenderer(t,e){const s=e.container||this.container,o=s.offsetWidth,r=s.offsetHeight,i=t==="css2d"?new De.CSS2DRenderer:new Me.CSS3DRenderer;i.domElement.style.position="absolute",i.domElement.style.top="0",i.domElement.style.pointerEvents="none",i.domElement.style.zIndex=e.zIndex,i.setSize(o,r),s.appendChild(i.domElement),t==="css2d"?this.css2Drenderer=i:t==="css3d"&&(this.css3Drenderer=i)}setSize(t,e){var s,o;(s=this.css2Drenderer)==null||s.setSize(t,e),(o=this.css3Drenderer)==null||o.setSize(t,e)}render(t,e){var s,o;(s=this.css2Drenderer)==null||s.render(t,e),(o=this.css3Drenderer)==null||o.render(t,e)}dispose(){var t,e;(t=this.css2Drenderer)==null||t.domElement.remove(),(e=this.css3Drenderer)==null||e.domElement.remove(),this.css2Drenderer=void 0,this.css3Drenderer=void 0}}const as={name:"OutputShader",uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1},premultiplieAlpha:{value:0}},vertexShader:`
1
+ "use strict";var ge=Object.defineProperty,ye=Object.defineProperties;var Ee=Object.getOwnPropertyDescriptors;var Qt=Object.getOwnPropertySymbols;var Ce=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable;var jt=(d,t,e)=>t in d?ge(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,it=(d,t)=>{for(var e in t||(t={}))Ce.call(t,e)&&jt(d,e,t[e]);if(Qt)for(var e of Qt(t))Te.call(t,e)&&jt(d,e,t[e]);return d},zt=(d,t)=>ye(d,Ee(t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("three"),Oe=require("@tweenjs/tween.js"),pe=require("./events.js"),we=require("deepmerge"),ve=require("stats-gl"),xe=require("lil-gui"),Pe=require("./colorCorrection.js"),be=require("./disposeMesh.js");require("idb-keyval");require("esus-lite");require("d3-geo");require("d3-geo-projection");const Se=require("three/examples/jsm/helpers/RectAreaLightHelper"),Me=require("three/examples/jsm/renderers/CSS3DRenderer"),De=require("three/examples/jsm/renderers/CSS2DRenderer"),qt=require("three/examples/jsm/postprocessing/EffectComposer"),Ae=require("three/examples/jsm/postprocessing/RenderPass"),Ue=require("three/examples/jsm/postprocessing/Pass"),Le=require("three/examples/jsm/postprocessing/OutputPass"),Re=require("three/examples/jsm/postprocessing/ShaderPass"),ze=require("three/examples/jsm/postprocessing/UnrealBloomPass"),Ie=require("./isPlainObject.js"),Fe=require("./BaseObject.js");function _e(d){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(d){for(const e in d)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(d,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>d[e]})}}return t.default=d,Object.freeze(t)}const b=_e(n),Wt=_e(Oe),R={LEFT:1,RIGHT:2,MIDDLE:4},h=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}),ot={NONE:0,IN:1,OUT:-1};function q(d){return d.isPerspectiveCamera}function j(d){return d.isOrthographicCamera}const rt=Math.PI*2,Kt=Math.PI/2,ue=1e-5,ht=Math.PI/180;function B(d,t,e){return Math.max(t,Math.min(e,d))}function U(d,t=ue){return Math.abs(d)<t}function M(d,t,e=ue){return U(d-t,e)}function $t(d,t){return Math.round(d/t)*t}function lt(d){return isFinite(d)?d:d<0?-Number.MAX_VALUE:Number.MAX_VALUE}function ct(d){return Math.abs(d)<Number.MAX_VALUE?d:d*(1/0)}function Ot(d,t,e,s,o=1/0,r){s=Math.max(1e-4,s);const i=2/s,a=i*r,l=1/(1+a+.48*a*a+.235*a*a*a);let m=d-t;const E=t,_=o*s;m=B(m,-_,_),t=d-m;const C=(e.value+i*m)*r;e.value=(e.value-i*C)*l;let y=t+(m+C)*l;return E-d>0==y>E&&(y=E,e.value=(y-E)/r),y}function Jt(d,t,e,s,o=1/0,r,i){s=Math.max(1e-4,s);const a=2/s,l=a*r,m=1/(1+l+.48*l*l+.235*l*l*l);let E=t.x,_=t.y,C=t.z,y=d.x-E,P=d.y-_,u=d.z-C;const w=E,c=_,p=C,f=o*s,g=f*f,v=y*y+P*P+u*u;if(v>g){const I=Math.sqrt(v);y=y/I*f,P=P/I*f,u=u/I*f}E=d.x-y,_=d.y-P,C=d.z-u;const T=(e.x+a*y)*r,A=(e.y+a*P)*r,z=(e.z+a*u)*r;e.x=(e.x-a*T)*m,e.y=(e.y-a*A)*m,e.z=(e.z-a*z)*m,i.x=E+(y+T)*m,i.y=_+(P+A)*m,i.z=C+(u+z)*m;const tt=w-d.x,et=c-d.y,Ut=p-d.z,Lt=i.x-w,Rt=i.y-c,k=i.z-p;return tt*Lt+et*Rt+Ut*k>0&&(i.x=w,i.y=c,i.z=p,e.x=(i.x-w)/r,e.y=(i.y-c)/r,e.z=(i.z-p)/r),i}function It(d,t){t.set(0,0),d.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=d.length,t.y/=d.length}function Ft(d,t){return j(d)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}class He{constructor(){this._listeners={}}addEventListener(t,e){const s=this._listeners;s[t]===void 0&&(s[t]=[]),s[t].indexOf(e)===-1&&s[t].push(e)}hasEventListener(t,e){const s=this._listeners;return s[t]!==void 0&&s[t].indexOf(e)!==-1}removeEventListener(t,e){const o=this._listeners[t];if(o!==void 0){const r=o.indexOf(e);r!==-1&&o.splice(r,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const s=this._listeners[t.type];if(s!==void 0){t.target=this;const o=s.slice(0);for(let r=0,i=o.length;r<i;r++)o[r].call(this,t)}}}const wt=1/8,Ye=/Mac/.test(navigator.platform);let O,te,vt,Ht,Y,x,S,nt,dt,N,G,W,ee,se,V,mt,at,ie,Yt,oe,Vt,kt,xt;class J extends He{static install(t){O=t.THREE,te=Object.freeze(new O.Vector3(0,0,0)),vt=Object.freeze(new O.Vector3(0,1,0)),Ht=Object.freeze(new O.Vector3(0,0,1)),Y=new O.Vector2,x=new O.Vector3,S=new O.Vector3,nt=new O.Vector3,dt=new O.Vector3,N=new O.Vector3,G=new O.Vector3,W=new O.Vector3,ee=new O.Vector3,se=new O.Vector3,V=new O.Spherical,mt=new O.Spherical,at=new O.Box3,ie=new O.Box3,Yt=new O.Sphere,oe=new O.Quaternion,Vt=new O.Quaternion,kt=new O.Matrix4,xt=new O.Raycaster}static get ACTION(){return h}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.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=h.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=ot.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new O.Vector3,this._focalOffsetVelocity=new O.Vector3,this._zoomVelocity={value:0},this._truckInternal=(c,p,f)=>{let g,v;if(q(this._camera)){const T=x.copy(this._camera.position).sub(this._target),A=this._camera.getEffectiveFOV()*ht,z=T.length()*Math.tan(A*.5);g=this.truckSpeed*c*z/this._elementRect.height,v=this.truckSpeed*p*z/this._elementRect.height}else if(j(this._camera)){const T=this._camera;g=c*(T.right-T.left)/T.zoom/this._elementRect.width,v=p*(T.top-T.bottom)/T.zoom/this._elementRect.height}else return;this.verticalDragToForward?(f?this.setFocalOffset(this._focalOffsetEnd.x+g,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(g,0,!0),this.forward(-v,!0)):f?this.setFocalOffset(this._focalOffsetEnd.x+g,this._focalOffsetEnd.y+v,this._focalOffsetEnd.z,!0):this.truck(g,v,!0)},this._rotateInternal=(c,p)=>{const f=rt*this.azimuthRotateSpeed*c/this._elementRect.height,g=rt*this.polarRotateSpeed*p/this._elementRect.height;this.rotate(f,g,!0)},this._dollyInternal=(c,p,f)=>{const g=Math.pow(.95,-c*this.dollySpeed),v=this._sphericalEnd.radius,T=this._sphericalEnd.radius*g,A=B(T,this.minDistance,this.maxDistance),z=A-T;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(T,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(z,!0),this._dollyToNoClamp(A,!0)):this._dollyToNoClamp(A,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?T:A)-v,this._dollyControlCoord.set(p,f)),this._lastDollyDirection=Math.sign(-c)},this._zoomInternal=(c,p,f)=>{const g=Math.pow(.95,c*this.dollySpeed),v=this._zoom,T=this._zoom*g;this.zoomTo(T,!0),this.dollyToCursor&&(this._changedZoom+=T-v,this._dollyControlCoord.set(p,f))},typeof O=="undefined"&&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 O.Quaternion().setFromUnitVectors(this._camera.up,vt),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=h.NONE,this._target=new O.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new O.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new O.Spherical().setFromVector3(x.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 O.Vector3,new O.Vector3,new O.Vector3,new O.Vector3],this._updateNearPlaneCorners(),this._boundary=new O.Box3(new O.Vector3(-1/0,-1/0,-1/0),new O.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 O.Vector2,this.mouseButtons={left:h.ROTATE,middle:h.DOLLY,right:h.TRUCK,wheel:q(this._camera)?h.DOLLY:j(this._camera)?h.ZOOM:h.NONE},this.touches={one:h.TOUCH_ROTATE,two:q(this._camera)?h.TOUCH_DOLLY_TRUCK:j(this._camera)?h.TOUCH_ZOOM_TRUCK:h.NONE,three:h.TOUCH_TRUCK};const s=new O.Vector2,o=new O.Vector2,r=new O.Vector2,i=c=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const g=this._domElement.getBoundingClientRect(),v=(c.clientX-g.left)/(g.right-g.left),T=(c.clientY-g.top)/(g.bottom-g.top);if(v<this._interactiveArea.left||v>this._interactiveArea.right||T<this._interactiveArea.top||T>this._interactiveArea.bottom)return}const p=c.pointerType!=="mouse"?null:(c.buttons&R.LEFT)===R.LEFT?R.LEFT:(c.buttons&R.MIDDLE)===R.MIDDLE?R.MIDDLE:(c.buttons&R.RIGHT)===R.RIGHT?R.RIGHT:null;if(p!==null){const g=this._findPointerByMouseButton(p);g&&this._disposePointer(g)}if((c.buttons&R.LEFT)===R.LEFT&&this._lockedPointer)return;const f={pointerId:c.pointerId,clientX:c.clientX,clientY:c.clientY,deltaX:0,deltaY:0,mouseButton:p};this._activePointers.push(f),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),this._isDragging=!0,C(c)},a=c=>{c.cancelable&&c.preventDefault();const p=c.pointerId,f=this._lockedPointer||this._findPointerById(p);if(f){if(f.clientX=c.clientX,f.clientY=c.clientY,f.deltaX=c.movementX,f.deltaY=c.movementY,this._state=0,c.pointerType==="touch")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;break}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(c.buttons&R.LEFT)===R.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(c.buttons&R.MIDDLE)===R.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(c.buttons&R.RIGHT)===R.RIGHT&&(this._state=this._state|this.mouseButtons.right);y()}},l=c=>{const p=this._findPointerById(c.pointerId);if(!(p&&p===this._lockedPointer)){if(p&&this._disposePointer(p),c.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=h.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;break}else this._state=h.NONE;P()}};let m=-1;const E=c=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===h.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const T=this._domElement.getBoundingClientRect(),A=(c.clientX-T.left)/(T.right-T.left),z=(c.clientY-T.top)/(T.bottom-T.top);if(A<this._interactiveArea.left||A>this._interactiveArea.right||z<this._interactiveArea.top||z>this._interactiveArea.bottom)return}if(c.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===h.ROTATE||this.mouseButtons.wheel===h.TRUCK){const T=performance.now();m-T<1e3&&this._getClientRect(this._elementRect),m=T}const p=Ye?-1:-3,f=c.deltaMode===1?c.deltaY/p:c.deltaY/(p*10),g=this.dollyToCursor?(c.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,v=this.dollyToCursor?(c.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case h.ROTATE:{this._rotateInternal(c.deltaX,c.deltaY),this._isUserControllingRotate=!0;break}case h.TRUCK:{this._truckInternal(c.deltaX,c.deltaY,!1),this._isUserControllingTruck=!0;break}case h.OFFSET:{this._truckInternal(c.deltaX,c.deltaY,!0),this._isUserControllingOffset=!0;break}case h.DOLLY:{this._dollyInternal(-f,g,v),this._isUserControllingDolly=!0;break}case h.ZOOM:{this._zoomInternal(-f,g,v),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},_=c=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===J.ACTION.NONE){const p=c instanceof PointerEvent?c.pointerId:0,f=this._findPointerById(p);f&&this._disposePointer(f),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l);return}c.preventDefault()}},C=c=>{if(!this._enabled)return;if(It(this._activePointers,Y),this._getClientRect(this._elementRect),s.copy(Y),o.copy(Y),this._activePointers.length>=2){const f=Y.x-this._activePointers[1].clientX,g=Y.y-this._activePointers[1].clientY,v=Math.sqrt(f*f+g*g);r.set(0,v);const T=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,A=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;o.set(T,A)}if(this._state=0,!c)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in c&&c.pointerType==="touch")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;break}else!this._lockedPointer&&(c.buttons&R.LEFT)===R.LEFT&&(this._state=this._state|this.mouseButtons.left),(c.buttons&R.MIDDLE)===R.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(c.buttons&R.RIGHT)===R.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&h.ROTATE)===h.ROTATE||(this._state&h.TOUCH_ROTATE)===h.TOUCH_ROTATE||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_ZOOM_ROTATE)===h.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&h.TRUCK)===h.TRUCK||(this._state&h.TOUCH_TRUCK)===h.TOUCH_TRUCK||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&h.DOLLY)===h.DOLLY||(this._state&h.TOUCH_DOLLY)===h.TOUCH_DOLLY||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&h.ZOOM)===h.ZOOM||(this._state&h.TOUCH_ZOOM)===h.TOUCH_ZOOM||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&h.OFFSET)===h.OFFSET||(this._state&h.TOUCH_OFFSET)===h.TOUCH_OFFSET||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},y=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,It(this._activePointers,Y);const p=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,f=p?-p.deltaX:o.x-Y.x,g=p?-p.deltaY:o.y-Y.y;if(o.copy(Y),((this._state&h.ROTATE)===h.ROTATE||(this._state&h.TOUCH_ROTATE)===h.TOUCH_ROTATE||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(f,g),this._isUserControllingRotate=!0),(this._state&h.DOLLY)===h.DOLLY||(this._state&h.ZOOM)===h.ZOOM){const v=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,T=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,A=this.dollyDragInverted?-1:1;(this._state&h.DOLLY)===h.DOLLY?(this._dollyInternal(A*g*wt,v,T),this._isUserControllingDolly=!0):(this._zoomInternal(A*g*wt,v,T),this._isUserControllingZoom=!0)}if((this._state&h.TOUCH_DOLLY)===h.TOUCH_DOLLY||(this._state&h.TOUCH_ZOOM)===h.TOUCH_ZOOM||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE){const v=Y.x-this._activePointers[1].clientX,T=Y.y-this._activePointers[1].clientY,A=Math.sqrt(v*v+T*T),z=r.y-A;r.set(0,A);const tt=this.dollyToCursor?(o.x-this._elementRect.x)/this._elementRect.width*2-1:0,et=this.dollyToCursor?(o.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&h.TOUCH_DOLLY)===h.TOUCH_DOLLY||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET?(this._dollyInternal(z*wt,tt,et),this._isUserControllingDolly=!0):(this._zoomInternal(z*wt,tt,et),this._isUserControllingZoom=!0)}((this._state&h.TRUCK)===h.TRUCK||(this._state&h.TOUCH_TRUCK)===h.TOUCH_TRUCK||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(f,g,!1),this._isUserControllingTruck=!0),((this._state&h.OFFSET)===h.OFFSET||(this._state&h.TOUCH_OFFSET)===h.TOUCH_OFFSET||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(f,g,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},P=()=>{It(this._activePointers,Y),o.copy(Y),this._dragNeedsUpdate=!1,(this._activePointers.length===0||this._activePointers.length===1&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),this._activePointers.length===0&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),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",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",u),this._domElement.ownerDocument.addEventListener("pointerlockerror",w),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),C())},this.unlockPointer=()=>{var c,p,f;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(c=this._domElement)===null||c===void 0||c.ownerDocument.exitPointerLock(),(p=this._domElement)===null||p===void 0||p.ownerDocument.removeEventListener("pointerlockchange",u),(f=this._domElement)===null||f===void 0||f.ownerDocument.removeEventListener("pointerlockerror",w),this.cancel()};const u=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},w=()=>{this.unlockPointer()};this._addAllEventListeners=c=>{this._domElement=c,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",i),this._domElement.addEventListener("pointercancel",l),this._domElement.addEventListener("wheel",E,{passive:!1}),this._domElement.addEventListener("contextmenu",_)},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",l),this._domElement.removeEventListener("wheel",E,{passive:!1}),this._domElement.removeEventListener("contextmenu",_),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.removeEventListener("pointerlockchange",u),this._domElement.ownerDocument.removeEventListener("pointerlockerror",w))},this.cancel=()=>{this._state!==h.NONE&&(this._state=h.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=B(t.width,0,1),this._interactiveArea.height=B(t.height,0,1),this._interactiveArea.x=B(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=B(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,s=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,s)}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,s=!1){this._isUserControllingRotate=!1;const o=B(t,this.minAzimuthAngle,this.maxAzimuthAngle),r=B(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=o,this._sphericalEnd.phi=r,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const i=!s||M(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&M(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(i)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=ot.NONE,this._changedDolly=0,this._dollyToNoClamp(B(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const i=this._collisionTest(),a=M(i,this._spherical.radius);if(!(s>t)&&a)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,i)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const r=!e||M(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(r)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(dt).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const s=!e||M(this._target.x,this._targetEnd.x,this.restThreshold)&&M(this._target.y,this._targetEnd.y,this.restThreshold)&&M(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=B(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const s=!e||M(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(s)}pan(t,e,s=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,s)}truck(t,e,s=!1){this._camera.updateMatrix(),N.setFromMatrixColumn(this._camera.matrix,0),G.setFromMatrixColumn(this._camera.matrix,1),N.multiplyScalar(t),G.multiplyScalar(-e);const o=x.copy(N).add(G),r=S.copy(this._targetEnd).add(o);return this.moveTo(r.x,r.y,r.z,s)}forward(t,e=!1){x.setFromMatrixColumn(this._camera.matrix,0),x.crossVectors(this._camera.up,x),x.multiplyScalar(t);const s=S.copy(this._targetEnd).add(x);return this.moveTo(s.x,s.y,s.z,e)}elevate(t,e=!1){return x.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+x.x,this._targetEnd.y+x.y,this._targetEnd.z+x.z,e)}moveTo(t,e,s,o=!1){this._isUserControllingTruck=!1;const r=x.set(t,e,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,r,this.boundaryFriction),this._needsUpdate=!0,o||this._target.copy(this._targetEnd);const i=!o||M(this._target.x,this._targetEnd.x,this.restThreshold)&&M(this._target.y,this._targetEnd.y,this.restThreshold)&&M(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(i)}lookInDirectionOf(t,e,s,o=!1){const a=x.set(t,e,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(a.x,a.y,a.z,o)}fitToBox(t,e,{cover:s=!1,paddingLeft:o=0,paddingRight:r=0,paddingBottom:i=0,paddingTop:a=0}={}){const l=[],m=t.isBox3?at.copy(t):at.setFromObject(t);m.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const E=$t(this._sphericalEnd.theta,Kt),_=$t(this._sphericalEnd.phi,Kt);l.push(this.rotateTo(E,_,e));const C=x.setFromSpherical(this._sphericalEnd).normalize(),y=oe.setFromUnitVectors(C,Ht),P=M(Math.abs(C.y),1);P&&y.multiply(Vt.setFromAxisAngle(vt,E)),y.multiply(this._yAxisUpSpaceInverse);const u=ie.makeEmpty();S.copy(m.min).applyQuaternion(y),u.expandByPoint(S),S.copy(m.min).setX(m.max.x).applyQuaternion(y),u.expandByPoint(S),S.copy(m.min).setY(m.max.y).applyQuaternion(y),u.expandByPoint(S),S.copy(m.max).setZ(m.min.z).applyQuaternion(y),u.expandByPoint(S),S.copy(m.min).setZ(m.max.z).applyQuaternion(y),u.expandByPoint(S),S.copy(m.max).setY(m.min.y).applyQuaternion(y),u.expandByPoint(S),S.copy(m.max).setX(m.min.x).applyQuaternion(y),u.expandByPoint(S),S.copy(m.max).applyQuaternion(y),u.expandByPoint(S),u.min.x-=o,u.min.y-=i,u.max.x+=r,u.max.y+=a,y.setFromUnitVectors(Ht,C),P&&y.premultiply(Vt.invert()),y.premultiply(this._yAxisUpSpace);const w=u.getSize(x),c=u.getCenter(S).applyQuaternion(y);if(q(this._camera)){const p=this.getDistanceToFitBox(w.x,w.y,w.z,s);l.push(this.moveTo(c.x,c.y,c.z,e)),l.push(this.dollyTo(p,e)),l.push(this.setFocalOffset(0,0,0,e))}else if(j(this._camera)){const p=this._camera,f=p.right-p.left,g=p.top-p.bottom,v=s?Math.max(f/w.x,g/w.y):Math.min(f/w.x,g/w.y);l.push(this.moveTo(c.x,c.y,c.z,e)),l.push(this.zoomTo(v,e)),l.push(this.setFocalOffset(0,0,0,e))}return Promise.all(l)}fitToSphere(t,e){const s=[],r="isObject3D"in t?J.createBoundingSphere(t,Yt):Yt.copy(t);if(s.push(this.moveTo(r.center.x,r.center.y,r.center.z,e)),q(this._camera)){const i=this.getDistanceToFitSphere(r.radius);s.push(this.dollyTo(i,e))}else if(j(this._camera)){const i=this._camera.right-this._camera.left,a=this._camera.top-this._camera.bottom,l=2*r.radius,m=Math.min(i/l,a/l);s.push(this.zoomTo(m,e))}return s.push(this.setFocalOffset(0,0,0,e)),Promise.all(s)}setLookAt(t,e,s,o,r,i,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=ot.NONE,this._changedDolly=0;const l=S.set(o,r,i),m=x.set(t,e,s);this._targetEnd.copy(l),this._sphericalEnd.setFromVector3(m.sub(l).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,a||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const E=!a||M(this._target.x,this._targetEnd.x,this.restThreshold)&&M(this._target.y,this._targetEnd.y,this.restThreshold)&&M(this._target.z,this._targetEnd.z,this.restThreshold)&&M(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&M(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&M(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(E)}lerpLookAt(t,e,s,o,r,i,a,l,m,E,_,C,y,P=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=ot.NONE,this._changedDolly=0;const u=x.set(o,r,i),w=S.set(t,e,s);V.setFromVector3(w.sub(u).applyQuaternion(this._yAxisUpSpace));const c=nt.set(E,_,C),p=S.set(a,l,m);mt.setFromVector3(p.sub(c).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(u.lerp(c,y));const f=mt.theta-V.theta,g=mt.phi-V.phi,v=mt.radius-V.radius;this._sphericalEnd.set(V.radius+v*y,V.phi+g*y,V.theta+f*y),this.normalizeRotations(),this._needsUpdate=!0,P||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const T=!P||M(this._target.x,this._targetEnd.x,this.restThreshold)&&M(this._target.y,this._targetEnd.y,this.restThreshold)&&M(this._target.z,this._targetEnd.z,this.restThreshold)&&M(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&M(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&M(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(T)}setPosition(t,e,s,o=!1){return this.setLookAt(t,e,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,o)}setTarget(t,e,s,o=!1){const r=this.getPosition(x),i=this.setLookAt(r.x,r.y,r.z,t,e,s,o);return this._sphericalEnd.phi=B(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),i}setFocalOffset(t,e,s,o=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,s),this._needsUpdate=!0,o||this._focalOffset.copy(this._focalOffsetEnd);const r=!o||M(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&M(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&M(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}setOrbitPoint(t,e,s){this._camera.updateMatrixWorld(),N.setFromMatrixColumn(this._camera.matrixWorldInverse,0),G.setFromMatrixColumn(this._camera.matrixWorldInverse,1),W.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const o=x.set(t,e,s),r=o.distanceTo(this._camera.position),i=o.sub(this._camera.position);N.multiplyScalar(i.x),G.multiplyScalar(i.y),W.multiplyScalar(i.z),x.copy(N).add(G).add(W),x.z=x.z+r,this.dollyTo(r,!1),this.setFocalOffset(-x.x,x.y,-x.z,!1),this.moveTo(t,e,s,!1)}setBoundary(t){if(!t){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,s,o){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new O.Vector4,typeof t=="number"?this._viewport.set(t,e,s,o):this._viewport.copy(t)}getDistanceToFitBox(t,e,s,o=!1){if(Ft(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const r=t/e,i=this._camera.getEffectiveFOV()*ht,a=this._camera.aspect;return((o?r>a:r<a)?e:t/a)*.5/Math.tan(i*.5)+s*.5}getDistanceToFitSphere(t){if(Ft(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*ht,s=Math.atan(Math.tan(e*.5)*this._camera.aspect)*2,o=1<this._camera.aspect?e:s;return t/Math.sin(o*.5)}getTarget(t,e=!0){return(t&&t.isVector3?t:new O.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new O.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new O.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new O.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%rt,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=rt),this._spherical.theta+=rt*Math.round((this._sphericalEnd.theta-this._spherical.theta)/rt)}reset(t=!1){if(!M(this._camera.up.x,this._cameraUp0.x)||!M(this._camera.up.y,this._cameraUp0.y)||!M(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(x);this.updateCameraUp(),this.setPosition(s.x,s.y,s.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,vt),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=x.subVectors(this._target,this._camera.position).normalize(),e=S.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const s=this.getPosition(x);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}update(t){const e=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,o=this._sphericalEnd.radius-this._spherical.radius,r=ee.subVectors(this._targetEnd,this._target),i=se.subVectors(this._focalOffsetEnd,this._focalOffset),a=this._zoomEnd-this._zoom;if(U(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const _=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Ot(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,_,1/0,t),this._needsUpdate=!0}if(U(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const _=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Ot(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,_,1/0,t),this._needsUpdate=!0}if(U(o))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const _=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Ot(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,_,this.maxSpeed,t),this._needsUpdate=!0}if(U(r.x)&&U(r.y)&&U(r.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const _=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Jt(this._target,this._targetEnd,this._targetVelocity,_,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(U(i.x)&&U(i.y)&&U(i.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const _=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Jt(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,_,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(U(a))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const _=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Ot(this._zoom,this._zoomEnd,this._zoomVelocity,_,1/0,t)}if(this.dollyToCursor){if(q(this._camera)&&this._changedDolly!==0){const _=this._spherical.radius-this._lastDistance,C=this._camera,y=this._getCameraDirection(dt),P=x.copy(y).cross(C.up).normalize();P.lengthSq()===0&&(P.x=1);const u=S.crossVectors(P,y),w=this._sphericalEnd.radius*Math.tan(C.getEffectiveFOV()*ht*.5),p=(this._sphericalEnd.radius-_-this._sphericalEnd.radius)/this._sphericalEnd.radius,f=nt.copy(this._targetEnd).add(P.multiplyScalar(this._dollyControlCoord.x*w*C.aspect)).add(u.multiplyScalar(this._dollyControlCoord.y*w)),g=x.copy(this._targetEnd).lerp(f,p),v=this._lastDollyDirection===ot.IN&&this._spherical.radius<=this.minDistance,T=this._lastDollyDirection===ot.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(v||T)){this._sphericalEnd.radius-=_,this._spherical.radius-=_;const z=S.copy(y).multiplyScalar(-_);g.add(z)}this._boundary.clampPoint(g,g);const A=S.subVectors(g,this._targetEnd);this._targetEnd.copy(g),this._target.add(A),this._changedDolly-=_,U(this._changedDolly)&&(this._changedDolly=0)}else if(j(this._camera)&&this._changedZoom!==0){const _=this._zoom-this._lastZoom,C=this._camera,y=x.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(C.near+C.far)/(C.near-C.far)).unproject(C),P=S.set(0,0,-1).applyQuaternion(C.quaternion),u=nt.copy(y).add(P.multiplyScalar(-y.dot(C.up))),c=-(this._zoom-_-this._zoom)/this._zoom,p=this._getCameraDirection(dt),f=this._targetEnd.dot(p),g=x.copy(this._targetEnd).lerp(u,c),v=g.dot(p),T=p.multiplyScalar(v-f);g.sub(T),this._boundary.clampPoint(g,g);const A=S.subVectors(g,this._targetEnd);this._targetEnd.copy(g),this._target.add(A),this._changedZoom-=_,U(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 l=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,l),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!U(this._focalOffset.x)||!U(this._focalOffset.y)||!U(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),N.setFromMatrixColumn(this._camera.matrix,0),G.setFromMatrixColumn(this._camera.matrix,1),W.setFromMatrixColumn(this._camera.matrix,2),N.multiplyScalar(this._focalOffset.x),G.multiplyScalar(-this._focalOffset.y),W.multiplyScalar(this._focalOffset.z),x.copy(N).add(G).add(W),this._camera.position.add(x)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),x.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const E=this._needsUpdate;return E&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):E?(this.dispatchEvent({type:"update"}),U(e,this.restThreshold)&&U(s,this.restThreshold)&&U(o,this.restThreshold)&&U(r.x,this.restThreshold)&&U(r.y,this.restThreshold)&&U(r.z,this.restThreshold)&&U(i.x,this.restThreshold)&&U(i.y,this.restThreshold)&&U(i.z,this.restThreshold)&&U(a,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!E&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=E,this._needsUpdate=!1,E}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:lt(this.maxDistance),minZoom:this.minZoom,maxZoom:lt(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:lt(this.maxPolarAngle),minAzimuthAngle:lt(this.minAzimuthAngle),maxAzimuthAngle:lt(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:x.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 s=JSON.parse(t);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=ct(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=ct(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=ct(s.maxPolarAngle),this.minAzimuthAngle=ct(s.minAzimuthAngle),this.maxAzimuthAngle=ct(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this.verticalDragToForward=s.verticalDragToForward,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],e),V.setFromVector3(x.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(V.theta,V.phi,e),this.dollyTo(V.radius,e),this.zoomTo(s.zoom,e),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],e),this._needsUpdate=!0}connect(t){if(this._domElement){console.warn("camera-controls is already connected.");return}this._addAllEventListeners(t),this._getClientRect(this._elementRect)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(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,s){const o=e.lengthSq();if(o===0)return t;const r=S.copy(e).add(t),a=this._boundary.clampPoint(r,nt).sub(r),l=a.lengthSq();if(l===0)return t.add(e);if(l===o)return t;if(s===0)return t.add(e).add(a);{const m=1+s*l/e.dot(a);return t.add(S.copy(e).multiplyScalar(m)).add(a.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(q(this._camera)){const t=this._camera,e=t.near,s=t.getEffectiveFOV()*ht,o=Math.tan(s*.5)*e,r=o*t.aspect;this._nearPlaneCorners[0].set(-r,-o,0),this._nearPlaneCorners[1].set(r,-o,0),this._nearPlaneCorners[2].set(r,o,0),this._nearPlaneCorners[3].set(-r,o,0)}else if(j(this._camera)){const t=this._camera,e=1/t.zoom,s=t.left*e,o=t.right*e,r=t.top*e,i=t.bottom*e;this._nearPlaneCorners[0].set(s,r,0),this._nearPlaneCorners[1].set(o,r,0),this._nearPlaneCorners[2].set(o,i,0),this._nearPlaneCorners[3].set(s,i,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||Ft(this._camera,"_collisionTest"))return t;const s=this._getTargetDirection(dt);kt.lookAt(te,s,this._camera.up);for(let o=0;o<4;o++){const r=S.copy(this._nearPlaneCorners[o]);r.applyMatrix4(kt);const i=nt.addVectors(this._target,r);xt.set(i,s),xt.far=this._spherical.radius+1;const a=xt.intersectObjects(this.colliderMeshes);a.length!==0&&a[0].distance<t&&(t=a[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(e=>{const s=()=>{this.removeEventListener("rest",s),e()};this.addEventListener("rest",s)}))}_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 O.Sphere){const s=e,o=s.center;at.makeEmpty(),t.traverseVisible(i=>{i.isMesh&&at.expandByObject(i)}),at.getCenter(o);let r=0;return t.traverseVisible(i=>{if(!i.isMesh)return;const a=i,l=a.geometry.clone();l.applyMatrix4(a.matrixWorld);const E=l.attributes.position;for(let _=0,C=E.count;_<C;_++)x.fromBufferAttribute(E,_),r=Math.max(r,o.distanceToSquared(x))}),s.radius=Math.sqrt(r),s}}const Ve={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:Pe.ColorSpace.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1,physicallyCorrectLights:!1};class ke{constructor(t){this.options=t;const{width:e,height:s,rendererParams:o}=t,{canvas:r,context:i,alpha:a,devicePixelRatio:l,antialias:m,powerPreference:E,toneMappingExposure:_,outputColorSpace:C,logarithmicDepthBuffer:y,preserveDrawingBuffer:P,stencil:u,depth:w,physicallyCorrectLights:c}=o,p=new b.WebGLRenderer({canvas:r,context:i,alpha:a,antialias:m,powerPreference:E,logarithmicDepthBuffer:y,preserveDrawingBuffer:P,stencil:u,depth:w});p.setSize(e,s),p.setPixelRatio(l),p.toneMappingExposure=_,p.outputColorSpace=C,+b.REVISION<155&&(p.useLegacyLights=c),this.renderer=p}setSize(t,e){this.renderer.setSize(t,e)}setPixelRatio(t){this.renderer.setPixelRatio(t)}render(t){const{scene:e,camera:s}=this.options;this.renderer.render(e,t||s)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}const Ze={antialias:!0,devicePixelRatio:window.devicePixelRatio};class Be{constructor(t){this.options=t;const{width:e,height:s,rendererParams:o,renderer:r}=t,{devicePixelRatio:i,antialias:a}=o,l=new r({antialias:a});l.setSize(e,s),l.setPixelRatio(i),this.renderer=l}setSize(t,e){this.renderer.setSize(t,e)}render(t){const{scene:e,camera:s}=this.options;this.renderer.render(e,t||s)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}class Gt{constructor(t){this.guiParams={},t&&(this.guiParams=t)}showGui(t){t&&Object.keys(this.guiParams).forEach(e=>{const s=t.addFolder(e),o=this.guiParams[e];Object.keys(o).forEach(r=>{const{min:i,max:a,step:l,name:m,paramMap:E,items:_,value:C,target:y}=o[r],P=r.toLowerCase().indexOf("color")>-1;let u;const w=typeof C=="undefined"&&y,c=w?y():o[r],p=w?r:"value";_?u=s.add(c,p,_):P?u=s.addColor(c,p):u=s.add(c,p),u=u.name(m||r),typeof i!="undefined"&&(u=u.min(i)),typeof a!="undefined"&&(u=u.max(a)),typeof l!="undefined"&&(u=u.step(l)),u=u.onChange(()=>{this.setTargetValue(e,r,c[p],E)}),w&&u.listen()})})}setTargetValue(t,e,s,o){const{onChange:r,target:i,value:a}=this.guiParams[t][e],l=e.toLowerCase().indexOf("color")>-1;if(i&&!(typeof a=="undefined"&&i)){let E=i();Array.isArray(E)||(E=[E]),E.forEach(_=>{if(_)if(l)try{_[o||e].set(s)}catch(C){e!=="color"&&!o&&console.warn(`${e} is not a color,set paramMap`)}else _[o||e]=s})}r&&r(s)}setTargetValueByParams(){Object.keys(this.guiParams).forEach(t=>{Object.keys(this.guiParams[t]).forEach(e=>{const s=this.guiParams[t][e];typeof s.value!="undefined"&&this.setTargetValue(t,e,s.value,s.paramMap)})})}}const Ne={fov:45,near:1,far:1e3,up:new b.Vector3(0,1,0)};class Ge{constructor(t){this.customCamera=!1,this.syncCamera=null,this.options=t;const{width:e,height:s,cameraParams:o}=t;if(o instanceof b.Camera)this.camera=o,this.customCamera=!0;else{const{fov:r,far:i,near:a,up:l}=o,m=new b.PerspectiveCamera(r,e/s,a,i);m.position.set(0,0,400),m.lookAt(0,0,0),m.up=l,this.camera=m}}setSize(t,e){this.options.width=t,this.options.height=e,this.camera instanceof b.PerspectiveCamera&&(this.camera.aspect=t/e),this.camera.updateProjectionMatrix(),this.camera2&&(this.camera2.aspect=t/e,this.camera2.updateProjectionMatrix())}addCamera2(){const t=new b.PerspectiveCamera(this.camera.fov,this.camera.aspect,this.camera.near,this.camera.far);return t.position.copy(this.camera.position),this.camera2=t,t}sync(){if(this.syncCamera)if(this.syncCamera.type==="PerspectiveCamera"){const t=this.syncCamera;(!this.camera.matrixWorld.equals(t.matrixWorld)||this.camera.far!==t.far||this.camera.near!==t.near||this.camera.fov!==t.fov||this.camera.aspect!==t.aspect)&&this.camera.copy(t)}else{const t=this.syncCamera;this.camera.fov=t.fov,this.camera.updateProjectionMatrix(),this.camera.matrixAutoUpdate=!1;const e=t.viewMatrix,s=t.inverseViewMatrix;this.camera.matrixWorld.set(s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14],s[3],s[7],s[11],s[15]),this.camera.matrixWorldInverse.set(e[0],e[4],e[8],e[12],e[1],e[5],e[9],e[13],e[2],e[6],e[10],e[14],e[3],e[7],e[11],e[15]);const{width:o,height:r}=this.options,i=o/r;this.camera.aspect=i,this.camera.updateProjectionMatrix()}}setGui(t){const e=new Gt({camera:zt(it({},this.options.cameraControls?{}:{x:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},y:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},z:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position}}),{near:{min:0,max:1e3,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}},far:{min:0,max:2e4,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}})});this.camera instanceof b.PerspectiveCamera&&(e.guiParams.camera.fov={min:0,max:90,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}),e.showGui(t)}}const Xe={background:null,addCamera:!0};class Qe{constructor(t){this.overrideMaterial=!1,this.options=t;const{camera:e,sceneParams:s}=t,{background:o,addCamera:r}=s,i=new b.Scene;o&&(i.background=o),r&&i.add(e),this.scene=i}dispose(){var t;(t=this.scene)==null||t.traverse(e=>{be.disposeMesh(e)})}}class je{constructor(t){this.helpers={},this.options=t}add(t){const e=t.uuid,{scene:s}=this.options;let o=this.helpers[e];if(o===void 0){if(t.isScene)o=new b.AxesHelper(100);else if(t.isCamera)o=new b.CameraHelper(t);else if(t.isPointLight)o=new b.PointLightHelper(t,1);else if(t.isDirectionalLight)o=new b.DirectionalLightHelper(t,1);else if(t.isSpotLight)o=new b.SpotLightHelper(t);else if(t.isHemisphereLight)o=new b.HemisphereLightHelper(t,10);else if(t.isRectAreaLight)o=new Se.RectAreaLightHelper(t);else{const r=new b.Box3;if(r.setFromObject(t,!0),r.isEmpty()===!1){o=new b.Box3Helper(r);const i=o.material;i.userData.object=t,i.depthTest=!1,i.transparent=!0}else return}s.add(o),this.helpers[e]=o}}remove(t){var o;const e=t.uuid,{scene:s}=this.options;if(this.helpers[e]!==void 0){const r=this.helpers[e];s.remove(r),delete this.helpers[e],(o=r.dispose)==null||o.call(r)}}removeAll(){Object.keys(this.helpers).forEach(t=>{this.remove({uuid:t})}),this.helpers={}}removeAllExcludeScene(){Object.keys(this.helpers).forEach(t=>{this.helpers[t]instanceof b.AxesHelper||this.remove({uuid:t})})}update(){Object.values(this.helpers).forEach(t=>{if(t.update&&t.update(),t instanceof b.Box3Helper){const e=t.material,{object:s}=e.userData;s&&t.box.setFromObject(s,!0)}})}dispose(){this.helpers={}}}class qe{constructor(t){this.autoRotateSpeed=0,this.options=t;const{camera:e,controlsParams:s,customControl:o}=t,{domElement:r}=s;if(o){const i=new o(e,r);i.enableDamping=!0,i.dampingFactor=.063,i.autoRotate=!1,i.autoRotateSpeed=-60,i.enableZoom=!0,i.zoomSpeed=.2,this.controls=i}else J.install({THREE:b}),this.cameraControls=new J(e,r)}addCameraControls2(t){const{controlsParams:e}=this.options,{domElement:s}=e;this.cameraControls2=new J(t,s),this.cameraControls2.addEventListener("update",()=>{this.cameraControls.enabled=!1}),this.cameraControls2.addEventListener("sleep",()=>{this.cameraControls.enabled=!0})}enable(){this.controls?this.controls.enabled=!0:this.cameraControls&&(this.cameraControls.enabled=!0,this.cameraControls2&&(this.cameraControls2.enabled=!0))}disable(){this.controls?this.controls.enabled=!1:this.cameraControls&&(this.cameraControls.enabled=!1,this.cameraControls2&&(this.cameraControls2.enabled=!1))}update(t){var e,s,o;(e=this.controls)==null||e.update(),(s=this.cameraControls)==null||s.update(t),(o=this.cameraControls2)==null||o.update(t),this.autoRotateSpeed&&this.cameraControls&&(this.cameraControls.azimuthAngle+=this.autoRotateSpeed*t*b.MathUtils.DEG2RAD)}dispose(){var t,e,s;(t=this.controls)==null||t.dispose(),(e=this.cameraControls)==null||e.dispose(),(s=this.cameraControls2)==null||s.dispose()}}const K=new n.Raycaster,F=new n.Vector3,Q=new n.Vector3,L=new n.Quaternion,re={X:new n.Vector3(1,0,0),Y:new n.Vector3(0,1,0),Z:new n.Vector3(0,0,1)},Zt={type:"change"},ne={type:"mouseDown",mode:null},ae={type:"mouseUp",mode:null},he={type:"objectChange"};class We extends n.Controls{constructor(t,e=null){super(void 0,e);const s=new ss(this);this._root=s;const o=new is;this._gizmo=o,s.add(o);const r=new os;this._plane=r,s.add(r);const i=this;function a(f,g){let v=g;Object.defineProperty(i,f,{get:function(){return v!==void 0?v:g},set:function(T){v!==T&&(v=T,r[f]=T,o[f]=T,i.dispatchEvent({type:f+"-changed",value:T}),i.dispatchEvent(Zt))}}),i[f]=g,r[f]=g,o[f]=g}a("camera",t),a("object",void 0),a("enabled",!0),a("axis",null),a("mode","translate"),a("translationSnap",null),a("rotationSnap",null),a("scaleSnap",null),a("space","world"),a("size",1),a("dragging",!1),a("showX",!0),a("showY",!0),a("showZ",!0);const l=new n.Vector3,m=new n.Vector3,E=new n.Quaternion,_=new n.Quaternion,C=new n.Vector3,y=new n.Quaternion,P=new n.Vector3,u=new n.Vector3,w=new n.Vector3,c=0,p=new n.Vector3;a("worldPosition",l),a("worldPositionStart",m),a("worldQuaternion",E),a("worldQuaternionStart",_),a("cameraPosition",C),a("cameraQuaternion",y),a("pointStart",P),a("pointEnd",u),a("rotationAxis",w),a("rotationAngle",c),a("eye",p),this._offset=new n.Vector3,this._startNorm=new n.Vector3,this._endNorm=new n.Vector3,this._cameraScale=new n.Vector3,this._parentPosition=new n.Vector3,this._parentQuaternion=new n.Quaternion,this._parentQuaternionInv=new n.Quaternion,this._parentScale=new n.Vector3,this._worldScaleStart=new n.Vector3,this._worldQuaternionInv=new n.Quaternion,this._worldScale=new n.Vector3,this._positionStart=new n.Vector3,this._quaternionStart=new n.Quaternion,this._scaleStart=new n.Vector3,this._getPointer=Ke.bind(this),this._onPointerDown=Je.bind(this),this._onPointerHover=$e.bind(this),this._onPointerMove=ts.bind(this),this._onPointerUp=es.bind(this),e!==null&&this.connect()}connect(){this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="auto"}getHelper(){return this._root}pointerHover(t){if(this.object===void 0||this.dragging===!0)return;t!==null&&K.setFromCamera(t,this.camera);const e=Bt(this._gizmo.picker[this.mode],K);e?this.axis=e.object.name:this.axis=null}pointerDown(t){if(!(this.object===void 0||this.dragging===!0||t!=null&&t.button!==0)&&this.axis!==null){t!==null&&K.setFromCamera(t,this.camera);const e=Bt(this._plane,K,!0);e&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(e.point).sub(this.worldPositionStart)),this.dragging=!0,ne.mode=this.mode,this.dispatchEvent(ne)}}pointerMove(t){const e=this.axis,s=this.mode,o=this.object;let r=this.space;if(s==="scale"?r="local":(e==="E"||e==="XYZE"||e==="XYZ")&&(r="world"),o===void 0||e===null||this.dragging===!1||t!==null&&t.button!==-1)return;t!==null&&K.setFromCamera(t,this.camera);const i=Bt(this._plane,K,!0);if(i){if(this.pointEnd.copy(i.point).sub(this.worldPositionStart),s==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),r==="local"&&e!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),e.indexOf("X")===-1&&(this._offset.x=0),e.indexOf("Y")===-1&&(this._offset.y=0),e.indexOf("Z")===-1&&(this._offset.z=0),r==="local"&&e!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),o.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(r==="local"&&(o.position.applyQuaternion(L.copy(this._quaternionStart).invert()),e.search("X")!==-1&&(o.position.x=Math.round(o.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(o.position.y=Math.round(o.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(o.position.z=Math.round(o.position.z/this.translationSnap)*this.translationSnap),o.position.applyQuaternion(this._quaternionStart)),r==="world"&&(o.parent&&o.position.add(F.setFromMatrixPosition(o.parent.matrixWorld)),e.search("X")!==-1&&(o.position.x=Math.round(o.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(o.position.y=Math.round(o.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(o.position.z=Math.round(o.position.z/this.translationSnap)*this.translationSnap),o.parent&&o.position.sub(F.setFromMatrixPosition(o.parent.matrixWorld))));else if(s==="scale"){if(e.search("XYZ")!==-1){let a=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(a*=-1),Q.set(a,a,a)}else F.copy(this.pointStart),Q.copy(this.pointEnd),F.applyQuaternion(this._worldQuaternionInv),Q.applyQuaternion(this._worldQuaternionInv),Q.divide(F),e.search("X")===-1&&(Q.x=1),e.search("Y")===-1&&(Q.y=1),e.search("Z")===-1&&(Q.z=1);o.scale.copy(this._scaleStart).multiply(Q),this.scaleSnap&&(e.search("X")!==-1&&(o.scale.x=Math.round(o.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Y")!==-1&&(o.scale.y=Math.round(o.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Z")!==-1&&(o.scale.z=Math.round(o.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(s==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const a=20/this.worldPosition.distanceTo(F.setFromMatrixPosition(this.camera.matrixWorld));let l=!1;e==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(F.copy(this.rotationAxis).cross(this.eye))*a):(e==="X"||e==="Y"||e==="Z")&&(this.rotationAxis.copy(re[e]),F.copy(re[e]),r==="local"&&F.applyQuaternion(this.worldQuaternion),F.cross(this.eye),F.length()===0?l=!0:this.rotationAngle=this._offset.dot(F.normalize())*a),(e==="E"||l)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),r==="local"&&e!=="E"&&e!=="XYZE"?(o.quaternion.copy(this._quaternionStart),o.quaternion.multiply(L.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),o.quaternion.copy(L.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),o.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(Zt),this.dispatchEvent(he)}}pointerUp(t){t!==null&&t.button!==0||(this.dragging&&this.axis!==null&&(ae.mode=this.mode,this.dispatchEvent(ae)),this.dragging=!1,this.axis=null)}dispose(){this.disconnect(),this._root.dispose()}attach(t){return this.object=t,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this._root.visible=!1,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(Zt),this.dispatchEvent(he),this.pointStart.copy(this.pointEnd))}getRaycaster(){return K}getMode(){return this.mode}setMode(t){this.mode=t}setTranslationSnap(t){this.translationSnap=t}setRotationSnap(t){this.rotationSnap=t}setScaleSnap(t){this.scaleSnap=t}setSize(t){this.size=t}setSpace(t){this.space=t}}function Ke(d){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:d.button};{const t=this.domElement.getBoundingClientRect();return{x:(d.clientX-t.left)/t.width*2-1,y:-(d.clientY-t.top)/t.height*2+1,button:d.button}}}function $e(d){if(this.enabled)switch(d.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(d));break}}function Je(d){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(d.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(d)),this.pointerDown(this._getPointer(d)))}function ts(d){this.enabled&&this.pointerMove(this._getPointer(d))}function es(d){this.enabled&&(this.domElement.releasePointerCapture(d.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(d)))}function Bt(d,t,e){const s=t.intersectObject(d,!0);for(let o=0;o<s.length;o++)if(s[o].object.visible||e)return s[o];return!1}const Pt=new n.Euler,D=new n.Vector3(0,1,0),le=new n.Vector3(0,0,0),ce=new n.Matrix4,bt=new n.Quaternion,Mt=new n.Quaternion,X=new n.Vector3,de=new n.Matrix4,ft=new n.Vector3(1,0,0),$=new n.Vector3(0,1,0),gt=new n.Vector3(0,0,1),St=new n.Vector3,pt=new n.Vector3,_t=new n.Vector3;class ss extends n.Object3D{constructor(t){super(),this.isTransformControlsRoot=!0,this.controls=t,this.visible=!1}updateMatrixWorld(t){const e=this.controls;e.object!==void 0&&(e.object.updateMatrixWorld(),e.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):e.object.parent.matrixWorld.decompose(e._parentPosition,e._parentQuaternion,e._parentScale),e.object.matrixWorld.decompose(e.worldPosition,e.worldQuaternion,e._worldScale),e._parentQuaternionInv.copy(e._parentQuaternion).invert(),e._worldQuaternionInv.copy(e.worldQuaternion).invert()),e.camera.updateMatrixWorld(),e.camera.matrixWorld.decompose(e.cameraPosition,e.cameraQuaternion,e._cameraScale),e.camera.isOrthographicCamera?e.camera.getWorldDirection(e.eye).negate():e.eye.copy(e.cameraPosition).sub(e.worldPosition).normalize(),super.updateMatrixWorld(t)}dispose(){this.traverse(function(t){t.geometry&&t.geometry.dispose(),t.material&&t.material.dispose()})}}class is extends n.Object3D{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const t=new n.MeshBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),e=new n.LineBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),s=t.clone();s.opacity=.15;const o=e.clone();o.opacity=.5;const r=t.clone();r.color.setHex(16711680);const i=t.clone();i.color.setHex(65280);const a=t.clone();a.color.setHex(255);const l=t.clone();l.color.setHex(16711680),l.opacity=.5;const m=t.clone();m.color.setHex(65280),m.opacity=.5;const E=t.clone();E.color.setHex(255),E.opacity=.5;const _=t.clone();_.opacity=.25;const C=t.clone();C.color.setHex(16776960),C.opacity=.25,t.clone().color.setHex(16776960);const P=t.clone();P.color.setHex(7895160);const u=new n.CylinderGeometry(0,.04,.1,12);u.translate(0,.05,0);const w=new n.BoxGeometry(.08,.08,.08);w.translate(0,.04,0);const c=new n.BufferGeometry;c.setAttribute("position",new n.Float32BufferAttribute([0,0,0,1,0,0],3));const p=new n.CylinderGeometry(.0075,.0075,.5,3);p.translate(0,.25,0);function f(I,yt){const Z=new n.TorusGeometry(I,.0075,3,64,yt*Math.PI*2);return Z.rotateY(Math.PI/2),Z.rotateX(Math.PI/2),Z}function g(){const I=new n.BufferGeometry;return I.setAttribute("position",new n.Float32BufferAttribute([0,0,0,1,1,1],3)),I}const v={X:[[new n.Mesh(u,r),[.5,0,0],[0,0,-Math.PI/2]],[new n.Mesh(u,r),[-.5,0,0],[0,0,Math.PI/2]],[new n.Mesh(p,r),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new n.Mesh(u,i),[0,.5,0]],[new n.Mesh(u,i),[0,-.5,0],[Math.PI,0,0]],[new n.Mesh(p,i)]],Z:[[new n.Mesh(u,a),[0,0,.5],[Math.PI/2,0,0]],[new n.Mesh(u,a),[0,0,-.5],[-Math.PI/2,0,0]],[new n.Mesh(p,a),null,[Math.PI/2,0,0]]],XYZ:[[new n.Mesh(new n.OctahedronGeometry(.1,0),_.clone()),[0,0,0]]],XY:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),E.clone()),[.15,.15,0]]],YZ:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),l.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),m.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},T={X:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[.3,0,0],[0,0,-Math.PI/2]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,.3,0]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,-.3,0],[0,0,Math.PI]]],Z:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,0,.3],[Math.PI/2,0,0]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new n.Mesh(new n.OctahedronGeometry(.2,0),s)]],XY:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),s),[.15,.15,0]]],YZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),s),[.15,0,.15],[-Math.PI/2,0,0]]]},A={START:[[new n.Mesh(new n.OctahedronGeometry(.01,2),o),null,null,null,"helper"]],END:[[new n.Mesh(new n.OctahedronGeometry(.01,2),o),null,null,null,"helper"]],DELTA:[[new n.Line(g(),o),null,null,null,"helper"]],X:[[new n.Line(c,o.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new n.Line(c,o.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new n.Line(c,o.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},z={XYZE:[[new n.Mesh(f(.5,1),P),null,[0,Math.PI/2,0]]],X:[[new n.Mesh(f(.5,.5),r)]],Y:[[new n.Mesh(f(.5,.5),i),null,[0,0,-Math.PI/2]]],Z:[[new n.Mesh(f(.5,.5),a),null,[0,Math.PI/2,0]]],E:[[new n.Mesh(f(.75,1),C),null,[0,Math.PI/2,0]]]},tt={AXIS:[[new n.Line(c,o.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},et={XYZE:[[new n.Mesh(new n.SphereGeometry(.25,10,8),s)]],X:[[new n.Mesh(new n.TorusGeometry(.5,.1,4,24),s),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new n.Mesh(new n.TorusGeometry(.5,.1,4,24),s),[0,0,0],[Math.PI/2,0,0]]],Z:[[new n.Mesh(new n.TorusGeometry(.5,.1,4,24),s),[0,0,0],[0,0,-Math.PI/2]]],E:[[new n.Mesh(new n.TorusGeometry(.75,.1,2,24),s)]]},Ut={X:[[new n.Mesh(w,r),[.5,0,0],[0,0,-Math.PI/2]],[new n.Mesh(p,r),[0,0,0],[0,0,-Math.PI/2]],[new n.Mesh(w,r),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new n.Mesh(w,i),[0,.5,0]],[new n.Mesh(p,i)],[new n.Mesh(w,i),[0,-.5,0],[0,0,Math.PI]]],Z:[[new n.Mesh(w,a),[0,0,.5],[Math.PI/2,0,0]],[new n.Mesh(p,a),[0,0,0],[Math.PI/2,0,0]],[new n.Mesh(w,a),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),E),[.15,.15,0]]],YZ:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),l),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),m),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new n.Mesh(new n.BoxGeometry(.1,.1,.1),_.clone())]]},Lt={X:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[.3,0,0],[0,0,-Math.PI/2]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,.3,0]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,-.3,0],[0,0,Math.PI]]],Z:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,0,.3],[Math.PI/2,0,0]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),s),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),s),[.15,.15,0]]],YZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),s),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.2),s),[0,0,0]]]},Rt={X:[[new n.Line(c,o.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new n.Line(c,o.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new n.Line(c,o.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function k(I){const yt=new n.Object3D;for(const Z in I)for(let st=I[Z].length;st--;){const H=I[Z][st][0].clone(),Et=I[Z][st][1],Ct=I[Z][st][2],Tt=I[Z][st][3],fe=I[Z][st][4];H.name=Z,H.tag=fe,Et&&H.position.set(Et[0],Et[1],Et[2]),Ct&&H.rotation.set(Ct[0],Ct[1],Ct[2]),Tt&&H.scale.set(Tt[0],Tt[1],Tt[2]),H.updateMatrix();const Xt=H.geometry.clone();Xt.applyMatrix4(H.matrix),H.geometry=Xt,H.renderOrder=1/0,H.position.set(0,0,0),H.rotation.set(0,0,0),H.scale.set(1,1,1),yt.add(H)}return yt}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=k(v)),this.add(this.gizmo.rotate=k(z)),this.add(this.gizmo.scale=k(Ut)),this.add(this.picker.translate=k(T)),this.add(this.picker.rotate=k(et)),this.add(this.picker.scale=k(Lt)),this.add(this.helper.translate=k(A)),this.add(this.helper.rotate=k(tt)),this.add(this.helper.scale=k(Rt)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(t){const s=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:Mt;this.gizmo.translate.visible=this.mode==="translate",this.gizmo.rotate.visible=this.mode==="rotate",this.gizmo.scale.visible=this.mode==="scale",this.helper.translate.visible=this.mode==="translate",this.helper.rotate.visible=this.mode==="rotate",this.helper.scale.visible=this.mode==="scale";let o=[];o=o.concat(this.picker[this.mode].children),o=o.concat(this.gizmo[this.mode].children),o=o.concat(this.helper[this.mode].children);for(let r=0;r<o.length;r++){const i=o[r];i.visible=!0,i.rotation.set(0,0,0),i.position.copy(this.worldPosition);let a;if(this.camera.isOrthographicCamera?a=(this.camera.top-this.camera.bottom)/this.camera.zoom:a=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),i.scale.set(1,1,1).multiplyScalar(a*this.size/4),i.tag==="helper"){i.visible=!1,i.name==="AXIS"?(i.visible=!!this.axis,this.axis==="X"&&(L.setFromEuler(Pt.set(0,0,0)),i.quaternion.copy(s).multiply(L),Math.abs(D.copy(ft).applyQuaternion(s).dot(this.eye))>.9&&(i.visible=!1)),this.axis==="Y"&&(L.setFromEuler(Pt.set(0,0,Math.PI/2)),i.quaternion.copy(s).multiply(L),Math.abs(D.copy($).applyQuaternion(s).dot(this.eye))>.9&&(i.visible=!1)),this.axis==="Z"&&(L.setFromEuler(Pt.set(0,Math.PI/2,0)),i.quaternion.copy(s).multiply(L),Math.abs(D.copy(gt).applyQuaternion(s).dot(this.eye))>.9&&(i.visible=!1)),this.axis==="XYZE"&&(L.setFromEuler(Pt.set(0,Math.PI/2,0)),D.copy(this.rotationAxis),i.quaternion.setFromRotationMatrix(ce.lookAt(le,D,$)),i.quaternion.multiply(L),i.visible=this.dragging),this.axis==="E"&&(i.visible=!1)):i.name==="START"?(i.position.copy(this.worldPositionStart),i.visible=this.dragging):i.name==="END"?(i.position.copy(this.worldPosition),i.visible=this.dragging):i.name==="DELTA"?(i.position.copy(this.worldPositionStart),i.quaternion.copy(this.worldQuaternionStart),F.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),F.applyQuaternion(this.worldQuaternionStart.clone().invert()),i.scale.copy(F),i.visible=this.dragging):(i.quaternion.copy(s),this.dragging?i.position.copy(this.worldPositionStart):i.position.copy(this.worldPosition),this.axis&&(i.visible=this.axis.search(i.name)!==-1));continue}i.quaternion.copy(s),this.mode==="translate"||this.mode==="scale"?(i.name==="X"&&Math.abs(D.copy(ft).applyQuaternion(s).dot(this.eye))>.99&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="Y"&&Math.abs(D.copy($).applyQuaternion(s).dot(this.eye))>.99&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="Z"&&Math.abs(D.copy(gt).applyQuaternion(s).dot(this.eye))>.99&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="XY"&&Math.abs(D.copy(gt).applyQuaternion(s).dot(this.eye))<.2&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="YZ"&&Math.abs(D.copy(ft).applyQuaternion(s).dot(this.eye))<.2&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="XZ"&&Math.abs(D.copy($).applyQuaternion(s).dot(this.eye))<.2&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1)):this.mode==="rotate"&&(bt.copy(s),D.copy(this.eye).applyQuaternion(L.copy(s).invert()),i.name.search("E")!==-1&&i.quaternion.setFromRotationMatrix(ce.lookAt(this.eye,le,$)),i.name==="X"&&(L.setFromAxisAngle(ft,Math.atan2(-D.y,D.z)),L.multiplyQuaternions(bt,L),i.quaternion.copy(L)),i.name==="Y"&&(L.setFromAxisAngle($,Math.atan2(D.x,D.z)),L.multiplyQuaternions(bt,L),i.quaternion.copy(L)),i.name==="Z"&&(L.setFromAxisAngle(gt,Math.atan2(D.y,D.x)),L.multiplyQuaternions(bt,L),i.quaternion.copy(L))),i.visible=i.visible&&(i.name.indexOf("X")===-1||this.showX),i.visible=i.visible&&(i.name.indexOf("Y")===-1||this.showY),i.visible=i.visible&&(i.name.indexOf("Z")===-1||this.showZ),i.visible=i.visible&&(i.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),i.material._color=i.material._color||i.material.color.clone(),i.material._opacity=i.material._opacity||i.material.opacity,i.material.color.copy(i.material._color),i.material.opacity=i.material._opacity,this.enabled&&this.axis&&(i.name===this.axis||this.axis.split("").some(function(l){return i.name===l}))&&(i.material.color.setHex(16776960),i.material.opacity=1)}super.updateMatrixWorld(t)}}class os extends n.Mesh{constructor(){super(new n.PlaneGeometry(1e5,1e5,2,2),new n.MeshBasicMaterial({visible:!1,wireframe:!0,side:n.DoubleSide,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(t){let e=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(e="local"),St.copy(ft).applyQuaternion(e==="local"?this.worldQuaternion:Mt),pt.copy($).applyQuaternion(e==="local"?this.worldQuaternion:Mt),_t.copy(gt).applyQuaternion(e==="local"?this.worldQuaternion:Mt),D.copy(pt),this.mode){case"translate":case"scale":switch(this.axis){case"X":D.copy(this.eye).cross(St),X.copy(St).cross(D);break;case"Y":D.copy(this.eye).cross(pt),X.copy(pt).cross(D);break;case"Z":D.copy(this.eye).cross(_t),X.copy(_t).cross(D);break;case"XY":X.copy(_t);break;case"YZ":X.copy(St);break;case"XZ":D.copy(_t),X.copy(pt);break;case"XYZ":case"E":X.set(0,0,0);break}break;case"rotate":default:X.set(0,0,0)}X.length()===0?this.quaternion.copy(this.cameraQuaternion):(de.lookAt(F.set(0,0,0),X,D),this.quaternion.setFromRotationMatrix(de)),super.updateMatrixWorld(t)}}class rs{constructor(t){this.event=new pe.eventsExports.EventEmitter;const{renderer:e,scene:s,camera:o}=t,r=new We(o,e.domElement);if(r.getHelper){const i=r.getHelper();s.add(i)}else r instanceof b.Object3D&&s.add(r);this.controls=r,this.addEvent()}get detach(){return this.controls.detach.bind(this.controls)}get attach(){return this.controls.attach.bind(this.controls)}addEvent(){let t=null,e=null,s=null;const o=this.controls;o.addEventListener("change",()=>{const r=o.object;r!==void 0&&this.event.emit("change",r)}),o.addEventListener("mouseDown",()=>{const r=o.object;t=r.position.clone(),e=r.rotation.clone(),s=r.scale.clone(),this.event.emit("mouseDown",r)}),o.addEventListener("mouseUp",()=>{const r=o.object;if(r!==void 0)switch(o.getMode()){case"translate":t.equals(r.position)||this.event.emit("translate",r,r.position,t);break;case"rotate":e.equals(r.rotation)||this.event.emit("rotate",r,r.rotation,e);break;case"scale":s.equals(r.scale)||this.event.emit("scale",r,r.scale,s);break}this.event.emit("mouseUp")})}dispose(){var t;this.event.removeAllListeners(),(t=this.controls)==null||t.dispose()}}const me={zIndex:"auto"};class ns{constructor(t){this.container=t}addRenderer(t,e){const s=e.container||this.container,o=s.offsetWidth,r=s.offsetHeight,i=t==="css2d"?new De.CSS2DRenderer:new Me.CSS3DRenderer;i.domElement.style.position="absolute",i.domElement.style.top="0",i.domElement.style.pointerEvents="none",i.domElement.style.zIndex=e.zIndex,i.setSize(o,r),s.appendChild(i.domElement),t==="css2d"?this.css2Drenderer=i:t==="css3d"&&(this.css3Drenderer=i)}setSize(t,e){var s,o;(s=this.css2Drenderer)==null||s.setSize(t,e),(o=this.css3Drenderer)==null||o.setSize(t,e)}render(t,e){var s,o;(s=this.css2Drenderer)==null||s.render(t,e),(o=this.css3Drenderer)==null||o.render(t,e)}dispose(){var t,e;(t=this.css2Drenderer)==null||t.domElement.remove(),(e=this.css3Drenderer)==null||e.domElement.remove(),this.css2Drenderer=void 0,this.css3Drenderer=void 0}}const as={name:"OutputShader",uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1},premultiplieAlpha:{value:0}},vertexShader:`
2
2
  precision highp float;
3
3
 
4
4
  uniform mat4 modelViewMatrix;
@@ -70,7 +70,7 @@
70
70
 
71
71
  #endif
72
72
 
73
- }`};class hs extends Ue.OutputPass{constructor(){super();const t=as;this.uniforms=n.UniformsUtils.clone(t.uniforms),this.material=new n.RawShaderMaterial({name:t.name,uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),this.fsQuad=new Le.FullScreenQuad(this.material)}}const ls=d=>{const t=new Re.ShaderPass(new b.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:d.renderTarget2.texture},bloomAlphaType:{value:0}},vertexShader:`
73
+ }`};class hs extends Le.OutputPass{constructor(){super();const t=as;this.uniforms=n.UniformsUtils.clone(t.uniforms),this.material=new n.RawShaderMaterial({name:t.name,uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),this.fsQuad=new Ue.FullScreenQuad(this.material)}}const ls=d=>{const t=new Re.ShaderPass(new b.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:d.renderTarget2.texture},bloomAlphaType:{value:0}},vertexShader:`
74
74
  varying vec2 vUv;
75
75
  void main() {
76
76
  vUv = uv;
@@ -91,4 +91,4 @@
91
91
  gl_FragColor = ( base_color + vec4( 1.0 ) * bloom_color );
92
92
  }
93
93
  }
94
- `,defines:{}}),"baseTexture");return t.needsSwap=!0,t},Nt=1,ut=!1,cs=new b.MeshBasicMaterial({color:"black"}),ds=new b.SpriteMaterial({color:"black",sizeAttenuation:!0}),ms=new b.SpriteMaterial({color:"black",sizeAttenuation:!1}),ps={threshold:0,strength:.4,radius:.1,bloomAlphaType:0},_s={multisampling:4,premultiplieAlpha:!1};class us{constructor(t){this.bloomComposerActive=!1,this.active=!0,this.bloomSelection=new Set,this.bloomLayer=new b.Layers,this.bloomMaterials={},this.bloomVisible={},this.options=t;const{renderer:e,scene:s,camera:o,composerParams:r}=t,{multisampling:i}=r,{maxSamples:a}=e.capabilities,l=e.getDrawingBufferSize(new b.Vector2),m=new b.WebGLRenderTarget(l.width,l.height,{samples:Math.min(i,a),type:b.HalfFloatType}),E=new Ae.RenderPass(s,o),_=new qt.EffectComposer(e,m);_.addPass(E),this.renderer=e,this.scene=s,this.camera=o,this.finalComposer=_,this.renderPass=E;const C=e.getSize(new b.Vector2);this.setSize(C.width,C.height)}setRenderPassCamera(t){this.renderPass.camera=t}resetRenderPassCamera(){this.renderPass.camera=this.camera}addOutputPass(){const{premultiplieAlpha:t}=this.options.composerParams,e=new hs;this.outputPass=e,this.setPremultiplieAlpha(t),this.finalComposer.addPass(e)}setPremultiplieAlpha(t){this.outputPass&&(this.outputPass.uniforms.premultiplieAlpha.value=t?1:0)}addBloomPass(t){const{renderer:e}=this,{threshold:s,strength:o,radius:r,bloomAlphaType:i}=t,a=new ze.UnrealBloomPass(new b.Vector2(window.innerWidth,window.innerHeight),o,r,s);this.bloomPass=a;const l=new qt.EffectComposer(e);l.renderToScreen=!1,l.addPass(this.renderPass),l.addPass(a),this.bloomComposer=l;const m=ls(l);m.uniforms.bloomAlphaType.value=i,this.bloomComposer=l,this.finalComposer.addPass(m),this.mixPass=m,this.bloomLayer.set(Nt)}addBloomGui(t){if(!this.bloomComposer)return;new Gt({bloom:{threshold:{min:0,max:1,step:.01,target:()=>this.bloomPass},radius:{min:0,max:1,step:.001,target:()=>this.bloomPass},strength:{min:0,max:10,step:.001,target:()=>this.bloomPass}}}).showGui(t)}toggleBloomSelection(t,e){if(!this.bloomComposer){console.warn("err:pencil.options.bloom");return}const{object3d:s}=t;if(!s)return;let o=e;e===void 0&&(o=!this.bloomSelection.has(s)),o?(this.bloomSelection.add(s),s.layers.enable(Nt)):(this.bloomSelection.delete(s),s.layers.disable(Nt)),this.bloomSelection.size===0?this.bloomComposerActive=!1:this.bloomComposerActive=!0}enable(){this.active||(this.active=!0)}disable(){this.active&&(this.active=!1)}setSize(t,e){var s;(s=this.bloomComposer)==null||s.setSize(t,e),this.finalComposer.setSize(t,e)}setPixelRatio(t){var e;(e=this.bloomComposer)==null||e.setPixelRatio(t),this.finalComposer.setPixelRatio(t)}darkenNonBloomed(){const t=[],e=[];this.scene.children.forEach(s=>{s.isTransformControls||s.isTransformControlsRoot||s.type==="RectAreaLightHelper"?t.push(s):e.push(s)}),t.forEach(s=>{this.bloomVisible[s.uuid]=s.visible,s.visible=!1}),e.forEach(s=>{s.traverse(o=>{const r=o,i=o;r.material&&this.bloomLayer.test(r.layers)===!1&&(this.bloomMaterials[r.uuid]=r.material,i.isSprite?i.material.sizeAttenuation?i.material=ds:i.material=ms:r.material=cs)})})}restoreNonBloomed(){this.scene.traverse(t=>{const e=t;this.bloomMaterials[e.uuid]?(e.material=this.bloomMaterials[e.uuid],delete this.bloomMaterials[e.uuid]):this.bloomVisible[e.uuid]!==void 0&&(e.visible=this.bloomVisible[e.uuid],delete this.bloomVisible[e.uuid])})}render(){this.active&&(this.bloomComposerActive&&this.bloomComposer?(this.mixPass.enabled=!0,this.darkenNonBloomed(),this.bloomComposer.render(),this.restoreNonBloomed()):this.mixPass&&(this.mixPass.enabled=!1),this.finalComposer.render())}render2(){this.active}dispose(){var t;this.bloomMaterials={},this.bloomVisible={},this.bloomSelection.clear(),this.finalComposer.dispose(),(t=this.bloomComposer)==null||t.dispose()}}const At=class At{constructor(t,e){this.raycaster=new b.Raycaster,this.installPlugins=new Map,this.event=new pe.eventsExports.EventEmitter,this.clock=new b.Clock,this.userData={},this.pipViewportState=!1,this.options=we(At.options,t,{isMergeableObject:Ie.isPlainObject}),this.event.setMaxListeners(1/0);const{container:s,stats:o,gui:r,resizeObserver:i}=this.options;if(r){const a=new xe;a.open(!1),this.gui=a}if(this.init(),o){const a=new ve({horizontal:!1});a.init(this.renderer),a.dom.style.position="absolute",s.appendChild(a.dom),this.stats=a}this.options.WebGPUTHREE||this.initComposer(),this.initCSSRenderer(),this.initControls(),i&&this.initResizeObserver(),this.clock.getDelta(),this.clock.getElapsedTime(),e&&(Array.isArray(e)||(e=[e]),e.forEach(a=>{Array.isArray(a)||(a=[a]),this.use(a[0],a[1])}))}getPlugin(t){return this.installPlugins.get(t)}get renderer(){return this.rendererController.renderer}get maxAnisotropy(){return this.options.WebGPUTHREE?0:this.renderer.capabilities.getMaxAnisotropy()}get cameraControls(){return this.controlsController.cameraControls}get cameraPositon(){return this.cameraControls.getPosition(new b.Vector3,!1)}get cameraTarget(){return this.cameraControls.getTarget(new b.Vector3,!1)}get camera(){return this.cameraController.camera}get scene(){return this.sceneController.scene}use(t,...e){this.installPlugins.has(t.pluginName)?console.log("plugin already installed"):typeof t.install=="function"&&(t.install(this,...e),this.installPlugins.set(t.pluginName,t))}init(){const{container:t,isdev:e,WebGPUTHREE:s,helper:o,renderer:r,scene:i,camera:a,control:l}=this.options,{width:m,height:E}=this.getSize(),_=new Ge({isdev:e,width:m,height:E,cameraParams:a,cameraControls:l===!0});this.gui&&_.setGui(this.gui);const C=_.camera,y=new Qe({camera:C,sceneParams:i}),P=y.scene,u=s?new Be({width:m,height:E,scene:P,camera:C,isdev:e,renderer:s.WebGPURenderer,rendererParams:Ze}):new Ve({width:m,height:E,scene:P,camera:C,isdev:e,rendererParams:zt(it({},r),{antialias:!1})});if(o){const w=new je({scene:P});w.add(P),this.helperController=w}this.sceneController=y,this.rendererController=u,this.cameraController=_,t.appendChild(u.renderer.domElement)}initComposer(){const{bloom:t,bloomParams:e,composer:s}=this.options,o=new us({renderer:this.renderer,scene:this.scene,camera:this.camera,composerParams:s});this.composerController=o,t&&(o.addBloomPass(it({},e)),this.gui&&o.addBloomGui(this.gui)),o.addOutputPass()}initCSSRenderer(){const{container:t,css2DRenderer:e,css3DRenderer:s,css2DRendererParams:o,css3DRendererParams:r}=this.options;if(e||s){const i=new ns(t);e&&i.addRenderer("css2d",o),s&&i.addRenderer("css3d",r),this.cssRendererController=i}}initControls(){const{control:t,controlParams:e,transformControls:s}=this.options;if(t){const o=new qe({camera:this.camera,controlsParams:{domElement:(e==null?void 0:e.domElement)||this.renderer.domElement},customControl:typeof t=="boolean"?void 0:t});this.controlsController=o}if(s){const o=new rs({camera:this.camera,renderer:this.renderer,scene:this.scene});o.event.on("mouseDown",()=>{var r;(r=this.controlsController)==null||r.disable()}),o.event.on("mouseUp",()=>{var r;(r=this.controlsController)==null||r.enable()}),this.transformController=o}}getSize(){const{container:t}=this.options;return{width:t.offsetWidth,height:t.offsetHeight}}initResizeObserver(){const{container:t}=this.options;if(this.resizeObserver)return;const e=this.getSize(),s=new ResizeObserver(o=>{for(const r of o){const i=r.contentRect;(i.width!==e.width||i.height!==e.height)&&(e.width=i.width,e.height=i.height,this.handeleResize(i.width,i.height),this.render())}});s.observe(t),this.resizeObserver=s}handeleResize(t,e,s=!0){const{rendererController:o,cameraController:r,composerController:i,cssRendererController:a}=this;r==null||r.setSize(t,e),o==null||o.setSize(t,e),i==null||i.setSize(t,e),a==null||a.setSize(t,e),this.installPlugins.forEach(l=>{var m;(m=l.setSize)==null||m.call(l,t,e)}),s&&this.event.emit("resize",{width:t,height:e})}setDevicePixelRatio(t){var e;this.rendererController.setPixelRatio(t),(e=this.composerController)==null||e.setPixelRatio(t)}pick(t,e,s=!0){const{raycaster:o,options:r}=this,{container:i}=r,a=new b.Vector2,l=i.getBoundingClientRect();if(a.x=(t.clientX-l.left)/(l.right-l.left)*2-1,a.y=-((t.clientY-l.top)/(l.bottom-l.top))*2+1,this.camera&&this.scene){o.setFromCamera(a,this.camera);const m=o.intersectObjects(e||this.scene.children,s);if(m.length)return{object:m[0].object,intersects:m}}}render(){var i,a,l,m,E,_;const{scene:t,camera:e,clock:s}=this,o=s.getDelta(),r=s.getElapsedTime();Wt.update(),(i=this.controlsController)==null||i.update(o),this.installPlugins.forEach(C=>{var y;(y=C.update)==null||y.call(C,o,r)}),(a=this.helperController)==null||a.update(),this.cameraController.sync(),(l=this.composerController)!=null&&l.active?this.cameraController.camera2?(this.composerController.resetRenderPassCamera(),this.setViewportFull(),this.composerController.render(),this.pipViewportState&&(this.setViewportPip(),this.composerController.setRenderPassCamera(this.cameraController.camera2),this.composerController.render())):this.composerController.render():(m=this.rendererController)==null||m.render(),(E=this.cssRendererController)==null||E.render(t,e),(_=this.stats)==null||_.update(),this.event.emit("render",{delta:o,elapsed:r})}start(){this.renderer.setAnimationLoop(this.render.bind(this)),this.event.emit("start")}stop(){this.renderer.setAnimationLoop(null),this.event.emit("stop")}autoRotate(t){this.controlsController.autoRotateSpeed=t}showPipViewport(t){if(t===!0){const e=this.getSize(),s=240,o=s/e.width,r=s/e.height,i=1-o,a=1-r;t={left:i,top:a,width:o,height:r}}if(this.pipViewportState=t,t){if(this.controlsController.cameraControls2)this.controlsController.cameraControls2.enabled=!0,this.cameraController.camera2.position.copy(this.cameraController.camera.position);else{const e=this.cameraController.addCamera2();this.controlsController.addCameraControls2(e)}this.controlsController.cameraControls2.interactiveArea=new DOMRect(t.left,t.top,t.width,t.height)}else this.controlsController.cameraControls2&&(this.controlsController.cameraControls2.enabled=!1)}setViewportFull(){const t=this.getSize(),e=0,s=0,o=t.width,r=t.height,i=o/r;this.camera.aspect!==i&&(this.camera.aspect=i,this.camera.updateProjectionMatrix()),this.renderer.setViewport(e,s,o,r),this.renderer.setScissor(e,s,o,r),this.renderer.setScissorTest(!0)}setViewportPip(){if(!this.pipViewportState)return;const t=this.pipViewportState,e=this.getSize(),s=e.width*t.left,o=(1-(t.top+t.height))*e.height,r=e.width*t.width,i=e.height*t.height,a=r/i,l=this.cameraController.camera2;l&&l.aspect!==a&&(l.aspect=a,l.updateProjectionMatrix()),this.renderer.setViewport(s,o,r,i),this.renderer.setScissor(s,o,r,i),this.renderer.setScissorTest(!0)}dispose(){var t,e,s,o,r,i,a,l,m,E,_;this.stop(),Wt.removeAll(),this.event.removeAllListeners(),(t=this.resizeObserver)==null||t.unobserve(this.options.container),this.installPlugins.forEach(C=>{var y;(y=C.dispose)==null||y.call(C)}),(e=this.controlsController)==null||e.dispose(),(s=this.transformController)==null||s.dispose(),(o=this.cssRendererController)==null||o.dispose(),(r=this.sceneController)==null||r.dispose(),(i=this.helperController)==null||i.dispose(),(a=this.composerController)==null||a.dispose(),(l=this.rendererController)==null||l.dispose(),this.cssRendererController=void 0,(m=this.gui)==null||m.destroy(),this.installPlugins.clear(),(E=this.stats)==null||E.dom.remove(),(_=this.renderer)==null||_.domElement.remove()}};At.options={isdev:ut,stats:ut,gui:ut,helper:ut,control:!0,transformControls:ut,resizeObserver:!0,renderer:ke,composer:_s,scene:Xe,camera:Ne,bloom:!1,bloomParams:ps,css2DRenderer:!1,css2DRendererParams:it({},me),css3DRenderer:!1,css3DRendererParams:it({},me)};let Dt=At;const fs=J.ACTION;exports.BaseObject=Fe.BaseObject;exports.GUIObject=Gt;exports.Pencil=Dt;exports.cameraControlsAction=fs;exports.default=Dt;
94
+ `,defines:{}}),"baseTexture");return t.needsSwap=!0,t},Nt=1,ut=!1,cs=new b.MeshBasicMaterial({color:"black"}),ds=new b.SpriteMaterial({color:"black",sizeAttenuation:!0}),ms=new b.SpriteMaterial({color:"black",sizeAttenuation:!1}),ps={threshold:0,strength:.4,radius:.1,bloomAlphaType:0},_s={multisampling:4,premultiplieAlpha:!1};class us{constructor(t){this.bloomComposerActive=!1,this.active=!0,this.bloomSelection=new Set,this.bloomLayer=new b.Layers,this.bloomMaterials={},this.bloomVisible={},this.options=t;const{renderer:e,scene:s,camera:o,composerParams:r}=t,{multisampling:i}=r,{maxSamples:a}=e.capabilities,l=e.getDrawingBufferSize(new b.Vector2),m=new b.WebGLRenderTarget(l.width,l.height,{samples:Math.min(i,a),type:b.HalfFloatType}),E=new Ae.RenderPass(s,o),_=new qt.EffectComposer(e,m);_.addPass(E),this.renderer=e,this.scene=s,this.camera=o,this.finalComposer=_,this.renderPass=E;const C=e.getSize(new b.Vector2);this.setSize(C.width,C.height)}setRenderPassCamera(t){this.renderPass.camera=t}resetRenderPassCamera(){this.renderPass.camera=this.camera}addOutputPass(){const{premultiplieAlpha:t}=this.options.composerParams,e=new hs;this.outputPass=e,this.setPremultiplieAlpha(t),this.finalComposer.addPass(e)}setPremultiplieAlpha(t){this.outputPass&&(this.outputPass.uniforms.premultiplieAlpha.value=t?1:0)}addBloomPass(t){const{renderer:e}=this,{threshold:s,strength:o,radius:r,bloomAlphaType:i}=t,a=new ze.UnrealBloomPass(new b.Vector2(window.innerWidth,window.innerHeight),o,r,s);this.bloomPass=a;const l=new qt.EffectComposer(e);l.renderToScreen=!1,l.addPass(this.renderPass),l.addPass(a),this.bloomComposer=l;const m=ls(l);m.uniforms.bloomAlphaType.value=i,this.bloomComposer=l,this.finalComposer.addPass(m),this.mixPass=m,this.bloomLayer.set(Nt)}addBloomGui(t){if(!this.bloomComposer)return;new Gt({bloom:{threshold:{min:0,max:1,step:.01,target:()=>this.bloomPass},radius:{min:0,max:1,step:.001,target:()=>this.bloomPass},strength:{min:0,max:10,step:.001,target:()=>this.bloomPass}}}).showGui(t)}toggleBloomSelection(t,e){if(!this.bloomComposer){console.warn("err:pencil.options.bloom");return}const{object3d:s}=t;if(!s)return;let o=e;e===void 0&&(o=!this.bloomSelection.has(s)),o?(this.bloomSelection.add(s),s.layers.enable(Nt)):(this.bloomSelection.delete(s),s.layers.disable(Nt)),this.bloomSelection.size===0?this.bloomComposerActive=!1:this.bloomComposerActive=!0}enable(){this.active||(this.active=!0)}disable(){this.active&&(this.active=!1)}setSize(t,e){var s;(s=this.bloomComposer)==null||s.setSize(t,e),this.finalComposer.setSize(t,e)}setPixelRatio(t){var e;(e=this.bloomComposer)==null||e.setPixelRatio(t),this.finalComposer.setPixelRatio(t)}darkenNonBloomed(){const t=[],e=[];this.scene.children.forEach(s=>{s.isTransformControls||s.isTransformControlsRoot||s.type==="RectAreaLightHelper"?t.push(s):e.push(s)}),t.forEach(s=>{this.bloomVisible[s.uuid]=s.visible,s.visible=!1}),e.forEach(s=>{s.traverse(o=>{const r=o,i=o;r.material&&this.bloomLayer.test(r.layers)===!1&&(this.bloomMaterials[r.uuid]=r.material,i.isSprite?i.material.sizeAttenuation?i.material=ds:i.material=ms:r.material=cs)})})}restoreNonBloomed(){this.scene.traverse(t=>{const e=t;this.bloomMaterials[e.uuid]?(e.material=this.bloomMaterials[e.uuid],delete this.bloomMaterials[e.uuid]):this.bloomVisible[e.uuid]!==void 0&&(e.visible=this.bloomVisible[e.uuid],delete this.bloomVisible[e.uuid])})}render(){this.active&&(this.bloomComposerActive&&this.bloomComposer?(this.mixPass.enabled=!0,this.darkenNonBloomed(),this.bloomComposer.render(),this.restoreNonBloomed()):this.mixPass&&(this.mixPass.enabled=!1),this.finalComposer.render())}render2(){this.active}dispose(){var t;this.bloomMaterials={},this.bloomVisible={},this.bloomSelection.clear(),this.finalComposer.dispose(),(t=this.bloomComposer)==null||t.dispose()}}const At=class At{constructor(t,e){this.raycaster=new b.Raycaster,this.installPlugins=new Map,this.event=new pe.eventsExports.EventEmitter,this.clock=new b.Clock,this.userData={},this.pipViewportState=!1,this.options=we(At.options,t,{isMergeableObject:Ie.isPlainObject}),this.event.setMaxListeners(1/0);const{container:s,stats:o,gui:r,resizeObserver:i}=this.options;if(r){const a=new xe;a.open(!1),this.gui=a}if(this.init(),o){const a=new ve({horizontal:!1});a.init(this.renderer),a.dom.style.position="absolute",s.appendChild(a.dom),this.stats=a}this.options.WebGPUTHREE||this.initComposer(),this.initCSSRenderer(),this.initControls(),i&&this.initResizeObserver(),this.clock.getDelta(),this.clock.getElapsedTime(),e&&(Array.isArray(e)||(e=[e]),e.forEach(a=>{Array.isArray(a)||(a=[a]),this.use(a[0],a[1])}))}getPlugin(t){return this.installPlugins.get(t)}get renderer(){return this.rendererController.renderer}get maxAnisotropy(){return this.options.WebGPUTHREE?0:this.renderer.capabilities.getMaxAnisotropy()}get cameraControls(){return this.controlsController.cameraControls}get cameraPositon(){return this.cameraControls.getPosition(new b.Vector3,!1)}get cameraTarget(){return this.cameraControls.getTarget(new b.Vector3,!1)}get camera(){return this.cameraController.camera}get scene(){return this.sceneController.scene}use(t,...e){this.installPlugins.has(t.pluginName)?console.log("plugin already installed"):typeof t.install=="function"&&(t.install(this,...e),this.installPlugins.set(t.pluginName,t))}init(){const{container:t,isdev:e,WebGPUTHREE:s,helper:o,renderer:r,scene:i,camera:a,control:l}=this.options,{width:m,height:E}=this.getSize(),_=new Ge({isdev:e,width:m,height:E,cameraParams:a,cameraControls:l===!0});this.gui&&_.setGui(this.gui);const C=_.camera,y=new Qe({camera:C,sceneParams:i}),P=y.scene,u=s?new Be({width:m,height:E,scene:P,camera:C,isdev:e,renderer:s.WebGPURenderer,rendererParams:Ze}):new ke({width:m,height:E,scene:P,camera:C,isdev:e,rendererParams:zt(it({},r),{antialias:!1})});if(o){const w=new je({scene:P});w.add(P),this.helperController=w}this.sceneController=y,this.rendererController=u,this.cameraController=_,t.appendChild(u.renderer.domElement)}initComposer(){const{bloom:t,bloomParams:e,composer:s}=this.options,o=new us({renderer:this.renderer,scene:this.scene,camera:this.camera,composerParams:s});this.composerController=o,t&&(o.addBloomPass(it({},e)),this.gui&&o.addBloomGui(this.gui)),o.addOutputPass()}initCSSRenderer(){const{container:t,css2DRenderer:e,css3DRenderer:s,css2DRendererParams:o,css3DRendererParams:r}=this.options;if(e||s){const i=new ns(t);e&&i.addRenderer("css2d",o),s&&i.addRenderer("css3d",r),this.cssRendererController=i}}initControls(){const{control:t,controlParams:e,transformControls:s}=this.options;if(t){const o=new qe({camera:this.camera,controlsParams:{domElement:(e==null?void 0:e.domElement)||this.renderer.domElement},customControl:typeof t=="boolean"?void 0:t});this.controlsController=o}if(s){const o=new rs({camera:this.camera,renderer:this.renderer,scene:this.scene});o.event.on("mouseDown",()=>{var r;(r=this.controlsController)==null||r.disable()}),o.event.on("mouseUp",()=>{var r;(r=this.controlsController)==null||r.enable()}),this.transformController=o}}getSize(){const{container:t}=this.options;return{width:t.offsetWidth,height:t.offsetHeight}}initResizeObserver(){const{container:t}=this.options;if(this.resizeObserver)return;const e=this.getSize(),s=new ResizeObserver(o=>{for(const r of o){const i=r.contentRect;(i.width!==e.width||i.height!==e.height)&&(e.width=i.width,e.height=i.height,this.handeleResize(i.width,i.height),this.render())}});s.observe(t),this.resizeObserver=s}handeleResize(t,e,s=!0){const{rendererController:o,cameraController:r,composerController:i,cssRendererController:a}=this;r==null||r.setSize(t,e),o==null||o.setSize(t,e),i==null||i.setSize(t,e),a==null||a.setSize(t,e),this.installPlugins.forEach(l=>{var m;(m=l.setSize)==null||m.call(l,t,e)}),s&&this.event.emit("resize",{width:t,height:e})}setDevicePixelRatio(t){var e;this.rendererController.setPixelRatio(t),(e=this.composerController)==null||e.setPixelRatio(t)}pick(t,e,s=!0){const{raycaster:o,options:r}=this,{container:i}=r,a=new b.Vector2,l=i.getBoundingClientRect();if(a.x=(t.clientX-l.left)/(l.right-l.left)*2-1,a.y=-((t.clientY-l.top)/(l.bottom-l.top))*2+1,this.camera&&this.scene){o.setFromCamera(a,this.camera);const m=o.intersectObjects(e||this.scene.children,s);if(m.length)return{object:m[0].object,intersects:m}}}render(){var i,a,l,m,E,_;const{scene:t,camera:e,clock:s}=this,o=s.getDelta(),r=s.getElapsedTime();Wt.update(),(i=this.controlsController)==null||i.update(o),this.installPlugins.forEach(C=>{var y;(y=C.update)==null||y.call(C,o,r)}),(a=this.helperController)==null||a.update(),this.cameraController.sync(),(l=this.composerController)!=null&&l.active?this.cameraController.camera2?(this.composerController.resetRenderPassCamera(),this.setViewportFull(),this.composerController.render(),this.pipViewportState&&(this.setViewportPip(),this.composerController.setRenderPassCamera(this.cameraController.camera2),this.composerController.render())):this.composerController.render():(m=this.rendererController)==null||m.render(),(E=this.cssRendererController)==null||E.render(t,e),(_=this.stats)==null||_.update(),this.event.emit("render",{delta:o,elapsed:r})}start(){this.renderer.setAnimationLoop(this.render.bind(this)),this.event.emit("start")}stop(){this.renderer.setAnimationLoop(null),this.event.emit("stop")}autoRotate(t){this.controlsController.autoRotateSpeed=t}showPipViewport(t){if(t===!0){const e=this.getSize(),s=240,o=s/e.width,r=s/e.height,i=1-o,a=1-r;t={left:i,top:a,width:o,height:r}}if(this.pipViewportState=t,t){if(this.controlsController.cameraControls2)this.controlsController.cameraControls2.enabled=!0,this.cameraController.camera2.position.copy(this.cameraController.camera.position);else{const e=this.cameraController.addCamera2();this.controlsController.addCameraControls2(e)}this.controlsController.cameraControls2.interactiveArea=new DOMRect(t.left,t.top,t.width,t.height)}else this.controlsController.cameraControls2&&(this.controlsController.cameraControls2.enabled=!1)}setViewportFull(){const t=this.getSize(),e=0,s=0,o=t.width,r=t.height,i=o/r;this.camera.aspect!==i&&(this.camera.aspect=i,this.camera.updateProjectionMatrix()),this.renderer.setViewport(e,s,o,r),this.renderer.setScissor(e,s,o,r),this.renderer.setScissorTest(!0)}setViewportPip(){if(!this.pipViewportState)return;const t=this.pipViewportState,e=this.getSize(),s=e.width*t.left,o=(1-(t.top+t.height))*e.height,r=e.width*t.width,i=e.height*t.height,a=r/i,l=this.cameraController.camera2;l&&l.aspect!==a&&(l.aspect=a,l.updateProjectionMatrix()),this.renderer.setViewport(s,o,r,i),this.renderer.setScissor(s,o,r,i),this.renderer.setScissorTest(!0)}dispose(){var t,e,s,o,r,i,a,l,m,E,_;this.stop(),Wt.removeAll(),this.event.removeAllListeners(),(t=this.resizeObserver)==null||t.unobserve(this.options.container),this.installPlugins.forEach(C=>{var y;(y=C.dispose)==null||y.call(C)}),(e=this.controlsController)==null||e.dispose(),(s=this.transformController)==null||s.dispose(),(o=this.cssRendererController)==null||o.dispose(),(r=this.sceneController)==null||r.dispose(),(i=this.helperController)==null||i.dispose(),(a=this.composerController)==null||a.dispose(),(l=this.rendererController)==null||l.dispose(),this.cssRendererController=void 0,(m=this.gui)==null||m.destroy(),this.installPlugins.clear(),(E=this.stats)==null||E.dom.remove(),(_=this.renderer)==null||_.domElement.remove()}};At.options={isdev:ut,stats:ut,gui:ut,helper:ut,control:!0,transformControls:ut,resizeObserver:!0,renderer:Ve,composer:_s,scene:Xe,camera:Ne,bloom:!1,bloomParams:ps,css2DRenderer:!1,css2DRendererParams:it({},me),css3DRenderer:!1,css3DRendererParams:it({},me)};let Dt=At;const fs=J.ACTION;exports.BaseObject=Fe.BaseObject;exports.GUIObject=Gt;exports.Pencil=Dt;exports.cameraControlsAction=fs;exports.default=Dt;