@vctrl/hooks 0.2.2 → 0.3.2

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