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