@pinkaphant/kolmo 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 d, useEffect as f, useLayoutEffect as p, useMemo as m, useRef as h, useState as g } from "react";
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
10
  import * as oe from "three";
11
11
  import { useFrame as se } from "@react-three/fiber";
12
12
  import { cloneKhrBundle as ce, loadKhrGlb as _, useKhrGlb as v } from "@khr3/core";
13
13
  import { jsx as y, jsxs as le } from "react/jsx-runtime";
14
- import { KhrVehicle as ue } from "@khr3/core/vehicle";
14
+ import { useRapier as ue } from "@react-three/rapier";
15
+ import { KhrVehicle as b } from "@khr3/core/vehicle";
15
16
  // src/engine/kolmoVehicle.tsx
16
- function b(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;
@@ -42,36 +43,36 @@ function x({ id: t, sourceBundle: o, rawGlbBytes: g, position: _ = [
42
43
  0,
43
44
  .35,
44
45
  0
45
- ], rotation: v, piloted: x = !1, flightMode: S = !1, vehicleMode: C, enable: fe = !0, ccd: w, linearDamping: T, angularDamping: E, userData: D, onCollisionEnter: O, wheelConfig: k, propellerConfig: A, carConfig: j, droneConfig: M, vehicleRef: N, getInput: pe, driver: P, cameraController: F, children: I }) {
46
- let L = d(e), R = re();
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();
47
48
  p(() => {
48
- ne(R);
49
- }, [R]);
50
- let z = ie(R, c), me = ee(pe), B = m(() => ce(o), [o]), V = m(() => i(B), [B]), H = m(() => (b(B.scene), r(B.scene, g)), [B, g]);
51
- p(() => de([
52
- B.scene,
53
- ...B.wheels.map((e) => e.object),
54
- ...B.propellers.map((e) => e.object)
55
- ]), [B]);
56
- let U = !!(C === "rocket" || S || C !== "drive" && B.propellers.length > 0), W = m(() => H.sockets.find((e) => e.role === "seat" || e.role === "optic")?.localPosition ?? [
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
- ], [H]), G = m(() => H.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
- ], [H]), K = m(() => {
65
+ ], [V]), G = m(() => {
65
66
  if (k || C !== void 0) return {
66
67
  ...C === void 0 ? {} : { enable: C === "drive" },
67
68
  ...k ?? {}
68
69
  };
69
- }, [k, C]), q = m(() => {
70
+ }, [k, C]), K = m(() => {
70
71
  if (A || C !== void 0) return {
71
72
  ...C === void 0 ? {} : { enable: C === "rocket" },
72
73
  ...A ?? {}
73
74
  };
74
- }, [A, C]), J = m(() => U ? {
75
+ }, [A, C]), q = m(() => H ? {
75
76
  controlMode: "VELOCITY",
76
77
  maxHorizSpeed: 46,
77
78
  maxVertSpeed: 16,
@@ -79,21 +80,21 @@ function x({ id: t, sourceBundle: o, rawGlbBytes: g, position: _ = [
79
80
  maxTiltAngle: .52,
80
81
  HORIZ_VEL_P: 1.8,
81
82
  VERT_VEL_P: 2.8,
82
- ...B.droneTune ?? {},
83
+ ...z.droneTune ?? {},
83
84
  ...M ?? {}
84
85
  } : M, [
85
- U,
86
- B.droneTune,
86
+ H,
87
+ z.droneTune,
87
88
  M
88
- ]), Y = h(null), he = h([
89
+ ]), J = h(null), _e = h([
89
90
  _[0],
90
91
  _[1],
91
92
  _[2]
92
- ]), X = h(v ? [
93
+ ]), Y = h(v ? [
93
94
  v[0],
94
95
  v[1],
95
96
  v[2]
96
- ] : void 0), Z = h(n()), Q = h(new oe.Vector3()), ge = h({
97
+ ] : void 0), X = h(n()), Z = h(new oe.Vector3()), ve = h({
97
98
  camInit: !1,
98
99
  cockpit: !1,
99
100
  prevCam: !1,
@@ -101,7 +102,7 @@ function x({ id: t, sourceBundle: o, rawGlbBytes: g, position: _ = [
101
102
  prevR: !1,
102
103
  turnL: !1,
103
104
  turnR: !1
104
- }), _e = h({
105
+ }), ye = h({
105
106
  forward: !1,
106
107
  backward: !1,
107
108
  steerLeft: !1,
@@ -115,9 +116,9 @@ function x({ id: t, sourceBundle: o, rawGlbBytes: g, position: _ = [
115
116
  pitchBackward: !1,
116
117
  rollLeft: !1,
117
118
  rollRight: !1
118
- }), $ = u((e, t) => {
119
- Q.current.x -= e, Q.current.z -= t;
120
- let n = Y.current;
119
+ }), Q = d((e, t) => {
120
+ Z.current.x -= e, Z.current.z -= t;
121
+ let n = J.current;
121
122
  if (n) {
122
123
  n.currPos.x -= e, n.currPos.z -= t;
123
124
  for (let r of n.wheelsInfo.values()) {
@@ -127,92 +128,92 @@ function x({ id: t, sourceBundle: o, rawGlbBytes: g, position: _ = [
127
128
  }
128
129
  }, []);
129
130
  f(() => {
130
- let e = R.spawn(s({
131
+ let e = L.spawn(s({
131
132
  id: t,
132
- handle: Y.current,
133
- centerOfMass: [...B.centerOfMass],
134
- seatOffset: W,
135
- exitOffset: G,
136
- isFlight: U,
137
- onOriginShift: $
133
+ handle: J.current,
134
+ centerOfMass: [...z.centerOfMass],
135
+ seatOffset: U,
136
+ exitOffset: W,
137
+ isFlight: H,
138
+ onOriginShift: Q
138
139
  }), te({
139
140
  id: t,
140
141
  radius: 4.2,
141
142
  kind: "vehicle"
142
143
  }));
143
- return x && !R.get(c)?.activeVehicleId && l(R).boardVehicle(t), () => {
144
- 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();
145
146
  };
146
147
  }, [
147
- R,
148
+ L,
148
149
  t,
149
- B,
150
- W,
151
- G,
150
+ z,
152
151
  U,
152
+ W,
153
+ H,
153
154
  x,
154
- $
155
+ Q
155
156
  ]);
156
- let ve = u((e) => {
157
- Y.current = e, N && (N.current = e);
158
- 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)) {
159
160
  let r = n.get(s);
160
161
  r && r.id === t && n.set(s, {
161
162
  ...r,
162
163
  handle: e,
163
- onOriginShift: $
164
+ onOriginShift: Q
164
165
  });
165
166
  }
166
167
  }, [
167
- R,
168
+ L,
168
169
  t,
169
170
  N,
170
- $
171
- ]), ye = z?.activeVehicleId === t || x && !z?.activeVehicleId;
171
+ Q
172
+ ]), { world: $ } = ue(), xe = R?.activeVehicleId === t || x && !R?.activeVehicleId;
172
173
  return se((e, n) => {
173
- let r = Math.min(Math.max(n, 1e-4), .05);
174
- V.step(r);
175
- let i = Y.current;
176
- i && i.body && (P ? (P(i, r, e), F && F(i, r, e)) : ae({
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({
177
178
  id: t,
178
179
  veh: i,
179
- keys: me(),
180
- cmd: _e.current,
181
- sig: Z.current,
182
- st: ge.current,
183
- camTarget: Q.current,
184
- centerOfMass: B.centerOfMass,
185
- seatOffset: W,
186
- isPiloted: ye,
187
- isFlight: U,
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,
188
189
  dt: r,
189
190
  state: e,
190
191
  cameraController: F
191
192
  }));
192
193
  }), /* @__PURE__ */ y("group", {
193
194
  onClick: (e) => {
194
- e.delta <= 5 && V.toggleHitObject(e.object) && e.stopPropagation();
195
+ e.delta <= 5 && B.toggleHitObject(e.object) && e.stopPropagation();
195
196
  },
196
- children: /* @__PURE__ */ le(ue, {
197
- ref: ve,
198
- bundle: B,
199
- position: he.current,
200
- enable: fe,
201
- enableCustomGravity: L,
202
- ...X.current === void 0 ? {} : { rotation: X.current },
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 },
203
204
  ...w === void 0 ? {} : { ccd: w },
204
205
  ...T === void 0 ? {} : { linearDamping: T },
205
206
  ...E === void 0 ? {} : { angularDamping: E },
206
207
  ...D === void 0 ? {} : { userData: D },
207
208
  ...O === void 0 ? {} : { onCollisionEnter: O },
208
- ...K === void 0 ? {} : { wheelConfig: K },
209
- ...q === void 0 ? {} : { propellerConfig: q },
209
+ ...G === void 0 ? {} : { wheelConfig: G },
210
+ ...K === void 0 ? {} : { propellerConfig: K },
210
211
  ...j === void 0 ? {} : { carConfig: j },
211
- ...J === void 0 ? {} : { droneConfig: J },
212
+ ...q === void 0 ? {} : { droneConfig: q },
212
213
  children: [/* @__PURE__ */ y(a, {
213
- emitters: H.emitters,
214
- signalsRef: Z
215
- }), I]
214
+ emitters: V.emitters,
215
+ signalsRef: X
216
+ }), he]
216
217
  })
217
218
  });
218
219
  }
@@ -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 };