@babylonjs/loaders 5.0.0-beta.1 → 5.0.0-beta.12
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/mtlFileLoader.js +12 -2
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.js +2 -2
- package/OBJ/objFileLoader.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +8 -8
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +1 -0
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +5 -4
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +2 -2
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.js +2 -2
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +27 -7
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +7 -7
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +5 -5
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +5 -5
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.js +5 -5
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +2 -2
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +2 -2
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +3 -3
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.js +6 -6
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js +2 -2
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +2 -2
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +13 -13
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +0 -1
- package/glTF/2.0/Extensions/MSFT_lod.js +17 -54
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +4 -2
- package/glTF/2.0/glTFLoader.js +289 -206
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +0 -3
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +11 -2
- package/glTF/glTFFileLoader.js +35 -29
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.js +1 -1
- package/glTF/glTFValidation.js.map +1 -1
- package/package.json +3 -3
package/glTF/2.0/glTFLoader.js
CHANGED
@@ -39,7 +39,7 @@ var ArrayItem = /** @class */ (function () {
|
|
39
39
|
*/
|
40
40
|
ArrayItem.Get = function (context, array, index) {
|
41
41
|
if (!array || index == undefined || !array[index]) {
|
42
|
-
throw new Error(context
|
42
|
+
throw new Error("".concat(context, ": Failed to find index (").concat(index, ")"));
|
43
43
|
}
|
44
44
|
return array[index];
|
45
45
|
};
|
@@ -71,10 +71,15 @@ var GLTFLoader = /** @class */ (function () {
|
|
71
71
|
this._babylonLights = [];
|
72
72
|
/** @hidden */
|
73
73
|
this._disableInstancedMesh = 0;
|
74
|
-
this._disposed = false;
|
75
74
|
this._extensions = new Array();
|
75
|
+
this._disposed = false;
|
76
|
+
this._rootUrl = null;
|
77
|
+
this._fileName = null;
|
78
|
+
this._uniqueRootUrl = null;
|
79
|
+
this._bin = null;
|
76
80
|
this._rootBabylonMesh = null;
|
77
81
|
this._defaultBabylonMaterialData = {};
|
82
|
+
this._postSceneLoadActions = new Array();
|
78
83
|
this._parent = parent;
|
79
84
|
}
|
80
85
|
/**
|
@@ -84,7 +89,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
84
89
|
*/
|
85
90
|
GLTFLoader.RegisterExtension = function (name, factory) {
|
86
91
|
if (GLTFLoader.UnregisterExtension(name)) {
|
87
|
-
Logger.Warn("Extension with the name '"
|
92
|
+
Logger.Warn("Extension with the name '".concat(name, "' already exists"));
|
88
93
|
}
|
89
94
|
GLTFLoader._RegisteredExtensions[name] = {
|
90
95
|
factory: factory
|
@@ -107,6 +112,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
107
112
|
* The object that represents the glTF JSON.
|
108
113
|
*/
|
109
114
|
get: function () {
|
115
|
+
if (!this._gltf) {
|
116
|
+
throw new Error("glTF JSON is not available");
|
117
|
+
}
|
110
118
|
return this._gltf;
|
111
119
|
},
|
112
120
|
enumerable: false,
|
@@ -137,6 +145,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
137
145
|
* The Babylon scene when loading the asset.
|
138
146
|
*/
|
139
147
|
get: function () {
|
148
|
+
if (!this._babylonScene) {
|
149
|
+
throw new Error("Scene is not available");
|
150
|
+
}
|
140
151
|
return this._babylonScene;
|
141
152
|
},
|
142
153
|
enumerable: false,
|
@@ -159,14 +170,14 @@ var GLTFLoader = /** @class */ (function () {
|
|
159
170
|
}
|
160
171
|
this._disposed = true;
|
161
172
|
this._completePromises.length = 0;
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
this._gltf = null;
|
168
|
-
this._babylonScene = null;
|
173
|
+
this._extensions.forEach(function (extension) { return extension.dispose && extension.dispose(); });
|
174
|
+
this._extensions.length = 0;
|
175
|
+
this._gltf = null; // TODO
|
176
|
+
this._bin = null;
|
177
|
+
this._babylonScene = null; // TODO
|
169
178
|
this._rootBabylonMesh = null;
|
179
|
+
this._defaultBabylonMaterialData = {};
|
180
|
+
this._postSceneLoadActions.length = 0;
|
170
181
|
this._parent.dispose();
|
171
182
|
};
|
172
183
|
/** @hidden */
|
@@ -192,7 +203,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
192
203
|
nodes = names.map(function (name) {
|
193
204
|
var node = nodeMap_1[name];
|
194
205
|
if (node === undefined) {
|
195
|
-
throw new Error("Failed to find node '"
|
206
|
+
throw new Error("Failed to find node '".concat(name, "'"));
|
196
207
|
}
|
197
208
|
return node;
|
198
209
|
});
|
@@ -224,12 +235,12 @@ var GLTFLoader = /** @class */ (function () {
|
|
224
235
|
var _this = this;
|
225
236
|
return Promise.resolve().then(function () {
|
226
237
|
_this._rootUrl = rootUrl;
|
227
|
-
_this._uniqueRootUrl = (!StringTools.StartsWith(rootUrl, "file:") && fileName) ? rootUrl : ""
|
238
|
+
_this._uniqueRootUrl = (!StringTools.StartsWith(rootUrl, "file:") && fileName) ? rootUrl : "".concat(rootUrl).concat(Date.now(), "/");
|
228
239
|
_this._fileName = fileName;
|
229
240
|
_this._loadExtensions();
|
230
241
|
_this._checkExtensions();
|
231
|
-
var loadingToReadyCounterName = GLTFLoaderState[GLTFLoaderState.LOADING]
|
232
|
-
var loadingToCompleteCounterName = GLTFLoaderState[GLTFLoaderState.LOADING]
|
242
|
+
var loadingToReadyCounterName = "".concat(GLTFLoaderState[GLTFLoaderState.LOADING], " => ").concat(GLTFLoaderState[GLTFLoaderState.READY]);
|
243
|
+
var loadingToCompleteCounterName = "".concat(GLTFLoaderState[GLTFLoaderState.LOADING], " => ").concat(GLTFLoaderState[GLTFLoaderState.COMPLETE]);
|
233
244
|
_this._parent._startPerformanceCounter(loadingToReadyCounterName);
|
234
245
|
_this._parent._startPerformanceCounter(loadingToCompleteCounterName);
|
235
246
|
_this._parent._setState(GLTFLoaderState.LOADING);
|
@@ -243,7 +254,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
243
254
|
}
|
244
255
|
else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
|
245
256
|
var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
|
246
|
-
promises.push(_this.loadSceneAsync("/scenes/"
|
257
|
+
promises.push(_this.loadSceneAsync("/scenes/".concat(scene.index), scene));
|
247
258
|
}
|
248
259
|
if (_this.parent.loadAllMaterials && _this._gltf.materials) {
|
249
260
|
for (var m = 0; m < _this._gltf.materials.length; ++m) {
|
@@ -306,7 +317,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
306
317
|
if (buffers && buffers[0] && !buffers[0].uri) {
|
307
318
|
var binaryBuffer = buffers[0];
|
308
319
|
if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
|
309
|
-
Logger.Warn("Binary buffer length ("
|
320
|
+
Logger.Warn("Binary buffer length (".concat(binaryBuffer.byteLength, ") from JSON does not match chunk length (").concat(data.bin.byteLength, ")"));
|
310
321
|
}
|
311
322
|
this._bin = data.bin;
|
312
323
|
}
|
@@ -349,10 +360,10 @@ var GLTFLoader = /** @class */ (function () {
|
|
349
360
|
}
|
350
361
|
};
|
351
362
|
GLTFLoader.prototype._loadExtensions = function () {
|
352
|
-
for (var
|
353
|
-
var extension = GLTFLoader._RegisteredExtensions[
|
354
|
-
if (extension.name !==
|
355
|
-
Logger.Warn("The name of the glTF loader extension instance does not match the registered name: "
|
363
|
+
for (var name_1 in GLTFLoader._RegisteredExtensions) {
|
364
|
+
var extension = GLTFLoader._RegisteredExtensions[name_1].factory(this);
|
365
|
+
if (extension.name !== name_1) {
|
366
|
+
Logger.Warn("The name of the glTF loader extension instance does not match the registered name: ".concat(extension.name, " !== ").concat(name_1));
|
356
367
|
}
|
357
368
|
this._extensions.push(extension);
|
358
369
|
this._parent.onExtensionLoadedObservable.notifyObservers(extension);
|
@@ -362,16 +373,16 @@ var GLTFLoader = /** @class */ (function () {
|
|
362
373
|
};
|
363
374
|
GLTFLoader.prototype._checkExtensions = function () {
|
364
375
|
if (this._gltf.extensionsRequired) {
|
365
|
-
var _loop_1 = function (
|
366
|
-
var available = this_1._extensions.some(function (extension) { return extension.name ===
|
376
|
+
var _loop_1 = function (name_2) {
|
377
|
+
var available = this_1._extensions.some(function (extension) { return extension.name === name_2 && extension.enabled; });
|
367
378
|
if (!available) {
|
368
|
-
throw new Error("Require extension "
|
379
|
+
throw new Error("Require extension ".concat(name_2, " is not available"));
|
369
380
|
}
|
370
381
|
};
|
371
382
|
var this_1 = this;
|
372
383
|
for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
|
373
|
-
var
|
374
|
-
_loop_1(
|
384
|
+
var name_2 = _a[_i];
|
385
|
+
_loop_1(name_2);
|
375
386
|
}
|
376
387
|
}
|
377
388
|
};
|
@@ -399,7 +410,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
399
410
|
break;
|
400
411
|
}
|
401
412
|
default: {
|
402
|
-
throw new Error("Invalid coordinate system mode ("
|
413
|
+
throw new Error("Invalid coordinate system mode (".concat(this._parent.coordinateSystemMode, ")"));
|
403
414
|
}
|
404
415
|
}
|
405
416
|
this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
|
@@ -418,28 +429,19 @@ var GLTFLoader = /** @class */ (function () {
|
|
418
429
|
return extensionPromise;
|
419
430
|
}
|
420
431
|
var promises = new Array();
|
421
|
-
this.logOpen(context
|
432
|
+
this.logOpen("".concat(context, " ").concat(scene.name || ""));
|
422
433
|
if (scene.nodes) {
|
423
434
|
for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
|
424
435
|
var index = _a[_i];
|
425
|
-
var node = ArrayItem.Get(context
|
426
|
-
promises.push(this.loadNodeAsync("/nodes/"
|
436
|
+
var node = ArrayItem.Get("".concat(context, "/nodes/").concat(index), this._gltf.nodes, index);
|
437
|
+
promises.push(this.loadNodeAsync("/nodes/".concat(node.index), node, function (babylonMesh) {
|
427
438
|
babylonMesh.parent = _this._rootBabylonMesh;
|
428
439
|
}));
|
429
440
|
}
|
430
441
|
}
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
|
435
|
-
var node = _c[_b];
|
436
|
-
if (node._babylonTransformNode && node._babylonBones) {
|
437
|
-
for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
|
438
|
-
var babylonBone = _e[_d];
|
439
|
-
babylonBone.linkTransformNode(node._babylonTransformNode);
|
440
|
-
}
|
441
|
-
}
|
442
|
-
}
|
442
|
+
for (var _b = 0, _c = this._postSceneLoadActions; _b < _c.length; _b++) {
|
443
|
+
var action = _c[_b];
|
444
|
+
action();
|
443
445
|
}
|
444
446
|
promises.push(this._loadAnimationsAsync());
|
445
447
|
this.logClose();
|
@@ -547,7 +549,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
547
549
|
break;
|
548
550
|
}
|
549
551
|
default: {
|
550
|
-
Logger.Error("Invalid animation start mode ("
|
552
|
+
Logger.Error("Invalid animation start mode (".concat(this._parent.animationStartMode, ")"));
|
551
553
|
return;
|
552
554
|
}
|
553
555
|
}
|
@@ -567,41 +569,69 @@ var GLTFLoader = /** @class */ (function () {
|
|
567
569
|
return extensionPromise;
|
568
570
|
}
|
569
571
|
if (node._babylonTransformNode) {
|
570
|
-
throw new Error(context
|
572
|
+
throw new Error("".concat(context, ": Invalid recursive node hierarchy"));
|
571
573
|
}
|
572
574
|
var promises = new Array();
|
573
|
-
this.logOpen(context
|
575
|
+
this.logOpen("".concat(context, " ").concat(node.name || ""));
|
574
576
|
var loadNode = function (babylonTransformNode) {
|
575
577
|
GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
|
576
578
|
GLTFLoader._LoadTransform(node, babylonTransformNode);
|
577
579
|
if (node.camera != undefined) {
|
578
|
-
var camera = ArrayItem.Get(context
|
579
|
-
promises.push(_this.loadCameraAsync("/cameras/"
|
580
|
+
var camera = ArrayItem.Get("".concat(context, "/camera"), _this._gltf.cameras, node.camera);
|
581
|
+
promises.push(_this.loadCameraAsync("/cameras/".concat(camera.index), camera, function (babylonCamera) {
|
580
582
|
babylonCamera.parent = babylonTransformNode;
|
581
583
|
}));
|
582
584
|
}
|
583
585
|
if (node.children) {
|
584
586
|
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
|
585
587
|
var index = _a[_i];
|
586
|
-
var childNode = ArrayItem.Get(context
|
587
|
-
promises.push(_this.loadNodeAsync("/nodes/"
|
588
|
+
var childNode = ArrayItem.Get("".concat(context, "/children/").concat(index), _this._gltf.nodes, index);
|
589
|
+
promises.push(_this.loadNodeAsync("/nodes/".concat(childNode.index), childNode, function (childBabylonMesh) {
|
588
590
|
childBabylonMesh.parent = babylonTransformNode;
|
589
591
|
}));
|
590
592
|
}
|
591
593
|
}
|
592
594
|
assign(babylonTransformNode);
|
593
595
|
};
|
594
|
-
if (node.mesh == undefined) {
|
595
|
-
var nodeName = node.name || "node"
|
596
|
+
if (node.mesh == undefined || node.skin != undefined) {
|
597
|
+
var nodeName = node.name || "node".concat(node.index);
|
596
598
|
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
597
599
|
node._babylonTransformNode = new TransformNode(nodeName, this._babylonScene);
|
598
600
|
node._babylonTransformNode._parentContainer = this._assetContainer;
|
599
601
|
this._babylonScene._blockEntityCollection = false;
|
600
602
|
loadNode(node._babylonTransformNode);
|
601
603
|
}
|
602
|
-
|
603
|
-
|
604
|
-
|
604
|
+
if (node.mesh != undefined) {
|
605
|
+
if (node.skin == undefined) {
|
606
|
+
var mesh = ArrayItem.Get("".concat(context, "/mesh"), this._gltf.meshes, node.mesh);
|
607
|
+
promises.push(this._loadMeshAsync("/meshes/".concat(mesh.index), node, mesh, loadNode));
|
608
|
+
}
|
609
|
+
else {
|
610
|
+
// See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
|
611
|
+
// This code path will place the skinned mesh as a sibling of the skeleton root node without loading the
|
612
|
+
// transform, which effectively ignores the transform of the skinned mesh, as per spec.
|
613
|
+
var mesh = ArrayItem.Get("".concat(context, "/mesh"), this._gltf.meshes, node.mesh);
|
614
|
+
promises.push(this._loadMeshAsync("/meshes/".concat(mesh.index), node, mesh, function (babylonTransformNode) {
|
615
|
+
GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
|
616
|
+
var skin = ArrayItem.Get("".concat(context, "/skin"), _this._gltf.skins, node.skin);
|
617
|
+
promises.push(_this._loadSkinAsync("/skins/".concat(skin.index), node, skin, function (babylonSkeleton) {
|
618
|
+
_this._forEachPrimitive(node, function (babylonMesh) {
|
619
|
+
babylonMesh.skeleton = babylonSkeleton;
|
620
|
+
});
|
621
|
+
// Wait until the scene is loaded to ensure the skeleton root node has been loaded.
|
622
|
+
_this._postSceneLoadActions.push(function () {
|
623
|
+
if (skin.skeleton != undefined) {
|
624
|
+
// Place the skinned mesh node as a sibling of the skeleton root node.
|
625
|
+
var skeletonRootNode = ArrayItem.Get("/skins/".concat(skin.index, "/skeleton"), _this._gltf.nodes, skin.skeleton);
|
626
|
+
babylonTransformNode.parent = skeletonRootNode.parent._babylonTransformNode;
|
627
|
+
}
|
628
|
+
else {
|
629
|
+
babylonTransformNode.parent = _this._rootBabylonMesh;
|
630
|
+
}
|
631
|
+
});
|
632
|
+
}));
|
633
|
+
}));
|
634
|
+
}
|
605
635
|
}
|
606
636
|
this.logClose();
|
607
637
|
return Promise.all(promises).then(function () {
|
@@ -620,17 +650,17 @@ var GLTFLoader = /** @class */ (function () {
|
|
620
650
|
GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
|
621
651
|
var primitives = mesh.primitives;
|
622
652
|
if (!primitives || !primitives.length) {
|
623
|
-
throw new Error(context
|
653
|
+
throw new Error("".concat(context, ": Primitives are missing"));
|
624
654
|
}
|
625
655
|
if (primitives[0].index == undefined) {
|
626
656
|
ArrayItem.Assign(primitives);
|
627
657
|
}
|
628
658
|
var promises = new Array();
|
629
|
-
this.logOpen(context
|
630
|
-
var name = node.name || "node"
|
659
|
+
this.logOpen("".concat(context, " ").concat(mesh.name || ""));
|
660
|
+
var name = node.name || "node".concat(node.index);
|
631
661
|
if (primitives.length === 1) {
|
632
662
|
var primitive = mesh.primitives[0];
|
633
|
-
promises.push(this._loadMeshPrimitiveAsync(context
|
663
|
+
promises.push(this._loadMeshPrimitiveAsync("".concat(context, "/primitives/").concat(primitive.index), name, node, mesh, primitive, function (babylonMesh) {
|
634
664
|
node._babylonTransformNode = babylonMesh;
|
635
665
|
node._primitiveBabylonMeshes = [babylonMesh];
|
636
666
|
}));
|
@@ -643,16 +673,12 @@ var GLTFLoader = /** @class */ (function () {
|
|
643
673
|
node._primitiveBabylonMeshes = [];
|
644
674
|
for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
|
645
675
|
var primitive = primitives_1[_i];
|
646
|
-
promises.push(this._loadMeshPrimitiveAsync(context
|
676
|
+
promises.push(this._loadMeshPrimitiveAsync("".concat(context, "/primitives/").concat(primitive.index), "".concat(name, "_primitive").concat(primitive.index), node, mesh, primitive, function (babylonMesh) {
|
647
677
|
babylonMesh.parent = node._babylonTransformNode;
|
648
678
|
node._primitiveBabylonMeshes.push(babylonMesh);
|
649
679
|
}));
|
650
680
|
}
|
651
681
|
}
|
652
|
-
if (node.skin != undefined) {
|
653
|
-
var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
|
654
|
-
promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
|
655
|
-
}
|
656
682
|
assign(node._babylonTransformNode);
|
657
683
|
this.logClose();
|
658
684
|
return Promise.all(promises).then(function () {
|
@@ -675,7 +701,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
675
701
|
if (extensionPromise) {
|
676
702
|
return extensionPromise;
|
677
703
|
}
|
678
|
-
this.logOpen(""
|
704
|
+
this.logOpen("".concat(context));
|
679
705
|
var shouldInstance = (this._disableInstancedMesh === 0) && this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
|
680
706
|
var babylonAbstractMesh;
|
681
707
|
var promise;
|
@@ -713,8 +739,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
713
739
|
babylonMesh_1.material = babylonMaterial;
|
714
740
|
}
|
715
741
|
else {
|
716
|
-
var material = ArrayItem.Get(context
|
717
|
-
promises.push(this._loadMaterialAsync("/materials/"
|
742
|
+
var material = ArrayItem.Get("".concat(context, "/material"), this._gltf.materials, primitive.material);
|
743
|
+
promises.push(this._loadMaterialAsync("/materials/".concat(material.index), material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
|
718
744
|
babylonMesh_1.material = babylonMaterial;
|
719
745
|
}));
|
720
746
|
}
|
@@ -743,7 +769,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
743
769
|
}
|
744
770
|
var attributes = primitive.attributes;
|
745
771
|
if (!attributes) {
|
746
|
-
throw new Error(context
|
772
|
+
throw new Error("".concat(context, ": Attributes are missing"));
|
747
773
|
}
|
748
774
|
var promises = new Array();
|
749
775
|
var babylonGeometry = new Geometry(babylonMesh.name, this._babylonScene);
|
@@ -751,8 +777,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
751
777
|
babylonMesh.isUnIndexed = true;
|
752
778
|
}
|
753
779
|
else {
|
754
|
-
var accessor = ArrayItem.Get(context
|
755
|
-
promises.push(this._loadIndicesAccessorAsync("/accessors/"
|
780
|
+
var accessor = ArrayItem.Get("".concat(context, "/indices"), this._gltf.accessors, primitive.indices);
|
781
|
+
promises.push(this._loadIndicesAccessorAsync("/accessors/".concat(accessor.index), accessor).then(function (data) {
|
756
782
|
babylonGeometry.setIndices(data);
|
757
783
|
}));
|
758
784
|
}
|
@@ -764,8 +790,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
764
790
|
if (babylonMesh._delayInfo.indexOf(kind) === -1) {
|
765
791
|
babylonMesh._delayInfo.push(kind);
|
766
792
|
}
|
767
|
-
var accessor = ArrayItem.Get(context
|
768
|
-
promises.push(_this._loadVertexAccessorAsync("/accessors/"
|
793
|
+
var accessor = ArrayItem.Get("".concat(context, "/attributes/").concat(attribute), _this._gltf.accessors, attributes[attribute]);
|
794
|
+
promises.push(_this._loadVertexAccessorAsync("/accessors/".concat(accessor.index), accessor, kind).then(function (babylonVertexBuffer) {
|
769
795
|
if (babylonVertexBuffer.getKind() === VertexBuffer.PositionKind && !_this.parent.alwaysComputeBoundingBox && !babylonMesh.skeleton) {
|
770
796
|
var mmin = accessor.min, mmax = accessor.max;
|
771
797
|
if (mmin !== undefined && mmax !== undefined) {
|
@@ -836,15 +862,15 @@ var GLTFLoader = /** @class */ (function () {
|
|
836
862
|
node._numMorphTargets = primitive.targets.length;
|
837
863
|
}
|
838
864
|
else if (primitive.targets.length !== node._numMorphTargets) {
|
839
|
-
throw new Error(context
|
865
|
+
throw new Error("".concat(context, ": Primitives do not have the same number of targets"));
|
840
866
|
}
|
841
867
|
var targetNames = mesh.extras ? mesh.extras.targetNames : null;
|
842
868
|
babylonMesh.morphTargetManager = new MorphTargetManager(babylonMesh.getScene());
|
843
869
|
babylonMesh.morphTargetManager.areUpdatesFrozen = true;
|
844
870
|
for (var index = 0; index < primitive.targets.length; index++) {
|
845
871
|
var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
|
846
|
-
var
|
847
|
-
babylonMesh.morphTargetManager.addTarget(new MorphTarget(
|
872
|
+
var name_3 = targetNames ? targetNames[index] : "morphTarget".concat(index);
|
873
|
+
babylonMesh.morphTargetManager.addTarget(new MorphTarget(name_3, weight, babylonMesh.getScene()));
|
848
874
|
// TODO: tell the target whether it has positions, normals, tangents
|
849
875
|
}
|
850
876
|
};
|
@@ -856,7 +882,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
856
882
|
var morphTargetManager = babylonMesh.morphTargetManager;
|
857
883
|
for (var index = 0; index < morphTargetManager.numTargets; index++) {
|
858
884
|
var babylonMorphTarget = morphTargetManager.getTarget(index);
|
859
|
-
promises.push(this._loadMorphTargetVertexDataAsync(context
|
885
|
+
promises.push(this._loadMorphTargetVertexDataAsync("".concat(context, "/targets/").concat(index), babylonGeometry, primitive.targets[index], babylonMorphTarget));
|
860
886
|
}
|
861
887
|
return Promise.all(promises).then(function () {
|
862
888
|
morphTargetManager.areUpdatesFrozen = false;
|
@@ -873,8 +899,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
873
899
|
if (!babylonVertexBuffer) {
|
874
900
|
return;
|
875
901
|
}
|
876
|
-
var accessor = ArrayItem.Get(context
|
877
|
-
promises.push(_this._loadFloatAccessorAsync("/accessors/"
|
902
|
+
var accessor = ArrayItem.Get("".concat(context, "/").concat(attribute), _this._gltf.accessors, attributes[attribute]);
|
903
|
+
promises.push(_this._loadFloatAccessorAsync("/accessors/".concat(accessor.index), accessor).then(function (data) {
|
878
904
|
setData(babylonVertexBuffer, data);
|
879
905
|
}));
|
880
906
|
};
|
@@ -936,30 +962,22 @@ var GLTFLoader = /** @class */ (function () {
|
|
936
962
|
babylonNode.rotationQuaternion = rotation;
|
937
963
|
babylonNode.scaling = scaling;
|
938
964
|
};
|
939
|
-
GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
|
965
|
+
GLTFLoader.prototype._loadSkinAsync = function (context, node, skin, assign) {
|
940
966
|
var _this = this;
|
941
967
|
var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
|
942
968
|
if (extensionPromise) {
|
943
969
|
return extensionPromise;
|
944
970
|
}
|
945
|
-
var assignSkeleton = function (skeleton) {
|
946
|
-
_this._forEachPrimitive(node, function (babylonMesh) {
|
947
|
-
babylonMesh.skeleton = skeleton;
|
948
|
-
});
|
949
|
-
};
|
950
971
|
if (skin._data) {
|
951
|
-
|
972
|
+
assign(skin._data.babylonSkeleton);
|
952
973
|
return skin._data.promise;
|
953
974
|
}
|
954
|
-
var skeletonId = "skeleton"
|
975
|
+
var skeletonId = "skeleton".concat(skin.index);
|
955
976
|
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
956
977
|
var babylonSkeleton = new Skeleton(skin.name || skeletonId, skeletonId, this._babylonScene);
|
957
978
|
babylonSkeleton._parentContainer = this._assetContainer;
|
958
979
|
this._babylonScene._blockEntityCollection = false;
|
959
|
-
// See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
|
960
|
-
babylonSkeleton.overrideMesh = this._rootBabylonMesh;
|
961
980
|
this._loadBones(context, skin, babylonSkeleton);
|
962
|
-
assignSkeleton(babylonSkeleton);
|
963
981
|
var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
|
964
982
|
_this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
|
965
983
|
});
|
@@ -967,38 +985,102 @@ var GLTFLoader = /** @class */ (function () {
|
|
967
985
|
babylonSkeleton: babylonSkeleton,
|
968
986
|
promise: promise
|
969
987
|
};
|
988
|
+
assign(babylonSkeleton);
|
970
989
|
return promise;
|
971
990
|
};
|
972
991
|
GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
|
992
|
+
if (skin.skeleton == undefined || this._parent.alwaysComputeSkeletonRootNode) {
|
993
|
+
var rootNode = this._findSkeletonRootNode("".concat(context, "/joints"), skin.joints);
|
994
|
+
if (rootNode) {
|
995
|
+
if (skin.skeleton === undefined) {
|
996
|
+
skin.skeleton = rootNode.index;
|
997
|
+
}
|
998
|
+
else {
|
999
|
+
var isParent = function (a, b) {
|
1000
|
+
for (; b.parent; b = b.parent) {
|
1001
|
+
if (b.parent === a) {
|
1002
|
+
return true;
|
1003
|
+
}
|
1004
|
+
}
|
1005
|
+
return false;
|
1006
|
+
};
|
1007
|
+
var skeletonNode = ArrayItem.Get("".concat(context, "/skeleton"), this._gltf.nodes, skin.skeleton);
|
1008
|
+
if (skeletonNode !== rootNode && !isParent(skeletonNode, rootNode)) {
|
1009
|
+
Logger.Warn("".concat(context, "/skeleton: Overriding with nearest common ancestor as skeleton node is not a common root"));
|
1010
|
+
skin.skeleton = rootNode.index;
|
1011
|
+
}
|
1012
|
+
}
|
1013
|
+
}
|
1014
|
+
else {
|
1015
|
+
Logger.Warn("".concat(context, ": Failed to find common root"));
|
1016
|
+
}
|
1017
|
+
}
|
973
1018
|
var babylonBones = {};
|
974
1019
|
for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
|
975
1020
|
var index = _a[_i];
|
976
|
-
var node = ArrayItem.Get(context
|
1021
|
+
var node = ArrayItem.Get("".concat(context, "/joints/").concat(index), this._gltf.nodes, index);
|
977
1022
|
this._loadBone(node, skin, babylonSkeleton, babylonBones);
|
978
1023
|
}
|
979
1024
|
};
|
1025
|
+
GLTFLoader.prototype._findSkeletonRootNode = function (context, joints) {
|
1026
|
+
var paths = {};
|
1027
|
+
for (var _i = 0, joints_1 = joints; _i < joints_1.length; _i++) {
|
1028
|
+
var index = joints_1[_i];
|
1029
|
+
var path = new Array();
|
1030
|
+
var node = ArrayItem.Get("".concat(context, "/").concat(index), this._gltf.nodes, index);
|
1031
|
+
while (node.index !== -1) {
|
1032
|
+
path.unshift(node);
|
1033
|
+
node = node.parent;
|
1034
|
+
}
|
1035
|
+
paths[index] = path;
|
1036
|
+
}
|
1037
|
+
var rootNode = null;
|
1038
|
+
for (var i = 0;; ++i) {
|
1039
|
+
var path = paths[joints[0]];
|
1040
|
+
if (i >= path.length) {
|
1041
|
+
return rootNode;
|
1042
|
+
}
|
1043
|
+
var node = path[i];
|
1044
|
+
for (var j = 1; j < joints.length; ++j) {
|
1045
|
+
path = paths[joints[j]];
|
1046
|
+
if (i >= path.length || node !== path[i]) {
|
1047
|
+
return rootNode;
|
1048
|
+
}
|
1049
|
+
}
|
1050
|
+
rootNode = node;
|
1051
|
+
}
|
1052
|
+
};
|
980
1053
|
GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
|
981
1054
|
var babylonBone = babylonBones[node.index];
|
982
1055
|
if (babylonBone) {
|
983
1056
|
return babylonBone;
|
984
1057
|
}
|
985
|
-
var
|
986
|
-
if (node.
|
987
|
-
|
1058
|
+
var parentBabylonBone = null;
|
1059
|
+
if (node.index !== skin.skeleton) {
|
1060
|
+
if (node.parent && node.parent.index !== -1) {
|
1061
|
+
parentBabylonBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
|
1062
|
+
}
|
1063
|
+
else if (skin.skeleton !== undefined) {
|
1064
|
+
Logger.Warn("/skins/".concat(skin.index, "/skeleton: Skeleton node is not a common root"));
|
1065
|
+
}
|
988
1066
|
}
|
989
1067
|
var boneIndex = skin.joints.indexOf(node.index);
|
990
|
-
babylonBone = new Bone(node.name || "joint"
|
1068
|
+
babylonBone = new Bone(node.name || "joint".concat(node.index), babylonSkeleton, parentBabylonBone, this._getNodeMatrix(node), null, null, boneIndex);
|
991
1069
|
babylonBones[node.index] = babylonBone;
|
992
|
-
|
993
|
-
|
1070
|
+
// Wait until the scene is loaded to ensure the transform nodes are loaded.
|
1071
|
+
this._postSceneLoadActions.push(function () {
|
1072
|
+
// Link the Babylon bone with the corresponding Babylon transform node.
|
1073
|
+
// A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
|
1074
|
+
babylonBone.linkTransformNode(node._babylonTransformNode);
|
1075
|
+
});
|
994
1076
|
return babylonBone;
|
995
1077
|
};
|
996
1078
|
GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
|
997
1079
|
if (skin.inverseBindMatrices == undefined) {
|
998
1080
|
return Promise.resolve(null);
|
999
1081
|
}
|
1000
|
-
var accessor = ArrayItem.Get(context
|
1001
|
-
return this._loadFloatAccessorAsync("/accessors/"
|
1082
|
+
var accessor = ArrayItem.Get("".concat(context, "/inverseBindMatrices"), this._gltf.accessors, skin.inverseBindMatrices);
|
1083
|
+
return this._loadFloatAccessorAsync("/accessors/".concat(accessor.index), accessor);
|
1002
1084
|
};
|
1003
1085
|
GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
|
1004
1086
|
for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
|
@@ -1036,9 +1118,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
1036
1118
|
return extensionPromise;
|
1037
1119
|
}
|
1038
1120
|
var promises = new Array();
|
1039
|
-
this.logOpen(context
|
1121
|
+
this.logOpen("".concat(context, " ").concat(camera.name || ""));
|
1040
1122
|
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1041
|
-
var babylonCamera = new FreeCamera(camera.name || "camera"
|
1123
|
+
var babylonCamera = new FreeCamera(camera.name || "camera".concat(camera.index), Vector3.Zero(), this._babylonScene, false);
|
1042
1124
|
babylonCamera._parentContainer = this._assetContainer;
|
1043
1125
|
this._babylonScene._blockEntityCollection = false;
|
1044
1126
|
babylonCamera.ignoreParentScaling = true;
|
@@ -1047,7 +1129,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1047
1129
|
case "perspective" /* PERSPECTIVE */: {
|
1048
1130
|
var perspective = camera.perspective;
|
1049
1131
|
if (!perspective) {
|
1050
|
-
throw new Error(context
|
1132
|
+
throw new Error("".concat(context, ": Camera perspective properties are missing"));
|
1051
1133
|
}
|
1052
1134
|
babylonCamera.fov = perspective.yfov;
|
1053
1135
|
babylonCamera.minZ = perspective.znear;
|
@@ -1056,7 +1138,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1056
1138
|
}
|
1057
1139
|
case "orthographic" /* ORTHOGRAPHIC */: {
|
1058
1140
|
if (!camera.orthographic) {
|
1059
|
-
throw new Error(context
|
1141
|
+
throw new Error("".concat(context, ": Camera orthographic properties are missing"));
|
1060
1142
|
}
|
1061
1143
|
babylonCamera.mode = Camera.ORTHOGRAPHIC_CAMERA;
|
1062
1144
|
babylonCamera.orthoLeft = -camera.orthographic.xmag;
|
@@ -1068,7 +1150,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1068
1150
|
break;
|
1069
1151
|
}
|
1070
1152
|
default: {
|
1071
|
-
throw new Error(context
|
1153
|
+
throw new Error("".concat(context, ": Invalid camera type (").concat(camera.type, ")"));
|
1072
1154
|
}
|
1073
1155
|
}
|
1074
1156
|
GLTFLoader.AddPointerMetadata(babylonCamera, context);
|
@@ -1087,7 +1169,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1087
1169
|
var promises = new Array();
|
1088
1170
|
for (var index = 0; index < animations.length; index++) {
|
1089
1171
|
var animation = animations[index];
|
1090
|
-
promises.push(this.loadAnimationAsync("/animations/"
|
1172
|
+
promises.push(this.loadAnimationAsync("/animations/".concat(animation.index), animation).then(function (animationGroup) {
|
1091
1173
|
// Delete the animation group if it ended up not having any animations in it.
|
1092
1174
|
if (animationGroup.targetedAnimations.length === 0) {
|
1093
1175
|
animationGroup.dispose();
|
@@ -1108,7 +1190,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1108
1190
|
return promise;
|
1109
1191
|
}
|
1110
1192
|
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1111
|
-
var babylonAnimationGroup = new AnimationGroup(animation.name || "animation"
|
1193
|
+
var babylonAnimationGroup = new AnimationGroup(animation.name || "animation".concat(animation.index), this._babylonScene);
|
1112
1194
|
babylonAnimationGroup._parentContainer = this._assetContainer;
|
1113
1195
|
this._babylonScene._blockEntityCollection = false;
|
1114
1196
|
animation._babylonAnimationGroup = babylonAnimationGroup;
|
@@ -1117,7 +1199,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1117
1199
|
ArrayItem.Assign(animation.samplers);
|
1118
1200
|
for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
|
1119
1201
|
var channel = _a[_i];
|
1120
|
-
promises.push(this._loadAnimationChannelAsync(context
|
1202
|
+
promises.push(this._loadAnimationChannelAsync("".concat(context, "/channels/").concat(channel.index), context, animation, channel, babylonAnimationGroup));
|
1121
1203
|
}
|
1122
1204
|
return Promise.all(promises).then(function () {
|
1123
1205
|
babylonAnimationGroup.normalize(0);
|
@@ -1140,14 +1222,14 @@ var GLTFLoader = /** @class */ (function () {
|
|
1140
1222
|
if (channel.target.node == undefined) {
|
1141
1223
|
return Promise.resolve();
|
1142
1224
|
}
|
1143
|
-
var targetNode = ArrayItem.Get(context
|
1225
|
+
var targetNode = ArrayItem.Get("".concat(context, "/target/node"), this._gltf.nodes, channel.target.node);
|
1144
1226
|
// Ignore animations that have no animation targets.
|
1145
1227
|
if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
|
1146
1228
|
(channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
|
1147
1229
|
return Promise.resolve();
|
1148
1230
|
}
|
1149
|
-
var sampler = ArrayItem.Get(context
|
1150
|
-
return this._loadAnimationSamplerAsync(animationContext
|
1231
|
+
var sampler = ArrayItem.Get("".concat(context, "/sampler"), animation.samplers, channel.sampler);
|
1232
|
+
return this._loadAnimationSamplerAsync("".concat(animationContext, "/samplers/").concat(channel.sampler), sampler).then(function (data) {
|
1151
1233
|
var targetPath;
|
1152
1234
|
var animationType;
|
1153
1235
|
switch (channel.target.path) {
|
@@ -1172,41 +1254,41 @@ var GLTFLoader = /** @class */ (function () {
|
|
1172
1254
|
break;
|
1173
1255
|
}
|
1174
1256
|
default: {
|
1175
|
-
throw new Error(context
|
1257
|
+
throw new Error("".concat(context, "/target/path: Invalid value (").concat(channel.target.path, ")"));
|
1176
1258
|
}
|
1177
1259
|
}
|
1178
1260
|
var outputBufferOffset = 0;
|
1179
1261
|
var getNextOutputValue;
|
1180
1262
|
switch (targetPath) {
|
1181
1263
|
case "position": {
|
1182
|
-
getNextOutputValue = function () {
|
1183
|
-
var value = Vector3.FromArray(data.output, outputBufferOffset);
|
1264
|
+
getNextOutputValue = function (scale) {
|
1265
|
+
var value = Vector3.FromArray(data.output, outputBufferOffset).scaleInPlace(scale);
|
1184
1266
|
outputBufferOffset += 3;
|
1185
1267
|
return value;
|
1186
1268
|
};
|
1187
1269
|
break;
|
1188
1270
|
}
|
1189
1271
|
case "rotationQuaternion": {
|
1190
|
-
getNextOutputValue = function () {
|
1191
|
-
var value = Quaternion.FromArray(data.output, outputBufferOffset);
|
1272
|
+
getNextOutputValue = function (scale) {
|
1273
|
+
var value = Quaternion.FromArray(data.output, outputBufferOffset).scaleInPlace(scale);
|
1192
1274
|
outputBufferOffset += 4;
|
1193
1275
|
return value;
|
1194
1276
|
};
|
1195
1277
|
break;
|
1196
1278
|
}
|
1197
1279
|
case "scaling": {
|
1198
|
-
getNextOutputValue = function () {
|
1199
|
-
var value = Vector3.FromArray(data.output, outputBufferOffset);
|
1280
|
+
getNextOutputValue = function (scale) {
|
1281
|
+
var value = Vector3.FromArray(data.output, outputBufferOffset).scaleInPlace(scale);
|
1200
1282
|
outputBufferOffset += 3;
|
1201
1283
|
return value;
|
1202
1284
|
};
|
1203
1285
|
break;
|
1204
1286
|
}
|
1205
1287
|
case "influence": {
|
1206
|
-
getNextOutputValue = function () {
|
1288
|
+
getNextOutputValue = function (scale) {
|
1207
1289
|
var value = new Array(targetNode._numMorphTargets);
|
1208
1290
|
for (var i = 0; i < targetNode._numMorphTargets; i++) {
|
1209
|
-
value[i] = data.output[outputBufferOffset++];
|
1291
|
+
value[i] = data.output[outputBufferOffset++] * scale;
|
1210
1292
|
}
|
1211
1293
|
return value;
|
1212
1294
|
};
|
@@ -1217,25 +1299,26 @@ var GLTFLoader = /** @class */ (function () {
|
|
1217
1299
|
switch (data.interpolation) {
|
1218
1300
|
case "STEP" /* STEP */: {
|
1219
1301
|
getNextKey = function (frameIndex) { return ({
|
1220
|
-
frame: data.input[frameIndex],
|
1221
|
-
value: getNextOutputValue(),
|
1302
|
+
frame: data.input[frameIndex] * _this.parent.targetFps,
|
1303
|
+
value: getNextOutputValue(1),
|
1222
1304
|
interpolation: AnimationKeyInterpolation.STEP
|
1223
1305
|
}); };
|
1224
1306
|
break;
|
1225
1307
|
}
|
1226
1308
|
case "LINEAR" /* LINEAR */: {
|
1227
1309
|
getNextKey = function (frameIndex) { return ({
|
1228
|
-
frame: data.input[frameIndex],
|
1229
|
-
value: getNextOutputValue()
|
1310
|
+
frame: data.input[frameIndex] * _this.parent.targetFps,
|
1311
|
+
value: getNextOutputValue(1)
|
1230
1312
|
}); };
|
1231
1313
|
break;
|
1232
1314
|
}
|
1233
1315
|
case "CUBICSPLINE" /* CUBICSPLINE */: {
|
1316
|
+
var invTargetFps_1 = 1 / _this.parent.targetFps;
|
1234
1317
|
getNextKey = function (frameIndex) { return ({
|
1235
|
-
frame: data.input[frameIndex],
|
1236
|
-
inTangent: getNextOutputValue(),
|
1237
|
-
value: getNextOutputValue(),
|
1238
|
-
outTangent: getNextOutputValue()
|
1318
|
+
frame: data.input[frameIndex] * _this.parent.targetFps,
|
1319
|
+
inTangent: getNextOutputValue(invTargetFps_1),
|
1320
|
+
value: getNextOutputValue(1),
|
1321
|
+
outTangent: getNextOutputValue(invTargetFps_1)
|
1239
1322
|
}); };
|
1240
1323
|
break;
|
1241
1324
|
}
|
@@ -1246,8 +1329,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1246
1329
|
}
|
1247
1330
|
if (targetPath === "influence") {
|
1248
1331
|
var _loop_2 = function (targetIndex) {
|
1249
|
-
var animationName = babylonAnimationGroup.name
|
1250
|
-
var babylonAnimation = new Animation(animationName, targetPath,
|
1332
|
+
var animationName = "".concat(babylonAnimationGroup.name, "_channel").concat(babylonAnimationGroup.targetedAnimations.length);
|
1333
|
+
var babylonAnimation = new Animation(animationName, targetPath, _this.parent.targetFps, animationType);
|
1251
1334
|
babylonAnimation.setKeys(keys.map(function (key) { return ({
|
1252
1335
|
frame: key.frame,
|
1253
1336
|
inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
|
@@ -1267,8 +1350,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1267
1350
|
}
|
1268
1351
|
}
|
1269
1352
|
else {
|
1270
|
-
var animationName = babylonAnimationGroup.name
|
1271
|
-
var babylonAnimation = new Animation(animationName, targetPath,
|
1353
|
+
var animationName = "".concat(babylonAnimationGroup.name, "_channel").concat(babylonAnimationGroup.targetedAnimations.length);
|
1354
|
+
var babylonAnimation = new Animation(animationName, targetPath, _this.parent.targetFps, animationType);
|
1272
1355
|
babylonAnimation.setKeys(keys);
|
1273
1356
|
if (animationTargetOverride != null && animationTargetOverride.animations != null) {
|
1274
1357
|
animationTargetOverride.animations.push(babylonAnimation);
|
@@ -1293,14 +1376,14 @@ var GLTFLoader = /** @class */ (function () {
|
|
1293
1376
|
break;
|
1294
1377
|
}
|
1295
1378
|
default: {
|
1296
|
-
throw new Error(context
|
1379
|
+
throw new Error("".concat(context, "/interpolation: Invalid value (").concat(sampler.interpolation, ")"));
|
1297
1380
|
}
|
1298
1381
|
}
|
1299
|
-
var inputAccessor = ArrayItem.Get(context
|
1300
|
-
var outputAccessor = ArrayItem.Get(context
|
1382
|
+
var inputAccessor = ArrayItem.Get("".concat(context, "/input"), this._gltf.accessors, sampler.input);
|
1383
|
+
var outputAccessor = ArrayItem.Get("".concat(context, "/output"), this._gltf.accessors, sampler.output);
|
1301
1384
|
sampler._data = Promise.all([
|
1302
|
-
this._loadFloatAccessorAsync("/accessors/"
|
1303
|
-
this._loadFloatAccessorAsync("/accessors/"
|
1385
|
+
this._loadFloatAccessorAsync("/accessors/".concat(inputAccessor.index), inputAccessor),
|
1386
|
+
this._loadFloatAccessorAsync("/accessors/".concat(outputAccessor.index), outputAccessor)
|
1304
1387
|
]).then(function (_a) {
|
1305
1388
|
var inputData = _a[0], outputData = _a[1];
|
1306
1389
|
return {
|
@@ -1326,11 +1409,11 @@ var GLTFLoader = /** @class */ (function () {
|
|
1326
1409
|
}
|
1327
1410
|
if (!buffer._data) {
|
1328
1411
|
if (buffer.uri) {
|
1329
|
-
buffer._data = this.loadUriAsync(context
|
1412
|
+
buffer._data = this.loadUriAsync("".concat(context, "/uri"), buffer, buffer.uri);
|
1330
1413
|
}
|
1331
1414
|
else {
|
1332
1415
|
if (!this._bin) {
|
1333
|
-
throw new Error(context
|
1416
|
+
throw new Error("".concat(context, ": Uri is missing or the binary glTF is missing its binary chunk"));
|
1334
1417
|
}
|
1335
1418
|
buffer._data = this._bin.readAsync(0, buffer.byteLength);
|
1336
1419
|
}
|
@@ -1340,7 +1423,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1340
1423
|
return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
|
1341
1424
|
}
|
1342
1425
|
catch (e) {
|
1343
|
-
throw new Error(context
|
1426
|
+
throw new Error("".concat(context, ": ").concat(e.message));
|
1344
1427
|
}
|
1345
1428
|
});
|
1346
1429
|
};
|
@@ -1358,8 +1441,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1358
1441
|
if (bufferView._data) {
|
1359
1442
|
return bufferView._data;
|
1360
1443
|
}
|
1361
|
-
var buffer = ArrayItem.Get(context
|
1362
|
-
bufferView._data = this.loadBufferAsync("/buffers/"
|
1444
|
+
var buffer = ArrayItem.Get("".concat(context, "/buffer"), this._gltf.buffers, bufferView.buffer);
|
1445
|
+
bufferView._data = this.loadBufferAsync("/buffers/".concat(buffer.index), buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
|
1363
1446
|
return bufferView._data;
|
1364
1447
|
};
|
1365
1448
|
GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
|
@@ -1374,8 +1457,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1374
1457
|
accessor._data = Promise.resolve(new constructor(length));
|
1375
1458
|
}
|
1376
1459
|
else {
|
1377
|
-
var bufferView_1 = ArrayItem.Get(context
|
1378
|
-
accessor._data = this.loadBufferViewAsync("/bufferViews/"
|
1460
|
+
var bufferView_1 = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, accessor.bufferView);
|
1461
|
+
accessor._data = this.loadBufferViewAsync("/bufferViews/".concat(bufferView_1.index), bufferView_1).then(function (data) {
|
1379
1462
|
if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized && (!bufferView_1.byteStride || bufferView_1.byteStride === byteStride)) {
|
1380
1463
|
return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
|
1381
1464
|
}
|
@@ -1392,21 +1475,21 @@ var GLTFLoader = /** @class */ (function () {
|
|
1392
1475
|
var sparse_1 = accessor.sparse;
|
1393
1476
|
accessor._data = accessor._data.then(function (data) {
|
1394
1477
|
var typedArray = data;
|
1395
|
-
var indicesBufferView = ArrayItem.Get(context
|
1396
|
-
var valuesBufferView = ArrayItem.Get(context
|
1478
|
+
var indicesBufferView = ArrayItem.Get("".concat(context, "/sparse/indices/bufferView"), _this._gltf.bufferViews, sparse_1.indices.bufferView);
|
1479
|
+
var valuesBufferView = ArrayItem.Get("".concat(context, "/sparse/values/bufferView"), _this._gltf.bufferViews, sparse_1.values.bufferView);
|
1397
1480
|
return Promise.all([
|
1398
|
-
_this.loadBufferViewAsync("/bufferViews/"
|
1399
|
-
_this.loadBufferViewAsync("/bufferViews/"
|
1481
|
+
_this.loadBufferViewAsync("/bufferViews/".concat(indicesBufferView.index), indicesBufferView),
|
1482
|
+
_this.loadBufferViewAsync("/bufferViews/".concat(valuesBufferView.index), valuesBufferView)
|
1400
1483
|
]).then(function (_a) {
|
1401
1484
|
var indicesData = _a[0], valuesData = _a[1];
|
1402
|
-
var indices = GLTFLoader._GetTypedArray(context
|
1485
|
+
var indices = GLTFLoader._GetTypedArray("".concat(context, "/sparse/indices"), sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
|
1403
1486
|
var sparseLength = numComponents * sparse_1.count;
|
1404
1487
|
var values;
|
1405
1488
|
if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
|
1406
|
-
values = GLTFLoader._GetTypedArray(context
|
1489
|
+
values = GLTFLoader._GetTypedArray("".concat(context, "/sparse/values"), accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
|
1407
1490
|
}
|
1408
1491
|
else {
|
1409
|
-
var sparseData = GLTFLoader._GetTypedArray(context
|
1492
|
+
var sparseData = GLTFLoader._GetTypedArray("".concat(context, "/sparse/values"), accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
|
1410
1493
|
values = new constructor(sparseLength);
|
1411
1494
|
VertexBuffer.ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
|
1412
1495
|
values[index] = value;
|
@@ -1431,23 +1514,23 @@ var GLTFLoader = /** @class */ (function () {
|
|
1431
1514
|
};
|
1432
1515
|
GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
|
1433
1516
|
if (accessor.type !== "SCALAR" /* SCALAR */) {
|
1434
|
-
throw new Error(context
|
1517
|
+
throw new Error("".concat(context, "/type: Invalid value ").concat(accessor.type));
|
1435
1518
|
}
|
1436
1519
|
if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
|
1437
1520
|
accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
|
1438
1521
|
accessor.componentType !== 5125 /* UNSIGNED_INT */) {
|
1439
|
-
throw new Error(context
|
1522
|
+
throw new Error("".concat(context, "/componentType: Invalid value ").concat(accessor.componentType));
|
1440
1523
|
}
|
1441
1524
|
if (accessor._data) {
|
1442
1525
|
return accessor._data;
|
1443
1526
|
}
|
1444
1527
|
if (accessor.sparse) {
|
1445
|
-
var constructor = GLTFLoader._GetTypedArrayConstructor(context
|
1528
|
+
var constructor = GLTFLoader._GetTypedArrayConstructor("".concat(context, "/componentType"), accessor.componentType);
|
1446
1529
|
accessor._data = this._loadAccessorAsync(context, accessor, constructor);
|
1447
1530
|
}
|
1448
1531
|
else {
|
1449
|
-
var bufferView = ArrayItem.Get(context
|
1450
|
-
accessor._data = this.loadBufferViewAsync("/bufferViews/"
|
1532
|
+
var bufferView = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, accessor.bufferView);
|
1533
|
+
accessor._data = this.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView).then(function (data) {
|
1451
1534
|
return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
|
1452
1535
|
});
|
1453
1536
|
}
|
@@ -1458,7 +1541,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1458
1541
|
if (bufferView._babylonBuffer) {
|
1459
1542
|
return bufferView._babylonBuffer;
|
1460
1543
|
}
|
1461
|
-
bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/"
|
1544
|
+
bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView).then(function (data) {
|
1462
1545
|
return new Buffer(_this._babylonScene.getEngine(), data, false);
|
1463
1546
|
});
|
1464
1547
|
return bufferView._babylonBuffer;
|
@@ -1485,7 +1568,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1485
1568
|
});
|
1486
1569
|
}
|
1487
1570
|
else {
|
1488
|
-
var bufferView_2 = ArrayItem.Get(context
|
1571
|
+
var bufferView_2 = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, accessor.bufferView);
|
1489
1572
|
accessor._babylonVertexBuffer[kind] = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
|
1490
1573
|
var size = GLTFLoader._GetNumComponents(context, accessor.type);
|
1491
1574
|
return new VertexBuffer(_this._babylonScene.getEngine(), babylonBuffer, kind, false, false, bufferView_2.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true, 1, true);
|
@@ -1495,7 +1578,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1495
1578
|
};
|
1496
1579
|
GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
|
1497
1580
|
if (!(babylonMaterial instanceof PBRMaterial)) {
|
1498
|
-
throw new Error(context
|
1581
|
+
throw new Error("".concat(context, ": Material type not supported"));
|
1499
1582
|
}
|
1500
1583
|
var promises = new Array();
|
1501
1584
|
if (properties) {
|
@@ -1509,15 +1592,15 @@ var GLTFLoader = /** @class */ (function () {
|
|
1509
1592
|
babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
|
1510
1593
|
babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
|
1511
1594
|
if (properties.baseColorTexture) {
|
1512
|
-
promises.push(this.loadTextureInfoAsync(context
|
1513
|
-
texture.name = babylonMaterial.name
|
1595
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/baseColorTexture"), properties.baseColorTexture, function (texture) {
|
1596
|
+
texture.name = "".concat(babylonMaterial.name, " (Base Color)");
|
1514
1597
|
babylonMaterial.albedoTexture = texture;
|
1515
1598
|
}));
|
1516
1599
|
}
|
1517
1600
|
if (properties.metallicRoughnessTexture) {
|
1518
1601
|
properties.metallicRoughnessTexture.nonColorData = true;
|
1519
|
-
promises.push(this.loadTextureInfoAsync(context
|
1520
|
-
texture.name = babylonMaterial.name
|
1602
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/metallicRoughnessTexture"), properties.metallicRoughnessTexture, function (texture) {
|
1603
|
+
texture.name = "".concat(babylonMaterial.name, " (Metallic Roughness)");
|
1521
1604
|
babylonMaterial.metallicTexture = texture;
|
1522
1605
|
}));
|
1523
1606
|
babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
|
@@ -1537,7 +1620,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1537
1620
|
material._data = material._data || {};
|
1538
1621
|
var babylonData = material._data[babylonDrawMode];
|
1539
1622
|
if (!babylonData) {
|
1540
|
-
this.logOpen(context
|
1623
|
+
this.logOpen("".concat(context, " ").concat(material.name || ""));
|
1541
1624
|
var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
|
1542
1625
|
babylonData = {
|
1543
1626
|
babylonMaterial: babylonMaterial,
|
@@ -1590,7 +1673,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1590
1673
|
if (extensionPromise) {
|
1591
1674
|
return extensionPromise;
|
1592
1675
|
}
|
1593
|
-
var name = material.name || "material"
|
1676
|
+
var name = material.name || "material".concat(material.index);
|
1594
1677
|
var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
|
1595
1678
|
return babylonMaterial;
|
1596
1679
|
};
|
@@ -1609,7 +1692,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1609
1692
|
var promises = new Array();
|
1610
1693
|
promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
|
1611
1694
|
if (material.pbrMetallicRoughness) {
|
1612
|
-
promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context
|
1695
|
+
promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync("".concat(context, "/pbrMetallicRoughness"), material.pbrMetallicRoughness, babylonMaterial));
|
1613
1696
|
}
|
1614
1697
|
this.loadMaterialAlphaProperties(context, material, babylonMaterial);
|
1615
1698
|
return Promise.all(promises).then(function () { });
|
@@ -1623,7 +1706,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1623
1706
|
*/
|
1624
1707
|
GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
|
1625
1708
|
if (!(babylonMaterial instanceof PBRMaterial)) {
|
1626
|
-
throw new Error(context
|
1709
|
+
throw new Error("".concat(context, ": Material type not supported"));
|
1627
1710
|
}
|
1628
1711
|
var promises = new Array();
|
1629
1712
|
babylonMaterial.emissiveColor = material.emissiveFactor ? Color3.FromArray(material.emissiveFactor) : new Color3(0, 0, 0);
|
@@ -1633,8 +1716,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1633
1716
|
}
|
1634
1717
|
if (material.normalTexture) {
|
1635
1718
|
material.normalTexture.nonColorData = true;
|
1636
|
-
promises.push(this.loadTextureInfoAsync(context
|
1637
|
-
texture.name = babylonMaterial.name
|
1719
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/normalTexture"), material.normalTexture, function (texture) {
|
1720
|
+
texture.name = "".concat(babylonMaterial.name, " (Normal)");
|
1638
1721
|
babylonMaterial.bumpTexture = texture;
|
1639
1722
|
}));
|
1640
1723
|
babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
|
@@ -1646,8 +1729,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1646
1729
|
}
|
1647
1730
|
if (material.occlusionTexture) {
|
1648
1731
|
material.occlusionTexture.nonColorData = true;
|
1649
|
-
promises.push(this.loadTextureInfoAsync(context
|
1650
|
-
texture.name = babylonMaterial.name
|
1732
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/occlusionTexture"), material.occlusionTexture, function (texture) {
|
1733
|
+
texture.name = "".concat(babylonMaterial.name, " (Occlusion)");
|
1651
1734
|
babylonMaterial.ambientTexture = texture;
|
1652
1735
|
}));
|
1653
1736
|
babylonMaterial.useAmbientInGrayScale = true;
|
@@ -1656,8 +1739,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1656
1739
|
}
|
1657
1740
|
}
|
1658
1741
|
if (material.emissiveTexture) {
|
1659
|
-
promises.push(this.loadTextureInfoAsync(context
|
1660
|
-
texture.name = babylonMaterial.name
|
1742
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/emissiveTexture"), material.emissiveTexture, function (texture) {
|
1743
|
+
texture.name = "".concat(babylonMaterial.name, " (Emissive)");
|
1661
1744
|
babylonMaterial.emissiveTexture = texture;
|
1662
1745
|
}));
|
1663
1746
|
}
|
@@ -1672,7 +1755,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1672
1755
|
*/
|
1673
1756
|
GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
|
1674
1757
|
if (!(babylonMaterial instanceof PBRMaterial)) {
|
1675
|
-
throw new Error(context
|
1758
|
+
throw new Error("".concat(context, ": Material type not supported"));
|
1676
1759
|
}
|
1677
1760
|
var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
|
1678
1761
|
switch (alphaMode) {
|
@@ -1697,7 +1780,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1697
1780
|
break;
|
1698
1781
|
}
|
1699
1782
|
default: {
|
1700
|
-
throw new Error(context
|
1783
|
+
throw new Error("".concat(context, "/alphaMode: Invalid value (").concat(material.alphaMode, ")"));
|
1701
1784
|
}
|
1702
1785
|
}
|
1703
1786
|
};
|
@@ -1715,13 +1798,13 @@ var GLTFLoader = /** @class */ (function () {
|
|
1715
1798
|
if (extensionPromise) {
|
1716
1799
|
return extensionPromise;
|
1717
1800
|
}
|
1718
|
-
this.logOpen(""
|
1801
|
+
this.logOpen("".concat(context));
|
1719
1802
|
if (textureInfo.texCoord >= 6) {
|
1720
|
-
throw new Error(context
|
1803
|
+
throw new Error("".concat(context, "/texCoord: Invalid value (").concat(textureInfo.texCoord, ")"));
|
1721
1804
|
}
|
1722
|
-
var texture = ArrayItem.Get(context
|
1805
|
+
var texture = ArrayItem.Get("".concat(context, "/index"), this._gltf.textures, textureInfo.index);
|
1723
1806
|
texture._textureInfo = textureInfo;
|
1724
|
-
var promise = this._loadTextureAsync("/textures/"
|
1807
|
+
var promise = this._loadTextureAsync("/textures/".concat(textureInfo.index), texture, function (babylonTexture) {
|
1725
1808
|
babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
|
1726
1809
|
GLTFLoader.AddPointerMetadata(babylonTexture, context);
|
1727
1810
|
_this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
|
@@ -1737,9 +1820,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
1737
1820
|
if (extensionPromise) {
|
1738
1821
|
return extensionPromise;
|
1739
1822
|
}
|
1740
|
-
this.logOpen(context
|
1741
|
-
var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context
|
1742
|
-
var image = ArrayItem.Get(context
|
1823
|
+
this.logOpen("".concat(context, " ").concat(texture.name || ""));
|
1824
|
+
var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get("".concat(context, "/sampler"), this._gltf.samplers, texture.sampler));
|
1825
|
+
var image = ArrayItem.Get("".concat(context, "/source"), this._gltf.images, texture.source);
|
1743
1826
|
var promise = this._createTextureAsync(context, sampler, image, assign, undefined, !texture._textureInfo.nonColorData);
|
1744
1827
|
this.logClose();
|
1745
1828
|
return promise;
|
@@ -1748,7 +1831,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1748
1831
|
GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign, textureLoaderOptions, useSRGBBuffer) {
|
1749
1832
|
var _this = this;
|
1750
1833
|
if (assign === void 0) { assign = function () { }; }
|
1751
|
-
var samplerData = this._loadSampler("/samplers/"
|
1834
|
+
var samplerData = this._loadSampler("/samplers/".concat(sampler.index), sampler);
|
1752
1835
|
var promises = new Array();
|
1753
1836
|
var deferred = new Deferred();
|
1754
1837
|
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
@@ -1763,7 +1846,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1763
1846
|
},
|
1764
1847
|
onError: function (message, exception) {
|
1765
1848
|
if (!_this._disposed) {
|
1766
|
-
deferred.reject(new Error(context
|
1849
|
+
deferred.reject(new Error("".concat(context, ": ").concat((exception && exception.message) ? exception.message : message || "Failed to load texture")));
|
1767
1850
|
}
|
1768
1851
|
},
|
1769
1852
|
mimeType: image.mimeType,
|
@@ -1774,9 +1857,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
1774
1857
|
babylonTexture._parentContainer = this._assetContainer;
|
1775
1858
|
this._babylonScene._blockEntityCollection = false;
|
1776
1859
|
promises.push(deferred.promise);
|
1777
|
-
promises.push(this.loadImageAsync("/images/"
|
1778
|
-
var name = image.uri || _this._fileName
|
1779
|
-
var dataUrl = "data:"
|
1860
|
+
promises.push(this.loadImageAsync("/images/".concat(image.index), image).then(function (data) {
|
1861
|
+
var name = image.uri || "".concat(_this._fileName, "#image").concat(image.index);
|
1862
|
+
var dataUrl = "data:".concat(_this._uniqueRootUrl).concat(name);
|
1780
1863
|
babylonTexture.updateURL(dataUrl, data);
|
1781
1864
|
}));
|
1782
1865
|
babylonTexture.wrapU = samplerData.wrapU;
|
@@ -1791,8 +1874,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1791
1874
|
sampler._data = {
|
1792
1875
|
noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
|
1793
1876
|
samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
|
1794
|
-
wrapU: GLTFLoader._GetTextureWrapMode(context
|
1795
|
-
wrapV: GLTFLoader._GetTextureWrapMode(context
|
1877
|
+
wrapU: GLTFLoader._GetTextureWrapMode("".concat(context, "/wrapS"), sampler.wrapS),
|
1878
|
+
wrapV: GLTFLoader._GetTextureWrapMode("".concat(context, "/wrapT"), sampler.wrapT)
|
1796
1879
|
};
|
1797
1880
|
}
|
1798
1881
|
return sampler._data;
|
@@ -1805,13 +1888,13 @@ var GLTFLoader = /** @class */ (function () {
|
|
1805
1888
|
*/
|
1806
1889
|
GLTFLoader.prototype.loadImageAsync = function (context, image) {
|
1807
1890
|
if (!image._data) {
|
1808
|
-
this.logOpen(context
|
1891
|
+
this.logOpen("".concat(context, " ").concat(image.name || ""));
|
1809
1892
|
if (image.uri) {
|
1810
|
-
image._data = this.loadUriAsync(context
|
1893
|
+
image._data = this.loadUriAsync("".concat(context, "/uri"), image, image.uri);
|
1811
1894
|
}
|
1812
1895
|
else {
|
1813
|
-
var bufferView = ArrayItem.Get(context
|
1814
|
-
image._data = this.loadBufferViewAsync("/bufferViews/"
|
1896
|
+
var bufferView = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, image.bufferView);
|
1897
|
+
image._data = this.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView);
|
1815
1898
|
}
|
1816
1899
|
this.logClose();
|
1817
1900
|
}
|
@@ -1831,23 +1914,23 @@ var GLTFLoader = /** @class */ (function () {
|
|
1831
1914
|
return extensionPromise;
|
1832
1915
|
}
|
1833
1916
|
if (!GLTFLoader._ValidateUri(uri)) {
|
1834
|
-
throw new Error(context
|
1917
|
+
throw new Error("".concat(context, ": '").concat(uri, "' is invalid"));
|
1835
1918
|
}
|
1836
1919
|
if (IsBase64DataUrl(uri)) {
|
1837
1920
|
var data = new Uint8Array(DecodeBase64UrlToBinary(uri));
|
1838
|
-
this.log(context
|
1921
|
+
this.log("".concat(context, ": Decoded ").concat(uri.substr(0, 64), "... (").concat(data.length, " bytes)"));
|
1839
1922
|
return Promise.resolve(data);
|
1840
1923
|
}
|
1841
|
-
this.log(context
|
1924
|
+
this.log("".concat(context, ": Loading ").concat(uri));
|
1842
1925
|
return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
|
1843
1926
|
return new Promise(function (resolve, reject) {
|
1844
1927
|
_this._parent._loadFile(_this._babylonScene, url, function (data) {
|
1845
1928
|
if (!_this._disposed) {
|
1846
|
-
_this.log(context
|
1929
|
+
_this.log("".concat(context, ": Loaded ").concat(uri, " (").concat(data.byteLength, " bytes)"));
|
1847
1930
|
resolve(new Uint8Array(data));
|
1848
1931
|
}
|
1849
1932
|
}, true, function (request) {
|
1850
|
-
reject(new LoadFileError(context
|
1933
|
+
reject(new LoadFileError("".concat(context, ": Failed to load '").concat(uri, "'").concat(request ? ": " + request.status + " " + request.statusText : ""), request));
|
1851
1934
|
});
|
1852
1935
|
});
|
1853
1936
|
});
|
@@ -1871,7 +1954,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1871
1954
|
case 33648 /* MIRRORED_REPEAT */: return Texture.MIRROR_ADDRESSMODE;
|
1872
1955
|
case 10497 /* REPEAT */: return Texture.WRAP_ADDRESSMODE;
|
1873
1956
|
default:
|
1874
|
-
Logger.Warn(context
|
1957
|
+
Logger.Warn("".concat(context, ": Invalid value (").concat(mode, ")"));
|
1875
1958
|
return Texture.WRAP_ADDRESSMODE;
|
1876
1959
|
}
|
1877
1960
|
};
|
@@ -1888,13 +1971,13 @@ var GLTFLoader = /** @class */ (function () {
|
|
1888
1971
|
case 9986 /* NEAREST_MIPMAP_LINEAR */: return Texture.LINEAR_NEAREST_MIPLINEAR;
|
1889
1972
|
case 9987 /* LINEAR_MIPMAP_LINEAR */: return Texture.LINEAR_LINEAR_MIPLINEAR;
|
1890
1973
|
default:
|
1891
|
-
Logger.Warn(context
|
1974
|
+
Logger.Warn("".concat(context, "/minFilter: Invalid value (").concat(minFilter, ")"));
|
1892
1975
|
return Texture.LINEAR_LINEAR_MIPLINEAR;
|
1893
1976
|
}
|
1894
1977
|
}
|
1895
1978
|
else {
|
1896
1979
|
if (magFilter !== 9728 /* NEAREST */) {
|
1897
|
-
Logger.Warn(context
|
1980
|
+
Logger.Warn("".concat(context, "/magFilter: Invalid value (").concat(magFilter, ")"));
|
1898
1981
|
}
|
1899
1982
|
switch (minFilter) {
|
1900
1983
|
case 9728 /* NEAREST */: return Texture.NEAREST_NEAREST;
|
@@ -1904,7 +1987,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1904
1987
|
case 9986 /* NEAREST_MIPMAP_LINEAR */: return Texture.NEAREST_NEAREST_MIPLINEAR;
|
1905
1988
|
case 9987 /* LINEAR_MIPMAP_LINEAR */: return Texture.NEAREST_LINEAR_MIPLINEAR;
|
1906
1989
|
default:
|
1907
|
-
Logger.Warn(context
|
1990
|
+
Logger.Warn("".concat(context, "/minFilter: Invalid value (").concat(minFilter, ")"));
|
1908
1991
|
return Texture.NEAREST_NEAREST_MIPNEAREST;
|
1909
1992
|
}
|
1910
1993
|
}
|
@@ -1917,17 +2000,17 @@ var GLTFLoader = /** @class */ (function () {
|
|
1917
2000
|
case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
|
1918
2001
|
case 5125 /* UNSIGNED_INT */: return Uint32Array;
|
1919
2002
|
case 5126 /* FLOAT */: return Float32Array;
|
1920
|
-
default: throw new Error(context
|
2003
|
+
default: throw new Error("".concat(context, ": Invalid component type ").concat(componentType));
|
1921
2004
|
}
|
1922
2005
|
};
|
1923
2006
|
GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
|
1924
2007
|
var buffer = bufferView.buffer;
|
1925
2008
|
byteOffset = bufferView.byteOffset + (byteOffset || 0);
|
1926
|
-
var constructor = GLTFLoader._GetTypedArrayConstructor(context
|
2009
|
+
var constructor = GLTFLoader._GetTypedArrayConstructor("".concat(context, "/componentType"), componentType);
|
1927
2010
|
var componentTypeLength = VertexBuffer.GetTypeByteLength(componentType);
|
1928
2011
|
if (byteOffset % componentTypeLength !== 0) {
|
1929
2012
|
// HACK: Copy the buffer if byte offset is not a multiple of component type byte length.
|
1930
|
-
Logger.Warn(context
|
2013
|
+
Logger.Warn("".concat(context, ": Copying buffer as byte offset (").concat(byteOffset, ") is not a multiple of component type byte length (").concat(componentTypeLength, ")"));
|
1931
2014
|
return new constructor(buffer.slice(byteOffset, byteOffset + length * componentTypeLength), 0);
|
1932
2015
|
}
|
1933
2016
|
return new constructor(buffer, byteOffset, length);
|
@@ -1942,7 +2025,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1942
2025
|
case "MAT3": return 9;
|
1943
2026
|
case "MAT4": return 16;
|
1944
2027
|
}
|
1945
|
-
throw new Error(context
|
2028
|
+
throw new Error("".concat(context, ": Invalid type (").concat(type, ")"));
|
1946
2029
|
};
|
1947
2030
|
GLTFLoader._ValidateUri = function (uri) {
|
1948
2031
|
return (Tools.IsBase64(uri) || uri.indexOf("..") === -1);
|
@@ -1961,7 +2044,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1961
2044
|
case 5 /* TRIANGLE_STRIP */: return Material.TriangleStripDrawMode;
|
1962
2045
|
case 6 /* TRIANGLE_FAN */: return Material.TriangleFanDrawMode;
|
1963
2046
|
}
|
1964
|
-
throw new Error(context
|
2047
|
+
throw new Error("".concat(context, ": Invalid mesh primitive mode (").concat(mode, ")"));
|
1965
2048
|
};
|
1966
2049
|
GLTFLoader.prototype._compileMaterialsAsync = function () {
|
1967
2050
|
var _this = this;
|
@@ -2021,7 +2104,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
2021
2104
|
for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
|
2022
2105
|
var extension = _a[_i];
|
2023
2106
|
if (extension.enabled) {
|
2024
|
-
var id = extension.name
|
2107
|
+
var id = "".concat(extension.name, ".").concat(functionName);
|
2025
2108
|
var loaderProperty = property;
|
2026
2109
|
loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
|
2027
2110
|
var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
|
@@ -2109,7 +2192,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
2109
2192
|
if (!extension) {
|
2110
2193
|
return null;
|
2111
2194
|
}
|
2112
|
-
return actionAsync(context
|
2195
|
+
return actionAsync("".concat(context, "/extensions/").concat(extensionName), extension);
|
2113
2196
|
};
|
2114
2197
|
/**
|
2115
2198
|
* Helper method called by a loader extension to load a glTF extra.
|
@@ -2128,7 +2211,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
2128
2211
|
if (!extra) {
|
2129
2212
|
return null;
|
2130
2213
|
}
|
2131
|
-
return actionAsync(context
|
2214
|
+
return actionAsync("".concat(context, "/extras/").concat(extensionName), extra);
|
2132
2215
|
};
|
2133
2216
|
/**
|
2134
2217
|
* Checks for presence of an extension.
|