@pinkaphant/kolmo 0.1.2 → 0.2.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 (130) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -14
  3. package/bin/kolmo.mjs +22 -54
  4. package/dist/body/HeldItem.js +171 -0
  5. package/dist/body/KhrBody.js +171 -0
  6. package/dist/body/bodySi.d.ts +0 -11
  7. package/dist/body/bodySi.js +52 -0
  8. package/dist/body/index.d.ts +1 -1
  9. package/dist/body/index.js +4 -1
  10. package/dist/engine/index.d.ts +4 -4
  11. package/dist/engine/index.js +12 -3
  12. package/dist/engine/kolmoActor.d.ts +11 -4
  13. package/dist/engine/kolmoActor.js +197 -0
  14. package/dist/engine/kolmoInput.d.ts +17 -0
  15. package/dist/engine/kolmoInput.js +78 -0
  16. package/dist/engine/kolmoIsland.d.ts +3 -1
  17. package/dist/engine/kolmoIsland.js +311 -0
  18. package/dist/engine/kolmoLongDrive.js +223 -0
  19. package/dist/engine/kolmoRigs.js +59 -0
  20. package/dist/engine/kolmoStore.d.ts +53 -27
  21. package/dist/engine/kolmoStore.js +211 -0
  22. package/dist/engine/kolmoSurface.d.ts +1 -1
  23. package/dist/engine/kolmoSurface.js +182 -0
  24. package/dist/engine/kolmoVehicle.d.ts +3 -1
  25. package/dist/engine/kolmoVehicle.js +250 -0
  26. package/dist/engine/kolmoVehicleDriver.d.ts +30 -0
  27. package/dist/engine/kolmoVehicleDriver.js +29 -0
  28. package/dist/engine/kolmoWorld.d.ts +7 -15
  29. package/dist/engine/kolmoWorld.js +139 -0
  30. package/dist/engine/longDriveKit.d.ts +4 -2
  31. package/dist/engine/longDriveKit.js +254 -0
  32. package/dist/engine/mainlandMacroCell.d.ts +3 -7
  33. package/dist/engine/mainlandMacroCell.js +247 -0
  34. package/dist/engine/shiftedFixedBody.d.ts +13 -0
  35. package/dist/engine/shiftedFixedBody.js +64 -0
  36. package/dist/importer/ChopShopPanel.js +465 -0
  37. package/dist/importer/DomainWorkshopPanel.d.ts +9 -4
  38. package/dist/importer/DomainWorkshopPanel.js +385 -0
  39. package/dist/importer/GateHudBar.js +312 -0
  40. package/dist/importer/GlbImportGate.js +250 -0
  41. package/dist/importer/ImperativeVehicleRig.js +336 -0
  42. package/dist/importer/ImporterPlinthUikitTags.js +112 -0
  43. package/dist/importer/Step1CalibrationPlinth.js +275 -0
  44. package/dist/importer/Step2UniversalPad.js +244 -0
  45. package/dist/importer/VfxEmitterPool.js +91 -0
  46. package/dist/importer/chopShopActions.d.ts +22 -2
  47. package/dist/importer/chopShopActions.js +232 -0
  48. package/dist/importer/gateStore.d.ts +1 -1
  49. package/dist/importer/gateStore.js +92 -0
  50. package/dist/importer/glbNormalizer.js +133 -0
  51. package/dist/importer/importerWebMcp.d.ts +17 -6
  52. package/dist/importer/importerWebMcp.js +343 -0
  53. package/dist/importer/index.js +22 -3
  54. package/dist/importer/khrCompiler.d.ts +1 -1
  55. package/dist/importer/khrCompiler.js +434 -0
  56. package/dist/importer/launcherBake.js +51 -0
  57. package/dist/importer/meshIslands.d.ts +1 -1
  58. package/dist/importer/meshIslands.js +301 -0
  59. package/dist/importer/surfaceCutter.js +254 -0
  60. package/dist/importer/surfaceTopology.js +183 -0
  61. package/dist/importer/universalGateBake.js +162 -0
  62. package/dist/importer/usdToGlb.js +294 -0
  63. package/dist/importer/useChopShopController.d.ts +11 -2
  64. package/dist/importer/useChopShopController.js +364 -0
  65. package/dist/importer/vehiclePanelAnim.js +214 -0
  66. package/dist/importer/wheelAxlePairing.d.ts +1 -2
  67. package/dist/importer/wheelAxlePairing.js +102 -0
  68. package/dist/index.d.ts +1 -1
  69. package/dist/index.js +69 -13
  70. package/dist/junk/DestructibleTarget.js +154 -0
  71. package/dist/junk/KolmoJunk.js +65 -0
  72. package/dist/junk/ShardPieces.d.ts +6 -4
  73. package/dist/junk/ShardPieces.js +74 -0
  74. package/dist/junk/TargetDecals.js +51 -0
  75. package/dist/junk/bvhShatter.js +55 -0
  76. package/dist/junk/bvhTriCollector.js +78 -0
  77. package/dist/junk/index.js +11 -1
  78. package/dist/junk/junkGeometry.js +69 -0
  79. package/dist/junk/junkImportSanitize.js +54 -0
  80. package/dist/junk/junkImporter.js +95 -0
  81. package/dist/junk/junkLabelCanvas.js +67 -0
  82. package/dist/junk/junkLabels.js +35 -0
  83. package/dist/junk/targetHelpers.js +103 -0
  84. package/dist/junk/targetHitLogic.js +128 -0
  85. package/dist/junk/useTargetAssets.js +102 -0
  86. package/dist/physics/index.d.ts +26 -0
  87. package/dist/physics/index.js +84 -0
  88. package/dist/schema/kolmoSchema.d.ts +2 -1
  89. package/dist/schema/kolmoSchema.js +184 -0
  90. package/dist/shaders/celestialBackdrop.d.ts +1 -1
  91. package/dist/shaders/celestialBackdrop.js +344 -0
  92. package/dist/shaders/index.d.ts +0 -1
  93. package/dist/shaders/index.js +9 -1
  94. package/dist/shaders/plumeAndSparkle.js +271 -0
  95. package/dist/shaders/ps2GlslShared.d.ts +1 -1
  96. package/dist/shaders/ps2GlslShared.js +3 -0
  97. package/dist/shaders/ps2MaterialsTSL.js +65 -0
  98. package/dist/shaders/ps2MaterialsWebGL.js +40 -0
  99. package/dist/shaders/ps2RoadWebGL.js +101 -0
  100. package/dist/shaders/ps2TerrainWebGL.js +54 -0
  101. package/dist/shaders/ps2Textures.js +224 -0
  102. package/dist/shaders/retroPalettes.js +188 -0
  103. package/dist/shaders/retroShader.d.ts +31 -3
  104. package/dist/shaders/retroShader.js +249 -0
  105. package/dist/shaders/tsl.d.ts +1 -0
  106. package/dist/shaders/tsl.js +1 -0
  107. package/dist/vite/index.d.ts +15 -0
  108. package/dist/vite/index.js +90 -0
  109. package/dist/world/frontage.js +32 -0
  110. package/dist/world/index.d.ts +1 -1
  111. package/dist/world/index.js +11 -3
  112. package/dist/world/infiniteWorld2D.js +244 -0
  113. package/dist/world/island.js +201 -0
  114. package/dist/world/macroCellSchema.js +27 -0
  115. package/dist/world/macroKnightAStar.js +171 -0
  116. package/dist/world/random.js +33 -0
  117. package/dist/world/road.js +136 -0
  118. package/dist/world/roadRibbon.d.ts +6 -6
  119. package/dist/world/roadRibbon.js +161 -0
  120. package/dist/world/terrain.js +87 -0
  121. package/dist/world/worldTypes.js +111 -0
  122. package/package.json +32 -18
  123. package/dist/body-B7FTf67o.js +0 -362
  124. package/dist/engine-BeKvBM8d.js +0 -1745
  125. package/dist/importer-B2-S-N_e.js +0 -5113
  126. package/dist/junk-B4bC1zAl.js +0 -1049
  127. package/dist/kolmoSurface-DTnrFXH0.js +0 -558
  128. package/dist/shaders-GS71Ek1A.js +0 -1383
  129. package/dist/world-PRWPYrlx.js +0 -947
  130. package/dist/worldTypes-Z0KfdCd0.js +0 -226
@@ -1,558 +0,0 @@
1
- import { O as e } from "./shaders-GS71Ek1A.js";
2
- import { useCallback as t, useEffect as n, useLayoutEffect as r, useMemo as i, useRef as a, useState as o } from "react";
3
- import * as s from "three";
4
- import { KhrAssembly as c, cloneKhrBundle as l, exportKhrGlb as u, loadKhrGlb as d, patchGlbJsonChunk as f, useKhrGlb as p } from "@khr3/core";
5
- import { jsx as m } from "react/jsx-runtime";
6
- // src/schema/kolmoSchema.ts
7
- var h = "KOLMO_emitter";
8
- function g() {
9
- return {
10
- throttle: 0,
11
- boost: 0,
12
- brake: 0,
13
- slip: 0,
14
- reverse: 0,
15
- turn_l: 0,
16
- turn_r: 0,
17
- headlight: 1,
18
- fire: 0,
19
- damage: 0,
20
- always: 1
21
- };
22
- }
23
- var _ = /* @__PURE__ */ new Set([
24
- "plume",
25
- "sparkle",
26
- "fume",
27
- "trail",
28
- "flare"
29
- ]), v = /* @__PURE__ */ new Set([
30
- "throttle",
31
- "boost",
32
- "brake",
33
- "slip",
34
- "reverse",
35
- "turn_l",
36
- "turn_r",
37
- "headlight",
38
- "fire",
39
- "damage",
40
- "always"
41
- ]), y = /* @__PURE__ */ new Set([
42
- "seat",
43
- "exit",
44
- "grip_primary",
45
- "grip_secondary",
46
- "optic",
47
- "muzzle",
48
- "mount"
49
- ]), b = {
50
- plume: [
51
- .22,
52
- .91,
53
- 1
54
- ],
55
- sparkle: [
56
- 1,
57
- .72,
58
- .24
59
- ],
60
- fume: [
61
- .68,
62
- .74,
63
- .82
64
- ],
65
- trail: [
66
- .32,
67
- .88,
68
- 1
69
- ],
70
- flare: [
71
- 1,
72
- .18,
73
- .08
74
- ]
75
- }, x = new s.Matrix4(), S = new s.Matrix4(), C = new s.Vector3(), w = new s.Quaternion(), T = new s.Vector3();
76
- function E(e, t) {
77
- e.updateMatrixWorld(!0), x.copy(e.matrixWorld).invert();
78
- let n = /* @__PURE__ */ new Map();
79
- if (t) {
80
- let e = t instanceof Uint8Array ? t : new Uint8Array(t), r = new DataView(e.buffer, e.byteOffset, e.byteLength);
81
- if (e.byteLength >= 20 && r.getUint32(0, !0) === 1179937895) {
82
- let t = r.getUint32(12, !0), i = JSON.parse(new TextDecoder().decode(e.subarray(20, 20 + t)));
83
- for (let e of i.nodes ?? []) {
84
- let t = e.extensions?.[h];
85
- e.name && t && typeof t == "object" && n.set(e.name, t);
86
- }
87
- }
88
- }
89
- let r = [], i = [];
90
- return e.traverse((t) => {
91
- if (t === e) return;
92
- let a = n.get(t.name) ?? t.userData?.KOLMO_emitter;
93
- if (!a || typeof a != "object") return;
94
- t.userData[h] = a, S.multiplyMatrices(x, t.matrixWorld), S.decompose(C, w, T);
95
- let o = [
96
- C.x,
97
- C.y,
98
- C.z
99
- ], s = [
100
- w.x,
101
- w.y,
102
- w.z,
103
- w.w
104
- ];
105
- if (typeof a.kind == "string" && _.has(a.kind)) {
106
- let e = a.kind, n = typeof a.drive == "string" && v.has(a.drive) ? a.drive : "always", i = Array.isArray(a.color) && a.color.length === 3 ? a.color : b[e], c = [
107
- Number(i[0]),
108
- Number(i[1]),
109
- Number(i[2])
110
- ], l = typeof a.size == "number" && a.size > 0 ? a.size : 1;
111
- r.push({
112
- nodeName: t.name,
113
- object: t,
114
- localPosition: o,
115
- localQuaternion: s,
116
- kind: e,
117
- drive: n,
118
- color: c,
119
- size: l
120
- });
121
- }
122
- typeof a.socket == "string" && y.has(a.socket) && i.push({
123
- nodeName: t.name,
124
- role: a.socket,
125
- localPosition: o,
126
- localQuaternion: s
127
- });
128
- }), {
129
- emitters: r,
130
- sockets: i
131
- };
132
- }
133
- function D(e, t, n) {
134
- return t.length === 0 && !n ? e : new Uint8Array(f(e, (e) => {
135
- let r = e;
136
- r.extensionsUsed = Array.from(/* @__PURE__ */ new Set([...r.extensionsUsed ?? [], h])), r.nodes = r.nodes ?? [];
137
- let i = r.scene ?? 0, a = r.scenes?.[i];
138
- a && n && (a.extras = {
139
- ...a.extras ?? {},
140
- ...n
141
- });
142
- for (let e of t) {
143
- let t;
144
- if (e.spotLight) {
145
- r.extensionsUsed = Array.from(/* @__PURE__ */ new Set([...r.extensionsUsed, "KHR_lights_punctual"])), r.extensions = r.extensions ?? {};
146
- let n = r.extensions.KHR_lights_punctual ?? { lights: [] };
147
- n.lights = n.lights ?? [], t = n.lights.length, n.lights.push({
148
- name: `${e.nodeName}_spot`,
149
- type: "spot",
150
- color: e.spotLight.color,
151
- intensity: e.spotLight.intensity,
152
- ...e.spotLight.range ? { range: e.spotLight.range } : {},
153
- spot: {
154
- innerConeAngle: e.spotLight.innerConeAngle ?? .22,
155
- outerConeAngle: e.spotLight.outerConeAngle ?? .58
156
- }
157
- }), r.extensions.KHR_lights_punctual = n;
158
- }
159
- let n = r.nodes.findIndex((t) => t.name === e.nodeName), i = { [h]: e.extension };
160
- if (t !== void 0 && (i.KHR_lights_punctual = { light: t }), n >= 0) {
161
- let t = r.nodes[n];
162
- t.translation = e.translation, e.rotation && (t.rotation = e.rotation), t.extensions = {
163
- ...t.extensions ?? {},
164
- ...i
165
- };
166
- } else {
167
- let t = r.nodes.length;
168
- r.nodes.push({
169
- name: e.nodeName,
170
- translation: e.translation,
171
- ...e.rotation ? { rotation: e.rotation } : {},
172
- extensions: i
173
- }), a && (a.nodes = a.nodes ?? [], a.nodes.push(t));
174
- }
175
- }
176
- }));
177
- }
178
- // src/importer/vehiclePanelAnim.ts
179
- var O = {
180
- plume: [
181
- .22,
182
- .91,
183
- 1
184
- ],
185
- sparkle: [
186
- 1,
187
- .72,
188
- .24
189
- ],
190
- fume: [
191
- .68,
192
- .74,
193
- .82
194
- ],
195
- trail: [
196
- .32,
197
- .88,
198
- 1
199
- ],
200
- flare: [
201
- 1,
202
- .18,
203
- .08
204
- ]
205
- }, k = new s.Vector3(0, 0, 0), A = new s.Vector3(0, 1, 0), j = new s.Vector3(0, 0, 1), M = new s.Matrix4(), N = new s.Quaternion(), P = new s.Vector3(), F = (e) => Number(e.toFixed(4));
206
- function I(e) {
207
- let t = e.clone();
208
- return t.lengthSq() < 1e-10 ? t.set(0, 0, -1) : t.normalize(), M.lookAt(k, t, Math.abs(t.y) > .98 ? j : A), N.setFromRotationMatrix(M).normalize(), [
209
- Number(N.x.toFixed(5)),
210
- Number(N.y.toFixed(5)),
211
- Number(N.z.toFixed(5)),
212
- Number(N.w.toFixed(5))
213
- ];
214
- }
215
- function L(e) {
216
- let t = [];
217
- for (let n of e) {
218
- let e = n.extension.kind;
219
- if (!e) continue;
220
- let r = n.rotation ?? [
221
- 0,
222
- 0,
223
- 0,
224
- 1
225
- ], i = new s.Object3D();
226
- i.name = n.nodeName, i.position.set(n.translation[0], n.translation[1], n.translation[2]), i.quaternion.set(r[0], r[1], r[2], r[3]);
227
- let a = n.extension.drive ?? "always", o = n.extension.color ?? O[e];
228
- t.push({
229
- nodeName: n.nodeName,
230
- object: i,
231
- localPosition: n.translation,
232
- localQuaternion: r,
233
- kind: e,
234
- drive: a,
235
- color: o,
236
- size: n.extension.size ?? 1
237
- });
238
- }
239
- return t;
240
- }
241
- function R(e, t) {
242
- let [n, r, i] = e.min, [a, o, s] = e.max, [c, l, u] = e.center;
243
- if (t === "door") {
244
- let e = c >= 0;
245
- return {
246
- anchor: [
247
- F(e ? a - .02 : n + .02),
248
- F(l),
249
- F(s)
250
- ],
251
- axis: [
252
- 0,
253
- 1,
254
- 0
255
- ],
256
- limits: e ? [-1.15, 0] : [0, 1.15],
257
- openAngle: e ? -1.15 : 1.15,
258
- explodeDir: [
259
- e ? 1 : -1,
260
- .1,
261
- 0
262
- ]
263
- };
264
- }
265
- if (t === "hood") return {
266
- anchor: [
267
- F(c),
268
- F(o),
269
- F(i)
270
- ],
271
- axis: [
272
- 1,
273
- 0,
274
- 0
275
- ],
276
- limits: [-1.05, 0],
277
- openAngle: -1.05,
278
- explodeDir: [
279
- 0,
280
- .55,
281
- .75
282
- ]
283
- };
284
- if (t === "trunk") return {
285
- anchor: [
286
- F(c),
287
- F(o),
288
- F(s)
289
- ],
290
- axis: [
291
- 1,
292
- 0,
293
- 0
294
- ],
295
- limits: [0, 1.15],
296
- openAngle: 1.15,
297
- explodeDir: [
298
- 0,
299
- .55,
300
- -.75
301
- ]
302
- };
303
- if (t === "fender") {
304
- let e = c >= 0;
305
- return {
306
- anchor: [
307
- F(e ? n : a),
308
- F(o),
309
- F(u)
310
- ],
311
- axis: [
312
- 0,
313
- 0,
314
- 1
315
- ],
316
- limits: e ? [-.55, 0] : [0, .55],
317
- openAngle: e ? -.55 : .55,
318
- explodeDir: [
319
- e ? 1 : -1,
320
- .25,
321
- 0
322
- ]
323
- };
324
- }
325
- let d = u >= 0;
326
- return {
327
- anchor: [
328
- F(c),
329
- F(o),
330
- F(d ? i : s)
331
- ],
332
- axis: [
333
- 1,
334
- 0,
335
- 0
336
- ],
337
- limits: d ? [-.55, 0] : [0, .55],
338
- openAngle: d ? -.55 : .55,
339
- explodeDir: [
340
- 0,
341
- .15,
342
- d ? 1 : -1
343
- ]
344
- };
345
- }
346
- function z(e) {
347
- let t = e.bodies.filter((e) => e.joint !== null && e.joint.kind === "revolute" && e.joint.limits !== null).map((e) => {
348
- let t = e.joint.limits, n = Math.abs(t[0]) > Math.abs(t[1]) ? t[0] : t[1];
349
- return {
350
- nodeName: e.nodeName,
351
- role: (e.role ?? e.nodeName).toLowerCase(),
352
- object: e.object,
353
- restQuat: e.object.quaternion.clone(),
354
- axis: e.joint.axis,
355
- openAngle: n,
356
- open: !1,
357
- angle: 0
358
- };
359
- }), n = new Map(t.map((e) => [e.object, e])), r = new s.Quaternion();
360
- return {
361
- hasPanels: t.length > 0,
362
- panelNames: t.map((e) => e.nodeName),
363
- toggleHitObject(e) {
364
- for (let t = e; t; t = t.parent) {
365
- let e = n.get(t);
366
- if (e) return e.open = !e.open, !0;
367
- }
368
- return !1;
369
- },
370
- toggleRolePrefix(e) {
371
- let n = e.toLowerCase(), r = t.filter((e) => e.role.startsWith(n) || e.nodeName.toLowerCase().startsWith(n));
372
- if (r.length === 0) return;
373
- let i = !r[0].open;
374
- for (let e of r) e.open = i;
375
- },
376
- toggleAll() {
377
- if (t.length === 0) return;
378
- let e = !t.some((e) => e.open);
379
- for (let n of t) n.open = e;
380
- },
381
- step(e) {
382
- let n = 1 - Math.exp(-11 * Math.min(e, .05));
383
- for (let e of t) {
384
- let t = e.open ? e.openAngle : 0;
385
- Math.abs(t - e.angle) < 1e-4 || (e.angle += (t - e.angle) * n, P.set(e.axis[0], e.axis[1], e.axis[2]).normalize(), r.setFromAxisAngle(P, e.angle), e.object.quaternion.copy(e.restQuat).multiply(r));
386
- }
387
- }
388
- };
389
- }
390
- // src/engine/kolmoSurface.tsx
391
- var B = /* @__PURE__ */ new Map();
392
- function V(e) {
393
- let t = /* @__PURE__ */ new Uint8Array(16384);
394
- for (let e = 0; e < 64; e++) for (let n = 0; n < 64; n++) {
395
- let r = (e * 64 + n) * 4;
396
- if (n === 0 || e === 0) t[r] = 56, t[r + 1] = 178, t[r + 2] = 216;
397
- else if (n === 32 || e === 32) t[r] = 44, t[r + 1] = 58, t[r + 2] = 78;
398
- else {
399
- let i = (n >> 4) + (e >> 4) & 1 ? 30 : 35;
400
- t[r] = i, t[r + 1] = i + 3, t[r + 2] = i + 9;
401
- }
402
- t[r + 3] = 255;
403
- }
404
- let n = new s.DataTexture(t, 64, 64, s.RGBAFormat);
405
- return n.colorSpace = s.SRGBColorSpace, n.wrapS = s.RepeatWrapping, n.wrapT = s.RepeatWrapping, n.magFilter = s.NearestFilter, n.minFilter = s.NearestFilter, n.repeat.set(e, e), n.needsUpdate = !0, n;
406
- }
407
- function H(e) {
408
- let t = B.get(e);
409
- return t || (t = (async () => {
410
- let t = new s.Group();
411
- t.name = "KolmoProceduralSurface";
412
- let n = new s.Mesh(new s.BoxGeometry(e, 1, e), new s.MeshStandardMaterial({
413
- map: V(Math.max(4, Math.round(e / 8))),
414
- roughness: .92,
415
- metalness: .06
416
- }));
417
- n.name = "KolmoArenaSlab", n.position.set(0, -.5, 0), n.receiveShadow = !0, t.add(n);
418
- let r = await u(t, [{
419
- nodeName: "KolmoArenaSlab",
420
- motion: { isKinematic: !0 },
421
- collider: {
422
- shape: {
423
- type: "box",
424
- size: [
425
- e,
426
- 1,
427
- e
428
- ]
429
- },
430
- friction: .95,
431
- restitution: .04
432
- }
433
- }]);
434
- return d(r);
435
- })(), B.set(e, t)), t;
436
- }
437
- function U({ bundle: t, position: n }) {
438
- let a = i(() => l(t), [t]);
439
- return r(() => {
440
- e(a.scene, { flatShading: !1 });
441
- }, [a]), /* @__PURE__ */ m(c, {
442
- bundle: a,
443
- position: n,
444
- fixedRoot: !0
445
- });
446
- }
447
- function W({ src: t, position: n }) {
448
- let i = p(t);
449
- return r(() => {
450
- e(i.scene, { flatShading: !1 });
451
- }, [i]), /* @__PURE__ */ m(c, {
452
- bundle: i,
453
- position: n,
454
- fixedRoot: !0
455
- });
456
- }
457
- function G({ src: e, bundle: t, size: r = 200, position: i = [
458
- 0,
459
- 0,
460
- 0
461
- ] }) {
462
- let [a, s] = o(null);
463
- return n(() => {
464
- if (t || e) return;
465
- let n = !0;
466
- return H(r).then((e) => {
467
- n && s(e);
468
- }), () => {
469
- n = !1;
470
- };
471
- }, [
472
- t,
473
- e,
474
- r
475
- ]), t ? /* @__PURE__ */ m(U, {
476
- bundle: t,
477
- position: i
478
- }) : e ? /* @__PURE__ */ m(W, {
479
- src: e,
480
- position: i
481
- }) : a ? /* @__PURE__ */ m(U, {
482
- bundle: a,
483
- position: i
484
- }) : null;
485
- }
486
- function K(e) {
487
- if (!e) return {
488
- open: 1.35,
489
- closed: 0
490
- };
491
- let [t, n] = e;
492
- return {
493
- open: Math.abs(n) >= Math.abs(t) ? n : t,
494
- closed: Math.min(n, Math.max(t, 0))
495
- };
496
- }
497
- function q(e, t, n, r, i) {
498
- if (!e) return n;
499
- if (r && i) {
500
- let n = r;
501
- for (; n;) {
502
- let r = t.bodies.find((e) => e.object === n && e.joint?.drive?.stiffness !== void 0);
503
- if (r) {
504
- let t = !(i.get(r.nodeName) ?? !1);
505
- i.set(r.nodeName, t);
506
- let { open: n, closed: a } = K(r.joint?.limits);
507
- return e.setJointTarget(r.nodeName, t ? n : a), t;
508
- }
509
- n = n.parent;
510
- }
511
- }
512
- let a = !n;
513
- for (let n of t.bodies) {
514
- if (!n.joint?.drive || n.joint.drive.stiffness === void 0) continue;
515
- let { open: t, closed: r } = K(n.joint.limits);
516
- i?.set(n.nodeName, a), e.setJointTarget(n.nodeName, a ? t : r);
517
- }
518
- return a;
519
- }
520
- function J({ bundle: n, position: o, fixed: s }) {
521
- let u = a(null), d = a(!1), f = a(/* @__PURE__ */ new Map()), p = i(() => l(n), [n]);
522
- r(() => {
523
- e(p.scene);
524
- }, [p]);
525
- let h = t((e) => {
526
- e?.stopPropagation?.(), d.current = q(u.current, p, d.current, e?.object ?? null, f.current);
527
- }, [p]);
528
- return /* @__PURE__ */ m(c, {
529
- ref: u,
530
- bundle: p,
531
- position: o,
532
- fixedRoot: s,
533
- onClick: h
534
- });
535
- }
536
- function Y({ src: e, position: t, fixed: n }) {
537
- return /* @__PURE__ */ m(J, {
538
- bundle: p(e),
539
- position: t,
540
- fixed: n
541
- });
542
- }
543
- function X({ src: e, bundle: t, position: n = [
544
- 0,
545
- 0,
546
- 0
547
- ], fixed: r = !1 }) {
548
- return t ? /* @__PURE__ */ m(J, {
549
- bundle: t,
550
- position: n,
551
- fixed: r
552
- }) : e ? /* @__PURE__ */ m(Y, {
553
- src: e,
554
- position: n,
555
- fixed: r
556
- }) : null;
557
- }
558
- export { R as a, h as c, D as d, L as i, g as l, G as n, z as o, q as r, I as s, X as t, E as u };