Browse Source

First support for SIMD.js

David Catuhe 10 năm trước cách đây
mục cha
commit
1ee600555c

+ 1 - 1
Babylon/Audio/babylon.audioengine.js

@@ -66,4 +66,4 @@ var BABYLON;
     })();
     })();
     BABYLON.AudioEngine = AudioEngine;
     BABYLON.AudioEngine = AudioEngine;
 })(BABYLON || (BABYLON = {}));
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.audioengine.js.map
+//# sourceMappingURL=babylon.audioEngine.js.map

+ 9 - 3
Babylon/Debug/babylon.debugLayer.js

@@ -56,7 +56,7 @@ var BABYLON;
                     y: evt.clientY * _this._ratio
                     y: evt.clientY * _this._ratio
                 };
                 };
             };
             };
-            this._syncData = function () {
+            this._syncUI = function () {
                 if (_this._showUI) {
                 if (_this._showUI) {
                     if (_this._displayStatistics) {
                     if (_this._displayStatistics) {
                         _this._displayStats();
                         _this._displayStats();
@@ -82,6 +82,8 @@ var BABYLON;
                         _this._treeDiv.style.display = "none";
                         _this._treeDiv.style.display = "none";
                     }
                     }
                 }
                 }
+            };
+            this._syncData = function () {
                 if (_this._labelsEnabled || !_this._showUI) {
                 if (_this._labelsEnabled || !_this._showUI) {
                     _this._camera.getViewMatrix().multiplyToRef(_this._camera.getProjectionMatrix(), _this._transformationMatrix);
                     _this._camera.getViewMatrix().multiplyToRef(_this._camera.getProjectionMatrix(), _this._transformationMatrix);
                     _this._drawingContext.clearRect(0, 0, _this._drawingCanvas.width, _this._drawingCanvas.height);
                     _this._drawingContext.clearRect(0, 0, _this._drawingCanvas.width, _this._drawingCanvas.height);
@@ -238,6 +240,7 @@ var BABYLON;
             this._enabled = false;
             this._enabled = false;
             var engine = this._scene.getEngine();
             var engine = this._scene.getEngine();
             this._scene.unregisterBeforeRender(this._syncData);
             this._scene.unregisterBeforeRender(this._syncData);
+            this._scene.unregisterAfterRender(this._syncUI);
             document.body.removeChild(this._globalDiv);
             document.body.removeChild(this._globalDiv);
             window.removeEventListener("resize", this._syncPositions);
             window.removeEventListener("resize", this._syncPositions);
             this._scene.forceShowBoundingBoxes = false;
             this._scene.forceShowBoundingBoxes = false;
@@ -282,6 +285,7 @@ var BABYLON;
             engine.getRenderingCanvas().addEventListener("click", this._onCanvasClick);
             engine.getRenderingCanvas().addEventListener("click", this._onCanvasClick);
             this._syncPositions();
             this._syncPositions();
             this._scene.registerBeforeRender(this._syncData);
             this._scene.registerBeforeRender(this._syncData);
+            this._scene.registerAfterRender(this._syncUI);
         };
         };
         DebugLayer.prototype._clearLabels = function () {
         DebugLayer.prototype._clearLabels = function () {
             this._drawingContext.clearRect(0, 0, this._drawingCanvas.width, this._drawingCanvas.height);
             this._drawingContext.clearRect(0, 0, this._drawingCanvas.width, this._drawingCanvas.height);
@@ -351,8 +355,10 @@ var BABYLON;
             if (tag === void 0) { tag = null; }
             if (tag === void 0) { tag = null; }
             var button = document.createElement("button");
             var button = document.createElement("button");
             button.innerHTML = title;
             button.innerHTML = title;
-            button.style.height = "20px";
-            button.style.color = "#222222";
+            button.style.height = "24px";
+            button.style.color = "#444444";
+            button.style.border = "1px solid white";
+            button.className = "debugLayerButton";
             button.addEventListener("click", function (evt) {
             button.addEventListener("click", function (evt) {
                 task(evt.target, tag);
                 task(evt.target, tag);
             });
             });

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
Babylon/Debug/babylon.debugLayer.js.map


+ 11 - 4
Babylon/Debug/babylon.debugLayer.ts

@@ -22,6 +22,7 @@
 
 
         private _syncPositions: () => void;
         private _syncPositions: () => void;
         private _syncData: () => void;
         private _syncData: () => void;
+        private _syncUI: () => void;
         private _onCanvasClick: (evt: MouseEvent) => void;
         private _onCanvasClick: (evt: MouseEvent) => void;
 
 
         private _clickPosition: any;
         private _clickPosition: any;
@@ -102,7 +103,7 @@
                 };
                 };
             }
             }
 
 
-            this._syncData = (): void => {
+            this._syncUI = (): void => {
                 if (this._showUI) {
                 if (this._showUI) {
                     if (this._displayStatistics) {
                     if (this._displayStatistics) {
                         this._displayStats();
                         this._displayStats();
@@ -130,7 +131,9 @@
                         this._treeDiv.style.display = "none";
                         this._treeDiv.style.display = "none";
                     }
                     }
                 }
                 }
+            }
 
 
+            this._syncData = (): void => {
                 if (this._labelsEnabled || !this._showUI) {
                 if (this._labelsEnabled || !this._showUI) {
 
 
                     this._camera.getViewMatrix().multiplyToRef(this._camera.getProjectionMatrix(), this._transformationMatrix);
                     this._camera.getViewMatrix().multiplyToRef(this._camera.getProjectionMatrix(), this._transformationMatrix);
@@ -336,6 +339,7 @@
             var engine = this._scene.getEngine();
             var engine = this._scene.getEngine();
 
 
             this._scene.unregisterBeforeRender(this._syncData);
             this._scene.unregisterBeforeRender(this._syncData);
+            this._scene.unregisterAfterRender(this._syncUI);
             document.body.removeChild(this._globalDiv);
             document.body.removeChild(this._globalDiv);
 
 
             window.removeEventListener("resize", this._syncPositions);
             window.removeEventListener("resize", this._syncPositions);
@@ -391,6 +395,7 @@
 
 
             this._syncPositions();
             this._syncPositions();
             this._scene.registerBeforeRender(this._syncData);
             this._scene.registerBeforeRender(this._syncData);
+            this._scene.registerAfterRender(this._syncUI);
         }
         }
 
 
         private _clearLabels(): void {
         private _clearLabels(): void {
@@ -477,8 +482,10 @@
         private _generateButton(root: HTMLDivElement, title: string, task: (element, tag) => void, tag: any = null): void {
         private _generateButton(root: HTMLDivElement, title: string, task: (element, tag) => void, tag: any = null): void {
             var button = document.createElement("button");
             var button = document.createElement("button");
             button.innerHTML = title;
             button.innerHTML = title;
-            button.style.height = "20px";
-            button.style.color = "#222222";
+            button.style.height = "24px";
+            button.style.color = "#444444";
+            button.style.border = "1px solid white"; 
+            button.className = "debugLayerButton";
 
 
             button.addEventListener("click",(evt: Event) => {
             button.addEventListener("click",(evt: Event) => {
                 task(evt.target, tag);
                 task(evt.target, tag);
@@ -683,7 +690,7 @@
                 }
                 }
                 this._optionsSubsetDiv.appendChild(document.createElement("br"));
                 this._optionsSubsetDiv.appendChild(document.createElement("br"));
                 this._generateTexBox(this._optionsSubsetDiv, "<b>Tools:</b>", this.accentColor);
                 this._generateTexBox(this._optionsSubsetDiv, "<b>Tools:</b>", this.accentColor);
-                this._generateButton(this._optionsSubsetDiv, "Dump rendertargets",(element) => { this._scene.dumpNextRenderTargets = true; });
+                this._generateButton(this._optionsSubsetDiv, "Dump rendertargets", (element) => { this._scene.dumpNextRenderTargets = true; });
                 this._optionsSubsetDiv.appendChild(document.createElement("br"));
                 this._optionsSubsetDiv.appendChild(document.createElement("br"));
   
   
                 this._globalDiv.appendChild(this._statsDiv);
                 this._globalDiv.appendChild(this._statsDiv);

+ 11 - 7
Babylon/Lights/Shadows/babylon.shadowGenerator.js

@@ -7,8 +7,8 @@ var BABYLON;
             this.filter = ShadowGenerator.FILTER_NONE;
             this.filter = ShadowGenerator.FILTER_NONE;
             this.blurScale = 2;
             this.blurScale = 2;
             this._blurBoxOffset = 0;
             this._blurBoxOffset = 0;
-            this._darkness = 0;
             this._bias = 0.00005;
             this._bias = 0.00005;
+            this._darkness = 0;
             this._transparencyShadow = false;
             this._transparencyShadow = false;
             this._viewMatrix = BABYLON.Matrix.Zero();
             this._viewMatrix = BABYLON.Matrix.Zero();
             this._projectionMatrix = BABYLON.Matrix.Zero();
             this._projectionMatrix = BABYLON.Matrix.Zero();
@@ -127,6 +127,16 @@ var BABYLON;
             enumerable: true,
             enumerable: true,
             configurable: true
             configurable: true
         });
         });
+        Object.defineProperty(ShadowGenerator.prototype, "bias", {
+            get: function () {
+                return this._bias;
+            },
+            set: function (bias) {
+                this._bias = bias;
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(ShadowGenerator.prototype, "blurBoxOffset", {
         Object.defineProperty(ShadowGenerator.prototype, "blurBoxOffset", {
             get: function () {
             get: function () {
                 return this._blurBoxOffset;
                 return this._blurBoxOffset;
@@ -265,12 +275,6 @@ var BABYLON;
             else
             else
                 this._darkness = darkness;
                 this._darkness = darkness;
         };
         };
-        ShadowGenerator.prototype.getBias = function () {
-            return this._bias;
-        };
-        ShadowGenerator.prototype.setBias = function (bias) {
-            this._bias = bias;
-        };
         ShadowGenerator.prototype.setTransparencyShadow = function (hasShadow) {
         ShadowGenerator.prototype.setTransparencyShadow = function (hasShadow) {
             this._transparencyShadow = hasShadow;
             this._transparencyShadow = hasShadow;
         };
         };

+ 8 - 9
Babylon/Lights/Shadows/babylon.shadowGenerator.ts

@@ -26,7 +26,15 @@
         public filter = ShadowGenerator.FILTER_NONE;
         public filter = ShadowGenerator.FILTER_NONE;
         public blurScale = 2;
         public blurScale = 2;
         private _blurBoxOffset = 0;
         private _blurBoxOffset = 0;
+        private _bias = 0.00005;
+
+        public get bias(): number {
+            return this._bias;
+        }
 
 
+        public set bias(bias: number) {
+            this._bias = bias;
+        }
         public get blurBoxOffset(): number {
         public get blurBoxOffset(): number {
             return this._blurBoxOffset;
             return this._blurBoxOffset;
         }
         }
@@ -78,7 +86,6 @@
         private _shadowMap: RenderTargetTexture;
         private _shadowMap: RenderTargetTexture;
         private _shadowMap2: RenderTargetTexture;
         private _shadowMap2: RenderTargetTexture;
         private _darkness = 0;
         private _darkness = 0;
-        private _bias = 0.00005;
         private _transparencyShadow = false;
         private _transparencyShadow = false;
         private _effect: Effect;
         private _effect: Effect;
 
 
@@ -316,14 +323,6 @@
                 this._darkness = darkness;
                 this._darkness = darkness;
         }
         }
 
 
-        public getBias(): number {
-            return this._bias;
-        }
-
-        public setBias(bias: number): void {
-            this._bias = bias;
-        }
-
         public setTransparencyShadow(hasShadow: boolean): void {
         public setTransparencyShadow(hasShadow: boolean): void {
             this._transparencyShadow = hasShadow;
             this._transparencyShadow = hasShadow;
         }
         }

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

@@ -222,7 +222,7 @@ var BABYLON;
                 shadowGenerator.useBlurVarianceShadowMap = true;
                 shadowGenerator.useBlurVarianceShadowMap = true;
             }
             }
             if (parsedShadowGenerator.bias) {
             if (parsedShadowGenerator.bias) {
-                shadowGenerator.setBias(parsedShadowGenerator.bias);
+                shadowGenerator.bias = parsedShadowGenerator.bias;
             }
             }
             return shadowGenerator;
             return shadowGenerator;
         };
         };
@@ -759,8 +759,7 @@ var BABYLON;
                     }
                     }
                 }
                 }
                 else {
                 else {
-                    if (combineArray !== null)
-                        combineArray.push(newAction);
+                    combineArray.push(newAction);
                 }
                 }
                 for (var i = 0; i < parsedAction.children.length; i++)
                 for (var i = 0; i < parsedAction.children.length; i++)
                     traverse(parsedAction.children[i], trigger, condition, newAction, null);
                     traverse(parsedAction.children[i], trigger, condition, newAction, null);

+ 2 - 3
Babylon/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -276,7 +276,7 @@
         }
         }
 
 
         if (parsedShadowGenerator.bias) {
         if (parsedShadowGenerator.bias) {
-            shadowGenerator.setBias(parsedShadowGenerator.bias);
+            shadowGenerator.bias = parsedShadowGenerator.bias;
         }
         }
 
 
         return shadowGenerator;
         return shadowGenerator;
@@ -945,8 +945,7 @@
                 }
                 }
             }
             }
             else {
             else {
-                if (combineArray !== null)
-                    combineArray.push(newAction);
+                combineArray.push(newAction);
             }
             }
 
 
             for (var i = 0; i < parsedAction.children.length; i++)
             for (var i = 0; i < parsedAction.children.length; i++)

+ 1 - 1
Babylon/Materials/babylon.standardMaterial.js

@@ -477,7 +477,7 @@ var BABYLON;
                         if (mesh.receiveShadows && shadowGenerator) {
                         if (mesh.receiveShadows && shadowGenerator) {
                             this._effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
                             this._effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
                             this._effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
                             this._effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
-                            this._effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.getShadowMap().getSize().width, shadowGenerator.getBias());
+                            this._effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
                         }
                         }
                     }
                     }
                     lightIndex++;
                     lightIndex++;

+ 1 - 1
Babylon/Materials/babylon.standardMaterial.ts

@@ -585,7 +585,7 @@
                         if (mesh.receiveShadows && shadowGenerator) {
                         if (mesh.receiveShadows && shadowGenerator) {
                             this._effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
                             this._effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
                             this._effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
                             this._effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
-                            this._effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.getShadowMap().getSize().width, shadowGenerator.getBias());
+                            this._effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
                         }
                         }
                     }
                     }
 
 

+ 22 - 0
Babylon/Math/babylon.math.js

@@ -1450,6 +1450,23 @@ var BABYLON;
             result[offset + 15] = tm12 * om3 + tm13 * om7 + tm14 * om11 + tm15 * om15;
             result[offset + 15] = tm12 * om3 + tm13 * om7 + tm14 * om11 + tm15 * om15;
             return this;
             return this;
         };
         };
+        Matrix.prototype.multiplyToArraySIMD = function (other, result, offset) {
+            if (offset === void 0) { offset = 0; }
+            var tm = this.m;
+            var om = other.m;
+            var om0 = SIMD.float32x4.load(om, 0);
+            var om1 = SIMD.float32x4.load(om, 4);
+            var om2 = SIMD.float32x4.load(om, 8);
+            var om3 = SIMD.float32x4.load(om, 12);
+            var tm0 = SIMD.float32x4.load(tm, 0);
+            SIMD.float32x4.store(result, offset + 0, SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm0, 0, 0, 0, 0), om0), SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm0, 1, 1, 1, 1), om1), SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm0, 2, 2, 2, 2), om2), SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm0, 3, 3, 3, 3), om3)))));
+            var tm1 = SIMD.float32x4.load(tm, 4);
+            SIMD.float32x4.store(result, offset + 4, SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm1, 0, 0, 0, 0), om0), SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm1, 1, 1, 1, 1), om1), SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm1, 2, 2, 2, 2), om2), SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm1, 3, 3, 3, 3), om3)))));
+            var tm2 = SIMD.float32x4.load(tm, 8);
+            SIMD.float32x4.store(result, offset + 8, SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm2, 0, 0, 0, 0), om0), SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm2, 1, 1, 1, 1), om1), SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm2, 2, 2, 2, 2), om2), SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm2, 3, 3, 3, 3), om3)))));
+            var tm3 = SIMD.float32x4.load(tm, 12);
+            SIMD.float32x4.store(result, offset + 12, SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm3, 0, 0, 0, 0), om0), SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm3, 1, 1, 1, 1), om1), SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm3, 2, 2, 2, 2), om2), SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm3, 3, 3, 3, 3), om3)))));
+        };
         Matrix.prototype.equals = function (value) {
         Matrix.prototype.equals = function (value) {
             return value && (this.m[0] === value.m[0] && this.m[1] === value.m[1] && this.m[2] === value.m[2] && this.m[3] === value.m[3] && this.m[4] === value.m[4] && this.m[5] === value.m[5] && this.m[6] === value.m[6] && this.m[7] === value.m[7] && this.m[8] === value.m[8] && this.m[9] === value.m[9] && this.m[10] === value.m[10] && this.m[11] === value.m[11] && this.m[12] === value.m[12] && this.m[13] === value.m[13] && this.m[14] === value.m[14] && this.m[15] === value.m[15]);
             return value && (this.m[0] === value.m[0] && this.m[1] === value.m[1] && this.m[2] === value.m[2] && this.m[3] === value.m[3] && this.m[4] === value.m[4] && this.m[5] === value.m[5] && this.m[6] === value.m[6] && this.m[7] === value.m[7] && this.m[8] === value.m[8] && this.m[9] === value.m[9] && this.m[10] === value.m[10] && this.m[11] === value.m[11] && this.m[12] === value.m[12] && this.m[13] === value.m[13] && this.m[14] === value.m[14] && this.m[15] === value.m[15]);
         };
         };
@@ -2490,5 +2507,10 @@ var BABYLON;
         return Path3D;
         return Path3D;
     })();
     })();
     BABYLON.Path3D = Path3D;
     BABYLON.Path3D = Path3D;
+    // SIMD
+    if (window.SIMD !== undefined) {
+        // Replace functions
+        Matrix.prototype.multiplyToArray = Matrix.prototype.multiplyToArraySIMD;
+    }
 })(BABYLON || (BABYLON = {}));
 })(BABYLON || (BABYLON = {}));
 //# sourceMappingURL=babylon.math.js.map
 //# sourceMappingURL=babylon.math.js.map

+ 54 - 1
Babylon/Math/babylon.math.ts

@@ -1,4 +1,7 @@
 module BABYLON {
 module BABYLON {
+
+    declare var SIMD;
+
     export class Color3 {
     export class Color3 {
         constructor(public r: number = 0, public g: number = 0, public b: number = 0) {
         constructor(public r: number = 0, public g: number = 0, public b: number = 0) {
         }
         }
@@ -1734,7 +1737,6 @@
         }
         }
 
 
         public multiplyToArray(other: Matrix, result: Float32Array, offset: number): Matrix {
         public multiplyToArray(other: Matrix, result: Float32Array, offset: number): Matrix {
-
             var tm0 = this.m[0];
             var tm0 = this.m[0];
             var tm1 = this.m[1];
             var tm1 = this.m[1];
             var tm2 = this.m[2];
             var tm2 = this.m[2];
@@ -1792,6 +1794,51 @@
             return this;
             return this;
         }
         }
 
 
+        public multiplyToArraySIMD(other: Matrix, result: Matrix, offset = 0): void {
+            var tm = this.m;
+            var om = other.m;
+            var om0 = SIMD.float32x4.load(om, 0);
+            var om1 = SIMD.float32x4.load(om, 4);
+            var om2 = SIMD.float32x4.load(om, 8);
+            var om3 = SIMD.float32x4.load(om, 12);
+
+            var tm0 = SIMD.float32x4.load(tm, 0);
+            SIMD.float32x4.store(result, offset + 0, SIMD.float32x4.add(
+                SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm0, 0, 0, 0, 0), om0),
+                SIMD.float32x4.add(
+                    SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm0, 1, 1, 1, 1), om1),
+                    SIMD.float32x4.add(
+                        SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm0, 2, 2, 2, 2), om2),
+                        SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm0, 3, 3, 3, 3), om3)))));
+
+            var tm1 = SIMD.float32x4.load(tm, 4);
+            SIMD.float32x4.store(result, offset + 4, SIMD.float32x4.add(
+                SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm1, 0, 0, 0, 0), om0),
+                SIMD.float32x4.add(
+                    SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm1, 1, 1, 1, 1), om1),
+                    SIMD.float32x4.add(
+                        SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm1, 2, 2, 2, 2), om2),
+                        SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm1, 3, 3, 3, 3), om3)))));
+
+            var tm2 = SIMD.float32x4.load(tm, 8);
+            SIMD.float32x4.store(result, offset + 8, SIMD.float32x4.add(
+                SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm2, 0, 0, 0, 0), om0),
+                SIMD.float32x4.add(
+                    SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm2, 1, 1, 1, 1), om1),
+                    SIMD.float32x4.add(
+                        SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm2, 2, 2, 2, 2), om2),
+                        SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm2, 3, 3, 3, 3), om3)))));
+
+            var tm3 = SIMD.float32x4.load(tm, 12);
+            SIMD.float32x4.store(result, offset + 12, SIMD.float32x4.add(
+                SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm3, 0, 0, 0, 0), om0),
+                SIMD.float32x4.add(
+                    SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm3, 1, 1, 1, 1), om1),
+                    SIMD.float32x4.add(
+                        SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm3, 2, 2, 2, 2), om2),
+                        SIMD.float32x4.mul(SIMD.float32x4.swizzle(tm3, 3, 3, 3, 3), om3)))));
+        }
+
         public equals(value: Matrix): boolean {
         public equals(value: Matrix): boolean {
             return value &&
             return value &&
                 (this.m[0] === value.m[0] && this.m[1] === value.m[1] && this.m[2] === value.m[2] && this.m[3] === value.m[3] &&
                 (this.m[0] === value.m[0] && this.m[1] === value.m[1] && this.m[2] === value.m[2] && this.m[3] === value.m[3] &&
@@ -3108,4 +3155,10 @@
             return normal0;        
             return normal0;        
         }
         }
     }
     }
+
+    // SIMD
+    if (window.SIMD !== undefined) {
+        // Replace functions
+        Matrix.prototype.multiplyToArray = <any>Matrix.prototype.multiplyToArraySIMD;
+    }
 }
 }

+ 47 - 0
Babylon/Mesh/babylon.mesh.js

@@ -951,6 +951,53 @@ var BABYLON;
             vertexData.applyToMesh(lines, updatable);
             vertexData.applyToMesh(lines, updatable);
             return lines;
             return lines;
         };
         };
+        // Extrusion
+        Mesh.ExtrudeShape = function (name, shape, path, scale, rotation, scene, updatable, sideOrientation) {
+            if (sideOrientation === void 0) { sideOrientation = Mesh.DEFAULTSIDE; }
+            scale = scale || 1;
+            rotation = rotation || 0;
+            var extruded = Mesh._ExtrudeShapeGeneric(name, shape, path, scale, rotation, null, null, false, false, false, scene, updatable, sideOrientation);
+            return extruded;
+        };
+        Mesh.ExtrudeShapeCustom = function (name, shape, path, scaleFunction, rotateFunction, ribbonCloseArray, ribbonClosePath, scene, updatable, sideOrientation) {
+            if (sideOrientation === void 0) { sideOrientation = Mesh.DEFAULTSIDE; }
+            ribbonCloseArray = ribbonCloseArray || false;
+            ribbonClosePath = ribbonClosePath || false;
+            var extrudedCustom = Mesh._ExtrudeShapeGeneric(name, shape, path, null, null, scaleFunction, rotateFunction, ribbonCloseArray, ribbonClosePath, true, scene, updatable, sideOrientation);
+            return extrudedCustom;
+        };
+        Mesh._ExtrudeShapeGeneric = function (name, shape, curve, scale, rotation, scaleFunction, rotateFunction, rbCA, rbCP, custom, scene, updtbl, side) {
+            var path3D = new BABYLON.Path3D(curve);
+            var tangents = path3D.getTangents();
+            var normals = path3D.getNormals();
+            var binormals = path3D.getBinormals();
+            var distances = path3D.getDistances();
+            var shapePaths = new Array();
+            var angle = 0;
+            var returnScale = function (i, distance) {
+                return scale;
+            };
+            var returnRotation = function (i, distance) {
+                return rotation;
+            };
+            var rotate = custom ? rotateFunction : returnRotation;
+            var scl = custom ? scaleFunction : returnScale;
+            for (var i = 0; i < curve.length; i++) {
+                var shapePath = new Array();
+                var angleStep = rotate(i, distances[i]);
+                var scaleRatio = scl(i, distances[i]);
+                var rotationMatrix = BABYLON.Matrix.RotationAxis(tangents[i], angle);
+                for (var p = 0; p < shape.length; p++) {
+                    var planed = ((tangents[i].scale(shape[p].z)).add(normals[i].scale(shape[p].x)).add(binormals[i].scale(shape[p].y)));
+                    var rotated = BABYLON.Vector3.TransformCoordinates(planed, rotationMatrix).scaleInPlace(scaleRatio).add(curve[i]);
+                    shapePath.push(rotated);
+                }
+                shapePaths.push(shapePath);
+                angle += angleStep;
+            }
+            var extrudedGeneric = Mesh.CreateRibbon(name, shapePaths, rbCA, rbCP, 0, scene, updtbl, side);
+            return extrudedGeneric;
+        };
         // Plane & ground
         // Plane & ground
         Mesh.CreatePlane = function (name, size, scene, updatable, sideOrientation) {
         Mesh.CreatePlane = function (name, size, scene, updatable, sideOrientation) {
             if (sideOrientation === void 0) { sideOrientation = Mesh.DEFAULTSIDE; }
             if (sideOrientation === void 0) { sideOrientation = Mesh.DEFAULTSIDE; }

+ 52 - 6
Babylon/Mesh/babylon.mesh.ts

@@ -766,7 +766,7 @@
 
 
                     this.delayLoadState = Engine.DELAYLOADSTATE_LOADED;
                     this.delayLoadState = Engine.DELAYLOADSTATE_LOADED;
                     scene._removePendingData(this);
                     scene._removePendingData(this);
-                },() => { }, scene.database, getBinaryData);
+                }, () => { }, scene.database, getBinaryData);
             }
             }
         }
         }
 
 
@@ -923,7 +923,7 @@
                 }
                 }
             };
             };
 
 
-            Tools.LoadImage(url, onload,() => { }, scene.database);
+            Tools.LoadImage(url, onload, () => { }, scene.database);
         }
         }
 
 
         public applyDisplacementMapFromBuffer(buffer: Uint8Array, heightMapWidth: number, heightMapHeight: number, minHeight: number, maxHeight: number): void {
         public applyDisplacementMapFromBuffer(buffer: Uint8Array, heightMapWidth: number, heightMapHeight: number, minHeight: number, maxHeight: number): void {
@@ -944,7 +944,7 @@
             for (var index = 0; index < positions.length; index += 3) {
             for (var index = 0; index < positions.length; index += 3) {
                 Vector3.FromArrayToRef(positions, index, position);
                 Vector3.FromArrayToRef(positions, index, position);
                 Vector3.FromArrayToRef(normals, index, normal);
                 Vector3.FromArrayToRef(normals, index, normal);
-                Vector2.FromArrayToRef(uvs,(index / 3) * 2, uv);
+                Vector2.FromArrayToRef(uvs, (index / 3) * 2, uv);
 
 
                 // Compute height
                 // Compute height
                 var u = ((Math.abs(uv.x) * heightMapWidth) % heightMapWidth) | 0;
                 var u = ((Math.abs(uv.x) * heightMapWidth) % heightMapWidth) | 0;
@@ -1025,8 +1025,8 @@
                 indices[index + 2] = index + 2;
                 indices[index + 2] = index + 2;
 
 
                 var p1 = Vector3.FromArray(positions, index * 3);
                 var p1 = Vector3.FromArray(positions, index * 3);
-                var p2 = Vector3.FromArray(positions,(index + 1) * 3);
-                var p3 = Vector3.FromArray(positions,(index + 2) * 3);
+                var p2 = Vector3.FromArray(positions, (index + 1) * 3);
+                var p3 = Vector3.FromArray(positions, (index + 2) * 3);
 
 
                 var p1p2 = p1.subtract(p2);
                 var p1p2 = p1.subtract(p2);
                 var p3p2 = p3.subtract(p2);
                 var p3p2 = p3.subtract(p2);
@@ -1167,6 +1167,52 @@
             return lines;
             return lines;
         }
         }
 
 
+        // Extrusion
+        public static ExtrudeShape(name: string, shape: Vector3[], path: Vector3[], scale: number, rotation: number, scene: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE): Mesh {
+            scale = scale || 1;
+            rotation = rotation || 0;
+            var extruded = Mesh._ExtrudeShapeGeneric(name, shape, path, scale, rotation, null, null, false, false, false, scene, updatable, sideOrientation);
+            return extruded;
+        }
+
+        public static ExtrudeShapeCustom(name: string, shape: Vector3[], path: Vector3[], scaleFunction, rotateFunction, ribbonCloseArray: boolean, ribbonClosePath: boolean, scene: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE): Mesh {
+            ribbonCloseArray = ribbonCloseArray || false;
+            ribbonClosePath = ribbonClosePath || false;
+            var extrudedCustom = Mesh._ExtrudeShapeGeneric(name, shape, path, null, null, scaleFunction, rotateFunction, ribbonCloseArray, ribbonClosePath, true, scene, updatable, sideOrientation);
+            return extrudedCustom;
+        }
+
+        private static _ExtrudeShapeGeneric(name: string, shape: Vector3[], curve: Vector3[], scale: number, rotation: number, scaleFunction: { (i: number, distance: number): number; }, rotateFunction: { (i: number, distance: number): number; }, rbCA: boolean, rbCP: boolean, custom: boolean, scene: Scene, updtbl: boolean, side: number): Mesh {
+            var path3D = new Path3D(curve);
+            var tangents = path3D.getTangents();
+            var normals = path3D.getNormals();
+            var binormals = path3D.getBinormals();
+            var distances = path3D.getDistances();
+            var shapePaths = new Array<Array<Vector3>>();
+            var angle = 0;
+            var returnScale: { (i: number, distance: number): number; } = function (i, distance) { return scale; };
+            var returnRotation: { (i: number, distance: number): number; } = function (i, distance) { return rotation; };
+            var rotate: { (i: number, distance: number): number; } = custom ? rotateFunction : returnRotation;
+            var scl: { (i: number, distance: number): number; } = custom ? scaleFunction : returnScale;
+
+            for (var i: number = 0; i < curve.length; i++) {
+                var shapePath = new Array<Vector3>();
+                var angleStep = rotate(i, distances[i]);
+                var scaleRatio = scl(i, distances[i]);
+                var rotationMatrix = Matrix.RotationAxis(tangents[i], angle);
+                for (var p = 0; p < shape.length; p++) {
+                    var planed = ((tangents[i].scale(shape[p].z)).add(normals[i].scale(shape[p].x)).add(binormals[i].scale(shape[p].y)));
+                    var rotated = Vector3.TransformCoordinates(planed, rotationMatrix).scaleInPlace(scaleRatio).add(curve[i]);
+                    shapePath.push(rotated);
+                }
+                shapePaths.push(shapePath);
+                angle += angleStep;
+            }
+
+            var extrudedGeneric = Mesh.CreateRibbon(name, shapePaths, rbCA, rbCP, 0, scene, updtbl, side);
+            return extrudedGeneric;
+        }
+
         // Plane & ground
         // Plane & ground
         public static CreatePlane(name: string, size: number, scene: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE): Mesh {
         public static CreatePlane(name: string, size: number, scene: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE): Mesh {
             var plane = new Mesh(name, scene);
             var plane = new Mesh(name, scene);
@@ -1233,7 +1279,7 @@
                 }
                 }
             };
             };
 
 
-            Tools.LoadImage(url, onload,() => { }, scene.database);
+            Tools.LoadImage(url, onload, () => { }, scene.database);
 
 
             return ground;
             return ground;
         }
         }

+ 0 - 1
Babylon/Physics/Plugins/babylon.cannonJSPlugin.ts

@@ -1,6 +1,5 @@
 module BABYLON {
 module BABYLON {
     declare var CANNON;
     declare var CANNON;
-    declare var window;
 
 
     export class CannonJSPlugin implements IPhysicsEnginePlugin {
     export class CannonJSPlugin implements IPhysicsEnginePlugin {
         public checkWithEpsilon: (value: number) => number;
         public checkWithEpsilon: (value: number) => number;

+ 0 - 2
Babylon/Physics/babylon.physicsEngine.ts

@@ -1,6 +1,4 @@
 module BABYLON {
 module BABYLON {
-    declare var CANNON;
-
     export interface IPhysicsEnginePlugin {
     export interface IPhysicsEnginePlugin {
         initialize(iterations?: number);
         initialize(iterations?: number);
         setGravity(gravity: Vector3): void;
         setGravity(gravity: Vector3): void;

+ 9 - 5
Babylon/Shaders/default.fragment.fx

@@ -216,7 +216,8 @@ float unpackHalf(vec2 color)
 float computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float darkness, float bias)
 float computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float darkness, float bias)
 {
 {
 	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
 	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
-	vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);
+	depth = 0.5 * depth + vec3(0.5);
+	vec2 uv = depth.xy;
 
 
 	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)
 	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)
 	{
 	{
@@ -235,7 +236,8 @@ float computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float dark
 float computeShadowWithPCF(vec4 vPositionFromLight, sampler2D shadowSampler, float mapSize, float bias)
 float computeShadowWithPCF(vec4 vPositionFromLight, sampler2D shadowSampler, float mapSize, float bias)
 {
 {
 	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
 	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
-	vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);
+	depth = 0.5 * depth + vec3(0.5);
+	vec2 uv = depth.xy;
 
 
 	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)
 	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)
 	{
 	{
@@ -262,23 +264,25 @@ float computeShadowWithPCF(vec4 vPositionFromLight, sampler2D shadowSampler, flo
 // Thanks to http://devmaster.net/
 // Thanks to http://devmaster.net/
 float ChebychevInequality(vec2 moments, float t, float bias)
 float ChebychevInequality(vec2 moments, float t, float bias)
 {
 {
+	bias = 0.02 + bias;
 	if (t <= moments.x)
 	if (t <= moments.x)
 	{
 	{
 		return 0.0;
 		return 0.0;
 	}
 	}
 
 
 	float variance = moments.y - (moments.x * moments.x);
 	float variance = moments.y - (moments.x * moments.x);
-	variance = max(variance, 0.02 + bias);
+	variance = max(variance, bias);
 
 
 	float d = t - moments.x;
 	float d = t - moments.x;
 
 
-	return clamp(variance / (variance + d * d) - 0.05, 0.0, 1.0);
+	return clamp(variance / (variance + d * d) - 0.05 - bias, 0.0, 1.0);
 }
 }
 
 
 float computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler, float bias)
 float computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler, float bias)
 {
 {
 	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
 	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
-	vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);
+	depth = 0.5 * depth + vec3(0.5);
+	vec2 uv = depth.xy;
 
 
 	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0 || depth.z > 1.0)
 	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0 || depth.z > 1.0)
 	{
 	{

+ 3 - 3
Babylon/Shaders/shadowMap.fragment.fx

@@ -35,15 +35,15 @@ void main(void)
 	if (texture2D(diffuseSampler, vUV).a < 0.4)
 	if (texture2D(diffuseSampler, vUV).a < 0.4)
 		discard;
 		discard;
 #endif
 #endif
-
-#ifdef VSM
 	float depth = vPosition.z / vPosition.w;
 	float depth = vPosition.z / vPosition.w;
+	depth = depth * 0.5 + 0.5;
 
 
+#ifdef VSM
 	float moment1 = depth;
 	float moment1 = depth;
 	float moment2 = moment1 * moment1;
 	float moment2 = moment1 * moment1;
 
 
 	gl_FragColor = vec4(packHalf(moment1), packHalf(moment2));
 	gl_FragColor = vec4(packHalf(moment1), packHalf(moment2));
 #else
 #else
-	gl_FragColor = pack(vPosition.z / vPosition.w);
+	gl_FragColor = pack(depth);
 #endif
 #endif
 }
 }

+ 80 - 14
Babylon/Tools/babylon.sceneSerializer.js

@@ -56,21 +56,89 @@ var BABYLON;
         if (camera.parent) {
         if (camera.parent) {
             serializationObject.parentId = camera.parent.id;
             serializationObject.parentId = camera.parent.id;
         }
         }
-        // Target
-        serializationObject.rotation = camera.rotation.asArray();
-        // Locked target
-        if (camera.lockedTarget && camera.lockedTarget.id) {
-            serializationObject.lockedTargetId = camera.lockedTarget.id;
-        }
         serializationObject.fov = camera.fov;
         serializationObject.fov = camera.fov;
         serializationObject.minZ = camera.minZ;
         serializationObject.minZ = camera.minZ;
         serializationObject.maxZ = camera.maxZ;
         serializationObject.maxZ = camera.maxZ;
-        serializationObject.speed = camera.speed;
         serializationObject.inertia = camera.inertia;
         serializationObject.inertia = camera.inertia;
-        serializationObject.checkCollisions = camera.checkCollisions;
-        serializationObject.applyGravity = camera.applyGravity;
-        if (camera.ellipsoid) {
-            serializationObject.ellipsoid = camera.ellipsoid.asArray();
+        //setting the type
+        if (camera instanceof BABYLON.FreeCamera) {
+            serializationObject.type = "FreeCamera";
+        }
+        else if (camera instanceof BABYLON.ArcRotateCamera) {
+            serializationObject.type = "ArcRotateCamera";
+        }
+        else if (camera instanceof BABYLON.AnaglyphArcRotateCamera) {
+            serializationObject.type = "AnaglyphArcRotateCamera";
+        }
+        else if (camera instanceof BABYLON.GamepadCamera) {
+            serializationObject.type = "GamepadCamera";
+        }
+        else if (camera instanceof BABYLON.AnaglyphFreeCamera) {
+            serializationObject.type = "AnaglyphFreeCamera";
+        }
+        else if (camera instanceof BABYLON.DeviceOrientationCamera) {
+            serializationObject.type = "DeviceOrientationCamera";
+        }
+        else if (camera instanceof BABYLON.FollowCamera) {
+            serializationObject.type = "FollowCamera";
+        }
+        else if (camera instanceof BABYLON.OculusCamera) {
+            serializationObject.type = "OculusCamera";
+        }
+        else if (camera instanceof BABYLON.OculusGamepadCamera) {
+            serializationObject.type = "OculusGamepadCamera";
+        }
+        else if (camera instanceof BABYLON.TouchCamera) {
+            serializationObject.type = "TouchCamera";
+        }
+        else if (camera instanceof BABYLON.VirtualJoysticksCamera) {
+            serializationObject.type = "VirtualJoysticksCamera";
+        }
+        else if (camera instanceof BABYLON.WebVRCamera) {
+            serializationObject.type = "WebVRCamera";
+        }
+        else if (camera instanceof BABYLON.VRDeviceOrientationCamera) {
+            serializationObject.type = "VRDeviceOrientationCamera";
+        }
+        //special properties of specific cameras
+        if (camera instanceof BABYLON.ArcRotateCamera || camera instanceof BABYLON.AnaglyphArcRotateCamera) {
+            var arcCamera = camera;
+            serializationObject.alpha = arcCamera.alpha;
+            serializationObject.beta = arcCamera.beta;
+            serializationObject.radius = arcCamera.radius;
+        }
+        else if (camera instanceof BABYLON.FollowCamera) {
+            var followCam = camera;
+            serializationObject.radius = followCam.radius;
+            serializationObject.heightOffset = followCam.heightOffset;
+            serializationObject.rotationOffset = followCam.rotationOffset;
+        }
+        else if (camera instanceof BABYLON.AnaglyphFreeCamera || camera instanceof BABYLON.AnaglyphArcRotateCamera) {
+            //eye space is a private member and can only be access like this. Without changing the implementation this is the best way to get it.
+            if (camera['_eyeSpace'] !== undefined) {
+                serializationObject.eye_space = BABYLON.Tools.ToDegrees(camera['_eyeSpace']);
+            }
+        }
+        //general properties that not all cameras have. The [] is due to typescript's type safety
+        if (camera['speed'] !== undefined) {
+            serializationObject.speed = camera['speed'];
+        }
+        // Target
+        if (camera['rotation'] && camera['rotation'] instanceof BABYLON.Vector3) {
+            serializationObject.rotation = camera['rotation'].asArray();
+        }
+        // Locked target
+        if (camera['lockedTarget'] && camera['lockedTarget'].id) {
+            serializationObject.lockedTargetId = camera['lockedTarget'].id;
+        }
+        if (camera['checkCollisions'] !== undefined) {
+            serializationObject.checkCollisions = camera['checkCollisions'];
+        }
+        if (camera['applyGravity'] !== undefined) {
+            serializationObject.applyGravity = camera['applyGravity'];
+        }
+        if (camera['ellipsoid']) {
+            serializationObject.ellipsoid = camera['ellipsoid'].asArray();
         }
         }
         // Animations
         // Animations
         appendAnimations(camera, serializationObject);
         appendAnimations(camera, serializationObject);
@@ -551,9 +619,7 @@ var BABYLON;
             serializationObject.cameras = [];
             serializationObject.cameras = [];
             for (index = 0; index < scene.cameras.length; index++) {
             for (index = 0; index < scene.cameras.length; index++) {
                 var camera = scene.cameras[index];
                 var camera = scene.cameras[index];
-                if (camera instanceof BABYLON.FreeCamera) {
-                    serializationObject.cameras.push(serializeCamera(camera));
-                }
+                serializationObject.cameras.push(serializeCamera(camera));
             }
             }
             if (scene.activeCamera) {
             if (scene.activeCamera) {
                 serializationObject.activeCameraID = scene.activeCamera.id;
                 serializationObject.activeCameraID = scene.activeCamera.id;

+ 132 - 77
Babylon/Tools/babylon.sceneSerializer.ts

@@ -1,27 +1,27 @@
 module BABYLON {
 module BABYLON {
 
 
     var serializeLight = (light: Light): any => {
     var serializeLight = (light: Light): any => {
-        var serializationObject:any = {};
+        var serializationObject: any = {};
         serializationObject.name = light.name;
         serializationObject.name = light.name;
         serializationObject.id = light.id;
         serializationObject.id = light.id;
         serializationObject.tags = Tags.GetTags(light);
         serializationObject.tags = Tags.GetTags(light);
 
 
-        if (light instanceof BABYLON.PointLight) {
+        if (light instanceof PointLight) {
             serializationObject.type = 0;
             serializationObject.type = 0;
             serializationObject.position = (<PointLight>light).position.asArray();
             serializationObject.position = (<PointLight>light).position.asArray();
-        } else if (light instanceof BABYLON.DirectionalLight) {
+        } else if (light instanceof DirectionalLight) {
             serializationObject.type = 1;
             serializationObject.type = 1;
             var directionalLight = <DirectionalLight>light;
             var directionalLight = <DirectionalLight>light;
             serializationObject.position = directionalLight.position.asArray();
             serializationObject.position = directionalLight.position.asArray();
             serializationObject.direction = directionalLight.direction.asArray();
             serializationObject.direction = directionalLight.direction.asArray();
-        } else if (light instanceof BABYLON.SpotLight) {
+        } else if (light instanceof SpotLight) {
             serializationObject.type = 2;
             serializationObject.type = 2;
             var spotLight = <SpotLight>light;
             var spotLight = <SpotLight>light;
             serializationObject.position = spotLight.position.asArray();
             serializationObject.position = spotLight.position.asArray();
             serializationObject.direction = spotLight.position.asArray();
             serializationObject.direction = spotLight.position.asArray();
             serializationObject.angle = spotLight.angle;
             serializationObject.angle = spotLight.angle;
             serializationObject.exponent = spotLight.exponent;
             serializationObject.exponent = spotLight.exponent;
-        } else if (light instanceof BABYLON.HemisphericLight) {
+        } else if (light instanceof HemisphericLight) {
             serializationObject.type = 3;
             serializationObject.type = 3;
             var hemisphericLight = <HemisphericLight>light;
             var hemisphericLight = <HemisphericLight>light;
             serializationObject.direction = hemisphericLight.direction.asArray();
             serializationObject.direction = hemisphericLight.direction.asArray();
@@ -52,8 +52,8 @@
         return serializationObject;
         return serializationObject;
     }
     }
 
 
-    var serializeCamera = (camera: FreeCamera): any => {
-        var serializationObject:any = {};
+    var serializeCamera = (camera: Camera): any => {
+        var serializationObject: any = {};
         serializationObject.name = camera.name;
         serializationObject.name = camera.name;
         serializationObject.tags = Tags.GetTags(camera);
         serializationObject.tags = Tags.GetTags(camera);
         serializationObject.id = camera.id;
         serializationObject.id = camera.id;
@@ -64,26 +64,83 @@
             serializationObject.parentId = camera.parent.id;
             serializationObject.parentId = camera.parent.id;
         }
         }
 
 
-        // Target
-        serializationObject.rotation = camera.rotation.asArray();
-
-        // Locked target
-        if (camera.lockedTarget && camera.lockedTarget.id) {
-            serializationObject.lockedTargetId = camera.lockedTarget.id;
-        }
-
         serializationObject.fov = camera.fov;
         serializationObject.fov = camera.fov;
         serializationObject.minZ = camera.minZ;
         serializationObject.minZ = camera.minZ;
         serializationObject.maxZ = camera.maxZ;
         serializationObject.maxZ = camera.maxZ;
 
 
-        serializationObject.speed = camera.speed;
         serializationObject.inertia = camera.inertia;
         serializationObject.inertia = camera.inertia;
 
 
-        serializationObject.checkCollisions = camera.checkCollisions;
-        serializationObject.applyGravity = camera.applyGravity;
+        //setting the type
+        if (camera instanceof FreeCamera) {
+            serializationObject.type = "FreeCamera";
+        } else if (camera instanceof ArcRotateCamera) {
+            serializationObject.type = "ArcRotateCamera";
+        } else if (camera instanceof AnaglyphArcRotateCamera) {
+            serializationObject.type = "AnaglyphArcRotateCamera";
+        } else if (camera instanceof GamepadCamera) {
+            serializationObject.type = "GamepadCamera";
+        } else if (camera instanceof AnaglyphFreeCamera) {
+            serializationObject.type = "AnaglyphFreeCamera";
+        } else if (camera instanceof DeviceOrientationCamera) {
+            serializationObject.type = "DeviceOrientationCamera";
+        } else if (camera instanceof FollowCamera) {
+            serializationObject.type = "FollowCamera";
+        } else if (camera instanceof OculusCamera) {
+            serializationObject.type = "OculusCamera";
+        } else if (camera instanceof OculusGamepadCamera) {
+            serializationObject.type = "OculusGamepadCamera";
+        } else if (camera instanceof TouchCamera) {
+            serializationObject.type = "TouchCamera";
+        } else if (camera instanceof VirtualJoysticksCamera) {
+            serializationObject.type = "VirtualJoysticksCamera";
+        } else if (camera instanceof WebVRCamera) {
+            serializationObject.type = "WebVRCamera";
+        } else if (camera instanceof VRDeviceOrientationCamera) {
+            serializationObject.type = "VRDeviceOrientationCamera";
+        } 
+
+        //special properties of specific cameras
+        if (camera instanceof ArcRotateCamera || camera instanceof AnaglyphArcRotateCamera) {
+            var arcCamera = <ArcRotateCamera> camera;
+            serializationObject.alpha = arcCamera.alpha;
+            serializationObject.beta = arcCamera.beta;
+            serializationObject.radius = arcCamera.radius;
+        } else if (camera instanceof FollowCamera) {
+            var followCam = <FollowCamera> camera;
+            serializationObject.radius = followCam.radius;
+            serializationObject.heightOffset = followCam.heightOffset;
+            serializationObject.rotationOffset = followCam.rotationOffset;
+        } else if (camera instanceof AnaglyphFreeCamera || camera instanceof AnaglyphArcRotateCamera) {
+            //eye space is a private member and can only be access like this. Without changing the implementation this is the best way to get it.
+            if (camera['_eyeSpace'] !== undefined) {
+                serializationObject.eye_space = Tools.ToDegrees(camera['_eyeSpace']);
+            }
+        }
+
+        //general properties that not all cameras have. The [] is due to typescript's type safety
+        if (camera['speed'] !== undefined) {
+            serializationObject.speed = camera['speed'];
+        }
+
+        // Target
+        if (camera['rotation'] && camera['rotation'] instanceof Vector3) {
+            serializationObject.rotation = camera['rotation'].asArray();
+        }
+
+        // Locked target
+        if (camera['lockedTarget'] && camera['lockedTarget'].id) {
+            serializationObject.lockedTargetId = camera['lockedTarget'].id;
+        }
+
+        if (camera['checkCollisions'] !== undefined) {
+            serializationObject.checkCollisions = camera['checkCollisions'];
+        }
+        if (camera['applyGravity'] !== undefined) {
+            serializationObject.applyGravity = camera['applyGravity'];
+        }
 
 
-        if (camera.ellipsoid) {
-            serializationObject.ellipsoid = camera.ellipsoid.asArray();
+        if (camera['ellipsoid']) {
+            serializationObject.ellipsoid = camera['ellipsoid'].asArray();
         }
         }
 
 
         // Animations
         // Animations
@@ -107,7 +164,7 @@
     };
     };
 
 
     var serializeAnimation = (animation: Animation): any => {
     var serializeAnimation = (animation: Animation): any => {
-        var serializationObject:any = {};
+        var serializationObject: any = {};
 
 
         serializationObject.name = animation.name;
         serializationObject.name = animation.name;
         serializationObject.property = animation.targetProperty;
         serializationObject.property = animation.targetProperty;
@@ -121,18 +178,18 @@
         for (var index = 0; index < keys.length; index++) {
         for (var index = 0; index < keys.length; index++) {
             var animationKey = keys[index];
             var animationKey = keys[index];
 
 
-            var key:any = {};
+            var key: any = {};
             key.frame = animationKey.frame;
             key.frame = animationKey.frame;
 
 
             switch (dataType) {
             switch (dataType) {
-            case BABYLON.Animation.ANIMATIONTYPE_FLOAT:
-                key.values = [animationKey.value];
-                break;
-            case BABYLON.Animation.ANIMATIONTYPE_QUATERNION:
-            case BABYLON.Animation.ANIMATIONTYPE_MATRIX:
-            case BABYLON.Animation.ANIMATIONTYPE_VECTOR3:
-                key.values = animationKey.value.asArray();
-                break;
+                case Animation.ANIMATIONTYPE_FLOAT:
+                    key.values = [animationKey.value];
+                    break;
+                case Animation.ANIMATIONTYPE_QUATERNION:
+                case Animation.ANIMATIONTYPE_MATRIX:
+                case Animation.ANIMATIONTYPE_VECTOR3:
+                    key.values = animationKey.value.asArray();
+                    break;
             }
             }
 
 
             serializationObject.keys.push(key);
             serializationObject.keys.push(key);
@@ -142,7 +199,7 @@
     };
     };
 
 
     var serializeMultiMaterial = (material: MultiMaterial): any => {
     var serializeMultiMaterial = (material: MultiMaterial): any => {
-        var serializationObject:any = {};
+        var serializationObject: any = {};
 
 
         serializationObject.name = material.name;
         serializationObject.name = material.name;
         serializationObject.id = material.id;
         serializationObject.id = material.id;
@@ -164,7 +221,7 @@
     };
     };
 
 
     var serializeMaterial = (material: StandardMaterial): any => {
     var serializeMaterial = (material: StandardMaterial): any => {
-        var serializationObject:any = {};
+        var serializationObject: any = {};
 
 
         serializationObject.name = material.name;
         serializationObject.name = material.name;
 
 
@@ -228,13 +285,13 @@
     };
     };
 
 
     var serializeTexture = (texture: BaseTexture): any => {
     var serializeTexture = (texture: BaseTexture): any => {
-        var serializationObject:any = {};
+        var serializationObject: any = {};
 
 
         if (!texture.name) {
         if (!texture.name) {
             return null;
             return null;
         }
         }
 
 
-        if (texture instanceof BABYLON.CubeTexture) {
+        if (texture instanceof CubeTexture) {
             serializationObject.name = texture.name;
             serializationObject.name = texture.name;
             serializationObject.hasAlpha = texture.hasAlpha;
             serializationObject.hasAlpha = texture.hasAlpha;
             serializationObject.level = texture.level;
             serializationObject.level = texture.level;
@@ -243,7 +300,7 @@
             return serializationObject;
             return serializationObject;
         }
         }
 
 
-        if (texture instanceof BABYLON.MirrorTexture) {
+        if (texture instanceof MirrorTexture) {
             var mirrorTexture = <MirrorTexture>texture;
             var mirrorTexture = <MirrorTexture>texture;
             serializationObject.renderTargetSize = mirrorTexture.getRenderSize();
             serializationObject.renderTargetSize = mirrorTexture.getRenderSize();
             serializationObject.renderList = [];
             serializationObject.renderList = [];
@@ -253,7 +310,7 @@
             }
             }
 
 
             serializationObject.mirrorPlane = mirrorTexture.mirrorPlane.asArray();
             serializationObject.mirrorPlane = mirrorTexture.mirrorPlane.asArray();
-        } else if (texture instanceof BABYLON.RenderTargetTexture) {
+        } else if (texture instanceof RenderTargetTexture) {
             var renderTargetTexture = <RenderTargetTexture>texture;
             var renderTargetTexture = <RenderTargetTexture>texture;
             serializationObject.renderTargetSize = renderTargetTexture.getRenderSize();
             serializationObject.renderTargetSize = renderTargetTexture.getRenderSize();
             serializationObject.renderList = [];
             serializationObject.renderList = [];
@@ -288,8 +345,8 @@
         return serializationObject;
         return serializationObject;
     };
     };
 
 
-    var serializeSkeleton = (skeleton:Skeleton): any => {
-        var serializationObject:any = {};
+    var serializeSkeleton = (skeleton: Skeleton): any => {
+        var serializationObject: any = {};
 
 
         serializationObject.name = skeleton.name;
         serializationObject.name = skeleton.name;
         serializationObject.id = skeleton.id;
         serializationObject.id = skeleton.id;
@@ -299,7 +356,7 @@
         for (var index = 0; index < skeleton.bones.length; index++) {
         for (var index = 0; index < skeleton.bones.length; index++) {
             var bone = skeleton.bones[index];
             var bone = skeleton.bones[index];
 
 
-            var serializedBone:any = {
+            var serializedBone: any = {
                 parentBoneIndex: bone.getParent() ? skeleton.bones.indexOf(bone.getParent()) : -1,
                 parentBoneIndex: bone.getParent() ? skeleton.bones.indexOf(bone.getParent()) : -1,
                 name: bone.name,
                 name: bone.name,
                 matrix: bone.getLocalMatrix().toArray()
                 matrix: bone.getLocalMatrix().toArray()
@@ -314,8 +371,8 @@
         return serializationObject;
         return serializationObject;
     };
     };
 
 
-    var serializeParticleSystem = (particleSystem:ParticleSystem): any => {
-        var serializationObject:any = {};
+    var serializeParticleSystem = (particleSystem: ParticleSystem): any => {
+        var serializationObject: any = {};
 
 
         serializationObject.emitterId = particleSystem.emitter.id;
         serializationObject.emitterId = particleSystem.emitter.id;
         serializationObject.capacity = particleSystem.getCapacity();
         serializationObject.capacity = particleSystem.getCapacity();
@@ -347,8 +404,8 @@
         return serializationObject;
         return serializationObject;
     };
     };
 
 
-    var serializeLensFlareSystem = (lensFlareSystem:LensFlareSystem):any => {
-        var serializationObject:any = {};
+    var serializeLensFlareSystem = (lensFlareSystem: LensFlareSystem): any => {
+        var serializationObject: any = {};
 
 
         serializationObject.emitterId = lensFlareSystem.getEmitter().id;
         serializationObject.emitterId = lensFlareSystem.getEmitter().id;
         serializationObject.borderLimit = lensFlareSystem.borderLimit;
         serializationObject.borderLimit = lensFlareSystem.borderLimit;
@@ -361,7 +418,7 @@
                 size: flare.size,
                 size: flare.size,
                 position: flare.position,
                 position: flare.position,
                 color: flare.color.asArray(),
                 color: flare.color.asArray(),
-                textureName: BABYLON.Tools.GetFilename(flare.texture.name)
+                textureName: Tools.GetFilename(flare.texture.name)
             });
             });
         }
         }
 
 
@@ -369,8 +426,8 @@
         return serializationObject;
         return serializationObject;
     };
     };
 
 
-    var serializeShadowGenerator = (light: Light):any => {
-        var serializationObject:any = {};
+    var serializeShadowGenerator = (light: Light): any => {
+        var serializationObject: any = {};
         var shadowGenerator = light.getShadowGenerator();
         var shadowGenerator = light.getShadowGenerator();
 
 
         serializationObject.lightId = light.id;
         serializationObject.lightId = light.id;
@@ -439,33 +496,33 @@
     var serializeVertexData = (vertexData: Geometry): any => {
     var serializeVertexData = (vertexData: Geometry): any => {
         var serializationObject = serializeGeometryBase(vertexData);
         var serializationObject = serializeGeometryBase(vertexData);
 
 
-        if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
-            serializationObject.positions = vertexData.getVerticesData(BABYLON.VertexBuffer.PositionKind);
+        if (vertexData.isVerticesDataPresent(VertexBuffer.PositionKind)) {
+            serializationObject.positions = vertexData.getVerticesData(VertexBuffer.PositionKind);
         }
         }
 
 
-        if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
-            serializationObject.normals = vertexData.getVerticesData(BABYLON.VertexBuffer.NormalKind);
+        if (vertexData.isVerticesDataPresent(VertexBuffer.NormalKind)) {
+            serializationObject.normals = vertexData.getVerticesData(VertexBuffer.NormalKind);
         }
         }
 
 
-        if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
-            serializationObject.uvs = vertexData.getVerticesData(BABYLON.VertexBuffer.UVKind);
+        if (vertexData.isVerticesDataPresent(VertexBuffer.UVKind)) {
+            serializationObject.uvs = vertexData.getVerticesData(VertexBuffer.UVKind);
         }
         }
 
 
-        if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
-            serializationObject.uvs2 = vertexData.getVerticesData(BABYLON.VertexBuffer.UV2Kind);
+        if (vertexData.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
+            serializationObject.uvs2 = vertexData.getVerticesData(VertexBuffer.UV2Kind);
         }
         }
 
 
-        if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
-            serializationObject.colors = vertexData.getVerticesData(BABYLON.VertexBuffer.ColorKind);
+        if (vertexData.isVerticesDataPresent(VertexBuffer.ColorKind)) {
+            serializationObject.colors = vertexData.getVerticesData(VertexBuffer.ColorKind);
         }
         }
 
 
-        if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind)) {
-            serializationObject.matricesIndices = vertexData.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
+        if (vertexData.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind)) {
+            serializationObject.matricesIndices = vertexData.getVerticesData(VertexBuffer.MatricesIndicesKind);
             serializationObject.matricesIndices._isExpanded = true;
             serializationObject.matricesIndices._isExpanded = true;
         }
         }
 
 
-        if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
-            serializationObject.matricesWeights = vertexData.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
+        if (vertexData.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {
+            serializationObject.matricesWeights = vertexData.getVerticesData(VertexBuffer.MatricesWeightsKind);
         }
         }
 
 
         serializationObject.indices = vertexData.getIndices();
         serializationObject.indices = vertexData.getIndices();
@@ -550,8 +607,8 @@
         return serializationObject;
         return serializationObject;
     };
     };
 
 
-    var serializeMesh = (mesh: Mesh, serializationScene: any):any => {
-        var serializationObject:any = {};
+    var serializeMesh = (mesh: Mesh, serializationScene: any): any => {
+        var serializationObject: any = {};
 
 
         serializationObject.name = mesh.name;
         serializationObject.name = mesh.name;
         serializationObject.id = mesh.id;
         serializationObject.id = mesh.id;
@@ -627,18 +684,18 @@
         }
         }
 
 
         // Physics
         // Physics
-        if (mesh.getPhysicsImpostor() !== BABYLON.PhysicsEngine.NoImpostor) {
+        if (mesh.getPhysicsImpostor() !== PhysicsEngine.NoImpostor) {
             serializationObject.physicsMass = mesh.getPhysicsMass();
             serializationObject.physicsMass = mesh.getPhysicsMass();
             serializationObject.physicsFriction = mesh.getPhysicsFriction();
             serializationObject.physicsFriction = mesh.getPhysicsFriction();
             serializationObject.physicsRestitution = mesh.getPhysicsRestitution();
             serializationObject.physicsRestitution = mesh.getPhysicsRestitution();
 
 
             switch (mesh.getPhysicsImpostor()) {
             switch (mesh.getPhysicsImpostor()) {
-            case BABYLON.PhysicsEngine.BoxImpostor:
-                serializationObject.physicsImpostor = 1;
-                break;
-            case BABYLON.PhysicsEngine.SphereImpostor:
-                serializationObject.physicsImpostor = 2;
-                break;
+                case PhysicsEngine.BoxImpostor:
+                    serializationObject.physicsImpostor = 1;
+                    break;
+                case PhysicsEngine.SphereImpostor:
+                    serializationObject.physicsImpostor = 2;
+                    break;
             }
             }
         }
         }
 
 
@@ -671,7 +728,7 @@
 
 
     export class SceneSerializer {
     export class SceneSerializer {
         public static Serialize(scene: Scene): any {
         public static Serialize(scene: Scene): any {
-            var serializationObject:any = {};
+            var serializationObject: any = {};
 
 
             // Scene
             // Scene
             serializationObject.useDelayedTextureLoading = scene.useDelayedTextureLoading;
             serializationObject.useDelayedTextureLoading = scene.useDelayedTextureLoading;
@@ -701,11 +758,9 @@
             serializationObject.cameras = [];
             serializationObject.cameras = [];
             for (index = 0; index < scene.cameras.length; index++) {
             for (index = 0; index < scene.cameras.length; index++) {
                 var camera = scene.cameras[index];
                 var camera = scene.cameras[index];
-
-                if (camera instanceof BABYLON.FreeCamera) {
-                    serializationObject.cameras.push(serializeCamera(<FreeCamera>camera));
-                }
+                serializationObject.cameras.push(serializeCamera(camera));
             }
             }
+
             if (scene.activeCamera) {
             if (scene.activeCamera) {
                 serializationObject.activeCameraID = scene.activeCamera.id;
                 serializationObject.activeCameraID = scene.activeCamera.id;
             }
             }
@@ -716,9 +771,9 @@
             for (index = 0; index < scene.materials.length; index++) {
             for (index = 0; index < scene.materials.length; index++) {
                 var material = scene.materials[index];
                 var material = scene.materials[index];
 
 
-                if (material instanceof BABYLON.StandardMaterial) {
+                if (material instanceof StandardMaterial) {
                     serializationObject.materials.push(serializeMaterial(<StandardMaterial>material));
                     serializationObject.materials.push(serializeMaterial(<StandardMaterial>material));
-                } else if (material instanceof BABYLON.MultiMaterial) {
+                } else if (material instanceof MultiMaterial) {
                     serializationObject.multiMaterials.push(serializeMultiMaterial(<MultiMaterial>material));
                     serializationObject.multiMaterials.push(serializeMultiMaterial(<MultiMaterial>material));
                 }
                 }
             }
             }
@@ -758,7 +813,7 @@
 
 
                 if (abstractMesh instanceof Mesh) {
                 if (abstractMesh instanceof Mesh) {
                     var mesh = <Mesh>abstractMesh;
                     var mesh = <Mesh>abstractMesh;
-                    if (mesh.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADED || mesh.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NONE) {
+                    if (mesh.delayLoadState === Engine.DELAYLOADSTATE_LOADED || mesh.delayLoadState === Engine.DELAYLOADSTATE_NONE) {
                         serializationObject.meshes.push(serializeMesh(mesh, serializationObject));
                         serializationObject.meshes.push(serializeMesh(mesh, serializationObject));
                     }
                     }
                 }
                 }

+ 1 - 1
Babylon/babylon.engine.js

@@ -546,7 +546,7 @@ var BABYLON;
         });
         });
         Object.defineProperty(Engine, "Version", {
         Object.defineProperty(Engine, "Version", {
             get: function () {
             get: function () {
-                return "2.0.0";
+                return "2.1.0 alpha";
             },
             },
             enumerable: true,
             enumerable: true,
             configurable: true
             configurable: true

+ 1 - 1
Babylon/babylon.engine.ts

@@ -431,7 +431,7 @@
         }
         }
 
 
         public static get Version(): string {
         public static get Version(): string {
-            return "2.0.0";
+            return "2.1.0 alpha";
         }
         }
 
 
         // Updatable statics so stick with vars here
         // Updatable statics so stick with vars here

+ 2 - 0
Babylon/babylon.mixins.ts

@@ -15,6 +15,8 @@ interface Window {
     oRequestAnimationFrame(func: any): any;
     oRequestAnimationFrame(func: any): any;
     WebGLRenderingContext: WebGLRenderingContext;
     WebGLRenderingContext: WebGLRenderingContext;
     MSGesture: MSGesture;
     MSGesture: MSGesture;
+    CANNON: any;
+    SIMD: any;
 }
 }
 
 
 interface HTMLURL {
 interface HTMLURL {

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 176 - 32
babylon.2.1-alpha.debug.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 19 - 19
babylon.2.1-alpha.js