@pinkaphant/kolmo 0.1.2 → 0.2.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/LICENSE +21 -0
- package/README.md +16 -14
- package/bin/kolmo.mjs +22 -54
- package/dist/body/HeldItem.js +171 -0
- package/dist/body/KhrBody.js +171 -0
- package/dist/body/bodySi.d.ts +0 -11
- package/dist/body/bodySi.js +52 -0
- package/dist/body/index.d.ts +1 -1
- package/dist/body/index.js +4 -1
- 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 +17 -0
- package/dist/engine/kolmoInput.js +78 -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 +3 -1
- package/dist/engine/kolmoVehicle.js +250 -0
- package/dist/engine/kolmoVehicleDriver.d.ts +30 -0
- package/dist/engine/kolmoVehicleDriver.js +29 -0
- package/dist/engine/kolmoWorld.d.ts +7 -15
- package/dist/engine/kolmoWorld.js +139 -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 +1 -1
- package/dist/index.js +69 -13
- 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 +32 -18
- package/dist/body-B7FTf67o.js +0 -362
- package/dist/engine-BeKvBM8d.js +0 -1745
- package/dist/importer-B2-S-N_e.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,223 @@
|
|
|
1
|
+
import { createPS2RoadMaterialWebGL as e } from "../shaders/ps2RoadWebGL.js";
|
|
2
|
+
import { createPS2WorldTextures as t } from "../shaders/ps2Textures.js";
|
|
3
|
+
import { MACRO_SIZE_M as n, quantizeFloatingOrigin192 as r } from "../world/macroCellSchema.js";
|
|
4
|
+
import { InfiniteLongDrivePlanner as i } from "../world/infiniteWorld2D.js";
|
|
5
|
+
import { bakeWorldSplatMaps as a } from "../world/worldTypes.js";
|
|
6
|
+
import { buildRoadRibbonGeometry as o } from "../world/roadRibbon.js";
|
|
7
|
+
import { ShiftedFixedBody as s } from "./shiftedFixedBody.js";
|
|
8
|
+
import { roadFromPoints as c } from "../world/road.js";
|
|
9
|
+
import { KolmoIsland as l, getCachedIslandPlan as u } from "./kolmoIsland.js";
|
|
10
|
+
import { readFloatingOriginAnchorXZ as d, shiftFloatingOriginEntities as f, useActiveKolmoWorld as p } from "./kolmoStore.js";
|
|
11
|
+
import { InstancedC12Piece as m, InstancedWorldGlb as h } from "./longDriveKit.js";
|
|
12
|
+
import { MainlandMacroCell as g } from "./mainlandMacroCell.js";
|
|
13
|
+
import { useEffect as _, useLayoutEffect as v, useMemo as y, useRef as b, useState as x } from "react";
|
|
14
|
+
import * as S from "three";
|
|
15
|
+
import { useFrame as C, useThree as w } from "@react-three/fiber";
|
|
16
|
+
import { jsx as T, jsxs as E } from "react/jsx-runtime";
|
|
17
|
+
import { TrimeshCollider as D, useRapier as O } from "@react-three/rapier";
|
|
18
|
+
// src/engine/kolmoLongDrive.tsx
|
|
19
|
+
function k(e = 77, t = 960) {
|
|
20
|
+
let n = u(e, t), r = n.road.samples[0];
|
|
21
|
+
for (let e of n.road.samples) e.pos[0] > r.pos[0] && (r = e);
|
|
22
|
+
return {
|
|
23
|
+
vehiclePos: [
|
|
24
|
+
r.pos[0] + 10,
|
|
25
|
+
r.pos[1] + .6,
|
|
26
|
+
r.pos[2]
|
|
27
|
+
],
|
|
28
|
+
vehicleRot: [
|
|
29
|
+
0,
|
|
30
|
+
Math.PI * .5,
|
|
31
|
+
0
|
|
32
|
+
],
|
|
33
|
+
actorPos: [
|
|
34
|
+
r.pos[0] + 8,
|
|
35
|
+
r.pos[1] + 1.6,
|
|
36
|
+
r.pos[2] + 3.5
|
|
37
|
+
]
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function A(e = 77, t = 1, n = 0) {
|
|
41
|
+
let r = new i(e), a = r.generateMacroCell2D(t, n), o = a.highwayPolylines[0];
|
|
42
|
+
if (o && o.length >= 2) {
|
|
43
|
+
let e = o[1], t = o[Math.min(o.length - 1, 2)], n = Math.max(2, r.sampleMainlandHeight(e[0], e[1])), i = Math.atan2(t[0] - e[0], t[1] - e[1]);
|
|
44
|
+
return {
|
|
45
|
+
vehiclePos: [
|
|
46
|
+
e[0],
|
|
47
|
+
n + .45,
|
|
48
|
+
e[1]
|
|
49
|
+
],
|
|
50
|
+
vehicleRot: [
|
|
51
|
+
0,
|
|
52
|
+
i,
|
|
53
|
+
0
|
|
54
|
+
],
|
|
55
|
+
actorPos: [
|
|
56
|
+
e[0] - 2.6,
|
|
57
|
+
n + 1.35,
|
|
58
|
+
e[1] + 2.2
|
|
59
|
+
]
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
let s = Math.max(2.5, r.sampleMainlandHeight(a.hubX, a.hubZ));
|
|
63
|
+
return {
|
|
64
|
+
vehiclePos: [
|
|
65
|
+
a.hubX,
|
|
66
|
+
s + .45,
|
|
67
|
+
a.hubZ
|
|
68
|
+
],
|
|
69
|
+
vehicleRot: [
|
|
70
|
+
0,
|
|
71
|
+
Math.PI * .5,
|
|
72
|
+
0
|
|
73
|
+
],
|
|
74
|
+
actorPos: [
|
|
75
|
+
a.hubX - 2.5,
|
|
76
|
+
s + 1.35,
|
|
77
|
+
a.hubZ + 2.5
|
|
78
|
+
]
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function j({ seed: e, islandSize: t, planner: r, roadMat: i, offX: a, offZ: l }) {
|
|
82
|
+
let d = y(() => {
|
|
83
|
+
let i = u(e, t), a = i.road.samples[0];
|
|
84
|
+
for (let e of i.road.samples) e.pos[0] > a.pos[0] && (a = e);
|
|
85
|
+
let s = r.evalVerticalBorder(0, 0), l = n * .5, d = s.offsetMeters, f = r.sampleMainlandHeight(l, d), p = [];
|
|
86
|
+
for (let e = 0; e <= 28; e++) {
|
|
87
|
+
let t = e / 28, n = Math.sin(Math.PI * t), r = a.pos[0] + (l - a.pos[0]) * t, i = a.pos[2] + (d - a.pos[2]) * (t * t * (3 - 2 * t)), o = a.pos[1] * (1 - t) + f * t;
|
|
88
|
+
p.push([
|
|
89
|
+
r,
|
|
90
|
+
o * (1 - n) + 14 * n,
|
|
91
|
+
i
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
let m = c(p, 5, 3, !1), h = o(m, {
|
|
95
|
+
skirtDrop: .6,
|
|
96
|
+
crownHeight: .04
|
|
97
|
+
}), g = [], _ = [], v = new S.Object3D();
|
|
98
|
+
for (let e = 24; e < m.length - 24; e += 24) {
|
|
99
|
+
let t = m.at(e), n = Math.atan2(t.tangent[0], t.tangent[2]);
|
|
100
|
+
for (let e of [-3.6, 3.6]) {
|
|
101
|
+
let r = t.pos[0] + t.left[0] * e, i = t.pos[2] + t.left[2] * e, a = t.pos[1] + 14;
|
|
102
|
+
v.position.set(r, t.pos[1] - a * .5, i), v.rotation.set(0, n, 0), v.scale.set(.45, a / .24, .45), v.updateMatrix(), g.push(...v.matrix.elements);
|
|
103
|
+
}
|
|
104
|
+
v.position.set(t.pos[0] + t.left[0] * 4.8, t.pos[1], t.pos[2] + t.left[2] * 4.8), v.rotation.set(0, n, 0), v.scale.set(1, 1, 1), v.updateMatrix(), _.push(...v.matrix.elements);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
ribbon: h,
|
|
108
|
+
piers: new Float32Array(g),
|
|
109
|
+
lamps: new Float32Array(_)
|
|
110
|
+
};
|
|
111
|
+
}, [
|
|
112
|
+
e,
|
|
113
|
+
t,
|
|
114
|
+
r
|
|
115
|
+
]);
|
|
116
|
+
return _(() => () => {
|
|
117
|
+
d.ribbon.geometry.dispose();
|
|
118
|
+
}, [d]), /* @__PURE__ */ E("group", { children: [/* @__PURE__ */ E(s, {
|
|
119
|
+
x: a,
|
|
120
|
+
z: l,
|
|
121
|
+
friction: 1.05,
|
|
122
|
+
children: [/* @__PURE__ */ T(D, { args: [d.ribbon.colliderVertices, d.ribbon.colliderIndices] }), /* @__PURE__ */ T("mesh", {
|
|
123
|
+
geometry: d.ribbon.geometry,
|
|
124
|
+
material: i,
|
|
125
|
+
receiveShadow: !0
|
|
126
|
+
})]
|
|
127
|
+
}), /* @__PURE__ */ E("group", {
|
|
128
|
+
position: [
|
|
129
|
+
a,
|
|
130
|
+
0,
|
|
131
|
+
l
|
|
132
|
+
],
|
|
133
|
+
children: [/* @__PURE__ */ T(m, {
|
|
134
|
+
matrices: d.piers,
|
|
135
|
+
kind: "square",
|
|
136
|
+
color: "#64748b"
|
|
137
|
+
}), /* @__PURE__ */ T(h, {
|
|
138
|
+
kitKey: "light_pole",
|
|
139
|
+
fitSpan: [
|
|
140
|
+
.6,
|
|
141
|
+
6.5,
|
|
142
|
+
.6
|
|
143
|
+
],
|
|
144
|
+
matrices: d.lamps
|
|
145
|
+
})]
|
|
146
|
+
})] });
|
|
147
|
+
}
|
|
148
|
+
function M({ seed: o = 77, pureMainland: s = !1, initialOrigin: c = [0, 0], onOriginRebase: m, renderCellExtra: h }) {
|
|
149
|
+
let S = p(), D = w((e) => e.camera), k = O(), A = y(() => new i(o), [o]), [M, N] = x(c), P = b([c[0], c[1]]), F = b([c[0], c[1]]), [I, L] = x(() => [Math.max(+!!s, Math.round(c[0] / n)), Math.round(c[1] / n)]), [R, z] = x(() => {
|
|
150
|
+
let e = Math.max(1, Math.round(c[0] / n)), t = Math.round(c[1] / n);
|
|
151
|
+
return s ? [
|
|
152
|
+
[e, t],
|
|
153
|
+
[e, t - 1],
|
|
154
|
+
[e, t + 1],
|
|
155
|
+
[e + 1, t]
|
|
156
|
+
] : [[1, 0]];
|
|
157
|
+
}), B = y(() => {
|
|
158
|
+
let n = u(o, 960), r = t(a(n, 64));
|
|
159
|
+
return {
|
|
160
|
+
tex: r,
|
|
161
|
+
roadMat: e(r, { preset: "ASPHALT" }).material
|
|
162
|
+
};
|
|
163
|
+
}, [o]);
|
|
164
|
+
_(() => () => {
|
|
165
|
+
B.roadMat.dispose(), B.tex.dispose();
|
|
166
|
+
}, [B]);
|
|
167
|
+
let V = y(() => {
|
|
168
|
+
let [e, t] = I, n = [];
|
|
169
|
+
for (let r = -1; r <= 1; r++) for (let i = -1; i <= 1; i++) {
|
|
170
|
+
let a = e + r, o = t + i;
|
|
171
|
+
a >= 1 && n.push([a, o]);
|
|
172
|
+
}
|
|
173
|
+
return n.sort((n, r) => Math.hypot(n[0] - e, n[1] - t) - Math.hypot(r[0] - e, r[1] - t)), n;
|
|
174
|
+
}, [I]);
|
|
175
|
+
v(() => {
|
|
176
|
+
let e = M[0] - P.current[0], t = M[1] - P.current[1];
|
|
177
|
+
(e !== 0 || t !== 0) && (P.current = [M[0], M[1]], F.current = [M[0], M[1]], f(S, D, e, t, k), m?.(M[0], M[1], e, t));
|
|
178
|
+
}, [
|
|
179
|
+
M,
|
|
180
|
+
S,
|
|
181
|
+
D,
|
|
182
|
+
k,
|
|
183
|
+
m
|
|
184
|
+
]), C(() => {
|
|
185
|
+
z((e) => {
|
|
186
|
+
let t = e.filter(([e, t]) => V.some(([n, r]) => n === e && r === t)), n = V.find(([e, n]) => !t.some(([t, r]) => t === e && r === n));
|
|
187
|
+
return !n && t.length === e.length ? e : n ? [...t, n] : t;
|
|
188
|
+
});
|
|
189
|
+
let [e, t] = P.current, [i, a] = d(S, D), o = e + i, c = t + a, l = r(o, c), u = l.chunkOriginX - e, f = l.chunkOriginZ - t;
|
|
190
|
+
(Math.abs(u) >= 192 || Math.abs(f) >= 192) && (l.chunkOriginX !== F.current[0] || l.chunkOriginZ !== F.current[1]) && (F.current = [l.chunkOriginX, l.chunkOriginZ], N([l.chunkOriginX, l.chunkOriginZ]));
|
|
191
|
+
let p = Math.max(+!!s, Math.round(o / n)), m = Math.round(c / n);
|
|
192
|
+
(p !== I[0] || m !== I[1]) && L([p, m]);
|
|
193
|
+
});
|
|
194
|
+
let H = -M[0], U = -M[1];
|
|
195
|
+
return /* @__PURE__ */ E("group", { children: [
|
|
196
|
+
!s && I[0] <= 1 && Math.abs(I[1]) <= 1 && /* @__PURE__ */ T(l, {
|
|
197
|
+
seed: o,
|
|
198
|
+
size: 960,
|
|
199
|
+
segments: 144,
|
|
200
|
+
settlementTier: "town",
|
|
201
|
+
offX: H,
|
|
202
|
+
offZ: U
|
|
203
|
+
}),
|
|
204
|
+
!s && I[0] <= 2 && Math.abs(I[1]) <= 1 && /* @__PURE__ */ T(j, {
|
|
205
|
+
seed: o,
|
|
206
|
+
islandSize: 960,
|
|
207
|
+
planner: A,
|
|
208
|
+
roadMat: B.roadMat,
|
|
209
|
+
offX: H,
|
|
210
|
+
offZ: U
|
|
211
|
+
}),
|
|
212
|
+
R.map(([e, t]) => /* @__PURE__ */ T(g, {
|
|
213
|
+
mx: e,
|
|
214
|
+
mz: t,
|
|
215
|
+
planner: A,
|
|
216
|
+
roadMat: B.roadMat,
|
|
217
|
+
offX: H,
|
|
218
|
+
offZ: U,
|
|
219
|
+
renderExtra: h
|
|
220
|
+
}, `mc_${e}_${t}`))
|
|
221
|
+
] });
|
|
222
|
+
}
|
|
223
|
+
export { M as KolmoLongDrive, k as computeLongDriveBridgeheadSpawn, A as computeLongDriveMainlandSpawn };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { syncRetroViewport as e } from "../shaders/retroShader.js";
|
|
2
|
+
import { useEffect as t, useRef as n } from "react";
|
|
3
|
+
import * as r from "three";
|
|
4
|
+
import { useFrame as i, useThree as a } from "@react-three/fiber";
|
|
5
|
+
import { RoomEnvironment as o } from "three/examples/jsm/environments/RoomEnvironment.js";
|
|
6
|
+
// src/engine/kolmoRigs.tsx
|
|
7
|
+
function s({ intensity: e = .65 }) {
|
|
8
|
+
let { gl: n, scene: i } = a();
|
|
9
|
+
return t(() => {
|
|
10
|
+
let t = new r.PMREMGenerator(n), a = new o(), s = t.fromScene(a, .04), c = i.environment, l = i.environmentIntensity;
|
|
11
|
+
return i.environment = s.texture, i.environmentIntensity = e, a.dispose(), t.dispose(), () => {
|
|
12
|
+
i.environment = c, i.environmentIntensity = l, s.dispose();
|
|
13
|
+
};
|
|
14
|
+
}, [
|
|
15
|
+
n,
|
|
16
|
+
i,
|
|
17
|
+
e
|
|
18
|
+
]), null;
|
|
19
|
+
}
|
|
20
|
+
var c = new r.Vector2();
|
|
21
|
+
function l({ onViewportChange: r } = {}) {
|
|
22
|
+
let { gl: o } = a(), s = n({
|
|
23
|
+
w: 0,
|
|
24
|
+
h: 0,
|
|
25
|
+
dpr: 0
|
|
26
|
+
});
|
|
27
|
+
return t(() => {
|
|
28
|
+
o.getDrawingBufferSize(c);
|
|
29
|
+
let t = o.getPixelRatio();
|
|
30
|
+
s.current = {
|
|
31
|
+
w: c.x,
|
|
32
|
+
h: c.y,
|
|
33
|
+
dpr: t
|
|
34
|
+
}, e(c.x, c.y, t), r?.(c.x, c.y, t);
|
|
35
|
+
}, [o, r]), i(() => {
|
|
36
|
+
o.getDrawingBufferSize(c);
|
|
37
|
+
let t = o.getPixelRatio(), n = s.current;
|
|
38
|
+
(c.x !== n.w || c.y !== n.h || t !== n.dpr) && (n.w = c.x, n.h = c.y, n.dpr = t, e(c.x, c.y, t), r?.(c.x, c.y, t));
|
|
39
|
+
}), null;
|
|
40
|
+
}
|
|
41
|
+
var u = new r.Vector3(-120, 85, -120), d = new r.Vector3(0, 0, 0), f = new r.Vector3(0, 1, 0), p = new r.Vector3(), m = new r.Vector3(), h = new r.Vector3();
|
|
42
|
+
new r.Matrix4().lookAt(u, d, f).extractBasis(p, m, h);
|
|
43
|
+
function g({ sunLightRef: e }) {
|
|
44
|
+
return t(() => {
|
|
45
|
+
let t = e.current;
|
|
46
|
+
if (!t) return;
|
|
47
|
+
let n = t.shadow, r = n.updateMatrices;
|
|
48
|
+
return n.updateMatrices = function(e) {
|
|
49
|
+
if (e === t && t.castShadow) {
|
|
50
|
+
let e = n.camera, r = n.mapSize.x || 1024, i = Math.max(1, e.right - e.left) / r, a = Math.round(t.target.position.dot(p) / i) * i, o = Math.round(t.target.position.dot(m) / i) * i, s = t.target.position.dot(h);
|
|
51
|
+
t.target.position.set(0, 0, 0).addScaledVector(p, a).addScaledVector(m, o).addScaledVector(h, s), t.position.copy(t.target.position).add(u), t.updateMatrixWorld(), t.target.updateMatrixWorld();
|
|
52
|
+
}
|
|
53
|
+
return r.call(this, e);
|
|
54
|
+
}, () => {
|
|
55
|
+
n.updateMatrices = r;
|
|
56
|
+
};
|
|
57
|
+
}, [e]), null;
|
|
58
|
+
}
|
|
59
|
+
export { l as RetroViewportSync, s as RoomEnvRig, g as ShadowSnapRig };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { type Trait, type TraitRecord, type World } from "koota";
|
|
2
3
|
import type { EcctrlHandle } from "@pinkaphant/ecctrl";
|
|
3
4
|
import type { EcctrlVehicleHandle } from "@pinkaphant/ecctrl/vehicle";
|
|
4
|
-
import { type RetroPresetId } from "../shaders/
|
|
5
|
-
export type KolmoControlMode = "foot" | "car" | "
|
|
5
|
+
import { type RetroPresetId } from "../shaders/retroShader.js";
|
|
6
|
+
export type KolmoControlMode = "foot" | "car" | "flight";
|
|
6
7
|
export interface VehicleTraitData {
|
|
7
8
|
id: string;
|
|
8
9
|
handle: EcctrlVehicleHandle | null;
|
|
@@ -10,7 +11,7 @@ export interface VehicleTraitData {
|
|
|
10
11
|
seatOffset: [number, number, number];
|
|
11
12
|
exitOffset: [number, number, number];
|
|
12
13
|
isFlight: boolean;
|
|
13
|
-
|
|
14
|
+
onOriginShift?: (dx: number, dz: number) => void;
|
|
14
15
|
}
|
|
15
16
|
export interface ActorTraitData {
|
|
16
17
|
id: string;
|
|
@@ -18,43 +19,67 @@ export interface ActorTraitData {
|
|
|
18
19
|
exitSpawnPos: [number, number, number] | null;
|
|
19
20
|
exitSpawnYaw: number;
|
|
20
21
|
exitLinVel: [number, number, number] | null;
|
|
22
|
+
onOriginShift?: (dx: number, dz: number) => void;
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
export declare const
|
|
24
|
-
|
|
25
|
-
export declare const ActorTrait: import("koota").Trait<() => ActorTraitData>;
|
|
26
|
-
/** True SoA scalar schema trait (`trait({ ... })`) for fast proximity queries. */
|
|
27
|
-
export declare const InteractableTrait: import("koota").Trait<{
|
|
24
|
+
export declare const VehicleTrait: Trait<() => VehicleTraitData>;
|
|
25
|
+
export declare const ActorTrait: Trait<() => ActorTraitData>;
|
|
26
|
+
export declare const InteractableTrait: Trait<{
|
|
28
27
|
id: string;
|
|
29
28
|
radius: number;
|
|
30
29
|
kind: "vehicle" | "prop";
|
|
31
30
|
}>;
|
|
31
|
+
export interface FloatingOriginRapierSync {
|
|
32
|
+
world: {
|
|
33
|
+
timestep: number;
|
|
34
|
+
propagateModifiedBodyPositionsToColliders(): void;
|
|
35
|
+
step(): void;
|
|
36
|
+
};
|
|
37
|
+
rigidBodyStates?: Map<number, {
|
|
38
|
+
object: THREE.Object3D;
|
|
39
|
+
invertedWorldMatrix: THREE.Matrix4;
|
|
40
|
+
scale: THREE.Vector3;
|
|
41
|
+
meshType?: string;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
type ShiftableBody = {
|
|
45
|
+
handle?: number;
|
|
46
|
+
translation(): {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
z: number;
|
|
50
|
+
};
|
|
51
|
+
rotation?(): {
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
z: number;
|
|
55
|
+
w: number;
|
|
56
|
+
};
|
|
57
|
+
setTranslation(t: {
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
z: number;
|
|
61
|
+
}, wake: boolean): void;
|
|
62
|
+
};
|
|
32
63
|
export interface FloatingBodyTraitData {
|
|
33
64
|
id: string;
|
|
34
|
-
getBody: () =>
|
|
35
|
-
translation(): {
|
|
36
|
-
x: number;
|
|
37
|
-
y: number;
|
|
38
|
-
z: number;
|
|
39
|
-
};
|
|
40
|
-
setTranslation(t: {
|
|
41
|
-
x: number;
|
|
42
|
-
y: number;
|
|
43
|
-
z: number;
|
|
44
|
-
}, wake: boolean): void;
|
|
45
|
-
} | null;
|
|
65
|
+
getBody: () => ShiftableBody | null;
|
|
46
66
|
}
|
|
47
|
-
export declare const FloatingBodyTrait:
|
|
48
|
-
export declare const PilotLink: import("koota").Relation<
|
|
49
|
-
|
|
50
|
-
export declare const WorldSessionTrait: import("koota").Trait<{
|
|
67
|
+
export declare const FloatingBodyTrait: Trait<() => FloatingBodyTraitData>;
|
|
68
|
+
export declare const PilotLink: import("koota").Relation<Trait<Record<string, never>>>;
|
|
69
|
+
export declare const WorldSessionTrait: Trait<{
|
|
51
70
|
activeVehicleId: string;
|
|
52
71
|
activeRetroPreset: RetroPresetId;
|
|
53
72
|
}>;
|
|
54
73
|
export declare const kolmoWorld: World;
|
|
55
|
-
/** Safely resolves the active Koota `World` from `<WorldProvider>` (falling back to `kolmoWorld` when rendered standalone in tests). */
|
|
56
74
|
export declare function useActiveKolmoWorld(): World;
|
|
57
75
|
export declare function ensureWorldSession(w: World): void;
|
|
76
|
+
/**
|
|
77
|
+
* Subscribes to a world-level Koota trait directly on `world` without calling `useWorld()`,
|
|
78
|
+
* so `<KolmoWorld world={null}>` and standalone `<KolmoPhysics>` never throw without `<WorldProvider>`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function useWorldTrait<T extends Trait>(world: World | null | undefined, t: T): TraitRecord<T> | undefined;
|
|
81
|
+
export declare function readFloatingOriginAnchorXZ(world: World, camera: THREE.Camera | null): [number, number];
|
|
82
|
+
export declare function shiftFloatingOriginEntities(world: World, camera: THREE.Camera | null, dx: number, dz: number, rapier?: FloatingOriginRapierSync | null): void;
|
|
58
83
|
export interface KolmoTelemetryState {
|
|
59
84
|
speedKmh: number;
|
|
60
85
|
rpm: number;
|
|
@@ -72,3 +97,4 @@ export declare const kolmoActions: import("koota").Actions<{
|
|
|
72
97
|
exitVehicle: () => void;
|
|
73
98
|
setRetroPreset: (preset: RetroPresetId) => void;
|
|
74
99
|
}>;
|
|
100
|
+
export {};
|
|
@@ -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;
|