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