@pinkaphant/kolmo 0.1.1 → 0.1.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/LICENSE +21 -0
- package/README.md +16 -14
- package/bin/kolmo.mjs +19 -54
- package/dist/body/HeldItem.d.ts +22 -0
- package/dist/body/HeldItem.js +171 -0
- package/dist/body/KhrBody.d.ts +26 -0
- package/dist/body/KhrBody.js +179 -0
- package/dist/body/bodySi.d.ts +59 -0
- package/dist/body/bodySi.js +61 -0
- package/dist/body/index.d.ts +3 -0
- package/dist/body/index.js +4 -0
- package/dist/engine/index.d.ts +4 -4
- package/dist/engine/index.js +12 -3
- package/dist/engine/kolmoActor.d.ts +11 -4
- package/dist/engine/kolmoActor.js +197 -0
- package/dist/engine/kolmoInput.d.ts +12 -0
- package/dist/engine/kolmoInput.js +80 -0
- package/dist/engine/kolmoIsland.d.ts +3 -1
- package/dist/engine/kolmoIsland.js +311 -0
- package/dist/engine/kolmoLongDrive.js +223 -0
- package/dist/engine/kolmoRigs.js +59 -0
- package/dist/engine/kolmoStore.d.ts +53 -27
- package/dist/engine/kolmoStore.js +211 -0
- package/dist/engine/kolmoSurface.d.ts +1 -1
- package/dist/engine/kolmoSurface.js +182 -0
- package/dist/engine/kolmoVehicle.d.ts +2 -1
- package/dist/engine/kolmoVehicle.js +244 -0
- package/dist/engine/kolmoVehicleDriver.d.ts +30 -0
- package/dist/engine/kolmoVehicleDriver.js +38 -0
- package/dist/engine/kolmoWorld.d.ts +7 -15
- package/dist/engine/kolmoWorld.js +136 -0
- package/dist/engine/longDriveKit.d.ts +4 -2
- package/dist/engine/longDriveKit.js +254 -0
- package/dist/engine/mainlandMacroCell.d.ts +3 -7
- package/dist/engine/mainlandMacroCell.js +247 -0
- package/dist/engine/shiftedFixedBody.d.ts +13 -0
- package/dist/engine/shiftedFixedBody.js +64 -0
- package/dist/importer/ChopShopPanel.js +465 -0
- package/dist/importer/DomainWorkshopPanel.d.ts +9 -4
- package/dist/importer/DomainWorkshopPanel.js +385 -0
- package/dist/importer/GateHudBar.js +312 -0
- package/dist/importer/GlbImportGate.js +250 -0
- package/dist/importer/ImperativeVehicleRig.js +336 -0
- package/dist/importer/ImporterPlinthUikitTags.js +112 -0
- package/dist/importer/Step1CalibrationPlinth.js +275 -0
- package/dist/importer/Step2UniversalPad.js +244 -0
- package/dist/importer/VfxEmitterPool.js +91 -0
- package/dist/importer/chopShopActions.d.ts +22 -2
- package/dist/importer/chopShopActions.js +232 -0
- package/dist/importer/gateStore.d.ts +1 -1
- package/dist/importer/gateStore.js +92 -0
- package/dist/importer/glbNormalizer.js +133 -0
- package/dist/importer/importerWebMcp.d.ts +17 -6
- package/dist/importer/importerWebMcp.js +343 -0
- package/dist/importer/index.js +22 -3
- package/dist/importer/khrCompiler.d.ts +1 -1
- package/dist/importer/khrCompiler.js +434 -0
- package/dist/importer/launcherBake.js +51 -0
- package/dist/importer/meshIslands.d.ts +1 -1
- package/dist/importer/meshIslands.js +301 -0
- package/dist/importer/surfaceCutter.js +254 -0
- package/dist/importer/surfaceTopology.js +183 -0
- package/dist/importer/universalGateBake.js +162 -0
- package/dist/importer/usdToGlb.js +294 -0
- package/dist/importer/useChopShopController.d.ts +11 -2
- package/dist/importer/useChopShopController.js +364 -0
- package/dist/importer/vehiclePanelAnim.js +214 -0
- package/dist/importer/wheelAxlePairing.d.ts +1 -2
- package/dist/importer/wheelAxlePairing.js +102 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +69 -14
- package/dist/junk/DestructibleTarget.js +154 -0
- package/dist/junk/KolmoJunk.js +65 -0
- package/dist/junk/ShardPieces.d.ts +6 -4
- package/dist/junk/ShardPieces.js +74 -0
- package/dist/junk/TargetDecals.js +51 -0
- package/dist/junk/bvhShatter.js +55 -0
- package/dist/junk/bvhTriCollector.js +78 -0
- package/dist/junk/index.js +11 -1
- package/dist/junk/junkGeometry.js +69 -0
- package/dist/junk/junkImportSanitize.js +54 -0
- package/dist/junk/junkImporter.js +95 -0
- package/dist/junk/junkLabelCanvas.js +67 -0
- package/dist/junk/junkLabels.js +35 -0
- package/dist/junk/targetHelpers.js +103 -0
- package/dist/junk/targetHitLogic.js +128 -0
- package/dist/junk/useTargetAssets.js +102 -0
- package/dist/physics/index.d.ts +26 -0
- package/dist/physics/index.js +84 -0
- package/dist/schema/kolmoSchema.d.ts +2 -1
- package/dist/schema/kolmoSchema.js +184 -0
- package/dist/shaders/celestialBackdrop.d.ts +1 -1
- package/dist/shaders/celestialBackdrop.js +344 -0
- package/dist/shaders/index.d.ts +0 -1
- package/dist/shaders/index.js +9 -1
- package/dist/shaders/plumeAndSparkle.js +271 -0
- package/dist/shaders/ps2GlslShared.d.ts +1 -1
- package/dist/shaders/ps2GlslShared.js +3 -0
- package/dist/shaders/ps2MaterialsTSL.js +65 -0
- package/dist/shaders/ps2MaterialsWebGL.js +40 -0
- package/dist/shaders/ps2RoadWebGL.js +101 -0
- package/dist/shaders/ps2TerrainWebGL.js +54 -0
- package/dist/shaders/ps2Textures.js +224 -0
- package/dist/shaders/retroPalettes.js +188 -0
- package/dist/shaders/retroShader.d.ts +31 -3
- package/dist/shaders/retroShader.js +249 -0
- package/dist/shaders/tsl.d.ts +1 -0
- package/dist/shaders/tsl.js +1 -0
- package/dist/vite/index.d.ts +15 -0
- package/dist/vite/index.js +90 -0
- package/dist/world/frontage.js +32 -0
- package/dist/world/index.d.ts +1 -1
- package/dist/world/index.js +11 -3
- package/dist/world/infiniteWorld2D.js +244 -0
- package/dist/world/island.js +201 -0
- package/dist/world/macroCellSchema.js +27 -0
- package/dist/world/macroKnightAStar.js +171 -0
- package/dist/world/random.js +33 -0
- package/dist/world/road.js +136 -0
- package/dist/world/roadRibbon.d.ts +6 -6
- package/dist/world/roadRibbon.js +161 -0
- package/dist/world/terrain.js +87 -0
- package/dist/world/worldTypes.js +111 -0
- package/package.json +36 -19
- package/dist/engine-BeKvBM8d.js +0 -1745
- package/dist/importer-D9bdcGTh.js +0 -5113
- package/dist/junk-B4bC1zAl.js +0 -1049
- package/dist/kolmoSurface-DTnrFXH0.js +0 -558
- package/dist/shaders-GS71Ek1A.js +0 -1383
- package/dist/world-PRWPYrlx.js +0 -947
- package/dist/worldTypes-Z0KfdCd0.js +0 -226
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { syncRetroUniforms as e } from "../shaders/retroShader.js";
|
|
2
|
+
import { useEffect as t, useReducer as n, useRef as r } from "react";
|
|
3
|
+
import * as i from "three";
|
|
4
|
+
import { useWorld as a } from "koota/react";
|
|
5
|
+
import { createActions as o, createWorld as s, relation as c, trait as l } from "koota";
|
|
6
|
+
// src/engine/kolmoStore.ts
|
|
7
|
+
var u = l(() => ({
|
|
8
|
+
id: "",
|
|
9
|
+
handle: null,
|
|
10
|
+
centerOfMass: [
|
|
11
|
+
0,
|
|
12
|
+
0,
|
|
13
|
+
0
|
|
14
|
+
],
|
|
15
|
+
seatOffset: [
|
|
16
|
+
0,
|
|
17
|
+
.55,
|
|
18
|
+
0
|
|
19
|
+
],
|
|
20
|
+
exitOffset: [
|
|
21
|
+
-1.5,
|
|
22
|
+
.45,
|
|
23
|
+
0
|
|
24
|
+
],
|
|
25
|
+
isFlight: !1
|
|
26
|
+
})), d = l(() => ({
|
|
27
|
+
id: "pilot",
|
|
28
|
+
handle: null,
|
|
29
|
+
exitSpawnPos: null,
|
|
30
|
+
exitSpawnYaw: 0,
|
|
31
|
+
exitLinVel: null
|
|
32
|
+
})), f = l({
|
|
33
|
+
id: "",
|
|
34
|
+
radius: 4,
|
|
35
|
+
kind: "vehicle"
|
|
36
|
+
}), p = l(() => ({
|
|
37
|
+
id: "",
|
|
38
|
+
getBody: () => null
|
|
39
|
+
})), m = c({ exclusive: !0 }), h = l({
|
|
40
|
+
activeVehicleId: "",
|
|
41
|
+
activeRetroPreset: "dreamcast"
|
|
42
|
+
}), g = s(h);
|
|
43
|
+
function _() {
|
|
44
|
+
try {
|
|
45
|
+
return a();
|
|
46
|
+
} catch {
|
|
47
|
+
return g;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function v(e) {
|
|
51
|
+
e.has(h) || e.add(h);
|
|
52
|
+
}
|
|
53
|
+
function y(e, i) {
|
|
54
|
+
let [, a] = n((e) => e + 1, 0), o = r(e && e.has(i) ? e.get(i) : void 0);
|
|
55
|
+
return o.current = e && e.has(i) ? e.get(i) : void 0, t(() => {
|
|
56
|
+
if (!e) return;
|
|
57
|
+
let t = () => {
|
|
58
|
+
o.current = e.has(i) ? e.get(i) : void 0, a();
|
|
59
|
+
}, n = e.onAdd(i, () => t()), r = e.onChange(i, () => t()), s = e.onRemove(i, () => t());
|
|
60
|
+
return (e.has(i) ? e.get(i) : void 0) !== o.current && t(), () => {
|
|
61
|
+
n(), r(), s();
|
|
62
|
+
};
|
|
63
|
+
}, [e, i]), o.current;
|
|
64
|
+
}
|
|
65
|
+
function b(e, t) {
|
|
66
|
+
let n = e.has(h) ? e.get(h)?.activeVehicleId : "";
|
|
67
|
+
if (n) for (let t of e.query(u)) {
|
|
68
|
+
let e = t.get(u);
|
|
69
|
+
if (e?.id === n && e.handle?.body) {
|
|
70
|
+
let t = e.handle.body.translation();
|
|
71
|
+
return [t.x, t.z];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (let t of e.query(d)) {
|
|
75
|
+
let e = t.get(d)?.handle?.body;
|
|
76
|
+
if (e) {
|
|
77
|
+
let t = e.translation();
|
|
78
|
+
return [t.x, t.z];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (let t of e.query(u)) {
|
|
82
|
+
let e = t.get(u)?.handle?.body;
|
|
83
|
+
if (e) {
|
|
84
|
+
let t = e.translation();
|
|
85
|
+
return [t.x, t.z];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return [t?.position.x ?? 0, t?.position.z ?? 0];
|
|
89
|
+
}
|
|
90
|
+
var x = new i.Vector3(), S = new i.Quaternion(), C = new i.Matrix4(), w = new i.Vector3(), T = new i.Quaternion(), E = new i.Vector3();
|
|
91
|
+
function D(e, t, n, r) {
|
|
92
|
+
let i = e.translation(), a = i.x - t, o = i.z - n;
|
|
93
|
+
if (e.setTranslation({
|
|
94
|
+
x: a,
|
|
95
|
+
y: i.y,
|
|
96
|
+
z: o
|
|
97
|
+
}, !0), !r?.rigidBodyStates || typeof e.handle != "number") return;
|
|
98
|
+
let s = r.rigidBodyStates.get(e.handle);
|
|
99
|
+
if (!s || s.meshType === "instancedMesh") return;
|
|
100
|
+
let c = typeof e.rotation == "function" ? e.rotation() : null;
|
|
101
|
+
x.set(a, i.y, o), c ? S.set(c.x, c.y, c.z, c.w) : S.identity(), C.compose(x, S, s.scale).premultiply(s.invertedWorldMatrix).decompose(w, T, E), s.object.position.copy(w), c && s.object.quaternion.copy(T), s.object.updateMatrixWorld(!0);
|
|
102
|
+
}
|
|
103
|
+
function O(e, t, n, r, i) {
|
|
104
|
+
t && (t.position.x -= n, t.position.z -= r);
|
|
105
|
+
for (let t of e.query(u)) {
|
|
106
|
+
let e = t.get(u), a = e?.handle?.body;
|
|
107
|
+
a && D(a, n, r, i), e?.onOriginShift?.(n, r);
|
|
108
|
+
}
|
|
109
|
+
for (let t of e.query(d)) {
|
|
110
|
+
let e = t.get(d), a = e?.handle?.body;
|
|
111
|
+
a && D(a, n, r, i), e?.exitSpawnPos && t.set(d, {
|
|
112
|
+
...e,
|
|
113
|
+
exitSpawnPos: [
|
|
114
|
+
e.exitSpawnPos[0] - n,
|
|
115
|
+
e.exitSpawnPos[1],
|
|
116
|
+
e.exitSpawnPos[2] - r
|
|
117
|
+
]
|
|
118
|
+
}), e?.onOriginShift?.(n, r);
|
|
119
|
+
}
|
|
120
|
+
for (let t of e.query(p)) {
|
|
121
|
+
let e = t.get(p)?.getBody();
|
|
122
|
+
e && D(e, n, r, i);
|
|
123
|
+
}
|
|
124
|
+
if (i?.world) {
|
|
125
|
+
let e = i.world;
|
|
126
|
+
e.propagateModifiedBodyPositionsToColliders();
|
|
127
|
+
let t = e.timestep;
|
|
128
|
+
e.timestep = 0, e.step(), e.timestep = t;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
var k = {
|
|
132
|
+
speedKmh: 0,
|
|
133
|
+
rpm: 0,
|
|
134
|
+
gear: 1,
|
|
135
|
+
throttle: 0,
|
|
136
|
+
boost: 0,
|
|
137
|
+
mode: "foot",
|
|
138
|
+
activeVehicleId: null,
|
|
139
|
+
activeRetroPreset: "dreamcast",
|
|
140
|
+
nearVehicleId: null
|
|
141
|
+
}, A = new i.Vector3(), j = new i.Vector3(), M = o((t) => ({
|
|
142
|
+
boardVehicle: (e) => {
|
|
143
|
+
v(t);
|
|
144
|
+
let n = t.queryFirst(d);
|
|
145
|
+
for (let r of t.query(u)) if (r.get(u)?.id === e) {
|
|
146
|
+
n && n.add(m(r));
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
let r = t.get(h);
|
|
150
|
+
t.set(h, {
|
|
151
|
+
activeVehicleId: e,
|
|
152
|
+
activeRetroPreset: r?.activeRetroPreset ?? "dreamcast"
|
|
153
|
+
}), k.activeVehicleId = e, k.nearVehicleId = null;
|
|
154
|
+
},
|
|
155
|
+
exitVehicle: () => {
|
|
156
|
+
v(t);
|
|
157
|
+
let e = t.get(h), n = e?.activeVehicleId || "", r = t.queryFirst(d);
|
|
158
|
+
for (let e of t.query(u)) {
|
|
159
|
+
let t = e.get(u);
|
|
160
|
+
if (t && n && t.id === n) {
|
|
161
|
+
if (r && (r.has(m(e)) && r.remove(m(e)), t.handle)) {
|
|
162
|
+
A.set(t.exitOffset[0] - t.centerOfMass[0], t.exitOffset[1] - t.centerOfMass[1], t.exitOffset[2] - t.centerOfMass[2]).applyQuaternion(t.handle.currQuat).add(t.handle.currPos), j.copy(t.handle.bodyZAxis).projectOnPlane(t.handle.upAxis).normalize();
|
|
163
|
+
let e = j.lengthSq() > 1e-6 ? Math.atan2(j.x, j.z) : 0, n = t.handle.currLinVel, i = r.get(d);
|
|
164
|
+
r.set(d, {
|
|
165
|
+
id: i?.id ?? "pilot",
|
|
166
|
+
handle: null,
|
|
167
|
+
exitSpawnPos: [
|
|
168
|
+
A.x,
|
|
169
|
+
A.y,
|
|
170
|
+
A.z
|
|
171
|
+
],
|
|
172
|
+
exitSpawnYaw: e,
|
|
173
|
+
exitLinVel: [
|
|
174
|
+
n.x,
|
|
175
|
+
n.y,
|
|
176
|
+
n.z
|
|
177
|
+
],
|
|
178
|
+
onOriginShift: i?.onOriginShift
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
t.handle?.setMovement({
|
|
182
|
+
forward: !1,
|
|
183
|
+
backward: !1,
|
|
184
|
+
steerLeft: !1,
|
|
185
|
+
steerRight: !1,
|
|
186
|
+
brake: !t.isFlight
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
t.set(h, {
|
|
191
|
+
activeVehicleId: "",
|
|
192
|
+
activeRetroPreset: e?.activeRetroPreset ?? "dreamcast"
|
|
193
|
+
}), Object.assign(k, {
|
|
194
|
+
activeVehicleId: null,
|
|
195
|
+
mode: "foot",
|
|
196
|
+
speedKmh: 0,
|
|
197
|
+
rpm: 0,
|
|
198
|
+
throttle: 0,
|
|
199
|
+
boost: 0
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
setRetroPreset: (n) => {
|
|
203
|
+
v(t), e(n);
|
|
204
|
+
let r = t.get(h);
|
|
205
|
+
t.set(h, {
|
|
206
|
+
activeVehicleId: r?.activeVehicleId ?? "",
|
|
207
|
+
activeRetroPreset: n
|
|
208
|
+
}), k.activeRetroPreset = n;
|
|
209
|
+
}
|
|
210
|
+
}));
|
|
211
|
+
export { d as ActorTrait, p as FloatingBodyTrait, f as InteractableTrait, m as PilotLink, u as VehicleTrait, h as WorldSessionTrait, v as ensureWorldSession, M as kolmoActions, k as kolmoTelemetry, g as kolmoWorld, b as readFloatingOriginAnchorXZ, O as shiftFloatingOriginEntities, _ as useActiveKolmoWorld, y as useWorldTrait };
|
|
@@ -7,7 +7,7 @@ export interface KolmoSurfaceProps {
|
|
|
7
7
|
size?: number;
|
|
8
8
|
position?: [number, number, number];
|
|
9
9
|
}
|
|
10
|
-
export declare function KolmoSurface({ src, bundle, size, position }: KolmoSurfaceProps): React.JSX.Element
|
|
10
|
+
export declare function KolmoSurface({ src, bundle, size, position }: KolmoSurfaceProps): React.JSX.Element;
|
|
11
11
|
export declare function togglePropJoint(handle: KhrAssemblyHandle | null, bundle: KhrAssetBundle, openState: boolean, clickedObj?: THREE.Object3D | null, perBodyOpen?: Map<string, boolean>): boolean;
|
|
12
12
|
export interface KolmoPropProps {
|
|
13
13
|
src?: string;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { applyRetroMaterial as e, applySceneRetroMaterials as t } from "../shaders/retroShader.js";
|
|
2
|
+
import { ShiftedFixedBody as n } from "./shiftedFixedBody.js";
|
|
3
|
+
import { useCallback as r, useEffect as i, useLayoutEffect as a, useMemo as o, useRef as s } from "react";
|
|
4
|
+
import * as c from "three";
|
|
5
|
+
import { KhrAssembly as l, cloneKhrBundle as u, useKhrGlb as d } from "@khr3/core";
|
|
6
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
7
|
+
import { CuboidCollider as m } from "@react-three/rapier";
|
|
8
|
+
// src/engine/kolmoSurface.tsx
|
|
9
|
+
function h(e) {
|
|
10
|
+
let t = /* @__PURE__ */ new Uint8Array(16384);
|
|
11
|
+
for (let e = 0; e < 64; e++) for (let n = 0; n < 64; n++) {
|
|
12
|
+
let r = (e * 64 + n) * 4;
|
|
13
|
+
if (n === 0 || e === 0) t[r] = 56, t[r + 1] = 178, t[r + 2] = 216;
|
|
14
|
+
else if (n === 32 || e === 32) t[r] = 44, t[r + 1] = 58, t[r + 2] = 78;
|
|
15
|
+
else {
|
|
16
|
+
let i = (n >> 4) + (e >> 4) & 1 ? 30 : 35;
|
|
17
|
+
t[r] = i, t[r + 1] = i + 3, t[r + 2] = i + 9;
|
|
18
|
+
}
|
|
19
|
+
t[r + 3] = 255;
|
|
20
|
+
}
|
|
21
|
+
let n = new c.DataTexture(t, 64, 64, c.RGBAFormat);
|
|
22
|
+
return n.colorSpace = c.SRGBColorSpace, n.wrapS = c.RepeatWrapping, n.wrapT = c.RepeatWrapping, n.magFilter = c.NearestFilter, n.minFilter = c.NearestFilter, n.repeat.set(e, e), n.needsUpdate = !0, n;
|
|
23
|
+
}
|
|
24
|
+
function g({ size: t, position: r }) {
|
|
25
|
+
let a = o(() => {
|
|
26
|
+
let n = h(Math.max(4, Math.round(t / 8)));
|
|
27
|
+
return {
|
|
28
|
+
tex: n,
|
|
29
|
+
geo: new c.BoxGeometry(t, 1, t),
|
|
30
|
+
mat: e(new c.MeshStandardMaterial({
|
|
31
|
+
map: n,
|
|
32
|
+
roughness: .92,
|
|
33
|
+
metalness: .06
|
|
34
|
+
}), { flatShading: !1 })
|
|
35
|
+
};
|
|
36
|
+
}, [t]);
|
|
37
|
+
return i(() => () => {
|
|
38
|
+
a.geo.dispose(), a.mat.dispose(), a.tex.dispose();
|
|
39
|
+
}, [a]), /* @__PURE__ */ p(n, {
|
|
40
|
+
x: r[0],
|
|
41
|
+
y: r[1] - .5,
|
|
42
|
+
z: r[2],
|
|
43
|
+
friction: .95,
|
|
44
|
+
children: [/* @__PURE__ */ f(m, {
|
|
45
|
+
args: [
|
|
46
|
+
t * .5,
|
|
47
|
+
.5,
|
|
48
|
+
t * .5
|
|
49
|
+
],
|
|
50
|
+
restitution: .04
|
|
51
|
+
}), /* @__PURE__ */ f("mesh", {
|
|
52
|
+
name: "KolmoArenaSlab",
|
|
53
|
+
geometry: a.geo,
|
|
54
|
+
material: a.mat,
|
|
55
|
+
receiveShadow: !0
|
|
56
|
+
})]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function _(e, n) {
|
|
60
|
+
let r = u(e), i = [];
|
|
61
|
+
return ((e) => {
|
|
62
|
+
e.traverse((e) => {
|
|
63
|
+
let t = e;
|
|
64
|
+
if (t.material) {
|
|
65
|
+
if (Array.isArray(t.material)) t.material = t.material.map((e) => {
|
|
66
|
+
let t = e.clone();
|
|
67
|
+
return i.push(t), t;
|
|
68
|
+
});
|
|
69
|
+
else {
|
|
70
|
+
let e = t.material.clone();
|
|
71
|
+
i.push(e), t.material = e;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
})(r.scene), t(r.scene, n === void 0 ? void 0 : { flatShading: n }), {
|
|
76
|
+
cloned: r,
|
|
77
|
+
disposeMats: () => {
|
|
78
|
+
for (let e of i) e.dispose();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function v({ bundle: e, position: t }) {
|
|
83
|
+
let { cloned: n, disposeMats: r } = o(() => _(e, !1), [e]);
|
|
84
|
+
return a(() => () => r(), [r]), /* @__PURE__ */ f(l, {
|
|
85
|
+
bundle: n,
|
|
86
|
+
position: t,
|
|
87
|
+
fixedRoot: !0
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function y({ src: e, position: t }) {
|
|
91
|
+
return /* @__PURE__ */ f(v, {
|
|
92
|
+
bundle: d(e),
|
|
93
|
+
position: t
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function b({ src: e, bundle: t, size: n = 200, position: r = [
|
|
97
|
+
0,
|
|
98
|
+
0,
|
|
99
|
+
0
|
|
100
|
+
] }) {
|
|
101
|
+
return t ? /* @__PURE__ */ f(v, {
|
|
102
|
+
bundle: t,
|
|
103
|
+
position: r
|
|
104
|
+
}) : e ? /* @__PURE__ */ f(y, {
|
|
105
|
+
src: e,
|
|
106
|
+
position: r
|
|
107
|
+
}) : /* @__PURE__ */ f(g, {
|
|
108
|
+
size: n,
|
|
109
|
+
position: r
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function x(e) {
|
|
113
|
+
if (!e) return {
|
|
114
|
+
open: 1.35,
|
|
115
|
+
closed: 0
|
|
116
|
+
};
|
|
117
|
+
let [t, n] = e;
|
|
118
|
+
return {
|
|
119
|
+
open: Math.abs(n) >= Math.abs(t) ? n : t,
|
|
120
|
+
closed: Math.min(n, Math.max(t, 0))
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function S(e, t, n, r, i) {
|
|
124
|
+
if (!e) return n;
|
|
125
|
+
if (r && i) {
|
|
126
|
+
let n = r;
|
|
127
|
+
for (; n;) {
|
|
128
|
+
let r = t.bodies.find((e) => e.object === n && e.joint?.drive?.stiffness !== void 0);
|
|
129
|
+
if (r) {
|
|
130
|
+
let t = !(i.get(r.nodeName) ?? !1);
|
|
131
|
+
i.set(r.nodeName, t);
|
|
132
|
+
let { open: n, closed: a } = x(r.joint?.limits);
|
|
133
|
+
return e.setJointTarget(r.nodeName, t ? n : a), t;
|
|
134
|
+
}
|
|
135
|
+
n = n.parent;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
let a = !n;
|
|
139
|
+
for (let n of t.bodies) {
|
|
140
|
+
if (!n.joint?.drive || n.joint.drive.stiffness === void 0) continue;
|
|
141
|
+
let { open: t, closed: r } = x(n.joint.limits);
|
|
142
|
+
i?.set(n.nodeName, a), e.setJointTarget(n.nodeName, a ? t : r);
|
|
143
|
+
}
|
|
144
|
+
return a;
|
|
145
|
+
}
|
|
146
|
+
function C({ bundle: e, position: t, fixed: n }) {
|
|
147
|
+
let i = s(null), c = s(!1), u = s(/* @__PURE__ */ new Map()), { cloned: d, disposeMats: p } = o(() => _(e), [e]);
|
|
148
|
+
a(() => () => p(), [p]);
|
|
149
|
+
let m = r((e) => {
|
|
150
|
+
e?.stopPropagation?.(), c.current = S(i.current, d, c.current, e?.object ?? null, u.current);
|
|
151
|
+
}, [d]);
|
|
152
|
+
return /* @__PURE__ */ f(l, {
|
|
153
|
+
ref: i,
|
|
154
|
+
bundle: d,
|
|
155
|
+
position: t,
|
|
156
|
+
fixedRoot: n,
|
|
157
|
+
onClick: m
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function w({ src: e, position: t, fixed: n }) {
|
|
161
|
+
return /* @__PURE__ */ f(C, {
|
|
162
|
+
bundle: d(e),
|
|
163
|
+
position: t,
|
|
164
|
+
fixed: n
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function T({ src: e, bundle: t, position: n = [
|
|
168
|
+
0,
|
|
169
|
+
0,
|
|
170
|
+
0
|
|
171
|
+
], fixed: r = !1 }) {
|
|
172
|
+
return t ? /* @__PURE__ */ f(C, {
|
|
173
|
+
bundle: t,
|
|
174
|
+
position: n,
|
|
175
|
+
fixed: r
|
|
176
|
+
}) : e ? /* @__PURE__ */ f(w, {
|
|
177
|
+
src: e,
|
|
178
|
+
position: n,
|
|
179
|
+
fixed: r
|
|
180
|
+
}) : null;
|
|
181
|
+
}
|
|
182
|
+
export { T as KolmoProp, b as KolmoSurface, S as togglePropJoint };
|
|
@@ -4,6 +4,7 @@ import type { CollisionEnterPayload } from "@react-three/rapier";
|
|
|
4
4
|
import { type KhrAssetBundle } from "@khr3/core";
|
|
5
5
|
import { type KhrVehicleProps } from "@khr3/core/vehicle";
|
|
6
6
|
import type { DroneConfigType, EcctrlVehicleHandle } from "@pinkaphant/ecctrl/vehicle";
|
|
7
|
+
import { type KolmoInputGetter } from "./kolmoInput.js";
|
|
7
8
|
export interface KolmoVehicleProps {
|
|
8
9
|
id: string;
|
|
9
10
|
src?: string;
|
|
@@ -14,7 +15,6 @@ export interface KolmoVehicleProps {
|
|
|
14
15
|
piloted?: boolean;
|
|
15
16
|
flightMode?: boolean;
|
|
16
17
|
vehicleMode?: "drive" | "rocket";
|
|
17
|
-
twoWheel?: boolean;
|
|
18
18
|
enable?: boolean;
|
|
19
19
|
ccd?: boolean;
|
|
20
20
|
linearDamping?: number;
|
|
@@ -25,6 +25,7 @@ export interface KolmoVehicleProps {
|
|
|
25
25
|
carConfig?: Record<string, unknown>;
|
|
26
26
|
droneConfig?: Partial<DroneConfigType>;
|
|
27
27
|
vehicleRef?: React.RefObject<EcctrlVehicleHandle | null>;
|
|
28
|
+
getInput?: KolmoInputGetter;
|
|
28
29
|
driver?: (veh: EcctrlVehicleHandle, dt: number, state: RootState) => void;
|
|
29
30
|
cameraController?: (veh: EcctrlVehicleHandle, dt: number, state: RootState) => void;
|
|
30
31
|
children?: ReactNode;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { KolmoGravityContext as e } from "../physics/index.js";
|
|
2
|
+
import { KOLMO_EXTENSION_NAME as t, createDefaultSignals as n, decodeKolmoRig as r } from "../schema/kolmoSchema.js";
|
|
3
|
+
import { createVehiclePanelAnimator as i } from "../importer/vehiclePanelAnim.js";
|
|
4
|
+
import { KolmoEmitterRig as a } from "../shaders/plumeAndSparkle.js";
|
|
5
|
+
import { applySceneRetroMaterials as o } from "../shaders/retroShader.js";
|
|
6
|
+
import { useKolmoInput as ee } from "./kolmoInput.js";
|
|
7
|
+
import { InteractableTrait as te, VehicleTrait as s, WorldSessionTrait as c, ensureWorldSession as ne, kolmoActions as l, useActiveKolmoWorld as re, useWorldTrait as ie } from "./kolmoStore.js";
|
|
8
|
+
import { stepKolmoVehicleFrame as ae } from "./kolmoVehicleDriver.js";
|
|
9
|
+
import { useCallback as u, useContext as oe, useEffect as d, useLayoutEffect as f, useMemo as p, useRef as m, useState as h } from "react";
|
|
10
|
+
import * as se from "three";
|
|
11
|
+
import { useFrame as ce } from "@react-three/fiber";
|
|
12
|
+
import { cloneKhrBundle as le, loadKhrGlb as g, useKhrGlb as _ } from "@khr3/core";
|
|
13
|
+
import { jsx as v, jsxs as y } from "react/jsx-runtime";
|
|
14
|
+
import { KhrVehicle as b } from "@khr3/core/vehicle";
|
|
15
|
+
// src/engine/kolmoVehicle.tsx
|
|
16
|
+
function ue(e) {
|
|
17
|
+
e.traverse((e) => {
|
|
18
|
+
let n = e.userData?.gltfExtensions?.[t];
|
|
19
|
+
n && !e.userData.KOLMO_emitter && (e.userData[t] = n);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function de(e) {
|
|
23
|
+
let t = [];
|
|
24
|
+
for (let n of e) n.traverse((e) => {
|
|
25
|
+
let n = e;
|
|
26
|
+
if (n.material) {
|
|
27
|
+
if (Array.isArray(n.material)) n.material = n.material.map((e) => {
|
|
28
|
+
let n = e.clone();
|
|
29
|
+
return t.push(n), n;
|
|
30
|
+
});
|
|
31
|
+
else {
|
|
32
|
+
let e = n.material.clone();
|
|
33
|
+
t.push(e), n.material = e;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}), o(n);
|
|
37
|
+
return () => {
|
|
38
|
+
for (let e of t) e.dispose();
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function x({ id: t, sourceBundle: o, rawGlbBytes: h, position: g = [
|
|
42
|
+
0,
|
|
43
|
+
.35,
|
|
44
|
+
0
|
|
45
|
+
], rotation: _, piloted: x = !1, flightMode: S = !1, vehicleMode: C, enable: w = !0, ccd: T, linearDamping: E, angularDamping: D, userData: O, onCollisionEnter: k, wheelConfig: A, carConfig: j, droneConfig: M, vehicleRef: N, getInput: fe, driver: P, cameraController: F, children: I }) {
|
|
46
|
+
let L = oe(e), R = re();
|
|
47
|
+
f(() => {
|
|
48
|
+
ne(R);
|
|
49
|
+
}, [R]);
|
|
50
|
+
let z = ie(R, c), B = ee(fe), V = p(() => le(o), [o]), H = p(() => i(V), [V]), U = p(() => (ue(V.scene), r(V.scene, h)), [V, h]);
|
|
51
|
+
f(() => de([
|
|
52
|
+
V.scene,
|
|
53
|
+
...V.wheels.map((e) => e.object),
|
|
54
|
+
...V.propellers.map((e) => e.object)
|
|
55
|
+
]), [V]);
|
|
56
|
+
let W = !!(C === "rocket" || S || C !== "drive" && V.propellers.length > 0), G = p(() => U.sockets.find((e) => e.role === "seat" || e.role === "optic")?.localPosition ?? [
|
|
57
|
+
0,
|
|
58
|
+
.65,
|
|
59
|
+
0
|
|
60
|
+
], [U]), K = p(() => U.sockets.find((e) => e.role === "exit")?.localPosition ?? [
|
|
61
|
+
-1.55,
|
|
62
|
+
.45,
|
|
63
|
+
0
|
|
64
|
+
], [U]), q = p(() => {
|
|
65
|
+
if (A || C !== void 0) return {
|
|
66
|
+
...C === void 0 ? {} : { enable: C === "drive" },
|
|
67
|
+
...A ?? {}
|
|
68
|
+
};
|
|
69
|
+
}, [A, C]), J = p(() => W ? {
|
|
70
|
+
controlMode: "VELOCITY",
|
|
71
|
+
maxHorizSpeed: 46,
|
|
72
|
+
maxVertSpeed: 16,
|
|
73
|
+
maxYawRate: 2.3,
|
|
74
|
+
maxTiltAngle: .52,
|
|
75
|
+
HORIZ_VEL_P: 1.8,
|
|
76
|
+
VERT_VEL_P: 2.8,
|
|
77
|
+
...V.droneTune ?? {},
|
|
78
|
+
...M ?? {}
|
|
79
|
+
} : M, [
|
|
80
|
+
W,
|
|
81
|
+
V.droneTune,
|
|
82
|
+
M
|
|
83
|
+
]), Y = m(null), pe = m([
|
|
84
|
+
g[0],
|
|
85
|
+
g[1],
|
|
86
|
+
g[2]
|
|
87
|
+
]), X = m(_ ? [
|
|
88
|
+
_[0],
|
|
89
|
+
_[1],
|
|
90
|
+
_[2]
|
|
91
|
+
] : void 0), Z = m(n()), Q = m(new se.Vector3()), me = m({
|
|
92
|
+
camInit: !1,
|
|
93
|
+
cockpit: !1,
|
|
94
|
+
prevCam: !1,
|
|
95
|
+
prevL: !1,
|
|
96
|
+
prevR: !1,
|
|
97
|
+
turnL: !1,
|
|
98
|
+
turnR: !1
|
|
99
|
+
}), he = m({
|
|
100
|
+
forward: !1,
|
|
101
|
+
backward: !1,
|
|
102
|
+
steerLeft: !1,
|
|
103
|
+
steerRight: !1,
|
|
104
|
+
brake: !1,
|
|
105
|
+
throttleUp: !1,
|
|
106
|
+
throttleDown: !1,
|
|
107
|
+
yawLeft: !1,
|
|
108
|
+
yawRight: !1,
|
|
109
|
+
pitchForward: !1,
|
|
110
|
+
pitchBackward: !1,
|
|
111
|
+
rollLeft: !1,
|
|
112
|
+
rollRight: !1
|
|
113
|
+
}), $ = u((e, t) => {
|
|
114
|
+
Q.current.x -= e, Q.current.z -= t;
|
|
115
|
+
let n = Y.current;
|
|
116
|
+
if (n) {
|
|
117
|
+
n.currPos.x -= e, n.currPos.z -= t;
|
|
118
|
+
for (let r of n.wheelsInfo.values()) {
|
|
119
|
+
let n = r.current;
|
|
120
|
+
n.rayPos.x -= e, n.rayPos.z -= t, n.supPos.x -= e, n.supPos.z -= t, n.rayHitPos.x -= e, n.rayHitPos.z -= t;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}, []);
|
|
124
|
+
d(() => {
|
|
125
|
+
let e = R.spawn(s({
|
|
126
|
+
id: t,
|
|
127
|
+
handle: Y.current,
|
|
128
|
+
centerOfMass: [...V.centerOfMass],
|
|
129
|
+
seatOffset: G,
|
|
130
|
+
exitOffset: K,
|
|
131
|
+
isFlight: W,
|
|
132
|
+
onOriginShift: $
|
|
133
|
+
}), te({
|
|
134
|
+
id: t,
|
|
135
|
+
radius: 4.2,
|
|
136
|
+
kind: "vehicle"
|
|
137
|
+
}));
|
|
138
|
+
return x && !R.get(c)?.activeVehicleId && l(R).boardVehicle(t), () => {
|
|
139
|
+
R.get(c)?.activeVehicleId === t && l(R).exitVehicle(), e.destroy();
|
|
140
|
+
};
|
|
141
|
+
}, [
|
|
142
|
+
R,
|
|
143
|
+
t,
|
|
144
|
+
V,
|
|
145
|
+
G,
|
|
146
|
+
K,
|
|
147
|
+
W,
|
|
148
|
+
x,
|
|
149
|
+
$
|
|
150
|
+
]);
|
|
151
|
+
let ge = u((e) => {
|
|
152
|
+
Y.current = e, N && (N.current = e);
|
|
153
|
+
for (let n of R.query(s)) {
|
|
154
|
+
let r = n.get(s);
|
|
155
|
+
r && r.id === t && n.set(s, {
|
|
156
|
+
...r,
|
|
157
|
+
handle: e,
|
|
158
|
+
onOriginShift: $
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}, [
|
|
162
|
+
R,
|
|
163
|
+
t,
|
|
164
|
+
N,
|
|
165
|
+
$
|
|
166
|
+
]), _e = z?.activeVehicleId === t || x && !z?.activeVehicleId;
|
|
167
|
+
return ce((e, n) => {
|
|
168
|
+
let r = Math.min(Math.max(n, 1e-4), .05);
|
|
169
|
+
H.step(r);
|
|
170
|
+
let i = Y.current;
|
|
171
|
+
i && i.body && (P ? (P(i, r, e), F && F(i, r, e)) : ae({
|
|
172
|
+
id: t,
|
|
173
|
+
veh: i,
|
|
174
|
+
keys: B(),
|
|
175
|
+
cmd: he.current,
|
|
176
|
+
sig: Z.current,
|
|
177
|
+
st: me.current,
|
|
178
|
+
camTarget: Q.current,
|
|
179
|
+
centerOfMass: V.centerOfMass,
|
|
180
|
+
seatOffset: G,
|
|
181
|
+
isPiloted: _e,
|
|
182
|
+
isFlight: W,
|
|
183
|
+
dt: r,
|
|
184
|
+
state: e,
|
|
185
|
+
cameraController: F
|
|
186
|
+
}));
|
|
187
|
+
}), /* @__PURE__ */ v("group", {
|
|
188
|
+
onClick: (e) => {
|
|
189
|
+
e.delta <= 5 && H.toggleHitObject(e.object) && e.stopPropagation();
|
|
190
|
+
},
|
|
191
|
+
children: /* @__PURE__ */ y(b, {
|
|
192
|
+
ref: ge,
|
|
193
|
+
bundle: V,
|
|
194
|
+
position: pe.current,
|
|
195
|
+
enable: w,
|
|
196
|
+
enableCustomGravity: L,
|
|
197
|
+
...X.current === void 0 ? {} : { rotation: X.current },
|
|
198
|
+
...T === void 0 ? {} : { ccd: T },
|
|
199
|
+
...E === void 0 ? {} : { linearDamping: E },
|
|
200
|
+
...D === void 0 ? {} : { angularDamping: D },
|
|
201
|
+
...O === void 0 ? {} : { userData: O },
|
|
202
|
+
...k === void 0 ? {} : { onCollisionEnter: k },
|
|
203
|
+
...q === void 0 ? {} : { wheelConfig: q },
|
|
204
|
+
...j === void 0 ? {} : { carConfig: j },
|
|
205
|
+
...J === void 0 ? {} : { droneConfig: J },
|
|
206
|
+
children: [/* @__PURE__ */ v(a, {
|
|
207
|
+
emitters: U.emitters,
|
|
208
|
+
signalsRef: Z
|
|
209
|
+
}), I]
|
|
210
|
+
})
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
function S(e) {
|
|
214
|
+
return /* @__PURE__ */ v(x, {
|
|
215
|
+
...e,
|
|
216
|
+
sourceBundle: _(e.src)
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function C(e) {
|
|
220
|
+
let [t, n] = h(null);
|
|
221
|
+
return d(() => {
|
|
222
|
+
if (e.bundle || e.src || !e.rawGlbBytes) return;
|
|
223
|
+
let t = !0;
|
|
224
|
+
return g(e.rawGlbBytes).then((e) => {
|
|
225
|
+
t && n(e);
|
|
226
|
+
}), () => {
|
|
227
|
+
t = !1;
|
|
228
|
+
};
|
|
229
|
+
}, [
|
|
230
|
+
e.bundle,
|
|
231
|
+
e.src,
|
|
232
|
+
e.rawGlbBytes
|
|
233
|
+
]), e.bundle ? /* @__PURE__ */ v(x, {
|
|
234
|
+
...e,
|
|
235
|
+
sourceBundle: e.bundle
|
|
236
|
+
}) : e.src ? /* @__PURE__ */ v(S, {
|
|
237
|
+
...e,
|
|
238
|
+
src: e.src
|
|
239
|
+
}) : t ? /* @__PURE__ */ v(x, {
|
|
240
|
+
...e,
|
|
241
|
+
sourceBundle: t
|
|
242
|
+
}) : null;
|
|
243
|
+
}
|
|
244
|
+
export { C as KolmoVehicle };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import type { RootState } from "@react-three/fiber";
|
|
3
|
+
import type { EcctrlVehicleHandle, VehicleInput } from "@pinkaphant/ecctrl/vehicle";
|
|
4
|
+
import type { KolmoSignalState } from "../schema/kolmoSchema.js";
|
|
5
|
+
import type { KolmoInputState } from "./kolmoInput.js";
|
|
6
|
+
export interface KolmoVehicleFrameState {
|
|
7
|
+
camInit: boolean;
|
|
8
|
+
cockpit: boolean;
|
|
9
|
+
prevCam: boolean;
|
|
10
|
+
prevL: boolean;
|
|
11
|
+
prevR: boolean;
|
|
12
|
+
turnL: boolean;
|
|
13
|
+
turnR: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function stepKolmoVehicleFrame(params: {
|
|
16
|
+
id: string;
|
|
17
|
+
veh: EcctrlVehicleHandle;
|
|
18
|
+
keys: Readonly<KolmoInputState>;
|
|
19
|
+
cmd: VehicleInput;
|
|
20
|
+
sig: KolmoSignalState;
|
|
21
|
+
st: KolmoVehicleFrameState;
|
|
22
|
+
camTarget: THREE.Vector3;
|
|
23
|
+
centerOfMass: readonly [number, number, number];
|
|
24
|
+
seatOffset: readonly [number, number, number];
|
|
25
|
+
isPiloted: boolean;
|
|
26
|
+
isFlight: boolean;
|
|
27
|
+
dt: number;
|
|
28
|
+
state: RootState;
|
|
29
|
+
cameraController?: (veh: EcctrlVehicleHandle, dt: number, state: RootState) => void;
|
|
30
|
+
}): void;
|