Bläddra i källkod

Now serialize and parse all procedural textures

Julien MOREAU-MATHIS 7 år sedan
förälder
incheckning
6fcac3c6ea

+ 26 - 0
proceduralTexturesLibrary/src/cloud/babylon.cloudProceduralTexture.ts

@@ -15,6 +15,7 @@ module BABYLON {
             this.setColor4("cloudColor", this._cloudColor);
         }
     
+        @serializeAsColor4()
         public get skyColor(): Color4 {
             return this._skyColor;
         }
@@ -24,6 +25,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
     
+        @serializeAsColor4()
         public get cloudColor(): Color4 {
             return this._cloudColor;
         }
@@ -32,5 +34,29 @@ module BABYLON {
             this._cloudColor = value;
             this.updateShaderUniforms();
         }
+
+        /**
+         * Serializes this cloud procedural texture
+         * @returns a serialized cloud procedural texture object
+         */
+        public serialize(): any {
+            var serializationObject = SerializationHelper.Serialize(this, super.serialize());
+            serializationObject.customType = "BABYLON.CloudProceduralTexture";
+
+            return serializationObject;
+        }
+
+        /**
+         * Creates a Cloud Procedural Texture from parsed cloud procedural texture data
+         * @param parsedTexture defines parsed texture data
+         * @param scene defines the current scene
+         * @param rootUrl defines the root URL containing cloud procedural texture information
+         * @returns a parsed Cloud Procedural Texture
+         */
+        public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): CloudProceduralTexture {
+            var texture = SerializationHelper.Parse(() => new CloudProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
+
+            return texture;
+        }
     }
 }

+ 28 - 0
proceduralTexturesLibrary/src/fire/babylon.fireProceduralTexture.ts

@@ -79,6 +79,7 @@ module BABYLON {
             ];
         }
 
+        @serializeAsColor3()
         public get fireColors(): Color3[] {
             return this._fireColors;
         }
@@ -88,6 +89,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
 
+        @serialize()
         public get time(): number {
             return this._time;
         }
@@ -97,6 +99,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
 
+        @serializeAsVector2()
         public get speed(): Vector2 {
             return this._speed;
         }
@@ -106,6 +109,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
 
+        @serialize()
         public get alphaThreshold(): number {
             return this._alphaThreshold;
         }
@@ -114,5 +118,29 @@ module BABYLON {
             this._alphaThreshold = value;
             this.updateShaderUniforms();
         }
+
+        /**
+         * Serializes this fire procedural texture
+         * @returns a serialized fire procedural texture object
+         */
+        public serialize(): any {
+            var serializationObject = SerializationHelper.Serialize(this, super.serialize());
+            serializationObject.customType = "BABYLON.FireProceduralTexture";
+
+            return serializationObject;
+        }
+
+        /**
+         * Creates a Fire Procedural Texture from parsed fire procedural texture data
+         * @param parsedTexture defines parsed texture data
+         * @param scene defines the current scene
+         * @param rootUrl defines the root URL containing fire procedural texture information
+         * @returns a parsed Fire Procedural Texture
+         */
+        public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): FireProceduralTexture {
+            var texture = SerializationHelper.Parse(() => new FireProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
+
+            return texture;
+        }
     }
 }

+ 26 - 0
proceduralTexturesLibrary/src/grass/babylon.grassProceduralTexture.ts

@@ -24,6 +24,7 @@ module BABYLON {
             this.setColor3("groundColor", this._groundColor);
         }
 
+        @serializeAsColor3()
         public get grassColors(): Color3[] {
             return this._grassColors;
         }
@@ -33,6 +34,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
 
+        @serializeAsColor3()
         public get groundColor(): Color3 {
             return this._groundColor;
         }
@@ -41,5 +43,29 @@ module BABYLON {
             this._groundColor = value;
             this.updateShaderUniforms();
         }
+
+        /**
+         * Serializes this grass procedural texture
+         * @returns a serialized grass procedural texture object
+         */
+        public serialize(): any {
+            var serializationObject = SerializationHelper.Serialize(this, super.serialize());
+            serializationObject.customType = "BABYLON.GrassProceduralTexture";
+
+            return serializationObject;
+        }
+
+        /**
+         * Creates a Grass Procedural Texture from parsed grass procedural texture data
+         * @param parsedTexture defines parsed texture data
+         * @param scene defines the current scene
+         * @param rootUrl defines the root URL containing grass procedural texture information
+         * @returns a parsed Grass Procedural Texture
+         */
+        public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): GrassProceduralTexture {
+            var texture = SerializationHelper.Parse(() => new GrassProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
+
+            return texture;
+        }
     }
 }

+ 28 - 0
proceduralTexturesLibrary/src/marble/babylon.marbleProceduralTexture.ts

@@ -19,6 +19,7 @@ module BABYLON {
             this.setColor3("jointColor", this._jointColor);
         }
 
+        @serialize()
         public get numberOfTilesHeight(): number {
             return this._numberOfTilesHeight;
         }
@@ -28,6 +29,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
         
+        @serialize()
         public get amplitude(): number {
             return this._amplitude;
         }
@@ -37,6 +39,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
 
+        @serialize()
         public get numberOfTilesWidth(): number {
             return this._numberOfTilesWidth;
         }
@@ -46,6 +49,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
 
+        @serialize()
         public get jointColor(): Color3 {
             return this._jointColor;
         }
@@ -54,5 +58,29 @@ module BABYLON {
             this._jointColor = value;
             this.updateShaderUniforms();
         }
+
+        /**
+         * Serializes this marble procedural texture
+         * @returns a serialized marble procedural texture object
+         */
+        public serialize(): any {
+            var serializationObject = SerializationHelper.Serialize(this, super.serialize());
+            serializationObject.customType = "BABYLON.MarbleProceduralTexture";
+
+            return serializationObject;
+        }
+
+        /**
+         * Creates a Marble Procedural Texture from parsed marble procedural texture data
+         * @param parsedTexture defines parsed texture data
+         * @param scene defines the current scene
+         * @param rootUrl defines the root URL containing marble procedural texture information
+         * @returns a parsed Marble Procedural Texture
+         */
+        public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): MarbleProceduralTexture {
+            var texture = SerializationHelper.Parse(() => new MarbleProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
+
+            return texture;
+        }
     }
 }

+ 25 - 0
proceduralTexturesLibrary/src/normalMap/babylon.normalMapProceduralTexture.ts

@@ -25,6 +25,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
 
+        @serializeAsTexture()
         public get baseTexture(): Texture {
             return this._baseTexture;
         }
@@ -33,5 +34,29 @@ module BABYLON {
             this._baseTexture = texture;
             this.updateShaderUniforms();
         }
+
+        /**
+         * Serializes this normal map procedural texture
+         * @returns a serialized normal map procedural texture object
+         */
+        public serialize(): any {
+            var serializationObject = SerializationHelper.Serialize(this, super.serialize());
+            serializationObject.customType = "BABYLON.NormalMapProceduralTexture";
+
+            return serializationObject;
+        }
+
+        /**
+         * Creates a Normal Map Procedural Texture from parsed normal map procedural texture data
+         * @param parsedTexture defines parsed texture data
+         * @param scene defines the current scene
+         * @param rootUrl defines the root URL containing normal map procedural texture information
+         * @returns a parsed Normal Map Procedural Texture
+         */
+        public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): NormalMapProceduralTexture {
+            var texture = SerializationHelper.Parse(() => new NormalMapProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
+
+            return texture;
+        }
     }
 }

+ 29 - 0
proceduralTexturesLibrary/src/perlinNoise/babylon.perlinNoiseProceduralTexture.ts

@@ -2,8 +2,13 @@
 
 module BABYLON {
     export class PerlinNoiseProceduralTexture extends ProceduralTexture {
+        @serialize()
         public time: number = 0.0;
+
+        @serialize()
         public speed: number = 1.0;
+
+        @serialize()
         public translationSpeed: number = 1.0;
 
         private _currentTranslation: number = 0;
@@ -38,5 +43,29 @@ module BABYLON {
         public resize(size: any, generateMipMaps: any): void {
             super.resize(size, generateMipMaps);
         }
+
+        /**
+         * Serializes this perlin noise procedural texture
+         * @returns a serialized perlin noise procedural texture object
+         */
+        public serialize(): any {
+            var serializationObject = SerializationHelper.Serialize(this, super.serialize());
+            serializationObject.customType = "BABYLON.PerlinNoiseProceduralTexture";
+
+            return serializationObject;
+        }
+
+        /**
+         * Creates a Perlin Noise Procedural Texture from parsed perlin noise procedural texture data
+         * @param parsedTexture defines parsed texture data
+         * @param scene defines the current scene
+         * @param rootUrl defines the root URL containing perlin noise procedural texture information
+         * @returns a parsed Perlin Noise Procedural Texture
+         */
+        public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): PerlinNoiseProceduralTexture {
+            var texture = SerializationHelper.Parse(() => new PerlinNoiseProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
+
+            return texture;
+        }
     }
 }

+ 25 - 0
proceduralTexturesLibrary/src/road/babylon.roadProceduralTexture.ts

@@ -13,6 +13,7 @@ module BABYLON {
             this.setColor3("roadColor", this._roadColor);
         }
 
+        @serializeAsColor3()
         public get roadColor(): Color3 {
             return this._roadColor;
         }
@@ -21,5 +22,29 @@ module BABYLON {
             this._roadColor = value;
             this.updateShaderUniforms();
         }
+
+        /**
+         * Serializes this road procedural texture
+         * @returns a serialized road procedural texture object
+         */
+        public serialize(): any {
+            var serializationObject = SerializationHelper.Serialize(this, super.serialize());
+            serializationObject.customType = "BABYLON.RoadProceduralTexture";
+
+            return serializationObject;
+        }
+
+        /**
+         * Creates a Road Procedural Texture from parsed road procedural texture data
+         * @param parsedTexture defines parsed texture data
+         * @param scene defines the current scene
+         * @param rootUrl defines the root URL containing road procedural texture information
+         * @returns a parsed Road Procedural Texture
+         */
+        public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): RoadProceduralTexture {
+            var texture = SerializationHelper.Parse(() => new RoadProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
+
+            return texture;
+        }
     }
 }

+ 35 - 0
proceduralTexturesLibrary/src/starfield/babylon.starfieldProceduralTexture.ts

@@ -33,6 +33,7 @@ module BABYLON {
             this.setFloat("saturation", this._saturation); 
         }
 
+        @serialize()
         public get time(): number {
             return this._time;
         }
@@ -42,6 +43,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }      
         
+        @serialize()
         public get alpha(): number {
             return this._alpha;
         }
@@ -51,6 +53,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }    
 
+        @serialize()
         public get beta(): number {
             return this._beta;
         }
@@ -60,6 +63,7 @@ module BABYLON {
             this.updateShaderUniforms();
         } 
 
+        @serialize()
         public get formuparam(): number {
             return this._formuparam;
         }
@@ -69,6 +73,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
         
+        @serialize()
         public get stepsize(): number {
             return this._stepsize;
         }
@@ -78,6 +83,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
         
+        @serialize()
         public get zoom(): number {
             return this._zoom;
         }
@@ -87,6 +93,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
         
+        @serialize()
         public get tile(): number {
             return this._tile;
         }
@@ -96,6 +103,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
         
+        @serialize()
         public get brightness(): number {
             return this._brightness;
         }
@@ -105,6 +113,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
         
+        @serialize()
         public get darkmatter(): number {
             return this._darkmatter;
         }
@@ -114,6 +123,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
         
+        @serialize()
         public get distfading(): number {
             return this._distfading;
         }
@@ -123,6 +133,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
         
+        @serialize()
         public get saturation(): number {
             return this._saturation;
         }
@@ -131,5 +142,29 @@ module BABYLON {
             this._saturation = value;
             this.updateShaderUniforms();
         }
+
+        /**
+         * Serializes this starfield procedural texture
+         * @returns a serialized starfield procedural texture object
+         */
+        public serialize(): any {
+            var serializationObject = SerializationHelper.Serialize(this, super.serialize());
+            serializationObject.customType = "BABYLON.StarfieldProceduralTexture";
+
+            return serializationObject;
+        }
+
+        /**
+         * Creates a Starfield Procedural Texture from parsed startfield procedural texture data
+         * @param parsedTexture defines parsed texture data
+         * @param scene defines the current scene
+         * @param rootUrl defines the root URL containing startfield procedural texture information
+         * @returns a parsed Starfield Procedural Texture
+         */
+        public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): StarfieldProceduralTexture {
+            var texture = SerializationHelper.Parse(() => new StarfieldProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
+
+            return texture;
+        }
     }
 }

+ 26 - 0
proceduralTexturesLibrary/src/wood/babylon.woodProceduralTexture.ts

@@ -15,6 +15,7 @@ module BABYLON {
             this.setColor3("woodColor", this._woodColor);
         }
 
+        @serialize()
         public get ampScale(): number {
             return this._ampScale;
         }
@@ -24,6 +25,7 @@ module BABYLON {
             this.updateShaderUniforms();
         }
 
+        @serializeAsColor3()
         public get woodColor(): Color3 {
             return this._woodColor;
         }
@@ -32,5 +34,29 @@ module BABYLON {
             this._woodColor = value;
             this.updateShaderUniforms();
         }
+
+        /**
+         * Serializes this wood procedural texture
+         * @returns a serialized wood procedural texture object
+         */
+        public serialize(): any {
+            var serializationObject = SerializationHelper.Serialize(this, super.serialize());
+            serializationObject.customType = "BABYLON.WoodProceduralTexture";
+
+            return serializationObject;
+        }
+
+        /**
+         * Creates a Wood Procedural Texture from parsed wood procedural texture data
+         * @param parsedTexture defines parsed texture data
+         * @param scene defines the current scene
+         * @param rootUrl defines the root URL containing wood procedural texture information
+         * @returns a parsed Wood Procedural Texture
+         */
+        public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): WoodProceduralTexture {
+            var texture = SerializationHelper.Parse(() => new WoodProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
+
+            return texture;
+        }
     }
 }