|
@@ -1084,6 +1084,10 @@ var BABYLON;
|
|
|
*/
|
|
|
this.compileShadowGenerators = false;
|
|
|
/**
|
|
|
+ * Function called before loading a url referenced by the asset.
|
|
|
+ */
|
|
|
+ this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
|
|
|
+ /**
|
|
|
* Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
|
|
|
*/
|
|
|
this.onMeshLoadedObservable = new BABYLON.Observable();
|
|
@@ -1262,6 +1266,7 @@ var BABYLON;
|
|
|
this._loader.dispose();
|
|
|
this._loader = null;
|
|
|
}
|
|
|
+ this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
|
|
|
this.onMeshLoadedObservable.clear();
|
|
|
this.onTextureLoadedObservable.clear();
|
|
|
this.onMaterialLoadedObservable.clear();
|
|
@@ -1389,6 +1394,7 @@ var BABYLON;
|
|
|
loader.compileMaterials = this.compileMaterials;
|
|
|
loader.useClipPlane = this.useClipPlane;
|
|
|
loader.compileShadowGenerators = this.compileShadowGenerators;
|
|
|
+ loader.preprocessUrlAsync = this.preprocessUrlAsync;
|
|
|
loader.onMeshLoadedObservable.add(function (mesh) { return _this.onMeshLoadedObservable.notifyObservers(mesh); });
|
|
|
loader.onTextureLoadedObservable.add(function (texture) { return _this.onTextureLoadedObservable.notifyObservers(texture); });
|
|
|
loader.onMaterialLoadedObservable.add(function (material) { return _this.onMaterialLoadedObservable.notifyObservers(material); });
|
|
@@ -2968,16 +2974,14 @@ var BABYLON;
|
|
|
this.compileMaterials = false;
|
|
|
this.useClipPlane = false;
|
|
|
this.compileShadowGenerators = false;
|
|
|
- this.onDisposeObservable = new BABYLON.Observable();
|
|
|
+ this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
|
|
|
this.onMeshLoadedObservable = new BABYLON.Observable();
|
|
|
this.onTextureLoadedObservable = new BABYLON.Observable();
|
|
|
this.onMaterialLoadedObservable = new BABYLON.Observable();
|
|
|
this.onCameraLoadedObservable = new BABYLON.Observable();
|
|
|
this.onCompleteObservable = new BABYLON.Observable();
|
|
|
+ this.onDisposeObservable = new BABYLON.Observable();
|
|
|
this.onExtensionLoadedObservable = new BABYLON.Observable();
|
|
|
- /**
|
|
|
- * State of the loader
|
|
|
- */
|
|
|
this.state = null;
|
|
|
}
|
|
|
GLTFLoader.RegisterExtension = function (extension) {
|
|
@@ -3846,6 +3850,10 @@ var BABYLON;
|
|
|
*/
|
|
|
this.compileShadowGenerators = false;
|
|
|
/**
|
|
|
+ * Function called before loading a url referenced by the asset.
|
|
|
+ */
|
|
|
+ this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
|
|
|
+ /**
|
|
|
* Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
|
|
|
*/
|
|
|
this.onMeshLoadedObservable = new BABYLON.Observable();
|
|
@@ -3879,13 +3887,13 @@ var BABYLON;
|
|
|
}
|
|
|
/** @hidden */
|
|
|
GLTFLoader._Register = function (name, factory) {
|
|
|
- if (GLTFLoader._Factories[name]) {
|
|
|
+ if (GLTFLoader._ExtensionFactories[name]) {
|
|
|
BABYLON.Tools.Error("Extension with the name '" + name + "' already exists");
|
|
|
return;
|
|
|
}
|
|
|
- GLTFLoader._Factories[name] = factory;
|
|
|
+ GLTFLoader._ExtensionFactories[name] = factory;
|
|
|
// Keep the order of registration so that extensions registered first are called first.
|
|
|
- GLTFLoader._Names.push(name);
|
|
|
+ GLTFLoader._ExtensionNames.push(name);
|
|
|
};
|
|
|
Object.defineProperty(GLTFLoader.prototype, "state", {
|
|
|
/**
|
|
@@ -4008,15 +4016,17 @@ var BABYLON;
|
|
|
});
|
|
|
return resultPromise;
|
|
|
}).catch(function (error) {
|
|
|
- BABYLON.Tools.Error("glTF Loader: " + error.message);
|
|
|
- _this._clear();
|
|
|
- throw error;
|
|
|
+ if (!_this._disposed) {
|
|
|
+ BABYLON.Tools.Error("glTF Loader: " + error.message);
|
|
|
+ _this._clear();
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
});
|
|
|
};
|
|
|
GLTFLoader.prototype._loadExtensions = function () {
|
|
|
- for (var _i = 0, _a = GLTFLoader._Names; _i < _a.length; _i++) {
|
|
|
+ for (var _i = 0, _a = GLTFLoader._ExtensionNames; _i < _a.length; _i++) {
|
|
|
var name_1 = _a[_i];
|
|
|
- var extension = GLTFLoader._Factories[name_1](this);
|
|
|
+ var extension = GLTFLoader._ExtensionFactories[name_1](this);
|
|
|
this._extensions[name_1] = extension;
|
|
|
this.onExtensionLoadedObservable.notifyObservers(extension);
|
|
|
}
|
|
@@ -5095,31 +5105,35 @@ var BABYLON;
|
|
|
if (BABYLON.Tools.IsBase64(uri)) {
|
|
|
return Promise.resolve(new Uint8Array(BABYLON.Tools.DecodeBase64(uri)));
|
|
|
}
|
|
|
- return new Promise(function (resolve, reject) {
|
|
|
- var request = BABYLON.Tools.LoadFile(_this._rootUrl + uri, function (data) {
|
|
|
+ return this.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
if (!_this._disposed) {
|
|
|
- resolve(new Uint8Array(data));
|
|
|
- }
|
|
|
- }, function (event) {
|
|
|
- if (!_this._disposed) {
|
|
|
- try {
|
|
|
- if (request && _this._state === BABYLON.GLTFLoaderState.LOADING) {
|
|
|
- request._lengthComputable = event.lengthComputable;
|
|
|
- request._loaded = event.loaded;
|
|
|
- request._total = event.total;
|
|
|
- _this._onProgress();
|
|
|
+ var request_1 = BABYLON.Tools.LoadFile(url, function (data) {
|
|
|
+ if (!_this._disposed) {
|
|
|
+ resolve(new Uint8Array(data));
|
|
|
}
|
|
|
- }
|
|
|
- catch (e) {
|
|
|
- reject(e);
|
|
|
- }
|
|
|
- }
|
|
|
- }, _this._babylonScene.database, true, function (request, exception) {
|
|
|
- if (!_this._disposed) {
|
|
|
- reject(new BABYLON.LoadFileError(context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
|
|
|
+ }, function (event) {
|
|
|
+ if (!_this._disposed) {
|
|
|
+ try {
|
|
|
+ if (request_1 && _this._state === BABYLON.GLTFLoaderState.LOADING) {
|
|
|
+ request_1._lengthComputable = event.lengthComputable;
|
|
|
+ request_1._loaded = event.loaded;
|
|
|
+ request_1._total = event.total;
|
|
|
+ _this._onProgress();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+ reject(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, _this._babylonScene.database, true, function (request, exception) {
|
|
|
+ if (!_this._disposed) {
|
|
|
+ reject(new BABYLON.LoadFileError(context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ _this._requests.push(request_1);
|
|
|
}
|
|
|
});
|
|
|
- _this._requests.push(request);
|
|
|
});
|
|
|
};
|
|
|
GLTFLoader.prototype._onProgress = function () {
|
|
@@ -5310,7 +5324,7 @@ var BABYLON;
|
|
|
};
|
|
|
/** @hidden */
|
|
|
GLTFLoader.prototype._applyExtensions = function (actionAsync) {
|
|
|
- for (var _i = 0, _a = GLTFLoader._Names; _i < _a.length; _i++) {
|
|
|
+ for (var _i = 0, _a = GLTFLoader._ExtensionNames; _i < _a.length; _i++) {
|
|
|
var name_5 = _a[_i];
|
|
|
var extension = this._extensions[name_5];
|
|
|
if (extension.enabled) {
|
|
@@ -5322,8 +5336,8 @@ var BABYLON;
|
|
|
}
|
|
|
return null;
|
|
|
};
|
|
|
- GLTFLoader._Names = new Array();
|
|
|
- GLTFLoader._Factories = {};
|
|
|
+ GLTFLoader._ExtensionNames = new Array();
|
|
|
+ GLTFLoader._ExtensionFactories = {};
|
|
|
return GLTFLoader;
|
|
|
}());
|
|
|
GLTF2.GLTFLoader = GLTFLoader;
|