gl-draw 0.11.16 → 0.11.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Wt=Object.defineProperty,Gt=Object.defineProperties;var Xt=Object.getOwnPropertyDescriptors;var Ot=Object.getOwnPropertySymbols;var Kt=Object.prototype.hasOwnProperty,jt=Object.prototype.propertyIsEnumerable;var Et=(u,t,e)=>t in u?Wt(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,N=(u,t)=>{for(var e in t||(t={}))Kt.call(t,e)&&Et(u,e,t[e]);if(Ot)for(var e of Ot(t))jt.call(t,e)&&Et(u,e,t[e]);return u},mt=(u,t)=>Gt(u,Xt(t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const z=require("three"),Qt=require("@tweenjs/tween.js"),Vt=require("./events.js"),$t=require("deepmerge"),Jt=require("stats-gl"),te=require("lil-gui"),ee=require("./colorCorrection.js"),se=require("./disposeMesh.js");require("idb-keyval");require("esus-lite");require("d3-geo");require("d3-geo-projection");const ie=require("three/examples/jsm/helpers/RectAreaLightHelper"),oe=require("three/examples/jsm/helpers/ViewHelper"),re=require("three/examples/jsm/controls/TransformControls"),Tt=require("three/examples/jsm/postprocessing/EffectComposer"),ne=require("three/examples/jsm/postprocessing/RenderPass"),ae=require("three/examples/jsm/postprocessing/SSAOPass"),he=require("three/examples/jsm/postprocessing/Pass"),le=require("three/examples/jsm/postprocessing/OutputPass"),ce=require("three/examples/jsm/postprocessing/ShaderPass"),de=require("three/examples/jsm/postprocessing/UnrealBloomPass"),me=require("./isPlainObject.js"),pe=require("./BaseObject.js");function kt(u){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const e in u)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(u,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>u[e]})}}return t.default=u,Object.freeze(t)}const P=kt(z),vt=kt(Qt),A={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}),q={NONE:0,IN:1,OUT:-1};function B(u){return u.isPerspectiveCamera}function k(u){return u.isOrthographicCamera}const W=Math.PI*2,xt=Math.PI/2,Nt=1e-5,Q=Math.PI/180;function F(u,t,e){return Math.max(t,Math.min(e,u))}function U(u,t=Nt){return Math.abs(u)<t}function D(u,t,e=Nt){return U(u-t,e)}function wt(u,t){return Math.round(u/t)*t}function $(u){return isFinite(u)?u:u<0?-Number.MAX_VALUE:Number.MAX_VALUE}function J(u){return Math.abs(u)<Number.MAX_VALUE?u:u*(1/0)}function ot(u,t,e,s,i=1/0,o){s=Math.max(1e-4,s);const n=2/s,a=n*o,l=1/(1+a+.48*a*a+.235*a*a*a);let m=u-t;const C=t,c=i*s;m=F(m,-c,c),t=u-m;const E=(e.value+n*m)*o;e.value=(e.value-n*E)*l;let y=t+(m+E)*l;return C-u>0==y>C&&(y=C,e.value=(y-C)/o),y}function Pt(u,t,e,s,i=1/0,o,n){s=Math.max(1e-4,s);const a=2/s,l=a*o,m=1/(1+l+.48*l*l+.235*l*l*l);let C=t.x,c=t.y,E=t.z,y=u.x-C,f=u.y-c,p=u.z-E;const _=C,r=c,d=E,O=i*s,g=O*O,x=y*y+f*f+p*p;if(x>g){const dt=Math.sqrt(x);y=y/dt*O,f=f/dt*O,p=p/dt*O}C=u.x-y,c=u.y-f,E=u.z-p;const T=(e.x+a*y)*o,b=(e.y+a*f)*o,R=(e.z+a*p)*o;e.x=(e.x-a*T)*m,e.y=(e.y-a*b)*m,e.z=(e.z-a*R)*m,n.x=C+(y+T)*m,n.y=c+(f+b)*m,n.z=E+(p+R)*m;const st=_-u.x,it=r-u.y,Bt=d-u.z,Yt=n.x-_,Zt=n.y-r,qt=n.z-d;return st*Yt+it*Zt+Bt*qt>0&&(n.x=_,n.y=r,n.z=d,e.x=(n.x-_)/o,e.y=(n.y-r)/o,e.z=(n.z-d)/o),n}function pt(u,t){t.set(0,0),u.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=u.length,t.y/=u.length}function _t(u,t){return k(u)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}class _e{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 i=this._listeners[t];if(i!==void 0){const o=i.indexOf(e);o!==-1&&i.splice(o,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 i=s.slice(0);for(let o=0,n=i.length;o<n;o++)i[o].call(this,t)}}}const rt=1/8,ue=/Mac/.test(navigator.platform);let v,St,nt,ut,L,w,S,G,tt,H,I,Y,Dt,bt,M,et,X,Ut,ft,At,gt,yt,at;class Z extends _e{static install(t){v=t.THREE,St=Object.freeze(new v.Vector3(0,0,0)),nt=Object.freeze(new v.Vector3(0,1,0)),ut=Object.freeze(new v.Vector3(0,0,1)),L=new v.Vector2,w=new v.Vector3,S=new v.Vector3,G=new v.Vector3,tt=new v.Vector3,H=new v.Vector3,I=new v.Vector3,Y=new v.Vector3,Dt=new v.Vector3,bt=new v.Vector3,M=new v.Spherical,et=new v.Spherical,X=new v.Box3,Ut=new v.Box3,ft=new v.Sphere,At=new v.Quaternion,gt=new v.Quaternion,yt=new v.Matrix4,at=new v.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=q.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new v.Vector3,this._focalOffsetVelocity=new v.Vector3,this._zoomVelocity={value:0},this._truckInternal=(r,d,O)=>{let g,x;if(B(this._camera)){const T=w.copy(this._camera.position).sub(this._target),b=this._camera.getEffectiveFOV()*Q,R=T.length()*Math.tan(b*.5);g=this.truckSpeed*r*R/this._elementRect.height,x=this.truckSpeed*d*R/this._elementRect.height}else if(k(this._camera)){const T=this._camera;g=r*(T.right-T.left)/T.zoom/this._elementRect.width,x=d*(T.top-T.bottom)/T.zoom/this._elementRect.height}else return;this.verticalDragToForward?(O?this.setFocalOffset(this._focalOffsetEnd.x+g,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(g,0,!0),this.forward(-x,!0)):O?this.setFocalOffset(this._focalOffsetEnd.x+g,this._focalOffsetEnd.y+x,this._focalOffsetEnd.z,!0):this.truck(g,x,!0)},this._rotateInternal=(r,d)=>{const O=W*this.azimuthRotateSpeed*r/this._elementRect.height,g=W*this.polarRotateSpeed*d/this._elementRect.height;this.rotate(O,g,!0)},this._dollyInternal=(r,d,O)=>{const g=Math.pow(.95,-r*this.dollySpeed),x=this._sphericalEnd.radius,T=this._sphericalEnd.radius*g,b=F(T,this.minDistance,this.maxDistance),R=b-T;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(T,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(R,!0),this._dollyToNoClamp(b,!0)):this._dollyToNoClamp(b,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?T:b)-x,this._dollyControlCoord.set(d,O)),this._lastDollyDirection=Math.sign(-r)},this._zoomInternal=(r,d,O)=>{const g=Math.pow(.95,r*this.dollySpeed),x=this._zoom,T=this._zoom*g;this.zoomTo(T,!0),this.dollyToCursor&&(this._changedZoom+=T-x,this._dollyControlCoord.set(d,O))},typeof v=="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 v.Quaternion().setFromUnitVectors(this._camera.up,nt),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=h.NONE,this._target=new v.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new v.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new v.Spherical().setFromVector3(w.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 v.Vector3,new v.Vector3,new v.Vector3,new v.Vector3],this._updateNearPlaneCorners(),this._boundary=new v.Box3(new v.Vector3(-1/0,-1/0,-1/0),new v.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 v.Vector2,this.mouseButtons={left:h.ROTATE,middle:h.DOLLY,right:h.TRUCK,wheel:B(this._camera)?h.DOLLY:k(this._camera)?h.ZOOM:h.NONE},this.touches={one:h.TOUCH_ROTATE,two:B(this._camera)?h.TOUCH_DOLLY_TRUCK:k(this._camera)?h.TOUCH_ZOOM_TRUCK:h.NONE,three:h.TOUCH_TRUCK};const s=new v.Vector2,i=new v.Vector2,o=new v.Vector2,n=r=>{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(),x=(r.clientX-g.left)/(g.right-g.left),T=(r.clientY-g.top)/(g.bottom-g.top);if(x<this._interactiveArea.left||x>this._interactiveArea.right||T<this._interactiveArea.top||T>this._interactiveArea.bottom)return}const d=r.pointerType!=="mouse"?null:(r.buttons&A.LEFT)===A.LEFT?A.LEFT:(r.buttons&A.MIDDLE)===A.MIDDLE?A.MIDDLE:(r.buttons&A.RIGHT)===A.RIGHT?A.RIGHT:null;if(d!==null){const g=this._findPointerByMouseButton(d);g&&this._disposePointer(g)}if((r.buttons&A.LEFT)===A.LEFT&&this._lockedPointer)return;const O={pointerId:r.pointerId,clientX:r.clientX,clientY:r.clientY,deltaX:0,deltaY:0,mouseButton:d};this._activePointers.push(O),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,E(r)},a=r=>{r.cancelable&&r.preventDefault();const d=r.pointerId,O=this._lockedPointer||this._findPointerById(d);if(O){if(O.clientX=r.clientX,O.clientY=r.clientY,O.deltaX=r.movementX,O.deltaY=r.movementY,this._state=0,r.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&&(r.buttons&A.LEFT)===A.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(r.buttons&A.MIDDLE)===A.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(r.buttons&A.RIGHT)===A.RIGHT&&(this._state=this._state|this.mouseButtons.right);y()}},l=r=>{const d=this._findPointerById(r.pointerId);if(!(d&&d===this._lockedPointer)){if(d&&this._disposePointer(d),r.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;f()}};let m=-1;const C=r=>{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(),b=(r.clientX-T.left)/(T.right-T.left),R=(r.clientY-T.top)/(T.bottom-T.top);if(b<this._interactiveArea.left||b>this._interactiveArea.right||R<this._interactiveArea.top||R>this._interactiveArea.bottom)return}if(r.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 d=ue?-1:-3,O=r.deltaMode===1?r.deltaY/d:r.deltaY/(d*10),g=this.dollyToCursor?(r.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,x=this.dollyToCursor?(r.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case h.ROTATE:{this._rotateInternal(r.deltaX,r.deltaY),this._isUserControllingRotate=!0;break}case h.TRUCK:{this._truckInternal(r.deltaX,r.deltaY,!1),this._isUserControllingTruck=!0;break}case h.OFFSET:{this._truckInternal(r.deltaX,r.deltaY,!0),this._isUserControllingOffset=!0;break}case h.DOLLY:{this._dollyInternal(-O,g,x),this._isUserControllingDolly=!0;break}case h.ZOOM:{this._zoomInternal(-O,g,x),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},c=r=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===Z.ACTION.NONE){const d=r instanceof PointerEvent?r.pointerId:0,O=this._findPointerById(d);O&&this._disposePointer(O),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l);return}r.preventDefault()}},E=r=>{if(!this._enabled)return;if(pt(this._activePointers,L),this._getClientRect(this._elementRect),s.copy(L),i.copy(L),this._activePointers.length>=2){const O=L.x-this._activePointers[1].clientX,g=L.y-this._activePointers[1].clientY,x=Math.sqrt(O*O+g*g);o.set(0,x);const T=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,b=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;i.set(T,b)}if(this._state=0,!r)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in r&&r.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&&(r.buttons&A.LEFT)===A.LEFT&&(this._state=this._state|this.mouseButtons.left),(r.buttons&A.MIDDLE)===A.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(r.buttons&A.RIGHT)===A.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,pt(this._activePointers,L);const d=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,O=d?-d.deltaX:i.x-L.x,g=d?-d.deltaY:i.y-L.y;if(i.copy(L),((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(O,g),this._isUserControllingRotate=!0),(this._state&h.DOLLY)===h.DOLLY||(this._state&h.ZOOM)===h.ZOOM){const x=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,b=this.dollyDragInverted?-1:1;(this._state&h.DOLLY)===h.DOLLY?(this._dollyInternal(b*g*rt,x,T),this._isUserControllingDolly=!0):(this._zoomInternal(b*g*rt,x,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 x=L.x-this._activePointers[1].clientX,T=L.y-this._activePointers[1].clientY,b=Math.sqrt(x*x+T*T),R=o.y-b;o.set(0,b);const st=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,it=this.dollyToCursor?(i.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(R*rt,st,it),this._isUserControllingDolly=!0):(this._zoomInternal(R*rt,st,it),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(O,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(O,g,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},f=()=>{pt(this._activePointers,L),i.copy(L),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",p),this._domElement.ownerDocument.addEventListener("pointerlockerror",_),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),E())},this.unlockPointer=()=>{var r,d,O;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(r=this._domElement)===null||r===void 0||r.ownerDocument.exitPointerLock(),(d=this._domElement)===null||d===void 0||d.ownerDocument.removeEventListener("pointerlockchange",p),(O=this._domElement)===null||O===void 0||O.ownerDocument.removeEventListener("pointerlockerror",_),this.cancel()};const p=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},_=()=>{this.unlockPointer()};this._addAllEventListeners=r=>{this._domElement=r,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",n),this._domElement.addEventListener("pointercancel",l),this._domElement.addEventListener("wheel",C,{passive:!1}),this._domElement.addEventListener("contextmenu",c)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",n),this._domElement.removeEventListener("pointercancel",l),this._domElement.removeEventListener("wheel",C,{passive:!1}),this._domElement.removeEventListener("contextmenu",c),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.removeEventListener("pointerlockchange",p),this._domElement.ownerDocument.removeEventListener("pointerlockerror",_))},this.cancel=()=>{this._state!==h.NONE&&(this._state=h.NONE,this._activePointers.length=0,f())},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=F(t.width,0,1),this._interactiveArea.height=F(t.height,0,1),this._interactiveArea.x=F(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=F(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 i=F(t,this.minAzimuthAngle,this.maxAzimuthAngle),o=F(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=o,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const n=!s||D(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&D(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(n)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=q.NONE,this._changedDolly=0,this._dollyToNoClamp(F(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const n=this._collisionTest(),a=D(n,this._spherical.radius);if(!(s>t)&&a)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,n)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const o=!e||D(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(o)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(tt).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const s=!e||D(this._target.x,this._targetEnd.x,this.restThreshold)&&D(this._target.y,this._targetEnd.y,this.restThreshold)&&D(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=F(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const s=!e||D(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(),H.setFromMatrixColumn(this._camera.matrix,0),I.setFromMatrixColumn(this._camera.matrix,1),H.multiplyScalar(t),I.multiplyScalar(-e);const i=w.copy(H).add(I),o=S.copy(this._targetEnd).add(i);return this.moveTo(o.x,o.y,o.z,s)}forward(t,e=!1){w.setFromMatrixColumn(this._camera.matrix,0),w.crossVectors(this._camera.up,w),w.multiplyScalar(t);const s=S.copy(this._targetEnd).add(w);return this.moveTo(s.x,s.y,s.z,e)}elevate(t,e=!1){return w.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+w.x,this._targetEnd.y+w.y,this._targetEnd.z+w.z,e)}moveTo(t,e,s,i=!1){this._isUserControllingTruck=!1;const o=w.set(t,e,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,o,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const n=!i||D(this._target.x,this._targetEnd.x,this.restThreshold)&&D(this._target.y,this._targetEnd.y,this.restThreshold)&&D(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}lookInDirectionOf(t,e,s,i=!1){const a=w.set(t,e,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(a.x,a.y,a.z,i)}fitToBox(t,e,{cover:s=!1,paddingLeft:i=0,paddingRight:o=0,paddingBottom:n=0,paddingTop:a=0}={}){const l=[],m=t.isBox3?X.copy(t):X.setFromObject(t);m.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const C=wt(this._sphericalEnd.theta,xt),c=wt(this._sphericalEnd.phi,xt);l.push(this.rotateTo(C,c,e));const E=w.setFromSpherical(this._sphericalEnd).normalize(),y=At.setFromUnitVectors(E,ut),f=D(Math.abs(E.y),1);f&&y.multiply(gt.setFromAxisAngle(nt,C)),y.multiply(this._yAxisUpSpaceInverse);const p=Ut.makeEmpty();S.copy(m.min).applyQuaternion(y),p.expandByPoint(S),S.copy(m.min).setX(m.max.x).applyQuaternion(y),p.expandByPoint(S),S.copy(m.min).setY(m.max.y).applyQuaternion(y),p.expandByPoint(S),S.copy(m.max).setZ(m.min.z).applyQuaternion(y),p.expandByPoint(S),S.copy(m.min).setZ(m.max.z).applyQuaternion(y),p.expandByPoint(S),S.copy(m.max).setY(m.min.y).applyQuaternion(y),p.expandByPoint(S),S.copy(m.max).setX(m.min.x).applyQuaternion(y),p.expandByPoint(S),S.copy(m.max).applyQuaternion(y),p.expandByPoint(S),p.min.x-=i,p.min.y-=n,p.max.x+=o,p.max.y+=a,y.setFromUnitVectors(ut,E),f&&y.premultiply(gt.invert()),y.premultiply(this._yAxisUpSpace);const _=p.getSize(w),r=p.getCenter(S).applyQuaternion(y);if(B(this._camera)){const d=this.getDistanceToFitBox(_.x,_.y,_.z,s);l.push(this.moveTo(r.x,r.y,r.z,e)),l.push(this.dollyTo(d,e)),l.push(this.setFocalOffset(0,0,0,e))}else if(k(this._camera)){const d=this._camera,O=d.right-d.left,g=d.top-d.bottom,x=s?Math.max(O/_.x,g/_.y):Math.min(O/_.x,g/_.y);l.push(this.moveTo(r.x,r.y,r.z,e)),l.push(this.zoomTo(x,e)),l.push(this.setFocalOffset(0,0,0,e))}return Promise.all(l)}fitToSphere(t,e){const s=[],o="isObject3D"in t?Z.createBoundingSphere(t,ft):ft.copy(t);if(s.push(this.moveTo(o.center.x,o.center.y,o.center.z,e)),B(this._camera)){const n=this.getDistanceToFitSphere(o.radius);s.push(this.dollyTo(n,e))}else if(k(this._camera)){const n=this._camera.right-this._camera.left,a=this._camera.top-this._camera.bottom,l=2*o.radius,m=Math.min(n/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,i,o,n,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=q.NONE,this._changedDolly=0;const l=S.set(i,o,n),m=w.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 C=!a||D(this._target.x,this._targetEnd.x,this.restThreshold)&&D(this._target.y,this._targetEnd.y,this.restThreshold)&&D(this._target.z,this._targetEnd.z,this.restThreshold)&&D(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&D(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&D(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(C)}lerpLookAt(t,e,s,i,o,n,a,l,m,C,c,E,y,f=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=q.NONE,this._changedDolly=0;const p=w.set(i,o,n),_=S.set(t,e,s);M.setFromVector3(_.sub(p).applyQuaternion(this._yAxisUpSpace));const r=G.set(C,c,E),d=S.set(a,l,m);et.setFromVector3(d.sub(r).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(p.lerp(r,y));const O=et.theta-M.theta,g=et.phi-M.phi,x=et.radius-M.radius;this._sphericalEnd.set(M.radius+x*y,M.phi+g*y,M.theta+O*y),this.normalizeRotations(),this._needsUpdate=!0,f||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const T=!f||D(this._target.x,this._targetEnd.x,this.restThreshold)&&D(this._target.y,this._targetEnd.y,this.restThreshold)&&D(this._target.z,this._targetEnd.z,this.restThreshold)&&D(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&D(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&D(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(T)}setPosition(t,e,s,i=!1){return this.setLookAt(t,e,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(t,e,s,i=!1){const o=this.getPosition(w),n=this.setLookAt(o.x,o.y,o.z,t,e,s,i);return this._sphericalEnd.phi=F(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),n}setFocalOffset(t,e,s,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,s),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const o=!i||D(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&D(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&D(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(o)}setOrbitPoint(t,e,s){this._camera.updateMatrixWorld(),H.setFromMatrixColumn(this._camera.matrixWorldInverse,0),I.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Y.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=w.set(t,e,s),o=i.distanceTo(this._camera.position),n=i.sub(this._camera.position);H.multiplyScalar(n.x),I.multiplyScalar(n.y),Y.multiplyScalar(n.z),w.copy(H).add(I).add(Y),w.z=w.z+o,this.dollyTo(o,!1),this.setFocalOffset(-w.x,w.y,-w.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,i){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new v.Vector4,typeof t=="number"?this._viewport.set(t,e,s,i):this._viewport.copy(t)}getDistanceToFitBox(t,e,s,i=!1){if(_t(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const o=t/e,n=this._camera.getEffectiveFOV()*Q,a=this._camera.aspect;return((i?o>a:o<a)?e:t/a)*.5/Math.tan(n*.5)+s*.5}getDistanceToFitSphere(t){if(_t(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*Q,s=Math.atan(Math.tan(e*.5)*this._camera.aspect)*2,i=1<this._camera.aspect?e:s;return t/Math.sin(i*.5)}getTarget(t,e=!0){return(t&&t.isVector3?t:new v.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new v.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new v.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new v.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%W,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=W),this._spherical.theta+=W*Math.round((this._sphericalEnd.theta-this._spherical.theta)/W)}reset(t=!1){if(!D(this._camera.up.x,this._cameraUp0.x)||!D(this._camera.up.y,this._cameraUp0.y)||!D(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(w);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,nt),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=w.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(w);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,i=this._sphericalEnd.radius-this._spherical.radius,o=Dt.subVectors(this._targetEnd,this._target),n=bt.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 c=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=ot(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,c,1/0,t),this._needsUpdate=!0}if(U(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const c=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=ot(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,c,1/0,t),this._needsUpdate=!0}if(U(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const c=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=ot(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,c,this.maxSpeed,t),this._needsUpdate=!0}if(U(o.x)&&U(o.y)&&U(o.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const c=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Pt(this._target,this._targetEnd,this._targetVelocity,c,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(U(n.x)&&U(n.y)&&U(n.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const c=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Pt(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,c,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(U(a))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const c=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=ot(this._zoom,this._zoomEnd,this._zoomVelocity,c,1/0,t)}if(this.dollyToCursor){if(B(this._camera)&&this._changedDolly!==0){const c=this._spherical.radius-this._lastDistance,E=this._camera,y=this._getCameraDirection(tt),f=w.copy(y).cross(E.up).normalize();f.lengthSq()===0&&(f.x=1);const p=S.crossVectors(f,y),_=this._sphericalEnd.radius*Math.tan(E.getEffectiveFOV()*Q*.5),d=(this._sphericalEnd.radius-c-this._sphericalEnd.radius)/this._sphericalEnd.radius,O=G.copy(this._targetEnd).add(f.multiplyScalar(this._dollyControlCoord.x*_*E.aspect)).add(p.multiplyScalar(this._dollyControlCoord.y*_)),g=w.copy(this._targetEnd).lerp(O,d),x=this._lastDollyDirection===q.IN&&this._spherical.radius<=this.minDistance,T=this._lastDollyDirection===q.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(x||T)){this._sphericalEnd.radius-=c,this._spherical.radius-=c;const R=S.copy(y).multiplyScalar(-c);g.add(R)}this._boundary.clampPoint(g,g);const b=S.subVectors(g,this._targetEnd);this._targetEnd.copy(g),this._target.add(b),this._changedDolly-=c,U(this._changedDolly)&&(this._changedDolly=0)}else if(k(this._camera)&&this._changedZoom!==0){const c=this._zoom-this._lastZoom,E=this._camera,y=w.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(E.near+E.far)/(E.near-E.far)).unproject(E),f=S.set(0,0,-1).applyQuaternion(E.quaternion),p=G.copy(y).add(f.multiplyScalar(-y.dot(E.up))),r=-(this._zoom-c-this._zoom)/this._zoom,d=this._getCameraDirection(tt),O=this._targetEnd.dot(d),g=w.copy(this._targetEnd).lerp(p,r),x=g.dot(d),T=d.multiplyScalar(x-O);g.sub(T),this._boundary.clampPoint(g,g);const b=S.subVectors(g,this._targetEnd);this._targetEnd.copy(g),this._target.add(b),this._changedZoom-=c,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(),H.setFromMatrixColumn(this._camera.matrix,0),I.setFromMatrixColumn(this._camera.matrix,1),Y.setFromMatrixColumn(this._camera.matrix,2),H.multiplyScalar(this._focalOffset.x),I.multiplyScalar(-this._focalOffset.y),Y.multiplyScalar(this._focalOffset.z),w.copy(H).add(I).add(Y),this._camera.position.add(w)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),w.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const C=this._needsUpdate;return C&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):C?(this.dispatchEvent({type:"update"}),U(e,this.restThreshold)&&U(s,this.restThreshold)&&U(i,this.restThreshold)&&U(o.x,this.restThreshold)&&U(o.y,this.restThreshold)&&U(o.z,this.restThreshold)&&U(n.x,this.restThreshold)&&U(n.y,this.restThreshold)&&U(n.z,this.restThreshold)&&U(a,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!C&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=C,this._needsUpdate=!1,C}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:$(this.maxDistance),minZoom:this.minZoom,maxZoom:$(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:$(this.maxPolarAngle),minAzimuthAngle:$(this.minAzimuthAngle),maxAzimuthAngle:$(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:w.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=J(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=J(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=J(s.maxPolarAngle),this.minAzimuthAngle=J(s.minAzimuthAngle),this.maxAzimuthAngle=J(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),M.setFromVector3(w.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(M.theta,M.phi,e),this.dollyTo(M.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 i=e.lengthSq();if(i===0)return t;const o=S.copy(e).add(t),a=this._boundary.clampPoint(o,G).sub(o),l=a.lengthSq();if(l===0)return t.add(e);if(l===i)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(B(this._camera)){const t=this._camera,e=t.near,s=t.getEffectiveFOV()*Q,i=Math.tan(s*.5)*e,o=i*t.aspect;this._nearPlaneCorners[0].set(-o,-i,0),this._nearPlaneCorners[1].set(o,-i,0),this._nearPlaneCorners[2].set(o,i,0),this._nearPlaneCorners[3].set(-o,i,0)}else if(k(this._camera)){const t=this._camera,e=1/t.zoom,s=t.left*e,i=t.right*e,o=t.top*e,n=t.bottom*e;this._nearPlaneCorners[0].set(s,o,0),this._nearPlaneCorners[1].set(i,o,0),this._nearPlaneCorners[2].set(i,n,0),this._nearPlaneCorners[3].set(s,n,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||_t(this._camera,"_collisionTest"))return t;const s=this._getTargetDirection(tt);yt.lookAt(St,s,this._camera.up);for(let i=0;i<4;i++){const o=S.copy(this._nearPlaneCorners[i]);o.applyMatrix4(yt);const n=G.addVectors(this._target,o);at.set(n,s),at.far=this._spherical.radius+1;const a=at.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 v.Sphere){const s=e,i=s.center;X.makeEmpty(),t.traverseVisible(n=>{n.isMesh&&X.expandByObject(n)}),X.getCenter(i);let o=0;return t.traverseVisible(n=>{if(!n.isMesh)return;const a=n,l=a.geometry.clone();l.applyMatrix4(a.matrixWorld);const C=l.attributes.position;for(let c=0,E=C.count;c<E;c++)w.fromBufferAttribute(C,c),o=Math.max(o,i.distanceToSquared(w))}),s.radius=Math.sqrt(o),s}}const fe={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:ee.ColorSpace.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1,physicallyCorrectLights:!1};class ge{constructor(t){this.options=t;const{width:e,height:s,rendererParams:i}=t,{canvas:o,context:n,alpha:a,devicePixelRatio:l,antialias:m,powerPreference:C,toneMappingExposure:c,outputColorSpace:E,logarithmicDepthBuffer:y,preserveDrawingBuffer:f,stencil:p,depth:_,physicallyCorrectLights:r}=i,d=new P.WebGLRenderer({canvas:o,context:n,alpha:a,antialias:m,powerPreference:C,logarithmicDepthBuffer:y,preserveDrawingBuffer:f,stencil:p,depth:_});d.setSize(e,s),d.setPixelRatio(l),d.toneMappingExposure=c,d.outputColorSpace=E,+P.REVISION<155&&(d.useLegacyLights=r),this.renderer=d}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 ye={antialias:!0,devicePixelRatio:window.devicePixelRatio};class Ce{constructor(t){this.options=t;const{width:e,height:s,rendererParams:i,renderer:o}=t,{devicePixelRatio:n,antialias:a}=i,l=new o({antialias:a});l.setSize(e,s),l.setPixelRatio(n),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 ht{constructor(t){this.guiParams={},t&&(this.guiParams=t)}showGui(t){t&&Object.keys(this.guiParams).forEach(e=>{const s=t.addFolder(e),i=this.guiParams[e];Object.keys(i).forEach(o=>{const{min:n,max:a,step:l,name:m,paramMap:C,items:c,value:E,target:y}=i[o],f=o.toLowerCase().indexOf("color")>-1;let p;const _=typeof E=="undefined"&&y,r=_?y():i[o],d=_?o:"value";c?p=s.add(r,d,c):f?p=s.addColor(r,d):p=s.add(r,d),p=p.name(m||o),typeof n!="undefined"&&(p=p.min(n)),typeof a!="undefined"&&(p=p.max(a)),typeof l!="undefined"&&(p=p.step(l)),p=p.onChange(()=>{this.setTargetValue(e,o,r[d],C)}),_&&p.listen()})})}setTargetValue(t,e,s,i){const{onChange:o,target:n,value:a}=this.guiParams[t][e],l=e.toLowerCase().indexOf("color")>-1;if(n&&!(typeof a=="undefined"&&n)){let C=n();Array.isArray(C)||(C=[C]),C.forEach(c=>{if(c)if(l)try{c[i||e].set(s)}catch(E){e!=="color"&&!i&&console.warn(`${e} is not a color,set paramMap`)}else c[i||e]=s})}o&&o(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 Oe={fov:45,near:1,far:1e3,up:new P.Vector3(0,1,0)};class Ee{constructor(t){this.customCamera=!1,this.options=t;const{width:e,height:s,cameraParams:i}=t;if(i instanceof P.Camera)this.camera=i,this.customCamera=!0;else{const{fov:o,far:n,near:a,up:l}=i,m=new P.PerspectiveCamera(o,e/s,a,n);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 P.PerspectiveCamera&&(this.camera.aspect=t/e),this.camera.updateProjectionMatrix(),this.camera2&&(this.camera2.aspect=t/e,this.camera2.updateProjectionMatrix())}addCamera2(){const t=new P.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(t){if(t.type==="PerspectiveCamera"){const e=t;(!this.camera.matrixWorld.equals(e.matrixWorld)||this.camera.far!==e.far||this.camera.near!==e.near||this.camera.fov!==e.fov||this.camera.aspect!==e.aspect)&&this.camera.copy(e)}else{const e=t,s=e.viewMatrix,i=e.inverseViewMatrix,o=new P.Matrix4(i[0],i[4],i[8],i[12],i[1],i[5],i[9],i[13],i[2],i[6],i[10],i[14],i[3],i[7],i[11],i[15]),n=new P.Matrix4(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]),{width:a,height:l}=this.options,m=a/l;(this.camera.fov!==e.fov||this.camera.aspect!==m||!this.camera.matrixWorld.equals(o)||!this.camera.matrixWorldInverse.equals(n))&&(this.camera.fov=e.fov,this.camera.updateProjectionMatrix(),this.camera.matrixAutoUpdate=!1,this.camera.matrixWorld.copy(o),this.camera.matrixWorldInverse.copy(n),this.camera.aspect=m,this.camera.updateProjectionMatrix())}}setGui(t){const e=new ht({camera:mt(N({},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 P.PerspectiveCamera&&(e.guiParams.camera.fov={min:0,max:90,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}),e.showGui(t)}}const Te={background:null,addCamera:!0};class ve{constructor(t){this.overrideMaterial=!1,this.options=t;const{camera:e,sceneParams:s}=t,{background:i,addCamera:o}=s,n=new P.Scene;i&&(n.background=i),o&&n.add(e),this.scene=n}dispose(){var t;(t=this.scene)==null||t.traverse(e=>{se.disposeMesh(e)})}}class xe{constructor(t){this.helpers={},this.options=t}add(t){const e=t.uuid,{scene:s}=this.options;let i=this.helpers[e];if(i===void 0){if(t.isScene)i=new P.AxesHelper(100);else if(t.isCamera)i=new P.CameraHelper(t);else if(t.isPointLight)i=new P.PointLightHelper(t,1);else if(t.isDirectionalLight)i=new P.DirectionalLightHelper(t,1);else if(t.isSpotLight)i=new P.SpotLightHelper(t);else if(t.isHemisphereLight)i=new P.HemisphereLightHelper(t,10);else if(t.isRectAreaLight)i=new ie.RectAreaLightHelper(t);else{const o=new P.Box3;if(o.setFromObject(t,!0),o.isEmpty()===!1){i=new P.Box3Helper(o);const n=i.material;n.userData.object=t,n.depthTest=!1,n.transparent=!0}else return}s.add(i),this.helpers[e]=i}}addViewHelper(){const{camera:t,container:e}=this.options,s=new oe.ViewHelper(t,e);e.addEventListener("pointerdown",i=>{i.preventDefault(),s.handleClick(i)}),this.viewHelper=s}remove(t){var i;const e=t.uuid,{scene:s}=this.options;if(this.helpers[e]!==void 0){const o=this.helpers[e];s.remove(o),delete this.helpers[e],(i=o.dispose)==null||i.call(o)}}removeAll(){Object.keys(this.helpers).forEach(t=>{this.remove({uuid:t})}),this.helpers={}}removeAllExcludeScene(){Object.keys(this.helpers).forEach(t=>{this.helpers[t]instanceof P.AxesHelper||this.remove({uuid:t})})}update(t,e,s){var o,n;const{camera:i}=this.options;Object.values(this.helpers).forEach(a=>{if(a.update&&a.update(),a instanceof P.Box3Helper){const l=a.material,{object:m}=l.userData;m&&a.box.setFromObject(m,!0)}}),((o=this.viewHelper)==null?void 0:o.animating)===!0&&(this.viewHelper.update(t),(n=e.cameraControls)==null||n.setPosition(...i.position.toArray()),this.viewHelper.center.copy(s))}renderViewHelper(t){if(!this.viewHelper)return;const e=t.autoClear;t.autoClear=!1,this.viewHelper.render(t),t.autoClear=e}dispose(){var t;this.helpers={},(t=this.viewHelper)==null||t.dispose()}}class we{constructor(t){this.autoRotateSpeed=0,this.options=t;const{camera:e,controlsParams:s,customControls:i}=t,{domElement:o}=s;if(i){const n=new i(e,o);n.enableDamping=!0,n.dampingFactor=.063,n.autoRotate=!1,n.autoRotateSpeed=-60,n.enableZoom=!0,n.zoomSpeed=.2,this.customControls=n}else Z.install({THREE:P}),this.cameraControls=new Z(e,o)}addCameraControls2(t){const{controlsParams:e}=this.options,{domElement:s}=e;this.cameraControls2=new Z(t,s),this.cameraControls2.addEventListener("update",()=>{this.cameraControls.enabled=!1}),this.cameraControls2.addEventListener("sleep",()=>{this.cameraControls.enabled=!0})}enable(){this.customControls?this.customControls.enabled=!0:this.cameraControls&&(this.cameraControls.enabled=!0,this.cameraControls2&&(this.cameraControls2.enabled=!0))}disable(){this.customControls?this.customControls.enabled=!1:this.cameraControls&&(this.cameraControls.enabled=!1,this.cameraControls2&&(this.cameraControls2.enabled=!1))}update(t){var e,s,i;(e=this.customControls)==null||e.update(),(s=this.cameraControls)==null||s.update(t),(i=this.cameraControls2)==null||i.update(t),this.autoRotateSpeed&&this.cameraControls&&(this.cameraControls.azimuthAngle+=this.autoRotateSpeed*t*P.MathUtils.DEG2RAD)}dispose(){var t,e,s;(t=this.customControls)==null||t.dispose(),(e=this.cameraControls)==null||e.dispose(),(s=this.cameraControls2)==null||s.dispose()}}class Pe{constructor(t){this.event=new Vt.eventsExports.EventEmitter;const{renderer:e,scene:s,camera:i}=t,o=new re.TransformControls(i,e.domElement);if(o.getHelper){const n=o.getHelper();if(s.add(n),+P.REVISION<170){const a=o._root;a.dispose=()=>{a.traverse(l=>{l.geometry&&l.geometry.dispose(),l.material&&l.material.dispose()})},o.dispose=()=>{o.disconnect(),a.dispose()}}}else o instanceof P.Object3D&&s.add(o);this.controls=o,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 i=this.controls;i.addEventListener("change",()=>{const o=i.object;o!==void 0&&this.event.emit("change",o)}),i.addEventListener("mouseDown",()=>{const o=i.object;t=o.position.clone(),e=o.rotation.clone(),s=o.scale.clone(),this.event.emit("mouseDown",o)}),i.addEventListener("mouseUp",()=>{const o=i.object;if(o!==void 0)switch(i.getMode()){case"translate":t.equals(o.position)||this.event.emit("translate",o,o.position,t);break;case"rotate":e.equals(o.rotation)||this.event.emit("rotate",o,o.rotation,e);break;case"scale":s.equals(o.scale)||this.event.emit("scale",o,o.scale,s);break}this.event.emit("mouseUp")})}dispose(){var t;this.event.removeAllListeners(),(t=this.controls)==null||t.dispose()}}const Rt=new z.Vector3,Se=new z.Quaternion,Lt=new z.Vector3,V=new z.Matrix4,De=new z.Matrix4;class be{constructor(t={}){const e=this;let s,i,o,n;const a={camera:{style:""},objects:new WeakMap},l=t.element!==void 0?t.element:document.createElement("div");l.style.overflow="hidden",this.domElement=l;const m=document.createElement("div");m.style.transformOrigin="0 0",m.style.pointerEvents="none",l.appendChild(m);const C=document.createElement("div");C.style.transformStyle="preserve-3d",m.appendChild(C),this.getSize=function(){return{width:s,height:i}},this.render=function(_,r){const d=r.projectionMatrix.elements[5]*n;r.view&&r.view.enabled?(m.style.transform=`translate( ${-r.view.offsetX*(s/r.view.width)}px, ${-r.view.offsetY*(i/r.view.height)}px )`,m.style.transform+=`scale( ${r.view.fullWidth/r.view.width}, ${r.view.fullHeight/r.view.height} )`):m.style.transform="",_.matrixWorldAutoUpdate===!0&&_.updateMatrixWorld(),r.parent===null&&r.matrixWorldAutoUpdate===!0&&r.updateMatrixWorld();let O,g;r.isOrthographicCamera&&(O=-(r.right+r.left)/2,g=(r.top+r.bottom)/2);const x=r.view&&r.view.enabled?r.view.height/r.view.fullHeight:1,T=r.isOrthographicCamera?`scale( ${x} )scale(`+d+")translate("+c(O)+"px,"+c(g)+"px)"+E(r.matrixWorldInverse):`scale( ${x} )translateZ(`+d+"px)"+E(r.matrixWorldInverse),R=(r.isPerspectiveCamera?"perspective("+d+"px) ":"")+T+"translate("+o+"px,"+n+"px)";a.camera.style!==R&&(C.style.transform=R,a.camera.style=R),p(_,_,r)},this.setSize=function(_,r){s=_,i=r,o=s/2,n=i/2,l.style.width=_+"px",l.style.height=r+"px",m.style.width=_+"px",m.style.height=r+"px",C.style.width=_+"px",C.style.height=r+"px"};function c(_){return Math.abs(_)<1e-10?0:_}function E(_){const r=_.elements;return"matrix3d("+c(r[0])+","+c(-r[1])+","+c(r[2])+","+c(r[3])+","+c(r[4])+","+c(-r[5])+","+c(r[6])+","+c(r[7])+","+c(r[8])+","+c(-r[9])+","+c(r[10])+","+c(r[11])+","+c(r[12])+","+c(-r[13])+","+c(r[14])+","+c(r[15])+")"}function y(_){const r=_.elements;return"translate(-50%,-50%)"+("matrix3d("+c(r[0])+","+c(r[1])+","+c(r[2])+","+c(r[3])+","+c(-r[4])+","+c(-r[5])+","+c(-r[6])+","+c(-r[7])+","+c(r[8])+","+c(r[9])+","+c(r[10])+","+c(r[11])+","+c(r[12])+","+c(r[13])+","+c(r[14])+","+c(r[15])+")")}function f(_){_.isCSS3DObject&&(_.element.style.display="none");for(let r=0,d=_.children.length;r<d;r++)f(_.children[r])}function p(_,r,d,O){if(_.visible===!1){f(_);return}if(_.isCSS3DObject){const g=_.layers.test(d.layers)===!0,x=_.element;if(x.style.display=g===!0?"":"none",g===!0){_.onBeforeRender(e,r,d);let T;_.isCSS3DSprite?(V.copy(d.matrixWorldInverse),V.transpose(),_.rotation2D!==0&&V.multiply(De.makeRotationZ(_.rotation2D)),_.matrixWorld.decompose(Rt,Se,Lt),V.setPosition(Rt),V.scale(Lt),V.elements[3]=0,V.elements[7]=0,V.elements[11]=0,V.elements[15]=1,T=y(V)):T=y(_.matrixWorld);const b=a.objects.get(_);if(b===void 0||b.style!==T){x.style.transform=T;const R={style:T};a.objects.set(_,R)}x.parentNode!==C&&C.appendChild(x),_.onAfterRender(e,r,d)}}for(let g=0,x=_.children.length;g<x;g++)p(_.children[g],r,d)}}}const K=new z.Vector3,zt=new z.Matrix4,Mt=new z.Matrix4,Ft=new z.Vector3,Ht=new z.Vector3;class Ue{constructor(t={}){const e=this;let s,i,o,n;const a={objects:new WeakMap},l=t.element!==void 0?t.element:document.createElement("div");l.style.overflow="hidden",this.domElement=l,this.getSize=function(){return{width:s,height:i}},this.render=function(f,p){f.matrixWorldAutoUpdate===!0&&f.updateMatrixWorld(),p.parent===null&&p.matrixWorldAutoUpdate===!0&&p.updateMatrixWorld(),zt.copy(p.matrixWorldInverse),Mt.multiplyMatrices(p.projectionMatrix,zt),C(f,f,p),y(f)},this.setSize=function(f,p){s=f,i=p,o=s/2,n=i/2,l.style.width=f+"px",l.style.height=p+"px"};function m(f){f.isCSS2DObject&&(f.element.style.display="none");for(let p=0,_=f.children.length;p<_;p++)m(f.children[p])}function C(f,p,_){if(f.visible===!1){m(f);return}if(f.isCSS2DObject){K.setFromMatrixPosition(f.matrixWorld),K.applyMatrix4(Mt);const r=K.z>=-1&&K.z<=1&&f.layers.test(_.layers)===!0,d=f.element;d.style.display=r===!0?"":"none",r===!0&&(f.onBeforeRender(e,p,_),d.style.transform="translate("+-100*f.center.x+"%,"+-100*f.center.y+"%)translate("+(K.x*o+o)+"px,"+(-K.y*n+n)+"px)",d.parentNode!==l&&l.appendChild(d),f.onAfterRender(e,p,_));const O={distanceToCameraSquared:c(_,f)};a.objects.set(f,O)}for(let r=0,d=f.children.length;r<d;r++)C(f.children[r],p,_)}function c(f,p){return Ft.setFromMatrixPosition(f.matrixWorld),Ht.setFromMatrixPosition(p.matrixWorld),Ft.distanceToSquared(Ht)}function E(f){const p=[];return f.traverseVisible(function(_){_.isCSS2DObject&&p.push(_)}),p}function y(f){const p=E(f).sort(function(r,d){if(r.renderOrder!==d.renderOrder)return d.renderOrder-r.renderOrder;const O=a.objects.get(r).distanceToCameraSquared,g=a.objects.get(d).distanceToCameraSquared;return O-g}),_=p.length;for(let r=0,d=p.length;r<d;r++)p[r].element.style.zIndex=_-r}}}const It={zIndex:"auto"};class Ae{constructor(t){this.container=t}addRenderer(t,e){const s=e.container||this.container,i=s.getBoundingClientRect(),{width:o,height:n}=i,a=t==="css2d"?new Ue:new be;a.domElement.style.position="absolute",a.domElement.style.top="0",a.domElement.style.pointerEvents="none",a.domElement.style.zIndex=e.zIndex,a.setSize(o,n),s.appendChild(a.domElement),t==="css2d"?this.css2Drenderer=a:t==="css3d"&&(this.css3Drenderer=a)}setSize(t,e){var s,i;(s=this.css2Drenderer)==null||s.setSize(t,e),(i=this.css3Drenderer)==null||i.setSize(t,e)}render(t,e){var s,i;(s=this.css2Drenderer)==null||s.render(t,e),(i=this.css3Drenderer)==null||i.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 Re={name:"OutputShader",uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1},premultiplieAlpha:{value:0}},vertexShader:`
1
+ "use strict";var Wt=Object.defineProperty,Gt=Object.defineProperties;var Xt=Object.getOwnPropertyDescriptors;var Ot=Object.getOwnPropertySymbols;var Kt=Object.prototype.hasOwnProperty,jt=Object.prototype.propertyIsEnumerable;var Et=(u,t,e)=>t in u?Wt(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,N=(u,t)=>{for(var e in t||(t={}))Kt.call(t,e)&&Et(u,e,t[e]);if(Ot)for(var e of Ot(t))jt.call(t,e)&&Et(u,e,t[e]);return u},mt=(u,t)=>Gt(u,Xt(t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const z=require("three"),Qt=require("@tweenjs/tween.js"),Vt=require("./events.js"),$t=require("deepmerge"),Jt=require("stats-gl"),te=require("lil-gui"),ee=require("./colorCorrection.js"),se=require("./disposeMesh.js");require("idb-keyval");require("esus-lite");require("d3-geo");require("d3-geo-projection");const ie=require("three/examples/jsm/helpers/RectAreaLightHelper"),oe=require("three/examples/jsm/helpers/ViewHelper"),re=require("three/examples/jsm/controls/TransformControls"),Tt=require("three/examples/jsm/postprocessing/EffectComposer"),ne=require("three/examples/jsm/postprocessing/RenderPass"),ae=require("three/examples/jsm/postprocessing/SSAOPass"),he=require("three/examples/jsm/postprocessing/Pass"),le=require("three/examples/jsm/postprocessing/OutputPass"),ce=require("three/examples/jsm/postprocessing/ShaderPass"),de=require("three/examples/jsm/postprocessing/UnrealBloomPass"),me=require("./isPlainObject.js"),pe=require("./BaseObject.js");function kt(u){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const e in u)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(u,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>u[e]})}}return t.default=u,Object.freeze(t)}const P=kt(z),vt=kt(Qt),A={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}),q={NONE:0,IN:1,OUT:-1};function B(u){return u.isPerspectiveCamera}function k(u){return u.isOrthographicCamera}const W=Math.PI*2,xt=Math.PI/2,Nt=1e-5,Q=Math.PI/180;function F(u,t,e){return Math.max(t,Math.min(e,u))}function U(u,t=Nt){return Math.abs(u)<t}function D(u,t,e=Nt){return U(u-t,e)}function wt(u,t){return Math.round(u/t)*t}function $(u){return isFinite(u)?u:u<0?-Number.MAX_VALUE:Number.MAX_VALUE}function J(u){return Math.abs(u)<Number.MAX_VALUE?u:u*(1/0)}function ot(u,t,e,s,i=1/0,o){s=Math.max(1e-4,s);const n=2/s,a=n*o,l=1/(1+a+.48*a*a+.235*a*a*a);let m=u-t;const C=t,c=i*s;m=F(m,-c,c),t=u-m;const E=(e.value+n*m)*o;e.value=(e.value-n*E)*l;let y=t+(m+E)*l;return C-u>0==y>C&&(y=C,e.value=(y-C)/o),y}function Pt(u,t,e,s,i=1/0,o,n){s=Math.max(1e-4,s);const a=2/s,l=a*o,m=1/(1+l+.48*l*l+.235*l*l*l);let C=t.x,c=t.y,E=t.z,y=u.x-C,f=u.y-c,p=u.z-E;const _=C,r=c,d=E,O=i*s,g=O*O,x=y*y+f*f+p*p;if(x>g){const dt=Math.sqrt(x);y=y/dt*O,f=f/dt*O,p=p/dt*O}C=u.x-y,c=u.y-f,E=u.z-p;const T=(e.x+a*y)*o,b=(e.y+a*f)*o,R=(e.z+a*p)*o;e.x=(e.x-a*T)*m,e.y=(e.y-a*b)*m,e.z=(e.z-a*R)*m,n.x=C+(y+T)*m,n.y=c+(f+b)*m,n.z=E+(p+R)*m;const st=_-u.x,it=r-u.y,Bt=d-u.z,Yt=n.x-_,Zt=n.y-r,qt=n.z-d;return st*Yt+it*Zt+Bt*qt>0&&(n.x=_,n.y=r,n.z=d,e.x=(n.x-_)/o,e.y=(n.y-r)/o,e.z=(n.z-d)/o),n}function pt(u,t){t.set(0,0),u.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=u.length,t.y/=u.length}function _t(u,t){return k(u)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}class _e{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 i=this._listeners[t];if(i!==void 0){const o=i.indexOf(e);o!==-1&&i.splice(o,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 i=s.slice(0);for(let o=0,n=i.length;o<n;o++)i[o].call(this,t)}}}const rt=1/8,ue=/Mac/.test(navigator.platform);let v,St,nt,ut,L,w,S,G,tt,H,I,Y,Dt,bt,M,et,X,Ut,ft,At,gt,yt,at;class Z extends _e{static install(t){v=t.THREE,St=Object.freeze(new v.Vector3(0,0,0)),nt=Object.freeze(new v.Vector3(0,1,0)),ut=Object.freeze(new v.Vector3(0,0,1)),L=new v.Vector2,w=new v.Vector3,S=new v.Vector3,G=new v.Vector3,tt=new v.Vector3,H=new v.Vector3,I=new v.Vector3,Y=new v.Vector3,Dt=new v.Vector3,bt=new v.Vector3,M=new v.Spherical,et=new v.Spherical,X=new v.Box3,Ut=new v.Box3,ft=new v.Sphere,At=new v.Quaternion,gt=new v.Quaternion,yt=new v.Matrix4,at=new v.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=q.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new v.Vector3,this._focalOffsetVelocity=new v.Vector3,this._zoomVelocity={value:0},this._truckInternal=(r,d,O)=>{let g,x;if(B(this._camera)){const T=w.copy(this._camera.position).sub(this._target),b=this._camera.getEffectiveFOV()*Q,R=T.length()*Math.tan(b*.5);g=this.truckSpeed*r*R/this._elementRect.height,x=this.truckSpeed*d*R/this._elementRect.height}else if(k(this._camera)){const T=this._camera;g=r*(T.right-T.left)/T.zoom/this._elementRect.width,x=d*(T.top-T.bottom)/T.zoom/this._elementRect.height}else return;this.verticalDragToForward?(O?this.setFocalOffset(this._focalOffsetEnd.x+g,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(g,0,!0),this.forward(-x,!0)):O?this.setFocalOffset(this._focalOffsetEnd.x+g,this._focalOffsetEnd.y+x,this._focalOffsetEnd.z,!0):this.truck(g,x,!0)},this._rotateInternal=(r,d)=>{const O=W*this.azimuthRotateSpeed*r/this._elementRect.height,g=W*this.polarRotateSpeed*d/this._elementRect.height;this.rotate(O,g,!0)},this._dollyInternal=(r,d,O)=>{const g=Math.pow(.95,-r*this.dollySpeed),x=this._sphericalEnd.radius,T=this._sphericalEnd.radius*g,b=F(T,this.minDistance,this.maxDistance),R=b-T;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(T,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(R,!0),this._dollyToNoClamp(b,!0)):this._dollyToNoClamp(b,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?T:b)-x,this._dollyControlCoord.set(d,O)),this._lastDollyDirection=Math.sign(-r)},this._zoomInternal=(r,d,O)=>{const g=Math.pow(.95,r*this.dollySpeed),x=this._zoom,T=this._zoom*g;this.zoomTo(T,!0),this.dollyToCursor&&(this._changedZoom+=T-x,this._dollyControlCoord.set(d,O))},typeof v=="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 v.Quaternion().setFromUnitVectors(this._camera.up,nt),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=h.NONE,this._target=new v.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new v.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new v.Spherical().setFromVector3(w.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 v.Vector3,new v.Vector3,new v.Vector3,new v.Vector3],this._updateNearPlaneCorners(),this._boundary=new v.Box3(new v.Vector3(-1/0,-1/0,-1/0),new v.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 v.Vector2,this.mouseButtons={left:h.ROTATE,middle:h.DOLLY,right:h.TRUCK,wheel:B(this._camera)?h.DOLLY:k(this._camera)?h.ZOOM:h.NONE},this.touches={one:h.TOUCH_ROTATE,two:B(this._camera)?h.TOUCH_DOLLY_TRUCK:k(this._camera)?h.TOUCH_ZOOM_TRUCK:h.NONE,three:h.TOUCH_TRUCK};const s=new v.Vector2,i=new v.Vector2,o=new v.Vector2,n=r=>{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(),x=(r.clientX-g.left)/(g.right-g.left),T=(r.clientY-g.top)/(g.bottom-g.top);if(x<this._interactiveArea.left||x>this._interactiveArea.right||T<this._interactiveArea.top||T>this._interactiveArea.bottom)return}const d=r.pointerType!=="mouse"?null:(r.buttons&A.LEFT)===A.LEFT?A.LEFT:(r.buttons&A.MIDDLE)===A.MIDDLE?A.MIDDLE:(r.buttons&A.RIGHT)===A.RIGHT?A.RIGHT:null;if(d!==null){const g=this._findPointerByMouseButton(d);g&&this._disposePointer(g)}if((r.buttons&A.LEFT)===A.LEFT&&this._lockedPointer)return;const O={pointerId:r.pointerId,clientX:r.clientX,clientY:r.clientY,deltaX:0,deltaY:0,mouseButton:d};this._activePointers.push(O),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,E(r)},a=r=>{r.cancelable&&r.preventDefault();const d=r.pointerId,O=this._lockedPointer||this._findPointerById(d);if(O){if(O.clientX=r.clientX,O.clientY=r.clientY,O.deltaX=r.movementX,O.deltaY=r.movementY,this._state=0,r.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&&(r.buttons&A.LEFT)===A.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(r.buttons&A.MIDDLE)===A.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(r.buttons&A.RIGHT)===A.RIGHT&&(this._state=this._state|this.mouseButtons.right);y()}},l=r=>{const d=this._findPointerById(r.pointerId);if(!(d&&d===this._lockedPointer)){if(d&&this._disposePointer(d),r.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;f()}};let m=-1;const C=r=>{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(),b=(r.clientX-T.left)/(T.right-T.left),R=(r.clientY-T.top)/(T.bottom-T.top);if(b<this._interactiveArea.left||b>this._interactiveArea.right||R<this._interactiveArea.top||R>this._interactiveArea.bottom)return}if(r.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 d=ue?-1:-3,O=r.deltaMode===1?r.deltaY/d:r.deltaY/(d*10),g=this.dollyToCursor?(r.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,x=this.dollyToCursor?(r.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case h.ROTATE:{this._rotateInternal(r.deltaX,r.deltaY),this._isUserControllingRotate=!0;break}case h.TRUCK:{this._truckInternal(r.deltaX,r.deltaY,!1),this._isUserControllingTruck=!0;break}case h.OFFSET:{this._truckInternal(r.deltaX,r.deltaY,!0),this._isUserControllingOffset=!0;break}case h.DOLLY:{this._dollyInternal(-O,g,x),this._isUserControllingDolly=!0;break}case h.ZOOM:{this._zoomInternal(-O,g,x),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},c=r=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===Z.ACTION.NONE){const d=r instanceof PointerEvent?r.pointerId:0,O=this._findPointerById(d);O&&this._disposePointer(O),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l);return}r.preventDefault()}},E=r=>{if(!this._enabled)return;if(pt(this._activePointers,L),this._getClientRect(this._elementRect),s.copy(L),i.copy(L),this._activePointers.length>=2){const O=L.x-this._activePointers[1].clientX,g=L.y-this._activePointers[1].clientY,x=Math.sqrt(O*O+g*g);o.set(0,x);const T=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,b=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;i.set(T,b)}if(this._state=0,!r)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in r&&r.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&&(r.buttons&A.LEFT)===A.LEFT&&(this._state=this._state|this.mouseButtons.left),(r.buttons&A.MIDDLE)===A.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(r.buttons&A.RIGHT)===A.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,pt(this._activePointers,L);const d=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,O=d?-d.deltaX:i.x-L.x,g=d?-d.deltaY:i.y-L.y;if(i.copy(L),((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(O,g),this._isUserControllingRotate=!0),(this._state&h.DOLLY)===h.DOLLY||(this._state&h.ZOOM)===h.ZOOM){const x=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,b=this.dollyDragInverted?-1:1;(this._state&h.DOLLY)===h.DOLLY?(this._dollyInternal(b*g*rt,x,T),this._isUserControllingDolly=!0):(this._zoomInternal(b*g*rt,x,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 x=L.x-this._activePointers[1].clientX,T=L.y-this._activePointers[1].clientY,b=Math.sqrt(x*x+T*T),R=o.y-b;o.set(0,b);const st=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,it=this.dollyToCursor?(i.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(R*rt,st,it),this._isUserControllingDolly=!0):(this._zoomInternal(R*rt,st,it),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(O,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(O,g,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},f=()=>{pt(this._activePointers,L),i.copy(L),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",p),this._domElement.ownerDocument.addEventListener("pointerlockerror",_),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),E())},this.unlockPointer=()=>{var r,d,O;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(r=this._domElement)===null||r===void 0||r.ownerDocument.exitPointerLock(),(d=this._domElement)===null||d===void 0||d.ownerDocument.removeEventListener("pointerlockchange",p),(O=this._domElement)===null||O===void 0||O.ownerDocument.removeEventListener("pointerlockerror",_),this.cancel()};const p=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},_=()=>{this.unlockPointer()};this._addAllEventListeners=r=>{this._domElement=r,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",n),this._domElement.addEventListener("pointercancel",l),this._domElement.addEventListener("wheel",C,{passive:!1}),this._domElement.addEventListener("contextmenu",c)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",n),this._domElement.removeEventListener("pointercancel",l),this._domElement.removeEventListener("wheel",C,{passive:!1}),this._domElement.removeEventListener("contextmenu",c),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.removeEventListener("pointerlockchange",p),this._domElement.ownerDocument.removeEventListener("pointerlockerror",_))},this.cancel=()=>{this._state!==h.NONE&&(this._state=h.NONE,this._activePointers.length=0,f())},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=F(t.width,0,1),this._interactiveArea.height=F(t.height,0,1),this._interactiveArea.x=F(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=F(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 i=F(t,this.minAzimuthAngle,this.maxAzimuthAngle),o=F(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=o,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const n=!s||D(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&D(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(n)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=q.NONE,this._changedDolly=0,this._dollyToNoClamp(F(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const n=this._collisionTest(),a=D(n,this._spherical.radius);if(!(s>t)&&a)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,n)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const o=!e||D(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(o)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(tt).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const s=!e||D(this._target.x,this._targetEnd.x,this.restThreshold)&&D(this._target.y,this._targetEnd.y,this.restThreshold)&&D(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=F(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const s=!e||D(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(),H.setFromMatrixColumn(this._camera.matrix,0),I.setFromMatrixColumn(this._camera.matrix,1),H.multiplyScalar(t),I.multiplyScalar(-e);const i=w.copy(H).add(I),o=S.copy(this._targetEnd).add(i);return this.moveTo(o.x,o.y,o.z,s)}forward(t,e=!1){w.setFromMatrixColumn(this._camera.matrix,0),w.crossVectors(this._camera.up,w),w.multiplyScalar(t);const s=S.copy(this._targetEnd).add(w);return this.moveTo(s.x,s.y,s.z,e)}elevate(t,e=!1){return w.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+w.x,this._targetEnd.y+w.y,this._targetEnd.z+w.z,e)}moveTo(t,e,s,i=!1){this._isUserControllingTruck=!1;const o=w.set(t,e,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,o,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const n=!i||D(this._target.x,this._targetEnd.x,this.restThreshold)&&D(this._target.y,this._targetEnd.y,this.restThreshold)&&D(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}lookInDirectionOf(t,e,s,i=!1){const a=w.set(t,e,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(a.x,a.y,a.z,i)}fitToBox(t,e,{cover:s=!1,paddingLeft:i=0,paddingRight:o=0,paddingBottom:n=0,paddingTop:a=0}={}){const l=[],m=t.isBox3?X.copy(t):X.setFromObject(t);m.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const C=wt(this._sphericalEnd.theta,xt),c=wt(this._sphericalEnd.phi,xt);l.push(this.rotateTo(C,c,e));const E=w.setFromSpherical(this._sphericalEnd).normalize(),y=At.setFromUnitVectors(E,ut),f=D(Math.abs(E.y),1);f&&y.multiply(gt.setFromAxisAngle(nt,C)),y.multiply(this._yAxisUpSpaceInverse);const p=Ut.makeEmpty();S.copy(m.min).applyQuaternion(y),p.expandByPoint(S),S.copy(m.min).setX(m.max.x).applyQuaternion(y),p.expandByPoint(S),S.copy(m.min).setY(m.max.y).applyQuaternion(y),p.expandByPoint(S),S.copy(m.max).setZ(m.min.z).applyQuaternion(y),p.expandByPoint(S),S.copy(m.min).setZ(m.max.z).applyQuaternion(y),p.expandByPoint(S),S.copy(m.max).setY(m.min.y).applyQuaternion(y),p.expandByPoint(S),S.copy(m.max).setX(m.min.x).applyQuaternion(y),p.expandByPoint(S),S.copy(m.max).applyQuaternion(y),p.expandByPoint(S),p.min.x-=i,p.min.y-=n,p.max.x+=o,p.max.y+=a,y.setFromUnitVectors(ut,E),f&&y.premultiply(gt.invert()),y.premultiply(this._yAxisUpSpace);const _=p.getSize(w),r=p.getCenter(S).applyQuaternion(y);if(B(this._camera)){const d=this.getDistanceToFitBox(_.x,_.y,_.z,s);l.push(this.moveTo(r.x,r.y,r.z,e)),l.push(this.dollyTo(d,e)),l.push(this.setFocalOffset(0,0,0,e))}else if(k(this._camera)){const d=this._camera,O=d.right-d.left,g=d.top-d.bottom,x=s?Math.max(O/_.x,g/_.y):Math.min(O/_.x,g/_.y);l.push(this.moveTo(r.x,r.y,r.z,e)),l.push(this.zoomTo(x,e)),l.push(this.setFocalOffset(0,0,0,e))}return Promise.all(l)}fitToSphere(t,e){const s=[],o="isObject3D"in t?Z.createBoundingSphere(t,ft):ft.copy(t);if(s.push(this.moveTo(o.center.x,o.center.y,o.center.z,e)),B(this._camera)){const n=this.getDistanceToFitSphere(o.radius);s.push(this.dollyTo(n,e))}else if(k(this._camera)){const n=this._camera.right-this._camera.left,a=this._camera.top-this._camera.bottom,l=2*o.radius,m=Math.min(n/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,i,o,n,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=q.NONE,this._changedDolly=0;const l=S.set(i,o,n),m=w.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 C=!a||D(this._target.x,this._targetEnd.x,this.restThreshold)&&D(this._target.y,this._targetEnd.y,this.restThreshold)&&D(this._target.z,this._targetEnd.z,this.restThreshold)&&D(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&D(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&D(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(C)}lerpLookAt(t,e,s,i,o,n,a,l,m,C,c,E,y,f=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=q.NONE,this._changedDolly=0;const p=w.set(i,o,n),_=S.set(t,e,s);M.setFromVector3(_.sub(p).applyQuaternion(this._yAxisUpSpace));const r=G.set(C,c,E),d=S.set(a,l,m);et.setFromVector3(d.sub(r).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(p.lerp(r,y));const O=et.theta-M.theta,g=et.phi-M.phi,x=et.radius-M.radius;this._sphericalEnd.set(M.radius+x*y,M.phi+g*y,M.theta+O*y),this.normalizeRotations(),this._needsUpdate=!0,f||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const T=!f||D(this._target.x,this._targetEnd.x,this.restThreshold)&&D(this._target.y,this._targetEnd.y,this.restThreshold)&&D(this._target.z,this._targetEnd.z,this.restThreshold)&&D(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&D(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&D(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(T)}setPosition(t,e,s,i=!1){return this.setLookAt(t,e,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(t,e,s,i=!1){const o=this.getPosition(w),n=this.setLookAt(o.x,o.y,o.z,t,e,s,i);return this._sphericalEnd.phi=F(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),n}setFocalOffset(t,e,s,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,s),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const o=!i||D(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&D(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&D(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(o)}setOrbitPoint(t,e,s){this._camera.updateMatrixWorld(),H.setFromMatrixColumn(this._camera.matrixWorldInverse,0),I.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Y.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=w.set(t,e,s),o=i.distanceTo(this._camera.position),n=i.sub(this._camera.position);H.multiplyScalar(n.x),I.multiplyScalar(n.y),Y.multiplyScalar(n.z),w.copy(H).add(I).add(Y),w.z=w.z+o,this.dollyTo(o,!1),this.setFocalOffset(-w.x,w.y,-w.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,i){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new v.Vector4,typeof t=="number"?this._viewport.set(t,e,s,i):this._viewport.copy(t)}getDistanceToFitBox(t,e,s,i=!1){if(_t(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const o=t/e,n=this._camera.getEffectiveFOV()*Q,a=this._camera.aspect;return((i?o>a:o<a)?e:t/a)*.5/Math.tan(n*.5)+s*.5}getDistanceToFitSphere(t){if(_t(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*Q,s=Math.atan(Math.tan(e*.5)*this._camera.aspect)*2,i=1<this._camera.aspect?e:s;return t/Math.sin(i*.5)}getTarget(t,e=!0){return(t&&t.isVector3?t:new v.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new v.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new v.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new v.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%W,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=W),this._spherical.theta+=W*Math.round((this._sphericalEnd.theta-this._spherical.theta)/W)}reset(t=!1){if(!D(this._camera.up.x,this._cameraUp0.x)||!D(this._camera.up.y,this._cameraUp0.y)||!D(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(w);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,nt),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=w.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(w);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,i=this._sphericalEnd.radius-this._spherical.radius,o=Dt.subVectors(this._targetEnd,this._target),n=bt.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 c=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=ot(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,c,1/0,t),this._needsUpdate=!0}if(U(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const c=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=ot(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,c,1/0,t),this._needsUpdate=!0}if(U(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const c=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=ot(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,c,this.maxSpeed,t),this._needsUpdate=!0}if(U(o.x)&&U(o.y)&&U(o.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const c=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Pt(this._target,this._targetEnd,this._targetVelocity,c,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(U(n.x)&&U(n.y)&&U(n.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const c=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Pt(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,c,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(U(a))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const c=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=ot(this._zoom,this._zoomEnd,this._zoomVelocity,c,1/0,t)}if(this.dollyToCursor){if(B(this._camera)&&this._changedDolly!==0){const c=this._spherical.radius-this._lastDistance,E=this._camera,y=this._getCameraDirection(tt),f=w.copy(y).cross(E.up).normalize();f.lengthSq()===0&&(f.x=1);const p=S.crossVectors(f,y),_=this._sphericalEnd.radius*Math.tan(E.getEffectiveFOV()*Q*.5),d=(this._sphericalEnd.radius-c-this._sphericalEnd.radius)/this._sphericalEnd.radius,O=G.copy(this._targetEnd).add(f.multiplyScalar(this._dollyControlCoord.x*_*E.aspect)).add(p.multiplyScalar(this._dollyControlCoord.y*_)),g=w.copy(this._targetEnd).lerp(O,d),x=this._lastDollyDirection===q.IN&&this._spherical.radius<=this.minDistance,T=this._lastDollyDirection===q.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(x||T)){this._sphericalEnd.radius-=c,this._spherical.radius-=c;const R=S.copy(y).multiplyScalar(-c);g.add(R)}this._boundary.clampPoint(g,g);const b=S.subVectors(g,this._targetEnd);this._targetEnd.copy(g),this._target.add(b),this._changedDolly-=c,U(this._changedDolly)&&(this._changedDolly=0)}else if(k(this._camera)&&this._changedZoom!==0){const c=this._zoom-this._lastZoom,E=this._camera,y=w.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(E.near+E.far)/(E.near-E.far)).unproject(E),f=S.set(0,0,-1).applyQuaternion(E.quaternion),p=G.copy(y).add(f.multiplyScalar(-y.dot(E.up))),r=-(this._zoom-c-this._zoom)/this._zoom,d=this._getCameraDirection(tt),O=this._targetEnd.dot(d),g=w.copy(this._targetEnd).lerp(p,r),x=g.dot(d),T=d.multiplyScalar(x-O);g.sub(T),this._boundary.clampPoint(g,g);const b=S.subVectors(g,this._targetEnd);this._targetEnd.copy(g),this._target.add(b),this._changedZoom-=c,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(),H.setFromMatrixColumn(this._camera.matrix,0),I.setFromMatrixColumn(this._camera.matrix,1),Y.setFromMatrixColumn(this._camera.matrix,2),H.multiplyScalar(this._focalOffset.x),I.multiplyScalar(-this._focalOffset.y),Y.multiplyScalar(this._focalOffset.z),w.copy(H).add(I).add(Y),this._camera.position.add(w)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),w.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const C=this._needsUpdate;return C&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):C?(this.dispatchEvent({type:"update"}),U(e,this.restThreshold)&&U(s,this.restThreshold)&&U(i,this.restThreshold)&&U(o.x,this.restThreshold)&&U(o.y,this.restThreshold)&&U(o.z,this.restThreshold)&&U(n.x,this.restThreshold)&&U(n.y,this.restThreshold)&&U(n.z,this.restThreshold)&&U(a,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!C&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=C,this._needsUpdate=!1,C}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:$(this.maxDistance),minZoom:this.minZoom,maxZoom:$(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:$(this.maxPolarAngle),minAzimuthAngle:$(this.minAzimuthAngle),maxAzimuthAngle:$(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:w.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=J(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=J(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=J(s.maxPolarAngle),this.minAzimuthAngle=J(s.minAzimuthAngle),this.maxAzimuthAngle=J(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),M.setFromVector3(w.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(M.theta,M.phi,e),this.dollyTo(M.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 i=e.lengthSq();if(i===0)return t;const o=S.copy(e).add(t),a=this._boundary.clampPoint(o,G).sub(o),l=a.lengthSq();if(l===0)return t.add(e);if(l===i)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(B(this._camera)){const t=this._camera,e=t.near,s=t.getEffectiveFOV()*Q,i=Math.tan(s*.5)*e,o=i*t.aspect;this._nearPlaneCorners[0].set(-o,-i,0),this._nearPlaneCorners[1].set(o,-i,0),this._nearPlaneCorners[2].set(o,i,0),this._nearPlaneCorners[3].set(-o,i,0)}else if(k(this._camera)){const t=this._camera,e=1/t.zoom,s=t.left*e,i=t.right*e,o=t.top*e,n=t.bottom*e;this._nearPlaneCorners[0].set(s,o,0),this._nearPlaneCorners[1].set(i,o,0),this._nearPlaneCorners[2].set(i,n,0),this._nearPlaneCorners[3].set(s,n,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||_t(this._camera,"_collisionTest"))return t;const s=this._getTargetDirection(tt);yt.lookAt(St,s,this._camera.up);for(let i=0;i<4;i++){const o=S.copy(this._nearPlaneCorners[i]);o.applyMatrix4(yt);const n=G.addVectors(this._target,o);at.set(n,s),at.far=this._spherical.radius+1;const a=at.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 v.Sphere){const s=e,i=s.center;X.makeEmpty(),t.traverseVisible(n=>{n.isMesh&&X.expandByObject(n)}),X.getCenter(i);let o=0;return t.traverseVisible(n=>{if(!n.isMesh)return;const a=n,l=a.geometry.clone();l.applyMatrix4(a.matrixWorld);const C=l.attributes.position;for(let c=0,E=C.count;c<E;c++)w.fromBufferAttribute(C,c),o=Math.max(o,i.distanceToSquared(w))}),s.radius=Math.sqrt(o),s}}const fe={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:ee.ColorSpace.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1,physicallyCorrectLights:!1};class ge{constructor(t){this.options=t;const{width:e,height:s,rendererParams:i}=t,{canvas:o,context:n,alpha:a,devicePixelRatio:l,antialias:m,powerPreference:C,toneMappingExposure:c,outputColorSpace:E,logarithmicDepthBuffer:y,preserveDrawingBuffer:f,stencil:p,depth:_,physicallyCorrectLights:r}=i,d=new P.WebGLRenderer({canvas:o,context:n,alpha:a,antialias:m,powerPreference:C,logarithmicDepthBuffer:y,preserveDrawingBuffer:f,stencil:p,depth:_});d.setSize(e,s),d.setPixelRatio(l),d.toneMappingExposure=c,d.outputColorSpace=E,+P.REVISION<155&&(d.useLegacyLights=r),this.renderer=d}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 ye={antialias:!0,devicePixelRatio:window.devicePixelRatio};class Ce{constructor(t){this.options=t;const{width:e,height:s,rendererParams:i,renderer:o}=t,{devicePixelRatio:n,antialias:a}=i,l=new o({antialias:a});l.setSize(e,s),l.setPixelRatio(n),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 ht{constructor(t){this.guiParams={},t&&(this.guiParams=t)}showGui(t){t&&Object.keys(this.guiParams).forEach(e=>{const s=t.addFolder(e),i=this.guiParams[e];Object.keys(i).forEach(o=>{const{min:n,max:a,step:l,name:m,paramMap:C,items:c,value:E,target:y}=i[o],f=o.toLowerCase().indexOf("color")>-1;let p;const _=typeof E=="undefined"&&y,r=_?y():i[o],d=_?o:"value";c?p=s.add(r,d,c):f?p=s.addColor(r,d):p=s.add(r,d),p=p.name(m||o),typeof n!="undefined"&&(p=p.min(n)),typeof a!="undefined"&&(p=p.max(a)),typeof l!="undefined"&&(p=p.step(l)),p=p.onChange(()=>{this.setTargetValue(e,o,r[d],C)}),_&&p.listen()})})}setTargetValue(t,e,s,i){const{onChange:o,target:n,value:a}=this.guiParams[t][e],l=e.toLowerCase().indexOf("color")>-1;if(n&&!(typeof a=="undefined"&&n)){let C=n();Array.isArray(C)||(C=[C]),C.forEach(c=>{if(c)if(l)try{c[i||e].set(s)}catch(E){e!=="color"&&!i&&console.warn(`${e} is not a color,set paramMap`)}else c[i||e]=s})}o&&o(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 Oe={fov:45,near:1,far:1e3,up:new P.Vector3(0,1,0)};class Ee{constructor(t){this.customCamera=!1,this.options=t;const{width:e,height:s,cameraParams:i}=t;if(i instanceof P.Camera)this.camera=i,this.customCamera=!0;else{const{fov:o,far:n,near:a,up:l}=i,m=new P.PerspectiveCamera(o,e/s,a,n);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 P.PerspectiveCamera&&(this.camera.aspect=t/e),this.camera.updateProjectionMatrix(),this.camera2&&(this.camera2.aspect=t/e,this.camera2.updateProjectionMatrix())}addCamera2(){const t=new P.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(t){if(t.type==="PerspectiveCamera"){const e=t;(!this.camera.matrixWorld.equals(e.matrixWorld)||this.camera.far!==e.far||this.camera.near!==e.near||this.camera.fov!==e.fov||this.camera.aspect!==e.aspect)&&this.camera.copy(e)}else{const e=t,s=e.viewMatrix,i=e.inverseViewMatrix,o=new P.Matrix4(i[0],i[4],i[8],i[12],i[1],i[5],i[9],i[13],i[2],i[6],i[10],i[14],i[3],i[7],i[11],i[15]),n=new P.Matrix4(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]),{width:a,height:l}=this.options,m=a/l;(this.camera.fov!==e.fov||this.camera.aspect!==m||!this.camera.matrixWorld.equals(o)||!this.camera.matrixWorldInverse.equals(n))&&(this.camera.fov=e.fov,this.camera.updateProjectionMatrix(),this.camera.matrixAutoUpdate=!1,this.camera.matrixWorld.copy(o),this.camera.matrixWorldInverse.copy(n),this.camera.aspect=m,this.camera.updateProjectionMatrix())}}setGui(t){const e=new ht({camera:mt(N({},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 P.PerspectiveCamera&&(e.guiParams.camera.fov={min:0,max:90,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}),e.showGui(t)}}const Te={background:null,addCamera:!0};class ve{constructor(t){this.overrideMaterial=!1,this.options=t;const{camera:e,sceneParams:s}=t,{background:i,addCamera:o}=s,n=new P.Scene;i&&(n.background=i),o&&n.add(e),this.scene=n}dispose(){var t;(t=this.scene)==null||t.traverse(e=>{se.disposeMesh(e)})}}class xe{constructor(t){this.helpers={},this.options=t}add(t){const e=t.uuid,{scene:s}=this.options;let i=this.helpers[e];if(i===void 0){if(t.isScene)i=new P.AxesHelper(100);else if(t.isCamera)i=new P.CameraHelper(t);else if(t.isPointLight)i=new P.PointLightHelper(t,1);else if(t.isDirectionalLight)i=new P.DirectionalLightHelper(t,1);else if(t.isSpotLight)i=new P.SpotLightHelper(t);else if(t.isHemisphereLight)i=new P.HemisphereLightHelper(t,10);else if(t.isRectAreaLight)i=new ie.RectAreaLightHelper(t);else{const o=new P.Box3;if(o.setFromObject(t,!0),o.isEmpty()===!1){i=new P.Box3Helper(o);const n=i.material;n.userData.object=t,n.depthTest=!1,n.transparent=!0}else return}s.add(i),this.helpers[e]=i}}addViewHelper(){const{camera:t,container:e}=this.options,s=new oe.ViewHelper(t,e);e.addEventListener("pointerdown",i=>{i.preventDefault(),s.handleClick(i)}),this.viewHelper=s}remove(t){var i;const e=t.uuid,{scene:s}=this.options;if(this.helpers[e]!==void 0){const o=this.helpers[e];s.remove(o),delete this.helpers[e],(i=o.dispose)==null||i.call(o)}}removeAll(){Object.keys(this.helpers).forEach(t=>{this.remove({uuid:t})}),this.helpers={}}removeAllExcludeScene(){Object.keys(this.helpers).forEach(t=>{this.helpers[t]instanceof P.AxesHelper||this.remove({uuid:t})})}update(t,e,s){var o,n;const{camera:i}=this.options;Object.values(this.helpers).forEach(a=>{if(a.update&&a.update(),a instanceof P.Box3Helper){const l=a.material,{object:m}=l.userData;m&&a.box.setFromObject(m,!0)}}),((o=this.viewHelper)==null?void 0:o.animating)===!0&&(this.viewHelper.update(t),(n=e.cameraControls)==null||n.setPosition(...i.position.toArray()),this.viewHelper.center.copy(s))}renderViewHelper(t){if(!this.viewHelper)return;const e=t.autoClear;t.autoClear=!1,this.viewHelper.render(t),t.autoClear=e}dispose(){var t;this.helpers={},(t=this.viewHelper)==null||t.dispose()}}class we{constructor(t){this.autoRotateSpeed=0,this.options=t;const{camera:e,controlsParams:s,customControls:i}=t,{domElement:o}=s;if(i){const n=new i(e,o);n.enableDamping=!0,n.dampingFactor=.063,n.autoRotate=!1,n.autoRotateSpeed=-60,n.enableZoom=!0,n.zoomSpeed=.2,this.customControls=n}else Z.install({THREE:P}),this.cameraControls=new Z(e,o)}addCameraControls2(t){const{controlsParams:e}=this.options,{domElement:s}=e;this.cameraControls2=new Z(t,s),this.cameraControls2.addEventListener("update",()=>{this.cameraControls.enabled=!1}),this.cameraControls2.addEventListener("sleep",()=>{this.cameraControls.enabled=!0})}enable(){this.customControls?this.customControls.enabled=!0:this.cameraControls&&(this.cameraControls.enabled=!0,this.cameraControls2&&(this.cameraControls2.enabled=!0))}disable(){this.customControls?this.customControls.enabled=!1:this.cameraControls&&(this.cameraControls.enabled=!1,this.cameraControls2&&(this.cameraControls2.enabled=!1))}update(t){var e,s,i;(e=this.customControls)==null||e.update(),(s=this.cameraControls)==null||s.update(t),(i=this.cameraControls2)==null||i.update(t),this.autoRotateSpeed&&this.cameraControls&&(this.cameraControls.azimuthAngle+=this.autoRotateSpeed*t*P.MathUtils.DEG2RAD)}dispose(){var t,e,s;(t=this.customControls)==null||t.dispose(),(e=this.cameraControls)==null||e.dispose(),(s=this.cameraControls2)==null||s.dispose()}}class Pe{constructor(t){this.event=new Vt.eventsExports.EventEmitter;const{renderer:e,scene:s,camera:i}=t,o=new re.TransformControls(i,e.domElement);if(o.getHelper){const n=o.getHelper();if(s.add(n),+P.REVISION<170){const a=o._root;a.dispose=()=>{a.traverse(l=>{l.geometry&&l.geometry.dispose(),l.material&&l.material.dispose()})},o.dispose=()=>{o.disconnect(),a.dispose()}}}else o instanceof P.Object3D&&s.add(o);this.controls=o,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 i=this.controls;i.addEventListener("change",()=>{const o=i.object;o!==void 0&&this.event.emit("change",o)}),i.addEventListener("mouseDown",()=>{const o=i.object;t=o.position.clone(),e=o.rotation.clone(),s=o.scale.clone(),this.event.emit("mouseDown",o)}),i.addEventListener("mouseUp",()=>{const o=i.object;if(o!==void 0)switch(i.getMode()){case"translate":t.equals(o.position)||this.event.emit("translate",o,o.position,t);break;case"rotate":e.equals(o.rotation)||this.event.emit("rotate",o,o.rotation,e);break;case"scale":s.equals(o.scale)||this.event.emit("scale",o,o.scale,s);break}this.event.emit("mouseUp")})}dispose(){var t;this.event.removeAllListeners(),(t=this.controls)==null||t.dispose()}}const Rt=new z.Vector3,Se=new z.Quaternion,Lt=new z.Vector3,V=new z.Matrix4,De=new z.Matrix4;class be{constructor(t={}){const e=this;let s,i,o,n;const a={camera:{style:""},objects:new WeakMap},l=t.element!==void 0?t.element:document.createElement("div");l.style.overflow="hidden",this.domElement=l;const m=document.createElement("div");m.style.transformOrigin="0 0",m.style.pointerEvents="none",l.appendChild(m);const C=document.createElement("div");C.style.transformStyle="preserve-3d",m.appendChild(C),this.getSize=function(){return{width:s,height:i}},this.render=function(_,r){const d=r.projectionMatrix.elements[5]*n;r.view&&r.view.enabled?(m.style.transform=`translate( ${-r.view.offsetX*(s/r.view.width)}px, ${-r.view.offsetY*(i/r.view.height)}px )`,m.style.transform+=`scale( ${r.view.fullWidth/r.view.width}, ${r.view.fullHeight/r.view.height} )`):m.style.transform="",_.matrixWorldAutoUpdate===!0&&_.updateMatrixWorld(),r.parent===null&&r.matrixWorldAutoUpdate===!0&&r.updateMatrixWorld();let O,g;r.isOrthographicCamera&&(O=-(r.right+r.left)/2,g=(r.top+r.bottom)/2);const x=r.view&&r.view.enabled?r.view.height/r.view.fullHeight:1,T=r.isOrthographicCamera?`scale( ${x} )scale(`+d+")translate("+c(O)+"px,"+c(g)+"px)"+E(r.matrixWorldInverse):`scale( ${x} )translateZ(`+d+"px)"+E(r.matrixWorldInverse),R=(r.isPerspectiveCamera?"perspective("+d+"px) ":"")+T+"translate("+o+"px,"+n+"px)";a.camera.style!==R&&(C.style.transform=R,a.camera.style=R),p(_,_,r)},this.setSize=function(_,r){s=_,i=r,o=s/2,n=i/2,l.style.width=_+"px",l.style.height=r+"px",m.style.width=_+"px",m.style.height=r+"px",C.style.width=_+"px",C.style.height=r+"px"};function c(_){return Math.abs(_)<1e-10?0:_}function E(_){const r=_.elements;return"matrix3d("+c(r[0])+","+c(-r[1])+","+c(r[2])+","+c(r[3])+","+c(r[4])+","+c(-r[5])+","+c(r[6])+","+c(r[7])+","+c(r[8])+","+c(-r[9])+","+c(r[10])+","+c(r[11])+","+c(r[12])+","+c(-r[13])+","+c(r[14])+","+c(r[15])+")"}function y(_){const r=_.elements;return"translate(-50%,-50%)"+("matrix3d("+c(r[0])+","+c(r[1])+","+c(r[2])+","+c(r[3])+","+c(-r[4])+","+c(-r[5])+","+c(-r[6])+","+c(-r[7])+","+c(r[8])+","+c(r[9])+","+c(r[10])+","+c(r[11])+","+c(r[12])+","+c(r[13])+","+c(r[14])+","+c(r[15])+")")}function f(_){_.isCSS3DObject&&(_.element.style.display="none");for(let r=0,d=_.children.length;r<d;r++)f(_.children[r])}function p(_,r,d,O){if(_.visible===!1){f(_);return}if(_.isCSS3DObject){const g=_.layers.test(d.layers)===!0,x=_.element;if(x.style.display=g===!0?"":"none",g===!0){_.onBeforeRender(e,r,d);let T;_.isCSS3DSprite?(V.copy(d.matrixWorldInverse),V.transpose(),_.rotation2D!==0&&V.multiply(De.makeRotationZ(_.rotation2D)),_.matrixWorld.decompose(Rt,Se,Lt),V.setPosition(Rt),V.scale(Lt),V.elements[3]=0,V.elements[7]=0,V.elements[11]=0,V.elements[15]=1,T=y(V)):T=y(_.matrixWorld);const b=a.objects.get(_);if(b===void 0||b.style!==T){x.style.transform=T;const R={style:T};a.objects.set(_,R)}x.parentNode!==C&&C.appendChild(x),_.onAfterRender(e,r,d)}}for(let g=0,x=_.children.length;g<x;g++)p(_.children[g],r,d)}}}const K=new z.Vector3,zt=new z.Matrix4,Mt=new z.Matrix4,Ft=new z.Vector3,Ht=new z.Vector3;class Ue{constructor(t={}){const e=this;let s,i,o,n;const a={objects:new WeakMap},l=t.element!==void 0?t.element:document.createElement("div");l.style.overflow="hidden",this.domElement=l,this.getSize=function(){return{width:s,height:i}},this.render=function(f,p){f.matrixWorldAutoUpdate===!0&&f.updateMatrixWorld(),p.parent===null&&p.matrixWorldAutoUpdate===!0&&p.updateMatrixWorld(),zt.copy(p.matrixWorldInverse),Mt.multiplyMatrices(p.projectionMatrix,zt),C(f,f,p),y(f)},this.setSize=function(f,p){s=f,i=p,o=s/2,n=i/2,l.style.width=f+"px",l.style.height=p+"px"};function m(f){f.isCSS2DObject&&(f.element.style.display="none");for(let p=0,_=f.children.length;p<_;p++)m(f.children[p])}function C(f,p,_){if(f.visible===!1){m(f);return}if(f.isCSS2DObject){K.setFromMatrixPosition(f.matrixWorld),K.applyMatrix4(Mt);const r=K.z>=-1&&K.z<=1&&f.layers.test(_.layers)===!0,d=f.element;d.style.display=r===!0?"":"none",r===!0&&(f.onBeforeRender(e,p,_),d.style.transform="translate("+-100*f.center.x+"%,"+-100*f.center.y+"%)translate("+(K.x*o+o)+"px,"+(-K.y*n+n)+"px)",d.parentNode!==l&&l.appendChild(d),f.onAfterRender(e,p,_));const O={distanceToCameraSquared:c(_,f)};a.objects.set(f,O)}for(let r=0,d=f.children.length;r<d;r++)C(f.children[r],p,_)}function c(f,p){return Ft.setFromMatrixPosition(f.matrixWorld),Ht.setFromMatrixPosition(p.matrixWorld),Ft.distanceToSquared(Ht)}function E(f){const p=[];return f.traverseVisible(function(_){_.isCSS2DObject&&p.push(_)}),p}function y(f){const p=E(f).sort(function(r,d){if(r.renderOrder!==d.renderOrder)return d.renderOrder-r.renderOrder;const O=a.objects.get(r).distanceToCameraSquared,g=a.objects.get(d).distanceToCameraSquared;return O-g}),_=p.length;for(let r=0,d=p.length;r<d;r++)p[r].element.style.zIndex=_-r}}}const It={zIndex:"auto"};class Ae{constructor(t){this.container=t}addRenderer(t,e){const s=e.container||this.container,i=s.offsetWidth,o=s.offsetHeight,n=t==="css2d"?new Ue:new be;n.domElement.style.position="absolute",n.domElement.style.top="0",n.domElement.style.pointerEvents="none",n.domElement.style.zIndex=e.zIndex,n.setSize(i,o),s.appendChild(n.domElement),t==="css2d"?this.css2Drenderer=n:t==="css3d"&&(this.css3Drenderer=n)}setSize(t,e){var s,i;(s=this.css2Drenderer)==null||s.setSize(t,e),(i=this.css3Drenderer)==null||i.setSize(t,e)}render(t,e){var s,i;(s=this.css2Drenderer)==null||s.render(t,e),(i=this.css3Drenderer)==null||i.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 Re={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;
@@ -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},Ct=1,j=!1,Me=new P.MeshBasicMaterial({color:"black"}),Fe=new P.SpriteMaterial({color:"black",sizeAttenuation:!0}),He=new P.SpriteMaterial({color:"black",sizeAttenuation:!1}),Ie={kernelRadius:8,minDistance:.005,maxDistance:.1},Ve={threshold:0,strength:.4,radius:.1,bloomAlphaType:0},ke={multisampling:4,premultiplieAlpha:!1};class Ne{constructor(t){this.bloomComposerActive=!1,this.active=!0,this.bloomSelection=new Set,this.bloomLayer=new P.Layers,this.bloomMaterials={},this.bloomVisible={},this.options=t;const{renderer:e,scene:s,camera:i,composerParams:o}=t,{multisampling:n}=o,{maxSamples:a}=e.capabilities,l=e.getDrawingBufferSize(new P.Vector2),m=new P.WebGLRenderTarget(l.width,l.height,{samples:Math.min(n,a),type:P.HalfFloatType}),C=new ne.RenderPass(s,i),c=new Tt.EffectComposer(e,m);c.addPass(C),this.renderer=e,this.scene=s,this.camera=i,this.finalComposer=c,this.renderPass=C;const E=e.getSize(new P.Vector2);this.setSize(E.width,E.height)}setRenderPassCamera(t){this.renderPass.camera=t}resetRenderPassCamera(){this.renderPass.camera=this.camera}addOutputPass(){const{premultiplieAlpha:t}=this.options.composerParams,e=new Le;this.outputPass=e,this.setPremultiplieAlpha(t),this.finalComposer.addPass(e)}setPremultiplieAlpha(t){this.outputPass&&(this.outputPass.uniforms.premultiplieAlpha.value=t?1:0)}addSSAOPass(t){const{scene:e,camera:s,renderer:i}=this,o=i.getSize(new P.Vector2),n=o.width,a=o.height,l=new ae.SSAOPass(e,s,n,a);l.kernelRadius=t.kernelRadius,l.minDistance=t.minDistance,l.maxDistance=t.maxDistance,this.ssaoPass=l,this.finalComposer.addPass(l)}addSSAOGui(t){if(!this.ssaoPass)return;new ht({ssao:{kernelRadius:{min:0,max:32,target:()=>this.ssaoPass},minDistance:{min:.001,max:.02,target:()=>this.ssaoPass},maxDistance:{min:.01,max:.3,target:()=>this.ssaoPass}}}).showGui(t)}addBloomPass(t){const{renderer:e}=this,{threshold:s,strength:i,radius:o,bloomAlphaType:n}=t,a=new de.UnrealBloomPass(new P.Vector2(window.innerWidth,window.innerHeight),i,o,s);this.bloomPass=a;const l=new Tt.EffectComposer(e);l.renderToScreen=!1,l.addPass(this.renderPass),l.addPass(a),this.bloomComposer=l;const m=ze(l);m.uniforms.bloomAlphaType.value=n,this.bloomComposer=l,this.finalComposer.addPass(m),this.mixPass=m,this.bloomLayer.set(Ct)}addBloomGui(t){if(!this.bloomComposer)return;new ht({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 i=e;e===void 0&&(i=!this.bloomSelection.has(s)),i?(this.bloomSelection.add(s),s.layers.enable(Ct)):(this.bloomSelection.delete(s),s.layers.disable(Ct)),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(i=>{const o=i,n=i;o.material&&this.bloomLayer.test(o.layers)===!1&&(this.bloomMaterials[o.uuid]=o.material,n.isSprite?n.material.sizeAttenuation?n.material=Fe:n.material=He:o.material=Me)})})}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 ct=class ct{constructor(t,e){this.raycaster=new P.Raycaster,this.installPlugins=new Map,this._cameraPositon=new P.Vector3,this._cameraTarget=new P.Vector3,this.event=new Vt.eventsExports.EventEmitter,this.clock=new P.Clock,this.userData={},this.pipViewportState=!1,this.options=$t(ct.options,t,{isMergeableObject:me.isPlainObject}),this.event.setMaxListeners(1/0);const{container:s,stats:i,gui:o,resizeObserver:n}=this.options;if(o){const a=new te;a.open(!1),this.gui=a}if(this.init(),i){const a=new Jt({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(),n&&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 controls(){return this.controlsController.cameraControls}get cameraPositon(){return this.controls.getPosition(this._cameraPositon,!1)}get cameraTarget(){return this.controls.getTarget(this._cameraTarget,!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:i,viewHelper:o,renderer:n,scene:a,camera:l,controls:m}=this.options,{width:C,height:c}=this.getSize(),E=new Ee({isdev:e,width:C,height:c,cameraParams:l,cameraControls:m===!0});this.gui&&E.setGui(this.gui);const y=E.camera,f=new ve({camera:y,sceneParams:a}),p=f.scene,_=s?new Ce({width:C,height:c,scene:p,camera:y,isdev:e,renderer:s.WebGPURenderer,rendererParams:ye}):new ge({width:C,height:c,scene:p,camera:y,isdev:e,rendererParams:mt(N({},n),{antialias:!1})});if(i){const r=new xe({container:t,scene:p,camera:y});r.add(p),this.helperController=r,o&&r.addViewHelper()}this.sceneController=f,this.rendererController=_,this.cameraController=E,t.appendChild(_.renderer.domElement)}initComposer(){const{bloom:t,bloomParams:e,ssao:s,ssaoParams:i,composer:o}=this.options,n=new Ne({renderer:this.renderer,scene:this.scene,camera:this.camera,composerParams:o});this.composerController=n,t&&(n.addBloomPass(N({},e)),this.gui&&n.addBloomGui(this.gui)),s&&(n.addSSAOPass(N({},i)),this.gui&&n.addSSAOGui(this.gui)),n.addOutputPass()}initCSSRenderer(){const{container:t,css2DRenderer:e,css3DRenderer:s,css2DRendererParams:i,css3DRendererParams:o}=this.options;if(e||s){const n=new Ae(t);e&&n.addRenderer("css2d",i),s&&n.addRenderer("css3d",o),this.cssRendererController=n}}initControls(){const{controls:t,controlsParams:e,transformControls:s}=this.options;if(t){const i=new we({camera:this.camera,controlsParams:{domElement:(e==null?void 0:e.domElement)||this.renderer.domElement},customControls:typeof t=="boolean"?void 0:t});this.controlsController=i}if(s){const i=new Pe({camera:this.camera,renderer:this.renderer,scene:this.scene});i.event.on("mouseDown",()=>{var o;(o=this.controlsController)==null||o.disable()}),i.event.on("mouseUp",()=>{var o;(o=this.controlsController)==null||o.enable()}),this.transformController=i}}getSize(){const{container:t}=this.options,e=t.getBoundingClientRect();return{width:e.width,height:e.height}}initResizeObserver(){const{container:t}=this.options;if(this.resizeObserver)return;const e=this.getSize(),s=new ResizeObserver(()=>{const i=this.getSize();(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:i,cameraController:o,composerController:n,cssRendererController:a}=this;o==null||o.setSize(t,e),i==null||i.setSize(t,e),n==null||n.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:i,options:o}=this,{container:n}=o,a=new P.Vector2,l=n.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){i.setFromCamera(a,this.camera);const m=i.intersectObjects(e||this.scene.children,s);if(m.length)return{object:m[0].object,intersects:m}}}render(){var n,a,l,m,C,c,E;const{scene:t,camera:e,clock:s}=this,i=s.getDelta(),o=s.getElapsedTime();vt.update(),(n=this.controlsController)==null||n.update(i),this.installPlugins.forEach(y=>{var f;(f=y.update)==null||f.call(y,i,o)}),(a=this.helperController)==null||a.update(i,this.controlsController,this.cameraTarget),(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(),(C=this.helperController)==null||C.renderViewHelper(this.renderer),(c=this.cssRendererController)==null||c.render(t,e),(E=this.stats)==null||E.update(),this.event.emit("render",{delta:i,elapsed:o})}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,i=s/e.width,o=s/e.height,n=1-i,a=1-o;t={left:n,top:a,width:i,height:o}}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,i=t.width,o=t.height,n=i/o;this.camera.aspect!==n&&(this.camera.aspect=n,this.camera.updateProjectionMatrix()),this.renderer.setViewport(e,s,i,o),this.renderer.setScissor(e,s,i,o),this.renderer.setScissorTest(!0)}setViewportPip(){if(!this.pipViewportState)return;const t=this.pipViewportState,e=this.getSize(),s=e.width*t.left,i=(1-(t.top+t.height))*e.height,o=e.width*t.width,n=e.height*t.height,a=o/n,l=this.cameraController.camera2;l&&l.aspect!==a&&(l.aspect=a,l.updateProjectionMatrix()),this.renderer.setViewport(s,i,o,n),this.renderer.setScissor(s,i,o,n),this.renderer.setScissorTest(!0)}dispose(){var t,e,s,i,o,n,a,l,m,C,c;this.stop(),vt.removeAll(),this.event.removeAllListeners(),(t=this.resizeObserver)==null||t.unobserve(this.options.container),this.installPlugins.forEach(E=>{var y;(y=E.dispose)==null||y.call(E)}),(e=this.controlsController)==null||e.dispose(),(s=this.transformController)==null||s.dispose(),(i=this.cssRendererController)==null||i.dispose(),(o=this.sceneController)==null||o.dispose(),(n=this.helperController)==null||n.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(),(C=this.stats)==null||C.dom.remove(),(c=this.renderer)==null||c.domElement.remove()}};ct.options={isdev:j,stats:j,gui:j,helper:j,viewHelper:j,controls:!0,transformControls:j,resizeObserver:!0,renderer:fe,composer:ke,scene:Te,camera:Oe,bloom:!1,bloomParams:Ve,ssao:!1,ssaoParams:Ie,css2DRenderer:!1,css2DRendererParams:N({},It),css3DRenderer:!1,css3DRendererParams:N({},It)};let lt=ct;const Be=Z.ACTION;exports.BaseObject=pe.BaseObject;exports.GUIObject=ht;exports.Pencil=lt;exports.cameraControlsAction=Be;exports.default=lt;
94
+ `,defines:{}}),"baseTexture");return t.needsSwap=!0,t},Ct=1,j=!1,Me=new P.MeshBasicMaterial({color:"black"}),Fe=new P.SpriteMaterial({color:"black",sizeAttenuation:!0}),He=new P.SpriteMaterial({color:"black",sizeAttenuation:!1}),Ie={kernelRadius:8,minDistance:.005,maxDistance:.1},Ve={threshold:0,strength:.4,radius:.1,bloomAlphaType:0},ke={multisampling:4,premultiplieAlpha:!1};class Ne{constructor(t){this.bloomComposerActive=!1,this.active=!0,this.bloomSelection=new Set,this.bloomLayer=new P.Layers,this.bloomMaterials={},this.bloomVisible={},this.options=t;const{renderer:e,scene:s,camera:i,composerParams:o}=t,{multisampling:n}=o,{maxSamples:a}=e.capabilities,l=e.getDrawingBufferSize(new P.Vector2),m=new P.WebGLRenderTarget(l.width,l.height,{samples:Math.min(n,a),type:P.HalfFloatType}),C=new ne.RenderPass(s,i),c=new Tt.EffectComposer(e,m);c.addPass(C),this.renderer=e,this.scene=s,this.camera=i,this.finalComposer=c,this.renderPass=C;const E=e.getSize(new P.Vector2);this.setSize(E.width,E.height)}setRenderPassCamera(t){this.renderPass.camera=t}resetRenderPassCamera(){this.renderPass.camera=this.camera}addOutputPass(){const{premultiplieAlpha:t}=this.options.composerParams,e=new Le;this.outputPass=e,this.setPremultiplieAlpha(t),this.finalComposer.addPass(e)}setPremultiplieAlpha(t){this.outputPass&&(this.outputPass.uniforms.premultiplieAlpha.value=t?1:0)}addSSAOPass(t){const{scene:e,camera:s,renderer:i}=this,o=i.getSize(new P.Vector2),n=o.width,a=o.height,l=new ae.SSAOPass(e,s,n,a);l.kernelRadius=t.kernelRadius,l.minDistance=t.minDistance,l.maxDistance=t.maxDistance,this.ssaoPass=l,this.finalComposer.addPass(l)}addSSAOGui(t){if(!this.ssaoPass)return;new ht({ssao:{kernelRadius:{min:0,max:32,target:()=>this.ssaoPass},minDistance:{min:.001,max:.02,target:()=>this.ssaoPass},maxDistance:{min:.01,max:.3,target:()=>this.ssaoPass}}}).showGui(t)}addBloomPass(t){const{renderer:e}=this,{threshold:s,strength:i,radius:o,bloomAlphaType:n}=t,a=new de.UnrealBloomPass(new P.Vector2(window.innerWidth,window.innerHeight),i,o,s);this.bloomPass=a;const l=new Tt.EffectComposer(e);l.renderToScreen=!1,l.addPass(this.renderPass),l.addPass(a),this.bloomComposer=l;const m=ze(l);m.uniforms.bloomAlphaType.value=n,this.bloomComposer=l,this.finalComposer.addPass(m),this.mixPass=m,this.bloomLayer.set(Ct)}addBloomGui(t){if(!this.bloomComposer)return;new ht({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 i=e;e===void 0&&(i=!this.bloomSelection.has(s)),i?(this.bloomSelection.add(s),s.layers.enable(Ct)):(this.bloomSelection.delete(s),s.layers.disable(Ct)),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(i=>{const o=i,n=i;o.material&&this.bloomLayer.test(o.layers)===!1&&(this.bloomMaterials[o.uuid]=o.material,n.isSprite?n.material.sizeAttenuation?n.material=Fe:n.material=He:o.material=Me)})})}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 ct=class ct{constructor(t,e){this.raycaster=new P.Raycaster,this.installPlugins=new Map,this._cameraPositon=new P.Vector3,this._cameraTarget=new P.Vector3,this.event=new Vt.eventsExports.EventEmitter,this.clock=new P.Clock,this.userData={},this.pipViewportState=!1,this.options=$t(ct.options,t,{isMergeableObject:me.isPlainObject}),this.event.setMaxListeners(1/0);const{container:s,stats:i,gui:o,resizeObserver:n}=this.options;if(o){const a=new te;a.open(!1),this.gui=a}if(this.init(),i){const a=new Jt({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(),n&&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 controls(){return this.controlsController.cameraControls}get cameraPositon(){return this.controls.getPosition(this._cameraPositon,!1)}get cameraTarget(){return this.controls.getTarget(this._cameraTarget,!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:i,viewHelper:o,renderer:n,scene:a,camera:l,controls:m}=this.options,{width:C,height:c}=this.getSize(),E=new Ee({isdev:e,width:C,height:c,cameraParams:l,cameraControls:m===!0});this.gui&&E.setGui(this.gui);const y=E.camera,f=new ve({camera:y,sceneParams:a}),p=f.scene,_=s?new Ce({width:C,height:c,scene:p,camera:y,isdev:e,renderer:s.WebGPURenderer,rendererParams:ye}):new ge({width:C,height:c,scene:p,camera:y,isdev:e,rendererParams:mt(N({},n),{antialias:!1})});if(i){const r=new xe({container:t,scene:p,camera:y});r.add(p),this.helperController=r,o&&r.addViewHelper()}this.sceneController=f,this.rendererController=_,this.cameraController=E,t.appendChild(_.renderer.domElement)}initComposer(){const{bloom:t,bloomParams:e,ssao:s,ssaoParams:i,composer:o}=this.options,n=new Ne({renderer:this.renderer,scene:this.scene,camera:this.camera,composerParams:o});this.composerController=n,t&&(n.addBloomPass(N({},e)),this.gui&&n.addBloomGui(this.gui)),s&&(n.addSSAOPass(N({},i)),this.gui&&n.addSSAOGui(this.gui)),n.addOutputPass()}initCSSRenderer(){const{container:t,css2DRenderer:e,css3DRenderer:s,css2DRendererParams:i,css3DRendererParams:o}=this.options;if(e||s){const n=new Ae(t);e&&n.addRenderer("css2d",i),s&&n.addRenderer("css3d",o),this.cssRendererController=n}}initControls(){const{controls:t,controlsParams:e,transformControls:s}=this.options;if(t){const i=new we({camera:this.camera,controlsParams:{domElement:(e==null?void 0:e.domElement)||this.renderer.domElement},customControls:typeof t=="boolean"?void 0:t});this.controlsController=i}if(s){const i=new Pe({camera:this.camera,renderer:this.renderer,scene:this.scene});i.event.on("mouseDown",()=>{var o;(o=this.controlsController)==null||o.disable()}),i.event.on("mouseUp",()=>{var o;(o=this.controlsController)==null||o.enable()}),this.transformController=i}}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(i=>{for(const o of i){const n=o.contentRect;(n.width!==e.width||n.height!==e.height)&&(e.width=n.width,e.height=n.height,this.handeleResize(n.width,n.height),this.render())}});s.observe(t),this.resizeObserver=s}handeleResize(t,e,s=!0){const{rendererController:i,cameraController:o,composerController:n,cssRendererController:a}=this;o==null||o.setSize(t,e),i==null||i.setSize(t,e),n==null||n.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:i,options:o}=this,{container:n}=o,a=new P.Vector2,l=n.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){i.setFromCamera(a,this.camera);const m=i.intersectObjects(e||this.scene.children,s);if(m.length)return{object:m[0].object,intersects:m}}}render(){var n,a,l,m,C,c,E;const{scene:t,camera:e,clock:s}=this,i=s.getDelta(),o=s.getElapsedTime();vt.update(),(n=this.controlsController)==null||n.update(i),this.installPlugins.forEach(y=>{var f;(f=y.update)==null||f.call(y,i,o)}),(a=this.helperController)==null||a.update(i,this.controlsController,this.cameraTarget),(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(),(C=this.helperController)==null||C.renderViewHelper(this.renderer),(c=this.cssRendererController)==null||c.render(t,e),(E=this.stats)==null||E.update(),this.event.emit("render",{delta:i,elapsed:o})}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,i=s/e.width,o=s/e.height,n=1-i,a=1-o;t={left:n,top:a,width:i,height:o}}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,i=t.width,o=t.height,n=i/o;this.camera.aspect!==n&&(this.camera.aspect=n,this.camera.updateProjectionMatrix()),this.renderer.setViewport(e,s,i,o),this.renderer.setScissor(e,s,i,o),this.renderer.setScissorTest(!0)}setViewportPip(){if(!this.pipViewportState)return;const t=this.pipViewportState,e=this.getSize(),s=e.width*t.left,i=(1-(t.top+t.height))*e.height,o=e.width*t.width,n=e.height*t.height,a=o/n,l=this.cameraController.camera2;l&&l.aspect!==a&&(l.aspect=a,l.updateProjectionMatrix()),this.renderer.setViewport(s,i,o,n),this.renderer.setScissor(s,i,o,n),this.renderer.setScissorTest(!0)}dispose(){var t,e,s,i,o,n,a,l,m,C,c;this.stop(),vt.removeAll(),this.event.removeAllListeners(),(t=this.resizeObserver)==null||t.unobserve(this.options.container),this.installPlugins.forEach(E=>{var y;(y=E.dispose)==null||y.call(E)}),(e=this.controlsController)==null||e.dispose(),(s=this.transformController)==null||s.dispose(),(i=this.cssRendererController)==null||i.dispose(),(o=this.sceneController)==null||o.dispose(),(n=this.helperController)==null||n.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(),(C=this.stats)==null||C.dom.remove(),(c=this.renderer)==null||c.domElement.remove()}};ct.options={isdev:j,stats:j,gui:j,helper:j,viewHelper:j,controls:!0,transformControls:j,resizeObserver:!0,renderer:fe,composer:ke,scene:Te,camera:Oe,bloom:!1,bloomParams:Ve,ssao:!1,ssaoParams:Ie,css2DRenderer:!1,css2DRendererParams:N({},It),css3DRenderer:!1,css3DRendererParams:N({},It)};let lt=ct;const Be=Z.ACTION;exports.BaseObject=pe.BaseObject;exports.GUIObject=ht;exports.Pencil=lt;exports.cameraControlsAction=Be;exports.default=lt;
@@ -2321,8 +2321,8 @@ class Re {
2321
2321
  this.container = t;
2322
2322
  }
2323
2323
  addRenderer(t, e) {
2324
- const s = e.container || this.container, i = s.getBoundingClientRect(), { width: o, height: n } = i, a = t === "css2d" ? new Ae() : new Ue();
2325
- a.domElement.style.position = "absolute", a.domElement.style.top = "0", a.domElement.style.pointerEvents = "none", a.domElement.style.zIndex = e.zIndex, a.setSize(o, n), s.appendChild(a.domElement), t === "css2d" ? this.css2Drenderer = a : t === "css3d" && (this.css3Drenderer = a);
2324
+ const s = e.container || this.container, i = s.offsetWidth, o = s.offsetHeight, n = t === "css2d" ? new Ae() : new Ue();
2325
+ n.domElement.style.position = "absolute", n.domElement.style.top = "0", n.domElement.style.pointerEvents = "none", n.domElement.style.zIndex = e.zIndex, n.setSize(i, o), s.appendChild(n.domElement), t === "css2d" ? this.css2Drenderer = n : t === "css3d" && (this.css3Drenderer = n);
2326
2326
  }
2327
2327
  setSize(t, e) {
2328
2328
  var s, i;
@@ -2803,18 +2803,20 @@ const ht = class ht {
2803
2803
  }
2804
2804
  }
2805
2805
  getSize() {
2806
- const { container: t } = this.options, e = t.getBoundingClientRect();
2806
+ const { container: t } = this.options;
2807
2807
  return {
2808
- width: e.width,
2809
- height: e.height
2808
+ width: t.offsetWidth,
2809
+ height: t.offsetHeight
2810
2810
  };
2811
2811
  }
2812
2812
  initResizeObserver() {
2813
2813
  const { container: t } = this.options;
2814
2814
  if (this.resizeObserver) return;
2815
- const e = this.getSize(), s = new ResizeObserver(() => {
2816
- const i = this.getSize();
2817
- (i.width !== e.width || i.height !== e.height) && (e.width = i.width, e.height = i.height, this.handeleResize(i.width, i.height), this.render());
2815
+ const e = this.getSize(), s = new ResizeObserver((i) => {
2816
+ for (const o of i) {
2817
+ const n = o.contentRect;
2818
+ (n.width !== e.width || n.height !== e.height) && (e.width = n.width, e.height = n.height, this.handeleResize(n.width, n.height), this.render());
2819
+ }
2818
2820
  });
2819
2821
  s.observe(t), this.resizeObserver = s;
2820
2822
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gl-draw",
3
- "version": "0.11.16",
3
+ "version": "0.11.17",
4
4
  "author": "gitplus <hstits@gmail.com>",
5
5
  "scripts": {
6
6
  "start": "bundler-dev",