@khr3/launchers 0.2.9 → 0.3.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.
Files changed (107) hide show
  1. package/AGENTS.md +3 -3
  2. package/CLAUDE.md +1 -5
  3. package/LICENSE +1 -1
  4. package/README.md +39 -32
  5. package/dist/KhrLauncher.d.ts +46 -0
  6. package/dist/KhrLauncher.js +316 -0
  7. package/dist/KhrLauncher.js.map +1 -0
  8. package/dist/armory/engine/assemblyVerifier.d.ts +48 -0
  9. package/dist/armory/engine/assemblyVerifier.js +443 -0
  10. package/dist/armory/engine/assemblyVerifier.js.map +1 -0
  11. package/dist/armory/engine/audioSynth.d.ts +26 -0
  12. package/dist/armory/engine/audioSynth.js +256 -0
  13. package/dist/armory/engine/audioSynth.js.map +1 -0
  14. package/dist/armory/engine/ballistics.d.ts +125 -0
  15. package/dist/armory/engine/ballistics.js +399 -0
  16. package/dist/armory/engine/ballistics.js.map +1 -0
  17. package/dist/armory/engine/bvhExploder.d.ts +43 -0
  18. package/dist/armory/engine/bvhExploder.js +326 -0
  19. package/dist/armory/engine/bvhExploder.js.map +1 -0
  20. package/dist/armory/engine/dispose.d.ts +6 -0
  21. package/dist/armory/engine/dispose.js +54 -0
  22. package/dist/armory/engine/dispose.js.map +1 -0
  23. package/dist/armory/engine/glbPhysicsExporter.d.ts +116 -0
  24. package/dist/armory/engine/glbPhysicsExporter.js +1960 -0
  25. package/dist/armory/engine/glbPhysicsExporter.js.map +1 -0
  26. package/dist/armory/engine/jointGraph.d.ts +5 -0
  27. package/dist/armory/engine/jointGraph.js +50 -0
  28. package/dist/armory/engine/jointGraph.js.map +1 -0
  29. package/dist/armory/engine/materials.d.ts +87 -0
  30. package/dist/armory/engine/materials.js +1089 -0
  31. package/dist/armory/engine/materials.js.map +1 -0
  32. package/dist/armory/engine/meshSegmenter.d.ts +44 -0
  33. package/dist/armory/engine/meshSegmenter.js +527 -0
  34. package/dist/armory/engine/meshSegmenter.js.map +1 -0
  35. package/dist/armory/engine/orthoExtruder.d.ts +33 -0
  36. package/dist/armory/engine/orthoExtruder.js +549 -0
  37. package/dist/armory/engine/orthoExtruder.js.map +1 -0
  38. package/dist/armory/engine/parts/boltRifleBuilder.d.ts +16 -0
  39. package/dist/armory/engine/parts/boltRifleBuilder.js +233 -0
  40. package/dist/armory/engine/parts/boltRifleBuilder.js.map +1 -0
  41. package/dist/armory/engine/parts/cadKernel.d.ts +39 -0
  42. package/dist/armory/engine/parts/cadKernel.js +367 -0
  43. package/dist/armory/engine/parts/cadKernel.js.map +1 -0
  44. package/dist/armory/engine/parts/fireControlGroup.d.ts +29 -0
  45. package/dist/armory/engine/parts/fireControlGroup.js +428 -0
  46. package/dist/armory/engine/parts/fireControlGroup.js.map +1 -0
  47. package/dist/armory/engine/parts/magazineBuilder.d.ts +14 -0
  48. package/dist/armory/engine/parts/magazineBuilder.js +146 -0
  49. package/dist/armory/engine/parts/magazineBuilder.js.map +1 -0
  50. package/dist/armory/engine/parts/muzzleDevices.d.ts +8 -0
  51. package/dist/armory/engine/parts/muzzleDevices.js +72 -0
  52. package/dist/armory/engine/parts/muzzleDevices.js.map +1 -0
  53. package/dist/armory/engine/parts/picatinnyRail.d.ts +49 -0
  54. package/dist/armory/engine/parts/picatinnyRail.js +474 -0
  55. package/dist/armory/engine/parts/picatinnyRail.js.map +1 -0
  56. package/dist/armory/engine/parts/pistolVariants.d.ts +28 -0
  57. package/dist/armory/engine/parts/pistolVariants.js +318 -0
  58. package/dist/armory/engine/parts/pistolVariants.js.map +1 -0
  59. package/dist/armory/engine/parts/revolverBuilder.d.ts +49 -0
  60. package/dist/armory/engine/parts/revolverBuilder.js +475 -0
  61. package/dist/armory/engine/parts/revolverBuilder.js.map +1 -0
  62. package/dist/armory/engine/proceduralGeometry.d.ts +113 -0
  63. package/dist/armory/engine/proceduralGeometry.js +1591 -0
  64. package/dist/armory/engine/proceduralGeometry.js.map +1 -0
  65. package/dist/armory/engine/renderState.d.ts +2 -0
  66. package/dist/armory/engine/renderState.js +20 -0
  67. package/dist/armory/engine/renderState.js.map +1 -0
  68. package/dist/armory/engine/simSolver.d.ts +127 -0
  69. package/dist/armory/engine/simSolver.js +736 -0
  70. package/dist/armory/engine/simSolver.js.map +1 -0
  71. package/dist/armory/engine/weaponSpecs.d.ts +277 -0
  72. package/dist/armory/engine/weaponSpecs.js +1311 -0
  73. package/dist/armory/engine/weaponSpecs.js.map +1 -0
  74. package/dist/armory/engine/webglContext.d.ts +1 -0
  75. package/dist/armory/engine/webglContext.js +14 -0
  76. package/dist/armory/engine/webglContext.js.map +1 -0
  77. package/dist/armory/types/physicsSchema.d.ts +205 -0
  78. package/dist/armory/types/physicsSchema.js +2 -0
  79. package/dist/armory/types/physicsSchema.js.map +1 -0
  80. package/dist/index.d.ts +7 -0
  81. package/dist/index.js +8 -0
  82. package/dist/index.js.map +1 -1
  83. package/dist/inertia.d.ts +3 -9
  84. package/dist/inertia.js +6 -6
  85. package/dist/inertia.js.map +1 -1
  86. package/dist/launcherKhr.d.ts +3 -9
  87. package/dist/launcherKhr.js +3 -15
  88. package/dist/launcherKhr.js.map +1 -1
  89. package/dist/launcherParts.d.ts +3 -8
  90. package/dist/launcherParts.js +19 -39
  91. package/dist/launcherParts.js.map +1 -1
  92. package/dist/react.d.ts +3 -0
  93. package/dist/react.js +4 -0
  94. package/dist/react.js.map +1 -0
  95. package/dist/recipes.d.ts +18 -12
  96. package/dist/recipes.js +103 -2
  97. package/dist/recipes.js.map +1 -1
  98. package/dist/runtime.js +3 -2
  99. package/dist/runtime.js.map +1 -1
  100. package/dist/schema.d.ts +2 -1
  101. package/dist/schema.js +18 -0
  102. package/dist/schema.js.map +1 -1
  103. package/dist/three.d.ts +54 -0
  104. package/dist/three.js +58 -0
  105. package/dist/three.js.map +1 -0
  106. package/docs/api-reference.md +49 -299
  107. package/package.json +63 -8
@@ -0,0 +1 @@
1
+ {"version":3,"file":"three.js","sourceRoot":"","sources":["../src/three.ts"],"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AAC,CAAC,CAAC;IACjD,OAAO;QACL,WAAW;QACX,SAAS,EAAE,iBAAiB,CAAC,WAAW,CAAC;QACzC,OAAO;QACP,WAAW;QACX,MAAM;QACN,UAAU;QACV,MAAM;KACP,CAAC;AACJ,CAAC"}
@@ -1,25 +1,26 @@
1
1
  # `@khr3/launchers` API and Configuration Guide
2
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.
3
+ `@khr3/launchers` unifies the zero-dependency KHR launcher planner and 240Hz mechanism/ballistics solver (`@khr3/launchers`) with the procedural 3D armory `.glb` generator (`@khr3/launchers/three`) and React Three Fiber `<KhrLauncher>` rig (`@khr3/launchers/react`).
4
4
 
5
- ## Import Path
5
+ ---
6
+
7
+ ## Import Paths
6
8
 
7
9
  ```ts
10
+ // 1. Zero-dependency pure TypeScript planner, recipes, ballistics & 240Hz mechanism solver
8
11
  import {
9
12
  LAUNCHER_PART_ROLES,
10
13
  LAUNCHER_SOCKETS,
11
14
  RAIL_SOCKETS,
12
15
  CHARACTER_SOCKETS,
13
16
  DEFAULT_AMMO_CATALOG,
14
- KOLMOGOROV_PISTOL,
15
- KOLMOGOROV_SMG,
16
- KOLMOGOROV_CARBINE,
17
- KOLMOGOROV_SHOTGUN,
18
- KOLMOGOROV_RPG,
19
17
  PISTOL_9MM,
18
+ REVOLVER_44,
20
19
  SMG_9MM,
21
20
  CARBINE_556,
21
+ BOLT_RIFLE_762,
22
22
  SHOTGUN_12G,
23
+ ROTARY_GL_40MM,
23
24
  RPG_LAUNCHER,
24
25
  LAUNCHER_RECIPES,
25
26
  findLauncherRecipe,
@@ -28,306 +29,55 @@ import {
28
29
  stepLauncher,
29
30
  attachModule,
30
31
  detachModule,
31
- boxInertiaDiagonal,
32
- buildLauncherParts,
33
- fallbackRailSocket,
34
- resolveLauncherSockets,
32
+ planLauncher,
35
33
  diagonalizeInertiaTensor,
36
34
  sumLauncherBoxes,
37
- planLauncher,
38
- type LauncherPartRole,
39
- type LauncherSocketName,
40
- type RailSocketName,
41
- type CharacterSocketName,
42
- type Vec3Tuple,
43
- type Vec3,
44
- type Quat,
45
- type AmmoSpec,
46
- type AttachmentSpec,
47
- type LauncherSpec,
48
- type LauncherInput,
49
- type LaunchEvent,
50
- type LauncherState,
51
- type LauncherJointSpec,
52
- type LauncherPart,
53
- type LauncherDims,
54
- type LauncherMasses,
55
- type LauncherRecipe,
56
- type ResolvedLauncherSockets,
57
- type MassBoxLike,
58
- type LumpedInertiaProps,
59
- type LauncherNode,
60
- type KhrLauncherNodeSpecLike,
61
- type LauncherPlan,
35
+ WEAPON_ARCHETYPES,
36
+ WEAPON_CATALOG,
37
+ DEFAULT_LOADOUT,
38
+ DEFAULT_TUNING,
39
+ createInitialSimState,
40
+ triggerSimFire,
41
+ triggerSimRack,
42
+ triggerSimReload,
43
+ advanceFixedSimulation,
44
+ computeWeaponBarrelBallistics,
45
+ sweepProjectileStep,
46
+ audioSynth,
62
47
  } from "@khr3/launchers";
63
- ```
64
-
65
- ## Schema & Ammo (`schema`)
66
-
67
- - `LAUNCHER_PART_ROLES`: `"receiver" | "bolt" | "pump" | "trigger" | "magazine" | "barrel" | "stock" | "screen_rect"`
68
- - `LAUNCHER_SOCKETS`: `"grip_primary" | "grip_secondary" | "rail_top" | "rail_under" | "muzzle" | "eject_port" | "sight_align"`
69
- - `RAIL_SOCKETS`: `"rail_top" | "rail_under" | "muzzle"`
70
- - `CHARACTER_SOCKETS`: `"Socket_Hand_R" | "Socket_Hand_L" | "Socket_Head" | "Socket_Back"`
71
-
72
- ```ts
73
- export type Vec3Tuple = readonly [number, number, number];
74
-
75
- export interface AmmoSpec {
76
- readonly id: string;
77
- readonly muzzleSpeedMs: number;
78
- readonly massKg: number;
79
- readonly casingRadiusM: number;
80
- readonly casingLengthM: number;
81
- readonly tipRatio: number;
82
- readonly color: string;
83
- }
84
-
85
- export interface AttachmentSpec {
86
- readonly id: string;
87
- readonly rail: RailSocketName;
88
- readonly massKg: number;
89
- readonly glbKey?: string;
90
- }
91
-
92
- export interface LauncherSpec {
93
- readonly id: string;
94
- readonly ammoId: string;
95
- readonly fireRateHz: number;
96
- readonly magazineCapacity: number;
97
- readonly reloadSec: number;
98
- readonly recoilImpulseNs: number;
99
- readonly sockets: Partial<Record<LauncherSocketName, Vec3Tuple>>;
100
- readonly attachments?: Partial<Record<RailSocketName, AttachmentSpec>>;
101
- }
102
- ```
103
-
104
- ### `DEFAULT_AMMO_CATALOG`
105
-
106
- | ID | `muzzleSpeedMs` | `massKg` | `casingRadiusM` | `casingLengthM` | `tipRatio` | `color` |
107
- | --- | --- | --- | --- | --- | --- | --- |
108
- | `pistol` | `360` | `0.008` | `0.0049` | `0.019` | `0.35` | `#E3A83B` |
109
- | `rifle` | `880` | `0.004` | `0.0048` | `0.045` | `0.45` | `#D68A28` |
110
- | `shells_12g` | `400` | `0.032` | `0.01` | `0.07` | `0` | `#C83228` |
111
- | `laser` | `1200` | `0.0001` | `0` | `0` | `0` | `#26E3E8` |
112
- | `orb` | `42` | `0.12` | `0` | `0` | `0` | `#E3782A` |
113
- | `rocket` | `95` | `1.4` | `0.035` | `0.32` | `0.3` | `#D93832` |
114
-
115
- `validateLauncherSpec(spec)` throws `Error` / `RangeError` if `id`/`ammoId` is missing, `fireRateHz <= 0`, `magazineCapacity < 1` or non-integer, `reloadSec < 0`, `recoilImpulseNs < 0`, `grip_primary` / `muzzle` sockets are missing/non-finite, any defined socket is non-finite, or any attachment has a missing/empty `id` or `massKg < 0` / non-finite.
116
-
117
- ## Runtime State Machine (`runtime`)
118
-
119
- ```ts
120
- export interface LauncherInput {
121
- trigger: boolean;
122
- reload?: boolean;
123
- }
124
-
125
- export interface LaunchEvent {
126
- readonly launcherId: string;
127
- readonly ammoId: string;
128
- readonly muzzleLocal: Vec3Tuple;
129
- readonly ejectLocal: Vec3Tuple | null;
130
- readonly recoilImpulseNs: number;
131
- }
132
-
133
- export interface LauncherState {
134
- readonly spec: LauncherSpec;
135
- ammoInMag: number;
136
- cooldownSec: number;
137
- reloadRemainingSec: number;
138
- /** 0 = closed/resting, 1 = full rearward bolt/pump stroke */
139
- cyclePhase: number;
140
- totalFired: number;
141
- }
142
- ```
143
-
144
- | Function | Signature | Description |
145
- | --- | --- | --- |
146
- | `createLauncherState` | `(spec: LauncherSpec) => LauncherState` | Validates `spec` and initializes full magazine (`ammoInMag = spec.magazineCapacity`) |
147
- | `stepLauncher` | `(state: LauncherState, input: LauncherInput, dt: number) => LaunchEvent \| null` | Advances cooldown, reload, fractional cooldown carry, and smooth C1 `cyclePhase` in `[0, 1]`; returns `null` for non-positive/non-finite `dt` |
148
- | `attachModule` | `(spec: LauncherSpec, attachment: AttachmentSpec) => LauncherSpec` | Returns new spec with rail attachment (validates `id` and finite `massKg >= 0`) |
149
- | `detachModule` | `(spec: LauncherSpec, rail: RailSocketName) => LauncherSpec` | Returns new spec without attachment on `rail` |
150
-
151
- ## Parametric Parts, Inertia & KHR Planner (`launcherParts`, `inertia`, `launcherKhr`)
152
-
153
- ```ts
154
- export type Vec3 = [number, number, number];
155
- export type Quat = [number, number, number, number]; // [qx, qy, qz, qw]
156
48
 
157
- export interface LauncherJointSpec {
158
- readonly kind: "prismatic" | "revolute";
159
- readonly anchor: Vec3;
160
- readonly axis: Vec3;
161
- readonly limits: [number, number]; // metres for prismatic, radians for revolute
162
- readonly stiffness: number;
163
- readonly damping: number;
164
- }
165
-
166
- export interface LauncherPart {
167
- readonly name: string;
168
- readonly role: LauncherPartRole;
169
- readonly massKg: number;
170
- readonly center: Vec3;
171
- readonly size: Vec3;
172
- readonly joint?: LauncherJointSpec;
173
- }
174
-
175
- export interface LauncherDims {
176
- readonly receiverLength: number;
177
- readonly receiverWidth: number;
178
- readonly receiverHeight: number;
179
- readonly barrelLength: number;
180
- readonly barrelDiameter: number;
181
- readonly gripHeight: number;
182
- readonly magLength: number;
183
- readonly boltStroke: number;
184
- readonly hasStock: boolean;
185
- readonly hasPump: boolean;
186
- readonly hasScreen?: boolean;
187
- }
188
-
189
- export interface LauncherMasses {
190
- readonly receiver: number;
191
- readonly barrel: number;
192
- readonly bolt: number;
193
- readonly trigger: number;
194
- readonly magazine: number;
195
- readonly stock: number;
196
- readonly pump: number;
197
- readonly screen?: number; // defaults to 0.03 kg when dims.hasScreen is true
198
- }
199
-
200
- export interface LauncherRecipe {
201
- readonly id: string;
202
- readonly label: string;
203
- /** Optional external R2 asset metadata; decoupled from offline procedural `planLauncher()` synthesis. */
204
- readonly r2Key?: string;
205
- readonly spec: LauncherSpec;
206
- readonly dims: LauncherDims;
207
- readonly masses: LauncherMasses;
208
- }
209
-
210
- export type ResolvedLauncherSockets = Partial<Record<LauncherSocketName, Vec3Tuple>> & {
211
- readonly grip_primary: Vec3Tuple;
212
- readonly muzzle: Vec3Tuple;
213
- };
214
-
215
- export interface MassBoxLike {
216
- readonly massKg: number;
217
- readonly center: Vec3;
218
- readonly size: Vec3;
219
- }
220
-
221
- export interface LumpedInertiaProps {
222
- readonly massKg: number;
223
- readonly centerOfMass: Vec3;
224
- readonly inertiaDiagonal: Vec3;
225
- readonly inertiaOrientation: Quat;
226
- readonly inertiaTensor: readonly [Vec3, Vec3, Vec3];
227
- }
228
-
229
- export interface LauncherNode {
230
- readonly name: string;
231
- readonly parent: string;
232
- readonly position: Vec3;
233
- readonly size: Vec3;
234
- }
235
-
236
- export interface KhrLauncherNodeSpecLike {
237
- readonly nodeName: string;
238
- readonly motion?: {
239
- readonly isKinematic?: boolean;
240
- readonly mass?: number;
241
- readonly centerOfMass?: Vec3;
242
- readonly inertiaDiagonal?: Vec3;
243
- readonly inertiaOrientation?: Quat;
244
- };
245
- readonly collider?: {
246
- readonly shape: { readonly type: "box"; readonly size: Vec3 };
247
- readonly friction?: number;
248
- };
249
- readonly joint?: {
250
- readonly connectedNodeName: string;
251
- readonly kind: "revolute" | "prismatic";
252
- readonly axis: Vec3;
253
- readonly limits: [number, number];
254
- readonly drive: {
255
- readonly mode: "acceleration";
256
- readonly stiffness: number;
257
- readonly damping: number;
258
- readonly positionTarget: number;
259
- };
260
- };
261
- readonly extras?: Record<string, unknown>;
262
- }
263
-
264
- export interface LauncherPlan {
265
- readonly recipeId: string;
266
- readonly spec: LauncherSpec;
267
- readonly parts: LauncherPart[];
268
- readonly totalMassKg: number;
269
- readonly fixedMassKg: number;
270
- readonly centerOfMass: Vec3;
271
- readonly inertiaDiagonal: Vec3;
272
- readonly inertiaOrientation: Quat;
273
- readonly sockets: ResolvedLauncherSockets;
274
- readonly nodes: LauncherNode[];
275
- readonly specs: KhrLauncherNodeSpecLike[];
276
- }
49
+ // 2. Three.js procedural 3D armory rigs, multi-LOD ammo & @khr3/core KhrAssetBundle synthesis
50
+ import {
51
+ buildArmoryWeaponRig,
52
+ loadArmoryLauncherBundle,
53
+ buildWeaponKhrGlbBuffer,
54
+ buildAmmoLodChain,
55
+ buildAmmoLodsGlbBuffer,
56
+ createArmoryMaterials,
57
+ buildTaggedExternalKhrGlbBuffer,
58
+ captureWeaponSideBlueprint,
59
+ } from "@khr3/launchers/three";
60
+
61
+ // 3. React Three Fiber <KhrLauncher> HeldItem rig (priority-0 useFrame, zero impulse joints)
62
+ import {
63
+ KhrLauncher,
64
+ type KhrLauncherHandle,
65
+ type KhrLauncherProps,
66
+ type KhrLauncherShotInfo,
67
+ } from "@khr3/launchers/react";
277
68
  ```
278
69
 
279
- ### Functions & Planner Defaults
70
+ ---
280
71
 
281
- - `boxInertiaDiagonal(massKg: number, size: Vec3) => Vec3`
282
- - `buildLauncherParts(recipe: LauncherRecipe) => LauncherPart[]`
283
- - `fallbackRailSocket(d: LauncherDims, rail: RailSocketName) => Vec3`
284
- - `resolveLauncherSockets(recipe: LauncherRecipe) => ResolvedLauncherSockets`
285
- - `diagonalizeInertiaTensor(t00, t11, t22, t01, t02, t12) => { inertiaDiagonal, inertiaOrientation }`
286
- - `sumLauncherBoxes(parts: readonly MassBoxLike[]) => LumpedInertiaProps`
287
- - `planLauncher(recipe: LauncherRecipe, friction = 0.5) => LauncherPlan` (throws `RangeError` if `friction` is negative or non-finite):
288
- - Lumps fixed parts + rail attachment masses (`rail_top`, `rail_under`, `muzzle`, using fallback rail positions when unsocketed) into `Receiver_Root` (`extras`: `{ role: "receiver", launcherId, ammoId, fireRateHz, magazineCapacity }`).
289
- - Emits `Screen_Rect` (`role: "screen_rect"`, default mass `0.03` kg unless `masses.screen` is specified) when `dims.hasScreen` is `true` and mass `> 0`.
290
- - Emits articulated moving parts with `<Part>_Collider` child nodes and spring-driven `KHR_physics_rigid_bodies` joints (`drive.mode = "acceleration"`, `drive.positionTarget = 0`):
291
- - `Bolt`: prismatic along `[0, 0, 1]`, limits `[-boltStroke, 0]`, `omega = max(90, 7.5 * fireRateHz)`, `stiffness = omega^2`, `damping = 2 * omega`.
292
- - `Trigger`: revolute about `[1, 0, 0]`, limits `[0, 0.45]`, `stiffness = 80`, `damping = 18`.
293
- - `Pump` (when `dims.hasPump` and `masses.pump > 0`): prismatic along `[0, 0, 1]`, limits `[-0.095, 0]`, `stiffness = 900`, `damping = 60`.
294
- - Emits `Socket_<socketName>` locator nodes with `extras: { socketId, isIkAnchor }` (`isIkAnchor: true` for `grip_*` sockets, `false` otherwise).
72
+ ## Coordinate Conventions
295
73
 
296
- ## Authored Recipes (`recipes`)
74
+ - **Actor / glTF Space (`forwardAxis: "+Z"`)**: `+Y` up, `+Z` muzzle forward, `-X` shooter right, `+X` shooter left, `[1, 1, 1]` SI metres. Use `"+Z"` when parenting onto a 3rd-person VRM/glTF character hand bone (`rightHand` / `Socket_Hand_R`).
75
+ - **Camera View-Model Space (`forwardAxis: "-Z"`, default for `<KhrLauncher>`)**: `+Y` up, `-Z` muzzle forward, `+X` right. Use `"-Z"` when mounting onto `<KhrBody>` `KhrBody_ViewModel` sockets (`Socket_Hand_R`), which track Three.js `camera.position` and `camera.quaternion`.
297
76
 
298
- | Export | Alias | `id` | `r2Key` | `ammoId` | `fireRateHz` | `magazineCapacity` | `reloadSec` | `recoilImpulseNs` | `hasStock` | `hasPump` |
299
- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
300
- | `KOLMOGOROV_PISTOL` | `PISTOL_9MM` | `kolmogorov_pistol` | `weapons/kolmogorov_pistol.glb` | `pistol` | `6.5` | `15` | `1.4` | `3.4` | `false` | `false` |
301
- | `KOLMOGOROV_SMG` | `SMG_9MM` | `kolmogorov_smg` | `weapons/kolmogorov_smg.glb` | `pistol` | `14.0` | `32` | `1.7` | `3.1` | `true` | `false` |
302
- | `KOLMOGOROV_CARBINE` | `CARBINE_556` | `kolmogorov_carbine` | — (procedural via `planLauncher`; no R2 `.glb`) | `rifle` | `11.5` | `30` | `1.9` | `4.8` | `true` | `false` |
303
- | `KOLMOGOROV_SHOTGUN` | `SHOTGUN_12G` | `kolmogorov_shotgun` | `weapons/kolmogorov_shotgun.glb` | `shells_12g` | `1.4` | `8` | `2.6` | `14.5` | `true` | `true` |
304
- | `KOLMOGOROV_RPG` | `RPG_LAUNCHER` | `kolmogorov_rpg` | `weapons/kolmogorov_rpg.glb` | `rocket` | `0.5` | `1` | `3.2` | `28.0` | `true` | `false` |
77
+ ---
305
78
 
306
- - `LAUNCHER_RECIPES`: frozen array `[KOLMOGOROV_PISTOL, KOLMOGOROV_SMG, KOLMOGOROV_CARBINE, KOLMOGOROV_SHOTGUN, KOLMOGOROV_RPG]`.
307
- - `findLauncherRecipe(id: string) => LauncherRecipe`: accepts canonical `id` or `"pistol"` / `"pistol_9mm"` / `"smg"` / `"smg_9mm"` / `"carbine"` / `"carbine_556"` / `"shotgun"` / `"shotgun_12g"` / `"rpg"` / `"rpg_launcher"`; throws `RangeError` if unknown.
79
+ ## `<KhrLauncher>` Frame & Physics Contract (`@khr3/launchers/react`)
308
80
 
309
- ## Minimal Runtime & Planner Usage
310
-
311
- ```ts
312
- import {
313
- DEFAULT_AMMO_CATALOG,
314
- KOLMOGOROV_CARBINE,
315
- attachModule,
316
- createLauncherState,
317
- planLauncher,
318
- stepLauncher,
319
- } from "@khr3/launchers";
320
-
321
- const equipped = {
322
- ...KOLMOGOROV_CARBINE,
323
- spec: attachModule(KOLMOGOROV_CARBINE.spec, { id: "optic_1x", rail: "rail_top", massKg: 0.14 }),
324
- };
325
-
326
- const plan = planLauncher(equipped);
327
- const state = createLauncherState(equipped.spec);
328
- const ev = stepLauncher(state, { trigger: true, reload: false }, 1 / 60);
329
- if (ev) {
330
- const ammo = DEFAULT_AMMO_CATALOG[ev.ammoId];
331
- console.log(plan.recipeId, ev.launcherId, ammo.muzzleSpeedMs, ev.recoilImpulseNs);
332
- }
333
- ```
81
+ 1. Mount inside `@khr3/core` `<PhysicsWorld>` alongside `@khr3/body/react` `<KhrBody ref={bodyRef} />`.
82
+ 2. Runs strictly at default `useFrame` priority `0` with zero `useBeforePhysicsStep` calls, zero Rapier impulse joints, and zero per-frame heap allocations (`resetSimEvents` reuses pre-allocated scratch state).
83
+ 3. Drives `<HeldItem>` articulated KHR joints (`slide_blowback`, `pump_action`, `trigger`, `trigger_bar`, `sear`, `chamber_breech`, `hammer`, `magazine_well`) via `JointRegistryContext` and aligns `Socket_AdsEye` with the camera optical axis when `ads` is active.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@khr3/launchers",
3
- "version": "0.2.9",
4
- "description": "Zero-dependency KHR launcher moving-part schema, rail attachment sockets, data-driven ammo catalog, and deterministic cycle state machine for khr3.",
3
+ "version": "0.3.1",
4
+ "description": "Zero-dependency KHR launcher planner, 240Hz mechanism & ballistics solver, procedural 3D armory .glb synthesis (@khr3/launchers/three), and R3F <KhrLauncher> HeldItem rig (@khr3/launchers/react).",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "sideEffects": false,
@@ -12,6 +12,14 @@
12
12
  "types": "./dist/index.d.ts",
13
13
  "import": "./dist/index.js"
14
14
  },
15
+ "./three": {
16
+ "types": "./dist/three.d.ts",
17
+ "import": "./dist/three.js"
18
+ },
19
+ "./react": {
20
+ "types": "./dist/react.d.ts",
21
+ "import": "./dist/react.js"
22
+ },
15
23
  "./package.json": "./package.json"
16
24
  },
17
25
  "files": [
@@ -25,31 +33,78 @@
25
33
  "keywords": [
26
34
  "khr3",
27
35
  "launchers",
36
+ "armory",
37
+ "khr_physics_rigid_bodies",
28
38
  "sockets",
29
39
  "gltf",
30
40
  "glb",
31
41
  "threejs",
32
42
  "r3f",
43
+ "ecctrl",
33
44
  "gamedev"
34
45
  ],
35
46
  "repository": {
36
47
  "type": "git",
37
48
  "url": "git+https://github.com/pinkAphant/khr3-launchers.git"
38
49
  },
50
+ "bugs": {
51
+ "url": "https://github.com/pinkAphant/khr3-launchers/issues"
52
+ },
39
53
  "publishConfig": {
40
54
  "access": "public"
41
55
  },
42
56
  "scripts": {
43
- "typecheck": "tsc --noEmit && tsc --noEmit --target ES2022 --module NodeNext --moduleResolution NodeNext --lib ES2022 --strict --skipLibCheck example/index.ts",
44
- "build": "rm -rf dist && tsc && rm -f dist/*.test.*",
45
- "test": "rm -rf dist && tsc && node --test dist/*.test.js && rm -f dist/*.test.*",
57
+ "typecheck": "tsc -p tsconfig.build.json --noEmit && tsc --noEmit",
58
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && rm -f dist/*.test.*",
46
59
  "example": "tsx example/index.ts",
47
60
  "prepack": "npm run build",
48
61
  "pack:dry": "npm pack --dry-run"
49
62
  },
63
+ "peerDependencies": {
64
+ "@khr3/body": ">=0.2.0",
65
+ "@khr3/core": ">=0.2.20",
66
+ "@react-three/fiber": ">=9.4.0",
67
+ "@react-three/rapier": ">=2.2.0",
68
+ "react": ">=19.0.0",
69
+ "three": ">=0.184.0"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "@khr3/body": {
73
+ "optional": true
74
+ },
75
+ "@khr3/core": {
76
+ "optional": true
77
+ },
78
+ "@react-three/fiber": {
79
+ "optional": true
80
+ },
81
+ "@react-three/rapier": {
82
+ "optional": true
83
+ },
84
+ "react": {
85
+ "optional": true
86
+ },
87
+ "three": {
88
+ "optional": true
89
+ }
90
+ },
50
91
  "devDependencies": {
51
- "@types/node": "^22.0.0",
52
- "tsx": "^4.21.0",
53
- "typescript": "^5.8.0"
92
+ "@dimforge/rapier3d-compat": "^0.19.2",
93
+ "@khr3/body": "^0.2.0",
94
+ "@khr3/core": "^0.2.22",
95
+ "@pinkaphant/ecctrl": "2.0.4-beta.13",
96
+ "@react-three/drei": "^10.7.7",
97
+ "@react-three/fiber": "^9.6.1",
98
+ "@react-three/rapier": "^2.2.0",
99
+ "@react-three/test-renderer": "^9.1.1",
100
+ "@types/node": "^22.20.5",
101
+ "@types/react": "^19.2.16",
102
+ "@types/react-dom": "^19.2.3",
103
+ "@types/three": "^0.184.0",
104
+ "react": "^19.2.7",
105
+ "react-dom": "^19.2.7",
106
+ "three": "^0.184.0",
107
+ "tsx": "^4.23.15",
108
+ "typescript": "^5.8.3"
54
109
  }
55
110
  }