@autarkis/chitin-web 0.1.0 → 0.1.2
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 +81 -0
- package/package.json +71 -55
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @autarkis/chitin-web
|
|
2
|
+
|
|
3
|
+
Load chitin `.phys` collision sidecars in the browser. Parses the binary format
|
|
4
|
+
and turns it into Rapier colliders or Three.js debug meshes.
|
|
5
|
+
|
|
6
|
+
## Setup
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @autarkis/chitin-web
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The package uses subpath exports. The root is dependency-free -- just the `.phys`
|
|
13
|
+
parser and validator. The Rapier and Three.js bindings live under `/rapier` and
|
|
14
|
+
`/three` and pull their engines in as optional peer dependencies:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @dimforge/rapier3d-compat # for /rapier
|
|
18
|
+
npm install three # for /three
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Parse a .phys file
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { parsePhys } from "@autarkis/chitin-web";
|
|
27
|
+
|
|
28
|
+
const buffer = await fetch("/assets/scene.phys").then((r) => r.arrayBuffer());
|
|
29
|
+
const phys = parsePhys(buffer); // throws on malformed input
|
|
30
|
+
|
|
31
|
+
for (const hull of phys.hulls) {
|
|
32
|
+
console.log(hull.vertices, hull.indices); // Float32Array, Uint16Array
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Add colliders to a Rapier world
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import RAPIER from "@dimforge/rapier3d-compat";
|
|
40
|
+
import { parsePhys } from "@autarkis/chitin-web";
|
|
41
|
+
import { addToWorld } from "@autarkis/chitin-web/rapier";
|
|
42
|
+
|
|
43
|
+
const phys = parsePhys(await fetch("/scene.phys").then((r) => r.arrayBuffer()));
|
|
44
|
+
addToWorld(RAPIER, world, phys);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Use `createColliders(rapier, phys)` if you want the `ColliderDesc`s without
|
|
48
|
+
attaching them to a body.
|
|
49
|
+
|
|
50
|
+
### Pick a LOD tier
|
|
51
|
+
|
|
52
|
+
For a `.phys` with LOD tiers, select the set nearest a target concavity:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { selectLodHulls } from "@autarkis/chitin-web";
|
|
56
|
+
import { createColliders } from "@autarkis/chitin-web/rapier";
|
|
57
|
+
|
|
58
|
+
const coarseHulls = selectLodHulls(phys, 0.3); // hull data only
|
|
59
|
+
const { colliders } = createColliders(rapier, phys, { lodConcavity: 0.3 });
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Readers with no target pick default to LOD 0 (highest detail).
|
|
63
|
+
|
|
64
|
+
### Debug meshes
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { createDebugMeshes } from "@autarkis/chitin-web/three";
|
|
68
|
+
|
|
69
|
+
scene.add(createDebugMeshes(phys)); // wireframe hull visualization
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Other engines
|
|
73
|
+
|
|
74
|
+
`parsePhys` returns plain `Float32Array` / `Uint16Array` hull data. If you use a
|
|
75
|
+
physics engine other than Rapier, read the hulls directly and pass each one's
|
|
76
|
+
vertices and indices to your engine's convex-collider API -- no `/rapier` import
|
|
77
|
+
needed.
|
|
78
|
+
|
|
79
|
+
Colliders are generated by the [chitin](https://github.com/Autarkis/chitin)
|
|
80
|
+
compiler (or `@autarkis/chitin-lite` in the browser); this package only reads
|
|
81
|
+
their `.phys` output.
|
package/package.json
CHANGED
|
@@ -1,55 +1,71 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@autarkis/chitin-web",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Load chitin .phys collision sidecars in the browser",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@autarkis/chitin-web",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Load chitin .phys collision sidecars in the browser",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"physics",
|
|
7
|
+
"collision",
|
|
8
|
+
"collider",
|
|
9
|
+
"convex-hull",
|
|
10
|
+
"three",
|
|
11
|
+
"threejs",
|
|
12
|
+
"rapier",
|
|
13
|
+
"gltf",
|
|
14
|
+
"glb",
|
|
15
|
+
"robotics",
|
|
16
|
+
"webgl",
|
|
17
|
+
"phys"
|
|
18
|
+
],
|
|
19
|
+
"homepage": "https://github.com/Autarkis/chitin#readme",
|
|
20
|
+
"bugs": "https://github.com/Autarkis/chitin/issues",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Autarkis/chitin.git",
|
|
24
|
+
"directory": "integrations/web"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "dist/index.js",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./rapier": {
|
|
35
|
+
"types": "./dist/rapier.d.ts",
|
|
36
|
+
"import": "./dist/rapier.js"
|
|
37
|
+
},
|
|
38
|
+
"./three": {
|
|
39
|
+
"types": "./dist/three.d.ts",
|
|
40
|
+
"import": "./dist/three.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": false,
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc",
|
|
49
|
+
"test": "vitest run"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@dimforge/rapier3d-compat": ">=0.13",
|
|
53
|
+
"three": ">=0.160"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"three": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"@dimforge/rapier3d-compat": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@dimforge/rapier3d-compat": "^0.19.3",
|
|
65
|
+
"@types/three": "^0.184.1",
|
|
66
|
+
"three": "^0.184.0",
|
|
67
|
+
"typescript": "^6.0.3",
|
|
68
|
+
"vitest": "^4.1.6"
|
|
69
|
+
},
|
|
70
|
+
"license": "MIT"
|
|
71
|
+
}
|