@babylonjs/loaders 5.0.0-alpha.9 → 5.0.0-beta.11
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/index.d.ts +2 -0
- package/OBJ/index.js +4 -2
- package/OBJ/index.js.map +1 -1
- package/OBJ/mtlFileLoader.d.ts +4 -2
- package/OBJ/mtlFileLoader.js +7 -6
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.d.ts +12 -84
- package/OBJ/objFileLoader.js +52 -669
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/objLoadingOptions.d.ts +43 -0
- package/OBJ/objLoadingOptions.js +2 -0
- package/OBJ/objLoadingOptions.js.map +1 -0
- package/OBJ/solidParser.d.ts +153 -0
- package/OBJ/solidParser.js +700 -0
- package/OBJ/solidParser.js.map +1 -0
- package/STL/index.js +1 -1
- package/STL/stlFileLoader.d.ts +6 -0
- package/STL/stlFileLoader.js +38 -11
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.js +4 -4
- package/glTF/1.0/glTFLoader.d.ts +4 -4
- package/glTF/1.0/glTFLoader.js +60 -55
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +3 -1
- package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.js +6 -6
- package/glTF/1.0/glTFMaterialsCommonExtension.js +12 -12
- package/glTF/1.0/index.js +5 -5
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +15 -12
- 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 +8 -7
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +1 -5
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +6 -22
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.js +4 -4
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +35 -11
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +10 -9
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +9 -9
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +30 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +46 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +1 -2
- package/glTF/2.0/Extensions/KHR_materials_ior.js +4 -5
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +8 -9
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +0 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +8 -9
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +1 -2
- package/glTF/2.0/Extensions/KHR_materials_specular.js +14 -8
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +8 -8
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +95 -86
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +6 -6
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.js +76 -11
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +31 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.js +79 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +1 -2
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +5 -6
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js +3 -3
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +2 -2
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +6 -3
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +19 -20
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.js +20 -17
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +3 -3
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +3 -3
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/Extensions/index.d.ts +2 -0
- package/glTF/2.0/Extensions/index.js +26 -24
- package/glTF/2.0/Extensions/index.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +10 -13
- package/glTF/2.0/glTFLoader.js +416 -299
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +4 -5
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/2.0/index.d.ts +1 -1
- package/glTF/2.0/index.js +4 -4
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +25 -10
- package/glTF/glTFFileLoader.js +86 -94
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.js +2 -2
- package/glTF/glTFValidation.js.map +1 -1
- package/glTF/index.d.ts +2 -2
- package/glTF/index.js +4 -4
- package/glTF/index.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +3 -3
- package/index.js.map +1 -1
- package/legacy/legacy-glTF.js +4 -4
- package/legacy/legacy-glTF1.d.ts +1 -1
- package/legacy/legacy-glTF1.js +1 -1
- package/legacy/legacy-glTF1.js.map +1 -1
- package/legacy/legacy-glTF1FileLoader.js +2 -2
- package/legacy/legacy-glTF2.d.ts +1 -1
- package/legacy/legacy-glTF2.js +3 -3
- package/legacy/legacy-glTF2.js.map +1 -1
- package/legacy/legacy-glTF2FileLoader.js +2 -2
- package/legacy/legacy-glTFFileLoader.js +3 -3
- package/legacy/legacy-objFileLoader.d.ts +1 -1
- package/legacy/legacy-objFileLoader.js +2 -2
- package/legacy/legacy-objFileLoader.js.map +1 -1
- package/legacy/legacy-stlFileLoader.d.ts +1 -1
- package/legacy/legacy-stlFileLoader.js +2 -2
- package/legacy/legacy-stlFileLoader.js.map +1 -1
- package/legacy/legacy.js +6 -6
- package/package.json +16 -4
package/glTF/2.0/glTFLoader.js
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
import { Deferred } from "@babylonjs/core/Misc/deferred";
|
2
|
-
import { Quaternion, Vector3, Matrix } from "@babylonjs/core/Maths/math.vector";
|
3
|
-
import { Color3 } from '@babylonjs/core/Maths/math.color';
|
4
|
-
import { Tools } from "@babylonjs/core/Misc/tools";
|
5
|
-
import { Camera } from "@babylonjs/core/Cameras/camera";
|
6
|
-
import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera";
|
7
|
-
import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup";
|
8
|
-
import { Animation } from "@babylonjs/core/Animations/animation";
|
9
|
-
import { Bone } from "@babylonjs/core/Bones/bone";
|
10
|
-
import { Skeleton } from "@babylonjs/core/Bones/skeleton";
|
11
|
-
import { Material } from "@babylonjs/core/Materials/material";
|
12
|
-
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
|
13
|
-
import { Texture } from "@babylonjs/core/Materials/Textures/texture";
|
14
|
-
import { TransformNode } from "@babylonjs/core/Meshes/transformNode";
|
15
|
-
import { Buffer, VertexBuffer } from "@babylonjs/core/
|
16
|
-
import { Geometry } from "@babylonjs/core/Meshes/geometry";
|
17
|
-
import { Mesh } from "@babylonjs/core/Meshes/mesh";
|
18
|
-
import { MorphTarget } from "@babylonjs/core/Morph/morphTarget";
|
19
|
-
import { MorphTargetManager } from "@babylonjs/core/Morph/morphTargetManager";
|
20
|
-
import { GLTFFileLoader, GLTFLoaderState, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode } from "../glTFFileLoader";
|
21
|
-
import { AnimationKeyInterpolation } from '@babylonjs/core/Animations/animationKey';
|
22
|
-
import { LoadFileError } from '@babylonjs/core/Misc/fileTools';
|
23
|
-
import { Logger } from '@babylonjs/core/Misc/logger';
|
24
|
-
import { TmpVectors } from '@babylonjs/core/Maths/math.vector';
|
25
|
-
import { BoundingInfo } from '@babylonjs/core/Culling/boundingInfo';
|
26
|
-
import { StringTools } from '@babylonjs/core/Misc/stringTools';
|
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 '@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.js";
|
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 { TmpVectors } from '@babylonjs/core/Maths/math.vector.js';
|
25
|
+
import { BoundingInfo } from '@babylonjs/core/Culling/boundingInfo.js';
|
26
|
+
import { StringTools } from '@babylonjs/core/Misc/stringTools.js';
|
27
27
|
/**
|
28
28
|
* Helper class for working with arrays when loading the glTF asset
|
29
29
|
*/
|
@@ -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
|
};
|
@@ -66,15 +66,20 @@ var GLTFLoader = /** @class */ (function () {
|
|
66
66
|
/** @hidden */
|
67
67
|
this._completePromises = new Array();
|
68
68
|
/** @hidden */
|
69
|
-
this.
|
69
|
+
this._assetContainer = null;
|
70
70
|
/** Storage */
|
71
71
|
this._babylonLights = [];
|
72
72
|
/** @hidden */
|
73
73
|
this._disableInstancedMesh = 0;
|
74
|
-
this._disposed = false;
|
75
|
-
this._state = null;
|
76
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;
|
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
|
@@ -102,21 +107,14 @@ var GLTFLoader = /** @class */ (function () {
|
|
102
107
|
delete GLTFLoader._RegisteredExtensions[name];
|
103
108
|
return true;
|
104
109
|
};
|
105
|
-
Object.defineProperty(GLTFLoader.prototype, "state", {
|
106
|
-
/**
|
107
|
-
* The loader state.
|
108
|
-
*/
|
109
|
-
get: function () {
|
110
|
-
return this._state;
|
111
|
-
},
|
112
|
-
enumerable: false,
|
113
|
-
configurable: true
|
114
|
-
});
|
115
110
|
Object.defineProperty(GLTFLoader.prototype, "gltf", {
|
116
111
|
/**
|
117
112
|
* The object that represents the glTF JSON.
|
118
113
|
*/
|
119
114
|
get: function () {
|
115
|
+
if (!this._gltf) {
|
116
|
+
throw new Error("glTF JSON is not available");
|
117
|
+
}
|
120
118
|
return this._gltf;
|
121
119
|
},
|
122
120
|
enumerable: false,
|
@@ -147,6 +145,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
147
145
|
* The Babylon scene when loading the asset.
|
148
146
|
*/
|
149
147
|
get: function () {
|
148
|
+
if (!this._babylonScene) {
|
149
|
+
throw new Error("Scene is not available");
|
150
|
+
}
|
150
151
|
return this._babylonScene;
|
151
152
|
},
|
152
153
|
enumerable: false,
|
@@ -169,23 +170,23 @@ var GLTFLoader = /** @class */ (function () {
|
|
169
170
|
}
|
170
171
|
this._disposed = true;
|
171
172
|
this._completePromises.length = 0;
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
this._gltf = null;
|
178
|
-
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
|
179
178
|
this._rootBabylonMesh = null;
|
179
|
+
this._defaultBabylonMaterialData = {};
|
180
|
+
this._postSceneLoadActions.length = 0;
|
180
181
|
this._parent.dispose();
|
181
182
|
};
|
182
183
|
/** @hidden */
|
183
|
-
GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene,
|
184
|
+
GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, container, data, rootUrl, onProgress, fileName) {
|
184
185
|
var _this = this;
|
185
186
|
if (fileName === void 0) { fileName = ""; }
|
186
187
|
return Promise.resolve().then(function () {
|
187
188
|
_this._babylonScene = scene;
|
188
|
-
_this.
|
189
|
+
_this._assetContainer = container;
|
189
190
|
_this._loadData(data);
|
190
191
|
var nodes = null;
|
191
192
|
if (meshesNames) {
|
@@ -202,7 +203,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
202
203
|
nodes = names.map(function (name) {
|
203
204
|
var node = nodeMap_1[name];
|
204
205
|
if (node === undefined) {
|
205
|
-
throw new Error("Failed to find node '"
|
206
|
+
throw new Error("Failed to find node '".concat(name, "'"));
|
206
207
|
}
|
207
208
|
return node;
|
208
209
|
});
|
@@ -234,15 +235,15 @@ var GLTFLoader = /** @class */ (function () {
|
|
234
235
|
var _this = this;
|
235
236
|
return Promise.resolve().then(function () {
|
236
237
|
_this._rootUrl = rootUrl;
|
237
|
-
_this._uniqueRootUrl = (!StringTools.StartsWith(rootUrl, "file:") && fileName) ? rootUrl : ""
|
238
|
+
_this._uniqueRootUrl = (!StringTools.StartsWith(rootUrl, "file:") && fileName) ? rootUrl : "".concat(rootUrl).concat(Date.now(), "/");
|
238
239
|
_this._fileName = fileName;
|
239
240
|
_this._loadExtensions();
|
240
241
|
_this._checkExtensions();
|
241
|
-
var loadingToReadyCounterName = GLTFLoaderState[GLTFLoaderState.LOADING]
|
242
|
-
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]);
|
243
244
|
_this._parent._startPerformanceCounter(loadingToReadyCounterName);
|
244
245
|
_this._parent._startPerformanceCounter(loadingToCompleteCounterName);
|
245
|
-
_this._setState(GLTFLoaderState.LOADING);
|
246
|
+
_this._parent._setState(GLTFLoaderState.LOADING);
|
246
247
|
_this._extensionsOnLoading();
|
247
248
|
var promises = new Array();
|
248
249
|
// Block the marking of materials dirty until the scene is loaded.
|
@@ -253,7 +254,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
253
254
|
}
|
254
255
|
else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
|
255
256
|
var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
|
256
|
-
promises.push(_this.loadSceneAsync("/scenes/"
|
257
|
+
promises.push(_this.loadSceneAsync("/scenes/".concat(scene.index), scene));
|
257
258
|
}
|
258
259
|
if (_this.parent.loadAllMaterials && _this._gltf.materials) {
|
259
260
|
for (var m = 0; m < _this._gltf.materials.length; ++m) {
|
@@ -276,7 +277,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
276
277
|
_this._rootBabylonMesh.setEnabled(true);
|
277
278
|
}
|
278
279
|
_this._extensionsOnReady();
|
279
|
-
_this._setState(GLTFLoaderState.READY);
|
280
|
+
_this._parent._setState(GLTFLoaderState.READY);
|
280
281
|
_this._startAnimations();
|
281
282
|
return resultFunc();
|
282
283
|
});
|
@@ -286,7 +287,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
286
287
|
if (!_this._disposed) {
|
287
288
|
Promise.all(_this._completePromises).then(function () {
|
288
289
|
_this._parent._endPerformanceCounter(loadingToCompleteCounterName);
|
289
|
-
_this._setState(GLTFLoaderState.COMPLETE);
|
290
|
+
_this._parent._setState(GLTFLoaderState.COMPLETE);
|
290
291
|
_this._parent.onCompleteObservable.notifyObservers(undefined);
|
291
292
|
_this._parent.onCompleteObservable.clear();
|
292
293
|
_this.dispose();
|
@@ -316,7 +317,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
316
317
|
if (buffers && buffers[0] && !buffers[0].uri) {
|
317
318
|
var binaryBuffer = buffers[0];
|
318
319
|
if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
|
319
|
-
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, ")"));
|
320
321
|
}
|
321
322
|
this._bin = data.bin;
|
322
323
|
}
|
@@ -359,10 +360,10 @@ var GLTFLoader = /** @class */ (function () {
|
|
359
360
|
}
|
360
361
|
};
|
361
362
|
GLTFLoader.prototype._loadExtensions = function () {
|
362
|
-
for (var
|
363
|
-
var extension = GLTFLoader._RegisteredExtensions[
|
364
|
-
if (extension.name !==
|
365
|
-
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));
|
366
367
|
}
|
367
368
|
this._extensions.push(extension);
|
368
369
|
this._parent.onExtensionLoadedObservable.notifyObservers(extension);
|
@@ -372,26 +373,23 @@ var GLTFLoader = /** @class */ (function () {
|
|
372
373
|
};
|
373
374
|
GLTFLoader.prototype._checkExtensions = function () {
|
374
375
|
if (this._gltf.extensionsRequired) {
|
375
|
-
var _loop_1 = function (
|
376
|
-
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; });
|
377
378
|
if (!available) {
|
378
|
-
throw new Error("Require extension "
|
379
|
+
throw new Error("Require extension ".concat(name_2, " is not available"));
|
379
380
|
}
|
380
381
|
};
|
381
382
|
var this_1 = this;
|
382
383
|
for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
|
383
|
-
var
|
384
|
-
_loop_1(
|
384
|
+
var name_2 = _a[_i];
|
385
|
+
_loop_1(name_2);
|
385
386
|
}
|
386
387
|
}
|
387
388
|
};
|
388
|
-
GLTFLoader.prototype._setState = function (state) {
|
389
|
-
this._state = state;
|
390
|
-
this.log(GLTFLoaderState[this._state]);
|
391
|
-
};
|
392
389
|
GLTFLoader.prototype._createRootNode = function () {
|
393
|
-
this._babylonScene._blockEntityCollection = this.
|
390
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
394
391
|
this._rootBabylonMesh = new Mesh("__root__", this._babylonScene);
|
392
|
+
this._rootBabylonMesh._parentContainer = this._assetContainer;
|
395
393
|
this._babylonScene._blockEntityCollection = false;
|
396
394
|
this._rootBabylonMesh.setEnabled(false);
|
397
395
|
var rootNode = {
|
@@ -412,7 +410,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
412
410
|
break;
|
413
411
|
}
|
414
412
|
default: {
|
415
|
-
throw new Error("Invalid coordinate system mode ("
|
413
|
+
throw new Error("Invalid coordinate system mode (".concat(this._parent.coordinateSystemMode, ")"));
|
416
414
|
}
|
417
415
|
}
|
418
416
|
this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
|
@@ -431,28 +429,19 @@ var GLTFLoader = /** @class */ (function () {
|
|
431
429
|
return extensionPromise;
|
432
430
|
}
|
433
431
|
var promises = new Array();
|
434
|
-
this.logOpen(context
|
432
|
+
this.logOpen("".concat(context, " ").concat(scene.name || ""));
|
435
433
|
if (scene.nodes) {
|
436
434
|
for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
|
437
435
|
var index = _a[_i];
|
438
|
-
var node = ArrayItem.Get(context
|
439
|
-
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) {
|
440
438
|
babylonMesh.parent = _this._rootBabylonMesh;
|
441
439
|
}));
|
442
440
|
}
|
443
441
|
}
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
|
448
|
-
var node = _c[_b];
|
449
|
-
if (node._babylonTransformNode && node._babylonBones) {
|
450
|
-
for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
|
451
|
-
var babylonBone = _e[_d];
|
452
|
-
babylonBone.linkTransformNode(node._babylonTransformNode);
|
453
|
-
}
|
454
|
-
}
|
455
|
-
}
|
442
|
+
for (var _b = 0, _c = this._postSceneLoadActions; _b < _c.length; _b++) {
|
443
|
+
var action = _c[_b];
|
444
|
+
action();
|
456
445
|
}
|
457
446
|
promises.push(this._loadAnimationsAsync());
|
458
447
|
this.logClose();
|
@@ -484,8 +473,10 @@ var GLTFLoader = /** @class */ (function () {
|
|
484
473
|
};
|
485
474
|
GLTFLoader.prototype._getMeshes = function () {
|
486
475
|
var meshes = new Array();
|
487
|
-
// Root mesh is always first.
|
488
|
-
|
476
|
+
// Root mesh is always first, if available.
|
477
|
+
if (this._rootBabylonMesh) {
|
478
|
+
meshes.push(this._rootBabylonMesh);
|
479
|
+
}
|
489
480
|
var nodes = this._gltf.nodes;
|
490
481
|
if (nodes) {
|
491
482
|
for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
|
@@ -558,7 +549,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
558
549
|
break;
|
559
550
|
}
|
560
551
|
default: {
|
561
|
-
Logger.Error("Invalid animation start mode ("
|
552
|
+
Logger.Error("Invalid animation start mode (".concat(this._parent.animationStartMode, ")"));
|
562
553
|
return;
|
563
554
|
}
|
564
555
|
}
|
@@ -578,40 +569,69 @@ var GLTFLoader = /** @class */ (function () {
|
|
578
569
|
return extensionPromise;
|
579
570
|
}
|
580
571
|
if (node._babylonTransformNode) {
|
581
|
-
throw new Error(context
|
572
|
+
throw new Error("".concat(context, ": Invalid recursive node hierarchy"));
|
582
573
|
}
|
583
574
|
var promises = new Array();
|
584
|
-
this.logOpen(context
|
575
|
+
this.logOpen("".concat(context, " ").concat(node.name || ""));
|
585
576
|
var loadNode = function (babylonTransformNode) {
|
586
577
|
GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
|
587
578
|
GLTFLoader._LoadTransform(node, babylonTransformNode);
|
588
579
|
if (node.camera != undefined) {
|
589
|
-
var camera = ArrayItem.Get(context
|
590
|
-
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) {
|
591
582
|
babylonCamera.parent = babylonTransformNode;
|
592
583
|
}));
|
593
584
|
}
|
594
585
|
if (node.children) {
|
595
586
|
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
|
596
587
|
var index = _a[_i];
|
597
|
-
var childNode = ArrayItem.Get(context
|
598
|
-
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) {
|
599
590
|
childBabylonMesh.parent = babylonTransformNode;
|
600
591
|
}));
|
601
592
|
}
|
602
593
|
}
|
603
594
|
assign(babylonTransformNode);
|
604
595
|
};
|
605
|
-
if (node.mesh == undefined) {
|
606
|
-
var nodeName = node.name || "node"
|
607
|
-
this._babylonScene._blockEntityCollection = this.
|
596
|
+
if (node.mesh == undefined || node.skin != undefined) {
|
597
|
+
var nodeName = node.name || "node".concat(node.index);
|
598
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
608
599
|
node._babylonTransformNode = new TransformNode(nodeName, this._babylonScene);
|
600
|
+
node._babylonTransformNode._parentContainer = this._assetContainer;
|
609
601
|
this._babylonScene._blockEntityCollection = false;
|
610
602
|
loadNode(node._babylonTransformNode);
|
611
603
|
}
|
612
|
-
|
613
|
-
|
614
|
-
|
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
|
+
}
|
615
635
|
}
|
616
636
|
this.logClose();
|
617
637
|
return Promise.all(promises).then(function () {
|
@@ -630,38 +650,35 @@ var GLTFLoader = /** @class */ (function () {
|
|
630
650
|
GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
|
631
651
|
var primitives = mesh.primitives;
|
632
652
|
if (!primitives || !primitives.length) {
|
633
|
-
throw new Error(context
|
653
|
+
throw new Error("".concat(context, ": Primitives are missing"));
|
634
654
|
}
|
635
655
|
if (primitives[0].index == undefined) {
|
636
656
|
ArrayItem.Assign(primitives);
|
637
657
|
}
|
638
658
|
var promises = new Array();
|
639
|
-
this.logOpen(context
|
640
|
-
var name = node.name || "node"
|
659
|
+
this.logOpen("".concat(context, " ").concat(mesh.name || ""));
|
660
|
+
var name = node.name || "node".concat(node.index);
|
641
661
|
if (primitives.length === 1) {
|
642
662
|
var primitive = mesh.primitives[0];
|
643
|
-
promises.push(this._loadMeshPrimitiveAsync(context
|
663
|
+
promises.push(this._loadMeshPrimitiveAsync("".concat(context, "/primitives/").concat(primitive.index), name, node, mesh, primitive, function (babylonMesh) {
|
644
664
|
node._babylonTransformNode = babylonMesh;
|
645
665
|
node._primitiveBabylonMeshes = [babylonMesh];
|
646
666
|
}));
|
647
667
|
}
|
648
668
|
else {
|
649
|
-
this._babylonScene._blockEntityCollection = this.
|
669
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
650
670
|
node._babylonTransformNode = new TransformNode(name, this._babylonScene);
|
671
|
+
node._babylonTransformNode._parentContainer = this._assetContainer;
|
651
672
|
this._babylonScene._blockEntityCollection = false;
|
652
673
|
node._primitiveBabylonMeshes = [];
|
653
674
|
for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
|
654
675
|
var primitive = primitives_1[_i];
|
655
|
-
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) {
|
656
677
|
babylonMesh.parent = node._babylonTransformNode;
|
657
678
|
node._primitiveBabylonMeshes.push(babylonMesh);
|
658
679
|
}));
|
659
680
|
}
|
660
681
|
}
|
661
|
-
if (node.skin != undefined) {
|
662
|
-
var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
|
663
|
-
promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
|
664
|
-
}
|
665
682
|
assign(node._babylonTransformNode);
|
666
683
|
this.logClose();
|
667
684
|
return Promise.all(promises).then(function () {
|
@@ -684,27 +701,30 @@ var GLTFLoader = /** @class */ (function () {
|
|
684
701
|
if (extensionPromise) {
|
685
702
|
return extensionPromise;
|
686
703
|
}
|
687
|
-
this.logOpen(""
|
704
|
+
this.logOpen("".concat(context));
|
688
705
|
var shouldInstance = (this._disableInstancedMesh === 0) && this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
|
689
706
|
var babylonAbstractMesh;
|
690
707
|
var promise;
|
691
708
|
if (shouldInstance && primitive._instanceData) {
|
692
|
-
this._babylonScene._blockEntityCollection = this.
|
709
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
693
710
|
babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
|
711
|
+
babylonAbstractMesh._parentContainer = this._assetContainer;
|
694
712
|
this._babylonScene._blockEntityCollection = false;
|
695
713
|
promise = primitive._instanceData.promise;
|
696
714
|
}
|
697
715
|
else {
|
698
716
|
var promises = new Array();
|
699
|
-
this._babylonScene._blockEntityCollection = this.
|
717
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
700
718
|
var babylonMesh_1 = new Mesh(name, this._babylonScene);
|
719
|
+
babylonMesh_1._parentContainer = this._assetContainer;
|
701
720
|
this._babylonScene._blockEntityCollection = false;
|
702
721
|
babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
|
703
722
|
this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
|
704
723
|
promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
|
705
724
|
return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
|
706
|
-
_this._babylonScene._blockEntityCollection = _this.
|
725
|
+
_this._babylonScene._blockEntityCollection = !!_this._assetContainer;
|
707
726
|
babylonGeometry.applyToMesh(babylonMesh_1);
|
727
|
+
babylonGeometry._parentContainer = _this._assetContainer;
|
708
728
|
_this._babylonScene._blockEntityCollection = false;
|
709
729
|
});
|
710
730
|
}));
|
@@ -719,8 +739,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
719
739
|
babylonMesh_1.material = babylonMaterial;
|
720
740
|
}
|
721
741
|
else {
|
722
|
-
var material = ArrayItem.Get(context
|
723
|
-
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) {
|
724
744
|
babylonMesh_1.material = babylonMaterial;
|
725
745
|
}));
|
726
746
|
}
|
@@ -749,7 +769,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
749
769
|
}
|
750
770
|
var attributes = primitive.attributes;
|
751
771
|
if (!attributes) {
|
752
|
-
throw new Error(context
|
772
|
+
throw new Error("".concat(context, ": Attributes are missing"));
|
753
773
|
}
|
754
774
|
var promises = new Array();
|
755
775
|
var babylonGeometry = new Geometry(babylonMesh.name, this._babylonScene);
|
@@ -757,8 +777,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
757
777
|
babylonMesh.isUnIndexed = true;
|
758
778
|
}
|
759
779
|
else {
|
760
|
-
var accessor = ArrayItem.Get(context
|
761
|
-
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) {
|
762
782
|
babylonGeometry.setIndices(data);
|
763
783
|
}));
|
764
784
|
}
|
@@ -770,11 +790,32 @@ var GLTFLoader = /** @class */ (function () {
|
|
770
790
|
if (babylonMesh._delayInfo.indexOf(kind) === -1) {
|
771
791
|
babylonMesh._delayInfo.push(kind);
|
772
792
|
}
|
773
|
-
var accessor = ArrayItem.Get(context
|
774
|
-
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) {
|
775
795
|
if (babylonVertexBuffer.getKind() === VertexBuffer.PositionKind && !_this.parent.alwaysComputeBoundingBox && !babylonMesh.skeleton) {
|
776
796
|
var mmin = accessor.min, mmax = accessor.max;
|
777
797
|
if (mmin !== undefined && mmax !== undefined) {
|
798
|
+
if (accessor.normalized && accessor.componentType !== 5126 /* FLOAT */) {
|
799
|
+
var divider = 1;
|
800
|
+
switch (accessor.componentType) {
|
801
|
+
case 5120 /* BYTE */:
|
802
|
+
divider = 127.0;
|
803
|
+
break;
|
804
|
+
case 5121 /* UNSIGNED_BYTE */:
|
805
|
+
divider = 255.0;
|
806
|
+
break;
|
807
|
+
case 5122 /* SHORT */:
|
808
|
+
divider = 32767.0;
|
809
|
+
break;
|
810
|
+
case 5123 /* UNSIGNED_SHORT */:
|
811
|
+
divider = 65535.0;
|
812
|
+
break;
|
813
|
+
}
|
814
|
+
for (var i = 0; i < 3; ++i) {
|
815
|
+
mmin[i] = Math.max(mmin[i] / divider, -1.0);
|
816
|
+
mmax[i] = Math.max(mmax[i] / divider, -1.0);
|
817
|
+
}
|
818
|
+
}
|
778
819
|
var min = TmpVectors.Vector3[0], max = TmpVectors.Vector3[1];
|
779
820
|
min.copyFromFloats.apply(min, mmin);
|
780
821
|
max.copyFromFloats.apply(max, mmax);
|
@@ -796,6 +837,10 @@ var GLTFLoader = /** @class */ (function () {
|
|
796
837
|
loadAttribute("TANGENT", VertexBuffer.TangentKind);
|
797
838
|
loadAttribute("TEXCOORD_0", VertexBuffer.UVKind);
|
798
839
|
loadAttribute("TEXCOORD_1", VertexBuffer.UV2Kind);
|
840
|
+
loadAttribute("TEXCOORD_2", VertexBuffer.UV3Kind);
|
841
|
+
loadAttribute("TEXCOORD_3", VertexBuffer.UV4Kind);
|
842
|
+
loadAttribute("TEXCOORD_4", VertexBuffer.UV5Kind);
|
843
|
+
loadAttribute("TEXCOORD_5", VertexBuffer.UV6Kind);
|
799
844
|
loadAttribute("JOINTS_0", VertexBuffer.MatricesIndicesKind);
|
800
845
|
loadAttribute("WEIGHTS_0", VertexBuffer.MatricesWeightsKind);
|
801
846
|
loadAttribute("JOINTS_1", VertexBuffer.MatricesIndicesExtraKind);
|
@@ -817,14 +862,15 @@ var GLTFLoader = /** @class */ (function () {
|
|
817
862
|
node._numMorphTargets = primitive.targets.length;
|
818
863
|
}
|
819
864
|
else if (primitive.targets.length !== node._numMorphTargets) {
|
820
|
-
throw new Error(context
|
865
|
+
throw new Error("".concat(context, ": Primitives do not have the same number of targets"));
|
821
866
|
}
|
822
867
|
var targetNames = mesh.extras ? mesh.extras.targetNames : null;
|
823
868
|
babylonMesh.morphTargetManager = new MorphTargetManager(babylonMesh.getScene());
|
869
|
+
babylonMesh.morphTargetManager.areUpdatesFrozen = true;
|
824
870
|
for (var index = 0; index < primitive.targets.length; index++) {
|
825
871
|
var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
|
826
|
-
var
|
827
|
-
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()));
|
828
874
|
// TODO: tell the target whether it has positions, normals, tangents
|
829
875
|
}
|
830
876
|
};
|
@@ -836,9 +882,11 @@ var GLTFLoader = /** @class */ (function () {
|
|
836
882
|
var morphTargetManager = babylonMesh.morphTargetManager;
|
837
883
|
for (var index = 0; index < morphTargetManager.numTargets; index++) {
|
838
884
|
var babylonMorphTarget = morphTargetManager.getTarget(index);
|
839
|
-
promises.push(this._loadMorphTargetVertexDataAsync(context
|
885
|
+
promises.push(this._loadMorphTargetVertexDataAsync("".concat(context, "/targets/").concat(index), babylonGeometry, primitive.targets[index], babylonMorphTarget));
|
840
886
|
}
|
841
|
-
return Promise.all(promises).then(function () {
|
887
|
+
return Promise.all(promises).then(function () {
|
888
|
+
morphTargetManager.areUpdatesFrozen = false;
|
889
|
+
});
|
842
890
|
};
|
843
891
|
GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
|
844
892
|
var _this = this;
|
@@ -851,8 +899,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
851
899
|
if (!babylonVertexBuffer) {
|
852
900
|
return;
|
853
901
|
}
|
854
|
-
var accessor = ArrayItem.Get(context
|
855
|
-
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) {
|
856
904
|
setData(babylonVertexBuffer, data);
|
857
905
|
}));
|
858
906
|
};
|
@@ -914,29 +962,22 @@ var GLTFLoader = /** @class */ (function () {
|
|
914
962
|
babylonNode.rotationQuaternion = rotation;
|
915
963
|
babylonNode.scaling = scaling;
|
916
964
|
};
|
917
|
-
GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
|
965
|
+
GLTFLoader.prototype._loadSkinAsync = function (context, node, skin, assign) {
|
918
966
|
var _this = this;
|
919
967
|
var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
|
920
968
|
if (extensionPromise) {
|
921
969
|
return extensionPromise;
|
922
970
|
}
|
923
|
-
var assignSkeleton = function (skeleton) {
|
924
|
-
_this._forEachPrimitive(node, function (babylonMesh) {
|
925
|
-
babylonMesh.skeleton = skeleton;
|
926
|
-
});
|
927
|
-
};
|
928
971
|
if (skin._data) {
|
929
|
-
|
972
|
+
assign(skin._data.babylonSkeleton);
|
930
973
|
return skin._data.promise;
|
931
974
|
}
|
932
|
-
var skeletonId = "skeleton"
|
933
|
-
this._babylonScene._blockEntityCollection = this.
|
975
|
+
var skeletonId = "skeleton".concat(skin.index);
|
976
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
934
977
|
var babylonSkeleton = new Skeleton(skin.name || skeletonId, skeletonId, this._babylonScene);
|
978
|
+
babylonSkeleton._parentContainer = this._assetContainer;
|
935
979
|
this._babylonScene._blockEntityCollection = false;
|
936
|
-
// See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
|
937
|
-
babylonSkeleton.overrideMesh = this._rootBabylonMesh;
|
938
980
|
this._loadBones(context, skin, babylonSkeleton);
|
939
|
-
assignSkeleton(babylonSkeleton);
|
940
981
|
var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
|
941
982
|
_this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
|
942
983
|
});
|
@@ -944,38 +985,102 @@ var GLTFLoader = /** @class */ (function () {
|
|
944
985
|
babylonSkeleton: babylonSkeleton,
|
945
986
|
promise: promise
|
946
987
|
};
|
988
|
+
assign(babylonSkeleton);
|
947
989
|
return promise;
|
948
990
|
};
|
949
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
|
+
}
|
950
1018
|
var babylonBones = {};
|
951
1019
|
for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
|
952
1020
|
var index = _a[_i];
|
953
|
-
var node = ArrayItem.Get(context
|
1021
|
+
var node = ArrayItem.Get("".concat(context, "/joints/").concat(index), this._gltf.nodes, index);
|
954
1022
|
this._loadBone(node, skin, babylonSkeleton, babylonBones);
|
955
1023
|
}
|
956
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
|
+
};
|
957
1053
|
GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
|
958
1054
|
var babylonBone = babylonBones[node.index];
|
959
1055
|
if (babylonBone) {
|
960
1056
|
return babylonBone;
|
961
1057
|
}
|
962
|
-
var
|
963
|
-
if (node.
|
964
|
-
|
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
|
+
}
|
965
1066
|
}
|
966
1067
|
var boneIndex = skin.joints.indexOf(node.index);
|
967
|
-
babylonBone = new Bone(node.name || "joint"
|
1068
|
+
babylonBone = new Bone(node.name || "joint".concat(node.index), babylonSkeleton, parentBabylonBone, this._getNodeMatrix(node), null, null, boneIndex);
|
968
1069
|
babylonBones[node.index] = babylonBone;
|
969
|
-
|
970
|
-
|
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
|
+
});
|
971
1076
|
return babylonBone;
|
972
1077
|
};
|
973
1078
|
GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
|
974
1079
|
if (skin.inverseBindMatrices == undefined) {
|
975
1080
|
return Promise.resolve(null);
|
976
1081
|
}
|
977
|
-
var accessor = ArrayItem.Get(context
|
978
|
-
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);
|
979
1084
|
};
|
980
1085
|
GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
|
981
1086
|
for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
|
@@ -990,7 +1095,6 @@ var GLTFLoader = /** @class */ (function () {
|
|
990
1095
|
if (babylonParentBone) {
|
991
1096
|
baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
|
992
1097
|
}
|
993
|
-
babylonBone.setBindPose(baseMatrix);
|
994
1098
|
babylonBone.updateMatrix(baseMatrix, false, false);
|
995
1099
|
babylonBone._updateDifferenceMatrix(undefined, false);
|
996
1100
|
}
|
@@ -1014,9 +1118,10 @@ var GLTFLoader = /** @class */ (function () {
|
|
1014
1118
|
return extensionPromise;
|
1015
1119
|
}
|
1016
1120
|
var promises = new Array();
|
1017
|
-
this.logOpen(context
|
1018
|
-
this._babylonScene._blockEntityCollection = this.
|
1019
|
-
var babylonCamera = new FreeCamera(camera.name || "camera"
|
1121
|
+
this.logOpen("".concat(context, " ").concat(camera.name || ""));
|
1122
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1123
|
+
var babylonCamera = new FreeCamera(camera.name || "camera".concat(camera.index), Vector3.Zero(), this._babylonScene, false);
|
1124
|
+
babylonCamera._parentContainer = this._assetContainer;
|
1020
1125
|
this._babylonScene._blockEntityCollection = false;
|
1021
1126
|
babylonCamera.ignoreParentScaling = true;
|
1022
1127
|
babylonCamera.rotation = new Vector3(0, Math.PI, 0);
|
@@ -1024,7 +1129,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1024
1129
|
case "perspective" /* PERSPECTIVE */: {
|
1025
1130
|
var perspective = camera.perspective;
|
1026
1131
|
if (!perspective) {
|
1027
|
-
throw new Error(context
|
1132
|
+
throw new Error("".concat(context, ": Camera perspective properties are missing"));
|
1028
1133
|
}
|
1029
1134
|
babylonCamera.fov = perspective.yfov;
|
1030
1135
|
babylonCamera.minZ = perspective.znear;
|
@@ -1033,7 +1138,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1033
1138
|
}
|
1034
1139
|
case "orthographic" /* ORTHOGRAPHIC */: {
|
1035
1140
|
if (!camera.orthographic) {
|
1036
|
-
throw new Error(context
|
1141
|
+
throw new Error("".concat(context, ": Camera orthographic properties are missing"));
|
1037
1142
|
}
|
1038
1143
|
babylonCamera.mode = Camera.ORTHOGRAPHIC_CAMERA;
|
1039
1144
|
babylonCamera.orthoLeft = -camera.orthographic.xmag;
|
@@ -1045,7 +1150,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1045
1150
|
break;
|
1046
1151
|
}
|
1047
1152
|
default: {
|
1048
|
-
throw new Error(context
|
1153
|
+
throw new Error("".concat(context, ": Invalid camera type (").concat(camera.type, ")"));
|
1049
1154
|
}
|
1050
1155
|
}
|
1051
1156
|
GLTFLoader.AddPointerMetadata(babylonCamera, context);
|
@@ -1064,7 +1169,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1064
1169
|
var promises = new Array();
|
1065
1170
|
for (var index = 0; index < animations.length; index++) {
|
1066
1171
|
var animation = animations[index];
|
1067
|
-
promises.push(this.loadAnimationAsync("/animations/"
|
1172
|
+
promises.push(this.loadAnimationAsync("/animations/".concat(animation.index), animation).then(function (animationGroup) {
|
1068
1173
|
// Delete the animation group if it ended up not having any animations in it.
|
1069
1174
|
if (animationGroup.targetedAnimations.length === 0) {
|
1070
1175
|
animationGroup.dispose();
|
@@ -1084,8 +1189,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
1084
1189
|
if (promise) {
|
1085
1190
|
return promise;
|
1086
1191
|
}
|
1087
|
-
this._babylonScene._blockEntityCollection = this.
|
1088
|
-
var babylonAnimationGroup = new AnimationGroup(animation.name || "animation"
|
1192
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1193
|
+
var babylonAnimationGroup = new AnimationGroup(animation.name || "animation".concat(animation.index), this._babylonScene);
|
1194
|
+
babylonAnimationGroup._parentContainer = this._assetContainer;
|
1089
1195
|
this._babylonScene._blockEntityCollection = false;
|
1090
1196
|
animation._babylonAnimationGroup = babylonAnimationGroup;
|
1091
1197
|
var promises = new Array();
|
@@ -1093,7 +1199,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1093
1199
|
ArrayItem.Assign(animation.samplers);
|
1094
1200
|
for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
|
1095
1201
|
var channel = _a[_i];
|
1096
|
-
promises.push(this._loadAnimationChannelAsync(context
|
1202
|
+
promises.push(this._loadAnimationChannelAsync("".concat(context, "/channels/").concat(channel.index), context, animation, channel, babylonAnimationGroup));
|
1097
1203
|
}
|
1098
1204
|
return Promise.all(promises).then(function () {
|
1099
1205
|
babylonAnimationGroup.normalize(0);
|
@@ -1116,14 +1222,14 @@ var GLTFLoader = /** @class */ (function () {
|
|
1116
1222
|
if (channel.target.node == undefined) {
|
1117
1223
|
return Promise.resolve();
|
1118
1224
|
}
|
1119
|
-
var targetNode = ArrayItem.Get(context
|
1225
|
+
var targetNode = ArrayItem.Get("".concat(context, "/target/node"), this._gltf.nodes, channel.target.node);
|
1120
1226
|
// Ignore animations that have no animation targets.
|
1121
1227
|
if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
|
1122
1228
|
(channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
|
1123
1229
|
return Promise.resolve();
|
1124
1230
|
}
|
1125
|
-
var sampler = ArrayItem.Get(context
|
1126
|
-
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) {
|
1127
1233
|
var targetPath;
|
1128
1234
|
var animationType;
|
1129
1235
|
switch (channel.target.path) {
|
@@ -1148,41 +1254,41 @@ var GLTFLoader = /** @class */ (function () {
|
|
1148
1254
|
break;
|
1149
1255
|
}
|
1150
1256
|
default: {
|
1151
|
-
throw new Error(context
|
1257
|
+
throw new Error("".concat(context, "/target/path: Invalid value (").concat(channel.target.path, ")"));
|
1152
1258
|
}
|
1153
1259
|
}
|
1154
1260
|
var outputBufferOffset = 0;
|
1155
1261
|
var getNextOutputValue;
|
1156
1262
|
switch (targetPath) {
|
1157
1263
|
case "position": {
|
1158
|
-
getNextOutputValue = function () {
|
1159
|
-
var value = Vector3.FromArray(data.output, outputBufferOffset);
|
1264
|
+
getNextOutputValue = function (scale) {
|
1265
|
+
var value = Vector3.FromArray(data.output, outputBufferOffset).scaleInPlace(scale);
|
1160
1266
|
outputBufferOffset += 3;
|
1161
1267
|
return value;
|
1162
1268
|
};
|
1163
1269
|
break;
|
1164
1270
|
}
|
1165
1271
|
case "rotationQuaternion": {
|
1166
|
-
getNextOutputValue = function () {
|
1167
|
-
var value = Quaternion.FromArray(data.output, outputBufferOffset);
|
1272
|
+
getNextOutputValue = function (scale) {
|
1273
|
+
var value = Quaternion.FromArray(data.output, outputBufferOffset).scaleInPlace(scale);
|
1168
1274
|
outputBufferOffset += 4;
|
1169
1275
|
return value;
|
1170
1276
|
};
|
1171
1277
|
break;
|
1172
1278
|
}
|
1173
1279
|
case "scaling": {
|
1174
|
-
getNextOutputValue = function () {
|
1175
|
-
var value = Vector3.FromArray(data.output, outputBufferOffset);
|
1280
|
+
getNextOutputValue = function (scale) {
|
1281
|
+
var value = Vector3.FromArray(data.output, outputBufferOffset).scaleInPlace(scale);
|
1176
1282
|
outputBufferOffset += 3;
|
1177
1283
|
return value;
|
1178
1284
|
};
|
1179
1285
|
break;
|
1180
1286
|
}
|
1181
1287
|
case "influence": {
|
1182
|
-
getNextOutputValue = function () {
|
1288
|
+
getNextOutputValue = function (scale) {
|
1183
1289
|
var value = new Array(targetNode._numMorphTargets);
|
1184
1290
|
for (var i = 0; i < targetNode._numMorphTargets; i++) {
|
1185
|
-
value[i] = data.output[outputBufferOffset++];
|
1291
|
+
value[i] = data.output[outputBufferOffset++] * scale;
|
1186
1292
|
}
|
1187
1293
|
return value;
|
1188
1294
|
};
|
@@ -1193,25 +1299,26 @@ var GLTFLoader = /** @class */ (function () {
|
|
1193
1299
|
switch (data.interpolation) {
|
1194
1300
|
case "STEP" /* STEP */: {
|
1195
1301
|
getNextKey = function (frameIndex) { return ({
|
1196
|
-
frame: data.input[frameIndex],
|
1197
|
-
value: getNextOutputValue(),
|
1302
|
+
frame: data.input[frameIndex] * _this.parent.targetFps,
|
1303
|
+
value: getNextOutputValue(1),
|
1198
1304
|
interpolation: AnimationKeyInterpolation.STEP
|
1199
1305
|
}); };
|
1200
1306
|
break;
|
1201
1307
|
}
|
1202
1308
|
case "LINEAR" /* LINEAR */: {
|
1203
1309
|
getNextKey = function (frameIndex) { return ({
|
1204
|
-
frame: data.input[frameIndex],
|
1205
|
-
value: getNextOutputValue()
|
1310
|
+
frame: data.input[frameIndex] * _this.parent.targetFps,
|
1311
|
+
value: getNextOutputValue(1)
|
1206
1312
|
}); };
|
1207
1313
|
break;
|
1208
1314
|
}
|
1209
1315
|
case "CUBICSPLINE" /* CUBICSPLINE */: {
|
1316
|
+
var invTargetFps_1 = 1 / _this.parent.targetFps;
|
1210
1317
|
getNextKey = function (frameIndex) { return ({
|
1211
|
-
frame: data.input[frameIndex],
|
1212
|
-
inTangent: getNextOutputValue(),
|
1213
|
-
value: getNextOutputValue(),
|
1214
|
-
outTangent: getNextOutputValue()
|
1318
|
+
frame: data.input[frameIndex] * _this.parent.targetFps,
|
1319
|
+
inTangent: getNextOutputValue(invTargetFps_1),
|
1320
|
+
value: getNextOutputValue(1),
|
1321
|
+
outTangent: getNextOutputValue(invTargetFps_1)
|
1215
1322
|
}); };
|
1216
1323
|
break;
|
1217
1324
|
}
|
@@ -1222,8 +1329,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1222
1329
|
}
|
1223
1330
|
if (targetPath === "influence") {
|
1224
1331
|
var _loop_2 = function (targetIndex) {
|
1225
|
-
var animationName = babylonAnimationGroup.name
|
1226
|
-
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);
|
1227
1334
|
babylonAnimation.setKeys(keys.map(function (key) { return ({
|
1228
1335
|
frame: key.frame,
|
1229
1336
|
inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
|
@@ -1243,8 +1350,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1243
1350
|
}
|
1244
1351
|
}
|
1245
1352
|
else {
|
1246
|
-
var animationName = babylonAnimationGroup.name
|
1247
|
-
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);
|
1248
1355
|
babylonAnimation.setKeys(keys);
|
1249
1356
|
if (animationTargetOverride != null && animationTargetOverride.animations != null) {
|
1250
1357
|
animationTargetOverride.animations.push(babylonAnimation);
|
@@ -1269,14 +1376,14 @@ var GLTFLoader = /** @class */ (function () {
|
|
1269
1376
|
break;
|
1270
1377
|
}
|
1271
1378
|
default: {
|
1272
|
-
throw new Error(context
|
1379
|
+
throw new Error("".concat(context, "/interpolation: Invalid value (").concat(sampler.interpolation, ")"));
|
1273
1380
|
}
|
1274
1381
|
}
|
1275
|
-
var inputAccessor = ArrayItem.Get(context
|
1276
|
-
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);
|
1277
1384
|
sampler._data = Promise.all([
|
1278
|
-
this._loadFloatAccessorAsync("/accessors/"
|
1279
|
-
this._loadFloatAccessorAsync("/accessors/"
|
1385
|
+
this._loadFloatAccessorAsync("/accessors/".concat(inputAccessor.index), inputAccessor),
|
1386
|
+
this._loadFloatAccessorAsync("/accessors/".concat(outputAccessor.index), outputAccessor)
|
1280
1387
|
]).then(function (_a) {
|
1281
1388
|
var inputData = _a[0], outputData = _a[1];
|
1282
1389
|
return {
|
@@ -1302,11 +1409,11 @@ var GLTFLoader = /** @class */ (function () {
|
|
1302
1409
|
}
|
1303
1410
|
if (!buffer._data) {
|
1304
1411
|
if (buffer.uri) {
|
1305
|
-
buffer._data = this.loadUriAsync(context
|
1412
|
+
buffer._data = this.loadUriAsync("".concat(context, "/uri"), buffer, buffer.uri);
|
1306
1413
|
}
|
1307
1414
|
else {
|
1308
1415
|
if (!this._bin) {
|
1309
|
-
throw new Error(context
|
1416
|
+
throw new Error("".concat(context, ": Uri is missing or the binary glTF is missing its binary chunk"));
|
1310
1417
|
}
|
1311
1418
|
buffer._data = this._bin.readAsync(0, buffer.byteLength);
|
1312
1419
|
}
|
@@ -1316,7 +1423,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1316
1423
|
return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
|
1317
1424
|
}
|
1318
1425
|
catch (e) {
|
1319
|
-
throw new Error(context
|
1426
|
+
throw new Error("".concat(context, ": ").concat(e.message));
|
1320
1427
|
}
|
1321
1428
|
});
|
1322
1429
|
};
|
@@ -1334,8 +1441,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1334
1441
|
if (bufferView._data) {
|
1335
1442
|
return bufferView._data;
|
1336
1443
|
}
|
1337
|
-
var buffer = ArrayItem.Get(context
|
1338
|
-
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);
|
1339
1446
|
return bufferView._data;
|
1340
1447
|
};
|
1341
1448
|
GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
|
@@ -1350,8 +1457,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1350
1457
|
accessor._data = Promise.resolve(new constructor(length));
|
1351
1458
|
}
|
1352
1459
|
else {
|
1353
|
-
var bufferView_1 = ArrayItem.Get(context
|
1354
|
-
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) {
|
1355
1462
|
if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized && (!bufferView_1.byteStride || bufferView_1.byteStride === byteStride)) {
|
1356
1463
|
return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
|
1357
1464
|
}
|
@@ -1368,21 +1475,21 @@ var GLTFLoader = /** @class */ (function () {
|
|
1368
1475
|
var sparse_1 = accessor.sparse;
|
1369
1476
|
accessor._data = accessor._data.then(function (data) {
|
1370
1477
|
var typedArray = data;
|
1371
|
-
var indicesBufferView = ArrayItem.Get(context
|
1372
|
-
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);
|
1373
1480
|
return Promise.all([
|
1374
|
-
_this.loadBufferViewAsync("/bufferViews/"
|
1375
|
-
_this.loadBufferViewAsync("/bufferViews/"
|
1481
|
+
_this.loadBufferViewAsync("/bufferViews/".concat(indicesBufferView.index), indicesBufferView),
|
1482
|
+
_this.loadBufferViewAsync("/bufferViews/".concat(valuesBufferView.index), valuesBufferView)
|
1376
1483
|
]).then(function (_a) {
|
1377
1484
|
var indicesData = _a[0], valuesData = _a[1];
|
1378
|
-
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);
|
1379
1486
|
var sparseLength = numComponents * sparse_1.count;
|
1380
1487
|
var values;
|
1381
1488
|
if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
|
1382
|
-
values = GLTFLoader._GetTypedArray(context
|
1489
|
+
values = GLTFLoader._GetTypedArray("".concat(context, "/sparse/values"), accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
|
1383
1490
|
}
|
1384
1491
|
else {
|
1385
|
-
var sparseData = GLTFLoader._GetTypedArray(context
|
1492
|
+
var sparseData = GLTFLoader._GetTypedArray("".concat(context, "/sparse/values"), accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
|
1386
1493
|
values = new constructor(sparseLength);
|
1387
1494
|
VertexBuffer.ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
|
1388
1495
|
values[index] = value;
|
@@ -1407,23 +1514,23 @@ var GLTFLoader = /** @class */ (function () {
|
|
1407
1514
|
};
|
1408
1515
|
GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
|
1409
1516
|
if (accessor.type !== "SCALAR" /* SCALAR */) {
|
1410
|
-
throw new Error(context
|
1517
|
+
throw new Error("".concat(context, "/type: Invalid value ").concat(accessor.type));
|
1411
1518
|
}
|
1412
1519
|
if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
|
1413
1520
|
accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
|
1414
1521
|
accessor.componentType !== 5125 /* UNSIGNED_INT */) {
|
1415
|
-
throw new Error(context
|
1522
|
+
throw new Error("".concat(context, "/componentType: Invalid value ").concat(accessor.componentType));
|
1416
1523
|
}
|
1417
1524
|
if (accessor._data) {
|
1418
1525
|
return accessor._data;
|
1419
1526
|
}
|
1420
1527
|
if (accessor.sparse) {
|
1421
|
-
var constructor = GLTFLoader._GetTypedArrayConstructor(context
|
1528
|
+
var constructor = GLTFLoader._GetTypedArrayConstructor("".concat(context, "/componentType"), accessor.componentType);
|
1422
1529
|
accessor._data = this._loadAccessorAsync(context, accessor, constructor);
|
1423
1530
|
}
|
1424
1531
|
else {
|
1425
|
-
var bufferView = ArrayItem.Get(context
|
1426
|
-
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) {
|
1427
1534
|
return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
|
1428
1535
|
});
|
1429
1536
|
}
|
@@ -1434,47 +1541,44 @@ var GLTFLoader = /** @class */ (function () {
|
|
1434
1541
|
if (bufferView._babylonBuffer) {
|
1435
1542
|
return bufferView._babylonBuffer;
|
1436
1543
|
}
|
1437
|
-
bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/"
|
1544
|
+
bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView).then(function (data) {
|
1438
1545
|
return new Buffer(_this._babylonScene.getEngine(), data, false);
|
1439
1546
|
});
|
1440
1547
|
return bufferView._babylonBuffer;
|
1441
1548
|
};
|
1442
1549
|
GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
|
1443
1550
|
var _this = this;
|
1444
|
-
|
1445
|
-
|
1551
|
+
var _a;
|
1552
|
+
if ((_a = accessor._babylonVertexBuffer) === null || _a === void 0 ? void 0 : _a[kind]) {
|
1553
|
+
return accessor._babylonVertexBuffer[kind];
|
1446
1554
|
}
|
1447
|
-
if (accessor.
|
1448
|
-
accessor._babylonVertexBuffer =
|
1449
|
-
return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
|
1450
|
-
});
|
1555
|
+
if (!accessor._babylonVertexBuffer) {
|
1556
|
+
accessor._babylonVertexBuffer = {};
|
1451
1557
|
}
|
1452
|
-
|
1453
|
-
|
1454
|
-
Logger.Warn("Accessor byte offset is not a multiple of component type byte length");
|
1455
|
-
accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
|
1558
|
+
if (accessor.sparse) {
|
1559
|
+
accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
|
1456
1560
|
return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
|
1457
1561
|
});
|
1458
1562
|
}
|
1459
1563
|
// Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
|
1460
1564
|
// This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
|
1461
1565
|
else if (kind === VertexBuffer.MatricesIndicesKind || kind === VertexBuffer.MatricesIndicesExtraKind) {
|
1462
|
-
accessor._babylonVertexBuffer = this._loadFloatAccessorAsync(
|
1566
|
+
accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
|
1463
1567
|
return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
|
1464
1568
|
});
|
1465
1569
|
}
|
1466
1570
|
else {
|
1467
|
-
var bufferView_2 = ArrayItem.Get(context
|
1468
|
-
accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
|
1571
|
+
var bufferView_2 = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, accessor.bufferView);
|
1572
|
+
accessor._babylonVertexBuffer[kind] = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
|
1469
1573
|
var size = GLTFLoader._GetNumComponents(context, accessor.type);
|
1470
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);
|
1471
1575
|
});
|
1472
1576
|
}
|
1473
|
-
return accessor._babylonVertexBuffer;
|
1577
|
+
return accessor._babylonVertexBuffer[kind];
|
1474
1578
|
};
|
1475
1579
|
GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
|
1476
1580
|
if (!(babylonMaterial instanceof PBRMaterial)) {
|
1477
|
-
throw new Error(context
|
1581
|
+
throw new Error("".concat(context, ": Material type not supported"));
|
1478
1582
|
}
|
1479
1583
|
var promises = new Array();
|
1480
1584
|
if (properties) {
|
@@ -1488,15 +1592,15 @@ var GLTFLoader = /** @class */ (function () {
|
|
1488
1592
|
babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
|
1489
1593
|
babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
|
1490
1594
|
if (properties.baseColorTexture) {
|
1491
|
-
promises.push(this.loadTextureInfoAsync(context
|
1492
|
-
texture.name = babylonMaterial.name
|
1595
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/baseColorTexture"), properties.baseColorTexture, function (texture) {
|
1596
|
+
texture.name = "".concat(babylonMaterial.name, " (Base Color)");
|
1493
1597
|
babylonMaterial.albedoTexture = texture;
|
1494
1598
|
}));
|
1495
1599
|
}
|
1496
1600
|
if (properties.metallicRoughnessTexture) {
|
1497
1601
|
properties.metallicRoughnessTexture.nonColorData = true;
|
1498
|
-
promises.push(this.loadTextureInfoAsync(context
|
1499
|
-
texture.name = babylonMaterial.name
|
1602
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/metallicRoughnessTexture"), properties.metallicRoughnessTexture, function (texture) {
|
1603
|
+
texture.name = "".concat(babylonMaterial.name, " (Metallic Roughness)");
|
1500
1604
|
babylonMaterial.metallicTexture = texture;
|
1501
1605
|
}));
|
1502
1606
|
babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
|
@@ -1516,7 +1620,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1516
1620
|
material._data = material._data || {};
|
1517
1621
|
var babylonData = material._data[babylonDrawMode];
|
1518
1622
|
if (!babylonData) {
|
1519
|
-
this.logOpen(context
|
1623
|
+
this.logOpen("".concat(context, " ").concat(material.name || ""));
|
1520
1624
|
var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
|
1521
1625
|
babylonData = {
|
1522
1626
|
babylonMaterial: babylonMaterial,
|
@@ -1543,8 +1647,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
1543
1647
|
});
|
1544
1648
|
};
|
1545
1649
|
GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
|
1546
|
-
this._babylonScene._blockEntityCollection = this.
|
1650
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1547
1651
|
var babylonMaterial = new PBRMaterial(name, this._babylonScene);
|
1652
|
+
babylonMaterial._parentContainer = this._assetContainer;
|
1548
1653
|
this._babylonScene._blockEntityCollection = false;
|
1549
1654
|
// Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
|
1550
1655
|
babylonMaterial.fillMode = babylonDrawMode;
|
@@ -1568,7 +1673,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1568
1673
|
if (extensionPromise) {
|
1569
1674
|
return extensionPromise;
|
1570
1675
|
}
|
1571
|
-
var name = material.name || "material"
|
1676
|
+
var name = material.name || "material".concat(material.index);
|
1572
1677
|
var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
|
1573
1678
|
return babylonMaterial;
|
1574
1679
|
};
|
@@ -1587,7 +1692,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1587
1692
|
var promises = new Array();
|
1588
1693
|
promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
|
1589
1694
|
if (material.pbrMetallicRoughness) {
|
1590
|
-
promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context
|
1695
|
+
promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync("".concat(context, "/pbrMetallicRoughness"), material.pbrMetallicRoughness, babylonMaterial));
|
1591
1696
|
}
|
1592
1697
|
this.loadMaterialAlphaProperties(context, material, babylonMaterial);
|
1593
1698
|
return Promise.all(promises).then(function () { });
|
@@ -1601,7 +1706,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1601
1706
|
*/
|
1602
1707
|
GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
|
1603
1708
|
if (!(babylonMaterial instanceof PBRMaterial)) {
|
1604
|
-
throw new Error(context
|
1709
|
+
throw new Error("".concat(context, ": Material type not supported"));
|
1605
1710
|
}
|
1606
1711
|
var promises = new Array();
|
1607
1712
|
babylonMaterial.emissiveColor = material.emissiveFactor ? Color3.FromArray(material.emissiveFactor) : new Color3(0, 0, 0);
|
@@ -1611,8 +1716,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1611
1716
|
}
|
1612
1717
|
if (material.normalTexture) {
|
1613
1718
|
material.normalTexture.nonColorData = true;
|
1614
|
-
promises.push(this.loadTextureInfoAsync(context
|
1615
|
-
texture.name = babylonMaterial.name
|
1719
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/normalTexture"), material.normalTexture, function (texture) {
|
1720
|
+
texture.name = "".concat(babylonMaterial.name, " (Normal)");
|
1616
1721
|
babylonMaterial.bumpTexture = texture;
|
1617
1722
|
}));
|
1618
1723
|
babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
|
@@ -1624,8 +1729,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1624
1729
|
}
|
1625
1730
|
if (material.occlusionTexture) {
|
1626
1731
|
material.occlusionTexture.nonColorData = true;
|
1627
|
-
promises.push(this.loadTextureInfoAsync(context
|
1628
|
-
texture.name = babylonMaterial.name
|
1732
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/occlusionTexture"), material.occlusionTexture, function (texture) {
|
1733
|
+
texture.name = "".concat(babylonMaterial.name, " (Occlusion)");
|
1629
1734
|
babylonMaterial.ambientTexture = texture;
|
1630
1735
|
}));
|
1631
1736
|
babylonMaterial.useAmbientInGrayScale = true;
|
@@ -1634,8 +1739,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1634
1739
|
}
|
1635
1740
|
}
|
1636
1741
|
if (material.emissiveTexture) {
|
1637
|
-
promises.push(this.loadTextureInfoAsync(context
|
1638
|
-
texture.name = babylonMaterial.name
|
1742
|
+
promises.push(this.loadTextureInfoAsync("".concat(context, "/emissiveTexture"), material.emissiveTexture, function (texture) {
|
1743
|
+
texture.name = "".concat(babylonMaterial.name, " (Emissive)");
|
1639
1744
|
babylonMaterial.emissiveTexture = texture;
|
1640
1745
|
}));
|
1641
1746
|
}
|
@@ -1650,7 +1755,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1650
1755
|
*/
|
1651
1756
|
GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
|
1652
1757
|
if (!(babylonMaterial instanceof PBRMaterial)) {
|
1653
|
-
throw new Error(context
|
1758
|
+
throw new Error("".concat(context, ": Material type not supported"));
|
1654
1759
|
}
|
1655
1760
|
var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
|
1656
1761
|
switch (alphaMode) {
|
@@ -1675,7 +1780,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1675
1780
|
break;
|
1676
1781
|
}
|
1677
1782
|
default: {
|
1678
|
-
throw new Error(context
|
1783
|
+
throw new Error("".concat(context, "/alphaMode: Invalid value (").concat(material.alphaMode, ")"));
|
1679
1784
|
}
|
1680
1785
|
}
|
1681
1786
|
};
|
@@ -1693,13 +1798,13 @@ var GLTFLoader = /** @class */ (function () {
|
|
1693
1798
|
if (extensionPromise) {
|
1694
1799
|
return extensionPromise;
|
1695
1800
|
}
|
1696
|
-
this.logOpen(""
|
1697
|
-
if (textureInfo.texCoord >=
|
1698
|
-
throw new Error(context
|
1801
|
+
this.logOpen("".concat(context));
|
1802
|
+
if (textureInfo.texCoord >= 6) {
|
1803
|
+
throw new Error("".concat(context, "/texCoord: Invalid value (").concat(textureInfo.texCoord, ")"));
|
1699
1804
|
}
|
1700
|
-
var texture = ArrayItem.Get(context
|
1805
|
+
var texture = ArrayItem.Get("".concat(context, "/index"), this._gltf.textures, textureInfo.index);
|
1701
1806
|
texture._textureInfo = textureInfo;
|
1702
|
-
var promise = this._loadTextureAsync("/textures/"
|
1807
|
+
var promise = this._loadTextureAsync("/textures/".concat(textureInfo.index), texture, function (babylonTexture) {
|
1703
1808
|
babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
|
1704
1809
|
GLTFLoader.AddPointerMetadata(babylonTexture, context);
|
1705
1810
|
_this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
|
@@ -1715,35 +1820,46 @@ var GLTFLoader = /** @class */ (function () {
|
|
1715
1820
|
if (extensionPromise) {
|
1716
1821
|
return extensionPromise;
|
1717
1822
|
}
|
1718
|
-
this.logOpen(context
|
1719
|
-
var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context
|
1720
|
-
var image = ArrayItem.Get(context
|
1721
|
-
var promise = this._createTextureAsync(context, sampler, image, assign);
|
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);
|
1826
|
+
var promise = this._createTextureAsync(context, sampler, image, assign, undefined, !texture._textureInfo.nonColorData);
|
1722
1827
|
this.logClose();
|
1723
1828
|
return promise;
|
1724
1829
|
};
|
1725
1830
|
/** @hidden */
|
1726
|
-
GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign, textureLoaderOptions) {
|
1831
|
+
GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign, textureLoaderOptions, useSRGBBuffer) {
|
1727
1832
|
var _this = this;
|
1728
1833
|
if (assign === void 0) { assign = function () { }; }
|
1729
|
-
var samplerData = this._loadSampler("/samplers/"
|
1834
|
+
var samplerData = this._loadSampler("/samplers/".concat(sampler.index), sampler);
|
1730
1835
|
var promises = new Array();
|
1731
1836
|
var deferred = new Deferred();
|
1732
|
-
this._babylonScene._blockEntityCollection = this.
|
1733
|
-
var
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1837
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1838
|
+
var textureCreationOptions = {
|
1839
|
+
noMipmap: samplerData.noMipMaps,
|
1840
|
+
invertY: false,
|
1841
|
+
samplingMode: samplerData.samplingMode,
|
1842
|
+
onLoad: function () {
|
1843
|
+
if (!_this._disposed) {
|
1844
|
+
deferred.resolve();
|
1845
|
+
}
|
1846
|
+
},
|
1847
|
+
onError: function (message, exception) {
|
1848
|
+
if (!_this._disposed) {
|
1849
|
+
deferred.reject(new Error("".concat(context, ": ").concat((exception && exception.message) ? exception.message : message || "Failed to load texture")));
|
1850
|
+
}
|
1851
|
+
},
|
1852
|
+
mimeType: image.mimeType,
|
1853
|
+
loaderOptions: textureLoaderOptions,
|
1854
|
+
useSRGBBuffer: !!useSRGBBuffer && this._parent.useSRGBBuffers,
|
1855
|
+
};
|
1856
|
+
var babylonTexture = new Texture(null, this._babylonScene, textureCreationOptions);
|
1857
|
+
babylonTexture._parentContainer = this._assetContainer;
|
1742
1858
|
this._babylonScene._blockEntityCollection = false;
|
1743
1859
|
promises.push(deferred.promise);
|
1744
|
-
promises.push(this.loadImageAsync("/images/"
|
1745
|
-
var name = image.uri || _this._fileName
|
1746
|
-
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);
|
1747
1863
|
babylonTexture.updateURL(dataUrl, data);
|
1748
1864
|
}));
|
1749
1865
|
babylonTexture.wrapU = samplerData.wrapU;
|
@@ -1758,8 +1874,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
1758
1874
|
sampler._data = {
|
1759
1875
|
noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
|
1760
1876
|
samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
|
1761
|
-
wrapU: GLTFLoader._GetTextureWrapMode(context
|
1762
|
-
wrapV: GLTFLoader._GetTextureWrapMode(context
|
1877
|
+
wrapU: GLTFLoader._GetTextureWrapMode("".concat(context, "/wrapS"), sampler.wrapS),
|
1878
|
+
wrapV: GLTFLoader._GetTextureWrapMode("".concat(context, "/wrapT"), sampler.wrapT)
|
1763
1879
|
};
|
1764
1880
|
}
|
1765
1881
|
return sampler._data;
|
@@ -1772,13 +1888,13 @@ var GLTFLoader = /** @class */ (function () {
|
|
1772
1888
|
*/
|
1773
1889
|
GLTFLoader.prototype.loadImageAsync = function (context, image) {
|
1774
1890
|
if (!image._data) {
|
1775
|
-
this.logOpen(context
|
1891
|
+
this.logOpen("".concat(context, " ").concat(image.name || ""));
|
1776
1892
|
if (image.uri) {
|
1777
|
-
image._data = this.loadUriAsync(context
|
1893
|
+
image._data = this.loadUriAsync("".concat(context, "/uri"), image, image.uri);
|
1778
1894
|
}
|
1779
1895
|
else {
|
1780
|
-
var bufferView = ArrayItem.Get(context
|
1781
|
-
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);
|
1782
1898
|
}
|
1783
1899
|
this.logClose();
|
1784
1900
|
}
|
@@ -1798,23 +1914,23 @@ var GLTFLoader = /** @class */ (function () {
|
|
1798
1914
|
return extensionPromise;
|
1799
1915
|
}
|
1800
1916
|
if (!GLTFLoader._ValidateUri(uri)) {
|
1801
|
-
throw new Error(context
|
1917
|
+
throw new Error("".concat(context, ": '").concat(uri, "' is invalid"));
|
1802
1918
|
}
|
1803
|
-
if (
|
1804
|
-
var data = new Uint8Array(
|
1805
|
-
this.log(context
|
1919
|
+
if (IsBase64DataUrl(uri)) {
|
1920
|
+
var data = new Uint8Array(DecodeBase64UrlToBinary(uri));
|
1921
|
+
this.log("".concat(context, ": Decoded ").concat(uri.substr(0, 64), "... (").concat(data.length, " bytes)"));
|
1806
1922
|
return Promise.resolve(data);
|
1807
1923
|
}
|
1808
|
-
this.log(context
|
1924
|
+
this.log("".concat(context, ": Loading ").concat(uri));
|
1809
1925
|
return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
|
1810
1926
|
return new Promise(function (resolve, reject) {
|
1811
|
-
_this._parent._loadFile(
|
1927
|
+
_this._parent._loadFile(_this._babylonScene, url, function (data) {
|
1812
1928
|
if (!_this._disposed) {
|
1813
|
-
_this.log(context
|
1929
|
+
_this.log("".concat(context, ": Loaded ").concat(uri, " (").concat(data.byteLength, " bytes)"));
|
1814
1930
|
resolve(new Uint8Array(data));
|
1815
1931
|
}
|
1816
1932
|
}, true, function (request) {
|
1817
|
-
reject(new LoadFileError(context
|
1933
|
+
reject(new LoadFileError("".concat(context, ": Failed to load '").concat(uri, "'").concat(request ? ": " + request.status + " " + request.statusText : ""), request));
|
1818
1934
|
});
|
1819
1935
|
});
|
1820
1936
|
});
|
@@ -1838,7 +1954,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1838
1954
|
case 33648 /* MIRRORED_REPEAT */: return Texture.MIRROR_ADDRESSMODE;
|
1839
1955
|
case 10497 /* REPEAT */: return Texture.WRAP_ADDRESSMODE;
|
1840
1956
|
default:
|
1841
|
-
Logger.Warn(context
|
1957
|
+
Logger.Warn("".concat(context, ": Invalid value (").concat(mode, ")"));
|
1842
1958
|
return Texture.WRAP_ADDRESSMODE;
|
1843
1959
|
}
|
1844
1960
|
};
|
@@ -1855,13 +1971,13 @@ var GLTFLoader = /** @class */ (function () {
|
|
1855
1971
|
case 9986 /* NEAREST_MIPMAP_LINEAR */: return Texture.LINEAR_NEAREST_MIPLINEAR;
|
1856
1972
|
case 9987 /* LINEAR_MIPMAP_LINEAR */: return Texture.LINEAR_LINEAR_MIPLINEAR;
|
1857
1973
|
default:
|
1858
|
-
Logger.Warn(context
|
1974
|
+
Logger.Warn("".concat(context, "/minFilter: Invalid value (").concat(minFilter, ")"));
|
1859
1975
|
return Texture.LINEAR_LINEAR_MIPLINEAR;
|
1860
1976
|
}
|
1861
1977
|
}
|
1862
1978
|
else {
|
1863
1979
|
if (magFilter !== 9728 /* NEAREST */) {
|
1864
|
-
Logger.Warn(context
|
1980
|
+
Logger.Warn("".concat(context, "/magFilter: Invalid value (").concat(magFilter, ")"));
|
1865
1981
|
}
|
1866
1982
|
switch (minFilter) {
|
1867
1983
|
case 9728 /* NEAREST */: return Texture.NEAREST_NEAREST;
|
@@ -1871,7 +1987,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1871
1987
|
case 9986 /* NEAREST_MIPMAP_LINEAR */: return Texture.NEAREST_NEAREST_MIPLINEAR;
|
1872
1988
|
case 9987 /* LINEAR_MIPMAP_LINEAR */: return Texture.NEAREST_LINEAR_MIPLINEAR;
|
1873
1989
|
default:
|
1874
|
-
Logger.Warn(context
|
1990
|
+
Logger.Warn("".concat(context, "/minFilter: Invalid value (").concat(minFilter, ")"));
|
1875
1991
|
return Texture.NEAREST_NEAREST_MIPNEAREST;
|
1876
1992
|
}
|
1877
1993
|
}
|
@@ -1884,19 +2000,20 @@ var GLTFLoader = /** @class */ (function () {
|
|
1884
2000
|
case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
|
1885
2001
|
case 5125 /* UNSIGNED_INT */: return Uint32Array;
|
1886
2002
|
case 5126 /* FLOAT */: return Float32Array;
|
1887
|
-
default: throw new Error(context
|
2003
|
+
default: throw new Error("".concat(context, ": Invalid component type ").concat(componentType));
|
1888
2004
|
}
|
1889
2005
|
};
|
1890
2006
|
GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
|
1891
2007
|
var buffer = bufferView.buffer;
|
1892
2008
|
byteOffset = bufferView.byteOffset + (byteOffset || 0);
|
1893
|
-
var constructor = GLTFLoader._GetTypedArrayConstructor(context
|
1894
|
-
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
2009
|
+
var constructor = GLTFLoader._GetTypedArrayConstructor("".concat(context, "/componentType"), componentType);
|
2010
|
+
var componentTypeLength = VertexBuffer.GetTypeByteLength(componentType);
|
2011
|
+
if (byteOffset % componentTypeLength !== 0) {
|
2012
|
+
// HACK: Copy the buffer if byte offset is not a multiple of component type byte length.
|
2013
|
+
Logger.Warn("".concat(context, ": Copying buffer as byte offset (").concat(byteOffset, ") is not a multiple of component type byte length (").concat(componentTypeLength, ")"));
|
2014
|
+
return new constructor(buffer.slice(byteOffset, byteOffset + length * componentTypeLength), 0);
|
1899
2015
|
}
|
2016
|
+
return new constructor(buffer, byteOffset, length);
|
1900
2017
|
};
|
1901
2018
|
GLTFLoader._GetNumComponents = function (context, type) {
|
1902
2019
|
switch (type) {
|
@@ -1908,7 +2025,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1908
2025
|
case "MAT3": return 9;
|
1909
2026
|
case "MAT4": return 16;
|
1910
2027
|
}
|
1911
|
-
throw new Error(context
|
2028
|
+
throw new Error("".concat(context, ": Invalid type (").concat(type, ")"));
|
1912
2029
|
};
|
1913
2030
|
GLTFLoader._ValidateUri = function (uri) {
|
1914
2031
|
return (Tools.IsBase64(uri) || uri.indexOf("..") === -1);
|
@@ -1927,7 +2044,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1927
2044
|
case 5 /* TRIANGLE_STRIP */: return Material.TriangleStripDrawMode;
|
1928
2045
|
case 6 /* TRIANGLE_FAN */: return Material.TriangleFanDrawMode;
|
1929
2046
|
}
|
1930
|
-
throw new Error(context
|
2047
|
+
throw new Error("".concat(context, ": Invalid mesh primitive mode (").concat(mode, ")"));
|
1931
2048
|
};
|
1932
2049
|
GLTFLoader.prototype._compileMaterialsAsync = function () {
|
1933
2050
|
var _this = this;
|
@@ -1987,7 +2104,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1987
2104
|
for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
|
1988
2105
|
var extension = _a[_i];
|
1989
2106
|
if (extension.enabled) {
|
1990
|
-
var id = extension.name
|
2107
|
+
var id = "".concat(extension.name, ".").concat(functionName);
|
1991
2108
|
var loaderProperty = property;
|
1992
2109
|
loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
|
1993
2110
|
var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
|
@@ -2075,7 +2192,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
2075
2192
|
if (!extension) {
|
2076
2193
|
return null;
|
2077
2194
|
}
|
2078
|
-
return actionAsync(context
|
2195
|
+
return actionAsync("".concat(context, "/extensions/").concat(extensionName), extension);
|
2079
2196
|
};
|
2080
2197
|
/**
|
2081
2198
|
* Helper method called by a loader extension to load a glTF extra.
|
@@ -2094,7 +2211,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
2094
2211
|
if (!extra) {
|
2095
2212
|
return null;
|
2096
2213
|
}
|
2097
|
-
return actionAsync(context
|
2214
|
+
return actionAsync("".concat(context, "/extras/").concat(extensionName), extra);
|
2098
2215
|
};
|
2099
2216
|
/**
|
2100
2217
|
* Checks for presence of an extension.
|