|
@@ -2439,6 +2439,8 @@ var BABYLON;
|
|
(function (GLTF2) {
|
|
(function (GLTF2) {
|
|
var GLTFLoader = (function () {
|
|
var GLTFLoader = (function () {
|
|
function GLTFLoader(parent) {
|
|
function GLTFLoader(parent) {
|
|
|
|
+ // Observable with boolean indicating success or error.
|
|
|
|
+ this._renderReadyObservable = new BABYLON.Observable();
|
|
this._parent = parent;
|
|
this._parent = parent;
|
|
}
|
|
}
|
|
GLTFLoader.RegisterExtension = function (extension) {
|
|
GLTFLoader.RegisterExtension = function (extension) {
|
|
@@ -2464,6 +2466,14 @@ var BABYLON;
|
|
enumerable: true,
|
|
enumerable: true,
|
|
configurable: true
|
|
configurable: true
|
|
});
|
|
});
|
|
|
|
+ GLTFLoader.prototype.executeWhenRenderReady = function (func) {
|
|
|
|
+ if (this._renderReady) {
|
|
|
|
+ func(this._succeeded);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ this._renderReadyObservable.add(func);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onError) {
|
|
GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onError) {
|
|
var _this = this;
|
|
var _this = this;
|
|
this._loadAsync(meshesNames, scene, data, rootUrl, function () {
|
|
this._loadAsync(meshesNames, scene, data, rootUrl, function () {
|
|
@@ -2505,9 +2515,10 @@ var BABYLON;
|
|
this.removePendingData(this);
|
|
this.removePendingData(this);
|
|
};
|
|
};
|
|
GLTFLoader.prototype._onRenderReady = function () {
|
|
GLTFLoader.prototype._onRenderReady = function () {
|
|
- this._showMeshes();
|
|
|
|
- this._startAnimations();
|
|
|
|
- if (this._errors.length === 0) {
|
|
|
|
|
|
+ this._succeeded = (this._errors.length === 0);
|
|
|
|
+ if (this._succeeded) {
|
|
|
|
+ this._showMeshes();
|
|
|
|
+ this._startAnimations();
|
|
this._onSuccess();
|
|
this._onSuccess();
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -2515,6 +2526,7 @@ var BABYLON;
|
|
this._errors = [];
|
|
this._errors = [];
|
|
this._onError();
|
|
this._onError();
|
|
}
|
|
}
|
|
|
|
+ this._renderReadyObservable.notifyObservers(this._succeeded);
|
|
};
|
|
};
|
|
GLTFLoader.prototype._onLoaderComplete = function () {
|
|
GLTFLoader.prototype._onLoaderComplete = function () {
|
|
this._errors.forEach(function (error) { return BABYLON.Tools.Error(error); });
|
|
this._errors.forEach(function (error) { return BABYLON.Tools.Error(error); });
|
|
@@ -2581,7 +2593,9 @@ var BABYLON;
|
|
this._defaultMaterial = undefined;
|
|
this._defaultMaterial = undefined;
|
|
this._onSuccess = undefined;
|
|
this._onSuccess = undefined;
|
|
this._onError = undefined;
|
|
this._onError = undefined;
|
|
|
|
+ this._succeeded = false;
|
|
this._renderReady = false;
|
|
this._renderReady = false;
|
|
|
|
+ this._renderReadyObservable.clear();
|
|
this._renderPendingCount = 0;
|
|
this._renderPendingCount = 0;
|
|
this._loaderPendingCount = 0;
|
|
this._loaderPendingCount = 0;
|
|
};
|
|
};
|
|
@@ -3499,16 +3513,21 @@ var BABYLON;
|
|
MSFTLOD.prototype.loadMaterialLOD = function (loader, material, materialLODs, lod, assign) {
|
|
MSFTLOD.prototype.loadMaterialLOD = function (loader, material, materialLODs, lod, assign) {
|
|
var _this = this;
|
|
var _this = this;
|
|
loader.loadMaterial(materialLODs[lod], function (babylonMaterial) {
|
|
loader.loadMaterial(materialLODs[lod], function (babylonMaterial) {
|
|
- babylonMaterial.name += ".LOD" + lod;
|
|
|
|
assign(babylonMaterial);
|
|
assign(babylonMaterial);
|
|
// Loading is complete if this is the highest quality LOD.
|
|
// Loading is complete if this is the highest quality LOD.
|
|
if (lod === 0) {
|
|
if (lod === 0) {
|
|
loader.removeLoaderPendingData(material);
|
|
loader.removeLoaderPendingData(material);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- // Load the next LOD when all of the textures are loaded.
|
|
|
|
- BABYLON.BaseTexture.WhenAllReady(babylonMaterial.getActiveTextures(), function () {
|
|
|
|
- _this.loadMaterialLOD(loader, material, materialLODs, lod - 1, assign);
|
|
|
|
|
|
+ // Load the next LOD once the loader has succeeded.
|
|
|
|
+ loader.executeWhenRenderReady(function (succeeded) {
|
|
|
|
+ if (!succeeded) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // Load the next LOD when all of the textures are loaded.
|
|
|
|
+ BABYLON.BaseTexture.WhenAllReady(babylonMaterial.getActiveTextures(), function () {
|
|
|
|
+ _this.loadMaterialLOD(loader, material, materialLODs, lod - 1, assign);
|
|
|
|
+ });
|
|
});
|
|
});
|
|
});
|
|
});
|
|
};
|
|
};
|