@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.
- 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 +94 -441
- 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 +10 -6
- 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 +17 -6
- package/dist/toolgun/index.d.ts +2 -2
- package/dist/toolgun/index.js +1 -1
- package/dist/toolgun/store.d.ts +25 -75
- package/dist/{toolgun-BfcCIAQx.js → toolgun-COu_5SxS.js} +391 -673
- 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/{surface-DUol_5ml.js → world-BDhBihjW.js} +442 -57
- package/dist/world-BDhBihjW.js.map +1 -0
- package/docs/api-reference.md +201 -0
- package/package.json +25 -8
- package/dist/physics-ZDFXaCli.js +0 -475
- package/dist/physics-ZDFXaCli.js.map +0 -1
- package/dist/surface-DUol_5ml.js.map +0 -1
- package/dist/toolgun-BfcCIAQx.js.map +0 -1
package/dist/engine/index.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
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 { 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
|
-
import {
|
|
6
|
+
import { useFrame, useThree } from "@react-three/fiber";
|
|
7
7
|
import { useRapier } from "@react-three/rapier";
|
|
8
|
-
import {
|
|
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
|
+
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
|
-
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
14
|
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
19
15
|
import { KTX2Loader } from "three/examples/jsm/loaders/KTX2Loader.js";
|
|
20
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";
|
|
21
20
|
// src/engine/actor.tsx
|
|
22
21
|
var _seatVec = new THREE.Vector3();
|
|
23
22
|
var _camFwd = new THREE.Vector3();
|
|
24
23
|
var _worldUp = new THREE.Vector3(0, 1, 0);
|
|
24
|
+
var _exitQuat = new THREE.Quaternion();
|
|
25
25
|
function findNearestInteractableVehicleId(world, actorPos) {
|
|
26
26
|
let nearestId = null;
|
|
27
27
|
let bestDistSq = 1e400;
|
|
@@ -38,7 +38,7 @@ function findNearestInteractableVehicleId(world, actorPos) {
|
|
|
38
38
|
}
|
|
39
39
|
return nearestId;
|
|
40
40
|
}
|
|
41
|
-
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 = [
|
|
42
42
|
0,
|
|
43
43
|
1.4,
|
|
44
44
|
0
|
|
@@ -76,7 +76,48 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
76
76
|
run: false,
|
|
77
77
|
jump: false
|
|
78
78
|
});
|
|
79
|
-
const
|
|
79
|
+
const applyPendingExit = useCallback((handle, liveBody) => {
|
|
80
|
+
const ent = actorEntRef.current;
|
|
81
|
+
if (!ent?.isAlive()) return;
|
|
82
|
+
const d = ent.get(ActorTrait);
|
|
83
|
+
if (!d?.exitSpawnPos) return;
|
|
84
|
+
const [ex, ey, ez] = d.exitSpawnPos;
|
|
85
|
+
_exitQuat.setFromAxisAngle(_worldUp, d.exitSpawnYaw);
|
|
86
|
+
liveBody.setTranslation({
|
|
87
|
+
x: ex,
|
|
88
|
+
y: ey,
|
|
89
|
+
z: ez
|
|
90
|
+
}, true);
|
|
91
|
+
liveBody.setRotation({
|
|
92
|
+
x: _exitQuat.x,
|
|
93
|
+
y: _exitQuat.y,
|
|
94
|
+
z: _exitQuat.z,
|
|
95
|
+
w: _exitQuat.w
|
|
96
|
+
}, true);
|
|
97
|
+
const lv = d.exitLinVel;
|
|
98
|
+
liveBody.setLinvel(lv ? {
|
|
99
|
+
x: lv[0],
|
|
100
|
+
y: lv[1],
|
|
101
|
+
z: lv[2]
|
|
102
|
+
} : {
|
|
103
|
+
x: 0,
|
|
104
|
+
y: 0,
|
|
105
|
+
z: 0
|
|
106
|
+
}, true);
|
|
107
|
+
liveBody.setAngvel({
|
|
108
|
+
x: 0,
|
|
109
|
+
y: 0,
|
|
110
|
+
z: 0
|
|
111
|
+
}, true);
|
|
112
|
+
handle.currPos.set(ex, ey, ez);
|
|
113
|
+
handle.currQuat.copy(_exitQuat);
|
|
114
|
+
ent.set(ActorTrait, {
|
|
115
|
+
...d,
|
|
116
|
+
handle,
|
|
117
|
+
exitSpawnPos: null,
|
|
118
|
+
exitLinVel: null
|
|
119
|
+
});
|
|
120
|
+
}, []);
|
|
80
121
|
useLayoutEffect(() => {
|
|
81
122
|
const ent = activeWorld.spawn(ActorTrait({
|
|
82
123
|
id: "pilot",
|
|
@@ -88,18 +129,9 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
88
129
|
actorEntRef.current = ent;
|
|
89
130
|
const prePiloted = activeWorld.queryFirst(pilotedVehicleQuery);
|
|
90
131
|
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
132
|
return () => {
|
|
100
|
-
unsub();
|
|
101
133
|
actorEntRef.current = null;
|
|
102
|
-
ent.destroy();
|
|
134
|
+
if (ent.isAlive()) ent.destroy();
|
|
103
135
|
};
|
|
104
136
|
}, [activeWorld]);
|
|
105
137
|
const onFoot = enable && !pilotedVehEnt;
|
|
@@ -108,7 +140,7 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
108
140
|
}, [onFoot]);
|
|
109
141
|
useLayoutEffect(() => {
|
|
110
142
|
const ent = actorEntRef.current;
|
|
111
|
-
if (ent && pilotedVehEnt && !ent.has(PilotLink(pilotedVehEnt))) ent.add(PilotLink(pilotedVehEnt));
|
|
143
|
+
if (ent?.isAlive() && pilotedVehEnt && !ent.has(PilotLink(pilotedVehEnt))) ent.add(PilotLink(pilotedVehEnt));
|
|
112
144
|
}, [pilotedVehEnt]);
|
|
113
145
|
const assignEcctrlRef = useCallback((handle) => {
|
|
114
146
|
ecctrlRef.current = handle;
|
|
@@ -116,17 +148,12 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
116
148
|
const ent = actorEntRef.current;
|
|
117
149
|
if (!ent?.isAlive()) return;
|
|
118
150
|
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);
|
|
124
151
|
ent.set(ActorTrait, {
|
|
125
152
|
id: cur?.id ?? "pilot",
|
|
126
153
|
handle,
|
|
127
154
|
exitSpawnPos: cur?.exitSpawnPos ?? null,
|
|
128
155
|
exitSpawnYaw: cur?.exitSpawnYaw ?? 0,
|
|
129
|
-
exitLinVel:
|
|
156
|
+
exitLinVel: cur?.exitLinVel ?? null
|
|
130
157
|
});
|
|
131
158
|
}, [ref]);
|
|
132
159
|
const assignCamRef = useCallback((ctrl) => {
|
|
@@ -145,22 +172,42 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
145
172
|
};
|
|
146
173
|
}, [userData]);
|
|
147
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
|
+
]);
|
|
148
188
|
useFrame((state, delta) => {
|
|
149
|
-
|
|
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
|
+
}
|
|
150
195
|
const dt = rapierWorld.timestep > 0 ? rapierWorld.timestep : Math.min(Math.max(delta, 1e-4), 1 / 30);
|
|
151
196
|
if (cooldownRef.current > 0) cooldownRef.current = Math.max(0, cooldownRef.current - dt);
|
|
152
197
|
const inp = readInput();
|
|
153
198
|
const interactEdge = inp.interact && !prevInteractRef.current;
|
|
154
199
|
prevInteractRef.current = inp.interact;
|
|
155
200
|
if (activeWorld.queryFirst(pilotedVehicleQuery)) {
|
|
201
|
+
if (liveBody && liveBody.isEnabled()) liveBody.setEnabled(false);
|
|
156
202
|
if (interactEdge && cooldownRef.current === 0) {
|
|
157
203
|
cooldownRef.current = .25;
|
|
158
204
|
kolmoActions(activeWorld).exitVehicle();
|
|
159
205
|
}
|
|
160
206
|
return;
|
|
161
207
|
}
|
|
162
|
-
|
|
163
|
-
if (!
|
|
208
|
+
if (!handle || !liveBody) return;
|
|
209
|
+
if (!liveBody.isEnabled()) liveBody.setEnabled(true);
|
|
210
|
+
applyPendingExit(handle, liveBody);
|
|
164
211
|
stickRef.current.x = inp.stickX;
|
|
165
212
|
stickRef.current.y = inp.stickY;
|
|
166
213
|
const cmd = moveCmdRef.current;
|
|
@@ -205,422 +252,28 @@ function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable = tr
|
|
|
205
252
|
}
|
|
206
253
|
}
|
|
207
254
|
});
|
|
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
255
|
return /* @__PURE__ */ jsxs(Fragment, { children: [hasDom && cameraProps !== false && cameraProps !== null && /* @__PURE__ */ jsx(EcctrlCameraControls, {
|
|
216
256
|
ref: assignCamRef,
|
|
217
257
|
makeDefault: true,
|
|
258
|
+
enabled: onFoot,
|
|
218
259
|
minPolarAngle: .12,
|
|
219
260
|
maxPolarAngle: Math.PI - .12,
|
|
220
261
|
smoothTime: .08,
|
|
221
262
|
...cameraProps ?? {}
|
|
222
|
-
}), /* @__PURE__ */ jsx(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
|
263
|
+
}), /* @__PURE__ */ jsx("group", {
|
|
264
|
+
visible: onFoot,
|
|
265
|
+
children: /* @__PURE__ */ jsx(Ecctrl, {
|
|
266
|
+
ref: assignEcctrlRef,
|
|
267
|
+
enable: onFoot,
|
|
268
|
+
enableToggleRun,
|
|
269
|
+
enableCustomGravity: effCustomGravity,
|
|
270
|
+
position,
|
|
271
|
+
...rotation === void 0 ? {} : { rotation },
|
|
272
|
+
userData: mergedUserData,
|
|
273
|
+
...ecctrlRest,
|
|
274
|
+
children: children ?? (clonedScene ? /* @__PURE__ */ jsx("primitive", { object: clonedScene }) : null)
|
|
369
275
|
})
|
|
370
|
-
})
|
|
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;
|
|
276
|
+
})] });
|
|
624
277
|
}
|
|
625
278
|
// src/engine/gltfLoader.ts
|
|
626
279
|
var ktx2ByRenderer = /* @__PURE__ */ new WeakMap();
|
|
@@ -662,6 +315,6 @@ async function loadKolmoGlbUrl(url, options) {
|
|
|
662
315
|
if (!res.ok) throw new Error(`Failed to fetch GLB (${res.status}): ${url}`);
|
|
663
316
|
return parseKolmoGlbBuffer(await res.arrayBuffer(), options);
|
|
664
317
|
}
|
|
665
|
-
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 };
|
|
666
319
|
|
|
667
320
|
//# sourceMappingURL=index.js.map
|