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