UNPKG

@cocos/cannon

Version:

A lightweight 3D physics engine written in JavaScript.

26 lines (24 loc) 146 kB
// Tue, 20 Jul 2021 10:46:34 GMT /* * Copyright (c) 2015 cannon.js Authors * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ !function(t){var e;"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):("undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.CANNON=t())}(function(){return function o(n,s,r){function a(i,t){if(!s[i]){if(!n[i]){var e="function"==typeof require&&require;if(!t&&e)return e(i,!0);if(h)return h(i,!0);throw new Error("Cannot find module '"+i+"'")}e=s[i]={exports:{}};n[i][0].call(e.exports,function(t){var e=n[i][1][t];return a(e||t)},e,e.exports,o,n,s,r)}return s[i].exports}for(var h="function"==typeof require&&require,t=0;t<r.length;t++)a(r[t]);return a}({1:[function(t,e,i){e.exports={name:"@cocos/cannon",version:"1.2.8",description:"A lightweight 3D physics engine written in JavaScript.",homepage:"https://github.com/cocos-creator/cannon.js",author:"Stefan Hedman <schteppe@gmail.com> (http://steffe.se), JayceLai",keywords:["cannon.js","cocos","creator","physics","engine","3d"],scripts:{build:"grunt && npm run preprocess && grunt addLicense && grunt addDate",preprocess:"node node_modules/uglify-js/bin/uglifyjs build/cannon.js -o build/cannon.min.js -c -m",postpublish:"cnpm sync @cocos/cannon"},main:"./build/cannon.js",engines:{node:"*"},repository:{type:"git",url:"https://github.com/cocos-creator/cannon.js.git"},bugs:{url:"https://github.com/cocos-creator/cannon.js/issues"},licenses:[{type:"MIT"}],devDependencies:{jshint:"latest","uglify-js":"latest",nodeunit:"^0.9.0",grunt:"~0.4.0","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-concat":"~0.1.3","grunt-contrib-uglify":"^0.5.1","grunt-browserify":"^2.1.4","grunt-contrib-yuidoc":"^0.5.2",browserify:"*"},dependencies:{}}},{}],2:[function(t,e,i){e.exports={version:t("../package.json").version,AABB:t("./collision/AABB"),ArrayCollisionMatrix:t("./collision/ArrayCollisionMatrix"),Body:t("./objects/Body"),Box:t("./shapes/Box"),Broadphase:t("./collision/Broadphase"),Constraint:t("./constraints/Constraint"),ContactEquation:t("./equations/ContactEquation"),Narrowphase:t("./world/Narrowphase"),ConeTwistConstraint:t("./constraints/ConeTwistConstraint"),ContactMaterial:t("./material/ContactMaterial"),ConvexPolyhedron:t("./shapes/ConvexPolyhedron"),Cylinder:t("./shapes/Cylinder"),DistanceConstraint:t("./constraints/DistanceConstraint"),Equation:t("./equations/Equation"),EventTarget:t("./utils/EventTarget"),FrictionEquation:t("./equations/FrictionEquation"),GSSolver:t("./solver/GSSolver"),GridBroadphase:t("./collision/GridBroadphase"),Heightfield:t("./shapes/Heightfield"),HingeConstraint:t("./constraints/HingeConstraint"),LockConstraint:t("./constraints/LockConstraint"),Mat3:t("./math/Mat3"),Material:t("./material/Material"),NaiveBroadphase:t("./collision/NaiveBroadphase"),ObjectCollisionMatrix:t("./collision/ObjectCollisionMatrix"),Pool:t("./utils/Pool"),Particle:t("./shapes/Particle"),Plane:t("./shapes/Plane"),PointToPointConstraint:t("./constraints/PointToPointConstraint"),Quaternion:t("./math/Quaternion"),Ray:t("./collision/Ray"),RaycastVehicle:t("./objects/RaycastVehicle"),RaycastResult:t("./collision/RaycastResult"),RigidVehicle:t("./objects/RigidVehicle"),RotationalEquation:t("./equations/RotationalEquation"),RotationalMotorEquation:t("./equations/RotationalMotorEquation"),SAPBroadphase:t("./collision/SAPBroadphase"),SPHSystem:t("./objects/SPHSystem"),Shape:t("./shapes/Shape"),Solver:t("./solver/Solver"),Sphere:t("./shapes/Sphere"),SplitSolver:t("./solver/SplitSolver"),Spring:t("./objects/Spring"),Transform:t("./math/Transform"),Trimesh:t("./shapes/Trimesh"),Vec3:t("./math/Vec3"),Vec3Pool:t("./utils/Vec3Pool"),World:t("./world/World"),Octree:t("./utils/Octree")}},{"../package.json":1,"./collision/AABB":3,"./collision/ArrayCollisionMatrix":4,"./collision/Broadphase":5,"./collision/GridBroadphase":6,"./collision/NaiveBroadphase":7,"./collision/ObjectCollisionMatrix":8,"./collision/Ray":10,"./collision/RaycastResult":11,"./collision/SAPBroadphase":12,"./constraints/ConeTwistConstraint":13,"./constraints/Constraint":14,"./constraints/DistanceConstraint":15,"./constraints/HingeConstraint":16,"./constraints/LockConstraint":17,"./constraints/PointToPointConstraint":18,"./equations/ContactEquation":20,"./equations/Equation":21,"./equations/FrictionEquation":22,"./equations/RotationalEquation":23,"./equations/RotationalMotorEquation":24,"./material/ContactMaterial":25,"./material/Material":26,"./math/Mat3":28,"./math/Quaternion":29,"./math/Transform":30,"./math/Vec3":31,"./objects/Body":32,"./objects/RaycastVehicle":33,"./objects/RigidVehicle":34,"./objects/SPHSystem":35,"./objects/Spring":36,"./shapes/Box":38,"./shapes/ConvexPolyhedron":39,"./shapes/Cylinder":40,"./shapes/Heightfield":41,"./shapes/Particle":42,"./shapes/Plane":43,"./shapes/Shape":44,"./shapes/Sphere":45,"./shapes/Trimesh":46,"./solver/GSSolver":47,"./solver/Solver":48,"./solver/SplitSolver":49,"./utils/EventTarget":50,"./utils/Octree":51,"./utils/Pool":52,"./utils/Vec3Pool":55,"./world/Narrowphase":56,"./world/World":57}],3:[function(t,e,i){var o=t("../math/Vec3");t("../utils/Utils");function n(t){t=t||{},this.lowerBound=new o,t.lowerBound&&this.lowerBound.copy(t.lowerBound),this.upperBound=new o,t.upperBound&&this.upperBound.copy(t.upperBound)}e.exports=n;var l=new o;n.prototype.setFromPoints=function(t,e,i,o){var n=this.lowerBound,s=this.upperBound,r=i;n.copy(t[0]),r&&r.vmult(n,n),s.copy(n);for(var a=1;a<t.length;a++){var h=t[a];r&&(r.vmult(h,l),h=l),h.x>s.x&&(s.x=h.x),h.x<n.x&&(n.x=h.x),h.y>s.y&&(s.y=h.y),h.y<n.y&&(n.y=h.y),h.z>s.z&&(s.z=h.z),h.z<n.z&&(n.z=h.z)}return e&&(e.vadd(n,n),e.vadd(s,s)),o&&(n.x-=o,n.y-=o,n.z-=o,s.x+=o,s.y+=o,s.z+=o),this},n.prototype.copy=function(t){return this.lowerBound.copy(t.lowerBound),this.upperBound.copy(t.upperBound),this},n.prototype.clone=function(){return(new n).copy(this)},n.prototype.extend=function(t){this.lowerBound.x=Math.min(this.lowerBound.x,t.lowerBound.x),this.upperBound.x=Math.max(this.upperBound.x,t.upperBound.x),this.lowerBound.y=Math.min(this.lowerBound.y,t.lowerBound.y),this.upperBound.y=Math.max(this.upperBound.y,t.upperBound.y),this.lowerBound.z=Math.min(this.lowerBound.z,t.lowerBound.z),this.upperBound.z=Math.max(this.upperBound.z,t.upperBound.z)},n.prototype.overlaps=function(t){var e=this.lowerBound,i=this.upperBound,o=t.lowerBound,n=t.upperBound,s=o.x<=i.x&&i.x<=n.x||e.x<=n.x&&n.x<=i.x,t=o.y<=i.y&&i.y<=n.y||e.y<=n.y&&n.y<=i.y,i=o.z<=i.z&&i.z<=n.z||e.z<=n.z&&n.z<=i.z;return s&&t&&i},n.prototype.volume=function(){var t=this.lowerBound,e=this.upperBound;return(e.x-t.x)*(e.y-t.y)*(e.z-t.z)},n.prototype.contains=function(t){var e=this.lowerBound,i=this.upperBound,o=t.lowerBound,t=t.upperBound;return e.x<=o.x&&i.x>=t.x&&e.y<=o.y&&i.y>=t.y&&e.z<=o.z&&i.z>=t.z},n.prototype.getCorners=function(t,e,i,o,n,s,r,a){var h=this.lowerBound,l=this.upperBound;t.copy(h),e.set(l.x,h.y,h.z),i.set(l.x,l.y,h.z),o.set(h.x,l.y,l.z),n.set(l.x,h.y,l.z),s.set(h.x,l.y,h.z),r.set(h.x,h.y,l.z),a.copy(l)};var s=[new o,new o,new o,new o,new o,new o,new o,new o];n.prototype.toLocalFrame=function(t,e){var i=s;this.getCorners(i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7]);for(var o=0;8!==o;o++){var n=i[o];t.pointToLocal(n,n)}return e.setFromPoints(i)},n.prototype.toWorldFrame=function(t,e){var i=s;this.getCorners(i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7]);for(var o=0;8!==o;o++){var n=i[o];t.pointToWorld(n,n)}return e.setFromPoints(i)},n.prototype.overlapsRay=function(t){var e=1/t._direction.x,i=1/t._direction.y,o=1/t._direction.z,n=(this.lowerBound.x-t.from.x)*e,s=(this.upperBound.x-t.from.x)*e,r=(this.lowerBound.y-t.from.y)*i,e=(this.upperBound.y-t.from.y)*i,i=(this.lowerBound.z-t.from.z)*o,t=(this.upperBound.z-t.from.z)*o,o=Math.max(Math.max(Math.min(n,s),Math.min(r,e)),Math.min(i,t)),t=Math.min(Math.min(Math.max(n,s),Math.max(r,e)),Math.max(i,t));return!(t<0)&&!(t<o)}},{"../math/Vec3":31,"../utils/Utils":54}],4:[function(t,e,i){function o(){this.matrix=[]}(e.exports=o).prototype.get=function(t,e){var i;return(t=t.index)<(e=e.index)&&(i=e,e=t,t=i),this.matrix[(t*(t+1)>>1)+e-1]},o.prototype.set=function(t,e,i){var o;(t=t.index)<(e=e.index)&&(o=e,e=t,t=o),this.matrix[(t*(t+1)>>1)+e-1]=i?1:0},o.prototype.reset=function(){for(var t=0,e=this.matrix.length;t!==e;t++)this.matrix[t]=0},o.prototype.setNumObjects=function(t){this.matrix.length=t*(t-1)>>1}},{}],5:[function(t,e,i){var n=t("../objects/Body"),o=t("../math/Vec3"),s=t("../math/Quaternion");t("../shapes/Shape"),t("../shapes/Plane");function r(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}(e.exports=r).prototype.collisionPairs=function(t,e,i){throw new Error("collisionPairs not implemented for this BroadPhase class!")},r.prototype.needBroadphaseCollision=function(t,e){if(0==(t.collisionFilterGroup&e.collisionFilterMask)||0==(e.collisionFilterGroup&t.collisionFilterMask))return!1;var i=0!=(t.type&n.STATIC),o=0!=(e.type&n.STATIC);return(!i||!o)&&(!(!t.hasTrigger&&!e.hasTrigger)||(t.sleepState!==n.SLEEPING||e.sleepState!==n.SLEEPING))},r.prototype.intersectionTest=function(t,e,i,o){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,e,i,o):this.doBoundingSphereBroadphase(t,e,i,o)};var a=new o;new o,new s,new o;r.prototype.doBoundingSphereBroadphase=function(t,e,i,o){var n=a;e.position.vsub(t.position,n);var s=Math.pow(t.boundingRadius+e.boundingRadius,2);n.norm2()<s&&(i.push(t),o.push(e))},r.prototype.doBoundingBoxBroadphase=function(t,e,i,o){t.aabbNeedsUpdate&&t.computeAABB(),e.aabbNeedsUpdate&&e.computeAABB(),t.aabb.overlaps(e.aabb)&&(i.push(t),o.push(e))};var c={keys:[]},u=[],d=[];r.prototype.makePairsUnique=function(t,e){for(var i=c,o=u,n=d,s=t.length,r=0;r!==s;r++)o[r]=t[r],n[r]=e[r];t.length=0;for(r=e.length=0;r!==s;r++){var a=o[r].id,h=n[r].id;i[l=a<h?a+","+h:h+","+a]=r,i.keys.push(l)}for(r=0;r!==i.keys.length;r++){var l=i.keys.pop(),p=i[l];t.push(o[p]),e.push(n[p]),delete i[l]}},r.prototype.setWorld=function(t){};var h=new o;r.boundingSphereCheck=function(t,e){var i=h;return t.position.vsub(e.position,i),Math.pow(t.shape.boundingSphereRadius+e.shape.boundingSphereRadius,2)>i.norm2()},r.prototype.aabbQuery=function(t,e,i){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}},{"../math/Quaternion":29,"../math/Vec3":31,"../objects/Body":32,"../shapes/Plane":43,"../shapes/Shape":44}],6:[function(t,e,i){e.exports=o;var a=t("./Broadphase"),h=t("../math/Vec3"),$=t("../shapes/Shape");function o(t,e,i,o,n){a.apply(this),this.nx=i||10,this.ny=o||10,this.nz=n||10,this.aabbMin=t||new h(100,100,100),this.aabbMax=e||new h(-100,-100,-100);var s=this.nx*this.ny*this.nz;if(s<=0)throw"GridBroadphase: Each dimension's n must be >0";this.bins=[],this.binLengths=[],this.bins.length=s,this.binLengths.length=s;for(var r=0;r<s;r++)this.bins[r]=[],this.binLengths[r]=0}(o.prototype=new a).constructor=o;var tt=new h;new h;o.prototype.collisionPairs=function(t,e,i){for(var o=t.numObjects(),n=t.bodies,s=this.aabbMax,r=this.aabbMin,f=this.nx,m=this.ny,w=this.nz,g=m*w,x=w,b=1,a=s.x,h=s.y,t=s.z,B=r.x,A=r.y,E=r.z,S=f/(a-B),z=m/(h-A),C=w/(t-E),l=(a-B)/f,p=(h-A)/m,c=(t-E)/w,u=.5*Math.sqrt(l*l+p*p+c*c),t=$.types,d=t.SPHERE,v=t.PLANE,M=(t.BOX,t.COMPOUND,t.CONVEXPOLYHEDRON,this.bins),q=this.binLengths,y=this.bins.length,R=0;R!==y;R++)q[R]=0;var F=Math.ceil;Math.min,Math.max;function T(t,e,i,o,n,s,r){var t=(t-B)*S|0,a=(e-A)*z|0,h=(i-E)*C|0,l=F((o-B)*S),p=F((n-A)*z),c=F((s-E)*C);t<0?t=0:f<=t&&(t=f-1),a<0?a=0:m<=a&&(a=m-1),h<0?h=0:w<=h&&(h=w-1),l<0?l=0:f<=l&&(l=f-1),p<0?p=0:m<=p&&(p=m-1),c<0?c=0:w<=c&&(c=w-1),a*=x,h*=b,l*=g,p*=x,c*=b;for(var u=t*=g;u<=l;u+=g)for(var d=a;d<=p;d+=x)for(var v=h;v<=c;v+=b){var y=u+d+v;M[y][q[y]++]=r}}for(R=0;R!==o;R++){var P=(Z=n[R]).shape;switch(P.type){case d:var V=Z.position.x,I=Z.position.y,N=Z.position.z,L=P.radius;T(V-L,I-L,N-L,V+L,I+L,N+L,Z);break;case v:P.worldNormalNeedsUpdate&&P.computeWorldNormal(Z.quaternion);var W=P.worldNormal,L=B+.5*l-Z.position.x,j=A+.5*p-Z.position.y,O=E+.5*c-Z.position.z,k=tt;k.set(L,j,O);for(var D=0,_=0;D!==f;D++,_+=g,k.y=j,k.x+=l)for(var H=0,U=0;H!==m;H++,U+=x,k.z=O,k.y+=p)for(var G,X=0,Q=0;X!==w;X++,Q+=b,k.z+=c)k.dot(W)<u&&(M[G=_+U+Q][q[G]++]=Z);break;default:Z.aabbNeedsUpdate&&Z.computeAABB(),T(Z.aabb.lowerBound.x,Z.aabb.lowerBound.y,Z.aabb.lowerBound.z,Z.aabb.upperBound.x,Z.aabb.upperBound.y,Z.aabb.upperBound.z,Z)}}for(R=0;R!==y;R++){var Y=q[R];if(1<Y)for(var K=M[R],D=0;D!==Y;D++)for(var Z=K[D],H=0;H!==D;H++){var J=K[H];this.needBroadphaseCollision(Z,J)&&this.intersectionTest(Z,J,e,i)}}this.makePairsUnique(e,i)}},{"../math/Vec3":31,"../shapes/Shape":44,"./Broadphase":5}],7:[function(t,e,i){e.exports=n;var o=t("./Broadphase"),t=t("./AABB");function n(){o.apply(this)}((n.prototype=new o).constructor=n).prototype.collisionPairs=function(t,e,i){for(var o,n,s,r=t.bodies,a=r.length,h=0;h!==a;h++)for(o=0;o!==h;o++)n=r[h],s=r[o],this.needBroadphaseCollision(n,s)&&this.intersectionTest(n,s,e,i)};new t;n.prototype.aabbQuery=function(t,e,i){i=i||[];for(var o=0;o<t.bodies.length;o++){var n=t.bodies[o];n.aabbNeedsUpdate&&n.computeAABB(),n.aabb.overlaps(e)&&i.push(n)}return i}},{"./AABB":3,"./Broadphase":5}],8:[function(t,e,i){function o(){this.matrix={}}(e.exports=o).prototype.get=function(t,e){var i;return(t=t.id)<(e=e.id)&&(i=e,e=t,t=i),t+"-"+e in this.matrix},o.prototype.set=function(t,e,i){var o;(t=t.id)<(e=e.id)&&(o=e,e=t,t=o),i?this.matrix[t+"-"+e]=!0:delete this.matrix[t+"-"+e]},o.prototype.reset=function(){this.matrix={}},o.prototype.setNumObjects=function(t){}},{}],9:[function(t,e,i){function o(){this.current=[],this.previous=[]}function p(t,e){t.push((4294901760&e)>>16,65535&e)}(e.exports=o).prototype.getKey=function(t,e){var i;return e<t&&(i=e,e=t,t=i),t<<16|e},o.prototype.set=function(t,e){for(var i=this.getKey(t,e),o=this.current,n=0;i>o[n];)n++;if(i!==o[n]){for(e=o.length-1;n<=e;e--)o[e+1]=o[e];o[n]=i}},o.prototype.tick=function(){var t=this.current;this.current=this.previous,this.previous=t,this.current.length=0},o.prototype.getDiff=function(t,e){for(var i=this.current,o=this.previous,n=i.length,s=o.length,r=0,a=0;a<n;a++){for(var h=i[a];h>o[r];)r++;h===o[r]||p(t,h)}for(r=0,a=0;a<s;a++){for(var l=o[a];l>i[r];)r++;i[r]===l||p(e,l)}}},{}],10:[function(t,e,i){e.exports=l;var c=t("../math/Vec3"),o=t("../math/Quaternion"),A=t("../math/Transform"),n=(t("../shapes/ConvexPolyhedron"),t("../shapes/Box"),t("../collision/RaycastResult")),e=t("../shapes/Shape"),v=t("../collision/AABB");function l(t,e){this.from=t?t.clone():new c,this.to=e?e.clone():new c,this._direction=new c,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=l.ANY,this.result=new n,this.hasHit=!1,this.callback=function(t){}}(l.prototype.constructor=l).CLOSEST=1,l.ANY=2,l.ALL=4;var s=new v,r=[];l.prototype.intersectWorld=function(t,e){return this.mode=e.mode||l.ANY,this.result=e.result||new n,this.skipBackfaces=!!e.skipBackfaces,this.checkCollisionResponse=!!e.checkCollisionResponse,this.collisionFilterMask=void 0!==e.collisionFilterMask?e.collisionFilterMask:-1,this.collisionFilterGroup=void 0!==e.collisionFilterGroup?e.collisionFilterGroup:-1,e.from&&this.from.copy(e.from),e.to&&this.to.copy(e.to),this.callback=e.callback||function(){},this.hasHit=!1,this.result.reset(),this._updateDirection(),this.getAABB(s),r.length=0,t.broadphase.aabbQuery(t,s,r),this.intersectBodies(r),this.hasHit};var a=new c,h=new c;function S(t,e,i,o){o.vsub(e,x),i.vsub(e,a),t.vsub(e,h);var n,s=x.dot(x),r=x.dot(a),o=x.dot(h),i=a.dot(a),t=a.dot(h);return 0<=(e=i*o-r*t)&&0<=(n=s*t-r*o)&&e+n<s*i-r*r}l.pointInTriangle=S;var p=new c,u=new o;l.prototype.intersectBody=function(t,e){e&&(this.result=e,this._updateDirection());e=this.checkCollisionResponse;if((!e||t.collisionResponse)&&l.perBodyFilter(this,t))for(var i=p,o=u,n=0,s=t.shapes.length;n<s;n++){var r=t.shapes[n];if(l.perShapeFilter(this,r)&&(t.quaternion.mult(t.shapeOrientations[n],o),t.quaternion.vmult(t.shapeOffsets[n],i),i.vadd(t.position,i),this.intersectShape(r,o,i,t),this.result._shouldStop))break}},l.prototype.intersectBodies=function(t,e){e&&(this.result=e,this._updateDirection());for(var i=0,o=t.length;!this.result._shouldStop&&i<o;i++)this.intersectBody(t[i])},l.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction),this._direction.normalize()},l.prototype.intersectShape=function(t,e,i,o){var n;(function(t,e,i){i.vsub(t,x);var o=x.dot(e);return e.mult(o,b),b.vadd(t,b),i.distanceTo(b)})(this.from,this._direction,i)>t.boundingSphereRadius||(n=this[t.type])&&n.call(this,t,e,i,o,t)};new c,new c;var z=new c,C=new c,M=new c,q=new c;new c,new n;l.prototype[e.types.BOX]=l.prototype.intersectBox=function(t,e,i,o,n){return this.intersectConvex(t.convexPolyhedronRepresentation,e,i,o,n)},l.prototype[e.types.PLANE]=l.prototype.intersectPlane=function(t,e,i,o,n){var s=this.from,r=this.to,a=this._direction,h=new c(0,0,1);e.vmult(h,h);var l=new c;s.vsub(i,l);var p=l.dot(h);r.vsub(i,l),0<p*l.dot(h)||s.distanceTo(r)<p||(e=h.dot(a),Math.abs(e)<this.precision||(l=new c,r=new c,p=new c,s.vsub(i,l),e=-h.dot(l)/e,a.scale(e,r),s.vadd(r,p),this.reportIntersection(h,p,n,o,-1)))},l.prototype.getAABB=function(t){var e=this.to,i=this.from;t.lowerBound.x=Math.min(e.x,i.x),t.lowerBound.y=Math.min(e.y,i.y),t.lowerBound.z=Math.min(e.z,i.z),t.upperBound.x=Math.max(e.x,i.x),t.upperBound.y=Math.max(e.y,i.y),t.upperBound.z=Math.max(e.z,i.z)};var y={faceList:[0]},f=new c,m=new l,w=[];l.prototype[e.types.HEIGHTFIELD]=l.prototype.intersectHeightfield=function(t,e,i,o,n){t.data,t.elementSize;var s=m;s.from.copy(this.from),s.to.copy(this.to),A.pointToLocalFrame(i,e,s.from,s.from),A.pointToLocalFrame(i,e,s.to,s.to),s._updateDirection();var r,a,h=w,l=c=t.data.length-1,p=new v;s.getAABB(p),t.getIndexOfPosition(p.lowerBound.x,p.lowerBound.y,h,!0),a=Math.max(0,h[0]),r=Math.max(0,h[1]),t.getIndexOfPosition(p.upperBound.x,p.upperBound.y,h,!0),l=Math.min(l,h[0]+1);for(var c=Math.min(c,h[1]+1),u=a;u<l;u++)for(var d=r;d<c;d++){if(this.result._shouldStop)return;if(t.getAabbAtIndex(u,d,p),p.overlapsRay(s)){if(t.getConvexTrianglePillar(u,d,!1),A.pointToWorldFrame(i,e,t.pillarOffset,f),this.intersectConvex(t.pillarConvex,e,f,o,n,y),this.result._shouldStop)return;t.getConvexTrianglePillar(u,d,!0),A.pointToWorldFrame(i,e,t.pillarOffset,f),this.intersectConvex(t.pillarConvex,e,f,o,n,y)}}};var d=new c,g=new c;l.prototype[e.types.SPHERE]=l.prototype.intersectSphere=function(t,e,i,o,n){var s=this.from,r=this.to,a=t.radius,h=Math.pow(r.x-s.x,2)+Math.pow(r.y-s.y,2)+Math.pow(r.z-s.z,2),l=2*((r.x-s.x)*(s.x-i.x)+(r.y-s.y)*(s.y-i.y)+(r.z-s.z)*(s.z-i.z)),p=Math.pow(s.x-i.x,2)+Math.pow(s.y-i.y,2)+Math.pow(s.z-i.z,2)-Math.pow(a,2),c=Math.pow(l,2)-4*h*p,t=d,a=g;c<0||(0==c?(s.lerp(r,c,t),t.vsub(i,a),a.normalize(),this.reportIntersection(a,t,n,o,-1)):(p=(-l-Math.sqrt(c))/(2*h),h=(-l+Math.sqrt(c))/(2*h),0<=p&&p<=1&&(s.lerp(r,p,t),t.vsub(i,a),a.normalize(),this.reportIntersection(a,t,n,o,-1)),this.result._shouldStop||0<=h&&h<=1&&(s.lerp(r,h,t),t.vsub(i,a),a.normalize(),this.reportIntersection(a,t,n,o,-1))))};var R=new c,F=(new c,new c,new c);l.prototype[e.types.CONVEXPOLYHEDRON]=l.prototype.intersectConvex=function(t,e,i,o,n,s){for(var r=R,a=F,h=s&&s.faceList||null,l=t.faces,p=t.vertices,c=t.faceNormals,u=this._direction,d=this.from,t=this.to,v=d.distanceTo(t),y=(h||l).length,f=this.result,m=0;!f._shouldStop&&m<y;m++){var w=h?h[m]:m,g=l[w],x=c[w],b=e,B=i;a.copy(p[g[0]]),b.vmult(a,a),a.vadd(B,a),a.vsub(d,a),b.vmult(x,r);x=u.dot(r);if(!(Math.abs(x)<this.precision)){x=r.dot(a)/x;if(!(x<0)){u.mult(x,z),z.vadd(d,z),C.copy(p[g[0]]),b.vmult(C,C),B.vadd(C,C);for(var A=1;!f._shouldStop&&A<g.length-1;A++){M.copy(p[g[A]]),q.copy(p[g[A+1]]),b.vmult(M,M),b.vmult(q,q),B.vadd(M,M),B.vadd(q,q);var E=z.distanceTo(d);!S(z,C,M,q)&&!S(z,M,C,q)||v<E||this.reportIntersection(r,z,n,o,w)}}}}};var E=new c,T=new c,P=new c,V=new c,I=new c,N=new c,L=(new v,[]),W=new A;l.prototype[e.types.TRIMESH]=l.prototype.intersectTrimesh=function(t,e,i,o,n,s){var r=E,a=L,h=W,l=F,p=T,c=P,u=V,d=N,v=I,y=(s&&s.faceList,t.indices),f=(t.vertices,t.faceNormals,this.from),m=this.to,s=this._direction;h.position.copy(i),h.quaternion.copy(e),A.vectorToLocalFrame(i,e,s,p),A.pointToLocalFrame(i,e,f,c),A.pointToLocalFrame(i,e,m,u),u.x*=t.scale.x,u.y*=t.scale.y,u.z*=t.scale.z,c.x*=t.scale.x,c.y*=t.scale.y,c.z*=t.scale.z,u.vsub(c,p),p.normalize();var w=c.distanceSquared(u);t.tree.rayQuery(this,h,a);for(var g=0,x=a.length;!this.result._shouldStop&&g!==x;g++){var b=a[g];t.getNormal(b,r),t.getVertex(y[3*b],C),C.vsub(c,l);var B=p.dot(r),B=r.dot(l)/B;B<0||(p.scale(B,z),z.vadd(c,z),t.getVertex(y[3*b+1],M),t.getVertex(y[3*b+2],q),B=z.distanceSquared(c),!S(z,M,C,q)&&!S(z,C,M,q)||w<B||(A.vectorToWorldFrame(e,r,v),A.pointToWorldFrame(i,e,z,d),this.reportIntersection(v,d,n,o,b)))}a.length=0},l.prototype.reportIntersection=function(t,e,i,o,n){var s=this.from,r=this.to,a=s.distanceTo(e),h=this.result;if(!(this.skipBackfaces&&0<t.dot(this._direction)))switch(h.hitFaceIndex=void 0!==n?n:-1,this.mode){case l.ALL:this.hasHit=!0,h.set(s,r,t,e,i,o,a),h.hasHit=!0,this.callback(h);break;case l.CLOSEST:(a<h.distance||!h.hasHit)&&(this.hasHit=!0,h.hasHit=!0,h.set(s,r,t,e,i,o,a));break;case l.ANY:this.hasHit=!0,h.hasHit=!0,h.set(s,r,t,e,i,o,a),h._shouldStop=!0}};var x=new c,b=new c;l.perBodyFilter=function(t,e){return 0!=(t.collisionFilterGroup&e.collisionFilterMask)&&0!=(e.collisionFilterGroup&t.collisionFilterMask)},l.perShapeFilter=function(t,e){return!(t.checkCollisionResponse&&!e.collisionResponse)}},{"../collision/AABB":3,"../collision/RaycastResult":11,"../math/Quaternion":29,"../math/Transform":30,"../math/Vec3":31,"../shapes/Box":38,"../shapes/ConvexPolyhedron":39,"../shapes/Shape":44}],11:[function(t,e,i){var o=t("../math/Vec3");function n(){this.rayFromWorld=new o,this.rayToWorld=new o,this.hitNormalWorld=new o,this.hitPointWorld=new o,this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this._shouldStop=!1}(e.exports=n).prototype.reset=function(){this.rayFromWorld.setZero(),this.rayToWorld.setZero(),this.hitNormalWorld.setZero(),this.hitPointWorld.setZero(),this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this._shouldStop=!1},n.prototype.abort=function(){this._shouldStop=!0},n.prototype.set=function(t,e,i,o,n,s,r){this.rayFromWorld.copy(t),this.rayToWorld.copy(e),this.hitNormalWorld.copy(i),this.hitPointWorld.copy(o),this.shape=n,this.body=s,this.distance=r}},{"../math/Vec3":31}],12:[function(t,e,i){t("../shapes/Shape");var o=t("../collision/Broadphase");function p(t){o.apply(this),this.axisList=[],this.world=null,this.axisIndex=0;var e=this.axisList;this._addBodyHandler=function(t){e.push(t.body)},this._removeBodyHandler=function(t){t=e.indexOf(t.body);-1!==t&&e.splice(t,1)},t&&this.setWorld(t)}((e.exports=p).prototype=new o).setWorld=function(t){for(var e=this.axisList.length=0;e<t.bodies.length;e++)this.axisList.push(t.bodies[e]);t.removeEventListener("addBody",this._addBodyHandler),t.removeEventListener("removeBody",this._removeBodyHandler),t.addEventListener("addBody",this._addBodyHandler),t.addEventListener("removeBody",this._removeBodyHandler),this.world=t,this.dirty=!0},p.insertionSortX=function(t){for(var e=1,i=t.length;e<i;e++){for(var o=t[e],n=e-1;0<=n&&!(t[n].aabb.lowerBound.x<=o.aabb.lowerBound.x);n--)t[n+1]=t[n];t[n+1]=o}return t},p.insertionSortY=function(t){for(var e=1,i=t.length;e<i;e++){for(var o=t[e],n=e-1;0<=n&&!(t[n].aabb.lowerBound.y<=o.aabb.lowerBound.y);n--)t[n+1]=t[n];t[n+1]=o}return t},p.insertionSortZ=function(t){for(var e=1,i=t.length;e<i;e++){for(var o=t[e],n=e-1;0<=n&&!(t[n].aabb.lowerBound.z<=o.aabb.lowerBound.z);n--)t[n+1]=t[n];t[n+1]=o}return t},p.prototype.collisionPairs=function(t,e,i){var o,n=this.axisList,s=n.length,r=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),o=0;o!==s;o++)for(var a=n[o],h=o+1;h<s;h++){var l=n[h];if(this.needBroadphaseCollision(a,l)){if(!p.checkBounds(a,l,r))break;this.intersectionTest(a,l,e,i)}}},p.prototype.sortList=function(){for(var t=this.axisList,e=this.axisIndex,i=t.length,o=0;o!==i;o++){var n=t[o];n.aabbNeedsUpdate&&n.computeAABB()}0===e?p.insertionSortX(t):1===e?p.insertionSortY(t):2===e&&p.insertionSortZ(t)},p.checkBounds=function(t,e,i){var o,n;0===i?(o=t.position.x,n=e.position.x):1===i?(o=t.position.y,n=e.position.y):2===i&&(o=t.position.z,n=e.position.z);t=t.boundingRadius,e=e.boundingRadius;return n-e<o+t},p.prototype.autoDetectAxis=function(){for(var t=0,e=0,i=0,o=0,n=0,s=0,r=this.axisList,a=r.length,h=1/a,l=0;l!==a;l++){var p=r[l],c=p.position.x;t+=c,e+=c*c;c=p.position.y;i+=c,o+=c*c;p=p.position.z;n+=p,s+=p*p}var u=e-t*t*h,d=o-i*i*h,h=s-n*n*h;this.axisIndex=d<u?h<u?0:2:h<d?1:2},p.prototype.aabbQuery=function(t,e,i){i=i||[],this.dirty&&(this.sortList(),this.dirty=!1);for(var o=this.axisIndex,o=2===o?"z":1===o?"y":"x",n=this.axisList,s=(e.lowerBound[o],e.upperBound[o],0);s<n.length;s++){var r=n[s];r.aabbNeedsUpdate&&r.computeAABB(),r.aabb.overlaps(e)&&i.push(r)}return i}},{"../collision/Broadphase":5,"../shapes/Shape":44}],13:[function(t,e,i){e.exports=o;t("./Constraint");var r=t("./PointToPointConstraint"),a=t("../equations/ConeEquation"),h=t("../equations/RotationalEquation"),l=(t("../equations/ContactEquation"),t("../math/Vec3"));function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,n=i.pivotA?i.pivotA.clone():new l,s=i.pivotB?i.pivotB.clone():new l;this.axisA=i.axisA?i.axisA.clone():new l,this.axisB=i.axisB?i.axisB.clone():new l,r.call(this,t,n,e,s,o),this.collideConnected=!!i.collideConnected,this.angle=void 0!==i.angle?i.angle:0;s=this.coneEquation=new a(t,e,i),e=this.twistEquation=new h(t,e,i);this.twistAngle=void 0!==i.twistAngle?i.twistAngle:0,s.maxForce=0,s.minForce=-o,e.maxForce=0,e.minForce=-o,this.equations.push(s,e)}o.prototype=new r,o.constructor=o;new l,new l;o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=this.coneEquation,o=this.twistEquation;r.prototype.update.call(this),t.vectorToWorldFrame(this.axisA,i.axisA),e.vectorToWorldFrame(this.axisB,i.axisB),this.axisA.tangents(o.axisA,o.axisA),t.vectorToWorldFrame(o.axisA,o.axisA),this.axisB.tangents(o.axisB,o.axisB),e.vectorToWorldFrame(o.axisB,o.axisB),i.angle=this.angle,o.maxAngle=this.twistAngle}},{"../equations/ConeEquation":19,"../equations/ContactEquation":20,"../equations/RotationalEquation":23,"../math/Vec3":31,"./Constraint":14,"./PointToPointConstraint":18}],14:[function(t,e,i){e.exports=n;var o=t("../utils/Utils");function n(t,e,i){i=o.defaults(i,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=t,this.bodyB=e,this.id=n.idCounter++,this.collideConnected=i.collideConnected,i.wakeUpBodies&&(t&&t.wakeUp(),e&&e.wakeUp())}n.prototype.update=function(){throw new Error("method update() not implmemented in this Constraint subclass!")},n.prototype.enable=function(){for(var t=this.equations,e=0;e<t.length;e++)t[e].enabled=!0},n.prototype.disable=function(){for(var t=this.equations,e=0;e<t.length;e++)t[e].enabled=!1},n.idCounter=0},{"../utils/Utils":54}],15:[function(t,e,i){e.exports=o;var n=t("./Constraint"),s=t("../equations/ContactEquation");function o(t,e,i,o){n.call(this,t,e),void 0===i&&(i=t.position.distanceTo(e.position)),void 0===o&&(o=1e6),this.distance=i;e=this.distanceEquation=new s(t,e);this.equations.push(e),e.minForce=-o,e.maxForce=o}(o.prototype=new n).update=function(){var t=this.bodyA,e=this.bodyB,i=this.distanceEquation,o=.5*this.distance,n=i.ni;e.position.vsub(t.position,n),n.normalize(),n.mult(o,i.ri),n.mult(-o,i.rj)}},{"../equations/ContactEquation":20,"./Constraint":14}],16:[function(t,e,i){e.exports=o;t("./Constraint");var l=t("./PointToPointConstraint"),r=t("../equations/RotationalEquation"),a=t("../equations/RotationalMotorEquation"),h=(t("../equations/ContactEquation"),t("../math/Vec3"));function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,n=i.pivotA?i.pivotA.clone():new h,s=i.pivotB?i.pivotB.clone():new h;l.call(this,t,n,e,s,o),(this.axisA=i.axisA?i.axisA.clone():new h(1,0,0)).normalize(),(this.axisB=i.axisB?i.axisB.clone():new h(1,0,0)).normalize();s=this.rotationalEquation1=new r(t,e,i),i=this.rotationalEquation2=new r(t,e,i),o=this.motorEquation=new a(t,e,o);o.enabled=!1,this.equations.push(s,i,o)}o.prototype=new l,(o.constructor=o).prototype.enableMotor=function(){this.motorEquation.enabled=!0},o.prototype.disableMotor=function(){this.motorEquation.enabled=!1},o.prototype.setMotorSpeed=function(t){this.motorEquation.targetVelocity=t},o.prototype.setMotorMaxForce=function(t){this.motorEquation.maxForce=t,this.motorEquation.minForce=-t};var p=new h,c=new h;o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=this.motorEquation,o=this.rotationalEquation1,n=this.rotationalEquation2,s=p,r=c,a=this.axisA,h=this.axisB;l.prototype.update.call(this),t.quaternion.vmult(a,s),e.quaternion.vmult(h,r),s.tangents(o.axisA,n.axisA),o.axisB.copy(r),n.axisB.copy(r),this.motorEquation.enabled&&(t.quaternion.vmult(this.axisA,i.axisA),e.quaternion.vmult(this.axisB,i.axisB))}},{"../equations/ContactEquation":20,"../equations/RotationalEquation":23,"../equations/RotationalMotorEquation":24,"../math/Vec3":31,"./Constraint":14,"./PointToPointConstraint":18}],17:[function(t,e,i){e.exports=o;t("./Constraint");var a=t("./PointToPointConstraint"),h=t("../equations/RotationalEquation"),l=(t("../equations/RotationalMotorEquation"),t("../equations/ContactEquation"),t("../math/Vec3"));function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,n=new l,s=new l,r=new l;t.position.vadd(e.position,r),r.scale(.5,r),e.pointToLocalFrame(r,s),t.pointToLocalFrame(r,n),a.call(this,t,n,e,s,o),this.xA=t.vectorToLocalFrame(l.UNIT_X),this.xB=e.vectorToLocalFrame(l.UNIT_X),this.yA=t.vectorToLocalFrame(l.UNIT_Y),this.yB=e.vectorToLocalFrame(l.UNIT_Y),this.zA=t.vectorToLocalFrame(l.UNIT_Z),this.zB=e.vectorToLocalFrame(l.UNIT_Z);s=this.rotationalEquation1=new h(t,e,i),o=this.rotationalEquation2=new h(t,e,i),i=this.rotationalEquation3=new h(t,e,i);this.equations.push(s,o,i)}o.prototype=new a,o.constructor=o;new l,new l;o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=(this.motorEquation,this.rotationalEquation1),o=this.rotationalEquation2,n=this.rotationalEquation3;a.prototype.update.call(this),t.vectorToWorldFrame(this.xA,i.axisA),e.vectorToWorldFrame(this.yB,i.axisB),t.vectorToWorldFrame(this.yA,o.axisA),e.vectorToWorldFrame(this.zB,o.axisB),t.vectorToWorldFrame(this.zA,n.axisA),e.vectorToWorldFrame(this.xB,n.axisB)}},{"../equations/ContactEquation":20,"../equations/RotationalEquation":23,"../equations/RotationalMotorEquation":24,"../math/Vec3":31,"./Constraint":14,"./PointToPointConstraint":18}],18:[function(t,e,i){e.exports=o;var s=t("./Constraint"),r=t("../equations/ContactEquation"),a=t("../math/Vec3");function o(t,e,i,o,n){s.call(this,t,i),n=void 0!==n?n:1e6,this.pivotA=e?e.clone():new a,this.pivotB=o?o.clone():new a;e=this.equationX=new r(t,i),o=this.equationY=new r(t,i),i=this.equationZ=new r(t,i);this.equations.push(e,o,i),e.minForce=o.minForce=i.minForce=-n,e.maxForce=o.maxForce=i.maxForce=n,e.ni.set(1,0,0),o.ni.set(0,1,0),i.ni.set(0,0,1)}(o.prototype=new s).update=function(){var t=this.bodyA,e=this.bodyB,i=this.equationX,o=this.equationY,n=this.equationZ;t.quaternion.vmult(this.pivotA,i.ri),e.quaternion.vmult(this.pivotB,i.rj),o.ri.copy(i.ri),o.rj.copy(i.rj),n.ri.copy(i.ri),n.rj.copy(i.rj)}},{"../equations/ContactEquation":20,"../math/Vec3":31,"./Constraint":14}],19:[function(t,e,i){e.exports=o;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6;s.call(this,t,e,-o,o),this.axisA=i.axisA?i.axisA.clone():new n(1,0,0),this.axisB=i.axisB?i.axisB.clone():new n(0,1,0),this.angle=void 0!==i.angle?i.angle:0}(o.prototype=new s).constructor=o;var l=new n,p=new n;o.prototype.computeB=function(t){var e=this.a,i=this.b,o=this.axisA,n=this.axisB,s=l,r=p,a=this.jacobianElementA,h=this.jacobianElementB;return o.cross(n,s),n.cross(o,r),a.rotational.copy(r),h.rotational.copy(s),-(Math.cos(this.angle)-o.dot(n))*e-this.computeGW()*i-t*this.computeGiMf()}},{"../math/Mat3":28,"../math/Vec3":31,"./Equation":21}],20:[function(t,e,i){e.exports=s;var o=t("./Equation"),n=t("../math/Vec3");t("../math/Mat3");function s(t,e,i){o.call(this,t,e,0,i=void 0!==i?i:1e6),this.si=null,this.sj=null,this.restitution=0,this.ri=new n,this.rj=new n,this.ni=new n}(s.prototype=new o).constructor=s;var m=new n,w=new n,g=new n;s.prototype.computeB=function(t){var e=this.a,i=this.b,o=this.bi,n=this.bj,s=this.ri,r=this.rj,a=m,h=w,l=o.velocity,p=o.angularVelocity,c=(o.force,o.torque,n.velocity),u=n.angularVelocity,d=(n.force,n.torque,g),v=this.jacobianElementA,y=this.jacobianElementB,f=this.ni;s.cross(f,a),r.cross(f,h),f.negate(v.spatial),a.negate(v.rotational),y.spatial.copy(f),y.rotational.copy(h),d.copy(n.position),d.vadd(r,d),d.vsub(o.position,d),d.vsub(s,d);s=f.dot(d),d=this.restitution+1;return-s*e-(d*c.dot(f)-d*l.dot(f)+u.dot(h)-p.dot(a))*i-t*this.computeGiMf()};var r=new n,a=new n,h=new n,l=new n,p=new n;s.prototype.getImpactVelocityAlongNormal=function(){var t=r,e=a,i=h,o=l,n=p;return this.bi.position.vadd(this.ri,i),this.bj.position.vadd(this.rj,o),this.bi.getVelocityAtWorldPoint(i,t),this.bj.getVelocityAtWorldPoint(o,e),t.vsub(e,n),this.ni.dot(n)}},{"../math/Mat3":28,"../math/Vec3":31,"./Equation":21}],21:[function(t,e,i){e.exports=s;var n=t("../math/JacobianElement"),t=t("../math/Vec3");function s(t,e,i,o){this.id=s.id++,this.minForce=void 0===i?-1e6:i,this.maxForce=void 0===o?1e6:o,this.bi=t,this.bj=e,this.a=0,this.b=0,this.eps=0,this.jacobianElementA=new n,this.jacobianElementB=new n,this.enabled=!0,this.multiplier=0,this.setSpookParams(1e7,4,1/60)}(s.prototype.constructor=s).id=0,s.prototype.setSpookParams=function(t,e,i){this.a=4/(i*(1+4*e)),this.b=4*e/(1+4*e),this.eps=4/(i*i*t*(1+4*e))},s.prototype.computeB=function(t,e,i){var o=this.computeGW();return-this.computeGq()*t-o*e-this.computeGiMf()*i},s.prototype.computeGq=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,i=i.position,o=o.position;return t.spatial.dot(i)+e.spatial.dot(o)};new t;s.prototype.computeGW=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.velocity,s=o.velocity,i=i.angularVelocity,o=o.angularVelocity;return t.multiplyVectors(n,i)+e.multiplyVectors(s,o)},s.prototype.computeGWlambda=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.vlambda,s=o.vlambda,i=i.wlambda,o=o.wlambda;return t.multiplyVectors(n,i)+e.multiplyVectors(s,o)};var p=new t,c=new t,u=new t,d=new t;s.prototype.computeGiMf=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.force,s=i.torque,r=o.force,a=o.torque,h=i.invMassSolve,l=o.invMassSolve;return n.scale(h,p),r.scale(l,c),i.invInertiaWorldSolve.vmult(s,u),o.invInertiaWorldSolve.vmult(a,d),t.multiplyVectors(p,u)+e.multiplyVectors(c,d)};var r=new t;s.prototype.computeGiMGt=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.invMassSolve,s=o.invMassSolve,i=i.invInertiaWorldSolve,o=o.invInertiaWorldSolve,s=n+s;return i.vmult(t.rotational,r),s+=r.dot(t.rotational),o.vmult(e.rotational,r),s+=r.dot(e.rotational)};var a=new t;new t,new t,new t,new t,new t;s.prototype.addToWlambda=function(t){var e=this.jacobianElementA,i=this.jacobianElementB,o=this.bi,n=this.bj,s=a;o.vlambda.addScaledVector(o.invMassSolve*t,e.spatial,o.vlambda),n.vlambda.addScaledVector(n.invMassSolve*t,i.spatial,n.vlambda),o.invInertiaWorldSolve.vmult(e.rotational,s),o.wlambda.addScaledVector(t,s,o.wlambda),n.invInertiaWorldSolve.vmult(i.rotational,s),n.wlambda.addScaledVector(t,s,n.wlambda)},s.prototype.computeC=function(){return this.computeGiMGt()+this.eps}},{"../math/JacobianElement":27,"../math/Vec3":31}],22:[function(t,e,i){e.exports=s;var o=t("./Equation"),n=t("../math/Vec3");t("../math/Mat3");function s(t,e,i){o.call(this,t,e,-i,i),this.ri=new n,this.rj=new n,this.t=new n}(s.prototype=new o).constructor=s;var a=new n,h=new n;s.prototype.computeB=function(t){this.a;var e=this.b,i=(this.bi,this.bj,this.ri),o=this.rj,n=a,s=h,r=this.t;i.cross(r,n),o.cross(r,s);i=this.jacobianElementA,o=this.jacobianElementB;return r.negate(i.spatial),n.negate(i.rotational),o.spatial.copy(r),o.rotational.copy(s),-this.computeGW()*e-t*this.computeGiMf()}},{"../math/Mat3":28,"../math/Vec3":31,"./Equation":21}],23:[function(t,e,i){e.exports=o;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6;s.call(this,t,e,-o,o),this.axisA=i.axisA?i.axisA.clone():new n(1,0,0),this.axisB=i.axisB?i.axisB.clone():new n(0,1,0),this.maxAngle=Math.PI/2}(o.prototype=new s).constructor=o;var l=new n,p=new n;o.prototype.computeB=function(t){var e=this.a,i=this.b,o=this.axisA,n=this.axisB,s=l,r=p,a=this.jacobianElementA,h=this.jacobianElementB;return o.cross(n,s),n.cross(o,r),a.rotational.copy(r),h.rotational.copy(s),-(Math.cos(this.maxAngle)-o.dot(n))*e-this.computeGW()*i-t*this.computeGiMf()}},{"../math/Mat3":28,"../math/Vec3":31,"./Equation":21}],24:[function(t,e,i){e.exports=s;var o=t("../math/Vec3"),n=(t("../math/Mat3"),t("./Equation"));function s(t,e,i){n.call(this,t,e,-(i=void 0!==i?i:1e6),i),this.axisA=new o,this.axisB=new o,this.targetVelocity=0}((s.prototype=new n).constructor=s).prototype.computeB=function(t){this.a;var e=this.b,i=(this.bi,this.bj,this.axisA),o=this.axisB,n=this.jacobianElementA,s=this.jacobianElementB;return n.rotational.copy(i),o.negate(s.rotational),-(this.computeGW()-this.targetVelocity)*e-t*this.computeGiMf()}},{"../math/Mat3":28,"../math/Vec3":31,"./Equation":21}],25:[function(t,e,i){var o=t("../utils/Utils");function n(t,e,i){i=o.defaults(i,{friction:.3,restitution:.3,contactEquationStiffness:1e7,contactEquationRelaxation:3,frictionEquationStiffness:1e7,frictionEquationRelaxation:3}),this.id=n.idCounter++,this.materials=[t,e],this.friction=i.friction,this.restitution=i.restitution,this.contactEquationStiffness=i.contactEquationStiffness,this.contactEquationRelaxation=i.contactEquationRelaxation,this.frictionEquationStiffness=i.frictionEquationStiffness,this.frictionEquationRelaxation=i.frictionEquationRelaxation}(e.exports=n).idCounter=0},{"../utils/Utils":54}],26:[function(t,e,i){function o(t){var e="";"string"==typeof(t=t||{})?(e=t,t={}):"object"==typeof t&&(e=""),this.name=e,this.id=o.idCounter++,this.friction=void 0!==t.friction?t.friction:-1,this.restitution=void 0!==t.restitution?t.restitution:-1,this.correctInelastic=0}(e.exports=o).idCounter=0},{}],27:[function(t,e,i){e.exports=n;var o=t("./Vec3");function n(){this.spatial=new o,this.rotational=new o}n.prototype.multiplyElement=function(t){return t.spatial.dot(this.spatial)+t.rotational.dot(this.rotational)},n.prototype.multiplyVectors=function(t,e){return t.dot(this.spatial)+e.dot(this.rotational)}},{"./Vec3":31}],28:[function(t,e,i){e.exports=l;var p=t("./Vec3");function l(t){this.elements=t||[0,0,0,0,0,0,0,0,0]}l.prototype.identity=function(){var t=this.elements;t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1},l.prototype.setZero=function(){var t=this.elements;t[0]=0,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=0,t[6]=0,t[7]=0,t[8]=0},l.prototype.setTrace=function(t){var e=this.elements;e[0]=t.x,e[4]=t.y,e[8]=t.z},l.prototype.getTrace=function(t){var t=t||new p,e=this.elements;t.x=e[0],t.y=e[4],t.z=e[8]},l.prototype.vmult=function(t,e){e=e||new p;var i=this.elements,o=t.x,n=t.y,t=t.z;return e.x=i[0]*o+i[1]*n+i[2]*t,e.y=i[3]*o+i[4]*n+i[5]*t,e.z=i[6]*o+i[7]*n+i[8]*t,e},l.prototype.smult=function(t){for(var e=0;e<this.elements.length;e++)this.elements[e]*=t},l.prototype.mmult=function(t,e){for(var i=e||new l,o=0;o<3;o++)for(var n=0;n<3;n++){for(var s=0,r=0;r<3;r++)s+=t.elements[o+3*r]*this.elements[r+3*n];i.elements[o+3*n]=s}return i},l.prototype.scale=function(t,e){e=e||new l;for(var i=this.elements,o=e.elements,n=0;3!==n;n++)o[3*n+0]=t.x*i[3*n+0],o[3*n+1]=t.y*i[3*n+1],o[3*n+2]=t.z*i[3*n+2];return e},l.prototype.solve=function(t,e){e=e||new p;for(var i,o=[],n=0;n<12;n++)o.push(0);for(n=0;n<3;n++)for(i=0;i<3;i++)o[n+4*i]=this.elements[n+3*i];o[3]=t.x,o[7]=t.y,o[11]=t.z;var s,r=3,a=r;do{if(0===o[(n=a-r)+4*n])for(i=n+1;i<a;i++)if(0!==o[n+4*i]){for(l=4;o[(s=4-l)+4*n]+=o[s+4*i],--l;);break}if(0!==o[n+4*n])for(i=n+1;i<a;i++)for(var h=o[n+4*i]/o[n+4*n],l=4;o[(s=4-l)+4*i]=s<=n?0:o[s+4*i]-o[s+4*n]*h,--l;);}while(--r);if(e.z=o[11]/o[10],e.y=(o[7]-o[6]*e.z)/o[5],e.x=(o[3]-o[2]*e.z-o[1]*e.y)/o[0],isNaN(e.x)||isNaN(e.y)||isNaN(e.z)||e.x===1/0||e.y===1/0||e.z===1/0)throw"Could not solve equation! Got x=["+e.toString()+"], b=["+t.toString()+"], A=["+this.toString()+"]";return e},l.prototype.e=function(t,e,i){if(void 0===i)return this.elements[e+3*t];this.elements[e+3*t]=i},l.prototype.copy=function(t){for(var e=0;e<t.elements.length;e++)this.elements[e]=t.elements[e];return this},l.prototype.toString=function(){for(var t="",e=0;e<9;e++)t+=this.elements[e]+",";return t},l.prototype.reverse=function(t){t=t||new l;for(var e,i=[],o=0;o<18;o++)i.push(0);for(o=0;o<3;o++)for(e=0;e<3;e++)i[o+6*e]=this.elements[o+3*e];i[3]=1,i[9]=0,i[15]=0,i[4]=0,i[10]=1,i[16]=0,i[5]=0,i[11]=0,i[17]=1;var n,s=3,r=s;do{if(0===i[(o=r-s)+6*o])for(e=o+1;e<r;e++)if(0!==i[o+6*e]){for(h=6;i[(n=6-h)+6*o]+=i[n+6*e],--h;);break}if(0!==i[o+6*o])for(e=o+1;e<r;e++)for(var a=i[o+6*e]/i[o+6*o],h=6;i[(n=6-h)+6*e]=n<=o?0:i[n+6*e]-i[n+6*o]*a,--h;);}while(--s);o=2;do{e=o-1;do{a=i[o+6*e]/i[o+6*o];for(h=6;i[(n=6-h)+6*e]=i[n+6*e]-i[n+6*o]*a,--h;);}while(e--)}while(--o);o=2;do{a=1/i[o+6*o];for(h=6;i[(n=6-h)+6*o]=i[n+6*o]*a,--h;);}while(o--);o=2;do{e=2;do{if(n=i[3+e+6*o],isNaN(n)||n===1/0)throw"Could not reverse! A=["+this.toString()+"]"}while(t.e(o,e,n),e--)}while(o--);return t},l.prototype.setRotationFromQuaternion=function(t){var e=t.x,i=t.y,o=t.z,n=t.w,s=e+e,r=i+i,a=o+o,h=e*s,l=e*r,t=e*a,e=i*r,i=i*a,o=o*a,s=n*s,r=n*r,n=n*a,a=this.elements;return a[0]=1-(e+o),a[1]=l-n,a[2]=t+r,a[3]=l+n,a[4]=1-(h+o),a[5]=i-s,a[6]=t-r,a[7]=i+s,a[8]=1-(h+e),this},l.prototype.transpose=function(t){for(var e=(t=t||new l).elements,i=this.elements,o=0;3!==o;o++)for(var n=0;3!==n;n++)e[3*o+n]=i[3*n+o];return t}},{"./Vec3":31}],29:[function(t,e,i){e.exports=d;var c=t("./Vec3");function d(t,e,i,o){this.x=void 0!==t?t:0,this.y=void 0!==e?e:0,this.z=void 0!==i?i:0,this.w=void 0!==o?o:1}d.prototype.set=function(t,e,i,o){return this.x=t,this.y=e,this.z=i,this.w=o,this},d.prototype.toString=function(){return this.x+","+this.y+","+this.z+","+this.w},d.prototype.toArray=function(){return[this.x,this.y,this.z,this.w]},d.prototype.setFromAxisAngle=function(t,e){var i=Math.sin(.5*e);return this.x=t.x*i,this.y=t.y*i,this.z=t.z*i,this.w=Math.cos(.5*e),this},d.prototype.toAxisAngle=function(t){t=t||new c,this.normalize();var e=2*Math.acos(this.w),i=Math.sqrt(1-this.w*this.w);return i<.001?(t.x=this.x,t.y=this.y,t.z=this.z):(t.x=this.x/i,t.y=this.y/i,t.z=this.z/i),[t,e]};var o=new c,n=new c;d.prototype.setFromVectors=function(t,e){var i;return t.isAntiparallelTo(e)?(t.tangents(i=o,n),this.setFromAxisAngle(i,Math.PI)):(i=t.cross(e),this.x=i.x,this.y=i.y,this.z=i.z,this.w=Math.sqrt(Math.pow(t.norm(),2)*Math.pow(e.norm(),2))+t.dot(e),this.normalize()),this};new c,new c,new c;d.prototype.mult=function(t,e){e=e||new d;var i=this.x,o=this.y,n=this.z,s=this.w,r=t.x,a=t.y,h=t.z,t=t.w;return e.x=i*t+s*r+o*h-n*a,e.y=o*t+s*a+n*r-i*h,e.z=n*t+s*h+i*a-o*r,e.w=s*t-i*r-o*a-n*h,e},d.prototype.inverse=function(t){var e=this.x,i=this.y,o=this.z,n=this.w;t=t||new d,this.conjugate(t);n=1/(e*e+i*i+o*o+n*n);return t.x*=n,t.y*=n,t.z*=n,t.w*=n,t},d.prototype.conjugate=function(t){return(t=t||new d).x=-this.x,t.y=-this.y,t.z=-this.z,t.w=this.w,t},d.prototype.normalize=function(){var t=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);return 0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=t=1/t,this.y*=t,this.z*=t,this.w*=t),this},d.prototype.normalizeFast=function(){var t=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;return 0==t?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=t,this.y*=t,this.z*=t,this.w*=t),this},d.prototype.vmult=function(t,e){e=e||new c;var i=t.x,o=t.y,n=t.z,s=this.x,r=this.y,a=this.z,h=this.w,l=h*i+r*n-a*o,p=h*o+a*i-s*n,t=h*n+s*o-r*i,n=-s*i-r*o-a*n;return e.x=l*h+n*-s+p*-a-t*-r,e.y=p*h+n*-r+t*-s-l*-a,e.z=t*h+n*-a+l*-r-p*-s,e},d.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},d.prototype.toEuler=function(t,e){e=e||"YZX";var i=this.x,o=this.y,n=this.z,s=this.w;if("YZX"!==e)throw new Error("Euler order "+e+" not supported yet.");var r,a,h,l,p=i*o+n*s;.499<p&&(a=2*Math.atan2(i,s),h=Math.PI/2,l=0),p<-.499&&(a=-2*Math.atan2(i,s),h=-Math.PI/2,l=0),isNaN(a)&&(r=i*i,e=n*n,a=Math.atan2(2*o*s-2*i*n,1-2*(o*o)-2*e),h=Math.asin(2*p),l=Math.atan2(2*i*s-2*o*n,1-2*r-2*e)),t.y=a,t.z=h,t.x=l},d.prototype.setFromEuler=function(t,e,i,o){o=o||"XYZ";var n=Math.cos(t/2),s=Math.cos(e/2),r=Math.cos(i/2),t=Math.sin(t/2),e=Math.sin(e/2),i=Math.sin(i/2);return"XYZ"===o?(this.x=t*s*r+n*e*i,this.y=n*e*r-t*s*i,this.z=n*s*i+t*e*r,this.w=n*s*r-t*e*i):"YXZ"===o?(this.x=t*s*r+n*e*i,this.y=n*e*r-t*s*i,this.z=n*s*i-t*e*r,this.w=n*s*r+t*e*i):"ZXY"===o?(this.x=t*s*r-n*e*i,this.y=n*e*r+t*s*i,this.z=n*s*i+t*e*r,this.w=n*s*r-t*e*i):"ZYX"===o?(this.x=t*s*r-n*e*i,this.y=n*e*r+t*s*i,this.z=n*s*i-t*e*r,this.w=n*s*r+t*e*i):"YZX"===o?(this.x=t*s*r+n*e*i,this.y=n*e*r+t*s*i,this.z=n*s*i-t*e*r,this.w=n*s*r-t*e*i):"XZY"===o&&(this.x=t*s*r-n*e*i,this.y=n*e*r-t*s*i,this.z=n*s*i+t*e*r,this.w=n*s*r+t*e*i),this},d.prototype.clone=function(){return new d(this.x,this.y,this.z,this.w)},d.prototype.slerp=function(t,e,i){i=i||new d;var o,n=this.x,s=this.y,r=this.z,a=this.w,h=t.x,l=t.y,p=t.z,c=t.w,u=n*h+s*l+r*p+a*c;return u<0&&(u=-u,h=-h,l=-l,p=-p,c=-c),e=1e-6<1-u?(t=Math.acos(u),u=Math.sin(t),o=Math.sin((1-e)*t)/u,Math.sin(e*t)/u):(o=1-e,e),i.x=o*n+e*h,i.y=o*s+e*l,i.z=o*r+e*p,i.w=o*a+e*c,i},d.prototype.integrate=function(t,e,i,o){o=o||new d;var n=t.x*i.x,s=t.y*i.y,r=t.z*i.z,a=this.x,h=this.y,t=this.z,i=this.w,e=.5*e;return o.x+=e*(n*i+s*t-r*h),o.y+=e*(s*i+r*a-n*t),o.z+=e*(r*i+n*h-s*a),o.w+=e*(-n*a-s*h-r*t),o},d.prototype.euqals=function(t){return this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w}},{"./Vec3":31}],30:[function(t,e,i){var n=t("./Vec3"),o=t("./Quaternion");function s(t){t=t||{},this.position=new n,t.position&&this.position.copy(t.position),this.quaternion=new o,t.quaternion&&this.quaternion.copy(t.quaternion)}e.exports=s;var r=new o;s.pointToLocalFrame=function(t,e,i,o){o=o||new n;return i.vsub(t,o),e.conjugate(r),r.vmult(o,o),o},s.prototype.pointToLocal=function(t,e){return s.pointToLocalFrame(this.position,this.quaternion,t,e)},s.pointToWorldFrame=function(t,e,i,o){o=o||new n;return e.vmult(i,o),o.vadd(t,o),o},s.prototype.pointToWorld=function(t,e){return s.pointToWorldFrame(this.position,this.quaternion,t,e)},s.prototype.vectorToWorldFrame=function(t,e){e=e||new n;return this.quaternion.vmult(t,e),e},s.vectorToWorldFrame=function(t,e,i){return t.vmult(e,i),i},s.vectorToLocalFrame=function(t,e,i,o){o=o||new n;return e.w*=-1,e.vmult(i,o),e.w*=-1,o}},{"./Quaternion":29,"./Vec3":31}],31:[function(t,e,i){e.exports=a;var o=t("./Mat3");function a(t,e,i){this.x=t||0,this.y=e||0,this.z=i||0}a.ZERO=new a(0,0,0),a.UNIT_X=new a(1,0,0),a.UNIT_Y=new a(0,1,0),a.UNIT_Z=new a(0,0,1),a.prototype.cross=function(t,e){var i=t.x,o=t.y,n=t.z,s=this.x,r=this.y,t=this.z;return(e=e||new a).x=r*n-t*o,e.y=t*i-s*n,e.z=s*o-r*i,e},a.prototype.set=function(t,e,i){return this.x=t,this.y=e,this.z=i,this},a.prototype.setZero=function(){this.x=this.y=this.z=0},a.prototype.vadd=function(t,e){if(!e)return new a(this.x+t.x,this.y+t.y,this.z+t.z);e.x=t.x+this.x,e.y=t.y+this.y,e.z=t.z+this.z},a.prototype.vsub=function(t,e){if(!e)return new a(this.x-t.x,this.y-t.y,this.z-t.z);e.x=this.x-t.x,e.y=this.y-t.y,e.z=this.z-t.z},a.prototype.crossmat=function(){return new o([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},a.prototype.normalize=function(){var t=this.x,e=this.y,i=this.z,e=Math.sqrt(t*t+e*e+i*i);return 0<e?(this.x*=i=1/e,this.y*=i,this.z*=i):(this.x=0,this.y=0,this.z=0),e},a.prototype.unit=function(t){t=t||new a;var e=this.x,i=this.y,o=this.z,n=Math.sqrt(e*e+i*i+o*o);return 0<n?(t.x=e*(n=1/n),t.y=i*n,t.z=o*n):(t.x=1,t.y=0,t.z=0),t},a.prototype.length=a.prototype.norm=function(){var t=this.x,e=this.y,i=this.z;return Math.sqrt(t*t+e*e+i*i)},a.prototype.lengthSquared=a.prototype.norm2=function(){return this.dot(this)},a.prototype.distanceTo=function(t){var e=this.x,i=this.y,o=this.z,n=t.x,s=t.y,t=t.z;return Math.sqrt((n-e)*(n-e)+(s-i)*(s-i)+(t-o)*(t-o))},a.prototype.distanceSquared=function(t){var e=this.x,i=this.y,o=this.z,n=