@khr3/launchers 0.1.0 → 0.2.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/README.md +39 -16
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/launcherKhr.d.ts +56 -0
- package/dist/launcherKhr.js +119 -0
- package/dist/launcherParts.d.ts +58 -0
- package/dist/launcherParts.js +119 -0
- package/dist/recipes.d.ts +6 -0
- package/dist/recipes.js +138 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@khr3/launchers`
|
|
2
2
|
|
|
3
|
-
Zero-dependency KHR launcher moving-part
|
|
3
|
+
Zero-dependency KHR firearm & launcher moving-part planner (`receiver`, `bolt`, `pump`, `trigger`, `magazine`, `barrel`, `stock`, `screen_rect`), rail/character mount sockets, data-driven ammo catalog, and deterministic 60Hz cycle state machine for `@khr3/core` and `Kolmo`.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- **Zero dependencies & zero `koota`**: Pure TypeScript ESM with `.d.ts` declarations.
|
|
6
|
+
- **Articulated KHR output**: `planLauncher(recipe)` lumps fixed parts into `Receiver_Root` (with exact parallel-axis mass & box inertia) and emits prismatic/revolute `KHR_physics_rigid_bodies` joints + spring drives for `Bolt`, `Trigger`, and `Pump`, ready for `@khr3/core` `exportKhrGlb`.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @khr3/launchers
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Main Exports
|
|
15
|
+
|
|
16
|
+
| Area | Exports |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| **Schema & Ammo** | `LAUNCHER_PART_ROLES`, `LAUNCHER_SOCKETS`, `RAIL_SOCKETS`, `CHARACTER_SOCKETS`, `DEFAULT_AMMO_CATALOG`, `validateLauncherSpec` |
|
|
19
|
+
| **Recipes & Multi-Body Planner** | `KOLMOGOROV_PISTOL`, `KOLMOGOROV_CARBINE`, `KOLMOGOROV_SHOTGUN`, `LAUNCHER_RECIPES`, `findLauncherRecipe`, `buildLauncherParts`, `resolveLauncherSockets`, `planLauncher` |
|
|
20
|
+
| **Deterministic Runtime** | `createLauncherState`, `stepLauncher`, `attachModule`, `detachModule` (fire cadence, bolt/pump cycling, magazine depletion, timed reload, recoil impulse, rail attachments) |
|
|
21
|
+
|
|
22
|
+
## 1. Plan an Articulated KHR3 Launcher `.glb`
|
|
6
23
|
|
|
7
24
|
```ts
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
import { KOLMOGOROV_CARBINE, planLauncher } from "@khr3/launchers";
|
|
26
|
+
|
|
27
|
+
const plan = planLauncher(KOLMOGOROV_CARBINE);
|
|
28
|
+
// plan.nodes -> scene hierarchy (Receiver_Root + articulated Bolt/Trigger + Socket_* nodes)
|
|
29
|
+
// plan.specs -> KhrExportNodeSpec-compatible rigid bodies, colliders, and prismatic/revolute joints
|
|
30
|
+
// plan.sceneExtras -> { launcher: plan.spec } for `@khr3/core` exportKhrGlb(root, plan.specs, plan.sceneExtras)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 2. Step the Deterministic Firing & Reload Cycle
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { KOLMOGOROV_PISTOL, createLauncherState, stepLauncher } from "@khr3/launchers";
|
|
37
|
+
|
|
38
|
+
const state = createLauncherState(KOLMOGOROV_PISTOL.spec);
|
|
39
|
+
const step = stepLauncher(state, { trigger: true, reload: false }, 1 / 60);
|
|
40
|
+
|
|
41
|
+
if (step.fired) {
|
|
42
|
+
// Spawn round from `muzzle` socket with `step.ammo.muzzleSpeedMs` and apply `step.recoilImpulseNs`
|
|
43
|
+
}
|
|
21
44
|
```
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn a parametric launcher recipe into the scene node tree and `KhrExportNodeSpecLike[]`
|
|
3
|
+
* consumed by `@khr3/core` `exportKhrGlb`.
|
|
4
|
+
* Fixed parts lump into `Receiver_Root`; articulated parts (`Bolt`, `Trigger`, `Pump`) emit
|
|
5
|
+
* `KHR_physics_rigid_bodies` prismatic/revolute joints with spring drives.
|
|
6
|
+
*/
|
|
7
|
+
import { type LauncherPart, type LauncherRecipe, type Vec3 } from "./launcherParts.js";
|
|
8
|
+
import type { LauncherSocketName, LauncherSpec, Vec3Tuple } from "./schema.js";
|
|
9
|
+
export interface LauncherNode {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly parent: string;
|
|
12
|
+
readonly position: Vec3;
|
|
13
|
+
readonly size: Vec3;
|
|
14
|
+
}
|
|
15
|
+
export interface KhrLauncherNodeSpecLike {
|
|
16
|
+
readonly nodeName: string;
|
|
17
|
+
readonly motion?: {
|
|
18
|
+
readonly isKinematic?: boolean;
|
|
19
|
+
readonly mass?: number;
|
|
20
|
+
readonly centerOfMass?: Vec3;
|
|
21
|
+
readonly inertiaDiagonal?: Vec3;
|
|
22
|
+
};
|
|
23
|
+
readonly collider?: {
|
|
24
|
+
readonly shape: {
|
|
25
|
+
readonly type: "box";
|
|
26
|
+
readonly size: Vec3;
|
|
27
|
+
};
|
|
28
|
+
readonly friction?: number;
|
|
29
|
+
};
|
|
30
|
+
readonly joint?: {
|
|
31
|
+
readonly connectedNodeName: string;
|
|
32
|
+
readonly kind: "revolute" | "prismatic";
|
|
33
|
+
readonly axis: Vec3;
|
|
34
|
+
readonly limits: [number, number];
|
|
35
|
+
readonly drive: {
|
|
36
|
+
readonly mode: "acceleration";
|
|
37
|
+
readonly stiffness: number;
|
|
38
|
+
readonly damping: number;
|
|
39
|
+
readonly positionTarget: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
readonly extras?: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
export interface LauncherPlan {
|
|
45
|
+
readonly recipeId: string;
|
|
46
|
+
readonly spec: LauncherSpec;
|
|
47
|
+
readonly parts: LauncherPart[];
|
|
48
|
+
readonly totalMassKg: number;
|
|
49
|
+
readonly fixedMassKg: number;
|
|
50
|
+
readonly centerOfMass: Vec3;
|
|
51
|
+
readonly inertiaDiagonal: Vec3;
|
|
52
|
+
readonly sockets: Record<LauncherSocketName, Vec3Tuple>;
|
|
53
|
+
readonly nodes: LauncherNode[];
|
|
54
|
+
readonly specs: KhrLauncherNodeSpecLike[];
|
|
55
|
+
}
|
|
56
|
+
export declare function planLauncher(recipe: LauncherRecipe, friction?: number): LauncherPlan;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn a parametric launcher recipe into the scene node tree and `KhrExportNodeSpecLike[]`
|
|
3
|
+
* consumed by `@khr3/core` `exportKhrGlb`.
|
|
4
|
+
* Fixed parts lump into `Receiver_Root`; articulated parts (`Bolt`, `Trigger`, `Pump`) emit
|
|
5
|
+
* `KHR_physics_rigid_bodies` prismatic/revolute joints with spring drives.
|
|
6
|
+
*/
|
|
7
|
+
import { boxInertiaDiagonal, buildLauncherParts, resolveLauncherSockets, } from "./launcherParts.js";
|
|
8
|
+
function sumLauncherBoxes(parts) {
|
|
9
|
+
let m = 0;
|
|
10
|
+
const c = [0, 0, 0];
|
|
11
|
+
for (const p of parts) {
|
|
12
|
+
m += p.massKg;
|
|
13
|
+
c[0] += p.massKg * p.center[0];
|
|
14
|
+
c[1] += p.massKg * p.center[1];
|
|
15
|
+
c[2] += p.massKg * p.center[2];
|
|
16
|
+
}
|
|
17
|
+
c[0] /= m;
|
|
18
|
+
c[1] /= m;
|
|
19
|
+
c[2] /= m;
|
|
20
|
+
const diag = [0, 0, 0];
|
|
21
|
+
for (const p of parts) {
|
|
22
|
+
const own = boxInertiaDiagonal(p.massKg, p.size);
|
|
23
|
+
const dx = p.center[0] - c[0], dy = p.center[1] - c[1], dz = p.center[2] - c[2];
|
|
24
|
+
diag[0] += own[0] + p.massKg * (dy * dy + dz * dz);
|
|
25
|
+
diag[1] += own[1] + p.massKg * (dx * dx + dz * dz);
|
|
26
|
+
diag[2] += own[2] + p.massKg * (dx * dx + dy * dy);
|
|
27
|
+
}
|
|
28
|
+
return { massKg: m, centerOfMass: c, inertiaDiagonal: diag };
|
|
29
|
+
}
|
|
30
|
+
export function planLauncher(recipe, friction = 0.5) {
|
|
31
|
+
const parts = buildLauncherParts(recipe);
|
|
32
|
+
const fixed = parts.filter((p) => !p.joint);
|
|
33
|
+
const moving = parts.filter((p) => p.joint);
|
|
34
|
+
const total = sumLauncherBoxes(parts);
|
|
35
|
+
const rootProps = sumLauncherBoxes(fixed);
|
|
36
|
+
const sockets = resolveLauncherSockets(recipe);
|
|
37
|
+
const nodes = [
|
|
38
|
+
{ name: "Receiver_Root", parent: "root", position: [0, 0, 0], size: [0, 0, 0] },
|
|
39
|
+
];
|
|
40
|
+
const specs = [
|
|
41
|
+
{
|
|
42
|
+
nodeName: "Receiver_Root",
|
|
43
|
+
motion: {
|
|
44
|
+
isKinematic: false,
|
|
45
|
+
mass: rootProps.massKg,
|
|
46
|
+
centerOfMass: rootProps.centerOfMass,
|
|
47
|
+
inertiaDiagonal: rootProps.inertiaDiagonal,
|
|
48
|
+
},
|
|
49
|
+
extras: {
|
|
50
|
+
role: "receiver",
|
|
51
|
+
launcherId: recipe.id,
|
|
52
|
+
ammoId: recipe.spec.ammoId,
|
|
53
|
+
fireRateHz: recipe.spec.fireRateHz,
|
|
54
|
+
magazineCapacity: recipe.spec.magazineCapacity,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
for (const p of fixed) {
|
|
59
|
+
nodes.push({ name: p.name, parent: "Receiver_Root", position: p.center, size: p.size });
|
|
60
|
+
specs.push({
|
|
61
|
+
nodeName: p.name,
|
|
62
|
+
collider: { shape: { type: "box", size: p.size }, friction },
|
|
63
|
+
extras: { role: p.role },
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
for (const p of moving) {
|
|
67
|
+
const j = p.joint;
|
|
68
|
+
const localOffset = [p.center[0] - j.anchor[0], p.center[1] - j.anchor[1], p.center[2] - j.anchor[2]];
|
|
69
|
+
const ownDiag = boxInertiaDiagonal(p.massKg, p.size);
|
|
70
|
+
nodes.push({ name: p.name, parent: "Receiver_Root", position: j.anchor, size: [0, 0, 0] });
|
|
71
|
+
nodes.push({ name: `${p.name}_Collider`, parent: p.name, position: localOffset, size: p.size });
|
|
72
|
+
specs.push({
|
|
73
|
+
nodeName: `${p.name}_Collider`,
|
|
74
|
+
collider: { shape: { type: "box", size: p.size }, friction },
|
|
75
|
+
});
|
|
76
|
+
specs.push({
|
|
77
|
+
nodeName: p.name,
|
|
78
|
+
motion: {
|
|
79
|
+
isKinematic: false,
|
|
80
|
+
mass: p.massKg,
|
|
81
|
+
centerOfMass: localOffset,
|
|
82
|
+
inertiaDiagonal: ownDiag,
|
|
83
|
+
},
|
|
84
|
+
joint: {
|
|
85
|
+
connectedNodeName: "Receiver_Root",
|
|
86
|
+
kind: j.kind,
|
|
87
|
+
axis: j.axis,
|
|
88
|
+
limits: j.limits,
|
|
89
|
+
drive: {
|
|
90
|
+
mode: "acceleration",
|
|
91
|
+
stiffness: j.stiffness,
|
|
92
|
+
damping: j.damping,
|
|
93
|
+
positionTarget: 0,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
extras: { role: p.role },
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
for (const [sockName, pos] of Object.entries(sockets)) {
|
|
100
|
+
const nodeName = `Socket_${sockName}`;
|
|
101
|
+
nodes.push({ name: nodeName, parent: "Receiver_Root", position: [pos[0], pos[1], pos[2]], size: [0, 0, 0] });
|
|
102
|
+
specs.push({
|
|
103
|
+
nodeName,
|
|
104
|
+
extras: { socketId: sockName, isIkAnchor: sockName.startsWith("grip_") },
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
recipeId: recipe.id,
|
|
109
|
+
spec: recipe.spec,
|
|
110
|
+
parts,
|
|
111
|
+
totalMassKg: total.massKg,
|
|
112
|
+
fixedMassKg: rootProps.massKg,
|
|
113
|
+
centerOfMass: total.centerOfMass,
|
|
114
|
+
inertiaDiagonal: total.inertiaDiagonal,
|
|
115
|
+
sockets,
|
|
116
|
+
nodes,
|
|
117
|
+
specs,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parametric multi-part launcher definition: receiver, barrel, bolt/slide, pump, trigger, magazine, stock.
|
|
3
|
+
* Frame: SI metres, +Y up, +Z muzzle forward (or -Z muzzle in Khronos emitter space; socket `muzzle` gives exact local point).
|
|
4
|
+
* Zero runtime dependencies.
|
|
5
|
+
*/
|
|
6
|
+
import type { LauncherPartRole, LauncherSocketName, LauncherSpec, Vec3Tuple } from "./schema.js";
|
|
7
|
+
export type Vec3 = [number, number, number];
|
|
8
|
+
export interface LauncherJointSpec {
|
|
9
|
+
readonly kind: "prismatic" | "revolute";
|
|
10
|
+
readonly anchor: Vec3;
|
|
11
|
+
readonly axis: Vec3;
|
|
12
|
+
/** Metres for prismatic, radians for revolute. */
|
|
13
|
+
readonly limits: [number, number];
|
|
14
|
+
readonly stiffness: number;
|
|
15
|
+
readonly damping: number;
|
|
16
|
+
}
|
|
17
|
+
export interface LauncherPart {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly role: LauncherPartRole;
|
|
20
|
+
readonly massKg: number;
|
|
21
|
+
readonly center: Vec3;
|
|
22
|
+
readonly size: Vec3;
|
|
23
|
+
readonly joint?: LauncherJointSpec;
|
|
24
|
+
}
|
|
25
|
+
export interface LauncherDims {
|
|
26
|
+
readonly receiverLength: number;
|
|
27
|
+
readonly receiverWidth: number;
|
|
28
|
+
readonly receiverHeight: number;
|
|
29
|
+
readonly barrelLength: number;
|
|
30
|
+
readonly barrelDiameter: number;
|
|
31
|
+
readonly gripHeight: number;
|
|
32
|
+
readonly magLength: number;
|
|
33
|
+
readonly boltStroke: number;
|
|
34
|
+
readonly hasStock: boolean;
|
|
35
|
+
readonly hasPump: boolean;
|
|
36
|
+
readonly hasScreen?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface LauncherMasses {
|
|
39
|
+
readonly receiver: number;
|
|
40
|
+
readonly barrel: number;
|
|
41
|
+
readonly bolt: number;
|
|
42
|
+
readonly trigger: number;
|
|
43
|
+
readonly magazine: number;
|
|
44
|
+
readonly stock: number;
|
|
45
|
+
readonly pump: number;
|
|
46
|
+
readonly screen?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface LauncherRecipe {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly label: string;
|
|
51
|
+
readonly r2Key: string;
|
|
52
|
+
readonly spec: LauncherSpec;
|
|
53
|
+
readonly dims: LauncherDims;
|
|
54
|
+
readonly masses: LauncherMasses;
|
|
55
|
+
}
|
|
56
|
+
export declare function boxInertiaDiagonal(massKg: number, size: Vec3): Vec3;
|
|
57
|
+
export declare function buildLauncherParts(recipe: LauncherRecipe): LauncherPart[];
|
|
58
|
+
export declare function resolveLauncherSockets(recipe: LauncherRecipe): Record<LauncherSocketName, Vec3Tuple>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export function boxInertiaDiagonal(massKg, size) {
|
|
2
|
+
const [x, y, z] = size;
|
|
3
|
+
const k = massKg / 12;
|
|
4
|
+
return [k * (y * y + z * z), k * (x * x + z * z), k * (x * x + y * y)];
|
|
5
|
+
}
|
|
6
|
+
export function buildLauncherParts(recipe) {
|
|
7
|
+
const d = recipe.dims;
|
|
8
|
+
const m = recipe.masses;
|
|
9
|
+
if (!(d.receiverLength > 0 && d.receiverWidth > 0 && d.receiverHeight > 0 && d.barrelLength > 0)) {
|
|
10
|
+
throw new RangeError(`launcherParts(${recipe.id}): dimensions must be > 0`);
|
|
11
|
+
}
|
|
12
|
+
const zBarrelCenter = d.receiverLength * 0.5 + d.barrelLength * 0.5;
|
|
13
|
+
const yBarrel = d.receiverHeight * 0.25;
|
|
14
|
+
const parts = [
|
|
15
|
+
{
|
|
16
|
+
name: "Receiver",
|
|
17
|
+
role: "receiver",
|
|
18
|
+
massKg: m.receiver,
|
|
19
|
+
center: [0, 0, 0],
|
|
20
|
+
size: [d.receiverWidth, d.receiverHeight, d.receiverLength],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "Barrel",
|
|
24
|
+
role: "barrel",
|
|
25
|
+
massKg: m.barrel,
|
|
26
|
+
center: [0, yBarrel, zBarrelCenter],
|
|
27
|
+
size: [d.barrelDiameter, d.barrelDiameter, d.barrelLength],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "Bolt",
|
|
31
|
+
role: "bolt",
|
|
32
|
+
massKg: m.bolt,
|
|
33
|
+
center: [0, d.receiverHeight * 0.35, 0],
|
|
34
|
+
size: [d.receiverWidth * 0.82, d.receiverHeight * 0.42, d.receiverLength * 0.55],
|
|
35
|
+
joint: {
|
|
36
|
+
kind: "prismatic",
|
|
37
|
+
anchor: [0, d.receiverHeight * 0.35, 0],
|
|
38
|
+
axis: [0, 0, 1],
|
|
39
|
+
limits: [-d.boltStroke, 0],
|
|
40
|
+
stiffness: 420,
|
|
41
|
+
damping: 24,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "Trigger",
|
|
46
|
+
role: "trigger",
|
|
47
|
+
massKg: m.trigger,
|
|
48
|
+
center: [0, -d.receiverHeight * 0.55, -d.receiverLength * 0.12],
|
|
49
|
+
size: [d.receiverWidth * 0.28, 0.028, 0.016],
|
|
50
|
+
joint: {
|
|
51
|
+
kind: "revolute",
|
|
52
|
+
anchor: [0, -d.receiverHeight * 0.42, -d.receiverLength * 0.12],
|
|
53
|
+
axis: [1, 0, 0],
|
|
54
|
+
limits: [0, 0.45],
|
|
55
|
+
stiffness: 80,
|
|
56
|
+
damping: 8,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "Magazine",
|
|
61
|
+
role: "magazine",
|
|
62
|
+
massKg: m.magazine,
|
|
63
|
+
center: [0, -d.receiverHeight * 0.5 - d.magLength * 0.45, d.hasStock ? 0.04 : -d.receiverLength * 0.18],
|
|
64
|
+
size: [d.receiverWidth * 0.68, d.magLength, 0.045],
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
if (d.hasStock && m.stock > 0) {
|
|
68
|
+
const stockLen = d.receiverLength * 0.75;
|
|
69
|
+
parts.push({
|
|
70
|
+
name: "Stock",
|
|
71
|
+
role: "stock",
|
|
72
|
+
massKg: m.stock,
|
|
73
|
+
center: [0, -d.receiverHeight * 0.1, -d.receiverLength * 0.5 - stockLen * 0.5],
|
|
74
|
+
size: [d.receiverWidth * 0.85, d.receiverHeight * 1.1, stockLen],
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (d.hasPump && m.pump > 0) {
|
|
78
|
+
const pumpZ = d.receiverLength * 0.5 + d.barrelLength * 0.38;
|
|
79
|
+
parts.push({
|
|
80
|
+
name: "Pump",
|
|
81
|
+
role: "pump",
|
|
82
|
+
massKg: m.pump,
|
|
83
|
+
center: [0, -d.receiverHeight * 0.1, pumpZ],
|
|
84
|
+
size: [d.receiverWidth * 1.15, d.receiverHeight * 0.65, 0.14],
|
|
85
|
+
joint: {
|
|
86
|
+
kind: "prismatic",
|
|
87
|
+
anchor: [0, -d.receiverHeight * 0.1, pumpZ],
|
|
88
|
+
axis: [0, 0, 1],
|
|
89
|
+
limits: [-0.095, 0],
|
|
90
|
+
stiffness: 320,
|
|
91
|
+
damping: 20,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (d.hasScreen && (m.screen ?? 0.03) > 0) {
|
|
96
|
+
parts.push({
|
|
97
|
+
name: "Screen_Rect",
|
|
98
|
+
role: "screen_rect",
|
|
99
|
+
massKg: m.screen ?? 0.03,
|
|
100
|
+
center: [0, d.receiverHeight * 0.52, -d.receiverLength * 0.32],
|
|
101
|
+
size: [d.receiverWidth * 0.72, 0.024, 0.006],
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return parts;
|
|
105
|
+
}
|
|
106
|
+
export function resolveLauncherSockets(recipe) {
|
|
107
|
+
const d = recipe.dims;
|
|
108
|
+
const s = recipe.spec.sockets;
|
|
109
|
+
const zMuzzle = d.receiverLength * 0.5 + d.barrelLength;
|
|
110
|
+
return {
|
|
111
|
+
grip_primary: s.grip_primary ?? [0, -d.receiverHeight * 0.5 - d.gripHeight * 0.5, -d.receiverLength * 0.2],
|
|
112
|
+
grip_secondary: s.grip_secondary ?? [0, -d.receiverHeight * 0.25, d.receiverLength * 0.5 + d.barrelLength * 0.35],
|
|
113
|
+
rail_top: s.rail_top ?? [0, d.receiverHeight * 0.5 + 0.008, 0],
|
|
114
|
+
rail_under: s.rail_under ?? [0, -d.receiverHeight * 0.5 - 0.008, d.receiverLength * 0.35],
|
|
115
|
+
muzzle: s.muzzle ?? [0, d.receiverHeight * 0.25, zMuzzle],
|
|
116
|
+
eject_port: s.eject_port ?? [d.receiverWidth * 0.52, d.receiverHeight * 0.25, 0.02],
|
|
117
|
+
sight_align: s.sight_align ?? [0, d.receiverHeight * 0.5 + 0.022, -d.receiverLength * 0.25],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LauncherRecipe } from "./launcherParts.js";
|
|
2
|
+
export declare const KOLMOGOROV_PISTOL: LauncherRecipe;
|
|
3
|
+
export declare const KOLMOGOROV_CARBINE: LauncherRecipe;
|
|
4
|
+
export declare const KOLMOGOROV_SHOTGUN: LauncherRecipe;
|
|
5
|
+
export declare const LAUNCHER_RECIPES: readonly LauncherRecipe[];
|
|
6
|
+
export declare function findLauncherRecipe(id: string): LauncherRecipe;
|
package/dist/recipes.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { DEFAULT_AMMO_CATALOG } from "./schema.js";
|
|
2
|
+
export const KOLMOGOROV_PISTOL = Object.freeze({
|
|
3
|
+
id: "kolmogorov_pistol",
|
|
4
|
+
label: "Kolmogorov 9mm Sidearm",
|
|
5
|
+
r2Key: "weapons/kolmogorov_pistol.glb",
|
|
6
|
+
spec: Object.freeze({
|
|
7
|
+
id: "kolmogorov_pistol",
|
|
8
|
+
ammoId: DEFAULT_AMMO_CATALOG.pistol.id,
|
|
9
|
+
fireRateHz: 6.5,
|
|
10
|
+
magazineCapacity: 15,
|
|
11
|
+
reloadSec: 1.4,
|
|
12
|
+
recoilImpulseNs: 2.4,
|
|
13
|
+
sockets: Object.freeze({
|
|
14
|
+
grip_primary: [0, -0.06, -0.04],
|
|
15
|
+
rail_under: [0, -0.015, 0.08],
|
|
16
|
+
muzzle: [0, 0.02, 0.19],
|
|
17
|
+
eject_port: [0.016, 0.024, 0.02],
|
|
18
|
+
sight_align: [0, 0.038, -0.06],
|
|
19
|
+
}),
|
|
20
|
+
}),
|
|
21
|
+
dims: Object.freeze({
|
|
22
|
+
receiverLength: 0.16,
|
|
23
|
+
receiverWidth: 0.032,
|
|
24
|
+
receiverHeight: 0.042,
|
|
25
|
+
barrelLength: 0.11,
|
|
26
|
+
barrelDiameter: 0.018,
|
|
27
|
+
gripHeight: 0.10,
|
|
28
|
+
magLength: 0.11,
|
|
29
|
+
boltStroke: 0.042,
|
|
30
|
+
hasStock: false,
|
|
31
|
+
hasPump: false,
|
|
32
|
+
}),
|
|
33
|
+
masses: Object.freeze({
|
|
34
|
+
receiver: 0.48,
|
|
35
|
+
barrel: 0.14,
|
|
36
|
+
bolt: 0.24,
|
|
37
|
+
trigger: 0.02,
|
|
38
|
+
magazine: 0.18,
|
|
39
|
+
stock: 0,
|
|
40
|
+
pump: 0,
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
export const KOLMOGOROV_CARBINE = Object.freeze({
|
|
44
|
+
id: "kolmogorov_carbine",
|
|
45
|
+
label: "Kolmogorov 5.56 Modular Carbine",
|
|
46
|
+
r2Key: "weapons/kolmogorov_carbine.glb",
|
|
47
|
+
spec: Object.freeze({
|
|
48
|
+
id: "kolmogorov_carbine",
|
|
49
|
+
ammoId: DEFAULT_AMMO_CATALOG.rifle.id,
|
|
50
|
+
fireRateHz: 11.5,
|
|
51
|
+
magazineCapacity: 30,
|
|
52
|
+
reloadSec: 1.9,
|
|
53
|
+
recoilImpulseNs: 4.1,
|
|
54
|
+
sockets: Object.freeze({
|
|
55
|
+
grip_primary: [0, -0.08, -0.07],
|
|
56
|
+
grip_secondary: [0, -0.03, 0.28],
|
|
57
|
+
rail_top: [0, 0.042, 0.04],
|
|
58
|
+
rail_under: [0, -0.032, 0.24],
|
|
59
|
+
muzzle: [0, 0.015, 0.56],
|
|
60
|
+
eject_port: [0.024, 0.018, 0.04],
|
|
61
|
+
sight_align: [0, 0.062, -0.08],
|
|
62
|
+
}),
|
|
63
|
+
}),
|
|
64
|
+
dims: Object.freeze({
|
|
65
|
+
receiverLength: 0.26,
|
|
66
|
+
receiverWidth: 0.046,
|
|
67
|
+
receiverHeight: 0.068,
|
|
68
|
+
barrelLength: 0.37,
|
|
69
|
+
barrelDiameter: 0.024,
|
|
70
|
+
gripHeight: 0.11,
|
|
71
|
+
magLength: 0.18,
|
|
72
|
+
boltStroke: 0.075,
|
|
73
|
+
hasStock: true,
|
|
74
|
+
hasPump: false,
|
|
75
|
+
}),
|
|
76
|
+
masses: Object.freeze({
|
|
77
|
+
receiver: 1.35,
|
|
78
|
+
barrel: 0.68,
|
|
79
|
+
bolt: 0.38,
|
|
80
|
+
trigger: 0.03,
|
|
81
|
+
magazine: 0.36,
|
|
82
|
+
stock: 0.45,
|
|
83
|
+
pump: 0,
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
export const KOLMOGOROV_SHOTGUN = Object.freeze({
|
|
87
|
+
id: "kolmogorov_shotgun",
|
|
88
|
+
label: "Kolmogorov 12G Pump Breacher",
|
|
89
|
+
r2Key: "weapons/kolmogorov_shotgun.glb",
|
|
90
|
+
spec: Object.freeze({
|
|
91
|
+
id: "kolmogorov_shotgun",
|
|
92
|
+
ammoId: DEFAULT_AMMO_CATALOG.orb.id,
|
|
93
|
+
fireRateHz: 1.4,
|
|
94
|
+
magazineCapacity: 8,
|
|
95
|
+
reloadSec: 2.6,
|
|
96
|
+
recoilImpulseNs: 9.5,
|
|
97
|
+
sockets: Object.freeze({
|
|
98
|
+
grip_primary: [0, -0.07, -0.08],
|
|
99
|
+
grip_secondary: [0, -0.02, 0.34],
|
|
100
|
+
rail_top: [0, 0.04, 0.02],
|
|
101
|
+
muzzle: [0, 0.018, 0.64],
|
|
102
|
+
eject_port: [0.025, 0.018, 0.05],
|
|
103
|
+
sight_align: [0, 0.052, -0.09],
|
|
104
|
+
}),
|
|
105
|
+
}),
|
|
106
|
+
dims: Object.freeze({
|
|
107
|
+
receiverLength: 0.24,
|
|
108
|
+
receiverWidth: 0.048,
|
|
109
|
+
receiverHeight: 0.064,
|
|
110
|
+
barrelLength: 0.46,
|
|
111
|
+
barrelDiameter: 0.028,
|
|
112
|
+
gripHeight: 0.10,
|
|
113
|
+
magLength: 0.08,
|
|
114
|
+
boltStroke: 0.085,
|
|
115
|
+
hasStock: true,
|
|
116
|
+
hasPump: true,
|
|
117
|
+
}),
|
|
118
|
+
masses: Object.freeze({
|
|
119
|
+
receiver: 1.45,
|
|
120
|
+
barrel: 0.85,
|
|
121
|
+
bolt: 0.32,
|
|
122
|
+
trigger: 0.03,
|
|
123
|
+
magazine: 0.22,
|
|
124
|
+
stock: 0.52,
|
|
125
|
+
pump: 0.28,
|
|
126
|
+
}),
|
|
127
|
+
});
|
|
128
|
+
export const LAUNCHER_RECIPES = Object.freeze([
|
|
129
|
+
KOLMOGOROV_PISTOL,
|
|
130
|
+
KOLMOGOROV_CARBINE,
|
|
131
|
+
KOLMOGOROV_SHOTGUN,
|
|
132
|
+
]);
|
|
133
|
+
export function findLauncherRecipe(id) {
|
|
134
|
+
const hit = LAUNCHER_RECIPES.find((r) => r.id === id);
|
|
135
|
+
if (!hit)
|
|
136
|
+
throw new RangeError(`@khr3/launchers: unknown recipe "${id}"`);
|
|
137
|
+
return hit;
|
|
138
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khr3/launchers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|