@newkrok/nape-js 3.13.5 → 3.13.7

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/README.md CHANGED
@@ -7,10 +7,10 @@
7
7
  [![npm version](https://img.shields.io/npm/v/@newkrok/nape-js.svg)](https://www.npmjs.com/package/@newkrok/nape-js)
8
8
  [![npm downloads](https://img.shields.io/npm/dm/@newkrok/nape-js.svg)](https://www.npmjs.com/package/@newkrok/nape-js)
9
9
  [![CI](https://github.com/NewKrok/nape-js/actions/workflows/ci.yml/badge.svg)](https://github.com/NewKrok/nape-js/actions/workflows/ci.yml)
10
- [![bundle size](https://img.shields.io/badge/gzip-414%20KB-blue.svg)](https://github.com/NewKrok/nape-js)
10
+ [![bundle size](https://img.shields.io/badge/gzip-16%20KB-blue.svg)](https://github.com/NewKrok/nape-js)
11
11
  [![license](https://img.shields.io/npm/l/@newkrok/nape-js.svg)](https://github.com/NewKrok/nape-js/blob/master/LICENSE)
12
12
 
13
- Fully typed, tree-shakeable 2D physics engine — a complete TypeScript port of the
13
+ Fully typed, tree-shakeable 2D physics engine — a modern TypeScript rewrite of the
14
14
  [Nape](https://github.com/deltaluca/nape) Haxe physics engine.
15
15
 
16
16
  - Originally created in Haxe by Luca Deltodesco
@@ -57,6 +57,8 @@ function update() {
57
57
 
58
58
  ## API Reference
59
59
 
60
+ > Full API documentation: [TypeDoc Reference](https://newkrok.github.io/nape-js/api/)
61
+
60
62
  ### Core Classes
61
63
 
62
64
  | Class | Description |
@@ -75,6 +77,7 @@ function update() {
75
77
  |-------|-------------|
76
78
  | `Circle` | Circular shape |
77
79
  | `Polygon` | Convex polygon (with `Polygon.box()`, `Polygon.rect()`, `Polygon.regular()`) |
80
+ | `Capsule` | Capsule shape (`Capsule.create()`, `Capsule.createVertical()`) |
78
81
  | `Shape` | Base class with material, filter, sensor support |
79
82
 
80
83
  ### Physics Properties
@@ -139,12 +142,44 @@ bootstrap when unused. The snapshot captures bodies, shapes, materials, interact
139
142
  filters, fluid properties, all constraint types (except `UserConstraint`), and compounds.
140
143
  Arbiters and broadphase tree state are reconstructed automatically on the first step.
141
144
 
145
+ ### Web Worker
146
+
147
+ Run physics off the main thread for smooth rendering even with hundreds of bodies.
148
+
149
+ ```typescript
150
+ import "@newkrok/nape-js";
151
+ import { PhysicsWorkerManager } from "@newkrok/nape-js/worker";
152
+
153
+ const mgr = new PhysicsWorkerManager({ gravityY: 600, maxBodies: 256 });
154
+ await mgr.init();
155
+
156
+ const id = mgr.addBody("dynamic", 100, 50, [{ type: "circle", radius: 20 }]);
157
+ mgr.start();
158
+
159
+ // Read transforms on the main thread (zero-copy with SharedArrayBuffer)
160
+ function render() {
161
+ const t = mgr.getTransform(id);
162
+ if (t) drawCircle(t.x, t.y, t.rotation);
163
+ requestAnimationFrame(render);
164
+ }
165
+ render();
166
+ ```
167
+
168
+ Uses SharedArrayBuffer for zero-copy transform sharing when COOP/COEP headers are
169
+ present, with automatic `postMessage` fallback otherwise.
170
+
171
+ ## Known Issues
172
+
173
+ - **Zero-friction tunneling** — Bodies with zero-friction material and horizontal
174
+ velocity may tunnel through floors. This affects all shape types (circles,
175
+ polygons, capsules). **Workaround:** use small friction values (e.g. `0.01`).
176
+
142
177
  ## Development
143
178
 
144
179
  ```bash
145
180
  npm install
146
181
  npm run build # tsup → dist/ (ESM + CJS + DTS)
147
- npm test # vitest — 3784 tests across 176 files
182
+ npm test # vitest — 3806 tests across 177 files
148
183
  npm run benchmark # Performance benchmarks
149
184
  ```
150
185
 
@@ -2673,4 +2673,4 @@ declare class ConvexResult {
2673
2673
  toString(): string;
2674
2674
  }
2675
2675
 
2676
- export { AABB as A, Body as B, CollisionArbiter as C, DebugDraw as D, Edge as E, FluidArbiter as F, GravMassMode as G, Polygon as H, InteractionFilter as I, RayResult as J, type RayResultList as K, Listener as L, Material as M, NapeList as N, type ShapeList as O, PreFlag as P, ShapeType as Q, Ray as R, Shape as S, Space as T, type TypedListLike as U, Vec2 as V, Vec3 as a, CbEvent as b, Interactor as c, InteractionType as d, Constraint as e, Arbiter as f, MatMN as g, type ArbiterList as h, ArbiterType as i, type BodyList as j, BodyType as k, Broadphase as l, type CbTypeSet as m, Compound as n, type CompoundList as o, type ConstraintList as p, ConvexResult as q, type ConvexResultList as r, type DebugVec2 as s, FluidProperties as t, InertiaMode as u, InteractionGroup as v, type ListenerList as w, ListenerType as x, MassMode as y, Mat23 as z };
2676
+ export { AABB as A, Body as B, CollisionArbiter as C, DebugDraw as D, Edge as E, FluidArbiter as F, GravMassMode as G, Polygon as H, InteractionFilter as I, RayResult as J, type RayResultList as K, Listener as L, Material as M, NapeList as N, type ShapeList as O, PreFlag as P, ShapeType as Q, Ray as R, Shape as S, Space as T, type TypedListLike as U, Vec2 as V, Vec3 as a, CbEvent as b, Interactor as c, InteractionType as d, Constraint as e, Arbiter as f, MatMN as g, BodyType as h, type ArbiterList as i, ArbiterType as j, type BodyList as k, Broadphase as l, type CbTypeSet as m, Compound as n, type CompoundList as o, type ConstraintList as p, ConvexResult as q, type ConvexResultList as r, type DebugVec2 as s, FluidProperties as t, InertiaMode as u, InteractionGroup as v, type ListenerList as w, ListenerType as x, MassMode as y, Mat23 as z };
@@ -2673,4 +2673,4 @@ declare class ConvexResult {
2673
2673
  toString(): string;
2674
2674
  }
2675
2675
 
2676
- export { AABB as A, Body as B, CollisionArbiter as C, DebugDraw as D, Edge as E, FluidArbiter as F, GravMassMode as G, Polygon as H, InteractionFilter as I, RayResult as J, type RayResultList as K, Listener as L, Material as M, NapeList as N, type ShapeList as O, PreFlag as P, ShapeType as Q, Ray as R, Shape as S, Space as T, type TypedListLike as U, Vec2 as V, Vec3 as a, CbEvent as b, Interactor as c, InteractionType as d, Constraint as e, Arbiter as f, MatMN as g, type ArbiterList as h, ArbiterType as i, type BodyList as j, BodyType as k, Broadphase as l, type CbTypeSet as m, Compound as n, type CompoundList as o, type ConstraintList as p, ConvexResult as q, type ConvexResultList as r, type DebugVec2 as s, FluidProperties as t, InertiaMode as u, InteractionGroup as v, type ListenerList as w, ListenerType as x, MassMode as y, Mat23 as z };
2676
+ export { AABB as A, Body as B, CollisionArbiter as C, DebugDraw as D, Edge as E, FluidArbiter as F, GravMassMode as G, Polygon as H, InteractionFilter as I, RayResult as J, type RayResultList as K, Listener as L, Material as M, NapeList as N, type ShapeList as O, PreFlag as P, ShapeType as Q, Ray as R, Shape as S, Space as T, type TypedListLike as U, Vec2 as V, Vec3 as a, CbEvent as b, Interactor as c, InteractionType as d, Constraint as e, Arbiter as f, MatMN as g, BodyType as h, type ArbiterList as i, ArbiterType as j, type BodyList as k, Broadphase as l, type CbTypeSet as m, Compound as n, type CompoundList as o, type ConstraintList as p, ConvexResult as q, type ConvexResultList as r, type DebugVec2 as s, FluidProperties as t, InertiaMode as u, InteractionGroup as v, type ListenerList as w, ListenerType as x, MassMode as y, Mat23 as z };