Przeglądaj źródła

Merge remote-tracking branch 'upstream/master'

Raanan Weber 10 lat temu
rodzic
commit
4bc074f58f
50 zmienionych plików z 3891 dodań i 2609 usunięć
  1. 22 2
      Babylon/Loading/Plugins/babylon.babylonFileLoader.js
  2. 26 6
      Babylon/Loading/Plugins/babylon.babylonFileLoader.ts
  3. 4 0
      Babylon/Materials/babylon.standardMaterial.js
  4. 4 0
      Babylon/Materials/babylon.standardMaterial.ts
  5. 124 0
      Babylon/Materials/textures/Procedurals/babylon.customProceduralTexture.js
  6. 122 0
      Babylon/Materials/textures/Procedurals/babylon.customProceduralTexture.ts
  7. 4 0
      Babylon/Materials/textures/Procedurals/babylon.proceduralTexture.js
  8. 5 0
      Babylon/Materials/textures/Procedurals/babylon.proceduralTexture.ts
  9. 101 0
      Babylon/Materials/textures/Procedurals/babylon.standardProceduralTexture.js
  10. 85 1
      Babylon/Materials/textures/Procedurals/babylon.standardProceduralTexture.ts
  11. 8 0
      Babylon/Materials/textures/babylon.texture.js
  12. 5 0
      Babylon/Materials/textures/babylon.texture.ts
  13. 12 3
      Babylon/Math/babylon.math.js
  14. 2354 2346
      Babylon/Math/babylon.math.ts
  15. 17 0
      Babylon/Mesh/babylon.abstractMesh.js
  16. 17 0
      Babylon/Mesh/babylon.abstractMesh.ts
  17. 10 10
      Babylon/Mesh/babylon.csg.js
  18. 12 14
      Babylon/Mesh/babylon.csg.ts
  19. 3 3
      Babylon/Mesh/babylon.geometry.js
  20. 3 3
      Babylon/Mesh/babylon.geometry.ts
  21. 2 2
      Babylon/Mesh/babylon.mesh.js
  22. 2 2
      Babylon/Mesh/babylon.mesh.ts
  23. 7 2
      Babylon/Mesh/babylon.vertexBuffer.js
  24. 8 2
      Babylon/Mesh/babylon.vertexBuffer.ts
  25. 2 0
      Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPass.js
  26. 2 1
      Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPass.ts
  27. 1 1
      Babylon/Rendering/babylon.renderingGroup.js
  28. 1 1
      Babylon/Rendering/babylon.renderingGroup.ts
  29. 82 0
      Babylon/Shaders/brick.fragment.fx
  30. 6 2
      Babylon/Shaders/default.fragment.fx
  31. 2 2
      Babylon/Shaders/default.vertex.fx
  32. 8 0
      Babylon/Shaders/empty.fragment.fx
  33. 11 24
      Babylon/Shaders/grass.fragment.fx
  34. 6 2
      Babylon/Shaders/legacydefault.fragment.fx
  35. 2 2
      Babylon/Shaders/legacydefault.vertex.fx
  36. 104 0
      Babylon/Shaders/marble.fragment.fx
  37. 98 92
      Babylon/Shaders/rock.fragment.fx
  38. 28 3
      Babylon/babylon.engine.js
  39. 30 3
      Babylon/babylon.engine.ts
  40. 1 0
      Babylon/babylon.mixins.ts
  41. 3 0
      Exporters/3ds Max/BabylonExport.Entities/BabylonMesh.cs
  42. BIN
      Exporters/3ds Max/Max2Babylon-0.8.2.zip
  43. BIN
      Exporters/3ds Max/Max2Babylon-0.8.3.zip
  44. 15 9
      Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Material.cs
  45. 22 5
      Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs
  46. 6 0
      Exporters/3ds Max/Max2Babylon/Exporter/GlobalVertex.cs
  47. 47 16
      Exporters/Blender/io_export_babylon.py
  48. 389 32
      babylon.2.0-alpha.debug.js
  49. 14 14
      babylon.2.0-alpha.js
  50. 54 4
      babylon.2.0.d.ts

+ 22 - 2
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -1,6 +1,24 @@
 var BABYLON;
 (function (BABYLON) {
     (function (Internals) {
+        var checkColors4 = function (colors, count) {
+            // Check if color3 was used
+            if (colors.length === count * 3) {
+                var colors4 = [];
+                for (var index = 0; index < colors.length; index += 3) {
+                    var newIndex = (index / 3) * 4;
+                    colors4[newIndex] = colors[index];
+                    colors4[newIndex + 1] = colors[index + 1];
+                    colors4[newIndex + 2] = colors[index + 2];
+                    colors4[newIndex + 3] = 1.0;
+                }
+
+                return colors4;
+            }
+
+            return colors;
+        };
+
         var loadCubeTexture = function (rootUrl, parsedTexture, scene) {
             var texture = new BABYLON.CubeTexture(rootUrl + parsedTexture.name, scene);
 
@@ -650,6 +668,8 @@
             }
 
             // Geometry
+            mesh.hasVertexAlpha = parsedMesh.hasVertexAlpha;
+
             if (parsedMesh.delayLoadingFile) {
                 mesh.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
                 mesh.delayLoadingFile = rootUrl + parsedMesh.delayLoadingFile;
@@ -810,7 +830,7 @@
             // colors
             var colors = parsedVertexData.colors;
             if (colors) {
-                vertexData.set(colors, BABYLON.VertexBuffer.ColorKind);
+                vertexData.set(checkColors4(colors, positions.length / 3), BABYLON.VertexBuffer.ColorKind);
             }
 
             // matricesIndices
@@ -914,7 +934,7 @@
                 }
 
                 if (parsedGeometry.colors) {
-                    mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, parsedGeometry.colors, false);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, checkColors4(parsedGeometry.colors, parsedGeometry.positions.length / 3), false);
                 }
 
                 if (parsedGeometry.matricesIndices) {

+ 26 - 6
Babylon/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -1,5 +1,23 @@
 module BABYLON.Internals {
 
+    var checkColors4 = (colors: number[], count:number): number[] => {
+        // Check if color3 was used
+        if (colors.length === count * 3) {
+            var colors4 = [];
+            for (var index = 0; index < colors.length; index += 3) {
+                var newIndex = (index / 3) * 4;
+                colors4[newIndex] = colors[index];
+                colors4[newIndex + 1] = colors[index + 1];
+                colors4[newIndex + 2] = colors[index + 2];
+                colors4[newIndex + 3] = 1.0;
+            }
+
+            return colors4;
+        } 
+
+        return colors
+    }
+
     var loadCubeTexture = (rootUrl, parsedTexture, scene) => {
         var texture = new BABYLON.CubeTexture(rootUrl + parsedTexture.name, scene);
 
@@ -333,8 +351,8 @@
         if (parsedLight.excludedMeshesIds) {
             light._excludedMeshesIds = parsedLight.excludedMeshesIds;
         }
-		
-		// Parent
+
+        // Parent
         if (parsedLight.parentId) {
             light._waitingParentId = parsedLight.parentId;
         }
@@ -659,6 +677,8 @@
         }
 
         // Geometry
+        mesh.hasVertexAlpha = parsedMesh.hasVertexAlpha;
+
         if (parsedMesh.delayLoadingFile) {
             mesh.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
             mesh.delayLoadingFile = rootUrl + parsedMesh.delayLoadingFile;
@@ -821,7 +841,7 @@
         // colors
         var colors = parsedVertexData.colors;
         if (colors) {
-            vertexData.set(colors, BABYLON.VertexBuffer.ColorKind);
+            vertexData.set(checkColors4(colors, positions.length / 3), BABYLON.VertexBuffer.ColorKind);
         }
 
         // matricesIndices
@@ -926,7 +946,7 @@
             }
 
             if (parsedGeometry.colors) {
-                mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, parsedGeometry.colors, false);
+                mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, checkColors4(parsedGeometry.colors, parsedGeometry.positions.length / 3), false);
             }
 
             if (parsedGeometry.matricesIndices) {
@@ -1217,8 +1237,8 @@
                     camera._waitingParentId = undefined;
                 }
             }
-			
-			for (index = 0; index < scene.lights.length; index++) {
+
+            for (index = 0; index < scene.lights.length; index++) {
                 var light = scene.lights[index];
                 if (light._waitingParentId) {
                     light.parent = scene.getLastEntryByID(light._waitingParentId);

+ 4 - 0
Babylon/Materials/babylon.standardMaterial.js

@@ -321,6 +321,10 @@ var BABYLON;
                 if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                     defines.push("#define VERTEXCOLOR");
+
+                    if (mesh.hasVertexAlpha) {
+                        defines.push("#define VERTEXALPHA");
+                    }
                 }
                 if (mesh.skeleton && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
                     attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);

+ 4 - 0
Babylon/Materials/babylon.standardMaterial.ts

@@ -330,6 +330,10 @@
                 if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                     defines.push("#define VERTEXCOLOR");
+
+                    if (mesh.hasVertexAlpha) {
+                        defines.push("#define VERTEXALPHA");
+                    }
                 }
                 if (mesh.skeleton && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
                     attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);

+ 124 - 0
Babylon/Materials/textures/Procedurals/babylon.customProceduralTexture.js

@@ -0,0 +1,124 @@
+var __extends = this.__extends || function (d, b) {
+    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+    function __() { this.constructor = d; }
+    __.prototype = b.prototype;
+    d.prototype = new __();
+};
+var BABYLON;
+(function (BABYLON) {
+    var CustomProceduralTexture = (function (_super) {
+        __extends(CustomProceduralTexture, _super);
+        function CustomProceduralTexture(name, texturePath, size, scene, fallbackTexture, generateMipMaps) {
+            _super.call(this, name, size, "empty", scene, fallbackTexture, generateMipMaps);
+            this._generateTime = true;
+            this._time = 0;
+            this._shaderLoaded = false;
+
+            this._texturePath = texturePath;
+
+            //readJson
+            this.loadJson(texturePath);
+
+            // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
+            this.refreshRate = 0;
+        }
+        CustomProceduralTexture.prototype.loadJson = function (jsonUrl) {
+            var _this = this;
+            function noConfigFile() {
+                BABYLON.Tools.Log("No config file found in " + jsonUrl);
+            }
+
+            var that = this;
+            var configFileUrl = jsonUrl + "/config.json";
+
+            var xhr = new XMLHttpRequest();
+
+            xhr.open("GET", configFileUrl, true);
+            xhr.addEventListener("load", function () {
+                if (xhr.status === 200 || BABYLON.Tools.ValidateXHRData(xhr, 1)) {
+                    try  {
+                        that._config = JSON.parse(xhr.response);
+                        that.updateShaderUniforms();
+                        that.setFragment(jsonUrl + "/custom");
+                        that._generateTime = that._config.generateTime;
+                        if (that._generateTime)
+                            _this.refreshRate = 1;
+                        that._shaderLoaded = true;
+                        that.render();
+                    } catch (ex) {
+                        noConfigFile();
+                    }
+                } else {
+                    noConfigFile();
+                }
+            }, false);
+
+            xhr.addEventListener("error", function (event) {
+                noConfigFile();
+            }, false);
+
+            try  {
+                xhr.send();
+            } catch (ex) {
+                BABYLON.Tools.Error("Error on XHR send request.");
+            }
+        };
+
+        CustomProceduralTexture.prototype.render = function (useCameraPostProcess) {
+            //if config and shader not loaded, do not render
+            if (!this._shaderLoaded)
+                return;
+
+            if (this._generateTime) {
+                this._time += this.getScene().getAnimationRatio() * 0.03;
+                this.updateShaderUniforms();
+            }
+
+            _super.prototype.render.call(this, useCameraPostProcess);
+        };
+
+        CustomProceduralTexture.prototype.updateShaderUniforms = function () {
+            for (var i = 0; i < this._config.texture2Ds.length; i++) {
+                this.setTexture(this._config.texture2Ds[i].textureName, new BABYLON.Texture(this._texturePath + "/" + this._config.texture2Ds[i].textureRelativeUrl, this.getScene()));
+            }
+
+            for (var j = 0; j < this._config.uniforms.length; j++) {
+                var uniform = this._config.uniforms[j];
+
+                switch (uniform.type) {
+                    case "float":
+                        this.setFloat(uniform.name, uniform.value);
+                        break;
+                    case "color3":
+                        this.setColor3(uniform.name, new BABYLON.Color3(uniform.r, uniform.g, uniform.b));
+                        break;
+                    case "color4":
+                        this.setColor4(uniform.name, new BABYLON.Color4(uniform.r, uniform.g, uniform.b, uniform.a));
+                        break;
+                    case "vector2":
+                        this.setVector2(uniform.name, new BABYLON.Vector2(uniform.x, uniform.y));
+                        break;
+                    case "vector3":
+                        this.setVector3(uniform.name, new BABYLON.Vector3(uniform.x, uniform.y, uniform.z));
+                        break;
+                }
+            }
+        };
+
+        Object.defineProperty(CustomProceduralTexture.prototype, "generateTime", {
+            get: function () {
+                return this.generateTime;
+            },
+            set: function (value) {
+                this.generateTime = value;
+                this.updateShaderUniforms();
+            },
+            enumerable: true,
+            configurable: true
+        });
+
+        return CustomProceduralTexture;
+    })(BABYLON.ProceduralTexture);
+    BABYLON.CustomProceduralTexture = CustomProceduralTexture;
+})(BABYLON || (BABYLON = {}));
+//# sourceMappingURL=babylon.customProceduralTexture.js.map

+ 122 - 0
Babylon/Materials/textures/Procedurals/babylon.customProceduralTexture.ts

@@ -0,0 +1,122 @@
+module BABYLON {
+    export class CustomProceduralTexture extends ProceduralTexture {
+
+        private _generateTime: boolean = true;
+        private _time: number = 0;
+        private _shaderLoaded: boolean = false;
+        private _config: any;
+        private _texturePath: string;
+
+        constructor(name: string, texturePath: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
+            super(name, size, "empty", scene, fallbackTexture, generateMipMaps);
+
+            this._texturePath = texturePath;
+
+            //readJson
+            this.loadJson(texturePath);
+
+            // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
+            this.refreshRate = 0;
+
+        }
+
+        private loadJson(jsonUrl: string) {
+
+            function noConfigFile() {
+                BABYLON.Tools.Log("No config file found in " + jsonUrl);
+            }
+
+            var that = this;
+            var configFileUrl = jsonUrl + "/config.json";
+
+            var xhr: XMLHttpRequest = new XMLHttpRequest();
+
+            xhr.open("GET", configFileUrl, true);
+            xhr.addEventListener("load", () => {
+                if (xhr.status === 200 || BABYLON.Tools.ValidateXHRData(xhr, 1)) {
+                    try {
+                        that._config = JSON.parse(xhr.response);
+                        that.updateShaderUniforms();
+                        that.setFragment(jsonUrl + "/custom");
+                        that._generateTime = that._config.generateTime;
+                        if (that._generateTime)
+                            this.refreshRate = 1;
+                        that._shaderLoaded = true;
+                        that.render();
+                    }
+                    catch (ex) {
+                        noConfigFile();
+                    }
+                }
+                else {
+                    noConfigFile();
+                }
+            }, false);
+
+            xhr.addEventListener("error", event => {
+                noConfigFile();
+            }, false);
+
+            try {
+                xhr.send();
+            }
+            catch (ex) {
+                BABYLON.Tools.Error("Error on XHR send request.");
+            }
+        }
+
+        public render(useCameraPostProcess?: boolean) {
+
+            //if config and shader not loaded, do not render
+            if (!this._shaderLoaded)
+                return;
+
+
+            if (this._generateTime) {
+                this._time += this.getScene().getAnimationRatio() * 0.03;
+                this.updateShaderUniforms();
+            }
+
+            super.render(useCameraPostProcess);
+        }
+
+        public updateShaderUniforms() {
+
+            for (var i = 0; i < this._config.texture2Ds.length; i++) {
+                this.setTexture(this._config.texture2Ds[i].textureName, new BABYLON.Texture(this._texturePath + "/" + this._config.texture2Ds[i].textureRelativeUrl, this.getScene()));
+            }
+
+            for (var j = 0; j < this._config.uniforms.length; j++) {
+                var uniform = this._config.uniforms[j];
+
+                switch (uniform.type) {
+                    case "float":
+                        this.setFloat(uniform.name, uniform.value);
+                        break;
+                    case "color3":
+                        this.setColor3(uniform.name, new BABYLON.Color3(uniform.r, uniform.g, uniform.b));
+                        break;
+                    case "color4":
+                        this.setColor4(uniform.name, new BABYLON.Color4(uniform.r, uniform.g, uniform.b, uniform.a));
+                        break;
+                    case "vector2":
+                        this.setVector2(uniform.name, new BABYLON.Vector2(uniform.x, uniform.y));
+                        break;
+                    case "vector3":
+                        this.setVector3(uniform.name, new BABYLON.Vector3(uniform.x, uniform.y, uniform.z));
+                        break;
+                }
+            }
+        }
+
+        public get generateTime(): boolean {
+            return this.generateTime;
+        }
+
+        public set generateTime(value: boolean) {
+            this.generateTime = value;
+            this.updateShaderUniforms();
+        }
+
+    }
+}

+ 4 - 0
Babylon/Materials/textures/Procedurals/babylon.proceduralTexture.js

@@ -77,6 +77,10 @@ var BABYLON;
             this._currentRefreshId = -1;
         };
 
+        ProceduralTexture.prototype.setFragment = function (fragment) {
+            this._fragment = fragment;
+        };
+
         Object.defineProperty(ProceduralTexture.prototype, "refreshRate", {
             get: function () {
                 return this._refreshRate;

+ 5 - 0
Babylon/Materials/textures/Procedurals/babylon.proceduralTexture.ts

@@ -66,6 +66,7 @@
             this._indexBuffer = scene.getEngine().createIndexBuffer(indices);
         }
 
+      
         public isReady(): boolean {
             var engine = this.getScene().getEngine();
 
@@ -87,6 +88,10 @@
             this._currentRefreshId = -1;
         }
 
+        public setFragment(fragment: any) {
+            this._fragment = fragment;
+        }
+
         public get refreshRate(): number {
             return this._refreshRate;
         }

+ 101 - 0
Babylon/Materials/textures/Procedurals/babylon.standardProceduralTexture.js

@@ -230,6 +230,7 @@ var BABYLON;
 
             // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
             this.refreshRate = 0;
+            // https://www.shadertoy.com/view/XsjSRt
         }
         CloudProceduralTexture.prototype.updateShaderUniforms = function () {
             this.setColor3("skyColor", this._skyColor);
@@ -300,5 +301,105 @@ var BABYLON;
         return RoadProceduralTexture;
     })(BABYLON.ProceduralTexture);
     BABYLON.RoadProceduralTexture = RoadProceduralTexture;
+
+    var BrickProceduralTexture = (function (_super) {
+        __extends(BrickProceduralTexture, _super);
+        function BrickProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
+            _super.call(this, name, size, "brick", scene, fallbackTexture, generateMipMaps);
+            this._numberOfBricksHeight = 15;
+            this._numberOfBricksWidth = 5;
+
+            this.updateShaderUniforms();
+
+            // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
+            this.refreshRate = 0;
+        }
+        BrickProceduralTexture.prototype.updateShaderUniforms = function () {
+            this.setFloat("numberOfBricksHeight", this._numberOfBricksHeight);
+            this.setFloat("numberOfBricksWidth", this._numberOfBricksWidth);
+        };
+
+        Object.defineProperty(BrickProceduralTexture.prototype, "numberOfBricksHeight", {
+            get: function () {
+                return this._numberOfBricksHeight;
+            },
+            enumerable: true,
+            configurable: true
+        });
+
+        Object.defineProperty(BrickProceduralTexture.prototype, "cloudColor", {
+            set: function (value) {
+                this._numberOfBricksHeight = value;
+                this.updateShaderUniforms();
+            },
+            enumerable: true,
+            configurable: true
+        });
+
+        Object.defineProperty(BrickProceduralTexture.prototype, "numberOfBricksWidth", {
+            get: function () {
+                return this._numberOfBricksWidth;
+            },
+            set: function (value) {
+                this._numberOfBricksHeight = value;
+                this.updateShaderUniforms();
+            },
+            enumerable: true,
+            configurable: true
+        });
+
+        return BrickProceduralTexture;
+    })(BABYLON.ProceduralTexture);
+    BABYLON.BrickProceduralTexture = BrickProceduralTexture;
+
+    var MarbleProceduralTexture = (function (_super) {
+        __extends(MarbleProceduralTexture, _super);
+        function MarbleProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
+            _super.call(this, name, size, "marble", scene, fallbackTexture, generateMipMaps);
+            this._numberOfBricksHeight = 3;
+            this._numberOfBricksWidth = 3;
+
+            this.updateShaderUniforms();
+
+            // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
+            this.refreshRate = 0;
+        }
+        MarbleProceduralTexture.prototype.updateShaderUniforms = function () {
+            this.setFloat("numberOfBricksHeight", this._numberOfBricksHeight);
+            this.setFloat("numberOfBricksWidth", this._numberOfBricksWidth);
+        };
+
+        Object.defineProperty(MarbleProceduralTexture.prototype, "numberOfBricksHeight", {
+            get: function () {
+                return this._numberOfBricksHeight;
+            },
+            enumerable: true,
+            configurable: true
+        });
+
+        Object.defineProperty(MarbleProceduralTexture.prototype, "cloudColor", {
+            set: function (value) {
+                this._numberOfBricksHeight = value;
+                this.updateShaderUniforms();
+            },
+            enumerable: true,
+            configurable: true
+        });
+
+        Object.defineProperty(MarbleProceduralTexture.prototype, "numberOfBricksWidth", {
+            get: function () {
+                return this._numberOfBricksWidth;
+            },
+            set: function (value) {
+                this._numberOfBricksHeight = value;
+                this.updateShaderUniforms();
+            },
+            enumerable: true,
+            configurable: true
+        });
+
+        return MarbleProceduralTexture;
+    })(BABYLON.ProceduralTexture);
+    BABYLON.MarbleProceduralTexture = MarbleProceduralTexture;
 })(BABYLON || (BABYLON = {}));
 //# sourceMappingURL=babylon.standardProceduralTexture.js.map

+ 85 - 1
Babylon/Materials/textures/Procedurals/babylon.standardProceduralTexture.ts

@@ -190,7 +190,7 @@
 
             // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
             this.refreshRate = 0;
-
+            // https://www.shadertoy.com/view/XsjSRt
         }
 
         public updateShaderUniforms() {
@@ -252,4 +252,88 @@
         }
     }
 
+
+    export class BrickProceduralTexture extends ProceduralTexture {
+
+        private _numberOfBricksHeight: number = 15;
+        private _numberOfBricksWidth: number = 5;
+
+        constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
+            super(name, size, "brick", scene, fallbackTexture, generateMipMaps);
+
+            this.updateShaderUniforms();
+
+            // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
+            this.refreshRate = 0;
+
+        }
+
+        public updateShaderUniforms() {
+
+            this.setFloat("numberOfBricksHeight", this._numberOfBricksHeight);
+            this.setFloat("numberOfBricksWidth", this._numberOfBricksWidth);
+        }
+
+
+        public get numberOfBricksHeight(): number {
+            return this._numberOfBricksHeight;
+        }
+
+        public set cloudColor(value: number) {
+            this._numberOfBricksHeight = value;
+            this.updateShaderUniforms();
+        }
+
+        public get numberOfBricksWidth(): number {
+            return this._numberOfBricksWidth;
+        }
+
+        public set numberOfBricksWidth(value: number) {
+            this._numberOfBricksHeight = value;
+            this.updateShaderUniforms();
+        }
+    }
+
+
+    export class MarbleProceduralTexture extends ProceduralTexture {
+
+        private _numberOfBricksHeight: number = 3;
+        private _numberOfBricksWidth: number = 3;
+
+        constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
+            super(name, size, "marble", scene, fallbackTexture, generateMipMaps);
+
+            this.updateShaderUniforms();
+
+            // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
+            this.refreshRate = 0;
+
+        }
+
+        public updateShaderUniforms() {
+
+            this.setFloat("numberOfBricksHeight", this._numberOfBricksHeight);
+            this.setFloat("numberOfBricksWidth", this._numberOfBricksWidth);
+        }
+
+        public get numberOfBricksHeight(): number {
+            return this._numberOfBricksHeight;
+        }
+
+        public set cloudColor(value: number) {
+            this._numberOfBricksHeight = value;
+            this.updateShaderUniforms();
+        }
+
+        public get numberOfBricksWidth(): number {
+            return this._numberOfBricksWidth;
+        }
+
+        public set numberOfBricksWidth(value: number) {
+            this._numberOfBricksHeight = value;
+            this.updateShaderUniforms();
+        }
+
+    }
+
 }

+ 8 - 0
Babylon/Materials/textures/babylon.texture.js

@@ -190,6 +190,14 @@ var BABYLON;
 
             return newTexture;
         };
+
+        // Statics
+        Texture.CreateFromBase64String = function (data, name, scene, noMipmap, invertY, samplingMode, onLoad, onError) {
+            if (typeof samplingMode === "undefined") { samplingMode = Texture.TRILINEAR_SAMPLINGMODE; }
+            if (typeof onLoad === "undefined") { onLoad = null; }
+            if (typeof onError === "undefined") { onError = null; }
+            return new Texture("data:" + name, scene, noMipmap, invertY, samplingMode, onLoad, onError, data);
+        };
         Texture.NEAREST_SAMPLINGMODE = 1;
         Texture.BILINEAR_SAMPLINGMODE = 2;
         Texture.TRILINEAR_SAMPLINGMODE = 3;

+ 5 - 0
Babylon/Materials/textures/babylon.texture.ts

@@ -224,5 +224,10 @@
 
             return newTexture;
         }
+
+        // Statics
+        public static CreateFromBase64String(data: string, name: string, scene: Scene, noMipmap?: boolean, invertY?: boolean, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE, onLoad: () => void = null, onError: () => void = null): Texture {
+            return new Texture("data:" + name, scene, noMipmap, invertY, samplingMode, onLoad, onError, data);
+        }
     }
 } 

+ 12 - 3
Babylon/Math/babylon.math.js

@@ -575,7 +575,7 @@
         };
 
         Vector3.prototype.equalsWithEpsilon = function (otherVector) {
-            return Math.abs(this.x - otherVector.x) < Engine.Epsilon && Math.abs(this.y - otherVector.y) < Engine.Epsilon && Math.abs(this.z - otherVector.z) < Engine.Epsilon;
+            return Math.abs(this.x - otherVector.x) < BABYLON.Engine.Epsilon && Math.abs(this.y - otherVector.y) < BABYLON.Engine.Epsilon && Math.abs(this.z - otherVector.z) < BABYLON.Engine.Epsilon;
         };
 
         Vector3.prototype.equalsToFloats = function (x, y, z) {
@@ -1005,7 +1005,7 @@
         };
 
         Vector4.prototype.equalsWithEpsilon = function (otherVector) {
-            return Math.abs(this.x - otherVector.x) < Engine.Epsilon && Math.abs(this.y - otherVector.y) < Engine.Epsilon && Math.abs(this.z - otherVector.z) < Engine.Epsilon && Math.abs(this.w - otherVector.w) < Engine.Epsilon;
+            return Math.abs(this.x - otherVector.x) < BABYLON.Engine.Epsilon && Math.abs(this.y - otherVector.y) < BABYLON.Engine.Epsilon && Math.abs(this.z - otherVector.z) < BABYLON.Engine.Epsilon && Math.abs(this.w - otherVector.w) < BABYLON.Engine.Epsilon;
         };
 
         Vector4.prototype.equalsToFloats = function (x, y, z, w) {
@@ -1743,6 +1743,14 @@
             return result;
         };
 
+        Matrix.Invert = function (source) {
+            var result = new Matrix();
+
+            source.invertToRef(result);
+
+            return result;
+        };
+
         Matrix.RotationXToRef = function (angle, result) {
             var s = Math.sin(angle);
             var c = Math.cos(angle);
@@ -2430,7 +2438,7 @@
                 return null;
             }
 
-            return new IntersectionInfo(bu, bv, distance);
+            return new BABYLON.IntersectionInfo(bu, bv, distance);
         };
 
         // Statics
@@ -2487,3 +2495,4 @@
     BABYLON.Axis = Axis;
     ;
 })(BABYLON || (BABYLON = {}));
+//# sourceMappingURL=babylon.math.js.map

Plik diff jest za duży
+ 2354 - 2346
Babylon/Math/babylon.math.ts


+ 17 - 0
Babylon/Mesh/babylon.abstractMesh.js

@@ -29,6 +29,7 @@ var BABYLON;
             this.renderOutline = false;
             this.outlineColor = BABYLON.Color3.Red();
             this.outlineWidth = 0.02;
+            this.hasVertexAlpha = false;
             this.useOctreeForRenderingSelection = true;
             this.useOctreeForPicking = true;
             this.useOctreeForCollisions = true;
@@ -547,6 +548,22 @@ var BABYLON;
             return this._physicRestitution;
         };
 
+        AbstractMesh.prototype.getPositionInCameraSpace = function (camera) {
+            if (!camera) {
+                camera = this.getScene().activeCamera;
+            }
+
+            return BABYLON.Vector3.TransformCoordinates(this.absolutePosition, camera.getViewMatrix());
+        };
+
+        AbstractMesh.prototype.getDistanceToCamera = function (camera) {
+            if (!camera) {
+                camera = this.getScene().activeCamera;
+            }
+
+            return this.absolutePosition.subtract(camera.position);
+        };
+
         AbstractMesh.prototype.applyImpulse = function (force, contactPoint) {
             if (!this._physicImpostor) {
                 return;

+ 17 - 0
Babylon/Mesh/babylon.abstractMesh.ts

@@ -50,6 +50,7 @@
         public renderOutline = false;
         public outlineColor = BABYLON.Color3.Red();
         public outlineWidth = 0.02;
+        public hasVertexAlpha = false;
 
         public useOctreeForRenderingSelection = true;
         public useOctreeForPicking = true;
@@ -540,6 +541,22 @@
             return this._physicRestitution;
         }
 
+        public getPositionInCameraSpace(camera?: Camera): Vector3 {
+            if (!camera) {
+                camera = this.getScene().activeCamera;
+            }
+
+            return Vector3.TransformCoordinates(this.absolutePosition, camera.getViewMatrix());
+        }
+
+        public getDistanceToCamera(camera?: Camera): Vector3 {
+            if (!camera) {
+                camera = this.getScene().activeCamera;
+            }
+
+            return this.absolutePosition.subtract(camera.position);
+        }
+
         public applyImpulse(force: Vector3, contactPoint: Vector3): void {
             if (!this._physicImpostor) {
                 return;

+ 10 - 10
Babylon/Mesh/babylon.csg.js

@@ -303,11 +303,11 @@
                 for (var i = subMeshes[sm].indexStart, il = subMeshes[sm].indexCount + subMeshes[sm].indexStart; i < il; i += 3) {
                     vertices = [];
                     for (var j = 0; j < 3; j++) {
-                        normal = new BABYLON.Vector3(normals[indices[i + j] * 3], normals[indices[i + j] * 3 + 1], normals[indices[i + j] * 3 + 2]);
+                        var sourceNormal = new BABYLON.Vector3(normals[indices[i + j] * 3], normals[indices[i + j] * 3 + 1], normals[indices[i + j] * 3 + 2]);
                         uv = new BABYLON.Vector2(uvs[indices[i + j] * 2], uvs[indices[i + j] * 2 + 1]);
-                        position = new BABYLON.Vector3(positions[indices[i + j] * 3], positions[indices[i + j] * 3 + 1], positions[indices[i + j] * 3 + 2]);
-                        BABYLON.Vector3.TransformCoordinatesToRef(position, matrix, position);
-                        BABYLON.Vector3.TransformNormalToRef(normal, matrix, normal);
+                        var sourcePosition = new BABYLON.Vector3(positions[indices[i + j] * 3], positions[indices[i + j] * 3 + 1], positions[indices[i + j] * 3 + 2]);
+                        position = BABYLON.Vector3.TransformCoordinates(sourcePosition, matrix);
+                        normal = BABYLON.Vector3.TransformNormal(sourceNormal, matrix);
 
                         vertex = new Vertex(position, normal, uv);
                         vertices.push(vertex);
@@ -506,17 +506,17 @@
                         vertex.copyFrom(polygon.vertices[polygonIndices[k]].pos);
                         normal.copyFrom(polygon.vertices[polygonIndices[k]].normal);
                         uv.copyFrom(polygon.vertices[polygonIndices[k]].uv);
-                        BABYLON.Vector3.TransformCoordinatesToRef(vertex, matrix, vertex);
-                        BABYLON.Vector3.TransformNormalToRef(normal, matrix, normal);
+                        var localVertex = BABYLON.Vector3.TransformCoordinates(vertex, matrix);
+                        var localNormal = BABYLON.Vector3.TransformNormal(normal, matrix);
 
-                        vertex_idx = vertice_dict[vertex.x + ',' + vertex.y + ',' + vertex.z];
+                        vertex_idx = vertice_dict[localVertex.x + ',' + localVertex.y + ',' + localVertex.z];
 
                         // Check if 2 points can be merged
-                        if (!(typeof vertex_idx !== 'undefined' && normals[vertex_idx * 3] === normal.x && normals[vertex_idx * 3 + 1] === normal.y && normals[vertex_idx * 3 + 2] === normal.z && uvs[vertex_idx * 2] === uv.x && uvs[vertex_idx * 2 + 1] === uv.y)) {
-                            vertices.push(vertex.x, vertex.y, vertex.z);
+                        if (!(typeof vertex_idx !== 'undefined' && normals[vertex_idx * 3] === localNormal.x && normals[vertex_idx * 3 + 1] === localNormal.y && normals[vertex_idx * 3 + 2] === localNormal.z && uvs[vertex_idx * 2] === uv.x && uvs[vertex_idx * 2 + 1] === uv.y)) {
+                            vertices.push(localVertex.x, localVertex.y, localVertex.z);
                             uvs.push(uv.x, uv.y);
                             normals.push(normal.x, normal.y, normal.z);
-                            vertex_idx = vertice_dict[vertex.x + ',' + vertex.y + ',' + vertex.z] = (vertices.length / 3) - 1;
+                            vertex_idx = vertice_dict[localVertex.x + ',' + localVertex.y + ',' + localVertex.z] = (vertices.length / 3) - 1;
                         }
 
                         indices.push(vertex_idx);

+ 12 - 14
Babylon/Mesh/babylon.csg.ts

@@ -306,11 +306,11 @@
                 for (var i = subMeshes[sm].indexStart, il = subMeshes[sm].indexCount + subMeshes[sm].indexStart; i < il; i += 3) {
                     vertices = [];
                     for (var j = 0; j < 3; j++) {
-                        normal = new BABYLON.Vector3(normals[indices[i + j] * 3], normals[indices[i + j] * 3 + 1], normals[indices[i + j] * 3 + 2]);
+                        var sourceNormal = new BABYLON.Vector3(normals[indices[i + j] * 3], normals[indices[i + j] * 3 + 1], normals[indices[i + j] * 3 + 2]);
                         uv = new BABYLON.Vector2(uvs[indices[i + j] * 2], uvs[indices[i + j] * 2 + 1]);
-                        position = new BABYLON.Vector3(positions[indices[i + j] * 3], positions[indices[i + j] * 3 + 1], positions[indices[i + j] * 3 + 2]);
-                        BABYLON.Vector3.TransformCoordinatesToRef(position, matrix, position);
-                        BABYLON.Vector3.TransformNormalToRef(normal, matrix, normal);
+                        var sourcePosition = new BABYLON.Vector3(positions[indices[i + j] * 3], positions[indices[i + j] * 3 + 1], positions[indices[i + j] * 3 + 2]);
+                        position = BABYLON.Vector3.TransformCoordinates(sourcePosition, matrix);
+                        normal = BABYLON.Vector3.TransformNormal(sourceNormal, matrix);
 
                         vertex = new Vertex(position, normal, uv);
                         vertices.push(vertex);
@@ -522,24 +522,22 @@
                         vertex.copyFrom(polygon.vertices[polygonIndices[k]].pos);
                         normal.copyFrom(polygon.vertices[polygonIndices[k]].normal);
                         uv.copyFrom(polygon.vertices[polygonIndices[k]].uv);
-                        BABYLON.Vector3.TransformCoordinatesToRef(vertex, matrix, vertex);
-                        BABYLON.Vector3.TransformNormalToRef(normal, matrix, normal);
+                        var localVertex = BABYLON.Vector3.TransformCoordinates(vertex, matrix);
+                        var localNormal = BABYLON.Vector3.TransformNormal(normal, matrix);
 
-
-
-                        vertex_idx = vertice_dict[vertex.x + ',' + vertex.y + ',' + vertex.z];
+                        vertex_idx = vertice_dict[localVertex.x + ',' + localVertex.y + ',' + localVertex.z];
 
                         // Check if 2 points can be merged
                         if (!(typeof vertex_idx !== 'undefined' &&
-                            normals[vertex_idx * 3] === normal.x &&
-                            normals[vertex_idx * 3 + 1] === normal.y &&
-                            normals[vertex_idx * 3 + 2] === normal.z &&
+                            normals[vertex_idx * 3] === localNormal.x &&
+                            normals[vertex_idx * 3 + 1] === localNormal.y &&
+                            normals[vertex_idx * 3 + 2] === localNormal.z &&
                             uvs[vertex_idx * 2] === uv.x &&
                             uvs[vertex_idx * 2 + 1] === uv.y)) {
-                            vertices.push(vertex.x, vertex.y, vertex.z);
+                            vertices.push(localVertex.x, localVertex.y, localVertex.z);
                             uvs.push(uv.x, uv.y);
                             normals.push(normal.x, normal.y, normal.z);
-                            vertex_idx = vertice_dict[vertex.x + ',' + vertex.y + ',' + vertex.z] = (vertices.length / 3) - 1;
+                            vertex_idx = vertice_dict[localVertex.x + ',' + localVertex.y + ',' + localVertex.z] = (vertices.length / 3) - 1;
                         }
 
                         indices.push(vertex_idx);

+ 3 - 3
Babylon/Mesh/babylon.geometry.js

@@ -45,17 +45,17 @@ var BABYLON;
             vertexData.applyToGeometry(this, updatable);
         };
 
-        Geometry.prototype.setVerticesData = function (kind, data, updatable) {
+        Geometry.prototype.setVerticesData = function (kind, data, updatable, stride) {
             this._vertexBuffers = this._vertexBuffers || {};
 
             if (this._vertexBuffers[kind]) {
                 this._vertexBuffers[kind].dispose();
             }
 
-            this._vertexBuffers[kind] = new BABYLON.VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0);
+            this._vertexBuffers[kind] = new BABYLON.VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0, stride);
 
             if (kind === BABYLON.VertexBuffer.PositionKind) {
-                var stride = this._vertexBuffers[kind].getStrideSize();
+                stride = this._vertexBuffers[kind].getStrideSize();
 
                 this._totalVertices = data.length / stride;
 

+ 3 - 3
Babylon/Mesh/babylon.geometry.ts

@@ -54,17 +54,17 @@
             vertexData.applyToGeometry(this, updatable);
         }
 
-        public setVerticesData(kind: string, data: number[], updatable?: boolean): void {
+        public setVerticesData(kind: string, data: number[], updatable?: boolean, stride?: number): void {
             this._vertexBuffers = this._vertexBuffers || {};
 
             if (this._vertexBuffers[kind]) {
                 this._vertexBuffers[kind].dispose();
             }
 
-            this._vertexBuffers[kind] = new VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0);
+            this._vertexBuffers[kind] = new VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0, stride);
 
             if (kind === BABYLON.VertexBuffer.PositionKind) {
-                var stride = this._vertexBuffers[kind].getStrideSize();
+                stride = this._vertexBuffers[kind].getStrideSize();
 
                 this._totalVertices = data.length / stride;
 

+ 2 - 2
Babylon/Mesh/babylon.mesh.js

@@ -274,7 +274,7 @@ var BABYLON;
             this.synchronizeInstances();
         };
 
-        Mesh.prototype.setVerticesData = function (kind, data, updatable) {
+        Mesh.prototype.setVerticesData = function (kind, data, updatable, stride) {
             if (kind instanceof Array) {
                 var temp = data;
                 data = kind;
@@ -291,7 +291,7 @@ var BABYLON;
 
                 new BABYLON.Geometry(BABYLON.Geometry.RandomId(), scene, vertexData, updatable, this);
             } else {
-                this._geometry.setVerticesData(kind, data, updatable);
+                this._geometry.setVerticesData(kind, data, updatable, stride);
             }
         };
 

+ 2 - 2
Babylon/Mesh/babylon.mesh.ts

@@ -269,7 +269,7 @@
             this.synchronizeInstances();
         }
 
-        public setVerticesData(kind: any, data: any, updatable?: boolean): void {
+        public setVerticesData(kind: any, data: any, updatable?: boolean, stride?: number): void {
             if (kind instanceof Array) {
                 var temp = data;
                 data = kind;
@@ -287,7 +287,7 @@
                 new BABYLON.Geometry(Geometry.RandomId(), scene, vertexData, updatable, this);
             }
             else {
-                this._geometry.setVerticesData(kind, data, updatable);
+                this._geometry.setVerticesData(kind, data, updatable, stride);
             }
         }
 

+ 7 - 2
Babylon/Mesh/babylon.vertexBuffer.js

@@ -1,7 +1,7 @@
 var BABYLON;
 (function (BABYLON) {
     var VertexBuffer = (function () {
-        function VertexBuffer(engine, data, kind, updatable, postponeInternalCreation) {
+        function VertexBuffer(engine, data, kind, updatable, postponeInternalCreation, stride) {
             if (engine instanceof BABYLON.Mesh) {
                 this._engine = engine.getScene().getEngine();
             } else {
@@ -18,6 +18,11 @@
 
             this._kind = kind;
 
+            if (stride) {
+                this._strideSize = stride;
+                return;
+            }
+
             switch (kind) {
                 case VertexBuffer.PositionKind:
                     this._strideSize = 3;
@@ -32,7 +37,7 @@
                     this._strideSize = 2;
                     break;
                 case VertexBuffer.ColorKind:
-                    this._strideSize = 3;
+                    this._strideSize = 4;
                     break;
                 case VertexBuffer.MatricesIndicesKind:
                     this._strideSize = 4;

+ 8 - 2
Babylon/Mesh/babylon.vertexBuffer.ts

@@ -8,7 +8,7 @@
         private _kind: string;
         private _strideSize: number;
 
-        constructor(engine: any, data: number[], kind: string, updatable: boolean, postponeInternalCreation?: boolean) {
+        constructor(engine: any, data: number[], kind: string, updatable: boolean, postponeInternalCreation?: boolean, stride?: number) {
             if (engine instanceof Mesh) { // old versions of BABYLON.VertexBuffer accepted 'mesh' instead of 'engine'
                 this._engine = engine.getScene().getEngine();
             }
@@ -26,6 +26,12 @@
 
             this._kind = kind;
 
+            if (stride) {
+                this._strideSize = stride;
+                return;
+            }
+
+            // Deduce stride from kind
             switch (kind) {
                 case VertexBuffer.PositionKind:
                     this._strideSize = 3;
@@ -40,7 +46,7 @@
                     this._strideSize = 2;
                     break;
                 case VertexBuffer.ColorKind:
-                    this._strideSize = 3;
+                    this._strideSize = 4;
                     break;
                 case VertexBuffer.MatricesIndicesKind:
                     this._strideSize = 4;

+ 2 - 0
Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPass.js

@@ -13,6 +13,8 @@
             this._renderTexture.onAfterRender = afterRender;
 
             this._scene = scene;
+
+            this._renderList = renderList;
         }
         // private
         PostProcessRenderPass.prototype._incRefCount = function () {

+ 2 - 1
Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPass.ts

@@ -19,10 +19,11 @@
             this._renderTexture.onAfterRender = afterRender;
 
             this._scene = scene;
+
+            this._renderList = renderList;
         }
 
         // private
-
         public _incRefCount(): number {
             if (this._refCount === 0) {
                 this._scene.customRenderTargets.push(this._renderTexture);

+ 1 - 1
Babylon/Rendering/babylon.renderingGroup.js

@@ -87,7 +87,7 @@
             var material = subMesh.getMaterial();
             var mesh = subMesh.getMesh();
 
-            if (material.needAlphaBlending() || mesh.visibility < 1.0) {
+            if (material.needAlphaBlending() || mesh.visibility < 1.0 || mesh.hasVertexAlpha) {
                 if (material.alpha > 0 || mesh.visibility < 1.0) {
                     this._transparentSubMeshes.push(subMesh);
                 }

+ 1 - 1
Babylon/Rendering/babylon.renderingGroup.ts

@@ -91,7 +91,7 @@
             var material = subMesh.getMaterial();
             var mesh = subMesh.getMesh();
 
-            if (material.needAlphaBlending() || mesh.visibility < 1.0) { // Transparent
+            if (material.needAlphaBlending() || mesh.visibility < 1.0 || mesh.hasVertexAlpha) { // Transparent
                 if (material.alpha > 0 || mesh.visibility < 1.0) {
                     this._transparentSubMeshes.push(subMesh);
                 }

+ 82 - 0
Babylon/Shaders/brick.fragment.fx

@@ -0,0 +1,82 @@
+#ifdef GL_ES
+precision highp float;
+#endif
+
+varying vec2 vPosition;
+varying vec2 vUV;
+
+uniform float numberOfBricksHeight;
+uniform float numberOfBricksWidth;
+
+float rand(vec2 n) {
+	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
+}
+
+float noise(vec2 n) {
+	const vec2 d = vec2(0.0, 1.0);
+	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
+	return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
+}
+
+float fbm(vec2 n) {
+	float total = 0.0, amplitude = 1.0;
+	for (int i = 0; i < 4; i++) {
+		total += noise(n) * amplitude;
+		n += n;
+		amplitude *= 0.5;
+	}
+	return total;
+}
+
+float round(float number){
+	return sign(number)*floor(abs(number) + 0.5);
+}
+
+void main(void)
+{
+	vec3 brick = vec3(0.77, 0.47, 0.40);
+	vec3 joint = vec3(0.72, 0.72, 0.72);
+
+	float brickW = 1.0 / numberOfBricksWidth;
+	float brickH = 1.0 / numberOfBricksHeight;
+	float jointWPercentage = 0.01;
+	float jointHPercentage = 0.05;
+
+	vec3 color = brick;
+
+
+	float yi = vUV.y / brickH;
+	float nyi = round(yi);
+
+	float xi = vUV.x / brickW;
+
+	if (mod(floor(yi), 2.0) == 0.0){
+		xi = xi - 0.5;
+	}
+
+	float nxi = round(xi);
+
+	vec2 brickvUV = vec2((xi - floor(xi)) / brickH, (yi - floor(yi)) /  brickW);
+
+
+	if (yi < nyi + jointHPercentage && yi > nyi - jointHPercentage){
+		color = mix(joint, vec3(0.37, 0.25, 0.25), (yi - nyi) / jointHPercentage + 0.2);
+	}
+	else if (xi < nxi + jointWPercentage && xi > nxi - jointWPercentage){
+		color = mix(joint, vec3(0.44, 0.44, 0.44), (xi - nxi) / jointWPercentage + 0.2);
+	}
+	else {
+		float momo = mod(floor(yi) + floor(xi), 3.0);
+
+		if (momo == 0.0)
+			color = mix(color, vec3(0.33, 0.33, 0.33), 0.3);
+		else if (momo == 2.0)
+			color = mix(color, vec3(0.11, 0.11, 0.11), 0.3);
+
+
+		//color = mix(momo, vec3(0.53, 0.2, 0.0), fbm(brickvUV * 2.0));
+	}
+
+
+	gl_FragColor = vec4(color, 1.0);
+}

+ 6 - 2
Babylon/Shaders/default.fragment.fx

@@ -21,7 +21,7 @@ varying vec3 vPositionW;
 varying vec3 vNormalW;
 
 #ifdef VERTEXCOLOR
-varying vec3 vColor;
+varying vec4 vColor;
 #endif
 
 // Lights
@@ -473,7 +473,7 @@ void main(void) {
 	float alpha = vDiffuseColor.a;
 
 #ifdef VERTEXCOLOR
-	diffuseColor *= vColor;
+	baseColor.rgb *= vColor.rgb;
 #endif
 
 #ifdef DIFFUSE
@@ -661,6 +661,10 @@ void main(void) {
 
 #endif
 
+#ifdef VERTEXALPHA
+	alpha *= vColor.a;
+#endif
+
 #ifdef OPACITYFRESNEL
 	float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, opacityParts.z, opacityParts.w);
 

+ 2 - 2
Babylon/Shaders/default.vertex.fx

@@ -12,7 +12,7 @@ attribute vec2 uv;
 attribute vec2 uv2;
 #endif
 #ifdef VERTEXCOLOR
-attribute vec3 color;
+attribute vec4 color;
 #endif
 #ifdef BONES
 attribute vec4 matricesIndices;
@@ -82,7 +82,7 @@ varying vec3 vPositionW;
 varying vec3 vNormalW;
 
 #ifdef VERTEXCOLOR
-varying vec3 vColor;
+varying vec4 vColor;
 #endif
 
 #ifdef CLIPPLANE

+ 8 - 0
Babylon/Shaders/empty.fragment.fx

@@ -0,0 +1,8 @@
+#ifdef GL_ES
+precision highp float;
+#endif
+
+void main(void)
+{
+	
+}

+ 11 - 24
Babylon/Shaders/grass.fragment.fx

@@ -5,11 +5,6 @@ precision highp float;
 varying vec2 vPosition;
 varying vec2 vUV;
 
-uniform float ampScale;
-uniform float ringScale;
-uniform vec3 woodColor1;
-uniform vec3 woodColor2;
-
 
 float rand(vec2 n) {
 	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
@@ -33,25 +28,17 @@ float fbm(vec2 n) {
 
 void main(void) {
 
-	float herbwidth = 8.0;
-
-	vec3 dirt = vec3(0.32, 0.17, 0.09);
-	vec3 herb = vec3(0.0, 0.39, 0.09);
-	vec3 ground = dirt;
-
-	herbwidth = floor(herbwidth - noise(vUV * 8.0 ));
-
-	float ratioy = mod(floor(gl_FragCoord.y), herbwidth);
-	float ratiox = mod(floor(gl_FragCoord.x), herbwidth);
-
-	/*herb = herb * ratiox;
-	dirt = dirt * ratioy;*/
-
-	if (ratioy >= 0.0 && ratioy < herbwidth / fbm(vUV * 2.0))
-		ground = herb;
-
-	if (ratiox >= 0.0 && ratiox < herbwidth / 2.0)
-		ground = herb;
+	vec3 herb1 = vec3(0.29, 0.38, 0.02);
+	vec3 herb2 = vec3(0.36, 0.49, 0.09);
+	vec3 herb3 = vec3(0.51, 0.6, 0.28);
+	vec3 dirt = vec3(0.6, 0.46, 0.13);
+
+	vec3 ground = vec3(1,1,1);
+	
+	ground = mix(ground, herb1, rand(gl_FragCoord.xy * 4.0));
+	ground = mix(ground, herb2, rand(gl_FragCoord.xy * 8.0));
+	ground = mix(ground, herb3, rand(gl_FragCoord.xy));
+	ground = mix(ground, herb1, fbm(gl_FragCoord.xy * 16.0));
 
 	gl_FragColor = vec4(ground, 1.0);
 }

+ 6 - 2
Babylon/Shaders/legacydefault.fragment.fx

@@ -16,7 +16,7 @@ varying vec3 vPositionW;
 varying vec3 vNormalW;
 
 #ifdef VERTEXCOLOR
-varying vec3 vColor;
+varying vec4 vColor;
 #endif
 
 // Lights
@@ -353,7 +353,7 @@ void main(void) {
 	vec3 diffuseColor = vDiffuseColor.rgb;
 
 #ifdef VERTEXCOLOR
-	diffuseColor *= vColor;
+	baseColor.rgb *= vColor.rgb;
 #endif
 
 #ifdef DIFFUSE
@@ -516,6 +516,10 @@ void main(void) {
 #endif
 #endif
 
+#ifdef VERTEXALPHA
+	alpha *= vColor.a;
+#endif
+
 #ifdef OPACITYFRESNEL
 	float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, opacityParts.z, opacityParts.w);
 

+ 2 - 2
Babylon/Shaders/legacydefault.vertex.fx

@@ -19,7 +19,7 @@ attribute vec2 uv;
 attribute vec2 uv2;
 #endif
 #ifdef VERTEXCOLOR
-attribute vec3 color;
+attribute vec4 color;
 #endif
 #ifdef BONES
 attribute vec4 matricesIndices;
@@ -83,7 +83,7 @@ varying vec3 vPositionW;
 varying vec3 vNormalW;
 
 #ifdef VERTEXCOLOR
-varying vec3 vColor;
+varying vec4 vColor;
 #endif
 
 #ifdef CLIPPLANE

+ 104 - 0
Babylon/Shaders/marble.fragment.fx

@@ -0,0 +1,104 @@
+#ifdef GL_ES
+precision highp float;
+#endif
+
+varying vec2 vPosition;
+varying vec2 vUV;
+
+
+uniform float numberOfBricksHeight;
+uniform float numberOfBricksWidth ;
+
+const vec3 tileSize = vec3(1.1, 1.0, 1.1);
+const vec3 tilePct = vec3(0.98, 1.0, 0.98);
+
+
+float rand(vec2 n) {
+	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
+}
+
+float noise(vec2 n) {
+	const vec2 d = vec2(0.0, 1.0);
+	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
+	return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
+}
+
+float turbulence(vec2 P)
+{
+	float val = 0.0;
+	float freq = 1.0;
+	for (int i = 0; i < 4; i++)
+	{
+		val += abs(noise(P*freq) / freq);
+		freq *= 2.07;
+	}
+	return val;
+}
+
+float round(float number){
+	return sign(number)*floor(abs(number) + 0.5);
+}
+
+
+vec3 marble_color(float x)
+{
+	vec3 col;
+	x = 0.5*(x + 1.);
+	x = sqrt(x);             
+	x = sqrt(x);
+	x = sqrt(x);
+	col = vec3(.2 + .75*x);  
+	col.b *= 0.95;           
+	return col;
+}
+void main()
+{
+
+	vec3 brick = vec3(0.77, 0.47, 0.40);
+	vec3 joint = vec3(0.72, 0.72, 0.72);
+
+	float brickW = 1.0 / numberOfBricksWidth;
+	float brickH = 1.0 / numberOfBricksHeight;
+	float jointWPercentage = 0.01;
+	float jointHPercentage = 0.01;
+
+	vec3 color = brick;
+
+
+	float yi = vUV.y / brickH;
+	float nyi = round(yi);
+
+	float xi = vUV.x / brickW;
+
+	if (mod(floor(yi), 2.0) == 0.0){
+		xi = xi - 0.5;
+	}
+
+	float nxi = round(xi);
+
+	vec2 brickvUV = vec2((xi - floor(xi)) / brickH, (yi - floor(yi)) / brickW);
+
+
+	if (yi < nyi + jointHPercentage && yi > nyi - jointHPercentage){
+		color = mix(joint, vec3(0.37, 0.25, 0.25), (yi - nyi) / jointHPercentage + 0.2);
+	}
+	else if (xi < nxi + jointWPercentage && xi > nxi - jointWPercentage){
+		color = mix(joint, vec3(0.44, 0.44, 0.44), (xi - nxi) / jointWPercentage + 0.2);
+	}
+	else {
+
+		float amplitude = 9.0;
+
+		float t = 6.28 * brickvUV.x / (tileSize.x + noise(vec2(vUV)*6.0));
+		t += amplitude * turbulence(brickvUV.xy);
+
+		t = sin(t);
+		color = marble_color(t);
+
+
+	}
+
+	gl_FragColor = vec4(color, 0.0);
+
+	
+}

+ 98 - 92
Babylon/Shaders/rock.fragment.fx

@@ -5,110 +5,116 @@ precision highp float;
 varying vec2 vPosition;
 varying vec2 vUV;
 
-uniform float ampScale;
-uniform float ringScale;
-uniform vec3 woodColor1;
-uniform vec3 woodColor2;
+vec3 hash(vec3 x)
+{
+	x = vec3(dot(x, vec3(127.1, 311.7, 74.7)),
+		dot(x, vec3(269.5, 183.3, 246.1)),
+		dot(x, vec3(113.5, 271.9, 124.6)));
 
-
-float rand(vec2 n) {
-	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
+	return fract(sin(x)*43758.5453123);
 }
 
-float noise(vec2 n) {
-	const vec2 d = vec2(0.0, 1.0);
-	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
-	return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
-}
+// returns closest, second closest, and cell id
+vec3 voronoi(in vec3 x)
+{
+	vec3 p = floor(x);
+	vec3 f = fract(x);
+
+	float id = 0.0;
+	vec2 res = vec2(100.0);
+	for (int k = -1; k <= 1; k++)
+		for (int j = -1; j <= 1; j++)
+			for (int i = -1; i <= 1; i++)
+			{
+		vec3 b = vec3(float(i), float(j), float(k));
+		vec3 r = vec3(b) - f + hash(p + b);
+		float d = dot(r, r);
+
+		if (d < res.x)
+		{
+			id = dot(p + b, vec3(1.0, 57.0, 113.0));
+			res = vec2(d, res.x);
+		}
+		else if (d < res.y)
+		{
+			res.y = d;
+		}
+			}
 
-float fbm(vec2 n) {
-	float total = 0.0, amplitude = 1.0;
-	for (int i = 0; i < 4; i++) {
-		total += noise(n) * amplitude;
-		n += n;
-		amplitude *= 0.5;
-	}
-	return total;
+	return vec3(sqrt(res), abs(id));
 }
 
+const mat3 m = mat3(0.00, 0.80, 0.60,
+	-0.80, 0.36, -0.48,
+	-0.60, -0.48, 0.64);
+
+void main(void)
+{
+	vec2 p = vUV;
+
+	// camera movement	
+	float an = 0.5*0.1;
+	vec3 ro = vec3(2.5*cos(an), 1.0, 2.5*sin(an));
+	vec3 ta = vec3(0.0, 1.0, 0.0);
+	// camera matrix
+	vec3 ww = normalize(ta - ro);
+	vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
+	vec3 vv = normalize(cross(uu, ww));
+	// create view ray
+	vec3 rd = normalize(p.x*uu + p.y*vv + 1.5*ww);
+
+	// sphere center	
+	vec3 sc = vec3(0.0, 1.0, 0.0);
+
+	// raytrace
+	float tmin = 10000.0;
+	vec3  nor = vec3(0.0);
+	float occ = 1.0;
+	vec3  pos = vec3(0.0);
+
+	// raytrace-plane
+	float h = (0.0 - ro.y) / rd.y;
+	if (h>0.0)
+	{
+		tmin = h;
+		nor = vec3(0.0, 1.0, 0.0);
+		pos = ro + h*rd;
+		vec3 di = sc - pos;
+		float l = length(di);
+		occ = 1.0 - dot(nor, di / l)*1.0*1.0 / (l*l);
+	}
 
-
-void main(void) {
-
-
-	/*vec3 rock = vec3(0.53, 0.53, 0.53);
-	vec3 roll = vec3(0.18, 0.18, 0.18);
-
-	float ratioy = mod(vUV.y * 50.0, fbm(vUV * 8.0));
-
-	rock = rock * ratioy;
-	roll = roll * ratioy;
-
-	vec3 stone = mix(rock, roll, 0.5);
-
-
-	gl_FragColor = vec4(stone, 1.0);*/
-
-
-	/* voronoi.frag */
-
-
-	vec2 seeds[16];
-	vec3 colors[16];
-
-	colors[0] = vec3(0.53, 0.53, 0.53);
-	colors[1] = vec3(0.28, 0.28, 0.28);
-	colors[2] = vec3(0.23, 0.23, 0.23);
-	colors[3] = vec3(0.38, 0.38, 0.38);
-	colors[4] = vec3(0.63, 0.63, 0.63);
-	colors[5] = vec3(0.78, 0.78, 0.78);
-	colors[6] = vec3(0.93, 0.93, 0.93);
-	colors[7] = vec3(0.73, 0.73, 0.73);
-	colors[8] = vec3(0.43, 0.43, 0.43);
-	colors[9] = vec3(0.11, 0.11, 0.11);
-	colors[10] = vec3(0.12, 0.12, 0.12);
-	colors[11] = vec3(0.64, 0.64, 0.64);
-	colors[12] = vec3(0.79, 0.79, 0.79);
-	colors[13] = vec3(0.43, 0.43, 0.43);
-	colors[14] = vec3(0.21, 0.21, 0.21);
-	colors[15] = vec3(0.37, 0.37, 0.37);
-
-	seeds[0] = vec2(0.1, 0.9);
-	seeds[1] = vec2(0.2, 0.8);
-	seeds[2] = vec2(0.3, 0.7);
-	seeds[3] = vec2(0.4, 0.4);
-	seeds[4] = vec2(0.5, 0.5);
-	seeds[5] = vec2(0.6, 0.3);
-	seeds[6] = vec2(0.7, 0.2);
-	seeds[7] = vec2(0.8, 0.3);
-	seeds[8] = vec2(0.9, 0.4);
-	seeds[9] = vec2(1.0, 0.3);
-	seeds[10] = vec2(0.5, 0.4);
-	seeds[11] = vec2(0.7, 0.8);
-	seeds[12] = vec2(0.5, 0.3);
-	seeds[13] = vec2(0.7, 0.7);
-	seeds[14] = vec2(0.3, 0.3);
-	seeds[15] = vec2(0.7, 0.7);
-
-	float dist = distance(seeds[0], vPosition);
-	vec3 color = colors[0];
-
-	float hotpoint = 1.0;
-	float current = 1.0;
-	for (int i = 1; i < 16; i++) {
-		current = distance(seeds[i], vPosition);
-		if (current < dist) {
-			hotpoint++;
-			color = colors[i];
-			dist = current;
+	// raytrace-sphere
+	vec3  ce = ro - sc;
+	float b = dot(rd, ce);
+	float c = dot(ce, ce) - 1.0;
+	h = b*b - c;
+	if (h>0.0)
+	{
+		h = -b - sqrt(h);
+		if (h<tmin)
+		{
+			tmin = h;
+			nor = normalize(ro + h*rd - sc);
+			occ = 0.5 + 0.5*nor.y;
 		}
 	}
 
-	if (hotpoint > 3.0)
-		color = mix(vec3(0.39, 0.32, 0), color, 1.0 / hotpoint);
+	// shading/lighting	
+	vec3 col = vec3(0.9);
+	if (tmin<100.0)
+	{
+		pos = ro + tmin*rd;
+
+		float f = voronoi(4.0*pos).x;
 
-	gl_FragColor = vec4(color, 1.0);
+		f *= occ;
+		col = vec3(f*1.2);
+		col = mix(col, vec3(0.9), 1.0 - exp(-0.003*tmin*tmin));
+	}
 
+	col = sqrt(col);
 
 
+	gl_FragColor = vec4(col, 1.0);
 }

+ 28 - 3
Babylon/babylon.engine.js

@@ -378,6 +378,7 @@
             this._loadedTexturesCache = new Array();
             this._activeTexturesCache = new Array();
             this._compiledEffects = {};
+            this._uintIndicesCurrentlySet = false;
             this._renderingCanvas = canvas;
             this._canvasClientRect = this._renderingCanvas.getBoundingClientRect();
 
@@ -427,6 +428,7 @@
             this._caps.textureAnisotropicFilterExtension = this._gl.getExtension('EXT_texture_filter_anisotropic') || this._gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic') || this._gl.getExtension('MOZ_EXT_texture_filter_anisotropic');
             this._caps.maxAnisotropy = this._caps.textureAnisotropicFilterExtension ? this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 0;
             this._caps.instancedArrays = this._gl.getExtension('ANGLE_instanced_arrays');
+            this._caps.uintIndices = this._gl.getExtension('OES_element_index_uint') !== null;
 
             // Depth buffer
             this.setDepthBuffer(true);
@@ -730,6 +732,7 @@
         };
 
         Engine.prototype.restoreDefaultFramebuffer = function () {
+            this._currentRenderTarget = null;
             this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
 
             this.setViewport(this._cachedViewport);
@@ -785,9 +788,28 @@
         Engine.prototype.createIndexBuffer = function (indices) {
             var vbo = this._gl.createBuffer();
             this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, vbo);
-            this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), this._gl.STATIC_DRAW);
+
+            // Check for 32 bits indices
+            var arrayBuffer;
+            var need32Bits = false;
+
+            if (this._caps.uintIndices) {
+                for (var index = 0; index < indices.length; index++) {
+                    if (indices[index] > 65535) {
+                        need32Bits = true;
+                        break;
+                    }
+                }
+
+                arrayBuffer = need32Bits ? new Uint32Array(indices) : new Uint16Array(indices);
+            } else {
+                arrayBuffer = new Uint16Array(indices);
+            }
+
+            this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, arrayBuffer, this._gl.STATIC_DRAW);
             this._resetIndexBufferBinding();
             vbo.references = 1;
+            vbo.is32Bits = need32Bits;
             return vbo;
         };
 
@@ -812,6 +834,7 @@
             if (this._cachedIndexBuffer !== indexBuffer) {
                 this._cachedIndexBuffer = indexBuffer;
                 this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
+                this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
             }
         };
 
@@ -840,6 +863,7 @@
             if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
                 this._cachedIndexBuffer = indexBuffer;
                 this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
+                this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
             }
         };
 
@@ -899,12 +923,13 @@
             this.applyStates();
 
             // Render
+            var indexFormat = this._uintIndicesCurrentlySet ? this._gl.UNSIGNED_INT : this._gl.UNSIGNED_SHORT;
             if (instancesCount) {
-                this._caps.instancedArrays.drawElementsInstancedANGLE(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, this._gl.UNSIGNED_SHORT, indexStart * 2, instancesCount);
+                this._caps.instancedArrays.drawElementsInstancedANGLE(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, indexFormat, indexStart * 2, instancesCount);
                 return;
             }
 
-            this._gl.drawElements(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, this._gl.UNSIGNED_SHORT, indexStart * 2);
+            this._gl.drawElements(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, indexFormat, indexStart * 2);
         };
 
         Engine.prototype.drawPointClouds = function (verticesStart, verticesCount, instancesCount) {

+ 30 - 3
Babylon/babylon.engine.ts

@@ -341,6 +341,7 @@
         public textureAnisotropicFilterExtension;
         public maxAnisotropy: number;
         public instancedArrays;
+        public uintIndices: boolean;
     }
 
     export class Engine {
@@ -439,6 +440,7 @@
         private _cachedEffectForVertexBuffers: Effect;
         private _currentRenderTarget: WebGLTexture;
         private _canvasClientRect: ClientRect;
+        private _uintIndicesCurrentlySet = false;
 
         private _workingCanvas: HTMLCanvasElement;
         private _workingContext: CanvasRenderingContext2D;
@@ -495,6 +497,7 @@
             this._caps.textureAnisotropicFilterExtension = this._gl.getExtension('EXT_texture_filter_anisotropic') || this._gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic') || this._gl.getExtension('MOZ_EXT_texture_filter_anisotropic');
             this._caps.maxAnisotropy = this._caps.textureAnisotropicFilterExtension ? this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 0;
             this._caps.instancedArrays = this._gl.getExtension('ANGLE_instanced_arrays');
+            this._caps.uintIndices = this._gl.getExtension('OES_element_index_uint') !== null;
 
             // Depth buffer
             this.setDepthBuffer(true);
@@ -740,6 +743,7 @@
         }
 
         public restoreDefaultFramebuffer(): void {
+            this._currentRenderTarget = null;
             this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
 
             this.setViewport(this._cachedViewport);
@@ -794,9 +798,29 @@
         public createIndexBuffer(indices: number[]): WebGLBuffer {
             var vbo = this._gl.createBuffer();
             this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, vbo);
-            this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), this._gl.STATIC_DRAW);
+
+            // Check for 32 bits indices
+            var arrayBuffer;
+            var need32Bits = false;
+
+            if (this._caps.uintIndices) {
+                
+                for (var index = 0; index < indices.length; index++) {
+                    if (indices[index] > 65535) {
+                        need32Bits = true;
+                        break;
+                    }
+                }
+
+                arrayBuffer = need32Bits ? new Uint32Array(indices) : new Uint16Array(indices);
+            } else {
+                arrayBuffer = new Uint16Array(indices);
+            }
+
+            this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, arrayBuffer, this._gl.STATIC_DRAW);
             this._resetIndexBufferBinding();
             vbo.references = 1;
+            vbo.is32Bits = need32Bits;
             return vbo;
         }
 
@@ -821,6 +845,7 @@
             if (this._cachedIndexBuffer !== indexBuffer) {
                 this._cachedIndexBuffer = indexBuffer;
                 this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
+                this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
             }
         }
 
@@ -849,6 +874,7 @@
             if (indexBuffer!= null && this._cachedIndexBuffer !== indexBuffer) {
                 this._cachedIndexBuffer = indexBuffer;
                 this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
+                this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
             }
         }
 
@@ -909,12 +935,13 @@
             this.applyStates();
 
             // Render
+            var indexFormat = this._uintIndicesCurrentlySet ? this._gl.UNSIGNED_INT : this._gl.UNSIGNED_SHORT;
             if (instancesCount) {
-                this._caps.instancedArrays.drawElementsInstancedANGLE(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, this._gl.UNSIGNED_SHORT, indexStart * 2, instancesCount);
+                this._caps.instancedArrays.drawElementsInstancedANGLE(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, indexFormat, indexStart * 2, instancesCount);
                 return;
             }
 
-            this._gl.drawElements(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, this._gl.UNSIGNED_SHORT, indexStart * 2);
+            this._gl.drawElements(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, indexFormat, indexStart * 2);
         }
 
         public drawPointClouds(verticesStart: number, verticesCount: number, instancesCount?: number): void {

+ 1 - 0
Babylon/babylon.mixins.ts

@@ -67,6 +67,7 @@ interface WebGLTexture {
 interface WebGLBuffer {
     references: number;
     capacity: number;
+    is32Bits: boolean;
 }
 
 interface MouseEvent {

+ 3 - 0
Exporters/3ds Max/BabylonExport.Entities/BabylonMesh.cs

@@ -43,6 +43,9 @@ namespace BabylonExport.Entities
         public float[] colors { get; set; }
 
         [DataMember]
+        public bool hasVertexAlpha { get; set; }
+
+        [DataMember]
         public int[] matricesIndices { get; set; }
 
         [DataMember]

BIN
Exporters/3ds Max/Max2Babylon-0.8.2.zip


BIN
Exporters/3ds Max/Max2Babylon-0.8.3.zip


+ 15 - 9
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Material.cs

@@ -18,7 +18,7 @@ namespace Max2Babylon
 
             if (materialNode.NumSubMtls > 0)
             {
-                var babylonMultimaterial = new BabylonMultiMaterial {name = name, id = id};
+                var babylonMultimaterial = new BabylonMultiMaterial { name = name, id = id };
 
                 var guids = new List<string>();
 
@@ -56,7 +56,7 @@ namespace Max2Babylon
                 ambient = materialNode.GetAmbient(0, false).ToArray(),
                 diffuse = materialNode.GetDiffuse(0, false).ToArray(),
                 specular = materialNode.GetSpecular(0, false).Scale(materialNode.GetShinStr(0, false)),
-                specularPower = materialNode.GetShininess(0, false)*256,
+                specularPower = materialNode.GetShininess(0, false) * 256,
                 emissive =
                     materialNode.GetSelfIllumColorOn(0, false)
                         ? materialNode.GetSelfIllumColor(0, false).ToArray()
@@ -87,18 +87,24 @@ namespace Max2Babylon
                 if (fresnelParameters != null)
                 {
                     babylonMaterial.emissiveFresnelParameters = fresnelParameters;
-                    if (babylonMaterial.emissive[0] == 0 && 
+                    if (babylonMaterial.emissive[0] == 0 &&
                         babylonMaterial.emissive[1] == 0 &&
-                        babylonMaterial.emissive[2] == 0)
+                        babylonMaterial.emissive[2] == 0 &&
+                        babylonMaterial.emissiveTexture == null)
                     {
-                        babylonMaterial.emissive = new float[]{1, 1, 1};
+                        babylonMaterial.emissive = new float[] { 1, 1, 1 };
                     }
                 }
-                
+
                 babylonMaterial.opacityTexture = ExportTexture(stdMat, 6, out fresnelParameters, babylonScene, false, true);   // Opacity
                 if (fresnelParameters != null)
                 {
                     babylonMaterial.opacityFresnelParameters = fresnelParameters;
+                    if (babylonMaterial.alpha == 1 &&
+                         babylonMaterial.opacityTexture == null)
+                    {
+                        babylonMaterial.alpha = 0;
+                    }
                 }
 
                 babylonMaterial.bumpTexture = ExportTexture(stdMat, 8, out fresnelParameters, babylonScene);                   // Bump
@@ -111,19 +117,19 @@ namespace Max2Babylon
                     }
                     else
                     {
-                        babylonMaterial.reflectionFresnelParameters = fresnelParameters;                        
+                        babylonMaterial.reflectionFresnelParameters = fresnelParameters;
                     }
                 }
 
                 // Constraints
                 if (babylonMaterial.diffuseTexture != null)
                 {
-                    babylonMaterial.diffuse = new [] { 1.0f, 1.0f, 1.0f };
+                    babylonMaterial.diffuse = new[] { 1.0f, 1.0f, 1.0f };
                 }
 
                 if (babylonMaterial.emissiveTexture != null)
                 {
-                    babylonMaterial.emissive = new float[]{0, 0, 0};
+                    babylonMaterial.emissive = new float[] { 0, 0, 0 };
                 }
 
                 if (babylonMaterial.opacityTexture != null && babylonMaterial.diffuseTexture != null &&

+ 22 - 5
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs

@@ -102,7 +102,7 @@ namespace Max2Babylon
 
                 if (mesh.NumVerts >= 65536)
                 {
-                    RaiseError(string.Format("Mesh {0} has too many vertices (more than 65535)", babylonMesh.name), 2);
+                    RaiseWarning(string.Format("Mesh {0} has tmore than 65536 vertices which means that it will require specific WebGL extension to be rendered. This may impact portability of your scene on low end devices.", babylonMesh.name), 2);
                 }
 
                 // Material
@@ -129,6 +129,8 @@ namespace Max2Babylon
 
                 var hasUV = mesh.NumTVerts > 0;
                 var hasUV2 = mesh.GetNumMapVerts(2) > 0;
+                var hasColor = mesh.NumVertCol > 0;
+                var hasAlpha = mesh.GetNumMapVerts(-2) > 0;
 
                 var optimizeVertices = meshNode.GetBoolProperty("babylonjs_optimizevertices");
 
@@ -151,9 +153,9 @@ namespace Max2Babylon
 
                 for (var face = 0; face < mesh.NumFaces; face++)
                 {
-                    indices.Add(CreateGlobalVertex(mesh, face, vx1, vertices, hasUV, hasUV2, vnorms, verticesAlreadyExported, skinContext));
-                    indices.Add(CreateGlobalVertex(mesh, face, vx2, vertices, hasUV, hasUV2, vnorms, verticesAlreadyExported, skinContext));
-                    indices.Add(CreateGlobalVertex(mesh, face, vx3, vertices, hasUV, hasUV2, vnorms, verticesAlreadyExported, skinContext));
+                    indices.Add(CreateGlobalVertex(mesh, face, vx1, vertices, hasUV, hasUV2, hasColor, hasAlpha, vnorms, verticesAlreadyExported, skinContext));
+                    indices.Add(CreateGlobalVertex(mesh, face, vx2, vertices, hasUV, hasUV2, hasColor, hasAlpha, vnorms, verticesAlreadyExported, skinContext));
+                    indices.Add(CreateGlobalVertex(mesh, face, vx3, vertices, hasUV, hasUV2, hasColor, hasAlpha, vnorms, verticesAlreadyExported, skinContext));
                     matIDs.Add(mesh.Faces[face].MatID % multiMatsCount);
                     CheckCancelled();
                 }
@@ -188,6 +190,12 @@ namespace Max2Babylon
                     babylonMesh.matricesIndices = vertices.Select(v => v.BonesIndices).ToArray();
                 }
 
+                if (hasColor)
+                {
+                    babylonMesh.colors = vertices.SelectMany(v => v.Color.ToArray()).ToArray();
+                    babylonMesh.hasVertexAlpha = hasAlpha;
+                }
+
                 // Submeshes
                 var sortedIndices = new List<int>();
                 var subMeshes = new List<BabylonSubMesh>();
@@ -360,7 +368,7 @@ namespace Max2Babylon
             }
         }
 
-        int CreateGlobalVertex(IMesh mesh, int face, int facePart, List<GlobalVertex> vertices, bool hasUV, bool hasUV2, VNormal[] vnorms, List<GlobalVertex>[] verticesAlreadyExported, IISkinContextData skinContextData)
+        int CreateGlobalVertex(IMesh mesh, int face, int facePart, List<GlobalVertex> vertices, bool hasUV, bool hasUV2, bool hasColor, bool hasAlpha, VNormal[] vnorms, List<GlobalVertex>[] verticesAlreadyExported, IISkinContextData skinContextData)
         {
             var faceObject = mesh.Faces[face];
             var vertexIndex = (int)faceObject.V[facePart];
@@ -384,6 +392,15 @@ namespace Max2Babylon
                 vertex.UV2 = Loader.Global.Point2.Create(mesh.MapVerts(2)[tvertexIndex].X, mesh.MapVerts(2)[tvertexIndex].Y);
             }
 
+            if (hasColor)
+            {
+                var vertexColorIndex = (int)mesh.VcFace[face].T[facePart];
+                var vertexColor = mesh.VertCol[vertexColorIndex];
+                var alpha = hasAlpha ? mesh.MapVerts(-2)[vertexColorIndex].X : 1;
+
+                vertex.Color = new float[] { vertexColor.X, vertexColor.Y, vertexColor.Z, alpha};
+            }
+
             if (skinContextData != null)
             {
                 float weight0 = 0;

+ 6 - 0
Exporters/3ds Max/Max2Babylon/Exporter/GlobalVertex.cs

@@ -12,6 +12,7 @@ namespace Max2Babylon
         public IPoint2 UV2 { get; set; }
         public int BonesIndices { get; set; }
         public IPoint4 Weights { get; set; }
+        public float[] Color { get; set; }
 
         public override int GetHashCode()
         {
@@ -57,6 +58,11 @@ namespace Max2Babylon
                 return false;
             }
 
+            if (Color != null && !other.Color.IsAlmostEqualTo(Color, Tools.Epsilon))
+            {
+                return false;
+            }
+
             return other.BonesIndices == BonesIndices;
         }
     }

+ 47 - 16
Exporters/Blender/io_export_babylon.py

@@ -335,7 +335,7 @@ class BabylonExporter(bpy.types.Operator, bpy_extras.io_utils.ExportHelper):
             # skip if mesh already written by that name, since this one is an instance
             skip = False
             for n in range(0, m):
-                skip |= mesh.dataName == self.meshesAndNodes[n].dataName # nodes have no dataname, so no need to check for
+                skip |= hasattr(mesh, "dataName") and hasattr(self.meshesAndNodes[n], "dataName") and mesh.dataName == self.meshesAndNodes[n].dataName # nodes have no dataname, so no need to check for
              
             if skip: continue
                 
@@ -458,15 +458,17 @@ class FCurveAnimatable:
                     self.animations.append(VectorAnimation(object, 'scale', 'scaling', 1))
                     scaAnim = True
             #Set Animations
-            self.autoAnimate = True
-            self.autoAnimateFrom = 0
-            self.autoAnimateTo =  bpy.context.scene.frame_end - bpy.context.scene.frame_start + 1
-          #  for animation in self.animations:
-          #      if self.autoAnimateFrom > animation.get_first_frame():
-          #          self.autoAnimateFrom = animation.get_first_frame()
-          #      if self.autoAnimateTo < animation.get_last_frame():
-          #          self.autoAnimateTo = animation.get_last_frame()
-            self.autoAnimateLoop = True
+
+            if (hasattr(object.data, "autoAnimate") and object.data.autoAnimate):
+                self.autoAnimate = True
+                self.autoAnimateFrom = 0
+                self.autoAnimateTo =  bpy.context.scene.frame_end - bpy.context.scene.frame_start + 1
+              #  for animation in self.animations:
+              #      if self.autoAnimateFrom > animation.get_first_frame():
+              #          self.autoAnimateFrom = animation.get_first_frame()
+              #      if self.autoAnimateTo < animation.get_last_frame():
+              #          self.autoAnimateTo = animation.get_last_frame()
+                self.autoAnimateLoop = True
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -                
     def to_scene_file(self, file_handler):     
         if (self.animationsPresent):
@@ -479,16 +481,17 @@ class FCurveAnimatable:
                 first = False
             file_handler.write(']')
             
-            write_bool(file_handler, 'autoAnimate', self.autoAnimate)
-            write_int(file_handler, 'autoAnimateFrom', self.autoAnimateFrom)
-            write_int(file_handler, 'autoAnimateTo', self.autoAnimateTo)
-            write_bool(file_handler, 'autoAnimateLoop', self.autoAnimateLoop)
+            if (hasattr(self, "autoAnimate") and self.autoAnimate):
+                write_bool(file_handler, 'autoAnimate', self.autoAnimate)
+                write_int(file_handler, 'autoAnimateFrom', self.autoAnimateFrom)
+                write_int(file_handler, 'autoAnimateTo', self.autoAnimateTo)
+                write_bool(file_handler, 'autoAnimateLoop', self.autoAnimateLoop)
 #===============================================================================
 class Mesh(FCurveAnimatable):
     def __init__(self, object, scene, multiMaterials, startFace, forcedParent, nameID):
         super().__init__(object, True, True, True)  #Should animations be done when foredParent
         
-        self.name = object.name + nameID
+        self.name = object.name + str(nameID)
         BabylonExporter.log('processing begun of mesh:  ' + self.name)
         self.isVisible = not object.hide_render
         self.isEnabled = True
@@ -744,6 +747,7 @@ class Mesh(FCurveAnimatable):
                             self.colors.append(vertex_Color.r)
                             self.colors.append(vertex_Color.g)
                             self.colors.append(vertex_Color.b)
+                            self.colors.append(1.0)
                         if hasSkeleton:
                             self.skeletonWeights.append(matricesWeights[0])
                             self.skeletonWeights.append(matricesWeights[1])
@@ -881,7 +885,7 @@ class Mesh(FCurveAnimatable):
         first = True
         file_handler.write('\n,"instances":[')
         for mesh in meshesAndNodes:
-            if mesh.dataName == self.dataName and mesh != self:  # nodes have no dataname, so no need to check for
+            if hasattr(mesh, "dataName") and mesh.dataName == self.dataName and mesh != self:  # nodes have no dataname, so no need to check for
                 if first == False:
                     file_handler.write(',')
                 file_handler.write('{')
@@ -1636,6 +1640,11 @@ def write_bool(file_handler, name, bool, noComma = False):
 #===============================================================================
 # custom properties definition and display 
 #===============================================================================
+bpy.types.Mesh.autoAnimate = bpy.props.BoolProperty(
+    name='Automatically launch animations', 
+    description='',
+    default = False
+)
 bpy.types.Mesh.useFlatShading = bpy.props.BoolProperty(
     name='Use Flat Shading', 
     description='',
@@ -1657,6 +1666,11 @@ bpy.types.Mesh.receiveShadows = bpy.props.BoolProperty(
     default = False
 )
 #===============================================================================
+bpy.types.Camera.autoAnimate = bpy.props.BoolProperty(
+    name='Automatically launch animations', 
+    description='',
+    default = False
+)
 bpy.types.Camera.CameraType = bpy.props.EnumProperty(
     name='Camera Type', 
     description='',
@@ -1695,6 +1709,11 @@ bpy.types.Camera.anaglyphEyeSpace = bpy.props.IntProperty(
     default = 1
 )    
 #===============================================================================
+bpy.types.Lamp.autoAnimate = bpy.props.BoolProperty(
+    name='Automatically launch animations', 
+    description='',
+    default = False
+)
 bpy.types.Lamp.shadowMap = bpy.props.EnumProperty(
     name='Shadow Map Type', 
     description='',
@@ -1727,6 +1746,10 @@ class ObjectPanel(bpy.types.Panel):
             layout.prop(ob.data, 'checkCollisions')     
             layout.prop(ob.data, 'castShadows')     
             layout.prop(ob.data, 'receiveShadows')   
+
+            layout.separator()
+
+            layout.prop(ob.data, 'autoAnimate')   
             
         elif isCamera:
             layout.prop(ob.data, 'CameraType')
@@ -1737,7 +1760,15 @@ class ObjectPanel(bpy.types.Panel):
             layout.separator()
             
             layout.prop(ob.data, 'anaglyphEyeSpace')
+
+            layout.separator()
+
+            layout.prop(ob.data, 'autoAnimate')   
             
         elif isLight:
             layout.prop(ob.data, 'shadowMap')
             layout.prop(ob.data, 'shadowMapSize')        
+
+            layout.separator()
+
+            layout.prop(ob.data, 'autoAnimate')   

Plik diff jest za duży
+ 389 - 32
babylon.2.0-alpha.debug.js


Plik diff jest za duży
+ 14 - 14
babylon.2.0-alpha.js


+ 54 - 4
babylon.2.0.d.ts

@@ -41,6 +41,7 @@ declare module BABYLON {
         public textureAnisotropicFilterExtension: any;
         public maxAnisotropy: number;
         public instancedArrays: any;
+        public uintIndices: boolean;
     }
     class Engine {
         private static _ALPHA_DISABLE;
@@ -97,6 +98,7 @@ declare module BABYLON {
         private _cachedEffectForVertexBuffers;
         private _currentRenderTarget;
         private _canvasClientRect;
+        private _uintIndicesCurrentlySet;
         private _workingCanvas;
         private _workingContext;
         constructor(canvas: HTMLCanvasElement, antialias?: boolean, options?: any);
@@ -255,6 +257,7 @@ interface WebGLTexture {
 interface WebGLBuffer {
     references: number;
     capacity: number;
+    is32Bits: boolean;
 }
 interface MouseEvent {
     movementX: number;
@@ -1852,6 +1855,7 @@ declare module BABYLON {
         public getTextureMatrix(): Matrix;
         public getReflectionTextureMatrix(): Matrix;
         public clone(): Texture;
+        static CreateFromBase64String(data: string, name: string, scene: Scene, noMipmap?: boolean, invertY?: boolean, samplingMode?: number, onLoad?: () => void, onError?: () => void): Texture;
     }
 }
 declare module BABYLON {
@@ -1864,6 +1868,20 @@ declare module BABYLON {
     }
 }
 declare module BABYLON {
+    class CustomProceduralTexture extends ProceduralTexture {
+        private _generateTime;
+        private _time;
+        private _shaderLoaded;
+        private _config;
+        private _texturePath;
+        constructor(name: string, texturePath: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean);
+        private loadJson(jsonUrl);
+        public render(useCameraPostProcess?: boolean): void;
+        public updateShaderUniforms(): void;
+        public generateTime : boolean;
+    }
+}
+declare module BABYLON {
     class ProceduralTexture extends Texture {
         private _size;
         public _generateMipMaps: boolean;
@@ -1890,6 +1908,7 @@ declare module BABYLON {
         constructor(name: string, size: any, fragment: any, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean);
         public isReady(): boolean;
         public resetRefreshCounter(): void;
+        public setFragment(fragment: any): void;
         public refreshRate : number;
         public _shouldRender(): boolean;
         public getRenderSize(): number;
@@ -1954,6 +1973,24 @@ declare module BABYLON {
     class RoadProceduralTexture extends ProceduralTexture {
         constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean);
     }
+    class BrickProceduralTexture extends ProceduralTexture {
+        private _numberOfBricksHeight;
+        private _numberOfBricksWidth;
+        constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean);
+        public updateShaderUniforms(): void;
+        public numberOfBricksHeight : number;
+        public cloudColor : number;
+        public numberOfBricksWidth : number;
+    }
+    class MarbleProceduralTexture extends ProceduralTexture {
+        private _numberOfBricksHeight;
+        private _numberOfBricksWidth;
+        constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean);
+        public updateShaderUniforms(): void;
+        public numberOfBricksHeight : number;
+        public cloudColor : number;
+        public numberOfBricksWidth : number;
+    }
 }
 declare module BABYLON {
     class Color3 {
@@ -2229,6 +2266,7 @@ declare module BABYLON {
         static IdentityToRef(result: Matrix): void;
         static Zero(): Matrix;
         static RotationX(angle: number): Matrix;
+        static Invert(source: Matrix): Matrix;
         static RotationXToRef(angle: number, result: Matrix): void;
         static RotationY(angle: number): Matrix;
         static RotationYToRef(angle: number, result: Matrix): void;
@@ -2286,17 +2324,26 @@ declare module BABYLON {
     class Ray {
         public origin: Vector3;
         public direction: Vector3;
+        public length: number;
         private _edge1;
         private _edge2;
         private _pvec;
         private _tvec;
         private _qvec;
-        constructor(origin: Vector3, direction: Vector3);
+        constructor(origin: Vector3, direction: Vector3, length?: number);
         public intersectsBoxMinMax(minimum: Vector3, maximum: Vector3): boolean;
         public intersectsBox(box: BoundingBox): boolean;
         public intersectsSphere(sphere: any): boolean;
         public intersectsTriangle(vertex0: Vector3, vertex1: Vector3, vertex2: Vector3): IntersectionInfo;
         static CreateNew(x: number, y: number, viewportWidth: number, viewportHeight: number, world: Matrix, view: Matrix, projection: Matrix): Ray;
+        /**
+        * Function will create a new transformed ray starting from origin and ending at the end point. Ray's length will be set, and ray will be
+        * transformed to the given world matrix.
+        * @param origin The origin point
+        * @param end The end point
+        * @param world a matrix to transform the ray to. Default is the identity matrix.
+        */
+        static CreateNewFromTo(origin: Vector3, end: Vector3, world?: Matrix): Ray;
         static Transform(ray: Ray, matrix: Matrix): Ray;
     }
     enum Space {
@@ -2343,6 +2390,7 @@ declare module BABYLON {
         public renderOutline: boolean;
         public outlineColor: Color3;
         public outlineWidth: number;
+        public hasVertexAlpha: boolean;
         public useOctreeForRenderingSelection: boolean;
         public useOctreeForPicking: boolean;
         public useOctreeForCollisions: boolean;
@@ -2415,6 +2463,8 @@ declare module BABYLON {
         public getPhysicsMass(): number;
         public getPhysicsFriction(): number;
         public getPhysicsRestitution(): number;
+        public getPositionInCameraSpace(camera?: Camera): Vector3;
+        public getDistanceToCamera(camera?: Camera): Vector3;
         public applyImpulse(force: Vector3, contactPoint: Vector3): void;
         public setPhysicsLinkWith(otherMesh: Mesh, pivot1: Vector3, pivot2: Vector3, options?: any): void;
         public updatePhysicsBodyPosition(): void;
@@ -2478,7 +2528,7 @@ declare module BABYLON {
         public getEngine(): Engine;
         public isReady(): boolean;
         public setAllVerticesData(vertexData: VertexData, updatable?: boolean): void;
-        public setVerticesData(kind: string, data: number[], updatable?: boolean): void;
+        public setVerticesData(kind: string, data: number[], updatable?: boolean, stride?: number): void;
         public updateVerticesDataDirectly(kind: string, data: Float32Array): void;
         public updateVerticesData(kind: string, data: number[], updateExtends?: boolean): void;
         public getTotalVertices(): number;
@@ -2693,7 +2743,7 @@ declare module BABYLON {
         public refreshBoundingInfo(): void;
         public _createGlobalSubMesh(): SubMesh;
         public subdivide(count: number): void;
-        public setVerticesData(kind: any, data: any, updatable?: boolean): void;
+        public setVerticesData(kind: any, data: any, updatable?: boolean, stride?: number): void;
         public updateVerticesData(kind: string, data: number[], updateExtends?: boolean, makeItUnique?: boolean): void;
         public updateVerticesDataDirectly(kind: string, data: Float32Array, makeItUnique?: boolean): void;
         public makeGeometryUnique(): void;
@@ -2848,7 +2898,7 @@ declare module BABYLON {
         private _updatable;
         private _kind;
         private _strideSize;
-        constructor(engine: any, data: number[], kind: string, updatable: boolean, postponeInternalCreation?: boolean);
+        constructor(engine: any, data: number[], kind: string, updatable: boolean, postponeInternalCreation?: boolean, stride?: number);
         public isUpdatable(): boolean;
         public getData(): number[];
         public getBuffer(): WebGLBuffer;