mbt-3d 0.3.6 → 0.3.7

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