|
@@ -5808,6 +5808,22 @@ var BABYLON;
|
|
return LoadFileError;
|
|
return LoadFileError;
|
|
}(Error));
|
|
}(Error));
|
|
BABYLON.LoadFileError = LoadFileError;
|
|
BABYLON.LoadFileError = LoadFileError;
|
|
|
|
+ var RetryStrategy = /** @class */ (function () {
|
|
|
|
+ function RetryStrategy() {
|
|
|
|
+ }
|
|
|
|
+ RetryStrategy.ExponentialBackoff = function (maxRetries, baseInterval) {
|
|
|
|
+ if (maxRetries === void 0) { maxRetries = 3; }
|
|
|
|
+ if (baseInterval === void 0) { baseInterval = 500; }
|
|
|
|
+ return function (url, request, retryIndex) {
|
|
|
|
+ if (request.status !== 0 || retryIndex >= maxRetries || url.indexOf("file:") !== -1) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ return Math.pow(2, retryIndex) * baseInterval;
|
|
|
|
+ };
|
|
|
|
+ };
|
|
|
|
+ return RetryStrategy;
|
|
|
|
+ }());
|
|
|
|
+ BABYLON.RetryStrategy = RetryStrategy;
|
|
// Screenshots
|
|
// Screenshots
|
|
var screenshotCanvas;
|
|
var screenshotCanvas;
|
|
var cloneValue = function (source, destinationObject) {
|
|
var cloneValue = function (source, destinationObject) {
|
|
@@ -6198,11 +6214,13 @@ var BABYLON;
|
|
}
|
|
}
|
|
return img;
|
|
return img;
|
|
};
|
|
};
|
|
- Tools.LoadFile = function (url, callback, progressCallBack, database, useArrayBuffer, onError) {
|
|
|
|
|
|
+ Tools.LoadFile = function (url, callback, progressCallBack, database, useArrayBuffer, onError, onRetry, retryStrategy) {
|
|
|
|
+ if (retryStrategy === void 0) { retryStrategy = null; }
|
|
url = Tools.CleanUrl(url);
|
|
url = Tools.CleanUrl(url);
|
|
url = Tools.PreprocessUrl(url);
|
|
url = Tools.PreprocessUrl(url);
|
|
var request = null;
|
|
var request = null;
|
|
- var noIndexedDB = function () {
|
|
|
|
|
|
+ var noIndexedDB = function (retryIndex) {
|
|
|
|
+ var oldRequest = request;
|
|
request = new XMLHttpRequest();
|
|
request = new XMLHttpRequest();
|
|
var loadUrl = Tools.BaseUrl + url;
|
|
var loadUrl = Tools.BaseUrl + url;
|
|
request.open('GET', loadUrl, true);
|
|
request.open('GET', loadUrl, true);
|
|
@@ -6219,19 +6237,29 @@ var BABYLON;
|
|
req.onreadystatechange = function () { }; //some browsers have issues where onreadystatechange can be called multiple times with the same value
|
|
req.onreadystatechange = function () { }; //some browsers have issues where onreadystatechange can be called multiple times with the same value
|
|
if (req.status >= 200 && req.status < 300 || (!Tools.IsWindowObjectExist() && (req.status === 0))) {
|
|
if (req.status >= 200 && req.status < 300 || (!Tools.IsWindowObjectExist() && (req.status === 0))) {
|
|
callback(!useArrayBuffer ? req.responseText : req.response, req.responseURL);
|
|
callback(!useArrayBuffer ? req.responseText : req.response, req.responseURL);
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- var e = new LoadFileError("Error status: " + req.status + " - Unable to load " + loadUrl, req);
|
|
|
|
- if (onError) {
|
|
|
|
- onError(req, e);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- throw e;
|
|
|
|
|
|
+ retryStrategy = retryStrategy || Tools.DefaultRetryStrategy;
|
|
|
|
+ if (retryStrategy) {
|
|
|
|
+ var waitTime = retryStrategy(loadUrl, req, retryIndex || 0);
|
|
|
|
+ if (waitTime !== -1) {
|
|
|
|
+ setTimeout(function () { return noIndexedDB((retryIndex || 0) + 1); }, waitTime);
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ var e = new Error("Error status: " + req.status + " - Unable to load " + loadUrl);
|
|
|
|
+ if (onError) {
|
|
|
|
+ onError(req, e);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- request.send(null);
|
|
|
|
|
|
+ request.send();
|
|
|
|
+ if (oldRequest && onRetry) {
|
|
|
|
+ onRetry(oldRequest, request);
|
|
|
|
+ }
|
|
};
|
|
};
|
|
var loadFromIndexedDB = function () {
|
|
var loadFromIndexedDB = function () {
|
|
if (database) {
|
|
if (database) {
|
|
@@ -6962,6 +6990,7 @@ var BABYLON;
|
|
return hash;
|
|
return hash;
|
|
};
|
|
};
|
|
Tools.BaseUrl = "";
|
|
Tools.BaseUrl = "";
|
|
|
|
+ Tools.DefaultRetryStrategy = RetryStrategy.ExponentialBackoff();
|
|
/**
|
|
/**
|
|
* Default behaviour for cors in the application.
|
|
* Default behaviour for cors in the application.
|
|
* It can be a string if the expected behavior is identical in the entire app.
|
|
* It can be a string if the expected behavior is identical in the entire app.
|
|
@@ -53582,6 +53611,9 @@ var BABYLON;
|
|
SceneLoader.GetPluginForExtension = function (extension) {
|
|
SceneLoader.GetPluginForExtension = function (extension) {
|
|
return SceneLoader._getPluginForExtension(extension).plugin;
|
|
return SceneLoader._getPluginForExtension(extension).plugin;
|
|
};
|
|
};
|
|
|
|
+ SceneLoader.IsPluginForExtensionAvailable = function (extension) {
|
|
|
|
+ return !!SceneLoader._registeredPlugins[extension];
|
|
|
|
+ };
|
|
SceneLoader.RegisterPlugin = function (plugin) {
|
|
SceneLoader.RegisterPlugin = function (plugin) {
|
|
if (typeof plugin.extensions === "string") {
|
|
if (typeof plugin.extensions === "string") {
|
|
var extension = plugin.extensions;
|
|
var extension = plugin.extensions;
|
|
@@ -57828,7 +57860,7 @@ var BABYLON;
|
|
var path;
|
|
var path;
|
|
var filename;
|
|
var filename;
|
|
// Checking if GLB loader is present
|
|
// Checking if GLB loader is present
|
|
- if (BABYLON.SceneLoader.GetPluginForExtension("glb")) {
|
|
|
|
|
|
+ if (BABYLON.SceneLoader.IsPluginForExtensionAvailable("glb")) {
|
|
// Determine the device specific folder based on the ID suffix
|
|
// Determine the device specific folder based on the ID suffix
|
|
var device = 'default';
|
|
var device = 'default';
|
|
if (this.id && !forceDefault) {
|
|
if (this.id && !forceDefault) {
|
|
@@ -82703,14 +82735,6 @@ var BABYLON;
|
|
this._loaderPendingCount = 0;
|
|
this._loaderPendingCount = 0;
|
|
this._loaderTrackers = new Array();
|
|
this._loaderTrackers = new Array();
|
|
this._parent = parent;
|
|
this._parent = parent;
|
|
- if (!GLTFLoader._progressEventFactory) {
|
|
|
|
- if (typeof window["ProgressEvent"] === "function") {
|
|
|
|
- GLTFLoader._progressEventFactory = GLTFLoader._createProgressEventByConstructor;
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- GLTFLoader._progressEventFactory = GLTFLoader._createProgressEventByDocument;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
GLTFLoader.RegisterExtension = function (extension) {
|
|
GLTFLoader.RegisterExtension = function (extension) {
|
|
if (GLTFLoader.Extensions[extension.name]) {
|
|
if (GLTFLoader.Extensions[extension.name]) {
|
|
@@ -82721,14 +82745,6 @@ var BABYLON;
|
|
// Keep the order of registration so that extensions registered first are called first.
|
|
// Keep the order of registration so that extensions registered first are called first.
|
|
GLTF2.GLTFLoaderExtension._Extensions.push(extension);
|
|
GLTF2.GLTFLoaderExtension._Extensions.push(extension);
|
|
};
|
|
};
|
|
- GLTFLoader._createProgressEventByConstructor = function (name, data) {
|
|
|
|
- return new ProgressEvent(name, data);
|
|
|
|
- };
|
|
|
|
- GLTFLoader._createProgressEventByDocument = function (name, data) {
|
|
|
|
- var event = document.createEvent("ProgressEvent");
|
|
|
|
- event.initProgressEvent(name, false, false, data.lengthComputable, data.loaded, data.total);
|
|
|
|
- return event;
|
|
|
|
- };
|
|
|
|
GLTFLoader.prototype.dispose = function () {
|
|
GLTFLoader.prototype.dispose = function () {
|
|
if (this._disposed) {
|
|
if (this._disposed) {
|
|
return;
|
|
return;
|
|
@@ -82781,21 +82797,19 @@ var BABYLON;
|
|
if (!this._progressCallback) {
|
|
if (!this._progressCallback) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ var lengthComputable = true;
|
|
var loaded = 0;
|
|
var loaded = 0;
|
|
var total = 0;
|
|
var total = 0;
|
|
for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
|
|
for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
|
|
var request = _a[_i];
|
|
var request = _a[_i];
|
|
- if (!request._loaded || !request._total) {
|
|
|
|
|
|
+ if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ lengthComputable = lengthComputable && request._lengthComputable;
|
|
loaded += request._loaded;
|
|
loaded += request._loaded;
|
|
total += request._total;
|
|
total += request._total;
|
|
}
|
|
}
|
|
- this._progressCallback(GLTFLoader._progressEventFactory("GLTFLoaderProgress", {
|
|
|
|
- lengthComputable: true,
|
|
|
|
- loaded: loaded,
|
|
|
|
- total: total
|
|
|
|
- }));
|
|
|
|
|
|
+ this._progressCallback(GLTFLoader._createProgressEvent(lengthComputable, loaded, lengthComputable ? total : 0));
|
|
};
|
|
};
|
|
GLTFLoader.prototype._executeWhenRenderReady = function (func) {
|
|
GLTFLoader.prototype._executeWhenRenderReady = function (func) {
|
|
if (this._renderReady) {
|
|
if (this._renderReady) {
|
|
@@ -84083,6 +84097,7 @@ var BABYLON;
|
|
}, function (event) {
|
|
}, function (event) {
|
|
_this._tryCatchOnError(function () {
|
|
_this._tryCatchOnError(function () {
|
|
if (request && !_this._renderReady) {
|
|
if (request && !_this._renderReady) {
|
|
|
|
+ request._lengthComputable = event.lengthComputable;
|
|
request._loaded = event.loaded;
|
|
request._loaded = event.loaded;
|
|
request._total = event.total;
|
|
request._total = event.total;
|
|
_this._onProgress();
|
|
_this._onProgress();
|
|
@@ -84092,10 +84107,10 @@ var BABYLON;
|
|
_this._tryCatchOnError(function () {
|
|
_this._tryCatchOnError(function () {
|
|
throw new BABYLON.LoadFileError(context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request);
|
|
throw new BABYLON.LoadFileError(context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request);
|
|
});
|
|
});
|
|
|
|
+ }, function (oldRequest, newRequest) {
|
|
|
|
+ _this._requests.splice(_this._requests.indexOf(oldRequest), 1, newRequest);
|
|
});
|
|
});
|
|
if (request) {
|
|
if (request) {
|
|
- request._loaded = null;
|
|
|
|
- request._total = null;
|
|
|
|
this._requests.push(request);
|
|
this._requests.push(request);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
@@ -84280,6 +84295,20 @@ var BABYLON;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
GLTFLoader.Extensions = {};
|
|
GLTFLoader.Extensions = {};
|
|
|
|
+ // IE 11 Compatibility.
|
|
|
|
+ GLTFLoader._createProgressEvent = (typeof window["ProgressEvent"] === "function")
|
|
|
|
+ ? function (lengthComputable, loaded, total) {
|
|
|
|
+ return new ProgressEvent("GLTFLoaderProgress", {
|
|
|
|
+ lengthComputable: lengthComputable,
|
|
|
|
+ loaded: loaded,
|
|
|
|
+ total: total
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ : function (lengthComputable, loaded, total) {
|
|
|
|
+ var event = document.createEvent("ProgressEvent");
|
|
|
|
+ event.initProgressEvent("GLTFLoaderProgress", false, false, lengthComputable, loaded, total);
|
|
|
|
+ return event;
|
|
|
|
+ };
|
|
return GLTFLoader;
|
|
return GLTFLoader;
|
|
}());
|
|
}());
|
|
GLTF2.GLTFLoader = GLTFLoader;
|
|
GLTF2.GLTFLoader = GLTFLoader;
|