Browse Source

address comments

Trevor Baron 6 years ago
parent
commit
1ad69f1e0c
2 changed files with 18 additions and 26 deletions
  1. 17 26
      loaders/src/glTF/2.0/babylon.glTFLoader.ts
  2. 1 0
      src/Engine/babylon.engine.ts

+ 17 - 26
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -1714,39 +1714,30 @@ module BABYLON.GLTF2 {
             const samplerData = this._loadSampler(`/samplers/${sampler.index}`, sampler);
             const samplerData = this._loadSampler(`/samplers/${sampler.index}`, sampler);
 
 
             const image = ArrayItem.Get(`${context}/source`, this.gltf.images, texture.source);
             const image = ArrayItem.Get(`${context}/source`, this.gltf.images, texture.source);
-            let babylonTexture: Texture;
-            if (image.uri && this.babylonScene.getEngine().textureFormatInUse) {
+            let textureURL: Nullable<string> = null;
+            if (image.uri && !Tools.IsBase64(image.uri) && this.babylonScene.getEngine().textureFormatInUse) {
                 // If an image uri and a texture format is set like (eg. KTX) load from url instead of blob to support texture format and fallback
                 // If an image uri and a texture format is set like (eg. KTX) load from url instead of blob to support texture format and fallback
-                const deferred = new Deferred<void>();
-                babylonTexture = new Texture(`${this._uniqueRootUrl}` + image.uri, this.babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, () => {
-                    if (!this._disposed) {
-                        deferred.resolve();
-                    }
-                }, (message, exception) => {
-                    if (!this._disposed) {
-                        deferred.reject(new Error(`${context}: ${(exception && exception.message) ? exception.message : message || "Failed to load texture"}`));
-                    }
-                });
-                promises.push(deferred.promise);
-            }else {
-                const deferred = new Deferred<void>();
-                babylonTexture = new Texture(null, this.babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, () => {
-                    if (!this._disposed) {
-                        deferred.resolve();
-                    }
-                }, (message, exception) => {
-                    if (!this._disposed) {
-                        deferred.reject(new Error(`${context}: ${(exception && exception.message) ? exception.message : message || "Failed to load texture"}`));
-                    }
-                });
-                promises.push(deferred.promise);
+                textureURL = this._uniqueRootUrl + image.uri;
+            }
 
 
+            const deferred = new Deferred<void>();
+            let babylonTexture = new Texture(textureURL, this.babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, () => {
+                if (!this._disposed) {
+                    deferred.resolve();
+                }
+            }, (message, exception) => {
+                if (!this._disposed) {
+                    deferred.reject(new Error(`${context}: ${(exception && exception.message) ? exception.message : message || "Failed to load texture"}`));
+                }
+            });
+            promises.push(deferred.promise);
+
+            if (!textureURL) {
                 promises.push(this.loadImageAsync(`/images/${image.index}`, image).then((data) => {
                 promises.push(this.loadImageAsync(`/images/${image.index}`, image).then((data) => {
                     const name = image.uri || `${this._fileName}#image${image.index}`;
                     const name = image.uri || `${this._fileName}#image${image.index}`;
                     const dataUrl = `data:${this._uniqueRootUrl}${name}`;
                     const dataUrl = `data:${this._uniqueRootUrl}${name}`;
                     babylonTexture.updateURL(dataUrl, new Blob([data], { type: image.mimeType }));
                     babylonTexture.updateURL(dataUrl, new Blob([data], { type: image.mimeType }));
                 }));
                 }));
-
             }
             }
 
 
             babylonTexture.wrapU = samplerData.wrapU;
             babylonTexture.wrapU = samplerData.wrapU;

+ 1 - 0
src/Engine/babylon.engine.ts

@@ -4317,6 +4317,7 @@ module BABYLON {
                     }
                     }
                     if (Tools.UseFallbackTexture) {
                     if (Tools.UseFallbackTexture) {
                         this.createTexture(Tools.fallbackTexture, noMipmap, invertY, scene, samplingMode, null, onError, buffer, texture);
                         this.createTexture(Tools.fallbackTexture, noMipmap, invertY, scene, samplingMode, null, onError, buffer, texture);
+                        return;
                     }
                     }
                 }
                 }