@newkrok/nape-js 3.14.0 → 3.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{$ as x,H as f,T as L,X as R,_ as j,aa as G,ba as W,ca as N,da as Y,ea as X,fa as q,ga as z,ha as H,ia as V,ja as $,la as K,ma as Q,na as Z,oa as tt,pa as ot,qa as et,ra as nt}from"../chunk-WWQTZ6HT.js";var at=1;function F(t){return{x:t.x,y:t.y}}function ut(t){if(t==null)return null;try{let o=JSON.stringify(t);return o==="{}"?null:JSON.parse(o)}catch{return null}}function mt(t){return{elasticity:t.elasticity,dynamicFriction:t.dynamicFriction,staticFriction:t.staticFriction,density:t.density,rollingFriction:t.rollingFriction}}function yt(t){return{collisionGroup:t.collisionGroup,collisionMask:t.collisionMask,sensorGroup:t.sensorGroup,sensorMask:t.sensorMask,fluidGroup:t.fluidGroup,fluidMask:t.fluidMask}}function ft(t){if(t==null)return null;let o=t.gravity;return{density:t.density,viscosity:t.viscosity,gravity:o!=null?F(o):null}}function Ft(t){let o=mt(t.material),n=yt(t.filter),e=t.fluidEnabled,r=e?ft(t.fluidProperties):null,a=t.sensorEnabled;if(t.isCircle()){let i=t,s=t.localCOM;return{type:"circle",radius:i.radius,localCOM:F(s),material:o,filter:n,sensorEnabled:a,fluidEnabled:e,fluidProperties:r}}else if(t.isCapsule()){let i=t,s=t.localCOM;return{type:"capsule",width:i.width,height:i.height,localCOM:F(s),material:o,filter:n,sensorEnabled:a,fluidEnabled:e,fluidProperties:r}}else{let s=t.localVerts,l=[],c=s.length;for(let m=0;m<c;m++)l.push(F(s.at(m)));return{type:"polygon",localVerts:l,material:o,filter:n,sensorEnabled:a,fluidEnabled:e,fluidProperties:r}}}var bt={1:"STATIC",2:"DYNAMIC",3:"KINEMATIC"},Dt={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},ht={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},Mt={0:"DEFAULT",1:"FIXED",2:"SCALED"};function gt(t,o){let n=t.zpp_inner,e=Dt[n.massMode]??"DEFAULT",r=ht[n.inertiaMode]??"DEFAULT",a=Mt[n.gravMassMode]??"DEFAULT",i=[],s=t.shapes,l=s.length;for(let c=0;c<l;c++)i.push(Ft(s.at(c)));return{id:o,type:bt[n.type]??"DYNAMIC",position:F(t.position),rotation:t.rotation,velocity:F(t.velocity),angularVel:t.angularVel,kinematicVel:F(t.kinematicVel),kinAngVel:t.kinAngVel,surfaceVel:F(t.surfaceVel),force:F(t.force),torque:n.type===2?t.torque:0,massMode:e,mass:e==="FIXED"?n.cmass:null,inertiaMode:r,inertia:r==="FIXED"?n.cinertia:null,gravMassMode:a,gravMassScale:n.gravMassScale,allowMovement:t.allowMovement,allowRotation:t.allowRotation,bullet:t.isBullet,shapes:i,userData:ut(n.userData)}}function B(t,o,n,e){let r=t.zpp_inner,a=n!=null?o.get(n.zpp_inner.id)??null:null,i=e!=null?o.get(e.zpp_inner.id)??null:null;return{body1Id:a,body2Id:i,active:r.active,ignore:r.ignore,stiff:r.stiff,frequency:r.frequency,damping:r.damping,maxForce:r.maxForce,maxError:r.maxError,breakUnderForce:r.breakUnderForce,breakUnderError:r.breakUnderError,removeOnBreak:r.removeOnBreak,userData:ut(r.userData)}}function Ct(t,o){switch(t.constructor?.name??""){case"PivotJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"PivotJoint",anchor1:F(e.anchor1),anchor2:F(e.anchor2)}}case"DistanceJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"DistanceJoint",anchor1:F(e.anchor1),anchor2:F(e.anchor2),jointMin:e.jointMin,jointMax:e.jointMax}}case"AngleJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"AngleJoint",jointMin:e.jointMin,jointMax:e.jointMax,ratio:e.ratio}}case"MotorJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"MotorJoint",rate:e.rate,ratio:e.ratio}}case"LineJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"LineJoint",anchor1:F(e.anchor1),anchor2:F(e.anchor2),direction:F(e.direction),jointMin:e.jointMin,jointMax:e.jointMax}}case"PulleyJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"PulleyJoint",anchor1:F(e.anchor1),anchor2:F(e.anchor2),anchor3:F(e.anchor3),anchor4:F(e.anchor4),jointMin:e.jointMin,jointMax:e.jointMax,ratio:e.ratio}}case"WeldJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"WeldJoint",anchor1:F(e.anchor1),anchor2:F(e.anchor2),phase:e.phase}}default:return null}}function wt(t){let o=[],n=new Map,e=new Map;function r(p){let d=p.zpp_inner.id;if(e.has(d))return;let y=o.length;n.set(p,y),e.set(d,y),o.push(gt(p,y))}let a=t.bodies,i=a.length;for(let p=0;p<i;p++)r(a.at(p));let s=t.compounds,l=s.length;for(let p=0;p<l;p++){let y=s.at(p).bodies,v=y.length;for(let A=0;A<v;A++)r(y.at(A))}let c=[],m=new Map;function b(p){if(m.has(p))return;let d=Ct(p,e);d!=null&&(m.set(p,c.length),c.push(d))}let C=t.constraints,I=C.length;for(let p=0;p<I;p++)b(C.at(p));for(let p=0;p<l;p++){let y=s.at(p).constraints,v=y.length;for(let A=0;A<v;A++)b(y.at(A))}let D=[];for(let p=0;p<l;p++){let d=s.at(p),y=[],v=d.bodies,A=v.length;for(let P=0;P<A;P++){let st=v.at(P),O=n.get(st);O!=null&&y.push(O)}let g=[],M=d.constraints,S=M.length;for(let P=0;P<S;P++){let st=M.at(P),O=m.get(st);O!=null&&g.push(O)}D.push({bodyIds:y,constraintIndices:g,childIndices:[]})}let u=t.zpp_inner.bphase.is_sweep?"SWEEP_AND_PRUNE":"DYNAMIC_AABB_TREE",h=t.gravity;return{version:1,gravity:F(h),worldLinearDrag:t.worldLinearDrag,worldAngularDrag:t.worldAngularDrag,sortContacts:t.sortContacts,broadphase:u,bodies:o,constraints:c,compounds:D}}function E(t){return f.get(t.x,t.y)}function w(t){return f.weak(t.x,t.y)}function vt(t){return new W(t.elasticity,t.dynamicFriction,t.staticFriction,t.density,t.rollingFriction)}function At(t){let o=new $;return o.collisionGroup=t.collisionGroup,o.collisionMask=t.collisionMask,o.sensorGroup=t.sensorGroup,o.sensorMask=t.sensorMask,o.fluidGroup=t.fluidGroup,o.fluidMask=t.fluidMask,o}function It(t){let o=new L(t.density,t.viscosity);return t.gravity!=null&&(o.gravity=E(t.gravity)),o}function Jt(t){let o=vt(t.material),n=At(t.filter),e;if(t.type==="circle"){let r=E(t.localCOM);e=new q(t.radius,r,o,n)}else if(t.type==="capsule"){let r=E(t.localCOM);e=new H(t.width,t.height,r,o,n)}else{let r=t.localVerts.map(a=>E(a));e=new z(r,o,n)}return e.sensorEnabled=t.sensorEnabled,e.fluidEnabled=t.fluidEnabled,t.fluidEnabled&&t.fluidProperties!=null&&(e.fluidProperties=It(t.fluidProperties)),e}function St(t){let o=t.type==="STATIC"?x.STATIC:t.type==="KINEMATIC"?x.KINEMATIC:x.DYNAMIC,n=new j(o,w(t.position));n.rotation=t.rotation,t.type!=="STATIC"&&(n.velocity=E(t.velocity),n.angularVel=t.angularVel),n.kinematicVel=E(t.kinematicVel),n.kinAngVel=t.kinAngVel,n.surfaceVel=E(t.surfaceVel),t.type==="DYNAMIC"&&(n.force=E(t.force),n.torque=t.torque),t.massMode==="FIXED"&&t.mass!=null?n.mass=t.mass:t.massMode==="DEFAULT"&&(n.massMode=X.DEFAULT),t.inertiaMode==="FIXED"&&t.inertia!=null?n.inertia=t.inertia:t.inertiaMode==="DEFAULT"&&(n.inertiaMode=Y.DEFAULT),t.gravMassMode==="SCALED"?(n.gravMassMode=N.SCALED,n.gravMassScale=t.gravMassScale):t.gravMassMode==="FIXED"&&(n.gravMassMode=N.FIXED),n.allowMovement=t.allowMovement,n.allowRotation=t.allowRotation,n.isBullet=t.bullet;for(let e of t.shapes)Jt(e).body=n;return t.userData!=null&&Object.assign(n.userData,t.userData),n}function U(t,o){t.active=o.active,t.ignore=o.ignore,t.stiff=o.stiff,t.frequency=o.frequency,t.damping=o.damping,t.maxForce=o.maxForce,t.maxError=o.maxError,t.breakUnderForce=o.breakUnderForce,t.breakUnderError=o.breakUnderError,t.removeOnBreak=o.removeOnBreak,o.userData!=null&&Object.assign(t.userData,o.userData)}function xt(t,o){let n=t.body1Id!=null?o[t.body1Id]??null:null,e=t.body2Id!=null?o[t.body2Id]??null:null;switch(t.type){case"PivotJoint":{let r=new ot(n,e,w(t.anchor1),w(t.anchor2));return U(r,t),r}case"DistanceJoint":{let r=new Q(n,e,w(t.anchor1),w(t.anchor2),t.jointMin,t.jointMax);return U(r,t),r}case"AngleJoint":{let r=new K(n,e,t.jointMin,t.jointMax,t.ratio);return U(r,t),r}case"MotorJoint":{let r=new tt(n,e,t.rate,t.ratio);return U(r,t),r}case"LineJoint":{let r=new Z(n,e,w(t.anchor1),w(t.anchor2),w(t.direction),t.jointMin,t.jointMax);return U(r,t),r}case"PulleyJoint":{let r=new et(n,e,null,null,w(t.anchor1),w(t.anchor2),w(t.anchor3),w(t.anchor4),t.jointMin,t.jointMax,t.ratio);return U(r,t),r}case"WeldJoint":{let r=new nt(n,e,w(t.anchor1),w(t.anchor2),t.phase);return U(r,t),r}}}function Et(t){if(t.version!==1)throw new Error(`nape-js serialization: unsupported snapshot version ${t.version} (expected ${1})`);let o=t.broadphase==="SWEEP_AND_PRUNE"?V.SWEEP_AND_PRUNE:V.DYNAMIC_AABB_TREE,n=new R(w(t.gravity),o);n.worldLinearDrag=t.worldLinearDrag,n.worldAngularDrag=t.worldAngularDrag,n.sortContacts=t.sortContacts;let e=t.bodies.map(St),r=t.constraints.map(s=>xt(s,e)),a=new Set,i=new Set;for(let s of t.compounds){let l=new G;for(let c of s.bodyIds)e[c].compound=l,a.add(c);for(let c of s.constraintIndices)r[c].compound=l,i.add(c);l.space=n}for(let s=0;s<e.length;s++)a.has(s)||(e[s].space=n);for(let s=0;s<r.length;s++)i.has(s)||(r[s].space=n);return n}var rt=class{constructor(o=4096){this.pos=0;this.buf=new ArrayBuffer(o),this.view=new DataView(this.buf)}ensure(o){let n=this.pos+o;if(n<=this.buf.byteLength)return;let e=this.buf.byteLength;for(;e<n;)e*=2;let r=new ArrayBuffer(e);new Uint8Array(r).set(new Uint8Array(this.buf)),this.buf=r,this.view=new DataView(this.buf)}writeUint8(o){this.ensure(1),this.view.setUint8(this.pos,o),this.pos+=1}writeUint16(o){this.ensure(2),this.view.setUint16(this.pos,o,!0),this.pos+=2}writeUint32(o){this.ensure(4),this.view.setUint32(this.pos,o,!0),this.pos+=4}writeInt32(o){this.ensure(4),this.view.setInt32(this.pos,o,!0),this.pos+=4}writeFloat64(o){this.ensure(8),this.view.setFloat64(this.pos,o,!0),this.pos+=8}writeBool(o){this.writeUint8(o?1:0)}finish(){return new Uint8Array(this.buf,0,this.pos)}};var Pt=1312903237,_=1,Bt=0,Ut=1,kt=2,Tt=3,Nt=4,Vt=5,Ot=6;function _t(t,o){t.writeFloat64(o.elasticity),t.writeFloat64(o.dynamicFriction),t.writeFloat64(o.staticFriction),t.writeFloat64(o.density),t.writeFloat64(o.rollingFriction)}function Lt(t,o){t.writeInt32(o.collisionGroup),t.writeInt32(o.collisionMask),t.writeInt32(o.sensorGroup),t.writeInt32(o.sensorMask),t.writeInt32(o.fluidGroup),t.writeInt32(o.fluidMask)}function Rt(t,o){if(o==null)return;t.writeFloat64(o.density),t.writeFloat64(o.viscosity);let n=o.gravity;t.writeBool(n!=null),n!=null&&(t.writeFloat64(n.x),t.writeFloat64(n.y))}function jt(t,o){if(o.isCircle()){t.writeUint8(0);let a=o;t.writeFloat64(a.radius);let i=o.localCOM;t.writeFloat64(i.x),t.writeFloat64(i.y)}else if(o.isCapsule()){t.writeUint8(2);let a=o;t.writeFloat64(a.width),t.writeFloat64(a.height);let i=o.localCOM;t.writeFloat64(i.x),t.writeFloat64(i.y)}else{t.writeUint8(1);let i=o.localVerts,s=i.length;t.writeUint16(s);for(let l=0;l<s;l++){let c=i.at(l);t.writeFloat64(c.x),t.writeFloat64(c.y)}}_t(t,o.material),Lt(t,o.filter);let n=o.fluidEnabled,e=n&&o.fluidProperties!=null,r=(o.sensorEnabled?1:0)|(n?2:0)|(e?4:0);t.writeUint8(r),e&&Rt(t,o.fluidProperties)}function Gt(t,o){let n=o.zpp_inner;t.writeUint8(n.type),t.writeFloat64(o.position.x),t.writeFloat64(o.position.y),t.writeFloat64(o.rotation),t.writeFloat64(o.velocity.x),t.writeFloat64(o.velocity.y),t.writeFloat64(o.angularVel),t.writeFloat64(o.kinematicVel.x),t.writeFloat64(o.kinematicVel.y),t.writeFloat64(o.kinAngVel),t.writeFloat64(o.surfaceVel.x),t.writeFloat64(o.surfaceVel.y),t.writeFloat64(o.force.x),t.writeFloat64(o.force.y),t.writeFloat64(n.type===2?o.torque:0),t.writeUint8(n.massMode),t.writeFloat64(n.massMode===1?n.cmass:0),t.writeUint8(n.inertiaMode),t.writeFloat64(n.inertiaMode===1?n.cinertia:0),t.writeUint8(n.gravMassMode),t.writeFloat64(n.gravMassScale);let e=(o.allowMovement?1:0)|(o.allowRotation?2:0)|(o.isBullet?4:0);t.writeUint8(e);let r=o.shapes,a=r.length;t.writeUint16(a);for(let i=0;i<a;i++)jt(t,r.at(i))}var pt={PivotJoint:Bt,DistanceJoint:Ut,AngleJoint:kt,MotorJoint:Tt,LineJoint:Nt,PulleyJoint:Vt,WeldJoint:Ot};function k(t,o,n,e,r){let a=e!=null?n.get(e.zpp_inner.id)??-1:-1,i=r!=null?n.get(r.zpp_inner.id)??-1:-1;t.writeInt32(a),t.writeInt32(i);let s=o.zpp_inner,l=(s.active?1:0)|(s.ignore?2:0)|(s.stiff?4:0)|(s.breakUnderForce?8:0)|(s.breakUnderError?16:0)|(s.removeOnBreak?32:0);t.writeUint8(l),t.writeFloat64(s.frequency),t.writeFloat64(s.damping),t.writeFloat64(s.maxForce),t.writeFloat64(s.maxError)}function Wt(t,o,n){let e=o.constructor?.name??"",r=pt[e];if(r===void 0)return!1;switch(t.writeUint8(r),e){case"PivotJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.anchor1.x),t.writeFloat64(a.anchor1.y),t.writeFloat64(a.anchor2.x),t.writeFloat64(a.anchor2.y);break}case"DistanceJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.anchor1.x),t.writeFloat64(a.anchor1.y),t.writeFloat64(a.anchor2.x),t.writeFloat64(a.anchor2.y),t.writeFloat64(a.jointMin),t.writeFloat64(a.jointMax);break}case"AngleJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.jointMin),t.writeFloat64(a.jointMax),t.writeFloat64(a.ratio);break}case"MotorJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.rate),t.writeFloat64(a.ratio);break}case"LineJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.anchor1.x),t.writeFloat64(a.anchor1.y),t.writeFloat64(a.anchor2.x),t.writeFloat64(a.anchor2.y),t.writeFloat64(a.direction.x),t.writeFloat64(a.direction.y),t.writeFloat64(a.jointMin),t.writeFloat64(a.jointMax);break}case"PulleyJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.anchor1.x),t.writeFloat64(a.anchor1.y),t.writeFloat64(a.anchor2.x),t.writeFloat64(a.anchor2.y),t.writeFloat64(a.anchor3.x),t.writeFloat64(a.anchor3.y),t.writeFloat64(a.anchor4.x),t.writeFloat64(a.anchor4.y),t.writeFloat64(a.jointMin),t.writeFloat64(a.jointMax),t.writeFloat64(a.ratio);break}case"WeldJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.anchor1.x),t.writeFloat64(a.anchor1.y),t.writeFloat64(a.anchor2.x),t.writeFloat64(a.anchor2.y),t.writeFloat64(a.phase);break}}return!0}function Yt(t){let o=new rt,n=[],e=new Map,r=new Map;function a(u){let h=u.zpp_inner.id;if(e.has(h))return;let p=n.length;r.set(u,p),e.set(h,p),n.push(u)}let i=t.bodies,s=i.length;for(let u=0;u<s;u++)a(i.at(u));let l=t.compounds,c=l.length;for(let u=0;u<c;u++){let p=l.at(u).bodies,d=p.length;for(let y=0;y<d;y++)a(p.at(y))}let m=[],b=new Map;function C(u){if(b.has(u))return;let h=u.constructor?.name??"";pt[h]!==void 0&&(b.set(u,m.length),m.push(u))}let I=t.constraints,D=I.length;for(let u=0;u<D;u++)C(I.at(u));for(let u=0;u<c;u++){let p=l.at(u).constraints,d=p.length;for(let y=0;y<d;y++)C(p.at(y))}o.writeUint32(Pt),o.writeUint16(_),o.writeUint32(n.length),o.writeUint32(m.length),o.writeUint32(c);let J=t.gravity;o.writeFloat64(J.x),o.writeFloat64(J.y),o.writeFloat64(t.worldLinearDrag),o.writeFloat64(t.worldAngularDrag),o.writeBool(t.sortContacts),o.writeUint8(t.zpp_inner.bphase.is_sweep?0:1);for(let u=0;u<n.length;u++)Gt(o,n[u]);for(let u=0;u<m.length;u++)Wt(o,m[u],e);for(let u=0;u<c;u++){let h=l.at(u),p=h.bodies,d=p.length;o.writeUint16(d);for(let g=0;g<d;g++){let M=p.at(g),S=r.get(M)??0;o.writeUint32(S)}let y=h.constraints,v=y.length,A=0;for(let g=0;g<v;g++){let M=y.at(g);b.has(M)&&A++}o.writeUint16(A);for(let g=0;g<v;g++){let M=y.at(g),S=b.get(M);S!=null&&o.writeUint32(S)}o.writeUint16(0)}return o.finish()}var it=class{constructor(o){this.pos=0;this.view=new DataView(o.buffer,o.byteOffset,o.byteLength)}readUint8(){let o=this.view.getUint8(this.pos);return this.pos+=1,o}readUint16(){let o=this.view.getUint16(this.pos,!0);return this.pos+=2,o}readUint32(){let o=this.view.getUint32(this.pos,!0);return this.pos+=4,o}readInt32(){let o=this.view.getInt32(this.pos,!0);return this.pos+=4,o}readFloat64(){let o=this.view.getFloat64(this.pos,!0);return this.pos+=8,o}readBool(){return this.readUint8()!==0}};var dt=1312903237,Xt=0,qt=1,zt=2,Ht=3,$t=4,Kt=5,Qt=6,Zt={1:x.STATIC,2:x.DYNAMIC,3:x.KINEMATIC};function lt(t){let o=t.readFloat64(),n=t.readFloat64(),e=t.readFloat64(),r=t.readFloat64(),a=t.readFloat64();return new W(o,n,e,r,a)}function ct(t){let o=new $;return o.collisionGroup=t.readInt32(),o.collisionMask=t.readInt32(),o.sensorGroup=t.readInt32(),o.sensorMask=t.readInt32(),o.fluidGroup=t.readInt32(),o.fluidMask=t.readInt32(),o}function to(t){let o=t.readFloat64(),n=t.readFloat64(),e=new L(o,n);return t.readBool()&&(e.gravity=f.get(t.readFloat64(),t.readFloat64())),e}function oo(t){let o=t.readUint8(),n;if(o===0){let a=t.readFloat64(),i=t.readFloat64(),s=t.readFloat64(),l=lt(t),c=ct(t);n=new q(a,f.weak(i,s),l,c)}else if(o===2){let a=t.readFloat64(),i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=lt(t),m=ct(t);n=new H(a,i,f.weak(s,l),c,m)}else{let a=t.readUint16(),i=[];for(let c=0;c<a;c++)i.push(f.get(t.readFloat64(),t.readFloat64()));let s=lt(t),l=ct(t);n=new z(i,s,l)}let e=t.readUint8();return n.sensorEnabled=(e&1)!==0,n.fluidEnabled=(e&2)!==0,(e&4)!==0&&(n.fluidProperties=to(t)),n}function eo(t){let o=t.readUint8(),n=Zt[o]??x.DYNAMIC,e=t.readFloat64(),r=t.readFloat64(),a=t.readFloat64(),i=new j(n,f.weak(e,r));i.rotation=a;let s=t.readFloat64(),l=t.readFloat64(),c=t.readFloat64();o!==1&&(i.velocity=f.get(s,l),i.angularVel=c),i.kinematicVel=f.get(t.readFloat64(),t.readFloat64()),i.kinAngVel=t.readFloat64(),i.surfaceVel=f.get(t.readFloat64(),t.readFloat64());let m=t.readFloat64(),b=t.readFloat64(),C=t.readFloat64();o===2&&(i.force=f.get(m,b),i.torque=C);let I=t.readUint8(),D=t.readFloat64();I===1&&D!==0?i.mass=D:I===0&&(i.massMode=X.DEFAULT);let J=t.readUint8(),u=t.readFloat64();J===1&&u!==0?i.inertia=u:J===0&&(i.inertiaMode=Y.DEFAULT);let h=t.readUint8(),p=t.readFloat64();h===2?(i.gravMassMode=N.SCALED,i.gravMassScale=p):h===1&&(i.gravMassMode=N.FIXED);let d=t.readUint8();i.allowMovement=(d&1)!==0,i.allowRotation=(d&2)!==0,i.isBullet=(d&4)!==0;let y=t.readUint16();for(let v=0;v<y;v++)oo(t).body=i;return i}function no(t){let o=t.readInt32(),n=t.readInt32(),e=t.readUint8(),r=t.readFloat64(),a=t.readFloat64(),i=t.readFloat64(),s=t.readFloat64();return{body1Id:o,body2Id:n,active:(e&1)!==0,ignore:(e&2)!==0,stiff:(e&4)!==0,breakUnderForce:(e&8)!==0,breakUnderError:(e&16)!==0,removeOnBreak:(e&32)!==0,frequency:r,damping:a,maxForce:i,maxError:s}}function T(t,o){t.active=o.active,t.ignore=o.ignore,t.stiff=o.stiff,t.frequency=o.frequency,t.damping=o.damping,t.maxForce=o.maxForce,t.maxError=o.maxError,t.breakUnderForce=o.breakUnderForce,t.breakUnderError=o.breakUnderError,t.removeOnBreak=o.removeOnBreak}function ao(t,o){let n=t.readUint8(),e=no(t),r=e.body1Id>=0?o[e.body1Id]??null:null,a=e.body2Id>=0?o[e.body2Id]??null:null;switch(n){case Xt:{let i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=t.readFloat64(),m=new ot(r,a,f.weak(i,s),f.weak(l,c));return T(m,e),m}case qt:{let i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=t.readFloat64(),m=t.readFloat64(),b=t.readFloat64(),C=new Q(r,a,f.weak(i,s),f.weak(l,c),m,b);return T(C,e),C}case zt:{let i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=new K(r,a,i,s,l);return T(c,e),c}case Ht:{let i=t.readFloat64(),s=t.readFloat64(),l=new tt(r,a,i,s);return T(l,e),l}case $t:{let i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=t.readFloat64(),m=t.readFloat64(),b=t.readFloat64(),C=t.readFloat64(),I=t.readFloat64(),D=new Z(r,a,f.weak(i,s),f.weak(l,c),f.weak(m,b),C,I);return T(D,e),D}case Kt:{let i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=t.readFloat64(),m=t.readFloat64(),b=t.readFloat64(),C=t.readFloat64(),I=t.readFloat64(),D=t.readFloat64(),J=t.readFloat64(),u=t.readFloat64(),h=new et(r,a,null,null,f.weak(i,s),f.weak(l,c),f.weak(m,b),f.weak(C,I),D,J,u);return T(h,e),h}case Qt:{let i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=t.readFloat64(),m=t.readFloat64(),b=new nt(r,a,f.weak(i,s),f.weak(l,c),m);return T(b,e),b}default:throw new Error(`nape-js binary: unknown constraint type tag ${n}`)}}function ro(t){let o=new it(t),n=o.readUint32();if(n!==dt)throw new Error(`nape-js binary: invalid magic bytes 0x${n.toString(16)} (expected 0x${dt.toString(16)})`);let e=o.readUint16();if(e!==_)throw new Error(`nape-js binary: unsupported version ${e} (expected ${_})`);let r=o.readUint32(),a=o.readUint32(),i=o.readUint32(),s=o.readFloat64(),l=o.readFloat64(),c=o.readFloat64(),m=o.readFloat64(),b=o.readBool(),I=o.readUint8()===0?V.SWEEP_AND_PRUNE:V.DYNAMIC_AABB_TREE,D=new R(f.weak(s,l),I);D.worldLinearDrag=c,D.worldAngularDrag=m,D.sortContacts=b;let J=new Array(r);for(let d=0;d<r;d++)J[d]=eo(o);let u=new Array(a);for(let d=0;d<a;d++)u[d]=ao(o,J);let h=new Set,p=new Set;for(let d=0;d<i;d++){let y=new G,v=o.readUint16();for(let M=0;M<v;M++){let S=o.readUint32();J[S].compound=y,h.add(S)}let A=o.readUint16();for(let M=0;M<A;M++){let S=o.readUint32();u[S].compound=y,p.add(S)}let g=o.readUint16();for(let M=0;M<g;M++)o.readUint32();y.space=D}for(let d=0;d<r;d++)h.has(d)||(J[d].space=D);for(let d=0;d<a;d++)p.has(d)||(u[d].space=D);return D}export{_ as BINARY_SNAPSHOT_VERSION,at as SNAPSHOT_VERSION,ro as spaceFromBinary,Et as spaceFromJSON,Yt as spaceToBinary,wt as spaceToJSON};
1
+ import{$ as x,H as f,T as L,X as R,_ as j,aa as G,ba as W,ca as N,da as Y,ea as X,fa as q,ga as z,ha as H,ia as V,ja as $,la as K,ma as Q,na as Z,oa as tt,pa as ot,qa as et,ra as nt}from"../chunk-L4RGZJSN.js";var at=1;function F(t){return{x:t.x,y:t.y}}function ut(t){if(t==null)return null;try{let o=JSON.stringify(t);return o==="{}"?null:JSON.parse(o)}catch{return null}}function mt(t){return{elasticity:t.elasticity,dynamicFriction:t.dynamicFriction,staticFriction:t.staticFriction,density:t.density,rollingFriction:t.rollingFriction}}function yt(t){return{collisionGroup:t.collisionGroup,collisionMask:t.collisionMask,sensorGroup:t.sensorGroup,sensorMask:t.sensorMask,fluidGroup:t.fluidGroup,fluidMask:t.fluidMask}}function ft(t){if(t==null)return null;let o=t.gravity;return{density:t.density,viscosity:t.viscosity,gravity:o!=null?F(o):null}}function Ft(t){let o=mt(t.material),n=yt(t.filter),e=t.fluidEnabled,r=e?ft(t.fluidProperties):null,a=t.sensorEnabled;if(t.isCircle()){let i=t,s=t.localCOM;return{type:"circle",radius:i.radius,localCOM:F(s),material:o,filter:n,sensorEnabled:a,fluidEnabled:e,fluidProperties:r}}else if(t.isCapsule()){let i=t,s=t.localCOM;return{type:"capsule",width:i.width,height:i.height,localCOM:F(s),material:o,filter:n,sensorEnabled:a,fluidEnabled:e,fluidProperties:r}}else{let s=t.localVerts,l=[],c=s.length;for(let m=0;m<c;m++)l.push(F(s.at(m)));return{type:"polygon",localVerts:l,material:o,filter:n,sensorEnabled:a,fluidEnabled:e,fluidProperties:r}}}var bt={1:"STATIC",2:"DYNAMIC",3:"KINEMATIC"},Dt={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},ht={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},Mt={0:"DEFAULT",1:"FIXED",2:"SCALED"};function gt(t,o){let n=t.zpp_inner,e=Dt[n.massMode]??"DEFAULT",r=ht[n.inertiaMode]??"DEFAULT",a=Mt[n.gravMassMode]??"DEFAULT",i=[],s=t.shapes,l=s.length;for(let c=0;c<l;c++)i.push(Ft(s.at(c)));return{id:o,type:bt[n.type]??"DYNAMIC",position:F(t.position),rotation:t.rotation,velocity:F(t.velocity),angularVel:t.angularVel,kinematicVel:F(t.kinematicVel),kinAngVel:t.kinAngVel,surfaceVel:F(t.surfaceVel),force:F(t.force),torque:n.type===2?t.torque:0,massMode:e,mass:e==="FIXED"?n.cmass:null,inertiaMode:r,inertia:r==="FIXED"?n.cinertia:null,gravMassMode:a,gravMassScale:n.gravMassScale,allowMovement:t.allowMovement,allowRotation:t.allowRotation,bullet:t.isBullet,shapes:i,userData:ut(n.userData)}}function B(t,o,n,e){let r=t.zpp_inner,a=n!=null?o.get(n.zpp_inner.id)??null:null,i=e!=null?o.get(e.zpp_inner.id)??null:null;return{body1Id:a,body2Id:i,active:r.active,ignore:r.ignore,stiff:r.stiff,frequency:r.frequency,damping:r.damping,maxForce:r.maxForce,maxError:r.maxError,breakUnderForce:r.breakUnderForce,breakUnderError:r.breakUnderError,removeOnBreak:r.removeOnBreak,userData:ut(r.userData)}}function Ct(t,o){switch(t.constructor?.name??""){case"PivotJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"PivotJoint",anchor1:F(e.anchor1),anchor2:F(e.anchor2)}}case"DistanceJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"DistanceJoint",anchor1:F(e.anchor1),anchor2:F(e.anchor2),jointMin:e.jointMin,jointMax:e.jointMax}}case"AngleJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"AngleJoint",jointMin:e.jointMin,jointMax:e.jointMax,ratio:e.ratio}}case"MotorJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"MotorJoint",rate:e.rate,ratio:e.ratio}}case"LineJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"LineJoint",anchor1:F(e.anchor1),anchor2:F(e.anchor2),direction:F(e.direction),jointMin:e.jointMin,jointMax:e.jointMax}}case"PulleyJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"PulleyJoint",anchor1:F(e.anchor1),anchor2:F(e.anchor2),anchor3:F(e.anchor3),anchor4:F(e.anchor4),jointMin:e.jointMin,jointMax:e.jointMax,ratio:e.ratio}}case"WeldJoint":{let e=t;return{...B(t,o,e.body1,e.body2),type:"WeldJoint",anchor1:F(e.anchor1),anchor2:F(e.anchor2),phase:e.phase}}default:return null}}function wt(t){let o=[],n=new Map,e=new Map;function r(p){let d=p.zpp_inner.id;if(e.has(d))return;let y=o.length;n.set(p,y),e.set(d,y),o.push(gt(p,y))}let a=t.bodies,i=a.length;for(let p=0;p<i;p++)r(a.at(p));let s=t.compounds,l=s.length;for(let p=0;p<l;p++){let y=s.at(p).bodies,v=y.length;for(let A=0;A<v;A++)r(y.at(A))}let c=[],m=new Map;function b(p){if(m.has(p))return;let d=Ct(p,e);d!=null&&(m.set(p,c.length),c.push(d))}let C=t.constraints,I=C.length;for(let p=0;p<I;p++)b(C.at(p));for(let p=0;p<l;p++){let y=s.at(p).constraints,v=y.length;for(let A=0;A<v;A++)b(y.at(A))}let D=[];for(let p=0;p<l;p++){let d=s.at(p),y=[],v=d.bodies,A=v.length;for(let P=0;P<A;P++){let st=v.at(P),O=n.get(st);O!=null&&y.push(O)}let g=[],M=d.constraints,S=M.length;for(let P=0;P<S;P++){let st=M.at(P),O=m.get(st);O!=null&&g.push(O)}D.push({bodyIds:y,constraintIndices:g,childIndices:[]})}let u=t.zpp_inner.bphase.is_sweep?"SWEEP_AND_PRUNE":"DYNAMIC_AABB_TREE",h=t.gravity;return{version:1,gravity:F(h),worldLinearDrag:t.worldLinearDrag,worldAngularDrag:t.worldAngularDrag,sortContacts:t.sortContacts,broadphase:u,bodies:o,constraints:c,compounds:D}}function E(t){return f.get(t.x,t.y)}function w(t){return f.weak(t.x,t.y)}function vt(t){return new W(t.elasticity,t.dynamicFriction,t.staticFriction,t.density,t.rollingFriction)}function At(t){let o=new $;return o.collisionGroup=t.collisionGroup,o.collisionMask=t.collisionMask,o.sensorGroup=t.sensorGroup,o.sensorMask=t.sensorMask,o.fluidGroup=t.fluidGroup,o.fluidMask=t.fluidMask,o}function It(t){let o=new L(t.density,t.viscosity);return t.gravity!=null&&(o.gravity=E(t.gravity)),o}function Jt(t){let o=vt(t.material),n=At(t.filter),e;if(t.type==="circle"){let r=E(t.localCOM);e=new q(t.radius,r,o,n)}else if(t.type==="capsule"){let r=E(t.localCOM);e=new H(t.width,t.height,r,o,n)}else{let r=t.localVerts.map(a=>E(a));e=new z(r,o,n)}return e.sensorEnabled=t.sensorEnabled,e.fluidEnabled=t.fluidEnabled,t.fluidEnabled&&t.fluidProperties!=null&&(e.fluidProperties=It(t.fluidProperties)),e}function St(t){let o=t.type==="STATIC"?x.STATIC:t.type==="KINEMATIC"?x.KINEMATIC:x.DYNAMIC,n=new j(o,w(t.position));n.rotation=t.rotation,t.type!=="STATIC"&&(n.velocity=E(t.velocity),n.angularVel=t.angularVel),n.kinematicVel=E(t.kinematicVel),n.kinAngVel=t.kinAngVel,n.surfaceVel=E(t.surfaceVel),t.type==="DYNAMIC"&&(n.force=E(t.force),n.torque=t.torque),t.massMode==="FIXED"&&t.mass!=null?n.mass=t.mass:t.massMode==="DEFAULT"&&(n.massMode=X.DEFAULT),t.inertiaMode==="FIXED"&&t.inertia!=null?n.inertia=t.inertia:t.inertiaMode==="DEFAULT"&&(n.inertiaMode=Y.DEFAULT),t.gravMassMode==="SCALED"?(n.gravMassMode=N.SCALED,n.gravMassScale=t.gravMassScale):t.gravMassMode==="FIXED"&&(n.gravMassMode=N.FIXED),n.allowMovement=t.allowMovement,n.allowRotation=t.allowRotation,n.isBullet=t.bullet;for(let e of t.shapes)Jt(e).body=n;return t.userData!=null&&Object.assign(n.userData,t.userData),n}function U(t,o){t.active=o.active,t.ignore=o.ignore,t.stiff=o.stiff,t.frequency=o.frequency,t.damping=o.damping,t.maxForce=o.maxForce,t.maxError=o.maxError,t.breakUnderForce=o.breakUnderForce,t.breakUnderError=o.breakUnderError,t.removeOnBreak=o.removeOnBreak,o.userData!=null&&Object.assign(t.userData,o.userData)}function xt(t,o){let n=t.body1Id!=null?o[t.body1Id]??null:null,e=t.body2Id!=null?o[t.body2Id]??null:null;switch(t.type){case"PivotJoint":{let r=new ot(n,e,w(t.anchor1),w(t.anchor2));return U(r,t),r}case"DistanceJoint":{let r=new Q(n,e,w(t.anchor1),w(t.anchor2),t.jointMin,t.jointMax);return U(r,t),r}case"AngleJoint":{let r=new K(n,e,t.jointMin,t.jointMax,t.ratio);return U(r,t),r}case"MotorJoint":{let r=new tt(n,e,t.rate,t.ratio);return U(r,t),r}case"LineJoint":{let r=new Z(n,e,w(t.anchor1),w(t.anchor2),w(t.direction),t.jointMin,t.jointMax);return U(r,t),r}case"PulleyJoint":{let r=new et(n,e,null,null,w(t.anchor1),w(t.anchor2),w(t.anchor3),w(t.anchor4),t.jointMin,t.jointMax,t.ratio);return U(r,t),r}case"WeldJoint":{let r=new nt(n,e,w(t.anchor1),w(t.anchor2),t.phase);return U(r,t),r}}}function Et(t){if(t.version!==1)throw new Error(`nape-js serialization: unsupported snapshot version ${t.version} (expected ${1})`);let o=t.broadphase==="SWEEP_AND_PRUNE"?V.SWEEP_AND_PRUNE:V.DYNAMIC_AABB_TREE,n=new R(w(t.gravity),o);n.worldLinearDrag=t.worldLinearDrag,n.worldAngularDrag=t.worldAngularDrag,n.sortContacts=t.sortContacts;let e=t.bodies.map(St),r=t.constraints.map(s=>xt(s,e)),a=new Set,i=new Set;for(let s of t.compounds){let l=new G;for(let c of s.bodyIds)e[c].compound=l,a.add(c);for(let c of s.constraintIndices)r[c].compound=l,i.add(c);l.space=n}for(let s=0;s<e.length;s++)a.has(s)||(e[s].space=n);for(let s=0;s<r.length;s++)i.has(s)||(r[s].space=n);return n}var rt=class{constructor(o=4096){this.pos=0;this.buf=new ArrayBuffer(o),this.view=new DataView(this.buf)}ensure(o){let n=this.pos+o;if(n<=this.buf.byteLength)return;let e=this.buf.byteLength;for(;e<n;)e*=2;let r=new ArrayBuffer(e);new Uint8Array(r).set(new Uint8Array(this.buf)),this.buf=r,this.view=new DataView(this.buf)}writeUint8(o){this.ensure(1),this.view.setUint8(this.pos,o),this.pos+=1}writeUint16(o){this.ensure(2),this.view.setUint16(this.pos,o,!0),this.pos+=2}writeUint32(o){this.ensure(4),this.view.setUint32(this.pos,o,!0),this.pos+=4}writeInt32(o){this.ensure(4),this.view.setInt32(this.pos,o,!0),this.pos+=4}writeFloat64(o){this.ensure(8),this.view.setFloat64(this.pos,o,!0),this.pos+=8}writeBool(o){this.writeUint8(o?1:0)}finish(){return new Uint8Array(this.buf,0,this.pos)}};var Pt=1312903237,_=1,Bt=0,Ut=1,kt=2,Tt=3,Nt=4,Vt=5,Ot=6;function _t(t,o){t.writeFloat64(o.elasticity),t.writeFloat64(o.dynamicFriction),t.writeFloat64(o.staticFriction),t.writeFloat64(o.density),t.writeFloat64(o.rollingFriction)}function Lt(t,o){t.writeInt32(o.collisionGroup),t.writeInt32(o.collisionMask),t.writeInt32(o.sensorGroup),t.writeInt32(o.sensorMask),t.writeInt32(o.fluidGroup),t.writeInt32(o.fluidMask)}function Rt(t,o){if(o==null)return;t.writeFloat64(o.density),t.writeFloat64(o.viscosity);let n=o.gravity;t.writeBool(n!=null),n!=null&&(t.writeFloat64(n.x),t.writeFloat64(n.y))}function jt(t,o){if(o.isCircle()){t.writeUint8(0);let a=o;t.writeFloat64(a.radius);let i=o.localCOM;t.writeFloat64(i.x),t.writeFloat64(i.y)}else if(o.isCapsule()){t.writeUint8(2);let a=o;t.writeFloat64(a.width),t.writeFloat64(a.height);let i=o.localCOM;t.writeFloat64(i.x),t.writeFloat64(i.y)}else{t.writeUint8(1);let i=o.localVerts,s=i.length;t.writeUint16(s);for(let l=0;l<s;l++){let c=i.at(l);t.writeFloat64(c.x),t.writeFloat64(c.y)}}_t(t,o.material),Lt(t,o.filter);let n=o.fluidEnabled,e=n&&o.fluidProperties!=null,r=(o.sensorEnabled?1:0)|(n?2:0)|(e?4:0);t.writeUint8(r),e&&Rt(t,o.fluidProperties)}function Gt(t,o){let n=o.zpp_inner;t.writeUint8(n.type),t.writeFloat64(o.position.x),t.writeFloat64(o.position.y),t.writeFloat64(o.rotation),t.writeFloat64(o.velocity.x),t.writeFloat64(o.velocity.y),t.writeFloat64(o.angularVel),t.writeFloat64(o.kinematicVel.x),t.writeFloat64(o.kinematicVel.y),t.writeFloat64(o.kinAngVel),t.writeFloat64(o.surfaceVel.x),t.writeFloat64(o.surfaceVel.y),t.writeFloat64(o.force.x),t.writeFloat64(o.force.y),t.writeFloat64(n.type===2?o.torque:0),t.writeUint8(n.massMode),t.writeFloat64(n.massMode===1?n.cmass:0),t.writeUint8(n.inertiaMode),t.writeFloat64(n.inertiaMode===1?n.cinertia:0),t.writeUint8(n.gravMassMode),t.writeFloat64(n.gravMassScale);let e=(o.allowMovement?1:0)|(o.allowRotation?2:0)|(o.isBullet?4:0);t.writeUint8(e);let r=o.shapes,a=r.length;t.writeUint16(a);for(let i=0;i<a;i++)jt(t,r.at(i))}var pt={PivotJoint:Bt,DistanceJoint:Ut,AngleJoint:kt,MotorJoint:Tt,LineJoint:Nt,PulleyJoint:Vt,WeldJoint:Ot};function k(t,o,n,e,r){let a=e!=null?n.get(e.zpp_inner.id)??-1:-1,i=r!=null?n.get(r.zpp_inner.id)??-1:-1;t.writeInt32(a),t.writeInt32(i);let s=o.zpp_inner,l=(s.active?1:0)|(s.ignore?2:0)|(s.stiff?4:0)|(s.breakUnderForce?8:0)|(s.breakUnderError?16:0)|(s.removeOnBreak?32:0);t.writeUint8(l),t.writeFloat64(s.frequency),t.writeFloat64(s.damping),t.writeFloat64(s.maxForce),t.writeFloat64(s.maxError)}function Wt(t,o,n){let e=o.constructor?.name??"",r=pt[e];if(r===void 0)return!1;switch(t.writeUint8(r),e){case"PivotJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.anchor1.x),t.writeFloat64(a.anchor1.y),t.writeFloat64(a.anchor2.x),t.writeFloat64(a.anchor2.y);break}case"DistanceJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.anchor1.x),t.writeFloat64(a.anchor1.y),t.writeFloat64(a.anchor2.x),t.writeFloat64(a.anchor2.y),t.writeFloat64(a.jointMin),t.writeFloat64(a.jointMax);break}case"AngleJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.jointMin),t.writeFloat64(a.jointMax),t.writeFloat64(a.ratio);break}case"MotorJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.rate),t.writeFloat64(a.ratio);break}case"LineJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.anchor1.x),t.writeFloat64(a.anchor1.y),t.writeFloat64(a.anchor2.x),t.writeFloat64(a.anchor2.y),t.writeFloat64(a.direction.x),t.writeFloat64(a.direction.y),t.writeFloat64(a.jointMin),t.writeFloat64(a.jointMax);break}case"PulleyJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.anchor1.x),t.writeFloat64(a.anchor1.y),t.writeFloat64(a.anchor2.x),t.writeFloat64(a.anchor2.y),t.writeFloat64(a.anchor3.x),t.writeFloat64(a.anchor3.y),t.writeFloat64(a.anchor4.x),t.writeFloat64(a.anchor4.y),t.writeFloat64(a.jointMin),t.writeFloat64(a.jointMax),t.writeFloat64(a.ratio);break}case"WeldJoint":{let a=o;k(t,o,n,a.body1,a.body2),t.writeFloat64(a.anchor1.x),t.writeFloat64(a.anchor1.y),t.writeFloat64(a.anchor2.x),t.writeFloat64(a.anchor2.y),t.writeFloat64(a.phase);break}}return!0}function Yt(t){let o=new rt,n=[],e=new Map,r=new Map;function a(u){let h=u.zpp_inner.id;if(e.has(h))return;let p=n.length;r.set(u,p),e.set(h,p),n.push(u)}let i=t.bodies,s=i.length;for(let u=0;u<s;u++)a(i.at(u));let l=t.compounds,c=l.length;for(let u=0;u<c;u++){let p=l.at(u).bodies,d=p.length;for(let y=0;y<d;y++)a(p.at(y))}let m=[],b=new Map;function C(u){if(b.has(u))return;let h=u.constructor?.name??"";pt[h]!==void 0&&(b.set(u,m.length),m.push(u))}let I=t.constraints,D=I.length;for(let u=0;u<D;u++)C(I.at(u));for(let u=0;u<c;u++){let p=l.at(u).constraints,d=p.length;for(let y=0;y<d;y++)C(p.at(y))}o.writeUint32(Pt),o.writeUint16(_),o.writeUint32(n.length),o.writeUint32(m.length),o.writeUint32(c);let J=t.gravity;o.writeFloat64(J.x),o.writeFloat64(J.y),o.writeFloat64(t.worldLinearDrag),o.writeFloat64(t.worldAngularDrag),o.writeBool(t.sortContacts),o.writeUint8(t.zpp_inner.bphase.is_sweep?0:1);for(let u=0;u<n.length;u++)Gt(o,n[u]);for(let u=0;u<m.length;u++)Wt(o,m[u],e);for(let u=0;u<c;u++){let h=l.at(u),p=h.bodies,d=p.length;o.writeUint16(d);for(let g=0;g<d;g++){let M=p.at(g),S=r.get(M)??0;o.writeUint32(S)}let y=h.constraints,v=y.length,A=0;for(let g=0;g<v;g++){let M=y.at(g);b.has(M)&&A++}o.writeUint16(A);for(let g=0;g<v;g++){let M=y.at(g),S=b.get(M);S!=null&&o.writeUint32(S)}o.writeUint16(0)}return o.finish()}var it=class{constructor(o){this.pos=0;this.view=new DataView(o.buffer,o.byteOffset,o.byteLength)}readUint8(){let o=this.view.getUint8(this.pos);return this.pos+=1,o}readUint16(){let o=this.view.getUint16(this.pos,!0);return this.pos+=2,o}readUint32(){let o=this.view.getUint32(this.pos,!0);return this.pos+=4,o}readInt32(){let o=this.view.getInt32(this.pos,!0);return this.pos+=4,o}readFloat64(){let o=this.view.getFloat64(this.pos,!0);return this.pos+=8,o}readBool(){return this.readUint8()!==0}};var dt=1312903237,Xt=0,qt=1,zt=2,Ht=3,$t=4,Kt=5,Qt=6,Zt={1:x.STATIC,2:x.DYNAMIC,3:x.KINEMATIC};function lt(t){let o=t.readFloat64(),n=t.readFloat64(),e=t.readFloat64(),r=t.readFloat64(),a=t.readFloat64();return new W(o,n,e,r,a)}function ct(t){let o=new $;return o.collisionGroup=t.readInt32(),o.collisionMask=t.readInt32(),o.sensorGroup=t.readInt32(),o.sensorMask=t.readInt32(),o.fluidGroup=t.readInt32(),o.fluidMask=t.readInt32(),o}function to(t){let o=t.readFloat64(),n=t.readFloat64(),e=new L(o,n);return t.readBool()&&(e.gravity=f.get(t.readFloat64(),t.readFloat64())),e}function oo(t){let o=t.readUint8(),n;if(o===0){let a=t.readFloat64(),i=t.readFloat64(),s=t.readFloat64(),l=lt(t),c=ct(t);n=new q(a,f.weak(i,s),l,c)}else if(o===2){let a=t.readFloat64(),i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=lt(t),m=ct(t);n=new H(a,i,f.weak(s,l),c,m)}else{let a=t.readUint16(),i=[];for(let c=0;c<a;c++)i.push(f.get(t.readFloat64(),t.readFloat64()));let s=lt(t),l=ct(t);n=new z(i,s,l)}let e=t.readUint8();return n.sensorEnabled=(e&1)!==0,n.fluidEnabled=(e&2)!==0,(e&4)!==0&&(n.fluidProperties=to(t)),n}function eo(t){let o=t.readUint8(),n=Zt[o]??x.DYNAMIC,e=t.readFloat64(),r=t.readFloat64(),a=t.readFloat64(),i=new j(n,f.weak(e,r));i.rotation=a;let s=t.readFloat64(),l=t.readFloat64(),c=t.readFloat64();o!==1&&(i.velocity=f.get(s,l),i.angularVel=c),i.kinematicVel=f.get(t.readFloat64(),t.readFloat64()),i.kinAngVel=t.readFloat64(),i.surfaceVel=f.get(t.readFloat64(),t.readFloat64());let m=t.readFloat64(),b=t.readFloat64(),C=t.readFloat64();o===2&&(i.force=f.get(m,b),i.torque=C);let I=t.readUint8(),D=t.readFloat64();I===1&&D!==0?i.mass=D:I===0&&(i.massMode=X.DEFAULT);let J=t.readUint8(),u=t.readFloat64();J===1&&u!==0?i.inertia=u:J===0&&(i.inertiaMode=Y.DEFAULT);let h=t.readUint8(),p=t.readFloat64();h===2?(i.gravMassMode=N.SCALED,i.gravMassScale=p):h===1&&(i.gravMassMode=N.FIXED);let d=t.readUint8();i.allowMovement=(d&1)!==0,i.allowRotation=(d&2)!==0,i.isBullet=(d&4)!==0;let y=t.readUint16();for(let v=0;v<y;v++)oo(t).body=i;return i}function no(t){let o=t.readInt32(),n=t.readInt32(),e=t.readUint8(),r=t.readFloat64(),a=t.readFloat64(),i=t.readFloat64(),s=t.readFloat64();return{body1Id:o,body2Id:n,active:(e&1)!==0,ignore:(e&2)!==0,stiff:(e&4)!==0,breakUnderForce:(e&8)!==0,breakUnderError:(e&16)!==0,removeOnBreak:(e&32)!==0,frequency:r,damping:a,maxForce:i,maxError:s}}function T(t,o){t.active=o.active,t.ignore=o.ignore,t.stiff=o.stiff,t.frequency=o.frequency,t.damping=o.damping,t.maxForce=o.maxForce,t.maxError=o.maxError,t.breakUnderForce=o.breakUnderForce,t.breakUnderError=o.breakUnderError,t.removeOnBreak=o.removeOnBreak}function ao(t,o){let n=t.readUint8(),e=no(t),r=e.body1Id>=0?o[e.body1Id]??null:null,a=e.body2Id>=0?o[e.body2Id]??null:null;switch(n){case Xt:{let i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=t.readFloat64(),m=new ot(r,a,f.weak(i,s),f.weak(l,c));return T(m,e),m}case qt:{let i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=t.readFloat64(),m=t.readFloat64(),b=t.readFloat64(),C=new Q(r,a,f.weak(i,s),f.weak(l,c),m,b);return T(C,e),C}case zt:{let i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=new K(r,a,i,s,l);return T(c,e),c}case Ht:{let i=t.readFloat64(),s=t.readFloat64(),l=new tt(r,a,i,s);return T(l,e),l}case $t:{let i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=t.readFloat64(),m=t.readFloat64(),b=t.readFloat64(),C=t.readFloat64(),I=t.readFloat64(),D=new Z(r,a,f.weak(i,s),f.weak(l,c),f.weak(m,b),C,I);return T(D,e),D}case Kt:{let i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=t.readFloat64(),m=t.readFloat64(),b=t.readFloat64(),C=t.readFloat64(),I=t.readFloat64(),D=t.readFloat64(),J=t.readFloat64(),u=t.readFloat64(),h=new et(r,a,null,null,f.weak(i,s),f.weak(l,c),f.weak(m,b),f.weak(C,I),D,J,u);return T(h,e),h}case Qt:{let i=t.readFloat64(),s=t.readFloat64(),l=t.readFloat64(),c=t.readFloat64(),m=t.readFloat64(),b=new nt(r,a,f.weak(i,s),f.weak(l,c),m);return T(b,e),b}default:throw new Error(`nape-js binary: unknown constraint type tag ${n}`)}}function ro(t){let o=new it(t),n=o.readUint32();if(n!==dt)throw new Error(`nape-js binary: invalid magic bytes 0x${n.toString(16)} (expected 0x${dt.toString(16)})`);let e=o.readUint16();if(e!==_)throw new Error(`nape-js binary: unsupported version ${e} (expected ${_})`);let r=o.readUint32(),a=o.readUint32(),i=o.readUint32(),s=o.readFloat64(),l=o.readFloat64(),c=o.readFloat64(),m=o.readFloat64(),b=o.readBool(),I=o.readUint8()===0?V.SWEEP_AND_PRUNE:V.DYNAMIC_AABB_TREE,D=new R(f.weak(s,l),I);D.worldLinearDrag=c,D.worldAngularDrag=m,D.sortContacts=b;let J=new Array(r);for(let d=0;d<r;d++)J[d]=eo(o);let u=new Array(a);for(let d=0;d<a;d++)u[d]=ao(o,J);let h=new Set,p=new Set;for(let d=0;d<i;d++){let y=new G,v=o.readUint16();for(let M=0;M<v;M++){let S=o.readUint32();J[S].compound=y,h.add(S)}let A=o.readUint16();for(let M=0;M<A;M++){let S=o.readUint32();u[S].compound=y,p.add(S)}let g=o.readUint16();for(let M=0;M<g;M++)o.readUint32();y.space=D}for(let d=0;d<r;d++)h.has(d)||(J[d].space=D);for(let d=0;d<a;d++)p.has(d)||(u[d].space=D);return D}export{_ as BINARY_SNAPSHOT_VERSION,at as SNAPSHOT_VERSION,ro as spaceFromBinary,Et as spaceFromJSON,Yt as spaceToBinary,wt as spaceToJSON};
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newkrok/nape-js",
3
- "version": "3.14.0",
3
+ "version": "3.15.0",
4
4
  "description": "Nape Physics Engine - Fully typed TypeScript 2D physics engine (rewrite of the Nape Haxe engine)",
5
5
  "type": "module",
6
6
  "sideEffects": [