mbt-3d 0.3.3 → 0.3.5

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/dist/mbt-3d.js CHANGED
@@ -1,134 +1,134 @@
1
- import { Suspense as Q, useMemo as W, useRef as w, useEffect as I, useCallback as C, createContext as ie, useContext as ce, forwardRef as ee, useImperativeHandle as te, useState as ue } from "react";
1
+ import { Suspense as Q, useMemo as W, useRef as w, useEffect as I, useCallback as R, createContext as ie, useContext as ce, forwardRef as ee, useImperativeHandle as te, useState as ue } from "react";
2
2
  import { ContactShadows as pe, OrbitControls as me, useTexture as fe, useGLTF as H, useAnimations as de } from "@react-three/drei";
3
3
  import * as E from "three";
4
- import * as re from "three/examples/jsm/utils/SkeletonUtils.js";
5
- import { Canvas as Me, useThree as oe, useFrame as z, createPortal as ge } from "@react-three/fiber";
4
+ import * as oe from "three/examples/jsm/utils/SkeletonUtils.js";
5
+ import { Canvas as ge, useThree as re, useFrame as z, createPortal as Me } from "@react-three/fiber";
6
6
  import { KTX2Loader as he } from "three/examples/jsm/loaders/KTX2Loader.js";
7
7
  import { jsx as A, jsxs as se } from "react/jsx-runtime";
8
8
  function ye({
9
- position: n,
10
- controlsConfig: e
9
+ position: a,
10
+ controlsConfig: o
11
11
  }) {
12
- const { camera: s } = oe(), a = w(null);
12
+ const { camera: s } = re(), n = w(null);
13
13
  return I(() => {
14
- n && s && (s.position.set(n[0], n[1], n[2]), s.updateProjectionMatrix(), a.current && (a.current.target.set(0, 0, 0), a.current.update()));
15
- }, [n, s]), /* @__PURE__ */ A(
14
+ a && s && (s.position.set(a[0], a[1], a[2]), s.updateProjectionMatrix(), n.current && (n.current.target.set(0, 0, 0), n.current.update()));
15
+ }, [a, s]), /* @__PURE__ */ A(
16
16
  me,
17
17
  {
18
- ref: a,
18
+ ref: n,
19
19
  makeDefault: !0,
20
- enabled: e.enabled,
21
- enablePan: e.enablePan,
22
- enableZoom: e.enableZoom,
23
- enableRotate: e.enableRotate,
24
- minDistance: e.minDistance,
25
- maxDistance: e.maxDistance,
26
- minPolarAngle: e.minPolarAngle,
27
- maxPolarAngle: e.maxPolarAngle,
28
- autoRotate: e.autoRotate,
29
- autoRotateSpeed: e.autoRotateSpeed
20
+ enabled: o.enabled,
21
+ enablePan: o.enablePan,
22
+ enableZoom: o.enableZoom,
23
+ enableRotate: o.enableRotate,
24
+ minDistance: o.minDistance,
25
+ maxDistance: o.maxDistance,
26
+ minPolarAngle: o.minPolarAngle,
27
+ maxPolarAngle: o.maxPolarAngle,
28
+ autoRotate: o.autoRotate,
29
+ autoRotateSpeed: o.autoRotateSpeed
30
30
  }
31
31
  );
32
32
  }
33
- function Te({ background: n }) {
34
- const e = n == null ? void 0 : n.startsWith("#");
35
- return n ? e ? /* @__PURE__ */ A("color", { attach: "background", args: [n] }) : /* @__PURE__ */ A(Se, { url: n }) : null;
33
+ function Te({ background: a }) {
34
+ const o = a == null ? void 0 : a.startsWith("#");
35
+ return a ? o ? /* @__PURE__ */ A("color", { attach: "background", args: [a] }) : /* @__PURE__ */ A(Se, { url: a }) : null;
36
36
  }
37
- function Se({ url: n }) {
38
- const e = fe(n);
37
+ function Se({ url: a }) {
38
+ const o = fe(a);
39
39
  return W(() => {
40
- e.colorSpace = E.SRGBColorSpace;
41
- }, [e]), /* @__PURE__ */ A("primitive", { attach: "background", object: e });
40
+ o.colorSpace = E.SRGBColorSpace;
41
+ }, [o]), /* @__PURE__ */ A("primitive", { attach: "background", object: o });
42
42
  }
43
- function be({ config: n }) {
44
- switch (n.type) {
43
+ function $e({ config: a }) {
44
+ switch (a.type) {
45
45
  case "spot": {
46
46
  const {
47
- position: e = [5, 10, 5],
47
+ position: o = [5, 10, 5],
48
48
  intensity: s = 50,
49
- castShadow: a = !0,
50
- angle: u = Math.PI / 6,
51
- penumbra: M = 0.5,
52
- decay: h = 2,
49
+ castShadow: n = !0,
50
+ angle: p = Math.PI / 6,
51
+ penumbra: g = 0.5,
52
+ decay: y = 2,
53
53
  distance: S = 0,
54
- color: g = "#ffffff"
55
- } = n;
54
+ color: h = "#ffffff"
55
+ } = a;
56
56
  return /* @__PURE__ */ A(
57
57
  "spotLight",
58
58
  {
59
- position: e,
59
+ position: o,
60
60
  intensity: s,
61
- castShadow: a,
62
- angle: u,
63
- penumbra: M,
64
- decay: h,
61
+ castShadow: n,
62
+ angle: p,
63
+ penumbra: g,
64
+ decay: y,
65
65
  distance: S,
66
- color: g
66
+ color: h
67
67
  }
68
68
  );
69
69
  }
70
70
  case "point": {
71
71
  const {
72
- position: e = [0, 5, 0],
72
+ position: o = [0, 5, 0],
73
73
  intensity: s = 20,
74
- color: a = "#ffffff",
75
- distance: u = 0,
76
- decay: M = 2,
77
- castShadow: h = !1
78
- } = n;
74
+ color: n = "#ffffff",
75
+ distance: p = 0,
76
+ decay: g = 2,
77
+ castShadow: y = !1
78
+ } = a;
79
79
  return /* @__PURE__ */ A(
80
80
  "pointLight",
81
81
  {
82
- position: e,
82
+ position: o,
83
83
  intensity: s,
84
- color: a,
85
- distance: u,
86
- decay: M,
87
- castShadow: h
84
+ color: n,
85
+ distance: p,
86
+ decay: g,
87
+ castShadow: y
88
88
  }
89
89
  );
90
90
  }
91
91
  case "directional": {
92
92
  const {
93
- position: e = [10, 20, 10],
93
+ position: o = [10, 20, 10],
94
94
  intensity: s = 40,
95
- color: a = "#ffffff",
96
- castShadow: u = !0
97
- } = n;
95
+ color: n = "#ffffff",
96
+ castShadow: p = !0
97
+ } = a;
98
98
  return /* @__PURE__ */ A(
99
99
  "directionalLight",
100
100
  {
101
- position: e,
101
+ position: o,
102
102
  intensity: s,
103
- color: a,
104
- castShadow: u
103
+ color: n,
104
+ castShadow: p
105
105
  }
106
106
  );
107
107
  }
108
108
  case "hemisphere": {
109
109
  const {
110
- skyColor: e = "#ffffff",
110
+ skyColor: o = "#ffffff",
111
111
  groundColor: s = "#444444",
112
- intensity: a = 0.5,
113
- position: u = [0, 10, 0]
114
- } = n, M = W(() => new E.Color(e), [e]), h = W(() => new E.Color(s), [s]);
112
+ intensity: n = 0.5,
113
+ position: p = [0, 10, 0]
114
+ } = a, g = W(() => new E.Color(o), [o]), y = W(() => new E.Color(s), [s]);
115
115
  return /* @__PURE__ */ A(
116
116
  "hemisphereLight",
117
117
  {
118
- args: [M, h, a],
119
- position: u
118
+ args: [g, y, n],
119
+ position: p
120
120
  }
121
121
  );
122
122
  }
123
123
  case "ambient": {
124
124
  const {
125
- intensity: e = 0.5,
125
+ intensity: o = 0.5,
126
126
  color: s = "#ffffff"
127
- } = n;
127
+ } = a;
128
128
  return /* @__PURE__ */ A(
129
129
  "ambientLight",
130
130
  {
131
- intensity: e,
131
+ intensity: o,
132
132
  color: s
133
133
  }
134
134
  );
@@ -138,23 +138,23 @@ function be({ config: n }) {
138
138
  }
139
139
  }
140
140
  function Le({
141
- children: n,
142
- camera: e = {},
141
+ children: a,
142
+ camera: o = {},
143
143
  controls: s = {},
144
- background: a,
145
- shadows: u = !0,
146
- lights: M = [
144
+ background: n,
145
+ shadows: p = !0,
146
+ lights: g = [
147
147
  { type: "ambient", intensity: 0.5 },
148
148
  { type: "spot", position: [5, 10, 5], intensity: 50, castShadow: !0 }
149
149
  ],
150
- contactShadows: h = !0,
150
+ contactShadows: y = !0,
151
151
  style: S,
152
- className: g
152
+ className: h
153
153
  }) {
154
154
  const t = {
155
- position: e.position || [0, 2, 5],
156
- fov: e.fov || 45
157
- }, r = {
155
+ position: o.position || [0, 2, 5],
156
+ fov: o.fov || 45
157
+ }, e = {
158
158
  enabled: s.enabled ?? !0,
159
159
  enablePan: s.enablePan ?? !0,
160
160
  enableZoom: s.enableZoom ?? !0,
@@ -165,29 +165,29 @@ function Le({
165
165
  maxPolarAngle: s.maxPolarAngle,
166
166
  autoRotate: s.autoRotate ?? !1,
167
167
  autoRotateSpeed: s.autoRotateSpeed ?? 2
168
- }, i = typeof h == "object" ? {
169
- position: h.position || [0, -1, 0],
170
- opacity: h.opacity ?? 0.5,
171
- blur: h.blur ?? 2
172
- } : h ? { position: [0, -1, 0], opacity: 0.5, blur: 2 } : null;
173
- return /* @__PURE__ */ A("div", { style: S, className: g, children: /* @__PURE__ */ se(
174
- Me,
168
+ }, i = typeof y == "object" ? {
169
+ position: y.position || [0, -1, 0],
170
+ opacity: y.opacity ?? 0.5,
171
+ blur: y.blur ?? 2
172
+ } : y ? { position: [0, -1, 0], opacity: 0.5, blur: 2 } : null;
173
+ return /* @__PURE__ */ A("div", { style: S, className: h, children: /* @__PURE__ */ se(
174
+ ge,
175
175
  {
176
- shadows: u,
176
+ shadows: p,
177
177
  camera: {
178
178
  position: t.position,
179
179
  fov: t.fov
180
180
  },
181
181
  style: { width: "100%", height: "100%" },
182
182
  children: [
183
- /* @__PURE__ */ A(Q, { fallback: null, children: /* @__PURE__ */ A(Te, { background: a }) }),
184
- M.map((p, y) => /* @__PURE__ */ A(be, { config: p }, `${p.type}-${y}`)),
185
- /* @__PURE__ */ A(Q, { fallback: null, children: n }),
183
+ /* @__PURE__ */ A(Q, { fallback: null, children: /* @__PURE__ */ A(Te, { background: n }) }),
184
+ g.map((c, M) => /* @__PURE__ */ A($e, { config: c }, `${c.type}-${M}`)),
185
+ /* @__PURE__ */ A(Q, { fallback: null, children: a }),
186
186
  /* @__PURE__ */ A(
187
187
  ye,
188
188
  {
189
189
  position: t.position,
190
- controlsConfig: r
190
+ controlsConfig: e
191
191
  }
192
192
  ),
193
193
  i && /* @__PURE__ */ A(
@@ -202,199 +202,207 @@ function Le({
202
202
  }
203
203
  ) });
204
204
  }
205
- function G(n, e) {
206
- const s = w(/* @__PURE__ */ new Map()), a = w({}), u = w({});
205
+ function G(a, o) {
206
+ const s = w(/* @__PURE__ */ new Map()), n = w({}), p = w({});
207
207
  I(() => {
208
- e && (a.current = { ...e });
209
- }, [e]), I(() => {
210
- if (!n) return;
211
- const g = /* @__PURE__ */ new Map();
212
- n.traverse((t) => {
208
+ o && (n.current = { ...o });
209
+ }, [o]), I(() => {
210
+ if (!a) return;
211
+ const h = /* @__PURE__ */ new Map();
212
+ a.traverse((t) => {
213
213
  if (t.isMesh) {
214
- const r = t;
215
- r.name && g.set(r.name, r);
214
+ const e = t;
215
+ e.name && h.set(e.name, e);
216
216
  }
217
- }), s.current = g;
218
- }, [n]), z(() => {
219
- const g = s.current;
220
- if (g.size === 0) return;
221
- const t = { ...a.current, ...u.current };
222
- for (const [r, i] of Object.entries(t)) {
223
- const p = g.get(r);
224
- p && p.visible !== i && (p.visible = i);
217
+ }), s.current = h;
218
+ }, [a]), z(() => {
219
+ const h = s.current;
220
+ if (h.size === 0) return;
221
+ const t = { ...n.current, ...p.current };
222
+ for (const [e, i] of Object.entries(t)) {
223
+ const c = h.get(e);
224
+ c && c.visible !== i && (c.visible = i);
225
225
  }
226
226
  });
227
- const M = C((g, t) => {
228
- u.current[g] = t;
229
- const r = s.current.get(g);
230
- r && (r.visible = t);
231
- }, []), h = C(() => Array.from(s.current.keys()).sort(), []), S = C(() => {
232
- const g = {};
233
- return s.current.forEach((t, r) => {
234
- g[r] = t.visible;
235
- }), g;
227
+ const g = R((h, t) => {
228
+ p.current[h] = t;
229
+ const e = s.current.get(h);
230
+ e && (e.visible = t);
231
+ }, []), y = R(() => Array.from(s.current.keys()).sort(), []), S = R(() => {
232
+ const h = {};
233
+ return s.current.forEach((t, e) => {
234
+ h[e] = t.visible;
235
+ }), h;
236
236
  }, []);
237
237
  return {
238
- setMeshVisibility: M,
239
- getMeshNames: h,
238
+ setMeshVisibility: g,
239
+ getMeshNames: y,
240
240
  getMeshVisibility: S
241
241
  };
242
242
  }
243
- function V(n, e) {
244
- const s = w(/* @__PURE__ */ new Map()), a = w(/* @__PURE__ */ new Map());
243
+ function V(a, o) {
244
+ const s = w(/* @__PURE__ */ new Map()), n = w(/* @__PURE__ */ new Map());
245
245
  I(() => {
246
- if (!n) return;
246
+ if (!a) return;
247
247
  const t = /* @__PURE__ */ new Map();
248
- n.traverse((r) => {
249
- if (r.isMesh) {
250
- const i = r;
251
- (Array.isArray(i.material) ? i.material : [i.material]).forEach((y) => {
252
- y.name && !t.has(y.name) && t.set(y.name, y);
248
+ a.traverse((e) => {
249
+ if (e.isMesh) {
250
+ const i = e;
251
+ (Array.isArray(i.material) ? i.material : [i.material]).forEach((M) => {
252
+ M.name && !t.has(M.name) && t.set(M.name, M);
253
253
  });
254
254
  }
255
- }), s.current = t, e && Object.entries(e).forEach(([r, i]) => {
256
- const p = t.get(r);
257
- if (p && !Array.isArray(p)) {
258
- const y = u(i);
259
- p.color && p.color.copy(y), a.current.set(r, y);
255
+ }), s.current = t, console.log("[useMaterialColor] 🎨 Discovered materials:", Array.from(t.keys())), t.forEach((e, i) => {
256
+ if (!Array.isArray(e)) {
257
+ const c = e;
258
+ if (c.color) {
259
+ const M = c.color.clone();
260
+ console.log(`[useMaterialColor] 📋 Original color for "${i}": ${M.getHexString()}`), c.color.set(16777215), c.needsUpdate = !0, console.log(`[useMaterialColor] ✅ Reset "${i}" to white (0xffffff)`), n.current.set(i, c.color.clone());
261
+ }
262
+ }
263
+ }), o && Object.entries(o).forEach(([e, i]) => {
264
+ const c = t.get(e);
265
+ if (c && !Array.isArray(c)) {
266
+ const M = p(i);
267
+ c.color && c.color.copy(M), n.current.set(e, M), console.log(`[useMaterialColor] 🎨 Applied custom color for "${e}": ${M.getHexString()}`);
260
268
  }
261
269
  });
262
- }, [n, e]), z(() => {
263
- a.current.forEach((t, r) => {
264
- const i = s.current.get(r);
270
+ }, [a, o]), z(() => {
271
+ n.current.forEach((t, e) => {
272
+ const i = s.current.get(e);
265
273
  if (i && !Array.isArray(i)) {
266
- const p = i;
267
- p.color && !p.color.equals(t) && (p.color.copy(t), p.needsUpdate = !0);
274
+ const c = i;
275
+ c.color && !c.color.equals(t) && (console.log(`[useMaterialColor] 🔄 Applying color to "${e}": ${c.color.getHexString()} -> ${t.getHexString()}`), c.color.copy(t), c.needsUpdate = !0);
268
276
  }
269
277
  });
270
278
  });
271
- const u = (t) => typeof t == "string" ? new E.Color(t) : new E.Color(t[0], t[1], t[2]), M = C((t, r) => {
272
- const i = u(r);
273
- a.current.set(t, i);
274
- const p = s.current.get(t);
275
- if (p && !Array.isArray(p)) {
276
- const y = p;
277
- y.color && (y.color.copy(i), y.needsUpdate = !0);
279
+ const p = (t) => typeof t == "string" ? new E.Color(t) : new E.Color(t[0], t[1], t[2]), g = R((t, e) => {
280
+ const i = p(e);
281
+ n.current.set(t, i);
282
+ const c = s.current.get(t);
283
+ if (c && !Array.isArray(c)) {
284
+ const M = c;
285
+ M.color && (M.color.copy(i), M.needsUpdate = !0);
278
286
  }
279
- }, []), h = C(() => Array.from(s.current.keys()).sort(), []), S = C((t) => {
280
- const r = s.current.get(t);
281
- if (r && !Array.isArray(r)) {
282
- const i = r;
287
+ }, []), y = R(() => Array.from(s.current.keys()).sort(), []), S = R((t) => {
288
+ const e = s.current.get(t);
289
+ if (e && !Array.isArray(e)) {
290
+ const i = e;
283
291
  if (i.color)
284
292
  return "#" + i.color.getHexString();
285
293
  }
286
294
  return null;
287
- }, []), g = C(() => {
295
+ }, []), h = R(() => {
288
296
  const t = {};
289
- return s.current.forEach((r, i) => {
290
- if (!Array.isArray(r)) {
291
- const p = r;
292
- p.color && (t[i] = "#" + p.color.getHexString());
297
+ return s.current.forEach((e, i) => {
298
+ if (!Array.isArray(e)) {
299
+ const c = e;
300
+ c.color && (t[i] = "#" + c.color.getHexString());
293
301
  }
294
302
  }), t;
295
303
  }, []);
296
304
  return {
297
- setMaterialColor: M,
298
- getMaterialNames: h,
305
+ setMaterialColor: g,
306
+ getMaterialNames: y,
299
307
  getMaterialColor: S,
300
- getAllMaterialColors: g
308
+ getAllMaterialColors: h
301
309
  };
302
310
  }
303
- function Y(n, e) {
304
- const { gl: s } = oe(), a = w(/* @__PURE__ */ new Map()), u = w(new E.TextureLoader()), M = w(null), h = w(/* @__PURE__ */ new Map()), S = w(/* @__PURE__ */ new Set()), g = w("");
311
+ function Y(a, o) {
312
+ const { gl: s } = re(), n = w(/* @__PURE__ */ new Map()), p = w(new E.TextureLoader()), g = w(null), y = w(/* @__PURE__ */ new Map()), S = w(/* @__PURE__ */ new Set()), h = w("");
305
313
  I(() => {
306
- if (!M.current)
314
+ if (!g.current)
307
315
  try {
308
- const o = typeof WebAssembly == "object" && typeof WebAssembly.validate == "function";
309
- console.log("[useMaterialTexture] Browser features:"), console.log(` WebAssembly supported: ${o}`), console.log(` WebGL2: ${s.capabilities.isWebGL2}`);
316
+ const r = typeof WebAssembly == "object" && typeof WebAssembly.validate == "function";
317
+ console.log("[useMaterialTexture] Browser features:"), console.log(` WebAssembly supported: ${r}`), console.log(` WebGL2: ${s.capabilities.isWebGL2}`);
310
318
  const l = new he();
311
- l.setTranscoderPath("/basis/"), l.detectSupport(s), M.current = l, console.log("[useMaterialTexture] ✅ KTX2Loader initialized"), console.log("[useMaterialTexture] Transcoder path: /basis/"), fetch("/basis/basis_transcoder.wasm").then((m) => {
319
+ l.setTranscoderPath("/basis/"), l.detectSupport(s), g.current = l, console.log("[useMaterialTexture] ✅ KTX2Loader initialized"), console.log("[useMaterialTexture] Transcoder path: /basis/"), fetch("/basis/basis_transcoder.wasm").then((m) => {
312
320
  m.ok ? console.log("[useMaterialTexture] ✅ basis_transcoder.wasm is accessible") : console.error("[useMaterialTexture] ❌ basis_transcoder.wasm returned", m.status);
313
321
  }).catch((m) => {
314
322
  console.error("[useMaterialTexture] ❌ Failed to check basis_transcoder.wasm:", m);
315
- }), o || (console.warn("[useMaterialTexture] ⚠️ WebAssembly not supported! KTX2 will fallback to CPU decoding (slow)"), console.warn("[useMaterialTexture] ⚠️ Recommend using WebP instead of KTX2 for this browser"));
316
- } catch (o) {
317
- console.error("[useMaterialTexture] ❌ Failed to initialize KTX2Loader:", o);
323
+ }), r || (console.warn("[useMaterialTexture] ⚠️ WebAssembly not supported! KTX2 will fallback to CPU decoding (slow)"), console.warn("[useMaterialTexture] ⚠️ Recommend using WebP instead of KTX2 for this browser"));
324
+ } catch (r) {
325
+ console.error("[useMaterialTexture] ❌ Failed to initialize KTX2Loader:", r);
318
326
  }
319
327
  return () => {
320
- M.current && (M.current.dispose(), M.current = null);
328
+ g.current && (g.current.dispose(), g.current = null);
321
329
  };
322
330
  }, [s]), I(() => {
323
- if (!n) return;
324
- const o = /* @__PURE__ */ new Map();
325
- n.traverse((l) => {
331
+ if (!a) return;
332
+ const r = /* @__PURE__ */ new Map();
333
+ a.traverse((l) => {
326
334
  if (l.isMesh) {
327
335
  const m = l;
328
336
  (Array.isArray(m.material) ? m.material : [m.material]).forEach((f) => {
329
- f.name && !o.has(f.name) && o.set(f.name, f);
337
+ f.name && !r.has(f.name) && r.set(f.name, f);
330
338
  });
331
339
  }
332
- }), a.current = o;
333
- }, [n]);
334
- const t = C((o) => o.toLowerCase().endsWith(".ktx2") ? M.current ? M.current : (console.warn("[useMaterialTexture] KTX2Loader not initialized, falling back to TextureLoader"), u.current) : u.current, []);
340
+ }), n.current = r;
341
+ }, [a]);
342
+ const t = R((r) => r.toLowerCase().endsWith(".ktx2") ? g.current ? g.current : (console.warn("[useMaterialTexture] KTX2Loader not initialized, falling back to TextureLoader"), p.current) : p.current, []);
335
343
  I(() => {
336
- if (!e || !n) return;
337
- const o = a.current;
338
- if (o.size === 0) return;
339
- const l = JSON.stringify(e);
340
- if (g.current === l) {
344
+ if (!o || !a) return;
345
+ const r = n.current;
346
+ if (r.size === 0) return;
347
+ const l = JSON.stringify(o);
348
+ if (h.current === l) {
341
349
  console.log("[useMaterialTexture] Textures unchanged, skipping reload");
342
350
  return;
343
351
  }
344
- g.current = l;
352
+ h.current = l;
345
353
  let m = !1;
346
- const b = /* @__PURE__ */ new Map();
347
- Object.entries(e).forEach(([d, T]) => {
348
- b.set(d, typeof T == "string" ? { map: T } : T);
349
- }), console.log("[useMaterialTexture] Starting texture load for", b.size, "materials");
354
+ const $ = /* @__PURE__ */ new Map();
355
+ Object.entries(o).forEach(([d, T]) => {
356
+ $.set(d, typeof T == "string" ? { map: T } : T);
357
+ }), console.log("[useMaterialTexture] Starting texture load for", $.size, "materials");
350
358
  const f = [];
351
- b.forEach((d, T) => {
359
+ $.forEach((d, T) => {
352
360
  var x, D;
353
- const j = o.get(T);
361
+ const j = r.get(T);
354
362
  if (!j || !j.isMeshStandardMaterial) {
355
363
  console.warn(`[useMaterialTexture] Material "${T}" not found or not MeshStandardMaterial`);
356
364
  return;
357
365
  }
358
- const c = j;
359
- console.log(`[useMaterialTexture] 📋 Material "${T}" BEFORE reset:`), console.log(` - map: ${c.map ? "EXISTS" : "null"} ${c.map ? `(uuid: ${c.map.uuid})` : ""}`), console.log(` - normalMap: ${c.normalMap ? "EXISTS" : "null"}`), console.log(` - roughnessMap: ${c.roughnessMap ? "EXISTS" : "null"}`), console.log(` - metalnessMap: ${c.metalnessMap ? "EXISTS" : "null"}`), console.log(` - emissiveMap: ${c.emissiveMap ? "EXISTS" : "null"}`), console.log(` - aoMap: ${c.aoMap ? "EXISTS" : "null"}`), console.log(` - color: ${(x = c.color) == null ? void 0 : x.getHexString()}`), console.log(` - emissive: ${(D = c.emissive) == null ? void 0 : D.getHexString()}`), console.log(` - material uuid: ${c.uuid}`), c.map && (console.log(`[useMaterialTexture] 🗑️ Disposing old map (uuid: ${c.map.uuid})`), c.map.dispose()), c.normalMap && (console.log("[useMaterialTexture] 🗑️ Disposing old normalMap"), c.normalMap.dispose()), c.roughnessMap && (console.log("[useMaterialTexture] 🗑️ Disposing old roughnessMap"), c.roughnessMap.dispose()), c.metalnessMap && (console.log("[useMaterialTexture] 🗑️ Disposing old metalnessMap"), c.metalnessMap.dispose()), c.emissiveMap && (console.log("[useMaterialTexture] 🗑️ Disposing old emissiveMap"), c.emissiveMap.dispose()), c.aoMap && (console.log("[useMaterialTexture] 🗑️ Disposing old aoMap"), c.aoMap.dispose()), c.map = null, c.normalMap = null, c.roughnessMap = null, c.metalnessMap = null, c.emissiveMap = null, c.emissive = new E.Color(0), c.emissiveIntensity = 0, c.aoMap = null, c.needsUpdate = !0, console.log(`[useMaterialTexture] ✅ Material "${T}" AFTER reset: all maps cleared and disposed`), Object.entries(d).forEach(([$, k]) => {
366
+ const u = j;
367
+ console.log(`[useMaterialTexture] 📋 Material "${T}" BEFORE reset:`), console.log(` - map: ${u.map ? "EXISTS" : "null"} ${u.map ? `(uuid: ${u.map.uuid})` : ""}`), console.log(` - normalMap: ${u.normalMap ? "EXISTS" : "null"}`), console.log(` - roughnessMap: ${u.roughnessMap ? "EXISTS" : "null"}`), console.log(` - metalnessMap: ${u.metalnessMap ? "EXISTS" : "null"}`), console.log(` - emissiveMap: ${u.emissiveMap ? "EXISTS" : "null"}`), console.log(` - aoMap: ${u.aoMap ? "EXISTS" : "null"}`), console.log(` - color: ${(x = u.color) == null ? void 0 : x.getHexString()}`), console.log(` - emissive: ${(D = u.emissive) == null ? void 0 : D.getHexString()}`), console.log(` - material uuid: ${u.uuid}`), u.map && (console.log(`[useMaterialTexture] 🗑️ Disposing old map (uuid: ${u.map.uuid})`), u.map.dispose()), u.normalMap && (console.log("[useMaterialTexture] 🗑️ Disposing old normalMap"), u.normalMap.dispose()), u.roughnessMap && (console.log("[useMaterialTexture] 🗑️ Disposing old roughnessMap"), u.roughnessMap.dispose()), u.metalnessMap && (console.log("[useMaterialTexture] 🗑️ Disposing old metalnessMap"), u.metalnessMap.dispose()), u.emissiveMap && (console.log("[useMaterialTexture] 🗑️ Disposing old emissiveMap"), u.emissiveMap.dispose()), u.aoMap && (console.log("[useMaterialTexture] 🗑️ Disposing old aoMap"), u.aoMap.dispose()), u.map = null, u.normalMap = null, u.roughnessMap = null, u.metalnessMap = null, u.emissiveMap = null, u.emissive = new E.Color(0), u.emissiveIntensity = 0, u.aoMap = null, u.needsUpdate = !0, console.log(`[useMaterialTexture] ✅ Material "${T}" AFTER reset: all maps cleared and disposed`), Object.entries(d).forEach(([b, k]) => {
360
368
  if (!k) return;
361
- const L = `${T}_${$}_${k}`, N = h.current.get(L);
362
- if (N) {
363
- console.log(`[useMaterialTexture] Using cached texture: ${T}.${$}`), m || r(c, $, N);
369
+ const L = `${T}_${b}_${k}`, P = y.current.get(L);
370
+ if (P) {
371
+ console.log(`[useMaterialTexture] Using cached texture: ${T}.${b}`), m || e(u, b, P);
364
372
  return;
365
373
  }
366
374
  if (S.current.has(L)) {
367
- console.log(`[useMaterialTexture] Skipping already loading: ${T}.${$}`);
375
+ console.log(`[useMaterialTexture] Skipping already loading: ${T}.${b}`);
368
376
  return;
369
377
  }
370
- f.push({ materialName: T, textureType: $, url: k, material: c });
378
+ f.push({ materialName: T, textureType: b, url: k, material: u });
371
379
  });
372
380
  }), console.log(`[useMaterialTexture] Queued ${f.length} textures to load`);
373
381
  let v = 0;
374
- const R = () => {
382
+ const C = () => {
375
383
  if (m || v >= f.length) {
376
- console.log("[useMaterialTexture] ✅ All textures loaded"), console.log("[useMaterialTexture] 📊 FINAL material states:"), o.forEach((x, D) => {
384
+ console.log("[useMaterialTexture] ✅ All textures loaded"), console.log("[useMaterialTexture] 📊 FINAL material states:"), r.forEach((x, D) => {
377
385
  var k, L;
378
- const $ = x;
379
- console.log(` Material "${D}":`), console.log(` - map: ${$.map ? "EXISTS" : "null"} ${$.map ? `(colorSpace: ${$.map.colorSpace})` : ""}`), console.log(` - normalMap: ${$.normalMap ? "EXISTS" : "null"}`), console.log(` - roughnessMap: ${$.roughnessMap ? "EXISTS" : "null"}`), console.log(` - metalnessMap: ${$.metalnessMap ? "EXISTS" : "null"}`), console.log(` - emissiveMap: ${$.emissiveMap ? "EXISTS" : "null"}`), console.log(` - color: ${(k = $.color) == null ? void 0 : k.getHexString()}`), console.log(` - emissive: ${(L = $.emissive) == null ? void 0 : L.getHexString()}`), console.log(` - emissiveIntensity: ${$.emissiveIntensity}`), console.log(` - roughness: ${$.roughness}`), console.log(` - metalness: ${$.metalness}`);
386
+ const b = x;
387
+ console.log(` Material "${D}":`), console.log(` - map: ${b.map ? "EXISTS" : "null"} ${b.map ? `(colorSpace: ${b.map.colorSpace})` : ""}`), console.log(` - normalMap: ${b.normalMap ? "EXISTS" : "null"}`), console.log(` - roughnessMap: ${b.roughnessMap ? "EXISTS" : "null"}`), console.log(` - metalnessMap: ${b.metalnessMap ? "EXISTS" : "null"}`), console.log(` - emissiveMap: ${b.emissiveMap ? "EXISTS" : "null"}`), console.log(` - color: ${(k = b.color) == null ? void 0 : k.getHexString()}`), console.log(` - emissive: ${(L = b.emissive) == null ? void 0 : L.getHexString()}`), console.log(` - emissiveIntensity: ${b.emissiveIntensity}`), console.log(` - roughness: ${b.roughness}`), console.log(` - metalness: ${b.metalness}`);
380
388
  });
381
389
  return;
382
390
  }
383
391
  const d = f[v++], T = `${d.materialName}_${d.textureType}_${d.url}`;
384
392
  console.log(`[useMaterialTexture] Loading (${v}/${f.length}): ${d.materialName}.${d.textureType} from ${d.url}`), S.current.add(T);
385
- const j = t(d.url), c = d.url.toLowerCase().endsWith(".ktx2") ? "KTX2Loader" : "TextureLoader";
386
- console.log(`[useMaterialTexture] Using ${c} for ${d.url}`), j.load(
393
+ const j = t(d.url), u = d.url.toLowerCase().endsWith(".ktx2") ? "KTX2Loader" : "TextureLoader";
394
+ console.log(`[useMaterialTexture] Using ${u} for ${d.url}`), j.load(
387
395
  d.url,
388
396
  (x) => {
389
- var L, N, B, X, O, _;
397
+ var L, P, B, X, O, _;
390
398
  if (S.current.delete(T), m) {
391
399
  console.log(`[useMaterialTexture] Disposed, cleaning up texture: ${d.materialName}.${d.textureType}`), x.dispose();
392
400
  return;
393
401
  }
394
- const D = ((L = x.image) == null ? void 0 : L.width) || ((B = (N = x.source) == null ? void 0 : N.data) == null ? void 0 : B.width) || "unknown", $ = ((X = x.image) == null ? void 0 : X.height) || ((_ = (O = x.source) == null ? void 0 : O.data) == null ? void 0 : _.height) || "unknown";
395
- console.log(`[useMaterialTexture] ✅ Loaded: ${d.materialName}.${d.textureType} (${D}x${$})`), x.colorSpace = d.textureType === "map" || d.textureType === "emissiveMap" ? E.SRGBColorSpace : E.NoColorSpace, x.wrapS = E.RepeatWrapping, x.wrapT = E.RepeatWrapping, x.flipY = !1, h.current.set(T, x), r(d.material, d.textureType, x);
396
- const k = d.url.endsWith(".ktx2") ? 500 : 15056;
397
- console.log(`[useMaterialTexture] Waiting111111 ${k}ms before next texture...`), setTimeout(R, 0);
402
+ const D = ((L = x.image) == null ? void 0 : L.width) || ((B = (P = x.source) == null ? void 0 : P.data) == null ? void 0 : B.width) || "unknown", b = ((X = x.image) == null ? void 0 : X.height) || ((_ = (O = x.source) == null ? void 0 : O.data) == null ? void 0 : _.height) || "unknown";
403
+ console.log(`[useMaterialTexture] ✅ Loaded: ${d.materialName}.${d.textureType} (${D}x${b})`), x.colorSpace = d.textureType === "map" || d.textureType === "emissiveMap" ? E.SRGBColorSpace : E.NoColorSpace, x.wrapS = E.RepeatWrapping, x.wrapT = E.RepeatWrapping, x.flipY = !1, y.current.set(T, x), e(d.material, d.textureType, x);
404
+ const k = d.url.endsWith(".ktx2") ? 500 : 150;
405
+ console.log(`[useMaterialTexture] Waiting111111 ${k}ms before next texture...`), setTimeout(C, 0);
398
406
  },
399
407
  (x) => {
400
408
  if (x.lengthComputable) {
@@ -403,299 +411,299 @@ function Y(n, e) {
403
411
  }
404
412
  },
405
413
  (x) => {
406
- S.current.delete(T), m || (console.error(`[useMaterialTexture] ❌ Failed to load ${d.materialName}.${d.textureType} from ${d.url}`), console.error("[useMaterialTexture] Error details:", x), console.error("[useMaterialTexture] Loader type:", c), d.url.endsWith(".ktx2") && (console.error("[useMaterialTexture] KTX2 error - file may not be in Basis Universal format!"), console.error("[useMaterialTexture] Make sure files are created with: gltf-transform etc1s input.png output.ktx2"))), setTimeout(R, 100);
414
+ S.current.delete(T), m || (console.error(`[useMaterialTexture] ❌ Failed to load ${d.materialName}.${d.textureType} from ${d.url}`), console.error("[useMaterialTexture] Error details:", x), console.error("[useMaterialTexture] Loader type:", u), d.url.endsWith(".ktx2") && (console.error("[useMaterialTexture] KTX2 error - file may not be in Basis Universal format!"), console.error("[useMaterialTexture] Make sure files are created with: gltf-transform etc1s input.png output.ktx2"))), setTimeout(C, 100);
407
415
  }
408
416
  );
409
417
  };
410
- return R(), () => {
418
+ return C(), () => {
411
419
  console.log("[useMaterialTexture] Cleanup: disposed"), m = !0;
412
420
  };
413
- }, [n, e, t]);
414
- const r = (o, l, m) => {
415
- var b, f;
416
- switch (console.log(`[useMaterialTexture] 🎨 Applying texture: ${o.name}.${l} (texture uuid: ${m.uuid})`), l) {
421
+ }, [a, o, t]);
422
+ const e = (r, l, m) => {
423
+ var $, f;
424
+ switch (console.log(`[useMaterialTexture] 🎨 Applying texture: ${r.name}.${l} (texture uuid: ${m.uuid})`), l) {
417
425
  case "map":
418
- o.map = m;
426
+ r.map = m;
419
427
  break;
420
428
  case "normalMap":
421
- o.normalMap = m;
429
+ r.normalMap = m;
422
430
  break;
423
431
  case "roughnessMap":
424
- o.roughnessMap = m;
432
+ r.roughnessMap = m;
425
433
  break;
426
434
  case "metalnessMap":
427
- o.metalnessMap = m;
435
+ r.metalnessMap = m;
428
436
  break;
429
437
  case "emissiveMap":
430
- o.emissiveMap = m, o.emissive = new E.Color(16777215), o.emissiveIntensity = 1;
438
+ r.emissiveMap = m, r.emissive = new E.Color(16777215), r.emissiveIntensity = 1;
431
439
  break;
432
440
  case "alphaMap":
433
- console.log(`[useMaterialTexture] Skipping alphaMap for "${o.name}" to prevent disappearing`);
441
+ console.log(`[useMaterialTexture] Skipping alphaMap for "${r.name}" to prevent disappearing`);
434
442
  break;
435
443
  case "aoMap":
436
- o.aoMap = m;
444
+ r.aoMap = m;
437
445
  break;
438
446
  }
439
- o.needsUpdate = !0, console.log(`[useMaterialTexture] ✅ Applied ${l} to ${o.name}, needsUpdate=true`), console.log(`[useMaterialTexture] 📊 Material "${o.name}" FINAL state:`), console.log(` - map: ${o.map ? "EXISTS" : "null"} ${o.map ? `(uuid: ${o.map.uuid}, colorSpace: ${o.map.colorSpace})` : ""}`), console.log(` - normalMap: ${o.normalMap ? "EXISTS" : "null"}`), console.log(` - roughnessMap: ${o.roughnessMap ? "EXISTS" : "null"}`), console.log(` - metalnessMap: ${o.metalnessMap ? "EXISTS" : "null"}`), console.log(` - emissiveMap: ${o.emissiveMap ? "EXISTS" : "null"}`), console.log(` - aoMap: ${o.aoMap ? "EXISTS" : "null"}`), console.log(` - color: ${(b = o.color) == null ? void 0 : b.getHexString()}`), console.log(` - emissive: ${(f = o.emissive) == null ? void 0 : f.getHexString()}`), console.log(` - emissiveIntensity: ${o.emissiveIntensity}`), console.log(` - roughness: ${o.roughness}`), console.log(` - metalness: ${o.metalness}`);
440
- }, i = C((o, l) => {
441
- const m = typeof l == "string" ? { map: l } : l, b = a.current.get(o);
442
- if (!b || !b.isMeshStandardMaterial) {
443
- console.warn(`Material "${o}" not found or not MeshStandardMaterial`);
447
+ r.needsUpdate = !0, console.log(`[useMaterialTexture] ✅ Applied ${l} to ${r.name}, needsUpdate=true`), console.log(`[useMaterialTexture] 📊 Material "${r.name}" FINAL state:`), console.log(` - map: ${r.map ? "EXISTS" : "null"} ${r.map ? `(uuid: ${r.map.uuid}, colorSpace: ${r.map.colorSpace})` : ""}`), console.log(` - normalMap: ${r.normalMap ? "EXISTS" : "null"}`), console.log(` - roughnessMap: ${r.roughnessMap ? "EXISTS" : "null"}`), console.log(` - metalnessMap: ${r.metalnessMap ? "EXISTS" : "null"}`), console.log(` - emissiveMap: ${r.emissiveMap ? "EXISTS" : "null"}`), console.log(` - aoMap: ${r.aoMap ? "EXISTS" : "null"}`), console.log(` - color: ${($ = r.color) == null ? void 0 : $.getHexString()}`), console.log(` - emissive: ${(f = r.emissive) == null ? void 0 : f.getHexString()}`), console.log(` - emissiveIntensity: ${r.emissiveIntensity}`), console.log(` - roughness: ${r.roughness}`), console.log(` - metalness: ${r.metalness}`);
448
+ }, i = R((r, l) => {
449
+ const m = typeof l == "string" ? { map: l } : l, $ = n.current.get(r);
450
+ if (!$ || !$.isMeshStandardMaterial) {
451
+ console.warn(`Material "${r}" not found or not MeshStandardMaterial`);
444
452
  return;
445
453
  }
446
- const f = b;
447
- Object.entries(m).forEach(([v, R]) => {
448
- if (!R) return;
449
- const d = `${o}_${v}_${R}`, T = h.current.get(d);
454
+ const f = $;
455
+ Object.entries(m).forEach(([v, C]) => {
456
+ if (!C) return;
457
+ const d = `${r}_${v}_${C}`, T = y.current.get(d);
450
458
  if (T) {
451
- r(f, v, T);
459
+ e(f, v, T);
452
460
  return;
453
461
  }
454
- t(R).load(
455
- R,
456
- (c) => {
457
- c.colorSpace = v === "map" || v === "emissiveMap" ? E.SRGBColorSpace : E.NoColorSpace, c.wrapS = E.RepeatWrapping, c.wrapT = E.RepeatWrapping, h.current.set(d, c), r(f, v, c);
462
+ t(C).load(
463
+ C,
464
+ (u) => {
465
+ u.colorSpace = v === "map" || v === "emissiveMap" ? E.SRGBColorSpace : E.NoColorSpace, u.wrapS = E.RepeatWrapping, u.wrapT = E.RepeatWrapping, y.current.set(d, u), e(f, v, u);
458
466
  },
459
467
  void 0,
460
- (c) => {
461
- console.error(`Failed to load texture ${R}:`, c);
468
+ (u) => {
469
+ console.error(`Failed to load texture ${C}:`, u);
462
470
  }
463
471
  );
464
472
  });
465
- }, [t]), p = C(() => Array.from(a.current.keys()).sort(), []), y = C((o) => {
466
- const l = a.current.get(o);
473
+ }, [t]), c = R(() => Array.from(n.current.keys()).sort(), []), M = R((r) => {
474
+ const l = n.current.get(r);
467
475
  if (!l || !l.isMeshStandardMaterial) return;
468
476
  const m = l;
469
477
  m.map = null, m.normalMap = null, m.roughnessMap = null, m.metalnessMap = null, m.emissiveMap = null, m.alphaMap = null, m.aoMap = null, m.needsUpdate = !0;
470
478
  }, []);
471
479
  return {
472
480
  setMaterialTextures: i,
473
- getMaterialNames: p,
474
- clearMaterialTextures: y
481
+ getMaterialNames: c,
482
+ clearMaterialTextures: M
475
483
  };
476
484
  }
477
- function $e({
478
- url: n,
479
- position: e = [0, 0, 0],
485
+ function be({
486
+ url: a,
487
+ position: o = [0, 0, 0],
480
488
  rotation: s = [0, 0, 0],
481
- scale: a = 1,
482
- meshVisibility: u,
483
- materialColors: M,
484
- materialTextures: h,
489
+ scale: n = 1,
490
+ meshVisibility: p,
491
+ materialColors: g,
492
+ materialTextures: y,
485
493
  onLoad: S,
486
- onError: g
494
+ onError: h
487
495
  }) {
488
- const { scene: t } = H(n), r = w(S);
489
- r.current = S;
496
+ const { scene: t } = H(a), e = w(S);
497
+ e.current = S;
490
498
  const i = W(() => {
491
- const y = t.clone();
499
+ const M = t.clone();
492
500
  console.log("[Model] 🔍 Scene clone created, checking materials...");
493
- const o = [], l = /* @__PURE__ */ new Set(), m = [];
494
- let b = 0;
495
- return y.traverse((f) => {
496
- if (b++, f.type === "Bone" && m.push(f.name), f.isMesh) {
501
+ const r = [], l = /* @__PURE__ */ new Set(), m = [];
502
+ let $ = 0;
503
+ return M.traverse((f) => {
504
+ if ($++, f.type === "Bone" && m.push(f.name), f.isMesh) {
497
505
  const v = f;
498
- o.push(v.name), v.castShadow = !0, v.receiveShadow = !0, (Array.isArray(v.material) ? v.material : [v.material]).forEach((d) => {
506
+ r.push(v.name), v.castShadow = !0, v.receiveShadow = !0, (Array.isArray(v.material) ? v.material : [v.material]).forEach((d) => {
499
507
  l.add(d.name), console.log(`[Model] 📦 Material found: "${d.name}" (uuid: ${d.uuid})`);
500
508
  const T = d;
501
509
  console.log(` - Has map: ${T.map ? "YES" : "NO"}`), console.log(` - Has normalMap: ${T.normalMap ? "YES" : "NO"}`), console.log(` - Has roughnessMap: ${T.roughnessMap ? "YES" : "NO"}`), console.log(` - Has metalnessMap: ${T.metalnessMap ? "YES" : "NO"}`);
502
510
  });
503
511
  }
504
- }), console.log(`[Model] 📊 Clone summary: ${o.length} meshes, ${l.size} materials`), setTimeout(() => {
512
+ }), console.log(`[Model] 📊 Clone summary: ${r.length} meshes, ${l.size} materials`), setTimeout(() => {
505
513
  var f;
506
- (f = r.current) == null || f.call(r, {
507
- meshes: o.sort(),
514
+ (f = e.current) == null || f.call(e, {
515
+ meshes: r.sort(),
508
516
  materials: Array.from(l).sort(),
509
517
  bones: m.sort(),
510
- nodeCount: b
518
+ nodeCount: $
511
519
  });
512
- }, 0), y;
520
+ }, 0), M;
513
521
  }, [t]);
514
- return G(i, u), V(i, M), Y(i, h), /* @__PURE__ */ A("group", { position: e, rotation: s, scale: typeof a == "number" ? [a, a, a] : a, children: /* @__PURE__ */ A("primitive", { object: i }) });
522
+ return G(i, p), V(i, g), Y(i, y), /* @__PURE__ */ A("group", { position: o, rotation: s, scale: typeof n == "number" ? [n, n, n] : n, children: /* @__PURE__ */ A("primitive", { object: i }) });
515
523
  }
516
- $e.preload = (n) => {
517
- H.preload(n);
524
+ be.preload = (a) => {
525
+ H.preload(a);
518
526
  };
519
- function xe(n, e, s) {
520
- const { actions: a, names: u } = de(n, e), M = w(null), h = w(s == null ? void 0 : s.defaultAnimation);
527
+ function xe(a, o, s) {
528
+ const { actions: n, names: p } = de(a, o), g = w(null), y = w(s == null ? void 0 : s.defaultAnimation);
521
529
  I(() => {
522
- if (u.length === 0) return;
523
- const r = h.current;
524
- let i = u[0];
525
- if (r) {
526
- const y = u.find((o) => o === r || o.includes(r));
527
- y && (i = y);
530
+ if (p.length === 0) return;
531
+ const e = y.current;
532
+ let i = p[0];
533
+ if (e) {
534
+ const M = p.find((r) => r === e || r.includes(e));
535
+ M && (i = M);
528
536
  }
529
- const p = a[i];
530
- p && (p.reset().fadeIn(0.5).play(), M.current = p);
531
- }, [a, u]);
532
- const S = C(
533
- (r, i) => {
537
+ const c = n[i];
538
+ c && (c.reset().fadeIn(0.5).play(), g.current = c);
539
+ }, [n, p]);
540
+ const S = R(
541
+ (e, i) => {
534
542
  const {
535
- loop: p = !1,
536
- crossFadeDuration: y = 0.2,
537
- restoreDefault: o = !0
543
+ loop: c = !1,
544
+ crossFadeDuration: M = 0.2,
545
+ restoreDefault: r = !0
538
546
  } = i || {};
539
- let l = a[r];
547
+ let l = n[e];
540
548
  if (!l) {
541
- const b = Object.keys(a).find(
542
- (f) => f.toLowerCase().includes(r.toLowerCase()) || r.toLowerCase().includes(f.toLowerCase())
549
+ const $ = Object.keys(n).find(
550
+ (f) => f.toLowerCase().includes(e.toLowerCase()) || e.toLowerCase().includes(f.toLowerCase())
543
551
  );
544
- b && (l = a[b]);
552
+ $ && (l = n[$]);
545
553
  }
546
554
  if (!l) {
547
- console.warn(`Animation "${r}" not found. Available: ${u.join(", ")}`);
555
+ console.warn(`Animation "${e}" not found. Available: ${p.join(", ")}`);
548
556
  return;
549
557
  }
550
- const m = M.current;
551
- if (!(m === l && l.isRunning()) && (m && m !== l && m.fadeOut(y), l.reset(), l.fadeIn(y), l.setLoop(
552
- p ? E.LoopRepeat : E.LoopOnce,
553
- p ? 1 / 0 : 1
554
- ), l.clampWhenFinished = !p, l.play(), p || l.getMixer().update(0), M.current = l, o && !p && h.current)) {
555
- const b = l.getMixer(), f = (v) => {
558
+ const m = g.current;
559
+ if (!(m === l && l.isRunning()) && (m && m !== l && m.fadeOut(M), l.reset(), l.fadeIn(M), l.setLoop(
560
+ c ? E.LoopRepeat : E.LoopOnce,
561
+ c ? 1 / 0 : 1
562
+ ), l.clampWhenFinished = !c, l.play(), c || l.getMixer().update(0), g.current = l, r && !c && y.current)) {
563
+ const $ = l.getMixer(), f = (v) => {
556
564
  if (v.action === l) {
557
- b.removeEventListener("finished", f);
558
- const R = a[h.current];
559
- R && (l.fadeOut(y), R.reset().fadeIn(y).play(), M.current = R);
565
+ $.removeEventListener("finished", f);
566
+ const C = n[y.current];
567
+ C && (l.fadeOut(M), C.reset().fadeIn(M).play(), g.current = C);
560
568
  }
561
569
  };
562
- b.addEventListener("finished", f);
570
+ $.addEventListener("finished", f);
563
571
  }
564
572
  },
565
- [a, u]
566
- ), g = C(() => {
567
- var r;
568
- (r = M.current) == null || r.fadeOut(0.2), M.current = null;
569
- }, []), t = C(() => u, [u]);
573
+ [n, p]
574
+ ), h = R(() => {
575
+ var e;
576
+ (e = g.current) == null || e.fadeOut(0.2), g.current = null;
577
+ }, []), t = R(() => p, [p]);
570
578
  return {
571
579
  playAnimation: S,
572
- stopAnimation: g,
580
+ stopAnimation: h,
573
581
  getAnimationNames: t,
574
- actions: a
582
+ actions: n
575
583
  };
576
584
  }
577
- function ne(n, e) {
578
- const s = w(e || {}), a = w([]), u = w([]);
585
+ function ne(a, o) {
586
+ const s = w(o || {}), n = w([]), p = w([]);
579
587
  I(() => {
580
- const g = /* @__PURE__ */ new Set(), t = [];
581
- n.traverse((r) => {
582
- r instanceof E.Mesh && r.morphTargetDictionary && r.morphTargetInfluences && (t.push(r), Object.keys(r.morphTargetDictionary).forEach((i) => {
583
- g.add(i);
588
+ const h = /* @__PURE__ */ new Set(), t = [];
589
+ a.traverse((e) => {
590
+ e instanceof E.Mesh && e.morphTargetDictionary && e.morphTargetInfluences && (t.push(e), Object.keys(e.morphTargetDictionary).forEach((i) => {
591
+ h.add(i);
584
592
  }));
585
- }), a.current = Array.from(g).sort(), u.current = t;
586
- }, [n]), z(() => {
587
- const g = s.current;
588
- u.current.forEach((t) => {
589
- !t.morphTargetDictionary || !t.morphTargetInfluences || Object.entries(g).forEach(([r, i]) => {
590
- const p = t.morphTargetDictionary[r];
591
- p !== void 0 && (t.morphTargetInfluences[p] = i);
593
+ }), n.current = Array.from(h).sort(), p.current = t;
594
+ }, [a]), z(() => {
595
+ const h = s.current;
596
+ p.current.forEach((t) => {
597
+ !t.morphTargetDictionary || !t.morphTargetInfluences || Object.entries(h).forEach(([e, i]) => {
598
+ const c = t.morphTargetDictionary[e];
599
+ c !== void 0 && (t.morphTargetInfluences[c] = i);
592
600
  });
593
601
  });
594
602
  }), I(() => {
595
- e && (s.current = { ...e });
596
- }, [e]);
597
- const M = C((g, t) => {
598
- s.current[g] = Math.max(0, Math.min(1, t));
599
- }, []), h = C(() => a.current, []), S = C(() => ({ ...s.current }), []);
603
+ o && (s.current = { ...o });
604
+ }, [o]);
605
+ const g = R((h, t) => {
606
+ s.current[h] = Math.max(0, Math.min(1, t));
607
+ }, []), y = R(() => n.current, []), S = R(() => ({ ...s.current }), []);
600
608
  return {
601
- setMorphTarget: M,
602
- getMorphTargetNames: h,
609
+ setMorphTarget: g,
610
+ getMorphTargetNames: y,
603
611
  getMorphTargetValues: S
604
612
  };
605
613
  }
606
614
  const ae = ie(null);
607
615
  function Ae() {
608
- const n = ce(ae);
609
- if (!n)
616
+ const a = ce(ae);
617
+ if (!a)
610
618
  throw new Error("BoneAttachment must be used within an AnimatedModel");
611
- return n;
619
+ return a;
612
620
  }
613
621
  const le = ee(
614
622
  ({
615
- url: n,
616
- position: e = [0, 0, 0],
623
+ url: a,
624
+ position: o = [0, 0, 0],
617
625
  rotation: s = [0, 0, 0],
618
- scale: a = 1,
619
- defaultAnimation: u,
620
- morphTargets: M,
621
- meshVisibility: h,
626
+ scale: n = 1,
627
+ defaultAnimation: p,
628
+ morphTargets: g,
629
+ meshVisibility: y,
622
630
  materialColors: S,
623
- materialTextures: g,
631
+ materialTextures: h,
624
632
  onLoad: t,
625
- onError: r,
633
+ onError: e,
626
634
  children: i
627
- }, p) => {
628
- const y = w(null), o = w([]), l = w(t);
635
+ }, c) => {
636
+ const M = w(null), r = w([]), l = w(t);
629
637
  l.current = t;
630
- const { scene: m, animations: b } = H(n), f = W(() => re.clone(m), [m]), { playAnimation: v, stopAnimation: R, getAnimationNames: d } = xe(
631
- b,
638
+ const { scene: m, animations: $ } = H(a), f = W(() => oe.clone(m), [m]), { playAnimation: v, stopAnimation: C, getAnimationNames: d } = xe(
639
+ $,
632
640
  f,
633
- { defaultAnimation: u }
641
+ { defaultAnimation: p }
634
642
  ), { setMorphTarget: T } = ne(
635
643
  f,
636
- M
637
- ), { setMeshVisibility: j, getMeshNames: c } = G(
644
+ g
645
+ ), { setMeshVisibility: j, getMeshNames: u } = G(
638
646
  f,
639
- h
640
- ), { setMaterialColor: x, getMaterialNames: D, getMaterialColor: $ } = V(
647
+ y
648
+ ), { setMaterialColor: x, getMaterialNames: D, getMaterialColor: b } = V(
641
649
  f,
642
650
  S
643
651
  ), { setMaterialTextures: k, clearMaterialTextures: L } = Y(
644
652
  f,
645
- g
653
+ h
646
654
  );
647
655
  I(() => {
648
656
  if (!f) return;
649
657
  const X = setTimeout(() => {
650
658
  var J;
651
- const O = [], _ = [], F = /* @__PURE__ */ new Set(), Z = /* @__PURE__ */ new Set();
659
+ const O = [], _ = [], U = /* @__PURE__ */ new Set(), Z = /* @__PURE__ */ new Set();
652
660
  let q = 0;
653
661
  f.traverse((K) => {
654
662
  if (q++, K.type === "Bone" && O.push(K.name), K.isMesh) {
655
- const P = K;
656
- _.push(P.name), P.castShadow = !0, P.receiveShadow = !0, (Array.isArray(P.material) ? P.material : [P.material]).forEach((U) => {
657
- F.add(U.name), U.shadowSide = E.DoubleSide;
658
- }), P.morphTargetDictionary && Object.keys(P.morphTargetDictionary).forEach((U) => {
659
- Z.add(U);
663
+ const N = K;
664
+ _.push(N.name), N.castShadow = !0, N.receiveShadow = !0, (Array.isArray(N.material) ? N.material : [N.material]).forEach((F) => {
665
+ U.add(F.name), F.shadowSide = E.DoubleSide;
666
+ }), N.morphTargetDictionary && Object.keys(N.morphTargetDictionary).forEach((F) => {
667
+ Z.add(F);
660
668
  });
661
669
  }
662
- }), o.current = Array.from(Z).sort(), (J = l.current) == null || J.call(l, {
670
+ }), r.current = Array.from(Z).sort(), (J = l.current) == null || J.call(l, {
663
671
  meshes: _.sort(),
664
- materials: Array.from(F).sort(),
672
+ materials: Array.from(U).sort(),
665
673
  bones: O.sort(),
666
674
  nodeCount: q,
667
- animations: b.map((K) => K.name),
668
- morphTargetNames: o.current
675
+ animations: $.map((K) => K.name),
676
+ morphTargetNames: r.current
669
677
  });
670
678
  }, 0);
671
679
  return () => clearTimeout(X);
672
- }, [f, b]), te(p, () => ({
680
+ }, [f, $]), te(c, () => ({
673
681
  playAnimation: v,
674
- stopAnimation: R,
682
+ stopAnimation: C,
675
683
  getAnimationNames: d,
676
- getGroup: () => y.current,
684
+ getGroup: () => M.current,
677
685
  setMorphTarget: T,
678
- getMorphTargetNames: () => o.current,
686
+ getMorphTargetNames: () => r.current,
679
687
  setMeshVisibility: j,
680
- getMeshNames: c,
688
+ getMeshNames: u,
681
689
  setMaterialColor: x,
682
690
  getMaterialNames: D,
683
- getMaterialColor: $,
691
+ getMaterialColor: b,
684
692
  setMaterialTextures: k,
685
693
  clearMaterialTextures: L
686
694
  }));
687
- const N = W(
695
+ const P = W(
688
696
  () => ({
689
697
  scene: f,
690
698
  getBone: (X) => f.getObjectByName(X) || null
691
699
  }),
692
700
  [f]
693
- ), B = typeof a == "number" ? [a, a, a] : a;
694
- return /* @__PURE__ */ A(ae.Provider, { value: N, children: /* @__PURE__ */ se(
701
+ ), B = typeof n == "number" ? [n, n, n] : n;
702
+ return /* @__PURE__ */ A(ae.Provider, { value: P, children: /* @__PURE__ */ se(
695
703
  "group",
696
704
  {
697
- ref: y,
698
- position: e,
705
+ ref: M,
706
+ position: o,
699
707
  rotation: s,
700
708
  scale: B,
701
709
  children: [
@@ -707,128 +715,128 @@ const le = ee(
707
715
  }
708
716
  );
709
717
  le.displayName = "AnimatedModel";
710
- le.preload = (n) => {
711
- H.preload(n);
718
+ le.preload = (a) => {
719
+ H.preload(a);
712
720
  };
713
721
  const we = ee(
714
722
  ({
715
- url: n,
716
- position: e = [0, 0, 0],
723
+ url: a,
724
+ position: o = [0, 0, 0],
717
725
  rotation: s = [0, 0, 0],
718
- scale: a = 1,
719
- morphTargets: u,
720
- meshVisibility: M,
721
- materialColors: h,
726
+ scale: n = 1,
727
+ morphTargets: p,
728
+ meshVisibility: g,
729
+ materialColors: y,
722
730
  materialTextures: S,
723
- onMorphTargetsFound: g,
731
+ onMorphTargetsFound: h,
724
732
  onLoad: t,
725
- onError: r
733
+ onError: e
726
734
  }, i) => {
727
- const { scene: p } = H(n), y = w(t);
728
- y.current = t;
729
- const o = w(g);
730
- o.current = g;
731
- const l = W(() => p.clone(), [p]), { setMorphTarget: m, getMorphTargetNames: b, getMorphTargetValues: f } = ne(
735
+ const { scene: c } = H(a), M = w(t);
736
+ M.current = t;
737
+ const r = w(h);
738
+ r.current = h;
739
+ const l = W(() => c.clone(), [c]), { setMorphTarget: m, getMorphTargetNames: $, getMorphTargetValues: f } = ne(
732
740
  l,
733
- u
734
- ), { setMeshVisibility: v, getMeshNames: R } = G(
741
+ p
742
+ ), { setMeshVisibility: v, getMeshNames: C } = G(
735
743
  l,
736
- M
744
+ g
737
745
  ), { setMaterialColor: d, getMaterialNames: T, getMaterialColor: j } = V(
738
746
  l,
739
- h
740
- ), { setMaterialTextures: c, clearMaterialTextures: x } = Y(
747
+ y
748
+ ), { setMaterialTextures: u, clearMaterialTextures: x } = Y(
741
749
  l,
742
750
  S
743
751
  );
744
752
  return I(() => {
745
753
  var k;
746
- const $ = b();
747
- $.length > 0 && ((k = o.current) == null || k.call(o, $));
748
- }, [l, b]), I(() => {
754
+ const b = $();
755
+ b.length > 0 && ((k = r.current) == null || k.call(r, b));
756
+ }, [l, $]), I(() => {
749
757
  var B;
750
758
  if (!l) return;
751
- const $ = [], k = /* @__PURE__ */ new Set(), L = [];
752
- let N = 0;
759
+ const b = [], k = /* @__PURE__ */ new Set(), L = [];
760
+ let P = 0;
753
761
  l.traverse((X) => {
754
- if (N++, X.type === "Bone" && L.push(X.name), X.isMesh) {
762
+ if (P++, X.type === "Bone" && L.push(X.name), X.isMesh) {
755
763
  const O = X;
756
- $.push(O.name), O.castShadow = !0, O.receiveShadow = !0, (Array.isArray(O.material) ? O.material : [O.material]).forEach((F) => k.add(F.name));
764
+ b.push(O.name), O.castShadow = !0, O.receiveShadow = !0, (Array.isArray(O.material) ? O.material : [O.material]).forEach((U) => k.add(U.name));
757
765
  }
758
- }), (B = y.current) == null || B.call(y, {
759
- meshes: $.sort(),
766
+ }), (B = M.current) == null || B.call(M, {
767
+ meshes: b.sort(),
760
768
  materials: Array.from(k).sort(),
761
769
  bones: L.sort(),
762
- nodeCount: N
770
+ nodeCount: P
763
771
  });
764
772
  }, [l]), te(i, () => ({
765
773
  setMorphTarget: m,
766
- getMorphTargetNames: b,
774
+ getMorphTargetNames: $,
767
775
  getMorphTargetValues: f,
768
776
  setMeshVisibility: v,
769
- getMeshNames: R,
777
+ getMeshNames: C,
770
778
  setMaterialColor: d,
771
779
  getMaterialNames: T,
772
780
  getMaterialColor: j,
773
- setMaterialTextures: c,
781
+ setMaterialTextures: u,
774
782
  clearMaterialTextures: x
775
- })), /* @__PURE__ */ A("group", { position: e, rotation: s, scale: typeof a == "number" ? [a, a, a] : a, children: /* @__PURE__ */ A("primitive", { object: l }) });
783
+ })), /* @__PURE__ */ A("group", { position: o, rotation: s, scale: typeof n == "number" ? [n, n, n] : n, children: /* @__PURE__ */ A("primitive", { object: l }) });
776
784
  }
777
785
  );
778
786
  we.displayName = "MorphableModel";
779
787
  function De({
780
- children: n,
781
- bone: e,
788
+ children: a,
789
+ bone: o,
782
790
  position: s = [0, 0, 0],
783
- rotation: a = [0, 0, 0],
784
- scale: u = 1
791
+ rotation: n = [0, 0, 0],
792
+ scale: p = 1
785
793
  }) {
786
- const { getBone: M } = Ae(), [h, S] = ue(null);
794
+ const { getBone: g } = Ae(), [y, S] = ue(null);
787
795
  return I(() => {
788
- const t = M(e);
789
- t ? S(t) : console.warn(`Bone "${e}" not found in model`);
790
- }, [e, M]), h ? ge(
796
+ const t = g(o);
797
+ t ? S(t) : console.warn(`Bone "${o}" not found in model`);
798
+ }, [o, g]), y ? Me(
791
799
  /* @__PURE__ */ A(
792
800
  "group",
793
801
  {
794
802
  position: s,
795
- rotation: a,
796
- scale: typeof u == "number" ? [u, u, u] : u,
797
- children: n
803
+ rotation: n,
804
+ scale: typeof p == "number" ? [p, p, p] : p,
805
+ children: a
798
806
  }
799
807
  ),
800
- h
808
+ y
801
809
  ) : null;
802
810
  }
803
- function Oe(n, e) {
804
- const { scene: s, animations: a } = H(n), u = W(() => re.clone(s), [s]);
811
+ function Oe(a, o) {
812
+ const { scene: s, animations: n } = H(a), p = W(() => oe.clone(s), [s]);
805
813
  return I(() => {
806
814
  var t;
807
- if (!u) return;
808
- const M = [], h = [], S = /* @__PURE__ */ new Set();
809
- let g = 0;
810
- u.traverse((r) => {
811
- if (g++, r.type === "Bone" && M.push(r.name), r.isMesh) {
812
- const i = r;
813
- h.push(i.name), i.castShadow = !0, i.receiveShadow = !0, (Array.isArray(i.material) ? i.material : [i.material]).forEach((y) => {
814
- S.add(y.name), y.shadowSide = E.DoubleSide;
815
+ if (!p) return;
816
+ const g = [], y = [], S = /* @__PURE__ */ new Set();
817
+ let h = 0;
818
+ p.traverse((e) => {
819
+ if (h++, e.type === "Bone" && g.push(e.name), e.isMesh) {
820
+ const i = e;
821
+ y.push(i.name), i.castShadow = !0, i.receiveShadow = !0, (Array.isArray(i.material) ? i.material : [i.material]).forEach((M) => {
822
+ S.add(M.name), M.shadowSide = E.DoubleSide;
815
823
  });
816
824
  }
817
- }), (t = e == null ? void 0 : e.onLoad) == null || t.call(e, {
818
- meshes: h.sort(),
825
+ }), (t = o == null ? void 0 : o.onLoad) == null || t.call(o, {
826
+ meshes: y.sort(),
819
827
  materials: Array.from(S).sort(),
820
- bones: M.sort(),
821
- nodeCount: g
828
+ bones: g.sort(),
829
+ nodeCount: h
822
830
  });
823
- }, [u, e]), { scene: u, animations: a };
831
+ }, [p, o]), { scene: p, animations: n };
824
832
  }
825
- function Xe(n) {
826
- H.preload(n);
833
+ function Xe(a) {
834
+ H.preload(a);
827
835
  }
828
836
  export {
829
837
  le as AnimatedModel,
830
838
  De as BoneAttachment,
831
- $e as Model,
839
+ be as Model,
832
840
  we as MorphableModel,
833
841
  Le as Scene3D,
834
842
  Xe as preloadModel,