"use strict";var e=function(){function e(e,t){for(var o in t){var n=t[o];n.configurable=!0,n.value&&(n.writable=!0)}Object.defineProperties(e,t)}return function(t,o,n){return o&&e(t.prototype,o),n&&e(t,n),t}}(),t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},o=require("animation-utilities").THREE,n=require("atom").CompositeDisposable,r=require("path"),i=require("animation-utilities"),a=i.JiboConfig,s=i.RobotInfo,d=i.visualize,u=new a,l=require("./dof-controller"),c=require("../views/three-debug.js"),h=function(){function i(e){t(this,i),this.animationModel=e,this.baseTexture=r.resolve(__dirname,"../../../","node_modules/animation-content/animations/textures/"),this.baseTextureURL=this.baseTexture+"/JiBO_eye_customizer_",this.baseBGURL=this.baseTexture+"/JiBO_BG_",this.disposable=new n}return e(i,{dispose:{value:function(){this.disposable.dispose()}},toTextureURL:{value:function(e){return this.baseTextureURL+this.getPaddedValueString(e)+".png"}},toBGTextureURL:{value:function(e){return this.baseBGURL+this.getPaddedValueString(e)+".png"}},onMouseDown:{value:function(e){this.container.focus(),this.onMouseChange(e)}},onMouseChange:{value:function(){this.renderer&&(this.animationModel.keyframeSelection.isMultiSelect()||!this.animationModel.isLayerOfTypeSelected("Body")?(this.container.childNodes[1].pointerEvents="none",this.container.childNodes[1].style.cursor="not-allowed"):(this.container.childNodes[1].pointerEvents="",this.container.childNodes[1].style.cursor="pointer"))}},_getThreeColorFromConfig:{value:function(e){var t=atom.config.get("jibo-sdk."+e);return new o.Color(t.red/255,t.green/255,t.blue/255)}},_updateBackgroundColor:{value:function(){var e=this._getThreeColorFromConfig("AnimationEditorBackgroundColor");this.renderer.setBackgroundColor(e.r,e.g,e.b,1)}},_updateGridColor:{value:function(){this.renderer.setGrid(.05,6,this._getThreeColorFromConfig("AnimationEditorGridColor"))}},getPaddedValueString:{value:function(e){var t=10>e?"0":"";return t+e}},setCamera:{value:function(e){var t=this,n=.35,r=.5,i=new o.Vector3(0,0,.15);this.renderer.scene._controls.reset();var a={front:function(){t.renderer.setCamera(new o.Vector3(r,0,n),i,45)},back:function(){t.renderer.setCamera(new o.Vector3(-r,0,n),i,45)},left:function(){t.renderer.setCamera(new o.Vector3(0,r,n),i,45)},right:function(){t.renderer.setCamera(new o.Vector3(0,-r,n),i,45)}};a[e]()}},initialize:{value:function(e,t){var n=this;this.container=e,e.addEventListener("mousemove",this.onMouseChange.bind(this),!0),e.addEventListener("mousedown",this.onMouseDown.bind(this),!0),e.addEventListener("mouseup",this.onMouseChange.bind(this),!0),s.createInfo(u,function(r){d.createRobotRenderer(r,e,d.DisplayType.BODY,function(i){if(i){n.renderer=i,n.robotInfo=r,n.dofValues=r.getDefaultDOFValues(),n.debug=new c(n.renderer.scene.getScene()),i.setCamera(new o.Vector3(.5,0,.35),new o.Vector3(0,0,.15),45),n.dofController=l.createWithRenderer(n.renderer,e,l.ControllerType.BODY,r),n.dofController.setDOFValues(n.dofValues),n.listenForChanges();var a=i.scene.getScene(),s=new o.AxisHelper(1);s.position.z+=.01,a.add(s),n._updateBackgroundColor(),n.disposable.add(atom.config.observe("jibo-sdk.AnimationEditorBackgroundColor",function(){n._updateBackgroundColor()})),n._updateGridColor(),n.disposable.add(atom.config.observe("jibo-sdk.AnimationEditorGridColor",function(){n._updateGridColor()})),t(null)}})})}},listenForChanges:{value:function(){var e=this,t=this;this.dofController.on(l.EventType.DOF_VALUES_CHANGED,function(o,n){var r=e.animationModel.getLayersOfType("Body");0!==r.length&&"Body"===e.animationModel.getSelectedLayer().type&&(n.topSection_r&&t.animationModel.updateSelectedLayerPropertiesRelative({Head:n.topSection_r/Math.PI*180}),n.middleSection_r&&t.animationModel.updateSelectedLayerPropertiesRelative({Torso:n.middleSection_r/Math.PI*180}),n.bottomSection_r&&t.animationModel.updateSelectedLayerPropertiesRelative({Pelvis:n.bottomSection_r/Math.PI*180}))}),this.dofController.on(l.EventType.DOF_SELECTION_CHANGED,function(e,t){1!==t.length}),this.dofController.on(l.EventType.DOF_MANIPULATION_ENDED,function(){t.animationModel.addRedoUndoEntry()})}},updateDofValues:{value:function(e){this.dofValues=e,this.dofController&&this.dofController.setDOFValues(this.dofValues)}},update:{value:function(){this.renderer&&this.renderer.display(this.dofValues)}}}),i}();module.exports=h;