@pinkaphant/kolmo 0.5.1 → 0.5.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 (41) hide show
  1. package/README.md +92 -14
  2. package/dist/engine/actor.d.ts +1 -1
  3. package/dist/engine/index.d.ts +3 -0
  4. package/dist/engine/index.js +94 -441
  5. package/dist/engine/index.js.map +1 -1
  6. package/dist/engine/surface.d.ts +5 -6
  7. package/dist/engine/traits.d.ts +27 -0
  8. package/dist/engine/world.d.ts +5 -3
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +10 -6
  11. package/dist/physics/index.d.ts +2 -1
  12. package/dist/physics/index.js +3 -1
  13. package/dist/physics-KYWAXctg.js +233 -0
  14. package/dist/physics-KYWAXctg.js.map +1 -0
  15. package/dist/replay/index.d.ts +84 -0
  16. package/dist/replay/index.js +380 -0
  17. package/dist/replay/index.js.map +1 -0
  18. package/dist/terrain/index.d.ts +119 -0
  19. package/dist/terrain/index.js +495 -0
  20. package/dist/terrain/index.js.map +1 -0
  21. package/dist/toolgun/Toolgun.d.ts +17 -6
  22. package/dist/toolgun/index.d.ts +2 -2
  23. package/dist/toolgun/index.js +1 -1
  24. package/dist/toolgun/store.d.ts +25 -75
  25. package/dist/{toolgun-BfcCIAQx.js → toolgun-COu_5SxS.js} +391 -673
  26. package/dist/toolgun-COu_5SxS.js.map +1 -0
  27. package/dist/traits-Dp1ey_4w.js +267 -0
  28. package/dist/traits-Dp1ey_4w.js.map +1 -0
  29. package/dist/vite/index.js +1 -0
  30. package/dist/vite/index.js.map +1 -1
  31. package/dist/water/index.d.ts +71 -0
  32. package/dist/water/index.js +442 -0
  33. package/dist/water/index.js.map +1 -0
  34. package/dist/{surface-DUol_5ml.js → world-BDhBihjW.js} +442 -57
  35. package/dist/world-BDhBihjW.js.map +1 -0
  36. package/docs/api-reference.md +201 -0
  37. package/package.json +25 -8
  38. package/dist/physics-ZDFXaCli.js +0 -475
  39. package/dist/physics-ZDFXaCli.js.map +0 -1
  40. package/dist/surface-DUol_5ml.js.map +0 -1
  41. package/dist/toolgun-BfcCIAQx.js.map +0 -1
@@ -1,15 +1,19 @@
1
- import { A as writeEntityKinematics, C as flipVehicleBodyUpright, D as useActiveKolmoWorld, E as pilotedVehicleQuery, S as ensureWorldSession, _ as VehicleTelemetryTrait, f as InteractableTrait, g as TransformTrait, h as PilotedTag, j as writeVehicleTelemetry, t as KolmoGravityContext, v as VehicleTrait, w as kolmoActions, x as createEmptyVehicleCmd, y as VelocityTrait } from "./physics-ZDFXaCli.js";
2
- import React, { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
1
+ import { C as writeEntityKinematics, _ as kolmoWorld, a as PilotedTag, b as useActiveKolmoWorld, c as VehicleTelemetryTrait, d as WorldSessionTrait, f as createEmptyVehicleCmd, g as kolmoActions, i as PilotLink, l as VehicleTrait, m as flipVehicleBodyUpright, n as InteractableTrait, o as PropTrait, p as ensureWorldSession, r as KolmoWorldContext, s as TransformTrait, t as ActorTrait, u as VelocityTrait, v as pilotedVehicleQuery, w as writeVehicleTelemetry, x as useOptionalKootaWorld } from "./traits-Dp1ey_4w.js";
2
+ import { n as KolmoPhysics, t as KolmoGravityContext } from "./physics-KYWAXctg.js";
3
+ import React, { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useReducer, useRef, useState } from "react";
3
4
  import * as THREE from "three";
4
- import { useKeyboardControls } from "@react-three/drei";
5
- import { useButtonStore, useJoystickStore } from "@pinkaphant/ecctrl/input";
6
- import { useFrame } from "@react-three/fiber";
7
- import { CuboidCollider, RigidBody, useRapier } from "@react-three/rapier";
8
- import { useHas } from "koota/react";
5
+ import "koota";
6
+ import { KeyboardControls, useKeyboardControls } from "@react-three/drei";
7
+ import { Joystick, VirtualButton, useButtonStore, useJoystickStore } from "@pinkaphant/ecctrl/input";
8
+ import { Canvas, addEffect, useFrame, useThree } from "@react-three/fiber";
9
+ import { useRapier } from "@react-three/rapier";
10
+ import { WorldProvider, useHas } from "koota/react";
9
11
  import { KhrAssembly, assignRef, cloneKhrBundle, useKhrGlb } from "@khr3/core";
10
- import { jsx, jsxs } from "react/jsx-runtime";
12
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
13
  import { easing } from "maath";
12
14
  import { KhrVehicle } from "@khr3/core/vehicle";
15
+ import { createPortal as createPortal$1 } from "react-dom";
16
+ import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
13
17
  // src/engine/input.ts
14
18
  var KolmoKeyboardContext = createContext(null);
15
19
  function KolmoKeyboardBridge({ children }) {
@@ -178,7 +182,7 @@ function KolmoVehicleMount({ ref, vehicleRef, jointsRef: outerJointsRef, id, sou
178
182
  const isFlight = Boolean(vehicleMode === "rocket" || (canHybridToggle ? hybridFlight : flightMode) || vehicleMode !== "drive" && bundle.propellers.length > 0 && bundle.wheels.length === 0);
179
183
  const isManualTrans = (carConfig?.transmissionMode ?? bundle.tune?.transmissionMode) === "manual";
180
184
  const seatOffset = useMemo(() => {
181
- const dot = bundle.sockets.IK_Seat ?? bundle.sockets.seat ?? bundle.sockets.driver_butt ?? bundle.sockets.butt;
185
+ const dot = bundle.sockets.seat ?? bundle.sockets.Socket_Seat ?? bundle.sockets.IK_Seat ?? bundle.sockets.Seat_L ?? bundle.sockets.driver_butt ?? bundle.sockets.butt;
182
186
  return dot ? [
183
187
  dot[0],
184
188
  dot[1],
@@ -190,7 +194,7 @@ function KolmoVehicleMount({ ref, vehicleRef, jointsRef: outerJointsRef, id, sou
190
194
  ];
191
195
  }, [bundle.sockets]);
192
196
  const exitOffset = useMemo(() => {
193
- const dot = bundle.sockets.Socket_Exit ?? bundle.sockets.exit;
197
+ const dot = bundle.sockets.exit ?? bundle.sockets.Socket_Exit;
194
198
  return dot ? [
195
199
  dot[0],
196
200
  dot[1],
@@ -486,42 +490,6 @@ function KolmoVehicle(props) {
486
490
  return null;
487
491
  }
488
492
  // src/engine/surface.tsx
489
- function ArenaSlab({ size, position, color = "#252b36" }) {
490
- const res = useMemo(() => ({
491
- geo: new THREE.BoxGeometry(size, 1, size),
492
- mat: new THREE.MeshStandardMaterial({
493
- color,
494
- roughness: .9,
495
- metalness: .05
496
- })
497
- }), [size, color]);
498
- useEffect(() => () => {
499
- res.geo.dispose();
500
- res.mat.dispose();
501
- }, [res]);
502
- return /* @__PURE__ */ jsxs(RigidBody, {
503
- type: "fixed",
504
- colliders: false,
505
- position: [
506
- position[0],
507
- position[1] - .5,
508
- position[2]
509
- ],
510
- friction: .9,
511
- children: [/* @__PURE__ */ jsx(CuboidCollider, {
512
- args: [
513
- size * .5,
514
- .5,
515
- size * .5
516
- ],
517
- restitution: .04
518
- }), /* @__PURE__ */ jsx("mesh", {
519
- geometry: res.geo,
520
- material: res.mat,
521
- receiveShadow: true
522
- })]
523
- });
524
- }
525
493
  function BundleSurface({ ref, bundle, alreadyCloned = false, position, enableCustomGravity, ...rest }) {
526
494
  const ctxCustomGravity = useContext(KolmoGravityContext);
527
495
  const cloned = useMemo(() => alreadyCloned ? bundle : cloneKhrBundle(bundle), [bundle, alreadyCloned]);
@@ -542,7 +510,7 @@ function UrlSurface({ src, ...rest }) {
542
510
  ...rest
543
511
  });
544
512
  }
545
- function KolmoSurface({ ref, src, bundle, size = 200, color, position = [
513
+ function KolmoSurface({ ref, src, bundle, position = [
546
514
  0,
547
515
  0,
548
516
  0
@@ -559,20 +527,59 @@ function KolmoSurface({ ref, src, bundle, size = 200, color, position = [
559
527
  position,
560
528
  ...rest
561
529
  });
562
- return /* @__PURE__ */ jsx(ArenaSlab, {
563
- size,
564
- position,
565
- color
566
- });
530
+ throw new Error("KolmoSurface requires a KHR .glb `bundle` or `src` — use <KolmoTerrain> for mathematical heightfield terrain.");
567
531
  }
568
- function BundleProp({ ref, bundle, alreadyCloned = false, fixed = false, enableCustomGravity, onClick: userOnClick, ...rest }) {
532
+ function BundleProp({ ref, propId, bundle, alreadyCloned = false, fixed = false, enableCustomGravity, onClick: userOnClick, ...rest }) {
569
533
  const ctxCustomGravity = useContext(KolmoGravityContext);
534
+ const activeWorld = useActiveKolmoWorld();
535
+ const { world: rapierWorld } = useRapier();
570
536
  const asmRef = useRef(null);
537
+ const propEntRef = useRef(null);
571
538
  const cloned = useMemo(() => alreadyCloned ? bundle : cloneKhrBundle(bundle), [bundle, alreadyCloned]);
539
+ const rootBodyName = useMemo(() => cloned.bodies.find((b) => !b.joint)?.nodeName ?? cloned.bodies[0]?.nodeName ?? "", [cloned]);
540
+ useLayoutEffect(() => {
541
+ const ent = activeWorld.spawn(PropTrait({
542
+ id: propId,
543
+ handle: asmRef.current,
544
+ fixed
545
+ }), TransformTrait, VelocityTrait);
546
+ propEntRef.current = ent;
547
+ return () => {
548
+ propEntRef.current = null;
549
+ if (ent.isAlive()) ent.destroy();
550
+ };
551
+ }, [
552
+ activeWorld,
553
+ propId,
554
+ fixed
555
+ ]);
572
556
  const assignAsmRef = useCallback((h) => {
573
557
  asmRef.current = h;
574
558
  assignRef(ref, h);
575
- }, [ref]);
559
+ const ent = propEntRef.current;
560
+ if (ent?.isAlive()) ent.set(PropTrait, {
561
+ id: propId,
562
+ handle: h,
563
+ fixed
564
+ });
565
+ }, [
566
+ ref,
567
+ propId,
568
+ fixed
569
+ ]);
570
+ useFrame(() => {
571
+ if (fixed || !rootBodyName) return;
572
+ const ent = propEntRef.current;
573
+ const rawRb = asmRef.current?.getBody(rootBodyName) ?? null;
574
+ if (!ent?.isAlive() || !rawRb) return;
575
+ const liveRb = rapierWorld.getRigidBody(rawRb.handle);
576
+ if (!liveRb) return;
577
+ const t = liveRb.translation();
578
+ const r = liveRb.rotation();
579
+ const lv = liveRb.linvel();
580
+ const speedKmh = Math.hypot(lv.x, lv.y, lv.z) * 3.6;
581
+ writeEntityKinematics(activeWorld, ent, t, r, lv, speedKmh);
582
+ });
576
583
  const onClick = useCallback((e) => {
577
584
  if (e.delta <= 5 && asmRef.current?.toggleHitObject(e.object)) e.stopPropagation();
578
585
  userOnClick?.(e);
@@ -594,17 +601,395 @@ function UrlProp({ src, ...rest }) {
594
601
  ...rest
595
602
  });
596
603
  }
597
- function KolmoProp({ src, bundle, ...rest }) {
604
+ function KolmoProp({ id: explicitId, src, bundle, ...rest }) {
605
+ const reactId = useId();
606
+ const propId = explicitId ?? `prop_${reactId.replace(/:/g, "")}`;
598
607
  if (bundle) return /* @__PURE__ */ jsx(BundleProp, {
608
+ propId,
599
609
  bundle,
600
610
  ...rest
601
611
  });
602
612
  if (src) return /* @__PURE__ */ jsx(UrlProp, {
613
+ propId,
603
614
  src,
604
615
  ...rest
605
616
  });
617
+ throw new Error("KolmoProp requires a KHR .glb `bundle` or `src`.");
618
+ }
619
+ // src/engine/world.tsx
620
+ var KolmoInCanvasContext = createContext(false);
621
+ var KolmoOverlayPortalContext = createContext(null);
622
+ function RoomEnvRig({ intensity = .65 }) {
623
+ const { gl, scene } = useThree();
624
+ useEffect(() => {
625
+ const pmrem = new THREE.PMREMGenerator(gl);
626
+ const room = new RoomEnvironment();
627
+ const rt = pmrem.fromScene(room, .04);
628
+ const prevEnv = scene.environment;
629
+ const prevInt = scene.environmentIntensity;
630
+ scene.environment = rt.texture;
631
+ scene.environmentIntensity = intensity;
632
+ room.dispose();
633
+ pmrem.dispose();
634
+ return () => {
635
+ scene.environment = prevEnv;
636
+ scene.environmentIntensity = prevInt;
637
+ rt.dispose();
638
+ };
639
+ }, [
640
+ gl,
641
+ scene,
642
+ intensity
643
+ ]);
606
644
  return null;
607
645
  }
608
- export { KOLMO_KEY_MAP as a, KolmoKeyboardContext as c, EMPTY_KOLMO_INPUT as i, useKolmoInput as l, KolmoSurface as n, KOLMO_STICK_DEADZONE as o, KolmoVehicle as r, KolmoKeyboardBridge as s, KolmoProp as t };
646
+ function KolmoCanvas({ children, className, style, fov = 56, near = .15, far = 4e3, cameraPosition = [
647
+ 0,
648
+ 3.2,
649
+ -8.5
650
+ ], dpr = [1, 1.5], frameloop = "always", shadows = true, antialias = true, toneMapping, roomEnv = .65 }) {
651
+ return /* @__PURE__ */ jsxs(Canvas, {
652
+ className,
653
+ style: {
654
+ width: "100%",
655
+ height: "100%",
656
+ display: "block",
657
+ touchAction: "none",
658
+ userSelect: "none",
659
+ ...style
660
+ },
661
+ shadows,
662
+ dpr,
663
+ frameloop,
664
+ gl: {
665
+ antialias,
666
+ powerPreference: "high-performance",
667
+ ...toneMapping === void 0 ? {} : { toneMapping }
668
+ },
669
+ camera: {
670
+ fov,
671
+ near,
672
+ far,
673
+ position: cameraPosition
674
+ },
675
+ onCreated: ({ gl }) => {
676
+ gl.outputColorSpace = THREE.SRGBColorSpace;
677
+ },
678
+ children: [roomEnv !== false && /* @__PURE__ */ jsx(RoomEnvRig, { intensity: typeof roomEnv === "number" ? roomEnv : .65 }), children]
679
+ });
680
+ }
681
+ function KolmoWorld({ gravity = "planar", paused = false, timeScale = 1, maxDelta, debug, physicsDebug = false, skybox = "day", lighting = "default", fogExp2, sunLightRef, world = kolmoWorld, keyboardMap = KOLMO_KEY_MAP, children }) {
682
+ const effDebug = debug ?? physicsDebug;
683
+ const outerWorld = useOptionalKootaWorld();
684
+ const effectiveWorld = world ?? outerWorld ?? kolmoWorld;
685
+ useLayoutEffect(() => {
686
+ ensureWorldSession(effectiveWorld);
687
+ }, [effectiveWorld]);
688
+ const inner = /* @__PURE__ */ jsxs(KolmoInCanvasContext.Provider, {
689
+ value: true,
690
+ children: [
691
+ skybox === "day" && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("color", {
692
+ attach: "background",
693
+ args: ["#6ba6d6"]
694
+ }), !fogExp2 && /* @__PURE__ */ jsx("fog", {
695
+ attach: "fog",
696
+ args: [
697
+ "#9dc4e2",
698
+ 110,
699
+ 520
700
+ ]
701
+ })] }),
702
+ skybox === "night" && /* @__PURE__ */ jsx("color", {
703
+ attach: "background",
704
+ args: ["#090d16"]
705
+ }),
706
+ fogExp2 && /* @__PURE__ */ jsx("fogExp2", {
707
+ attach: "fog",
708
+ args: fogExp2
709
+ }),
710
+ lighting === "default" && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("hemisphereLight", { args: [
711
+ "#b8dcff",
712
+ "#241d30",
713
+ .8
714
+ ] }), /* @__PURE__ */ jsx("directionalLight", {
715
+ ref: sunLightRef,
716
+ position: [
717
+ 48,
718
+ 76,
719
+ 36
720
+ ],
721
+ intensity: 1.85,
722
+ color: "#fff3dc",
723
+ castShadow: true,
724
+ "shadow-mapSize": [2048, 2048],
725
+ "shadow-bias": -4e-4,
726
+ "shadow-camera-left": -55,
727
+ "shadow-camera-right": 55,
728
+ "shadow-camera-top": 55,
729
+ "shadow-camera-bottom": -55,
730
+ "shadow-camera-near": 1,
731
+ "shadow-camera-far": 220
732
+ })] }),
733
+ /* @__PURE__ */ jsx(KolmoPhysics, {
734
+ gravity,
735
+ paused,
736
+ timeScale,
737
+ maxDelta,
738
+ debug: effDebug,
739
+ world: effectiveWorld,
740
+ children
741
+ })
742
+ ]
743
+ });
744
+ const withKeyboard = keyboardMap ? /* @__PURE__ */ jsx(KeyboardControls, {
745
+ map: keyboardMap,
746
+ children: /* @__PURE__ */ jsx(KolmoKeyboardBridge, { children: inner })
747
+ }) : /* @__PURE__ */ jsx(KolmoKeyboardContext.Provider, {
748
+ value: null,
749
+ children: inner
750
+ });
751
+ return effectiveWorld !== outerWorld ? /* @__PURE__ */ jsx(KolmoWorldContext.Provider, {
752
+ value: effectiveWorld,
753
+ children: /* @__PURE__ */ jsx(WorldProvider, {
754
+ world: effectiveWorld,
755
+ children: withKeyboard
756
+ })
757
+ }) : withKeyboard;
758
+ }
759
+ function useKolmoGame(explicitWorld) {
760
+ const active = useActiveKolmoWorld();
761
+ const targetWorld = explicitWorld ?? active;
762
+ const [, bump] = useReducer((x) => x + 1, 0);
763
+ useEffect(() => {
764
+ ensureWorldSession(targetWorld);
765
+ const onChange = () => bump();
766
+ const u1 = targetWorld.onChange(WorldSessionTrait, onChange);
767
+ const u2 = targetWorld.onAdd(PilotedTag, onChange);
768
+ const u3 = targetWorld.onRemove(PilotedTag, onChange);
769
+ const u4 = targetWorld.onAdd(PilotLink, onChange);
770
+ const u5 = targetWorld.onRemove(PilotLink, onChange);
771
+ const u6 = targetWorld.onChange(VehicleTrait, onChange);
772
+ return () => {
773
+ u1();
774
+ u2();
775
+ u3();
776
+ u4();
777
+ u5();
778
+ u6();
779
+ };
780
+ }, [targetWorld]);
781
+ const session = targetWorld.has(WorldSessionTrait) ? targetWorld.get(WorldSessionTrait) : void 0;
782
+ const pilotedData = (targetWorld.queryFirst(ActorTrait)?.targetFor(PilotLink) ?? targetWorld.queryFirst(pilotedVehicleQuery))?.get(VehicleTrait);
783
+ const actions = kolmoActions(targetWorld);
784
+ return {
785
+ world: targetWorld,
786
+ mode: pilotedData ? pilotedData.isFlight ? "flight" : "car" : "foot",
787
+ activeVehicleId: pilotedData?.id ?? "",
788
+ nearVehicleId: session?.nearVehicleId || null,
789
+ boardVehicle: actions.boardVehicle,
790
+ exitVehicle: actions.exitVehicle,
791
+ resetVehicle: actions.resetVehicle
792
+ };
793
+ }
794
+ function detectTouchDevice() {
795
+ if (typeof window === "undefined") return false;
796
+ return navigator.maxTouchPoints > 0 || window.matchMedia?.("(pointer: coarse)")?.matches === true;
797
+ }
798
+ function formatHudStrings(world) {
799
+ const actor = world.queryFirst(ActorTrait);
800
+ const vehEnt = actor?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);
801
+ if (vehEnt) {
802
+ const vd = vehEnt.get(VehicleTrait);
803
+ const vel = vehEnt.get(VelocityTrait);
804
+ const tel = vehEnt.get(VehicleTelemetryTrait);
805
+ const kmh = Math.round(vel?.speedKmh ?? 0);
806
+ const rpm = Math.round(tel?.rpm ?? 0);
807
+ const gear = tel?.gear ?? 1;
808
+ return {
809
+ line: `${vd?.isFlight ? "Flight" : "Car"} · ${kmh} km/h · G${gear} · ${rpm} rpm`,
810
+ 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"
811
+ };
812
+ }
813
+ const vel = actor?.get(VelocityTrait);
814
+ const near = world.has(WorldSessionTrait) ? world.get(WorldSessionTrait)?.nearVehicleId : "";
815
+ return {
816
+ line: `On foot · ${Math.round(vel?.speedKmh ?? 0)} km/h`,
817
+ prompt: near ? "[F] Board vehicle · [WASD] Walk · [Shift] Sprint · [Space] Jump" : "[WASD] Walk · [Shift] Sprint · [Space] Jump"
818
+ };
819
+ }
820
+ function KolmoHud({ showTouchControls, extraPrompt, style }) {
821
+ const inCanvas = useContext(KolmoInCanvasContext);
822
+ const portalTarget = useContext(KolmoOverlayPortalContext);
823
+ const world = useActiveKolmoWorld();
824
+ const telemetryRef = useRef(null);
825
+ const promptRef = useRef(null);
826
+ const lastMsRef = useRef(-1e400);
827
+ const [isTouch, setIsTouch] = useState(detectTouchDevice);
828
+ useEffect(() => {
829
+ setIsTouch(detectTouchDevice());
830
+ }, []);
831
+ const touchEnabled = showTouchControls ?? isTouch;
832
+ useEffect(() => {
833
+ ensureWorldSession(world);
834
+ const sync = () => {
835
+ const { line, prompt } = formatHudStrings(world);
836
+ const fullPrompt = extraPrompt ? `${prompt} · ${extraPrompt}` : prompt;
837
+ if (telemetryRef.current && telemetryRef.current.textContent !== line) telemetryRef.current.textContent = line;
838
+ if (promptRef.current && promptRef.current.textContent !== fullPrompt) promptRef.current.textContent = fullPrompt;
839
+ };
840
+ sync();
841
+ const u1 = world.onChange(WorldSessionTrait, sync);
842
+ const u2 = world.onAdd(PilotedTag, sync);
843
+ const u3 = world.onRemove(PilotedTag, sync);
844
+ const u4 = world.onAdd(PilotLink, sync);
845
+ const u5 = world.onRemove(PilotLink, sync);
846
+ const u6 = world.onChange(VehicleTrait, sync);
847
+ const unsubFrame = addEffect((now) => {
848
+ if (Math.abs(now - lastMsRef.current) < 50) return;
849
+ lastMsRef.current = now;
850
+ sync();
851
+ });
852
+ return () => {
853
+ u1();
854
+ u2();
855
+ u3();
856
+ u4();
857
+ u5();
858
+ u6();
859
+ unsubFrame();
860
+ };
861
+ }, [
862
+ world,
863
+ extraPrompt,
864
+ touchEnabled
865
+ ]);
866
+ const hudMarkup = /* @__PURE__ */ jsxs("div", {
867
+ style: {
868
+ position: "fixed",
869
+ inset: 0,
870
+ pointerEvents: "none",
871
+ zIndex: 30,
872
+ fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
873
+ color: "#e6edf3",
874
+ ...style
875
+ },
876
+ children: [/* @__PURE__ */ jsx("div", {
877
+ ref: telemetryRef,
878
+ style: {
879
+ position: "absolute",
880
+ top: "max(10px, env(safe-area-inset-top))",
881
+ left: "max(12px, env(safe-area-inset-left))",
882
+ padding: "6px 10px",
883
+ background: "rgba(9, 13, 22, 0.82)",
884
+ border: "1px solid #38bdf8",
885
+ borderRadius: 4,
886
+ fontSize: 12,
887
+ fontWeight: 700
888
+ },
889
+ children: "On foot · 0 km/h"
890
+ }), !touchEnabled ? /* @__PURE__ */ jsx("div", {
891
+ ref: promptRef,
892
+ style: {
893
+ position: "absolute",
894
+ bottom: "max(12px, env(safe-area-inset-bottom))",
895
+ left: "50%",
896
+ transform: "translateX(-50%)",
897
+ padding: "5px 10px",
898
+ background: "rgba(9, 13, 22, 0.78)",
899
+ border: "1px solid rgba(255,255,255,0.16)",
900
+ borderRadius: 4,
901
+ fontSize: 11,
902
+ whiteSpace: "nowrap"
903
+ },
904
+ children: "[WASD] Walk · [Shift] Sprint · [Space] Jump"
905
+ }) : /* @__PURE__ */ jsxs("div", {
906
+ style: { pointerEvents: "auto" },
907
+ children: [
908
+ /* @__PURE__ */ jsx(Joystick, {}),
909
+ /* @__PURE__ */ jsx(VirtualButton, {
910
+ id: "jump",
911
+ label: "JMP",
912
+ buttonWrapperStyle: {
913
+ position: "fixed",
914
+ right: 20,
915
+ bottom: 24
916
+ }
917
+ }),
918
+ /* @__PURE__ */ jsx(VirtualButton, {
919
+ id: "boost",
920
+ label: "BST",
921
+ buttonWrapperStyle: {
922
+ position: "fixed",
923
+ right: 88,
924
+ bottom: 24
925
+ }
926
+ }),
927
+ /* @__PURE__ */ jsx(VirtualButton, {
928
+ id: "interact",
929
+ label: "USE",
930
+ buttonWrapperStyle: {
931
+ position: "fixed",
932
+ right: 20,
933
+ bottom: 92
934
+ }
935
+ })
936
+ ]
937
+ })]
938
+ });
939
+ if (!inCanvas) return hudMarkup;
940
+ const target = portalTarget ?? (typeof document !== "undefined" ? document.body : null);
941
+ return target ? createPortal$1(hudMarkup, target) : null;
942
+ }
943
+ function KolmoGame({ gravity = "planar", skybox = "day", lighting = "default", fogExp2, paused = false, timeScale = 1, maxDelta, debug, physicsDebug = false, dpr, roomEnv = .65, kootaWorld = kolmoWorld, style, className, children }) {
944
+ const effDebug = debug ?? physicsDebug;
945
+ const outerWorld = useOptionalKootaWorld();
946
+ const [overlayEl, setOverlayEl] = useState(null);
947
+ const shell = /* @__PURE__ */ jsx(KolmoOverlayPortalContext.Provider, {
948
+ value: overlayEl,
949
+ children: /* @__PURE__ */ jsxs("div", {
950
+ className,
951
+ style: {
952
+ position: "relative",
953
+ width: "100vw",
954
+ height: "100dvh",
955
+ overflow: "hidden",
956
+ touchAction: "none",
957
+ userSelect: "none",
958
+ ...style
959
+ },
960
+ children: [/* @__PURE__ */ jsx(KolmoCanvas, {
961
+ dpr,
962
+ roomEnv,
963
+ children: /* @__PURE__ */ jsx(KolmoWorld, {
964
+ gravity,
965
+ paused,
966
+ timeScale,
967
+ maxDelta,
968
+ skybox,
969
+ lighting,
970
+ fogExp2,
971
+ debug: effDebug,
972
+ world: kootaWorld,
973
+ children
974
+ })
975
+ }), /* @__PURE__ */ jsx("div", {
976
+ ref: setOverlayEl,
977
+ style: {
978
+ position: "absolute",
979
+ inset: 0,
980
+ pointerEvents: "none"
981
+ }
982
+ })]
983
+ })
984
+ });
985
+ return kootaWorld !== outerWorld ? /* @__PURE__ */ jsx(KolmoWorldContext.Provider, {
986
+ value: kootaWorld,
987
+ children: /* @__PURE__ */ jsx(WorldProvider, {
988
+ world: kootaWorld,
989
+ children: shell
990
+ })
991
+ }) : shell;
992
+ }
993
+ export { useKolmoInput as _, KolmoOverlayPortalContext as a, useKolmoGame as c, KolmoVehicle as d, EMPTY_KOLMO_INPUT as f, KolmoKeyboardContext as g, KolmoKeyboardBridge as h, KolmoInCanvasContext as i, KolmoProp as l, KOLMO_STICK_DEADZONE as m, KolmoGame as n, KolmoWorld as o, KOLMO_KEY_MAP as p, KolmoHud as r, RoomEnvRig as s, KolmoCanvas as t, KolmoSurface as u };
609
994
 
610
- //# sourceMappingURL=surface-DUol_5ml.js.map
995
+ //# sourceMappingURL=world-BDhBihjW.js.map