@2112-lab/central-plant 0.1.4 → 0.1.5

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