@frsource/babylon-box3d 1.0.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.
- package/LICENSE +21 -0
- package/README.md +95 -0
- package/dist/index.d.mts +782 -0
- package/dist/index.d.ts +782 -0
- package/dist/index.js +1243 -0
- package/dist/index.mjs +1229 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jakub Freisler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://www.npmjs.com/package/@frsource/babylon-box3d">
|
|
3
|
+
<img src="https://img.shields.io/npm/v/@frsource/babylon-box3d.svg" alt="NPM version badge">
|
|
4
|
+
</a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@frsource/babylon-box3d">
|
|
6
|
+
<img src="https://img.shields.io/npm/dt/@frsource/babylon-box3d.svg" alt="NPM total downloads badge">
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://github.com/semantic-release/semantic-release">
|
|
9
|
+
<img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic-relase badge">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/FRSOURCE/babylon-box3d/blob/main/LICENSE">
|
|
12
|
+
<img src="https://img.shields.io/github/license/FRSOURCE/babylon-box3d.svg" alt="license MIT badge">
|
|
13
|
+
</a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
# @frsource/babylon-box3d
|
|
17
|
+
|
|
18
|
+
A Babylon.js [Physics V2](https://doc.babylonjs.com/features/featuresDeepDive/physics/v2overview) plugin backed by
|
|
19
|
+
[box3d-wasm](https://github.com/monteslu/box3d-wasm), a WebAssembly build of Erin Catto's Box3D rigid body engine.
|
|
20
|
+
|
|
21
|
+
It follows the same shape as `@babylonjs/havok`'s `HavokPlugin`: a class implementing `IPhysicsEnginePluginV2` that
|
|
22
|
+
can be passed straight to `scene.enablePhysics(gravity, plugin)`.
|
|
23
|
+
|
|
24
|
+
**[Live demo →](https://frsource.github.io/babylon-box3d/)**
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm i @frsource/babylon-box3d box3d-wasm
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`@babylonjs/core` is a peer dependency -- install whichever version (`^9.0.0`) your project already uses.
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import Box3D from 'box3d-wasm';
|
|
38
|
+
import { Box3DPlugin } from '@frsource/babylon-box3d';
|
|
39
|
+
|
|
40
|
+
const box3d = await Box3D();
|
|
41
|
+
const plugin = new Box3DPlugin(box3d);
|
|
42
|
+
|
|
43
|
+
scene.enablePhysics(new Vector3(0, -9.81, 0), plugin);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Coverage
|
|
47
|
+
|
|
48
|
+
Box3D's JS bindings are narrower than Havok's, so a few corners of `IPhysicsEnginePluginV2` are best-effort:
|
|
49
|
+
|
|
50
|
+
- Shapes: box, sphere, capsule and convex hull are fully supported. `CONTAINER` shapes are supported by attaching
|
|
51
|
+
every child shape to the same box3d body. `MESH`, `HEIGHTFIELD` and `CYLINDER` are not supported by box3d-wasm and
|
|
52
|
+
throw a descriptive error.
|
|
53
|
+
- Bodies: only a single instance per `PhysicsBody` is supported (no thin-instance batching) — `initBodyInstances`
|
|
54
|
+
falls back to treating the mesh's own transform as a single body.
|
|
55
|
+
- Constraints: `BALL_AND_SOCKET`, `DISTANCE`, `HINGE`, `SLIDER`/`PRISMATIC`, `LOCK` and `SIX_DOF` (approximated with
|
|
56
|
+
a weld/motor joint) map onto box3d's spherical/distance/revolute/prismatic/weld joints. Per-axis limit APIs are
|
|
57
|
+
best-effort since box3d joints are already axis-specific (unlike Havok's generic 6-DOF constraint).
|
|
58
|
+
- `raycast` only returns the closest hit per query (box3d-wasm exposes `castRayClosest`, not a multi-hit sweep).
|
|
59
|
+
|
|
60
|
+
## Raw box3d access
|
|
61
|
+
|
|
62
|
+
Some box3d-wasm features have no equivalent in Babylon's `IPhysicsEnginePluginV2` -- most notably its car wheel
|
|
63
|
+
joint (suspension + steering + drive in one joint), used for vehicles rather than generic constraints, plus its
|
|
64
|
+
filter and parallel joints. `Box3DPlugin` exposes the underlying `world: Box3DWorld` publicly for exactly this:
|
|
65
|
+
create bodies through Babylon as usual, then reach `plugin.world.createWheelJoint(bodyA, bodyB, options)` (or
|
|
66
|
+
`createFilterJoint`/`createParallelJoint`) directly.
|
|
67
|
+
|
|
68
|
+
`box3d-wasm` ships no bundled types at all, so this package's `box3d-wasm.d.ts` declares only what `Box3DPlugin`
|
|
69
|
+
itself uses. `extraJoints.d.ts` augments it with the wheel/filter/parallel joint surface (verified present in the
|
|
70
|
+
compiled `box3d-wasm@0.2.0` binary by instantiating it and inspecting the live prototypes) for consumers who need
|
|
71
|
+
raw access. Both are ambient module declarations; `index.ts` pulls them into the program via triple-slash
|
|
72
|
+
references, so any package that does `import { Box3DPlugin } from '@frsource/babylon-box3d'` gets them for free --
|
|
73
|
+
no `tsconfig.json` changes needed, _as long as you access box3d-wasm's types only through `Box3DPlugin` itself_
|
|
74
|
+
(e.g. `plugin.world.createWheelJoint(...)`). If your own code also writes a direct `import ... from 'box3d-wasm'`,
|
|
75
|
+
TypeScript won't honor a dependency's augmentation of an already-resolved-but-untyped module for that import (see
|
|
76
|
+
TS2665) -- copy `box3d-wasm.d.ts` (and `extraJoints.d.ts` if you need the wheel/filter/parallel joints) into your
|
|
77
|
+
own project in that case, the way `docs/` here does for the demo.
|
|
78
|
+
|
|
79
|
+
## Demo
|
|
80
|
+
|
|
81
|
+
`docs/` is a standalone Vite + Babylon.js app that ports
|
|
82
|
+
[monteslu/threejs-box3d-demo](https://github.com/monteslu/threejs-box3d-demo) (originally three.js) onto this
|
|
83
|
+
plugin, deployed to GitHub Pages from `main`. See `docs/README.md` for running it locally.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
[MIT](https://opensource.org/licenses/MIT)
|
|
88
|
+
|
|
89
|
+
Copyright (c) 2026-present, Jakub FRS Freisler, [FRSOURCE](https://www.frsource.org/)
|
|
90
|
+
|
|
91
|
+
<p align="center">
|
|
92
|
+
<a href="https://www.frsource.org/" title="Click to visit FRSOURCE page!">
|
|
93
|
+
<img src="https://www.frsource.org/logo.jpg" alt="FRSOURCE logo" height="60px"/>
|
|
94
|
+
</a>
|
|
95
|
+
</p>
|