text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).AMMO={})}(this,(function(t){"use strict";var e=function(t){var e,r=Object.prototype,o=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",n=i.asyncIterator||"@@asyncIterator",a=i.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function m(t,e,r,o){var i=e&&e.prototype instanceof y?e:y,s=Object.create(i.prototype),n=new C(o||[]);return s._invoke=function(t,e,r){var o=h;return function(i,s){if(o===p)throw new Error("Generator is already running");if(o===d){if("throw"===i)throw s;return V()}for(r.method=i,r.arg=s;;){var n=r.delegate;if(n){var a=S(n,r);if(a){if(a===f)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===h)throw o=d,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=p;var l=c(t,e,r);if("normal"===l.type){if(o=r.done?d:u,l.arg===f)continue;return{value:l.arg,done:r.done}}"throw"===l.type&&(o=d,r.method="throw",r.arg=l.arg)}}}(t,r,n),s}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=m;var h="suspendedStart",u="suspendedYield",p="executing",d="completed",f={};function y(){}function g(){}function v(){}var b={};b[s]=function(){return this};var A=Object.getPrototypeOf,w=A&&A(A(M([])));w&&w!==r&&o.call(w,s)&&(b=w);var x=v.prototype=y.prototype=Object.create(b);function _(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){function r(i,s,n,a){var l=c(t[i],t,s);if("throw"!==l.type){var m=l.arg,h=m.value;return h&&"object"==typeof h&&o.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,n,a)}),(function(t){r("throw",t,n,a)})):e.resolve(h).then((function(t){m.value=t,n(m)}),(function(t){return r("throw",t,n,a)}))}a(l.arg)}var i;this._invoke=function(t,o){function s(){return new e((function(e,i){r(t,o,e,i)}))}return i=i?i.then(s,s):s()}}function S(t,r){var o=t.iterator[r.method];if(o===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,S(t,r),"throw"===r.method))return f;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var i=c(o,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,f;var s=i.arg;return s?s.done?(r[t.resultName]=s.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,f):s:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,f)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function M(t){if(t){var r=t[s];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,n=function r(){for(;++i<t.length;)if(o.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return n.next=n}}return{next:V}}function V(){return{value:e,done:!0}}return g.prototype=x.constructor=v,v.constructor=g,g.displayName=l(v,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,l(t,a,"GeneratorFunction")),t.prototype=Object.create(x),t},t.awrap=function(t){return{__await:t}},_(k.prototype),k.prototype[n]=function(){return this},t.AsyncIterator=k,t.async=function(e,r,o,i,s){void 0===s&&(s=Promise);var n=new k(m(e,r,o,i),s);return t.isGeneratorFunction(r)?n:n.next().then((function(t){return t.done?t.value:n.next()}))},_(x),l(x,a,"Generator"),x[s]=function(){return this},x.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var o=e.pop();if(o in t)return r.value=o,r.done=!1,r}return r.done=!0,r}},t.values=M,C.prototype={constructor:C,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(L),!t)for(var r in this)"t"===r.charAt(0)&&o.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(o,i){return a.type="throw",a.arg=t,r.next=o,i&&(r.method="next",r.arg=e),!!i}for(var s=this.tryEntries.length-1;s>=0;--s){var n=this.tryEntries[s],a=n.completion;if("root"===n.tryLoc)return i("end");if(n.tryLoc<=this.prev){var l=o.call(n,"catchLoc"),m=o.call(n,"finallyLoc");if(l&&m){if(this.prev<n.catchLoc)return i(n.catchLoc,!0);if(this.prev<n.finallyLoc)return i(n.finallyLoc)}else if(l){if(this.prev<n.catchLoc)return i(n.catchLoc,!0)}else{if(!m)throw new Error("try statement without catch or finally");if(this.prev<n.finallyLoc)return i(n.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&o.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var s=i;break}}s&&("break"===t||"continue"===t)&&s.tryLoc<=e&&e<=s.finallyLoc&&(s=null);var n=s?s.completion:{};return n.type=t,n.arg=e,s?(this.method="next",this.next=s.finallyLoc,f):this.complete(n)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var o=r.completion;if("throw"===o.type){var i=o.arg;L(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,o){return this.delegate={iterator:M(t),resultName:r,nextLoc:o},"next"===this.method&&(this.arg=e),f}},t}("object"==typeof module?module.exports:{});try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}const r=new Map,o={world:null,delta:0,substep:1,flow:{tmp:[],key:[]},reflow:{ray:[],stat:{fps:0,delta:0}}},i=Math.PI/180;class s{static clear(){r.clear()}static byName(t){return r.has(t)?r.get(t):null}static add(t){if("ray"!==t.type&&"contact"!==t.type)switch(t.type){case"joint":o.world.addConstraint(t,!t.collision);break;case"solid":o.world.addCollisionObject(t,t.group,t.mask);break;default:o.world.addRigidBody(t,t.group,t.mask)}r.set(t.name,t)}static remove(t){if("ray"!==t.type&&"contact"!==t.type){switch(t.type){case"joint":o.world.removeConstraint(t),Ammo.destroy(t.formA),Ammo.destroy(t.formB);break;case"solid":o.world.removeCollisionObject(t);break;default:o.world.removeRigidBody(t)}Ammo.destroy(t)}r.delete(t.name)}static getConvexVolume(t){let e,r=t.length/3,o=[t[0],t[1],t[2]],i=[t[0],t[1],t[2]];for(;r--;)e=3*r,t[e]<o[0]?o[0]=t[e]:t[e]>i[0]&&(i[0]=t[e]),t[e+1]<o[1]?o[1]=t[e+1]:t[e+1]>i[1]&&(i[1]=t[e+1]),t[e+2]<o[2]?o[2]=t[e+2]:t[e+2]>i[2]&&(i[2]=t[e+2]);return(i[0]-o[0])*(i[1]-o[1])*(i[2]-o[2])}static stats(){}static extends(){Ammo.btVector3.prototype.set=function(t,e,r){return this.setValue(t,e,r),this},Ammo.btVector3.prototype.toArray=function(t,e){let r=void 0!==t;if(r||(t=[]),t[e=e||0]=this.x(),t[e+1]=this.y(),t[e+2]=this.z(),!r)return t},Ammo.btVector3.prototype.fromArray=function(t,e){return e=e||0,this.setValue(t[e],t[e+1],t[e+2]),this},Ammo.btVector3.prototype.copy=function(t){return this.setValue(t.x(),t.y(),t.z()),this},Ammo.btVector3.prototype.mul=function(){return this.x()*this.y()*this.z()},Ammo.btVector3.prototype.multiplyScalar=function(t){return this.setValue(this.x()*t,this.y()*t,this.z()*t),this},Ammo.btVector3.prototype.divideScalar=function(t){return this.multiplyScalar(1/t)},Ammo.btVector3.prototype.applyMatrix3=function(t){const e=this.x(),r=this.y(),o=this.z(),i=[];return t.getRow(0).toArray(i,0),t.getRow(1).toArray(i,3),t.getRow(2).toArray(i,6),this.setValue(i[0]*e+i[3]*r+i[6]*o,i[1]*e+i[4]*r+i[7]*o,i[2]*e+i[5]*r+i[8]*o),this},Ammo.btQuaternion.prototype.set=function(t,e,r,o){return this.setValue(t,e,r,o),this},Ammo.btQuaternion.prototype.toArray=function(t,e){let r=void 0!==t;if(r||(t=[]),t[e=e||0]=this.x(),t[e+1]=this.y(),t[e+2]=this.z(),t[e+3]=this.w(),!r)return t},Ammo.btQuaternion.prototype.fromArray=function(t,e){return e=e||0,this.setValue(t[e],t[e+1],t[e+2],t[e+3]),this},Ammo.btQuaternion.prototype.fromAxisAngle=function(t,e){var r=.5*e,o=Math.sin(r);return this.setValue(t[0]*o,t[1]*o,t[2]*o,Math.cos(r)),this},Ammo.btQuaternion.prototype.fromAxis=function(t){let e=t.toArray();if(e[2]>.99999)this.setValue(0,0,0,1);else if(e[2]<-.99999)this.setValue(1,0,0,0);else{let t=[e[1],e[0],0],r=Math.acos(e[2]);this.fromAxisAngle(t,r)}return this},Ammo.btTransform.prototype.set=function(t,e){return this.setOrigin(t),this.setRotation(e),this},Ammo.btTransform.prototype.identity=function(){return this.setIdentity(),this},Ammo.btTransform.prototype.fromArray=function(t,e,r,o){let i=this.getOrigin();i.fromArray(t||[0,0,0],r||0),this.setOrigin(i);let s=this.getRotation();return s.fromArray(e||[0,0,0,1],o||0),this.setRotation(s),this},Ammo.btTransform.prototype.toArray=function(t,e){e=e||0,this.getOrigin().toArray(t,e),this.getRotation().toArray(t,e+3)},Ammo.btTransform.prototype.getPos=function(){return this.getOrigin().toArray()},Ammo.btTransform.prototype.getQuat=function(){return this.getRotation().toArray()},Ammo.btTransform.prototype.copy=function(t){return this.op_set(t),this},Ammo.btTransform.prototype.rotationFromAxis=function(t){let e=this.getRotation();return e.fromAxis(t),this.setRotation(e),this}}}class n{constructor(){this.id=0,this.list=[],this.type="item",this.Utils=null}reset(){let t=this.list.length;for(;t--;)this.dispose(this.list[t]);this.id=0,this.list=[]}byName(t){return this.Utils.byName(t)}setName(t={}){let e=void 0!==t.name?t.name:this.type+this.id++;return t.id=this.remove(e,!0),e}addToWorld(t,e=-1){this.Utils.add(t),-1!==e?this.list[e]=t:this.list.push(t)}remove(t,e){let r=this.byName(t);return r?this.clear(r,e):-1}clear(t,e){let r=this.list.indexOf(t);return-1===r||e?this.list[r]=null:this.list.splice(r,1),this.dispose(t),r}dispose(t){null!==t&&this.Utils.remove(t)}add(t={}){}set(t={}){}step(t,e){}}class a extends n{constructor(){super(),this.Utils=s,this.type="body",this.v=new Ammo.btVector3,this.vv=new Ammo.btVector3,this.q=new Ammo.btQuaternion,this.t=new Ammo.btTransform,this.v1=new Ammo.btVector3,this.v2=new Ammo.btVector3,this.v3=new Ammo.btVector3}step(t,e){let r,o,i,s=this.list.length;for(;s--;)r=this.list[s],o=e+11*s,r?(i=r.getLinearVelocity(),t[o]=2===r.getMotionState()?0:9.8*i.length(),r.getMotionState().getWorldTransform(this.t),this.t.toArray(t,o+1),i.toArray(t,o+8)):t[o]=t[o+1]=t[o+2]=t[o+3]=t[o+4]=t[o+5]=t[o+6]=t[o+7]=0}shape(t={}){let e,r,o,i=t.type||"box",n=t.size||[1,1,1],a=1;switch(i){case"plane":e=new Ammo.btStaticPlaneShape(this.v.fromArray(t.dir||[0,1,0]),0);break;case"box":e=new Ammo.btBoxShape(this.v.set(.5*n[0],.5*n[1],.5*n[2])),a=8*this.v.mul();break;case"sphere":e=new Ammo.btSphereShape(n[0]),a=4*Math.PI*n[0]*n[0]*n[0]/3;break;case"cone":e=new Ammo.btConeShape(n[0],n[1]),a=Math.PI*n[0]*(.5*n[1])*2;break;case"cylinder":e=new Ammo.btCylinderShape(this.v.set(n[0],.5*n[1],n[0])),a=Math.PI*n[0]*n[0]*(.5*n[1])*2;break;case"capsule":e=new Ammo.btCapsuleShape(n[0],n[1]),a=4*Math.PI*n[0]*n[0]*n[0]/3+Math.PI*n[0]*n[0]*(.5*n[1])*2;break;case"convex":let i=void 0===t.optimize||t.optimize;for(e=new Ammo.btConvexHullShape,r=Math.floor(t.v.length/3);r--;)o=3*r,e.addPoint(this.v.fromArray(t.v,o),!0);i&&(e.optimizeConvexHull(),e.recalcLocalAabb(),e.initializePolyhedralFeatures(1)),a=s.getConvexVolume(t.v);break;case"mesh":let l=new Ammo.btTriangleMesh,m=!1,c=t.v,h=t.index||null,u=c.length;if(null!==h){for(u=c.length,r=0;r<u;r+=3)l.findOrAddVertex(this.v.set(c[r],c[r+1],c[r+2]),!1);for(u=h.length,r=0;r<u;r+=3)l.addTriangleIndices(h[r],h[r+1],h[r+2])}else for(r=0;r<u;r+=9)l.addTriangle(this.v1.set(c[r+0],c[r+1],c[r+2]),this.v2.set(c[r+3],c[r+4],c[r+5]),this.v3.set(c[r+6],c[r+7],c[r+8]),m);"solid"===this.type?(e=new Ammo.btBvhTriangleMeshShape(l,!0,!0),a=1):(e=new Ammo.btConvexTriangleMeshShape(l,!0),a=s.getConvexVolume(t.v))}return e.setMargin&&e.setMargin(t.margin||1e-4),e.volume=a,e}add(t={}){let e=this.setName(t),r=void 0!==t.flag?t.flag:"solid"===this.type?1:0,o=void 0!==t.group?t.group:"solid"===this.type?2:1,i=void 0!==t.mask?t.mask:-1;t.kinematic&&(r=2,o=4);let s=null;switch(t.type){case"null":i=0,s=this.shape({type:"sphere",size:[.01]});break;case"compound":let e,r;s=new Ammo.btCompoundShape,s.volume=0;for(var n=0;n<t.shapes.length;n++)e=t.shapes[n],this.t.fromArray(e.pos,e.quat),r=this.shape(e),s.volume+=r.volume,s.addChildShape(this.t,r);break;default:s=this.shape(t)}this.t.fromArray(t.pos,t.quat),this.v.set(0,0,0);let a=(t.density||0)*s.volume;0!==a&&s.calculateLocalInertia(a,this.v);let l=new Ammo.btDefaultMotionState(this.t),m=new Ammo.btRigidBodyConstructionInfo(a,l,s,this.v),c=new Ammo.btRigidBody(m);c.setCollisionFlags(r),Ammo.destroy(m),c.name=e,c.type=this.type,c.isKinematic=t.kinematic||!1,c.isGhost=!1,c.group=o,c.mask=i,c.first=!0,delete t.pos,delete t.quat,this.set(t,c),this.addToWorld(c,t.id)}set(t={},e=null){null===e&&(e=this.byName(t.name)),null!==e&&(void 0!==t.flag&&(e.setCollisionFlags(t.flag),e.isKinematic=2===t.flag),t.noGravity&&e.setGravity(this.v.fromArray([0,0,0])),(t.pos||t.quat)&&(t.pos&&t.quat||e.getMotionState().getWorldTransform(this.t),t.pos||(t.pos=this.t.getPos()),t.quat||(t.quat=this.t.getQuat()),this.t.fromArray(t.pos,t.quat),e.isKinematic?e.getMotionState().setWorldTransform(this.t):e.setWorldTransform(this.t)),void 0!==t.state&&e.setActivationState(t.state),(t.activate||t.wake)&&e.activate(),t.neverSleep&&(e.setSleepingThresholds(0,0),e.setActivationState(4)),t.sleep&&e.setActivationState(2),void 0!==t.friction&&e.setFriction(t.friction),void 0!==t.restitution&&e.setRestitution(t.restitution),void 0!==t.rollingFriction&&e.setRollingFriction(t.rollingFriction),t.reset&&(e.setLinearVelocity(this.v.set(0,0,0)),e.setAngularVelocity(this.v.set(0,0,0))),e.isGhost||(void 0!==t.group&&(e.getBroadphaseProxy().set_m_collisionFilterGroup(t.group),e.group=t.group),void 0!==t.mask&&(e.getBroadphaseProxy().set_m_collisionFilterMask(t.mask),e.mask=t.mask),void 0!==t.damping&&e.setDamping(t.damping[0],t.damping[1]),void 0!==t.sleeping&&e.setSleepingThresholds(t.sleeping[0],t.sleeping[1])),void 0!==t.linearVelocity&&e.setLinearVelocity(this.v.fromArray(t.linearVelocity)),void 0!==t.angularVelocity&&e.setAngularVelocity(this.v.fromArray(t.angularVelocity)),void 0!==t.linearFactor&&e.setLinearFactor(this.v.fromArray(t.linearFactor)),void 0!==t.angularFactor&&e.setAngularFactor(this.v.fromArray(t.angularFactor)),void 0!==t.anisotropic&&e.setAnisotropicFriction(t.anisotropic[0],t.anisotropic[1]),void 0!==t.massProps&&e.setMassProps(t.massProps[0],t.massProps[1]),void 0!==t.ccdThreshold&&e.setCcdMotionThreshold(t.ccdThreshold),void 0!==t.ccdRadius&&e.setCcdSweptSphereRadius(t.ccdRadius),void 0!==t.gravity&&e.setGravity(this.v.fromArray(t.gravity)),t.worldForce&&e.applyForce(this.v.fromArray(t.worldForce),this.v.fromArray(t.worldForce,3)),t.force&&e.applyForce(this.v.fromArray(t.force).divideScalar(o.substep)),t.torque&&e.applyTorque(this.v.fromArray(t.torque).divideScalar(o.substep)),t.linearImpulse&&(t.impulseCentral=t.linearImpulse),t.impulseCentral&&e.applyCentralImpulse(this.v.fromArray(t.impulseCentral)),t.impulse&&e.applyImpulse(this.v.fromArray(t.impulse),this.v.fromArray(t.impulse,3)))}}class l extends a{constructor(){super(),this.type="solid"}step(t,e){}}class m extends n{constructor(){super(),this.Utils=s,this.type="joint",this.t=new Ammo.btTransform,this.t1=new Ammo.btTransform,this.t2=new Ammo.btTransform,this.v1=new Ammo.btVector3,this.v2=new Ammo.btVector3,this.p1=new Ammo.btVector3,this.p2=new Ammo.btVector3,this.q1=new Ammo.btQuaternion,this.q2=new Ammo.btQuaternion}step(t,e){let r,o,i=this.list.length;for(;i--;)r=this.list[i],o=e+16*i,r.visible&&(this.t.copy(r.getRigidBodyA().getWorldTransform()).op_mul(r.formA).toArray(t,o),this.t.copy(r.getRigidBodyB().getWorldTransform()).op_mul(r.formB).toArray(t,o+7))}add(t={}){this.v;let e=this.setName(t);const r=this.byName(t.b1),o=this.byName(t.b2);let i=this.v1.fromArray(t.pos1||[0,0,0]),s=this.v2.fromArray(t.pos2||[0,0,0]),n=this.q1.fromArray(t.quat1||[0,0,0,1]),a=this.q2.fromArray(t.quat2||[0,0,0,1]),l=this.p1.fromArray(t.axis1||[0,0,1]),m=this.p2.fromArray(t.axis2||[0,0,1]);t.quat1||n.fromAxis(l),t.quat2||a.fromAxis(m),this.t1.identity(),this.t2.identity();const c=t.useA||!1;(t.worldAnchor||t.worldAxis)&&(r&&(r.activate(),r.getMotionState().getWorldTransform(this.t1)),o&&(o.activate(),o.getMotionState().getWorldTransform(this.t2))),t.worldAnchor&&(i=this.v1.fromArray(t.worldAnchor).op_sub(this.t1.getOrigin()),s=this.v2.fromArray(t.worldAnchor).op_sub(this.t2.getOrigin()),i.applyMatrix3(this.t1.getBasis()),s.applyMatrix3(this.t2.getBasis())),t.worldAxis&&(l=this.p1.fromArray(t.worldAxis),m=this.p2.fromArray(t.worldAxis),l.applyMatrix3(this.t1.getBasis()),m.applyMatrix3(this.t2.getBasis()),n.fromAxis(l),a.fromAxis(m));const h=(new Ammo.btTransform).set(i,n),u=(new Ammo.btTransform).set(s,a);let p,d=t.mode||"revolute";switch("d6"===d&&(d="dof"),"slider"===d&&(d="prismatic"),"joint_p2p"===d&&(d="spherical"),"conetwist"===d&&(d="ragdoll"),d){case"spherical":p=new Ammo.btPoint2PointConstraint(r,o,i,s),t.strength&&p.get_m_setting().set_m_tau(t.strength),t.damping&&p.get_m_setting().set_m_damping(t.damping),t.impulse&&p.get_m_setting().set_m_impulseClamp(t.impulse);break;case"hinge2":p=new Ammo.btHinge2Constraint(r,o,i,l,m);break;case"hinge":case"revolute":p=new Ammo.btHingeConstraint(r,o,h,u,c);break;case"prismatic":p=new Ammo.btSliderConstraint(r,o,h,u,c);break;case"ragdoll":p=new Ammo.btConeTwistConstraint(r,o,h,u);break;case"dof":p=new Ammo.btGeneric6DofSpringConstraint(r,o,h,u,c),p.setAngularLowerLimit(this.v1.fromArray([0,0,0])),p.setAngularUpperLimit(this.v1.fromArray([0,0,0]));break;case"fixe":p=new Ammo.btFixedConstraint(r,o,h,u);break;case"gear":p=new Ammo.btGearConstraint(r,o,l,m,t.ratio||1)}p.name=e,p.mode=d,p.type=this.type,p.formA=h,p.formB=u,p.visible=void 0===t.visible||t.visible,p.collision=t.collision||!1,this.set(t,p),this.addToWorld(p,t.id)}set(t={},e=null){if(null===e&&(e=this.byName(t.name)),null===e)return;let r,o,s,n;t.breaking&&e.setBreakingImpulseThreshold&&e.setBreakingImpulseThreshold(t.breaking),t.iteration&&e.setOverrideNumSolverIterations&&e.setOverrideNumSolverIterations(t.iteration);const a=["x","y","z","rx","ry","rz"];switch(e.mode){case"prismatic":break;case"hinge":case"revolute":t.lm&&e.setLimit(t.lm[0]*i,t.lm[1]*i,t.lm[2]||.9,t.lm[3]||.3,t.lm[4]||1),t.motor&&e.enableAngularMotor(!0,t.motor[0]*i,t.motor[1]);break;case"dof":case"sdof":if(t.motor)for(r=t.motor.length;r--;)o=t.motor[r],"rx"===o[0]&&(s=e.getRotationalLimitMotor(0)),"ry"===o[0]&&(s=e.getRotationalLimitMotor(1)),"rz"===o[0]&&(s=e.getRotationalLimitMotor(2)),s&&(s.set_m_enableMotor(!0),s.set_m_targetVelocity(-o[1]*i),s.set_m_maxMotorForce(o[2]));if(t.lm){for(s=[[0,0,0],[0,0,0],[0,0,0],[0,0,0]],r=t.lm.length;r--;)o=t.lm[r],"rx"===o[0]&&(s[0][0]=o[1]*i,s[1][0]=o[2]*i),"ry"===o[0]&&(s[0][1]=o[1]*i,s[1][1]=o[2]*i),"rz"===o[0]&&(s[0][2]=o[1]*i,s[1][2]=o[2]*i),"x"===o[0]&&(s[2][0]=o[1],s[3][0]=o[2]),"y"===o[0]&&(s[2][1]=o[1],s[3][1]=o[2]),"z"===o[0]&&(s[2][2]=o[1],s[3][2]=o[2]);e.setAngularLowerLimit(this.v1.fromArray(s[0])),e.setAngularUpperLimit(this.v1.fromArray(s[1])),e.setLinearLowerLimit(this.v1.fromArray(s[2])),e.setLinearUpperLimit(this.v1.fromArray(s[3]))}if(t.sd)for(r=t.sd.length;r--;)o=t.sd[r],n=a.indexOf(o[0]),console.log(e),e.setStiffness(n,o[1]),e.setDamping(n,o[2]),e.enableSpring(n,!0),o[3]&&e.setEquilibriumPoint(n)}}}class c extends n{constructor(){super(),this.Utils=s,this.type="ray",this.callback=new Ammo.ClosestRayResultCallback}step(t,e){o.reflow.ray=[];let r,i,s,n=this.list.length,a=this.callback;for(;n--;)i=e+8*n,r=this.list[n],t[i]=0,a.set_m_collisionObject(null),a.get_m_rayFromWorld().fromArray(t,i+1),a.get_m_rayToWorld().fromArray(t,i+4),a.set_m_collisionFilterGroup(r.group),a.set_m_collisionFilterMask(r.mask),a.set_m_closestHitFraction(r.precision),o.world.rayTest(a.get_m_rayFromWorld(),a.get_m_rayToWorld(),a),a.hasHit()&&(t[i]=1,a.get_m_hitPointWorld().toArray(t,i+1),a.get_m_hitNormalWorld().toArray(t,i+4),s=Ammo.castObject(a.get_m_collisionObject(),Ammo.btRigidBody).name,void 0===s&&(s=Ammo.castObject(ray.get_m_collisionObject(),Ammo.btSoftBody).name),o.reflow.ray[n]=s)}add(t={}){this.setName(t);let e=new h(t);this.addToWorld(e,t.id)}set(t={},e=null){}}class h{constructor(t={}){this.type="ray",this.name=t.name,this.precision=t.precision||1,this.group=void 0!==t.group||1,this.mask=void 0!==t.mask||-1}}class u extends n{constructor(){super(),this.Utils=s,this.type="contact",this.cb=new Ammo.ConcreteContactResultCallback}step(t,e){let r,i,s,n=this.list.length;for(;n--;)s=0,r=this.list[n],i=e+8*n,this.cb.addSingleResult=function(){s=1},null!==r.b2?o.world.contactPairTest(r.b1,r.b2,this.cb):o.world.contactTest(r.b1,this.cb),t[i]=s}add(t={}){this.setName(t),t.b1=this.byName(t.b1),t.b2=this.byName(t.b2);let e=new p(t);this.addToWorld(e,t.id)}}class p{constructor(t={}){this.type="contact",this.name=t.name,this.b1=t.b1||null,this.b2=t.b2||null,this.ignore=t.ignore||[],this.result={hit:!1,point:[0,0,0],normal:[0,0,0],distance:0}}update(){}}self.onmessage=function(t){J.message(t)};let d,f,y,g,v,b,A,w,x,_,k=!1,S=!0,T=!1;const L="undefined"==typeof performance?Date:performance,C={tmp:0,n:0,dt:0,fps:0};let M,V,F,R,O,P,I,N,j=1/60,B=4,W=!0,E=2,q=0,G=0,z=null,D=null,U=null,Q=null,H=[],K=[],Y=[];class J{static test(){}static message(t){let e=t.data;e.Ar&&(d=e.Ar),e.flow&&(o.flow=e.flow),e.m&&J[e.m](e.o)}static post(t,e){v?self.postMessage(t,e):g({data:t})}static init(t={}){v=!0,T=t.isBuffer||!1,f=t.ArPos,y=t.ArMax,void 0!==t.fps&&(j=1/t.fps),void 0!==t.substep&&(B=t.substep),t.returnMessage&&(g=t.returnMessage,v=!1,T=!1),t.blob&&importScripts(t.blob),Ammo().then((function(t){s.extends(),J.initItems(),J.post({m:"ready",o:{}})}))}static initItems(){b=new a,A=new l,w=new m,x=new c,_=new u}static set(t={}){k=t.isTimeout||!1,j=1/(t.fps||60),B=t.substep||1,W=void 0===t.fixe||t.fixe,E=t.broadphase||2,o.substep=B,S=void 0===t.soft||t.soft,U=(new Ammo.btVector3).fromArray(t.gravity||[0,-9.8,0]),t.penetration&&(Q=t.penetration),null===o.world&&J.start()}static start(){null===o.world&&(d=new Float32Array(y),this.makeWorld()),M=!1,V=!1,G=0,F=0,k?J.step():z=setInterval(J.step,1e3*j)}static makeWorld(){switch(R=new Ammo.btSequentialImpulseConstraintSolver,O=S?new Ammo.btDefaultSoftBodySolver:null,P=S?new Ammo.btSoftBodyRigidBodyCollisionConfiguration:new Ammo.btDefaultCollisionConfiguration,I=new Ammo.btCollisionDispatcher(P),E){case 1:let t=1e3;N=new Ammo.btAxisSweep3(new Ammo.btVector3(-t,-t,-t),new Ammo.btVector3(t,t,t),4096);break;case 2:N=new Ammo.btDbvtBroadphase}(o.world=S?new Ammo.btSoftRigidDynamicsWorld(I,N,R,P,O):new Ammo.btDiscreteDynamicsWorld(I,N,R,P),o.world.setGravity(U),S)&&o.world.getWorldInfo().set_m_gravity(U);Q&&o.world.getDispatchInfo().set_m_allowedCcdPenetration(Q)}static add(t={}){switch(t.type||"box"){case"contact":_.add(t);break;case"ray":x.add(t);break;case"joint":w.add(t);break;default:t.density||t.kinematic?b.add(t):A.add(t)}}static remove(t={}){let e=this.byName(t.name);if(null!==e)switch(e.type){case"contact":e=_.clear(e);break;case"ray":e=x.clear(e);break;case"joint":e=w.clear(e);break;case"solid":e=A.clear(e);break;case"body":e=b.clear(e)}}static change(t={}){let e=this.byName(t.name);if(null!==e)switch(e.type){case"ray":e=x.set(t,e);break;case"joint":e=w.set(t,e);break;case"solid":e=A.set(t,e);break;case"body":e=b.set(t,e)}}static dispatch(){for(K=o.flow.remove,H=o.flow.add,Y=o.flow.tmp;K.length>0;)this.remove(K.shift());for(;H.length>0;)this.add(H.shift());for(;Y.length>0;)this.change(Y.shift());o.flow={key:[],add:[],remove:[],tmp:[]}}static poststep(){if(!M&&(F=1,this.dispatch(),k)){let t=1e3*j-(L.now()-q);t<0?J.step():D=setTimeout(J.step,t)}}static step(){V?J.endReset():M||2===F||(F=2,q=L.now(),o.delta=.001*(q-G),G=q,W&&o.world.stepSimulation(j,B,j/B),J.stepItems(),q-1e3>C.tmp&&(C.tmp=q,o.reflow.stat.fps=C.n,C.n=0),C.n++,o.reflow.stat.delta=o.delta,T?J.post({m:"step",reflow:o.reflow,Ar:d},[d.buffer]):J.post({m:"step",reflow:o.reflow,Ar:d}))}static stepItems(){b.step(d,f.body),w.step(d,f.joint),x.step(d,f.ray),_.step(d,f.contact)}static byName(t){return s.byName(t)}static reset(){V=!0}static endReset(){J.stop(),b.reset(),A.reset(),w.reset(),x.reset(),_.reset(),Ammo.destroy(o.world),Ammo.destroy(R),S&&Ammo.destroy(O),Ammo.destroy(P),Ammo.destroy(I),Ammo.destroy(N),o.world=null,s.clear(),J.post({m:"resetCallback",o:{}})}static stop(){M=!0,D&&clearTimeout(D),z&&clearInterval(z),z=null,D=null}static pause(){M?this.start():this.stop()}}t.engine=J,Object.defineProperty(t,"__esModule",{value:!0})}));
  