@newkrok/nape-js 3.38.0 → 3.39.1
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.
- package/dist/chunk-BARGM4ZO.js +2 -0
- package/dist/{chunk-GPGT7DYQ.js → chunk-N7HIFDFT.js} +2 -2
- package/dist/{chunk-CA2F5ISB.cjs → chunk-Q2WPJQGU.cjs} +2 -2
- package/dist/chunk-WB53BIOZ.cjs +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/replay/index.cjs +1 -1
- package/dist/replay/index.js +1 -1
- package/dist/serialization/index.cjs +1 -1
- package/dist/serialization/index.js +1 -1
- package/dist/worker/index.cjs +3 -3
- package/dist/worker/index.d.cts +11 -1
- package/dist/worker/index.d.ts +11 -1
- package/dist/worker/index.js +3 -3
- package/package.json +2 -1
- package/dist/chunk-263GQ5UK.js +0 -2
- package/dist/chunk-HQH77APJ.cjs +0 -2
package/dist/replay/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkQ2WPJQGU_cjs=require('../chunk-Q2WPJQGU.cjs');require('../chunk-WB53BIOZ.cjs');var _=class{constructor(t,e={}){this._inputs=[];this._keyframes=[];this._frame=0;this._finished=false;if(t==null)throw new Error("Recorder: space is required");let i=e.keyframeEvery;if(i!=null&&(!Number.isFinite(i)||i<0||(i|0)!==i))throw new Error(`Recorder: keyframeEvery must be a non-negative integer (got ${i})`);this._space=t,this._keyframeEvery=i??60,this._initialSnapshot=chunkQ2WPJQGU_cjs.b(t);}get frame(){return this._frame}get finished(){return this._finished}recordFrame(t){if(this._finished)throw new Error("Recorder: cannot record after finish()");if(this._keyframeEvery>0&&this._frame>0&&this._frame%this._keyframeEvery===0&&this._keyframes.push({frame:this._frame,snapshot:chunkQ2WPJQGU_cjs.b(this._space)}),t!=null){let e=v(t);this._inputs.push({frame:this._frame,payload:e});}this._frame++;}finish(){return this._finished=true,{version:f,initialSnapshot:this._initialSnapshot,inputs:this._inputs.slice(),keyframes:this._keyframes.slice(),frameCount:this._frame}}},f=1;function v(r){let t=typeof r;return r===null||t==="number"||t==="string"||t==="boolean"?r:JSON.parse(JSON.stringify(r))}var d=class{constructor(t,e=null,i={}){this._space=null;this._frame=0;if(t==null)throw new Error("Player: replay is required");this._replay=t,this._applyInput=e,this._dt=i.dt??1/60,this._velocityIterations=i.velocityIterations??8,this._positionIterations=i.positionIterations??3;}restore(){return this._space=chunkQ2WPJQGU_cjs.c(this._replay.initialSnapshot),this._frame=0,this._space}get space(){if(this._space==null)throw new Error("Player: call restore() before reading space");return this._space}get frame(){return this._frame}get frameCount(){return this._replay.frameCount}get finished(){return this._frame>=this._replay.frameCount}get replay(){return this._replay}get applyInput(){return this._applyInput}set applyInput(t){this._applyInput=t;}step(){if(this._space==null)throw new Error("Player: call restore() before step()");if(this._frame>=this._replay.frameCount)throw new Error(`Player: already at end of replay (frame ${this._frame}/${this._replay.frameCount})`);let t=I(this._replay.inputs,this._frame);t!=null&&this._applyInput!=null&&this._applyInput(t.payload,this._space,this._frame),this._space.step(this._dt,this._velocityIterations,this._positionIterations),this._frame++;}stepTo(t){if(!Number.isFinite(t)||t<0||t>this._replay.frameCount)throw new Error(`Player: target frame ${t} out of range [0, ${this._replay.frameCount}]`);if(this._space==null&&this.restore(),t<this._frame){let e=S(this._replay.keyframes,t);e!=null?(this._space=chunkQ2WPJQGU_cjs.c(e.snapshot),this._frame=e.frame):this.restore();}for(;this._frame<t;)this.step();}};function I(r,t){let e=0,i=r.length-1;for(;e<=i;){let a=e+i>>>1,o=r[a].frame;if(o===t)return r[a];o<t?e=a+1:i=a-1;}return null}function S(r,t){let e=0,i=r.length-1,a=null;for(;e<=i;){let o=e+i>>>1,n=r[o];n.frame<=t?(a=n,e=o+1):i=o-1;}return a}var R=1380994137,T=new TextEncoder,E=new TextDecoder;function U(r){let t=[];for(let s of r.inputs){let u=JSON.stringify(s.payload);t.push({frame:s.frame,bytes:T.encode(u??"null")});}let e=14+r.initialSnapshot.byteLength;e+=4;for(let s of t)e+=8+s.bytes.byteLength;e+=4;for(let s of r.keyframes)e+=8+s.snapshot.byteLength;let i=new ArrayBuffer(e),a=new DataView(i),o=new Uint8Array(i),n=0;a.setUint32(n,R,false),n+=4,a.setUint16(n,r.version,true),n+=2,a.setUint32(n,r.frameCount,true),n+=4,a.setUint32(n,r.initialSnapshot.byteLength,true),n+=4,o.set(r.initialSnapshot,n),n+=r.initialSnapshot.byteLength,a.setUint32(n,t.length,true),n+=4;for(let s of t)a.setUint32(n,s.frame,true),n+=4,a.setUint32(n,s.bytes.byteLength,true),n+=4,o.set(s.bytes,n),n+=s.bytes.byteLength;a.setUint32(n,r.keyframes.length,true),n+=4;for(let s of r.keyframes)a.setUint32(n,s.frame,true),n+=4,a.setUint32(n,s.snapshot.byteLength,true),n+=4,o.set(s.snapshot,n),n+=s.snapshot.byteLength;return o}function k(r){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),e=0,i=t.getUint32(e,false);if(e+=4,i!==R)throw new Error(`decodeReplay: invalid magic 0x${i.toString(16).padStart(8,"0")} (expected 0x${R.toString(16)})`);let a=t.getUint16(e,true);if(e+=2,a!==f)throw new Error(`decodeReplay: unsupported version ${a} (expected ${f})`);let o=t.getUint32(e,true);e+=4;let n=t.getUint32(e,true);e+=4;let s=r.slice(e,e+n);e+=n;let u=t.getUint32(e,true);e+=4;let b=new Array(u);for(let p=0;p<u;p++){let m=t.getUint32(e,true);e+=4;let l=t.getUint32(e,true);e+=4;let y=E.decode(r.subarray(e,e+l));e+=l,b[p]={frame:m,payload:JSON.parse(y)};}let g=t.getUint32(e,true);e+=4;let w=new Array(g);for(let p=0;p<g;p++){let m=t.getUint32(e,true);e+=4;let l=t.getUint32(e,true);e+=4;let y=r.slice(e,e+l);e+=l,w[p]={frame:m,snapshot:y};}return {version:a,initialSnapshot:s,inputs:b,keyframes:w,frameCount:o}}function A(r){let t=[];return r==null?{ok:false,warnings:["space is null"]}:(r.deterministic||t.push("space.deterministic is false \u2014 replays will drift from the recording. Set space.deterministic = true."),{ok:t.length===0,warnings:t})}exports.Player=d;exports.REPLAY_VERSION=f;exports.Recorder=_;exports.decodeReplay=k;exports.encodeReplay=U;exports.validateDeterministicConfig=A;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/replay/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {b,c}from'../chunk-
|
|
1
|
+
import {b,c}from'../chunk-N7HIFDFT.js';import'../chunk-BARGM4ZO.js';var _=class{constructor(t,e={}){this._inputs=[];this._keyframes=[];this._frame=0;this._finished=false;if(t==null)throw new Error("Recorder: space is required");let i=e.keyframeEvery;if(i!=null&&(!Number.isFinite(i)||i<0||(i|0)!==i))throw new Error(`Recorder: keyframeEvery must be a non-negative integer (got ${i})`);this._space=t,this._keyframeEvery=i??60,this._initialSnapshot=b(t);}get frame(){return this._frame}get finished(){return this._finished}recordFrame(t){if(this._finished)throw new Error("Recorder: cannot record after finish()");if(this._keyframeEvery>0&&this._frame>0&&this._frame%this._keyframeEvery===0&&this._keyframes.push({frame:this._frame,snapshot:b(this._space)}),t!=null){let e=v(t);this._inputs.push({frame:this._frame,payload:e});}this._frame++;}finish(){return this._finished=true,{version:f,initialSnapshot:this._initialSnapshot,inputs:this._inputs.slice(),keyframes:this._keyframes.slice(),frameCount:this._frame}}},f=1;function v(r){let t=typeof r;return r===null||t==="number"||t==="string"||t==="boolean"?r:JSON.parse(JSON.stringify(r))}var d=class{constructor(t,e=null,i={}){this._space=null;this._frame=0;if(t==null)throw new Error("Player: replay is required");this._replay=t,this._applyInput=e,this._dt=i.dt??1/60,this._velocityIterations=i.velocityIterations??8,this._positionIterations=i.positionIterations??3;}restore(){return this._space=c(this._replay.initialSnapshot),this._frame=0,this._space}get space(){if(this._space==null)throw new Error("Player: call restore() before reading space");return this._space}get frame(){return this._frame}get frameCount(){return this._replay.frameCount}get finished(){return this._frame>=this._replay.frameCount}get replay(){return this._replay}get applyInput(){return this._applyInput}set applyInput(t){this._applyInput=t;}step(){if(this._space==null)throw new Error("Player: call restore() before step()");if(this._frame>=this._replay.frameCount)throw new Error(`Player: already at end of replay (frame ${this._frame}/${this._replay.frameCount})`);let t=I(this._replay.inputs,this._frame);t!=null&&this._applyInput!=null&&this._applyInput(t.payload,this._space,this._frame),this._space.step(this._dt,this._velocityIterations,this._positionIterations),this._frame++;}stepTo(t){if(!Number.isFinite(t)||t<0||t>this._replay.frameCount)throw new Error(`Player: target frame ${t} out of range [0, ${this._replay.frameCount}]`);if(this._space==null&&this.restore(),t<this._frame){let e=S(this._replay.keyframes,t);e!=null?(this._space=c(e.snapshot),this._frame=e.frame):this.restore();}for(;this._frame<t;)this.step();}};function I(r,t){let e=0,i=r.length-1;for(;e<=i;){let a=e+i>>>1,o=r[a].frame;if(o===t)return r[a];o<t?e=a+1:i=a-1;}return null}function S(r,t){let e=0,i=r.length-1,a=null;for(;e<=i;){let o=e+i>>>1,n=r[o];n.frame<=t?(a=n,e=o+1):i=o-1;}return a}var R=1380994137,T=new TextEncoder,E=new TextDecoder;function U(r){let t=[];for(let s of r.inputs){let u=JSON.stringify(s.payload);t.push({frame:s.frame,bytes:T.encode(u??"null")});}let e=14+r.initialSnapshot.byteLength;e+=4;for(let s of t)e+=8+s.bytes.byteLength;e+=4;for(let s of r.keyframes)e+=8+s.snapshot.byteLength;let i=new ArrayBuffer(e),a=new DataView(i),o=new Uint8Array(i),n=0;a.setUint32(n,R,false),n+=4,a.setUint16(n,r.version,true),n+=2,a.setUint32(n,r.frameCount,true),n+=4,a.setUint32(n,r.initialSnapshot.byteLength,true),n+=4,o.set(r.initialSnapshot,n),n+=r.initialSnapshot.byteLength,a.setUint32(n,t.length,true),n+=4;for(let s of t)a.setUint32(n,s.frame,true),n+=4,a.setUint32(n,s.bytes.byteLength,true),n+=4,o.set(s.bytes,n),n+=s.bytes.byteLength;a.setUint32(n,r.keyframes.length,true),n+=4;for(let s of r.keyframes)a.setUint32(n,s.frame,true),n+=4,a.setUint32(n,s.snapshot.byteLength,true),n+=4,o.set(s.snapshot,n),n+=s.snapshot.byteLength;return o}function k(r){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),e=0,i=t.getUint32(e,false);if(e+=4,i!==R)throw new Error(`decodeReplay: invalid magic 0x${i.toString(16).padStart(8,"0")} (expected 0x${R.toString(16)})`);let a=t.getUint16(e,true);if(e+=2,a!==f)throw new Error(`decodeReplay: unsupported version ${a} (expected ${f})`);let o=t.getUint32(e,true);e+=4;let n=t.getUint32(e,true);e+=4;let s=r.slice(e,e+n);e+=n;let u=t.getUint32(e,true);e+=4;let b=new Array(u);for(let p=0;p<u;p++){let m=t.getUint32(e,true);e+=4;let l=t.getUint32(e,true);e+=4;let y=E.decode(r.subarray(e,e+l));e+=l,b[p]={frame:m,payload:JSON.parse(y)};}let g=t.getUint32(e,true);e+=4;let w=new Array(g);for(let p=0;p<g;p++){let m=t.getUint32(e,true);e+=4;let l=t.getUint32(e,true);e+=4;let y=r.slice(e,e+l);e+=l,w[p]={frame:m,snapshot:y};}return {version:a,initialSnapshot:s,inputs:b,keyframes:w,frameCount:o}}function A(r){let t=[];return r==null?{ok:false,warnings:["space is null"]}:(r.deterministic||t.push("space.deterministic is false \u2014 replays will drift from the recording. Set space.deterministic = true."),{ok:t.length===0,warnings:t})}export{d as Player,f as REPLAY_VERSION,_ as Recorder,k as decodeReplay,U as encodeReplay,A as validateDeterministicConfig};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkQ2WPJQGU_cjs=require('../chunk-Q2WPJQGU.cjs'),chunkWB53BIOZ_cjs=require('../chunk-WB53BIOZ.cjs');var J=1;function s(t){return {x:t.x,y:t.y}}function Q(t){if(t==null)return null;try{let a=JSON.stringify(t);return a==="{}"?null:JSON.parse(a)}catch{return null}}function it(t){return {elasticity:t.elasticity,dynamicFriction:t.dynamicFriction,staticFriction:t.staticFriction,density:t.density,rollingFriction:t.rollingFriction}}function st(t){return {collisionGroup:t.collisionGroup,collisionMask:t.collisionMask,sensorGroup:t.sensorGroup,sensorMask:t.sensorMask,fluidGroup:t.fluidGroup,fluidMask:t.fluidMask}}function lt(t){if(t==null)return null;let a=t.gravity;return {density:t.density,viscosity:t.viscosity,gravity:a!=null?s(a):null}}function ct(t){let a=it(t.material),n=st(t.filter),e=t.fluidEnabled,o=e?lt(t.fluidProperties):null,l=t.sensorEnabled;if(t.isCircle()){let c=t,r=t.localCOM;return {type:"circle",radius:c.radius,localCOM:s(r),material:a,filter:n,sensorEnabled:l,fluidEnabled:e,fluidProperties:o}}else if(t.isCapsule()){let c=t,r=t.localCOM;return {type:"capsule",width:c.width,height:c.height,localCOM:s(r),material:a,filter:n,sensorEnabled:l,fluidEnabled:e,fluidProperties:o}}else {let r=t.localVerts,m=[],u=r.length;for(let b=0;b<u;b++)m.push(s(r.at(b)));return {type:"polygon",localVerts:m,material:a,filter:n,sensorEnabled:l,fluidEnabled:e,fluidProperties:o}}}var ut={1:"STATIC",2:"DYNAMIC",3:"KINEMATIC"},pt={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},mt={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},Dt={0:"DEFAULT",1:"FIXED",2:"SCALED"};function yt(t,a){let n=t.zpp_inner,e=pt[n.massMode]??"DEFAULT",o=mt[n.inertiaMode]??"DEFAULT",l=Dt[n.gravMassMode]??"DEFAULT",c=[],r=t.shapes,m=r.length;for(let u=0;u<m;u++)c.push(ct(r.at(u)));return {id:a,type:ut[n.type]??"DYNAMIC",position:s(t.position),rotation:t.rotation,velocity:s(t.velocity),angularVel:t.angularVel,kinematicVel:s(t.kinematicVel),kinAngVel:t.kinAngVel,surfaceVel:s(t.surfaceVel),force:s(t.force),torque:n.type===2?t.torque:0,massMode:e,mass:e==="FIXED"?n.cmass:null,inertiaMode:o,inertia:o==="FIXED"?n.cinertia:null,gravMassMode:l,gravMassScale:n.gravMassScale,allowMovement:t.allowMovement,allowRotation:t.allowRotation,bullet:t.isBullet,shapes:c,userData:Q(n.userData)}}function h(t,a,n,e){let o=t.zpp_inner,l=n!=null?a.get(n.zpp_inner.id)??null:null,c=e!=null?a.get(e.zpp_inner.id)??null:null;return {body1Id:l,body2Id:c,active:o.active,ignore:o.ignore,stiff:o.stiff,frequency:o.frequency,damping:o.damping,maxForce:o.maxForce,maxError:o.maxError,breakUnderForce:o.breakUnderForce,breakUnderError:o.breakUnderError,removeOnBreak:o.removeOnBreak,userData:Q(o.userData)}}function ft(t,a){switch(t.constructor?.name??""){case "PivotJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"PivotJoint",anchor1:s(e.anchor1),anchor2:s(e.anchor2)}}case "DistanceJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"DistanceJoint",anchor1:s(e.anchor1),anchor2:s(e.anchor2),jointMin:e.jointMin,jointMax:e.jointMax}}case "AngleJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"AngleJoint",jointMin:e.jointMin,jointMax:e.jointMax,ratio:e.ratio}}case "MotorJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"MotorJoint",rate:e.rate,ratio:e.ratio}}case "LineJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"LineJoint",anchor1:s(e.anchor1),anchor2:s(e.anchor2),direction:s(e.direction),jointMin:e.jointMin,jointMax:e.jointMax}}case "PulleyJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"PulleyJoint",anchor1:s(e.anchor1),anchor2:s(e.anchor2),anchor3:s(e.anchor3),anchor4:s(e.anchor4),jointMin:e.jointMin,jointMax:e.jointMax,ratio:e.ratio}}case "WeldJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"WeldJoint",anchor1:s(e.anchor1),anchor2:s(e.anchor2),phase:e.phase}}default:return null}}function dt(t){let a=[],n=new Map,e=new Map;function o(i){let y=i.zpp_inner.id;if(e.has(y))return;let D=a.length;n.set(i,D),e.set(y,D),a.push(yt(i,D));}let l=t.bodies,c=l.length;for(let i=0;i<c;i++)o(l.at(i));let r=t.compounds,m=r.length;for(let i=0;i<m;i++){let D=r.at(i).bodies,C=D.length;for(let f=0;f<C;f++)o(D.at(f));}let u=[],b=new Map;function I(i){if(b.has(i))return;let y=ft(i,e);y!=null&&(b.set(i,u.length),u.push(y));}let x=t.constraints,Z=x.length;for(let i=0;i<Z;i++)I(x.at(i));for(let i=0;i<m;i++){let D=r.at(i).constraints,C=D.length;for(let f=0;f<C;f++)I(D.at(f));}let V=[];for(let i=0;i<m;i++){let y=r.at(i),D=[],C=y.bodies,f=C.length;for(let M=0;M<f;M++){let F=C.at(M),S=n.get(F);S!=null&&D.push(S);}let B=[],w=y.constraints,nt=w.length;for(let M=0;M<nt;M++){let F=w.at(M),S=b.get(F);S!=null&&B.push(S);}V.push({bodyIds:D,constraintIndices:B,childIndices:[]});}let tt=t.zpp_inner.bphase.is_sweep?"SWEEP_AND_PRUNE":"DYNAMIC_AABB_TREE",et=t.gravity;return {version:1,gravity:s(et),worldLinearDrag:t.worldLinearDrag,worldAngularDrag:t.worldAngularDrag,sortContacts:t.sortContacts,deterministic:t.deterministic,broadphase:tt,bodies:a,constraints:u,compounds:V}}function d(t){return chunkWB53BIOZ_cjs.I.get(t.x,t.y)}function p(t){return chunkWB53BIOZ_cjs.I.weak(t.x,t.y)}function bt(t){return new chunkWB53BIOZ_cjs.ca(t.elasticity,t.dynamicFriction,t.staticFriction,t.density,t.rollingFriction)}function Mt(t){let a=new chunkWB53BIOZ_cjs.ha;return a.collisionGroup=t.collisionGroup,a.collisionMask=t.collisionMask,a.sensorGroup=t.sensorGroup,a.sensorMask=t.sensorMask,a.fluidGroup=t.fluidGroup,a.fluidMask=t.fluidMask,a}function ht(t){let a=new chunkWB53BIOZ_cjs.U(t.density,t.viscosity);return t.gravity!=null&&(a.gravity=d(t.gravity)),a}function gt(t){let a=bt(t.material),n=Mt(t.filter),e;if(t.type==="circle"){let o=d(t.localCOM);e=new chunkWB53BIOZ_cjs.ga(t.radius,o,a,n);}else if(t.type==="capsule"){let o=d(t.localCOM);e=new chunkWB53BIOZ_cjs.ja(t.width,t.height,o,a,n);}else {let o=t.localVerts.map(l=>d(l));e=new chunkWB53BIOZ_cjs.ia(o,a,n);}return e.sensorEnabled=t.sensorEnabled,e.fluidEnabled=t.fluidEnabled,t.fluidEnabled&&t.fluidProperties!=null&&(e.fluidProperties=ht(t.fluidProperties)),e}function Ct(t){let a=t.type==="STATIC"?chunkWB53BIOZ_cjs.aa.STATIC:t.type==="KINEMATIC"?chunkWB53BIOZ_cjs.aa.KINEMATIC:chunkWB53BIOZ_cjs.aa.DYNAMIC,n=new chunkWB53BIOZ_cjs.$(a,p(t.position));n.rotation=t.rotation,t.type!=="STATIC"&&(n.velocity=d(t.velocity),n.angularVel=t.angularVel),n.kinematicVel=d(t.kinematicVel),n.kinAngVel=t.kinAngVel,n.surfaceVel=d(t.surfaceVel),t.type==="DYNAMIC"&&(n.force=d(t.force),n.torque=t.torque),t.massMode==="FIXED"&&t.mass!=null?n.mass=t.mass:t.massMode==="DEFAULT"&&(n.massMode=chunkWB53BIOZ_cjs.fa.DEFAULT),t.inertiaMode==="FIXED"&&t.inertia!=null?n.inertia=t.inertia:t.inertiaMode==="DEFAULT"&&(n.inertiaMode=chunkWB53BIOZ_cjs.ea.DEFAULT),t.gravMassMode==="SCALED"?(n.gravMassMode=chunkWB53BIOZ_cjs.da.SCALED,n.gravMassScale=t.gravMassScale):t.gravMassMode==="FIXED"&&(n.gravMassMode=chunkWB53BIOZ_cjs.da.FIXED),n.allowMovement=t.allowMovement,n.allowRotation=t.allowRotation,n.isBullet=t.bullet;for(let e of t.shapes)gt(e).body=n;return t.userData!=null&&Object.assign(n.userData,t.userData),n}function g(t,a){t.active=a.active,t.ignore=a.ignore,t.stiff=a.stiff,t.frequency=a.frequency,t.damping=a.damping,t.maxForce=a.maxForce,t.maxError=a.maxError,t.breakUnderForce=a.breakUnderForce,t.breakUnderError=a.breakUnderError,t.removeOnBreak=a.removeOnBreak,a.userData!=null&&Object.assign(t.userData,a.userData);}function St(t,a){let n=t.body1Id!=null?a[t.body1Id]??null:null,e=t.body2Id!=null?a[t.body2Id]??null:null;switch(t.type){case "PivotJoint":{let o=new chunkWB53BIOZ_cjs.ra(n,e,p(t.anchor1),p(t.anchor2));return g(o,t),o}case "DistanceJoint":{let o=new chunkWB53BIOZ_cjs.oa(n,e,p(t.anchor1),p(t.anchor2),t.jointMin,t.jointMax);return g(o,t),o}case "AngleJoint":{let o=new chunkWB53BIOZ_cjs.na(n,e,t.jointMin,t.jointMax,t.ratio);return g(o,t),o}case "MotorJoint":{let o=new chunkWB53BIOZ_cjs.qa(n,e,t.rate,t.ratio);return g(o,t),o}case "LineJoint":{let o=new chunkWB53BIOZ_cjs.pa(n,e,p(t.anchor1),p(t.anchor2),p(t.direction),t.jointMin,t.jointMax);return g(o,t),o}case "PulleyJoint":{let o=new chunkWB53BIOZ_cjs.sa(n,e,null,null,p(t.anchor1),p(t.anchor2),p(t.anchor3),p(t.anchor4),t.jointMin,t.jointMax,t.ratio);return g(o,t),o}case "WeldJoint":{let o=new chunkWB53BIOZ_cjs.ta(n,e,p(t.anchor1),p(t.anchor2),t.phase);return g(o,t),o}}}function Et(t){if(t.version!==1)throw new Error(`nape-js serialization: unsupported snapshot version ${t.version} (expected ${1})`);let a=t.broadphase==="SWEEP_AND_PRUNE"?chunkWB53BIOZ_cjs.ka.SWEEP_AND_PRUNE:chunkWB53BIOZ_cjs.ka.DYNAMIC_AABB_TREE,n=new chunkWB53BIOZ_cjs.Y(p(t.gravity),a);n.worldLinearDrag=t.worldLinearDrag,n.worldAngularDrag=t.worldAngularDrag,n.sortContacts=t.sortContacts,n.deterministic=t.deterministic??false;let e=t.bodies.map(Ct),o=t.constraints.map(r=>St(r,e)),l=new Set,c=new Set;for(let r of t.compounds){let m=new chunkWB53BIOZ_cjs.ba;for(let u of r.bodyIds)e[u].compound=m,l.add(u);for(let u of r.constraintIndices)o[u].compound=m,c.add(u);m.space=n;}for(let r=0;r<e.length;r++)l.has(r)||(e[r].space=n);for(let r=0;r<o.length;r++)c.has(r)||(o[r].space=n);return n}Object.defineProperty(exports,"BINARY_SNAPSHOT_VERSION",{enumerable:true,get:function(){return chunkQ2WPJQGU_cjs.a}});Object.defineProperty(exports,"spaceFromBinary",{enumerable:true,get:function(){return chunkQ2WPJQGU_cjs.c}});Object.defineProperty(exports,"spaceToBinary",{enumerable:true,get:function(){return chunkQ2WPJQGU_cjs.b}});exports.SNAPSHOT_VERSION=J;exports.spaceFromJSON=Et;exports.spaceToJSON=dt;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as BINARY_SNAPSHOT_VERSION,c as spaceFromBinary,b as spaceToBinary}from'../chunk-
|
|
1
|
+
export{a as BINARY_SNAPSHOT_VERSION,c as spaceFromBinary,b as spaceToBinary}from'../chunk-N7HIFDFT.js';import {ka,Y,ba,I,aa,$,fa,ea,da,ta,sa,pa,qa,na,oa,ra,ga,ja,ia,ca,ha,U}from'../chunk-BARGM4ZO.js';var J=1;function s(t){return {x:t.x,y:t.y}}function Q(t){if(t==null)return null;try{let a=JSON.stringify(t);return a==="{}"?null:JSON.parse(a)}catch{return null}}function it(t){return {elasticity:t.elasticity,dynamicFriction:t.dynamicFriction,staticFriction:t.staticFriction,density:t.density,rollingFriction:t.rollingFriction}}function st(t){return {collisionGroup:t.collisionGroup,collisionMask:t.collisionMask,sensorGroup:t.sensorGroup,sensorMask:t.sensorMask,fluidGroup:t.fluidGroup,fluidMask:t.fluidMask}}function lt(t){if(t==null)return null;let a=t.gravity;return {density:t.density,viscosity:t.viscosity,gravity:a!=null?s(a):null}}function ct(t){let a=it(t.material),n=st(t.filter),e=t.fluidEnabled,o=e?lt(t.fluidProperties):null,l=t.sensorEnabled;if(t.isCircle()){let c=t,r=t.localCOM;return {type:"circle",radius:c.radius,localCOM:s(r),material:a,filter:n,sensorEnabled:l,fluidEnabled:e,fluidProperties:o}}else if(t.isCapsule()){let c=t,r=t.localCOM;return {type:"capsule",width:c.width,height:c.height,localCOM:s(r),material:a,filter:n,sensorEnabled:l,fluidEnabled:e,fluidProperties:o}}else {let r=t.localVerts,m=[],u=r.length;for(let b=0;b<u;b++)m.push(s(r.at(b)));return {type:"polygon",localVerts:m,material:a,filter:n,sensorEnabled:l,fluidEnabled:e,fluidProperties:o}}}var ut={1:"STATIC",2:"DYNAMIC",3:"KINEMATIC"},pt={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},mt={0:"DEFAULT",1:"FIXED",2:"FIXED_GROUP"},Dt={0:"DEFAULT",1:"FIXED",2:"SCALED"};function yt(t,a){let n=t.zpp_inner,e=pt[n.massMode]??"DEFAULT",o=mt[n.inertiaMode]??"DEFAULT",l=Dt[n.gravMassMode]??"DEFAULT",c=[],r=t.shapes,m=r.length;for(let u=0;u<m;u++)c.push(ct(r.at(u)));return {id:a,type:ut[n.type]??"DYNAMIC",position:s(t.position),rotation:t.rotation,velocity:s(t.velocity),angularVel:t.angularVel,kinematicVel:s(t.kinematicVel),kinAngVel:t.kinAngVel,surfaceVel:s(t.surfaceVel),force:s(t.force),torque:n.type===2?t.torque:0,massMode:e,mass:e==="FIXED"?n.cmass:null,inertiaMode:o,inertia:o==="FIXED"?n.cinertia:null,gravMassMode:l,gravMassScale:n.gravMassScale,allowMovement:t.allowMovement,allowRotation:t.allowRotation,bullet:t.isBullet,shapes:c,userData:Q(n.userData)}}function h(t,a,n,e){let o=t.zpp_inner,l=n!=null?a.get(n.zpp_inner.id)??null:null,c=e!=null?a.get(e.zpp_inner.id)??null:null;return {body1Id:l,body2Id:c,active:o.active,ignore:o.ignore,stiff:o.stiff,frequency:o.frequency,damping:o.damping,maxForce:o.maxForce,maxError:o.maxError,breakUnderForce:o.breakUnderForce,breakUnderError:o.breakUnderError,removeOnBreak:o.removeOnBreak,userData:Q(o.userData)}}function ft(t,a){switch(t.constructor?.name??""){case "PivotJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"PivotJoint",anchor1:s(e.anchor1),anchor2:s(e.anchor2)}}case "DistanceJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"DistanceJoint",anchor1:s(e.anchor1),anchor2:s(e.anchor2),jointMin:e.jointMin,jointMax:e.jointMax}}case "AngleJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"AngleJoint",jointMin:e.jointMin,jointMax:e.jointMax,ratio:e.ratio}}case "MotorJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"MotorJoint",rate:e.rate,ratio:e.ratio}}case "LineJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"LineJoint",anchor1:s(e.anchor1),anchor2:s(e.anchor2),direction:s(e.direction),jointMin:e.jointMin,jointMax:e.jointMax}}case "PulleyJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"PulleyJoint",anchor1:s(e.anchor1),anchor2:s(e.anchor2),anchor3:s(e.anchor3),anchor4:s(e.anchor4),jointMin:e.jointMin,jointMax:e.jointMax,ratio:e.ratio}}case "WeldJoint":{let e=t;return {...h(t,a,e.body1,e.body2),type:"WeldJoint",anchor1:s(e.anchor1),anchor2:s(e.anchor2),phase:e.phase}}default:return null}}function dt(t){let a=[],n=new Map,e=new Map;function o(i){let y=i.zpp_inner.id;if(e.has(y))return;let D=a.length;n.set(i,D),e.set(y,D),a.push(yt(i,D));}let l=t.bodies,c=l.length;for(let i=0;i<c;i++)o(l.at(i));let r=t.compounds,m=r.length;for(let i=0;i<m;i++){let D=r.at(i).bodies,C=D.length;for(let f=0;f<C;f++)o(D.at(f));}let u=[],b=new Map;function I(i){if(b.has(i))return;let y=ft(i,e);y!=null&&(b.set(i,u.length),u.push(y));}let x=t.constraints,Z=x.length;for(let i=0;i<Z;i++)I(x.at(i));for(let i=0;i<m;i++){let D=r.at(i).constraints,C=D.length;for(let f=0;f<C;f++)I(D.at(f));}let V=[];for(let i=0;i<m;i++){let y=r.at(i),D=[],C=y.bodies,f=C.length;for(let M=0;M<f;M++){let F=C.at(M),S=n.get(F);S!=null&&D.push(S);}let B=[],w=y.constraints,nt=w.length;for(let M=0;M<nt;M++){let F=w.at(M),S=b.get(F);S!=null&&B.push(S);}V.push({bodyIds:D,constraintIndices:B,childIndices:[]});}let tt=t.zpp_inner.bphase.is_sweep?"SWEEP_AND_PRUNE":"DYNAMIC_AABB_TREE",et=t.gravity;return {version:1,gravity:s(et),worldLinearDrag:t.worldLinearDrag,worldAngularDrag:t.worldAngularDrag,sortContacts:t.sortContacts,deterministic:t.deterministic,broadphase:tt,bodies:a,constraints:u,compounds:V}}function d(t){return I.get(t.x,t.y)}function p(t){return I.weak(t.x,t.y)}function bt(t){return new ca(t.elasticity,t.dynamicFriction,t.staticFriction,t.density,t.rollingFriction)}function Mt(t){let a=new ha;return a.collisionGroup=t.collisionGroup,a.collisionMask=t.collisionMask,a.sensorGroup=t.sensorGroup,a.sensorMask=t.sensorMask,a.fluidGroup=t.fluidGroup,a.fluidMask=t.fluidMask,a}function ht(t){let a=new U(t.density,t.viscosity);return t.gravity!=null&&(a.gravity=d(t.gravity)),a}function gt(t){let a=bt(t.material),n=Mt(t.filter),e;if(t.type==="circle"){let o=d(t.localCOM);e=new ga(t.radius,o,a,n);}else if(t.type==="capsule"){let o=d(t.localCOM);e=new ja(t.width,t.height,o,a,n);}else {let o=t.localVerts.map(l=>d(l));e=new ia(o,a,n);}return e.sensorEnabled=t.sensorEnabled,e.fluidEnabled=t.fluidEnabled,t.fluidEnabled&&t.fluidProperties!=null&&(e.fluidProperties=ht(t.fluidProperties)),e}function Ct(t){let a=t.type==="STATIC"?aa.STATIC:t.type==="KINEMATIC"?aa.KINEMATIC:aa.DYNAMIC,n=new $(a,p(t.position));n.rotation=t.rotation,t.type!=="STATIC"&&(n.velocity=d(t.velocity),n.angularVel=t.angularVel),n.kinematicVel=d(t.kinematicVel),n.kinAngVel=t.kinAngVel,n.surfaceVel=d(t.surfaceVel),t.type==="DYNAMIC"&&(n.force=d(t.force),n.torque=t.torque),t.massMode==="FIXED"&&t.mass!=null?n.mass=t.mass:t.massMode==="DEFAULT"&&(n.massMode=fa.DEFAULT),t.inertiaMode==="FIXED"&&t.inertia!=null?n.inertia=t.inertia:t.inertiaMode==="DEFAULT"&&(n.inertiaMode=ea.DEFAULT),t.gravMassMode==="SCALED"?(n.gravMassMode=da.SCALED,n.gravMassScale=t.gravMassScale):t.gravMassMode==="FIXED"&&(n.gravMassMode=da.FIXED),n.allowMovement=t.allowMovement,n.allowRotation=t.allowRotation,n.isBullet=t.bullet;for(let e of t.shapes)gt(e).body=n;return t.userData!=null&&Object.assign(n.userData,t.userData),n}function g(t,a){t.active=a.active,t.ignore=a.ignore,t.stiff=a.stiff,t.frequency=a.frequency,t.damping=a.damping,t.maxForce=a.maxForce,t.maxError=a.maxError,t.breakUnderForce=a.breakUnderForce,t.breakUnderError=a.breakUnderError,t.removeOnBreak=a.removeOnBreak,a.userData!=null&&Object.assign(t.userData,a.userData);}function St(t,a){let n=t.body1Id!=null?a[t.body1Id]??null:null,e=t.body2Id!=null?a[t.body2Id]??null:null;switch(t.type){case "PivotJoint":{let o=new ra(n,e,p(t.anchor1),p(t.anchor2));return g(o,t),o}case "DistanceJoint":{let o=new oa(n,e,p(t.anchor1),p(t.anchor2),t.jointMin,t.jointMax);return g(o,t),o}case "AngleJoint":{let o=new na(n,e,t.jointMin,t.jointMax,t.ratio);return g(o,t),o}case "MotorJoint":{let o=new qa(n,e,t.rate,t.ratio);return g(o,t),o}case "LineJoint":{let o=new pa(n,e,p(t.anchor1),p(t.anchor2),p(t.direction),t.jointMin,t.jointMax);return g(o,t),o}case "PulleyJoint":{let o=new sa(n,e,null,null,p(t.anchor1),p(t.anchor2),p(t.anchor3),p(t.anchor4),t.jointMin,t.jointMax,t.ratio);return g(o,t),o}case "WeldJoint":{let o=new ta(n,e,p(t.anchor1),p(t.anchor2),t.phase);return g(o,t),o}}}function Et(t){if(t.version!==1)throw new Error(`nape-js serialization: unsupported snapshot version ${t.version} (expected ${1})`);let a=t.broadphase==="SWEEP_AND_PRUNE"?ka.SWEEP_AND_PRUNE:ka.DYNAMIC_AABB_TREE,n=new Y(p(t.gravity),a);n.worldLinearDrag=t.worldLinearDrag,n.worldAngularDrag=t.worldAngularDrag,n.sortContacts=t.sortContacts,n.deterministic=t.deterministic??false;let e=t.bodies.map(Ct),o=t.constraints.map(r=>St(r,e)),l=new Set,c=new Set;for(let r of t.compounds){let m=new ba;for(let u of r.bodyIds)e[u].compound=m,l.add(u);for(let u of r.constraintIndices)o[u].compound=m,c.add(u);m.space=n;}for(let r=0;r<e.length;r++)l.has(r)||(e[r].space=n);for(let r=0;r<o.length;r++)c.has(r)||(o[r].space=n);return n}export{J as SNAPSHOT_VERSION,Et as spaceFromJSON,dt as spaceToJSON};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/worker/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var i=3,a=3;function p(d){return `
|
|
1
|
+
'use strict';var l=1,i=3,a=3;function p(d){return `
|
|
2
2
|
/* nape-js physics worker \u2014 auto-generated, do not edit */
|
|
3
3
|
const FLOATS_PER_BODY = 3;
|
|
4
4
|
const HEADER_FLOATS = 3;
|
|
@@ -234,6 +234,6 @@ self.onmessage = async (e) => {
|
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
};
|
|
237
|
-
`}var
|
|
238
|
-
exports.FLOATS_PER_BODY=i;exports.HEADER_FLOATS=a;exports.PhysicsWorkerManager=y;exports.buildWorkerScript=p;//# sourceMappingURL=index.cjs.map
|
|
237
|
+
`}var m="https://cdn.jsdelivr.net/npm/@newkrok/nape-js/dist/index.js",y=class{constructor(e={}){this.worker=null;this.buffer=null;this.transforms=null;this.useShared=false;this.nextId=0;this.bodySlots=new Map;this.readyPromise=null;this.onFrame=null;this.destroyed=false;this.napeUrl=m;this.maxBodies=e.maxBodies??512,this.timestep=e.timestep??1/60,this.velocityIterations=e.velocityIterations??10,this.positionIterations=e.positionIterations??10,this.gravityX=e.gravityX??0,this.gravityY=e.gravityY??600,this.workerUrl=e.workerUrl,this.autoStep=e.autoStep??true;}init(){return this.readyPromise?this.readyPromise:(this.readyPromise=this.doInit(),this.readyPromise)}async doInit(){if(this.workerUrl)this.worker=new Worker(this.workerUrl,{type:"module"});else {let s=p(this.napeUrl),t=new Blob([s],{type:"application/javascript"}),r=URL.createObjectURL(t);this.worker=new Worker(r,{type:"module"}),URL.revokeObjectURL(r);}let e=(3+this.maxBodies*3)*Float32Array.BYTES_PER_ELEMENT;return typeof SharedArrayBuffer<"u"?(this.buffer=new SharedArrayBuffer(e),this.transforms=new Float32Array(this.buffer),this.useShared=true):(this.buffer=null,this.transforms=new Float32Array(3+this.maxBodies*3),this.useShared=false),this.worker.onmessage=s=>{let t=s.data;t.type==="frame"&&!this.useShared&&t.buffer?(this.transforms=t.buffer,this.onFrame?.(t.buffer)):t.type==="frame"&&this.useShared&&this.onFrame?.(this.transforms);},new Promise((s,t)=>{let r=o=>{o.data.type==="ready"?(this.worker.removeEventListener("message",r),s()):o.data.type==="error"&&(this.worker.removeEventListener("message",r),t(new Error(o.data.message)));};this.worker.addEventListener("message",r),this.worker.postMessage({type:"init",maxBodies:this.maxBodies,timestep:this.timestep,velocityIterations:this.velocityIterations,positionIterations:this.positionIterations,gravityX:this.gravityX,gravityY:this.gravityY,buffer:this.useShared?this.buffer:null});})}start(){this.post({type:"start"});}stop(){this.post({type:"stop"});}step(){this.post({type:"step"});}destroy(){this.destroyed||(this.destroyed=true,this.post({type:"destroy"}),this.worker?.terminate(),this.worker=null,this.transforms=null,this.buffer=null,this.bodySlots.clear());}addBody(e,s,t,r,o){let n=this.nextId++;return this.bodySlots.set(n,this.bodySlots.size),this.post({type:"addBody",id:n,bodyType:e,x:s,y:t,shapes:r,options:o}),n}removeBody(e){this.bodySlots.delete(e),this.post({type:"removeBody",id:e});}applyForce(e,s,t){this.post({type:"applyForce",id:e,fx:s,fy:t});}applyImpulse(e,s,t){this.post({type:"applyImpulse",id:e,ix:s,iy:t});}setVelocity(e,s,t){this.post({type:"setVelocity",id:e,vx:s,vy:t});}setPosition(e,s,t){this.post({type:"setPosition",id:e,x:s,y:t});}setGravity(e,s){this.post({type:"setGravity",gravityX:e,gravityY:s});}getTransform(e){let s=this.bodySlots.get(e);if(s===void 0||!this.transforms)return null;let t=3+s*3;return {x:this.transforms[t],y:this.transforms[t+1],rotation:this.transforms[t+2]}}readAllTransforms(e){if(this.transforms)for(let[s,t]of this.bodySlots){let r=3+t*3,o=e.get(s);o?(o.x=this.transforms[r],o.y=this.transforms[r+1],o.rotation=this.transforms[r+2]):e.set(s,{x:this.transforms[r],y:this.transforms[r+1],rotation:this.transforms[r+2]});}}get rawTransforms(){return this.transforms}get bodyCount(){return this.transforms?this.transforms[0]:0}get timestamp(){return this.transforms?this.transforms[1]:0}get stepTimeMs(){return this.transforms?this.transforms[2]:0}get isSharedBuffer(){return this.useShared}set onFrameCallback(e){this.onFrame=e;}post(e){this.worker?.postMessage(e);}};
|
|
238
|
+
exports.FLOATS_PER_BODY=i;exports.HEADER_FLOATS=a;exports.PROTOCOL_VERSION=l;exports.PhysicsWorkerManager=y;exports.buildWorkerScript=p;//# sourceMappingURL=index.cjs.map
|
|
239
239
|
//# sourceMappingURL=index.cjs.map
|
package/dist/worker/index.d.cts
CHANGED
|
@@ -9,6 +9,16 @@
|
|
|
9
9
|
* (missing COOP/COEP headers) the worker posts a copy of the buffer each
|
|
10
10
|
* tick via `postMessage`.
|
|
11
11
|
*/
|
|
12
|
+
/**
|
|
13
|
+
* Version of the transform-buffer wire layout.
|
|
14
|
+
*
|
|
15
|
+
* Bump this whenever the float layout changes ({@link FLOATS_PER_BODY},
|
|
16
|
+
* {@link HEADER_FLOATS}, or the meaning of any slot) so that a mismatch
|
|
17
|
+
* between a cached worker bundle and the main thread is caught loudly
|
|
18
|
+
* instead of decoding garbage transforms. Must be kept in lockstep with
|
|
19
|
+
* `TRANSFORM_PROTOCOL_VERSION` in `@newkrok/nape-pixi`'s `workerProtocol.ts`.
|
|
20
|
+
*/
|
|
21
|
+
declare const PROTOCOL_VERSION = 1;
|
|
12
22
|
/** Floats per body in the transform buffer: x, y, rotation. */
|
|
13
23
|
declare const FLOATS_PER_BODY = 3;
|
|
14
24
|
/**
|
|
@@ -218,4 +228,4 @@ declare class PhysicsWorkerManager {
|
|
|
218
228
|
*/
|
|
219
229
|
declare function buildWorkerScript(napeUrl: string): string;
|
|
220
230
|
|
|
221
|
-
export { type BodyOptions, type BodyTransform, type BoxDesc, type CircleDesc, FLOATS_PER_BODY, HEADER_FLOATS, PhysicsWorkerManager, type PhysicsWorkerOptions, type PolygonDesc, type ShapeDesc, buildWorkerScript };
|
|
231
|
+
export { type BodyOptions, type BodyTransform, type BoxDesc, type CircleDesc, FLOATS_PER_BODY, HEADER_FLOATS, PROTOCOL_VERSION, PhysicsWorkerManager, type PhysicsWorkerOptions, type PolygonDesc, type ShapeDesc, buildWorkerScript };
|
package/dist/worker/index.d.ts
CHANGED
|
@@ -9,6 +9,16 @@
|
|
|
9
9
|
* (missing COOP/COEP headers) the worker posts a copy of the buffer each
|
|
10
10
|
* tick via `postMessage`.
|
|
11
11
|
*/
|
|
12
|
+
/**
|
|
13
|
+
* Version of the transform-buffer wire layout.
|
|
14
|
+
*
|
|
15
|
+
* Bump this whenever the float layout changes ({@link FLOATS_PER_BODY},
|
|
16
|
+
* {@link HEADER_FLOATS}, or the meaning of any slot) so that a mismatch
|
|
17
|
+
* between a cached worker bundle and the main thread is caught loudly
|
|
18
|
+
* instead of decoding garbage transforms. Must be kept in lockstep with
|
|
19
|
+
* `TRANSFORM_PROTOCOL_VERSION` in `@newkrok/nape-pixi`'s `workerProtocol.ts`.
|
|
20
|
+
*/
|
|
21
|
+
declare const PROTOCOL_VERSION = 1;
|
|
12
22
|
/** Floats per body in the transform buffer: x, y, rotation. */
|
|
13
23
|
declare const FLOATS_PER_BODY = 3;
|
|
14
24
|
/**
|
|
@@ -218,4 +228,4 @@ declare class PhysicsWorkerManager {
|
|
|
218
228
|
*/
|
|
219
229
|
declare function buildWorkerScript(napeUrl: string): string;
|
|
220
230
|
|
|
221
|
-
export { type BodyOptions, type BodyTransform, type BoxDesc, type CircleDesc, FLOATS_PER_BODY, HEADER_FLOATS, PhysicsWorkerManager, type PhysicsWorkerOptions, type PolygonDesc, type ShapeDesc, buildWorkerScript };
|
|
231
|
+
export { type BodyOptions, type BodyTransform, type BoxDesc, type CircleDesc, FLOATS_PER_BODY, HEADER_FLOATS, PROTOCOL_VERSION, PhysicsWorkerManager, type PhysicsWorkerOptions, type PolygonDesc, type ShapeDesc, buildWorkerScript };
|
package/dist/worker/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var i=3,a=3;function p(d){return `
|
|
1
|
+
var l=1,i=3,a=3;function p(d){return `
|
|
2
2
|
/* nape-js physics worker \u2014 auto-generated, do not edit */
|
|
3
3
|
const FLOATS_PER_BODY = 3;
|
|
4
4
|
const HEADER_FLOATS = 3;
|
|
@@ -234,6 +234,6 @@ self.onmessage = async (e) => {
|
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
};
|
|
237
|
-
`}var
|
|
238
|
-
export{i as FLOATS_PER_BODY,a as HEADER_FLOATS,y as PhysicsWorkerManager,p as buildWorkerScript};//# sourceMappingURL=index.js.map
|
|
237
|
+
`}var m="https://cdn.jsdelivr.net/npm/@newkrok/nape-js/dist/index.js",y=class{constructor(e={}){this.worker=null;this.buffer=null;this.transforms=null;this.useShared=false;this.nextId=0;this.bodySlots=new Map;this.readyPromise=null;this.onFrame=null;this.destroyed=false;this.napeUrl=m;this.maxBodies=e.maxBodies??512,this.timestep=e.timestep??1/60,this.velocityIterations=e.velocityIterations??10,this.positionIterations=e.positionIterations??10,this.gravityX=e.gravityX??0,this.gravityY=e.gravityY??600,this.workerUrl=e.workerUrl,this.autoStep=e.autoStep??true;}init(){return this.readyPromise?this.readyPromise:(this.readyPromise=this.doInit(),this.readyPromise)}async doInit(){if(this.workerUrl)this.worker=new Worker(this.workerUrl,{type:"module"});else {let s=p(this.napeUrl),t=new Blob([s],{type:"application/javascript"}),r=URL.createObjectURL(t);this.worker=new Worker(r,{type:"module"}),URL.revokeObjectURL(r);}let e=(3+this.maxBodies*3)*Float32Array.BYTES_PER_ELEMENT;return typeof SharedArrayBuffer<"u"?(this.buffer=new SharedArrayBuffer(e),this.transforms=new Float32Array(this.buffer),this.useShared=true):(this.buffer=null,this.transforms=new Float32Array(3+this.maxBodies*3),this.useShared=false),this.worker.onmessage=s=>{let t=s.data;t.type==="frame"&&!this.useShared&&t.buffer?(this.transforms=t.buffer,this.onFrame?.(t.buffer)):t.type==="frame"&&this.useShared&&this.onFrame?.(this.transforms);},new Promise((s,t)=>{let r=o=>{o.data.type==="ready"?(this.worker.removeEventListener("message",r),s()):o.data.type==="error"&&(this.worker.removeEventListener("message",r),t(new Error(o.data.message)));};this.worker.addEventListener("message",r),this.worker.postMessage({type:"init",maxBodies:this.maxBodies,timestep:this.timestep,velocityIterations:this.velocityIterations,positionIterations:this.positionIterations,gravityX:this.gravityX,gravityY:this.gravityY,buffer:this.useShared?this.buffer:null});})}start(){this.post({type:"start"});}stop(){this.post({type:"stop"});}step(){this.post({type:"step"});}destroy(){this.destroyed||(this.destroyed=true,this.post({type:"destroy"}),this.worker?.terminate(),this.worker=null,this.transforms=null,this.buffer=null,this.bodySlots.clear());}addBody(e,s,t,r,o){let n=this.nextId++;return this.bodySlots.set(n,this.bodySlots.size),this.post({type:"addBody",id:n,bodyType:e,x:s,y:t,shapes:r,options:o}),n}removeBody(e){this.bodySlots.delete(e),this.post({type:"removeBody",id:e});}applyForce(e,s,t){this.post({type:"applyForce",id:e,fx:s,fy:t});}applyImpulse(e,s,t){this.post({type:"applyImpulse",id:e,ix:s,iy:t});}setVelocity(e,s,t){this.post({type:"setVelocity",id:e,vx:s,vy:t});}setPosition(e,s,t){this.post({type:"setPosition",id:e,x:s,y:t});}setGravity(e,s){this.post({type:"setGravity",gravityX:e,gravityY:s});}getTransform(e){let s=this.bodySlots.get(e);if(s===void 0||!this.transforms)return null;let t=3+s*3;return {x:this.transforms[t],y:this.transforms[t+1],rotation:this.transforms[t+2]}}readAllTransforms(e){if(this.transforms)for(let[s,t]of this.bodySlots){let r=3+t*3,o=e.get(s);o?(o.x=this.transforms[r],o.y=this.transforms[r+1],o.rotation=this.transforms[r+2]):e.set(s,{x:this.transforms[r],y:this.transforms[r+1],rotation:this.transforms[r+2]});}}get rawTransforms(){return this.transforms}get bodyCount(){return this.transforms?this.transforms[0]:0}get timestamp(){return this.transforms?this.transforms[1]:0}get stepTimeMs(){return this.transforms?this.transforms[2]:0}get isSharedBuffer(){return this.useShared}set onFrameCallback(e){this.onFrame=e;}post(e){this.worker?.postMessage(e);}};
|
|
238
|
+
export{i as FLOATS_PER_BODY,a as HEADER_FLOATS,l as PROTOCOL_VERSION,y as PhysicsWorkerManager,p as buildWorkerScript};//# sourceMappingURL=index.js.map
|
|
239
239
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newkrok/nape-js",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.39.1",
|
|
4
4
|
"description": "High-performance 2D physics engine for TypeScript & JavaScript — rigid bodies, constraints, fluid simulation, raycasting, and deterministic multiplayer. Tree-shakeable, zero dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -92,6 +92,7 @@
|
|
|
92
92
|
"build": "tsup",
|
|
93
93
|
"test": "vitest run",
|
|
94
94
|
"test:watch": "vitest",
|
|
95
|
+
"coverage": "vitest run --coverage",
|
|
95
96
|
"lint": "eslint src/ tests/",
|
|
96
97
|
"format": "prettier --write src/ tests/",
|
|
97
98
|
"format:check": "prettier --check src/ tests/",
|