@shopware-ag/dive 1.18.5-beta.1 → 1.18.5-beta.3
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/build/AR-BzVanQ-t.js +722 -0
- package/build/AR-BzVanQ-t.js.map +1 -0
- package/build/AR-ySzrfSW3.cjs +2 -0
- package/build/AR-ySzrfSW3.cjs.map +1 -0
- package/build/IO-BTWL9Zfp.cjs +19 -0
- package/build/IO-BTWL9Zfp.cjs.map +1 -0
- package/build/IO-CYzpSt1J.js +1289 -0
- package/build/IO-CYzpSt1J.js.map +1 -0
- package/build/MediaCreator-BFa3Xfwk.js +22 -0
- package/build/MediaCreator-BFa3Xfwk.js.map +1 -0
- package/build/MediaCreator-BqLcaXbl.cjs +2 -0
- package/build/MediaCreator-BqLcaXbl.cjs.map +1 -0
- package/build/{dive-C-5_QywE.cjs → dive-BTQZqHRt.cjs} +184 -184
- package/build/{dive-C-5_QywE.cjs.map → dive-BTQZqHRt.cjs.map} +1 -1
- package/build/{dive-BmDCwQRo.js → dive-Dk0rFfvA.js} +2747 -2706
- package/build/{dive-BmDCwQRo.js.map → dive-Dk0rFfvA.js.map} +1 -1
- package/build/dive.cjs +1 -1
- package/build/dive.js +3 -3
- package/build/src/ar/arquicklook/ARQuickLook.d.ts +2 -3
- package/build/src/com/actions/media/generatemedia.d.ts +2 -3
- package/package.json +1 -1
- package/src/ar/arquicklook/ARQuickLook.ts +75 -46
- package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +44 -79
- package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -12
- package/src/com/Communication.ts +53 -23
- package/src/com/__test__/Communication.test.ts +16 -8
- package/src/com/actions/media/generatemedia.ts +2 -3
- package/build/AR-B6LRgTEL.js +0 -1482
- package/build/AR-B6LRgTEL.js.map +0 -1
- package/build/AR-YJZL1lm5.cjs +0 -170
- package/build/AR-YJZL1lm5.cjs.map +0 -1
|
@@ -0,0 +1,1289 @@
|
|
|
1
|
+
import { P as oe, S as ae, U as ce, a as te, M as le, b as ue, c as K, W as fe, C as he, d as pe, e as ne, V as G, Q as de, B as L, f as k, g as xe, N as ge, h as W, R as Te, i as me, j as P, I as Me, k as ye, l as we, m as Ee, L as Ie, n as Ae, o as Re, p as be, q as Ne, r as Le, s as Se, G as _e } from "./dive-Dk0rFfvA.js";
|
|
2
|
+
let F, H, _, B;
|
|
3
|
+
function V(a, e = 1 / 0, s = null) {
|
|
4
|
+
H || (H = new oe(2, 2, 1, 1)), _ || (_ = new ae({
|
|
5
|
+
uniforms: { blitTexture: new ce(a) },
|
|
6
|
+
vertexShader: `
|
|
7
|
+
varying vec2 vUv;
|
|
8
|
+
void main(){
|
|
9
|
+
vUv = uv;
|
|
10
|
+
gl_Position = vec4(position.xy * 1.0,0.,.999999);
|
|
11
|
+
}`,
|
|
12
|
+
fragmentShader: `
|
|
13
|
+
uniform sampler2D blitTexture;
|
|
14
|
+
varying vec2 vUv;
|
|
15
|
+
|
|
16
|
+
void main(){
|
|
17
|
+
gl_FragColor = vec4(vUv.xy, 0, 1);
|
|
18
|
+
|
|
19
|
+
#ifdef IS_SRGB
|
|
20
|
+
gl_FragColor = LinearTosRGB( texture2D( blitTexture, vUv) );
|
|
21
|
+
#else
|
|
22
|
+
gl_FragColor = texture2D( blitTexture, vUv);
|
|
23
|
+
#endif
|
|
24
|
+
}`
|
|
25
|
+
})), _.uniforms.blitTexture.value = a, _.defines.IS_SRGB = a.colorSpace == te, _.needsUpdate = !0, B || (B = new le(H, _), B.frustumCulled = !1);
|
|
26
|
+
const n = new ue(), t = new K();
|
|
27
|
+
t.add(B), s === null && (s = F = new fe({ antialias: !1 }));
|
|
28
|
+
const i = Math.min(a.image.width, e), r = Math.min(a.image.height, e);
|
|
29
|
+
s.setSize(i, r), s.clear(), s.render(t, n);
|
|
30
|
+
const o = document.createElement("canvas"), c = o.getContext("2d");
|
|
31
|
+
o.width = i, o.height = r, c.drawImage(s.domElement, 0, 0, i, r);
|
|
32
|
+
const l = new he(o);
|
|
33
|
+
return l.minFilter = a.minFilter, l.magFilter = a.magFilter, l.wrapS = a.wrapS, l.wrapT = a.wrapT, l.name = a.name, F && (F.forceContextLoss(), F.dispose(), F = null), l;
|
|
34
|
+
}
|
|
35
|
+
const J = {
|
|
36
|
+
POSITION: [
|
|
37
|
+
"byte",
|
|
38
|
+
"byte normalized",
|
|
39
|
+
"unsigned byte",
|
|
40
|
+
"unsigned byte normalized",
|
|
41
|
+
"short",
|
|
42
|
+
"short normalized",
|
|
43
|
+
"unsigned short",
|
|
44
|
+
"unsigned short normalized"
|
|
45
|
+
],
|
|
46
|
+
NORMAL: [
|
|
47
|
+
"byte normalized",
|
|
48
|
+
"short normalized"
|
|
49
|
+
],
|
|
50
|
+
TANGENT: [
|
|
51
|
+
"byte normalized",
|
|
52
|
+
"short normalized"
|
|
53
|
+
],
|
|
54
|
+
TEXCOORD: [
|
|
55
|
+
"byte",
|
|
56
|
+
"byte normalized",
|
|
57
|
+
"unsigned byte",
|
|
58
|
+
"short",
|
|
59
|
+
"short normalized",
|
|
60
|
+
"unsigned short"
|
|
61
|
+
]
|
|
62
|
+
};
|
|
63
|
+
class q {
|
|
64
|
+
constructor() {
|
|
65
|
+
this.pluginCallbacks = [], this.register(function(e) {
|
|
66
|
+
return new ze(e);
|
|
67
|
+
}), this.register(function(e) {
|
|
68
|
+
return new ke(e);
|
|
69
|
+
}), this.register(function(e) {
|
|
70
|
+
return new je(e);
|
|
71
|
+
}), this.register(function(e) {
|
|
72
|
+
return new Ye(e);
|
|
73
|
+
}), this.register(function(e) {
|
|
74
|
+
return new Ke(e);
|
|
75
|
+
}), this.register(function(e) {
|
|
76
|
+
return new We(e);
|
|
77
|
+
}), this.register(function(e) {
|
|
78
|
+
return new He(e);
|
|
79
|
+
}), this.register(function(e) {
|
|
80
|
+
return new Ve(e);
|
|
81
|
+
}), this.register(function(e) {
|
|
82
|
+
return new qe(e);
|
|
83
|
+
}), this.register(function(e) {
|
|
84
|
+
return new Xe(e);
|
|
85
|
+
}), this.register(function(e) {
|
|
86
|
+
return new Je(e);
|
|
87
|
+
}), this.register(function(e) {
|
|
88
|
+
return new Qe(e);
|
|
89
|
+
}), this.register(function(e) {
|
|
90
|
+
return new Ze(e);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
register(e) {
|
|
94
|
+
return this.pluginCallbacks.indexOf(e) === -1 && this.pluginCallbacks.push(e), this;
|
|
95
|
+
}
|
|
96
|
+
unregister(e) {
|
|
97
|
+
return this.pluginCallbacks.indexOf(e) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e), 1), this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Parse scenes and generate GLTF output
|
|
101
|
+
* @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
|
|
102
|
+
* @param {Function} onDone Callback on completed
|
|
103
|
+
* @param {Function} onError Callback on errors
|
|
104
|
+
* @param {Object} options options
|
|
105
|
+
*/
|
|
106
|
+
parse(e, s, n, t) {
|
|
107
|
+
const i = new Pe(), r = [];
|
|
108
|
+
for (let o = 0, c = this.pluginCallbacks.length; o < c; o++)
|
|
109
|
+
r.push(this.pluginCallbacks[o](i));
|
|
110
|
+
i.setPlugins(r), i.write(e, s, t).catch(n);
|
|
111
|
+
}
|
|
112
|
+
parseAsync(e, s) {
|
|
113
|
+
const n = this;
|
|
114
|
+
return new Promise(function(t, i) {
|
|
115
|
+
n.parse(e, t, i, s);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const T = {
|
|
120
|
+
POINTS: 0,
|
|
121
|
+
LINES: 1,
|
|
122
|
+
LINE_LOOP: 2,
|
|
123
|
+
LINE_STRIP: 3,
|
|
124
|
+
TRIANGLES: 4,
|
|
125
|
+
BYTE: 5120,
|
|
126
|
+
UNSIGNED_BYTE: 5121,
|
|
127
|
+
SHORT: 5122,
|
|
128
|
+
UNSIGNED_SHORT: 5123,
|
|
129
|
+
INT: 5124,
|
|
130
|
+
UNSIGNED_INT: 5125,
|
|
131
|
+
FLOAT: 5126,
|
|
132
|
+
ARRAY_BUFFER: 34962,
|
|
133
|
+
ELEMENT_ARRAY_BUFFER: 34963,
|
|
134
|
+
NEAREST: 9728,
|
|
135
|
+
LINEAR: 9729,
|
|
136
|
+
NEAREST_MIPMAP_NEAREST: 9984,
|
|
137
|
+
LINEAR_MIPMAP_NEAREST: 9985,
|
|
138
|
+
NEAREST_MIPMAP_LINEAR: 9986,
|
|
139
|
+
LINEAR_MIPMAP_LINEAR: 9987,
|
|
140
|
+
CLAMP_TO_EDGE: 33071,
|
|
141
|
+
MIRRORED_REPEAT: 33648,
|
|
142
|
+
REPEAT: 10497
|
|
143
|
+
}, j = "KHR_mesh_quantization", R = {};
|
|
144
|
+
R[ye] = T.NEAREST;
|
|
145
|
+
R[we] = T.NEAREST_MIPMAP_NEAREST;
|
|
146
|
+
R[Ee] = T.NEAREST_MIPMAP_LINEAR;
|
|
147
|
+
R[Ie] = T.LINEAR;
|
|
148
|
+
R[Ae] = T.LINEAR_MIPMAP_NEAREST;
|
|
149
|
+
R[Re] = T.LINEAR_MIPMAP_LINEAR;
|
|
150
|
+
R[be] = T.CLAMP_TO_EDGE;
|
|
151
|
+
R[Ne] = T.REPEAT;
|
|
152
|
+
R[Le] = T.MIRRORED_REPEAT;
|
|
153
|
+
const Q = {
|
|
154
|
+
scale: "scale",
|
|
155
|
+
position: "translation",
|
|
156
|
+
quaternion: "rotation",
|
|
157
|
+
morphTargetInfluences: "weights"
|
|
158
|
+
}, Ce = new pe(), Z = 12, Ue = 1179937895, ve = 2, $ = 8, Fe = 1313821514, Oe = 5130562;
|
|
159
|
+
function O(a, e) {
|
|
160
|
+
return a.length === e.length && a.every(function(s, n) {
|
|
161
|
+
return s === e[n];
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function De(a) {
|
|
165
|
+
return new TextEncoder().encode(a).buffer;
|
|
166
|
+
}
|
|
167
|
+
function Be(a) {
|
|
168
|
+
return O(a.elements, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
169
|
+
}
|
|
170
|
+
function Ge(a, e, s) {
|
|
171
|
+
const n = {
|
|
172
|
+
min: new Array(a.itemSize).fill(Number.POSITIVE_INFINITY),
|
|
173
|
+
max: new Array(a.itemSize).fill(Number.NEGATIVE_INFINITY)
|
|
174
|
+
};
|
|
175
|
+
for (let t = e; t < e + s; t++)
|
|
176
|
+
for (let i = 0; i < a.itemSize; i++) {
|
|
177
|
+
let r;
|
|
178
|
+
a.itemSize > 4 ? r = a.array[t * a.itemSize + i] : (i === 0 ? r = a.getX(t) : i === 1 ? r = a.getY(t) : i === 2 ? r = a.getZ(t) : i === 3 && (r = a.getW(t)), a.normalized === !0 && (r = W.normalize(r, a.array))), n.min[i] = Math.min(n.min[i], r), n.max[i] = Math.max(n.max[i], r);
|
|
179
|
+
}
|
|
180
|
+
return n;
|
|
181
|
+
}
|
|
182
|
+
function re(a) {
|
|
183
|
+
return Math.ceil(a / 4) * 4;
|
|
184
|
+
}
|
|
185
|
+
function Y(a, e = 0) {
|
|
186
|
+
const s = re(a.byteLength);
|
|
187
|
+
if (s !== a.byteLength) {
|
|
188
|
+
const n = new Uint8Array(s);
|
|
189
|
+
if (n.set(new Uint8Array(a)), e !== 0)
|
|
190
|
+
for (let t = a.byteLength; t < s; t++)
|
|
191
|
+
n[t] = e;
|
|
192
|
+
return n.buffer;
|
|
193
|
+
}
|
|
194
|
+
return a;
|
|
195
|
+
}
|
|
196
|
+
function ee() {
|
|
197
|
+
return typeof document > "u" && typeof OffscreenCanvas < "u" ? new OffscreenCanvas(1, 1) : document.createElement("canvas");
|
|
198
|
+
}
|
|
199
|
+
function se(a, e) {
|
|
200
|
+
if (a.toBlob !== void 0)
|
|
201
|
+
return new Promise((n) => a.toBlob(n, e));
|
|
202
|
+
let s;
|
|
203
|
+
return e === "image/jpeg" ? s = 0.92 : e === "image/webp" && (s = 0.8), a.convertToBlob({
|
|
204
|
+
type: e,
|
|
205
|
+
quality: s
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
class Pe {
|
|
209
|
+
constructor() {
|
|
210
|
+
this.plugins = [], this.options = {}, this.pending = [], this.buffers = [], this.byteOffset = 0, this.buffers = [], this.nodeMap = /* @__PURE__ */ new Map(), this.skins = [], this.extensionsUsed = {}, this.extensionsRequired = {}, this.uids = /* @__PURE__ */ new Map(), this.uid = 0, this.json = {
|
|
211
|
+
asset: {
|
|
212
|
+
version: "2.0",
|
|
213
|
+
generator: "THREE.GLTFExporter"
|
|
214
|
+
}
|
|
215
|
+
}, this.cache = {
|
|
216
|
+
meshes: /* @__PURE__ */ new Map(),
|
|
217
|
+
attributes: /* @__PURE__ */ new Map(),
|
|
218
|
+
attributesNormalized: /* @__PURE__ */ new Map(),
|
|
219
|
+
materials: /* @__PURE__ */ new Map(),
|
|
220
|
+
textures: /* @__PURE__ */ new Map(),
|
|
221
|
+
images: /* @__PURE__ */ new Map()
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
setPlugins(e) {
|
|
225
|
+
this.plugins = e;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Parse scenes and generate GLTF output
|
|
229
|
+
* @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
|
|
230
|
+
* @param {Function} onDone Callback on completed
|
|
231
|
+
* @param {Object} options options
|
|
232
|
+
*/
|
|
233
|
+
async write(e, s, n = {}) {
|
|
234
|
+
this.options = Object.assign({
|
|
235
|
+
// default options
|
|
236
|
+
binary: !1,
|
|
237
|
+
trs: !1,
|
|
238
|
+
onlyVisible: !0,
|
|
239
|
+
maxTextureSize: 1 / 0,
|
|
240
|
+
animations: [],
|
|
241
|
+
includeCustomExtensions: !1
|
|
242
|
+
}, n), this.options.animations.length > 0 && (this.options.trs = !0), this.processInput(e), await Promise.all(this.pending);
|
|
243
|
+
const t = this, i = t.buffers, r = t.json;
|
|
244
|
+
n = t.options;
|
|
245
|
+
const o = t.extensionsUsed, c = t.extensionsRequired, l = new Blob(i, { type: "application/octet-stream" }), h = Object.keys(o), u = Object.keys(c);
|
|
246
|
+
if (h.length > 0 && (r.extensionsUsed = h), u.length > 0 && (r.extensionsRequired = u), r.buffers && r.buffers.length > 0 && (r.buffers[0].byteLength = l.size), n.binary === !0) {
|
|
247
|
+
const m = new FileReader();
|
|
248
|
+
m.readAsArrayBuffer(l), m.onloadend = function() {
|
|
249
|
+
const f = Y(m.result), p = new DataView(new ArrayBuffer($));
|
|
250
|
+
p.setUint32(0, f.byteLength, !0), p.setUint32(4, Oe, !0);
|
|
251
|
+
const d = Y(De(JSON.stringify(r)), 32), g = new DataView(new ArrayBuffer($));
|
|
252
|
+
g.setUint32(0, d.byteLength, !0), g.setUint32(4, Fe, !0);
|
|
253
|
+
const y = new ArrayBuffer(Z), b = new DataView(y);
|
|
254
|
+
b.setUint32(0, Ue, !0), b.setUint32(4, ve, !0);
|
|
255
|
+
const D = Z + g.byteLength + d.byteLength + p.byteLength + f.byteLength;
|
|
256
|
+
b.setUint32(8, D, !0);
|
|
257
|
+
const x = new Blob([
|
|
258
|
+
y,
|
|
259
|
+
g,
|
|
260
|
+
d,
|
|
261
|
+
p,
|
|
262
|
+
f
|
|
263
|
+
], { type: "application/octet-stream" }), M = new FileReader();
|
|
264
|
+
M.readAsArrayBuffer(x), M.onloadend = function() {
|
|
265
|
+
s(M.result);
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
} else if (r.buffers && r.buffers.length > 0) {
|
|
269
|
+
const m = new FileReader();
|
|
270
|
+
m.readAsDataURL(l), m.onloadend = function() {
|
|
271
|
+
const f = m.result;
|
|
272
|
+
r.buffers[0].uri = f, s(r);
|
|
273
|
+
};
|
|
274
|
+
} else
|
|
275
|
+
s(r);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Serializes a userData.
|
|
279
|
+
*
|
|
280
|
+
* @param {THREE.Object3D|THREE.Material} object
|
|
281
|
+
* @param {Object} objectDef
|
|
282
|
+
*/
|
|
283
|
+
serializeUserData(e, s) {
|
|
284
|
+
if (Object.keys(e.userData).length === 0) return;
|
|
285
|
+
const n = this.options, t = this.extensionsUsed;
|
|
286
|
+
try {
|
|
287
|
+
const i = JSON.parse(JSON.stringify(e.userData));
|
|
288
|
+
if (n.includeCustomExtensions && i.gltfExtensions) {
|
|
289
|
+
s.extensions === void 0 && (s.extensions = {});
|
|
290
|
+
for (const r in i.gltfExtensions)
|
|
291
|
+
s.extensions[r] = i.gltfExtensions[r], t[r] = !0;
|
|
292
|
+
delete i.gltfExtensions;
|
|
293
|
+
}
|
|
294
|
+
Object.keys(i).length > 0 && (s.extras = i);
|
|
295
|
+
} catch (i) {
|
|
296
|
+
console.warn("THREE.GLTFExporter: userData of '" + e.name + "' won't be serialized because of JSON.stringify error - " + i.message);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Returns ids for buffer attributes.
|
|
301
|
+
* @param {Object} object
|
|
302
|
+
* @return {Integer}
|
|
303
|
+
*/
|
|
304
|
+
getUID(e, s = !1) {
|
|
305
|
+
if (this.uids.has(e) === !1) {
|
|
306
|
+
const t = /* @__PURE__ */ new Map();
|
|
307
|
+
t.set(!0, this.uid++), t.set(!1, this.uid++), this.uids.set(e, t);
|
|
308
|
+
}
|
|
309
|
+
return this.uids.get(e).get(s);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Checks if normal attribute values are normalized.
|
|
313
|
+
*
|
|
314
|
+
* @param {BufferAttribute} normal
|
|
315
|
+
* @returns {Boolean}
|
|
316
|
+
*/
|
|
317
|
+
isNormalizedNormalAttribute(e) {
|
|
318
|
+
if (this.cache.attributesNormalized.has(e)) return !1;
|
|
319
|
+
const n = new G();
|
|
320
|
+
for (let t = 0, i = e.count; t < i; t++)
|
|
321
|
+
if (Math.abs(n.fromBufferAttribute(e, t).length() - 1) > 5e-4) return !1;
|
|
322
|
+
return !0;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Creates normalized normal buffer attribute.
|
|
326
|
+
*
|
|
327
|
+
* @param {BufferAttribute} normal
|
|
328
|
+
* @returns {BufferAttribute}
|
|
329
|
+
*
|
|
330
|
+
*/
|
|
331
|
+
createNormalizedNormalAttribute(e) {
|
|
332
|
+
const s = this.cache;
|
|
333
|
+
if (s.attributesNormalized.has(e)) return s.attributesNormalized.get(e);
|
|
334
|
+
const n = e.clone(), t = new G();
|
|
335
|
+
for (let i = 0, r = n.count; i < r; i++)
|
|
336
|
+
t.fromBufferAttribute(n, i), t.x === 0 && t.y === 0 && t.z === 0 ? t.setX(1) : t.normalize(), n.setXYZ(i, t.x, t.y, t.z);
|
|
337
|
+
return s.attributesNormalized.set(e, n), n;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Applies a texture transform, if present, to the map definition. Requires
|
|
341
|
+
* the KHR_texture_transform extension.
|
|
342
|
+
*
|
|
343
|
+
* @param {Object} mapDef
|
|
344
|
+
* @param {THREE.Texture} texture
|
|
345
|
+
*/
|
|
346
|
+
applyTextureTransform(e, s) {
|
|
347
|
+
let n = !1;
|
|
348
|
+
const t = {};
|
|
349
|
+
(s.offset.x !== 0 || s.offset.y !== 0) && (t.offset = s.offset.toArray(), n = !0), s.rotation !== 0 && (t.rotation = s.rotation, n = !0), (s.repeat.x !== 1 || s.repeat.y !== 1) && (t.scale = s.repeat.toArray(), n = !0), n && (e.extensions = e.extensions || {}, e.extensions.KHR_texture_transform = t, this.extensionsUsed.KHR_texture_transform = !0);
|
|
350
|
+
}
|
|
351
|
+
buildMetalRoughTexture(e, s) {
|
|
352
|
+
if (e === s) return e;
|
|
353
|
+
function n(f) {
|
|
354
|
+
return f.colorSpace === te ? function(d) {
|
|
355
|
+
return d < 0.04045 ? d * 0.0773993808 : Math.pow(d * 0.9478672986 + 0.0521327014, 2.4);
|
|
356
|
+
} : function(d) {
|
|
357
|
+
return d;
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures."), e instanceof k && (e = V(e)), s instanceof k && (s = V(s));
|
|
361
|
+
const t = e ? e.image : null, i = s ? s.image : null, r = Math.max(t ? t.width : 0, i ? i.width : 0), o = Math.max(t ? t.height : 0, i ? i.height : 0), c = ee();
|
|
362
|
+
c.width = r, c.height = o;
|
|
363
|
+
const l = c.getContext("2d");
|
|
364
|
+
l.fillStyle = "#00ffff", l.fillRect(0, 0, r, o);
|
|
365
|
+
const h = l.getImageData(0, 0, r, o);
|
|
366
|
+
if (t) {
|
|
367
|
+
l.drawImage(t, 0, 0, r, o);
|
|
368
|
+
const f = n(e), p = l.getImageData(0, 0, r, o).data;
|
|
369
|
+
for (let d = 2; d < p.length; d += 4)
|
|
370
|
+
h.data[d] = f(p[d] / 256) * 256;
|
|
371
|
+
}
|
|
372
|
+
if (i) {
|
|
373
|
+
l.drawImage(i, 0, 0, r, o);
|
|
374
|
+
const f = n(s), p = l.getImageData(0, 0, r, o).data;
|
|
375
|
+
for (let d = 1; d < p.length; d += 4)
|
|
376
|
+
h.data[d] = f(p[d] / 256) * 256;
|
|
377
|
+
}
|
|
378
|
+
l.putImageData(h, 0, 0);
|
|
379
|
+
const m = (e || s).clone();
|
|
380
|
+
return m.source = new xe(c), m.colorSpace = ge, m.channel = (e || s).channel, e && s && e.channel !== s.channel && console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match."), m;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Process a buffer to append to the default one.
|
|
384
|
+
* @param {ArrayBuffer} buffer
|
|
385
|
+
* @return {Integer}
|
|
386
|
+
*/
|
|
387
|
+
processBuffer(e) {
|
|
388
|
+
const s = this.json, n = this.buffers;
|
|
389
|
+
return s.buffers || (s.buffers = [{ byteLength: 0 }]), n.push(e), 0;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Process and generate a BufferView
|
|
393
|
+
* @param {BufferAttribute} attribute
|
|
394
|
+
* @param {number} componentType
|
|
395
|
+
* @param {number} start
|
|
396
|
+
* @param {number} count
|
|
397
|
+
* @param {number} target (Optional) Target usage of the BufferView
|
|
398
|
+
* @return {Object}
|
|
399
|
+
*/
|
|
400
|
+
processBufferView(e, s, n, t, i) {
|
|
401
|
+
const r = this.json;
|
|
402
|
+
r.bufferViews || (r.bufferViews = []);
|
|
403
|
+
let o;
|
|
404
|
+
switch (s) {
|
|
405
|
+
case T.BYTE:
|
|
406
|
+
case T.UNSIGNED_BYTE:
|
|
407
|
+
o = 1;
|
|
408
|
+
break;
|
|
409
|
+
case T.SHORT:
|
|
410
|
+
case T.UNSIGNED_SHORT:
|
|
411
|
+
o = 2;
|
|
412
|
+
break;
|
|
413
|
+
default:
|
|
414
|
+
o = 4;
|
|
415
|
+
}
|
|
416
|
+
let c = e.itemSize * o;
|
|
417
|
+
i === T.ARRAY_BUFFER && (c = Math.ceil(c / 4) * 4);
|
|
418
|
+
const l = re(t * c), h = new DataView(new ArrayBuffer(l));
|
|
419
|
+
let u = 0;
|
|
420
|
+
for (let p = n; p < n + t; p++) {
|
|
421
|
+
for (let d = 0; d < e.itemSize; d++) {
|
|
422
|
+
let g;
|
|
423
|
+
e.itemSize > 4 ? g = e.array[p * e.itemSize + d] : (d === 0 ? g = e.getX(p) : d === 1 ? g = e.getY(p) : d === 2 ? g = e.getZ(p) : d === 3 && (g = e.getW(p)), e.normalized === !0 && (g = W.normalize(g, e.array))), s === T.FLOAT ? h.setFloat32(u, g, !0) : s === T.INT ? h.setInt32(u, g, !0) : s === T.UNSIGNED_INT ? h.setUint32(u, g, !0) : s === T.SHORT ? h.setInt16(u, g, !0) : s === T.UNSIGNED_SHORT ? h.setUint16(u, g, !0) : s === T.BYTE ? h.setInt8(u, g) : s === T.UNSIGNED_BYTE && h.setUint8(u, g), u += o;
|
|
424
|
+
}
|
|
425
|
+
u % c !== 0 && (u += c - u % c);
|
|
426
|
+
}
|
|
427
|
+
const m = {
|
|
428
|
+
buffer: this.processBuffer(h.buffer),
|
|
429
|
+
byteOffset: this.byteOffset,
|
|
430
|
+
byteLength: l
|
|
431
|
+
};
|
|
432
|
+
return i !== void 0 && (m.target = i), i === T.ARRAY_BUFFER && (m.byteStride = c), this.byteOffset += l, r.bufferViews.push(m), {
|
|
433
|
+
id: r.bufferViews.length - 1,
|
|
434
|
+
byteLength: 0
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Process and generate a BufferView from an image Blob.
|
|
439
|
+
* @param {Blob} blob
|
|
440
|
+
* @return {Promise<Integer>}
|
|
441
|
+
*/
|
|
442
|
+
processBufferViewImage(e) {
|
|
443
|
+
const s = this, n = s.json;
|
|
444
|
+
return n.bufferViews || (n.bufferViews = []), new Promise(function(t) {
|
|
445
|
+
const i = new FileReader();
|
|
446
|
+
i.readAsArrayBuffer(e), i.onloadend = function() {
|
|
447
|
+
const r = Y(i.result), o = {
|
|
448
|
+
buffer: s.processBuffer(r),
|
|
449
|
+
byteOffset: s.byteOffset,
|
|
450
|
+
byteLength: r.byteLength
|
|
451
|
+
};
|
|
452
|
+
s.byteOffset += r.byteLength, t(n.bufferViews.push(o) - 1);
|
|
453
|
+
};
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Process attribute to generate an accessor
|
|
458
|
+
* @param {BufferAttribute} attribute Attribute to process
|
|
459
|
+
* @param {THREE.BufferGeometry} geometry (Optional) Geometry used for truncated draw range
|
|
460
|
+
* @param {Integer} start (Optional)
|
|
461
|
+
* @param {Integer} count (Optional)
|
|
462
|
+
* @return {Integer|null} Index of the processed accessor on the "accessors" array
|
|
463
|
+
*/
|
|
464
|
+
processAccessor(e, s, n, t) {
|
|
465
|
+
const i = this.json, r = {
|
|
466
|
+
1: "SCALAR",
|
|
467
|
+
2: "VEC2",
|
|
468
|
+
3: "VEC3",
|
|
469
|
+
4: "VEC4",
|
|
470
|
+
9: "MAT3",
|
|
471
|
+
16: "MAT4"
|
|
472
|
+
};
|
|
473
|
+
let o;
|
|
474
|
+
if (e.array.constructor === Float32Array)
|
|
475
|
+
o = T.FLOAT;
|
|
476
|
+
else if (e.array.constructor === Int32Array)
|
|
477
|
+
o = T.INT;
|
|
478
|
+
else if (e.array.constructor === Uint32Array)
|
|
479
|
+
o = T.UNSIGNED_INT;
|
|
480
|
+
else if (e.array.constructor === Int16Array)
|
|
481
|
+
o = T.SHORT;
|
|
482
|
+
else if (e.array.constructor === Uint16Array)
|
|
483
|
+
o = T.UNSIGNED_SHORT;
|
|
484
|
+
else if (e.array.constructor === Int8Array)
|
|
485
|
+
o = T.BYTE;
|
|
486
|
+
else if (e.array.constructor === Uint8Array)
|
|
487
|
+
o = T.UNSIGNED_BYTE;
|
|
488
|
+
else
|
|
489
|
+
throw new Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: " + e.array.constructor.name);
|
|
490
|
+
if (n === void 0 && (n = 0), (t === void 0 || t === 1 / 0) && (t = e.count), t === 0) return null;
|
|
491
|
+
const c = Ge(e, n, t);
|
|
492
|
+
let l;
|
|
493
|
+
s !== void 0 && (l = e === s.index ? T.ELEMENT_ARRAY_BUFFER : T.ARRAY_BUFFER);
|
|
494
|
+
const h = this.processBufferView(e, o, n, t, l), u = {
|
|
495
|
+
bufferView: h.id,
|
|
496
|
+
byteOffset: h.byteOffset,
|
|
497
|
+
componentType: o,
|
|
498
|
+
count: t,
|
|
499
|
+
max: c.max,
|
|
500
|
+
min: c.min,
|
|
501
|
+
type: r[e.itemSize]
|
|
502
|
+
};
|
|
503
|
+
return e.normalized === !0 && (u.normalized = !0), i.accessors || (i.accessors = []), i.accessors.push(u) - 1;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Process image
|
|
507
|
+
* @param {Image} image to process
|
|
508
|
+
* @param {Integer} format of the image (RGBAFormat)
|
|
509
|
+
* @param {Boolean} flipY before writing out the image
|
|
510
|
+
* @param {String} mimeType export format
|
|
511
|
+
* @return {Integer} Index of the processed texture in the "images" array
|
|
512
|
+
*/
|
|
513
|
+
processImage(e, s, n, t = "image/png") {
|
|
514
|
+
if (e !== null) {
|
|
515
|
+
const i = this, r = i.cache, o = i.json, c = i.options, l = i.pending;
|
|
516
|
+
r.images.has(e) || r.images.set(e, {});
|
|
517
|
+
const h = r.images.get(e), u = t + ":flipY/" + n.toString();
|
|
518
|
+
if (h[u] !== void 0) return h[u];
|
|
519
|
+
o.images || (o.images = []);
|
|
520
|
+
const m = { mimeType: t }, f = ee();
|
|
521
|
+
f.width = Math.min(e.width, c.maxTextureSize), f.height = Math.min(e.height, c.maxTextureSize);
|
|
522
|
+
const p = f.getContext("2d");
|
|
523
|
+
if (n === !0 && (p.translate(0, f.height), p.scale(1, -1)), e.data !== void 0) {
|
|
524
|
+
s !== Te && console.error("GLTFExporter: Only RGBAFormat is supported.", s), (e.width > c.maxTextureSize || e.height > c.maxTextureSize) && console.warn("GLTFExporter: Image size is bigger than maxTextureSize", e);
|
|
525
|
+
const g = new Uint8ClampedArray(e.height * e.width * 4);
|
|
526
|
+
for (let y = 0; y < g.length; y += 4)
|
|
527
|
+
g[y + 0] = e.data[y + 0], g[y + 1] = e.data[y + 1], g[y + 2] = e.data[y + 2], g[y + 3] = e.data[y + 3];
|
|
528
|
+
p.putImageData(new ImageData(g, e.width, e.height), 0, 0);
|
|
529
|
+
} else if (typeof HTMLImageElement < "u" && e instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && e instanceof HTMLCanvasElement || typeof ImageBitmap < "u" && e instanceof ImageBitmap || typeof OffscreenCanvas < "u" && e instanceof OffscreenCanvas)
|
|
530
|
+
p.drawImage(e, 0, 0, f.width, f.height);
|
|
531
|
+
else
|
|
532
|
+
throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");
|
|
533
|
+
c.binary === !0 ? l.push(
|
|
534
|
+
se(f, t).then((g) => i.processBufferViewImage(g)).then((g) => {
|
|
535
|
+
m.bufferView = g;
|
|
536
|
+
})
|
|
537
|
+
) : f.toDataURL !== void 0 ? m.uri = f.toDataURL(t) : l.push(
|
|
538
|
+
se(f, t).then((g) => new FileReader().readAsDataURL(g)).then((g) => {
|
|
539
|
+
m.uri = g;
|
|
540
|
+
})
|
|
541
|
+
);
|
|
542
|
+
const d = o.images.push(m) - 1;
|
|
543
|
+
return h[u] = d, d;
|
|
544
|
+
} else
|
|
545
|
+
throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.");
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Process sampler
|
|
549
|
+
* @param {Texture} map Texture to process
|
|
550
|
+
* @return {Integer} Index of the processed texture in the "samplers" array
|
|
551
|
+
*/
|
|
552
|
+
processSampler(e) {
|
|
553
|
+
const s = this.json;
|
|
554
|
+
s.samplers || (s.samplers = []);
|
|
555
|
+
const n = {
|
|
556
|
+
magFilter: R[e.magFilter],
|
|
557
|
+
minFilter: R[e.minFilter],
|
|
558
|
+
wrapS: R[e.wrapS],
|
|
559
|
+
wrapT: R[e.wrapT]
|
|
560
|
+
};
|
|
561
|
+
return s.samplers.push(n) - 1;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Process texture
|
|
565
|
+
* @param {Texture} map Map to process
|
|
566
|
+
* @return {Integer} Index of the processed texture in the "textures" array
|
|
567
|
+
*/
|
|
568
|
+
processTexture(e) {
|
|
569
|
+
const n = this.options, t = this.cache, i = this.json;
|
|
570
|
+
if (t.textures.has(e)) return t.textures.get(e);
|
|
571
|
+
i.textures || (i.textures = []), e instanceof k && (e = V(e, n.maxTextureSize));
|
|
572
|
+
let r = e.userData.mimeType;
|
|
573
|
+
r === "image/webp" && (r = "image/png");
|
|
574
|
+
const o = {
|
|
575
|
+
sampler: this.processSampler(e),
|
|
576
|
+
source: this.processImage(e.image, e.format, e.flipY, r)
|
|
577
|
+
};
|
|
578
|
+
e.name && (o.name = e.name), this._invokeAll(function(l) {
|
|
579
|
+
l.writeTexture && l.writeTexture(e, o);
|
|
580
|
+
});
|
|
581
|
+
const c = i.textures.push(o) - 1;
|
|
582
|
+
return t.textures.set(e, c), c;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Process material
|
|
586
|
+
* @param {THREE.Material} material Material to process
|
|
587
|
+
* @return {Integer|null} Index of the processed material in the "materials" array
|
|
588
|
+
*/
|
|
589
|
+
processMaterial(e) {
|
|
590
|
+
const s = this.cache, n = this.json;
|
|
591
|
+
if (s.materials.has(e)) return s.materials.get(e);
|
|
592
|
+
if (e.isShaderMaterial)
|
|
593
|
+
return console.warn("GLTFExporter: THREE.ShaderMaterial not supported."), null;
|
|
594
|
+
n.materials || (n.materials = []);
|
|
595
|
+
const t = { pbrMetallicRoughness: {} };
|
|
596
|
+
e.isMeshStandardMaterial !== !0 && e.isMeshBasicMaterial !== !0 && console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");
|
|
597
|
+
const i = e.color.toArray().concat([e.opacity]);
|
|
598
|
+
if (O(i, [1, 1, 1, 1]) || (t.pbrMetallicRoughness.baseColorFactor = i), e.isMeshStandardMaterial ? (t.pbrMetallicRoughness.metallicFactor = e.metalness, t.pbrMetallicRoughness.roughnessFactor = e.roughness) : (t.pbrMetallicRoughness.metallicFactor = 0.5, t.pbrMetallicRoughness.roughnessFactor = 0.5), e.metalnessMap || e.roughnessMap) {
|
|
599
|
+
const o = this.buildMetalRoughTexture(e.metalnessMap, e.roughnessMap), c = {
|
|
600
|
+
index: this.processTexture(o),
|
|
601
|
+
channel: o.channel
|
|
602
|
+
};
|
|
603
|
+
this.applyTextureTransform(c, o), t.pbrMetallicRoughness.metallicRoughnessTexture = c;
|
|
604
|
+
}
|
|
605
|
+
if (e.map) {
|
|
606
|
+
const o = {
|
|
607
|
+
index: this.processTexture(e.map),
|
|
608
|
+
texCoord: e.map.channel
|
|
609
|
+
};
|
|
610
|
+
this.applyTextureTransform(o, e.map), t.pbrMetallicRoughness.baseColorTexture = o;
|
|
611
|
+
}
|
|
612
|
+
if (e.emissive) {
|
|
613
|
+
const o = e.emissive;
|
|
614
|
+
if (Math.max(o.r, o.g, o.b) > 0 && (t.emissiveFactor = e.emissive.toArray()), e.emissiveMap) {
|
|
615
|
+
const l = {
|
|
616
|
+
index: this.processTexture(e.emissiveMap),
|
|
617
|
+
texCoord: e.emissiveMap.channel
|
|
618
|
+
};
|
|
619
|
+
this.applyTextureTransform(l, e.emissiveMap), t.emissiveTexture = l;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
if (e.normalMap) {
|
|
623
|
+
const o = {
|
|
624
|
+
index: this.processTexture(e.normalMap),
|
|
625
|
+
texCoord: e.normalMap.channel
|
|
626
|
+
};
|
|
627
|
+
e.normalScale && e.normalScale.x !== 1 && (o.scale = e.normalScale.x), this.applyTextureTransform(o, e.normalMap), t.normalTexture = o;
|
|
628
|
+
}
|
|
629
|
+
if (e.aoMap) {
|
|
630
|
+
const o = {
|
|
631
|
+
index: this.processTexture(e.aoMap),
|
|
632
|
+
texCoord: e.aoMap.channel
|
|
633
|
+
};
|
|
634
|
+
e.aoMapIntensity !== 1 && (o.strength = e.aoMapIntensity), this.applyTextureTransform(o, e.aoMap), t.occlusionTexture = o;
|
|
635
|
+
}
|
|
636
|
+
e.transparent ? t.alphaMode = "BLEND" : e.alphaTest > 0 && (t.alphaMode = "MASK", t.alphaCutoff = e.alphaTest), e.side === me && (t.doubleSided = !0), e.name !== "" && (t.name = e.name), this.serializeUserData(e, t), this._invokeAll(function(o) {
|
|
637
|
+
o.writeMaterial && o.writeMaterial(e, t);
|
|
638
|
+
});
|
|
639
|
+
const r = n.materials.push(t) - 1;
|
|
640
|
+
return s.materials.set(e, r), r;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Process mesh
|
|
644
|
+
* @param {THREE.Mesh} mesh Mesh to process
|
|
645
|
+
* @return {Integer|null} Index of the processed mesh in the "meshes" array
|
|
646
|
+
*/
|
|
647
|
+
processMesh(e) {
|
|
648
|
+
const s = this.cache, n = this.json, t = [e.geometry.uuid];
|
|
649
|
+
if (Array.isArray(e.material))
|
|
650
|
+
for (let x = 0, M = e.material.length; x < M; x++)
|
|
651
|
+
t.push(e.material[x].uuid);
|
|
652
|
+
else
|
|
653
|
+
t.push(e.material.uuid);
|
|
654
|
+
const i = t.join(":");
|
|
655
|
+
if (s.meshes.has(i)) return s.meshes.get(i);
|
|
656
|
+
const r = e.geometry;
|
|
657
|
+
let o;
|
|
658
|
+
e.isLineSegments ? o = T.LINES : e.isLineLoop ? o = T.LINE_LOOP : e.isLine ? o = T.LINE_STRIP : e.isPoints ? o = T.POINTS : o = e.material.wireframe ? T.LINES : T.TRIANGLES;
|
|
659
|
+
const c = {}, l = {}, h = [], u = [], m = {
|
|
660
|
+
uv: "TEXCOORD_0",
|
|
661
|
+
uv1: "TEXCOORD_1",
|
|
662
|
+
uv2: "TEXCOORD_2",
|
|
663
|
+
uv3: "TEXCOORD_3",
|
|
664
|
+
color: "COLOR_0",
|
|
665
|
+
skinWeight: "WEIGHTS_0",
|
|
666
|
+
skinIndex: "JOINTS_0"
|
|
667
|
+
}, f = r.getAttribute("normal");
|
|
668
|
+
f !== void 0 && !this.isNormalizedNormalAttribute(f) && (console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one."), r.setAttribute("normal", this.createNormalizedNormalAttribute(f)));
|
|
669
|
+
let p = null;
|
|
670
|
+
for (let x in r.attributes) {
|
|
671
|
+
if (x.slice(0, 5) === "morph") continue;
|
|
672
|
+
const M = r.attributes[x];
|
|
673
|
+
if (x = m[x] || x.toUpperCase(), /^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(x) || (x = "_" + x), s.attributes.has(this.getUID(M))) {
|
|
674
|
+
l[x] = s.attributes.get(this.getUID(M));
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
p = null;
|
|
678
|
+
const E = M.array;
|
|
679
|
+
x === "JOINTS_0" && !(E instanceof Uint16Array) && !(E instanceof Uint8Array) && (console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.'), p = new L(new Uint16Array(E), M.itemSize, M.normalized));
|
|
680
|
+
const A = this.processAccessor(p || M, r);
|
|
681
|
+
A !== null && (x.startsWith("_") || this.detectMeshQuantization(x, M), l[x] = A, s.attributes.set(this.getUID(M), A));
|
|
682
|
+
}
|
|
683
|
+
if (f !== void 0 && r.setAttribute("normal", f), Object.keys(l).length === 0) return null;
|
|
684
|
+
if (e.morphTargetInfluences !== void 0 && e.morphTargetInfluences.length > 0) {
|
|
685
|
+
const x = [], M = [], w = {};
|
|
686
|
+
if (e.morphTargetDictionary !== void 0)
|
|
687
|
+
for (const E in e.morphTargetDictionary)
|
|
688
|
+
w[e.morphTargetDictionary[E]] = E;
|
|
689
|
+
for (let E = 0; E < e.morphTargetInfluences.length; ++E) {
|
|
690
|
+
const A = {};
|
|
691
|
+
let X = !1;
|
|
692
|
+
for (const C in r.morphAttributes) {
|
|
693
|
+
if (C !== "position" && C !== "normal") {
|
|
694
|
+
X || (console.warn("GLTFExporter: Only POSITION and NORMAL morph are supported."), X = !0);
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
const N = r.morphAttributes[C][E], z = C.toUpperCase(), U = r.attributes[C];
|
|
698
|
+
if (s.attributes.has(this.getUID(N, !0))) {
|
|
699
|
+
A[z] = s.attributes.get(this.getUID(N, !0));
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
const v = N.clone();
|
|
703
|
+
if (!r.morphTargetsRelative)
|
|
704
|
+
for (let I = 0, ie = N.count; I < ie; I++)
|
|
705
|
+
for (let S = 0; S < N.itemSize; S++)
|
|
706
|
+
S === 0 && v.setX(I, N.getX(I) - U.getX(I)), S === 1 && v.setY(I, N.getY(I) - U.getY(I)), S === 2 && v.setZ(I, N.getZ(I) - U.getZ(I)), S === 3 && v.setW(I, N.getW(I) - U.getW(I));
|
|
707
|
+
A[z] = this.processAccessor(v, r), s.attributes.set(this.getUID(U, !0), A[z]);
|
|
708
|
+
}
|
|
709
|
+
u.push(A), x.push(e.morphTargetInfluences[E]), e.morphTargetDictionary !== void 0 && M.push(w[E]);
|
|
710
|
+
}
|
|
711
|
+
c.weights = x, M.length > 0 && (c.extras = {}, c.extras.targetNames = M);
|
|
712
|
+
}
|
|
713
|
+
const d = Array.isArray(e.material);
|
|
714
|
+
if (d && r.groups.length === 0) return null;
|
|
715
|
+
let g = !1;
|
|
716
|
+
if (d && r.index === null) {
|
|
717
|
+
const x = [];
|
|
718
|
+
for (let M = 0, w = r.attributes.position.count; M < w; M++)
|
|
719
|
+
x[M] = M;
|
|
720
|
+
r.setIndex(x), g = !0;
|
|
721
|
+
}
|
|
722
|
+
const y = d ? e.material : [e.material], b = d ? r.groups : [{ materialIndex: 0, start: void 0, count: void 0 }];
|
|
723
|
+
for (let x = 0, M = b.length; x < M; x++) {
|
|
724
|
+
const w = {
|
|
725
|
+
mode: o,
|
|
726
|
+
attributes: l
|
|
727
|
+
};
|
|
728
|
+
if (this.serializeUserData(r, w), u.length > 0 && (w.targets = u), r.index !== null) {
|
|
729
|
+
let A = this.getUID(r.index);
|
|
730
|
+
(b[x].start !== void 0 || b[x].count !== void 0) && (A += ":" + b[x].start + ":" + b[x].count), s.attributes.has(A) ? w.indices = s.attributes.get(A) : (w.indices = this.processAccessor(r.index, r, b[x].start, b[x].count), s.attributes.set(A, w.indices)), w.indices === null && delete w.indices;
|
|
731
|
+
}
|
|
732
|
+
const E = this.processMaterial(y[b[x].materialIndex]);
|
|
733
|
+
E !== null && (w.material = E), h.push(w);
|
|
734
|
+
}
|
|
735
|
+
g === !0 && r.setIndex(null), c.primitives = h, n.meshes || (n.meshes = []), this._invokeAll(function(x) {
|
|
736
|
+
x.writeMesh && x.writeMesh(e, c);
|
|
737
|
+
});
|
|
738
|
+
const D = n.meshes.push(c) - 1;
|
|
739
|
+
return s.meshes.set(i, D), D;
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* If a vertex attribute with a
|
|
743
|
+
* [non-standard data type](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview)
|
|
744
|
+
* is used, it is checked whether it is a valid data type according to the
|
|
745
|
+
* [KHR_mesh_quantization](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md)
|
|
746
|
+
* extension.
|
|
747
|
+
* In this case the extension is automatically added to the list of used extensions.
|
|
748
|
+
*
|
|
749
|
+
* @param {string} attributeName
|
|
750
|
+
* @param {THREE.BufferAttribute} attribute
|
|
751
|
+
*/
|
|
752
|
+
detectMeshQuantization(e, s) {
|
|
753
|
+
if (this.extensionsUsed[j]) return;
|
|
754
|
+
let n;
|
|
755
|
+
switch (s.array.constructor) {
|
|
756
|
+
case Int8Array:
|
|
757
|
+
n = "byte";
|
|
758
|
+
break;
|
|
759
|
+
case Uint8Array:
|
|
760
|
+
n = "unsigned byte";
|
|
761
|
+
break;
|
|
762
|
+
case Int16Array:
|
|
763
|
+
n = "short";
|
|
764
|
+
break;
|
|
765
|
+
case Uint16Array:
|
|
766
|
+
n = "unsigned short";
|
|
767
|
+
break;
|
|
768
|
+
default:
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
s.normalized && (n += " normalized");
|
|
772
|
+
const t = e.split("_", 1)[0];
|
|
773
|
+
J[t] && J[t].includes(n) && (this.extensionsUsed[j] = !0, this.extensionsRequired[j] = !0);
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Process camera
|
|
777
|
+
* @param {THREE.Camera} camera Camera to process
|
|
778
|
+
* @return {Integer} Index of the processed mesh in the "camera" array
|
|
779
|
+
*/
|
|
780
|
+
processCamera(e) {
|
|
781
|
+
const s = this.json;
|
|
782
|
+
s.cameras || (s.cameras = []);
|
|
783
|
+
const n = e.isOrthographicCamera, t = {
|
|
784
|
+
type: n ? "orthographic" : "perspective"
|
|
785
|
+
};
|
|
786
|
+
return n ? t.orthographic = {
|
|
787
|
+
xmag: e.right * 2,
|
|
788
|
+
ymag: e.top * 2,
|
|
789
|
+
zfar: e.far <= 0 ? 1e-3 : e.far,
|
|
790
|
+
znear: e.near < 0 ? 0 : e.near
|
|
791
|
+
} : t.perspective = {
|
|
792
|
+
aspectRatio: e.aspect,
|
|
793
|
+
yfov: W.degToRad(e.fov),
|
|
794
|
+
zfar: e.far <= 0 ? 1e-3 : e.far,
|
|
795
|
+
znear: e.near < 0 ? 0 : e.near
|
|
796
|
+
}, e.name !== "" && (t.name = e.type), s.cameras.push(t) - 1;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Creates glTF animation entry from AnimationClip object.
|
|
800
|
+
*
|
|
801
|
+
* Status:
|
|
802
|
+
* - Only properties listed in PATH_PROPERTIES may be animated.
|
|
803
|
+
*
|
|
804
|
+
* @param {THREE.AnimationClip} clip
|
|
805
|
+
* @param {THREE.Object3D} root
|
|
806
|
+
* @return {number|null}
|
|
807
|
+
*/
|
|
808
|
+
processAnimation(e, s) {
|
|
809
|
+
const n = this.json, t = this.nodeMap;
|
|
810
|
+
n.animations || (n.animations = []), e = q.Utils.mergeMorphTargetTracks(e.clone(), s);
|
|
811
|
+
const i = e.tracks, r = [], o = [];
|
|
812
|
+
for (let c = 0; c < i.length; ++c) {
|
|
813
|
+
const l = i[c], h = P.parseTrackName(l.name);
|
|
814
|
+
let u = P.findNode(s, h.nodeName);
|
|
815
|
+
const m = Q[h.propertyName];
|
|
816
|
+
if (h.objectName === "bones" && (u.isSkinnedMesh === !0 ? u = u.skeleton.getBoneByName(h.objectIndex) : u = void 0), !u || !m)
|
|
817
|
+
return console.warn('THREE.GLTFExporter: Could not export animation track "%s".', l.name), null;
|
|
818
|
+
const f = 1;
|
|
819
|
+
let p = l.values.length / l.times.length;
|
|
820
|
+
m === Q.morphTargetInfluences && (p /= u.morphTargetInfluences.length);
|
|
821
|
+
let d;
|
|
822
|
+
l.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === !0 ? (d = "CUBICSPLINE", p /= 3) : l.getInterpolation() === Me ? d = "STEP" : d = "LINEAR", o.push({
|
|
823
|
+
input: this.processAccessor(new L(l.times, f)),
|
|
824
|
+
output: this.processAccessor(new L(l.values, p)),
|
|
825
|
+
interpolation: d
|
|
826
|
+
}), r.push({
|
|
827
|
+
sampler: o.length - 1,
|
|
828
|
+
target: {
|
|
829
|
+
node: t.get(u),
|
|
830
|
+
path: m
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
return n.animations.push({
|
|
835
|
+
name: e.name || "clip_" + n.animations.length,
|
|
836
|
+
samplers: o,
|
|
837
|
+
channels: r
|
|
838
|
+
}), n.animations.length - 1;
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* @param {THREE.Object3D} object
|
|
842
|
+
* @return {number|null}
|
|
843
|
+
*/
|
|
844
|
+
processSkin(e) {
|
|
845
|
+
const s = this.json, n = this.nodeMap, t = s.nodes[n.get(e)], i = e.skeleton;
|
|
846
|
+
if (i === void 0) return null;
|
|
847
|
+
const r = e.skeleton.bones[0];
|
|
848
|
+
if (r === void 0) return null;
|
|
849
|
+
const o = [], c = new Float32Array(i.bones.length * 16), l = new ne();
|
|
850
|
+
for (let u = 0; u < i.bones.length; ++u)
|
|
851
|
+
o.push(n.get(i.bones[u])), l.copy(i.boneInverses[u]), l.multiply(e.bindMatrix).toArray(c, u * 16);
|
|
852
|
+
return s.skins === void 0 && (s.skins = []), s.skins.push({
|
|
853
|
+
inverseBindMatrices: this.processAccessor(new L(c, 16)),
|
|
854
|
+
joints: o,
|
|
855
|
+
skeleton: n.get(r)
|
|
856
|
+
}), t.skin = s.skins.length - 1;
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Process Object3D node
|
|
860
|
+
* @param {THREE.Object3D} node Object3D to processNode
|
|
861
|
+
* @return {Integer} Index of the node in the nodes list
|
|
862
|
+
*/
|
|
863
|
+
processNode(e) {
|
|
864
|
+
const s = this.json, n = this.options, t = this.nodeMap;
|
|
865
|
+
s.nodes || (s.nodes = []);
|
|
866
|
+
const i = {};
|
|
867
|
+
if (n.trs) {
|
|
868
|
+
const o = e.quaternion.toArray(), c = e.position.toArray(), l = e.scale.toArray();
|
|
869
|
+
O(o, [0, 0, 0, 1]) || (i.rotation = o), O(c, [0, 0, 0]) || (i.translation = c), O(l, [1, 1, 1]) || (i.scale = l);
|
|
870
|
+
} else
|
|
871
|
+
e.matrixAutoUpdate && e.updateMatrix(), Be(e.matrix) === !1 && (i.matrix = e.matrix.elements);
|
|
872
|
+
if (e.name !== "" && (i.name = String(e.name)), this.serializeUserData(e, i), e.isMesh || e.isLine || e.isPoints) {
|
|
873
|
+
const o = this.processMesh(e);
|
|
874
|
+
o !== null && (i.mesh = o);
|
|
875
|
+
} else e.isCamera && (i.camera = this.processCamera(e));
|
|
876
|
+
if (e.isSkinnedMesh && this.skins.push(e), e.children.length > 0) {
|
|
877
|
+
const o = [];
|
|
878
|
+
for (let c = 0, l = e.children.length; c < l; c++) {
|
|
879
|
+
const h = e.children[c];
|
|
880
|
+
if (h.visible || n.onlyVisible === !1) {
|
|
881
|
+
const u = this.processNode(h);
|
|
882
|
+
u !== null && o.push(u);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
o.length > 0 && (i.children = o);
|
|
886
|
+
}
|
|
887
|
+
this._invokeAll(function(o) {
|
|
888
|
+
o.writeNode && o.writeNode(e, i);
|
|
889
|
+
});
|
|
890
|
+
const r = s.nodes.push(i) - 1;
|
|
891
|
+
return t.set(e, r), r;
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Process Scene
|
|
895
|
+
* @param {Scene} node Scene to process
|
|
896
|
+
*/
|
|
897
|
+
processScene(e) {
|
|
898
|
+
const s = this.json, n = this.options;
|
|
899
|
+
s.scenes || (s.scenes = [], s.scene = 0);
|
|
900
|
+
const t = {};
|
|
901
|
+
e.name !== "" && (t.name = e.name), s.scenes.push(t);
|
|
902
|
+
const i = [];
|
|
903
|
+
for (let r = 0, o = e.children.length; r < o; r++) {
|
|
904
|
+
const c = e.children[r];
|
|
905
|
+
if (c.visible || n.onlyVisible === !1) {
|
|
906
|
+
const l = this.processNode(c);
|
|
907
|
+
l !== null && i.push(l);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
i.length > 0 && (t.nodes = i), this.serializeUserData(e, t);
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Creates a Scene to hold a list of objects and parse it
|
|
914
|
+
* @param {Array} objects List of objects to process
|
|
915
|
+
*/
|
|
916
|
+
processObjects(e) {
|
|
917
|
+
const s = new K();
|
|
918
|
+
s.name = "AuxScene";
|
|
919
|
+
for (let n = 0; n < e.length; n++)
|
|
920
|
+
s.children.push(e[n]);
|
|
921
|
+
this.processScene(s);
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* @param {THREE.Object3D|Array<THREE.Object3D>} input
|
|
925
|
+
*/
|
|
926
|
+
processInput(e) {
|
|
927
|
+
const s = this.options;
|
|
928
|
+
e = e instanceof Array ? e : [e], this._invokeAll(function(t) {
|
|
929
|
+
t.beforeParse && t.beforeParse(e);
|
|
930
|
+
});
|
|
931
|
+
const n = [];
|
|
932
|
+
for (let t = 0; t < e.length; t++)
|
|
933
|
+
e[t] instanceof K ? this.processScene(e[t]) : n.push(e[t]);
|
|
934
|
+
n.length > 0 && this.processObjects(n);
|
|
935
|
+
for (let t = 0; t < this.skins.length; ++t)
|
|
936
|
+
this.processSkin(this.skins[t]);
|
|
937
|
+
for (let t = 0; t < s.animations.length; ++t)
|
|
938
|
+
this.processAnimation(s.animations[t], e[0]);
|
|
939
|
+
this._invokeAll(function(t) {
|
|
940
|
+
t.afterParse && t.afterParse(e);
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
_invokeAll(e) {
|
|
944
|
+
for (let s = 0, n = this.plugins.length; s < n; s++)
|
|
945
|
+
e(this.plugins[s]);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
class ze {
|
|
949
|
+
constructor(e) {
|
|
950
|
+
this.writer = e, this.name = "KHR_lights_punctual";
|
|
951
|
+
}
|
|
952
|
+
writeNode(e, s) {
|
|
953
|
+
if (!e.isLight) return;
|
|
954
|
+
if (!e.isDirectionalLight && !e.isPointLight && !e.isSpotLight) {
|
|
955
|
+
console.warn("THREE.GLTFExporter: Only directional, point, and spot lights are supported.", e);
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
const n = this.writer, t = n.json, i = n.extensionsUsed, r = {};
|
|
959
|
+
e.name && (r.name = e.name), r.color = e.color.toArray(), r.intensity = e.intensity, e.isDirectionalLight ? r.type = "directional" : e.isPointLight ? (r.type = "point", e.distance > 0 && (r.range = e.distance)) : e.isSpotLight && (r.type = "spot", e.distance > 0 && (r.range = e.distance), r.spot = {}, r.spot.innerConeAngle = (1 - e.penumbra) * e.angle, r.spot.outerConeAngle = e.angle), e.decay !== void 0 && e.decay !== 2 && console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."), e.target && (e.target.parent !== e || e.target.position.x !== 0 || e.target.position.y !== 0 || e.target.position.z !== -1) && console.warn("THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."), i[this.name] || (t.extensions = t.extensions || {}, t.extensions[this.name] = { lights: [] }, i[this.name] = !0);
|
|
960
|
+
const o = t.extensions[this.name].lights;
|
|
961
|
+
o.push(r), s.extensions = s.extensions || {}, s.extensions[this.name] = { light: o.length - 1 };
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
class ke {
|
|
965
|
+
constructor(e) {
|
|
966
|
+
this.writer = e, this.name = "KHR_materials_unlit";
|
|
967
|
+
}
|
|
968
|
+
writeMaterial(e, s) {
|
|
969
|
+
if (!e.isMeshBasicMaterial) return;
|
|
970
|
+
const t = this.writer.extensionsUsed;
|
|
971
|
+
s.extensions = s.extensions || {}, s.extensions[this.name] = {}, t[this.name] = !0, s.pbrMetallicRoughness.metallicFactor = 0, s.pbrMetallicRoughness.roughnessFactor = 0.9;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
class He {
|
|
975
|
+
constructor(e) {
|
|
976
|
+
this.writer = e, this.name = "KHR_materials_clearcoat";
|
|
977
|
+
}
|
|
978
|
+
writeMaterial(e, s) {
|
|
979
|
+
if (!e.isMeshPhysicalMaterial || e.clearcoat === 0) return;
|
|
980
|
+
const n = this.writer, t = n.extensionsUsed, i = {};
|
|
981
|
+
if (i.clearcoatFactor = e.clearcoat, e.clearcoatMap) {
|
|
982
|
+
const r = {
|
|
983
|
+
index: n.processTexture(e.clearcoatMap),
|
|
984
|
+
texCoord: e.clearcoatMap.channel
|
|
985
|
+
};
|
|
986
|
+
n.applyTextureTransform(r, e.clearcoatMap), i.clearcoatTexture = r;
|
|
987
|
+
}
|
|
988
|
+
if (i.clearcoatRoughnessFactor = e.clearcoatRoughness, e.clearcoatRoughnessMap) {
|
|
989
|
+
const r = {
|
|
990
|
+
index: n.processTexture(e.clearcoatRoughnessMap),
|
|
991
|
+
texCoord: e.clearcoatRoughnessMap.channel
|
|
992
|
+
};
|
|
993
|
+
n.applyTextureTransform(r, e.clearcoatRoughnessMap), i.clearcoatRoughnessTexture = r;
|
|
994
|
+
}
|
|
995
|
+
if (e.clearcoatNormalMap) {
|
|
996
|
+
const r = {
|
|
997
|
+
index: n.processTexture(e.clearcoatNormalMap),
|
|
998
|
+
texCoord: e.clearcoatNormalMap.channel
|
|
999
|
+
};
|
|
1000
|
+
n.applyTextureTransform(r, e.clearcoatNormalMap), i.clearcoatNormalTexture = r;
|
|
1001
|
+
}
|
|
1002
|
+
s.extensions = s.extensions || {}, s.extensions[this.name] = i, t[this.name] = !0;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
class Ve {
|
|
1006
|
+
constructor(e) {
|
|
1007
|
+
this.writer = e, this.name = "KHR_materials_iridescence";
|
|
1008
|
+
}
|
|
1009
|
+
writeMaterial(e, s) {
|
|
1010
|
+
if (!e.isMeshPhysicalMaterial || e.iridescence === 0) return;
|
|
1011
|
+
const n = this.writer, t = n.extensionsUsed, i = {};
|
|
1012
|
+
if (i.iridescenceFactor = e.iridescence, e.iridescenceMap) {
|
|
1013
|
+
const r = {
|
|
1014
|
+
index: n.processTexture(e.iridescenceMap),
|
|
1015
|
+
texCoord: e.iridescenceMap.channel
|
|
1016
|
+
};
|
|
1017
|
+
n.applyTextureTransform(r, e.iridescenceMap), i.iridescenceTexture = r;
|
|
1018
|
+
}
|
|
1019
|
+
if (i.iridescenceIor = e.iridescenceIOR, i.iridescenceThicknessMinimum = e.iridescenceThicknessRange[0], i.iridescenceThicknessMaximum = e.iridescenceThicknessRange[1], e.iridescenceThicknessMap) {
|
|
1020
|
+
const r = {
|
|
1021
|
+
index: n.processTexture(e.iridescenceThicknessMap),
|
|
1022
|
+
texCoord: e.iridescenceThicknessMap.channel
|
|
1023
|
+
};
|
|
1024
|
+
n.applyTextureTransform(r, e.iridescenceThicknessMap), i.iridescenceThicknessTexture = r;
|
|
1025
|
+
}
|
|
1026
|
+
s.extensions = s.extensions || {}, s.extensions[this.name] = i, t[this.name] = !0;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
class je {
|
|
1030
|
+
constructor(e) {
|
|
1031
|
+
this.writer = e, this.name = "KHR_materials_transmission";
|
|
1032
|
+
}
|
|
1033
|
+
writeMaterial(e, s) {
|
|
1034
|
+
if (!e.isMeshPhysicalMaterial || e.transmission === 0) return;
|
|
1035
|
+
const n = this.writer, t = n.extensionsUsed, i = {};
|
|
1036
|
+
if (i.transmissionFactor = e.transmission, e.transmissionMap) {
|
|
1037
|
+
const r = {
|
|
1038
|
+
index: n.processTexture(e.transmissionMap),
|
|
1039
|
+
texCoord: e.transmissionMap.channel
|
|
1040
|
+
};
|
|
1041
|
+
n.applyTextureTransform(r, e.transmissionMap), i.transmissionTexture = r;
|
|
1042
|
+
}
|
|
1043
|
+
s.extensions = s.extensions || {}, s.extensions[this.name] = i, t[this.name] = !0;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
class Ye {
|
|
1047
|
+
constructor(e) {
|
|
1048
|
+
this.writer = e, this.name = "KHR_materials_volume";
|
|
1049
|
+
}
|
|
1050
|
+
writeMaterial(e, s) {
|
|
1051
|
+
if (!e.isMeshPhysicalMaterial || e.transmission === 0) return;
|
|
1052
|
+
const n = this.writer, t = n.extensionsUsed, i = {};
|
|
1053
|
+
if (i.thicknessFactor = e.thickness, e.thicknessMap) {
|
|
1054
|
+
const r = {
|
|
1055
|
+
index: n.processTexture(e.thicknessMap),
|
|
1056
|
+
texCoord: e.thicknessMap.channel
|
|
1057
|
+
};
|
|
1058
|
+
n.applyTextureTransform(r, e.thicknessMap), i.thicknessTexture = r;
|
|
1059
|
+
}
|
|
1060
|
+
i.attenuationDistance = e.attenuationDistance, i.attenuationColor = e.attenuationColor.toArray(), s.extensions = s.extensions || {}, s.extensions[this.name] = i, t[this.name] = !0;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
class Ke {
|
|
1064
|
+
constructor(e) {
|
|
1065
|
+
this.writer = e, this.name = "KHR_materials_ior";
|
|
1066
|
+
}
|
|
1067
|
+
writeMaterial(e, s) {
|
|
1068
|
+
if (!e.isMeshPhysicalMaterial || e.ior === 1.5) return;
|
|
1069
|
+
const t = this.writer.extensionsUsed, i = {};
|
|
1070
|
+
i.ior = e.ior, s.extensions = s.extensions || {}, s.extensions[this.name] = i, t[this.name] = !0;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
class We {
|
|
1074
|
+
constructor(e) {
|
|
1075
|
+
this.writer = e, this.name = "KHR_materials_specular";
|
|
1076
|
+
}
|
|
1077
|
+
writeMaterial(e, s) {
|
|
1078
|
+
if (!e.isMeshPhysicalMaterial || e.specularIntensity === 1 && e.specularColor.equals(Ce) && !e.specularIntensityMap && !e.specularColorMap) return;
|
|
1079
|
+
const n = this.writer, t = n.extensionsUsed, i = {};
|
|
1080
|
+
if (e.specularIntensityMap) {
|
|
1081
|
+
const r = {
|
|
1082
|
+
index: n.processTexture(e.specularIntensityMap),
|
|
1083
|
+
texCoord: e.specularIntensityMap.channel
|
|
1084
|
+
};
|
|
1085
|
+
n.applyTextureTransform(r, e.specularIntensityMap), i.specularTexture = r;
|
|
1086
|
+
}
|
|
1087
|
+
if (e.specularColorMap) {
|
|
1088
|
+
const r = {
|
|
1089
|
+
index: n.processTexture(e.specularColorMap),
|
|
1090
|
+
texCoord: e.specularColorMap.channel
|
|
1091
|
+
};
|
|
1092
|
+
n.applyTextureTransform(r, e.specularColorMap), i.specularColorTexture = r;
|
|
1093
|
+
}
|
|
1094
|
+
i.specularFactor = e.specularIntensity, i.specularColorFactor = e.specularColor.toArray(), s.extensions = s.extensions || {}, s.extensions[this.name] = i, t[this.name] = !0;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
class qe {
|
|
1098
|
+
constructor(e) {
|
|
1099
|
+
this.writer = e, this.name = "KHR_materials_sheen";
|
|
1100
|
+
}
|
|
1101
|
+
writeMaterial(e, s) {
|
|
1102
|
+
if (!e.isMeshPhysicalMaterial || e.sheen == 0) return;
|
|
1103
|
+
const n = this.writer, t = n.extensionsUsed, i = {};
|
|
1104
|
+
if (e.sheenRoughnessMap) {
|
|
1105
|
+
const r = {
|
|
1106
|
+
index: n.processTexture(e.sheenRoughnessMap),
|
|
1107
|
+
texCoord: e.sheenRoughnessMap.channel
|
|
1108
|
+
};
|
|
1109
|
+
n.applyTextureTransform(r, e.sheenRoughnessMap), i.sheenRoughnessTexture = r;
|
|
1110
|
+
}
|
|
1111
|
+
if (e.sheenColorMap) {
|
|
1112
|
+
const r = {
|
|
1113
|
+
index: n.processTexture(e.sheenColorMap),
|
|
1114
|
+
texCoord: e.sheenColorMap.channel
|
|
1115
|
+
};
|
|
1116
|
+
n.applyTextureTransform(r, e.sheenColorMap), i.sheenColorTexture = r;
|
|
1117
|
+
}
|
|
1118
|
+
i.sheenRoughnessFactor = e.sheenRoughness, i.sheenColorFactor = e.sheenColor.toArray(), s.extensions = s.extensions || {}, s.extensions[this.name] = i, t[this.name] = !0;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
class Xe {
|
|
1122
|
+
constructor(e) {
|
|
1123
|
+
this.writer = e, this.name = "KHR_materials_anisotropy";
|
|
1124
|
+
}
|
|
1125
|
+
writeMaterial(e, s) {
|
|
1126
|
+
if (!e.isMeshPhysicalMaterial || e.anisotropy == 0) return;
|
|
1127
|
+
const n = this.writer, t = n.extensionsUsed, i = {};
|
|
1128
|
+
if (e.anisotropyMap) {
|
|
1129
|
+
const r = { index: n.processTexture(e.anisotropyMap) };
|
|
1130
|
+
n.applyTextureTransform(r, e.anisotropyMap), i.anisotropyTexture = r;
|
|
1131
|
+
}
|
|
1132
|
+
i.anisotropyStrength = e.anisotropy, i.anisotropyRotation = e.anisotropyRotation, s.extensions = s.extensions || {}, s.extensions[this.name] = i, t[this.name] = !0;
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
class Je {
|
|
1136
|
+
constructor(e) {
|
|
1137
|
+
this.writer = e, this.name = "KHR_materials_emissive_strength";
|
|
1138
|
+
}
|
|
1139
|
+
writeMaterial(e, s) {
|
|
1140
|
+
if (!e.isMeshStandardMaterial || e.emissiveIntensity === 1) return;
|
|
1141
|
+
const t = this.writer.extensionsUsed, i = {};
|
|
1142
|
+
i.emissiveStrength = e.emissiveIntensity, s.extensions = s.extensions || {}, s.extensions[this.name] = i, t[this.name] = !0;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
class Qe {
|
|
1146
|
+
constructor(e) {
|
|
1147
|
+
this.writer = e, this.name = "EXT_materials_bump";
|
|
1148
|
+
}
|
|
1149
|
+
writeMaterial(e, s) {
|
|
1150
|
+
if (!e.isMeshStandardMaterial || e.bumpScale === 1 && !e.bumpMap) return;
|
|
1151
|
+
const n = this.writer, t = n.extensionsUsed, i = {};
|
|
1152
|
+
if (e.bumpMap) {
|
|
1153
|
+
const r = {
|
|
1154
|
+
index: n.processTexture(e.bumpMap),
|
|
1155
|
+
texCoord: e.bumpMap.channel
|
|
1156
|
+
};
|
|
1157
|
+
n.applyTextureTransform(r, e.bumpMap), i.bumpTexture = r;
|
|
1158
|
+
}
|
|
1159
|
+
i.bumpFactor = e.bumpScale, s.extensions = s.extensions || {}, s.extensions[this.name] = i, t[this.name] = !0;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
class Ze {
|
|
1163
|
+
constructor(e) {
|
|
1164
|
+
this.writer = e, this.name = "EXT_mesh_gpu_instancing";
|
|
1165
|
+
}
|
|
1166
|
+
writeNode(e, s) {
|
|
1167
|
+
if (!e.isInstancedMesh) return;
|
|
1168
|
+
const n = this.writer, t = e, i = new Float32Array(t.count * 3), r = new Float32Array(t.count * 4), o = new Float32Array(t.count * 3), c = new ne(), l = new G(), h = new de(), u = new G();
|
|
1169
|
+
for (let f = 0; f < t.count; f++)
|
|
1170
|
+
t.getMatrixAt(f, c), c.decompose(l, h, u), l.toArray(i, f * 3), h.toArray(r, f * 4), u.toArray(o, f * 3);
|
|
1171
|
+
const m = {
|
|
1172
|
+
TRANSLATION: n.processAccessor(new L(i, 3)),
|
|
1173
|
+
ROTATION: n.processAccessor(new L(r, 4)),
|
|
1174
|
+
SCALE: n.processAccessor(new L(o, 3))
|
|
1175
|
+
};
|
|
1176
|
+
t.instanceColor && (m._COLOR_0 = n.processAccessor(t.instanceColor)), s.extensions = s.extensions || {}, s.extensions[this.name] = { attributes: m }, n.extensionsUsed[this.name] = !0, n.extensionsRequired[this.name] = !0;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
q.Utils = {
|
|
1180
|
+
insertKeyframe: function(a, e) {
|
|
1181
|
+
const n = a.getValueSize(), t = new a.TimeBufferType(a.times.length + 1), i = new a.ValueBufferType(a.values.length + n), r = a.createInterpolant(new a.ValueBufferType(n));
|
|
1182
|
+
let o;
|
|
1183
|
+
if (a.times.length === 0) {
|
|
1184
|
+
t[0] = e;
|
|
1185
|
+
for (let c = 0; c < n; c++)
|
|
1186
|
+
i[c] = 0;
|
|
1187
|
+
o = 0;
|
|
1188
|
+
} else if (e < a.times[0]) {
|
|
1189
|
+
if (Math.abs(a.times[0] - e) < 1e-3) return 0;
|
|
1190
|
+
t[0] = e, t.set(a.times, 1), i.set(r.evaluate(e), 0), i.set(a.values, n), o = 0;
|
|
1191
|
+
} else if (e > a.times[a.times.length - 1]) {
|
|
1192
|
+
if (Math.abs(a.times[a.times.length - 1] - e) < 1e-3)
|
|
1193
|
+
return a.times.length - 1;
|
|
1194
|
+
t[t.length - 1] = e, t.set(a.times, 0), i.set(a.values, 0), i.set(r.evaluate(e), a.values.length), o = t.length - 1;
|
|
1195
|
+
} else
|
|
1196
|
+
for (let c = 0; c < a.times.length; c++) {
|
|
1197
|
+
if (Math.abs(a.times[c] - e) < 1e-3) return c;
|
|
1198
|
+
if (a.times[c] < e && a.times[c + 1] > e) {
|
|
1199
|
+
t.set(a.times.slice(0, c + 1), 0), t[c + 1] = e, t.set(a.times.slice(c + 1), c + 2), i.set(a.values.slice(0, (c + 1) * n), 0), i.set(r.evaluate(e), (c + 1) * n), i.set(a.values.slice((c + 1) * n), (c + 2) * n), o = c + 1;
|
|
1200
|
+
break;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
return a.times = t, a.values = i, o;
|
|
1204
|
+
},
|
|
1205
|
+
mergeMorphTargetTracks: function(a, e) {
|
|
1206
|
+
const s = [], n = {}, t = a.tracks;
|
|
1207
|
+
for (let i = 0; i < t.length; ++i) {
|
|
1208
|
+
let r = t[i];
|
|
1209
|
+
const o = P.parseTrackName(r.name), c = P.findNode(e, o.nodeName);
|
|
1210
|
+
if (o.propertyName !== "morphTargetInfluences" || o.propertyIndex === void 0) {
|
|
1211
|
+
s.push(r);
|
|
1212
|
+
continue;
|
|
1213
|
+
}
|
|
1214
|
+
if (r.createInterpolant !== r.InterpolantFactoryMethodDiscrete && r.createInterpolant !== r.InterpolantFactoryMethodLinear) {
|
|
1215
|
+
if (r.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline)
|
|
1216
|
+
throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");
|
|
1217
|
+
console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead."), r = r.clone(), r.setInterpolation(Se);
|
|
1218
|
+
}
|
|
1219
|
+
const l = c.morphTargetInfluences.length, h = c.morphTargetDictionary[o.propertyIndex];
|
|
1220
|
+
if (h === void 0)
|
|
1221
|
+
throw new Error("THREE.GLTFExporter: Morph target name not found: " + o.propertyIndex);
|
|
1222
|
+
let u;
|
|
1223
|
+
if (n[c.uuid] === void 0) {
|
|
1224
|
+
u = r.clone();
|
|
1225
|
+
const f = new u.ValueBufferType(l * u.times.length);
|
|
1226
|
+
for (let p = 0; p < u.times.length; p++)
|
|
1227
|
+
f[p * l + h] = u.values[p];
|
|
1228
|
+
u.name = (o.nodeName || "") + ".morphTargetInfluences", u.values = f, n[c.uuid] = u, s.push(u);
|
|
1229
|
+
continue;
|
|
1230
|
+
}
|
|
1231
|
+
const m = r.createInterpolant(new r.ValueBufferType(1));
|
|
1232
|
+
u = n[c.uuid];
|
|
1233
|
+
for (let f = 0; f < u.times.length; f++)
|
|
1234
|
+
u.values[f * l + h] = m.evaluate(u.times[f]);
|
|
1235
|
+
for (let f = 0; f < r.times.length; f++) {
|
|
1236
|
+
const p = this.insertKeyframe(u, r.times[f]);
|
|
1237
|
+
u.values[p * l + h] = r.values[f];
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
return a.tracks = s, a;
|
|
1241
|
+
}
|
|
1242
|
+
};
|
|
1243
|
+
class $e {
|
|
1244
|
+
constructor() {
|
|
1245
|
+
this._importer = new _e(), this._exporter = new q();
|
|
1246
|
+
}
|
|
1247
|
+
Import(e, s) {
|
|
1248
|
+
return this._importer.loadAsync(e, (n) => {
|
|
1249
|
+
s && s(n.loaded / n.total);
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
Export(e, s, n) {
|
|
1253
|
+
return s ? this._exporter.parseAsync(e, {
|
|
1254
|
+
binary: s,
|
|
1255
|
+
onlyVisible: n
|
|
1256
|
+
}) : this._exporter.parseAsync(e, {
|
|
1257
|
+
binary: s,
|
|
1258
|
+
onlyVisible: n
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
class ss {
|
|
1263
|
+
constructor(e) {
|
|
1264
|
+
this._scene = e, this._gltfIO = new $e();
|
|
1265
|
+
}
|
|
1266
|
+
Import(e, s) {
|
|
1267
|
+
switch (e) {
|
|
1268
|
+
case "glb":
|
|
1269
|
+
return this._gltfIO.Import(s).catch((n) => (console.error(n), null));
|
|
1270
|
+
default:
|
|
1271
|
+
return console.error("DIVEIO.Import: Unsupported file type: " + e), Promise.reject();
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
Export(e) {
|
|
1275
|
+
switch (e) {
|
|
1276
|
+
case "glb":
|
|
1277
|
+
return this._gltfIO.Export(this._scene, !0, !0).then((s) => this._createBlobURL(s)).catch((s) => (console.error(s), null));
|
|
1278
|
+
default:
|
|
1279
|
+
return console.error("DIVEIO.Export: Unsupported file type: " + e), Promise.reject();
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
_createBlobURL(e) {
|
|
1283
|
+
return URL.createObjectURL(new Blob([e]));
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
export {
|
|
1287
|
+
ss as DIVEIO
|
|
1288
|
+
};
|
|
1289
|
+
//# sourceMappingURL=IO-CYzpSt1J.js.map
|