@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.
Files changed (2) hide show
  1. package/README.md +81 -0
  2. 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.0",
4
- "description": "Load chitin .phys collision sidecars in the browser",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/Autarkis/chitin.git",
8
- "directory": "integrations/web"
9
- },
10
- "type": "module",
11
- "main": "dist/index.js",
12
- "types": "dist/index.d.ts",
13
- "exports": {
14
- ".": {
15
- "types": "./dist/index.d.ts",
16
- "import": "./dist/index.js"
17
- },
18
- "./rapier": {
19
- "types": "./dist/rapier.d.ts",
20
- "import": "./dist/rapier.js"
21
- },
22
- "./three": {
23
- "types": "./dist/three.d.ts",
24
- "import": "./dist/three.js"
25
- }
26
- },
27
- "sideEffects": false,
28
- "files": [
29
- "dist"
30
- ],
31
- "scripts": {
32
- "build": "tsc",
33
- "test": "vitest run"
34
- },
35
- "peerDependencies": {
36
- "@dimforge/rapier3d-compat": ">=0.13",
37
- "three": ">=0.160"
38
- },
39
- "peerDependenciesMeta": {
40
- "three": {
41
- "optional": true
42
- },
43
- "@dimforge/rapier3d-compat": {
44
- "optional": true
45
- }
46
- },
47
- "devDependencies": {
48
- "@dimforge/rapier3d-compat": "^0.19.3",
49
- "@types/three": "^0.184.1",
50
- "three": "^0.184.0",
51
- "typescript": "^6.0.3",
52
- "vitest": "^4.1.6"
53
- },
54
- "license": "MIT"
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
+ }