@newkrok/nape-js 3.29.0 → 3.30.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/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/llms-full.txt +1 -1
- package/llms.txt +2 -1
- package/package.json +5 -25
- package/README.md +0 -193
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newkrok/nape-js",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.30.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": [
|
|
@@ -85,19 +85,12 @@
|
|
|
85
85
|
"lint": "eslint src/ tests/",
|
|
86
86
|
"format": "prettier --write src/ tests/",
|
|
87
87
|
"format:check": "prettier --check src/ tests/",
|
|
88
|
-
"check:circular": "madge --circular --extensions ts src/ --json | node -e \"const d=JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));if(d.length>27){console.error('New circular dependencies detected: '+d.length+' (max 27)');process.exit(1)}else{console.log('Circular dependencies: '+d.length+'/27 (OK)')}\""
|
|
89
|
-
"benchmark": "npm run build && node benchmarks/run.mjs",
|
|
90
|
-
"benchmark:json": "npm run build && node benchmarks/run.mjs --json",
|
|
91
|
-
"benchmark:compare": "node benchmarks/compare.mjs",
|
|
92
|
-
"benchmark:update-baseline": "npm run benchmark:json -- > benchmarks/baseline.json && echo 'baseline.json updated'",
|
|
93
|
-
"build:docs": "npm run build && cp dist/index.js docs/nape-js.esm.js && rm -f docs/chunk-*.js && cp dist/chunk-*.js docs/ && node scripts/stamp-docs.mjs && npm run build:typedoc",
|
|
94
|
-
"build:typedoc": "typedoc",
|
|
95
|
-
"serve:docs": "npx serve docs",
|
|
96
|
-
"dev:multiplayer": "npm run build && cp dist/index.js docs/nape-js.esm.js && rm -f docs/chunk-*.js && cp dist/chunk-*.js docs/ && npx concurrently -k -n docs,server -c cyan,green \"npx serve docs -l 5500\" \"cd server && PORT=3001 node index.js\""
|
|
88
|
+
"check:circular": "madge --circular --extensions ts src/ --json | node -e \"const d=JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));if(d.length>27){console.error('New circular dependencies detected: '+d.length+' (max 27)');process.exit(1)}else{console.log('Circular dependencies: '+d.length+'/27 (OK)')}\""
|
|
97
89
|
},
|
|
98
90
|
"repository": {
|
|
99
91
|
"type": "git",
|
|
100
|
-
"url": "git+https://github.com/NewKrok/nape-js"
|
|
92
|
+
"url": "git+https://github.com/NewKrok/nape-js",
|
|
93
|
+
"directory": "packages/nape-js"
|
|
101
94
|
},
|
|
102
95
|
"keywords": [
|
|
103
96
|
"nape",
|
|
@@ -126,18 +119,5 @@
|
|
|
126
119
|
"bugs": {
|
|
127
120
|
"url": "https://github.com/NewKrok/nape-js/issues"
|
|
128
121
|
},
|
|
129
|
-
"homepage": "https://newkrok.github.io/nape-js/"
|
|
130
|
-
"devDependencies": {
|
|
131
|
-
"@eslint/js": "^10.0.1",
|
|
132
|
-
"@vitest/coverage-v8": "^4.1.4",
|
|
133
|
-
"eslint": "^10.2.1",
|
|
134
|
-
"eslint-config-prettier": "^10.1.8",
|
|
135
|
-
"madge": "^8.0.0",
|
|
136
|
-
"prettier": "^3.8.3",
|
|
137
|
-
"tsup": "^8.4.0",
|
|
138
|
-
"typedoc": "^0.28.19",
|
|
139
|
-
"typescript": "^6.0.3",
|
|
140
|
-
"typescript-eslint": "^8.59.0",
|
|
141
|
-
"vitest": "^4.1.4"
|
|
142
|
-
}
|
|
122
|
+
"homepage": "https://newkrok.github.io/nape-js/"
|
|
143
123
|
}
|
package/README.md
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<img src="docs/logo.svg" alt="nape-js logo" width="80" />
|
|
3
|
-
</p>
|
|
4
|
-
|
|
5
|
-
# @newkrok/nape-js
|
|
6
|
-
|
|
7
|
-
[](https://www.npmjs.com/package/@newkrok/nape-js)
|
|
8
|
-
[](https://www.npmjs.com/package/@newkrok/nape-js)
|
|
9
|
-
[](https://github.com/NewKrok/nape-js/actions/workflows/ci.yml)
|
|
10
|
-
[](https://github.com/NewKrok/nape-js)
|
|
11
|
-
[](https://github.com/NewKrok/nape-js/blob/master/LICENSE)
|
|
12
|
-
[](https://newkrok.github.io/nape-js/)
|
|
13
|
-
|
|
14
|
-
Fully typed, tree-shakeable 2D physics engine — a modern TypeScript rewrite of the
|
|
15
|
-
[Nape](https://github.com/deltaluca/nape) Haxe physics engine.
|
|
16
|
-
|
|
17
|
-
**[Homepage & Interactive Demos](https://newkrok.github.io/nape-js/)** | **[API Reference](https://newkrok.github.io/nape-js/api/)** | **[Examples](https://newkrok.github.io/nape-js/examples.html)** | **[Multiplayer Demo](https://newkrok.github.io/nape-js/multiplayer.html)**
|
|
18
|
-
|
|
19
|
-
**[Cookbook](docs/guides/cookbook.md)** | **[Troubleshooting](docs/guides/troubleshooting.md)** | **[Anti-Patterns](docs/guides/anti-patterns.md)**
|
|
20
|
-
|
|
21
|
-
- Originally created in Haxe by Luca Deltodesco
|
|
22
|
-
- Ported to TypeScript by Istvan Krisztian Somoracz
|
|
23
|
-
|
|
24
|
-
## Installation
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
npm install @newkrok/nape-js
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Quick Start
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
import { Space, Body, BodyType, Vec2, Circle, Polygon } from "@newkrok/nape-js";
|
|
34
|
-
|
|
35
|
-
// Create a physics world with downward gravity
|
|
36
|
-
const space = new Space(new Vec2(0, 600));
|
|
37
|
-
|
|
38
|
-
// Static floor
|
|
39
|
-
const floor = new Body(BodyType.STATIC, new Vec2(400, 550));
|
|
40
|
-
floor.shapes.add(new Polygon(Polygon.box(800, 20)));
|
|
41
|
-
floor.space = space;
|
|
42
|
-
|
|
43
|
-
// Dynamic box
|
|
44
|
-
const box = new Body(BodyType.DYNAMIC, new Vec2(400, 100));
|
|
45
|
-
box.shapes.add(new Polygon(Polygon.box(40, 40)));
|
|
46
|
-
box.space = space;
|
|
47
|
-
|
|
48
|
-
// Dynamic circle
|
|
49
|
-
const ball = new Body(BodyType.DYNAMIC, new Vec2(420, 50));
|
|
50
|
-
ball.shapes.add(new Circle(20));
|
|
51
|
-
ball.space = space;
|
|
52
|
-
|
|
53
|
-
// Game loop
|
|
54
|
-
function update() {
|
|
55
|
-
space.step(1 / 60);
|
|
56
|
-
|
|
57
|
-
for (const body of space.bodies) {
|
|
58
|
-
console.log(`x=${body.position.x.toFixed(1)} y=${body.position.y.toFixed(1)}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## API Reference
|
|
64
|
-
|
|
65
|
-
> Full API documentation: [TypeDoc Reference](https://newkrok.github.io/nape-js/api/)
|
|
66
|
-
|
|
67
|
-
### Core Classes
|
|
68
|
-
|
|
69
|
-
| Class | Description |
|
|
70
|
-
|-------|-------------|
|
|
71
|
-
| `Space` | Physics world — add bodies, step simulation, `deterministic` mode for rollback/prediction |
|
|
72
|
-
| `Body` | Rigid body with position, velocity, mass |
|
|
73
|
-
| `Vec2` | 2D vector — pooling, `clone()`, `equals()`, `lerp()`, `fromAngle()` |
|
|
74
|
-
| `Vec3` | 3D vector for constraint impulses — `clone()`, `equals()` |
|
|
75
|
-
| `AABB` | Axis-aligned bounding box — `clone()`, `equals()`, `fromPoints()` |
|
|
76
|
-
| `Mat23` | 2×3 affine matrix — `clone()`, `equals()`, transform, inverse |
|
|
77
|
-
| `Ray` | Raycasting — `clone()`, `fromSegment()`, spatial queries |
|
|
78
|
-
|
|
79
|
-
### Shapes
|
|
80
|
-
|
|
81
|
-
| Class | Description |
|
|
82
|
-
|-------|-------------|
|
|
83
|
-
| `Circle` | Circular shape |
|
|
84
|
-
| `Polygon` | Convex polygon (with `Polygon.box()`, `Polygon.rect()`, `Polygon.regular()`) |
|
|
85
|
-
| `Capsule` | Capsule shape (`Capsule.create()`, `Capsule.createVertical()`) |
|
|
86
|
-
| `Shape` | Base class with material, filter, sensor support |
|
|
87
|
-
|
|
88
|
-
### Physics Properties
|
|
89
|
-
|
|
90
|
-
| Class | Description |
|
|
91
|
-
|-------|-------------|
|
|
92
|
-
| `Material` | Elasticity, friction, density |
|
|
93
|
-
| `BodyType` | `STATIC`, `DYNAMIC`, `KINEMATIC` |
|
|
94
|
-
| `InteractionFilter` | Bit-mask collision/sensor/fluid filtering |
|
|
95
|
-
| `FluidProperties` | Density, viscosity for fluid shapes |
|
|
96
|
-
|
|
97
|
-
### Constraints
|
|
98
|
-
|
|
99
|
-
| Class | Description |
|
|
100
|
-
|-------|-------------|
|
|
101
|
-
| `PivotJoint` | Pin two bodies at a shared point |
|
|
102
|
-
| `DistanceJoint` | Constrain distance between anchors |
|
|
103
|
-
| `WeldJoint` | Fix relative position and angle |
|
|
104
|
-
| `AngleJoint` | Constrain relative angle |
|
|
105
|
-
| `MotorJoint` | Apply angular velocity |
|
|
106
|
-
| `LineJoint` | Slide along a line |
|
|
107
|
-
| `PulleyJoint` | Constrain combined distances |
|
|
108
|
-
|
|
109
|
-
### Callbacks
|
|
110
|
-
|
|
111
|
-
| Class | Description |
|
|
112
|
-
|-------|-------------|
|
|
113
|
-
| `InteractionListener` | Collision/sensor/fluid events |
|
|
114
|
-
| `BodyListener` | Body wake/sleep events |
|
|
115
|
-
| `ConstraintListener` | Constraint events |
|
|
116
|
-
| `PreListener` | Pre-collision filtering |
|
|
117
|
-
| `CbType` | Tag interactors for filtering |
|
|
118
|
-
| `CbEvent` | `BEGIN`, `ONGOING`, `END`, `WAKE`, `SLEEP`, `BREAK` |
|
|
119
|
-
|
|
120
|
-
### Utilities
|
|
121
|
-
|
|
122
|
-
| Class | Description |
|
|
123
|
-
|-------|-------------|
|
|
124
|
-
| `NapeList<T>` | Iterable list with `for...of` support |
|
|
125
|
-
| `MatMN` | Variable-sized M×N matrix — `clone()`, `equals()`, multiply, transpose |
|
|
126
|
-
|
|
127
|
-
### Serialization
|
|
128
|
-
|
|
129
|
-
Full physics state snapshot/restore — suitable for save/load, replay, and multiplayer
|
|
130
|
-
server↔client synchronization.
|
|
131
|
-
|
|
132
|
-
```typescript
|
|
133
|
-
import "@newkrok/nape-js";
|
|
134
|
-
import { spaceToJSON, spaceFromJSON } from "@newkrok/nape-js/serialization";
|
|
135
|
-
|
|
136
|
-
// Serialize
|
|
137
|
-
const snapshot = spaceToJSON(space);
|
|
138
|
-
const json = JSON.stringify(snapshot);
|
|
139
|
-
|
|
140
|
-
// Restore (e.g. on another machine / after network transfer)
|
|
141
|
-
const restored = spaceFromJSON(JSON.parse(json));
|
|
142
|
-
restored.step(1 / 60);
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
The `/serialization` entry point is tree-shakeable — it does not pull in the engine
|
|
146
|
-
bootstrap when unused. The snapshot captures bodies, shapes, materials, interaction
|
|
147
|
-
filters, fluid properties, all constraint types (except `UserConstraint`), and compounds.
|
|
148
|
-
Arbiters and broadphase tree state are reconstructed automatically on the first step.
|
|
149
|
-
|
|
150
|
-
### Web Worker
|
|
151
|
-
|
|
152
|
-
Run physics off the main thread for smooth rendering even with hundreds of bodies.
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
import "@newkrok/nape-js";
|
|
156
|
-
import { PhysicsWorkerManager } from "@newkrok/nape-js/worker";
|
|
157
|
-
|
|
158
|
-
const mgr = new PhysicsWorkerManager({ gravityY: 600, maxBodies: 256 });
|
|
159
|
-
await mgr.init();
|
|
160
|
-
|
|
161
|
-
const id = mgr.addBody("dynamic", 100, 50, [{ type: "circle", radius: 20 }]);
|
|
162
|
-
mgr.start();
|
|
163
|
-
|
|
164
|
-
// Read transforms on the main thread (zero-copy with SharedArrayBuffer)
|
|
165
|
-
function render() {
|
|
166
|
-
const t = mgr.getTransform(id);
|
|
167
|
-
if (t) drawCircle(t.x, t.y, t.rotation);
|
|
168
|
-
requestAnimationFrame(render);
|
|
169
|
-
}
|
|
170
|
-
render();
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
Uses SharedArrayBuffer for zero-copy transform sharing when COOP/COEP headers are
|
|
174
|
-
present, with automatic `postMessage` fallback otherwise.
|
|
175
|
-
|
|
176
|
-
## Known Issues
|
|
177
|
-
|
|
178
|
-
- **Zero-friction tunneling** — Bodies with zero-friction material and horizontal
|
|
179
|
-
velocity may tunnel through floors. This affects all shape types (circles,
|
|
180
|
-
polygons, capsules). **Workaround:** use small friction values (e.g. `0.01`).
|
|
181
|
-
|
|
182
|
-
## Development
|
|
183
|
-
|
|
184
|
-
```bash
|
|
185
|
-
npm install
|
|
186
|
-
npm run build # tsup → dist/ (ESM + CJS + DTS)
|
|
187
|
-
npm test # vitest — 4773 tests across 208 files
|
|
188
|
-
npm run benchmark # Performance benchmarks
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
## License
|
|
192
|
-
|
|
193
|
-
MIT
|