@pinkaphant/kolmo 0.2.3 → 0.3.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.
Files changed (61) hide show
  1. package/bin/kolmo.mjs +1 -1
  2. package/dist/engine/kolmoActor.js +125 -83
  3. package/dist/engine/kolmoLongDrive.js +136 -91
  4. package/dist/engine/kolmoStore.d.ts +6 -5
  5. package/dist/engine/kolmoStore.js +115 -79
  6. package/dist/engine/kolmoVehicle.d.ts +1 -1
  7. package/dist/engine/kolmoVehicle.js +160 -147
  8. package/dist/engine/kolmoVehicleDriver.d.ts +12 -4
  9. package/dist/engine/kolmoVehicleDriver.js +40 -20
  10. package/dist/engine/kolmoWorld.js +55 -35
  11. package/dist/importer/CabinPreviewRig.d.ts +13 -0
  12. package/dist/importer/CabinPreviewRig.js +138 -0
  13. package/dist/importer/CabinStepSection.d.ts +17 -0
  14. package/dist/importer/CabinStepSection.js +222 -0
  15. package/dist/importer/ChopShopPanel.d.ts +31 -1
  16. package/dist/importer/ChopShopPanel.js +474 -380
  17. package/dist/importer/GateHudBar.d.ts +3 -0
  18. package/dist/importer/GateHudBar.js +8 -2
  19. package/dist/importer/GlbImportGate.js +183 -147
  20. package/dist/importer/ImporterPlinthUikitTags.d.ts +2 -1
  21. package/dist/importer/ImporterPlinthUikitTags.js +23 -16
  22. package/dist/importer/Step1CalibrationPlinth.d.ts +10 -0
  23. package/dist/importer/Step1CalibrationPlinth.js +203 -141
  24. package/dist/importer/Step2UniversalPad.d.ts +8 -1
  25. package/dist/importer/Step2UniversalPad.js +112 -90
  26. package/dist/importer/cabinMeshBuilders.d.ts +13 -0
  27. package/dist/importer/cabinMeshBuilders.js +104 -0
  28. package/dist/importer/cabinMixamoRig.d.ts +53 -0
  29. package/dist/importer/cabinMixamoRig.js +150 -0
  30. package/dist/importer/chopShopActions.d.ts +6 -0
  31. package/dist/importer/chopShopActions.js +86 -61
  32. package/dist/importer/chopShopUiComponents.d.ts +22 -0
  33. package/dist/importer/chopShopUiComponents.js +91 -0
  34. package/dist/importer/gateStore.d.ts +5 -2
  35. package/dist/importer/gateStore.js +13 -10
  36. package/dist/importer/glbNormalizer.d.ts +10 -1
  37. package/dist/importer/glbNormalizer.js +114 -49
  38. package/dist/importer/importerWebMcp.js +4 -1
  39. package/dist/importer/index.d.ts +4 -2
  40. package/dist/importer/index.js +24 -21
  41. package/dist/importer/khrCompiler.d.ts +20 -1
  42. package/dist/importer/khrCompiler.js +539 -290
  43. package/dist/importer/launcherBake.js +12 -8
  44. package/dist/importer/meshIslands.d.ts +4 -0
  45. package/dist/importer/meshIslands.js +104 -99
  46. package/dist/importer/surfaceCutter.d.ts +12 -3
  47. package/dist/importer/surfaceCutter.js +220 -127
  48. package/dist/importer/surfaceTopology.d.ts +13 -2
  49. package/dist/importer/surfaceTopology.js +57 -29
  50. package/dist/importer/universalGateBake.d.ts +7 -1
  51. package/dist/importer/universalGateBake.js +63 -60
  52. package/dist/importer/usdToGlb.js +19 -7
  53. package/dist/importer/useChopShopController.d.ts +27 -1
  54. package/dist/importer/useChopShopController.js +369 -255
  55. package/dist/importer/wheelAxlePairing.d.ts +3 -1
  56. package/dist/importer/wheelAxlePairing.js +82 -33
  57. package/dist/index.js +31 -28
  58. package/dist/junk/ShardPieces.js +3 -3
  59. package/dist/physics/index.d.ts +7 -0
  60. package/dist/physics/index.js +66 -40
  61. package/package.json +1 -1
package/bin/kolmo.mjs CHANGED
@@ -102,7 +102,7 @@ fs.writeFileSync(path.join(targetDir, "wrangler.jsonc"), JSON.stringify({
102
102
  assets: { directory: "./dist", not_found_handling: "single-page-application" },
103
103
  }, null, 2));
104
104
 
105
- fs.writeFileSync(path.join(targetDir, "index.html"), `<!doctype html><html><head><meta charset="utf-8"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>${pkgName}</title><style>html,body,#root{margin:0;width:100%;height:100%;overflow:hidden;background:#05070e}</style></head><body><div id="root"></div><script type="module" src="/src/main.tsx"></script></body></html>\n`.replace('<meta charset="utf-8"/><meta charset="utf-8"/>', '<meta charset="utf-8"/>'));
105
+ fs.writeFileSync(path.join(targetDir, "index.html"), `<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>${pkgName}</title><style>html,body,#root{margin:0;width:100%;height:100%;overflow:hidden;background:#05070e}</style></head><body><div id="root"></div><script type="module" src="/src/main.tsx"></script></body></html>\n`);
106
106
 
107
107
  const appSrc = template === "garage"
108
108
  ? `import { GlbImportGate } from "@pinkaphant/kolmo/importer";\nexport function App() {\n return <GlbImportGate />;\n}\n`
@@ -1,46 +1,65 @@
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 { useRapier as C } from "@react-three/rapier";
10
- import { Ecctrl as w } from "@pinkaphant/ecctrl";
1
+ import { KolmoGravityContext as e, KolmoTimeContext as t, isKolmoPhysicsStepping as n } from "../physics/index.js";
2
+ import { applyRetroMaterial as r } from "../shaders/retroShader.js";
3
+ import { useKolmoInput as i } from "./kolmoInput.js";
4
+ import { ActorTrait as a, InteractableTrait as o, VehicleTrait as s, WorldSessionTrait as c, ensureWorldSession as l, kolmoActions as u, kolmoTelemetry as d, setWorldCameraControls as f, useActiveKolmoWorld as p, useWorldTrait as m } from "./kolmoStore.js";
5
+ import { useCallback as h, useContext as g, useLayoutEffect as _, useMemo as v, useRef as y, useState as b } from "react";
6
+ import * as x from "three";
7
+ import { useFrame as S, useThree as ee } from "@react-three/fiber";
8
+ import { Fragment as te, jsx as C, jsxs as w } from "react/jsx-runtime";
9
+ import { Ecctrl as ne } from "@pinkaphant/ecctrl";
11
10
  import { EcctrlCameraControls as T } from "@pinkaphant/ecctrl/camera";
12
11
  // src/engine/kolmoActor.tsx
13
- var E = new _.Vector3(), D = new _.Vector3(), O = new _.Vector3();
14
- function k() {
15
- let e = h(() => ({
16
- suitGeo: new _.CapsuleGeometry(.28, .56, 6, 12),
17
- visorGeo: new _.BoxGeometry(.34, .16, .14),
18
- packGeo: new _.BoxGeometry(.32, .42, .16),
19
- suitMat: t(new _.MeshStandardMaterial({
12
+ var E = new x.Vector3(), D = new x.Vector3(), O = new x.Vector3(), k = new x.Vector3(), A = new x.Vector3(), j = new x.Vector3();
13
+ function M(e, t) {
14
+ if (Array.isArray(e) && e.length >= 3) return [
15
+ Number(e[0]) || 0,
16
+ Number(e[1]) || 0,
17
+ Number(e[2]) || 0
18
+ ];
19
+ if (e && typeof e == "object" && "x" in e && "y" in e && "z" in e) {
20
+ let t = e;
21
+ return [
22
+ t.x,
23
+ t.y,
24
+ t.z
25
+ ];
26
+ }
27
+ return [
28
+ t[0],
29
+ t[1],
30
+ t[2]
31
+ ];
32
+ }
33
+ function N() {
34
+ let e = v(() => ({
35
+ suitGeo: new x.CapsuleGeometry(.28, .56, 6, 12),
36
+ visorGeo: new x.BoxGeometry(.34, .16, .14),
37
+ packGeo: new x.BoxGeometry(.32, .42, .16),
38
+ suitMat: r(new x.MeshStandardMaterial({
20
39
  color: "#e2e8f0",
21
40
  roughness: .55,
22
41
  metalness: .15
23
42
  })),
24
- visorMat: t(new _.MeshStandardMaterial({
43
+ visorMat: r(new x.MeshStandardMaterial({
25
44
  color: "#38bdf8",
26
45
  emissive: "#0284c7",
27
46
  emissiveIntensity: .55,
28
47
  roughness: .2
29
48
  })),
30
- packMat: t(new _.MeshStandardMaterial({
49
+ packMat: r(new x.MeshStandardMaterial({
31
50
  color: "#334155",
32
51
  roughness: .7
33
52
  }))
34
53
  }), []);
35
- return m(() => () => {
54
+ return _(() => () => {
36
55
  e.suitGeo.dispose(), e.visorGeo.dispose(), e.packGeo.dispose(), e.suitMat.dispose(), e.visorMat.dispose(), e.packMat.dispose();
37
- }, [e]), /* @__PURE__ */ S("group", { children: [
38
- /* @__PURE__ */ x("mesh", {
56
+ }, [e]), /* @__PURE__ */ w("group", { children: [
57
+ /* @__PURE__ */ C("mesh", {
39
58
  castShadow: !0,
40
59
  geometry: e.suitGeo,
41
60
  material: e.suitMat
42
61
  }),
43
- /* @__PURE__ */ x("mesh", {
62
+ /* @__PURE__ */ C("mesh", {
44
63
  position: [
45
64
  0,
46
65
  .24,
@@ -49,7 +68,7 @@ function k() {
49
68
  geometry: e.visorGeo,
50
69
  material: e.visorMat
51
70
  }),
52
- /* @__PURE__ */ x("mesh", {
71
+ /* @__PURE__ */ C("mesh", {
53
72
  position: [
54
73
  0,
55
74
  .06,
@@ -61,75 +80,81 @@ function k() {
61
80
  })
62
81
  ] });
63
82
  }
64
- function A({ position: t = [
83
+ function P({ position: r = [
65
84
  0,
66
85
  1.4,
67
86
  0
68
- ], enabled: A = !0, getInput: j, ecctrlProps: M, cameraProps: N, children: P }) {
69
- let F = p(e), I = u();
70
- m(() => {
71
- s(I);
72
- }, [I]);
73
- let L = d(I, o), R = n(j), z = y((e) => typeof e.gl?.domElement?.setAttribute == "function"), B = g(null), V = g(null), H = g(new _.Vector3()), U = g(new _.Vector3(0, 1, 0)), W = g(!1), G = g(0), K = g({
87
+ ], enabled: P = !0, getInput: F, ecctrlProps: I, cameraProps: L, children: re }) {
88
+ let ie = g(e), R = g(t), z = p();
89
+ _(() => {
90
+ l(z);
91
+ }, [z]);
92
+ let ae = m(z, c), oe = i(F), se = ee((e) => typeof e.gl?.domElement?.setAttribute == "function"), B = y(null), V = y(null), H = y(new x.Vector3()), U = y(new x.Vector3(0, 1, 0)), W = y(!1), G = y(0), K = y({
74
93
  pos: null,
75
- yaw: 0
76
- }), q = g(null), J = g({
94
+ yaw: 0,
95
+ rot: null
96
+ }), q = y(null), ce = y({
77
97
  forward: !1,
78
98
  backward: !1,
79
99
  leftward: !1,
80
100
  rightward: !1,
81
101
  run: !1,
82
102
  jump: !1
83
- }), Y = f((e, t) => {
103
+ }), J = n(R), [le, ue] = b(J), Y = y(J), X = h((e, t) => {
84
104
  H.current.x -= e, H.current.z -= t, B.current && (B.current.currPos.x -= e, B.current.currPos.z -= t);
85
105
  let n = V.current;
86
- n?.getPosition && n?.getTarget && n?.setLookAt && (n.getPosition(D), n.getTarget(O), n.setLookAt(D.x - e, D.y, D.z - t, O.x - e, O.y, O.z - t, !1));
87
- }, []);
88
- m(() => {
89
- let e = I.spawn(r({
106
+ n && (n.getPosition(D), n.getTarget(O), n.setLookAt(D.x - e, D.y, D.z - t, O.x - e, O.y, O.z - t, !1));
107
+ }, []), de = h((e) => {
108
+ V.current = e, f(z, e);
109
+ }, [z]);
110
+ _(() => {
111
+ let e = z.spawn(a({
90
112
  id: "pilot",
91
113
  handle: B.current,
92
114
  exitSpawnPos: null,
93
115
  exitSpawnYaw: 0,
116
+ exitSpawnRot: null,
94
117
  exitLinVel: null,
95
- onOriginShift: Y
96
- })), t = I.onChange(r, (t) => {
118
+ onOriginShift: X
119
+ })), t = z.onChange(a, (t) => {
97
120
  if (t !== e) return;
98
- let n = e.get(r);
121
+ let n = e.get(a);
99
122
  n && (K.current = {
100
123
  pos: n.exitSpawnPos,
101
- yaw: n.exitSpawnYaw
124
+ yaw: n.exitSpawnYaw,
125
+ rot: n.exitSpawnRot ?? null
102
126
  });
103
127
  });
104
128
  return () => {
105
- t(), e.destroy();
129
+ t(), f(z, null), e.destroy();
106
130
  };
107
- }, [I, Y]);
108
- let X = f((e) => {
131
+ }, [z, X]);
132
+ let Z = h((e) => {
109
133
  B.current = e;
110
- let t = I.queryFirst(r);
134
+ let t = z.queryFirst(a);
111
135
  if (!t) return;
112
- let n = t.get(r);
136
+ let n = t.get(a);
113
137
  e?.body && n?.exitLinVel && e.body.setLinvel({
114
138
  x: n.exitLinVel[0],
115
139
  y: n.exitLinVel[1],
116
140
  z: n.exitLinVel[2]
117
- }, !0), e?.body && (K.current.pos = null), t.set(r, {
141
+ }, !0), e?.body && (K.current.pos = null, K.current.rot = null), t.set(a, {
118
142
  id: n?.id ?? "pilot",
119
143
  handle: e,
120
144
  exitSpawnPos: e?.body ? null : n?.exitSpawnPos ?? null,
121
145
  exitSpawnYaw: n?.exitSpawnYaw ?? 0,
146
+ exitSpawnRot: e?.body ? null : n?.exitSpawnRot ?? null,
122
147
  exitLinVel: e?.body ? null : n?.exitLinVel ?? null,
123
- onOriginShift: Y
148
+ onOriginShift: X
124
149
  });
125
- }, [I, Y]), { world: Z } = C(), Q = L?.activeVehicleId || "", $ = A && !Q;
150
+ }, [z, X]), Q = ae?.activeVehicleId || "", $ = P && !Q;
126
151
  if (!$) q.current = null;
127
152
  else if (!q.current) {
128
- let e = K.current.pos ?? M?.position ?? t, n = M?.rotation ?? [
153
+ let e = K.current.pos ?? M(I?.position, r), t = K.current.rot ?? [
129
154
  0,
130
155
  K.current.yaw,
131
156
  0
132
- ];
157
+ ], n = I?.rotation !== void 0 && !K.current.pos ? M(I.rotation, t) : t;
133
158
  q.current = {
134
159
  pos: [
135
160
  e[0],
@@ -143,8 +168,8 @@ function A({ position: t = [
143
168
  ]
144
169
  };
145
170
  }
146
- let ee = h(() => {
147
- let e = M?.userData ?? {}, t = e.ecctrl ?? {};
171
+ let fe = v(() => {
172
+ let e = I?.userData ?? {}, t = e.ecctrl ?? {};
148
173
  return {
149
174
  ...e,
150
175
  ecctrl: {
@@ -152,47 +177,64 @@ function A({ position: t = [
152
177
  ...t
153
178
  }
154
179
  };
155
- }, [M?.userData]);
156
- return v((e, t) => {
157
- if (!A) return;
158
- let n = Z.timestep > 0 ? Z.timestep : Math.min(Math.max(t, 1e-4), 1 / 30);
159
- G.current > 0 && (G.current = Math.max(0, G.current - n));
160
- let r = R(), o = r.interact && !W.current;
161
- if (W.current = r.interact, Q) {
162
- o && G.current === 0 && (G.current = .25, c(I).exitVehicle());
180
+ }, [I?.userData]);
181
+ if (S((e, t) => {
182
+ if (!P) return;
183
+ let r = n(R);
184
+ r !== Y.current && (Y.current = r, ue(r));
185
+ let i = Math.min(Math.max(t, 1e-4), 1 / 30);
186
+ G.current > 0 && (G.current = Math.max(0, G.current - i));
187
+ let a = oe(), c = a.interact && !W.current;
188
+ if (W.current = a.interact, Q) {
189
+ c && G.current === 0 && (G.current = .25, u(z).exitVehicle());
163
190
  return;
164
191
  }
165
- let s = B.current;
166
- if (!s || !s.body) return;
167
- let u = J.current;
168
- 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;
169
- let d = null, f = Infinity;
170
- for (let e of I.query(a, i)) {
171
- let t = e.get(a), n = e.get(i);
192
+ let l = B.current;
193
+ if (!l || !l.body) return;
194
+ if (r) {
195
+ let e = ce.current;
196
+ e.forward = a.forward, e.backward = a.backward, e.leftward = a.left, e.rightward = a.right, e.run = a.boost, e.jump = a.brake, l.setMovement(e);
197
+ }
198
+ d.mode = "foot", d.speedKmh = l.moveSpeed * 3.6, d.rpm = 0, d.gear = 0, d.throttle = +!!l.isMoving, d.boost = a.boost && l.isMoving ? 1 : 0;
199
+ let f = null, p = Infinity;
200
+ for (let e of z.query(s, o)) {
201
+ let t = e.get(s), n = e.get(o);
172
202
  if (!t?.handle || !n) continue;
173
203
  E.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);
174
- let r = s.currPos.distanceToSquared(E);
175
- r <= n.radius * n.radius && r < f && (f = r, d = t.id);
204
+ let r = l.currPos.distanceToSquared(E);
205
+ r <= n.radius * n.radius && r < p && (p = r, f = t.id);
206
+ }
207
+ if (d.nearVehicleId = f, c && f && G.current === 0) {
208
+ G.current = .25, u(z).boardVehicle(f);
209
+ return;
210
+ }
211
+ let m = V.current;
212
+ if (m && l.currPos.lengthSq() > 0 && (m.enabled ||= !0, H.current.copy(l.currPos).addScaledVector(l.bodyYAxis, .55), m.moveTo(H.current.x, H.current.y, H.current.z, !0), U.current.copy(l.upAxis), U.current.lengthSq() > 1e-6 && (U.current.normalize(), e.camera.up.lerp(U.current, 1 - Math.exp(-8 * i)), m.setUp(e.camera.up), l.isOnPlatform && (e.camera.getWorldDirection(k).projectOnPlane(U.current), k.lengthSq() > 1e-6)))) {
213
+ k.normalize(), A.copy(k).applyQuaternion(l.turnOnYQuat), j.crossVectors(k, A);
214
+ let e = x.MathUtils.clamp(k.dot(A), -1, 1);
215
+ Math.abs(e) < 1e-10 && (e = 0), m.rotate(Math.atan2(j.dot(U.current), e), 0, !0);
176
216
  }
177
- l.nearVehicleId = d, o && d && G.current === 0 ? (G.current = .25, c(I).boardVehicle(d)) : V.current && s.currPos.lengthSq() > 0 && (H.current.copy(s.currPos).addScaledVector(s.bodyYAxis, .55), U.current.copy(s.upAxis), V.current.moveTo(H.current.x, H.current.y, H.current.z, !0), e.camera.up.lerp(U.current, .14), V.current.setUp(e.camera.up));
178
- }), $ ? /* @__PURE__ */ S(b, { children: [z && N !== !1 && N !== null && /* @__PURE__ */ x(T, {
179
- ref: V,
217
+ }), !P) return null;
218
+ let pe = !R.paused && le && (I?.enable ?? !0);
219
+ return /* @__PURE__ */ w(te, { children: [se && L !== !1 && L !== null && /* @__PURE__ */ C(T, {
220
+ ref: de,
180
221
  makeDefault: !0,
181
222
  minPolarAngle: .12,
182
223
  maxPolarAngle: Math.PI - .12,
183
224
  smoothTime: .08,
184
- ...N ?? {}
185
- }), /* @__PURE__ */ x(w, {
186
- ref: X,
187
- enableCustomGravity: F,
225
+ ...L ?? {}
226
+ }), $ && /* @__PURE__ */ C(ne, {
227
+ ref: Z,
228
+ enableCustomGravity: ie,
188
229
  maxWalkVel: 3.2,
189
230
  maxRunVel: 7.2,
190
231
  jumpVel: 5.8,
191
- ...M,
232
+ ...I,
233
+ enable: pe,
192
234
  position: q.current.pos,
193
235
  rotation: q.current.rot,
194
- userData: ee,
195
- children: P ?? /* @__PURE__ */ x(k, {})
196
- })] }) : null;
236
+ userData: fe,
237
+ children: re ?? /* @__PURE__ */ C(N, {})
238
+ })] });
197
239
  }
198
- export { A as KolmoActor };
240
+ export { P as KolmoActor };
@@ -1,23 +1,23 @@
1
1
  import { createPS2RoadMaterialWebGL as e } from "../shaders/ps2RoadWebGL.js";
2
2
  import { createPS2WorldTextures as t } from "../shaders/ps2Textures.js";
3
- import { MACRO_SIZE_M as n, quantizeFloatingOrigin192 as r } from "../world/macroCellSchema.js";
4
- import { InfiniteLongDrivePlanner as i } from "../world/infiniteWorld2D.js";
5
- import { bakeWorldSplatMaps as a } from "../world/worldTypes.js";
6
- import { buildRoadRibbonGeometry as o } from "../world/roadRibbon.js";
7
- import { ShiftedFixedBody as s } from "./shiftedFixedBody.js";
8
- import { roadFromPoints as c } from "../world/road.js";
9
- import { KolmoIsland as l, getCachedIslandPlan as u } from "./kolmoIsland.js";
10
- import { readFloatingOriginAnchorXZ as d, shiftFloatingOriginEntities as f, useActiveKolmoWorld as p } from "./kolmoStore.js";
11
- import { InstancedC12Piece as m, InstancedWorldGlb as h } from "./longDriveKit.js";
12
- import { MainlandMacroCell as g } from "./mainlandMacroCell.js";
13
- import { useEffect as _, useMemo as v, useRef as y, useState as b } from "react";
14
- import * as x from "three";
15
- import { useFrame as S, useThree as C } from "@react-three/fiber";
16
- import { jsx as w, jsxs as T } from "react/jsx-runtime";
17
- import { TrimeshCollider as E, useRapier as D } from "@react-three/rapier";
3
+ import { MACRO_SIZE_M as n } from "../world/macroCellSchema.js";
4
+ import { InfiniteLongDrivePlanner as r } from "../world/infiniteWorld2D.js";
5
+ import { bakeWorldSplatMaps as i } from "../world/worldTypes.js";
6
+ import { buildRoadRibbonGeometry as a } from "../world/roadRibbon.js";
7
+ import { ShiftedFixedBody as o } from "./shiftedFixedBody.js";
8
+ import { roadFromPoints as s } from "../world/road.js";
9
+ import { KolmoIsland as c, getCachedIslandPlan as l } from "./kolmoIsland.js";
10
+ import { readFloatingOriginAnchorXZ as u, shiftFloatingOriginEntities as d, useActiveKolmoWorld as f } from "./kolmoStore.js";
11
+ import { InstancedC12Piece as p, InstancedWorldGlb as m } from "./longDriveKit.js";
12
+ import { MainlandMacroCell as h } from "./mainlandMacroCell.js";
13
+ import { useEffect as g, useMemo as _, useRef as v, useState as y } from "react";
14
+ import * as b from "three";
15
+ import { useFrame as x, useThree as S } from "@react-three/fiber";
16
+ import { jsx as C, jsxs as w } from "react/jsx-runtime";
17
+ import { TrimeshCollider as T, useRapier as E } from "@react-three/rapier";
18
18
  // src/engine/kolmoLongDrive.tsx
19
- function O(e = 77, t = 960) {
20
- let n = u(e, t), r = n.road.samples[0];
19
+ function D(e = 77, t = 960) {
20
+ let n = l(e, t), r = n.road.samples[0];
21
21
  for (let e of n.road.samples) e.pos[0] > r.pos[0] && (r = e);
22
22
  return {
23
23
  vehiclePos: [
@@ -37,10 +37,10 @@ function O(e = 77, t = 960) {
37
37
  ]
38
38
  };
39
39
  }
40
- function k(e = 77, t = 1, n = 0) {
41
- let r = new i(e), a = r.generateMacroCell2D(t, n), o = a.highwayPolylines[0];
40
+ function O(e = 77, t = 1, n = 0) {
41
+ let i = new r(e), a = i.generateMacroCell2D(t, n), o = a.highwayPolylines[0];
42
42
  if (o && o.length >= 2) {
43
- let e = o[1], t = o[Math.min(o.length - 1, 2)], n = Math.max(2, r.sampleMainlandHeight(e[0], e[1])), i = Math.atan2(t[0] - e[0], t[1] - e[1]);
43
+ let e = o[1], t = o[Math.min(o.length - 1, 2)], n = Math.max(2, i.sampleMainlandHeight(e[0], e[1])), r = Math.atan2(t[0] - e[0], t[1] - e[1]);
44
44
  return {
45
45
  vehiclePos: [
46
46
  e[0],
@@ -49,7 +49,7 @@ function k(e = 77, t = 1, n = 0) {
49
49
  ],
50
50
  vehicleRot: [
51
51
  0,
52
- i,
52
+ r,
53
53
  0
54
54
  ],
55
55
  actorPos: [
@@ -59,7 +59,7 @@ function k(e = 77, t = 1, n = 0) {
59
59
  ]
60
60
  };
61
61
  }
62
- let s = Math.max(2.5, r.sampleMainlandHeight(a.hubX, a.hubZ));
62
+ let s = Math.max(2.5, i.sampleMainlandHeight(a.hubX, a.hubZ));
63
63
  return {
64
64
  vehiclePos: [
65
65
  a.hubX,
@@ -78,23 +78,23 @@ function k(e = 77, t = 1, n = 0) {
78
78
  ]
79
79
  };
80
80
  }
81
- function A({ seed: e, islandSize: t, planner: r, roadMat: i, offX: a, offZ: l }) {
82
- let d = v(() => {
83
- let i = u(e, t), a = i.road.samples[0];
84
- for (let e of i.road.samples) e.pos[0] > a.pos[0] && (a = e);
85
- let s = r.evalVerticalBorder(0, 0), l = n * .5, d = s.offsetMeters, f = r.sampleMainlandHeight(l, d), p = [];
81
+ function k({ seed: e, islandSize: t, planner: r, roadMat: i, offX: c, offZ: u }) {
82
+ let d = _(() => {
83
+ let i = l(e, t), o = i.road.samples[0];
84
+ for (let e of i.road.samples) e.pos[0] > o.pos[0] && (o = e);
85
+ let c = r.evalVerticalBorder(0, 0), u = n * .5, d = c.offsetMeters, f = r.sampleMainlandHeight(u, d), p = [];
86
86
  for (let e = 0; e <= 28; e++) {
87
- let t = e / 28, n = Math.sin(Math.PI * t), r = a.pos[0] + (l - a.pos[0]) * t, i = a.pos[2] + (d - a.pos[2]) * (t * t * (3 - 2 * t)), o = a.pos[1] * (1 - t) + f * t;
87
+ let t = e / 28, n = Math.sin(Math.PI * t), r = o.pos[0] + (u - o.pos[0]) * t, i = o.pos[2] + (d - o.pos[2]) * (t * t * (3 - 2 * t)), a = o.pos[1] * (1 - t) + f * t;
88
88
  p.push([
89
89
  r,
90
- o * (1 - n) + 14 * n,
90
+ a * (1 - n) + 14 * n,
91
91
  i
92
92
  ]);
93
93
  }
94
- let m = c(p, 5, 3, !1), h = o(m, {
94
+ let m = s(p, 5, 3, !1), h = a(m, {
95
95
  skirtDrop: .6,
96
96
  crownHeight: .04
97
- }), g = [], _ = [], v = new x.Object3D();
97
+ }), g = [], _ = [], v = new b.Object3D();
98
98
  for (let e = 24; e < m.length - 24; e += 24) {
99
99
  let t = m.at(e), n = Math.atan2(t.tangent[0], t.tangent[2]);
100
100
  for (let e of [-3.6, 3.6]) {
@@ -113,28 +113,28 @@ function A({ seed: e, islandSize: t, planner: r, roadMat: i, offX: a, offZ: l })
113
113
  t,
114
114
  r
115
115
  ]);
116
- return _(() => () => {
116
+ return g(() => () => {
117
117
  d.ribbon.geometry.dispose();
118
- }, [d]), /* @__PURE__ */ T("group", { children: [/* @__PURE__ */ T(s, {
119
- x: a,
120
- z: l,
118
+ }, [d]), /* @__PURE__ */ w("group", { children: [/* @__PURE__ */ w(o, {
119
+ x: c,
120
+ z: u,
121
121
  friction: 1.05,
122
- children: [/* @__PURE__ */ w(E, { args: [d.ribbon.colliderVertices, d.ribbon.colliderIndices] }), /* @__PURE__ */ w("mesh", {
122
+ children: [/* @__PURE__ */ C(T, { args: [d.ribbon.colliderVertices, d.ribbon.colliderIndices] }), /* @__PURE__ */ C("mesh", {
123
123
  geometry: d.ribbon.geometry,
124
124
  material: i,
125
125
  receiveShadow: !0
126
126
  })]
127
- }), /* @__PURE__ */ T("group", {
127
+ }), /* @__PURE__ */ w("group", {
128
128
  position: [
129
- a,
129
+ c,
130
130
  0,
131
- l
131
+ u
132
132
  ],
133
- children: [/* @__PURE__ */ w(m, {
133
+ children: [/* @__PURE__ */ C(p, {
134
134
  matrices: d.piers,
135
135
  kind: "square",
136
136
  color: "#64748b"
137
- }), /* @__PURE__ */ w(h, {
137
+ }), /* @__PURE__ */ C(m, {
138
138
  kitKey: "light_pole",
139
139
  fitSpan: [
140
140
  .6,
@@ -145,79 +145,124 @@ function A({ seed: e, islandSize: t, planner: r, roadMat: i, offX: a, offZ: l })
145
145
  })]
146
146
  })] });
147
147
  }
148
- function j({ seed: o = 77, pureMainland: s = !1, initialOrigin: c = [0, 0], onOriginRebase: m, renderCellExtra: h }) {
149
- let x = p(), E = C((e) => e.camera), O = D(), k = v(() => new i(o), [o]), [j, M] = b(c), N = y([c[0], c[1]]), P = y([c[0], c[1]]), [F, I] = b(() => [Math.max(+!!s, Math.round(c[0] / n)), Math.round(c[1] / n)]), [L, R] = b(() => {
150
- let e = Math.max(1, Math.round(c[0] / n)), t = Math.round(c[1] / n);
151
- return s ? [
148
+ function A({ seed: a = 77, pureMainland: o = !1, initialOrigin: s = [0, 0], onOriginRebase: p, renderCellExtra: m }) {
149
+ let b = f(), T = S((e) => e.camera), D = E(), O = _(() => new r(a), [a]), [A, j] = y(s), M = v([s[0], s[1]]), N = v([s[0], s[1]]), [P, F] = y(() => [Math.max(+!!o, Math.round(s[0] / n)), Math.round(s[1] / n)]), I = v([P[0], P[1]]), [L, R] = y(() => {
150
+ let e = Math.max(1, Math.round(s[0] / n)), t = Math.round(s[1] / n);
151
+ return o ? [
152
152
  [e, t],
153
153
  [e, t - 1],
154
154
  [e, t + 1],
155
155
  [e + 1, t]
156
156
  ] : [[1, 0]];
157
- }), z = v(() => {
158
- let n = u(o, 960), r = t(a(n, 64));
157
+ }), z = v(L);
158
+ z.current = L;
159
+ let B = v(!1), V = v([0, 0]), H = _(() => {
160
+ let n = l(a, 960), r = t(i(n, 64));
159
161
  return {
160
162
  tex: r,
161
163
  roadMat: e(r, { preset: "ASPHALT" }).material
162
164
  };
163
- }, [o]);
164
- _(() => () => {
165
- z.roadMat.dispose(), z.tex.dispose();
166
- }, [z]);
167
- let B = v(() => {
168
- let [e, t] = F, n = [];
165
+ }, [a]);
166
+ g(() => () => {
167
+ H.roadMat.dispose(), H.tex.dispose();
168
+ }, [H]);
169
+ let U = _(() => {
170
+ let [e, t] = P, n = [];
169
171
  for (let r = -1; r <= 1; r++) for (let i = -1; i <= 1; i++) {
170
172
  let a = e + r, o = t + i;
171
173
  a >= 1 && n.push([a, o]);
172
174
  }
173
- return n.sort((n, r) => Math.hypot(n[0] - e, n[1] - t) - Math.hypot(r[0] - e, r[1] - t)), n;
174
- }, [F]);
175
- _(() => {
176
- let e = j[0] - N.current[0], t = j[1] - N.current[1];
177
- (e !== 0 || t !== 0) && (N.current = [j[0], j[1]], P.current = [j[0], j[1]], f(x, E, e, t, O), m?.(j[0], j[1], e, t));
175
+ return n.sort((n, r) => Math.hypot(n[0] - e, n[1] - t) - Math.hypot(r[0] - e, r[1] - t)), B.current = !1, n;
176
+ }, [P]);
177
+ g(() => {
178
+ let e = A[0] - M.current[0], t = A[1] - M.current[1];
179
+ (e !== 0 || t !== 0) && (M.current = [A[0], A[1]], N.current = [A[0], A[1]], d(b, T, e, t, D), p?.(A[0], A[1], e, t));
178
180
  }, [
179
- j,
180
- x,
181
- E,
182
- O,
183
- m
184
- ]), S(() => {
185
- R((e) => {
186
- let t = e.filter(([e, t]) => B.some(([n, r]) => n === e && r === t)), n = B.find(([e, n]) => !t.some(([t, r]) => t === e && r === n));
187
- return !n && t.length === e.length ? e : n ? [...t, n] : t;
188
- });
189
- let [e, t] = N.current, [i, a] = d(x, E), o = e + i, c = t + a, l = r(o, c), u = l.chunkOriginX - e, f = l.chunkOriginZ - t;
190
- (Math.abs(u) >= 192 || Math.abs(f) >= 192) && (l.chunkOriginX !== P.current[0] || l.chunkOriginZ !== P.current[1]) && (P.current = [l.chunkOriginX, l.chunkOriginZ], M([l.chunkOriginX, l.chunkOriginZ]));
191
- let p = Math.max(+!!s, Math.round(o / n)), m = Math.round(c / n);
192
- (p !== F[0] || m !== F[1]) && I([p, m]);
181
+ A,
182
+ b,
183
+ T,
184
+ D,
185
+ p
186
+ ]), x(() => {
187
+ if (!B.current) {
188
+ let e = z.current, t = !1;
189
+ for (let n = 0; n < e.length; n++) {
190
+ let r = e[n], i = !1;
191
+ for (let e = 0; e < U.length; e++) {
192
+ let t = U[e];
193
+ if (t[0] === r[0] && t[1] === r[1]) {
194
+ i = !0;
195
+ break;
196
+ }
197
+ }
198
+ if (!i) {
199
+ t = !0;
200
+ break;
201
+ }
202
+ }
203
+ let n = null;
204
+ for (let t = 0; t < U.length; t++) {
205
+ let r = U[t], i = !1;
206
+ for (let t = 0; t < e.length; t++) {
207
+ let n = e[t];
208
+ if (n[0] === r[0] && n[1] === r[1]) {
209
+ i = !0;
210
+ break;
211
+ }
212
+ }
213
+ if (!i) {
214
+ n = r;
215
+ break;
216
+ }
217
+ }
218
+ if (!t && !n) B.current = !0;
219
+ else {
220
+ let t = [];
221
+ for (let n = 0; n < e.length; n++) {
222
+ let r = e[n];
223
+ for (let e = 0; e < U.length; e++) {
224
+ let n = U[e];
225
+ if (n[0] === r[0] && n[1] === r[1]) {
226
+ t.push(r);
227
+ break;
228
+ }
229
+ }
230
+ }
231
+ n && t.push(n), z.current = t, R(t);
232
+ }
233
+ }
234
+ let e = M.current[0], t = M.current[1], r = u(b, T, V.current), i = e + r[0], a = t + r[1], s = Math.round(i / 192) * 192, c = Math.round(a / 192) * 192, l = s - e, d = c - t;
235
+ (Math.abs(l) >= 192 || Math.abs(d) >= 192) && (s !== N.current[0] || c !== N.current[1]) && (N.current[0] = s, N.current[1] = c, j([s, c]));
236
+ let f = Math.max(+!!o, Math.round(i / n)), p = Math.round(a / n);
237
+ (f !== I.current[0] || p !== I.current[1]) && (I.current[0] = f, I.current[1] = p, F([f, p]));
193
238
  });
194
- let V = -j[0], H = -j[1];
195
- return /* @__PURE__ */ T("group", { children: [
196
- !s && F[0] <= 1 && Math.abs(F[1]) <= 1 && /* @__PURE__ */ w(l, {
197
- seed: o,
239
+ let W = -A[0], G = -A[1];
240
+ return /* @__PURE__ */ w("group", { children: [
241
+ !o && P[0] <= 1 && Math.abs(P[1]) <= 1 && /* @__PURE__ */ C(c, {
242
+ seed: a,
198
243
  size: 960,
199
244
  segments: 144,
200
245
  settlementTier: "town",
201
- offX: V,
202
- offZ: H
246
+ offX: W,
247
+ offZ: G
203
248
  }),
204
- !s && F[0] <= 2 && Math.abs(F[1]) <= 1 && /* @__PURE__ */ w(A, {
205
- seed: o,
249
+ !o && P[0] <= 2 && Math.abs(P[1]) <= 1 && /* @__PURE__ */ C(k, {
250
+ seed: a,
206
251
  islandSize: 960,
207
- planner: k,
208
- roadMat: z.roadMat,
209
- offX: V,
210
- offZ: H
252
+ planner: O,
253
+ roadMat: H.roadMat,
254
+ offX: W,
255
+ offZ: G
211
256
  }),
212
- L.map(([e, t]) => /* @__PURE__ */ w(g, {
257
+ L.map(([e, t]) => /* @__PURE__ */ C(h, {
213
258
  mx: e,
214
259
  mz: t,
215
- planner: k,
216
- roadMat: z.roadMat,
217
- offX: V,
218
- offZ: H,
219
- renderExtra: h
260
+ planner: O,
261
+ roadMat: H.roadMat,
262
+ offX: W,
263
+ offZ: G,
264
+ renderExtra: m
220
265
  }, `mc_${e}_${t}`))
221
266
  ] });
222
267
  }
223
- export { j as KolmoLongDrive, O as computeLongDriveBridgeheadSpawn, k as computeLongDriveMainlandSpawn };
268
+ export { A as KolmoLongDrive, D as computeLongDriveBridgeheadSpawn, O as computeLongDriveMainlandSpawn };