@pinkaphant/kolmo 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 CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ```sh
8
8
  # Install into an existing R3F / Vite app:
9
- npm install @pinkaphant/kolmo @pinkaphant/ecctrl@^2.0.4-beta.3 @khr3/core @khr3/assets @khr3/c12 @khr3/vehicles @khr3/launchers @khr3/body
9
+ npm install @pinkaphant/kolmo @pinkaphant/ecctrl@^2.0.4-beta.3 @khr3/core @khr3/assets @khr3/c12 @khr3/vehicles @khr3/launchers
10
10
 
11
11
  # Or scaffold your own standalone game (configured for your own Cloudflare Workers/R2 account):
12
12
  npx @pinkaphant/kolmo create my-road-game --template longline
@@ -26,7 +26,7 @@ All `@khr3/*` packages are **zero-`koota`** reusable libraries. **`@pinkaphant/k
26
26
  | `@pinkaphant/kolmo/shaders` | [src/shaders/index.ts](./src/shaders/index.ts) | 6-mode retro quantizer (`rgb555`, `rgb444`, `rgb332`, `crunchy16`/`crunchy64` 3D LUTs, linear-light Bayer 8×8, [retroShader.ts](./src/shaders/retroShader.ts)), PS2 world-locked splat shaders ([ps2TerrainWebGL.ts](./src/shaders/ps2TerrainWebGL.ts), [ps2RoadWebGL.ts](./src/shaders/ps2RoadWebGL.ts)), `<KolmoSkybox>`, `<KolmoExoplanet>` |
27
27
  | `@pinkaphant/kolmo/importer` | [src/importer/index.ts](./src/importer/index.ts) | `<GlbImportGate>` ([GlbImportGate.tsx](./src/importer/GlbImportGate.tsx)), `<ChopShopPanel>`, `<DomainWorkshopPanel>` (`c12`, `launcher`, `person`, live R2 vault), zero-WASM USD intake ([usdToGlb.ts](./src/importer/usdToGlb.ts)), and W3C WebMCP (`importer_*` tools in [importerWebMcp.ts](./src/importer/importerWebMcp.ts)) |
28
28
  | `@pinkaphant/kolmo/junk` | [src/junk/index.ts](./src/junk/index.ts) | `<KolmoJunk>` ([KolmoJunk.tsx](./src/junk/KolmoJunk.tsx)), `<DestructibleTarget>`, multi-LOD cans & bottles, decals, and BVH shattering (`<ShardPieces>`) |
29
- | `@khr3/body` + `@khr3/body/react` | Re-exported from `@pinkaphant/kolmo` | `1.75 m` SI standing capsule (`BODY_SI`, `bodySpawnPosition`, `withExcludeCharacterRay`), `<KhrBody>`, and `<HeldItem>` |
29
+ | `@pinkaphant/kolmo/body` | [src/body/index.ts](./src/body/index.ts) | `1.75 m` SI standing capsule (`BODY_SI`, `bodySpawnPosition`, `withExcludeCharacterRay`), `<KhrBody>`, and `<HeldItem>` |
30
30
 
31
31
  ## Flagship Games Inside `Kolmo/games/` (Excluded from npm Tarball)
32
32
 
package/bin/kolmo.mjs CHANGED
@@ -25,8 +25,9 @@ const pkgName = path.basename(targetDir).toLowerCase().replace(/[^a-z0-9-_]/g, "
25
25
 
26
26
  const SINGLETON_DEDUPE = [
27
27
  "react", "react-dom", "three", "@react-three/fiber",
28
- "@react-three/drei", "@react-three/rapier", "@dimforge/rapier3d-compat",
29
- "@pinkaphant/ecctrl", "koota",
28
+ "@react-three/drei", "@react-three/rapier", "@react-three/uikit",
29
+ "@pmndrs/uikit", "@preact/signals-core", "@dimforge/rapier3d-compat",
30
+ "@pinkaphant/ecctrl", "koota", "zustand",
30
31
  ];
31
32
 
32
33
  fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify({
@@ -43,22 +44,26 @@ fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify({
43
44
  dependencies: {
44
45
  "@dimforge/rapier3d-compat": "^0.19.2",
45
46
  "@khr3/assets": "^0.2.1",
46
- "@khr3/body": "^0.1.0",
47
47
  "@khr3/c12": "^0.3.0",
48
48
  "@khr3/core": "^0.1.1",
49
49
  "@khr3/launchers": "^0.2.1",
50
- "@khr3/vehicles": "^0.1.1",
50
+ "@khr3/vehicles": "^0.1.2",
51
51
  "@pinkaphant/ecctrl": "^2.0.4-beta.3",
52
- "@pinkaphant/kolmo": "^0.1.0",
52
+ "@pinkaphant/kolmo": "^0.1.2",
53
+ "@pmndrs/uikit": "^1.0.78",
54
+ "@preact/signals-core": "^1.5.1",
53
55
  "@react-three/drei": "^10.7.7",
54
56
  "@react-three/fiber": "^9.6.1",
55
57
  "@react-three/rapier": "^2.2.0",
58
+ "@react-three/uikit": "^1.0.78",
56
59
  "koota": "^0.6.5",
57
60
  "react": "^19.2.7",
58
61
  "react-dom": "^19.2.7",
59
62
  "three": "^0.184.0",
63
+ "zustand": "^5.0.14",
60
64
  },
61
65
  devDependencies: {
66
+ "@types/node": "^22.20.5",
62
67
  "@types/react": "^19.2.16",
63
68
  "@types/react-dom": "^19.2.3",
64
69
  "@types/three": "^0.184.0",
@@ -69,14 +74,46 @@ fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify({
69
74
  },
70
75
  }, null, 2));
71
76
 
72
- fs.writeFileSync(path.join(targetDir, "vite.config.ts"), `import react from "@vitejs/plugin-react";
73
- import { defineConfig } from "vite";
77
+ fs.writeFileSync(path.join(targetDir, "vite.config.ts"), `import fs from "node:fs";
78
+ import path from "node:path";
79
+ import react from "@vitejs/plugin-react";
80
+ import { defineConfig, type Plugin } from "vite";
81
+
82
+ function externalizeRapierWasm(): Plugin {
83
+ return {
84
+ name: "kolmo-externalize-rapier-wasm",
85
+ apply: "build",
86
+ transform(code, id) {
87
+ if (!id.replace(/\\\\/g, "/").endsWith("/@dimforge/rapier3d-compat/rapier.mjs")) return null;
88
+ const wasmPath = path.join(path.dirname(id), "rapier_wasm3d_bg.wasm");
89
+ if (!fs.existsSync(wasmPath)) return null;
90
+ const refId = this.emitFile({ type: "asset", name: "rapier_wasm3d_bg.wasm", source: fs.readFileSync(wasmPath) });
91
+ return {
92
+ code: code.replace(/[\\w$]+\\.toByteArray\\(["']AGFzbQE[A-Za-z0-9+/=]+["']\\)\\.buffer/, \`import.meta.ROLLUP_FILE_URL_\${refId}\`),
93
+ map: null,
94
+ };
95
+ },
96
+ };
97
+ }
74
98
 
75
99
  export default defineConfig({
76
- plugins: [react()],
77
- assetsInclude: ["**/*.wasm", "**/*.glb"],
100
+ plugins: [react(), externalizeRapierWasm()],
78
101
  resolve: { dedupe: ${JSON.stringify(SINGLETON_DEDUPE)} },
79
- optimizeDeps: { exclude: ["@dimforge/rapier3d-compat"] },
102
+ build: {
103
+ chunkSizeWarningLimit: 1100,
104
+ rolldownOptions: {
105
+ output: {
106
+ codeSplitting: {
107
+ groups: [
108
+ { name: "vendor-react", test: /[\\\\/]node_modules[\\\\/](react|react-dom|scheduler)[\\\\/]/, priority: 40 },
109
+ { name: "vendor-three", test: /[\\\\/]node_modules[\\\\/](three|three-stdlib|maath|camera-controls)[\\\\/]/, priority: 30, includeDependenciesRecursively: false },
110
+ { name: "vendor-physics", test: /[\\\\/]node_modules[\\\\/](@dimforge\\/rapier3d-compat|@react-three\\/rapier|@pinkaphant\\/ecctrl)[\\\\/]/, priority: 20, includeDependenciesRecursively: false },
111
+ { name: "vendor-r3f", test: /[\\\\/]node_modules[\\\\/]/, priority: 10, includeDependenciesRecursively: false },
112
+ ],
113
+ },
114
+ },
115
+ },
116
+ },
80
117
  });\n`);
81
118
 
82
119
  fs.writeFileSync(path.join(targetDir, "tsconfig.json"), JSON.stringify({
@@ -0,0 +1,22 @@
1
+ import { type KhrAssetBundle } from "@khr3/core";
2
+ import { type RapierRigidBody } from "@react-three/rapier";
3
+ import { type Ref, type RefObject } from "react";
4
+ import * as THREE from "three";
5
+ import { type BodySocketId } from "./bodySi.js";
6
+ import type { KhrBodyHandle } from "./KhrBody.js";
7
+ export interface HeldItemHandle {
8
+ readonly socket: BodySocketId;
9
+ readonly rigidBody: RapierRigidBody | null;
10
+ setRoleTarget(role: string, target: number): number;
11
+ setJointTarget(nodeName: string, target: number): number;
12
+ getRoleValue(role: string): number;
13
+ }
14
+ export interface HeldItemProps {
15
+ readonly ref?: Ref<HeldItemHandle>;
16
+ readonly bundle: KhrAssetBundle;
17
+ readonly socket: BodySocketId;
18
+ readonly bodyRef?: RefObject<KhrBodyHandle | null>;
19
+ readonly parentSocketObject?: THREE.Object3D | null;
20
+ readonly userData?: Record<string, unknown>;
21
+ }
22
+ export declare function HeldItem({ ref, bundle, socket, bodyRef, parentSocketObject, userData }: HeldItemProps): import("react").JSX.Element;
@@ -0,0 +1,26 @@
1
+ import { type EcctrlHandle, type EcctrlProps } from "@pinkaphant/ecctrl";
2
+ import { type EcctrlCameraControlsHandle } from "@pinkaphant/ecctrl/camera";
3
+ import { type ReactNode, type Ref } from "react";
4
+ import * as THREE from "three";
5
+ import { stepCameraSync, type BodySiConstants, type BodySocketId } from "./bodySi.js";
6
+ export { stepCameraSync };
7
+ export interface KhrBodyHandle {
8
+ readonly ecctrl: EcctrlHandle | null;
9
+ readonly cameraControls: EcctrlCameraControlsHandle | null;
10
+ socket(id: BodySocketId): THREE.Object3D | null;
11
+ syncCameraStep(pos: {
12
+ x: number;
13
+ y: number;
14
+ z: number;
15
+ }): void;
16
+ }
17
+ export interface KhrBodyProps extends Omit<EcctrlProps, "ref"> {
18
+ readonly ref?: Ref<KhrBodyHandle>;
19
+ readonly si?: BodySiConstants;
20
+ readonly smoothCamera?: boolean;
21
+ readonly makeDefaultCamera?: boolean;
22
+ readonly enableInput?: boolean;
23
+ readonly viewModelChildren?: ReactNode;
24
+ readonly socketOffsets?: Partial<Record<BodySocketId, readonly [number, number, number]>>;
25
+ }
26
+ export declare function KhrBody({ ref, si, smoothCamera, makeDefaultCamera, enableInput, enable, viewModelChildren, socketOffsets, children, userData: callerUserData, position, ...ecctrlProps }: KhrBodyProps): import("react").JSX.Element;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * SI first-person and third-person body dimensions and zero-allocation camera helpers
3
+ * for `@pinkaphant/ecctrl` `<Ecctrl>` and `<EcctrlCameraControls>`.
4
+ */
5
+ export interface BodySiConstants {
6
+ /** `<Ecctrl capsuleHalfHeight>` in metres. */
7
+ readonly capsuleHalfHeight: number;
8
+ /** `<Ecctrl capsuleRadius>` in metres. */
9
+ readonly capsuleRadius: number;
10
+ /** `<Ecctrl floatHeight>` in metres. */
11
+ readonly floatHeight: number;
12
+ /** Eye height above the floor in metres. */
13
+ readonly eyeHeight: number;
14
+ /** Camera dolly distance in first person (metres). */
15
+ readonly firstPersonDistance: number;
16
+ /** Camera dolly distance in third person (metres). */
17
+ readonly thirdPersonDistance: number;
18
+ }
19
+ /** 1.75 m standing adult: 2 * 0.50 + 2 * 0.30 + 0.15. */
20
+ export declare const BODY_SI: BodySiConstants;
21
+ /** Ecctrl movement tuning for the standing SI body. */
22
+ export declare const BODY_MOVE_TUNE: Readonly<{
23
+ readonly maxWalkVel: 2.5;
24
+ readonly maxRunVel: 9;
25
+ readonly accDeltaTime: 0.96;
26
+ readonly decDeltaTime: 0.9;
27
+ readonly slideGripFactor: 1;
28
+ readonly moveImpulsePointOffset: 0;
29
+ readonly airDragFactor: 0.85;
30
+ readonly enableToggleRun: false;
31
+ }>;
32
+ export type BodySocketId = "Socket_Hand_R" | "Socket_Hand_L" | "Socket_Head" | "Socket_Back";
33
+ export declare const BODY_SOCKET_IDS: readonly BodySocketId[];
34
+ /** Rigid-body centre height when standing at rest on flat ground. */
35
+ export declare function bodyRestCenterY(b?: BodySiConstants): number;
36
+ /** Total standing height from floor to the top of the capsule. */
37
+ export declare function bodyStandingHeight(b?: BodySiConstants): number;
38
+ /** Camera target offset above the rigid-body centre. */
39
+ export declare function bodyEyeOffsetY(b?: BodySiConstants): number;
40
+ /** Spawn position whose feet rest on `floorY`. */
41
+ export declare function bodySpawnPosition(x: number, floorY: number, z: number, b?: BodySiConstants): [number, number, number];
42
+ /**
43
+ * Merges `ecctrl.excludeCharacterRay: true` into a RigidBody `userData` object for held-item colliders
44
+ * so `@pinkaphant/ecctrl` ground casts ignore held items (`collider.parent()?.userData`).
45
+ */
46
+ export declare function withExcludeCharacterRay(userData?: Record<string, unknown>): Record<string, unknown>;
47
+ /** Zero-allocation camera step sync from live handle position (and optional local Y axis) to camera controls at eye height. */
48
+ export declare function stepCameraSync(controls: {
49
+ moveTo?: (x: number, y: number, z: number, smooth: boolean) => unknown;
50
+ update?: (dt: number) => unknown;
51
+ } | null, pos: {
52
+ x: number;
53
+ y: number;
54
+ z: number;
55
+ }, eyeOffsetY: number, smooth: boolean, bodyYAxis?: {
56
+ x: number;
57
+ y: number;
58
+ z: number;
59
+ }): void;
@@ -0,0 +1,3 @@
1
+ export { BODY_MOVE_TUNE, BODY_SI, BODY_SOCKET_IDS, bodyEyeOffsetY, bodyRestCenterY, bodySpawnPosition, bodyStandingHeight, stepCameraSync, withExcludeCharacterRay, type BodySiConstants, type BodySocketId, } from "./bodySi.js";
2
+ export { KhrBody, type KhrBodyHandle, type KhrBodyProps } from "./KhrBody.js";
3
+ export { HeldItem, type HeldItemHandle, type HeldItemProps } from "./HeldItem.js";
@@ -0,0 +1 @@
1
+ export { r as BODY_MOVE_TUNE, i as BODY_SI, a as BODY_SOCKET_IDS, t as HeldItem, n as KhrBody, o as bodyEyeOffsetY, s as bodyRestCenterY, c as bodySpawnPosition, l as bodyStandingHeight, u as stepCameraSync, d as withExcludeCharacterRay } from "../body-B7FTf67o.js";
@@ -0,0 +1,362 @@
1
+ import { useContext as e, useEffect as t, useImperativeHandle as n, useLayoutEffect as r, useMemo as i, useRef as a } from "react";
2
+ import * as o from "three";
3
+ import { useFrame as s, useThree as c } from "@react-three/fiber";
4
+ import { JointRegistryContext as l, KhrCollider as u, KhrValidationError as d, claimBundleMount as f, releaseBundleMount as p } from "@khr3/core";
5
+ import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
6
+ import { RigidBody as _ } from "@react-three/rapier";
7
+ import { Ecctrl as v } from "@pinkaphant/ecctrl";
8
+ import { EcctrlCameraControls as y } from "@pinkaphant/ecctrl/camera";
9
+ // src/body/bodySi.ts
10
+ var b = Object.freeze({
11
+ capsuleHalfHeight: .5,
12
+ capsuleRadius: .3,
13
+ floatHeight: .15,
14
+ eyeHeight: 1.62,
15
+ firstPersonDistance: .02,
16
+ thirdPersonDistance: 3.2
17
+ }), x = Object.freeze({
18
+ maxWalkVel: 2.5,
19
+ maxRunVel: 9,
20
+ accDeltaTime: .96,
21
+ decDeltaTime: .9,
22
+ slideGripFactor: 1,
23
+ moveImpulsePointOffset: 0,
24
+ airDragFactor: .85,
25
+ enableToggleRun: !1
26
+ }), S = Object.freeze([
27
+ "Socket_Hand_R",
28
+ "Socket_Hand_L",
29
+ "Socket_Head",
30
+ "Socket_Back"
31
+ ]);
32
+ function C(e) {
33
+ for (let [t, n] of Object.entries(e)) if (!(typeof n == "number" && Number.isFinite(n) && n >= 0)) throw RangeError(`kolmo/body: ${t} must be a finite non-negative number, got ${String(n)}`);
34
+ if (!(e.capsuleRadius > 0)) throw RangeError("kolmo/body: capsuleRadius must be > 0");
35
+ }
36
+ function w(e = b) {
37
+ return C(e), e.floatHeight + e.capsuleRadius + e.capsuleHalfHeight;
38
+ }
39
+ function T(e = b) {
40
+ return w(e) + e.capsuleHalfHeight + e.capsuleRadius;
41
+ }
42
+ function E(e = b) {
43
+ let t = e.eyeHeight - w(e);
44
+ if (!(t > 0)) throw RangeError("kolmo/body: eyeHeight must sit above the body centre");
45
+ return t;
46
+ }
47
+ function D(e, t, n, r = b) {
48
+ return [
49
+ e,
50
+ t + w(r),
51
+ n
52
+ ];
53
+ }
54
+ function O(e) {
55
+ let t = e?.ecctrl ?? {};
56
+ return {
57
+ ...e ?? {},
58
+ ecctrl: {
59
+ ...t,
60
+ excludeCharacterRay: !0
61
+ }
62
+ };
63
+ }
64
+ function k(e, t, n, r, i) {
65
+ if (!e) return;
66
+ let a = i ? t.x + i.x * n : t.x, o = i ? t.y + i.y * n : t.y + n, s = i ? t.z + i.z * n : t.z;
67
+ e.moveTo?.(a, o, s, r), e.update?.(0);
68
+ }
69
+ // src/body/KhrBody.tsx
70
+ var A = Object.freeze({
71
+ Socket_Hand_R: [
72
+ .22,
73
+ -.18,
74
+ -.38
75
+ ],
76
+ Socket_Hand_L: [
77
+ -.22,
78
+ -.18,
79
+ -.38
80
+ ],
81
+ Socket_Head: [
82
+ 0,
83
+ 0,
84
+ -.12
85
+ ],
86
+ Socket_Back: [
87
+ 0,
88
+ -.25,
89
+ .28
90
+ ]
91
+ }), j = {
92
+ forward: !1,
93
+ backward: !1,
94
+ leftward: !1,
95
+ rightward: !1,
96
+ run: !1,
97
+ jump: !1
98
+ };
99
+ function M({ active: e, ecctrlRef: n }) {
100
+ let r = a({
101
+ w: !1,
102
+ s: !1,
103
+ a: !1,
104
+ d: !1,
105
+ shift: !1,
106
+ space: !1,
107
+ dirty: !1
108
+ }), i = a(e);
109
+ return t(() => {
110
+ if (!e || typeof window > "u" || typeof window.addEventListener != "function") return;
111
+ let t = (e) => (t) => {
112
+ let n = r.current;
113
+ t.code === "KeyW" || t.code === "ArrowUp" ? n.w !== e && (n.w = e, n.dirty = !0) : t.code === "KeyS" || t.code === "ArrowDown" ? n.s !== e && (n.s = e, n.dirty = !0) : t.code === "KeyA" || t.code === "ArrowLeft" ? n.a !== e && (n.a = e, n.dirty = !0) : t.code === "KeyD" || t.code === "ArrowRight" ? n.d !== e && (n.d = e, n.dirty = !0) : t.code === "ShiftLeft" || t.code === "ShiftRight" ? n.shift !== e && (n.shift = e, n.dirty = !0) : t.code === "Space" && n.space !== e && (n.space = e, n.dirty = !0);
114
+ }, n = () => {
115
+ let e = r.current;
116
+ (e.w || e.s || e.a || e.d || e.shift || e.space) && (e.w = !1, e.s = !1, e.a = !1, e.d = !1, e.shift = !1, e.space = !1, e.dirty = !0);
117
+ }, i = t(!0), a = t(!1);
118
+ return window.addEventListener("keydown", i), window.addEventListener("keyup", a), window.addEventListener("blur", n), () => {
119
+ window.removeEventListener("keydown", i), window.removeEventListener("keyup", a), window.removeEventListener("blur", n);
120
+ };
121
+ }, [e]), s(() => {
122
+ let t = n.current;
123
+ if (!t) return;
124
+ if (!e) {
125
+ if (i.current) {
126
+ let e = r.current;
127
+ e.w = !1, e.s = !1, e.a = !1, e.d = !1, e.shift = !1, e.space = !1, e.dirty = !1, j.forward = !1, j.backward = !1, j.leftward = !1, j.rightward = !1, j.run = !1, j.jump = !1, t.setMovement(j), i.current = !1;
128
+ }
129
+ return;
130
+ }
131
+ i.current = !0;
132
+ let a = r.current;
133
+ a.dirty && (a.dirty = !1, j.forward = a.w, j.backward = a.s, j.leftward = a.a, j.rightward = a.d, j.run = a.shift, j.jump = a.space, t.setMovement(j));
134
+ }), null;
135
+ }
136
+ function N({ ref: e, si: t = b, smoothCamera: r = !1, makeDefaultCamera: o = !0, enableInput: s = !0, enable: l = !0, viewModelChildren: u, socketOffsets: d, children: f, userData: p, position: _, ...C }) {
137
+ let T = a(null), D = a(null), O = a(null), j = a({
138
+ Socket_Hand_R: null,
139
+ Socket_Hand_L: null,
140
+ Socket_Head: null,
141
+ Socket_Back: null
142
+ }), N = i(() => E(t), [t]), F = i(() => [
143
+ 0,
144
+ w(t),
145
+ 0
146
+ ], [t]), I = c((e) => typeof e.gl?.domElement?.setAttribute == "function"), L = i(() => {
147
+ let e = p ?? {}, t = e.ecctrl ?? {};
148
+ return {
149
+ ...e,
150
+ ecctrl: {
151
+ excludeVehicleRay: !0,
152
+ ...t
153
+ }
154
+ };
155
+ }, [p]);
156
+ return n(e, () => ({
157
+ get ecctrl() {
158
+ return T.current;
159
+ },
160
+ get cameraControls() {
161
+ return D.current;
162
+ },
163
+ socket(e) {
164
+ return j.current[e] ?? null;
165
+ },
166
+ syncCameraStep(e) {
167
+ k(D.current, e, N, r, T.current?.bodyYAxis);
168
+ }
169
+ }), [N, r]), /* @__PURE__ */ g(m, { children: [
170
+ /* @__PURE__ */ h(M, {
171
+ active: !!(l && s),
172
+ ecctrlRef: T
173
+ }),
174
+ /* @__PURE__ */ h(v, {
175
+ ref: T,
176
+ enable: l,
177
+ position: _ ?? F,
178
+ capsuleHalfHeight: t.capsuleHalfHeight,
179
+ capsuleRadius: t.capsuleRadius,
180
+ floatHeight: t.floatHeight,
181
+ maxWalkVel: x.maxWalkVel,
182
+ maxRunVel: x.maxRunVel,
183
+ accDeltaTime: x.accDeltaTime,
184
+ decDeltaTime: x.decDeltaTime,
185
+ slideGripFactor: x.slideGripFactor,
186
+ moveImpulsePointOffset: x.moveImpulsePointOffset,
187
+ airDragFactor: x.airDragFactor,
188
+ enableToggleRun: x.enableToggleRun,
189
+ ...C,
190
+ userData: L,
191
+ children: f
192
+ }),
193
+ I ? /* @__PURE__ */ h(y, {
194
+ ref: D,
195
+ makeDefault: o
196
+ }) : null,
197
+ /* @__PURE__ */ h(P, {
198
+ enable: l,
199
+ ecctrlRef: T,
200
+ camControlsRef: D,
201
+ viewModelGroupRef: O,
202
+ eyeOffsetY: N,
203
+ smoothCamera: r
204
+ }),
205
+ /* @__PURE__ */ g("group", {
206
+ ref: O,
207
+ name: "KhrBody_ViewModel",
208
+ children: [S.map((e) => {
209
+ let t = d?.[e] ?? A[e];
210
+ return /* @__PURE__ */ h("group", {
211
+ name: e,
212
+ position: [
213
+ t[0],
214
+ t[1],
215
+ t[2]
216
+ ],
217
+ ref: (t) => {
218
+ j.current[e] = t;
219
+ }
220
+ }, e);
221
+ }), u]
222
+ })
223
+ ] });
224
+ }
225
+ function P({ enable: e, ecctrlRef: t, camControlsRef: n, viewModelGroupRef: r, eyeOffsetY: i, smoothCamera: a }) {
226
+ return s((o) => {
227
+ if (!e) return;
228
+ let s = t.current;
229
+ s && k(n.current, s.currPos, i, a, s.bodyYAxis);
230
+ let c = r.current;
231
+ c && (c.position.copy(o.camera.position), c.quaternion.copy(o.camera.quaternion));
232
+ }), null;
233
+ }
234
+ // src/body/HeldItem.tsx
235
+ var F = new o.Vector3(), I = new o.Vector3(), L = new o.Quaternion(), R = new o.Vector3(), z = new o.Quaternion(), B = 1e5;
236
+ function V(e, t) {
237
+ if (t.kind === "fixed") return 0;
238
+ if (t.kind === "prismatic") return e.mass > 0 ? e.mass : 1;
239
+ F.fromArray(t.axis).normalize(), L.fromArray(e.inertiaOrientation).invert();
240
+ let n = F.clone().applyQuaternion(L), [r, i, a] = e.inertiaDiagonal, o = r * n.x * n.x + i * n.y * n.y + a * n.z * n.z;
241
+ I.fromArray(e.centerOfMass);
242
+ let s = I.dot(F), c = o + e.mass * (I.lengthSq() - s * s);
243
+ return c > 0 ? c : 1;
244
+ }
245
+ var H = (e) => new o.Matrix4().compose(new o.Vector3().fromArray(e.localPosition), new o.Quaternion().fromArray(e.localQuaternion), new o.Vector3(1, 1, 1));
246
+ function U({ ref: t, bundle: c, socket: v, bodyRef: y, parentSocketObject: b, userData: x }) {
247
+ let S = e(l), C = i(() => B++, []), w = a(null), T = a(null), E = a(/* @__PURE__ */ new Map()), D = i(() => O(x), [x]), k = i(() => {
248
+ let e = [];
249
+ for (let t of c.bodies) for (let n = 0; n < t.colliders.length; n++) {
250
+ let r = t.colliders[n], i = new o.Matrix4().compose(new o.Vector3().fromArray(r.localPosition), new o.Quaternion().fromArray(r.localQuaternion), new o.Vector3(1, 1, 1));
251
+ e.push({
252
+ key: `${t.nodeName}:${n}`,
253
+ nodeName: t.nodeName,
254
+ spec: r,
255
+ local: i,
256
+ ref: { current: null }
257
+ });
258
+ }
259
+ return e;
260
+ }, [c]);
261
+ return r(() => {
262
+ f(c, "HeldItem");
263
+ let e = c.scene.position.clone(), t = c.scene.quaternion.clone(), n = c.scene.parent, r = c.sockets.grip_primary ?? c.sockets.IK_Palm_Primary;
264
+ r ? c.scene.position.set(-r[0], -r[1], -r[2]) : c.scene.position.set(0, 0, 0);
265
+ let i = b ?? y?.current?.socket(v) ?? T.current;
266
+ i && c.scene.parent !== i && i.add(c.scene);
267
+ let a = new Map(c.bodies.map((e) => [e.nodeName, e])), s = c.bodies.find((e) => !e.joint) ?? c.bodies[0], l = s ? H(s).invert() : new o.Matrix4(), u = /* @__PURE__ */ new Map();
268
+ for (let e of c.bodies) {
269
+ let t = e.joint;
270
+ if (!t) continue;
271
+ let n = a.get(t.connectedNodeName), r = l.clone().multiply(H(e)), i = n && n.joint ? H(n).invert().multiply(H(e)) : r, s = k.filter((t) => t.nodeName === e.nodeName).map((e) => ({
272
+ ref: e.ref,
273
+ local: e.local
274
+ })), c = t.drive, d = {
275
+ assemblyId: C,
276
+ nodeName: e.nodeName,
277
+ role: t.role ?? e.role,
278
+ kind: t.kind,
279
+ object: e.object,
280
+ axis: new o.Vector3().fromArray(t.axis).normalize(),
281
+ restPosition: e.object.position.clone(),
282
+ restQuaternion: e.object.quaternion.clone(),
283
+ q: 0,
284
+ v: 0,
285
+ positionTarget: c?.positionTarget ?? null,
286
+ velocityTarget: c?.velocityTarget ?? 0,
287
+ drive: c,
288
+ limits: t.limits ? [t.limits[0], t.limits[1]] : null,
289
+ limitStiffness: t.limitStiffness ?? null,
290
+ limitDamping: t.limitDamping ?? 0,
291
+ inertia: V(e, t),
292
+ parent: null,
293
+ restRelParent: i,
294
+ current: i.clone(),
295
+ stamp: -1,
296
+ colliders: s
297
+ };
298
+ u.set(d.nodeName, d);
299
+ }
300
+ for (let e of c.bodies) {
301
+ if (!e.joint) continue;
302
+ let t = u.get(e.nodeName);
303
+ t.parent = u.get(e.joint.connectedNodeName) ?? null, S?.add(t);
304
+ }
305
+ return E.current = u, () => {
306
+ for (let e of u.values()) S?.delete(e), e.object.position.copy(e.restPosition), e.object.quaternion.copy(e.restQuaternion);
307
+ E.current = /* @__PURE__ */ new Map(), c.scene.parent && c.scene.parent.remove(c.scene), n && n.add(c.scene), c.scene.position.copy(e), c.scene.quaternion.copy(t), p(c);
308
+ };
309
+ }, [
310
+ c,
311
+ v,
312
+ y,
313
+ b,
314
+ S,
315
+ C,
316
+ k
317
+ ]), s(() => {
318
+ let e = w.current, t = b ?? y?.current?.socket(v) ?? T.current;
319
+ e && t && (c.scene.parent !== t && t.add(c.scene), c.scene.getWorldPosition(R), c.scene.getWorldQuaternion(z), e.setNextKinematicTranslation(R), e.setNextKinematicRotation(z));
320
+ }), n(t, () => {
321
+ let e = (e, t) => {
322
+ if (!e.drive || e.drive.stiffness === void 0) throw new d(`Joint "${e.nodeName}" has no authored drive stiffness; cannot set a position target`);
323
+ let n = e.limits ? Math.max(e.limits[0], Math.min(e.limits[1], t)) : t;
324
+ return e.positionTarget = n, n;
325
+ };
326
+ return {
327
+ socket: v,
328
+ get rigidBody() {
329
+ return w.current;
330
+ },
331
+ setJointTarget(t, n) {
332
+ let r = E.current.get(t);
333
+ if (!r) throw new d(`kolmo/body: HeldItem has no joint named "${t}"`);
334
+ return e(r, n);
335
+ },
336
+ setRoleTarget(t, n) {
337
+ let r = !1, i = n;
338
+ for (let a of E.current.values()) a.role === t && (i = e(a, n), r = !0);
339
+ if (!r) throw new d(`kolmo/body: HeldItem has no joint with role "${t}"`);
340
+ return i;
341
+ },
342
+ getRoleValue(e) {
343
+ for (let t of E.current.values()) if (t.role === e) return t.q;
344
+ throw new d(`kolmo/body: HeldItem has no joint with role "${e}"`);
345
+ }
346
+ };
347
+ }, [v]), /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h("group", {
348
+ ref: T,
349
+ name: `HeldItem_Fallback_${v}`
350
+ }), /* @__PURE__ */ h(_, {
351
+ ref: w,
352
+ type: "kinematicPosition",
353
+ colliders: !1,
354
+ sensor: !0,
355
+ userData: D,
356
+ children: k.map((e) => /* @__PURE__ */ h(u, {
357
+ ref: e.ref,
358
+ c: e.spec
359
+ }, e.key))
360
+ })] });
361
+ }
362
+ export { S as a, D as c, O as d, b as i, T as l, N as n, E as o, x as r, w as s, U as t, k as u };
@@ -5,4 +5,4 @@ export { KolmoSurface, KolmoProp, togglePropJoint, type KolmoSurfaceProps, type
5
5
  export { KolmoIsland, computeIslandSpawnPose, getCachedIslandPlan, type IslandSpawnPose, type KolmoIslandProps, } from "./kolmoIsland.js";
6
6
  export { KolmoLongDrive, computeLongDriveBridgeheadSpawn, computeLongDriveMainlandSpawn, type KolmoLongDriveProps, } from "./kolmoLongDrive.js";
7
7
  export { ShiftedFixedBody } from "./mainlandMacroCell.js";
8
- export { kolmoWorld, kolmoActions, kolmoTelemetry, VehicleTrait, ActorTrait, InteractableTrait, FloatingBodyTrait, PilotLink, WorldSessionTrait, type KolmoControlMode, type KolmoTelemetryState, } from "./kolmoStore.js";
8
+ export { kolmoWorld, kolmoActions, kolmoTelemetry, useActiveKolmoWorld, ensureWorldSession, VehicleTrait, ActorTrait, InteractableTrait, FloatingBodyTrait, PilotLink, WorldSessionTrait, type KolmoControlMode, type KolmoTelemetryState, } from "./kolmoStore.js";
@@ -1,3 +1,3 @@
1
- import { C as e, S as t, T as n, _ as r, a as i, b as a, c as o, d as s, f as c, g as l, h as u, i as d, l as f, m as p, n as m, o as h, p as g, r as _, s as v, t as y, u as b, v as x, w as S, x as C, y as w } from "../engine-BiMeAPAi.js";
2
- import { n as T, r as E, t as D } from "../kolmoSurface-DTnrFXH0.js";
3
- export { p as ActorTrait, u as FloatingBodyTrait, l as InteractableTrait, b as KOLMO_KEY_MAP, o as KolmoActor, s as KolmoCanvas, c as KolmoGravityContext, i as KolmoIsland, y as KolmoLongDrive, D as KolmoProp, T as KolmoSurface, f as KolmoVehicle, g as KolmoWorld, r as PilotLink, e as RetroViewportSync, S as RoomEnvRig, n as ShadowSnapRig, d as ShiftedFixedBody, x as VehicleTrait, w as WorldSessionTrait, h as computeIslandSpawnPose, m as computeLongDriveBridgeheadSpawn, _ as computeLongDriveMainlandSpawn, v as getCachedIslandPlan, a as kolmoActions, C as kolmoTelemetry, t as kolmoWorld, E as togglePropJoint };
1
+ import { C as e, D as t, E as n, S as r, T as i, _ as a, a as o, b as s, c, d as l, f as u, g as d, h as f, i as p, l as m, m as h, n as g, o as _, p as v, r as y, s as b, t as x, u as S, v as C, w, x as T, y as E } from "../engine-BeKvBM8d.js";
2
+ import { n as D, r as O, t as k } from "../kolmoSurface-DTnrFXH0.js";
3
+ export { h as ActorTrait, f as FloatingBodyTrait, d as InteractableTrait, S as KOLMO_KEY_MAP, c as KolmoActor, l as KolmoCanvas, u as KolmoGravityContext, o as KolmoIsland, x as KolmoLongDrive, k as KolmoProp, D as KolmoSurface, m as KolmoVehicle, v as KolmoWorld, a as PilotLink, i as RetroViewportSync, n as RoomEnvRig, t as ShadowSnapRig, p as ShiftedFixedBody, C as VehicleTrait, E as WorldSessionTrait, _ as computeIslandSpawnPose, g as computeLongDriveBridgeheadSpawn, y as computeLongDriveMainlandSpawn, s as ensureWorldSession, b as getCachedIslandPlan, T as kolmoActions, r as kolmoTelemetry, e as kolmoWorld, O as togglePropJoint, w as useActiveKolmoWorld };
@@ -1,3 +1,4 @@
1
+ import { type World } from "koota";
1
2
  import type { EcctrlHandle } from "@pinkaphant/ecctrl";
2
3
  import type { EcctrlVehicleHandle } from "@pinkaphant/ecctrl/vehicle";
3
4
  import { type RetroPresetId } from "../shaders/index.js";
@@ -18,18 +19,16 @@ export interface ActorTraitData {
18
19
  exitSpawnYaw: number;
19
20
  exitLinVel: [number, number, number] | null;
20
21
  }
21
- export interface InteractableTraitData {
22
+ /** AoS trait holding live EcctrlVehicle handle & offsets. */
23
+ export declare const VehicleTrait: import("koota").Trait<() => VehicleTraitData>;
24
+ /** AoS trait holding live Ecctrl character handle & exit momentum. */
25
+ export declare const ActorTrait: import("koota").Trait<() => ActorTraitData>;
26
+ /** True SoA scalar schema trait (`trait({ ... })`) for fast proximity queries. */
27
+ export declare const InteractableTrait: import("koota").Trait<{
22
28
  id: string;
23
29
  radius: number;
24
30
  kind: "vehicle" | "prop";
25
- }
26
- export interface WorldSessionData {
27
- activeVehicleId: string | null;
28
- activeRetroPreset: RetroPresetId;
29
- }
30
- export declare const VehicleTrait: import("koota").Trait<() => VehicleTraitData>;
31
- export declare const ActorTrait: import("koota").Trait<() => ActorTraitData>;
32
- export declare const InteractableTrait: import("koota").Trait<() => InteractableTraitData>;
31
+ }>;
33
32
  export interface FloatingBodyTraitData {
34
33
  id: string;
35
34
  getBody: () => {
@@ -47,8 +46,15 @@ export interface FloatingBodyTraitData {
47
46
  }
48
47
  export declare const FloatingBodyTrait: import("koota").Trait<() => FloatingBodyTraitData>;
49
48
  export declare const PilotLink: import("koota").Relation<import("koota").Trait<Record<string, never>>>;
50
- export declare const WorldSessionTrait: import("koota").Trait<() => WorldSessionData>;
51
- export declare const kolmoWorld: import("koota").World;
49
+ /** True SoA world trait attached automatically to any custom `world` passed to `<KolmoWorld>`. */
50
+ export declare const WorldSessionTrait: import("koota").Trait<{
51
+ activeVehicleId: string;
52
+ activeRetroPreset: RetroPresetId;
53
+ }>;
54
+ export declare const kolmoWorld: World;
55
+ /** Safely resolves the active Koota `World` from `<WorldProvider>` (falling back to `kolmoWorld` when rendered standalone in tests). */
56
+ export declare function useActiveKolmoWorld(): World;
57
+ export declare function ensureWorldSession(w: World): void;
52
58
  export interface KolmoTelemetryState {
53
59
  speedKmh: number;
54
60
  rpm: number;