1 line
3.6 KiB
JavaScript
1 line
3.6 KiB
JavaScript
"use strict";var e=function(){function e(e,t){for(var i in t){var s=t[i];s.configurable=!0,s.value&&(s.writable=!0)}Object.defineProperties(e,t)}return function(t,i,s){return i&&e(t.prototype,i),s&&e(t,s),t}}(),t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},i=require("animation-utilities"),s=i.THREE,o=i.MouseCoordinateWrangler,n=require("jibo-keyframes").conversion,r=function(){function i(e,s,o,n,r){t(this,i),this.renderer=e,this.element=s,this.robotInfo=o,this.animationModel=n,this.prefix=r?"overlay_vertexJoint":"vertexJoint",this.vertices={},this.vertexToPropMap={},this.spheres={};var a=e.scene.getScene(),h=r?"overlay_textureSubRootBn":"eyeSubRootBn";this.rootBone=a.getObjectByName(h);for(var c=1;10>c;c++){var u=""+this.prefix+c,v=a.getObjectByName(u);this.vertices[u]=v,this.createSphere(v),this.vertexToPropMap[u]="Vertex "+c}this.onMouseDownBind=this.onMouseDown.bind(this),this.onMouseUpBind=this.onMouseUp.bind(this),this.onMouseMoveBind=this.onMouseMove.bind(this),this.element.addEventListener("mousedown",this.onMouseDownBind),this.element.addEventListener("mouseup",this.onMouseUpBind)}return e(i,{scaleSpheres:{value:function(){var e=this;Object.keys(this.spheres).forEach(function(t){var i=e.spheres[t];i.scale.x=1/e.rootBone.scale.x,i.scale.y=1/e.rootBone.scale.y})}},createSphere:{value:function(e){var t=new s.SphereGeometry(.0018,32,32),i=new s.MeshLambertMaterial({color:0,emissive:3355545}),o=new s.Mesh(t,i);o.position.x=e.position.x,o.position.y=e.position.y,o.position.z=e.position.z,this.scaleSpheres(),o.name=e.name,this.vertices[e.name]&&(this.spheres[e.name]=o,this.vertices[e.name]=e,e.parent.add(o))}},setIntersectedObject:{value:function(e){var t=this.renderer.scene.getScene(),i=this.renderer.scene.getCamera(),n=o.getLocalCoordinatesNDCCentered(e,this.element),r=new s.Raycaster;r.setFromCamera(n,i);for(var a=r.intersectObject(t,!0),h=0;h<a.length;h++)if(this.vertices[a[h].object.name])return this.sphere=a[h].object,void(this.vertex=this.vertices[a[h].object.name])}},getIntersectionAtHeight:{value:function(e,t,i){var o=new s.Vector3;o.set(e/this.element.clientWidth*2-1,2*-(t/this.element.clientHeight)+1,.5);var n=this.renderer.scene.getCamera();return o.unproject(n),o.z=i,o}},onMouseMove:{value:function(e){this.startedManipulation=!0;var t=this.getIntersectionAtHeight(e.offsetX,e.offsetY,0);t=this.rootBone.worldToLocal(t.clone());var i=t.sub(this.initMousePosition),s=this.vertexToPropMap[this.vertex.name],o={};o[s]={x:n.toPixelsX(this.initSpherePosition.x+i.x),y:n.toPixelsY(this.initSpherePosition.y+i.y)},this.animationModel.updateSelectedLayerPropertiesRelative(o)}},setProps:{value:function(e){for(var t=1;10>t;t++){var i=e["Vertex "+t],s=""+this.prefix+t,o=this.spheres[s];o.position.x=n.toMetersX(i.x),o.position.y=n.toMetersY(i.y)}this.scaleSpheres()}},onMouseUp:{value:function(){this.sphere=void 0,this.vertex=void 0,this.element.removeEventListener("mousemove",this.onMouseMoveBind),this.startedManipulation&&(this.startedManipulation=!1,this.animationModel.addRedoUndoEntry())}},onMouseDown:{value:function(e){this.setIntersectedObject(e),this.vertex&&this.sphere&&(this.initSpherePosition=this.sphere.position.clone(),this.initMousePosition=this.rootBone.worldToLocal(this.getIntersectionAtHeight(e.offsetX,e.offsetY,0)),this.element.addEventListener("mousemove",this.onMouseMoveBind))}},dispose:{value:function(){var e=this;this.element.removeEventListener("mousedown",this.onMouseDownBind),this.element.removeEventListener("mouseup",this.onMouseUpBind),Object.keys(this.spheres).forEach(function(t){var i=e.spheres[t];i.parent&&i.parent.remove(i)}),this.disposed=!0}}}),i}();module.exports=r; |