diff --git "a/libs/Oimo.js" "b/libs/Oimo.js" new file mode 100644--- /dev/null +++ "b/libs/Oimo.js" @@ -0,0 +1,2 @@ +// lo-th.github.io/Oimo.js/license +!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:t>0?1:+t}),void 0===Function.prototype.name&&Object.defineProperty(Function.prototype,"name",{get:function(){return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1]}}),void 0===Object.assign&&(Object.assign=function(t){if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var i=Object(t),s=1;s>=4,e[t]=h[19===t?3&s|8:s]);return e.join("")}),int:function(t){return g.floor(t)},fix:function(t,i){return t.toFixed(i||3,10)},clamp:function(t,i,s){return g.max(i,g.min(s,t))},distance:function(t,i){var s=i[0]-t[0],h=i[1]-t[1],e=i[2]-t[2];return g.sqrt(s*s+h*h+e*e)},acosClamp:function(t){return t>1?0:t<-1?g.PI:g.acos(t)},distanceVector:function(t,i){var s=t.x-i.x,h=t.y-i.y,e=t.z-i.z;return s*s+h*h+e*e},dotVectors:function(t,i){return t.x*i.x+t.y*i.y+t.z*i.z}};function I(t,i){console.error("[OIMO] "+t+": "+i)}function V(t){this.parent=t,this.infos=new Float32Array(13),this.f=[0,0,0],this.times=[0,0,0,0],this.broadPhase=this.parent.broadPhaseType,this.version=o,this.fps=0,this.tt=0,this.broadPhaseTime=0,this.narrowPhaseTime=0,this.solvingTime=0,this.totalTime=0,this.updateTime=0,this.MaxBroadPhaseTime=0,this.MaxNarrowPhaseTime=0,this.MaxSolvingTime=0,this.MaxTotalTime=0,this.MaxUpdateTime=0}function L(t,i,s){this.x=t||0,this.y=i||0,this.z=s||0}function S(t,i,s,h){this.x=t||0,this.y=i||0,this.z=s||0,this.w=void 0!==h?h:1}function P(t,i,s,h,e,a,o,n,r){this.elements=[1,0,0,0,1,0,0,0,1],arguments.length>0&&console.error("OIMO.Mat33: the constructor no longer reads arguments. use .set() instead.")}function T(t,i,s,h,e,a){this.elements=new Float32Array(6);var o=this.elements;o[0]=t||0,o[1]=s||0,o[2]=e||0,o[3]=i||0,o[4]=h||0,o[5]=a||0}Object.assign(V.prototype,{setTime:function(t){this.times[t||0]=performance.now()},resetMax:function(){this.MaxBroadPhaseTime=0,this.MaxNarrowPhaseTime=0,this.MaxSolvingTime=0,this.MaxTotalTime=0,this.MaxUpdateTime=0},calcBroadPhase:function(){this.setTime(2),this.broadPhaseTime=this.times[2]-this.times[1]},calcNarrowPhase:function(){this.setTime(3),this.narrowPhaseTime=this.times[3]-this.times[2]},calcEnd:function(){this.setTime(2),this.solvingTime=this.times[2]-this.times[1],this.totalTime=this.times[2]-this.times[0],this.updateTime=this.totalTime-(this.broadPhaseTime+this.narrowPhaseTime+this.solvingTime),100===this.tt&&this.resetMax(),this.tt>100&&(this.broadPhaseTime>this.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++,this.tt>500&&(this.tt=0)},upfps:function(){this.f[1]=Date.now(),this.f[1]-1e3>this.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  "+g.fix(this.broadPhaseTime)+" | "+g.fix(this.MaxBroadPhaseTime)+"
","narrowphase "+g.fix(this.narrowPhaseTime)+" | "+g.fix(this.MaxNarrowPhaseTime)+"
","solving     "+g.fix(this.solvingTime)+" | "+g.fix(this.MaxSolvingTime)+"
","total       "+g.fix(this.totalTime)+" | "+g.fix(this.MaxTotalTime)+"
","updating    "+g.fix(this.updateTime)+" | "+g.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(L.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 g.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 i?(this.x=a[0]*s+a[1]*h+a[2]*e,this.y=a[3]*s+a[4]*h+a[5]*e,this.z=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,this.z=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(S.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 L,h=t.dot(i)+1;return hg.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/g.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=g.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 g.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 S(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=g.sin(i);return this.x=s*t.x,this.y=s*t.y,this.z=s*t.z,this.w=g.cos(i),this},setFromMat33:function(t){var i,s=t[0]+t[4]+t[8];if(s>0)i=g.sqrt(s+1),this.w=.5/i,i=.5/i,this.x=(t[5]-t[7])*i,this.y=(t[6]-t[2])*i,this.z=(t[1]-t[3])*i;else{var h=[],e=0;t[4]>t[0]&&(e=1),t[8]>t[3*e+e]&&(e=2);var a=(e+1)%3,o=(e+2)%3;i=g.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(P.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 P).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(T.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;i-1&&i<1)this.localAngle1.set(this.localAxis2.x-i*this.localAxis1.x,this.localAxis2.y-i*this.localAxis1.y,this.localAxis2.z-i*this.localAxis1.z).normalize(),this.localAngle2.set(this.localAxis1.x-i*this.localAxis2.x,this.localAxis1.y-i*this.localAxis2.y,this.localAxis1.z-i*this.localAxis2.z).normalize();else{var s=(new P).setQuat((new S).setFromUnitVectors(this.localAxis1,this.localAxis2));this.localAngle1.tangent(this.localAxis1).normalize(),this.localAngle2=this.localAngle1.clone().applyMatrix3(s,!0)}this.ax1=new L,this.ax2=new L,this.an1=new L,this.an2=new L,this.tmp=new L,this.nor=new L,this.tan=new L,this.bin=new L,this.translationalLimitMotor=new q(this.tan,!0),this.translationalLimitMotor.frequency=8,this.translationalLimitMotor.dampingRatio=1,this.rotationalLimitMotor1=new q(this.tan,!1),this.rotationalLimitMotor2=new q(this.bin,!1),this.t3=new K(this,new q(this.nor,!0),this.translationalLimitMotor,new q(this.bin,!0)),this.t3.weight=1,this.r3=new W(this,new q(this.nor,!0),this.rotationalLimitMotor1,this.rotationalLimitMotor2)}function it(){this.scale=1,this.invScale=1,this.body1=null,this.body2=null,this.localAnchorPoint1=new L,this.localAnchorPoint2=new L,this.localAxis1=new L,this.localAxis2=new L,this.allowCollision=!1}function st(){this.mass=0,this.inertia=new P}function ht(t){this.prev=null,this.next=null,this.shape=null,this.body=null,this.contact=t}function et(){this.lp1X=NaN,this.lp1Y=NaN,this.lp1Z=NaN,this.lp2X=NaN,this.lp2Y=NaN,this.lp2Z=NaN,this.impulse=NaN}function at(){this.warmStarted=!1,this.position=new L,this.localPoint1=new L,this.localPoint2=new L,this.normal=new L,this.tangent=new L,this.binormal=new L,this.normalImpulse=0,this.tangentImpulse=0,this.binormalImpulse=0,this.normalDenominator=0,this.tangentDenominator=0,this.binormalDenominator=0,this.penetration=0}function ot(){this.body1=null,this.body2=null,this.numPoints=0,this.points=[new at,new at,new at,new at]}function nt(){this.nor=new L,this.tan=new L,this.bin=new L,this.norU1=new L,this.tanU1=new L,this.binU1=new L,this.norU2=new L,this.tanU2=new L,this.binU2=new L,this.norT1=new L,this.tanT1=new L,this.binT1=new L,this.norT2=new L,this.tanT2=new L,this.binT2=new L,this.norTU1=new L,this.tanTU1=new L,this.binTU1=new L,this.norTU2=new L,this.tanTU2=new L,this.binTU2=new L,this.norImp=0,this.tanImp=0,this.binImp=0,this.norDen=0,this.tanDen=0,this.binDen=0,this.norTar=0,this.next=null,this.last=!1}function rt(t){U.call(this),this.manifold=t,this.restitution=NaN,this.friction=NaN,this.p1=null,this.p2=null,this.lv1=null,this.lv2=null,this.av1=null,this.av2=null,this.i1=null,this.i2=null,this.tmp=new L,this.tmpC1=new L,this.tmpC2=new L,this.tmpP1=new L,this.tmpP2=new L,this.tmplv1=new L,this.tmplv2=new L,this.tmpav1=new L,this.tmpav2=new L,this.m1=NaN,this.m2=NaN,this.num=0,this.ps=t.points,this.cs=new nt,this.cs.next=new nt,this.cs.next.next=new nt,this.cs.next.next.next=new nt}function lt(){this.shape1=null,this.shape2=null,this.body1=null,this.body2=null,this.prev=null,this.next=null,this.persisting=!1,this.sleeping=!1,this.detector=null,this.constraint=null,this.touching=!1,this.close=!1,this.dist=g.INF,this.b1Link=new ht(this),this.b2Link=new ht(this),this.s1Link=new ht(this),this.s2Link=new ht(this),this.manifold=new ot,this.buffer=[new et,new et,new et,new et],this.points=this.manifold.points,this.constraint=new rt(this.manifold)}function ct(t,i){this.position=t||new L,this.orientation=i||new S,this.scale=1,this.invScale=1,this.mesh=null,this.id=NaN,this.name="",this.prev=null,this.next=null,this.type=m,this.massInfo=new st,this.newPosition=new L,this.controlPos=!1,this.newOrientation=new S,this.newRotation=new L,this.currentRotation=new L,this.controlRot=!1,this.controlRotInTime=!1,this.quaternion=new S,this.pos=new L,this.linearVelocity=new L,this.angularVelocity=new L,this.parent=null,this.contactLink=null,this.numContacts=0,this.shapes=null,this.numShapes=0,this.jointLink=null,this.numJoints=0,this.sleepPosition=new L,this.sleepOrientation=new S,this.isStatic=!1,this.isDynamic=!1,this.isKinematic=!1,this.rotation=new P,this.mass=0,this.inverseMass=0,this.inverseInertia=new P,this.localInertia=new P,this.inverseLocalInertia=new P,this.tmpInertia=new P,this.addedToIsland=!1,this.allowSleep=!0,this.sleepTime=0,this.sleeping=!1}function mt(t,i){this.shape1=t||null,this.shape2=i||null}function pt(){this.types=n,this.numPairChecks=0,this.numPairs=0,this.pairs=[]}Object.assign(j.prototype,{Shape:!0,calculateMassInfo:function(t){I("Shape","Inheritance error.")},updateProxy:function(){I("Shape","Inheritance error.")}}),C.prototype=Object.assign(Object.create(j.prototype),{constructor:C,calculateMassInfo:function(t){var i=this.width*this.height*this.depth*this.density;t.mass=i,t.inertia.set(i*(this.height*this.height+this.depth*this.depth)*(1/12),0,0,0,i*(this.width*this.width+this.depth*this.depth)*(1/12),0,0,0,i*(this.width*this.width+this.height*this.height)*(1/12))},updateProxy:function(){var t=this.rotation.elements,i=this.dimentions;i[0]=t[0],i[1]=t[3],i[2]=t[6],i[3]=t[1],i[4]=t[4],i[5]=t[7],i[6]=t[2],i[7]=t[5],i[8]=t[8],i[9]=t[0]*this.halfWidth,i[10]=t[3]*this.halfWidth,i[11]=t[6]*this.halfWidth,i[12]=t[1]*this.halfHeight,i[13]=t[4]*this.halfHeight,i[14]=t[7]*this.halfHeight,i[15]=t[2]*this.halfDepth,i[16]=t[5]*this.halfDepth,i[17]=t[8]*this.halfDepth;var s=i[9],h=i[10],e=i[11],a=i[12],o=i[13],n=i[14],r=i[15],l=i[16],c=i[17],m=this.position.x,p=this.position.y,u=this.position.z,y=this.elements;y[0]=m+s+a+r,y[1]=p+h+o+l,y[2]=u+e+n+c,y[3]=m+s+a-r,y[4]=p+h+o-l,y[5]=u+e+n-c,y[6]=m+s-a+r,y[7]=p+h-o+l,y[8]=u+e-n+c,y[9]=m+s-a-r,y[10]=p+h-o-l,y[11]=u+e-n-c,y[12]=m-s+a+r,y[13]=p-h+o+l,y[14]=u-e+n+c,y[15]=m-s+a-r,y[16]=p-h+o-l,y[17]=u-e+n-c,y[18]=m-s-a+r,y[19]=p-h-o+l,y[20]=u-e-n+c,y[21]=m-s-a-r,y[22]=p-h-o-l,y[23]=u-e-n-c;var x=i[9]<0?-i[9]:i[9],d=i[10]<0?-i[10]:i[10],f=i[11]<0?-i[11]:i[11];x=i[12]<0?x-i[12]:x+i[12],d=i[13]<0?d-i[13]:d+i[13],f=i[14]<0?f-i[14]:f+i[14],x=i[15]<0?x-i[15]:x+i[15],d=i[16]<0?d-i[16]:d+i[16],f=i[17]<0?f-i[17]:f+i[17];var b=.005;this.aabb.set(this.position.x-x-b,this.position.x+x+b,this.position.y-d-b,this.position.y+d+b,this.position.z-f-b,this.position.z+f+b),null!=this.proxy&&this.proxy.update()}}),O.prototype=Object.assign(Object.create(j.prototype),{constructor:O,volume:function(){return g.PI*this.radius*1.333333},calculateMassInfo:function(t){var i=this.volume()*this.radius*this.radius*this.density;t.mass=i;var s=i*this.radius*this.radius*.4;t.inertia.set(s,0,0,0,s,0,0,0,s)},updateProxy:function(){var t=.005;this.aabb.set(this.position.x-this.radius-t,this.position.x+this.radius+t,this.position.y-this.radius-t,this.position.y+this.radius+t,this.position.z-this.radius-t,this.position.z+this.radius+t),null!=this.proxy&&this.proxy.update()}}),D.prototype=Object.assign(Object.create(j.prototype),{constructor:D,calculateMassInfo:function(t){var i=this.radius*this.radius,s=g.PI*i*this.height*this.density,h=(.25*i+.0833*this.height*this.height)*s,e=.5*i;t.mass=s,t.inertia.set(h,0,0,0,e,0,0,0,h)},updateProxy:function(){var t,i,s,h,e,a,o,n,r,l,c,m=this.rotation.elements;e=m[1]*m[1],a=m[4]*m[4],o=m[7]*m[7],this.normalDirection.set(m[1],m[4],m[7]),this.halfDirection.scale(this.normalDirection,this.halfHeight),i=1-e,(t=g.sqrt(i*i+e*a+e*o))>0&&(t=this.radius/t),i*=t,s=1-a,(t=g.sqrt(a*e+s*s+a*o))>0&&(t=this.radius/t),s*=t,h=1-o,(t=g.sqrt(o*e+o*a+h*h))>0&&(t=this.radius/t),h*=t,n=this.halfDirection.x<0?-this.halfDirection.x:this.halfDirection.x,r=this.halfDirection.y<0?-this.halfDirection.y:this.halfDirection.y,l=this.halfDirection.z<0?-this.halfDirection.z:this.halfDirection.z,n=i<0?n-i:n+i,r=s<0?r-s:r+s,l=h<0?l-h:l+h,c=.005,this.aabb.set(this.position.x-n-c,this.position.x+n+c,this.position.y-r-c,this.position.y+r+c,this.position.z-l-c,this.position.z+l+c),null!=this.proxy&&this.proxy.update()}}),E.prototype=Object.assign(Object.create(j.prototype),{constructor:E,volume:function(){return Number.MAX_VALUE},calculateMassInfo:function(t){t.mass=this.density;t.inertia.set(1,0,0,0,1,0,0,0,1)},updateProxy:function(){var t=.005,i=-g.INF,s=g.INF,h=this.normal;this.aabb.set(-1===h.x?this.position.x-t:i,1===h.x?this.position.x+t:s,-1===h.y?this.position.y-t:i,1===h.y?this.position.y+t:s,-1===h.z?this.position.z-t:i,1===h.z?this.position.z+t:s),null!=this.proxy&&this.proxy.update()}}),B.prototype=Object.assign(Object.create(j.prototype),{constructor:B,volume:function(){return Number.MAX_VALUE},calculateMassInfo:function(t){t.inertia.set(0,0,0,0,0,0,0,0,0)},updateProxy:function(){this.aabb.set(this.position.x-0,this.position.x+0,this.position.y-0,this.position.y+0,this.position.z-0,this.position.z+0),null!=this.proxy&&this.proxy.update()}}),Object.assign(q.prototype,{LimitMotor:!0,setLimit:function(t,i){this.lowerLimit=t,this.upperLimit=i},setMotor:function(t,i){this.motorSpeed=t,this.maxMotorForce=i},setSpring:function(t,i){this.frequency=t,this.dampingRatio=i}}),Object.assign(U.prototype,{Constraint:!0,preSolve:function(t,i){I("Constraint","Inheritance error.")},solve:function(){I("Constraint","Inheritance error.")},postSolve:function(){I("Constraint","Inheritance error.")}}),_.prototype=Object.assign(Object.create(U.prototype),{constructor:_,setId:function(t){this.id=i},setParent:function(t){this.parent=t,this.scale=this.parent.scale,this.invScale=this.parent.invScale,this.id=this.parent.numJoints,this.name||(this.name="J"+this.id)},updateAnchorPoints:function(){this.relativeAnchorPoint1.copy(this.localAnchorPoint1).applyMatrix3(this.body1.rotation,!0),this.relativeAnchorPoint2.copy(this.localAnchorPoint2).applyMatrix3(this.body2.rotation,!0),this.anchorPoint1.add(this.relativeAnchorPoint1,this.body1.position),this.anchorPoint2.add(this.relativeAnchorPoint2,this.body2.position)},attach:function(t){this.b1Link.body=this.body2,this.b2Link.body=this.body1,t?(this.body1.jointLink.push(this.b1Link),this.body2.jointLink.push(this.b2Link)):(null!=this.body1.jointLink?(this.b1Link.next=this.body1.jointLink).prev=this.b1Link:this.b1Link.next=null,this.body1.jointLink=this.b1Link,this.body1.numJoints++,null!=this.body2.jointLink?(this.b2Link.next=this.body2.jointLink).prev=this.b2Link:this.b2Link.next=null,this.body2.jointLink=this.b2Link,this.body2.numJoints++)},detach:function(t){if(t)this.body1.jointLink.splice(this.body1.jointLink.indexOf(this.b1Link),1),this.body2.jointLink.splice(this.body2.jointLink.indexOf(this.b2Link),1);else{var i=this.b1Link.prev,s=this.b1Link.next;null!=i&&(i.next=s),null!=s&&(s.prev=i),this.body1.jointLink==this.b1Link&&(this.body1.jointLink=s),this.b1Link.prev=null,this.b1Link.next=null,this.b1Link.body=null,this.body1.numJoints--,i=this.b2Link.prev,s=this.b2Link.next,null!=i&&(i.next=s),null!=s&&(s.prev=i),this.body2.jointLink==this.b2Link&&(this.body2.jointLink=s),this.b2Link.prev=null,this.b2Link.next=null,this.b2Link.body=null,this.body2.numJoints--}this.b1Link.body=null,this.b2Link.body=null},awake:function(){this.body1.awake(),this.body2.awake()},preSolve:function(t,i){},solve:function(){},postSolve:function(){},remove:function(){this.dispose()},dispose:function(){this.parent.removeJoint(this)},getPosition:function(){return[(new L).scale(this.anchorPoint1,this.scale),(new L).scale(this.anchorPoint2,this.scale)]}}),Object.assign(J.prototype,{LinearConstraint:!0,preSolve:function(t,i){this.r1x=this.r1.x,this.r1y=this.r1.y,this.r1z=this.r1.z,this.r2x=this.r2.x,this.r2y=this.r2.y,this.r2z=this.r2.z,this.m1=this.b1.inverseMass,this.m2=this.b2.inverseMass,this.ii1=this.i1.clone(),this.ii2=this.i2.clone();var s=this.ii1.elements,h=this.ii2.elements;this.ax1x=this.r1z*s[1]+-this.r1y*s[2],this.ax1y=this.r1z*s[4]+-this.r1y*s[5],this.ax1z=this.r1z*s[7]+-this.r1y*s[8],this.ay1x=-this.r1z*s[0]+this.r1x*s[2],this.ay1y=-this.r1z*s[3]+this.r1x*s[5],this.ay1z=-this.r1z*s[6]+this.r1x*s[8],this.az1x=this.r1y*s[0]+-this.r1x*s[1],this.az1y=this.r1y*s[3]+-this.r1x*s[4],this.az1z=this.r1y*s[6]+-this.r1x*s[7],this.ax2x=this.r2z*h[1]+-this.r2y*h[2],this.ax2y=this.r2z*h[4]+-this.r2y*h[5],this.ax2z=this.r2z*h[7]+-this.r2y*h[8],this.ay2x=-this.r2z*h[0]+this.r2x*h[2],this.ay2y=-this.r2z*h[3]+this.r2x*h[5],this.ay2z=-this.r2z*h[6]+this.r2x*h[8],this.az2x=this.r2y*h[0]+-this.r2x*h[1],this.az2y=this.r2y*h[3]+-this.r2x*h[4],this.az2z=this.r2y*h[6]+-this.r2x*h[7];var e=this.m1+this.m2,a=(new P).set(e,0,0,0,e,0,0,0,e).elements;a[0]+=s[4]*this.r1z*this.r1z-(s[7]+s[5])*this.r1y*this.r1z+s[8]*this.r1y*this.r1y,a[1]+=(s[6]*this.r1y+s[5]*this.r1x)*this.r1z-s[3]*this.r1z*this.r1z-s[8]*this.r1x*this.r1y,a[2]+=(s[3]*this.r1y-s[4]*this.r1x)*this.r1z-s[6]*this.r1y*this.r1y+s[7]*this.r1x*this.r1y,a[3]+=(s[2]*this.r1y+s[7]*this.r1x)*this.r1z-s[1]*this.r1z*this.r1z-s[8]*this.r1x*this.r1y,a[4]+=s[0]*this.r1z*this.r1z-(s[6]+s[2])*this.r1x*this.r1z+s[8]*this.r1x*this.r1x,a[5]+=(s[1]*this.r1x-s[0]*this.r1y)*this.r1z-s[7]*this.r1x*this.r1x+s[6]*this.r1x*this.r1y,a[6]+=(s[1]*this.r1y-s[4]*this.r1x)*this.r1z-s[2]*this.r1y*this.r1y+s[5]*this.r1x*this.r1y,a[7]+=(s[3]*this.r1x-s[0]*this.r1y)*this.r1z-s[5]*this.r1x*this.r1x+s[2]*this.r1x*this.r1y,a[8]+=s[0]*this.r1y*this.r1y-(s[3]+s[1])*this.r1x*this.r1y+s[4]*this.r1x*this.r1x,a[0]+=h[4]*this.r2z*this.r2z-(h[7]+h[5])*this.r2y*this.r2z+h[8]*this.r2y*this.r2y,a[1]+=(h[6]*this.r2y+h[5]*this.r2x)*this.r2z-h[3]*this.r2z*this.r2z-h[8]*this.r2x*this.r2y,a[2]+=(h[3]*this.r2y-h[4]*this.r2x)*this.r2z-h[6]*this.r2y*this.r2y+h[7]*this.r2x*this.r2y,a[3]+=(h[2]*this.r2y+h[7]*this.r2x)*this.r2z-h[1]*this.r2z*this.r2z-h[8]*this.r2x*this.r2y,a[4]+=h[0]*this.r2z*this.r2z-(h[6]+h[2])*this.r2x*this.r2z+h[8]*this.r2x*this.r2x,a[5]+=(h[1]*this.r2x-h[0]*this.r2y)*this.r2z-h[7]*this.r2x*this.r2x+h[6]*this.r2x*this.r2y,a[6]+=(h[1]*this.r2y-h[4]*this.r2x)*this.r2z-h[2]*this.r2y*this.r2y+h[5]*this.r2x*this.r2y,a[7]+=(h[3]*this.r2x-h[0]*this.r2y)*this.r2z-h[5]*this.r2x*this.r2x+h[2]*this.r2x*this.r2y,a[8]+=h[0]*this.r2y*this.r2y-(h[3]+h[1])*this.r2x*this.r2y+h[4]*this.r2x*this.r2x;var o=1/(a[0]*(a[4]*a[8]-a[7]*a[5])+a[3]*(a[7]*a[2]-a[1]*a[8])+a[6]*(a[1]*a[5]-a[4]*a[2]));this.dd=(new P).set(a[4]*a[8]-a[5]*a[7],a[2]*a[7]-a[1]*a[8],a[1]*a[5]-a[2]*a[4],a[5]*a[6]-a[3]*a[8],a[0]*a[8]-a[2]*a[6],a[2]*a[3]-a[0]*a[5],a[3]*a[7]-a[4]*a[6],a[1]*a[6]-a[0]*a[7],a[0]*a[4]-a[1]*a[3]).scaleEqual(o),this.velx=this.p2.x-this.p1.x,this.vely=this.p2.y-this.p1.y,this.velz=this.p2.z-this.p1.z;var n=g.sqrt(this.velx*this.velx+this.vely*this.vely+this.velz*this.velz);n>.005?(n=(.005-n)/n*i*.05,this.velx*=n,this.vely*=n,this.velz*=n):(this.velx=0,this.vely=0,this.velz=0),this.impx*=.95,this.impy*=.95,this.impz*=.95,this.l1.x+=this.impx*this.m1,this.l1.y+=this.impy*this.m1,this.l1.z+=this.impz*this.m1,this.a1.x+=this.impx*this.ax1x+this.impy*this.ay1x+this.impz*this.az1x,this.a1.y+=this.impx*this.ax1y+this.impy*this.ay1y+this.impz*this.az1y,this.a1.z+=this.impx*this.ax1z+this.impy*this.ay1z+this.impz*this.az1z,this.l2.x-=this.impx*this.m2,this.l2.y-=this.impy*this.m2,this.l2.z-=this.impz*this.m2,this.a2.x-=this.impx*this.ax2x+this.impy*this.ay2x+this.impz*this.az2x,this.a2.y-=this.impx*this.ax2y+this.impy*this.ay2y+this.impz*this.az2y,this.a2.z-=this.impx*this.ax2z+this.impy*this.ay2z+this.impz*this.az2z},solve:function(){var t=this.dd.elements,i=this.l2.x-this.l1.x+this.a2.y*this.r2z-this.a2.z*this.r2y-this.a1.y*this.r1z+this.a1.z*this.r1y-this.velx,s=this.l2.y-this.l1.y+this.a2.z*this.r2x-this.a2.x*this.r2z-this.a1.z*this.r1x+this.a1.x*this.r1z-this.vely,h=this.l2.z-this.l1.z+this.a2.x*this.r2y-this.a2.y*this.r2x-this.a1.x*this.r1y+this.a1.y*this.r1x-this.velz,e=i*t[0]+s*t[1]+h*t[2],a=i*t[3]+s*t[4]+h*t[5],o=i*t[6]+s*t[7]+h*t[8];this.impx+=e,this.impy+=a,this.impz+=o,this.l1.x+=e*this.m1,this.l1.y+=a*this.m1,this.l1.z+=o*this.m1,this.a1.x+=e*this.ax1x+a*this.ay1x+o*this.az1x,this.a1.y+=e*this.ax1y+a*this.ay1y+o*this.az1y,this.a1.z+=e*this.ax1z+a*this.ay1z+o*this.az1z,this.l2.x-=e*this.m2,this.l2.y-=a*this.m2,this.l2.z-=o*this.m2,this.a2.x-=e*this.ax2x+a*this.ay2x+o*this.az2x,this.a2.y-=e*this.ax2y+a*this.ay2y+o*this.az2y,this.a2.z-=e*this.ax2z+a*this.ay2z+o*this.az2z}}),Object.assign(W.prototype,{Rotational3Constraint:!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=this.maxMotorForce1>0,this.lowerLimit2=this.limitMotor2.lowerLimit,this.upperLimit2=this.limitMotor2.upperLimit,this.motorSpeed2=this.limitMotor2.motorSpeed,this.maxMotorForce2=this.limitMotor2.maxMotorForce,this.enableMotor2=this.maxMotorForce2>0,this.lowerLimit3=this.limitMotor3.lowerLimit,this.upperLimit3=this.limitMotor3.upperLimit,this.motorSpeed3=this.limitMotor3.motorSpeed,this.maxMotorForce3=this.limitMotor3.maxMotorForce,this.enableMotor3=this.maxMotorForce3>0;var s=this.i1.elements,h=this.i2.elements;this.i1e00=s[0],this.i1e01=s[1],this.i1e02=s[2],this.i1e10=s[3],this.i1e11=s[4],this.i1e12=s[5],this.i1e20=s[6],this.i1e21=s[7],this.i1e22=s[8],this.i2e00=h[0],this.i2e01=h[1],this.i2e02=h[2],this.i2e10=h[3],this.i2e11=h[4],this.i2e12=h[5],this.i2e20=h[6],this.i2e21=h[7],this.i2e22=h[8];var e=this.limitMotor1.frequency,a=this.limitMotor2.frequency,o=this.limitMotor3.frequency,n=e>0,r=a>0,l=o>0,c=this.lowerLimit1<=this.upperLimit1,m=this.lowerLimit2<=this.upperLimit2,p=this.lowerLimit3<=this.upperLimit3,u=this.limitMotor1.angle;c?(this.lowerLimit1==this.upperLimit1?(0!=this.limitState1&&(this.limitState1=0,this.limitImpulse1=0),this.limitVelocity1=this.lowerLimit1-u):uthis.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||(this.limitVelocity1>.02?this.limitVelocity1-=.02:this.limitVelocity1<-.02?this.limitVelocity1+=.02:this.limitVelocity1=0)):(this.limitState1=2,this.limitImpulse1=0);var y=this.limitMotor2.angle;m?(this.lowerLimit2==this.upperLimit2?(0!=this.limitState2&&(this.limitState2=0,this.limitImpulse2=0),this.limitVelocity2=this.lowerLimit2-y):ythis.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||(this.limitVelocity2>.02?this.limitVelocity2-=.02:this.limitVelocity2<-.02?this.limitVelocity2+=.02:this.limitVelocity2=0)):(this.limitState2=2,this.limitImpulse2=0);var x=this.limitMotor3.angle;if(p?(this.lowerLimit3==this.upperLimit3?(0!=this.limitState3&&(this.limitState3=0,this.limitImpulse3=0),this.limitVelocity3=this.lowerLimit3-x):xthis.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||(this.limitVelocity3>.02?this.limitVelocity3-=.02:this.limitVelocity3<-.02?this.limitVelocity3+=.02:this.limitVelocity3=0)):(this.limitState3=2,this.limitImpulse3=0),this.enableMotor1&&(0!=this.limitState1||n)?this.maxMotorImpulse1=this.maxMotorForce1*t:(this.motorImpulse1=0,this.maxMotorImpulse1=0),this.enableMotor2&&(0!=this.limitState2||r)?this.maxMotorImpulse2=this.maxMotorForce2*t:(this.motorImpulse2=0,this.maxMotorImpulse2=0),this.enableMotor3&&(0!=this.limitState3||l)?this.maxMotorImpulse3=this.maxMotorForce3*t:(this.motorImpulse3=0,this.maxMotorImpulse3=0),this.a1x1=this.ax1*this.i1e00+this.ay1*this.i1e01+this.az1*this.i1e02,this.a1y1=this.ax1*this.i1e10+this.ay1*this.i1e11+this.az1*this.i1e12,this.a1z1=this.ax1*this.i1e20+this.ay1*this.i1e21+this.az1*this.i1e22,this.a2x1=this.ax1*this.i2e00+this.ay1*this.i2e01+this.az1*this.i2e02,this.a2y1=this.ax1*this.i2e10+this.ay1*this.i2e11+this.az1*this.i2e12,this.a2z1=this.ax1*this.i2e20+this.ay1*this.i2e21+this.az1*this.i2e22,this.a1x2=this.ax2*this.i1e00+this.ay2*this.i1e01+this.az2*this.i1e02,this.a1y2=this.ax2*this.i1e10+this.ay2*this.i1e11+this.az2*this.i1e12,this.a1z2=this.ax2*this.i1e20+this.ay2*this.i1e21+this.az2*this.i1e22,this.a2x2=this.ax2*this.i2e00+this.ay2*this.i2e01+this.az2*this.i2e02,this.a2y2=this.ax2*this.i2e10+this.ay2*this.i2e11+this.az2*this.i2e12,this.a2z2=this.ax2*this.i2e20+this.ay2*this.i2e21+this.az2*this.i2e22,this.a1x3=this.ax3*this.i1e00+this.ay3*this.i1e01+this.az3*this.i1e02,this.a1y3=this.ax3*this.i1e10+this.ay3*this.i1e11+this.az3*this.i1e12,this.a1z3=this.ax3*this.i1e20+this.ay3*this.i1e21+this.az3*this.i1e22,this.a2x3=this.ax3*this.i2e00+this.ay3*this.i2e01+this.az3*this.i2e02,this.a2y3=this.ax3*this.i2e10+this.ay3*this.i2e11+this.az3*this.i2e12,this.a2z3=this.ax3*this.i2e20+this.ay3*this.i2e21+this.az3*this.i2e22,this.k00=this.ax1*(this.a1x1+this.a2x1)+this.ay1*(this.a1y1+this.a2y1)+this.az1*(this.a1z1+this.a2z1),this.k01=this.ax1*(this.a1x2+this.a2x2)+this.ay1*(this.a1y2+this.a2y2)+this.az1*(this.a1z2+this.a2z2),this.k02=this.ax1*(this.a1x3+this.a2x3)+this.ay1*(this.a1y3+this.a2y3)+this.az1*(this.a1z3+this.a2z3),this.k10=this.ax2*(this.a1x1+this.a2x1)+this.ay2*(this.a1y1+this.a2y1)+this.az2*(this.a1z1+this.a2z1),this.k11=this.ax2*(this.a1x2+this.a2x2)+this.ay2*(this.a1y2+this.a2y2)+this.az2*(this.a1z2+this.a2z2),this.k12=this.ax2*(this.a1x3+this.a2x3)+this.ay2*(this.a1y3+this.a2y3)+this.az2*(this.a1z3+this.a2z3),this.k20=this.ax3*(this.a1x1+this.a2x1)+this.ay3*(this.a1y1+this.a2y1)+this.az3*(this.a1z1+this.a2z1),this.k21=this.ax3*(this.a1x2+this.a2x2)+this.ay3*(this.a1y2+this.a2y2)+this.az3*(this.a1z2+this.a2z2),this.k22=this.ax3*(this.a1x3+this.a2x3)+this.ay3*(this.a1y3+this.a2y3)+this.az3*(this.a1z3+this.a2z3),this.kv00=this.k00,this.kv11=this.k11,this.kv22=this.k22,this.dv00=1/this.kv00,this.dv11=1/this.kv11,this.dv22=1/this.kv22,n&&2!=this.limitState1){var d=6.2831853*e,f=d*d*t,b=i/(f+2*this.limitMotor1.dampingRatio*d);this.cfm1=this.kv00*b,this.limitVelocity1*=f*b}else this.cfm1=0,this.limitVelocity1*=.05*i;r&&2!=this.limitState2?(b=i/((f=(d=6.2831853*a)*d*t)+2*this.limitMotor2.dampingRatio*d),this.cfm2=this.kv11*b,this.limitVelocity2*=f*b):(this.cfm2=0,this.limitVelocity2*=.05*i),l&&2!=this.limitState3?(b=i/((f=(d=6.2831853*o)*d*t)+2*this.limitMotor3.dampingRatio*d),this.cfm3=this.kv22*b,this.limitVelocity3*=f*b):(this.cfm3=0,this.limitVelocity3*=.05*i),this.k00+=this.cfm1,this.k11+=this.cfm2,this.k22+=this.cfm3;var v=1/(this.k00*(this.k11*this.k22-this.k21*this.k12)+this.k10*(this.k21*this.k02-this.k01*this.k22)+this.k20*(this.k01*this.k12-this.k11*this.k02));this.d00=(this.k11*this.k22-this.k12*this.k21)*v,this.d01=(this.k02*this.k21-this.k01*this.k22)*v,this.d02=(this.k01*this.k12-this.k02*this.k11)*v,this.d10=(this.k12*this.k20-this.k10*this.k22)*v,this.d11=(this.k00*this.k22-this.k02*this.k20)*v,this.d12=(this.k02*this.k10-this.k00*this.k12)*v,this.d20=(this.k10*this.k21-this.k11*this.k20)*v,this.d21=(this.k01*this.k20-this.k00*this.k21)*v,this.d22=(this.k00*this.k11-this.k01*this.k10)*v,this.limitImpulse1*=.95,this.motorImpulse1*=.95,this.limitImpulse2*=.95,this.motorImpulse2*=.95,this.limitImpulse3*=.95,this.motorImpulse3*=.95;var z=this.limitImpulse1+this.motorImpulse1,N=this.limitImpulse2+this.motorImpulse2,k=this.limitImpulse3+this.motorImpulse3;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},solve_:function(){var t=this.a2.x-this.a1.x,i=this.a2.y-this.a1.y,s=this.a2.z-this.a1.z;this.limitVelocity3=30;var h=t*this.ax1+i*this.ay1+s*this.az1-this.limitVelocity1,e=t*this.ax2+i*this.ay2+s*this.az2-this.limitVelocity2,a=t*this.ax3+i*this.ay3+s*this.az3-this.limitVelocity3,o=h*this.d00+e*this.d01+a*this.d02,n=h*this.d10+e*this.d11+a*this.d12,r=h*this.d20+e*this.d21+a*this.d22;this.limitImpulse1+=o,this.limitImpulse2+=n,this.limitImpulse3+=r,this.a1.x+=o*this.a1x1+n*this.a1x2+r*this.a1x3,this.a1.y+=o*this.a1y1+n*this.a1y2+r*this.a1y3,this.a1.z+=o*this.a1z1+n*this.a1z2+r*this.a1z3,this.a2.x-=o*this.a2x1+n*this.a2x2+r*this.a2x3,this.a2.y-=o*this.a2y1+n*this.a2y2+r*this.a2y3,this.a2.z-=o*this.a2z1+n*this.a2z2+r*this.a2z3},solve:function(){var t=this.a2.x-this.a1.x,i=this.a2.y-this.a1.y,s=this.a2.z-this.a1.z,h=t*this.ax1+i*this.ay1+s*this.az1,e=t*this.ax2+i*this.ay2+s*this.az2,a=t*this.ax3+i*this.ay3+s*this.az3,o=this.motorImpulse1,n=this.motorImpulse2,r=this.motorImpulse3,l=0,c=0,m=0;this.enableMotor1&&(l=(h-this.motorSpeed1)*this.dv00,this.motorImpulse1+=l,this.motorImpulse1>this.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}}),H.prototype=Object.assign(Object.create(_.prototype),{constructor:H,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=g.acosClamp(g.dotVectors(this.an1,this.an2));this.tmp.crossVectors(this.an1,this.an2),g.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=g.dotVectors(this.tan,this.tmp),this.r3.limitMotor3.angle=g.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(){}}),Q.prototype=Object.assign(Object.create(_.prototype),{constructor:Q,preSolve:function(t,i){this.updateAnchorPoints(),this.lc.preSolve(t,i)},solve:function(){this.lc.solve()},postSolve:function(){}}),Object.assign(X.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=this.maxMotorForce>0,this.m1=this.b1.inverseMass,this.m2=this.b2.inverseMass;var s=this.i1.elements,h=this.i2.elements;this.i1e00=s[0],this.i1e01=s[1],this.i1e02=s[2],this.i1e10=s[3],this.i1e11=s[4],this.i1e12=s[5],this.i1e20=s[6],this.i1e21=s[7],this.i1e22=s[8],this.i2e00=h[0],this.i2e01=h[1],this.i2e02=h[2],this.i2e10=h[3],this.i2e11=h[4],this.i2e12=h[5],this.i2e20=h[6],this.i2e21=h[7],this.i2e22=h[8];var e=this.p2.x-this.p1.x,a=this.p2.y-this.p1.y,o=this.p2.z-this.p1.z,n=e*this.ax+a*this.ay+o*this.az,r=this.limitMotor.frequency,l=r>0;(l&&n>20||n<-20)&&(l=!1),this.lowerLimit<=this.upperLimit?(this.lowerLimit==this.upperLimit?(0!=this.limitState&&(this.limitState=0,this.limitImpulse=0),this.limitVelocity=this.lowerLimit-n,l||(n=this.lowerLimit)):nthis.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||(this.limitVelocity>.005?this.limitVelocity-=.005:this.limitVelocity<-.005?this.limitVelocity+=.005:this.limitVelocity=0)):(this.limitState=2,this.limitImpulse=0),this.enableMotor&&(0!=this.limitState||l)?this.maxMotorImpulse=this.maxMotorForce*t:(this.motorImpulse=0,this.maxMotorImpulse=0);var c=n*this.ax,m=n*this.ay,p=n*this.az,u=this.m1/(this.m1+this.m2),y=1-u;if(this.r1x=this.r1.x+c*u,this.r1y=this.r1.y+m*u,this.r1z=this.r1.z+p*u,this.r2x=this.r2.x-c*y,this.r2y=this.r2.y-m*y,this.r2z=this.r2.z-p*y,this.t1x=this.r1y*this.az-this.r1z*this.ay,this.t1y=this.r1z*this.ax-this.r1x*this.az,this.t1z=this.r1x*this.ay-this.r1y*this.ax,this.t2x=this.r2y*this.az-this.r2z*this.ay,this.t2y=this.r2z*this.ax-this.r2x*this.az,this.t2z=this.r2x*this.ay-this.r2y*this.ax,this.l1x=this.ax*this.m1,this.l1y=this.ay*this.m1,this.l1z=this.az*this.m1,this.l2x=this.ax*this.m2,this.l2y=this.ay*this.m2,this.l2z=this.az*this.m2,this.a1x=this.t1x*this.i1e00+this.t1y*this.i1e01+this.t1z*this.i1e02,this.a1y=this.t1x*this.i1e10+this.t1y*this.i1e11+this.t1z*this.i1e12,this.a1z=this.t1x*this.i1e20+this.t1y*this.i1e21+this.t1z*this.i1e22,this.a2x=this.t2x*this.i2e00+this.t2y*this.i2e01+this.t2z*this.i2e02,this.a2y=this.t2x*this.i2e10+this.t2y*this.i2e11+this.t2z*this.i2e12,this.a2z=this.t2x*this.i2e20+this.t2y*this.i2e21+this.t2z*this.i2e22,this.motorDenom=this.m1+this.m2+this.ax*(this.a1y*this.r1z-this.a1z*this.r1y+this.a2y*this.r2z-this.a2z*this.r2y)+this.ay*(this.a1z*this.r1x-this.a1x*this.r1z+this.a2z*this.r2x-this.a2x*this.r2z)+this.az*(this.a1x*this.r1y-this.a1y*this.r1x+this.a2x*this.r2y-this.a2y*this.r2x),this.invMotorDenom=1/this.motorDenom,l&&2!=this.limitState){var x=6.2831853*r,d=x*x*t,f=i/(d+2*this.limitMotor.dampingRatio*x);this.cfm=this.motorDenom*f,this.limitVelocity*=d*f}else this.cfm=0,this.limitVelocity*=.05*i;this.invDenom=1/(this.motorDenom+this.cfm);var b=this.limitImpulse+this.motorImpulse;this.l1.x+=b*this.l1x,this.l1.y+=b*this.l1y,this.l1.z+=b*this.l1z,this.a1.x+=b*this.a1x,this.a1.y+=b*this.a1y,this.a1.z+=b*this.a1z,this.l2.x-=b*this.l2x,this.l2.y-=b*this.l2y,this.l2.z-=b*this.l2z,this.a2.x-=b*this.a2x,this.a2.y-=b*this.a2y,this.a2.z-=b*this.a2z},solve:function(){var t,i,s=this.ax*(this.l2.x-this.l1.x)+this.ay*(this.l2.y-this.l1.y)+this.az*(this.l2.z-this.l1.z)+this.t2x*this.a2.x-this.t1x*this.a1.x+this.t2y*this.a2.y-this.t1y*this.a1.y+this.t2z*this.a2.z-this.t1z*this.a1.z;if(this.enableMotor){t=(s-this.motorSpeed)*this.invMotorDenom;var h=this.motorImpulse;this.motorImpulse+=t,this.motorImpulse>this.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}}),Y.prototype=Object.assign(Object.create(_.prototype),{constructor:Y,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(Z.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 P).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 P).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),(h=this.vel.length())>.02?(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(K.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=this.maxMotorForce1>0,this.lowerLimit2=this.limitMotor2.lowerLimit,this.upperLimit2=this.limitMotor2.upperLimit,this.motorSpeed2=this.limitMotor2.motorSpeed,this.maxMotorForce2=this.limitMotor2.maxMotorForce,this.enableMotor2=this.maxMotorForce2>0,this.lowerLimit3=this.limitMotor3.lowerLimit,this.upperLimit3=this.limitMotor3.upperLimit,this.motorSpeed3=this.limitMotor3.motorSpeed,this.maxMotorForce3=this.limitMotor3.maxMotorForce,this.enableMotor3=this.maxMotorForce3>0,this.m1=this.b1.inverseMass,this.m2=this.b2.inverseMass;var s=this.i1.elements,h=this.i2.elements;this.i1e00=s[0],this.i1e01=s[1],this.i1e02=s[2],this.i1e10=s[3],this.i1e11=s[4],this.i1e12=s[5],this.i1e20=s[6],this.i1e21=s[7],this.i1e22=s[8],this.i2e00=h[0],this.i2e01=h[1],this.i2e02=h[2],this.i2e10=h[3],this.i2e11=h[4],this.i2e12=h[5],this.i2e20=h[6],this.i2e21=h[7],this.i2e22=h[8];var e=this.p2.x-this.p1.x,a=this.p2.y-this.p1.y,o=this.p2.z-this.p1.z,n=e*this.ax1+a*this.ay1+o*this.az1,r=e*this.ax2+a*this.ay2+o*this.az2,l=e*this.ax3+a*this.ay3+o*this.az3,c=this.limitMotor1.frequency,m=this.limitMotor2.frequency,p=this.limitMotor3.frequency,u=c>0,y=m>0,x=p>0,d=this.lowerLimit1<=this.upperLimit1,f=this.lowerLimit2<=this.upperLimit2,b=this.lowerLimit3<=this.upperLimit3;(u&&n>20||n<-20)&&(u=!1),(y&&r>20||r<-20)&&(y=!1),(x&&l>20||l<-20)&&(x=!1),d?(this.lowerLimit1==this.upperLimit1?(0!=this.limitState1&&(this.limitState1=0,this.limitImpulse1=0),this.limitVelocity1=this.lowerLimit1-n,u||(n=this.lowerLimit1)):nthis.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||(this.limitVelocity1>.005?this.limitVelocity1-=.005:this.limitVelocity1<-.005?this.limitVelocity1+=.005:this.limitVelocity1=0)):(this.limitState1=2,this.limitImpulse1=0),f?(this.lowerLimit2==this.upperLimit2?(0!=this.limitState2&&(this.limitState2=0,this.limitImpulse2=0),this.limitVelocity2=this.lowerLimit2-r,y||(r=this.lowerLimit2)):rthis.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||(this.limitVelocity2>.005?this.limitVelocity2-=.005:this.limitVelocity2<-.005?this.limitVelocity2+=.005:this.limitVelocity2=0)):(this.limitState2=2,this.limitImpulse2=0),b?(this.lowerLimit3==this.upperLimit3?(0!=this.limitState3&&(this.limitState3=0,this.limitImpulse3=0),this.limitVelocity3=this.lowerLimit3-l,x||(l=this.lowerLimit3)):lthis.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||(this.limitVelocity3>.005?this.limitVelocity3-=.005:this.limitVelocity3<-.005?this.limitVelocity3+=.005:this.limitVelocity3=0)):(this.limitState3=2,this.limitImpulse3=0),this.enableMotor1&&(0!=this.limitState1||u)?this.maxMotorImpulse1=this.maxMotorForce1*t:(this.motorImpulse1=0,this.maxMotorImpulse1=0),this.enableMotor2&&(0!=this.limitState2||y)?this.maxMotorImpulse2=this.maxMotorForce2*t:(this.motorImpulse2=0,this.maxMotorImpulse2=0),this.enableMotor3&&(0!=this.limitState3||x)?this.maxMotorImpulse3=this.maxMotorForce3*t:(this.motorImpulse3=0,this.maxMotorImpulse3=0);var v=n*this.ax1+r*this.ax2+l*this.ax2,z=n*this.ay1+r*this.ay2+l*this.ay2,N=n*this.az1+r*this.az2+l*this.az2,k=this.m2/(this.m1+this.m2);this.weight>=0&&(k=this.weight);var w=1-k;this.r1x=this.r1.x+v*k,this.r1y=this.r1.y+z*k,this.r1z=this.r1.z+N*k,this.r2x=this.r2.x-v*w,this.r2y=this.r2.y-z*w,this.r2z=this.r2.z-N*w,this.t1x1=this.r1y*this.az1-this.r1z*this.ay1,this.t1y1=this.r1z*this.ax1-this.r1x*this.az1,this.t1z1=this.r1x*this.ay1-this.r1y*this.ax1,this.t2x1=this.r2y*this.az1-this.r2z*this.ay1,this.t2y1=this.r2z*this.ax1-this.r2x*this.az1,this.t2z1=this.r2x*this.ay1-this.r2y*this.ax1,this.l1x1=this.ax1*this.m1,this.l1y1=this.ay1*this.m1,this.l1z1=this.az1*this.m1,this.l2x1=this.ax1*this.m2,this.l2y1=this.ay1*this.m2,this.l2z1=this.az1*this.m2,this.a1x1=this.t1x1*this.i1e00+this.t1y1*this.i1e01+this.t1z1*this.i1e02,this.a1y1=this.t1x1*this.i1e10+this.t1y1*this.i1e11+this.t1z1*this.i1e12,this.a1z1=this.t1x1*this.i1e20+this.t1y1*this.i1e21+this.t1z1*this.i1e22,this.a2x1=this.t2x1*this.i2e00+this.t2y1*this.i2e01+this.t2z1*this.i2e02,this.a2y1=this.t2x1*this.i2e10+this.t2y1*this.i2e11+this.t2z1*this.i2e12,this.a2z1=this.t2x1*this.i2e20+this.t2y1*this.i2e21+this.t2z1*this.i2e22,this.t1x2=this.r1y*this.az2-this.r1z*this.ay2,this.t1y2=this.r1z*this.ax2-this.r1x*this.az2,this.t1z2=this.r1x*this.ay2-this.r1y*this.ax2,this.t2x2=this.r2y*this.az2-this.r2z*this.ay2,this.t2y2=this.r2z*this.ax2-this.r2x*this.az2,this.t2z2=this.r2x*this.ay2-this.r2y*this.ax2,this.l1x2=this.ax2*this.m1,this.l1y2=this.ay2*this.m1,this.l1z2=this.az2*this.m1,this.l2x2=this.ax2*this.m2,this.l2y2=this.ay2*this.m2,this.l2z2=this.az2*this.m2,this.a1x2=this.t1x2*this.i1e00+this.t1y2*this.i1e01+this.t1z2*this.i1e02,this.a1y2=this.t1x2*this.i1e10+this.t1y2*this.i1e11+this.t1z2*this.i1e12,this.a1z2=this.t1x2*this.i1e20+this.t1y2*this.i1e21+this.t1z2*this.i1e22,this.a2x2=this.t2x2*this.i2e00+this.t2y2*this.i2e01+this.t2z2*this.i2e02,this.a2y2=this.t2x2*this.i2e10+this.t2y2*this.i2e11+this.t2z2*this.i2e12,this.a2z2=this.t2x2*this.i2e20+this.t2y2*this.i2e21+this.t2z2*this.i2e22,this.t1x3=this.r1y*this.az3-this.r1z*this.ay3,this.t1y3=this.r1z*this.ax3-this.r1x*this.az3,this.t1z3=this.r1x*this.ay3-this.r1y*this.ax3,this.t2x3=this.r2y*this.az3-this.r2z*this.ay3,this.t2y3=this.r2z*this.ax3-this.r2x*this.az3,this.t2z3=this.r2x*this.ay3-this.r2y*this.ax3,this.l1x3=this.ax3*this.m1,this.l1y3=this.ay3*this.m1,this.l1z3=this.az3*this.m1,this.l2x3=this.ax3*this.m2,this.l2y3=this.ay3*this.m2,this.l2z3=this.az3*this.m2,this.a1x3=this.t1x3*this.i1e00+this.t1y3*this.i1e01+this.t1z3*this.i1e02,this.a1y3=this.t1x3*this.i1e10+this.t1y3*this.i1e11+this.t1z3*this.i1e12,this.a1z3=this.t1x3*this.i1e20+this.t1y3*this.i1e21+this.t1z3*this.i1e22,this.a2x3=this.t2x3*this.i2e00+this.t2y3*this.i2e01+this.t2z3*this.i2e02,this.a2y3=this.t2x3*this.i2e10+this.t2y3*this.i2e11+this.t2z3*this.i2e12,this.a2z3=this.t2x3*this.i2e20+this.t2y3*this.i2e21+this.t2z3*this.i2e22;var M=this.m1+this.m2;if(this.k00=(this.ax1*this.ax1+this.ay1*this.ay1+this.az1*this.az1)*M,this.k01=(this.ax1*this.ax2+this.ay1*this.ay2+this.az1*this.az2)*M,this.k02=(this.ax1*this.ax3+this.ay1*this.ay3+this.az1*this.az3)*M,this.k10=(this.ax2*this.ax1+this.ay2*this.ay1+this.az2*this.az1)*M,this.k11=(this.ax2*this.ax2+this.ay2*this.ay2+this.az2*this.az2)*M,this.k12=(this.ax2*this.ax3+this.ay2*this.ay3+this.az2*this.az3)*M,this.k20=(this.ax3*this.ax1+this.ay3*this.ay1+this.az3*this.az1)*M,this.k21=(this.ax3*this.ax2+this.ay3*this.ay2+this.az3*this.az2)*M,this.k22=(this.ax3*this.ax3+this.ay3*this.ay3+this.az3*this.az3)*M,this.k00+=this.t1x1*this.a1x1+this.t1y1*this.a1y1+this.t1z1*this.a1z1,this.k01+=this.t1x1*this.a1x2+this.t1y1*this.a1y2+this.t1z1*this.a1z2,this.k02+=this.t1x1*this.a1x3+this.t1y1*this.a1y3+this.t1z1*this.a1z3,this.k10+=this.t1x2*this.a1x1+this.t1y2*this.a1y1+this.t1z2*this.a1z1,this.k11+=this.t1x2*this.a1x2+this.t1y2*this.a1y2+this.t1z2*this.a1z2,this.k12+=this.t1x2*this.a1x3+this.t1y2*this.a1y3+this.t1z2*this.a1z3,this.k20+=this.t1x3*this.a1x1+this.t1y3*this.a1y1+this.t1z3*this.a1z1,this.k21+=this.t1x3*this.a1x2+this.t1y3*this.a1y2+this.t1z3*this.a1z2,this.k22+=this.t1x3*this.a1x3+this.t1y3*this.a1y3+this.t1z3*this.a1z3,this.k00+=this.t2x1*this.a2x1+this.t2y1*this.a2y1+this.t2z1*this.a2z1,this.k01+=this.t2x1*this.a2x2+this.t2y1*this.a2y2+this.t2z1*this.a2z2,this.k02+=this.t2x1*this.a2x3+this.t2y1*this.a2y3+this.t2z1*this.a2z3,this.k10+=this.t2x2*this.a2x1+this.t2y2*this.a2y1+this.t2z2*this.a2z1,this.k11+=this.t2x2*this.a2x2+this.t2y2*this.a2y2+this.t2z2*this.a2z2,this.k12+=this.t2x2*this.a2x3+this.t2y2*this.a2y3+this.t2z2*this.a2z3,this.k20+=this.t2x3*this.a2x1+this.t2y3*this.a2y1+this.t2z3*this.a2z1,this.k21+=this.t2x3*this.a2x2+this.t2y3*this.a2y2+this.t2z3*this.a2z2,this.k22+=this.t2x3*this.a2x3+this.t2y3*this.a2y3+this.t2z3*this.a2z3,this.kv00=this.k00,this.kv11=this.k11,this.kv22=this.k22,this.dv00=1/this.kv00,this.dv11=1/this.kv11,this.dv22=1/this.kv22,u&&2!=this.limitState1){var g=6.2831853*c,I=g*g*t,V=i/(I+2*this.limitMotor1.dampingRatio*g);this.cfm1=this.kv00*V,this.limitVelocity1*=I*V}else this.cfm1=0,this.limitVelocity1*=.05*i;y&&2!=this.limitState2?(V=i/((I=(g=6.2831853*m)*g*t)+2*this.limitMotor2.dampingRatio*g),this.cfm2=this.kv11*V,this.limitVelocity2*=I*V):(this.cfm2=0,this.limitVelocity2*=.05*i),x&&2!=this.limitState3?(V=i/((I=(g=6.2831853*p)*g*t)+2*this.limitMotor3.dampingRatio*g),this.cfm3=this.kv22*V,this.limitVelocity3*=I*V):(this.cfm3=0,this.limitVelocity3*=.05*i),this.k00+=this.cfm1,this.k11+=this.cfm2,this.k22+=this.cfm3;var L=1/(this.k00*(this.k11*this.k22-this.k21*this.k12)+this.k10*(this.k21*this.k02-this.k01*this.k22)+this.k20*(this.k01*this.k12-this.k11*this.k02));this.d00=(this.k11*this.k22-this.k12*this.k21)*L,this.d01=(this.k02*this.k21-this.k01*this.k22)*L,this.d02=(this.k01*this.k12-this.k02*this.k11)*L,this.d10=(this.k12*this.k20-this.k10*this.k22)*L,this.d11=(this.k00*this.k22-this.k02*this.k20)*L,this.d12=(this.k02*this.k10-this.k00*this.k12)*L,this.d20=(this.k10*this.k21-this.k11*this.k20)*L,this.d21=(this.k01*this.k20-this.k00*this.k21)*L,this.d22=(this.k00*this.k11-this.k01*this.k10)*L;var S=this.limitImpulse1+this.motorImpulse1,P=this.limitImpulse2+this.motorImpulse2,T=this.limitImpulse3+this.motorImpulse3;this.l1.x+=S*this.l1x1+P*this.l1x2+T*this.l1x3,this.l1.y+=S*this.l1y1+P*this.l1y2+T*this.l1y3,this.l1.z+=S*this.l1z1+P*this.l1z2+T*this.l1z3,this.a1.x+=S*this.a1x1+P*this.a1x2+T*this.a1x3,this.a1.y+=S*this.a1y1+P*this.a1y2+T*this.a1y3,this.a1.z+=S*this.a1z1+P*this.a1z2+T*this.a1z3,this.l2.x-=S*this.l2x1+P*this.l2x2+T*this.l2x3,this.l2.y-=S*this.l2y1+P*this.l2y2+T*this.l2y3,this.l2.z-=S*this.l2z1+P*this.l2z2+T*this.l2z3,this.a2.x-=S*this.a2x1+P*this.a2x2+T*this.a2x3,this.a2.y-=S*this.a2y1+P*this.a2y2+T*this.a2y3,this.a2.z-=S*this.a2z1+P*this.a2z2+T*this.a2z3},solve:function(){var t=this.l2.x-this.l1.x+this.a2.y*this.r2z-this.a2.z*this.r2y-this.a1.y*this.r1z+this.a1.z*this.r1y,i=this.l2.y-this.l1.y+this.a2.z*this.r2x-this.a2.x*this.r2z-this.a1.z*this.r1x+this.a1.x*this.r1z,s=this.l2.z-this.l1.z+this.a2.x*this.r2y-this.a2.y*this.r2x-this.a1.x*this.r1y+this.a1.y*this.r1x,h=t*this.ax1+i*this.ay1+s*this.az1,e=t*this.ax2+i*this.ay2+s*this.az2,a=t*this.ax3+i*this.ay3+s*this.az3,o=this.motorImpulse1,n=this.motorImpulse2,r=this.motorImpulse3,l=0,c=0,m=0;this.enableMotor1&&(l=(h-this.motorSpeed1)*this.dv00,this.motorImpulse1+=l,this.motorImpulse1>this.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}}),G.prototype=Object.assign(Object.create(_.prototype),{constructor:G,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(){}}),$.prototype=Object.assign(Object.create(_.prototype),{constructor:$,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=g.acosClamp(g.dotVectors(this.an1,this.an2));g.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=g.dotVectors(this.tan,this.tmp),this.r3.limitMotor3.angle=g.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(){}}),tt.prototype=Object.assign(Object.create(_.prototype),{constructor:tt,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=g.dotVectors(this.ax1,this.ax2);var s=g.dotVectors(this.an1,this.ax2);g.dotVectors(this.ax1,this.tmp.crossVectors(this.an1,this.ax2))<0?this.rotationalLimitMotor1.angle=-s:this.rotationalLimitMotor1.angle=s,s=g.dotVectors(this.an2,this.ax1),g.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(){}}),ot.prototype={constructor:ot,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}},rt.prototype=Object.assign(Object.create(U.prototype),{constructor:rt,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&&(e=0),(o=this.restitution*-e)<(n=-(h.penetration+.005)*i*.05)&&(o=n),c.norTar=o,c.last=m==this.num-1,c=c.next},solve:function(){var t,i,s,h,e,a,o,n,r;this.tmplv1.copy(this.lv1),this.tmplv2.copy(this.lv2),this.tmpav1.copy(this.av1),this.tmpav2.copy(this.av2);for(var l=this.cs;e=l.norImp,a=l.tanImp,o=l.binImp,n=-e*this.friction,this.tmp.sub(this.tmplv2,this.tmplv1),t=a,s=o,(r=(a+=i=(g.dotVectors(this.tmp,l.tan)+g.dotVectors(this.tmpav2,l.tanT2)-g.dotVectors(this.tmpav1,l.tanT1))*l.tanDen)*a+(o+=h=(g.dotVectors(this.tmp,l.bin)+g.dotVectors(this.tmpav2,l.binT2)-g.dotVectors(this.tmpav1,l.binT1))*l.binDen)*o)>n*n&&(a*=r=n/g.sqrt(r),o*=r),i=a-t,h=o-s,this.tmp.set(l.tanU1.x*i+l.binU1.x*h,l.tanU1.y*i+l.binU1.y*h,l.tanU1.z*i+l.binU1.z*h),this.tmplv1.addEqual(this.tmp),this.tmp.set(l.tanTU1.x*i+l.binTU1.x*h,l.tanTU1.y*i+l.binTU1.y*h,l.tanTU1.z*i+l.binTU1.z*h),this.tmpav1.addEqual(this.tmp),this.tmp.set(l.tanU2.x*i+l.binU2.x*h,l.tanU2.y*i+l.binU2.y*h,l.tanU2.z*i+l.binU2.z*h),this.tmplv2.subEqual(this.tmp),this.tmp.set(l.tanTU2.x*i+l.binTU2.x*h,l.tanTU2.y*i+l.binTU2.y*h,l.tanTU2.z*i+l.binTU2.z*h),this.tmpav2.subEqual(this.tmp),this.tmp.sub(this.tmplv2,this.tmplv1),t=e,(e+=i=(g.dotVectors(this.tmp,l.nor)+g.dotVectors(this.tmpav2,l.norT2)-g.dotVectors(this.tmpav1,l.norT1)-l.norTar)*l.norDen)>0&&(e=0),i=e-t,this.tmplv1.addScaledVector(l.norU1,i),this.tmpav1.addScaledVector(l.norTU1,i),this.tmplv2.subScaledVector(l.norU2,i),this.tmpav2.subScaledVector(l.norTU2,i),l.norImp=e,l.tanImp=a,l.binImp=o,!l.last;)l=l.next;this.lv1.copy(this.tmplv1),this.lv2.copy(this.tmplv2),this.av1.copy(this.tmpav1),this.av2.copy(this.tmpav2)},postSolve:function(){for(var t,i=this.cs,s=this.num;s--;)(t=this.ps[s]).normal.copy(i.nor),t.tangent.copy(i.tan),t.binormal.copy(i.bin),t.normalImpulse=i.norImp,t.tangentImpulse=i.tanImp,t.binormalImpulse=i.binImp,t.normalDenominator=i.norDen,t.tangentDenominator=i.tanDen,t.binormalDenominator=i.binDen,i=i.next}}),Object.assign(lt.prototype,{Contact:!0,mixRestitution:function(t,i){return g.sqrt(t*i)},mixFriction:function(t,i){return g.sqrt(t*i)},updateManifold:function(){this.constraint.restitution=this.mixRestitution(this.shape1.restitution,this.shape2.restitution),this.constraint.friction=this.mixFriction(this.shape1.friction,this.shape2.friction);for(var t=this.manifold.numPoints,i=t;i--;){var s=this.buffer[i],h=this.points[i];s.lp1X=h.localPoint1.x,s.lp1Y=h.localPoint1.y,s.lp1Z=h.localPoint1.z,s.lp2X=h.localPoint2.x,s.lp2Y=h.localPoint2.y,s.lp2Z=h.localPoint2.z,s.impulse=h.normalImpulse}this.manifold.numPoints=0,this.detector.detectCollision(this.shape1,this.shape2,this.manifold);var e=this.manifold.numPoints;if(0==e)return this.touching=!1,this.close=!1,void(this.dist=g.INF);for((this.touching||this.dist<.001)&&(this.close=!0),this.touching=!0,i=e;i--;){for(var a=(h=this.points[i]).localPoint1.x,o=h.localPoint1.y,n=h.localPoint1.z,r=h.localPoint2.x,l=h.localPoint2.y,c=h.localPoint2.z,m=-1,p=4e-4,u=t;u--;){var y=(s=this.buffer[u]).lp1X-a,x=s.lp1Y-o,d=s.lp1Z-n,f=y*y+x*x+d*d,b=(y=s.lp2X-r)*y+(x=s.lp2Y-l)*x+(d=s.lp2Z-c)*d;f-1&&this.proxies.splice(i,1)},collectPairs:function(){var t,i,s,h=0,e=this.proxies,a=e.length;for(this.numPairChecks=a*(a-1)>>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,(t+=e-l)>i){s=!0;break}}}if(s){t=2;var c=this.stack;for(c[0]=0,c[1]=this.numElements-1;t>0;){var m=c[--t],p=c[--t],u=m-p;if(u>16){var y=p+g.floor(.5*u);for(o=h[y],h[y]=h[m],h[m]=o,n=o.value,e=p-1,l=m;;){var x,d;do{x=h[++e]}while(x.value=l)break;h[e]=d,h[l]=x}h[m]=h[e],h[e]=o,e-p>m-e?(c[t++]=p,c[t++]=e-1,c[t++]=e+1,c[t++]=m):(c[t++]=e+1,c[t++]=m,c[t++]=p,c[t++]=e-1)}else for(e=p+1;e<=m;e++)if(n=(o=h[e]).value,(r=h[e-1]).value>n){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||f0?this.freeNodes[--this.numFreeNodes]:new Nt).parent=x,y.child1=t,y.child2=e,y.aabb.combine(t.aabb,e.aabb),y.height=e.height+1,e.parent=y,t.parent=y,e==this.root?this.root=y:x.child1==e?x.child1=y:x.child2=y;do{y=this.balance(y),this.fix(y),y=y.parent}while(null!=y)}else this.root=t},getBalance:function(t){return null!=t.proxy?0:t.child1.height-t.child2.height},deleteLeaf:function(t){if(t!=this.root){var i,s=t.parent;if(i=s.child1==t?s.child2:s.child1,s==this.root)return this.root=i,void(i.parent=null);var h=s.parent;i.parent=h,h.child1==s?h.child1=i:h.child2=i,this.numFreeNodes<16384&&(this.freeNodes[this.numFreeNodes++]=s);do{h=this.balance(h),this.fix(h),h=h.parent}while(null!=h)}else this.root=null},balance:function(t){var i=t.height;if(i<2)return t;var s,h=t.parent,e=t.child1,a=t.child2,o=e.height,n=a.height,r=o-n;if(r>1){var l=e.child1,c=e.child2,m=l.height,p=c.height;return m>p?(e.child2=t,t.parent=e,t.child1=c,c.parent=t,t.aabb.combine(c.aabb,a.aabb),s=p-n,t.height=p-(s&s>>31)+1,e.aabb.combine(l.aabb,t.aabb),s=m-i,e.height=m-(s&s>>31)+1):(e.child1=t,t.parent=e,t.child1=l,l.parent=t,t.aabb.combine(l.aabb,a.aabb),s=m-n,t.height=m-(s&s>>31)+1,e.aabb.combine(t.aabb,c.aabb),s=i-p,e.height=i-(s&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 x>d?(a.child2=t,t.parent=a,t.child2=y,y.parent=t,t.aabb.combine(e.aabb,y.aabb),s=o-d,t.height=o-(s&s>>31)+1,a.aabb.combine(u.aabb,t.aabb),s=x-i,a.height=x-(s&s>>31)+1):(a.child1=t,t.parent=a,t.child2=u,u.parent=t,t.aabb.combine(e.aabb,u.aabb),s=o-x,t.height=o-(s&s>>31)+1,a.aabb.combine(t.aabb,y.aabb),s=i-d,a.height=i-(s&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.height-1&&(this.leaves.splice(i,1),this.numLeaves--)},collectPairs:function(){if(!(this.numLeaves<2))for(var t,i=this.numLeaves;i--;)(t=this.leaves[i]).proxy.aabb.intersectTestTwo(t.aabb)&&(t.aabb.copy(t.proxy.aabb,.1),this.tree.deleteLeaf(t),this.tree.insertLeaf(t),this.collide(t,this.tree.root))},collide:function(t,i){var s,h,e,a,o,n,r=2;for(this.stack[0]=t,this.stack[1]=i;r>0;)if(e=this.stack[--r],a=this.stack[--r],o=null!=e.proxy,n=null!=a.proxy,this.numPairChecks++,o&&n){if((s=e.proxy.shape)==(h=a.proxy.shape)||s.aabb.intersectTest(h.aabb)||!this.isAvailablePair(s,h))continue;this.addPair(s,h)}else{if(e.aabb.intersectTest(a.aabb))continue;n||!o&&e.aabb.surfaceArea()>a.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(gt.prototype,{CollisionDetector:!0,detectCollision:function(t,i,s){I("CollisionDetector","Inheritance error.")}}),It.prototype=Object.assign(Object.create(gt.prototype),{constructor:It,detectCollision:function(t,i,s){var h,e;t.id0)||(D=-D),(B=rt*It+lt*Vt+ct*Lt)<0&&(B=-B),(F=rt*St+lt*Pt+ct*Tt)<0&&(F=-F),(q=rt*At+lt*jt+ct*Ct)<0&&(q=-q),!((z=D-(E=st)-(B*at+F*ot+q*nt))>0||((o=(D=mt*$+pt*tt+ut*it)>0)||(D=-D),(B=mt*It+pt*Vt+ut*Lt)<0&&(B=-B),(F=mt*St+pt*Pt+ut*Tt)<0&&(F=-F),(q=mt*At+pt*jt+ut*Ct)<0&&(q=-q),(N=D-(E=ht)-(B*at+F*ot+q*nt))>0||((n=(D=yt*$+xt*tt+dt*it)>0)||(D=-D),(B=yt*It+xt*Vt+dt*Lt)<0&&(B=-B),(F=yt*St+xt*Pt+dt*Tt)<0&&(F=-F),(q=yt*At+xt*jt+dt*Ct)<0&&(q=-q),(k=D-(E=et)-(B*at+F*ot+q*nt))>0||((r=(D=It*$+Vt*tt+Lt*it)>0)||(D=-D),(B=It*rt+Vt*lt+Lt*ct)<0&&(B=-B),(F=It*mt+Vt*pt+Lt*ut)<0&&(F=-F),(q=It*yt+Vt*xt+Lt*dt)<0&&(q=-q),(w=1*(D-(E=B*st+F*ht+q*et)-at))>0||((l=(D=St*$+Pt*tt+Tt*it)>0)||(D=-D),(B=St*rt+Pt*lt+Tt*ct)<0&&(B=-B),(F=St*mt+Pt*pt+Tt*ut)<0&&(F=-F),(q=St*yt+Pt*xt+Tt*dt)<0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))>0)return}else u=!1,S=0,vi=!0;if((D=$t*$t+ti*ti+ii*ii)>1e-5){if((y=(D=($t*=D=1/g.sqrt(D))*$+(ti*=D)*tt+(ii*=D)*it)>0)||(D=-D),(B=$t*rt+ti*lt+ii*ct)<0&&(B=-B),(F=$t*yt+ti*xt+ii*dt)<0&&(F=-F),E=B*st+F*et,(B=$t*St+ti*Pt+ii*Tt)<0&&(B=-B),(F=$t*At+ti*jt+ii*Ct)<0&&(F=-F),(P=D-E-(B*ot+F*nt))>0)return}else y=!1,P=0,zi=!0;if((D=si*si+hi*hi+ei*ei)>1e-5){if((x=(D=(si*=D=1/g.sqrt(D))*$+(hi*=D)*tt+(ei*=D)*it)>0)||(D=-D),(B=si*rt+hi*lt+ei*ct)<0&&(B=-B),(F=si*yt+hi*xt+ei*dt)<0&&(F=-F),E=B*st+F*et,(B=si*It+hi*Vt+ei*Lt)<0&&(B=-B),(F=si*At+hi*jt+ei*Ct)<0&&(F=-F),(T=D-E-(B*at+F*nt))>0)return}else x=!1,T=0,Ni=!0;if((D=ai*ai+oi*oi+ni*ni)>1e-5){if((d=(D=(ai*=D=1/g.sqrt(D))*$+(oi*=D)*tt+(ni*=D)*it)>0)||(D=-D),(B=ai*rt+oi*lt+ni*ct)<0&&(B=-B),(F=ai*yt+oi*xt+ni*dt)<0&&(F=-F),E=B*st+F*et,(B=ai*It+oi*Vt+ni*Lt)<0&&(B=-B),(F=ai*St+oi*Pt+ni*Tt)<0&&(F=-F),(A=D-E-(B*at+F*ot))>0)return}else d=!1,A=0,ki=!0;if((D=ri*ri+li*li+ci*ci)>1e-5){if((f=(D=(ri*=D=1/g.sqrt(D))*$+(li*=D)*tt+(ci*=D)*it)>0)||(D=-D),(B=ri*rt+li*lt+ci*ct)<0&&(B=-B),(F=ri*mt+li*pt+ci*ut)<0&&(F=-F),E=B*st+F*ht,(B=ri*St+li*Pt+ci*Tt)<0&&(B=-B),(F=ri*At+li*jt+ci*Ct)<0&&(F=-F),(j=D-E-(B*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]=Ms+(Vs-Ms)*os,Ns=3*zs,zs++,this.clipVertices2[Ns]=gs,this.clipVertices2[Ns+1]=Is,this.clipVertices2[Ns+2]=Vs),ks=gs,ws=Is,Ms=Vs,B=F;if(0!=(vs=zs)){for(zs=0,Ns=3*(vs-1),B=((ks=this.clipVertices2[Ns])-Fi-Wi)*Di+((ws=this.clipVertices2[Ns+1])-qi-Hi)*Ei+((Ms=this.clipVertices2[Ns+2])-Ui-Qi)*Bi,Ts=0;Ts0?F>0?(Ns=3*zs,zs++,this.clipVertices1[Ns]=gs,this.clipVertices1[Ns+1]=Is,this.clipVertices1[Ns+2]=Vs):(Ns=3*zs,zs++,os=B/(B-F),this.clipVertices1[Ns]=ks+(gs-ks)*os,this.clipVertices1[Ns+1]=ws+(Is-ws)*os,this.clipVertices1[Ns+2]=Ms+(Vs-Ms)*os):F>0&&(Ns=3*zs,zs++,os=B/(B-F),this.clipVertices1[Ns]=ks+(gs-ks)*os,this.clipVertices1[Ns+1]=ws+(Is-ws)*os,this.clipVertices1[Ns+2]=Ms+(Vs-Ms)*os,Ns=3*zs,zs++,this.clipVertices1[Ns]=gs,this.clipVertices1[Ns+1]=Is,this.clipVertices1[Ns+2]=Vs),ks=gs,ws=Is,Ms=Vs,B=F;if(0!=(vs=zs)){for(zs=0,Ns=3*(vs-1),B=((ks=this.clipVertices1[Ns])-Fi+Ri)*-ji+((ws=this.clipVertices1[Ns+1])-qi+_i)*-Ci+((Ms=this.clipVertices1[Ns+2])-Ui+Ji)*-Oi,Ts=0;Ts0?F>0?(Ns=3*zs,zs++,this.clipVertices2[Ns]=gs,this.clipVertices2[Ns+1]=Is,this.clipVertices2[Ns+2]=Vs):(Ns=3*zs,zs++,os=B/(B-F),this.clipVertices2[Ns]=ks+(gs-ks)*os,this.clipVertices2[Ns+1]=ws+(Is-ws)*os,this.clipVertices2[Ns+2]=Ms+(Vs-Ms)*os):F>0&&(Ns=3*zs,zs++,os=B/(B-F),this.clipVertices2[Ns]=ks+(gs-ks)*os,this.clipVertices2[Ns+1]=ws+(Is-ws)*os,this.clipVertices2[Ns+2]=Ms+(Vs-Ms)*os,Ns=3*zs,zs++,this.clipVertices2[Ns]=gs,this.clipVertices2[Ns+1]=Is,this.clipVertices2[Ns+2]=Vs),ks=gs,ws=Is,Ms=Vs,B=F;if(0!=(vs=zs)){for(zs=0,Ns=3*(vs-1),B=((ks=this.clipVertices2[Ns])-Fi+Wi)*-Di+((ws=this.clipVertices2[Ns+1])-qi+Hi)*-Ei+((Ms=this.clipVertices2[Ns+2])-Ui+Qi)*-Bi,Ts=0;Ts0?F>0?(Ns=3*zs,zs++,this.clipVertices1[Ns]=gs,this.clipVertices1[Ns+1]=Is,this.clipVertices1[Ns+2]=Vs):(Ns=3*zs,zs++,os=B/(B-F),this.clipVertices1[Ns]=ks+(gs-ks)*os,this.clipVertices1[Ns+1]=ws+(Is-ws)*os,this.clipVertices1[Ns+2]=Ms+(Vs-Ms)*os):F>0&&(Ns=3*zs,zs++,os=B/(B-F),this.clipVertices1[Ns]=ks+(gs-ks)*os,this.clipVertices1[Ns+1]=ws+(Is-ws)*os,this.clipVertices1[Ns+2]=Ms+(Vs-Ms)*os,Ns=3*zs,zs++,this.clipVertices1[Ns]=gs,this.clipVertices1[Ns+1]=Is,this.clipVertices1[Ns+2]=Vs),ks=gs,ws=Is,Ms=Vs,B=F;if(Xi){var As=h;h=e,e=As}if(0!=(vs=zs)){var js=h!=t;if(vs>4){ji=ns-(ks=.25*(ns+cs+us+ds)),Ci=rs-(ws=.25*(rs+ms+ys+fs)),Oi=ls-(Ms=.25*(ls+ps+xs+bs)),Di=cs-ks,Ei=ms-ws,Bi=ps-Ms;var Cs=0,Os=0,Ds=0,Es=0,Bs=-this.INF;for(Ls=this.INF,Ts=0;TsBs&&(Bs=Ss,Ds=Ts);for(this.used[Cs]=!0,this.used[Ds]=!0,Bs=-this.INF,Ls=this.INF,Ts=0;TsBs&&(Bs=Ss,Es=Ts));Ns=3*Cs,(Ss=((ks=this.clipVertices1[Ns])-Fi)*Pi+((ws=this.clipVertices1[Ns+1])-qi)*Ti+((Ms=this.clipVertices1[Ns+2])-Ui)*Ai)<0&&s.addPoint(ks,ws,Ms,Pi,Ti,Ai,Ss,js),Ns=3*Os,(Ss=((ks=this.clipVertices1[Ns])-Fi)*Pi+((ws=this.clipVertices1[Ns+1])-qi)*Ti+((Ms=this.clipVertices1[Ns+2])-Ui)*Ai)<0&&s.addPoint(ks,ws,Ms,Pi,Ti,Ai,Ss,js),Ns=3*Ds,(Ss=((ks=this.clipVertices1[Ns])-Fi)*Pi+((ws=this.clipVertices1[Ns+1])-qi)*Ti+((Ms=this.clipVertices1[Ns+2])-Ui)*Ai)<0&&s.addPoint(ks,ws,Ms,Pi,Ti,Ai,Ss,js),Ns=3*Es,(Ss=((ks=this.clipVertices1[Ns])-Fi)*Pi+((ws=this.clipVertices1[Ns+1])-qi)*Ti+((Ms=this.clipVertices1[Ns+2])-Ui)*Ai)<0&&s.addPoint(ks,ws,Ms,Pi,Ti,Ai,Ss,js)}else for(Ts=0;Ts0&&(a=F,o=q,n=U,F=X,q=Y,U=Z,X=a,Y=o,Z=n,a=j,o=C,n=O,j=R,C=_,O=J,R=a,_=o,J=n,a=D,o=E,n=B,D=W,E=H,B=Q,W=a,H=o,Q=n,P=-P,T=-T,A=-A);for(var K=0;;){if(++K>100)return!1;this.supportPointB(t,-P,-T,-A,b);var G=b.x,$=b.y,tt=b.z;this.supportPointC(i,P,T,A,b);var it=b.x,st=b.y,ht=b.z,et=it-G,at=st-$,ot=ht-tt;if(et*P+at*T+ot*A<=0)return!1;if((q*ot-U*at)*I+(U*et-F*ot)*V+(F*at-q*et)*S<0)X=et,Y=at,Z=ot,R=G,_=$,J=tt,W=it,H=st,Q=ht,P=(o=q-V)*(c=ot-S)-(n=U-S)*(l=at-V),T=n*(r=et-I)-(a=F-I)*c,A=a*l-o*r;else if((at*Z-ot*Y)*I+(ot*X-et*Z)*V+(et*Y-at*X)*S<0)F=et,q=at,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q-Nt*F)*S<0?(Nt*Z-kt*Y)*I+(kt*X-zt*Z)*V+(zt*Y-Nt*X)*S<0?(F=zt,q=Nt,U=kt,j=yt,C=xt,O=dt,D=ft,E=bt,B=vt):(et=zt,at=Nt,ot=kt,G=yt,$=xt,tt=dt,it=ft,st=bt,ht=vt):(Nt*ot-kt*at)*I+(kt*et-zt*ot)*V+(zt*at-Nt*et)*S<0?(X=zt,Y=Nt,Z=kt,R=yt,_=xt,J=dt,W=ft,H=bt,Q=vt):(F=zt,q=Nt,U=kt,j=yt,C=xt,O=dt,D=ft,E=bt,B=vt)}}},supportPointB:function(t,i,s,h,e){var a,o,n,r=t.rotation.elements,l=r[0]*i+r[3]*s+r[6]*h,c=r[1]*i+r[4]*s+r[7]*h,m=r[2]*i+r[5]*s+r[8]*h,p=t.halfWidth,u=t.halfHeight,y=t.halfDepth;a=l<0?-p:p,o=c<0?-u:u,n=m<0?-y:y,l=r[0]*a+r[1]*o+r[2]*n+t.position.x,c=r[3]*a+r[4]*o+r[5]*n+t.position.y,m=r[6]*a+r[7]*o+r[8]*n+t.position.z,e.set(l,c,m)},supportPointC:function(t,i,s,h,e){var a,o,n,r=t.rotation.elements,l=r[0]*i+r[3]*s+r[6]*h,c=r[1]*i+r[4]*s+r[7]*h,m=r[2]*i+r[5]*s+r[8]*h,p=l,u=m,y=p*p+u*u,x=t.radius,d=t.halfHeight;0==y?c<0?(a=x,o=-d,n=0):(a=x,o=d,n=0):(y=t.radius/g.sqrt(y),c<0?(a=p*y,o=-d,n=u*y):(a=p*y,o=d,n=u*y)),l=r[0]*a+r[1]*o+r[2]*n+t.position.x,c=r[3]*a+r[4]*o+r[5]*n+t.position.y,m=r[6]*a+r[7]*o+r[8]*n+t.position.z,e.set(l,c,m)},detectCollision:function(t,i,s){var h,e;this.flip?(h=i,e=t):(h=t,e=i);var a=new L,o=new L,n=new L;if(this.getSep(h,e,a,o,n)){var r=h.position.x,l=h.position.y,c=h.position.z,m=e.position.x,p=e.position.y,u=e.position.z,y=h.halfWidth,x=h.halfHeight,d=h.halfDepth,f=e.halfHeight,b=e.radius,v=h.dimentions,z=v[0],N=v[1],k=v[2],w=v[3],M=v[4],I=v[5],V=v[6],S=v[7],P=v[8],T=v[9],A=v[10],j=v[11],C=v[12],O=v[13],D=v[14],E=v[15],B=v[16],F=v[17],q=e.normalDirection.x,U=e.normalDirection.y,R=e.normalDirection.z,_=e.halfDirection.x,J=e.halfDirection.y,W=e.halfDirection.z,H=a.x,Q=a.y,X=a.z,Y=H*z+Q*N+X*k,Z=H*w+Q*M+X*I,K=H*V+Q*S+X*P,G=H*q+Q*U+X*R,$=Y>0,tt=Z>0,it=K>0,st=G>0;$||(Y=-Y),tt||(Z=-Z),it||(K=-K),st||(G=-G);var ht,et,at,ot,nt,rt,lt,ct,mt,pt,ut,yt,xt,dt,ft,bt,vt,zt,Nt,kt,wt,Mt,gt,It,Vt,Lt,St,Pt,Tt,At,jt,Ct,Ot,Dt,Et,Bt,Ft,qt,Ut,Rt,_t,Jt,Wt,Ht,Qt,Xt,Yt,Zt,Kt,Gt,$t,ti,ii,si=0;if(G>.999?si=Y>.999?Y>G?1:4:Z>.999?Z>G?2:4:K>.999&&K>G?3:4:Y>.999?si=1:Z>.999?si=2:K>.999&&(si=3),0==si)s.addPoint(o.x,o.y,o.z,H,Q,X,n.x,this.flip);else if(4==si){var hi,ei,ai,oi,ni,ri,li,ci,mi,pi,ui,yi;st?(ot=m-_,nt=p-J,rt=u-W,H=-q,Q=-U,X=-R):(ot=m+_,nt=p+J,rt=u+W,H=q,Q=U,X=R),si=0,(Wt=z*H+N*Q+k*X)<(kt=1)&&(kt=Wt,si=0),-Wt=.999999?(Mt=-Q,gt=X,It=H):(Mt=H,gt=Q,It=X),Lt=(wt=Mt*q+gt*U+It*R)*q-Mt,St=wt*U-gt,Pt=wt*R-It,0==(wt=g.sqrt(Lt*Lt+St*St+Pt*Pt)))return;if(Mt=ot+(Lt*=wt=b/wt),gt=nt+(St*=wt),It=rt+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I,T=-V,A=-S;this.supportPoint(t,-P,-T,-A,b);var j=b.x,C=b.y,O=b.z;this.supportPoint(i,P,T,A,b);var D=b.x,E=b.y,B=b.z,F=D-j,q=E-C,U=B-O;if(F*P+q*T+U*A<=0)return!1;if((P=q*S-U*V)*P+(T=U*I-F*S)*T+(A=F*V-q*I)*A==0)return s.set(F-I,q-V,U-S).normalize(),h.set(.5*(j+D),.5*(C+E),.5*(O+B)),!0;this.supportPoint(t,-P,-T,-A,b);var R=b.x,_=b.y,J=b.z;this.supportPoint(i,P,T,A,b);var W=b.x,H=b.y,Q=b.z,X=W-R,Y=H-_,Z=Q-J;if(X*P+Y*T+Z*A<=0)return!1;(P=(o=q-V)*(c=Z-S)-(n=U-S)*(l=Y-V))*I+(T=n*(r=X-I)-(a=F-I)*c)*V+(A=a*l-o*r)*S>0&&(a=F,o=q,n=U,F=X,q=Y,U=Z,X=a,Y=o,Z=n,a=j,o=C,n=O,j=R,C=_,O=J,R=a,_=o,J=n,a=D,o=E,n=B,D=W,E=H,B=Q,W=a,H=o,Q=n,P=-P,T=-T,A=-A);for(var K=0;;){if(++K>100)return!1;this.supportPoint(t,-P,-T,-A,b);var G=b.x,$=b.y,tt=b.z;this.supportPoint(i,P,T,A,b);var it=b.x,st=b.y,ht=b.z,et=it-G,at=st-$,ot=ht-tt;if(et*P+at*T+ot*A<=0)return!1;if((q*ot-U*at)*I+(U*et-F*ot)*V+(F*at-q*et)*S<0)X=et,Y=at,Z=ot,R=G,_=$,J=tt,W=it,H=st,Q=ht,P=(o=q-V)*(c=ot-S)-(n=U-S)*(l=at-V),T=n*(r=et-I)-(a=F-I)*c,A=a*l-o*r;else if((at*Z-ot*Y)*I+(ot*X-et*Z)*V+(et*Y-at*X)*S<0)F=et,q=at,U=ot,j=G,C=$,O=tt,D=it,E=st,B=ht,P=(o=at-V)*(c=Z-S)-(n=ot-S)*(l=Y-V),T=n*(r=X-I)-(a=et-I)*c,A=a*l-o*r;else for(var nt=!1;;){if(P=(o=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Nt,ot=kt,G=yt,$=xt,tt=dt,it=ft,st=bt,ht=vt):(Nt*ot-kt*at)*I+(kt*et-zt*ot)*V+(zt*at-Nt*et)*S<0?(X=zt,Y=Nt,Z=kt,R=yt,_=xt,J=dt,W=ft,H=bt,Q=vt):(F=zt,q=Nt,U=kt,j=yt,C=xt,O=dt,D=ft,E=bt,B=vt)}}},supportPoint:function(t,i,s,h,e){var a,o,n,r=t.rotation.elements,l=r[0]*i+r[3]*s+r[6]*h,c=r[1]*i+r[4]*s+r[7]*h,m=r[2]*i+r[5]*s+r[8]*h,p=l,u=m,y=p*p+u*u,x=t.radius,d=t.halfHeight;0==y?c<0?(a=x,o=-d,n=0):(a=x,o=d,n=0):(y=t.radius/g.sqrt(y),c<0?(a=p*y,o=-d,n=u*y):(a=p*y,o=d,n=u*y)),l=r[0]*a+r[1]*o+r[2]*n+t.position.x,c=r[3]*a+r[4]*o+r[5]*n+t.position.y,m=r[6]*a+r[7]*o+r[8]*n+t.position.z,e.set(l,c,m)},detectCollision:function(t,i,s){var h,e;t.id0,mt=lt>0;ct||(rt=-rt),mt||(lt=-lt);var pt,ut,yt,xt=0;(rt>.999||lt>.999)&&(xt=rt>lt?1:2);var dt,ft,bt,vt,zt,Nt,kt,wt,Mt,gt,It,Vt,Lt,St,Pt,Tt,At=nt.x;switch(pt=at.x,ut=at.y,yt=at.z,xt){case 0:s.addPoint(ot.x,ot.y,ot.z,pt,ut,yt,At,!1);break;case 1:if(ct?(o=P+Z,n=T+K,r=A+G,pt=J,ut=W,yt=H):(o=P-Z,n=T-K,r=A-G,pt=-J,ut=-W,yt=-H),l=j+(a=(w=pt*Q+ut*X+yt*Y)<0?E:-E)*Q,c=C+a*X,m=O+a*Y,lt>=.999999?(p=-ut,u=yt,y=pt):(p=pt,u=ut,y=yt),st=(a=p*Q+u*X+y*Y)*Q-p,ht=a*X-u,et=a*Y-y,0==(a=g.sqrt(st*st+ht*ht+et*et)))break;if(p=l+(st*=a=_/a),u=c+(ht*=a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,x=p,d=u,f=y,a=N+(k-N)*M,k=N+(k-N)*I,(N=a)<0&&s.addPoint(x,d,f,-pt,-ut,-yt,N,!1),k<0&&s.addPoint(b,v,z,-pt,-ut,-yt,k,!1)}}}}}),St.prototype=Object.assign(Object.create(gt.prototype),{constructor:St,detectCollision:function(t,i,s){var h,e;this.flip?(h=i,e=t):(h=t,e=i);var a,o,n,r,l,c=e.dimentions,m=h.position,p=m.x,u=m.y,y=m.z,x=e.position,d=x.x,f=x.y,b=x.z,v=h.radius,z=e.halfWidth,N=e.halfHeight,k=e.halfDepth,w=p-d,M=u-f,I=y-b,V=c[0]*w+c[1]*M+c[2]*I,L=c[3]*w+c[4]*M+c[5]*I,S=c[6]*w+c[7]*M+c[8]*I,P=0;V>z?V=z:V<-z?V=-z:P=1,L>N?L=N:L<-N?L=-N:P|=2,S>k?S=k:S<-k?S=-k:P|=4,7==P?(I=S<0?k+S:k-S,(w=V<0?z+V:z-V)<(M=L<0?N+L:N-L)?w0&&rv+d)){var M,I=c+w*u,V=m+w*y,L=p+w*x,S=o-I,P=n-V,T=r-L,A=S*S+P*P+T*T;if(!(A>b*b))A>f*f&&(S*=A=f/g.sqrt(A),P*=A,T*=A),w<-v?w=-v:w>v&&(w=v),(A=(z=(I=c+w*u+S)-o)*z+(N=(V=m+w*y+P)-n)*N+(k=(L=p+w*x+T)-r)*k)>0&&A0&&c0&&hc?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.04)&&!(t.angularVelocity.lengthSq()>.25))},step:function(){var t=this.isStat;t&&this.performance.setTime(0);for(var i=this.rigidBodies;null!==i;)i.addedToIsland=!1,i.sleeping&&i.testWakeUp(),i=i.next;t&&this.performance.setTime(1),this.broadPhase.detectPairs();for(var s=this.broadPhase.pairs,h=this.broadPhase.numPairs;h--;){var e,a,o,n=s[h];n.shape1.id.5?x.sleep():x.updatePosition(this.timeStep)):(x.sleepTime=0,x.updatePosition(this.timeStep)),this.numIslands++;else{var d=0,f=0,b=1;this.islandStack[0]=x,x.addedToIsland=!0;do{if(i=this.islandStack[--b],this.islandStack[b]=null,i.sleeping=!1,this.islandRigidBodies[d++]=i,!i.isStatic){for(var v=i.contactLink;null!==v;v=v.next){var z;if(!(u=(z=v.contact).constraint).addedToIsland&&z.touching)this.islandConstraints[f++]=u,u.addedToIsland=!0,(m=v.body).addedToIsland||(this.islandStack[b++]=m,m.addedToIsland=!0)}for(var N=i.jointLink;null!==N;N=N.next)(u=N.joint).addedToIsland||(this.islandConstraints[f++]=u,u.addedToIsland=!0,!(m=N.body).addedToIsland&&m.isDynamic&&(this.islandStack[b++]=m,m.addedToIsland=!0))}}while(0!=b);for(var k=(new L).addScaledVector(this.gravity,this.timeStep),w=d;w--;)(i=this.islandRigidBodies[w]).isDynamic&&i.linearVelocity.addEqual(k);if(this.enableRandomizer)for(w=f;w--;)if(0!==w){var M=(this.randX=this.randX*this.randA+this.randB&2147483647)/2147483648*w|0;u=this.islandConstraints[w],this.islandConstraints[w]=this.islandConstraints[M],this.islandConstraints[M]=u}for(w=f;w--;)this.islandConstraints[w].preSolve(this.timeStep,y);for(var g=this.numIterations;g--;)for(w=f;w--;)this.islandConstraints[w].solve();for(w=f;w--;)this.islandConstraints[w].postSolve(),this.islandConstraints[w]=null;var I=10;for(w=d;w--;)i=this.islandRigidBodies[w],this.callSleep(i)?(i.sleepTime+=this.timeStep,i.sleepTime.5)for(w=d;w--;)this.islandRigidBodies[w].sleep(),this.islandRigidBodies[w]=null;else for(w=d;w--;)this.islandRigidBodies[w].updatePosition(this.timeStep),this.islandRigidBodies[w]=null;this.numIslands++}t&&this.performance.calcEnd(),null!==this.postLoop&&this.postLoop()},remove:function(t){},add:function(t){var i=(t=t||{}).type||"box";return i.constructor===String&&(i=[i]),"joint"===i[0].substring(0,5)?this.initJoint(i[0],t):this.initBody(i,t)},initBody:function(t,i){var s=this.invScale,h=i.move||!1,e=i.kinematic||!1,a=i.pos||[0,0,0];a=a.map(function(t){return t*s});var o=i.posShape||[0,0,0];o=o.map(function(t){return t*s});var n=i.rot||[0,0,0];n=n.map(function(t){return t*g.degtorad});var r=i.rotShape;r=n.map(function(t){return t*g.degtorad});var l=void 0===i.size?[1,1,1]:i.size;1===l.length&&(l[1]=l[0]),2===l.length&&(l[2]=l[0]),l=l.map(function(t){return t*s});var c=new F;void 0!==i.density&&(c.density=i.density),void 0!==i.friction&&(c.friction=i.friction),void 0!==i.restitution&&(c.restitution=i.restitution),void 0!==i.belongsTo&&(c.belongsTo=i.belongsTo),void 0!==i.collidesWith&&(c.collidesWith=i.collidesWith),void 0!==i.config&&(void 0!==i.config[0]&&(c.density=i.config[0]),void 0!==i.config[1]&&(c.friction=i.config[1]),void 0!==i.config[2]&&(c.restitution=i.config[2]),void 0!==i.config[3]&&(c.belongsTo=i.config[3]),void 0!==i.config[4]&&(c.collidesWith=i.config[4]));for(var m,p,u=new ct(new L(a[0],a[1],a[2]),(new S).setFromEuler(n[0],n[1],n[2])),y=0;y