babylonjs-editcontrol 3.3.0 → 4.0.0

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.
@@ -1,3 +1,2085 @@
1
- /*! For license information please see EditControl.max.js.LICENSE.txt */
2
- !function(t,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("babylonjs"));else if("function"==typeof define&&define.amd)define(["babylonjs"],i);else{var s="object"==typeof exports?i(require("babylonjs")):i(t.BABYLON);for(var h in s)("object"==typeof exports?exports:t)[h]=s[h]}}(self,(t=>(()=>{"use strict";var i={babylonjs:i=>{i.exports=t}},s={};function h(t){var n=s[t];if(void 0!==n)return n.exports;var u=s[t]={exports:{}};return i[t](u,u.exports,h),u.exports}h.n=t=>{var i=t&&t.t?()=>t.default:()=>t;return h.d(i,{a:i}),i},h.d=(t,i)=>{for(var s in i)h.o(i,s)&&!h.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:i[s]})},h.o=(t,i)=>Object.prototype.hasOwnProperty.call(t,i),h.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"t",{value:!0})};var n={};return(()=>{h.r(n),h.d(n,{EditControl:()=>s});var t,i=h("babylonjs");!function(t){t[t.TRANS=0]="TRANS",t[t.ROT=1]="ROT",t[t.SCALE=2]="SCALE"}(t||(t={}));var s=function(){function s(t,s,h,n,e,r){var o=this;this.i=!0,this.h=!1,this.u=!1,this.l=1,this.v=Math.PI/18,this.M=.4,this.p=1,this.L=.02,this.A=new i.Color3(1,.2,.2),this.j=new i.Color3(.2,1,.2),this.S=new i.Color3(.2,.2,1),this.O=new i.Color3(1,1,1),this.T=new i.Color3(1,1,.2),this.R=.75,this.g=!1,this.k=new i.Matrix,this.q=new i.Vector3(0,0,0),this.C=2,this._=new i.Vector3(0,0,0),this.B=new i.Vector3(0,0,0),this.N="",this.D=!1,this.F=null,this.G=null,this.H=null,this.I=!1,this.J=!1,this.K=!1,this.P=!1,this.U=new i.Vector3(0,0,0),this.V=new i.Vector3(0,0,0),this.W=!1,this.$=new i.Vector3(0,0,0),this.tt=.25,this.it=new i.Vector3(0,0,0),this.st=new i.Vector3(0,0,0),this.ht=new i.Vector3(0,0,0),this.nt=new i.Vector3(0,0,0),this.ut=!1,this.et=0,this.rt=!1,this.ot=!1,this.ft=!1,this.lt=180,this.ct=new i.Vector3(this.l,this.l,this.l),this.vt=new i.Vector3(0,0,0),this.wt=new i.Vector3(0,0,0),this.Mt=new i.Vector3(0,0,0),this.Xt=new i.Matrix,this.Yt=t,this.Zt=s,this.bt=h,null!=n&&(this.p=n),this.ut=null!==e&&e,this.dt(),null!=r&&(this.L=r),this.Lt=i.UtilityLayerRenderer.DefaultUtilityLayer,this.Lt.onlyCheckPointerDownEvents=!1,this.zt=this.Lt.utilityLayerScene,this.yt=new u(t,10),t.computeWorldMatrix(!0),this.At=this.jt(t),this.St(t),this.g=this.xt(t),console.log("lhs rhs issue "+this.g),this.Ot=new i.Mesh("",this.zt),this.Ot.rotationQuaternion=i.Quaternion.Identity(),this.Ot.visibility=0,this.Ot.isPickable=!1,this.Tt(this.zt),this.Et().parent=this.Ot,this.Rt().parent=this.Ot,this.gt=function(t){return o.kt(t)},this.qt=function(t){return o.Ct(t)},this._t=function(t){return o.Bt(t)},h.addEventListener("pointerdown",this.gt,!1),h.addEventListener("pointerup",this.qt,!1),h.addEventListener("pointermove",this._t,!1),this.Nt=function(){return o.Qt()},this.zt.registerBeforeRender(this.Nt)}return s.prototype.getRoot=function(){return this.Ot},s.prototype.dt=function(){if(!this.ut&&(null==this.Yt.rotationQuaternion||null==this.Yt.rotationQuaternion))throw"Error: Eulerian is set to false but the mesh's rotationQuaternion is not set."},s.prototype.xt=function(t){var s=!1,h=t.parent;if(null==h)return!1;this.St(h);var n=i.Vector3.Cross(this.st,this.ht);return s=i.Vector3.Dot(n,this.nt)<0,this.St(t),s},s.prototype.Qt=function(){this.Ot.position=this.Yt.getAbsolutePivotPoint(),this.Dt(),this.Ft(),this.i?(this.Ot.getWorldMatrix().invertToRef(this.k),i.Vector3.TransformCoordinatesToRef(this.Zt.position,this.k,this.q),this.Gt.lookAt(this.q,0,0,0,i.Space.LOCAL)):(this.Zt.position.subtractToRef(this.Ot.position,this.q),this.Gt.lookAt(this.Zt.position,0,0,0,i.Space.WORLD)),this.ot?this.Ht():this.rt?this.It(this.Jt,this.Kt,this.Pt):this.ft&&this.It(this.Ut,this.Vt,this.Wt)},s.prototype.Dt=function(){if(this.i)if(null==this.Yt.parent)if(this.ut){var t=this.Yt.rotation;i.Quaternion.RotationYawPitchRollToRef(t.y,t.x,t.z,this.Ot.rotationQuaternion)}else this.Ot.rotationQuaternion.copyFrom(this.Yt.rotationQuaternion);else{if(this.$t(this.Yt))return;this.Yt.getWorldMatrix().getRotationMatrixToRef(this.Xt),i.Quaternion.FromRotationMatrixToRef(this.Xt,this.Ot.rotationQuaternion)}},s.prototype.$t=function(t){if(null==t.parent)return!1;for(;null!=t.parent;){if(t.parent.scaling.x!=t.parent.scaling.y||t.parent.scaling.y!=t.parent.scaling.z)return!0;t=t.parent}return!1},s.prototype.Ft=function(){this.Ot.position.subtractToRef(this.Zt.position,this._),i.Vector3.FromArrayToRef(this.Zt.getWorldMatrix().asArray(),8,this.B);var t=i.Vector3.Dot(this._,this.B)/this.B.length(),s=Math.abs(t/this.C);i.Vector3.FromFloatsToRef(s,s,s,this.Ot.scaling)},s.prototype.Ht=function(){var t=Math.atan(this.q.y/this.q.z);this.q.z>=0?this.ti.rotation.x=-t:this.ti.rotation.x=-t-Math.PI;var i=Math.atan(this.q.x/this.q.z);this.q.z>=0?this.ii.rotation.y=i:this.ii.rotation.y=i+Math.PI;var s=Math.atan(this.q.x/this.q.y);this.q.y>=0?this.si.rotation.z=-s:this.si.rotation.z=-s-Math.PI},s.prototype.It=function(t,i,s){var h=this.q;t.rotation.x=0,t.rotation.y=0,t.rotation.z=0,i.rotation.x=0,i.rotation.y=0,i.rotation.z=0,s.rotation.x=0,s.rotation.y=0,s.rotation.z=0,h.x<=0&&h.y>=0&&h.z>=0?(t.rotation.z=3.14,s.rotation.y=3.14):h.x<=0&&h.y>=0&&h.z<=0?(t.rotation.y=3.14,i.rotation.y=3.14,s.rotation.y=3.14):h.x>=0&&h.y>=0&&h.z<=0?(t.rotation.x=3.14,i.rotation.y=3.14):h.x>=0&&h.y<=0&&h.z>=0?(i.rotation.z=3.14,s.rotation.x=3.14):h.x<=0&&h.y<=0&&h.z>=0?(t.rotation.z=3.14,i.rotation.z=3.14,s.rotation.z=3.14):h.x<=0&&h.y<=0&&h.z<=0?(t.rotation.y=3.14,i.rotation.x=3.14,s.rotation.z=3.14):h.x>=0&&h.y<=0&&h.z<=0&&(t.rotation.x=3.14,i.rotation.x=3.14,s.rotation.x=3.14)},s.prototype.switchTo=function(t,i){t.computeWorldMatrix(!0),this.Yt=t,null!=i&&(this.ut=i),this.dt(),this.St(t),this.yt=new u(t,10),this.g=this.xt(t),this.refreshBoundingInfo()},s.prototype.switchCamera=function(t){this.Zt=t},s.prototype.setUndoCount=function(t){this.yt.setCapacity(t)},s.prototype.undo=function(){var t=this.yt.undo();this.Yt.computeWorldMatrix(!0),this.St(this.Yt),this.hi(t),this.ni(t),this.ui(t)},s.prototype.redo=function(){var t=this.yt.redo();this.Yt.computeWorldMatrix(!0),this.St(this.Yt),this.hi(t),this.ni(t),this.ui(t)},s.prototype.detach=function(){this.bt.removeEventListener("pointerdown",this.gt,!1),this.bt.removeEventListener("pointerup",this.qt,!1),this.bt.removeEventListener("pointermove",this._t,!1),this.zt.unregisterBeforeRender(this.Nt),this.removeAllActionListeners(),this.ei()},s.prototype.hide=function(){this.D=!0,this.rt?(this.N="T",this.disableTranslation()):this.ot?(this.N="R",this.disableRotation()):this.ft&&(this.N="S",this.disableScaling()),this.ri()},s.prototype.ri=function(){this.oi.visibility=0,this.fi.visibility=0,this.li.visibility=0},s.prototype.ai=function(){this.oi.visibility=this.R,this.fi.visibility=this.R,this.li.visibility=this.R},s.prototype.show=function(){this.D=!1,this.ai(),"T"==this.N?this.enableTranslation():"R"==this.N?this.enableRotation():"S"==this.N&&this.enableScaling()},s.prototype.isHidden=function(){return this.D},s.prototype.ei=function(){this.Ot.dispose(),this.ci(),this.yt=null},s.prototype.addActionListener=function(t){this.F=t},s.prototype.removeActionListener=function(){this.F=null},s.prototype.addActionStartListener=function(t){this.G=t},s.prototype.removeActionStartListener=function(){this.G=null},s.prototype.addActionEndListener=function(t){this.H=t},s.prototype.removeActionEndListener=function(){this.H=null},s.prototype.removeAllActionListeners=function(){this.F=null,this.G=null,this.H=null},s.prototype.kt=function(t){var i=this;if(t.preventDefault(),this.I=!0,0==t.button){var s=this.zt.getEngine(),h=s.isPointerLock?.5*this.bt.width:this.zt.pointerX,n=s.isPointerLock?.5*this.bt.height:this.zt.pointerY,u=this.zt.pick(h,n,(function(t){if(i.rt){if(t==i.vi||t==i.wi||t==i.Mi||t==i.Jt||t==i.Kt||t==i.Pt||t==i.pi)return!0}else if(i.ot){if(t==i.ti||t==i.ii||t==i.si||t==i.Xi)return!0}else if(i.ft&&(t==i.Yi||t==i.Zi||t==i.bi||t==i.Ut||t==i.Vt||t==i.Wt||t==i.di))return!0;return!1}),!1,this.Zt);if(u.hit){this.Li=u.pickedMesh;var e=this.Li.getChildren();e.length>0?e[0].visibility=this.R:this.Li.visibility=this.R;var r=this.Li.name;"X"==r?this.zi.visibility=1:"Y"==r?this.yi.visibility=1:"Z"==r?this.Ai.visibility=1:"XZ"==r?(this.zi.visibility=1,this.Ai.visibility=1):"ZY"==r?(this.Ai.visibility=1,this.yi.visibility=1):"YX"==r?(this.yi.visibility=1,this.zi.visibility=1):"ALL"==r&&(this.zi.visibility=1,this.yi.visibility=1,this.Ai.visibility=1),this.ji(!0),this.mi=this.Si(this.Li),null!=this.mi?this.xi=this.Oi():this.xi=null,window.setTimeout((function(t,s){return i.Ti(t,s)}),0,this.Zt,this.bt)}}},s.prototype.ji=function(i){this.K=i,i?(this.Ei(),this.Ri==t.ROT&&(this.et=0),this.hi(this.Ri)):this.ui(this.Ri)},s.prototype.isEditing=function(){return this.K},s.prototype.Ti=function(t,i){var s=t,h=i;this.zt.getEngine().isPointerLock||s.detachControl(h)},s.prototype.isPointerOver=function(){return this.J},s.prototype.gi=function(){var t=this,i=this.zt.getEngine(),s=i.isPointerLock?.5*this.bt.width:this.zt.pointerX,h=i.isPointerLock?.5*this.bt.height:this.zt.pointerY,n=this.zt.pick(s,h,(function(i){if(t.rt){if(i==t.vi||i==t.wi||i==t.Mi||i==t.Jt||i==t.Kt||i==t.Pt||i==t.pi)return!0}else if(t.ot){if(i==t.ti||i==t.ii||i==t.si||i==t.Xi)return!0}else if(t.ft&&(i==t.Yi||i==t.Zi||i==t.bi||i==t.Ut||i==t.Vt||i==t.Wt||i==t.di))return!0;return!1}),!1,this.Zt);if(n.hit){if(n.pickedMesh!=this.ki){if(this.J=!0,this.qi(),this.ki=n.pickedMesh,this.ot)this.Ci=this.ki.getChildren()[0].color,this.ki.getChildren()[0].color=this.O;else{var u=this.ki.getChildren();u.length>0?(this._i=u[0].material,u[0].material=this.Bi):(this._i=this.ki.material,this.ki.material=this.Bi)}"X"==this.ki.name?this.oi.color=this.O:"Y"==this.ki.name?this.fi.color=this.O:"Z"==this.ki.name&&(this.li.color=this.O)}}else this.J=!1,null!=this.ki&&(this.Ni(this.ki),this.ki=null)},s.prototype.qi=function(){null!=this.ki&&(this.ki.visibility=0,this.Ni(this.ki))},s.prototype.Ni=function(t){switch(t.name){case"X":this.oi.color=this.A;break;case"Y":this.fi.color=this.j;break;case"Z":this.li.color=this.S}if(this.ot)t.getChildren()[0].color=this.Ci;else{var i=t.getChildren();i.length>0?i[0].material=this._i:t.material=this._i}},s.prototype.Ct=function(t){(this.I=!1,this.K)&&(this.zt.getEngine().isPointerLock||this.Zt.attachControl(!0),this.ji(!1),this.Qi(),null!=this.ki&&(this.Ni(this.ki),this.ki=null),this.yt.add(this.Ri))},s.prototype.Ei=function(){this.rt?this.Ri=t.TRANS:this.ot?this.Ri=t.ROT:this.ft&&(this.Ri=t.SCALE)},s.prototype.ni=function(t){null!=this.F&&this.F(t)},s.prototype.hi=function(t){null!=this.G&&this.G(t)},s.prototype.ui=function(t){null!=this.H&&this.H(t)},s.prototype.Bt=function(t){if(this.I){if(this.K&&null!=this.xi){var i=this.Oi();if(null!=i){if(this.ot)this.Di(this.Yt,this.Li,i,this.xi);else{var s=i.subtract(this.xi);if(0==s.x&&0==s.y&&0==s.z)return;this.rt?this.Fi(s):this.ft&&this.i&&this.Gi(s)}this.xi=i,this.ni(this.Ri)}}}else this.gi()},s.prototype.Si=function(t){var s=t.name;if(this.rt||this.ft){if("XZ"==s)return this.Hi;if("ZY"==s)return this.Ii;if("YX"==s)return this.Ji;if("ALL"==s)return this.Gt;this.Ot.getWorldMatrix().invertToRef(this.k),i.Vector3.TransformCoordinatesToRef(this.Zt.position,this.k,this.q);var h=this.q;if("X"===s)return Math.abs(h.y)>Math.abs(h.z)?this.Hi:this.Ji;if("Z"===s)return Math.abs(h.y)>Math.abs(h.x)?this.Hi:this.Ii;if("Y"===s)return Math.abs(h.z)>Math.abs(h.x)?this.Ji:this.Ii}else{if(!this.ot)return null;this.P=!1,this.Ot.getWorldMatrix().invertToRef(this.k),i.Vector3.TransformCoordinatesToRef(this.Zt.position,this.k,this.q);h=this.q;switch(s){case"X":return Math.abs(h.x)<.2?(this.P=!0,this.Gt):this.Ii;case"Y":return Math.abs(h.y)<.2?(this.P=!0,this.Gt):this.Hi;case"Z":return Math.abs(h.z)<.2?(this.P=!0,this.Gt):this.Ji;default:return this.Gt}}},s.prototype.Fi=function(t){null!=this.Yt.parent&&this.$t(this.Yt)?this.St(this.Ot):this.St(this.Yt);var s=this.Li.name;this.U.x=0,this.U.y=0,this.U.z=0,"X"!=s&&"XZ"!=s&&"YX"!=s&&"ALL"!=s||(this.i?this.U.x=i.Vector3.Dot(t,this.st)/this.st.length():this.U.x=t.x),"Y"!=s&&"ZY"!=s&&"YX"!=s&&"ALL"!=s||(this.i?this.U.y=i.Vector3.Dot(t,this.ht)/this.ht.length():this.U.y=t.y),"Z"!=s&&"XZ"!=s&&"ZY"!=s&&"ALL"!=s||(this.i?this.U.z=i.Vector3.Dot(t,this.nt)/this.nt.length():this.U.z=t.z),this.Ki(this.Yt,this.U,this.i),this.Pi&&(this.Yt.position.x=Math.max(this.Yt.position.x,this.Pi.x),this.Yt.position.y=Math.max(this.Yt.position.y,this.Pi.y),this.Yt.position.z=Math.max(this.Yt.position.z,this.Pi.z)),this.Ui&&(this.Yt.position.x=Math.min(this.Yt.position.x,this.Ui.x),this.Yt.position.y=Math.min(this.Yt.position.y,this.Ui.y),this.Yt.position.z=Math.min(this.Yt.position.z,this.Ui.z)),this.Yt.computeWorldMatrix(!0)},s.prototype.Ki=function(t,s,h){if(this.h){var n=!1;if(this.V.addInPlace(s),Math.abs(this.V.x)>this.ct.x&&(this.V.x>0?s.x=this.ct.x:s.x=-this.ct.x,n=!0),Math.abs(this.V.y)>this.ct.y&&(this.V.y>0?s.y=this.ct.y:s.y=-this.ct.y,n=!0),Math.abs(this.V.z)>this.ct.z&&(this.V.z>0?s.z=this.ct.z:s.z=-this.ct.z,n=!0),!n)return;Math.abs(s.x)!==this.ct.x&&(s.x=0),Math.abs(s.y)!==this.ct.y&&(s.y=0),Math.abs(s.z)!==this.ct.z&&(s.z=0),i.Vector3.FromFloatsToRef(0,0,0,this.V),n=!1}h?(this.st.normalizeToRef(this.vt),this.ht.normalizeToRef(this.wt),this.nt.normalizeToRef(this.Mt),this.Yt.translate(this.vt,s.x,i.Space.WORLD),this.Yt.translate(this.wt,s.y,i.Space.WORLD),this.Yt.translate(this.Mt,s.z,i.Space.WORLD)):null==this.Yt.parent?this.Yt.position.addInPlace(s):this.Yt.setAbsolutePosition(s.addInPlace(this.Yt.absolutePosition))},s.prototype.Gi=function(t){this.St(this.Yt),this.it.x=0,this.it.y=0,this.it.z=0;var s=this.Li.name;"X"!=s&&"XZ"!=s&&"YX"!=s||(this.it.x=i.Vector3.Dot(t,this.st)/this.st.length(),this.Yt.scaling.x<0&&(this.it.x=-this.it.x)),"Y"!=s&&"ZY"!=s&&"YX"!=s||(this.it.y=i.Vector3.Dot(t,this.ht)/this.ht.length(),this.Yt.scaling.y<0&&(this.it.y=-this.it.y)),"Z"!=s&&"XZ"!=s&&"ZY"!=s||(this.it.z=i.Vector3.Dot(t,this.nt)/this.nt.length(),this.Yt.scaling.z<0&&(this.it.z=-this.it.z));var h=this.At;if(this.it.x=this.it.x/h.x,this.it.y=this.it.y/h.y,this.it.z=this.it.z/h.z,"ALL"==s){var n=i.Vector3.Dot(t,this.Zt.upVector);n/=Math.max(h.x,h.y,h.z),this.it.copyFromFloats(n,n,n)}else{var u=!1;if("XZ"==s?(u=!0,Math.abs(this.it.x)>Math.abs(this.it.z)?this.it.z=this.it.x:this.it.x=this.it.z):"ZY"==s?(u=!0,Math.abs(this.it.z)>Math.abs(this.it.y)?this.it.y=this.it.z:this.it.z=this.it.y):"YX"==s&&(u=!0,Math.abs(this.it.y)>Math.abs(this.it.x)?this.it.x=this.it.y:this.it.y=this.it.x),u){this.Ot.position.subtractToRef(this.Zt.position,this._);n=i.Vector3.Dot(t,this._);this.it.x=Math.abs(this.it.x),this.it.y=Math.abs(this.it.y),this.it.z=Math.abs(this.it.z),n>0?(this.Yt.scaling.x>0&&(this.it.x=-this.it.x),this.Yt.scaling.y>0&&(this.it.y=-this.it.y),this.Yt.scaling.z>0&&(this.it.z=-this.it.z)):(this.Yt.scaling.x<0&&(this.it.x=-this.it.x),this.Yt.scaling.y<0&&(this.it.y=-this.it.y),this.Yt.scaling.z<0&&(this.it.z=-this.it.z))}}this.Vi(this.Yt,this.it),this.Wi&&(this.Yt.scaling.x=Math.max(this.Yt.scaling.x,this.Wi.x),this.Yt.scaling.y=Math.max(this.Yt.scaling.y,this.Wi.y),this.Yt.scaling.z=Math.max(this.Yt.scaling.z,this.Wi.z)),this.$i&&(this.Yt.scaling.x=Math.min(this.Yt.scaling.x,this.$i.x),this.Yt.scaling.y=Math.min(this.Yt.scaling.y,this.$i.y),this.Yt.scaling.z=Math.min(this.Yt.scaling.z,this.$i.z))},s.prototype.Vi=function(t,s){if(this.W){var h=!1;if(this.$.addInPlace(s),Math.abs(this.$.x)>this.tt&&(s.x>0?s.x=this.tt:s.x=-this.tt,h=!0),Math.abs(this.$.y)>this.tt&&(s.y>0?s.y=this.tt:s.y=-this.tt,h=!0),Math.abs(this.$.z)>this.tt&&(s.z>0?s.z=this.tt:s.z=-this.tt,h=!0),!h)return;Math.abs(s.x)!==this.tt&&0!==s.x&&(s.x=0),Math.abs(s.y)!==this.tt&&0!==s.y&&(s.y=0),Math.abs(s.z)!==this.tt&&0!==s.z&&(s.z=0),i.Vector3.FromFloatsToRef(0,0,0,this.$),h=!1}t.scaling.addInPlace(s)},s.prototype.St=function(t){var s=t.getWorldMatrix();i.Vector3.FromArrayToRef(s.m,0,this.st),i.Vector3.FromArrayToRef(s.m,4,this.ht),i.Vector3.FromArrayToRef(s.m,8,this.nt)},s.prototype.jt=function(t){if(t instanceof i.AbstractMesh){var s=t.getBoundingInfo().boundingBox,h=s.maximum.subtract(s.minimum);return 0==h.x&&(h.x=1),0==h.y&&(h.y=1),0==h.z&&(h.z=1),h}return new i.Vector3(1,1,1)},s.prototype.refreshBoundingInfo=function(){this.At=this.jt(this.Yt)},s.prototype.Di=function(t,s,h,n){this.i&&null!=this.Yt.parent&&this.$t(t)?this.St(this.Ot):this.St(t);var u,e=0;s==this.ti?u=this.i?this.st:i.Axis.X:s==this.ii?u=this.i?this.ht:i.Axis.Y:s==this.si&&(u=this.i?this.nt:i.Axis.Z),this.Ot.position.subtractToRef(this.Zt.position,this._),this.P?(e=this.ts(n,h,this.Zt.position,this._,u),this.zt.useRightHandedSystem&&(e=-e)):e=this.ss(n,h,t.getAbsolutePivotPoint(),this._),this.g&&(e=-e),this.u&&(this.et+=e,e=0,Math.abs(this.et)>=this.v&&(e=this.et>0?this.v:-this.v,this.et=0)),0!==e&&(this._.normalize(),s==this.Xi?t.rotate(this._,-e,i.Space.WORLD):(i.Vector3.Dot(u,this._)>=0&&(e=-e),t.rotate(u,e,i.Space.WORLD)),this.ut&&(t.rotation=t.rotationQuaternion.toEulerAngles(),t.rotationQuaternion=null),this.i&&(this.g&&(e=-e),null!=this.Yt.parent&&this.$t(t)&&(s==this.Xi?this.Ot.rotate(this._,-e,i.Space.WORLD):this.Ot.rotate(u,e,i.Space.WORLD))))},s.prototype.Oi=function(){var t=this,i=this.zt.getEngine(),s=i.isPointerLock?.5*this.bt.width:this.zt.pointerX,h=i.isPointerLock?.5*this.bt.height:this.zt.pointerY,n=this.zt.pick(s,h,(function(i){return i==t.mi}),null,this.Zt);return n.hit?n.pickedPoint:null},s.prototype.Qi=function(){this.zi.visibility=0,this.yi.visibility=0,this.Ai.visibility=0},s.prototype.getRotationQuaternion=function(){return this.Ot.rotationQuaternion},s.prototype.getPosition=function(){return this.Ot.position},s.prototype.isTranslationEnabled=function(){return this.rt},s.prototype.enableTranslation=function(){this.D||(null==this.vi&&(this.hs(),this.ns.parent=this.Ot),this.qi(),this.rt||(this.us(this.es,this.R),this.rt=!0,this.disableRotation(),this.disableScaling()))},s.prototype.disableTranslation=function(){this.rt&&(this.us(this.es,0),this.rt=!1)},s.prototype.isRotationEnabled=function(){return this.ot},s.prototype.returnEuler=function(t){this.ut=t},s.prototype.enableRotation=function(){this.D||(null==this.rs&&(this.os(),this.rs.parent=this.Ot),this.qi(),this.ot||(this.us(this.fs,this.R),this.ot=!0,this.disableTranslation(),this.disableScaling()))},s.prototype.disableRotation=function(){this.ot&&(this.us(this.fs,0),this.ot=!1)},s.prototype.isScalingEnabled=function(){return this.ft},s.prototype.enableScaling=function(){this.D||(null==this.Yi&&(this.ls(),this.cs.parent=this.Ot),this.qi(),this.ft||(this.us(this.vs,this.R),this.ft=!0,this.disableTranslation(),this.disableRotation()))},s.prototype.disableScaling=function(){this.ft&&(this.us(this.vs,0),this.ft=!1)},s.prototype.setScaleBounds=function(t,i){this.Wi=t||null,this.$i=i||null,null!=this.Wi&&(0==this.Wi.x&&(this.Wi.x=1e-8),0==this.Wi.y&&(this.Wi.y=1e-8),0==this.Wi.z&&(this.Wi.z=1e-8))},s.prototype.removeScaleBounds=function(){this.Wi=null,this.$i=null},s.prototype.setTransBounds=function(t,i){this.Pi=t||null,this.Ui=i||null},s.prototype.removeTransBounds=function(){this.Pi=null,this.Ui=null},s.prototype.setRotBounds=function(t,i){this.ws=t||null,this.Ms=i||null},s.prototype.removeRotBounds=function(){this.ws=null,this.Ms=null},s.prototype.Et=function(){var t=new i.Mesh("",this.zt);this.zi=i.MeshBuilder.CreateLines("",{points:[new i.Vector3(-100,0,0),new i.Vector3(100,0,0)]},this.zt),this.yi=i.MeshBuilder.CreateLines("",{points:[new i.Vector3(0,-100,0),new i.Vector3(0,100,0)]},this.zt),this.Ai=i.MeshBuilder.CreateLines("",{points:[new i.Vector3(0,0,-100),new i.Vector3(0,0,100)]},this.zt),this.zi.isPickable=!1,this.yi.isPickable=!1,this.Ai.isPickable=!1,this.zi.parent=t,this.yi.parent=t,this.Ai.parent=t,this.zi.color=this.A,this.yi.color=this.j,this.Ai.color=this.S,this.Qi();var s=this.M*this.p*.75;return this.oi=i.MeshBuilder.CreateLines("",{points:[new i.Vector3(0,0,0),new i.Vector3(s,0,0)]},this.zt),this.fi=i.MeshBuilder.CreateLines("",{points:[new i.Vector3(0,0,0),new i.Vector3(0,s,0)]},this.zt),this.li=i.MeshBuilder.CreateLines("",{points:[new i.Vector3(0,0,0),new i.Vector3(0,0,s)]},this.zt),this.oi.isPickable=!1,this.fi.isPickable=!1,this.li.isPickable=!1,this.oi.parent=t,this.fi.parent=t,this.li.parent=t,this.oi.color=this.A,this.fi.color=this.j,this.li.color=this.S,this.oi.renderingGroupId=1,this.fi.renderingGroupId=1,this.li.renderingGroupId=1,t},s.prototype.Rt=function(){this.Gt=i.MeshBuilder.CreatePlane("",{size:5},this.zt),this.Hi=i.MeshBuilder.CreatePlane("",{size:5},this.zt),this.Ii=i.MeshBuilder.CreatePlane("",{size:5},this.zt),this.Ji=i.MeshBuilder.CreatePlane("",{size:5},this.zt),this.Gt.isPickable=!1,this.Hi.isPickable=!1,this.Ii.isPickable=!1,this.Ji.isPickable=!1,this.Gt.visibility=0,this.Hi.visibility=0,this.Ii.visibility=0,this.Ji.visibility=0,this.Gt.renderingGroupId=1,this.Hi.renderingGroupId=1,this.Ii.renderingGroupId=1,this.Ji.renderingGroupId=1,this.Gt.lookAt(this.Zt.position),this.Hi.rotate(i.Axis.X,1.57),this.Ii.rotate(i.Axis.Y,1.57);var t=new i.Mesh("",this.zt);return this.Gt.parent=t,this.Hi.parent=t,this.Ii.parent=t,this.Ji.parent=t,t},s.prototype.hs=function(){var t=2*this.L*this.p,s=this.M*this.p;this.ns=new i.Mesh("",this.zt),this.ps(t,s,this.ns,this.zt),this.Xs(t,s,this.zt)},s.prototype.ps=function(t,s,h,n){var u=this.Ys(t/2,s);u.name="X";var e=u.clone("Y"),r=u.clone("Z"),o=2*t,f=i.MeshBuilder.CreatePlane("XZ",{size:o},n),l=i.MeshBuilder.CreatePlane("ZY",{size:o},n),a=i.MeshBuilder.CreatePlane("YX",{size:o},n);f.rotation.x=1.57,l.rotation.y=-1.57,f.position.x=2*t,f.position.z=2*t,l.position.z=2*t,l.position.y=2*t,a.position.y=2*t,a.position.x=2*t,f.bakeCurrentTransformIntoVertices(),l.bakeCurrentTransformIntoVertices(),a.bakeCurrentTransformIntoVertices();var c=i.MeshBuilder.CreateBox("ALL",{size:2*t},n);u.parent=h,e.parent=h,r.parent=h,f.parent=h,l.parent=h,a.parent=h,c.parent=h,u.rotation.y=1.57,e.rotation.x-=1.57,this.vi=u,this.wi=e,this.Mi=r,this.Jt=f,this.Kt=l,this.Pt=a,this.pi=c,this.Zs=[u,e,r,f,l,a,c],this.us(this.Zs,0),this.bs(this.Zs)},s.prototype.Xs=function(t,s,h){var n=s/5,u=i.MeshBuilder.CreateCylinder("",{height:n,diameterTop:0,diameterBottom:t,tessellation:6,subdivisions:1},h),e=u.clone(""),r=u.clone(""),o=2*t,f=i.MeshBuilder.CreatePlane("XZ",{size:o},h),l=i.MeshBuilder.CreatePlane("ZY",{size:o},h),a=i.MeshBuilder.CreatePlane("YX",{size:o},h),c=i.MeshBuilder.CreateBox("ALL",{size:t},h);u.rotation.x=1.57,e.rotation.x=1.57,r.rotation.x=1.57,f.rotation.x=1.57,l.rotation.y=1.57,f.position.x=o,f.position.z=o,l.position.z=o,l.position.y=o,a.position.y=o,a.position.x=o,u.parent=this.vi,e.parent=this.wi,r.parent=this.Mi,f.parent=this.Jt,l.parent=this.Kt,a.parent=this.Pt,c.parent=this.pi,u.position.z=s-n/2,e.position.z=s-n/2,r.position.z=s-n/2,u.material=this.ds,e.material=this.Ls,r.material=this.zs,f.material=this.Ls,l.material=this.ds,a.material=this.zs,c.material=this.ys,this.As=u,this.js=e,this.Ss=r,this.xs=f,this.Os=l,this.Ts=a,this.Es=c,this.es=[u,e,r,f,l,a,c],this.bs(this.es),this.Rs(this.es)},s.prototype.setRotGuideFull=function(t){this.lt=t?360:180,null!=this.rs&&(this.rs.dispose(),this.Xi.dispose(),this.rs=null,this.enableRotation())},s.prototype.os=function(){var t=this.M*this.p*2;this.rs=new i.Mesh("",this.zt),this.gs(t,this.rs),this.ks(t)},s.prototype.gs=function(t,i){var s=this.qs(t/2,this.lt),h=this.qs(t/2,this.lt),n=this.qs(t/2,this.lt),u=this.qs(t/1.75,360);s.name="X",h.name="Y",n.name="Z",u.name="ALL",s.rotation.z=1.57,n.rotation.x=-1.57,s.bakeCurrentTransformIntoVertices(),n.bakeCurrentTransformIntoVertices(),u.rotation.x=1.57,s.parent=i,h.parent=i,n.parent=i,u.parent=this.Gt,this.ti=s,this.ii=h,this.si=n,this.Xi=u,this.Cs=[s,h,n,u],this.us(this.Cs,0),this.bs(this.Cs)},s.prototype.ks=function(t){var s=this._s(t/2,this.lt,!1),h=s.clone(""),n=s.clone(""),u=this._s(t/1.75,360,!1),e=this._s(t/2,360,!1);s.parent=this.ti,h.parent=this.ii,n.parent=this.si,s.rotation.z=1.57,n.rotation.x=-1.57,u.parent=this.Xi,e.parent=this.Xi,s.color=this.A,h.color=this.j,n.color=this.S,u.color=this.T,e.color=i.Color3.Gray(),this.Bs=s,this.Ns=h,this.Qs=n,this.Ds=u,this.Fs=e,this.fs=[s,h,n,u,e],this.bs(this.fs),this.Rs(this.fs)},s.prototype.us=function(t,i){t.map((function(t){return t.visibility=i}))},s.prototype.bs=function(t){t.map((function(t){t.isPickable=!1}))},s.prototype.Rs=function(t){t.map((function(t){return t.renderingGroupId=2}))},s.prototype.Ys=function(t,s){var h=[new i.Vector3(t,t,0),new i.Vector3(-t,t,0),new i.Vector3(-t,-t,0),new i.Vector3(t,-t,0),new i.Vector3(t,t,0)],n=[new i.Vector3(0,0,0),new i.Vector3(0,0,s)];return i.MeshBuilder.ExtrudeShape("",{shape:h,path:n,scale:1,rotation:0,cap:2},this.zt)},s.prototype._s=function(t,s,h){null===s&&(s=360);for(var n,u,e=[],r=3.14/180,o=0,f=0;f<=s;f+=5)n=t*Math.cos(f*r),u=90==f?t:270==f?-t:t*Math.sin(f*r),e[o]=new i.Vector3(n,0,u),o++;if(h){t-=.04;for(f=0;f<=s;f+=5)n=t*Math.cos(f*r),u=90==f?t:270==f?-t:t*Math.sin(f*r),e[o]=new i.Vector3(n,0,u),o++}return i.MeshBuilder.CreateLines("",{points:e},this.zt)},s.prototype.qs=function(t,s){null===s&&(s=360);for(var h,n,u=[],e=3.14/180,r=0,o=0;o<=s;o+=30)h=t*Math.cos(o*e),n=90==o?t:270==o?-t:t*Math.sin(o*e),u[r]=new i.Vector3(h,0,n),r++;return i.MeshBuilder.CreateTube("",{path:u,radius:this.L*this.p*2,tessellation:3,cap:i.Mesh.NO_CAP},this.zt)},s.prototype.ls=function(){var t=2*this.L*this.p,s=this.M*this.p;this.cs=new i.Mesh("",this.zt),this.Gs(t,s,this.cs),this.Hs(t,s)},s.prototype.Gs=function(t,s,h){var n=this.Ys(t/2,s);n.name="X";var u=n.clone("Y"),e=n.clone("Z"),r=i.MeshBuilder.CreatePlane("XZ",{size:2*t},this.zt),o=i.MeshBuilder.CreatePlane("ZY",{size:2*t},this.zt),f=i.MeshBuilder.CreatePlane("YX",{size:2*t},this.zt);r.rotation.x=1.57,o.rotation.y=-1.57,r.position.x=2*t,r.position.z=2*t,o.position.z=2*t,o.position.y=2*t,f.position.y=2*t,f.position.x=2*t,r.bakeCurrentTransformIntoVertices(),o.bakeCurrentTransformIntoVertices(),f.bakeCurrentTransformIntoVertices();var l=i.MeshBuilder.CreateBox("ALL",{size:2*t},this.zt);n.parent=h,u.parent=h,e.parent=h,l.parent=h,r.parent=h,o.parent=h,f.parent=h,n.rotation.y=1.57,u.rotation.x-=1.57,this.Yi=n,this.Zi=u,this.bi=e,this.Ut=r,this.Vt=o,this.Wt=f,this.di=l,this.Is=[n,u,e,r,o,f,l],this.us(this.Is,0),this.bs(this.Is)},s.prototype.Hs=function(t,s){var h=i.MeshBuilder.CreateBox("",{size:t},this.zt),n=h.clone(""),u=h.clone(""),e=2*t,r=i.MeshBuilder.CreatePlane("XZ",{size:e},this.zt),o=i.MeshBuilder.CreatePlane("ZY",{size:e},this.zt),f=i.MeshBuilder.CreatePlane("YX",{size:e},this.zt),l=i.MeshBuilder.CreateBox("ALL",{size:t},this.zt);r.rotation.x=1.57,o.rotation.y=-1.57,r.position.x=e,r.position.z=e,o.position.z=e,o.position.y=e,f.position.y=e,f.position.x=e,h.parent=this.Yi,n.parent=this.Zi,u.parent=this.bi,r.parent=this.Ut,o.parent=this.Vt,f.parent=this.Wt,l.parent=this.di,h.position.z=s-t/2,n.position.z=s-t/2,u.position.z=s-t/2,h.material=this.ds,n.material=this.Ls,u.material=this.zs,r.material=this.Ls,o.material=this.ds,f.material=this.zs,l.material=this.ys,this.Js=h,this.Ks=n,this.Ps=u,this.Us=r,this.Vs=o,this.Ws=f,this.$s=l,this.vs=[h,n,u,r,o,f,l],this.bs(this.vs),this.Rs(this.vs)},s.prototype.setVisibility=function(t){this.R=t},s.prototype.setLocal=function(t){this.i!=t&&(this.i=t,t||(this.Ot.rotationQuaternion=i.Quaternion.Identity()))},s.prototype.isLocal=function(){return this.i},s.prototype.setTransSnap=function(t){this.h=t},s.prototype.isTransSnap=function(){return this.h},s.prototype.setRotSnap=function(t){this.u=t},s.prototype.isRotSnap=function(){return this.u},s.prototype.setScaleSnap=function(t){this.W=t},s.prototype.isScaleSnap=function(){return this.W},s.prototype.setTransSnapValue=function(t){this.ct.copyFromFloats(t,t,t),this.l=t},s.prototype.getTransSnapValue=function(){return this.l},s.prototype.setRotSnapValue=function(t){this.v=t},s.prototype.getRotSnapValue=function(){return this.v},s.prototype.setScaleSnapValue=function(t){this.tt=t},s.prototype.getScaleSnapValue=function(){return this.tt},s.prototype.ts=function(t,s,h,n,u){var e=i.Vector3.Dot(n,u);u.scaleToRef(e,this.vt),h.addToRef(this.vt,this.wt);var r=this.wt;this.Zt.getWorldMatrix().invertToRef(this.Xt),i.Vector3.TransformCoordinatesToRef(this.wt,this.Xt,this.wt);var o=0;r.x>=0&&r.y>=0?o=1:r.x<=0&&r.y>=0?o=2:r.x<=0&&r.y<=0?o=3:r.x>=0&&r.y<=0&&(o=4),i.Vector3.TransformCoordinatesToRef(t,this.Xt,this.vt),i.Vector3.TransformCoordinatesToRef(s,this.Xt,this.wt),this.wt.subtractInPlace(this.vt);var f=this.wt,l=f.length(),a="";f.x>=0&&f.y>=0?a=f.x>=f.y?"r":"u":f.x<=0&&f.y>=0?a=-f.x>=f.y?"l":"u":f.x<=0&&f.y<=0?a=-f.x>=-f.y?"l":"d":f.x>=0&&f.y<=0&&(a=f.x>=-f.y?"r":"d");var c=0;return"d"==a?c=1==o||4==o?1:-1:"u"==a?c=1==o||4==o?-1:1:"r"==a?c=2==o||1==o?1:-1:"l"==a&&(c=2==o||1==o?-1:1),c*l},s.prototype.ss=function(t,s,h,n){t.subtractToRef(h,this.vt),s.subtractToRef(h,this.wt),i.Vector3.CrossToRef(this.vt,this.wt,this.Mt);var u=Math.asin(this.Mt.length()/(this.vt.length()*this.wt.length()));return i.Vector3.Dot(this.Mt,n)>0&&(u*=-1),u},s.th=function(t,s){var h=new i.StandardMaterial("",s);return h.emissiveColor=t,h.diffuseColor=i.Color3.Black(),h.specularColor=i.Color3.Black(),h.backFaceCulling=!1,h},s.prototype.Tt=function(t){this.ds=s.th(this.A,t),this.Ls=s.th(this.j,t),this.zs=s.th(this.S,t),this.Bi=s.th(this.O,t),this.ys=s.th(this.T,t)},s.prototype.ci=function(){this.ds.dispose(),this.Ls.dispose(),this.zs.dispose(),this.Bi.dispose(),this.ys.dispose()},s}(),u=function(){function t(t,i){this.lastMax=10,this.acts=new Array,this.last=-1,this.current=-1,this.mesh=t,this.lastMax=i-1,this.add()}return t.prototype.setCapacity=function(t){0!=t?(this.lastMax=t-1,this.last=-1,this.current=-1,this.acts=new Array,this.add()):console.error("capacity should be more than zero")},t.prototype.add=function(t){void 0===t&&(t=null);var i=new e(this.mesh,t);this.current<this.last&&(this.acts.splice(this.current+1),this.last=this.current),this.last==this.lastMax?(this.acts.shift(),this.acts.push(i)):(this.acts.push(i),this.last++,this.current++)},t.prototype.undo=function(){if(this.current>0){var t=this.acts[this.current].getActionType();return this.current--,this.acts[this.current].perform(this.mesh),t}},t.prototype.redo=function(){if(this.current<this.last)return this.current++,this.acts[this.current].perform(this.mesh),this.acts[this.current].getActionType()},t}(),e=function(){function t(t,i){this.ih=t.position.clone(),null==t.rotationQuaternion?(this.sh=null,this.hh=t.rotation.clone()):(this.sh=t.rotationQuaternion.clone(),this.hh=null),this.nh=t.scaling.clone(),this.uh=i}return t.prototype.getActionType=function(){return this.uh},t.prototype.perform=function(t){t.position.copyFrom(this.ih),null==t.rotationQuaternion?null!=this.hh?t.rotation.copyFrom(this.hh):t.rotation.copyFrom(this.sh.toEulerAngles()):null!=this.sh?t.rotationQuaternion.copyFrom(this.sh):t.rotationQuaternion.copyFrom(i.Quaternion.RotationYawPitchRoll(this.hh.y,this.hh.x,this.hh.z)),t.scaling.copyFrom(this.nh)},t}()})(),n})()));
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory(require("babylonjs"));
4
+ else if(typeof define === 'function' && define.amd)
5
+ define(["babylonjs"], factory);
6
+ else {
7
+ var a = typeof exports === 'object' ? factory(require("babylonjs")) : factory(root["BABYLON"]);
8
+ for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
9
+ }
10
+ })(self, (__WEBPACK_EXTERNAL_MODULE_babylonjs__) => {
11
+ return /******/ (() => { // webpackBootstrap
12
+ /******/ "use strict";
13
+ /******/ var __webpack_modules__ = ({
14
+
15
+ /***/ "babylonjs"
16
+ /*!****************************************************************************************************!*\
17
+ !*** external {"commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs","root":"BABYLON"} ***!
18
+ \****************************************************************************************************/
19
+ (module) {
20
+
21
+ module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__;
22
+
23
+ /***/ }
24
+
25
+ /******/ });
26
+ /************************************************************************/
27
+ /******/ // The module cache
28
+ /******/ var __webpack_module_cache__ = {};
29
+ /******/
30
+ /******/ // The require function
31
+ /******/ function __webpack_require__(moduleId) {
32
+ /******/ // Check if module is in cache
33
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
34
+ /******/ if (cachedModule !== undefined) {
35
+ /******/ return cachedModule.exports;
36
+ /******/ }
37
+ /******/ // Check if module exists (development only)
38
+ /******/ if (__webpack_modules__[moduleId] === undefined) {
39
+ /******/ var e = new Error("Cannot find module '" + moduleId + "'");
40
+ /******/ e.code = 'MODULE_NOT_FOUND';
41
+ /******/ throw e;
42
+ /******/ }
43
+ /******/ // Create a new module (and put it into the cache)
44
+ /******/ var module = __webpack_module_cache__[moduleId] = {
45
+ /******/ // no module.id needed
46
+ /******/ // no module.loaded needed
47
+ /******/ exports: {}
48
+ /******/ };
49
+ /******/
50
+ /******/ // Execute the module function
51
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
52
+ /******/
53
+ /******/ // Return the exports of the module
54
+ /******/ return module.exports;
55
+ /******/ }
56
+ /******/
57
+ /************************************************************************/
58
+ var __webpack_exports__ = {};
59
+ // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
60
+ (() => {
61
+ var exports = __webpack_exports__;
62
+ /*!****************************!*\
63
+ !*** ./src/EditControl.ts ***!
64
+ \****************************/
65
+
66
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
67
+ exports.EditControl = void 0;
68
+ const babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
69
+ var ActionType;
70
+ (function (ActionType) {
71
+ ActionType[ActionType["TRANS"] = 0] = "TRANS";
72
+ ActionType[ActionType["ROT"] = 1] = "ROT";
73
+ ActionType[ActionType["SCALE"] = 2] = "SCALE";
74
+ })(ActionType || (ActionType = {}));
75
+ /**
76
+ * Draws a transform widget at the mesh's location (its pivot location).
77
+ * The widget transforms(translates,rotates and scales) the mesh based on user
78
+ * interactions with the widget.
79
+ * The widget shows the mesh position and rotation at any time.
80
+ * The widget follows the mesh constantly.
81
+ * Note: An alternate approach would have been for the mesh to follow the widget.
82
+ * The problem with the alternate approach - syncing the transforms
83
+ * if the mesh was being transformed by entities other than the widget say physics
84
+ * or script for example.
85
+ *
86
+ */
87
+ class EditControl {
88
+ _isEulerian(mesh) {
89
+ return ((mesh.rotationQuaternion == null) || (mesh.rotationQuaternion == undefined));
90
+ }
91
+ constructor(mesh, camera, canvas, scale, pickWidth) {
92
+ this._local = true;
93
+ this._snapT = false;
94
+ this._snapR = false;
95
+ this._transSnap = 1;
96
+ this._rotSnap = Math.PI / 18;
97
+ this._axesLen = 0.4;
98
+ this._axesScale = 1;
99
+ //how close to an axis should we get before we can pick it
100
+ this._pickWidth = 0.02;
101
+ this._redCol = new babylonjs_1.Color3(1, 0.34, 0.26);
102
+ this._greenCol = new babylonjs_1.Color3(0.0, 0.8, 0.16);
103
+ this._blueCol = new babylonjs_1.Color3(0.21, 0.5, 1);
104
+ this._whiteCol = new babylonjs_1.Color3(0.7, 0.7, 0.7);
105
+ this._yellowCol = new babylonjs_1.Color3(1, 1, 0);
106
+ //axes visibility
107
+ this._visibility = 0.75;
108
+ //lhs-rhs issue. lhs mesh in rhs or rhs mesh in lhs
109
+ this._lhsRhs = false;
110
+ this._ecMatrix = new babylonjs_1.Matrix();
111
+ //edit control to camera vector
112
+ this._ecTOcamera = new babylonjs_1.Vector3(0, 0, 0);
113
+ //how far away from camera should the edit control appear to be
114
+ this._distFromCamera = 2;
115
+ //vector from camera to edit control
116
+ this._cameraTOec = new babylonjs_1.Vector3(0, 0, 0);
117
+ this._cameraNormal = new babylonjs_1.Vector3(0, 0, 0);
118
+ this._prevState = "";
119
+ this._hidden = false;
120
+ this._actionListener = null;
121
+ this._actionStartListener = null;
122
+ this._actionEndListener = null;
123
+ this._pDown = false;
124
+ this._pointerIsOver = false;
125
+ this._editing = false;
126
+ //rotate differently if camera is too close to the rotation plane
127
+ this._rotate2 = false;
128
+ //TODO when translating, the orientation of pALL keeps changing
129
+ //TODo this is not so with rotation or scaling
130
+ //TODO so for translation instead of pALL maybe we should use the camera view plane for picking
131
+ this._transBy = new babylonjs_1.Vector3(0, 0, 0);
132
+ this._snapTV = new babylonjs_1.Vector3(0, 0, 0);
133
+ this._snapS = false;
134
+ this._snapSV = new babylonjs_1.Vector3(0, 0, 0);
135
+ this._scaleSnap = 0.25;
136
+ this._scale = new babylonjs_1.Vector3(0, 0, 0);
137
+ this._localX = new babylonjs_1.Vector3(0, 0, 0);
138
+ this._localY = new babylonjs_1.Vector3(0, 0, 0);
139
+ this._localZ = new babylonjs_1.Vector3(0, 0, 0);
140
+ // private _eulerian: boolean = false;
141
+ this._snapRA = 0;
142
+ this._transEnabled = false;
143
+ this._rotEnabled = false;
144
+ this._scaleEnabled = false;
145
+ this._guideSize = 180;
146
+ this._tSnap = new babylonjs_1.Vector3(this._transSnap, this._transSnap, this._transSnap);
147
+ //few temp vectors & matrix
148
+ this._tv1 = new babylonjs_1.Vector3(0, 0, 0);
149
+ this._tv2 = new babylonjs_1.Vector3(0, 0, 0);
150
+ this._tv3 = new babylonjs_1.Vector3(0, 0, 0);
151
+ this._tm = new babylonjs_1.Matrix();
152
+ this._mesh = mesh;
153
+ this._mainCamera = camera;
154
+ this._canvas = canvas;
155
+ if (scale != null) {
156
+ this._axesScale = scale;
157
+ }
158
+ if (pickWidth != null) {
159
+ this._pickWidth = pickWidth;
160
+ }
161
+ this._utilLayer = babylonjs_1.UtilityLayerRenderer.DefaultUtilityLayer;
162
+ this._utilLayer.onlyCheckPointerDownEvents = false;
163
+ this._scene = this._utilLayer.utilityLayerScene;
164
+ this._actHist = new ActHist(mesh, 10);
165
+ mesh.computeWorldMatrix(true);
166
+ this._boundingDimesion = this._getBoundingDimension(mesh);
167
+ this._setLocalAxes(mesh);
168
+ this._lhsRhs = this._check_LHS_RHS(mesh);
169
+ if (this._lhsRhs)
170
+ console.warn("we have lhs rhs issue " + this._lhsRhs);
171
+ //build the edit control axes
172
+ this._ecRoot = new babylonjs_1.Mesh("", this._scene);
173
+ this._ecRoot.rotationQuaternion = babylonjs_1.Quaternion.Identity();
174
+ this._ecRoot.visibility = 0;
175
+ this._ecRoot.isPickable = false;
176
+ this._createMaterials(this._scene);
177
+ let guideAxes = this._createCommonAxes();
178
+ guideAxes.parent = this._ecRoot;
179
+ //build the pickplanes
180
+ let pickPlanes = this._createPickPlanes();
181
+ pickPlanes.parent = this._ecRoot;
182
+ this._pointerdown = (evt) => { return this._onPointerDown(evt); };
183
+ this._pointerup = (evt) => { return this._onPointerUp(evt); };
184
+ this._pointermove = (evt) => { return this._onPointerMove(evt); };
185
+ //use canvas rather than scene to handle pointer events
186
+ //scene cannot have mutiple eventlisteners for an event
187
+ //with canvas one will have to do ones own pickinfo generation.
188
+ canvas.addEventListener("pointerdown", this._pointerdown, false);
189
+ canvas.addEventListener("pointerup", this._pointerup, false);
190
+ canvas.addEventListener("pointermove", this._pointermove, false);
191
+ this._renderer = () => { return this._renderLoopProcess(); };
192
+ this._scene.registerBeforeRender(this._renderer);
193
+ }
194
+ getRoot() {
195
+ return this._ecRoot;
196
+ }
197
+ /**
198
+ * checks if a have left hand , right hand issue.
199
+ * In other words if a mesh is a LHS mesh in RHS system or
200
+ * a RHS mesh in LHS system
201
+ * The X axis will be reversed in such cases.
202
+ * thus Cross product of X and Y should be inverse of Z.
203
+ *
204
+ * if no parent then we are ok.
205
+ * If parent and parent has issue then we have issue.
206
+ *
207
+ */
208
+ _check_LHS_RHS(mesh) {
209
+ let _issue = false;
210
+ let root = mesh.parent;
211
+ if (root == null)
212
+ return false;
213
+ this._setLocalAxes(root);
214
+ let actualZ = babylonjs_1.Vector3.Cross(this._localX, this._localY);
215
+ //same direction or opposite direction of Z
216
+ if (babylonjs_1.Vector3.Dot(actualZ, this._localZ) < 0)
217
+ _issue = true;
218
+ else
219
+ _issue = false;
220
+ this._setLocalAxes(mesh);
221
+ return _issue;
222
+ }
223
+ _renderLoopProcess() {
224
+ //sync the edit control position and rotation with that of mesh
225
+ this._ecRoot.position = this._mesh.getAbsolutePivotPoint();
226
+ this._setECRotation();
227
+ //scale the EditControl so it seems at the same distance from camera/user
228
+ this._setECScale();
229
+ //rotate the free move,rotate,scale pick plane to face the camera/user
230
+ if (this._local) {
231
+ this._ecRoot.getWorldMatrix().invertToRef(this._ecMatrix);
232
+ babylonjs_1.Vector3.TransformCoordinatesToRef(this._mainCamera.position, this._ecMatrix, this._ecTOcamera);
233
+ //note pALL is child of ecRoot hence lookAt in local space
234
+ this._pALL.lookAt(this._ecTOcamera, 0, 0, 0, babylonjs_1.Space.LOCAL);
235
+ }
236
+ else {
237
+ this._mainCamera.position.subtractToRef(this._ecRoot.position, this._ecTOcamera);
238
+ this._pALL.lookAt(this._mainCamera.position, 0, 0, 0, babylonjs_1.Space.WORLD);
239
+ }
240
+ //rotate the rotation and planar guide to face the camera/user
241
+ if (this._rotEnabled) {
242
+ this._rotRotGuides();
243
+ }
244
+ else if (this._transEnabled)
245
+ this._rotPlanarGuides(this._tXZ, this._tZY, this._tYX);
246
+ else if (this._scaleEnabled)
247
+ this._rotPlanarGuides(this._sXZ, this._sZY, this._sYX);
248
+ //check pointer over axes only during pointer moves
249
+ //this.onPointerOver();
250
+ }
251
+ /**
252
+ * sets rotaion of edit control to that of the mesh
253
+ */
254
+ _setECRotation() {
255
+ if (this._local) {
256
+ if (this._mesh.parent == null) {
257
+ if (this._isEulerian(this._mesh)) {
258
+ let rot = this._mesh.rotation;
259
+ babylonjs_1.Quaternion.RotationYawPitchRollToRef(rot.y, rot.x, rot.z, this._ecRoot.rotationQuaternion);
260
+ }
261
+ else {
262
+ this._ecRoot.rotationQuaternion.copyFrom(this._mesh.rotationQuaternion);
263
+ }
264
+ }
265
+ else {
266
+ if (this._isScaleUnEqual(this._mesh))
267
+ return;
268
+ this._mesh.getWorldMatrix().getRotationMatrixToRef(this._tm);
269
+ babylonjs_1.Quaternion.FromRotationMatrixToRef(this._tm, this._ecRoot.rotationQuaternion);
270
+ //this._ecRoot.rotationQuaternion.normalize();
271
+ }
272
+ }
273
+ }
274
+ /**
275
+ * checks if any of the mesh's ancestors has non uniform scale
276
+ */
277
+ _isScaleUnEqual(mesh) {
278
+ if (mesh.parent == null)
279
+ return false;
280
+ while (mesh.parent != null) {
281
+ if ((mesh.parent.scaling.x != mesh.parent.scaling.y ||
282
+ mesh.parent.scaling.y != mesh.parent.scaling.z)) {
283
+ return true;
284
+ }
285
+ else {
286
+ mesh = mesh.parent;
287
+ }
288
+ }
289
+ return false;
290
+ }
291
+ _setECScale() {
292
+ this._ecRoot.position.subtractToRef(this._mainCamera.position, this._cameraTOec);
293
+ babylonjs_1.Vector3.FromArrayToRef(this._mainCamera.getWorldMatrix().asArray(), 8, this._cameraNormal);
294
+ //get distance of edit control from the camera plane
295
+ //project "camera to edit control" vector onto the camera normal
296
+ let parentOnNormal = babylonjs_1.Vector3.Dot(this._cameraTOec, this._cameraNormal) / this._cameraNormal.length();
297
+ let s = Math.abs(parentOnNormal / this._distFromCamera);
298
+ babylonjs_1.Vector3.FromFloatsToRef(s, s, s, this._ecRoot.scaling);
299
+ //Vector3.FromFloatsToRef(s,s,s,this.pALL.scaling);
300
+ }
301
+ //rotate the rotation guides so that they are facing the camera
302
+ _rotRotGuides() {
303
+ let rotX = Math.atan(this._ecTOcamera.y / this._ecTOcamera.z);
304
+ if (this._ecTOcamera.z >= 0) {
305
+ this._rX.rotation.x = -rotX;
306
+ }
307
+ else {
308
+ this._rX.rotation.x = -rotX - Math.PI;
309
+ }
310
+ let rotY = Math.atan(this._ecTOcamera.x / this._ecTOcamera.z);
311
+ if (this._ecTOcamera.z >= 0) {
312
+ this._rY.rotation.y = rotY;
313
+ }
314
+ else {
315
+ this._rY.rotation.y = rotY + Math.PI;
316
+ }
317
+ let rotZ = Math.atan(this._ecTOcamera.x / this._ecTOcamera.y);
318
+ if (this._ecTOcamera.y >= 0) {
319
+ this._rZ.rotation.z = -rotZ;
320
+ }
321
+ else {
322
+ this._rZ.rotation.z = -rotZ - Math.PI;
323
+ }
324
+ }
325
+ /**
326
+ * rotate the planar guide so that they are facing the camera
327
+ */
328
+ _rotPlanarGuides(XZ, ZY, YX) {
329
+ let ec = this._ecTOcamera;
330
+ XZ.rotation.x = 0;
331
+ XZ.rotation.y = 0;
332
+ XZ.rotation.z = 0;
333
+ ZY.rotation.x = 0;
334
+ ZY.rotation.y = 0;
335
+ ZY.rotation.z = 0;
336
+ YX.rotation.x = 0;
337
+ YX.rotation.y = 0;
338
+ YX.rotation.z = 0;
339
+ if (ec.x <= 0 && ec.y >= 0 && ec.z >= 0) {
340
+ XZ.rotation.z = 3.14;
341
+ YX.rotation.y = 3.14;
342
+ }
343
+ else if (ec.x <= 0 && ec.y >= 0 && ec.z <= 0) {
344
+ XZ.rotation.y = 3.14;
345
+ ZY.rotation.y = 3.14;
346
+ YX.rotation.y = 3.14;
347
+ }
348
+ else if (ec.x >= 0 && ec.y >= 0 && ec.z <= 0) {
349
+ XZ.rotation.x = 3.14;
350
+ ZY.rotation.y = 3.14;
351
+ }
352
+ else if (ec.x >= 0 && ec.y <= 0 && ec.z >= 0) {
353
+ ZY.rotation.z = 3.14;
354
+ YX.rotation.x = 3.14;
355
+ }
356
+ else if (ec.x <= 0 && ec.y <= 0 && ec.z >= 0) {
357
+ XZ.rotation.z = 3.14;
358
+ ZY.rotation.z = 3.14;
359
+ YX.rotation.z = 3.14;
360
+ }
361
+ else if (ec.x <= 0 && ec.y <= 0 && ec.z <= 0) {
362
+ XZ.rotation.y = 3.14;
363
+ ZY.rotation.x = 3.14;
364
+ YX.rotation.z = 3.14;
365
+ }
366
+ else if (ec.x >= 0 && ec.y <= 0 && ec.z <= 0) {
367
+ XZ.rotation.x = 3.14;
368
+ ZY.rotation.x = 3.14;
369
+ YX.rotation.x = 3.14;
370
+ }
371
+ }
372
+ switchTo(mesh) {
373
+ mesh.computeWorldMatrix(true);
374
+ this._mesh = mesh;
375
+ this._setLocalAxes(mesh);
376
+ this._actHist = new ActHist(mesh, 10);
377
+ this._lhsRhs = this._check_LHS_RHS(mesh);
378
+ this.refreshBoundingInfo();
379
+ }
380
+ switchCamera(camera) {
381
+ this._mainCamera = camera;
382
+ }
383
+ setUndoCount(c) {
384
+ this._actHist.setCapacity(c);
385
+ }
386
+ undo() {
387
+ let at = this._actHist.undo();
388
+ this._mesh.computeWorldMatrix(true);
389
+ this._setLocalAxes(this._mesh);
390
+ this._callActionStartListener(at);
391
+ this._callActionListener(at);
392
+ this._callActionEndListener(at);
393
+ }
394
+ redo() {
395
+ let at = this._actHist.redo();
396
+ this._mesh.computeWorldMatrix(true);
397
+ this._setLocalAxes(this._mesh);
398
+ this._callActionStartListener(at);
399
+ this._callActionListener(at);
400
+ this._callActionEndListener(at);
401
+ }
402
+ /**
403
+ * detach the edit control from the mesh and dispose off all
404
+ * resources created by the edit control
405
+ */
406
+ detach() {
407
+ this._canvas.removeEventListener("pointerdown", this._pointerdown, false);
408
+ this._canvas.removeEventListener("pointerup", this._pointerup, false);
409
+ this._canvas.removeEventListener("pointermove", this._pointermove, false);
410
+ this._scene.unregisterBeforeRender(this._renderer);
411
+ this.removeAllActionListeners();
412
+ this._disposeAll();
413
+ }
414
+ /**
415
+ * hide the edit control. use show() to unhide the control.
416
+ */
417
+ hide() {
418
+ this._hidden = true;
419
+ if (this._transEnabled) {
420
+ this._prevState = "T";
421
+ this.disableTranslation();
422
+ }
423
+ else if (this._rotEnabled) {
424
+ this._prevState = "R";
425
+ this.disableRotation();
426
+ }
427
+ else if (this._scaleEnabled) {
428
+ this._prevState = "S";
429
+ this.disableScaling();
430
+ }
431
+ this._hideCommonAxes();
432
+ }
433
+ _hideCommonAxes() {
434
+ this._xaxis.visibility = 0;
435
+ this._yaxis.visibility = 0;
436
+ this._zaxis.visibility = 0;
437
+ }
438
+ _showCommonAxes() {
439
+ this._xaxis.visibility = this._visibility;
440
+ this._yaxis.visibility = this._visibility;
441
+ this._zaxis.visibility = this._visibility;
442
+ }
443
+ /**
444
+ * unhide the editcontrol hidden using the hide() method
445
+ */
446
+ show() {
447
+ this._hidden = false;
448
+ this._showCommonAxes();
449
+ if (this._prevState == "T")
450
+ this.enableTranslation();
451
+ else if (this._prevState == "R")
452
+ this.enableRotation();
453
+ else if (this._prevState == "S")
454
+ this.enableScaling();
455
+ }
456
+ /**
457
+ * check if the editcontrol was hidden using the hide() methods
458
+ */
459
+ isHidden() {
460
+ return this._hidden;
461
+ }
462
+ _disposeAll() {
463
+ this._ecRoot.dispose();
464
+ this._disposeMaterials();
465
+ this._actHist = null;
466
+ }
467
+ addActionListener(actionListener) {
468
+ this._actionListener = actionListener;
469
+ }
470
+ removeActionListener() {
471
+ this._actionListener = null;
472
+ }
473
+ addActionStartListener(actionStartListener) {
474
+ this._actionStartListener = actionStartListener;
475
+ }
476
+ removeActionStartListener() {
477
+ this._actionStartListener = null;
478
+ }
479
+ addActionEndListener(actionEndListener) {
480
+ this._actionEndListener = actionEndListener;
481
+ }
482
+ removeActionEndListener() {
483
+ this._actionEndListener = null;
484
+ }
485
+ removeAllActionListeners() {
486
+ this._actionListener = null;
487
+ this._actionStartListener = null;
488
+ this._actionEndListener = null;
489
+ }
490
+ _onPointerDown(evt) {
491
+ evt.preventDefault();
492
+ this._pDown = true;
493
+ if (evt.button != 0)
494
+ return;
495
+ let engine = this._scene.getEngine();
496
+ let x = (engine.isPointerLock) ? this._canvas.width * 0.5 : this._scene.pointerX;
497
+ let y = (engine.isPointerLock) ? this._canvas.height * 0.5 : this._scene.pointerY;
498
+ let pickResult = this._scene.pick(x, y, (mesh) => {
499
+ if (this._transEnabled) {
500
+ if ((mesh == this._tX) || (mesh == this._tY) || (mesh == this._tZ) || (mesh == this._tXZ) || (mesh == this._tZY) || (mesh == this._tYX) || (mesh == this._tAll))
501
+ return true;
502
+ }
503
+ else if ((this._rotEnabled)) {
504
+ if ((mesh == this._rX) || (mesh == this._rY) || (mesh == this._rZ) || (mesh == this._rAll))
505
+ return true;
506
+ }
507
+ else if ((this._scaleEnabled)) {
508
+ if ((mesh == this._sX) || (mesh == this._sY) || (mesh == this._sZ) || (mesh == this._sXZ) || (mesh == this._sZY) || (mesh == this._sYX) || (mesh == this._sAll))
509
+ return true;
510
+ }
511
+ return false;
512
+ }, false, this._mainCamera);
513
+ if (pickResult.hit) {
514
+ //this.setAxesVisiblity(0);
515
+ this._axisPicked = pickResult.pickedMesh;
516
+ let childs = this._axisPicked.getChildren();
517
+ if (childs.length > 0) {
518
+ childs[0].visibility = this._visibility;
519
+ }
520
+ else {
521
+ this._axisPicked.visibility = this._visibility;
522
+ }
523
+ let name = this._axisPicked.name;
524
+ if ((name == "X"))
525
+ this._bXaxis.visibility = 1;
526
+ else if ((name == "Y"))
527
+ this._bYaxis.visibility = 1;
528
+ else if ((name == "Z"))
529
+ this._bZaxis.visibility = 1;
530
+ else if ((name == "XZ")) {
531
+ this._bXaxis.visibility = 1;
532
+ this._bZaxis.visibility = 1;
533
+ }
534
+ else if ((name == "ZY")) {
535
+ this._bZaxis.visibility = 1;
536
+ this._bYaxis.visibility = 1;
537
+ }
538
+ else if ((name == "YX")) {
539
+ this._bYaxis.visibility = 1;
540
+ this._bXaxis.visibility = 1;
541
+ }
542
+ else if ((name == "ALL")) {
543
+ this._bXaxis.visibility = 1;
544
+ this._bYaxis.visibility = 1;
545
+ this._bZaxis.visibility = 1;
546
+ }
547
+ this._setEditing(true);
548
+ //lets find out where we are on the pickplane
549
+ this._pickedPlane = this._getPickPlane(this._axisPicked);
550
+ if (this._pickedPlane != null) {
551
+ this._prevPos = this._getPosOnPickPlane();
552
+ }
553
+ else {
554
+ this._prevPos = null;
555
+ }
556
+ window.setTimeout(((cam, can) => { return this._detachCamera(cam, can); }), 0, this._mainCamera, this._canvas);
557
+ }
558
+ }
559
+ _setEditing(editing) {
560
+ this._editing = editing;
561
+ if (editing) {
562
+ this._setActionType();
563
+ if (this._actionType == ActionType.ROT) {
564
+ this._snapRA = 0;
565
+ }
566
+ this._callActionStartListener(this._actionType);
567
+ }
568
+ else {
569
+ this._callActionEndListener(this._actionType);
570
+ }
571
+ }
572
+ isEditing() {
573
+ return this._editing;
574
+ }
575
+ /**
576
+ * no camera movement during edit
577
+ */
578
+ _detachCamera(cam, can) {
579
+ let camera = cam;
580
+ let canvas = can;
581
+ let engine = this._scene.getEngine();
582
+ if (!engine.isPointerLock) {
583
+ camera.detachControl(canvas);
584
+ }
585
+ }
586
+ isPointerOver() {
587
+ return this._pointerIsOver;
588
+ }
589
+ _onPointerOver() {
590
+ //if(this.pDown) return;
591
+ let engine = this._scene.getEngine();
592
+ let x = (engine.isPointerLock) ? this._canvas.width * 0.5 : this._scene.pointerX;
593
+ let y = (engine.isPointerLock) ? this._canvas.height * 0.5 : this._scene.pointerY;
594
+ let pickResult = this._scene.pick(x, y, (mesh) => {
595
+ if (this._transEnabled) {
596
+ if ((mesh == this._tX) || (mesh == this._tY) || (mesh == this._tZ) || (mesh == this._tXZ) || (mesh == this._tZY) || (mesh == this._tYX) || (mesh == this._tAll))
597
+ return true;
598
+ }
599
+ else if ((this._rotEnabled)) {
600
+ if ((mesh == this._rX) || (mesh == this._rY) || (mesh == this._rZ) || (mesh == this._rAll))
601
+ return true;
602
+ }
603
+ else if (this._scaleEnabled) {
604
+ if ((mesh == this._sX) || (mesh == this._sY) || (mesh == this._sZ) || (mesh == this._sXZ) || (mesh == this._sZY) || (mesh == this._sYX) || (mesh == this._sAll))
605
+ return true;
606
+ }
607
+ return false;
608
+ }, false, this._mainCamera);
609
+ if (pickResult.hit) {
610
+ //if we are still over the same axis mesh then don't do anything
611
+ if (pickResult.pickedMesh != this._prevOverMesh) {
612
+ this._pointerIsOver = true;
613
+ //if we moved directly from one axis mesh to this then clean up the prev axis mesh
614
+ this._clearPrevOverMesh();
615
+ this._prevOverMesh = pickResult.pickedMesh;
616
+ if (this._rotEnabled) {
617
+ this._savedCol = this._prevOverMesh.getChildren()[0].color;
618
+ this._prevOverMesh.getChildren()[0].color = this._yellowCol;
619
+ }
620
+ else {
621
+ let childs = this._prevOverMesh.getChildren();
622
+ if (childs.length > 0) {
623
+ this._savedMat = childs[0].material;
624
+ childs[0].material = this._whiteMat;
625
+ }
626
+ else {
627
+ this._savedMat = this._prevOverMesh.material;
628
+ this._prevOverMesh.material = this._whiteMat;
629
+ }
630
+ }
631
+ if (this._prevOverMesh.name == "X") {
632
+ this._xaxis.color = this._yellowCol;
633
+ }
634
+ else if (this._prevOverMesh.name == "Y") {
635
+ this._yaxis.color = this._yellowCol;
636
+ }
637
+ else if (this._prevOverMesh.name == "Z") {
638
+ this._zaxis.color = this._yellowCol;
639
+ }
640
+ }
641
+ }
642
+ else {
643
+ this._pointerIsOver = false;
644
+ if (this._prevOverMesh != null) {
645
+ this._restoreColor(this._prevOverMesh);
646
+ this._prevOverMesh = null;
647
+ }
648
+ }
649
+ }
650
+ //clean up any axis we might have been howering over before
651
+ _clearPrevOverMesh() {
652
+ if (this._prevOverMesh != null) {
653
+ this._prevOverMesh.visibility = 0;
654
+ this._restoreColor(this._prevOverMesh);
655
+ }
656
+ }
657
+ _restoreColor(mesh) {
658
+ switch (mesh.name) {
659
+ case "X":
660
+ this._xaxis.color = this._redCol;
661
+ break;
662
+ case "Y":
663
+ this._yaxis.color = this._greenCol;
664
+ break;
665
+ case "Z":
666
+ this._zaxis.color = this._blueCol;
667
+ break;
668
+ }
669
+ if (this._rotEnabled) {
670
+ mesh.getChildren()[0].color = this._savedCol;
671
+ }
672
+ else {
673
+ let childs = mesh.getChildren();
674
+ if (childs.length > 0) {
675
+ childs[0].material = this._savedMat;
676
+ }
677
+ else {
678
+ mesh.material = this._savedMat;
679
+ }
680
+ }
681
+ }
682
+ _onPointerUp(evt) {
683
+ this._pDown = false;
684
+ if (this._editing) {
685
+ let engine = this._scene.getEngine();
686
+ if (!engine.isPointerLock) {
687
+ this._mainCamera.attachControl(true);
688
+ }
689
+ this._setEditing(false);
690
+ //this.setAxesVisiblity(1);
691
+ this._hideBaxis();
692
+ if (this._prevOverMesh != null) {
693
+ this._restoreColor(this._prevOverMesh);
694
+ this._prevOverMesh = null;
695
+ }
696
+ this._actHist.add(this._actionType);
697
+ }
698
+ }
699
+ _setActionType() {
700
+ if (this._transEnabled) {
701
+ this._actionType = ActionType.TRANS;
702
+ }
703
+ else if ((this._rotEnabled)) {
704
+ this._actionType = ActionType.ROT;
705
+ }
706
+ else if ((this._scaleEnabled)) {
707
+ this._actionType = ActionType.SCALE;
708
+ }
709
+ }
710
+ _callActionListener(at) {
711
+ //call actionListener if registered
712
+ if (this._actionListener != null) {
713
+ this._actionListener(at);
714
+ }
715
+ }
716
+ _callActionStartListener(at) {
717
+ //call actionListener if registered
718
+ if (this._actionStartListener != null) {
719
+ this._actionStartListener(at);
720
+ }
721
+ }
722
+ _callActionEndListener(at) {
723
+ //call actionListener if registered
724
+ if (this._actionEndListener != null) {
725
+ this._actionEndListener(at);
726
+ }
727
+ }
728
+ _onPointerMove(evt) {
729
+ if (!this._pDown) {
730
+ this._onPointerOver();
731
+ return;
732
+ }
733
+ if (!this._editing)
734
+ return;
735
+ if (this._prevPos == null)
736
+ return;
737
+ let newPos = this._getPosOnPickPlane();
738
+ if (newPos == null)
739
+ return;
740
+ if (this._rotEnabled) {
741
+ this._doRotation(this._mesh, this._axisPicked, newPos, this._prevPos);
742
+ }
743
+ else {
744
+ let diff = newPos.subtract(this._prevPos);
745
+ if (diff.x == 0 && diff.y == 0 && diff.z == 0)
746
+ return;
747
+ if (this._transEnabled) {
748
+ this._doTranslation(diff);
749
+ }
750
+ else {
751
+ if (this._scaleEnabled && this._local)
752
+ this._doScaling(diff);
753
+ }
754
+ }
755
+ this._prevPos = newPos;
756
+ this._callActionListener(this._actionType);
757
+ }
758
+ _getPickPlane(axis) {
759
+ let n = axis.name;
760
+ if (this._transEnabled || this._scaleEnabled) {
761
+ if (n == "XZ")
762
+ return this._pXZ;
763
+ else if (n == "ZY")
764
+ return this._pZY;
765
+ else if (n == "YX")
766
+ return this._pYX;
767
+ else if (n == "ALL")
768
+ return this._pALL;
769
+ else {
770
+ //get the position of camera in the edit control frame of reference
771
+ this._ecRoot.getWorldMatrix().invertToRef(this._ecMatrix);
772
+ babylonjs_1.Vector3.TransformCoordinatesToRef(this._mainCamera.position, this._ecMatrix, this._ecTOcamera);
773
+ let c = this._ecTOcamera;
774
+ if (n === "X") {
775
+ if (Math.abs(c.y) > Math.abs(c.z)) {
776
+ return this._pXZ;
777
+ }
778
+ else
779
+ return this._pYX;
780
+ }
781
+ else if (n === "Z") {
782
+ if (Math.abs(c.y) > Math.abs(c.x)) {
783
+ return this._pXZ;
784
+ }
785
+ else
786
+ return this._pZY;
787
+ }
788
+ else if (n === "Y") {
789
+ if (Math.abs(c.z) > Math.abs(c.x)) {
790
+ return this._pYX;
791
+ }
792
+ else
793
+ return this._pZY;
794
+ }
795
+ }
796
+ }
797
+ else if (this._rotEnabled) {
798
+ this._rotate2 = false;
799
+ //get the position of camera in the edit control frame of reference
800
+ this._ecRoot.getWorldMatrix().invertToRef(this._ecMatrix);
801
+ babylonjs_1.Vector3.TransformCoordinatesToRef(this._mainCamera.position, this._ecMatrix, this._ecTOcamera);
802
+ let c = this._ecTOcamera;
803
+ //if camera is too close to the rotation plane then use alternate rotation process
804
+ switch (n) {
805
+ case "X":
806
+ if (Math.abs(c.x) < 0.2) {
807
+ this._rotate2 = true;
808
+ return this._pALL;
809
+ }
810
+ else
811
+ return this._pZY;
812
+ case "Y":
813
+ if (Math.abs(c.y) < 0.2) {
814
+ this._rotate2 = true;
815
+ return this._pALL;
816
+ }
817
+ else
818
+ return this._pXZ;
819
+ case "Z":
820
+ if (Math.abs(c.z) < 0.2) {
821
+ this._rotate2 = true;
822
+ return this._pALL;
823
+ }
824
+ else
825
+ return this._pYX;
826
+ default:
827
+ return this._pALL;
828
+ }
829
+ }
830
+ else
831
+ return null;
832
+ }
833
+ _doTranslation(diff) {
834
+ if ((this._mesh.parent != null) && this._isScaleUnEqual(this._mesh)) {
835
+ this._setLocalAxes(this._ecRoot);
836
+ }
837
+ else {
838
+ this._setLocalAxes(this._mesh);
839
+ }
840
+ let n = this._axisPicked.name;
841
+ this._transBy.x = 0;
842
+ this._transBy.y = 0;
843
+ this._transBy.z = 0;
844
+ if ((n == "X") || (n == "XZ") || (n == "YX") || (n == "ALL")) {
845
+ if (this._local)
846
+ this._transBy.x = babylonjs_1.Vector3.Dot(diff, this._localX) / this._localX.length();
847
+ else
848
+ this._transBy.x = diff.x;
849
+ }
850
+ if ((n == "Y") || (n == "ZY") || (n == "YX") || (n == "ALL")) {
851
+ if (this._local)
852
+ this._transBy.y = babylonjs_1.Vector3.Dot(diff, this._localY) / this._localY.length();
853
+ else
854
+ this._transBy.y = diff.y;
855
+ }
856
+ if ((n == "Z") || (n == "XZ") || (n == "ZY") || (n == "ALL")) {
857
+ if (this._local)
858
+ this._transBy.z = babylonjs_1.Vector3.Dot(diff, this._localZ) / this._localZ.length();
859
+ else
860
+ this._transBy.z = diff.z;
861
+ }
862
+ this._transWithSnap(this._mesh, this._transBy, this._local);
863
+ // bound the translation
864
+ if (this._transBoundsMin) {
865
+ this._mesh.position.x = Math.max(this._mesh.position.x, this._transBoundsMin.x);
866
+ this._mesh.position.y = Math.max(this._mesh.position.y, this._transBoundsMin.y);
867
+ this._mesh.position.z = Math.max(this._mesh.position.z, this._transBoundsMin.z);
868
+ }
869
+ if (this._transBoundsMax) {
870
+ this._mesh.position.x = Math.min(this._mesh.position.x, this._transBoundsMax.x);
871
+ this._mesh.position.y = Math.min(this._mesh.position.y, this._transBoundsMax.y);
872
+ this._mesh.position.z = Math.min(this._mesh.position.z, this._transBoundsMax.z);
873
+ }
874
+ this._mesh.computeWorldMatrix(true);
875
+ }
876
+ _transWithSnap(mesh, trans, local) {
877
+ if (this._snapT) {
878
+ let snapit = false;
879
+ this._snapTV.addInPlace(trans);
880
+ if (Math.abs(this._snapTV.x) > this._tSnap.x) {
881
+ if (this._snapTV.x > 0)
882
+ trans.x = this._tSnap.x;
883
+ else
884
+ trans.x = -this._tSnap.x;
885
+ snapit = true;
886
+ }
887
+ if (Math.abs(this._snapTV.y) > this._tSnap.y) {
888
+ if (this._snapTV.y > 0)
889
+ trans.y = this._tSnap.y;
890
+ else
891
+ trans.y = -this._tSnap.y;
892
+ snapit = true;
893
+ }
894
+ if (Math.abs(this._snapTV.z) > this._tSnap.z) {
895
+ if (this._snapTV.z > 0)
896
+ trans.z = this._tSnap.z;
897
+ else
898
+ trans.z = -this._tSnap.z;
899
+ snapit = true;
900
+ }
901
+ if (snapit) {
902
+ if (Math.abs(trans.x) !== this._tSnap.x)
903
+ trans.x = 0;
904
+ if (Math.abs(trans.y) !== this._tSnap.y)
905
+ trans.y = 0;
906
+ if (Math.abs(trans.z) !== this._tSnap.z)
907
+ trans.z = 0;
908
+ babylonjs_1.Vector3.FromFloatsToRef(0, 0, 0, this._snapTV);
909
+ snapit = false;
910
+ }
911
+ else {
912
+ return;
913
+ }
914
+ }
915
+ if (local) {
916
+ //locallyTranslate moves the mesh wrt the absolute location not pivotlocation :(
917
+ //this.mesh.locallyTranslate(trans);
918
+ //
919
+ this._localX.normalizeToRef(this._tv1);
920
+ this._localY.normalizeToRef(this._tv2);
921
+ this._localZ.normalizeToRef(this._tv3);
922
+ this._mesh.translate(this._tv1, trans.x, babylonjs_1.Space.WORLD);
923
+ this._mesh.translate(this._tv2, trans.y, babylonjs_1.Space.WORLD);
924
+ this._mesh.translate(this._tv3, trans.z, babylonjs_1.Space.WORLD);
925
+ }
926
+ else {
927
+ if (this._mesh.parent == null) {
928
+ this._mesh.position.addInPlace(trans);
929
+ }
930
+ else {
931
+ this._mesh.setAbsolutePosition(trans.addInPlace(this._mesh.absolutePosition));
932
+ }
933
+ }
934
+ }
935
+ _doScaling(diff) {
936
+ this._setLocalAxes(this._mesh);
937
+ this._scale.x = 0;
938
+ this._scale.y = 0;
939
+ this._scale.z = 0;
940
+ let n = this._axisPicked.name;
941
+ if ((n == "X") || (n == "XZ") || (n == "YX")) {
942
+ this._scale.x = babylonjs_1.Vector3.Dot(diff, this._localX) / this._localX.length();
943
+ if (this._mesh.scaling.x < 0)
944
+ this._scale.x = -this._scale.x;
945
+ //if(this.lhsRhs) this.scale.x=-this.scale.x;
946
+ }
947
+ if ((n == "Y") || (n == "ZY") || (n == "YX")) {
948
+ this._scale.y = babylonjs_1.Vector3.Dot(diff, this._localY) / this._localY.length();
949
+ if (this._mesh.scaling.y < 0)
950
+ this._scale.y = -this._scale.y;
951
+ }
952
+ if ((n == "Z") || (n == "XZ") || (n == "ZY")) {
953
+ this._scale.z = babylonjs_1.Vector3.Dot(diff, this._localZ) / this._localZ.length();
954
+ if (this._mesh.scaling.z < 0)
955
+ this._scale.z = -this._scale.z;
956
+ }
957
+ //as the mesh becomes large reduce the amount by which we scale.
958
+ let bbd = this._boundingDimesion;
959
+ this._scale.x = this._scale.x / bbd.x;
960
+ this._scale.y = this._scale.y / bbd.y;
961
+ this._scale.z = this._scale.z / bbd.z;
962
+ if (n == "ALL") {
963
+ //project movement along camera up vector
964
+ //if up then scale up else scale down
965
+ let s = babylonjs_1.Vector3.Dot(diff, this._mainCamera.upVector);
966
+ s = s / Math.max(bbd.x, bbd.y, bbd.z);
967
+ this._scale.copyFromFloats(s, s, s);
968
+ }
969
+ else {
970
+ let inPlane = false;
971
+ if (n == "XZ") {
972
+ inPlane = true;
973
+ if (Math.abs(this._scale.x) > Math.abs(this._scale.z)) {
974
+ this._scale.z = this._scale.x;
975
+ }
976
+ else
977
+ this._scale.x = this._scale.z;
978
+ }
979
+ else if (n == "ZY") {
980
+ inPlane = true;
981
+ if (Math.abs(this._scale.z) > Math.abs(this._scale.y)) {
982
+ this._scale.y = this._scale.z;
983
+ }
984
+ else
985
+ this._scale.z = this._scale.y;
986
+ }
987
+ else if (n == "YX") {
988
+ inPlane = true;
989
+ if (Math.abs(this._scale.y) > Math.abs(this._scale.x)) {
990
+ this._scale.x = this._scale.y;
991
+ }
992
+ else
993
+ this._scale.y = this._scale.x;
994
+ }
995
+ if (inPlane) {
996
+ //check if the mouse/pointer was moved towards camera or away from camera
997
+ //if towards then scale up else scale down
998
+ this._ecRoot.position.subtractToRef(this._mainCamera.position, this._cameraTOec);
999
+ let s = babylonjs_1.Vector3.Dot(diff, this._cameraTOec);
1000
+ this._scale.x = Math.abs(this._scale.x);
1001
+ this._scale.y = Math.abs(this._scale.y);
1002
+ this._scale.z = Math.abs(this._scale.z);
1003
+ if (s > 0) {
1004
+ if (this._mesh.scaling.x > 0)
1005
+ this._scale.x = -this._scale.x;
1006
+ //if(this.lhsRhs) this.scale.y=Math.abs(this.scale.y);
1007
+ if (this._mesh.scaling.y > 0)
1008
+ this._scale.y = -this._scale.y;
1009
+ if (this._mesh.scaling.z > 0)
1010
+ this._scale.z = -this._scale.z;
1011
+ }
1012
+ else {
1013
+ //this.scale.x=Math.abs(this.scale.x);
1014
+ //if(this.lhsRhs) this.scale.y=-Math.abs(this.scale.y);
1015
+ //else this.scale.y=Math.abs(this.scale.y);
1016
+ if (this._mesh.scaling.x < 0)
1017
+ this._scale.x = -this._scale.x;
1018
+ if (this._mesh.scaling.y < 0)
1019
+ this._scale.y = -this._scale.y;
1020
+ if (this._mesh.scaling.z < 0)
1021
+ this._scale.z = -this._scale.z;
1022
+ }
1023
+ }
1024
+ }
1025
+ this._scaleWithSnap(this._mesh, this._scale);
1026
+ // bound the scale
1027
+ if (this._scaleBoundsMin) {
1028
+ this._mesh.scaling.x = Math.max(this._mesh.scaling.x, this._scaleBoundsMin.x);
1029
+ this._mesh.scaling.y = Math.max(this._mesh.scaling.y, this._scaleBoundsMin.y);
1030
+ this._mesh.scaling.z = Math.max(this._mesh.scaling.z, this._scaleBoundsMin.z);
1031
+ }
1032
+ if (this._scaleBoundsMax) {
1033
+ this._mesh.scaling.x = Math.min(this._mesh.scaling.x, this._scaleBoundsMax.x);
1034
+ this._mesh.scaling.y = Math.min(this._mesh.scaling.y, this._scaleBoundsMax.y);
1035
+ this._mesh.scaling.z = Math.min(this._mesh.scaling.z, this._scaleBoundsMax.z);
1036
+ }
1037
+ }
1038
+ _scaleWithSnap(mesh, p) {
1039
+ if (this._snapS) {
1040
+ let snapit = false;
1041
+ this._snapSV.addInPlace(p);
1042
+ if (Math.abs(this._snapSV.x) > this._scaleSnap) {
1043
+ if (p.x > 0)
1044
+ p.x = this._scaleSnap;
1045
+ else
1046
+ p.x = -this._scaleSnap;
1047
+ snapit = true;
1048
+ }
1049
+ if (Math.abs(this._snapSV.y) > this._scaleSnap) {
1050
+ if (p.y > 0)
1051
+ p.y = this._scaleSnap;
1052
+ else
1053
+ p.y = -this._scaleSnap;
1054
+ snapit = true;
1055
+ }
1056
+ if (Math.abs(this._snapSV.z) > this._scaleSnap) {
1057
+ if (p.z > 0)
1058
+ p.z = this._scaleSnap;
1059
+ else
1060
+ p.z = -this._scaleSnap;
1061
+ snapit = true;
1062
+ }
1063
+ if (!snapit)
1064
+ return;
1065
+ if ((Math.abs(p.x) !== this._scaleSnap) && (p.x !== 0))
1066
+ p.x = 0;
1067
+ if ((Math.abs(p.y) !== this._scaleSnap) && (p.y !== 0))
1068
+ p.y = 0;
1069
+ if ((Math.abs(p.z) !== this._scaleSnap) && (p.z !== 0))
1070
+ p.z = 0;
1071
+ babylonjs_1.Vector3.FromFloatsToRef(0, 0, 0, this._snapSV);
1072
+ snapit = false;
1073
+ }
1074
+ mesh.scaling.addInPlace(p);
1075
+ }
1076
+ /*
1077
+ * This would be called after rotation or scaling as the local axes direction or length might have changed
1078
+ * We need to set the local axis as these are used in all three modes to figure out
1079
+ * direction of mouse move wrt the axes
1080
+ * TODO should use world pivotmatrix instead of worldmatrix - incase pivot axes were rotated?
1081
+ */
1082
+ _setLocalAxes(mesh) {
1083
+ let meshMatrix = mesh.getWorldMatrix();
1084
+ babylonjs_1.Vector3.FromArrayToRef(meshMatrix.m, 0, this._localX);
1085
+ babylonjs_1.Vector3.FromArrayToRef(meshMatrix.m, 4, this._localY);
1086
+ babylonjs_1.Vector3.FromArrayToRef(meshMatrix.m, 8, this._localZ);
1087
+ }
1088
+ _getBoundingDimension(mesh) {
1089
+ if (mesh instanceof babylonjs_1.AbstractMesh) {
1090
+ { }
1091
+ let bb = mesh.getBoundingInfo().boundingBox;
1092
+ let bd = bb.maximum.subtract(bb.minimum);
1093
+ if (bd.x == 0)
1094
+ bd.x = 1;
1095
+ if (bd.y == 0)
1096
+ bd.y = 1;
1097
+ if (bd.z == 0)
1098
+ bd.z = 1;
1099
+ return bd;
1100
+ }
1101
+ else
1102
+ return new babylonjs_1.Vector3(1, 1, 1);
1103
+ }
1104
+ /*
1105
+ *
1106
+ * For the sake of speed the editcontrol calculates bounding info only once.
1107
+ * This is in the constructor.
1108
+ * Now The boundingbox dimension can change if the mesh is baked.
1109
+ * If the editcontrol is attached to the mesh when the mesh was baked then
1110
+ * the scaling speed will be incorrect.
1111
+ * Thus client application should call refreshBoundingInfo if it bakes the mesh.
1112
+ *
1113
+ */
1114
+ refreshBoundingInfo() {
1115
+ this._boundingDimesion = this._getBoundingDimension(this._mesh);
1116
+ }
1117
+ _doRotation(mesh, axis, newPos, prevPos) {
1118
+ //for now no rotation if parents have non uniform scale
1119
+ if (this._local && (this._mesh.parent != null) && this._isScaleUnEqual(mesh)) {
1120
+ this._setLocalAxes(this._ecRoot);
1121
+ }
1122
+ else {
1123
+ this._setLocalAxes(mesh);
1124
+ }
1125
+ let angle = 0;
1126
+ //rotation axis
1127
+ let rAxis;
1128
+ if (axis == this._rX)
1129
+ rAxis = this._local ? this._localX : babylonjs_1.Axis.X;
1130
+ else if (axis == this._rY)
1131
+ rAxis = this._local ? this._localY : babylonjs_1.Axis.Y;
1132
+ else if (axis == this._rZ)
1133
+ rAxis = this._local ? this._localZ : babylonjs_1.Axis.Z;
1134
+ this._ecRoot.position.subtractToRef(this._mainCamera.position, this._cameraTOec);
1135
+ /**
1136
+ * A)first find the angle and the direction (clockwise or anticlockwise) by which the user was trying to rotate
1137
+ * from the user(camera) perspective
1138
+ */
1139
+ if (this._rotate2) {
1140
+ angle = this._getAngle2(prevPos, newPos, this._mainCamera.position, this._cameraTOec, rAxis);
1141
+ //TODO check why we need to handle righ hand this way
1142
+ if (this._scene.useRightHandedSystem)
1143
+ angle = -angle;
1144
+ }
1145
+ else {
1146
+ angle = this._getAngle(prevPos, newPos, mesh.getAbsolutePivotPoint(), this._cameraTOec);
1147
+ }
1148
+ if (this._lhsRhs) {
1149
+ angle = -angle;
1150
+ }
1151
+ /**
1152
+ * B)then rotate based on users(camera) postion and orientation in the local/world space
1153
+ *
1154
+ */
1155
+ if (this._snapR) {
1156
+ this._snapRA += angle;
1157
+ angle = 0;
1158
+ if (Math.abs(this._snapRA) >= this._rotSnap) {
1159
+ if (this._snapRA > 0)
1160
+ angle = this._rotSnap;
1161
+ else
1162
+ angle = -this._rotSnap;
1163
+ this._snapRA = 0;
1164
+ }
1165
+ }
1166
+ if (angle !== 0) {
1167
+ this._cameraTOec.normalize();
1168
+ if (axis == this._rAll) {
1169
+ mesh.rotate(this._cameraTOec, -angle, babylonjs_1.Space.WORLD);
1170
+ }
1171
+ else {
1172
+ if (babylonjs_1.Vector3.Dot(rAxis, this._cameraTOec) >= 0)
1173
+ angle = -angle;
1174
+ mesh.rotate(rAxis, angle, babylonjs_1.Space.WORLD);
1175
+ }
1176
+ if (this._local) {
1177
+ if (this._lhsRhs) {
1178
+ angle = -angle;
1179
+ }
1180
+ if ((this._mesh.parent != null) && this._isScaleUnEqual(mesh)) {
1181
+ if (axis == this._rAll) {
1182
+ this._ecRoot.rotate(this._cameraTOec, -angle, babylonjs_1.Space.WORLD);
1183
+ }
1184
+ else {
1185
+ this._ecRoot.rotate(rAxis, angle, babylonjs_1.Space.WORLD);
1186
+ }
1187
+ }
1188
+ }
1189
+ }
1190
+ }
1191
+ _getPosOnPickPlane() {
1192
+ let engine = this._scene.getEngine();
1193
+ let x = (engine.isPointerLock) ? this._canvas.width * 0.5 : this._scene.pointerX;
1194
+ let y = (engine.isPointerLock) ? this._canvas.height * 0.5 : this._scene.pointerY;
1195
+ let pickinfo = this._scene.pick(x, y, (mesh) => {
1196
+ return mesh == this._pickedPlane;
1197
+ }, null, this._mainCamera);
1198
+ if (pickinfo.hit) {
1199
+ return pickinfo.pickedPoint;
1200
+ }
1201
+ else {
1202
+ return null;
1203
+ }
1204
+ }
1205
+ _hideBaxis() {
1206
+ this._bXaxis.visibility = 0;
1207
+ this._bYaxis.visibility = 0;
1208
+ this._bZaxis.visibility = 0;
1209
+ }
1210
+ // private _setAxesVisiblity(v: number) {
1211
+ // if (this._transEnabled) {
1212
+ // this._tEndX.visibility = v;
1213
+ // this._tEndY.visibility = v;
1214
+ // this._tEndZ.visibility = v;
1215
+ // this._tEndXZ.visibility = v;
1216
+ // this._tEndZY.visibility = v;
1217
+ // this._tEndYX.visibility = v;
1218
+ // this._tEndAll.visibility = v;
1219
+ // }
1220
+ // if (this._rotEnabled) {
1221
+ // this._rEndX.visibility = v;
1222
+ // this._rEndY.visibility = v;
1223
+ // this._rEndZ.visibility = v;
1224
+ // this._rEndAll.visibility = v;
1225
+ // }
1226
+ // if (this._scaleEnabled) {
1227
+ // this._sEndX.visibility = v;
1228
+ // this._sEndY.visibility = v;
1229
+ // this._sEndZ.visibility = v;
1230
+ // this._sEndXZ.visibility = v;
1231
+ // this._sEndZY.visibility = v;
1232
+ // this._sEndYX.visibility = v;
1233
+ // this._sEndAll.visibility = v;
1234
+ // }
1235
+ // }
1236
+ getRotationQuaternion() {
1237
+ return this._ecRoot.rotationQuaternion;
1238
+ }
1239
+ getPosition() {
1240
+ return this._ecRoot.position;
1241
+ }
1242
+ isTranslationEnabled() {
1243
+ return this._transEnabled;
1244
+ }
1245
+ enableTranslation() {
1246
+ if (this._hidden)
1247
+ return;
1248
+ if (this._tX == null) {
1249
+ this._createTransAxes();
1250
+ this._tCtl.parent = this._ecRoot;
1251
+ }
1252
+ this._clearPrevOverMesh();
1253
+ if (!this._transEnabled) {
1254
+ this._setVisibility(this._all_tEnd, this._visibility);
1255
+ this._transEnabled = true;
1256
+ this.disableRotation();
1257
+ this.disableScaling();
1258
+ }
1259
+ }
1260
+ disableTranslation() {
1261
+ if (this._transEnabled) {
1262
+ this._setVisibility(this._all_tEnd, 0);
1263
+ this._transEnabled = false;
1264
+ }
1265
+ }
1266
+ isRotationEnabled() {
1267
+ return this._rotEnabled;
1268
+ }
1269
+ enableRotation() {
1270
+ if (this._hidden)
1271
+ return;
1272
+ if (this._rCtl == null) {
1273
+ this._createRotAxes();
1274
+ this._rCtl.parent = this._ecRoot;
1275
+ }
1276
+ this._clearPrevOverMesh();
1277
+ if (!this._rotEnabled) {
1278
+ this._setVisibility(this._all_rEnd, this._visibility);
1279
+ this._rotEnabled = true;
1280
+ this.disableTranslation();
1281
+ this.disableScaling();
1282
+ }
1283
+ }
1284
+ disableRotation() {
1285
+ if (this._rotEnabled) {
1286
+ this._setVisibility(this._all_rEnd, 0);
1287
+ this._rotEnabled = false;
1288
+ }
1289
+ }
1290
+ isScalingEnabled() {
1291
+ return this._scaleEnabled;
1292
+ }
1293
+ enableScaling() {
1294
+ if (this._hidden)
1295
+ return;
1296
+ if (this._sX == null) {
1297
+ this._createScaleAxes();
1298
+ this._sCtl.parent = this._ecRoot;
1299
+ }
1300
+ this._clearPrevOverMesh();
1301
+ if (!this._scaleEnabled) {
1302
+ this._setVisibility(this._all_sEnd, this._visibility);
1303
+ this._scaleEnabled = true;
1304
+ this.disableTranslation();
1305
+ this.disableRotation();
1306
+ }
1307
+ }
1308
+ disableScaling() {
1309
+ if (this._scaleEnabled) {
1310
+ this._setVisibility(this._all_sEnd, 0);
1311
+ this._scaleEnabled = false;
1312
+ }
1313
+ }
1314
+ setScaleBounds(min, max) {
1315
+ this._scaleBoundsMin = min ? min : null;
1316
+ this._scaleBoundsMax = max ? max : null;
1317
+ if (this._scaleBoundsMin != null) {
1318
+ if (this._scaleBoundsMin.x == 0)
1319
+ this._scaleBoundsMin.x = 0.00000001;
1320
+ if (this._scaleBoundsMin.y == 0)
1321
+ this._scaleBoundsMin.y = 0.00000001;
1322
+ if (this._scaleBoundsMin.z == 0)
1323
+ this._scaleBoundsMin.z = 0.00000001;
1324
+ }
1325
+ }
1326
+ removeScaleBounds() {
1327
+ this._scaleBoundsMin = null;
1328
+ this._scaleBoundsMax = null;
1329
+ }
1330
+ setTransBounds(min, max) {
1331
+ this._transBoundsMin = min ? min : null;
1332
+ this._transBoundsMax = max ? max : null;
1333
+ }
1334
+ removeTransBounds() {
1335
+ this._transBoundsMin = null;
1336
+ this._transBoundsMax = null;
1337
+ }
1338
+ setRotBounds(min, max) {
1339
+ this._rotBoundsMin = min ? min : null;
1340
+ this._rotBoundsMax = max ? max : null;
1341
+ }
1342
+ removeRotBounds() {
1343
+ this._rotBoundsMin = null;
1344
+ this._rotBoundsMax = null;
1345
+ }
1346
+ /*
1347
+ * create big and small axeses which will be shown in translate, rotate and scale mode.
1348
+ *
1349
+ */
1350
+ _createCommonAxes() {
1351
+ let guideAxes = new babylonjs_1.Mesh("", this._scene);
1352
+ //the big axes, shown when an axis is selected
1353
+ this._bXaxis = babylonjs_1.MeshBuilder.CreateLines("", { points: [new babylonjs_1.Vector3(-100, 0, 0), new babylonjs_1.Vector3(100, 0, 0)] }, this._scene);
1354
+ this._bYaxis = babylonjs_1.MeshBuilder.CreateLines("", { points: [new babylonjs_1.Vector3(0, -100, 0), new babylonjs_1.Vector3(0, 100, 0)] }, this._scene);
1355
+ this._bZaxis = babylonjs_1.MeshBuilder.CreateLines("", { points: [new babylonjs_1.Vector3(0, 0, -100), new babylonjs_1.Vector3(0, 0, 100)] }, this._scene);
1356
+ //lines are now pickable too
1357
+ this._bXaxis.isPickable = false;
1358
+ this._bYaxis.isPickable = false;
1359
+ this._bZaxis.isPickable = false;
1360
+ this._bXaxis.parent = guideAxes;
1361
+ this._bYaxis.parent = guideAxes;
1362
+ this._bZaxis.parent = guideAxes;
1363
+ this._bXaxis.color = this._redCol;
1364
+ this._bYaxis.color = this._greenCol;
1365
+ this._bZaxis.color = this._blueCol;
1366
+ this._hideBaxis();
1367
+ //the small axis
1368
+ let al = this._axesLen * this._axesScale * 0.75;
1369
+ this._xaxis = babylonjs_1.MeshBuilder.CreateLines("", { points: [new babylonjs_1.Vector3(0, 0, 0), new babylonjs_1.Vector3(al, 0, 0)] }, this._scene);
1370
+ this._yaxis = babylonjs_1.MeshBuilder.CreateLines("", { points: [new babylonjs_1.Vector3(0, 0, 0), new babylonjs_1.Vector3(0, al, 0)] }, this._scene);
1371
+ this._zaxis = babylonjs_1.MeshBuilder.CreateLines("", { points: [new babylonjs_1.Vector3(0, 0, 0), new babylonjs_1.Vector3(0, 0, al)] }, this._scene);
1372
+ //lines are now pickable too
1373
+ this._xaxis.isPickable = false;
1374
+ this._yaxis.isPickable = false;
1375
+ this._zaxis.isPickable = false;
1376
+ this._xaxis.parent = guideAxes;
1377
+ this._yaxis.parent = guideAxes;
1378
+ this._zaxis.parent = guideAxes;
1379
+ this._xaxis.color = this._redCol;
1380
+ this._yaxis.color = this._greenCol;
1381
+ this._zaxis.color = this._blueCol;
1382
+ this._xaxis.renderingGroupId = 1;
1383
+ this._yaxis.renderingGroupId = 1;
1384
+ this._zaxis.renderingGroupId = 1;
1385
+ return guideAxes;
1386
+ }
1387
+ _createPickPlanes() {
1388
+ this._pALL = babylonjs_1.MeshBuilder.CreatePlane("", { size: 5 }, this._scene);
1389
+ this._pXZ = babylonjs_1.MeshBuilder.CreatePlane("", { size: 5 }, this._scene);
1390
+ this._pZY = babylonjs_1.MeshBuilder.CreatePlane("", { size: 5 }, this._scene);
1391
+ this._pYX = babylonjs_1.MeshBuilder.CreatePlane("", { size: 5 }, this._scene);
1392
+ this._pALL.isPickable = false;
1393
+ this._pXZ.isPickable = false;
1394
+ this._pZY.isPickable = false;
1395
+ this._pYX.isPickable = false;
1396
+ this._pALL.visibility = 0;
1397
+ this._pXZ.visibility = 0;
1398
+ this._pZY.visibility = 0;
1399
+ this._pYX.visibility = 0;
1400
+ this._pALL.renderingGroupId = 1;
1401
+ this._pXZ.renderingGroupId = 1;
1402
+ this._pZY.renderingGroupId = 1;
1403
+ this._pYX.renderingGroupId = 1;
1404
+ this._pALL.lookAt(this._mainCamera.position);
1405
+ this._pXZ.rotate(babylonjs_1.Axis.X, 1.57);
1406
+ this._pZY.rotate(babylonjs_1.Axis.Y, 1.57);
1407
+ let pickPlanes = new babylonjs_1.Mesh("", this._scene);
1408
+ this._pALL.parent = pickPlanes;
1409
+ this._pXZ.parent = pickPlanes;
1410
+ this._pZY.parent = pickPlanes;
1411
+ this._pYX.parent = pickPlanes;
1412
+ return pickPlanes;
1413
+ }
1414
+ _createTransAxes() {
1415
+ let r = this._pickWidth * 2 * this._axesScale;
1416
+ let l = this._axesLen * this._axesScale;
1417
+ this._tCtl = new babylonjs_1.Mesh("", this._scene);
1418
+ // pickable invisible boxes around axes lines
1419
+ this._createPickableTrans(r, l, this._tCtl, this._scene);
1420
+ //non pickable but visible cones at end of axes lines
1421
+ this._createNonPickableTrans(r, l, this._scene);
1422
+ }
1423
+ /**
1424
+ * pickable but invisible
1425
+ * a) 3 boxes around each of the 3 small axes lines
1426
+ * b) 3 small planes near origin for movement along a plane
1427
+ * @param r
1428
+ * @param l
1429
+ * @param tCtl
1430
+ * @param scene
1431
+ */
1432
+ _createPickableTrans(r, l, tCtl, scene) {
1433
+ let tX = this._extrudeBox(r / 2, l);
1434
+ tX.name = "X";
1435
+ let tY = tX.clone("Y");
1436
+ let tZ = tX.clone("Z");
1437
+ let s = r * 2;
1438
+ let tXZ = babylonjs_1.MeshBuilder.CreatePlane("XZ", { size: s }, scene);
1439
+ let tZY = babylonjs_1.MeshBuilder.CreatePlane("ZY", { size: s }, scene);
1440
+ let tYX = babylonjs_1.MeshBuilder.CreatePlane("YX", { size: s }, scene);
1441
+ tXZ.rotation.x = 1.57;
1442
+ tZY.rotation.y = -1.57;
1443
+ tXZ.position.x = 2 * r;
1444
+ tXZ.position.z = 2 * r;
1445
+ tZY.position.z = 2 * r;
1446
+ tZY.position.y = 2 * r;
1447
+ tYX.position.y = 2 * r;
1448
+ tYX.position.x = 2 * r;
1449
+ tXZ.bakeCurrentTransformIntoVertices();
1450
+ tZY.bakeCurrentTransformIntoVertices();
1451
+ tYX.bakeCurrentTransformIntoVertices();
1452
+ let tAll = babylonjs_1.MeshBuilder.CreateBox("ALL", { size: r * 2 }, scene);
1453
+ tX.parent = tCtl;
1454
+ tY.parent = tCtl;
1455
+ tZ.parent = tCtl;
1456
+ tXZ.parent = tCtl;
1457
+ tZY.parent = tCtl;
1458
+ tYX.parent = tCtl;
1459
+ tAll.parent = tCtl;
1460
+ tX.rotation.y = 1.57;
1461
+ tY.rotation.x -= 1.57;
1462
+ this._tX = tX;
1463
+ this._tY = tY;
1464
+ this._tZ = tZ;
1465
+ this._tXZ = tXZ;
1466
+ this._tZY = tZY;
1467
+ this._tYX = tYX;
1468
+ this._tAll = tAll;
1469
+ this._all_t = [tX, tY, tZ, tXZ, tZY, tYX, tAll];
1470
+ this._setVisibility(this._all_t, 0);
1471
+ //do not want clients picking this
1472
+ //we will pick using mesh filter in scene.pick function
1473
+ this._setPickableFalse(this._all_t);
1474
+ }
1475
+ //non pickable but visible
1476
+ // a) 3 cones at end of the 3 small axes lines
1477
+ // b) 3 small planes near origin for movement along a plane
1478
+ _createNonPickableTrans(r, l, scene) {
1479
+ //cone length
1480
+ let cl = l / 5;
1481
+ //cone base radius
1482
+ //let cr: number = r;
1483
+ let tEndX = babylonjs_1.MeshBuilder.CreateCylinder("", { height: cl, diameterTop: 0, diameterBottom: r, tessellation: 6, subdivisions: 1 }, scene);
1484
+ let tEndY = tEndX.clone("");
1485
+ let tEndZ = tEndX.clone("");
1486
+ let s = r * 2;
1487
+ let tEndXZ = babylonjs_1.MeshBuilder.CreatePlane("XZ", { size: s }, scene);
1488
+ let tEndZY = babylonjs_1.MeshBuilder.CreatePlane("ZY", { size: s }, scene);
1489
+ let tEndYX = babylonjs_1.MeshBuilder.CreatePlane("YX", { size: s }, scene);
1490
+ let tEndAll = babylonjs_1.MeshBuilder.CreateBox("ALL", { size: r }, scene);
1491
+ tEndX.rotation.x = 1.57;
1492
+ tEndY.rotation.x = 1.57;
1493
+ tEndZ.rotation.x = 1.57;
1494
+ tEndXZ.rotation.x = 1.57;
1495
+ tEndZY.rotation.y = 1.57;
1496
+ //tEndYX.rotation.x = 0;
1497
+ tEndXZ.position.x = s;
1498
+ tEndXZ.position.z = s;
1499
+ tEndZY.position.z = s;
1500
+ tEndZY.position.y = s;
1501
+ tEndYX.position.y = s;
1502
+ tEndYX.position.x = s;
1503
+ tEndX.parent = this._tX;
1504
+ tEndY.parent = this._tY;
1505
+ tEndZ.parent = this._tZ;
1506
+ tEndXZ.parent = this._tXZ;
1507
+ tEndZY.parent = this._tZY;
1508
+ tEndYX.parent = this._tYX;
1509
+ tEndAll.parent = this._tAll;
1510
+ tEndX.position.z = l - cl / 2;
1511
+ tEndY.position.z = l - cl / 2;
1512
+ tEndZ.position.z = l - cl / 2;
1513
+ tEndX.material = this._redMat;
1514
+ tEndY.material = this._greenMat;
1515
+ tEndZ.material = this._blueMat;
1516
+ tEndXZ.material = this._greenMat;
1517
+ tEndZY.material = this._redMat;
1518
+ tEndYX.material = this._blueMat;
1519
+ tEndAll.material = this._yellowMat;
1520
+ this._tEndX = tEndX;
1521
+ this._tEndY = tEndY;
1522
+ this._tEndZ = tEndZ;
1523
+ this._tEndXZ = tEndXZ;
1524
+ this._tEndZY = tEndZY;
1525
+ this._tEndYX = tEndYX;
1526
+ this._tEndAll = tEndAll;
1527
+ this._all_tEnd = [tEndX, tEndY, tEndZ, tEndXZ, tEndZY, tEndYX, tEndAll];
1528
+ this._setPickableFalse(this._all_tEnd);
1529
+ this._setRenderingGroup(this._all_tEnd);
1530
+ }
1531
+ setRotGuideFull(y) {
1532
+ if (y)
1533
+ this._guideSize = 360;
1534
+ else
1535
+ this._guideSize = 180;
1536
+ if (this._rCtl != null) {
1537
+ this._rCtl.dispose();
1538
+ this._rAll.dispose();
1539
+ this._rCtl = null;
1540
+ this.enableRotation();
1541
+ }
1542
+ }
1543
+ _createRotAxes() {
1544
+ let d = this._axesLen * this._axesScale * 2;
1545
+ this._rCtl = new babylonjs_1.Mesh("", this._scene);
1546
+ //pickable invisible torus around the rotation circles
1547
+ this._createPickableRot(d, this._rCtl);
1548
+ /*non pickable but visible circles */
1549
+ this._createNonPickableRot(d);
1550
+ }
1551
+ _createPickableRot(d, rCtl) {
1552
+ let rX = this._createTube(d / 2, this._guideSize);
1553
+ let rY = this._createTube(d / 2, this._guideSize);
1554
+ let rZ = this._createTube(d / 2, this._guideSize);
1555
+ let rAll = this._createTube(d / 1.75, 360);
1556
+ rX.name = "X";
1557
+ rY.name = "Y";
1558
+ rZ.name = "Z";
1559
+ rAll.name = "ALL";
1560
+ rX.rotation.z = 1.57;
1561
+ rZ.rotation.x = -1.57;
1562
+ rX.bakeCurrentTransformIntoVertices();
1563
+ rZ.bakeCurrentTransformIntoVertices();
1564
+ rAll.rotation.x = 1.57;
1565
+ rX.parent = rCtl;
1566
+ rY.parent = rCtl;
1567
+ rZ.parent = rCtl;
1568
+ rAll.parent = this._pALL;
1569
+ this._rX = rX;
1570
+ this._rY = rY;
1571
+ this._rZ = rZ;
1572
+ this._rAll = rAll;
1573
+ this._all_r = [rX, rY, rZ, rAll];
1574
+ this._setVisibility(this._all_r, 0);
1575
+ //do not want clients picking this
1576
+ //we will pick using mesh filter in scene.pick function
1577
+ this._setPickableFalse(this._all_r);
1578
+ }
1579
+ _createNonPickableRot(d) {
1580
+ let rEndX = this._createCircle(d / 2, this._guideSize, false);
1581
+ let rEndY = rEndX.clone("");
1582
+ let rEndZ = rEndX.clone("");
1583
+ let rEndAll = this._createCircle(d / 1.75, 360, false);
1584
+ let rEndAll2 = this._createCircle(d / 2, 360, false);
1585
+ rEndX.parent = this._rX;
1586
+ rEndY.parent = this._rY;
1587
+ rEndZ.parent = this._rZ;
1588
+ rEndX.rotation.z = 1.57;
1589
+ rEndZ.rotation.x = -1.57;
1590
+ rEndAll.parent = this._rAll;
1591
+ rEndAll2.parent = this._rAll;
1592
+ rEndX.color = this._redCol;
1593
+ rEndY.color = this._greenCol;
1594
+ rEndZ.color = this._blueCol;
1595
+ rEndAll.color = this._whiteCol;
1596
+ rEndAll2.color = babylonjs_1.Color3.Gray();
1597
+ this._rEndX = rEndX;
1598
+ this._rEndY = rEndY;
1599
+ this._rEndZ = rEndZ;
1600
+ this._rEndAll = rEndAll;
1601
+ this._rEndAll2 = rEndAll2;
1602
+ this._all_rEnd = [rEndX, rEndY, rEndZ, rEndAll, rEndAll2];
1603
+ this._setPickableFalse(this._all_rEnd);
1604
+ this._setRenderingGroup(this._all_rEnd);
1605
+ }
1606
+ _setVisibility(meshes, v) {
1607
+ meshes.map((m) => m.visibility = v);
1608
+ }
1609
+ _setPickableFalse(meshes) {
1610
+ meshes.map((m) => { m.isPickable = false; });
1611
+ }
1612
+ _setRenderingGroup(meshes) {
1613
+ meshes.map((m) => m.renderingGroupId = 2);
1614
+ }
1615
+ _extrudeBox(w, l) {
1616
+ let shape = [new babylonjs_1.Vector3(w, w, 0), new babylonjs_1.Vector3(-w, w, 0), new babylonjs_1.Vector3(-w, -w, 0), new babylonjs_1.Vector3(w, -w, 0), new babylonjs_1.Vector3(w, w, 0)];
1617
+ let path = [new babylonjs_1.Vector3(0, 0, 0), new babylonjs_1.Vector3(0, 0, l)];
1618
+ let box = babylonjs_1.MeshBuilder.ExtrudeShape("", { shape: shape, path: path, scale: 1, rotation: 0, cap: 2 }, this._scene);
1619
+ return box;
1620
+ }
1621
+ _createCircle(r, t, double) {
1622
+ if (t === null)
1623
+ t = 360;
1624
+ let points = [];
1625
+ let x;
1626
+ let z;
1627
+ let a = 3.14 / 180;
1628
+ let p = 0;
1629
+ for (let i = 0; i <= t; i = i + 5) {
1630
+ x = r * Math.cos(i * a);
1631
+ if (i == 90)
1632
+ z = r;
1633
+ else if (i == 270)
1634
+ z = -r;
1635
+ else
1636
+ z = r * Math.sin(i * a);
1637
+ points[p] = new babylonjs_1.Vector3(x, 0, z);
1638
+ p++;
1639
+ }
1640
+ if (double) {
1641
+ r = r - 0.04;
1642
+ for (let i = 0; i <= t; i = i + 5) {
1643
+ x = r * Math.cos(i * a);
1644
+ if (i == 90)
1645
+ z = r;
1646
+ else if (i == 270)
1647
+ z = -r;
1648
+ else
1649
+ z = r * Math.sin(i * a);
1650
+ points[p] = new babylonjs_1.Vector3(x, 0, z);
1651
+ p++;
1652
+ }
1653
+ }
1654
+ let circle = babylonjs_1.MeshBuilder.CreateLines("", { points: points }, this._scene);
1655
+ return circle;
1656
+ }
1657
+ _createTube(r, t) {
1658
+ if (t === null)
1659
+ t = 360;
1660
+ let points = [];
1661
+ let x;
1662
+ let z;
1663
+ let a = 3.14 / 180;
1664
+ let p = 0;
1665
+ for (let i = 0; i <= t; i = i + 30) {
1666
+ x = r * Math.cos(i * a);
1667
+ if (i == 90)
1668
+ z = r;
1669
+ else if (i == 270)
1670
+ z = -r;
1671
+ else
1672
+ z = r * Math.sin(i * a);
1673
+ points[p] = new babylonjs_1.Vector3(x, 0, z);
1674
+ p++;
1675
+ }
1676
+ let tube = babylonjs_1.MeshBuilder.CreateTube("", { path: points, radius: this._pickWidth * this._axesScale * 2, tessellation: 3, cap: babylonjs_1.Mesh.NO_CAP }, this._scene);
1677
+ return tube;
1678
+ }
1679
+ _createScaleAxes() {
1680
+ let r = this._pickWidth * 2 * this._axesScale;
1681
+ let l = this._axesLen * this._axesScale;
1682
+ this._sCtl = new babylonjs_1.Mesh("", this._scene);
1683
+ /* pickable , invisible part */
1684
+ this._createPickableScale(r, l, this._sCtl);
1685
+ /* non pickable visible boxes at end of axes */
1686
+ this._createNonPickableScale(r, l);
1687
+ }
1688
+ _createPickableScale(r, l, sCtl) {
1689
+ let sX = this._extrudeBox(r / 2, l);
1690
+ sX.name = "X";
1691
+ let sY = sX.clone("Y");
1692
+ let sZ = sX.clone("Z");
1693
+ let sXZ = babylonjs_1.MeshBuilder.CreatePlane("XZ", { size: r * 2 }, this._scene);
1694
+ let sZY = babylonjs_1.MeshBuilder.CreatePlane("ZY", { size: r * 2 }, this._scene);
1695
+ let sYX = babylonjs_1.MeshBuilder.CreatePlane("YX", { size: r * 2 }, this._scene);
1696
+ sXZ.rotation.x = 1.57;
1697
+ sZY.rotation.y = -1.57;
1698
+ sXZ.position.x = 2 * r;
1699
+ sXZ.position.z = 2 * r;
1700
+ sZY.position.z = 2 * r;
1701
+ sZY.position.y = 2 * r;
1702
+ sYX.position.y = 2 * r;
1703
+ sYX.position.x = 2 * r;
1704
+ sXZ.bakeCurrentTransformIntoVertices();
1705
+ sZY.bakeCurrentTransformIntoVertices();
1706
+ sYX.bakeCurrentTransformIntoVertices();
1707
+ let sAll = babylonjs_1.MeshBuilder.CreateBox("ALL", { size: 2 * r }, this._scene);
1708
+ sX.parent = sCtl;
1709
+ sY.parent = sCtl;
1710
+ sZ.parent = sCtl;
1711
+ sAll.parent = sCtl;
1712
+ sXZ.parent = sCtl;
1713
+ sZY.parent = sCtl;
1714
+ sYX.parent = sCtl;
1715
+ sX.rotation.y = 1.57;
1716
+ sY.rotation.x -= 1.57;
1717
+ this._sX = sX;
1718
+ this._sY = sY;
1719
+ this._sZ = sZ;
1720
+ this._sXZ = sXZ;
1721
+ this._sZY = sZY;
1722
+ this._sYX = sYX;
1723
+ this._sAll = sAll;
1724
+ this._all_s = [sX, sY, sZ, sXZ, sZY, sYX, sAll];
1725
+ this._setVisibility(this._all_s, 0);
1726
+ //do not want clients picking this
1727
+ //we will pick using mesh filter in scene.pick function
1728
+ this._setPickableFalse(this._all_s);
1729
+ }
1730
+ _createNonPickableScale(r, l) {
1731
+ let sEndX = babylonjs_1.MeshBuilder.CreateBox("", { size: r }, this._scene);
1732
+ let sEndY = sEndX.clone("");
1733
+ let sEndZ = sEndX.clone("");
1734
+ let s = r * 2;
1735
+ let sEndXZ = babylonjs_1.MeshBuilder.CreatePlane("XZ", { size: s }, this._scene);
1736
+ let sEndZY = babylonjs_1.MeshBuilder.CreatePlane("ZY", { size: s }, this._scene);
1737
+ let sEndYX = babylonjs_1.MeshBuilder.CreatePlane("YX", { size: s }, this._scene);
1738
+ let sEndAll = babylonjs_1.MeshBuilder.CreateBox("ALL", { size: r }, this._scene);
1739
+ sEndXZ.rotation.x = 1.57;
1740
+ sEndZY.rotation.y = -1.57;
1741
+ sEndXZ.position.x = s;
1742
+ sEndXZ.position.z = s;
1743
+ sEndZY.position.z = s;
1744
+ sEndZY.position.y = s;
1745
+ sEndYX.position.y = s;
1746
+ sEndYX.position.x = s;
1747
+ sEndX.parent = this._sX;
1748
+ sEndY.parent = this._sY;
1749
+ sEndZ.parent = this._sZ;
1750
+ sEndXZ.parent = this._sXZ;
1751
+ sEndZY.parent = this._sZY;
1752
+ sEndYX.parent = this._sYX;
1753
+ sEndAll.parent = this._sAll;
1754
+ sEndX.position.z = l - r / 2;
1755
+ sEndY.position.z = l - r / 2;
1756
+ sEndZ.position.z = l - r / 2;
1757
+ sEndX.material = this._redMat;
1758
+ sEndY.material = this._greenMat;
1759
+ sEndZ.material = this._blueMat;
1760
+ sEndXZ.material = this._greenMat;
1761
+ sEndZY.material = this._redMat;
1762
+ sEndYX.material = this._blueMat;
1763
+ sEndAll.material = this._yellowMat;
1764
+ this._sEndX = sEndX;
1765
+ this._sEndY = sEndY;
1766
+ this._sEndZ = sEndZ;
1767
+ this._sEndXZ = sEndXZ;
1768
+ this._sEndZY = sEndZY;
1769
+ this._sEndYX = sEndYX;
1770
+ this._sEndAll = sEndAll;
1771
+ this._all_sEnd = [sEndX, sEndY, sEndZ, sEndXZ, sEndZY, sEndYX, sEndAll];
1772
+ this._setPickableFalse(this._all_sEnd);
1773
+ this._setRenderingGroup(this._all_sEnd);
1774
+ }
1775
+ /**
1776
+ * checks if a have left hand , right hand issue.
1777
+ * In other words if a mesh is a LHS mesh in RHS system or
1778
+ * a RHS mesh in LHS system
1779
+ * The X axis will be reversed in such cases.
1780
+ * thus Cross product of X and Y should be inverse of Z.
1781
+ *
1782
+ */
1783
+ // private _check_LHS_RHS(mesh: Mesh) {
1784
+ // let actualZ = Vector3.Cross(this._localX, this._localY);
1785
+ // //same direction or opposite direction of Z
1786
+ // if (Vector3.Dot(actualZ, this._localZ) < 0) return true;
1787
+ // else return false;
1788
+ // }
1789
+ /**
1790
+ * set how transparent the axes are
1791
+ * 0 to 1
1792
+ * 0 - completely transparent
1793
+ * 1 - completely non transparent
1794
+ * default is 0.75
1795
+ */
1796
+ setVisibility(v) {
1797
+ this._visibility = v;
1798
+ }
1799
+ setLocal(l) {
1800
+ if (this._local == l)
1801
+ return;
1802
+ this._local = l;
1803
+ if (!l) {
1804
+ this._ecRoot.rotationQuaternion = babylonjs_1.Quaternion.Identity();
1805
+ }
1806
+ }
1807
+ isLocal() {
1808
+ return this._local;
1809
+ }
1810
+ setTransSnap(s) {
1811
+ this._snapT = s;
1812
+ }
1813
+ isTransSnap() {
1814
+ return this._snapT;
1815
+ }
1816
+ setRotSnap(s) {
1817
+ this._snapR = s;
1818
+ }
1819
+ isRotSnap() {
1820
+ return this._snapR;
1821
+ }
1822
+ setScaleSnap(s) {
1823
+ this._snapS = s;
1824
+ }
1825
+ isScaleSnap() {
1826
+ return this._snapS;
1827
+ }
1828
+ setTransSnapValue(t) {
1829
+ this._tSnap.copyFromFloats(t, t, t);
1830
+ this._transSnap = t;
1831
+ }
1832
+ getTransSnapValue() {
1833
+ return this._transSnap;
1834
+ }
1835
+ setRotSnapValue(r) {
1836
+ this._rotSnap = r;
1837
+ }
1838
+ getRotSnapValue() {
1839
+ return this._rotSnap;
1840
+ }
1841
+ setScaleSnapValue(r) {
1842
+ this._scaleSnap = r;
1843
+ }
1844
+ getScaleSnapValue() {
1845
+ return this._scaleSnap;
1846
+ }
1847
+ _getAngle2(p1, p2, cameraPos, c2ec, mN) {
1848
+ /**
1849
+ * A) find out if the camera is above , below, left, right of the rotation plane
1850
+ */
1851
+ //project "camera to ec" vector onto mesh normal to get distance to rotation plane
1852
+ let d = babylonjs_1.Vector3.Dot(c2ec, mN);
1853
+ //scale mesh normal by above ammount to get vector to rotation plane
1854
+ mN.scaleToRef(d, this._tv1);
1855
+ //get the point of intersection of vector from camera perpendicular to rotation plane
1856
+ cameraPos.addToRef(this._tv1, this._tv2);
1857
+ let i = this._tv2; //save some typing
1858
+ //find the co-ordinate of this point in the cameras frame of reference
1859
+ this._mainCamera.getWorldMatrix().invertToRef(this._tm);
1860
+ babylonjs_1.Vector3.TransformCoordinatesToRef(this._tv2, this._tm, this._tv2);
1861
+ //find in which quadarant the point (and thus the rotation plane) is in the camera xy plane
1862
+ let q = 0; //(1=x y,2=-x y,3=-x -y,4=x -y)
1863
+ if (i.x >= 0 && i.y >= 0)
1864
+ q = 1;
1865
+ else if (i.x <= 0 && i.y >= 0)
1866
+ q = 2;
1867
+ else if (i.x <= 0 && i.y <= 0)
1868
+ q = 3;
1869
+ else if (i.x >= 0 && i.y <= 0)
1870
+ q = 4;
1871
+ /**
1872
+ * B) find out if the user moved pointer up,down, right, left
1873
+ */
1874
+ //find movement vector in camera frame of reference
1875
+ babylonjs_1.Vector3.TransformCoordinatesToRef(p1, this._tm, this._tv1);
1876
+ babylonjs_1.Vector3.TransformCoordinatesToRef(p2, this._tm, this._tv2);
1877
+ this._tv2.subtractInPlace(this._tv1);
1878
+ let mv = this._tv2; //save some typing
1879
+ //for now lets set the angle magnitutde same as amount by which the mouse moved
1880
+ let angle = mv.length();
1881
+ let m = ""; //(u ,d ,r,l)
1882
+ if (mv.x >= 0 && mv.y >= 0) {
1883
+ if (mv.x >= mv.y)
1884
+ m = "r";
1885
+ else
1886
+ m = "u";
1887
+ }
1888
+ else if (mv.x <= 0 && mv.y >= 0) {
1889
+ if (-mv.x >= mv.y)
1890
+ m = "l";
1891
+ else
1892
+ m = "u";
1893
+ }
1894
+ else if (mv.x <= 0 && mv.y <= 0) {
1895
+ if (-mv.x >= -mv.y)
1896
+ m = "l";
1897
+ else
1898
+ m = "d";
1899
+ }
1900
+ else if (mv.x >= 0 && mv.y <= 0) {
1901
+ if (mv.x >= -mv.y)
1902
+ m = "r";
1903
+ else
1904
+ m = "d";
1905
+ }
1906
+ /**
1907
+ * C) decide if the user was trying to rotate clockwise (+1) or anti-clockwise(-1)
1908
+ */
1909
+ let r = 0;
1910
+ //if mouse moved down /up and rotation plane is on right or left side of user
1911
+ if (m == "d") {
1912
+ if (q == 1 || q == 4)
1913
+ r = 1;
1914
+ else
1915
+ r = -1;
1916
+ }
1917
+ else if (m == "u") {
1918
+ if (q == 1 || q == 4)
1919
+ r = -1;
1920
+ else
1921
+ r = 1;
1922
+ //if mouse moved right/left and rotation plane is above or below user
1923
+ }
1924
+ else if (m == "r") {
1925
+ if (q == 2 || q == 1)
1926
+ r = 1;
1927
+ else
1928
+ r = -1;
1929
+ }
1930
+ else if (m == "l") {
1931
+ if (q == 2 || q == 1)
1932
+ r = -1;
1933
+ else
1934
+ r = 1;
1935
+ }
1936
+ return r * angle;
1937
+ }
1938
+ /**
1939
+ * finds the angle subtended from points p1 to p2 around the point p
1940
+ * checks if the user was trying to rotate clockwise (+ve in LHS) or anticlockwise (-ve in LHS)
1941
+ * to figure this check the orientation of the user(camera)to ec vector with the rotation normal vector
1942
+ */
1943
+ _getAngle(p1, p2, p, c2ec) {
1944
+ p1.subtractToRef(p, this._tv1);
1945
+ p2.subtractToRef(p, this._tv2);
1946
+ babylonjs_1.Vector3.CrossToRef(this._tv1, this._tv2, this._tv3);
1947
+ let angle = Math.asin(this._tv3.length() / (this._tv1.length() * this._tv2.length()));
1948
+ //camera looking down from front of plane or looking up from behind plane
1949
+ if ((babylonjs_1.Vector3.Dot(this._tv3, c2ec) > 0)) {
1950
+ angle = -1 * angle;
1951
+ }
1952
+ return angle;
1953
+ }
1954
+ static _getStandardMaterial(col, scene) {
1955
+ let mat = new babylonjs_1.StandardMaterial("", scene);
1956
+ mat.emissiveColor = col;
1957
+ mat.diffuseColor = babylonjs_1.Color3.Black();
1958
+ mat.specularColor = babylonjs_1.Color3.Black();
1959
+ mat.backFaceCulling = false;
1960
+ return mat;
1961
+ }
1962
+ _createMaterials(scene) {
1963
+ this._redMat = EditControl._getStandardMaterial(this._redCol, scene);
1964
+ this._greenMat = EditControl._getStandardMaterial(this._greenCol, scene);
1965
+ this._blueMat = EditControl._getStandardMaterial(this._blueCol, scene);
1966
+ this._whiteMat = EditControl._getStandardMaterial(this._yellowCol, scene);
1967
+ this._yellowMat = EditControl._getStandardMaterial(this._whiteCol, scene);
1968
+ }
1969
+ _disposeMaterials() {
1970
+ this._redMat.dispose();
1971
+ this._greenMat.dispose();
1972
+ this._blueMat.dispose();
1973
+ this._whiteMat.dispose();
1974
+ this._yellowMat.dispose();
1975
+ }
1976
+ }
1977
+ exports.EditControl = EditControl;
1978
+ class ActHist {
1979
+ constructor(mesh, capacity) {
1980
+ this.lastMax = 10;
1981
+ this.acts = new Array();
1982
+ this.last = -1;
1983
+ this.current = -1;
1984
+ this.mesh = mesh;
1985
+ this.lastMax = capacity - 1;
1986
+ this.add();
1987
+ }
1988
+ setCapacity(c) {
1989
+ if ((c == 0)) {
1990
+ console.error("capacity should be more than zero");
1991
+ return;
1992
+ }
1993
+ this.lastMax = c - 1;
1994
+ this.last = -1;
1995
+ this.current = -1;
1996
+ this.acts = new Array();
1997
+ this.add();
1998
+ }
1999
+ add(at) {
2000
+ if (at === undefined)
2001
+ at = null;
2002
+ let act = new Act(this.mesh, at);
2003
+ if ((this.current < this.last)) {
2004
+ this.acts.splice(this.current + 1);
2005
+ this.last = this.current;
2006
+ }
2007
+ if ((this.last == this.lastMax)) {
2008
+ this.acts.shift();
2009
+ this.acts.push(act);
2010
+ }
2011
+ else {
2012
+ this.acts.push(act);
2013
+ this.last++;
2014
+ this.current++;
2015
+ }
2016
+ }
2017
+ undo() {
2018
+ if ((this.current > 0)) {
2019
+ let at = this.acts[this.current].getActionType();
2020
+ this.current--;
2021
+ this.acts[this.current].perform(this.mesh);
2022
+ return at;
2023
+ }
2024
+ }
2025
+ redo() {
2026
+ if ((this.current < this.last)) {
2027
+ this.current++;
2028
+ this.acts[this.current].perform(this.mesh);
2029
+ return this.acts[this.current].getActionType();
2030
+ }
2031
+ }
2032
+ }
2033
+ class Act {
2034
+ constructor(mesh, at) {
2035
+ this._p = mesh.position.clone();
2036
+ if (mesh.rotationQuaternion == null) {
2037
+ this._rQ = null;
2038
+ this._rE = mesh.rotation.clone();
2039
+ }
2040
+ else {
2041
+ this._rQ = mesh.rotationQuaternion.clone();
2042
+ this._rE = null;
2043
+ }
2044
+ this._s = mesh.scaling.clone();
2045
+ this._at = at;
2046
+ }
2047
+ getActionType() {
2048
+ return this._at;
2049
+ }
2050
+ perform(mesh) {
2051
+ mesh.position.copyFrom(this._p);
2052
+ //check if we are doing euler or quaternion now
2053
+ //also check what were we doing when the rotation value
2054
+ //was captured and set value accordingly
2055
+ if (mesh.rotationQuaternion == null) {
2056
+ if (this._rE != null) {
2057
+ //mesh.rotation = this.rE.clone();
2058
+ mesh.rotation.copyFrom(this._rE);
2059
+ }
2060
+ else {
2061
+ //mesh.rotation = this.r.toEulerAngles();
2062
+ mesh.rotation.copyFrom(this._rQ.toEulerAngles());
2063
+ }
2064
+ }
2065
+ else {
2066
+ if (this._rQ != null) {
2067
+ mesh.rotationQuaternion.copyFrom(this._rQ);
2068
+ }
2069
+ else {
2070
+ //TODO use BABYLON.Quaternion.RotationYawPitchRoll(rot.y, rot.x, rot.z) instead of toQuaternion.
2071
+ //mesh.rotationQuaternion.copyFrom(this.rE.toQuaternion());
2072
+ mesh.rotationQuaternion.copyFrom(babylonjs_1.Quaternion.RotationYawPitchRoll(this._rE.y, this._rE.x, this._rE.z));
2073
+ }
2074
+ }
2075
+ mesh.scaling.copyFrom(this._s);
2076
+ }
2077
+ }
2078
+
2079
+ })();
2080
+
2081
+ /******/ return __webpack_exports__;
2082
+ /******/ })()
2083
+ ;
2084
+ });
3
2085
  //# sourceMappingURL=EditControl.max.js.map