@newkrok/nape-js 3.13.5 → 3.13.6
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 +38 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/worker/index.cjs +238 -0
- package/dist/worker/index.d.cts +221 -0
- package/dist/worker/index.d.ts +221 -0
- package/dist/worker/index.js +238 -0
- package/llms-full.txt +126 -0
- package/llms.txt +7 -0
- package/package.json +12 -2
package/README.md
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
[](https://www.npmjs.com/package/@newkrok/nape-js)
|
|
8
8
|
[](https://www.npmjs.com/package/@newkrok/nape-js)
|
|
9
9
|
[](https://github.com/NewKrok/nape-js/actions/workflows/ci.yml)
|
|
10
|
-
[](https://github.com/NewKrok/nape-js)
|
|
11
11
|
[](https://github.com/NewKrok/nape-js/blob/master/LICENSE)
|
|
12
12
|
|
|
13
|
-
Fully typed, tree-shakeable 2D physics engine — a
|
|
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,6 +142,39 @@ 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
|
+
- **Polygon-Polygon tunneling** — When two or more dynamic `Polygon` bodies are
|
|
174
|
+
present in the same space, they may tunnel through static `Polygon` floors.
|
|
175
|
+
Single polygon works fine; circles and capsules are unaffected.
|
|
176
|
+
**Workaround:** use `Circle` shapes for free-falling objects.
|
|
177
|
+
|
|
142
178
|
## Development
|
|
143
179
|
|
|
144
180
|
```bash
|