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.cjs +1 -1
- package/dist/mbt-3d.cjs.map +1 -1
- package/dist/mbt-3d.js +431 -423
- package/dist/mbt-3d.js.map +1 -1
- package/package.json +1 -1
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
|
|
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
|
|
5
|
-
import { Canvas as
|
|
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:
|
|
10
|
-
controlsConfig:
|
|
9
|
+
position: a,
|
|
10
|
+
controlsConfig: o
|
|
11
11
|
}) {
|
|
12
|
-
const { camera: s } =
|
|
12
|
+
const { camera: s } = re(), n = w(null);
|
|
13
13
|
return I(() => {
|
|
14
|
-
|
|
15
|
-
}, [
|
|
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:
|
|
18
|
+
ref: n,
|
|
19
19
|
makeDefault: !0,
|
|
20
|
-
enabled:
|
|
21
|
-
enablePan:
|
|
22
|
-
enableZoom:
|
|
23
|
-
enableRotate:
|
|
24
|
-
minDistance:
|
|
25
|
-
maxDistance:
|
|
26
|
-
minPolarAngle:
|
|
27
|
-
maxPolarAngle:
|
|
28
|
-
autoRotate:
|
|
29
|
-
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:
|
|
34
|
-
const
|
|
35
|
-
return
|
|
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:
|
|
38
|
-
const
|
|
37
|
+
function Se({ url: a }) {
|
|
38
|
+
const o = fe(a);
|
|
39
39
|
return W(() => {
|
|
40
|
-
|
|
41
|
-
}, [
|
|
40
|
+
o.colorSpace = E.SRGBColorSpace;
|
|
41
|
+
}, [o]), /* @__PURE__ */ A("primitive", { attach: "background", object: o });
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
switch (
|
|
43
|
+
function $e({ config: a }) {
|
|
44
|
+
switch (a.type) {
|
|
45
45
|
case "spot": {
|
|
46
46
|
const {
|
|
47
|
-
position:
|
|
47
|
+
position: o = [5, 10, 5],
|
|
48
48
|
intensity: s = 50,
|
|
49
|
-
castShadow:
|
|
50
|
-
angle:
|
|
51
|
-
penumbra:
|
|
52
|
-
decay:
|
|
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:
|
|
55
|
-
} =
|
|
54
|
+
color: h = "#ffffff"
|
|
55
|
+
} = a;
|
|
56
56
|
return /* @__PURE__ */ A(
|
|
57
57
|
"spotLight",
|
|
58
58
|
{
|
|
59
|
-
position:
|
|
59
|
+
position: o,
|
|
60
60
|
intensity: s,
|
|
61
|
-
castShadow:
|
|
62
|
-
angle:
|
|
63
|
-
penumbra:
|
|
64
|
-
decay:
|
|
61
|
+
castShadow: n,
|
|
62
|
+
angle: p,
|
|
63
|
+
penumbra: g,
|
|
64
|
+
decay: y,
|
|
65
65
|
distance: S,
|
|
66
|
-
color:
|
|
66
|
+
color: h
|
|
67
67
|
}
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
70
|
case "point": {
|
|
71
71
|
const {
|
|
72
|
-
position:
|
|
72
|
+
position: o = [0, 5, 0],
|
|
73
73
|
intensity: s = 20,
|
|
74
|
-
color:
|
|
75
|
-
distance:
|
|
76
|
-
decay:
|
|
77
|
-
castShadow:
|
|
78
|
-
} =
|
|
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:
|
|
82
|
+
position: o,
|
|
83
83
|
intensity: s,
|
|
84
|
-
color:
|
|
85
|
-
distance:
|
|
86
|
-
decay:
|
|
87
|
-
castShadow:
|
|
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:
|
|
93
|
+
position: o = [10, 20, 10],
|
|
94
94
|
intensity: s = 40,
|
|
95
|
-
color:
|
|
96
|
-
castShadow:
|
|
97
|
-
} =
|
|
95
|
+
color: n = "#ffffff",
|
|
96
|
+
castShadow: p = !0
|
|
97
|
+
} = a;
|
|
98
98
|
return /* @__PURE__ */ A(
|
|
99
99
|
"directionalLight",
|
|
100
100
|
{
|
|
101
|
-
position:
|
|
101
|
+
position: o,
|
|
102
102
|
intensity: s,
|
|
103
|
-
color:
|
|
104
|
-
castShadow:
|
|
103
|
+
color: n,
|
|
104
|
+
castShadow: p
|
|
105
105
|
}
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
108
|
case "hemisphere": {
|
|
109
109
|
const {
|
|
110
|
-
skyColor:
|
|
110
|
+
skyColor: o = "#ffffff",
|
|
111
111
|
groundColor: s = "#444444",
|
|
112
|
-
intensity:
|
|
113
|
-
position:
|
|
114
|
-
} =
|
|
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: [
|
|
119
|
-
position:
|
|
118
|
+
args: [g, y, n],
|
|
119
|
+
position: p
|
|
120
120
|
}
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
case "ambient": {
|
|
124
124
|
const {
|
|
125
|
-
intensity:
|
|
125
|
+
intensity: o = 0.5,
|
|
126
126
|
color: s = "#ffffff"
|
|
127
|
-
} =
|
|
127
|
+
} = a;
|
|
128
128
|
return /* @__PURE__ */ A(
|
|
129
129
|
"ambientLight",
|
|
130
130
|
{
|
|
131
|
-
intensity:
|
|
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:
|
|
142
|
-
camera:
|
|
141
|
+
children: a,
|
|
142
|
+
camera: o = {},
|
|
143
143
|
controls: s = {},
|
|
144
|
-
background:
|
|
145
|
-
shadows:
|
|
146
|
-
lights:
|
|
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:
|
|
150
|
+
contactShadows: y = !0,
|
|
151
151
|
style: S,
|
|
152
|
-
className:
|
|
152
|
+
className: h
|
|
153
153
|
}) {
|
|
154
154
|
const t = {
|
|
155
|
-
position:
|
|
156
|
-
fov:
|
|
157
|
-
},
|
|
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
|
|
169
|
-
position:
|
|
170
|
-
opacity:
|
|
171
|
-
blur:
|
|
172
|
-
} :
|
|
173
|
-
return /* @__PURE__ */ A("div", { style: S, className:
|
|
174
|
-
|
|
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:
|
|
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:
|
|
184
|
-
|
|
185
|
-
/* @__PURE__ */ A(Q, { fallback: null, children:
|
|
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:
|
|
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(
|
|
206
|
-
const s = w(/* @__PURE__ */ new Map()),
|
|
205
|
+
function G(a, o) {
|
|
206
|
+
const s = w(/* @__PURE__ */ new Map()), n = w({}), p = w({});
|
|
207
207
|
I(() => {
|
|
208
|
-
|
|
209
|
-
}, [
|
|
210
|
-
if (!
|
|
211
|
-
const
|
|
212
|
-
|
|
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
|
|
215
|
-
|
|
214
|
+
const e = t;
|
|
215
|
+
e.name && h.set(e.name, e);
|
|
216
216
|
}
|
|
217
|
-
}), s.current =
|
|
218
|
-
}, [
|
|
219
|
-
const
|
|
220
|
-
if (
|
|
221
|
-
const t = { ...
|
|
222
|
-
for (const [
|
|
223
|
-
const
|
|
224
|
-
|
|
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
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
}, []),
|
|
232
|
-
const
|
|
233
|
-
return s.current.forEach((t,
|
|
234
|
-
|
|
235
|
-
}),
|
|
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:
|
|
239
|
-
getMeshNames:
|
|
238
|
+
setMeshVisibility: g,
|
|
239
|
+
getMeshNames: y,
|
|
240
240
|
getMeshVisibility: S
|
|
241
241
|
};
|
|
242
242
|
}
|
|
243
|
-
function V(
|
|
244
|
-
const s = 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 (!
|
|
246
|
+
if (!a) return;
|
|
247
247
|
const t = /* @__PURE__ */ new Map();
|
|
248
|
-
|
|
249
|
-
if (
|
|
250
|
-
const i =
|
|
251
|
-
(Array.isArray(i.material) ? i.material : [i.material]).forEach((
|
|
252
|
-
|
|
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,
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
}, [
|
|
263
|
-
|
|
264
|
-
const i = s.current.get(
|
|
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
|
|
267
|
-
|
|
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
|
|
272
|
-
const i =
|
|
273
|
-
|
|
274
|
-
const
|
|
275
|
-
if (
|
|
276
|
-
const
|
|
277
|
-
|
|
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
|
-
}, []),
|
|
280
|
-
const
|
|
281
|
-
if (
|
|
282
|
-
const i =
|
|
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
|
-
}, []),
|
|
295
|
+
}, []), h = R(() => {
|
|
288
296
|
const t = {};
|
|
289
|
-
return s.current.forEach((
|
|
290
|
-
if (!Array.isArray(
|
|
291
|
-
const
|
|
292
|
-
|
|
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:
|
|
298
|
-
getMaterialNames:
|
|
305
|
+
setMaterialColor: g,
|
|
306
|
+
getMaterialNames: y,
|
|
299
307
|
getMaterialColor: S,
|
|
300
|
-
getAllMaterialColors:
|
|
308
|
+
getAllMaterialColors: h
|
|
301
309
|
};
|
|
302
310
|
}
|
|
303
|
-
function Y(
|
|
304
|
-
const { gl: s } =
|
|
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 (!
|
|
314
|
+
if (!g.current)
|
|
307
315
|
try {
|
|
308
|
-
const
|
|
309
|
-
console.log("[useMaterialTexture] Browser features:"), console.log(` WebAssembly supported: ${
|
|
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),
|
|
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
|
-
}),
|
|
316
|
-
} catch (
|
|
317
|
-
console.error("[useMaterialTexture] ❌ Failed to initialize KTX2Loader:",
|
|
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
|
-
|
|
328
|
+
g.current && (g.current.dispose(), g.current = null);
|
|
321
329
|
};
|
|
322
330
|
}, [s]), I(() => {
|
|
323
|
-
if (!
|
|
324
|
-
const
|
|
325
|
-
|
|
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 && !
|
|
337
|
+
f.name && !r.has(f.name) && r.set(f.name, f);
|
|
330
338
|
});
|
|
331
339
|
}
|
|
332
|
-
}),
|
|
333
|
-
}, [
|
|
334
|
-
const t =
|
|
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 (!
|
|
337
|
-
const
|
|
338
|
-
if (
|
|
339
|
-
const l = JSON.stringify(
|
|
340
|
-
if (
|
|
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
|
-
|
|
352
|
+
h.current = l;
|
|
345
353
|
let m = !1;
|
|
346
|
-
const
|
|
347
|
-
Object.entries(
|
|
348
|
-
|
|
349
|
-
}), console.log("[useMaterialTexture] Starting texture load for",
|
|
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
|
-
|
|
359
|
+
$.forEach((d, T) => {
|
|
352
360
|
var x, D;
|
|
353
|
-
const j =
|
|
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
|
|
359
|
-
console.log(`[useMaterialTexture] 📋 Material "${T}" BEFORE reset:`), console.log(` - map: ${
|
|
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}_${
|
|
362
|
-
if (
|
|
363
|
-
console.log(`[useMaterialTexture] Using cached texture: ${T}.${
|
|
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:
|
|
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
|
|
382
|
+
const C = () => {
|
|
375
383
|
if (m || v >= f.length) {
|
|
376
|
-
console.log("[useMaterialTexture] ✅ All textures loaded"), console.log("[useMaterialTexture] 📊 FINAL material states:"),
|
|
384
|
+
console.log("[useMaterialTexture] ✅ All textures loaded"), console.log("[useMaterialTexture] 📊 FINAL material states:"), r.forEach((x, D) => {
|
|
377
385
|
var k, L;
|
|
378
|
-
const
|
|
379
|
-
console.log(` Material "${D}":`), console.log(` - map: ${
|
|
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),
|
|
386
|
-
console.log(`[useMaterialTexture] Using ${
|
|
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,
|
|
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 = (
|
|
395
|
-
console.log(`[useMaterialTexture] ✅ Loaded: ${d.materialName}.${d.textureType} (${D}x${
|
|
396
|
-
const k = d.url.endsWith(".ktx2") ? 500 :
|
|
397
|
-
console.log(`[useMaterialTexture] Waiting111111 ${k}ms before next texture...`), setTimeout(
|
|
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:",
|
|
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
|
|
418
|
+
return C(), () => {
|
|
411
419
|
console.log("[useMaterialTexture] Cleanup: disposed"), m = !0;
|
|
412
420
|
};
|
|
413
|
-
}, [
|
|
414
|
-
const
|
|
415
|
-
var
|
|
416
|
-
switch (console.log(`[useMaterialTexture] 🎨 Applying texture: ${
|
|
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
|
-
|
|
426
|
+
r.map = m;
|
|
419
427
|
break;
|
|
420
428
|
case "normalMap":
|
|
421
|
-
|
|
429
|
+
r.normalMap = m;
|
|
422
430
|
break;
|
|
423
431
|
case "roughnessMap":
|
|
424
|
-
|
|
432
|
+
r.roughnessMap = m;
|
|
425
433
|
break;
|
|
426
434
|
case "metalnessMap":
|
|
427
|
-
|
|
435
|
+
r.metalnessMap = m;
|
|
428
436
|
break;
|
|
429
437
|
case "emissiveMap":
|
|
430
|
-
|
|
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 "${
|
|
441
|
+
console.log(`[useMaterialTexture] Skipping alphaMap for "${r.name}" to prevent disappearing`);
|
|
434
442
|
break;
|
|
435
443
|
case "aoMap":
|
|
436
|
-
|
|
444
|
+
r.aoMap = m;
|
|
437
445
|
break;
|
|
438
446
|
}
|
|
439
|
-
|
|
440
|
-
}, i =
|
|
441
|
-
const m = typeof l == "string" ? { map: l } : l,
|
|
442
|
-
if (
|
|
443
|
-
console.warn(`Material "${
|
|
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 =
|
|
447
|
-
Object.entries(m).forEach(([v,
|
|
448
|
-
if (!
|
|
449
|
-
const 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
|
-
|
|
459
|
+
e(f, v, T);
|
|
452
460
|
return;
|
|
453
461
|
}
|
|
454
|
-
t(
|
|
455
|
-
|
|
456
|
-
(
|
|
457
|
-
|
|
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
|
-
(
|
|
461
|
-
console.error(`Failed to load texture ${
|
|
468
|
+
(u) => {
|
|
469
|
+
console.error(`Failed to load texture ${C}:`, u);
|
|
462
470
|
}
|
|
463
471
|
);
|
|
464
472
|
});
|
|
465
|
-
}, [t]),
|
|
466
|
-
const l =
|
|
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:
|
|
474
|
-
clearMaterialTextures:
|
|
481
|
+
getMaterialNames: c,
|
|
482
|
+
clearMaterialTextures: M
|
|
475
483
|
};
|
|
476
484
|
}
|
|
477
|
-
function
|
|
478
|
-
url:
|
|
479
|
-
position:
|
|
485
|
+
function be({
|
|
486
|
+
url: a,
|
|
487
|
+
position: o = [0, 0, 0],
|
|
480
488
|
rotation: s = [0, 0, 0],
|
|
481
|
-
scale:
|
|
482
|
-
meshVisibility:
|
|
483
|
-
materialColors:
|
|
484
|
-
materialTextures:
|
|
489
|
+
scale: n = 1,
|
|
490
|
+
meshVisibility: p,
|
|
491
|
+
materialColors: g,
|
|
492
|
+
materialTextures: y,
|
|
485
493
|
onLoad: S,
|
|
486
|
-
onError:
|
|
494
|
+
onError: h
|
|
487
495
|
}) {
|
|
488
|
-
const { scene: t } = H(
|
|
489
|
-
|
|
496
|
+
const { scene: t } = H(a), e = w(S);
|
|
497
|
+
e.current = S;
|
|
490
498
|
const i = W(() => {
|
|
491
|
-
const
|
|
499
|
+
const M = t.clone();
|
|
492
500
|
console.log("[Model] 🔍 Scene clone created, checking materials...");
|
|
493
|
-
const
|
|
494
|
-
let
|
|
495
|
-
return
|
|
496
|
-
if (
|
|
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
|
-
|
|
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: ${
|
|
512
|
+
}), console.log(`[Model] 📊 Clone summary: ${r.length} meshes, ${l.size} materials`), setTimeout(() => {
|
|
505
513
|
var f;
|
|
506
|
-
(f =
|
|
507
|
-
meshes:
|
|
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:
|
|
518
|
+
nodeCount: $
|
|
511
519
|
});
|
|
512
|
-
}, 0),
|
|
520
|
+
}, 0), M;
|
|
513
521
|
}, [t]);
|
|
514
|
-
return G(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
|
-
|
|
517
|
-
H.preload(
|
|
524
|
+
be.preload = (a) => {
|
|
525
|
+
H.preload(a);
|
|
518
526
|
};
|
|
519
|
-
function xe(
|
|
520
|
-
const { actions:
|
|
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 (
|
|
523
|
-
const
|
|
524
|
-
let i =
|
|
525
|
-
if (
|
|
526
|
-
const
|
|
527
|
-
|
|
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
|
|
530
|
-
|
|
531
|
-
}, [
|
|
532
|
-
const S =
|
|
533
|
-
(
|
|
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:
|
|
536
|
-
crossFadeDuration:
|
|
537
|
-
restoreDefault:
|
|
543
|
+
loop: c = !1,
|
|
544
|
+
crossFadeDuration: M = 0.2,
|
|
545
|
+
restoreDefault: r = !0
|
|
538
546
|
} = i || {};
|
|
539
|
-
let l =
|
|
547
|
+
let l = n[e];
|
|
540
548
|
if (!l) {
|
|
541
|
-
const
|
|
542
|
-
(f) => f.toLowerCase().includes(
|
|
549
|
+
const $ = Object.keys(n).find(
|
|
550
|
+
(f) => f.toLowerCase().includes(e.toLowerCase()) || e.toLowerCase().includes(f.toLowerCase())
|
|
543
551
|
);
|
|
544
|
-
|
|
552
|
+
$ && (l = n[$]);
|
|
545
553
|
}
|
|
546
554
|
if (!l) {
|
|
547
|
-
console.warn(`Animation "${
|
|
555
|
+
console.warn(`Animation "${e}" not found. Available: ${p.join(", ")}`);
|
|
548
556
|
return;
|
|
549
557
|
}
|
|
550
|
-
const m =
|
|
551
|
-
if (!(m === l && l.isRunning()) && (m && m !== l && m.fadeOut(
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
), l.clampWhenFinished = !
|
|
555
|
-
const
|
|
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
|
-
|
|
558
|
-
const
|
|
559
|
-
|
|
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
|
-
|
|
570
|
+
$.addEventListener("finished", f);
|
|
563
571
|
}
|
|
564
572
|
},
|
|
565
|
-
[
|
|
566
|
-
),
|
|
567
|
-
var
|
|
568
|
-
(
|
|
569
|
-
}, []), t =
|
|
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:
|
|
580
|
+
stopAnimation: h,
|
|
573
581
|
getAnimationNames: t,
|
|
574
|
-
actions:
|
|
582
|
+
actions: n
|
|
575
583
|
};
|
|
576
584
|
}
|
|
577
|
-
function ne(
|
|
578
|
-
const s = w(
|
|
585
|
+
function ne(a, o) {
|
|
586
|
+
const s = w(o || {}), n = w([]), p = w([]);
|
|
579
587
|
I(() => {
|
|
580
|
-
const
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
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
|
-
}),
|
|
586
|
-
}, [
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
!t.morphTargetDictionary || !t.morphTargetInfluences || Object.entries(
|
|
590
|
-
const
|
|
591
|
-
|
|
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
|
-
|
|
596
|
-
}, [
|
|
597
|
-
const
|
|
598
|
-
s.current[
|
|
599
|
-
}, []),
|
|
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:
|
|
602
|
-
getMorphTargetNames:
|
|
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
|
|
609
|
-
if (!
|
|
616
|
+
const a = ce(ae);
|
|
617
|
+
if (!a)
|
|
610
618
|
throw new Error("BoneAttachment must be used within an AnimatedModel");
|
|
611
|
-
return
|
|
619
|
+
return a;
|
|
612
620
|
}
|
|
613
621
|
const le = ee(
|
|
614
622
|
({
|
|
615
|
-
url:
|
|
616
|
-
position:
|
|
623
|
+
url: a,
|
|
624
|
+
position: o = [0, 0, 0],
|
|
617
625
|
rotation: s = [0, 0, 0],
|
|
618
|
-
scale:
|
|
619
|
-
defaultAnimation:
|
|
620
|
-
morphTargets:
|
|
621
|
-
meshVisibility:
|
|
626
|
+
scale: n = 1,
|
|
627
|
+
defaultAnimation: p,
|
|
628
|
+
morphTargets: g,
|
|
629
|
+
meshVisibility: y,
|
|
622
630
|
materialColors: S,
|
|
623
|
-
materialTextures:
|
|
631
|
+
materialTextures: h,
|
|
624
632
|
onLoad: t,
|
|
625
|
-
onError:
|
|
633
|
+
onError: e,
|
|
626
634
|
children: i
|
|
627
|
-
},
|
|
628
|
-
const
|
|
635
|
+
}, c) => {
|
|
636
|
+
const M = w(null), r = w([]), l = w(t);
|
|
629
637
|
l.current = t;
|
|
630
|
-
const { scene: m, animations:
|
|
631
|
-
|
|
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:
|
|
641
|
+
{ defaultAnimation: p }
|
|
634
642
|
), { setMorphTarget: T } = ne(
|
|
635
643
|
f,
|
|
636
|
-
|
|
637
|
-
), { setMeshVisibility: j, getMeshNames:
|
|
644
|
+
g
|
|
645
|
+
), { setMeshVisibility: j, getMeshNames: u } = G(
|
|
638
646
|
f,
|
|
639
|
-
|
|
640
|
-
), { setMaterialColor: x, getMaterialNames: D, getMaterialColor:
|
|
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
|
-
|
|
653
|
+
h
|
|
646
654
|
);
|
|
647
655
|
I(() => {
|
|
648
656
|
if (!f) return;
|
|
649
657
|
const X = setTimeout(() => {
|
|
650
658
|
var J;
|
|
651
|
-
const O = [], _ = [],
|
|
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
|
|
656
|
-
_.push(
|
|
657
|
-
|
|
658
|
-
}),
|
|
659
|
-
Z.add(
|
|
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
|
-
}),
|
|
670
|
+
}), r.current = Array.from(Z).sort(), (J = l.current) == null || J.call(l, {
|
|
663
671
|
meshes: _.sort(),
|
|
664
|
-
materials: Array.from(
|
|
672
|
+
materials: Array.from(U).sort(),
|
|
665
673
|
bones: O.sort(),
|
|
666
674
|
nodeCount: q,
|
|
667
|
-
animations:
|
|
668
|
-
morphTargetNames:
|
|
675
|
+
animations: $.map((K) => K.name),
|
|
676
|
+
morphTargetNames: r.current
|
|
669
677
|
});
|
|
670
678
|
}, 0);
|
|
671
679
|
return () => clearTimeout(X);
|
|
672
|
-
}, [f,
|
|
680
|
+
}, [f, $]), te(c, () => ({
|
|
673
681
|
playAnimation: v,
|
|
674
|
-
stopAnimation:
|
|
682
|
+
stopAnimation: C,
|
|
675
683
|
getAnimationNames: d,
|
|
676
|
-
getGroup: () =>
|
|
684
|
+
getGroup: () => M.current,
|
|
677
685
|
setMorphTarget: T,
|
|
678
|
-
getMorphTargetNames: () =>
|
|
686
|
+
getMorphTargetNames: () => r.current,
|
|
679
687
|
setMeshVisibility: j,
|
|
680
|
-
getMeshNames:
|
|
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
|
|
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
|
|
694
|
-
return /* @__PURE__ */ A(ae.Provider, { value:
|
|
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:
|
|
698
|
-
position:
|
|
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 = (
|
|
711
|
-
H.preload(
|
|
718
|
+
le.preload = (a) => {
|
|
719
|
+
H.preload(a);
|
|
712
720
|
};
|
|
713
721
|
const we = ee(
|
|
714
722
|
({
|
|
715
|
-
url:
|
|
716
|
-
position:
|
|
723
|
+
url: a,
|
|
724
|
+
position: o = [0, 0, 0],
|
|
717
725
|
rotation: s = [0, 0, 0],
|
|
718
|
-
scale:
|
|
719
|
-
morphTargets:
|
|
720
|
-
meshVisibility:
|
|
721
|
-
materialColors:
|
|
726
|
+
scale: n = 1,
|
|
727
|
+
morphTargets: p,
|
|
728
|
+
meshVisibility: g,
|
|
729
|
+
materialColors: y,
|
|
722
730
|
materialTextures: S,
|
|
723
|
-
onMorphTargetsFound:
|
|
731
|
+
onMorphTargetsFound: h,
|
|
724
732
|
onLoad: t,
|
|
725
|
-
onError:
|
|
733
|
+
onError: e
|
|
726
734
|
}, i) => {
|
|
727
|
-
const { scene:
|
|
728
|
-
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
const l = W(() =>
|
|
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
|
-
|
|
734
|
-
), { setMeshVisibility: v, getMeshNames:
|
|
741
|
+
p
|
|
742
|
+
), { setMeshVisibility: v, getMeshNames: C } = G(
|
|
735
743
|
l,
|
|
736
|
-
|
|
744
|
+
g
|
|
737
745
|
), { setMaterialColor: d, getMaterialNames: T, getMaterialColor: j } = V(
|
|
738
746
|
l,
|
|
739
|
-
|
|
740
|
-
), { setMaterialTextures:
|
|
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
|
|
747
|
-
|
|
748
|
-
}, [l,
|
|
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
|
|
752
|
-
let
|
|
759
|
+
const b = [], k = /* @__PURE__ */ new Set(), L = [];
|
|
760
|
+
let P = 0;
|
|
753
761
|
l.traverse((X) => {
|
|
754
|
-
if (
|
|
762
|
+
if (P++, X.type === "Bone" && L.push(X.name), X.isMesh) {
|
|
755
763
|
const O = X;
|
|
756
|
-
|
|
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 =
|
|
759
|
-
meshes:
|
|
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:
|
|
770
|
+
nodeCount: P
|
|
763
771
|
});
|
|
764
772
|
}, [l]), te(i, () => ({
|
|
765
773
|
setMorphTarget: m,
|
|
766
|
-
getMorphTargetNames:
|
|
774
|
+
getMorphTargetNames: $,
|
|
767
775
|
getMorphTargetValues: f,
|
|
768
776
|
setMeshVisibility: v,
|
|
769
|
-
getMeshNames:
|
|
777
|
+
getMeshNames: C,
|
|
770
778
|
setMaterialColor: d,
|
|
771
779
|
getMaterialNames: T,
|
|
772
780
|
getMaterialColor: j,
|
|
773
|
-
setMaterialTextures:
|
|
781
|
+
setMaterialTextures: u,
|
|
774
782
|
clearMaterialTextures: x
|
|
775
|
-
})), /* @__PURE__ */ A("group", { position:
|
|
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:
|
|
781
|
-
bone:
|
|
788
|
+
children: a,
|
|
789
|
+
bone: o,
|
|
782
790
|
position: s = [0, 0, 0],
|
|
783
|
-
rotation:
|
|
784
|
-
scale:
|
|
791
|
+
rotation: n = [0, 0, 0],
|
|
792
|
+
scale: p = 1
|
|
785
793
|
}) {
|
|
786
|
-
const { getBone:
|
|
794
|
+
const { getBone: g } = Ae(), [y, S] = ue(null);
|
|
787
795
|
return I(() => {
|
|
788
|
-
const t =
|
|
789
|
-
t ? S(t) : console.warn(`Bone "${
|
|
790
|
-
}, [
|
|
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:
|
|
796
|
-
scale: typeof
|
|
797
|
-
children:
|
|
803
|
+
rotation: n,
|
|
804
|
+
scale: typeof p == "number" ? [p, p, p] : p,
|
|
805
|
+
children: a
|
|
798
806
|
}
|
|
799
807
|
),
|
|
800
|
-
|
|
808
|
+
y
|
|
801
809
|
) : null;
|
|
802
810
|
}
|
|
803
|
-
function Oe(
|
|
804
|
-
const { scene: s, animations:
|
|
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 (!
|
|
808
|
-
const
|
|
809
|
-
let
|
|
810
|
-
|
|
811
|
-
if (
|
|
812
|
-
const i =
|
|
813
|
-
|
|
814
|
-
S.add(
|
|
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 =
|
|
818
|
-
meshes:
|
|
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:
|
|
821
|
-
nodeCount:
|
|
828
|
+
bones: g.sort(),
|
|
829
|
+
nodeCount: h
|
|
822
830
|
});
|
|
823
|
-
}, [
|
|
831
|
+
}, [p, o]), { scene: p, animations: n };
|
|
824
832
|
}
|
|
825
|
-
function Xe(
|
|
826
|
-
H.preload(
|
|
833
|
+
function Xe(a) {
|
|
834
|
+
H.preload(a);
|
|
827
835
|
}
|
|
828
836
|
export {
|
|
829
837
|
le as AnimatedModel,
|
|
830
838
|
De as BoneAttachment,
|
|
831
|
-
|
|
839
|
+
be as Model,
|
|
832
840
|
we as MorphableModel,
|
|
833
841
|
Le as Scene3D,
|
|
834
842
|
Xe as preloadModel,
|