@vctrl/hooks 0.9.5 → 0.11.1

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