@pinkaphant/kolmo 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/bin/kolmo.mjs +1 -1
  2. package/dist/engine/kolmoActor.js +125 -83
  3. package/dist/engine/kolmoLongDrive.js +136 -91
  4. package/dist/engine/kolmoStore.d.ts +6 -5
  5. package/dist/engine/kolmoStore.js +115 -79
  6. package/dist/engine/kolmoVehicle.d.ts +1 -1
  7. package/dist/engine/kolmoVehicle.js +160 -147
  8. package/dist/engine/kolmoVehicleDriver.d.ts +12 -4
  9. package/dist/engine/kolmoVehicleDriver.js +40 -20
  10. package/dist/engine/kolmoWorld.js +55 -35
  11. package/dist/importer/CabinPreviewRig.d.ts +13 -0
  12. package/dist/importer/CabinPreviewRig.js +138 -0
  13. package/dist/importer/CabinStepSection.d.ts +17 -0
  14. package/dist/importer/CabinStepSection.js +222 -0
  15. package/dist/importer/ChopShopPanel.d.ts +31 -1
  16. package/dist/importer/ChopShopPanel.js +474 -380
  17. package/dist/importer/GateHudBar.d.ts +3 -0
  18. package/dist/importer/GateHudBar.js +8 -2
  19. package/dist/importer/GlbImportGate.js +183 -147
  20. package/dist/importer/ImporterPlinthUikitTags.d.ts +2 -1
  21. package/dist/importer/ImporterPlinthUikitTags.js +23 -16
  22. package/dist/importer/Step1CalibrationPlinth.d.ts +10 -0
  23. package/dist/importer/Step1CalibrationPlinth.js +203 -141
  24. package/dist/importer/Step2UniversalPad.d.ts +8 -1
  25. package/dist/importer/Step2UniversalPad.js +112 -90
  26. package/dist/importer/cabinMeshBuilders.d.ts +13 -0
  27. package/dist/importer/cabinMeshBuilders.js +104 -0
  28. package/dist/importer/cabinMixamoRig.d.ts +53 -0
  29. package/dist/importer/cabinMixamoRig.js +150 -0
  30. package/dist/importer/chopShopActions.d.ts +6 -0
  31. package/dist/importer/chopShopActions.js +86 -61
  32. package/dist/importer/chopShopUiComponents.d.ts +22 -0
  33. package/dist/importer/chopShopUiComponents.js +91 -0
  34. package/dist/importer/gateStore.d.ts +5 -2
  35. package/dist/importer/gateStore.js +13 -10
  36. package/dist/importer/glbNormalizer.d.ts +10 -1
  37. package/dist/importer/glbNormalizer.js +114 -49
  38. package/dist/importer/importerWebMcp.js +4 -1
  39. package/dist/importer/index.d.ts +4 -2
  40. package/dist/importer/index.js +24 -21
  41. package/dist/importer/khrCompiler.d.ts +20 -1
  42. package/dist/importer/khrCompiler.js +539 -290
  43. package/dist/importer/launcherBake.js +12 -8
  44. package/dist/importer/meshIslands.d.ts +4 -0
  45. package/dist/importer/meshIslands.js +104 -99
  46. package/dist/importer/surfaceCutter.d.ts +12 -3
  47. package/dist/importer/surfaceCutter.js +220 -127
  48. package/dist/importer/surfaceTopology.d.ts +13 -2
  49. package/dist/importer/surfaceTopology.js +57 -29
  50. package/dist/importer/universalGateBake.d.ts +7 -1
  51. package/dist/importer/universalGateBake.js +63 -60
  52. package/dist/importer/usdToGlb.js +19 -7
  53. package/dist/importer/useChopShopController.d.ts +27 -1
  54. package/dist/importer/useChopShopController.js +369 -255
  55. package/dist/importer/wheelAxlePairing.d.ts +3 -1
  56. package/dist/importer/wheelAxlePairing.js +82 -33
  57. package/dist/index.js +31 -28
  58. package/dist/junk/ShardPieces.js +3 -3
  59. package/dist/physics/index.d.ts +7 -0
  60. package/dist/physics/index.js +66 -40
  61. package/package.json +1 -1
@@ -1,38 +1,99 @@
1
- import { sliceMeshTriangles as e } from "./meshIslands.js";
2
- import { CHOP_ROLES as t, buildSurfaceTopology as n, edgeKey as r, edgeLength as i, edgeWeight as a, floodFillByCrease as o, floodTriangles as s, getIslandTopology as c, mirrorTriangles as l, shortestEdgePath as u, snapToVertex as d, weldKey as f } from "./surfaceTopology.js";
3
- import * as p from "three";
1
+ import { createFleet12GonWheelGroup as e } from "./wheelAxlePairing.js";
2
+ import { sliceMeshTriangles as t } from "./meshIslands.js";
3
+ import { CHOP_ROLES as n, MIRROR_OFF_CENTER_M as r, buildSurfaceTopology as i, countSelectionFaces as a, edgeKey as o, edgeLength as s, edgeWeight as c, floodFillByCrease as l, floodTriangles as u, getIslandTopology as d, mirrorTriangles as f, selectionEntries as p, shortestEdgePath as m, snapToVertex as h, weldKey as g } from "./surfaceTopology.js";
4
+ import * as _ from "three";
4
5
  // src/importer/surfaceCutter.ts
5
- function m(e, t) {
6
- let n = 0, r = 0;
7
- for (let i of t) {
8
- let t = e.areas[i];
9
- for (let r = 0; r < 3; r++) n += e.points[e.corners[i * 3 + r] * 3] * t / 3;
10
- r += t;
6
+ var v = new _.Triangle(), y = new _.Vector3(), b = new _.Vector3();
7
+ function x(e, t) {
8
+ let n = 0, r = 0, i = 0;
9
+ for (let a = 0; a < 3; a++) {
10
+ let o = e.corners[t * 3 + a] * 3;
11
+ n += e.points[o], r += e.points[o + 1], i += e.points[o + 2];
11
12
  }
12
- return r > 0 ? n / r : 0;
13
+ return [
14
+ n / 3,
15
+ r / 3,
16
+ i / 3
17
+ ];
13
18
  }
14
- function h(e, t, n) {
15
- let r = c(e), i = [...new Set(t)].sort((e, t) => e - t), a = n && Math.abs(m(r, i)) > .08 ? l(r, i) : [];
19
+ function S(e, t, n, r, i, a, o, s) {
20
+ y.set(t, n, r);
21
+ let c = -1, l = s;
22
+ for (let t = 0; t < e.triangleCount; t++) {
23
+ let n = t * 3;
24
+ if (i * e.normals[n] + a * e.normals[n + 1] + o * e.normals[n + 2] < .5) continue;
25
+ let r = e.corners[n] * 3, s = e.corners[n + 1] * 3, u = e.corners[n + 2] * 3;
26
+ v.a.set(e.points[r], e.points[r + 1], e.points[r + 2]), v.b.set(e.points[s], e.points[s + 1], e.points[s + 2]), v.c.set(e.points[u], e.points[u + 1], e.points[u + 2]);
27
+ let d = v.closestPointToPoint(y, b).distanceTo(y);
28
+ d <= l && (l = d, c = t);
29
+ }
16
30
  return {
17
- islandId: e.id,
18
- triangles: i,
19
- mirrored: a
31
+ t: c,
32
+ d: l
20
33
  };
21
34
  }
22
- function g(e, t, n, r) {
23
- let i = c(e), a = n === "crease" ? o(i, t, r.creaseDeg) : [t], s = r.current?.islandId === e.id ? new Set(r.current.triangles) : /* @__PURE__ */ new Set();
35
+ function C(e, t, n, i, a) {
36
+ let o = new Map(i.map((e) => [e.id, e])), s = /* @__PURE__ */ new Map(), c = (t, n) => {
37
+ if (e.get(t)?.includes(n)) return;
38
+ let r = s.get(t);
39
+ r || (r = /* @__PURE__ */ new Set(), s.set(t, r)), r.add(n);
40
+ };
41
+ if (n) {
42
+ let t = .035;
43
+ for (let [n, s] of e) {
44
+ let e = o.get(n);
45
+ if (!e || s.length === 0) continue;
46
+ let l = d(e), u = s.filter((e) => Math.abs(x(l, e)[0]) > r);
47
+ if (u.length === 0) continue;
48
+ let p = e.min[0] < -.08 && e.max[0] > .08 ? f(l, u, t) : [];
49
+ for (let e of p) c(n, e);
50
+ if (p.length < u.length) {
51
+ let e = i.filter((e) => !a?.has(e.id));
52
+ for (let r of u) {
53
+ let [i, a, o] = x(l, r), s = -i, u = -l.normals[r * 3], f = l.normals[r * 3 + 1], p = l.normals[r * 3 + 2], m = -1, h = -1, g = t;
54
+ for (let i of e) {
55
+ if (s < i.min[0] - t || s > i.max[0] + t || a < i.min[1] - t || a > i.max[1] + t || o < i.min[2] - t || o > i.max[2] + t) continue;
56
+ let e = S(d(i), s, a, o, u, f, p, g);
57
+ e.t >= 0 && e.d <= g && (i.id !== n || e.t !== r) && (g = e.d, m = i.id, h = e.t);
58
+ }
59
+ m >= 0 && h >= 0 && c(m, h);
60
+ }
61
+ }
62
+ }
63
+ }
64
+ let l = [];
65
+ for (let t of [.../* @__PURE__ */ new Set([...e.keys(), ...s.keys()])].sort((e, t) => e - t)) {
66
+ let n = [...new Set(e.get(t) ?? [])].sort((e, t) => e - t), r = [...s.get(t) ?? []].filter((e) => !n.includes(e)).sort((e, t) => e - t);
67
+ (n.length > 0 || r.length > 0) && l.push({
68
+ islandId: t,
69
+ triangles: n,
70
+ mirrored: r
71
+ });
72
+ }
73
+ let u = l.find((e) => e.islandId === t) ?? l[0];
74
+ return {
75
+ islandId: u?.islandId ?? t,
76
+ triangles: u?.triangles ?? [],
77
+ mirrored: u?.mirrored ?? [],
78
+ entries: l
79
+ };
80
+ }
81
+ function w(e, t, n, r) {
82
+ let i = d(e), a = n === "crease" ? l(i, t, r.creaseDeg) : [t], o = /* @__PURE__ */ new Map();
83
+ for (let e of p(r.current)) e.triangles.length > 0 && o.set(e.islandId, [...e.triangles]);
84
+ let s = new Set(o.get(e.id) ?? []);
24
85
  for (let e of a) r.remove ? s.delete(e) : s.add(e);
25
- return h(e, [...s], r.mirrorX);
86
+ return s.size > 0 ? o.set(e.id, [...s].sort((e, t) => e - t)) : o.delete(e.id), C(o, e.id, r.mirrorX, r.allIslands?.length ? r.allIslands : [e], r.excludeMirrorIds);
26
87
  }
27
- function _(e, t) {
88
+ function T(e, t) {
28
89
  if (t.length < 2) return t.map((e) => [
29
90
  e[0],
30
91
  e[1],
31
92
  e[2]
32
93
  ]);
33
- let n = c(e), r = t.map((e) => d(n, e)), i = [], a = t.length >= 3 ? r.length : r.length - 1;
94
+ let n = d(e), r = t.map((e) => h(n, e)), i = [], a = t.length >= 3 ? r.length : r.length - 1;
34
95
  for (let e = 0; e < a; e++) {
35
- let o = u(n, r[e], r[(e + 1) % r.length]) ?? [r[e], r[(e + 1) % r.length]];
96
+ let o = m(n, r[e], r[(e + 1) % r.length]) ?? [r[e], r[(e + 1) % r.length]];
36
97
  for (let r of o.slice(0, e === a - 1 && t.length < 3 ? void 0 : -1)) i.push([
37
98
  n.points[r * 3],
38
99
  n.points[r * 3 + 1],
@@ -41,31 +102,31 @@ function _(e, t) {
41
102
  }
42
103
  return t.length >= 3 && i.length > 0 && i.push([...i[0]]), i;
43
104
  }
44
- function v(e, t, n) {
105
+ function E(e, t, n) {
45
106
  if (t.length < 3) throw Error("Place at least 3 seam dots around the panel first.");
46
- let o = c(e), l = t.map((e) => d(o, e));
47
- if (new Set(l).size !== l.length) throw Error("Two dots snapped to the same vertex — spread dots apart or enable Split Coarse Edges.");
48
- let f = [], p = /* @__PURE__ */ new Set();
49
- for (let e = 0; e < l.length; e++) {
50
- let t = u(o, l[e], l[(e + 1) % l.length], p, n.exact ? i : a);
51
- if (!t) throw Error(`No mesh edge path connects dot ${e + 1} to dot ${(e + 1) % l.length + 1}.`);
52
- for (let e of t.slice(0, -1)) f.push(e), p.add(e);
53
- }
54
- let m = /* @__PURE__ */ new Set();
55
- for (let e = 0; e < f.length; e++) m.add(r(f[e], f[(e + 1) % f.length]));
56
- let g = [...m].map((e) => o.edgeTriangles.get(e) ?? []).find((e) => e.length === 2);
57
- if (!g) throw Error("Loop runs only along open mesh border — nothing enclosed to peel.");
58
- let _ = s(o, g[0], (e) => !m.has(e));
59
- if (new Set(_).has(g[1])) throw Error("Loop didn't enclose an isolated patch — add another dot along the shutline.");
60
- let v = s(o, g[1], (e) => !m.has(e)), y = (e) => e.reduce((e, t) => e + o.areas[t], 0);
61
- return h(e, y(_) <= y(v) ? _ : v, n.mirrorX);
107
+ let r = d(e), i = t.map((e) => h(r, e));
108
+ if (new Set(i).size !== i.length) throw Error("Two dots snapped to the same vertex — spread dots apart or enable Split Coarse Edges.");
109
+ let a = [], l = /* @__PURE__ */ new Set();
110
+ for (let e = 0; e < i.length; e++) {
111
+ let t = m(r, i[e], i[(e + 1) % i.length], l, n.exact ? s : c);
112
+ if (!t) throw Error(`No mesh edge path connects dot ${e + 1} to dot ${(e + 1) % i.length + 1}.`);
113
+ for (let e of t.slice(0, -1)) a.push(e), l.add(e);
114
+ }
115
+ let f = /* @__PURE__ */ new Set();
116
+ for (let e = 0; e < a.length; e++) f.add(o(a[e], a[(e + 1) % a.length]));
117
+ let p = [...f].map((e) => r.edgeTriangles.get(e) ?? []).find((e) => e.length === 2);
118
+ if (!p) throw Error("Loop runs only along open mesh border — nothing enclosed to peel.");
119
+ let g = u(r, p[0], (e) => !f.has(e));
120
+ if (new Set(g).has(p[1])) throw Error("Loop didn't enclose an isolated patch — add another dot along the shutline.");
121
+ let _ = u(r, p[1], (e) => !f.has(e)), v = (e) => e.reduce((e, t) => e + r.areas[t], 0), y = v(g) <= v(_) ? g : _;
122
+ return C(/* @__PURE__ */ new Map([[e.id, y]]), e.id, n.mirrorX, n.allIslands?.length ? n.allIslands : [e], n.excludeMirrorIds);
62
123
  }
63
- function y(e, t, i = .28) {
64
- let a = e.index ? e.toNonIndexed() : e.clone(), o = Object.keys(a.attributes), s = o.map((e) => a.getAttribute(e).itemSize), c = o.slice(0, o.indexOf("position")).reduce((e, t, n) => e + s[n], 0), l = a.getAttribute("position").count, u = (e) => {
124
+ function D(e, t, n = .28) {
125
+ let r = e.index ? e.toNonIndexed() : e.clone(), a = Object.keys(r.attributes), s = a.map((e) => r.getAttribute(e).itemSize), c = a.slice(0, a.indexOf("position")).reduce((e, t, n) => e + s[n], 0), l = r.getAttribute("position").count, u = (e) => {
65
126
  let t = [];
66
- return o.forEach((n, r) => {
67
- let i = a.getAttribute(n);
68
- for (let n = 0; n < s[r]; n++) t.push(i.getComponent(e, n));
127
+ return a.forEach((n, i) => {
128
+ let a = r.getAttribute(n);
129
+ for (let n = 0; n < s[i]; n++) t.push(a.getComponent(e, n));
69
130
  }), t;
70
131
  }, d = [];
71
132
  for (let e = 0; e * 3 + 2 < l; e++) d.push([
@@ -73,54 +134,54 @@ function y(e, t, i = .28) {
73
134
  u(e * 3 + 1),
74
135
  u(e * 3 + 2)
75
136
  ]);
76
- let m = d.length, h = (e) => new p.Vector3(e[c], e[c + 1], e[c + 2]), g = (e, t, n) => e.map((e, r) => e + (t[r] - e) * n), _ = n(a);
137
+ let f = d.length, p = (e) => new _.Vector3(e[c], e[c + 1], e[c + 2]), m = (e, t, n) => e.map((e, r) => e + (t[r] - e) * n), h = i(r);
77
138
  for (let e = 0; e < t.length; e++) {
78
- let n = new p.Vector3(...t[e]), a = new p.Vector3(...t[(e + 1) % t.length]), o = a.clone().sub(n), s = o.length();
139
+ let r = new _.Vector3(...t[e]), i = new _.Vector3(...t[(e + 1) % t.length]), a = i.clone().sub(r), s = a.length();
79
140
  if (s < 1e-7) continue;
80
- o.divideScalar(s);
81
- let c = n.clone().add(a).multiplyScalar(.5), l = new p.Vector3(), u = new p.Vector3();
82
- for (let e = 0; e < _.triangleCount; e++) {
141
+ a.divideScalar(s);
142
+ let c = r.clone().add(i).multiplyScalar(.5), l = new _.Vector3(), u = new _.Vector3();
143
+ for (let e = 0; e < h.triangleCount; e++) {
83
144
  u.set(0, 0, 0);
84
- for (let t = 0; t < 3; t++) u.add(new p.Vector3().fromArray(_.points, _.corners[e * 3 + t] * 3));
85
- u.multiplyScalar(1 / 3).distanceTo(c) <= Math.max(s, .25) && l.addScaledVector(new p.Vector3().fromArray(_.normals, e * 3), _.areas[e]);
145
+ for (let t = 0; t < 3; t++) u.add(new _.Vector3().fromArray(h.points, h.corners[e * 3 + t] * 3));
146
+ u.multiplyScalar(1 / 3).distanceTo(c) <= Math.max(s, .25) && l.addScaledVector(new _.Vector3().fromArray(h.normals, e * 3), h.areas[e]);
86
147
  }
87
- let m = l.lengthSq() > 0 ? l.normalize() : new p.Vector3(0, 1, 0), v = new p.Vector3().crossVectors(o, m);
148
+ let f = l.lengthSq() > 0 ? l.normalize() : new _.Vector3(0, 1, 0), v = new _.Vector3().crossVectors(a, f);
88
149
  if (v.lengthSq() < 1e-12) continue;
89
150
  v.normalize();
90
- let y = (e) => v.dot(e) - v.dot(n), b = 1e-6, x = /* @__PURE__ */ new Map(), S = (e) => {
91
- let t = h(e), n = f(t.x, t.y, t.z), r = x.get(n);
151
+ let y = (e) => v.dot(e) - v.dot(r), b = 1e-6, x = /* @__PURE__ */ new Map(), S = (e) => {
152
+ let t = p(e), n = g(t.x, t.y, t.z), r = x.get(n);
92
153
  return r === void 0 && (r = x.size, x.set(n, r)), r;
93
154
  }, C = d.map((e) => {
94
- let t = e.map((e) => y(h(e))), n = t.filter((e) => e > b).length, i = t.filter((e) => e < -1e-6).length;
95
- if (n === 0 || i === 0) return null;
96
- let a = n === 1 ? t.findIndex((e) => e > b) : t.findIndex((e) => e < -1e-6), [o, s, c] = [
155
+ let t = e.map((e) => y(p(e))), n = t.filter((e) => e > b).length, r = t.filter((e) => e < -1e-6).length;
156
+ if (n === 0 || r === 0) return null;
157
+ let i = n === 1 ? t.findIndex((e) => e > b) : t.findIndex((e) => e < -1e-6), [a, s, c] = [
97
158
  0,
98
159
  1,
99
160
  2
100
- ].map((t) => e[(a + t) % 3]), [l, u, d] = [
161
+ ].map((t) => e[(i + t) % 3]), [l, u, d] = [
101
162
  0,
102
163
  1,
103
164
  2
104
- ].map((e) => t[(a + e) % 3]), f = Math.abs(u) <= b ? null : g(o, s, l / (l - u)), p = Math.abs(d) <= b ? null : g(o, c, l / (l - d));
165
+ ].map((e) => t[(i + e) % 3]), f = Math.abs(u) <= b ? null : m(a, s, l / (l - u)), h = Math.abs(d) <= b ? null : m(a, c, l / (l - d));
105
166
  return {
106
- c0: o,
167
+ c0: a,
107
168
  c1: s,
108
169
  c2: c,
109
170
  p01: f,
110
- p02: p,
111
- k01: f ? r(S(o), S(s)) : -1,
112
- k02: p ? r(S(o), S(c)) : -1,
113
- chord: [f ?? s, p ?? c]
171
+ p02: h,
172
+ k01: f ? o(S(a), S(s)) : -1,
173
+ k02: h ? o(S(a), S(c)) : -1,
174
+ chord: [f ?? s, h ?? c]
114
175
  };
115
176
  }), w = /* @__PURE__ */ new Set();
116
177
  for (let e of C) {
117
178
  if (!e) continue;
118
- let t = Infinity, r = -Infinity, a = Infinity;
119
- for (let i of e.chord) {
120
- let e = h(i).sub(n), s = e.dot(o);
121
- t = Math.min(t, s), r = Math.max(r, s), a = Math.min(a, Math.abs(e.dot(m)));
179
+ let t = Infinity, i = -Infinity, o = Infinity;
180
+ for (let n of e.chord) {
181
+ let e = p(n).sub(r), s = e.dot(a);
182
+ t = Math.min(t, s), i = Math.max(i, s), o = Math.min(o, Math.abs(e.dot(f)));
122
183
  }
123
- r >= -1e-6 && t <= s + b && a <= i && (e.p01 && w.add(e.k01), e.p02 && w.add(e.k02));
184
+ i >= -1e-6 && t <= s + b && o <= n && (e.p01 && w.add(e.k01), e.p02 && w.add(e.k02));
124
185
  }
125
186
  let T = [];
126
187
  d.forEach((e, t) => {
@@ -161,47 +222,100 @@ function y(e, t, i = .28) {
161
222
  ]);
162
223
  }), d = T;
163
224
  }
164
- let v = new p.BufferGeometry(), y = 0;
165
- return o.forEach((e, t) => {
166
- let n = s[t], r = new Float32Array(d.length * 3 * n);
225
+ let v = new _.BufferGeometry(), y = 0;
226
+ return a.forEach((e, t) => {
227
+ let n = s[t], i = new Float32Array(d.length * 3 * n);
167
228
  d.forEach((e, t) => {
168
- for (let i = 0; i < 3; i++) for (let a = 0; a < n; a++) r[(t * 3 + i) * n + a] = e[i][y + a];
169
- }), v.setAttribute(e, new p.BufferAttribute(r, n, a.getAttribute(e).normalized)), y += n;
229
+ for (let r = 0; r < 3; r++) for (let a = 0; a < n; a++) i[(t * 3 + r) * n + a] = e[r][y + a];
230
+ }), v.setAttribute(e, new _.BufferAttribute(i, n, r.getAttribute(e).normalized)), y += n;
170
231
  }), v.getAttribute("normal") || v.computeVertexNormals(), v.computeBoundingBox(), v.computeBoundingSphere(), {
171
232
  geometry: v,
172
- added: d.length - m
233
+ added: d.length - f
173
234
  };
174
235
  }
175
- function b(t, n, r) {
176
- let i = t.mesh, a = i.parent;
177
- if (!a) throw Error("Selected island mesh has no parent scene.");
178
- let o = i.geometry, s = o.getAttribute("position"), c = o.getIndex(), l = s ? Math.floor((c ? c.count : s.count) / 3) : 0, u = (e) => e.map((e) => t.triangleIndices[e]), d = u(n.triangles), f = u(n.mirrored), m = /* @__PURE__ */ new Set([...d, ...f]), h = [], g = (t, n) => {
179
- if (t.length === 0) return;
180
- let r = new p.Mesh(e(o, t), i.material);
181
- r.name = n, r.position.copy(i.position), r.quaternion.copy(i.quaternion), r.scale.copy(i.scale), a.add(r), h.push(r);
236
+ function O(e) {
237
+ if (e.length === 0) return new _.BufferGeometry();
238
+ if (e.length === 1) return e[0];
239
+ let t = Object.keys(e[0].attributes).filter((t) => e.every((e) => !!e.getAttribute(t))), n = e.reduce((e, t) => e + (t.getAttribute("position")?.count ?? 0), 0), r = new _.BufferGeometry();
240
+ for (let i of t) {
241
+ let t = e[0].getAttribute(i).itemSize, a = new Float32Array(n * t), o = 0;
242
+ for (let n of e) {
243
+ let e = n.getAttribute(i);
244
+ for (let n = 0; n < e.count; n++) for (let r = 0; r < t; r++) a[(o + n) * t + r] = e.getComponent(n, r);
245
+ o += e.count;
246
+ }
247
+ r.setAttribute(i, new _.BufferAttribute(a, t));
248
+ }
249
+ for (let t of e) t.dispose();
250
+ return r.getAttribute("normal") || r.computeVertexNormals(), r.computeBoundingBox(), r.computeBoundingSphere(), r;
251
+ }
252
+ function k(e, n, r, i) {
253
+ let a = new Map(e.map((e) => [e.id, e])), o = p(n).filter((e) => a.has(e.islandId) && (e.triangles.length > 0 || e.mirrored.length > 0));
254
+ if (o.length === 0) throw Error("Selected surface island no longer exists.");
255
+ let s = a.get(o[0].islandId).mesh.parent, c = i ?? s;
256
+ if (!i && c) for (; c.parent;) c = c.parent;
257
+ if (!c) throw Error("Selected island mesh has no parent scene.");
258
+ let l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), f = (e, t, n) => {
259
+ let r = e.get(t);
260
+ r ? r.push(n) : e.set(t, [n]);
261
+ };
262
+ for (let e of o) {
263
+ let n = a.get(e.islandId), r = l.get(n.mesh);
264
+ r || (r = /* @__PURE__ */ new Set(), l.set(n.mesh, r));
265
+ for (let t of e.triangles) r.add(n.triangleIndices[t]);
266
+ for (let t of e.mirrored) r.add(n.triangleIndices[t]);
267
+ e.triangles.length > 0 && f(u, n.material, t(n.geometry, e.triangles)), e.mirrored.length > 0 && f(d, n.material, t(n.geometry, e.mirrored));
268
+ }
269
+ let m = [], h = (e, t) => {
270
+ let n = 0;
271
+ for (let [r, i] of e) {
272
+ let e = new _.Mesh(O(i), r);
273
+ e.name = n === 0 ? t : `${t}_${n}`, c.add(e), m.push(e), n++;
274
+ }
182
275
  };
183
- g(d, r), g(f, `${r}_mirror`);
184
- let _ = [];
185
- for (let e = 0; e < l; e++) m.has(e) || _.push(e);
186
- return i.geometry = _.length > 0 ? e(o, _) : new p.BufferGeometry(), {
187
- mintedMeshes: h,
276
+ h(u, r), h(d, `${r}_mirror`);
277
+ let g = /* @__PURE__ */ new Map();
278
+ for (let [e, n] of l) {
279
+ let r = e.geometry, i = r.getAttribute("position"), a = r.getIndex(), o = i ? Math.floor((a ? a.count : i.count) / 3) : 0;
280
+ g.set(e, r);
281
+ let s = [];
282
+ for (let e = 0; e < o; e++) n.has(e) || s.push(e);
283
+ e.geometry = s.length > 0 ? t(r, s) : new _.BufferGeometry();
284
+ }
285
+ return {
286
+ mintedMeshes: m,
188
287
  undo: () => {
189
- i.geometry = o;
190
- for (let e of h) e.removeFromParent(), e.geometry.dispose();
288
+ for (let [e, t] of g) e.geometry.dispose(), e.geometry = t;
289
+ for (let e of m) e.removeFromParent(), e.geometry.dispose();
191
290
  }
192
291
  };
193
292
  }
194
- function x(e, t) {
195
- let n = (e) => `${e.mesh.uuid}|${e.triangleIndices.length}|${e.center.map((e) => e.toFixed(4)).join(",")}`, r = /* @__PURE__ */ new Map();
293
+ function A(e, t, n) {
294
+ return k([e], t, n);
295
+ }
296
+ function j(e, t) {
297
+ let n = (e) => `${e.mesh.uuid}|${e.triangleIndices.length}|${e.center.map((e) => e.toFixed(4)).join(",")}`, r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map();
196
298
  for (let e of t) {
197
299
  let t = n(e), i = r.get(t);
198
300
  i ? i.push(e.id) : r.set(t, [e.id]);
199
301
  }
200
- let i = /* @__PURE__ */ new Map();
201
- for (let t of e) i.set(t.id, r.get(n(t))?.shift() ?? null);
202
- return i;
302
+ for (let t of e) {
303
+ let e = r.get(n(t))?.shift() ?? null;
304
+ e !== null && i.add(e), a.set(t.id, e);
305
+ }
306
+ for (let n of e) {
307
+ if (a.get(n.id) !== null) continue;
308
+ let e = null, r = .03;
309
+ for (let a of t) {
310
+ if (i.has(a.id) || a.mesh.uuid !== n.mesh.uuid) continue;
311
+ let t = Math.hypot(a.center[0] - n.center[0], a.center[1] - n.center[1], a.center[2] - n.center[2]) + Math.hypot(a.size[0] - n.size[0], a.size[1] - n.size[1], a.size[2] - n.size[2]);
312
+ t <= r && (r = t, e = a.id);
313
+ }
314
+ e !== null && (i.add(e), a.set(n.id, e));
315
+ }
316
+ return a;
203
317
  }
204
- function S(e, t, n) {
318
+ function M(e, t, n) {
205
319
  let r = e.find((e) => e.id === t);
206
320
  if (!r || Math.abs(r.center[0]) <= .08) return null;
207
321
  let i = Math.max(...r.size, .15), a = null, o = .55;
@@ -212,43 +326,22 @@ function S(e, t, n) {
212
326
  }
213
327
  return a;
214
328
  }
215
- function C(t, n, r = .004) {
216
- let i = e(t, n), a = i.getAttribute("position"), o = i.getAttribute("normal");
329
+ function N(e, n, r = .004) {
330
+ let i = t(e, n), a = i.getAttribute("position"), o = i.getAttribute("normal");
217
331
  if (a && o) {
218
332
  for (let e = 0; e < a.count; e++) a.setXYZ(e, a.getX(e) + o.getX(e) * r, a.getY(e) + o.getY(e) * r, a.getZ(e) + o.getZ(e) * r);
219
333
  a.needsUpdate = !0;
220
334
  }
221
335
  return i;
222
336
  }
223
- function w(e, t, n = "Wheel_12gon") {
224
- let r = new p.Group();
225
- r.name = n;
226
- let i = new p.CylinderGeometry(e, e, t, 12, 1);
227
- i.rotateZ(Math.PI * .5);
228
- let a = new p.CylinderGeometry(e * .62, e * .62, t * 1.04, 12, 1);
229
- a.rotateZ(Math.PI * .5);
230
- let o = new p.CylinderGeometry(e * .22, e * .22, t * 1.1, 6, 1);
231
- o.rotateZ(Math.PI * .5);
232
- let s = new p.Mesh(i, new p.MeshStandardMaterial({
233
- color: "#1b2028",
234
- roughness: .92,
235
- metalness: .05,
236
- flatShading: !0
237
- }));
238
- s.name = `${n}_tire`;
239
- let c = new p.Mesh(a, new p.MeshStandardMaterial({
240
- color: "#cbd5e1",
241
- roughness: .36,
242
- metalness: .72,
243
- flatShading: !0
244
- }));
245
- c.name = `${n}_rim`;
246
- let l = new p.Mesh(o, new p.MeshStandardMaterial({
247
- color: "#f59e0b",
248
- roughness: .45,
249
- metalness: .6,
250
- flatShading: !0
251
- }));
252
- return l.name = `${n}_hub`, r.add(s, c, l), r;
337
+ function P(e, t, n, r = .0045) {
338
+ let i = p(t);
339
+ if (i.length === 0) return null;
340
+ let a = new Map(e.map((e) => [e.id, e])), o = [];
341
+ for (let e of i) {
342
+ let t = e[n], i = a.get(e.islandId);
343
+ i && t.length > 0 && o.push(N(i.geometry, t, r));
344
+ }
345
+ return o.length > 0 ? O(o) : null;
253
346
  }
254
- export { t as CHOP_ROLES, C as buildSelectionOverlayGeometry, n as buildSurfaceTopology, w as createFleet12GonWheelGroup, S as findMirrorIslandId, o as floodFillByCrease, c as getIslandTopology, l as mirrorTriangles, b as peelIslandSelection, _ as previewLoopPolyline, y as refineMeshAlongLoop, x as remapIslandIds, g as selectFacesByClick, v as selectFacesByLoop };
347
+ export { n as CHOP_ROLES, P as buildMultiSelectionOverlay, N as buildSelectionOverlayGeometry, i as buildSurfaceTopology, a as countSelectionFaces, e as createFleet12GonWheelGroup, M as findMirrorIslandId, l as floodFillByCrease, d as getIslandTopology, f as mirrorTriangles, k as peelFaceSelection, A as peelIslandSelection, T as previewLoopPolyline, D as refineMeshAlongLoop, j as remapIslandIds, w as selectFacesByClick, E as selectFacesByLoop, p as selectionEntries };
@@ -1,8 +1,8 @@
1
1
  import * as THREE from "three";
2
2
  import type { MeshIsland } from "./meshIslands.js";
3
3
  export type SurfaceSelectMode = "island" | "crease" | "loop" | "triangle";
4
- export type ChopPartRole = "door" | "hood" | "trunk" | "fender" | "bumper";
5
- export type ActiveChopRole = "wheel" | ChopPartRole;
4
+ export type ChopPartRole = "door" | "hood" | "trunk" | "glass" | "fender" | "bumper";
5
+ export type ActiveChopRole = "wheel" | "propeller" | ChopPartRole;
6
6
  export type CutVec3 = readonly [number, number, number];
7
7
  export declare const CHOP_ROLES: ReadonlyArray<{
8
8
  role: ActiveChopRole;
@@ -10,11 +10,22 @@ export declare const CHOP_ROLES: ReadonlyArray<{
10
10
  color: string;
11
11
  massKg: number;
12
12
  }>;
13
+ export interface IslandFaceSlice {
14
+ readonly islandId: number;
15
+ readonly triangles: number[];
16
+ readonly mirrored: number[];
17
+ }
13
18
  export interface FaceSelection {
14
19
  readonly islandId: number;
15
20
  readonly triangles: number[];
16
21
  readonly mirrored: number[];
22
+ readonly entries?: readonly IslandFaceSlice[];
17
23
  }
24
+ export declare function selectionEntries(sel: FaceSelection | null | undefined): readonly IslandFaceSlice[];
25
+ export declare function countSelectionFaces(sel: FaceSelection | null | undefined): {
26
+ primary: number;
27
+ mirrored: number;
28
+ };
18
29
  export interface SurfaceTopology {
19
30
  readonly geometry: THREE.BufferGeometry;
20
31
  readonly triangleCount: number;
@@ -7,6 +7,12 @@ var t = [
7
7
  color: "#00E5FF",
8
8
  massKg: 22
9
9
  },
10
+ {
11
+ role: "propeller",
12
+ label: "Propeller / Rotor",
13
+ color: "#EC4899",
14
+ massKg: 14
15
+ },
10
16
  {
11
17
  role: "door",
12
18
  label: "Door (Hinge)",
@@ -25,6 +31,12 @@ var t = [
25
31
  color: "#A855F7",
26
32
  massKg: 16
27
33
  },
34
+ {
35
+ role: "glass",
36
+ label: "Glass / Window",
37
+ color: "#7DD3FC",
38
+ massKg: 6
39
+ },
28
40
  {
29
41
  role: "fender",
30
42
  label: "Fender Panel",
@@ -37,22 +49,38 @@ var t = [
37
49
  color: "#38BDF8",
38
50
  massKg: 12
39
51
  }
40
- ], n = 2 ** 26, r = .08, i = .65, a = /* @__PURE__ */ new WeakMap(), o = (e, t) => e < t ? e * n + t : t * n + e, s = (e, t, n) => `${Math.round(e * 1e4)},${Math.round(t * 1e4)},${Math.round(n * 1e4)}`;
41
- function c(e) {
42
- let t = a.get(e.geometry);
52
+ ];
53
+ function n(e) {
54
+ return e ? e.entries && e.entries.length > 0 ? e.entries : e.triangles.length > 0 || e.mirrored.length > 0 ? [{
55
+ islandId: e.islandId,
56
+ triangles: e.triangles,
57
+ mirrored: e.mirrored
58
+ }] : [] : [];
59
+ }
60
+ function r(e) {
61
+ let t = 0, r = 0;
62
+ for (let i of n(e)) t += i.triangles.length, r += i.mirrored.length;
63
+ return {
64
+ primary: t,
65
+ mirrored: r
66
+ };
67
+ }
68
+ var i = 2 ** 26, a = .08, o = .65, s = /* @__PURE__ */ new WeakMap(), c = (e, t) => e < t ? e * i + t : t * i + e, l = (e, t, n) => `${Math.round(e * 1e4)},${Math.round(t * 1e4)},${Math.round(n * 1e4)}`;
69
+ function u(e) {
70
+ let t = s.get(e.geometry);
43
71
  if (t) return t;
44
- let n = l(e.geometry);
45
- return a.set(e.geometry, n), n;
72
+ let n = d(e.geometry);
73
+ return s.set(e.geometry, n), n;
46
74
  }
47
- function l(t) {
48
- let n = t.getAttribute("position"), r = t.getIndex(), i = n ? r ? r.count : n.count : 0, a = Math.floor(i / 3), c = new Uint32Array(a * 3), l = /* @__PURE__ */ new Map(), u = [];
75
+ function d(t) {
76
+ let n = t.getAttribute("position"), r = t.getIndex(), i = n ? r ? r.count : n.count : 0, a = Math.floor(i / 3), o = new Uint32Array(a * 3), s = /* @__PURE__ */ new Map(), u = [];
49
77
  for (let e = 0; e < a * 3; e++) {
50
- let t = r ? r.getX(e) : e, i = n.getX(t), a = n.getY(t), o = n.getZ(t), d = s(i, a, o), f = l.get(d);
51
- f === void 0 && (f = l.size, l.set(d, f), u.push(i, a, o)), c[e] = f;
78
+ let t = r ? r.getX(e) : e, i = n.getX(t), a = n.getY(t), c = n.getZ(t), d = l(i, a, c), f = s.get(d);
79
+ f === void 0 && (f = s.size, s.set(d, f), u.push(i, a, c)), o[e] = f;
52
80
  }
53
- let d = Float32Array.from(u), f = l.size, p = new Float32Array(a * 3), m = new Float32Array(a), h = /* @__PURE__ */ new Map(), g = Array.from({ length: f }, () => /* @__PURE__ */ new Set()), _ = new e.Vector3(), v = new e.Vector3(), y = new e.Vector3(), b = new e.Vector3();
81
+ let d = Float32Array.from(u), f = s.size, p = new Float32Array(a * 3), m = new Float32Array(a), h = /* @__PURE__ */ new Map(), g = Array.from({ length: f }, () => /* @__PURE__ */ new Set()), _ = new e.Vector3(), v = new e.Vector3(), y = new e.Vector3(), b = new e.Vector3();
54
82
  for (let e = 0; e < a; e++) {
55
- let t = c[e * 3], n = c[e * 3 + 1], r = c[e * 3 + 2];
83
+ let t = o[e * 3], n = o[e * 3 + 1], r = o[e * 3 + 2];
56
84
  _.fromArray(d, t * 3), v.fromArray(d, n * 3), y.fromArray(d, r * 3), b.crossVectors(v.sub(_), y.sub(_));
57
85
  let i = b.length();
58
86
  m[e] = i * .5, i > 0 && b.divideScalar(i).toArray(p, e * 3);
@@ -62,7 +90,7 @@ function l(t) {
62
90
  [r, t]
63
91
  ]) {
64
92
  if (i === a) continue;
65
- let t = o(i, a), n = h.get(t);
93
+ let t = c(i, a), n = h.get(t);
66
94
  n ? n.push(e) : h.set(t, [e]), g[i].add(a), g[a].add(i);
67
95
  }
68
96
  }
@@ -70,7 +98,7 @@ function l(t) {
70
98
  geometry: t,
71
99
  triangleCount: a,
72
100
  vertexCount: f,
73
- corners: c,
101
+ corners: o,
74
102
  points: d,
75
103
  normals: p,
76
104
  areas: m,
@@ -78,26 +106,26 @@ function l(t) {
78
106
  neighbors: g.map((e) => [...e])
79
107
  };
80
108
  }
81
- function u(e, t, n) {
109
+ function f(e, t, n) {
82
110
  if (t < 0 || t >= e.triangleCount) return [];
83
111
  let r = new Uint8Array(e.triangleCount), i = [t];
84
112
  r[t] = 1;
85
113
  for (let t = 0; t < i.length; t++) {
86
114
  let a = i[t];
87
115
  for (let t = 0; t < 3; t++) {
88
- let s = e.corners[a * 3 + t], c = e.corners[a * 3 + (t + 1) % 3];
89
- if (s === c) continue;
90
- let l = o(s, c);
116
+ let o = e.corners[a * 3 + t], s = e.corners[a * 3 + (t + 1) % 3];
117
+ if (o === s) continue;
118
+ let l = c(o, s);
91
119
  for (let t of e.edgeTriangles.get(l) ?? []) !r[t] && n(l, a, t) && (r[t] = 1, i.push(t));
92
120
  }
93
121
  }
94
122
  return i.sort((e, t) => e - t);
95
123
  }
96
- function d(e, t, n = 32) {
124
+ function p(e, t, n = 32) {
97
125
  let r = Math.cos(n * Math.PI / 180), i = e.normals;
98
- return u(e, t, (e, t, n) => i[t * 3] * i[n * 3] + i[t * 3 + 1] * i[n * 3 + 1] + i[t * 3 + 2] * i[n * 3 + 2] >= r);
126
+ return f(e, t, (e, t, n) => i[t * 3] * i[n * 3] + i[t * 3 + 1] * i[n * 3 + 1] + i[t * 3 + 2] * i[n * 3 + 2] >= r);
99
127
  }
100
- function f(e, t, n = .03) {
128
+ function m(e, t, n = .03) {
101
129
  let r = Math.max(n, 1e-4), i = (e, t, n) => `${Math.floor(e / r)},${Math.floor(t / r)},${Math.floor(n / r)}`, a = /* @__PURE__ */ new Map(), o = new Float32Array(e.triangleCount * 3);
102
130
  for (let t = 0; t < e.triangleCount; t++) {
103
131
  let n = 0, r = 0, s = 0;
@@ -121,19 +149,19 @@ function f(e, t, n = .03) {
121
149
  }
122
150
  return [...c].sort((e, t) => e - t);
123
151
  }
124
- function p(e, t, n) {
152
+ function h(e, t, n) {
125
153
  let r = e.points;
126
154
  return Math.hypot(r[t * 3] - r[n * 3], r[t * 3 + 1] - r[n * 3 + 1], r[t * 3 + 2] - r[n * 3 + 2]);
127
155
  }
128
- function m(e, t, n) {
129
- let r = e.edgeTriangles.get(o(t, n)), a = 1;
156
+ function g(e, t, n) {
157
+ let r = e.edgeTriangles.get(c(t, n)), i = 1;
130
158
  if (r && r.length === 2) {
131
- let t = e.normals, n = r[0], i = r[1], o = t[n * 3] * t[i * 3] + t[n * 3 + 1] * t[i * 3 + 1] + t[n * 3 + 2] * t[i * 3 + 2];
132
- a = Math.min(1, Math.acos(Math.max(-1, Math.min(1, o))) / (Math.PI / 2));
159
+ let t = e.normals, n = r[0], a = r[1], o = t[n * 3] * t[a * 3] + t[n * 3 + 1] * t[a * 3 + 1] + t[n * 3 + 2] * t[a * 3 + 2];
160
+ i = Math.min(1, Math.acos(Math.max(-1, Math.min(1, o))) / (Math.PI / 2));
133
161
  }
134
- return p(e, t, n) * (1 - i * a);
162
+ return h(e, t, n) * (1 - o * i);
135
163
  }
136
- function h(e, t) {
164
+ function _(e, t) {
137
165
  let n = 0, r = Infinity;
138
166
  for (let i = 0; i < e.vertexCount; i++) {
139
167
  let a = (e.points[i * 3] - t[0]) ** 2 + (e.points[i * 3 + 1] - t[1]) ** 2 + (e.points[i * 3 + 2] - t[2]) ** 2;
@@ -141,7 +169,7 @@ function h(e, t) {
141
169
  }
142
170
  return n;
143
171
  }
144
- function g(e, t, n, r, i = m) {
172
+ function v(e, t, n, r, i = g) {
145
173
  if (t === n) return [t];
146
174
  let a = new Float64Array(e.vertexCount).fill(Infinity), o = new Int32Array(e.vertexCount).fill(-1), s = [[0, t]];
147
175
  a[t] = 0;
@@ -180,4 +208,4 @@ function g(e, t, n, r, i = m) {
180
208
  for (let e = n; e !== t;) e = o[e], u.push(e);
181
209
  return u.reverse();
182
210
  }
183
- export { t as CHOP_ROLES, r as MIRROR_OFF_CENTER_M, l as buildSurfaceTopology, o as edgeKey, p as edgeLength, m as edgeWeight, d as floodFillByCrease, u as floodTriangles, c as getIslandTopology, f as mirrorTriangles, g as shortestEdgePath, h as snapToVertex, s as weldKey };
211
+ export { t as CHOP_ROLES, a as MIRROR_OFF_CENTER_M, d as buildSurfaceTopology, r as countSelectionFaces, c as edgeKey, h as edgeLength, g as edgeWeight, p as floodFillByCrease, f as floodTriangles, u as getIslandTopology, m as mirrorTriangles, n as selectionEntries, v as shortestEdgePath, _ as snapToVertex, l as weldKey };