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