@pinkaphant/kolmo 0.5.1 → 0.5.2

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.
@@ -1,20 +1,15 @@
1
- import { A as writeEntityKinematics, C as flipVehicleBodyUpright, D as useActiveKolmoWorld, E as pilotedVehicleQuery, O as useOptionalKootaWorld, S as ensureWorldSession, T as kolmoWorld, _ as VehicleTelemetryTrait, a as computeCircularOrbitSpeed, b as WorldSessionTrait, c as evaluatePreparedNBodyGravity, d as ActorTrait, f as InteractableTrait, g as TransformTrait, h as PilotedTag, i as G_SI, j as writeVehicleTelemetry, k as vehicleSimQuery, l as prepareAttractors, m as PilotLink, n as KolmoPhysics, o as createNBodyGravityField, p as KolmoWorldContext, r as useIsKolmoCustomGravity, s as evaluateNBodyGravity, t as KolmoGravityContext, u as resolveAttractorMu, v as VehicleTrait, w as kolmoActions, x as createEmptyVehicleCmd, y as VelocityTrait } from "../physics-ZDFXaCli.js";
2
- import { a as KOLMO_KEY_MAP, c as KolmoKeyboardContext, i as EMPTY_KOLMO_INPUT, l as useKolmoInput, n as KolmoSurface, o as KOLMO_STICK_DEADZONE, r as KolmoVehicle, s as KolmoKeyboardBridge, t as KolmoProp } from "../surface-DUol_5ml.js";
3
- import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState } from "react";
1
+ import { A as writeEntityKinematics, C as flipVehicleBodyUpright, D as useActiveKolmoWorld, E as pilotedVehicleQuery, O as useOptionalKootaWorld, S as ensureWorldSession, T as kolmoWorld, _ as VehicleTelemetryTrait, a as computeCircularOrbitSpeed, b as WorldSessionTrait, c as evaluatePreparedNBodyGravity, d as ActorTrait, f as InteractableTrait, g as TransformTrait, h as PilotedTag, i as G_SI, j as writeVehicleTelemetry, k as vehicleSimQuery, l as prepareAttractors, m as PilotLink, n as KolmoPhysics, o as createNBodyGravityField, p as KolmoWorldContext, r as useIsKolmoCustomGravity, s as evaluateNBodyGravity, t as KolmoGravityContext, u as resolveAttractorMu, v as VehicleTrait, w as kolmoActions, x as createEmptyVehicleCmd, y as VelocityTrait } from "../physics-CA1abDCY.js";
2
+ import { _ as useKolmoInput, a as KolmoOverlayPortalContext, c as useKolmoGame, d as KolmoVehicle, f as EMPTY_KOLMO_INPUT, g as KolmoKeyboardContext, h as KolmoKeyboardBridge, i as KolmoInCanvasContext, l as KolmoProp, m as KOLMO_STICK_DEADZONE, n as KolmoGame, o as KolmoWorld, p as KOLMO_KEY_MAP, r as KolmoHud, s as RoomEnvRig, t as KolmoCanvas, u as KolmoSurface } from "../world-BljtS6Fb.js";
3
+ import { useCallback, useContext, useLayoutEffect, useMemo, useRef } from "react";
4
4
  import * as THREE from "three";
5
5
  import { clone } from "three/examples/jsm/utils/SkeletonUtils.js";
6
- import { Canvas, useFrame, useThree } from "@react-three/fiber";
6
+ import { useFrame, useThree } from "@react-three/fiber";
7
7
  import { useRapier } from "@react-three/rapier";
8
- import { WorldProvider, useQueryFirst } from "koota/react";
8
+ import { useQueryFirst } from "koota/react";
9
9
  import { Ecctrl } from "@pinkaphant/ecctrl";
10
10
  import { EcctrlCameraControls } from "@pinkaphant/ecctrl/camera";
11
11
  import { assignRef, loadKhrGlb } from "@khr3/core";
12
12
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
- import { createPortal as createPortal$1 } from "react-dom";
14
- import { KeyboardControls } from "@react-three/drei";
15
- import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
16
- import "koota";
17
- import { Joystick, VirtualButton } from "@pinkaphant/ecctrl/input";
18
13
  import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
19
14
  import { KTX2Loader } from "three/examples/jsm/loaders/KTX2Loader.js";
20
15
  import { MeshoptDecoder } from "three/examples/jsm/libs/meshopt_decoder.module.js";
@@ -22,6 +17,7 @@ import { MeshoptDecoder } from "three/examples/jsm/libs/meshopt_decoder.module.j
22
17
  var _seatVec = new THREE.Vector3();
23
18
  var _camFwd = new THREE.Vector3();
24
19
  var _worldUp = new THREE.Vector3(0, 1, 0);
20
+ var _exitQuat = new THREE.Quaternion();
25
21
  function findNearestInteractableVehicleId(world, actorPos) {
26
22
  let nearestId = null;
27
23
  let bestDistSq = 1e400;
@@ -76,7 +72,48 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
76
72
  run: false,
77
73
  jump: false
78
74
  });
79
- const [latchedExit, setLatchedExit] = useState(null);
75
+ const applyPendingExit = useCallback((handle) => {
76
+ const ent = actorEntRef.current;
77
+ if (!handle?.body || !ent?.isAlive()) return;
78
+ const d = ent.get(ActorTrait);
79
+ if (!d?.exitSpawnPos) return;
80
+ const [ex, ey, ez] = d.exitSpawnPos;
81
+ _exitQuat.setFromAxisAngle(_worldUp, d.exitSpawnYaw);
82
+ handle.body.setTranslation({
83
+ x: ex,
84
+ y: ey,
85
+ z: ez
86
+ }, true);
87
+ handle.body.setRotation({
88
+ x: _exitQuat.x,
89
+ y: _exitQuat.y,
90
+ z: _exitQuat.z,
91
+ w: _exitQuat.w
92
+ }, true);
93
+ const lv = d.exitLinVel;
94
+ handle.body.setLinvel(lv ? {
95
+ x: lv[0],
96
+ y: lv[1],
97
+ z: lv[2]
98
+ } : {
99
+ x: 0,
100
+ y: 0,
101
+ z: 0
102
+ }, true);
103
+ handle.body.setAngvel({
104
+ x: 0,
105
+ y: 0,
106
+ z: 0
107
+ }, true);
108
+ handle.currPos.set(ex, ey, ez);
109
+ handle.currQuat.copy(_exitQuat);
110
+ ent.set(ActorTrait, {
111
+ ...d,
112
+ handle,
113
+ exitSpawnPos: null,
114
+ exitLinVel: null
115
+ });
116
+ }, []);
80
117
  useLayoutEffect(() => {
81
118
  const ent = activeWorld.spawn(ActorTrait({
82
119
  id: "pilot",
@@ -88,24 +125,22 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
88
125
  actorEntRef.current = ent;
89
126
  const prePiloted = activeWorld.queryFirst(pilotedVehicleQuery);
90
127
  if (prePiloted) ent.add(PilotLink(prePiloted));
91
- const unsub = activeWorld.onChange(ActorTrait, (changed) => {
92
- if (changed !== ent) return;
93
- const d = ent.get(ActorTrait);
94
- if (d?.exitSpawnPos) setLatchedExit({
95
- pos: d.exitSpawnPos,
96
- yaw: d.exitSpawnYaw
97
- });
98
- });
99
128
  return () => {
100
- unsub();
101
129
  actorEntRef.current = null;
102
130
  ent.destroy();
103
131
  };
104
132
  }, [activeWorld]);
105
133
  const onFoot = enable && !pilotedVehEnt;
106
134
  useLayoutEffect(() => {
107
- if (!onFoot) camSyncedRef.current = false;
108
- }, [onFoot]);
135
+ const body = ecctrlRef.current?.body;
136
+ if (!onFoot) {
137
+ camSyncedRef.current = false;
138
+ body?.setEnabled(false);
139
+ return;
140
+ }
141
+ body?.setEnabled(true);
142
+ applyPendingExit(ecctrlRef.current);
143
+ }, [onFoot, applyPendingExit]);
109
144
  useLayoutEffect(() => {
110
145
  const ent = actorEntRef.current;
111
146
  if (ent && pilotedVehEnt && !ent.has(PilotLink(pilotedVehEnt))) ent.add(PilotLink(pilotedVehEnt));
@@ -116,19 +151,22 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
116
151
  const ent = actorEntRef.current;
117
152
  if (!ent?.isAlive()) return;
118
153
  const cur = ent.get(ActorTrait);
119
- if (handle?.body && cur?.exitLinVel) handle.body.setLinvel({
120
- x: cur.exitLinVel[0],
121
- y: cur.exitLinVel[1],
122
- z: cur.exitLinVel[2]
123
- }, true);
154
+ const isFoot = enable && !activeWorld.queryFirst(pilotedVehicleQuery);
155
+ handle?.body?.setEnabled(isFoot);
124
156
  ent.set(ActorTrait, {
125
157
  id: cur?.id ?? "pilot",
126
158
  handle,
127
159
  exitSpawnPos: cur?.exitSpawnPos ?? null,
128
160
  exitSpawnYaw: cur?.exitSpawnYaw ?? 0,
129
- exitLinVel: handle?.body ? null : cur?.exitLinVel ?? null
161
+ exitLinVel: cur?.exitLinVel ?? null
130
162
  });
131
- }, [ref]);
163
+ if (isFoot) applyPendingExit(handle);
164
+ }, [
165
+ ref,
166
+ enable,
167
+ activeWorld,
168
+ applyPendingExit
169
+ ]);
132
170
  const assignCamRef = useCallback((ctrl) => {
133
171
  camCtrlRef.current = ctrl;
134
172
  assignRef(cameraRef, ctrl);
@@ -205,422 +243,27 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
205
243
  }
206
244
  }
207
245
  });
208
- if (!onFoot) return null;
209
- const spawnPos = latchedExit?.pos ?? position;
210
- const spawnRot = rotation ?? (latchedExit ? [
211
- 0,
212
- latchedExit.yaw,
213
- 0
214
- ] : void 0);
215
246
  return /* @__PURE__ */ jsxs(Fragment, { children: [hasDom && cameraProps !== false && cameraProps !== null && /* @__PURE__ */ jsx(EcctrlCameraControls, {
216
247
  ref: assignCamRef,
217
248
  makeDefault: true,
249
+ enabled: onFoot,
218
250
  minPolarAngle: .12,
219
251
  maxPolarAngle: Math.PI - .12,
220
252
  smoothTime: .08,
221
253
  ...cameraProps ?? {}
222
- }), /* @__PURE__ */ jsx(Ecctrl, {
223
- ref: assignEcctrlRef,
224
- enable,
225
- enableCustomGravity: effCustomGravity,
226
- position: spawnPos,
227
- ...spawnRot === void 0 ? {} : { rotation: spawnRot },
228
- userData: mergedUserData,
229
- ...ecctrlRest,
230
- children: children ?? (clonedScene ? /* @__PURE__ */ jsx("primitive", { object: clonedScene }) : null)
231
- })] });
232
- }
233
- // src/engine/world.tsx
234
- var KolmoInCanvasContext = createContext(false);
235
- var KolmoOverlayPortalContext = createContext(null);
236
- function RoomEnvRig({ intensity = .65 }) {
237
- const { gl, scene } = useThree();
238
- useEffect(() => {
239
- const pmrem = new THREE.PMREMGenerator(gl);
240
- const room = new RoomEnvironment();
241
- const rt = pmrem.fromScene(room, .04);
242
- const prevEnv = scene.environment;
243
- const prevInt = scene.environmentIntensity;
244
- scene.environment = rt.texture;
245
- scene.environmentIntensity = intensity;
246
- room.dispose();
247
- pmrem.dispose();
248
- return () => {
249
- scene.environment = prevEnv;
250
- scene.environmentIntensity = prevInt;
251
- rt.dispose();
252
- };
253
- }, [
254
- gl,
255
- scene,
256
- intensity
257
- ]);
258
- return null;
259
- }
260
- function KolmoCanvas({ children, className, style, fov = 56, near = .15, far = 4e3, cameraPosition = [
261
- 0,
262
- 3.2,
263
- -8.5
264
- ], dpr = [1, 1.5], frameloop = "always", shadows = true, antialias = true, toneMapping, roomEnv = .65 }) {
265
- return /* @__PURE__ */ jsxs(Canvas, {
266
- className,
267
- style: {
268
- width: "100%",
269
- height: "100%",
270
- display: "block",
271
- touchAction: "none",
272
- userSelect: "none",
273
- ...style
274
- },
275
- shadows,
276
- dpr,
277
- frameloop,
278
- gl: {
279
- antialias,
280
- powerPreference: "high-performance",
281
- ...toneMapping === void 0 ? {} : { toneMapping }
282
- },
283
- camera: {
284
- fov,
285
- near,
286
- far,
287
- position: cameraPosition
288
- },
289
- onCreated: ({ gl }) => {
290
- gl.outputColorSpace = THREE.SRGBColorSpace;
291
- },
292
- children: [roomEnv !== false && /* @__PURE__ */ jsx(RoomEnvRig, { intensity: typeof roomEnv === "number" ? roomEnv : .65 }), children]
293
- });
294
- }
295
- function KolmoWorld({ gravity = "planar", paused = false, timeScale = 1, maxDelta, physicsDebug = false, skybox = "day", lighting = "default", fogExp2, sunLightRef, world = kolmoWorld, keyboardMap = KOLMO_KEY_MAP, children }) {
296
- const outerWorld = useOptionalKootaWorld();
297
- const effectiveWorld = world ?? outerWorld ?? kolmoWorld;
298
- useLayoutEffect(() => {
299
- ensureWorldSession(effectiveWorld);
300
- }, [effectiveWorld]);
301
- const inner = /* @__PURE__ */ jsxs(KolmoInCanvasContext.Provider, {
302
- value: true,
303
- children: [
304
- skybox === "day" && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("color", {
305
- attach: "background",
306
- args: ["#6ba6d6"]
307
- }), !fogExp2 && /* @__PURE__ */ jsx("fog", {
308
- attach: "fog",
309
- args: [
310
- "#9dc4e2",
311
- 110,
312
- 520
313
- ]
314
- })] }),
315
- skybox === "night" && /* @__PURE__ */ jsx("color", {
316
- attach: "background",
317
- args: ["#090d16"]
318
- }),
319
- fogExp2 && /* @__PURE__ */ jsx("fogExp2", {
320
- attach: "fog",
321
- args: fogExp2
322
- }),
323
- lighting === "default" && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("hemisphereLight", { args: [
324
- "#b8dcff",
325
- "#241d30",
326
- .8
327
- ] }), /* @__PURE__ */ jsx("directionalLight", {
328
- ref: sunLightRef,
329
- position: [
330
- 48,
331
- 76,
332
- 36
333
- ],
334
- intensity: 1.85,
335
- color: "#fff3dc",
336
- castShadow: true,
337
- "shadow-mapSize": [2048, 2048],
338
- "shadow-bias": -4e-4,
339
- "shadow-camera-left": -55,
340
- "shadow-camera-right": 55,
341
- "shadow-camera-top": 55,
342
- "shadow-camera-bottom": -55,
343
- "shadow-camera-near": 1,
344
- "shadow-camera-far": 220
345
- })] }),
346
- /* @__PURE__ */ jsx(KolmoPhysics, {
347
- gravity,
348
- paused,
349
- timeScale,
350
- maxDelta,
351
- physicsDebug,
352
- world: effectiveWorld,
353
- children
354
- })
355
- ]
356
- });
357
- const withKeyboard = keyboardMap ? /* @__PURE__ */ jsx(KeyboardControls, {
358
- map: keyboardMap,
359
- children: /* @__PURE__ */ jsx(KolmoKeyboardBridge, { children: inner })
360
- }) : /* @__PURE__ */ jsx(KolmoKeyboardContext.Provider, {
361
- value: null,
362
- children: inner
363
- });
364
- return effectiveWorld !== outerWorld ? /* @__PURE__ */ jsx(KolmoWorldContext.Provider, {
365
- value: effectiveWorld,
366
- children: /* @__PURE__ */ jsx(WorldProvider, {
367
- world: effectiveWorld,
368
- children: withKeyboard
254
+ }), /* @__PURE__ */ jsx("group", {
255
+ visible: onFoot,
256
+ children: /* @__PURE__ */ jsx(Ecctrl, {
257
+ ref: assignEcctrlRef,
258
+ enable: onFoot,
259
+ enableCustomGravity: effCustomGravity,
260
+ position,
261
+ ...rotation === void 0 ? {} : { rotation },
262
+ userData: mergedUserData,
263
+ ...ecctrlRest,
264
+ children: children ?? (clonedScene ? /* @__PURE__ */ jsx("primitive", { object: clonedScene }) : null)
369
265
  })
370
- }) : withKeyboard;
371
- }
372
- function useKolmoGame(explicitWorld) {
373
- const active = useActiveKolmoWorld();
374
- const targetWorld = explicitWorld ?? active;
375
- const [, bump] = useReducer((x) => x + 1, 0);
376
- useEffect(() => {
377
- ensureWorldSession(targetWorld);
378
- const onChange = () => bump();
379
- const u1 = targetWorld.onChange(WorldSessionTrait, onChange);
380
- const u2 = targetWorld.onAdd(PilotedTag, onChange);
381
- const u3 = targetWorld.onRemove(PilotedTag, onChange);
382
- const u4 = targetWorld.onAdd(PilotLink, onChange);
383
- const u5 = targetWorld.onRemove(PilotLink, onChange);
384
- return () => {
385
- u1();
386
- u2();
387
- u3();
388
- u4();
389
- u5();
390
- };
391
- }, [targetWorld]);
392
- const session = targetWorld.has(WorldSessionTrait) ? targetWorld.get(WorldSessionTrait) : void 0;
393
- const pilotedData = (targetWorld.queryFirst(ActorTrait)?.targetFor(PilotLink) ?? targetWorld.queryFirst(pilotedVehicleQuery))?.get(VehicleTrait);
394
- const actions = kolmoActions(targetWorld);
395
- return {
396
- world: targetWorld,
397
- mode: pilotedData ? pilotedData.isFlight ? "flight" : "car" : "foot",
398
- activeVehicleId: pilotedData?.id ?? "",
399
- nearVehicleId: session?.nearVehicleId || null,
400
- boardVehicle: actions.boardVehicle,
401
- exitVehicle: actions.exitVehicle,
402
- resetVehicle: actions.resetVehicle
403
- };
404
- }
405
- function detectTouchDevice() {
406
- if (typeof window === "undefined") return false;
407
- return navigator.maxTouchPoints > 0 || window.matchMedia?.("(pointer: coarse)")?.matches === true;
408
- }
409
- function formatHudStrings(world) {
410
- const actor = world.queryFirst(ActorTrait);
411
- const vehEnt = actor?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);
412
- if (vehEnt) {
413
- const vd = vehEnt.get(VehicleTrait);
414
- const vel = vehEnt.get(VelocityTrait);
415
- const tel = vehEnt.get(VehicleTelemetryTrait);
416
- const kmh = Math.round(vel?.speedKmh ?? 0);
417
- const rpm = Math.round(tel?.rpm ?? 0);
418
- const gear = tel?.gear ?? 1;
419
- return {
420
- line: `${vd?.isFlight ? "Flight" : "Car"} · ${kmh} km/h · G${gear} · ${rpm} rpm`,
421
- prompt: vd?.isFlight ? "[WASD] Fly · [Space/X] Rise/Dive · [Shift] Boost · [G] Mode · [V] Cam · [F] Exit" : "[WASD] Drive · [Shift] Boost · [Space] Brake · [V] Cam · [R] Flip · [F] Exit"
422
- };
423
- }
424
- const vel = actor?.get(VelocityTrait);
425
- const near = world.has(WorldSessionTrait) ? world.get(WorldSessionTrait)?.nearVehicleId : "";
426
- return {
427
- line: `On foot · ${Math.round(vel?.speedKmh ?? 0)} km/h`,
428
- prompt: near ? "[F] Board vehicle · [WASD] Walk · [Shift] Sprint · [Space] Jump" : "[WASD] Walk · [Shift] Sprint · [Space] Jump"
429
- };
430
- }
431
- function KolmoHudView({ telemetryRef, promptRef, touchEnabled, style }) {
432
- return /* @__PURE__ */ jsxs("div", {
433
- style: {
434
- position: "fixed",
435
- inset: 0,
436
- pointerEvents: "none",
437
- zIndex: 30,
438
- fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
439
- color: "#e6edf3",
440
- ...style
441
- },
442
- children: [/* @__PURE__ */ jsx("div", {
443
- ref: telemetryRef,
444
- style: {
445
- position: "absolute",
446
- top: "max(10px, env(safe-area-inset-top))",
447
- left: "max(12px, env(safe-area-inset-left))",
448
- padding: "6px 10px",
449
- background: "rgba(9, 13, 22, 0.82)",
450
- border: "1px solid #38bdf8",
451
- borderRadius: 4,
452
- fontSize: 12,
453
- fontWeight: 700
454
- },
455
- children: "On foot · 0 km/h"
456
- }), !touchEnabled ? /* @__PURE__ */ jsx("div", {
457
- ref: promptRef,
458
- style: {
459
- position: "absolute",
460
- bottom: "max(12px, env(safe-area-inset-bottom))",
461
- left: "50%",
462
- transform: "translateX(-50%)",
463
- padding: "5px 10px",
464
- background: "rgba(9, 13, 22, 0.78)",
465
- border: "1px solid rgba(255,255,255,0.16)",
466
- borderRadius: 4,
467
- fontSize: 11,
468
- whiteSpace: "nowrap"
469
- },
470
- children: "[WASD] Walk · [Shift] Sprint · [Space] Jump"
471
- }) : /* @__PURE__ */ jsxs("div", {
472
- style: { pointerEvents: "auto" },
473
- children: [
474
- /* @__PURE__ */ jsx(Joystick, {}),
475
- /* @__PURE__ */ jsx(VirtualButton, {
476
- id: "jump",
477
- label: "JMP",
478
- buttonWrapperStyle: {
479
- position: "fixed",
480
- right: 20,
481
- bottom: 24
482
- }
483
- }),
484
- /* @__PURE__ */ jsx(VirtualButton, {
485
- id: "boost",
486
- label: "BST",
487
- buttonWrapperStyle: {
488
- position: "fixed",
489
- right: 88,
490
- bottom: 24
491
- }
492
- }),
493
- /* @__PURE__ */ jsx(VirtualButton, {
494
- id: "interact",
495
- label: "USE",
496
- buttonWrapperStyle: {
497
- position: "fixed",
498
- right: 20,
499
- bottom: 92
500
- }
501
- })
502
- ]
503
- })]
504
- });
505
- }
506
- function KolmoHudInCanvas({ showTouchControls, extraPrompt, style }) {
507
- const portalTarget = useContext(KolmoOverlayPortalContext);
508
- const world = useActiveKolmoWorld();
509
- const telemetryRef = useRef(null);
510
- const promptRef = useRef(null);
511
- const lastRef = useRef({
512
- line: "",
513
- prompt: "",
514
- elapsed: 0
515
- });
516
- const [isTouch, setIsTouch] = useState(detectTouchDevice);
517
- useEffect(() => {
518
- setIsTouch(detectTouchDevice());
519
- }, []);
520
- const touchEnabled = showTouchControls ?? isTouch;
521
- useFrame((_, delta) => {
522
- const st = lastRef.current;
523
- st.elapsed += delta;
524
- if (st.elapsed < .05) return;
525
- st.elapsed = 0;
526
- const { line, prompt } = formatHudStrings(world);
527
- const fullPrompt = extraPrompt ? `${prompt} · ${extraPrompt}` : prompt;
528
- if (line !== st.line && telemetryRef.current) {
529
- telemetryRef.current.textContent = line;
530
- st.line = line;
531
- }
532
- if (fullPrompt !== st.prompt && promptRef.current) {
533
- promptRef.current.textContent = fullPrompt;
534
- st.prompt = fullPrompt;
535
- }
536
- });
537
- const target = portalTarget ?? (typeof document !== "undefined" ? document.body : null);
538
- if (!target) return null;
539
- return createPortal$1(/* @__PURE__ */ jsx(KolmoHudView, {
540
- telemetryRef,
541
- promptRef,
542
- touchEnabled,
543
- style
544
- }), target);
545
- }
546
- function KolmoHudOutsideCanvas({ showTouchControls, extraPrompt, style }) {
547
- const world = useActiveKolmoWorld();
548
- const telemetryRef = useRef(null);
549
- const promptRef = useRef(null);
550
- const [isTouch, setIsTouch] = useState(detectTouchDevice);
551
- useEffect(() => {
552
- setIsTouch(detectTouchDevice());
553
- }, []);
554
- const touchEnabled = showTouchControls ?? isTouch;
555
- useEffect(() => {
556
- const sync = () => {
557
- const { line, prompt } = formatHudStrings(world);
558
- const fullPrompt = extraPrompt ? `${prompt} · ${extraPrompt}` : prompt;
559
- if (telemetryRef.current) telemetryRef.current.textContent = line;
560
- if (promptRef.current) promptRef.current.textContent = fullPrompt;
561
- };
562
- sync();
563
- const id = window.setInterval(sync, 66);
564
- return () => window.clearInterval(id);
565
- }, [world, extraPrompt]);
566
- return /* @__PURE__ */ jsx(KolmoHudView, {
567
- telemetryRef,
568
- promptRef,
569
- touchEnabled,
570
- style
571
- });
572
- }
573
- function KolmoHud(props) {
574
- return useContext(KolmoInCanvasContext) ? /* @__PURE__ */ jsx(KolmoHudInCanvas, { ...props }) : /* @__PURE__ */ jsx(KolmoHudOutsideCanvas, { ...props });
575
- }
576
- function KolmoGame({ gravity = "planar", skybox = "day", lighting = "default", fogExp2, paused = false, timeScale = 1, maxDelta, physicsDebug = false, dpr, roomEnv = .65, kootaWorld = kolmoWorld, style, className, children }) {
577
- const outerWorld = useOptionalKootaWorld();
578
- const [overlayEl, setOverlayEl] = useState(null);
579
- const shell = /* @__PURE__ */ jsx(KolmoOverlayPortalContext.Provider, {
580
- value: overlayEl,
581
- children: /* @__PURE__ */ jsxs("div", {
582
- className,
583
- style: {
584
- position: "relative",
585
- width: "100vw",
586
- height: "100dvh",
587
- overflow: "hidden",
588
- touchAction: "none",
589
- userSelect: "none",
590
- ...style
591
- },
592
- children: [/* @__PURE__ */ jsx(KolmoCanvas, {
593
- dpr,
594
- roomEnv,
595
- children: /* @__PURE__ */ jsx(KolmoWorld, {
596
- gravity,
597
- paused,
598
- timeScale,
599
- maxDelta,
600
- skybox,
601
- lighting,
602
- fogExp2,
603
- physicsDebug,
604
- world: kootaWorld,
605
- children
606
- })
607
- }), /* @__PURE__ */ jsx("div", {
608
- ref: setOverlayEl,
609
- style: {
610
- position: "absolute",
611
- inset: 0,
612
- pointerEvents: "none"
613
- }
614
- })]
615
- })
616
- });
617
- return kootaWorld !== outerWorld ? /* @__PURE__ */ jsx(KolmoWorldContext.Provider, {
618
- value: kootaWorld,
619
- children: /* @__PURE__ */ jsx(WorldProvider, {
620
- world: kootaWorld,
621
- children: shell
622
- })
623
- }) : shell;
266
+ })] });
624
267
  }
625
268
  // src/engine/gltfLoader.ts
626
269
  var ktx2ByRenderer = /* @__PURE__ */ new WeakMap();