@pinkaphant/kolmo 0.2.3 → 0.3.0
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/bin/kolmo.mjs +1 -1
- package/dist/engine/kolmoActor.js +125 -83
- package/dist/engine/kolmoLongDrive.js +136 -91
- package/dist/engine/kolmoStore.d.ts +6 -5
- package/dist/engine/kolmoStore.js +115 -79
- package/dist/engine/kolmoVehicle.d.ts +1 -1
- package/dist/engine/kolmoVehicle.js +160 -147
- package/dist/engine/kolmoVehicleDriver.d.ts +12 -4
- package/dist/engine/kolmoVehicleDriver.js +40 -20
- package/dist/engine/kolmoWorld.js +55 -35
- package/dist/importer/CabinPreviewRig.d.ts +13 -0
- package/dist/importer/CabinPreviewRig.js +138 -0
- package/dist/importer/CabinStepSection.d.ts +17 -0
- package/dist/importer/CabinStepSection.js +222 -0
- package/dist/importer/ChopShopPanel.d.ts +31 -1
- package/dist/importer/ChopShopPanel.js +474 -380
- package/dist/importer/GateHudBar.d.ts +3 -0
- package/dist/importer/GateHudBar.js +8 -2
- package/dist/importer/GlbImportGate.js +183 -147
- package/dist/importer/ImporterPlinthUikitTags.d.ts +2 -1
- package/dist/importer/ImporterPlinthUikitTags.js +23 -16
- package/dist/importer/Step1CalibrationPlinth.d.ts +10 -0
- package/dist/importer/Step1CalibrationPlinth.js +203 -141
- package/dist/importer/Step2UniversalPad.d.ts +8 -1
- package/dist/importer/Step2UniversalPad.js +112 -90
- package/dist/importer/cabinMeshBuilders.d.ts +13 -0
- package/dist/importer/cabinMeshBuilders.js +104 -0
- package/dist/importer/cabinMixamoRig.d.ts +53 -0
- package/dist/importer/cabinMixamoRig.js +150 -0
- package/dist/importer/chopShopActions.d.ts +6 -0
- package/dist/importer/chopShopActions.js +86 -61
- package/dist/importer/chopShopUiComponents.d.ts +22 -0
- package/dist/importer/chopShopUiComponents.js +91 -0
- package/dist/importer/gateStore.d.ts +5 -2
- package/dist/importer/gateStore.js +13 -10
- package/dist/importer/glbNormalizer.d.ts +10 -1
- package/dist/importer/glbNormalizer.js +114 -49
- package/dist/importer/importerWebMcp.js +4 -1
- package/dist/importer/index.d.ts +4 -2
- package/dist/importer/index.js +24 -21
- package/dist/importer/khrCompiler.d.ts +20 -1
- package/dist/importer/khrCompiler.js +539 -290
- package/dist/importer/launcherBake.js +12 -8
- package/dist/importer/meshIslands.d.ts +4 -0
- package/dist/importer/meshIslands.js +104 -99
- package/dist/importer/surfaceCutter.d.ts +12 -3
- package/dist/importer/surfaceCutter.js +220 -127
- package/dist/importer/surfaceTopology.d.ts +13 -2
- package/dist/importer/surfaceTopology.js +57 -29
- package/dist/importer/universalGateBake.d.ts +7 -1
- package/dist/importer/universalGateBake.js +63 -60
- package/dist/importer/usdToGlb.js +19 -7
- package/dist/importer/useChopShopController.d.ts +27 -1
- package/dist/importer/useChopShopController.js +369 -255
- package/dist/importer/wheelAxlePairing.d.ts +3 -1
- package/dist/importer/wheelAxlePairing.js +82 -33
- package/dist/index.js +31 -28
- package/dist/junk/ShardPieces.js +3 -3
- package/dist/physics/index.d.ts +7 -0
- package/dist/physics/index.js +66 -40
- package/package.json +1 -1
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { KolmoGravityContext as e } from "../physics/index.js";
|
|
2
|
-
import { KOLMO_EXTENSION_NAME as
|
|
3
|
-
import { createVehiclePanelAnimator as
|
|
4
|
-
import { KolmoEmitterRig as
|
|
5
|
-
import { applySceneRetroMaterials as
|
|
6
|
-
import { useKolmoInput as
|
|
7
|
-
import { InteractableTrait as
|
|
8
|
-
import { stepKolmoVehicleFrame as
|
|
9
|
-
import { useCallback as
|
|
10
|
-
import * as
|
|
11
|
-
import { useFrame as
|
|
12
|
-
import { cloneKhrBundle as
|
|
13
|
-
import { jsx as
|
|
14
|
-
import { useRapier as
|
|
15
|
-
import { KhrVehicle as
|
|
1
|
+
import { KolmoGravityContext as e, KolmoTimeContext as t, isKolmoPhysicsStepping as n } from "../physics/index.js";
|
|
2
|
+
import { KOLMO_EXTENSION_NAME as r, createDefaultSignals as i, decodeKolmoRig as a } from "../schema/kolmoSchema.js";
|
|
3
|
+
import { createVehiclePanelAnimator as o } from "../importer/vehiclePanelAnim.js";
|
|
4
|
+
import { KolmoEmitterRig as s } from "../shaders/plumeAndSparkle.js";
|
|
5
|
+
import { applySceneRetroMaterials as c } from "../shaders/retroShader.js";
|
|
6
|
+
import { useKolmoInput as l } from "./kolmoInput.js";
|
|
7
|
+
import { InteractableTrait as ee, VehicleTrait as u, WorldSessionTrait as d, ensureWorldSession as te, getWorldCameraControls as ne, kolmoActions as f, useActiveKolmoWorld as re, useWorldTrait as ie } from "./kolmoStore.js";
|
|
8
|
+
import { stepKolmoVehicleFrame as ae } from "./kolmoVehicleDriver.js";
|
|
9
|
+
import { useCallback as p, useContext as oe, useEffect as m, useLayoutEffect as h, useMemo as g, useRef as _, useState as v } from "react";
|
|
10
|
+
import * as se from "three";
|
|
11
|
+
import { useFrame as ce } from "@react-three/fiber";
|
|
12
|
+
import { cloneKhrBundle as le, loadKhrGlb as y, useKhrGlb as b } from "@khr3/core";
|
|
13
|
+
import { jsx as x, jsxs as ue } from "react/jsx-runtime";
|
|
14
|
+
import { useRapier as de } from "@react-three/rapier";
|
|
15
|
+
import { KhrVehicle as fe } from "@khr3/core/vehicle";
|
|
16
16
|
// src/engine/kolmoVehicle.tsx
|
|
17
|
-
function
|
|
17
|
+
function pe(e) {
|
|
18
18
|
e.traverse((e) => {
|
|
19
|
-
let
|
|
20
|
-
|
|
19
|
+
let t = e.userData?.gltfExtensions?.[r];
|
|
20
|
+
t && !e.userData.KOLMO_emitter && (e.userData[r] = t);
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function me(e) {
|
|
24
24
|
let t = [];
|
|
25
25
|
for (let n of e) n.traverse((e) => {
|
|
26
26
|
let n = e;
|
|
@@ -34,75 +34,63 @@ function fe(e) {
|
|
|
34
34
|
t.push(e), n.material = e;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
}),
|
|
37
|
+
}), c(n);
|
|
38
38
|
return () => {
|
|
39
39
|
for (let e of t) e.dispose();
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function S({ id: r, sourceBundle: c, rawGlbBytes: m, position: v = [
|
|
43
43
|
0,
|
|
44
44
|
.35,
|
|
45
45
|
0
|
|
46
|
-
], rotation:
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}, [
|
|
51
|
-
let
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
...
|
|
55
|
-
...
|
|
56
|
-
]), [
|
|
57
|
-
let H =
|
|
46
|
+
], rotation: y, piloted: b = !1, flightMode: S = !1, vehicleMode: C, enable: he = !0, ccd: ge, linearDamping: _e, angularDamping: w, userData: T, onCollisionEnter: E, wheelConfig: D, propellerConfig: O, carConfig: k, droneConfig: A, vehicleRef: j, getInput: ve, driver: M, cameraController: N, children: ye }) {
|
|
47
|
+
let be = oe(e), xe = oe(t), P = re();
|
|
48
|
+
h(() => {
|
|
49
|
+
te(P);
|
|
50
|
+
}, [P]);
|
|
51
|
+
let F = ie(P, d), I = l(ve), L = g(() => le(c), [c]), R = g(() => o(L), [L]), z = g(() => (pe(L.scene), a(L.scene, m)), [L, m]);
|
|
52
|
+
h(() => me([
|
|
53
|
+
L.scene,
|
|
54
|
+
...L.wheels.map((e) => e.object),
|
|
55
|
+
...L.propellers.map((e) => e.object)
|
|
56
|
+
]), [L]);
|
|
57
|
+
let B = L.wheels.length > 0, Se = L.propellers.length > 0, V = B && C !== "rocket" && D?.enable !== !1, H = Se && C !== "drive" && O?.enable !== !1 || C === "rocket" || S && !B, U = !!(C === "rocket" || S || H && !V), W = U, G = g(() => z.sockets.find((e) => e.role === "seat" || e.role === "optic")?.localPosition ?? [
|
|
58
58
|
0,
|
|
59
59
|
.65,
|
|
60
60
|
0
|
|
61
|
-
], [
|
|
61
|
+
], [z]), K = g(() => z.sockets.find((e) => e.role === "exit")?.localPosition ?? [
|
|
62
62
|
-1.55,
|
|
63
63
|
.45,
|
|
64
64
|
0
|
|
65
|
-
], [
|
|
66
|
-
if (
|
|
65
|
+
], [z]), q = g(() => {
|
|
66
|
+
if (D || C !== void 0) return {
|
|
67
67
|
...C === void 0 ? {} : { enable: C === "drive" },
|
|
68
|
-
...
|
|
68
|
+
...D ?? {}
|
|
69
69
|
};
|
|
70
|
-
}, [
|
|
71
|
-
if (
|
|
70
|
+
}, [D, C]), Ce = g(() => {
|
|
71
|
+
if (O || C !== void 0) return {
|
|
72
72
|
...C === void 0 ? {} : { enable: C === "rocket" },
|
|
73
|
-
...
|
|
73
|
+
...O ?? {}
|
|
74
74
|
};
|
|
75
|
-
}, [
|
|
76
|
-
controlMode: "VELOCITY",
|
|
77
|
-
maxHorizSpeed: 46,
|
|
78
|
-
maxVertSpeed: 16,
|
|
79
|
-
maxYawRate: 2.3,
|
|
80
|
-
maxTiltAngle: .52,
|
|
81
|
-
HORIZ_VEL_P: 1.8,
|
|
82
|
-
VERT_VEL_P: 2.8,
|
|
83
|
-
...z.droneTune ?? {},
|
|
84
|
-
...M ?? {}
|
|
85
|
-
} : M, [
|
|
86
|
-
H,
|
|
87
|
-
z.droneTune,
|
|
88
|
-
M
|
|
89
|
-
]), J = h(null), _e = h([
|
|
90
|
-
_[0],
|
|
91
|
-
_[1],
|
|
92
|
-
_[2]
|
|
93
|
-
]), Y = h(v ? [
|
|
75
|
+
}, [O, C]), J = _(null), Y = _(null), X = _(!1), we = _([
|
|
94
76
|
v[0],
|
|
95
77
|
v[1],
|
|
96
78
|
v[2]
|
|
97
|
-
]
|
|
79
|
+
]), Te = _(y ? [
|
|
80
|
+
y[0],
|
|
81
|
+
y[1],
|
|
82
|
+
y[2]
|
|
83
|
+
] : void 0), Z = _(i()), Q = _(new se.Vector3()), Ee = _({
|
|
98
84
|
camInit: !1,
|
|
85
|
+
hadCamCtrl: !1,
|
|
99
86
|
cockpit: !1,
|
|
87
|
+
wasPiloted: !1,
|
|
100
88
|
prevCam: !1,
|
|
101
89
|
prevL: !1,
|
|
102
90
|
prevR: !1,
|
|
103
91
|
turnL: !1,
|
|
104
92
|
turnR: !1
|
|
105
|
-
}),
|
|
93
|
+
}), De = _({
|
|
106
94
|
forward: !1,
|
|
107
95
|
backward: !1,
|
|
108
96
|
steerLeft: !1,
|
|
@@ -116,119 +104,144 @@ function x({ id: t, sourceBundle: o, rawGlbBytes: g, position: _ = [
|
|
|
116
104
|
pitchBackward: !1,
|
|
117
105
|
rollLeft: !1,
|
|
118
106
|
rollRight: !1
|
|
119
|
-
}),
|
|
120
|
-
|
|
107
|
+
}), Oe = _(null), $ = p((e, t) => {
|
|
108
|
+
Q.current.x -= e, Q.current.z -= t;
|
|
121
109
|
let n = J.current;
|
|
122
110
|
if (n) {
|
|
123
|
-
n.currPos.x -= e, n.currPos.z -= t;
|
|
111
|
+
n.currPos.x -= e, n.currPos.z -= t, n.targetPos.x -= e, n.targetPos.z -= t;
|
|
124
112
|
for (let r of n.wheelsInfo.values()) {
|
|
125
113
|
let n = r.current;
|
|
126
114
|
n.rayPos.x -= e, n.rayPos.z -= t, n.supPos.x -= e, n.supPos.z -= t, n.rayHitPos.x -= e, n.rayHitPos.z -= t;
|
|
127
115
|
}
|
|
116
|
+
for (let r of n.propellersInfo.values()) {
|
|
117
|
+
let n = r.current;
|
|
118
|
+
n.worldThrustPos.x -= e, n.worldThrustPos.z -= t;
|
|
119
|
+
}
|
|
128
120
|
}
|
|
129
121
|
}, []);
|
|
130
|
-
|
|
131
|
-
let e =
|
|
132
|
-
id:
|
|
122
|
+
h(() => {
|
|
123
|
+
let e = P.spawn(u({
|
|
124
|
+
id: r,
|
|
133
125
|
handle: J.current,
|
|
134
|
-
centerOfMass: [...
|
|
135
|
-
seatOffset:
|
|
136
|
-
exitOffset:
|
|
137
|
-
isFlight:
|
|
138
|
-
onOriginShift:
|
|
139
|
-
}),
|
|
140
|
-
id:
|
|
126
|
+
centerOfMass: [...L.centerOfMass],
|
|
127
|
+
seatOffset: G,
|
|
128
|
+
exitOffset: K,
|
|
129
|
+
isFlight: W,
|
|
130
|
+
onOriginShift: $
|
|
131
|
+
}), ee({
|
|
132
|
+
id: r,
|
|
141
133
|
radius: 4.2,
|
|
142
134
|
kind: "vehicle"
|
|
143
135
|
}));
|
|
144
|
-
return
|
|
145
|
-
|
|
136
|
+
return Y.current = e, () => {
|
|
137
|
+
P.get(d)?.activeVehicleId === r && f(P).exitVehicle(), Y.current = null, X.current = !1, e.destroy();
|
|
146
138
|
};
|
|
139
|
+
}, [P, r]), h(() => {
|
|
140
|
+
let e = Y.current;
|
|
141
|
+
e && e.set(u, {
|
|
142
|
+
id: r,
|
|
143
|
+
handle: J.current,
|
|
144
|
+
centerOfMass: [...L.centerOfMass],
|
|
145
|
+
seatOffset: G,
|
|
146
|
+
exitOffset: K,
|
|
147
|
+
isFlight: W,
|
|
148
|
+
onOriginShift: $
|
|
149
|
+
});
|
|
147
150
|
}, [
|
|
151
|
+
r,
|
|
148
152
|
L,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
U,
|
|
153
|
+
G,
|
|
154
|
+
K,
|
|
152
155
|
W,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
+
$
|
|
157
|
+
]), h(() => {
|
|
158
|
+
b && !X.current && !P.get(d)?.activeVehicleId && f(P).boardVehicle(r), X.current = b;
|
|
159
|
+
}, [
|
|
160
|
+
P,
|
|
161
|
+
r,
|
|
162
|
+
b
|
|
156
163
|
]);
|
|
157
|
-
let
|
|
158
|
-
J.current = e,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
let ke = p((e) => {
|
|
165
|
+
J.current = e, j && (j.current = e);
|
|
166
|
+
let t = Y.current;
|
|
167
|
+
if (t) {
|
|
168
|
+
let n = t.get(u);
|
|
169
|
+
n && t.set(u, {
|
|
170
|
+
...n,
|
|
163
171
|
handle: e,
|
|
164
|
-
onOriginShift:
|
|
172
|
+
onOriginShift: $
|
|
165
173
|
});
|
|
166
174
|
}
|
|
167
|
-
}, [
|
|
168
|
-
|
|
169
|
-
t,
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
175
|
+
}, [j, $]), { world: Ae } = de(), je = F ? F.activeVehicleId === r : b;
|
|
176
|
+
return ce((e, t) => {
|
|
177
|
+
let i = n(xe), a = Math.min(Math.max(t, 1e-4), 1 / 30), o = i ? Ae.timestep > 0 ? Ae.timestep : a : 0;
|
|
178
|
+
o > 0 && R.step(o);
|
|
179
|
+
let s = J.current;
|
|
180
|
+
if (!s || !s.body) return;
|
|
181
|
+
if (M) {
|
|
182
|
+
M(s, o > 0 ? o : a, e), N && N(s, a, e);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
let c = ne(P), l = Oe.current;
|
|
186
|
+
l ? (l.id = r, l.veh = s, l.keys = I(), l.centerOfMass = L.centerOfMass, l.seatOffset = G, l.isPiloted = je, l.driveEnabled = V, l.flightEnabled = H, l.flightPriority = U, l.simStepping = i, l.camDt = a, l.state = e, l.camCtrl = c, l.cameraController = N) : (l = {
|
|
187
|
+
id: r,
|
|
188
|
+
veh: s,
|
|
189
|
+
keys: I(),
|
|
190
|
+
cmd: De.current,
|
|
191
|
+
sig: Z.current,
|
|
192
|
+
st: Ee.current,
|
|
193
|
+
camTarget: Q.current,
|
|
194
|
+
centerOfMass: L.centerOfMass,
|
|
195
|
+
seatOffset: G,
|
|
196
|
+
isPiloted: je,
|
|
197
|
+
driveEnabled: V,
|
|
198
|
+
flightEnabled: H,
|
|
199
|
+
flightPriority: U,
|
|
200
|
+
simStepping: i,
|
|
201
|
+
camDt: a,
|
|
190
202
|
state: e,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
203
|
+
camCtrl: c,
|
|
204
|
+
cameraController: N
|
|
205
|
+
}, Oe.current = l), ae(l);
|
|
206
|
+
}), /* @__PURE__ */ x("group", {
|
|
194
207
|
onClick: (e) => {
|
|
195
|
-
e.delta <= 5 &&
|
|
208
|
+
e.delta <= 5 && R.toggleHitObject(e.object) && e.stopPropagation();
|
|
196
209
|
},
|
|
197
|
-
children: /* @__PURE__ */
|
|
198
|
-
ref:
|
|
199
|
-
bundle:
|
|
200
|
-
position:
|
|
201
|
-
enable:
|
|
202
|
-
enableCustomGravity:
|
|
203
|
-
...
|
|
204
|
-
...
|
|
205
|
-
...
|
|
206
|
-
...
|
|
207
|
-
...
|
|
208
|
-
...
|
|
209
|
-
...
|
|
210
|
-
...
|
|
211
|
-
...
|
|
212
|
-
...
|
|
213
|
-
children: [/* @__PURE__ */
|
|
214
|
-
emitters:
|
|
215
|
-
signalsRef:
|
|
216
|
-
}),
|
|
210
|
+
children: /* @__PURE__ */ ue(fe, {
|
|
211
|
+
ref: ke,
|
|
212
|
+
bundle: L,
|
|
213
|
+
position: we.current,
|
|
214
|
+
enable: he,
|
|
215
|
+
enableCustomGravity: be,
|
|
216
|
+
...Te.current === void 0 ? {} : { rotation: Te.current },
|
|
217
|
+
...ge === void 0 ? {} : { ccd: ge },
|
|
218
|
+
..._e === void 0 ? {} : { linearDamping: _e },
|
|
219
|
+
...w === void 0 ? {} : { angularDamping: w },
|
|
220
|
+
...T === void 0 ? {} : { userData: T },
|
|
221
|
+
...E === void 0 ? {} : { onCollisionEnter: E },
|
|
222
|
+
...q === void 0 ? {} : { wheelConfig: q },
|
|
223
|
+
...Ce === void 0 ? {} : { propellerConfig: Ce },
|
|
224
|
+
...k === void 0 ? {} : { carConfig: k },
|
|
225
|
+
...A === void 0 ? {} : { droneConfig: A },
|
|
226
|
+
children: [/* @__PURE__ */ x(s, {
|
|
227
|
+
emitters: z.emitters,
|
|
228
|
+
signalsRef: Z
|
|
229
|
+
}), ye]
|
|
217
230
|
})
|
|
218
231
|
});
|
|
219
232
|
}
|
|
220
|
-
function
|
|
221
|
-
return /* @__PURE__ */
|
|
233
|
+
function C(e) {
|
|
234
|
+
return /* @__PURE__ */ x(S, {
|
|
222
235
|
...e,
|
|
223
|
-
sourceBundle:
|
|
236
|
+
sourceBundle: b(e.src)
|
|
224
237
|
});
|
|
225
238
|
}
|
|
226
|
-
function
|
|
227
|
-
let [t, n] =
|
|
228
|
-
return
|
|
239
|
+
function he(e) {
|
|
240
|
+
let [t, n] = v(null);
|
|
241
|
+
return m(() => {
|
|
229
242
|
if (e.bundle || e.src || !e.rawGlbBytes) return;
|
|
230
243
|
let t = !0;
|
|
231
|
-
return
|
|
244
|
+
return y(e.rawGlbBytes).then((e) => {
|
|
232
245
|
t && n(e);
|
|
233
246
|
}), () => {
|
|
234
247
|
t = !1;
|
|
@@ -237,15 +250,15 @@ function C(e) {
|
|
|
237
250
|
e.bundle,
|
|
238
251
|
e.src,
|
|
239
252
|
e.rawGlbBytes
|
|
240
|
-
]), e.bundle ? /* @__PURE__ */
|
|
253
|
+
]), e.bundle ? /* @__PURE__ */ x(S, {
|
|
241
254
|
...e,
|
|
242
255
|
sourceBundle: e.bundle
|
|
243
|
-
}) : e.src ? /* @__PURE__ */
|
|
256
|
+
}) : e.src ? /* @__PURE__ */ x(C, {
|
|
244
257
|
...e,
|
|
245
258
|
src: e.src
|
|
246
|
-
}) : t ? /* @__PURE__ */
|
|
259
|
+
}) : t ? /* @__PURE__ */ x(S, {
|
|
247
260
|
...e,
|
|
248
261
|
sourceBundle: t
|
|
249
262
|
}) : null;
|
|
250
263
|
}
|
|
251
|
-
export {
|
|
264
|
+
export { he as KolmoVehicle };
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
2
|
import type { RootState } from "@react-three/fiber";
|
|
3
|
+
import type { EcctrlCameraControlsHandle } from "@pinkaphant/ecctrl/camera";
|
|
3
4
|
import type { EcctrlVehicleHandle, VehicleInput } from "@pinkaphant/ecctrl/vehicle";
|
|
4
5
|
import type { KolmoSignalState } from "../schema/kolmoSchema.js";
|
|
5
6
|
import type { KolmoInputState } from "./kolmoInput.js";
|
|
6
7
|
export interface KolmoVehicleFrameState {
|
|
7
8
|
camInit: boolean;
|
|
9
|
+
hadCamCtrl: boolean;
|
|
8
10
|
cockpit: boolean;
|
|
11
|
+
wasPiloted: boolean;
|
|
9
12
|
prevCam: boolean;
|
|
10
13
|
prevL: boolean;
|
|
11
14
|
prevR: boolean;
|
|
12
15
|
turnL: boolean;
|
|
13
16
|
turnR: boolean;
|
|
14
17
|
}
|
|
15
|
-
export
|
|
18
|
+
export interface KolmoVehicleFrameParams {
|
|
16
19
|
id: string;
|
|
17
20
|
veh: EcctrlVehicleHandle;
|
|
18
21
|
keys: Readonly<KolmoInputState>;
|
|
@@ -23,8 +26,13 @@ export declare function stepKolmoVehicleFrame(params: {
|
|
|
23
26
|
centerOfMass: readonly [number, number, number];
|
|
24
27
|
seatOffset: readonly [number, number, number];
|
|
25
28
|
isPiloted: boolean;
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
driveEnabled: boolean;
|
|
30
|
+
flightEnabled: boolean;
|
|
31
|
+
flightPriority: boolean;
|
|
32
|
+
simStepping: boolean;
|
|
33
|
+
camDt: number;
|
|
28
34
|
state: RootState;
|
|
35
|
+
camCtrl: EcctrlCameraControlsHandle | null;
|
|
29
36
|
cameraController?: (veh: EcctrlVehicleHandle, dt: number, state: RootState) => void;
|
|
30
|
-
}
|
|
37
|
+
}
|
|
38
|
+
export declare function stepKolmoVehicleFrame(params: KolmoVehicleFrameParams): void;
|
|
@@ -2,28 +2,48 @@ import { kolmoTelemetry as e } from "./kolmoStore.js";
|
|
|
2
2
|
import * as t from "three";
|
|
3
3
|
import { easing as n } from "maath";
|
|
4
4
|
// src/engine/kolmoVehicleDriver.ts
|
|
5
|
-
var r = new t.Vector3(), i = new t.Vector3(), a = new t.Vector3(), o = new t.Vector3();
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
for (let e of c.propellersInfo.values()) S += e.current.finalThrottle;
|
|
13
|
-
S /= c.propellersInfo.size;
|
|
14
|
-
}
|
|
15
|
-
let C = c.currLinVel.dot(c.bodyZAxis);
|
|
16
|
-
if (d.throttle = g ? _ ? l.forward || l.brake ? 1 : Math.max(.22, S) : +!!l.forward : 0, d.boost = g ? _ ? l.boost ? 1 : l.forward ? .58 : .16 : l.boost && l.forward ? 1 : 0 : 0, d.brake = g && !_ && (l.brake || l.backward && C > 1) ? 1 : 0, d.reverse = g && !_ && l.backward && C <= 1 ? 1 : 0, d.slip = Math.min(1, x), d.turn_l = +!!f.turnL, d.turn_r = +!!f.turnR, d.headlight = 1, d.always = 1, !g) return;
|
|
17
|
-
if (e.speedKmh = c.currLinVel.length() * 3.6, e.rpm = Math.round(_ ? 1800 + d.throttle * 6200 + d.boost * 4200 : c.engineRPM), e.gear = _ ? l.boost ? 2 : 1 : c.gearIndex + 1, e.throttle = d.throttle, e.boost = d.boost, e.mode = _ ? "flight" : "car", e.activeVehicleId = s, b) {
|
|
18
|
-
b(c, v, y);
|
|
5
|
+
var r = new t.Vector3(), i = new t.Vector3(), a = new t.Vector3(), o = new t.Vector3(), s = new t.Vector3(), c = new t.Vector3(), l = new t.Vector3();
|
|
6
|
+
function u(e, t) {
|
|
7
|
+
e.forward = !1, e.backward = !1, e.steerLeft = !1, e.steerRight = !1, e.brake = t, e.throttleUp = !1, e.throttleDown = !1, e.yawLeft = !1, e.yawRight = !1, e.pitchForward = !1, e.pitchBackward = !1, e.rollLeft = !1, e.rollRight = !1;
|
|
8
|
+
}
|
|
9
|
+
function d(e, u, d, f, p, m, h, g, _, v) {
|
|
10
|
+
if (v) {
|
|
11
|
+
_ && _.enabled && (_.enabled = !1), v(e, h, g);
|
|
19
12
|
return;
|
|
20
13
|
}
|
|
21
|
-
if (r.copy(
|
|
22
|
-
a.set(
|
|
14
|
+
if (r.copy(e.upAxis), r.lengthSq() < 1e-6 && r.copy(e.bodyYAxis), r.lengthSq() < 1e-6 ? r.set(0, 1, 0) : r.normalize(), u.cockpit) {
|
|
15
|
+
_ && _.enabled && (_.enabled = !1), a.set(p[0] - f[0], p[1] - f[1] + .32, p[2] - f[2]).applyQuaternion(e.currQuat).add(e.currPos), o.copy(a).addScaledVector(e.bodyZAxis, 24), n.damp3(g.camera.position, a, .04, h), n.damp3(g.camera.up, e.bodyYAxis, .08, h), g.camera.lookAt(o), u.camInit = !1;
|
|
23
16
|
return;
|
|
24
17
|
}
|
|
25
|
-
i.copy(
|
|
26
|
-
let
|
|
27
|
-
a.copy(
|
|
18
|
+
i.copy(e.bodyZAxis), m || i.projectOnPlane(r), i.lengthSq() < 1e-6 && i.copy(e.bodyZAxis), i.lengthSq() < 1e-6 ? i.set(0, 0, 1) : i.normalize();
|
|
19
|
+
let y = m ? 11.2 : 6.8, b = m ? 3.1 : 2.15;
|
|
20
|
+
a.copy(e.currPos).addScaledVector(i, -y).addScaledVector(r, b);
|
|
21
|
+
let x = !!_;
|
|
22
|
+
if (x !== u.hadCamCtrl && (u.hadCamCtrl = x, u.camInit = !1), _) {
|
|
23
|
+
o.copy(e.currPos).addScaledVector(r, m ? .85 : .65);
|
|
24
|
+
let n = !_.enabled;
|
|
25
|
+
if (n && (_.enabled = !0), !u.camInit || n) {
|
|
26
|
+
let e = n || g.camera.position.distanceToSquared(o) > 900;
|
|
27
|
+
g.camera.up.copy(r), _.setUp(g.camera.up), _.setLookAt(a.x, a.y, a.z, o.x, o.y, o.z, !e), u.camInit = !0;
|
|
28
|
+
} else if (_.moveTo(o.x, o.y, o.z, !0), g.camera.up.lerp(r, 1 - Math.exp(-8 * h)), _.setUp(g.camera.up), _.currentAction === 0 && (g.camera.getWorldDirection(s).projectOnPlane(r), c.copy(e.bodyZAxis).projectOnPlane(r), s.lengthSq() > 1e-6 && c.lengthSq() > 1e-6)) {
|
|
29
|
+
s.normalize(), c.normalize(), l.crossVectors(s, c);
|
|
30
|
+
let e = t.MathUtils.clamp(s.dot(c), -1, 1);
|
|
31
|
+
Math.abs(e) < 1e-10 && (e = 0);
|
|
32
|
+
let n = Math.atan2(l.dot(r), e);
|
|
33
|
+
_.rotate(n * Math.min(1, 5 * h), 0, !0);
|
|
34
|
+
}
|
|
35
|
+
} else o.copy(e.currPos).addScaledVector(i, m ? 7.5 : 3.6).addScaledVector(r, .65), u.camInit ||= (g.camera.position.copy(a), d.copy(o), !0), n.damp3(g.camera.position, a, .14, h), n.damp3(d, o, .08, h), n.damp3(g.camera.up, r, .16, h), g.camera.lookAt(d);
|
|
36
|
+
}
|
|
37
|
+
function f(t) {
|
|
38
|
+
let { id: n, veh: r, keys: i, cmd: a, sig: o, st: s, camTarget: c, centerOfMass: l, seatOffset: f, isPiloted: p, driveEnabled: m, flightEnabled: h, flightPriority: g, simStepping: _, camDt: v, state: y, camCtrl: b, cameraController: x } = t;
|
|
39
|
+
p ? (i.cameraView && !s.prevCam && (s.cockpit = !s.cockpit), s.prevCam = i.cameraView, _ && (m ? (h || (i.turnLeft && !s.prevL && (s.turnL = !s.turnL, s.turnR = !1), i.turnRight && !s.prevR && (s.turnR = !s.turnR, s.turnL = !1), s.prevL = i.turnLeft, s.prevR = i.turnRight), a.forward = i.forward, a.backward = i.backward, a.steerLeft = i.left, a.steerRight = i.right, a.brake = !g && i.brake) : (a.forward = !1, a.backward = !1, a.steerLeft = !1, a.steerRight = !1, a.brake = !1), h ? (a.pitchForward = i.forward, a.pitchBackward = i.backward, a.yawLeft = i.left, a.yawRight = i.right, a.rollLeft = i.turnLeft, a.rollRight = i.turnRight, a.throttleUp = g ? i.brake : i.boost, a.throttleDown = i.descend) : (a.pitchForward = !1, a.pitchBackward = !1, a.yawLeft = !1, a.yawRight = !1, a.rollLeft = !1, a.rollRight = !1, a.throttleUp = !1, a.throttleDown = !1), r.setMovement(a)), s.wasPiloted = !0) : s.wasPiloted && (s.wasPiloted = !1, s.camInit = !1, s.cockpit = !1, s.prevCam = !1, b && !b.enabled && (b.enabled = !0), u(a, m && !g), r.setMovement(a));
|
|
40
|
+
let S = 0, C = !1, w = 0;
|
|
41
|
+
for (let e of r.wheelsInfo.values()) e.current.rayHit && (C = !0, e.current.slipStrength > S && (S = e.current.slipStrength));
|
|
42
|
+
if (r.propellersInfo.size > 0) {
|
|
43
|
+
for (let e of r.propellersInfo.values()) w += e.current.finalThrottle;
|
|
44
|
+
w /= r.propellersInfo.size;
|
|
45
|
+
}
|
|
46
|
+
let T = h && (g || !m || !C), E = r.currLinVel.dot(r.bodyZAxis);
|
|
47
|
+
o.throttle = p ? T ? i.forward || i.brake ? 1 : Math.max(.22, w) : +!!i.forward : 0, o.boost = p ? T ? i.boost ? 1 : i.forward ? .58 : .16 : i.boost && i.forward ? 1 : 0 : 0, o.brake = p && m && !g && (i.brake || i.backward && E > 1) ? 1 : 0, o.reverse = p && m && !g && i.backward && E <= 1 ? 1 : 0, o.slip = Math.min(1, S), o.turn_l = +!!s.turnL, o.turn_r = +!!s.turnR, o.headlight = 1, o.always = 1, p && (e.speedKmh = r.currLinVel.length() * 3.6, e.rpm = Math.round(T && !m ? w * 1e4 : r.engineRPM), e.gear = m ? r.gearIndex + 1 : 1, e.throttle = o.throttle, e.boost = o.boost, e.mode = T ? "flight" : "car", e.activeVehicleId = n, d(r, s, c, l, f, T, v, y, b, x));
|
|
28
48
|
}
|
|
29
|
-
export {
|
|
49
|
+
export { f as stepKolmoVehicleFrame };
|