@pinkaphant/kolmo 0.1.3 → 0.2.1

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.
@@ -4,22 +4,23 @@ import { createVehiclePanelAnimator as i } from "../importer/vehiclePanelAnim.js
4
4
  import { KolmoEmitterRig as a } from "../shaders/plumeAndSparkle.js";
5
5
  import { applySceneRetroMaterials as o } from "../shaders/retroShader.js";
6
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";
7
+ import { InteractableTrait as te, VehicleTrait as s, WorldSessionTrait as c, ensureWorldSession as ne, kolmoActions as l, useActiveKolmoWorld as re, useWorldTrait as u } from "./kolmoStore.js";
8
+ import { stepKolmoVehicleFrame as ie } from "./kolmoVehicleDriver.js";
9
+ import { useCallback as d, useContext as ae, useEffect as f, useLayoutEffect as p, useMemo as m, useRef as h, useState as g } from "react";
10
+ import * as oe from "three";
11
+ import { useFrame as se } from "@react-three/fiber";
12
+ import { cloneKhrBundle as ce, loadKhrGlb as _, useKhrGlb as v } from "@khr3/core";
13
+ import { jsx as y, jsxs as le } from "react/jsx-runtime";
14
+ import { useRapier as ue } from "@react-three/rapier";
14
15
  import { KhrVehicle as b } from "@khr3/core/vehicle";
15
16
  // src/engine/kolmoVehicle.tsx
16
- function ue(e) {
17
+ function de(e) {
17
18
  e.traverse((e) => {
18
19
  let n = e.userData?.gltfExtensions?.[t];
19
20
  n && !e.userData.KOLMO_emitter && (e.userData[t] = n);
20
21
  });
21
22
  }
22
- function de(e) {
23
+ function fe(e) {
23
24
  let t = [];
24
25
  for (let n of e) n.traverse((e) => {
25
26
  let n = e;
@@ -38,35 +39,40 @@ function de(e) {
38
39
  for (let e of t) e.dispose();
39
40
  };
40
41
  }
41
- function x({ id: t, sourceBundle: o, rawGlbBytes: h, position: g = [
42
+ function x({ id: t, sourceBundle: o, rawGlbBytes: g, position: _ = [
42
43
  0,
43
44
  .35,
44
45
  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 ?? [
46
+ ], rotation: v, piloted: x = !1, flightMode: S = !1, vehicleMode: C, enable: pe = !0, ccd: w, linearDamping: T, angularDamping: E, userData: D, onCollisionEnter: O, wheelConfig: k, propellerConfig: A, carConfig: j, droneConfig: M, vehicleRef: N, getInput: me, driver: P, cameraController: F, children: he }) {
47
+ let I = ae(e), L = re();
48
+ p(() => {
49
+ ne(L);
50
+ }, [L]);
51
+ let R = u(L, c), ge = ee(me), z = m(() => ce(o), [o]), B = m(() => i(z), [z]), V = m(() => (de(z.scene), r(z.scene, g)), [z, g]);
52
+ p(() => fe([
53
+ z.scene,
54
+ ...z.wheels.map((e) => e.object),
55
+ ...z.propellers.map((e) => e.object)
56
+ ]), [z]);
57
+ let H = !!(C === "rocket" || S || C !== "drive" && z.propellers.length > 0), U = m(() => V.sockets.find((e) => e.role === "seat" || e.role === "optic")?.localPosition ?? [
57
58
  0,
58
59
  .65,
59
60
  0
60
- ], [U]), K = p(() => U.sockets.find((e) => e.role === "exit")?.localPosition ?? [
61
+ ], [V]), W = m(() => V.sockets.find((e) => e.role === "exit")?.localPosition ?? [
61
62
  -1.55,
62
63
  .45,
63
64
  0
64
- ], [U]), q = p(() => {
65
- if (A || C !== void 0) return {
65
+ ], [V]), G = m(() => {
66
+ if (k || C !== void 0) return {
66
67
  ...C === void 0 ? {} : { enable: C === "drive" },
68
+ ...k ?? {}
69
+ };
70
+ }, [k, C]), K = m(() => {
71
+ if (A || C !== void 0) return {
72
+ ...C === void 0 ? {} : { enable: C === "rocket" },
67
73
  ...A ?? {}
68
74
  };
69
- }, [A, C]), J = p(() => W ? {
75
+ }, [A, C]), q = m(() => H ? {
70
76
  controlMode: "VELOCITY",
71
77
  maxHorizSpeed: 46,
72
78
  maxVertSpeed: 16,
@@ -74,21 +80,21 @@ function x({ id: t, sourceBundle: o, rawGlbBytes: h, position: g = [
74
80
  maxTiltAngle: .52,
75
81
  HORIZ_VEL_P: 1.8,
76
82
  VERT_VEL_P: 2.8,
77
- ...V.droneTune ?? {},
83
+ ...z.droneTune ?? {},
78
84
  ...M ?? {}
79
85
  } : M, [
80
- W,
81
- V.droneTune,
86
+ H,
87
+ z.droneTune,
82
88
  M
83
- ]), Y = m(null), pe = m([
84
- g[0],
85
- g[1],
86
- g[2]
87
- ]), X = m(_ ? [
89
+ ]), J = h(null), _e = h([
88
90
  _[0],
89
91
  _[1],
90
92
  _[2]
91
- ] : void 0), Z = m(n()), Q = m(new se.Vector3()), me = m({
93
+ ]), Y = h(v ? [
94
+ v[0],
95
+ v[1],
96
+ v[2]
97
+ ] : void 0), X = h(n()), Z = h(new oe.Vector3()), ve = h({
92
98
  camInit: !1,
93
99
  cockpit: !1,
94
100
  prevCam: !1,
@@ -96,7 +102,7 @@ function x({ id: t, sourceBundle: o, rawGlbBytes: h, position: g = [
96
102
  prevR: !1,
97
103
  turnL: !1,
98
104
  turnR: !1
99
- }), he = m({
105
+ }), ye = h({
100
106
  forward: !1,
101
107
  backward: !1,
102
108
  steerLeft: !1,
@@ -110,9 +116,9 @@ function x({ id: t, sourceBundle: o, rawGlbBytes: h, position: g = [
110
116
  pitchBackward: !1,
111
117
  rollLeft: !1,
112
118
  rollRight: !1
113
- }), $ = u((e, t) => {
114
- Q.current.x -= e, Q.current.z -= t;
115
- let n = Y.current;
119
+ }), Q = d((e, t) => {
120
+ Z.current.x -= e, Z.current.z -= t;
121
+ let n = J.current;
116
122
  if (n) {
117
123
  n.currPos.x -= e, n.currPos.z -= t;
118
124
  for (let r of n.wheelsInfo.values()) {
@@ -121,107 +127,108 @@ function x({ id: t, sourceBundle: o, rawGlbBytes: h, position: g = [
121
127
  }
122
128
  }
123
129
  }, []);
124
- d(() => {
125
- let e = R.spawn(s({
130
+ f(() => {
131
+ let e = L.spawn(s({
126
132
  id: t,
127
- handle: Y.current,
128
- centerOfMass: [...V.centerOfMass],
129
- seatOffset: G,
130
- exitOffset: K,
131
- isFlight: W,
132
- onOriginShift: $
133
+ handle: J.current,
134
+ centerOfMass: [...z.centerOfMass],
135
+ seatOffset: U,
136
+ exitOffset: W,
137
+ isFlight: H,
138
+ onOriginShift: Q
133
139
  }), te({
134
140
  id: t,
135
141
  radius: 4.2,
136
142
  kind: "vehicle"
137
143
  }));
138
- return x && !R.get(c)?.activeVehicleId && l(R).boardVehicle(t), () => {
139
- R.get(c)?.activeVehicleId === t && l(R).exitVehicle(), e.destroy();
144
+ return x && !L.get(c)?.activeVehicleId && l(L).boardVehicle(t), () => {
145
+ L.get(c)?.activeVehicleId === t && l(L).exitVehicle(), e.destroy();
140
146
  };
141
147
  }, [
142
- R,
148
+ L,
143
149
  t,
144
- V,
145
- G,
146
- K,
150
+ z,
151
+ U,
147
152
  W,
153
+ H,
148
154
  x,
149
- $
155
+ Q
150
156
  ]);
151
- let ge = u((e) => {
152
- Y.current = e, N && (N.current = e);
153
- for (let n of R.query(s)) {
157
+ let be = d((e) => {
158
+ J.current = e, N && (N.current = e);
159
+ for (let n of L.query(s)) {
154
160
  let r = n.get(s);
155
161
  r && r.id === t && n.set(s, {
156
162
  ...r,
157
163
  handle: e,
158
- onOriginShift: $
164
+ onOriginShift: Q
159
165
  });
160
166
  }
161
167
  }, [
162
- R,
168
+ L,
163
169
  t,
164
170
  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({
171
+ Q
172
+ ]), { world: $ } = ue(), xe = R?.activeVehicleId === t || x && !R?.activeVehicleId;
173
+ return se((e, n) => {
174
+ let r = $.timestep > 0 ? $.timestep : Math.min(Math.max(n, 1e-4), 1 / 30);
175
+ B.step(r);
176
+ let i = J.current;
177
+ i && i.body && (P ? (P(i, r, e), F && F(i, r, e)) : ie({
172
178
  id: t,
173
179
  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,
180
+ keys: ge(),
181
+ cmd: ye.current,
182
+ sig: X.current,
183
+ st: ve.current,
184
+ camTarget: Z.current,
185
+ centerOfMass: z.centerOfMass,
186
+ seatOffset: U,
187
+ isPiloted: xe,
188
+ isFlight: H,
183
189
  dt: r,
184
190
  state: e,
185
191
  cameraController: F
186
192
  }));
187
- }), /* @__PURE__ */ v("group", {
193
+ }), /* @__PURE__ */ y("group", {
188
194
  onClick: (e) => {
189
- e.delta <= 5 && H.toggleHitObject(e.object) && e.stopPropagation();
195
+ e.delta <= 5 && B.toggleHitObject(e.object) && e.stopPropagation();
190
196
  },
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 },
197
+ children: /* @__PURE__ */ le(b, {
198
+ ref: be,
199
+ bundle: z,
200
+ position: _e.current,
201
+ enable: pe,
202
+ enableCustomGravity: I,
203
+ ...Y.current === void 0 ? {} : { rotation: Y.current },
204
+ ...w === void 0 ? {} : { ccd: w },
205
+ ...T === void 0 ? {} : { linearDamping: T },
206
+ ...E === void 0 ? {} : { angularDamping: E },
207
+ ...D === void 0 ? {} : { userData: D },
208
+ ...O === void 0 ? {} : { onCollisionEnter: O },
209
+ ...G === void 0 ? {} : { wheelConfig: G },
210
+ ...K === void 0 ? {} : { propellerConfig: K },
204
211
  ...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]
212
+ ...q === void 0 ? {} : { droneConfig: q },
213
+ children: [/* @__PURE__ */ y(a, {
214
+ emitters: V.emitters,
215
+ signalsRef: X
216
+ }), he]
210
217
  })
211
218
  });
212
219
  }
213
220
  function S(e) {
214
- return /* @__PURE__ */ v(x, {
221
+ return /* @__PURE__ */ y(x, {
215
222
  ...e,
216
- sourceBundle: _(e.src)
223
+ sourceBundle: v(e.src)
217
224
  });
218
225
  }
219
226
  function C(e) {
220
- let [t, n] = h(null);
221
- return d(() => {
227
+ let [t, n] = g(null);
228
+ return f(() => {
222
229
  if (e.bundle || e.src || !e.rawGlbBytes) return;
223
230
  let t = !0;
224
- return g(e.rawGlbBytes).then((e) => {
231
+ return _(e.rawGlbBytes).then((e) => {
225
232
  t && n(e);
226
233
  }), () => {
227
234
  t = !1;
@@ -230,13 +237,13 @@ function C(e) {
230
237
  e.bundle,
231
238
  e.src,
232
239
  e.rawGlbBytes
233
- ]), e.bundle ? /* @__PURE__ */ v(x, {
240
+ ]), e.bundle ? /* @__PURE__ */ y(x, {
234
241
  ...e,
235
242
  sourceBundle: e.bundle
236
- }) : e.src ? /* @__PURE__ */ v(S, {
243
+ }) : e.src ? /* @__PURE__ */ y(S, {
237
244
  ...e,
238
245
  src: e.src
239
- }) : t ? /* @__PURE__ */ v(x, {
246
+ }) : t ? /* @__PURE__ */ y(x, {
240
247
  ...e,
241
248
  sourceBundle: t
242
249
  }) : null;
@@ -2,37 +2,28 @@ 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(), s = new t.Vector3();
6
- function c(t) {
7
- let { id: c, veh: l, keys: u, cmd: d, sig: f, st: p, camTarget: m, centerOfMass: h, seatOffset: g, isPiloted: _, isFlight: v, dt: y, state: b, cameraController: x } = t;
8
- if (_) {
9
- if (u.cameraView && !p.prevCam && (p.cockpit = !p.cockpit), p.prevCam = u.cameraView, v) d.pitchForward = u.forward, d.pitchBackward = u.backward, d.yawLeft = u.left, d.yawRight = u.right, d.rollLeft = u.turnLeft, d.rollRight = u.turnRight, d.throttleUp = u.brake, d.throttleDown = u.descend, d.forward = !1, d.backward = !1, d.steerLeft = !1, d.steerRight = !1, d.brake = !1, u.boost && l.body.applyImpulse(s.copy(l.bodyZAxis).multiplyScalar(l.body.mass() * 14 * y), !1);
10
- else if (u.turnLeft && !p.prevL && (p.turnL = !p.turnL, p.turnR = !1), u.turnRight && !p.prevR && (p.turnR = !p.turnR, p.turnL = !1), p.prevL = u.turnLeft, p.prevR = u.turnRight, d.forward = u.forward, d.backward = u.backward, d.steerLeft = u.left, d.steerRight = u.right, d.brake = u.brake, d.pitchForward = !1, d.pitchBackward = !1, d.throttleUp = !1, d.throttleDown = !1, d.yawLeft = !1, d.yawRight = !1, d.rollLeft = !1, d.rollRight = !1, u.boost && u.forward) {
11
- for (let e of l.wheelsInfo.values()) if (e.current.rayHit) {
12
- l.body.applyImpulse(s.copy(l.bodyZAxis).multiplyScalar(l.body.mass() * 6.5 * y), !1);
13
- break;
14
- }
15
- }
16
- l.setMovement(d);
5
+ var r = new t.Vector3(), i = new t.Vector3(), a = new t.Vector3(), o = new t.Vector3();
6
+ function s(t) {
7
+ let { id: s, veh: c, keys: l, cmd: u, sig: d, st: f, camTarget: p, centerOfMass: m, seatOffset: h, isPiloted: g, isFlight: _, dt: v, state: y, cameraController: b } = t;
8
+ g && (l.cameraView && !f.prevCam && (f.cockpit = !f.cockpit), f.prevCam = l.cameraView, _ ? (u.pitchForward = l.forward, u.pitchBackward = l.backward, u.yawLeft = l.left, u.yawRight = l.right, u.rollLeft = l.turnLeft, u.rollRight = l.turnRight, u.throttleUp = l.brake, u.throttleDown = l.descend, u.forward = !1, u.backward = !1, u.steerLeft = !1, u.steerRight = !1, u.brake = !1) : (l.turnLeft && !f.prevL && (f.turnL = !f.turnL, f.turnR = !1), l.turnRight && !f.prevR && (f.turnR = !f.turnR, f.turnL = !1), f.prevL = l.turnLeft, f.prevR = l.turnRight, u.forward = l.forward, u.backward = l.backward, u.steerLeft = l.left, u.steerRight = l.right, u.brake = l.brake, u.pitchForward = !1, u.pitchBackward = !1, u.throttleUp = !1, u.throttleDown = !1, u.yawLeft = !1, u.yawRight = !1, u.rollLeft = !1, u.rollRight = !1), c.setMovement(u));
9
+ let x = 0, S = 0;
10
+ for (let e of c.wheelsInfo.values()) e.current.rayHit && e.current.slipStrength > x && (x = e.current.slipStrength);
11
+ if (c.propellersInfo.size > 0) {
12
+ for (let e of c.propellersInfo.values()) S += e.current.finalThrottle;
13
+ S /= c.propellersInfo.size;
17
14
  }
18
- let S = 0, C = 0;
19
- for (let e of l.wheelsInfo.values()) e.current.rayHit && e.current.slipStrength > S && (S = e.current.slipStrength);
20
- if (l.propellersInfo.size > 0) {
21
- for (let e of l.propellersInfo.values()) C += e.current.finalThrottle;
22
- C /= l.propellersInfo.size;
23
- }
24
- let w = l.currLinVel.dot(l.bodyZAxis);
25
- if (f.throttle = _ ? v ? u.forward || u.brake ? 1 : Math.max(.22, C) : +!!u.forward : 0, f.boost = _ ? v ? u.boost ? 1 : u.forward ? .58 : .16 : u.boost && u.forward ? 1 : 0 : 0, f.brake = _ && !v && (u.brake || u.backward && w > 1) ? 1 : 0, f.reverse = _ && !v && u.backward && w <= 1 ? 1 : 0, f.slip = Math.min(1, S), f.turn_l = +!!p.turnL, f.turn_r = +!!p.turnR, f.headlight = 1, f.always = 1, !_) return;
26
- if (e.speedKmh = l.currLinVel.length() * 3.6, e.rpm = Math.round(v ? 1800 + f.throttle * 6200 + f.boost * 4200 : l.engineRPM), e.gear = v ? u.boost ? 2 : 1 : l.gearIndex + 1, e.throttle = f.throttle, e.boost = f.boost, e.mode = v ? "flight" : "car", e.activeVehicleId = c, x) {
27
- x(l, y, b);
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);
28
19
  return;
29
20
  }
30
- if (r.copy(l.upAxis), r.lengthSq() < 1e-6 && r.copy(l.bodyYAxis), p.cockpit) {
31
- a.set(g[0] - h[0], g[1] - h[1] + .32, g[2] - h[2]).applyQuaternion(l.currQuat).add(l.currPos), o.copy(a).addScaledVector(l.bodyZAxis, 24), n.damp3(b.camera.position, a, .04, y), n.damp3(b.camera.up, l.bodyYAxis, .08, y), b.camera.lookAt(o);
21
+ if (r.copy(c.upAxis), r.lengthSq() < 1e-6 && r.copy(c.bodyYAxis), f.cockpit) {
22
+ a.set(h[0] - m[0], h[1] - m[1] + .32, h[2] - m[2]).applyQuaternion(c.currQuat).add(c.currPos), o.copy(a).addScaledVector(c.bodyZAxis, 24), n.damp3(y.camera.position, a, .04, v), n.damp3(y.camera.up, c.bodyYAxis, .08, v), y.camera.lookAt(o);
32
23
  return;
33
24
  }
34
- i.copy(l.bodyZAxis), v || i.projectOnPlane(r).normalize(), i.lengthSq() < 1e-6 && i.copy(l.bodyZAxis);
35
- let T = v ? 11.2 : 6.8, E = v ? 3.1 : 2.15;
36
- a.copy(l.currPos).addScaledVector(i, -T).addScaledVector(r, E), o.copy(l.currPos).addScaledVector(i, v ? 7.5 : 3.6).addScaledVector(r, .65), p.camInit ||= (b.camera.position.copy(a), m.copy(o), !0), n.damp3(b.camera.position, a, .14, y), n.damp3(m, o, .08, y), n.damp3(b.camera.up, r, .16, y), b.camera.lookAt(m);
25
+ i.copy(c.bodyZAxis), _ || i.projectOnPlane(r).normalize(), i.lengthSq() < 1e-6 && i.copy(c.bodyZAxis);
26
+ let w = _ ? 11.2 : 6.8, T = _ ? 3.1 : 2.15;
27
+ a.copy(c.currPos).addScaledVector(i, -w).addScaledVector(r, T), o.copy(c.currPos).addScaledVector(i, _ ? 7.5 : 3.6).addScaledVector(r, .65), f.camInit ||= (y.camera.position.copy(a), p.copy(o), !0), n.damp3(y.camera.position, a, .14, v), n.damp3(p, o, .08, v), n.damp3(y.camera.up, r, .16, v), y.camera.lookAt(p);
37
28
  }
38
- export { c as stepKolmoVehicleFrame };
29
+ export { s as stepKolmoVehicleFrame };
@@ -1,22 +1,22 @@
1
1
  import { KolmoGravityContext as e, KolmoPhysics as t, useIsKolmoCustomGravity as n, useOptionalKootaWorld as r } from "../physics/index.js";
2
2
  import { KolmoSkybox as i } from "../shaders/celestialBackdrop.js";
3
3
  import { syncRetroUniforms as a } from "../shaders/retroShader.js";
4
- import { EMPTY_KOLMO_INPUT as o, KOLMO_KEY_MAP as s, useKolmoInput as c } from "./kolmoInput.js";
5
- import { RetroViewportSync as l, RoomEnvRig as u, ShadowSnapRig as d } from "./kolmoRigs.js";
6
- import { WorldSessionTrait as f, ensureWorldSession as p, kolmoActions as m, kolmoWorld as h, useWorldTrait as g } from "./kolmoStore.js";
7
- import { useEffect as _, useLayoutEffect as v } from "react";
8
- import * as y from "three";
9
- import { Canvas as b } from "@react-three/fiber";
10
- import { KeyboardControls as x } from "@react-three/drei";
11
- import { WorldProvider as S } from "koota/react";
12
- import { Fragment as C, jsx as w, jsxs as T } from "react/jsx-runtime";
4
+ import { EMPTY_KOLMO_INPUT as o, KOLMO_KEY_MAP as s, KolmoKeyboardBridge as c, KolmoKeyboardContext as l, useKolmoInput as u } from "./kolmoInput.js";
5
+ import { RetroViewportSync as d, RoomEnvRig as f, ShadowSnapRig as p } from "./kolmoRigs.js";
6
+ import { WorldSessionTrait as m, ensureWorldSession as h, kolmoActions as g, kolmoWorld as _, useWorldTrait as v } from "./kolmoStore.js";
7
+ import { useEffect as y, useLayoutEffect as b } from "react";
8
+ import * as x from "three";
9
+ import { Canvas as S } from "@react-three/fiber";
10
+ import { KeyboardControls as C } from "@react-three/drei";
11
+ import { WorldProvider as w } from "koota/react";
12
+ import { Fragment as T, jsx as E, jsxs as D } from "react/jsx-runtime";
13
13
  // src/engine/kolmoWorld.tsx
14
- function E({ children: e, className: t, style: n, fov: r = 56, near: i = .15, far: a = 6500, cameraPosition: o = [
14
+ function O({ children: e, className: t, style: n, fov: r = 56, near: i = .15, far: a = 6500, cameraPosition: o = [
15
15
  0,
16
16
  3.2,
17
17
  -8.5
18
- ], dpr: s = [1, 1.5], frameloop: c = "always", shadows: l = "basic", toneMapping: d, onCanvasReady: f, onContextLost: p, roomEnv: m = !1 }) {
19
- return /* @__PURE__ */ T(b, {
18
+ ], dpr: s = [1, 1.5], frameloop: c = "always", shadows: l = "basic", toneMapping: u, onCanvasReady: d, onContextLost: p, roomEnv: m = !1 }) {
19
+ return /* @__PURE__ */ D(S, {
20
20
  className: t,
21
21
  style: n ?? {
22
22
  width: "100%",
@@ -29,7 +29,7 @@ function E({ children: e, className: t, style: n, fov: r = 56, near: i = .15, fa
29
29
  gl: {
30
30
  antialias: !1,
31
31
  powerPreference: "high-performance",
32
- ...d === void 0 ? {} : { toneMapping: d }
32
+ ...u === void 0 ? {} : { toneMapping: u }
33
33
  },
34
34
  camera: {
35
35
  fov: r,
@@ -38,44 +38,44 @@ function E({ children: e, className: t, style: n, fov: r = 56, near: i = .15, fa
38
38
  position: o
39
39
  },
40
40
  onCreated: ({ gl: e }) => {
41
- e.outputColorSpace = y.SRGBColorSpace;
41
+ e.outputColorSpace = x.SRGBColorSpace;
42
42
  let t = e.domElement;
43
- f?.(t), p && (t.addEventListener("webglcontextlost", (e) => {
43
+ d?.(t), p && (t.addEventListener("webglcontextlost", (e) => {
44
44
  e.preventDefault(), p(!0);
45
45
  }), t.addEventListener("webglcontextrestored", () => p(!1)));
46
46
  },
47
- children: [m !== !1 && /* @__PURE__ */ w(u, { intensity: typeof m == "number" ? m : .65 }), e]
47
+ children: [m !== !1 && /* @__PURE__ */ E(f, { intensity: typeof m == "number" ? m : .65 }), e]
48
48
  });
49
49
  }
50
- function D({ world: e, retroPreset: t }) {
51
- v(() => {
52
- e && p(e);
50
+ function k({ world: e, retroPreset: t }) {
51
+ b(() => {
52
+ e && h(e);
53
53
  }, [e]);
54
- let n = g(e, f);
55
- return _(() => {
56
- e ? t ? m(e).setRetroPreset(t) : n?.activeRetroPreset && a(n.activeRetroPreset) : t && a(t);
54
+ let n = v(e, m);
55
+ return y(() => {
56
+ e ? t ? g(e).setRetroPreset(t) : n?.activeRetroPreset && a(n.activeRetroPreset) : t && a(t);
57
57
  }, [
58
58
  e,
59
59
  t,
60
60
  n?.activeRetroPreset
61
61
  ]), null;
62
62
  }
63
- function O({ gravity: e = "planar", paused: n = !1, timeScale: a = 1, maxDelta: o, physicsDebug: c = !1, retroPreset: l, skybox: u = "nebula", lighting: f = "default", fogExp2: m, sunLightRef: g, shadowSnap: _ = !1, world: y = h, keyboardMap: b = s, children: E }) {
64
- let O = r(), k = y === null ? O : y;
65
- v(() => {
66
- k && p(k);
67
- }, [k]);
68
- let A = /* @__PURE__ */ T(C, { children: [
69
- /* @__PURE__ */ w(D, {
70
- world: k,
71
- retroPreset: l
63
+ function A({ gravity: e = "planar", paused: n = !1, timeScale: a = 1, maxDelta: o, physicsDebug: u = !1, retroPreset: d, skybox: f = "nebula", lighting: m = "default", fogExp2: g, sunLightRef: v, shadowSnap: y = !1, world: x = _, keyboardMap: S = s, children: O }) {
64
+ let A = r(), j = x === null ? A : x;
65
+ b(() => {
66
+ j && h(j);
67
+ }, [j]);
68
+ let M = /* @__PURE__ */ D(T, { children: [
69
+ /* @__PURE__ */ E(k, {
70
+ world: j,
71
+ retroPreset: d
72
72
  }),
73
- _ && g && /* @__PURE__ */ w(d, { sunLightRef: g }),
74
- u === "nebula" && /* @__PURE__ */ w(i, {}),
75
- u === "day" && /* @__PURE__ */ T(C, { children: [/* @__PURE__ */ w("color", {
73
+ y && v && /* @__PURE__ */ E(p, { sunLightRef: v }),
74
+ f === "nebula" && /* @__PURE__ */ E(i, {}),
75
+ f === "day" && /* @__PURE__ */ D(T, { children: [/* @__PURE__ */ E("color", {
76
76
  attach: "background",
77
77
  args: ["#6ba6d6"]
78
- }), !m && /* @__PURE__ */ w("fog", {
78
+ }), !g && /* @__PURE__ */ E("fog", {
79
79
  attach: "fog",
80
80
  args: [
81
81
  "#9dc4e2",
@@ -83,18 +83,18 @@ function O({ gravity: e = "planar", paused: n = !1, timeScale: a = 1, maxDelta:
83
83
  520
84
84
  ]
85
85
  })] }),
86
- m && /* @__PURE__ */ w("fogExp2", {
86
+ g && /* @__PURE__ */ E("fogExp2", {
87
87
  attach: "fog",
88
- args: m
88
+ args: g
89
89
  }),
90
- f === "default" && /* @__PURE__ */ T(C, { children: [
91
- /* @__PURE__ */ w("hemisphereLight", { args: [
90
+ m === "default" && /* @__PURE__ */ D(T, { children: [
91
+ /* @__PURE__ */ E("hemisphereLight", { args: [
92
92
  "#b8dcff",
93
93
  "#241d30",
94
94
  .8
95
95
  ] }),
96
- /* @__PURE__ */ w("directionalLight", {
97
- ref: g,
96
+ /* @__PURE__ */ E("directionalLight", {
97
+ ref: v,
98
98
  position: [
99
99
  48,
100
100
  76,
@@ -105,7 +105,7 @@ function O({ gravity: e = "planar", paused: n = !1, timeScale: a = 1, maxDelta:
105
105
  castShadow: !0,
106
106
  "shadow-mapSize": [1024, 1024]
107
107
  }),
108
- /* @__PURE__ */ w("directionalLight", {
108
+ /* @__PURE__ */ E("directionalLight", {
109
109
  position: [
110
110
  -42,
111
111
  28,
@@ -115,22 +115,25 @@ function O({ gravity: e = "planar", paused: n = !1, timeScale: a = 1, maxDelta:
115
115
  color: "#68a8ff"
116
116
  })
117
117
  ] }),
118
- /* @__PURE__ */ w(t, {
118
+ /* @__PURE__ */ E(t, {
119
119
  gravity: e,
120
120
  paused: n,
121
121
  timeScale: a,
122
122
  maxDelta: o,
123
- physicsDebug: c,
123
+ physicsDebug: u,
124
124
  world: null,
125
- children: E
125
+ children: O
126
126
  })
127
- ] }), j = b ? /* @__PURE__ */ w(x, {
128
- map: b,
129
- children: A
130
- }) : A;
131
- return y !== null && y !== O ? /* @__PURE__ */ w(S, {
132
- world: y,
133
- children: j
134
- }) : j;
127
+ ] }), N = S ? /* @__PURE__ */ E(C, {
128
+ map: S,
129
+ children: /* @__PURE__ */ E(c, { children: M })
130
+ }) : /* @__PURE__ */ E(l.Provider, {
131
+ value: null,
132
+ children: M
133
+ });
134
+ return x !== null && x !== A ? /* @__PURE__ */ E(w, {
135
+ world: x,
136
+ children: N
137
+ }) : N;
135
138
  }
136
- export { o as EMPTY_KOLMO_INPUT, s as KOLMO_KEY_MAP, E as KolmoCanvas, e as KolmoGravityContext, t as KolmoPhysics, O as KolmoWorld, l as RetroViewportSync, u as RoomEnvRig, d as ShadowSnapRig, n as useIsKolmoCustomGravity, c as useKolmoInput, r as useOptionalKootaWorld };
139
+ export { o as EMPTY_KOLMO_INPUT, s as KOLMO_KEY_MAP, O as KolmoCanvas, e as KolmoGravityContext, t as KolmoPhysics, A as KolmoWorld, d as RetroViewportSync, f as RoomEnvRig, p as ShadowSnapRig, n as useIsKolmoCustomGravity, u as useKolmoInput, r as useOptionalKootaWorld };
@@ -1,44 +1,28 @@
1
1
  import { MACRO_SIZE_M as e } from "../world/macroCellSchema.js";
2
- import { useLayoutEffect as t, useRef as n } from "react";
3
- import * as r from "three";
4
- import { jsx as i } from "react/jsx-runtime";
5
- import { RigidBody as a } from "@react-three/rapier";
2
+ import "react";
3
+ import { jsx as t } from "react/jsx-runtime";
4
+ import { RigidBody as n } from "@react-three/rapier";
6
5
  // src/engine/shiftedFixedBody.tsx
7
- var o = new r.Euler(), s = new r.Quaternion();
8
- function c({ x: e, y: r = 0, z: c, yaw: l = 0, friction: u = 1, userData: d, children: f }) {
9
- let p = n(null);
10
- return t(() => {
11
- let t = p.current;
12
- t && (t.setTranslation({
13
- x: e,
14
- y: r,
15
- z: c
16
- }, !1), o.set(0, l, 0), s.setFromEuler(o), t.setRotation(s, !1));
17
- }, [
18
- e,
19
- r,
20
- c,
21
- l
22
- ]), /* @__PURE__ */ i(a, {
23
- ref: p,
6
+ function r({ x: e, y: r = 0, z: i, yaw: a = 0, friction: o = 1, userData: s, children: c }) {
7
+ return /* @__PURE__ */ t(n, {
24
8
  type: "fixed",
25
9
  position: [
26
10
  e,
27
11
  r,
28
- c
12
+ i
29
13
  ],
30
14
  rotation: [
31
15
  0,
32
- l,
16
+ a,
33
17
  0
34
18
  ],
35
19
  colliders: !1,
36
- friction: u,
37
- ...d === void 0 ? {} : { userData: d },
38
- children: f
20
+ friction: o,
21
+ ...s === void 0 ? {} : { userData: s },
22
+ children: c
39
23
  });
40
24
  }
41
- function l(t, n, r, i) {
25
+ function i(t, n, r, i) {
42
26
  let a = e * .5, o = /* @__PURE__ */ new Uint8Array(9216);
43
27
  o.fill(255);
44
28
  let s = /* @__PURE__ */ new Uint8Array(36864), c = /* @__PURE__ */ new Uint8Array(36864);
@@ -61,4 +45,4 @@ function l(t, n, r, i) {
61
45
  splat1: c
62
46
  };
63
47
  }
64
- export { c as ShiftedFixedBody, l as bakeMacroCellSplat };
48
+ export { r as ShiftedFixedBody, i as bakeMacroCellSplat };