@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,1057 @@
1
- import{inherits as t,createClass as e,superPropGet as i,classCallCheck as h,callSuper as n}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{Raycaster as s,Vector3 as a,Quaternion as r,Euler as w,Matrix4 as o,Object3D as l,Mesh as u,MeshBasicMaterial as c,LineBasicMaterial as M,CylinderGeometry as v,BoxGeometry as p,BufferGeometry as f,Float32BufferAttribute as X,OctahedronGeometry as Y,Line as Z,SphereGeometry as d,TorusGeometry as y,PlaneGeometry as k,DoubleSide as m}from"three";var E=new s,S=new a,b=new a,g=new r,T={X:new a(1,0,0),Y:new a(0,1,0),Z:new a(0,0,1)},x={type:"change"},D={type:"mouseDown"},A={type:"mouseUp",mode:null},W={type:"objectChange"},C=function(){function s(t,e){var i;h(this,s),i=n(this,s),void 0===e&&(e=document),i.isTransformControls=!0,i.visible=!1,i.domElement=e,i.domElement.style.touchAction="none";var w=new tt;i.t=w,i.add(w);var o=new et;i.i=o,i.add(o);var l=i;function u(t,e){var i=e;Object.defineProperty(l,t,{get:function(){return void 0!==i?i:e},set:function(e){i!==e&&(i=e,o[t]=e,w[t]=e,l.dispatchEvent({type:t+"-changed",value:e}),l.dispatchEvent(x))}}),l[t]=e,o[t]=e,w[t]=e}u("camera",t),u("object",void 0),u("enabled",!0),u("axis",null),u("mode","translate"),u("translationSnap",null),u("rotationSnap",null),u("scaleSnap",null),u("space","world"),u("size",1),u("dragging",!1),u("showX",!0),u("showY",!0),u("showZ",!0),u("showXY",!0),u("showYZ",!0),u("showXZ",!0),i.clickDelay=null,i.lastInteractionTime=0;var c=new a,M=new a,v=new r,p=new r,f=new a,X=new r,Y=new a,Z=new a,d=new a,y=new a;return u("worldPosition",c),u("worldPositionStart",M),u("worldQuaternion",v),u("worldQuaternionStart",p),u("cameraPosition",f),u("cameraQuaternion",X),u("pointStart",Y),u("pointEnd",Z),u("rotationAxis",d),u("rotationAngle",0),u("eye",y),i.h=new a,i.o=new a,i.l=new a,i.u=new a,i.M=new a,i.v=new r,i.p=new r,i.k=new a,i.m=new a,i.S=new r,i.T=new a,i.D=new a,i.A=new r,i.W=new a,i.C=P.bind(i),i.P=R.bind(i),i.j=j.bind(i),i.R=z.bind(i),i.I=I.bind(i),i.domElement.addEventListener("pointerdown",i.P),i.domElement.addEventListener("pointermove",i.j),i.domElement.addEventListener("pointerup",i.I),i}return t(s,l),e(s,[{key:"updateMatrixWorld",value:function(){void 0!==this.object&&(this.object.updateMatrixWorld(),null===this.object.parent||this.object.parent.matrixWorld.decompose(this.M,this.v,this.k),this.object.matrixWorld.decompose(this.worldPosition,this.worldQuaternion,this.T),this.p.copy(this.v).invert(),this.S.copy(this.worldQuaternion).invert()),this.camera.updateMatrixWorld(),this.camera.matrixWorld.decompose(this.cameraPosition,this.cameraQuaternion,this.u),this.camera.isOrthographicCamera?this.camera.getWorldDirection(this.eye).negate():this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(),i(s,"updateMatrixWorld",this,3)([this])}},{key:"pointerHover",value:function(t){if(void 0!==this.object&&!0!==this.dragging){if(this.clickDelay&&this.clickDelay.doubleClickDelay)if(Date.now()-this.lastInteractionTime<this.clickDelay.doubleClickDelay)return;E.setFromCamera(t,this.camera);var e=Q(this.t.picker[this.mode],E);this.axis=e?e.object.name:null}}},{key:"pointerDown",value:function(t){if(void 0!==this.object&&!0!==this.dragging&&0===t.button){if(this.clickDelay&&this.clickDelay.doubleClickDelay){var e=Date.now();if(e-this.lastInteractionTime<this.clickDelay.doubleClickDelay)return;this.lastInteractionTime=e}if(null!==this.axis){E.setFromCamera(t,this.camera);var i=Q(this.i,E,!0);i&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this.D.copy(this.object.position),this.A.copy(this.object.quaternion),this.W.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this.m),this.pointStart.copy(i.point).sub(this.worldPositionStart)),this.dragging=!0,D.mode=this.mode,this.dispatchEvent(D)}}}},{key:"pointerMove",value:function(t){var e=this.axis,i=this.mode,h=this.object,n=this.space;if("scale"===i?n="local":"E"!==e&&"XYZE"!==e&&"XYZ"!==e||(n="world"),void 0!==h&&null!==e&&!1!==this.dragging&&-1===t.button){E.setFromCamera(t,this.camera);var s=Q(this.i,E,!0);if(s){if(this.pointEnd.copy(s.point).sub(this.worldPositionStart),"translate"===i)this.h.copy(this.pointEnd).sub(this.pointStart),"local"===n&&"XYZ"!==e&&this.h.applyQuaternion(this.S),-1===e.indexOf("X")&&(this.h.x=0),-1===e.indexOf("Y")&&(this.h.y=0),-1===e.indexOf("Z")&&(this.h.z=0),"local"===n&&"XYZ"!==e?this.h.applyQuaternion(this.A).divide(this.k):this.h.applyQuaternion(this.p).divide(this.k),h.position.copy(this.h).add(this.D),this.translationSnap&&("local"===n&&(h.position.applyQuaternion(g.copy(this.A).invert()),-1!==e.search("X")&&(h.position.x=Math.round(h.position.x/this.translationSnap)*this.translationSnap),-1!==e.search("Y")&&(h.position.y=Math.round(h.position.y/this.translationSnap)*this.translationSnap),-1!==e.search("Z")&&(h.position.z=Math.round(h.position.z/this.translationSnap)*this.translationSnap),h.position.applyQuaternion(this.A)),"world"===n&&(h.parent&&h.position.add(S.setFromMatrixPosition(h.parent.matrixWorld)),-1!==e.search("X")&&(h.position.x=Math.round(h.position.x/this.translationSnap)*this.translationSnap),-1!==e.search("Y")&&(h.position.y=Math.round(h.position.y/this.translationSnap)*this.translationSnap),-1!==e.search("Z")&&(h.position.z=Math.round(h.position.z/this.translationSnap)*this.translationSnap),h.parent&&h.position.sub(S.setFromMatrixPosition(h.parent.matrixWorld))));else if("scale"===i){if(-1!==e.search("XYZ")){var a=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(a*=-1),b.set(a,a,a)}else S.copy(this.pointStart),b.copy(this.pointEnd),S.applyQuaternion(this.S),b.applyQuaternion(this.S),b.divide(S),-1===e.search("X")&&(b.x=1),-1===e.search("Y")&&(b.y=1),-1===e.search("Z")&&(b.z=1);h.scale.copy(this.W).multiply(b),this.scaleSnap&&(-1!==e.search("X")&&(h.scale.x=Math.round(h.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),-1!==e.search("Y")&&(h.scale.y=Math.round(h.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),-1!==e.search("Z")&&(h.scale.z=Math.round(h.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if("rotate"===i){this.h.copy(this.pointEnd).sub(this.pointStart);var r=20/this.worldPosition.distanceTo(S.setFromMatrixPosition(this.camera.matrixWorld));"E"===e?(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this.o.copy(this.pointStart).normalize(),this.l.copy(this.pointEnd).normalize(),this.rotationAngle*=this.l.cross(this.o).dot(this.eye)<0?1:-1):"XYZE"===e?(this.rotationAxis.copy(this.h).cross(this.eye).normalize(),this.rotationAngle=this.h.dot(S.copy(this.rotationAxis).cross(this.eye))*r):"X"!==e&&"Y"!==e&&"Z"!==e||(this.rotationAxis.copy(T[e]),S.copy(T[e]),"local"===n&&S.applyQuaternion(this.worldQuaternion),this.rotationAngle=this.h.dot(S.cross(this.eye).normalize())*r),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),"local"===n&&"E"!==e&&"XYZE"!==e?(h.quaternion.copy(this.A),h.quaternion.multiply(g.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this.p),h.quaternion.copy(g.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),h.quaternion.multiply(this.A).normalize())}this.dispatchEvent(x),this.dispatchEvent(W)}}}},{key:"pointerUp",value:function(t){0===t.button&&(this.dragging&&null!==this.axis&&(A.mode=this.mode,this.dispatchEvent(A)),this.dragging=!1,this.axis=null)}},{key:"dispose",value:function(){this.domElement.removeEventListener("pointerdown",this.P),this.domElement.removeEventListener("pointermove",this.j),this.domElement.removeEventListener("pointermove",this.R),this.domElement.removeEventListener("pointerup",this.I),this.traverse(function(t){t.geometry&&t.geometry.dispose(),t.material&&t.material.dispose()})}},{key:"attach",value:function(t){return this.object=t,this.visible=!0,this}},{key:"detach",value:function(){return this.object=void 0,this.visible=!1,this.axis=null,this}},{key:"reset",value:function(){this.enabled&&this.dragging&&(this.object.position.copy(this.D),this.object.quaternion.copy(this.A),this.object.scale.copy(this.W),this.dispatchEvent(x),this.dispatchEvent(W),this.pointStart.copy(this.pointEnd))}},{key:"getRaycaster",value:function(){return E}},{key:"getMode",value:function(){return this.mode}},{key:"setMode",value:function(t){this.mode=t}},{key:"setTranslationSnap",value:function(t){this.translationSnap=t}},{key:"setRotationSnap",value:function(t){this.rotationSnap=t}},{key:"setScaleSnap",value:function(t){this.scaleSnap=t}},{key:"setSize",value:function(t){this.size=t}},{key:"setSpace",value:function(t){this.space=t}},{key:"setDelay",value:function(t){this.clickDelay=t}},{key:"updateInteractionTime",value:function(){this.lastInteractionTime=Date.now()}}])}();function P(t){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:t.button};var e=this.domElement.getBoundingClientRect();return{x:(t.clientX-e.left)/e.width*2-1,y:-(t.clientY-e.top)/e.height*2+1,button:t.button}}function j(t){if(this.enabled)switch(t.pointerType){case"mouse":case"pen":this.pointerHover(this.C(t))}}function R(t){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(t.pointerId),this.domElement.addEventListener("pointermove",this.R),this.pointerHover(this.C(t)),this.pointerDown(this.C(t)))}function z(t){this.enabled&&this.pointerMove(this.C(t))}function I(t){this.enabled&&(this.domElement.releasePointerCapture(t.pointerId),this.domElement.removeEventListener("pointermove",this.R),this.pointerUp(this.C(t)))}function Q(t,e,i){for(var h=e.intersectObject(t,!0),n=0;n<h.length;n++)if(h[n].object.visible||i)return h[n];return!1}var G=new w,H=new a(0,1,0),L=new a(0,0,0),N=new o,U=new r,_=new r,B=new a,O=new o,q=new a(1,0,0),F=new a(0,1,0),J=new a(0,0,1),K=new a,V=new a,$=new a,tt=function(){function s(){var t;h(this,s),(t=n(this,s)).isTransformControlsGizmo=!0,t.type="TransformControlsGizmo";var e=new c({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),i=new M({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),a=e.clone();a.opacity=.15;var r=i.clone();r.opacity=.5;var w=e.clone();w.color.setHex(16711680);var o=e.clone();o.color.setHex(65280);var k=e.clone();k.color.setHex(255);var m=e.clone();m.color.setHex(16711680),m.opacity=.5;var E=e.clone();E.color.setHex(65280),E.opacity=.5;var S=e.clone();S.color.setHex(255),S.opacity=.5;var b=e.clone();b.opacity=.25;var g=e.clone();g.color.setHex(16776960),g.opacity=.25,e.clone().color.setHex(16776960);var T=e.clone();T.color.setHex(7895160);var x=new v(0,.04,.1,12);x.translate(0,.05,0);var D=new p(.08,.08,.08);D.translate(0,.04,0);var A=new f;A.setAttribute("position",new X([0,0,0,1,0,0],3));var W=new v(.0075,.0075,.5,3);function C(t,e){var i=new y(t,.0075,3,64,e*Math.PI*2);return i.rotateY(Math.PI/2),i.rotateX(Math.PI/2),i}W.translate(0,.25,0);var P,j={X:[[new u(x,w),[.5,0,0],[0,0,-Math.PI/2]],[new u(x,w),[-.5,0,0],[0,0,Math.PI/2]],[new u(W,w),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new u(x,o),[0,.5,0]],[new u(x,o),[0,-.5,0],[Math.PI,0,0]],[new u(W,o)]],Z:[[new u(x,k),[0,0,.5],[Math.PI/2,0,0]],[new u(x,k),[0,0,-.5],[-Math.PI/2,0,0]],[new u(W,k),null,[Math.PI/2,0,0]]],XYZ:[[new u(new Y(.1,0),b.clone()),[0,0,0]]],XY:[[new u(new p(.15,.15,.01),S.clone()),[.15,.15,0]]],YZ:[[new u(new p(.15,.15,.01),m.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new u(new p(.15,.15,.01),E.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},R={X:[[new u(new v(.2,0,.6,4),a),[.3,0,0],[0,0,-Math.PI/2]],[new u(new v(.2,0,.6,4),a),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new u(new v(.2,0,.6,4),a),[0,.3,0]],[new u(new v(.2,0,.6,4),a),[0,-.3,0],[0,0,Math.PI]]],Z:[[new u(new v(.2,0,.6,4),a),[0,0,.3],[Math.PI/2,0,0]],[new u(new v(.2,0,.6,4),a),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new u(new Y(.2,0),a)]],XY:[[new u(new p(.2,.2,.01),a),[.15,.15,0]]],YZ:[[new u(new p(.2,.2,.01),a),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new u(new p(.2,.2,.01),a),[.15,0,.15],[-Math.PI/2,0,0]]]},z={START:[[new u(new Y(.01,2),r),null,null,null,"helper"]],END:[[new u(new Y(.01,2),r),null,null,null,"helper"]],DELTA:[[new Z((P=new f,P.setAttribute("position",new X([0,0,0,1,1,1],3)),P),r),null,null,null,"helper"]],X:[[new Z(A,r.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new Z(A,r.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new Z(A,r.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},I={XYZE:[[new u(C(.5,1),T),null,[0,Math.PI/2,0]]],X:[[new u(C(.5,.5),w)]],Y:[[new u(C(.5,.5),o),null,[0,0,-Math.PI/2]]],Z:[[new u(C(.5,.5),k),null,[0,Math.PI/2,0]]],E:[[new u(C(.75,1),g),null,[0,Math.PI/2,0]]]},Q={AXIS:[[new Z(A,r.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},G={XYZE:[[new u(new d(.25,10,8),a)]],X:[[new u(new y(.5,.1,4,24),a),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new u(new y(.5,.1,4,24),a),[0,0,0],[Math.PI/2,0,0]]],Z:[[new u(new y(.5,.1,4,24),a),[0,0,0],[0,0,-Math.PI/2]]],E:[[new u(new y(.75,.1,2,24),a)]]},H={X:[[new u(D,w),[.5,0,0],[0,0,-Math.PI/2]],[new u(W,w),[0,0,0],[0,0,-Math.PI/2]],[new u(D,w),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new u(D,o),[0,.5,0]],[new u(W,o)],[new u(D,o),[0,-.5,0],[0,0,Math.PI]]],Z:[[new u(D,k),[0,0,.5],[Math.PI/2,0,0]],[new u(W,k),[0,0,0],[Math.PI/2,0,0]],[new u(D,k),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new u(new p(.15,.15,.01),S),[.15,.15,0]]],YZ:[[new u(new p(.15,.15,.01),m),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new u(new p(.15,.15,.01),E),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new u(new p(.1,.1,.1),b.clone())]]},L={X:[[new u(new v(.2,0,.6,4),a),[.3,0,0],[0,0,-Math.PI/2]],[new u(new v(.2,0,.6,4),a),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new u(new v(.2,0,.6,4),a),[0,.3,0]],[new u(new v(.2,0,.6,4),a),[0,-.3,0],[0,0,Math.PI]]],Z:[[new u(new v(.2,0,.6,4),a),[0,0,.3],[Math.PI/2,0,0]],[new u(new v(.2,0,.6,4),a),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new u(new p(.2,.2,.01),a),[.15,.15,0]]],YZ:[[new u(new p(.2,.2,.01),a),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new u(new p(.2,.2,.01),a),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new u(new p(.2,.2,.2),a),[0,0,0]]]},N={X:[[new Z(A,r.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new Z(A,r.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new Z(A,r.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function U(t){var e=new l;for(var i in t)for(var h=t[i].length;h--;){var n=t[i][h][0].clone(),s=t[i][h][1],a=t[i][h][2],r=t[i][h][3],w=t[i][h][4];n.name=i,n.tag=w,s&&n.position.set(s[0],s[1],s[2]),a&&n.rotation.set(a[0],a[1],a[2]),r&&n.scale.set(r[0],r[1],r[2]),n.updateMatrix();var o=n.geometry.clone();o.applyMatrix4(n.matrix),n.geometry=o,n.renderOrder=1/0,n.position.set(0,0,0),n.rotation.set(0,0,0),n.scale.set(1,1,1),e.add(n)}return e}return t.gizmo={},t.picker={},t.helper={},t.add(t.gizmo.translate=U(j)),t.add(t.gizmo.rotate=U(I)),t.add(t.gizmo.scale=U(H)),t.add(t.picker.translate=U(R)),t.add(t.picker.rotate=U(G)),t.add(t.picker.scale=U(L)),t.add(t.helper.translate=U(z)),t.add(t.helper.rotate=U(Q)),t.add(t.helper.scale=U(N)),t.picker.translate.visible=!1,t.picker.rotate.visible=!1,t.picker.scale.visible=!1,t}return t(s,l),e(s,[{key:"updateMatrixWorld",value:function(t){var e=this,h="local"===("scale"===this.mode?"local":this.space)?this.worldQuaternion:_;this.gizmo.translate.visible="translate"===this.mode,this.gizmo.rotate.visible="rotate"===this.mode,this.gizmo.scale.visible="scale"===this.mode,this.helper.translate.visible="translate"===this.mode,this.helper.rotate.visible="rotate"===this.mode,this.helper.scale.visible="scale"===this.mode;var n=[];n=(n=(n=n.concat(this.picker[this.mode].children)).concat(this.gizmo[this.mode].children)).concat(this.helper[this.mode].children);for(var a=function(){var t,i=n[r];if(i.visible=!0,i.rotation.set(0,0,0),i.position.copy(e.worldPosition),t=e.camera.isOrthographicCamera?(e.camera.top-e.camera.bottom)/e.camera.zoom:e.worldPosition.distanceTo(e.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*e.camera.fov/360)/e.camera.zoom,7),i.scale.set(1,1,1).multiplyScalar(t*e.size/4),"helper"===i.tag)return i.visible=!1,"AXIS"===i.name?(i.visible=!!e.axis,"X"===e.axis&&(g.setFromEuler(G.set(0,0,0)),i.quaternion.copy(h).multiply(g),Math.abs(H.copy(q).applyQuaternion(h).dot(e.eye))>.9&&(i.visible=!1)),"Y"===e.axis&&(g.setFromEuler(G.set(0,0,Math.PI/2)),i.quaternion.copy(h).multiply(g),Math.abs(H.copy(F).applyQuaternion(h).dot(e.eye))>.9&&(i.visible=!1)),"Z"===e.axis&&(g.setFromEuler(G.set(0,Math.PI/2,0)),i.quaternion.copy(h).multiply(g),Math.abs(H.copy(J).applyQuaternion(h).dot(e.eye))>.9&&(i.visible=!1)),"XYZE"===e.axis&&(g.setFromEuler(G.set(0,Math.PI/2,0)),H.copy(e.rotationAxis),i.quaternion.setFromRotationMatrix(N.lookAt(L,H,F)),i.quaternion.multiply(g),i.visible=e.dragging),"E"===e.axis&&(i.visible=!1)):"START"===i.name?(i.position.copy(e.worldPositionStart),i.visible=e.dragging):"END"===i.name?(i.position.copy(e.worldPosition),i.visible=e.dragging):"DELTA"===i.name?(i.position.copy(e.worldPositionStart),i.quaternion.copy(e.worldQuaternionStart),S.set(1e-10,1e-10,1e-10).add(e.worldPositionStart).sub(e.worldPosition).multiplyScalar(-1),S.applyQuaternion(e.worldQuaternionStart.clone().invert()),i.scale.copy(S),i.visible=e.dragging):(i.quaternion.copy(h),e.dragging?i.position.copy(e.worldPositionStart):i.position.copy(e.worldPosition),e.axis&&(i.visible=-1!==e.axis.search(i.name))),1;if(i.quaternion.copy(h),"translate"===e.mode||"scale"===e.mode){var s=.99;"X"===i.name&&Math.abs(H.copy(q).applyQuaternion(h).dot(e.eye))>s&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),"Y"===i.name&&Math.abs(H.copy(F).applyQuaternion(h).dot(e.eye))>s&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),"Z"===i.name&&Math.abs(H.copy(J).applyQuaternion(h).dot(e.eye))>s&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),"XY"===i.name&&Math.abs(H.copy(J).applyQuaternion(h).dot(e.eye))<.2&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),"YZ"===i.name&&Math.abs(H.copy(q).applyQuaternion(h).dot(e.eye))<.2&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),"XZ"===i.name&&Math.abs(H.copy(F).applyQuaternion(h).dot(e.eye))<.2&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1)}else"rotate"===e.mode&&(U.copy(h),H.copy(e.eye).applyQuaternion(g.copy(h).invert()),-1!==i.name.search("E")&&i.quaternion.setFromRotationMatrix(N.lookAt(e.eye,L,F)),"X"===i.name&&(g.setFromAxisAngle(q,Math.atan2(-H.y,H.z)),g.multiplyQuaternions(U,g),i.quaternion.copy(g)),"Y"===i.name&&(g.setFromAxisAngle(F,Math.atan2(H.x,H.z)),g.multiplyQuaternions(U,g),i.quaternion.copy(g)),"Z"===i.name&&(g.setFromAxisAngle(J,Math.atan2(H.y,H.x)),g.multiplyQuaternions(U,g),i.quaternion.copy(g)));i.visible=i.visible&&(-1===i.name.indexOf("X")||e.showX),i.visible=i.visible&&(-1===i.name.indexOf("Y")||e.showY),i.visible=i.visible&&(-1===i.name.indexOf("Z")||e.showZ),i.visible=i.visible&&(-1===i.name.indexOf("E")||e.showX&&e.showY&&e.showZ),i.visible=i.visible&&("XY"!==i.name||e.showXY),i.visible=i.visible&&("YZ"!==i.name||e.showYZ),i.visible=i.visible&&("XZ"!==i.name||e.showXZ),i.material.G=i.material.G||i.material.color.clone(),i.material.H=i.material.H||i.material.opacity,i.material.color.copy(i.material.G),i.material.opacity=i.material.H,e.enabled&&e.axis&&(i.name===e.axis||e.axis.split("").some(function(t){return i.name===t}))&&(i.material.color.setHex(16776960),i.material.opacity=1)},r=0;r<n.length;r++)a();i(s,"updateMatrixWorld",this,3)([t])}}])}(),et=function(){function s(){var t;return h(this,s),(t=n(this,s,[new k(1e5,1e5,2,2),new c({visible:!1,wireframe:!0,side:m,transparent:!0,opacity:.1,toneMapped:!1})])).isTransformControlsPlane=!0,t.type="TransformControlsPlane",t}return t(s,u),e(s,[{key:"updateMatrixWorld",value:function(t){var e=this.space;switch(this.position.copy(this.worldPosition),"scale"===this.mode&&(e="local"),K.copy(q).applyQuaternion("local"===e?this.worldQuaternion:_),V.copy(F).applyQuaternion("local"===e?this.worldQuaternion:_),$.copy(J).applyQuaternion("local"===e?this.worldQuaternion:_),H.copy(V),this.mode){case"translate":case"scale":switch(this.axis){case"X":H.copy(this.eye).cross(K),B.copy(K).cross(H);break;case"Y":H.copy(this.eye).cross(V),B.copy(V).cross(H);break;case"Z":H.copy(this.eye).cross($),B.copy($).cross(H);break;case"XY":B.copy($);break;case"YZ":B.copy(K);break;case"XZ":H.copy($),B.copy(V);break;case"XYZ":case"E":B.set(0,0,0)}break;default:B.set(0,0,0)}0===B.length()?this.quaternion.copy(this.cameraQuaternion):(O.lookAt(S.set(0,0,0),B,H),this.quaternion.setFromRotationMatrix(O)),i(s,"updateMatrixWorld",this,3)([t])}}])}();export{C as TransformControls,tt as TransformControlsGizmo,et as TransformControlsPlane};
1
+ import { inherits as _inherits, createClass as _createClass, superPropGet as _superPropGet, classCallCheck as _classCallCheck, callSuper as _callSuper } from '../../../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { Raycaster, Vector3, Quaternion, Euler, Matrix4, Object3D, Mesh, MeshBasicMaterial, LineBasicMaterial, CylinderGeometry, BoxGeometry, BufferGeometry, Float32BufferAttribute, OctahedronGeometry, Line, SphereGeometry, TorusGeometry, PlaneGeometry, DoubleSide } from 'three';
3
+
4
+ var _raycaster = new Raycaster();
5
+ var _tempVector = new Vector3();
6
+ var _tempVector2 = new Vector3();
7
+ var _tempQuaternion = new Quaternion();
8
+ var _unit = {
9
+ X: new Vector3(1, 0, 0),
10
+ Y: new Vector3(0, 1, 0),
11
+ Z: new Vector3(0, 0, 1)
12
+ };
13
+ var _changeEvent = {
14
+ type: 'change'
15
+ };
16
+ var _mouseDownEvent = {
17
+ type: 'mouseDown'
18
+ };
19
+ var _mouseUpEvent = {
20
+ type: 'mouseUp',
21
+ mode: null
22
+ };
23
+ var _objectChangeEvent = {
24
+ type: 'objectChange'
25
+ };
26
+ var TransformControls = /*#__PURE__*/function (_Object3D) {
27
+ function TransformControls(camera, domElement) {
28
+ var _this;
29
+ _classCallCheck(this, TransformControls);
30
+ _this = _callSuper(this, TransformControls);
31
+ if (domElement === undefined) {
32
+ console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.');
33
+ domElement = document;
34
+ }
35
+ _this.isTransformControls = true;
36
+ _this.visible = false;
37
+ _this.domElement = domElement;
38
+ _this.domElement.style.touchAction = 'none'; // disable touch scroll
39
+
40
+ var _gizmo = new TransformControlsGizmo();
41
+ _this._gizmo = _gizmo;
42
+ _this.add(_gizmo);
43
+ var _plane = new TransformControlsPlane();
44
+ _this._plane = _plane;
45
+ _this.add(_plane);
46
+ var scope = _this;
47
+
48
+ // Defined getter, setter and store for a property
49
+ function defineProperty(propName, defaultValue) {
50
+ var propValue = defaultValue;
51
+ Object.defineProperty(scope, propName, {
52
+ get: function get() {
53
+ return propValue !== undefined ? propValue : defaultValue;
54
+ },
55
+ set: function set(value) {
56
+ if (propValue !== value) {
57
+ propValue = value;
58
+ _plane[propName] = value;
59
+ _gizmo[propName] = value;
60
+ scope.dispatchEvent({
61
+ type: propName + '-changed',
62
+ value: value
63
+ });
64
+ scope.dispatchEvent(_changeEvent);
65
+ }
66
+ }
67
+ });
68
+ scope[propName] = defaultValue;
69
+ _plane[propName] = defaultValue;
70
+ _gizmo[propName] = defaultValue;
71
+ }
72
+
73
+ // Define properties with getters/setter
74
+ // Setting the defined property will automatically trigger change event
75
+ // Defined properties are passed down to gizmo and plane
76
+
77
+ defineProperty('camera', camera);
78
+ defineProperty('object', undefined);
79
+ defineProperty('enabled', true);
80
+ defineProperty('axis', null);
81
+ defineProperty('mode', 'translate');
82
+ defineProperty('translationSnap', null);
83
+ defineProperty('rotationSnap', null);
84
+ defineProperty('scaleSnap', null);
85
+ defineProperty('space', 'world');
86
+ defineProperty('size', 1);
87
+ defineProperty('dragging', false);
88
+ defineProperty('showX', true);
89
+ defineProperty('showY', true);
90
+ defineProperty('showZ', true);
91
+ defineProperty('showXY', true);
92
+ defineProperty('showYZ', true);
93
+ defineProperty('showXZ', true);
94
+
95
+ // Click timing delay configuration
96
+ _this.clickDelay = null;
97
+ _this.lastInteractionTime = 0;
98
+
99
+ // Reusable utility variables
100
+
101
+ var worldPosition = new Vector3();
102
+ var worldPositionStart = new Vector3();
103
+ var worldQuaternion = new Quaternion();
104
+ var worldQuaternionStart = new Quaternion();
105
+ var cameraPosition = new Vector3();
106
+ var cameraQuaternion = new Quaternion();
107
+ var pointStart = new Vector3();
108
+ var pointEnd = new Vector3();
109
+ var rotationAxis = new Vector3();
110
+ var rotationAngle = 0;
111
+ var eye = new Vector3();
112
+
113
+ // TODO: remove properties unused in plane and gizmo
114
+
115
+ defineProperty('worldPosition', worldPosition);
116
+ defineProperty('worldPositionStart', worldPositionStart);
117
+ defineProperty('worldQuaternion', worldQuaternion);
118
+ defineProperty('worldQuaternionStart', worldQuaternionStart);
119
+ defineProperty('cameraPosition', cameraPosition);
120
+ defineProperty('cameraQuaternion', cameraQuaternion);
121
+ defineProperty('pointStart', pointStart);
122
+ defineProperty('pointEnd', pointEnd);
123
+ defineProperty('rotationAxis', rotationAxis);
124
+ defineProperty('rotationAngle', rotationAngle);
125
+ defineProperty('eye', eye);
126
+ _this._offset = new Vector3();
127
+ _this._startNorm = new Vector3();
128
+ _this._endNorm = new Vector3();
129
+ _this._cameraScale = new Vector3();
130
+ _this._parentPosition = new Vector3();
131
+ _this._parentQuaternion = new Quaternion();
132
+ _this._parentQuaternionInv = new Quaternion();
133
+ _this._parentScale = new Vector3();
134
+ _this._worldScaleStart = new Vector3();
135
+ _this._worldQuaternionInv = new Quaternion();
136
+ _this._worldScale = new Vector3();
137
+ _this._positionStart = new Vector3();
138
+ _this._quaternionStart = new Quaternion();
139
+ _this._scaleStart = new Vector3();
140
+ _this._getPointer = getPointer.bind(_this);
141
+ _this._onPointerDown = onPointerDown.bind(_this);
142
+ _this._onPointerHover = onPointerHover.bind(_this);
143
+ _this._onPointerMove = onPointerMove.bind(_this);
144
+ _this._onPointerUp = onPointerUp.bind(_this);
145
+ _this.domElement.addEventListener('pointerdown', _this._onPointerDown);
146
+ _this.domElement.addEventListener('pointermove', _this._onPointerHover);
147
+ _this.domElement.addEventListener('pointerup', _this._onPointerUp);
148
+ return _this;
149
+ }
150
+
151
+ // updateMatrixWorld updates key transformation variables
152
+ _inherits(TransformControls, _Object3D);
153
+ return _createClass(TransformControls, [{
154
+ key: "updateMatrixWorld",
155
+ value: function updateMatrixWorld() {
156
+ if (this.object !== undefined) {
157
+ this.object.updateMatrixWorld();
158
+ if (this.object.parent === null) {
159
+ console.error('TransformControls: The attached 3D object must be a part of the scene graph.');
160
+ } else {
161
+ this.object.parent.matrixWorld.decompose(this._parentPosition, this._parentQuaternion, this._parentScale);
162
+ }
163
+ this.object.matrixWorld.decompose(this.worldPosition, this.worldQuaternion, this._worldScale);
164
+ this._parentQuaternionInv.copy(this._parentQuaternion).invert();
165
+ this._worldQuaternionInv.copy(this.worldQuaternion).invert();
166
+ }
167
+ this.camera.updateMatrixWorld();
168
+ this.camera.matrixWorld.decompose(this.cameraPosition, this.cameraQuaternion, this._cameraScale);
169
+ if (this.camera.isOrthographicCamera) {
170
+ this.camera.getWorldDirection(this.eye).negate();
171
+ } else {
172
+ this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize();
173
+ }
174
+ _superPropGet(TransformControls, "updateMatrixWorld", this, 3)([this]);
175
+ }
176
+ }, {
177
+ key: "pointerHover",
178
+ value: function pointerHover(pointer) {
179
+ if (this.object === undefined || this.dragging === true) return;
180
+
181
+ // Check if we should delay interactions based on click timing
182
+ if (this.clickDelay && this.clickDelay.doubleClickDelay) {
183
+ var currentTime = Date.now();
184
+ var timeSinceLastInteraction = currentTime - this.lastInteractionTime;
185
+
186
+ // If not enough time has passed since last interaction, ignore hover
187
+ if (timeSinceLastInteraction < this.clickDelay.doubleClickDelay) {
188
+ return;
189
+ }
190
+ }
191
+ _raycaster.setFromCamera(pointer, this.camera);
192
+ var intersect = intersectObjectWithRay(this._gizmo.picker[this.mode], _raycaster);
193
+ if (intersect) {
194
+ this.axis = intersect.object.name;
195
+ } else {
196
+ this.axis = null;
197
+ }
198
+ }
199
+ }, {
200
+ key: "pointerDown",
201
+ value: function pointerDown(pointer) {
202
+ if (this.object === undefined || this.dragging === true || pointer.button !== 0) return;
203
+
204
+ // Check if we should delay interactions based on click timing
205
+ if (this.clickDelay && this.clickDelay.doubleClickDelay) {
206
+ var currentTime = Date.now();
207
+ var timeSinceLastInteraction = currentTime - this.lastInteractionTime;
208
+
209
+ // If not enough time has passed since last interaction, ignore this input
210
+ if (timeSinceLastInteraction < this.clickDelay.doubleClickDelay) {
211
+ return;
212
+ }
213
+
214
+ // Update last interaction time
215
+ this.lastInteractionTime = currentTime;
216
+ }
217
+ if (this.axis !== null) {
218
+ _raycaster.setFromCamera(pointer, this.camera);
219
+ var planeIntersect = intersectObjectWithRay(this._plane, _raycaster, true);
220
+ if (planeIntersect) {
221
+ this.object.updateMatrixWorld();
222
+ this.object.parent.updateMatrixWorld();
223
+ this._positionStart.copy(this.object.position);
224
+ this._quaternionStart.copy(this.object.quaternion);
225
+ this._scaleStart.copy(this.object.scale);
226
+ this.object.matrixWorld.decompose(this.worldPositionStart, this.worldQuaternionStart, this._worldScaleStart);
227
+ this.pointStart.copy(planeIntersect.point).sub(this.worldPositionStart);
228
+ }
229
+ this.dragging = true;
230
+ _mouseDownEvent.mode = this.mode;
231
+ this.dispatchEvent(_mouseDownEvent);
232
+ }
233
+ }
234
+ }, {
235
+ key: "pointerMove",
236
+ value: function pointerMove(pointer) {
237
+ var axis = this.axis;
238
+ var mode = this.mode;
239
+ var object = this.object;
240
+ var space = this.space;
241
+ if (mode === 'scale') {
242
+ space = 'local';
243
+ } else if (axis === 'E' || axis === 'XYZE' || axis === 'XYZ') {
244
+ space = 'world';
245
+ }
246
+ if (object === undefined || axis === null || this.dragging === false || pointer.button !== -1) return;
247
+ _raycaster.setFromCamera(pointer, this.camera);
248
+ var planeIntersect = intersectObjectWithRay(this._plane, _raycaster, true);
249
+ if (!planeIntersect) return;
250
+ this.pointEnd.copy(planeIntersect.point).sub(this.worldPositionStart);
251
+ if (mode === 'translate') {
252
+ // Apply translate
253
+
254
+ this._offset.copy(this.pointEnd).sub(this.pointStart);
255
+ if (space === 'local' && axis !== 'XYZ') {
256
+ this._offset.applyQuaternion(this._worldQuaternionInv);
257
+ }
258
+ if (axis.indexOf('X') === -1) this._offset.x = 0;
259
+ if (axis.indexOf('Y') === -1) this._offset.y = 0;
260
+ if (axis.indexOf('Z') === -1) this._offset.z = 0;
261
+ if (space === 'local' && axis !== 'XYZ') {
262
+ this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale);
263
+ } else {
264
+ this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale);
265
+ }
266
+ object.position.copy(this._offset).add(this._positionStart);
267
+
268
+ // Apply translation snap
269
+
270
+ if (this.translationSnap) {
271
+ if (space === 'local') {
272
+ object.position.applyQuaternion(_tempQuaternion.copy(this._quaternionStart).invert());
273
+ if (axis.search('X') !== -1) {
274
+ object.position.x = Math.round(object.position.x / this.translationSnap) * this.translationSnap;
275
+ }
276
+ if (axis.search('Y') !== -1) {
277
+ object.position.y = Math.round(object.position.y / this.translationSnap) * this.translationSnap;
278
+ }
279
+ if (axis.search('Z') !== -1) {
280
+ object.position.z = Math.round(object.position.z / this.translationSnap) * this.translationSnap;
281
+ }
282
+ object.position.applyQuaternion(this._quaternionStart);
283
+ }
284
+ if (space === 'world') {
285
+ if (object.parent) {
286
+ object.position.add(_tempVector.setFromMatrixPosition(object.parent.matrixWorld));
287
+ }
288
+ if (axis.search('X') !== -1) {
289
+ object.position.x = Math.round(object.position.x / this.translationSnap) * this.translationSnap;
290
+ }
291
+ if (axis.search('Y') !== -1) {
292
+ object.position.y = Math.round(object.position.y / this.translationSnap) * this.translationSnap;
293
+ }
294
+ if (axis.search('Z') !== -1) {
295
+ object.position.z = Math.round(object.position.z / this.translationSnap) * this.translationSnap;
296
+ }
297
+ if (object.parent) {
298
+ object.position.sub(_tempVector.setFromMatrixPosition(object.parent.matrixWorld));
299
+ }
300
+ }
301
+ }
302
+ } else if (mode === 'scale') {
303
+ if (axis.search('XYZ') !== -1) {
304
+ var d = this.pointEnd.length() / this.pointStart.length();
305
+ if (this.pointEnd.dot(this.pointStart) < 0) d *= -1;
306
+ _tempVector2.set(d, d, d);
307
+ } else {
308
+ _tempVector.copy(this.pointStart);
309
+ _tempVector2.copy(this.pointEnd);
310
+ _tempVector.applyQuaternion(this._worldQuaternionInv);
311
+ _tempVector2.applyQuaternion(this._worldQuaternionInv);
312
+ _tempVector2.divide(_tempVector);
313
+ if (axis.search('X') === -1) {
314
+ _tempVector2.x = 1;
315
+ }
316
+ if (axis.search('Y') === -1) {
317
+ _tempVector2.y = 1;
318
+ }
319
+ if (axis.search('Z') === -1) {
320
+ _tempVector2.z = 1;
321
+ }
322
+ }
323
+
324
+ // Apply scale
325
+
326
+ object.scale.copy(this._scaleStart).multiply(_tempVector2);
327
+ if (this.scaleSnap) {
328
+ if (axis.search('X') !== -1) {
329
+ object.scale.x = Math.round(object.scale.x / this.scaleSnap) * this.scaleSnap || this.scaleSnap;
330
+ }
331
+ if (axis.search('Y') !== -1) {
332
+ object.scale.y = Math.round(object.scale.y / this.scaleSnap) * this.scaleSnap || this.scaleSnap;
333
+ }
334
+ if (axis.search('Z') !== -1) {
335
+ object.scale.z = Math.round(object.scale.z / this.scaleSnap) * this.scaleSnap || this.scaleSnap;
336
+ }
337
+ }
338
+ } else if (mode === 'rotate') {
339
+ this._offset.copy(this.pointEnd).sub(this.pointStart);
340
+ var ROTATION_SPEED = 20 / this.worldPosition.distanceTo(_tempVector.setFromMatrixPosition(this.camera.matrixWorld));
341
+ if (axis === 'E') {
342
+ this.rotationAxis.copy(this.eye);
343
+ this.rotationAngle = this.pointEnd.angleTo(this.pointStart);
344
+ this._startNorm.copy(this.pointStart).normalize();
345
+ this._endNorm.copy(this.pointEnd).normalize();
346
+ this.rotationAngle *= this._endNorm.cross(this._startNorm).dot(this.eye) < 0 ? 1 : -1;
347
+ } else if (axis === 'XYZE') {
348
+ this.rotationAxis.copy(this._offset).cross(this.eye).normalize();
349
+ this.rotationAngle = this._offset.dot(_tempVector.copy(this.rotationAxis).cross(this.eye)) * ROTATION_SPEED;
350
+ } else if (axis === 'X' || axis === 'Y' || axis === 'Z') {
351
+ this.rotationAxis.copy(_unit[axis]);
352
+ _tempVector.copy(_unit[axis]);
353
+ if (space === 'local') {
354
+ _tempVector.applyQuaternion(this.worldQuaternion);
355
+ }
356
+ this.rotationAngle = this._offset.dot(_tempVector.cross(this.eye).normalize()) * ROTATION_SPEED;
357
+ }
358
+
359
+ // Apply rotation snap
360
+
361
+ if (this.rotationSnap) this.rotationAngle = Math.round(this.rotationAngle / this.rotationSnap) * this.rotationSnap;
362
+
363
+ // Apply rotate
364
+ if (space === 'local' && axis !== 'E' && axis !== 'XYZE') {
365
+ object.quaternion.copy(this._quaternionStart);
366
+ object.quaternion.multiply(_tempQuaternion.setFromAxisAngle(this.rotationAxis, this.rotationAngle)).normalize();
367
+ } else {
368
+ this.rotationAxis.applyQuaternion(this._parentQuaternionInv);
369
+ object.quaternion.copy(_tempQuaternion.setFromAxisAngle(this.rotationAxis, this.rotationAngle));
370
+ object.quaternion.multiply(this._quaternionStart).normalize();
371
+ }
372
+ }
373
+ this.dispatchEvent(_changeEvent);
374
+ this.dispatchEvent(_objectChangeEvent);
375
+ }
376
+ }, {
377
+ key: "pointerUp",
378
+ value: function pointerUp(pointer) {
379
+ if (pointer.button !== 0) return;
380
+ if (this.dragging && this.axis !== null) {
381
+ _mouseUpEvent.mode = this.mode;
382
+ this.dispatchEvent(_mouseUpEvent);
383
+ }
384
+ this.dragging = false;
385
+ this.axis = null;
386
+ }
387
+ }, {
388
+ key: "dispose",
389
+ value: function dispose() {
390
+ this.domElement.removeEventListener('pointerdown', this._onPointerDown);
391
+ this.domElement.removeEventListener('pointermove', this._onPointerHover);
392
+ this.domElement.removeEventListener('pointermove', this._onPointerMove);
393
+ this.domElement.removeEventListener('pointerup', this._onPointerUp);
394
+ this.traverse(function (child) {
395
+ if (child.geometry) child.geometry.dispose();
396
+ if (child.material) child.material.dispose();
397
+ });
398
+ }
399
+
400
+ // Set current object
401
+ }, {
402
+ key: "attach",
403
+ value: function attach(object) {
404
+ this.object = object;
405
+ this.visible = true;
406
+ return this;
407
+ }
408
+
409
+ // Detach from object
410
+ }, {
411
+ key: "detach",
412
+ value: function detach() {
413
+ this.object = undefined;
414
+ this.visible = false;
415
+ this.axis = null;
416
+ return this;
417
+ }
418
+ }, {
419
+ key: "reset",
420
+ value: function reset() {
421
+ if (!this.enabled) return;
422
+ if (this.dragging) {
423
+ this.object.position.copy(this._positionStart);
424
+ this.object.quaternion.copy(this._quaternionStart);
425
+ this.object.scale.copy(this._scaleStart);
426
+ this.dispatchEvent(_changeEvent);
427
+ this.dispatchEvent(_objectChangeEvent);
428
+ this.pointStart.copy(this.pointEnd);
429
+ }
430
+ }
431
+ }, {
432
+ key: "getRaycaster",
433
+ value: function getRaycaster() {
434
+ return _raycaster;
435
+ }
436
+
437
+ // TODO: deprecate
438
+ }, {
439
+ key: "getMode",
440
+ value: function getMode() {
441
+ return this.mode;
442
+ }
443
+ }, {
444
+ key: "setMode",
445
+ value: function setMode(mode) {
446
+ this.mode = mode;
447
+ }
448
+ }, {
449
+ key: "setTranslationSnap",
450
+ value: function setTranslationSnap(translationSnap) {
451
+ this.translationSnap = translationSnap;
452
+ }
453
+ }, {
454
+ key: "setRotationSnap",
455
+ value: function setRotationSnap(rotationSnap) {
456
+ this.rotationSnap = rotationSnap;
457
+ }
458
+ }, {
459
+ key: "setScaleSnap",
460
+ value: function setScaleSnap(scaleSnap) {
461
+ this.scaleSnap = scaleSnap;
462
+ }
463
+ }, {
464
+ key: "setSize",
465
+ value: function setSize(size) {
466
+ this.size = size;
467
+ }
468
+ }, {
469
+ key: "setSpace",
470
+ value: function setSpace(space) {
471
+ this.space = space;
472
+ }
473
+ }, {
474
+ key: "setDelay",
475
+ value: function setDelay(clickTiming) {
476
+ this.clickDelay = clickTiming;
477
+ }
478
+ }, {
479
+ key: "updateInteractionTime",
480
+ value: function updateInteractionTime() {
481
+ this.lastInteractionTime = Date.now();
482
+ }
483
+ }]);
484
+ }(Object3D); // mouse / touch event handlers
485
+ function getPointer(event) {
486
+ if (this.domElement.ownerDocument.pointerLockElement) {
487
+ return {
488
+ x: 0,
489
+ y: 0,
490
+ button: event.button
491
+ };
492
+ } else {
493
+ var rect = this.domElement.getBoundingClientRect();
494
+ return {
495
+ x: (event.clientX - rect.left) / rect.width * 2 - 1,
496
+ y: -(event.clientY - rect.top) / rect.height * 2 + 1,
497
+ button: event.button
498
+ };
499
+ }
500
+ }
501
+ function onPointerHover(event) {
502
+ if (!this.enabled) return;
503
+ switch (event.pointerType) {
504
+ case 'mouse':
505
+ case 'pen':
506
+ this.pointerHover(this._getPointer(event));
507
+ break;
508
+ }
509
+ }
510
+ function onPointerDown(event) {
511
+ if (!this.enabled) return;
512
+ if (!document.pointerLockElement) {
513
+ this.domElement.setPointerCapture(event.pointerId);
514
+ }
515
+ this.domElement.addEventListener('pointermove', this._onPointerMove);
516
+ this.pointerHover(this._getPointer(event));
517
+ this.pointerDown(this._getPointer(event));
518
+ }
519
+ function onPointerMove(event) {
520
+ if (!this.enabled) return;
521
+ this.pointerMove(this._getPointer(event));
522
+ }
523
+ function onPointerUp(event) {
524
+ if (!this.enabled) return;
525
+ this.domElement.releasePointerCapture(event.pointerId);
526
+ this.domElement.removeEventListener('pointermove', this._onPointerMove);
527
+ this.pointerUp(this._getPointer(event));
528
+ }
529
+ function intersectObjectWithRay(object, raycaster, includeInvisible) {
530
+ var allIntersections = raycaster.intersectObject(object, true);
531
+ for (var i = 0; i < allIntersections.length; i++) {
532
+ if (allIntersections[i].object.visible || includeInvisible) {
533
+ return allIntersections[i];
534
+ }
535
+ }
536
+ return false;
537
+ }
538
+
539
+ //
540
+
541
+ // Reusable utility variables
542
+
543
+ var _tempEuler = new Euler();
544
+ var _alignVector = new Vector3(0, 1, 0);
545
+ var _zeroVector = new Vector3(0, 0, 0);
546
+ var _lookAtMatrix = new Matrix4();
547
+ var _tempQuaternion2 = new Quaternion();
548
+ var _identityQuaternion = new Quaternion();
549
+ var _dirVector = new Vector3();
550
+ var _tempMatrix = new Matrix4();
551
+ var _unitX = new Vector3(1, 0, 0);
552
+ var _unitY = new Vector3(0, 1, 0);
553
+ var _unitZ = new Vector3(0, 0, 1);
554
+ var _v1 = new Vector3();
555
+ var _v2 = new Vector3();
556
+ var _v3 = new Vector3();
557
+ var TransformControlsGizmo = /*#__PURE__*/function (_Object3D2) {
558
+ function TransformControlsGizmo() {
559
+ var _this2;
560
+ _classCallCheck(this, TransformControlsGizmo);
561
+ _this2 = _callSuper(this, TransformControlsGizmo);
562
+ _this2.isTransformControlsGizmo = true;
563
+ _this2.type = 'TransformControlsGizmo';
564
+
565
+ // shared materials
566
+
567
+ var gizmoMaterial = new MeshBasicMaterial({
568
+ depthTest: false,
569
+ depthWrite: false,
570
+ fog: false,
571
+ toneMapped: false,
572
+ transparent: true
573
+ });
574
+ var gizmoLineMaterial = new LineBasicMaterial({
575
+ depthTest: false,
576
+ depthWrite: false,
577
+ fog: false,
578
+ toneMapped: false,
579
+ transparent: true
580
+ });
581
+
582
+ // Make unique material for each axis/color
583
+
584
+ var matInvisible = gizmoMaterial.clone();
585
+ matInvisible.opacity = 0.15;
586
+ var matHelper = gizmoLineMaterial.clone();
587
+ matHelper.opacity = 0.5;
588
+ var matRed = gizmoMaterial.clone();
589
+ matRed.color.setHex(0xff0000);
590
+ var matGreen = gizmoMaterial.clone();
591
+ matGreen.color.setHex(0x00ff00);
592
+ var matBlue = gizmoMaterial.clone();
593
+ matBlue.color.setHex(0x0000ff);
594
+ var matRedTransparent = gizmoMaterial.clone();
595
+ matRedTransparent.color.setHex(0xff0000);
596
+ matRedTransparent.opacity = 0.5;
597
+ var matGreenTransparent = gizmoMaterial.clone();
598
+ matGreenTransparent.color.setHex(0x00ff00);
599
+ matGreenTransparent.opacity = 0.5;
600
+ var matBlueTransparent = gizmoMaterial.clone();
601
+ matBlueTransparent.color.setHex(0x0000ff);
602
+ matBlueTransparent.opacity = 0.5;
603
+ var matWhiteTransparent = gizmoMaterial.clone();
604
+ matWhiteTransparent.opacity = 0.25;
605
+ var matYellowTransparent = gizmoMaterial.clone();
606
+ matYellowTransparent.color.setHex(0xffff00);
607
+ matYellowTransparent.opacity = 0.25;
608
+ var matYellow = gizmoMaterial.clone();
609
+ matYellow.color.setHex(0xffff00);
610
+ var matGray = gizmoMaterial.clone();
611
+ matGray.color.setHex(0x787878);
612
+
613
+ // reusable geometry
614
+
615
+ var arrowGeometry = new CylinderGeometry(0, 0.04, 0.1, 12);
616
+ arrowGeometry.translate(0, 0.05, 0);
617
+ var scaleHandleGeometry = new BoxGeometry(0.08, 0.08, 0.08);
618
+ scaleHandleGeometry.translate(0, 0.04, 0);
619
+ var lineGeometry = new BufferGeometry();
620
+ lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 1, 0, 0], 3));
621
+ var lineGeometry2 = new CylinderGeometry(0.0075, 0.0075, 0.5, 3);
622
+ lineGeometry2.translate(0, 0.25, 0);
623
+ function CircleGeometry(radius, arc) {
624
+ var geometry = new TorusGeometry(radius, 0.0075, 3, 64, arc * Math.PI * 2);
625
+ geometry.rotateY(Math.PI / 2);
626
+ geometry.rotateX(Math.PI / 2);
627
+ return geometry;
628
+ }
629
+
630
+ // Special geometry for transform helper. If scaled with position vector it spans from [0,0,0] to position
631
+
632
+ function TranslateHelperGeometry() {
633
+ var geometry = new BufferGeometry();
634
+ geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 1, 1, 1], 3));
635
+ return geometry;
636
+ }
637
+
638
+ // Gizmo definitions - custom hierarchy definitions for setupGizmo() function
639
+
640
+ var gizmoTranslate = {
641
+ X: [[new Mesh(arrowGeometry, matRed), [0.5, 0, 0], [0, 0, -Math.PI / 2]], [new Mesh(arrowGeometry, matRed), [-0.5, 0, 0], [0, 0, Math.PI / 2]], [new Mesh(lineGeometry2, matRed), [0, 0, 0], [0, 0, -Math.PI / 2]]],
642
+ Y: [[new Mesh(arrowGeometry, matGreen), [0, 0.5, 0]], [new Mesh(arrowGeometry, matGreen), [0, -0.5, 0], [Math.PI, 0, 0]], [new Mesh(lineGeometry2, matGreen)]],
643
+ Z: [[new Mesh(arrowGeometry, matBlue), [0, 0, 0.5], [Math.PI / 2, 0, 0]], [new Mesh(arrowGeometry, matBlue), [0, 0, -0.5], [-Math.PI / 2, 0, 0]], [new Mesh(lineGeometry2, matBlue), null, [Math.PI / 2, 0, 0]]],
644
+ XYZ: [[new Mesh(new OctahedronGeometry(0.1, 0), matWhiteTransparent.clone()), [0, 0, 0]]],
645
+ XY: [[new Mesh(new BoxGeometry(0.15, 0.15, 0.01), matBlueTransparent.clone()), [0.15, 0.15, 0]]],
646
+ YZ: [[new Mesh(new BoxGeometry(0.15, 0.15, 0.01), matRedTransparent.clone()), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]],
647
+ XZ: [[new Mesh(new BoxGeometry(0.15, 0.15, 0.01), matGreenTransparent.clone()), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]]
648
+ };
649
+ var pickerTranslate = {
650
+ X: [[new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0.3, 0, 0], [0, 0, -Math.PI / 2]], [new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [-0.3, 0, 0], [0, 0, Math.PI / 2]]],
651
+ Y: [[new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0.3, 0]], [new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, -0.3, 0], [0, 0, Math.PI]]],
652
+ Z: [[new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, 0.3], [Math.PI / 2, 0, 0]], [new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, -0.3], [-Math.PI / 2, 0, 0]]],
653
+ XYZ: [[new Mesh(new OctahedronGeometry(0.2, 0), matInvisible)]],
654
+ XY: [[new Mesh(new BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0.15, 0]]],
655
+ YZ: [[new Mesh(new BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]],
656
+ XZ: [[new Mesh(new BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]]
657
+ };
658
+ var helperTranslate = {
659
+ START: [[new Mesh(new OctahedronGeometry(0.01, 2), matHelper), null, null, null, 'helper']],
660
+ END: [[new Mesh(new OctahedronGeometry(0.01, 2), matHelper), null, null, null, 'helper']],
661
+ DELTA: [[new Line(TranslateHelperGeometry(), matHelper), null, null, null, 'helper']],
662
+ X: [[new Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']],
663
+ Y: [[new Line(lineGeometry, matHelper.clone()), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], 'helper']],
664
+ Z: [[new Line(lineGeometry, matHelper.clone()), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], 'helper']]
665
+ };
666
+ var gizmoRotate = {
667
+ XYZE: [[new Mesh(CircleGeometry(0.5, 1), matGray), null, [0, Math.PI / 2, 0]]],
668
+ X: [[new Mesh(CircleGeometry(0.5, 0.5), matRed)]],
669
+ Y: [[new Mesh(CircleGeometry(0.5, 0.5), matGreen), null, [0, 0, -Math.PI / 2]]],
670
+ Z: [[new Mesh(CircleGeometry(0.5, 0.5), matBlue), null, [0, Math.PI / 2, 0]]],
671
+ E: [[new Mesh(CircleGeometry(0.75, 1), matYellowTransparent), null, [0, Math.PI / 2, 0]]]
672
+ };
673
+ var helperRotate = {
674
+ AXIS: [[new Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']]
675
+ };
676
+ var pickerRotate = {
677
+ XYZE: [[new Mesh(new SphereGeometry(0.25, 10, 8), matInvisible)]],
678
+ X: [[new Mesh(new TorusGeometry(0.5, 0.1, 4, 24), matInvisible), [0, 0, 0], [0, -Math.PI / 2, -Math.PI / 2]]],
679
+ Y: [[new Mesh(new TorusGeometry(0.5, 0.1, 4, 24), matInvisible), [0, 0, 0], [Math.PI / 2, 0, 0]]],
680
+ Z: [[new Mesh(new TorusGeometry(0.5, 0.1, 4, 24), matInvisible), [0, 0, 0], [0, 0, -Math.PI / 2]]],
681
+ E: [[new Mesh(new TorusGeometry(0.75, 0.1, 2, 24), matInvisible)]]
682
+ };
683
+ var gizmoScale = {
684
+ X: [[new Mesh(scaleHandleGeometry, matRed), [0.5, 0, 0], [0, 0, -Math.PI / 2]], [new Mesh(lineGeometry2, matRed), [0, 0, 0], [0, 0, -Math.PI / 2]], [new Mesh(scaleHandleGeometry, matRed), [-0.5, 0, 0], [0, 0, Math.PI / 2]]],
685
+ Y: [[new Mesh(scaleHandleGeometry, matGreen), [0, 0.5, 0]], [new Mesh(lineGeometry2, matGreen)], [new Mesh(scaleHandleGeometry, matGreen), [0, -0.5, 0], [0, 0, Math.PI]]],
686
+ Z: [[new Mesh(scaleHandleGeometry, matBlue), [0, 0, 0.5], [Math.PI / 2, 0, 0]], [new Mesh(lineGeometry2, matBlue), [0, 0, 0], [Math.PI / 2, 0, 0]], [new Mesh(scaleHandleGeometry, matBlue), [0, 0, -0.5], [-Math.PI / 2, 0, 0]]],
687
+ XY: [[new Mesh(new BoxGeometry(0.15, 0.15, 0.01), matBlueTransparent), [0.15, 0.15, 0]]],
688
+ YZ: [[new Mesh(new BoxGeometry(0.15, 0.15, 0.01), matRedTransparent), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]],
689
+ XZ: [[new Mesh(new BoxGeometry(0.15, 0.15, 0.01), matGreenTransparent), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]],
690
+ XYZ: [[new Mesh(new BoxGeometry(0.1, 0.1, 0.1), matWhiteTransparent.clone())]]
691
+ };
692
+ var pickerScale = {
693
+ X: [[new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0.3, 0, 0], [0, 0, -Math.PI / 2]], [new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [-0.3, 0, 0], [0, 0, Math.PI / 2]]],
694
+ Y: [[new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0.3, 0]], [new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, -0.3, 0], [0, 0, Math.PI]]],
695
+ Z: [[new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, 0.3], [Math.PI / 2, 0, 0]], [new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, -0.3], [-Math.PI / 2, 0, 0]]],
696
+ XY: [[new Mesh(new BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0.15, 0]]],
697
+ YZ: [[new Mesh(new BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]],
698
+ XZ: [[new Mesh(new BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]],
699
+ XYZ: [[new Mesh(new BoxGeometry(0.2, 0.2, 0.2), matInvisible), [0, 0, 0]]]
700
+ };
701
+ var helperScale = {
702
+ X: [[new Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']],
703
+ Y: [[new Line(lineGeometry, matHelper.clone()), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], 'helper']],
704
+ Z: [[new Line(lineGeometry, matHelper.clone()), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], 'helper']]
705
+ };
706
+
707
+ // Creates an Object3D with gizmos described in custom hierarchy definition.
708
+
709
+ function setupGizmo(gizmoMap) {
710
+ var gizmo = new Object3D();
711
+ for (var name in gizmoMap) {
712
+ for (var i = gizmoMap[name].length; i--;) {
713
+ var object = gizmoMap[name][i][0].clone();
714
+ var position = gizmoMap[name][i][1];
715
+ var rotation = gizmoMap[name][i][2];
716
+ var scale = gizmoMap[name][i][3];
717
+ var tag = gizmoMap[name][i][4];
718
+
719
+ // name and tag properties are essential for picking and updating logic.
720
+ object.name = name;
721
+ object.tag = tag;
722
+ if (position) {
723
+ object.position.set(position[0], position[1], position[2]);
724
+ }
725
+ if (rotation) {
726
+ object.rotation.set(rotation[0], rotation[1], rotation[2]);
727
+ }
728
+ if (scale) {
729
+ object.scale.set(scale[0], scale[1], scale[2]);
730
+ }
731
+ object.updateMatrix();
732
+ var tempGeometry = object.geometry.clone();
733
+ tempGeometry.applyMatrix4(object.matrix);
734
+ object.geometry = tempGeometry;
735
+ object.renderOrder = Infinity;
736
+ object.position.set(0, 0, 0);
737
+ object.rotation.set(0, 0, 0);
738
+ object.scale.set(1, 1, 1);
739
+ gizmo.add(object);
740
+ }
741
+ }
742
+ return gizmo;
743
+ }
744
+
745
+ // Gizmo creation
746
+
747
+ _this2.gizmo = {};
748
+ _this2.picker = {};
749
+ _this2.helper = {};
750
+ _this2.add(_this2.gizmo['translate'] = setupGizmo(gizmoTranslate));
751
+ _this2.add(_this2.gizmo['rotate'] = setupGizmo(gizmoRotate));
752
+ _this2.add(_this2.gizmo['scale'] = setupGizmo(gizmoScale));
753
+ _this2.add(_this2.picker['translate'] = setupGizmo(pickerTranslate));
754
+ _this2.add(_this2.picker['rotate'] = setupGizmo(pickerRotate));
755
+ _this2.add(_this2.picker['scale'] = setupGizmo(pickerScale));
756
+ _this2.add(_this2.helper['translate'] = setupGizmo(helperTranslate));
757
+ _this2.add(_this2.helper['rotate'] = setupGizmo(helperRotate));
758
+ _this2.add(_this2.helper['scale'] = setupGizmo(helperScale));
759
+
760
+ // Pickers should be hidden always
761
+
762
+ _this2.picker['translate'].visible = false;
763
+ _this2.picker['rotate'].visible = false;
764
+ _this2.picker['scale'].visible = false;
765
+ return _this2;
766
+ }
767
+
768
+ // updateMatrixWorld will update transformations and appearance of individual handles
769
+ _inherits(TransformControlsGizmo, _Object3D2);
770
+ return _createClass(TransformControlsGizmo, [{
771
+ key: "updateMatrixWorld",
772
+ value: function updateMatrixWorld(force) {
773
+ var _this3 = this;
774
+ var space = this.mode === 'scale' ? 'local' : this.space; // scale always oriented to local rotation
775
+
776
+ var quaternion = space === 'local' ? this.worldQuaternion : _identityQuaternion;
777
+
778
+ // Show only gizmos for current transform mode
779
+
780
+ this.gizmo['translate'].visible = this.mode === 'translate';
781
+ this.gizmo['rotate'].visible = this.mode === 'rotate';
782
+ this.gizmo['scale'].visible = this.mode === 'scale';
783
+ this.helper['translate'].visible = this.mode === 'translate';
784
+ this.helper['rotate'].visible = this.mode === 'rotate';
785
+ this.helper['scale'].visible = this.mode === 'scale';
786
+ var handles = [];
787
+ handles = handles.concat(this.picker[this.mode].children);
788
+ handles = handles.concat(this.gizmo[this.mode].children);
789
+ handles = handles.concat(this.helper[this.mode].children);
790
+ var _loop = function _loop() {
791
+ var handle = handles[i];
792
+
793
+ // hide aligned to camera
794
+
795
+ handle.visible = true;
796
+ handle.rotation.set(0, 0, 0);
797
+ handle.position.copy(_this3.worldPosition);
798
+ var factor;
799
+ if (_this3.camera.isOrthographicCamera) {
800
+ factor = (_this3.camera.top - _this3.camera.bottom) / _this3.camera.zoom;
801
+ } else {
802
+ factor = _this3.worldPosition.distanceTo(_this3.cameraPosition) * Math.min(1.9 * Math.tan(Math.PI * _this3.camera.fov / 360) / _this3.camera.zoom, 7);
803
+ }
804
+ handle.scale.set(1, 1, 1).multiplyScalar(factor * _this3.size / 4);
805
+
806
+ // TODO: simplify helpers and consider decoupling from gizmo
807
+
808
+ if (handle.tag === 'helper') {
809
+ handle.visible = false;
810
+ if (handle.name === 'AXIS') {
811
+ handle.visible = !!_this3.axis;
812
+ if (_this3.axis === 'X') {
813
+ _tempQuaternion.setFromEuler(_tempEuler.set(0, 0, 0));
814
+ handle.quaternion.copy(quaternion).multiply(_tempQuaternion);
815
+ if (Math.abs(_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(_this3.eye)) > 0.9) {
816
+ handle.visible = false;
817
+ }
818
+ }
819
+ if (_this3.axis === 'Y') {
820
+ _tempQuaternion.setFromEuler(_tempEuler.set(0, 0, Math.PI / 2));
821
+ handle.quaternion.copy(quaternion).multiply(_tempQuaternion);
822
+ if (Math.abs(_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(_this3.eye)) > 0.9) {
823
+ handle.visible = false;
824
+ }
825
+ }
826
+ if (_this3.axis === 'Z') {
827
+ _tempQuaternion.setFromEuler(_tempEuler.set(0, Math.PI / 2, 0));
828
+ handle.quaternion.copy(quaternion).multiply(_tempQuaternion);
829
+ if (Math.abs(_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(_this3.eye)) > 0.9) {
830
+ handle.visible = false;
831
+ }
832
+ }
833
+ if (_this3.axis === 'XYZE') {
834
+ _tempQuaternion.setFromEuler(_tempEuler.set(0, Math.PI / 2, 0));
835
+ _alignVector.copy(_this3.rotationAxis);
836
+ handle.quaternion.setFromRotationMatrix(_lookAtMatrix.lookAt(_zeroVector, _alignVector, _unitY));
837
+ handle.quaternion.multiply(_tempQuaternion);
838
+ handle.visible = _this3.dragging;
839
+ }
840
+ if (_this3.axis === 'E') {
841
+ handle.visible = false;
842
+ }
843
+ } else if (handle.name === 'START') {
844
+ handle.position.copy(_this3.worldPositionStart);
845
+ handle.visible = _this3.dragging;
846
+ } else if (handle.name === 'END') {
847
+ handle.position.copy(_this3.worldPosition);
848
+ handle.visible = _this3.dragging;
849
+ } else if (handle.name === 'DELTA') {
850
+ handle.position.copy(_this3.worldPositionStart);
851
+ handle.quaternion.copy(_this3.worldQuaternionStart);
852
+ _tempVector.set(1e-10, 1e-10, 1e-10).add(_this3.worldPositionStart).sub(_this3.worldPosition).multiplyScalar(-1);
853
+ _tempVector.applyQuaternion(_this3.worldQuaternionStart.clone().invert());
854
+ handle.scale.copy(_tempVector);
855
+ handle.visible = _this3.dragging;
856
+ } else {
857
+ handle.quaternion.copy(quaternion);
858
+ if (_this3.dragging) {
859
+ handle.position.copy(_this3.worldPositionStart);
860
+ } else {
861
+ handle.position.copy(_this3.worldPosition);
862
+ }
863
+ if (_this3.axis) {
864
+ handle.visible = _this3.axis.search(handle.name) !== -1;
865
+ }
866
+ }
867
+
868
+ // If updating helper, skip rest of the loop
869
+ return 1; // continue
870
+ }
871
+
872
+ // Align handles to current local or world rotation
873
+
874
+ handle.quaternion.copy(quaternion);
875
+ if (_this3.mode === 'translate' || _this3.mode === 'scale') {
876
+ // Hide translate and scale axis facing the camera
877
+
878
+ var AXIS_HIDE_THRESHOLD = 0.99;
879
+ var PLANE_HIDE_THRESHOLD = 0.2;
880
+ if (handle.name === 'X') {
881
+ if (Math.abs(_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(_this3.eye)) > AXIS_HIDE_THRESHOLD) {
882
+ handle.scale.set(1e-10, 1e-10, 1e-10);
883
+ handle.visible = false;
884
+ }
885
+ }
886
+ if (handle.name === 'Y') {
887
+ if (Math.abs(_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(_this3.eye)) > AXIS_HIDE_THRESHOLD) {
888
+ handle.scale.set(1e-10, 1e-10, 1e-10);
889
+ handle.visible = false;
890
+ }
891
+ }
892
+ if (handle.name === 'Z') {
893
+ if (Math.abs(_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(_this3.eye)) > AXIS_HIDE_THRESHOLD) {
894
+ handle.scale.set(1e-10, 1e-10, 1e-10);
895
+ handle.visible = false;
896
+ }
897
+ }
898
+ if (handle.name === 'XY') {
899
+ if (Math.abs(_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(_this3.eye)) < PLANE_HIDE_THRESHOLD) {
900
+ handle.scale.set(1e-10, 1e-10, 1e-10);
901
+ handle.visible = false;
902
+ }
903
+ }
904
+ if (handle.name === 'YZ') {
905
+ if (Math.abs(_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(_this3.eye)) < PLANE_HIDE_THRESHOLD) {
906
+ handle.scale.set(1e-10, 1e-10, 1e-10);
907
+ handle.visible = false;
908
+ }
909
+ }
910
+ if (handle.name === 'XZ') {
911
+ if (Math.abs(_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(_this3.eye)) < PLANE_HIDE_THRESHOLD) {
912
+ handle.scale.set(1e-10, 1e-10, 1e-10);
913
+ handle.visible = false;
914
+ }
915
+ }
916
+ } else if (_this3.mode === 'rotate') {
917
+ // Align handles to current local or world rotation
918
+
919
+ _tempQuaternion2.copy(quaternion);
920
+ _alignVector.copy(_this3.eye).applyQuaternion(_tempQuaternion.copy(quaternion).invert());
921
+ if (handle.name.search('E') !== -1) {
922
+ handle.quaternion.setFromRotationMatrix(_lookAtMatrix.lookAt(_this3.eye, _zeroVector, _unitY));
923
+ }
924
+ if (handle.name === 'X') {
925
+ _tempQuaternion.setFromAxisAngle(_unitX, Math.atan2(-_alignVector.y, _alignVector.z));
926
+ _tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion);
927
+ handle.quaternion.copy(_tempQuaternion);
928
+ }
929
+ if (handle.name === 'Y') {
930
+ _tempQuaternion.setFromAxisAngle(_unitY, Math.atan2(_alignVector.x, _alignVector.z));
931
+ _tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion);
932
+ handle.quaternion.copy(_tempQuaternion);
933
+ }
934
+ if (handle.name === 'Z') {
935
+ _tempQuaternion.setFromAxisAngle(_unitZ, Math.atan2(_alignVector.y, _alignVector.x));
936
+ _tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion);
937
+ handle.quaternion.copy(_tempQuaternion);
938
+ }
939
+ }
940
+
941
+ // Hide disabled axes
942
+ handle.visible = handle.visible && (handle.name.indexOf('X') === -1 || _this3.showX);
943
+ handle.visible = handle.visible && (handle.name.indexOf('Y') === -1 || _this3.showY);
944
+ handle.visible = handle.visible && (handle.name.indexOf('Z') === -1 || _this3.showZ);
945
+ handle.visible = handle.visible && (handle.name.indexOf('E') === -1 || _this3.showX && _this3.showY && _this3.showZ);
946
+
947
+ // Hide disabled plane helpers
948
+ handle.visible = handle.visible && (handle.name !== 'XY' || _this3.showXY);
949
+ handle.visible = handle.visible && (handle.name !== 'YZ' || _this3.showYZ);
950
+ handle.visible = handle.visible && (handle.name !== 'XZ' || _this3.showXZ);
951
+
952
+ // highlight selected axis
953
+
954
+ handle.material._color = handle.material._color || handle.material.color.clone();
955
+ handle.material._opacity = handle.material._opacity || handle.material.opacity;
956
+ handle.material.color.copy(handle.material._color);
957
+ handle.material.opacity = handle.material._opacity;
958
+ if (_this3.enabled && _this3.axis) {
959
+ if (handle.name === _this3.axis) {
960
+ handle.material.color.setHex(0xffff00);
961
+ handle.material.opacity = 1.0;
962
+ } else if (_this3.axis.split('').some(function (a) {
963
+ return handle.name === a;
964
+ })) {
965
+ handle.material.color.setHex(0xffff00);
966
+ handle.material.opacity = 1.0;
967
+ }
968
+ }
969
+ };
970
+ for (var i = 0; i < handles.length; i++) {
971
+ if (_loop()) continue;
972
+ }
973
+ _superPropGet(TransformControlsGizmo, "updateMatrixWorld", this, 3)([force]);
974
+ }
975
+ }]);
976
+ }(Object3D); //
977
+ var TransformControlsPlane = /*#__PURE__*/function (_Mesh) {
978
+ function TransformControlsPlane() {
979
+ var _this4;
980
+ _classCallCheck(this, TransformControlsPlane);
981
+ _this4 = _callSuper(this, TransformControlsPlane, [new PlaneGeometry(100000, 100000, 2, 2), new MeshBasicMaterial({
982
+ visible: false,
983
+ wireframe: true,
984
+ side: DoubleSide,
985
+ transparent: true,
986
+ opacity: 0.1,
987
+ toneMapped: false
988
+ })]);
989
+ _this4.isTransformControlsPlane = true;
990
+ _this4.type = 'TransformControlsPlane';
991
+ return _this4;
992
+ }
993
+ _inherits(TransformControlsPlane, _Mesh);
994
+ return _createClass(TransformControlsPlane, [{
995
+ key: "updateMatrixWorld",
996
+ value: function updateMatrixWorld(force) {
997
+ var space = this.space;
998
+ this.position.copy(this.worldPosition);
999
+ if (this.mode === 'scale') space = 'local'; // scale always oriented to local rotation
1000
+
1001
+ _v1.copy(_unitX).applyQuaternion(space === 'local' ? this.worldQuaternion : _identityQuaternion);
1002
+ _v2.copy(_unitY).applyQuaternion(space === 'local' ? this.worldQuaternion : _identityQuaternion);
1003
+ _v3.copy(_unitZ).applyQuaternion(space === 'local' ? this.worldQuaternion : _identityQuaternion);
1004
+
1005
+ // Align the plane for current transform mode, axis and space.
1006
+
1007
+ _alignVector.copy(_v2);
1008
+ switch (this.mode) {
1009
+ case 'translate':
1010
+ case 'scale':
1011
+ switch (this.axis) {
1012
+ case 'X':
1013
+ _alignVector.copy(this.eye).cross(_v1);
1014
+ _dirVector.copy(_v1).cross(_alignVector);
1015
+ break;
1016
+ case 'Y':
1017
+ _alignVector.copy(this.eye).cross(_v2);
1018
+ _dirVector.copy(_v2).cross(_alignVector);
1019
+ break;
1020
+ case 'Z':
1021
+ _alignVector.copy(this.eye).cross(_v3);
1022
+ _dirVector.copy(_v3).cross(_alignVector);
1023
+ break;
1024
+ case 'XY':
1025
+ _dirVector.copy(_v3);
1026
+ break;
1027
+ case 'YZ':
1028
+ _dirVector.copy(_v1);
1029
+ break;
1030
+ case 'XZ':
1031
+ _alignVector.copy(_v3);
1032
+ _dirVector.copy(_v2);
1033
+ break;
1034
+ case 'XYZ':
1035
+ case 'E':
1036
+ _dirVector.set(0, 0, 0);
1037
+ break;
1038
+ }
1039
+ break;
1040
+ case 'rotate':
1041
+ default:
1042
+ // special case for rotate
1043
+ _dirVector.set(0, 0, 0);
1044
+ }
1045
+ if (_dirVector.length() === 0) {
1046
+ // If in rotate mode, make the plane parallel to camera
1047
+ this.quaternion.copy(this.cameraQuaternion);
1048
+ } else {
1049
+ _tempMatrix.lookAt(_tempVector.set(0, 0, 0), _dirVector, _alignVector);
1050
+ this.quaternion.setFromRotationMatrix(_tempMatrix);
1051
+ }
1052
+ _superPropGet(TransformControlsPlane, "updateMatrixWorld", this, 3)([force]);
1053
+ }
1054
+ }]);
1055
+ }(Mesh);
1056
+
1057
+ export { TransformControls, TransformControlsGizmo, TransformControlsPlane };