@2112-lab/central-plant 0.1.4 → 0.1.6

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.
Files changed (88) hide show
  1. package/dist/bundle/index.js +33146 -1
  2. package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +432 -1
  3. package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1448 -1
  4. package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1853 -1
  5. package/dist/cjs/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3537 -1
  6. package/dist/cjs/node_modules/three/examples/jsm/exporters/OBJExporter.js +305 -1
  7. package/dist/cjs/node_modules/three/examples/jsm/exporters/PLYExporter.js +542 -1
  8. package/dist/cjs/node_modules/three/examples/jsm/exporters/STLExporter.js +218 -1
  9. package/dist/cjs/node_modules/three/examples/jsm/loaders/DRACOLoader.js +683 -1
  10. package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4811 -1
  11. package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +480 -1
  12. package/dist/cjs/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +309 -1
  13. package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +120 -1
  14. package/dist/cjs/src/analysis/analysis.js +560 -1
  15. package/dist/cjs/src/analysis/testing.js +958 -1
  16. package/dist/cjs/src/core/centralPlant.js +1149 -1
  17. package/dist/cjs/src/core/debugLogger.js +175 -1
  18. package/dist/cjs/src/core/mathUtils.js +574 -1
  19. package/dist/cjs/src/core/nameUtils.js +93 -1
  20. package/dist/cjs/src/data/export.js +716 -1
  21. package/dist/cjs/src/data/import.js +380 -1
  22. package/dist/cjs/src/data/numerics.js +522 -1
  23. package/dist/cjs/src/helpers/sceneHelper.js +572 -1
  24. package/dist/cjs/src/index.js +69 -1
  25. package/dist/cjs/src/managers/components/animationManager.js +123 -1
  26. package/dist/cjs/src/managers/components/componentManager.js +332 -1
  27. package/dist/cjs/src/managers/components/pathfindingManager.js +1441 -1
  28. package/dist/cjs/src/managers/controls/TransformControls.js +1063 -1
  29. package/dist/cjs/src/managers/controls/cameraControlsManager.js +79 -1
  30. package/dist/cjs/src/managers/controls/dragDropManager.js +1026 -1
  31. package/dist/cjs/src/managers/controls/keyboardControlsManager.js +395 -1
  32. package/dist/cjs/src/managers/controls/transformControlsManager.js +1807 -1
  33. package/dist/cjs/src/managers/environment/environmentManager.js +714 -1
  34. package/dist/cjs/src/managers/environment/textureConfig.js +229 -1
  35. package/dist/cjs/src/managers/scene/sceneExportManager.js +264 -1
  36. package/dist/cjs/src/managers/scene/sceneInitializationManager.js +346 -1
  37. package/dist/cjs/src/managers/scene/sceneOperationsManager.js +1509 -1
  38. package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +661 -1
  39. package/dist/cjs/src/managers/system/disposalManager.js +444 -1
  40. package/dist/cjs/src/managers/system/hotReloadManager.js +291 -1
  41. package/dist/cjs/src/managers/system/performanceMonitor.js +863 -1
  42. package/dist/cjs/src/rendering/modelPreloader.js +369 -1
  43. package/dist/cjs/src/rendering/rendering2D.js +631 -1
  44. package/dist/cjs/src/rendering/rendering3D.js +685 -1
  45. package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +396 -1
  46. package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1444 -1
  47. package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1849 -1
  48. package/dist/esm/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3533 -1
  49. package/dist/esm/node_modules/three/examples/jsm/exporters/OBJExporter.js +301 -1
  50. package/dist/esm/node_modules/three/examples/jsm/exporters/PLYExporter.js +538 -1
  51. package/dist/esm/node_modules/three/examples/jsm/exporters/STLExporter.js +214 -1
  52. package/dist/esm/node_modules/three/examples/jsm/loaders/DRACOLoader.js +679 -1
  53. package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4807 -1
  54. package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +476 -1
  55. package/dist/esm/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +304 -1
  56. package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +116 -1
  57. package/dist/esm/src/analysis/analysis.js +536 -1
  58. package/dist/esm/src/analysis/testing.js +954 -1
  59. package/dist/esm/src/core/centralPlant.js +1144 -1
  60. package/dist/esm/src/core/debugLogger.js +167 -1
  61. package/dist/esm/src/core/mathUtils.js +570 -1
  62. package/dist/esm/src/core/nameUtils.js +87 -1
  63. package/dist/esm/src/data/export.js +712 -1
  64. package/dist/esm/src/data/import.js +356 -1
  65. package/dist/esm/src/data/numerics.js +518 -1
  66. package/dist/esm/src/helpers/sceneHelper.js +547 -1
  67. package/dist/esm/src/index.js +35 -1
  68. package/dist/esm/src/managers/components/animationManager.js +119 -1
  69. package/dist/esm/src/managers/components/componentManager.js +328 -1
  70. package/dist/esm/src/managers/components/pathfindingManager.js +1417 -1
  71. package/dist/esm/src/managers/controls/TransformControls.js +1057 -1
  72. package/dist/esm/src/managers/controls/cameraControlsManager.js +75 -1
  73. package/dist/esm/src/managers/controls/dragDropManager.js +1002 -1
  74. package/dist/esm/src/managers/controls/keyboardControlsManager.js +371 -1
  75. package/dist/esm/src/managers/controls/transformControlsManager.js +1782 -1
  76. package/dist/esm/src/managers/environment/environmentManager.js +690 -1
  77. package/dist/esm/src/managers/environment/textureConfig.js +202 -1
  78. package/dist/esm/src/managers/scene/sceneExportManager.js +260 -1
  79. package/dist/esm/src/managers/scene/sceneInitializationManager.js +322 -1
  80. package/dist/esm/src/managers/scene/sceneOperationsManager.js +1485 -1
  81. package/dist/esm/src/managers/scene/sceneTooltipsManager.js +637 -1
  82. package/dist/esm/src/managers/system/disposalManager.js +440 -1
  83. package/dist/esm/src/managers/system/hotReloadManager.js +287 -1
  84. package/dist/esm/src/managers/system/performanceMonitor.js +858 -1
  85. package/dist/esm/src/rendering/modelPreloader.js +364 -1
  86. package/dist/esm/src/rendering/rendering2D.js +627 -1
  87. package/dist/esm/src/rendering/rendering3D.js +661 -1
  88. package/package.json +1 -1
@@ -1 +1,1849 @@
1
- import{Ray as t,Plane as s,MathUtils as i,Vector3 as h,Controls as e,MOUSE as n,TOUCH as a,Quaternion as o,Spherical as r,Vector2 as c}from"three";const l={type:"change"},u={type:"start"},f={type:"end"},w=new t,d=new s,p=Math.cos(70*i.DEG2RAD),M=new h,_=2*Math.PI,k=-1,b=0,v=1,y=2,T=3,D=4,P=5,g=6,m=1e-6;class R extends e{constructor(t,s=null){super(t,s),this.state=k,this.target=new h,this.cursor=new h,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:n.ROTATE,MIDDLE:n.DOLLY,RIGHT:n.PAN},this.touches={ONE:a.ROTATE,TWO:a.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this.t=null,this.i=new h,this.h=new o,this.o=new h,this.l=(new o).setFromUnitVectors(t.up,new h(0,1,0)),this.u=this.l.clone().invert(),this.p=new r,this.M=new r,this._=1,this.k=new h,this.v=new c,this.T=new c,this.D=new c,this.P=new c,this.m=new c,this.R=new c,this.A=new c,this.S=new c,this.L=new c,this.I=new h,this.O=new c,this.F=!1,this.U=[],this.K={},this.W=!1,this.Y=S.bind(this),this.C=A.bind(this),this.G=E.bind(this),this.H=K.bind(this),this.X=O.bind(this),this.Z=x.bind(this),this.B=F.bind(this),this.N=U.bind(this),this.j=L.bind(this),this.q=I.bind(this),this.J=W.bind(this),this.V=Y.bind(this),null!==this.domElement&&this.connect(this.domElement),this.update()}connect(t){super.connect(t),this.domElement.addEventListener("pointerdown",this.C),this.domElement.addEventListener("pointercancel",this.G),this.domElement.addEventListener("contextmenu",this.H),this.domElement.addEventListener("wheel",this.X,{passive:!1});this.domElement.getRootNode().addEventListener("keydown",this.J,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this.C),this.domElement.removeEventListener("pointermove",this.Y),this.domElement.removeEventListener("pointerup",this.G),this.domElement.removeEventListener("pointercancel",this.G),this.domElement.removeEventListener("wheel",this.X),this.domElement.removeEventListener("contextmenu",this.H),this.stopListenToKeyEvents();this.domElement.getRootNode().removeEventListener("keydown",this.J,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this.p.phi}getAzimuthalAngle(){return this.p.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(t){t.addEventListener("keydown",this.Z),this.t=t}stopListenToKeyEvents(){null!==this.t&&(this.t.removeEventListener("keydown",this.Z),this.t=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(l),this.update(),this.state=k}update(t=null){const s=this.object.position;M.copy(s).sub(this.target),M.applyQuaternion(this.l),this.p.setFromVector3(M),this.autoRotate&&this.state===k&&this.$(this.tt(t)),this.enableDamping?(this.p.theta+=this.M.theta*this.dampingFactor,this.p.phi+=this.M.phi*this.dampingFactor):(this.p.theta+=this.M.theta,this.p.phi+=this.M.phi);let i=this.minAzimuthAngle,e=this.maxAzimuthAngle;isFinite(i)&&isFinite(e)&&(i<-Math.PI?i+=_:i>Math.PI&&(i-=_),e<-Math.PI?e+=_:e>Math.PI&&(e-=_),this.p.theta=i<=e?Math.max(i,Math.min(e,this.p.theta)):this.p.theta>(i+e)/2?Math.max(i,this.p.theta):Math.min(e,this.p.theta)),this.p.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this.p.phi)),this.p.makeSafe(),!0===this.enableDamping?this.target.addScaledVector(this.k,this.dampingFactor):this.target.add(this.k),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let n=!1;if(this.zoomToCursor&&this.F||this.object.isOrthographicCamera)this.p.radius=this.st(this.p.radius);else{const t=this.p.radius;this.p.radius=this.st(this.p.radius*this._),n=t!=this.p.radius}if(M.setFromSpherical(this.p),M.applyQuaternion(this.u),s.copy(this.target).add(M),this.object.lookAt(this.target),!0===this.enableDamping?(this.M.theta*=1-this.dampingFactor,this.M.phi*=1-this.dampingFactor,this.k.multiplyScalar(1-this.dampingFactor)):(this.M.set(0,0,0),this.k.set(0,0,0)),this.zoomToCursor&&this.F){let t=null;if(this.object.isPerspectiveCamera){const s=M.length();t=this.st(s*this._);const i=s-t;this.object.position.addScaledVector(this.I,i),this.object.updateMatrixWorld(),n=!!i}else if(this.object.isOrthographicCamera){const s=new h(this.O.x,this.O.y,0);s.unproject(this.object);const i=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._)),this.object.updateProjectionMatrix(),n=i!==this.object.zoom;const e=new h(this.O.x,this.O.y,0);e.unproject(this.object),this.object.position.sub(e).add(s),this.object.updateMatrixWorld(),t=M.length()}else this.zoomToCursor=!1;null!==t&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(t).add(this.object.position):(w.origin.copy(this.object.position),w.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(w.direction))<p?this.object.lookAt(this.target):(d.setFromNormalAndCoplanarPoint(this.object.up,this.target),w.intersectPlane(d,this.target))))}else if(this.object.isOrthographicCamera){const t=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._)),t!==this.object.zoom&&(this.object.updateProjectionMatrix(),n=!0)}return this._=1,this.F=!1,!!(n||this.i.distanceToSquared(this.object.position)>m||8*(1-this.h.dot(this.object.quaternion))>m||this.o.distanceToSquared(this.target)>m)&&(this.dispatchEvent(l),this.i.copy(this.object.position),this.h.copy(this.object.quaternion),this.o.copy(this.target),!0)}tt(t){return null!==t?_/60*this.autoRotateSpeed*t:_/60/60*this.autoRotateSpeed}it(t){const s=Math.abs(.01*t);return Math.pow(.95,this.zoomSpeed*s)}$(t){this.M.theta-=t}ht(t){this.M.phi-=t}et(t,s){M.setFromMatrixColumn(s,0),M.multiplyScalar(-t),this.k.add(M)}nt(t,s){!0===this.screenSpacePanning?M.setFromMatrixColumn(s,1):(M.setFromMatrixColumn(s,0),M.crossVectors(this.object.up,M)),M.multiplyScalar(t),this.k.add(M)}ot(t,s){const i=this.domElement;if(this.object.isPerspectiveCamera){const h=this.object.position;M.copy(h).sub(this.target);let e=M.length();e*=Math.tan(this.object.fov/2*Math.PI/180),this.et(2*t*e/i.clientHeight,this.object.matrix),this.nt(2*s*e/i.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this.et(t*(this.object.right-this.object.left)/this.object.zoom/i.clientWidth,this.object.matrix),this.nt(s*(this.object.top-this.object.bottom)/this.object.zoom/i.clientHeight,this.object.matrix)):this.enablePan=!1}rt(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._/=t:this.enableZoom=!1}ct(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._*=t:this.enableZoom=!1}lt(t,s){if(!this.zoomToCursor)return;this.F=!0;const i=this.domElement.getBoundingClientRect(),h=t-i.left,e=s-i.top,n=i.width,a=i.height;this.O.x=h/n*2-1,this.O.y=-e/a*2+1,this.I.set(this.O.x,this.O.y,1).unproject(this.object).sub(this.object.position).normalize()}st(t){return Math.max(this.minDistance,Math.min(this.maxDistance,t))}ut(t){this.v.set(t.clientX,t.clientY)}ft(t){this.lt(t.clientX,t.clientX),this.A.set(t.clientX,t.clientY)}wt(t){this.P.set(t.clientX,t.clientY)}dt(t){this.T.set(t.clientX,t.clientY),this.D.subVectors(this.T,this.v).multiplyScalar(this.rotateSpeed);const s=this.domElement;this.$(_*this.D.x/s.clientHeight),this.ht(_*this.D.y/s.clientHeight),this.v.copy(this.T),this.update()}Mt(t){this.S.set(t.clientX,t.clientY),this.L.subVectors(this.S,this.A),this.L.y>0?this.rt(this.it(this.L.y)):this.L.y<0&&this.ct(this.it(this.L.y)),this.A.copy(this.S),this.update()}_t(t){this.m.set(t.clientX,t.clientY),this.R.subVectors(this.m,this.P).multiplyScalar(this.panSpeed),this.ot(this.R.x,this.R.y),this.P.copy(this.m),this.update()}kt(t){this.lt(t.clientX,t.clientY),t.deltaY<0?this.ct(this.it(t.deltaY)):t.deltaY>0&&this.rt(this.it(t.deltaY)),this.update()}bt(t){let s=!1;switch(t.code){case this.keys.UP:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this.ht(_*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this.ot(0,this.keyPanSpeed),s=!0;break;case this.keys.BOTTOM:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this.ht(-_*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this.ot(0,-this.keyPanSpeed),s=!0;break;case this.keys.LEFT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this.$(_*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this.ot(this.keyPanSpeed,0),s=!0;break;case this.keys.RIGHT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this.$(-_*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this.ot(-this.keyPanSpeed,0),s=!0}s&&(t.preventDefault(),this.update())}vt(t){if(1===this.U.length)this.v.set(t.pageX,t.pageY);else{const s=this.yt(t),i=.5*(t.pageX+s.x),h=.5*(t.pageY+s.y);this.v.set(i,h)}}Tt(t){if(1===this.U.length)this.P.set(t.pageX,t.pageY);else{const s=this.yt(t),i=.5*(t.pageX+s.x),h=.5*(t.pageY+s.y);this.P.set(i,h)}}Dt(t){const s=this.yt(t),i=t.pageX-s.x,h=t.pageY-s.y,e=Math.sqrt(i*i+h*h);this.A.set(0,e)}Pt(t){this.enableZoom&&this.Dt(t),this.enablePan&&this.Tt(t)}gt(t){this.enableZoom&&this.Dt(t),this.enableRotate&&this.vt(t)}Rt(t){if(1==this.U.length)this.T.set(t.pageX,t.pageY);else{const s=this.yt(t),i=.5*(t.pageX+s.x),h=.5*(t.pageY+s.y);this.T.set(i,h)}this.D.subVectors(this.T,this.v).multiplyScalar(this.rotateSpeed);const s=this.domElement;this.$(_*this.D.x/s.clientHeight),this.ht(_*this.D.y/s.clientHeight),this.v.copy(this.T)}At(t){if(1===this.U.length)this.m.set(t.pageX,t.pageY);else{const s=this.yt(t),i=.5*(t.pageX+s.x),h=.5*(t.pageY+s.y);this.m.set(i,h)}this.R.subVectors(this.m,this.P).multiplyScalar(this.panSpeed),this.ot(this.R.x,this.R.y),this.P.copy(this.m)}St(t){const s=this.yt(t),i=t.pageX-s.x,h=t.pageY-s.y,e=Math.sqrt(i*i+h*h);this.S.set(0,e),this.L.set(0,Math.pow(this.S.y/this.A.y,this.zoomSpeed)),this.rt(this.L.y),this.A.copy(this.S);const n=.5*(t.pageX+s.x),a=.5*(t.pageY+s.y);this.lt(n,a)}Et(t){this.enableZoom&&this.St(t),this.enablePan&&this.At(t)}Lt(t){this.enableZoom&&this.St(t),this.enableRotate&&this.Rt(t)}It(t){this.U.push(t.pointerId)}Ot(t){delete this.K[t.pointerId];for(let s=0;s<this.U.length;s++)if(this.U[s]==t.pointerId)return void this.U.splice(s,1)}xt(t){for(let s=0;s<this.U.length;s++)if(this.U[s]==t.pointerId)return!0;return!1}Ft(t){let s=this.K[t.pointerId];void 0===s&&(s=new c,this.K[t.pointerId]=s),s.set(t.pageX,t.pageY)}yt(t){const s=t.pointerId===this.U[0]?this.U[1]:this.U[0];return this.K[s]}Ut(t){const s=t.deltaMode,i={clientX:t.clientX,clientY:t.clientY,deltaY:t.deltaY};switch(s){case 1:i.deltaY*=16;break;case 2:i.deltaY*=100}return t.ctrlKey&&!this.W&&(i.deltaY*=10),i}}function A(t){!1!==this.enabled&&(0===this.U.length&&(this.domElement.setPointerCapture(t.pointerId),this.domElement.addEventListener("pointermove",this.Y),this.domElement.addEventListener("pointerup",this.G)),this.xt(t)||(this.It(t),"touch"===t.pointerType?this.B(t):this.j(t)))}function S(t){!1!==this.enabled&&("touch"===t.pointerType?this.N(t):this.q(t))}function E(t){switch(this.Ot(t),this.U.length){case 0:this.domElement.releasePointerCapture(t.pointerId),this.domElement.removeEventListener("pointermove",this.Y),this.domElement.removeEventListener("pointerup",this.G),this.dispatchEvent(f),this.state=k;break;case 1:const s=this.U[0],i=this.K[s];this.B({pointerId:s,pageX:i.x,pageY:i.y})}}function L(t){let s;switch(t.button){case 0:s=this.mouseButtons.LEFT;break;case 1:s=this.mouseButtons.MIDDLE;break;case 2:s=this.mouseButtons.RIGHT;break;default:s=-1}switch(s){case n.DOLLY:if(!1===this.enableZoom)return;this.ft(t),this.state=v;break;case n.ROTATE:if(t.ctrlKey||t.metaKey||t.shiftKey){if(!1===this.enablePan)return;this.wt(t),this.state=y}else{if(!1===this.enableRotate)return;this.ut(t),this.state=b}break;case n.PAN:if(t.ctrlKey||t.metaKey||t.shiftKey){if(!1===this.enableRotate)return;this.ut(t),this.state=b}else{if(!1===this.enablePan)return;this.wt(t),this.state=y}break;default:this.state=k}this.state!==k&&this.dispatchEvent(u)}function I(t){switch(this.state){case b:if(!1===this.enableRotate)return;this.dt(t);break;case v:if(!1===this.enableZoom)return;this.Mt(t);break;case y:if(!1===this.enablePan)return;this._t(t)}}function O(t){!1!==this.enabled&&!1!==this.enableZoom&&this.state===k&&(t.preventDefault(),this.dispatchEvent(u),this.kt(this.Ut(t)),this.dispatchEvent(f))}function x(t){!1!==this.enabled&&this.bt(t)}function F(t){switch(this.Ft(t),this.U.length){case 1:switch(this.touches.ONE){case a.ROTATE:if(!1===this.enableRotate)return;this.vt(t),this.state=T;break;case a.PAN:if(!1===this.enablePan)return;this.Tt(t),this.state=D;break;default:this.state=k}break;case 2:switch(this.touches.TWO){case a.DOLLY_PAN:if(!1===this.enableZoom&&!1===this.enablePan)return;this.Pt(t),this.state=P;break;case a.DOLLY_ROTATE:if(!1===this.enableZoom&&!1===this.enableRotate)return;this.gt(t),this.state=g;break;default:this.state=k}break;default:this.state=k}this.state!==k&&this.dispatchEvent(u)}function U(t){switch(this.Ft(t),this.state){case T:if(!1===this.enableRotate)return;this.Rt(t),this.update();break;case D:if(!1===this.enablePan)return;this.At(t),this.update();break;case P:if(!1===this.enableZoom&&!1===this.enablePan)return;this.Et(t),this.update();break;case g:if(!1===this.enableZoom&&!1===this.enableRotate)return;this.Lt(t),this.update();break;default:this.state=k}}function K(t){!1!==this.enabled&&t.preventDefault()}function W(t){if("Control"===t.key){this.W=!0;this.domElement.getRootNode().addEventListener("keyup",this.V,{passive:!0,capture:!0})}}function Y(t){if("Control"===t.key){this.W=!1;this.domElement.getRootNode().removeEventListener("keyup",this.V,{passive:!0,capture:!0})}}export{R as OrbitControls};
1
+ import { Ray, Plane, MathUtils, Vector3, Controls, MOUSE, TOUCH, Quaternion, Spherical, Vector2 } from 'three';
2
+
3
+ /**
4
+ * Fires when the camera has been transformed by the controls.
5
+ *
6
+ * @event OrbitControls#change
7
+ * @type {Object}
8
+ */
9
+ const _changeEvent = { type: 'change' };
10
+
11
+ /**
12
+ * Fires when an interaction was initiated.
13
+ *
14
+ * @event OrbitControls#start
15
+ * @type {Object}
16
+ */
17
+ const _startEvent = { type: 'start' };
18
+
19
+ /**
20
+ * Fires when an interaction has finished.
21
+ *
22
+ * @event OrbitControls#end
23
+ * @type {Object}
24
+ */
25
+ const _endEvent = { type: 'end' };
26
+
27
+ const _ray = new Ray();
28
+ const _plane = new Plane();
29
+ const _TILT_LIMIT = Math.cos( 70 * MathUtils.DEG2RAD );
30
+
31
+ const _v = new Vector3();
32
+ const _twoPI = 2 * Math.PI;
33
+
34
+ const _STATE = {
35
+ NONE: - 1,
36
+ ROTATE: 0,
37
+ DOLLY: 1,
38
+ PAN: 2,
39
+ TOUCH_ROTATE: 3,
40
+ TOUCH_PAN: 4,
41
+ TOUCH_DOLLY_PAN: 5,
42
+ TOUCH_DOLLY_ROTATE: 6
43
+ };
44
+ const _EPS = 0.000001;
45
+
46
+
47
+ /**
48
+ * Orbit controls allow the camera to orbit around a target.
49
+ *
50
+ * OrbitControls performs orbiting, dollying (zooming), and panning. Unlike {@link TrackballControls},
51
+ * it maintains the "up" direction `object.up` (+Y by default).
52
+ *
53
+ * - Orbit: Left mouse / touch: one-finger move.
54
+ * - Zoom: Middle mouse, or mousewheel / touch: two-finger spread or squish.
55
+ * - Pan: Right mouse, or left mouse + ctrl/meta/shiftKey, or arrow keys / touch: two-finger move.
56
+ *
57
+ * ```js
58
+ * const controls = new OrbitControls( camera, renderer.domElement );
59
+ *
60
+ * // controls.update() must be called after any manual changes to the camera's transform
61
+ * camera.position.set( 0, 20, 100 );
62
+ * controls.update();
63
+ *
64
+ * function animate() {
65
+ *
66
+ * // required if controls.enableDamping or controls.autoRotate are set to true
67
+ * controls.update();
68
+ *
69
+ * renderer.render( scene, camera );
70
+ *
71
+ * }
72
+ * ```
73
+ *
74
+ * @augments Controls
75
+ * @three_import import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
76
+ */
77
+ class OrbitControls extends Controls {
78
+
79
+ /**
80
+ * Constructs a new controls instance.
81
+ *
82
+ * @param {Object3D} object - The object that is managed by the controls.
83
+ * @param {?HTMLDOMElement} domElement - The HTML element used for event listeners.
84
+ */
85
+ constructor( object, domElement = null ) {
86
+
87
+ super( object, domElement );
88
+
89
+ this.state = _STATE.NONE;
90
+
91
+ /**
92
+ * The focus point of the controls, the `object` orbits around this.
93
+ * It can be updated manually at any point to change the focus of the controls.
94
+ *
95
+ * @type {Vector3}
96
+ */
97
+ this.target = new Vector3();
98
+
99
+ /**
100
+ * The focus point of the `minTargetRadius` and `maxTargetRadius` limits.
101
+ * It can be updated manually at any point to change the center of interest
102
+ * for the `target`.
103
+ *
104
+ * @type {Vector3}
105
+ */
106
+ this.cursor = new Vector3();
107
+
108
+ /**
109
+ * How far you can dolly in (perspective camera only).
110
+ *
111
+ * @type {number}
112
+ * @default 0
113
+ */
114
+ this.minDistance = 0;
115
+
116
+ /**
117
+ * How far you can dolly out (perspective camera only).
118
+ *
119
+ * @type {number}
120
+ * @default Infinity
121
+ */
122
+ this.maxDistance = Infinity;
123
+
124
+ /**
125
+ * How far you can zoom in (orthographic camera only).
126
+ *
127
+ * @type {number}
128
+ * @default 0
129
+ */
130
+ this.minZoom = 0;
131
+
132
+ /**
133
+ * How far you can zoom out (orthographic camera only).
134
+ *
135
+ * @type {number}
136
+ * @default Infinity
137
+ */
138
+ this.maxZoom = Infinity;
139
+
140
+ /**
141
+ * How close you can get the target to the 3D `cursor`.
142
+ *
143
+ * @type {number}
144
+ * @default 0
145
+ */
146
+ this.minTargetRadius = 0;
147
+
148
+ /**
149
+ * How far you can move the target from the 3D `cursor`.
150
+ *
151
+ * @type {number}
152
+ * @default Infinity
153
+ */
154
+ this.maxTargetRadius = Infinity;
155
+
156
+ /**
157
+ * How far you can orbit vertically, lower limit. Range is `[0, Math.PI]` radians.
158
+ *
159
+ * @type {number}
160
+ * @default 0
161
+ */
162
+ this.minPolarAngle = 0;
163
+
164
+ /**
165
+ * How far you can orbit vertically, upper limit. Range is `[0, Math.PI]` radians.
166
+ *
167
+ * @type {number}
168
+ * @default Math.PI
169
+ */
170
+ this.maxPolarAngle = Math.PI;
171
+
172
+ /**
173
+ * How far you can orbit horizontally, lower limit. If set, the interval `[ min, max ]`
174
+ * must be a sub-interval of `[ - 2 PI, 2 PI ]`, with `( max - min < 2 PI )`.
175
+ *
176
+ * @type {number}
177
+ * @default -Infinity
178
+ */
179
+ this.minAzimuthAngle = - Infinity;
180
+
181
+ /**
182
+ * How far you can orbit horizontally, upper limit. If set, the interval `[ min, max ]`
183
+ * must be a sub-interval of `[ - 2 PI, 2 PI ]`, with `( max - min < 2 PI )`.
184
+ *
185
+ * @type {number}
186
+ * @default -Infinity
187
+ */
188
+ this.maxAzimuthAngle = Infinity;
189
+
190
+ /**
191
+ * Set to `true` to enable damping (inertia), which can be used to give a sense of weight
192
+ * to the controls. Note that if this is enabled, you must call `update()` in your animation
193
+ * loop.
194
+ *
195
+ * @type {boolean}
196
+ * @default false
197
+ */
198
+ this.enableDamping = false;
199
+
200
+ /**
201
+ * The damping inertia used if `enableDamping` is set to `true`.
202
+ *
203
+ * Note that for this to work, you must call `update()` in your animation loop.
204
+ *
205
+ * @type {number}
206
+ * @default 0.05
207
+ */
208
+ this.dampingFactor = 0.05;
209
+
210
+ /**
211
+ * Enable or disable zooming (dollying) of the camera.
212
+ *
213
+ * @type {boolean}
214
+ * @default true
215
+ */
216
+ this.enableZoom = true;
217
+
218
+ /**
219
+ * Speed of zooming / dollying.
220
+ *
221
+ * @type {number}
222
+ * @default 1
223
+ */
224
+ this.zoomSpeed = 1.0;
225
+
226
+ /**
227
+ * Enable or disable horizontal and vertical rotation of the camera.
228
+ *
229
+ * Note that it is possible to disable a single axis by setting the min and max of the
230
+ * `minPolarAngle` or `minAzimuthAngle` to the same value, which will cause the vertical
231
+ * or horizontal rotation to be fixed at that value.
232
+ *
233
+ * @type {boolean}
234
+ * @default true
235
+ */
236
+ this.enableRotate = true;
237
+
238
+ /**
239
+ * Speed of rotation.
240
+ *
241
+ * @type {number}
242
+ * @default 1
243
+ */
244
+ this.rotateSpeed = 1.0;
245
+
246
+ /**
247
+ * How fast to rotate the camera when the keyboard is used.
248
+ *
249
+ * @type {number}
250
+ * @default 1
251
+ */
252
+ this.keyRotateSpeed = 1.0;
253
+
254
+ /**
255
+ * Enable or disable camera panning.
256
+ *
257
+ * @type {boolean}
258
+ * @default true
259
+ */
260
+ this.enablePan = true;
261
+
262
+ /**
263
+ * Speed of panning.
264
+ *
265
+ * @type {number}
266
+ * @default 1
267
+ */
268
+ this.panSpeed = 1.0;
269
+
270
+ /**
271
+ * Defines how the camera's position is translated when panning. If `true`, the camera pans
272
+ * in screen space. Otherwise, the camera pans in the plane orthogonal to the camera's up
273
+ * direction.
274
+ *
275
+ * @type {boolean}
276
+ * @default true
277
+ */
278
+ this.screenSpacePanning = true;
279
+
280
+ /**
281
+ * How fast to pan the camera when the keyboard is used in
282
+ * pixels per keypress.
283
+ *
284
+ * @type {number}
285
+ * @default 7
286
+ */
287
+ this.keyPanSpeed = 7.0;
288
+
289
+ /**
290
+ * Setting this property to `true` allows to zoom to the cursor's position.
291
+ *
292
+ * @type {boolean}
293
+ * @default false
294
+ */
295
+ this.zoomToCursor = false;
296
+
297
+ /**
298
+ * Set to true to automatically rotate around the target
299
+ *
300
+ * Note that if this is enabled, you must call `update()` in your animation loop.
301
+ * If you want the auto-rotate speed to be independent of the frame rate (the refresh
302
+ * rate of the display), you must pass the time `deltaTime`, in seconds, to `update()`.
303
+ *
304
+ * @type {boolean}
305
+ * @default false
306
+ */
307
+ this.autoRotate = false;
308
+
309
+ /**
310
+ * How fast to rotate around the target if `autoRotate` is `true`. The default equates to 30 seconds
311
+ * per orbit at 60fps.
312
+ *
313
+ * Note that if `autoRotate` is enabled, you must call `update()` in your animation loop.
314
+ *
315
+ * @type {number}
316
+ * @default 2
317
+ */
318
+ this.autoRotateSpeed = 2.0;
319
+
320
+ /**
321
+ * This object contains references to the keycodes for controlling camera panning.
322
+ *
323
+ * ```js
324
+ * controls.keys = {
325
+ * LEFT: 'ArrowLeft', //left arrow
326
+ * UP: 'ArrowUp', // up arrow
327
+ * RIGHT: 'ArrowRight', // right arrow
328
+ * BOTTOM: 'ArrowDown' // down arrow
329
+ * }
330
+ * ```
331
+ * @type {Object}
332
+ */
333
+ this.keys = { LEFT: 'ArrowLeft', UP: 'ArrowUp', RIGHT: 'ArrowRight', BOTTOM: 'ArrowDown' };
334
+
335
+ /**
336
+ * This object contains references to the mouse actions used by the controls.
337
+ *
338
+ * ```js
339
+ * controls.mouseButtons = {
340
+ * LEFT: THREE.MOUSE.ROTATE,
341
+ * MIDDLE: THREE.MOUSE.DOLLY,
342
+ * RIGHT: THREE.MOUSE.PAN
343
+ * }
344
+ * ```
345
+ * @type {Object}
346
+ */
347
+ this.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };
348
+
349
+ /**
350
+ * This object contains references to the touch actions used by the controls.
351
+ *
352
+ * ```js
353
+ * controls.mouseButtons = {
354
+ * ONE: THREE.TOUCH.ROTATE,
355
+ * TWO: THREE.TOUCH.DOLLY_PAN
356
+ * }
357
+ * ```
358
+ * @type {Object}
359
+ */
360
+ this.touches = { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN };
361
+
362
+ /**
363
+ * Used internally by `saveState()` and `reset()`.
364
+ *
365
+ * @type {Vector3}
366
+ */
367
+ this.target0 = this.target.clone();
368
+
369
+ /**
370
+ * Used internally by `saveState()` and `reset()`.
371
+ *
372
+ * @type {Vector3}
373
+ */
374
+ this.position0 = this.object.position.clone();
375
+
376
+ /**
377
+ * Used internally by `saveState()` and `reset()`.
378
+ *
379
+ * @type {number}
380
+ */
381
+ this.zoom0 = this.object.zoom;
382
+
383
+ // the target DOM element for key events
384
+ this._domElementKeyEvents = null;
385
+
386
+ // internals
387
+
388
+ this._lastPosition = new Vector3();
389
+ this._lastQuaternion = new Quaternion();
390
+ this._lastTargetPosition = new Vector3();
391
+
392
+ // so camera.up is the orbit axis
393
+ this._quat = new Quaternion().setFromUnitVectors( object.up, new Vector3( 0, 1, 0 ) );
394
+ this._quatInverse = this._quat.clone().invert();
395
+
396
+ // current position in spherical coordinates
397
+ this._spherical = new Spherical();
398
+ this._sphericalDelta = new Spherical();
399
+
400
+ this._scale = 1;
401
+ this._panOffset = new Vector3();
402
+
403
+ this._rotateStart = new Vector2();
404
+ this._rotateEnd = new Vector2();
405
+ this._rotateDelta = new Vector2();
406
+
407
+ this._panStart = new Vector2();
408
+ this._panEnd = new Vector2();
409
+ this._panDelta = new Vector2();
410
+
411
+ this._dollyStart = new Vector2();
412
+ this._dollyEnd = new Vector2();
413
+ this._dollyDelta = new Vector2();
414
+
415
+ this._dollyDirection = new Vector3();
416
+ this._mouse = new Vector2();
417
+ this._performCursorZoom = false;
418
+
419
+ this._pointers = [];
420
+ this._pointerPositions = {};
421
+
422
+ this._controlActive = false;
423
+
424
+ // event listeners
425
+
426
+ this._onPointerMove = onPointerMove.bind( this );
427
+ this._onPointerDown = onPointerDown.bind( this );
428
+ this._onPointerUp = onPointerUp.bind( this );
429
+ this._onContextMenu = onContextMenu.bind( this );
430
+ this._onMouseWheel = onMouseWheel.bind( this );
431
+ this._onKeyDown = onKeyDown.bind( this );
432
+
433
+ this._onTouchStart = onTouchStart.bind( this );
434
+ this._onTouchMove = onTouchMove.bind( this );
435
+
436
+ this._onMouseDown = onMouseDown.bind( this );
437
+ this._onMouseMove = onMouseMove.bind( this );
438
+
439
+ this._interceptControlDown = interceptControlDown.bind( this );
440
+ this._interceptControlUp = interceptControlUp.bind( this );
441
+
442
+ //
443
+
444
+ if ( this.domElement !== null ) {
445
+
446
+ this.connect( this.domElement );
447
+
448
+ }
449
+
450
+ this.update();
451
+
452
+ }
453
+
454
+ connect( element ) {
455
+
456
+ super.connect( element );
457
+
458
+ this.domElement.addEventListener( 'pointerdown', this._onPointerDown );
459
+ this.domElement.addEventListener( 'pointercancel', this._onPointerUp );
460
+
461
+ this.domElement.addEventListener( 'contextmenu', this._onContextMenu );
462
+ this.domElement.addEventListener( 'wheel', this._onMouseWheel, { passive: false } );
463
+
464
+ const document = this.domElement.getRootNode(); // offscreen canvas compatibility
465
+ document.addEventListener( 'keydown', this._interceptControlDown, { passive: true, capture: true } );
466
+
467
+ this.domElement.style.touchAction = 'none'; // disable touch scroll
468
+
469
+ }
470
+
471
+ disconnect() {
472
+
473
+ this.domElement.removeEventListener( 'pointerdown', this._onPointerDown );
474
+ this.domElement.removeEventListener( 'pointermove', this._onPointerMove );
475
+ this.domElement.removeEventListener( 'pointerup', this._onPointerUp );
476
+ this.domElement.removeEventListener( 'pointercancel', this._onPointerUp );
477
+
478
+ this.domElement.removeEventListener( 'wheel', this._onMouseWheel );
479
+ this.domElement.removeEventListener( 'contextmenu', this._onContextMenu );
480
+
481
+ this.stopListenToKeyEvents();
482
+
483
+ const document = this.domElement.getRootNode(); // offscreen canvas compatibility
484
+ document.removeEventListener( 'keydown', this._interceptControlDown, { capture: true } );
485
+
486
+ this.domElement.style.touchAction = 'auto';
487
+
488
+ }
489
+
490
+ dispose() {
491
+
492
+ this.disconnect();
493
+
494
+ }
495
+
496
+ /**
497
+ * Get the current vertical rotation, in radians.
498
+ *
499
+ * @return {number} The current vertical rotation, in radians.
500
+ */
501
+ getPolarAngle() {
502
+
503
+ return this._spherical.phi;
504
+
505
+ }
506
+
507
+ /**
508
+ * Get the current horizontal rotation, in radians.
509
+ *
510
+ * @return {number} The current horizontal rotation, in radians.
511
+ */
512
+ getAzimuthalAngle() {
513
+
514
+ return this._spherical.theta;
515
+
516
+ }
517
+
518
+ /**
519
+ * Returns the distance from the camera to the target.
520
+ *
521
+ * @return {number} The distance from the camera to the target.
522
+ */
523
+ getDistance() {
524
+
525
+ return this.object.position.distanceTo( this.target );
526
+
527
+ }
528
+
529
+ /**
530
+ * Adds key event listeners to the given DOM element.
531
+ * `window` is a recommended argument for using this method.
532
+ *
533
+ * @param {HTMLDOMElement} domElement - The DOM element
534
+ */
535
+ listenToKeyEvents( domElement ) {
536
+
537
+ domElement.addEventListener( 'keydown', this._onKeyDown );
538
+ this._domElementKeyEvents = domElement;
539
+
540
+ }
541
+
542
+ /**
543
+ * Removes the key event listener previously defined with `listenToKeyEvents()`.
544
+ */
545
+ stopListenToKeyEvents() {
546
+
547
+ if ( this._domElementKeyEvents !== null ) {
548
+
549
+ this._domElementKeyEvents.removeEventListener( 'keydown', this._onKeyDown );
550
+ this._domElementKeyEvents = null;
551
+
552
+ }
553
+
554
+ }
555
+
556
+ /**
557
+ * Save the current state of the controls. This can later be recovered with `reset()`.
558
+ */
559
+ saveState() {
560
+
561
+ this.target0.copy( this.target );
562
+ this.position0.copy( this.object.position );
563
+ this.zoom0 = this.object.zoom;
564
+
565
+ }
566
+
567
+ /**
568
+ * Reset the controls to their state from either the last time the `saveState()`
569
+ * was called, or the initial state.
570
+ */
571
+ reset() {
572
+
573
+ this.target.copy( this.target0 );
574
+ this.object.position.copy( this.position0 );
575
+ this.object.zoom = this.zoom0;
576
+
577
+ this.object.updateProjectionMatrix();
578
+ this.dispatchEvent( _changeEvent );
579
+
580
+ this.update();
581
+
582
+ this.state = _STATE.NONE;
583
+
584
+ }
585
+
586
+ update( deltaTime = null ) {
587
+
588
+ const position = this.object.position;
589
+
590
+ _v.copy( position ).sub( this.target );
591
+
592
+ // rotate offset to "y-axis-is-up" space
593
+ _v.applyQuaternion( this._quat );
594
+
595
+ // angle from z-axis around y-axis
596
+ this._spherical.setFromVector3( _v );
597
+
598
+ if ( this.autoRotate && this.state === _STATE.NONE ) {
599
+
600
+ this._rotateLeft( this._getAutoRotationAngle( deltaTime ) );
601
+
602
+ }
603
+
604
+ if ( this.enableDamping ) {
605
+
606
+ this._spherical.theta += this._sphericalDelta.theta * this.dampingFactor;
607
+ this._spherical.phi += this._sphericalDelta.phi * this.dampingFactor;
608
+
609
+ } else {
610
+
611
+ this._spherical.theta += this._sphericalDelta.theta;
612
+ this._spherical.phi += this._sphericalDelta.phi;
613
+
614
+ }
615
+
616
+ // restrict theta to be between desired limits
617
+
618
+ let min = this.minAzimuthAngle;
619
+ let max = this.maxAzimuthAngle;
620
+
621
+ if ( isFinite( min ) && isFinite( max ) ) {
622
+
623
+ if ( min < - Math.PI ) min += _twoPI; else if ( min > Math.PI ) min -= _twoPI;
624
+
625
+ if ( max < - Math.PI ) max += _twoPI; else if ( max > Math.PI ) max -= _twoPI;
626
+
627
+ if ( min <= max ) {
628
+
629
+ this._spherical.theta = Math.max( min, Math.min( max, this._spherical.theta ) );
630
+
631
+ } else {
632
+
633
+ this._spherical.theta = ( this._spherical.theta > ( min + max ) / 2 ) ?
634
+ Math.max( min, this._spherical.theta ) :
635
+ Math.min( max, this._spherical.theta );
636
+
637
+ }
638
+
639
+ }
640
+
641
+ // restrict phi to be between desired limits
642
+ this._spherical.phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, this._spherical.phi ) );
643
+
644
+ this._spherical.makeSafe();
645
+
646
+
647
+ // move target to panned location
648
+
649
+ if ( this.enableDamping === true ) {
650
+
651
+ this.target.addScaledVector( this._panOffset, this.dampingFactor );
652
+
653
+ } else {
654
+
655
+ this.target.add( this._panOffset );
656
+
657
+ }
658
+
659
+ // Limit the target distance from the cursor to create a sphere around the center of interest
660
+ this.target.sub( this.cursor );
661
+ this.target.clampLength( this.minTargetRadius, this.maxTargetRadius );
662
+ this.target.add( this.cursor );
663
+
664
+ let zoomChanged = false;
665
+ // adjust the camera position based on zoom only if we're not zooming to the cursor or if it's an ortho camera
666
+ // we adjust zoom later in these cases
667
+ if ( this.zoomToCursor && this._performCursorZoom || this.object.isOrthographicCamera ) {
668
+
669
+ this._spherical.radius = this._clampDistance( this._spherical.radius );
670
+
671
+ } else {
672
+
673
+ const prevRadius = this._spherical.radius;
674
+ this._spherical.radius = this._clampDistance( this._spherical.radius * this._scale );
675
+ zoomChanged = prevRadius != this._spherical.radius;
676
+
677
+ }
678
+
679
+ _v.setFromSpherical( this._spherical );
680
+
681
+ // rotate offset back to "camera-up-vector-is-up" space
682
+ _v.applyQuaternion( this._quatInverse );
683
+
684
+ position.copy( this.target ).add( _v );
685
+
686
+ this.object.lookAt( this.target );
687
+
688
+ if ( this.enableDamping === true ) {
689
+
690
+ this._sphericalDelta.theta *= ( 1 - this.dampingFactor );
691
+ this._sphericalDelta.phi *= ( 1 - this.dampingFactor );
692
+
693
+ this._panOffset.multiplyScalar( 1 - this.dampingFactor );
694
+
695
+ } else {
696
+
697
+ this._sphericalDelta.set( 0, 0, 0 );
698
+
699
+ this._panOffset.set( 0, 0, 0 );
700
+
701
+ }
702
+
703
+ // adjust camera position
704
+ if ( this.zoomToCursor && this._performCursorZoom ) {
705
+
706
+ let newRadius = null;
707
+ if ( this.object.isPerspectiveCamera ) {
708
+
709
+ // move the camera down the pointer ray
710
+ // this method avoids floating point error
711
+ const prevRadius = _v.length();
712
+ newRadius = this._clampDistance( prevRadius * this._scale );
713
+
714
+ const radiusDelta = prevRadius - newRadius;
715
+ this.object.position.addScaledVector( this._dollyDirection, radiusDelta );
716
+ this.object.updateMatrixWorld();
717
+
718
+ zoomChanged = !! radiusDelta;
719
+
720
+ } else if ( this.object.isOrthographicCamera ) {
721
+
722
+ // adjust the ortho camera position based on zoom changes
723
+ const mouseBefore = new Vector3( this._mouse.x, this._mouse.y, 0 );
724
+ mouseBefore.unproject( this.object );
725
+
726
+ const prevZoom = this.object.zoom;
727
+ this.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / this._scale ) );
728
+ this.object.updateProjectionMatrix();
729
+
730
+ zoomChanged = prevZoom !== this.object.zoom;
731
+
732
+ const mouseAfter = new Vector3( this._mouse.x, this._mouse.y, 0 );
733
+ mouseAfter.unproject( this.object );
734
+
735
+ this.object.position.sub( mouseAfter ).add( mouseBefore );
736
+ this.object.updateMatrixWorld();
737
+
738
+ newRadius = _v.length();
739
+
740
+ } else {
741
+
742
+ console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.' );
743
+ this.zoomToCursor = false;
744
+
745
+ }
746
+
747
+ // handle the placement of the target
748
+ if ( newRadius !== null ) {
749
+
750
+ if ( this.screenSpacePanning ) {
751
+
752
+ // position the orbit target in front of the new camera position
753
+ this.target.set( 0, 0, - 1 )
754
+ .transformDirection( this.object.matrix )
755
+ .multiplyScalar( newRadius )
756
+ .add( this.object.position );
757
+
758
+ } else {
759
+
760
+ // get the ray and translation plane to compute target
761
+ _ray.origin.copy( this.object.position );
762
+ _ray.direction.set( 0, 0, - 1 ).transformDirection( this.object.matrix );
763
+
764
+ // if the camera is 20 degrees above the horizon then don't adjust the focus target to avoid
765
+ // extremely large values
766
+ if ( Math.abs( this.object.up.dot( _ray.direction ) ) < _TILT_LIMIT ) {
767
+
768
+ this.object.lookAt( this.target );
769
+
770
+ } else {
771
+
772
+ _plane.setFromNormalAndCoplanarPoint( this.object.up, this.target );
773
+ _ray.intersectPlane( _plane, this.target );
774
+
775
+ }
776
+
777
+ }
778
+
779
+ }
780
+
781
+ } else if ( this.object.isOrthographicCamera ) {
782
+
783
+ const prevZoom = this.object.zoom;
784
+ this.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / this._scale ) );
785
+
786
+ if ( prevZoom !== this.object.zoom ) {
787
+
788
+ this.object.updateProjectionMatrix();
789
+ zoomChanged = true;
790
+
791
+ }
792
+
793
+ }
794
+
795
+ this._scale = 1;
796
+ this._performCursorZoom = false;
797
+
798
+ // update condition is:
799
+ // min(camera displacement, camera rotation in radians)^2 > EPS
800
+ // using small-angle approximation cos(x/2) = 1 - x^2 / 8
801
+
802
+ if ( zoomChanged ||
803
+ this._lastPosition.distanceToSquared( this.object.position ) > _EPS ||
804
+ 8 * ( 1 - this._lastQuaternion.dot( this.object.quaternion ) ) > _EPS ||
805
+ this._lastTargetPosition.distanceToSquared( this.target ) > _EPS ) {
806
+
807
+ this.dispatchEvent( _changeEvent );
808
+
809
+ this._lastPosition.copy( this.object.position );
810
+ this._lastQuaternion.copy( this.object.quaternion );
811
+ this._lastTargetPosition.copy( this.target );
812
+
813
+ return true;
814
+
815
+ }
816
+
817
+ return false;
818
+
819
+ }
820
+
821
+ _getAutoRotationAngle( deltaTime ) {
822
+
823
+ if ( deltaTime !== null ) {
824
+
825
+ return ( _twoPI / 60 * this.autoRotateSpeed ) * deltaTime;
826
+
827
+ } else {
828
+
829
+ return _twoPI / 60 / 60 * this.autoRotateSpeed;
830
+
831
+ }
832
+
833
+ }
834
+
835
+ _getZoomScale( delta ) {
836
+
837
+ const normalizedDelta = Math.abs( delta * 0.01 );
838
+ return Math.pow( 0.95, this.zoomSpeed * normalizedDelta );
839
+
840
+ }
841
+
842
+ _rotateLeft( angle ) {
843
+
844
+ this._sphericalDelta.theta -= angle;
845
+
846
+ }
847
+
848
+ _rotateUp( angle ) {
849
+
850
+ this._sphericalDelta.phi -= angle;
851
+
852
+ }
853
+
854
+ _panLeft( distance, objectMatrix ) {
855
+
856
+ _v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix
857
+ _v.multiplyScalar( - distance );
858
+
859
+ this._panOffset.add( _v );
860
+
861
+ }
862
+
863
+ _panUp( distance, objectMatrix ) {
864
+
865
+ if ( this.screenSpacePanning === true ) {
866
+
867
+ _v.setFromMatrixColumn( objectMatrix, 1 );
868
+
869
+ } else {
870
+
871
+ _v.setFromMatrixColumn( objectMatrix, 0 );
872
+ _v.crossVectors( this.object.up, _v );
873
+
874
+ }
875
+
876
+ _v.multiplyScalar( distance );
877
+
878
+ this._panOffset.add( _v );
879
+
880
+ }
881
+
882
+ // deltaX and deltaY are in pixels; right and down are positive
883
+ _pan( deltaX, deltaY ) {
884
+
885
+ const element = this.domElement;
886
+
887
+ if ( this.object.isPerspectiveCamera ) {
888
+
889
+ // perspective
890
+ const position = this.object.position;
891
+ _v.copy( position ).sub( this.target );
892
+ let targetDistance = _v.length();
893
+
894
+ // half of the fov is center to top of screen
895
+ targetDistance *= Math.tan( ( this.object.fov / 2 ) * Math.PI / 180.0 );
896
+
897
+ // we use only clientHeight here so aspect ratio does not distort speed
898
+ this._panLeft( 2 * deltaX * targetDistance / element.clientHeight, this.object.matrix );
899
+ this._panUp( 2 * deltaY * targetDistance / element.clientHeight, this.object.matrix );
900
+
901
+ } else if ( this.object.isOrthographicCamera ) {
902
+
903
+ // orthographic
904
+ this._panLeft( deltaX * ( this.object.right - this.object.left ) / this.object.zoom / element.clientWidth, this.object.matrix );
905
+ this._panUp( deltaY * ( this.object.top - this.object.bottom ) / this.object.zoom / element.clientHeight, this.object.matrix );
906
+
907
+ } else {
908
+
909
+ // camera neither orthographic nor perspective
910
+ console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
911
+ this.enablePan = false;
912
+
913
+ }
914
+
915
+ }
916
+
917
+ _dollyOut( dollyScale ) {
918
+
919
+ if ( this.object.isPerspectiveCamera || this.object.isOrthographicCamera ) {
920
+
921
+ this._scale /= dollyScale;
922
+
923
+ } else {
924
+
925
+ console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
926
+ this.enableZoom = false;
927
+
928
+ }
929
+
930
+ }
931
+
932
+ _dollyIn( dollyScale ) {
933
+
934
+ if ( this.object.isPerspectiveCamera || this.object.isOrthographicCamera ) {
935
+
936
+ this._scale *= dollyScale;
937
+
938
+ } else {
939
+
940
+ console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
941
+ this.enableZoom = false;
942
+
943
+ }
944
+
945
+ }
946
+
947
+ _updateZoomParameters( x, y ) {
948
+
949
+ if ( ! this.zoomToCursor ) {
950
+
951
+ return;
952
+
953
+ }
954
+
955
+ this._performCursorZoom = true;
956
+
957
+ const rect = this.domElement.getBoundingClientRect();
958
+ const dx = x - rect.left;
959
+ const dy = y - rect.top;
960
+ const w = rect.width;
961
+ const h = rect.height;
962
+
963
+ this._mouse.x = ( dx / w ) * 2 - 1;
964
+ this._mouse.y = - ( dy / h ) * 2 + 1;
965
+
966
+ this._dollyDirection.set( this._mouse.x, this._mouse.y, 1 ).unproject( this.object ).sub( this.object.position ).normalize();
967
+
968
+ }
969
+
970
+ _clampDistance( dist ) {
971
+
972
+ return Math.max( this.minDistance, Math.min( this.maxDistance, dist ) );
973
+
974
+ }
975
+
976
+ //
977
+ // event callbacks - update the object state
978
+ //
979
+
980
+ _handleMouseDownRotate( event ) {
981
+
982
+ this._rotateStart.set( event.clientX, event.clientY );
983
+
984
+ }
985
+
986
+ _handleMouseDownDolly( event ) {
987
+
988
+ this._updateZoomParameters( event.clientX, event.clientX );
989
+ this._dollyStart.set( event.clientX, event.clientY );
990
+
991
+ }
992
+
993
+ _handleMouseDownPan( event ) {
994
+
995
+ this._panStart.set( event.clientX, event.clientY );
996
+
997
+ }
998
+
999
+ _handleMouseMoveRotate( event ) {
1000
+
1001
+ this._rotateEnd.set( event.clientX, event.clientY );
1002
+
1003
+ this._rotateDelta.subVectors( this._rotateEnd, this._rotateStart ).multiplyScalar( this.rotateSpeed );
1004
+
1005
+ const element = this.domElement;
1006
+
1007
+ this._rotateLeft( _twoPI * this._rotateDelta.x / element.clientHeight ); // yes, height
1008
+
1009
+ this._rotateUp( _twoPI * this._rotateDelta.y / element.clientHeight );
1010
+
1011
+ this._rotateStart.copy( this._rotateEnd );
1012
+
1013
+ this.update();
1014
+
1015
+ }
1016
+
1017
+ _handleMouseMoveDolly( event ) {
1018
+
1019
+ this._dollyEnd.set( event.clientX, event.clientY );
1020
+
1021
+ this._dollyDelta.subVectors( this._dollyEnd, this._dollyStart );
1022
+
1023
+ if ( this._dollyDelta.y > 0 ) {
1024
+
1025
+ this._dollyOut( this._getZoomScale( this._dollyDelta.y ) );
1026
+
1027
+ } else if ( this._dollyDelta.y < 0 ) {
1028
+
1029
+ this._dollyIn( this._getZoomScale( this._dollyDelta.y ) );
1030
+
1031
+ }
1032
+
1033
+ this._dollyStart.copy( this._dollyEnd );
1034
+
1035
+ this.update();
1036
+
1037
+ }
1038
+
1039
+ _handleMouseMovePan( event ) {
1040
+
1041
+ this._panEnd.set( event.clientX, event.clientY );
1042
+
1043
+ this._panDelta.subVectors( this._panEnd, this._panStart ).multiplyScalar( this.panSpeed );
1044
+
1045
+ this._pan( this._panDelta.x, this._panDelta.y );
1046
+
1047
+ this._panStart.copy( this._panEnd );
1048
+
1049
+ this.update();
1050
+
1051
+ }
1052
+
1053
+ _handleMouseWheel( event ) {
1054
+
1055
+ this._updateZoomParameters( event.clientX, event.clientY );
1056
+
1057
+ if ( event.deltaY < 0 ) {
1058
+
1059
+ this._dollyIn( this._getZoomScale( event.deltaY ) );
1060
+
1061
+ } else if ( event.deltaY > 0 ) {
1062
+
1063
+ this._dollyOut( this._getZoomScale( event.deltaY ) );
1064
+
1065
+ }
1066
+
1067
+ this.update();
1068
+
1069
+ }
1070
+
1071
+ _handleKeyDown( event ) {
1072
+
1073
+ let needsUpdate = false;
1074
+
1075
+ switch ( event.code ) {
1076
+
1077
+ case this.keys.UP:
1078
+
1079
+ if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
1080
+
1081
+ if ( this.enableRotate ) {
1082
+
1083
+ this._rotateUp( _twoPI * this.keyRotateSpeed / this.domElement.clientHeight );
1084
+
1085
+ }
1086
+
1087
+ } else {
1088
+
1089
+ if ( this.enablePan ) {
1090
+
1091
+ this._pan( 0, this.keyPanSpeed );
1092
+
1093
+ }
1094
+
1095
+ }
1096
+
1097
+ needsUpdate = true;
1098
+ break;
1099
+
1100
+ case this.keys.BOTTOM:
1101
+
1102
+ if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
1103
+
1104
+ if ( this.enableRotate ) {
1105
+
1106
+ this._rotateUp( - _twoPI * this.keyRotateSpeed / this.domElement.clientHeight );
1107
+
1108
+ }
1109
+
1110
+ } else {
1111
+
1112
+ if ( this.enablePan ) {
1113
+
1114
+ this._pan( 0, - this.keyPanSpeed );
1115
+
1116
+ }
1117
+
1118
+ }
1119
+
1120
+ needsUpdate = true;
1121
+ break;
1122
+
1123
+ case this.keys.LEFT:
1124
+
1125
+ if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
1126
+
1127
+ if ( this.enableRotate ) {
1128
+
1129
+ this._rotateLeft( _twoPI * this.keyRotateSpeed / this.domElement.clientHeight );
1130
+
1131
+ }
1132
+
1133
+ } else {
1134
+
1135
+ if ( this.enablePan ) {
1136
+
1137
+ this._pan( this.keyPanSpeed, 0 );
1138
+
1139
+ }
1140
+
1141
+ }
1142
+
1143
+ needsUpdate = true;
1144
+ break;
1145
+
1146
+ case this.keys.RIGHT:
1147
+
1148
+ if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
1149
+
1150
+ if ( this.enableRotate ) {
1151
+
1152
+ this._rotateLeft( - _twoPI * this.keyRotateSpeed / this.domElement.clientHeight );
1153
+
1154
+ }
1155
+
1156
+ } else {
1157
+
1158
+ if ( this.enablePan ) {
1159
+
1160
+ this._pan( - this.keyPanSpeed, 0 );
1161
+
1162
+ }
1163
+
1164
+ }
1165
+
1166
+ needsUpdate = true;
1167
+ break;
1168
+
1169
+ }
1170
+
1171
+ if ( needsUpdate ) {
1172
+
1173
+ // prevent the browser from scrolling on cursor keys
1174
+ event.preventDefault();
1175
+
1176
+ this.update();
1177
+
1178
+ }
1179
+
1180
+
1181
+ }
1182
+
1183
+ _handleTouchStartRotate( event ) {
1184
+
1185
+ if ( this._pointers.length === 1 ) {
1186
+
1187
+ this._rotateStart.set( event.pageX, event.pageY );
1188
+
1189
+ } else {
1190
+
1191
+ const position = this._getSecondPointerPosition( event );
1192
+
1193
+ const x = 0.5 * ( event.pageX + position.x );
1194
+ const y = 0.5 * ( event.pageY + position.y );
1195
+
1196
+ this._rotateStart.set( x, y );
1197
+
1198
+ }
1199
+
1200
+ }
1201
+
1202
+ _handleTouchStartPan( event ) {
1203
+
1204
+ if ( this._pointers.length === 1 ) {
1205
+
1206
+ this._panStart.set( event.pageX, event.pageY );
1207
+
1208
+ } else {
1209
+
1210
+ const position = this._getSecondPointerPosition( event );
1211
+
1212
+ const x = 0.5 * ( event.pageX + position.x );
1213
+ const y = 0.5 * ( event.pageY + position.y );
1214
+
1215
+ this._panStart.set( x, y );
1216
+
1217
+ }
1218
+
1219
+ }
1220
+
1221
+ _handleTouchStartDolly( event ) {
1222
+
1223
+ const position = this._getSecondPointerPosition( event );
1224
+
1225
+ const dx = event.pageX - position.x;
1226
+ const dy = event.pageY - position.y;
1227
+
1228
+ const distance = Math.sqrt( dx * dx + dy * dy );
1229
+
1230
+ this._dollyStart.set( 0, distance );
1231
+
1232
+ }
1233
+
1234
+ _handleTouchStartDollyPan( event ) {
1235
+
1236
+ if ( this.enableZoom ) this._handleTouchStartDolly( event );
1237
+
1238
+ if ( this.enablePan ) this._handleTouchStartPan( event );
1239
+
1240
+ }
1241
+
1242
+ _handleTouchStartDollyRotate( event ) {
1243
+
1244
+ if ( this.enableZoom ) this._handleTouchStartDolly( event );
1245
+
1246
+ if ( this.enableRotate ) this._handleTouchStartRotate( event );
1247
+
1248
+ }
1249
+
1250
+ _handleTouchMoveRotate( event ) {
1251
+
1252
+ if ( this._pointers.length == 1 ) {
1253
+
1254
+ this._rotateEnd.set( event.pageX, event.pageY );
1255
+
1256
+ } else {
1257
+
1258
+ const position = this._getSecondPointerPosition( event );
1259
+
1260
+ const x = 0.5 * ( event.pageX + position.x );
1261
+ const y = 0.5 * ( event.pageY + position.y );
1262
+
1263
+ this._rotateEnd.set( x, y );
1264
+
1265
+ }
1266
+
1267
+ this._rotateDelta.subVectors( this._rotateEnd, this._rotateStart ).multiplyScalar( this.rotateSpeed );
1268
+
1269
+ const element = this.domElement;
1270
+
1271
+ this._rotateLeft( _twoPI * this._rotateDelta.x / element.clientHeight ); // yes, height
1272
+
1273
+ this._rotateUp( _twoPI * this._rotateDelta.y / element.clientHeight );
1274
+
1275
+ this._rotateStart.copy( this._rotateEnd );
1276
+
1277
+ }
1278
+
1279
+ _handleTouchMovePan( event ) {
1280
+
1281
+ if ( this._pointers.length === 1 ) {
1282
+
1283
+ this._panEnd.set( event.pageX, event.pageY );
1284
+
1285
+ } else {
1286
+
1287
+ const position = this._getSecondPointerPosition( event );
1288
+
1289
+ const x = 0.5 * ( event.pageX + position.x );
1290
+ const y = 0.5 * ( event.pageY + position.y );
1291
+
1292
+ this._panEnd.set( x, y );
1293
+
1294
+ }
1295
+
1296
+ this._panDelta.subVectors( this._panEnd, this._panStart ).multiplyScalar( this.panSpeed );
1297
+
1298
+ this._pan( this._panDelta.x, this._panDelta.y );
1299
+
1300
+ this._panStart.copy( this._panEnd );
1301
+
1302
+ }
1303
+
1304
+ _handleTouchMoveDolly( event ) {
1305
+
1306
+ const position = this._getSecondPointerPosition( event );
1307
+
1308
+ const dx = event.pageX - position.x;
1309
+ const dy = event.pageY - position.y;
1310
+
1311
+ const distance = Math.sqrt( dx * dx + dy * dy );
1312
+
1313
+ this._dollyEnd.set( 0, distance );
1314
+
1315
+ this._dollyDelta.set( 0, Math.pow( this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed ) );
1316
+
1317
+ this._dollyOut( this._dollyDelta.y );
1318
+
1319
+ this._dollyStart.copy( this._dollyEnd );
1320
+
1321
+ const centerX = ( event.pageX + position.x ) * 0.5;
1322
+ const centerY = ( event.pageY + position.y ) * 0.5;
1323
+
1324
+ this._updateZoomParameters( centerX, centerY );
1325
+
1326
+ }
1327
+
1328
+ _handleTouchMoveDollyPan( event ) {
1329
+
1330
+ if ( this.enableZoom ) this._handleTouchMoveDolly( event );
1331
+
1332
+ if ( this.enablePan ) this._handleTouchMovePan( event );
1333
+
1334
+ }
1335
+
1336
+ _handleTouchMoveDollyRotate( event ) {
1337
+
1338
+ if ( this.enableZoom ) this._handleTouchMoveDolly( event );
1339
+
1340
+ if ( this.enableRotate ) this._handleTouchMoveRotate( event );
1341
+
1342
+ }
1343
+
1344
+ // pointers
1345
+
1346
+ _addPointer( event ) {
1347
+
1348
+ this._pointers.push( event.pointerId );
1349
+
1350
+ }
1351
+
1352
+ _removePointer( event ) {
1353
+
1354
+ delete this._pointerPositions[ event.pointerId ];
1355
+
1356
+ for ( let i = 0; i < this._pointers.length; i ++ ) {
1357
+
1358
+ if ( this._pointers[ i ] == event.pointerId ) {
1359
+
1360
+ this._pointers.splice( i, 1 );
1361
+ return;
1362
+
1363
+ }
1364
+
1365
+ }
1366
+
1367
+ }
1368
+
1369
+ _isTrackingPointer( event ) {
1370
+
1371
+ for ( let i = 0; i < this._pointers.length; i ++ ) {
1372
+
1373
+ if ( this._pointers[ i ] == event.pointerId ) return true;
1374
+
1375
+ }
1376
+
1377
+ return false;
1378
+
1379
+ }
1380
+
1381
+ _trackPointer( event ) {
1382
+
1383
+ let position = this._pointerPositions[ event.pointerId ];
1384
+
1385
+ if ( position === undefined ) {
1386
+
1387
+ position = new Vector2();
1388
+ this._pointerPositions[ event.pointerId ] = position;
1389
+
1390
+ }
1391
+
1392
+ position.set( event.pageX, event.pageY );
1393
+
1394
+ }
1395
+
1396
+ _getSecondPointerPosition( event ) {
1397
+
1398
+ const pointerId = ( event.pointerId === this._pointers[ 0 ] ) ? this._pointers[ 1 ] : this._pointers[ 0 ];
1399
+
1400
+ return this._pointerPositions[ pointerId ];
1401
+
1402
+ }
1403
+
1404
+ //
1405
+
1406
+ _customWheelEvent( event ) {
1407
+
1408
+ const mode = event.deltaMode;
1409
+
1410
+ // minimal wheel event altered to meet delta-zoom demand
1411
+ const newEvent = {
1412
+ clientX: event.clientX,
1413
+ clientY: event.clientY,
1414
+ deltaY: event.deltaY,
1415
+ };
1416
+
1417
+ switch ( mode ) {
1418
+
1419
+ case 1: // LINE_MODE
1420
+ newEvent.deltaY *= 16;
1421
+ break;
1422
+
1423
+ case 2: // PAGE_MODE
1424
+ newEvent.deltaY *= 100;
1425
+ break;
1426
+
1427
+ }
1428
+
1429
+ // detect if event was triggered by pinching
1430
+ if ( event.ctrlKey && ! this._controlActive ) {
1431
+
1432
+ newEvent.deltaY *= 10;
1433
+
1434
+ }
1435
+
1436
+ return newEvent;
1437
+
1438
+ }
1439
+
1440
+ }
1441
+
1442
+ function onPointerDown( event ) {
1443
+
1444
+ if ( this.enabled === false ) return;
1445
+
1446
+ if ( this._pointers.length === 0 ) {
1447
+
1448
+ this.domElement.setPointerCapture( event.pointerId );
1449
+
1450
+ this.domElement.addEventListener( 'pointermove', this._onPointerMove );
1451
+ this.domElement.addEventListener( 'pointerup', this._onPointerUp );
1452
+
1453
+ }
1454
+
1455
+ //
1456
+
1457
+ if ( this._isTrackingPointer( event ) ) return;
1458
+
1459
+ //
1460
+
1461
+ this._addPointer( event );
1462
+
1463
+ if ( event.pointerType === 'touch' ) {
1464
+
1465
+ this._onTouchStart( event );
1466
+
1467
+ } else {
1468
+
1469
+ this._onMouseDown( event );
1470
+
1471
+ }
1472
+
1473
+ }
1474
+
1475
+ function onPointerMove( event ) {
1476
+
1477
+ if ( this.enabled === false ) return;
1478
+
1479
+ if ( event.pointerType === 'touch' ) {
1480
+
1481
+ this._onTouchMove( event );
1482
+
1483
+ } else {
1484
+
1485
+ this._onMouseMove( event );
1486
+
1487
+ }
1488
+
1489
+ }
1490
+
1491
+ function onPointerUp( event ) {
1492
+
1493
+ this._removePointer( event );
1494
+
1495
+ switch ( this._pointers.length ) {
1496
+
1497
+ case 0:
1498
+
1499
+ this.domElement.releasePointerCapture( event.pointerId );
1500
+
1501
+ this.domElement.removeEventListener( 'pointermove', this._onPointerMove );
1502
+ this.domElement.removeEventListener( 'pointerup', this._onPointerUp );
1503
+
1504
+ this.dispatchEvent( _endEvent );
1505
+
1506
+ this.state = _STATE.NONE;
1507
+
1508
+ break;
1509
+
1510
+ case 1:
1511
+
1512
+ const pointerId = this._pointers[ 0 ];
1513
+ const position = this._pointerPositions[ pointerId ];
1514
+
1515
+ // minimal placeholder event - allows state correction on pointer-up
1516
+ this._onTouchStart( { pointerId: pointerId, pageX: position.x, pageY: position.y } );
1517
+
1518
+ break;
1519
+
1520
+ }
1521
+
1522
+ }
1523
+
1524
+ function onMouseDown( event ) {
1525
+
1526
+ let mouseAction;
1527
+
1528
+ switch ( event.button ) {
1529
+
1530
+ case 0:
1531
+
1532
+ mouseAction = this.mouseButtons.LEFT;
1533
+ break;
1534
+
1535
+ case 1:
1536
+
1537
+ mouseAction = this.mouseButtons.MIDDLE;
1538
+ break;
1539
+
1540
+ case 2:
1541
+
1542
+ mouseAction = this.mouseButtons.RIGHT;
1543
+ break;
1544
+
1545
+ default:
1546
+
1547
+ mouseAction = - 1;
1548
+
1549
+ }
1550
+
1551
+ switch ( mouseAction ) {
1552
+
1553
+ case MOUSE.DOLLY:
1554
+
1555
+ if ( this.enableZoom === false ) return;
1556
+
1557
+ this._handleMouseDownDolly( event );
1558
+
1559
+ this.state = _STATE.DOLLY;
1560
+
1561
+ break;
1562
+
1563
+ case MOUSE.ROTATE:
1564
+
1565
+ if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
1566
+
1567
+ if ( this.enablePan === false ) return;
1568
+
1569
+ this._handleMouseDownPan( event );
1570
+
1571
+ this.state = _STATE.PAN;
1572
+
1573
+ } else {
1574
+
1575
+ if ( this.enableRotate === false ) return;
1576
+
1577
+ this._handleMouseDownRotate( event );
1578
+
1579
+ this.state = _STATE.ROTATE;
1580
+
1581
+ }
1582
+
1583
+ break;
1584
+
1585
+ case MOUSE.PAN:
1586
+
1587
+ if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
1588
+
1589
+ if ( this.enableRotate === false ) return;
1590
+
1591
+ this._handleMouseDownRotate( event );
1592
+
1593
+ this.state = _STATE.ROTATE;
1594
+
1595
+ } else {
1596
+
1597
+ if ( this.enablePan === false ) return;
1598
+
1599
+ this._handleMouseDownPan( event );
1600
+
1601
+ this.state = _STATE.PAN;
1602
+
1603
+ }
1604
+
1605
+ break;
1606
+
1607
+ default:
1608
+
1609
+ this.state = _STATE.NONE;
1610
+
1611
+ }
1612
+
1613
+ if ( this.state !== _STATE.NONE ) {
1614
+
1615
+ this.dispatchEvent( _startEvent );
1616
+
1617
+ }
1618
+
1619
+ }
1620
+
1621
+ function onMouseMove( event ) {
1622
+
1623
+ switch ( this.state ) {
1624
+
1625
+ case _STATE.ROTATE:
1626
+
1627
+ if ( this.enableRotate === false ) return;
1628
+
1629
+ this._handleMouseMoveRotate( event );
1630
+
1631
+ break;
1632
+
1633
+ case _STATE.DOLLY:
1634
+
1635
+ if ( this.enableZoom === false ) return;
1636
+
1637
+ this._handleMouseMoveDolly( event );
1638
+
1639
+ break;
1640
+
1641
+ case _STATE.PAN:
1642
+
1643
+ if ( this.enablePan === false ) return;
1644
+
1645
+ this._handleMouseMovePan( event );
1646
+
1647
+ break;
1648
+
1649
+ }
1650
+
1651
+ }
1652
+
1653
+ function onMouseWheel( event ) {
1654
+
1655
+ if ( this.enabled === false || this.enableZoom === false || this.state !== _STATE.NONE ) return;
1656
+
1657
+ event.preventDefault();
1658
+
1659
+ this.dispatchEvent( _startEvent );
1660
+
1661
+ this._handleMouseWheel( this._customWheelEvent( event ) );
1662
+
1663
+ this.dispatchEvent( _endEvent );
1664
+
1665
+ }
1666
+
1667
+ function onKeyDown( event ) {
1668
+
1669
+ if ( this.enabled === false ) return;
1670
+
1671
+ this._handleKeyDown( event );
1672
+
1673
+ }
1674
+
1675
+ function onTouchStart( event ) {
1676
+
1677
+ this._trackPointer( event );
1678
+
1679
+ switch ( this._pointers.length ) {
1680
+
1681
+ case 1:
1682
+
1683
+ switch ( this.touches.ONE ) {
1684
+
1685
+ case TOUCH.ROTATE:
1686
+
1687
+ if ( this.enableRotate === false ) return;
1688
+
1689
+ this._handleTouchStartRotate( event );
1690
+
1691
+ this.state = _STATE.TOUCH_ROTATE;
1692
+
1693
+ break;
1694
+
1695
+ case TOUCH.PAN:
1696
+
1697
+ if ( this.enablePan === false ) return;
1698
+
1699
+ this._handleTouchStartPan( event );
1700
+
1701
+ this.state = _STATE.TOUCH_PAN;
1702
+
1703
+ break;
1704
+
1705
+ default:
1706
+
1707
+ this.state = _STATE.NONE;
1708
+
1709
+ }
1710
+
1711
+ break;
1712
+
1713
+ case 2:
1714
+
1715
+ switch ( this.touches.TWO ) {
1716
+
1717
+ case TOUCH.DOLLY_PAN:
1718
+
1719
+ if ( this.enableZoom === false && this.enablePan === false ) return;
1720
+
1721
+ this._handleTouchStartDollyPan( event );
1722
+
1723
+ this.state = _STATE.TOUCH_DOLLY_PAN;
1724
+
1725
+ break;
1726
+
1727
+ case TOUCH.DOLLY_ROTATE:
1728
+
1729
+ if ( this.enableZoom === false && this.enableRotate === false ) return;
1730
+
1731
+ this._handleTouchStartDollyRotate( event );
1732
+
1733
+ this.state = _STATE.TOUCH_DOLLY_ROTATE;
1734
+
1735
+ break;
1736
+
1737
+ default:
1738
+
1739
+ this.state = _STATE.NONE;
1740
+
1741
+ }
1742
+
1743
+ break;
1744
+
1745
+ default:
1746
+
1747
+ this.state = _STATE.NONE;
1748
+
1749
+ }
1750
+
1751
+ if ( this.state !== _STATE.NONE ) {
1752
+
1753
+ this.dispatchEvent( _startEvent );
1754
+
1755
+ }
1756
+
1757
+ }
1758
+
1759
+ function onTouchMove( event ) {
1760
+
1761
+ this._trackPointer( event );
1762
+
1763
+ switch ( this.state ) {
1764
+
1765
+ case _STATE.TOUCH_ROTATE:
1766
+
1767
+ if ( this.enableRotate === false ) return;
1768
+
1769
+ this._handleTouchMoveRotate( event );
1770
+
1771
+ this.update();
1772
+
1773
+ break;
1774
+
1775
+ case _STATE.TOUCH_PAN:
1776
+
1777
+ if ( this.enablePan === false ) return;
1778
+
1779
+ this._handleTouchMovePan( event );
1780
+
1781
+ this.update();
1782
+
1783
+ break;
1784
+
1785
+ case _STATE.TOUCH_DOLLY_PAN:
1786
+
1787
+ if ( this.enableZoom === false && this.enablePan === false ) return;
1788
+
1789
+ this._handleTouchMoveDollyPan( event );
1790
+
1791
+ this.update();
1792
+
1793
+ break;
1794
+
1795
+ case _STATE.TOUCH_DOLLY_ROTATE:
1796
+
1797
+ if ( this.enableZoom === false && this.enableRotate === false ) return;
1798
+
1799
+ this._handleTouchMoveDollyRotate( event );
1800
+
1801
+ this.update();
1802
+
1803
+ break;
1804
+
1805
+ default:
1806
+
1807
+ this.state = _STATE.NONE;
1808
+
1809
+ }
1810
+
1811
+ }
1812
+
1813
+ function onContextMenu( event ) {
1814
+
1815
+ if ( this.enabled === false ) return;
1816
+
1817
+ event.preventDefault();
1818
+
1819
+ }
1820
+
1821
+ function interceptControlDown( event ) {
1822
+
1823
+ if ( event.key === 'Control' ) {
1824
+
1825
+ this._controlActive = true;
1826
+
1827
+ const document = this.domElement.getRootNode(); // offscreen canvas compatibility
1828
+
1829
+ document.addEventListener( 'keyup', this._interceptControlUp, { passive: true, capture: true } );
1830
+
1831
+ }
1832
+
1833
+ }
1834
+
1835
+ function interceptControlUp( event ) {
1836
+
1837
+ if ( event.key === 'Control' ) {
1838
+
1839
+ this._controlActive = false;
1840
+
1841
+ const document = this.domElement.getRootNode(); // offscreen canvas compatibility
1842
+
1843
+ document.removeEventListener( 'keyup', this._interceptControlUp, { passive: true, capture: true } );
1844
+
1845
+ }
1846
+
1847
+ }
1848
+
1849
+ export { OrbitControls };