@khr3/launchers 0.2.2 → 0.2.3

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 CHANGED
@@ -5,6 +5,9 @@ Zero-dependency KHR articulated launcher moving-part planner (`receiver`, `bolt`
5
5
  - **Zero dependencies & zero `koota`**: Pure TypeScript ESM with `.d.ts` declarations.
6
6
  - **Articulated KHR physics output**: `planLauncher(recipe)` lumps fixed parts and mounted rail attachments into `Receiver_Root` — diagonalizing the full 3x3 parallel-axis inertia tensor into `inertiaDiagonal` + right-handed `inertiaOrientation` quaternion (`[qx, qy, qz, qw]`) — and emits prismatic/revolute `KHR_physics_rigid_bodies` joints with critically damped spring drives for `Bolt`, `Trigger`, and `Pump`.
7
7
 
8
+ - Full API & integration reference: [docs/api-reference.md](./docs/api-reference.md)
9
+ - Runnable example: [example/index.ts](./example/index.ts)
10
+
8
11
  ## Install
9
12
 
10
13
  ```sh
@@ -4,9 +4,9 @@
4
4
  * Fixed parts and rail attachments lump into `Receiver_Root`; articulated parts (`Bolt`, `Trigger`,
5
5
  * `Pump`) emit `KHR_physics_rigid_bodies` prismatic/revolute joints with spring drives.
6
6
  */
7
- import { diagonalizeInertiaTensor, sumLauncherBoxes, } from "./inertia.js";
8
- import { boxInertiaDiagonal, buildLauncherParts, resolveLauncherSockets, } from "./launcherParts.js";
9
- import { RAIL_SOCKETS, } from "./schema.js";
7
+ import { diagonalizeInertiaTensor, sumLauncherBoxes } from "./inertia.js";
8
+ import { boxInertiaDiagonal, buildLauncherParts, resolveLauncherSockets } from "./launcherParts.js";
9
+ import { RAIL_SOCKETS } from "./schema.js";
10
10
  export { diagonalizeInertiaTensor, sumLauncherBoxes };
11
11
  function fallbackRailSocket(d, rail) {
12
12
  if (rail === "rail_top")
@@ -3,7 +3,7 @@
3
3
  * Frame: SI metres, +Y up, +Z muzzle forward (or -Z muzzle in Khronos emitter space; socket `muzzle` gives exact local point).
4
4
  * Zero runtime dependencies.
5
5
  */
6
- import { LAUNCHER_SOCKETS, validateLauncherSpec, } from "./schema.js";
6
+ import { LAUNCHER_SOCKETS, validateLauncherSpec } from "./schema.js";
7
7
  function isPosFinite(v) {
8
8
  return Number.isFinite(v) && v > 0;
9
9
  }
package/dist/recipes.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { LauncherRecipe } from "./launcherParts.js";
1
+ import { type LauncherRecipe } from "./launcherParts.js";
2
2
  export declare const KOLMOGOROV_PISTOL: LauncherRecipe;
3
3
  export declare const KOLMOGOROV_CARBINE: LauncherRecipe;
4
4
  export declare const KOLMOGOROV_SHOTGUN: LauncherRecipe;
package/dist/recipes.js CHANGED
@@ -1,24 +1,25 @@
1
+ import {} from "./launcherParts.js";
1
2
  import { DEFAULT_AMMO_CATALOG } from "./schema.js";
2
- export const KOLMOGOROV_PISTOL = Object.freeze({
3
+ export const KOLMOGOROV_PISTOL = {
3
4
  id: "kolmogorov_pistol",
4
5
  label: "Kolmogorov 9mm Sidearm",
5
6
  r2Key: "weapons/kolmogorov_pistol.glb",
6
- spec: Object.freeze({
7
+ spec: {
7
8
  id: "kolmogorov_pistol",
8
9
  ammoId: DEFAULT_AMMO_CATALOG.pistol.id,
9
10
  fireRateHz: 6.5,
10
11
  magazineCapacity: 15,
11
12
  reloadSec: 1.4,
12
13
  recoilImpulseNs: 3.4,
13
- sockets: Object.freeze({
14
+ sockets: {
14
15
  grip_primary: [0, -0.06, -0.04],
15
16
  rail_under: [0, -0.015, 0.08],
16
17
  muzzle: [0, 0.0105, 0.19],
17
18
  eject_port: [0.016, 0.024, 0.02],
18
19
  sight_align: [0, 0.038, -0.06],
19
- }),
20
- }),
21
- dims: Object.freeze({
20
+ },
21
+ },
22
+ dims: {
22
23
  receiverLength: 0.16,
23
24
  receiverWidth: 0.032,
24
25
  receiverHeight: 0.042,
@@ -29,8 +30,8 @@ export const KOLMOGOROV_PISTOL = Object.freeze({
29
30
  boltStroke: 0.042,
30
31
  hasStock: false,
31
32
  hasPump: false,
32
- }),
33
- masses: Object.freeze({
33
+ },
34
+ masses: {
34
35
  receiver: 0.48,
35
36
  barrel: 0.14,
36
37
  bolt: 0.24,
@@ -38,20 +39,20 @@ export const KOLMOGOROV_PISTOL = Object.freeze({
38
39
  magazine: 0.18,
39
40
  stock: 0,
40
41
  pump: 0,
41
- }),
42
- });
43
- export const KOLMOGOROV_CARBINE = Object.freeze({
42
+ },
43
+ };
44
+ export const KOLMOGOROV_CARBINE = {
44
45
  id: "kolmogorov_carbine",
45
46
  label: "Kolmogorov 5.56 Modular Carbine",
46
47
  r2Key: "weapons/kolmogorov_carbine.glb",
47
- spec: Object.freeze({
48
+ spec: {
48
49
  id: "kolmogorov_carbine",
49
50
  ammoId: DEFAULT_AMMO_CATALOG.rifle.id,
50
51
  fireRateHz: 11.5,
51
52
  magazineCapacity: 30,
52
53
  reloadSec: 1.9,
53
54
  recoilImpulseNs: 4.8,
54
- sockets: Object.freeze({
55
+ sockets: {
55
56
  grip_primary: [0, -0.08, -0.07],
56
57
  grip_secondary: [0, -0.03, 0.28],
57
58
  rail_top: [0, 0.042, 0.04],
@@ -59,9 +60,9 @@ export const KOLMOGOROV_CARBINE = Object.freeze({
59
60
  muzzle: [0, 0.017, 0.5],
60
61
  eject_port: [0.024, 0.018, 0.04],
61
62
  sight_align: [0, 0.062, -0.08],
62
- }),
63
- }),
64
- dims: Object.freeze({
63
+ },
64
+ },
65
+ dims: {
65
66
  receiverLength: 0.26,
66
67
  receiverWidth: 0.046,
67
68
  receiverHeight: 0.068,
@@ -72,8 +73,8 @@ export const KOLMOGOROV_CARBINE = Object.freeze({
72
73
  boltStroke: 0.075,
73
74
  hasStock: true,
74
75
  hasPump: false,
75
- }),
76
- masses: Object.freeze({
76
+ },
77
+ masses: {
77
78
  receiver: 1.35,
78
79
  barrel: 0.68,
79
80
  bolt: 0.38,
@@ -81,29 +82,29 @@ export const KOLMOGOROV_CARBINE = Object.freeze({
81
82
  magazine: 0.36,
82
83
  stock: 0.45,
83
84
  pump: 0,
84
- }),
85
- });
86
- export const KOLMOGOROV_SHOTGUN = Object.freeze({
85
+ },
86
+ };
87
+ export const KOLMOGOROV_SHOTGUN = {
87
88
  id: "kolmogorov_shotgun",
88
89
  label: "Kolmogorov 12G Pump Breacher",
89
90
  r2Key: "weapons/kolmogorov_shotgun.glb",
90
- spec: Object.freeze({
91
+ spec: {
91
92
  id: "kolmogorov_shotgun",
92
93
  ammoId: DEFAULT_AMMO_CATALOG.shells_12g.id,
93
94
  fireRateHz: 1.4,
94
95
  magazineCapacity: 8,
95
96
  reloadSec: 2.6,
96
97
  recoilImpulseNs: 14.5,
97
- sockets: Object.freeze({
98
+ sockets: {
98
99
  grip_primary: [0, -0.07, -0.08],
99
100
  grip_secondary: [0, -0.02, 0.34],
100
101
  rail_top: [0, 0.04, 0.02],
101
102
  muzzle: [0, 0.016, 0.58],
102
103
  eject_port: [0.025, 0.018, 0.05],
103
104
  sight_align: [0, 0.052, -0.09],
104
- }),
105
- }),
106
- dims: Object.freeze({
105
+ },
106
+ },
107
+ dims: {
107
108
  receiverLength: 0.24,
108
109
  receiverWidth: 0.048,
109
110
  receiverHeight: 0.064,
@@ -114,8 +115,8 @@ export const KOLMOGOROV_SHOTGUN = Object.freeze({
114
115
  boltStroke: 0.085,
115
116
  hasStock: true,
116
117
  hasPump: true,
117
- }),
118
- masses: Object.freeze({
118
+ },
119
+ masses: {
119
120
  receiver: 1.45,
120
121
  barrel: 0.85,
121
122
  bolt: 0.32,
@@ -123,8 +124,8 @@ export const KOLMOGOROV_SHOTGUN = Object.freeze({
123
124
  magazine: 0.22,
124
125
  stock: 0.52,
125
126
  pump: 0.28,
126
- }),
127
- });
127
+ },
128
+ };
128
129
  export const PISTOL_9MM = KOLMOGOROV_PISTOL;
129
130
  export const CARBINE_556 = KOLMOGOROV_CARBINE;
130
131
  export const SHOTGUN_12G = KOLMOGOROV_SHOTGUN;
package/dist/runtime.js CHANGED
@@ -1,4 +1,4 @@
1
- import { validateLauncherSpec, } from "./schema.js";
1
+ import { validateLauncherSpec } from "./schema.js";
2
2
  export function createLauncherState(spec) {
3
3
  validateLauncherSpec(spec);
4
4
  return {
@@ -0,0 +1,72 @@
1
+ # `@khr3/launchers` API and Configuration Guide
2
+
3
+ This guide documents the public `@khr3/launchers` API: part roles, rail/character sockets, SI ammo specs, recipes, multi-body KHR planning, and deterministic launch cycle state stepping.
4
+
5
+ ## Import Path
6
+
7
+ ```ts
8
+ import {
9
+ LAUNCHER_PART_ROLES,
10
+ LAUNCHER_SOCKETS,
11
+ RAIL_SOCKETS,
12
+ CHARACTER_SOCKETS,
13
+ DEFAULT_AMMO_CATALOG,
14
+ PISTOL_9MM,
15
+ CARBINE_556,
16
+ SHOTGUN_12G,
17
+ LAUNCHER_RECIPES,
18
+ findLauncherRecipe,
19
+ validateLauncherSpec,
20
+ createLauncherState,
21
+ stepLauncher,
22
+ attachModule,
23
+ detachModule,
24
+ buildLauncherParts,
25
+ resolveLauncherSockets,
26
+ diagonalizeInertiaTensor,
27
+ sumLauncherBoxes,
28
+ planLauncher,
29
+ } from "@khr3/launchers";
30
+ ```
31
+
32
+ ## Schema & Ammo (`schema`)
33
+
34
+ - `LAUNCHER_PART_ROLES`: `"receiver" | "bolt" | "pump" | "trigger" | "magazine" | "barrel" | "stock" | "screen_rect"`
35
+ - `LAUNCHER_SOCKETS`: `"grip_primary" | "grip_secondary" | "rail_top" | "rail_under" | "muzzle" | "eject_port" | "sight_align"`
36
+ - `RAIL_SOCKETS`: `"rail_top" | "rail_under" | "muzzle"`
37
+ - `CHARACTER_SOCKETS`: `"Socket_Hand_R" | "Socket_Hand_L" | "Socket_Head" | "Socket_Back"`
38
+
39
+ ### `DEFAULT_AMMO_CATALOG`
40
+
41
+ | ID | `muzzleSpeedMs` | `massKg` | `casingRadiusM` | `casingLengthM` | `tipRatio` | `color` |
42
+ | --- | --- | --- | --- | --- | --- | --- |
43
+ | `pistol` | `360` | `0.008` | `0.0049` | `0.019` | `0.35` | `#E3A83B` |
44
+ | `rifle` | `880` | `0.004` | `0.0048` | `0.045` | `0.45` | `#D68A28` |
45
+ | `shells_12g` | `400` | `0.032` | `0.01` | `0.07` | `0` | `#C83228` |
46
+ | `laser` | `1200` | `0.0001` | `0` | `0` | `0` | `#26E3E8` |
47
+ | `orb` | `42` | `0.12` | `0` | `0` | `0` | `#E3782A` |
48
+ | `rocket` | `95` | `1.4` | `0.035` | `0.32` | `0.3` | `#D93832` |
49
+
50
+ `validateLauncherSpec(spec)` throws `Error` / `RangeError` if `fireRateHz <= 0`, `magazineCapacity < 1` (non-int), `reloadSec < 0`, `recoilImpulseNs < 0`, or `grip_primary` / `muzzle` sockets are missing/non-finite.
51
+
52
+ ## Runtime State Machine (`runtime`)
53
+
54
+ | Function | Signature | Description |
55
+ | --- | --- | --- |
56
+ | `createLauncherState` | `(spec: LauncherSpec) => LauncherState` | Validates `spec` and initializes full magazine |
57
+ | `stepLauncher` | `(state: LauncherState, input: LauncherInput, dt: number) => LaunchEvent \| null` | Advances cooldown, reload, fractional cooldown carry, and smooth C1 `cyclePhase` |
58
+ | `attachModule` | `(spec: LauncherSpec, attachment: AttachmentSpec) => LauncherSpec` | Returns new spec with rail attachment |
59
+ | `detachModule` | `(spec: LauncherSpec, rail: RailSocketName) => LauncherSpec` | Returns new spec without attachment on `rail` |
60
+
61
+ ## Multi-Body Inertia & KHR Planner (`inertia`, `launcherParts`, `launcherKhr`)
62
+
63
+ - `boxInertiaDiagonal(massKg, size) => Vec3`
64
+ - `buildLauncherParts(recipe) => LauncherPart[]`
65
+ - `resolveLauncherSockets(recipe) => ResolvedLauncherSockets`
66
+ - `diagonalizeInertiaTensor(t00, t11, t22, t01, t02, t12) => { inertiaDiagonal, inertiaOrientation }`
67
+ - `sumLauncherBoxes(parts) => LumpedInertiaProps`
68
+ - `planLauncher(recipe, friction = 0.5) => LauncherPlan`: emits `Receiver_Root` (lumped fixed parts + rail attachment masses), articulated `Bolt` (prismatic), `Trigger` (revolute), optional `Pump` (prismatic), and `Socket_*` locator nodes.
69
+
70
+ ## Authored Recipes (`recipes`)
71
+
72
+ `KOLMOGOROV_PISTOL` (`PISTOL_9MM`), `KOLMOGOROV_CARBINE` (`CARBINE_556`), `KOLMOGOROV_SHOTGUN` (`SHOTGUN_12G`), `LAUNCHER_RECIPES`, `findLauncherRecipe(id)` (accepts recipe `id` or `"pistol_9mm"` / `"carbine_556"` / `"shotgun_12g"`).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khr3/launchers",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Zero-dependency KHR launcher moving-part schema, rail attachment sockets, data-driven ammo catalog, and deterministic cycle state machine for khr3.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,6 +16,7 @@
16
16
  },
17
17
  "files": [
18
18
  "dist",
19
+ "docs",
19
20
  "LICENSE",
20
21
  "README.md"
21
22
  ],
@@ -40,6 +41,7 @@
40
41
  "typecheck": "tsc --noEmit",
41
42
  "build": "rm -rf dist && tsc && rm -f dist/*.test.*",
42
43
  "test": "rm -rf dist && tsc && node --test dist/launchers.test.js && rm -f dist/*.test.*",
44
+ "example": "tsx example/index.ts",
43
45
  "prepack": "npm run build",
44
46
  "pack:dry": "npm pack --dry-run"
45
47
  },