@nebula-spatial/viewer 0.5.7 → 0.5.9
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/CHANGELOG.md +54 -0
- package/README.md +59 -2
- package/USD-VISUAL-MATERIAL-SUPPORT.md +52 -4
- package/dist/assets/types.d.ts +2 -0
- package/dist/assets/{usd-worker-B-HuMXLo.js → usd-worker-B9O1idq-.js} +196 -193
- package/dist/collision-debug-FutuxXPm.js +2896 -0
- package/dist/{index-BTAC6njT.js → index-BQn4yVNd.js} +4575 -3421
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{mjcf-visual-BVT3h87h.js → mjcf-visual-BxcQ3hIg.js} +1 -1
- package/dist/{mujoco-runtime-CAyK0LHM.js → mujoco-runtime-DNqHIXvQ.js} +1 -1
- package/dist/session-9j-PNz4O.js +2519 -0
- package/dist/{session-BQ8eCFRL.js → session-S3ZuhqY8.js} +186 -186
- package/dist/{stage-DUC-YNhD.js → stage-Ck2xORK4.js} +22 -15
- package/dist/types.d.ts +46 -3
- package/dist/ui/types.d.ts +2 -0
- package/dist/urdf-session-DJs9oT_G.js +1264 -0
- package/dist/usd-session-BEjswMmU.js +7461 -0
- package/dist/version.d.ts +1 -1
- package/dist/{xacro-F7rdDouN.js → xacro-CFFshEJJ.js} +1 -1
- package/package.json +1 -1
- package/dist/collision-debug-B2CISPB9.js +0 -792
- package/dist/session-Dwoi1H46.js +0 -965
- package/dist/urdf-session-E0Nnr4Vs.js +0 -3266
- package/dist/usd-session-BUD3KtCr.js +0 -6875
|
@@ -0,0 +1,2519 @@
|
|
|
1
|
+
import { DataTexture as ne, LinearMipmapLinearFilter as ke, LinearFilter as Xe, Loader as J, LoaderUtils as _e, FileLoader as Ve, TextureLoader as Me, RepeatWrapping as ue, ClampToEdgeWrapping as pe, Texture as Y, MeshPhongMaterial as W, MeshLambertMaterial as Se, ColorManagement as N, Color as k, SRGBColorSpace as X, EquirectangularReflectionMapping as Ge, Matrix4 as L, Group as ce, Bone as fe, PropertyBinding as ee, Object3D as Z, PerspectiveCamera as Ne, PointLight as he, MathUtils as B, SpotLight as $e, DirectionalLight as ze, SkinnedMesh as je, Mesh as Fe, LineBasicMaterial as He, Line as We, Vector3 as V, Skeleton as Ye, AmbientLight as qe, BufferGeometry as re, Float32BufferAttribute as j, Uint16BufferAttribute as Ke, Matrix3 as Ze, Vector2 as Qe, ShapeUtils as Je, Vector4 as et, Euler as z, AnimationClip as tt, Quaternion as G, VectorKeyframeTrack as nt, QuaternionKeyframeTrack as de, NumberKeyframeTrack as rt, LoadingManager as st, LinearSRGBColorSpace as me, RGBAFormat as Ie, UnsignedByteType as Ae, NoColorSpace as at, MeshPhysicalMaterial as De, Box3 as ot } from "three";
|
|
2
|
+
import { DRACOLoader as it } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
3
|
+
import { GLTFLoader as lt } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
4
|
+
import { D as ct } from "./index-BQn4yVNd.js";
|
|
5
|
+
import { d as ge, a as ye, S as ut } from "./stage-Ck2xORK4.js";
|
|
6
|
+
import { TGALoader as pt } from "three/examples/jsm/loaders/TGALoader.js";
|
|
7
|
+
import * as ft from "three/examples/jsm/libs/fflate.module.js";
|
|
8
|
+
import { unzlibSync as ht } from "three/examples/jsm/libs/fflate.module.js";
|
|
9
|
+
import { NURBSCurve as dt } from "three/examples/jsm/curves/NURBSCurve.js";
|
|
10
|
+
import { disposeModelResources as we } from "./resources-CHhCm2f7.js";
|
|
11
|
+
const mt = 16 * 1024 * 1024;
|
|
12
|
+
function Re(i, e) {
|
|
13
|
+
if (!i || !e || i * e > mt) throw new Error("Invalid or oversized image dimensions (maximum 16M pixels).");
|
|
14
|
+
}
|
|
15
|
+
function $(i, e, t) {
|
|
16
|
+
if (e < 0 || t < 0 || e + t > i.length) throw new Error("Truncated image payload.");
|
|
17
|
+
}
|
|
18
|
+
function gt(i) {
|
|
19
|
+
const e = new Uint8Array(i);
|
|
20
|
+
$(e, 0, 18);
|
|
21
|
+
const t = new DataView(i), n = e[2], r = e[16], s = t.getUint16(12, !0), a = t.getUint16(14, !0);
|
|
22
|
+
if (Re(s, a), e[1] !== 0 || ![2, 3, 10, 11].includes(n) || !([3, 11].includes(n) ? [8, 16] : [24, 32]).includes(r) || e[17] & 192)
|
|
23
|
+
throw new Error("Unsupported TGA: require non-interleaved 24/32-bit true-color or 8/16-bit grayscale.");
|
|
24
|
+
let o = 18 + e[0];
|
|
25
|
+
$(e, 18, e[0]);
|
|
26
|
+
const l = r / 8, p = s * a;
|
|
27
|
+
if (n === 2 || n === 3) $(e, o, p * l);
|
|
28
|
+
else {
|
|
29
|
+
let u = 0;
|
|
30
|
+
for (; u < p; ) {
|
|
31
|
+
$(e, o, 1);
|
|
32
|
+
const c = e[o++], h = (c & 127) + 1;
|
|
33
|
+
if (u + h > p) throw new Error("Invalid TGA RLE packet length.");
|
|
34
|
+
const m = (c & 128 ? 1 : h) * l;
|
|
35
|
+
$(e, o, m), o += m, u += h;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { data: new pt().parse(i).data, width: s, height: a };
|
|
39
|
+
}
|
|
40
|
+
function ve(i) {
|
|
41
|
+
const e = i >>> 11 & 31, t = i >>> 5 & 63, n = i & 31;
|
|
42
|
+
return [e << 3 | e >>> 2, t << 2 | t >>> 4, n << 3 | n >>> 2, 255];
|
|
43
|
+
}
|
|
44
|
+
function yt(i) {
|
|
45
|
+
const e = new Uint8Array(i);
|
|
46
|
+
$(e, 0, 128);
|
|
47
|
+
const t = new DataView(i), n = (h) => t.getUint32(h, !0);
|
|
48
|
+
if (n(0) !== 542327876 || n(4) !== 124 || n(76) !== 32) throw new Error("Invalid DDS header.");
|
|
49
|
+
const r = n(16), s = n(12);
|
|
50
|
+
if (Re(r, s), n(112) & 2162176 || n(24) > 1) throw new Error("DDS cubemap/volume textures are unsupported.");
|
|
51
|
+
const a = n(80), o = String.fromCharCode(...e.subarray(84, 88)), l = (a & 4) !== 0;
|
|
52
|
+
if (l && !["DXT1", "DXT3", "DXT5"].includes(o)) throw new Error(`Unsupported DDS FourCC: ${o}. Require DXT1/DXT3/DXT5.`);
|
|
53
|
+
const p = new Uint8Array(r * s * 4);
|
|
54
|
+
if (!l) {
|
|
55
|
+
const h = n(88), m = n(92), g = n(96), d = n(100), T = n(104);
|
|
56
|
+
if (!(a & 64) || ![24, 32].includes(h) || g !== 65280 || !(m === 16711680 && d === 255 || m === 255 && d === 16711680) || (h === 24 ? T !== 0 : T !== 0 && T !== 4278190080)) throw new Error("Unsupported DDS RGB bit masks.");
|
|
57
|
+
const F = h / 8, y = n(8) & 8 ? n(20) : r * F;
|
|
58
|
+
if (y < r * F) throw new Error("Invalid DDS row pitch.");
|
|
59
|
+
$(e, 128, y * s);
|
|
60
|
+
for (let x = 0; x < s; x++) for (let I = 0; I < r; I++) {
|
|
61
|
+
const A = 128 + x * y + I * F, M = (x * r + I) * 4;
|
|
62
|
+
p[M] = e[A + (m === 255 ? 0 : 2)], p[M + 1] = e[A + 1], p[M + 2] = e[A + (d === 255 ? 0 : 2)], p[M + 3] = T && a & 1 ? e[A + 3] : 255;
|
|
63
|
+
}
|
|
64
|
+
return { data: p, width: r, height: s };
|
|
65
|
+
}
|
|
66
|
+
const f = o === "DXT1" ? 8 : 16, u = Math.ceil(r / 4), c = Math.ceil(s / 4);
|
|
67
|
+
$(e, 128, u * c * f);
|
|
68
|
+
for (let h = 0; h < c; h++) for (let m = 0; m < u; m++) {
|
|
69
|
+
const g = 128 + (h * u + m) * f, d = g + (f === 8 ? 0 : 8), T = t.getUint16(d, !0), F = t.getUint16(d + 2, !0), y = [ve(T), ve(F)], x = o !== "DXT1" || T > F;
|
|
70
|
+
y.push([0, 1, 2].map((M) => Math.floor(x ? (2 * y[0][M] + y[1][M]) / 3 : (y[0][M] + y[1][M]) / 2)).concat(255)), y.push(x ? [0, 1, 2].map((M) => Math.floor((y[0][M] + 2 * y[1][M]) / 3)).concat(255) : [0, 0, 0, 0]);
|
|
71
|
+
const I = n(d + 4), A = [e[g], e[g + 1]];
|
|
72
|
+
if (o === "DXT5") {
|
|
73
|
+
const M = A[0] > A[1] ? 6 : 4;
|
|
74
|
+
for (let v = 1; v <= M; v++) A.push(Math.floor(((M + 1 - v) * A[0] + v * A[1]) / (M + 1)));
|
|
75
|
+
M === 4 && A.push(0, 255);
|
|
76
|
+
}
|
|
77
|
+
for (let M = 0; M < 16; M++) {
|
|
78
|
+
const v = m * 4 + M % 4, S = h * 4 + Math.floor(M / 4);
|
|
79
|
+
if (v >= r || S >= s) continue;
|
|
80
|
+
const E = y[I >>> 2 * M & 3], b = (S * r + v) * 4;
|
|
81
|
+
if (p.set(E, b), o === "DXT3" && (p[b + 3] = (e[g + Math.floor(M / 2)] >>> M % 2 * 4 & 15) * 17), o === "DXT5") {
|
|
82
|
+
const D = M * 3, w = g + 2 + Math.floor(D / 8), R = e[w] | (w + 1 < g + 8 ? e[w + 1] : 0) << 8;
|
|
83
|
+
p[b + 3] = A[R >>> D % 8 & 7];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { data: p, width: r, height: s };
|
|
88
|
+
}
|
|
89
|
+
function wt(i, e) {
|
|
90
|
+
const t = e === "tga" ? gt(i) : yt(i), n = new Uint8Array(t.data.length), r = t.width * 4;
|
|
91
|
+
for (let a = 0; a < t.height; a++) n.set(t.data.subarray(a * r, (a + 1) * r), (t.height - 1 - a) * r);
|
|
92
|
+
const s = new ne(n, t.width, t.height);
|
|
93
|
+
return s.flipY = !1, s.generateMipmaps = !0, s.minFilter = ke, s.magFilter = Xe, s.needsUpdate = !0, s;
|
|
94
|
+
}
|
|
95
|
+
let C, O, U;
|
|
96
|
+
class vt extends J {
|
|
97
|
+
/**
|
|
98
|
+
* Constructs a new FBX loader.
|
|
99
|
+
*
|
|
100
|
+
* @param {LoadingManager} [manager] - The loading manager.
|
|
101
|
+
*/
|
|
102
|
+
constructor(e) {
|
|
103
|
+
super(e);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Starts loading from the given URL and passes the loaded FBX asset
|
|
107
|
+
* to the `onLoad()` callback.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
|
|
110
|
+
* @param {function(Group)} onLoad - Executed when the loading process has been finished.
|
|
111
|
+
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
|
|
112
|
+
* @param {onErrorCallback} onError - Executed when errors occur.
|
|
113
|
+
*/
|
|
114
|
+
load(e, t, n, r) {
|
|
115
|
+
const s = this, a = s.path === "" ? _e.extractUrlBase(e) : s.path, o = new Ve(this.manager);
|
|
116
|
+
o.setPath(s.path), o.setResponseType("arraybuffer"), o.setRequestHeader(s.requestHeader), o.setWithCredentials(s.withCredentials), o.load(e, function(l) {
|
|
117
|
+
try {
|
|
118
|
+
t(s.parse(l, a));
|
|
119
|
+
} catch (p) {
|
|
120
|
+
r ? r(p) : console.error(p), s.manager.itemError(e);
|
|
121
|
+
}
|
|
122
|
+
}, n, r);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Parses the given FBX data and returns the resulting group.
|
|
126
|
+
*
|
|
127
|
+
* @param {ArrayBuffer} FBXBuffer - The raw FBX data as an array buffer.
|
|
128
|
+
* @param {string} path - The URL base path.
|
|
129
|
+
* @return {Group} An object representing the parsed asset.
|
|
130
|
+
*/
|
|
131
|
+
parse(e, t) {
|
|
132
|
+
if (St(e))
|
|
133
|
+
C = new Mt().parse(e);
|
|
134
|
+
else {
|
|
135
|
+
const r = Le(e);
|
|
136
|
+
if (!Ft(r))
|
|
137
|
+
throw new Error("THREE.FBXLoader: Unknown format.");
|
|
138
|
+
if (xe(r) < 7e3)
|
|
139
|
+
throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: " + xe(r));
|
|
140
|
+
C = new bt().parse(r);
|
|
141
|
+
}
|
|
142
|
+
const n = new Me(this.manager).setPath(this.resourcePath || t).setCrossOrigin(this.crossOrigin);
|
|
143
|
+
return new Tt(n, this.manager).parse(C);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
class Tt {
|
|
147
|
+
constructor(e, t) {
|
|
148
|
+
this.textureLoader = e, this.manager = t;
|
|
149
|
+
}
|
|
150
|
+
parse() {
|
|
151
|
+
O = this.parseConnections();
|
|
152
|
+
const e = this.parseImages(), t = this.parseTextures(e), n = this.parseMaterials(t), r = this.parseDeformers(), s = new xt().parse(r);
|
|
153
|
+
return this.parseScene(r, s, n), U;
|
|
154
|
+
}
|
|
155
|
+
// Parses FBXTree.Connections which holds parent-child connections between objects (e.g. material -> texture, model->geometry )
|
|
156
|
+
// and details the connection type
|
|
157
|
+
parseConnections() {
|
|
158
|
+
const e = /* @__PURE__ */ new Map();
|
|
159
|
+
return "Connections" in C && C.Connections.connections.forEach(function(n) {
|
|
160
|
+
const r = n[0], s = n[1], a = n[2];
|
|
161
|
+
e.has(r) || e.set(r, {
|
|
162
|
+
parents: [],
|
|
163
|
+
children: []
|
|
164
|
+
});
|
|
165
|
+
const o = { ID: s, relationship: a };
|
|
166
|
+
e.get(r).parents.push(o), e.has(s) || e.set(s, {
|
|
167
|
+
parents: [],
|
|
168
|
+
children: []
|
|
169
|
+
});
|
|
170
|
+
const l = { ID: r, relationship: a };
|
|
171
|
+
e.get(s).children.push(l);
|
|
172
|
+
}), e;
|
|
173
|
+
}
|
|
174
|
+
// Parse FBXTree.Objects.Video for embedded image data
|
|
175
|
+
// These images are connected to textures in FBXTree.Objects.Textures
|
|
176
|
+
// via FBXTree.Connections.
|
|
177
|
+
parseImages() {
|
|
178
|
+
const e = {}, t = {};
|
|
179
|
+
if ("Video" in C.Objects) {
|
|
180
|
+
const n = C.Objects.Video;
|
|
181
|
+
for (const r in n) {
|
|
182
|
+
const s = n[r], a = parseInt(r);
|
|
183
|
+
if (e[a] = s.RelativeFilename || s.Filename, "Content" in s) {
|
|
184
|
+
const o = s.Content instanceof ArrayBuffer && s.Content.byteLength > 0, l = typeof s.Content == "string" && s.Content !== "";
|
|
185
|
+
if (o || l) {
|
|
186
|
+
const p = this.parseImage(n[r]);
|
|
187
|
+
t[s.RelativeFilename || s.Filename] = p;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
for (const n in e) {
|
|
193
|
+
const r = e[n];
|
|
194
|
+
t[r] !== void 0 ? e[n] = t[r] : e[n] = e[n].split("\\").pop();
|
|
195
|
+
}
|
|
196
|
+
return e;
|
|
197
|
+
}
|
|
198
|
+
// Parse embedded image data in FBXTree.Video.Content
|
|
199
|
+
parseImage(e) {
|
|
200
|
+
const t = e.Content, n = e.RelativeFilename || e.Filename, r = n.slice(n.lastIndexOf(".") + 1).toLowerCase();
|
|
201
|
+
let s;
|
|
202
|
+
switch (r) {
|
|
203
|
+
case "bmp":
|
|
204
|
+
s = "image/bmp";
|
|
205
|
+
break;
|
|
206
|
+
case "jpg":
|
|
207
|
+
case "jpeg":
|
|
208
|
+
s = "image/jpeg";
|
|
209
|
+
break;
|
|
210
|
+
case "png":
|
|
211
|
+
s = "image/png";
|
|
212
|
+
break;
|
|
213
|
+
case "tif":
|
|
214
|
+
s = "image/tiff";
|
|
215
|
+
break;
|
|
216
|
+
case "tga":
|
|
217
|
+
this.manager.getHandler(".tga") === null && console.warn("FBXLoader: TGA loader not found, skipping ", n), s = "image/tga";
|
|
218
|
+
break;
|
|
219
|
+
case "webp":
|
|
220
|
+
s = "image/webp";
|
|
221
|
+
break;
|
|
222
|
+
default:
|
|
223
|
+
console.warn('FBXLoader: Image type "' + r + '" is not supported.');
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (typeof t == "string")
|
|
227
|
+
return "data:" + s + ";base64," + t;
|
|
228
|
+
{
|
|
229
|
+
const a = new Uint8Array(t);
|
|
230
|
+
return window.URL.createObjectURL(new Blob([a], { type: s }));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// Parse nodes in FBXTree.Objects.Texture
|
|
234
|
+
// These contain details such as UV scaling, cropping, rotation etc and are connected
|
|
235
|
+
// to images in FBXTree.Objects.Video
|
|
236
|
+
parseTextures(e) {
|
|
237
|
+
const t = /* @__PURE__ */ new Map();
|
|
238
|
+
if ("Texture" in C.Objects) {
|
|
239
|
+
const n = C.Objects.Texture;
|
|
240
|
+
for (const r in n) {
|
|
241
|
+
const s = this.parseTexture(n[r], e);
|
|
242
|
+
t.set(parseInt(r), s);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return t;
|
|
246
|
+
}
|
|
247
|
+
// Parse individual node in FBXTree.Objects.Texture
|
|
248
|
+
parseTexture(e, t) {
|
|
249
|
+
const n = this.loadTexture(e, t);
|
|
250
|
+
n.ID = e.id, n.name = e.attrName;
|
|
251
|
+
const r = e.WrapModeU, s = e.WrapModeV, a = r !== void 0 ? r.value : 0, o = s !== void 0 ? s.value : 0;
|
|
252
|
+
if (n.wrapS = a === 0 ? ue : pe, n.wrapT = o === 0 ? ue : pe, "Scaling" in e) {
|
|
253
|
+
const l = e.Scaling.value;
|
|
254
|
+
n.repeat.x = l[0], n.repeat.y = l[1];
|
|
255
|
+
}
|
|
256
|
+
if ("Translation" in e) {
|
|
257
|
+
const l = e.Translation.value;
|
|
258
|
+
n.offset.x = l[0], n.offset.y = l[1];
|
|
259
|
+
}
|
|
260
|
+
return n;
|
|
261
|
+
}
|
|
262
|
+
// load a texture specified as a blob or data URI, or via an external URL using TextureLoader
|
|
263
|
+
loadTexture(e, t) {
|
|
264
|
+
const n = e.FileName.split(".").pop().toLowerCase();
|
|
265
|
+
let r = this.manager.getHandler(`.${n}`);
|
|
266
|
+
r === null && (r = this.textureLoader);
|
|
267
|
+
const s = r.path;
|
|
268
|
+
s || r.setPath(this.textureLoader.path);
|
|
269
|
+
const a = O.get(e.id).children;
|
|
270
|
+
let o;
|
|
271
|
+
if (a !== void 0 && a.length > 0 && t[a[0].ID] !== void 0 && (o = t[a[0].ID], (o.indexOf("blob:") === 0 || o.indexOf("data:") === 0) && r.setPath(void 0)), o === void 0)
|
|
272
|
+
return console.warn("FBXLoader: Undefined filename, creating placeholder texture."), new Y();
|
|
273
|
+
const l = r.load(o);
|
|
274
|
+
return r.setPath(s), l;
|
|
275
|
+
}
|
|
276
|
+
// Parse nodes in FBXTree.Objects.Material
|
|
277
|
+
parseMaterials(e) {
|
|
278
|
+
const t = /* @__PURE__ */ new Map();
|
|
279
|
+
if ("Material" in C.Objects) {
|
|
280
|
+
const n = C.Objects.Material;
|
|
281
|
+
for (const r in n) {
|
|
282
|
+
const s = this.parseMaterial(n[r], e);
|
|
283
|
+
s !== null && t.set(parseInt(r), s);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return t;
|
|
287
|
+
}
|
|
288
|
+
// Parse single node in FBXTree.Objects.Material
|
|
289
|
+
// Materials are connected to texture maps in FBXTree.Objects.Textures
|
|
290
|
+
// FBX format currently only supports Lambert and Phong shading models
|
|
291
|
+
parseMaterial(e, t) {
|
|
292
|
+
const n = e.id, r = e.attrName;
|
|
293
|
+
let s = e.ShadingModel;
|
|
294
|
+
if (typeof s == "object" && (s = s.value), !O.has(n)) return null;
|
|
295
|
+
const a = this.parseParameters(e, t, n);
|
|
296
|
+
let o;
|
|
297
|
+
switch (s.toLowerCase()) {
|
|
298
|
+
case "phong":
|
|
299
|
+
o = new W();
|
|
300
|
+
break;
|
|
301
|
+
case "lambert":
|
|
302
|
+
o = new Se();
|
|
303
|
+
break;
|
|
304
|
+
default:
|
|
305
|
+
console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.', s), o = new W();
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
return o.setValues(a), o.name = r, o;
|
|
309
|
+
}
|
|
310
|
+
// Parse FBX material and return parameters suitable for a three.js material
|
|
311
|
+
// Also parse the texture map and return any textures associated with the material
|
|
312
|
+
parseParameters(e, t, n) {
|
|
313
|
+
const r = {};
|
|
314
|
+
e.BumpFactor && (r.bumpScale = e.BumpFactor.value), e.Diffuse ? r.color = N.colorSpaceToWorking(new k().fromArray(e.Diffuse.value), X) : e.DiffuseColor && (e.DiffuseColor.type === "Color" || e.DiffuseColor.type === "ColorRGB") && (r.color = N.colorSpaceToWorking(new k().fromArray(e.DiffuseColor.value), X)), e.DisplacementFactor && (r.displacementScale = e.DisplacementFactor.value), e.Emissive ? r.emissive = N.colorSpaceToWorking(new k().fromArray(e.Emissive.value), X) : e.EmissiveColor && (e.EmissiveColor.type === "Color" || e.EmissiveColor.type === "ColorRGB") && (r.emissive = N.colorSpaceToWorking(new k().fromArray(e.EmissiveColor.value), X)), e.EmissiveFactor && (r.emissiveIntensity = parseFloat(e.EmissiveFactor.value)), r.opacity = 1 - (e.TransparencyFactor ? parseFloat(e.TransparencyFactor.value) : 0), (r.opacity === 1 || r.opacity === 0) && (r.opacity = e.Opacity ? parseFloat(e.Opacity.value) : null, r.opacity === null && (r.opacity = 1 - (e.TransparentColor ? parseFloat(e.TransparentColor.value[0]) : 0))), r.opacity < 1 && (r.transparent = !0), e.ReflectionFactor && (r.reflectivity = e.ReflectionFactor.value), e.Shininess && (r.shininess = e.Shininess.value), e.Specular ? r.specular = N.colorSpaceToWorking(new k().fromArray(e.Specular.value), X) : e.SpecularColor && e.SpecularColor.type === "Color" && (r.specular = N.colorSpaceToWorking(new k().fromArray(e.SpecularColor.value), X));
|
|
315
|
+
const s = this;
|
|
316
|
+
return O.get(n).children.forEach(function(a) {
|
|
317
|
+
const o = a.relationship;
|
|
318
|
+
switch (o) {
|
|
319
|
+
case "Bump":
|
|
320
|
+
r.bumpMap = s.getTexture(t, a.ID);
|
|
321
|
+
break;
|
|
322
|
+
case "Maya|TEX_ao_map":
|
|
323
|
+
r.aoMap = s.getTexture(t, a.ID);
|
|
324
|
+
break;
|
|
325
|
+
case "DiffuseColor":
|
|
326
|
+
case "Maya|TEX_color_map":
|
|
327
|
+
r.map = s.getTexture(t, a.ID), r.map !== void 0 && (r.map.colorSpace = X);
|
|
328
|
+
break;
|
|
329
|
+
case "DisplacementColor":
|
|
330
|
+
r.displacementMap = s.getTexture(t, a.ID);
|
|
331
|
+
break;
|
|
332
|
+
case "EmissiveColor":
|
|
333
|
+
r.emissiveMap = s.getTexture(t, a.ID), r.emissiveMap !== void 0 && (r.emissiveMap.colorSpace = X);
|
|
334
|
+
break;
|
|
335
|
+
case "NormalMap":
|
|
336
|
+
case "Maya|TEX_normal_map":
|
|
337
|
+
r.normalMap = s.getTexture(t, a.ID);
|
|
338
|
+
break;
|
|
339
|
+
case "ReflectionColor":
|
|
340
|
+
r.envMap = s.getTexture(t, a.ID), r.envMap !== void 0 && (r.envMap.mapping = Ge, r.envMap.colorSpace = X);
|
|
341
|
+
break;
|
|
342
|
+
case "SpecularColor":
|
|
343
|
+
r.specularMap = s.getTexture(t, a.ID), r.specularMap !== void 0 && (r.specularMap.colorSpace = X);
|
|
344
|
+
break;
|
|
345
|
+
case "TransparentColor":
|
|
346
|
+
case "TransparencyFactor":
|
|
347
|
+
r.alphaMap = s.getTexture(t, a.ID), r.transparent = !0;
|
|
348
|
+
break;
|
|
349
|
+
case "AmbientColor":
|
|
350
|
+
case "ShininessExponent":
|
|
351
|
+
case "SpecularFactor":
|
|
352
|
+
case "VectorDisplacementColor":
|
|
353
|
+
default:
|
|
354
|
+
console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.", o);
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
}), r;
|
|
358
|
+
}
|
|
359
|
+
// get a texture from the textureMap for use by a material.
|
|
360
|
+
getTexture(e, t) {
|
|
361
|
+
return "LayeredTexture" in C.Objects && t in C.Objects.LayeredTexture && (console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer."), t = O.get(t).children[0].ID), e.get(t);
|
|
362
|
+
}
|
|
363
|
+
// Parse nodes in FBXTree.Objects.Deformer
|
|
364
|
+
// Deformer node can contain skinning or Vertex Cache animation data, however only skinning is supported here
|
|
365
|
+
// Generates map of Skeleton-like objects for use later when generating and binding skeletons.
|
|
366
|
+
parseDeformers() {
|
|
367
|
+
const e = {}, t = {};
|
|
368
|
+
if ("Deformer" in C.Objects) {
|
|
369
|
+
const n = C.Objects.Deformer;
|
|
370
|
+
for (const r in n) {
|
|
371
|
+
const s = n[r], a = O.get(parseInt(r));
|
|
372
|
+
if (s.attrType === "Skin") {
|
|
373
|
+
const o = this.parseSkeleton(a, n);
|
|
374
|
+
o.ID = r, a.parents.length > 1 && console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported."), o.geometryID = a.parents[0].ID, e[r] = o;
|
|
375
|
+
} else if (s.attrType === "BlendShape") {
|
|
376
|
+
const o = {
|
|
377
|
+
id: r
|
|
378
|
+
};
|
|
379
|
+
o.rawTargets = this.parseMorphTargets(a, n), o.id = r, a.parents.length > 1 && console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported."), t[r] = o;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
skeletons: e,
|
|
385
|
+
morphTargets: t
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
// Parse single nodes in FBXTree.Objects.Deformer
|
|
389
|
+
// The top level skeleton node has type 'Skin' and sub nodes have type 'Cluster'
|
|
390
|
+
// Each skin node represents a skeleton and each cluster node represents a bone
|
|
391
|
+
parseSkeleton(e, t) {
|
|
392
|
+
const n = [];
|
|
393
|
+
return e.children.forEach(function(r) {
|
|
394
|
+
const s = t[r.ID];
|
|
395
|
+
if (s.attrType !== "Cluster") return;
|
|
396
|
+
const a = {
|
|
397
|
+
ID: r.ID,
|
|
398
|
+
indices: [],
|
|
399
|
+
weights: [],
|
|
400
|
+
transformLink: new L().fromArray(s.TransformLink.a)
|
|
401
|
+
// transform: new Matrix4().fromArray( boneNode.Transform.a ),
|
|
402
|
+
// linkMode: boneNode.Mode,
|
|
403
|
+
};
|
|
404
|
+
"Indexes" in s && (a.indices = s.Indexes.a, a.weights = s.Weights.a), n.push(a);
|
|
405
|
+
}), {
|
|
406
|
+
rawBones: n,
|
|
407
|
+
bones: []
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
// The top level morph deformer node has type "BlendShape" and sub nodes have type "BlendShapeChannel"
|
|
411
|
+
parseMorphTargets(e, t) {
|
|
412
|
+
const n = [];
|
|
413
|
+
for (let r = 0; r < e.children.length; r++) {
|
|
414
|
+
const s = e.children[r], a = t[s.ID], o = {
|
|
415
|
+
name: a.attrName,
|
|
416
|
+
initialWeight: a.DeformPercent,
|
|
417
|
+
id: a.id,
|
|
418
|
+
fullWeights: a.FullWeights.a
|
|
419
|
+
};
|
|
420
|
+
if (a.attrType !== "BlendShapeChannel") return;
|
|
421
|
+
o.geoID = O.get(parseInt(s.ID)).children.filter(function(l) {
|
|
422
|
+
return l.relationship === void 0;
|
|
423
|
+
})[0].ID, n.push(o);
|
|
424
|
+
}
|
|
425
|
+
return n;
|
|
426
|
+
}
|
|
427
|
+
// create the main Group() to be returned by the loader
|
|
428
|
+
parseScene(e, t, n) {
|
|
429
|
+
U = new ce();
|
|
430
|
+
const r = this.parseModels(e.skeletons, t, n), s = C.Objects.Model, a = this;
|
|
431
|
+
r.forEach(function(l) {
|
|
432
|
+
const p = s[l.ID];
|
|
433
|
+
a.setLookAtProperties(l, p), O.get(l.ID).parents.forEach(function(u) {
|
|
434
|
+
const c = r.get(u.ID);
|
|
435
|
+
c !== void 0 && c.add(l);
|
|
436
|
+
}), l.parent === null && U.add(l);
|
|
437
|
+
}), this.bindSkeleton(e.skeletons, t, r), this.addGlobalSceneSettings(), U.traverse(function(l) {
|
|
438
|
+
if (l.userData.transformData) {
|
|
439
|
+
l.parent && (l.userData.transformData.parentMatrix = l.parent.matrix, l.userData.transformData.parentMatrixWorld = l.parent.matrixWorld);
|
|
440
|
+
const p = Ce(l.userData.transformData);
|
|
441
|
+
l.applyMatrix4(p), l.updateWorldMatrix();
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
const o = new Et().parse();
|
|
445
|
+
U.children.length === 1 && U.children[0].isGroup && (U.children[0].animations = o, U = U.children[0]), U.animations = o;
|
|
446
|
+
}
|
|
447
|
+
// parse nodes in FBXTree.Objects.Model
|
|
448
|
+
parseModels(e, t, n) {
|
|
449
|
+
const r = /* @__PURE__ */ new Map(), s = C.Objects.Model;
|
|
450
|
+
for (const a in s) {
|
|
451
|
+
const o = parseInt(a), l = s[a], p = O.get(o);
|
|
452
|
+
if (p === void 0) continue;
|
|
453
|
+
let f = this.buildSkeleton(p, e, o, l.attrName);
|
|
454
|
+
if (!f) {
|
|
455
|
+
switch (l.attrType) {
|
|
456
|
+
case "Camera":
|
|
457
|
+
f = this.createCamera(p);
|
|
458
|
+
break;
|
|
459
|
+
case "Light":
|
|
460
|
+
f = this.createLight(p);
|
|
461
|
+
break;
|
|
462
|
+
case "Mesh":
|
|
463
|
+
f = this.createMesh(p, t, n);
|
|
464
|
+
break;
|
|
465
|
+
case "NurbsCurve":
|
|
466
|
+
f = this.createCurve(p, t);
|
|
467
|
+
break;
|
|
468
|
+
case "LimbNode":
|
|
469
|
+
case "Root":
|
|
470
|
+
f = new fe();
|
|
471
|
+
break;
|
|
472
|
+
case "Null":
|
|
473
|
+
default:
|
|
474
|
+
f = new ce();
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
f.name = l.attrName ? ee.sanitizeNodeName(l.attrName) : "", f.userData.originalName = l.attrName, f.ID = o;
|
|
478
|
+
}
|
|
479
|
+
this.getTransformData(f, l), r.set(o, f);
|
|
480
|
+
}
|
|
481
|
+
return r;
|
|
482
|
+
}
|
|
483
|
+
buildSkeleton(e, t, n, r) {
|
|
484
|
+
let s = null;
|
|
485
|
+
return e.parents.forEach(function(a) {
|
|
486
|
+
for (const o in t) {
|
|
487
|
+
const l = t[o];
|
|
488
|
+
l.rawBones.forEach(function(p, f) {
|
|
489
|
+
if (p.ID === a.ID) {
|
|
490
|
+
const u = s;
|
|
491
|
+
s = new fe(), s.matrixWorld.copy(p.transformLink), s.name = r ? ee.sanitizeNodeName(r) : "", s.userData.originalName = r, s.ID = n, l.bones[f] = s, u !== null && s.add(u);
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
}), s;
|
|
496
|
+
}
|
|
497
|
+
// create a PerspectiveCamera or OrthographicCamera
|
|
498
|
+
createCamera(e) {
|
|
499
|
+
let t, n;
|
|
500
|
+
if (e.children.forEach(function(r) {
|
|
501
|
+
const s = C.Objects.NodeAttribute[r.ID];
|
|
502
|
+
s !== void 0 && (n = s);
|
|
503
|
+
}), n === void 0)
|
|
504
|
+
t = new Z();
|
|
505
|
+
else {
|
|
506
|
+
let r = 0;
|
|
507
|
+
n.CameraProjectionType !== void 0 && n.CameraProjectionType.value === 1 && (r = 1);
|
|
508
|
+
let s = 1;
|
|
509
|
+
n.NearPlane !== void 0 && (s = n.NearPlane.value / 1e3);
|
|
510
|
+
let a = 1e3;
|
|
511
|
+
n.FarPlane !== void 0 && (a = n.FarPlane.value / 1e3);
|
|
512
|
+
let o = window.innerWidth, l = window.innerHeight;
|
|
513
|
+
n.AspectWidth !== void 0 && n.AspectHeight !== void 0 && (o = n.AspectWidth.value, l = n.AspectHeight.value);
|
|
514
|
+
const p = o / l;
|
|
515
|
+
let f = 45;
|
|
516
|
+
n.FieldOfView !== void 0 && (f = n.FieldOfView.value);
|
|
517
|
+
const u = n.FocalLength ? n.FocalLength.value : null;
|
|
518
|
+
switch (r) {
|
|
519
|
+
case 0:
|
|
520
|
+
t = new Ne(f, p, s, a), u !== null && t.setFocalLength(u);
|
|
521
|
+
break;
|
|
522
|
+
case 1:
|
|
523
|
+
console.warn("THREE.FBXLoader: Orthographic cameras not supported yet."), t = new Z();
|
|
524
|
+
break;
|
|
525
|
+
default:
|
|
526
|
+
console.warn("THREE.FBXLoader: Unknown camera type " + r + "."), t = new Z();
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return t;
|
|
531
|
+
}
|
|
532
|
+
// Create a DirectionalLight, PointLight or SpotLight
|
|
533
|
+
createLight(e) {
|
|
534
|
+
let t, n;
|
|
535
|
+
if (e.children.forEach(function(r) {
|
|
536
|
+
const s = C.Objects.NodeAttribute[r.ID];
|
|
537
|
+
s !== void 0 && (n = s);
|
|
538
|
+
}), n === void 0)
|
|
539
|
+
t = new Z();
|
|
540
|
+
else {
|
|
541
|
+
let r;
|
|
542
|
+
n.LightType === void 0 ? r = 0 : r = n.LightType.value;
|
|
543
|
+
let s = 16777215;
|
|
544
|
+
n.Color !== void 0 && (s = N.colorSpaceToWorking(new k().fromArray(n.Color.value), X));
|
|
545
|
+
let a = n.Intensity === void 0 ? 1 : n.Intensity.value / 100;
|
|
546
|
+
n.CastLightOnObject !== void 0 && n.CastLightOnObject.value === 0 && (a = 0);
|
|
547
|
+
let o = 0;
|
|
548
|
+
n.FarAttenuationEnd !== void 0 && (n.EnableFarAttenuation !== void 0 && n.EnableFarAttenuation.value === 0 ? o = 0 : o = n.FarAttenuationEnd.value);
|
|
549
|
+
const l = 1;
|
|
550
|
+
switch (r) {
|
|
551
|
+
case 0:
|
|
552
|
+
t = new he(s, a, o, l);
|
|
553
|
+
break;
|
|
554
|
+
case 1:
|
|
555
|
+
t = new ze(s, a);
|
|
556
|
+
break;
|
|
557
|
+
case 2:
|
|
558
|
+
let p = Math.PI / 3;
|
|
559
|
+
n.InnerAngle !== void 0 && (p = B.degToRad(n.InnerAngle.value));
|
|
560
|
+
let f = 0;
|
|
561
|
+
n.OuterAngle !== void 0 && (f = B.degToRad(n.OuterAngle.value), f = Math.max(f, 1)), t = new $e(s, a, o, p, f, l);
|
|
562
|
+
break;
|
|
563
|
+
default:
|
|
564
|
+
console.warn("THREE.FBXLoader: Unknown light type " + n.LightType.value + ", defaulting to a PointLight."), t = new he(s, a);
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
n.CastShadows !== void 0 && n.CastShadows.value === 1 && (t.castShadow = !0);
|
|
568
|
+
}
|
|
569
|
+
return t;
|
|
570
|
+
}
|
|
571
|
+
createMesh(e, t, n) {
|
|
572
|
+
let r, s = null, a = null;
|
|
573
|
+
const o = [];
|
|
574
|
+
if (e.children.forEach(function(l) {
|
|
575
|
+
t.has(l.ID) && (s = t.get(l.ID)), n.has(l.ID) && o.push(n.get(l.ID));
|
|
576
|
+
}), o.length > 1 ? a = o : o.length > 0 ? a = o[0] : (a = new W({
|
|
577
|
+
name: J.DEFAULT_MATERIAL_NAME,
|
|
578
|
+
color: 13421772
|
|
579
|
+
}), o.push(a)), "color" in s.attributes && o.forEach(function(l) {
|
|
580
|
+
l.vertexColors = !0;
|
|
581
|
+
}), s.groups.length > 0) {
|
|
582
|
+
let l = !1;
|
|
583
|
+
for (let p = 0, f = s.groups.length; p < f; p++) {
|
|
584
|
+
const u = s.groups[p];
|
|
585
|
+
(u.materialIndex < 0 || u.materialIndex >= o.length) && (u.materialIndex = o.length, l = !0);
|
|
586
|
+
}
|
|
587
|
+
if (l) {
|
|
588
|
+
const p = new W();
|
|
589
|
+
o.push(p);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return s.FBX_Deformer ? (r = new je(s, a), r.normalizeSkinWeights()) : r = new Fe(s, a), r;
|
|
593
|
+
}
|
|
594
|
+
createCurve(e, t) {
|
|
595
|
+
const n = e.children.reduce(function(s, a) {
|
|
596
|
+
return t.has(a.ID) && (s = t.get(a.ID)), s;
|
|
597
|
+
}, null), r = new He({
|
|
598
|
+
name: J.DEFAULT_MATERIAL_NAME,
|
|
599
|
+
color: 3342591,
|
|
600
|
+
linewidth: 1
|
|
601
|
+
});
|
|
602
|
+
return new We(n, r);
|
|
603
|
+
}
|
|
604
|
+
// parse the model node for transform data
|
|
605
|
+
getTransformData(e, t) {
|
|
606
|
+
const n = {};
|
|
607
|
+
"InheritType" in t && (n.inheritType = parseInt(t.InheritType.value)), "RotationOrder" in t ? n.eulerOrder = q(t.RotationOrder.value) : n.eulerOrder = q(0), "Lcl_Translation" in t && (n.translation = t.Lcl_Translation.value), "PreRotation" in t && (n.preRotation = t.PreRotation.value), "Lcl_Rotation" in t && (n.rotation = t.Lcl_Rotation.value), "PostRotation" in t && (n.postRotation = t.PostRotation.value), "Lcl_Scaling" in t && (n.scale = t.Lcl_Scaling.value), "ScalingOffset" in t && (n.scalingOffset = t.ScalingOffset.value), "ScalingPivot" in t && (n.scalingPivot = t.ScalingPivot.value), "RotationOffset" in t && (n.rotationOffset = t.RotationOffset.value), "RotationPivot" in t && (n.rotationPivot = t.RotationPivot.value), e.userData.transformData = n;
|
|
608
|
+
}
|
|
609
|
+
setLookAtProperties(e, t) {
|
|
610
|
+
"LookAtProperty" in t && O.get(e.ID).children.forEach(function(r) {
|
|
611
|
+
if (r.relationship === "LookAtProperty") {
|
|
612
|
+
const s = C.Objects.Model[r.ID];
|
|
613
|
+
if ("Lcl_Translation" in s) {
|
|
614
|
+
const a = s.Lcl_Translation.value;
|
|
615
|
+
e.target !== void 0 ? (e.target.position.fromArray(a), U.add(e.target)) : e.lookAt(new V().fromArray(a));
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
bindSkeleton(e, t, n) {
|
|
621
|
+
const r = this.parsePoseNodes();
|
|
622
|
+
for (const s in e) {
|
|
623
|
+
const a = e[s];
|
|
624
|
+
O.get(parseInt(a.ID)).parents.forEach(function(l) {
|
|
625
|
+
if (t.has(l.ID)) {
|
|
626
|
+
const p = l.ID;
|
|
627
|
+
O.get(p).parents.forEach(function(u) {
|
|
628
|
+
n.has(u.ID) && n.get(u.ID).bind(new Ye(a.bones), r[u.ID]);
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
parsePoseNodes() {
|
|
635
|
+
const e = {};
|
|
636
|
+
if ("Pose" in C.Objects) {
|
|
637
|
+
const t = C.Objects.Pose;
|
|
638
|
+
for (const n in t)
|
|
639
|
+
if (t[n].attrType === "BindPose" && t[n].NbPoseNodes > 0) {
|
|
640
|
+
const r = t[n].PoseNode;
|
|
641
|
+
Array.isArray(r) ? r.forEach(function(s) {
|
|
642
|
+
e[s.Node] = new L().fromArray(s.Matrix.a);
|
|
643
|
+
}) : e[r.Node] = new L().fromArray(r.Matrix.a);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
return e;
|
|
647
|
+
}
|
|
648
|
+
addGlobalSceneSettings() {
|
|
649
|
+
if ("GlobalSettings" in C) {
|
|
650
|
+
if ("AmbientColor" in C.GlobalSettings) {
|
|
651
|
+
const e = C.GlobalSettings.AmbientColor.value, t = e[0], n = e[1], r = e[2];
|
|
652
|
+
if (t !== 0 || n !== 0 || r !== 0) {
|
|
653
|
+
const s = new k().setRGB(t, n, r, X);
|
|
654
|
+
U.add(new qe(s, 1));
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
"UnitScaleFactor" in C.GlobalSettings && (U.userData.unitScaleFactor = C.GlobalSettings.UnitScaleFactor.value);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
class xt {
|
|
662
|
+
constructor() {
|
|
663
|
+
this.negativeMaterialIndices = !1;
|
|
664
|
+
}
|
|
665
|
+
// Parse nodes in FBXTree.Objects.Geometry
|
|
666
|
+
parse(e) {
|
|
667
|
+
const t = /* @__PURE__ */ new Map();
|
|
668
|
+
if ("Geometry" in C.Objects) {
|
|
669
|
+
const n = C.Objects.Geometry;
|
|
670
|
+
for (const r in n) {
|
|
671
|
+
const s = O.get(parseInt(r)), a = this.parseGeometry(s, n[r], e);
|
|
672
|
+
t.set(parseInt(r), a);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
return this.negativeMaterialIndices === !0 && console.warn("THREE.FBXLoader: The FBX file contains invalid (negative) material indices. The asset might not render as expected."), t;
|
|
676
|
+
}
|
|
677
|
+
// Parse single node in FBXTree.Objects.Geometry
|
|
678
|
+
parseGeometry(e, t, n) {
|
|
679
|
+
switch (t.attrType) {
|
|
680
|
+
case "Mesh":
|
|
681
|
+
return this.parseMeshGeometry(e, t, n);
|
|
682
|
+
case "NurbsCurve":
|
|
683
|
+
return this.parseNurbsGeometry(t);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
// Parse single node mesh geometry in FBXTree.Objects.Geometry
|
|
687
|
+
parseMeshGeometry(e, t, n) {
|
|
688
|
+
const r = n.skeletons, s = [], a = e.parents.map(function(u) {
|
|
689
|
+
return C.Objects.Model[u.ID];
|
|
690
|
+
});
|
|
691
|
+
if (a.length === 0) return;
|
|
692
|
+
const o = e.children.reduce(function(u, c) {
|
|
693
|
+
return r[c.ID] !== void 0 && (u = r[c.ID]), u;
|
|
694
|
+
}, null);
|
|
695
|
+
e.children.forEach(function(u) {
|
|
696
|
+
n.morphTargets[u.ID] !== void 0 && s.push(n.morphTargets[u.ID]);
|
|
697
|
+
});
|
|
698
|
+
const l = a[0], p = {};
|
|
699
|
+
"RotationOrder" in l && (p.eulerOrder = q(l.RotationOrder.value)), "InheritType" in l && (p.inheritType = parseInt(l.InheritType.value)), "GeometricTranslation" in l && (p.translation = l.GeometricTranslation.value), "GeometricRotation" in l && (p.rotation = l.GeometricRotation.value), "GeometricScaling" in l && (p.scale = l.GeometricScaling.value);
|
|
700
|
+
const f = Ce(p);
|
|
701
|
+
return this.genGeometry(t, o, s, f);
|
|
702
|
+
}
|
|
703
|
+
// Generate a BufferGeometry from a node in FBXTree.Objects.Geometry
|
|
704
|
+
genGeometry(e, t, n, r) {
|
|
705
|
+
const s = new re();
|
|
706
|
+
e.attrName && (s.name = e.attrName);
|
|
707
|
+
const a = this.parseGeoNode(e, t), o = this.genBuffers(a), l = new j(o.vertex, 3);
|
|
708
|
+
if (l.applyMatrix4(r), s.setAttribute("position", l), o.colors.length > 0 && s.setAttribute("color", new j(o.colors, 3)), t && (s.setAttribute("skinIndex", new Ke(o.weightsIndices, 4)), s.setAttribute("skinWeight", new j(o.vertexWeights, 4)), s.FBX_Deformer = t), o.normal.length > 0) {
|
|
709
|
+
const p = new Ze().getNormalMatrix(r), f = new j(o.normal, 3);
|
|
710
|
+
f.applyNormalMatrix(p), s.setAttribute("normal", f);
|
|
711
|
+
}
|
|
712
|
+
if (o.uvs.forEach(function(p, f) {
|
|
713
|
+
const u = f === 0 ? "uv" : `uv${f}`;
|
|
714
|
+
s.setAttribute(u, new j(o.uvs[f], 2));
|
|
715
|
+
}), a.material && a.material.mappingType !== "AllSame") {
|
|
716
|
+
let p = o.materialIndex[0], f = 0;
|
|
717
|
+
if (o.materialIndex.forEach(function(u, c) {
|
|
718
|
+
u !== p && (s.addGroup(f, c - f, p), p = u, f = c);
|
|
719
|
+
}), s.groups.length > 0) {
|
|
720
|
+
const u = s.groups[s.groups.length - 1], c = u.start + u.count;
|
|
721
|
+
c !== o.materialIndex.length && s.addGroup(c, o.materialIndex.length - c, p);
|
|
722
|
+
}
|
|
723
|
+
s.groups.length === 0 && s.addGroup(0, o.materialIndex.length, o.materialIndex[0]);
|
|
724
|
+
}
|
|
725
|
+
return this.addMorphTargets(s, e, n, r), s;
|
|
726
|
+
}
|
|
727
|
+
parseGeoNode(e, t) {
|
|
728
|
+
const n = {};
|
|
729
|
+
if (n.vertexPositions = e.Vertices !== void 0 ? e.Vertices.a : [], n.vertexIndices = e.PolygonVertexIndex !== void 0 ? e.PolygonVertexIndex.a : [], e.LayerElementColor && e.LayerElementColor[0].Colors && (n.color = this.parseVertexColors(e.LayerElementColor[0])), e.LayerElementMaterial && (n.material = this.parseMaterialIndices(e.LayerElementMaterial[0])), e.LayerElementNormal && (n.normal = this.parseNormals(e.LayerElementNormal[0])), e.LayerElementUV) {
|
|
730
|
+
n.uv = [];
|
|
731
|
+
let r = 0;
|
|
732
|
+
for (; e.LayerElementUV[r]; )
|
|
733
|
+
e.LayerElementUV[r].UV && n.uv.push(this.parseUVs(e.LayerElementUV[r])), r++;
|
|
734
|
+
}
|
|
735
|
+
return n.weightTable = {}, t !== null && (n.skeleton = t, t.rawBones.forEach(function(r, s) {
|
|
736
|
+
r.indices.forEach(function(a, o) {
|
|
737
|
+
n.weightTable[a] === void 0 && (n.weightTable[a] = []), n.weightTable[a].push({
|
|
738
|
+
id: s,
|
|
739
|
+
weight: r.weights[o]
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
})), n;
|
|
743
|
+
}
|
|
744
|
+
genBuffers(e) {
|
|
745
|
+
const t = {
|
|
746
|
+
vertex: [],
|
|
747
|
+
normal: [],
|
|
748
|
+
colors: [],
|
|
749
|
+
uvs: [],
|
|
750
|
+
materialIndex: [],
|
|
751
|
+
vertexWeights: [],
|
|
752
|
+
weightsIndices: []
|
|
753
|
+
};
|
|
754
|
+
let n = 0, r = 0, s = !1, a = [], o = [], l = [], p = [], f = [], u = [];
|
|
755
|
+
const c = this;
|
|
756
|
+
return e.vertexIndices.forEach(function(h, m) {
|
|
757
|
+
let g, d = !1;
|
|
758
|
+
h < 0 && (h = h ^ -1, d = !0);
|
|
759
|
+
let T = [], F = [];
|
|
760
|
+
if (a.push(h * 3, h * 3 + 1, h * 3 + 2), e.color) {
|
|
761
|
+
const y = Q(m, n, h, e.color);
|
|
762
|
+
l.push(y[0], y[1], y[2]);
|
|
763
|
+
}
|
|
764
|
+
if (e.skeleton) {
|
|
765
|
+
if (e.weightTable[h] !== void 0 && e.weightTable[h].forEach(function(y) {
|
|
766
|
+
F.push(y.weight), T.push(y.id);
|
|
767
|
+
}), F.length > 4) {
|
|
768
|
+
s || (console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."), s = !0);
|
|
769
|
+
const y = [0, 0, 0, 0], x = [0, 0, 0, 0];
|
|
770
|
+
F.forEach(function(I, A) {
|
|
771
|
+
let M = I, v = T[A];
|
|
772
|
+
x.forEach(function(S, E, b) {
|
|
773
|
+
if (M > S) {
|
|
774
|
+
b[E] = M, M = S;
|
|
775
|
+
const D = y[E];
|
|
776
|
+
y[E] = v, v = D;
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
}), T = y, F = x;
|
|
780
|
+
}
|
|
781
|
+
for (; F.length < 4; )
|
|
782
|
+
F.push(0), T.push(0);
|
|
783
|
+
for (let y = 0; y < 4; ++y)
|
|
784
|
+
f.push(F[y]), u.push(T[y]);
|
|
785
|
+
}
|
|
786
|
+
if (e.normal) {
|
|
787
|
+
const y = Q(m, n, h, e.normal);
|
|
788
|
+
o.push(y[0], y[1], y[2]);
|
|
789
|
+
}
|
|
790
|
+
e.material && e.material.mappingType !== "AllSame" && (g = Q(m, n, h, e.material)[0], g < 0 && (c.negativeMaterialIndices = !0, g = 0)), e.uv && e.uv.forEach(function(y, x) {
|
|
791
|
+
const I = Q(m, n, h, y);
|
|
792
|
+
p[x] === void 0 && (p[x] = []), p[x].push(I[0]), p[x].push(I[1]);
|
|
793
|
+
}), r++, d && (c.genFace(t, e, a, g, o, l, p, f, u, r), n++, r = 0, a = [], o = [], l = [], p = [], f = [], u = []);
|
|
794
|
+
}), t;
|
|
795
|
+
}
|
|
796
|
+
// See https://www.khronos.org/opengl/wiki/Calculating_a_Surface_Normal
|
|
797
|
+
getNormalNewell(e) {
|
|
798
|
+
const t = new V(0, 0, 0);
|
|
799
|
+
for (let n = 0; n < e.length; n++) {
|
|
800
|
+
const r = e[n], s = e[(n + 1) % e.length];
|
|
801
|
+
t.x += (r.y - s.y) * (r.z + s.z), t.y += (r.z - s.z) * (r.x + s.x), t.z += (r.x - s.x) * (r.y + s.y);
|
|
802
|
+
}
|
|
803
|
+
return t.normalize(), t;
|
|
804
|
+
}
|
|
805
|
+
getNormalTangentAndBitangent(e) {
|
|
806
|
+
const t = this.getNormalNewell(e), r = (Math.abs(t.z) > 0.5 ? new V(0, 1, 0) : new V(0, 0, 1)).cross(t).normalize(), s = t.clone().cross(r).normalize();
|
|
807
|
+
return {
|
|
808
|
+
normal: t,
|
|
809
|
+
tangent: r,
|
|
810
|
+
bitangent: s
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
flattenVertex(e, t, n) {
|
|
814
|
+
return new Qe(
|
|
815
|
+
e.dot(t),
|
|
816
|
+
e.dot(n)
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
// Generate data for a single face in a geometry. If the face is a quad then split it into 2 tris
|
|
820
|
+
genFace(e, t, n, r, s, a, o, l, p, f) {
|
|
821
|
+
let u;
|
|
822
|
+
if (f > 3) {
|
|
823
|
+
const c = [], h = t.baseVertexPositions || t.vertexPositions;
|
|
824
|
+
for (let T = 0; T < n.length; T += 3)
|
|
825
|
+
c.push(
|
|
826
|
+
new V(
|
|
827
|
+
h[n[T]],
|
|
828
|
+
h[n[T + 1]],
|
|
829
|
+
h[n[T + 2]]
|
|
830
|
+
)
|
|
831
|
+
);
|
|
832
|
+
const { tangent: m, bitangent: g } = this.getNormalTangentAndBitangent(c), d = [];
|
|
833
|
+
for (const T of c)
|
|
834
|
+
d.push(this.flattenVertex(T, m, g));
|
|
835
|
+
u = Je.triangulateShape(d, []);
|
|
836
|
+
} else
|
|
837
|
+
u = [[0, 1, 2]];
|
|
838
|
+
for (const [c, h, m] of u)
|
|
839
|
+
e.vertex.push(t.vertexPositions[n[c * 3]]), e.vertex.push(t.vertexPositions[n[c * 3 + 1]]), e.vertex.push(t.vertexPositions[n[c * 3 + 2]]), e.vertex.push(t.vertexPositions[n[h * 3]]), e.vertex.push(t.vertexPositions[n[h * 3 + 1]]), e.vertex.push(t.vertexPositions[n[h * 3 + 2]]), e.vertex.push(t.vertexPositions[n[m * 3]]), e.vertex.push(t.vertexPositions[n[m * 3 + 1]]), e.vertex.push(t.vertexPositions[n[m * 3 + 2]]), t.skeleton && (e.vertexWeights.push(l[c * 4]), e.vertexWeights.push(l[c * 4 + 1]), e.vertexWeights.push(l[c * 4 + 2]), e.vertexWeights.push(l[c * 4 + 3]), e.vertexWeights.push(l[h * 4]), e.vertexWeights.push(l[h * 4 + 1]), e.vertexWeights.push(l[h * 4 + 2]), e.vertexWeights.push(l[h * 4 + 3]), e.vertexWeights.push(l[m * 4]), e.vertexWeights.push(l[m * 4 + 1]), e.vertexWeights.push(l[m * 4 + 2]), e.vertexWeights.push(l[m * 4 + 3]), e.weightsIndices.push(p[c * 4]), e.weightsIndices.push(p[c * 4 + 1]), e.weightsIndices.push(p[c * 4 + 2]), e.weightsIndices.push(p[c * 4 + 3]), e.weightsIndices.push(p[h * 4]), e.weightsIndices.push(p[h * 4 + 1]), e.weightsIndices.push(p[h * 4 + 2]), e.weightsIndices.push(p[h * 4 + 3]), e.weightsIndices.push(p[m * 4]), e.weightsIndices.push(p[m * 4 + 1]), e.weightsIndices.push(p[m * 4 + 2]), e.weightsIndices.push(p[m * 4 + 3])), t.color && (e.colors.push(a[c * 3]), e.colors.push(a[c * 3 + 1]), e.colors.push(a[c * 3 + 2]), e.colors.push(a[h * 3]), e.colors.push(a[h * 3 + 1]), e.colors.push(a[h * 3 + 2]), e.colors.push(a[m * 3]), e.colors.push(a[m * 3 + 1]), e.colors.push(a[m * 3 + 2])), t.material && t.material.mappingType !== "AllSame" && (e.materialIndex.push(r), e.materialIndex.push(r), e.materialIndex.push(r)), t.normal && (e.normal.push(s[c * 3]), e.normal.push(s[c * 3 + 1]), e.normal.push(s[c * 3 + 2]), e.normal.push(s[h * 3]), e.normal.push(s[h * 3 + 1]), e.normal.push(s[h * 3 + 2]), e.normal.push(s[m * 3]), e.normal.push(s[m * 3 + 1]), e.normal.push(s[m * 3 + 2])), t.uv && t.uv.forEach(function(g, d) {
|
|
840
|
+
e.uvs[d] === void 0 && (e.uvs[d] = []), e.uvs[d].push(o[d][c * 2]), e.uvs[d].push(o[d][c * 2 + 1]), e.uvs[d].push(o[d][h * 2]), e.uvs[d].push(o[d][h * 2 + 1]), e.uvs[d].push(o[d][m * 2]), e.uvs[d].push(o[d][m * 2 + 1]);
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
addMorphTargets(e, t, n, r) {
|
|
844
|
+
if (n.length === 0) return;
|
|
845
|
+
e.morphTargetsRelative = !0, e.morphAttributes.position = [];
|
|
846
|
+
const s = this;
|
|
847
|
+
n.forEach(function(a) {
|
|
848
|
+
a.rawTargets.forEach(function(o) {
|
|
849
|
+
const l = C.Objects.Geometry[o.geoID];
|
|
850
|
+
l !== void 0 && s.genMorphGeometry(e, t, l, r, o.name);
|
|
851
|
+
});
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
// a morph geometry node is similar to a standard node, and the node is also contained
|
|
855
|
+
// in FBXTree.Objects.Geometry, however it can only have attributes for position, normal
|
|
856
|
+
// and a special attribute Index defining which vertices of the original geometry are affected
|
|
857
|
+
// Normal and position attributes only have data for the vertices that are affected by the morph
|
|
858
|
+
genMorphGeometry(e, t, n, r, s) {
|
|
859
|
+
const a = t.Vertices !== void 0 ? t.Vertices.a : [], o = t.PolygonVertexIndex !== void 0 ? t.PolygonVertexIndex.a : [], l = n.Vertices !== void 0 ? n.Vertices.a : [], p = n.Indexes !== void 0 ? n.Indexes.a : [], f = e.attributes.position.count * 3, u = new Float32Array(f);
|
|
860
|
+
for (let g = 0; g < p.length; g++) {
|
|
861
|
+
const d = p[g] * 3;
|
|
862
|
+
u[d] = l[g * 3], u[d + 1] = l[g * 3 + 1], u[d + 2] = l[g * 3 + 2];
|
|
863
|
+
}
|
|
864
|
+
const c = {
|
|
865
|
+
vertexIndices: o,
|
|
866
|
+
vertexPositions: u,
|
|
867
|
+
baseVertexPositions: a
|
|
868
|
+
}, h = this.genBuffers(c), m = new j(h.vertex, 3);
|
|
869
|
+
m.name = s || n.attrName, m.applyMatrix4(r), e.morphAttributes.position.push(m);
|
|
870
|
+
}
|
|
871
|
+
// Parse normal from FBXTree.Objects.Geometry.LayerElementNormal if it exists
|
|
872
|
+
parseNormals(e) {
|
|
873
|
+
const t = e.MappingInformationType, n = e.ReferenceInformationType, r = e.Normals.a;
|
|
874
|
+
let s = [];
|
|
875
|
+
return n === "IndexToDirect" && ("NormalIndex" in e ? s = e.NormalIndex.a : "NormalsIndex" in e && (s = e.NormalsIndex.a)), {
|
|
876
|
+
dataSize: 3,
|
|
877
|
+
buffer: r,
|
|
878
|
+
indices: s,
|
|
879
|
+
mappingType: t,
|
|
880
|
+
referenceType: n
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
// Parse UVs from FBXTree.Objects.Geometry.LayerElementUV if it exists
|
|
884
|
+
parseUVs(e) {
|
|
885
|
+
const t = e.MappingInformationType, n = e.ReferenceInformationType, r = e.UV.a;
|
|
886
|
+
let s = [];
|
|
887
|
+
return n === "IndexToDirect" && (s = e.UVIndex.a), {
|
|
888
|
+
dataSize: 2,
|
|
889
|
+
buffer: r,
|
|
890
|
+
indices: s,
|
|
891
|
+
mappingType: t,
|
|
892
|
+
referenceType: n
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
// Parse Vertex Colors from FBXTree.Objects.Geometry.LayerElementColor if it exists
|
|
896
|
+
parseVertexColors(e) {
|
|
897
|
+
const t = e.MappingInformationType, n = e.ReferenceInformationType, r = e.Colors.a;
|
|
898
|
+
let s = [];
|
|
899
|
+
n === "IndexToDirect" && (s = e.ColorIndex.a);
|
|
900
|
+
for (let a = 0, o = new k(); a < r.length; a += 4)
|
|
901
|
+
o.fromArray(r, a), N.colorSpaceToWorking(o, X), o.toArray(r, a);
|
|
902
|
+
return {
|
|
903
|
+
dataSize: 4,
|
|
904
|
+
buffer: r,
|
|
905
|
+
indices: s,
|
|
906
|
+
mappingType: t,
|
|
907
|
+
referenceType: n
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
// Parse mapping and material data in FBXTree.Objects.Geometry.LayerElementMaterial if it exists
|
|
911
|
+
parseMaterialIndices(e) {
|
|
912
|
+
const t = e.MappingInformationType, n = e.ReferenceInformationType;
|
|
913
|
+
if (t === "NoMappingInformation")
|
|
914
|
+
return {
|
|
915
|
+
dataSize: 1,
|
|
916
|
+
buffer: [0],
|
|
917
|
+
indices: [0],
|
|
918
|
+
mappingType: "AllSame",
|
|
919
|
+
referenceType: n
|
|
920
|
+
};
|
|
921
|
+
const r = e.Materials.a, s = [];
|
|
922
|
+
for (let a = 0; a < r.length; ++a)
|
|
923
|
+
s.push(a);
|
|
924
|
+
return {
|
|
925
|
+
dataSize: 1,
|
|
926
|
+
buffer: r,
|
|
927
|
+
indices: s,
|
|
928
|
+
mappingType: t,
|
|
929
|
+
referenceType: n
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
// Generate a NurbGeometry from a node in FBXTree.Objects.Geometry
|
|
933
|
+
parseNurbsGeometry(e) {
|
|
934
|
+
const t = parseInt(e.Order);
|
|
935
|
+
if (isNaN(t))
|
|
936
|
+
return console.error("THREE.FBXLoader: Invalid Order %s given for geometry ID: %s", e.Order, e.id), new re();
|
|
937
|
+
const n = t - 1, r = e.KnotVector.a, s = [], a = e.Points.a;
|
|
938
|
+
for (let u = 0, c = a.length; u < c; u += 4)
|
|
939
|
+
s.push(new et().fromArray(a, u));
|
|
940
|
+
let o, l;
|
|
941
|
+
if (e.Form === "Closed")
|
|
942
|
+
s.push(s[0]);
|
|
943
|
+
else if (e.Form === "Periodic") {
|
|
944
|
+
o = n, l = r.length - 1 - o;
|
|
945
|
+
for (let u = 0; u < n; ++u)
|
|
946
|
+
s.push(s[u]);
|
|
947
|
+
}
|
|
948
|
+
const f = new dt(n, r, s, o, l).getPoints(s.length * 12);
|
|
949
|
+
return new re().setFromPoints(f);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
class Et {
|
|
953
|
+
// take raw animation clips and turn them into three.js animation clips
|
|
954
|
+
parse() {
|
|
955
|
+
const e = [], t = this.parseClips();
|
|
956
|
+
if (t !== void 0)
|
|
957
|
+
for (const n in t) {
|
|
958
|
+
const r = t[n], s = this.addClip(r);
|
|
959
|
+
e.push(s);
|
|
960
|
+
}
|
|
961
|
+
return e;
|
|
962
|
+
}
|
|
963
|
+
parseClips() {
|
|
964
|
+
if (C.Objects.AnimationCurve === void 0) return;
|
|
965
|
+
const e = this.parseAnimationCurveNodes();
|
|
966
|
+
this.parseAnimationCurves(e);
|
|
967
|
+
const t = this.parseAnimationLayers(e);
|
|
968
|
+
return this.parseAnimStacks(t);
|
|
969
|
+
}
|
|
970
|
+
// parse nodes in FBXTree.Objects.AnimationCurveNode
|
|
971
|
+
// each AnimationCurveNode holds data for an animation transform for a model (e.g. left arm rotation )
|
|
972
|
+
// and is referenced by an AnimationLayer
|
|
973
|
+
parseAnimationCurveNodes() {
|
|
974
|
+
const e = C.Objects.AnimationCurveNode, t = /* @__PURE__ */ new Map();
|
|
975
|
+
for (const n in e) {
|
|
976
|
+
const r = e[n];
|
|
977
|
+
if (r.attrName.match(/S|R|T|DeformPercent/) !== null) {
|
|
978
|
+
const s = {
|
|
979
|
+
id: r.id,
|
|
980
|
+
attr: r.attrName,
|
|
981
|
+
curves: {}
|
|
982
|
+
};
|
|
983
|
+
t.set(s.id, s);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
return t;
|
|
987
|
+
}
|
|
988
|
+
// parse nodes in FBXTree.Objects.AnimationCurve and connect them up to
|
|
989
|
+
// previously parsed AnimationCurveNodes. Each AnimationCurve holds data for a single animated
|
|
990
|
+
// axis ( e.g. times and values of x rotation)
|
|
991
|
+
parseAnimationCurves(e) {
|
|
992
|
+
const t = C.Objects.AnimationCurve;
|
|
993
|
+
for (const n in t) {
|
|
994
|
+
const r = {
|
|
995
|
+
id: t[n].id,
|
|
996
|
+
times: t[n].KeyTime.a.map(It),
|
|
997
|
+
values: t[n].KeyValueFloat.a
|
|
998
|
+
}, s = O.get(r.id);
|
|
999
|
+
if (s !== void 0) {
|
|
1000
|
+
const a = s.parents[0].ID, o = s.parents[0].relationship;
|
|
1001
|
+
o.match(/X/) ? e.get(a).curves.x = r : o.match(/Y/) ? e.get(a).curves.y = r : o.match(/Z/) ? e.get(a).curves.z = r : o.match(/DeformPercent/) && e.has(a) && (e.get(a).curves.morph = r);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
// parse nodes in FBXTree.Objects.AnimationLayer. Each layers holds references
|
|
1006
|
+
// to various AnimationCurveNodes and is referenced by an AnimationStack node
|
|
1007
|
+
// note: theoretically a stack can have multiple layers, however in practice there always seems to be one per stack
|
|
1008
|
+
parseAnimationLayers(e) {
|
|
1009
|
+
const t = C.Objects.AnimationLayer, n = /* @__PURE__ */ new Map();
|
|
1010
|
+
for (const r in t) {
|
|
1011
|
+
const s = [], a = O.get(parseInt(r));
|
|
1012
|
+
a !== void 0 && (a.children.forEach(function(l, p) {
|
|
1013
|
+
if (e.has(l.ID)) {
|
|
1014
|
+
const f = e.get(l.ID);
|
|
1015
|
+
if (f.curves.x !== void 0 || f.curves.y !== void 0 || f.curves.z !== void 0) {
|
|
1016
|
+
if (s[p] === void 0) {
|
|
1017
|
+
const u = O.get(l.ID).parents.filter(function(c) {
|
|
1018
|
+
return c.relationship !== void 0;
|
|
1019
|
+
})[0].ID;
|
|
1020
|
+
if (u !== void 0) {
|
|
1021
|
+
const c = C.Objects.Model[u.toString()];
|
|
1022
|
+
if (c === void 0) {
|
|
1023
|
+
console.warn("THREE.FBXLoader: Encountered a unused curve.", l);
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
const h = {
|
|
1027
|
+
modelName: c.attrName ? ee.sanitizeNodeName(c.attrName) : "",
|
|
1028
|
+
ID: c.id,
|
|
1029
|
+
initialPosition: [0, 0, 0],
|
|
1030
|
+
initialRotation: [0, 0, 0],
|
|
1031
|
+
initialScale: [1, 1, 1]
|
|
1032
|
+
};
|
|
1033
|
+
U.traverse(function(m) {
|
|
1034
|
+
m.ID === c.id && (h.transform = m.matrix, m.userData.transformData && (h.eulerOrder = m.userData.transformData.eulerOrder));
|
|
1035
|
+
}), h.transform || (h.transform = new L()), "PreRotation" in c && (h.preRotation = c.PreRotation.value), "PostRotation" in c && (h.postRotation = c.PostRotation.value), s[p] = h;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
s[p] && (s[p][f.attr] = f);
|
|
1039
|
+
} else if (f.curves.morph !== void 0) {
|
|
1040
|
+
if (s[p] === void 0) {
|
|
1041
|
+
const u = O.get(l.ID).parents.filter(function(T) {
|
|
1042
|
+
return T.relationship !== void 0;
|
|
1043
|
+
})[0].ID, c = O.get(u).parents[0].ID, h = O.get(c).parents[0].ID, m = O.get(h).parents[0].ID, g = C.Objects.Model[m], d = {
|
|
1044
|
+
modelName: g.attrName ? ee.sanitizeNodeName(g.attrName) : "",
|
|
1045
|
+
morphName: C.Objects.Deformer[u].attrName
|
|
1046
|
+
};
|
|
1047
|
+
s[p] = d;
|
|
1048
|
+
}
|
|
1049
|
+
s[p][f.attr] = f;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
}), n.set(parseInt(r), s));
|
|
1053
|
+
}
|
|
1054
|
+
return n;
|
|
1055
|
+
}
|
|
1056
|
+
// parse nodes in FBXTree.Objects.AnimationStack. These are the top level node in the animation
|
|
1057
|
+
// hierarchy. Each Stack node will be used to create an AnimationClip
|
|
1058
|
+
parseAnimStacks(e) {
|
|
1059
|
+
const t = C.Objects.AnimationStack, n = {};
|
|
1060
|
+
for (const r in t) {
|
|
1061
|
+
const s = O.get(parseInt(r)).children;
|
|
1062
|
+
s.length > 1 && console.warn("THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.");
|
|
1063
|
+
const a = e.get(s[0].ID);
|
|
1064
|
+
n[r] = {
|
|
1065
|
+
name: t[r].attrName,
|
|
1066
|
+
layer: a
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
return n;
|
|
1070
|
+
}
|
|
1071
|
+
addClip(e) {
|
|
1072
|
+
let t = [];
|
|
1073
|
+
const n = this;
|
|
1074
|
+
return e.layer.forEach(function(r) {
|
|
1075
|
+
t = t.concat(n.generateTracks(r));
|
|
1076
|
+
}), new tt(e.name, -1, t);
|
|
1077
|
+
}
|
|
1078
|
+
generateTracks(e) {
|
|
1079
|
+
const t = [];
|
|
1080
|
+
let n = new V(), r = new V();
|
|
1081
|
+
if (e.transform && e.transform.decompose(n, new G(), r), n = n.toArray(), r = r.toArray(), e.T !== void 0 && Object.keys(e.T.curves).length > 0) {
|
|
1082
|
+
const s = this.generateVectorTrack(e.modelName, e.T.curves, n, "position");
|
|
1083
|
+
s !== void 0 && t.push(s);
|
|
1084
|
+
}
|
|
1085
|
+
if (e.R !== void 0 && Object.keys(e.R.curves).length > 0) {
|
|
1086
|
+
const s = this.generateRotationTrack(e.modelName, e.R.curves, e.preRotation, e.postRotation, e.eulerOrder);
|
|
1087
|
+
s !== void 0 && t.push(s);
|
|
1088
|
+
}
|
|
1089
|
+
if (e.S !== void 0 && Object.keys(e.S.curves).length > 0) {
|
|
1090
|
+
const s = this.generateVectorTrack(e.modelName, e.S.curves, r, "scale");
|
|
1091
|
+
s !== void 0 && t.push(s);
|
|
1092
|
+
}
|
|
1093
|
+
if (e.DeformPercent !== void 0) {
|
|
1094
|
+
const s = this.generateMorphTrack(e);
|
|
1095
|
+
s !== void 0 && t.push(s);
|
|
1096
|
+
}
|
|
1097
|
+
return t;
|
|
1098
|
+
}
|
|
1099
|
+
generateVectorTrack(e, t, n, r) {
|
|
1100
|
+
const s = this.getTimesForAllAxes(t), a = this.getKeyframeTrackValues(s, t, n);
|
|
1101
|
+
return new nt(e + "." + r, s, a);
|
|
1102
|
+
}
|
|
1103
|
+
generateRotationTrack(e, t, n, r, s) {
|
|
1104
|
+
let a, o;
|
|
1105
|
+
if (t.x !== void 0 && t.y !== void 0 && t.z !== void 0) {
|
|
1106
|
+
const c = this.interpolateRotations(t.x, t.y, t.z, s);
|
|
1107
|
+
a = c[0], o = c[1];
|
|
1108
|
+
}
|
|
1109
|
+
const l = q(0);
|
|
1110
|
+
n !== void 0 && (n = n.map(B.degToRad), n.push(l), n = new z().fromArray(n), n = new G().setFromEuler(n)), r !== void 0 && (r = r.map(B.degToRad), r.push(l), r = new z().fromArray(r), r = new G().setFromEuler(r).invert());
|
|
1111
|
+
const p = new G(), f = new z(), u = [];
|
|
1112
|
+
if (!o || !a) return new de(e + ".quaternion", [0], [0]);
|
|
1113
|
+
for (let c = 0; c < o.length; c += 3)
|
|
1114
|
+
f.set(o[c], o[c + 1], o[c + 2], s), p.setFromEuler(f), n !== void 0 && p.premultiply(n), r !== void 0 && p.multiply(r), c > 2 && new G().fromArray(
|
|
1115
|
+
u,
|
|
1116
|
+
(c - 3) / 3 * 4
|
|
1117
|
+
).dot(p) < 0 && p.set(-p.x, -p.y, -p.z, -p.w), p.toArray(u, c / 3 * 4);
|
|
1118
|
+
return new de(e + ".quaternion", a, u);
|
|
1119
|
+
}
|
|
1120
|
+
generateMorphTrack(e) {
|
|
1121
|
+
const t = e.DeformPercent.curves.morph, n = t.values.map(function(s) {
|
|
1122
|
+
return s / 100;
|
|
1123
|
+
}), r = U.getObjectByName(e.modelName).morphTargetDictionary[e.morphName];
|
|
1124
|
+
return new rt(e.modelName + ".morphTargetInfluences[" + r + "]", t.times, n);
|
|
1125
|
+
}
|
|
1126
|
+
// For all animated objects, times are defined separately for each axis
|
|
1127
|
+
// Here we'll combine the times into one sorted array without duplicates
|
|
1128
|
+
getTimesForAllAxes(e) {
|
|
1129
|
+
let t = [];
|
|
1130
|
+
if (e.x !== void 0 && (t = t.concat(e.x.times)), e.y !== void 0 && (t = t.concat(e.y.times)), e.z !== void 0 && (t = t.concat(e.z.times)), t = t.sort(function(n, r) {
|
|
1131
|
+
return n - r;
|
|
1132
|
+
}), t.length > 1) {
|
|
1133
|
+
let n = 1, r = t[0];
|
|
1134
|
+
for (let s = 1; s < t.length; s++) {
|
|
1135
|
+
const a = t[s];
|
|
1136
|
+
a !== r && (t[n] = a, r = a, n++);
|
|
1137
|
+
}
|
|
1138
|
+
t = t.slice(0, n);
|
|
1139
|
+
}
|
|
1140
|
+
return t;
|
|
1141
|
+
}
|
|
1142
|
+
getKeyframeTrackValues(e, t, n) {
|
|
1143
|
+
const r = n, s = [];
|
|
1144
|
+
let a = -1, o = -1, l = -1;
|
|
1145
|
+
return e.forEach(function(p) {
|
|
1146
|
+
if (t.x && (a = t.x.times.indexOf(p)), t.y && (o = t.y.times.indexOf(p)), t.z && (l = t.z.times.indexOf(p)), a !== -1) {
|
|
1147
|
+
const f = t.x.values[a];
|
|
1148
|
+
s.push(f), r[0] = f;
|
|
1149
|
+
} else
|
|
1150
|
+
s.push(r[0]);
|
|
1151
|
+
if (o !== -1) {
|
|
1152
|
+
const f = t.y.values[o];
|
|
1153
|
+
s.push(f), r[1] = f;
|
|
1154
|
+
} else
|
|
1155
|
+
s.push(r[1]);
|
|
1156
|
+
if (l !== -1) {
|
|
1157
|
+
const f = t.z.values[l];
|
|
1158
|
+
s.push(f), r[2] = f;
|
|
1159
|
+
} else
|
|
1160
|
+
s.push(r[2]);
|
|
1161
|
+
}), s;
|
|
1162
|
+
}
|
|
1163
|
+
// Rotations are defined as Euler angles which can have values of any size
|
|
1164
|
+
// These will be converted to quaternions which don't support values greater than
|
|
1165
|
+
// PI, so we'll interpolate large rotations
|
|
1166
|
+
interpolateRotations(e, t, n, r) {
|
|
1167
|
+
const s = [], a = [];
|
|
1168
|
+
s.push(e.times[0]), a.push(B.degToRad(e.values[0])), a.push(B.degToRad(t.values[0])), a.push(B.degToRad(n.values[0]));
|
|
1169
|
+
for (let o = 1; o < e.values.length; o++) {
|
|
1170
|
+
const l = [
|
|
1171
|
+
e.values[o - 1],
|
|
1172
|
+
t.values[o - 1],
|
|
1173
|
+
n.values[o - 1]
|
|
1174
|
+
];
|
|
1175
|
+
if (isNaN(l[0]) || isNaN(l[1]) || isNaN(l[2]))
|
|
1176
|
+
continue;
|
|
1177
|
+
const p = l.map(B.degToRad), f = [
|
|
1178
|
+
e.values[o],
|
|
1179
|
+
t.values[o],
|
|
1180
|
+
n.values[o]
|
|
1181
|
+
];
|
|
1182
|
+
if (isNaN(f[0]) || isNaN(f[1]) || isNaN(f[2]))
|
|
1183
|
+
continue;
|
|
1184
|
+
const u = f.map(B.degToRad), c = [
|
|
1185
|
+
f[0] - l[0],
|
|
1186
|
+
f[1] - l[1],
|
|
1187
|
+
f[2] - l[2]
|
|
1188
|
+
], h = [
|
|
1189
|
+
Math.abs(c[0]),
|
|
1190
|
+
Math.abs(c[1]),
|
|
1191
|
+
Math.abs(c[2])
|
|
1192
|
+
];
|
|
1193
|
+
if (h[0] >= 180 || h[1] >= 180 || h[2] >= 180) {
|
|
1194
|
+
const g = Math.max(...h) / 180, d = new z(...p, r), T = new z(...u, r), F = new G().setFromEuler(d), y = new G().setFromEuler(T);
|
|
1195
|
+
F.dot(y) && y.set(-y.x, -y.y, -y.z, -y.w);
|
|
1196
|
+
const x = e.times[o - 1], I = e.times[o] - x, A = new G(), M = new z();
|
|
1197
|
+
for (let v = 0; v < 1; v += 1 / g)
|
|
1198
|
+
A.copy(F.clone().slerp(y.clone(), v)), s.push(x + v * I), M.setFromQuaternion(A, r), a.push(M.x), a.push(M.y), a.push(M.z);
|
|
1199
|
+
} else
|
|
1200
|
+
s.push(e.times[o]), a.push(B.degToRad(e.values[o])), a.push(B.degToRad(t.values[o])), a.push(B.degToRad(n.values[o]));
|
|
1201
|
+
}
|
|
1202
|
+
return [s, a];
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
class bt {
|
|
1206
|
+
getPrevNode() {
|
|
1207
|
+
return this.nodeStack[this.currentIndent - 2];
|
|
1208
|
+
}
|
|
1209
|
+
getCurrentNode() {
|
|
1210
|
+
return this.nodeStack[this.currentIndent - 1];
|
|
1211
|
+
}
|
|
1212
|
+
getCurrentProp() {
|
|
1213
|
+
return this.currentProp;
|
|
1214
|
+
}
|
|
1215
|
+
pushStack(e) {
|
|
1216
|
+
this.nodeStack.push(e), this.currentIndent += 1;
|
|
1217
|
+
}
|
|
1218
|
+
popStack() {
|
|
1219
|
+
this.nodeStack.pop(), this.currentIndent -= 1;
|
|
1220
|
+
}
|
|
1221
|
+
setCurrentProp(e, t) {
|
|
1222
|
+
this.currentProp = e, this.currentPropName = t;
|
|
1223
|
+
}
|
|
1224
|
+
parse(e) {
|
|
1225
|
+
this.currentIndent = 0, this.allNodes = new Pe(), this.nodeStack = [], this.currentProp = [], this.currentPropName = "";
|
|
1226
|
+
const t = this, n = e.split(/[\r\n]+/);
|
|
1227
|
+
return n.forEach(function(r, s) {
|
|
1228
|
+
const a = r.match(/^[\s\t]*;/), o = r.match(/^[\s\t]*$/);
|
|
1229
|
+
if (a || o) return;
|
|
1230
|
+
const l = r.match("^\\t{" + t.currentIndent + "}(\\w+):(.*){", ""), p = r.match("^\\t{" + t.currentIndent + "}(\\w+):[\\s\\t\\r\\n](.*)"), f = r.match("^\\t{" + (t.currentIndent - 1) + "}}");
|
|
1231
|
+
l ? t.parseNodeBegin(r, l) : p ? t.parseNodeProperty(r, p, n[++s]) : f ? t.popStack() : r.match(/^[^\s\t}]/) && t.parseNodePropertyContinued(r);
|
|
1232
|
+
}), this.allNodes;
|
|
1233
|
+
}
|
|
1234
|
+
parseNodeBegin(e, t) {
|
|
1235
|
+
const n = t[1].trim().replace(/^"/, "").replace(/"$/, ""), r = t[2].split(",").map(function(l) {
|
|
1236
|
+
return l.trim().replace(/^"/, "").replace(/"$/, "");
|
|
1237
|
+
}), s = { name: n }, a = this.parseNodeAttr(r), o = this.getCurrentNode();
|
|
1238
|
+
this.currentIndent === 0 ? this.allNodes.add(n, s) : n in o ? (n === "PoseNode" ? o.PoseNode.push(s) : o[n].id !== void 0 && (o[n] = {}, o[n][o[n].id] = o[n]), a.id !== "" && (o[n][a.id] = s)) : typeof a.id == "number" ? (o[n] = {}, o[n][a.id] = s) : n !== "Properties70" && (n === "PoseNode" ? o[n] = [s] : o[n] = s), typeof a.id == "number" && (s.id = a.id), a.name !== "" && (s.attrName = a.name), a.type !== "" && (s.attrType = a.type), this.pushStack(s);
|
|
1239
|
+
}
|
|
1240
|
+
parseNodeAttr(e) {
|
|
1241
|
+
let t = e[0];
|
|
1242
|
+
e[0] !== "" && (t = parseInt(e[0]), isNaN(t) && (t = e[0]));
|
|
1243
|
+
let n = "", r = "";
|
|
1244
|
+
return e.length > 1 && (n = e[1].replace(/^(\w+)::/, ""), r = e[2]), { id: t, name: n, type: r };
|
|
1245
|
+
}
|
|
1246
|
+
parseNodeProperty(e, t, n) {
|
|
1247
|
+
let r = t[1].replace(/^"/, "").replace(/"$/, "").trim(), s = t[2].replace(/^"/, "").replace(/"$/, "").trim();
|
|
1248
|
+
r === "Content" && s === "," && (s = n.replace(/"/g, "").replace(/,$/, "").trim());
|
|
1249
|
+
const a = this.getCurrentNode();
|
|
1250
|
+
if (a.name === "Properties70") {
|
|
1251
|
+
this.parseNodeSpecialProperty(e, r, s);
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
if (r === "C") {
|
|
1255
|
+
const l = s.split(",").slice(1), p = parseInt(l[0]), f = parseInt(l[1]);
|
|
1256
|
+
let u = s.split(",").slice(3);
|
|
1257
|
+
u = u.map(function(c) {
|
|
1258
|
+
return c.trim().replace(/^"/, "");
|
|
1259
|
+
}), r = "connections", s = [p, f], Dt(s, u), a[r] === void 0 && (a[r] = []);
|
|
1260
|
+
}
|
|
1261
|
+
r === "Node" && (a.id = s), r in a && Array.isArray(a[r]) ? a[r].push(s) : r !== "a" ? a[r] = s : a.a = s, this.setCurrentProp(a, r), r === "a" && s.slice(-1) !== "," && (a.a = ae(s));
|
|
1262
|
+
}
|
|
1263
|
+
parseNodePropertyContinued(e) {
|
|
1264
|
+
const t = this.getCurrentNode();
|
|
1265
|
+
t.a += e, e.slice(-1) !== "," && (t.a = ae(t.a));
|
|
1266
|
+
}
|
|
1267
|
+
// parse "Property70"
|
|
1268
|
+
parseNodeSpecialProperty(e, t, n) {
|
|
1269
|
+
const r = n.split('",').map(function(f) {
|
|
1270
|
+
return f.trim().replace(/^\"/, "").replace(/\s/, "_");
|
|
1271
|
+
}), s = r[0], a = r[1], o = r[2], l = r[3];
|
|
1272
|
+
let p = r[4];
|
|
1273
|
+
switch (a) {
|
|
1274
|
+
case "int":
|
|
1275
|
+
case "enum":
|
|
1276
|
+
case "bool":
|
|
1277
|
+
case "ULongLong":
|
|
1278
|
+
case "double":
|
|
1279
|
+
case "Number":
|
|
1280
|
+
case "FieldOfView":
|
|
1281
|
+
p = parseFloat(p);
|
|
1282
|
+
break;
|
|
1283
|
+
case "Color":
|
|
1284
|
+
case "ColorRGB":
|
|
1285
|
+
case "Vector3D":
|
|
1286
|
+
case "Lcl_Translation":
|
|
1287
|
+
case "Lcl_Rotation":
|
|
1288
|
+
case "Lcl_Scaling":
|
|
1289
|
+
p = ae(p);
|
|
1290
|
+
break;
|
|
1291
|
+
}
|
|
1292
|
+
this.getPrevNode()[s] = {
|
|
1293
|
+
type: a,
|
|
1294
|
+
type2: o,
|
|
1295
|
+
flag: l,
|
|
1296
|
+
value: p
|
|
1297
|
+
}, this.setCurrentProp(this.getPrevNode(), s);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
class Mt {
|
|
1301
|
+
parse(e) {
|
|
1302
|
+
const t = new Te(e);
|
|
1303
|
+
t.skip(23);
|
|
1304
|
+
const n = t.getUint32();
|
|
1305
|
+
if (n < 6400)
|
|
1306
|
+
throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: " + n);
|
|
1307
|
+
const r = new Pe();
|
|
1308
|
+
for (; !this.endOfContent(t); ) {
|
|
1309
|
+
const s = this.parseNode(t, n);
|
|
1310
|
+
s !== null && r.add(s.name, s);
|
|
1311
|
+
}
|
|
1312
|
+
return r;
|
|
1313
|
+
}
|
|
1314
|
+
// Check if reader has reached the end of content.
|
|
1315
|
+
endOfContent(e) {
|
|
1316
|
+
return e.size() % 16 === 0 ? (e.getOffset() + 160 + 16 & -16) >= e.size() : e.getOffset() + 160 + 16 >= e.size();
|
|
1317
|
+
}
|
|
1318
|
+
// recursively parse nodes until the end of the file is reached
|
|
1319
|
+
parseNode(e, t) {
|
|
1320
|
+
const n = {}, r = t >= 7500 ? e.getUint64() : e.getUint32(), s = t >= 7500 ? e.getUint64() : e.getUint32();
|
|
1321
|
+
t >= 7500 ? e.getUint64() : e.getUint32();
|
|
1322
|
+
const a = e.getUint8(), o = e.getString(a);
|
|
1323
|
+
if (r === 0) return null;
|
|
1324
|
+
const l = [];
|
|
1325
|
+
for (let c = 0; c < s; c++)
|
|
1326
|
+
l.push(this.parseProperty(e));
|
|
1327
|
+
const p = l.length > 0 ? l[0] : "", f = l.length > 1 ? l[1] : "", u = l.length > 2 ? l[2] : "";
|
|
1328
|
+
for (n.singleProperty = s === 1 && e.getOffset() === r; r > e.getOffset(); ) {
|
|
1329
|
+
const c = this.parseNode(e, t);
|
|
1330
|
+
c !== null && this.parseSubNode(o, n, c);
|
|
1331
|
+
}
|
|
1332
|
+
return n.propertyList = l, typeof p == "number" && (n.id = p), f !== "" && (n.attrName = f), u !== "" && (n.attrType = u), o !== "" && (n.name = o), n;
|
|
1333
|
+
}
|
|
1334
|
+
parseSubNode(e, t, n) {
|
|
1335
|
+
if (n.singleProperty === !0) {
|
|
1336
|
+
const r = n.propertyList[0];
|
|
1337
|
+
Array.isArray(r) ? (t[n.name] = n, n.a = r) : t[n.name] = r;
|
|
1338
|
+
} else if (e === "Connections" && n.name === "C") {
|
|
1339
|
+
const r = [];
|
|
1340
|
+
n.propertyList.forEach(function(s, a) {
|
|
1341
|
+
a !== 0 && r.push(s);
|
|
1342
|
+
}), t.connections === void 0 && (t.connections = []), t.connections.push(r);
|
|
1343
|
+
} else if (n.name === "Properties70")
|
|
1344
|
+
Object.keys(n).forEach(function(s) {
|
|
1345
|
+
t[s] = n[s];
|
|
1346
|
+
});
|
|
1347
|
+
else if (e === "Properties70" && n.name === "P") {
|
|
1348
|
+
let r = n.propertyList[0], s = n.propertyList[1];
|
|
1349
|
+
const a = n.propertyList[2], o = n.propertyList[3];
|
|
1350
|
+
let l;
|
|
1351
|
+
r.indexOf("Lcl ") === 0 && (r = r.replace("Lcl ", "Lcl_")), s.indexOf("Lcl ") === 0 && (s = s.replace("Lcl ", "Lcl_")), s === "Color" || s === "ColorRGB" || s === "Vector" || s === "Vector3D" || s.indexOf("Lcl_") === 0 ? l = [
|
|
1352
|
+
n.propertyList[4],
|
|
1353
|
+
n.propertyList[5],
|
|
1354
|
+
n.propertyList[6]
|
|
1355
|
+
] : l = n.propertyList[4], t[r] = {
|
|
1356
|
+
type: s,
|
|
1357
|
+
type2: a,
|
|
1358
|
+
flag: o,
|
|
1359
|
+
value: l
|
|
1360
|
+
};
|
|
1361
|
+
} else t[n.name] === void 0 ? typeof n.id == "number" ? (t[n.name] = {}, t[n.name][n.id] = n) : t[n.name] = n : n.name === "PoseNode" ? (Array.isArray(t[n.name]) || (t[n.name] = [t[n.name]]), t[n.name].push(n)) : t[n.name][n.id] === void 0 && (t[n.name][n.id] = n);
|
|
1362
|
+
}
|
|
1363
|
+
parseProperty(e) {
|
|
1364
|
+
const t = e.getString(1);
|
|
1365
|
+
let n;
|
|
1366
|
+
switch (t) {
|
|
1367
|
+
case "C":
|
|
1368
|
+
return e.getBoolean();
|
|
1369
|
+
case "D":
|
|
1370
|
+
return e.getFloat64();
|
|
1371
|
+
case "F":
|
|
1372
|
+
return e.getFloat32();
|
|
1373
|
+
case "I":
|
|
1374
|
+
return e.getInt32();
|
|
1375
|
+
case "L":
|
|
1376
|
+
return e.getInt64();
|
|
1377
|
+
case "R":
|
|
1378
|
+
return n = e.getUint32(), e.getArrayBuffer(n);
|
|
1379
|
+
case "S":
|
|
1380
|
+
return n = e.getUint32(), e.getString(n);
|
|
1381
|
+
case "Y":
|
|
1382
|
+
return e.getInt16();
|
|
1383
|
+
case "b":
|
|
1384
|
+
case "c":
|
|
1385
|
+
case "d":
|
|
1386
|
+
case "f":
|
|
1387
|
+
case "i":
|
|
1388
|
+
case "l":
|
|
1389
|
+
const r = e.getUint32(), s = e.getUint32(), a = e.getUint32();
|
|
1390
|
+
if (s === 0)
|
|
1391
|
+
switch (t) {
|
|
1392
|
+
case "b":
|
|
1393
|
+
case "c":
|
|
1394
|
+
return e.getBooleanArray(r);
|
|
1395
|
+
case "d":
|
|
1396
|
+
return e.getFloat64Array(r);
|
|
1397
|
+
case "f":
|
|
1398
|
+
return e.getFloat32Array(r);
|
|
1399
|
+
case "i":
|
|
1400
|
+
return e.getInt32Array(r);
|
|
1401
|
+
case "l":
|
|
1402
|
+
return e.getInt64Array(r);
|
|
1403
|
+
}
|
|
1404
|
+
const o = ft.unzlibSync(new Uint8Array(e.getArrayBuffer(a))), l = new Te(o.buffer);
|
|
1405
|
+
switch (t) {
|
|
1406
|
+
case "b":
|
|
1407
|
+
case "c":
|
|
1408
|
+
return l.getBooleanArray(r);
|
|
1409
|
+
case "d":
|
|
1410
|
+
return l.getFloat64Array(r);
|
|
1411
|
+
case "f":
|
|
1412
|
+
return l.getFloat32Array(r);
|
|
1413
|
+
case "i":
|
|
1414
|
+
return l.getInt32Array(r);
|
|
1415
|
+
case "l":
|
|
1416
|
+
return l.getInt64Array(r);
|
|
1417
|
+
}
|
|
1418
|
+
break;
|
|
1419
|
+
default:
|
|
1420
|
+
throw new Error("THREE.FBXLoader: Unknown property type " + t);
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
class Te {
|
|
1425
|
+
constructor(e, t) {
|
|
1426
|
+
this.dv = new DataView(e), this.offset = 0, this.littleEndian = t !== void 0 ? t : !0, this._textDecoder = new TextDecoder();
|
|
1427
|
+
}
|
|
1428
|
+
getOffset() {
|
|
1429
|
+
return this.offset;
|
|
1430
|
+
}
|
|
1431
|
+
size() {
|
|
1432
|
+
return this.dv.buffer.byteLength;
|
|
1433
|
+
}
|
|
1434
|
+
skip(e) {
|
|
1435
|
+
this.offset += e;
|
|
1436
|
+
}
|
|
1437
|
+
// seems like true/false representation depends on exporter.
|
|
1438
|
+
// true: 1 or 'Y'(=0x59), false: 0 or 'T'(=0x54)
|
|
1439
|
+
// then sees LSB.
|
|
1440
|
+
getBoolean() {
|
|
1441
|
+
return (this.getUint8() & 1) === 1;
|
|
1442
|
+
}
|
|
1443
|
+
getBooleanArray(e) {
|
|
1444
|
+
const t = [];
|
|
1445
|
+
for (let n = 0; n < e; n++)
|
|
1446
|
+
t.push(this.getBoolean());
|
|
1447
|
+
return t;
|
|
1448
|
+
}
|
|
1449
|
+
getUint8() {
|
|
1450
|
+
const e = this.dv.getUint8(this.offset);
|
|
1451
|
+
return this.offset += 1, e;
|
|
1452
|
+
}
|
|
1453
|
+
getInt16() {
|
|
1454
|
+
const e = this.dv.getInt16(this.offset, this.littleEndian);
|
|
1455
|
+
return this.offset += 2, e;
|
|
1456
|
+
}
|
|
1457
|
+
getInt32() {
|
|
1458
|
+
const e = this.dv.getInt32(this.offset, this.littleEndian);
|
|
1459
|
+
return this.offset += 4, e;
|
|
1460
|
+
}
|
|
1461
|
+
getInt32Array(e) {
|
|
1462
|
+
const t = [];
|
|
1463
|
+
for (let n = 0; n < e; n++)
|
|
1464
|
+
t.push(this.getInt32());
|
|
1465
|
+
return t;
|
|
1466
|
+
}
|
|
1467
|
+
getUint32() {
|
|
1468
|
+
const e = this.dv.getUint32(this.offset, this.littleEndian);
|
|
1469
|
+
return this.offset += 4, e;
|
|
1470
|
+
}
|
|
1471
|
+
// JavaScript doesn't support 64-bit integer so calculate this here
|
|
1472
|
+
// 1 << 32 will return 1 so using multiply operation instead here.
|
|
1473
|
+
// There's a possibility that this method returns wrong value if the value
|
|
1474
|
+
// is out of the range between Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER.
|
|
1475
|
+
// TODO: safely handle 64-bit integer
|
|
1476
|
+
getInt64() {
|
|
1477
|
+
let e, t;
|
|
1478
|
+
return this.littleEndian ? (e = this.getUint32(), t = this.getUint32()) : (t = this.getUint32(), e = this.getUint32()), t & 2147483648 ? (t = ~t & 4294967295, e = ~e & 4294967295, e === 4294967295 && (t = t + 1 & 4294967295), e = e + 1 & 4294967295, -(t * 4294967296 + e)) : t * 4294967296 + e;
|
|
1479
|
+
}
|
|
1480
|
+
getInt64Array(e) {
|
|
1481
|
+
const t = [];
|
|
1482
|
+
for (let n = 0; n < e; n++)
|
|
1483
|
+
t.push(this.getInt64());
|
|
1484
|
+
return t;
|
|
1485
|
+
}
|
|
1486
|
+
// Note: see getInt64() comment
|
|
1487
|
+
getUint64() {
|
|
1488
|
+
let e, t;
|
|
1489
|
+
return this.littleEndian ? (e = this.getUint32(), t = this.getUint32()) : (t = this.getUint32(), e = this.getUint32()), t * 4294967296 + e;
|
|
1490
|
+
}
|
|
1491
|
+
getFloat32() {
|
|
1492
|
+
const e = this.dv.getFloat32(this.offset, this.littleEndian);
|
|
1493
|
+
return this.offset += 4, e;
|
|
1494
|
+
}
|
|
1495
|
+
getFloat32Array(e) {
|
|
1496
|
+
const t = [];
|
|
1497
|
+
for (let n = 0; n < e; n++)
|
|
1498
|
+
t.push(this.getFloat32());
|
|
1499
|
+
return t;
|
|
1500
|
+
}
|
|
1501
|
+
getFloat64() {
|
|
1502
|
+
const e = this.dv.getFloat64(this.offset, this.littleEndian);
|
|
1503
|
+
return this.offset += 8, e;
|
|
1504
|
+
}
|
|
1505
|
+
getFloat64Array(e) {
|
|
1506
|
+
const t = [];
|
|
1507
|
+
for (let n = 0; n < e; n++)
|
|
1508
|
+
t.push(this.getFloat64());
|
|
1509
|
+
return t;
|
|
1510
|
+
}
|
|
1511
|
+
getArrayBuffer(e) {
|
|
1512
|
+
const t = this.dv.buffer.slice(this.offset, this.offset + e);
|
|
1513
|
+
return this.offset += e, t;
|
|
1514
|
+
}
|
|
1515
|
+
getString(e) {
|
|
1516
|
+
const t = this.offset;
|
|
1517
|
+
let n = new Uint8Array(this.dv.buffer, t, e);
|
|
1518
|
+
this.skip(e);
|
|
1519
|
+
const r = n.indexOf(0);
|
|
1520
|
+
return r >= 0 && (n = new Uint8Array(this.dv.buffer, t, r)), this._textDecoder.decode(n);
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
class Pe {
|
|
1524
|
+
add(e, t) {
|
|
1525
|
+
this[e] = t;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
function St(i) {
|
|
1529
|
+
const e = "Kaydara FBX Binary \0";
|
|
1530
|
+
return i.byteLength >= e.length && e === Le(i, 0, e.length);
|
|
1531
|
+
}
|
|
1532
|
+
function Ft(i) {
|
|
1533
|
+
const e = ["K", "a", "y", "d", "a", "r", "a", "\\", "F", "B", "X", "\\", "B", "i", "n", "a", "r", "y", "\\", "\\"];
|
|
1534
|
+
let t = 0;
|
|
1535
|
+
function n(r) {
|
|
1536
|
+
const s = i[r - 1];
|
|
1537
|
+
return i = i.slice(t + r), t++, s;
|
|
1538
|
+
}
|
|
1539
|
+
for (let r = 0; r < e.length; ++r)
|
|
1540
|
+
if (n(1) === e[r])
|
|
1541
|
+
return !1;
|
|
1542
|
+
return !0;
|
|
1543
|
+
}
|
|
1544
|
+
function xe(i) {
|
|
1545
|
+
const e = /FBXVersion: (\d+)/, t = i.match(e);
|
|
1546
|
+
if (t)
|
|
1547
|
+
return parseInt(t[1]);
|
|
1548
|
+
throw new Error("THREE.FBXLoader: Cannot find the version number for the file given.");
|
|
1549
|
+
}
|
|
1550
|
+
function It(i) {
|
|
1551
|
+
return i / 46186158e3;
|
|
1552
|
+
}
|
|
1553
|
+
const At = [];
|
|
1554
|
+
function Q(i, e, t, n) {
|
|
1555
|
+
let r;
|
|
1556
|
+
switch (n.mappingType) {
|
|
1557
|
+
case "ByPolygonVertex":
|
|
1558
|
+
r = i;
|
|
1559
|
+
break;
|
|
1560
|
+
case "ByPolygon":
|
|
1561
|
+
r = e;
|
|
1562
|
+
break;
|
|
1563
|
+
case "ByVertice":
|
|
1564
|
+
r = t;
|
|
1565
|
+
break;
|
|
1566
|
+
case "AllSame":
|
|
1567
|
+
r = n.indices[0];
|
|
1568
|
+
break;
|
|
1569
|
+
default:
|
|
1570
|
+
console.warn("THREE.FBXLoader: unknown attribute mapping type " + n.mappingType);
|
|
1571
|
+
}
|
|
1572
|
+
n.referenceType === "IndexToDirect" && (r = n.indices[r]);
|
|
1573
|
+
const s = r * n.dataSize, a = s + n.dataSize;
|
|
1574
|
+
return Rt(At, n.buffer, s, a);
|
|
1575
|
+
}
|
|
1576
|
+
const se = new z(), H = new V();
|
|
1577
|
+
function Ce(i) {
|
|
1578
|
+
const e = new L(), t = new L(), n = new L(), r = new L(), s = new L(), a = new L(), o = new L(), l = new L(), p = new L(), f = new L(), u = new L(), c = new L(), h = i.inheritType ? i.inheritType : 0;
|
|
1579
|
+
i.translation && e.setPosition(H.fromArray(i.translation));
|
|
1580
|
+
const m = q(0);
|
|
1581
|
+
if (i.preRotation) {
|
|
1582
|
+
const b = i.preRotation.map(B.degToRad);
|
|
1583
|
+
b.push(m), t.makeRotationFromEuler(se.fromArray(b));
|
|
1584
|
+
}
|
|
1585
|
+
if (i.rotation) {
|
|
1586
|
+
const b = i.rotation.map(B.degToRad);
|
|
1587
|
+
b.push(i.eulerOrder || m), n.makeRotationFromEuler(se.fromArray(b));
|
|
1588
|
+
}
|
|
1589
|
+
if (i.postRotation) {
|
|
1590
|
+
const b = i.postRotation.map(B.degToRad);
|
|
1591
|
+
b.push(m), r.makeRotationFromEuler(se.fromArray(b)), r.invert();
|
|
1592
|
+
}
|
|
1593
|
+
i.scale && s.scale(H.fromArray(i.scale)), i.scalingOffset && o.setPosition(H.fromArray(i.scalingOffset)), i.scalingPivot && a.setPosition(H.fromArray(i.scalingPivot)), i.rotationOffset && l.setPosition(H.fromArray(i.rotationOffset)), i.rotationPivot && p.setPosition(H.fromArray(i.rotationPivot)), i.parentMatrixWorld && (u.copy(i.parentMatrix), f.copy(i.parentMatrixWorld));
|
|
1594
|
+
const g = t.clone().multiply(n).multiply(r), d = new L();
|
|
1595
|
+
d.extractRotation(f);
|
|
1596
|
+
const T = new L();
|
|
1597
|
+
T.copyPosition(f);
|
|
1598
|
+
const F = T.clone().invert().multiply(f), y = d.clone().invert().multiply(F), x = s, I = new L();
|
|
1599
|
+
if (h === 0)
|
|
1600
|
+
I.copy(d).multiply(g).multiply(y).multiply(x);
|
|
1601
|
+
else if (h === 1)
|
|
1602
|
+
I.copy(d).multiply(y).multiply(g).multiply(x);
|
|
1603
|
+
else {
|
|
1604
|
+
const D = new L().scale(new V().setFromMatrixScale(u)).clone().invert(), w = y.clone().multiply(D);
|
|
1605
|
+
I.copy(d).multiply(g).multiply(w).multiply(x);
|
|
1606
|
+
}
|
|
1607
|
+
const A = p.clone().invert(), M = a.clone().invert();
|
|
1608
|
+
let v = e.clone().multiply(l).multiply(p).multiply(t).multiply(n).multiply(r).multiply(A).multiply(o).multiply(a).multiply(s).multiply(M);
|
|
1609
|
+
const S = new L().copyPosition(v), E = f.clone().multiply(S);
|
|
1610
|
+
return c.copyPosition(E), v = c.clone().multiply(I), v.premultiply(f.invert()), v;
|
|
1611
|
+
}
|
|
1612
|
+
function q(i) {
|
|
1613
|
+
i = i || 0;
|
|
1614
|
+
const e = [
|
|
1615
|
+
"ZYX",
|
|
1616
|
+
// -> XYZ extrinsic
|
|
1617
|
+
"YZX",
|
|
1618
|
+
// -> XZY extrinsic
|
|
1619
|
+
"XZY",
|
|
1620
|
+
// -> YZX extrinsic
|
|
1621
|
+
"ZXY",
|
|
1622
|
+
// -> YXZ extrinsic
|
|
1623
|
+
"YXZ",
|
|
1624
|
+
// -> ZXY extrinsic
|
|
1625
|
+
"XYZ"
|
|
1626
|
+
// -> ZYX extrinsic
|
|
1627
|
+
//'SphericXYZ', // not possible to support
|
|
1628
|
+
];
|
|
1629
|
+
return i === 6 ? (console.warn("THREE.FBXLoader: unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect."), e[0]) : e[i];
|
|
1630
|
+
}
|
|
1631
|
+
function ae(i) {
|
|
1632
|
+
return i.split(",").map(function(t) {
|
|
1633
|
+
return parseFloat(t);
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
function Le(i, e, t) {
|
|
1637
|
+
return e === void 0 && (e = 0), t === void 0 && (t = i.byteLength), new TextDecoder().decode(new Uint8Array(i, e, t));
|
|
1638
|
+
}
|
|
1639
|
+
function Dt(i, e) {
|
|
1640
|
+
for (let t = 0, n = i.length, r = e.length; t < r; t++, n++)
|
|
1641
|
+
i[n] = e[t];
|
|
1642
|
+
}
|
|
1643
|
+
function Rt(i, e, t, n) {
|
|
1644
|
+
for (let r = t, s = 0; r < n; r++, s++)
|
|
1645
|
+
i[s] = e[r];
|
|
1646
|
+
return i;
|
|
1647
|
+
}
|
|
1648
|
+
async function Pt(i, e, t) {
|
|
1649
|
+
e.signal.throwIfAborted();
|
|
1650
|
+
const n = new AbortController(), r = n.signal, s = () => n.abort(e.signal.reason);
|
|
1651
|
+
e.signal.addEventListener("abort", s, { once: !0 });
|
|
1652
|
+
const a = (g, d) => new Promise((T, F) => {
|
|
1653
|
+
let y = !1;
|
|
1654
|
+
const x = () => {
|
|
1655
|
+
y || (y = !0, F(r.reason));
|
|
1656
|
+
};
|
|
1657
|
+
r.aborted ? x() : r.addEventListener("abort", x, { once: !0 }), g.then((I) => {
|
|
1658
|
+
r.removeEventListener("abort", x), y ? d == null || d(I) : (y = !0, T(I));
|
|
1659
|
+
}, (I) => {
|
|
1660
|
+
r.removeEventListener("abort", x), y || (y = !0, F(I));
|
|
1661
|
+
});
|
|
1662
|
+
}), o = [], l = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set(), f = [], u = new st(), c = async (g) => {
|
|
1663
|
+
var A;
|
|
1664
|
+
if (/^(blob:|data:)/i.test(g))
|
|
1665
|
+
return g.startsWith("blob:") && p.add(g), g;
|
|
1666
|
+
const d = [...new Set([...t.textures.values()].map((M) => M.path).filter(Boolean))], T = (M) => M.replaceAll("\\", "/").replace(/^\.\//, ""), F = T(g);
|
|
1667
|
+
let y = d.filter((M) => T(M) === F);
|
|
1668
|
+
if (y.length || (y = d.filter((M) => T(M).split("/").pop() === F.split("/").pop())), y.length > 1) throw new Error(`FBX texture path is ambiguous: ${g}`);
|
|
1669
|
+
const x = T(y[0] ?? g), I = e.original;
|
|
1670
|
+
if (typeof I == "object" && I !== null && "kind" in I && I.kind === "files") {
|
|
1671
|
+
const M = ((A = e.entryPath) == null ? void 0 : A.replace(/[^/]*$/, "")) ?? "", v = (b) => {
|
|
1672
|
+
const D = [];
|
|
1673
|
+
for (const w of T(b).split("/"))
|
|
1674
|
+
w === ".." ? D.pop() : w && w !== "." && D.push(w);
|
|
1675
|
+
return D.join("/");
|
|
1676
|
+
}, S = I.files.filter((b) => v(b.path) === v(M + x));
|
|
1677
|
+
if (S.length === 1) return e.resolve(S[0].path);
|
|
1678
|
+
const E = I.files.filter((b) => v(b.path).split("/").pop() === x.split("/").pop());
|
|
1679
|
+
if (E.length === 1) return e.resolve(E[0].path);
|
|
1680
|
+
if (E.length > 1) throw new Error(`FBX texture path is ambiguous: ${x}`);
|
|
1681
|
+
if (!e.hasResourceResolver) throw new Error(`FBX texture is missing from the selected files: ${x}`);
|
|
1682
|
+
}
|
|
1683
|
+
if (/^[A-Za-z]:\//.test(x) && !e.hasResourceResolver) throw new Error(`FBX texture uses an unavailable local path: ${x}`);
|
|
1684
|
+
if (!e.baseUrl && !e.hasResourceResolver && !/^https?:/i.test(x)) throw new Error(`FBX external texture requires a file package or baseUrl: ${x}`);
|
|
1685
|
+
return e.resolve(x);
|
|
1686
|
+
};
|
|
1687
|
+
class h extends J {
|
|
1688
|
+
constructor(d) {
|
|
1689
|
+
super(u), this.binaryFormat = d;
|
|
1690
|
+
}
|
|
1691
|
+
load(d, T, F, y) {
|
|
1692
|
+
const x = this.binaryFormat ? new ne() : new Y();
|
|
1693
|
+
l.add(x);
|
|
1694
|
+
const I = (async () => {
|
|
1695
|
+
const A = await a(c(d));
|
|
1696
|
+
r.throwIfAborted();
|
|
1697
|
+
const M = await fetch(A, { signal: r });
|
|
1698
|
+
if (!M.ok) throw new Error(`FBX texture request failed (${M.status}): ${d}`);
|
|
1699
|
+
if (this.binaryFormat) {
|
|
1700
|
+
const S = await M.arrayBuffer();
|
|
1701
|
+
r.throwIfAborted();
|
|
1702
|
+
let E;
|
|
1703
|
+
try {
|
|
1704
|
+
E = wt(S, this.binaryFormat);
|
|
1705
|
+
} catch (b) {
|
|
1706
|
+
throw new Error(`FBX texture decode failed (${this.binaryFormat}): ${d}: ${String(b)}`, { cause: b });
|
|
1707
|
+
}
|
|
1708
|
+
x.image = E.image, x.flipY = E.flipY, x.generateMipmaps = E.generateMipmaps, x.minFilter = E.minFilter, x.magFilter = E.magFilter, x.format = E.format, x.type = E.type, E.dispose(), x.needsUpdate = !0, T == null || T(x);
|
|
1709
|
+
return;
|
|
1710
|
+
}
|
|
1711
|
+
const v = URL.createObjectURL(await M.blob());
|
|
1712
|
+
try {
|
|
1713
|
+
const S = new Me().loadAsync(v).catch((b) => {
|
|
1714
|
+
const D = b instanceof Error ? `: ${b.message}` : "";
|
|
1715
|
+
throw new Error(`FBX texture decode failed: ${d}${D}`, { cause: b });
|
|
1716
|
+
}), E = await a(S, (b) => {
|
|
1717
|
+
b.dispose();
|
|
1718
|
+
});
|
|
1719
|
+
x.image = E.image, E.dispose(), r.throwIfAborted(), x.needsUpdate = !0, T == null || T(x);
|
|
1720
|
+
} finally {
|
|
1721
|
+
URL.revokeObjectURL(v);
|
|
1722
|
+
}
|
|
1723
|
+
})().catch((A) => {
|
|
1724
|
+
if (r.aborted) throw A;
|
|
1725
|
+
f.push(A instanceof Error ? A.message : String(A)), console.warn(`[viewer] FBX texture skipped: ${d}`, A), y == null || y(A);
|
|
1726
|
+
});
|
|
1727
|
+
return I.catch(() => {
|
|
1728
|
+
}), o.push(I), x;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
u.addHandler(/\.tga$/i, new h("tga")), u.addHandler(/\.dds$/i, new h("dds")), u.addHandler(/.*/, new h());
|
|
1732
|
+
let m;
|
|
1733
|
+
try {
|
|
1734
|
+
return m = new vt(u).parse(i, ""), await Promise.all(o), e.signal.throwIfAborted(), { root: m, textures: l, textureFailures: f };
|
|
1735
|
+
} catch (g) {
|
|
1736
|
+
if (n.abort(g), await Promise.allSettled(o), m) {
|
|
1737
|
+
const { disposeModelResources: d } = await import("./resources-CHhCm2f7.js");
|
|
1738
|
+
d(m, l);
|
|
1739
|
+
} else for (const d of l) d.dispose();
|
|
1740
|
+
throw g;
|
|
1741
|
+
} finally {
|
|
1742
|
+
e.signal.removeEventListener("abort", s);
|
|
1743
|
+
for (const g of p) URL.revokeObjectURL(g);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
const oe = "Kaydara FBX Binary \0", Ct = /(?:^|[\r\n])\s*P:\s*"UpAxis"\s*,\s*"int"\s*,\s*"Integer"\s*,\s*""\s*,\s*(-?\d+)/i, Lt = /(?:^|[\r\n])\s*P:\s*"UpAxisSign"\s*,\s*"int"\s*,\s*"Integer"\s*,\s*""\s*,\s*(-?\d+)/i;
|
|
1747
|
+
function Ot(i) {
|
|
1748
|
+
try {
|
|
1749
|
+
const e = new Uint8Array(i), t = Ut(e) ? kt(i) : Bt(new TextDecoder().decode(e));
|
|
1750
|
+
return !t || t.sign !== 1 ? null : t.axis === 1 ? "y" : t.axis === 2 ? "z" : null;
|
|
1751
|
+
} catch {
|
|
1752
|
+
return null;
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
function Ut(i) {
|
|
1756
|
+
if (i.byteLength < oe.length) return !1;
|
|
1757
|
+
for (let e = 0; e < oe.length; e += 1)
|
|
1758
|
+
if (i[e] !== oe.charCodeAt(e)) return !1;
|
|
1759
|
+
return !0;
|
|
1760
|
+
}
|
|
1761
|
+
function Bt(i) {
|
|
1762
|
+
var r, s;
|
|
1763
|
+
const e = Number.parseInt(((r = Ct.exec(i)) == null ? void 0 : r[1]) ?? "", 10);
|
|
1764
|
+
if (!Number.isInteger(e)) return null;
|
|
1765
|
+
const t = (s = Lt.exec(i)) == null ? void 0 : s[1], n = t === void 0 ? 1 : Number.parseInt(t, 10);
|
|
1766
|
+
return Number.isInteger(n) ? { axis: e, sign: n } : null;
|
|
1767
|
+
}
|
|
1768
|
+
function kt(i) {
|
|
1769
|
+
const e = new DataView(i);
|
|
1770
|
+
if (e.byteLength < 27) return null;
|
|
1771
|
+
const t = e.getUint32(23, !0) >= 7500;
|
|
1772
|
+
let n = 27;
|
|
1773
|
+
for (; n < e.byteLength; ) {
|
|
1774
|
+
const r = K(e, n, t, !1);
|
|
1775
|
+
if (!r) break;
|
|
1776
|
+
if (r.name === "GlobalSettings") return Oe(e, r.childrenOffset, r.endOffset, t);
|
|
1777
|
+
n = r.endOffset;
|
|
1778
|
+
}
|
|
1779
|
+
return null;
|
|
1780
|
+
}
|
|
1781
|
+
function Oe(i, e, t, n) {
|
|
1782
|
+
let r = e, s = null, a = 1;
|
|
1783
|
+
for (; r < t; ) {
|
|
1784
|
+
const o = K(i, r, n, !0);
|
|
1785
|
+
if (!o) break;
|
|
1786
|
+
if (o.name === "P") {
|
|
1787
|
+
const [l, , , , p] = o.properties;
|
|
1788
|
+
l === "UpAxis" && typeof p == "number" && (s = p), l === "UpAxisSign" && typeof p == "number" && (a = p);
|
|
1789
|
+
}
|
|
1790
|
+
if (o.childrenOffset < o.endOffset) {
|
|
1791
|
+
const l = Oe(i, o.childrenOffset, o.endOffset, n);
|
|
1792
|
+
l && (s ?? (s = l.axis), a = l.sign);
|
|
1793
|
+
}
|
|
1794
|
+
r = o.endOffset;
|
|
1795
|
+
}
|
|
1796
|
+
return s === null ? null : { axis: s, sign: a };
|
|
1797
|
+
}
|
|
1798
|
+
function K(i, e, t, n) {
|
|
1799
|
+
const r = t ? 25 : 13;
|
|
1800
|
+
if (e + r > i.byteLength) return null;
|
|
1801
|
+
const s = ie(i, e, t), a = ie(i, e + (t ? 8 : 4), t), o = ie(i, e + (t ? 16 : 8), t), l = i.getUint8(e + (t ? 24 : 12));
|
|
1802
|
+
if (s === 0) return null;
|
|
1803
|
+
const p = e + r, f = p + l, u = f + o;
|
|
1804
|
+
if (s <= e || s > i.byteLength || u > s) throw new Error("Invalid FBX node bounds.");
|
|
1805
|
+
const c = new TextDecoder().decode(new Uint8Array(i.buffer, i.byteOffset + p, l)), h = [];
|
|
1806
|
+
if (n) {
|
|
1807
|
+
let m = f;
|
|
1808
|
+
for (let g = 0; g < a; g += 1) {
|
|
1809
|
+
const d = Xt(i, m);
|
|
1810
|
+
if (h.push(d.value), m = d.nextOffset, m > u) return null;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
return { name: c, endOffset: s, childrenOffset: u, properties: h };
|
|
1814
|
+
}
|
|
1815
|
+
function ie(i, e, t) {
|
|
1816
|
+
if (!t) return i.getUint32(e, !0);
|
|
1817
|
+
const n = i.getBigUint64(e, !0);
|
|
1818
|
+
if (n > BigInt(Number.MAX_SAFE_INTEGER)) throw new Error("FBX offset exceeds the safe integer range.");
|
|
1819
|
+
return Number(n);
|
|
1820
|
+
}
|
|
1821
|
+
function Xt(i, e) {
|
|
1822
|
+
const t = String.fromCharCode(i.getUint8(e));
|
|
1823
|
+
switch (t) {
|
|
1824
|
+
case "Y":
|
|
1825
|
+
return { value: i.getInt16(e + 1, !0), nextOffset: e + 3 };
|
|
1826
|
+
case "C":
|
|
1827
|
+
return { value: i.getUint8(e + 1) !== 0, nextOffset: e + 2 };
|
|
1828
|
+
case "I":
|
|
1829
|
+
return { value: i.getInt32(e + 1, !0), nextOffset: e + 5 };
|
|
1830
|
+
case "F":
|
|
1831
|
+
return { value: i.getFloat32(e + 1, !0), nextOffset: e + 5 };
|
|
1832
|
+
case "D":
|
|
1833
|
+
return { value: i.getFloat64(e + 1, !0), nextOffset: e + 9 };
|
|
1834
|
+
case "L":
|
|
1835
|
+
return { value: Number(i.getBigInt64(e + 1, !0)), nextOffset: e + 9 };
|
|
1836
|
+
case "S":
|
|
1837
|
+
case "R": {
|
|
1838
|
+
const n = i.getUint32(e + 1, !0), r = e + 5, s = new Uint8Array(i.buffer, i.byteOffset + r, n);
|
|
1839
|
+
return { value: t === "S" ? new TextDecoder().decode(s) : s, nextOffset: r + n };
|
|
1840
|
+
}
|
|
1841
|
+
case "f":
|
|
1842
|
+
case "d":
|
|
1843
|
+
case "l":
|
|
1844
|
+
case "i":
|
|
1845
|
+
case "b":
|
|
1846
|
+
case "c": {
|
|
1847
|
+
const n = i.getUint32(e + 9, !0);
|
|
1848
|
+
return { value: null, nextOffset: e + 13 + n };
|
|
1849
|
+
}
|
|
1850
|
+
default:
|
|
1851
|
+
throw new Error(`Unsupported FBX property type: ${t}`);
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
const te = /* @__PURE__ */ new Set(["Definitions", "ObjectType", "PropertyTemplate", "Objects", "Material", "Properties70", "Connections", "Texture", "Video", "Geometry", "LayerElementUV", "LayeredTexture", "BlendModes", "Alphas"]), Ue = /* @__PURE__ */ new Set(["P", "C", "RelativeFilename", "FileName", "Filename", "ShadingModel", "UVSet", "Scaling", "Translation", "Rotation", "RotationPivot", "ScalingPivot", "Name", "UV", "a"]);
|
|
1855
|
+
function _t(i) {
|
|
1856
|
+
var F, y, x, I, A, M;
|
|
1857
|
+
const e = new Uint8Array(i), n = new TextDecoder().decode(e.subarray(0, 21)) === "Kaydara FBX Binary \0" ? Vt(i) : Gt(new TextDecoder().decode(e)), r = (v) => {
|
|
1858
|
+
var S;
|
|
1859
|
+
return new Map(
|
|
1860
|
+
(((S = v == null ? void 0 : v.children.find((E) => E.name === "Properties70")) == null ? void 0 : S.children) ?? []).filter((E) => E.name === "P" && typeof E.values[0] == "string").map((E) => [E.values[0], E.values.slice(4)])
|
|
1861
|
+
);
|
|
1862
|
+
}, s = n.find((v) => v.name === "Definitions"), a = s == null ? void 0 : s.children.find((v) => v.name === "ObjectType" && v.values[0] === "Material"), o = (a == null ? void 0 : a.children.filter((v) => v.name === "PropertyTemplate")) ?? [], l = ((F = n.find((v) => v.name === "Connections")) == null ? void 0 : F.children.filter((v) => v.name === "C")) ?? [], p = ((y = n.find((v) => v.name === "Objects")) == null ? void 0 : y.children) ?? [], f = /* @__PURE__ */ new Map(), u = (v, S) => {
|
|
1863
|
+
var E;
|
|
1864
|
+
return (E = v == null ? void 0 : v.children.find((b) => b.name === S)) == null ? void 0 : E.values[0];
|
|
1865
|
+
};
|
|
1866
|
+
for (const v of p.filter((S) => S.name === "Texture")) {
|
|
1867
|
+
const S = Number(v.values[0]), E = (x = l.find((P) => P.values[0] === "OO" && P.values[2] === S)) == null ? void 0 : x.values[1], b = p.find((P) => P.name === "Video" && P.values[0] === E), D = String(u(b, "RelativeFilename") || u(v, "RelativeFilename") || u(b, "Filename") || u(v, "FileName") || ""), w = r(v);
|
|
1868
|
+
for (const P of ["Scaling", "Translation", "Rotation", "RotationPivot", "ScalingPivot"]) {
|
|
1869
|
+
const _ = (I = v.children.find((Be) => Be.name === P)) == null ? void 0 : I.values;
|
|
1870
|
+
_ && w.set(P, _);
|
|
1871
|
+
}
|
|
1872
|
+
const R = u(v, "UVSet") ?? ((A = w.get("UVSet")) == null ? void 0 : A[0]);
|
|
1873
|
+
f.set(S, { id: S, path: D, values: w, uvSet: typeof R == "string" ? R : null });
|
|
1874
|
+
}
|
|
1875
|
+
const c = /* @__PURE__ */ new Map(), h = (v, S) => {
|
|
1876
|
+
var D;
|
|
1877
|
+
const E = v.children.find((w) => w.name === S), b = ((D = E == null ? void 0 : E.children.find((w) => w.name === "a")) == null ? void 0 : D.values) ?? (E == null ? void 0 : E.values) ?? [];
|
|
1878
|
+
if (b.some((w) => typeof w != "number" || !Number.isFinite(w))) throw new Error(`Invalid FBX layered ${S}.`);
|
|
1879
|
+
return b;
|
|
1880
|
+
};
|
|
1881
|
+
for (const v of p.filter((S) => S.name === "LayeredTexture")) {
|
|
1882
|
+
const S = Number(v.values[0]);
|
|
1883
|
+
if (!Number.isSafeInteger(S)) throw new Error("Invalid FBX layered texture ID.");
|
|
1884
|
+
c.set(S, {
|
|
1885
|
+
id: S,
|
|
1886
|
+
name: String(v.values[1] ?? ""),
|
|
1887
|
+
textureIds: l.filter((E) => E.values[0] === "OO" && E.values[2] === S).map((E) => Number(E.values[1])),
|
|
1888
|
+
blendModes: h(v, "BlendModes"),
|
|
1889
|
+
alphas: h(v, "Alphas")
|
|
1890
|
+
});
|
|
1891
|
+
}
|
|
1892
|
+
const m = /* @__PURE__ */ new Map();
|
|
1893
|
+
for (const v of ((M = n.find((S) => S.name === "Objects")) == null ? void 0 : M.children) ?? []) {
|
|
1894
|
+
if (v.name !== "Material") continue;
|
|
1895
|
+
const S = v.values[0];
|
|
1896
|
+
if (typeof S != "number" || !Number.isSafeInteger(S)) throw new Error("Invalid FBX material ID.");
|
|
1897
|
+
const E = r(v), b = l.filter((P) => P.values[0] === "OP" && P.values[2] === S).map((P) => String(P.values[3])), D = l.filter((P) => P.values[0] === "OP" && P.values[2] === S).map((P) => ({ id: Number(P.values[1]), role: String(P.values[3]) })), w = String(u(v, "ShadingModel") ?? "phong").toLowerCase(), R = r(o.find((P) => String(P.values[0]).toLowerCase() === `fbxsurface${w}`));
|
|
1898
|
+
m.set(S, {
|
|
1899
|
+
textureConnections: D,
|
|
1900
|
+
shadingModel: w,
|
|
1901
|
+
id: S,
|
|
1902
|
+
name: String(v.values[1] ?? ""),
|
|
1903
|
+
ownValues: E,
|
|
1904
|
+
values: new Map([...R, ...E]),
|
|
1905
|
+
textureRoles: b
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
const g = /* @__PURE__ */ new Map();
|
|
1909
|
+
for (const v of l) {
|
|
1910
|
+
const [S, E, b] = v.values;
|
|
1911
|
+
if (S !== "OO" || typeof E != "number" || typeof b != "number" || !m.has(E)) continue;
|
|
1912
|
+
const D = g.get(b) ?? [];
|
|
1913
|
+
D.push(E), g.set(b, D);
|
|
1914
|
+
}
|
|
1915
|
+
const d = /* @__PURE__ */ new Map();
|
|
1916
|
+
for (const v of p.filter((S) => S.name === "Geometry")) {
|
|
1917
|
+
const S = new Map(v.children.filter((b) => b.name === "LayerElementUV").map((b) => [Number(b.values[0]), b])), E = [];
|
|
1918
|
+
for (let b = 0; S.has(b); b++) {
|
|
1919
|
+
const D = S.get(b);
|
|
1920
|
+
D.children.some((w) => w.name === "UV") && E.push(String(u(D, "Name") ?? ""));
|
|
1921
|
+
}
|
|
1922
|
+
d.set(Number(v.values[0]), E);
|
|
1923
|
+
}
|
|
1924
|
+
const T = /* @__PURE__ */ new Map();
|
|
1925
|
+
for (const v of l) {
|
|
1926
|
+
const [S, E, b] = v.values;
|
|
1927
|
+
S === "OO" && typeof E == "number" && typeof b == "number" && d.has(E) && T.set(b, d.get(E));
|
|
1928
|
+
}
|
|
1929
|
+
return { materials: m, modelMaterials: g, textures: f, modelUvSets: T, layeredTextures: c };
|
|
1930
|
+
}
|
|
1931
|
+
function Vt(i) {
|
|
1932
|
+
const e = new DataView(i);
|
|
1933
|
+
if (e.byteLength < 27) throw new Error("Truncated FBX header.");
|
|
1934
|
+
const t = e.getUint32(23, !0) >= 7500, n = (r, s, a) => {
|
|
1935
|
+
if (a > 16) throw new Error("Excessive FBX metadata nesting.");
|
|
1936
|
+
const o = [];
|
|
1937
|
+
let l = r;
|
|
1938
|
+
for (; l < s; ) {
|
|
1939
|
+
const p = K(e, l, t, !1);
|
|
1940
|
+
if (!p) break;
|
|
1941
|
+
if (p.endOffset > s) throw new Error("FBX child extends past its parent.");
|
|
1942
|
+
if (te.has(p.name) || Ue.has(p.name)) {
|
|
1943
|
+
const f = K(e, l, t, p.name !== "UV");
|
|
1944
|
+
o.push({ name: f.name, values: ["BlendModes", "Alphas"].includes(f.name) ? Nt(e, l, t, f.childrenOffset) : [...f.properties], children: te.has(f.name) ? n(f.childrenOffset, f.endOffset, a + 1) : [] });
|
|
1945
|
+
}
|
|
1946
|
+
l = p.endOffset;
|
|
1947
|
+
}
|
|
1948
|
+
return o;
|
|
1949
|
+
};
|
|
1950
|
+
return n(27, e.byteLength, 0);
|
|
1951
|
+
}
|
|
1952
|
+
function Gt(i) {
|
|
1953
|
+
const e = /"(?:\\.|[^"\\])*"|;[^\r\n]*|\r?\n|[^\S\r\n]+|[{}:,]|[^\s{}:,;]+/g;
|
|
1954
|
+
let t = null;
|
|
1955
|
+
const n = () => {
|
|
1956
|
+
var a;
|
|
1957
|
+
if (t !== null) {
|
|
1958
|
+
const o = t;
|
|
1959
|
+
return t = null, o;
|
|
1960
|
+
}
|
|
1961
|
+
for (; ; ) {
|
|
1962
|
+
const o = ((a = e.exec(i)) == null ? void 0 : a[0]) ?? null;
|
|
1963
|
+
if (o === null) return null;
|
|
1964
|
+
if (!(o.startsWith(";") || /^[^\S\r\n]+$/.test(o)))
|
|
1965
|
+
return o;
|
|
1966
|
+
}
|
|
1967
|
+
}, r = (a) => a.startsWith('"') ? a.slice(1, -1).replace(/\\(["\\])/g, "$1") : Number.isFinite(Number(a)) ? Number(a) : a, s = (a) => {
|
|
1968
|
+
if (a > 16) throw new Error("Excessive FBX metadata nesting.");
|
|
1969
|
+
const o = [];
|
|
1970
|
+
for (; ; ) {
|
|
1971
|
+
const l = n();
|
|
1972
|
+
if (l === null) {
|
|
1973
|
+
if (a) throw new Error("Unclosed FBX block.");
|
|
1974
|
+
return o;
|
|
1975
|
+
}
|
|
1976
|
+
if (l === "}") {
|
|
1977
|
+
if (!a) throw new Error("Unexpected FBX closing brace.");
|
|
1978
|
+
return o;
|
|
1979
|
+
}
|
|
1980
|
+
if (l === `
|
|
1981
|
+
` || l === `\r
|
|
1982
|
+
`) continue;
|
|
1983
|
+
if (n() !== ":") throw new Error("Malformed ASCII FBX metadata.");
|
|
1984
|
+
const p = te.has(l) || Ue.has(l), f = [];
|
|
1985
|
+
let u = [];
|
|
1986
|
+
for (; ; ) {
|
|
1987
|
+
const c = n();
|
|
1988
|
+
if (c === null || c === `
|
|
1989
|
+
` || c === `\r
|
|
1990
|
+
`) break;
|
|
1991
|
+
if (c === "}") {
|
|
1992
|
+
t = c;
|
|
1993
|
+
break;
|
|
1994
|
+
}
|
|
1995
|
+
if (c === "{") {
|
|
1996
|
+
if (te.has(l)) u = s(a + 1);
|
|
1997
|
+
else {
|
|
1998
|
+
let h = 1;
|
|
1999
|
+
for (; h; ) {
|
|
2000
|
+
const m = n();
|
|
2001
|
+
if (m === null) throw new Error("Unclosed FBX block.");
|
|
2002
|
+
m === "{" && h++, m === "}" && h--;
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
break;
|
|
2006
|
+
}
|
|
2007
|
+
p && c !== "," && f.push(r(c));
|
|
2008
|
+
}
|
|
2009
|
+
p && o.push({ name: l, values: f, children: u });
|
|
2010
|
+
}
|
|
2011
|
+
};
|
|
2012
|
+
return s(0);
|
|
2013
|
+
}
|
|
2014
|
+
function Nt(i, e, t, n) {
|
|
2015
|
+
const r = t ? 25 : 13;
|
|
2016
|
+
let s = e + r + i.getUint8(e + r - 1);
|
|
2017
|
+
if (s === n) return [];
|
|
2018
|
+
const a = String.fromCharCode(i.getUint8(s));
|
|
2019
|
+
if (!["i", "d", "f"].includes(a)) return [...K(i, e, t, !0).properties];
|
|
2020
|
+
if (s + 13 > n) throw new Error("Truncated FBX layered array header.");
|
|
2021
|
+
const o = i.getUint32(s + 1, !0), l = i.getUint32(s + 5, !0), p = i.getUint32(s + 9, !0), f = a === "d" ? 8 : 4;
|
|
2022
|
+
if (o > 4096 || s + 13 + p !== n || ![0, 1].includes(l)) throw new Error("Invalid FBX layered array bounds.");
|
|
2023
|
+
const u = new Uint8Array(i.buffer, i.byteOffset + s + 13, p), c = l === 1 ? ht(u, { out: new Uint8Array(o * f) }) : u;
|
|
2024
|
+
if (c.length !== o * f) throw new Error("Invalid FBX layered array size.");
|
|
2025
|
+
const h = new DataView(c.buffer, c.byteOffset, c.byteLength);
|
|
2026
|
+
return Array.from({ length: o }, (m, g) => a === "i" ? h.getInt32(g * f, !0) : a === "d" ? h.getFloat64(g * f, !0) : h.getFloat32(g * f, !0));
|
|
2027
|
+
}
|
|
2028
|
+
const Ee = (i) => i <= 0.04045 ? i / 12.92 : ((i + 0.055) / 1.055) ** 2.4, $t = (i) => i <= 31308e-7 ? i * 12.92 : 1.055 * i ** (1 / 2.4) - 0.055, zt = /* @__PURE__ */ new Set([0, 1, 2, 4, 5]), jt = 4 * 1024 * 1024;
|
|
2029
|
+
function be(i) {
|
|
2030
|
+
const e = i.image, t = (e == null ? void 0 : e.naturalWidth) || (e == null ? void 0 : e.width), n = (e == null ? void 0 : e.naturalHeight) || (e == null ? void 0 : e.height);
|
|
2031
|
+
if (!t || !n || t * n > jt) throw new Error("missing image or image exceeds 4M pixels");
|
|
2032
|
+
let r;
|
|
2033
|
+
if (e.data) {
|
|
2034
|
+
if (i.format !== Ie || i.type !== Ae || !(e.data instanceof Uint8Array) || e.data.length !== t * n * 4) throw new Error("require RGBA8 source");
|
|
2035
|
+
r = e.data;
|
|
2036
|
+
} else {
|
|
2037
|
+
const a = document.createElement("canvas");
|
|
2038
|
+
a.width = t, a.height = n;
|
|
2039
|
+
const o = a.getContext("2d", { willReadFrequently: !0 });
|
|
2040
|
+
if (!o) throw new Error("canvas readback unavailable");
|
|
2041
|
+
o.drawImage(i.image, 0, 0), r = o.getImageData(0, 0, t, n).data;
|
|
2042
|
+
}
|
|
2043
|
+
const s = new Uint8Array(t * n * 4);
|
|
2044
|
+
for (let a = 0; a < n; a++) for (let o = 0; o < t * 4; o++) s[(i.flipY ? n - a - 1 : a) * t * 4 + o] = r[a * t * 4 + o];
|
|
2045
|
+
return { data: s, width: t, height: n };
|
|
2046
|
+
}
|
|
2047
|
+
function Ht(i, e, t) {
|
|
2048
|
+
if (i.issues.some((u) => u.code !== "LAYERED_TEXTURE_NOT_COMPOSITED")) throw new Error("incompatible layer graph or coordinates");
|
|
2049
|
+
if (i.layers.length < 1 || i.layers.length > 8) throw new Error("require 1–8 layers");
|
|
2050
|
+
if (!i.layers.every((u) => u.blendMode !== null && zt.has(u.blendMode))) throw new Error("unsupported blend mode");
|
|
2051
|
+
const n = i.layers.map((u) => {
|
|
2052
|
+
const c = [...t].find((h) => h.ID === u.textureId);
|
|
2053
|
+
if (!c) throw new Error(`missing decoded texture ${u.textureId}`);
|
|
2054
|
+
return c;
|
|
2055
|
+
}), r = n[0], s = (u) => JSON.stringify([
|
|
2056
|
+
u.wrapS,
|
|
2057
|
+
u.wrapT,
|
|
2058
|
+
u.minFilter,
|
|
2059
|
+
u.magFilter,
|
|
2060
|
+
u.anisotropy,
|
|
2061
|
+
u.channel,
|
|
2062
|
+
u.mapping,
|
|
2063
|
+
u.matrixAutoUpdate,
|
|
2064
|
+
u.offset.toArray(),
|
|
2065
|
+
u.repeat.toArray(),
|
|
2066
|
+
u.center.toArray(),
|
|
2067
|
+
u.rotation,
|
|
2068
|
+
u.matrix.elements
|
|
2069
|
+
]);
|
|
2070
|
+
if (n.some((u) => s(u) !== s(r))) throw new Error("incompatible sampling state");
|
|
2071
|
+
if (i.layers.some((u) => !e.textures.has(u.textureId))) throw new Error("missing source metadata");
|
|
2072
|
+
const a = be(r), o = a.width * a.height;
|
|
2073
|
+
if (i.layers[0].alpha !== 1 || a.data.some((u, c) => c % 4 === 3 && u !== 255)) throw new Error("base layer must be fully opaque with weight 1");
|
|
2074
|
+
const l = new Float32Array(o * 3);
|
|
2075
|
+
for (let u = 0; u < o; u++) for (let c = 0; c < 3; c++) l[u * 3 + c] = r.colorSpace === me ? a.data[u * 4 + c] / 255 : Ee(a.data[u * 4 + c] / 255);
|
|
2076
|
+
for (let u = 1; u < n.length; u++) {
|
|
2077
|
+
const c = n[u], h = be(c), m = i.layers[u];
|
|
2078
|
+
if (h.width !== a.width || h.height !== a.height) throw new Error("layer dimensions differ");
|
|
2079
|
+
for (let g = 0; g < o; g++) {
|
|
2080
|
+
const d = m.alpha * h.data[g * 4 + 3] / 255;
|
|
2081
|
+
for (let T = 0; T < 3; T++) {
|
|
2082
|
+
const F = l[g * 3 + T], y = h.data[g * 4 + T] / 255, x = c.colorSpace === me ? y : Ee(y), I = m.blendMode === 1 ? Math.min(1, F + x) : m.blendMode === 2 ? F * x : x;
|
|
2083
|
+
l[g * 3 + T] = F + (I - F) * d;
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
const p = new Uint8Array(o * 4);
|
|
2088
|
+
for (let u = 0; u < o; u++) p[u * 4 + 3] = 255;
|
|
2089
|
+
for (let u = 0; u < o; u++) for (let c = 0; c < 3; c++) p[u * 4 + c] = Math.round(255 * Math.min(1, Math.max(0, $t(l[u * 3 + c]))));
|
|
2090
|
+
const f = new ne(p, a.width, a.height);
|
|
2091
|
+
return f.colorSpace = X, f.generateMipmaps = r.generateMipmaps, f.wrapS = r.wrapS, f.wrapT = r.wrapT, f.minFilter = r.minFilter, f.magFilter = r.magFilter, f.anisotropy = r.anisotropy, f.offset.copy(r.offset), f.repeat.copy(r.repeat), f.center.copy(r.center), f.rotation = r.rotation, f.matrix.copy(r.matrix), f.matrixAutoUpdate = r.matrixAutoUpdate, f.channel = r.channel, f.mapping = r.mapping, f.userData.fbxLayerBaseId = i.layers[0].textureId, f.needsUpdate = !0, f;
|
|
2092
|
+
}
|
|
2093
|
+
function Wt(i, e) {
|
|
2094
|
+
return i.textureConnections.flatMap((t) => {
|
|
2095
|
+
var u;
|
|
2096
|
+
const n = (u = e.layeredTextures) == null ? void 0 : u.get(t.id);
|
|
2097
|
+
if (!n) return [];
|
|
2098
|
+
const r = [], s = (c, h) => r.push({ status: "unsupported", code: c, source: `layered:${n.id}:${h}`, target: t.role });
|
|
2099
|
+
s("LAYERED_TEXTURE_NOT_COMPOSITED", "preview uses loader fallback; layers have not been composited");
|
|
2100
|
+
const a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), l = [], p = (c, h) => {
|
|
2101
|
+
var g;
|
|
2102
|
+
if (a.has(c)) {
|
|
2103
|
+
s("LAYERED_TEXTURE_CYCLE", String(c));
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
if (h > 32 || o.size >= 4096) {
|
|
2107
|
+
s("LAYERED_TEXTURE_GRAPH_LIMIT", String(c));
|
|
2108
|
+
return;
|
|
2109
|
+
}
|
|
2110
|
+
if (o.has(c)) return;
|
|
2111
|
+
const m = (g = e.layeredTextures) == null ? void 0 : g.get(c);
|
|
2112
|
+
if (!m) {
|
|
2113
|
+
e.textures.has(c) ? l.push(c) : s("LAYERED_TEXTURE_MISSING_SOURCE", String(c)), o.add(c);
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
h && s("LAYERED_TEXTURE_NESTED", String(c)), m.textureIds.length || s("LAYERED_TEXTURE_EMPTY", String(c)), (m.blendModes.length !== m.textureIds.length || m.alphas.length !== m.textureIds.length) && s("LAYERED_TEXTURE_METADATA_MISMATCH", `${c}:sources=${m.textureIds.length},modes=${m.blendModes.length},alphas=${m.alphas.length}`), m.blendModes.some((d) => !Number.isInteger(d) || d < 0) && s("LAYERED_TEXTURE_INVALID_MODE", String(c)), m.alphas.some((d) => !Number.isFinite(d) || d < 0 || d > 1) && s("LAYERED_TEXTURE_INVALID_ALPHA", String(c)), a.add(c);
|
|
2117
|
+
for (const d of m.textureIds) p(d, h + 1);
|
|
2118
|
+
a.delete(c), o.add(c);
|
|
2119
|
+
};
|
|
2120
|
+
return p(n.id, 0), new Set(l.map((c) => {
|
|
2121
|
+
const h = e.textures.get(c);
|
|
2122
|
+
return JSON.stringify([h.uvSet ?? "default", ...["Translation", "Scaling", "Rotation", "RotationPivot", "ScalingPivot"].map((m) => h.values.get(m) ?? null)]);
|
|
2123
|
+
})).size > 1 && s("LAYERED_TEXTURE_COORDINATES_DIFFER", "UV sets or transforms differ; direct pixel blending is unsafe"), [{ id: n.id, role: t.role, layers: n.textureIds.map((c, h) => ({ textureId: c, blendMode: n.blendModes[h] ?? null, alpha: n.alphas[h] ?? null })), issues: r }];
|
|
2124
|
+
});
|
|
2125
|
+
}
|
|
2126
|
+
const Yt = {
|
|
2127
|
+
DiffuseColor: "map",
|
|
2128
|
+
"Maya|TEX_color_map": "map",
|
|
2129
|
+
NormalMap: "normalMap",
|
|
2130
|
+
"Maya|TEX_normal_map": "normalMap",
|
|
2131
|
+
Bump: "bumpMap",
|
|
2132
|
+
EmissiveColor: "emissiveMap",
|
|
2133
|
+
DisplacementColor: "displacementMap",
|
|
2134
|
+
"Maya|TEX_ao_map": "aoMap",
|
|
2135
|
+
ReflectionFactor: "metalnessMap",
|
|
2136
|
+
ReflectionColor: "metalnessMap",
|
|
2137
|
+
ShininessExponent: "roughnessMap",
|
|
2138
|
+
SpecularFactor: "specularIntensityMap",
|
|
2139
|
+
SpecularColor: "specularIntensityMap",
|
|
2140
|
+
TransparentColor: "alphaMap",
|
|
2141
|
+
TransparencyFactor: "alphaMap"
|
|
2142
|
+
};
|
|
2143
|
+
function qt(i, e, t, n, r, s) {
|
|
2144
|
+
var c;
|
|
2145
|
+
const a = (c = n.modelUvSets) == null ? void 0 : c.get(i.ID ?? NaN), o = [], l = [], p = /* @__PURE__ */ new Set();
|
|
2146
|
+
for (const h of t.textureConnections) {
|
|
2147
|
+
const m = Yt[h.role], g = m ? e[m] : void 0, d = n.textures.get(h.id) ?? (g instanceof Y ? n.textures.get(g.userData.fbxLayerBaseId) : void 0);
|
|
2148
|
+
if (!m || !d || p.has(m)) continue;
|
|
2149
|
+
p.add(m);
|
|
2150
|
+
const T = e[m];
|
|
2151
|
+
if (!(T instanceof Y)) continue;
|
|
2152
|
+
const F = (D, w) => l.push({ status: "unsupported", code: D, source: `texture:${h.id}:${w}`, target: String(m) });
|
|
2153
|
+
let y = 0;
|
|
2154
|
+
if (d.uvSet) {
|
|
2155
|
+
const D = (a == null ? void 0 : a.flatMap((w, R) => w === d.uvSet ? [R] : [])) ?? [];
|
|
2156
|
+
if (D.length === 1) y = D[0];
|
|
2157
|
+
else if (D.length > 1 || d.uvSet !== "default") {
|
|
2158
|
+
F("UV_SET_UNRESOLVED", `UVSet:${d.uvSet}:${D.length > 1 ? "ambiguous" : "missing"}`);
|
|
2159
|
+
continue;
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
if (y > 3 || !i.geometry.hasAttribute(y === 0 ? "uv" : `uv${y}`)) {
|
|
2163
|
+
F("UV_CHANNEL_UNAVAILABLE", `channel:${y}`);
|
|
2164
|
+
continue;
|
|
2165
|
+
}
|
|
2166
|
+
const x = (D, w) => {
|
|
2167
|
+
const R = d.values.get(D);
|
|
2168
|
+
return R ? R.length < 2 || !R.every((P) => typeof P == "number" && Number.isFinite(P)) ? (F("TEXTURE_TRANSFORM_INVALID", D), w) : R : w;
|
|
2169
|
+
}, I = x("Translation", [T.offset.x, T.offset.y, 0]), A = x("Scaling", [T.repeat.x, T.repeat.y, 1]), M = x("Rotation", [0, 0, 0]), v = x("RotationPivot", [0, 0, 0]), S = x("ScalingPivot", [0, 0, 0]), E = M[0] !== 0 || M[1] !== 0 || v.some((D) => D !== 0) || S.some((D) => D !== 0);
|
|
2170
|
+
E && F("TEXTURE_TRANSFORM_UNSUPPORTED", "3D-rotation-or-pivot"), (I[2] || A[2] !== void 0 && A[2] !== 1) && F("TEXTURE_TRANSFORM_UNSUPPORTED", "3D-translation-or-scale");
|
|
2171
|
+
const b = E ? 0 : -(M[2] ?? 0) * Math.PI / 180;
|
|
2172
|
+
b && l.push({ status: "approximate", code: "TEXTURE_ROTATION_PROFILE", source: `texture:${h.id}:Rotation`, target: "T * Rccw * S; origin pivot" }), (y !== T.channel || I[0] !== T.offset.x || I[1] !== T.offset.y || A[0] !== T.repeat.x || A[1] !== T.repeat.y || b !== T.rotation) && o.push({ slot: m, source: T, channel: y, offset: I, scale: A, rotation: b });
|
|
2173
|
+
}
|
|
2174
|
+
if (!o.length && !l.length) return e;
|
|
2175
|
+
const f = e.clone();
|
|
2176
|
+
r(f);
|
|
2177
|
+
const u = f.userData.fbxConversionReport;
|
|
2178
|
+
u.issues.push(...l);
|
|
2179
|
+
for (const h of o) {
|
|
2180
|
+
const m = h.source.clone();
|
|
2181
|
+
s(m), m.channel = h.channel, m.offset.set(h.offset[0], h.offset[1]), m.repeat.set(h.scale[0], h.scale[1]), m.center.set(0, 0), m.rotation = h.rotation;
|
|
2182
|
+
const g = -h.rotation, d = Math.cos(g), T = Math.sin(g);
|
|
2183
|
+
m.matrixAutoUpdate = !1, m.matrix.set(
|
|
2184
|
+
d * h.scale[0],
|
|
2185
|
+
-T * h.scale[1],
|
|
2186
|
+
h.offset[0],
|
|
2187
|
+
T * h.scale[0],
|
|
2188
|
+
d * h.scale[1],
|
|
2189
|
+
h.offset[1],
|
|
2190
|
+
0,
|
|
2191
|
+
0,
|
|
2192
|
+
1
|
|
2193
|
+
), f[h.slot] = m, u.mappings.push({ source: `${h.slot}:UV`, target: `uv${h.channel || ""}`, rule: "geometry UV name binding; T * Rccw * S" });
|
|
2194
|
+
}
|
|
2195
|
+
return f.needsUpdate = !0, f;
|
|
2196
|
+
}
|
|
2197
|
+
function Kt(i, e) {
|
|
2198
|
+
return Math.min(1, Math.max(0, i));
|
|
2199
|
+
}
|
|
2200
|
+
function Zt(i, e, t, n, r = "r", s = !1) {
|
|
2201
|
+
if (!Number.isInteger(e) || !Number.isInteger(t) || e <= 0 || t <= 0 || i.length !== e * t * 4)
|
|
2202
|
+
throw new Error("Invalid FBX scalar RGBA dimensions.");
|
|
2203
|
+
const a = new Uint8Array(i.length), o = { r: 0, g: 1, b: 2, a: 3 }[r];
|
|
2204
|
+
for (let l = 0; l < t; l++) for (let p = 0; p < e; p++) {
|
|
2205
|
+
const f = (l * e + p) * 4, u = ((s ? t - l - 1 : l) * e + p) * 4, c = Math.round(255 * Kt(i[f + o] / 255));
|
|
2206
|
+
a.fill(c, u, u + 4);
|
|
2207
|
+
}
|
|
2208
|
+
return a;
|
|
2209
|
+
}
|
|
2210
|
+
function Qt(i, e) {
|
|
2211
|
+
const t = i.image;
|
|
2212
|
+
if (!t) throw new Error("FBX scalar texture has no decoded image.");
|
|
2213
|
+
const n = t.naturalWidth || t.width, r = t.naturalHeight || t.height;
|
|
2214
|
+
if (!n || !r) throw new Error("FBX scalar texture has no decoded image.");
|
|
2215
|
+
let s;
|
|
2216
|
+
if (t.data) {
|
|
2217
|
+
if (!(t.data instanceof Uint8Array || t.data instanceof Uint8ClampedArray) || i.format !== Ie || i.type !== Ae)
|
|
2218
|
+
throw new Error("FBX scalar conversion requires 8-bit RGBA pixels.");
|
|
2219
|
+
s = t.data;
|
|
2220
|
+
} else {
|
|
2221
|
+
const o = document.createElement("canvas");
|
|
2222
|
+
o.width = n, o.height = r;
|
|
2223
|
+
const l = o.getContext("2d", { willReadFrequently: !0 });
|
|
2224
|
+
if (!l) throw new Error("FBX scalar texture conversion requires a 2D canvas.");
|
|
2225
|
+
l.drawImage(t, 0, 0), s = l.getImageData(0, 0, n, r).data;
|
|
2226
|
+
}
|
|
2227
|
+
const a = new ne(Zt(s, n, r, e, "r", i.flipY), n, r);
|
|
2228
|
+
return a.wrapS = i.wrapS, a.wrapT = i.wrapT, a.offset.copy(i.offset), a.repeat.copy(i.repeat), a.center.copy(i.center), a.rotation = i.rotation, a.matrix.copy(i.matrix), a.matrixAutoUpdate = i.matrixAutoUpdate, a.channel = i.channel, a.magFilter = i.magFilter, a.minFilter = i.minFilter, a.generateMipmaps = i.generateMipmaps, a.anisotropy = i.anisotropy, a.colorSpace = at, a.needsUpdate = !0, a;
|
|
2229
|
+
}
|
|
2230
|
+
function Jt(i, e, t) {
|
|
2231
|
+
const n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), l = [];
|
|
2232
|
+
try {
|
|
2233
|
+
i.traverse((c) => {
|
|
2234
|
+
if (!(c instanceof Fe)) return;
|
|
2235
|
+
const h = e == null ? void 0 : e.modelMaterials.get(c.ID ?? NaN), m = (d) => h ? e == null ? void 0 : e.materials.get(h[d]) : void 0, g = (d, T) => {
|
|
2236
|
+
const F = m(T), y = en(d, n, F, t, e, r, s);
|
|
2237
|
+
return y instanceof De && F && e ? qt(c, y, F, e, (x) => a.add(x), (x) => o.add(x)) : y;
|
|
2238
|
+
};
|
|
2239
|
+
l.push({ mesh: c, material: Array.isArray(c.material) ? c.material.map(g) : g(c.material, 0) });
|
|
2240
|
+
});
|
|
2241
|
+
} catch (c) {
|
|
2242
|
+
for (const [h, m] of n) h !== m && m.dispose();
|
|
2243
|
+
for (const h of r.values()) h.dispose();
|
|
2244
|
+
for (const h of a) h.dispose();
|
|
2245
|
+
for (const h of o) h.dispose();
|
|
2246
|
+
for (const h of s.values()) h.dispose();
|
|
2247
|
+
throw c;
|
|
2248
|
+
}
|
|
2249
|
+
for (const { mesh: c, material: h } of l) c.material = h;
|
|
2250
|
+
const p = new Set(l.flatMap((c) => Array.isArray(c.material) ? c.material : [c.material]));
|
|
2251
|
+
for (const [c, h] of n)
|
|
2252
|
+
c !== h && (c.dispose(), p.has(h) || h.dispose());
|
|
2253
|
+
const f = /* @__PURE__ */ new Set();
|
|
2254
|
+
for (const c of p) for (const h of Object.values(c)) h instanceof Y && f.add(h);
|
|
2255
|
+
for (const c of r.values()) f.has(c) || c.dispose();
|
|
2256
|
+
for (const c of s.values()) f.has(c) || c.dispose();
|
|
2257
|
+
const u = [...p].flatMap((c) => c.userData.fbxConversionReport ? [c.userData.fbxConversionReport] : []);
|
|
2258
|
+
return i.userData.fbxConversionReports = u, u;
|
|
2259
|
+
}
|
|
2260
|
+
function en(i, e, t, n, r, s = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map()) {
|
|
2261
|
+
var E, b, D;
|
|
2262
|
+
const o = e.get(i);
|
|
2263
|
+
if (o) return o;
|
|
2264
|
+
if (!(i instanceof W) && !(i instanceof Se))
|
|
2265
|
+
return e.set(i, i), i;
|
|
2266
|
+
const l = i instanceof W ? i : null, p = (w, R) => {
|
|
2267
|
+
var _;
|
|
2268
|
+
const P = (_ = t == null ? void 0 : t.values.get(w)) == null ? void 0 : _[0];
|
|
2269
|
+
return typeof P == "number" && Number.isFinite(P) ? P : R;
|
|
2270
|
+
}, f = (w, R) => {
|
|
2271
|
+
const P = t == null ? void 0 : t.values.get(w);
|
|
2272
|
+
return P && P.length >= 3 && P.slice(0, 3).every((_) => typeof _ == "number" && Number.isFinite(_)) ? new k().setRGB(P[0], P[1], P[2]) : R.clone();
|
|
2273
|
+
}, u = (w) => Math.min(1, Math.max(0, w)), c = u(p("SpecularFactor", 0.25) * 2), h = Math.sqrt(0.08 * c), m = (1 + h) / (1 - h);
|
|
2274
|
+
let g = i.opacity;
|
|
2275
|
+
if (t && (g = 1 - p("TransparencyFactor", 0), g === 0 || g === 1)) {
|
|
2276
|
+
const w = (E = t.ownValues.get("Opacity")) == null ? void 0 : E[0];
|
|
2277
|
+
g = typeof w == "number" && Number.isFinite(w) ? w : 1 - f("TransparentColor", new k(0)).r;
|
|
2278
|
+
}
|
|
2279
|
+
const d = new De({
|
|
2280
|
+
name: i.name,
|
|
2281
|
+
// FBX diffuse textures supply the base color (as in Blender's importer),
|
|
2282
|
+
// not an additional tint. Multiplying the atlas by DiffuseColor can turn
|
|
2283
|
+
// blue atlas regions black when the material's constant color is red.
|
|
2284
|
+
color: i.map ? new k(16777215) : f("DiffuseColor", t ? new k(1, 1, 1) : i.color),
|
|
2285
|
+
map: i.map,
|
|
2286
|
+
emissive: i.emissiveMap ? new k(16777215) : f("EmissiveColor", t ? new k(0) : i.emissive),
|
|
2287
|
+
emissiveMap: i.emissiveMap,
|
|
2288
|
+
emissiveIntensity: p("EmissiveFactor", t ? 1 : i.emissiveIntensity),
|
|
2289
|
+
normalMap: i.normalMap,
|
|
2290
|
+
normalMapType: i.normalMapType,
|
|
2291
|
+
normalScale: i.normalScale.clone().setScalar(p("BumpFactor", 1)),
|
|
2292
|
+
bumpMap: i.bumpMap,
|
|
2293
|
+
bumpScale: i.bumpScale,
|
|
2294
|
+
displacementMap: i.displacementMap,
|
|
2295
|
+
displacementScale: i.displacementScale,
|
|
2296
|
+
displacementBias: i.displacementBias,
|
|
2297
|
+
aoMap: i.aoMap,
|
|
2298
|
+
aoMapIntensity: i.aoMapIntensity,
|
|
2299
|
+
alphaMap: i.alphaMap,
|
|
2300
|
+
opacity: u(g),
|
|
2301
|
+
transparent: i.transparent || g < 1,
|
|
2302
|
+
alphaTest: i.alphaTest,
|
|
2303
|
+
side: i.side,
|
|
2304
|
+
depthTest: i.depthTest,
|
|
2305
|
+
depthWrite: i.depthWrite,
|
|
2306
|
+
vertexColors: i.vertexColors,
|
|
2307
|
+
wireframe: i.wireframe,
|
|
2308
|
+
flatShading: i.flatShading,
|
|
2309
|
+
metalness: u(p("ReflectionFactor", 0)),
|
|
2310
|
+
ior: m,
|
|
2311
|
+
specularIntensity: 1,
|
|
2312
|
+
// Match Blender's empirical FBX Shininess -> Principled roughness mapping.
|
|
2313
|
+
// This is an importer convention, not an exact BRDF conversion.
|
|
2314
|
+
roughness: t || l ? u(1 - Math.sqrt(Math.max(0, p("Shininess", t ? 20 : l.shininess))) / 10) : 1
|
|
2315
|
+
});
|
|
2316
|
+
e.set(i, d);
|
|
2317
|
+
const T = (w) => {
|
|
2318
|
+
let R = s.get(w);
|
|
2319
|
+
return R || (R = Qt(w, "identity"), s.set(w, R)), R;
|
|
2320
|
+
}, F = t && r ? Wt(t, r) : [], y = [];
|
|
2321
|
+
for (const w of F)
|
|
2322
|
+
if (!(!["DiffuseColor", "EmissiveColor"].includes(w.role) || !r || !n) && t.textureConnections.filter((R) => R.role === w.role).length === 1)
|
|
2323
|
+
try {
|
|
2324
|
+
let R = a.get(w.id);
|
|
2325
|
+
R || (R = Ht(w, r, n), a.set(w.id, R)), w.role === "DiffuseColor" ? (d.map = R, d.color.setRGB(1, 1, 1)) : (d.emissiveMap = R, d.emissive.setRGB(1, 1, 1)), w.issues = [], y.push(w.id);
|
|
2326
|
+
} catch (R) {
|
|
2327
|
+
w.issues.push({ status: "unsupported", code: "LAYERED_TEXTURE_BAKE_REJECTED", source: `layered:${w.id}:${R instanceof Error ? R.message : String(R)}`, target: w.role });
|
|
2328
|
+
}
|
|
2329
|
+
const x = /* @__PURE__ */ new Set(), I = [], A = /* @__PURE__ */ new Set(), M = {
|
|
2330
|
+
ReflectionFactor: "metalnessMap",
|
|
2331
|
+
ReflectionColor: "metalnessMap",
|
|
2332
|
+
ShininessExponent: "roughnessMap",
|
|
2333
|
+
SpecularFactor: "specularIntensityMap",
|
|
2334
|
+
SpecularColor: "specularIntensityMap",
|
|
2335
|
+
TransparentColor: "alphaMap",
|
|
2336
|
+
TransparencyFactor: "alphaMap"
|
|
2337
|
+
};
|
|
2338
|
+
for (const w of (t == null ? void 0 : t.textureConnections) ?? []) {
|
|
2339
|
+
if ((b = r == null ? void 0 : r.layeredTextures) != null && b.has(w.id)) continue;
|
|
2340
|
+
const R = [...n ?? []].find((_) => _.ID === w.id);
|
|
2341
|
+
if (!R) {
|
|
2342
|
+
I.push(`texture:${w.id}:unresolved:${w.role}`);
|
|
2343
|
+
continue;
|
|
2344
|
+
}
|
|
2345
|
+
const P = M[w.role];
|
|
2346
|
+
if (P && A.has(P)) {
|
|
2347
|
+
I.push(`conflicting-input:${w.role}:${P}`);
|
|
2348
|
+
continue;
|
|
2349
|
+
}
|
|
2350
|
+
switch (P && A.add(P), w.role) {
|
|
2351
|
+
case "ReflectionFactor":
|
|
2352
|
+
case "ReflectionColor":
|
|
2353
|
+
d.metalnessMap = T(R), d.metalness = 1, x.add(w.role);
|
|
2354
|
+
break;
|
|
2355
|
+
case "ShininessExponent":
|
|
2356
|
+
d.roughnessMap = T(R), d.roughness = 1, x.add(w.role);
|
|
2357
|
+
break;
|
|
2358
|
+
case "SpecularFactor":
|
|
2359
|
+
case "SpecularColor":
|
|
2360
|
+
d.specularIntensityMap = T(R), d.ior = (1 + Math.sqrt(0.08)) / (1 - Math.sqrt(0.08)), d.specularIntensity = 1, x.add(w.role);
|
|
2361
|
+
break;
|
|
2362
|
+
case "TransparentColor":
|
|
2363
|
+
case "TransparencyFactor":
|
|
2364
|
+
d.alphaMap = T(R), d.opacity = 1, d.transparent = !0, x.add(w.role);
|
|
2365
|
+
break;
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
d.userData = { ...i.userData, fbxMaterialId: t == null ? void 0 : t.id };
|
|
2369
|
+
const v = (t == null ? void 0 : t.textureRoles.filter((w) => ![
|
|
2370
|
+
"DiffuseColor",
|
|
2371
|
+
"Maya|TEX_color_map",
|
|
2372
|
+
"NormalMap",
|
|
2373
|
+
"Maya|TEX_normal_map",
|
|
2374
|
+
"Bump",
|
|
2375
|
+
"EmissiveColor",
|
|
2376
|
+
"DisplacementColor",
|
|
2377
|
+
"TransparentColor",
|
|
2378
|
+
"TransparencyFactor",
|
|
2379
|
+
"Maya|TEX_ao_map"
|
|
2380
|
+
].includes(w) && !x.has(w))) ?? [];
|
|
2381
|
+
v.push(...I);
|
|
2382
|
+
for (const w of (t == null ? void 0 : t.textureConnections) ?? [])
|
|
2383
|
+
!(r == null ? void 0 : r.textures.get(w.id)) && !((D = r == null ? void 0 : r.layeredTextures) != null && D.has(w.id)) && v.push(`texture:${w.id}:layered-or-unknown`);
|
|
2384
|
+
t && !["phong", "lambert"].includes(t.shadingModel) && v.push(`shader:${t.shadingModel}`), v.length && (d.userData.fbxUnsupportedTextureRoles = v, console.warn(`[viewer] FBX material ${i.name}: unsupported texture semantics: ${v.join(", ")}`));
|
|
2385
|
+
const S = {
|
|
2386
|
+
layerStacks: F,
|
|
2387
|
+
strategy: "blender-compatible-v1",
|
|
2388
|
+
materialId: t == null ? void 0 : t.id,
|
|
2389
|
+
materialName: i.name,
|
|
2390
|
+
mappings: [
|
|
2391
|
+
{ source: "DiffuseColor", target: "color/map", rule: "texture replaces constant; raw constant RGB otherwise" },
|
|
2392
|
+
{ source: "Shininess", target: "roughness", rule: "clamp(1-sqrt(max(0,s))/10); empirical approximation" },
|
|
2393
|
+
{ source: "ReflectionFactor", target: "metalness", rule: "clamp(value); importer convention" },
|
|
2394
|
+
{ source: "SpecularFactor", target: "ior", rule: "match normal-incidence F0 only" },
|
|
2395
|
+
...[...x].map((w) => ({ source: w, target: M[w], rule: "raw R; identity; replaces scalar constant" }))
|
|
2396
|
+
],
|
|
2397
|
+
issues: [
|
|
2398
|
+
...F.flatMap((w) => w.issues),
|
|
2399
|
+
...y.map((w) => ({ status: "approximate", code: "LAYERED_TEXTURE_BAKED", source: `layered:${w}:linear-color-v1; opaque base; first connection bottom`, target: "RGBA8 color texture" })),
|
|
2400
|
+
{ status: "approximate", code: "PHONG_TO_PBR", source: (t == null ? void 0 : t.shadingModel) ?? i.type, target: "MeshPhysicalMaterial" },
|
|
2401
|
+
...v.map((w) => ({ status: "unsupported", code: "UNSUPPORTED_SEMANTICS", source: w }))
|
|
2402
|
+
]
|
|
2403
|
+
};
|
|
2404
|
+
return d.userData.fbxConversionReport = S, d.visible = i.visible, d.toneMapped = i.toneMapped, d.clippingPlanes = i.clippingPlanes, d.clipIntersection = i.clipIntersection, d.clipShadows = i.clipShadows, d.polygonOffset = i.polygonOffset, d.polygonOffsetFactor = i.polygonOffsetFactor, d.polygonOffsetUnits = i.polygonOffsetUnits, d.dithering = i.dithering, d.needsUpdate = !0, e.set(i, d), d;
|
|
2405
|
+
}
|
|
2406
|
+
function fn(i, e) {
|
|
2407
|
+
let t = !1, n = null, r = null, s = "z", a, o = null, l;
|
|
2408
|
+
const p = () => {
|
|
2409
|
+
t = !0;
|
|
2410
|
+
}, f = (async () => {
|
|
2411
|
+
s = e.options.upAxis ?? ge(e.format);
|
|
2412
|
+
let u = null;
|
|
2413
|
+
try {
|
|
2414
|
+
if (t || e.signal.aborted) throw le();
|
|
2415
|
+
const c = i.url ?? await i.resolve(i.entryPath ?? "");
|
|
2416
|
+
if (u = new ce(), u.name = "viewer-model-root", e.format === "fbx") {
|
|
2417
|
+
const m = await fetch(c, { signal: e.signal });
|
|
2418
|
+
if (!m.ok) throw new Error(`FBX request failed: ${m.status} ${m.statusText}`);
|
|
2419
|
+
const g = await m.arrayBuffer();
|
|
2420
|
+
s = e.options.upAxis ?? Ot(g) ?? ge(e.format);
|
|
2421
|
+
const d = _t(g), T = await Pt(g, i, d);
|
|
2422
|
+
l = T.textures, u.add(T.root);
|
|
2423
|
+
const y = Jt(u, d, l).flatMap((I) => I.issues.filter((A) => A.status === "unsupported" || A.code === "TEXTURE_ROTATION_PROFILE" || A.code === "LAYERED_TEXTURE_BAKED").map((A) => `${I.materialName || I.materialId || "material"}: ${A.source}`));
|
|
2424
|
+
y.length && (o = {
|
|
2425
|
+
code: "W_FBX_MATERIAL_APPROXIMATED",
|
|
2426
|
+
stage: "material-conversion",
|
|
2427
|
+
message: `FBX 材质存在未支持或按兼容规则近似处理的语义:${[...new Set(y)].join("、")}。当前为近似预览。`
|
|
2428
|
+
});
|
|
2429
|
+
const x = [...new Set(T.textureFailures)];
|
|
2430
|
+
x.length && (o = {
|
|
2431
|
+
code: "W_FBX_TEXTURE_UNAVAILABLE",
|
|
2432
|
+
stage: "material-conversion",
|
|
2433
|
+
message: `FBX 贴图缺失或加载失败,已按无贴图降级显示:${x.join("、")}。${o ? `另有材质近似处理:${o.message}` : ""}`
|
|
2434
|
+
});
|
|
2435
|
+
} else {
|
|
2436
|
+
const m = new it(), g = new lt();
|
|
2437
|
+
try {
|
|
2438
|
+
e.options.dracoDecoderPath && m.setDecoderPath(e.options.dracoDecoderPath), g.setDRACOLoader(m);
|
|
2439
|
+
const d = await g.loadAsync(c), T = d.scenes.filter((F) => F !== d.scene);
|
|
2440
|
+
if (u.add(d.scene), t || e.signal.aborted) {
|
|
2441
|
+
for (const F of T) u.add(F);
|
|
2442
|
+
throw le();
|
|
2443
|
+
}
|
|
2444
|
+
} finally {
|
|
2445
|
+
m.dispose();
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
if (t || e.signal.aborted) throw le();
|
|
2449
|
+
ye(u, s), tn(u);
|
|
2450
|
+
const h = new ut(u, e.options.simulationTheme, void 0, "model");
|
|
2451
|
+
h.setCacheInvalidationCallback(e.invalidateTransmissionCaches), n = u, r = h, u = null;
|
|
2452
|
+
} finally {
|
|
2453
|
+
u && (we(u, l), l = void 0);
|
|
2454
|
+
}
|
|
2455
|
+
})();
|
|
2456
|
+
return f.catch(() => {
|
|
2457
|
+
}), {
|
|
2458
|
+
id: `model-${Math.random().toString(36).slice(2)}`,
|
|
2459
|
+
opened: f,
|
|
2460
|
+
get warning() {
|
|
2461
|
+
return o;
|
|
2462
|
+
},
|
|
2463
|
+
get root() {
|
|
2464
|
+
return (r == null ? void 0 : r.root) ?? null;
|
|
2465
|
+
},
|
|
2466
|
+
getFitBounds() {
|
|
2467
|
+
return (r == null ? void 0 : r.getModelBounds()) ?? null;
|
|
2468
|
+
},
|
|
2469
|
+
beforeRender(u, c, h) {
|
|
2470
|
+
return r == null ? void 0 : r.beforeRender(u, c, h);
|
|
2471
|
+
},
|
|
2472
|
+
capabilities: { canPlay: !1, canPause: !1, canReset: !1, hasPhysics: !1, canReorientUpAxis: !0, canToggleGround: !0 },
|
|
2473
|
+
// Session presentation overrides are only consulted for `interactionMode`
|
|
2474
|
+
// and `fitPolicy`; the UI group comes from the loader descriptor. Keep the
|
|
2475
|
+
// two in sync so the override never reads as a contradictory value.
|
|
2476
|
+
presentation: { preferredViewMode: "3d", interactionMode: "object", uiProfile: "model", fitPolicy: "fit-on-ready" },
|
|
2477
|
+
getUpAxis() {
|
|
2478
|
+
return n ? s : null;
|
|
2479
|
+
},
|
|
2480
|
+
setTheme(u) {
|
|
2481
|
+
r == null || r.setTheme(u);
|
|
2482
|
+
},
|
|
2483
|
+
setGroundVisible(u) {
|
|
2484
|
+
r == null || r.setGroundVisible(u);
|
|
2485
|
+
},
|
|
2486
|
+
getGroundVisible() {
|
|
2487
|
+
return (r == null ? void 0 : r.getGroundVisible()) ?? !0;
|
|
2488
|
+
},
|
|
2489
|
+
getGroundGridScale() {
|
|
2490
|
+
return (r == null ? void 0 : r.getGroundGridScale()) ?? ct;
|
|
2491
|
+
},
|
|
2492
|
+
setUpAxis(u) {
|
|
2493
|
+
if (t || !n || !r || !ye(n, u)) return;
|
|
2494
|
+
s = u, r.reseatGround();
|
|
2495
|
+
const c = r.getModelBounds();
|
|
2496
|
+
e.requestRender(), e.fit(c, { padding: 1.15 });
|
|
2497
|
+
},
|
|
2498
|
+
beginDispose: p,
|
|
2499
|
+
dispose() {
|
|
2500
|
+
return p(), a ?? (a = f.catch(() => {
|
|
2501
|
+
}).then(() => {
|
|
2502
|
+
r == null || r.dispose(), r = null, n && we(n, l), n = null, l = void 0;
|
|
2503
|
+
})), a;
|
|
2504
|
+
}
|
|
2505
|
+
};
|
|
2506
|
+
}
|
|
2507
|
+
function tn(i) {
|
|
2508
|
+
i.updateMatrixWorld(!0);
|
|
2509
|
+
const e = new ot().setFromObject(i);
|
|
2510
|
+
if (e.isEmpty()) throw new Error("模型不包含可显示的几何内容。");
|
|
2511
|
+
const t = e.getSize(new V()), n = Math.max(t.x, t.y, t.z);
|
|
2512
|
+
if (!Number.isFinite(n) || n <= 0) throw new Error("模型尺寸无效。");
|
|
2513
|
+
}
|
|
2514
|
+
function le() {
|
|
2515
|
+
return Object.assign(new Error("Model load aborted."), { name: "AbortError", code: "E_ABORTED" });
|
|
2516
|
+
}
|
|
2517
|
+
export {
|
|
2518
|
+
fn as createModelSession
|
|
2519
|
+
};
|