@babylonjs/serializers 5.0.0-rc.6 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/OBJ/index.d.ts +1 -1
- package/OBJ/index.js +1 -1
- package/OBJ/objSerializer.d.ts +21 -21
- package/OBJ/objSerializer.js +174 -174
- package/OBJ/objSerializer.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +41 -41
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +189 -189
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +24 -24
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +90 -90
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +24 -24
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +73 -73
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +20 -20
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +51 -51
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +30 -30
- package/glTF/2.0/Extensions/KHR_texture_transform.js +137 -137
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/index.d.ts +5 -5
- package/glTF/2.0/Extensions/index.js +5 -5
- package/glTF/2.0/glTFAnimation.d.ts +206 -205
- package/glTF/2.0/glTFAnimation.js +852 -852
- package/glTF/2.0/glTFAnimation.js.map +1 -1
- package/glTF/2.0/glTFData.d.ts +19 -19
- package/glTF/2.0/glTFData.js +52 -52
- package/glTF/2.0/glTFExporter.d.ts +456 -455
- package/glTF/2.0/glTFExporter.js +1975 -1972
- package/glTF/2.0/glTFExporter.js.map +1 -1
- package/glTF/2.0/glTFExporterExtension.d.ts +74 -74
- package/glTF/2.0/glTFExporterExtension.js +3 -3
- package/glTF/2.0/glTFExporterExtension.js.map +1 -1
- package/glTF/2.0/glTFMaterialExporter.d.ts +208 -207
- package/glTF/2.0/glTFMaterialExporter.js +1114 -1110
- package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
- package/glTF/2.0/glTFSerializer.d.ts +60 -60
- package/glTF/2.0/glTFSerializer.js +62 -62
- package/glTF/2.0/glTFSerializer.js.map +1 -1
- package/glTF/2.0/glTFUtilities.d.ts +99 -97
- package/glTF/2.0/glTFUtilities.js +196 -196
- package/glTF/2.0/glTFUtilities.js.map +1 -1
- package/glTF/2.0/index.d.ts +8 -8
- package/glTF/2.0/index.js +9 -8
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/2.0/shaders/textureTransform.fragment.d.ts +5 -5
- package/glTF/2.0/shaders/textureTransform.fragment.js +8 -8
- package/glTF/glTFFileExporter.d.ts +20 -20
- package/glTF/glTFFileExporter.js +3 -3
- package/glTF/index.d.ts +2 -2
- package/glTF/index.js +3 -2
- package/glTF/index.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +4 -3
- package/index.js.map +1 -1
- package/legacy/legacy-glTF2Serializer.d.ts +2 -2
- package/legacy/legacy-glTF2Serializer.js +44 -43
- package/legacy/legacy-glTF2Serializer.js.map +1 -1
- package/legacy/legacy-objSerializer.d.ts +1 -1
- package/legacy/legacy-objSerializer.js +13 -12
- package/legacy/legacy-objSerializer.js.map +1 -1
- package/legacy/legacy-stlSerializer.d.ts +1 -1
- package/legacy/legacy-stlSerializer.js +13 -12
- package/legacy/legacy-stlSerializer.js.map +1 -1
- package/legacy/legacy.d.ts +4 -4
- package/legacy/legacy.js +6 -5
- package/legacy/legacy.js.map +1 -1
- package/license.md +71 -0
- package/package.json +25 -6
- package/stl/index.d.ts +1 -1
- package/stl/index.js +1 -1
- package/stl/stlSerializer.d.ts +17 -17
- package/stl/stlSerializer.js +107 -107
- package/stl/stlSerializer.js.map +1 -1
package/glTF/2.0/glTFExporter.js
CHANGED
|
@@ -1,1973 +1,1976 @@
|
|
|
1
|
-
import { __spreadArray } from "tslib";
|
|
2
|
-
import { Vector2, Vector3, Vector4, Quaternion } from "@babylonjs/core/Maths/math.vector.js";
|
|
3
|
-
import { Color3, Color4 } from "@babylonjs/core/Maths/math.color.js";
|
|
4
|
-
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
5
|
-
import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
|
|
6
|
-
import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
|
|
7
|
-
import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh.js";
|
|
8
|
-
import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
|
9
|
-
import { LinesMesh } from "@babylonjs/core/Meshes/linesMesh.js";
|
|
10
|
-
import { InstancedMesh } from "@babylonjs/core/Meshes/instancedMesh.js";
|
|
11
|
-
import { Material } from "@babylonjs/core/Materials/material.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
* @param
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
var
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
var
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
extension.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
*
|
|
170
|
-
* @param
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
_Exporter.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
*
|
|
182
|
-
* @
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
var
|
|
206
|
-
binaryWriter.
|
|
207
|
-
binaryWriter.setUInt32(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
byteOffset
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
binaryWriter.setUInt32(babylonIndices[submesh.indexStart +
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* @param
|
|
232
|
-
* @param
|
|
233
|
-
* @param
|
|
234
|
-
* @param
|
|
235
|
-
* @param
|
|
236
|
-
* @param
|
|
237
|
-
* @param
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* @param
|
|
262
|
-
* @param
|
|
263
|
-
* @param
|
|
264
|
-
* @param
|
|
265
|
-
* @param
|
|
266
|
-
* @param
|
|
267
|
-
* @param
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
var
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
case VertexBuffer.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
vertexData.push(Vector3.FromArray(meshAttributeArray, index
|
|
286
|
-
vertexData.push(Vector3.FromArray(meshAttributeArray, index + stride));
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
vertexData.push(Vector4.FromArray(meshAttributeArray, index
|
|
295
|
-
vertexData.push(Vector4.FromArray(meshAttributeArray, index + stride));
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
vertexData.push(Vector4.FromArray(meshAttributeArray, index
|
|
306
|
-
vertexData.push(Vector4.FromArray(meshAttributeArray, index + stride));
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
vertexData.push(Vector3.FromArray(meshAttributeArray, index
|
|
311
|
-
vertexData.push(Vector3.FromArray(meshAttributeArray, index + stride));
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
case VertexBuffer.
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
vertexData.push(Vector2.FromArray(meshAttributeArray, index
|
|
322
|
-
vertexData.push(Vector2.FromArray(meshAttributeArray, index + stride));
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
* @param
|
|
342
|
-
* @param
|
|
343
|
-
* @param
|
|
344
|
-
* @param
|
|
345
|
-
* @param
|
|
346
|
-
* @param
|
|
347
|
-
* @param
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
var
|
|
354
|
-
var
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
case VertexBuffer.
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
vertexData.push(Vector3.FromArray(meshAttributeArray, index + stride));
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
case VertexBuffer.
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
* @param
|
|
402
|
-
* @param
|
|
403
|
-
* @param
|
|
404
|
-
* @param
|
|
405
|
-
* @param
|
|
406
|
-
* @param
|
|
407
|
-
* @param
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
var
|
|
414
|
-
var
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
case VertexBuffer.
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
case VertexBuffer.
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
*
|
|
462
|
-
* @param
|
|
463
|
-
* @param
|
|
464
|
-
* @param
|
|
465
|
-
* @param
|
|
466
|
-
* @param
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
byteOffset
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
* @param
|
|
505
|
-
* @param
|
|
506
|
-
* @param
|
|
507
|
-
* @param
|
|
508
|
-
* @param
|
|
509
|
-
* @param
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
var
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
var
|
|
553
|
-
var
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
case VertexBuffer.
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
case VertexBuffer.
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
case VertexBuffer.
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
*
|
|
637
|
-
*
|
|
638
|
-
* @param
|
|
639
|
-
* @param
|
|
640
|
-
* @param
|
|
641
|
-
* @param
|
|
642
|
-
* @param
|
|
643
|
-
* @param
|
|
644
|
-
* @param
|
|
645
|
-
* @param
|
|
646
|
-
* @param
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
var
|
|
651
|
-
var
|
|
652
|
-
var
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
var
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
minMax.
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
vertexData.
|
|
676
|
-
|
|
677
|
-
morphData.
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
*
|
|
740
|
-
* @param
|
|
741
|
-
* @param
|
|
742
|
-
* @
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
var
|
|
747
|
-
var
|
|
748
|
-
var
|
|
749
|
-
var
|
|
750
|
-
var
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
this._glTF.
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
this.
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
_this.
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
byteOffset
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
image.
|
|
804
|
-
image.
|
|
805
|
-
image.
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
*
|
|
825
|
-
* @param
|
|
826
|
-
* @
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
var
|
|
835
|
-
var
|
|
836
|
-
var
|
|
837
|
-
var
|
|
838
|
-
container
|
|
839
|
-
container.glTFFiles[
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
*
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
var
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
*
|
|
868
|
-
* @
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
var
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
* @param
|
|
878
|
-
* @
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
var
|
|
887
|
-
var
|
|
888
|
-
var
|
|
889
|
-
var
|
|
890
|
-
var
|
|
891
|
-
var
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
var
|
|
903
|
-
var
|
|
904
|
-
var
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
var
|
|
908
|
-
headerBufferView
|
|
909
|
-
headerBufferView.setUint32(
|
|
910
|
-
headerBufferView.setUint32(
|
|
911
|
-
//
|
|
912
|
-
|
|
913
|
-
var
|
|
914
|
-
jsonChunkBufferView
|
|
915
|
-
jsonChunkBufferView.setUint32(
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
if
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
if
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
var
|
|
943
|
-
binaryChunkBufferView
|
|
944
|
-
binaryChunkBufferView.setUint32(
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
var
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
var
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
glbData.push(
|
|
963
|
-
|
|
964
|
-
var
|
|
965
|
-
container
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
*
|
|
978
|
-
* @param
|
|
979
|
-
* @param
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
*
|
|
1028
|
-
* @param
|
|
1029
|
-
* @param
|
|
1030
|
-
* @param
|
|
1031
|
-
* @param
|
|
1032
|
-
* @param
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
var
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
var
|
|
1046
|
-
var
|
|
1047
|
-
|
|
1048
|
-
this.
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
*
|
|
1055
|
-
* @param
|
|
1056
|
-
* @param
|
|
1057
|
-
* @param
|
|
1058
|
-
* @param
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
var
|
|
1069
|
-
var
|
|
1070
|
-
var
|
|
1071
|
-
var
|
|
1072
|
-
var
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
var
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
this.
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
var
|
|
1083
|
-
var
|
|
1084
|
-
var
|
|
1085
|
-
var
|
|
1086
|
-
var
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
var
|
|
1090
|
-
var
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
this.
|
|
1094
|
-
|
|
1095
|
-
accessor.
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
var
|
|
1100
|
-
var
|
|
1101
|
-
var
|
|
1102
|
-
var
|
|
1103
|
-
var
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
var
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
this.
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
*
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
*
|
|
1127
|
-
* @param
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
*
|
|
1168
|
-
* @param
|
|
1169
|
-
* @
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
*
|
|
1221
|
-
* @param
|
|
1222
|
-
* @param
|
|
1223
|
-
* @param
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
var
|
|
1228
|
-
var
|
|
1229
|
-
var
|
|
1230
|
-
var
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
{ kind: VertexBuffer.
|
|
1240
|
-
{ kind: VertexBuffer.
|
|
1241
|
-
{ kind: VertexBuffer.
|
|
1242
|
-
{ kind: VertexBuffer.
|
|
1243
|
-
{ kind: VertexBuffer.
|
|
1244
|
-
{ kind: VertexBuffer.
|
|
1245
|
-
{ kind: VertexBuffer.
|
|
1246
|
-
{ kind: VertexBuffer.
|
|
1247
|
-
{ kind: VertexBuffer.
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
var
|
|
1252
|
-
var
|
|
1253
|
-
var
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
var
|
|
1258
|
-
var
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
var
|
|
1289
|
-
var
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
var
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
var
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
var
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
this.
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
var
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
*
|
|
1404
|
-
* @
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
*
|
|
1430
|
-
*
|
|
1431
|
-
* @param
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
var
|
|
1436
|
-
var
|
|
1437
|
-
var
|
|
1438
|
-
var
|
|
1439
|
-
var
|
|
1440
|
-
var
|
|
1441
|
-
|
|
1442
|
-
this.
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
rootNode.
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
glTFNode.extras = babylonNode.metadata
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
}
|
|
1522
|
-
if (
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
*
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
*
|
|
1607
|
-
* @
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
var
|
|
1614
|
-
var
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
return
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
}
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
*
|
|
1672
|
-
* @
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
}
|
|
1684
|
-
if (babylonNode
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
return node;
|
|
1710
|
-
}
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
*
|
|
1718
|
-
* @
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
var
|
|
1729
|
-
|
|
1730
|
-
var
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
}
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
var
|
|
1757
|
-
|
|
1758
|
-
var
|
|
1759
|
-
var
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
inverseBindMatrices
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
}
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
vector4.
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
this._dataView.setFloat32(byteOffset
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
if (
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
}
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
}
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
}
|
|
1972
|
-
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
|
+
import { Vector2, Vector3, Vector4, Quaternion } from "@babylonjs/core/Maths/math.vector.js";
|
|
3
|
+
import { Color3, Color4 } from "@babylonjs/core/Maths/math.color.js";
|
|
4
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
5
|
+
import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
|
|
6
|
+
import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
|
|
7
|
+
import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh.js";
|
|
8
|
+
import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
|
9
|
+
import { LinesMesh } from "@babylonjs/core/Meshes/linesMesh.js";
|
|
10
|
+
import { InstancedMesh } from "@babylonjs/core/Meshes/instancedMesh.js";
|
|
11
|
+
import { Material } from "@babylonjs/core/Materials/material.js";
|
|
12
|
+
import { Engine } from "@babylonjs/core/Engines/engine.js";
|
|
13
|
+
import { _GLTFMaterialExporter } from "./glTFMaterialExporter.js";
|
|
14
|
+
import { _GLTFUtilities } from "./glTFUtilities.js";
|
|
15
|
+
import { GLTFData } from "./glTFData.js";
|
|
16
|
+
import { _GLTFAnimation } from "./glTFAnimation.js";
|
|
17
|
+
import { Camera } from "@babylonjs/core/Cameras/camera.js";
|
|
18
|
+
import { EngineStore } from "@babylonjs/core/Engines/engineStore.js";
|
|
19
|
+
import { MultiMaterial } from "@babylonjs/core/Materials/multiMaterial.js";
|
|
20
|
+
/**
|
|
21
|
+
* Converts Babylon Scene into glTF 2.0.
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
var _Exporter = /** @class */ (function () {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a glTF Exporter instance, which can accept optional exporter options
|
|
27
|
+
* @param babylonScene Babylon scene object
|
|
28
|
+
* @param options Options to modify the behavior of the exporter
|
|
29
|
+
*/
|
|
30
|
+
function _Exporter(babylonScene, options) {
|
|
31
|
+
/*
|
|
32
|
+
* Specifies if root Babylon empty nodes that act as a coordinate space transform should be included in export
|
|
33
|
+
*/
|
|
34
|
+
this._includeCoordinateSystemConversionNodes = false;
|
|
35
|
+
this._extensions = {};
|
|
36
|
+
this._glTF = {
|
|
37
|
+
asset: { generator: "Babylon.js v".concat(Engine.Version), version: "2.0" },
|
|
38
|
+
};
|
|
39
|
+
babylonScene = babylonScene || EngineStore.LastCreatedScene;
|
|
40
|
+
if (!babylonScene) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this._babylonScene = babylonScene;
|
|
44
|
+
this._bufferViews = [];
|
|
45
|
+
this._accessors = [];
|
|
46
|
+
this._meshes = [];
|
|
47
|
+
this._scenes = [];
|
|
48
|
+
this._cameras = [];
|
|
49
|
+
this._nodes = [];
|
|
50
|
+
this._images = [];
|
|
51
|
+
this._materials = [];
|
|
52
|
+
this._materialMap = [];
|
|
53
|
+
this._textures = [];
|
|
54
|
+
this._samplers = [];
|
|
55
|
+
this._skins = [];
|
|
56
|
+
this._animations = [];
|
|
57
|
+
this._imageData = {};
|
|
58
|
+
this._orderedImageData = [];
|
|
59
|
+
this._options = options || {};
|
|
60
|
+
this._animationSampleRate = options && options.animationSampleRate ? options.animationSampleRate : 1 / 60;
|
|
61
|
+
this._includeCoordinateSystemConversionNodes = options && options.includeCoordinateSystemConversionNodes ? true : false;
|
|
62
|
+
this._glTFMaterialExporter = new _GLTFMaterialExporter(this);
|
|
63
|
+
this._loadExtensions();
|
|
64
|
+
}
|
|
65
|
+
_Exporter.prototype._applyExtension = function (node, extensions, index, actionAsync) {
|
|
66
|
+
var _this = this;
|
|
67
|
+
if (index >= extensions.length) {
|
|
68
|
+
return Promise.resolve(node);
|
|
69
|
+
}
|
|
70
|
+
var currentPromise = actionAsync(extensions[index], node);
|
|
71
|
+
if (!currentPromise) {
|
|
72
|
+
return this._applyExtension(node, extensions, index + 1, actionAsync);
|
|
73
|
+
}
|
|
74
|
+
return currentPromise.then(function (newNode) { return _this._applyExtension(newNode, extensions, index + 1, actionAsync); });
|
|
75
|
+
};
|
|
76
|
+
_Exporter.prototype._applyExtensions = function (node, actionAsync) {
|
|
77
|
+
var extensions = [];
|
|
78
|
+
for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
|
|
79
|
+
var name_1 = _a[_i];
|
|
80
|
+
extensions.push(this._extensions[name_1]);
|
|
81
|
+
}
|
|
82
|
+
return this._applyExtension(node, extensions, 0, actionAsync);
|
|
83
|
+
};
|
|
84
|
+
_Exporter.prototype._extensionsPreExportTextureAsync = function (context, babylonTexture, mimeType) {
|
|
85
|
+
return this._applyExtensions(babylonTexture, function (extension, node) { return extension.preExportTextureAsync && extension.preExportTextureAsync(context, node, mimeType); });
|
|
86
|
+
};
|
|
87
|
+
_Exporter.prototype._extensionsPostExportMeshPrimitiveAsync = function (context, meshPrimitive, babylonSubMesh, binaryWriter) {
|
|
88
|
+
return this._applyExtensions(meshPrimitive, function (extension, node) { return extension.postExportMeshPrimitiveAsync && extension.postExportMeshPrimitiveAsync(context, node, babylonSubMesh, binaryWriter); });
|
|
89
|
+
};
|
|
90
|
+
_Exporter.prototype._extensionsPostExportNodeAsync = function (context, node, babylonNode, nodeMap) {
|
|
91
|
+
return this._applyExtensions(node, function (extension, node) { return extension.postExportNodeAsync && extension.postExportNodeAsync(context, node, babylonNode, nodeMap); });
|
|
92
|
+
};
|
|
93
|
+
_Exporter.prototype._extensionsPostExportMaterialAsync = function (context, material, babylonMaterial) {
|
|
94
|
+
return this._applyExtensions(material, function (extension, node) { return extension.postExportMaterialAsync && extension.postExportMaterialAsync(context, node, babylonMaterial); });
|
|
95
|
+
};
|
|
96
|
+
_Exporter.prototype._extensionsPostExportMaterialAdditionalTextures = function (context, material, babylonMaterial) {
|
|
97
|
+
var output = [];
|
|
98
|
+
for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
|
|
99
|
+
var name_2 = _a[_i];
|
|
100
|
+
var extension = this._extensions[name_2];
|
|
101
|
+
if (extension.postExportMaterialAdditionalTextures) {
|
|
102
|
+
output.push.apply(output, extension.postExportMaterialAdditionalTextures(context, material, babylonMaterial));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return output;
|
|
106
|
+
};
|
|
107
|
+
_Exporter.prototype._extensionsPostExportTextures = function (context, textureInfo, babylonTexture) {
|
|
108
|
+
for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
|
|
109
|
+
var name_3 = _a[_i];
|
|
110
|
+
var extension = this._extensions[name_3];
|
|
111
|
+
if (extension.postExportTexture) {
|
|
112
|
+
extension.postExportTexture(context, textureInfo, babylonTexture);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
_Exporter.prototype._forEachExtensions = function (action) {
|
|
117
|
+
for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
|
|
118
|
+
var name_4 = _a[_i];
|
|
119
|
+
var extension = this._extensions[name_4];
|
|
120
|
+
if (extension.enabled) {
|
|
121
|
+
action(extension);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
_Exporter.prototype._extensionsOnExporting = function () {
|
|
126
|
+
var _this = this;
|
|
127
|
+
this._forEachExtensions(function (extension) {
|
|
128
|
+
if (extension.wasUsed) {
|
|
129
|
+
if (_this._glTF.extensionsUsed == null) {
|
|
130
|
+
_this._glTF.extensionsUsed = [];
|
|
131
|
+
}
|
|
132
|
+
if (_this._glTF.extensionsUsed.indexOf(extension.name) === -1) {
|
|
133
|
+
_this._glTF.extensionsUsed.push(extension.name);
|
|
134
|
+
}
|
|
135
|
+
if (extension.required) {
|
|
136
|
+
if (_this._glTF.extensionsRequired == null) {
|
|
137
|
+
_this._glTF.extensionsRequired = [];
|
|
138
|
+
}
|
|
139
|
+
if (_this._glTF.extensionsRequired.indexOf(extension.name) === -1) {
|
|
140
|
+
_this._glTF.extensionsRequired.push(extension.name);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (_this._glTF.extensions == null) {
|
|
144
|
+
_this._glTF.extensions = {};
|
|
145
|
+
}
|
|
146
|
+
if (extension.onExporting) {
|
|
147
|
+
extension.onExporting();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Load glTF serializer extensions
|
|
154
|
+
*/
|
|
155
|
+
_Exporter.prototype._loadExtensions = function () {
|
|
156
|
+
for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
|
|
157
|
+
var name_5 = _a[_i];
|
|
158
|
+
var extension = _Exporter._ExtensionFactories[name_5](this);
|
|
159
|
+
this._extensions[name_5] = extension;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
_Exporter.prototype.dispose = function () {
|
|
163
|
+
for (var extensionKey in this._extensions) {
|
|
164
|
+
var extension = this._extensions[extensionKey];
|
|
165
|
+
extension.dispose();
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Registers a glTF exporter extension
|
|
170
|
+
* @param name Name of the extension to export
|
|
171
|
+
* @param factory The factory function that creates the exporter extension
|
|
172
|
+
*/
|
|
173
|
+
_Exporter.RegisterExtension = function (name, factory) {
|
|
174
|
+
if (_Exporter.UnregisterExtension(name)) {
|
|
175
|
+
Tools.Warn("Extension with the name ".concat(name, " already exists"));
|
|
176
|
+
}
|
|
177
|
+
_Exporter._ExtensionFactories[name] = factory;
|
|
178
|
+
_Exporter._ExtensionNames.push(name);
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Un-registers an exporter extension
|
|
182
|
+
* @param name The name fo the exporter extension
|
|
183
|
+
* @returns A boolean indicating whether the extension has been un-registered
|
|
184
|
+
*/
|
|
185
|
+
_Exporter.UnregisterExtension = function (name) {
|
|
186
|
+
if (!_Exporter._ExtensionFactories[name]) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
delete _Exporter._ExtensionFactories[name];
|
|
190
|
+
var index = _Exporter._ExtensionNames.indexOf(name);
|
|
191
|
+
if (index !== -1) {
|
|
192
|
+
_Exporter._ExtensionNames.splice(index, 1);
|
|
193
|
+
}
|
|
194
|
+
return true;
|
|
195
|
+
};
|
|
196
|
+
_Exporter.prototype._reorderIndicesBasedOnPrimitiveMode = function (submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter) {
|
|
197
|
+
switch (primitiveMode) {
|
|
198
|
+
case Material.TriangleFillMode: {
|
|
199
|
+
if (!byteOffset) {
|
|
200
|
+
byteOffset = 0;
|
|
201
|
+
}
|
|
202
|
+
for (var i = submesh.indexStart, length_1 = submesh.indexStart + submesh.indexCount; i < length_1; i = i + 3) {
|
|
203
|
+
var index = byteOffset + i * 4;
|
|
204
|
+
// swap the second and third indices
|
|
205
|
+
var secondIndex = binaryWriter.getUInt32(index + 4);
|
|
206
|
+
var thirdIndex = binaryWriter.getUInt32(index + 8);
|
|
207
|
+
binaryWriter.setUInt32(thirdIndex, index + 4);
|
|
208
|
+
binaryWriter.setUInt32(secondIndex, index + 8);
|
|
209
|
+
}
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
case Material.TriangleFanDrawMode: {
|
|
213
|
+
for (var i = submesh.indexStart + submesh.indexCount - 1, start = submesh.indexStart; i >= start; --i) {
|
|
214
|
+
binaryWriter.setUInt32(babylonIndices[i], byteOffset);
|
|
215
|
+
byteOffset += 4;
|
|
216
|
+
}
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
case Material.TriangleStripDrawMode: {
|
|
220
|
+
if (submesh.indexCount >= 3) {
|
|
221
|
+
binaryWriter.setUInt32(babylonIndices[submesh.indexStart + 2], byteOffset + 4);
|
|
222
|
+
binaryWriter.setUInt32(babylonIndices[submesh.indexStart + 1], byteOffset + 8);
|
|
223
|
+
}
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is
|
|
230
|
+
* clock-wise during export to glTF
|
|
231
|
+
* @param submesh BabylonJS submesh
|
|
232
|
+
* @param primitiveMode Primitive mode of the mesh
|
|
233
|
+
* @param sideOrientation the winding order of the submesh
|
|
234
|
+
* @param vertexBufferKind The type of vertex attribute
|
|
235
|
+
* @param meshAttributeArray The vertex attribute data
|
|
236
|
+
* @param byteOffset The offset to the binary data
|
|
237
|
+
* @param binaryWriter The binary data for the glTF file
|
|
238
|
+
* @param convertToRightHandedSystem Converts the values to right-handed
|
|
239
|
+
*/
|
|
240
|
+
_Exporter.prototype._reorderVertexAttributeDataBasedOnPrimitiveMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem) {
|
|
241
|
+
if (convertToRightHandedSystem && sideOrientation === Material.ClockWiseSideOrientation) {
|
|
242
|
+
switch (primitiveMode) {
|
|
243
|
+
case Material.TriangleFillMode: {
|
|
244
|
+
this._reorderTriangleFillMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem);
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
case Material.TriangleStripDrawMode: {
|
|
248
|
+
this._reorderTriangleStripDrawMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem);
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
case Material.TriangleFanDrawMode: {
|
|
252
|
+
this._reorderTriangleFanMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is
|
|
260
|
+
* clock-wise during export to glTF
|
|
261
|
+
* @param submesh BabylonJS submesh
|
|
262
|
+
* @param primitiveMode Primitive mode of the mesh
|
|
263
|
+
* @param sideOrientation the winding order of the submesh
|
|
264
|
+
* @param vertexBufferKind The type of vertex attribute
|
|
265
|
+
* @param meshAttributeArray The vertex attribute data
|
|
266
|
+
* @param byteOffset The offset to the binary data
|
|
267
|
+
* @param binaryWriter The binary data for the glTF file
|
|
268
|
+
* @param convertToRightHandedSystem Converts the values to right-handed
|
|
269
|
+
*/
|
|
270
|
+
_Exporter.prototype._reorderTriangleFillMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem) {
|
|
271
|
+
var vertexBuffer = this._getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());
|
|
272
|
+
if (vertexBuffer) {
|
|
273
|
+
var stride = vertexBuffer.byteStride / VertexBuffer.GetTypeByteLength(vertexBuffer.type);
|
|
274
|
+
if (submesh.verticesCount % 3 !== 0) {
|
|
275
|
+
Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
var vertexData = [];
|
|
279
|
+
var index = 0;
|
|
280
|
+
switch (vertexBufferKind) {
|
|
281
|
+
case VertexBuffer.PositionKind:
|
|
282
|
+
case VertexBuffer.NormalKind: {
|
|
283
|
+
for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
|
|
284
|
+
index = x * stride;
|
|
285
|
+
vertexData.push(Vector3.FromArray(meshAttributeArray, index));
|
|
286
|
+
vertexData.push(Vector3.FromArray(meshAttributeArray, index + 2 * stride));
|
|
287
|
+
vertexData.push(Vector3.FromArray(meshAttributeArray, index + stride));
|
|
288
|
+
}
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
case VertexBuffer.TangentKind: {
|
|
292
|
+
for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
|
|
293
|
+
index = x * stride;
|
|
294
|
+
vertexData.push(Vector4.FromArray(meshAttributeArray, index));
|
|
295
|
+
vertexData.push(Vector4.FromArray(meshAttributeArray, index + 2 * stride));
|
|
296
|
+
vertexData.push(Vector4.FromArray(meshAttributeArray, index + stride));
|
|
297
|
+
}
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
case VertexBuffer.ColorKind: {
|
|
301
|
+
var size = vertexBuffer.getSize();
|
|
302
|
+
for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + size) {
|
|
303
|
+
index = x * stride;
|
|
304
|
+
if (size === 4) {
|
|
305
|
+
vertexData.push(Vector4.FromArray(meshAttributeArray, index));
|
|
306
|
+
vertexData.push(Vector4.FromArray(meshAttributeArray, index + 2 * stride));
|
|
307
|
+
vertexData.push(Vector4.FromArray(meshAttributeArray, index + stride));
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
vertexData.push(Vector3.FromArray(meshAttributeArray, index));
|
|
311
|
+
vertexData.push(Vector3.FromArray(meshAttributeArray, index + 2 * stride));
|
|
312
|
+
vertexData.push(Vector3.FromArray(meshAttributeArray, index + stride));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
case VertexBuffer.UVKind:
|
|
318
|
+
case VertexBuffer.UV2Kind: {
|
|
319
|
+
for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
|
|
320
|
+
index = x * stride;
|
|
321
|
+
vertexData.push(Vector2.FromArray(meshAttributeArray, index));
|
|
322
|
+
vertexData.push(Vector2.FromArray(meshAttributeArray, index + 2 * stride));
|
|
323
|
+
vertexData.push(Vector2.FromArray(meshAttributeArray, index + stride));
|
|
324
|
+
}
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
default: {
|
|
328
|
+
Tools.Error("Unsupported Vertex Buffer type: ".concat(vertexBufferKind));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
this._writeVertexAttributeData(vertexData, byteOffset, vertexBufferKind, meshAttributeArray, binaryWriter, convertToRightHandedSystem);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(vertexBufferKind, " not present!"));
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is
|
|
340
|
+
* clock-wise during export to glTF
|
|
341
|
+
* @param submesh BabylonJS submesh
|
|
342
|
+
* @param primitiveMode Primitive mode of the mesh
|
|
343
|
+
* @param sideOrientation the winding order of the submesh
|
|
344
|
+
* @param vertexBufferKind The type of vertex attribute
|
|
345
|
+
* @param meshAttributeArray The vertex attribute data
|
|
346
|
+
* @param byteOffset The offset to the binary data
|
|
347
|
+
* @param binaryWriter The binary data for the glTF file
|
|
348
|
+
* @param convertToRightHandedSystem Converts the values to right-handed
|
|
349
|
+
*/
|
|
350
|
+
_Exporter.prototype._reorderTriangleStripDrawMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem) {
|
|
351
|
+
var vertexBuffer = this._getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());
|
|
352
|
+
if (vertexBuffer) {
|
|
353
|
+
var stride = vertexBuffer.byteStride / VertexBuffer.GetTypeByteLength(vertexBuffer.type);
|
|
354
|
+
var vertexData = [];
|
|
355
|
+
var index = 0;
|
|
356
|
+
switch (vertexBufferKind) {
|
|
357
|
+
case VertexBuffer.PositionKind:
|
|
358
|
+
case VertexBuffer.NormalKind: {
|
|
359
|
+
index = submesh.verticesStart;
|
|
360
|
+
vertexData.push(Vector3.FromArray(meshAttributeArray, index + 2 * stride));
|
|
361
|
+
vertexData.push(Vector3.FromArray(meshAttributeArray, index + stride));
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
case VertexBuffer.TangentKind: {
|
|
365
|
+
for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
|
|
366
|
+
index = x * stride;
|
|
367
|
+
vertexData.push(Vector4.FromArray(meshAttributeArray, index));
|
|
368
|
+
}
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
case VertexBuffer.ColorKind: {
|
|
372
|
+
for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
|
|
373
|
+
index = x * stride;
|
|
374
|
+
vertexBuffer.getSize() === 4
|
|
375
|
+
? vertexData.push(Vector4.FromArray(meshAttributeArray, index))
|
|
376
|
+
: vertexData.push(Vector3.FromArray(meshAttributeArray, index));
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
case VertexBuffer.UVKind:
|
|
381
|
+
case VertexBuffer.UV2Kind: {
|
|
382
|
+
for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
|
|
383
|
+
index = x * stride;
|
|
384
|
+
vertexData.push(Vector2.FromArray(meshAttributeArray, index));
|
|
385
|
+
}
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
default: {
|
|
389
|
+
Tools.Error("Unsupported Vertex Buffer type: ".concat(vertexBufferKind));
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
this._writeVertexAttributeData(vertexData, byteOffset + 12, vertexBufferKind, meshAttributeArray, binaryWriter, convertToRightHandedSystem);
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(vertexBufferKind, " not present!"));
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is
|
|
400
|
+
* clock-wise during export to glTF
|
|
401
|
+
* @param submesh BabylonJS submesh
|
|
402
|
+
* @param primitiveMode Primitive mode of the mesh
|
|
403
|
+
* @param sideOrientation the winding order of the submesh
|
|
404
|
+
* @param vertexBufferKind The type of vertex attribute
|
|
405
|
+
* @param meshAttributeArray The vertex attribute data
|
|
406
|
+
* @param byteOffset The offset to the binary data
|
|
407
|
+
* @param binaryWriter The binary data for the glTF file
|
|
408
|
+
* @param convertToRightHandedSystem Converts the values to right-handed
|
|
409
|
+
*/
|
|
410
|
+
_Exporter.prototype._reorderTriangleFanMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem) {
|
|
411
|
+
var vertexBuffer = this._getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());
|
|
412
|
+
if (vertexBuffer) {
|
|
413
|
+
var stride = vertexBuffer.byteStride / VertexBuffer.GetTypeByteLength(vertexBuffer.type);
|
|
414
|
+
var vertexData = [];
|
|
415
|
+
var index = 0;
|
|
416
|
+
switch (vertexBufferKind) {
|
|
417
|
+
case VertexBuffer.PositionKind:
|
|
418
|
+
case VertexBuffer.NormalKind: {
|
|
419
|
+
for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
|
|
420
|
+
index = x * stride;
|
|
421
|
+
vertexData.push(Vector3.FromArray(meshAttributeArray, index));
|
|
422
|
+
}
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
case VertexBuffer.TangentKind: {
|
|
426
|
+
for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
|
|
427
|
+
index = x * stride;
|
|
428
|
+
vertexData.push(Vector4.FromArray(meshAttributeArray, index));
|
|
429
|
+
}
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
case VertexBuffer.ColorKind: {
|
|
433
|
+
for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
|
|
434
|
+
index = x * stride;
|
|
435
|
+
vertexData.push(Vector4.FromArray(meshAttributeArray, index));
|
|
436
|
+
vertexBuffer.getSize() === 4
|
|
437
|
+
? vertexData.push(Vector4.FromArray(meshAttributeArray, index))
|
|
438
|
+
: vertexData.push(Vector3.FromArray(meshAttributeArray, index));
|
|
439
|
+
}
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
case VertexBuffer.UVKind:
|
|
443
|
+
case VertexBuffer.UV2Kind: {
|
|
444
|
+
for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
|
|
445
|
+
index = x * stride;
|
|
446
|
+
vertexData.push(Vector2.FromArray(meshAttributeArray, index));
|
|
447
|
+
}
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
default: {
|
|
451
|
+
Tools.Error("Unsupported Vertex Buffer type: ".concat(vertexBufferKind));
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
this._writeVertexAttributeData(vertexData, byteOffset, vertexBufferKind, meshAttributeArray, binaryWriter, convertToRightHandedSystem);
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(vertexBufferKind, " not present!"));
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
/**
|
|
461
|
+
* Writes the vertex attribute data to binary
|
|
462
|
+
* @param vertices The vertices to write to the binary writer
|
|
463
|
+
* @param byteOffset The offset into the binary writer to overwrite binary data
|
|
464
|
+
* @param vertexAttributeKind The vertex attribute type
|
|
465
|
+
* @param meshAttributeArray The vertex attribute data
|
|
466
|
+
* @param binaryWriter The writer containing the binary data
|
|
467
|
+
* @param convertToRightHandedSystem Converts the values to right-handed
|
|
468
|
+
*/
|
|
469
|
+
_Exporter.prototype._writeVertexAttributeData = function (vertices, byteOffset, vertexAttributeKind, meshAttributeArray, binaryWriter, convertToRightHandedSystem) {
|
|
470
|
+
for (var _i = 0, vertices_1 = vertices; _i < vertices_1.length; _i++) {
|
|
471
|
+
var vertex = vertices_1[_i];
|
|
472
|
+
if (convertToRightHandedSystem && !(vertexAttributeKind === VertexBuffer.ColorKind) && !(vertex instanceof Vector2)) {
|
|
473
|
+
if (vertex instanceof Vector3) {
|
|
474
|
+
if (vertexAttributeKind === VertexBuffer.NormalKind) {
|
|
475
|
+
_GLTFUtilities._GetRightHandedNormalVector3FromRef(vertex);
|
|
476
|
+
}
|
|
477
|
+
else if (vertexAttributeKind === VertexBuffer.PositionKind) {
|
|
478
|
+
_GLTFUtilities._GetRightHandedPositionVector3FromRef(vertex);
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
Tools.Error("Unsupported vertex attribute kind!");
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
_GLTFUtilities._GetRightHandedVector4FromRef(vertex);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (vertexAttributeKind === VertexBuffer.NormalKind) {
|
|
489
|
+
vertex.normalize();
|
|
490
|
+
}
|
|
491
|
+
else if (vertexAttributeKind === VertexBuffer.TangentKind && vertex instanceof Vector4) {
|
|
492
|
+
_GLTFUtilities._NormalizeTangentFromRef(vertex);
|
|
493
|
+
}
|
|
494
|
+
for (var _a = 0, _b = vertex.asArray(); _a < _b.length; _a++) {
|
|
495
|
+
var component = _b[_a];
|
|
496
|
+
binaryWriter.setFloat32(component, byteOffset);
|
|
497
|
+
byteOffset += 4;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* Writes mesh attribute data to a data buffer
|
|
503
|
+
* Returns the bytelength of the data
|
|
504
|
+
* @param vertexBufferKind Indicates what kind of vertex data is being passed in
|
|
505
|
+
* @param attributeComponentKind
|
|
506
|
+
* @param meshAttributeArray Array containing the attribute data
|
|
507
|
+
* @param stride Specifies the space between data
|
|
508
|
+
* @param binaryWriter The buffer to write the binary data to
|
|
509
|
+
* @param convertToRightHandedSystem Converts the values to right-handed
|
|
510
|
+
* @param babylonTransformNode
|
|
511
|
+
*/
|
|
512
|
+
_Exporter.prototype._writeAttributeData = function (vertexBufferKind, attributeComponentKind, meshAttributeArray, stride, binaryWriter, convertToRightHandedSystem, babylonTransformNode) {
|
|
513
|
+
var vertexAttributes = [];
|
|
514
|
+
var index;
|
|
515
|
+
switch (vertexBufferKind) {
|
|
516
|
+
case VertexBuffer.PositionKind: {
|
|
517
|
+
for (var k = 0, length_2 = meshAttributeArray.length / stride; k < length_2; ++k) {
|
|
518
|
+
index = k * stride;
|
|
519
|
+
var vertexData = Vector3.FromArray(meshAttributeArray, index);
|
|
520
|
+
if (convertToRightHandedSystem) {
|
|
521
|
+
_GLTFUtilities._GetRightHandedPositionVector3FromRef(vertexData);
|
|
522
|
+
}
|
|
523
|
+
vertexAttributes.push(vertexData.asArray());
|
|
524
|
+
}
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
case VertexBuffer.NormalKind: {
|
|
528
|
+
for (var k = 0, length_3 = meshAttributeArray.length / stride; k < length_3; ++k) {
|
|
529
|
+
index = k * stride;
|
|
530
|
+
var vertexData = Vector3.FromArray(meshAttributeArray, index);
|
|
531
|
+
if (convertToRightHandedSystem) {
|
|
532
|
+
_GLTFUtilities._GetRightHandedNormalVector3FromRef(vertexData);
|
|
533
|
+
}
|
|
534
|
+
vertexData.normalize();
|
|
535
|
+
vertexAttributes.push(vertexData.asArray());
|
|
536
|
+
}
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
case VertexBuffer.TangentKind: {
|
|
540
|
+
for (var k = 0, length_4 = meshAttributeArray.length / stride; k < length_4; ++k) {
|
|
541
|
+
index = k * stride;
|
|
542
|
+
var vertexData = Vector4.FromArray(meshAttributeArray, index);
|
|
543
|
+
if (convertToRightHandedSystem) {
|
|
544
|
+
_GLTFUtilities._GetRightHandedVector4FromRef(vertexData);
|
|
545
|
+
}
|
|
546
|
+
_GLTFUtilities._NormalizeTangentFromRef(vertexData);
|
|
547
|
+
vertexAttributes.push(vertexData.asArray());
|
|
548
|
+
}
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
case VertexBuffer.ColorKind: {
|
|
552
|
+
var meshMaterial = babylonTransformNode.material;
|
|
553
|
+
var convertToLinear = meshMaterial ? meshMaterial.getClassName() === "StandardMaterial" : true;
|
|
554
|
+
var vertexData = stride === 3 ? new Color3() : new Color4();
|
|
555
|
+
for (var k = 0, length_5 = meshAttributeArray.length / stride; k < length_5; ++k) {
|
|
556
|
+
index = k * stride;
|
|
557
|
+
if (stride === 3) {
|
|
558
|
+
Color3.FromArrayToRef(meshAttributeArray, index, vertexData);
|
|
559
|
+
if (convertToLinear) {
|
|
560
|
+
vertexData.toLinearSpaceToRef(vertexData);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
Color4.FromArrayToRef(meshAttributeArray, index, vertexData);
|
|
565
|
+
if (convertToLinear) {
|
|
566
|
+
vertexData.toLinearSpaceToRef(vertexData);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
vertexAttributes.push(vertexData.asArray());
|
|
570
|
+
}
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
573
|
+
case VertexBuffer.UVKind:
|
|
574
|
+
case VertexBuffer.UV2Kind: {
|
|
575
|
+
for (var k = 0, length_6 = meshAttributeArray.length / stride; k < length_6; ++k) {
|
|
576
|
+
index = k * stride;
|
|
577
|
+
vertexAttributes.push(convertToRightHandedSystem ? [meshAttributeArray[index], meshAttributeArray[index + 1]] : [meshAttributeArray[index], meshAttributeArray[index + 1]]);
|
|
578
|
+
}
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
case VertexBuffer.MatricesIndicesKind:
|
|
582
|
+
case VertexBuffer.MatricesIndicesExtraKind: {
|
|
583
|
+
for (var k = 0, length_7 = meshAttributeArray.length / stride; k < length_7; ++k) {
|
|
584
|
+
index = k * stride;
|
|
585
|
+
var vertexData = Vector4.FromArray(meshAttributeArray, index);
|
|
586
|
+
vertexAttributes.push(vertexData.asArray());
|
|
587
|
+
}
|
|
588
|
+
break;
|
|
589
|
+
}
|
|
590
|
+
case VertexBuffer.MatricesWeightsKind:
|
|
591
|
+
case VertexBuffer.MatricesWeightsExtraKind: {
|
|
592
|
+
for (var k = 0, length_8 = meshAttributeArray.length / stride; k < length_8; ++k) {
|
|
593
|
+
index = k * stride;
|
|
594
|
+
var vertexData = Vector4.FromArray(meshAttributeArray, index);
|
|
595
|
+
vertexAttributes.push(vertexData.asArray());
|
|
596
|
+
}
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
default: {
|
|
600
|
+
Tools.Warn("Unsupported Vertex Buffer Type: " + vertexBufferKind);
|
|
601
|
+
vertexAttributes = [];
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
var writeBinaryFunc;
|
|
605
|
+
switch (attributeComponentKind) {
|
|
606
|
+
case 5121 /* UNSIGNED_BYTE */: {
|
|
607
|
+
writeBinaryFunc = binaryWriter.setUInt8.bind(binaryWriter);
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
case 5123 /* UNSIGNED_SHORT */: {
|
|
611
|
+
writeBinaryFunc = binaryWriter.setUInt16.bind(binaryWriter);
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
case 5125 /* UNSIGNED_INT */: {
|
|
615
|
+
writeBinaryFunc = binaryWriter.setUInt32.bind(binaryWriter);
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
case 5126 /* FLOAT */: {
|
|
619
|
+
writeBinaryFunc = binaryWriter.setFloat32.bind(binaryWriter);
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
default: {
|
|
623
|
+
Tools.Warn("Unsupported Attribute Component kind: " + attributeComponentKind);
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
for (var _i = 0, vertexAttributes_1 = vertexAttributes; _i < vertexAttributes_1.length; _i++) {
|
|
628
|
+
var vertexAttribute = vertexAttributes_1[_i];
|
|
629
|
+
for (var _a = 0, vertexAttribute_1 = vertexAttribute; _a < vertexAttribute_1.length; _a++) {
|
|
630
|
+
var component = vertexAttribute_1[_a];
|
|
631
|
+
writeBinaryFunc(component);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
/**
|
|
636
|
+
* Writes mesh attribute data to a data buffer
|
|
637
|
+
* Returns the bytelength of the data
|
|
638
|
+
* @param vertexBufferKind Indicates what kind of vertex data is being passed in
|
|
639
|
+
* @param attributeComponentKind
|
|
640
|
+
* @param meshPrimitive
|
|
641
|
+
* @param morphTarget
|
|
642
|
+
* @param meshAttributeArray Array containing the attribute data
|
|
643
|
+
* @param morphTargetAttributeArray
|
|
644
|
+
* @param stride Specifies the space between data
|
|
645
|
+
* @param binaryWriter The buffer to write the binary data to
|
|
646
|
+
* @param convertToRightHandedSystem Converts the values to right-handed
|
|
647
|
+
* @param minMax
|
|
648
|
+
*/
|
|
649
|
+
_Exporter.prototype.writeMorphTargetAttributeData = function (vertexBufferKind, attributeComponentKind, meshPrimitive, morphTarget, meshAttributeArray, morphTargetAttributeArray, stride, binaryWriter, convertToRightHandedSystem, minMax) {
|
|
650
|
+
var vertexAttributes = [];
|
|
651
|
+
var index;
|
|
652
|
+
var difference = new Vector3();
|
|
653
|
+
var difference4 = new Vector4(0, 0, 0, 0);
|
|
654
|
+
switch (vertexBufferKind) {
|
|
655
|
+
case VertexBuffer.PositionKind: {
|
|
656
|
+
for (var k = meshPrimitive.verticesStart; k < meshPrimitive.verticesCount; ++k) {
|
|
657
|
+
index = meshPrimitive.indexStart + k * stride;
|
|
658
|
+
var vertexData = Vector3.FromArray(meshAttributeArray, index);
|
|
659
|
+
var morphData = Vector3.FromArray(morphTargetAttributeArray, index);
|
|
660
|
+
difference = morphData.subtractToRef(vertexData, difference);
|
|
661
|
+
if (convertToRightHandedSystem) {
|
|
662
|
+
_GLTFUtilities._GetRightHandedPositionVector3FromRef(difference);
|
|
663
|
+
}
|
|
664
|
+
if (minMax) {
|
|
665
|
+
minMax.min.copyFromFloats(Math.min(difference.x, minMax.min.x), Math.min(difference.y, minMax.min.y), Math.min(difference.z, minMax.min.z));
|
|
666
|
+
minMax.max.copyFromFloats(Math.max(difference.x, minMax.max.x), Math.max(difference.y, minMax.max.y), Math.max(difference.z, minMax.max.z));
|
|
667
|
+
}
|
|
668
|
+
vertexAttributes.push(difference.asArray());
|
|
669
|
+
}
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
case VertexBuffer.NormalKind: {
|
|
673
|
+
for (var k = meshPrimitive.verticesStart; k < meshPrimitive.verticesCount; ++k) {
|
|
674
|
+
index = meshPrimitive.indexStart + k * stride;
|
|
675
|
+
var vertexData = Vector3.FromArray(meshAttributeArray, index);
|
|
676
|
+
vertexData.normalize();
|
|
677
|
+
var morphData = Vector3.FromArray(morphTargetAttributeArray, index);
|
|
678
|
+
morphData.normalize();
|
|
679
|
+
difference = morphData.subtractToRef(vertexData, difference);
|
|
680
|
+
if (convertToRightHandedSystem) {
|
|
681
|
+
_GLTFUtilities._GetRightHandedNormalVector3FromRef(difference);
|
|
682
|
+
}
|
|
683
|
+
vertexAttributes.push(difference.asArray());
|
|
684
|
+
}
|
|
685
|
+
break;
|
|
686
|
+
}
|
|
687
|
+
case VertexBuffer.TangentKind: {
|
|
688
|
+
for (var k = meshPrimitive.verticesStart; k < meshPrimitive.verticesCount; ++k) {
|
|
689
|
+
index = meshPrimitive.indexStart + k * (stride + 1);
|
|
690
|
+
var vertexData = Vector4.FromArray(meshAttributeArray, index);
|
|
691
|
+
_GLTFUtilities._NormalizeTangentFromRef(vertexData);
|
|
692
|
+
var morphData = Vector4.FromArray(morphTargetAttributeArray, index);
|
|
693
|
+
_GLTFUtilities._NormalizeTangentFromRef(morphData);
|
|
694
|
+
difference4 = morphData.subtractToRef(vertexData, difference4);
|
|
695
|
+
if (convertToRightHandedSystem) {
|
|
696
|
+
_GLTFUtilities._GetRightHandedVector4FromRef(difference4);
|
|
697
|
+
}
|
|
698
|
+
vertexAttributes.push([difference4.x, difference4.y, difference4.z]);
|
|
699
|
+
}
|
|
700
|
+
break;
|
|
701
|
+
}
|
|
702
|
+
default: {
|
|
703
|
+
Tools.Warn("Unsupported Vertex Buffer Type: " + vertexBufferKind);
|
|
704
|
+
vertexAttributes = [];
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
var writeBinaryFunc;
|
|
708
|
+
switch (attributeComponentKind) {
|
|
709
|
+
case 5121 /* UNSIGNED_BYTE */: {
|
|
710
|
+
writeBinaryFunc = binaryWriter.setUInt8.bind(binaryWriter);
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
case 5123 /* UNSIGNED_SHORT */: {
|
|
714
|
+
writeBinaryFunc = binaryWriter.setUInt16.bind(binaryWriter);
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
case 5125 /* UNSIGNED_INT */: {
|
|
718
|
+
writeBinaryFunc = binaryWriter.setUInt32.bind(binaryWriter);
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
case 5126 /* FLOAT */: {
|
|
722
|
+
writeBinaryFunc = binaryWriter.setFloat32.bind(binaryWriter);
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
default: {
|
|
726
|
+
Tools.Warn("Unsupported Attribute Component kind: " + attributeComponentKind);
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
for (var _i = 0, vertexAttributes_2 = vertexAttributes; _i < vertexAttributes_2.length; _i++) {
|
|
731
|
+
var vertexAttribute = vertexAttributes_2[_i];
|
|
732
|
+
for (var _a = 0, vertexAttribute_2 = vertexAttribute; _a < vertexAttribute_2.length; _a++) {
|
|
733
|
+
var component = vertexAttribute_2[_a];
|
|
734
|
+
writeBinaryFunc(component);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
/**
|
|
739
|
+
* Generates glTF json data
|
|
740
|
+
* @param shouldUseGlb Indicates whether the json should be written for a glb file
|
|
741
|
+
* @param glTFPrefix Text to use when prefixing a glTF file
|
|
742
|
+
* @param prettyPrint Indicates whether the json file should be pretty printed (true) or not (false)
|
|
743
|
+
* @returns json data as string
|
|
744
|
+
*/
|
|
745
|
+
_Exporter.prototype._generateJSON = function (shouldUseGlb, glTFPrefix, prettyPrint) {
|
|
746
|
+
var _this = this;
|
|
747
|
+
var buffer = { byteLength: this._totalByteLength };
|
|
748
|
+
var imageName;
|
|
749
|
+
var imageData;
|
|
750
|
+
var bufferView;
|
|
751
|
+
var byteOffset = this._totalByteLength;
|
|
752
|
+
if (buffer.byteLength) {
|
|
753
|
+
this._glTF.buffers = [buffer];
|
|
754
|
+
}
|
|
755
|
+
if (this._nodes && this._nodes.length) {
|
|
756
|
+
this._glTF.nodes = this._nodes;
|
|
757
|
+
}
|
|
758
|
+
if (this._meshes && this._meshes.length) {
|
|
759
|
+
this._glTF.meshes = this._meshes;
|
|
760
|
+
}
|
|
761
|
+
if (this._scenes && this._scenes.length) {
|
|
762
|
+
this._glTF.scenes = this._scenes;
|
|
763
|
+
this._glTF.scene = 0;
|
|
764
|
+
}
|
|
765
|
+
if (this._cameras && this._cameras.length) {
|
|
766
|
+
this._glTF.cameras = this._cameras;
|
|
767
|
+
}
|
|
768
|
+
if (this._bufferViews && this._bufferViews.length) {
|
|
769
|
+
this._glTF.bufferViews = this._bufferViews;
|
|
770
|
+
}
|
|
771
|
+
if (this._accessors && this._accessors.length) {
|
|
772
|
+
this._glTF.accessors = this._accessors;
|
|
773
|
+
}
|
|
774
|
+
if (this._animations && this._animations.length) {
|
|
775
|
+
this._glTF.animations = this._animations;
|
|
776
|
+
}
|
|
777
|
+
if (this._materials && this._materials.length) {
|
|
778
|
+
this._glTF.materials = this._materials;
|
|
779
|
+
}
|
|
780
|
+
if (this._textures && this._textures.length) {
|
|
781
|
+
this._glTF.textures = this._textures;
|
|
782
|
+
}
|
|
783
|
+
if (this._samplers && this._samplers.length) {
|
|
784
|
+
this._glTF.samplers = this._samplers;
|
|
785
|
+
}
|
|
786
|
+
if (this._skins && this._skins.length) {
|
|
787
|
+
this._glTF.skins = this._skins;
|
|
788
|
+
}
|
|
789
|
+
if (this._images && this._images.length) {
|
|
790
|
+
if (!shouldUseGlb) {
|
|
791
|
+
this._glTF.images = this._images;
|
|
792
|
+
}
|
|
793
|
+
else {
|
|
794
|
+
this._glTF.images = [];
|
|
795
|
+
this._images.forEach(function (image) {
|
|
796
|
+
if (image.uri) {
|
|
797
|
+
imageData = _this._imageData[image.uri];
|
|
798
|
+
_this._orderedImageData.push(imageData);
|
|
799
|
+
imageName = image.uri.split(".")[0] + " image";
|
|
800
|
+
bufferView = _GLTFUtilities._CreateBufferView(0, byteOffset, imageData.data.length, undefined, imageName);
|
|
801
|
+
byteOffset += imageData.data.buffer.byteLength;
|
|
802
|
+
_this._bufferViews.push(bufferView);
|
|
803
|
+
image.bufferView = _this._bufferViews.length - 1;
|
|
804
|
+
image.name = imageName;
|
|
805
|
+
image.mimeType = imageData.mimeType;
|
|
806
|
+
image.uri = undefined;
|
|
807
|
+
if (!_this._glTF.images) {
|
|
808
|
+
_this._glTF.images = [];
|
|
809
|
+
}
|
|
810
|
+
_this._glTF.images.push(image);
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
// Replace uri with bufferview and mime type for glb
|
|
814
|
+
buffer.byteLength = byteOffset;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (!shouldUseGlb) {
|
|
818
|
+
buffer.uri = glTFPrefix + ".bin";
|
|
819
|
+
}
|
|
820
|
+
var jsonText = prettyPrint ? JSON.stringify(this._glTF, null, 2) : JSON.stringify(this._glTF);
|
|
821
|
+
return jsonText;
|
|
822
|
+
};
|
|
823
|
+
/**
|
|
824
|
+
* Generates data for .gltf and .bin files based on the glTF prefix string
|
|
825
|
+
* @param glTFPrefix Text to use when prefixing a glTF file
|
|
826
|
+
* @param dispose Dispose the exporter
|
|
827
|
+
* @returns GLTFData with glTF file data
|
|
828
|
+
*/
|
|
829
|
+
_Exporter.prototype._generateGLTFAsync = function (glTFPrefix, dispose) {
|
|
830
|
+
var _this = this;
|
|
831
|
+
if (dispose === void 0) { dispose = true; }
|
|
832
|
+
return this._generateBinaryAsync().then(function (binaryBuffer) {
|
|
833
|
+
_this._extensionsOnExporting();
|
|
834
|
+
var jsonText = _this._generateJSON(false, glTFPrefix, true);
|
|
835
|
+
var bin = new Blob([binaryBuffer], { type: "application/octet-stream" });
|
|
836
|
+
var glTFFileName = glTFPrefix + ".gltf";
|
|
837
|
+
var glTFBinFile = glTFPrefix + ".bin";
|
|
838
|
+
var container = new GLTFData();
|
|
839
|
+
container.glTFFiles[glTFFileName] = jsonText;
|
|
840
|
+
container.glTFFiles[glTFBinFile] = bin;
|
|
841
|
+
if (_this._imageData) {
|
|
842
|
+
for (var image in _this._imageData) {
|
|
843
|
+
container.glTFFiles[image] = new Blob([_this._imageData[image].data], { type: _this._imageData[image].mimeType });
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (dispose) {
|
|
847
|
+
_this.dispose();
|
|
848
|
+
}
|
|
849
|
+
return container;
|
|
850
|
+
});
|
|
851
|
+
};
|
|
852
|
+
/**
|
|
853
|
+
* Creates a binary buffer for glTF
|
|
854
|
+
* @returns array buffer for binary data
|
|
855
|
+
*/
|
|
856
|
+
_Exporter.prototype._generateBinaryAsync = function () {
|
|
857
|
+
var _this = this;
|
|
858
|
+
var binaryWriter = new _BinaryWriter(4);
|
|
859
|
+
return this._createSceneAsync(this._babylonScene, binaryWriter).then(function () {
|
|
860
|
+
if (_this._localEngine) {
|
|
861
|
+
_this._localEngine.dispose();
|
|
862
|
+
}
|
|
863
|
+
return binaryWriter.getArrayBuffer();
|
|
864
|
+
});
|
|
865
|
+
};
|
|
866
|
+
/**
|
|
867
|
+
* Pads the number to a multiple of 4
|
|
868
|
+
* @param num number to pad
|
|
869
|
+
* @returns padded number
|
|
870
|
+
*/
|
|
871
|
+
_Exporter.prototype._getPadding = function (num) {
|
|
872
|
+
var remainder = num % 4;
|
|
873
|
+
var padding = remainder === 0 ? remainder : 4 - remainder;
|
|
874
|
+
return padding;
|
|
875
|
+
};
|
|
876
|
+
/**
|
|
877
|
+
* @param glTFPrefix
|
|
878
|
+
* @param dispose
|
|
879
|
+
* @hidden
|
|
880
|
+
*/
|
|
881
|
+
_Exporter.prototype._generateGLBAsync = function (glTFPrefix, dispose) {
|
|
882
|
+
var _this = this;
|
|
883
|
+
if (dispose === void 0) { dispose = true; }
|
|
884
|
+
return this._generateBinaryAsync().then(function (binaryBuffer) {
|
|
885
|
+
_this._extensionsOnExporting();
|
|
886
|
+
var jsonText = _this._generateJSON(true);
|
|
887
|
+
var glbFileName = glTFPrefix + ".glb";
|
|
888
|
+
var headerLength = 12;
|
|
889
|
+
var chunkLengthPrefix = 8;
|
|
890
|
+
var jsonLength = jsonText.length;
|
|
891
|
+
var encodedJsonText;
|
|
892
|
+
var imageByteLength = 0;
|
|
893
|
+
// make use of TextEncoder when available
|
|
894
|
+
if (typeof TextEncoder !== "undefined") {
|
|
895
|
+
var encoder = new TextEncoder();
|
|
896
|
+
encodedJsonText = encoder.encode(jsonText);
|
|
897
|
+
jsonLength = encodedJsonText.length;
|
|
898
|
+
}
|
|
899
|
+
for (var i = 0; i < _this._orderedImageData.length; ++i) {
|
|
900
|
+
imageByteLength += _this._orderedImageData[i].data.byteLength;
|
|
901
|
+
}
|
|
902
|
+
var jsonPadding = _this._getPadding(jsonLength);
|
|
903
|
+
var binPadding = _this._getPadding(binaryBuffer.byteLength);
|
|
904
|
+
var imagePadding = _this._getPadding(imageByteLength);
|
|
905
|
+
var byteLength = headerLength + 2 * chunkLengthPrefix + jsonLength + jsonPadding + binaryBuffer.byteLength + binPadding + imageByteLength + imagePadding;
|
|
906
|
+
//header
|
|
907
|
+
var headerBuffer = new ArrayBuffer(headerLength);
|
|
908
|
+
var headerBufferView = new DataView(headerBuffer);
|
|
909
|
+
headerBufferView.setUint32(0, 0x46546c67, true); //glTF
|
|
910
|
+
headerBufferView.setUint32(4, 2, true); // version
|
|
911
|
+
headerBufferView.setUint32(8, byteLength, true); // total bytes in file
|
|
912
|
+
//json chunk
|
|
913
|
+
var jsonChunkBuffer = new ArrayBuffer(chunkLengthPrefix + jsonLength + jsonPadding);
|
|
914
|
+
var jsonChunkBufferView = new DataView(jsonChunkBuffer);
|
|
915
|
+
jsonChunkBufferView.setUint32(0, jsonLength + jsonPadding, true);
|
|
916
|
+
jsonChunkBufferView.setUint32(4, 0x4e4f534a, true);
|
|
917
|
+
//json chunk bytes
|
|
918
|
+
var jsonData = new Uint8Array(jsonChunkBuffer, chunkLengthPrefix);
|
|
919
|
+
// if TextEncoder was available, we can simply copy the encoded array
|
|
920
|
+
if (encodedJsonText) {
|
|
921
|
+
jsonData.set(encodedJsonText);
|
|
922
|
+
}
|
|
923
|
+
else {
|
|
924
|
+
var blankCharCode = "_".charCodeAt(0);
|
|
925
|
+
for (var i = 0; i < jsonLength; ++i) {
|
|
926
|
+
var charCode = jsonText.charCodeAt(i);
|
|
927
|
+
// if the character doesn't fit into a single UTF-16 code unit, just put a blank character
|
|
928
|
+
if (charCode != jsonText.codePointAt(i)) {
|
|
929
|
+
jsonData[i] = blankCharCode;
|
|
930
|
+
}
|
|
931
|
+
else {
|
|
932
|
+
jsonData[i] = charCode;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
//json padding
|
|
937
|
+
var jsonPaddingView = new Uint8Array(jsonChunkBuffer, chunkLengthPrefix + jsonLength);
|
|
938
|
+
for (var i = 0; i < jsonPadding; ++i) {
|
|
939
|
+
jsonPaddingView[i] = 0x20;
|
|
940
|
+
}
|
|
941
|
+
//binary chunk
|
|
942
|
+
var binaryChunkBuffer = new ArrayBuffer(chunkLengthPrefix);
|
|
943
|
+
var binaryChunkBufferView = new DataView(binaryChunkBuffer);
|
|
944
|
+
binaryChunkBufferView.setUint32(0, binaryBuffer.byteLength + imageByteLength + imagePadding, true);
|
|
945
|
+
binaryChunkBufferView.setUint32(4, 0x004e4942, true);
|
|
946
|
+
// binary padding
|
|
947
|
+
var binPaddingBuffer = new ArrayBuffer(binPadding);
|
|
948
|
+
var binPaddingView = new Uint8Array(binPaddingBuffer);
|
|
949
|
+
for (var i = 0; i < binPadding; ++i) {
|
|
950
|
+
binPaddingView[i] = 0;
|
|
951
|
+
}
|
|
952
|
+
var imagePaddingBuffer = new ArrayBuffer(imagePadding);
|
|
953
|
+
var imagePaddingView = new Uint8Array(imagePaddingBuffer);
|
|
954
|
+
for (var i = 0; i < imagePadding; ++i) {
|
|
955
|
+
imagePaddingView[i] = 0;
|
|
956
|
+
}
|
|
957
|
+
var glbData = [headerBuffer, jsonChunkBuffer, binaryChunkBuffer, binaryBuffer];
|
|
958
|
+
// binary data
|
|
959
|
+
for (var i = 0; i < _this._orderedImageData.length; ++i) {
|
|
960
|
+
glbData.push(_this._orderedImageData[i].data.buffer);
|
|
961
|
+
}
|
|
962
|
+
glbData.push(binPaddingBuffer);
|
|
963
|
+
glbData.push(imagePaddingBuffer);
|
|
964
|
+
var glbFile = new Blob(glbData, { type: "application/octet-stream" });
|
|
965
|
+
var container = new GLTFData();
|
|
966
|
+
container.glTFFiles[glbFileName] = glbFile;
|
|
967
|
+
if (_this._localEngine != null) {
|
|
968
|
+
_this._localEngine.dispose();
|
|
969
|
+
}
|
|
970
|
+
if (dispose) {
|
|
971
|
+
_this.dispose();
|
|
972
|
+
}
|
|
973
|
+
return container;
|
|
974
|
+
});
|
|
975
|
+
};
|
|
976
|
+
/**
|
|
977
|
+
* Sets the TRS for each node
|
|
978
|
+
* @param node glTF Node for storing the transformation data
|
|
979
|
+
* @param babylonTransformNode Babylon mesh used as the source for the transformation data
|
|
980
|
+
* @param convertToRightHandedSystem Converts the values to right-handed
|
|
981
|
+
*/
|
|
982
|
+
_Exporter.prototype._setNodeTransformation = function (node, babylonTransformNode, convertToRightHandedSystem) {
|
|
983
|
+
if (!babylonTransformNode.getPivotPoint().equalsToFloats(0, 0, 0)) {
|
|
984
|
+
Tools.Warn("Pivot points are not supported in the glTF serializer");
|
|
985
|
+
}
|
|
986
|
+
if (!babylonTransformNode.position.equalsToFloats(0, 0, 0)) {
|
|
987
|
+
node.translation = convertToRightHandedSystem
|
|
988
|
+
? _GLTFUtilities._GetRightHandedPositionVector3(babylonTransformNode.position).asArray()
|
|
989
|
+
: babylonTransformNode.position.asArray();
|
|
990
|
+
}
|
|
991
|
+
if (!babylonTransformNode.scaling.equalsToFloats(1, 1, 1)) {
|
|
992
|
+
node.scale = babylonTransformNode.scaling.asArray();
|
|
993
|
+
}
|
|
994
|
+
var rotationQuaternion = Quaternion.RotationYawPitchRoll(babylonTransformNode.rotation.y, babylonTransformNode.rotation.x, babylonTransformNode.rotation.z);
|
|
995
|
+
if (babylonTransformNode.rotationQuaternion) {
|
|
996
|
+
rotationQuaternion.multiplyInPlace(babylonTransformNode.rotationQuaternion);
|
|
997
|
+
}
|
|
998
|
+
if (!Quaternion.IsIdentity(rotationQuaternion)) {
|
|
999
|
+
if (convertToRightHandedSystem) {
|
|
1000
|
+
_GLTFUtilities._GetRightHandedQuaternionFromRef(rotationQuaternion);
|
|
1001
|
+
}
|
|
1002
|
+
node.rotation = rotationQuaternion.normalize().asArray();
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
_Exporter.prototype._setCameraTransformation = function (node, babylonCamera, convertToRightHandedSystem) {
|
|
1006
|
+
if (!babylonCamera.position.equalsToFloats(0, 0, 0)) {
|
|
1007
|
+
node.translation = convertToRightHandedSystem ? _GLTFUtilities._GetRightHandedPositionVector3(babylonCamera.position).asArray() : babylonCamera.position.asArray();
|
|
1008
|
+
}
|
|
1009
|
+
var rotationQuaternion = babylonCamera.absoluteRotation;
|
|
1010
|
+
if (!Quaternion.IsIdentity(rotationQuaternion)) {
|
|
1011
|
+
if (convertToRightHandedSystem) {
|
|
1012
|
+
_GLTFUtilities._GetRightHandedQuaternionFromRef(rotationQuaternion);
|
|
1013
|
+
}
|
|
1014
|
+
node.rotation = rotationQuaternion.normalize().asArray();
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
_Exporter.prototype._getVertexBufferFromMesh = function (attributeKind, bufferMesh) {
|
|
1018
|
+
if (bufferMesh.isVerticesDataPresent(attributeKind)) {
|
|
1019
|
+
var vertexBuffer = bufferMesh.getVertexBuffer(attributeKind);
|
|
1020
|
+
if (vertexBuffer) {
|
|
1021
|
+
return vertexBuffer;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
return null;
|
|
1025
|
+
};
|
|
1026
|
+
/**
|
|
1027
|
+
* Creates a bufferview based on the vertices type for the Babylon mesh
|
|
1028
|
+
* @param kind Indicates the type of vertices data
|
|
1029
|
+
* @param attributeComponentKind Indicates the numerical type used to store the data
|
|
1030
|
+
* @param babylonTransformNode The Babylon mesh to get the vertices data from
|
|
1031
|
+
* @param binaryWriter The buffer to write the bufferview data to
|
|
1032
|
+
* @param byteStride
|
|
1033
|
+
* @param convertToRightHandedSystem Converts the values to right-handed
|
|
1034
|
+
*/
|
|
1035
|
+
_Exporter.prototype._createBufferViewKind = function (kind, attributeComponentKind, babylonTransformNode, binaryWriter, byteStride, convertToRightHandedSystem) {
|
|
1036
|
+
var bufferMesh = babylonTransformNode instanceof Mesh
|
|
1037
|
+
? babylonTransformNode
|
|
1038
|
+
: babylonTransformNode instanceof InstancedMesh
|
|
1039
|
+
? babylonTransformNode.sourceMesh
|
|
1040
|
+
: null;
|
|
1041
|
+
if (bufferMesh) {
|
|
1042
|
+
var vertexBuffer = bufferMesh.getVertexBuffer(kind);
|
|
1043
|
+
var vertexData = bufferMesh.getVerticesData(kind);
|
|
1044
|
+
if (vertexBuffer && vertexData) {
|
|
1045
|
+
var typeByteLength = VertexBuffer.GetTypeByteLength(attributeComponentKind);
|
|
1046
|
+
var byteLength = vertexData.length * typeByteLength;
|
|
1047
|
+
var bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, kind + " - " + bufferMesh.name);
|
|
1048
|
+
this._bufferViews.push(bufferView);
|
|
1049
|
+
this._writeAttributeData(kind, attributeComponentKind, vertexData, byteStride / typeByteLength, binaryWriter, convertToRightHandedSystem, babylonTransformNode);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
/**
|
|
1054
|
+
* Creates a bufferview based on the vertices type for the Babylon mesh
|
|
1055
|
+
* @param babylonSubMesh The Babylon submesh that the morph target is applied to
|
|
1056
|
+
* @param meshPrimitive
|
|
1057
|
+
* @param babylonMorphTarget the morph target to be exported
|
|
1058
|
+
* @param binaryWriter The buffer to write the bufferview data to
|
|
1059
|
+
* @param convertToRightHandedSystem Converts the values to right-handed
|
|
1060
|
+
*/
|
|
1061
|
+
_Exporter.prototype._setMorphTargetAttributes = function (babylonSubMesh, meshPrimitive, babylonMorphTarget, binaryWriter, convertToRightHandedSystem) {
|
|
1062
|
+
if (babylonMorphTarget) {
|
|
1063
|
+
if (!meshPrimitive.targets) {
|
|
1064
|
+
meshPrimitive.targets = [];
|
|
1065
|
+
}
|
|
1066
|
+
var target = {};
|
|
1067
|
+
if (babylonMorphTarget.hasNormals) {
|
|
1068
|
+
var vertexNormals = babylonSubMesh.getMesh().getVerticesData(VertexBuffer.NormalKind);
|
|
1069
|
+
var morphNormals = babylonMorphTarget.getNormals();
|
|
1070
|
+
var count = babylonSubMesh.verticesCount;
|
|
1071
|
+
var byteStride = 12; // 3 x 4 byte floats
|
|
1072
|
+
var byteLength = count * byteStride;
|
|
1073
|
+
var bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, babylonMorphTarget.name + "_NORMAL");
|
|
1074
|
+
this._bufferViews.push(bufferView);
|
|
1075
|
+
var bufferViewIndex = this._bufferViews.length - 1;
|
|
1076
|
+
var accessor = _GLTFUtilities._CreateAccessor(bufferViewIndex, babylonMorphTarget.name + " - " + "NORMAL", "VEC3" /* VEC3 */, 5126 /* FLOAT */, count, 0, null, null);
|
|
1077
|
+
this._accessors.push(accessor);
|
|
1078
|
+
target.NORMAL = this._accessors.length - 1;
|
|
1079
|
+
this.writeMorphTargetAttributeData(VertexBuffer.NormalKind, 5126 /* FLOAT */, babylonSubMesh, babylonMorphTarget, vertexNormals, morphNormals, byteStride / 4, binaryWriter, convertToRightHandedSystem);
|
|
1080
|
+
}
|
|
1081
|
+
if (babylonMorphTarget.hasPositions) {
|
|
1082
|
+
var vertexPositions = babylonSubMesh.getMesh().getVerticesData(VertexBuffer.PositionKind);
|
|
1083
|
+
var morphPositions = babylonMorphTarget.getPositions();
|
|
1084
|
+
var count = babylonSubMesh.verticesCount;
|
|
1085
|
+
var byteStride = 12; // 3 x 4 byte floats
|
|
1086
|
+
var byteLength = count * byteStride;
|
|
1087
|
+
var bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, babylonMorphTarget.name + "_POSITION");
|
|
1088
|
+
this._bufferViews.push(bufferView);
|
|
1089
|
+
var bufferViewIndex = this._bufferViews.length - 1;
|
|
1090
|
+
var minMax = { min: new Vector3(Infinity, Infinity, Infinity), max: new Vector3(-Infinity, -Infinity, -Infinity) };
|
|
1091
|
+
var accessor = _GLTFUtilities._CreateAccessor(bufferViewIndex, babylonMorphTarget.name + " - " + "POSITION", "VEC3" /* VEC3 */, 5126 /* FLOAT */, count, 0, null, null);
|
|
1092
|
+
this._accessors.push(accessor);
|
|
1093
|
+
target.POSITION = this._accessors.length - 1;
|
|
1094
|
+
this.writeMorphTargetAttributeData(VertexBuffer.PositionKind, 5126 /* FLOAT */, babylonSubMesh, babylonMorphTarget, vertexPositions, morphPositions, byteStride / 4, binaryWriter, convertToRightHandedSystem, minMax);
|
|
1095
|
+
accessor.min = minMax.min.asArray();
|
|
1096
|
+
accessor.max = minMax.max.asArray();
|
|
1097
|
+
}
|
|
1098
|
+
if (babylonMorphTarget.hasTangents) {
|
|
1099
|
+
var vertexTangents = babylonSubMesh.getMesh().getVerticesData(VertexBuffer.TangentKind);
|
|
1100
|
+
var morphTangents = babylonMorphTarget.getTangents();
|
|
1101
|
+
var count = babylonSubMesh.verticesCount;
|
|
1102
|
+
var byteStride = 12; // 3 x 4 byte floats
|
|
1103
|
+
var byteLength = count * byteStride;
|
|
1104
|
+
var bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, babylonMorphTarget.name + "_NORMAL");
|
|
1105
|
+
this._bufferViews.push(bufferView);
|
|
1106
|
+
var bufferViewIndex = this._bufferViews.length - 1;
|
|
1107
|
+
var accessor = _GLTFUtilities._CreateAccessor(bufferViewIndex, babylonMorphTarget.name + " - " + "TANGENT", "VEC3" /* VEC3 */, 5126 /* FLOAT */, count, 0, null, null);
|
|
1108
|
+
this._accessors.push(accessor);
|
|
1109
|
+
target.TANGENT = this._accessors.length - 1;
|
|
1110
|
+
this.writeMorphTargetAttributeData(VertexBuffer.TangentKind, 5126 /* FLOAT */, babylonSubMesh, babylonMorphTarget, vertexTangents, morphTangents, byteStride / 4, binaryWriter, convertToRightHandedSystem);
|
|
1111
|
+
}
|
|
1112
|
+
meshPrimitive.targets.push(target);
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
/**
|
|
1116
|
+
* The primitive mode of the Babylon mesh
|
|
1117
|
+
* @param babylonMesh The BabylonJS mesh
|
|
1118
|
+
*/
|
|
1119
|
+
_Exporter.prototype._getMeshPrimitiveMode = function (babylonMesh) {
|
|
1120
|
+
if (babylonMesh instanceof LinesMesh) {
|
|
1121
|
+
return Material.LineListDrawMode;
|
|
1122
|
+
}
|
|
1123
|
+
return babylonMesh.material ? babylonMesh.material.fillMode : Material.TriangleFillMode;
|
|
1124
|
+
};
|
|
1125
|
+
/**
|
|
1126
|
+
* Sets the primitive mode of the glTF mesh primitive
|
|
1127
|
+
* @param meshPrimitive glTF mesh primitive
|
|
1128
|
+
* @param primitiveMode The primitive mode
|
|
1129
|
+
*/
|
|
1130
|
+
_Exporter.prototype._setPrimitiveMode = function (meshPrimitive, primitiveMode) {
|
|
1131
|
+
switch (primitiveMode) {
|
|
1132
|
+
case Material.TriangleFillMode: {
|
|
1133
|
+
// glTF defaults to using Triangle Mode
|
|
1134
|
+
break;
|
|
1135
|
+
}
|
|
1136
|
+
case Material.TriangleStripDrawMode: {
|
|
1137
|
+
meshPrimitive.mode = 5 /* TRIANGLE_STRIP */;
|
|
1138
|
+
break;
|
|
1139
|
+
}
|
|
1140
|
+
case Material.TriangleFanDrawMode: {
|
|
1141
|
+
meshPrimitive.mode = 6 /* TRIANGLE_FAN */;
|
|
1142
|
+
break;
|
|
1143
|
+
}
|
|
1144
|
+
case Material.PointListDrawMode: {
|
|
1145
|
+
meshPrimitive.mode = 0 /* POINTS */;
|
|
1146
|
+
break;
|
|
1147
|
+
}
|
|
1148
|
+
case Material.PointFillMode: {
|
|
1149
|
+
meshPrimitive.mode = 0 /* POINTS */;
|
|
1150
|
+
break;
|
|
1151
|
+
}
|
|
1152
|
+
case Material.LineLoopDrawMode: {
|
|
1153
|
+
meshPrimitive.mode = 2 /* LINE_LOOP */;
|
|
1154
|
+
break;
|
|
1155
|
+
}
|
|
1156
|
+
case Material.LineListDrawMode: {
|
|
1157
|
+
meshPrimitive.mode = 1 /* LINES */;
|
|
1158
|
+
break;
|
|
1159
|
+
}
|
|
1160
|
+
case Material.LineStripDrawMode: {
|
|
1161
|
+
meshPrimitive.mode = 3 /* LINE_STRIP */;
|
|
1162
|
+
break;
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
/**
|
|
1167
|
+
* Sets the vertex attribute accessor based of the glTF mesh primitive
|
|
1168
|
+
* @param meshPrimitive glTF mesh primitive
|
|
1169
|
+
* @param attributeKind vertex attribute
|
|
1170
|
+
* @returns boolean specifying if uv coordinates are present
|
|
1171
|
+
*/
|
|
1172
|
+
_Exporter.prototype._setAttributeKind = function (meshPrimitive, attributeKind) {
|
|
1173
|
+
switch (attributeKind) {
|
|
1174
|
+
case VertexBuffer.PositionKind: {
|
|
1175
|
+
meshPrimitive.attributes.POSITION = this._accessors.length - 1;
|
|
1176
|
+
break;
|
|
1177
|
+
}
|
|
1178
|
+
case VertexBuffer.NormalKind: {
|
|
1179
|
+
meshPrimitive.attributes.NORMAL = this._accessors.length - 1;
|
|
1180
|
+
break;
|
|
1181
|
+
}
|
|
1182
|
+
case VertexBuffer.ColorKind: {
|
|
1183
|
+
meshPrimitive.attributes.COLOR_0 = this._accessors.length - 1;
|
|
1184
|
+
break;
|
|
1185
|
+
}
|
|
1186
|
+
case VertexBuffer.TangentKind: {
|
|
1187
|
+
meshPrimitive.attributes.TANGENT = this._accessors.length - 1;
|
|
1188
|
+
break;
|
|
1189
|
+
}
|
|
1190
|
+
case VertexBuffer.UVKind: {
|
|
1191
|
+
meshPrimitive.attributes.TEXCOORD_0 = this._accessors.length - 1;
|
|
1192
|
+
break;
|
|
1193
|
+
}
|
|
1194
|
+
case VertexBuffer.UV2Kind: {
|
|
1195
|
+
meshPrimitive.attributes.TEXCOORD_1 = this._accessors.length - 1;
|
|
1196
|
+
break;
|
|
1197
|
+
}
|
|
1198
|
+
case VertexBuffer.MatricesIndicesKind: {
|
|
1199
|
+
meshPrimitive.attributes.JOINTS_0 = this._accessors.length - 1;
|
|
1200
|
+
break;
|
|
1201
|
+
}
|
|
1202
|
+
case VertexBuffer.MatricesIndicesExtraKind: {
|
|
1203
|
+
meshPrimitive.attributes.JOINTS_1 = this._accessors.length - 1;
|
|
1204
|
+
break;
|
|
1205
|
+
}
|
|
1206
|
+
case VertexBuffer.MatricesWeightsKind: {
|
|
1207
|
+
meshPrimitive.attributes.WEIGHTS_0 = this._accessors.length - 1;
|
|
1208
|
+
break;
|
|
1209
|
+
}
|
|
1210
|
+
case VertexBuffer.MatricesWeightsExtraKind: {
|
|
1211
|
+
meshPrimitive.attributes.WEIGHTS_1 = this._accessors.length - 1;
|
|
1212
|
+
break;
|
|
1213
|
+
}
|
|
1214
|
+
default: {
|
|
1215
|
+
Tools.Warn("Unsupported Vertex Buffer Type: " + attributeKind);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
/**
|
|
1220
|
+
* Sets data for the primitive attributes of each submesh
|
|
1221
|
+
* @param mesh glTF Mesh object to store the primitive attribute information
|
|
1222
|
+
* @param babylonTransformNode Babylon mesh to get the primitive attribute data from
|
|
1223
|
+
* @param binaryWriter Buffer to write the attribute data to
|
|
1224
|
+
* @param convertToRightHandedSystem Converts the values to right-handed
|
|
1225
|
+
*/
|
|
1226
|
+
_Exporter.prototype._setPrimitiveAttributesAsync = function (mesh, babylonTransformNode, binaryWriter, convertToRightHandedSystem) {
|
|
1227
|
+
var _a;
|
|
1228
|
+
var promises = [];
|
|
1229
|
+
var bufferMesh = null;
|
|
1230
|
+
var bufferView;
|
|
1231
|
+
var minMax;
|
|
1232
|
+
if (babylonTransformNode instanceof Mesh) {
|
|
1233
|
+
bufferMesh = babylonTransformNode;
|
|
1234
|
+
}
|
|
1235
|
+
else if (babylonTransformNode instanceof InstancedMesh) {
|
|
1236
|
+
bufferMesh = babylonTransformNode.sourceMesh;
|
|
1237
|
+
}
|
|
1238
|
+
var attributeData = [
|
|
1239
|
+
{ kind: VertexBuffer.PositionKind, accessorType: "VEC3" /* VEC3 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 12 },
|
|
1240
|
+
{ kind: VertexBuffer.NormalKind, accessorType: "VEC3" /* VEC3 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 12 },
|
|
1241
|
+
{ kind: VertexBuffer.ColorKind, accessorType: "VEC4" /* VEC4 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 16 },
|
|
1242
|
+
{ kind: VertexBuffer.TangentKind, accessorType: "VEC4" /* VEC4 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 16 },
|
|
1243
|
+
{ kind: VertexBuffer.UVKind, accessorType: "VEC2" /* VEC2 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 8 },
|
|
1244
|
+
{ kind: VertexBuffer.UV2Kind, accessorType: "VEC2" /* VEC2 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 8 },
|
|
1245
|
+
{ kind: VertexBuffer.MatricesIndicesKind, accessorType: "VEC4" /* VEC4 */, accessorComponentType: 5123 /* UNSIGNED_SHORT */, byteStride: 8 },
|
|
1246
|
+
{ kind: VertexBuffer.MatricesIndicesExtraKind, accessorType: "VEC4" /* VEC4 */, accessorComponentType: 5123 /* UNSIGNED_SHORT */, byteStride: 8 },
|
|
1247
|
+
{ kind: VertexBuffer.MatricesWeightsKind, accessorType: "VEC4" /* VEC4 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 16 },
|
|
1248
|
+
{ kind: VertexBuffer.MatricesWeightsExtraKind, accessorType: "VEC4" /* VEC4 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 16 },
|
|
1249
|
+
];
|
|
1250
|
+
if (bufferMesh) {
|
|
1251
|
+
var indexBufferViewIndex = null;
|
|
1252
|
+
var primitiveMode = this._getMeshPrimitiveMode(bufferMesh);
|
|
1253
|
+
var vertexAttributeBufferViews = {};
|
|
1254
|
+
var morphTargetManager = bufferMesh.morphTargetManager;
|
|
1255
|
+
// For each BabylonMesh, create bufferviews for each 'kind'
|
|
1256
|
+
for (var _i = 0, attributeData_1 = attributeData; _i < attributeData_1.length; _i++) {
|
|
1257
|
+
var attribute = attributeData_1[_i];
|
|
1258
|
+
var attributeKind = attribute.kind;
|
|
1259
|
+
var attributeComponentKind = attribute.accessorComponentType;
|
|
1260
|
+
if (bufferMesh.isVerticesDataPresent(attributeKind)) {
|
|
1261
|
+
var vertexBuffer = this._getVertexBufferFromMesh(attributeKind, bufferMesh);
|
|
1262
|
+
attribute.byteStride = vertexBuffer
|
|
1263
|
+
? vertexBuffer.getSize() * VertexBuffer.GetTypeByteLength(attribute.accessorComponentType)
|
|
1264
|
+
: VertexBuffer.DeduceStride(attributeKind) * 4;
|
|
1265
|
+
if (attribute.byteStride === 12) {
|
|
1266
|
+
attribute.accessorType = "VEC3" /* VEC3 */;
|
|
1267
|
+
}
|
|
1268
|
+
this._createBufferViewKind(attributeKind, attributeComponentKind, babylonTransformNode, binaryWriter, attribute.byteStride, convertToRightHandedSystem);
|
|
1269
|
+
attribute.bufferViewIndex = this._bufferViews.length - 1;
|
|
1270
|
+
vertexAttributeBufferViews[attributeKind] = attribute.bufferViewIndex;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
if (bufferMesh.getTotalIndices()) {
|
|
1274
|
+
var indices = bufferMesh.getIndices();
|
|
1275
|
+
if (indices) {
|
|
1276
|
+
var byteLength = indices.length * 4;
|
|
1277
|
+
bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, "Indices - " + bufferMesh.name);
|
|
1278
|
+
this._bufferViews.push(bufferView);
|
|
1279
|
+
indexBufferViewIndex = this._bufferViews.length - 1;
|
|
1280
|
+
for (var k = 0, length_9 = indices.length; k < length_9; ++k) {
|
|
1281
|
+
binaryWriter.setUInt32(indices[k]);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
if (bufferMesh.subMeshes) {
|
|
1286
|
+
// go through all mesh primitives (submeshes)
|
|
1287
|
+
for (var _b = 0, _c = bufferMesh.subMeshes; _b < _c.length; _b++) {
|
|
1288
|
+
var submesh = _c[_b];
|
|
1289
|
+
var babylonMaterial = submesh.getMaterial() || bufferMesh.getScene().defaultMaterial;
|
|
1290
|
+
var materialIndex = null;
|
|
1291
|
+
if (babylonMaterial) {
|
|
1292
|
+
if (bufferMesh instanceof LinesMesh) {
|
|
1293
|
+
// get the color from the lines mesh and set it in the material
|
|
1294
|
+
var material = {
|
|
1295
|
+
name: bufferMesh.name + " material",
|
|
1296
|
+
};
|
|
1297
|
+
if (!bufferMesh.color.equals(Color3.White()) || bufferMesh.alpha < 1) {
|
|
1298
|
+
material.pbrMetallicRoughness = {
|
|
1299
|
+
baseColorFactor: bufferMesh.color.asArray().concat([bufferMesh.alpha]),
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
this._materials.push(material);
|
|
1303
|
+
materialIndex = this._materials.length - 1;
|
|
1304
|
+
}
|
|
1305
|
+
else if (babylonMaterial instanceof MultiMaterial) {
|
|
1306
|
+
var subMaterial = babylonMaterial.subMaterials[submesh.materialIndex];
|
|
1307
|
+
if (subMaterial) {
|
|
1308
|
+
babylonMaterial = subMaterial;
|
|
1309
|
+
materialIndex = this._materialMap[babylonMaterial.uniqueId];
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
else {
|
|
1313
|
+
materialIndex = this._materialMap[babylonMaterial.uniqueId];
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
var glTFMaterial = materialIndex != null ? this._materials[materialIndex] : null;
|
|
1317
|
+
var meshPrimitive = { attributes: {} };
|
|
1318
|
+
this._setPrimitiveMode(meshPrimitive, primitiveMode);
|
|
1319
|
+
for (var _d = 0, attributeData_2 = attributeData; _d < attributeData_2.length; _d++) {
|
|
1320
|
+
var attribute = attributeData_2[_d];
|
|
1321
|
+
var attributeKind = attribute.kind;
|
|
1322
|
+
if ((attributeKind === VertexBuffer.UVKind || attributeKind === VertexBuffer.UV2Kind) && !this._options.exportUnusedUVs) {
|
|
1323
|
+
if (!glTFMaterial || !this._glTFMaterialExporter._hasTexturesPresent(glTFMaterial)) {
|
|
1324
|
+
continue;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
var vertexData = bufferMesh.getVerticesData(attributeKind);
|
|
1328
|
+
if (vertexData) {
|
|
1329
|
+
var vertexBuffer = this._getVertexBufferFromMesh(attributeKind, bufferMesh);
|
|
1330
|
+
if (vertexBuffer) {
|
|
1331
|
+
var stride = vertexBuffer.getSize();
|
|
1332
|
+
var bufferViewIndex = attribute.bufferViewIndex;
|
|
1333
|
+
if (bufferViewIndex != undefined) {
|
|
1334
|
+
// check to see if bufferviewindex has a numeric value assigned.
|
|
1335
|
+
minMax = { min: null, max: null };
|
|
1336
|
+
if (attributeKind == VertexBuffer.PositionKind) {
|
|
1337
|
+
minMax = _GLTFUtilities._CalculateMinMaxPositions(vertexData, 0, vertexData.length / stride, convertToRightHandedSystem);
|
|
1338
|
+
}
|
|
1339
|
+
var accessor = _GLTFUtilities._CreateAccessor(bufferViewIndex, attributeKind + " - " + babylonTransformNode.name, attribute.accessorType, attribute.accessorComponentType, vertexData.length / stride, 0, minMax.min, minMax.max);
|
|
1340
|
+
this._accessors.push(accessor);
|
|
1341
|
+
this._setAttributeKind(meshPrimitive, attributeKind);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
if (indexBufferViewIndex) {
|
|
1347
|
+
// Create accessor
|
|
1348
|
+
var accessor = _GLTFUtilities._CreateAccessor(indexBufferViewIndex, "indices - " + babylonTransformNode.name, "SCALAR" /* SCALAR */, 5125 /* UNSIGNED_INT */, submesh.indexCount, submesh.indexStart * 4, null, null);
|
|
1349
|
+
this._accessors.push(accessor);
|
|
1350
|
+
meshPrimitive.indices = this._accessors.length - 1;
|
|
1351
|
+
}
|
|
1352
|
+
if (materialIndex != null && Object.keys(meshPrimitive.attributes).length > 0) {
|
|
1353
|
+
var sideOrientation = bufferMesh.overrideMaterialSideOrientation !== null ? bufferMesh.overrideMaterialSideOrientation : babylonMaterial.sideOrientation;
|
|
1354
|
+
if ((sideOrientation == Material.ClockWiseSideOrientation && this._babylonScene.useRightHandedSystem) ||
|
|
1355
|
+
(sideOrientation == Material.ClockWiseSideOrientation &&
|
|
1356
|
+
convertToRightHandedSystem &&
|
|
1357
|
+
bufferMesh.overrideMaterialSideOrientation !== ((_a = bufferMesh.material) === null || _a === void 0 ? void 0 : _a.sideOrientation))) {
|
|
1358
|
+
var byteOffset = indexBufferViewIndex != null ? this._bufferViews[indexBufferViewIndex].byteOffset : null;
|
|
1359
|
+
if (byteOffset == null) {
|
|
1360
|
+
byteOffset = 0;
|
|
1361
|
+
}
|
|
1362
|
+
var babylonIndices = null;
|
|
1363
|
+
if (indexBufferViewIndex != null) {
|
|
1364
|
+
babylonIndices = bufferMesh.getIndices();
|
|
1365
|
+
}
|
|
1366
|
+
if (babylonIndices) {
|
|
1367
|
+
this._reorderIndicesBasedOnPrimitiveMode(submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter);
|
|
1368
|
+
}
|
|
1369
|
+
else {
|
|
1370
|
+
for (var _e = 0, attributeData_3 = attributeData; _e < attributeData_3.length; _e++) {
|
|
1371
|
+
var attribute = attributeData_3[_e];
|
|
1372
|
+
var vertexData = bufferMesh.getVerticesData(attribute.kind);
|
|
1373
|
+
if (vertexData) {
|
|
1374
|
+
var byteOffset_1 = this._bufferViews[vertexAttributeBufferViews[attribute.kind]].byteOffset;
|
|
1375
|
+
if (!byteOffset_1) {
|
|
1376
|
+
byteOffset_1 = 0;
|
|
1377
|
+
}
|
|
1378
|
+
this._reorderVertexAttributeDataBasedOnPrimitiveMode(submesh, primitiveMode, sideOrientation, attribute.kind, vertexData, byteOffset_1, binaryWriter, convertToRightHandedSystem);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
meshPrimitive.material = materialIndex;
|
|
1384
|
+
}
|
|
1385
|
+
if (morphTargetManager) {
|
|
1386
|
+
var target = void 0;
|
|
1387
|
+
for (var i = 0; i < morphTargetManager.numTargets; ++i) {
|
|
1388
|
+
target = morphTargetManager.getTarget(i);
|
|
1389
|
+
this._setMorphTargetAttributes(submesh, meshPrimitive, target, binaryWriter, convertToRightHandedSystem);
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
mesh.primitives.push(meshPrimitive);
|
|
1393
|
+
this._extensionsPostExportMeshPrimitiveAsync("postExport", meshPrimitive, submesh, binaryWriter);
|
|
1394
|
+
promises.push();
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
return Promise.all(promises).then(function () {
|
|
1399
|
+
/* do nothing */
|
|
1400
|
+
});
|
|
1401
|
+
};
|
|
1402
|
+
/**
|
|
1403
|
+
* Check if the node is used to convert its descendants from a right handed coordinate system to the Babylon scene's coordinate system.
|
|
1404
|
+
* @param node The node to check
|
|
1405
|
+
* @returns True if the node is used to convert its descendants from right-handed to left-handed. False otherwise
|
|
1406
|
+
*/
|
|
1407
|
+
_Exporter.prototype._isBabylonCoordinateSystemConvertingNode = function (node) {
|
|
1408
|
+
if (node instanceof TransformNode) {
|
|
1409
|
+
if (node.name !== "__root__") {
|
|
1410
|
+
return false;
|
|
1411
|
+
}
|
|
1412
|
+
// Transform
|
|
1413
|
+
var matrix = node.getWorldMatrix();
|
|
1414
|
+
if (matrix.determinant() === 1) {
|
|
1415
|
+
return false;
|
|
1416
|
+
}
|
|
1417
|
+
// Geometry
|
|
1418
|
+
if ((node instanceof Mesh && node.geometry !== null) || (node instanceof InstancedMesh && node.sourceMesh.geometry !== null)) {
|
|
1419
|
+
return false;
|
|
1420
|
+
}
|
|
1421
|
+
if (this._includeCoordinateSystemConversionNodes) {
|
|
1422
|
+
return false;
|
|
1423
|
+
}
|
|
1424
|
+
return true;
|
|
1425
|
+
}
|
|
1426
|
+
return false;
|
|
1427
|
+
};
|
|
1428
|
+
/**
|
|
1429
|
+
* Creates a glTF scene based on the array of meshes
|
|
1430
|
+
* Returns the the total byte offset
|
|
1431
|
+
* @param babylonScene Babylon scene to get the mesh data from
|
|
1432
|
+
* @param binaryWriter Buffer to write binary data to
|
|
1433
|
+
*/
|
|
1434
|
+
_Exporter.prototype._createSceneAsync = function (babylonScene, binaryWriter) {
|
|
1435
|
+
var _this = this;
|
|
1436
|
+
var scene = { nodes: [] };
|
|
1437
|
+
var glTFNodeIndex;
|
|
1438
|
+
var glTFNode;
|
|
1439
|
+
var directDescendents;
|
|
1440
|
+
var nodes = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], babylonScene.transformNodes, true), babylonScene.meshes, true), babylonScene.lights, true), babylonScene.cameras, true);
|
|
1441
|
+
var rootNodesToLeftHanded = [];
|
|
1442
|
+
this._convertToRightHandedSystem = !babylonScene.useRightHandedSystem;
|
|
1443
|
+
this._convertToRightHandedSystemMap = {};
|
|
1444
|
+
// Set default values for all nodes
|
|
1445
|
+
babylonScene.rootNodes.forEach(function (rootNode) {
|
|
1446
|
+
_this._convertToRightHandedSystemMap[rootNode.uniqueId] = _this._convertToRightHandedSystem;
|
|
1447
|
+
rootNode.getDescendants(false).forEach(function (descendant) {
|
|
1448
|
+
_this._convertToRightHandedSystemMap[descendant.uniqueId] = _this._convertToRightHandedSystem;
|
|
1449
|
+
});
|
|
1450
|
+
});
|
|
1451
|
+
// Check if root nodes converting to left-handed are present
|
|
1452
|
+
babylonScene.rootNodes.forEach(function (rootNode) {
|
|
1453
|
+
if (_this._isBabylonCoordinateSystemConvertingNode(rootNode)) {
|
|
1454
|
+
rootNodesToLeftHanded.push(rootNode);
|
|
1455
|
+
// Exclude the node from list of nodes to export
|
|
1456
|
+
var indexRootNode = nodes.indexOf(rootNode);
|
|
1457
|
+
if (indexRootNode !== -1) {
|
|
1458
|
+
// should always be true
|
|
1459
|
+
nodes.splice(indexRootNode, 1);
|
|
1460
|
+
}
|
|
1461
|
+
// Cancel conversion to right handed system
|
|
1462
|
+
rootNode.getDescendants(false).forEach(function (descendant) {
|
|
1463
|
+
_this._convertToRightHandedSystemMap[descendant.uniqueId] = false;
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
});
|
|
1467
|
+
// Export babylon cameras to glTFCamera
|
|
1468
|
+
var cameraMap = new Map();
|
|
1469
|
+
babylonScene.cameras.forEach(function (camera) {
|
|
1470
|
+
if (!_this._options.shouldExportNode || _this._options.shouldExportNode(camera)) {
|
|
1471
|
+
var glTFCamera = {
|
|
1472
|
+
type: camera.mode === Camera.PERSPECTIVE_CAMERA ? "perspective" /* PERSPECTIVE */ : "orthographic" /* ORTHOGRAPHIC */,
|
|
1473
|
+
};
|
|
1474
|
+
if (camera.name) {
|
|
1475
|
+
glTFCamera.name = camera.name;
|
|
1476
|
+
}
|
|
1477
|
+
if (glTFCamera.type === "perspective" /* PERSPECTIVE */) {
|
|
1478
|
+
glTFCamera.perspective = {
|
|
1479
|
+
aspectRatio: camera.getEngine().getAspectRatio(camera),
|
|
1480
|
+
yfov: camera.fovMode === Camera.FOVMODE_VERTICAL_FIXED ? camera.fov : camera.fov * camera.getEngine().getAspectRatio(camera),
|
|
1481
|
+
znear: camera.minZ,
|
|
1482
|
+
zfar: camera.maxZ,
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
else if (glTFCamera.type === "orthographic" /* ORTHOGRAPHIC */) {
|
|
1486
|
+
var halfWidth = camera.orthoLeft && camera.orthoRight ? 0.5 * (camera.orthoRight - camera.orthoLeft) : camera.getEngine().getRenderWidth() * 0.5;
|
|
1487
|
+
var halfHeight = camera.orthoBottom && camera.orthoTop ? 0.5 * (camera.orthoTop - camera.orthoBottom) : camera.getEngine().getRenderHeight() * 0.5;
|
|
1488
|
+
glTFCamera.orthographic = {
|
|
1489
|
+
xmag: halfWidth,
|
|
1490
|
+
ymag: halfHeight,
|
|
1491
|
+
znear: camera.minZ,
|
|
1492
|
+
zfar: camera.maxZ,
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
cameraMap.set(camera, _this._cameras.length);
|
|
1496
|
+
_this._cameras.push(glTFCamera);
|
|
1497
|
+
}
|
|
1498
|
+
});
|
|
1499
|
+
var _a = this._getExportNodes(nodes), exportNodes = _a[0], exportMaterials = _a[1];
|
|
1500
|
+
return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(exportMaterials, "image/png" /* PNG */, true).then(function () {
|
|
1501
|
+
return _this._createNodeMapAndAnimationsAsync(babylonScene, exportNodes, binaryWriter).then(function (nodeMap) {
|
|
1502
|
+
return _this._createSkinsAsync(babylonScene, nodeMap, binaryWriter).then(function (skinMap) {
|
|
1503
|
+
_this._nodeMap = nodeMap;
|
|
1504
|
+
_this._totalByteLength = binaryWriter.getByteOffset();
|
|
1505
|
+
if (_this._totalByteLength == undefined) {
|
|
1506
|
+
throw new Error("undefined byte length!");
|
|
1507
|
+
}
|
|
1508
|
+
// Build Hierarchy with the node map.
|
|
1509
|
+
for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
|
|
1510
|
+
var babylonNode = nodes_1[_i];
|
|
1511
|
+
glTFNodeIndex = _this._nodeMap[babylonNode.uniqueId];
|
|
1512
|
+
if (glTFNodeIndex !== undefined) {
|
|
1513
|
+
glTFNode = _this._nodes[glTFNodeIndex];
|
|
1514
|
+
if (babylonNode.metadata) {
|
|
1515
|
+
if (_this._options.metadataSelector) {
|
|
1516
|
+
glTFNode.extras = _this._options.metadataSelector(babylonNode.metadata);
|
|
1517
|
+
}
|
|
1518
|
+
else if (babylonNode.metadata.gltf) {
|
|
1519
|
+
glTFNode.extras = babylonNode.metadata.gltf.extras;
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
if (babylonNode instanceof Camera) {
|
|
1523
|
+
glTFNode.camera = cameraMap.get(babylonNode);
|
|
1524
|
+
}
|
|
1525
|
+
if (!babylonNode.parent || rootNodesToLeftHanded.indexOf(babylonNode.parent) !== -1) {
|
|
1526
|
+
if (_this._options.shouldExportNode && !_this._options.shouldExportNode(babylonNode)) {
|
|
1527
|
+
Tools.Log("Omitting " + babylonNode.name + " from scene.");
|
|
1528
|
+
}
|
|
1529
|
+
else {
|
|
1530
|
+
var convertToRightHandedSystem = _this._convertToRightHandedSystemMap[babylonNode.uniqueId];
|
|
1531
|
+
if (convertToRightHandedSystem) {
|
|
1532
|
+
if (glTFNode.translation) {
|
|
1533
|
+
glTFNode.translation[2] *= -1;
|
|
1534
|
+
glTFNode.translation[0] *= -1;
|
|
1535
|
+
}
|
|
1536
|
+
glTFNode.rotation = glTFNode.rotation
|
|
1537
|
+
? Quaternion.FromArray([0, 1, 0, 0]).multiply(Quaternion.FromArray(glTFNode.rotation)).asArray()
|
|
1538
|
+
: Quaternion.FromArray([0, 1, 0, 0]).asArray();
|
|
1539
|
+
}
|
|
1540
|
+
scene.nodes.push(glTFNodeIndex);
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
if (babylonNode instanceof Mesh) {
|
|
1544
|
+
var babylonMesh = babylonNode;
|
|
1545
|
+
if (babylonMesh.skeleton) {
|
|
1546
|
+
glTFNode.skin = skinMap[babylonMesh.skeleton.uniqueId];
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
directDescendents = babylonNode.getDescendants(true);
|
|
1550
|
+
if (!glTFNode.children && directDescendents && directDescendents.length) {
|
|
1551
|
+
var children = [];
|
|
1552
|
+
for (var _a = 0, directDescendents_1 = directDescendents; _a < directDescendents_1.length; _a++) {
|
|
1553
|
+
var descendent = directDescendents_1[_a];
|
|
1554
|
+
if (_this._nodeMap[descendent.uniqueId] != null) {
|
|
1555
|
+
children.push(_this._nodeMap[descendent.uniqueId]);
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
if (children.length) {
|
|
1559
|
+
glTFNode.children = children;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
if (scene.nodes.length) {
|
|
1565
|
+
_this._scenes.push(scene);
|
|
1566
|
+
}
|
|
1567
|
+
});
|
|
1568
|
+
});
|
|
1569
|
+
});
|
|
1570
|
+
};
|
|
1571
|
+
/**
|
|
1572
|
+
* Getting the nodes and materials that would be exported.
|
|
1573
|
+
* @param nodes Babylon transform nodes
|
|
1574
|
+
* @returns Array of nodes which would be exported.
|
|
1575
|
+
* @returns Set of materials which would be exported.
|
|
1576
|
+
*/
|
|
1577
|
+
_Exporter.prototype._getExportNodes = function (nodes) {
|
|
1578
|
+
var exportNodes = [];
|
|
1579
|
+
var exportMaterials = new Set();
|
|
1580
|
+
for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
|
|
1581
|
+
var babylonNode = nodes_2[_i];
|
|
1582
|
+
if (!this._options.shouldExportNode || this._options.shouldExportNode(babylonNode)) {
|
|
1583
|
+
exportNodes.push(babylonNode);
|
|
1584
|
+
if (babylonNode instanceof AbstractMesh) {
|
|
1585
|
+
var material = babylonNode.material || babylonNode.getScene().defaultMaterial;
|
|
1586
|
+
if (material instanceof MultiMaterial) {
|
|
1587
|
+
for (var _a = 0, _b = material.subMaterials; _a < _b.length; _a++) {
|
|
1588
|
+
var subMaterial = _b[_a];
|
|
1589
|
+
if (subMaterial) {
|
|
1590
|
+
exportMaterials.add(subMaterial);
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
else {
|
|
1595
|
+
exportMaterials.add(material);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
else {
|
|
1600
|
+
"Excluding node ".concat(babylonNode.name);
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
return [exportNodes, exportMaterials];
|
|
1604
|
+
};
|
|
1605
|
+
/**
|
|
1606
|
+
* Creates a mapping of Node unique id to node index and handles animations
|
|
1607
|
+
* @param babylonScene Babylon Scene
|
|
1608
|
+
* @param nodes Babylon transform nodes
|
|
1609
|
+
* @param binaryWriter Buffer to write binary data to
|
|
1610
|
+
* @returns Node mapping of unique id to index
|
|
1611
|
+
*/
|
|
1612
|
+
_Exporter.prototype._createNodeMapAndAnimationsAsync = function (babylonScene, nodes, binaryWriter) {
|
|
1613
|
+
var _this = this;
|
|
1614
|
+
var promiseChain = Promise.resolve();
|
|
1615
|
+
var nodeMap = {};
|
|
1616
|
+
var nodeIndex;
|
|
1617
|
+
var runtimeGLTFAnimation = {
|
|
1618
|
+
name: "runtime animations",
|
|
1619
|
+
channels: [],
|
|
1620
|
+
samplers: [],
|
|
1621
|
+
};
|
|
1622
|
+
var idleGLTFAnimations = [];
|
|
1623
|
+
var _loop_1 = function (babylonNode) {
|
|
1624
|
+
promiseChain = promiseChain.then(function () {
|
|
1625
|
+
var convertToRightHandedSystem = _this._convertToRightHandedSystemMap[babylonNode.uniqueId];
|
|
1626
|
+
return _this._createNodeAsync(babylonNode, binaryWriter, convertToRightHandedSystem).then(function (node) {
|
|
1627
|
+
var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode, nodeMap);
|
|
1628
|
+
if (promise == null) {
|
|
1629
|
+
Tools.Warn("Not exporting node ".concat(babylonNode.name));
|
|
1630
|
+
return Promise.resolve();
|
|
1631
|
+
}
|
|
1632
|
+
else {
|
|
1633
|
+
return promise.then(function (node) {
|
|
1634
|
+
if (!node) {
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
_this._nodes.push(node);
|
|
1638
|
+
nodeIndex = _this._nodes.length - 1;
|
|
1639
|
+
nodeMap[babylonNode.uniqueId] = nodeIndex;
|
|
1640
|
+
if (!babylonScene.animationGroups.length) {
|
|
1641
|
+
_GLTFAnimation._CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, convertToRightHandedSystem, _this._animationSampleRate);
|
|
1642
|
+
if (babylonNode.animations.length) {
|
|
1643
|
+
_GLTFAnimation._CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, convertToRightHandedSystem, _this._animationSampleRate);
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
});
|
|
1650
|
+
};
|
|
1651
|
+
for (var _i = 0, nodes_3 = nodes; _i < nodes_3.length; _i++) {
|
|
1652
|
+
var babylonNode = nodes_3[_i];
|
|
1653
|
+
_loop_1(babylonNode);
|
|
1654
|
+
}
|
|
1655
|
+
return promiseChain.then(function () {
|
|
1656
|
+
if (runtimeGLTFAnimation.channels.length && runtimeGLTFAnimation.samplers.length) {
|
|
1657
|
+
_this._animations.push(runtimeGLTFAnimation);
|
|
1658
|
+
}
|
|
1659
|
+
idleGLTFAnimations.forEach(function (idleGLTFAnimation) {
|
|
1660
|
+
if (idleGLTFAnimation.channels.length && idleGLTFAnimation.samplers.length) {
|
|
1661
|
+
_this._animations.push(idleGLTFAnimation);
|
|
1662
|
+
}
|
|
1663
|
+
});
|
|
1664
|
+
if (babylonScene.animationGroups.length) {
|
|
1665
|
+
_GLTFAnimation._CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene, _this._animations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, _this._convertToRightHandedSystemMap, _this._animationSampleRate);
|
|
1666
|
+
}
|
|
1667
|
+
return nodeMap;
|
|
1668
|
+
});
|
|
1669
|
+
};
|
|
1670
|
+
/**
|
|
1671
|
+
* Creates a glTF node from a Babylon mesh
|
|
1672
|
+
* @param babylonNode Source Babylon mesh
|
|
1673
|
+
* @param binaryWriter Buffer for storing geometry data
|
|
1674
|
+
* @param convertToRightHandedSystem Converts the values to right-handed
|
|
1675
|
+
* @returns glTF node
|
|
1676
|
+
*/
|
|
1677
|
+
_Exporter.prototype._createNodeAsync = function (babylonNode, binaryWriter, convertToRightHandedSystem) {
|
|
1678
|
+
var _this = this;
|
|
1679
|
+
return Promise.resolve().then(function () {
|
|
1680
|
+
// create node to hold translation/rotation/scale and the mesh
|
|
1681
|
+
var node = {};
|
|
1682
|
+
// create mesh
|
|
1683
|
+
var mesh = { primitives: [] };
|
|
1684
|
+
if (babylonNode.name) {
|
|
1685
|
+
node.name = babylonNode.name;
|
|
1686
|
+
}
|
|
1687
|
+
if (babylonNode instanceof TransformNode) {
|
|
1688
|
+
// Set transformation
|
|
1689
|
+
_this._setNodeTransformation(node, babylonNode, convertToRightHandedSystem);
|
|
1690
|
+
if (babylonNode instanceof Mesh) {
|
|
1691
|
+
var morphTargetManager = babylonNode.morphTargetManager;
|
|
1692
|
+
if (morphTargetManager && morphTargetManager.numTargets > 0) {
|
|
1693
|
+
mesh.weights = [];
|
|
1694
|
+
for (var i = 0; i < morphTargetManager.numTargets; ++i) {
|
|
1695
|
+
mesh.weights.push(morphTargetManager.getTarget(i).influence);
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
return _this._setPrimitiveAttributesAsync(mesh, babylonNode, binaryWriter, convertToRightHandedSystem).then(function () {
|
|
1700
|
+
if (mesh.primitives.length) {
|
|
1701
|
+
_this._meshes.push(mesh);
|
|
1702
|
+
node.mesh = _this._meshes.length - 1;
|
|
1703
|
+
}
|
|
1704
|
+
return node;
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
else if (babylonNode instanceof Camera) {
|
|
1708
|
+
_this._setCameraTransformation(node, babylonNode, convertToRightHandedSystem);
|
|
1709
|
+
return node;
|
|
1710
|
+
}
|
|
1711
|
+
else {
|
|
1712
|
+
return node;
|
|
1713
|
+
}
|
|
1714
|
+
});
|
|
1715
|
+
};
|
|
1716
|
+
/**
|
|
1717
|
+
* Creates a glTF skin from a Babylon skeleton
|
|
1718
|
+
* @param babylonScene Babylon Scene
|
|
1719
|
+
* @param nodeMap Babylon transform nodes
|
|
1720
|
+
* @param binaryWriter Buffer to write binary data to
|
|
1721
|
+
* @returns Node mapping of unique id to index
|
|
1722
|
+
*/
|
|
1723
|
+
_Exporter.prototype._createSkinsAsync = function (babylonScene, nodeMap, binaryWriter) {
|
|
1724
|
+
var _a;
|
|
1725
|
+
var promiseChain = Promise.resolve();
|
|
1726
|
+
var skinMap = {};
|
|
1727
|
+
for (var _i = 0, _b = babylonScene.skeletons; _i < _b.length; _i++) {
|
|
1728
|
+
var skeleton = _b[_i];
|
|
1729
|
+
// create skin
|
|
1730
|
+
var skin = { joints: [] };
|
|
1731
|
+
var inverseBindMatrices = [];
|
|
1732
|
+
var boneIndexMap = {};
|
|
1733
|
+
var maxBoneIndex = -1;
|
|
1734
|
+
for (var i = 0; i < skeleton.bones.length; ++i) {
|
|
1735
|
+
var bone = skeleton.bones[i];
|
|
1736
|
+
var boneIndex = (_a = bone.getIndex()) !== null && _a !== void 0 ? _a : i;
|
|
1737
|
+
if (boneIndex !== -1) {
|
|
1738
|
+
boneIndexMap[boneIndex] = bone;
|
|
1739
|
+
if (boneIndex > maxBoneIndex) {
|
|
1740
|
+
maxBoneIndex = boneIndex;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
for (var boneIndex = 0; boneIndex <= maxBoneIndex; ++boneIndex) {
|
|
1745
|
+
var bone = boneIndexMap[boneIndex];
|
|
1746
|
+
inverseBindMatrices.push(bone.getInvertedAbsoluteTransform());
|
|
1747
|
+
var transformNode = bone.getTransformNode();
|
|
1748
|
+
if (transformNode) {
|
|
1749
|
+
skin.joints.push(nodeMap[transformNode.uniqueId]);
|
|
1750
|
+
}
|
|
1751
|
+
else {
|
|
1752
|
+
Tools.Warn("Exporting a bone without a linked transform node is currently unsupported");
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
// create buffer view for inverse bind matrices
|
|
1756
|
+
var byteStride = 64; // 4 x 4 matrix of 32 bit float
|
|
1757
|
+
var byteLength = inverseBindMatrices.length * byteStride;
|
|
1758
|
+
var bufferViewOffset = binaryWriter.getByteOffset();
|
|
1759
|
+
var bufferView = _GLTFUtilities._CreateBufferView(0, bufferViewOffset, byteLength, undefined, "InverseBindMatrices" + " - " + skeleton.name);
|
|
1760
|
+
this._bufferViews.push(bufferView);
|
|
1761
|
+
var bufferViewIndex = this._bufferViews.length - 1;
|
|
1762
|
+
var bindMatrixAccessor = _GLTFUtilities._CreateAccessor(bufferViewIndex, "InverseBindMatrices" + " - " + skeleton.name, "MAT4" /* MAT4 */, 5126 /* FLOAT */, inverseBindMatrices.length, null, null, null);
|
|
1763
|
+
var inverseBindAccessorIndex = this._accessors.push(bindMatrixAccessor) - 1;
|
|
1764
|
+
skin.inverseBindMatrices = inverseBindAccessorIndex;
|
|
1765
|
+
this._skins.push(skin);
|
|
1766
|
+
skinMap[skeleton.uniqueId] = this._skins.length - 1;
|
|
1767
|
+
inverseBindMatrices.forEach(function (mat) {
|
|
1768
|
+
mat.m.forEach(function (cell) {
|
|
1769
|
+
binaryWriter.setFloat32(cell);
|
|
1770
|
+
});
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
1773
|
+
return promiseChain.then(function () {
|
|
1774
|
+
return skinMap;
|
|
1775
|
+
});
|
|
1776
|
+
};
|
|
1777
|
+
_Exporter._ExtensionNames = new Array();
|
|
1778
|
+
_Exporter._ExtensionFactories = {};
|
|
1779
|
+
return _Exporter;
|
|
1780
|
+
}());
|
|
1781
|
+
export { _Exporter };
|
|
1782
|
+
/**
|
|
1783
|
+
* @hidden
|
|
1784
|
+
*
|
|
1785
|
+
* Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically
|
|
1786
|
+
*/
|
|
1787
|
+
var _BinaryWriter = /** @class */ (function () {
|
|
1788
|
+
/**
|
|
1789
|
+
* Initialize binary writer with an initial byte length
|
|
1790
|
+
* @param byteLength Initial byte length of the array buffer
|
|
1791
|
+
*/
|
|
1792
|
+
function _BinaryWriter(byteLength) {
|
|
1793
|
+
this._arrayBuffer = new ArrayBuffer(byteLength);
|
|
1794
|
+
this._dataView = new DataView(this._arrayBuffer);
|
|
1795
|
+
this._byteOffset = 0;
|
|
1796
|
+
}
|
|
1797
|
+
/**
|
|
1798
|
+
* Resize the array buffer to the specified byte length
|
|
1799
|
+
* @param byteLength
|
|
1800
|
+
*/
|
|
1801
|
+
_BinaryWriter.prototype._resizeBuffer = function (byteLength) {
|
|
1802
|
+
var newBuffer = new ArrayBuffer(byteLength);
|
|
1803
|
+
var oldUint8Array = new Uint8Array(this._arrayBuffer);
|
|
1804
|
+
var newUint8Array = new Uint8Array(newBuffer);
|
|
1805
|
+
for (var i = 0, length_10 = newUint8Array.byteLength; i < length_10; ++i) {
|
|
1806
|
+
newUint8Array[i] = oldUint8Array[i];
|
|
1807
|
+
}
|
|
1808
|
+
this._arrayBuffer = newBuffer;
|
|
1809
|
+
this._dataView = new DataView(this._arrayBuffer);
|
|
1810
|
+
return newBuffer;
|
|
1811
|
+
};
|
|
1812
|
+
/**
|
|
1813
|
+
* Get an array buffer with the length of the byte offset
|
|
1814
|
+
* @returns ArrayBuffer resized to the byte offset
|
|
1815
|
+
*/
|
|
1816
|
+
_BinaryWriter.prototype.getArrayBuffer = function () {
|
|
1817
|
+
return this._resizeBuffer(this.getByteOffset());
|
|
1818
|
+
};
|
|
1819
|
+
/**
|
|
1820
|
+
* Get the byte offset of the array buffer
|
|
1821
|
+
* @returns byte offset
|
|
1822
|
+
*/
|
|
1823
|
+
_BinaryWriter.prototype.getByteOffset = function () {
|
|
1824
|
+
if (this._byteOffset == undefined) {
|
|
1825
|
+
throw new Error("Byte offset is undefined!");
|
|
1826
|
+
}
|
|
1827
|
+
return this._byteOffset;
|
|
1828
|
+
};
|
|
1829
|
+
/**
|
|
1830
|
+
* Stores an UInt8 in the array buffer
|
|
1831
|
+
* @param entry
|
|
1832
|
+
* @param byteOffset If defined, specifies where to set the value as an offset.
|
|
1833
|
+
*/
|
|
1834
|
+
_BinaryWriter.prototype.setUInt8 = function (entry, byteOffset) {
|
|
1835
|
+
if (byteOffset != null) {
|
|
1836
|
+
if (byteOffset < this._byteOffset) {
|
|
1837
|
+
this._dataView.setUint8(byteOffset, entry);
|
|
1838
|
+
}
|
|
1839
|
+
else {
|
|
1840
|
+
Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
else {
|
|
1844
|
+
if (this._byteOffset + 1 > this._arrayBuffer.byteLength) {
|
|
1845
|
+
this._resizeBuffer(this._arrayBuffer.byteLength * 2);
|
|
1846
|
+
}
|
|
1847
|
+
this._dataView.setUint8(this._byteOffset, entry);
|
|
1848
|
+
this._byteOffset += 1;
|
|
1849
|
+
}
|
|
1850
|
+
};
|
|
1851
|
+
/**
|
|
1852
|
+
* Stores an UInt16 in the array buffer
|
|
1853
|
+
* @param entry
|
|
1854
|
+
* @param byteOffset If defined, specifies where to set the value as an offset.
|
|
1855
|
+
*/
|
|
1856
|
+
_BinaryWriter.prototype.setUInt16 = function (entry, byteOffset) {
|
|
1857
|
+
if (byteOffset != null) {
|
|
1858
|
+
if (byteOffset < this._byteOffset) {
|
|
1859
|
+
this._dataView.setUint16(byteOffset, entry, true);
|
|
1860
|
+
}
|
|
1861
|
+
else {
|
|
1862
|
+
Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
else {
|
|
1866
|
+
if (this._byteOffset + 2 > this._arrayBuffer.byteLength) {
|
|
1867
|
+
this._resizeBuffer(this._arrayBuffer.byteLength * 2);
|
|
1868
|
+
}
|
|
1869
|
+
this._dataView.setUint16(this._byteOffset, entry, true);
|
|
1870
|
+
this._byteOffset += 2;
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
/**
|
|
1874
|
+
* Gets an UInt32 in the array buffer
|
|
1875
|
+
* @param byteOffset If defined, specifies where to set the value as an offset.
|
|
1876
|
+
*/
|
|
1877
|
+
_BinaryWriter.prototype.getUInt32 = function (byteOffset) {
|
|
1878
|
+
if (byteOffset < this._byteOffset) {
|
|
1879
|
+
return this._dataView.getUint32(byteOffset, true);
|
|
1880
|
+
}
|
|
1881
|
+
else {
|
|
1882
|
+
Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
|
|
1883
|
+
throw new Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1886
|
+
_BinaryWriter.prototype.getVector3Float32FromRef = function (vector3, byteOffset) {
|
|
1887
|
+
if (byteOffset + 8 > this._byteOffset) {
|
|
1888
|
+
Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
|
|
1889
|
+
}
|
|
1890
|
+
else {
|
|
1891
|
+
vector3.x = this._dataView.getFloat32(byteOffset, true);
|
|
1892
|
+
vector3.y = this._dataView.getFloat32(byteOffset + 4, true);
|
|
1893
|
+
vector3.z = this._dataView.getFloat32(byteOffset + 8, true);
|
|
1894
|
+
}
|
|
1895
|
+
};
|
|
1896
|
+
_BinaryWriter.prototype.setVector3Float32FromRef = function (vector3, byteOffset) {
|
|
1897
|
+
if (byteOffset + 8 > this._byteOffset) {
|
|
1898
|
+
Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
|
|
1899
|
+
}
|
|
1900
|
+
else {
|
|
1901
|
+
this._dataView.setFloat32(byteOffset, vector3.x, true);
|
|
1902
|
+
this._dataView.setFloat32(byteOffset + 4, vector3.y, true);
|
|
1903
|
+
this._dataView.setFloat32(byteOffset + 8, vector3.z, true);
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
_BinaryWriter.prototype.getVector4Float32FromRef = function (vector4, byteOffset) {
|
|
1907
|
+
if (byteOffset + 12 > this._byteOffset) {
|
|
1908
|
+
Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
|
|
1909
|
+
}
|
|
1910
|
+
else {
|
|
1911
|
+
vector4.x = this._dataView.getFloat32(byteOffset, true);
|
|
1912
|
+
vector4.y = this._dataView.getFloat32(byteOffset + 4, true);
|
|
1913
|
+
vector4.z = this._dataView.getFloat32(byteOffset + 8, true);
|
|
1914
|
+
vector4.w = this._dataView.getFloat32(byteOffset + 12, true);
|
|
1915
|
+
}
|
|
1916
|
+
};
|
|
1917
|
+
_BinaryWriter.prototype.setVector4Float32FromRef = function (vector4, byteOffset) {
|
|
1918
|
+
if (byteOffset + 12 > this._byteOffset) {
|
|
1919
|
+
Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
|
|
1920
|
+
}
|
|
1921
|
+
else {
|
|
1922
|
+
this._dataView.setFloat32(byteOffset, vector4.x, true);
|
|
1923
|
+
this._dataView.setFloat32(byteOffset + 4, vector4.y, true);
|
|
1924
|
+
this._dataView.setFloat32(byteOffset + 8, vector4.z, true);
|
|
1925
|
+
this._dataView.setFloat32(byteOffset + 12, vector4.w, true);
|
|
1926
|
+
}
|
|
1927
|
+
};
|
|
1928
|
+
/**
|
|
1929
|
+
* Stores a Float32 in the array buffer
|
|
1930
|
+
* @param entry
|
|
1931
|
+
* @param byteOffset
|
|
1932
|
+
*/
|
|
1933
|
+
_BinaryWriter.prototype.setFloat32 = function (entry, byteOffset) {
|
|
1934
|
+
if (isNaN(entry)) {
|
|
1935
|
+
Tools.Error("Invalid data being written!");
|
|
1936
|
+
}
|
|
1937
|
+
if (byteOffset != null) {
|
|
1938
|
+
if (byteOffset < this._byteOffset) {
|
|
1939
|
+
this._dataView.setFloat32(byteOffset, entry, true);
|
|
1940
|
+
}
|
|
1941
|
+
else {
|
|
1942
|
+
Tools.Error("BinaryWriter: byteoffset is greater than the current binary length!");
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {
|
|
1946
|
+
this._resizeBuffer(this._arrayBuffer.byteLength * 2);
|
|
1947
|
+
}
|
|
1948
|
+
this._dataView.setFloat32(this._byteOffset, entry, true);
|
|
1949
|
+
this._byteOffset += 4;
|
|
1950
|
+
};
|
|
1951
|
+
/**
|
|
1952
|
+
* Stores an UInt32 in the array buffer
|
|
1953
|
+
* @param entry
|
|
1954
|
+
* @param byteOffset If defined, specifies where to set the value as an offset.
|
|
1955
|
+
*/
|
|
1956
|
+
_BinaryWriter.prototype.setUInt32 = function (entry, byteOffset) {
|
|
1957
|
+
if (byteOffset != null) {
|
|
1958
|
+
if (byteOffset < this._byteOffset) {
|
|
1959
|
+
this._dataView.setUint32(byteOffset, entry, true);
|
|
1960
|
+
}
|
|
1961
|
+
else {
|
|
1962
|
+
Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
else {
|
|
1966
|
+
if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {
|
|
1967
|
+
this._resizeBuffer(this._arrayBuffer.byteLength * 2);
|
|
1968
|
+
}
|
|
1969
|
+
this._dataView.setUint32(this._byteOffset, entry, true);
|
|
1970
|
+
this._byteOffset += 4;
|
|
1971
|
+
}
|
|
1972
|
+
};
|
|
1973
|
+
return _BinaryWriter;
|
|
1974
|
+
}());
|
|
1975
|
+
export { _BinaryWriter };
|
|
1973
1976
|
//# sourceMappingURL=glTFExporter.js.map
|