@babylonjs/loaders 5.0.0-rc.1 → 5.0.0-rc.10
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/index.d.ts +4 -4
- package/OBJ/index.js +4 -4
- package/OBJ/index.js.map +1 -1
- package/OBJ/mtlFileLoader.d.ts +41 -40
- package/OBJ/mtlFileLoader.js +232 -231
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.d.ts +126 -133
- package/OBJ/objFileLoader.js +296 -300
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/objLoadingOptions.d.ts +43 -43
- package/OBJ/objLoadingOptions.js +1 -1
- package/OBJ/objLoadingOptions.js.map +1 -1
- package/OBJ/solidParser.d.ts +154 -153
- package/OBJ/solidParser.js +693 -699
- package/OBJ/solidParser.js.map +1 -1
- package/STL/index.d.ts +1 -1
- package/STL/index.js +1 -1
- package/STL/index.js.map +1 -1
- package/STL/stlFileLoader.d.ts +64 -71
- package/STL/stlFileLoader.js +233 -239
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
- package/glTF/1.0/glTFBinaryExtension.js +60 -61
- package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
- package/glTF/1.0/glTFLoader.d.ts +136 -106
- package/glTF/1.0/glTFLoader.js +1814 -1696
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
- package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
- package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.d.ts +63 -62
- package/glTF/1.0/glTFLoaderUtils.js +250 -232
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
- package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
- package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -127
- package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
- package/glTF/1.0/index.d.ts +5 -5
- package/glTF/1.0/index.js +5 -5
- package/glTF/1.0/index.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -36
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -110
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -28
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -80
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -27
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -42
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -21
- package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -32
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -32
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -55
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -101
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -28
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -81
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -86
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -45
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -34
- package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -54
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -72
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -76
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -66
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -76
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -277
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -65
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -76
- package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -243
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -78
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -19
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -21
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -21
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -32
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -25
- package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -53
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -29
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -46
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -38
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -216
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -75
- package/glTF/2.0/Extensions/MSFT_lod.js +369 -333
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +14 -14
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +36 -36
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +14 -14
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +36 -36
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/Extensions/index.d.ts +26 -26
- package/glTF/2.0/Extensions/index.js +26 -26
- package/glTF/2.0/Extensions/index.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +406 -357
- package/glTF/2.0/glTFLoader.js +2366 -2266
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
- package/glTF/2.0/glTFLoaderExtension.js +1 -1
- package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -209
- package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/2.0/index.d.ts +4 -4
- package/glTF/2.0/index.js +5 -4
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +433 -373
- package/glTF/glTFFileLoader.js +927 -870
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.d.ts +29 -29
- package/glTF/glTFValidation.js +123 -121
- package/glTF/glTFValidation.js.map +1 -1
- package/glTF/index.d.ts +5 -5
- package/glTF/index.js +6 -5
- 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-glTF.d.ts +2 -2
- package/legacy/legacy-glTF.js +18 -18
- package/legacy/legacy-glTF.js.map +1 -1
- package/legacy/legacy-glTF1.d.ts +2 -2
- package/legacy/legacy-glTF1.js +15 -14
- package/legacy/legacy-glTF1.js.map +1 -1
- package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF1FileLoader.js +3 -2
- package/legacy/legacy-glTF1FileLoader.js.map +1 -1
- package/legacy/legacy-glTF2.d.ts +2 -2
- package/legacy/legacy-glTF2.js +33 -32
- package/legacy/legacy-glTF2.js.map +1 -1
- package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF2FileLoader.js +3 -2
- package/legacy/legacy-glTF2FileLoader.js.map +1 -1
- package/legacy/legacy-glTFFileLoader.d.ts +3 -3
- package/legacy/legacy-glTFFileLoader.js +4 -3
- package/legacy/legacy-glTFFileLoader.js.map +1 -1
- package/legacy/legacy-objFileLoader.d.ts +1 -1
- package/legacy/legacy-objFileLoader.js +13 -12
- package/legacy/legacy-objFileLoader.js.map +1 -1
- package/legacy/legacy-stlFileLoader.d.ts +1 -1
- package/legacy/legacy-stlFileLoader.js +13 -12
- package/legacy/legacy-stlFileLoader.js.map +1 -1
- package/legacy/legacy.d.ts +6 -6
- package/legacy/legacy.js +8 -6
- package/legacy/legacy.js.map +1 -1
- package/package.json +23 -198
- package/readme.md +2 -2
package/glTF/2.0/glTFLoader.js
CHANGED
@@ -1,2267 +1,2367 @@
|
|
1
|
-
import { Deferred } from "@babylonjs/core/Misc/deferred.js";
|
2
|
-
import { Quaternion, Vector3, Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
3
|
-
import { Color3 } from
|
4
|
-
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
5
|
-
import { Camera } from "@babylonjs/core/Cameras/camera.js";
|
6
|
-
import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera.js";
|
7
|
-
import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup.js";
|
8
|
-
import { Animation } from "@babylonjs/core/Animations/animation.js";
|
9
|
-
import { Bone } from "@babylonjs/core/Bones/bone.js";
|
10
|
-
import { Skeleton } from "@babylonjs/core/Bones/skeleton.js";
|
11
|
-
import { Material } from "@babylonjs/core/Materials/material.js";
|
12
|
-
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
13
|
-
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
14
|
-
import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
|
15
|
-
import { Buffer, VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
|
16
|
-
import { Geometry } from "@babylonjs/core/Meshes/geometry.js";
|
17
|
-
import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
18
|
-
import { MorphTarget } from "@babylonjs/core/Morph/morphTarget.js";
|
19
|
-
import { MorphTargetManager } from "@babylonjs/core/Morph/morphTargetManager.js";
|
20
|
-
import { GLTFFileLoader, GLTFLoaderState, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode } from "../glTFFileLoader
|
21
|
-
import { AnimationKeyInterpolation } from
|
22
|
-
import { DecodeBase64UrlToBinary, IsBase64DataUrl, LoadFileError } from
|
23
|
-
import { Logger } from
|
24
|
-
import {
|
25
|
-
import {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
*/
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
*
|
35
|
-
* @param
|
36
|
-
* @param
|
37
|
-
* @
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
*
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
}
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
*/
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
/** @hidden */
|
69
|
-
this.
|
70
|
-
/**
|
71
|
-
this.
|
72
|
-
/**
|
73
|
-
this.
|
74
|
-
|
75
|
-
this.
|
76
|
-
this.
|
77
|
-
this.
|
78
|
-
this.
|
79
|
-
this.
|
80
|
-
this.
|
81
|
-
this.
|
82
|
-
this.
|
83
|
-
this.
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
*
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
*
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
this.
|
174
|
-
this.
|
175
|
-
this.
|
176
|
-
this.
|
177
|
-
this.
|
178
|
-
this.
|
179
|
-
this.
|
180
|
-
this.
|
181
|
-
this.
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
};
|
221
|
-
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
_this.
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
_this.
|
278
|
-
}
|
279
|
-
|
280
|
-
|
281
|
-
_this.
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
_this._parent.
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
}
|
322
|
-
|
323
|
-
}
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
var
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
}
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
this.
|
394
|
-
this.
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
this.
|
417
|
-
|
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
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
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
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
}
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
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
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
}
|
596
|
-
if (node.
|
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
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
}
|
667
|
-
}
|
668
|
-
|
669
|
-
|
670
|
-
node
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
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
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
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
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
}
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
var
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
return
|
974
|
-
}
|
975
|
-
var
|
976
|
-
|
977
|
-
var
|
978
|
-
|
979
|
-
|
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
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
if (
|
1096
|
-
|
1097
|
-
}
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
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
|
-
this.
|
1158
|
-
|
1159
|
-
this.
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
this.
|
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
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
case "
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
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
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
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
|
-
|
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
|
-
var
|
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
|
-
|
1432
|
-
|
1433
|
-
*
|
1434
|
-
* @
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
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
|
-
return
|
1506
|
-
}
|
1507
|
-
});
|
1508
|
-
}
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
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
|
-
if (
|
1556
|
-
|
1557
|
-
}
|
1558
|
-
if (accessor.
|
1559
|
-
accessor.
|
1560
|
-
|
1561
|
-
|
1562
|
-
}
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
}
|
1570
|
-
else {
|
1571
|
-
var
|
1572
|
-
accessor.
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
if (
|
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
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
babylonMaterial
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
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
|
-
|
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
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
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
|
-
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
babylonMaterial.
|
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
|
-
* @param
|
1886
|
-
* @param
|
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
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
var
|
1921
|
-
|
1922
|
-
|
1923
|
-
}
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
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
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1977
|
-
}
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
}
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
2012
|
-
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
2016
|
-
|
2017
|
-
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
|
2027
|
-
|
2028
|
-
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
}
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2074
|
-
|
2075
|
-
|
2076
|
-
|
2077
|
-
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
2083
|
-
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2123
|
-
|
2124
|
-
|
2125
|
-
|
2126
|
-
|
2127
|
-
GLTFLoader.
|
2128
|
-
|
2129
|
-
|
2130
|
-
|
2131
|
-
|
2132
|
-
|
2133
|
-
|
2134
|
-
|
2135
|
-
|
2136
|
-
|
2137
|
-
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2202
|
-
|
2203
|
-
|
2204
|
-
|
2205
|
-
|
2206
|
-
|
2207
|
-
|
2208
|
-
|
2209
|
-
|
2210
|
-
|
2211
|
-
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2233
|
-
|
2234
|
-
|
2235
|
-
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2239
|
-
|
2240
|
-
|
2241
|
-
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
GLTFLoader.prototype.
|
2249
|
-
this.
|
2250
|
-
};
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2258
|
-
|
2259
|
-
|
2260
|
-
|
2261
|
-
|
2262
|
-
|
2263
|
-
|
2264
|
-
|
2265
|
-
|
2266
|
-
|
1
|
+
import { Deferred } from "@babylonjs/core/Misc/deferred.js";
|
2
|
+
import { Quaternion, Vector3, Matrix, TmpVectors } from "@babylonjs/core/Maths/math.vector.js";
|
3
|
+
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
4
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
5
|
+
import { Camera } from "@babylonjs/core/Cameras/camera.js";
|
6
|
+
import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera.js";
|
7
|
+
import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup.js";
|
8
|
+
import { Animation } from "@babylonjs/core/Animations/animation.js";
|
9
|
+
import { Bone } from "@babylonjs/core/Bones/bone.js";
|
10
|
+
import { Skeleton } from "@babylonjs/core/Bones/skeleton.js";
|
11
|
+
import { Material } from "@babylonjs/core/Materials/material.js";
|
12
|
+
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
13
|
+
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
14
|
+
import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
|
15
|
+
import { Buffer, VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
|
16
|
+
import { Geometry } from "@babylonjs/core/Meshes/geometry.js";
|
17
|
+
import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
18
|
+
import { MorphTarget } from "@babylonjs/core/Morph/morphTarget.js";
|
19
|
+
import { MorphTargetManager } from "@babylonjs/core/Morph/morphTargetManager.js";
|
20
|
+
import { GLTFFileLoader, GLTFLoaderState, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode } from "../glTFFileLoader";
|
21
|
+
import { AnimationKeyInterpolation } from "@babylonjs/core/Animations/animationKey.js";
|
22
|
+
import { DecodeBase64UrlToBinary, IsBase64DataUrl, LoadFileError } from "@babylonjs/core/Misc/fileTools.js";
|
23
|
+
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
24
|
+
import { BoundingInfo } from "@babylonjs/core/Culling/boundingInfo.js";
|
25
|
+
import { StringTools } from "@babylonjs/core/Misc/stringTools.js";
|
26
|
+
/**
|
27
|
+
* Helper class for working with arrays when loading the glTF asset
|
28
|
+
*/
|
29
|
+
var ArrayItem = /** @class */ (function () {
|
30
|
+
function ArrayItem() {
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* Gets an item from the given array.
|
34
|
+
* @param context The context when loading the asset
|
35
|
+
* @param array The array to get the item from
|
36
|
+
* @param index The index to the array
|
37
|
+
* @returns The array item
|
38
|
+
*/
|
39
|
+
ArrayItem.Get = function (context, array, index) {
|
40
|
+
if (!array || index == undefined || !array[index]) {
|
41
|
+
throw new Error("".concat(context, ": Failed to find index (").concat(index, ")"));
|
42
|
+
}
|
43
|
+
return array[index];
|
44
|
+
};
|
45
|
+
/**
|
46
|
+
* Assign an `index` field to each item of the given array.
|
47
|
+
* @param array The array of items
|
48
|
+
*/
|
49
|
+
ArrayItem.Assign = function (array) {
|
50
|
+
if (array) {
|
51
|
+
for (var index = 0; index < array.length; index++) {
|
52
|
+
array[index].index = index;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
};
|
56
|
+
return ArrayItem;
|
57
|
+
}());
|
58
|
+
export { ArrayItem };
|
59
|
+
/**
|
60
|
+
* The glTF 2.0 loader
|
61
|
+
*/
|
62
|
+
var GLTFLoader = /** @class */ (function () {
|
63
|
+
/**
|
64
|
+
* @param parent
|
65
|
+
* @hidden
|
66
|
+
*/
|
67
|
+
function GLTFLoader(parent) {
|
68
|
+
/** @hidden */
|
69
|
+
this._completePromises = new Array();
|
70
|
+
/** @hidden */
|
71
|
+
this._assetContainer = null;
|
72
|
+
/** Storage */
|
73
|
+
this._babylonLights = [];
|
74
|
+
/** @hidden */
|
75
|
+
this._disableInstancedMesh = 0;
|
76
|
+
this._extensions = new Array();
|
77
|
+
this._disposed = false;
|
78
|
+
this._rootUrl = null;
|
79
|
+
this._fileName = null;
|
80
|
+
this._uniqueRootUrl = null;
|
81
|
+
this._bin = null;
|
82
|
+
this._rootBabylonMesh = null;
|
83
|
+
this._defaultBabylonMaterialData = {};
|
84
|
+
this._postSceneLoadActions = new Array();
|
85
|
+
this._parent = parent;
|
86
|
+
}
|
87
|
+
/**
|
88
|
+
* Registers a loader extension.
|
89
|
+
* @param name The name of the loader extension.
|
90
|
+
* @param factory The factory function that creates the loader extension.
|
91
|
+
*/
|
92
|
+
GLTFLoader.RegisterExtension = function (name, factory) {
|
93
|
+
if (GLTFLoader.UnregisterExtension(name)) {
|
94
|
+
Logger.Warn("Extension with the name '".concat(name, "' already exists"));
|
95
|
+
}
|
96
|
+
GLTFLoader._RegisteredExtensions[name] = {
|
97
|
+
factory: factory,
|
98
|
+
};
|
99
|
+
};
|
100
|
+
/**
|
101
|
+
* Unregisters a loader extension.
|
102
|
+
* @param name The name of the loader extension.
|
103
|
+
* @returns A boolean indicating whether the extension has been unregistered
|
104
|
+
*/
|
105
|
+
GLTFLoader.UnregisterExtension = function (name) {
|
106
|
+
if (!GLTFLoader._RegisteredExtensions[name]) {
|
107
|
+
return false;
|
108
|
+
}
|
109
|
+
delete GLTFLoader._RegisteredExtensions[name];
|
110
|
+
return true;
|
111
|
+
};
|
112
|
+
Object.defineProperty(GLTFLoader.prototype, "gltf", {
|
113
|
+
/**
|
114
|
+
* The object that represents the glTF JSON.
|
115
|
+
*/
|
116
|
+
get: function () {
|
117
|
+
if (!this._gltf) {
|
118
|
+
throw new Error("glTF JSON is not available");
|
119
|
+
}
|
120
|
+
return this._gltf;
|
121
|
+
},
|
122
|
+
enumerable: false,
|
123
|
+
configurable: true
|
124
|
+
});
|
125
|
+
Object.defineProperty(GLTFLoader.prototype, "bin", {
|
126
|
+
/**
|
127
|
+
* The BIN chunk of a binary glTF.
|
128
|
+
*/
|
129
|
+
get: function () {
|
130
|
+
return this._bin;
|
131
|
+
},
|
132
|
+
enumerable: false,
|
133
|
+
configurable: true
|
134
|
+
});
|
135
|
+
Object.defineProperty(GLTFLoader.prototype, "parent", {
|
136
|
+
/**
|
137
|
+
* The parent file loader.
|
138
|
+
*/
|
139
|
+
get: function () {
|
140
|
+
return this._parent;
|
141
|
+
},
|
142
|
+
enumerable: false,
|
143
|
+
configurable: true
|
144
|
+
});
|
145
|
+
Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
|
146
|
+
/**
|
147
|
+
* The Babylon scene when loading the asset.
|
148
|
+
*/
|
149
|
+
get: function () {
|
150
|
+
if (!this._babylonScene) {
|
151
|
+
throw new Error("Scene is not available");
|
152
|
+
}
|
153
|
+
return this._babylonScene;
|
154
|
+
},
|
155
|
+
enumerable: false,
|
156
|
+
configurable: true
|
157
|
+
});
|
158
|
+
Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
|
159
|
+
/**
|
160
|
+
* The root Babylon mesh when loading the asset.
|
161
|
+
*/
|
162
|
+
get: function () {
|
163
|
+
return this._rootBabylonMesh;
|
164
|
+
},
|
165
|
+
enumerable: false,
|
166
|
+
configurable: true
|
167
|
+
});
|
168
|
+
/** @hidden */
|
169
|
+
GLTFLoader.prototype.dispose = function () {
|
170
|
+
if (this._disposed) {
|
171
|
+
return;
|
172
|
+
}
|
173
|
+
this._disposed = true;
|
174
|
+
this._completePromises.length = 0;
|
175
|
+
this._extensions.forEach(function (extension) { return extension.dispose && extension.dispose(); });
|
176
|
+
this._extensions.length = 0;
|
177
|
+
this._gltf = null; // TODO
|
178
|
+
this._bin = null;
|
179
|
+
this._babylonScene = null; // TODO
|
180
|
+
this._rootBabylonMesh = null;
|
181
|
+
this._defaultBabylonMaterialData = {};
|
182
|
+
this._postSceneLoadActions.length = 0;
|
183
|
+
this._parent.dispose();
|
184
|
+
};
|
185
|
+
/**
|
186
|
+
* @param meshesNames
|
187
|
+
* @param scene
|
188
|
+
* @param container
|
189
|
+
* @param data
|
190
|
+
* @param rootUrl
|
191
|
+
* @param onProgress
|
192
|
+
* @param fileName
|
193
|
+
* @hidden
|
194
|
+
*/
|
195
|
+
GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, container, data, rootUrl, onProgress, fileName) {
|
196
|
+
var _this = this;
|
197
|
+
if (fileName === void 0) { fileName = ""; }
|
198
|
+
return Promise.resolve().then(function () {
|
199
|
+
_this._babylonScene = scene;
|
200
|
+
_this._assetContainer = container;
|
201
|
+
_this._loadData(data);
|
202
|
+
var nodes = null;
|
203
|
+
if (meshesNames) {
|
204
|
+
var nodeMap_1 = {};
|
205
|
+
if (_this._gltf.nodes) {
|
206
|
+
for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
|
207
|
+
var node = _a[_i];
|
208
|
+
if (node.name) {
|
209
|
+
nodeMap_1[node.name] = node.index;
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
var names = meshesNames instanceof Array ? meshesNames : [meshesNames];
|
214
|
+
nodes = names.map(function (name) {
|
215
|
+
var node = nodeMap_1[name];
|
216
|
+
if (node === undefined) {
|
217
|
+
throw new Error("Failed to find node '".concat(name, "'"));
|
218
|
+
}
|
219
|
+
return node;
|
220
|
+
});
|
221
|
+
}
|
222
|
+
return _this._loadAsync(rootUrl, fileName, nodes, function () {
|
223
|
+
return {
|
224
|
+
meshes: _this._getMeshes(),
|
225
|
+
particleSystems: [],
|
226
|
+
skeletons: _this._getSkeletons(),
|
227
|
+
animationGroups: _this._getAnimationGroups(),
|
228
|
+
lights: _this._babylonLights,
|
229
|
+
transformNodes: _this._getTransformNodes(),
|
230
|
+
geometries: _this._getGeometries(),
|
231
|
+
};
|
232
|
+
});
|
233
|
+
});
|
234
|
+
};
|
235
|
+
/**
|
236
|
+
* @param scene
|
237
|
+
* @param data
|
238
|
+
* @param rootUrl
|
239
|
+
* @param onProgress
|
240
|
+
* @param fileName
|
241
|
+
* @hidden
|
242
|
+
*/
|
243
|
+
GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
|
244
|
+
var _this = this;
|
245
|
+
if (fileName === void 0) { fileName = ""; }
|
246
|
+
return Promise.resolve().then(function () {
|
247
|
+
_this._babylonScene = scene;
|
248
|
+
_this._loadData(data);
|
249
|
+
return _this._loadAsync(rootUrl, fileName, null, function () { return undefined; });
|
250
|
+
});
|
251
|
+
};
|
252
|
+
GLTFLoader.prototype._loadAsync = function (rootUrl, fileName, nodes, resultFunc) {
|
253
|
+
var _this = this;
|
254
|
+
return Promise.resolve()
|
255
|
+
.then(function () {
|
256
|
+
_this._rootUrl = rootUrl;
|
257
|
+
_this._uniqueRootUrl = !StringTools.StartsWith(rootUrl, "file:") && fileName ? rootUrl : "".concat(rootUrl).concat(Date.now(), "/");
|
258
|
+
_this._fileName = fileName;
|
259
|
+
_this._loadExtensions();
|
260
|
+
_this._checkExtensions();
|
261
|
+
var loadingToReadyCounterName = "".concat(GLTFLoaderState[GLTFLoaderState.LOADING], " => ").concat(GLTFLoaderState[GLTFLoaderState.READY]);
|
262
|
+
var loadingToCompleteCounterName = "".concat(GLTFLoaderState[GLTFLoaderState.LOADING], " => ").concat(GLTFLoaderState[GLTFLoaderState.COMPLETE]);
|
263
|
+
_this._parent._startPerformanceCounter(loadingToReadyCounterName);
|
264
|
+
_this._parent._startPerformanceCounter(loadingToCompleteCounterName);
|
265
|
+
_this._parent._setState(GLTFLoaderState.LOADING);
|
266
|
+
_this._extensionsOnLoading();
|
267
|
+
var promises = new Array();
|
268
|
+
// Block the marking of materials dirty until the scene is loaded.
|
269
|
+
var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
|
270
|
+
_this._babylonScene.blockMaterialDirtyMechanism = true;
|
271
|
+
if (!_this.parent.loadOnlyMaterials) {
|
272
|
+
if (nodes) {
|
273
|
+
promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
|
274
|
+
}
|
275
|
+
else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
|
276
|
+
var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
|
277
|
+
promises.push(_this.loadSceneAsync("/scenes/".concat(scene.index), scene));
|
278
|
+
}
|
279
|
+
}
|
280
|
+
if (!_this.parent.skipMaterials && _this.parent.loadAllMaterials && _this._gltf.materials) {
|
281
|
+
for (var m = 0; m < _this._gltf.materials.length; ++m) {
|
282
|
+
var material = _this._gltf.materials[m];
|
283
|
+
var context_1 = "/materials/" + m;
|
284
|
+
var babylonDrawMode = Material.TriangleFillMode;
|
285
|
+
promises.push(_this._loadMaterialAsync(context_1, material, null, babylonDrawMode, function () { }));
|
286
|
+
}
|
287
|
+
}
|
288
|
+
// Restore the blocking of material dirty.
|
289
|
+
_this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
|
290
|
+
if (_this._parent.compileMaterials) {
|
291
|
+
promises.push(_this._compileMaterialsAsync());
|
292
|
+
}
|
293
|
+
if (_this._parent.compileShadowGenerators) {
|
294
|
+
promises.push(_this._compileShadowGeneratorsAsync());
|
295
|
+
}
|
296
|
+
var resultPromise = Promise.all(promises).then(function () {
|
297
|
+
if (_this._rootBabylonMesh) {
|
298
|
+
_this._rootBabylonMesh.setEnabled(true);
|
299
|
+
}
|
300
|
+
_this._extensionsOnReady();
|
301
|
+
_this._parent._setState(GLTFLoaderState.READY);
|
302
|
+
_this._startAnimations();
|
303
|
+
return resultFunc();
|
304
|
+
});
|
305
|
+
return resultPromise.then(function (result) {
|
306
|
+
_this._parent._endPerformanceCounter(loadingToReadyCounterName);
|
307
|
+
Tools.SetImmediate(function () {
|
308
|
+
if (!_this._disposed) {
|
309
|
+
Promise.all(_this._completePromises).then(function () {
|
310
|
+
_this._parent._endPerformanceCounter(loadingToCompleteCounterName);
|
311
|
+
_this._parent._setState(GLTFLoaderState.COMPLETE);
|
312
|
+
_this._parent.onCompleteObservable.notifyObservers(undefined);
|
313
|
+
_this._parent.onCompleteObservable.clear();
|
314
|
+
_this.dispose();
|
315
|
+
}, function (error) {
|
316
|
+
_this._parent.onErrorObservable.notifyObservers(error);
|
317
|
+
_this._parent.onErrorObservable.clear();
|
318
|
+
_this.dispose();
|
319
|
+
});
|
320
|
+
}
|
321
|
+
});
|
322
|
+
return result;
|
323
|
+
});
|
324
|
+
})
|
325
|
+
.catch(function (error) {
|
326
|
+
if (!_this._disposed) {
|
327
|
+
_this._parent.onErrorObservable.notifyObservers(error);
|
328
|
+
_this._parent.onErrorObservable.clear();
|
329
|
+
_this.dispose();
|
330
|
+
}
|
331
|
+
throw error;
|
332
|
+
});
|
333
|
+
};
|
334
|
+
GLTFLoader.prototype._loadData = function (data) {
|
335
|
+
this._gltf = data.json;
|
336
|
+
this._setupData();
|
337
|
+
if (data.bin) {
|
338
|
+
var buffers = this._gltf.buffers;
|
339
|
+
if (buffers && buffers[0] && !buffers[0].uri) {
|
340
|
+
var binaryBuffer = buffers[0];
|
341
|
+
if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
|
342
|
+
Logger.Warn("Binary buffer length (".concat(binaryBuffer.byteLength, ") from JSON does not match chunk length (").concat(data.bin.byteLength, ")"));
|
343
|
+
}
|
344
|
+
this._bin = data.bin;
|
345
|
+
}
|
346
|
+
else {
|
347
|
+
Logger.Warn("Unexpected BIN chunk");
|
348
|
+
}
|
349
|
+
}
|
350
|
+
};
|
351
|
+
GLTFLoader.prototype._setupData = function () {
|
352
|
+
ArrayItem.Assign(this._gltf.accessors);
|
353
|
+
ArrayItem.Assign(this._gltf.animations);
|
354
|
+
ArrayItem.Assign(this._gltf.buffers);
|
355
|
+
ArrayItem.Assign(this._gltf.bufferViews);
|
356
|
+
ArrayItem.Assign(this._gltf.cameras);
|
357
|
+
ArrayItem.Assign(this._gltf.images);
|
358
|
+
ArrayItem.Assign(this._gltf.materials);
|
359
|
+
ArrayItem.Assign(this._gltf.meshes);
|
360
|
+
ArrayItem.Assign(this._gltf.nodes);
|
361
|
+
ArrayItem.Assign(this._gltf.samplers);
|
362
|
+
ArrayItem.Assign(this._gltf.scenes);
|
363
|
+
ArrayItem.Assign(this._gltf.skins);
|
364
|
+
ArrayItem.Assign(this._gltf.textures);
|
365
|
+
if (this._gltf.nodes) {
|
366
|
+
var nodeParents = {};
|
367
|
+
for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
|
368
|
+
var node = _a[_i];
|
369
|
+
if (node.children) {
|
370
|
+
for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
|
371
|
+
var index = _c[_b];
|
372
|
+
nodeParents[index] = node.index;
|
373
|
+
}
|
374
|
+
}
|
375
|
+
}
|
376
|
+
var rootNode = this._createRootNode();
|
377
|
+
for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
|
378
|
+
var node = _e[_d];
|
379
|
+
var parentIndex = nodeParents[node.index];
|
380
|
+
node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
|
381
|
+
}
|
382
|
+
}
|
383
|
+
};
|
384
|
+
GLTFLoader.prototype._loadExtensions = function () {
|
385
|
+
for (var name_1 in GLTFLoader._RegisteredExtensions) {
|
386
|
+
var extension = GLTFLoader._RegisteredExtensions[name_1].factory(this);
|
387
|
+
if (extension.name !== name_1) {
|
388
|
+
Logger.Warn("The name of the glTF loader extension instance does not match the registered name: ".concat(extension.name, " !== ").concat(name_1));
|
389
|
+
}
|
390
|
+
this._extensions.push(extension);
|
391
|
+
this._parent.onExtensionLoadedObservable.notifyObservers(extension);
|
392
|
+
}
|
393
|
+
this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
|
394
|
+
this._parent.onExtensionLoadedObservable.clear();
|
395
|
+
};
|
396
|
+
GLTFLoader.prototype._checkExtensions = function () {
|
397
|
+
if (this._gltf.extensionsRequired) {
|
398
|
+
var _loop_1 = function (name_2) {
|
399
|
+
var available = this_1._extensions.some(function (extension) { return extension.name === name_2 && extension.enabled; });
|
400
|
+
if (!available) {
|
401
|
+
throw new Error("Require extension ".concat(name_2, " is not available"));
|
402
|
+
}
|
403
|
+
};
|
404
|
+
var this_1 = this;
|
405
|
+
for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
|
406
|
+
var name_2 = _a[_i];
|
407
|
+
_loop_1(name_2);
|
408
|
+
}
|
409
|
+
}
|
410
|
+
};
|
411
|
+
GLTFLoader.prototype._createRootNode = function () {
|
412
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
413
|
+
this._rootBabylonMesh = new Mesh("__root__", this._babylonScene);
|
414
|
+
this._rootBabylonMesh._parentContainer = this._assetContainer;
|
415
|
+
this._babylonScene._blockEntityCollection = false;
|
416
|
+
this._rootBabylonMesh.setEnabled(false);
|
417
|
+
var rootNode = {
|
418
|
+
_babylonTransformNode: this._rootBabylonMesh,
|
419
|
+
index: -1,
|
420
|
+
};
|
421
|
+
switch (this._parent.coordinateSystemMode) {
|
422
|
+
case GLTFLoaderCoordinateSystemMode.AUTO: {
|
423
|
+
if (!this._babylonScene.useRightHandedSystem) {
|
424
|
+
rootNode.rotation = [0, 1, 0, 0];
|
425
|
+
rootNode.scale = [1, 1, -1];
|
426
|
+
GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
|
427
|
+
}
|
428
|
+
break;
|
429
|
+
}
|
430
|
+
case GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED: {
|
431
|
+
this._babylonScene.useRightHandedSystem = true;
|
432
|
+
break;
|
433
|
+
}
|
434
|
+
default: {
|
435
|
+
throw new Error("Invalid coordinate system mode (".concat(this._parent.coordinateSystemMode, ")"));
|
436
|
+
}
|
437
|
+
}
|
438
|
+
this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
|
439
|
+
return rootNode;
|
440
|
+
};
|
441
|
+
/**
|
442
|
+
* Loads a glTF scene.
|
443
|
+
* @param context The context when loading the asset
|
444
|
+
* @param scene The glTF scene property
|
445
|
+
* @returns A promise that resolves when the load is complete
|
446
|
+
*/
|
447
|
+
GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
|
448
|
+
var _this = this;
|
449
|
+
var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
|
450
|
+
if (extensionPromise) {
|
451
|
+
return extensionPromise;
|
452
|
+
}
|
453
|
+
var promises = new Array();
|
454
|
+
this.logOpen("".concat(context, " ").concat(scene.name || ""));
|
455
|
+
if (scene.nodes) {
|
456
|
+
for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
|
457
|
+
var index = _a[_i];
|
458
|
+
var node = ArrayItem.Get("".concat(context, "/nodes/").concat(index), this._gltf.nodes, index);
|
459
|
+
promises.push(this.loadNodeAsync("/nodes/".concat(node.index), node, function (babylonMesh) {
|
460
|
+
babylonMesh.parent = _this._rootBabylonMesh;
|
461
|
+
}));
|
462
|
+
}
|
463
|
+
}
|
464
|
+
for (var _b = 0, _c = this._postSceneLoadActions; _b < _c.length; _b++) {
|
465
|
+
var action = _c[_b];
|
466
|
+
action();
|
467
|
+
}
|
468
|
+
promises.push(this._loadAnimationsAsync());
|
469
|
+
this.logClose();
|
470
|
+
return Promise.all(promises).then(function () { });
|
471
|
+
};
|
472
|
+
GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
|
473
|
+
if (node._primitiveBabylonMeshes) {
|
474
|
+
for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
|
475
|
+
var babylonMesh = _a[_i];
|
476
|
+
callback(babylonMesh);
|
477
|
+
}
|
478
|
+
}
|
479
|
+
};
|
480
|
+
GLTFLoader.prototype._getGeometries = function () {
|
481
|
+
var geometries = new Array();
|
482
|
+
var nodes = this._gltf.nodes;
|
483
|
+
if (nodes) {
|
484
|
+
for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
|
485
|
+
var node = nodes_1[_i];
|
486
|
+
this._forEachPrimitive(node, function (babylonMesh) {
|
487
|
+
var geometry = babylonMesh.geometry;
|
488
|
+
if (geometry && geometries.indexOf(geometry) === -1) {
|
489
|
+
geometries.push(geometry);
|
490
|
+
}
|
491
|
+
});
|
492
|
+
}
|
493
|
+
}
|
494
|
+
return geometries;
|
495
|
+
};
|
496
|
+
GLTFLoader.prototype._getMeshes = function () {
|
497
|
+
var meshes = new Array();
|
498
|
+
// Root mesh is always first, if available.
|
499
|
+
if (this._rootBabylonMesh) {
|
500
|
+
meshes.push(this._rootBabylonMesh);
|
501
|
+
}
|
502
|
+
var nodes = this._gltf.nodes;
|
503
|
+
if (nodes) {
|
504
|
+
for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
|
505
|
+
var node = nodes_2[_i];
|
506
|
+
this._forEachPrimitive(node, function (babylonMesh) {
|
507
|
+
meshes.push(babylonMesh);
|
508
|
+
});
|
509
|
+
}
|
510
|
+
}
|
511
|
+
return meshes;
|
512
|
+
};
|
513
|
+
GLTFLoader.prototype._getTransformNodes = function () {
|
514
|
+
var transformNodes = new Array();
|
515
|
+
var nodes = this._gltf.nodes;
|
516
|
+
if (nodes) {
|
517
|
+
for (var _i = 0, nodes_3 = nodes; _i < nodes_3.length; _i++) {
|
518
|
+
var node = nodes_3[_i];
|
519
|
+
if (node._babylonTransformNode && node._babylonTransformNode.getClassName() === "TransformNode") {
|
520
|
+
transformNodes.push(node._babylonTransformNode);
|
521
|
+
}
|
522
|
+
if (node._babylonTransformNodeForSkin) {
|
523
|
+
transformNodes.push(node._babylonTransformNodeForSkin);
|
524
|
+
}
|
525
|
+
}
|
526
|
+
}
|
527
|
+
return transformNodes;
|
528
|
+
};
|
529
|
+
GLTFLoader.prototype._getSkeletons = function () {
|
530
|
+
var skeletons = new Array();
|
531
|
+
var skins = this._gltf.skins;
|
532
|
+
if (skins) {
|
533
|
+
for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
|
534
|
+
var skin = skins_1[_i];
|
535
|
+
if (skin._data) {
|
536
|
+
skeletons.push(skin._data.babylonSkeleton);
|
537
|
+
}
|
538
|
+
}
|
539
|
+
}
|
540
|
+
return skeletons;
|
541
|
+
};
|
542
|
+
GLTFLoader.prototype._getAnimationGroups = function () {
|
543
|
+
var animationGroups = new Array();
|
544
|
+
var animations = this._gltf.animations;
|
545
|
+
if (animations) {
|
546
|
+
for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
|
547
|
+
var animation = animations_1[_i];
|
548
|
+
if (animation._babylonAnimationGroup) {
|
549
|
+
animationGroups.push(animation._babylonAnimationGroup);
|
550
|
+
}
|
551
|
+
}
|
552
|
+
}
|
553
|
+
return animationGroups;
|
554
|
+
};
|
555
|
+
GLTFLoader.prototype._startAnimations = function () {
|
556
|
+
switch (this._parent.animationStartMode) {
|
557
|
+
case GLTFLoaderAnimationStartMode.NONE: {
|
558
|
+
// do nothing
|
559
|
+
break;
|
560
|
+
}
|
561
|
+
case GLTFLoaderAnimationStartMode.FIRST: {
|
562
|
+
var babylonAnimationGroups = this._getAnimationGroups();
|
563
|
+
if (babylonAnimationGroups.length !== 0) {
|
564
|
+
babylonAnimationGroups[0].start(true);
|
565
|
+
}
|
566
|
+
break;
|
567
|
+
}
|
568
|
+
case GLTFLoaderAnimationStartMode.ALL: {
|
569
|
+
var babylonAnimationGroups = this._getAnimationGroups();
|
570
|
+
for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
|
571
|
+
var babylonAnimationGroup = babylonAnimationGroups_1[_i];
|
572
|
+
babylonAnimationGroup.start(true);
|
573
|
+
}
|
574
|
+
break;
|
575
|
+
}
|
576
|
+
default: {
|
577
|
+
Logger.Error("Invalid animation start mode (".concat(this._parent.animationStartMode, ")"));
|
578
|
+
return;
|
579
|
+
}
|
580
|
+
}
|
581
|
+
};
|
582
|
+
/**
|
583
|
+
* Loads a glTF node.
|
584
|
+
* @param context The context when loading the asset
|
585
|
+
* @param node The glTF node property
|
586
|
+
* @param assign A function called synchronously after parsing the glTF properties
|
587
|
+
* @returns A promise that resolves with the loaded Babylon mesh when the load is complete
|
588
|
+
*/
|
589
|
+
GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
|
590
|
+
var _this = this;
|
591
|
+
if (assign === void 0) { assign = function () { }; }
|
592
|
+
var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
|
593
|
+
if (extensionPromise) {
|
594
|
+
return extensionPromise;
|
595
|
+
}
|
596
|
+
if (node._babylonTransformNode) {
|
597
|
+
throw new Error("".concat(context, ": Invalid recursive node hierarchy"));
|
598
|
+
}
|
599
|
+
var promises = new Array();
|
600
|
+
this.logOpen("".concat(context, " ").concat(node.name || ""));
|
601
|
+
var loadNode = function (babylonTransformNode) {
|
602
|
+
GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
|
603
|
+
GLTFLoader._LoadTransform(node, babylonTransformNode);
|
604
|
+
if (node.camera != undefined) {
|
605
|
+
var camera = ArrayItem.Get("".concat(context, "/camera"), _this._gltf.cameras, node.camera);
|
606
|
+
promises.push(_this.loadCameraAsync("/cameras/".concat(camera.index), camera, function (babylonCamera) {
|
607
|
+
babylonCamera.parent = babylonTransformNode;
|
608
|
+
}));
|
609
|
+
}
|
610
|
+
if (node.children) {
|
611
|
+
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
|
612
|
+
var index = _a[_i];
|
613
|
+
var childNode = ArrayItem.Get("".concat(context, "/children/").concat(index), _this._gltf.nodes, index);
|
614
|
+
promises.push(_this.loadNodeAsync("/nodes/".concat(childNode.index), childNode, function (childBabylonMesh) {
|
615
|
+
childBabylonMesh.parent = babylonTransformNode;
|
616
|
+
}));
|
617
|
+
}
|
618
|
+
}
|
619
|
+
assign(babylonTransformNode);
|
620
|
+
};
|
621
|
+
if (node.mesh == undefined || node.skin != undefined) {
|
622
|
+
var nodeName = node.name || "node".concat(node.index);
|
623
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
624
|
+
var transformNode = new TransformNode(nodeName, this._babylonScene);
|
625
|
+
transformNode._parentContainer = this._assetContainer;
|
626
|
+
this._babylonScene._blockEntityCollection = false;
|
627
|
+
if (node.mesh == undefined) {
|
628
|
+
node._babylonTransformNode = transformNode;
|
629
|
+
}
|
630
|
+
else {
|
631
|
+
node._babylonTransformNodeForSkin = transformNode;
|
632
|
+
}
|
633
|
+
loadNode(transformNode);
|
634
|
+
}
|
635
|
+
if (node.mesh != undefined) {
|
636
|
+
if (node.skin == undefined) {
|
637
|
+
var mesh = ArrayItem.Get("".concat(context, "/mesh"), this._gltf.meshes, node.mesh);
|
638
|
+
promises.push(this._loadMeshAsync("/meshes/".concat(mesh.index), node, mesh, loadNode));
|
639
|
+
}
|
640
|
+
else {
|
641
|
+
// See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
|
642
|
+
// This code path will place the skinned mesh as a sibling of the skeleton root node without loading the
|
643
|
+
// transform, which effectively ignores the transform of the skinned mesh, as per spec.
|
644
|
+
var mesh = ArrayItem.Get("".concat(context, "/mesh"), this._gltf.meshes, node.mesh);
|
645
|
+
promises.push(this._loadMeshAsync("/meshes/".concat(mesh.index), node, mesh, function (babylonTransformNode) {
|
646
|
+
// Duplicate the metadata from the skin node to the skinned mesh in case any loader extension added metadata.
|
647
|
+
babylonTransformNode.metadata = node._babylonTransformNodeForSkin.metadata;
|
648
|
+
var skin = ArrayItem.Get("".concat(context, "/skin"), _this._gltf.skins, node.skin);
|
649
|
+
promises.push(_this._loadSkinAsync("/skins/".concat(skin.index), node, skin, function (babylonSkeleton) {
|
650
|
+
_this._forEachPrimitive(node, function (babylonMesh) {
|
651
|
+
babylonMesh.skeleton = babylonSkeleton;
|
652
|
+
});
|
653
|
+
// Wait until the scene is loaded to ensure the skeleton root node has been loaded.
|
654
|
+
_this._postSceneLoadActions.push(function () {
|
655
|
+
if (skin.skeleton != undefined) {
|
656
|
+
// Place the skinned mesh node as a sibling of the skeleton root node.
|
657
|
+
var skeletonRootNode = ArrayItem.Get("/skins/".concat(skin.index, "/skeleton"), _this._gltf.nodes, skin.skeleton);
|
658
|
+
babylonTransformNode.parent = skeletonRootNode.parent._babylonTransformNode;
|
659
|
+
}
|
660
|
+
else {
|
661
|
+
babylonTransformNode.parent = _this._rootBabylonMesh;
|
662
|
+
}
|
663
|
+
});
|
664
|
+
}));
|
665
|
+
}));
|
666
|
+
}
|
667
|
+
}
|
668
|
+
this.logClose();
|
669
|
+
return Promise.all(promises).then(function () {
|
670
|
+
_this._forEachPrimitive(node, function (babylonMesh) {
|
671
|
+
if (babylonMesh.geometry && babylonMesh.geometry.useBoundingInfoFromGeometry) {
|
672
|
+
// simply apply the world matrices to the bounding info - the extends are already ok
|
673
|
+
babylonMesh._updateBoundingInfo();
|
674
|
+
}
|
675
|
+
else {
|
676
|
+
babylonMesh.refreshBoundingInfo(true);
|
677
|
+
}
|
678
|
+
});
|
679
|
+
return node._babylonTransformNode;
|
680
|
+
});
|
681
|
+
};
|
682
|
+
GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
|
683
|
+
var primitives = mesh.primitives;
|
684
|
+
if (!primitives || !primitives.length) {
|
685
|
+
throw new Error("".concat(context, ": Primitives are missing"));
|
686
|
+
}
|
687
|
+
if (primitives[0].index == undefined) {
|
688
|
+
ArrayItem.Assign(primitives);
|
689
|
+
}
|
690
|
+
var promises = new Array();
|
691
|
+
this.logOpen("".concat(context, " ").concat(mesh.name || ""));
|
692
|
+
var name = node.name || "node".concat(node.index);
|
693
|
+
if (primitives.length === 1) {
|
694
|
+
var primitive = mesh.primitives[0];
|
695
|
+
promises.push(this._loadMeshPrimitiveAsync("".concat(context, "/primitives/").concat(primitive.index), name, node, mesh, primitive, function (babylonMesh) {
|
696
|
+
node._babylonTransformNode = babylonMesh;
|
697
|
+
node._primitiveBabylonMeshes = [babylonMesh];
|
698
|
+
}));
|
699
|
+
}
|
700
|
+
else {
|
701
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
702
|
+
node._babylonTransformNode = new TransformNode(name, this._babylonScene);
|
703
|
+
node._babylonTransformNode._parentContainer = this._assetContainer;
|
704
|
+
this._babylonScene._blockEntityCollection = false;
|
705
|
+
node._primitiveBabylonMeshes = [];
|
706
|
+
for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
|
707
|
+
var primitive = primitives_1[_i];
|
708
|
+
promises.push(this._loadMeshPrimitiveAsync("".concat(context, "/primitives/").concat(primitive.index), "".concat(name, "_primitive").concat(primitive.index), node, mesh, primitive, function (babylonMesh) {
|
709
|
+
babylonMesh.parent = node._babylonTransformNode;
|
710
|
+
node._primitiveBabylonMeshes.push(babylonMesh);
|
711
|
+
}));
|
712
|
+
}
|
713
|
+
}
|
714
|
+
assign(node._babylonTransformNode);
|
715
|
+
this.logClose();
|
716
|
+
return Promise.all(promises).then(function () {
|
717
|
+
return node._babylonTransformNode;
|
718
|
+
});
|
719
|
+
};
|
720
|
+
/**
|
721
|
+
* @hidden Define this method to modify the default behavior when loading data for mesh primitives.
|
722
|
+
* @param context The context when loading the asset
|
723
|
+
* @param name The mesh name when loading the asset
|
724
|
+
* @param node The glTF node when loading the asset
|
725
|
+
* @param mesh The glTF mesh when loading the asset
|
726
|
+
* @param primitive The glTF mesh primitive property
|
727
|
+
* @param assign A function called synchronously after parsing the glTF properties
|
728
|
+
* @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
|
729
|
+
*/
|
730
|
+
GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
|
731
|
+
var _this = this;
|
732
|
+
var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
|
733
|
+
if (extensionPromise) {
|
734
|
+
return extensionPromise;
|
735
|
+
}
|
736
|
+
this.logOpen("".concat(context));
|
737
|
+
var shouldInstance = this._disableInstancedMesh === 0 && this._parent.createInstances && node.skin == undefined && !mesh.primitives[0].targets;
|
738
|
+
var babylonAbstractMesh;
|
739
|
+
var promise;
|
740
|
+
if (shouldInstance && primitive._instanceData) {
|
741
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
742
|
+
babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
|
743
|
+
babylonAbstractMesh._parentContainer = this._assetContainer;
|
744
|
+
this._babylonScene._blockEntityCollection = false;
|
745
|
+
promise = primitive._instanceData.promise;
|
746
|
+
}
|
747
|
+
else {
|
748
|
+
var promises = new Array();
|
749
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
750
|
+
var babylonMesh_1 = new Mesh(name, this._babylonScene);
|
751
|
+
babylonMesh_1._parentContainer = this._assetContainer;
|
752
|
+
this._babylonScene._blockEntityCollection = false;
|
753
|
+
babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
|
754
|
+
this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
|
755
|
+
promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
|
756
|
+
return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
|
757
|
+
_this._babylonScene._blockEntityCollection = !!_this._assetContainer;
|
758
|
+
babylonGeometry.applyToMesh(babylonMesh_1);
|
759
|
+
babylonGeometry._parentContainer = _this._assetContainer;
|
760
|
+
_this._babylonScene._blockEntityCollection = false;
|
761
|
+
});
|
762
|
+
}));
|
763
|
+
var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
|
764
|
+
if (primitive.material == undefined) {
|
765
|
+
var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
|
766
|
+
if (!babylonMaterial) {
|
767
|
+
babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
|
768
|
+
this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
|
769
|
+
this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
|
770
|
+
}
|
771
|
+
babylonMesh_1.material = babylonMaterial;
|
772
|
+
}
|
773
|
+
else if (!this.parent.skipMaterials) {
|
774
|
+
var material = ArrayItem.Get("".concat(context, "/material"), this._gltf.materials, primitive.material);
|
775
|
+
promises.push(this._loadMaterialAsync("/materials/".concat(material.index), material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
|
776
|
+
babylonMesh_1.material = babylonMaterial;
|
777
|
+
}));
|
778
|
+
}
|
779
|
+
promise = Promise.all(promises);
|
780
|
+
if (shouldInstance) {
|
781
|
+
primitive._instanceData = {
|
782
|
+
babylonSourceMesh: babylonMesh_1,
|
783
|
+
promise: promise,
|
784
|
+
};
|
785
|
+
}
|
786
|
+
babylonAbstractMesh = babylonMesh_1;
|
787
|
+
}
|
788
|
+
GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
|
789
|
+
this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
|
790
|
+
assign(babylonAbstractMesh);
|
791
|
+
this.logClose();
|
792
|
+
return promise.then(function () {
|
793
|
+
return babylonAbstractMesh;
|
794
|
+
});
|
795
|
+
};
|
796
|
+
GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
|
797
|
+
var _this = this;
|
798
|
+
var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
|
799
|
+
if (extensionPromise) {
|
800
|
+
return extensionPromise;
|
801
|
+
}
|
802
|
+
var attributes = primitive.attributes;
|
803
|
+
if (!attributes) {
|
804
|
+
throw new Error("".concat(context, ": Attributes are missing"));
|
805
|
+
}
|
806
|
+
var promises = new Array();
|
807
|
+
var babylonGeometry = new Geometry(babylonMesh.name, this._babylonScene);
|
808
|
+
if (primitive.indices == undefined) {
|
809
|
+
babylonMesh.isUnIndexed = true;
|
810
|
+
}
|
811
|
+
else {
|
812
|
+
var accessor = ArrayItem.Get("".concat(context, "/indices"), this._gltf.accessors, primitive.indices);
|
813
|
+
promises.push(this._loadIndicesAccessorAsync("/accessors/".concat(accessor.index), accessor).then(function (data) {
|
814
|
+
babylonGeometry.setIndices(data);
|
815
|
+
}));
|
816
|
+
}
|
817
|
+
var loadAttribute = function (attribute, kind, callback) {
|
818
|
+
if (attributes[attribute] == undefined) {
|
819
|
+
return;
|
820
|
+
}
|
821
|
+
babylonMesh._delayInfo = babylonMesh._delayInfo || [];
|
822
|
+
if (babylonMesh._delayInfo.indexOf(kind) === -1) {
|
823
|
+
babylonMesh._delayInfo.push(kind);
|
824
|
+
}
|
825
|
+
var accessor = ArrayItem.Get("".concat(context, "/attributes/").concat(attribute), _this._gltf.accessors, attributes[attribute]);
|
826
|
+
promises.push(_this._loadVertexAccessorAsync("/accessors/".concat(accessor.index), accessor, kind).then(function (babylonVertexBuffer) {
|
827
|
+
if (babylonVertexBuffer.getKind() === VertexBuffer.PositionKind && !_this.parent.alwaysComputeBoundingBox && !babylonMesh.skeleton) {
|
828
|
+
var mmin = accessor.min, mmax = accessor.max;
|
829
|
+
if (mmin !== undefined && mmax !== undefined) {
|
830
|
+
if (accessor.normalized && accessor.componentType !== 5126 /* FLOAT */) {
|
831
|
+
var divider = 1;
|
832
|
+
switch (accessor.componentType) {
|
833
|
+
case 5120 /* BYTE */:
|
834
|
+
divider = 127.0;
|
835
|
+
break;
|
836
|
+
case 5121 /* UNSIGNED_BYTE */:
|
837
|
+
divider = 255.0;
|
838
|
+
break;
|
839
|
+
case 5122 /* SHORT */:
|
840
|
+
divider = 32767.0;
|
841
|
+
break;
|
842
|
+
case 5123 /* UNSIGNED_SHORT */:
|
843
|
+
divider = 65535.0;
|
844
|
+
break;
|
845
|
+
}
|
846
|
+
for (var i = 0; i < 3; ++i) {
|
847
|
+
mmin[i] = Math.max(mmin[i] / divider, -1.0);
|
848
|
+
mmax[i] = Math.max(mmax[i] / divider, -1.0);
|
849
|
+
}
|
850
|
+
}
|
851
|
+
var min = TmpVectors.Vector3[0], max = TmpVectors.Vector3[1];
|
852
|
+
min.copyFromFloats.apply(min, mmin);
|
853
|
+
max.copyFromFloats.apply(max, mmax);
|
854
|
+
babylonGeometry._boundingInfo = new BoundingInfo(min, max);
|
855
|
+
babylonGeometry.useBoundingInfoFromGeometry = true;
|
856
|
+
}
|
857
|
+
}
|
858
|
+
babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
|
859
|
+
}));
|
860
|
+
if (kind == VertexBuffer.MatricesIndicesExtraKind) {
|
861
|
+
babylonMesh.numBoneInfluencers = 8;
|
862
|
+
}
|
863
|
+
if (callback) {
|
864
|
+
callback(accessor);
|
865
|
+
}
|
866
|
+
};
|
867
|
+
loadAttribute("POSITION", VertexBuffer.PositionKind);
|
868
|
+
loadAttribute("NORMAL", VertexBuffer.NormalKind);
|
869
|
+
loadAttribute("TANGENT", VertexBuffer.TangentKind);
|
870
|
+
loadAttribute("TEXCOORD_0", VertexBuffer.UVKind);
|
871
|
+
loadAttribute("TEXCOORD_1", VertexBuffer.UV2Kind);
|
872
|
+
loadAttribute("TEXCOORD_2", VertexBuffer.UV3Kind);
|
873
|
+
loadAttribute("TEXCOORD_3", VertexBuffer.UV4Kind);
|
874
|
+
loadAttribute("TEXCOORD_4", VertexBuffer.UV5Kind);
|
875
|
+
loadAttribute("TEXCOORD_5", VertexBuffer.UV6Kind);
|
876
|
+
loadAttribute("JOINTS_0", VertexBuffer.MatricesIndicesKind);
|
877
|
+
loadAttribute("WEIGHTS_0", VertexBuffer.MatricesWeightsKind);
|
878
|
+
loadAttribute("JOINTS_1", VertexBuffer.MatricesIndicesExtraKind);
|
879
|
+
loadAttribute("WEIGHTS_1", VertexBuffer.MatricesWeightsExtraKind);
|
880
|
+
loadAttribute("COLOR_0", VertexBuffer.ColorKind, function (accessor) {
|
881
|
+
if (accessor.type === "VEC4" /* VEC4 */) {
|
882
|
+
babylonMesh.hasVertexAlpha = true;
|
883
|
+
}
|
884
|
+
});
|
885
|
+
return Promise.all(promises).then(function () {
|
886
|
+
return babylonGeometry;
|
887
|
+
});
|
888
|
+
};
|
889
|
+
GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
|
890
|
+
if (!primitive.targets) {
|
891
|
+
return;
|
892
|
+
}
|
893
|
+
if (node._numMorphTargets == undefined) {
|
894
|
+
node._numMorphTargets = primitive.targets.length;
|
895
|
+
}
|
896
|
+
else if (primitive.targets.length !== node._numMorphTargets) {
|
897
|
+
throw new Error("".concat(context, ": Primitives do not have the same number of targets"));
|
898
|
+
}
|
899
|
+
var targetNames = mesh.extras ? mesh.extras.targetNames : null;
|
900
|
+
babylonMesh.morphTargetManager = new MorphTargetManager(babylonMesh.getScene());
|
901
|
+
babylonMesh.morphTargetManager.areUpdatesFrozen = true;
|
902
|
+
for (var index = 0; index < primitive.targets.length; index++) {
|
903
|
+
var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
|
904
|
+
var name_3 = targetNames ? targetNames[index] : "morphTarget".concat(index);
|
905
|
+
babylonMesh.morphTargetManager.addTarget(new MorphTarget(name_3, weight, babylonMesh.getScene()));
|
906
|
+
// TODO: tell the target whether it has positions, normals, tangents
|
907
|
+
}
|
908
|
+
};
|
909
|
+
GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
|
910
|
+
if (!primitive.targets) {
|
911
|
+
return Promise.resolve();
|
912
|
+
}
|
913
|
+
var promises = new Array();
|
914
|
+
var morphTargetManager = babylonMesh.morphTargetManager;
|
915
|
+
for (var index = 0; index < morphTargetManager.numTargets; index++) {
|
916
|
+
var babylonMorphTarget = morphTargetManager.getTarget(index);
|
917
|
+
promises.push(this._loadMorphTargetVertexDataAsync("".concat(context, "/targets/").concat(index), babylonGeometry, primitive.targets[index], babylonMorphTarget));
|
918
|
+
}
|
919
|
+
return Promise.all(promises).then(function () {
|
920
|
+
morphTargetManager.areUpdatesFrozen = false;
|
921
|
+
});
|
922
|
+
};
|
923
|
+
GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
|
924
|
+
var _this = this;
|
925
|
+
var promises = new Array();
|
926
|
+
var loadAttribute = function (attribute, kind, setData) {
|
927
|
+
if (attributes[attribute] == undefined) {
|
928
|
+
return;
|
929
|
+
}
|
930
|
+
var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
|
931
|
+
if (!babylonVertexBuffer) {
|
932
|
+
return;
|
933
|
+
}
|
934
|
+
var accessor = ArrayItem.Get("".concat(context, "/").concat(attribute), _this._gltf.accessors, attributes[attribute]);
|
935
|
+
promises.push(_this._loadFloatAccessorAsync("/accessors/".concat(accessor.index), accessor).then(function (data) {
|
936
|
+
setData(babylonVertexBuffer, data);
|
937
|
+
}));
|
938
|
+
};
|
939
|
+
loadAttribute("POSITION", VertexBuffer.PositionKind, function (babylonVertexBuffer, data) {
|
940
|
+
var positions = new Float32Array(data.length);
|
941
|
+
babylonVertexBuffer.forEach(data.length, function (value, index) {
|
942
|
+
positions[index] = data[index] + value;
|
943
|
+
});
|
944
|
+
babylonMorphTarget.setPositions(positions);
|
945
|
+
});
|
946
|
+
loadAttribute("NORMAL", VertexBuffer.NormalKind, function (babylonVertexBuffer, data) {
|
947
|
+
var normals = new Float32Array(data.length);
|
948
|
+
babylonVertexBuffer.forEach(normals.length, function (value, index) {
|
949
|
+
normals[index] = data[index] + value;
|
950
|
+
});
|
951
|
+
babylonMorphTarget.setNormals(normals);
|
952
|
+
});
|
953
|
+
loadAttribute("TANGENT", VertexBuffer.TangentKind, function (babylonVertexBuffer, data) {
|
954
|
+
var tangents = new Float32Array((data.length / 3) * 4);
|
955
|
+
var dataIndex = 0;
|
956
|
+
babylonVertexBuffer.forEach((data.length / 3) * 4, function (value, index) {
|
957
|
+
// Tangent data for morph targets is stored as xyz delta.
|
958
|
+
// The vertexData.tangent is stored as xyzw.
|
959
|
+
// So we need to skip every fourth vertexData.tangent.
|
960
|
+
if ((index + 1) % 4 !== 0) {
|
961
|
+
tangents[dataIndex] = data[dataIndex] + value;
|
962
|
+
dataIndex++;
|
963
|
+
}
|
964
|
+
});
|
965
|
+
babylonMorphTarget.setTangents(tangents);
|
966
|
+
});
|
967
|
+
return Promise.all(promises).then(function () { });
|
968
|
+
};
|
969
|
+
GLTFLoader._LoadTransform = function (node, babylonNode) {
|
970
|
+
// Ignore the TRS of skinned nodes.
|
971
|
+
// See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
|
972
|
+
if (node.skin != undefined) {
|
973
|
+
return;
|
974
|
+
}
|
975
|
+
var position = Vector3.Zero();
|
976
|
+
var rotation = Quaternion.Identity();
|
977
|
+
var scaling = Vector3.One();
|
978
|
+
if (node.matrix) {
|
979
|
+
var matrix = Matrix.FromArray(node.matrix);
|
980
|
+
matrix.decompose(scaling, rotation, position);
|
981
|
+
}
|
982
|
+
else {
|
983
|
+
if (node.translation) {
|
984
|
+
position = Vector3.FromArray(node.translation);
|
985
|
+
}
|
986
|
+
if (node.rotation) {
|
987
|
+
rotation = Quaternion.FromArray(node.rotation);
|
988
|
+
}
|
989
|
+
if (node.scale) {
|
990
|
+
scaling = Vector3.FromArray(node.scale);
|
991
|
+
}
|
992
|
+
}
|
993
|
+
babylonNode.position = position;
|
994
|
+
babylonNode.rotationQuaternion = rotation;
|
995
|
+
babylonNode.scaling = scaling;
|
996
|
+
};
|
997
|
+
GLTFLoader.prototype._loadSkinAsync = function (context, node, skin, assign) {
|
998
|
+
var _this = this;
|
999
|
+
var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
|
1000
|
+
if (extensionPromise) {
|
1001
|
+
return extensionPromise;
|
1002
|
+
}
|
1003
|
+
if (skin._data) {
|
1004
|
+
assign(skin._data.babylonSkeleton);
|
1005
|
+
return skin._data.promise;
|
1006
|
+
}
|
1007
|
+
var skeletonId = "skeleton".concat(skin.index);
|
1008
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1009
|
+
var babylonSkeleton = new Skeleton(skin.name || skeletonId, skeletonId, this._babylonScene);
|
1010
|
+
babylonSkeleton._parentContainer = this._assetContainer;
|
1011
|
+
this._babylonScene._blockEntityCollection = false;
|
1012
|
+
this._loadBones(context, skin, babylonSkeleton);
|
1013
|
+
var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
|
1014
|
+
_this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
|
1015
|
+
});
|
1016
|
+
skin._data = {
|
1017
|
+
babylonSkeleton: babylonSkeleton,
|
1018
|
+
promise: promise,
|
1019
|
+
};
|
1020
|
+
assign(babylonSkeleton);
|
1021
|
+
return promise;
|
1022
|
+
};
|
1023
|
+
GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
|
1024
|
+
if (skin.skeleton == undefined || this._parent.alwaysComputeSkeletonRootNode) {
|
1025
|
+
var rootNode = this._findSkeletonRootNode("".concat(context, "/joints"), skin.joints);
|
1026
|
+
if (rootNode) {
|
1027
|
+
if (skin.skeleton === undefined) {
|
1028
|
+
skin.skeleton = rootNode.index;
|
1029
|
+
}
|
1030
|
+
else {
|
1031
|
+
var isParent = function (a, b) {
|
1032
|
+
for (; b.parent; b = b.parent) {
|
1033
|
+
if (b.parent === a) {
|
1034
|
+
return true;
|
1035
|
+
}
|
1036
|
+
}
|
1037
|
+
return false;
|
1038
|
+
};
|
1039
|
+
var skeletonNode = ArrayItem.Get("".concat(context, "/skeleton"), this._gltf.nodes, skin.skeleton);
|
1040
|
+
if (skeletonNode !== rootNode && !isParent(skeletonNode, rootNode)) {
|
1041
|
+
Logger.Warn("".concat(context, "/skeleton: Overriding with nearest common ancestor as skeleton node is not a common root"));
|
1042
|
+
skin.skeleton = rootNode.index;
|
1043
|
+
}
|
1044
|
+
}
|
1045
|
+
}
|
1046
|
+
else {
|
1047
|
+
Logger.Warn("".concat(context, ": Failed to find common root"));
|
1048
|
+
}
|
1049
|
+
}
|
1050
|
+
var babylonBones = {};
|
1051
|
+
for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
|
1052
|
+
var index = _a[_i];
|
1053
|
+
var node = ArrayItem.Get("".concat(context, "/joints/").concat(index), this._gltf.nodes, index);
|
1054
|
+
this._loadBone(node, skin, babylonSkeleton, babylonBones);
|
1055
|
+
}
|
1056
|
+
};
|
1057
|
+
GLTFLoader.prototype._findSkeletonRootNode = function (context, joints) {
|
1058
|
+
if (joints.length === 0) {
|
1059
|
+
return null;
|
1060
|
+
}
|
1061
|
+
var paths = {};
|
1062
|
+
for (var _i = 0, joints_1 = joints; _i < joints_1.length; _i++) {
|
1063
|
+
var index = joints_1[_i];
|
1064
|
+
var path = new Array();
|
1065
|
+
var node = ArrayItem.Get("".concat(context, "/").concat(index), this._gltf.nodes, index);
|
1066
|
+
while (node.index !== -1) {
|
1067
|
+
path.unshift(node);
|
1068
|
+
node = node.parent;
|
1069
|
+
}
|
1070
|
+
paths[index] = path;
|
1071
|
+
}
|
1072
|
+
var rootNode = null;
|
1073
|
+
for (var i = 0;; ++i) {
|
1074
|
+
var path = paths[joints[0]];
|
1075
|
+
if (i >= path.length) {
|
1076
|
+
return rootNode;
|
1077
|
+
}
|
1078
|
+
var node = path[i];
|
1079
|
+
for (var j = 1; j < joints.length; ++j) {
|
1080
|
+
path = paths[joints[j]];
|
1081
|
+
if (i >= path.length || node !== path[i]) {
|
1082
|
+
return rootNode;
|
1083
|
+
}
|
1084
|
+
}
|
1085
|
+
rootNode = node;
|
1086
|
+
}
|
1087
|
+
};
|
1088
|
+
GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
|
1089
|
+
var babylonBone = babylonBones[node.index];
|
1090
|
+
if (babylonBone) {
|
1091
|
+
return babylonBone;
|
1092
|
+
}
|
1093
|
+
var parentBabylonBone = null;
|
1094
|
+
if (node.index !== skin.skeleton) {
|
1095
|
+
if (node.parent && node.parent.index !== -1) {
|
1096
|
+
parentBabylonBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
|
1097
|
+
}
|
1098
|
+
else if (skin.skeleton !== undefined) {
|
1099
|
+
Logger.Warn("/skins/".concat(skin.index, "/skeleton: Skeleton node is not a common root"));
|
1100
|
+
}
|
1101
|
+
}
|
1102
|
+
var boneIndex = skin.joints.indexOf(node.index);
|
1103
|
+
babylonBone = new Bone(node.name || "joint".concat(node.index), babylonSkeleton, parentBabylonBone, this._getNodeMatrix(node), null, null, boneIndex);
|
1104
|
+
babylonBones[node.index] = babylonBone;
|
1105
|
+
// Wait until the scene is loaded to ensure the transform nodes are loaded.
|
1106
|
+
this._postSceneLoadActions.push(function () {
|
1107
|
+
// Link the Babylon bone with the corresponding Babylon transform node.
|
1108
|
+
// A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
|
1109
|
+
babylonBone.linkTransformNode(node._babylonTransformNode);
|
1110
|
+
});
|
1111
|
+
return babylonBone;
|
1112
|
+
};
|
1113
|
+
GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
|
1114
|
+
if (skin.inverseBindMatrices == undefined) {
|
1115
|
+
return Promise.resolve(null);
|
1116
|
+
}
|
1117
|
+
var accessor = ArrayItem.Get("".concat(context, "/inverseBindMatrices"), this._gltf.accessors, skin.inverseBindMatrices);
|
1118
|
+
return this._loadFloatAccessorAsync("/accessors/".concat(accessor.index), accessor);
|
1119
|
+
};
|
1120
|
+
GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
|
1121
|
+
for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
|
1122
|
+
var babylonBone = _a[_i];
|
1123
|
+
var baseMatrix = Matrix.Identity();
|
1124
|
+
var boneIndex = babylonBone._index;
|
1125
|
+
if (inverseBindMatricesData && boneIndex !== -1) {
|
1126
|
+
Matrix.FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
|
1127
|
+
baseMatrix.invertToRef(baseMatrix);
|
1128
|
+
}
|
1129
|
+
var babylonParentBone = babylonBone.getParent();
|
1130
|
+
if (babylonParentBone) {
|
1131
|
+
baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
|
1132
|
+
}
|
1133
|
+
babylonBone.updateMatrix(baseMatrix, false, false);
|
1134
|
+
babylonBone._updateDifferenceMatrix(undefined, false);
|
1135
|
+
}
|
1136
|
+
};
|
1137
|
+
GLTFLoader.prototype._getNodeMatrix = function (node) {
|
1138
|
+
return node.matrix
|
1139
|
+
? Matrix.FromArray(node.matrix)
|
1140
|
+
: Matrix.Compose(node.scale ? Vector3.FromArray(node.scale) : Vector3.One(), node.rotation ? Quaternion.FromArray(node.rotation) : Quaternion.Identity(), node.translation ? Vector3.FromArray(node.translation) : Vector3.Zero());
|
1141
|
+
};
|
1142
|
+
/**
|
1143
|
+
* Loads a glTF camera.
|
1144
|
+
* @param context The context when loading the asset
|
1145
|
+
* @param camera The glTF camera property
|
1146
|
+
* @param assign A function called synchronously after parsing the glTF properties
|
1147
|
+
* @returns A promise that resolves with the loaded Babylon camera when the load is complete
|
1148
|
+
*/
|
1149
|
+
GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
|
1150
|
+
if (assign === void 0) { assign = function () { }; }
|
1151
|
+
var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
|
1152
|
+
if (extensionPromise) {
|
1153
|
+
return extensionPromise;
|
1154
|
+
}
|
1155
|
+
var promises = new Array();
|
1156
|
+
this.logOpen("".concat(context, " ").concat(camera.name || ""));
|
1157
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1158
|
+
var babylonCamera = new FreeCamera(camera.name || "camera".concat(camera.index), Vector3.Zero(), this._babylonScene, false);
|
1159
|
+
babylonCamera._parentContainer = this._assetContainer;
|
1160
|
+
this._babylonScene._blockEntityCollection = false;
|
1161
|
+
babylonCamera.ignoreParentScaling = true;
|
1162
|
+
babylonCamera.rotation = new Vector3(0, Math.PI, 0);
|
1163
|
+
switch (camera.type) {
|
1164
|
+
case "perspective" /* PERSPECTIVE */: {
|
1165
|
+
var perspective = camera.perspective;
|
1166
|
+
if (!perspective) {
|
1167
|
+
throw new Error("".concat(context, ": Camera perspective properties are missing"));
|
1168
|
+
}
|
1169
|
+
babylonCamera.fov = perspective.yfov;
|
1170
|
+
babylonCamera.minZ = perspective.znear;
|
1171
|
+
babylonCamera.maxZ = perspective.zfar || 0;
|
1172
|
+
break;
|
1173
|
+
}
|
1174
|
+
case "orthographic" /* ORTHOGRAPHIC */: {
|
1175
|
+
if (!camera.orthographic) {
|
1176
|
+
throw new Error("".concat(context, ": Camera orthographic properties are missing"));
|
1177
|
+
}
|
1178
|
+
babylonCamera.mode = Camera.ORTHOGRAPHIC_CAMERA;
|
1179
|
+
babylonCamera.orthoLeft = -camera.orthographic.xmag;
|
1180
|
+
babylonCamera.orthoRight = camera.orthographic.xmag;
|
1181
|
+
babylonCamera.orthoBottom = -camera.orthographic.ymag;
|
1182
|
+
babylonCamera.orthoTop = camera.orthographic.ymag;
|
1183
|
+
babylonCamera.minZ = camera.orthographic.znear;
|
1184
|
+
babylonCamera.maxZ = camera.orthographic.zfar;
|
1185
|
+
break;
|
1186
|
+
}
|
1187
|
+
default: {
|
1188
|
+
throw new Error("".concat(context, ": Invalid camera type (").concat(camera.type, ")"));
|
1189
|
+
}
|
1190
|
+
}
|
1191
|
+
GLTFLoader.AddPointerMetadata(babylonCamera, context);
|
1192
|
+
this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
|
1193
|
+
assign(babylonCamera);
|
1194
|
+
this.logClose();
|
1195
|
+
return Promise.all(promises).then(function () {
|
1196
|
+
return babylonCamera;
|
1197
|
+
});
|
1198
|
+
};
|
1199
|
+
GLTFLoader.prototype._loadAnimationsAsync = function () {
|
1200
|
+
var animations = this._gltf.animations;
|
1201
|
+
if (!animations) {
|
1202
|
+
return Promise.resolve();
|
1203
|
+
}
|
1204
|
+
var promises = new Array();
|
1205
|
+
for (var index = 0; index < animations.length; index++) {
|
1206
|
+
var animation = animations[index];
|
1207
|
+
promises.push(this.loadAnimationAsync("/animations/".concat(animation.index), animation).then(function (animationGroup) {
|
1208
|
+
// Delete the animation group if it ended up not having any animations in it.
|
1209
|
+
if (animationGroup.targetedAnimations.length === 0) {
|
1210
|
+
animationGroup.dispose();
|
1211
|
+
}
|
1212
|
+
}));
|
1213
|
+
}
|
1214
|
+
return Promise.all(promises).then(function () { });
|
1215
|
+
};
|
1216
|
+
/**
|
1217
|
+
* Loads a glTF animation.
|
1218
|
+
* @param context The context when loading the asset
|
1219
|
+
* @param animation The glTF animation property
|
1220
|
+
* @returns A promise that resolves with the loaded Babylon animation group when the load is complete
|
1221
|
+
*/
|
1222
|
+
GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
|
1223
|
+
var promise = this._extensionsLoadAnimationAsync(context, animation);
|
1224
|
+
if (promise) {
|
1225
|
+
return promise;
|
1226
|
+
}
|
1227
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1228
|
+
var babylonAnimationGroup = new AnimationGroup(animation.name || "animation".concat(animation.index), this._babylonScene);
|
1229
|
+
babylonAnimationGroup._parentContainer = this._assetContainer;
|
1230
|
+
this._babylonScene._blockEntityCollection = false;
|
1231
|
+
animation._babylonAnimationGroup = babylonAnimationGroup;
|
1232
|
+
var promises = new Array();
|
1233
|
+
ArrayItem.Assign(animation.channels);
|
1234
|
+
ArrayItem.Assign(animation.samplers);
|
1235
|
+
for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
|
1236
|
+
var channel = _a[_i];
|
1237
|
+
promises.push(this._loadAnimationChannelAsync("".concat(context, "/channels/").concat(channel.index), context, animation, channel, babylonAnimationGroup));
|
1238
|
+
}
|
1239
|
+
return Promise.all(promises).then(function () {
|
1240
|
+
babylonAnimationGroup.normalize(0);
|
1241
|
+
return babylonAnimationGroup;
|
1242
|
+
});
|
1243
|
+
};
|
1244
|
+
/**
|
1245
|
+
* @hidden Loads a glTF animation channel.
|
1246
|
+
* @param context The context when loading the asset
|
1247
|
+
* @param animationContext The context of the animation when loading the asset
|
1248
|
+
* @param animation The glTF animation property
|
1249
|
+
* @param channel The glTF animation channel property
|
1250
|
+
* @param babylonAnimationGroup The babylon animation group property
|
1251
|
+
* @param animationTargetOverride The babylon animation channel target override property. My be null.
|
1252
|
+
* @returns A void promise when the channel load is complete
|
1253
|
+
*/
|
1254
|
+
GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
|
1255
|
+
var _this = this;
|
1256
|
+
if (animationTargetOverride === void 0) { animationTargetOverride = null; }
|
1257
|
+
if (channel.target.node == undefined) {
|
1258
|
+
return Promise.resolve();
|
1259
|
+
}
|
1260
|
+
var targetNode = ArrayItem.Get("".concat(context, "/target/node"), this._gltf.nodes, channel.target.node);
|
1261
|
+
// Ignore animations that have no animation targets.
|
1262
|
+
if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
|
1263
|
+
(channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
|
1264
|
+
return Promise.resolve();
|
1265
|
+
}
|
1266
|
+
var sampler = ArrayItem.Get("".concat(context, "/sampler"), animation.samplers, channel.sampler);
|
1267
|
+
return this._loadAnimationSamplerAsync("".concat(animationContext, "/samplers/").concat(channel.sampler), sampler).then(function (data) {
|
1268
|
+
var targetPath;
|
1269
|
+
var animationType;
|
1270
|
+
switch (channel.target.path) {
|
1271
|
+
case "translation" /* TRANSLATION */: {
|
1272
|
+
targetPath = "position";
|
1273
|
+
animationType = Animation.ANIMATIONTYPE_VECTOR3;
|
1274
|
+
break;
|
1275
|
+
}
|
1276
|
+
case "rotation" /* ROTATION */: {
|
1277
|
+
targetPath = "rotationQuaternion";
|
1278
|
+
animationType = Animation.ANIMATIONTYPE_QUATERNION;
|
1279
|
+
break;
|
1280
|
+
}
|
1281
|
+
case "scale" /* SCALE */: {
|
1282
|
+
targetPath = "scaling";
|
1283
|
+
animationType = Animation.ANIMATIONTYPE_VECTOR3;
|
1284
|
+
break;
|
1285
|
+
}
|
1286
|
+
case "weights" /* WEIGHTS */: {
|
1287
|
+
targetPath = "influence";
|
1288
|
+
animationType = Animation.ANIMATIONTYPE_FLOAT;
|
1289
|
+
break;
|
1290
|
+
}
|
1291
|
+
default: {
|
1292
|
+
throw new Error("".concat(context, "/target/path: Invalid value (").concat(channel.target.path, ")"));
|
1293
|
+
}
|
1294
|
+
}
|
1295
|
+
var outputBufferOffset = 0;
|
1296
|
+
var getNextOutputValue;
|
1297
|
+
switch (targetPath) {
|
1298
|
+
case "position": {
|
1299
|
+
getNextOutputValue = function (scale) {
|
1300
|
+
var value = Vector3.FromArray(data.output, outputBufferOffset).scaleInPlace(scale);
|
1301
|
+
outputBufferOffset += 3;
|
1302
|
+
return value;
|
1303
|
+
};
|
1304
|
+
break;
|
1305
|
+
}
|
1306
|
+
case "rotationQuaternion": {
|
1307
|
+
getNextOutputValue = function (scale) {
|
1308
|
+
var value = Quaternion.FromArray(data.output, outputBufferOffset).scaleInPlace(scale);
|
1309
|
+
outputBufferOffset += 4;
|
1310
|
+
return value;
|
1311
|
+
};
|
1312
|
+
break;
|
1313
|
+
}
|
1314
|
+
case "scaling": {
|
1315
|
+
getNextOutputValue = function (scale) {
|
1316
|
+
var value = Vector3.FromArray(data.output, outputBufferOffset).scaleInPlace(scale);
|
1317
|
+
outputBufferOffset += 3;
|
1318
|
+
return value;
|
1319
|
+
};
|
1320
|
+
break;
|
1321
|
+
}
|
1322
|
+
case "influence": {
|
1323
|
+
getNextOutputValue = function (scale) {
|
1324
|
+
var value = new Array(targetNode._numMorphTargets);
|
1325
|
+
for (var i = 0; i < targetNode._numMorphTargets; i++) {
|
1326
|
+
value[i] = data.output[outputBufferOffset++] * scale;
|
1327
|
+
}
|
1328
|
+
return value;
|
1329
|
+
};
|
1330
|
+
break;
|
1331
|
+
}
|
1332
|
+
}
|
1333
|
+
var getNextKey;
|
1334
|
+
switch (data.interpolation) {
|
1335
|
+
case "STEP" /* STEP */: {
|
1336
|
+
getNextKey = function (frameIndex) { return ({
|
1337
|
+
frame: data.input[frameIndex] * _this.parent.targetFps,
|
1338
|
+
value: getNextOutputValue(1),
|
1339
|
+
interpolation: AnimationKeyInterpolation.STEP,
|
1340
|
+
}); };
|
1341
|
+
break;
|
1342
|
+
}
|
1343
|
+
case "LINEAR" /* LINEAR */: {
|
1344
|
+
getNextKey = function (frameIndex) { return ({
|
1345
|
+
frame: data.input[frameIndex] * _this.parent.targetFps,
|
1346
|
+
value: getNextOutputValue(1),
|
1347
|
+
}); };
|
1348
|
+
break;
|
1349
|
+
}
|
1350
|
+
case "CUBICSPLINE" /* CUBICSPLINE */: {
|
1351
|
+
var invTargetFps_1 = 1 / _this.parent.targetFps;
|
1352
|
+
getNextKey = function (frameIndex) { return ({
|
1353
|
+
frame: data.input[frameIndex] * _this.parent.targetFps,
|
1354
|
+
inTangent: getNextOutputValue(invTargetFps_1),
|
1355
|
+
value: getNextOutputValue(1),
|
1356
|
+
outTangent: getNextOutputValue(invTargetFps_1),
|
1357
|
+
}); };
|
1358
|
+
break;
|
1359
|
+
}
|
1360
|
+
}
|
1361
|
+
var keys = new Array(data.input.length);
|
1362
|
+
for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
|
1363
|
+
keys[frameIndex] = getNextKey(frameIndex);
|
1364
|
+
}
|
1365
|
+
if (targetPath === "influence") {
|
1366
|
+
var _loop_2 = function (targetIndex) {
|
1367
|
+
var animationName = "".concat(babylonAnimationGroup.name, "_channel").concat(babylonAnimationGroup.targetedAnimations.length);
|
1368
|
+
var babylonAnimation = new Animation(animationName, targetPath, _this.parent.targetFps, animationType);
|
1369
|
+
babylonAnimation.setKeys(keys.map(function (key) { return ({
|
1370
|
+
frame: key.frame,
|
1371
|
+
inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
|
1372
|
+
value: key.value[targetIndex],
|
1373
|
+
outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined,
|
1374
|
+
}); }));
|
1375
|
+
_this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
|
1376
|
+
var babylonMesh = babylonAbstractMesh;
|
1377
|
+
var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
|
1378
|
+
var babylonAnimationClone = babylonAnimation.clone();
|
1379
|
+
morphTarget.animations.push(babylonAnimationClone);
|
1380
|
+
babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
|
1381
|
+
});
|
1382
|
+
};
|
1383
|
+
for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
|
1384
|
+
_loop_2(targetIndex);
|
1385
|
+
}
|
1386
|
+
}
|
1387
|
+
else {
|
1388
|
+
var animationName = "".concat(babylonAnimationGroup.name, "_channel").concat(babylonAnimationGroup.targetedAnimations.length);
|
1389
|
+
var babylonAnimation = new Animation(animationName, targetPath, _this.parent.targetFps, animationType);
|
1390
|
+
babylonAnimation.setKeys(keys);
|
1391
|
+
if (animationTargetOverride != null && animationTargetOverride.animations != null) {
|
1392
|
+
animationTargetOverride.animations.push(babylonAnimation);
|
1393
|
+
babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
|
1394
|
+
}
|
1395
|
+
else {
|
1396
|
+
targetNode._babylonTransformNode.animations.push(babylonAnimation);
|
1397
|
+
babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
|
1398
|
+
}
|
1399
|
+
}
|
1400
|
+
});
|
1401
|
+
};
|
1402
|
+
GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
|
1403
|
+
if (sampler._data) {
|
1404
|
+
return sampler._data;
|
1405
|
+
}
|
1406
|
+
var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
|
1407
|
+
switch (interpolation) {
|
1408
|
+
case "STEP" /* STEP */:
|
1409
|
+
case "LINEAR" /* LINEAR */:
|
1410
|
+
case "CUBICSPLINE" /* CUBICSPLINE */: {
|
1411
|
+
break;
|
1412
|
+
}
|
1413
|
+
default: {
|
1414
|
+
throw new Error("".concat(context, "/interpolation: Invalid value (").concat(sampler.interpolation, ")"));
|
1415
|
+
}
|
1416
|
+
}
|
1417
|
+
var inputAccessor = ArrayItem.Get("".concat(context, "/input"), this._gltf.accessors, sampler.input);
|
1418
|
+
var outputAccessor = ArrayItem.Get("".concat(context, "/output"), this._gltf.accessors, sampler.output);
|
1419
|
+
sampler._data = Promise.all([
|
1420
|
+
this._loadFloatAccessorAsync("/accessors/".concat(inputAccessor.index), inputAccessor),
|
1421
|
+
this._loadFloatAccessorAsync("/accessors/".concat(outputAccessor.index), outputAccessor),
|
1422
|
+
]).then(function (_a) {
|
1423
|
+
var inputData = _a[0], outputData = _a[1];
|
1424
|
+
return {
|
1425
|
+
input: inputData,
|
1426
|
+
interpolation: interpolation,
|
1427
|
+
output: outputData,
|
1428
|
+
};
|
1429
|
+
});
|
1430
|
+
return sampler._data;
|
1431
|
+
};
|
1432
|
+
/**
|
1433
|
+
* Loads a glTF buffer.
|
1434
|
+
* @param context The context when loading the asset
|
1435
|
+
* @param buffer The glTF buffer property
|
1436
|
+
* @param byteOffset The byte offset to use
|
1437
|
+
* @param byteLength The byte length to use
|
1438
|
+
* @returns A promise that resolves with the loaded data when the load is complete
|
1439
|
+
*/
|
1440
|
+
GLTFLoader.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
|
1441
|
+
var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
|
1442
|
+
if (extensionPromise) {
|
1443
|
+
return extensionPromise;
|
1444
|
+
}
|
1445
|
+
if (!buffer._data) {
|
1446
|
+
if (buffer.uri) {
|
1447
|
+
buffer._data = this.loadUriAsync("".concat(context, "/uri"), buffer, buffer.uri);
|
1448
|
+
}
|
1449
|
+
else {
|
1450
|
+
if (!this._bin) {
|
1451
|
+
throw new Error("".concat(context, ": Uri is missing or the binary glTF is missing its binary chunk"));
|
1452
|
+
}
|
1453
|
+
buffer._data = this._bin.readAsync(0, buffer.byteLength);
|
1454
|
+
}
|
1455
|
+
}
|
1456
|
+
return buffer._data.then(function (data) {
|
1457
|
+
try {
|
1458
|
+
return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
|
1459
|
+
}
|
1460
|
+
catch (e) {
|
1461
|
+
throw new Error("".concat(context, ": ").concat(e.message));
|
1462
|
+
}
|
1463
|
+
});
|
1464
|
+
};
|
1465
|
+
/**
|
1466
|
+
* Loads a glTF buffer view.
|
1467
|
+
* @param context The context when loading the asset
|
1468
|
+
* @param bufferView The glTF buffer view property
|
1469
|
+
* @returns A promise that resolves with the loaded data when the load is complete
|
1470
|
+
*/
|
1471
|
+
GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
|
1472
|
+
var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
|
1473
|
+
if (extensionPromise) {
|
1474
|
+
return extensionPromise;
|
1475
|
+
}
|
1476
|
+
if (bufferView._data) {
|
1477
|
+
return bufferView._data;
|
1478
|
+
}
|
1479
|
+
var buffer = ArrayItem.Get("".concat(context, "/buffer"), this._gltf.buffers, bufferView.buffer);
|
1480
|
+
bufferView._data = this.loadBufferAsync("/buffers/".concat(buffer.index), buffer, bufferView.byteOffset || 0, bufferView.byteLength);
|
1481
|
+
return bufferView._data;
|
1482
|
+
};
|
1483
|
+
GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
|
1484
|
+
var _this = this;
|
1485
|
+
if (accessor._data) {
|
1486
|
+
return accessor._data;
|
1487
|
+
}
|
1488
|
+
var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
|
1489
|
+
var byteStride = numComponents * VertexBuffer.GetTypeByteLength(accessor.componentType);
|
1490
|
+
var length = numComponents * accessor.count;
|
1491
|
+
if (accessor.bufferView == undefined) {
|
1492
|
+
accessor._data = Promise.resolve(new constructor(length));
|
1493
|
+
}
|
1494
|
+
else {
|
1495
|
+
var bufferView_1 = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, accessor.bufferView);
|
1496
|
+
accessor._data = this.loadBufferViewAsync("/bufferViews/".concat(bufferView_1.index), bufferView_1).then(function (data) {
|
1497
|
+
if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized && (!bufferView_1.byteStride || bufferView_1.byteStride === byteStride)) {
|
1498
|
+
return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
|
1499
|
+
}
|
1500
|
+
else {
|
1501
|
+
var typedArray_1 = new constructor(length);
|
1502
|
+
VertexBuffer.ForEach(data, accessor.byteOffset || 0, bufferView_1.byteStride || byteStride, numComponents, accessor.componentType, typedArray_1.length, accessor.normalized || false, function (value, index) {
|
1503
|
+
typedArray_1[index] = value;
|
1504
|
+
});
|
1505
|
+
return typedArray_1;
|
1506
|
+
}
|
1507
|
+
});
|
1508
|
+
}
|
1509
|
+
if (accessor.sparse) {
|
1510
|
+
var sparse_1 = accessor.sparse;
|
1511
|
+
accessor._data = accessor._data.then(function (data) {
|
1512
|
+
var typedArray = data;
|
1513
|
+
var indicesBufferView = ArrayItem.Get("".concat(context, "/sparse/indices/bufferView"), _this._gltf.bufferViews, sparse_1.indices.bufferView);
|
1514
|
+
var valuesBufferView = ArrayItem.Get("".concat(context, "/sparse/values/bufferView"), _this._gltf.bufferViews, sparse_1.values.bufferView);
|
1515
|
+
return Promise.all([
|
1516
|
+
_this.loadBufferViewAsync("/bufferViews/".concat(indicesBufferView.index), indicesBufferView),
|
1517
|
+
_this.loadBufferViewAsync("/bufferViews/".concat(valuesBufferView.index), valuesBufferView),
|
1518
|
+
]).then(function (_a) {
|
1519
|
+
var indicesData = _a[0], valuesData = _a[1];
|
1520
|
+
var indices = GLTFLoader._GetTypedArray("".concat(context, "/sparse/indices"), sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
|
1521
|
+
var sparseLength = numComponents * sparse_1.count;
|
1522
|
+
var values;
|
1523
|
+
if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
|
1524
|
+
values = GLTFLoader._GetTypedArray("".concat(context, "/sparse/values"), accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
|
1525
|
+
}
|
1526
|
+
else {
|
1527
|
+
var sparseData = GLTFLoader._GetTypedArray("".concat(context, "/sparse/values"), accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
|
1528
|
+
values = new constructor(sparseLength);
|
1529
|
+
VertexBuffer.ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
|
1530
|
+
values[index] = value;
|
1531
|
+
});
|
1532
|
+
}
|
1533
|
+
var valuesIndex = 0;
|
1534
|
+
for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
|
1535
|
+
var dataIndex = indices[indicesIndex] * numComponents;
|
1536
|
+
for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
|
1537
|
+
typedArray[dataIndex++] = values[valuesIndex++];
|
1538
|
+
}
|
1539
|
+
}
|
1540
|
+
return typedArray;
|
1541
|
+
});
|
1542
|
+
});
|
1543
|
+
}
|
1544
|
+
return accessor._data;
|
1545
|
+
};
|
1546
|
+
/**
|
1547
|
+
* @param context
|
1548
|
+
* @param accessor
|
1549
|
+
* @hidden
|
1550
|
+
*/
|
1551
|
+
GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
|
1552
|
+
return this._loadAccessorAsync(context, accessor, Float32Array);
|
1553
|
+
};
|
1554
|
+
GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
|
1555
|
+
if (accessor.type !== "SCALAR" /* SCALAR */) {
|
1556
|
+
throw new Error("".concat(context, "/type: Invalid value ").concat(accessor.type));
|
1557
|
+
}
|
1558
|
+
if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
|
1559
|
+
accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
|
1560
|
+
accessor.componentType !== 5125 /* UNSIGNED_INT */) {
|
1561
|
+
throw new Error("".concat(context, "/componentType: Invalid value ").concat(accessor.componentType));
|
1562
|
+
}
|
1563
|
+
if (accessor._data) {
|
1564
|
+
return accessor._data;
|
1565
|
+
}
|
1566
|
+
if (accessor.sparse) {
|
1567
|
+
var constructor = GLTFLoader._GetTypedArrayConstructor("".concat(context, "/componentType"), accessor.componentType);
|
1568
|
+
accessor._data = this._loadAccessorAsync(context, accessor, constructor);
|
1569
|
+
}
|
1570
|
+
else {
|
1571
|
+
var bufferView = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, accessor.bufferView);
|
1572
|
+
accessor._data = this.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView).then(function (data) {
|
1573
|
+
return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
|
1574
|
+
});
|
1575
|
+
}
|
1576
|
+
return accessor._data;
|
1577
|
+
};
|
1578
|
+
GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView) {
|
1579
|
+
var _this = this;
|
1580
|
+
if (bufferView._babylonBuffer) {
|
1581
|
+
return bufferView._babylonBuffer;
|
1582
|
+
}
|
1583
|
+
bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView).then(function (data) {
|
1584
|
+
return new Buffer(_this._babylonScene.getEngine(), data, false);
|
1585
|
+
});
|
1586
|
+
return bufferView._babylonBuffer;
|
1587
|
+
};
|
1588
|
+
GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
|
1589
|
+
var _this = this;
|
1590
|
+
var _a;
|
1591
|
+
if ((_a = accessor._babylonVertexBuffer) === null || _a === void 0 ? void 0 : _a[kind]) {
|
1592
|
+
return accessor._babylonVertexBuffer[kind];
|
1593
|
+
}
|
1594
|
+
if (!accessor._babylonVertexBuffer) {
|
1595
|
+
accessor._babylonVertexBuffer = {};
|
1596
|
+
}
|
1597
|
+
if (accessor.sparse) {
|
1598
|
+
accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
|
1599
|
+
return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
|
1600
|
+
});
|
1601
|
+
}
|
1602
|
+
// Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
|
1603
|
+
// This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
|
1604
|
+
else if (kind === VertexBuffer.MatricesIndicesKind || kind === VertexBuffer.MatricesIndicesExtraKind) {
|
1605
|
+
accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
|
1606
|
+
return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
|
1607
|
+
});
|
1608
|
+
}
|
1609
|
+
else {
|
1610
|
+
var bufferView_2 = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, accessor.bufferView);
|
1611
|
+
accessor._babylonVertexBuffer[kind] = this._loadVertexBufferViewAsync(bufferView_2).then(function (babylonBuffer) {
|
1612
|
+
var size = GLTFLoader._GetNumComponents(context, accessor.type);
|
1613
|
+
return new VertexBuffer(_this._babylonScene.getEngine(), babylonBuffer, kind, false, false, bufferView_2.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true, 1, true);
|
1614
|
+
});
|
1615
|
+
}
|
1616
|
+
return accessor._babylonVertexBuffer[kind];
|
1617
|
+
};
|
1618
|
+
GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
|
1619
|
+
if (!(babylonMaterial instanceof PBRMaterial)) {
|
1620
|
+
throw new Error("".concat(context, ": Material type not supported"));
|
1621
|
+
}
|
1622
|
+
var promises = new Array();
|
1623
|
+
if (properties) {
|
1624
|
+
if (properties.baseColorFactor) {
|
1625
|
+
babylonMaterial.albedoColor = Color3.FromArray(properties.baseColorFactor);
|
1626
|
+
babylonMaterial.alpha = properties.baseColorFactor[3];
|
1627
|
+
}
|
1628
|
+
else {
|
1629
|
+
babylonMaterial.albedoColor = Color3.White();
|
1630
|
+
}
|
1631
|
+
babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
|
1632
|
+
babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
|
1633
|
+
if (properties.baseColorTexture) {
|
1634
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/baseColorTexture"), properties.baseColorTexture, function (texture) {
|
1635
|
+
texture.name = "".concat(babylonMaterial.name, " (Base Color)");
|
1636
|
+
babylonMaterial.albedoTexture = texture;
|
1637
|
+
}));
|
1638
|
+
}
|
1639
|
+
if (properties.metallicRoughnessTexture) {
|
1640
|
+
properties.metallicRoughnessTexture.nonColorData = true;
|
1641
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/metallicRoughnessTexture"), properties.metallicRoughnessTexture, function (texture) {
|
1642
|
+
texture.name = "".concat(babylonMaterial.name, " (Metallic Roughness)");
|
1643
|
+
babylonMaterial.metallicTexture = texture;
|
1644
|
+
}));
|
1645
|
+
babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
|
1646
|
+
babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
|
1647
|
+
babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
|
1648
|
+
}
|
1649
|
+
}
|
1650
|
+
return Promise.all(promises).then(function () { });
|
1651
|
+
};
|
1652
|
+
/**
|
1653
|
+
* @param context
|
1654
|
+
* @param material
|
1655
|
+
* @param babylonMesh
|
1656
|
+
* @param babylonDrawMode
|
1657
|
+
* @param assign
|
1658
|
+
* @hidden
|
1659
|
+
*/
|
1660
|
+
GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
|
1661
|
+
if (assign === void 0) { assign = function () { }; }
|
1662
|
+
var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
|
1663
|
+
if (extensionPromise) {
|
1664
|
+
return extensionPromise;
|
1665
|
+
}
|
1666
|
+
material._data = material._data || {};
|
1667
|
+
var babylonData = material._data[babylonDrawMode];
|
1668
|
+
if (!babylonData) {
|
1669
|
+
this.logOpen("".concat(context, " ").concat(material.name || ""));
|
1670
|
+
var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
|
1671
|
+
babylonData = {
|
1672
|
+
babylonMaterial: babylonMaterial,
|
1673
|
+
babylonMeshes: [],
|
1674
|
+
promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial),
|
1675
|
+
};
|
1676
|
+
material._data[babylonDrawMode] = babylonData;
|
1677
|
+
GLTFLoader.AddPointerMetadata(babylonMaterial, context);
|
1678
|
+
this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
|
1679
|
+
this.logClose();
|
1680
|
+
}
|
1681
|
+
if (babylonMesh) {
|
1682
|
+
babylonData.babylonMeshes.push(babylonMesh);
|
1683
|
+
babylonMesh.onDisposeObservable.addOnce(function () {
|
1684
|
+
var index = babylonData.babylonMeshes.indexOf(babylonMesh);
|
1685
|
+
if (index !== -1) {
|
1686
|
+
babylonData.babylonMeshes.splice(index, 1);
|
1687
|
+
}
|
1688
|
+
});
|
1689
|
+
}
|
1690
|
+
assign(babylonData.babylonMaterial);
|
1691
|
+
return babylonData.promise.then(function () {
|
1692
|
+
return babylonData.babylonMaterial;
|
1693
|
+
});
|
1694
|
+
};
|
1695
|
+
GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
|
1696
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1697
|
+
var babylonMaterial = new PBRMaterial(name, this._babylonScene);
|
1698
|
+
babylonMaterial._parentContainer = this._assetContainer;
|
1699
|
+
this._babylonScene._blockEntityCollection = false;
|
1700
|
+
// Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
|
1701
|
+
babylonMaterial.fillMode = babylonDrawMode;
|
1702
|
+
babylonMaterial.enableSpecularAntiAliasing = true;
|
1703
|
+
babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
|
1704
|
+
babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
|
1705
|
+
babylonMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_OPAQUE;
|
1706
|
+
babylonMaterial.metallic = 1;
|
1707
|
+
babylonMaterial.roughness = 1;
|
1708
|
+
return babylonMaterial;
|
1709
|
+
};
|
1710
|
+
/**
|
1711
|
+
* Creates a Babylon material from a glTF material.
|
1712
|
+
* @param context The context when loading the asset
|
1713
|
+
* @param material The glTF material property
|
1714
|
+
* @param babylonDrawMode The draw mode for the Babylon material
|
1715
|
+
* @returns The Babylon material
|
1716
|
+
*/
|
1717
|
+
GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
|
1718
|
+
var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
|
1719
|
+
if (extensionPromise) {
|
1720
|
+
return extensionPromise;
|
1721
|
+
}
|
1722
|
+
var name = material.name || "material".concat(material.index);
|
1723
|
+
var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
|
1724
|
+
return babylonMaterial;
|
1725
|
+
};
|
1726
|
+
/**
|
1727
|
+
* Loads properties from a glTF material into a Babylon material.
|
1728
|
+
* @param context The context when loading the asset
|
1729
|
+
* @param material The glTF material property
|
1730
|
+
* @param babylonMaterial The Babylon material
|
1731
|
+
* @returns A promise that resolves when the load is complete
|
1732
|
+
*/
|
1733
|
+
GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
|
1734
|
+
var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
|
1735
|
+
if (extensionPromise) {
|
1736
|
+
return extensionPromise;
|
1737
|
+
}
|
1738
|
+
var promises = new Array();
|
1739
|
+
promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
|
1740
|
+
if (material.pbrMetallicRoughness) {
|
1741
|
+
promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync("".concat(context, "/pbrMetallicRoughness"), material.pbrMetallicRoughness, babylonMaterial));
|
1742
|
+
}
|
1743
|
+
this.loadMaterialAlphaProperties(context, material, babylonMaterial);
|
1744
|
+
return Promise.all(promises).then(function () { });
|
1745
|
+
};
|
1746
|
+
/**
|
1747
|
+
* Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
|
1748
|
+
* @param context The context when loading the asset
|
1749
|
+
* @param material The glTF material property
|
1750
|
+
* @param babylonMaterial The Babylon material
|
1751
|
+
* @returns A promise that resolves when the load is complete
|
1752
|
+
*/
|
1753
|
+
GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
|
1754
|
+
if (!(babylonMaterial instanceof PBRMaterial)) {
|
1755
|
+
throw new Error("".concat(context, ": Material type not supported"));
|
1756
|
+
}
|
1757
|
+
var promises = new Array();
|
1758
|
+
babylonMaterial.emissiveColor = material.emissiveFactor ? Color3.FromArray(material.emissiveFactor) : new Color3(0, 0, 0);
|
1759
|
+
if (material.doubleSided) {
|
1760
|
+
babylonMaterial.backFaceCulling = false;
|
1761
|
+
babylonMaterial.twoSidedLighting = true;
|
1762
|
+
}
|
1763
|
+
if (material.normalTexture) {
|
1764
|
+
material.normalTexture.nonColorData = true;
|
1765
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/normalTexture"), material.normalTexture, function (texture) {
|
1766
|
+
texture.name = "".concat(babylonMaterial.name, " (Normal)");
|
1767
|
+
babylonMaterial.bumpTexture = texture;
|
1768
|
+
}));
|
1769
|
+
babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
|
1770
|
+
babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
|
1771
|
+
if (material.normalTexture.scale != undefined) {
|
1772
|
+
babylonMaterial.bumpTexture.level = material.normalTexture.scale;
|
1773
|
+
}
|
1774
|
+
babylonMaterial.forceIrradianceInFragment = true;
|
1775
|
+
}
|
1776
|
+
if (material.occlusionTexture) {
|
1777
|
+
material.occlusionTexture.nonColorData = true;
|
1778
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/occlusionTexture"), material.occlusionTexture, function (texture) {
|
1779
|
+
texture.name = "".concat(babylonMaterial.name, " (Occlusion)");
|
1780
|
+
babylonMaterial.ambientTexture = texture;
|
1781
|
+
}));
|
1782
|
+
babylonMaterial.useAmbientInGrayScale = true;
|
1783
|
+
if (material.occlusionTexture.strength != undefined) {
|
1784
|
+
babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
|
1785
|
+
}
|
1786
|
+
}
|
1787
|
+
if (material.emissiveTexture) {
|
1788
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/emissiveTexture"), material.emissiveTexture, function (texture) {
|
1789
|
+
texture.name = "".concat(babylonMaterial.name, " (Emissive)");
|
1790
|
+
babylonMaterial.emissiveTexture = texture;
|
1791
|
+
}));
|
1792
|
+
}
|
1793
|
+
return Promise.all(promises).then(function () { });
|
1794
|
+
};
|
1795
|
+
/**
|
1796
|
+
* Loads the alpha properties from a glTF material into a Babylon material.
|
1797
|
+
* Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
|
1798
|
+
* @param context The context when loading the asset
|
1799
|
+
* @param material The glTF material property
|
1800
|
+
* @param babylonMaterial The Babylon material
|
1801
|
+
*/
|
1802
|
+
GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
|
1803
|
+
if (!(babylonMaterial instanceof PBRMaterial)) {
|
1804
|
+
throw new Error("".concat(context, ": Material type not supported"));
|
1805
|
+
}
|
1806
|
+
var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
|
1807
|
+
switch (alphaMode) {
|
1808
|
+
case "OPAQUE" /* OPAQUE */: {
|
1809
|
+
babylonMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_OPAQUE;
|
1810
|
+
break;
|
1811
|
+
}
|
1812
|
+
case "MASK" /* MASK */: {
|
1813
|
+
babylonMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_ALPHATEST;
|
1814
|
+
babylonMaterial.alphaCutOff = material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff;
|
1815
|
+
if (babylonMaterial.albedoTexture) {
|
1816
|
+
babylonMaterial.albedoTexture.hasAlpha = true;
|
1817
|
+
}
|
1818
|
+
break;
|
1819
|
+
}
|
1820
|
+
case "BLEND" /* BLEND */: {
|
1821
|
+
babylonMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_ALPHABLEND;
|
1822
|
+
if (babylonMaterial.albedoTexture) {
|
1823
|
+
babylonMaterial.albedoTexture.hasAlpha = true;
|
1824
|
+
babylonMaterial.useAlphaFromAlbedoTexture = true;
|
1825
|
+
}
|
1826
|
+
break;
|
1827
|
+
}
|
1828
|
+
default: {
|
1829
|
+
throw new Error("".concat(context, "/alphaMode: Invalid value (").concat(material.alphaMode, ")"));
|
1830
|
+
}
|
1831
|
+
}
|
1832
|
+
};
|
1833
|
+
/**
|
1834
|
+
* Loads a glTF texture info.
|
1835
|
+
* @param context The context when loading the asset
|
1836
|
+
* @param textureInfo The glTF texture info property
|
1837
|
+
* @param assign A function called synchronously after parsing the glTF properties
|
1838
|
+
* @returns A promise that resolves with the loaded Babylon texture when the load is complete
|
1839
|
+
*/
|
1840
|
+
GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
|
1841
|
+
var _this = this;
|
1842
|
+
if (assign === void 0) { assign = function () { }; }
|
1843
|
+
var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
|
1844
|
+
if (extensionPromise) {
|
1845
|
+
return extensionPromise;
|
1846
|
+
}
|
1847
|
+
this.logOpen("".concat(context));
|
1848
|
+
if (textureInfo.texCoord >= 6) {
|
1849
|
+
throw new Error("".concat(context, "/texCoord: Invalid value (").concat(textureInfo.texCoord, ")"));
|
1850
|
+
}
|
1851
|
+
var texture = ArrayItem.Get("".concat(context, "/index"), this._gltf.textures, textureInfo.index);
|
1852
|
+
texture._textureInfo = textureInfo;
|
1853
|
+
var promise = this._loadTextureAsync("/textures/".concat(textureInfo.index), texture, function (babylonTexture) {
|
1854
|
+
babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
|
1855
|
+
GLTFLoader.AddPointerMetadata(babylonTexture, context);
|
1856
|
+
_this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
|
1857
|
+
assign(babylonTexture);
|
1858
|
+
});
|
1859
|
+
this.logClose();
|
1860
|
+
return promise;
|
1861
|
+
};
|
1862
|
+
/**
|
1863
|
+
* @param context
|
1864
|
+
* @param texture
|
1865
|
+
* @param assign
|
1866
|
+
* @hidden
|
1867
|
+
*/
|
1868
|
+
GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
|
1869
|
+
if (assign === void 0) { assign = function () { }; }
|
1870
|
+
var extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
|
1871
|
+
if (extensionPromise) {
|
1872
|
+
return extensionPromise;
|
1873
|
+
}
|
1874
|
+
this.logOpen("".concat(context, " ").concat(texture.name || ""));
|
1875
|
+
var sampler = texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get("".concat(context, "/sampler"), this._gltf.samplers, texture.sampler);
|
1876
|
+
var image = ArrayItem.Get("".concat(context, "/source"), this._gltf.images, texture.source);
|
1877
|
+
var promise = this._createTextureAsync(context, sampler, image, assign, undefined, !texture._textureInfo.nonColorData);
|
1878
|
+
this.logClose();
|
1879
|
+
return promise;
|
1880
|
+
};
|
1881
|
+
/**
|
1882
|
+
* @param context
|
1883
|
+
* @param sampler
|
1884
|
+
* @param image
|
1885
|
+
* @param assign
|
1886
|
+
* @param textureLoaderOptions
|
1887
|
+
* @param useSRGBBuffer
|
1888
|
+
* @hidden
|
1889
|
+
*/
|
1890
|
+
GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign, textureLoaderOptions, useSRGBBuffer) {
|
1891
|
+
var _this = this;
|
1892
|
+
if (assign === void 0) { assign = function () { }; }
|
1893
|
+
var samplerData = this._loadSampler("/samplers/".concat(sampler.index), sampler);
|
1894
|
+
var promises = new Array();
|
1895
|
+
var deferred = new Deferred();
|
1896
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1897
|
+
var textureCreationOptions = {
|
1898
|
+
noMipmap: samplerData.noMipMaps,
|
1899
|
+
invertY: false,
|
1900
|
+
samplingMode: samplerData.samplingMode,
|
1901
|
+
onLoad: function () {
|
1902
|
+
if (!_this._disposed) {
|
1903
|
+
deferred.resolve();
|
1904
|
+
}
|
1905
|
+
},
|
1906
|
+
onError: function (message, exception) {
|
1907
|
+
if (!_this._disposed) {
|
1908
|
+
deferred.reject(new Error("".concat(context, ": ").concat(exception && exception.message ? exception.message : message || "Failed to load texture")));
|
1909
|
+
}
|
1910
|
+
},
|
1911
|
+
mimeType: image.mimeType,
|
1912
|
+
loaderOptions: textureLoaderOptions,
|
1913
|
+
useSRGBBuffer: !!useSRGBBuffer && this._parent.useSRGBBuffers,
|
1914
|
+
};
|
1915
|
+
var babylonTexture = new Texture(null, this._babylonScene, textureCreationOptions);
|
1916
|
+
babylonTexture._parentContainer = this._assetContainer;
|
1917
|
+
this._babylonScene._blockEntityCollection = false;
|
1918
|
+
promises.push(deferred.promise);
|
1919
|
+
promises.push(this.loadImageAsync("/images/".concat(image.index), image).then(function (data) {
|
1920
|
+
var name = image.uri || "".concat(_this._fileName, "#image").concat(image.index);
|
1921
|
+
var dataUrl = "data:".concat(_this._uniqueRootUrl).concat(name);
|
1922
|
+
babylonTexture.updateURL(dataUrl, data);
|
1923
|
+
}));
|
1924
|
+
babylonTexture.wrapU = samplerData.wrapU;
|
1925
|
+
babylonTexture.wrapV = samplerData.wrapV;
|
1926
|
+
assign(babylonTexture);
|
1927
|
+
return Promise.all(promises).then(function () {
|
1928
|
+
return babylonTexture;
|
1929
|
+
});
|
1930
|
+
};
|
1931
|
+
GLTFLoader.prototype._loadSampler = function (context, sampler) {
|
1932
|
+
if (!sampler._data) {
|
1933
|
+
sampler._data = {
|
1934
|
+
noMipMaps: sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */,
|
1935
|
+
samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
|
1936
|
+
wrapU: GLTFLoader._GetTextureWrapMode("".concat(context, "/wrapS"), sampler.wrapS),
|
1937
|
+
wrapV: GLTFLoader._GetTextureWrapMode("".concat(context, "/wrapT"), sampler.wrapT),
|
1938
|
+
};
|
1939
|
+
}
|
1940
|
+
return sampler._data;
|
1941
|
+
};
|
1942
|
+
/**
|
1943
|
+
* Loads a glTF image.
|
1944
|
+
* @param context The context when loading the asset
|
1945
|
+
* @param image The glTF image property
|
1946
|
+
* @returns A promise that resolves with the loaded data when the load is complete
|
1947
|
+
*/
|
1948
|
+
GLTFLoader.prototype.loadImageAsync = function (context, image) {
|
1949
|
+
if (!image._data) {
|
1950
|
+
this.logOpen("".concat(context, " ").concat(image.name || ""));
|
1951
|
+
if (image.uri) {
|
1952
|
+
image._data = this.loadUriAsync("".concat(context, "/uri"), image, image.uri);
|
1953
|
+
}
|
1954
|
+
else {
|
1955
|
+
var bufferView = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, image.bufferView);
|
1956
|
+
image._data = this.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView);
|
1957
|
+
}
|
1958
|
+
this.logClose();
|
1959
|
+
}
|
1960
|
+
return image._data;
|
1961
|
+
};
|
1962
|
+
/**
|
1963
|
+
* Loads a glTF uri.
|
1964
|
+
* @param context The context when loading the asset
|
1965
|
+
* @param property The glTF property associated with the uri
|
1966
|
+
* @param uri The base64 or relative uri
|
1967
|
+
* @returns A promise that resolves with the loaded data when the load is complete
|
1968
|
+
*/
|
1969
|
+
GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
|
1970
|
+
var _this = this;
|
1971
|
+
var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
|
1972
|
+
if (extensionPromise) {
|
1973
|
+
return extensionPromise;
|
1974
|
+
}
|
1975
|
+
if (!GLTFLoader._ValidateUri(uri)) {
|
1976
|
+
throw new Error("".concat(context, ": '").concat(uri, "' is invalid"));
|
1977
|
+
}
|
1978
|
+
if (IsBase64DataUrl(uri)) {
|
1979
|
+
var data = new Uint8Array(DecodeBase64UrlToBinary(uri));
|
1980
|
+
this.log("".concat(context, ": Decoded ").concat(uri.substr(0, 64), "... (").concat(data.length, " bytes)"));
|
1981
|
+
return Promise.resolve(data);
|
1982
|
+
}
|
1983
|
+
this.log("".concat(context, ": Loading ").concat(uri));
|
1984
|
+
return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
|
1985
|
+
return new Promise(function (resolve, reject) {
|
1986
|
+
_this._parent._loadFile(_this._babylonScene, url, function (data) {
|
1987
|
+
if (!_this._disposed) {
|
1988
|
+
_this.log("".concat(context, ": Loaded ").concat(uri, " (").concat(data.byteLength, " bytes)"));
|
1989
|
+
resolve(new Uint8Array(data));
|
1990
|
+
}
|
1991
|
+
}, true, function (request) {
|
1992
|
+
reject(new LoadFileError("".concat(context, ": Failed to load '").concat(uri, "'").concat(request ? ": " + request.status + " " + request.statusText : ""), request));
|
1993
|
+
});
|
1994
|
+
});
|
1995
|
+
});
|
1996
|
+
};
|
1997
|
+
/**
|
1998
|
+
* Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
|
1999
|
+
* @param babylonObject the Babylon object with metadata
|
2000
|
+
* @param babylonObject.metadata
|
2001
|
+
* @param pointer the JSON pointer
|
2002
|
+
*/
|
2003
|
+
GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
|
2004
|
+
var metadata = (babylonObject.metadata = babylonObject.metadata || {});
|
2005
|
+
var gltf = (metadata.gltf = metadata.gltf || {});
|
2006
|
+
var pointers = (gltf.pointers = gltf.pointers || []);
|
2007
|
+
pointers.push(pointer);
|
2008
|
+
};
|
2009
|
+
GLTFLoader._GetTextureWrapMode = function (context, mode) {
|
2010
|
+
// Set defaults if undefined
|
2011
|
+
mode = mode == undefined ? 10497 /* REPEAT */ : mode;
|
2012
|
+
switch (mode) {
|
2013
|
+
case 33071 /* CLAMP_TO_EDGE */:
|
2014
|
+
return Texture.CLAMP_ADDRESSMODE;
|
2015
|
+
case 33648 /* MIRRORED_REPEAT */:
|
2016
|
+
return Texture.MIRROR_ADDRESSMODE;
|
2017
|
+
case 10497 /* REPEAT */:
|
2018
|
+
return Texture.WRAP_ADDRESSMODE;
|
2019
|
+
default:
|
2020
|
+
Logger.Warn("".concat(context, ": Invalid value (").concat(mode, ")"));
|
2021
|
+
return Texture.WRAP_ADDRESSMODE;
|
2022
|
+
}
|
2023
|
+
};
|
2024
|
+
GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
|
2025
|
+
// Set defaults if undefined
|
2026
|
+
var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
|
2027
|
+
var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
|
2028
|
+
if (magFilter === 9729 /* LINEAR */) {
|
2029
|
+
switch (minFilter) {
|
2030
|
+
case 9728 /* NEAREST */:
|
2031
|
+
return Texture.LINEAR_NEAREST;
|
2032
|
+
case 9729 /* LINEAR */:
|
2033
|
+
return Texture.LINEAR_LINEAR;
|
2034
|
+
case 9984 /* NEAREST_MIPMAP_NEAREST */:
|
2035
|
+
return Texture.LINEAR_NEAREST_MIPNEAREST;
|
2036
|
+
case 9985 /* LINEAR_MIPMAP_NEAREST */:
|
2037
|
+
return Texture.LINEAR_LINEAR_MIPNEAREST;
|
2038
|
+
case 9986 /* NEAREST_MIPMAP_LINEAR */:
|
2039
|
+
return Texture.LINEAR_NEAREST_MIPLINEAR;
|
2040
|
+
case 9987 /* LINEAR_MIPMAP_LINEAR */:
|
2041
|
+
return Texture.LINEAR_LINEAR_MIPLINEAR;
|
2042
|
+
default:
|
2043
|
+
Logger.Warn("".concat(context, "/minFilter: Invalid value (").concat(minFilter, ")"));
|
2044
|
+
return Texture.LINEAR_LINEAR_MIPLINEAR;
|
2045
|
+
}
|
2046
|
+
}
|
2047
|
+
else {
|
2048
|
+
if (magFilter !== 9728 /* NEAREST */) {
|
2049
|
+
Logger.Warn("".concat(context, "/magFilter: Invalid value (").concat(magFilter, ")"));
|
2050
|
+
}
|
2051
|
+
switch (minFilter) {
|
2052
|
+
case 9728 /* NEAREST */:
|
2053
|
+
return Texture.NEAREST_NEAREST;
|
2054
|
+
case 9729 /* LINEAR */:
|
2055
|
+
return Texture.NEAREST_LINEAR;
|
2056
|
+
case 9984 /* NEAREST_MIPMAP_NEAREST */:
|
2057
|
+
return Texture.NEAREST_NEAREST_MIPNEAREST;
|
2058
|
+
case 9985 /* LINEAR_MIPMAP_NEAREST */:
|
2059
|
+
return Texture.NEAREST_LINEAR_MIPNEAREST;
|
2060
|
+
case 9986 /* NEAREST_MIPMAP_LINEAR */:
|
2061
|
+
return Texture.NEAREST_NEAREST_MIPLINEAR;
|
2062
|
+
case 9987 /* LINEAR_MIPMAP_LINEAR */:
|
2063
|
+
return Texture.NEAREST_LINEAR_MIPLINEAR;
|
2064
|
+
default:
|
2065
|
+
Logger.Warn("".concat(context, "/minFilter: Invalid value (").concat(minFilter, ")"));
|
2066
|
+
return Texture.NEAREST_NEAREST_MIPNEAREST;
|
2067
|
+
}
|
2068
|
+
}
|
2069
|
+
};
|
2070
|
+
GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
|
2071
|
+
switch (componentType) {
|
2072
|
+
case 5120 /* BYTE */:
|
2073
|
+
return Int8Array;
|
2074
|
+
case 5121 /* UNSIGNED_BYTE */:
|
2075
|
+
return Uint8Array;
|
2076
|
+
case 5122 /* SHORT */:
|
2077
|
+
return Int16Array;
|
2078
|
+
case 5123 /* UNSIGNED_SHORT */:
|
2079
|
+
return Uint16Array;
|
2080
|
+
case 5125 /* UNSIGNED_INT */:
|
2081
|
+
return Uint32Array;
|
2082
|
+
case 5126 /* FLOAT */:
|
2083
|
+
return Float32Array;
|
2084
|
+
default:
|
2085
|
+
throw new Error("".concat(context, ": Invalid component type ").concat(componentType));
|
2086
|
+
}
|
2087
|
+
};
|
2088
|
+
GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
|
2089
|
+
var buffer = bufferView.buffer;
|
2090
|
+
byteOffset = bufferView.byteOffset + (byteOffset || 0);
|
2091
|
+
var constructor = GLTFLoader._GetTypedArrayConstructor("".concat(context, "/componentType"), componentType);
|
2092
|
+
var componentTypeLength = VertexBuffer.GetTypeByteLength(componentType);
|
2093
|
+
if (byteOffset % componentTypeLength !== 0) {
|
2094
|
+
// HACK: Copy the buffer if byte offset is not a multiple of component type byte length.
|
2095
|
+
Logger.Warn("".concat(context, ": Copying buffer as byte offset (").concat(byteOffset, ") is not a multiple of component type byte length (").concat(componentTypeLength, ")"));
|
2096
|
+
return new constructor(buffer.slice(byteOffset, byteOffset + length * componentTypeLength), 0);
|
2097
|
+
}
|
2098
|
+
return new constructor(buffer, byteOffset, length);
|
2099
|
+
};
|
2100
|
+
GLTFLoader._GetNumComponents = function (context, type) {
|
2101
|
+
switch (type) {
|
2102
|
+
case "SCALAR":
|
2103
|
+
return 1;
|
2104
|
+
case "VEC2":
|
2105
|
+
return 2;
|
2106
|
+
case "VEC3":
|
2107
|
+
return 3;
|
2108
|
+
case "VEC4":
|
2109
|
+
return 4;
|
2110
|
+
case "MAT2":
|
2111
|
+
return 4;
|
2112
|
+
case "MAT3":
|
2113
|
+
return 9;
|
2114
|
+
case "MAT4":
|
2115
|
+
return 16;
|
2116
|
+
}
|
2117
|
+
throw new Error("".concat(context, ": Invalid type (").concat(type, ")"));
|
2118
|
+
};
|
2119
|
+
GLTFLoader._ValidateUri = function (uri) {
|
2120
|
+
return Tools.IsBase64(uri) || uri.indexOf("..") === -1;
|
2121
|
+
};
|
2122
|
+
/**
|
2123
|
+
* @param context
|
2124
|
+
* @param mode
|
2125
|
+
* @hidden
|
2126
|
+
*/
|
2127
|
+
GLTFLoader._GetDrawMode = function (context, mode) {
|
2128
|
+
if (mode == undefined) {
|
2129
|
+
mode = 4 /* TRIANGLES */;
|
2130
|
+
}
|
2131
|
+
switch (mode) {
|
2132
|
+
case 0 /* POINTS */:
|
2133
|
+
return Material.PointListDrawMode;
|
2134
|
+
case 1 /* LINES */:
|
2135
|
+
return Material.LineListDrawMode;
|
2136
|
+
case 2 /* LINE_LOOP */:
|
2137
|
+
return Material.LineLoopDrawMode;
|
2138
|
+
case 3 /* LINE_STRIP */:
|
2139
|
+
return Material.LineStripDrawMode;
|
2140
|
+
case 4 /* TRIANGLES */:
|
2141
|
+
return Material.TriangleFillMode;
|
2142
|
+
case 5 /* TRIANGLE_STRIP */:
|
2143
|
+
return Material.TriangleStripDrawMode;
|
2144
|
+
case 6 /* TRIANGLE_FAN */:
|
2145
|
+
return Material.TriangleFanDrawMode;
|
2146
|
+
}
|
2147
|
+
throw new Error("".concat(context, ": Invalid mesh primitive mode (").concat(mode, ")"));
|
2148
|
+
};
|
2149
|
+
GLTFLoader.prototype._compileMaterialsAsync = function () {
|
2150
|
+
var _this = this;
|
2151
|
+
this._parent._startPerformanceCounter("Compile materials");
|
2152
|
+
var promises = new Array();
|
2153
|
+
if (this._gltf.materials) {
|
2154
|
+
for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
|
2155
|
+
var material = _a[_i];
|
2156
|
+
if (material._data) {
|
2157
|
+
for (var babylonDrawMode in material._data) {
|
2158
|
+
var babylonData = material._data[babylonDrawMode];
|
2159
|
+
for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
|
2160
|
+
var babylonMesh = _c[_b];
|
2161
|
+
// Ensure nonUniformScaling is set if necessary.
|
2162
|
+
babylonMesh.computeWorldMatrix(true);
|
2163
|
+
var babylonMaterial = babylonData.babylonMaterial;
|
2164
|
+
promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
|
2165
|
+
promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
|
2166
|
+
if (this._parent.useClipPlane) {
|
2167
|
+
promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
|
2168
|
+
promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
|
2169
|
+
}
|
2170
|
+
}
|
2171
|
+
}
|
2172
|
+
}
|
2173
|
+
}
|
2174
|
+
}
|
2175
|
+
return Promise.all(promises).then(function () {
|
2176
|
+
_this._parent._endPerformanceCounter("Compile materials");
|
2177
|
+
});
|
2178
|
+
};
|
2179
|
+
GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
|
2180
|
+
var _this = this;
|
2181
|
+
this._parent._startPerformanceCounter("Compile shadow generators");
|
2182
|
+
var promises = new Array();
|
2183
|
+
var lights = this._babylonScene.lights;
|
2184
|
+
for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
|
2185
|
+
var light = lights_1[_i];
|
2186
|
+
var generator = light.getShadowGenerator();
|
2187
|
+
if (generator) {
|
2188
|
+
promises.push(generator.forceCompilationAsync());
|
2189
|
+
}
|
2190
|
+
}
|
2191
|
+
return Promise.all(promises).then(function () {
|
2192
|
+
_this._parent._endPerformanceCounter("Compile shadow generators");
|
2193
|
+
});
|
2194
|
+
};
|
2195
|
+
GLTFLoader.prototype._forEachExtensions = function (action) {
|
2196
|
+
for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
|
2197
|
+
var extension = _a[_i];
|
2198
|
+
if (extension.enabled) {
|
2199
|
+
action(extension);
|
2200
|
+
}
|
2201
|
+
}
|
2202
|
+
};
|
2203
|
+
GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
|
2204
|
+
for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
|
2205
|
+
var extension = _a[_i];
|
2206
|
+
if (extension.enabled) {
|
2207
|
+
var id = "".concat(extension.name, ".").concat(functionName);
|
2208
|
+
var loaderProperty = property;
|
2209
|
+
loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
|
2210
|
+
var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
|
2211
|
+
if (!activeLoaderExtensionFunctions[id]) {
|
2212
|
+
activeLoaderExtensionFunctions[id] = true;
|
2213
|
+
try {
|
2214
|
+
var result = actionAsync(extension);
|
2215
|
+
if (result) {
|
2216
|
+
return result;
|
2217
|
+
}
|
2218
|
+
}
|
2219
|
+
finally {
|
2220
|
+
delete activeLoaderExtensionFunctions[id];
|
2221
|
+
}
|
2222
|
+
}
|
2223
|
+
}
|
2224
|
+
}
|
2225
|
+
return null;
|
2226
|
+
};
|
2227
|
+
GLTFLoader.prototype._extensionsOnLoading = function () {
|
2228
|
+
this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
|
2229
|
+
};
|
2230
|
+
GLTFLoader.prototype._extensionsOnReady = function () {
|
2231
|
+
this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
|
2232
|
+
};
|
2233
|
+
GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
|
2234
|
+
return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
|
2235
|
+
};
|
2236
|
+
GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
|
2237
|
+
return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
|
2238
|
+
};
|
2239
|
+
GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
|
2240
|
+
return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
|
2241
|
+
};
|
2242
|
+
GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
|
2243
|
+
return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
|
2244
|
+
};
|
2245
|
+
GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
|
2246
|
+
return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
|
2247
|
+
};
|
2248
|
+
GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
|
2249
|
+
return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
|
2250
|
+
};
|
2251
|
+
GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
|
2252
|
+
return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
|
2253
|
+
};
|
2254
|
+
GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
|
2255
|
+
return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
|
2256
|
+
};
|
2257
|
+
GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
|
2258
|
+
return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
|
2259
|
+
};
|
2260
|
+
GLTFLoader.prototype._extensionsLoadTextureAsync = function (context, texture, assign) {
|
2261
|
+
return this._applyExtensions(texture, "loadTexture", function (extension) { return extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign); });
|
2262
|
+
};
|
2263
|
+
GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
|
2264
|
+
return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
|
2265
|
+
};
|
2266
|
+
GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
|
2267
|
+
return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
|
2268
|
+
};
|
2269
|
+
GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
|
2270
|
+
return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
|
2271
|
+
};
|
2272
|
+
GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
|
2273
|
+
return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
|
2274
|
+
};
|
2275
|
+
GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
|
2276
|
+
return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
|
2277
|
+
};
|
2278
|
+
/**
|
2279
|
+
* Helper method called by a loader extension to load an glTF extension.
|
2280
|
+
* @param context The context when loading the asset
|
2281
|
+
* @param property The glTF property to load the extension from
|
2282
|
+
* @param extensionName The name of the extension to load
|
2283
|
+
* @param actionAsync The action to run
|
2284
|
+
* @returns The promise returned by actionAsync or null if the extension does not exist
|
2285
|
+
*/
|
2286
|
+
GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
|
2287
|
+
if (!property.extensions) {
|
2288
|
+
return null;
|
2289
|
+
}
|
2290
|
+
var extensions = property.extensions;
|
2291
|
+
var extension = extensions[extensionName];
|
2292
|
+
if (!extension) {
|
2293
|
+
return null;
|
2294
|
+
}
|
2295
|
+
return actionAsync("".concat(context, "/extensions/").concat(extensionName), extension);
|
2296
|
+
};
|
2297
|
+
/**
|
2298
|
+
* Helper method called by a loader extension to load a glTF extra.
|
2299
|
+
* @param context The context when loading the asset
|
2300
|
+
* @param property The glTF property to load the extra from
|
2301
|
+
* @param extensionName The name of the extension to load
|
2302
|
+
* @param actionAsync The action to run
|
2303
|
+
* @returns The promise returned by actionAsync or null if the extra does not exist
|
2304
|
+
*/
|
2305
|
+
GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
|
2306
|
+
if (!property.extras) {
|
2307
|
+
return null;
|
2308
|
+
}
|
2309
|
+
var extras = property.extras;
|
2310
|
+
var extra = extras[extensionName];
|
2311
|
+
if (!extra) {
|
2312
|
+
return null;
|
2313
|
+
}
|
2314
|
+
return actionAsync("".concat(context, "/extras/").concat(extensionName), extra);
|
2315
|
+
};
|
2316
|
+
/**
|
2317
|
+
* Checks for presence of an extension.
|
2318
|
+
* @param name The name of the extension to check
|
2319
|
+
* @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
|
2320
|
+
*/
|
2321
|
+
GLTFLoader.prototype.isExtensionUsed = function (name) {
|
2322
|
+
return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
|
2323
|
+
};
|
2324
|
+
/**
|
2325
|
+
* Increments the indentation level and logs a message.
|
2326
|
+
* @param message The message to log
|
2327
|
+
*/
|
2328
|
+
GLTFLoader.prototype.logOpen = function (message) {
|
2329
|
+
this._parent._logOpen(message);
|
2330
|
+
};
|
2331
|
+
/**
|
2332
|
+
* Decrements the indentation level.
|
2333
|
+
*/
|
2334
|
+
GLTFLoader.prototype.logClose = function () {
|
2335
|
+
this._parent._logClose();
|
2336
|
+
};
|
2337
|
+
/**
|
2338
|
+
* Logs a message
|
2339
|
+
* @param message The message to log
|
2340
|
+
*/
|
2341
|
+
GLTFLoader.prototype.log = function (message) {
|
2342
|
+
this._parent._log(message);
|
2343
|
+
};
|
2344
|
+
/**
|
2345
|
+
* Starts a performance counter.
|
2346
|
+
* @param counterName The name of the performance counter
|
2347
|
+
*/
|
2348
|
+
GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
|
2349
|
+
this._parent._startPerformanceCounter(counterName);
|
2350
|
+
};
|
2351
|
+
/**
|
2352
|
+
* Ends a performance counter.
|
2353
|
+
* @param counterName The name of the performance counter
|
2354
|
+
*/
|
2355
|
+
GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
|
2356
|
+
this._parent._endPerformanceCounter(counterName);
|
2357
|
+
};
|
2358
|
+
GLTFLoader._RegisteredExtensions = {};
|
2359
|
+
/**
|
2360
|
+
* The default glTF sampler.
|
2361
|
+
*/
|
2362
|
+
GLTFLoader.DefaultSampler = { index: -1 };
|
2363
|
+
return GLTFLoader;
|
2364
|
+
}());
|
2365
|
+
export { GLTFLoader };
|
2366
|
+
GLTFFileLoader._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
|
2267
2367
|
//# sourceMappingURL=glTFLoader.js.map
|