Pārlūkot izejas kodu

Add ability to update url after texture construction

Gary Hsu 8 gadi atpakaļ
vecāks
revīzija
88c6774986
1 mainītis faili ar 20 papildinājumiem un 5 dzēšanām
  1. 20 5
      src/Materials/Textures/babylon.texture.ts

+ 20 - 5
src/Materials/Textures/babylon.texture.ts

@@ -96,11 +96,6 @@
             this._format = format;
 
             scene = this.getScene();
-            if (!url) {
-                return;
-            }
-
-            this._texture = this._getFromCache(url, noMipmap, samplingMode);
 
             let load = () => {
                 if (this._onLoadObservarble && this._onLoadObservarble.hasObservers()) {
@@ -115,6 +110,14 @@
                 }
             }
 
+            if (!url) {
+                this._delayedOnLoad = load;
+                this._delayedOnError = onError;
+                return;
+            }
+
+            this._texture = this._getFromCache(url, noMipmap, samplingMode);
+
             if (!this._texture) {
                 if (!scene.useDelayedTextureLoading) {
                     this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene, this._samplingMode, load, onError, this._buffer, null, this._format);
@@ -136,6 +139,12 @@
             }
         }
 
+        public updateURL(url: string): void {
+            this.url = url;
+            this.delayLoadState = Engine.DELAYLOADSTATE_NOTLOADED;
+            this.delayLoad();
+        }
+
         public delayLoad(): void {
             if (this.delayLoadState !== Engine.DELAYLOADSTATE_NOTLOADED) {
                 return;
@@ -149,6 +158,12 @@
                 if (this._deleteBuffer) {
                     delete this._buffer;
                 }
+            } else {
+                if (this._texture.isReady) {
+                    Tools.SetImmediate(() => this._delayedOnLoad());
+                } else {
+                    this._texture.onLoadedCallbacks.push(this._delayedOnLoad);
+                }
             }
         }