!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t=t||self).OIMO={})}(this,function(t){"use strict";void 0===Number.EPSILON&&(Number.EPSILON=Math.pow(2,-52)),void 0===Math.sign&&(Math.sign=function(t){return t<0?-1:0>=4,h[19===t?3&s|8:s]);return e.join("")}),int:function(t){return Bs.floor(t)},fix:function(t,i){return t.toFixed(i||3,10)},clamp:function(t,i,s){return Bs.max(i,Bs.min(s,t))},distance:function(t,i){var s=i[0]-t[0],h=i[1]-t[1],e=i[2]-t[2];return Bs.sqrt(s*s+h*h+e*e)},acosClamp:function(t){return 1this.MaxBroadPhaseTime&&(this.MaxBroadPhaseTime=this.broadPhaseTime),this.narrowPhaseTime>this.MaxNarrowPhaseTime&&(this.MaxNarrowPhaseTime=this.narrowPhaseTime),this.solvingTime>this.MaxSolvingTime&&(this.MaxSolvingTime=this.solvingTime),this.totalTime>this.MaxTotalTime&&(this.MaxTotalTime=this.totalTime),this.updateTime>this.MaxUpdateTime&&(this.MaxUpdateTime=this.updateTime)),this.upfps(),this.tt++,500this.f[0]&&(this.f[0]=this.f[1],this.fps=this.f[2],this.f[2]=0),this.f[2]++},show:function(){return["Oimo.js "+this.version+"
",this.broadPhase+"

","FPS: "+this.fps+" fps

","rigidbody "+this.parent.numRigidBodies+"
","contact   "+this.parent.numContacts+"
","ct-point  "+this.parent.numContactPoints+"
","paircheck "+this.parent.broadPhase.numPairChecks+"
","island    "+this.parent.numIslands+"

","Time in milliseconds

","broadphase  "+Bs.fix(this.broadPhaseTime)+" | "+Bs.fix(this.MaxBroadPhaseTime)+"
","narrowphase "+Bs.fix(this.narrowPhaseTime)+" | "+Bs.fix(this.MaxNarrowPhaseTime)+"
","solving     "+Bs.fix(this.solvingTime)+" | "+Bs.fix(this.MaxSolvingTime)+"
","total       "+Bs.fix(this.totalTime)+" | "+Bs.fix(this.MaxTotalTime)+"
","updating    "+Bs.fix(this.updateTime)+" | "+Bs.fix(this.MaxUpdateTime)+"
"].join("\n")},toArray:function(){return this.infos[0]=this.parent.broadPhase.types,this.infos[1]=this.parent.numRigidBodies,this.infos[2]=this.parent.numContacts,this.infos[3]=this.parent.broadPhase.numPairChecks,this.infos[4]=this.parent.numContactPoints,this.infos[5]=this.parent.numIslands,this.infos[6]=this.broadPhaseTime,this.infos[7]=this.narrowPhaseTime,this.infos[8]=this.solvingTime,this.infos[9]=this.updateTime,this.infos[10]=this.totalTime,this.infos[11]=this.fps,this.infos}}),Object.assign(yi.prototype,{Vec3:!0,set:function(t,i,s){return this.x=t,this.y=i,this.z=s,this},add:function(t,i){return void 0!==i?this.addVectors(t,i):(this.x+=t.x,this.y+=t.y,this.z+=t.z,this)},addVectors:function(t,i){return this.x=t.x+i.x,this.y=t.y+i.y,this.z=t.z+i.z,this},addEqual:function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},sub:function(t,i){return void 0!==i?this.subVectors(t,i):(this.x-=t.x,this.y-=t.y,this.z-=t.z,this)},subVectors:function(t,i){return this.x=t.x-i.x,this.y=t.y-i.y,this.z=t.z-i.z,this},subEqual:function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},scale:function(t,i){return this.x=t.x*i,this.y=t.y*i,this.z=t.z*i,this},scaleEqual:function(t){return this.x*=t,this.y*=t,this.z*=t,this},multiply:function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this},addScaledVector:function(t,i){return this.x+=t.x*i,this.y+=t.y*i,this.z+=t.z*i,this},subScaledVector:function(t,i){return this.x-=t.x*i,this.y-=t.y*i,this.z-=t.z*i,this},cross:function(t,i){if(void 0!==i)return this.crossVectors(t,i);var s=this.x,h=this.y,e=this.z;return this.x=h*t.z-e*t.y,this.y=e*t.x-s*t.z,this.z=s*t.y-h*t.x,this},crossVectors:function(t,i){var s=t.x,h=t.y,e=t.z,a=i.x,o=i.y,n=i.z;return this.x=h*n-e*o,this.y=e*a-s*n,this.z=s*o-h*a,this},tangent:function(t){var i=t.x,s=t.y,h=t.z;return this.x=s*i-h*h,this.y=-h*s-i*i,this.z=i*h+s*s,this},invert:function(t){return this.x=-t.x,this.y=-t.y,this.z=-t.z,this},negate:function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},dot:function(t){return this.x*t.x+this.y*t.y+this.z*t.z},addition:function(){return this.x+this.y+this.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Bs.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},copy:function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},applyMatrix3:function(t,i){var s=this.x,h=this.y,e=this.z,a=t.elements;return this.z=i?(this.x=a[0]*s+a[1]*h+a[2]*e,this.y=a[3]*s+a[4]*h+a[5]*e,a[6]*s+a[7]*h+a[8]*e):(this.x=a[0]*s+a[3]*h+a[6]*e,this.y=a[1]*s+a[4]*h+a[7]*e,a[2]*s+a[5]*h+a[8]*e),this},applyQuaternion:function(t){var i=this.x,s=this.y,h=this.z,e=t.x,a=t.y,o=t.z,n=t.w,r=n*i+a*h-o*s,l=n*s+o*i-e*h,c=n*h+e*s-a*i,m=-e*i-a*s-o*h;return this.x=r*n+m*-e+l*-o-c*-a,this.y=l*n+m*-a+c*-e-r*-o,this.z=c*n+m*-o+r*-a-l*-e,this},testZero:function(){return 0!==this.x||0!==this.y||0!==this.z},testDiff:function(t){return!this.equals(t)},equals:function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z},clone:function(){return new this.constructor(this.x,this.y,this.z)},toString:function(){return"Vec3["+this.x.toFixed(4)+", "+this.y.toFixed(4)+", "+this.z.toFixed(4)+"]"},multiplyScalar:function(t){return isFinite(t)?(this.x*=t,this.y*=t,this.z*=t):(this.x=0,this.y=0,this.z=0),this},divideScalar:function(t){return this.multiplyScalar(1/t)},normalize:function(){return this.divideScalar(this.length())},toArray:function(t,i){void 0===i&&(i=0),t[i]=this.x,t[i+1]=this.y,t[i+2]=this.z},fromArray:function(t,i){return void 0===i&&(i=0),this.x=t[i],this.y=t[i+1],this.z=t[i+2],this}}),Object.assign(x.prototype,{Quat:!0,set:function(t,i,s,h){return this.x=t,this.y=i,this.z=s,this.w=h,this},addTime:function(t,i){var s=t.x,h=t.y,e=t.z,a=this.w,o=this.x,n=this.y,r=this.z;return i*=.5,this.x+=i*(s*a+h*r-e*n),this.y+=i*(h*a+e*o-s*r),this.z+=i*(e*a+s*n-h*o),this.w+=i*(-s*o-h*n-e*r),this.normalize(),this},multiply:function(t,i){return void 0!==i?this.multiplyQuaternions(t,i):this.multiplyQuaternions(this,t)},multiplyQuaternions:function(t,i){var s=t.x,h=t.y,e=t.z,a=t.w,o=i.x,n=i.y,r=i.z,l=i.w;return this.x=s*l+a*o+h*r-e*n,this.y=h*l+a*n+e*o-s*r,this.z=e*l+a*r+s*n-h*o,this.w=a*l-s*o-h*n-e*r,this},setFromUnitVectors:function(t,i){var s=new yi,h=t.dot(i)+1;return hBs.abs(t.z)?s.set(-t.y,t.x,0):s.set(0,-t.z,t.y)):s.crossVectors(t,i),this._x=s.x,this._y=s.y,this._z=s.z,this._w=h,this.normalize()},arc:function(t,i){var s=t.x,h=t.y,e=t.z,a=i.x,o=i.y,n=i.z,r=s*a+h*o+e*n;if(-1==r)return a=h*s-e*e,o=-e*h-s*s,n=s*e+h*h,r=1/Bs.sqrt(a*a+o*o+n*n),this.w=0,this.x=a*r,this.y=o*r,this.z=n*r,this;var l=h*n-e*o,c=e*a-s*n,m=s*o-h*a;return this.w=Bs.sqrt(.5*(1+r)),r=.5/this.w,this.x=l*r,this.y=c*r,this.z=m*r,this},normalize:function(){var t=this.length();return 0===t?this.set(0,0,0,1):(t=1/t,this.x=this.x*t,this.y=this.y*t,this.z=this.z*t,this.w=this.w*t),this},inverse:function(){return this.conjugate().normalize()},invert:function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this.conjugate().normalize(),this},conjugate:function(){return this.x*=-1,this.y*=-1,this.z*=-1,this},length:function(){return Bs.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},copy:function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},clone:function(t){return new x(this.x,this.y,this.z,this.w)},testDiff:function(t){return!this.equals(t)},equals:function(t){return this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w},toString:function(){return"Quat["+this.x.toFixed(4)+", ("+this.y.toFixed(4)+", "+this.z.toFixed(4)+", "+this.w.toFixed(4)+")]"},setFromEuler:function(t,i,s){var h=Math.cos(.5*t),e=Math.cos(.5*i),a=Math.cos(.5*s),o=Math.sin(.5*t),n=Math.sin(.5*i),r=Math.sin(.5*s);return this.x=o*e*a+h*n*r,this.y=h*n*a-o*e*r,this.z=h*e*r+o*n*a,this.w=h*e*a-o*n*r,this},setFromAxis:function(t,i){t.normalize(),i*=.5;var s=Bs.sin(i);return this.x=s*t.x,this.y=s*t.y,this.z=s*t.z,this.w=Bs.cos(i),this},setFromMat33:function(t){var i,s=t[0]+t[4]+t[8];if(0t[0]&&(e=1),t[8]>t[3*e+e]&&(e=2);var a=(e+1)%3,o=(e+2)%3;i=Bs.sqrt(t[3*e+e]-t[3*a+a]-t[3*o+o]+1),h[e]=.5*fRoot,i=.5/fRoot,this.w=(t[3*a+o]-t[3*o+a])*i,h[a]=(t[3*a+e]+t[3*e+a])*i,h[o]=(t[3*o+e]+t[3*e+o])*i,this.x=h[1],this.y=h[2],this.z=h[3]}return this},toArray:function(t,i){t[i=i||0]=this.x,t[i+1]=this.y,t[i+2]=this.z,t[i+3]=this.w},fromArray:function(t,i){return i=i||0,this.set(t[i],t[i+1],t[i+2],t[i+3]),this}}),Object.assign(y.prototype,{Mat33:!0,set:function(t,i,s,h,e,a,o,n,r){var l=this.elements;return l[0]=t,l[1]=i,l[2]=s,l[3]=h,l[4]=e,l[5]=a,l[6]=o,l[7]=n,l[8]=r,this},add:function(t,i){if(void 0!==i)return this.addMatrixs(t,i);var s=this.elements,h=t.elements;return s[0]+=h[0],s[1]+=h[1],s[2]+=h[2],s[3]+=h[3],s[4]+=h[4],s[5]+=h[5],s[6]+=h[6],s[7]+=h[7],s[8]+=h[8],this},addMatrixs:function(t,i){var s=this.elements,h=t.elements,e=i.elements;return s[0]=h[0]+e[0],s[1]=h[1]+e[1],s[2]=h[2]+e[2],s[3]=h[3]+e[3],s[4]=h[4]+e[4],s[5]=h[5]+e[5],s[6]=h[6]+e[6],s[7]=h[7]+e[7],s[8]=h[8]+e[8],this},addEqual:function(t){var i=this.elements,s=t.elements;return i[0]+=s[0],i[1]+=s[1],i[2]+=s[2],i[3]+=s[3],i[4]+=s[4],i[5]+=s[5],i[6]+=s[6],i[7]+=s[7],i[8]+=s[8],this},sub:function(t,i){if(void 0!==i)return this.subMatrixs(t,i);var s=this.elements,h=t.elements;return s[0]-=h[0],s[1]-=h[1],s[2]-=h[2],s[3]-=h[3],s[4]-=h[4],s[5]-=h[5],s[6]-=h[6],s[7]-=h[7],s[8]-=h[8],this},subMatrixs:function(t,i){var s=this.elements,h=t.elements,e=i.elements;return s[0]=h[0]-e[0],s[1]=h[1]-e[1],s[2]=h[2]-e[2],s[3]=h[3]-e[3],s[4]=h[4]-e[4],s[5]=h[5]-e[5],s[6]=h[6]-e[6],s[7]=h[7]-e[7],s[8]=h[8]-e[8],this},subEqual:function(t){var i=this.elements,s=t.elements;return i[0]-=s[0],i[1]-=s[1],i[2]-=s[2],i[3]-=s[3],i[4]-=s[4],i[5]-=s[5],i[6]-=s[6],i[7]-=s[7],i[8]-=s[8],this},scale:function(t,i){var s=this.elements,h=t.elements;return s[0]=h[0]*i,s[1]=h[1]*i,s[2]=h[2]*i,s[3]=h[3]*i,s[4]=h[4]*i,s[5]=h[5]*i,s[6]=h[6]*i,s[7]=h[7]*i,s[8]=h[8]*i,this},scaleEqual:function(t){var i=this.elements;return i[0]*=t,i[1]*=t,i[2]*=t,i[3]*=t,i[4]*=t,i[5]*=t,i[6]*=t,i[7]*=t,i[8]*=t,this},multiplyMatrices:function(t,i,s){s&&(i=i.clone().transpose());var h=this.elements,e=t.elements,a=i.elements,o=e[0],n=e[3],r=e[6],l=e[1],c=e[4],m=e[7],p=e[2],u=e[5],y=e[8],x=a[0],d=a[3],f=a[6],b=a[1],v=a[4],z=a[7],N=a[2],k=a[5],w=a[8];return h[0]=o*x+l*d+p*f,h[1]=o*b+l*v+p*z,h[2]=o*N+l*k+p*w,h[3]=n*x+c*d+u*f,h[4]=n*b+c*v+u*z,h[5]=n*N+c*k+u*w,h[6]=r*x+m*d+y*f,h[7]=r*b+m*v+y*z,h[8]=r*N+m*k+y*w,this},transpose:function(t){if(void 0!==t){var i=t.elements;return this.set(i[0],i[3],i[6],i[1],i[4],i[7],i[2],i[5],i[8]),this}var s=this.elements,h=s[1],e=s[2],a=s[5];return s[1]=s[3],s[2]=s[6],s[3]=h,s[5]=s[7],s[6]=e,s[7]=a,this},setQuat:function(t){var i=this.elements,s=t.x,h=t.y,e=t.z,a=t.w,o=s+s,n=h+h,r=e+e,l=s*o,c=s*n,m=s*r,p=h*n,u=h*r,y=e*r,x=a*o,d=a*n,f=a*r;return i[0]=1-(p+y),i[1]=c-f,i[2]=m+d,i[3]=c+f,i[4]=1-(l+y),i[5]=u-x,i[6]=m-d,i[7]=u+x,i[8]=1-(l+p),this},invert:function(t){var i=this.elements,s=t.elements,h=s[0],e=s[3],a=s[6],o=s[1],n=s[4],r=s[7],l=s[2],c=s[5],m=s[8],p=m*n-c*r,u=-m*e+c*a,y=r*e-n*a,x=h*p+o*u+l*y;return 0===x?(console.log("can't invert matrix, determinant is 0"),this.identity()):(x=1/x,i[0]=p*x,i[1]=(-m*o+l*r)*x,i[2]=(c*o-l*n)*x,i[3]=u*x,i[4]=(m*h-l*a)*x,i[5]=(-c*h+l*e)*x,i[6]=y*x,i[7]=(-r*h+o*a)*x,i[8]=(n*h-o*e)*x,this)},addOffset:function(t,i){var s=i.x,h=i.y,e=i.z,a=this.elements;a[0]+=t*(h*h+e*e),a[4]+=t*(s*s+e*e),a[8]+=t*(s*s+h*h);var o=t*s*h,n=t*h*e,r=t*e*s;return a[1]-=o,a[3]-=o,a[2]-=n,a[6]-=n,a[5]-=r,a[7]-=r,this},subOffset:function(t,i){var s=i.x,h=i.y,e=i.z,a=this.elements;a[0]-=t*(h*h+e*e),a[4]-=t*(s*s+e*e),a[8]-=t*(s*s+h*h);var o=t*s*h,n=t*h*e,r=t*e*s;return a[1]+=o,a[3]+=o,a[2]+=n,a[6]+=n,a[5]+=r,a[7]+=r,this},multiplyScalar:function(t){var i=this.elements;return i[0]*=t,i[3]*=t,i[6]*=t,i[1]*=t,i[4]*=t,i[7]*=t,i[2]*=t,i[5]*=t,i[8]*=t,this},identity:function(){return this.set(1,0,0,0,1,0,0,0,1),this},clone:function(){return(new y).fromArray(this.elements)},copy:function(t){for(var i=0;i<9;i++)this.elements[i]=t.elements[i];return this},determinant:function(){var t=this.elements,i=t[0],s=t[1],h=t[2],e=t[3],a=t[4],o=t[5],n=t[6],r=t[7],l=t[8];return i*a*l-i*o*r-s*e*l+s*o*n+h*e*r-h*a*n},fromArray:function(t,i){void 0===i&&(i=0);for(var s=0;s<9;s++)this.elements[s]=t[s+i];return this},toArray:function(t,i){void 0===t&&(t=[]),void 0===i&&(i=0);var s=this.elements;return t[i]=s[0],t[i+1]=s[1],t[i+2]=s[2],t[i+3]=s[3],t[i+4]=s[4],t[i+5]=s[5],t[i+6]=s[6],t[i+7]=s[7],t[i+8]=s[8],t}}),Object.assign(f.prototype,{AABB:!0,set:function(t,i,s,h,e,a){var o=this.elements;return o[0]=t,o[3]=i,o[1]=s,o[4]=h,o[2]=e,o[5]=a,this},intersectTest:function(t){var i=this.elements,s=t.elements;return i[0]>s[3]||i[1]>s[4]||i[2]>s[5]||i[3]s[3]||i[4]>s[4]||i[5]>s[5]},clone:function(){return(new this.constructor).fromArray(this.elements)},copy:function(t,i){var s=i||0,h=t.elements;return this.set(h[0]-s,h[3]+s,h[1]-s,h[4]+s,h[2]-s,h[5]+s),this},fromArray:function(t){return this.elements.set(t),this},combine:function(t,i){var s=t.elements,h=i.elements,e=this.elements;return e[0]=s[0]h[3]?s[3]:h[3],e[4]=s[4]>h[4]?s[4]:h[4],e[5]=s[5]>h[5]?s[5]:h[5],this},surfaceArea:function(){var t=this.elements,i=t[3]-t[0],s=t[4]-t[1],h=t[5]-t[2];return 2*(i*(s+h)+s*h)},intersectsWithPoint:function(t,i,s){var h=this.elements;return t>=h[0]&&t<=h[3]&&i>=h[1]&&i<=h[4]&&s>=h[2]&&s<=h[5]},setFromPoints:function(t){this.makeEmpty();for(var i=0;ithis.upperLimit1?(1!=this.limitState1&&(this.limitState1=1,this.limitImpulse1=0),this.limitVelocity1=this.upperLimit1-u):(this.limitState1=2,this.limitImpulse1=0,this.limitVelocity1=0),n||(.02this.upperLimit2?(1!=this.limitState2&&(this.limitState2=1,this.limitImpulse2=0),this.limitVelocity2=this.upperLimit2-y):(this.limitState2=2,this.limitImpulse2=0,this.limitVelocity2=0),r||(.02this.upperLimit3?(1!=this.limitState3&&(this.limitState3=1,this.limitImpulse3=0),this.limitVelocity3=this.upperLimit3-x):(this.limitState3=2,this.limitImpulse3=0,this.limitVelocity3=0),l||(.02this.maxMotorImpulse1?this.motorImpulse1=this.maxMotorImpulse1:this.motorImpulse1<-this.maxMotorImpulse1&&(this.motorImpulse1=-this.maxMotorImpulse1),l=this.motorImpulse1-o),this.enableMotor2&&(c=(e-this.motorSpeed2)*this.dv11,this.motorImpulse2+=c,this.motorImpulse2>this.maxMotorImpulse2?this.motorImpulse2=this.maxMotorImpulse2:this.motorImpulse2<-this.maxMotorImpulse2&&(this.motorImpulse2=-this.maxMotorImpulse2),c=this.motorImpulse2-n),this.enableMotor3&&(m=(a-this.motorSpeed3)*this.dv22,this.motorImpulse3+=m,this.motorImpulse3>this.maxMotorImpulse3?this.motorImpulse3=this.maxMotorImpulse3:this.motorImpulse3<-this.maxMotorImpulse3&&(this.motorImpulse3=-this.maxMotorImpulse3),m=this.motorImpulse3-r),h+=l*this.kv00+c*this.k01+m*this.k02,e+=l*this.k10+c*this.kv11+m*this.k12,a+=l*this.k20+c*this.k21+m*this.kv22,h-=this.limitVelocity1+this.limitImpulse1*this.cfm1,e-=this.limitVelocity2+this.limitImpulse2*this.cfm2,a-=this.limitVelocity3+this.limitImpulse3*this.cfm3;var p=this.limitImpulse1,u=this.limitImpulse2,y=this.limitImpulse3,x=h*this.d00+e*this.d01+a*this.d02,d=h*this.d10+e*this.d11+a*this.d12,f=h*this.d20+e*this.d21+a*this.d22;this.limitImpulse1+=x,this.limitImpulse2+=d,this.limitImpulse3+=f;var b,v=0;switch((2==this.limitState1||this.limitImpulse1*this.limitState1<0)&&(e+=(x=-p)*this.k10,a+=x*this.k20,v|=1),(2==this.limitState2||this.limitImpulse2*this.limitState2<0)&&(h+=(d=-u)*this.k01,a+=d*this.k21,v|=2),(2==this.limitState3||this.limitImpulse3*this.limitState3<0)&&(h+=(f=-y)*this.k02,e+=f*this.k12,v|=4),v){case 1:b=1/(this.k11*this.k22-this.k12*this.k21),d=(this.k22*e+-this.k12*a)*b,f=(-this.k21*e+this.k11*a)*b;break;case 2:b=1/(this.k00*this.k22-this.k02*this.k20),x=(this.k22*h+-this.k02*a)*b,f=(-this.k20*h+this.k00*a)*b;break;case 3:f=a/this.k22;break;case 4:b=1/(this.k00*this.k11-this.k01*this.k10),x=(this.k11*h+-this.k01*e)*b,d=(-this.k10*h+this.k00*e)*b;break;case 5:d=e/this.k11;break;case 6:x=h/this.k00}this.limitImpulse1=x+p,this.limitImpulse2=d+u,this.limitImpulse3=f+y;var z=l+x,N=c+d,k=m+f;this.a1.x+=z*this.a1x1+N*this.a1x2+k*this.a1x3,this.a1.y+=z*this.a1y1+N*this.a1y2+k*this.a1y3,this.a1.z+=z*this.a1z1+N*this.a1z2+k*this.a1z3,this.a2.x-=z*this.a2x1+N*this.a2x2+k*this.a2x3,this.a2.y-=z*this.a2y1+N*this.a2y2+k*this.a2y3,this.a2.z-=z*this.a2z1+N*this.a2z2+k*this.a2z3,t=this.a2.x-this.a1.x,i=this.a2.y-this.a1.y,s=this.a2.z-this.a1.z,e=t*this.ax2+i*this.ay2+s*this.az2}}),j.prototype=Object.assign(Object.create(P.prototype),{constructor:j,preSolve:function(t,i){this.updateAnchorPoints(),this.ax1.copy(this.localAxis1).applyMatrix3(this.body1.rotation,!0),this.ax2.copy(this.localAxis2).applyMatrix3(this.body2.rotation,!0),this.an1.copy(this.localAngle1).applyMatrix3(this.body1.rotation,!0),this.an2.copy(this.localAngle2).applyMatrix3(this.body2.rotation,!0),this.nor.set(this.ax1.x*this.body2.inverseMass+this.ax2.x*this.body1.inverseMass,this.ax1.y*this.body2.inverseMass+this.ax2.y*this.body1.inverseMass,this.ax1.z*this.body2.inverseMass+this.ax2.z*this.body1.inverseMass).normalize(),this.tan.tangent(this.nor).normalize(),this.bin.crossVectors(this.nor,this.tan);var s=Bs.acosClamp(Bs.dotVectors(this.an1,this.an2));this.tmp.crossVectors(this.an1,this.an2),Bs.dotVectors(this.nor,this.tmp)<0?this.limitMotor.angle=-s:this.limitMotor.angle=s,this.tmp.crossVectors(this.ax1,this.ax2),this.r3.limitMotor2.angle=Bs.dotVectors(this.tan,this.tmp),this.r3.limitMotor3.angle=Bs.dotVectors(this.bin,this.tmp),this.r3.preSolve(t,i),this.lc.preSolve(t,i)},solve:function(){this.r3.solve(),this.lc.solve()},postSolve:function(){}}),C.prototype=Object.assign(Object.create(P.prototype),{constructor:C,preSolve:function(t,i){this.updateAnchorPoints(),this.lc.preSolve(t,i)},solve:function(){this.lc.solve()},postSolve:function(){}}),Object.assign(O.prototype,{TranslationalConstraint:!0,preSolve:function(t,i){this.ax=this.limitMotor.axis.x,this.ay=this.limitMotor.axis.y,this.az=this.limitMotor.axis.z,this.lowerLimit=this.limitMotor.lowerLimit,this.upperLimit=this.limitMotor.upperLimit,this.motorSpeed=this.limitMotor.motorSpeed,this.maxMotorForce=this.limitMotor.maxMotorForce,this.enableMotor=0this.upperLimit?(1!=this.limitState&&(this.limitState=1,this.limitImpulse=0),this.limitVelocity=this.upperLimit-n,l||(n=this.upperLimit)):(this.limitState=2,this.limitImpulse=0,this.limitVelocity=0),l||(.005this.maxMotorImpulse?this.motorImpulse=this.maxMotorImpulse:this.motorImpulse<-this.maxMotorImpulse&&(this.motorImpulse=-this.maxMotorImpulse),s-=(t=this.motorImpulse-h)*this.motorDenom}else t=0;if(2!=this.limitState){i=(s-this.limitVelocity-this.limitImpulse*this.cfm)*this.invDenom;var e=this.limitImpulse;this.limitImpulse+=i,this.limitImpulse*this.limitState<0&&(this.limitImpulse=0),i=this.limitImpulse-e}else i=0;var a=i+t;this.l1.x+=a*this.l1x,this.l1.y+=a*this.l1y,this.l1.z+=a*this.l1z,this.a1.x+=a*this.a1x,this.a1.y+=a*this.a1y,this.a1.z+=a*this.a1z,this.l2.x-=a*this.l2x,this.l2.y-=a*this.l2y,this.l2.z-=a*this.l2z,this.a2.x-=a*this.a2x,this.a2.y-=a*this.a2y,this.a2.z-=a*this.a2z}}),D.prototype=Object.assign(Object.create(P.prototype),{constructor:D,preSolve:function(t,i){this.updateAnchorPoints(),this.nor.sub(this.anchorPoint2,this.anchorPoint1).normalize(),this.t.preSolve(t,i)},solve:function(){this.t.solve()},postSolve:function(){}}),Object.assign(E.prototype,{AngularConstraint:!0,preSolve:function(t,i){var s,h,e;this.ii1=this.i1.clone(),this.ii2=this.i2.clone(),s=1/((e=(new y).add(this.ii1,this.ii2).elements)[0]*(e[4]*e[8]-e[7]*e[5])+e[3]*(e[7]*e[2]-e[1]*e[8])+e[6]*(e[1]*e[5]-e[4]*e[2])),this.dd=(new y).set(e[4]*e[8]-e[5]*e[7],e[2]*e[7]-e[1]*e[8],e[1]*e[5]-e[2]*e[4],e[5]*e[6]-e[3]*e[8],e[0]*e[8]-e[2]*e[6],e[2]*e[3]-e[0]*e[5],e[3]*e[7]-e[4]*e[6],e[1]*e[6]-e[0]*e[7],e[0]*e[4]-e[1]*e[3]).multiplyScalar(s),this.relativeOrientation.invert(this.b1.orientation).multiply(this.targetOrientation).multiply(this.b2.orientation),s=2*this.relativeOrientation.w,this.vel.copy(this.relativeOrientation).multiplyScalar(s),.02<(h=this.vel.length())?(h=(.02-h)/h*i*.05,this.vel.multiplyScalar(h)):this.vel.set(0,0,0),this.rn1.copy(this.imp).applyMatrix3(this.ii1,!0),this.rn2.copy(this.imp).applyMatrix3(this.ii2,!0),this.a1.add(this.rn1),this.a2.sub(this.rn2)},solve:function(){var t=this.a2.clone().sub(this.a1).sub(this.vel);this.rn0.copy(t).applyMatrix3(this.dd,!0),this.rn1.copy(this.rn0).applyMatrix3(this.ii1,!0),this.rn2.copy(this.rn0).applyMatrix3(this.ii2,!0),this.imp.add(this.rn0),this.a1.add(this.rn1),this.a2.sub(this.rn2)}}),Object.assign(B.prototype,{Translational3Constraint:!0,preSolve:function(t,i){this.ax1=this.limitMotor1.axis.x,this.ay1=this.limitMotor1.axis.y,this.az1=this.limitMotor1.axis.z,this.ax2=this.limitMotor2.axis.x,this.ay2=this.limitMotor2.axis.y,this.az2=this.limitMotor2.axis.z,this.ax3=this.limitMotor3.axis.x,this.ay3=this.limitMotor3.axis.y,this.az3=this.limitMotor3.axis.z,this.lowerLimit1=this.limitMotor1.lowerLimit,this.upperLimit1=this.limitMotor1.upperLimit,this.motorSpeed1=this.limitMotor1.motorSpeed,this.maxMotorForce1=this.limitMotor1.maxMotorForce,this.enableMotor1=0this.upperLimit1?(1!=this.limitState1&&(this.limitState1=1,this.limitImpulse1=0),this.limitVelocity1=this.upperLimit1-n,u||(n=this.upperLimit1)):(this.limitState1=2,this.limitImpulse1=0,this.limitVelocity1=0),u||(.005this.upperLimit2?(1!=this.limitState2&&(this.limitState2=1,this.limitImpulse2=0),this.limitVelocity2=this.upperLimit2-r,y||(r=this.upperLimit2)):(this.limitState2=2,this.limitImpulse2=0,this.limitVelocity2=0),y||(.005this.upperLimit3?(1!=this.limitState3&&(this.limitState3=1,this.limitImpulse3=0),this.limitVelocity3=this.upperLimit3-l,x||(l=this.upperLimit3)):(this.limitState3=2,this.limitImpulse3=0,this.limitVelocity3=0),x||(.005this.maxMotorImpulse1?this.motorImpulse1=this.maxMotorImpulse1:this.motorImpulse1<-this.maxMotorImpulse1&&(this.motorImpulse1=-this.maxMotorImpulse1),l=this.motorImpulse1-o),this.enableMotor2&&(c=(e-this.motorSpeed2)*this.dv11,this.motorImpulse2+=c,this.motorImpulse2>this.maxMotorImpulse2?this.motorImpulse2=this.maxMotorImpulse2:this.motorImpulse2<-this.maxMotorImpulse2&&(this.motorImpulse2=-this.maxMotorImpulse2),c=this.motorImpulse2-n),this.enableMotor3&&(m=(a-this.motorSpeed3)*this.dv22,this.motorImpulse3+=m,this.motorImpulse3>this.maxMotorImpulse3?this.motorImpulse3=this.maxMotorImpulse3:this.motorImpulse3<-this.maxMotorImpulse3&&(this.motorImpulse3=-this.maxMotorImpulse3),m=this.motorImpulse3-r),h+=l*this.kv00+c*this.k01+m*this.k02,e+=l*this.k10+c*this.kv11+m*this.k12,a+=l*this.k20+c*this.k21+m*this.kv22,h-=this.limitVelocity1+this.limitImpulse1*this.cfm1,e-=this.limitVelocity2+this.limitImpulse2*this.cfm2,a-=this.limitVelocity3+this.limitImpulse3*this.cfm3;var p=this.limitImpulse1,u=this.limitImpulse2,y=this.limitImpulse3,x=h*this.d00+e*this.d01+a*this.d02,d=h*this.d10+e*this.d11+a*this.d12,f=h*this.d20+e*this.d21+a*this.d22;this.limitImpulse1+=x,this.limitImpulse2+=d,this.limitImpulse3+=f;var b,v=0;switch((2==this.limitState1||this.limitImpulse1*this.limitState1<0)&&(e+=(x=-p)*this.k10,a+=x*this.k20,v|=1),(2==this.limitState2||this.limitImpulse2*this.limitState2<0)&&(h+=(d=-u)*this.k01,a+=d*this.k21,v|=2),(2==this.limitState3||this.limitImpulse3*this.limitState3<0)&&(h+=(f=-y)*this.k02,e+=f*this.k12,v|=4),v){case 1:b=1/(this.k11*this.k22-this.k12*this.k21),d=(this.k22*e+-this.k12*a)*b,f=(-this.k21*e+this.k11*a)*b;break;case 2:b=1/(this.k00*this.k22-this.k02*this.k20),x=(this.k22*h+-this.k02*a)*b,f=(-this.k20*h+this.k00*a)*b;break;case 3:f=a/this.k22;break;case 4:b=1/(this.k00*this.k11-this.k01*this.k10),x=(this.k11*h+-this.k01*e)*b,d=(-this.k10*h+this.k00*e)*b;break;case 5:d=e/this.k11;break;case 6:x=h/this.k00}this.limitImpulse1=p+x,this.limitImpulse2=u+d,this.limitImpulse3=y+f;var z=l+x,N=c+d,k=m+f;this.l1.x+=z*this.l1x1+N*this.l1x2+k*this.l1x3,this.l1.y+=z*this.l1y1+N*this.l1y2+k*this.l1y3,this.l1.z+=z*this.l1z1+N*this.l1z2+k*this.l1z3,this.a1.x+=z*this.a1x1+N*this.a1x2+k*this.a1x3,this.a1.y+=z*this.a1y1+N*this.a1y2+k*this.a1y3,this.a1.z+=z*this.a1z1+N*this.a1z2+k*this.a1z3,this.l2.x-=z*this.l2x1+N*this.l2x2+k*this.l2x3,this.l2.y-=z*this.l2y1+N*this.l2y2+k*this.l2y3,this.l2.z-=z*this.l2z1+N*this.l2z2+k*this.l2z3,this.a2.x-=z*this.a2x1+N*this.a2x2+k*this.a2x3,this.a2.y-=z*this.a2y1+N*this.a2y2+k*this.a2y3,this.a2.z-=z*this.a2z1+N*this.a2z2+k*this.a2z3}}),F.prototype=Object.assign(Object.create(P.prototype),{constructor:F,preSolve:function(t,i){this.updateAnchorPoints(),this.ax1.copy(this.localAxis1).applyMatrix3(this.body1.rotation,!0),this.ax2.copy(this.localAxis2).applyMatrix3(this.body2.rotation,!0),this.nor.set(this.ax1.x*this.body2.inverseMass+this.ax2.x*this.body1.inverseMass,this.ax1.y*this.body2.inverseMass+this.ax2.y*this.body1.inverseMass,this.ax1.z*this.body2.inverseMass+this.ax2.z*this.body1.inverseMass).normalize(),this.tan.tangent(this.nor).normalize(),this.bin.crossVectors(this.nor,this.tan),this.ac.preSolve(t,i),this.t3.preSolve(t,i)},solve:function(){this.ac.solve(),this.t3.solve()},postSolve:function(){}}),q.prototype=Object.assign(Object.create(P.prototype),{constructor:q,preSolve:function(t,i){this.updateAnchorPoints(),this.ax1.copy(this.localAxis1).applyMatrix3(this.body1.rotation,!0),this.an1.copy(this.localAngle1).applyMatrix3(this.body1.rotation,!0),this.ax2.copy(this.localAxis2).applyMatrix3(this.body2.rotation,!0),this.an2.copy(this.localAngle2).applyMatrix3(this.body2.rotation,!0),this.nor.set(this.ax1.x*this.body2.inverseMass+this.ax2.x*this.body1.inverseMass,this.ax1.y*this.body2.inverseMass+this.ax2.y*this.body1.inverseMass,this.ax1.z*this.body2.inverseMass+this.ax2.z*this.body1.inverseMass).normalize(),this.tan.tangent(this.nor).normalize(),this.bin.crossVectors(this.nor,this.tan),this.tmp.crossVectors(this.an1,this.an2);var s=Bs.acosClamp(Bs.dotVectors(this.an1,this.an2));Bs.dotVectors(this.nor,this.tmp)<0?this.rotationalLimitMotor.angle=-s:this.rotationalLimitMotor.angle=s,this.tmp.crossVectors(this.ax1,this.ax2),this.r3.limitMotor2.angle=Bs.dotVectors(this.tan,this.tmp),this.r3.limitMotor3.angle=Bs.dotVectors(this.bin,this.tmp),this.r3.preSolve(t,i),this.t3.preSolve(t,i)},solve:function(){this.r3.solve(),this.t3.solve()},postSolve:function(){}}),U.prototype=Object.assign(Object.create(P.prototype),{constructor:U,preSolve:function(t,i){this.updateAnchorPoints(),this.ax1.copy(this.localAxis1).applyMatrix3(this.body1.rotation,!0),this.an1.copy(this.localAngle1).applyMatrix3(this.body1.rotation,!0),this.ax2.copy(this.localAxis2).applyMatrix3(this.body2.rotation,!0),this.an2.copy(this.localAngle2).applyMatrix3(this.body2.rotation,!0),this.r3.limitMotor1.angle=Bs.dotVectors(this.ax1,this.ax2);var s=Bs.dotVectors(this.an1,this.ax2);Bs.dotVectors(this.ax1,this.tmp.crossVectors(this.an1,this.ax2))<0?this.rotationalLimitMotor1.angle=-s:this.rotationalLimitMotor1.angle=s,s=Bs.dotVectors(this.an2,this.ax1),Bs.dotVectors(this.ax2,this.tmp.crossVectors(this.an2,this.ax1))<0?this.rotationalLimitMotor2.angle=-s:this.rotationalLimitMotor2.angle=s,this.nor.crossVectors(this.ax1,this.ax2).normalize(),this.tan.crossVectors(this.nor,this.ax2).normalize(),this.bin.crossVectors(this.nor,this.ax1).normalize(),this.r3.preSolve(t,i),this.t3.preSolve(t,i)},solve:function(){this.r3.solve(),this.t3.solve()},postSolve:function(){}}),Q.prototype={constructor:Q,reset:function(t,i){this.body1=t.parent,this.body2=i.parent,this.numPoints=0},addPointVec:function(t,i,s,h){var e=this.points[this.numPoints++];e.position.copy(t),e.localPoint1.sub(t,this.body1.position).applyMatrix3(this.body1.rotation),e.localPoint2.sub(t,this.body2.position).applyMatrix3(this.body2.rotation),e.normal.copy(i),h&&e.normal.negate(),e.normalImpulse=0,e.penetration=s,e.warmStarted=!1},addPoint:function(t,i,s,h,e,a,o,n){var r=this.points[this.numPoints++];r.position.set(t,i,s),r.localPoint1.sub(r.position,this.body1.position).applyMatrix3(this.body1.rotation),r.localPoint2.sub(r.position,this.body2.position).applyMatrix3(this.body2.rotation),r.normalImpulse=0,r.normal.set(h,e,a),n&&r.normal.negate(),r.penetration=o,r.warmStarted=!1}},Y.prototype=Object.assign(Object.create(L.prototype),{constructor:Y,attach:function(){this.p1=this.body1.position,this.p2=this.body2.position,this.lv1=this.body1.linearVelocity,this.av1=this.body1.angularVelocity,this.lv2=this.body2.linearVelocity,this.av2=this.body2.angularVelocity,this.i1=this.body1.inverseInertia,this.i2=this.body2.inverseInertia},detach:function(){this.p1=null,this.p2=null,this.lv1=null,this.lv2=null,this.av1=null,this.av2=null,this.i1=null,this.i2=null},preSolve:function(t,i){this.m1=this.body1.inverseMass,this.m2=this.body2.inverseMass;var s=this.m1+this.m2;this.num=this.manifold.numPoints;for(var h,e,a,o,n,r,l,c=this.cs,m=0;m>1;h=this.bufferSize){this.bufferSize*=2;for(var s=[],h=this.numElements;h--;)s[h]=this.elements[h]}this.elements[this.numElements++]=t,this.elements[this.numElements++]=i},removeElements:function(t,i){for(var s=-1,h=-1,e=0,a=this.numElements;e>i!=0;)i++;i=i*this.numElements>>2,t=0;for(var s=!1,h=this.elements,e=1,a=this.numElements;en){var l=e;do{if(h[l]=r,0==--l)break;r=h[l-1]}while(r.value>n);if(h[l]=o,i<(t+=e-l)){s=!0;break}}}if(s){t=2;var c=this.stack;for(c[0]=0,c[1]=this.numElements-1;0n){l=e;do{if(h[l]=r,0==--l)break;r=h[l-1]}while(r.value>n);h[l]=o}}}},calculateTestCount:function(){for(var t=1,i=0,s=1,h=this.numElements;sb.max1.value||xb.max2.value||fb.max1.value||xb.max2.value||f>31)+1,e.aabb.combine(l.aabb,t.aabb),m-((s=m-i)&s>>31)+1):((e.child1=t).parent=e,((t.child1=l).parent=t).aabb.combine(l.aabb,a.aabb),s=m-n,t.height=m-(s&s>>31)+1,e.aabb.combine(t.aabb,c.aabb),i-((s=i-p)&s>>31)+1),null!=h?h.child1==t?h.child1=e:h.child2=e:this.root=e,e.parent=h,e}if(r<-1){var u=a.child1,y=a.child2,x=u.height,d=y.height;return a.height=d>31)+1,a.aabb.combine(u.aabb,t.aabb),x-((s=x-i)&s>>31)+1):((a.child1=t).parent=a,((t.child2=u).parent=t).aabb.combine(e.aabb,u.aabb),s=o-x,t.height=o-(s&s>>31)+1,a.aabb.combine(t.aabb,y.aabb),i-((s=i-d)&s>>31)+1),null!=h?h.child1==t?h.child1=a:h.child2=a:this.root=a,a.parent=h,a}return t},fix:function(t){var i=t.child1,s=t.child2;t.aabb.combine(i.aabb,s.aabb),t.height=i.heighta.aabb.surfaceArea()?(this.stack[r++]=e.child1,this.stack[r++]=a,this.stack[r++]=e.child2,this.stack[r++]=a):(this.stack[r++]=e,this.stack[r++]=a.child1,this.stack[r++]=e,this.stack[r++]=a.child2)}}}),Object.assign(pt.prototype,{CollisionDetector:!0,detectCollision:function(t,i,s){d("CollisionDetector","Inheritance error.")}}),ut.prototype=Object.assign(Object.create(pt.prototype),{constructor:ut,detectCollision:function(t,i,s){var h,e;e=t.idc?o.x=c:o.x<-c?o.x=-c:u=1,o.y>m?o.y=m:o.y<-m?o.y=-m:u|=2,o.z>p?o.z=p:o.z<-p?o.z=-p:u|=4,7===u&&(e.set(o.x<0?c+o.x:c-o.x,o.y<0?m+o.y:m-o.y,o.z<0?p+o.z:p-o.z),e.x