@pinkaphant/kolmo 0.0.0-stage → 0.1.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 (90) hide show
  1. package/README.md +44 -2
  2. package/bin/kolmo.mjs +112 -0
  3. package/dist/engine/index.d.ts +8 -0
  4. package/dist/engine/index.js +3 -0
  5. package/dist/engine/kolmoActor.d.ts +6 -0
  6. package/dist/engine/kolmoIsland.d.ts +17 -0
  7. package/dist/engine/kolmoLongDrive.d.ts +13 -0
  8. package/dist/engine/kolmoRigs.d.ts +13 -0
  9. package/dist/engine/kolmoStore.d.ts +68 -0
  10. package/dist/engine/kolmoSurface.d.ts +18 -0
  11. package/dist/engine/kolmoVehicle.d.ts +32 -0
  12. package/dist/engine/kolmoWorld.d.ts +51 -0
  13. package/dist/engine/longDriveKit.d.ts +19 -0
  14. package/dist/engine/mainlandMacroCell.d.ts +19 -0
  15. package/dist/engine-BiMeAPAi.js +1717 -0
  16. package/dist/importer/ChopShopPanel.d.ts +44 -0
  17. package/dist/importer/DomainWorkshopPanel.d.ts +17 -0
  18. package/dist/importer/GateHudBar.d.ts +29 -0
  19. package/dist/importer/GlbImportGate.d.ts +7 -0
  20. package/dist/importer/ImperativeVehicleRig.d.ts +9 -0
  21. package/dist/importer/Step1CalibrationPlinth.d.ts +38 -0
  22. package/dist/importer/Step2UniversalPad.d.ts +18 -0
  23. package/dist/importer/VfxEmitterPool.d.ts +8 -0
  24. package/dist/importer/chopShopActions.d.ts +44 -0
  25. package/dist/importer/gateStore.d.ts +73 -0
  26. package/dist/importer/glbNormalizer.d.ts +22 -0
  27. package/dist/importer/importerWebMcp.d.ts +37 -0
  28. package/dist/importer/index.d.ts +17 -0
  29. package/dist/importer/index.js +3 -0
  30. package/dist/importer/khrCompiler.d.ts +23 -0
  31. package/dist/importer/launcherBake.d.ts +15 -0
  32. package/dist/importer/meshIslands.d.ts +59 -0
  33. package/dist/importer/surfaceCutter.d.ts +27 -0
  34. package/dist/importer/surfaceTopology.d.ts +40 -0
  35. package/dist/importer/universalGateBake.d.ts +41 -0
  36. package/dist/importer/usdToGlb.d.ts +11 -0
  37. package/dist/importer/useChopShopController.d.ts +94 -0
  38. package/dist/importer/vehiclePanelAnim.d.ts +25 -0
  39. package/dist/importer/wheelAxlePairing.d.ts +19 -0
  40. package/dist/importer-Cz5w0mnC.js +5005 -0
  41. package/dist/index.d.ts +16 -0
  42. package/dist/index.js +14 -0
  43. package/dist/junk/DestructibleTarget.d.ts +18 -0
  44. package/dist/junk/KolmoJunk.d.ts +14 -0
  45. package/dist/junk/ShardPieces.d.ts +10 -0
  46. package/dist/junk/TargetDecals.d.ts +18 -0
  47. package/dist/junk/bvhShatter.d.ts +7 -0
  48. package/dist/junk/bvhTriCollector.d.ts +20 -0
  49. package/dist/junk/index.d.ts +12 -0
  50. package/dist/junk/index.js +1 -0
  51. package/dist/junk/junkGeometry.d.ts +34 -0
  52. package/dist/junk/junkImportSanitize.d.ts +6 -0
  53. package/dist/junk/junkImporter.d.ts +25 -0
  54. package/dist/junk/junkLabelCanvas.d.ts +7 -0
  55. package/dist/junk/junkLabels.d.ts +31 -0
  56. package/dist/junk/junkTypes.d.ts +48 -0
  57. package/dist/junk/targetHelpers.d.ts +56 -0
  58. package/dist/junk/targetHitLogic.d.ts +30 -0
  59. package/dist/junk/useTargetAssets.d.ts +24 -0
  60. package/dist/junk-B4bC1zAl.js +1049 -0
  61. package/dist/kolmoSurface-DTnrFXH0.js +558 -0
  62. package/dist/schema/kolmoSchema.d.ts +69 -0
  63. package/dist/shaders/celestialBackdrop.d.ts +22 -0
  64. package/dist/shaders/index.d.ts +6 -0
  65. package/dist/shaders/index.js +1 -0
  66. package/dist/shaders/plumeAndSparkle.d.ts +14 -0
  67. package/dist/shaders/ps2GlslShared.d.ts +20 -0
  68. package/dist/shaders/ps2MaterialsTSL.d.ts +23 -0
  69. package/dist/shaders/ps2MaterialsWebGL.d.ts +15 -0
  70. package/dist/shaders/ps2RoadWebGL.d.ts +7 -0
  71. package/dist/shaders/ps2TerrainWebGL.d.ts +8 -0
  72. package/dist/shaders/ps2Textures.d.ts +22 -0
  73. package/dist/shaders/retroPalettes.d.ts +24 -0
  74. package/dist/shaders/retroShader.d.ts +69 -0
  75. package/dist/shaders-GS71Ek1A.js +1383 -0
  76. package/dist/world/frontage.d.ts +26 -0
  77. package/dist/world/index.d.ts +9 -0
  78. package/dist/world/index.js +3 -0
  79. package/dist/world/infiniteWorld2D.d.ts +24 -0
  80. package/dist/world/island.d.ts +29 -0
  81. package/dist/world/macroCellSchema.d.ts +72 -0
  82. package/dist/world/macroKnightAStar.d.ts +11 -0
  83. package/dist/world/random.d.ts +23 -0
  84. package/dist/world/road.d.ts +37 -0
  85. package/dist/world/roadRibbon.d.ts +44 -0
  86. package/dist/world/terrain.d.ts +62 -0
  87. package/dist/world/worldTypes.d.ts +39 -0
  88. package/dist/world-PRWPYrlx.js +947 -0
  89. package/dist/worldTypes-Z0KfdCd0.js +226 -0
  90. package/package.json +100 -4
@@ -0,0 +1,1717 @@
1
+ import { D as e, M as t, O as n, a as r, g as i, i as a, j as o, p as s, s as c } from "./shaders-GS71Ek1A.js";
2
+ import { c as l, l as u, o as d, u as f } from "./kolmoSurface-DTnrFXH0.js";
3
+ import { c as p, o as m, r as h, u as g } from "./worldTypes-Z0KfdCd0.js";
4
+ import { a as _, b as v, d as y, h as b, i as x, l as S, o as C, r as w, t as T } from "./world-PRWPYrlx.js";
5
+ import { t as ee } from "./junk-B4bC1zAl.js";
6
+ import { Suspense as te, createContext as ne, useCallback as re, useContext as ie, useEffect as E, useLayoutEffect as D, useMemo as O, useRef as k, useState as ae } from "react";
7
+ import * as A from "three";
8
+ import { Canvas as j, useFrame as oe, useThree as se } from "@react-three/fiber";
9
+ import { KeyboardControls as M, useGLTF as N, useKeyboardControls as ce } from "@react-three/drei";
10
+ import { PhysicsWorld as P, cloneKhrBundle as le, loadKhrGlb as F, useKhrGlb as ue } from "@khr3/core";
11
+ import { useCustomGravity as de } from "@pinkaphant/ecctrl/gravity";
12
+ import { WorldProvider as fe, useTrait as pe } from "koota/react";
13
+ import { Fragment as me, jsx as I, jsxs as L } from "react/jsx-runtime";
14
+ import { CuboidCollider as he, RigidBody as R, TrimeshCollider as z } from "@react-three/rapier";
15
+ import { RoomEnvironment as ge } from "three/examples/jsm/environments/RoomEnvironment.js";
16
+ import { createActions as _e, createWorld as ve, relation as B, trait as ye } from "koota";
17
+ import { easing as be } from "maath";
18
+ import { KhrVehicle as xe } from "@khr3/core/vehicle";
19
+ import { Ecctrl as Se } from "@pinkaphant/ecctrl";
20
+ import { EcctrlCameraControls as Ce } from "@pinkaphant/ecctrl/camera";
21
+ import { instanceBatches as we, planSettlement as Te, poseToFloat as Ee } from "@khr3/c12";
22
+ import { mergeGeometries as De } from "three/examples/jsm/utils/BufferGeometryUtils.js";
23
+ // src/engine/kolmoRigs.tsx
24
+ function Oe({ intensity: e = .65 }) {
25
+ let { gl: t, scene: n } = se();
26
+ return E(() => {
27
+ let r = new A.PMREMGenerator(t), i = new ge(), a = r.fromScene(i, .04), o = n.environment, s = n.environmentIntensity;
28
+ return n.environment = a.texture, n.environmentIntensity = e, i.dispose(), r.dispose(), () => {
29
+ n.environment = o, n.environmentIntensity = s, a.dispose();
30
+ };
31
+ }, [
32
+ t,
33
+ n,
34
+ e
35
+ ]), null;
36
+ }
37
+ var V = new A.Vector2();
38
+ function ke({ onViewportChange: e } = {}) {
39
+ let { gl: n } = se(), r = k({
40
+ w: 0,
41
+ h: 0,
42
+ dpr: 0
43
+ });
44
+ return E(() => {
45
+ n.getDrawingBufferSize(V);
46
+ let i = n.getPixelRatio();
47
+ r.current = {
48
+ w: V.x,
49
+ h: V.y,
50
+ dpr: i
51
+ }, t(V.x, V.y, i), e?.(V.x, V.y, i);
52
+ }, [n, e]), oe(() => {
53
+ n.getDrawingBufferSize(V);
54
+ let i = n.getPixelRatio(), a = r.current;
55
+ (V.x !== a.w || V.y !== a.h || i !== a.dpr) && (a.w = V.x, a.h = V.y, a.dpr = i, t(V.x, V.y, i), e?.(V.x, V.y, i));
56
+ }), null;
57
+ }
58
+ var Ae = new A.Vector3(-120, 85, -120), je = new A.Vector3(0, 0, 0), Me = new A.Vector3(0, 1, 0), Ne = new A.Vector3(), Pe = new A.Vector3(), Fe = new A.Vector3();
59
+ new A.Matrix4().lookAt(Ae, je, Me).extractBasis(Ne, Pe, Fe);
60
+ function Ie({ sunLightRef: e }) {
61
+ return E(() => {
62
+ let t = e.current;
63
+ if (!t) return;
64
+ let n = t.shadow, r = n.updateMatrices;
65
+ return n.updateMatrices = function(e) {
66
+ if (e === t && t.castShadow) {
67
+ let e = n.camera, r = n.mapSize.x || 1024, i = Math.max(1, e.right - e.left) / r, a = Math.round(t.target.position.dot(Ne) / i) * i, o = Math.round(t.target.position.dot(Pe) / i) * i, s = t.target.position.dot(Fe);
68
+ t.target.position.set(0, 0, 0).addScaledVector(Ne, a).addScaledVector(Pe, o).addScaledVector(Fe, s), t.position.copy(t.target.position).add(Ae), t.updateMatrixWorld(), t.target.updateMatrixWorld();
69
+ }
70
+ return r.call(this, e);
71
+ }, () => {
72
+ n.updateMatrices = r;
73
+ };
74
+ }, [e]), null;
75
+ }
76
+ // src/engine/kolmoStore.ts
77
+ var H = ye(() => ({
78
+ id: "",
79
+ handle: null,
80
+ centerOfMass: [
81
+ 0,
82
+ 0,
83
+ 0
84
+ ],
85
+ seatOffset: [
86
+ 0,
87
+ .55,
88
+ 0
89
+ ],
90
+ exitOffset: [
91
+ -1.5,
92
+ .45,
93
+ 0
94
+ ],
95
+ isFlight: !1,
96
+ isTwoWheel: !1
97
+ })), U = ye(() => ({
98
+ id: "pilot",
99
+ handle: null,
100
+ exitSpawnPos: null,
101
+ exitSpawnYaw: 0,
102
+ exitLinVel: null
103
+ })), Le = ye(() => ({
104
+ id: "",
105
+ radius: 4,
106
+ kind: "vehicle"
107
+ })), Re = ye(() => ({
108
+ id: "",
109
+ getBody: () => null
110
+ })), ze = B({ exclusive: !0 }), W = ye(() => ({
111
+ activeVehicleId: null,
112
+ activeRetroPreset: "dreamcast"
113
+ })), G = ve(W), K = {
114
+ speedKmh: 0,
115
+ rpm: 0,
116
+ gear: 1,
117
+ throttle: 0,
118
+ boost: 0,
119
+ mode: "foot",
120
+ activeVehicleId: null,
121
+ activeRetroPreset: "dreamcast",
122
+ nearVehicleId: null
123
+ }, Be = new A.Vector3(), Ve = new A.Vector3(), q = _e((e) => ({
124
+ boardVehicle: (t) => {
125
+ let n = e.queryFirst(U);
126
+ for (let r of e.query(H)) if (r.get(H)?.id === t) {
127
+ n && n.add(ze(r));
128
+ break;
129
+ }
130
+ let r = e.get(W);
131
+ e.set(W, {
132
+ activeVehicleId: t,
133
+ activeRetroPreset: r?.activeRetroPreset ?? "dreamcast"
134
+ }), K.activeVehicleId = t, K.nearVehicleId = null;
135
+ },
136
+ exitVehicle: () => {
137
+ let t = e.get(W), n = t?.activeVehicleId, r = e.queryFirst(U);
138
+ for (let t of e.query(H)) {
139
+ let e = t.get(H);
140
+ if (e && e.id === n) {
141
+ if (r && (r.has(ze(t)) && r.remove(ze(t)), e.handle)) {
142
+ Be.set(e.exitOffset[0] - e.centerOfMass[0], e.exitOffset[1] - e.centerOfMass[1], e.exitOffset[2] - e.centerOfMass[2]).applyQuaternion(e.handle.currQuat).add(e.handle.currPos), Ve.copy(e.handle.bodyZAxis).projectOnPlane(e.handle.upAxis).normalize();
143
+ let t = Ve.lengthSq() > 1e-6 ? Math.atan2(Ve.x, Ve.z) : 0, n = e.handle.currLinVel;
144
+ r.set(U, {
145
+ id: r.get(U)?.id ?? "pilot",
146
+ handle: null,
147
+ exitSpawnPos: [
148
+ Be.x,
149
+ Be.y,
150
+ Be.z
151
+ ],
152
+ exitSpawnYaw: t,
153
+ exitLinVel: [
154
+ n.x,
155
+ n.y,
156
+ n.z
157
+ ]
158
+ });
159
+ }
160
+ e.handle?.setMovement({
161
+ forward: !1,
162
+ backward: !1,
163
+ steerLeft: !1,
164
+ steerRight: !1,
165
+ brake: !e.isFlight
166
+ });
167
+ }
168
+ }
169
+ e.set(W, {
170
+ activeVehicleId: null,
171
+ activeRetroPreset: t?.activeRetroPreset ?? "dreamcast"
172
+ }), Object.assign(K, {
173
+ activeVehicleId: null,
174
+ mode: "foot",
175
+ speedKmh: 0,
176
+ rpm: 0,
177
+ throttle: 0,
178
+ boost: 0
179
+ });
180
+ },
181
+ setRetroPreset: (t) => {
182
+ o(t);
183
+ let n = e.get(W);
184
+ e.set(W, {
185
+ activeVehicleId: n?.activeVehicleId ?? null,
186
+ activeRetroPreset: t
187
+ }), K.activeRetroPreset = t;
188
+ }
189
+ })), He = [
190
+ {
191
+ name: "forward",
192
+ keys: ["KeyW", "ArrowUp"]
193
+ },
194
+ {
195
+ name: "backward",
196
+ keys: ["KeyS", "ArrowDown"]
197
+ },
198
+ {
199
+ name: "left",
200
+ keys: ["KeyA", "ArrowLeft"]
201
+ },
202
+ {
203
+ name: "right",
204
+ keys: ["KeyD", "ArrowRight"]
205
+ },
206
+ {
207
+ name: "brake",
208
+ keys: ["Space"]
209
+ },
210
+ {
211
+ name: "boost",
212
+ keys: ["ShiftLeft", "ShiftRight"]
213
+ },
214
+ {
215
+ name: "interact",
216
+ keys: ["KeyF", "KeyE"]
217
+ },
218
+ {
219
+ name: "turnLeft",
220
+ keys: ["KeyQ"]
221
+ },
222
+ {
223
+ name: "turnRight",
224
+ keys: ["KeyC"]
225
+ },
226
+ {
227
+ name: "descend",
228
+ keys: ["KeyX", "ControlLeft"]
229
+ },
230
+ {
231
+ name: "cameraView",
232
+ keys: ["KeyV"]
233
+ }
234
+ ], Ue = ne(!1), We = new A.Vector3(), J = new A.Vector3();
235
+ function Ge({ children: e, className: t, style: n, fov: r = 56, near: i = .15, far: a = 6500, cameraPosition: o = [
236
+ 0,
237
+ 3.2,
238
+ -8.5
239
+ ], dpr: s = [1, 1.5], frameloop: c = "always", shadows: l = "basic", toneMapping: u, onCanvasReady: d, onContextLost: f, roomEnv: p = !1 }) {
240
+ return /* @__PURE__ */ L(j, {
241
+ className: t,
242
+ style: n ?? {
243
+ width: "100%",
244
+ height: "100%",
245
+ display: "block"
246
+ },
247
+ shadows: l,
248
+ dpr: s,
249
+ frameloop: c,
250
+ gl: {
251
+ antialias: !1,
252
+ powerPreference: "high-performance",
253
+ ...u === void 0 ? {} : { toneMapping: u }
254
+ },
255
+ camera: {
256
+ fov: r,
257
+ near: i,
258
+ far: a,
259
+ position: o
260
+ },
261
+ onCreated: ({ gl: e }) => {
262
+ e.outputColorSpace = A.SRGBColorSpace;
263
+ let t = e.domElement;
264
+ d?.(t), f && (t.addEventListener("webglcontextlost", (e) => {
265
+ e.preventDefault(), f(!0);
266
+ }), t.addEventListener("webglcontextrestored", () => f(!1)));
267
+ },
268
+ children: [p !== !1 && /* @__PURE__ */ I(Oe, { intensity: typeof p == "number" ? p : .65 }), e]
269
+ });
270
+ }
271
+ function Ke({ retroPreset: e }) {
272
+ let t = pe(G, W);
273
+ return E(() => {
274
+ e ? q(G).setRetroPreset(e) : t?.activeRetroPreset && o(t.activeRetroPreset);
275
+ }, [e, t?.activeRetroPreset]), null;
276
+ }
277
+ function qe({ gravity: e = "planar", paused: t = !1, timeScale: n = 1, physicsDebug: r = !1, retroPreset: i, skybox: a = "nebula", lighting: o = "default", fogExp2: c, sunLightRef: l, shadowSnap: u = !1, world: d = G, keyboardMap: f = He, children: p }) {
278
+ let m = typeof e == "function", h = Array.isArray(e), g = !m && !h && typeof e == "object" && e.kind === "point", _ = m || g, v = g ? e.center[0] : 0, y = g ? e.center[1] : 0, b = g ? e.center[2] : 0, x = g ? e.surfaceG : e === "zero" ? 0 : 9.81, S = O(() => h ? [
279
+ e[0],
280
+ e[1],
281
+ e[2]
282
+ ] : _ || e === "zero" ? [
283
+ 0,
284
+ 0,
285
+ 0
286
+ ] : [
287
+ 0,
288
+ -9.81,
289
+ 0
290
+ ], [
291
+ h,
292
+ _,
293
+ e
294
+ ]);
295
+ E(() => {
296
+ let t = de.getState().setGravityField;
297
+ if (m) t((t) => e(t, J));
298
+ else if (g) We.set(v, y, b), t((e) => {
299
+ J.subVectors(e, We);
300
+ let t = J.lengthSq();
301
+ return t < 1e-8 ? J.set(0, -x, 0) : J.multiplyScalar(-x / Math.sqrt(t));
302
+ });
303
+ else if (h) {
304
+ let n = e[0], r = e[1], i = e[2];
305
+ t(() => J.set(n, r, i));
306
+ } else t(e === "zero" ? () => J.set(0, 0, 0) : () => J.set(0, -9.81, 0));
307
+ }, [
308
+ m,
309
+ g,
310
+ h,
311
+ e,
312
+ v,
313
+ y,
314
+ b,
315
+ x
316
+ ]);
317
+ let C = /* @__PURE__ */ L(me, { children: [
318
+ /* @__PURE__ */ I(Ke, { retroPreset: i }),
319
+ u && l && /* @__PURE__ */ I(Ie, { sunLightRef: l }),
320
+ a === "nebula" && /* @__PURE__ */ I(s, {}),
321
+ a === "day" && /* @__PURE__ */ L(me, { children: [/* @__PURE__ */ I("color", {
322
+ attach: "background",
323
+ args: ["#6ba6d6"]
324
+ }), !c && /* @__PURE__ */ I("fog", {
325
+ attach: "fog",
326
+ args: [
327
+ "#9dc4e2",
328
+ 110,
329
+ 520
330
+ ]
331
+ })] }),
332
+ c && /* @__PURE__ */ I("fogExp2", {
333
+ attach: "fog",
334
+ args: c
335
+ }),
336
+ o === "default" && /* @__PURE__ */ L(me, { children: [
337
+ /* @__PURE__ */ I("hemisphereLight", { args: [
338
+ "#b8dcff",
339
+ "#241d30",
340
+ .8
341
+ ] }),
342
+ /* @__PURE__ */ I("directionalLight", {
343
+ ref: l,
344
+ position: [
345
+ 48,
346
+ 76,
347
+ 36
348
+ ],
349
+ intensity: 1.85,
350
+ color: "#fff3dc",
351
+ castShadow: !0,
352
+ "shadow-mapSize": [1024, 1024]
353
+ }),
354
+ /* @__PURE__ */ I("directionalLight", {
355
+ position: [
356
+ -42,
357
+ 28,
358
+ -50
359
+ ],
360
+ intensity: .55,
361
+ color: "#68a8ff"
362
+ })
363
+ ] }),
364
+ /* @__PURE__ */ I(P, {
365
+ paused: t,
366
+ timeScale: n,
367
+ gravity: S,
368
+ debug: r,
369
+ children: /* @__PURE__ */ I(te, {
370
+ fallback: null,
371
+ children: p
372
+ })
373
+ })
374
+ ] }), w = f ? /* @__PURE__ */ I(M, {
375
+ map: f,
376
+ children: C
377
+ }) : C, T = /* @__PURE__ */ I(Ue.Provider, {
378
+ value: _,
379
+ children: w
380
+ });
381
+ return d ? /* @__PURE__ */ I(fe, {
382
+ world: d,
383
+ children: T
384
+ }) : T;
385
+ }
386
+ // src/engine/kolmoVehicle.tsx
387
+ var Y = new A.Vector3(), X = new A.Vector3(), Je = new A.Vector3(), Ye = new A.Vector3(), Xe = new A.Vector3();
388
+ function Ze(e) {
389
+ e.traverse((e) => {
390
+ let t = e.userData?.gltfExtensions?.[l];
391
+ t && !e.userData.KOLMO_emitter && (e.userData[l] = t);
392
+ });
393
+ }
394
+ function Qe({ id: e, sourceBundle: t, rawGlbBytes: r, position: a = [
395
+ 0,
396
+ .35,
397
+ 0
398
+ ], rotation: o, piloted: s = !1, flightMode: c = !1, vehicleMode: l, twoWheel: p = !1, enable: m = !0, ccd: h, linearDamping: g, angularDamping: _, userData: v, onCollisionEnter: y, wheelConfig: b, carConfig: x, droneConfig: S, vehicleRef: C, driver: w, cameraController: T, children: ee }) {
399
+ let te = ie(Ue), ne = pe(G, W), [, ae] = ce(), j = O(() => le(t), [t]), se = O(() => d(j), [j]), M = O(() => (Ze(j.scene), f(j.scene, r)), [j, r]);
400
+ D(() => {
401
+ n(j.scene);
402
+ for (let e of j.wheels) n(e.object);
403
+ for (let e of j.propellers) n(e.object);
404
+ }, [j]);
405
+ let N = !!(l === "rocket" || c || l !== "drive" && j.propellers.length > 0), P = O(() => p || !!j.tune?.twoWheelBalance || j.wheels.length === 2 && Math.abs(j.wheels[0].position[0] - j.wheels[1].position[0]) < .25, [p, j]), F = O(() => M.sockets.find((e) => e.role === "seat" || e.role === "optic")?.localPosition ?? [
406
+ 0,
407
+ .65,
408
+ 0
409
+ ], [M]), ue = O(() => M.sockets.find((e) => e.role === "exit")?.localPosition ?? [
410
+ -1.55,
411
+ .45,
412
+ 0
413
+ ], [M]), de = O(() => ({
414
+ ...P ? {
415
+ twoWheelBalance: !0,
416
+ maxLeanAngle: .78
417
+ } : {},
418
+ ...j.tune ?? {},
419
+ ...x ?? {}
420
+ }), [
421
+ P,
422
+ j.tune,
423
+ x
424
+ ]), fe = O(() => {
425
+ if (b || l !== void 0) return {
426
+ ...l === void 0 ? {} : { enable: l === "drive" },
427
+ ...b ?? {}
428
+ };
429
+ }, [b, l]), me = O(() => N ? {
430
+ controlMode: "VELOCITY",
431
+ maxHorizSpeed: 46,
432
+ maxVertSpeed: 16,
433
+ maxYawRate: 2.3,
434
+ maxTiltAngle: .52,
435
+ HORIZ_VEL_P: 1.8,
436
+ VERT_VEL_P: 2.8,
437
+ ...j.droneTune ?? {},
438
+ ...S ?? {}
439
+ } : S, [
440
+ N,
441
+ j.droneTune,
442
+ S
443
+ ]), he = k(null), R = k(u()), z = k(new A.Vector3()), ge = k({
444
+ camInit: !1,
445
+ cockpit: !1,
446
+ prevCam: !1,
447
+ prevL: !1,
448
+ prevR: !1,
449
+ turnL: !1,
450
+ turnR: !1
451
+ }), _e = k({
452
+ forward: !1,
453
+ backward: !1,
454
+ steerLeft: !1,
455
+ steerRight: !1,
456
+ brake: !1,
457
+ throttleUp: !1,
458
+ throttleDown: !1,
459
+ yawLeft: !1,
460
+ yawRight: !1,
461
+ pitchForward: !1,
462
+ pitchBackward: !1,
463
+ rollLeft: !1,
464
+ rollRight: !1
465
+ });
466
+ E(() => {
467
+ let t = G.spawn(H({
468
+ id: e,
469
+ handle: he.current,
470
+ centerOfMass: [...j.centerOfMass],
471
+ seatOffset: F,
472
+ exitOffset: ue,
473
+ isFlight: N,
474
+ isTwoWheel: P
475
+ }), Le({
476
+ id: e,
477
+ radius: 4.2,
478
+ kind: "vehicle"
479
+ }));
480
+ return s && G.get(W)?.activeVehicleId === null && q(G).boardVehicle(e), () => {
481
+ G.get(W)?.activeVehicleId === e && q(G).exitVehicle(), t.destroy();
482
+ };
483
+ }, [
484
+ e,
485
+ j,
486
+ F,
487
+ ue,
488
+ N,
489
+ P,
490
+ s
491
+ ]);
492
+ let ve = re((t) => {
493
+ he.current = t, C && (C.current = t);
494
+ for (let n of G.query(H)) {
495
+ let r = n.get(H);
496
+ r && r.id === e && n.set(H, {
497
+ ...r,
498
+ handle: t
499
+ });
500
+ }
501
+ }, [e, C]), B = ne?.activeVehicleId === e || s && ne?.activeVehicleId === null;
502
+ return oe((t, n) => {
503
+ let r = Math.min(Math.max(n, 1e-4), .05);
504
+ se.step(r);
505
+ let i = he.current;
506
+ if (!i || !i.body) return;
507
+ if (w) {
508
+ w(i, r, t), T && T(i, r, t);
509
+ return;
510
+ }
511
+ let a = ae(), o = _e.current, s = R.current, c = ge.current;
512
+ if (B) {
513
+ if (a.cameraView && !c.prevCam && (c.cockpit = !c.cockpit), c.prevCam = a.cameraView, N) o.pitchForward = a.forward, o.pitchBackward = a.backward, o.yawLeft = a.left, o.yawRight = a.right, o.rollLeft = a.turnLeft, o.rollRight = a.turnRight, o.throttleUp = a.brake, o.throttleDown = a.descend, o.forward = !1, o.backward = !1, o.steerLeft = !1, o.steerRight = !1, o.brake = !1, a.boost && i.body.applyImpulse(Xe.copy(i.bodyZAxis).multiplyScalar(i.body.mass() * 14 * r), !1);
514
+ else if (a.turnLeft && !c.prevL && (c.turnL = !c.turnL, c.turnR = !1), a.turnRight && !c.prevR && (c.turnR = !c.turnR, c.turnL = !1), c.prevL = a.turnLeft, c.prevR = a.turnRight, o.forward = a.forward, o.backward = a.backward, o.steerLeft = a.left, o.steerRight = a.right, o.brake = a.brake, o.pitchForward = !1, o.pitchBackward = !1, o.throttleUp = !1, o.throttleDown = !1, o.yawLeft = !1, o.yawRight = !1, o.rollLeft = !1, o.rollRight = !1, a.boost && a.forward) {
515
+ for (let e of i.wheelsInfo.values()) if (e.current.rayHit) {
516
+ i.body.applyImpulse(Xe.copy(i.bodyZAxis).multiplyScalar(i.body.mass() * 6.5 * r), !1);
517
+ break;
518
+ }
519
+ }
520
+ i.setMovement(o);
521
+ }
522
+ let l = 0, u = 0;
523
+ for (let e of i.wheelsInfo.values()) e.current.rayHit && e.current.slipStrength > l && (l = e.current.slipStrength);
524
+ if (i.propellersInfo.size > 0) {
525
+ for (let e of i.propellersInfo.values()) u += e.current.finalThrottle;
526
+ u /= i.propellersInfo.size;
527
+ }
528
+ let d = i.currLinVel.dot(i.bodyZAxis);
529
+ if (s.throttle = B ? N ? a.forward || a.brake ? 1 : Math.max(.22, u) : +!!a.forward : 0, s.boost = B ? N ? a.boost ? 1 : a.forward ? .58 : .16 : a.boost && a.forward ? 1 : 0 : 0, s.brake = B && !N && (a.brake || a.backward && d > 1) ? 1 : 0, s.reverse = B && !N && a.backward && d <= 1 ? 1 : 0, s.slip = Math.min(1, l), s.turn_l = +!!c.turnL, s.turn_r = +!!c.turnR, s.headlight = 1, s.always = 1, !B) return;
530
+ if (K.speedKmh = i.currLinVel.length() * 3.6, K.rpm = Math.round(N ? 1800 + s.throttle * 6200 + s.boost * 4200 : i.engineRPM), K.gear = N ? a.boost ? 2 : 1 : i.gearIndex + 1, K.throttle = s.throttle, K.boost = s.boost, K.mode = N ? "flight" : P ? "motorcycle" : "car", K.activeVehicleId = e, T) {
531
+ T(i, r, t);
532
+ return;
533
+ }
534
+ if (Y.copy(i.upAxis), Y.lengthSq() < 1e-6 && Y.copy(i.bodyYAxis), c.cockpit) {
535
+ let e = j.centerOfMass;
536
+ Je.set(F[0] - e[0], F[1] - e[1] + .32, F[2] - e[2]).applyQuaternion(i.currQuat).add(i.currPos), Ye.copy(Je).addScaledVector(i.bodyZAxis, 24), be.damp3(t.camera.position, Je, .04, r), be.damp3(t.camera.up, i.bodyYAxis, .08, r), t.camera.lookAt(Ye);
537
+ return;
538
+ }
539
+ X.copy(i.bodyZAxis), N || X.projectOnPlane(Y).normalize(), X.lengthSq() < 1e-6 && X.copy(i.bodyZAxis);
540
+ let f = N ? 11.2 : P ? 5.2 : 6.8, p = N ? 3.1 : P ? 1.85 : 2.15;
541
+ Je.copy(i.currPos).addScaledVector(X, -f).addScaledVector(Y, p), Ye.copy(i.currPos).addScaledVector(X, N ? 7.5 : 3.6).addScaledVector(Y, .65), c.camInit ||= (t.camera.position.copy(Je), z.current.copy(Ye), !0), be.damp3(t.camera.position, Je, .14, r), be.damp3(z.current, Ye, .08, r), be.damp3(t.camera.up, Y, .16, r), t.camera.lookAt(z.current);
542
+ }), /* @__PURE__ */ I("group", {
543
+ onClick: (e) => {
544
+ e.delta <= 5 && se.toggleHitObject(e.object) && e.stopPropagation();
545
+ },
546
+ children: /* @__PURE__ */ L(xe, {
547
+ ref: ve,
548
+ bundle: j,
549
+ position: a,
550
+ rotation: o,
551
+ enable: m,
552
+ ccd: h,
553
+ linearDamping: g,
554
+ angularDamping: _,
555
+ userData: v,
556
+ onCollisionEnter: y,
557
+ enableCustomGravity: te,
558
+ wheelConfig: fe,
559
+ carConfig: de,
560
+ droneConfig: me,
561
+ children: [/* @__PURE__ */ I(i, {
562
+ emitters: M.emitters,
563
+ signalsRef: R
564
+ }), ee]
565
+ })
566
+ });
567
+ }
568
+ function $e(e) {
569
+ return /* @__PURE__ */ I(Qe, {
570
+ ...e,
571
+ sourceBundle: ue(e.src)
572
+ });
573
+ }
574
+ function et(e) {
575
+ let [t, n] = ae(null);
576
+ return E(() => {
577
+ if (e.bundle || e.src || !e.rawGlbBytes) return;
578
+ let t = !0;
579
+ return F(e.rawGlbBytes).then((e) => {
580
+ t && n(e);
581
+ }), () => {
582
+ t = !1;
583
+ };
584
+ }, [
585
+ e.bundle,
586
+ e.src,
587
+ e.rawGlbBytes
588
+ ]), e.bundle ? /* @__PURE__ */ I(Qe, {
589
+ ...e,
590
+ sourceBundle: e.bundle
591
+ }) : e.src ? /* @__PURE__ */ I($e, {
592
+ ...e,
593
+ src: e.src
594
+ }) : t ? /* @__PURE__ */ I(Qe, {
595
+ ...e,
596
+ sourceBundle: t
597
+ }) : null;
598
+ }
599
+ // src/engine/kolmoActor.tsx
600
+ var tt = new A.Vector3();
601
+ function nt() {
602
+ let t = O(() => ({
603
+ suit: e(new A.MeshStandardMaterial({
604
+ color: "#e2e8f0",
605
+ roughness: .55,
606
+ metalness: .15
607
+ })),
608
+ visor: e(new A.MeshStandardMaterial({
609
+ color: "#38bdf8",
610
+ emissive: "#0284c7",
611
+ emissiveIntensity: .55,
612
+ roughness: .2
613
+ })),
614
+ pack: e(new A.MeshStandardMaterial({
615
+ color: "#334155",
616
+ roughness: .7
617
+ }))
618
+ }), []);
619
+ return D(() => () => {
620
+ t.suit.dispose(), t.visor.dispose(), t.pack.dispose();
621
+ }, [t]), /* @__PURE__ */ L("group", { children: [
622
+ /* @__PURE__ */ I("mesh", {
623
+ castShadow: !0,
624
+ material: t.suit,
625
+ children: /* @__PURE__ */ I("capsuleGeometry", { args: [
626
+ .28,
627
+ .56,
628
+ 6,
629
+ 12
630
+ ] })
631
+ }),
632
+ /* @__PURE__ */ I("mesh", {
633
+ position: [
634
+ 0,
635
+ .24,
636
+ .22
637
+ ],
638
+ material: t.visor,
639
+ children: /* @__PURE__ */ I("boxGeometry", { args: [
640
+ .34,
641
+ .16,
642
+ .14
643
+ ] })
644
+ }),
645
+ /* @__PURE__ */ I("mesh", {
646
+ position: [
647
+ 0,
648
+ .06,
649
+ -.24
650
+ ],
651
+ castShadow: !0,
652
+ material: t.pack,
653
+ children: /* @__PURE__ */ I("boxGeometry", { args: [
654
+ .32,
655
+ .42,
656
+ .16
657
+ ] })
658
+ })
659
+ ] });
660
+ }
661
+ function rt({ position: e = [
662
+ 0,
663
+ 1.4,
664
+ 0
665
+ ], enabled: t = !0 }) {
666
+ let n = ie(Ue), r = pe(G, W), [, i] = ce(), a = k(null), o = k(null), s = k(new A.Vector3()), c = k(new A.Vector3(0, 1, 0)), l = k(!1), u = k(0), d = k({
667
+ forward: !1,
668
+ backward: !1,
669
+ leftward: !1,
670
+ rightward: !1,
671
+ run: !1,
672
+ jump: !1
673
+ });
674
+ E(() => {
675
+ let e = G.spawn(U({
676
+ id: "pilot",
677
+ handle: null,
678
+ exitSpawnPos: null,
679
+ exitSpawnYaw: 0,
680
+ exitLinVel: null
681
+ }));
682
+ return () => {
683
+ e.destroy();
684
+ };
685
+ }, []);
686
+ let f = re((e) => {
687
+ a.current = e;
688
+ let t = G.queryFirst(U);
689
+ if (t) {
690
+ let n = t.get(U);
691
+ e?.body && n?.exitLinVel && e.body.setLinvel({
692
+ x: n.exitLinVel[0],
693
+ y: n.exitLinVel[1],
694
+ z: n.exitLinVel[2]
695
+ }, !0), t.set(U, {
696
+ id: n?.id ?? "pilot",
697
+ handle: e,
698
+ exitSpawnPos: n?.exitSpawnPos ?? null,
699
+ exitSpawnYaw: n?.exitSpawnYaw ?? 0,
700
+ exitLinVel: e?.body ? null : n?.exitLinVel ?? null
701
+ });
702
+ }
703
+ }, []), p = r?.activeVehicleId ?? null, m = t && p === null, h = G.queryFirst(U)?.get(U), g = h?.exitSpawnPos ?? e, _ = O(() => [
704
+ 0,
705
+ h?.exitSpawnYaw ?? 0,
706
+ 0
707
+ ], [h?.exitSpawnYaw]);
708
+ return oe((e, n) => {
709
+ if (!t) return;
710
+ let r = Math.min(Math.max(n, 1e-4), .05);
711
+ u.current > 0 && (u.current = Math.max(0, u.current - r));
712
+ let f = i(), m = f.interact && !l.current;
713
+ if (l.current = f.interact, p !== null) {
714
+ m && u.current === 0 && (u.current = .25, q(G).exitVehicle());
715
+ return;
716
+ }
717
+ let h = a.current;
718
+ if (!h || !h.body) return;
719
+ let g = d.current;
720
+ g.forward = f.forward, g.backward = f.backward, g.leftward = f.left, g.rightward = f.right, g.run = f.boost, g.jump = f.brake, h.setMovement(g), K.mode = "foot", K.speedKmh = h.moveSpeed * 3.6, K.rpm = 0, K.gear = 0, K.throttle = +!!h.isMoving, K.boost = f.boost && h.isMoving ? 1 : 0;
721
+ let _ = null, v = Infinity;
722
+ for (let e of G.query(H, Le)) {
723
+ let t = e.get(H), n = e.get(Le);
724
+ if (!t?.handle || !n) continue;
725
+ tt.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);
726
+ let r = h.currPos.distanceToSquared(tt);
727
+ r <= n.radius * n.radius && r < v && (v = r, _ = t.id);
728
+ }
729
+ K.nearVehicleId = _, m && _ && u.current === 0 ? (u.current = .25, q(G).boardVehicle(_)) : o.current && h.currPos.lengthSq() > 0 && (s.current.copy(h.currPos).addScaledVector(h.bodyYAxis, .55), c.current.copy(h.upAxis), o.current.moveTo(s.current.x, s.current.y, s.current.z, !0), e.camera.up.lerp(c.current, .14), o.current.setUp(e.camera.up));
730
+ }), m ? /* @__PURE__ */ L(me, { children: [/* @__PURE__ */ I(Ce, {
731
+ ref: o,
732
+ makeDefault: !0,
733
+ minPolarAngle: .12,
734
+ maxPolarAngle: Math.PI - .12,
735
+ smoothTime: .08
736
+ }), /* @__PURE__ */ I(Se, {
737
+ ref: f,
738
+ position: g,
739
+ rotation: _,
740
+ enableCustomGravity: n,
741
+ maxWalkVel: 3.2,
742
+ maxRunVel: 7.2,
743
+ jumpVel: 5.8,
744
+ userData: { ecctrl: { excludeVehicleRay: !0 } },
745
+ children: /* @__PURE__ */ I(nt, {})
746
+ })] }) : null;
747
+ }
748
+ // src/engine/kolmoIsland.tsx
749
+ var it = /* @__PURE__ */ new Map();
750
+ function at(e = 77, t = 960) {
751
+ let n = `${e}:${t}`, r = it.get(n);
752
+ return r || (r = b(e, { size: t }), it.set(n, r)), r;
753
+ }
754
+ function ot(e = 77, t = 960) {
755
+ let n = at(e, t), r = n.road.at(n.road.length * .48), i = Math.atan2(r.tangent[0], r.tangent[2]);
756
+ return {
757
+ vehiclePos: [
758
+ r.pos[0],
759
+ r.pos[1] + .45,
760
+ r.pos[2]
761
+ ],
762
+ vehicleRot: [
763
+ 0,
764
+ i,
765
+ 0
766
+ ],
767
+ actorPos: [
768
+ r.pos[0] + r.left[0] * (n.road.halfWidth + 2),
769
+ r.pos[1] + 1.5,
770
+ r.pos[2] + r.left[2] * (n.road.halfWidth + 2)
771
+ ]
772
+ };
773
+ }
774
+ function st(e) {
775
+ if (e === "FoundationSquare") {
776
+ let e = new A.BoxGeometry(3, .36, 3);
777
+ return e.translate(0, -.18, 0), {
778
+ geo: e,
779
+ color: "#64748b"
780
+ };
781
+ }
782
+ if (e === "Street") {
783
+ let e = new A.BoxGeometry(3, .14, 3);
784
+ return e.translate(0, .05, 0), {
785
+ geo: e,
786
+ color: "#475569"
787
+ };
788
+ }
789
+ if (e === "Wall") {
790
+ let e = new A.BoxGeometry(3, 3, .22);
791
+ return e.translate(0, 1.5, 0), {
792
+ geo: e,
793
+ color: "#cbd5e1"
794
+ };
795
+ }
796
+ if (e === "Doorway") {
797
+ let e = new A.BoxGeometry(3, .85, .24);
798
+ return e.translate(0, 2.575, 0), {
799
+ geo: e,
800
+ color: "#94a3b8"
801
+ };
802
+ }
803
+ if (e === "DoorLeaf") {
804
+ let e = new A.BoxGeometry(.92, 2.12, .1);
805
+ return e.translate(0, 1.06, 0), {
806
+ geo: e,
807
+ color: "#d97706"
808
+ };
809
+ }
810
+ if (e === "Stairs") {
811
+ let e = new A.BoxGeometry(1.4, .24, 3.8);
812
+ return e.rotateX(-Math.PI / 4), e.translate(0, 1.5, 0), {
813
+ geo: e,
814
+ color: "#a16207"
815
+ };
816
+ }
817
+ if (e === "Roof") {
818
+ let e = new A.BoxGeometry(3.16, .26, 3.16);
819
+ return e.translate(0, .13, 0), {
820
+ geo: e,
821
+ color: "#be123c"
822
+ };
823
+ }
824
+ let t = new A.BoxGeometry(3, .2, 3);
825
+ return t.translate(0, .1, 0), {
826
+ geo: t,
827
+ color: "#94a3b8"
828
+ };
829
+ }
830
+ function ct({ matrices: e, count: t, geo: n, mat: r }) {
831
+ let i = k(null);
832
+ return D(() => {
833
+ let t = i.current;
834
+ t && (t.instanceMatrix.array.set(e), t.instanceMatrix.needsUpdate = !0, t.computeBoundingSphere());
835
+ }, [e, t]), /* @__PURE__ */ I("instancedMesh", {
836
+ ref: i,
837
+ args: [
838
+ n,
839
+ r,
840
+ t
841
+ ],
842
+ frustumCulled: !1
843
+ });
844
+ }
845
+ function lt({ seed: t = 77, size: n = 960, segments: i = 160, settlementTier: o = "town" }) {
846
+ let s = O(() => at(t, n), [t, n]), { spurs: l, junctions: u } = O(() => x(s, 2), [s]), d = O(() => h(s, 256, l), [s, l]), f = O(() => T(s.terrain, s.size, i), [s, i]), m = O(() => w(s.road, { tJunctions: u }), [s, u]), _ = O(() => l.map((e) => w(e, { crownHeight: .03 })), [l]), v = O(() => Te(s.road, o, t), [
847
+ s,
848
+ o,
849
+ t
850
+ ]), y = O(() => we(v.pieces), [v]), b = O(() => {
851
+ let t = c(d), { material: n, depthMaterial: i } = a(t, {
852
+ ditherTexelsPerMeter: 16,
853
+ ps2ColorQuantize: .85
854
+ }), { material: o } = r(t, {
855
+ preset: "ASPHALT",
856
+ ditherTexelsPerMeter: 16,
857
+ ps2ColorQuantize: .85
858
+ }), { material: s } = r(t, {
859
+ preset: "DIRT",
860
+ ditherTexelsPerMeter: 16,
861
+ ps2ColorQuantize: .85
862
+ }), l = new A.MeshLambertMaterial({
863
+ color: "#125274",
864
+ transparent: !0,
865
+ opacity: .84,
866
+ fog: !0
867
+ }), u = new A.MeshLambertMaterial({
868
+ color: "#2d4c24",
869
+ flatShading: !0,
870
+ fog: !0
871
+ });
872
+ return e(u, { flatShading: !0 }), {
873
+ tex: t,
874
+ terrainMat: n,
875
+ terrainDepthMat: i,
876
+ asphaltMat: o,
877
+ dirtMat: s,
878
+ waterMat: l,
879
+ treeMat: u
880
+ };
881
+ }, [d]), S = O(() => {
882
+ let t = /* @__PURE__ */ new Map();
883
+ for (let n of y) {
884
+ let { geo: r, color: i } = st(n.kind), a = new A.MeshStandardMaterial({
885
+ color: i,
886
+ roughness: .82,
887
+ flatShading: !0
888
+ });
889
+ e(a, { flatShading: !0 }), t.set(n.kind, {
890
+ geo: r,
891
+ mat: a
892
+ });
893
+ }
894
+ return t;
895
+ }, [y]), C = O(() => {
896
+ let e = g(p(t, "island-trees")), n = [], r = new A.Object3D(), i = v.buildings.map((e) => ({
897
+ p: Ee(e.pose).position,
898
+ r: Math.hypot(e.width, e.depth) * 2.2
899
+ }));
900
+ for (let t = 0; t < 950 && n.length < 3520; t++) {
901
+ let t = (e() - .5) * s.size * .82, a = (e() - .5) * s.size * .82, o = s.terrain.height(t, a);
902
+ if (o < s.waterLevel + 2.4 || o > 40 || s.terrain.roadMask(t, a).exclude || i.some((e) => Math.hypot(t - e.p[0], a - e.p[2]) < e.r)) continue;
903
+ let c = .85 + e() * .8;
904
+ r.position.set(t, o + 2.1 * c, a), r.rotation.set(0, e() * Math.PI * 2, 0), r.scale.set(c, c, c), r.updateMatrix(), n.push(...r.matrix.elements);
905
+ }
906
+ return {
907
+ geo: new A.ConeGeometry(1.5, 4.6, 6),
908
+ matrices: new Float32Array(n),
909
+ count: n.length / 16
910
+ };
911
+ }, [
912
+ s,
913
+ v,
914
+ t
915
+ ]);
916
+ return E(() => () => {
917
+ b.tex.dispose(), f.geometry.dispose(), m.geometry.dispose(), _.forEach((e) => e.geometry.dispose()), C.geo.dispose();
918
+ }, [
919
+ b,
920
+ f,
921
+ m,
922
+ _,
923
+ C
924
+ ]), /* @__PURE__ */ L("group", { children: [
925
+ /* @__PURE__ */ I("fogExp2", {
926
+ attach: "fog",
927
+ args: [10335428, .00145]
928
+ }),
929
+ /* @__PURE__ */ I("hemisphereLight", { args: [
930
+ 11059416,
931
+ 5392440,
932
+ .72
933
+ ] }),
934
+ /* @__PURE__ */ L(R, {
935
+ type: "fixed",
936
+ colliders: !1,
937
+ friction: .9,
938
+ children: [/* @__PURE__ */ I(z, { args: [f.colliderVertices, f.colliderIndices] }), /* @__PURE__ */ I("mesh", {
939
+ geometry: f.geometry,
940
+ material: b.terrainMat,
941
+ customDepthMaterial: b.terrainDepthMat,
942
+ castShadow: !0,
943
+ receiveShadow: !0
944
+ })]
945
+ }),
946
+ /* @__PURE__ */ L(R, {
947
+ type: "fixed",
948
+ colliders: !1,
949
+ friction: 1.05,
950
+ children: [/* @__PURE__ */ I(z, { args: [m.colliderVertices, m.colliderIndices] }), /* @__PURE__ */ I("mesh", {
951
+ geometry: m.geometry,
952
+ material: b.asphaltMat,
953
+ receiveShadow: !0
954
+ })]
955
+ }),
956
+ _.map((e, t) => /* @__PURE__ */ L(R, {
957
+ type: "fixed",
958
+ colliders: !1,
959
+ friction: .85,
960
+ children: [/* @__PURE__ */ I(z, { args: [e.colliderVertices, e.colliderIndices] }), /* @__PURE__ */ I("mesh", {
961
+ geometry: e.geometry,
962
+ material: b.dirtMat,
963
+ receiveShadow: !0
964
+ })]
965
+ }, `spur_${t}`)),
966
+ /* @__PURE__ */ I("mesh", {
967
+ position: [
968
+ 0,
969
+ s.waterLevel,
970
+ 0
971
+ ],
972
+ rotation: [
973
+ -Math.PI * .5,
974
+ 0,
975
+ 0
976
+ ],
977
+ material: b.waterMat,
978
+ children: /* @__PURE__ */ I("planeGeometry", { args: [s.size * 1.8, s.size * 1.8] })
979
+ }),
980
+ y.map((e) => {
981
+ let t = S.get(e.kind);
982
+ return /* @__PURE__ */ I(ct, {
983
+ matrices: e.matrices,
984
+ count: e.count,
985
+ geo: t.geo,
986
+ mat: t.mat
987
+ }, e.kind);
988
+ }),
989
+ /* @__PURE__ */ I(R, {
990
+ type: "fixed",
991
+ colliders: !1,
992
+ children: v.buildings.map((e) => {
993
+ let { position: t, yaw: n } = Ee(e.pose);
994
+ return /* @__PURE__ */ I(he, {
995
+ position: [
996
+ t[0],
997
+ t[1] + e.storeys * 1.5,
998
+ t[2]
999
+ ],
1000
+ rotation: [
1001
+ 0,
1002
+ n,
1003
+ 0
1004
+ ],
1005
+ args: [
1006
+ e.width * 1.5,
1007
+ e.storeys * 1.5,
1008
+ e.depth * 1.5
1009
+ ]
1010
+ }, e.id);
1011
+ })
1012
+ }),
1013
+ C.count > 0 && /* @__PURE__ */ I(ct, {
1014
+ matrices: C.matrices,
1015
+ count: C.count,
1016
+ geo: C.geo,
1017
+ mat: b.treeMat
1018
+ })
1019
+ ] });
1020
+ }
1021
+ // src/engine/longDriveKit.tsx
1022
+ var Z = "https://khr3.optimuspi.workers.dev/assets", ut = {
1023
+ road_straight: `${Z}/city/R_Straight_6x6.glb`,
1024
+ road_crosswalk: `${Z}/city/R_Crosswalk_6x6.glb`,
1025
+ road_intersection: `${Z}/city/R_Intersection_6x6.glb`,
1026
+ curb_straight: `${Z}/city/S_Straight_3x6.glb`,
1027
+ curb_ramp: `${Z}/city/S_AccessibleRamp_3x6.glb`,
1028
+ curb_driveway: `${Z}/city/S_Driveway_3x6.glb`,
1029
+ light_pole: `${Z}/city/L_LightPole_12gon.glb`
1030
+ }, dt = {
1031
+ canopy: `${Z}/city/gas-canopy-roof.glb`,
1032
+ pump: `${Z}/city/gas-pump-twin.glb`,
1033
+ sign: `${Z}/city/neon-petro-sign.glb`
1034
+ }, ft = /* @__PURE__ */ new Map();
1035
+ function pt(t, n, r) {
1036
+ let i = ft.get(n);
1037
+ if (i) return i;
1038
+ t.updateMatrixWorld(!0);
1039
+ let a = new A.Matrix4().copy(t.matrixWorld).invert(), o = new A.Matrix4(), s = [], c = null;
1040
+ t.traverse((e) => {
1041
+ if (!(e instanceof A.Mesh) || !e.geometry) return;
1042
+ let t = e.geometry.index ? e.geometry.toNonIndexed() : e.geometry.clone();
1043
+ t.applyMatrix4(o.multiplyMatrices(a, e.matrixWorld));
1044
+ for (let e of Object.keys(t.attributes)) e !== "position" && e !== "normal" && e !== "uv" && e !== "color" && t.deleteAttribute(e);
1045
+ if (t.getAttribute("normal") || t.computeVertexNormals(), !t.getAttribute("uv")) {
1046
+ let e = t.getAttribute("position").count;
1047
+ t.setAttribute("uv", new A.BufferAttribute(new Float32Array(e * 2), 2));
1048
+ }
1049
+ s.push(t), !c && e.material && (c = (Array.isArray(e.material) ? e.material[0] : e.material).clone());
1050
+ });
1051
+ let l = s.length > 0 ? De(s, !1) ?? s[0] : new A.BoxGeometry(r[0], r[1], r[2]);
1052
+ l.computeBoundingBox();
1053
+ let u = l.boundingBox, d = u.getSize(new A.Vector3()), f = u.getCenter(new A.Vector3()), p = r[0] / Math.max(d.x, 1e-4), m = r[1] / Math.max(d.y, 1e-4), h = r[2] / Math.max(d.z, 1e-4), g = n === "light_pole" ? m : Math.min(p, h);
1054
+ l.translate(-f.x, -u.min.y, -f.z), l.scale(n === "light_pole" ? g : p, n === "light_pole" ? m : g, n === "light_pole" ? g : h), l.computeBoundingSphere();
1055
+ let _ = c ?? new A.MeshLambertMaterial({
1056
+ color: "#64748b",
1057
+ flatShading: !0
1058
+ });
1059
+ e(_, { flatShading: !0 });
1060
+ let v = {
1061
+ geometry: l,
1062
+ material: _
1063
+ };
1064
+ return ft.set(n, v), v;
1065
+ }
1066
+ function Q({ kitKey: e, fitSpan: t, matrices: n }) {
1067
+ let r = n.length / 16, i = N(ut[e]), a = k(null), o = O(() => pt(i.scene, e, t), [
1068
+ i.scene,
1069
+ e,
1070
+ t
1071
+ ]);
1072
+ return D(() => {
1073
+ a.current && r !== 0 && (a.current.instanceMatrix.array.set(n), a.current.instanceMatrix.needsUpdate = !0, a.current.computeBoundingSphere());
1074
+ }, [n, r]), r > 0 ? /* @__PURE__ */ I("instancedMesh", {
1075
+ ref: a,
1076
+ args: [
1077
+ o.geometry,
1078
+ o.material,
1079
+ r
1080
+ ],
1081
+ frustumCulled: !1,
1082
+ receiveShadow: !0
1083
+ }) : null;
1084
+ }
1085
+ function $({ matrices: t, kind: n, color: r }) {
1086
+ let i = k(null), a = t.length / 16, o = O(() => {
1087
+ if (n === "triangle") {
1088
+ let e = 3 * Math.sqrt(3) * .5, t = new A.Shape([
1089
+ new A.Vector2(-1.5, 0),
1090
+ new A.Vector2(1.5, 0),
1091
+ new A.Vector2(0, e)
1092
+ ]), n = new A.ExtrudeGeometry(t, {
1093
+ depth: .24,
1094
+ bevelEnabled: !1
1095
+ });
1096
+ return n.rotateX(-Math.PI * .5), n;
1097
+ }
1098
+ return n === "wall" ? new A.BoxGeometry(3, 3, .22) : n === "roof" ? new A.BoxGeometry(3.08, .24, 3.08) : new A.BoxGeometry(3, .24, 3);
1099
+ }, [n]), s = O(() => e(new A.MeshLambertMaterial({
1100
+ color: r,
1101
+ flatShading: !0
1102
+ }), { flatShading: !0 }), [r]);
1103
+ return D(() => {
1104
+ i.current && a !== 0 && (i.current.instanceMatrix.array.set(t), i.current.instanceMatrix.needsUpdate = !0, i.current.computeBoundingSphere());
1105
+ }, [t, a]), a > 0 ? /* @__PURE__ */ I("instancedMesh", {
1106
+ ref: i,
1107
+ args: [
1108
+ o,
1109
+ s,
1110
+ a
1111
+ ],
1112
+ frustumCulled: !1,
1113
+ castShadow: !0,
1114
+ receiveShadow: !0
1115
+ }) : null;
1116
+ }
1117
+ function mt({ stop: e, groundY: t, cellTag: r }) {
1118
+ let i = N(dt.canopy), a = N(dt.pump), o = N(dt.sign), s = O(() => {
1119
+ let e = (e, t) => {
1120
+ let r = e.clone(!0);
1121
+ r.updateMatrixWorld(!0);
1122
+ let i = new A.Box3().setFromObject(r), a = i.getSize(new A.Vector3()), o = i.getCenter(new A.Vector3()), s = t / Math.max(a.y, .1);
1123
+ return r.scale.setScalar(s), r.position.set(-o.x * s, -i.min.y * s, -o.z * s), n(r), r;
1124
+ };
1125
+ return {
1126
+ canopy: e(i.scene, 4.6),
1127
+ pumpA: e(a.scene, 2.1),
1128
+ pumpB: e(a.scene, 2.1),
1129
+ sign: e(o.scene, 6.8)
1130
+ };
1131
+ }, [
1132
+ i.scene,
1133
+ a.scene,
1134
+ o.scene
1135
+ ]);
1136
+ return /* @__PURE__ */ L("group", {
1137
+ position: [
1138
+ e.worldX,
1139
+ t,
1140
+ e.worldZ
1141
+ ],
1142
+ rotation: [
1143
+ 0,
1144
+ e.yaw,
1145
+ 0
1146
+ ],
1147
+ children: [
1148
+ /* @__PURE__ */ L(R, {
1149
+ type: "fixed",
1150
+ colliders: !1,
1151
+ children: [/* @__PURE__ */ I(he, {
1152
+ args: [
1153
+ e.widthMeters * .5,
1154
+ .12,
1155
+ e.depthMeters * .5
1156
+ ],
1157
+ position: [
1158
+ 0,
1159
+ .12,
1160
+ 0
1161
+ ]
1162
+ }), /* @__PURE__ */ L("mesh", {
1163
+ position: [
1164
+ 0,
1165
+ .08,
1166
+ 0
1167
+ ],
1168
+ receiveShadow: !0,
1169
+ children: [/* @__PURE__ */ I("boxGeometry", { args: [
1170
+ e.widthMeters,
1171
+ .16,
1172
+ e.depthMeters
1173
+ ] }), /* @__PURE__ */ I("meshLambertMaterial", {
1174
+ color: "#475569",
1175
+ flatShading: !0
1176
+ })]
1177
+ })]
1178
+ }),
1179
+ /* @__PURE__ */ I("primitive", {
1180
+ object: s.canopy,
1181
+ position: [
1182
+ 0,
1183
+ .16,
1184
+ 0
1185
+ ]
1186
+ }),
1187
+ e.kind === "GAS_STATION" && /* @__PURE__ */ L(me, { children: [
1188
+ /* @__PURE__ */ I("primitive", {
1189
+ object: s.pumpA,
1190
+ position: [
1191
+ -2.4,
1192
+ .16,
1193
+ 0
1194
+ ]
1195
+ }),
1196
+ /* @__PURE__ */ I("primitive", {
1197
+ object: s.pumpB,
1198
+ position: [
1199
+ 2.4,
1200
+ .16,
1201
+ 0
1202
+ ]
1203
+ }),
1204
+ /* @__PURE__ */ I("primitive", {
1205
+ object: s.sign,
1206
+ position: [
1207
+ e.widthMeters * .42,
1208
+ .16,
1209
+ e.depthMeters * .36
1210
+ ]
1211
+ })
1212
+ ] }),
1213
+ /* @__PURE__ */ I(ee, {
1214
+ id: `${r}_can`,
1215
+ kind: "tin-can",
1216
+ labelId: "tris-soda",
1217
+ position: [
1218
+ 1.1,
1219
+ .55,
1220
+ 1.4
1221
+ ]
1222
+ }),
1223
+ /* @__PURE__ */ I(ee, {
1224
+ id: `${r}_bot`,
1225
+ kind: "glass-bottle",
1226
+ position: [
1227
+ -1.1,
1228
+ .55,
1229
+ 1.4
1230
+ ]
1231
+ })
1232
+ ]
1233
+ });
1234
+ }
1235
+ // src/engine/mainlandMacroCell.tsx
1236
+ function ht({ x: e, z: t, friction: n = 1, children: r }) {
1237
+ let i = k(null);
1238
+ return D(() => {
1239
+ i.current?.setTranslation({
1240
+ x: e,
1241
+ y: 0,
1242
+ z: t
1243
+ }, !1);
1244
+ }, [e, t]), /* @__PURE__ */ I(R, {
1245
+ ref: i,
1246
+ type: "fixed",
1247
+ position: [
1248
+ e,
1249
+ 0,
1250
+ t
1251
+ ],
1252
+ colliders: !1,
1253
+ friction: n,
1254
+ children: r
1255
+ });
1256
+ }
1257
+ function gt({ mx: e, mz: t, planner: n, roadMat: r, terrainMat: i, offX: a, offZ: o, renderExtra: s }) {
1258
+ let c = O(() => {
1259
+ let r = n.generateMacroCell2D(e, t), i = r.highwayPolylines.filter((e) => e.length >= 2).map((e) => {
1260
+ let t = e.map(([e, t]) => [
1261
+ e,
1262
+ Math.max(2, n.sampleMainlandHeight(e, t)),
1263
+ t
1264
+ ]);
1265
+ for (let e = 0; e < 4; e++) for (let e = 1; e < t.length - 1; e++) t[e] = [
1266
+ t[e][0],
1267
+ .5 * t[e][1] + .25 * (t[e - 1][1] + t[e + 1][1]),
1268
+ t[e][2]
1269
+ ];
1270
+ return v(t, 4.5, 4, !1);
1271
+ }), a = i.map((e) => w(e)), o = Math.max(2.5, n.sampleMainlandHeight(r.hubX, r.hubZ)), s = (e, t) => r.settlementRadiusM > 0 && Math.hypot(e - r.hubX, t - r.hubZ) <= r.settlementRadiusM + 18 ? o : n.sampleMainlandHeight(e, t), c = i[0] ?? v([[
1272
+ r.originWorldX - 20,
1273
+ o,
1274
+ r.originWorldZ
1275
+ ], [
1276
+ r.originWorldX + 20,
1277
+ o,
1278
+ r.originWorldZ
1279
+ ]], 4.5, 4, !1), l = m(e * 73856093 ^ t * 19349663, c, {
1280
+ amplitude: 28,
1281
+ noise: {
1282
+ wavelength: 300,
1283
+ octaves: 2,
1284
+ gain: .5,
1285
+ lacunarity: 2
1286
+ },
1287
+ maxSlope: .55,
1288
+ minShoulder: 8,
1289
+ verge: 3.5,
1290
+ baseHeight: s,
1291
+ maxCutFill: 16,
1292
+ extraRoads: i.slice(1)
1293
+ }), u = {
1294
+ ...l,
1295
+ height: (e, t) => l.height(r.originWorldX + e, r.originWorldZ + t),
1296
+ visualHeight: (e, t, n) => l.visualHeight(r.originWorldX + e, r.originWorldZ + t, n),
1297
+ roadMask: (e, t) => l.roadMask(r.originWorldX + e, r.originWorldZ + t)
1298
+ }, d = T(u, S, 96), f = new A.Object3D(), p = [], h = [], g = [], _ = [], y = [], b = [], x = [], ee = [], te = [], ne = [], re = [];
1299
+ for (let e of i) for (let t = 36; t < e.length - 36; t += 48) {
1300
+ let n = e.at(t);
1301
+ f.position.set(n.pos[0] + n.left[0] * 6.8, n.pos[1], n.pos[2] + n.left[2] * 6.8), f.rotation.set(0, Math.atan2(n.tangent[0], n.tangent[2]), 0), f.scale.set(1, 1, 1), f.updateMatrix(), p.push(...f.matrix.elements);
1302
+ }
1303
+ if (r.settlementRadiusM > 0) {
1304
+ let e = Math.min(84, Math.ceil(r.settlementRadiusM / 3));
1305
+ for (let t = -e; t <= e; t++) for (let i = -e; i <= e; i++) {
1306
+ let e = r.hubX + i * 3 + 1.5, a = r.hubZ + t * 3 + 1.5, s = n.classifySettlementC12Tile(e, a, r);
1307
+ s < C.ROAD_LANE || s > C.C12_PLAZA_HUB || (f.position.set(e, o + .02, a), f.rotation.set(0, 0, 0), f.scale.set(1, 1, 1), f.updateMatrix(), s === C.CROSSWALK ? g.push(...f.matrix.elements) : s === C.INTERSECTION_BOX || s === C.C12_PLAZA_HUB ? _.push(...f.matrix.elements) : s === C.CURB_RAMP_CORNER ? b.push(...f.matrix.elements) : s === C.CURB_DRIVEWAY ? x.push(...f.matrix.elements) : s === C.CURB_STRAIGHT || s === C.BOULEVARD_MEDIAN ? y.push(...f.matrix.elements) : h.push(...f.matrix.elements));
1308
+ }
1309
+ for (let e of r.parcels.slice(0, 140)) {
1310
+ let t = e.zone === "COMMERCIAL" ? 4 : e.zone === "INDUSTRIAL" ? 2 : 1, n = e.zone === "COMMERCIAL" ? te : e.zone === "INDUSTRIAL" ? ne : ee, r = Math.max(2, Math.floor((e.width - 3) / 3)), i = Math.max(2, Math.floor((e.depth - 3) / 3));
1311
+ for (let a = 0; a < t; a++) {
1312
+ let t = o + a * 3 + 1.5;
1313
+ for (let a = 0; a < r; a++) for (let [r, o] of [[0, 0], [i * 3, Math.PI]]) f.position.set(e.minX + 1.5 + a * 3 + 1.5, t, e.minZ + 1.5 + r), f.rotation.set(0, o, 0), f.scale.set(1, 1, 1), f.updateMatrix(), n.push(...f.matrix.elements);
1314
+ }
1315
+ for (let n = 0; n < i; n++) for (let i = 0; i < r; i++) f.position.set(e.minX + 3 + i * 3, o + t * 3 + .12, e.minZ + 3 + n * 3), f.rotation.set(0, 0, 0), f.scale.set(1, 1, 1), f.updateMatrix(), re.push(...f.matrix.elements);
1316
+ }
1317
+ }
1318
+ let ie = r.civicHubBatches.find((e) => e.kind === "FoundationSquare")?.matrices ?? /* @__PURE__ */ new Float32Array(), E = r.civicHubBatches.find((e) => e.kind === "FoundationTriangle")?.matrices ?? /* @__PURE__ */ new Float32Array();
1319
+ return {
1320
+ plan2d: r,
1321
+ ribbons: a,
1322
+ terrainGeo: d,
1323
+ poles: new Float32Array(p),
1324
+ rdStr: new Float32Array(h),
1325
+ rdCw: new Float32Array(g),
1326
+ rdInt: new Float32Array(_),
1327
+ cbStr: new Float32Array(y),
1328
+ cbRmp: new Float32Array(b),
1329
+ cbDrv: new Float32Array(x),
1330
+ wallRes: new Float32Array(ee),
1331
+ wallCom: new Float32Array(te),
1332
+ wallInd: new Float32Array(ne),
1333
+ roofAll: new Float32Array(re),
1334
+ sqHub: ie,
1335
+ triHub: E
1336
+ };
1337
+ }, [
1338
+ e,
1339
+ t,
1340
+ n
1341
+ ]);
1342
+ return /* @__PURE__ */ L("group", { children: [
1343
+ /* @__PURE__ */ L(ht, {
1344
+ x: c.plan2d.originWorldX + a,
1345
+ z: c.plan2d.originWorldZ + o,
1346
+ friction: .9,
1347
+ children: [/* @__PURE__ */ I(z, { args: [c.terrainGeo.colliderVertices, c.terrainGeo.colliderIndices] }), /* @__PURE__ */ I("mesh", {
1348
+ geometry: c.terrainGeo.geometry,
1349
+ material: i,
1350
+ receiveShadow: !0
1351
+ })]
1352
+ }),
1353
+ c.ribbons.map((e, t) => /* @__PURE__ */ L(ht, {
1354
+ x: a,
1355
+ z: o,
1356
+ friction: 1.05,
1357
+ children: [/* @__PURE__ */ I(z, { args: [e.colliderVertices, e.colliderIndices] }), /* @__PURE__ */ I("mesh", {
1358
+ geometry: e.geometry,
1359
+ material: r,
1360
+ receiveShadow: !0
1361
+ })]
1362
+ }, `hwy_${t}`)),
1363
+ /* @__PURE__ */ L("group", {
1364
+ position: [
1365
+ a,
1366
+ 0,
1367
+ o
1368
+ ],
1369
+ children: [
1370
+ /* @__PURE__ */ I(Q, {
1371
+ kitKey: "light_pole",
1372
+ fitSpan: [
1373
+ .6,
1374
+ 6.8,
1375
+ .6
1376
+ ],
1377
+ matrices: c.poles
1378
+ }),
1379
+ /* @__PURE__ */ I(Q, {
1380
+ kitKey: "road_straight",
1381
+ fitSpan: [
1382
+ 3,
1383
+ .08,
1384
+ 3
1385
+ ],
1386
+ matrices: c.rdStr
1387
+ }),
1388
+ /* @__PURE__ */ I(Q, {
1389
+ kitKey: "road_crosswalk",
1390
+ fitSpan: [
1391
+ 3,
1392
+ .08,
1393
+ 3
1394
+ ],
1395
+ matrices: c.rdCw
1396
+ }),
1397
+ /* @__PURE__ */ I(Q, {
1398
+ kitKey: "road_intersection",
1399
+ fitSpan: [
1400
+ 3,
1401
+ .08,
1402
+ 3
1403
+ ],
1404
+ matrices: c.rdInt
1405
+ }),
1406
+ /* @__PURE__ */ I(Q, {
1407
+ kitKey: "curb_straight",
1408
+ fitSpan: [
1409
+ 3,
1410
+ .18,
1411
+ 3
1412
+ ],
1413
+ matrices: c.cbStr
1414
+ }),
1415
+ /* @__PURE__ */ I(Q, {
1416
+ kitKey: "curb_ramp",
1417
+ fitSpan: [
1418
+ 3,
1419
+ .18,
1420
+ 3
1421
+ ],
1422
+ matrices: c.cbRmp
1423
+ }),
1424
+ /* @__PURE__ */ I(Q, {
1425
+ kitKey: "curb_driveway",
1426
+ fitSpan: [
1427
+ 3,
1428
+ .14,
1429
+ 3
1430
+ ],
1431
+ matrices: c.cbDrv
1432
+ }),
1433
+ /* @__PURE__ */ I($, {
1434
+ matrices: c.sqHub,
1435
+ kind: "square",
1436
+ color: "#94a3b8"
1437
+ }),
1438
+ /* @__PURE__ */ I($, {
1439
+ matrices: c.triHub,
1440
+ kind: "triangle",
1441
+ color: "#cbd5e1"
1442
+ }),
1443
+ /* @__PURE__ */ I($, {
1444
+ matrices: c.wallRes,
1445
+ kind: "wall",
1446
+ color: "#d6c7b2"
1447
+ }),
1448
+ /* @__PURE__ */ I($, {
1449
+ matrices: c.wallCom,
1450
+ kind: "wall",
1451
+ color: "#38bdf8"
1452
+ }),
1453
+ /* @__PURE__ */ I($, {
1454
+ matrices: c.wallInd,
1455
+ kind: "wall",
1456
+ color: "#b45309"
1457
+ }),
1458
+ /* @__PURE__ */ I($, {
1459
+ matrices: c.roofAll,
1460
+ kind: "roof",
1461
+ color: "#334155"
1462
+ }),
1463
+ c.plan2d.roadsideStops.map((r, i) => /* @__PURE__ */ I(mt, {
1464
+ stop: r,
1465
+ groundY: Math.max(2, n.sampleMainlandHeight(r.worldX, r.worldZ)),
1466
+ cellTag: `stop_${e}_${t}_${i}`
1467
+ }, `stop_${i}`))
1468
+ ]
1469
+ }),
1470
+ s?.(e, t, c.plan2d, a, o)
1471
+ ] });
1472
+ }
1473
+ // src/engine/kolmoLongDrive.tsx
1474
+ function _t(e = 77, t = 960) {
1475
+ let n = at(e, t), r = n.road.samples[0];
1476
+ for (let e of n.road.samples) e.pos[0] > r.pos[0] && (r = e);
1477
+ return {
1478
+ vehiclePos: [
1479
+ r.pos[0] + 10,
1480
+ r.pos[1] + .6,
1481
+ r.pos[2]
1482
+ ],
1483
+ vehicleRot: [
1484
+ 0,
1485
+ Math.PI * .5,
1486
+ 0
1487
+ ],
1488
+ actorPos: [
1489
+ r.pos[0] + 8,
1490
+ r.pos[1] + 1.6,
1491
+ r.pos[2] + 3.5
1492
+ ]
1493
+ };
1494
+ }
1495
+ function vt(e = 77, t = 1, n = 0) {
1496
+ let r = new _(e), i = r.generateMacroCell2D(t, n), a = i.highwayPolylines[0];
1497
+ if (a && a.length >= 2) {
1498
+ let e = a[1], t = a[Math.min(a.length - 1, 2)], n = Math.max(2, r.sampleMainlandHeight(e[0], e[1])), i = Math.atan2(t[0] - e[0], t[1] - e[1]);
1499
+ return {
1500
+ vehiclePos: [
1501
+ e[0],
1502
+ n + .45,
1503
+ e[1]
1504
+ ],
1505
+ vehicleRot: [
1506
+ 0,
1507
+ i,
1508
+ 0
1509
+ ],
1510
+ actorPos: [
1511
+ e[0] - 2.6,
1512
+ n + 1.35,
1513
+ e[1] + 2.2
1514
+ ]
1515
+ };
1516
+ }
1517
+ let o = Math.max(2.5, r.sampleMainlandHeight(i.hubX, i.hubZ));
1518
+ return {
1519
+ vehiclePos: [
1520
+ i.hubX,
1521
+ o + .45,
1522
+ i.hubZ
1523
+ ],
1524
+ vehicleRot: [
1525
+ 0,
1526
+ Math.PI * .5,
1527
+ 0
1528
+ ],
1529
+ actorPos: [
1530
+ i.hubX - 2.5,
1531
+ o + 1.35,
1532
+ i.hubZ + 2.5
1533
+ ]
1534
+ };
1535
+ }
1536
+ function yt({ seed: e, islandSize: t, planner: n, roadMat: r, offX: i, offZ: a }) {
1537
+ let o = O(() => {
1538
+ let r = at(e, t), i = r.road.samples[0];
1539
+ for (let e of r.road.samples) e.pos[0] > i.pos[0] && (i = e);
1540
+ let a = n.evalVerticalBorder(0, 0), o = S * .5, s = a.offsetMeters, c = n.sampleMainlandHeight(o, s), l = [];
1541
+ for (let e = 0; e <= 28; e++) {
1542
+ let t = e / 28, n = Math.sin(Math.PI * t), r = i.pos[0] + (o - i.pos[0]) * t, a = i.pos[2] + (s - i.pos[2]) * (t * t * (3 - 2 * t)), u = i.pos[1] * (1 - t) + c * t;
1543
+ l.push([
1544
+ r,
1545
+ u * (1 - n) + 14 * n,
1546
+ a
1547
+ ]);
1548
+ }
1549
+ let u = v(l, 5, 3, !1), d = w(u, {
1550
+ skirtDrop: .6,
1551
+ crownHeight: .04
1552
+ }), f = [], p = [], m = new A.Object3D();
1553
+ for (let e = 24; e < u.length - 24; e += 24) {
1554
+ let t = u.at(e), n = Math.atan2(t.tangent[0], t.tangent[2]);
1555
+ for (let e of [-3.6, 3.6]) {
1556
+ let r = t.pos[0] + t.left[0] * e, i = t.pos[2] + t.left[2] * e, a = t.pos[1] + 14;
1557
+ m.position.set(r, t.pos[1] - a * .5, i), m.rotation.set(0, n, 0), m.scale.set(.45, a / .24, .45), m.updateMatrix(), f.push(...m.matrix.elements);
1558
+ }
1559
+ m.position.set(t.pos[0] + t.left[0] * 4.8, t.pos[1], t.pos[2] + t.left[2] * 4.8), m.rotation.set(0, n, 0), m.scale.set(1, 1, 1), m.updateMatrix(), p.push(...m.matrix.elements);
1560
+ }
1561
+ return {
1562
+ ribbon: d,
1563
+ piers: new Float32Array(f),
1564
+ lamps: new Float32Array(p)
1565
+ };
1566
+ }, [
1567
+ e,
1568
+ t,
1569
+ n
1570
+ ]);
1571
+ return /* @__PURE__ */ L("group", { children: [/* @__PURE__ */ L(ht, {
1572
+ x: i,
1573
+ z: a,
1574
+ friction: 1.05,
1575
+ children: [/* @__PURE__ */ I(z, { args: [o.ribbon.colliderVertices, o.ribbon.colliderIndices] }), /* @__PURE__ */ I("mesh", {
1576
+ geometry: o.ribbon.geometry,
1577
+ material: r,
1578
+ receiveShadow: !0
1579
+ })]
1580
+ }), /* @__PURE__ */ L("group", {
1581
+ position: [
1582
+ i,
1583
+ 0,
1584
+ a
1585
+ ],
1586
+ children: [/* @__PURE__ */ I($, {
1587
+ matrices: o.piers,
1588
+ kind: "square",
1589
+ color: "#64748b"
1590
+ }), /* @__PURE__ */ I(Q, {
1591
+ kitKey: "light_pole",
1592
+ fitSpan: [
1593
+ .6,
1594
+ 6.5,
1595
+ .6
1596
+ ],
1597
+ matrices: o.lamps
1598
+ })]
1599
+ })] });
1600
+ }
1601
+ function bt({ seed: e = 77, pureMainland: t = !1, initialOrigin: n = [0, 0], onOriginRebase: i, renderCellExtra: o }) {
1602
+ let s = O(() => new _(e), [e]), [l, u] = ae(n), d = k([n[0], n[1]]), [f, p] = ae(() => [Math.max(+!!t, Math.round(n[0] / S)), Math.round(n[1] / S)]), [m, g] = ae(() => t ? [
1603
+ [1, 0],
1604
+ [1, -1],
1605
+ [1, 1],
1606
+ [2, 0]
1607
+ ] : [[1, 0]]), v = O(() => {
1608
+ let t = at(e, 960), n = c(h(t, 128));
1609
+ return {
1610
+ terrainMat: a(n).material,
1611
+ roadMat: r(n, { preset: "ASPHALT" }).material
1612
+ };
1613
+ }, [e]), b = O(() => {
1614
+ let [e, t] = f, n = [];
1615
+ for (let r = -1; r <= 1; r++) for (let i = -1; i <= 1; i++) {
1616
+ let a = e + r, o = t + i;
1617
+ a >= 1 && n.push([a, o]);
1618
+ }
1619
+ return n.sort((n, r) => Math.hypot(n[0] - e, n[1] - t) - Math.hypot(r[0] - e, r[1] - t)), n;
1620
+ }, [f, t]);
1621
+ E(() => {
1622
+ let e = 0, t = () => {
1623
+ g((n) => {
1624
+ let r = n.filter(([e, t]) => b.some(([n, r]) => n === e && r === t)), i = b.find(([e, t]) => !r.some(([n, r]) => n === e && r === t));
1625
+ if (!i && r.length === n.length) return n;
1626
+ let a = i ? [...r, i] : r;
1627
+ return a.length < b.length && (e = requestAnimationFrame(t)), a;
1628
+ });
1629
+ };
1630
+ return e = requestAnimationFrame(t), () => cancelAnimationFrame(e);
1631
+ }, [b]), oe(({ camera: e }) => {
1632
+ let [n, r] = d.current, a = e.position.x, o = e.position.z;
1633
+ for (let e of G.query(H)) {
1634
+ let t = e.get(H)?.handle;
1635
+ if (t?.body) {
1636
+ let e = t.body.translation();
1637
+ a = e.x, o = e.z;
1638
+ break;
1639
+ }
1640
+ }
1641
+ let s = n + a, c = r + o, l = y(s, c), m = l.chunkOriginX - n, h = l.chunkOriginZ - r;
1642
+ if (Math.abs(m) >= 192 || Math.abs(h) >= 192) {
1643
+ d.current = [l.chunkOriginX, l.chunkOriginZ], e.position.x -= m, e.position.z -= h;
1644
+ for (let e of G.query(H)) {
1645
+ let t = e.get(H)?.handle?.body;
1646
+ if (t) {
1647
+ let e = t.translation();
1648
+ t.setTranslation({
1649
+ x: e.x - m,
1650
+ y: e.y,
1651
+ z: e.z - h
1652
+ }, !0);
1653
+ }
1654
+ }
1655
+ for (let e of G.query(U)) {
1656
+ let t = e.get(U)?.handle?.body;
1657
+ if (t) {
1658
+ let e = t.translation();
1659
+ t.setTranslation({
1660
+ x: e.x - m,
1661
+ y: e.y,
1662
+ z: e.z - h
1663
+ }, !0);
1664
+ }
1665
+ }
1666
+ for (let e of G.query(Re)) {
1667
+ let t = e.get(Re)?.getBody();
1668
+ if (t) {
1669
+ let e = t.translation();
1670
+ t.setTranslation({
1671
+ x: e.x - m,
1672
+ y: e.y,
1673
+ z: e.z - h
1674
+ }, !0);
1675
+ }
1676
+ }
1677
+ i?.(l.chunkOriginX, l.chunkOriginZ, m, h), u([l.chunkOriginX, l.chunkOriginZ]);
1678
+ }
1679
+ let g = Math.max(+!!t, Math.round(s / S)), _ = Math.round(c / S);
1680
+ (g !== f[0] || _ !== f[1]) && p([g, _]);
1681
+ });
1682
+ let x = -l[0], C = -l[1];
1683
+ return /* @__PURE__ */ L("group", { children: [
1684
+ !t && f[0] <= 1 && Math.abs(f[1]) <= 1 && /* @__PURE__ */ I("group", {
1685
+ position: [
1686
+ x,
1687
+ 0,
1688
+ C
1689
+ ],
1690
+ children: /* @__PURE__ */ I(lt, {
1691
+ seed: e,
1692
+ size: 960,
1693
+ segments: 144,
1694
+ settlementTier: "town"
1695
+ })
1696
+ }),
1697
+ !t && f[0] <= 2 && Math.abs(f[1]) <= 1 && /* @__PURE__ */ I(yt, {
1698
+ seed: e,
1699
+ islandSize: 960,
1700
+ planner: s,
1701
+ roadMat: v.roadMat,
1702
+ offX: x,
1703
+ offZ: C
1704
+ }),
1705
+ m.map(([e, t]) => /* @__PURE__ */ I(gt, {
1706
+ mx: e,
1707
+ mz: t,
1708
+ planner: s,
1709
+ roadMat: v.roadMat,
1710
+ terrainMat: v.terrainMat,
1711
+ offX: x,
1712
+ offZ: C,
1713
+ renderExtra: o
1714
+ }, `mc_${e}_${t}`))
1715
+ ] });
1716
+ }
1717
+ export { ke as C, G as S, Ie as T, ze as _, lt as a, q as b, rt as c, Ge as d, Ue as f, Le as g, Re as h, ht as i, et as l, U as m, _t as n, ot as o, qe as p, vt as r, at as s, bt as t, He as u, H as v, Oe as w, K as x, W as y };