@pinkaphant/kolmo 0.1.2 → 0.1.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.
Files changed (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -14
  3. package/bin/kolmo.mjs +19 -53
  4. package/dist/body/HeldItem.js +171 -0
  5. package/dist/body/KhrBody.js +179 -0
  6. package/dist/body/bodySi.d.ts +2 -2
  7. package/dist/body/bodySi.js +61 -0
  8. package/dist/body/index.js +4 -1
  9. package/dist/engine/index.d.ts +4 -4
  10. package/dist/engine/index.js +12 -3
  11. package/dist/engine/kolmoActor.d.ts +11 -4
  12. package/dist/engine/kolmoActor.js +197 -0
  13. package/dist/engine/kolmoInput.d.ts +12 -0
  14. package/dist/engine/kolmoInput.js +80 -0
  15. package/dist/engine/kolmoIsland.d.ts +3 -1
  16. package/dist/engine/kolmoIsland.js +311 -0
  17. package/dist/engine/kolmoLongDrive.js +223 -0
  18. package/dist/engine/kolmoRigs.js +59 -0
  19. package/dist/engine/kolmoStore.d.ts +53 -27
  20. package/dist/engine/kolmoStore.js +211 -0
  21. package/dist/engine/kolmoSurface.d.ts +1 -1
  22. package/dist/engine/kolmoSurface.js +182 -0
  23. package/dist/engine/kolmoVehicle.d.ts +2 -1
  24. package/dist/engine/kolmoVehicle.js +244 -0
  25. package/dist/engine/kolmoVehicleDriver.d.ts +30 -0
  26. package/dist/engine/kolmoVehicleDriver.js +38 -0
  27. package/dist/engine/kolmoWorld.d.ts +7 -15
  28. package/dist/engine/kolmoWorld.js +136 -0
  29. package/dist/engine/longDriveKit.d.ts +4 -2
  30. package/dist/engine/longDriveKit.js +254 -0
  31. package/dist/engine/mainlandMacroCell.d.ts +3 -7
  32. package/dist/engine/mainlandMacroCell.js +247 -0
  33. package/dist/engine/shiftedFixedBody.d.ts +13 -0
  34. package/dist/engine/shiftedFixedBody.js +64 -0
  35. package/dist/importer/ChopShopPanel.js +465 -0
  36. package/dist/importer/DomainWorkshopPanel.d.ts +9 -4
  37. package/dist/importer/DomainWorkshopPanel.js +385 -0
  38. package/dist/importer/GateHudBar.js +312 -0
  39. package/dist/importer/GlbImportGate.js +250 -0
  40. package/dist/importer/ImperativeVehicleRig.js +336 -0
  41. package/dist/importer/ImporterPlinthUikitTags.js +112 -0
  42. package/dist/importer/Step1CalibrationPlinth.js +275 -0
  43. package/dist/importer/Step2UniversalPad.js +244 -0
  44. package/dist/importer/VfxEmitterPool.js +91 -0
  45. package/dist/importer/chopShopActions.d.ts +22 -2
  46. package/dist/importer/chopShopActions.js +232 -0
  47. package/dist/importer/gateStore.d.ts +1 -1
  48. package/dist/importer/gateStore.js +92 -0
  49. package/dist/importer/glbNormalizer.js +133 -0
  50. package/dist/importer/importerWebMcp.d.ts +17 -6
  51. package/dist/importer/importerWebMcp.js +343 -0
  52. package/dist/importer/index.js +22 -3
  53. package/dist/importer/khrCompiler.d.ts +1 -1
  54. package/dist/importer/khrCompiler.js +434 -0
  55. package/dist/importer/launcherBake.js +51 -0
  56. package/dist/importer/meshIslands.d.ts +1 -1
  57. package/dist/importer/meshIslands.js +301 -0
  58. package/dist/importer/surfaceCutter.js +254 -0
  59. package/dist/importer/surfaceTopology.js +183 -0
  60. package/dist/importer/universalGateBake.js +162 -0
  61. package/dist/importer/usdToGlb.js +294 -0
  62. package/dist/importer/useChopShopController.d.ts +11 -2
  63. package/dist/importer/useChopShopController.js +364 -0
  64. package/dist/importer/vehiclePanelAnim.js +214 -0
  65. package/dist/importer/wheelAxlePairing.d.ts +1 -2
  66. package/dist/importer/wheelAxlePairing.js +102 -0
  67. package/dist/index.d.ts +1 -1
  68. package/dist/index.js +69 -13
  69. package/dist/junk/DestructibleTarget.js +154 -0
  70. package/dist/junk/KolmoJunk.js +65 -0
  71. package/dist/junk/ShardPieces.d.ts +6 -4
  72. package/dist/junk/ShardPieces.js +74 -0
  73. package/dist/junk/TargetDecals.js +51 -0
  74. package/dist/junk/bvhShatter.js +55 -0
  75. package/dist/junk/bvhTriCollector.js +78 -0
  76. package/dist/junk/index.js +11 -1
  77. package/dist/junk/junkGeometry.js +69 -0
  78. package/dist/junk/junkImportSanitize.js +54 -0
  79. package/dist/junk/junkImporter.js +95 -0
  80. package/dist/junk/junkLabelCanvas.js +67 -0
  81. package/dist/junk/junkLabels.js +35 -0
  82. package/dist/junk/targetHelpers.js +103 -0
  83. package/dist/junk/targetHitLogic.js +128 -0
  84. package/dist/junk/useTargetAssets.js +102 -0
  85. package/dist/physics/index.d.ts +26 -0
  86. package/dist/physics/index.js +84 -0
  87. package/dist/schema/kolmoSchema.d.ts +2 -1
  88. package/dist/schema/kolmoSchema.js +184 -0
  89. package/dist/shaders/celestialBackdrop.d.ts +1 -1
  90. package/dist/shaders/celestialBackdrop.js +344 -0
  91. package/dist/shaders/index.d.ts +0 -1
  92. package/dist/shaders/index.js +9 -1
  93. package/dist/shaders/plumeAndSparkle.js +271 -0
  94. package/dist/shaders/ps2GlslShared.d.ts +1 -1
  95. package/dist/shaders/ps2GlslShared.js +3 -0
  96. package/dist/shaders/ps2MaterialsTSL.js +65 -0
  97. package/dist/shaders/ps2MaterialsWebGL.js +40 -0
  98. package/dist/shaders/ps2RoadWebGL.js +101 -0
  99. package/dist/shaders/ps2TerrainWebGL.js +54 -0
  100. package/dist/shaders/ps2Textures.js +224 -0
  101. package/dist/shaders/retroPalettes.js +188 -0
  102. package/dist/shaders/retroShader.d.ts +31 -3
  103. package/dist/shaders/retroShader.js +249 -0
  104. package/dist/shaders/tsl.d.ts +1 -0
  105. package/dist/shaders/tsl.js +1 -0
  106. package/dist/vite/index.d.ts +15 -0
  107. package/dist/vite/index.js +90 -0
  108. package/dist/world/frontage.js +32 -0
  109. package/dist/world/index.d.ts +1 -1
  110. package/dist/world/index.js +11 -3
  111. package/dist/world/infiniteWorld2D.js +244 -0
  112. package/dist/world/island.js +201 -0
  113. package/dist/world/macroCellSchema.js +27 -0
  114. package/dist/world/macroKnightAStar.js +171 -0
  115. package/dist/world/random.js +33 -0
  116. package/dist/world/road.js +136 -0
  117. package/dist/world/roadRibbon.d.ts +6 -6
  118. package/dist/world/roadRibbon.js +161 -0
  119. package/dist/world/terrain.js +87 -0
  120. package/dist/world/worldTypes.js +111 -0
  121. package/package.json +32 -18
  122. package/dist/body-B7FTf67o.js +0 -362
  123. package/dist/engine-BeKvBM8d.js +0 -1745
  124. package/dist/importer-B2-S-N_e.js +0 -5113
  125. package/dist/junk-B4bC1zAl.js +0 -1049
  126. package/dist/kolmoSurface-DTnrFXH0.js +0 -558
  127. package/dist/shaders-GS71Ek1A.js +0 -1383
  128. package/dist/world-PRWPYrlx.js +0 -947
  129. package/dist/worldTypes-Z0KfdCd0.js +0 -226
@@ -1,8 +1,8 @@
1
- export { KolmoCanvas, KolmoWorld, KolmoGravityContext, KOLMO_KEY_MAP, RetroViewportSync, RoomEnvRig, ShadowSnapRig, type RetroViewportSyncProps, type RoomEnvRigProps, type KolmoCanvasProps, type KolmoWorldProps, type KolmoGravitySpec, type KolmoGravityCallback, type KolmoPointGravity, type KolmoKeyAction, } from "./kolmoWorld.js";
1
+ export { EMPTY_KOLMO_INPUT, KOLMO_KEY_MAP, KolmoCanvas, KolmoGravityContext, KolmoPhysics, KolmoWorld, RetroViewportSync, RoomEnvRig, ShadowSnapRig, useIsKolmoCustomGravity, useKolmoInput, useOptionalKootaWorld, type KolmoCanvasProps, type KolmoGravityCallback, type KolmoGravitySpec, type KolmoInputGetter, type KolmoInputState, type KolmoKeyAction, type KolmoPhysicsProps, type KolmoPointGravity, type KolmoTimeControlValue, type KolmoWorldProps, type RetroViewportSyncProps, type RoomEnvRigProps, } from "./kolmoWorld.js";
2
2
  export { KolmoVehicle, type KolmoVehicleProps } from "./kolmoVehicle.js";
3
3
  export { KolmoActor, type KolmoActorProps } from "./kolmoActor.js";
4
- export { KolmoSurface, KolmoProp, togglePropJoint, type KolmoSurfaceProps, type KolmoPropProps, } from "./kolmoSurface.js";
4
+ export { KolmoProp, KolmoSurface, togglePropJoint, type KolmoPropProps, type KolmoSurfaceProps, } from "./kolmoSurface.js";
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
- export { ShiftedFixedBody } from "./mainlandMacroCell.js";
8
- export { kolmoWorld, kolmoActions, kolmoTelemetry, useActiveKolmoWorld, ensureWorldSession, VehicleTrait, ActorTrait, InteractableTrait, FloatingBodyTrait, PilotLink, WorldSessionTrait, type KolmoControlMode, type KolmoTelemetryState, } from "./kolmoStore.js";
7
+ export { ShiftedFixedBody, type ShiftedFixedBodyProps } from "./mainlandMacroCell.js";
8
+ export { ActorTrait, FloatingBodyTrait, InteractableTrait, PilotLink, VehicleTrait, WorldSessionTrait, ensureWorldSession, kolmoActions, kolmoTelemetry, kolmoWorld, readFloatingOriginAnchorXZ, shiftFloatingOriginEntities, useActiveKolmoWorld, useWorldTrait, type FloatingOriginRapierSync, type KolmoControlMode, type KolmoTelemetryState, } from "./kolmoStore.js";
@@ -1,3 +1,12 @@
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
+ import { KolmoGravityContext as e, KolmoPhysics as t, useIsKolmoCustomGravity as n, useOptionalKootaWorld as r } from "../physics/index.js";
2
+ import { EMPTY_KOLMO_INPUT as i, KOLMO_KEY_MAP as a, useKolmoInput as o } from "./kolmoInput.js";
3
+ import { RetroViewportSync as s, RoomEnvRig as c, ShadowSnapRig as l } from "./kolmoRigs.js";
4
+ import { KolmoCanvas as u, KolmoWorld as d } from "./kolmoWorld.js";
5
+ import { KolmoVehicle as f } from "./kolmoVehicle.js";
6
+ import { KolmoActor as p } from "./kolmoActor.js";
7
+ import { KolmoProp as m, KolmoSurface as h, togglePropJoint as g } from "./kolmoSurface.js";
8
+ import { KolmoIsland as _, computeIslandSpawnPose as v, getCachedIslandPlan as y } from "./kolmoIsland.js";
9
+ import { KolmoLongDrive as b, computeLongDriveBridgeheadSpawn as x, computeLongDriveMainlandSpawn as S } from "./kolmoLongDrive.js";
10
+ import { ShiftedFixedBody as C } from "./shiftedFixedBody.js";
11
+ import { ActorTrait as w, FloatingBodyTrait as T, InteractableTrait as E, PilotLink as D, VehicleTrait as O, WorldSessionTrait as k, ensureWorldSession as A, kolmoActions as j, kolmoTelemetry as M, kolmoWorld as N, readFloatingOriginAnchorXZ as P, shiftFloatingOriginEntities as F, useActiveKolmoWorld as I, useWorldTrait as L } from "./kolmoStore.js";
12
+ export { w as ActorTrait, i as EMPTY_KOLMO_INPUT, T as FloatingBodyTrait, E as InteractableTrait, a as KOLMO_KEY_MAP, p as KolmoActor, u as KolmoCanvas, e as KolmoGravityContext, _ as KolmoIsland, b as KolmoLongDrive, t as KolmoPhysics, m as KolmoProp, h as KolmoSurface, f as KolmoVehicle, d as KolmoWorld, D as PilotLink, s as RetroViewportSync, c as RoomEnvRig, l as ShadowSnapRig, C as ShiftedFixedBody, O as VehicleTrait, k as WorldSessionTrait, v as computeIslandSpawnPose, x as computeLongDriveBridgeheadSpawn, S as computeLongDriveMainlandSpawn, A as ensureWorldSession, y as getCachedIslandPlan, j as kolmoActions, M as kolmoTelemetry, N as kolmoWorld, P as readFloatingOriginAnchorXZ, F as shiftFloatingOriginEntities, g as togglePropJoint, I as useActiveKolmoWorld, n as useIsKolmoCustomGravity, o as useKolmoInput, r as useOptionalKootaWorld, L as useWorldTrait };
@@ -1,6 +1,13 @@
1
- import React from "react";
1
+ import React, { type ComponentProps, type ReactNode } from "react";
2
+ import { type EcctrlProps } from "@pinkaphant/ecctrl";
3
+ import { EcctrlCameraControls } from "@pinkaphant/ecctrl/camera";
4
+ import { type KolmoInputGetter } from "./kolmoInput.js";
2
5
  export interface KolmoActorProps {
3
- position?: [number, number, number];
4
- enabled?: boolean;
6
+ readonly position?: [number, number, number];
7
+ readonly enabled?: boolean;
8
+ readonly getInput?: KolmoInputGetter;
9
+ readonly ecctrlProps?: Omit<EcctrlProps, "ref">;
10
+ readonly cameraProps?: Omit<ComponentProps<typeof EcctrlCameraControls>, "ref"> | null | false;
11
+ readonly children?: ReactNode;
5
12
  }
6
- export declare function KolmoActor({ position, enabled }: KolmoActorProps): React.JSX.Element | null;
13
+ export declare function KolmoActor({ position, enabled, getInput, ecctrlProps, cameraProps, children, }: KolmoActorProps): React.JSX.Element | null;
@@ -0,0 +1,197 @@
1
+ import { KolmoGravityContext as e } from "../physics/index.js";
2
+ import { applyRetroMaterial as t } from "../shaders/retroShader.js";
3
+ import { useKolmoInput as n } from "./kolmoInput.js";
4
+ import { ActorTrait as r, InteractableTrait as i, VehicleTrait as a, WorldSessionTrait as o, ensureWorldSession as s, kolmoActions as c, kolmoTelemetry as l, useActiveKolmoWorld as u, useWorldTrait as d } from "./kolmoStore.js";
5
+ import { useCallback as f, useContext as p, useLayoutEffect as m, useMemo as h, useRef as g } from "react";
6
+ import * as _ from "three";
7
+ import { useFrame as v, useThree as y } from "@react-three/fiber";
8
+ import { Fragment as b, jsx as x, jsxs as S } from "react/jsx-runtime";
9
+ import { Ecctrl as C } from "@pinkaphant/ecctrl";
10
+ import { EcctrlCameraControls as w } from "@pinkaphant/ecctrl/camera";
11
+ // src/engine/kolmoActor.tsx
12
+ var T = new _.Vector3(), E = new _.Vector3(), D = new _.Vector3();
13
+ function O() {
14
+ let e = h(() => ({
15
+ suitGeo: new _.CapsuleGeometry(.28, .56, 6, 12),
16
+ visorGeo: new _.BoxGeometry(.34, .16, .14),
17
+ packGeo: new _.BoxGeometry(.32, .42, .16),
18
+ suitMat: t(new _.MeshStandardMaterial({
19
+ color: "#e2e8f0",
20
+ roughness: .55,
21
+ metalness: .15
22
+ })),
23
+ visorMat: t(new _.MeshStandardMaterial({
24
+ color: "#38bdf8",
25
+ emissive: "#0284c7",
26
+ emissiveIntensity: .55,
27
+ roughness: .2
28
+ })),
29
+ packMat: t(new _.MeshStandardMaterial({
30
+ color: "#334155",
31
+ roughness: .7
32
+ }))
33
+ }), []);
34
+ return m(() => () => {
35
+ e.suitGeo.dispose(), e.visorGeo.dispose(), e.packGeo.dispose(), e.suitMat.dispose(), e.visorMat.dispose(), e.packMat.dispose();
36
+ }, [e]), /* @__PURE__ */ S("group", { children: [
37
+ /* @__PURE__ */ x("mesh", {
38
+ castShadow: !0,
39
+ geometry: e.suitGeo,
40
+ material: e.suitMat
41
+ }),
42
+ /* @__PURE__ */ x("mesh", {
43
+ position: [
44
+ 0,
45
+ .24,
46
+ .22
47
+ ],
48
+ geometry: e.visorGeo,
49
+ material: e.visorMat
50
+ }),
51
+ /* @__PURE__ */ x("mesh", {
52
+ position: [
53
+ 0,
54
+ .06,
55
+ -.24
56
+ ],
57
+ castShadow: !0,
58
+ geometry: e.packGeo,
59
+ material: e.packMat
60
+ })
61
+ ] });
62
+ }
63
+ function k({ position: t = [
64
+ 0,
65
+ 1.4,
66
+ 0
67
+ ], enabled: k = !0, getInput: A, ecctrlProps: j, cameraProps: M, children: N }) {
68
+ let P = p(e), F = u();
69
+ m(() => {
70
+ s(F);
71
+ }, [F]);
72
+ let I = d(F, o), L = n(A), R = y((e) => typeof e.gl?.domElement?.setAttribute == "function"), z = g(null), B = g(null), V = g(new _.Vector3()), H = g(new _.Vector3(0, 1, 0)), U = g(!1), W = g(0), G = g({
73
+ pos: null,
74
+ yaw: 0
75
+ }), K = g(null), q = g({
76
+ forward: !1,
77
+ backward: !1,
78
+ leftward: !1,
79
+ rightward: !1,
80
+ run: !1,
81
+ jump: !1
82
+ }), J = f((e, t) => {
83
+ V.current.x -= e, V.current.z -= t, z.current && (z.current.currPos.x -= e, z.current.currPos.z -= t);
84
+ let n = B.current;
85
+ n?.getPosition && n?.getTarget && n?.setLookAt && (n.getPosition(E), n.getTarget(D), n.setLookAt(E.x - e, E.y, E.z - t, D.x - e, D.y, D.z - t, !1));
86
+ }, []);
87
+ m(() => {
88
+ let e = F.spawn(r({
89
+ id: "pilot",
90
+ handle: z.current,
91
+ exitSpawnPos: null,
92
+ exitSpawnYaw: 0,
93
+ exitLinVel: null,
94
+ onOriginShift: J
95
+ })), t = F.onChange(r, (t) => {
96
+ if (t !== e) return;
97
+ let n = e.get(r);
98
+ n && (G.current = {
99
+ pos: n.exitSpawnPos,
100
+ yaw: n.exitSpawnYaw
101
+ });
102
+ });
103
+ return () => {
104
+ t(), e.destroy();
105
+ };
106
+ }, [F, J]);
107
+ let Y = f((e) => {
108
+ z.current = e;
109
+ let t = F.queryFirst(r);
110
+ if (!t) return;
111
+ let n = t.get(r);
112
+ e?.body && n?.exitLinVel && e.body.setLinvel({
113
+ x: n.exitLinVel[0],
114
+ y: n.exitLinVel[1],
115
+ z: n.exitLinVel[2]
116
+ }, !0), e?.body && (G.current.pos = null), t.set(r, {
117
+ id: n?.id ?? "pilot",
118
+ handle: e,
119
+ exitSpawnPos: e?.body ? null : n?.exitSpawnPos ?? null,
120
+ exitSpawnYaw: n?.exitSpawnYaw ?? 0,
121
+ exitLinVel: e?.body ? null : n?.exitLinVel ?? null,
122
+ onOriginShift: J
123
+ });
124
+ }, [F, J]), X = I?.activeVehicleId || "", Z = k && !X;
125
+ if (!Z) K.current = null;
126
+ else if (!K.current) {
127
+ let e = G.current.pos ?? j?.position ?? t, n = j?.rotation ?? [
128
+ 0,
129
+ G.current.yaw,
130
+ 0
131
+ ];
132
+ K.current = {
133
+ pos: [
134
+ e[0],
135
+ e[1],
136
+ e[2]
137
+ ],
138
+ rot: [
139
+ n[0],
140
+ n[1],
141
+ n[2]
142
+ ]
143
+ };
144
+ }
145
+ let Q = h(() => {
146
+ let e = j?.userData ?? {}, t = e.ecctrl ?? {};
147
+ return {
148
+ ...e,
149
+ ecctrl: {
150
+ excludeVehicleRay: !0,
151
+ ...t
152
+ }
153
+ };
154
+ }, [j?.userData]);
155
+ return v((e, t) => {
156
+ if (!k) return;
157
+ let n = Math.min(Math.max(t, 1e-4), .05);
158
+ W.current > 0 && (W.current = Math.max(0, W.current - n));
159
+ let r = L(), o = r.interact && !U.current;
160
+ if (U.current = r.interact, X) {
161
+ o && W.current === 0 && (W.current = .25, c(F).exitVehicle());
162
+ return;
163
+ }
164
+ let s = z.current;
165
+ if (!s || !s.body) return;
166
+ let u = q.current;
167
+ u.forward = r.forward, u.backward = r.backward, u.leftward = r.left, u.rightward = r.right, u.run = r.boost, u.jump = r.brake, s.setMovement(u), l.mode = "foot", l.speedKmh = s.moveSpeed * 3.6, l.rpm = 0, l.gear = 0, l.throttle = +!!s.isMoving, l.boost = r.boost && s.isMoving ? 1 : 0;
168
+ let d = null, f = Infinity;
169
+ for (let e of F.query(a, i)) {
170
+ let t = e.get(a), n = e.get(i);
171
+ if (!t?.handle || !n) continue;
172
+ T.set(t.seatOffset[0] - t.centerOfMass[0], t.seatOffset[1] - t.centerOfMass[1], t.seatOffset[2] - t.centerOfMass[2]).applyQuaternion(t.handle.currQuat).add(t.handle.currPos);
173
+ let r = s.currPos.distanceToSquared(T);
174
+ r <= n.radius * n.radius && r < f && (f = r, d = t.id);
175
+ }
176
+ l.nearVehicleId = d, o && d && W.current === 0 ? (W.current = .25, c(F).boardVehicle(d)) : B.current && s.currPos.lengthSq() > 0 && (V.current.copy(s.currPos).addScaledVector(s.bodyYAxis, .55), H.current.copy(s.upAxis), B.current.moveTo(V.current.x, V.current.y, V.current.z, !0), e.camera.up.lerp(H.current, .14), B.current.setUp(e.camera.up));
177
+ }), Z ? /* @__PURE__ */ S(b, { children: [R && M !== !1 && M !== null && /* @__PURE__ */ x(w, {
178
+ ref: B,
179
+ makeDefault: !0,
180
+ minPolarAngle: .12,
181
+ maxPolarAngle: Math.PI - .12,
182
+ smoothTime: .08,
183
+ ...M ?? {}
184
+ }), /* @__PURE__ */ x(C, {
185
+ ref: Y,
186
+ enableCustomGravity: P,
187
+ maxWalkVel: 3.2,
188
+ maxRunVel: 7.2,
189
+ jumpVel: 5.8,
190
+ ...j,
191
+ position: K.current.pos,
192
+ rotation: K.current.rot,
193
+ userData: Q,
194
+ children: N ?? /* @__PURE__ */ x(O, {})
195
+ })] }) : null;
196
+ }
197
+ export { k as KolmoActor };
@@ -0,0 +1,12 @@
1
+ import { type KeyboardControlsEntry } from "@react-three/drei";
2
+ export type KolmoKeyAction = "forward" | "backward" | "left" | "right" | "brake" | "boost" | "interact" | "turnLeft" | "turnRight" | "descend" | "cameraView";
3
+ export type KolmoInputState = Record<KolmoKeyAction, boolean>;
4
+ export type KolmoInputGetter = () => Partial<KolmoInputState>;
5
+ export declare const EMPTY_KOLMO_INPUT: Readonly<KolmoInputState>;
6
+ export declare const KOLMO_KEY_MAP: KeyboardControlsEntry<KolmoKeyAction>[];
7
+ /**
8
+ * Safe zero-allocation input reader that falls back cleanly to `EMPTY_KOLMO_INPUT`
9
+ * when `<KeyboardControls>` is omitted (`keyboardMap={null}` or `<KolmoPhysics>`),
10
+ * and merges optional caller `getInput()` overrides.
11
+ */
12
+ export declare function useKolmoInput(getInput?: KolmoInputGetter): () => Readonly<KolmoInputState>;
@@ -0,0 +1,80 @@
1
+ import { useCallback as e, useRef as t } from "react";
2
+ import { useKeyboardControls as n } from "@react-three/drei";
3
+ // src/engine/kolmoInput.ts
4
+ var r = Object.freeze({
5
+ forward: !1,
6
+ backward: !1,
7
+ left: !1,
8
+ right: !1,
9
+ brake: !1,
10
+ boost: !1,
11
+ interact: !1,
12
+ turnLeft: !1,
13
+ turnRight: !1,
14
+ descend: !1,
15
+ cameraView: !1
16
+ }), i = [
17
+ {
18
+ name: "forward",
19
+ keys: ["KeyW", "ArrowUp"]
20
+ },
21
+ {
22
+ name: "backward",
23
+ keys: ["KeyS", "ArrowDown"]
24
+ },
25
+ {
26
+ name: "left",
27
+ keys: ["KeyA", "ArrowLeft"]
28
+ },
29
+ {
30
+ name: "right",
31
+ keys: ["KeyD", "ArrowRight"]
32
+ },
33
+ {
34
+ name: "brake",
35
+ keys: ["Space"]
36
+ },
37
+ {
38
+ name: "boost",
39
+ keys: ["ShiftLeft", "ShiftRight"]
40
+ },
41
+ {
42
+ name: "interact",
43
+ keys: ["KeyF", "KeyE"]
44
+ },
45
+ {
46
+ name: "turnLeft",
47
+ keys: ["KeyQ"]
48
+ },
49
+ {
50
+ name: "turnRight",
51
+ keys: ["KeyC"]
52
+ },
53
+ {
54
+ name: "descend",
55
+ keys: ["KeyX", "ControlLeft"]
56
+ },
57
+ {
58
+ name: "cameraView",
59
+ keys: ["KeyV"]
60
+ }
61
+ ];
62
+ function a(i) {
63
+ let a = null;
64
+ try {
65
+ let [, e] = n();
66
+ a = e;
67
+ } catch {
68
+ a = null;
69
+ }
70
+ let o = t(i);
71
+ o.current = i;
72
+ let s = t({ ...r });
73
+ return e(() => {
74
+ let e = o.current?.();
75
+ if (!a && !e) return r;
76
+ let t = a ? a() : r, n = s.current;
77
+ return n.forward = !!(e?.forward ?? t.forward), n.backward = !!(e?.backward ?? t.backward), n.left = !!(e?.left ?? t.left), n.right = !!(e?.right ?? t.right), n.brake = !!(e?.brake ?? t.brake), n.boost = !!(e?.boost ?? t.boost), n.interact = !!(e?.interact ?? t.interact), n.turnLeft = !!(e?.turnLeft ?? t.turnLeft), n.turnRight = !!(e?.turnRight ?? t.turnRight), n.descend = !!(e?.descend ?? t.descend), n.cameraView = !!(e?.cameraView ?? t.cameraView), n;
78
+ }, [a]);
79
+ }
80
+ export { r as EMPTY_KOLMO_INPUT, i as KOLMO_KEY_MAP, a as useKolmoInput };
@@ -13,5 +13,7 @@ export interface KolmoIslandProps {
13
13
  readonly size?: number;
14
14
  readonly segments?: number;
15
15
  readonly settlementTier?: SettlementTier;
16
+ readonly offX?: number;
17
+ readonly offZ?: number;
16
18
  }
17
- export declare function KolmoIsland({ seed, size, segments, settlementTier, }: KolmoIslandProps): React.JSX.Element;
19
+ export declare function KolmoIsland({ seed, size, segments, settlementTier, offX, offZ, }: KolmoIslandProps): React.JSX.Element;
@@ -0,0 +1,311 @@
1
+ import { createPS2RoadMaterialWebGL as e } from "../shaders/ps2RoadWebGL.js";
2
+ import { createPS2TerrainMaterialWebGL as t } from "../shaders/ps2TerrainWebGL.js";
3
+ import { createPS2WorldTextures as n } from "../shaders/ps2Textures.js";
4
+ import { applyRetroMaterial as r } from "../shaders/retroShader.js";
5
+ import { bakeWorldSplatMaps as i } from "../world/worldTypes.js";
6
+ import { buildCarvedTerrainGeometry as a, buildRoadRibbonGeometry as o, planDirtSpurs as s } from "../world/roadRibbon.js";
7
+ import { childSeed as c, mulberry32 as l } from "../world/random.js";
8
+ import { planIslandWorld as u } from "../world/island.js";
9
+ import { ShiftedFixedBody as d } from "./shiftedFixedBody.js";
10
+ import { useEffect as f, useLayoutEffect as p, useMemo as m, useRef as h } from "react";
11
+ import * as g from "three";
12
+ import { jsx as _, jsxs as v } from "react/jsx-runtime";
13
+ import { CuboidCollider as y, TrimeshCollider as b } from "@react-three/rapier";
14
+ import { instanceBatches as x, planSettlement as S, poseToFloat as C } from "@khr3/c12";
15
+ import { mergeGeometries as w } from "three/examples/jsm/utils/BufferGeometryUtils.js";
16
+ // src/engine/kolmoIsland.tsx
17
+ var T = /* @__PURE__ */ new Map();
18
+ function E(e = 77, t = 960) {
19
+ let n = `${e}:${t}`, r = T.get(n);
20
+ return r || (r = u(e, { size: t }), T.set(n, r)), r;
21
+ }
22
+ function D(e = 77, t = 960) {
23
+ let n = E(e, t), r = n.road.at(n.road.length * .48), i = Math.atan2(r.tangent[0], r.tangent[2]);
24
+ return {
25
+ vehiclePos: [
26
+ r.pos[0],
27
+ r.pos[1] + .45,
28
+ r.pos[2]
29
+ ],
30
+ vehicleRot: [
31
+ 0,
32
+ i,
33
+ 0
34
+ ],
35
+ actorPos: [
36
+ r.pos[0] + r.left[0] * (n.road.halfWidth + 2),
37
+ r.pos[1] + 1.5,
38
+ r.pos[2] + r.left[2] * (n.road.halfWidth + 2)
39
+ ]
40
+ };
41
+ }
42
+ function O(e) {
43
+ if (e === "FoundationSquare") {
44
+ let e = new g.BoxGeometry(3, .36, 3);
45
+ return e.translate(0, -.18, 0), {
46
+ geo: e,
47
+ color: "#64748b"
48
+ };
49
+ }
50
+ if (e === "Street") {
51
+ let e = new g.BoxGeometry(3, .14, 3);
52
+ return e.translate(0, .05, 0), {
53
+ geo: e,
54
+ color: "#475569"
55
+ };
56
+ }
57
+ if (e === "Wall") {
58
+ let e = new g.BoxGeometry(3, 3, .22);
59
+ return e.translate(0, 1.5, 0), {
60
+ geo: e,
61
+ color: "#cbd5e1"
62
+ };
63
+ }
64
+ if (e === "Doorway") {
65
+ let e = new g.BoxGeometry(1.05, 3, .24);
66
+ e.translate(-.975, 1.5, 0);
67
+ let t = new g.BoxGeometry(1.05, 3, .24);
68
+ t.translate(.975, 1.5, 0);
69
+ let n = new g.BoxGeometry(.9, .9, .24);
70
+ n.translate(0, 2.55, 0);
71
+ let r = w([
72
+ e,
73
+ t,
74
+ n
75
+ ], !1);
76
+ return e.dispose(), t.dispose(), n.dispose(), {
77
+ geo: r,
78
+ color: "#94a3b8"
79
+ };
80
+ }
81
+ if (e === "DoorLeaf") {
82
+ let e = new g.BoxGeometry(.9, 2.1, .1);
83
+ return e.translate(0, 1.05, 0), {
84
+ geo: e,
85
+ color: "#d97706"
86
+ };
87
+ }
88
+ if (e === "Stairs") {
89
+ let e = new g.BoxGeometry(1.4, .24, 3.8);
90
+ return e.rotateX(-Math.PI / 4), e.translate(0, 1.5, 0), {
91
+ geo: e,
92
+ color: "#a16207"
93
+ };
94
+ }
95
+ if (e === "Roof") {
96
+ let e = new g.BoxGeometry(3.16, .26, 3.16);
97
+ return e.translate(0, .13, 0), {
98
+ geo: e,
99
+ color: "#be123c"
100
+ };
101
+ }
102
+ let t = new g.BoxGeometry(3, .2, 3);
103
+ return t.translate(0, .1, 0), {
104
+ geo: t,
105
+ color: "#94a3b8"
106
+ };
107
+ }
108
+ function k({ matrices: e, count: t, geo: n, mat: r }) {
109
+ let i = h(null);
110
+ return p(() => {
111
+ let t = i.current;
112
+ t && (t.instanceMatrix.array.set(e), t.instanceMatrix.needsUpdate = !0, t.computeBoundingSphere());
113
+ }, [e, t]), /* @__PURE__ */ _("instancedMesh", {
114
+ ref: i,
115
+ args: [
116
+ n,
117
+ r,
118
+ t
119
+ ],
120
+ frustumCulled: !1
121
+ });
122
+ }
123
+ function A({ seed: u = 77, size: p = 960, segments: h = 160, settlementTier: w = "town", offX: T = 0, offZ: D = 0 }) {
124
+ let A = m(() => E(u, p), [u, p]), { spurs: j, junctions: M } = m(() => s(A, 2), [A]), N = m(() => i(A, 256, j), [A, j]), P = m(() => a(A.terrain, A.size, h), [A, h]), F = m(() => o(A.road, { tJunctions: M }), [A, M]), I = m(() => j.map((e) => o(e, { crownHeight: .03 })), [j]), L = m(() => S(A.road, w, u), [
125
+ A,
126
+ w,
127
+ u
128
+ ]), R = m(() => x(L.pieces), [L]), z = m(() => new g.PlaneGeometry(A.size * 1.8, A.size * 1.8), [A.size]), B = m(() => {
129
+ let i = n(N), { material: a, depthMaterial: o } = t(i, {
130
+ ditherTexelsPerMeter: 16,
131
+ ps2ColorQuantize: .85
132
+ }), { material: s } = e(i, {
133
+ preset: "ASPHALT",
134
+ ditherTexelsPerMeter: 16,
135
+ ps2ColorQuantize: .85
136
+ }), { material: c } = e(i, {
137
+ preset: "DIRT",
138
+ ditherTexelsPerMeter: 16,
139
+ ps2ColorQuantize: .85
140
+ }), l = new g.MeshLambertMaterial({
141
+ color: "#125274",
142
+ transparent: !0,
143
+ opacity: .84,
144
+ fog: !0
145
+ }), u = new g.MeshLambertMaterial({
146
+ color: "#2d4c24",
147
+ flatShading: !0,
148
+ fog: !0
149
+ });
150
+ return r(u, { flatShading: !0 }), {
151
+ tex: i,
152
+ terrainMat: a,
153
+ terrainDepthMat: o,
154
+ asphaltMat: s,
155
+ dirtMat: c,
156
+ waterMat: l,
157
+ treeMat: u
158
+ };
159
+ }, [N]), V = m(() => {
160
+ let e = /* @__PURE__ */ new Map();
161
+ for (let t of R) {
162
+ let { geo: n, color: i } = O(t.kind), a = new g.MeshStandardMaterial({
163
+ color: i,
164
+ roughness: .82,
165
+ flatShading: !0
166
+ });
167
+ r(a, { flatShading: !0 }), e.set(t.kind, {
168
+ geo: n,
169
+ mat: a
170
+ });
171
+ }
172
+ return e;
173
+ }, [R]), H = m(() => {
174
+ let e = l(c(u, "island-trees")), t = [], n = new g.Object3D(), r = L.buildings.map((e) => ({
175
+ p: C(e.pose).position,
176
+ r: Math.hypot(e.width, e.depth) * 2.2
177
+ }));
178
+ for (let i = 0; i < 950 && t.length < 3520; i++) {
179
+ let i = (e() - .5) * A.size * .82, a = (e() - .5) * A.size * .82, o = A.terrain.height(i, a);
180
+ if (o < A.waterLevel + 2.4 || o > 40 || A.terrain.roadMask(i, a).exclude || r.some((e) => Math.hypot(i - e.p[0], a - e.p[2]) < e.r)) continue;
181
+ let s = .85 + e() * .8;
182
+ n.position.set(i, o + 2.1 * s, a), n.rotation.set(0, e() * Math.PI * 2, 0), n.scale.set(s, s, s), n.updateMatrix(), t.push(...n.matrix.elements);
183
+ }
184
+ return {
185
+ geo: new g.ConeGeometry(1.5, 4.6, 6),
186
+ matrices: new Float32Array(t),
187
+ count: t.length / 16
188
+ };
189
+ }, [
190
+ A,
191
+ L,
192
+ u
193
+ ]);
194
+ return f(() => () => {
195
+ B.terrainMat.dispose(), B.terrainDepthMat.dispose(), B.asphaltMat.dispose(), B.dirtMat.dispose(), B.waterMat.dispose(), B.treeMat.dispose(), B.tex.dispose(), P.geometry.dispose(), F.geometry.dispose(), I.forEach((e) => e.geometry.dispose()), H.geo.dispose(), z.dispose();
196
+ for (let e of V.values()) e.geo.dispose(), e.mat.dispose();
197
+ }, [
198
+ B,
199
+ P,
200
+ F,
201
+ I,
202
+ H,
203
+ z,
204
+ V
205
+ ]), /* @__PURE__ */ v("group", { children: [
206
+ /* @__PURE__ */ _("fogExp2", {
207
+ attach: "fog",
208
+ args: [10335428, .00145]
209
+ }),
210
+ /* @__PURE__ */ _("hemisphereLight", { args: [
211
+ 11059416,
212
+ 5392440,
213
+ .72
214
+ ] }),
215
+ /* @__PURE__ */ v(d, {
216
+ x: T,
217
+ z: D,
218
+ friction: .9,
219
+ children: [/* @__PURE__ */ _(b, { args: [P.colliderVertices, P.colliderIndices] }), /* @__PURE__ */ _("mesh", {
220
+ geometry: P.geometry,
221
+ material: B.terrainMat,
222
+ customDepthMaterial: B.terrainDepthMat,
223
+ castShadow: !0,
224
+ receiveShadow: !0
225
+ })]
226
+ }),
227
+ /* @__PURE__ */ v(d, {
228
+ x: T,
229
+ z: D,
230
+ friction: 1.05,
231
+ children: [/* @__PURE__ */ _(b, { args: [F.colliderVertices, F.colliderIndices] }), /* @__PURE__ */ _("mesh", {
232
+ geometry: F.geometry,
233
+ material: B.asphaltMat,
234
+ receiveShadow: !0
235
+ })]
236
+ }),
237
+ I.map((e, t) => /* @__PURE__ */ v(d, {
238
+ x: T,
239
+ z: D,
240
+ friction: .85,
241
+ children: [/* @__PURE__ */ _(b, { args: [e.colliderVertices, e.colliderIndices] }), /* @__PURE__ */ _("mesh", {
242
+ geometry: e.geometry,
243
+ material: B.dirtMat,
244
+ receiveShadow: !0
245
+ })]
246
+ }, `spur_${t}`)),
247
+ /* @__PURE__ */ _(d, {
248
+ x: T,
249
+ z: D,
250
+ children: L.buildings.map((e) => {
251
+ let { position: t, yaw: n } = C(e.pose);
252
+ return /* @__PURE__ */ _(y, {
253
+ position: [
254
+ t[0],
255
+ t[1] + e.storeys * 1.5,
256
+ t[2]
257
+ ],
258
+ rotation: [
259
+ 0,
260
+ n,
261
+ 0
262
+ ],
263
+ args: [
264
+ e.width * 1.5,
265
+ e.storeys * 1.5,
266
+ e.depth * 1.5
267
+ ]
268
+ }, e.id);
269
+ })
270
+ }),
271
+ /* @__PURE__ */ v("group", {
272
+ position: [
273
+ T,
274
+ 0,
275
+ D
276
+ ],
277
+ children: [
278
+ /* @__PURE__ */ _("mesh", {
279
+ position: [
280
+ 0,
281
+ A.waterLevel,
282
+ 0
283
+ ],
284
+ rotation: [
285
+ -Math.PI * .5,
286
+ 0,
287
+ 0
288
+ ],
289
+ geometry: z,
290
+ material: B.waterMat
291
+ }),
292
+ R.map((e) => {
293
+ let t = V.get(e.kind);
294
+ return /* @__PURE__ */ _(k, {
295
+ matrices: e.matrices,
296
+ count: e.count,
297
+ geo: t.geo,
298
+ mat: t.mat
299
+ }, e.kind);
300
+ }),
301
+ H.count > 0 && /* @__PURE__ */ _(k, {
302
+ matrices: H.matrices,
303
+ count: H.count,
304
+ geo: H.geo,
305
+ mat: B.treeMat
306
+ })
307
+ ]
308
+ })
309
+ ] });
310
+ }
311
+ export { A as KolmoIsland, D as computeIslandSpawnPose, E as getCachedIslandPlan };