David Catuhe 8 年之前
父節點
當前提交
10d556a6e9

文件差異過大導致無法顯示
+ 1118 - 1117
dist/preview release/babylon.d.ts


文件差異過大導致無法顯示
+ 1118 - 1117
dist/preview release/babylon.module.d.ts


+ 17 - 12
src/Layer/babylon.layer.ts

@@ -70,6 +70,23 @@
 
             var engine = this._scene.getEngine();
 
+            this._rebuild();
+
+            // Effects
+            this._effect = engine.createEffect("layer",
+                [VertexBuffer.PositionKind],
+                ["textureMatrix", "color", "scale", "offset"],
+                ["textureSampler"], "");
+
+            this._alphaTestEffect = engine.createEffect("layer",
+                [VertexBuffer.PositionKind],
+                ["textureMatrix", "color", "scale", "offset"],
+                ["textureSampler"], "#define ALPHATEST");
+        }
+
+        public _rebuild(): void {
+            var engine = this._scene.getEngine();
+
             // VBO
             var vertices = [];
             vertices.push(1, 1);
@@ -91,17 +108,6 @@
             indices.push(3);
 
             this._indexBuffer = engine.createIndexBuffer(indices);
-
-            // Effects
-            this._effect = engine.createEffect("layer",
-                [VertexBuffer.PositionKind],
-                ["textureMatrix", "color", "scale", "offset"],
-                ["textureSampler"], "");
-
-            this._alphaTestEffect = engine.createEffect("layer",
-                [VertexBuffer.PositionKind],
-                ["textureMatrix", "color", "scale", "offset"],
-                ["textureSampler"], "#define ALPHATEST");
         }
 
         public render(): void {
@@ -119,7 +125,6 @@
             engine.enableEffect(currentEffect);
             engine.setState(false);
 
-
             // Texture
             currentEffect.setTexture("textureSampler", this.texture);
             currentEffect.setMatrix("textureMatrix", this.texture.getTextureMatrix());

+ 27 - 9
src/Materials/Textures/babylon.internalTexture.ts

@@ -9,9 +9,8 @@ module BABYLON {
         public static DATASOURCE_RENDERTARGET = 5;
         public static DATASOURCE_MULTIRENDERTARGET = 6;
         public static DATASOURCE_CUBE = 7;
-        public static DATASOURCE_CUBELOD = 8;
-        public static DATASOURCE_CUBERAW = 9;
-        public static DATASOURCE_CUBEPREFILTERED = 10;
+        public static DATASOURCE_CUBERAW = 8;
+        public static DATASOURCE_CUBEPREFILTERED = 9;
 
         public isReady: boolean;
         public isCube: boolean;
@@ -33,6 +32,7 @@ module BABYLON {
         public _buffer: ArrayBuffer | HTMLImageElement;
         public _size: number;
         public _extension: string;
+        public _files: string[];
         public _workingCanvas: HTMLCanvasElement;
         public _workingContext: CanvasRenderingContext2D;
         public _framebuffer: WebGLFramebuffer;
@@ -92,19 +92,37 @@ module BABYLON {
             this._cachedAnisotropicFilteringLevel = null;
 
             switch (this._dataSource) {
+                case InternalTexture.DATASOURCE_TEMP:
+                    return;
+
                 case InternalTexture.DATASOURCE_URL:
                     proxy = this._engine.createTexture(this.url, !this.generateMipMaps, this.invertY, null, this.samplingMode, () => {
                         this.isReady = true;
                     }, null, this._buffer, null, this.format); 
-                    break;                   
+                    proxy._swapAndDie(this);
+                    return;
+                
+                case InternalTexture.DATASOURCE_DYNAMIC:
+                    proxy = this._engine.createDynamicTexture(this.baseWidth, this.baseHeight, this.generateMipMaps, this.samplingMode); 
+                    proxy._swapAndDie(this);
+
+                    // The engine will make sure to update content so no need to flag it as isReady = true
+                return;
+
+                case InternalTexture.DATASOURCE_CUBE:
+                    proxy = this._engine.createCubeTexture(this.url, null, this._files, !this.generateMipMaps, () => {
+                        this.isReady = true;
+                    }, null, this.format, this._extension);
+                    proxy._swapAndDie(this);
+                    return;
+
                 case InternalTexture.DATASOURCE_CUBEPREFILTERED:
-                    proxy = this._engine.createPrefilteredCubeTexture(this.url, null, this._lodGenerationScale, this._lodGenerationOffset, () => {
+                    proxy = this._engine.createPrefilteredCubeTexture(this.url, null, this._lodGenerationScale, this._lodGenerationOffset, (proxy) => {
+                        proxy._swapAndDie(this);
+                        
                         this.isReady = true;
                     }, null, this.format, this._extension);
-                    break;
-            }
-            if (proxy) {
-                proxy._swapAndDie(this);
+                    return;
             }
         }
 

+ 16 - 9
src/babylon.engine.ts

@@ -113,7 +113,9 @@
             loadedImages[index] = img;
             loadedImages._internalCount++;
 
-            scene._removePendingData(img);
+            if (scene) {
+                scene._removePendingData(img);
+            }
 
             if (loadedImages._internalCount === 6) {
                 onfinish(loadedImages);
@@ -121,15 +123,19 @@
         };
 
         var onerror = () => {
-            scene._removePendingData(img);
+            if (scene) {
+                scene._removePendingData(img);
+            }
 
             if (onErrorCallBack) {
                 onErrorCallBack();
             }
         };
 
-        img = Tools.LoadImage(url, onload, onerror, scene.database);
-        scene._addPendingData(img);
+        img = Tools.LoadImage(url, onload, onerror, scene ? scene.database : null);
+        if (scene) {
+            scene._addPendingData(img);
+        }
     }
 
     var cascadeLoad = (rootUrl: string, scene,
@@ -3396,11 +3402,11 @@
             return texture;
         }
 
-        public createPrefilteredCubeTexture(rootUrl: string, scene: Scene, scale: number, offset: number, onLoad: () => void, onError: () => void = null, format?: number, forcedExtension = null): InternalTexture {
+        public createPrefilteredCubeTexture(rootUrl: string, scene: Scene, scale: number, offset: number, onLoad: (internalTexture: InternalTexture) => void, onError: () => void = null, format?: number, forcedExtension = null): InternalTexture {
             var callback = (loadData) => {
                 if (!loadData) {
                     if (onLoad) {
-                        onLoad();
+                        onLoad(null);
                     }
                     return;
                 }
@@ -3413,7 +3419,7 @@
                 if (this._caps.textureLOD) {
                     // Do not add extra process if texture lod is supported.
                     if (onLoad) {
-                        onLoad();
+                        onLoad(texture);
                     }
                     return;
                 }
@@ -3438,7 +3444,7 @@
                     let lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;
                     let mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));
 
-                    var glTextureFromLod = new InternalTexture(this, InternalTexture.DATASOURCE_CUBELOD);
+                    var glTextureFromLod = new InternalTexture(this, InternalTexture.DATASOURCE_TEMP);
                     glTextureFromLod.isCube = true;
                     this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, glTextureFromLod);
 
@@ -3474,7 +3480,7 @@
                 texture._lodTextureLow = textures[0];
 
                 if (onLoad) {
-                    onLoad();
+                    onLoad(texture);
                 }
             };
 
@@ -3489,6 +3495,7 @@
             texture.url = rootUrl;
             texture.generateMipMaps = !noMipmap;
             texture._extension = forcedExtension;
+            texture._files = files;
 
             var isKTX = false;
             var isDDS = false;

+ 4 - 0
src/babylon.scene.ts

@@ -3839,6 +3839,10 @@
             for (var mesh of this.meshes) {
                 mesh._rebuild();
             }
+
+            for (var layer of this.layers) {
+                layer._rebuild();
+            }
         }
 
         public _rebuildTextures(): void {