@pinkaphant/kolmo 0.5.2 → 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.
- package/README.md +92 -14
- package/dist/engine/actor.d.ts +1 -1
- package/dist/engine/index.d.ts +3 -0
- package/dist/engine/index.js +44 -34
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/surface.d.ts +5 -6
- package/dist/engine/traits.d.ts +27 -0
- package/dist/engine/world.d.ts +5 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9 -5
- package/dist/physics/index.d.ts +2 -1
- package/dist/physics/index.js +3 -1
- package/dist/physics-KYWAXctg.js +233 -0
- package/dist/physics-KYWAXctg.js.map +1 -0
- package/dist/replay/index.d.ts +84 -0
- package/dist/replay/index.js +380 -0
- package/dist/replay/index.js.map +1 -0
- package/dist/terrain/index.d.ts +119 -0
- package/dist/terrain/index.js +495 -0
- package/dist/terrain/index.js.map +1 -0
- package/dist/toolgun/Toolgun.d.ts +11 -4
- package/dist/toolgun/index.d.ts +2 -2
- package/dist/toolgun/index.js +1 -1
- package/dist/{toolgun-CFCNO00q.js → toolgun-COu_5SxS.js} +202 -542
- package/dist/toolgun-COu_5SxS.js.map +1 -0
- package/dist/traits-Dp1ey_4w.js +267 -0
- package/dist/traits-Dp1ey_4w.js.map +1 -0
- package/dist/vite/index.js +1 -0
- package/dist/vite/index.js.map +1 -1
- package/dist/water/index.d.ts +71 -0
- package/dist/water/index.js +442 -0
- package/dist/water/index.js.map +1 -0
- package/dist/{world-BljtS6Fb.js → world-BDhBihjW.js} +114 -139
- package/dist/world-BDhBihjW.js.map +1 -0
- package/docs/api-reference.md +201 -0
- package/package.json +23 -6
- package/dist/physics-CA1abDCY.js +0 -476
- package/dist/physics-CA1abDCY.js.map +0 -1
- package/dist/toolgun/c12Outlets.d.ts +0 -36
- package/dist/toolgun-CFCNO00q.js.map +0 -1
- package/dist/world-BljtS6Fb.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,29 +1,107 @@
|
|
|
1
1
|
# `@pinkaphant/kolmo`
|
|
2
2
|
|
|
3
|
-
Thin React Three Fiber + Rapier WASM
|
|
3
|
+
Thin, composable React Three Fiber + Rapier WASM + `@pinkaphant/ecctrl` + `@khr3/core` + `@khr3/c12` + Koota ECA game layer.
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
- **
|
|
7
|
-
-
|
|
8
|
-
- **`<Toolgun />` (`@pinkaphant/kolmo/toolgun`)**: Handheld physics/building toolgun with real Rapier WASM raycasts (`castRayAndGetNormal`), two-shot Fixed Weld & Revolute Hinge `ImpulseJoint`s, direct `@khr3/core` `JointRuntime` rigging/breakaway, KHR `.glb` spawning, exact `@khr3/c12` 30° `yaw12` socket building, and diegetic `256×192` LCD screen.
|
|
5
|
+
- **Full API Reference**: [`docs/api-reference.md`](./docs/api-reference.md)
|
|
6
|
+
- **SI Right-Handed Frame**: `1.0 unit === 1.0 m`, `+Y` up, `+Z` forward, baked `[1, 1, 1]` scale.
|
|
7
|
+
- **React 19 `<StrictMode>` Safe**: Every Rapier `RigidBody` and `ImpulseJoint` pointer is verified against the live `RAPIER.World` before mutation.
|
|
9
8
|
|
|
10
|
-
##
|
|
9
|
+
## Installation & Vite Config
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @pinkaphant/kolmo @khr3/core @khr3/c12 @khr3/roads @pinkaphant/ecctrl \
|
|
13
|
+
three @react-three/fiber @react-three/drei @react-three/rapier @dimforge/rapier3d-compat \
|
|
14
|
+
koota maath zustand
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Always pass `KOLMO_SINGLETON_DEDUPE` in `vite.config.ts` so React, R3F, Rapier WASM, Koota, and Zustand share singletons:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { defineConfig } from "vite";
|
|
21
|
+
import react from "@vitejs/plugin-react";
|
|
22
|
+
import { KOLMO_SINGLETON_DEDUPE } from "@pinkaphant/kolmo/vite";
|
|
23
|
+
|
|
24
|
+
export default defineConfig({
|
|
25
|
+
plugins: [react()],
|
|
26
|
+
resolve: { dedupe: KOLMO_SINGLETON_DEDUPE },
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start (R2 Vault + `@khr3/roads` + `<Terrain>` + `<Vehicle>` + `<Actor>`)
|
|
11
31
|
|
|
12
32
|
```tsx
|
|
13
|
-
import { useRef } from "react";
|
|
14
|
-
import {
|
|
33
|
+
import { useMemo, useRef } from "react";
|
|
34
|
+
import {
|
|
35
|
+
Game,
|
|
36
|
+
Terrain,
|
|
37
|
+
Water,
|
|
38
|
+
Actor,
|
|
39
|
+
Vehicle,
|
|
40
|
+
Prop,
|
|
41
|
+
Toolgun,
|
|
42
|
+
Hud,
|
|
43
|
+
type EcctrlHandle,
|
|
44
|
+
} from "@pinkaphant/kolmo";
|
|
45
|
+
import { growRoad, makeTerrain, sampleRapierHeightfield, frontage } from "@khr3/roads";
|
|
15
46
|
|
|
16
|
-
|
|
47
|
+
const VAULT = "https://khr3.optimuspi.workers.dev/assets";
|
|
48
|
+
|
|
49
|
+
export default function App() {
|
|
17
50
|
const actorRef = useRef<EcctrlHandle>(null);
|
|
18
51
|
|
|
52
|
+
const { heights, startPos, lotPos } = useMemo(() => {
|
|
53
|
+
const road = growRoad(42, {
|
|
54
|
+
length: 600,
|
|
55
|
+
halfWidth: 4.5,
|
|
56
|
+
controlSpacing: 35,
|
|
57
|
+
maxTurn: 0.28,
|
|
58
|
+
maxGrade: 0.06,
|
|
59
|
+
hilliness: 18,
|
|
60
|
+
start: [0, 0, -140],
|
|
61
|
+
});
|
|
62
|
+
const land = makeTerrain(42, road, {
|
|
63
|
+
amplitude: 12,
|
|
64
|
+
noise: { wavelength: 140, octaves: 4, gain: 0.5, lacunarity: 2 },
|
|
65
|
+
maxSlope: 0.55,
|
|
66
|
+
minShoulder: 6,
|
|
67
|
+
verge: 2,
|
|
68
|
+
});
|
|
69
|
+
const heights = sampleRapierHeightfield(land, [-160, 0, -160], 320, 128);
|
|
70
|
+
const s0 = road.at(25).pos;
|
|
71
|
+
const lot = frontage(road, { spacing: 24, setback: 3 })[0];
|
|
72
|
+
return {
|
|
73
|
+
heights,
|
|
74
|
+
startPos: [s0[0], s0[1] + 1.5, s0[2]] as [number, number, number],
|
|
75
|
+
lotPos: lot ? ([lot.front[0], lot.groundY, lot.front[2]] as [number, number, number]) : ([10, 0, 20] as [number, number, number]),
|
|
76
|
+
};
|
|
77
|
+
}, []);
|
|
78
|
+
|
|
19
79
|
return (
|
|
20
|
-
<Game skybox="day">
|
|
21
|
-
<
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
<
|
|
80
|
+
<Game skybox="day" debug={false}>
|
|
81
|
+
<Terrain heights={heights} segments={128} size={[320, 320]} />
|
|
82
|
+
<Water levelY={-3.5} size={[120, 120]} />
|
|
83
|
+
|
|
84
|
+
<Vehicle id="r34" src={`${VAULT}/cars/nissan_skyline_r34.glb`} position={startPos} />
|
|
85
|
+
<Vehicle id="arwing" src={`${VAULT}/cars/starfox_rocket.glb`} position={[startPos[0] + 5, startPos[1] + 0.5, startPos[2]]} />
|
|
86
|
+
<Prop src={`${VAULT}/city/door_hinged_single_900x2100.glb`} position={lotPos} fixed />
|
|
87
|
+
|
|
88
|
+
<Actor ref={actorRef} position={[startPos[0] - 3.2, startPos[1] + 0.8, startPos[2]]} />
|
|
89
|
+
<Toolgun
|
|
90
|
+
actorRef={actorRef}
|
|
91
|
+
defaultArmedAsset={{ id: "supra", name: "Supra A80", src: `${VAULT}/cars/toyota_supra_a80.glb`, kind: "vehicle" }}
|
|
92
|
+
/>
|
|
25
93
|
<Hud />
|
|
26
94
|
</Game>
|
|
27
95
|
);
|
|
28
96
|
}
|
|
29
97
|
```
|
|
98
|
+
|
|
99
|
+
## Subpath Entrypoints
|
|
100
|
+
|
|
101
|
+
- `@pinkaphant/kolmo` — `Game`, `Canvas`, `World`, `Physics`, `Hud`, `Actor`, `Vehicle`, `Prop`, `Surface`, `Terrain`, `Water`, `Toolgun`, plus Koota, `@pinkaphant/ecctrl`, `@khr3/core`, and `@khr3/c12` re-exports
|
|
102
|
+
- `@pinkaphant/kolmo/terrain` — `KolmoTerrain`, `KolmoTerrainField`, `createRollingBasinHeightFn`, `exportTerrainKhrGlb`
|
|
103
|
+
- `@pinkaphant/kolmo/water` — `KolmoWater`, `KolmoWaterField`, `stepWaterHydrodynamics`, `sphericalCapVolume`
|
|
104
|
+
- `@pinkaphant/kolmo/physics` — `KolmoPhysics`, `evaluateNBodyGravity`, `createNBodyGravityField`, `computeCircularOrbitSpeed`
|
|
105
|
+
- `@pinkaphant/kolmo/replay` — `FixedStepAccumulator`, `InputTapeRecorder`, `InputTapePlayer`, `KootaTrajectoryTape`
|
|
106
|
+
- `@pinkaphant/kolmo/toolgun` — `KolmoToolgun`, `useToolgunStore`, `DEFAULT_VAULT_C12_URLS`, `castToolgunRay`, `createWeldImpulseJoint`, `createHingeImpulseJoint`
|
|
107
|
+
- `@pinkaphant/kolmo/vite` — `KOLMO_SINGLETON_DEDUPE`
|
package/dist/engine/actor.d.ts
CHANGED
|
@@ -10,4 +10,4 @@ export interface KolmoActorProps extends Omit<EcctrlProps, "ref"> {
|
|
|
10
10
|
readonly getInput?: KolmoInputGetter;
|
|
11
11
|
readonly bundle?: KhrAssetBundle | null;
|
|
12
12
|
}
|
|
13
|
-
export declare function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable, enableCustomGravity, position, rotation, userData, children, ...ecctrlRest }: KolmoActorProps): React.JSX.Element | null;
|
|
13
|
+
export declare function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable, enableToggleRun, enableCustomGravity, position, rotation, userData, children, ...ecctrlRest }: KolmoActorProps): React.JSX.Element | null;
|
package/dist/engine/index.d.ts
CHANGED
package/dist/engine/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
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-
|
|
3
|
-
import { useCallback, useContext, useLayoutEffect, useMemo, useRef } from "react";
|
|
1
|
+
import { C as writeEntityKinematics, S as vehicleSimQuery, _ as kolmoWorld, a as PilotedTag, b as useActiveKolmoWorld, c as VehicleTelemetryTrait, d as WorldSessionTrait, f as createEmptyVehicleCmd, g as kolmoActions, h as getLiveActorBody, 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, y as propSimQuery } from "../traits-Dp1ey_4w.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-BDhBihjW.js";
|
|
3
|
+
import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
4
4
|
import * as THREE from "three";
|
|
5
5
|
import { clone } from "three/examples/jsm/utils/SkeletonUtils.js";
|
|
6
6
|
import { useFrame, useThree } from "@react-three/fiber";
|
|
@@ -9,10 +9,14 @@ 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
|
+
import { a as computeCircularOrbitSpeed, c as evaluatePreparedNBodyGravity, i as G_SI, l as prepareAttractors, n as KolmoPhysics, o as createNBodyGravityField, r as useIsKolmoCustomGravity, s as evaluateNBodyGravity, t as KolmoGravityContext, u as resolveAttractorMu } from "../physics-KYWAXctg.js";
|
|
12
13
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
13
14
|
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
14
15
|
import { KTX2Loader } from "three/examples/jsm/loaders/KTX2Loader.js";
|
|
15
16
|
import { MeshoptDecoder } from "three/examples/jsm/libs/meshopt_decoder.module.js";
|
|
17
|
+
import { KolmoTerrain, KolmoTerrainField, createRollingBasinHeightFn, exportTerrainKhrGlb } from "../terrain/index.js";
|
|
18
|
+
import { KolmoWater, KolmoWaterField, sphericalCapVolume, stepWaterHydrodynamics } from "../water/index.js";
|
|
19
|
+
import { FixedStepAccumulator, InputTapePlayer, InputTapeRecorder, KootaTrajectoryTape } from "../replay/index.js";
|
|
16
20
|
// src/engine/actor.tsx
|
|
17
21
|
var _seatVec = new THREE.Vector3();
|
|
18
22
|
var _camFwd = new THREE.Vector3();
|
|
@@ -34,7 +38,7 @@ function findNearestInteractableVehicleId(world, actorPos) {
|
|
|
34
38
|
}
|
|
35
39
|
return nearestId;
|
|
36
40
|
}
|
|
37
|
-
function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = true, enableCustomGravity, position = [
|
|
41
|
+
function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = true, enableToggleRun = false, enableCustomGravity, position = [
|
|
38
42
|
0,
|
|
39
43
|
1.4,
|
|
40
44
|
0
|
|
@@ -72,26 +76,26 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
72
76
|
run: false,
|
|
73
77
|
jump: false
|
|
74
78
|
});
|
|
75
|
-
const applyPendingExit = useCallback((handle) => {
|
|
79
|
+
const applyPendingExit = useCallback((handle, liveBody) => {
|
|
76
80
|
const ent = actorEntRef.current;
|
|
77
|
-
if (!
|
|
81
|
+
if (!ent?.isAlive()) return;
|
|
78
82
|
const d = ent.get(ActorTrait);
|
|
79
83
|
if (!d?.exitSpawnPos) return;
|
|
80
84
|
const [ex, ey, ez] = d.exitSpawnPos;
|
|
81
85
|
_exitQuat.setFromAxisAngle(_worldUp, d.exitSpawnYaw);
|
|
82
|
-
|
|
86
|
+
liveBody.setTranslation({
|
|
83
87
|
x: ex,
|
|
84
88
|
y: ey,
|
|
85
89
|
z: ez
|
|
86
90
|
}, true);
|
|
87
|
-
|
|
91
|
+
liveBody.setRotation({
|
|
88
92
|
x: _exitQuat.x,
|
|
89
93
|
y: _exitQuat.y,
|
|
90
94
|
z: _exitQuat.z,
|
|
91
95
|
w: _exitQuat.w
|
|
92
96
|
}, true);
|
|
93
97
|
const lv = d.exitLinVel;
|
|
94
|
-
|
|
98
|
+
liveBody.setLinvel(lv ? {
|
|
95
99
|
x: lv[0],
|
|
96
100
|
y: lv[1],
|
|
97
101
|
z: lv[2]
|
|
@@ -100,7 +104,7 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
100
104
|
y: 0,
|
|
101
105
|
z: 0
|
|
102
106
|
}, true);
|
|
103
|
-
|
|
107
|
+
liveBody.setAngvel({
|
|
104
108
|
x: 0,
|
|
105
109
|
y: 0,
|
|
106
110
|
z: 0
|
|
@@ -127,23 +131,16 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
127
131
|
if (prePiloted) ent.add(PilotLink(prePiloted));
|
|
128
132
|
return () => {
|
|
129
133
|
actorEntRef.current = null;
|
|
130
|
-
ent.destroy();
|
|
134
|
+
if (ent.isAlive()) ent.destroy();
|
|
131
135
|
};
|
|
132
136
|
}, [activeWorld]);
|
|
133
137
|
const onFoot = enable && !pilotedVehEnt;
|
|
134
138
|
useLayoutEffect(() => {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
camSyncedRef.current = false;
|
|
138
|
-
body?.setEnabled(false);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
body?.setEnabled(true);
|
|
142
|
-
applyPendingExit(ecctrlRef.current);
|
|
143
|
-
}, [onFoot, applyPendingExit]);
|
|
139
|
+
if (!onFoot) camSyncedRef.current = false;
|
|
140
|
+
}, [onFoot]);
|
|
144
141
|
useLayoutEffect(() => {
|
|
145
142
|
const ent = actorEntRef.current;
|
|
146
|
-
if (ent && pilotedVehEnt && !ent.has(PilotLink(pilotedVehEnt))) ent.add(PilotLink(pilotedVehEnt));
|
|
143
|
+
if (ent?.isAlive() && pilotedVehEnt && !ent.has(PilotLink(pilotedVehEnt))) ent.add(PilotLink(pilotedVehEnt));
|
|
147
144
|
}, [pilotedVehEnt]);
|
|
148
145
|
const assignEcctrlRef = useCallback((handle) => {
|
|
149
146
|
ecctrlRef.current = handle;
|
|
@@ -151,8 +148,6 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
151
148
|
const ent = actorEntRef.current;
|
|
152
149
|
if (!ent?.isAlive()) return;
|
|
153
150
|
const cur = ent.get(ActorTrait);
|
|
154
|
-
const isFoot = enable && !activeWorld.queryFirst(pilotedVehicleQuery);
|
|
155
|
-
handle?.body?.setEnabled(isFoot);
|
|
156
151
|
ent.set(ActorTrait, {
|
|
157
152
|
id: cur?.id ?? "pilot",
|
|
158
153
|
handle,
|
|
@@ -160,13 +155,7 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
160
155
|
exitSpawnYaw: cur?.exitSpawnYaw ?? 0,
|
|
161
156
|
exitLinVel: cur?.exitLinVel ?? null
|
|
162
157
|
});
|
|
163
|
-
|
|
164
|
-
}, [
|
|
165
|
-
ref,
|
|
166
|
-
enable,
|
|
167
|
-
activeWorld,
|
|
168
|
-
applyPendingExit
|
|
169
|
-
]);
|
|
158
|
+
}, [ref]);
|
|
170
159
|
const assignCamRef = useCallback((ctrl) => {
|
|
171
160
|
camCtrlRef.current = ctrl;
|
|
172
161
|
assignRef(cameraRef, ctrl);
|
|
@@ -183,22 +172,42 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
183
172
|
};
|
|
184
173
|
}, [userData]);
|
|
185
174
|
const clonedScene = useMemo(() => bundle ? clone(bundle.scene) : null, [bundle]);
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
const handle = ecctrlRef.current;
|
|
177
|
+
const liveBody = getLiveActorBody(rapierWorld, handle);
|
|
178
|
+
if (!handle || !liveBody) return;
|
|
179
|
+
if (onFoot) {
|
|
180
|
+
if (!liveBody.isEnabled()) liveBody.setEnabled(true);
|
|
181
|
+
applyPendingExit(handle, liveBody);
|
|
182
|
+
} else if (liveBody.isEnabled()) liveBody.setEnabled(false);
|
|
183
|
+
}, [
|
|
184
|
+
rapierWorld,
|
|
185
|
+
onFoot,
|
|
186
|
+
applyPendingExit
|
|
187
|
+
]);
|
|
186
188
|
useFrame((state, delta) => {
|
|
187
|
-
|
|
189
|
+
const handle = ecctrlRef.current;
|
|
190
|
+
const liveBody = getLiveActorBody(rapierWorld, handle);
|
|
191
|
+
if (!enable) {
|
|
192
|
+
if (liveBody && liveBody.isEnabled()) liveBody.setEnabled(false);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
188
195
|
const dt = rapierWorld.timestep > 0 ? rapierWorld.timestep : Math.min(Math.max(delta, 1e-4), 1 / 30);
|
|
189
196
|
if (cooldownRef.current > 0) cooldownRef.current = Math.max(0, cooldownRef.current - dt);
|
|
190
197
|
const inp = readInput();
|
|
191
198
|
const interactEdge = inp.interact && !prevInteractRef.current;
|
|
192
199
|
prevInteractRef.current = inp.interact;
|
|
193
200
|
if (activeWorld.queryFirst(pilotedVehicleQuery)) {
|
|
201
|
+
if (liveBody && liveBody.isEnabled()) liveBody.setEnabled(false);
|
|
194
202
|
if (interactEdge && cooldownRef.current === 0) {
|
|
195
203
|
cooldownRef.current = .25;
|
|
196
204
|
kolmoActions(activeWorld).exitVehicle();
|
|
197
205
|
}
|
|
198
206
|
return;
|
|
199
207
|
}
|
|
200
|
-
|
|
201
|
-
if (!
|
|
208
|
+
if (!handle || !liveBody) return;
|
|
209
|
+
if (!liveBody.isEnabled()) liveBody.setEnabled(true);
|
|
210
|
+
applyPendingExit(handle, liveBody);
|
|
202
211
|
stickRef.current.x = inp.stickX;
|
|
203
212
|
stickRef.current.y = inp.stickY;
|
|
204
213
|
const cmd = moveCmdRef.current;
|
|
@@ -256,6 +265,7 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
256
265
|
children: /* @__PURE__ */ jsx(Ecctrl, {
|
|
257
266
|
ref: assignEcctrlRef,
|
|
258
267
|
enable: onFoot,
|
|
268
|
+
enableToggleRun,
|
|
259
269
|
enableCustomGravity: effCustomGravity,
|
|
260
270
|
position,
|
|
261
271
|
...rotation === void 0 ? {} : { rotation },
|
|
@@ -305,6 +315,6 @@ async function loadKolmoGlbUrl(url, options) {
|
|
|
305
315
|
if (!res.ok) throw new Error(`Failed to fetch GLB (${res.status}): ${url}`);
|
|
306
316
|
return parseKolmoGlbBuffer(await res.arrayBuffer(), options);
|
|
307
317
|
}
|
|
308
|
-
export { ActorTrait, EMPTY_KOLMO_INPUT, G_SI, InteractableTrait, KOLMO_KEY_MAP, KOLMO_STICK_DEADZONE, KolmoActor, KolmoCanvas, KolmoGame, KolmoGravityContext, KolmoHud, KolmoInCanvasContext, KolmoKeyboardBridge, KolmoKeyboardContext, KolmoOverlayPortalContext, KolmoPhysics, KolmoProp, KolmoSurface, KolmoVehicle, KolmoWorld, KolmoWorldContext, PilotLink, PilotedTag, RoomEnvRig, TransformTrait, VehicleTelemetryTrait, VehicleTrait, VelocityTrait, WorldSessionTrait, computeCircularOrbitSpeed, createEmptyVehicleCmd, createKolmoGltfLoader, createNBodyGravityField, ensureWorldSession, evaluateNBodyGravity, evaluatePreparedNBodyGravity, flipVehicleBodyUpright, kolmoActions, kolmoWorld, loadKolmoGlbUrl, parseKolmoGlbBuffer, pilotedVehicleQuery, prepareAttractors, resolveAttractorMu, useActiveKolmoWorld, useIsKolmoCustomGravity, useKolmoGame, useKolmoInput, useOptionalKootaWorld, vehicleSimQuery, writeEntityKinematics, writeVehicleTelemetry };
|
|
318
|
+
export { ActorTrait, EMPTY_KOLMO_INPUT, FixedStepAccumulator, G_SI, InputTapePlayer, InputTapeRecorder, InteractableTrait, KOLMO_KEY_MAP, KOLMO_STICK_DEADZONE, KolmoActor, KolmoCanvas, KolmoGame, KolmoGravityContext, KolmoHud, KolmoInCanvasContext, KolmoKeyboardBridge, KolmoKeyboardContext, KolmoOverlayPortalContext, KolmoPhysics, KolmoProp, KolmoSurface, KolmoTerrain, KolmoTerrainField, KolmoVehicle, KolmoWater, KolmoWaterField, KolmoWorld, KolmoWorldContext, KootaTrajectoryTape, PilotLink, PilotedTag, PropTrait, RoomEnvRig, TransformTrait, VehicleTelemetryTrait, VehicleTrait, VelocityTrait, WorldSessionTrait, computeCircularOrbitSpeed, createEmptyVehicleCmd, createKolmoGltfLoader, createNBodyGravityField, createRollingBasinHeightFn, ensureWorldSession, evaluateNBodyGravity, evaluatePreparedNBodyGravity, exportTerrainKhrGlb, flipVehicleBodyUpright, getLiveActorBody, kolmoActions, kolmoWorld, loadKolmoGlbUrl, parseKolmoGlbBuffer, pilotedVehicleQuery, prepareAttractors, propSimQuery, resolveAttractorMu, sphericalCapVolume, stepWaterHydrodynamics, useActiveKolmoWorld, useIsKolmoCustomGravity, useKolmoGame, useKolmoInput, useOptionalKootaWorld, vehicleSimQuery, writeEntityKinematics, writeVehicleTelemetry };
|
|
309
319
|
|
|
310
320
|
//# sourceMappingURL=index.js.map
|
package/dist/engine/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["cloneSkinned","_jsxs","_Fragment","_jsx"],"sources":["../../src/engine/actor.tsx","../../src/engine/gltfLoader.ts"],"sourcesContent":["import React, { useCallback, useContext, useLayoutEffect, useMemo, useRef, type ComponentProps } from \"react\";\nimport * as THREE from \"three\";\nimport { clone as cloneSkinned } from \"three/examples/jsm/utils/SkeletonUtils.js\";\nimport { useFrame, useThree } from \"@react-three/fiber\";\nimport { useRapier } from \"@react-three/rapier\";\nimport { useQueryFirst } from \"koota/react\";\nimport { Ecctrl, type EcctrlHandle, type EcctrlProps, type MovementInput } from \"@pinkaphant/ecctrl\";\nimport { EcctrlCameraControls, type EcctrlCameraControlsHandle } from \"@pinkaphant/ecctrl/camera\";\nimport { assignRef, type KhrAssetBundle } from \"@khr3/core\";\nimport { KolmoGravityContext } from \"../physics/index.js\";\nimport { useKolmoInput, type KolmoInputGetter } from \"./input.js\";\nimport {\n ActorTrait,\n InteractableTrait,\n PilotLink,\n PilotedTag,\n TransformTrait,\n VehicleTrait,\n VelocityTrait,\n WorldSessionTrait,\n ensureWorldSession,\n kolmoActions,\n pilotedVehicleQuery,\n useActiveKolmoWorld,\n writeEntityKinematics,\n} from \"./traits.js\";\n\nconst _seatVec = new THREE.Vector3();\nconst _camFwd = new THREE.Vector3();\nconst _worldUp = new THREE.Vector3(0, 1, 0);\nconst _exitQuat = new THREE.Quaternion();\n\nfunction findNearestInteractableVehicleId(world: ReturnType<typeof useActiveKolmoWorld>, actorPos: THREE.Vector3): string | null {\n let nearestId: string | null = null;\n let bestDistSq = Infinity;\n for (const ent of world.query(VehicleTrait, InteractableTrait)) {\n const v = ent.get(VehicleTrait);\n const it = ent.get(InteractableTrait);\n if (!v?.handle || !it)\n continue;\n _seatVec.set(v.seatOffset[0], v.seatOffset[1], v.seatOffset[2]).applyQuaternion(v.handle.currQuat).add(v.handle.currPos);\n const dSq = actorPos.distanceToSquared(_seatVec);\n if (dSq <= it.radius * it.radius && dSq < bestDistSq) {\n bestDistSq = dSq;\n nearestId = v.id;\n }\n }\n return nearestId;\n}\n\nexport interface KolmoActorProps extends Omit<EcctrlProps, \"ref\"> {\n readonly ref?: React.Ref<EcctrlHandle>;\n readonly cameraRef?: React.Ref<EcctrlCameraControlsHandle>;\n readonly cameraProps?: Omit<ComponentProps<typeof EcctrlCameraControls>, \"ref\"> | null | false;\n readonly getInput?: KolmoInputGetter;\n readonly bundle?: KhrAssetBundle | null;\n}\n\nexport function KolmoActor({\n ref,\n cameraRef,\n cameraProps,\n getInput,\n bundle,\n enable = true,\n enableCustomGravity,\n position = [0, 1.4, 0],\n rotation,\n userData,\n children,\n ...ecctrlRest\n}: KolmoActorProps): React.JSX.Element | null {\n const ctxCustomGravity = useContext(KolmoGravityContext);\n const effCustomGravity = enableCustomGravity ?? ctxCustomGravity;\n const activeWorld = useActiveKolmoWorld();\n useLayoutEffect(() => {\n ensureWorldSession(activeWorld);\n }, [activeWorld]);\n\n const pilotedVehEnt = useQueryFirst(VehicleTrait, PilotedTag);\n const readInput = useKolmoInput(getInput);\n const domElement = useThree((s) => s.gl?.domElement);\n const hasDom = Boolean(domElement && typeof domElement.addEventListener === \"function\");\n const { world: rapierWorld } = useRapier();\n\n const actorEntRef = useRef<ReturnType<typeof activeWorld.spawn> | null>(null);\n const ecctrlRef = useRef<EcctrlHandle | null>(null);\n const camCtrlRef = useRef<EcctrlCameraControlsHandle | null>(null);\n const followPos = useRef(new THREE.Vector3());\n const followUp = useRef(new THREE.Vector3(0, 1, 0));\n const camSyncedRef = useRef(false);\n const prevInteractRef = useRef(false);\n const prevNearIdRef = useRef(\"\");\n const cooldownRef = useRef(0);\n const stickRef = useRef({ x: 0, y: 0 });\n const moveCmdRef = useRef<MovementInput>({\n forward: false,\n backward: false,\n leftward: false,\n rightward: false,\n joystick: stickRef.current,\n run: false,\n jump: false,\n });\n\n const applyPendingExit = useCallback((handle: EcctrlHandle | null) => {\n const ent = actorEntRef.current;\n if (!handle?.body || !ent?.isAlive())\n return;\n const d = ent.get(ActorTrait);\n if (!d?.exitSpawnPos)\n return;\n const [ex, ey, ez] = d.exitSpawnPos;\n _exitQuat.setFromAxisAngle(_worldUp, d.exitSpawnYaw);\n handle.body.setTranslation({ x: ex, y: ey, z: ez }, true);\n handle.body.setRotation({ x: _exitQuat.x, y: _exitQuat.y, z: _exitQuat.z, w: _exitQuat.w }, true);\n const lv = d.exitLinVel;\n handle.body.setLinvel(lv ? { x: lv[0], y: lv[1], z: lv[2] } : { x: 0, y: 0, z: 0 }, true);\n handle.body.setAngvel({ x: 0, y: 0, z: 0 }, true);\n handle.currPos.set(ex, ey, ez);\n handle.currQuat.copy(_exitQuat);\n ent.set(ActorTrait, { ...d, handle, exitSpawnPos: null, exitLinVel: null });\n }, []);\n\n useLayoutEffect(() => {\n const ent = activeWorld.spawn(\n ActorTrait({ id: \"pilot\", handle: ecctrlRef.current, exitSpawnPos: null, exitSpawnYaw: 0, exitLinVel: null }),\n TransformTrait,\n VelocityTrait,\n );\n actorEntRef.current = ent;\n const prePiloted = activeWorld.queryFirst(pilotedVehicleQuery);\n if (prePiloted)\n ent.add(PilotLink(prePiloted));\n return () => {\n actorEntRef.current = null;\n ent.destroy();\n };\n }, [activeWorld]);\n\n const onFoot = enable && !pilotedVehEnt;\n useLayoutEffect(() => {\n const body = ecctrlRef.current?.body;\n if (!onFoot) {\n camSyncedRef.current = false;\n body?.setEnabled(false);\n return;\n }\n body?.setEnabled(true);\n applyPendingExit(ecctrlRef.current);\n }, [onFoot, applyPendingExit]);\n\n useLayoutEffect(() => {\n const ent = actorEntRef.current;\n if (ent && pilotedVehEnt && !ent.has(PilotLink(pilotedVehEnt)))\n ent.add(PilotLink(pilotedVehEnt));\n }, [pilotedVehEnt]);\n\n const assignEcctrlRef = useCallback((handle: EcctrlHandle | null) => {\n ecctrlRef.current = handle;\n assignRef(ref, handle);\n const ent = actorEntRef.current;\n if (!ent?.isAlive())\n return;\n const cur = ent.get(ActorTrait);\n const isFoot = enable && !activeWorld.queryFirst(pilotedVehicleQuery);\n handle?.body?.setEnabled(isFoot);\n ent.set(ActorTrait, {\n id: cur?.id ?? \"pilot\",\n handle,\n exitSpawnPos: cur?.exitSpawnPos ?? null,\n exitSpawnYaw: cur?.exitSpawnYaw ?? 0,\n exitLinVel: cur?.exitLinVel ?? null,\n });\n if (isFoot)\n applyPendingExit(handle);\n }, [ref, enable, activeWorld, applyPendingExit]);\n\n const assignCamRef = useCallback((ctrl: EcctrlCameraControlsHandle | null) => {\n camCtrlRef.current = ctrl;\n assignRef(cameraRef, ctrl);\n }, [cameraRef]);\n\n const mergedUserData = useMemo(() => {\n const base = (userData ?? {}) as Record<string, unknown>;\n const ecctrlMeta = (base.ecctrl ?? {}) as Record<string, unknown>;\n return { ...base, ecctrl: { excludeVehicleRay: true, ...ecctrlMeta } };\n }, [userData]);\n\n const clonedScene = useMemo(() => (bundle ? cloneSkinned(bundle.scene) : null), [bundle]);\n\n useFrame((state, delta) => {\n if (!enable)\n return;\n const dt = rapierWorld.timestep > 0 ? rapierWorld.timestep : Math.min(Math.max(delta, 1e-4), 1 / 30);\n if (cooldownRef.current > 0)\n cooldownRef.current = Math.max(0, cooldownRef.current - dt);\n\n const inp = readInput();\n const interactEdge = inp.interact && !prevInteractRef.current;\n prevInteractRef.current = inp.interact;\n\n if (activeWorld.queryFirst(pilotedVehicleQuery)) {\n if (interactEdge && cooldownRef.current === 0) {\n cooldownRef.current = 0.25;\n kolmoActions(activeWorld).exitVehicle();\n }\n return;\n }\n\n const handle = ecctrlRef.current;\n if (!handle?.body)\n return;\n\n stickRef.current.x = inp.stickX;\n stickRef.current.y = inp.stickY;\n const cmd = moveCmdRef.current;\n cmd.forward = inp.forward;\n cmd.backward = inp.backward;\n cmd.leftward = inp.left;\n cmd.rightward = inp.right;\n cmd.joystick = stickRef.current;\n cmd.run = inp.boost;\n cmd.jump = inp.brake;\n handle.setMovement(cmd);\n\n if (actorEntRef.current?.isAlive()) {\n writeEntityKinematics(activeWorld, actorEntRef.current, handle.currPos, handle.currQuat, handle.currLinVel, handle.moveSpeed * 3.6);\n }\n\n const nearId = findNearestInteractableVehicleId(activeWorld, handle.currPos) ?? \"\";\n if (nearId !== prevNearIdRef.current) {\n prevNearIdRef.current = nearId;\n activeWorld.set(WorldSessionTrait, { nearVehicleId: nearId });\n }\n\n if (interactEdge && nearId && cooldownRef.current === 0) {\n cooldownRef.current = 0.25;\n kolmoActions(activeWorld).boardVehicle(nearId);\n return;\n }\n\n const cam = camCtrlRef.current;\n if (cam && handle.currPos.lengthSq() > 0) {\n const hasValidUp = handle.upAxis.lengthSq() > 0.25;\n if (hasValidUp)\n followUp.current.copy(handle.upAxis).normalize();\n else\n followUp.current.copy(_worldUp);\n followPos.current.copy(handle.currPos).addScaledVector(followUp.current, 0.55);\n\n if (!camSyncedRef.current) {\n camSyncedRef.current = true;\n state.camera.up.copy(followUp.current);\n cam.setUp(followUp.current);\n _camFwd.copy(handle.bodyZAxis).projectOnPlane(followUp.current);\n if (_camFwd.lengthSq() < 1e-4)\n _camFwd.set(0, 0, -1).projectOnPlane(followUp.current);\n _camFwd.normalize();\n cam.setLookAt(\n followPos.current.x - _camFwd.x * 7.5 + followUp.current.x * 2.4,\n followPos.current.y - _camFwd.y * 7.5 + followUp.current.y * 2.4,\n followPos.current.z - _camFwd.z * 7.5 + followUp.current.z * 2.4,\n followPos.current.x,\n followPos.current.y,\n followPos.current.z,\n false,\n );\n }\n else {\n cam.moveTo(followPos.current.x, followPos.current.y, followPos.current.z, true);\n if (effCustomGravity && state.camera.up.distanceToSquared(followUp.current) > 1e-6) {\n state.camera.up.lerp(followUp.current, 1 - Math.exp(-8 * dt)).normalize();\n cam.setUp(state.camera.up);\n }\n }\n }\n });\n\n return (\n <>\n {hasDom && cameraProps !== false && cameraProps !== null && (\n <EcctrlCameraControls\n ref={assignCamRef}\n makeDefault\n enabled={onFoot}\n minPolarAngle={0.12}\n maxPolarAngle={Math.PI - 0.12}\n smoothTime={0.08}\n {...(cameraProps ?? {})}\n />\n )}\n <group visible={onFoot}>\n <Ecctrl\n ref={assignEcctrlRef}\n enable={onFoot}\n enableCustomGravity={effCustomGravity}\n position={position}\n {...(rotation === undefined ? {} : { rotation })}\n userData={mergedUserData}\n {...ecctrlRest}\n >\n {children ?? (clonedScene ? <primitive object={clonedScene} /> : null)}\n </Ecctrl>\n </group>\n </>\n );\n}\n","import type * as THREE from \"three\";\nimport { GLTFLoader } from \"three/examples/jsm/loaders/GLTFLoader.js\";\nimport { KTX2Loader } from \"three/examples/jsm/loaders/KTX2Loader.js\";\nimport { MeshoptDecoder } from \"three/examples/jsm/libs/meshopt_decoder.module.js\";\nimport { loadKhrGlb, type KhrAssetBundle, type KhrPluginOptions } from \"@khr3/core\";\n\nexport interface KolmoGltfLoaderOptions {\n /** Optional WebGLRenderer so KTX2 (`KHR_texture_basisu`) detects hardware ASTC/BC7/ETC2 support. */\n readonly renderer?: THREE.WebGLRenderer | null;\n /** Optional path hosting Basis Universal transcoder `.js`/`.wasm` files (defaults to `\"/basis/\"`). */\n readonly basisTranscoderPath?: string;\n /** Optional `@khr3/core` plugin options. */\n readonly khrOptions?: KhrPluginOptions;\n}\n\nconst ktx2ByRenderer = new WeakMap<THREE.WebGLRenderer, Map<string, KTX2Loader>>();\n\nfunction getScopedKtx2Loader(renderer: THREE.WebGLRenderer, transcoderPath: string): KTX2Loader {\n let byPath = ktx2ByRenderer.get(renderer);\n if (!byPath) {\n byPath = new Map();\n ktx2ByRenderer.set(renderer, byPath);\n }\n let ktx2 = byPath.get(transcoderPath);\n if (!ktx2) {\n ktx2 = new KTX2Loader();\n ktx2.setTranscoderPath(transcoderPath);\n ktx2.detectSupport(renderer);\n byPath.set(transcoderPath, ktx2);\n }\n return ktx2;\n}\n\n/**\n * Khronos-compliant `GLTFLoader` configured with `EXT_meshopt_compression` (`MeshoptDecoder`)\n * and `KHR_texture_basisu` (`KTX2Loader` when a renderer is supplied).\n */\nexport function createKolmoGltfLoader(options?: KolmoGltfLoaderOptions): GLTFLoader {\n const loader = new GLTFLoader();\n loader.setMeshoptDecoder(MeshoptDecoder);\n if (options?.renderer) {\n loader.setKTX2Loader(getScopedKtx2Loader(options.renderer, options.basisTranscoderPath ?? \"/basis/\"));\n }\n return loader;\n}\n\nexport async function parseKolmoGlbBuffer(\n buffer: ArrayBuffer | Uint8Array,\n options?: KolmoGltfLoaderOptions,\n): Promise<KhrAssetBundle> {\n await MeshoptDecoder.ready;\n const loader = createKolmoGltfLoader(options);\n return loadKhrGlb(buffer, { ...options?.khrOptions, loader });\n}\n\nexport async function loadKolmoGlbUrl(\n url: string,\n options?: KolmoGltfLoaderOptions,\n): Promise<KhrAssetBundle> {\n const res = await fetch(url);\n if (!res.ok)\n throw new Error(`Failed to fetch GLB (${res.status}): ${url}`);\n return parseKolmoGlbBuffer(await res.arrayBuffer(), options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA2BA,IAAM,WAAW,IAAI,MAAM,QAAQ;AACnC,IAAM,UAAU,IAAI,MAAM,QAAQ;AAClC,IAAM,WAAW,IAAI,MAAM,QAAQ,GAAG,GAAG,CAAC;AAC1C,IAAM,YAAY,IAAI,MAAM,WAAW;AAEvC,SAAS,iCAAiC,OAA+C,UAAwC;CAC7H,IAAI,YAA2B;CAC/B,IAAI,aAAa;CACjB,KAAK,MAAM,OAAO,MAAM,MAAM,cAAc,iBAAiB,GAAG;EAC5D,MAAM,IAAI,IAAI,IAAI,YAAY;EAC9B,MAAM,KAAK,IAAI,IAAI,iBAAiB;EACpC,IAAI,CAAC,GAAG,UAAU,CAAC,IACf;EACJ,SAAS,IAAI,EAAE,WAAW,IAAI,EAAE,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,gBAAgB,EAAE,OAAO,QAAQ,CAAC,CAAC,IAAI,EAAE,OAAO,OAAO;EACvH,MAAM,MAAM,SAAS,kBAAkB,QAAQ;EAC/C,IAAI,OAAO,GAAG,SAAS,GAAG,UAAU,MAAM,YAAY;GAClD,aAAa;GACb,YAAY,EAAE;EAClB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"file":"index.js","names":["cloneSkinned","_jsxs","_Fragment","_jsx"],"sources":["../../src/engine/actor.tsx","../../src/engine/gltfLoader.ts"],"sourcesContent":["import React, { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, type ComponentProps } from \"react\";\nimport * as THREE from \"three\";\nimport { clone as cloneSkinned } from \"three/examples/jsm/utils/SkeletonUtils.js\";\nimport { useFrame, useThree } from \"@react-three/fiber\";\nimport { useRapier } from \"@react-three/rapier\";\nimport type RAPIER from \"@dimforge/rapier3d-compat\";\nimport { useQueryFirst } from \"koota/react\";\nimport { Ecctrl, type EcctrlHandle, type EcctrlProps, type MovementInput } from \"@pinkaphant/ecctrl\";\nimport { EcctrlCameraControls, type EcctrlCameraControlsHandle } from \"@pinkaphant/ecctrl/camera\";\nimport { assignRef, type KhrAssetBundle } from \"@khr3/core\";\nimport { KolmoGravityContext } from \"../physics/index.js\";\nimport { useKolmoInput, type KolmoInputGetter } from \"./input.js\";\nimport {\n ActorTrait,\n InteractableTrait,\n PilotLink,\n PilotedTag,\n TransformTrait,\n VehicleTrait,\n VelocityTrait,\n WorldSessionTrait,\n ensureWorldSession,\n getLiveActorBody,\n kolmoActions,\n pilotedVehicleQuery,\n useActiveKolmoWorld,\n writeEntityKinematics,\n} from \"./traits.js\";\n\nconst _seatVec = new THREE.Vector3();\nconst _camFwd = new THREE.Vector3();\nconst _worldUp = new THREE.Vector3(0, 1, 0);\nconst _exitQuat = new THREE.Quaternion();\n\nfunction findNearestInteractableVehicleId(world: ReturnType<typeof useActiveKolmoWorld>, actorPos: THREE.Vector3): string | null {\n let nearestId: string | null = null;\n let bestDistSq = Infinity;\n for (const ent of world.query(VehicleTrait, InteractableTrait)) {\n const v = ent.get(VehicleTrait);\n const it = ent.get(InteractableTrait);\n if (!v?.handle || !it)\n continue;\n _seatVec.set(v.seatOffset[0], v.seatOffset[1], v.seatOffset[2]).applyQuaternion(v.handle.currQuat).add(v.handle.currPos);\n const dSq = actorPos.distanceToSquared(_seatVec);\n if (dSq <= it.radius * it.radius && dSq < bestDistSq) {\n bestDistSq = dSq;\n nearestId = v.id;\n }\n }\n return nearestId;\n}\n\nexport interface KolmoActorProps extends Omit<EcctrlProps, \"ref\"> {\n readonly ref?: React.Ref<EcctrlHandle>;\n readonly cameraRef?: React.Ref<EcctrlCameraControlsHandle>;\n readonly cameraProps?: Omit<ComponentProps<typeof EcctrlCameraControls>, \"ref\"> | null | false;\n readonly getInput?: KolmoInputGetter;\n readonly bundle?: KhrAssetBundle | null;\n}\n\nexport function KolmoActor({\n ref,\n cameraRef,\n cameraProps,\n getInput,\n bundle,\n enable = true,\n enableToggleRun = false,\n enableCustomGravity,\n position = [0, 1.4, 0],\n rotation,\n userData,\n children,\n ...ecctrlRest\n}: KolmoActorProps): React.JSX.Element | null {\n const ctxCustomGravity = useContext(KolmoGravityContext);\n const effCustomGravity = enableCustomGravity ?? ctxCustomGravity;\n const activeWorld = useActiveKolmoWorld();\n useLayoutEffect(() => {\n ensureWorldSession(activeWorld);\n }, [activeWorld]);\n\n const pilotedVehEnt = useQueryFirst(VehicleTrait, PilotedTag);\n const readInput = useKolmoInput(getInput);\n const domElement = useThree((s) => s.gl?.domElement);\n const hasDom = Boolean(domElement && typeof domElement.addEventListener === \"function\");\n const { world: rapierWorld } = useRapier();\n\n const actorEntRef = useRef<ReturnType<typeof activeWorld.spawn> | null>(null);\n const ecctrlRef = useRef<EcctrlHandle | null>(null);\n const camCtrlRef = useRef<EcctrlCameraControlsHandle | null>(null);\n const followPos = useRef(new THREE.Vector3());\n const followUp = useRef(new THREE.Vector3(0, 1, 0));\n const camSyncedRef = useRef(false);\n const prevInteractRef = useRef(false);\n const prevNearIdRef = useRef(\"\");\n const cooldownRef = useRef(0);\n const stickRef = useRef({ x: 0, y: 0 });\n const moveCmdRef = useRef<MovementInput>({\n forward: false,\n backward: false,\n leftward: false,\n rightward: false,\n joystick: stickRef.current,\n run: false,\n jump: false,\n });\n\n const applyPendingExit = useCallback((handle: EcctrlHandle, liveBody: RAPIER.RigidBody) => {\n const ent = actorEntRef.current;\n if (!ent?.isAlive())\n return;\n const d = ent.get(ActorTrait);\n if (!d?.exitSpawnPos)\n return;\n const [ex, ey, ez] = d.exitSpawnPos;\n _exitQuat.setFromAxisAngle(_worldUp, d.exitSpawnYaw);\n liveBody.setTranslation({ x: ex, y: ey, z: ez }, true);\n liveBody.setRotation({ x: _exitQuat.x, y: _exitQuat.y, z: _exitQuat.z, w: _exitQuat.w }, true);\n const lv = d.exitLinVel;\n liveBody.setLinvel(lv ? { x: lv[0], y: lv[1], z: lv[2] } : { x: 0, y: 0, z: 0 }, true);\n liveBody.setAngvel({ x: 0, y: 0, z: 0 }, true);\n handle.currPos.set(ex, ey, ez);\n handle.currQuat.copy(_exitQuat);\n ent.set(ActorTrait, { ...d, handle, exitSpawnPos: null, exitLinVel: null });\n }, []);\n\n useLayoutEffect(() => {\n const ent = activeWorld.spawn(\n ActorTrait({ id: \"pilot\", handle: ecctrlRef.current, exitSpawnPos: null, exitSpawnYaw: 0, exitLinVel: null }),\n TransformTrait,\n VelocityTrait,\n );\n actorEntRef.current = ent;\n const prePiloted = activeWorld.queryFirst(pilotedVehicleQuery);\n if (prePiloted)\n ent.add(PilotLink(prePiloted));\n return () => {\n actorEntRef.current = null;\n if (ent.isAlive())\n ent.destroy();\n };\n }, [activeWorld]);\n\n const onFoot = enable && !pilotedVehEnt;\n useLayoutEffect(() => {\n if (!onFoot) {\n camSyncedRef.current = false;\n }\n }, [onFoot]);\n\n useLayoutEffect(() => {\n const ent = actorEntRef.current;\n if (ent?.isAlive() && pilotedVehEnt && !ent.has(PilotLink(pilotedVehEnt)))\n ent.add(PilotLink(pilotedVehEnt));\n }, [pilotedVehEnt]);\n\n // Never touch Rapier WASM pointers inside ref callbacks (prevents React 19 StrictMode freed-body Rust panics)\n const assignEcctrlRef = useCallback((handle: EcctrlHandle | null) => {\n ecctrlRef.current = handle;\n assignRef(ref, handle);\n const ent = actorEntRef.current;\n if (!ent?.isAlive())\n return;\n const cur = ent.get(ActorTrait);\n ent.set(ActorTrait, {\n id: cur?.id ?? \"pilot\",\n handle,\n exitSpawnPos: cur?.exitSpawnPos ?? null,\n exitSpawnYaw: cur?.exitSpawnYaw ?? 0,\n exitLinVel: cur?.exitLinVel ?? null,\n });\n }, [ref]);\n\n const assignCamRef = useCallback((ctrl: EcctrlCameraControlsHandle | null) => {\n camCtrlRef.current = ctrl;\n assignRef(cameraRef, ctrl);\n }, [cameraRef]);\n\n const mergedUserData = useMemo(() => {\n const base = (userData ?? {}) as Record<string, unknown>;\n const ecctrlMeta = (base.ecctrl ?? {}) as Record<string, unknown>;\n return { ...base, ecctrl: { excludeVehicleRay: true, ...ecctrlMeta } };\n }, [userData]);\n\n const clonedScene = useMemo(() => (bundle ? cloneSkinned(bundle.scene) : null), [bundle]);\n\n useEffect(() => {\n const handle = ecctrlRef.current;\n const liveBody = getLiveActorBody(rapierWorld, handle);\n if (!handle || !liveBody)\n return;\n if (onFoot) {\n if (!liveBody.isEnabled())\n liveBody.setEnabled(true);\n applyPendingExit(handle, liveBody);\n }\n else if (liveBody.isEnabled()) {\n liveBody.setEnabled(false);\n }\n }, [rapierWorld, onFoot, applyPendingExit]);\n\n useFrame((state, delta) => {\n const handle = ecctrlRef.current;\n const liveBody = getLiveActorBody(rapierWorld, handle);\n\n if (!enable) {\n if (liveBody && liveBody.isEnabled())\n liveBody.setEnabled(false);\n return;\n }\n\n const dt = rapierWorld.timestep > 0 ? rapierWorld.timestep : Math.min(Math.max(delta, 1e-4), 1 / 30);\n if (cooldownRef.current > 0)\n cooldownRef.current = Math.max(0, cooldownRef.current - dt);\n\n const inp = readInput();\n const interactEdge = inp.interact && !prevInteractRef.current;\n prevInteractRef.current = inp.interact;\n\n if (activeWorld.queryFirst(pilotedVehicleQuery)) {\n if (liveBody && liveBody.isEnabled())\n liveBody.setEnabled(false);\n if (interactEdge && cooldownRef.current === 0) {\n cooldownRef.current = 0.25;\n kolmoActions(activeWorld).exitVehicle();\n }\n return;\n }\n\n if (!handle || !liveBody)\n return;\n\n if (!liveBody.isEnabled())\n liveBody.setEnabled(true);\n applyPendingExit(handle, liveBody);\n\n stickRef.current.x = inp.stickX;\n stickRef.current.y = inp.stickY;\n const cmd = moveCmdRef.current;\n cmd.forward = inp.forward;\n cmd.backward = inp.backward;\n cmd.leftward = inp.left;\n cmd.rightward = inp.right;\n cmd.joystick = stickRef.current;\n cmd.run = inp.boost;\n cmd.jump = inp.brake;\n handle.setMovement(cmd);\n\n if (actorEntRef.current?.isAlive()) {\n writeEntityKinematics(activeWorld, actorEntRef.current, handle.currPos, handle.currQuat, handle.currLinVel, handle.moveSpeed * 3.6);\n }\n\n const nearId = findNearestInteractableVehicleId(activeWorld, handle.currPos) ?? \"\";\n if (nearId !== prevNearIdRef.current) {\n prevNearIdRef.current = nearId;\n activeWorld.set(WorldSessionTrait, { nearVehicleId: nearId });\n }\n\n if (interactEdge && nearId && cooldownRef.current === 0) {\n cooldownRef.current = 0.25;\n kolmoActions(activeWorld).boardVehicle(nearId);\n return;\n }\n\n const cam = camCtrlRef.current;\n if (cam && handle.currPos.lengthSq() > 0) {\n const hasValidUp = handle.upAxis.lengthSq() > 0.25;\n if (hasValidUp)\n followUp.current.copy(handle.upAxis).normalize();\n else\n followUp.current.copy(_worldUp);\n followPos.current.copy(handle.currPos).addScaledVector(followUp.current, 0.55);\n\n if (!camSyncedRef.current) {\n camSyncedRef.current = true;\n state.camera.up.copy(followUp.current);\n cam.setUp(followUp.current);\n _camFwd.copy(handle.bodyZAxis).projectOnPlane(followUp.current);\n if (_camFwd.lengthSq() < 1e-4)\n _camFwd.set(0, 0, -1).projectOnPlane(followUp.current);\n _camFwd.normalize();\n cam.setLookAt(\n followPos.current.x - _camFwd.x * 7.5 + followUp.current.x * 2.4,\n followPos.current.y - _camFwd.y * 7.5 + followUp.current.y * 2.4,\n followPos.current.z - _camFwd.z * 7.5 + followUp.current.z * 2.4,\n followPos.current.x,\n followPos.current.y,\n followPos.current.z,\n false,\n );\n }\n else {\n cam.moveTo(followPos.current.x, followPos.current.y, followPos.current.z, true);\n if (effCustomGravity && state.camera.up.distanceToSquared(followUp.current) > 1e-6) {\n state.camera.up.lerp(followUp.current, 1 - Math.exp(-8 * dt)).normalize();\n cam.setUp(state.camera.up);\n }\n }\n }\n });\n\n return (\n <>\n {hasDom && cameraProps !== false && cameraProps !== null && (\n <EcctrlCameraControls\n ref={assignCamRef}\n makeDefault\n enabled={onFoot}\n minPolarAngle={0.12}\n maxPolarAngle={Math.PI - 0.12}\n smoothTime={0.08}\n {...(cameraProps ?? {})}\n />\n )}\n <group visible={onFoot}>\n <Ecctrl\n ref={assignEcctrlRef}\n enable={onFoot}\n enableToggleRun={enableToggleRun}\n enableCustomGravity={effCustomGravity}\n position={position}\n {...(rotation === undefined ? {} : { rotation })}\n userData={mergedUserData}\n {...ecctrlRest}\n >\n {children ?? (clonedScene ? <primitive object={clonedScene} /> : null)}\n </Ecctrl>\n </group>\n </>\n );\n}\n","import type * as THREE from \"three\";\nimport { GLTFLoader } from \"three/examples/jsm/loaders/GLTFLoader.js\";\nimport { KTX2Loader } from \"three/examples/jsm/loaders/KTX2Loader.js\";\nimport { MeshoptDecoder } from \"three/examples/jsm/libs/meshopt_decoder.module.js\";\nimport { loadKhrGlb, type KhrAssetBundle, type KhrPluginOptions } from \"@khr3/core\";\n\nexport interface KolmoGltfLoaderOptions {\n /** Optional WebGLRenderer so KTX2 (`KHR_texture_basisu`) detects hardware ASTC/BC7/ETC2 support. */\n readonly renderer?: THREE.WebGLRenderer | null;\n /** Optional path hosting Basis Universal transcoder `.js`/`.wasm` files (defaults to `\"/basis/\"`). */\n readonly basisTranscoderPath?: string;\n /** Optional `@khr3/core` plugin options. */\n readonly khrOptions?: KhrPluginOptions;\n}\n\nconst ktx2ByRenderer = new WeakMap<THREE.WebGLRenderer, Map<string, KTX2Loader>>();\n\nfunction getScopedKtx2Loader(renderer: THREE.WebGLRenderer, transcoderPath: string): KTX2Loader {\n let byPath = ktx2ByRenderer.get(renderer);\n if (!byPath) {\n byPath = new Map();\n ktx2ByRenderer.set(renderer, byPath);\n }\n let ktx2 = byPath.get(transcoderPath);\n if (!ktx2) {\n ktx2 = new KTX2Loader();\n ktx2.setTranscoderPath(transcoderPath);\n ktx2.detectSupport(renderer);\n byPath.set(transcoderPath, ktx2);\n }\n return ktx2;\n}\n\n/**\n * Khronos-compliant `GLTFLoader` configured with `EXT_meshopt_compression` (`MeshoptDecoder`)\n * and `KHR_texture_basisu` (`KTX2Loader` when a renderer is supplied).\n */\nexport function createKolmoGltfLoader(options?: KolmoGltfLoaderOptions): GLTFLoader {\n const loader = new GLTFLoader();\n loader.setMeshoptDecoder(MeshoptDecoder);\n if (options?.renderer) {\n loader.setKTX2Loader(getScopedKtx2Loader(options.renderer, options.basisTranscoderPath ?? \"/basis/\"));\n }\n return loader;\n}\n\nexport async function parseKolmoGlbBuffer(\n buffer: ArrayBuffer | Uint8Array,\n options?: KolmoGltfLoaderOptions,\n): Promise<KhrAssetBundle> {\n await MeshoptDecoder.ready;\n const loader = createKolmoGltfLoader(options);\n return loadKhrGlb(buffer, { ...options?.khrOptions, loader });\n}\n\nexport async function loadKolmoGlbUrl(\n url: string,\n options?: KolmoGltfLoaderOptions,\n): Promise<KhrAssetBundle> {\n const res = await fetch(url);\n if (!res.ok)\n throw new Error(`Failed to fetch GLB (${res.status}): ${url}`);\n return parseKolmoGlbBuffer(await res.arrayBuffer(), options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6BA,IAAM,WAAW,IAAI,MAAM,QAAQ;AACnC,IAAM,UAAU,IAAI,MAAM,QAAQ;AAClC,IAAM,WAAW,IAAI,MAAM,QAAQ,GAAG,GAAG,CAAC;AAC1C,IAAM,YAAY,IAAI,MAAM,WAAW;AAEvC,SAAS,iCAAiC,OAA+C,UAAwC;CAC7H,IAAI,YAA2B;CAC/B,IAAI,aAAa;CACjB,KAAK,MAAM,OAAO,MAAM,MAAM,cAAc,iB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cAAc;CACpC,IAAI,CAAC,MAAM;EACP,OAAO,IAAI,WAAW;EACtB,KAAK,kBAAkB,cAAc;EACrC,KAAK,cAAc,QAAQ;EAC3B,OAAO,IAAI,gBAAgB,IAAI;CACnC;CACA,OAAO;AACX;;;;;AAMA,SAAgB,sBAAsB,SAA8C;CAChF,MAAM,SAAS,IAAI,WAAW;CAC9B,OAAO,kBAAkB,cAAc;CACvC,IAAI,SAAS,UACT,OAAO,cAAc,oBAAoB,QAAQ,UAAU,QAAQ,uBAAuB,SAAS,CAAC;CAExG,OAAO;AACX;AAEA,eAAsB,oBAClB,QACA,SACuB;CACvB,MAAM,eAAe;CACrB,MAAM,SAAS,sBAAsB,OAAO;CAC5C,OAAO,WAAW,QAAQ;EAAE,GAAG,SAAS;EAAY;CAAO,CAAC;AAChE;AAEA,eAAsB,gBAClB,KACA,SACuB;CACvB,MAAM,MAAM,MAAM,MAAM,GAAG;CAC3B,IAAI,CAAC,IAAI,IACL,MAAM,IAAI,MAAM,wBAAwB,IAAI,OAAO,KAAK,KAAK;CACjE,OAAO,oBAAoB,MAAM,IAAI,YAAY,GAAG,OAAO;AAC/D"}
|
package/dist/engine/surface.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type
|
|
2
|
+
import { type ThreeEvent } from "@react-three/fiber";
|
|
3
3
|
import { type KhrAssemblyProps, type KhrAssetBundle } from "@khr3/core";
|
|
4
4
|
export interface KolmoSurfaceProps extends Omit<KhrAssemblyProps, "bundle"> {
|
|
5
5
|
readonly src?: string;
|
|
6
6
|
readonly bundle?: KhrAssetBundle;
|
|
7
|
-
readonly size?: number;
|
|
8
|
-
readonly color?: string;
|
|
9
7
|
}
|
|
10
|
-
export declare function KolmoSurface({ ref, src, bundle,
|
|
11
|
-
export interface KolmoPropProps extends Omit<KhrAssemblyProps, "bundle" | "onClick"> {
|
|
8
|
+
export declare function KolmoSurface({ ref, src, bundle, position, ...rest }: KolmoSurfaceProps): React.JSX.Element;
|
|
9
|
+
export interface KolmoPropProps extends Omit<KhrAssemblyProps, "bundle" | "onClick" | "id"> {
|
|
10
|
+
readonly id?: string;
|
|
12
11
|
readonly src?: string;
|
|
13
12
|
readonly bundle?: KhrAssetBundle;
|
|
14
13
|
readonly fixed?: boolean;
|
|
15
14
|
readonly onClick?: (e: ThreeEvent<MouseEvent>) => void;
|
|
16
15
|
}
|
|
17
|
-
export declare function KolmoProp({ src, bundle, ...rest }: KolmoPropProps): React.JSX.Element
|
|
16
|
+
export declare function KolmoProp({ id: explicitId, src, bundle, ...rest }: KolmoPropProps): React.JSX.Element;
|
package/dist/engine/traits.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { type Entity, type World } from "koota";
|
|
2
|
+
import type RAPIER from "@dimforge/rapier3d-compat";
|
|
2
3
|
import type { EcctrlHandle } from "@pinkaphant/ecctrl";
|
|
3
4
|
import type { EcctrlVehicleHandle, VehicleInput } from "@pinkaphant/ecctrl/vehicle";
|
|
5
|
+
import type { KhrAssemblyHandle } from "@khr3/core";
|
|
4
6
|
import type { KhrVehicleJointsHandle } from "@khr3/core/vehicle";
|
|
7
|
+
/**
|
|
8
|
+
* Verifies that `handle.body` is a live `RigidBody` registered in `rapierWorld` (`live === candidate`),
|
|
9
|
+
* preventing React 19 `<StrictMode>` pass-1 freed WASM arena handle panics (`RuntimeError: unreachable`).
|
|
10
|
+
*/
|
|
11
|
+
export declare function getLiveActorBody(rapierWorld: Pick<RAPIER.World, "getRigidBody">, handle: Pick<EcctrlHandle, "body"> | null | undefined): RAPIER.RigidBody | null;
|
|
5
12
|
export type KolmoControlMode = "foot" | "car" | "flight";
|
|
13
|
+
export interface PropTraitData {
|
|
14
|
+
id: string;
|
|
15
|
+
handle: KhrAssemblyHandle | null;
|
|
16
|
+
fixed: boolean;
|
|
17
|
+
}
|
|
6
18
|
export interface VehicleTraitData {
|
|
7
19
|
id: string;
|
|
8
20
|
handle: EcctrlVehicleHandle | null;
|
|
@@ -20,6 +32,7 @@ export interface ActorTraitData {
|
|
|
20
32
|
}
|
|
21
33
|
export declare const VehicleTrait: import("koota").Trait<() => VehicleTraitData>;
|
|
22
34
|
export declare const ActorTrait: import("koota").Trait<() => ActorTraitData>;
|
|
35
|
+
export declare const PropTrait: import("koota").Trait<() => PropTraitData>;
|
|
23
36
|
export declare const TransformTrait: import("koota").Trait<{
|
|
24
37
|
x: number;
|
|
25
38
|
y: number;
|
|
@@ -72,6 +85,20 @@ export declare const vehicleSimQuery: import("koota").Query<[import("koota").Tra
|
|
|
72
85
|
boost: number;
|
|
73
86
|
slip: number;
|
|
74
87
|
}>]>;
|
|
88
|
+
export declare const propSimQuery: import("koota").Query<[import("koota").Trait<() => PropTraitData>, import("koota").Trait<{
|
|
89
|
+
x: number;
|
|
90
|
+
y: number;
|
|
91
|
+
z: number;
|
|
92
|
+
qx: number;
|
|
93
|
+
qy: number;
|
|
94
|
+
qz: number;
|
|
95
|
+
qw: number;
|
|
96
|
+
}>, import("koota").Trait<{
|
|
97
|
+
vx: number;
|
|
98
|
+
vy: number;
|
|
99
|
+
vz: number;
|
|
100
|
+
speedKmh: number;
|
|
101
|
+
}>]>;
|
|
75
102
|
export declare const pilotedVehicleQuery: import("koota").Query<[import("koota").Trait<() => VehicleTraitData>, import("koota").TagTrait]>;
|
|
76
103
|
export declare const kolmoWorld: World;
|
|
77
104
|
export declare const KolmoWorldContext: import("react").Context<World | null>;
|
package/dist/engine/world.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export interface KolmoWorldProps {
|
|
|
31
31
|
readonly paused?: boolean;
|
|
32
32
|
readonly timeScale?: KolmoTimeControlValue;
|
|
33
33
|
readonly maxDelta?: KolmoTimeControlValue;
|
|
34
|
+
readonly debug?: boolean;
|
|
34
35
|
readonly physicsDebug?: boolean;
|
|
35
36
|
readonly skybox?: "day" | "night" | "none";
|
|
36
37
|
readonly lighting?: "default" | "none";
|
|
@@ -40,7 +41,7 @@ export interface KolmoWorldProps {
|
|
|
40
41
|
readonly keyboardMap?: KeyboardControlsEntry<string>[] | null;
|
|
41
42
|
readonly children: ReactNode;
|
|
42
43
|
}
|
|
43
|
-
export declare function KolmoWorld({ gravity, paused, timeScale, maxDelta, physicsDebug, skybox, lighting, fogExp2, sunLightRef, world, keyboardMap, children, }: KolmoWorldProps): React.JSX.Element;
|
|
44
|
+
export declare function KolmoWorld({ gravity, paused, timeScale, maxDelta, debug, physicsDebug, skybox, lighting, fogExp2, sunLightRef, world, keyboardMap, children, }: KolmoWorldProps): React.JSX.Element;
|
|
44
45
|
export interface KolmoGameHookState {
|
|
45
46
|
readonly world: World;
|
|
46
47
|
readonly mode: KolmoControlMode;
|
|
@@ -56,7 +57,7 @@ export interface KolmoHudProps {
|
|
|
56
57
|
readonly extraPrompt?: string;
|
|
57
58
|
readonly style?: CSSProperties;
|
|
58
59
|
}
|
|
59
|
-
export declare function KolmoHud(
|
|
60
|
+
export declare function KolmoHud({ showTouchControls, extraPrompt, style }: KolmoHudProps): React.JSX.Element | null;
|
|
60
61
|
export interface KolmoGameProps {
|
|
61
62
|
readonly gravity?: KolmoGravitySpec;
|
|
62
63
|
readonly skybox?: "day" | "night" | "none";
|
|
@@ -65,6 +66,7 @@ export interface KolmoGameProps {
|
|
|
65
66
|
readonly paused?: boolean;
|
|
66
67
|
readonly timeScale?: KolmoTimeControlValue;
|
|
67
68
|
readonly maxDelta?: KolmoTimeControlValue;
|
|
69
|
+
readonly debug?: boolean;
|
|
68
70
|
readonly physicsDebug?: boolean;
|
|
69
71
|
readonly dpr?: number | [number, number];
|
|
70
72
|
readonly roomEnv?: boolean | number;
|
|
@@ -73,4 +75,4 @@ export interface KolmoGameProps {
|
|
|
73
75
|
readonly className?: string;
|
|
74
76
|
readonly children?: ReactNode;
|
|
75
77
|
}
|
|
76
|
-
export declare function KolmoGame({ gravity, skybox, lighting, fogExp2, paused, timeScale, maxDelta, physicsDebug, dpr, roomEnv, kootaWorld, style, className, children, }: KolmoGameProps): React.JSX.Element;
|
|
78
|
+
export declare function KolmoGame({ gravity, skybox, lighting, fogExp2, paused, timeScale, maxDelta, debug, physicsDebug, dpr, roomEnv, kootaWorld, style, className, children, }: KolmoGameProps): React.JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./engine/index.js";
|
|
2
|
-
export { KolmoCanvas as Canvas, KolmoPhysics as Physics, KolmoWorld as World, KolmoGame as Game, KolmoHud as Hud, KolmoVehicle as Vehicle, KolmoActor as Actor, KolmoSurface as Surface, KolmoProp as Prop, } from "./engine/index.js";
|
|
2
|
+
export { KolmoCanvas as Canvas, KolmoPhysics as Physics, KolmoWorld as World, KolmoGame as Game, KolmoHud as Hud, KolmoVehicle as Vehicle, KolmoActor as Actor, KolmoSurface as Surface, KolmoTerrain as Terrain, KolmoWater as Water, KolmoProp as Prop, } from "./engine/index.js";
|
|
3
3
|
export * from "./toolgun/index.js";
|
|
4
4
|
export { KolmoToolgun as Toolgun } from "./toolgun/index.js";
|
|
5
5
|
export { Ecctrl, type EcctrlHandle, type EcctrlProps, type MovementInput } from "@pinkaphant/ecctrl";
|
|
@@ -8,7 +8,7 @@ export { Joystick, VirtualButton, useButtonStore, useJoystickStore } from "@pink
|
|
|
8
8
|
export { EcctrlCameraControls, type EcctrlCameraControlsHandle } from "@pinkaphant/ecctrl/camera";
|
|
9
9
|
export { EcctrlAnimationStateController, useEcctrlAnimationStore, type EcctrlAnimationState, } from "@pinkaphant/ecctrl/animation";
|
|
10
10
|
export { useCustomGravity, type CustomGravityState } from "@pinkaphant/ecctrl/gravity";
|
|
11
|
-
export { JointRegistryContext, KhrAssembly, PhysicsWorld, cloneKhrBundle, createKhrGltfPlugin, disposeKhrBundle, exportKhrGlb, loadKhrGlb, useKhrGlb, type JointRegistry, type JointRuntime, type KhrAssemblyHandle, type KhrAssemblyProps, type KhrAssetBundle, type KhrExportNodeSpec, } from "@khr3/core";
|
|
11
|
+
export { JointRegistryContext, KHR_HEIGHTFIELD_FLAGS, KHR_TRIMESH_FLAGS, KhrAssembly, KhrCollider, KhrHeightfield, KhrValidationError, PhysicsWorld, cloneKhrBundle, createHeightfieldGeometry, createKhrGltfPlugin, disposeKhrBundle, exportKhrGlb, loadKhrGlb, sampleRapierHeightfield, transposeHeightfieldForRapier, useKhrGlb, type HeightfieldLayout, type JointRegistry, type JointRuntime, type KhrAssemblyHandle, type KhrAssemblyProps, type KhrAssetBundle, type KhrEmitterSpec, type KhrExportNodeSpec, type KhrHeightfieldProps, } from "@khr3/core";
|
|
12
12
|
export { KhrVehicle, type KhrVehicleJointsHandle, type KhrVehicleProps } from "@khr3/core/vehicle";
|
|
13
13
|
export { DOOR_HINGE_SPEC, Ex, PIECE_KINDS, ROOT3, SIDE_METRES, STOREY_METRES, buildFootprint, canPlace, instanceBatches, latticePose, planSettlement, poseEq, poseFromJSON, poseToFloat, poseToJSON, snapPose, socketFor, triangleCorners, vToFloat, worldSockets, type PieceKind, type PiecePose, type PlacedPiece, } from "@khr3/c12";
|
|
14
14
|
export { createActions, createQuery, createWorld, getStore, relation, trait, unpackEntity, type Entity, type World as KootaWorld, } from "koota";
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
import {
|
|
1
|
+
import { C as writeEntityKinematics, S as vehicleSimQuery, _ as kolmoWorld, a as PilotedTag, b as useActiveKolmoWorld, c as VehicleTelemetryTrait, d as WorldSessionTrait, f as createEmptyVehicleCmd, g as kolmoActions, h as getLiveActorBody, 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, y as propSimQuery } from "./traits-Dp1ey_4w.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-BDhBihjW.js";
|
|
3
|
+
import { a as computeCircularOrbitSpeed, c as evaluatePreparedNBodyGravity, i as G_SI, l as prepareAttractors, n as KolmoPhysics, o as createNBodyGravityField, r as useIsKolmoCustomGravity, s as evaluateNBodyGravity, t as KolmoGravityContext, u as resolveAttractorMu } from "./physics-KYWAXctg.js";
|
|
3
4
|
import { KolmoActor, createKolmoGltfLoader, loadKolmoGlbUrl, parseKolmoGlbBuffer } from "./engine/index.js";
|
|
4
|
-
import {
|
|
5
|
+
import { KolmoTerrain, KolmoTerrainField, createRollingBasinHeightFn, exportTerrainKhrGlb } from "./terrain/index.js";
|
|
6
|
+
import { KolmoWater, KolmoWaterField, sphericalCapVolume, stepWaterHydrodynamics } from "./water/index.js";
|
|
7
|
+
import { FixedStepAccumulator, InputTapePlayer, InputTapeRecorder, KootaTrajectoryTape } from "./replay/index.js";
|
|
8
|
+
import { a as TOOLGUN_MODES, c as computeBuildCandidate, d as createWeldImpulseJoint, f as isSameBuildPreview, i as TOOLGUN_BUILD_KINDS, l as createHingeImpulseJoint, m as useToolgunStore, n as KolmoToolgun, o as castToolgunRay, p as rigJointRuntime, r as measureToolgunViewmodel, s as computeAlignedSpawnPose, t as DEFAULT_VAULT_C12_URLS, u as createToolgunStore } from "./toolgun-COu_5SxS.js";
|
|
5
9
|
import { Ecctrl } from "@pinkaphant/ecctrl";
|
|
6
10
|
import { EcctrlVehicle, ShapeCastWheel, ThrustPropeller } from "@pinkaphant/ecctrl/vehicle";
|
|
7
11
|
import { Joystick, VirtualButton, useButtonStore, useJoystickStore } from "@pinkaphant/ecctrl/input";
|
|
8
12
|
import { EcctrlCameraControls } from "@pinkaphant/ecctrl/camera";
|
|
9
13
|
import { EcctrlAnimationStateController, useEcctrlAnimationStore } from "@pinkaphant/ecctrl/animation";
|
|
10
14
|
import { useCustomGravity } from "@pinkaphant/ecctrl/gravity";
|
|
11
|
-
import { JointRegistryContext, KhrAssembly, PhysicsWorld, cloneKhrBundle, createKhrGltfPlugin, disposeKhrBundle, exportKhrGlb, loadKhrGlb, useKhrGlb } from "@khr3/core";
|
|
15
|
+
import { JointRegistryContext, KHR_HEIGHTFIELD_FLAGS, KHR_TRIMESH_FLAGS, KhrAssembly, KhrCollider, KhrHeightfield, KhrValidationError, PhysicsWorld, cloneKhrBundle, createHeightfieldGeometry, createKhrGltfPlugin, disposeKhrBundle, exportKhrGlb, loadKhrGlb, sampleRapierHeightfield, transposeHeightfieldForRapier, useKhrGlb } from "@khr3/core";
|
|
12
16
|
import { KhrVehicle } from "@khr3/core/vehicle";
|
|
13
17
|
import { DOOR_HINGE_SPEC, Ex, PIECE_KINDS, ROOT3, SIDE_METRES, STOREY_METRES, buildFootprint, canPlace, instanceBatches, latticePose, planSettlement, poseEq, poseFromJSON, poseToFloat, poseToJSON, snapPose, socketFor, triangleCorners, vToFloat, worldSockets } from "@khr3/c12";
|
|
14
18
|
import { createActions, createQuery, createWorld, getStore, relation, trait, unpackEntity } from "koota";
|
|
15
19
|
import { WorldProvider, useHas, useQuery, useQueryFirst, useTrait, useWorld } from "koota/react";
|
|
16
|
-
export { KolmoActor as Actor, KolmoActor, ActorTrait, KolmoCanvas as Canvas, KolmoCanvas, DOOR_HINGE_SPEC, EMPTY_KOLMO_INPUT, Ecctrl, EcctrlAnimationStateController, EcctrlCameraControls, EcctrlVehicle, Ex, G_SI, KolmoGame as Game, KolmoGame, KolmoHud as Hud, KolmoHud, InteractableTrait, JointRegistryContext, Joystick, KOLMO_KEY_MAP, KOLMO_STICK_DEADZONE, KhrAssembly, KhrVehicle, KolmoGravityContext, KolmoInCanvasContext, KolmoKeyboardBridge, KolmoKeyboardContext, KolmoOverlayPortalContext, KolmoPhysics, KolmoPhysics as Physics, KolmoProp, KolmoProp as Prop, KolmoSurface, KolmoSurface as Surface, KolmoToolgun, KolmoToolgun as Toolgun, KolmoVehicle, KolmoVehicle as Vehicle, KolmoWorld, KolmoWorld as World, KolmoWorldContext, PIECE_KINDS, PhysicsWorld, PilotLink, PilotedTag, ROOT3, RoomEnvRig, SIDE_METRES, STOREY_METRES, ShapeCastWheel, TOOLGUN_BUILD_KINDS, TOOLGUN_MODES, ThrustPropeller, TransformTrait, VehicleTelemetryTrait, VehicleTrait, VelocityTrait, VirtualButton, WorldProvider, WorldSessionTrait, buildFootprint, canPlace, castToolgunRay, cloneKhrBundle, computeAlignedSpawnPose, computeBuildCandidate, computeCircularOrbitSpeed, createActions, createEmptyVehicleCmd, createHingeImpulseJoint, createKhrGltfPlugin, createKolmoGltfLoader, createNBodyGravityField, createQuery, createToolgunStore, createWeldImpulseJoint, createWorld, disposeKhrBundle, ensureWorldSession, evaluateNBodyGravity, evaluatePreparedNBodyGravity, exportKhrGlb, flipVehicleBodyUpright, getStore, instanceBatches, isSameBuildPreview, kolmoActions, kolmoWorld, latticePose, loadKhrGlb, loadKolmoGlbUrl, measureToolgunViewmodel, parseKolmoGlbBuffer, pilotedVehicleQuery, planSettlement, poseEq, poseFromJSON, poseToFloat, poseToJSON, prepareAttractors, relation, resolveAttractorMu, rigJointRuntime, snapPose, socketFor, trait, triangleCorners, unpackEntity, useActiveKolmoWorld, useButtonStore, useCustomGravity, useEcctrlAnimationStore, useHas, useIsKolmoCustomGravity, useJoystickStore, useKhrGlb, useKolmoGame, useKolmoInput, useOptionalKootaWorld, useQuery, useQueryFirst, useToolgunStore, useTrait, useWorld, vToFloat, vehicleSimQuery, worldSockets, writeEntityKinematics, writeVehicleTelemetry };
|
|
20
|
+
export { KolmoActor as Actor, KolmoActor, ActorTrait, KolmoCanvas as Canvas, KolmoCanvas, DEFAULT_VAULT_C12_URLS, DOOR_HINGE_SPEC, EMPTY_KOLMO_INPUT, Ecctrl, EcctrlAnimationStateController, EcctrlCameraControls, EcctrlVehicle, Ex, FixedStepAccumulator, G_SI, KolmoGame as Game, KolmoGame, KolmoHud as Hud, KolmoHud, InputTapePlayer, InputTapeRecorder, InteractableTrait, JointRegistryContext, Joystick, KHR_HEIGHTFIELD_FLAGS, KHR_TRIMESH_FLAGS, KOLMO_KEY_MAP, KOLMO_STICK_DEADZONE, KhrAssembly, KhrCollider, KhrHeightfield, KhrValidationError, KhrVehicle, KolmoGravityContext, KolmoInCanvasContext, KolmoKeyboardBridge, KolmoKeyboardContext, KolmoOverlayPortalContext, KolmoPhysics, KolmoPhysics as Physics, KolmoProp, KolmoProp as Prop, KolmoSurface, KolmoSurface as Surface, KolmoTerrain, KolmoTerrain as Terrain, KolmoTerrainField, KolmoToolgun, KolmoToolgun as Toolgun, KolmoVehicle, KolmoVehicle as Vehicle, KolmoWater, KolmoWater as Water, KolmoWaterField, KolmoWorld, KolmoWorld as World, KolmoWorldContext, KootaTrajectoryTape, PIECE_KINDS, PhysicsWorld, PilotLink, PilotedTag, PropTrait, ROOT3, RoomEnvRig, SIDE_METRES, STOREY_METRES, ShapeCastWheel, TOOLGUN_BUILD_KINDS, TOOLGUN_MODES, ThrustPropeller, TransformTrait, VehicleTelemetryTrait, VehicleTrait, VelocityTrait, VirtualButton, WorldProvider, WorldSessionTrait, buildFootprint, canPlace, castToolgunRay, cloneKhrBundle, computeAlignedSpawnPose, computeBuildCandidate, computeCircularOrbitSpeed, createActions, createEmptyVehicleCmd, createHeightfieldGeometry, createHingeImpulseJoint, createKhrGltfPlugin, createKolmoGltfLoader, createNBodyGravityField, createQuery, createRollingBasinHeightFn, createToolgunStore, createWeldImpulseJoint, createWorld, disposeKhrBundle, ensureWorldSession, evaluateNBodyGravity, evaluatePreparedNBodyGravity, exportKhrGlb, exportTerrainKhrGlb, flipVehicleBodyUpright, getLiveActorBody, getStore, instanceBatches, isSameBuildPreview, kolmoActions, kolmoWorld, latticePose, loadKhrGlb, loadKolmoGlbUrl, measureToolgunViewmodel, parseKolmoGlbBuffer, pilotedVehicleQuery, planSettlement, poseEq, poseFromJSON, poseToFloat, poseToJSON, prepareAttractors, propSimQuery, relation, resolveAttractorMu, rigJointRuntime, sampleRapierHeightfield, snapPose, socketFor, sphericalCapVolume, stepWaterHydrodynamics, trait, transposeHeightfieldForRapier, triangleCorners, unpackEntity, useActiveKolmoWorld, useButtonStore, useCustomGravity, useEcctrlAnimationStore, useHas, useIsKolmoCustomGravity, useJoystickStore, useKhrGlb, useKolmoGame, useKolmoInput, useOptionalKootaWorld, useQuery, useQueryFirst, useToolgunStore, useTrait, useWorld, vToFloat, vehicleSimQuery, worldSockets, writeEntityKinematics, writeVehicleTelemetry };
|