1 line
2.6 KiB
JavaScript
1 line
2.6 KiB
JavaScript
"use strict";var t=function(){function t(t,e){for(var n in e){var i=e[n];i.configurable=!0,i.value&&(i.writable=!0)}Object.defineProperties(t,e)}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),e=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},n=require("animation-utilities").THREE,i=function(){function i(t,n,o,s,a){e(this,i),this.renderer=t,this.element=n,this.animationModel=s,this.spheres=[],this.scene=t.scene.getScene();var h=a?"overlay_textureSubRootBn":"eyeSubRootBn";this.rootBone=this.scene.getObjectByName(h),this.onMouseDownBind=this.onMouseDown.bind(this),this.onMouseUpBind=this.onMouseUp.bind(this),this.onRotateBind=this.onRotate.bind(this),this.element.addEventListener("mousedown",this.onMouseDownBind),this.element.addEventListener("mouseup",this.onMouseUpBind)}return t(i,{setProps:{value:function(t){this.lastAngle=t.Rotate}},getIntersectionAtHeight:{value:function(t,e,i){var o=new n.Vector3;o.set(t/this.element.clientWidth*2-1,2*-(e/this.element.clientHeight)+1,.5);var s=this.renderer.scene.getCamera();return o.unproject(s),o.z=i,o}},onRotate:{value:function(){this.startedManipulation=!0;var t=this.getMouseAngle(),e=t-this.tempInitialAngle,n=(this.tempInitialRotation+e)/Math.PI*180-this.lastAngle;n>120||-120>n?(this.lastAngle=(this.tempInitialRotation+e)/Math.PI*180-n,this.tempInitialRotation=this.lastAngle*Math.PI/180,this.tempInitialAngle=this.getMouseAngle()):this.lastAngle=(this.tempInitialRotation+e)/Math.PI*180,this.animationModel.updateSelectedLayerPropertiesRelative({Rotate:this.lastAngle})}},onMouseUp:{value:function(){this.element.removeEventListener("mousemove",this.onMouseMoveBind),this.element.removeEventListener("mousemove",this.onRotateBind),this.sphere=void 0,this.startedManipulation&&(this.startedManipulation=!1,this.animationModel.addRedoUndoEntry())}},getMouseAngle:{value:function(){var t=this.getIntersectionAtHeight(event.offsetX,event.offsetY,0),e=new n.Vector2(1,0),i=new n.Vector2(this.rootBone.position.x,this.rootBone.position.y),o=new n.Vector2(t.x,t.y),s=o.sub(i).normalize();return s.y<0?2*Math.PI-Math.acos(e.dot(s)):Math.acos(e.dot(s))}},onMouseDown:{value:function(){this.initialMouseAngle=this.getMouseAngle(),this.initialRotation=this.rootBone.rotation.z,this.tempInitialAngle=this.initialMouseAngle,this.tempInitialRotation=this.initialRotation,this.element.addEventListener("mousemove",this.onRotateBind)}},dispose:{value:function(){this.element.removeEventListener("mousedown",this.onMouseDownBind),this.element.removeEventListener("mouseup",this.onMouseUpBind),this.disposed=!0}},scaleSpheres:{value:function(){}}}),i}();module.exports=i; |