@pinkaphant/kolmo 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -23
- package/dist/engine/actor.d.ts +1 -1
- package/dist/engine/gltfLoader.d.ts +6 -7
- package/dist/engine/index.js +122 -1082
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/input.d.ts +2 -1
- package/dist/engine/surface.d.ts +1 -3
- package/dist/engine/traits.d.ts +7 -2
- package/dist/engine/world.d.ts +2 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +7 -5
- package/dist/physics/index.d.ts +3 -3
- package/dist/physics/index.js +1 -1
- package/dist/physics/nBodyGravity.d.ts +14 -7
- package/dist/{physics-FhWvTBfH.js → physics-CA1abDCY.js} +124 -72
- package/dist/physics-CA1abDCY.js.map +1 -0
- package/dist/toolgun/Toolgun.d.ts +37 -0
- package/dist/toolgun/c12Outlets.d.ts +36 -0
- package/dist/toolgun/index.d.ts +2 -0
- package/dist/toolgun/index.js +1 -0
- package/dist/toolgun/store.d.ts +148 -0
- package/dist/toolgun-CFCNO00q.js +1640 -0
- package/dist/toolgun-CFCNO00q.js.map +1 -0
- package/dist/vite/index.d.ts +0 -4
- package/dist/vite/index.js +1 -9
- package/dist/vite/index.js.map +1 -1
- package/dist/world-BljtS6Fb.js +1020 -0
- package/dist/world-BljtS6Fb.js.map +1 -0
- package/package.json +12 -15
- package/dist/physics-FhWvTBfH.js.map +0 -1
|
@@ -3,12 +3,13 @@ import * as THREE from "three";
|
|
|
3
3
|
import { PhysicsWorld } from "@khr3/core";
|
|
4
4
|
import { useCustomGravity } from "@pinkaphant/ecctrl/gravity";
|
|
5
5
|
import { createActions, createQuery, createWorld, getStore, relation, trait, unpackEntity } from "koota";
|
|
6
|
-
import { WorldProvider
|
|
6
|
+
import { WorldProvider } from "koota/react";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
8
|
// src/engine/traits.ts
|
|
9
9
|
var VehicleTrait = trait(() => ({
|
|
10
10
|
id: "",
|
|
11
11
|
handle: null,
|
|
12
|
+
jointsHandle: null,
|
|
12
13
|
seatOffset: [
|
|
13
14
|
0,
|
|
14
15
|
.55,
|
|
@@ -61,16 +62,41 @@ var WorldSessionTrait = trait({ nearVehicleId: "" });
|
|
|
61
62
|
var vehicleSimQuery = createQuery(VehicleTrait, TransformTrait, VelocityTrait, VehicleTelemetryTrait);
|
|
62
63
|
var pilotedVehicleQuery = createQuery(VehicleTrait, PilotedTag);
|
|
63
64
|
var kolmoWorld = createWorld(WorldSessionTrait);
|
|
65
|
+
var KolmoWorldContext = createContext(null);
|
|
66
|
+
function useOptionalKootaWorld() {
|
|
67
|
+
return useContext(KolmoWorldContext);
|
|
68
|
+
}
|
|
64
69
|
function useActiveKolmoWorld() {
|
|
65
|
-
|
|
66
|
-
return useWorld();
|
|
67
|
-
} catch {
|
|
68
|
-
return kolmoWorld;
|
|
69
|
-
}
|
|
70
|
+
return useContext(KolmoWorldContext) ?? kolmoWorld;
|
|
70
71
|
}
|
|
71
72
|
function ensureWorldSession(w) {
|
|
72
73
|
if (!w.has(WorldSessionTrait)) w.add(WorldSessionTrait);
|
|
73
74
|
}
|
|
75
|
+
function createEmptyVehicleCmd(brake = false) {
|
|
76
|
+
return {
|
|
77
|
+
forward: false,
|
|
78
|
+
backward: false,
|
|
79
|
+
steerLeft: false,
|
|
80
|
+
steerRight: false,
|
|
81
|
+
brake,
|
|
82
|
+
throttleUp: false,
|
|
83
|
+
throttleDown: false,
|
|
84
|
+
yawLeft: false,
|
|
85
|
+
yawRight: false,
|
|
86
|
+
pitchForward: false,
|
|
87
|
+
pitchBackward: false,
|
|
88
|
+
rollLeft: false,
|
|
89
|
+
rollRight: false,
|
|
90
|
+
joystickL: {
|
|
91
|
+
x: 0,
|
|
92
|
+
y: 0
|
|
93
|
+
},
|
|
94
|
+
joystickR: {
|
|
95
|
+
x: 0,
|
|
96
|
+
y: 0
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
74
100
|
/** Zero-allocation SoA typed-array writer using Koota's public `unpackEntity` + `getStore`. */
|
|
75
101
|
function writeEntityKinematics(world, entity, pos, quat, linVel, speedKmh) {
|
|
76
102
|
const { entityId } = unpackEntity(entity);
|
|
@@ -110,7 +136,7 @@ var _flipFwd = new THREE.Vector3();
|
|
|
110
136
|
var _flipRight = new THREE.Vector3();
|
|
111
137
|
var _flipMat = new THREE.Matrix4();
|
|
112
138
|
var _flipQuat = new THREE.Quaternion();
|
|
113
|
-
function flipVehicleBodyUpright(veh) {
|
|
139
|
+
function flipVehicleBodyUpright(veh, joints) {
|
|
114
140
|
const body = veh.body;
|
|
115
141
|
if (!body) return;
|
|
116
142
|
const pos = body.translation();
|
|
@@ -147,17 +173,16 @@ function flipVehicleBodyUpright(veh) {
|
|
|
147
173
|
y: 0,
|
|
148
174
|
z: 0
|
|
149
175
|
}, true);
|
|
176
|
+
joints?.syncBodiesToParent();
|
|
150
177
|
}
|
|
151
178
|
var kolmoActions = createActions((world) => ({
|
|
152
179
|
boardVehicle: (vehicleId) => {
|
|
180
|
+
if (!vehicleId) return;
|
|
153
181
|
ensureWorldSession(world);
|
|
154
182
|
let targetEnt;
|
|
155
|
-
for (const vehEnt of world.query(VehicleTrait)) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
targetEnt = vehEnt;
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
183
|
+
for (const vehEnt of world.query(VehicleTrait)) if (vehEnt.get(VehicleTrait)?.id === vehicleId) {
|
|
184
|
+
targetEnt = vehEnt;
|
|
185
|
+
break;
|
|
161
186
|
}
|
|
162
187
|
if (!targetEnt) return;
|
|
163
188
|
for (const prev of world.query(pilotedVehicleQuery)) if (prev !== targetEnt && prev.has(PilotedTag)) prev.remove(PilotedTag);
|
|
@@ -182,7 +207,7 @@ var kolmoActions = createActions((world) => ({
|
|
|
182
207
|
const curActor = pilot.get(ActorTrait);
|
|
183
208
|
pilot.set(ActorTrait, {
|
|
184
209
|
id: curActor?.id ?? "pilot",
|
|
185
|
-
handle: null,
|
|
210
|
+
handle: curActor?.handle ?? null,
|
|
186
211
|
exitSpawnPos: [
|
|
187
212
|
_exitPos.x,
|
|
188
213
|
_exitPos.y,
|
|
@@ -198,13 +223,7 @@ var kolmoActions = createActions((world) => ({
|
|
|
198
223
|
}
|
|
199
224
|
}
|
|
200
225
|
if (linked.has(PilotedTag)) linked.remove(PilotedTag);
|
|
201
|
-
v?.handle?.setMovement(
|
|
202
|
-
forward: false,
|
|
203
|
-
backward: false,
|
|
204
|
-
steerLeft: false,
|
|
205
|
-
steerRight: false,
|
|
206
|
-
brake: !v.isFlight
|
|
207
|
-
});
|
|
226
|
+
v?.handle?.setMovement(createEmptyVehicleCmd(!v.isFlight));
|
|
208
227
|
}
|
|
209
228
|
for (const extra of world.query(pilotedVehicleQuery)) if (extra.has(PilotedTag)) extra.remove(PilotedTag);
|
|
210
229
|
},
|
|
@@ -228,7 +247,7 @@ var kolmoActions = createActions((world) => ({
|
|
|
228
247
|
break;
|
|
229
248
|
}
|
|
230
249
|
}
|
|
231
|
-
if (target?.handle) flipVehicleBodyUpright(target.handle);
|
|
250
|
+
if (target?.handle) flipVehicleBodyUpright(target.handle, target.jointsHandle);
|
|
232
251
|
}
|
|
233
252
|
}));
|
|
234
253
|
// src/physics/nBodyGravity.ts
|
|
@@ -258,15 +277,43 @@ function resolveAttractorMu(attractor, gravitationalConstant = G_SI) {
|
|
|
258
277
|
epsSq
|
|
259
278
|
};
|
|
260
279
|
}
|
|
280
|
+
function prepareAttractors(attractors, gravitationalConstant = G_SI) {
|
|
281
|
+
const out = [];
|
|
282
|
+
for (let i = 0; i < attractors.length; i++) {
|
|
283
|
+
const a = attractors[i];
|
|
284
|
+
const { mu, epsSq } = resolveAttractorMu(a, gravitationalConstant);
|
|
285
|
+
if (mu > 0) out.push({
|
|
286
|
+
px: a.position[0],
|
|
287
|
+
py: a.position[1],
|
|
288
|
+
pz: a.position[2],
|
|
289
|
+
mu,
|
|
290
|
+
epsSq
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
return out;
|
|
294
|
+
}
|
|
295
|
+
function evaluatePreparedNBodyGravity(pos, prepared, out) {
|
|
296
|
+
let gx = 0, gy = 0, gz = 0;
|
|
297
|
+
for (let i = 0; i < prepared.length; i++) {
|
|
298
|
+
const a = prepared[i];
|
|
299
|
+
const dx = a.px - pos.x;
|
|
300
|
+
const dy = a.py - pos.y;
|
|
301
|
+
const dz = a.pz - pos.z;
|
|
302
|
+
const rSq = dx * dx + dy * dy + dz * dz;
|
|
303
|
+
if (rSq < 1e-12) continue;
|
|
304
|
+
const scale = a.mu / Math.pow(rSq + a.epsSq, 1.5);
|
|
305
|
+
gx += dx * scale;
|
|
306
|
+
gy += dy * scale;
|
|
307
|
+
gz += dz * scale;
|
|
308
|
+
}
|
|
309
|
+
return out.set(gx, gy, gz);
|
|
310
|
+
}
|
|
261
311
|
/**
|
|
262
312
|
* Evaluates softened Newtonian multi-attractor gravitational acceleration (m/s^2):
|
|
263
313
|
* g(x) = sum_i mu_i * (p_i - x) / (|p_i - x|^2 + eps_i^2)^(3/2)
|
|
264
|
-
* Zero artificial floor clamps and zero boundary fences.
|
|
265
314
|
*/
|
|
266
315
|
function evaluateNBodyGravity(pos, attractors, out, gravitationalConstant = G_SI) {
|
|
267
|
-
let gx = 0;
|
|
268
|
-
let gy = 0;
|
|
269
|
-
let gz = 0;
|
|
316
|
+
let gx = 0, gy = 0, gz = 0;
|
|
270
317
|
for (let i = 0; i < attractors.length; i++) {
|
|
271
318
|
const a = attractors[i];
|
|
272
319
|
const { mu, epsSq } = resolveAttractorMu(a, gravitationalConstant);
|
|
@@ -276,7 +323,7 @@ function evaluateNBodyGravity(pos, attractors, out, gravitationalConstant = G_SI
|
|
|
276
323
|
const dz = a.position[2] - pos.z;
|
|
277
324
|
const rSq = dx * dx + dy * dy + dz * dz;
|
|
278
325
|
if (rSq < 1e-12) continue;
|
|
279
|
-
const scale = mu
|
|
326
|
+
const scale = mu / Math.pow(rSq + epsSq, 1.5);
|
|
280
327
|
gx += dx * scale;
|
|
281
328
|
gy += dy * scale;
|
|
282
329
|
gz += dz * scale;
|
|
@@ -284,13 +331,9 @@ function evaluateNBodyGravity(pos, attractors, out, gravitationalConstant = G_SI
|
|
|
284
331
|
return out.set(gx, gy, gz);
|
|
285
332
|
}
|
|
286
333
|
function createNBodyGravityField(attractors, gravitationalConstant = G_SI) {
|
|
287
|
-
|
|
334
|
+
const prepared = prepareAttractors(attractors, gravitationalConstant);
|
|
335
|
+
return (pos, out = new THREE.Vector3()) => evaluatePreparedNBodyGravity(pos, prepared, out);
|
|
288
336
|
}
|
|
289
|
-
/**
|
|
290
|
-
* Exact tangential speed v_circ (m/s) for a circular orbit of radius `orbitRadiusM`
|
|
291
|
-
* around a softened point/spherical attractor:
|
|
292
|
-
* v^2 / r = mu * r / (r^2 + eps^2)^(3/2) => v = r * sqrt(mu / (r^2 + eps^2)^(3/2))
|
|
293
|
-
*/
|
|
294
337
|
function computeCircularOrbitSpeed(attractor, orbitRadiusM, gravitationalConstant = G_SI) {
|
|
295
338
|
if (orbitRadiusM <= 0) return 0;
|
|
296
339
|
const { mu, epsSq } = resolveAttractorMu(attractor, gravitationalConstant);
|
|
@@ -299,13 +342,6 @@ function computeCircularOrbitSpeed(attractor, orbitRadiusM, gravitationalConstan
|
|
|
299
342
|
}
|
|
300
343
|
// src/physics/index.tsx
|
|
301
344
|
var KolmoGravityContext = createContext(false);
|
|
302
|
-
function useOptionalKootaWorld() {
|
|
303
|
-
try {
|
|
304
|
-
return useWorld();
|
|
305
|
-
} catch {
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
345
|
function isGravityTuple(g) {
|
|
310
346
|
return Array.isArray(g);
|
|
311
347
|
}
|
|
@@ -315,12 +351,13 @@ function isPointGravity(g) {
|
|
|
315
351
|
function isNBodyGravity(g) {
|
|
316
352
|
return typeof g === "object" && !Array.isArray(g) && "kind" in g && g.kind === "nbody";
|
|
317
353
|
}
|
|
318
|
-
var
|
|
354
|
+
var DEFAULT_GRAVITY_FN = () => new THREE.Vector3(0, -9.81, 0);
|
|
319
355
|
function KolmoPhysics({ gravity = "planar", paused = false, timeScale = 1, maxDelta, physicsDebug = false, world = null, children, ...physicsProps }) {
|
|
320
356
|
const outerWorld = useOptionalKootaWorld();
|
|
321
357
|
const resolvedWorld = world ?? outerWorld ?? kolmoWorld;
|
|
322
358
|
const isCallback = typeof gravity === "function";
|
|
323
359
|
const isTuple = isGravityTuple(gravity);
|
|
360
|
+
const isZero = gravity === "zero";
|
|
324
361
|
const isCustomLiteral = gravity === "custom";
|
|
325
362
|
const isPoint = isPointGravity(gravity);
|
|
326
363
|
const isNBody = isNBodyGravity(gravity);
|
|
@@ -333,14 +370,36 @@ function KolmoPhysics({ gravity = "planar", paused = false, timeScale = 1, maxDe
|
|
|
333
370
|
const cz = isPoint ? gravity.center[2] : 0;
|
|
334
371
|
const pointRadius = isPoint ? gravity.radius : 1;
|
|
335
372
|
const pointInverseSq = isPoint ? Boolean(gravity.inverseSquare) : false;
|
|
336
|
-
const surfaceG = isPoint ? gravity.surfaceG :
|
|
373
|
+
const surfaceG = isPoint ? gravity.surfaceG : isZero ? 0 : 9.81;
|
|
337
374
|
const gravityFn = isCallback ? gravity : null;
|
|
338
375
|
const nBodySpec = isNBody ? gravity : null;
|
|
376
|
+
const preparedAttractors = useMemo(() => {
|
|
377
|
+
if (nBodySpec) return prepareAttractors(nBodySpec.attractors, nBodySpec.gravitationalConstant);
|
|
378
|
+
if (isPoint && pointInverseSq) return prepareAttractors([{
|
|
379
|
+
position: [
|
|
380
|
+
cx,
|
|
381
|
+
cy,
|
|
382
|
+
cz
|
|
383
|
+
],
|
|
384
|
+
surfaceG,
|
|
385
|
+
radius: pointRadius
|
|
386
|
+
}]);
|
|
387
|
+
return [];
|
|
388
|
+
}, [
|
|
389
|
+
nBodySpec,
|
|
390
|
+
isPoint,
|
|
391
|
+
pointInverseSq,
|
|
392
|
+
cx,
|
|
393
|
+
cy,
|
|
394
|
+
cz,
|
|
395
|
+
surfaceG,
|
|
396
|
+
pointRadius
|
|
397
|
+
]);
|
|
339
398
|
const rapierGravity = useMemo(() => isTuple ? [
|
|
340
399
|
gx,
|
|
341
400
|
gy,
|
|
342
401
|
gz
|
|
343
|
-
] : isCustomGravity ||
|
|
402
|
+
] : isCustomGravity || isZero ? [
|
|
344
403
|
0,
|
|
345
404
|
0,
|
|
346
405
|
0
|
|
@@ -354,33 +413,23 @@ function KolmoPhysics({ gravity = "planar", paused = false, timeScale = 1, maxDe
|
|
|
354
413
|
gy,
|
|
355
414
|
gz,
|
|
356
415
|
isCustomGravity,
|
|
357
|
-
|
|
416
|
+
isZero
|
|
358
417
|
]);
|
|
359
418
|
useLayoutEffect(() => {
|
|
360
419
|
if (isCustomLiteral || !isCallback && !isPoint && !isNBody) return;
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
else if (isPoint)
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
surfaceG,
|
|
373
|
-
radius: pointRadius
|
|
374
|
-
}];
|
|
375
|
-
setField((pos) => evaluateNBodyGravity(pos, single, _gravTmp));
|
|
376
|
-
} else setField((pos) => {
|
|
377
|
-
_gravTmp.set(pos.x - cx, pos.y - cy, pos.z - cz);
|
|
378
|
-
const lenSq = _gravTmp.lengthSq();
|
|
379
|
-
return lenSq < 1e-8 ? _gravTmp.set(0, -surfaceG, 0) : _gravTmp.multiplyScalar(-surfaceG / Math.sqrt(lenSq));
|
|
380
|
-
});
|
|
381
|
-
}
|
|
420
|
+
const scratch = new THREE.Vector3();
|
|
421
|
+
let installed = null;
|
|
422
|
+
if (gravityFn) installed = (pos) => gravityFn(pos, scratch.set(0, 0, 0));
|
|
423
|
+
else if (nBodySpec || isPoint && pointInverseSq) installed = (pos) => evaluatePreparedNBodyGravity(pos, preparedAttractors, scratch);
|
|
424
|
+
else if (isPoint) installed = (pos) => {
|
|
425
|
+
scratch.set(pos.x - cx, pos.y - cy, pos.z - cz);
|
|
426
|
+
const lenSq = scratch.lengthSq();
|
|
427
|
+
return lenSq < 1e-8 ? scratch.set(0, -surfaceG, 0) : scratch.multiplyScalar(-surfaceG / Math.sqrt(lenSq));
|
|
428
|
+
};
|
|
429
|
+
if (!installed) return;
|
|
430
|
+
useCustomGravity.getState().setGravityField(installed);
|
|
382
431
|
return () => {
|
|
383
|
-
|
|
432
|
+
if (useCustomGravity.getState().gravityField === installed) useCustomGravity.getState().setGravityField(DEFAULT_GRAVITY_FN);
|
|
384
433
|
};
|
|
385
434
|
}, [
|
|
386
435
|
isCustomLiteral,
|
|
@@ -389,10 +438,10 @@ function KolmoPhysics({ gravity = "planar", paused = false, timeScale = 1, maxDe
|
|
|
389
438
|
isNBody,
|
|
390
439
|
gravityFn,
|
|
391
440
|
nBodySpec,
|
|
441
|
+
preparedAttractors,
|
|
392
442
|
cx,
|
|
393
443
|
cy,
|
|
394
444
|
cz,
|
|
395
|
-
pointRadius,
|
|
396
445
|
pointInverseSq,
|
|
397
446
|
surfaceG
|
|
398
447
|
]);
|
|
@@ -411,14 +460,17 @@ function KolmoPhysics({ gravity = "planar", paused = false, timeScale = 1, maxDe
|
|
|
411
460
|
})
|
|
412
461
|
})
|
|
413
462
|
});
|
|
414
|
-
return resolvedWorld !== outerWorld ? /* @__PURE__ */ jsx(
|
|
415
|
-
|
|
416
|
-
children:
|
|
463
|
+
return resolvedWorld !== outerWorld ? /* @__PURE__ */ jsx(KolmoWorldContext.Provider, {
|
|
464
|
+
value: resolvedWorld,
|
|
465
|
+
children: /* @__PURE__ */ jsx(WorldProvider, {
|
|
466
|
+
world: resolvedWorld,
|
|
467
|
+
children: content
|
|
468
|
+
})
|
|
417
469
|
}) : content;
|
|
418
470
|
}
|
|
419
471
|
function useIsKolmoCustomGravity() {
|
|
420
472
|
return useContext(KolmoGravityContext);
|
|
421
473
|
}
|
|
422
|
-
export {
|
|
474
|
+
export { writeEntityKinematics as A, flipVehicleBodyUpright as C, useActiveKolmoWorld as D, pilotedVehicleQuery as E, useOptionalKootaWorld as O, ensureWorldSession as S, kolmoWorld as T, VehicleTelemetryTrait as _, computeCircularOrbitSpeed as a, WorldSessionTrait as b, evaluatePreparedNBodyGravity as c, ActorTrait as d, InteractableTrait as f, TransformTrait as g, PilotedTag as h, G_SI as i, writeVehicleTelemetry as j, vehicleSimQuery as k, prepareAttractors as l, PilotLink as m, KolmoPhysics as n, createNBodyGravityField as o, KolmoWorldContext as p, useIsKolmoCustomGravity as r, evaluateNBodyGravity as s, KolmoGravityContext as t, resolveAttractorMu as u, VehicleTrait as v, kolmoActions as w, createEmptyVehicleCmd as x, VelocityTrait as y };
|
|
423
475
|
|
|
424
|
-
//# sourceMappingURL=physics-
|
|
476
|
+
//# sourceMappingURL=physics-CA1abDCY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"physics-CA1abDCY.js","names":["_jsx"],"sources":["../src/engine/traits.ts","../src/physics/nBodyGravity.ts","../src/physics/index.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport * as THREE from \"three\";\nimport {\n createActions,\n createQuery,\n createWorld,\n getStore,\n relation,\n trait,\n unpackEntity,\n type Entity,\n type World,\n} from \"koota\";\nimport type { EcctrlHandle } from \"@pinkaphant/ecctrl\";\nimport type { EcctrlVehicleHandle, VehicleInput } from \"@pinkaphant/ecctrl/vehicle\";\nimport type { KhrVehicleJointsHandle } from \"@khr3/core/vehicle\";\n\nexport type KolmoControlMode = \"foot\" | \"car\" | \"flight\";\n\nexport interface VehicleTraitData {\n id: string;\n handle: EcctrlVehicleHandle | null;\n jointsHandle?: KhrVehicleJointsHandle | null;\n seatOffset: [number, number, number];\n exitOffset: [number, number, number];\n isFlight: boolean;\n}\n\nexport interface ActorTraitData {\n id: string;\n handle: EcctrlHandle | null;\n exitSpawnPos: [number, number, number] | null;\n exitSpawnYaw: number;\n exitLinVel: [number, number, number] | null;\n}\n\nexport const VehicleTrait = trait((): VehicleTraitData => ({\n id: \"\",\n handle: null,\n jointsHandle: null,\n seatOffset: [0, 0.55, 0],\n exitOffset: [-1.5, 0.45, 0],\n isFlight: false,\n}));\n\nexport const ActorTrait = trait((): ActorTraitData => ({\n id: \"pilot\",\n handle: null,\n exitSpawnPos: null,\n exitSpawnYaw: 0,\n exitLinVel: null,\n}));\n\nexport const TransformTrait = trait({ x: 0, y: 0, z: 0, qx: 0, qy: 0, qz: 0, qw: 1 });\nexport const VelocityTrait = trait({ vx: 0, vy: 0, vz: 0, speedKmh: 0 });\nexport const VehicleTelemetryTrait = trait({ rpm: 0, gear: 1, throttle: 0, boost: 0, slip: 0 });\nexport const InteractableTrait = trait({ id: \"\", radius: 4, kind: \"vehicle\" as \"vehicle\" | \"prop\" });\nexport const PilotedTag = trait();\nexport const PilotLink = relation({ exclusive: true });\nexport const WorldSessionTrait = trait({ nearVehicleId: \"\" });\n\nexport const vehicleSimQuery = createQuery(VehicleTrait, TransformTrait, VelocityTrait, VehicleTelemetryTrait);\nexport const pilotedVehicleQuery = createQuery(VehicleTrait, PilotedTag);\n\nexport const kolmoWorld: World = createWorld(WorldSessionTrait);\nexport const KolmoWorldContext = createContext<World | null>(null);\n\nexport function useOptionalKootaWorld(): World | null {\n return useContext(KolmoWorldContext);\n}\n\nexport function useActiveKolmoWorld(): World {\n return useContext(KolmoWorldContext) ?? kolmoWorld;\n}\n\nexport function ensureWorldSession(w: World): void {\n if (!w.has(WorldSessionTrait))\n w.add(WorldSessionTrait);\n}\n\nexport function createEmptyVehicleCmd(brake = false): VehicleInput {\n return {\n forward: false,\n backward: false,\n steerLeft: false,\n steerRight: false,\n brake,\n throttleUp: false,\n throttleDown: false,\n yawLeft: false,\n yawRight: false,\n pitchForward: false,\n pitchBackward: false,\n rollLeft: false,\n rollRight: false,\n joystickL: { x: 0, y: 0 },\n joystickR: { x: 0, y: 0 },\n };\n}\n\n/** Zero-allocation SoA typed-array writer using Koota's public `unpackEntity` + `getStore`. */\nexport function writeEntityKinematics(\n world: World,\n entity: Entity,\n pos: { readonly x: number; readonly y: number; readonly z: number },\n quat: { readonly x: number; readonly y: number; readonly z: number; readonly w: number },\n linVel: { readonly x: number; readonly y: number; readonly z: number },\n speedKmh: number,\n): void {\n const { entityId } = unpackEntity(entity);\n if (entity.has(TransformTrait)) {\n const xf = getStore(world, TransformTrait);\n xf.x[entityId] = pos.x;\n xf.y[entityId] = pos.y;\n xf.z[entityId] = pos.z;\n xf.qx[entityId] = quat.x;\n xf.qy[entityId] = quat.y;\n xf.qz[entityId] = quat.z;\n xf.qw[entityId] = quat.w;\n }\n if (entity.has(VelocityTrait)) {\n const vl = getStore(world, VelocityTrait);\n vl.vx[entityId] = linVel.x;\n vl.vy[entityId] = linVel.y;\n vl.vz[entityId] = linVel.z;\n vl.speedKmh[entityId] = speedKmh;\n }\n}\n\n/** Zero-allocation SoA typed-array writer for `VehicleTelemetryTrait` inside `useFrame`. */\nexport function writeVehicleTelemetry(\n world: World,\n entity: Entity,\n rpm: number,\n gear: number,\n throttle: number,\n boost: number,\n slip: number,\n): void {\n if (!entity.has(VehicleTelemetryTrait))\n return;\n const { entityId } = unpackEntity(entity);\n const st = getStore(world, VehicleTelemetryTrait);\n st.rpm[entityId] = rpm;\n st.gear[entityId] = gear;\n st.throttle[entityId] = throttle;\n st.boost[entityId] = boost;\n st.slip[entityId] = slip;\n}\n\nconst _exitPos = new THREE.Vector3();\nconst _exitFwd = new THREE.Vector3();\nconst _flipUp = new THREE.Vector3();\nconst _flipFwd = new THREE.Vector3();\nconst _flipRight = new THREE.Vector3();\nconst _flipMat = new THREE.Matrix4();\nconst _flipQuat = new THREE.Quaternion();\n\nexport function flipVehicleBodyUpright(veh: EcctrlVehicleHandle, joints?: KhrVehicleJointsHandle | null): void {\n const body = veh.body;\n if (!body)\n return;\n const pos = body.translation();\n _flipUp.copy(veh.upAxis);\n if (_flipUp.lengthSq() < 1e-6)\n _flipUp.set(0, 1, 0);\n else\n _flipUp.normalize();\n\n _flipFwd.copy(veh.bodyZAxis).projectOnPlane(_flipUp);\n if (_flipFwd.lengthSq() < 1e-6) {\n if (Math.abs(_flipUp.y) < 0.9)\n _flipFwd.set(0, 1, 0).projectOnPlane(_flipUp);\n else\n _flipFwd.set(0, 0, 1).projectOnPlane(_flipUp);\n }\n _flipFwd.normalize();\n _flipRight.crossVectors(_flipUp, _flipFwd).normalize();\n _flipMat.makeBasis(_flipRight, _flipUp, _flipFwd);\n _flipQuat.setFromRotationMatrix(_flipMat);\n\n body.setTranslation({ x: pos.x + _flipUp.x * 1.35, y: pos.y + _flipUp.y * 1.35, z: pos.z + _flipUp.z * 1.35 }, true);\n body.setRotation({ x: _flipQuat.x, y: _flipQuat.y, z: _flipQuat.z, w: _flipQuat.w }, true);\n body.setLinvel({ x: 0, y: 0, z: 0 }, true);\n body.setAngvel({ x: 0, y: 0, z: 0 }, true);\n joints?.syncBodiesToParent();\n}\n\nexport const kolmoActions = createActions((world) => ({\n boardVehicle: (vehicleId: string) => {\n if (!vehicleId)\n return;\n ensureWorldSession(world);\n let targetEnt: Entity | undefined;\n for (const vehEnt of world.query(VehicleTrait)) {\n const v = vehEnt.get(VehicleTrait);\n if (v?.id === vehicleId) {\n targetEnt = vehEnt;\n break;\n }\n }\n if (!targetEnt)\n return;\n\n for (const prev of world.query(pilotedVehicleQuery)) {\n if (prev !== targetEnt && prev.has(PilotedTag))\n prev.remove(PilotedTag);\n }\n if (!targetEnt.has(PilotedTag))\n targetEnt.add(PilotedTag);\n\n const pilot = world.queryFirst(ActorTrait);\n if (pilot)\n pilot.add(PilotLink(targetEnt));\n\n if (world.get(WorldSessionTrait)?.nearVehicleId) {\n world.set(WorldSessionTrait, { nearVehicleId: \"\" });\n }\n },\n exitVehicle: () => {\n ensureWorldSession(world);\n const pilot = world.queryFirst(ActorTrait);\n const linked = pilot?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);\n if (linked) {\n const v = linked.get(VehicleTrait);\n if (pilot) {\n if (pilot.has(PilotLink(linked)))\n pilot.remove(PilotLink(linked));\n if (v?.handle) {\n _exitPos\n .set(v.exitOffset[0], v.exitOffset[1], v.exitOffset[2])\n .applyQuaternion(v.handle.currQuat)\n .add(v.handle.currPos);\n _exitFwd.copy(v.handle.bodyZAxis).projectOnPlane(v.handle.upAxis).normalize();\n const yaw = _exitFwd.lengthSq() > 1e-6 ? Math.atan2(_exitFwd.x, _exitFwd.z) : 0;\n const lv = v.handle.currLinVel;\n const curActor = pilot.get(ActorTrait);\n pilot.set(ActorTrait, {\n id: curActor?.id ?? \"pilot\",\n handle: curActor?.handle ?? null,\n exitSpawnPos: [_exitPos.x, _exitPos.y, _exitPos.z],\n exitSpawnYaw: yaw,\n exitLinVel: [lv.x, lv.y, lv.z],\n });\n }\n }\n if (linked.has(PilotedTag))\n linked.remove(PilotedTag);\n v?.handle?.setMovement(createEmptyVehicleCmd(!v.isFlight));\n }\n for (const extra of world.query(pilotedVehicleQuery)) {\n if (extra.has(PilotedTag))\n extra.remove(PilotedTag);\n }\n },\n resetVehicle: (vehicleId?: string) => {\n let target: VehicleTraitData | undefined;\n if (vehicleId) {\n for (const ent of world.query(VehicleTrait)) {\n const v = ent.get(VehicleTrait);\n if (v?.id === vehicleId && v.handle?.body) {\n target = v;\n break;\n }\n }\n }\n if (!target) {\n const piloted = world.queryFirst(ActorTrait)?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);\n const pv = piloted?.get(VehicleTrait);\n if (pv?.handle?.body)\n target = pv;\n }\n if (!target) {\n for (const ent of world.query(VehicleTrait)) {\n const v = ent.get(VehicleTrait);\n if (v?.handle?.body) {\n target = v;\n break;\n }\n }\n }\n if (target?.handle)\n flipVehicleBodyUpright(target.handle, target.jointsHandle);\n },\n}));\n","import * as THREE from \"three\";\n\n/** CODATA Newtonian gravitational constant in SI units (m^3 kg^-1 s^-2). */\nexport const G_SI = 6.6743e-11;\n\nexport interface KolmoGravityAttractor {\n readonly id?: string;\n readonly position: readonly [number, number, number];\n /** Direct standard gravitational parameter mu = G * M (m^3 / s^2). */\n readonly mu?: number;\n /** Mass in kilograms (used with `gravitationalConstant`, defaults to `G_SI`). */\n readonly massKg?: number;\n /** Surface gravity (m/s^2) paired with `radius` (m) -> mu = surfaceG * (radius^2 + softeningM^2)^(3/2) / radius. */\n readonly surfaceG?: number;\n readonly radius?: number;\n /** Plummer softening length epsilon (m) preventing r -> 0 singularities. */\n readonly softeningM?: number;\n}\n\nexport interface KolmoNBodyGravity {\n readonly kind: \"nbody\";\n readonly attractors: readonly KolmoGravityAttractor[];\n readonly gravitationalConstant?: number;\n}\n\nexport interface PreparedGravityAttractor {\n readonly px: number;\n readonly py: number;\n readonly pz: number;\n readonly mu: number;\n readonly epsSq: number;\n}\n\nexport function resolveAttractorMu(\n attractor: KolmoGravityAttractor,\n gravitationalConstant = G_SI,\n): { mu: number; epsSq: number } {\n const rRef = Math.max(0, attractor.radius ?? 0);\n const eps = Math.max(1e-4, attractor.softeningM ?? (rRef > 0 ? rRef * 0.05 : 0.5));\n const epsSq = eps * eps;\n if (typeof attractor.mu === \"number\" && Number.isFinite(attractor.mu)) {\n return { mu: Math.max(0, attractor.mu), epsSq };\n }\n if (typeof attractor.surfaceG === \"number\" && Number.isFinite(attractor.surfaceG) && rRef > 0) {\n const denom = Math.pow(rRef * rRef + epsSq, 1.5);\n return { mu: Math.max(0, (attractor.surfaceG * denom) / rRef), epsSq };\n }\n if (typeof attractor.massKg === \"number\" && Number.isFinite(attractor.massKg)) {\n return { mu: Math.max(0, attractor.massKg * gravitationalConstant), epsSq };\n }\n return { mu: 0, epsSq };\n}\n\nexport function prepareAttractors(\n attractors: readonly KolmoGravityAttractor[],\n gravitationalConstant = G_SI,\n): PreparedGravityAttractor[] {\n const out: PreparedGravityAttractor[] = [];\n for (let i = 0; i < attractors.length; i++) {\n const a = attractors[i];\n const { mu, epsSq } = resolveAttractorMu(a, gravitationalConstant);\n if (mu > 0) {\n out.push({ px: a.position[0], py: a.position[1], pz: a.position[2], mu, epsSq });\n }\n }\n return out;\n}\n\nexport function evaluatePreparedNBodyGravity(\n pos: { readonly x: number; readonly y: number; readonly z: number },\n prepared: readonly PreparedGravityAttractor[],\n out: THREE.Vector3,\n): THREE.Vector3 {\n let gx = 0, gy = 0, gz = 0;\n for (let i = 0; i < prepared.length; i++) {\n const a = prepared[i];\n const dx = a.px - pos.x;\n const dy = a.py - pos.y;\n const dz = a.pz - pos.z;\n const rSq = dx * dx + dy * dy + dz * dz;\n if (rSq < 1e-12)\n continue;\n const scale = a.mu / Math.pow(rSq + a.epsSq, 1.5);\n gx += dx * scale;\n gy += dy * scale;\n gz += dz * scale;\n }\n return out.set(gx, gy, gz);\n}\n\n/**\n * Evaluates softened Newtonian multi-attractor gravitational acceleration (m/s^2):\n * g(x) = sum_i mu_i * (p_i - x) / (|p_i - x|^2 + eps_i^2)^(3/2)\n */\nexport function evaluateNBodyGravity(\n pos: { readonly x: number; readonly y: number; readonly z: number },\n attractors: readonly KolmoGravityAttractor[],\n out: THREE.Vector3,\n gravitationalConstant = G_SI,\n): THREE.Vector3 {\n let gx = 0, gy = 0, gz = 0;\n for (let i = 0; i < attractors.length; i++) {\n const a = attractors[i];\n const { mu, epsSq } = resolveAttractorMu(a, gravitationalConstant);\n if (mu <= 0)\n continue;\n const dx = a.position[0] - pos.x;\n const dy = a.position[1] - pos.y;\n const dz = a.position[2] - pos.z;\n const rSq = dx * dx + dy * dy + dz * dz;\n if (rSq < 1e-12)\n continue;\n const scale = mu / Math.pow(rSq + epsSq, 1.5);\n gx += dx * scale;\n gy += dy * scale;\n gz += dz * scale;\n }\n return out.set(gx, gy, gz);\n}\n\nexport function createNBodyGravityField(\n attractors: readonly KolmoGravityAttractor[],\n gravitationalConstant = G_SI,\n): (pos: THREE.Vector3, out?: THREE.Vector3) => THREE.Vector3 {\n const prepared = prepareAttractors(attractors, gravitationalConstant);\n return (pos, out = new THREE.Vector3()) => evaluatePreparedNBodyGravity(pos, prepared, out);\n}\n\nexport function computeCircularOrbitSpeed(\n attractor: KolmoGravityAttractor,\n orbitRadiusM: number,\n gravitationalConstant = G_SI,\n): number {\n if (orbitRadiusM <= 0)\n return 0;\n const { mu, epsSq } = resolveAttractorMu(attractor, gravitationalConstant);\n if (mu <= 0)\n return 0;\n return orbitRadiusM * Math.sqrt(mu / Math.pow(orbitRadiusM * orbitRadiusM + epsSq, 1.5));\n}\n","import React, { Suspense, createContext, useContext, useLayoutEffect, useMemo, type ReactNode, type RefObject } from \"react\";\nimport * as THREE from \"three\";\nimport { PhysicsWorld, type PhysicsWorldProps } from \"@khr3/core\";\nimport { useCustomGravity } from \"@pinkaphant/ecctrl/gravity\";\nimport { type World } from \"koota\";\nimport { WorldProvider } from \"koota/react\";\nimport { KolmoWorldContext, kolmoWorld, useOptionalKootaWorld } from \"../engine/traits.js\";\nimport {\n G_SI,\n computeCircularOrbitSpeed,\n createNBodyGravityField,\n evaluateNBodyGravity,\n evaluatePreparedNBodyGravity,\n prepareAttractors,\n resolveAttractorMu,\n type KolmoGravityAttractor,\n type KolmoNBodyGravity,\n type PreparedGravityAttractor,\n} from \"./nBodyGravity.js\";\n\nexport {\n G_SI,\n computeCircularOrbitSpeed,\n createNBodyGravityField,\n evaluateNBodyGravity,\n evaluatePreparedNBodyGravity,\n prepareAttractors,\n resolveAttractorMu,\n useOptionalKootaWorld,\n type KolmoGravityAttractor,\n type KolmoNBodyGravity,\n type PreparedGravityAttractor,\n};\n\nexport type KolmoTimeControlValue = number | RefObject<number>;\n\nexport type KolmoPointGravity = {\n readonly kind: \"point\";\n readonly center: readonly [number, number, number];\n readonly surfaceG: number;\n readonly radius: number;\n readonly inverseSquare?: boolean;\n};\n\nexport type KolmoGravityCallback = (pos: THREE.Vector3, out: THREE.Vector3) => THREE.Vector3;\n\nexport type KolmoGravitySpec =\n | \"planar\"\n | \"zero\"\n | \"custom\"\n | readonly [number, number, number]\n | KolmoPointGravity\n | KolmoNBodyGravity\n | KolmoGravityCallback;\n\nexport const KolmoGravityContext = createContext<boolean>(false);\n\nfunction isGravityTuple(g: KolmoGravitySpec): g is readonly [number, number, number] {\n return Array.isArray(g);\n}\n\nfunction isPointGravity(g: KolmoGravitySpec): g is KolmoPointGravity {\n return typeof g === \"object\" && !Array.isArray(g) && \"kind\" in g && g.kind === \"point\";\n}\n\nfunction isNBodyGravity(g: KolmoGravitySpec): g is KolmoNBodyGravity {\n return typeof g === \"object\" && !Array.isArray(g) && \"kind\" in g && g.kind === \"nbody\";\n}\n\nconst DEFAULT_GRAVITY_FN = (): THREE.Vector3 => new THREE.Vector3(0, -9.81, 0);\n\nexport interface KolmoPhysicsProps extends Omit<PhysicsWorldProps, \"gravity\" | \"debug\" | \"timeScale\" | \"maxDelta\" | \"children\"> {\n readonly gravity?: KolmoGravitySpec;\n readonly paused?: boolean;\n readonly timeScale?: KolmoTimeControlValue;\n readonly maxDelta?: KolmoTimeControlValue;\n readonly physicsDebug?: boolean;\n readonly world?: World | null;\n readonly children: ReactNode;\n}\n\nexport function KolmoPhysics({\n gravity = \"planar\",\n paused = false,\n timeScale = 1,\n maxDelta,\n physicsDebug = false,\n world = null,\n children,\n ...physicsProps\n}: KolmoPhysicsProps): React.JSX.Element {\n const outerWorld = useOptionalKootaWorld();\n const resolvedWorld = world ?? outerWorld ?? kolmoWorld;\n const isCallback = typeof gravity === \"function\";\n const isTuple = isGravityTuple(gravity);\n const isZero = gravity === \"zero\";\n const isCustomLiteral = gravity === \"custom\";\n const isPoint = isPointGravity(gravity);\n const isNBody = isNBodyGravity(gravity);\n const isCustomGravity = isCallback || isPoint || isNBody || isCustomLiteral;\n\n const gx = isTuple ? gravity[0] : 0;\n const gy = isTuple ? gravity[1] : -9.81;\n const gz = isTuple ? gravity[2] : 0;\n const cx = isPoint ? gravity.center[0] : 0;\n const cy = isPoint ? gravity.center[1] : 0;\n const cz = isPoint ? gravity.center[2] : 0;\n const pointRadius = isPoint ? gravity.radius : 1;\n const pointInverseSq = isPoint ? Boolean(gravity.inverseSquare) : false;\n const surfaceG = isPoint ? gravity.surfaceG : isZero ? 0 : 9.81;\n const gravityFn = isCallback ? gravity : null;\n const nBodySpec = isNBody ? gravity : null;\n\n const preparedAttractors = useMemo<readonly PreparedGravityAttractor[]>(() => {\n if (nBodySpec)\n return prepareAttractors(nBodySpec.attractors, nBodySpec.gravitationalConstant);\n if (isPoint && pointInverseSq)\n return prepareAttractors([{ position: [cx, cy, cz], surfaceG, radius: pointRadius }]);\n return [];\n }, [nBodySpec, isPoint, pointInverseSq, cx, cy, cz, surfaceG, pointRadius]);\n\n const rapierGravity = useMemo<[number, number, number]>(\n () => (isTuple ? [gx, gy, gz] : isCustomGravity || isZero ? [0, 0, 0] : [0, -9.81, 0]),\n [isTuple, gx, gy, gz, isCustomGravity, isZero],\n );\n\n useLayoutEffect(() => {\n if (isCustomLiteral || (!isCallback && !isPoint && !isNBody))\n return;\n const scratch = new THREE.Vector3();\n let installed: ((pos: THREE.Vector3) => THREE.Vector3) | null = null;\n if (gravityFn) {\n installed = (pos: THREE.Vector3) => gravityFn(pos, scratch.set(0, 0, 0));\n }\n else if (nBodySpec || (isPoint && pointInverseSq)) {\n installed = (pos: THREE.Vector3) => evaluatePreparedNBodyGravity(pos, preparedAttractors, scratch);\n }\n else if (isPoint) {\n installed = (pos: THREE.Vector3) => {\n scratch.set(pos.x - cx, pos.y - cy, pos.z - cz);\n const lenSq = scratch.lengthSq();\n return lenSq < 1e-8 ? scratch.set(0, -surfaceG, 0) : scratch.multiplyScalar(-surfaceG / Math.sqrt(lenSq));\n };\n }\n if (!installed)\n return;\n useCustomGravity.getState().setGravityField(installed);\n return () => {\n if (useCustomGravity.getState().gravityField === installed) {\n useCustomGravity.getState().setGravityField(DEFAULT_GRAVITY_FN);\n }\n };\n }, [isCustomLiteral, isCallback, isPoint, isNBody, gravityFn, nBodySpec, preparedAttractors, cx, cy, cz, pointInverseSq, surfaceG]);\n\n const content = (\n <KolmoGravityContext.Provider value={isCustomGravity}>\n <PhysicsWorld\n {...physicsProps}\n paused={paused}\n timeScale={timeScale}\n {...(maxDelta === undefined ? {} : { maxDelta })}\n gravity={rapierGravity}\n debug={physicsDebug}\n >\n <Suspense fallback={null}>{children}</Suspense>\n </PhysicsWorld>\n </KolmoGravityContext.Provider>\n );\n\n return resolvedWorld !== outerWorld ? (\n <KolmoWorldContext.Provider value={resolvedWorld}>\n <WorldProvider world={resolvedWorld}>{content}</WorldProvider>\n </KolmoWorldContext.Provider>\n ) : (\n content\n );\n}\n\nexport function useIsKolmoCustomGravity(): boolean {\n return useContext(KolmoGravityContext);\n}\n"],"mappings":";;;;;;;;AAoCA,IAAa,eAAe,aAA+B;CACvD,IAAI;CACJ,QAAQ;CACR,cAAc;CACd,YAAY;EAAC;EAAG;EAAM;CAAC;CACvB,YAAY;EAAC;EAAM;EAAM;CAAC;CAC1B,UAAU;AACd,EAAE;AAEF,IAAa,aAAa,aAA6B;CACnD,IAAI;CACJ,QAAQ;CACR,cAAc;CACd,cAAc;CACd,YAAY;AAChB,EAAE;AAEF,IAAa,iBAAiB,MAAM;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,IAAI;CAAG,IAAI;CAAG,IAAI;CAAG,IAAI;AAAE,CAAC;AACpF,IAAa,gBAAgB,MAAM;CAAE,IAAI;CAAG,IAAI;CAAG,IAAI;CAAG,UAAU;AAAE,CAAC;AACvE,IAAa,wBAAwB,MAAM;CAAE,KAAK;CAAG,MAAM;CAAG,UAAU;CAAG,OAAO;CAAG,MAAM;AAAE,CAAC;AAC9F,IAAa,oBAAoB,MAAM;CAAE,IAAI;CAAI,QAAQ;CAAG,MAAM;AAAgC,CAAC;AACnG,IAAa,aAAa,MAAM;AAChC,IAAa,YAAY,SAAS,EAAE,WAAW,KAAK,CAAC;AACrD,IAAa,oBAAoB,MAAM,EAAE,eAAe,GAAG,CAAC;AAE5D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,aAAa,QAAuB;GAChC,QAAQ,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;GAC9C,MAAM,QAAQ,QAAQ,SAAS;GAC/B,OAAO,QAAQ,OAAO,QAAQ,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,QAAQ,eAAe,CAAC,WAAW,KAAK,KAAK,KAAK,CAAC;EAC5G;EAEJ,IAAI,CAAC,WACD;EACJ,iBAAiB,SAAS,CAAC,CAAC,gBAAgB,SAAS;EACrD,aAAa;GACT,IAAI,iBAAiB,SAAS,CAAC,CAAC,iBAAiB,WAC7C,iBAAiB,SAAS,CAAC,CAAC,gBAAgB,kBAAkB;EAEtE;CACJ,GAAG;EAAC;EAAiB;EAAY;EAAS;EAAS;EAAW;EAAW;EAAoB;EAAI;EAAI;EAAI;EAAgB;CAAQ,CAAC;CAElI,MAAM,UACFA,oBAAC,oBAAoB,UAArB;EAA8B,OAAO;EACjC,UAAAA,oBAAC,cAAD;GACI,GAAI;GACI;GACG;GACX,GAAK,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS;GAC9C,SAAS;GACT,OAAO;GAEP,UAAAA,oBAAC,UAAD;IAAU,UAAU;IAAO;GAAmB,CAAA;EACpC,CAAA;CACY,CAAA;CAGlC,OAAO,kBAAkB,aACrBA,oBAAC,kBAAkB,UAAnB;EAA4B,OAAO;EAC/B,UAAAA,oBAAC,eAAD;GAAe,OAAO;GAAgB,UAAA;EAAuB,CAAA;CACrC,CAAA,IAE5B;AAER;AAEA,SAAgB,0BAAmC;CAC/C,OAAO,WAAW,mBAAmB;AACzC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
import type { EcctrlHandle } from "@pinkaphant/ecctrl";
|
|
4
|
+
import { type KhrAssetBundle } from "@khr3/core";
|
|
5
|
+
import { type ArmedToolgunAsset, type ToolgunActionOutcome } from "./store.js";
|
|
6
|
+
export interface MeasuredToolgunViewmodel {
|
|
7
|
+
readonly scene: THREE.Object3D;
|
|
8
|
+
readonly gripOffset: [number, number, number];
|
|
9
|
+
readonly muzzleLocal: [number, number, number];
|
|
10
|
+
readonly screenPos: [number, number, number];
|
|
11
|
+
readonly screenQuat: [number, number, number, number];
|
|
12
|
+
readonly screenSize: [number, number];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Measures grip, muzzle, and LCD bezel sockets on an already-cloned viewmodel scene without duplicating it.
|
|
16
|
+
* Offsets the LCD quad 1mm along `screen_rect`'s local +Z normal in root space so arbitrary bezel orientations never z-fight.
|
|
17
|
+
*/
|
|
18
|
+
export declare function measureToolgunViewmodel(clonedScene: THREE.Object3D): MeasuredToolgunViewmodel;
|
|
19
|
+
export interface KolmoToolgunHandle {
|
|
20
|
+
fire: (shiftKey?: boolean) => ToolgunActionOutcome;
|
|
21
|
+
undo: () => string;
|
|
22
|
+
}
|
|
23
|
+
export interface KolmoToolgunProps {
|
|
24
|
+
readonly ref?: React.Ref<KolmoToolgunHandle>;
|
|
25
|
+
readonly src?: string;
|
|
26
|
+
readonly bundle?: KhrAssetBundle | null;
|
|
27
|
+
readonly actorRef?: React.RefObject<EcctrlHandle | null>;
|
|
28
|
+
readonly accentColor?: string;
|
|
29
|
+
readonly defaultArmedAsset?: ArmedToolgunAsset | null;
|
|
30
|
+
readonly maxRangeM?: number;
|
|
31
|
+
readonly hipOffset?: readonly [number, number, number];
|
|
32
|
+
readonly zoomOffset?: readonly [number, number, number];
|
|
33
|
+
readonly enableShortcuts?: boolean;
|
|
34
|
+
readonly mountWorldOutlets?: boolean;
|
|
35
|
+
readonly enable?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare function KolmoToolgun({ src, bundle, ...rest }: KolmoToolgunProps): React.JSX.Element | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
import { type PieceKind, type PlacedPiece } from "@khr3/c12";
|
|
4
|
+
import type { BuildSnapCandidate } from "./store.js";
|
|
5
|
+
export declare const WALL_THICK = 0.2;
|
|
6
|
+
export declare const SLAB_THICK = 0.2;
|
|
7
|
+
interface SharedC12Resources {
|
|
8
|
+
readonly slabGeo: THREE.BoxGeometry;
|
|
9
|
+
readonly wallGeo: THREE.BoxGeometry;
|
|
10
|
+
readonly jambGeo: THREE.BoxGeometry;
|
|
11
|
+
readonly lintelGeo: THREE.BoxGeometry;
|
|
12
|
+
readonly rampGeo: THREE.BoxGeometry;
|
|
13
|
+
readonly triGroundGeo: THREE.BufferGeometry;
|
|
14
|
+
readonly triUpperGeo: THREE.BufferGeometry;
|
|
15
|
+
readonly triGroundVerts: Float32Array;
|
|
16
|
+
readonly triUpperVerts: Float32Array;
|
|
17
|
+
readonly slabMat: THREE.MeshStandardMaterial;
|
|
18
|
+
readonly roofMat: THREE.MeshStandardMaterial;
|
|
19
|
+
readonly streetMat: THREE.MeshStandardMaterial;
|
|
20
|
+
readonly wallMat: THREE.MeshStandardMaterial;
|
|
21
|
+
readonly stairMat: THREE.MeshStandardMaterial;
|
|
22
|
+
readonly ghostValidMat: THREE.MeshBasicMaterial;
|
|
23
|
+
readonly ghostInvalidMat: THREE.MeshBasicMaterial;
|
|
24
|
+
}
|
|
25
|
+
export declare function getSharedC12Resources(): SharedC12Resources;
|
|
26
|
+
export declare function C12PieceMeshes({ kind, overrideMaterial, }: {
|
|
27
|
+
kind: PieceKind;
|
|
28
|
+
overrideMaterial?: THREE.Material;
|
|
29
|
+
}): React.JSX.Element;
|
|
30
|
+
export declare function C12PieceColliderAndMesh({ piece }: {
|
|
31
|
+
piece: PlacedPiece;
|
|
32
|
+
}): React.JSX.Element;
|
|
33
|
+
export declare function BuildGhostPreview({ candidate }: {
|
|
34
|
+
candidate: BuildSnapCandidate;
|
|
35
|
+
}): React.JSX.Element;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { TOOLGUN_BUILD_KINDS, TOOLGUN_MODES, castToolgunRay, computeAlignedSpawnPose, computeBuildCandidate, createHingeImpulseJoint, createToolgunStore, createWeldImpulseJoint, isSameBuildPreview, rigJointRuntime, useToolgunStore, type ArmedToolgunAsset, type BuildSnapCandidate, type CreatedToolgunJoint, type PendingJointAnchor, type SpawnedToolgunEntity, type ToolgunActionOutcome, type ToolgunBuildKind, type ToolgunHistoryEntry, type ToolgunMode, type ToolgunRaycastResult, type ToolgunStoreState, } from "./store.js";
|
|
2
|
+
export { KolmoToolgun, KolmoToolgun as Toolgun, measureToolgunViewmodel, type KolmoToolgunHandle, type KolmoToolgunProps, type MeasuredToolgunViewmodel, } from "./Toolgun.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as KolmoToolgun, t as Toolgun, r as TOOLGUN_BUILD_KINDS, i as TOOLGUN_MODES, a as castToolgunRay, o as computeAlignedSpawnPose, s as computeBuildCandidate, c as createHingeImpulseJoint, l as createToolgunStore, u as createWeldImpulseJoint, d as isSameBuildPreview, n as measureToolgunViewmodel, f as rigJointRuntime, p as useToolgunStore } from "../toolgun-CFCNO00q.js";
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type RAPIER from "@dimforge/rapier3d-compat";
|
|
2
|
+
import { type StoreApi, type UseBoundStore } from "zustand";
|
|
3
|
+
import { type JointRuntime, type KhrAssetBundle } from "@khr3/core";
|
|
4
|
+
import { type PiecePose, type PlacedPiece } from "@khr3/c12";
|
|
5
|
+
export declare const TOOLGUN_MODES: readonly ["spawn", "weld", "hinge", "rig", "build", "delete"];
|
|
6
|
+
export type ToolgunMode = (typeof TOOLGUN_MODES)[number];
|
|
7
|
+
export declare const TOOLGUN_BUILD_KINDS: readonly ["FoundationSquare", "FoundationTriangle", "Wall", "Doorway", "Floor", "FloorTriangle", "Roof", "RoofTriangle", "Stairs"];
|
|
8
|
+
export type ToolgunBuildKind = (typeof TOOLGUN_BUILD_KINDS)[number];
|
|
9
|
+
export interface ArmedToolgunAsset {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly src?: string;
|
|
13
|
+
readonly bundle?: KhrAssetBundle;
|
|
14
|
+
readonly kind?: "auto" | "vehicle" | "prop";
|
|
15
|
+
readonly fixed?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface SpawnedToolgunEntity {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly kind: "vehicle" | "prop";
|
|
21
|
+
readonly src?: string;
|
|
22
|
+
readonly bundle?: KhrAssetBundle;
|
|
23
|
+
readonly fixed: boolean;
|
|
24
|
+
readonly position: [number, number, number];
|
|
25
|
+
readonly quaternion: [number, number, number, number];
|
|
26
|
+
}
|
|
27
|
+
export interface CreatedToolgunJoint {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly kind: "weld" | "hinge";
|
|
30
|
+
readonly world: RAPIER.World;
|
|
31
|
+
readonly handle: number;
|
|
32
|
+
readonly joint: RAPIER.ImpulseJoint;
|
|
33
|
+
readonly anchorWorld: [number, number, number];
|
|
34
|
+
}
|
|
35
|
+
export interface ToolgunRaycastResult {
|
|
36
|
+
point: [number, number, number];
|
|
37
|
+
normal: [number, number, number];
|
|
38
|
+
toi: number;
|
|
39
|
+
collider: RAPIER.Collider;
|
|
40
|
+
body: RAPIER.RigidBody | null;
|
|
41
|
+
}
|
|
42
|
+
export interface PendingJointAnchor {
|
|
43
|
+
readonly world: RAPIER.World;
|
|
44
|
+
readonly body: RAPIER.RigidBody;
|
|
45
|
+
readonly worldPoint: [number, number, number];
|
|
46
|
+
readonly worldNormal: [number, number, number];
|
|
47
|
+
readonly label: string;
|
|
48
|
+
}
|
|
49
|
+
export interface BuildSnapCandidate {
|
|
50
|
+
readonly kind: ToolgunBuildKind;
|
|
51
|
+
readonly pose: PiecePose;
|
|
52
|
+
readonly position: [number, number, number];
|
|
53
|
+
readonly quaternion: [number, number, number, number];
|
|
54
|
+
readonly snappedSocket: boolean;
|
|
55
|
+
readonly valid: boolean;
|
|
56
|
+
readonly reason: string;
|
|
57
|
+
}
|
|
58
|
+
export type ToolgunHistoryEntry = {
|
|
59
|
+
readonly type: "spawn";
|
|
60
|
+
readonly id: string;
|
|
61
|
+
} | {
|
|
62
|
+
readonly type: "piece";
|
|
63
|
+
readonly id: string;
|
|
64
|
+
} | {
|
|
65
|
+
readonly type: "joint";
|
|
66
|
+
readonly id: string;
|
|
67
|
+
};
|
|
68
|
+
export interface ToolgunActionOutcome {
|
|
69
|
+
readonly ok: boolean;
|
|
70
|
+
readonly status: string;
|
|
71
|
+
readonly beamEnd: [number, number, number];
|
|
72
|
+
}
|
|
73
|
+
type Vec3Input = {
|
|
74
|
+
readonly x: number;
|
|
75
|
+
readonly y: number;
|
|
76
|
+
readonly z: number;
|
|
77
|
+
} | readonly [number, number, number];
|
|
78
|
+
/**
|
|
79
|
+
* Casts a solid ray against Rapier WASM colliders using `QueryFilterFlags.EXCLUDE_SENSORS`,
|
|
80
|
+
* ignoring the optional actor `RigidBody`. Pass `out` on hot `useFrame` paths for zero heap allocations.
|
|
81
|
+
*/
|
|
82
|
+
export declare function castToolgunRay(rapier: typeof RAPIER, world: RAPIER.World, origin: Vec3Input, direction: Vec3Input, maxRange?: number, excludeBody?: RAPIER.RigidBody | null, out?: ToolgunRaycastResult): ToolgunRaycastResult | null;
|
|
83
|
+
/**
|
|
84
|
+
* Aligns a spawned asset's +Y axis to `surfaceNormal` (when sloped <= 55°) composed with exact 30° `yaw12` turn.
|
|
85
|
+
*/
|
|
86
|
+
export declare function computeAlignedSpawnPose(point: readonly [number, number, number], yaw12: number, surfaceNormal?: readonly [number, number, number], clearanceM?: number): {
|
|
87
|
+
position: [number, number, number];
|
|
88
|
+
quaternion: [number, number, number, number];
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Creates a real Rapier WASM Fixed `ImpulseJoint` locking `bodyA` and `bodyB` at their current relative 6-DOF pose.
|
|
92
|
+
*/
|
|
93
|
+
export declare function createWeldImpulseJoint(rapier: typeof RAPIER, world: RAPIER.World, bodyA: RAPIER.RigidBody, bodyB: RAPIER.RigidBody, worldAnchor: readonly [number, number, number]): RAPIER.ImpulseJoint;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a real Rapier WASM Revolute `ImpulseJoint` around `worldAxis` through `worldAnchor`.
|
|
96
|
+
* Aligns `bodyB`'s hinge shaft to `worldAxis` about `worldAnchor` when `bodyB` is tilted off-axis so `t=0` has zero snap error.
|
|
97
|
+
*/
|
|
98
|
+
export declare function createHingeImpulseJoint(rapier: typeof RAPIER, world: RAPIER.World, bodyA: RAPIER.RigidBody, bodyB: RAPIER.RigidBody, worldAnchor: readonly [number, number, number], worldAxis?: readonly [number, number, number]): RAPIER.ImpulseJoint;
|
|
99
|
+
/**
|
|
100
|
+
* Toggles or breaks an articulated `@khr3/core` `JointRuntime`.
|
|
101
|
+
*/
|
|
102
|
+
export declare function rigJointRuntime(rt: JointRuntime, severBreakaway?: boolean): string;
|
|
103
|
+
/**
|
|
104
|
+
* Exact equality check for `BuildSnapCandidate` using `@khr3/c12`'s `poseEq`
|
|
105
|
+
* (avoiding float quaternion sign collisions such as 60° vs 300° where `qy === 0.5`).
|
|
106
|
+
*/
|
|
107
|
+
export declare function isSameBuildPreview(a: BuildSnapCandidate | null, b: BuildSnapCandidate): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Computes the nearest exact `@khr3/c12` socket-snapped or ground-lattice `BuildSnapCandidate` for `kind`.
|
|
110
|
+
*/
|
|
111
|
+
export declare function computeBuildCandidate(placedPieces: readonly PlacedPiece[], aimPoint: readonly [number, number, number], kind: ToolgunBuildKind, yaw12: number, snapRadiusM?: number): BuildSnapCandidate;
|
|
112
|
+
export interface ToolgunStoreState {
|
|
113
|
+
readonly mode: ToolgunMode;
|
|
114
|
+
readonly yaw12: number;
|
|
115
|
+
readonly buildKind: ToolgunBuildKind;
|
|
116
|
+
readonly zoomed: boolean;
|
|
117
|
+
readonly armedAsset: ArmedToolgunAsset | null;
|
|
118
|
+
readonly buildPreview: BuildSnapCandidate | null;
|
|
119
|
+
readonly pendingAnchor: PendingJointAnchor | null;
|
|
120
|
+
readonly spawnedEntities: readonly SpawnedToolgunEntity[];
|
|
121
|
+
readonly placedPieces: readonly PlacedPiece[];
|
|
122
|
+
readonly createdJoints: readonly CreatedToolgunJoint[];
|
|
123
|
+
readonly history: readonly ToolgunHistoryEntry[];
|
|
124
|
+
readonly statusText: string;
|
|
125
|
+
readonly fireCount: number;
|
|
126
|
+
setMode: (mode: ToolgunMode) => void;
|
|
127
|
+
cycleMode: (delta?: number) => void;
|
|
128
|
+
rotateYaw12: (stepsDelta?: number) => void;
|
|
129
|
+
setBuildKind: (kind: ToolgunBuildKind) => void;
|
|
130
|
+
cycleBuildKind: (delta?: number) => void;
|
|
131
|
+
setZoomed: (zoomed: boolean) => void;
|
|
132
|
+
armAsset: (asset: ArmedToolgunAsset | null) => void;
|
|
133
|
+
setBuildPreview: (candidate: BuildSnapCandidate | null) => void;
|
|
134
|
+
setPendingAnchor: (anchor: PendingJointAnchor | null) => void;
|
|
135
|
+
recordSpawn: (entry: SpawnedToolgunEntity) => void;
|
|
136
|
+
placeBuildPiece: (candidate: BuildSnapCandidate) => PlacedPiece | null;
|
|
137
|
+
recordJoint: (entry: CreatedToolgunJoint) => void;
|
|
138
|
+
removeEntityById: (id: string, world?: RAPIER.World | null) => boolean;
|
|
139
|
+
removePieceById: (id: string) => boolean;
|
|
140
|
+
removeJointByBody: (world: RAPIER.World, body: RAPIER.RigidBody) => number;
|
|
141
|
+
clearWorldHandles: (world: RAPIER.World) => void;
|
|
142
|
+
undoLast: (world?: RAPIER.World | null) => string;
|
|
143
|
+
bumpFire: (status: string) => void;
|
|
144
|
+
resetAll: (world?: RAPIER.World | null) => void;
|
|
145
|
+
}
|
|
146
|
+
export declare function createToolgunStore(): UseBoundStore<StoreApi<ToolgunStoreState>>;
|
|
147
|
+
export declare const useToolgunStore: UseBoundStore<StoreApi<ToolgunStoreState>>;
|
|
148
|
+
export {};
|