Jelajahi Sumber

Added serialization decorators for materials

David Catuhe 9 tahun lalu
induk
melakukan
3581c0aad4

+ 1 - 0
Tools/Gulp/config.json

@@ -16,6 +16,7 @@
     ],
     "files": [
       "../../src/Math/babylon.math.js",
+      "../../src/Tools/babylon.decorators.js",
       "../../src/Tools/babylon.database.js",
       "../../src/Tools/babylon.tools.tga.js",
       "../../src/Tools/babylon.smartArray.js",

+ 4 - 2
Tools/Gulp/gulpfile.js

@@ -67,7 +67,8 @@ gulp.task('typescript-compile', function () {
             noExternalResolve: true,
             target: 'ES5',
             declarationFiles: true,
-            typescript: require('typescript')
+            typescript: require('typescript'),
+            experimentalDecorators: true
         }));
     return merge2([
         tsResult.dts
@@ -85,7 +86,8 @@ gulp.task('typescript-sourcemaps', function () {
             noExternalResolve: true,
             target: 'ES5',
             declarationFiles: true,
-            typescript: require('typescript')
+            typescript: require('typescript'),
+            experimentalDecorators: true
         }));
     return tsResult.js
         .pipe(sourcemaps.write("./")) // sourcemaps are written.

File diff ditekan karena terlalu besar
+ 22 - 22
dist/preview release/babylon.core.js


File diff ditekan karena terlalu besar
+ 1074 - 1063
dist/preview release/babylon.d.ts


File diff ditekan karena terlalu besar
+ 26 - 26
dist/preview release/babylon.js


+ 272 - 215
dist/preview release/babylon.max.js

@@ -3050,6 +3050,123 @@ var BABYLON;
 
 var BABYLON;
 (function (BABYLON) {
+    function generateSerializableMember(type, sourceName) {
+        return function (target, propertyKey) {
+            if (!target.__serializableMembers) {
+                target.__serializableMembers = {};
+            }
+            target.__serializableMembers[propertyKey] = { type: type, sourceName: sourceName };
+        };
+    }
+    function serialize(sourceName) {
+        return generateSerializableMember(0, sourceName); // value member
+    }
+    BABYLON.serialize = serialize;
+    function serializeAsTexture(sourceName) {
+        return generateSerializableMember(1, sourceName); // texture member
+    }
+    BABYLON.serializeAsTexture = serializeAsTexture;
+    function serializeAsColor3(sourceName) {
+        return generateSerializableMember(2, sourceName); // color3 member
+    }
+    BABYLON.serializeAsColor3 = serializeAsColor3;
+    function serializeAsFresnelParameters(sourceName) {
+        return generateSerializableMember(3, sourceName); // fresnel parameters member
+    }
+    BABYLON.serializeAsFresnelParameters = serializeAsFresnelParameters;
+    var SerializationHelper = (function () {
+        function SerializationHelper() {
+        }
+        SerializationHelper.Serialize = function (entity, serializationObject) {
+            if (!serializationObject) {
+                serializationObject = {};
+            }
+            // Tags
+            serializationObject.tags = BABYLON.Tags.GetTags(entity);
+            // Properties
+            for (var property in entity.__serializableMembers) {
+                var propertyDescriptor = entity.__serializableMembers[property];
+                var targetPropertyName = propertyDescriptor.sourceName || property;
+                var propertyType = propertyDescriptor.type;
+                var sourceProperty = entity[property];
+                if (sourceProperty !== undefined && sourceProperty !== null) {
+                    switch (propertyType) {
+                        case 0:
+                            serializationObject[targetPropertyName] = sourceProperty;
+                            break;
+                        case 1:
+                            serializationObject[targetPropertyName] = sourceProperty.serialize();
+                            break;
+                        case 2:
+                            serializationObject[targetPropertyName] = sourceProperty.asArray();
+                            break;
+                        case 3:
+                            serializationObject[targetPropertyName] = sourceProperty.serialize();
+                            break;
+                    }
+                }
+            }
+            return serializationObject;
+        };
+        SerializationHelper.Parse = function (creationFunction, source, scene, rootUrl) {
+            var destination = creationFunction();
+            // Tags
+            BABYLON.Tags.AddTagsTo(destination, source.tags);
+            // Properties
+            for (var property in destination.__serializableMembers) {
+                var propertyDescriptor = destination.__serializableMembers[property];
+                var sourceProperty = source[propertyDescriptor.sourceName || property];
+                var propertyType = propertyDescriptor.type;
+                if (sourceProperty !== undefined && sourceProperty !== null) {
+                    switch (propertyType) {
+                        case 0:
+                            destination[property] = sourceProperty;
+                            break;
+                        case 1:
+                            destination[property] = BABYLON.Texture.Parse(sourceProperty, scene, rootUrl);
+                            break;
+                        case 2:
+                            destination[property] = BABYLON.Color3.FromArray(sourceProperty);
+                            break;
+                        case 3:
+                            destination[property] = BABYLON.FresnelParameters.Parse(sourceProperty);
+                            break;
+                    }
+                }
+            }
+            return destination;
+        };
+        SerializationHelper.Clone = function (creationFunction, source) {
+            var destination = creationFunction();
+            // Tags
+            BABYLON.Tags.AddTagsTo(destination, source.tags);
+            // Properties
+            for (var property in destination.__serializableMembers) {
+                var propertyDescriptor = destination.__serializableMembers[property];
+                var sourceProperty = source[property];
+                var propertyType = propertyDescriptor.type;
+                if (sourceProperty !== undefined && sourceProperty !== null) {
+                    switch (propertyType) {
+                        case 0:
+                            destination[property] = sourceProperty;
+                            break;
+                        case 1: // Texture
+                        case 2: // Color3
+                        case 3:
+                            destination[property] = sourceProperty.clone();
+                            break;
+                    }
+                }
+            }
+            return destination;
+        };
+        return SerializationHelper;
+    })();
+    BABYLON.SerializationHelper = SerializationHelper;
+})(BABYLON || (BABYLON = {}));
+
+var BABYLON;
+(function (BABYLON) {
     var Database = (function () {
         function Database(urlToScene, callbackManifestChecked) {
             // Handling various flavors of prefixed version of IndexedDB
@@ -19581,6 +19698,12 @@ var BABYLON;
     BABYLON.FresnelParameters = FresnelParameters;
 })(BABYLON || (BABYLON = {}));
 
+var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
+    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
+    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
+    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
+    return c > 3 && r && Object.defineProperty(target, key, r), r;
+};
 var BABYLON;
 (function (BABYLON) {
     var MaterialDefines = (function () {
@@ -19640,10 +19763,10 @@ var BABYLON;
             this.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
             this.disableDepthWrite = false;
             this.fogEnabled = true;
-            this._wasPreviouslyReady = false;
-            this._fillMode = Material.TriangleFillMode;
             this.pointSize = 1.0;
             this.zOffset = 0;
+            this._wasPreviouslyReady = false;
+            this._fillMode = Material.TriangleFillMode;
             this.id = name;
             this._scene = scene;
             if (!doNotAdd) {
@@ -19813,31 +19936,8 @@ var BABYLON;
                 this.onDispose();
             }
         };
-        Material.prototype.copyTo = function (other) {
-            other.checkReadyOnlyOnce = this.checkReadyOnlyOnce;
-            other.checkReadyOnEveryCall = this.checkReadyOnEveryCall;
-            other.alpha = this.alpha;
-            other.fillMode = this.fillMode;
-            other.backFaceCulling = this.backFaceCulling;
-            other.fogEnabled = this.fogEnabled;
-            other.wireframe = this.wireframe;
-            other.zOffset = this.zOffset;
-            other.alphaMode = this.alphaMode;
-            other.sideOrientation = this.sideOrientation;
-            other.disableDepthWrite = this.disableDepthWrite;
-            other.pointSize = this.pointSize;
-            other.pointsCloud = this.pointsCloud;
-        };
         Material.prototype.serialize = function () {
-            var serializationObject = {};
-            serializationObject.name = this.name;
-            serializationObject.alpha = this.alpha;
-            serializationObject.id = this.id;
-            serializationObject.tags = BABYLON.Tags.GetTags(this);
-            serializationObject.backFaceCulling = this.backFaceCulling;
-            serializationObject.checkReadyOnlyOnce = this.checkReadyOnlyOnce;
-            serializationObject.disableDepthWrite = this.disableDepthWrite;
-            return serializationObject;
+            return BABYLON.SerializationHelper.Serialize(this);
         };
         Material.ParseMultiMaterial = function (parsedMultiMaterial, scene) {
             var multiMaterial = new BABYLON.MultiMaterial(parsedMultiMaterial.name, scene);
@@ -19867,6 +19967,51 @@ var BABYLON;
         Material._PointFillMode = 2;
         Material._ClockWiseSideOrientation = 0;
         Material._CounterClockWiseSideOrientation = 1;
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "id", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "checkReadyOnEveryCall", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "checkReadyOnlyOnce", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "state", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "alpha", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "backFaceCulling", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "sideOrientation", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "alphaMode", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "disableDepthWrite", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "fogEnabled", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "pointSize", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "zOffset", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "wireframe", null);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "pointsCloud", null);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "fillMode", null);
         return Material;
     })();
     BABYLON.Material = Material;
@@ -19979,8 +20124,8 @@ var BABYLON;
             this.ambientColor = new BABYLON.Color3(0, 0, 0);
             this.diffuseColor = new BABYLON.Color3(1, 1, 1);
             this.specularColor = new BABYLON.Color3(1, 1, 1);
-            this.specularPower = 64;
             this.emissiveColor = new BABYLON.Color3(0, 0, 0);
+            this.specularPower = 64;
             this.useAlphaFromDiffuseTexture = false;
             this.useEmissiveAsIllumination = false;
             this.linkEmissiveWithDiffuse = false;
@@ -20576,195 +20721,14 @@ var BABYLON;
             _super.prototype.dispose.call(this, forceDisposeEffect);
         };
         StandardMaterial.prototype.clone = function (name) {
-            var newStandardMaterial = new StandardMaterial(name, this.getScene());
-            // Base material
-            this.copyTo(newStandardMaterial);
-            // Standard material
-            if (this.diffuseTexture && this.diffuseTexture.clone) {
-                newStandardMaterial.diffuseTexture = this.diffuseTexture.clone();
-            }
-            if (this.ambientTexture && this.ambientTexture.clone) {
-                newStandardMaterial.ambientTexture = this.ambientTexture.clone();
-            }
-            if (this.opacityTexture && this.opacityTexture.clone) {
-                newStandardMaterial.opacityTexture = this.opacityTexture.clone();
-            }
-            if (this.reflectionTexture && this.reflectionTexture.clone) {
-                newStandardMaterial.reflectionTexture = this.reflectionTexture.clone();
-            }
-            if (this.emissiveTexture && this.emissiveTexture.clone) {
-                newStandardMaterial.emissiveTexture = this.emissiveTexture.clone();
-            }
-            if (this.specularTexture && this.specularTexture.clone) {
-                newStandardMaterial.specularTexture = this.specularTexture.clone();
-            }
-            if (this.bumpTexture && this.bumpTexture.clone) {
-                newStandardMaterial.bumpTexture = this.bumpTexture.clone();
-            }
-            if (this.lightmapTexture && this.lightmapTexture.clone) {
-                newStandardMaterial.lightmapTexture = this.lightmapTexture.clone();
-                newStandardMaterial.useLightmapAsShadowmap = this.useLightmapAsShadowmap;
-            }
-            if (this.refractionTexture && this.refractionTexture.clone) {
-                newStandardMaterial.refractionTexture = this.refractionTexture.clone();
-            }
-            newStandardMaterial.ambientColor = this.ambientColor.clone();
-            newStandardMaterial.diffuseColor = this.diffuseColor.clone();
-            newStandardMaterial.specularColor = this.specularColor.clone();
-            newStandardMaterial.specularPower = this.specularPower;
-            newStandardMaterial.emissiveColor = this.emissiveColor.clone();
-            newStandardMaterial.useAlphaFromDiffuseTexture = this.useAlphaFromDiffuseTexture;
-            newStandardMaterial.useEmissiveAsIllumination = this.useEmissiveAsIllumination;
-            newStandardMaterial.useGlossinessFromSpecularMapAlpha = this.useGlossinessFromSpecularMapAlpha;
-            newStandardMaterial.useReflectionFresnelFromSpecular = this.useReflectionFresnelFromSpecular;
-            newStandardMaterial.useSpecularOverAlpha = this.useSpecularOverAlpha;
-            newStandardMaterial.useReflectionOverAlpha = this.useReflectionOverAlpha;
-            newStandardMaterial.roughness = this.roughness;
-            newStandardMaterial.indexOfRefraction = this.indexOfRefraction;
-            newStandardMaterial.invertRefractionY = this.invertRefractionY;
-            if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.clone) {
-                newStandardMaterial.diffuseFresnelParameters = this.diffuseFresnelParameters.clone();
-            }
-            if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.clone) {
-                newStandardMaterial.emissiveFresnelParameters = this.emissiveFresnelParameters.clone();
-            }
-            if (this.reflectionFresnelParameters && this.reflectionFresnelParameters.clone) {
-                newStandardMaterial.reflectionFresnelParameters = this.reflectionFresnelParameters.clone();
-            }
-            if (this.refractionFresnelParameters && this.refractionFresnelParameters.clone) {
-                newStandardMaterial.refractionFresnelParameters = this.refractionFresnelParameters.clone();
-            }
-            if (this.opacityFresnelParameters && this.opacityFresnelParameters.clone) {
-                newStandardMaterial.opacityFresnelParameters = this.opacityFresnelParameters.clone();
-            }
-            return newStandardMaterial;
+            var _this = this;
+            return BABYLON.SerializationHelper.Clone(function () { return new StandardMaterial(name, _this.getScene()); }, this);
         };
         StandardMaterial.prototype.serialize = function () {
-            var serializationObject = _super.prototype.serialize.call(this);
-            serializationObject.ambient = this.ambientColor.asArray();
-            serializationObject.diffuse = this.diffuseColor.asArray();
-            serializationObject.specular = this.specularColor.asArray();
-            serializationObject.specularPower = this.specularPower;
-            serializationObject.emissive = this.emissiveColor.asArray();
-            serializationObject.useReflectionFresnelFromSpecular = this.useReflectionFresnelFromSpecular;
-            serializationObject.useEmissiveAsIllumination = this.useEmissiveAsIllumination;
-            serializationObject.indexOfRefraction = this.indexOfRefraction;
-            serializationObject.invertRefractionY = this.invertRefractionY;
-            serializationObject.useSpecularOverAlpha = this.useSpecularOverAlpha;
-            serializationObject.useReflectionOverAlpha = this.useReflectionOverAlpha;
-            if (this.diffuseTexture) {
-                serializationObject.diffuseTexture = this.diffuseTexture.serialize();
-            }
-            if (this.diffuseFresnelParameters) {
-                serializationObject.diffuseFresnelParameters = this.diffuseFresnelParameters.serialize();
-            }
-            if (this.ambientTexture) {
-                serializationObject.ambientTexture = this.ambientTexture.serialize();
-            }
-            if (this.opacityTexture) {
-                serializationObject.opacityTexture = this.opacityTexture.serialize();
-            }
-            if (this.opacityFresnelParameters) {
-                serializationObject.opacityFresnelParameters = this.diffuseFresnelParameters.serialize();
-            }
-            if (this.reflectionTexture) {
-                serializationObject.reflectionTexture = this.reflectionTexture.serialize();
-            }
-            if (this.reflectionFresnelParameters) {
-                serializationObject.reflectionFresnelParameters = this.reflectionFresnelParameters.serialize();
-            }
-            if (this.refractionFresnelParameters) {
-                serializationObject.refractionFresnelParameters = this.refractionFresnelParameters.serialize();
-            }
-            if (this.emissiveTexture) {
-                serializationObject.emissiveTexture = this.emissiveTexture.serialize();
-            }
-            if (this.lightmapTexture) {
-                serializationObject.lightmapTexture = this.lightmapTexture.serialize();
-                serializationObject.useLightmapAsShadowmap = this.useLightmapAsShadowmap;
-            }
-            if (this.emissiveFresnelParameters) {
-                serializationObject.emissiveFresnelParameters = this.emissiveFresnelParameters.serialize();
-            }
-            if (this.specularTexture) {
-                serializationObject.specularTexture = this.specularTexture.serialize();
-            }
-            if (this.bumpTexture) {
-                serializationObject.bumpTexture = this.bumpTexture.serialize();
-            }
-            if (this.refractionTexture) {
-                serializationObject.refractionTexture = this.refractionTexture.serialize();
-            }
-            return serializationObject;
+            return BABYLON.SerializationHelper.Serialize(this);
         };
         StandardMaterial.Parse = function (source, scene, rootUrl) {
-            var material = new StandardMaterial(source.name, scene);
-            material.ambientColor = BABYLON.Color3.FromArray(source.ambient);
-            material.diffuseColor = BABYLON.Color3.FromArray(source.diffuse);
-            material.specularColor = BABYLON.Color3.FromArray(source.specular);
-            material.specularPower = source.specularPower;
-            material.emissiveColor = BABYLON.Color3.FromArray(source.emissive);
-            material.useReflectionFresnelFromSpecular = source.useReflectionFresnelFromSpecular;
-            material.useEmissiveAsIllumination = source.useEmissiveAsIllumination;
-            material.indexOfRefraction = source.indexOfRefraction;
-            material.invertRefractionY = source.invertRefractionY;
-            material.useSpecularOverAlpha = source.useSpecularOverAlpha;
-            material.useReflectionOverAlpha = source.useReflectionOverAlpha;
-            material.alpha = source.alpha;
-            material.id = source.id;
-            if (source.disableDepthWrite) {
-                material.disableDepthWrite = source.disableDepthWrite;
-            }
-            BABYLON.Tags.AddTagsTo(material, source.tags);
-            material.backFaceCulling = source.backFaceCulling;
-            material.wireframe = source.wireframe;
-            if (source.diffuseTexture) {
-                material.diffuseTexture = BABYLON.Texture.Parse(source.diffuseTexture, scene, rootUrl);
-            }
-            if (source.diffuseFresnelParameters) {
-                material.diffuseFresnelParameters = BABYLON.FresnelParameters.Parse(source.diffuseFresnelParameters);
-            }
-            if (source.ambientTexture) {
-                material.ambientTexture = BABYLON.Texture.Parse(source.ambientTexture, scene, rootUrl);
-            }
-            if (source.opacityTexture) {
-                material.opacityTexture = BABYLON.Texture.Parse(source.opacityTexture, scene, rootUrl);
-            }
-            if (source.opacityFresnelParameters) {
-                material.opacityFresnelParameters = BABYLON.FresnelParameters.Parse(source.opacityFresnelParameters);
-            }
-            if (source.reflectionTexture) {
-                material.reflectionTexture = BABYLON.Texture.Parse(source.reflectionTexture, scene, rootUrl);
-            }
-            if (source.reflectionFresnelParameters) {
-                material.reflectionFresnelParameters = BABYLON.FresnelParameters.Parse(source.reflectionFresnelParameters);
-            }
-            if (source.refractionFresnelParameters) {
-                material.refractionFresnelParameters = BABYLON.FresnelParameters.Parse(source.refractionFresnelParameters);
-            }
-            if (source.emissiveTexture) {
-                material.emissiveTexture = BABYLON.Texture.Parse(source.emissiveTexture, scene, rootUrl);
-            }
-            if (source.lightmapTexture) {
-                material.lightmapTexture = BABYLON.Texture.Parse(source.lightmapTexture, scene, rootUrl);
-                material.useLightmapAsShadowmap = source.useLightmapAsShadowmap;
-            }
-            if (source.emissiveFresnelParameters) {
-                material.emissiveFresnelParameters = BABYLON.FresnelParameters.Parse(source.emissiveFresnelParameters);
-            }
-            if (source.specularTexture) {
-                material.specularTexture = BABYLON.Texture.Parse(source.specularTexture, scene, rootUrl);
-            }
-            if (source.bumpTexture) {
-                material.bumpTexture = BABYLON.Texture.Parse(source.bumpTexture, scene, rootUrl);
-            }
-            if (source.refractionTexture) {
-                material.refractionTexture = BABYLON.Texture.Parse(source.refractionTexture, scene, rootUrl);
-            }
-            if (source.checkReadyOnlyOnce) {
-                material.checkReadyOnlyOnce = source.checkReadyOnlyOnce;
-            }
-            return material;
+            return BABYLON.SerializationHelper.Parse(function () { return new StandardMaterial(source.name, scene); }, source, scene, rootUrl);
         };
         // Statics
         // Flags used to enable or disable a type of texture for all Standard Materials
@@ -20778,6 +20742,99 @@ var BABYLON;
         StandardMaterial.FresnelEnabled = true;
         StandardMaterial.LightmapTextureEnabled = true;
         StandardMaterial.RefractionTextureEnabled = true;
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "diffuseTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "ambientTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "opacityTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "reflectionTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "emissiveTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "specularTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "bumpTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "lightmapTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "refractionTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsColor3("ambient")
+        ], StandardMaterial.prototype, "ambientColor", void 0);
+        __decorate([
+            BABYLON.serializeAsColor3("diffuse")
+        ], StandardMaterial.prototype, "diffuseColor", void 0);
+        __decorate([
+            BABYLON.serializeAsColor3("specular")
+        ], StandardMaterial.prototype, "specularColor", void 0);
+        __decorate([
+            BABYLON.serializeAsColor3("emissive")
+        ], StandardMaterial.prototype, "emissiveColor", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "specularPower", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useAlphaFromDiffuseTexture", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useEmissiveAsIllumination", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "linkEmissiveWithDiffuse", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useReflectionFresnelFromSpecular", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useSpecularOverAlpha", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useReflectionOverAlpha", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "disableLighting", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "roughness", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "indexOfRefraction", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "invertRefractionY", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useLightmapAsShadowmap", void 0);
+        __decorate([
+            BABYLON.serializeAsFresnelParameters()
+        ], StandardMaterial.prototype, "diffuseFresnelParameters", void 0);
+        __decorate([
+            BABYLON.serializeAsFresnelParameters()
+        ], StandardMaterial.prototype, "opacityFresnelParameters", void 0);
+        __decorate([
+            BABYLON.serializeAsFresnelParameters()
+        ], StandardMaterial.prototype, "reflectionFresnelParameters", void 0);
+        __decorate([
+            BABYLON.serializeAsFresnelParameters()
+        ], StandardMaterial.prototype, "refractionFresnelParameters", void 0);
+        __decorate([
+            BABYLON.serializeAsFresnelParameters()
+        ], StandardMaterial.prototype, "emissiveFresnelParameters", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useGlossinessFromSpecularMapAlpha", void 0);
         return StandardMaterial;
     })(BABYLON.Material);
     BABYLON.StandardMaterial = StandardMaterial;
@@ -29968,10 +30025,10 @@ var BABYLON;
             _super.prototype.dispose.call(this, forceDisposeEffect);
         };
         ShaderMaterial.prototype.serialize = function () {
-            var serializationObject = _super.prototype.serialize.call(this);
+            var serializationObject = BABYLON.SerializationHelper.Serialize(this);
+            serializationObject.customType = "BABYLON.ShaderMaterial";
             serializationObject.options = this._options;
             serializationObject.shaderPath = this._shaderPath;
-            serializationObject.customType = "BABYLON.ShaderMaterial";
             // Texture
             serializationObject.textures = {};
             for (var name in this._textures) {
@@ -30030,7 +30087,7 @@ var BABYLON;
             return serializationObject;
         };
         ShaderMaterial.Parse = function (source, scene, rootUrl) {
-            var material = new ShaderMaterial(source.name, scene, source.shaderPath, source.options);
+            var material = BABYLON.SerializationHelper.Parse(function () { return new ShaderMaterial(source.name, scene, source.shaderPath, source.options); }, source, scene, rootUrl);
             // Texture
             for (var name in source.textures) {
                 material.setTexture(name, BABYLON.Texture.Parse(source.textures[name], scene, rootUrl));

File diff ditekan karena terlalu besar
+ 26 - 26
dist/preview release/babylon.noworker.js


+ 54 - 26
src/Materials/babylon.material.js

@@ -1,3 +1,9 @@
+var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
+    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
+    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
+    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
+    return c > 3 && r && Object.defineProperty(target, key, r), r;
+};
 var BABYLON;
 (function (BABYLON) {
     var MaterialDefines = (function () {
@@ -57,10 +63,10 @@ var BABYLON;
             this.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
             this.disableDepthWrite = false;
             this.fogEnabled = true;
-            this._wasPreviouslyReady = false;
-            this._fillMode = Material.TriangleFillMode;
             this.pointSize = 1.0;
             this.zOffset = 0;
+            this._wasPreviouslyReady = false;
+            this._fillMode = Material.TriangleFillMode;
             this.id = name;
             this._scene = scene;
             if (!doNotAdd) {
@@ -230,31 +236,8 @@ var BABYLON;
                 this.onDispose();
             }
         };
-        Material.prototype.copyTo = function (other) {
-            other.checkReadyOnlyOnce = this.checkReadyOnlyOnce;
-            other.checkReadyOnEveryCall = this.checkReadyOnEveryCall;
-            other.alpha = this.alpha;
-            other.fillMode = this.fillMode;
-            other.backFaceCulling = this.backFaceCulling;
-            other.fogEnabled = this.fogEnabled;
-            other.wireframe = this.wireframe;
-            other.zOffset = this.zOffset;
-            other.alphaMode = this.alphaMode;
-            other.sideOrientation = this.sideOrientation;
-            other.disableDepthWrite = this.disableDepthWrite;
-            other.pointSize = this.pointSize;
-            other.pointsCloud = this.pointsCloud;
-        };
         Material.prototype.serialize = function () {
-            var serializationObject = {};
-            serializationObject.name = this.name;
-            serializationObject.alpha = this.alpha;
-            serializationObject.id = this.id;
-            serializationObject.tags = BABYLON.Tags.GetTags(this);
-            serializationObject.backFaceCulling = this.backFaceCulling;
-            serializationObject.checkReadyOnlyOnce = this.checkReadyOnlyOnce;
-            serializationObject.disableDepthWrite = this.disableDepthWrite;
-            return serializationObject;
+            return BABYLON.SerializationHelper.Serialize(this);
         };
         Material.ParseMultiMaterial = function (parsedMultiMaterial, scene) {
             var multiMaterial = new BABYLON.MultiMaterial(parsedMultiMaterial.name, scene);
@@ -284,6 +267,51 @@ var BABYLON;
         Material._PointFillMode = 2;
         Material._ClockWiseSideOrientation = 0;
         Material._CounterClockWiseSideOrientation = 1;
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "id", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "checkReadyOnEveryCall", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "checkReadyOnlyOnce", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "state", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "alpha", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "backFaceCulling", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "sideOrientation", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "alphaMode", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "disableDepthWrite", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "fogEnabled", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "pointSize", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "zOffset", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "wireframe", null);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "pointsCloud", null);
+        __decorate([
+            BABYLON.serialize()
+        ], Material.prototype, "fillMode", null);
         return Material;
     })();
     BABYLON.Material = Material;

+ 33 - 34
src/Materials/babylon.material.ts

@@ -80,32 +80,49 @@
             return Material._CounterClockWiseSideOrientation;
         }
 
+        @serialize()
         public id: string;
+
+        @serialize()
         public checkReadyOnEveryCall = false;
+
+        @serialize()
         public checkReadyOnlyOnce = false;
+
+        @serialize()
         public state = "";
+
+        @serialize()
         public alpha = 1.0;
+
+        @serialize()
         public backFaceCulling = true;
+
+        @serialize()
         public sideOrientation = Material.CounterClockWiseSideOrientation;
+
         public onCompiled: (effect: Effect) => void;
         public onError: (effect: Effect, errors: string) => void;
         public onDispose: () => void;
         public onBind: (material: Material, mesh: Mesh) => void;
         public getRenderTargetTextures: () => SmartArray<RenderTargetTexture>;
+
+        @serialize()
         public alphaMode = Engine.ALPHA_COMBINE;
+
+        @serialize()
         public disableDepthWrite = false;
-        public fogEnabled = true;
 
-        public _effect: Effect;
-        public _wasPreviouslyReady = false;
-        private _scene: Scene;
-        private _fillMode = Material.TriangleFillMode;
-        private _cachedDepthWriteState: boolean;
+        @serialize()
+        public fogEnabled = true;
 
+        @serialize()
         public pointSize = 1.0;
 
+        @serialize()
         public zOffset = 0;
 
+        @serialize()
         public get wireframe(): boolean {
             return this._fillMode === Material.WireFrameFillMode;
         }
@@ -114,6 +131,7 @@
             this._fillMode = (value ? Material.WireFrameFillMode : Material.TriangleFillMode);
         }
 
+        @serialize()
         public get pointsCloud(): boolean {
             return this._fillMode === Material.PointFillMode;
         }
@@ -122,6 +140,7 @@
             this._fillMode = (value ? Material.PointFillMode : Material.TriangleFillMode);
         }
 
+        @serialize()
         public get fillMode(): number {
             return this._fillMode;
         }
@@ -130,6 +149,13 @@
             this._fillMode = value;
         }
 
+        public _effect: Effect;
+        public _wasPreviouslyReady = false;
+        private _scene: Scene;
+        private _fillMode = Material.TriangleFillMode;
+        private _cachedDepthWriteState: boolean;
+
+
         constructor(public name: string, scene: Scene, doNotAdd?: boolean) {
             this.id = name;
 
@@ -263,35 +289,8 @@
             }
         }
 
-        public copyTo(other: Material): void {
-            other.checkReadyOnlyOnce = this.checkReadyOnlyOnce;
-            other.checkReadyOnEveryCall = this.checkReadyOnEveryCall;
-            other.alpha = this.alpha;
-            other.fillMode = this.fillMode;
-            other.backFaceCulling = this.backFaceCulling;
-            other.fogEnabled = this.fogEnabled;
-            other.wireframe = this.wireframe;
-            other.zOffset = this.zOffset;
-            other.alphaMode = this.alphaMode;
-            other.sideOrientation = this.sideOrientation;
-            other.disableDepthWrite = this.disableDepthWrite;
-            other.pointSize = this.pointSize;
-            other.pointsCloud = this.pointsCloud;
-        }
-
         public serialize(): any {
-            var serializationObject: any = {};
-
-            serializationObject.name = this.name;
-            serializationObject.alpha = this.alpha;
-
-            serializationObject.id = this.id;
-            serializationObject.tags = Tags.GetTags(this);
-            serializationObject.backFaceCulling = this.backFaceCulling;
-            serializationObject.checkReadyOnlyOnce = this.checkReadyOnlyOnce;
-            serializationObject.disableDepthWrite = this.disableDepthWrite;
-
-            return serializationObject;
+            return SerializationHelper.Serialize(this);
         }
 
         public static ParseMultiMaterial(parsedMultiMaterial: any, scene: Scene): MultiMaterial {

+ 3 - 3
src/Materials/babylon.shaderMaterial.js

@@ -227,10 +227,10 @@ var BABYLON;
             _super.prototype.dispose.call(this, forceDisposeEffect);
         };
         ShaderMaterial.prototype.serialize = function () {
-            var serializationObject = _super.prototype.serialize.call(this);
+            var serializationObject = BABYLON.SerializationHelper.Serialize(this);
+            serializationObject.customType = "BABYLON.ShaderMaterial";
             serializationObject.options = this._options;
             serializationObject.shaderPath = this._shaderPath;
-            serializationObject.customType = "BABYLON.ShaderMaterial";
             // Texture
             serializationObject.textures = {};
             for (var name in this._textures) {
@@ -289,7 +289,7 @@ var BABYLON;
             return serializationObject;
         };
         ShaderMaterial.Parse = function (source, scene, rootUrl) {
-            var material = new ShaderMaterial(source.name, scene, source.shaderPath, source.options);
+            var material = BABYLON.SerializationHelper.Parse(function () { return new ShaderMaterial(source.name, scene, source.shaderPath, source.options); }, source, scene, rootUrl);
             // Texture
             for (var name in source.textures) {
                 material.setTexture(name, BABYLON.Texture.Parse(source.textures[name], scene, rootUrl));

+ 5 - 4
src/Materials/babylon.shaderMaterial.ts

@@ -294,11 +294,12 @@
         }
 
         public serialize(): any {
-            var serializationObject = super.serialize();
-            serializationObject.options = this._options;
-            serializationObject.shaderPath = this._shaderPath;
+            var serializationObject = SerializationHelper.Serialize(this);
             serializationObject.customType = "BABYLON.ShaderMaterial";
 			
+            serializationObject.options = this._options;
+            serializationObject.shaderPath = this._shaderPath;
+
             // Texture
             serializationObject.textures = {};
             for (var name in this._textures) {
@@ -369,7 +370,7 @@
         }
 
         public static Parse(source: any, scene: Scene, rootUrl: string): ShaderMaterial {
-            var material = new ShaderMaterial(source.name, scene, source.shaderPath, source.options);
+            var material = SerializationHelper.Parse(() => new ShaderMaterial(source.name, scene, source.shaderPath, source.options), source, scene, rootUrl);
 			
             // Texture
             for (var name in source.textures) {

+ 105 - 187
src/Materials/babylon.standardMaterial.js

@@ -3,6 +3,12 @@ var __extends = (this && this.__extends) || function (d, b) {
     function __() { this.constructor = d; }
     d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
 };
+var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
+    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
+    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
+    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
+    return c > 3 && r && Object.defineProperty(target, key, r), r;
+};
 var BABYLON;
 (function (BABYLON) {
     var StandardMaterialDefines = (function (_super) {
@@ -104,8 +110,8 @@ var BABYLON;
             this.ambientColor = new BABYLON.Color3(0, 0, 0);
             this.diffuseColor = new BABYLON.Color3(1, 1, 1);
             this.specularColor = new BABYLON.Color3(1, 1, 1);
-            this.specularPower = 64;
             this.emissiveColor = new BABYLON.Color3(0, 0, 0);
+            this.specularPower = 64;
             this.useAlphaFromDiffuseTexture = false;
             this.useEmissiveAsIllumination = false;
             this.linkEmissiveWithDiffuse = false;
@@ -701,197 +707,16 @@ var BABYLON;
             _super.prototype.dispose.call(this, forceDisposeEffect);
         };
         StandardMaterial.prototype.clone = function (name) {
-            var newStandardMaterial = new StandardMaterial(name, this.getScene());
-            // Base material
-            this.copyTo(newStandardMaterial);
-            // Standard material
-            if (this.diffuseTexture && this.diffuseTexture.clone) {
-                newStandardMaterial.diffuseTexture = this.diffuseTexture.clone();
-            }
-            if (this.ambientTexture && this.ambientTexture.clone) {
-                newStandardMaterial.ambientTexture = this.ambientTexture.clone();
-            }
-            if (this.opacityTexture && this.opacityTexture.clone) {
-                newStandardMaterial.opacityTexture = this.opacityTexture.clone();
-            }
-            if (this.reflectionTexture && this.reflectionTexture.clone) {
-                newStandardMaterial.reflectionTexture = this.reflectionTexture.clone();
-            }
-            if (this.emissiveTexture && this.emissiveTexture.clone) {
-                newStandardMaterial.emissiveTexture = this.emissiveTexture.clone();
-            }
-            if (this.specularTexture && this.specularTexture.clone) {
-                newStandardMaterial.specularTexture = this.specularTexture.clone();
-            }
-            if (this.bumpTexture && this.bumpTexture.clone) {
-                newStandardMaterial.bumpTexture = this.bumpTexture.clone();
-            }
-            if (this.lightmapTexture && this.lightmapTexture.clone) {
-                newStandardMaterial.lightmapTexture = this.lightmapTexture.clone();
-                newStandardMaterial.useLightmapAsShadowmap = this.useLightmapAsShadowmap;
-            }
-            if (this.refractionTexture && this.refractionTexture.clone) {
-                newStandardMaterial.refractionTexture = this.refractionTexture.clone();
-            }
-            newStandardMaterial.ambientColor = this.ambientColor.clone();
-            newStandardMaterial.diffuseColor = this.diffuseColor.clone();
-            newStandardMaterial.specularColor = this.specularColor.clone();
-            newStandardMaterial.specularPower = this.specularPower;
-            newStandardMaterial.emissiveColor = this.emissiveColor.clone();
-            newStandardMaterial.useAlphaFromDiffuseTexture = this.useAlphaFromDiffuseTexture;
-            newStandardMaterial.useEmissiveAsIllumination = this.useEmissiveAsIllumination;
-            newStandardMaterial.useGlossinessFromSpecularMapAlpha = this.useGlossinessFromSpecularMapAlpha;
-            newStandardMaterial.useReflectionFresnelFromSpecular = this.useReflectionFresnelFromSpecular;
-            newStandardMaterial.useSpecularOverAlpha = this.useSpecularOverAlpha;
-            newStandardMaterial.useReflectionOverAlpha = this.useReflectionOverAlpha;
-            newStandardMaterial.roughness = this.roughness;
-            newStandardMaterial.indexOfRefraction = this.indexOfRefraction;
-            newStandardMaterial.invertRefractionY = this.invertRefractionY;
-            if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.clone) {
-                newStandardMaterial.diffuseFresnelParameters = this.diffuseFresnelParameters.clone();
-            }
-            if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.clone) {
-                newStandardMaterial.emissiveFresnelParameters = this.emissiveFresnelParameters.clone();
-            }
-            if (this.reflectionFresnelParameters && this.reflectionFresnelParameters.clone) {
-                newStandardMaterial.reflectionFresnelParameters = this.reflectionFresnelParameters.clone();
-            }
-            if (this.refractionFresnelParameters && this.refractionFresnelParameters.clone) {
-                newStandardMaterial.refractionFresnelParameters = this.refractionFresnelParameters.clone();
-            }
-            if (this.opacityFresnelParameters && this.opacityFresnelParameters.clone) {
-                newStandardMaterial.opacityFresnelParameters = this.opacityFresnelParameters.clone();
-            }
-            return newStandardMaterial;
+            var _this = this;
+            return BABYLON.SerializationHelper.Clone(function () { return new StandardMaterial(name, _this.getScene()); }, this);
         };
         StandardMaterial.prototype.serialize = function () {
-            var serializationObject = _super.prototype.serialize.call(this);
-            serializationObject.ambient = this.ambientColor.asArray();
-            serializationObject.diffuse = this.diffuseColor.asArray();
-            serializationObject.specular = this.specularColor.asArray();
-            serializationObject.specularPower = this.specularPower;
-            serializationObject.emissive = this.emissiveColor.asArray();
-            serializationObject.useReflectionFresnelFromSpecular = this.useReflectionFresnelFromSpecular;
-            serializationObject.useEmissiveAsIllumination = this.useEmissiveAsIllumination;
-            serializationObject.indexOfRefraction = this.indexOfRefraction;
-            serializationObject.invertRefractionY = this.invertRefractionY;
-            serializationObject.useSpecularOverAlpha = this.useSpecularOverAlpha;
-            serializationObject.useReflectionOverAlpha = this.useReflectionOverAlpha;
-            if (this.diffuseTexture) {
-                serializationObject.diffuseTexture = this.diffuseTexture.serialize();
-            }
-            if (this.diffuseFresnelParameters) {
-                serializationObject.diffuseFresnelParameters = this.diffuseFresnelParameters.serialize();
-            }
-            if (this.ambientTexture) {
-                serializationObject.ambientTexture = this.ambientTexture.serialize();
-            }
-            if (this.opacityTexture) {
-                serializationObject.opacityTexture = this.opacityTexture.serialize();
-            }
-            if (this.opacityFresnelParameters) {
-                serializationObject.opacityFresnelParameters = this.diffuseFresnelParameters.serialize();
-            }
-            if (this.reflectionTexture) {
-                serializationObject.reflectionTexture = this.reflectionTexture.serialize();
-            }
-            if (this.reflectionFresnelParameters) {
-                serializationObject.reflectionFresnelParameters = this.reflectionFresnelParameters.serialize();
-            }
-            if (this.refractionFresnelParameters) {
-                serializationObject.refractionFresnelParameters = this.refractionFresnelParameters.serialize();
-            }
-            if (this.emissiveTexture) {
-                serializationObject.emissiveTexture = this.emissiveTexture.serialize();
-            }
-            if (this.lightmapTexture) {
-                serializationObject.lightmapTexture = this.lightmapTexture.serialize();
-                serializationObject.useLightmapAsShadowmap = this.useLightmapAsShadowmap;
-            }
-            if (this.emissiveFresnelParameters) {
-                serializationObject.emissiveFresnelParameters = this.emissiveFresnelParameters.serialize();
-            }
-            if (this.specularTexture) {
-                serializationObject.specularTexture = this.specularTexture.serialize();
-            }
-            if (this.bumpTexture) {
-                serializationObject.bumpTexture = this.bumpTexture.serialize();
-            }
-            if (this.refractionTexture) {
-                serializationObject.refractionTexture = this.refractionTexture.serialize();
-            }
-            return serializationObject;
+            return BABYLON.SerializationHelper.Serialize(this);
         };
+        // Statics
         StandardMaterial.Parse = function (source, scene, rootUrl) {
-            var material = new StandardMaterial(source.name, scene);
-            material.ambientColor = BABYLON.Color3.FromArray(source.ambient);
-            material.diffuseColor = BABYLON.Color3.FromArray(source.diffuse);
-            material.specularColor = BABYLON.Color3.FromArray(source.specular);
-            material.specularPower = source.specularPower;
-            material.emissiveColor = BABYLON.Color3.FromArray(source.emissive);
-            material.useReflectionFresnelFromSpecular = source.useReflectionFresnelFromSpecular;
-            material.useEmissiveAsIllumination = source.useEmissiveAsIllumination;
-            material.indexOfRefraction = source.indexOfRefraction;
-            material.invertRefractionY = source.invertRefractionY;
-            material.useSpecularOverAlpha = source.useSpecularOverAlpha;
-            material.useReflectionOverAlpha = source.useReflectionOverAlpha;
-            material.alpha = source.alpha;
-            material.id = source.id;
-            if (source.disableDepthWrite) {
-                material.disableDepthWrite = source.disableDepthWrite;
-            }
-            BABYLON.Tags.AddTagsTo(material, source.tags);
-            material.backFaceCulling = source.backFaceCulling;
-            material.wireframe = source.wireframe;
-            if (source.diffuseTexture) {
-                material.diffuseTexture = BABYLON.Texture.Parse(source.diffuseTexture, scene, rootUrl);
-            }
-            if (source.diffuseFresnelParameters) {
-                material.diffuseFresnelParameters = BABYLON.FresnelParameters.Parse(source.diffuseFresnelParameters);
-            }
-            if (source.ambientTexture) {
-                material.ambientTexture = BABYLON.Texture.Parse(source.ambientTexture, scene, rootUrl);
-            }
-            if (source.opacityTexture) {
-                material.opacityTexture = BABYLON.Texture.Parse(source.opacityTexture, scene, rootUrl);
-            }
-            if (source.opacityFresnelParameters) {
-                material.opacityFresnelParameters = BABYLON.FresnelParameters.Parse(source.opacityFresnelParameters);
-            }
-            if (source.reflectionTexture) {
-                material.reflectionTexture = BABYLON.Texture.Parse(source.reflectionTexture, scene, rootUrl);
-            }
-            if (source.reflectionFresnelParameters) {
-                material.reflectionFresnelParameters = BABYLON.FresnelParameters.Parse(source.reflectionFresnelParameters);
-            }
-            if (source.refractionFresnelParameters) {
-                material.refractionFresnelParameters = BABYLON.FresnelParameters.Parse(source.refractionFresnelParameters);
-            }
-            if (source.emissiveTexture) {
-                material.emissiveTexture = BABYLON.Texture.Parse(source.emissiveTexture, scene, rootUrl);
-            }
-            if (source.lightmapTexture) {
-                material.lightmapTexture = BABYLON.Texture.Parse(source.lightmapTexture, scene, rootUrl);
-                material.useLightmapAsShadowmap = source.useLightmapAsShadowmap;
-            }
-            if (source.emissiveFresnelParameters) {
-                material.emissiveFresnelParameters = BABYLON.FresnelParameters.Parse(source.emissiveFresnelParameters);
-            }
-            if (source.specularTexture) {
-                material.specularTexture = BABYLON.Texture.Parse(source.specularTexture, scene, rootUrl);
-            }
-            if (source.bumpTexture) {
-                material.bumpTexture = BABYLON.Texture.Parse(source.bumpTexture, scene, rootUrl);
-            }
-            if (source.refractionTexture) {
-                material.refractionTexture = BABYLON.Texture.Parse(source.refractionTexture, scene, rootUrl);
-            }
-            if (source.checkReadyOnlyOnce) {
-                material.checkReadyOnlyOnce = source.checkReadyOnlyOnce;
-            }
-            return material;
+            return BABYLON.SerializationHelper.Parse(function () { return new StandardMaterial(source.name, scene); }, source, scene, rootUrl);
         };
-        // Statics
         // Flags used to enable or disable a type of texture for all Standard Materials
         StandardMaterial.DiffuseTextureEnabled = true;
         StandardMaterial.AmbientTextureEnabled = true;
@@ -903,6 +728,99 @@ var BABYLON;
         StandardMaterial.FresnelEnabled = true;
         StandardMaterial.LightmapTextureEnabled = true;
         StandardMaterial.RefractionTextureEnabled = true;
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "diffuseTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "ambientTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "opacityTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "reflectionTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "emissiveTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "specularTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "bumpTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "lightmapTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "refractionTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsColor3("ambient")
+        ], StandardMaterial.prototype, "ambientColor", void 0);
+        __decorate([
+            BABYLON.serializeAsColor3("diffuse")
+        ], StandardMaterial.prototype, "diffuseColor", void 0);
+        __decorate([
+            BABYLON.serializeAsColor3("specular")
+        ], StandardMaterial.prototype, "specularColor", void 0);
+        __decorate([
+            BABYLON.serializeAsColor3("emissive")
+        ], StandardMaterial.prototype, "emissiveColor", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "specularPower", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useAlphaFromDiffuseTexture", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useEmissiveAsIllumination", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "linkEmissiveWithDiffuse", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useReflectionFresnelFromSpecular", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useSpecularOverAlpha", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useReflectionOverAlpha", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "disableLighting", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "roughness", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "indexOfRefraction", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "invertRefractionY", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useLightmapAsShadowmap", void 0);
+        __decorate([
+            BABYLON.serializeAsFresnelParameters()
+        ], StandardMaterial.prototype, "diffuseFresnelParameters", void 0);
+        __decorate([
+            BABYLON.serializeAsFresnelParameters()
+        ], StandardMaterial.prototype, "opacityFresnelParameters", void 0);
+        __decorate([
+            BABYLON.serializeAsFresnelParameters()
+        ], StandardMaterial.prototype, "reflectionFresnelParameters", void 0);
+        __decorate([
+            BABYLON.serializeAsFresnelParameters()
+        ], StandardMaterial.prototype, "refractionFresnelParameters", void 0);
+        __decorate([
+            BABYLON.serializeAsFresnelParameters()
+        ], StandardMaterial.prototype, "emissiveFresnelParameters", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "useGlossinessFromSpecularMapAlpha", void 0);
         return StandardMaterial;
     })(BABYLON.Material);
     BABYLON.StandardMaterial = StandardMaterial;

+ 62 - 231
src/Materials/babylon.standardMaterial.ts

@@ -91,42 +91,97 @@
     }
 
     export class StandardMaterial extends Material {
+        @serializeAsTexture()
         public diffuseTexture: BaseTexture;
+
+        @serializeAsTexture()
         public ambientTexture: BaseTexture;
+
+        @serializeAsTexture()
         public opacityTexture: BaseTexture;
+
+        @serializeAsTexture()
         public reflectionTexture: BaseTexture;
+
+        @serializeAsTexture()
         public emissiveTexture: BaseTexture;
+
+        @serializeAsTexture()
         public specularTexture: BaseTexture;
+
+        @serializeAsTexture()
         public bumpTexture: BaseTexture;
+
+        @serializeAsTexture()
         public lightmapTexture: BaseTexture;
+
+        @serializeAsTexture()
         public refractionTexture: BaseTexture;
 
+        @serializeAsColor3("ambient")
         public ambientColor = new Color3(0, 0, 0);
+
+        @serializeAsColor3("diffuse")
         public diffuseColor = new Color3(1, 1, 1);
+
+        @serializeAsColor3("specular")
         public specularColor = new Color3(1, 1, 1);
-        public specularPower = 64;
+
+        @serializeAsColor3("emissive")
         public emissiveColor = new Color3(0, 0, 0);
+
+        @serialize()
+        public specularPower = 64;
+
+        @serialize()
         public useAlphaFromDiffuseTexture = false;
+
+        @serialize()
         public useEmissiveAsIllumination = false;
+
+        @serialize()
         public linkEmissiveWithDiffuse = false;
+
+        @serialize()
         public useReflectionFresnelFromSpecular = false;
+
+        @serialize()
         public useSpecularOverAlpha = false;
+
+        @serialize()
         public useReflectionOverAlpha = false;
+
+        @serialize()
         public disableLighting = false;
 
+        @serialize()
         public roughness = 0;
 
+        @serialize()
         public indexOfRefraction = 0.98;
+
+        @serialize()
         public invertRefractionY = true;
 
+        @serialize()
         public useLightmapAsShadowmap = false;
 
+        @serializeAsFresnelParameters()
         public diffuseFresnelParameters: FresnelParameters;
+
+        @serializeAsFresnelParameters()
         public opacityFresnelParameters: FresnelParameters;
+
+        @serializeAsFresnelParameters()
         public reflectionFresnelParameters: FresnelParameters;
+
+        @serializeAsFresnelParameters()
         public refractionFresnelParameters: FresnelParameters;
+
+        @serializeAsFresnelParameters()
         public emissiveFresnelParameters: FresnelParameters;
 
+        @serialize()
         public useGlossinessFromSpecularMapAlpha = false;
 
         private _renderTargets = new SmartArray<RenderTargetTexture>(16);
@@ -857,151 +912,18 @@
         }
 
         public clone(name: string): StandardMaterial {
-            var newStandardMaterial = new StandardMaterial(name, this.getScene());
-
-            // Base material
-            this.copyTo(newStandardMaterial);
-
-            // Standard material
-            if (this.diffuseTexture && this.diffuseTexture.clone) {
-                newStandardMaterial.diffuseTexture = this.diffuseTexture.clone();
-            }
-            if (this.ambientTexture && this.ambientTexture.clone) {
-                newStandardMaterial.ambientTexture = this.ambientTexture.clone();
-            }
-            if (this.opacityTexture && this.opacityTexture.clone) {
-                newStandardMaterial.opacityTexture = this.opacityTexture.clone();
-            }
-            if (this.reflectionTexture && this.reflectionTexture.clone) {
-                newStandardMaterial.reflectionTexture = this.reflectionTexture.clone();
-            }
-            if (this.emissiveTexture && this.emissiveTexture.clone) {
-                newStandardMaterial.emissiveTexture = this.emissiveTexture.clone();
-            }
-            if (this.specularTexture && this.specularTexture.clone) {
-                newStandardMaterial.specularTexture = this.specularTexture.clone();
-            }
-            if (this.bumpTexture && this.bumpTexture.clone) {
-                newStandardMaterial.bumpTexture = this.bumpTexture.clone();
-            }
-            if (this.lightmapTexture && this.lightmapTexture.clone) {
-                newStandardMaterial.lightmapTexture = this.lightmapTexture.clone();
-                newStandardMaterial.useLightmapAsShadowmap = this.useLightmapAsShadowmap;
-            }
-            if (this.refractionTexture && this.refractionTexture.clone) {
-                newStandardMaterial.refractionTexture = this.refractionTexture.clone();
-            }
-
-            newStandardMaterial.ambientColor = this.ambientColor.clone();
-            newStandardMaterial.diffuseColor = this.diffuseColor.clone();
-            newStandardMaterial.specularColor = this.specularColor.clone();
-            newStandardMaterial.specularPower = this.specularPower;
-            newStandardMaterial.emissiveColor = this.emissiveColor.clone();
-            newStandardMaterial.useAlphaFromDiffuseTexture = this.useAlphaFromDiffuseTexture;
-            newStandardMaterial.useEmissiveAsIllumination = this.useEmissiveAsIllumination;
-            newStandardMaterial.useGlossinessFromSpecularMapAlpha = this.useGlossinessFromSpecularMapAlpha;
-            newStandardMaterial.useReflectionFresnelFromSpecular = this.useReflectionFresnelFromSpecular;
-            newStandardMaterial.useSpecularOverAlpha = this.useSpecularOverAlpha;
-            newStandardMaterial.useReflectionOverAlpha = this.useReflectionOverAlpha;
-            newStandardMaterial.roughness = this.roughness;
-            newStandardMaterial.indexOfRefraction = this.indexOfRefraction;
-            newStandardMaterial.invertRefractionY = this.invertRefractionY;
-
-            if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.clone) {
-                newStandardMaterial.diffuseFresnelParameters = this.diffuseFresnelParameters.clone();
-            }
-            if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.clone) {
-                newStandardMaterial.emissiveFresnelParameters = this.emissiveFresnelParameters.clone();
-            }
-            if (this.reflectionFresnelParameters && this.reflectionFresnelParameters.clone) {
-                newStandardMaterial.reflectionFresnelParameters = this.reflectionFresnelParameters.clone();
-            }
-            if (this.refractionFresnelParameters && this.refractionFresnelParameters.clone) {
-                newStandardMaterial.refractionFresnelParameters = this.refractionFresnelParameters.clone();
-            }
-            if (this.opacityFresnelParameters && this.opacityFresnelParameters.clone) {
-                newStandardMaterial.opacityFresnelParameters = this.opacityFresnelParameters.clone();
-            }
-
-            return newStandardMaterial;
+            return SerializationHelper.Clone(() => new StandardMaterial(name, this.getScene()), this);
         }
 
         public serialize(): any {
-            var serializationObject = super.serialize();
-
-            serializationObject.ambient = this.ambientColor.asArray();
-            serializationObject.diffuse = this.diffuseColor.asArray();
-            serializationObject.specular = this.specularColor.asArray();
-            serializationObject.specularPower = this.specularPower;
-            serializationObject.emissive = this.emissiveColor.asArray();
-            serializationObject.useReflectionFresnelFromSpecular = this.useReflectionFresnelFromSpecular;
-            serializationObject.useEmissiveAsIllumination = this.useEmissiveAsIllumination;
-            serializationObject.indexOfRefraction = this.indexOfRefraction;
-            serializationObject.invertRefractionY = this.invertRefractionY;
-            serializationObject.useSpecularOverAlpha = this.useSpecularOverAlpha;
-            serializationObject.useReflectionOverAlpha = this.useReflectionOverAlpha;
-
-            if (this.diffuseTexture) {
-                serializationObject.diffuseTexture = this.diffuseTexture.serialize();
-            }
-
-            if (this.diffuseFresnelParameters) {
-                serializationObject.diffuseFresnelParameters = this.diffuseFresnelParameters.serialize();
-            }
-
-            if (this.ambientTexture) {
-                serializationObject.ambientTexture = this.ambientTexture.serialize();
-            }
-
-            if (this.opacityTexture) {
-                serializationObject.opacityTexture = this.opacityTexture.serialize();
-            }
-
-            if (this.opacityFresnelParameters) {
-                serializationObject.opacityFresnelParameters = this.diffuseFresnelParameters.serialize();
-            }
-
-            if (this.reflectionTexture) {
-                serializationObject.reflectionTexture = this.reflectionTexture.serialize();
-            }
-
-            if (this.reflectionFresnelParameters) {
-                serializationObject.reflectionFresnelParameters = this.reflectionFresnelParameters.serialize();
-            }
-
-            if (this.refractionFresnelParameters) {
-                serializationObject.refractionFresnelParameters = this.refractionFresnelParameters.serialize();
-            }
-
-            if (this.emissiveTexture) {
-                serializationObject.emissiveTexture = this.emissiveTexture.serialize();
-            }
-
-            if (this.lightmapTexture) {
-                serializationObject.lightmapTexture = this.lightmapTexture.serialize();
-                serializationObject.useLightmapAsShadowmap = this.useLightmapAsShadowmap;
-            }
-
-            if (this.emissiveFresnelParameters) {
-                serializationObject.emissiveFresnelParameters = this.emissiveFresnelParameters.serialize();
-            }
-
-            if (this.specularTexture) {
-                serializationObject.specularTexture = this.specularTexture.serialize();
-            }
-
-            if (this.bumpTexture) {
-                serializationObject.bumpTexture = this.bumpTexture.serialize();
-            }
-
-            if (this.refractionTexture) {
-                serializationObject.refractionTexture = this.refractionTexture.serialize();
-            }
-
-            return serializationObject;
+            return SerializationHelper.Serialize(this);
         }
 
         // Statics
+        public static Parse(source: any, scene: Scene, rootUrl: string): StandardMaterial {
+            return SerializationHelper.Parse(() => new StandardMaterial(source.name, scene), source, scene, rootUrl);
+        }
+
         // Flags used to enable or disable a type of texture for all Standard Materials
         public static DiffuseTextureEnabled = true;
         public static AmbientTextureEnabled = true;
@@ -1013,96 +935,5 @@
         public static FresnelEnabled = true;
         public static LightmapTextureEnabled = true;
         public static RefractionTextureEnabled = true;
-
-        public static Parse(source: any, scene: Scene, rootUrl: string): StandardMaterial {
-            var material = new StandardMaterial(source.name, scene);
-
-            material.ambientColor = Color3.FromArray(source.ambient);
-            material.diffuseColor = Color3.FromArray(source.diffuse);
-            material.specularColor = Color3.FromArray(source.specular);
-            material.specularPower = source.specularPower;
-            material.emissiveColor = Color3.FromArray(source.emissive);
-            material.useReflectionFresnelFromSpecular = source.useReflectionFresnelFromSpecular;
-            material.useEmissiveAsIllumination = source.useEmissiveAsIllumination;
-            material.indexOfRefraction = source.indexOfRefraction;
-            material.invertRefractionY = source.invertRefractionY;
-            material.useSpecularOverAlpha = source.useSpecularOverAlpha;
-            material.useReflectionOverAlpha = source.useReflectionOverAlpha;
-
-            material.alpha = source.alpha;
-
-            material.id = source.id;
-
-            if (source.disableDepthWrite) {
-                material.disableDepthWrite = source.disableDepthWrite;
-            }
-
-            Tags.AddTagsTo(material, source.tags);
-            material.backFaceCulling = source.backFaceCulling;
-            material.wireframe = source.wireframe;
-
-            if (source.diffuseTexture) {
-                material.diffuseTexture = Texture.Parse(source.diffuseTexture, scene, rootUrl);
-            }
-
-            if (source.diffuseFresnelParameters) {
-                material.diffuseFresnelParameters = FresnelParameters.Parse(source.diffuseFresnelParameters);
-            }
-
-            if (source.ambientTexture) {
-                material.ambientTexture = Texture.Parse(source.ambientTexture, scene, rootUrl);
-            }
-
-            if (source.opacityTexture) {
-                material.opacityTexture = Texture.Parse(source.opacityTexture, scene, rootUrl);
-            }
-
-            if (source.opacityFresnelParameters) {
-                material.opacityFresnelParameters = FresnelParameters.Parse(source.opacityFresnelParameters);
-            }
-
-            if (source.reflectionTexture) {
-                material.reflectionTexture = Texture.Parse(source.reflectionTexture, scene, rootUrl);
-            }
-
-            if (source.reflectionFresnelParameters) {
-                material.reflectionFresnelParameters = FresnelParameters.Parse(source.reflectionFresnelParameters);
-            }
-
-            if (source.refractionFresnelParameters) {
-                material.refractionFresnelParameters = FresnelParameters.Parse(source.refractionFresnelParameters);
-            }
-
-            if (source.emissiveTexture) {
-                material.emissiveTexture = Texture.Parse(source.emissiveTexture, scene, rootUrl);
-            }
-
-            if (source.lightmapTexture) {
-                material.lightmapTexture = Texture.Parse(source.lightmapTexture, scene, rootUrl);
-                material.useLightmapAsShadowmap = source.useLightmapAsShadowmap;
-            }
-
-            if (source.emissiveFresnelParameters) {
-                material.emissiveFresnelParameters = FresnelParameters.Parse(source.emissiveFresnelParameters);
-            }
-
-            if (source.specularTexture) {
-                material.specularTexture = Texture.Parse(source.specularTexture, scene, rootUrl);
-            }
-
-            if (source.bumpTexture) {
-                material.bumpTexture = Texture.Parse(source.bumpTexture, scene, rootUrl);
-            }
-
-            if (source.refractionTexture) {
-                material.refractionTexture = Texture.Parse(source.refractionTexture, scene, rootUrl);
-            }
-
-            if (source.checkReadyOnlyOnce) {
-                material.checkReadyOnlyOnce = source.checkReadyOnlyOnce;
-            }
-
-            return material;
-        }
     }
 } 

+ 116 - 0
src/Tools/babylon.decorators.js

@@ -0,0 +1,116 @@
+var BABYLON;
+(function (BABYLON) {
+    function generateSerializableMember(type, sourceName) {
+        return function (target, propertyKey) {
+            if (!target.__serializableMembers) {
+                target.__serializableMembers = {};
+            }
+            target.__serializableMembers[propertyKey] = { type: type, sourceName: sourceName };
+        };
+    }
+    function serialize(sourceName) {
+        return generateSerializableMember(0, sourceName); // value member
+    }
+    BABYLON.serialize = serialize;
+    function serializeAsTexture(sourceName) {
+        return generateSerializableMember(1, sourceName); // texture member
+    }
+    BABYLON.serializeAsTexture = serializeAsTexture;
+    function serializeAsColor3(sourceName) {
+        return generateSerializableMember(2, sourceName); // color3 member
+    }
+    BABYLON.serializeAsColor3 = serializeAsColor3;
+    function serializeAsFresnelParameters(sourceName) {
+        return generateSerializableMember(3, sourceName); // fresnel parameters member
+    }
+    BABYLON.serializeAsFresnelParameters = serializeAsFresnelParameters;
+    var SerializationHelper = (function () {
+        function SerializationHelper() {
+        }
+        SerializationHelper.Serialize = function (entity, serializationObject) {
+            if (!serializationObject) {
+                serializationObject = {};
+            }
+            // Tags
+            serializationObject.tags = BABYLON.Tags.GetTags(entity);
+            // Properties
+            for (var property in entity.__serializableMembers) {
+                var propertyDescriptor = entity.__serializableMembers[property];
+                var targetPropertyName = propertyDescriptor.sourceName || property;
+                var propertyType = propertyDescriptor.type;
+                var sourceProperty = entity[property];
+                if (sourceProperty !== undefined && sourceProperty !== null) {
+                    switch (propertyType) {
+                        case 0:
+                            serializationObject[targetPropertyName] = sourceProperty;
+                            break;
+                        case 1:
+                            serializationObject[targetPropertyName] = sourceProperty.serialize();
+                            break;
+                        case 2:
+                            serializationObject[targetPropertyName] = sourceProperty.asArray();
+                            break;
+                        case 3:
+                            serializationObject[targetPropertyName] = sourceProperty.serialize();
+                            break;
+                    }
+                }
+            }
+            return serializationObject;
+        };
+        SerializationHelper.Parse = function (creationFunction, source, scene, rootUrl) {
+            var destination = creationFunction();
+            // Tags
+            BABYLON.Tags.AddTagsTo(destination, source.tags);
+            // Properties
+            for (var property in destination.__serializableMembers) {
+                var propertyDescriptor = destination.__serializableMembers[property];
+                var sourceProperty = source[propertyDescriptor.sourceName || property];
+                var propertyType = propertyDescriptor.type;
+                if (sourceProperty !== undefined && sourceProperty !== null) {
+                    switch (propertyType) {
+                        case 0:
+                            destination[property] = sourceProperty;
+                            break;
+                        case 1:
+                            destination[property] = BABYLON.Texture.Parse(sourceProperty, scene, rootUrl);
+                            break;
+                        case 2:
+                            destination[property] = BABYLON.Color3.FromArray(sourceProperty);
+                            break;
+                        case 3:
+                            destination[property] = BABYLON.FresnelParameters.Parse(sourceProperty);
+                            break;
+                    }
+                }
+            }
+            return destination;
+        };
+        SerializationHelper.Clone = function (creationFunction, source) {
+            var destination = creationFunction();
+            // Tags
+            BABYLON.Tags.AddTagsTo(destination, source.tags);
+            // Properties
+            for (var property in destination.__serializableMembers) {
+                var propertyDescriptor = destination.__serializableMembers[property];
+                var sourceProperty = source[property];
+                var propertyType = propertyDescriptor.type;
+                if (sourceProperty !== undefined && sourceProperty !== null) {
+                    switch (propertyType) {
+                        case 0:
+                            destination[property] = sourceProperty;
+                            break;
+                        case 1: // Texture
+                        case 2: // Color3
+                        case 3:
+                            destination[property] = sourceProperty.clone();
+                            break;
+                    }
+                }
+            }
+            return destination;
+        };
+        return SerializationHelper;
+    })();
+    BABYLON.SerializationHelper = SerializationHelper;
+})(BABYLON || (BABYLON = {}));

+ 128 - 0
src/Tools/babylon.decorators.ts

@@ -0,0 +1,128 @@
+module BABYLON {
+    function generateSerializableMember(type: number, sourceName?: string) {
+        return (target: any, propertyKey: string | symbol) => {
+            if (!target.__serializableMembers) {
+                target.__serializableMembers = {};
+            }
+
+            target.__serializableMembers[propertyKey] = { type: type, sourceName: sourceName }; 
+        }
+    }
+
+    export function serialize(sourceName?: string) {
+        return generateSerializableMember(0, sourceName); // value member
+    }
+
+    export function serializeAsTexture(sourceName?: string) {
+        return generateSerializableMember(1, sourceName);// texture member
+    }
+
+    export function serializeAsColor3(sourceName?: string) {
+        return generateSerializableMember(2, sourceName); // color3 member
+    }
+
+    export function serializeAsFresnelParameters(sourceName?: string) {
+        return generateSerializableMember(3, sourceName); // fresnel parameters member
+    }
+
+    export class SerializationHelper {
+
+        public static Serialize<T>(entity: T, serializationObject?: any): any {
+            if (!serializationObject) {
+                serializationObject = {};
+            }
+
+            // Tags
+            serializationObject.tags = Tags.GetTags(entity);
+
+            // Properties
+            for (var property in (<any>entity).__serializableMembers) {
+                var propertyDescriptor = (<any>entity).__serializableMembers[property];
+                var targetPropertyName = propertyDescriptor.sourceName || property;
+                var propertyType = propertyDescriptor.type;
+                var sourceProperty = entity[property];
+
+                if (sourceProperty !== undefined && sourceProperty !== null) {
+                    switch (propertyType) {
+                        case 0:     // Value
+                            serializationObject[targetPropertyName] = sourceProperty;
+                            break;
+                        case 1:     // Texture
+                            serializationObject[targetPropertyName] = sourceProperty.serialize();
+                            break;
+                        case 2:     // Color3
+                            serializationObject[targetPropertyName] = sourceProperty.asArray();
+                            break;
+                        case 3:     // FresnelParameters
+                            serializationObject[targetPropertyName] = sourceProperty.serialize();
+                            break;
+                    }
+                }
+            }
+
+            return serializationObject;
+        }
+
+        public static Parse<T>(creationFunction: () => T, source: any, scene: Scene, rootUrl: string): T {
+            var destination = creationFunction();
+
+            // Tags
+            Tags.AddTagsTo(destination, source.tags);
+
+            // Properties
+            for (var property in (<any>destination).__serializableMembers) {
+                var propertyDescriptor = (<any>destination).__serializableMembers[property];
+                var sourceProperty = source[propertyDescriptor.sourceName || property];
+                var propertyType = propertyDescriptor.type;
+
+                if (sourceProperty !== undefined && sourceProperty !== null) {
+                    switch (propertyType) {
+                        case 0:     // Value
+                            destination[property] = sourceProperty;
+                            break;
+                        case 1:     // Texture
+                            destination[property] = Texture.Parse(sourceProperty, scene, rootUrl);
+                            break;
+                        case 2:     // Color3
+                            destination[property] = Color3.FromArray(sourceProperty);
+                            break;
+                        case 3:     // FresnelParameters
+                            destination[property] = FresnelParameters.Parse(sourceProperty);
+                            break;
+                    }
+                }
+            }
+
+            return destination;
+        }
+
+        public static Clone<T>(creationFunction: () => T, source: T): T {
+            var destination = creationFunction();
+
+            // Tags
+            Tags.AddTagsTo(destination, (<any>source).tags);
+
+            // Properties
+            for (var property in (<any>destination).__serializableMembers) {
+                var propertyDescriptor = (<any>destination).__serializableMembers[property];
+                var sourceProperty = source[property];
+                var propertyType = propertyDescriptor.type;
+
+                if (sourceProperty !== undefined && sourceProperty !== null) {
+                    switch (propertyType) {
+                        case 0:     // Value
+                            destination[property] = sourceProperty;
+                            break;
+                        case 1:     // Texture
+                        case 2:     // Color3
+                        case 3:     // FresnelParameters
+                            destination[property] = sourceProperty.clone();
+                            break;
+                    }
+                }
+            }
+
+            return destination;
+        }
+    }
+}