瀏覽代碼

Merge pull request #9 from BabylonJS/master

update from upstream
Loïc Baumann 9 年之前
父節點
當前提交
5b355e603d
共有 57 個文件被更改,包括 4899 次插入4738 次删除
  1. 5 2
      Exporters/Unity 5/Unity3D2Babylon/SceneBuilder.Lights.cs
  2. 2 3
      Tools/Gulp/config.json
  3. 24 24
      dist/preview release/babylon.core.js
  4. 2200 2200
      dist/preview release/babylon.d.ts
  5. 39 39
      dist/preview release/babylon.js
  6. 2093 2048
      dist/preview release/babylon.max.js
  7. 38 38
      dist/preview release/babylon.noworker.js
  8. 3 0
      dist/preview release/what's new.md
  9. 16 4
      loaders/glTF/babylon.glTFFileLoader.js
  10. 9 1
      loaders/glTF/babylon.glTFFileLoader.ts
  11. 2 1
      src/.gitignore
  12. 1 9
      src/Cameras/Inputs/babylon.arcrotatecamera.input.pointers.js
  13. 2 11
      src/Cameras/Inputs/babylon.arcrotatecamera.input.pointers.ts
  14. 0 53
      src/Cameras/Inputs/babylon.freecamera.input.vrdeviceorientation.js
  15. 0 65
      src/Cameras/Inputs/babylon.freecamera.input.vrdeviceorientation.ts
  16. 5 7
      src/Cameras/VR/babylon.vrDeviceOrientationCamera.js
  17. 4 9
      src/Cameras/VR/babylon.vrDeviceOrientationCamera.ts
  18. 4 4
      src/Cameras/VR/babylon.webVRCamera.js
  19. 3 4
      src/Cameras/VR/babylon.webVRCamera.ts
  20. 0 37
      src/Cameras/babylon.anaglyphCamera.js
  21. 1 2
      src/Cameras/babylon.arcRotateCamera.ts
  22. 4 3
      src/Cameras/babylon.camera.js
  23. 4 3
      src/Cameras/babylon.camera.ts
  24. 27 20
      src/Cameras/babylon.deviceOrientationCamera.js
  25. 32 16
      src/Cameras/babylon.deviceOrientationCamera.ts
  26. 0 4
      src/Cameras/babylon.freeCameraInputsManager.js
  27. 0 5
      src/Cameras/babylon.freeCameraInputsManager.ts
  28. 1 0
      src/Canvas2d/babylon.prim2dBase.js
  29. 5 3
      src/Canvas2d/babylon.renderablePrim2d.js
  30. 1 1
      src/Canvas2d/babylon.renderablePrim2d.ts
  31. 1 0
      src/Canvas2d/babylon.sprite2d.js
  32. 1 0
      src/Canvas2d/babylon.sprite2d.ts
  33. 7 1
      src/Lights/Shadows/babylon.shadowGenerator.ts
  34. 3 3
      src/Lights/babylon.light.ts
  35. 1 0
      src/Materials/Textures/babylon.colorGradingTexture.js
  36. 1 0
      src/Materials/Textures/babylon.colorGradingTexture.ts
  37. 1 0
      src/Materials/Textures/babylon.hdrCubeTexture.js
  38. 2 1
      src/Materials/Textures/babylon.hdrCubeTexture.ts
  39. 5 1
      src/Materials/Textures/babylon.texture.js
  40. 4 1
      src/Materials/Textures/babylon.texture.ts
  41. 40 0
      src/Materials/babylon.effect.js
  42. 62 6
      src/Materials/babylon.effect.ts
  43. 2 2
      src/Materials/babylon.materialHelper.ts
  44. 6 6
      src/Materials/babylon.standardMaterial.js
  45. 7 6
      src/Materials/babylon.standardMaterial.ts
  46. 2 4
      src/Mesh/babylon.abstractMesh.js
  47. 9 9
      src/Mesh/babylon.abstractMesh.ts
  48. 19 19
      src/Particles/babylon.solidParticleSystem.js
  49. 22 22
      src/Particles/babylon.solidParticleSystem.ts
  50. 1 1
      src/Rendering/babylon.renderingGroup.ts
  51. 10 3
      src/Sprites/babylon.spriteManager.js
  52. 14 4
      src/Sprites/babylon.spriteManager.ts
  53. 1 1
      src/Tools/babylon.dynamicFloatArray.js
  54. 4 2
      src/Tools/babylon.sceneSerializer.js
  55. 4 2
      src/Tools/babylon.sceneSerializer.ts
  56. 59 11
      src/babylon.engine.js
  57. 86 17
      src/babylon.engine.ts

+ 5 - 2
Exporters/Unity 5/Unity3D2Babylon/SceneBuilder.Lights.cs

@@ -93,9 +93,12 @@ namespace Unity3D2Babylon
             ExportAnimations(light.transform, babylonLight);
 
             // Shadows
-            if ((light.type == LightType.Directional || light.type == LightType.Spot) && light.shadows != LightShadows.None)
+            if (exportationOptions.ExportShadows)
             {
-                GenerateShadowsGenerator(light);
+                if ((light.type == LightType.Directional || light.type == LightType.Spot) && light.shadows != LightShadows.None)
+                {
+                    GenerateShadowsGenerator(light);
+                }
             }
         }
     }

+ 2 - 3
Tools/Gulp/config.json

@@ -48,7 +48,6 @@
       "../../src/Cameras/Inputs/babylon.freecamera.input.keyboard.js",
       "../../src/Cameras/Inputs/babylon.freecamera.input.touch.js",
       "../../src/Cameras/Inputs/babylon.freecamera.input.deviceorientation.js",
-      "../../src/Cameras/Inputs/babylon.freecamera.input.vrdeviceorientation.js",
       "../../src/Cameras/Inputs/babylon.freecamera.input.gamepad.js",
       "../../src/Cameras/Inputs/babylon.arcrotatecamera.input.keyboard.js",
       "../../src/Cameras/Inputs/babylon.arcrotatecamera.input.mousewheel.js",
@@ -159,7 +158,7 @@
       "../../src/Materials/Textures/babylon.fontTexture.js",
       "../../src/Materials/Textures/babylon.mapTexture.js",
       "../../src/Canvas2d/babylon.bounding2d.js",
-      "../../src/Canvas2d/babylon.canvas2dLayoutEngine.js",
+      "../../src/Canvas2d/babylon.canvas2dLayoutEngine.js",
       "../../src/Canvas2d/babylon.brushes2d.js",
       "../../src/Canvas2d/babylon.smartPropertyPrim.js",
       "../../src/Canvas2d/babylon.prim2dBase.js",
@@ -191,7 +190,6 @@
       "../../src/Rendering/babylon.outlineRenderer.js",
       "../../src/Tools/babylon.assetsManager.js",
       "../../src/Cameras/VR/babylon.vrCameraMetrics.js",
-      "../../src/Cameras/VR/babylon.vrDeviceOrientationCamera.js",
       "../../src/Cameras/VR/babylon.webVRCamera.js",
       "../../src/Tools/babylon.sceneOptimizer.js",
       "../../src/Mesh/babylon.meshLODLevel.js",
@@ -209,6 +207,7 @@
       "../../src/LensFlare/babylon.lensFlare.js",
       "../../src/LensFlare/babylon.lensFlareSystem.js",
       "../../src/Cameras/babylon.deviceOrientationCamera.js",
+      "../../src/Cameras/VR/babylon.vrDeviceOrientationCamera.js",
       "../../src/Cameras/babylon.universalCamera.js",
       "../../src/Tools/babylon.gamepads.js",
       "../../src/Cameras/babylon.gamepadCamera.js",

文件差異過大導致無法顯示
+ 24 - 24
dist/preview release/babylon.core.js


文件差異過大導致無法顯示
+ 2200 - 2200
dist/preview release/babylon.d.ts


文件差異過大導致無法顯示
+ 39 - 39
dist/preview release/babylon.js


文件差異過大導致無法顯示
+ 2093 - 2048
dist/preview release/babylon.max.js


文件差異過大導致無法顯示
+ 38 - 38
dist/preview release/babylon.noworker.js


+ 3 - 0
dist/preview release/what's new.md

@@ -3,6 +3,7 @@
 ### Major updates
     
 ### Updates
+- Added support for non square textures for sprites ([deltakosh](https://github.com/deltakosh)) 
 - Added support for texture arrays ([deltakosh](https://github.com/deltakosh)) 
 - Added `camera.isInFrustum` and `camera.isCompletelyInFrustum`. Can be used with meshes, submeshes and boundingInfo ([deltakosh](https://github.com/deltakosh)) 
 - Several memory allocation reduction ([benaadams](https://github.com/benaadams))
@@ -28,6 +29,7 @@
 - Fixed some missing parameter default values in `MeshBuilder.CreateGroundFromHeightMap()` and `MeshBuilder.CreateTiledGround()` ([jerome](https://github.com/jbousquie))
 - Fixed cross vector calculation in `_computeHeightQuads()` that affected  all the `GroundMesh.getHeightAtCoordinates()` and `GroundMesh.getNormalAtCoordinates()` methods ([jerome](https://github.com/jbousquie))
 - Fixed `Mesh.CreateDashedLines()` missing `instance` parameter on update ([jerome](https://github.com/jbousquie))
+- Added BBox update on each ribbon based shape (ribbon, tube, extrusion, etc) on dynamic updates ([jerome](https://github.com/jbousquie))
 - Fixed model shape initial red vertex color set to zero not formerly being taken in account in the `SolidParticleSystem` ([jerome](https://github.com/jbousquie))
 - Fixed RenderTargetTexture meshes selection ([deltakosh](https://github.com/deltakosh))
 - Fixed camera speed computation ([deltakosh](https://github.com/deltakosh))
@@ -46,6 +48,7 @@
 	- Rendering above transparent surface is now blending correctly
 
 ### Breaking changes
+ - Removed legacy shaders support ([deltakosh](https://github.com/deltakosh))
  - Canvas2D: ([nockawa](https://github.com/nockawa))
   - `WorldSpaceCanvas2D`:
 	- WorldSpaceRenderScale is no longer supported (deprecated because of adaptive feature added).

+ 16 - 4
loaders/glTF/babylon.glTFFileLoader.js

@@ -132,7 +132,7 @@ var BABYLON;
             return this._pos >= this._maxPos;
         };
         return Tokenizer;
-    })();
+    }());
     /**
     * Values
     */
@@ -742,8 +742,14 @@ var BABYLON;
                     }
                     else if (semantic === "POSITION") {
                         tempVertexData.positions = [];
-                        for (var j = 0; j < buffer.length; j++) {
+                        var count = 3;
+                        if (GLTFFileLoader.HomogeneousCoordinates) {
+                            count = 4;
+                        }
+                        for (var j = 0; j < buffer.length; j += count) {
                             tempVertexData.positions.push(buffer[j]);
+                            tempVertexData.positions.push(buffer[j + 1]);
+                            tempVertexData.positions.push(buffer[j + 2]);
                         }
                         verticesCounts.push(tempVertexData.positions.length);
                     }
@@ -1198,7 +1204,7 @@ var BABYLON;
     var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
         return function (_) {
             prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
-            shaderMaterial.onBind = function (mat, mesh) {
+            shaderMaterial.onBind = function (mesh) {
                 onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material);
             };
         };
@@ -1375,7 +1381,9 @@ var BABYLON;
     */
     var load = function (gltfRuntime) {
         // Begin with shaders
+        var atLeastOnShader = false;
         for (var sha in gltfRuntime.shaders) {
+            atLeastOnShader = true;
             var shader = gltfRuntime.shaders[sha];
             if (shader) {
                 if (isBase64(shader.uri)) {
@@ -1390,6 +1398,9 @@ var BABYLON;
                 BABYLON.Tools.Error("No shader file named " + shader.uri);
             }
         }
+        if (!atLeastOnShader) {
+            loadBuffers(gltfRuntime);
+        }
     };
     /**
     * glTF File Loader Plugin
@@ -1552,8 +1563,9 @@ var BABYLON;
         * Static members
         */
         GLTFFileLoader.MakeYUP = false;
+        GLTFFileLoader.HomogeneousCoordinates = false;
         return GLTFFileLoader;
-    })();
+    }());
     BABYLON.GLTFFileLoader = GLTFFileLoader;
     ;
     BABYLON.SceneLoader.RegisterPlugin(new GLTFFileLoader());

+ 9 - 1
loaders/glTF/babylon.glTFFileLoader.ts

@@ -1418,7 +1418,7 @@
         return (_: Effect) => {
             prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
 
-            shaderMaterial.onBind = (mat: Material, mesh: Mesh) => {
+            shaderMaterial.onBind = (mesh: Mesh) => {
                 onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material);
             };
         };
@@ -1630,7 +1630,11 @@
     */
     var load = (gltfRuntime: IGLTFRuntime) => {
         // Begin with shaders
+        var atLeastOneShader = false;
+
         for (var sha in gltfRuntime.shaders) {
+            atLeastOneShader = true;
+
             var shader: IGLTFShader = gltfRuntime.shaders[sha];
             
             if (shader) {
@@ -1646,6 +1650,10 @@
                 Tools.Error("No shader file named " + shader.uri);
             }
         }
+
+        if (!atLeastOneShader) {
+            loadBuffers(gltfRuntime);
+        }
     };
 
     /**

+ 2 - 1
src/.gitignore

@@ -1 +1,2 @@
-*.d.ts
+*.d.ts
+.history

+ 1 - 9
src/Cameras/Inputs/babylon.arcrotatecamera.input.pointers.js

@@ -14,7 +14,6 @@ var BABYLON;
             this.pinchPrecision = 6.0;
             this.panningSensibility = 50.0;
             this._isPanClick = false;
-            this._isCtrlPushed = false;
             this.pinchInwards = true;
         }
         ArcRotateCameraPointersInput.prototype.attachControl = function (element, noPreventDefault) {
@@ -70,7 +69,7 @@ var BABYLON;
                     // One button down
                     if (pointA && pointB === undefined) {
                         if (_this.panningSensibility !== 0 &&
-                            ((_this._isCtrlPushed && _this.camera._useCtrlForPanning) ||
+                            ((evt.ctrlKey && _this.camera._useCtrlForPanning) ||
                                 (!_this.camera._useCtrlForPanning && _this._isPanClick))) {
                             _this.camera
                                 .inertialPanningX += -(evt.clientX - cacheSoloPointer.x) / _this.panningSensibility;
@@ -123,12 +122,6 @@ var BABYLON;
                 previousPinchDistance = 0;
                 cacheSoloPointer = null;
             };
-            this._onKeyDown = function (evt) {
-                _this._isCtrlPushed = evt.ctrlKey;
-            };
-            this._onKeyUp = function (evt) {
-                _this._isCtrlPushed = evt.ctrlKey;
-            };
             this._onMouseMove = function (evt) {
                 if (!engine.isPointerLock) {
                     return;
@@ -180,7 +173,6 @@ var BABYLON;
                 element.removeEventListener("keydown", this._onKeyDown);
                 element.removeEventListener("keyup", this._onKeyUp);
                 this._isPanClick = false;
-                this._isCtrlPushed = false;
                 this.pinchInwards = true;
                 this._onKeyDown = null;
                 this._onKeyUp = null;

+ 2 - 11
src/Cameras/Inputs/babylon.arcrotatecamera.input.pointers.ts

@@ -17,7 +17,6 @@ module BABYLON {
         public panningSensibility: number = 50.0;
 
         private _isPanClick: boolean = false;
-        private _isCtrlPushed: boolean = false;
         public pinchInwards = true;
 
         private _pointerInput: (p: PointerInfo, s: EventState) => void;
@@ -89,7 +88,7 @@ module BABYLON {
                     // One button down
                     if (pointA && pointB === undefined) {
                         if (this.panningSensibility !== 0 &&
-                            ((this._isCtrlPushed && this.camera._useCtrlForPanning) ||
+                            ((evt.ctrlKey && this.camera._useCtrlForPanning) ||
                                 (!this.camera._useCtrlForPanning && this._isPanClick))) {
                             this.camera
                                 .inertialPanningX += -(evt.clientX - cacheSoloPointer.x) / this.panningSensibility;
@@ -101,6 +100,7 @@ module BABYLON {
                             this.camera.inertialAlphaOffset -= offsetX / this.angularSensibilityX;
                             this.camera.inertialBetaOffset -= offsetY / this.angularSensibilityY;
                         }
+
                         cacheSoloPointer.x = evt.clientX;
                         cacheSoloPointer.y = evt.clientY;
                     }
@@ -149,14 +149,6 @@ module BABYLON {
                 cacheSoloPointer = null;
             };
 
-            this._onKeyDown = evt => {
-                this._isCtrlPushed = evt.ctrlKey;
-            };
-
-            this._onKeyUp = evt => {
-                this._isCtrlPushed = evt.ctrlKey;
-            };
-
             this._onMouseMove = evt => {
                 if (!engine.isPointerLock) {
                     return;
@@ -224,7 +216,6 @@ module BABYLON {
                 element.removeEventListener("keyup", this._onKeyUp);
 
                 this._isPanClick = false;
-                this._isCtrlPushed = false;
                 this.pinchInwards = true;
 
                 this._onKeyDown = null;

+ 0 - 53
src/Cameras/Inputs/babylon.freecamera.input.vrdeviceorientation.js

@@ -1,53 +0,0 @@
-var BABYLON;
-(function (BABYLON) {
-    var FreeCameraVRDeviceOrientationInput = (function () {
-        function FreeCameraVRDeviceOrientationInput() {
-            this.alphaCorrection = 1;
-            this.betaCorrection = 1;
-            this.gammaCorrection = 1;
-            this._alpha = 0;
-            this._beta = 0;
-            this._gamma = 0;
-            this._dirty = false;
-            this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
-        }
-        FreeCameraVRDeviceOrientationInput.prototype.attachControl = function (element, noPreventDefault) {
-            window.addEventListener("deviceorientation", this._deviceOrientationHandler);
-        };
-        FreeCameraVRDeviceOrientationInput.prototype._onOrientationEvent = function (evt) {
-            var camera = this.camera;
-            this._alpha = evt.alpha;
-            this._beta = evt.beta;
-            this._gamma = evt.gamma;
-            this._dirty = true;
-        };
-        FreeCameraVRDeviceOrientationInput.prototype.checkInputs = function () {
-            if (this._dirty) {
-                this._dirty = false;
-                var rotationX = this._gamma;
-                if (rotationX < 0) {
-                    rotationX = 90 + rotationX;
-                }
-                else {
-                    // Incline it in the correct angle.
-                    rotationX = 270 - rotationX;
-                }
-                this.camera.rotation.x = this.gammaCorrection * rotationX / 180.0 * Math.PI;
-                this.camera.rotation.y = this.alphaCorrection * -this._alpha / 180.0 * Math.PI;
-                this.camera.rotation.z = this.betaCorrection * this._beta / 180.0 * Math.PI;
-            }
-        };
-        FreeCameraVRDeviceOrientationInput.prototype.detachControl = function (element) {
-            window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
-        };
-        FreeCameraVRDeviceOrientationInput.prototype.getTypeName = function () {
-            return "FreeCameraVRDeviceOrientationInput";
-        };
-        FreeCameraVRDeviceOrientationInput.prototype.getSimpleName = function () {
-            return "VRDeviceOrientation";
-        };
-        return FreeCameraVRDeviceOrientationInput;
-    }());
-    BABYLON.FreeCameraVRDeviceOrientationInput = FreeCameraVRDeviceOrientationInput;
-    BABYLON.CameraInputTypes["FreeCameraVRDeviceOrientationInput"] = FreeCameraVRDeviceOrientationInput;
-})(BABYLON || (BABYLON = {}));

+ 0 - 65
src/Cameras/Inputs/babylon.freecamera.input.vrdeviceorientation.ts

@@ -1,65 +0,0 @@
-module BABYLON {
-    export class FreeCameraVRDeviceOrientationInput implements ICameraInput<FreeCamera> {
-        camera: FreeCamera;
-
-        public alphaCorrection = 1;
-        public betaCorrection = 1;
-        public gammaCorrection = 1;
-
-        private _alpha = 0;
-        private _beta = 0;
-        private _gamma = 0;
-        private _dirty = false;
-
-        private _offsetOrientation: { yaw: number; pitch: number; roll: number };
-        private _deviceOrientationHandler;
-
-        constructor() {
-            this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
-        }
-
-        attachControl(element: HTMLElement, noPreventDefault?: boolean) {
-            window.addEventListener("deviceorientation", this._deviceOrientationHandler);
-        }
-
-        public _onOrientationEvent(evt: DeviceOrientationEvent): void {
-            var camera = this.camera;
-            this._alpha = evt.alpha;
-            this._beta = evt.beta;
-            this._gamma = evt.gamma;
-            this._dirty = true;
-        }
-
-        public checkInputs() {
-            if (this._dirty) {
-                this._dirty = false;
-                var rotationX = this._gamma;
-                if (rotationX < 0) {
-                    rotationX = 90 + rotationX;
-                }
-                else {
-                    // Incline it in the correct angle.
-                    rotationX = 270 - rotationX;
-                }
-
-                this.camera.rotation.x = this.gammaCorrection * rotationX / 180.0 * Math.PI;
-                this.camera.rotation.y = this.alphaCorrection * -this._alpha / 180.0 * Math.PI;
-                this.camera.rotation.z = this.betaCorrection * this._beta / 180.0 * Math.PI;
-            }
-        }
-
-        detachControl(element: HTMLElement) {
-            window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
-        }
-
-        getTypeName(): string {
-            return "FreeCameraVRDeviceOrientationInput";
-        }
-
-        getSimpleName() {
-            return "VRDeviceOrientation";
-        }
-    }
-
-    CameraInputTypes["FreeCameraVRDeviceOrientationInput"] = FreeCameraVRDeviceOrientationInput;
-}

+ 5 - 7
src/Cameras/VR/babylon.vrDeviceOrientationCamera.js

@@ -7,20 +7,18 @@ var BABYLON;
 (function (BABYLON) {
     var VRDeviceOrientationFreeCamera = (function (_super) {
         __extends(VRDeviceOrientationFreeCamera, _super);
-        function VRDeviceOrientationFreeCamera(name, position, scene, compensateDistortion) {
+        function VRDeviceOrientationFreeCamera(name, position, scene, compensateDistortion, vrCameraMetrics) {
             if (compensateDistortion === void 0) { compensateDistortion = true; }
+            if (vrCameraMetrics === void 0) { vrCameraMetrics = BABYLON.VRCameraMetrics.GetDefault(); }
             _super.call(this, name, position, scene);
-            this.rotationQuaternion = new BABYLON.Quaternion();
-            var metrics = BABYLON.VRCameraMetrics.GetDefault();
-            metrics.compensateDistortion = compensateDistortion;
-            this.setCameraRigMode(BABYLON.Camera.RIG_MODE_VR, { vrCameraMetrics: metrics });
-            this.inputs.addDeviceOrientation();
+            vrCameraMetrics.compensateDistortion = compensateDistortion;
+            this.setCameraRigMode(BABYLON.Camera.RIG_MODE_VR, { vrCameraMetrics: vrCameraMetrics });
         }
         VRDeviceOrientationFreeCamera.prototype.getTypeName = function () {
             return "VRDeviceOrientationFreeCamera";
         };
         return VRDeviceOrientationFreeCamera;
-    }(BABYLON.FreeCamera));
+    }(BABYLON.DeviceOrientationCamera));
     BABYLON.VRDeviceOrientationFreeCamera = VRDeviceOrientationFreeCamera;
     var VRDeviceOrientationArcRotateCamera = (function (_super) {
         __extends(VRDeviceOrientationArcRotateCamera, _super);

+ 4 - 9
src/Cameras/VR/babylon.vrDeviceOrientationCamera.ts

@@ -1,16 +1,11 @@
 module BABYLON {
-    export class VRDeviceOrientationFreeCamera extends FreeCamera {
+    export class VRDeviceOrientationFreeCamera extends DeviceOrientationCamera {
 
-        constructor(name: string, position: Vector3, scene: Scene, compensateDistortion = true) {
+        constructor(name: string, position: Vector3, scene: Scene, compensateDistortion = true, vrCameraMetrics: VRCameraMetrics = VRCameraMetrics.GetDefault()) {
             super(name, position, scene);
 
-            this.rotationQuaternion = new Quaternion();
-
-            var metrics = VRCameraMetrics.GetDefault();
-            metrics.compensateDistortion = compensateDistortion;
-            this.setCameraRigMode(Camera.RIG_MODE_VR, { vrCameraMetrics: metrics });
-
-            this.inputs.addDeviceOrientation();
+            vrCameraMetrics.compensateDistortion = compensateDistortion;
+            this.setCameraRigMode(Camera.RIG_MODE_VR, { vrCameraMetrics: vrCameraMetrics });
         }
 
 

+ 4 - 4
src/Cameras/VR/babylon.webVRCamera.js

@@ -7,16 +7,16 @@ var BABYLON;
 (function (BABYLON) {
     var WebVRFreeCamera = (function (_super) {
         __extends(WebVRFreeCamera, _super);
-        function WebVRFreeCamera(name, position, scene, compensateDistortion) {
+        function WebVRFreeCamera(name, position, scene, compensateDistortion, vrCameraMetrics) {
             if (compensateDistortion === void 0) { compensateDistortion = true; }
+            if (vrCameraMetrics === void 0) { vrCameraMetrics = BABYLON.VRCameraMetrics.GetDefault(); }
             _super.call(this, name, position, scene);
             this._hmdDevice = null;
             this._sensorDevice = null;
             this._cacheState = null;
             this._vrEnabled = false;
-            var metrics = BABYLON.VRCameraMetrics.GetDefault();
-            metrics.compensateDistortion = compensateDistortion;
-            this.setCameraRigMode(BABYLON.Camera.RIG_MODE_VR, { vrCameraMetrics: metrics });
+            vrCameraMetrics.compensateDistortion = compensateDistortion;
+            this.setCameraRigMode(BABYLON.Camera.RIG_MODE_VR, { vrCameraMetrics: vrCameraMetrics });
             this._getWebVRDevices = this._getWebVRDevices.bind(this);
             this.rotationQuaternion = new BABYLON.Quaternion();
         }

+ 3 - 4
src/Cameras/VR/babylon.webVRCamera.ts

@@ -8,12 +8,11 @@ module BABYLON {
         private _cacheState = null;
         public _vrEnabled = false;
 
-        constructor(name: string, position: Vector3, scene: Scene, compensateDistortion = true) {
+        constructor(name: string, position: Vector3, scene: Scene, compensateDistortion = true, vrCameraMetrics: VRCameraMetrics = VRCameraMetrics.GetDefault()) {
             super(name, position, scene);
 
-            var metrics = VRCameraMetrics.GetDefault();
-            metrics.compensateDistortion = compensateDistortion;
-            this.setCameraRigMode(Camera.RIG_MODE_VR, { vrCameraMetrics: metrics });
+            vrCameraMetrics.compensateDistortion = compensateDistortion;
+            this.setCameraRigMode(Camera.RIG_MODE_VR, { vrCameraMetrics: vrCameraMetrics });
 
             this._getWebVRDevices = this._getWebVRDevices.bind(this);
 

+ 0 - 37
src/Cameras/babylon.anaglyphCamera.js

@@ -1,37 +0,0 @@
-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 AnaglyphFreeCamera = (function (_super) {
-        __extends(AnaglyphFreeCamera, _super);
-        function AnaglyphFreeCamera(name, position, eyeSpace, scene) {
-            _super.call(this, name, position, scene);
-            this.setSubCameraMode(BABYLON.Camera.SUB_CAMERA_MODE_ANAGLYPH, eyeSpace);
-        }
-        return AnaglyphFreeCamera;
-    })(BABYLON.FreeCamera);
-    BABYLON.AnaglyphFreeCamera = AnaglyphFreeCamera;
-    var AnaglyphArcRotateCamera = (function (_super) {
-        __extends(AnaglyphArcRotateCamera, _super);
-        function AnaglyphArcRotateCamera(name, alpha, beta, radius, target, eyeSpace, scene) {
-            _super.call(this, name, alpha, beta, radius, target, scene);
-            this.setSubCameraMode(BABYLON.Camera.SUB_CAMERA_MODE_ANAGLYPH, eyeSpace);
-        }
-        return AnaglyphArcRotateCamera;
-    })(BABYLON.ArcRotateCamera);
-    BABYLON.AnaglyphArcRotateCamera = AnaglyphArcRotateCamera;
-    var AnaglyphGamepadCamera = (function (_super) {
-        __extends(AnaglyphGamepadCamera, _super);
-        function AnaglyphGamepadCamera(name, position, eyeSpace, scene) {
-            _super.call(this, name, position, scene);
-            this.setSubCameraMode(BABYLON.Camera.SUB_CAMERA_MODE_ANAGLYPH, eyeSpace);
-        }
-        return AnaglyphGamepadCamera;
-    })(BABYLON.GamepadCamera);
-    BABYLON.AnaglyphGamepadCamera = AnaglyphGamepadCamera;
-})(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.anaglyphCamera.js.map

+ 1 - 2
src/Cameras/babylon.arcRotateCamera.ts

@@ -282,8 +282,7 @@
                 return;
             }
 
-            this.inputs.checkInputs();            
-			
+            this.inputs.checkInputs();
             // Inertia
             if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset !== 0) {
                 this.alpha += this.beta <= 0 ? -this.inertialAlphaOffset : this.inertialAlphaOffset;

+ 4 - 3
src/Cameras/babylon.camera.js

@@ -182,7 +182,7 @@ var BABYLON;
         };
         Camera.prototype._updateFromScene = function () {
             this.updateCache();
-            this._update();
+            this.update();
         };
         // Synchronized
         Camera.prototype._isSynchronized = function () {
@@ -222,7 +222,7 @@ var BABYLON;
         };
         Camera.prototype.detachControl = function (element) {
         };
-        Camera.prototype._update = function () {
+        Camera.prototype.update = function () {
             if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {
                 this._updateRigCameras();
             }
@@ -441,7 +441,8 @@ var BABYLON;
                     break;
             }
             this._cascadePostProcessesToRigCams();
-            this._update();
+            this.
+                update();
         };
         Camera.prototype._getVRProjectionMatrix = function () {
             BABYLON.Matrix.PerspectiveFovLHToRef(this._cameraRigParams.vrMetrics.aspectRatioFov, this._cameraRigParams.vrMetrics.aspectRatio, this.minZ, this.maxZ, this._cameraRigParams.vrWorkMatrix);

+ 4 - 3
src/Cameras/babylon.camera.ts

@@ -217,7 +217,7 @@
 
         public _updateFromScene(): void {
             this.updateCache();
-            this._update();
+            this.update();
         }
 
         // Synchronized
@@ -268,7 +268,7 @@
         public detachControl(element: HTMLElement): void {
         }
 
-        public _update(): void {
+        public update(): void {
             if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {
                 this._updateRigCameras();
             }
@@ -536,7 +536,8 @@
             }
 
             this._cascadePostProcessesToRigCams();
-            this._update();
+            this.
+                update();
         }
 
         private _getVRProjectionMatrix(): Matrix {

+ 27 - 20
src/Cameras/babylon.deviceOrientationCamera.js

@@ -8,33 +8,40 @@ var BABYLON;
     // We're mainly based on the logic defined into the FreeCamera code
     var DeviceOrientationCamera = (function (_super) {
         __extends(DeviceOrientationCamera, _super);
-        //-- end properties for backward compatibility for inputs
         function DeviceOrientationCamera(name, position, scene) {
             _super.call(this, name, position, scene);
             this.inputs.addDeviceOrientation();
         }
-        Object.defineProperty(DeviceOrientationCamera.prototype, "angularSensibility", {
-            //-- Begin properties for backward compatibility for inputs
-            get: function () {
-                return 0;
-            },
-            set: function (value) {
-            },
-            enumerable: true,
-            configurable: true
-        });
-        Object.defineProperty(DeviceOrientationCamera.prototype, "moveSensibility", {
-            get: function () {
-                return 0;
-            },
-            set: function (value) {
-            },
-            enumerable: true,
-            configurable: true
-        });
         DeviceOrientationCamera.prototype.getTypeName = function () {
             return "DeviceOrientationCamera";
         };
+        DeviceOrientationCamera.prototype._checkInputs = function () {
+            _super.prototype._checkInputs.call(this);
+            if (this._initialQuaternion) {
+                this._quaternionCache.copyFrom(this.rotationQuaternion);
+                this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
+            }
+        };
+        DeviceOrientationCamera.prototype.resetToCurrentRotation = function (axis) {
+            var _this = this;
+            if (axis === void 0) { axis = BABYLON.Axis.Y; }
+            //can only work if this camera has a rotation quaternion already.
+            if (!this.rotationQuaternion)
+                return;
+            if (!this._initialQuaternion) {
+                this._initialQuaternion = new BABYLON.Quaternion();
+            }
+            this._initialQuaternion.copyFrom(this._quaternionCache || this.rotationQuaternion);
+            ['x', 'y', 'z'].forEach(function (axisName) {
+                if (!axis[axisName]) {
+                    _this._initialQuaternion[axisName] = 0;
+                }
+                else {
+                    _this._initialQuaternion[axisName] *= -1;
+                }
+            });
+            this._initialQuaternion.normalize();
+        };
         return DeviceOrientationCamera;
     }(BABYLON.FreeCamera));
     BABYLON.DeviceOrientationCamera = DeviceOrientationCamera;

+ 32 - 16
src/Cameras/babylon.deviceOrientationCamera.ts

@@ -1,22 +1,10 @@
 module BABYLON {
     // We're mainly based on the logic defined into the FreeCamera code
     export class DeviceOrientationCamera extends FreeCamera {
-        //-- Begin properties for backward compatibility for inputs
-        public get angularSensibility() {
-            return 0;
-        }
-        
-        public set angularSensibility(value) {
-        }
-        
-        public get moveSensibility() {
-                return 0;
-        }
-        
-        public set moveSensibility(value) {
-        }
-        //-- end properties for backward compatibility for inputs
-        
+
+        private _initialQuaternion: Quaternion;
+        private _quaternionCache: Quaternion;
+
         constructor(name: string, position: Vector3, scene: Scene) {
             super(name, position, scene);
             this.inputs.addDeviceOrientation();
@@ -25,5 +13,33 @@ module BABYLON {
         public getTypeName(): string {
             return "DeviceOrientationCamera";
         }
+
+        public _checkInputs(): void {
+            super._checkInputs();
+            if (this._initialQuaternion) {
+                this._quaternionCache.copyFrom(this.rotationQuaternion);
+                this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
+            }
+        }
+
+        public resetToCurrentRotation(axis: BABYLON.Axis = BABYLON.Axis.Y) {
+            //can only work if this camera has a rotation quaternion already.
+            if (!this.rotationQuaternion) return;
+
+            if (!this._initialQuaternion) {
+                this._initialQuaternion = new BABYLON.Quaternion();
+            }
+
+            this._initialQuaternion.copyFrom(this._quaternionCache || this.rotationQuaternion);
+
+            ['x', 'y', 'z'].forEach((axisName) => {
+                if (!axis[axisName]) {
+                    this._initialQuaternion[axisName] = 0;
+                } else {
+                    this._initialQuaternion[axisName] *= -1;
+                }
+            });
+            this._initialQuaternion.normalize();
+        }
     }
 }

+ 0 - 4
src/Cameras/babylon.freeCameraInputsManager.js

@@ -27,10 +27,6 @@ var BABYLON;
             this.add(new BABYLON.FreeCameraDeviceOrientationInput());
             return this;
         };
-        FreeCameraInputsManager.prototype.addVRDeviceOrientation = function () {
-            this.add(new BABYLON.FreeCameraVRDeviceOrientationInput());
-            return this;
-        };
         FreeCameraInputsManager.prototype.addTouch = function () {
             this.add(new BABYLON.FreeCameraTouchInput());
             return this;

+ 0 - 5
src/Cameras/babylon.freeCameraInputsManager.ts

@@ -24,11 +24,6 @@ module BABYLON {
             return this;
         }
 
-        addVRDeviceOrientation(): FreeCameraInputsManager {
-            this.add(new FreeCameraVRDeviceOrientationInput());
-            return this;
-        }
-
         addTouch(): FreeCameraInputsManager {
             this.add(new FreeCameraTouchInput());
             return this;

+ 1 - 0
src/Canvas2d/babylon.prim2dBase.js

@@ -1832,6 +1832,7 @@ var BABYLON;
                 }
                 this._opacity = value;
                 this._updateRenderMode();
+                this._setFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
                 this._spreadActualOpacityChanged();
             },
             enumerable: true,

+ 5 - 3
src/Canvas2d/babylon.renderablePrim2d.js

@@ -274,7 +274,7 @@ var BABYLON;
             return this.typeInfo;
         };
         InstanceDataBase.prototype.allocElements = function () {
-            if (!this.dataBuffer) {
+            if (!this.dataBuffer || this.dataElements) {
                 return;
             }
             var res = new Array(this.dataElementCount);
@@ -603,9 +603,11 @@ var BABYLON;
             // For each Instance Data part, refresh it to update the data in the DynamicFloatArray
             for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
                 var part = _a[_i];
+                var justAllocated = false;
                 // Check if we need to allocate data elements (hidden prim which becomes visible again)
                 if (visChanged || !part.dataElements || rmChanged) {
                     part.allocElements();
+                    justAllocated = true;
                 }
                 InstanceClassInfo._CurCategories = gii.usedShaderCategories[gii.partIndexFromId.get(part.id.toString())];
                 // Will return false if the instance should not be rendered (not visible or other any reasons)
@@ -616,7 +618,7 @@ var BABYLON;
                         part.freeElements();
                     }
                 }
-                rebuildTrans = rebuildTrans || part.arrayLengthChanged;
+                rebuildTrans = rebuildTrans || part.arrayLengthChanged || justAllocated;
             }
             this._instanceDirtyFlags = 0;
             // Make the appropriate data dirty
@@ -639,7 +641,7 @@ var BABYLON;
             var maxOff = 0;
             for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
                 var part = _a[_i];
-                if (part) {
+                if (part && part.dataElements) {
                     part.dataBuffer.pack();
                     for (var _b = 0, _c = part.dataElements; _b < _c.length; _b++) {
                         var el = _c[_b];

+ 1 - 1
src/Canvas2d/babylon.renderablePrim2d.ts

@@ -287,7 +287,7 @@
         }
 
         allocElements() {
-            if (!this.dataBuffer) {
+            if (!this.dataBuffer || this.dataElements) {
                 return;
             }
             let res = new Array<DynamicFloatArrayElementInfo>(this.dataElementCount);

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

@@ -201,6 +201,7 @@ var BABYLON;
                 else {
                     texture.onLoadObservable.add(function () {
                         _this.size = texture.getSize();
+                        _this._positioningDirty();
                     });
                 }
             }

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

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

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

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

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

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

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

@@ -199,6 +199,7 @@ var BABYLON;
             var serializationObject = {};
             serializationObject.name = this.name;
             serializationObject.level = this.level;
+            serializationObject.customType = "BABYLON.ColorGradingTexture";
             return serializationObject;
         };
         /**

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

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

+ 1 - 0
src/Materials/Textures/babylon.hdrCubeTexture.js

@@ -323,6 +323,7 @@ var BABYLON;
             serializationObject.generateHarmonics = this._generateHarmonics;
             serializationObject.usePMREMGenerator = this._usePMREMGenerator;
             serializationObject.isBABYLONPreprocessed = this._isBABYLONPreprocessed;
+            serializationObject.customType = "BABYLON.HDRCubeTexture";
             return serializationObject;
         };
         /**

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

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

+ 5 - 1
src/Materials/Textures/babylon.texture.js

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

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

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

+ 40 - 0
src/Materials/babylon.effect.js

@@ -408,6 +408,46 @@ var BABYLON;
             }
             return changed;
         };
+        Effect.prototype.setIntArray = function (uniformName, array) {
+            this._valueCache[uniformName] = null;
+            this._engine.setIntArray(this.getUniform(uniformName), array);
+            return this;
+        };
+        Effect.prototype.setIntArray2 = function (uniformName, array) {
+            this._valueCache[uniformName] = null;
+            this._engine.setIntArray2(this.getUniform(uniformName), array);
+            return this;
+        };
+        Effect.prototype.setIntArray3 = function (uniformName, array) {
+            this._valueCache[uniformName] = null;
+            this._engine.setIntArray3(this.getUniform(uniformName), array);
+            return this;
+        };
+        Effect.prototype.setIntArray4 = function (uniformName, array) {
+            this._valueCache[uniformName] = null;
+            this._engine.setIntArray4(this.getUniform(uniformName), array);
+            return this;
+        };
+        Effect.prototype.setFloatArray = function (uniformName, array) {
+            this._valueCache[uniformName] = null;
+            this._engine.setFloatArray(this.getUniform(uniformName), array);
+            return this;
+        };
+        Effect.prototype.setFloatArray2 = function (uniformName, array) {
+            this._valueCache[uniformName] = null;
+            this._engine.setFloatArray2(this.getUniform(uniformName), array);
+            return this;
+        };
+        Effect.prototype.setFloatArray3 = function (uniformName, array) {
+            this._valueCache[uniformName] = null;
+            this._engine.setFloatArray3(this.getUniform(uniformName), array);
+            return this;
+        };
+        Effect.prototype.setFloatArray4 = function (uniformName, array) {
+            this._valueCache[uniformName] = null;
+            this._engine.setFloatArray4(this.getUniform(uniformName), array);
+            return this;
+        };
         Effect.prototype.setArray = function (uniformName, array) {
             this._valueCache[uniformName] = null;
             this._engine.setArray(this.getUniform(uniformName), array);

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

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

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

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

+ 6 - 6
src/Materials/babylon.standardMaterial.js

@@ -500,11 +500,7 @@ var BABYLON;
                 }
                 BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
                 BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
-                // Legacy browser patch
                 var shaderName = "default";
-                if (!scene.getEngine().getCaps().standardDerivatives) {
-                    shaderName = "legacydefault";
-                }
                 var join = this._defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vDiffuseColor", "vSpecularColor", "vEmissiveColor",
                     "vFogInfos", "vFogColor", "pointSize",
@@ -516,8 +512,12 @@ var BABYLON;
                     "logarithmicDepthConstant"
                 ];
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
-                BABYLON.ColorCurves.PrepareUniforms(uniforms);
-                BABYLON.ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers);
+                if (this._defines.CAMERACOLORCURVES) {
+                    BABYLON.ColorCurves.PrepareUniforms(uniforms);
+                }
+                if (this._defines.CAMERACOLORGRADING) {
+                    BABYLON.ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers);
+                }
                 BABYLON.MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights);
                 this._effect = scene.getEngine().createEffect(shaderName, attribs, uniforms, samplers, join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights - 1 });
             }

+ 7 - 6
src/Materials/babylon.standardMaterial.ts

@@ -657,11 +657,8 @@
                 MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
                 MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
                 
-                // Legacy browser patch
                 var shaderName = "default";
-                if (!scene.getEngine().getCaps().standardDerivatives) {
-                    shaderName = "legacydefault";
-                }
+
                 var join = this._defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vDiffuseColor", "vSpecularColor", "vEmissiveColor",
                     "vFogInfos", "vFogColor", "pointSize",
@@ -675,8 +672,12 @@
 
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"]
 
-                ColorCurves.PrepareUniforms(uniforms); 
-                ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers); 
+                if (this._defines.CAMERACOLORCURVES) {
+                    ColorCurves.PrepareUniforms(uniforms);
+                }
+                if (this._defines.CAMERACOLORGRADING) {
+                    ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers);
+                }
                 MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights);
 
                 this._effect = scene.getEngine().createEffect(shaderName,

+ 2 - 4
src/Mesh/babylon.abstractMesh.js

@@ -495,10 +495,8 @@ var BABYLON;
                 if (!this._cache.rotationQuaternion.equals(this.rotationQuaternion))
                     return false;
             }
-            else {
-                if (!this._cache.rotation.equals(this.rotation))
-                    return false;
-            }
+            if (!this._cache.rotation.equals(this.rotation))
+                return false;
             if (!this._cache.scaling.equals(this.scaling))
                 return false;
             return true;

+ 9 - 9
src/Mesh/babylon.abstractMesh.ts

@@ -125,7 +125,7 @@
         // Physics
         public physicsImpostor: BABYLON.PhysicsImpostor;
         //Deprecated, Legacy support
-        public onPhysicsCollide: (collidedMesh: AbstractMesh, contact: any) => void; 
+        public onPhysicsCollide: (collidedMesh: AbstractMesh, contact: any) => void;
 
         // Collisions
         private _checkCollisions = false;
@@ -220,8 +220,8 @@
                 ret += ", freeze wrld mat: " + (this._isWorldMatrixFrozen || this._waitingFreezeWorldMatrix ? "YES" : "NO");
             }
             return ret;
-        } 
-        
+        }
+
         /**
          * Getting the rotation object. 
          * If rotation quaternion is set, this vector will (almost always) be the Zero vector!
@@ -529,11 +529,11 @@
             if (this.rotationQuaternion) {
                 if (!this._cache.rotationQuaternion.equals(this.rotationQuaternion))
                     return false;
-            } else {
-                if (!this._cache.rotation.equals(this.rotation))
-                    return false;
             }
 
+            if (!this._cache.rotation.equals(this.rotation))
+                return false;
+
             if (!this._cache.scaling.equals(this.scaling))
                 return false;
 
@@ -602,7 +602,7 @@
             Matrix.ScalingToRef(this.scaling.x * this.scalingDeterminant, this.scaling.y * this.scalingDeterminant, this.scaling.z * this.scalingDeterminant, Tmp.Matrix[1]);
 
             // Rotation
-            
+
             //rotate, if quaternion is set and rotation was used
             if (this.rotationQuaternion) {
                 var len = this.rotation.length();
@@ -749,7 +749,7 @@
             this.position = Vector3.TransformCoordinates(vector3, this._localWorld);
         }
 
-        private static _lookAtVectorCache = new Vector3(0,0,0);
+        private static _lookAtVectorCache = new Vector3(0, 0, 0);
         public lookAt(targetPoint: Vector3, yawCor: number = 0, pitchCor: number = 0, rollCor: number = 0, space: Space = Space.LOCAL): void {
             /// <summary>Orients a mesh towards a target point. Mesh must be drawn facing user.</summary>
             /// <param name="targetPoint" type="Vector3">The position (must be in same space as current mesh) to look at</param>
@@ -1204,7 +1204,7 @@
             this.onAfterWorldMatrixUpdateObservable.clear();
             this.onCollideObservable.clear();
             this.onCollisionPositionChangeObservable.clear();
-            
+
             this._isDisposed = true;
 
             // Callback

+ 19 - 19
src/Particles/babylon.solidParticleSystem.js

@@ -59,7 +59,7 @@ var BABYLON;
             this._axisX = BABYLON.Axis.X;
             this._axisY = BABYLON.Axis.Y;
             this._axisZ = BABYLON.Axis.Z;
-            this._fakeCamPos = BABYLON.Vector3.Zero();
+            this._camDir = BABYLON.Vector3.Zero();
             this._rotMatrix = new BABYLON.Matrix();
             this._invertMatrix = new BABYLON.Matrix();
             this._rotated = BABYLON.Vector3.Zero();
@@ -426,32 +426,32 @@ var BABYLON;
             }
             // custom beforeUpdate
             this.beforeUpdateParticles(start, end, update);
-            this._cam_axisX.x = 1;
-            this._cam_axisX.y = 0;
-            this._cam_axisX.z = 0;
-            this._cam_axisY.x = 0;
-            this._cam_axisY.y = 1;
-            this._cam_axisY.z = 0;
-            this._cam_axisZ.x = 0;
-            this._cam_axisZ.y = 0;
-            this._cam_axisZ.z = 1;
+            this._cam_axisX.x = 1.0;
+            this._cam_axisX.y = 0.0;
+            this._cam_axisX.z = 0.0;
+            this._cam_axisY.x = 0.0;
+            this._cam_axisY.y = 1.0;
+            this._cam_axisY.z = 0.0;
+            this._cam_axisZ.x = 0.0;
+            this._cam_axisZ.y = 0.0;
+            this._cam_axisZ.z = 1.0;
             // if the particles will always face the camera
             if (this.billboard) {
-                // compute a fake camera position : un-rotate the camera position by the current mesh rotation
+                // compute the camera position and un-rotate it by the current mesh rotation
                 this._yaw = this.mesh.rotation.y;
                 this._pitch = this.mesh.rotation.x;
                 this._roll = this.mesh.rotation.z;
                 this._quaternionRotationYPR();
                 this._quaternionToRotationMatrix();
                 this._rotMatrix.invertToRef(this._invertMatrix);
-                BABYLON.Vector3.TransformCoordinatesToRef(this._camera.globalPosition, this._invertMatrix, this._fakeCamPos);
-                // set two orthogonal vectors (_cam_axisX and and _cam_axisY) to the cam-mesh axis (_cam_axisZ)
-                (this._fakeCamPos).subtractToRef(this.mesh.position, this._cam_axisZ);
+                this._camera._currentTarget.subtractToRef(this._camera.globalPosition, this._camDir);
+                BABYLON.Vector3.TransformCoordinatesToRef(this._camDir, this._invertMatrix, this._cam_axisZ);
+                this._cam_axisZ.normalize();
+                // set two orthogonal vectors (_cam_axisX and and _cam_axisY) to the rotated camDir axis (_cam_axisZ)
                 BABYLON.Vector3.CrossToRef(this._cam_axisZ, this._axisX, this._cam_axisY);
-                BABYLON.Vector3.CrossToRef(this._cam_axisZ, this._cam_axisY, this._cam_axisX);
+                BABYLON.Vector3.CrossToRef(this._cam_axisY, this._cam_axisZ, this._cam_axisX);
                 this._cam_axisY.normalize();
                 this._cam_axisX.normalize();
-                this._cam_axisZ.normalize();
             }
             BABYLON.Matrix.IdentityToRef(this._rotMatrix);
             var idx = 0;
@@ -479,7 +479,7 @@ var BABYLON;
                         this._particle.rotation.x = 0.0;
                         this._particle.rotation.y = 0.0;
                     }
-                    if (this._computeParticleRotation) {
+                    if (this._computeParticleRotation || this.billboard) {
                         if (this._particle.rotationQuaternion) {
                             this._quaternion.copyFrom(this._particle.rotationQuaternion);
                         }
@@ -534,7 +534,7 @@ var BABYLON;
                             }
                         }
                         // normals : if the particles can't be morphed then just rotate the normals, what if much more faster than ComputeNormals()
-                        if (!this._computeParticleVertex && !this.billboard) {
+                        if (!this._computeParticleVertex) {
                             this._normal.x = this._fixedNormal32[idx];
                             this._normal.y = this._fixedNormal32[idx + 1];
                             this._normal.z = this._fixedNormal32[idx + 2];
@@ -596,7 +596,7 @@ var BABYLON;
                 }
                 this.mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, this._positions32, false, false);
                 if (!this.mesh.areNormalsFrozen) {
-                    if (this._computeParticleVertex || this.billboard) {
+                    if (this._computeParticleVertex) {
                         // recompute the normals only if the particles can be morphed, update then also the normal reference array _fixedNormal32[]
                         BABYLON.VertexData.ComputeNormals(this._positions32, this._indices, this._normals32);
                         for (var i = 0; i < this._normals32.length; i++) {

+ 22 - 22
src/Particles/babylon.solidParticleSystem.ts

@@ -78,9 +78,9 @@
         private _axisX: Vector3 = Axis.X;
         private _axisY: Vector3 = Axis.Y;
         private _axisZ: Vector3 = Axis.Z;
-        private _camera: Camera;
+        private _camera: TargetCamera;
         private _particle: SolidParticle;
-        private _fakeCamPos: Vector3 = Vector3.Zero();
+        private _camDir: Vector3 = Vector3.Zero();
         private _rotMatrix: Matrix = new Matrix();
         private _invertMatrix: Matrix = new Matrix();
         private _rotated: Vector3 = Vector3.Zero();
@@ -114,7 +114,7 @@
         constructor(name: string, scene: Scene, options?: { updatable?: boolean; isPickable?: boolean }) {
             this.name = name;
             this._scene = scene;
-            this._camera = scene.activeCamera;
+            this._camera = <TargetCamera>scene.activeCamera;
             this._pickable = options ? options.isPickable : false;
             if (options && options.updatable) {
                 this._updatable = options.updatable;
@@ -493,36 +493,36 @@
             // custom beforeUpdate
             this.beforeUpdateParticles(start, end, update);
 
-            this._cam_axisX.x = 1;
-            this._cam_axisX.y = 0;
-            this._cam_axisX.z = 0;
+            this._cam_axisX.x = 1.0;
+            this._cam_axisX.y = 0.0;
+            this._cam_axisX.z = 0.0;
 
-            this._cam_axisY.x = 0;
-            this._cam_axisY.y = 1;
-            this._cam_axisY.z = 0;
+            this._cam_axisY.x = 0.0;
+            this._cam_axisY.y = 1.0;
+            this._cam_axisY.z = 0.0;
 
-            this._cam_axisZ.x = 0;
-            this._cam_axisZ.y = 0;
-            this._cam_axisZ.z = 1;
+            this._cam_axisZ.x = 0.0;
+            this._cam_axisZ.y = 0.0;
+            this._cam_axisZ.z = 1.0;
 
             // if the particles will always face the camera
             if (this.billboard) {
-                // compute a fake camera position : un-rotate the camera position by the current mesh rotation
+                // compute the camera position and un-rotate it by the current mesh rotation
                 this._yaw = this.mesh.rotation.y;
                 this._pitch = this.mesh.rotation.x;
                 this._roll = this.mesh.rotation.z;
                 this._quaternionRotationYPR();
                 this._quaternionToRotationMatrix();
                 this._rotMatrix.invertToRef(this._invertMatrix);
-                Vector3.TransformCoordinatesToRef(this._camera.globalPosition, this._invertMatrix, this._fakeCamPos);
+                this._camera._currentTarget.subtractToRef(this._camera.globalPosition, this._camDir);
+                Vector3.TransformCoordinatesToRef(this._camDir, this._invertMatrix, this._cam_axisZ);
+                this._cam_axisZ.normalize();
 
-                // set two orthogonal vectors (_cam_axisX and and _cam_axisY) to the cam-mesh axis (_cam_axisZ)
-                (this._fakeCamPos).subtractToRef(this.mesh.position, this._cam_axisZ);
+                // set two orthogonal vectors (_cam_axisX and and _cam_axisY) to the rotated camDir axis (_cam_axisZ)
                 Vector3.CrossToRef(this._cam_axisZ, this._axisX, this._cam_axisY);
-                Vector3.CrossToRef(this._cam_axisZ, this._cam_axisY, this._cam_axisX);
+                Vector3.CrossToRef(this._cam_axisY, this._cam_axisZ, this._cam_axisX);
                 this._cam_axisY.normalize();
-                this._cam_axisX.normalize();
-                this._cam_axisZ.normalize();
+                this._cam_axisX.normalize();             
             }
 
             Matrix.IdentityToRef(this._rotMatrix);
@@ -556,7 +556,7 @@
                         this._particle.rotation.x = 0.0;
                         this._particle.rotation.y = 0.0;
                     }
-                    if (this._computeParticleRotation) {
+                    if (this._computeParticleRotation || this.billboard) {
                         if (this._particle.rotationQuaternion) {
                             this._quaternion.copyFrom(this._particle.rotationQuaternion);
                         } else {
@@ -618,7 +618,7 @@
                         }
 
                         // normals : if the particles can't be morphed then just rotate the normals, what if much more faster than ComputeNormals()
-                        if (!this._computeParticleVertex && !this.billboard) {
+                        if (!this._computeParticleVertex) {
                             this._normal.x = this._fixedNormal32[idx];
                             this._normal.y = this._fixedNormal32[idx + 1];
                             this._normal.z = this._fixedNormal32[idx + 2];
@@ -688,7 +688,7 @@
                 }
                 this.mesh.updateVerticesData(VertexBuffer.PositionKind, this._positions32, false, false);
                 if (!this.mesh.areNormalsFrozen) {
-                    if (this._computeParticleVertex || this.billboard) {
+                    if (this._computeParticleVertex) {
                         // recompute the normals only if the particles can be morphed, update then also the normal reference array _fixedNormal32[]
                         VertexData.ComputeNormals(this._positions32, this._indices, this._normals32);
                         for (var i = 0; i < this._normals32.length; i++) {

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

@@ -1,6 +1,6 @@
 module BABYLON {
     export class RenderingGroup {
-        private _scene: Scene
+        private _scene: Scene;
         private _opaqueSubMeshes = new SmartArray<SubMesh>(256);
         private _transparentSubMeshes = new SmartArray<SubMesh>(256);
         private _alphaTestSubMeshes = new SmartArray<SubMesh>(256);

+ 10 - 3
src/Sprites/babylon.spriteManager.js

@@ -4,7 +4,6 @@ var BABYLON;
         function SpriteManager(name, imgUrl, capacity, cellSize, scene, epsilon, samplingMode) {
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             this.name = name;
-            this.cellSize = cellSize;
             this.sprites = new Array();
             this.renderingGroupId = 0;
             this.layerMask = 0x0FFFFFFF;
@@ -21,6 +20,14 @@ var BABYLON;
             this._spriteTexture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._spriteTexture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._epsilon = epsilon === undefined ? 0.01 : epsilon;
+            if (cellSize.width) {
+                this.cellWidth = cellSize.width;
+                this.cellHeight = cellSize.height;
+            }
+            else {
+                this.cellWidth = cellSize;
+                this.cellHeight = cellSize;
+            }
             this._scene = scene;
             this._scene.spriteManagers.push(this);
             var indices = [];
@@ -153,7 +160,7 @@ var BABYLON;
             // Sprites
             var deltaTime = engine.getDeltaTime();
             var max = Math.min(this._capacity, this.sprites.length);
-            var rowSize = baseSize.width / this.cellSize;
+            var rowSize = baseSize.width / this.cellWidth;
             var offset = 0;
             for (var index = 0; index < max; index++) {
                 var sprite = this.sprites[index];
@@ -177,7 +184,7 @@ var BABYLON;
             effect.setTexture("diffuseSampler", this._spriteTexture);
             effect.setMatrix("view", viewMatrix);
             effect.setMatrix("projection", this._scene.getProjectionMatrix());
-            effect.setFloat2("textureInfos", this.cellSize / baseSize.width, this.cellSize / baseSize.height);
+            effect.setFloat2("textureInfos", this.cellWidth / baseSize.width, this.cellHeight / baseSize.height);
             // Fog
             if (this._scene.fogEnabled && this._scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
                 effect.setFloat4("vFogInfos", this._scene.fogMode, this._scene.fogStart, this._scene.fogEnd, this._scene.fogDensity);

+ 14 - 4
src/Sprites/babylon.spriteManager.ts

@@ -5,6 +5,8 @@
         public layerMask: number = 0x0FFFFFFF;
         public fogEnabled = true;
         public isPickable = false;
+        public cellWidth: number;
+        public cellHeight: number;
 
         /**
         * An event triggered when the manager is disposed.
@@ -41,7 +43,7 @@
             this._spriteTexture = value;
         }
 
-        constructor(public name: string, imgUrl: string, capacity: number, public cellSize: number, scene: Scene, epsilon?: number, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) {
+        constructor(public name: string, imgUrl: string, capacity: number, cellSize: any, scene: Scene, epsilon?: number, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) {
             this._capacity = capacity;
             this._spriteTexture = new Texture(imgUrl, scene, true, false, samplingMode);
             this._spriteTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
@@ -49,6 +51,14 @@
 
             this._epsilon = epsilon === undefined ? 0.01 : epsilon;
 
+            if (cellSize.width) {
+                this.cellWidth = cellSize.width;
+                this.cellHeight = cellSize.height;
+            } else {
+                this.cellWidth = cellSize;
+                this.cellHeight = cellSize;
+            }
+
             this._scene = scene;
             this._scene.spriteManagers.push(this);
 
@@ -173,7 +183,7 @@
 
                 result.hit = true;
                 result.pickedSprite = currentSprite;
-                result.distance = distance
+                result.distance = distance;
 
                 return result;
             }
@@ -192,7 +202,7 @@
             // Sprites
             var deltaTime = engine.getDeltaTime();
             var max = Math.min(this._capacity, this.sprites.length);
-            var rowSize = baseSize.width / this.cellSize;
+            var rowSize = baseSize.width / this.cellWidth;
 
             var offset = 0;
             for (var index = 0; index < max; index++) {
@@ -224,7 +234,7 @@
             effect.setMatrix("view", viewMatrix);
             effect.setMatrix("projection", this._scene.getProjectionMatrix());
 
-            effect.setFloat2("textureInfos", this.cellSize / baseSize.width, this.cellSize / baseSize.height);
+            effect.setFloat2("textureInfos", this.cellWidth / baseSize.width, this.cellHeight / baseSize.height);
 
             // Fog
             if (this._scene.fogEnabled && this._scene.fogMode !== Scene.FOGMODE_NONE && this.fogEnabled) {

+ 1 - 1
src/Tools/babylon.dynamicFloatArray.js

@@ -226,7 +226,7 @@ var BABYLON;
                 var newCount = Math.min(this.totalElementCount, count * 2);
                 this._sortTable = new Array(newCount);
             }
-            if (!this._sortTable || this._sortTable.length !== count) {
+            if (!this._sortedTable || this._sortedTable.length !== count) {
                 this._sortedTable = new Array(count);
             }
             // Because, you know...

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

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

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

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

+ 59 - 11
src/babylon.engine.js

@@ -164,10 +164,15 @@ var BABYLON;
             this._renderingCanvas = canvas;
             this._externalData = new BABYLON.StringDictionary();
             options = options || {};
-            options.antialias = antialias;
+            if (antialias != null) {
+                options.antialias = antialias;
+            }
             if (options.preserveDrawingBuffer === undefined) {
                 options.preserveDrawingBuffer = false;
             }
+            // Checks if some of the format renders first to allow the use of webgl inspector.
+            var renderToFullFloat = this._canRenderToFloatTexture();
+            var renderToHalfFloat = this._canRenderToHalfFloatTexture();
             // GL
             //try {
             //    this._gl = <WebGLRenderingContext>(canvas.getContext("webgl2", options) || canvas.getContext("experimental-webgl2", options));
@@ -232,10 +237,10 @@ var BABYLON;
             this._caps.drawBuffersExtension = this._gl.getExtension('WEBGL_draw_buffers');
             this._caps.textureFloatLinearFiltering = this._gl.getExtension('OES_texture_float_linear');
             this._caps.textureLOD = this._gl.getExtension('EXT_shader_texture_lod');
-            this._caps.textureFloatRender = this._canRenderToFloatTexture();
+            this._caps.textureFloatRender = renderToFullFloat;
             this._caps.textureHalfFloat = (this._gl.getExtension('OES_texture_half_float') !== null);
             this._caps.textureHalfFloatLinearFiltering = this._gl.getExtension('OES_texture_half_float_linear');
-            this._caps.textureHalfFloatRender = this._canRenderToHalfFloatTexture();
+            this._caps.textureHalfFloatRender = renderToHalfFloat;
             if (this._gl.getShaderPrecisionFormat) {
                 var highp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
                 this._caps.highPrecisionShaderSupported = highp.precision !== 0;
@@ -1136,6 +1141,46 @@ var BABYLON;
                 effect.onBind(effect);
             }
         };
+        Engine.prototype.setIntArray = function (uniform, array) {
+            if (!uniform)
+                return;
+            this._gl.uniform1iv(uniform, array);
+        };
+        Engine.prototype.setIntArray2 = function (uniform, array) {
+            if (!uniform || array.length % 2 !== 0)
+                return;
+            this._gl.uniform2iv(uniform, array);
+        };
+        Engine.prototype.setIntArray3 = function (uniform, array) {
+            if (!uniform || array.length % 3 !== 0)
+                return;
+            this._gl.uniform3iv(uniform, array);
+        };
+        Engine.prototype.setIntArray4 = function (uniform, array) {
+            if (!uniform || array.length % 4 !== 0)
+                return;
+            this._gl.uniform4iv(uniform, array);
+        };
+        Engine.prototype.setFloatArray = function (uniform, array) {
+            if (!uniform)
+                return;
+            this._gl.uniform1fv(uniform, array);
+        };
+        Engine.prototype.setFloatArray2 = function (uniform, array) {
+            if (!uniform || array.length % 2 !== 0)
+                return;
+            this._gl.uniform2fv(uniform, array);
+        };
+        Engine.prototype.setFloatArray3 = function (uniform, array) {
+            if (!uniform || array.length % 3 !== 0)
+                return;
+            this._gl.uniform3fv(uniform, array);
+        };
+        Engine.prototype.setFloatArray4 = function (uniform, array) {
+            if (!uniform || array.length % 4 !== 0)
+                return;
+            this._gl.uniform4fv(uniform, array);
+        };
         Engine.prototype.setArray = function (uniform, array) {
             if (!uniform)
                 return;
@@ -1588,11 +1633,11 @@ var BABYLON;
                 if (options.samplingMode !== undefined) {
                     samplingMode = options.samplingMode;
                 }
-                if (type === BABYLON.Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
+                if (type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
                     // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
                     samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE;
                 }
-                else if (type === BABYLON.Engine.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {
+                else if (type === Engine.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {
                     // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE
                     samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE;
                 }
@@ -2177,6 +2222,12 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Engine.prototype.attachContextLostEvent = function (callback) {
+            this._renderingCanvas.addEventListener("webglcontextlost", callback, false);
+        };
+        Engine.prototype.attachContextRestoredEvent = function (callback) {
+            this._renderingCanvas.addEventListener("webglcontextrestored", callback, false);
+        };
         // FPS
         Engine.prototype.getFps = function () {
             return this.fps;
@@ -2203,15 +2254,9 @@ var BABYLON;
             }
         };
         Engine.prototype._canRenderToFloatTexture = function () {
-            if (!this.getCaps().textureFloat) {
-                return false;
-            }
             return this._canRenderToTextureOfType(BABYLON.Engine.TEXTURETYPE_FLOAT, 'OES_texture_float');
         };
         Engine.prototype._canRenderToHalfFloatTexture = function () {
-            if (!this.getCaps().textureHalfFloat) {
-                return false;
-            }
             return this._canRenderToTextureOfType(BABYLON.Engine.TEXTURETYPE_HALF_FLOAT, 'OES_texture_half_float');
         };
         // Thank you : http://stackoverflow.com/questions/28827511/webgl-ios-render-to-floating-point-texture
@@ -2222,6 +2267,9 @@ var BABYLON;
             var gl = (tempcanvas.getContext("webgl") || tempcanvas.getContext("experimental-webgl"));
             // extension.
             var ext = gl.getExtension(extension);
+            if (!ext) {
+                return false;
+            }
             // setup GLSL program
             var vertexCode = "attribute vec4 a_position;\n                void main() {\n                    gl_Position = a_position;\n                }";
             var fragmentCode = "precision mediump float;\n                uniform vec4 u_color;\n                uniform sampler2D u_texture;\n\n                void main() {\n                    gl_FragColor = texture2D(u_texture, vec2(0.5, 0.5)) * u_color;\n                }";

+ 86 - 17
src/babylon.engine.ts

@@ -183,6 +183,10 @@
         public textureLOD: boolean;
         public drawBuffersExtension;
     }
+    
+    export interface EngineOptions extends WebGLContextAttributes{
+        limitDeviceRatio?: number;
+    }
 
     /**
      * The engine class is responsible for interfacing with all lower-level APIs such as WebGL and Audio.
@@ -383,19 +387,25 @@
          * @param {boolean} [antialias] - enable antialias
          * @param options - further options to be sent to the getContext function
          */
-        constructor(canvas: HTMLCanvasElement, antialias?: boolean, options?: { antialias?: boolean, preserveDrawingBuffer?: boolean, limitDeviceRatio?: number }, adaptToDeviceRatio = true) {
+        constructor(canvas: HTMLCanvasElement, antialias?: boolean, options?: EngineOptions, adaptToDeviceRatio = true) {
             this._renderingCanvas = canvas;
 
             this._externalData = new StringDictionary<Object>();
 
             options = options || {};
-            options.antialias = antialias;
 
+            if(antialias != null){
+                options.antialias = antialias;
+            }
 
             if (options.preserveDrawingBuffer === undefined) {
                 options.preserveDrawingBuffer = false;
             }
 
+            // Checks if some of the format renders first to allow the use of webgl inspector.
+            var renderToFullFloat = this._canRenderToFloatTexture();
+            var renderToHalfFloat = this._canRenderToHalfFloatTexture();
+
             // GL
             //try {
             //    this._gl = <WebGLRenderingContext>(canvas.getContext("webgl2", options) || canvas.getContext("experimental-webgl2", options));
@@ -471,11 +481,11 @@
             this._caps.drawBuffersExtension = this._gl.getExtension('WEBGL_draw_buffers');
             this._caps.textureFloatLinearFiltering = this._gl.getExtension('OES_texture_float_linear');
             this._caps.textureLOD = this._gl.getExtension('EXT_shader_texture_lod');
-            this._caps.textureFloatRender = this._canRenderToFloatTexture();
+            this._caps.textureFloatRender = renderToFullFloat;
 
             this._caps.textureHalfFloat = (this._gl.getExtension('OES_texture_half_float') !== null);
             this._caps.textureHalfFloatLinearFiltering = this._gl.getExtension('OES_texture_half_float_linear');
-            this._caps.textureHalfFloatRender = this._canRenderToHalfFloatTexture();
+            this._caps.textureHalfFloatRender = renderToHalfFloat;
 
             if (this._gl.getShaderPrecisionFormat) {
                 var highp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
@@ -1366,6 +1376,62 @@
             }
         }
 
+        public setIntArray(uniform: WebGLUniformLocation, array: Int32Array): void {
+            if (!uniform)
+                return;
+
+            this._gl.uniform1iv(uniform, array);
+        }
+
+        public setIntArray2(uniform: WebGLUniformLocation, array: Int32Array): void {
+            if (!uniform || array.length % 2 !== 0)
+                return;
+
+            this._gl.uniform2iv(uniform, array);
+        }
+
+        public setIntArray3(uniform: WebGLUniformLocation, array: Int32Array): void {
+            if (!uniform || array.length % 3 !== 0)
+                return;
+
+            this._gl.uniform3iv(uniform, array);
+        }
+
+        public setIntArray4(uniform: WebGLUniformLocation, array: Int32Array): void {
+            if (!uniform || array.length % 4 !== 0)
+                return;
+
+            this._gl.uniform4iv(uniform, array);
+        }
+
+        public setFloatArray(uniform: WebGLUniformLocation, array: Float32Array): void {
+            if (!uniform)
+                return;
+
+            this._gl.uniform1fv(uniform, array);
+        }
+
+        public setFloatArray2(uniform: WebGLUniformLocation, array: Float32Array): void {
+            if (!uniform || array.length % 2 !== 0)
+                return;
+
+            this._gl.uniform2fv(uniform, array);
+        }
+
+        public setFloatArray3(uniform: WebGLUniformLocation, array: Float32Array): void {
+            if (!uniform || array.length % 3 !== 0)
+                return;
+
+            this._gl.uniform3fv(uniform, array);
+        }
+
+        public setFloatArray4(uniform: WebGLUniformLocation, array: Float32Array): void {
+            if (!uniform || array.length % 4 !== 0)
+                return;
+
+            this._gl.uniform4fv(uniform, array);
+        }
+
         public setArray(uniform: WebGLUniformLocation, array: number[]): void {
             if (!uniform)
                 return;
@@ -1905,13 +1971,13 @@
                 if (options.samplingMode !== undefined) {
                     samplingMode = options.samplingMode;
                 }
-                if (type === BABYLON.Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
+                if (type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
                     // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
-                    samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE;
+                    samplingMode = Texture.NEAREST_SAMPLINGMODE;
                 }
-                else if (type === BABYLON.Engine.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {
+                else if (type === Engine.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {
                     // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE
-                    samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE;
+                    samplingMode = Texture.NEAREST_SAMPLINGMODE;
                 }
             }
             var gl = this._gl;
@@ -2617,6 +2683,14 @@
             this._loadingScreen.loadingUIBackgroundColor = color;
         }
 
+        public attachContextLostEvent(callback: ((event: WebGLContextEvent) => void)): void {
+            this._renderingCanvas.addEventListener("webglcontextlost", callback, false);
+        }
+
+        public attachContextRestoredEvent(callback: ((event: WebGLContextEvent) => void)): void {
+            this._renderingCanvas.addEventListener("webglcontextrestored", callback, false);
+        }
+
         // FPS
         public getFps(): number {
             return this.fps;
@@ -2651,18 +2725,10 @@
         }
 
         private _canRenderToFloatTexture(): boolean {
-            if (!this.getCaps().textureFloat) {
-                return false;
-            }
-
             return this._canRenderToTextureOfType(BABYLON.Engine.TEXTURETYPE_FLOAT, 'OES_texture_float');
         }
 
         private _canRenderToHalfFloatTexture(): boolean {
-            if (!this.getCaps().textureHalfFloat) {
-                return false;
-            }
-
             return this._canRenderToTextureOfType(BABYLON.Engine.TEXTURETYPE_HALF_FLOAT, 'OES_texture_half_float');
         }
 
@@ -2675,6 +2741,9 @@
 
             // extension.
             var ext = gl.getExtension(extension);
+            if (!ext) {
+                return false;
+            }
 
             // setup GLSL program
             var vertexCode = `attribute vec4 a_position;
@@ -2784,4 +2853,4 @@
             }
         }
     }
-}
+}