diff --git a/dist/CameraControls.d.ts b/dist/CameraControls.d.ts index 30a8dd4..72c5478 100644 --- a/dist/CameraControls.d.ts +++ b/dist/CameraControls.d.ts @@ -1,8 +1,10 @@ import * as _THREE from 'three'; -import { ACTION, PointerInput, MouseButtons, Touches, FitToOptions, CameraControlsEventMap } from './types'; +import { THREESubset, ACTION, PointerInput, MouseButtons, Touches, FitToOptions, CameraControlsEventMap } from './types'; import { EventDispatcher } from './EventDispatcher'; export declare class CameraControls extends EventDispatcher { - static install(libs: any): void; + static install(libs: { + THREE: THREESubset; + }): void; static readonly ACTION: Readonly; minPolarAngle: number; maxPolarAngle: number; @@ -71,6 +73,8 @@ export declare class CameraControls extends EventDispatcher { addEventListener(type: K, listener: (event: CameraControlsEventMap[K]) => any): void; removeEventListener(type: K, listener: (event: CameraControlsEventMap[K]) => any): void; rotate(azimuthAngle: number, polarAngle: number, enableTransition?: boolean): void; + rotateAzimuthTo(azimuthAngle: number, enableTransition?: boolean): void; + rotatePolarTo(polarAngle: number, enableTransition?: boolean): void; rotateTo(azimuthAngle: number, polarAngle: number, enableTransition?: boolean): void; dolly(distance: number, enableTransition?: boolean): void; dollyTo(distance: number, enableTransition?: boolean): void; diff --git a/dist/camera-controls.js b/dist/camera-controls.js index 5e4fd6a..4e9ae9e 100644 --- a/dist/camera-controls.js +++ b/dist/camera-controls.js @@ -812,6 +812,14 @@ if (enableTransition === void 0) { enableTransition = false; } this.rotateTo(this._sphericalEnd.theta + azimuthAngle, this._sphericalEnd.phi + polarAngle, enableTransition); }; + CameraControls.prototype.rotateAzimuthTo = function (azimuthAngle, enableTransition) { + if (enableTransition === void 0) { enableTransition = false; } + this.rotateTo(this._sphericalEnd.theta + azimuthAngle, this._sphericalEnd.phi, enableTransition); + }; + CameraControls.prototype.rotatePolarTo = function (polarAngle, enableTransition) { + if (enableTransition === void 0) { enableTransition = false; } + this.rotateTo(this._sphericalEnd.theta, this._sphericalEnd.phi + polarAngle, enableTransition); + }; CameraControls.prototype.rotateTo = function (azimuthAngle, polarAngle, enableTransition) { if (enableTransition === void 0) { enableTransition = false; } var theta = THREE.MathUtils.clamp(azimuthAngle, this.minAzimuthAngle, this.maxAzimuthAngle); diff --git a/dist/camera-controls.min.js b/dist/camera-controls.min.js index 39a23c1..0a7af14 100644 --- a/dist/camera-controls.min.js +++ b/dist/camera-controls.min.js @@ -18,4 +18,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - ***************************************************************************** */var extendStatics=function(d,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)if(Object.prototype.hasOwnProperty.call(b,p))d[p]=b[p]};return extendStatics(d,b)};function __extends(d,b){if(typeof b!=="function"&&b!==null)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");extendStatics(d,b);function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)}var ACTION;(function(ACTION){ACTION[ACTION["NONE"]=0]="NONE";ACTION[ACTION["ROTATE"]=1]="ROTATE";ACTION[ACTION["TRUCK"]=2]="TRUCK";ACTION[ACTION["OFFSET"]=3]="OFFSET";ACTION[ACTION["DOLLY"]=4]="DOLLY";ACTION[ACTION["ZOOM"]=5]="ZOOM";ACTION[ACTION["TOUCH_ROTATE"]=6]="TOUCH_ROTATE";ACTION[ACTION["TOUCH_TRUCK"]=7]="TOUCH_TRUCK";ACTION[ACTION["TOUCH_OFFSET"]=8]="TOUCH_OFFSET";ACTION[ACTION["TOUCH_DOLLY"]=9]="TOUCH_DOLLY";ACTION[ACTION["TOUCH_ZOOM"]=10]="TOUCH_ZOOM";ACTION[ACTION["TOUCH_DOLLY_TRUCK"]=11]="TOUCH_DOLLY_TRUCK";ACTION[ACTION["TOUCH_DOLLY_OFFSET"]=12]="TOUCH_DOLLY_OFFSET";ACTION[ACTION["TOUCH_ZOOM_TRUCK"]=13]="TOUCH_ZOOM_TRUCK";ACTION[ACTION["TOUCH_ZOOM_OFFSET"]=14]="TOUCH_ZOOM_OFFSET"})(ACTION||(ACTION={}));function isPerspectiveCamera(camera){return camera.isPerspectiveCamera}function isOrthographicCamera(camera){return camera.isOrthographicCamera}var PI_2=Math.PI*2;var PI_HALF=Math.PI/2;var FPS_60=60;var EPSILON=1e-5;function approxZero(number){return Math.abs(number)=2;if(isMultiTouch){var dx=_v2.x-_this._activePointers[1].clientX;var dy=_v2.y-_this._activePointers[1].clientY;var distance=Math.sqrt(dx*dx+dy*dy);dollyStart_1.set(0,distance);var x=(_this._activePointers[0].clientX+_this._activePointers[1].clientX)*.5;var y=(_this._activePointers[0].clientY+_this._activePointers[1].clientY)*.5;lastDragPosition_1.set(x,y)}_this.dispatchEvent({type:"controlstart"})};var dragging_1=function(){if(!_this._enabled)return;extractClientCoordFromEvent(_this._activePointers,_v2);var deltaX=lastDragPosition_1.x-_v2.x;var deltaY=lastDragPosition_1.y-_v2.y;lastDragPosition_1.copy(_v2);switch(_this._state){case ACTION.ROTATE:case ACTION.TOUCH_ROTATE:{_this._rotateInternal(deltaX,deltaY);break}case ACTION.DOLLY:case ACTION.ZOOM:{var dollyX=_this.dollyToCursor?(dragStartPosition_1.x-_this._elementRect.x)/_this._elementRect.z*2-1:0;var dollyY=_this.dollyToCursor?(dragStartPosition_1.y-_this._elementRect.y)/_this._elementRect.w*-2+1:0;_this._state===ACTION.DOLLY?_this._dollyInternal(deltaY*TOUCH_DOLLY_FACTOR,dollyX,dollyY):_this._zoomInternal(deltaY*TOUCH_DOLLY_FACTOR,dollyX,dollyY);break}case ACTION.TOUCH_DOLLY:case ACTION.TOUCH_ZOOM:case ACTION.TOUCH_DOLLY_TRUCK:case ACTION.TOUCH_ZOOM_TRUCK:case ACTION.TOUCH_DOLLY_OFFSET:case ACTION.TOUCH_ZOOM_OFFSET:{var dx=_v2.x-_this._activePointers[1].clientX;var dy=_v2.y-_this._activePointers[1].clientY;var distance=Math.sqrt(dx*dx+dy*dy);var dollyDelta=dollyStart_1.y-distance;dollyStart_1.set(0,distance);var dollyX=_this.dollyToCursor?(lastDragPosition_1.x-_this._elementRect.x)/_this._elementRect.z*2-1:0;var dollyY=_this.dollyToCursor?(lastDragPosition_1.y-_this._elementRect.y)/_this._elementRect.w*-2+1:0;_this._state===ACTION.TOUCH_DOLLY||_this._state===ACTION.TOUCH_DOLLY_TRUCK?_this._dollyInternal(dollyDelta*TOUCH_DOLLY_FACTOR,dollyX,dollyY):_this._zoomInternal(dollyDelta*TOUCH_DOLLY_FACTOR,dollyX,dollyY);if(_this._state===ACTION.TOUCH_DOLLY_TRUCK||_this._state===ACTION.TOUCH_ZOOM_TRUCK){_this._truckInternal(deltaX,deltaY,false)}else if(_this._state===ACTION.TOUCH_DOLLY_OFFSET||_this._state===ACTION.TOUCH_ZOOM_OFFSET){_this._truckInternal(deltaX,deltaY,true)}break}case ACTION.TRUCK:case ACTION.TOUCH_TRUCK:{_this._truckInternal(deltaX,deltaY,false);break}case ACTION.OFFSET:case ACTION.TOUCH_OFFSET:{_this._truckInternal(deltaX,deltaY,true);break}}_this.dispatchEvent({type:"control"})};var endDragging_1=function(){extractClientCoordFromEvent(_this._activePointers,_v2);lastDragPosition_1.copy(_v2);if(_this._activePointers.length===0){_this._domElement.ownerDocument.removeEventListener("pointermove",onPointerMove_1,{passive:false});_this._domElement.ownerDocument.removeEventListener("pointerup",onPointerUp_1);_this._domElement.ownerDocument.removeEventListener("touchmove",onTouchMove_1,{passive:false});_this._domElement.ownerDocument.removeEventListener("touchend",onTouchEnd_1)}_this.dispatchEvent({type:"controlend"})};_this._domElement.addEventListener("pointerdown",onPointerDown_1);isPointerEventsNotSupported&&_this._domElement.addEventListener("mousedown",onMouseDown_1);isPointerEventsNotSupported&&_this._domElement.addEventListener("touchstart",onTouchStart_1);_this._domElement.addEventListener("pointercancel",onPointerUp_1);_this._domElement.addEventListener("wheel",onMouseWheel_1,{passive:false});_this._domElement.addEventListener("contextmenu",onContextMenu_1);_this._removeAllEventListeners=function(){_this._domElement.removeEventListener("pointerdown",onPointerDown_1);_this._domElement.removeEventListener("mousedown",onMouseDown_1);_this._domElement.removeEventListener("touchstart",onTouchStart_1);_this._domElement.removeEventListener("pointercancel",onPointerUp_1);_this._domElement.removeEventListener("wheel",onMouseWheel_1,{passive:false});_this._domElement.removeEventListener("contextmenu",onContextMenu_1);_this._domElement.ownerDocument.removeEventListener("pointermove",onPointerMove_1,{passive:false});_this._domElement.ownerDocument.removeEventListener("mousemove",onMouseMove_1);_this._domElement.ownerDocument.removeEventListener("touchmove",onTouchMove_1,{passive:false});_this._domElement.ownerDocument.removeEventListener("pointerup",onPointerUp_1);_this._domElement.ownerDocument.removeEventListener("mouseup",onMouseUp_1);_this._domElement.ownerDocument.removeEventListener("touchend",onTouchEnd_1)};_this.cancel=function(){cancelDragging_1();_this.dispatchEvent({type:"controlend"})}}_this.update(0);return _this}CameraControls.install=function(libs){THREE=libs.THREE;_ORIGIN=Object.freeze(new THREE.Vector3(0,0,0));_AXIS_Y=Object.freeze(new THREE.Vector3(0,1,0));_AXIS_Z=Object.freeze(new THREE.Vector3(0,0,1));_v2=new THREE.Vector2;_v3A=new THREE.Vector3;_v3B=new THREE.Vector3;_v3C=new THREE.Vector3;_xColumn=new THREE.Vector3;_yColumn=new THREE.Vector3;_zColumn=new THREE.Vector3;_sphericalA=new THREE.Spherical;_sphericalB=new THREE.Spherical;_box3A=new THREE.Box3;_box3B=new THREE.Box3;_sphere=new THREE.Sphere;_quaternionA=new THREE.Quaternion;_quaternionB=new THREE.Quaternion;_rotationMatrix=new THREE.Matrix4;_raycaster=new THREE.Raycaster};Object.defineProperty(CameraControls,"ACTION",{get:function(){return readonlyACTION},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"camera",{get:function(){return this._camera},set:function(camera){this._camera=camera;this.updateCameraUp();this._camera.updateProjectionMatrix();this._updateNearPlaneCorners();this._needsUpdate=true},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"enabled",{get:function(){return this._enabled},set:function(enabled){this._enabled=enabled;if(!enabled)this.cancel()},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"currentAction",{get:function(){return this._state},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"distance",{get:function(){return this._spherical.radius},set:function(distance){if(this._spherical.radius===distance&&this._sphericalEnd.radius===distance)return;this._spherical.radius=distance;this._sphericalEnd.radius=distance;this._needsUpdate=true},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"azimuthAngle",{get:function(){return this._spherical.theta},set:function(azimuthAngle){if(this._spherical.theta===azimuthAngle&&this._sphericalEnd.theta===azimuthAngle)return;this._spherical.theta=azimuthAngle;this._sphericalEnd.theta=azimuthAngle;this._needsUpdate=true},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"polarAngle",{get:function(){return this._spherical.phi},set:function(polarAngle){if(this._spherical.phi===polarAngle&&this._sphericalEnd.phi===polarAngle)return;this._spherical.phi=polarAngle;this._sphericalEnd.phi=polarAngle;this._needsUpdate=true},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"boundaryEnclosesCamera",{get:function(){return this._boundaryEnclosesCamera},set:function(boundaryEnclosesCamera){this._boundaryEnclosesCamera=boundaryEnclosesCamera;this._needsUpdate=true},enumerable:false,configurable:true});CameraControls.prototype.addEventListener=function(type,listener){_super.prototype.addEventListener.call(this,type,listener)};CameraControls.prototype.removeEventListener=function(type,listener){_super.prototype.removeEventListener.call(this,type,listener)};CameraControls.prototype.rotate=function(azimuthAngle,polarAngle,enableTransition){if(enableTransition===void 0){enableTransition=false}this.rotateTo(this._sphericalEnd.theta+azimuthAngle,this._sphericalEnd.phi+polarAngle,enableTransition)};CameraControls.prototype.rotateTo=function(azimuthAngle,polarAngle,enableTransition){if(enableTransition===void 0){enableTransition=false}var theta=THREE.MathUtils.clamp(azimuthAngle,this.minAzimuthAngle,this.maxAzimuthAngle);var phi=THREE.MathUtils.clamp(polarAngle,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=theta;this._sphericalEnd.phi=phi;this._sphericalEnd.makeSafe();if(!enableTransition){this._spherical.theta=this._sphericalEnd.theta;this._spherical.phi=this._sphericalEnd.phi}this._needsUpdate=true};CameraControls.prototype.dolly=function(distance,enableTransition){if(enableTransition===void 0){enableTransition=false}this.dollyTo(this._sphericalEnd.radius-distance,enableTransition)};CameraControls.prototype.dollyTo=function(distance,enableTransition){if(enableTransition===void 0){enableTransition=false}var lastRadius=this._sphericalEnd.radius;var newRadius=THREE.MathUtils.clamp(distance,this.minDistance,this.maxDistance);var hasCollider=this.colliderMeshes.length>=1;if(hasCollider){var maxDistanceByCollisionTest=this._collisionTest();var isCollided=approxEquals(maxDistanceByCollisionTest,this._spherical.radius);var isDollyIn=lastRadius>newRadius;if(!isDollyIn&&isCollided)return;this._sphericalEnd.radius=Math.min(newRadius,maxDistanceByCollisionTest)}else{this._sphericalEnd.radius=newRadius}if(!enableTransition){this._spherical.radius=this._sphericalEnd.radius}this._needsUpdate=true};CameraControls.prototype.zoom=function(zoomStep,enableTransition){if(enableTransition===void 0){enableTransition=false}this.zoomTo(this._zoomEnd+zoomStep,enableTransition)};CameraControls.prototype.zoomTo=function(zoom,enableTransition){if(enableTransition===void 0){enableTransition=false}this._zoomEnd=THREE.MathUtils.clamp(zoom,this.minZoom,this.maxZoom);if(!enableTransition){this._zoom=this._zoomEnd}this._needsUpdate=true};CameraControls.prototype.pan=function(x,y,enableTransition){if(enableTransition===void 0){enableTransition=false}console.log("`pan` has been renamed to `truck`");this.truck(x,y,enableTransition)};CameraControls.prototype.truck=function(x,y,enableTransition){if(enableTransition===void 0){enableTransition=false}this._camera.updateMatrix();_xColumn.setFromMatrixColumn(this._camera.matrix,0);_yColumn.setFromMatrixColumn(this._camera.matrix,1);_xColumn.multiplyScalar(x);_yColumn.multiplyScalar(-y);var offset=_v3A.copy(_xColumn).add(_yColumn);this._encloseToBoundary(this._targetEnd,offset,this.boundaryFriction);if(!enableTransition){this._target.copy(this._targetEnd)}this._needsUpdate=true};CameraControls.prototype.forward=function(distance,enableTransition){if(enableTransition===void 0){enableTransition=false}_v3A.setFromMatrixColumn(this._camera.matrix,0);_v3A.crossVectors(this._camera.up,_v3A);_v3A.multiplyScalar(distance);this._encloseToBoundary(this._targetEnd,_v3A,this.boundaryFriction);if(!enableTransition){this._target.copy(this._targetEnd)}this._needsUpdate=true};CameraControls.prototype.moveTo=function(x,y,z,enableTransition){if(enableTransition===void 0){enableTransition=false}this._targetEnd.set(x,y,z);if(!enableTransition){this._target.copy(this._targetEnd)}this._needsUpdate=true};CameraControls.prototype.fitToBox=function(box3OrObject,enableTransition,_a){var _b=_a===void 0?{}:_a,_c=_b.paddingLeft,paddingLeft=_c===void 0?0:_c,_d=_b.paddingRight,paddingRight=_d===void 0?0:_d,_e=_b.paddingBottom,paddingBottom=_e===void 0?0:_e,_f=_b.paddingTop,paddingTop=_f===void 0?0:_f;var aabb=box3OrObject.isBox3?_box3A.copy(box3OrObject):_box3A.setFromObject(box3OrObject);if(aabb.isEmpty()){console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting");return}var theta=roundToStep(this._sphericalEnd.theta,PI_HALF);var phi=roundToStep(this._sphericalEnd.phi,PI_HALF);this.rotateTo(theta,phi,enableTransition);var normal=_v3A.setFromSpherical(this._sphericalEnd).normalize();var rotation=_quaternionA.setFromUnitVectors(normal,_AXIS_Z);var viewFromPolar=approxEquals(Math.abs(normal.y),1);if(viewFromPolar){rotation.multiply(_quaternionB.setFromAxisAngle(_AXIS_Y,theta))}var bb=_box3B.makeEmpty();_v3B.copy(aabb.min).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.min).setX(aabb.max.x).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.min).setY(aabb.max.y).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.max).setZ(aabb.min.z).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.min).setZ(aabb.max.z).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.max).setY(aabb.min.y).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.max).setX(aabb.min.x).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.max).applyQuaternion(rotation);bb.expandByPoint(_v3B);rotation.setFromUnitVectors(_AXIS_Z,normal);bb.min.x-=paddingLeft;bb.min.y-=paddingBottom;bb.max.x+=paddingRight;bb.max.y+=paddingTop;var bbSize=bb.getSize(_v3A);var center=bb.getCenter(_v3B).applyQuaternion(rotation);if(isPerspectiveCamera(this._camera)){var distance=this.getDistanceToFitBox(bbSize.x,bbSize.y,bbSize.z);this.moveTo(center.x,center.y,center.z,enableTransition);this.dollyTo(distance,enableTransition);this.setFocalOffset(0,0,0,enableTransition);return}else if(isOrthographicCamera(this._camera)){var camera=this._camera;var width=camera.right-camera.left;var height=camera.top-camera.bottom;var zoom=Math.min(width/bbSize.x,height/bbSize.y);this.moveTo(center.x,center.y,center.z,enableTransition);this.zoomTo(zoom,enableTransition);this.setFocalOffset(0,0,0,enableTransition);return}};CameraControls.prototype.fitTo=function(box3OrObject,enableTransition,fitToOptions){if(fitToOptions===void 0){fitToOptions={}}console.warn("camera-controls: fitTo() has been renamed to fitToBox()");this.fitToBox(box3OrObject,enableTransition,fitToOptions)};CameraControls.prototype.fitToSphere=function(sphereOrMesh,enableTransition){var isSphere=sphereOrMesh instanceof THREE.Sphere;var boundingSphere=isSphere?_sphere.copy(sphereOrMesh):createBoundingSphere(sphereOrMesh,_sphere);this.moveTo(boundingSphere.center.x,boundingSphere.center.y,boundingSphere.center.z,enableTransition);if(isPerspectiveCamera(this._camera)){var distanceToFit=this.getDistanceToFitSphere(boundingSphere.radius);this.dollyTo(distanceToFit,enableTransition)}else if(isOrthographicCamera(this._camera)){var width=this._camera.right-this._camera.left;var height=this._camera.top-this._camera.bottom;var diameter=2*boundingSphere.radius;var zoom=Math.min(width/diameter,height/diameter);this.zoomTo(zoom,enableTransition)}this.setFocalOffset(0,0,0,enableTransition)};CameraControls.prototype.setLookAt=function(positionX,positionY,positionZ,targetX,targetY,targetZ,enableTransition){if(enableTransition===void 0){enableTransition=false}var position=_v3A.set(positionX,positionY,positionZ);var target=_v3B.set(targetX,targetY,targetZ);this._targetEnd.copy(target);this._sphericalEnd.setFromVector3(position.sub(target).applyQuaternion(this._yAxisUpSpace));this.normalizeRotations();if(!enableTransition){this._target.copy(this._targetEnd);this._spherical.copy(this._sphericalEnd)}this._needsUpdate=true};CameraControls.prototype.lerpLookAt=function(positionAX,positionAY,positionAZ,targetAX,targetAY,targetAZ,positionBX,positionBY,positionBZ,targetBX,targetBY,targetBZ,t,enableTransition){if(enableTransition===void 0){enableTransition=false}var positionA=_v3A.set(positionAX,positionAY,positionAZ);var targetA=_v3B.set(targetAX,targetAY,targetAZ);_sphericalA.setFromVector3(positionA.sub(targetA).applyQuaternion(this._yAxisUpSpace));var targetB=_v3A.set(targetBX,targetBY,targetBZ);this._targetEnd.copy(targetA).lerp(targetB,t);var positionB=_v3B.set(positionBX,positionBY,positionBZ);_sphericalB.setFromVector3(positionB.sub(targetB).applyQuaternion(this._yAxisUpSpace));var deltaTheta=_sphericalB.theta-_sphericalA.theta;var deltaPhi=_sphericalB.phi-_sphericalA.phi;var deltaRadius=_sphericalB.radius-_sphericalA.radius;this._sphericalEnd.set(_sphericalA.radius+deltaRadius*t,_sphericalA.phi+deltaPhi*t,_sphericalA.theta+deltaTheta*t);this.normalizeRotations();if(!enableTransition){this._target.copy(this._targetEnd);this._spherical.copy(this._sphericalEnd)}this._needsUpdate=true};CameraControls.prototype.setPosition=function(positionX,positionY,positionZ,enableTransition){if(enableTransition===void 0){enableTransition=false}this.setLookAt(positionX,positionY,positionZ,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,enableTransition)};CameraControls.prototype.setTarget=function(targetX,targetY,targetZ,enableTransition){if(enableTransition===void 0){enableTransition=false}var pos=this.getPosition(_v3A);this.setLookAt(pos.x,pos.y,pos.z,targetX,targetY,targetZ,enableTransition)};CameraControls.prototype.setFocalOffset=function(x,y,z,enableTransition){if(enableTransition===void 0){enableTransition=false}this._focalOffsetEnd.set(x,y,z);if(!enableTransition){this._focalOffset.copy(this._focalOffsetEnd)}this._needsUpdate=true};CameraControls.prototype.setBoundary=function(box3){if(!box3){this._boundary.min.set(-Infinity,-Infinity,-Infinity);this._boundary.max.set(Infinity,Infinity,Infinity);this._needsUpdate=true;return}this._boundary.copy(box3);this._boundary.clampPoint(this._targetEnd,this._targetEnd);this._needsUpdate=true};CameraControls.prototype.setViewport=function(viewportOrX,y,width,height){if(viewportOrX===null){this._viewport=null;return}this._viewport=this._viewport||new THREE.Vector4;if(typeof viewportOrX==="number"){this._viewport.set(viewportOrX,y,width,height)}else{this._viewport.copy(viewportOrX)}};CameraControls.prototype.getDistanceToFitBox=function(width,height,depth){if(notSupportedInOrthographicCamera(this._camera,"getDistanceToFitBox"))return this._spherical.radius;var boundingRectAspect=width/height;var fov=this._camera.getEffectiveFOV()*THREE.MathUtils.DEG2RAD;var aspect=this._camera.aspect;var heightToFit=boundingRectAspect=1;if(!hasCollider)return distance;if(notSupportedInOrthographicCamera(this._camera,"_collisionTest"))return distance;var direction=_v3A.setFromSpherical(this._spherical).divideScalar(this._spherical.radius);_rotationMatrix.lookAt(_ORIGIN,direction,this._camera.up);for(var i=0;i<4;i++){var nearPlaneCorner=_v3B.copy(this._nearPlaneCorners[i]);nearPlaneCorner.applyMatrix4(_rotationMatrix);var origin_1=_v3C.addVectors(this._target,nearPlaneCorner);_raycaster.set(origin_1,direction);_raycaster.far=this._spherical.radius+1;var intersects=_raycaster.intersectObjects(this.colliderMeshes);if(intersects.length!==0&&intersects[0].distance=2;if(isMultiTouch){var dx=_v2.x-_this._activePointers[1].clientX;var dy=_v2.y-_this._activePointers[1].clientY;var distance=Math.sqrt(dx*dx+dy*dy);dollyStart_1.set(0,distance);var x=(_this._activePointers[0].clientX+_this._activePointers[1].clientX)*.5;var y=(_this._activePointers[0].clientY+_this._activePointers[1].clientY)*.5;lastDragPosition_1.set(x,y)}_this.dispatchEvent({type:"controlstart"})};var dragging_1=function(){if(!_this._enabled)return;extractClientCoordFromEvent(_this._activePointers,_v2);var deltaX=lastDragPosition_1.x-_v2.x;var deltaY=lastDragPosition_1.y-_v2.y;lastDragPosition_1.copy(_v2);switch(_this._state){case ACTION.ROTATE:case ACTION.TOUCH_ROTATE:{_this._rotateInternal(deltaX,deltaY);break}case ACTION.DOLLY:case ACTION.ZOOM:{var dollyX=_this.dollyToCursor?(dragStartPosition_1.x-_this._elementRect.x)/_this._elementRect.z*2-1:0;var dollyY=_this.dollyToCursor?(dragStartPosition_1.y-_this._elementRect.y)/_this._elementRect.w*-2+1:0;_this._state===ACTION.DOLLY?_this._dollyInternal(deltaY*TOUCH_DOLLY_FACTOR,dollyX,dollyY):_this._zoomInternal(deltaY*TOUCH_DOLLY_FACTOR,dollyX,dollyY);break}case ACTION.TOUCH_DOLLY:case ACTION.TOUCH_ZOOM:case ACTION.TOUCH_DOLLY_TRUCK:case ACTION.TOUCH_ZOOM_TRUCK:case ACTION.TOUCH_DOLLY_OFFSET:case ACTION.TOUCH_ZOOM_OFFSET:{var dx=_v2.x-_this._activePointers[1].clientX;var dy=_v2.y-_this._activePointers[1].clientY;var distance=Math.sqrt(dx*dx+dy*dy);var dollyDelta=dollyStart_1.y-distance;dollyStart_1.set(0,distance);var dollyX=_this.dollyToCursor?(lastDragPosition_1.x-_this._elementRect.x)/_this._elementRect.z*2-1:0;var dollyY=_this.dollyToCursor?(lastDragPosition_1.y-_this._elementRect.y)/_this._elementRect.w*-2+1:0;_this._state===ACTION.TOUCH_DOLLY||_this._state===ACTION.TOUCH_DOLLY_TRUCK?_this._dollyInternal(dollyDelta*TOUCH_DOLLY_FACTOR,dollyX,dollyY):_this._zoomInternal(dollyDelta*TOUCH_DOLLY_FACTOR,dollyX,dollyY);if(_this._state===ACTION.TOUCH_DOLLY_TRUCK||_this._state===ACTION.TOUCH_ZOOM_TRUCK){_this._truckInternal(deltaX,deltaY,false)}else if(_this._state===ACTION.TOUCH_DOLLY_OFFSET||_this._state===ACTION.TOUCH_ZOOM_OFFSET){_this._truckInternal(deltaX,deltaY,true)}break}case ACTION.TRUCK:case ACTION.TOUCH_TRUCK:{_this._truckInternal(deltaX,deltaY,false);break}case ACTION.OFFSET:case ACTION.TOUCH_OFFSET:{_this._truckInternal(deltaX,deltaY,true);break}}_this.dispatchEvent({type:"control"})};var endDragging_1=function(){extractClientCoordFromEvent(_this._activePointers,_v2);lastDragPosition_1.copy(_v2);if(_this._activePointers.length===0){_this._domElement.ownerDocument.removeEventListener("pointermove",onPointerMove_1,{passive:false});_this._domElement.ownerDocument.removeEventListener("pointerup",onPointerUp_1);_this._domElement.ownerDocument.removeEventListener("touchmove",onTouchMove_1,{passive:false});_this._domElement.ownerDocument.removeEventListener("touchend",onTouchEnd_1)}_this.dispatchEvent({type:"controlend"})};_this._domElement.addEventListener("pointerdown",onPointerDown_1);isPointerEventsNotSupported&&_this._domElement.addEventListener("mousedown",onMouseDown_1);isPointerEventsNotSupported&&_this._domElement.addEventListener("touchstart",onTouchStart_1);_this._domElement.addEventListener("pointercancel",onPointerUp_1);_this._domElement.addEventListener("wheel",onMouseWheel_1,{passive:false});_this._domElement.addEventListener("contextmenu",onContextMenu_1);_this._removeAllEventListeners=function(){_this._domElement.removeEventListener("pointerdown",onPointerDown_1);_this._domElement.removeEventListener("mousedown",onMouseDown_1);_this._domElement.removeEventListener("touchstart",onTouchStart_1);_this._domElement.removeEventListener("pointercancel",onPointerUp_1);_this._domElement.removeEventListener("wheel",onMouseWheel_1,{passive:false});_this._domElement.removeEventListener("contextmenu",onContextMenu_1);_this._domElement.ownerDocument.removeEventListener("pointermove",onPointerMove_1,{passive:false});_this._domElement.ownerDocument.removeEventListener("mousemove",onMouseMove_1);_this._domElement.ownerDocument.removeEventListener("touchmove",onTouchMove_1,{passive:false});_this._domElement.ownerDocument.removeEventListener("pointerup",onPointerUp_1);_this._domElement.ownerDocument.removeEventListener("mouseup",onMouseUp_1);_this._domElement.ownerDocument.removeEventListener("touchend",onTouchEnd_1)};_this.cancel=function(){cancelDragging_1();_this.dispatchEvent({type:"controlend"})}}_this.update(0);return _this}CameraControls.install=function(libs){THREE=libs.THREE;_ORIGIN=Object.freeze(new THREE.Vector3(0,0,0));_AXIS_Y=Object.freeze(new THREE.Vector3(0,1,0));_AXIS_Z=Object.freeze(new THREE.Vector3(0,0,1));_v2=new THREE.Vector2;_v3A=new THREE.Vector3;_v3B=new THREE.Vector3;_v3C=new THREE.Vector3;_xColumn=new THREE.Vector3;_yColumn=new THREE.Vector3;_zColumn=new THREE.Vector3;_sphericalA=new THREE.Spherical;_sphericalB=new THREE.Spherical;_box3A=new THREE.Box3;_box3B=new THREE.Box3;_sphere=new THREE.Sphere;_quaternionA=new THREE.Quaternion;_quaternionB=new THREE.Quaternion;_rotationMatrix=new THREE.Matrix4;_raycaster=new THREE.Raycaster};Object.defineProperty(CameraControls,"ACTION",{get:function(){return readonlyACTION},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"camera",{get:function(){return this._camera},set:function(camera){this._camera=camera;this.updateCameraUp();this._camera.updateProjectionMatrix();this._updateNearPlaneCorners();this._needsUpdate=true},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"enabled",{get:function(){return this._enabled},set:function(enabled){this._enabled=enabled;if(!enabled)this.cancel()},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"currentAction",{get:function(){return this._state},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"distance",{get:function(){return this._spherical.radius},set:function(distance){if(this._spherical.radius===distance&&this._sphericalEnd.radius===distance)return;this._spherical.radius=distance;this._sphericalEnd.radius=distance;this._needsUpdate=true},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"azimuthAngle",{get:function(){return this._spherical.theta},set:function(azimuthAngle){if(this._spherical.theta===azimuthAngle&&this._sphericalEnd.theta===azimuthAngle)return;this._spherical.theta=azimuthAngle;this._sphericalEnd.theta=azimuthAngle;this._needsUpdate=true},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"polarAngle",{get:function(){return this._spherical.phi},set:function(polarAngle){if(this._spherical.phi===polarAngle&&this._sphericalEnd.phi===polarAngle)return;this._spherical.phi=polarAngle;this._sphericalEnd.phi=polarAngle;this._needsUpdate=true},enumerable:false,configurable:true});Object.defineProperty(CameraControls.prototype,"boundaryEnclosesCamera",{get:function(){return this._boundaryEnclosesCamera},set:function(boundaryEnclosesCamera){this._boundaryEnclosesCamera=boundaryEnclosesCamera;this._needsUpdate=true},enumerable:false,configurable:true});CameraControls.prototype.addEventListener=function(type,listener){_super.prototype.addEventListener.call(this,type,listener)};CameraControls.prototype.removeEventListener=function(type,listener){_super.prototype.removeEventListener.call(this,type,listener)};CameraControls.prototype.rotate=function(azimuthAngle,polarAngle,enableTransition){if(enableTransition===void 0){enableTransition=false}this.rotateTo(this._sphericalEnd.theta+azimuthAngle,this._sphericalEnd.phi+polarAngle,enableTransition)};CameraControls.prototype.rotateAzimuthTo=function(azimuthAngle,enableTransition){if(enableTransition===void 0){enableTransition=false}this.rotateTo(this._sphericalEnd.theta+azimuthAngle,this._sphericalEnd.phi,enableTransition)};CameraControls.prototype.rotatePolarTo=function(polarAngle,enableTransition){if(enableTransition===void 0){enableTransition=false}this.rotateTo(this._sphericalEnd.theta,this._sphericalEnd.phi+polarAngle,enableTransition)};CameraControls.prototype.rotateTo=function(azimuthAngle,polarAngle,enableTransition){if(enableTransition===void 0){enableTransition=false}var theta=THREE.MathUtils.clamp(azimuthAngle,this.minAzimuthAngle,this.maxAzimuthAngle);var phi=THREE.MathUtils.clamp(polarAngle,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=theta;this._sphericalEnd.phi=phi;this._sphericalEnd.makeSafe();if(!enableTransition){this._spherical.theta=this._sphericalEnd.theta;this._spherical.phi=this._sphericalEnd.phi}this._needsUpdate=true};CameraControls.prototype.dolly=function(distance,enableTransition){if(enableTransition===void 0){enableTransition=false}this.dollyTo(this._sphericalEnd.radius-distance,enableTransition)};CameraControls.prototype.dollyTo=function(distance,enableTransition){if(enableTransition===void 0){enableTransition=false}var lastRadius=this._sphericalEnd.radius;var newRadius=THREE.MathUtils.clamp(distance,this.minDistance,this.maxDistance);var hasCollider=this.colliderMeshes.length>=1;if(hasCollider){var maxDistanceByCollisionTest=this._collisionTest();var isCollided=approxEquals(maxDistanceByCollisionTest,this._spherical.radius);var isDollyIn=lastRadius>newRadius;if(!isDollyIn&&isCollided)return;this._sphericalEnd.radius=Math.min(newRadius,maxDistanceByCollisionTest)}else{this._sphericalEnd.radius=newRadius}if(!enableTransition){this._spherical.radius=this._sphericalEnd.radius}this._needsUpdate=true};CameraControls.prototype.zoom=function(zoomStep,enableTransition){if(enableTransition===void 0){enableTransition=false}this.zoomTo(this._zoomEnd+zoomStep,enableTransition)};CameraControls.prototype.zoomTo=function(zoom,enableTransition){if(enableTransition===void 0){enableTransition=false}this._zoomEnd=THREE.MathUtils.clamp(zoom,this.minZoom,this.maxZoom);if(!enableTransition){this._zoom=this._zoomEnd}this._needsUpdate=true};CameraControls.prototype.pan=function(x,y,enableTransition){if(enableTransition===void 0){enableTransition=false}console.log("`pan` has been renamed to `truck`");this.truck(x,y,enableTransition)};CameraControls.prototype.truck=function(x,y,enableTransition){if(enableTransition===void 0){enableTransition=false}this._camera.updateMatrix();_xColumn.setFromMatrixColumn(this._camera.matrix,0);_yColumn.setFromMatrixColumn(this._camera.matrix,1);_xColumn.multiplyScalar(x);_yColumn.multiplyScalar(-y);var offset=_v3A.copy(_xColumn).add(_yColumn);this._encloseToBoundary(this._targetEnd,offset,this.boundaryFriction);if(!enableTransition){this._target.copy(this._targetEnd)}this._needsUpdate=true};CameraControls.prototype.forward=function(distance,enableTransition){if(enableTransition===void 0){enableTransition=false}_v3A.setFromMatrixColumn(this._camera.matrix,0);_v3A.crossVectors(this._camera.up,_v3A);_v3A.multiplyScalar(distance);this._encloseToBoundary(this._targetEnd,_v3A,this.boundaryFriction);if(!enableTransition){this._target.copy(this._targetEnd)}this._needsUpdate=true};CameraControls.prototype.moveTo=function(x,y,z,enableTransition){if(enableTransition===void 0){enableTransition=false}this._targetEnd.set(x,y,z);if(!enableTransition){this._target.copy(this._targetEnd)}this._needsUpdate=true};CameraControls.prototype.fitToBox=function(box3OrObject,enableTransition,_a){var _b=_a===void 0?{}:_a,_c=_b.paddingLeft,paddingLeft=_c===void 0?0:_c,_d=_b.paddingRight,paddingRight=_d===void 0?0:_d,_e=_b.paddingBottom,paddingBottom=_e===void 0?0:_e,_f=_b.paddingTop,paddingTop=_f===void 0?0:_f;var aabb=box3OrObject.isBox3?_box3A.copy(box3OrObject):_box3A.setFromObject(box3OrObject);if(aabb.isEmpty()){console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting");return}var theta=roundToStep(this._sphericalEnd.theta,PI_HALF);var phi=roundToStep(this._sphericalEnd.phi,PI_HALF);this.rotateTo(theta,phi,enableTransition);var normal=_v3A.setFromSpherical(this._sphericalEnd).normalize();var rotation=_quaternionA.setFromUnitVectors(normal,_AXIS_Z);var viewFromPolar=approxEquals(Math.abs(normal.y),1);if(viewFromPolar){rotation.multiply(_quaternionB.setFromAxisAngle(_AXIS_Y,theta))}var bb=_box3B.makeEmpty();_v3B.copy(aabb.min).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.min).setX(aabb.max.x).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.min).setY(aabb.max.y).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.max).setZ(aabb.min.z).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.min).setZ(aabb.max.z).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.max).setY(aabb.min.y).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.max).setX(aabb.min.x).applyQuaternion(rotation);bb.expandByPoint(_v3B);_v3B.copy(aabb.max).applyQuaternion(rotation);bb.expandByPoint(_v3B);rotation.setFromUnitVectors(_AXIS_Z,normal);bb.min.x-=paddingLeft;bb.min.y-=paddingBottom;bb.max.x+=paddingRight;bb.max.y+=paddingTop;var bbSize=bb.getSize(_v3A);var center=bb.getCenter(_v3B).applyQuaternion(rotation);if(isPerspectiveCamera(this._camera)){var distance=this.getDistanceToFitBox(bbSize.x,bbSize.y,bbSize.z);this.moveTo(center.x,center.y,center.z,enableTransition);this.dollyTo(distance,enableTransition);this.setFocalOffset(0,0,0,enableTransition);return}else if(isOrthographicCamera(this._camera)){var camera=this._camera;var width=camera.right-camera.left;var height=camera.top-camera.bottom;var zoom=Math.min(width/bbSize.x,height/bbSize.y);this.moveTo(center.x,center.y,center.z,enableTransition);this.zoomTo(zoom,enableTransition);this.setFocalOffset(0,0,0,enableTransition);return}};CameraControls.prototype.fitTo=function(box3OrObject,enableTransition,fitToOptions){if(fitToOptions===void 0){fitToOptions={}}console.warn("camera-controls: fitTo() has been renamed to fitToBox()");this.fitToBox(box3OrObject,enableTransition,fitToOptions)};CameraControls.prototype.fitToSphere=function(sphereOrMesh,enableTransition){var isSphere=sphereOrMesh instanceof THREE.Sphere;var boundingSphere=isSphere?_sphere.copy(sphereOrMesh):createBoundingSphere(sphereOrMesh,_sphere);this.moveTo(boundingSphere.center.x,boundingSphere.center.y,boundingSphere.center.z,enableTransition);if(isPerspectiveCamera(this._camera)){var distanceToFit=this.getDistanceToFitSphere(boundingSphere.radius);this.dollyTo(distanceToFit,enableTransition)}else if(isOrthographicCamera(this._camera)){var width=this._camera.right-this._camera.left;var height=this._camera.top-this._camera.bottom;var diameter=2*boundingSphere.radius;var zoom=Math.min(width/diameter,height/diameter);this.zoomTo(zoom,enableTransition)}this.setFocalOffset(0,0,0,enableTransition)};CameraControls.prototype.setLookAt=function(positionX,positionY,positionZ,targetX,targetY,targetZ,enableTransition){if(enableTransition===void 0){enableTransition=false}var position=_v3A.set(positionX,positionY,positionZ);var target=_v3B.set(targetX,targetY,targetZ);this._targetEnd.copy(target);this._sphericalEnd.setFromVector3(position.sub(target).applyQuaternion(this._yAxisUpSpace));this.normalizeRotations();if(!enableTransition){this._target.copy(this._targetEnd);this._spherical.copy(this._sphericalEnd)}this._needsUpdate=true};CameraControls.prototype.lerpLookAt=function(positionAX,positionAY,positionAZ,targetAX,targetAY,targetAZ,positionBX,positionBY,positionBZ,targetBX,targetBY,targetBZ,t,enableTransition){if(enableTransition===void 0){enableTransition=false}var positionA=_v3A.set(positionAX,positionAY,positionAZ);var targetA=_v3B.set(targetAX,targetAY,targetAZ);_sphericalA.setFromVector3(positionA.sub(targetA).applyQuaternion(this._yAxisUpSpace));var targetB=_v3A.set(targetBX,targetBY,targetBZ);this._targetEnd.copy(targetA).lerp(targetB,t);var positionB=_v3B.set(positionBX,positionBY,positionBZ);_sphericalB.setFromVector3(positionB.sub(targetB).applyQuaternion(this._yAxisUpSpace));var deltaTheta=_sphericalB.theta-_sphericalA.theta;var deltaPhi=_sphericalB.phi-_sphericalA.phi;var deltaRadius=_sphericalB.radius-_sphericalA.radius;this._sphericalEnd.set(_sphericalA.radius+deltaRadius*t,_sphericalA.phi+deltaPhi*t,_sphericalA.theta+deltaTheta*t);this.normalizeRotations();if(!enableTransition){this._target.copy(this._targetEnd);this._spherical.copy(this._sphericalEnd)}this._needsUpdate=true};CameraControls.prototype.setPosition=function(positionX,positionY,positionZ,enableTransition){if(enableTransition===void 0){enableTransition=false}this.setLookAt(positionX,positionY,positionZ,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,enableTransition)};CameraControls.prototype.setTarget=function(targetX,targetY,targetZ,enableTransition){if(enableTransition===void 0){enableTransition=false}var pos=this.getPosition(_v3A);this.setLookAt(pos.x,pos.y,pos.z,targetX,targetY,targetZ,enableTransition)};CameraControls.prototype.setFocalOffset=function(x,y,z,enableTransition){if(enableTransition===void 0){enableTransition=false}this._focalOffsetEnd.set(x,y,z);if(!enableTransition){this._focalOffset.copy(this._focalOffsetEnd)}this._needsUpdate=true};CameraControls.prototype.setBoundary=function(box3){if(!box3){this._boundary.min.set(-Infinity,-Infinity,-Infinity);this._boundary.max.set(Infinity,Infinity,Infinity);this._needsUpdate=true;return}this._boundary.copy(box3);this._boundary.clampPoint(this._targetEnd,this._targetEnd);this._needsUpdate=true};CameraControls.prototype.setViewport=function(viewportOrX,y,width,height){if(viewportOrX===null){this._viewport=null;return}this._viewport=this._viewport||new THREE.Vector4;if(typeof viewportOrX==="number"){this._viewport.set(viewportOrX,y,width,height)}else{this._viewport.copy(viewportOrX)}};CameraControls.prototype.getDistanceToFitBox=function(width,height,depth){if(notSupportedInOrthographicCamera(this._camera,"getDistanceToFitBox"))return this._spherical.radius;var boundingRectAspect=width/height;var fov=this._camera.getEffectiveFOV()*THREE.MathUtils.DEG2RAD;var aspect=this._camera.aspect;var heightToFit=boundingRectAspect=1;if(!hasCollider)return distance;if(notSupportedInOrthographicCamera(this._camera,"_collisionTest"))return distance;var direction=_v3A.setFromSpherical(this._spherical).divideScalar(this._spherical.radius);_rotationMatrix.lookAt(_ORIGIN,direction,this._camera.up);for(var i=0;i<4;i++){var nearPlaneCorner=_v3B.copy(this._nearPlaneCorners[i]);nearPlaneCorner.applyMatrix4(_rotationMatrix);var origin_1=_v3C.addVectors(this._target,nearPlaneCorner);_raycaster.set(origin_1,direction);_raycaster.far=this._spherical.radius+1;var intersects=_raycaster.intersectObjects(this.colliderMeshes);if(intersects.length!==0&&intersects[0].distance