ソースを参照

Reintegrate deleted changes

= 9 年 前
コミット
83a21605d3

+ 1 - 0
src/Canvas2d/babylon.sprite2d.ts

@@ -317,6 +317,7 @@
                 } else {
                 } else {
                     texture.onLoadObservable.add(() => {
                     texture.onLoadObservable.add(() => {
                         this.size = <Size>texture.getSize();
                         this.size = <Size>texture.getSize();
+                        this._positioningDirty();
                     });
                     });
                 }
                 }
             }
             }

+ 7 - 1
src/Lights/Shadows/babylon.shadowGenerator.ts

@@ -1,5 +1,11 @@
 module BABYLON {
 module BABYLON {
-    export class ShadowGenerator {
+    export interface IShadowGenerator {
+        getShadowMap(): RenderTargetTexture;
+ 
+        dispose(): void;
+    }
+ 
+    export class ShadowGenerator implements IShadowGenerator {
         private static _FILTER_NONE = 0;
         private static _FILTER_NONE = 0;
         private static _FILTER_VARIANCESHADOWMAP = 1;
         private static _FILTER_VARIANCESHADOWMAP = 1;
         private static _FILTER_POISSONSAMPLING = 2;
         private static _FILTER_POISSONSAMPLING = 2;

+ 3 - 3
src/Lights/babylon.light.ts

@@ -17,7 +17,7 @@
 
 
         getShadowDirection(faceIndex?: number): Vector3;
         getShadowDirection(faceIndex?: number): Vector3;
 
 
-        _shadowGenerator: ShadowGenerator;
+        _shadowGenerator: IShadowGenerator;
     }
     }
 
 
     export class Light extends Node {
     export class Light extends Node {
@@ -46,7 +46,7 @@
         @serialize()
         @serialize()
         public radius = 0.00001;
         public radius = 0.00001;
 
 
-        public _shadowGenerator: ShadowGenerator;
+        public _shadowGenerator: IShadowGenerator;
         private _parentedWorldMatrix: Matrix;
         private _parentedWorldMatrix: Matrix;
         public _excludedMeshesIds = new Array<string>();
         public _excludedMeshesIds = new Array<string>();
         public _includedOnlyMeshesIds = new Array<string>();
         public _includedOnlyMeshesIds = new Array<string>();
@@ -73,7 +73,7 @@
             return ret;
             return ret;
         } 
         } 
         
         
-        public getShadowGenerator(): ShadowGenerator {
+        public getShadowGenerator(): IShadowGenerator {
             return this._shadowGenerator;
             return this._shadowGenerator;
         }
         }
 
 

+ 1 - 0
src/Materials/Textures/babylon.colorGradingTexture.ts

@@ -256,6 +256,7 @@ module BABYLON {
             var serializationObject: any = {};
             var serializationObject: any = {};
             serializationObject.name = this.name;
             serializationObject.name = this.name;
             serializationObject.level = this.level;
             serializationObject.level = this.level;
+            serializationObject.customType = "BABYLON.ColorGradingTexture";
 
 
             return serializationObject;
             return serializationObject;
         }
         }

+ 2 - 1
src/Materials/Textures/babylon.hdrCubeTexture.ts

@@ -410,7 +410,8 @@ module BABYLON {
             serializationObject.generateHarmonics = this._generateHarmonics;
             serializationObject.generateHarmonics = this._generateHarmonics;
             serializationObject.usePMREMGenerator = this._usePMREMGenerator;
             serializationObject.usePMREMGenerator = this._usePMREMGenerator;
             serializationObject.isBABYLONPreprocessed = this._isBABYLONPreprocessed;
             serializationObject.isBABYLONPreprocessed = this._isBABYLONPreprocessed;
-
+            serializationObject.customType = "BABYLON.HDRCubeTexture";
+            
             return serializationObject;
             return serializationObject;
         }
         }
 
 

+ 4 - 1
src/Materials/Textures/babylon.texture.ts

@@ -273,7 +273,10 @@
             }
             }
 
 
             var texture = SerializationHelper.Parse(() => {
             var texture = SerializationHelper.Parse(() => {
-                if (parsedTexture.mirrorPlane) {
+                if (parsedTexture.customType) {
+                     var customTexture = Tools.Instantiate(parsedTexture.customType);
+                     return customTexture.Parse(parsedTexture, scene, rootUrl);
+                 } else if (parsedTexture.mirrorPlane) {
                     var mirrorTexture = new MirrorTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene);
                     var mirrorTexture = new MirrorTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene);
                     mirrorTexture._waitingRenderList = parsedTexture.renderList;
                     mirrorTexture._waitingRenderList = parsedTexture.renderList;
                     mirrorTexture.mirrorPlane = Plane.FromArray(parsedTexture.mirrorPlane);
                     mirrorTexture.mirrorPlane = Plane.FromArray(parsedTexture.mirrorPlane);

+ 62 - 6
src/Materials/babylon.effect.ts

@@ -253,7 +253,7 @@
                     var includeContent = Effect.IncludesShadersStore[includeFile];
                     var includeContent = Effect.IncludesShadersStore[includeFile];
                     if (match[2]) {
                     if (match[2]) {
                         var splits = match[3].split(",");
                         var splits = match[3].split(",");
-                      
+
                         for (var index = 0; index < splits.length; index += 2) {
                         for (var index = 0; index < splits.length; index += 2) {
                             var source = new RegExp(splits[index], "g");
                             var source = new RegExp(splits[index], "g");
                             var dest = splits[index + 1];
                             var dest = splits[index + 1];
@@ -325,7 +325,7 @@
                 // Precision
                 // Precision
                 vertexSourceCode = this._processPrecision(vertexSourceCode);
                 vertexSourceCode = this._processPrecision(vertexSourceCode);
                 fragmentSourceCode = this._processPrecision(fragmentSourceCode);
                 fragmentSourceCode = this._processPrecision(fragmentSourceCode);
-                
+
                 this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
                 this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
 
 
                 this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
                 this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
@@ -406,7 +406,7 @@
             var tm = cache.m;
             var tm = cache.m;
             var om = matrix.m;
             var om = matrix.m;
             for (var index = 0; index < 16; index++) {
             for (var index = 0; index < 16; index++) {
-                if (tm[index] !== om[index]) { 
+                if (tm[index] !== om[index]) {
                     tm[index] = om[index];
                     tm[index] = om[index];
                     changed = true;
                     changed = true;
                 }
                 }
@@ -433,7 +433,7 @@
                 cache[1] = y;
                 cache[1] = y;
                 changed = true;
                 changed = true;
             }
             }
-            
+
             return changed;
             return changed;
         }
         }
 
 
@@ -458,7 +458,7 @@
                 cache[2] = z;
                 cache[2] = z;
                 changed = true;
                 changed = true;
             }
             }
-            
+
             return changed;
             return changed;
         }
         }
 
 
@@ -487,10 +487,66 @@
                 cache[3] = w;
                 cache[3] = w;
                 changed = true;
                 changed = true;
             }
             }
-            
+
             return changed;
             return changed;
         }
         }
 
 
+        public setIntArray(uniformName: string, array: Int32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setIntArray(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setIntArray2(uniformName: string, array: Int32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setIntArray2(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setIntArray3(uniformName: string, array: Int32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setIntArray3(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setIntArray4(uniformName: string, array: Int32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setIntArray4(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setFloatArray(uniformName: string, array: Float32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setFloatArray(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setFloatArray2(uniformName: string, array: Float32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setFloatArray2(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setFloatArray3(uniformName: string, array: Float32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setFloatArray3(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setFloatArray4(uniformName: string, array: Float32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setFloatArray4(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
         public setArray(uniformName: string, array: number[]): Effect {
         public setArray(uniformName: string, array: number[]): Effect {
             this._valueCache[uniformName] = null;
             this._valueCache[uniformName] = null;
             this._engine.setArray(this.getUniform(uniformName), array);
             this._engine.setArray(this.getUniform(uniformName), array);

+ 2 - 2
src/Materials/babylon.materialHelper.ts

@@ -74,7 +74,7 @@
 
 
                 // Shadows
                 // Shadows
                 if (scene.shadowsEnabled) {
                 if (scene.shadowsEnabled) {
-                    var shadowGenerator = light.getShadowGenerator();
+                    var shadowGenerator = <ShadowGenerator>light.getShadowGenerator();
                     if (mesh && mesh.receiveShadows && shadowGenerator) {
                     if (mesh && mesh.receiveShadows && shadowGenerator) {
                         if (defines["SHADOW" + lightIndex] === undefined) {
                         if (defines["SHADOW" + lightIndex] === undefined) {
                             needRebuild = true;
                             needRebuild = true;
@@ -192,7 +192,7 @@
 
 
         // Bindings
         // Bindings
         public static BindLightShadow(light: Light, scene: Scene, mesh: AbstractMesh, lightIndex: number, effect: Effect, depthValuesAlreadySet: boolean): boolean {
         public static BindLightShadow(light: Light, scene: Scene, mesh: AbstractMesh, lightIndex: number, effect: Effect, depthValuesAlreadySet: boolean): boolean {
-            var shadowGenerator = light.getShadowGenerator();
+            var shadowGenerator = <ShadowGenerator>light.getShadowGenerator();
             if (mesh.receiveShadows && shadowGenerator) {
             if (mesh.receiveShadows && shadowGenerator) {
                 if (!(<any>light).needCube()) {
                 if (!(<any>light).needCube()) {
                     effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
                     effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());

+ 4 - 2
src/Tools/babylon.sceneSerializer.ts

@@ -334,8 +334,10 @@
             for (index = 0; index < scene.lights.length; index++) {
             for (index = 0; index < scene.lights.length; index++) {
                 light = scene.lights[index];
                 light = scene.lights[index];
 
 
-                if (light.getShadowGenerator()) {
-                    serializationObject.shadowGenerators.push(light.getShadowGenerator().serialize());
+                let shadowGenerator = light.getShadowGenerator();
+                // Only support serialization for official generator so far.
+                if (shadowGenerator && shadowGenerator instanceof ShadowGenerator) {
+                     serializationObject.shadowGenerators.push(<ShadowGenerator>shadowGenerator.serialize());
                 }
                 }
             }
             }
 
 

+ 64 - 0
src/babylon.engine.ts

@@ -1366,6 +1366,62 @@
             }
             }
         }
         }
 
 
+        public setIntArray(uniform: WebGLUniformLocation, array: Int32Array): void {
+            if (!uniform)
+                return;
+
+            this._gl.uniform1iv(uniform, array);
+        }
+
+        public setIntArray2(uniform: WebGLUniformLocation, array: Int32Array): void {
+            if (!uniform || array.length % 2 !== 0)
+                return;
+
+            this._gl.uniform2iv(uniform, array);
+        }
+
+        public setIntArray3(uniform: WebGLUniformLocation, array: Int32Array): void {
+            if (!uniform || array.length % 3 !== 0)
+                return;
+
+            this._gl.uniform3iv(uniform, array);
+        }
+
+        public setIntArray4(uniform: WebGLUniformLocation, array: Int32Array): void {
+            if (!uniform || array.length % 4 !== 0)
+                return;
+
+            this._gl.uniform4iv(uniform, array);
+        }
+
+        public setFloatArray(uniform: WebGLUniformLocation, array: Float32Array): void {
+            if (!uniform)
+                return;
+
+            this._gl.uniform1fv(uniform, array);
+        }
+
+        public setFloatArray2(uniform: WebGLUniformLocation, array: Float32Array): void {
+            if (!uniform || array.length % 2 !== 0)
+                return;
+
+            this._gl.uniform2fv(uniform, array);
+        }
+
+        public setFloatArray3(uniform: WebGLUniformLocation, array: Float32Array): void {
+            if (!uniform || array.length % 3 !== 0)
+                return;
+
+            this._gl.uniform3fv(uniform, array);
+        }
+
+        public setFloatArray4(uniform: WebGLUniformLocation, array: Float32Array): void {
+            if (!uniform || array.length % 4 !== 0)
+                return;
+
+            this._gl.uniform4fv(uniform, array);
+        }
+
         public setArray(uniform: WebGLUniformLocation, array: number[]): void {
         public setArray(uniform: WebGLUniformLocation, array: number[]): void {
             if (!uniform)
             if (!uniform)
                 return;
                 return;
@@ -2617,6 +2673,14 @@
             this._loadingScreen.loadingUIBackgroundColor = color;
             this._loadingScreen.loadingUIBackgroundColor = color;
         }
         }
 
 
+        public attachContextLostEvent(callback: ((event: WebGLContextEvent) => void)): void {
+            this._renderingCanvas.addEventListener("webglcontextlost", callback, false);
+        }
+
+        public attachContextRestoredEvent(callback: ((event: WebGLContextEvent) => void)): void {
+            this._renderingCanvas.addEventListener("webglcontextrestored", callback, false);
+        }
+
         // FPS
         // FPS
         public getFps(): number {
         public getFps(): number {
             return this.fps;
             return this.fps;