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