Przeglądaj źródła

Moving to beta stage

David Catuhe 10 lat temu
rodzic
commit
7efb3eadb7
100 zmienionych plików z 4731 dodań i 818 usunięć
  1. 20 8
      Babylon/Actions/babylon.action.js
  2. 41 3
      Babylon/Actions/babylon.actionManager.js
  3. 17 6
      Babylon/Actions/babylon.condition.js
  4. 23 3
      Babylon/Actions/babylon.directActions.js
  5. 17 15
      Babylon/Actions/babylon.interpolateValueAction.js
  6. 23 8
      Babylon/Animations/babylon.animatable.js
  7. 80 16
      Babylon/Animations/babylon.animation.js
  8. 35 16
      Babylon/Animations/babylon.easing.js
  9. 103 0
      Babylon/Audio/babylon.analyser.js
  10. 111 0
      Babylon/Audio/babylon.analyser.ts
  11. 17 10
      Babylon/Audio/babylon.audioengine.js
  12. 8 0
      Babylon/Audio/babylon.audioengine.ts
  13. 80 55
      Babylon/Audio/babylon.sound.js
  14. 43 35
      Babylon/Audio/babylon.sound.ts
  15. 7 4
      Babylon/Audio/babylon.soundtrack.js
  16. 20 6
      Babylon/Bones/babylon.bone.js
  17. 21 4
      Babylon/Bones/babylon.skeleton.js
  18. 30 4
      Babylon/Cameras/VR/babylon.oculusCamera.js
  19. 35 4
      Babylon/Cameras/VR/babylon.oculusGamepadCamera.js
  20. 4 3
      Babylon/Cameras/VR/babylon.vrDeviceOrientationCamera.js
  21. 13 3
      Babylon/Cameras/VR/babylon.webVRCamera.js
  22. 29 2
      Babylon/Cameras/babylon.anaglyphCamera.js
  23. 104 13
      Babylon/Cameras/babylon.arcRotateCamera.js
  24. 71 9
      Babylon/Cameras/babylon.camera.js
  25. 12 1
      Babylon/Cameras/babylon.deviceOrientationCamera.js
  26. 11 3
      Babylon/Cameras/babylon.followCamera.js
  27. 42 14
      Babylon/Cameras/babylon.freeCamera.js
  28. 6 1
      Babylon/Cameras/babylon.gamepadCamera.js
  29. 42 12
      Babylon/Cameras/babylon.targetCamera.js
  30. 26 3
      Babylon/Cameras/babylon.touchCamera.js
  31. 3 2
      Babylon/Cameras/babylon.virtualJoysticksCamera.js
  32. 72 6
      Babylon/Collisions/babylon.collider.js
  33. 12 2
      Babylon/Collisions/babylon.pickingInfo.js
  34. 23 7
      Babylon/Culling/Octrees/babylon.octree.js
  35. 24 6
      Babylon/Culling/Octrees/babylon.octreeBlock.js
  36. 40 5
      Babylon/Culling/babylon.boundingBox.js
  37. 26 3
      Babylon/Culling/babylon.boundingInfo.js
  38. 14 2
      Babylon/Culling/babylon.boundingSphere.js
  39. 122 14
      Babylon/Debug/babylon.debugLayer.js
  40. 1 1
      Babylon/Debug/babylon.debugLayer.js.map
  41. 20 2
      Babylon/Layer/babylon.layer.js
  42. 4 2
      Babylon/LensFlare/babylon.lensFlare.js
  43. 56 11
      Babylon/LensFlare/babylon.lensFlareSystem.js
  44. 52 7
      Babylon/Lights/Shadows/babylon.shadowGenerator.js
  45. 14 2
      Babylon/Lights/babylon.directionalLight.js
  46. 6 2
      Babylon/Lights/babylon.hemisphericLight.js
  47. 18 2
      Babylon/Lights/babylon.light.js
  48. 10 2
      Babylon/Lights/babylon.pointLight.js
  49. 16 4
      Babylon/Lights/babylon.spotLight.js
  50. 324 76
      Babylon/Loading/Plugins/babylon.babylonFileLoader.js
  51. 36 9
      Babylon/Loading/babylon.sceneLoader.js
  52. 29 13
      Babylon/Materials/Textures/Procedurals/babylon.customProceduralTexture.js
  53. 72 5
      Babylon/Materials/Textures/Procedurals/babylon.proceduralTexture.js
  54. 55 2
      Babylon/Materials/Textures/Procedurals/babylon.standardProceduralTexture.js
  55. 32 2
      Babylon/Materials/Textures/babylon.baseTexture.js
  56. 16 4
      Babylon/Materials/Textures/babylon.cubeTexture.js
  57. 29 8
      Babylon/Materials/Textures/babylon.dynamicTexture.js
  58. 12 2
      Babylon/Materials/Textures/babylon.mirrorTexture.js
  59. 26 20
      Babylon/Materials/Textures/babylon.rawTexture.js
  60. 39 3
      Babylon/Materials/Textures/babylon.renderTargetTexture.js
  61. 42 13
      Babylon/Materials/Textures/babylon.texture.js
  62. 14 3
      Babylon/Materials/Textures/babylon.videoTexture.js
  63. 102 16
      Babylon/Materials/babylon.effect.js
  64. 28 2
      Babylon/Materials/babylon.material.js
  65. 6 2
      Babylon/Materials/babylon.multiMaterial.js
  66. 49 2
      Babylon/Materials/babylon.shaderMaterial.js
  67. 157 35
      Babylon/Materials/babylon.standardMaterial.js
  68. 582 36
      Babylon/Math/babylon.math.js
  69. 38 2
      Babylon/Mesh/babylon.InstancedMesh.js
  70. 185 33
      Babylon/Mesh/babylon.abstractMesh.js
  71. 88 15
      Babylon/Mesh/babylon.csg.js
  72. 133 14
      Babylon/Mesh/babylon.geometry.js
  73. 9 2
      Babylon/Mesh/babylon.groundMesh.js
  74. 16 3
      Babylon/Mesh/babylon.linesMesh.js
  75. 289 39
      Babylon/Mesh/babylon.mesh.js
  76. 201 7
      Babylon/Mesh/babylon.mesh.vertexData.js
  77. 4 4
      Babylon/Mesh/babylon.meshLODLevel.js
  78. 1 1
      Babylon/Mesh/babylon.meshSimplification.ts
  79. 36 13
      Babylon/Mesh/babylon.polygonmesh.js
  80. 42 6
      Babylon/Mesh/babylon.subMesh.js
  81. 29 8
      Babylon/Mesh/babylon.vertexBuffer.js
  82. 2 2
      Babylon/Particles/babylon.particle.js
  83. 96 17
      Babylon/Particles/babylon.particleSystem.js
  84. 79 9
      Babylon/Physics/Plugins/babylon.cannonJSPlugin.js
  85. 57 10
      Babylon/Physics/Plugins/babylon.oimoJSPlugin.js
  86. 15 5
      Babylon/Physics/babylon.physicsEngine.js
  87. 46 5
      Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderEffect.js
  88. 13 2
      Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPass.js
  89. 34 3
      Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPipeline.js
  90. 20 1
      Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPipelineManager.js
  91. 2 2
      Babylon/PostProcess/babylon.anaglyphPostProcess.js
  92. 2 2
      Babylon/PostProcess/babylon.blackAndWhitePostProcess.js
  93. 3 3
      Babylon/PostProcess/babylon.blurPostProcess.js
  94. 3 4
      Babylon/PostProcess/babylon.convolutionPostProcess.js
  95. 2 2
      Babylon/PostProcess/babylon.displayPassPostProcess.js
  96. 3 2
      Babylon/PostProcess/babylon.filterPostProcess.js
  97. 3 2
      Babylon/PostProcess/babylon.fxaaPostProcess.js
  98. 4 2
      Babylon/PostProcess/babylon.oculusDistortionCorrectionPostProcess.js
  99. 2 2
      Babylon/PostProcess/babylon.passPostProcess.js
  100. 0 0
      Babylon/PostProcess/babylon.postProcess.js

+ 20 - 8
Babylon/Actions/babylon.action.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var Action = (function () {
         function Action(triggerOptions, condition) {
@@ -6,59 +6,71 @@ var BABYLON;
             if (triggerOptions.parameter) {
                 this.trigger = triggerOptions.trigger;
                 this._triggerParameter = triggerOptions.parameter;
-            }
-            else {
+            } else {
                 this.trigger = triggerOptions;
             }
+
             this._nextActiveAction = this;
             this._condition = condition;
         }
         // Methods
         Action.prototype._prepare = function () {
         };
+
         Action.prototype.getTriggerParameter = function () {
             return this._triggerParameter;
         };
+
         Action.prototype._executeCurrent = function (evt) {
             if (this._condition) {
                 var currentRenderId = this._actionManager.getScene().getRenderId();
+
                 // We cache the current evaluation for the current frame
                 if (this._condition._evaluationId === currentRenderId) {
                     if (!this._condition._currentResult) {
                         return;
                     }
-                }
-                else {
+                } else {
                     this._condition._evaluationId = currentRenderId;
+
                     if (!this._condition.isValid()) {
                         this._condition._currentResult = false;
                         return;
                     }
+
                     this._condition._currentResult = true;
                 }
             }
+
             this._nextActiveAction.execute(evt);
+
             if (this._nextActiveAction._child) {
                 if (!this._nextActiveAction._child._actionManager) {
                     this._nextActiveAction._child._actionManager = this._actionManager;
                 }
+
                 this._nextActiveAction = this._nextActiveAction._child;
-            }
-            else {
+            } else {
                 this._nextActiveAction = this;
             }
         };
+
         Action.prototype.execute = function (evt) {
         };
+
         Action.prototype.then = function (action) {
             this._child = action;
+
             action._actionManager = this._actionManager;
             action._prepare();
+
             return action;
         };
+
         Action.prototype._getProperty = function (propertyPath) {
             return this._actionManager._getProperty(propertyPath);
         };
+
         Action.prototype._getEffectiveTarget = function (target, propertyPath) {
             return this._actionManager._getEffectiveTarget(target, propertyPath);
         };
@@ -66,4 +78,4 @@ var BABYLON;
     })();
     BABYLON.Action = Action;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.action.js.map
+//# sourceMappingURL=babylon.action.js.map

+ 41 - 3
Babylon/Actions/babylon.actionManager.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var ActionEvent = (function () {
         function ActionEvent(source, pointerX, pointerY, meshUnderPointer, sourceEvent) {
@@ -12,17 +12,20 @@ var BABYLON;
             var scene = source.getScene();
             return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt);
         };
+
         ActionEvent.CreateNewFromScene = function (scene, evt) {
             return new ActionEvent(null, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt);
         };
         return ActionEvent;
     })();
     BABYLON.ActionEvent = ActionEvent;
+
     var ActionManager = (function () {
         function ActionManager(scene) {
             // Members
             this.actions = new Array();
             this._scene = scene;
+
             scene._actionManagers.push(this);
         }
         Object.defineProperty(ActionManager, "NothingTrigger", {
@@ -32,6 +35,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ActionManager, "OnPickTrigger", {
             get: function () {
                 return ActionManager._OnPickTrigger;
@@ -39,6 +43,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ActionManager, "OnLeftPickTrigger", {
             get: function () {
                 return ActionManager._OnLeftPickTrigger;
@@ -46,6 +51,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ActionManager, "OnRightPickTrigger", {
             get: function () {
                 return ActionManager._OnRightPickTrigger;
@@ -53,6 +59,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ActionManager, "OnCenterPickTrigger", {
             get: function () {
                 return ActionManager._OnCenterPickTrigger;
@@ -60,6 +67,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ActionManager, "OnPointerOverTrigger", {
             get: function () {
                 return ActionManager._OnPointerOverTrigger;
@@ -67,6 +75,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ActionManager, "OnPointerOutTrigger", {
             get: function () {
                 return ActionManager._OnPointerOutTrigger;
@@ -74,6 +83,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ActionManager, "OnEveryFrameTrigger", {
             get: function () {
                 return ActionManager._OnEveryFrameTrigger;
@@ -81,6 +91,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ActionManager, "OnIntersectionEnterTrigger", {
             get: function () {
                 return ActionManager._OnIntersectionEnterTrigger;
@@ -88,6 +99,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ActionManager, "OnIntersectionExitTrigger", {
             get: function () {
                 return ActionManager._OnIntersectionExitTrigger;
@@ -95,6 +107,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ActionManager, "OnKeyDownTrigger", {
             get: function () {
                 return ActionManager._OnKeyDownTrigger;
@@ -102,6 +115,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ActionManager, "OnKeyUpTrigger", {
             get: function () {
                 return ActionManager._OnKeyUpTrigger;
@@ -109,51 +123,64 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         // Methods
         ActionManager.prototype.dispose = function () {
             var index = this._scene._actionManagers.indexOf(this);
+
             if (index > -1) {
                 this._scene._actionManagers.splice(index, 1);
             }
         };
+
         ActionManager.prototype.getScene = function () {
             return this._scene;
         };
+
         ActionManager.prototype.hasSpecificTriggers = function (triggers) {
             for (var index = 0; index < this.actions.length; index++) {
                 var action = this.actions[index];
+
                 if (triggers.indexOf(action.trigger) > -1) {
                     return true;
                 }
             }
+
             return false;
         };
+
         Object.defineProperty(ActionManager.prototype, "hasPointerTriggers", {
             get: function () {
                 for (var index = 0; index < this.actions.length; index++) {
                     var action = this.actions[index];
+
                     if (action.trigger >= ActionManager._OnPickTrigger && action.trigger <= ActionManager._OnPointerOutTrigger) {
                         return true;
                     }
                 }
+
                 return false;
             },
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ActionManager.prototype, "hasPickTriggers", {
             get: function () {
                 for (var index = 0; index < this.actions.length; index++) {
                     var action = this.actions[index];
+
                     if (action.trigger >= ActionManager._OnPickTrigger && action.trigger <= ActionManager._OnCenterPickTrigger) {
                         return true;
                     }
                 }
+
                 return false;
             },
             enumerable: true,
             configurable: true
         });
+
         ActionManager.prototype.registerAction = function (action) {
             if (action.trigger === ActionManager.OnEveryFrameTrigger) {
                 if (this.getScene().actionManager !== this) {
@@ -161,39 +188,50 @@ var BABYLON;
                     return null;
                 }
             }
+
             this.actions.push(action);
+
             action._actionManager = this;
             action._prepare();
+
             return action;
         };
+
         ActionManager.prototype.processTrigger = function (trigger, evt) {
             for (var index = 0; index < this.actions.length; index++) {
                 var action = this.actions[index];
+
                 if (action.trigger === trigger) {
                     if (trigger === ActionManager.OnKeyUpTrigger || trigger === ActionManager.OnKeyDownTrigger) {
                         var parameter = action.getTriggerParameter();
+
                         if (parameter) {
                             if (evt.sourceEvent.key !== parameter) {
                                 continue;
                             }
                         }
                     }
+
                     action._executeCurrent(evt);
                 }
             }
         };
+
         ActionManager.prototype._getEffectiveTarget = function (target, propertyPath) {
             var properties = propertyPath.split(".");
+
             for (var index = 0; index < properties.length - 1; index++) {
                 target = target[properties[index]];
             }
+
             return target;
         };
+
         ActionManager.prototype._getProperty = function (propertyPath) {
             var properties = propertyPath.split(".");
+
             return properties[properties.length - 1];
         };
-        // Statics
         ActionManager._NothingTrigger = 0;
         ActionManager._OnPickTrigger = 1;
         ActionManager._OnLeftPickTrigger = 2;
@@ -210,4 +248,4 @@ var BABYLON;
     })();
     BABYLON.ActionManager = ActionManager;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.actionManager.js.map
+//# sourceMappingURL=babylon.actionManager.js.map

+ 17 - 6
Babylon/Actions/babylon.condition.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -13,23 +13,27 @@ var BABYLON;
         Condition.prototype.isValid = function () {
             return true;
         };
+
         Condition.prototype._getProperty = function (propertyPath) {
             return this._actionManager._getProperty(propertyPath);
         };
+
         Condition.prototype._getEffectiveTarget = function (target, propertyPath) {
             return this._actionManager._getEffectiveTarget(target, propertyPath);
         };
         return Condition;
     })();
     BABYLON.Condition = Condition;
+
     var ValueCondition = (function (_super) {
         __extends(ValueCondition, _super);
         function ValueCondition(actionManager, target, propertyPath, value, operator) {
-            if (operator === void 0) { operator = ValueCondition.IsEqual; }
+            if (typeof operator === "undefined") { operator = ValueCondition.IsEqual; }
             _super.call(this, actionManager);
             this.propertyPath = propertyPath;
             this.value = value;
             this.operator = operator;
+
             this._target = this._getEffectiveTarget(target, this.propertyPath);
             this._property = this._getProperty(this.propertyPath);
         }
@@ -40,6 +44,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ValueCondition, "IsDifferent", {
             get: function () {
                 return ValueCondition._IsDifferent;
@@ -47,6 +52,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ValueCondition, "IsGreater", {
             get: function () {
                 return ValueCondition._IsGreater;
@@ -54,6 +60,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ValueCondition, "IsLesser", {
             get: function () {
                 return ValueCondition._IsLesser;
@@ -61,6 +68,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         // Methods
         ValueCondition.prototype.isValid = function () {
             switch (this.operator) {
@@ -71,17 +79,17 @@ var BABYLON;
                 case ValueCondition.IsEqual:
                 case ValueCondition.IsDifferent:
                     var check;
+
                     if (this.value.equals) {
                         check = this.value.equals(this._target[this._property]);
-                    }
-                    else {
+                    } else {
                         check = this.value === this._target[this._property];
                     }
                     return this.operator === ValueCondition.IsEqual ? check : !check;
             }
+
             return false;
         };
-        // Statics
         ValueCondition._IsEqual = 0;
         ValueCondition._IsDifferent = 1;
         ValueCondition._IsGreater = 2;
@@ -89,6 +97,7 @@ var BABYLON;
         return ValueCondition;
     })(Condition);
     BABYLON.ValueCondition = ValueCondition;
+
     var PredicateCondition = (function (_super) {
         __extends(PredicateCondition, _super);
         function PredicateCondition(actionManager, predicate) {
@@ -101,11 +110,13 @@ var BABYLON;
         return PredicateCondition;
     })(Condition);
     BABYLON.PredicateCondition = PredicateCondition;
+
     var StateCondition = (function (_super) {
         __extends(StateCondition, _super);
         function StateCondition(actionManager, target, value) {
             _super.call(this, actionManager);
             this.value = value;
+
             this._target = target;
         }
         // Methods
@@ -116,4 +127,4 @@ var BABYLON;
     })(Condition);
     BABYLON.StateCondition = StateCondition;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.condition.js.map
+//# sourceMappingURL=babylon.condition.js.map

+ 23 - 3
Babylon/Actions/babylon.directActions.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -17,12 +17,14 @@ var BABYLON;
             this._target = this._getEffectiveTarget(this._target, this.propertyPath);
             this._property = this._getProperty(this.propertyPath);
         };
+
         SwitchBooleanAction.prototype.execute = function () {
             this._target[this._property] = !this._target[this._property];
         };
         return SwitchBooleanAction;
     })(BABYLON.Action);
     BABYLON.SwitchBooleanAction = SwitchBooleanAction;
+
     var SetStateAction = (function (_super) {
         __extends(SetStateAction, _super);
         function SetStateAction(triggerOptions, target, value, condition) {
@@ -36,6 +38,7 @@ var BABYLON;
         return SetStateAction;
     })(BABYLON.Action);
     BABYLON.SetStateAction = SetStateAction;
+
     var SetValueAction = (function (_super) {
         __extends(SetValueAction, _super);
         function SetValueAction(triggerOptions, target, propertyPath, value, condition) {
@@ -48,12 +51,14 @@ var BABYLON;
             this._target = this._getEffectiveTarget(this._target, this.propertyPath);
             this._property = this._getProperty(this.propertyPath);
         };
+
         SetValueAction.prototype.execute = function () {
             this._target[this._property] = this.value;
         };
         return SetValueAction;
     })(BABYLON.Action);
     BABYLON.SetValueAction = SetValueAction;
+
     var IncrementValueAction = (function (_super) {
         __extends(IncrementValueAction, _super);
         function IncrementValueAction(triggerOptions, target, propertyPath, value, condition) {
@@ -65,16 +70,19 @@ var BABYLON;
         IncrementValueAction.prototype._prepare = function () {
             this._target = this._getEffectiveTarget(this._target, this.propertyPath);
             this._property = this._getProperty(this.propertyPath);
+
             if (typeof this._target[this._property] !== "number") {
                 BABYLON.Tools.Warn("Warning: IncrementValueAction can only be used with number values");
             }
         };
+
         IncrementValueAction.prototype.execute = function () {
             this._target[this._property] += this.value;
         };
         return IncrementValueAction;
     })(BABYLON.Action);
     BABYLON.IncrementValueAction = IncrementValueAction;
+
     var PlayAnimationAction = (function (_super) {
         __extends(PlayAnimationAction, _super);
         function PlayAnimationAction(triggerOptions, target, from, to, loop, condition) {
@@ -86,6 +94,7 @@ var BABYLON;
         }
         PlayAnimationAction.prototype._prepare = function () {
         };
+
         PlayAnimationAction.prototype.execute = function () {
             var scene = this._actionManager.getScene();
             scene.beginAnimation(this._target, this.from, this.to, this.loop);
@@ -93,6 +102,7 @@ var BABYLON;
         return PlayAnimationAction;
     })(BABYLON.Action);
     BABYLON.PlayAnimationAction = PlayAnimationAction;
+
     var StopAnimationAction = (function (_super) {
         __extends(StopAnimationAction, _super);
         function StopAnimationAction(triggerOptions, target, condition) {
@@ -101,6 +111,7 @@ var BABYLON;
         }
         StopAnimationAction.prototype._prepare = function () {
         };
+
         StopAnimationAction.prototype.execute = function () {
             var scene = this._actionManager.getScene();
             scene.stopAnimation(this._target);
@@ -108,10 +119,11 @@ var BABYLON;
         return StopAnimationAction;
     })(BABYLON.Action);
     BABYLON.StopAnimationAction = StopAnimationAction;
+
     var DoNothingAction = (function (_super) {
         __extends(DoNothingAction, _super);
         function DoNothingAction(triggerOptions, condition) {
-            if (triggerOptions === void 0) { triggerOptions = BABYLON.ActionManager.NothingTrigger; }
+            if (typeof triggerOptions === "undefined") { triggerOptions = BABYLON.ActionManager.NothingTrigger; }
             _super.call(this, triggerOptions, condition);
         }
         DoNothingAction.prototype.execute = function () {
@@ -119,6 +131,7 @@ var BABYLON;
         return DoNothingAction;
     })(BABYLON.Action);
     BABYLON.DoNothingAction = DoNothingAction;
+
     var CombineAction = (function (_super) {
         __extends(CombineAction, _super);
         function CombineAction(triggerOptions, children, condition) {
@@ -131,6 +144,7 @@ var BABYLON;
                 this.children[index]._prepare();
             }
         };
+
         CombineAction.prototype.execute = function (evt) {
             for (var index = 0; index < this.children.length; index++) {
                 this.children[index].execute(evt);
@@ -139,6 +153,7 @@ var BABYLON;
         return CombineAction;
     })(BABYLON.Action);
     BABYLON.CombineAction = CombineAction;
+
     var ExecuteCodeAction = (function (_super) {
         __extends(ExecuteCodeAction, _super);
         function ExecuteCodeAction(triggerOptions, func, condition) {
@@ -151,6 +166,7 @@ var BABYLON;
         return ExecuteCodeAction;
     })(BABYLON.Action);
     BABYLON.ExecuteCodeAction = ExecuteCodeAction;
+
     var SetParentAction = (function (_super) {
         __extends(SetParentAction, _super);
         function SetParentAction(triggerOptions, target, parent, condition) {
@@ -160,17 +176,21 @@ var BABYLON;
         }
         SetParentAction.prototype._prepare = function () {
         };
+
         SetParentAction.prototype.execute = function () {
             if (this._target.parent === this._parent) {
                 return;
             }
+
             var invertParentWorldMatrix = this._parent.getWorldMatrix().clone();
             invertParentWorldMatrix.invert();
+
             this._target.position = BABYLON.Vector3.TransformCoordinates(this._target.position, invertParentWorldMatrix);
+
             this._target.parent = this._parent;
         };
         return SetParentAction;
     })(BABYLON.Action);
     BABYLON.SetParentAction = SetParentAction;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.directActions.js.map
+//# sourceMappingURL=babylon.directActions.js.map

+ 17 - 15
Babylon/Actions/babylon.interpolateValueAction.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -9,59 +9,61 @@ var BABYLON;
     var InterpolateValueAction = (function (_super) {
         __extends(InterpolateValueAction, _super);
         function InterpolateValueAction(triggerOptions, target, propertyPath, value, duration, condition, stopOtherAnimations) {
-            if (duration === void 0) { duration = 1000; }
+            if (typeof duration === "undefined") { duration = 1000; }
             _super.call(this, triggerOptions, condition);
             this.propertyPath = propertyPath;
             this.value = value;
             this.duration = duration;
             this.stopOtherAnimations = stopOtherAnimations;
+
             this._target = target;
         }
         InterpolateValueAction.prototype._prepare = function () {
             this._target = this._getEffectiveTarget(this._target, this.propertyPath);
             this._property = this._getProperty(this.propertyPath);
         };
+
         InterpolateValueAction.prototype.execute = function () {
             var scene = this._actionManager.getScene();
             var keys = [
                 {
                     frame: 0,
                     value: this._target[this._property]
-                },
-                {
+                }, {
                     frame: 100,
                     value: this.value
                 }
             ];
+
             var dataType;
+
             if (typeof this.value === "number") {
                 dataType = BABYLON.Animation.ANIMATIONTYPE_FLOAT;
-            }
-            else if (this.value instanceof BABYLON.Color3) {
+            } else if (this.value instanceof BABYLON.Color3) {
                 dataType = BABYLON.Animation.ANIMATIONTYPE_COLOR3;
-            }
-            else if (this.value instanceof BABYLON.Vector3) {
+            } else if (this.value instanceof BABYLON.Vector3) {
                 dataType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
-            }
-            else if (this.value instanceof BABYLON.Matrix) {
+            } else if (this.value instanceof BABYLON.Matrix) {
                 dataType = BABYLON.Animation.ANIMATIONTYPE_MATRIX;
-            }
-            else if (this.value instanceof BABYLON.Quaternion) {
+            } else if (this.value instanceof BABYLON.Quaternion) {
                 dataType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
-            }
-            else {
+            } else {
                 BABYLON.Tools.Warn("InterpolateValueAction: Unsupported type (" + typeof this.value + ")");
                 return;
             }
+
             var animation = new BABYLON.Animation("InterpolateValueAction", this._property, 100 * (1000.0 / this.duration), dataType, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
+
             animation.setKeys(keys);
+
             if (this.stopOtherAnimations) {
                 scene.stopAnimation(this._target);
             }
+
             scene.beginDirectAnimation(this._target, [animation], 0, 100);
         };
         return InterpolateValueAction;
     })(BABYLON.Action);
     BABYLON.InterpolateValueAction = InterpolateValueAction;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.interpolateValueAction.js.map
+//# sourceMappingURL=babylon.interpolateValueAction.js.map

+ 23 - 8
Babylon/Animations/babylon.animatable.js

@@ -1,11 +1,11 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var Animatable = (function () {
         function Animatable(scene, target, fromFrame, toFrame, loopAnimation, speedRatio, onAnimationEnd, animations) {
-            if (fromFrame === void 0) { fromFrame = 0; }
-            if (toFrame === void 0) { toFrame = 100; }
-            if (loopAnimation === void 0) { loopAnimation = false; }
-            if (speedRatio === void 0) { speedRatio = 1.0; }
+            if (typeof fromFrame === "undefined") { fromFrame = 0; }
+            if (typeof toFrame === "undefined") { toFrame = 100; }
+            if (typeof loopAnimation === "undefined") { loopAnimation = false; }
+            if (typeof speedRatio === "undefined") { speedRatio = 1.0; }
             this.target = target;
             this.fromFrame = fromFrame;
             this.toFrame = toFrame;
@@ -18,6 +18,7 @@ var BABYLON;
             if (animations) {
                 this.appendAnimations(target, animations);
             }
+
             this._scene = scene;
             scene._activeAnimatables.push(this);
         }
@@ -25,37 +26,47 @@ var BABYLON;
         Animatable.prototype.appendAnimations = function (target, animations) {
             for (var index = 0; index < animations.length; index++) {
                 var animation = animations[index];
+
                 animation._target = target;
                 this._animations.push(animation);
             }
         };
+
         Animatable.prototype.getAnimationByTargetProperty = function (property) {
             var animations = this._animations;
+
             for (var index = 0; index < animations.length; index++) {
                 if (animations[index].targetProperty === property) {
                     return animations[index];
                 }
             }
+
             return null;
         };
+
         Animatable.prototype.pause = function () {
             if (this._paused) {
                 return;
             }
             this._paused = true;
         };
+
         Animatable.prototype.restart = function () {
             this._paused = false;
         };
+
         Animatable.prototype.stop = function () {
             var index = this._scene._activeAnimatables.indexOf(this);
+
             if (index > -1) {
                 this._scene._activeAnimatables.splice(index, 1);
             }
+
             if (this.onAnimationEnd) {
                 this.onAnimationEnd();
             }
         };
+
         Animatable.prototype._animate = function (delay) {
             if (this._paused) {
                 if (!this._pausedDelay) {
@@ -63,28 +74,32 @@ var BABYLON;
                 }
                 return true;
             }
+
             if (!this._localDelayOffset) {
                 this._localDelayOffset = delay;
-            }
-            else if (this._pausedDelay) {
+            } else if (this._pausedDelay) {
                 this._localDelayOffset += delay - this._pausedDelay;
                 this._pausedDelay = null;
             }
+
             // Animating
             var running = false;
             var animations = this._animations;
+
             for (var index = 0; index < animations.length; index++) {
                 var animation = animations[index];
                 var isRunning = animation.animate(delay - this._localDelayOffset, this.fromFrame, this.toFrame, this.loopAnimation, this.speedRatio);
                 running = running || isRunning;
             }
+
             if (!running && this.onAnimationEnd) {
                 this.onAnimationEnd();
             }
+
             return running;
         };
         return Animatable;
     })();
     BABYLON.Animatable = Animatable;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.animatable.js.map
+//# sourceMappingURL=babylon.animatable.js.map

+ 80 - 16
Babylon/Animations/babylon.animation.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var Animation = (function () {
         function Animation(name, targetProperty, framePerSecond, dataType, loopMode) {
@@ -16,107 +16,135 @@ var BABYLON;
         }
         Animation.CreateAndStartAnimation = function (name, mesh, tartgetProperty, framePerSecond, totalFrame, from, to, loopMode) {
             var dataType = undefined;
+
             if (!isNaN(parseFloat(from)) && isFinite(from)) {
                 dataType = Animation.ANIMATIONTYPE_FLOAT;
-            }
-            else if (from instanceof BABYLON.Quaternion) {
+            } else if (from instanceof BABYLON.Quaternion) {
                 dataType = Animation.ANIMATIONTYPE_QUATERNION;
-            }
-            else if (from instanceof BABYLON.Vector3) {
+            } else if (from instanceof BABYLON.Vector3) {
                 dataType = Animation.ANIMATIONTYPE_VECTOR3;
-            }
-            else if (from instanceof BABYLON.Vector2) {
+            } else if (from instanceof BABYLON.Vector2) {
                 dataType = Animation.ANIMATIONTYPE_VECTOR2;
-            }
-            else if (from instanceof BABYLON.Color3) {
+            } else if (from instanceof BABYLON.Color3) {
                 dataType = Animation.ANIMATIONTYPE_COLOR3;
             }
+
             if (dataType == undefined) {
                 return;
             }
+
             var animation = new Animation(name, tartgetProperty, framePerSecond, dataType, loopMode);
+
             var keys = [];
             keys.push({ frame: 0, value: from });
             keys.push({ frame: totalFrame, value: to });
             animation.setKeys(keys);
+
             mesh.animations.push(animation);
+
             mesh.getScene().beginAnimation(mesh, 0, totalFrame, (animation.loopMode === 1));
         };
-        // Methods   
+
+        // Methods
         Animation.prototype.isStopped = function () {
             return this._stopped;
         };
+
         Animation.prototype.getKeys = function () {
             return this._keys;
         };
+
         Animation.prototype.getEasingFunction = function () {
             return this._easingFunction;
         };
+
         Animation.prototype.setEasingFunction = function (easingFunction) {
             this._easingFunction = easingFunction;
         };
+
         Animation.prototype.floatInterpolateFunction = function (startValue, endValue, gradient) {
             return startValue + (endValue - startValue) * gradient;
         };
+
         Animation.prototype.quaternionInterpolateFunction = function (startValue, endValue, gradient) {
             return BABYLON.Quaternion.Slerp(startValue, endValue, gradient);
         };
+
         Animation.prototype.vector3InterpolateFunction = function (startValue, endValue, gradient) {
             return BABYLON.Vector3.Lerp(startValue, endValue, gradient);
         };
+
         Animation.prototype.vector2InterpolateFunction = function (startValue, endValue, gradient) {
             return BABYLON.Vector2.Lerp(startValue, endValue, gradient);
         };
+
         Animation.prototype.color3InterpolateFunction = function (startValue, endValue, gradient) {
             return BABYLON.Color3.Lerp(startValue, endValue, gradient);
         };
+
         Animation.prototype.matrixInterpolateFunction = function (startValue, endValue, gradient) {
             var startScale = new BABYLON.Vector3(0, 0, 0);
             var startRotation = new BABYLON.Quaternion();
             var startTranslation = new BABYLON.Vector3(0, 0, 0);
             startValue.decompose(startScale, startRotation, startTranslation);
+
             var endScale = new BABYLON.Vector3(0, 0, 0);
             var endRotation = new BABYLON.Quaternion();
             var endTranslation = new BABYLON.Vector3(0, 0, 0);
             endValue.decompose(endScale, endRotation, endTranslation);
+
             var resultScale = this.vector3InterpolateFunction(startScale, endScale, gradient);
             var resultRotation = this.quaternionInterpolateFunction(startRotation, endRotation, gradient);
             var resultTranslation = this.vector3InterpolateFunction(startTranslation, endTranslation, gradient);
+
             var result = BABYLON.Matrix.Compose(resultScale, resultRotation, resultTranslation);
+
             return result;
         };
+
         Animation.prototype.clone = function () {
             var clone = new Animation(this.name, this.targetPropertyPath.join("."), this.framePerSecond, this.dataType, this.loopMode);
+
             clone.setKeys(this._keys);
+
             return clone;
         };
+
         Animation.prototype.setKeys = function (values) {
             this._keys = values.slice(0);
             this._offsetsCache = {};
             this._highLimitsCache = {};
         };
+
         Animation.prototype._getKeyValue = function (value) {
             if (typeof value === "function") {
                 return value();
             }
+
             return value;
         };
+
         Animation.prototype._interpolate = function (currentFrame, repeatCount, loopMode, offsetValue, highLimitValue) {
             if (loopMode === Animation.ANIMATIONLOOPMODE_CONSTANT && repeatCount > 0) {
                 return highLimitValue.clone ? highLimitValue.clone() : highLimitValue;
             }
+
             this.currentFrame = currentFrame;
+
             for (var key = 0; key < this._keys.length; key++) {
                 // for each frame, we need the key just before the frame superior
                 if (this._keys[key + 1].frame >= currentFrame) {
                     var startValue = this._getKeyValue(this._keys[key].value);
                     var endValue = this._getKeyValue(this._keys[key + 1].value);
+
                     // gradient : percent of currentFrame between the frame inf and the frame sup
                     var gradient = (currentFrame - this._keys[key].frame) / (this._keys[key + 1].frame - this._keys[key].frame);
+
                     // check for easingFunction and correction of gradient
                     if (this._easingFunction != null) {
                         gradient = this._easingFunction.ease(gradient);
                     }
+
                     switch (this.dataType) {
                         case Animation.ANIMATIONTYPE_FLOAT:
                             switch (loopMode) {
@@ -127,6 +155,7 @@ var BABYLON;
                                     return offsetValue * repeatCount + this.floatInterpolateFunction(startValue, endValue, gradient);
                             }
                             break;
+
                         case Animation.ANIMATIONTYPE_QUATERNION:
                             var quaternion = null;
                             switch (loopMode) {
@@ -138,7 +167,9 @@ var BABYLON;
                                     quaternion = this.quaternionInterpolateFunction(startValue, endValue, gradient).add(offsetValue.scale(repeatCount));
                                     break;
                             }
+
                             return quaternion;
+
                         case Animation.ANIMATIONTYPE_VECTOR3:
                             switch (loopMode) {
                                 case Animation.ANIMATIONLOOPMODE_CYCLE:
@@ -147,6 +178,7 @@ var BABYLON;
                                 case Animation.ANIMATIONLOOPMODE_RELATIVE:
                                     return this.vector3InterpolateFunction(startValue, endValue, gradient).add(offsetValue.scale(repeatCount));
                             }
+
                         case Animation.ANIMATIONTYPE_VECTOR2:
                             switch (loopMode) {
                                 case Animation.ANIMATIONLOOPMODE_CYCLE:
@@ -155,6 +187,7 @@ var BABYLON;
                                 case Animation.ANIMATIONLOOPMODE_RELATIVE:
                                     return this.vector2InterpolateFunction(startValue, endValue, gradient).add(offsetValue.scale(repeatCount));
                             }
+
                         case Animation.ANIMATIONTYPE_COLOR3:
                             switch (loopMode) {
                                 case Animation.ANIMATIONLOOPMODE_CYCLE:
@@ -163,6 +196,7 @@ var BABYLON;
                                 case Animation.ANIMATIONLOOPMODE_RELATIVE:
                                     return this.color3InterpolateFunction(startValue, endValue, gradient).add(offsetValue.scale(repeatCount));
                             }
+
                         case Animation.ANIMATIONTYPE_MATRIX:
                             switch (loopMode) {
                                 case Animation.ANIMATIONLOOPMODE_CYCLE:
@@ -179,17 +213,20 @@ var BABYLON;
             }
             return this._getKeyValue(this._keys[this._keys.length - 1].value);
         };
+
         Animation.prototype.animate = function (delay, from, to, loop, speedRatio) {
             if (!this.targetPropertyPath || this.targetPropertyPath.length < 1) {
                 this._stopped = true;
                 return false;
             }
             var returnValue = true;
+
             // Adding a start key at frame 0 if missing
             if (this._keys[0].frame !== 0) {
                 var newKey = { frame: 0, value: this._keys[0].value };
                 this._keys.splice(0, 0, newKey);
             }
+
             // Check limits
             if (from < this._keys[0].frame || from > this._keys[this._keys.length - 1].frame) {
                 from = this._keys[0].frame;
@@ -197,17 +234,19 @@ var BABYLON;
             if (to < this._keys[0].frame || to > this._keys[this._keys.length - 1].frame) {
                 to = this._keys[this._keys.length - 1].frame;
             }
+
             // Compute ratio
             var range = to - from;
             var offsetValue;
+
             // ratio represents the frame delta between from and to
             var ratio = delay * (this.framePerSecond * speedRatio) / 1000.0;
             var highLimitValue = 0;
+
             if (ratio > range && !loop) {
                 returnValue = false;
                 highLimitValue = this._getKeyValue(this._keys[this._keys.length - 1].value);
-            }
-            else {
+            } else {
                 // Get max value if required
                 if (this.loopMode !== Animation.ANIMATIONLOOPMODE_CYCLE) {
                     var keyOffset = to.toString() + from.toString();
@@ -218,65 +257,83 @@ var BABYLON;
                             case Animation.ANIMATIONTYPE_FLOAT:
                                 this._offsetsCache[keyOffset] = toValue - fromValue;
                                 break;
+
                             case Animation.ANIMATIONTYPE_QUATERNION:
                                 this._offsetsCache[keyOffset] = toValue.subtract(fromValue);
                                 break;
+
                             case Animation.ANIMATIONTYPE_VECTOR3:
                                 this._offsetsCache[keyOffset] = toValue.subtract(fromValue);
+
                             case Animation.ANIMATIONTYPE_VECTOR2:
                                 this._offsetsCache[keyOffset] = toValue.subtract(fromValue);
+
                             case Animation.ANIMATIONTYPE_COLOR3:
                                 this._offsetsCache[keyOffset] = toValue.subtract(fromValue);
                             default:
                                 break;
                         }
+
                         this._highLimitsCache[keyOffset] = toValue;
                     }
+
                     highLimitValue = this._highLimitsCache[keyOffset];
                     offsetValue = this._offsetsCache[keyOffset];
                 }
             }
+
             if (offsetValue === undefined) {
                 switch (this.dataType) {
                     case Animation.ANIMATIONTYPE_FLOAT:
                         offsetValue = 0;
                         break;
+
                     case Animation.ANIMATIONTYPE_QUATERNION:
                         offsetValue = new BABYLON.Quaternion(0, 0, 0, 0);
                         break;
+
                     case Animation.ANIMATIONTYPE_VECTOR3:
                         offsetValue = BABYLON.Vector3.Zero();
                         break;
+
                     case Animation.ANIMATIONTYPE_VECTOR2:
                         offsetValue = BABYLON.Vector2.Zero();
                         break;
+
                     case Animation.ANIMATIONTYPE_COLOR3:
                         offsetValue = BABYLON.Color3.Black();
                 }
             }
+
             // Compute value
             var repeatCount = (ratio / range) >> 0;
             var currentFrame = returnValue ? from + ratio % range : to;
             var currentValue = this._interpolate(currentFrame, repeatCount, this.loopMode, offsetValue, highLimitValue);
+
             // Set value
             if (this.targetPropertyPath.length > 1) {
                 var property = this._target[this.targetPropertyPath[0]];
+
                 for (var index = 1; index < this.targetPropertyPath.length - 1; index++) {
                     property = property[this.targetPropertyPath[index]];
                 }
+
                 property[this.targetPropertyPath[this.targetPropertyPath.length - 1]] = currentValue;
-            }
-            else {
+            } else {
                 this._target[this.targetPropertyPath[0]] = currentValue;
             }
+
             if (this._target.markAsDirty) {
                 this._target.markAsDirty(this.targetProperty);
             }
+
             if (!returnValue) {
                 this._stopped = true;
             }
+
             return returnValue;
         };
+
         Object.defineProperty(Animation, "ANIMATIONTYPE_FLOAT", {
             get: function () {
                 return Animation._ANIMATIONTYPE_FLOAT;
@@ -284,6 +341,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(Animation, "ANIMATIONTYPE_VECTOR3", {
             get: function () {
                 return Animation._ANIMATIONTYPE_VECTOR3;
@@ -291,6 +349,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(Animation, "ANIMATIONTYPE_VECTOR2", {
             get: function () {
                 return Animation._ANIMATIONTYPE_VECTOR2;
@@ -298,6 +357,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(Animation, "ANIMATIONTYPE_QUATERNION", {
             get: function () {
                 return Animation._ANIMATIONTYPE_QUATERNION;
@@ -305,6 +365,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(Animation, "ANIMATIONTYPE_MATRIX", {
             get: function () {
                 return Animation._ANIMATIONTYPE_MATRIX;
@@ -312,6 +373,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(Animation, "ANIMATIONTYPE_COLOR3", {
             get: function () {
                 return Animation._ANIMATIONTYPE_COLOR3;
@@ -319,6 +381,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(Animation, "ANIMATIONLOOPMODE_RELATIVE", {
             get: function () {
                 return Animation._ANIMATIONLOOPMODE_RELATIVE;
@@ -326,6 +389,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(Animation, "ANIMATIONLOOPMODE_CYCLE", {
             get: function () {
                 return Animation._ANIMATIONLOOPMODE_CYCLE;
@@ -333,6 +397,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(Animation, "ANIMATIONLOOPMODE_CONSTANT", {
             get: function () {
                 return Animation._ANIMATIONLOOPMODE_CONSTANT;
@@ -340,7 +405,6 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
-        // Statics
         Animation._ANIMATIONTYPE_FLOAT = 0;
         Animation._ANIMATIONTYPE_VECTOR3 = 1;
         Animation._ANIMATIONTYPE_QUATERNION = 2;
@@ -354,4 +418,4 @@ var BABYLON;
     })();
     BABYLON.Animation = Animation;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.animation.js.map
+//# sourceMappingURL=babylon.animation.js.map

+ 35 - 16
Babylon/Animations/babylon.easing.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -18,6 +18,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(EasingFunction, "EASINGMODE_EASEOUT", {
             get: function () {
                 return EasingFunction._EASINGMODE_EASEOUT;
@@ -25,6 +26,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(EasingFunction, "EASINGMODE_EASEINOUT", {
             get: function () {
                 return EasingFunction._EASINGMODE_EASEINOUT;
@@ -32,6 +34,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         EasingFunction.prototype.setEasingMode = function (easingMode) {
             var n = Math.min(Math.max(easingMode, 0), 2);
             this._easingMode = n;
@@ -39,9 +42,11 @@ var BABYLON;
         EasingFunction.prototype.getEasingMode = function () {
             return this._easingMode;
         };
+
         EasingFunction.prototype.easeInCore = function (gradient) {
             throw new Error('You must implement this method');
         };
+
         EasingFunction.prototype.ease = function (gradient) {
             switch (this._easingMode) {
                 case EasingFunction.EASINGMODE_EASEIN:
@@ -49,18 +54,20 @@ var BABYLON;
                 case EasingFunction.EASINGMODE_EASEOUT:
                     return (1 - this.easeInCore(1 - gradient));
             }
+
             if (gradient >= 0.5) {
                 return (((1 - this.easeInCore((1 - gradient) * 2)) * 0.5) + 0.5);
             }
+
             return (this.easeInCore(gradient * 2) * 0.5);
         };
-        //Statics
         EasingFunction._EASINGMODE_EASEIN = 0;
         EasingFunction._EASINGMODE_EASEOUT = 1;
         EasingFunction._EASINGMODE_EASEINOUT = 2;
         return EasingFunction;
     })();
     BABYLON.EasingFunction = EasingFunction;
+
     var CircleEase = (function (_super) {
         __extends(CircleEase, _super);
         function CircleEase() {
@@ -73,10 +80,11 @@ var BABYLON;
         return CircleEase;
     })(EasingFunction);
     BABYLON.CircleEase = CircleEase;
+
     var BackEase = (function (_super) {
         __extends(BackEase, _super);
         function BackEase(amplitude) {
-            if (amplitude === void 0) { amplitude = 1; }
+            if (typeof amplitude === "undefined") { amplitude = 1; }
             _super.call(this);
             this.amplitude = amplitude;
         }
@@ -87,11 +95,12 @@ var BABYLON;
         return BackEase;
     })(EasingFunction);
     BABYLON.BackEase = BackEase;
+
     var BounceEase = (function (_super) {
         __extends(BounceEase, _super);
         function BounceEase(bounces, bounciness) {
-            if (bounces === void 0) { bounces = 3; }
-            if (bounciness === void 0) { bounciness = 2; }
+            if (typeof bounces === "undefined") { bounces = 3; }
+            if (typeof bounciness === "undefined") { bounciness = 2; }
             _super.call(this);
             this.bounces = bounces;
             this.bounciness = bounciness;
@@ -119,6 +128,7 @@ var BABYLON;
         return BounceEase;
     })(EasingFunction);
     BABYLON.BounceEase = BounceEase;
+
     var CubicEase = (function (_super) {
         __extends(CubicEase, _super);
         function CubicEase() {
@@ -130,11 +140,12 @@ var BABYLON;
         return CubicEase;
     })(EasingFunction);
     BABYLON.CubicEase = CubicEase;
+
     var ElasticEase = (function (_super) {
         __extends(ElasticEase, _super);
         function ElasticEase(oscillations, springiness) {
-            if (oscillations === void 0) { oscillations = 3; }
-            if (springiness === void 0) { springiness = 3; }
+            if (typeof oscillations === "undefined") { oscillations = 3; }
+            if (typeof springiness === "undefined") { springiness = 3; }
             _super.call(this);
             this.oscillations = oscillations;
             this.springiness = springiness;
@@ -143,10 +154,10 @@ var BABYLON;
             var num2;
             var num3 = Math.max(0.0, this.oscillations);
             var num = Math.max(0.0, this.springiness);
+
             if (num == 0) {
                 num2 = gradient;
-            }
-            else {
+            } else {
                 num2 = (Math.exp(num * gradient) - 1.0) / (Math.exp(num) - 1.0);
             }
             return (num2 * Math.sin(((6.2831853071795862 * num3) + 1.5707963267948966) * gradient));
@@ -154,10 +165,11 @@ var BABYLON;
         return ElasticEase;
     })(EasingFunction);
     BABYLON.ElasticEase = ElasticEase;
+
     var ExponentialEase = (function (_super) {
         __extends(ExponentialEase, _super);
         function ExponentialEase(exponent) {
-            if (exponent === void 0) { exponent = 2; }
+            if (typeof exponent === "undefined") { exponent = 2; }
             _super.call(this);
             this.exponent = exponent;
         }
@@ -165,15 +177,17 @@ var BABYLON;
             if (this.exponent <= 0) {
                 return gradient;
             }
+
             return ((Math.exp(this.exponent * gradient) - 1.0) / (Math.exp(this.exponent) - 1.0));
         };
         return ExponentialEase;
     })(EasingFunction);
     BABYLON.ExponentialEase = ExponentialEase;
+
     var PowerEase = (function (_super) {
         __extends(PowerEase, _super);
         function PowerEase(power) {
-            if (power === void 0) { power = 2; }
+            if (typeof power === "undefined") { power = 2; }
             _super.call(this);
             this.power = power;
         }
@@ -184,6 +198,7 @@ var BABYLON;
         return PowerEase;
     })(EasingFunction);
     BABYLON.PowerEase = PowerEase;
+
     var QuadraticEase = (function (_super) {
         __extends(QuadraticEase, _super);
         function QuadraticEase() {
@@ -195,6 +210,7 @@ var BABYLON;
         return QuadraticEase;
     })(EasingFunction);
     BABYLON.QuadraticEase = QuadraticEase;
+
     var QuarticEase = (function (_super) {
         __extends(QuarticEase, _super);
         function QuarticEase() {
@@ -206,6 +222,7 @@ var BABYLON;
         return QuarticEase;
     })(EasingFunction);
     BABYLON.QuarticEase = QuarticEase;
+
     var QuinticEase = (function (_super) {
         __extends(QuinticEase, _super);
         function QuinticEase() {
@@ -217,6 +234,7 @@ var BABYLON;
         return QuinticEase;
     })(EasingFunction);
     BABYLON.QuinticEase = QuinticEase;
+
     var SineEase = (function (_super) {
         __extends(SineEase, _super);
         function SineEase() {
@@ -228,13 +246,14 @@ var BABYLON;
         return SineEase;
     })(EasingFunction);
     BABYLON.SineEase = SineEase;
+
     var BezierCurveEase = (function (_super) {
         __extends(BezierCurveEase, _super);
         function BezierCurveEase(x1, y1, x2, y2) {
-            if (x1 === void 0) { x1 = 0; }
-            if (y1 === void 0) { y1 = 0; }
-            if (x2 === void 0) { x2 = 1; }
-            if (y2 === void 0) { y2 = 1; }
+            if (typeof x1 === "undefined") { x1 = 0; }
+            if (typeof y1 === "undefined") { y1 = 0; }
+            if (typeof x2 === "undefined") { x2 = 1; }
+            if (typeof y2 === "undefined") { y2 = 1; }
             _super.call(this);
             this.x1 = x1;
             this.y1 = y1;
@@ -248,4 +267,4 @@ var BABYLON;
     })(EasingFunction);
     BABYLON.BezierCurveEase = BezierCurveEase;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.easing.js.map
+//# sourceMappingURL=babylon.easing.js.map

+ 103 - 0
Babylon/Audio/babylon.analyser.js

@@ -0,0 +1,103 @@
+var BABYLON;
+(function (BABYLON) {
+    var Analyser = (function () {
+        function Analyser(scene) {
+            this.SMOOTHING = 0.75;
+            this.FFT_SIZE = 512;
+            this.BARGRAPHAMPLITUDE = 256;
+            this._debugCanvasWidth = 320;
+            this._debugCanvasHeight = 200;
+            this._scene = scene;
+            this._audioEngine = scene.getEngine().getAudioEngine();
+            if (this._audioEngine.canUseWebAudio) {
+                this._webAudioAnalyser = this._audioEngine.audioContext.createAnalyser();
+                this._webAudioAnalyser.minDecibels = -140;
+                this._webAudioAnalyser.maxDecibels = 0;
+                this._byteFreqs = new Uint8Array(this._webAudioAnalyser.frequencyBinCount);
+                this._byteTime = new Uint8Array(this._webAudioAnalyser.frequencyBinCount);
+                this._floatFreqs = new Float32Array(this._webAudioAnalyser.frequencyBinCount);
+            }
+        }
+        Analyser.prototype.getFrequencyBinCount = function () {
+            return this._webAudioAnalyser.frequencyBinCount;
+        };
+
+        Analyser.prototype.getByteFrequencyData = function () {
+            this._webAudioAnalyser.smoothingTimeConstant = this.SMOOTHING;
+            this._webAudioAnalyser.fftSize = this.FFT_SIZE;
+            this._webAudioAnalyser.getByteFrequencyData(this._byteFreqs);
+            return this._byteFreqs;
+        };
+
+        Analyser.prototype.getByteTimeDomainData = function () {
+            this._webAudioAnalyser.smoothingTimeConstant = this.SMOOTHING;
+            this._webAudioAnalyser.fftSize = this.FFT_SIZE;
+            this._webAudioAnalyser.getByteTimeDomainData(this._byteTime);
+            return this._byteTime;
+        };
+
+        Analyser.prototype.getFloatFrequencyData = function () {
+            this._webAudioAnalyser.smoothingTimeConstant = this.SMOOTHING;
+            this._webAudioAnalyser.fftSize = this.FFT_SIZE;
+            this._webAudioAnalyser.getFloatFrequencyData(this._floatFreqs);
+            return this._floatFreqs;
+        };
+
+        Analyser.prototype.drawDebugCanvas = function () {
+            var _this = this;
+            if (this._audioEngine.canUseWebAudio) {
+                if (!this._debugCanvas) {
+                    this._debugCanvas = document.createElement("canvas");
+                    this._debugCanvas.width = this._debugCanvasWidth;
+                    this._debugCanvas.height = this._debugCanvasHeight;
+                    this._debugCanvas.style.position = "absolute";
+                    this._debugCanvas.style.top = "30px";
+                    this._debugCanvas.style.left = "10px";
+                    this._debugCanvasContext = this._debugCanvas.getContext("2d");
+                    document.body.appendChild(this._debugCanvas);
+                    this._registerFunc = function () {
+                        _this.drawDebugCanvas();
+                    };
+                    this._scene.registerBeforeRender(this._registerFunc);
+                }
+                if (this._registerFunc) {
+                    var workingArray = this.getByteFrequencyData();
+
+                    this._debugCanvasContext.fillStyle = 'rgb(0, 0, 0)';
+                    this._debugCanvasContext.fillRect(0, 0, this._debugCanvasWidth, this._debugCanvasHeight);
+
+                    for (var i = 0; i < this.getFrequencyBinCount(); i++) {
+                        var value = workingArray[i];
+                        var percent = value / this.BARGRAPHAMPLITUDE;
+                        var height = this._debugCanvasHeight * percent;
+                        var offset = this._debugCanvasHeight - height - 1;
+                        var barWidth = this._debugCanvasWidth / this.getFrequencyBinCount();
+                        var hue = i / this.getFrequencyBinCount() * 360;
+                        this._debugCanvasContext.fillStyle = 'hsl(' + hue + ', 100%, 50%)';
+                        this._debugCanvasContext.fillRect(i * barWidth, offset, barWidth, height);
+                    }
+                }
+            }
+        };
+
+        Analyser.prototype.stopDebugCanvas = function () {
+            if (this._debugCanvas) {
+                this._scene.unregisterBeforeRender(this._registerFunc);
+                this._registerFunc = null;
+                document.body.removeChild(this._debugCanvas);
+                this._debugCanvas = null;
+                this._debugCanvasContext = null;
+            }
+        };
+
+        Analyser.prototype.connectAudioNodes = function (inputAudioNode, outputAudioNode) {
+            if (this._audioEngine.canUseWebAudio) {
+                inputAudioNode.connect(this._webAudioAnalyser);
+                this._webAudioAnalyser.connect(outputAudioNode);
+            }
+        };
+        return Analyser;
+    })();
+    BABYLON.Analyser = Analyser;
+})(BABYLON || (BABYLON = {}));
+//# sourceMappingURL=babylon.analyser.js.map

+ 111 - 0
Babylon/Audio/babylon.analyser.ts

@@ -0,0 +1,111 @@
+module BABYLON {
+    export class Analyser {
+        public SMOOTHING = 0.75;
+        public FFT_SIZE = 512;
+        public BARGRAPHAMPLITUDE = 256;
+
+        private _byteFreqs: Uint8Array;
+        private _byteTime: Uint8Array;
+        private _floatFreqs: Float32Array;
+        private _webAudioAnalyser: AnalyserNode;
+        private _debugCanvas: HTMLCanvasElement;
+        private _debugCanvasContext: CanvasRenderingContext2D;
+        private _debugCanvasWidth = 320;
+        private _debugCanvasHeight = 200;
+        private _scene: Scene;
+        private _registerFunc;
+        private _audioEngine: AudioEngine;
+
+        constructor(scene: BABYLON.Scene) {
+            this._scene = scene;
+            this._audioEngine = scene.getEngine().getAudioEngine();
+            if (this._audioEngine.canUseWebAudio) {
+                this._webAudioAnalyser = this._audioEngine.audioContext.createAnalyser();
+                this._webAudioAnalyser.minDecibels = -140;
+                this._webAudioAnalyser.maxDecibels = 0;
+                this._byteFreqs = new Uint8Array(this._webAudioAnalyser.frequencyBinCount);
+                this._byteTime = new Uint8Array(this._webAudioAnalyser.frequencyBinCount);
+                this._floatFreqs = new Float32Array(this._webAudioAnalyser.frequencyBinCount);
+            }
+        }
+
+        public getFrequencyBinCount(): number {
+            return this._webAudioAnalyser.frequencyBinCount;
+        }
+
+        public getByteFrequencyData(): Uint8Array {
+            this._webAudioAnalyser.smoothingTimeConstant = this.SMOOTHING;
+            this._webAudioAnalyser.fftSize = this.FFT_SIZE;
+            this._webAudioAnalyser.getByteFrequencyData(this._byteFreqs);
+            return this._byteFreqs;
+        }
+
+        public getByteTimeDomainData(): Uint8Array {
+            this._webAudioAnalyser.smoothingTimeConstant = this.SMOOTHING;
+            this._webAudioAnalyser.fftSize = this.FFT_SIZE;
+            this._webAudioAnalyser.getByteTimeDomainData(this._byteTime);
+            return this._byteTime;
+        }
+
+        public getFloatFrequencyData(): Uint8Array {
+            this._webAudioAnalyser.smoothingTimeConstant = this.SMOOTHING;
+            this._webAudioAnalyser.fftSize = this.FFT_SIZE;
+            this._webAudioAnalyser.getFloatFrequencyData(this._floatFreqs);
+            return this._floatFreqs;
+        }
+
+        public drawDebugCanvas() {
+            if (this._audioEngine.canUseWebAudio) {
+                if (!this._debugCanvas) {
+                    this._debugCanvas = document.createElement("canvas");
+                    this._debugCanvas.width = this._debugCanvasWidth;
+                    this._debugCanvas.height = this._debugCanvasHeight;
+                    this._debugCanvas.style.position = "absolute";
+                    this._debugCanvas.style.top = "30px";
+                    this._debugCanvas.style.left = "10px";
+                    this._debugCanvasContext = this._debugCanvas.getContext("2d");
+                    document.body.appendChild(this._debugCanvas);
+                    this._registerFunc = () => {
+                        this.drawDebugCanvas();
+                    };
+                    this._scene.registerBeforeRender(this._registerFunc);
+                }
+                if (this._registerFunc) {
+                    var workingArray = this.getByteFrequencyData();
+
+                    this._debugCanvasContext.fillStyle = 'rgb(0, 0, 0)';
+                    this._debugCanvasContext.fillRect(0, 0, this._debugCanvasWidth, this._debugCanvasHeight);
+
+                    // Draw the frequency domain chart.
+                    for (var i = 0; i < this.getFrequencyBinCount(); i++) {
+                        var value = workingArray[i];
+                        var percent = value / this.BARGRAPHAMPLITUDE;
+                        var height = this._debugCanvasHeight * percent;
+                        var offset = this._debugCanvasHeight - height - 1;
+                        var barWidth = this._debugCanvasWidth / this.getFrequencyBinCount();
+                        var hue = i / this.getFrequencyBinCount() * 360;
+                        this._debugCanvasContext.fillStyle = 'hsl(' + hue + ', 100%, 50%)';
+                        this._debugCanvasContext.fillRect(i * barWidth, offset, barWidth, height);
+                    }
+                }
+            }
+        }
+
+        public stopDebugCanvas() {
+            if (this._debugCanvas) {
+                this._scene.unregisterBeforeRender(this._registerFunc);
+                this._registerFunc = null;
+                document.body.removeChild(this._debugCanvas);
+                this._debugCanvas = null;
+                this._debugCanvasContext = null;
+            }
+        }
+
+        public connectAudioNodes(inputAudioNode: AudioNode, outputAudioNode: AudioNode) {
+            if (this._audioEngine.canUseWebAudio) {
+                inputAudioNode.connect(this._webAudioAnalyser);
+                this._webAudioAnalyser.connect(outputAudioNode);
+            }
+        }
+    }
+}

+ 17 - 10
Babylon/Audio/babylon.audioengine.js

@@ -1,23 +1,23 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var AudioEngine = (function () {
         function AudioEngine() {
             this.audioContext = null;
             this.canUseWebAudio = false;
-            try {
+            try  {
                 if (typeof AudioContext !== 'undefined') {
                     this.audioContext = new AudioContext();
                     this.canUseWebAudio = true;
-                }
-                else if (typeof webkitAudioContext !== 'undefined') {
+                } else if (typeof webkitAudioContext !== 'undefined') {
                     this.audioContext = new webkitAudioContext();
                     this.canUseWebAudio = true;
                 }
-            }
-            catch (e) {
+            } catch (e) {
                 this.canUseWebAudio = false;
+                BABYLON.Tools.Error("Your browser doesn't support Web Audio.");
             }
-            // create a global volume gain node 
+
+            // create a global volume gain node
             if (this.canUseWebAudio) {
                 this.masterGain = this.audioContext.createGain();
                 this.masterGain.gain.value = 1;
@@ -27,18 +27,25 @@ var BABYLON;
         AudioEngine.prototype.getGlobalVolume = function () {
             if (this.canUseWebAudio) {
                 return this.masterGain.gain.value;
-            }
-            else {
+            } else {
                 return -1;
             }
         };
+
         AudioEngine.prototype.setGlobalVolume = function (newVolume) {
             if (this.canUseWebAudio) {
                 this.masterGain.gain.value = newVolume;
             }
         };
+
+        AudioEngine.prototype.connectToAnalyser = function (analyser) {
+            if (this.canUseWebAudio) {
+                this.masterGain.disconnect();
+                analyser.connectAudioNodes(this.masterGain, this.audioContext.destination);
+            }
+        };
         return AudioEngine;
     })();
     BABYLON.AudioEngine = AudioEngine;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.audioengine.js.map
+//# sourceMappingURL=babylon.audioengine.js.map

+ 8 - 0
Babylon/Audio/babylon.audioengine.ts

@@ -16,6 +16,7 @@
                 } 
             } catch (e) {
                 this.canUseWebAudio = false;
+                BABYLON.Tools.Error("Your browser doesn't support Web Audio.");
             }
 
             // create a global volume gain node 
@@ -40,6 +41,13 @@
                 this.masterGain.gain.value = newVolume;
             }
         }
+
+        public connectToAnalyser(analyser: Analyser) {
+            if (this.canUseWebAudio) {
+                this.masterGain.disconnect();
+                analyser.connectAudioNodes(this.masterGain, this.audioContext.destination);
+            }
+        }
     }
 }
 

+ 80 - 55
Babylon/Audio/babylon.sound.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var Sound = (function () {
         /**
@@ -37,12 +37,12 @@ var BABYLON;
             this._scene = scene;
             this._audioEngine = this._scene.getEngine().getAudioEngine();
             this._readyToPlayCallback = readyToPlayCallback;
+
             // Default custom attenuation function is a linear attenuation
             this._customAttenuationFunction = function (currentVolume, currentDistance, maxDistance, refDistance, rolloffFactor) {
                 if (currentDistance < maxDistance) {
                     return currentVolume * (1 - currentDistance / maxDistance);
-                }
-                else {
+                } else {
                     return 0;
                 }
             };
@@ -58,13 +58,13 @@ var BABYLON;
                 this.distanceModel = options.distanceModel || "linear";
                 this.panningModel = options.panningModel || "HRTF";
             }
+
             if (this._audioEngine.canUseWebAudio) {
                 this._soundGain = this._audioEngine.audioContext.createGain();
                 this._soundGain.gain.value = this._volume;
                 if (this.spatialSound) {
                     this._createSpatialParameters();
-                }
-                else {
+                } else {
                     this._audioNode = this._soundGain;
                 }
                 this._scene.mainSoundTrack.AddSound(this);
@@ -72,17 +72,32 @@ var BABYLON;
                     BABYLON.Tools.LoadFile(urlOrArrayBuffer, function (data) {
                         _this._soundLoaded(data);
                     }, null, null, true);
-                }
-                else {
+                } else {
                     if (urlOrArrayBuffer instanceof ArrayBuffer) {
                         this._soundLoaded(urlOrArrayBuffer);
-                    }
-                    else {
+                    } else {
                         BABYLON.Tools.Error("Parameter must be a URL to the sound or an ArrayBuffer of the sound.");
                     }
                 }
             }
         }
+        Sound.prototype._soundLoaded = function (audioData) {
+            var _this = this;
+            this._isLoaded = true;
+            this._audioEngine.audioContext.decodeAudioData(audioData, function (buffer) {
+                _this._audioBuffer = buffer;
+                _this._isReadyToPlay = true;
+                if (_this.autoplay) {
+                    _this.play();
+                }
+                if (_this._readyToPlayCallback) {
+                    _this._readyToPlayCallback();
+                }
+            }, function (error) {
+                BABYLON.Tools.Error("Error while decoding audio data: " + error.err);
+            });
+        };
+
         Sound.prototype.updateOptions = function (options) {
             if (options) {
                 this.loop = options.loop || this.loop;
@@ -94,32 +109,37 @@ var BABYLON;
                 this.panningModel = options.panningModel || this.panningModel;
             }
         };
+
         Sound.prototype._createSpatialParameters = function () {
-            this._soundPanner = this._audioEngine.audioContext.createPanner();
-            if (this.useCustomAttenuation) {
-                // Tricks to disable in a way embedded Web Audio attenuation 
-                this._soundPanner.distanceModel = "linear";
-                this._soundPanner.maxDistance = Number.MAX_VALUE;
-                this._soundPanner.refDistance = 1;
-                this._soundPanner.rolloffFactor = 1;
-                this._soundPanner.panningModel = "HRTF";
-            }
-            else {
-                this._soundPanner.distanceModel = this.distanceModel;
-                this._soundPanner.maxDistance = this.maxDistance;
-                this._soundPanner.refDistance = this.refDistance;
-                this._soundPanner.rolloffFactor = this.rolloffFactor;
-                this._soundPanner.panningModel = this.panningModel;
+            if (this._audioEngine.canUseWebAudio) {
+                this._soundPanner = this._audioEngine.audioContext.createPanner();
+
+                if (this.useCustomAttenuation) {
+                    // Tricks to disable in a way embedded Web Audio attenuation
+                    this._soundPanner.distanceModel = "linear";
+                    this._soundPanner.maxDistance = Number.MAX_VALUE;
+                    this._soundPanner.refDistance = 1;
+                    this._soundPanner.rolloffFactor = 1;
+                    this._soundPanner.panningModel = "HRTF";
+                } else {
+                    this._soundPanner.distanceModel = this.distanceModel;
+                    this._soundPanner.maxDistance = this.maxDistance;
+                    this._soundPanner.refDistance = this.refDistance;
+                    this._soundPanner.rolloffFactor = this.rolloffFactor;
+                    this._soundPanner.panningModel = this.panningModel;
+                }
+                this._soundPanner.connect(this._soundGain);
+                this._audioNode = this._soundPanner;
             }
-            this._soundPanner.connect(this._soundGain);
-            this._audioNode = this._soundPanner;
         };
+
         Sound.prototype.connectToSoundTrackAudioNode = function (soundTrackAudioNode) {
             if (this._audioEngine.canUseWebAudio) {
                 this._audioNode.disconnect();
                 this._audioNode.connect(soundTrackAudioNode);
             }
         };
+
         /**
         * Transform this sound into a directional source
         * @param coneInnerAngle Size of the inner cone in degree
@@ -135,45 +155,54 @@ var BABYLON;
             this._coneOuterAngle = coneOuterAngle;
             this._coneOuterGain = coneOuterGain;
             this._isDirectional = true;
+
             if (this._isPlaying && this.loop) {
                 this.stop();
                 this.play();
             }
         };
+
         Sound.prototype.setPosition = function (newPosition) {
             this._position = newPosition;
+
             if (this._isPlaying && this.spatialSound) {
                 this._soundPanner.setPosition(this._position.x, this._position.y, this._position.z);
             }
         };
+
         Sound.prototype.setLocalDirectionToMesh = function (newLocalDirection) {
             this._localDirection = newLocalDirection;
+
             if (this._connectedMesh && this._isPlaying) {
                 this._updateDirection();
             }
         };
+
         Sound.prototype._updateDirection = function () {
             var mat = this._connectedMesh.getWorldMatrix();
             var direction = BABYLON.Vector3.TransformNormal(this._localDirection, mat);
             direction.normalize();
             this._soundPanner.setOrientation(direction.x, direction.y, direction.z);
         };
+
         Sound.prototype.updateDistanceFromListener = function () {
             if (this._connectedMesh && this.useCustomAttenuation) {
                 var distance = this._connectedMesh.getDistanceToCamera(this._scene.activeCamera);
                 this._soundGain.gain.value = this._customAttenuationFunction(this._volume, distance, this.maxDistance, this.refDistance, this.rolloffFactor);
             }
         };
+
         Sound.prototype.setAttenuationFunction = function (callback) {
             this._customAttenuationFunction = callback;
         };
+
         /**
         * Play the sound
         * @param time (optional) Start the sound after X seconds. Start immediately (0) by default.
         */
         Sound.prototype.play = function (time) {
             if (this._isReadyToPlay) {
-                try {
+                try  {
                     var startTime = time ? this._audioEngine.audioContext.currentTime + time : 0;
                     this._soundSource = this._audioEngine.audioContext.createBufferSource();
                     this._soundSource.buffer = this._audioBuffer;
@@ -185,8 +214,7 @@ var BABYLON;
                             this._soundPanner.coneOuterGain = this._coneOuterGain;
                             if (this._connectedMesh) {
                                 this._updateDirection();
-                            }
-                            else {
+                            } else {
                                 this._soundPanner.setOrientation(this._localDirection.x, this._localDirection.y, this._localDirection.z);
                             }
                         }
@@ -196,32 +224,42 @@ var BABYLON;
                     this.startTime = startTime;
                     this._soundSource.start(startTime, this.startOffset % this._soundSource.buffer.duration);
                     this._isPlaying = true;
-                }
-                catch (ex) {
+                } catch (ex) {
                     BABYLON.Tools.Error("Error while trying to play audio: " + this._name + ", " + ex.message);
                 }
             }
         };
+
         /**
         * Stop the sound
         * @param time (optional) Stop the sound after X seconds. Stop immediately (0) by default.
         */
         Sound.prototype.stop = function (time) {
-            var stopTime = time ? this._audioEngine.audioContext.currentTime + time : 0;
-            this._soundSource.stop(stopTime);
-            this._isPlaying = false;
+            if (this._isPlaying) {
+                var stopTime = time ? this._audioEngine.audioContext.currentTime + time : 0;
+                this._soundSource.stop(stopTime);
+                this._isPlaying = false;
+            }
         };
+
         Sound.prototype.pause = function () {
-            this._soundSource.stop(0);
-            this.startOffset += this._audioEngine.audioContext.currentTime - this.startTime;
+            if (this._isPlaying) {
+                this._soundSource.stop(0);
+                this.startOffset += this._audioEngine.audioContext.currentTime - this.startTime;
+            }
         };
+
         Sound.prototype.setVolume = function (newVolume) {
             this._volume = newVolume;
-            this._soundGain.gain.value = newVolume;
+            if (this._audioEngine.canUseWebAudio) {
+                this._soundGain.gain.value = newVolume;
+            }
         };
+
         Sound.prototype.getVolume = function () {
             return this._volume;
         };
+
         Sound.prototype.attachToMesh = function (meshToConnectTo) {
             var _this = this;
             this._connectedMesh = meshToConnectTo;
@@ -233,32 +271,19 @@ var BABYLON;
                     this.play();
                 }
             }
-            meshToConnectTo.registerAfterWorldMatrixUpdate(function (connectedMesh) { return _this._onRegisterAfterWorldMatrixUpdate(connectedMesh); });
+            meshToConnectTo.registerAfterWorldMatrixUpdate(function (connectedMesh) {
+                return _this._onRegisterAfterWorldMatrixUpdate(connectedMesh);
+            });
         };
+
         Sound.prototype._onRegisterAfterWorldMatrixUpdate = function (connectedMesh) {
             this.setPosition(connectedMesh.position);
             if (this._isDirectional && this._isPlaying) {
                 this._updateDirection();
             }
         };
-        Sound.prototype._soundLoaded = function (audioData) {
-            var _this = this;
-            this._isLoaded = true;
-            this._audioEngine.audioContext.decodeAudioData(audioData, function (buffer) {
-                _this._audioBuffer = buffer;
-                _this._isReadyToPlay = true;
-                if (_this.autoplay) {
-                    _this.play();
-                }
-                if (_this._readyToPlayCallback) {
-                    _this._readyToPlayCallback();
-                }
-            }, function (error) {
-                BABYLON.Tools.Error("Error while decoding audio data: " + error.err);
-            });
-        };
         return Sound;
     })();
     BABYLON.Sound = Sound;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.sound.js.map
+//# sourceMappingURL=babylon.sound.js.map

+ 43 - 35
Babylon/Audio/babylon.sound.ts

@@ -94,6 +94,18 @@
             }
         }
 
+        private _soundLoaded(audioData: ArrayBuffer) {
+            this._isLoaded = true;
+            this._audioEngine.audioContext.decodeAudioData(audioData, (buffer) => {
+                this._audioBuffer = buffer;
+                this._isReadyToPlay = true;
+                if (this.autoplay) { this.play(); }
+                if (this._readyToPlayCallback) { this._readyToPlayCallback(); }
+            }, function (error) {
+                    BABYLON.Tools.Error("Error while decoding audio data: " + error.err);
+                });
+        }
+
         public updateOptions(options) {
             if (options) {
                 this.loop = options.loop || this.loop;
@@ -107,25 +119,27 @@
         }
 
         private _createSpatialParameters() {
-            this._soundPanner = this._audioEngine.audioContext.createPanner();
+            if (this._audioEngine.canUseWebAudio) {
+                this._soundPanner = this._audioEngine.audioContext.createPanner();
 
-            if (this.useCustomAttenuation) {
-                // Tricks to disable in a way embedded Web Audio attenuation 
-                this._soundPanner.distanceModel = "linear";
-                this._soundPanner.maxDistance = Number.MAX_VALUE;
-                this._soundPanner.refDistance = 1;
-                this._soundPanner.rolloffFactor = 1;
-                this._soundPanner.panningModel = "HRTF";
-            }
-            else {
-                this._soundPanner.distanceModel = this.distanceModel;
-                this._soundPanner.maxDistance = this.maxDistance;
-                this._soundPanner.refDistance = this.refDistance;
-                this._soundPanner.rolloffFactor = this.rolloffFactor;
-                this._soundPanner.panningModel = this.panningModel;
+                if (this.useCustomAttenuation) {
+                    // Tricks to disable in a way embedded Web Audio attenuation 
+                    this._soundPanner.distanceModel = "linear";
+                    this._soundPanner.maxDistance = Number.MAX_VALUE;
+                    this._soundPanner.refDistance = 1;
+                    this._soundPanner.rolloffFactor = 1;
+                    this._soundPanner.panningModel = "HRTF";
+                }
+                else {
+                    this._soundPanner.distanceModel = this.distanceModel;
+                    this._soundPanner.maxDistance = this.maxDistance;
+                    this._soundPanner.refDistance = this.refDistance;
+                    this._soundPanner.rolloffFactor = this.rolloffFactor;
+                    this._soundPanner.panningModel = this.panningModel;
+                }
+                this._soundPanner.connect(this._soundGain);
+                this._audioNode = this._soundPanner;
             }
-            this._soundPanner.connect(this._soundGain);
-            this._audioNode = this._soundPanner;
         }
 
         public connectToSoundTrackAudioNode(soundTrackAudioNode: AudioNode) {
@@ -232,19 +246,25 @@
         * @param time (optional) Stop the sound after X seconds. Stop immediately (0) by default.
         */
         public stop(time?: number) {
-            var stopTime = time ? this._audioEngine.audioContext.currentTime + time : 0;
-            this._soundSource.stop(stopTime);
-            this._isPlaying = false;
+            if (this._isPlaying) {
+                var stopTime = time ? this._audioEngine.audioContext.currentTime + time : 0;
+                this._soundSource.stop(stopTime);
+                this._isPlaying = false;
+            }
         }
 
         public pause() {
-            this._soundSource.stop(0);
-            this.startOffset += this._audioEngine.audioContext.currentTime - this.startTime;
+            if (this._isPlaying) {
+                this._soundSource.stop(0);
+                this.startOffset += this._audioEngine.audioContext.currentTime - this.startTime;
+            }
         }
 
         public setVolume(newVolume: number) {
             this._volume = newVolume;
-            this._soundGain.gain.value = newVolume;
+            if (this._audioEngine.canUseWebAudio) {
+                this._soundGain.gain.value = newVolume;
+            }
         }
 
         public getVolume(): number {
@@ -270,17 +290,5 @@
                 this._updateDirection();
             }
         }
-
-        private _soundLoaded(audioData: ArrayBuffer) {
-            this._isLoaded = true;
-            this._audioEngine.audioContext.decodeAudioData(audioData, (buffer) => {
-                this._audioBuffer = buffer;
-                this._isReadyToPlay = true;
-                if (this.autoplay) { this.play(); }
-                if (this._readyToPlayCallback) { this._readyToPlayCallback(); }
-            }, function (error) {
-                    BABYLON.Tools.Error("Error while decoding audio data: " + error.err);
-                });
-        }
     }
 }

+ 7 - 4
Babylon/Audio/babylon.soundtrack.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var SoundTrack = (function () {
         function SoundTrack(scene, options) {
@@ -9,9 +9,11 @@ var BABYLON;
             this.soundCollection = new Array();
             if (this._audioEngine.canUseWebAudio) {
                 this._trackGain = this._audioEngine.audioContext.createGain();
+
                 //this._trackConvolver = this._audioEngine.audioContext.createConvolver();
                 //this._trackConvolver.connect(this._trackGain);
                 this._trackGain.connect(this._audioEngine.masterGain);
+
                 if (options) {
                     if (options.volume) {
                         this._trackGain.gain.value = options.volume;
@@ -31,20 +33,21 @@ var BABYLON;
             if (sound.soundTrackId) {
                 if (sound.soundTrackId === -1) {
                     this._scene.mainSoundTrack.RemoveSound(sound);
-                }
-                else {
+                } else {
                     this._scene.soundTracks[sound.soundTrackId].RemoveSound(sound);
                 }
             }
             this.soundCollection.push(sound);
             sound.soundTrackId = this.id;
         };
+
         SoundTrack.prototype.RemoveSound = function (sound) {
             var index = this.soundCollection.indexOf(sound);
             if (index !== -1) {
                 this.soundCollection.splice(index, 1);
             }
         };
+
         SoundTrack.prototype.setVolume = function (newVolume) {
             if (this._audioEngine.canUseWebAudio) {
                 this._trackGain.gain.value = newVolume;
@@ -54,4 +57,4 @@ var BABYLON;
     })();
     BABYLON.SoundTrack = SoundTrack;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.soundtrack.js.map
+//# sourceMappingURL=babylon.soundtrack.js.map

+ 20 - 6
Babylon/Bones/babylon.bone.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var Bone = (function () {
         function Bone(name, skeleton, parentBone, matrix) {
@@ -11,59 +11,73 @@ var BABYLON;
             this._skeleton = skeleton;
             this._matrix = matrix;
             this._baseMatrix = matrix;
+
             skeleton.bones.push(this);
+
             if (parentBone) {
                 this._parent = parentBone;
                 parentBone.children.push(this);
-            }
-            else {
+            } else {
                 this._parent = null;
             }
+
             this._updateDifferenceMatrix();
         }
         // Members
         Bone.prototype.getParent = function () {
             return this._parent;
         };
+
         Bone.prototype.getLocalMatrix = function () {
             return this._matrix;
         };
+
         Bone.prototype.getBaseMatrix = function () {
             return this._baseMatrix;
         };
+
         Bone.prototype.getWorldMatrix = function () {
             return this._worldTransform;
         };
+
         Bone.prototype.getInvertedAbsoluteTransform = function () {
             return this._invertedAbsoluteTransform;
         };
+
         Bone.prototype.getAbsoluteMatrix = function () {
             var matrix = this._matrix.clone();
             var parent = this._parent;
+
             while (parent) {
                 matrix = matrix.multiply(parent.getLocalMatrix());
                 parent = parent.getParent();
             }
+
             return matrix;
         };
+
         // Methods
         Bone.prototype.updateMatrix = function (matrix) {
             this._matrix = matrix;
             this._skeleton._markAsDirty();
+
             this._updateDifferenceMatrix();
         };
+
         Bone.prototype._updateDifferenceMatrix = function () {
             if (this._parent) {
                 this._matrix.multiplyToRef(this._parent._absoluteTransform, this._absoluteTransform);
-            }
-            else {
+            } else {
                 this._absoluteTransform.copyFrom(this._matrix);
             }
+
             this._absoluteTransform.invertToRef(this._invertedAbsoluteTransform);
+
             for (var index = 0; index < this.children.length; index++) {
                 this.children[index]._updateDifferenceMatrix();
             }
         };
+
         Bone.prototype.markAsDirty = function () {
             this._skeleton._markAsDirty();
         };
@@ -71,4 +85,4 @@ var BABYLON;
     })();
     BABYLON.Bone = Bone;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.bone.js.map
+//# sourceMappingURL=babylon.bone.js.map

+ 21 - 4
Babylon/Bones/babylon.skeleton.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var Skeleton = (function () {
         function Skeleton(name, id, scene) {
@@ -8,63 +8,80 @@ var BABYLON;
             this._isDirty = true;
             this._identity = BABYLON.Matrix.Identity();
             this.bones = [];
+
             this._scene = scene;
+
             scene.skeletons.push(this);
         }
         // Members
         Skeleton.prototype.getTransformMatrices = function () {
             return this._transformMatrices;
         };
+
         // Methods
         Skeleton.prototype._markAsDirty = function () {
             this._isDirty = true;
         };
+
         Skeleton.prototype.prepare = function () {
             if (!this._isDirty) {
                 return;
             }
+
             if (!this._transformMatrices || this._transformMatrices.length !== 16 * (this.bones.length + 1)) {
                 this._transformMatrices = new Float32Array(16 * (this.bones.length + 1));
             }
+
             for (var index = 0; index < this.bones.length; index++) {
                 var bone = this.bones[index];
                 var parentBone = bone.getParent();
+
                 if (parentBone) {
                     bone.getLocalMatrix().multiplyToRef(parentBone.getWorldMatrix(), bone.getWorldMatrix());
-                }
-                else {
+                } else {
                     bone.getWorldMatrix().copyFrom(bone.getLocalMatrix());
                 }
+
                 bone.getInvertedAbsoluteTransform().multiplyToArray(bone.getWorldMatrix(), this._transformMatrices, index * 16);
             }
+
             this._identity.copyToArray(this._transformMatrices, this.bones.length * 16);
+
             this._isDirty = false;
         };
+
         Skeleton.prototype.getAnimatables = function () {
             if (!this._animatables || this._animatables.length != this.bones.length) {
                 this._animatables = [];
+
                 for (var index = 0; index < this.bones.length; index++) {
                     this._animatables.push(this.bones[index]);
                 }
             }
+
             return this._animatables;
         };
+
         Skeleton.prototype.clone = function (name, id) {
             var result = new BABYLON.Skeleton(name, id || name, this._scene);
+
             for (var index = 0; index < this.bones.length; index++) {
                 var source = this.bones[index];
                 var parentBone = null;
+
                 if (source.getParent()) {
                     var parentIndex = this.bones.indexOf(source.getParent());
                     parentBone = result.bones[parentIndex];
                 }
+
                 var bone = new BABYLON.Bone(source.name, result, parentBone, source.getBaseMatrix());
                 BABYLON.Tools.DeepCopy(source.animations, bone.animations);
             }
+
             return result;
         };
         return Skeleton;
     })();
     BABYLON.Skeleton = Skeleton;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.skeleton.js.map
+//# sourceMappingURL=babylon.skeleton.js.map

+ 30 - 4
Babylon/Cameras/VR/babylon.oculusCamera.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -20,20 +20,27 @@ var BABYLON;
         PostProcessScaleFactor: 1.714605507808412,
         LensCenterOffset: 0.151976421
     };
+
     var _OculusInnerCamera = (function (_super) {
         __extends(_OculusInnerCamera, _super);
         function _OculusInnerCamera(name, position, scene, isLeftEye) {
             _super.call(this, name, position, scene);
             this._workMatrix = new BABYLON.Matrix();
             this._actualUp = new BABYLON.Vector3(0, 0, 0);
+
             // Constants
             this._aspectRatioAspectRatio = OculusRiftDevKit2013_Metric.HResolution / (2 * OculusRiftDevKit2013_Metric.VResolution);
             this._aspectRatioFov = (2 * Math.atan((OculusRiftDevKit2013_Metric.PostProcessScaleFactor * OculusRiftDevKit2013_Metric.VScreenSize) / (2 * OculusRiftDevKit2013_Metric.EyeToScreenDistance)));
+
             var hMeters = (OculusRiftDevKit2013_Metric.HScreenSize / 4) - (OculusRiftDevKit2013_Metric.LensSeparationDistance / 2);
             var h = (4 * hMeters) / OculusRiftDevKit2013_Metric.HScreenSize;
+
             this._hMatrix = BABYLON.Matrix.Translation(isLeftEye ? h : -h, 0, 0);
+
             this.viewport = new BABYLON.Viewport(isLeftEye ? 0 : 0.5, 0, 0.5, 1.0);
+
             this._preViewMatrix = BABYLON.Matrix.Translation(isLeftEye ? .5 * OculusRiftDevKit2013_Metric.InterpupillaryDistance : -.5 * OculusRiftDevKit2013_Metric.InterpupillaryDistance, 0, 0);
+
             // Postprocess
             var postProcess = new BABYLON.OculusDistortionCorrectionPostProcess("Oculus Distortion", this, !isLeftEye, OculusRiftDevKit2013_Metric);
         }
@@ -42,47 +49,62 @@ var BABYLON;
             this._workMatrix.multiplyToRef(this._hMatrix, this._projectionMatrix);
             return this._projectionMatrix;
         };
+
         _OculusInnerCamera.prototype._getViewMatrix = function () {
             BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
+
             BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
             BABYLON.Vector3.TransformNormalToRef(this.upVector, this._cameraRotationMatrix, this._actualUp);
+
             // Computing target and final matrix
             this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
+
             BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this._actualUp, this._workMatrix);
+
             this._workMatrix.multiplyToRef(this._preViewMatrix, this._viewMatrix);
             return this._viewMatrix;
         };
         return _OculusInnerCamera;
     })(BABYLON.FreeCamera);
+
     var OculusCamera = (function (_super) {
         __extends(OculusCamera, _super);
         function OculusCamera(name, position, scene) {
             _super.call(this, name, position, scene);
+
             this._leftCamera = new _OculusInnerCamera(name + "_left", position.clone(), scene, true);
             this._rightCamera = new _OculusInnerCamera(name + "_right", position.clone(), scene, false);
+
             this.subCameras.push(this._leftCamera);
             this.subCameras.push(this._rightCamera);
+
             this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
         }
         OculusCamera.prototype._update = function () {
             this._leftCamera.position.copyFrom(this.position);
             this._rightCamera.position.copyFrom(this.position);
+
             this._updateCamera(this._leftCamera);
             this._updateCamera(this._rightCamera);
+
             _super.prototype._update.call(this);
         };
+
         OculusCamera.prototype._updateCamera = function (camera) {
             camera.minZ = this.minZ;
             camera.maxZ = this.maxZ;
+
             camera.rotation.x = this.rotation.x;
             camera.rotation.y = this.rotation.y;
             camera.rotation.z = this.rotation.z;
         };
+
         // Oculus events
         OculusCamera.prototype._onOrientationEvent = function (evt) {
             var yaw = evt.alpha / 180 * Math.PI;
             var pitch = evt.beta / 180 * Math.PI;
             var roll = evt.gamma / 180 * Math.PI;
+
             if (!this._offsetOrientation) {
                 this._offsetOrientation = {
                     yaw: yaw,
@@ -90,26 +112,30 @@ var BABYLON;
                     roll: roll
                 };
                 return;
-            }
-            else {
+            } else {
                 this.rotation.y += yaw - this._offsetOrientation.yaw;
                 this.rotation.x += pitch - this._offsetOrientation.pitch;
                 this.rotation.z += this._offsetOrientation.roll - roll;
+
                 this._offsetOrientation.yaw = yaw;
                 this._offsetOrientation.pitch = pitch;
                 this._offsetOrientation.roll = roll;
             }
         };
+
         OculusCamera.prototype.attachControl = function (element, noPreventDefault) {
             _super.prototype.attachControl.call(this, element, noPreventDefault);
+
             window.addEventListener("deviceorientation", this._deviceOrientationHandler);
         };
+
         OculusCamera.prototype.detachControl = function (element) {
             _super.prototype.detachControl.call(this, element);
+
             window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
         };
         return OculusCamera;
     })(BABYLON.FreeCamera);
     BABYLON.OculusCamera = OculusCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.oculusCamera.js.map
+//# sourceMappingURL=babylon.oculusCamera.js.map

+ 35 - 4
Babylon/Cameras/VR/babylon.oculusGamepadCamera.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -20,20 +20,27 @@ var BABYLON;
         PostProcessScaleFactor: 1.714605507808412,
         LensCenterOffset: 0.151976421
     };
+
     var _OculusInnerGamepadCamera = (function (_super) {
         __extends(_OculusInnerGamepadCamera, _super);
         function _OculusInnerGamepadCamera(name, position, scene, isLeftEye) {
             _super.call(this, name, position, scene);
             this._workMatrix = new BABYLON.Matrix();
             this._actualUp = new BABYLON.Vector3(0, 0, 0);
+
             // Constants
             this._aspectRatioAspectRatio = OculusRiftDevKit2013_Metric.HResolution / (2 * OculusRiftDevKit2013_Metric.VResolution);
             this._aspectRatioFov = (2 * Math.atan((OculusRiftDevKit2013_Metric.PostProcessScaleFactor * OculusRiftDevKit2013_Metric.VScreenSize) / (2 * OculusRiftDevKit2013_Metric.EyeToScreenDistance)));
+
             var hMeters = (OculusRiftDevKit2013_Metric.HScreenSize / 4) - (OculusRiftDevKit2013_Metric.LensSeparationDistance / 2);
             var h = (4 * hMeters) / OculusRiftDevKit2013_Metric.HScreenSize;
+
             this._hMatrix = BABYLON.Matrix.Translation(isLeftEye ? h : -h, 0, 0);
+
             this.viewport = new BABYLON.Viewport(isLeftEye ? 0 : 0.5, 0, 0.5, 1.0);
+
             this._preViewMatrix = BABYLON.Matrix.Translation(isLeftEye ? .5 * OculusRiftDevKit2013_Metric.InterpupillaryDistance : -.5 * OculusRiftDevKit2013_Metric.InterpupillaryDistance, 0, 0);
+
             // Postprocess
             var postProcess = new BABYLON.OculusDistortionCorrectionPostProcess("Oculus Distortion", this, !isLeftEye, OculusRiftDevKit2013_Metric);
         }
@@ -42,18 +49,24 @@ var BABYLON;
             this._workMatrix.multiplyToRef(this._hMatrix, this._projectionMatrix);
             return this._projectionMatrix;
         };
+
         _OculusInnerGamepadCamera.prototype._getViewMatrix = function () {
             BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
+
             BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
             BABYLON.Vector3.TransformNormalToRef(this.upVector, this._cameraRotationMatrix, this._actualUp);
+
             // Computing target and final matrix
             this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
+
             BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this._actualUp, this._workMatrix);
+
             this._workMatrix.multiplyToRef(this._preViewMatrix, this._viewMatrix);
             return this._viewMatrix;
         };
         return _OculusInnerGamepadCamera;
     })(BABYLON.FreeCamera);
+
     var OculusGamepadCamera = (function (_super) {
         __extends(OculusGamepadCamera, _super);
         function OculusGamepadCamera(name, position, scene) {
@@ -61,10 +74,13 @@ var BABYLON;
             _super.call(this, name, position, scene);
             this.angularSensibility = 200;
             this.moveSensibility = 75;
+
             this._leftCamera = new _OculusInnerGamepadCamera(name + "_left", position.clone(), scene, true);
             this._rightCamera = new _OculusInnerGamepadCamera(name + "_right", position.clone(), scene, false);
+
             this.subCameras.push(this._leftCamera);
             this.subCameras.push(this._rightCamera);
+
             this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
             this._gamepads = new BABYLON.Gamepads(function (gamepad) {
                 _this._onNewGameConnected(gamepad);
@@ -76,38 +92,48 @@ var BABYLON;
                 this._gamepad = gamepad;
             }
         };
+
         OculusGamepadCamera.prototype._update = function () {
             this._leftCamera.position.copyFrom(this.position);
             this._rightCamera.position.copyFrom(this.position);
+
             this._updateCamera(this._leftCamera);
             this._updateCamera(this._rightCamera);
+
             _super.prototype._update.call(this);
         };
+
         OculusGamepadCamera.prototype._checkInputs = function () {
             if (!this._gamepad) {
                 return;
             }
+
             var LSValues = this._gamepad.leftStick;
             var normalizedLX = LSValues.x / this.moveSensibility;
             var normalizedLY = LSValues.y / this.moveSensibility;
             LSValues.x = Math.abs(normalizedLX) > 0.005 ? 0 + normalizedLX : 0;
             LSValues.y = Math.abs(normalizedLY) > 0.005 ? 0 + normalizedLY : 0;
+
             var cameraTransform = BABYLON.Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
             var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(LSValues.x, 0, -LSValues.y), cameraTransform);
             this.cameraDirection = this.cameraDirection.add(deltaTransform);
         };
+
         OculusGamepadCamera.prototype._updateCamera = function (camera) {
             camera.minZ = this.minZ;
             camera.maxZ = this.maxZ;
+
             camera.rotation.x = this.rotation.x;
             camera.rotation.y = this.rotation.y;
             camera.rotation.z = this.rotation.z;
         };
+
         // Oculus events
         OculusGamepadCamera.prototype._onOrientationEvent = function (evt) {
             var yaw = evt.alpha / 180 * Math.PI;
             var pitch = evt.beta / 180 * Math.PI;
             var roll = evt.gamma / 180 * Math.PI;
+
             if (!this._offsetOrientation) {
                 this._offsetOrientation = {
                     yaw: yaw,
@@ -115,24 +141,29 @@ var BABYLON;
                     roll: roll
                 };
                 return;
-            }
-            else {
+            } else {
                 this.rotation.y += yaw - this._offsetOrientation.yaw;
                 this.rotation.x += pitch - this._offsetOrientation.pitch;
                 this.rotation.z += this._offsetOrientation.roll - roll;
+
                 this._offsetOrientation.yaw = yaw;
                 this._offsetOrientation.pitch = pitch;
                 this._offsetOrientation.roll = roll;
             }
         };
+
         OculusGamepadCamera.prototype.attachControl = function (element, noPreventDefault) {
             _super.prototype.attachControl.call(this, element, noPreventDefault);
+
             window.addEventListener("deviceorientation", this._deviceOrientationHandler);
         };
+
         OculusGamepadCamera.prototype.detachControl = function (element) {
             _super.prototype.detachControl.call(this, element);
+
             window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
         };
+
         OculusGamepadCamera.prototype.dispose = function () {
             this._gamepads.dispose();
             _super.prototype.dispose.call(this);
@@ -141,4 +172,4 @@ var BABYLON;
     })(BABYLON.FreeCamera);
     BABYLON.OculusGamepadCamera = OculusGamepadCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.oculusGamepadCamera.js.map
+//# sourceMappingURL=babylon.oculusGamepadCamera.js.map

+ 4 - 3
Babylon/Cameras/VR/babylon.vrDeviceOrientationCamera.js

@@ -18,13 +18,14 @@ var BABYLON;
             this._alpha = +evt.alpha | 0;
             this._beta = +evt.beta | 0;
             this._gamma = +evt.gamma | 0;
+
             if (this._gamma < 0) {
                 this._gamma = 90 + this._gamma;
-            }
-            else {
+            } else {
                 // Incline it in the correct angle.
                 this._gamma = 270 - this._gamma;
             }
+
             this.rotation.x = this._gamma / 180.0 * Math.PI;
             this.rotation.y = -this._alpha / 180.0 * Math.PI;
             this.rotation.z = this._beta / 180.0 * Math.PI;
@@ -33,4 +34,4 @@ var BABYLON;
     })(BABYLON.OculusCamera);
     BABYLON.VRDeviceOrientationCamera = VRDeviceOrientationCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.vrDeviceOrientationCamera.js.map
+//# sourceMappingURL=babylon.vrDeviceOrientationCamera.js.map

+ 13 - 3
Babylon/Cameras/VR/babylon.webVRCamera.js

@@ -21,44 +21,54 @@ var BABYLON;
         WebVRCamera.prototype._getWebVRDevices = function (devices) {
             var size = devices.length;
             var i = 0;
+
             // Reset devices.
             this._sensorDevice = null;
             this._hmdDevice = null;
+
             while (i < size && this._hmdDevice === null) {
                 if (devices[i] instanceof HMDVRDevice) {
                     this._hmdDevice = devices[i];
                 }
                 i++;
             }
+
             i = 0;
+
             while (i < size && this._sensorDevice === null) {
                 if (devices[i] instanceof PositionSensorVRDevice && (!this._hmdDevice || devices[i].hardwareUnitId === this._hmdDevice.hardwareUnitId)) {
                     this._sensorDevice = devices[i];
                 }
                 i++;
             }
+
             this._vrEnabled = this._sensorDevice && this._hmdDevice ? true : false;
         };
+
         WebVRCamera.prototype._update = function () {
             if (this._vrEnabled) {
                 this._cacheState = this._sensorDevice.getState();
                 this._cacheQuaternion.copyFromFloats(this._cacheState.orientation.x, this._cacheState.orientation.y, this._cacheState.orientation.z, this._cacheState.orientation.w);
                 this._cacheQuaternion.toEulerAnglesToRef(this._cacheRotation);
+
                 this.rotation.x = -this._cacheRotation.z;
                 this.rotation.y = -this._cacheRotation.y;
                 this.rotation.z = this._cacheRotation.x;
             }
+
             _super.prototype._update.call(this);
         };
+
         WebVRCamera.prototype.attachControl = function (element, noPreventDefault) {
             _super.prototype.attachControl.call(this, element, noPreventDefault);
+
             if (navigator.getVRDevices) {
                 navigator.getVRDevices().then(this._getWebVRDevices);
-            }
-            else if (navigator.mozGetVRDevices) {
+            } else if (navigator.mozGetVRDevices) {
                 navigator.mozGetVRDevices(this._getWebVRDevices);
             }
         };
+
         WebVRCamera.prototype.detachControl = function (element) {
             _super.prototype.detachControl.call(this, element);
             this._vrEnabled = false;
@@ -67,4 +77,4 @@ var BABYLON;
     })(BABYLON.OculusCamera);
     BABYLON.WebVRCamera = WebVRCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.webVRCamera.js.map
+//# sourceMappingURL=babylon.webVRCamera.js.map

+ 29 - 2
Babylon/Cameras/babylon.anaglyphCamera.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -8,75 +8,102 @@ var BABYLON;
 (function (BABYLON) {
     var buildCamera = function (that, name) {
         that._leftCamera.isIntermediate = true;
+
         that.subCameras.push(that._leftCamera);
         that.subCameras.push(that._rightCamera);
+
         that._leftTexture = new BABYLON.PassPostProcess(name + "_leftTexture", 1.0, that._leftCamera);
         that._anaglyphPostProcess = new BABYLON.AnaglyphPostProcess(name + "_anaglyph", 1.0, that._rightCamera);
+
         that._anaglyphPostProcess.onApply = function (effect) {
             effect.setTextureFromPostProcess("leftSampler", that._leftTexture);
         };
+
         that._update();
     };
+
     var AnaglyphArcRotateCamera = (function (_super) {
         __extends(AnaglyphArcRotateCamera, _super);
         // ANY
         function AnaglyphArcRotateCamera(name, alpha, beta, radius, target, eyeSpace, scene) {
             _super.call(this, name, alpha, beta, radius, target, scene);
+
             this._eyeSpace = BABYLON.Tools.ToRadians(eyeSpace);
+
             this._leftCamera = new BABYLON.ArcRotateCamera(name + "_left", alpha - this._eyeSpace, beta, radius, target, scene);
             this._rightCamera = new BABYLON.ArcRotateCamera(name + "_right", alpha + this._eyeSpace, beta, radius, target, scene);
+
             buildCamera(this, name);
         }
         AnaglyphArcRotateCamera.prototype._update = function () {
             this._updateCamera(this._leftCamera);
             this._updateCamera(this._rightCamera);
+
             this._leftCamera.alpha = this.alpha - this._eyeSpace;
             this._rightCamera.alpha = this.alpha + this._eyeSpace;
+
             _super.prototype._update.call(this);
         };
+
         AnaglyphArcRotateCamera.prototype._updateCamera = function (camera) {
             camera.beta = this.beta;
             camera.radius = this.radius;
+
             camera.minZ = this.minZ;
             camera.maxZ = this.maxZ;
+
             camera.fov = this.fov;
+
             camera.target = this.target;
         };
         return AnaglyphArcRotateCamera;
     })(BABYLON.ArcRotateCamera);
     BABYLON.AnaglyphArcRotateCamera = AnaglyphArcRotateCamera;
+
     var AnaglyphFreeCamera = (function (_super) {
         __extends(AnaglyphFreeCamera, _super);
         function AnaglyphFreeCamera(name, position, eyeSpace, scene) {
             _super.call(this, name, position, scene);
+
             this._eyeSpace = BABYLON.Tools.ToRadians(eyeSpace);
             this._transformMatrix = new BABYLON.Matrix();
+
             this._leftCamera = new BABYLON.FreeCamera(name + "_left", position.clone(), scene);
             this._rightCamera = new BABYLON.FreeCamera(name + "_right", position.clone(), scene);
+
             buildCamera(this, name);
         }
         AnaglyphFreeCamera.prototype._getSubCameraPosition = function (eyeSpace, result) {
             var target = this.getTarget();
             BABYLON.Matrix.Translation(-target.x, -target.y, -target.z).multiplyToRef(BABYLON.Matrix.RotationY(eyeSpace), this._transformMatrix);
+
             this._transformMatrix = this._transformMatrix.multiply(BABYLON.Matrix.Translation(target.x, target.y, target.z));
+
             BABYLON.Vector3.TransformCoordinatesToRef(this.position, this._transformMatrix, result);
         };
+
         AnaglyphFreeCamera.prototype._update = function () {
             this._getSubCameraPosition(-this._eyeSpace, this._leftCamera.position);
             this._getSubCameraPosition(this._eyeSpace, this._rightCamera.position);
+
             this._updateCamera(this._leftCamera);
             this._updateCamera(this._rightCamera);
+
             _super.prototype._update.call(this);
         };
+
         AnaglyphFreeCamera.prototype._updateCamera = function (camera) {
             camera.minZ = this.minZ;
             camera.maxZ = this.maxZ;
+
             camera.fov = this.fov;
+
             camera.viewport = this.viewport;
+
             camera.setTarget(this.getTarget());
         };
         return AnaglyphFreeCamera;
     })(BABYLON.FreeCamera);
     BABYLON.AnaglyphFreeCamera = AnaglyphFreeCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.anaglyphCamera.js.map
+//# sourceMappingURL=babylon.anaglyphCamera.js.map

+ 104 - 13
Babylon/Cameras/babylon.arcRotateCamera.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -7,6 +7,7 @@ var __extends = this.__extends || function (d, b) {
 var BABYLON;
 (function (BABYLON) {
     var eventPrefix = BABYLON.Tools.GetPointerPrefix();
+
     var ArcRotateCamera = (function (_super) {
         __extends(ArcRotateCamera, _super);
         function ArcRotateCamera(name, alpha, beta, radius, target, scene) {
@@ -44,11 +45,13 @@ var BABYLON;
             // value for pinch step scaling
             // set to 20 by default
             this.pinchPrecision = 20;
+
             this.getViewMatrix();
         }
         ArcRotateCamera.prototype._getTargetPosition = function () {
             return this.target.position || this.target;
         };
+
         // Cache
         ArcRotateCamera.prototype._initCache = function () {
             _super.prototype._initCache.call(this);
@@ -58,51 +61,65 @@ var BABYLON;
             this._cache.radius = undefined;
             this._cache.targetScreenOffset = undefined;
         };
+
         ArcRotateCamera.prototype._updateCache = function (ignoreParentClass) {
             if (!ignoreParentClass) {
                 _super.prototype._updateCache.call(this);
             }
+
             this._cache.target.copyFrom(this._getTargetPosition());
             this._cache.alpha = this.alpha;
             this._cache.beta = this.beta;
             this._cache.radius = this.radius;
             this._cache.targetScreenOffset = this.targetScreenOffset.clone();
         };
+
         // Synchronized
         ArcRotateCamera.prototype._isSynchronizedViewMatrix = function () {
             if (!_super.prototype._isSynchronizedViewMatrix.call(this))
                 return false;
+
             return this._cache.target.equals(this._getTargetPosition()) && this._cache.alpha === this.alpha && this._cache.beta === this.beta && this._cache.radius === this.radius && this._cache.targetScreenOffset.equals(this.targetScreenOffset);
         };
+
         // Methods
         ArcRotateCamera.prototype.attachControl = function (element, noPreventDefault) {
             var _this = this;
             var previousPosition;
             var pointerId;
+
             // to know if pinch started
             var pinchStarted = false;
+
             // two pinch point on X
             // that will use for find if user action is pinch open or pinch close
             var pinchPointX1, pinchPointX2;
+
             if (this._attachedElement) {
                 return;
             }
             this._attachedElement = element;
+
             var engine = this.getEngine();
+
             if (this._onPointerDown === undefined) {
                 this._onPointerDown = function (evt) {
                     if (pointerId) {
                         return;
                     }
+
                     pointerId = evt.pointerId;
+
                     previousPosition = {
                         x: evt.clientX,
                         y: evt.clientY
                     };
+
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
                 };
+
                 this._onPointerUp = function (evt) {
                     previousPosition = null;
                     pointerId = null;
@@ -110,67 +127,84 @@ var BABYLON;
                         evt.preventDefault();
                     }
                 };
+
                 this._onPointerMove = function (evt) {
                     if (!previousPosition) {
                         return;
                     }
+
                     if (pointerId !== evt.pointerId) {
                         return;
                     }
+
                     // return pinch is started
                     if (pinchStarted) {
                         return;
                     }
+
                     var offsetX = evt.clientX - previousPosition.x;
                     var offsetY = evt.clientY - previousPosition.y;
+
                     _this.inertialAlphaOffset -= offsetX / _this.angularSensibility;
                     _this.inertialBetaOffset -= offsetY / _this.angularSensibility;
+
                     previousPosition = {
                         x: evt.clientX,
                         y: evt.clientY
                     };
+
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
                 };
+
                 this._onMouseMove = function (evt) {
                     if (!engine.isPointerLock) {
                         return;
                     }
+
                     // return pinch is started
                     if (pinchStarted) {
                         return;
                     }
+
                     var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
                     var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
+
                     _this.inertialAlphaOffset -= offsetX / _this.angularSensibility;
                     _this.inertialBetaOffset -= offsetY / _this.angularSensibility;
+
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
                 };
+
                 this._wheel = function (event) {
                     var delta = 0;
                     if (event.wheelDelta) {
                         delta = event.wheelDelta / (_this.wheelPrecision * 40);
-                    }
-                    else if (event.detail) {
+                    } else if (event.detail) {
                         delta = -event.detail / _this.wheelPrecision;
                     }
+
                     if (delta)
                         _this.inertialRadiusOffset += delta;
+
                     if (event.preventDefault) {
                         if (!noPreventDefault) {
                             event.preventDefault();
                         }
                     }
                 };
+
                 this._onKeyDown = function (evt) {
                     if (_this.keysUp.indexOf(evt.keyCode) !== -1 || _this.keysDown.indexOf(evt.keyCode) !== -1 || _this.keysLeft.indexOf(evt.keyCode) !== -1 || _this.keysRight.indexOf(evt.keyCode) !== -1) {
                         var index = _this._keys.indexOf(evt.keyCode);
+
                         if (index === -1) {
                             _this._keys.push(evt.keyCode);
                         }
+
                         if (evt.preventDefault) {
                             if (!noPreventDefault) {
                                 evt.preventDefault();
@@ -178,12 +212,15 @@ var BABYLON;
                         }
                     }
                 };
+
                 this._onKeyUp = function (evt) {
                     if (_this.keysUp.indexOf(evt.keyCode) !== -1 || _this.keysDown.indexOf(evt.keyCode) !== -1 || _this.keysLeft.indexOf(evt.keyCode) !== -1 || _this.keysRight.indexOf(evt.keyCode) !== -1) {
                         var index = _this._keys.indexOf(evt.keyCode);
+
                         if (index >= 0) {
                             _this._keys.splice(index, 1);
                         }
+
                         if (evt.preventDefault) {
                             if (!noPreventDefault) {
                                 evt.preventDefault();
@@ -191,22 +228,28 @@ var BABYLON;
                         }
                     }
                 };
+
                 this._onLostFocus = function () {
                     _this._keys = [];
                     pointerId = null;
                 };
+
                 this._onGestureStart = function (e) {
                     if (window.MSGesture === undefined) {
                         return;
                     }
+
                     if (!_this._MSGestureHandler) {
                         _this._MSGestureHandler = new MSGesture();
                         _this._MSGestureHandler.target = element;
                     }
+
                     _this._MSGestureHandler.addPointer(e.pointerId);
                 };
+
                 this._onGesture = function (e) {
                     _this.radius *= e.scale;
+
                     if (e.preventDefault) {
                         if (!noPreventDefault) {
                             e.stopPropagation();
@@ -214,6 +257,7 @@ var BABYLON;
                         }
                     }
                 };
+
                 this._reset = function () {
                     _this._keys = [];
                     _this.inertialAlphaOffset = 0;
@@ -222,6 +266,7 @@ var BABYLON;
                     previousPosition = null;
                     pointerId = null;
                 };
+
                 this._touchStart = function (event) {
                     if (event.touches.length === 2) {
                         //-- start pinch if two fingers on the screen
@@ -241,33 +286,42 @@ var BABYLON;
                         _this._pinchEnd(event);
                     }
                 };
+
                 this._pinchStart = function (event) {
                     // save origin touch point
                     pinchPointX1 = event.touches[0].clientX;
                     pinchPointX2 = event.touches[1].clientX;
-                    // block the camera 
+
+                    // block the camera
                     // if not it rotate around target during pinch
                     pinchStarted = true;
                 };
                 this._pinchMove = function (event) {
                     // variable for new camera's radius
                     var delta = 0;
+
                     // variables to know if pinch open or pinch close
                     var direction = 1;
                     var distanceXOrigine, distanceXNow;
+
                     if (event.touches.length !== 2)
                         return;
+
                     // calculate absolute distances of the two fingers
                     distanceXOrigine = Math.abs(pinchPointX1 - pinchPointX2);
                     distanceXNow = Math.abs(event.touches[0].clientX - event.touches[1].clientX);
+
                     // if distanceXNow < distanceXOrigine -> pinch close so direction = -1
                     if (distanceXNow < distanceXOrigine) {
                         direction = -1;
                     }
+
                     // calculate new radius
                     delta = (_this.pinchPrecision / (_this.wheelPrecision * 40)) * direction;
+
                     // set new radius
                     _this.inertialRadiusOffset -= delta;
+
                     // save origin touch point
                     pinchPointX1 = event.touches[0].clientX;
                     pinchPointX2 = event.touches[1].clientX;
@@ -277,6 +331,7 @@ var BABYLON;
                     pinchStarted = false;
                 };
             }
+
             element.addEventListener(eventPrefix + "down", this._onPointerDown, false);
             element.addEventListener(eventPrefix + "up", this._onPointerUp, false);
             element.addEventListener(eventPrefix + "out", this._onPointerUp, false);
@@ -286,20 +341,24 @@ var BABYLON;
             element.addEventListener("MSGestureChange", this._onGesture, false);
             element.addEventListener('mousewheel', this._wheel, false);
             element.addEventListener('DOMMouseScroll', this._wheel, false);
+
             // pinch
             element.addEventListener('touchstart', this._touchStart, false);
             element.addEventListener('touchmove', this._touchMove, false);
             element.addEventListener('touchend', this._touchEnd, false);
+
             BABYLON.Tools.RegisterTopRootEvents([
                 { name: "keydown", handler: this._onKeyDown },
                 { name: "keyup", handler: this._onKeyUp },
                 { name: "blur", handler: this._onLostFocus }
             ]);
         };
+
         ArcRotateCamera.prototype.detachControl = function (element) {
             if (this._attachedElement != element) {
                 return;
             }
+
             element.removeEventListener(eventPrefix + "down", this._onPointerDown);
             element.removeEventListener(eventPrefix + "up", this._onPointerUp);
             element.removeEventListener(eventPrefix + "out", this._onPointerUp);
@@ -309,52 +368,61 @@ var BABYLON;
             element.removeEventListener("MSGestureChange", this._onGesture);
             element.removeEventListener('mousewheel', this._wheel);
             element.removeEventListener('DOMMouseScroll', this._wheel);
+
             // pinch
             element.removeEventListener('touchstart', this._touchStart);
             element.removeEventListener('touchmove', this._touchMove);
             element.removeEventListener('touchend', this._touchEnd);
+
             BABYLON.Tools.UnregisterTopRootEvents([
                 { name: "keydown", handler: this._onKeyDown },
                 { name: "keyup", handler: this._onKeyUp },
                 { name: "blur", handler: this._onLostFocus }
             ]);
+
             this._MSGestureHandler = null;
             this._attachedElement = null;
+
             if (this._reset) {
                 this._reset();
             }
         };
+
         ArcRotateCamera.prototype._update = function () {
             for (var index = 0; index < this._keys.length; index++) {
                 var keyCode = this._keys[index];
+
                 if (this.keysLeft.indexOf(keyCode) !== -1) {
                     this.inertialAlphaOffset -= 0.01;
-                }
-                else if (this.keysUp.indexOf(keyCode) !== -1) {
+                } else if (this.keysUp.indexOf(keyCode) !== -1) {
                     this.inertialBetaOffset -= 0.01;
-                }
-                else if (this.keysRight.indexOf(keyCode) !== -1) {
+                } else if (this.keysRight.indexOf(keyCode) !== -1) {
                     this.inertialAlphaOffset += 0.01;
-                }
-                else if (this.keysDown.indexOf(keyCode) !== -1) {
+                } else if (this.keysDown.indexOf(keyCode) !== -1) {
                     this.inertialBetaOffset += 0.01;
                 }
             }
+
             // Inertia
             if (this.inertialAlphaOffset != 0 || this.inertialBetaOffset != 0 || this.inertialRadiusOffset != 0) {
                 this.alpha += this.inertialAlphaOffset;
                 this.beta += this.inertialBetaOffset;
                 this.radius -= this.inertialRadiusOffset;
+
                 this.inertialAlphaOffset *= this.inertia;
                 this.inertialBetaOffset *= this.inertia;
                 this.inertialRadiusOffset *= this.inertia;
+
                 if (Math.abs(this.inertialAlphaOffset) < BABYLON.Engine.Epsilon)
                     this.inertialAlphaOffset = 0;
+
                 if (Math.abs(this.inertialBetaOffset) < BABYLON.Engine.Epsilon)
                     this.inertialBetaOffset = 0;
+
                 if (Math.abs(this.inertialRadiusOffset) < BABYLON.Engine.Epsilon)
                     this.inertialRadiusOffset = 0;
             }
+
             // Limits
             if (this.lowerAlphaLimit && this.alpha < this.lowerAlphaLimit) {
                 this.alpha = this.lowerAlphaLimit;
@@ -375,72 +443,95 @@ var BABYLON;
                 this.radius = this.upperRadiusLimit;
             }
         };
+
         ArcRotateCamera.prototype.setPosition = function (position) {
             var radiusv3 = position.subtract(this._getTargetPosition());
             this.radius = radiusv3.length();
+
             // Alpha
             this.alpha = Math.acos(radiusv3.x / Math.sqrt(Math.pow(radiusv3.x, 2) + Math.pow(radiusv3.z, 2)));
+
             if (radiusv3.z < 0) {
                 this.alpha = 2 * Math.PI - this.alpha;
             }
+
             // Beta
             this.beta = Math.acos(radiusv3.y / this.radius);
         };
+
         ArcRotateCamera.prototype._getViewMatrix = function () {
             // Compute
             var cosa = Math.cos(this.alpha);
             var sina = Math.sin(this.alpha);
             var cosb = Math.cos(this.beta);
             var sinb = Math.sin(this.beta);
+
             var target = this._getTargetPosition();
+
             target.addToRef(new BABYLON.Vector3(this.radius * cosa * sinb, this.radius * cosb, this.radius * sina * sinb), this.position);
+
             if (this.checkCollisions) {
                 this._collider.radius = this.collisionRadius;
                 this.position.subtractToRef(this._previousPosition, this._collisionVelocity);
+
                 this.getScene()._getNewPosition(this._previousPosition, this._collisionVelocity, this._collider, 3, this._newPosition);
+
                 if (!this._newPosition.equalsWithEpsilon(this.position)) {
                     this.position.copyFrom(this._previousPosition);
+
                     this.alpha = this._previousAlpha;
                     this.beta = this._previousBeta;
                     this.radius = this._previousRadius;
+
                     if (this.onCollide) {
                         this.onCollide(this._collider.collidedMesh);
                     }
                 }
             }
+
             BABYLON.Matrix.LookAtLHToRef(this.position, target, this.upVector, this._viewMatrix);
+
             this._previousAlpha = this.alpha;
             this._previousBeta = this.beta;
             this._previousRadius = this.radius;
             this._previousPosition.copyFrom(this.position);
+
             this._viewMatrix.m[12] += this.targetScreenOffset.x;
             this._viewMatrix.m[13] += this.targetScreenOffset.y;
+
             return this._viewMatrix;
         };
+
         ArcRotateCamera.prototype.zoomOn = function (meshes) {
             meshes = meshes || this.getScene().meshes;
+
             var minMaxVector = BABYLON.Mesh.MinMax(meshes);
             var distance = BABYLON.Vector3.Distance(minMaxVector.min, minMaxVector.max);
+
             this.radius = distance * this.zoomOnFactor;
+
             this.focusOn({ min: minMaxVector.min, max: minMaxVector.max, distance: distance });
         };
+
         ArcRotateCamera.prototype.focusOn = function (meshesOrMinMaxVectorAndDistance) {
             var meshesOrMinMaxVector;
             var distance;
+
             if (meshesOrMinMaxVectorAndDistance.min === undefined) {
                 meshesOrMinMaxVector = meshesOrMinMaxVectorAndDistance || this.getScene().meshes;
                 meshesOrMinMaxVector = BABYLON.Mesh.MinMax(meshesOrMinMaxVector);
                 distance = BABYLON.Vector3.Distance(meshesOrMinMaxVector.min, meshesOrMinMaxVector.max);
-            }
-            else {
+            } else {
                 meshesOrMinMaxVector = meshesOrMinMaxVectorAndDistance;
                 distance = meshesOrMinMaxVectorAndDistance.distance;
             }
+
             this.target = BABYLON.Mesh.Center(meshesOrMinMaxVector);
+
             this.maxZ = distance * 2;
         };
         return ArcRotateCamera;
     })(BABYLON.Camera);
     BABYLON.ArcRotateCamera = ArcRotateCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.arcRotateCamera.js.map
+//# sourceMappingURL=babylon.arcRotateCamera.js.map

+ 71 - 9
Babylon/Cameras/babylon.camera.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -30,7 +30,9 @@ var BABYLON;
             this._projectionMatrix = new BABYLON.Matrix();
             this._postProcesses = new Array();
             this._postProcessesTakenIndices = [];
+
             scene.cameras.push(this);
+
             if (!scene.activeCamera) {
                 scene.activeCamera = this;
             }
@@ -38,13 +40,17 @@ var BABYLON;
         //Cache
         Camera.prototype._initCache = function () {
             _super.prototype._initCache.call(this);
+
             this._cache.position = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
             this._cache.upVector = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
+
             this._cache.mode = undefined;
             this._cache.minZ = undefined;
             this._cache.maxZ = undefined;
+
             this._cache.fov = undefined;
             this._cache.aspectRatio = undefined;
+
             this._cache.orthoLeft = undefined;
             this._cache.orthoRight = undefined;
             this._cache.orthoBottom = undefined;
@@ -52,18 +58,24 @@ var BABYLON;
             this._cache.renderWidth = undefined;
             this._cache.renderHeight = undefined;
         };
+
         Camera.prototype._updateCache = function (ignoreParentClass) {
             if (!ignoreParentClass) {
                 _super.prototype._updateCache.call(this);
             }
+
             var engine = this.getEngine();
+
             this._cache.position.copyFrom(this.position);
             this._cache.upVector.copyFrom(this.upVector);
+
             this._cache.mode = this.mode;
             this._cache.minZ = this.minZ;
             this._cache.maxZ = this.maxZ;
+
             this._cache.fov = this.fov;
             this._cache.aspectRatio = engine.getAspectRatio(this);
+
             this._cache.orthoLeft = this.orthoLeft;
             this._cache.orthoRight = this.orthoRight;
             this._cache.orthoBottom = this.orthoBottom;
@@ -71,63 +83,83 @@ var BABYLON;
             this._cache.renderWidth = engine.getRenderWidth();
             this._cache.renderHeight = engine.getRenderHeight();
         };
+
         Camera.prototype._updateFromScene = function () {
             this.updateCache();
             this._update();
         };
+
         // Synchronized
         Camera.prototype._isSynchronized = function () {
             return this._isSynchronizedViewMatrix() && this._isSynchronizedProjectionMatrix();
         };
+
         Camera.prototype._isSynchronizedViewMatrix = function () {
             if (!_super.prototype._isSynchronized.call(this))
                 return false;
+
             return this._cache.position.equals(this.position) && this._cache.upVector.equals(this.upVector) && this.isSynchronizedWithParent();
         };
+
         Camera.prototype._isSynchronizedProjectionMatrix = function () {
             var check = this._cache.mode === this.mode && this._cache.minZ === this.minZ && this._cache.maxZ === this.maxZ;
+
             if (!check) {
                 return false;
             }
+
             var engine = this.getEngine();
+
             if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
                 check = this._cache.fov === this.fov && this._cache.aspectRatio === engine.getAspectRatio(this);
-            }
-            else {
+            } else {
                 check = this._cache.orthoLeft === this.orthoLeft && this._cache.orthoRight === this.orthoRight && this._cache.orthoBottom === this.orthoBottom && this._cache.orthoTop === this.orthoTop && this._cache.renderWidth === engine.getRenderWidth() && this._cache.renderHeight === engine.getRenderHeight();
             }
+
             return check;
         };
+
         // Controls
         Camera.prototype.attachControl = function (element) {
         };
+
         Camera.prototype.detachControl = function (element) {
         };
+
         Camera.prototype._update = function () {
         };
+
         Camera.prototype.attachPostProcess = function (postProcess, insertAt) {
-            if (insertAt === void 0) { insertAt = null; }
+            if (typeof insertAt === "undefined") { insertAt = null; }
             if (!postProcess.isReusable() && this._postProcesses.indexOf(postProcess) > -1) {
                 BABYLON.Tools.Error("You're trying to reuse a post process not defined as reusable.");
                 return 0;
             }
+
             if (insertAt == null || insertAt < 0) {
                 this._postProcesses.push(postProcess);
                 this._postProcessesTakenIndices.push(this._postProcesses.length - 1);
+
                 return this._postProcesses.length - 1;
             }
+
             var add = 0;
+
             if (this._postProcesses[insertAt]) {
                 var start = this._postProcesses.length - 1;
+
                 for (var i = start; i >= insertAt + 1; --i) {
                     this._postProcesses[i + 1] = this._postProcesses[i];
                 }
+
                 add = 1;
             }
+
             for (i = 0; i < this._postProcessesTakenIndices.length; ++i) {
                 if (this._postProcessesTakenIndices[i] < insertAt) {
                     continue;
                 }
+
                 start = this._postProcessesTakenIndices.length - 1;
                 for (var j = start; j >= i; --j) {
                     this._postProcessesTakenIndices[j + 1] = this._postProcessesTakenIndices[j] + add;
@@ -135,107 +167,137 @@ var BABYLON;
                 this._postProcessesTakenIndices[i] = insertAt;
                 break;
             }
+
             if (!add && this._postProcessesTakenIndices.indexOf(insertAt) == -1) {
                 this._postProcessesTakenIndices.push(insertAt);
             }
+
             var result = insertAt + add;
+
             this._postProcesses[result] = postProcess;
+
             return result;
         };
+
         Camera.prototype.detachPostProcess = function (postProcess, atIndices) {
-            if (atIndices === void 0) { atIndices = null; }
+            if (typeof atIndices === "undefined") { atIndices = null; }
             var result = [];
+
             if (!atIndices) {
                 var length = this._postProcesses.length;
+
                 for (var i = 0; i < length; i++) {
                     if (this._postProcesses[i] !== postProcess) {
                         continue;
                     }
+
                     delete this._postProcesses[i];
+
                     var index = this._postProcessesTakenIndices.indexOf(i);
                     this._postProcessesTakenIndices.splice(index, 1);
                 }
-            }
-            else {
+            } else {
                 atIndices = (atIndices instanceof Array) ? atIndices : [atIndices];
                 for (i = 0; i < atIndices.length; i++) {
                     var foundPostProcess = this._postProcesses[atIndices[i]];
+
                     if (foundPostProcess !== postProcess) {
                         result.push(i);
                         continue;
                     }
+
                     delete this._postProcesses[atIndices[i]];
+
                     index = this._postProcessesTakenIndices.indexOf(atIndices[i]);
                     this._postProcessesTakenIndices.splice(index, 1);
                 }
             }
             return result;
         };
+
         Camera.prototype.getWorldMatrix = function () {
             if (!this._worldMatrix) {
                 this._worldMatrix = BABYLON.Matrix.Identity();
             }
+
             var viewMatrix = this.getViewMatrix();
+
             viewMatrix.invertToRef(this._worldMatrix);
+
             return this._worldMatrix;
         };
+
         Camera.prototype._getViewMatrix = function () {
             return BABYLON.Matrix.Identity();
         };
+
         Camera.prototype.getViewMatrix = function () {
             this._computedViewMatrix = this._computeViewMatrix();
+
             if (!this.parent || !this.parent.getWorldMatrix || this.isSynchronized()) {
                 return this._computedViewMatrix;
             }
+
             if (!this._worldMatrix) {
                 this._worldMatrix = BABYLON.Matrix.Identity();
             }
+
             this._computedViewMatrix.invertToRef(this._worldMatrix);
+
             this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._computedViewMatrix);
+
             this._computedViewMatrix.invert();
+
             this._currentRenderId = this.getScene().getRenderId();
             return this._computedViewMatrix;
         };
+
         Camera.prototype._computeViewMatrix = function (force) {
             if (!force && this._isSynchronizedViewMatrix()) {
                 return this._computedViewMatrix;
             }
+
             this._computedViewMatrix = this._getViewMatrix();
             if (!this.parent || !this.parent.getWorldMatrix) {
                 this._currentRenderId = this.getScene().getRenderId();
             }
             return this._computedViewMatrix;
         };
+
         Camera.prototype.getProjectionMatrix = function (force) {
             if (!force && this._isSynchronizedProjectionMatrix()) {
                 return this._projectionMatrix;
             }
+
             var engine = this.getEngine();
             if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
                 if (this.minZ <= 0) {
                     this.minZ = 0.1;
                 }
+
                 BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix);
                 return this._projectionMatrix;
             }
+
             var halfWidth = engine.getRenderWidth() / 2.0;
             var halfHeight = engine.getRenderHeight() / 2.0;
             BABYLON.Matrix.OrthoOffCenterLHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
             return this._projectionMatrix;
         };
+
         Camera.prototype.dispose = function () {
             // Remove from scene
             var index = this.getScene().cameras.indexOf(this);
             this.getScene().cameras.splice(index, 1);
+
             for (var i = 0; i < this._postProcessesTakenIndices.length; ++i) {
                 this._postProcesses[this._postProcessesTakenIndices[i]].dispose(this);
             }
         };
-        // Statics
         Camera.PERSPECTIVE_CAMERA = 0;
         Camera.ORTHOGRAPHIC_CAMERA = 1;
         return Camera;
     })(BABYLON.Node);
     BABYLON.Camera = Camera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.camera.js.map
+//# sourceMappingURL=babylon.camera.js.map

+ 12 - 1
Babylon/Cameras/babylon.deviceOrientationCamera.js

@@ -20,6 +20,7 @@ var BABYLON;
             this._initialOrientationBeta = 0;
             this.angularSensibility = 10000.0;
             this.moveSensibility = 50.0;
+
             window.addEventListener("resize", function () {
                 _this._initialOrientationGamma = null;
             }, false);
@@ -30,38 +31,48 @@ var BABYLON;
                 return;
             }
             this._attachedCanvas = canvas;
+
             if (!this._orientationChanged) {
                 this._orientationChanged = function (evt) {
                     if (!_this._initialOrientationGamma) {
                         _this._initialOrientationGamma = evt.gamma;
                         _this._initialOrientationBeta = evt.beta;
                     }
+
                     _this._orientationGamma = evt.gamma;
                     _this._orientationBeta = evt.beta;
+
                     _this._offsetY = (_this._initialOrientationBeta - _this._orientationBeta);
                     _this._offsetX = (_this._initialOrientationGamma - _this._orientationGamma);
                 };
             }
+
             window.addEventListener("deviceorientation", this._orientationChanged);
         };
+
         DeviceOrientationCamera.prototype.detachControl = function (canvas) {
             if (this._attachedCanvas != canvas) {
                 return;
             }
+
             window.removeEventListener("deviceorientation", this._orientationChanged);
+
             this._attachedCanvas = null;
             this._orientationGamma = 0;
             this._orientationBeta = 0;
             this._initialOrientationGamma = 0;
             this._initialOrientationBeta = 0;
         };
+
         DeviceOrientationCamera.prototype._checkInputs = function () {
             if (!this._offsetX) {
                 return;
             }
             this.cameraRotation.y -= this._offsetX / this.angularSensibility;
+
             var speed = this._computeLocalCameraSpeed();
             var direction = new BABYLON.Vector3(0, 0, speed * this._offsetY / this.moveSensibility);
+
             BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
             this.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
         };
@@ -69,4 +80,4 @@ var BABYLON;
     })(BABYLON.FreeCamera);
     BABYLON.DeviceOrientationCamera = DeviceOrientationCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.deviceOrientationCamera.js.map
+//# sourceMappingURL=babylon.deviceOrientationCamera.js.map

+ 11 - 3
Babylon/Cameras/babylon.followCamera.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -19,30 +19,38 @@ var BABYLON;
         FollowCamera.prototype.getRadians = function (degrees) {
             return degrees * Math.PI / 180;
         };
+
         FollowCamera.prototype.follow = function (cameraTarget) {
             if (!cameraTarget)
                 return;
+
             var radians = this.getRadians(this.rotationOffset) + cameraTarget.rotation.y;
             var targetX = cameraTarget.position.x + Math.sin(radians) * this.radius;
+
             var targetZ = cameraTarget.position.z + Math.cos(radians) * this.radius;
             var dx = targetX - this.position.x;
             var dy = (cameraTarget.position.y + this.heightOffset) - this.position.y;
             var dz = (targetZ) - this.position.z;
-            var vx = dx * this.cameraAcceleration * 2; //this is set to .05
+            var vx = dx * this.cameraAcceleration * 2;
             var vy = dy * this.cameraAcceleration;
             var vz = dz * this.cameraAcceleration * 2;
+
             if (vx > this.maxCameraSpeed || vx < -this.maxCameraSpeed) {
                 vx = vx < 1 ? -this.maxCameraSpeed : this.maxCameraSpeed;
             }
+
             if (vy > this.maxCameraSpeed || vy < -this.maxCameraSpeed) {
                 vy = vy < 1 ? -this.maxCameraSpeed : this.maxCameraSpeed;
             }
+
             if (vz > this.maxCameraSpeed || vz < -this.maxCameraSpeed) {
                 vz = vz < 1 ? -this.maxCameraSpeed : this.maxCameraSpeed;
             }
+
             this.position = new BABYLON.Vector3(this.position.x + vx, this.position.y + vy, this.position.z + vz);
             this.setTarget(cameraTarget.position);
         };
+
         FollowCamera.prototype._update = function () {
             _super.prototype._update.call(this);
             this.follow(this.target);
@@ -51,4 +59,4 @@ var BABYLON;
     })(BABYLON.TargetCamera);
     BABYLON.FollowCamera = FollowCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.followCamera.js.map
+//# sourceMappingURL=babylon.followCamera.js.map

+ 42 - 14
Babylon/Cameras/babylon.freeCamera.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -30,26 +30,31 @@ var BABYLON;
             var _this = this;
             var previousPosition;
             var engine = this.getEngine();
+
             if (this._attachedElement) {
                 return;
             }
             this._attachedElement = element;
+
             if (this._onMouseDown === undefined) {
                 this._onMouseDown = function (evt) {
                     previousPosition = {
                         x: evt.clientX,
                         y: evt.clientY
                     };
+
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
                 };
+
                 this._onMouseUp = function (evt) {
                     previousPosition = null;
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
                 };
+
                 this._onMouseOut = function (evt) {
                     previousPosition = null;
                     _this._keys = [];
@@ -57,22 +62,26 @@ var BABYLON;
                         evt.preventDefault();
                     }
                 };
+
                 this._onMouseMove = function (evt) {
                     if (!previousPosition && !engine.isPointerLock) {
                         return;
                     }
+
                     var offsetX;
                     var offsetY;
+
                     if (!engine.isPointerLock) {
                         offsetX = evt.clientX - previousPosition.x;
                         offsetY = evt.clientY - previousPosition.y;
-                    }
-                    else {
+                    } else {
                         offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
                         offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
                     }
+
                     _this.cameraRotation.y += offsetX / _this.angularSensibility;
                     _this.cameraRotation.x += offsetY / _this.angularSensibility;
+
                     previousPosition = {
                         x: evt.clientX,
                         y: evt.clientY
@@ -81,9 +90,11 @@ var BABYLON;
                         evt.preventDefault();
                     }
                 };
+
                 this._onKeyDown = function (evt) {
                     if (_this.keysUp.indexOf(evt.keyCode) !== -1 || _this.keysDown.indexOf(evt.keyCode) !== -1 || _this.keysLeft.indexOf(evt.keyCode) !== -1 || _this.keysRight.indexOf(evt.keyCode) !== -1) {
                         var index = _this._keys.indexOf(evt.keyCode);
+
                         if (index === -1) {
                             _this._keys.push(evt.keyCode);
                         }
@@ -92,9 +103,11 @@ var BABYLON;
                         }
                     }
                 };
+
                 this._onKeyUp = function (evt) {
                     if (_this.keysUp.indexOf(evt.keyCode) !== -1 || _this.keysDown.indexOf(evt.keyCode) !== -1 || _this.keysLeft.indexOf(evt.keyCode) !== -1 || _this.keysRight.indexOf(evt.keyCode) !== -1) {
                         var index = _this._keys.indexOf(evt.keyCode);
+
                         if (index >= 0) {
                             _this._keys.splice(index, 1);
                         }
@@ -103,9 +116,11 @@ var BABYLON;
                         }
                     }
                 };
+
                 this._onLostFocus = function () {
                     _this._keys = [];
                 };
+
                 this._reset = function () {
                     _this._keys = [];
                     previousPosition = null;
@@ -113,46 +128,56 @@ var BABYLON;
                     _this.cameraRotation = new BABYLON.Vector2(0, 0);
                 };
             }
+
             element.addEventListener("mousedown", this._onMouseDown, false);
             element.addEventListener("mouseup", this._onMouseUp, false);
             element.addEventListener("mouseout", this._onMouseOut, false);
             element.addEventListener("mousemove", this._onMouseMove, false);
+
             BABYLON.Tools.RegisterTopRootEvents([
                 { name: "keydown", handler: this._onKeyDown },
                 { name: "keyup", handler: this._onKeyUp },
                 { name: "blur", handler: this._onLostFocus }
             ]);
         };
+
         FreeCamera.prototype.detachControl = function (element) {
             if (this._attachedElement != element) {
                 return;
             }
+
             element.removeEventListener("mousedown", this._onMouseDown);
             element.removeEventListener("mouseup", this._onMouseUp);
             element.removeEventListener("mouseout", this._onMouseOut);
             element.removeEventListener("mousemove", this._onMouseMove);
+
             BABYLON.Tools.UnregisterTopRootEvents([
                 { name: "keydown", handler: this._onKeyDown },
                 { name: "keyup", handler: this._onKeyUp },
                 { name: "blur", handler: this._onLostFocus }
             ]);
+
             this._attachedElement = null;
             if (this._reset) {
                 this._reset();
             }
         };
+
         FreeCamera.prototype._collideWithWorld = function (velocity) {
             var globalPosition;
+
             if (this.parent) {
                 globalPosition = BABYLON.Vector3.TransformCoordinates(this.position, this.parent.getWorldMatrix());
-            }
-            else {
+            } else {
                 globalPosition = this.position;
             }
+
             globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPosition);
             this._collider.radius = this.ellipsoid;
+
             this.getScene()._getNewPosition(this._oldPosition, velocity, this._collider, 3, this._newPosition);
             this._newPosition.subtractToRef(this._oldPosition, this._diffPosition);
+
             if (this._diffPosition.length() > BABYLON.Engine.CollisionsEpsilon) {
                 this.position.addInPlace(this._diffPosition);
                 if (this.onCollide) {
@@ -160,34 +185,37 @@ var BABYLON;
                 }
             }
         };
+
         FreeCamera.prototype._checkInputs = function () {
             if (!this._localDirection) {
                 this._localDirection = BABYLON.Vector3.Zero();
                 this._transformedDirection = BABYLON.Vector3.Zero();
             }
+
             for (var index = 0; index < this._keys.length; index++) {
                 var keyCode = this._keys[index];
                 var speed = this._computeLocalCameraSpeed();
+
                 if (this.keysLeft.indexOf(keyCode) !== -1) {
                     this._localDirection.copyFromFloats(-speed, 0, 0);
-                }
-                else if (this.keysUp.indexOf(keyCode) !== -1) {
+                } else if (this.keysUp.indexOf(keyCode) !== -1) {
                     this._localDirection.copyFromFloats(0, 0, speed);
-                }
-                else if (this.keysRight.indexOf(keyCode) !== -1) {
+                } else if (this.keysRight.indexOf(keyCode) !== -1) {
                     this._localDirection.copyFromFloats(speed, 0, 0);
-                }
-                else if (this.keysDown.indexOf(keyCode) !== -1) {
+                } else if (this.keysDown.indexOf(keyCode) !== -1) {
                     this._localDirection.copyFromFloats(0, 0, -speed);
                 }
+
                 this.getViewMatrix().invertToRef(this._cameraTransformMatrix);
                 BABYLON.Vector3.TransformNormalToRef(this._localDirection, this._cameraTransformMatrix, this._transformedDirection);
                 this.cameraDirection.addInPlace(this._transformedDirection);
             }
         };
+
         FreeCamera.prototype._decideIfNeedsToMove = function () {
             return this._needMoveForGravity || Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;
         };
+
         FreeCamera.prototype._updatePosition = function () {
             if (this.checkCollisions && this.getScene().collisionsEnabled) {
                 this._collideWithWorld(this.cameraDirection);
@@ -196,11 +224,11 @@ var BABYLON;
                     this._collideWithWorld(this.getScene().gravity);
                     this._needMoveForGravity = (BABYLON.Vector3.DistanceSquared(oldPosition, this.position) != 0);
                 }
-            }
-            else {
+            } else {
                 this.position.addInPlace(this.cameraDirection);
             }
         };
+
         FreeCamera.prototype._update = function () {
             this._checkInputs();
             _super.prototype._update.call(this);
@@ -209,4 +237,4 @@ var BABYLON;
     })(BABYLON.TargetCamera);
     BABYLON.FreeCamera = FreeCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.freeCamera.js.map
+//# sourceMappingURL=babylon.freeCamera.js.map

+ 6 - 1
Babylon/Cameras/babylon.gamepadCamera.js

@@ -24,26 +24,31 @@ var BABYLON;
                 this._gamepad = gamepad;
             }
         };
+
         GamepadCamera.prototype._checkInputs = function () {
             if (!this._gamepad) {
                 return;
             }
+
             var LSValues = this._gamepad.leftStick;
             var normalizedLX = LSValues.x / this.moveSensibility;
             var normalizedLY = LSValues.y / this.moveSensibility;
             LSValues.x = Math.abs(normalizedLX) > 0.005 ? 0 + normalizedLX : 0;
             LSValues.y = Math.abs(normalizedLY) > 0.005 ? 0 + normalizedLY : 0;
+
             var RSValues = this._gamepad.rightStick;
             var normalizedRX = RSValues.x / this.angularSensibility;
             var normalizedRY = RSValues.y / this.angularSensibility;
             RSValues.x = Math.abs(normalizedRX) > 0.001 ? 0 + normalizedRX : 0;
             RSValues.y = Math.abs(normalizedRY) > 0.001 ? 0 + normalizedRY : 0;
             ;
+
             var cameraTransform = BABYLON.Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
             var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(LSValues.x, 0, -LSValues.y), cameraTransform);
             this.cameraDirection = this.cameraDirection.add(deltaTransform);
             this.cameraRotation = this.cameraRotation.add(new BABYLON.Vector2(RSValues.y, RSValues.x));
         };
+
         GamepadCamera.prototype.dispose = function () {
             this._gamepads.dispose();
             _super.prototype.dispose.call(this);
@@ -52,4 +57,4 @@ var BABYLON;
     })(BABYLON.FreeCamera);
     BABYLON.GamepadCamera = GamepadCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.gamepadCamera.js.map
+//# sourceMappingURL=babylon.gamepadCamera.js.map

+ 42 - 12
Babylon/Cameras/babylon.targetCamera.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -30,140 +30,170 @@ var BABYLON;
             if (!this.lockedTarget) {
                 return null;
             }
+
             return this.lockedTarget.position || this.lockedTarget;
         };
+
         // Cache
         TargetCamera.prototype._initCache = function () {
             _super.prototype._initCache.call(this);
             this._cache.lockedTarget = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
             this._cache.rotation = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
         };
+
         TargetCamera.prototype._updateCache = function (ignoreParentClass) {
             if (!ignoreParentClass) {
                 _super.prototype._updateCache.call(this);
             }
+
             var lockedTargetPosition = this._getLockedTargetPosition();
             if (!lockedTargetPosition) {
                 this._cache.lockedTarget = null;
-            }
-            else {
+            } else {
                 if (!this._cache.lockedTarget) {
                     this._cache.lockedTarget = lockedTargetPosition.clone();
-                }
-                else {
+                } else {
                     this._cache.lockedTarget.copyFrom(lockedTargetPosition);
                 }
             }
+
             this._cache.rotation.copyFrom(this.rotation);
         };
+
         // Synchronized
         TargetCamera.prototype._isSynchronizedViewMatrix = function () {
             if (!_super.prototype._isSynchronizedViewMatrix.call(this)) {
                 return false;
             }
+
             var lockedTargetPosition = this._getLockedTargetPosition();
+
             return (this._cache.lockedTarget ? this._cache.lockedTarget.equals(lockedTargetPosition) : !lockedTargetPosition) && this._cache.rotation.equals(this.rotation);
         };
+
         // Methods
         TargetCamera.prototype._computeLocalCameraSpeed = function () {
             var engine = this.getEngine();
             return this.speed * ((engine.getDeltaTime() / (engine.getFps() * 10.0)));
         };
+
         // Target
         TargetCamera.prototype.setTarget = function (target) {
             this.upVector.normalize();
+
             BABYLON.Matrix.LookAtLHToRef(this.position, target, this.upVector, this._camMatrix);
             this._camMatrix.invert();
+
             this.rotation.x = Math.atan(this._camMatrix.m[6] / this._camMatrix.m[10]);
+
             var vDir = target.subtract(this.position);
+
             if (vDir.x >= 0.0) {
                 this.rotation.y = (-Math.atan(vDir.z / vDir.x) + Math.PI / 2.0);
-            }
-            else {
+            } else {
                 this.rotation.y = (-Math.atan(vDir.z / vDir.x) - Math.PI / 2.0);
             }
+
             this.rotation.z = -Math.acos(BABYLON.Vector3.Dot(new BABYLON.Vector3(0, 1.0, 0), this.upVector));
+
             if (isNaN(this.rotation.x)) {
                 this.rotation.x = 0;
             }
+
             if (isNaN(this.rotation.y)) {
                 this.rotation.y = 0;
             }
+
             if (isNaN(this.rotation.z)) {
                 this.rotation.z = 0;
             }
         };
+
         TargetCamera.prototype.getTarget = function () {
             return this._currentTarget;
         };
+
         TargetCamera.prototype._decideIfNeedsToMove = function () {
             return Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;
         };
+
         TargetCamera.prototype._updatePosition = function () {
             this.position.addInPlace(this.cameraDirection);
         };
         TargetCamera.prototype._update = function () {
             var needToMove = this._decideIfNeedsToMove();
             var needToRotate = Math.abs(this.cameraRotation.x) > 0 || Math.abs(this.cameraRotation.y) > 0;
+
             // Move
             if (needToMove) {
                 this._updatePosition();
             }
+
             // Rotate
             if (needToRotate) {
                 this.rotation.x += this.cameraRotation.x;
                 this.rotation.y += this.cameraRotation.y;
+
                 if (!this.noRotationConstraint) {
                     var limit = (Math.PI / 2) * 0.95;
+
                     if (this.rotation.x > limit)
                         this.rotation.x = limit;
                     if (this.rotation.x < -limit)
                         this.rotation.x = -limit;
                 }
             }
+
             // Inertia
             if (needToMove) {
                 if (Math.abs(this.cameraDirection.x) < BABYLON.Engine.Epsilon) {
                     this.cameraDirection.x = 0;
                 }
+
                 if (Math.abs(this.cameraDirection.y) < BABYLON.Engine.Epsilon) {
                     this.cameraDirection.y = 0;
                 }
+
                 if (Math.abs(this.cameraDirection.z) < BABYLON.Engine.Epsilon) {
                     this.cameraDirection.z = 0;
                 }
+
                 this.cameraDirection.scaleInPlace(this.inertia);
             }
             if (needToRotate) {
                 if (Math.abs(this.cameraRotation.x) < BABYLON.Engine.Epsilon) {
                     this.cameraRotation.x = 0;
                 }
+
                 if (Math.abs(this.cameraRotation.y) < BABYLON.Engine.Epsilon) {
                     this.cameraRotation.y = 0;
                 }
                 this.cameraRotation.scaleInPlace(this.inertia);
             }
         };
+
         TargetCamera.prototype._getViewMatrix = function () {
             if (!this.lockedTarget) {
                 // Compute
                 if (this.upVector.x != 0 || this.upVector.y != 1.0 || this.upVector.z != 0) {
                     BABYLON.Matrix.LookAtLHToRef(BABYLON.Vector3.Zero(), this._referencePoint, this.upVector, this._lookAtTemp);
                     BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
+
                     this._lookAtTemp.multiplyToRef(this._cameraRotationMatrix, this._tempMatrix);
                     this._lookAtTemp.invert();
                     this._tempMatrix.multiplyToRef(this._lookAtTemp, this._cameraRotationMatrix);
-                }
-                else {
+                } else {
                     BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
                 }
+
                 BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
+
                 // Computing target and final matrix
                 this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
-            }
-            else {
+            } else {
                 this._currentTarget.copyFrom(this._getLockedTargetPosition());
             }
+
             BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this.upVector, this._viewMatrix);
             return this._viewMatrix;
         };
@@ -171,4 +201,4 @@ var BABYLON;
     })(BABYLON.Camera);
     BABYLON.TargetCamera = TargetCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.targetCamera.js.map
+//# sourceMappingURL=babylon.targetCamera.js.map

+ 26 - 3
Babylon/Cameras/babylon.touchCamera.js

@@ -21,33 +21,42 @@ var BABYLON;
         TouchCamera.prototype.attachControl = function (canvas, noPreventDefault) {
             var _this = this;
             var previousPosition;
+
             if (this._attachedCanvas) {
                 return;
             }
             this._attachedCanvas = canvas;
+
             if (this._onPointerDown === undefined) {
                 this._onPointerDown = function (evt) {
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
+
                     _this._pointerPressed.push(evt.pointerId);
+
                     if (_this._pointerPressed.length !== 1) {
                         return;
                     }
+
                     previousPosition = {
                         x: evt.clientX,
                         y: evt.clientY
                     };
                 };
+
                 this._onPointerUp = function (evt) {
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
+
                     var index = _this._pointerPressed.indexOf(evt.pointerId);
+
                     if (index === -1) {
                         return;
                     }
                     _this._pointerPressed.splice(index, 1);
+
                     if (index != 0) {
                         return;
                     }
@@ -55,57 +64,71 @@ var BABYLON;
                     _this._offsetX = null;
                     _this._offsetY = null;
                 };
+
                 this._onPointerMove = function (evt) {
                     if (!noPreventDefault) {
                         evt.preventDefault();
                     }
+
                     if (!previousPosition) {
                         return;
                     }
+
                     var index = _this._pointerPressed.indexOf(evt.pointerId);
+
                     if (index != 0) {
                         return;
                     }
+
                     _this._offsetX = evt.clientX - previousPosition.x;
                     _this._offsetY = -(evt.clientY - previousPosition.y);
                 };
+
                 this._onLostFocus = function () {
                     _this._offsetX = null;
                     _this._offsetY = null;
                 };
             }
+
             canvas.addEventListener("pointerdown", this._onPointerDown);
             canvas.addEventListener("pointerup", this._onPointerUp);
             canvas.addEventListener("pointerout", this._onPointerUp);
             canvas.addEventListener("pointermove", this._onPointerMove);
+
             BABYLON.Tools.RegisterTopRootEvents([
                 { name: "blur", handler: this._onLostFocus }
             ]);
         };
+
         TouchCamera.prototype.detachControl = function (canvas) {
             if (this._attachedCanvas != canvas) {
                 return;
             }
+
             canvas.removeEventListener("pointerdown", this._onPointerDown);
             canvas.removeEventListener("pointerup", this._onPointerUp);
             canvas.removeEventListener("pointerout", this._onPointerUp);
             canvas.removeEventListener("pointermove", this._onPointerMove);
+
             BABYLON.Tools.UnregisterTopRootEvents([
                 { name: "blur", handler: this._onLostFocus }
             ]);
+
             this._attachedCanvas = null;
         };
+
         TouchCamera.prototype._checkInputs = function () {
             if (!this._offsetX) {
                 return;
             }
             this.cameraRotation.y += this._offsetX / this.angularSensibility;
+
             if (this._pointerPressed.length > 1) {
                 this.cameraRotation.x += -this._offsetY / this.angularSensibility;
-            }
-            else {
+            } else {
                 var speed = this._computeLocalCameraSpeed();
                 var direction = new BABYLON.Vector3(0, 0, speed * this._offsetY / this.moveSensibility);
+
                 BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
                 this.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
             }
@@ -114,4 +137,4 @@ var BABYLON;
     })(BABYLON.FreeCamera);
     BABYLON.TouchCamera = TouchCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.touchCamera.js.map
+//# sourceMappingURL=babylon.touchCamera.js.map

+ 3 - 2
Babylon/Cameras/babylon.virtualJoysticksCamera.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -34,6 +34,7 @@ var BABYLON;
                 this._rightjoystick.deltaPosition = this._rightjoystick.deltaPosition.scale(0.9);
             }
         };
+
         VirtualJoysticksCamera.prototype.dispose = function () {
             this._leftjoystick.releaseCanvas();
             _super.prototype.dispose.call(this);
@@ -42,4 +43,4 @@ var BABYLON;
     })(BABYLON.FreeCamera);
     BABYLON.VirtualJoysticksCamera = VirtualJoysticksCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.virtualJoysticksCamera.js.map
+//# sourceMappingURL=babylon.virtualJoysticksCamera.js.map

+ 72 - 6
Babylon/Collisions/babylon.collider.js

@@ -1,45 +1,59 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var intersectBoxAASphere = function (boxMin, boxMax, sphereCenter, sphereRadius) {
         if (boxMin.x > sphereCenter.x + sphereRadius)
             return false;
+
         if (sphereCenter.x - sphereRadius > boxMax.x)
             return false;
+
         if (boxMin.y > sphereCenter.y + sphereRadius)
             return false;
+
         if (sphereCenter.y - sphereRadius > boxMax.y)
             return false;
+
         if (boxMin.z > sphereCenter.z + sphereRadius)
             return false;
+
         if (sphereCenter.z - sphereRadius > boxMax.z)
             return false;
+
         return true;
     };
+
     var getLowestRoot = function (a, b, c, maxR) {
         var determinant = b * b - 4.0 * a * c;
         var result = { root: 0, found: false };
+
         if (determinant < 0)
             return result;
+
         var sqrtD = Math.sqrt(determinant);
         var r1 = (-b - sqrtD) / (2.0 * a);
         var r2 = (-b + sqrtD) / (2.0 * a);
+
         if (r1 > r2) {
             var temp = r2;
             r2 = r1;
             r1 = temp;
         }
+
         if (r1 > 0 && r1 < maxR) {
             result.root = r1;
             result.found = true;
             return result;
         }
+
         if (r2 > 0 && r2 < maxR) {
             result.root = r2;
             result.found = true;
             return result;
         }
+
         return result;
     };
+
     var Collider = (function () {
         function Collider() {
             this.radius = new BABYLON.Vector3(1, 1, 1);
@@ -64,128 +78,165 @@ var BABYLON;
             this.velocity = dir;
             BABYLON.Vector3.NormalizeToRef(dir, this.normalizedVelocity);
             this.basePoint = source;
+
             source.multiplyToRef(this.radius, this.basePointWorld);
             dir.multiplyToRef(this.radius, this.velocityWorld);
+
             this.velocityWorldLength = this.velocityWorld.length();
+
             this.epsilon = e;
             this.collisionFound = false;
         };
+
         Collider.prototype._checkPointInTriangle = function (point, pa, pb, pc, n) {
             pa.subtractToRef(point, this._tempVector);
             pb.subtractToRef(point, this._tempVector2);
+
             BABYLON.Vector3.CrossToRef(this._tempVector, this._tempVector2, this._tempVector4);
             var d = BABYLON.Vector3.Dot(this._tempVector4, n);
             if (d < 0)
                 return false;
+
             pc.subtractToRef(point, this._tempVector3);
             BABYLON.Vector3.CrossToRef(this._tempVector2, this._tempVector3, this._tempVector4);
             d = BABYLON.Vector3.Dot(this._tempVector4, n);
             if (d < 0)
                 return false;
+
             BABYLON.Vector3.CrossToRef(this._tempVector3, this._tempVector, this._tempVector4);
             d = BABYLON.Vector3.Dot(this._tempVector4, n);
             return d >= 0;
         };
+
         Collider.prototype._canDoCollision = function (sphereCenter, sphereRadius, vecMin, vecMax) {
             var distance = BABYLON.Vector3.Distance(this.basePointWorld, sphereCenter);
+
             var max = Math.max(this.radius.x, this.radius.y, this.radius.z);
+
             if (distance > this.velocityWorldLength + max + sphereRadius) {
                 return false;
             }
+
             if (!intersectBoxAASphere(vecMin, vecMax, this.basePointWorld, this.velocityWorldLength + max))
                 return false;
+
             return true;
         };
+
         Collider.prototype._testTriangle = function (faceIndex, subMesh, p1, p2, p3) {
             var t0;
             var embeddedInPlane = false;
+
             if (!subMesh._trianglePlanes) {
                 subMesh._trianglePlanes = [];
             }
+
             if (!subMesh._trianglePlanes[faceIndex]) {
                 subMesh._trianglePlanes[faceIndex] = new BABYLON.Plane(0, 0, 0, 0);
                 subMesh._trianglePlanes[faceIndex].copyFromPoints(p1, p2, p3);
             }
+
             var trianglePlane = subMesh._trianglePlanes[faceIndex];
+
             if ((!subMesh.getMaterial()) && !trianglePlane.isFrontFacingTo(this.normalizedVelocity, 0))
                 return;
+
             var signedDistToTrianglePlane = trianglePlane.signedDistanceTo(this.basePoint);
             var normalDotVelocity = BABYLON.Vector3.Dot(trianglePlane.normal, this.velocity);
+
             if (normalDotVelocity == 0) {
                 if (Math.abs(signedDistToTrianglePlane) >= 1.0)
                     return;
                 embeddedInPlane = true;
                 t0 = 0;
-            }
-            else {
+            } else {
                 t0 = (-1.0 - signedDistToTrianglePlane) / normalDotVelocity;
                 var t1 = (1.0 - signedDistToTrianglePlane) / normalDotVelocity;
+
                 if (t0 > t1) {
                     var temp = t1;
                     t1 = t0;
                     t0 = temp;
                 }
+
                 if (t0 > 1.0 || t1 < 0.0)
                     return;
+
                 if (t0 < 0)
                     t0 = 0;
                 if (t0 > 1.0)
                     t0 = 1.0;
             }
+
             this._collisionPoint.copyFromFloats(0, 0, 0);
+
             var found = false;
             var t = 1.0;
+
             if (!embeddedInPlane) {
                 this.basePoint.subtractToRef(trianglePlane.normal, this._planeIntersectionPoint);
                 this.velocity.scaleToRef(t0, this._tempVector);
                 this._planeIntersectionPoint.addInPlace(this._tempVector);
+
                 if (this._checkPointInTriangle(this._planeIntersectionPoint, p1, p2, p3, trianglePlane.normal)) {
                     found = true;
                     t = t0;
                     this._collisionPoint.copyFrom(this._planeIntersectionPoint);
                 }
             }
+
             if (!found) {
                 var velocitySquaredLength = this.velocity.lengthSquared();
+
                 var a = velocitySquaredLength;
+
                 this.basePoint.subtractToRef(p1, this._tempVector);
                 var b = 2.0 * (BABYLON.Vector3.Dot(this.velocity, this._tempVector));
                 var c = this._tempVector.lengthSquared() - 1.0;
+
                 var lowestRoot = getLowestRoot(a, b, c, t);
                 if (lowestRoot.found) {
                     t = lowestRoot.root;
                     found = true;
                     this._collisionPoint.copyFrom(p1);
                 }
+
                 this.basePoint.subtractToRef(p2, this._tempVector);
                 b = 2.0 * (BABYLON.Vector3.Dot(this.velocity, this._tempVector));
                 c = this._tempVector.lengthSquared() - 1.0;
+
                 lowestRoot = getLowestRoot(a, b, c, t);
                 if (lowestRoot.found) {
                     t = lowestRoot.root;
                     found = true;
                     this._collisionPoint.copyFrom(p2);
                 }
+
                 this.basePoint.subtractToRef(p3, this._tempVector);
                 b = 2.0 * (BABYLON.Vector3.Dot(this.velocity, this._tempVector));
                 c = this._tempVector.lengthSquared() - 1.0;
+
                 lowestRoot = getLowestRoot(a, b, c, t);
                 if (lowestRoot.found) {
                     t = lowestRoot.root;
                     found = true;
                     this._collisionPoint.copyFrom(p3);
                 }
+
                 p2.subtractToRef(p1, this._edge);
                 p1.subtractToRef(this.basePoint, this._baseToVertex);
                 var edgeSquaredLength = this._edge.lengthSquared();
                 var edgeDotVelocity = BABYLON.Vector3.Dot(this._edge, this.velocity);
                 var edgeDotBaseToVertex = BABYLON.Vector3.Dot(this._edge, this._baseToVertex);
+
                 a = edgeSquaredLength * (-velocitySquaredLength) + edgeDotVelocity * edgeDotVelocity;
                 b = edgeSquaredLength * (2.0 * BABYLON.Vector3.Dot(this.velocity, this._baseToVertex)) - 2.0 * edgeDotVelocity * edgeDotBaseToVertex;
                 c = edgeSquaredLength * (1.0 - this._baseToVertex.lengthSquared()) + edgeDotBaseToVertex * edgeDotBaseToVertex;
+
                 lowestRoot = getLowestRoot(a, b, c, t);
                 if (lowestRoot.found) {
                     var f = (edgeDotVelocity * lowestRoot.root - edgeDotBaseToVertex) / edgeSquaredLength;
+
                     if (f >= 0.0 && f <= 1.0) {
                         t = lowestRoot.root;
                         found = true;
@@ -193,17 +244,20 @@ var BABYLON;
                         p1.addToRef(this._edge, this._collisionPoint);
                     }
                 }
+
                 p3.subtractToRef(p2, this._edge);
                 p2.subtractToRef(this.basePoint, this._baseToVertex);
                 edgeSquaredLength = this._edge.lengthSquared();
                 edgeDotVelocity = BABYLON.Vector3.Dot(this._edge, this.velocity);
                 edgeDotBaseToVertex = BABYLON.Vector3.Dot(this._edge, this._baseToVertex);
+
                 a = edgeSquaredLength * (-velocitySquaredLength) + edgeDotVelocity * edgeDotVelocity;
                 b = edgeSquaredLength * (2.0 * BABYLON.Vector3.Dot(this.velocity, this._baseToVertex)) - 2.0 * edgeDotVelocity * edgeDotBaseToVertex;
                 c = edgeSquaredLength * (1.0 - this._baseToVertex.lengthSquared()) + edgeDotBaseToVertex * edgeDotBaseToVertex;
                 lowestRoot = getLowestRoot(a, b, c, t);
                 if (lowestRoot.found) {
                     f = (edgeDotVelocity * lowestRoot.root - edgeDotBaseToVertex) / edgeSquaredLength;
+
                     if (f >= 0.0 && f <= 1.0) {
                         t = lowestRoot.root;
                         found = true;
@@ -211,17 +265,21 @@ var BABYLON;
                         p2.addToRef(this._edge, this._collisionPoint);
                     }
                 }
+
                 p1.subtractToRef(p3, this._edge);
                 p3.subtractToRef(this.basePoint, this._baseToVertex);
                 edgeSquaredLength = this._edge.lengthSquared();
                 edgeDotVelocity = BABYLON.Vector3.Dot(this._edge, this.velocity);
                 edgeDotBaseToVertex = BABYLON.Vector3.Dot(this._edge, this._baseToVertex);
+
                 a = edgeSquaredLength * (-velocitySquaredLength) + edgeDotVelocity * edgeDotVelocity;
                 b = edgeSquaredLength * (2.0 * BABYLON.Vector3.Dot(this.velocity, this._baseToVertex)) - 2.0 * edgeDotVelocity * edgeDotBaseToVertex;
                 c = edgeSquaredLength * (1.0 - this._baseToVertex.lengthSquared()) + edgeDotBaseToVertex * edgeDotBaseToVertex;
+
                 lowestRoot = getLowestRoot(a, b, c, t);
                 if (lowestRoot.found) {
                     f = (edgeDotVelocity * lowestRoot.root - edgeDotBaseToVertex) / edgeSquaredLength;
+
                     if (f >= 0.0 && f <= 1.0) {
                         t = lowestRoot.root;
                         found = true;
@@ -230,13 +288,14 @@ var BABYLON;
                     }
                 }
             }
+
             if (found) {
                 var distToCollision = t * this.velocity.length();
+
                 if (!this.collisionFound || distToCollision < this.nearestDistance) {
                     if (!this.intersectionPoint) {
                         this.intersectionPoint = this._collisionPoint.clone();
-                    }
-                    else {
+                    } else {
                         this.intersectionPoint.copyFrom(this._collisionPoint);
                     }
                     this.nearestDistance = distToCollision;
@@ -245,29 +304,36 @@ var BABYLON;
                 }
             }
         };
+
         Collider.prototype._collide = function (subMesh, pts, indices, indexStart, indexEnd, decal) {
             for (var i = indexStart; i < indexEnd; i += 3) {
                 var p1 = pts[indices[i] - decal];
                 var p2 = pts[indices[i + 1] - decal];
                 var p3 = pts[indices[i + 2] - decal];
+
                 this._testTriangle(i, subMesh, p3, p2, p1);
             }
         };
+
         Collider.prototype._getResponse = function (pos, vel) {
             pos.addToRef(vel, this._destinationPoint);
             vel.scaleInPlace((this.nearestDistance / vel.length()));
+
             this.basePoint.addToRef(vel, pos);
             pos.subtractToRef(this.intersectionPoint, this._slidePlaneNormal);
             this._slidePlaneNormal.normalize();
             this._slidePlaneNormal.scaleToRef(this.epsilon, this._displacementVector);
+
             pos.addInPlace(this._displacementVector);
             this.intersectionPoint.addInPlace(this._displacementVector);
+
             this._slidePlaneNormal.scaleInPlace(BABYLON.Plane.SignedDistanceToPlaneFromPositionAndNormal(this.intersectionPoint, this._slidePlaneNormal, this._destinationPoint));
             this._destinationPoint.subtractInPlace(this._slidePlaneNormal);
+
             this._destinationPoint.subtractToRef(this.intersectionPoint, vel);
         };
         return Collider;
     })();
     BABYLON.Collider = Collider;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.collider.js.map
+//# sourceMappingURL=babylon.collider.js.map

+ 12 - 2
Babylon/Collisions/babylon.pickingInfo.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var IntersectionInfo = (function () {
         function IntersectionInfo(bu, bv, distance) {
@@ -10,6 +10,7 @@ var BABYLON;
         return IntersectionInfo;
     })();
     BABYLON.IntersectionInfo = IntersectionInfo;
+
     var PickingInfo = (function () {
         function PickingInfo() {
             this.hit = false;
@@ -25,32 +26,41 @@ var BABYLON;
             if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
                 return null;
             }
+
             var indices = this.pickedMesh.getIndices();
             var normals = this.pickedMesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
+
             var normal0 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3] * 3);
             var normal1 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3 + 1] * 3);
             var normal2 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3 + 2] * 3);
+
             normal0 = normal0.scale(this.bu);
             normal1 = normal1.scale(this.bv);
             normal2 = normal2.scale(1.0 - this.bu - this.bv);
+
             return new BABYLON.Vector3(normal0.x + normal1.x + normal2.x, normal0.y + normal1.y + normal2.y, normal0.z + normal1.z + normal2.z);
         };
+
         PickingInfo.prototype.getTextureCoordinates = function () {
             if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
                 return null;
             }
+
             var indices = this.pickedMesh.getIndices();
             var uvs = this.pickedMesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
+
             var uv0 = BABYLON.Vector2.FromArray(uvs, indices[this.faceId * 3] * 2);
             var uv1 = BABYLON.Vector2.FromArray(uvs, indices[this.faceId * 3 + 1] * 2);
             var uv2 = BABYLON.Vector2.FromArray(uvs, indices[this.faceId * 3 + 2] * 2);
+
             uv0 = uv0.scale(this.bu);
             uv1 = uv1.scale(this.bv);
             uv2 = uv2.scale(1.0 - this.bu - this.bv);
+
             return new BABYLON.Vector2(uv0.x + uv1.x + uv2.x, uv0.y + uv1.y + uv2.y);
         };
         return PickingInfo;
     })();
     BABYLON.PickingInfo = PickingInfo;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.pickingInfo.js.map
+//# sourceMappingURL=babylon.pickingInfo.js.map

+ 23 - 7
Babylon/Culling/Octrees/babylon.octree.js

@@ -1,8 +1,8 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var Octree = (function () {
         function Octree(creationFunc, maxBlockCapacity, maxDepth) {
-            if (maxDepth === void 0) { maxDepth = 2; }
+            if (typeof maxDepth === "undefined") { maxDepth = 2; }
             this.maxDepth = maxDepth;
             this.dynamicContent = new Array();
             this._maxBlockCapacity = maxBlockCapacity || 64;
@@ -13,57 +13,71 @@ var BABYLON;
         Octree.prototype.update = function (worldMin, worldMax, entries) {
             Octree._CreateBlocks(worldMin, worldMax, entries, this._maxBlockCapacity, 0, this.maxDepth, this, this._creationFunc);
         };
+
         Octree.prototype.addMesh = function (entry) {
             for (var index = 0; index < this.blocks.length; index++) {
                 var block = this.blocks[index];
                 block.addEntry(entry);
             }
         };
+
         Octree.prototype.select = function (frustumPlanes, allowDuplicate) {
             this._selectionContent.reset();
+
             for (var index = 0; index < this.blocks.length; index++) {
                 var block = this.blocks[index];
                 block.select(frustumPlanes, this._selectionContent, allowDuplicate);
             }
+
             if (allowDuplicate) {
                 this._selectionContent.concat(this.dynamicContent);
-            }
-            else {
+            } else {
                 this._selectionContent.concatWithNoDuplicate(this.dynamicContent);
             }
+
             return this._selectionContent;
         };
+
         Octree.prototype.intersects = function (sphereCenter, sphereRadius, allowDuplicate) {
             this._selectionContent.reset();
+
             for (var index = 0; index < this.blocks.length; index++) {
                 var block = this.blocks[index];
                 block.intersects(sphereCenter, sphereRadius, this._selectionContent, allowDuplicate);
             }
+
             if (allowDuplicate) {
                 this._selectionContent.concat(this.dynamicContent);
-            }
-            else {
+            } else {
                 this._selectionContent.concatWithNoDuplicate(this.dynamicContent);
             }
+
             return this._selectionContent;
         };
+
         Octree.prototype.intersectsRay = function (ray) {
             this._selectionContent.reset();
+
             for (var index = 0; index < this.blocks.length; index++) {
                 var block = this.blocks[index];
                 block.intersectsRay(ray, this._selectionContent);
             }
+
             this._selectionContent.concatWithNoDuplicate(this.dynamicContent);
+
             return this._selectionContent;
         };
+
         Octree._CreateBlocks = function (worldMin, worldMax, entries, maxBlockCapacity, currentDepth, maxDepth, target, creationFunc) {
             target.blocks = new Array();
             var blockSize = new BABYLON.Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);
+
             for (var x = 0; x < 2; x++) {
                 for (var y = 0; y < 2; y++) {
                     for (var z = 0; z < 2; z++) {
                         var localMin = worldMin.add(blockSize.multiplyByFloats(x, y, z));
                         var localMax = worldMin.add(blockSize.multiplyByFloats(x + 1, y + 1, z + 1));
+
                         var block = new BABYLON.OctreeBlock(localMin, localMax, maxBlockCapacity, currentDepth + 1, maxDepth, creationFunc);
                         block.addEntries(entries);
                         target.blocks.push(block);
@@ -71,11 +85,13 @@ var BABYLON;
                 }
             }
         };
+
         Octree.CreationFuncForMeshes = function (entry, block) {
             if (!entry.isBlocked && entry.getBoundingInfo().boundingBox.intersectsMinMax(block.minPoint, block.maxPoint)) {
                 block.entries.push(entry);
             }
         };
+
         Octree.CreationFuncForSubMeshes = function (entry, block) {
             if (entry.getBoundingInfo().boundingBox.intersectsMinMax(block.minPoint, block.maxPoint)) {
                 block.entries.push(entry);
@@ -85,4 +101,4 @@ var BABYLON;
     })();
     BABYLON.Octree = Octree;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.octree.js.map
+//# sourceMappingURL=babylon.octree.js.map

+ 24 - 6
Babylon/Culling/Octrees/babylon.octreeBlock.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var OctreeBlock = (function () {
         function OctreeBlock(minPoint, maxPoint, capacity, depth, maxDepth, creationFunc) {
@@ -8,20 +8,28 @@ var BABYLON;
             this._depth = depth;
             this._maxDepth = maxDepth;
             this._creationFunc = creationFunc;
+
             this._minPoint = minPoint;
             this._maxPoint = maxPoint;
+
             this._boundingVectors.push(minPoint.clone());
             this._boundingVectors.push(maxPoint.clone());
+
             this._boundingVectors.push(minPoint.clone());
             this._boundingVectors[2].x = maxPoint.x;
+
             this._boundingVectors.push(minPoint.clone());
             this._boundingVectors[3].y = maxPoint.y;
+
             this._boundingVectors.push(minPoint.clone());
             this._boundingVectors[4].z = maxPoint.z;
+
             this._boundingVectors.push(maxPoint.clone());
             this._boundingVectors[5].z = minPoint.z;
+
             this._boundingVectors.push(maxPoint.clone());
             this._boundingVectors[6].x = minPoint.x;
+
             this._boundingVectors.push(maxPoint.clone());
             this._boundingVectors[7].y = minPoint.y;
         }
@@ -33,6 +41,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(OctreeBlock.prototype, "minPoint", {
             get: function () {
                 return this._minPoint;
@@ -40,6 +49,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(OctreeBlock.prototype, "maxPoint", {
             get: function () {
                 return this._maxPoint;
@@ -47,6 +57,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         // Methods
         OctreeBlock.prototype.addEntry = function (entry) {
             if (this.blocks) {
@@ -56,17 +67,21 @@ var BABYLON;
                 }
                 return;
             }
+
             this._creationFunc(entry, this);
+
             if (this.entries.length > this.capacity && this._depth < this._maxDepth) {
                 this.createInnerBlocks();
             }
         };
+
         OctreeBlock.prototype.addEntries = function (entries) {
             for (var index = 0; index < entries.length; index++) {
                 var mesh = entries[index];
                 this.addEntry(mesh);
             }
         };
+
         OctreeBlock.prototype.select = function (frustumPlanes, selection, allowDuplicate) {
             if (BABYLON.BoundingBox.IsInFrustum(this._boundingVectors, frustumPlanes)) {
                 if (this.blocks) {
@@ -76,14 +91,15 @@ var BABYLON;
                     }
                     return;
                 }
+
                 if (allowDuplicate) {
                     selection.concat(this.entries);
-                }
-                else {
+                } else {
                     selection.concatWithNoDuplicate(this.entries);
                 }
             }
         };
+
         OctreeBlock.prototype.intersects = function (sphereCenter, sphereRadius, selection, allowDuplicate) {
             if (BABYLON.BoundingBox.IntersectsSphere(this._minPoint, this._maxPoint, sphereCenter, sphereRadius)) {
                 if (this.blocks) {
@@ -93,14 +109,15 @@ var BABYLON;
                     }
                     return;
                 }
+
                 if (allowDuplicate) {
                     selection.concat(this.entries);
-                }
-                else {
+                } else {
                     selection.concatWithNoDuplicate(this.entries);
                 }
             }
         };
+
         OctreeBlock.prototype.intersectsRay = function (ray, selection) {
             if (ray.intersectsBoxMinMax(this._minPoint, this._maxPoint)) {
                 if (this.blocks) {
@@ -113,6 +130,7 @@ var BABYLON;
                 selection.concatWithNoDuplicate(this.entries);
             }
         };
+
         OctreeBlock.prototype.createInnerBlocks = function () {
             BABYLON.Octree._CreateBlocks(this._minPoint, this._maxPoint, this.entries, this._capacity, this._depth, this._maxDepth, this, this._creationFunc);
         };
@@ -120,4 +138,4 @@ var BABYLON;
     })();
     BABYLON.OctreeBlock = OctreeBlock;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.octreeBlock.js.map
+//# sourceMappingURL=babylon.octreeBlock.js.map

+ 40 - 5
Babylon/Culling/babylon.boundingBox.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var BoundingBox = (function () {
         function BoundingBox(minimum, maximum) {
@@ -6,48 +6,61 @@ var BABYLON;
             this.maximum = maximum;
             this.vectors = new Array();
             this.vectorsWorld = new Array();
-            // Bounding vectors            
+            // Bounding vectors
             this.vectors.push(this.minimum.clone());
             this.vectors.push(this.maximum.clone());
+
             this.vectors.push(this.minimum.clone());
             this.vectors[2].x = this.maximum.x;
+
             this.vectors.push(this.minimum.clone());
             this.vectors[3].y = this.maximum.y;
+
             this.vectors.push(this.minimum.clone());
             this.vectors[4].z = this.maximum.z;
+
             this.vectors.push(this.maximum.clone());
             this.vectors[5].z = this.minimum.z;
+
             this.vectors.push(this.maximum.clone());
             this.vectors[6].x = this.minimum.x;
+
             this.vectors.push(this.maximum.clone());
             this.vectors[7].y = this.minimum.y;
+
             // OBB
             this.center = this.maximum.add(this.minimum).scale(0.5);
             this.extendSize = this.maximum.subtract(this.minimum).scale(0.5);
             this.directions = [BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero()];
+
             for (var index = 0; index < this.vectors.length; index++) {
                 this.vectorsWorld[index] = BABYLON.Vector3.Zero();
             }
             this.minimumWorld = BABYLON.Vector3.Zero();
             this.maximumWorld = BABYLON.Vector3.Zero();
+
             this._update(BABYLON.Matrix.Identity());
         }
         // Methods
         BoundingBox.prototype.getWorldMatrix = function () {
             return this._worldMatrix;
         };
+
         BoundingBox.prototype._update = function (world) {
             BABYLON.Vector3.FromFloatsToRef(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, this.minimumWorld);
             BABYLON.Vector3.FromFloatsToRef(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE, this.maximumWorld);
+
             for (var index = 0; index < this.vectors.length; index++) {
                 var v = this.vectorsWorld[index];
                 BABYLON.Vector3.TransformCoordinatesToRef(this.vectors[index], world, v);
+
                 if (v.x < this.minimumWorld.x)
                     this.minimumWorld.x = v.x;
                 if (v.y < this.minimumWorld.y)
                     this.minimumWorld.y = v.y;
                 if (v.z < this.minimumWorld.z)
                     this.minimumWorld.z = v.z;
+
                 if (v.x > this.maximumWorld.x)
                     this.maximumWorld.x = v.x;
                 if (v.y > this.maximumWorld.y)
@@ -55,57 +68,78 @@ var BABYLON;
                 if (v.z > this.maximumWorld.z)
                     this.maximumWorld.z = v.z;
             }
+
             // OBB
             this.maximumWorld.addToRef(this.minimumWorld, this.center);
             this.center.scaleInPlace(0.5);
+
             BABYLON.Vector3.FromFloatArrayToRef(world.m, 0, this.directions[0]);
             BABYLON.Vector3.FromFloatArrayToRef(world.m, 4, this.directions[1]);
             BABYLON.Vector3.FromFloatArrayToRef(world.m, 8, this.directions[2]);
+
             this._worldMatrix = world;
         };
+
         BoundingBox.prototype.isInFrustum = function (frustumPlanes) {
             return BoundingBox.IsInFrustum(this.vectorsWorld, frustumPlanes);
         };
+
         BoundingBox.prototype.isCompletelyInFrustum = function (frustumPlanes) {
             return BoundingBox.IsCompletelyInFrustum(this.vectorsWorld, frustumPlanes);
         };
+
         BoundingBox.prototype.intersectsPoint = function (point) {
             var delta = BABYLON.Engine.Epsilon;
+
             if (this.maximumWorld.x - point.x < delta || delta > point.x - this.minimumWorld.x)
                 return false;
+
             if (this.maximumWorld.y - point.y < delta || delta > point.y - this.minimumWorld.y)
                 return false;
+
             if (this.maximumWorld.z - point.z < delta || delta > point.z - this.minimumWorld.z)
                 return false;
+
             return true;
         };
+
         BoundingBox.prototype.intersectsSphere = function (sphere) {
             return BoundingBox.IntersectsSphere(this.minimumWorld, this.maximumWorld, sphere.centerWorld, sphere.radiusWorld);
         };
+
         BoundingBox.prototype.intersectsMinMax = function (min, max) {
             if (this.maximumWorld.x < min.x || this.minimumWorld.x > max.x)
                 return false;
+
             if (this.maximumWorld.y < min.y || this.minimumWorld.y > max.y)
                 return false;
+
             if (this.maximumWorld.z < min.z || this.minimumWorld.z > max.z)
                 return false;
+
             return true;
         };
+
         // Statics
         BoundingBox.Intersects = function (box0, box1) {
             if (box0.maximumWorld.x < box1.minimumWorld.x || box0.minimumWorld.x > box1.maximumWorld.x)
                 return false;
+
             if (box0.maximumWorld.y < box1.minimumWorld.y || box0.minimumWorld.y > box1.maximumWorld.y)
                 return false;
+
             if (box0.maximumWorld.z < box1.minimumWorld.z || box0.minimumWorld.z > box1.maximumWorld.z)
                 return false;
+
             return true;
         };
+
         BoundingBox.IntersectsSphere = function (minPoint, maxPoint, sphereCenter, sphereRadius) {
             var vector = BABYLON.Vector3.Clamp(sphereCenter, minPoint, maxPoint);
             var num = BABYLON.Vector3.DistanceSquared(sphereCenter, vector);
             return (num <= (sphereRadius * sphereRadius));
         };
+
         BoundingBox.IsCompletelyInFrustum = function (boundingVectors, frustumPlanes) {
             for (var p = 0; p < 6; p++) {
                 for (var i = 0; i < 8; i++) {
@@ -116,14 +150,15 @@ var BABYLON;
             }
             return true;
         };
+
         BoundingBox.IsInFrustum = function (boundingVectors, frustumPlanes) {
             for (var p = 0; p < 6; p++) {
                 var inCount = 8;
+
                 for (var i = 0; i < 8; i++) {
                     if (frustumPlanes[p].dotCoordinate(boundingVectors[i]) < 0) {
                         --inCount;
-                    }
-                    else {
+                    } else {
                         break;
                     }
                 }
@@ -136,4 +171,4 @@ var BABYLON;
     })();
     BABYLON.BoundingBox = BoundingBox;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.boundingBox.js.map
+//# sourceMappingURL=babylon.boundingBox.js.map

+ 26 - 3
Babylon/Culling/babylon.boundingInfo.js

@@ -1,22 +1,30 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var computeBoxExtents = function (axis, box) {
         var p = BABYLON.Vector3.Dot(box.center, axis);
+
         var r0 = Math.abs(BABYLON.Vector3.Dot(box.directions[0], axis)) * box.extendSize.x;
         var r1 = Math.abs(BABYLON.Vector3.Dot(box.directions[1], axis)) * box.extendSize.y;
         var r2 = Math.abs(BABYLON.Vector3.Dot(box.directions[2], axis)) * box.extendSize.z;
+
         var r = r0 + r1 + r2;
         return {
             min: p - r,
             max: p + r
         };
     };
-    var extentsOverlap = function (min0, max0, min1, max1) { return !(min0 > max1 || min1 > max0); };
+
+    var extentsOverlap = function (min0, max0, min1, max1) {
+        return !(min0 > max1 || min1 > max0);
+    };
+
     var axisOverlap = function (axis, box0, box1) {
         var result0 = computeBoxExtents(axis, box0);
         var result1 = computeBoxExtents(axis, box1);
+
         return extentsOverlap(result0.min, result0.max, result1.min, result1.max);
     };
+
     var BoundingInfo = (function () {
         function BoundingInfo(minimum, maximum) {
             this.minimum = minimum;
@@ -29,44 +37,58 @@ var BABYLON;
             this.boundingBox._update(world);
             this.boundingSphere._update(world);
         };
+
         BoundingInfo.prototype.isInFrustum = function (frustumPlanes) {
             if (!this.boundingSphere.isInFrustum(frustumPlanes))
                 return false;
+
             return this.boundingBox.isInFrustum(frustumPlanes);
         };
+
         BoundingInfo.prototype.isCompletelyInFrustum = function (frustumPlanes) {
             return this.boundingBox.isCompletelyInFrustum(frustumPlanes);
         };
+
         BoundingInfo.prototype._checkCollision = function (collider) {
             return collider._canDoCollision(this.boundingSphere.centerWorld, this.boundingSphere.radiusWorld, this.boundingBox.minimumWorld, this.boundingBox.maximumWorld);
         };
+
         BoundingInfo.prototype.intersectsPoint = function (point) {
             if (!this.boundingSphere.centerWorld) {
                 return false;
             }
+
             if (!this.boundingSphere.intersectsPoint(point)) {
                 return false;
             }
+
             if (!this.boundingBox.intersectsPoint(point)) {
                 return false;
             }
+
             return true;
         };
+
         BoundingInfo.prototype.intersects = function (boundingInfo, precise) {
             if (!this.boundingSphere.centerWorld || !boundingInfo.boundingSphere.centerWorld) {
                 return false;
             }
+
             if (!BABYLON.BoundingSphere.Intersects(this.boundingSphere, boundingInfo.boundingSphere)) {
                 return false;
             }
+
             if (!BABYLON.BoundingBox.Intersects(this.boundingBox, boundingInfo.boundingBox)) {
                 return false;
             }
+
             if (!precise) {
                 return true;
             }
+
             var box0 = this.boundingBox;
             var box1 = boundingInfo.boundingBox;
+
             if (!axisOverlap(box0.directions[0], box0, box1))
                 return false;
             if (!axisOverlap(box0.directions[1], box0, box1))
@@ -97,10 +119,11 @@ var BABYLON;
                 return false;
             if (!axisOverlap(BABYLON.Vector3.Cross(box0.directions[2], box1.directions[2]), box0, box1))
                 return false;
+
             return true;
         };
         return BoundingInfo;
     })();
     BABYLON.BoundingInfo = BoundingInfo;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.boundingInfo.js.map
+//# sourceMappingURL=babylon.boundingInfo.js.map

+ 14 - 2
Babylon/Culling/babylon.boundingSphere.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var BoundingSphere = (function () {
         function BoundingSphere(minimum, maximum) {
@@ -6,8 +6,10 @@ var BABYLON;
             this.maximum = maximum;
             this._tempRadiusVector = BABYLON.Vector3.Zero();
             var distance = BABYLON.Vector3.Distance(minimum, maximum);
+
             this.center = BABYLON.Vector3.Lerp(minimum, maximum, 0.5);
             this.radius = distance * 0.5;
+
             this.centerWorld = BABYLON.Vector3.Zero();
             this._update(BABYLON.Matrix.Identity());
         }
@@ -17,34 +19,44 @@ var BABYLON;
             BABYLON.Vector3.TransformNormalFromFloatsToRef(1.0, 1.0, 1.0, world, this._tempRadiusVector);
             this.radiusWorld = Math.max(Math.abs(this._tempRadiusVector.x), Math.abs(this._tempRadiusVector.y), Math.abs(this._tempRadiusVector.z)) * this.radius;
         };
+
         BoundingSphere.prototype.isInFrustum = function (frustumPlanes) {
             for (var i = 0; i < 6; i++) {
                 if (frustumPlanes[i].dotCoordinate(this.centerWorld) <= -this.radiusWorld)
                     return false;
             }
+
             return true;
         };
+
         BoundingSphere.prototype.intersectsPoint = function (point) {
             var x = this.centerWorld.x - point.x;
             var y = this.centerWorld.y - point.y;
             var z = this.centerWorld.z - point.z;
+
             var distance = Math.sqrt((x * x) + (y * y) + (z * z));
+
             if (Math.abs(this.radiusWorld - distance) < BABYLON.Engine.Epsilon)
                 return false;
+
             return true;
         };
+
         // Statics
         BoundingSphere.Intersects = function (sphere0, sphere1) {
             var x = sphere0.centerWorld.x - sphere1.centerWorld.x;
             var y = sphere0.centerWorld.y - sphere1.centerWorld.y;
             var z = sphere0.centerWorld.z - sphere1.centerWorld.z;
+
             var distance = Math.sqrt((x * x) + (y * y) + (z * z));
+
             if (sphere0.radiusWorld + sphere1.radiusWorld < distance)
                 return false;
+
             return true;
         };
         return BoundingSphere;
     })();
     BABYLON.BoundingSphere = BoundingSphere;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.boundingSphere.js.map
+//# sourceMappingURL=babylon.boundingSphere.js.map

Plik diff jest za duży
+ 122 - 14
Babylon/Debug/babylon.debugLayer.js


Plik diff jest za duży
+ 1 - 1
Babylon/Debug/babylon.debugLayer.js.map


+ 20 - 2
Babylon/Layer/babylon.layer.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var Layer = (function () {
         function Layer(name, imgUrl, scene, isBackground, color) {
@@ -8,24 +8,31 @@ var BABYLON;
             this.texture = imgUrl ? new BABYLON.Texture(imgUrl, scene, true) : null;
             this.isBackground = isBackground === undefined ? true : isBackground;
             this.color = color === undefined ? new BABYLON.Color4(1, 1, 1, 1) : color;
+
             this._scene = scene;
             this._scene.layers.push(this);
+
             // VBO
             var vertices = [];
             vertices.push(1, 1);
             vertices.push(-1, 1);
             vertices.push(-1, -1);
             vertices.push(1, -1);
+
             this._vertexBuffer = scene.getEngine().createVertexBuffer(vertices);
+
             // Indices
             var indices = [];
             indices.push(0);
             indices.push(1);
             indices.push(2);
+
             indices.push(0);
             indices.push(2);
             indices.push(3);
+
             this._indexBuffer = scene.getEngine().createIndexBuffer(indices);
+
             // Effects
             this._effect = this._scene.getEngine().createEffect("layer", ["position"], ["textureMatrix", "color"], ["textureSampler"], "");
         }
@@ -33,38 +40,49 @@ var BABYLON;
             // Check
             if (!this._effect.isReady() || !this.texture || !this.texture.isReady())
                 return;
+
             var engine = this._scene.getEngine();
+
             // Render
             engine.enableEffect(this._effect);
             engine.setState(false);
+
             // Texture
             this._effect.setTexture("textureSampler", this.texture);
             this._effect.setMatrix("textureMatrix", this.texture.getTextureMatrix());
+
             // Color
             this._effect.setFloat4("color", this.color.r, this.color.g, this.color.b, this.color.a);
+
             // VBOs
             engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, this._effect);
+
             // Draw order
             engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE);
             engine.draw(true, 0, 6);
             engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
         };
+
         Layer.prototype.dispose = function () {
             if (this._vertexBuffer) {
                 this._scene.getEngine()._releaseBuffer(this._vertexBuffer);
                 this._vertexBuffer = null;
             }
+
             if (this._indexBuffer) {
                 this._scene.getEngine()._releaseBuffer(this._indexBuffer);
                 this._indexBuffer = null;
             }
+
             if (this.texture) {
                 this.texture.dispose();
                 this.texture = null;
             }
+
             // Remove from scene
             var index = this._scene.layers.indexOf(this);
             this._scene.layers.splice(index, 1);
+
             // Callback
             if (this.onDispose) {
                 this.onDispose();
@@ -74,4 +92,4 @@ var BABYLON;
     })();
     BABYLON.Layer = Layer;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.layer.js.map
+//# sourceMappingURL=babylon.layer.js.map

+ 4 - 2
Babylon/LensFlare/babylon.lensFlare.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var LensFlare = (function () {
         function LensFlare(size, position, color, imgUrl, system) {
@@ -8,6 +8,7 @@ var BABYLON;
                 if (this.texture) {
                     this.texture.dispose();
                 }
+
                 // Remove from scene
                 var index = this._system.lensFlares.indexOf(this);
                 this._system.lensFlares.splice(index, 1);
@@ -15,10 +16,11 @@ var BABYLON;
             this.color = color || new BABYLON.Color3(1, 1, 1);
             this.texture = imgUrl ? new BABYLON.Texture(imgUrl, system.getScene(), true) : null;
             this._system = system;
+
             system.lensFlares.push(this);
         }
         return LensFlare;
     })();
     BABYLON.LensFlare = LensFlare;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.lensFlare.js.map
+//# sourceMappingURL=babylon.lensFlare.js.map

+ 56 - 11
Babylon/LensFlare/babylon.lensFlareSystem.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var LensFlareSystem = (function () {
         function LensFlareSystem(name, emitter, scene) {
@@ -11,23 +11,32 @@ var BABYLON;
             this._scene = scene;
             this._emitter = emitter;
             scene.lensFlareSystems.push(this);
-            this.meshesSelectionPredicate = function (m) { return m.material && m.isVisible && m.isEnabled() && m.isBlocker && ((m.layerMask & scene.activeCamera.layerMask) != 0); };
+
+            this.meshesSelectionPredicate = function (m) {
+                return m.material && m.isVisible && m.isEnabled() && m.isBlocker && ((m.layerMask & scene.activeCamera.layerMask) != 0);
+            };
+
             // VBO
             var vertices = [];
             vertices.push(1, 1);
             vertices.push(-1, 1);
             vertices.push(-1, -1);
             vertices.push(1, -1);
+
             this._vertexBuffer = scene.getEngine().createVertexBuffer(vertices);
+
             // Indices
             var indices = [];
             indices.push(0);
             indices.push(1);
             indices.push(2);
+
             indices.push(0);
             indices.push(2);
             indices.push(3);
+
             this._indexBuffer = scene.getEngine().createIndexBuffer(indices);
+
             // Effects
             this._effect = this._scene.getEngine().createEffect("lensFlare", ["position"], ["color", "viewportMatrix"], ["textureSampler"], "");
         }
@@ -41,132 +50,168 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         LensFlareSystem.prototype.getScene = function () {
             return this._scene;
         };
+
         LensFlareSystem.prototype.getEmitter = function () {
             return this._emitter;
         };
+
         LensFlareSystem.prototype.getEmitterPosition = function () {
             return this._emitter.getAbsolutePosition ? this._emitter.getAbsolutePosition() : this._emitter.position;
         };
+
         LensFlareSystem.prototype.computeEffectivePosition = function (globalViewport) {
             var position = this.getEmitterPosition();
+
             position = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), this._scene.getTransformMatrix(), globalViewport);
+
             this._positionX = position.x;
             this._positionY = position.y;
+
             position = BABYLON.Vector3.TransformCoordinates(this.getEmitterPosition(), this._scene.getViewMatrix());
+
             if (position.z > 0) {
                 if ((this._positionX > globalViewport.x) && (this._positionX < globalViewport.x + globalViewport.width)) {
                     if ((this._positionY > globalViewport.y) && (this._positionY < globalViewport.y + globalViewport.height))
                         return true;
                 }
             }
+
             return false;
         };
+
         LensFlareSystem.prototype._isVisible = function () {
             if (!this._isEnabled) {
                 return false;
             }
+
             var emitterPosition = this.getEmitterPosition();
             var direction = emitterPosition.subtract(this._scene.activeCamera.position);
             var distance = direction.length();
             direction.normalize();
+
             var ray = new BABYLON.Ray(this._scene.activeCamera.position, direction);
             var pickInfo = this._scene.pickWithRay(ray, this.meshesSelectionPredicate, true);
+
             return !pickInfo.hit || pickInfo.distance > distance;
         };
+
         LensFlareSystem.prototype.render = function () {
             if (!this._effect.isReady())
                 return false;
+
             var engine = this._scene.getEngine();
             var viewport = this._scene.activeCamera.viewport;
             var globalViewport = viewport.toGlobal(engine);
+
             // Position
             if (!this.computeEffectivePosition(globalViewport)) {
                 return false;
             }
+
             // Visibility
             if (!this._isVisible()) {
                 return false;
             }
+
             // Intensity
             var awayX;
             var awayY;
+
             if (this._positionX < this.borderLimit + globalViewport.x) {
                 awayX = this.borderLimit + globalViewport.x - this._positionX;
-            }
-            else if (this._positionX > globalViewport.x + globalViewport.width - this.borderLimit) {
+            } else if (this._positionX > globalViewport.x + globalViewport.width - this.borderLimit) {
                 awayX = this._positionX - globalViewport.x - globalViewport.width + this.borderLimit;
-            }
-            else {
+            } else {
                 awayX = 0;
             }
+
             if (this._positionY < this.borderLimit + globalViewport.y) {
                 awayY = this.borderLimit + globalViewport.y - this._positionY;
-            }
-            else if (this._positionY > globalViewport.y + globalViewport.height - this.borderLimit) {
+            } else if (this._positionY > globalViewport.y + globalViewport.height - this.borderLimit) {
                 awayY = this._positionY - globalViewport.y - globalViewport.height + this.borderLimit;
-            }
-            else {
+            } else {
                 awayY = 0;
             }
+
             var away = (awayX > awayY) ? awayX : awayY;
             if (away > this.borderLimit) {
                 away = this.borderLimit;
             }
+
             var intensity = 1.0 - (away / this.borderLimit);
             if (intensity < 0) {
                 return false;
             }
+
             if (intensity > 1.0) {
                 intensity = 1.0;
             }
+
             // Position
             var centerX = globalViewport.x + globalViewport.width / 2;
             var centerY = globalViewport.y + globalViewport.height / 2;
             var distX = centerX - this._positionX;
             var distY = centerY - this._positionY;
+
             // Effects
             engine.enableEffect(this._effect);
             engine.setState(false);
             engine.setDepthBuffer(false);
             engine.setAlphaMode(BABYLON.Engine.ALPHA_ADD);
+
             // VBOs
             engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, this._effect);
+
             for (var index = 0; index < this.lensFlares.length; index++) {
                 var flare = this.lensFlares[index];
+
                 var x = centerX - (distX * flare.position);
                 var y = centerY - (distY * flare.position);
+
                 var cw = flare.size;
                 var ch = flare.size * engine.getAspectRatio(this._scene.activeCamera);
                 var cx = 2 * (x / globalViewport.width) - 1.0;
                 var cy = 1.0 - 2 * (y / globalViewport.height);
+
                 var viewportMatrix = BABYLON.Matrix.FromValues(cw / 2, 0, 0, 0, 0, ch / 2, 0, 0, 0, 0, 1, 0, cx, cy, 0, 1);
+
                 this._effect.setMatrix("viewportMatrix", viewportMatrix);
+
                 // Texture
                 this._effect.setTexture("textureSampler", flare.texture);
+
                 // Color
                 this._effect.setFloat4("color", flare.color.r * intensity, flare.color.g * intensity, flare.color.b * intensity, 1.0);
+
                 // Draw order
                 engine.draw(true, 0, 6);
             }
+
             engine.setDepthBuffer(true);
             engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
             return true;
         };
+
         LensFlareSystem.prototype.dispose = function () {
             if (this._vertexBuffer) {
                 this._scene.getEngine()._releaseBuffer(this._vertexBuffer);
                 this._vertexBuffer = null;
             }
+
             if (this._indexBuffer) {
                 this._scene.getEngine()._releaseBuffer(this._indexBuffer);
                 this._indexBuffer = null;
             }
+
             while (this.lensFlares.length) {
                 this.lensFlares[0].dispose();
             }
+
             // Remove from scene
             var index = this._scene.lensFlareSystems.indexOf(this);
             this._scene.lensFlareSystems.splice(index, 1);
@@ -175,4 +220,4 @@ var BABYLON;
     })();
     BABYLON.LensFlareSystem = LensFlareSystem;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.lensFlareSystem.js.map
+//# sourceMappingURL=babylon.lensFlareSystem.js.map

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

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var ShadowGenerator = (function () {
         function ShadowGenerator(mapSize, light) {
@@ -13,73 +13,92 @@ var BABYLON;
             this._worldViewProjection = BABYLON.Matrix.Zero();
             this._light = light;
             this._scene = light.getScene();
+
             light._shadowGenerator = this;
+
             // Render target
             this._shadowMap = new BABYLON.RenderTargetTexture(light.name + "_shadowMap", mapSize, this._scene, false);
             this._shadowMap.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._shadowMap.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._shadowMap.renderParticles = false;
+
             // Custom render function
             var renderSubMesh = function (subMesh) {
                 var mesh = subMesh.getRenderingMesh();
                 var scene = _this._scene;
                 var engine = scene.getEngine();
+
                 // Culling
                 engine.setState(subMesh.getMaterial().backFaceCulling);
+
                 // Managing instances
                 var batch = mesh._getInstancesRenderList(subMesh._id);
+
                 if (batch.mustReturn) {
                     return;
                 }
+
                 var hardwareInstancedRendering = (engine.getCaps().instancedArrays !== null) && (batch.visibleInstances[subMesh._id] !== null);
+
                 if (_this.isReady(subMesh, hardwareInstancedRendering)) {
                     engine.enableEffect(_this._effect);
                     mesh._bind(subMesh, _this._effect, BABYLON.Material.TriangleFillMode);
                     var material = subMesh.getMaterial();
+
                     _this._effect.setMatrix("viewProjection", _this.getTransformMatrix());
+
                     // Alpha test
                     if (material && material.needAlphaTesting()) {
                         var alphaTexture = material.getAlphaTestTexture();
                         _this._effect.setTexture("diffuseSampler", alphaTexture);
                         _this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
                     }
+
                     // Bones
                     var useBones = mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind);
+
                     if (useBones) {
                         _this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
                     }
+
                     if (hardwareInstancedRendering) {
                         mesh._renderWithInstances(subMesh, BABYLON.Material.TriangleFillMode, batch, _this._effect, engine);
-                    }
-                    else {
+                    } else {
                         if (batch.renderSelf[subMesh._id]) {
                             _this._effect.setMatrix("world", mesh.getWorldMatrix());
+
                             // Draw
                             mesh._draw(subMesh, BABYLON.Material.TriangleFillMode);
                         }
+
                         if (batch.visibleInstances[subMesh._id]) {
                             for (var instanceIndex = 0; instanceIndex < batch.visibleInstances[subMesh._id].length; instanceIndex++) {
                                 var instance = batch.visibleInstances[subMesh._id][instanceIndex];
+
                                 _this._effect.setMatrix("world", instance.getWorldMatrix());
+
                                 // Draw
                                 mesh._draw(subMesh, BABYLON.Material.TriangleFillMode);
                             }
                         }
                     }
-                }
-                else {
+                } else {
                     // Need to reset refresh rate of the shadowMap
                     _this._shadowMap.resetRefreshCounter();
                 }
             };
+
             this._shadowMap.customRenderFunction = function (opaqueSubMeshes, alphaTestSubMeshes, transparentSubMeshes) {
                 var index;
+
                 for (index = 0; index < opaqueSubMeshes.length; index++) {
                     renderSubMesh(opaqueSubMeshes.data[index]);
                 }
+
                 for (index = 0; index < alphaTestSubMeshes.length; index++) {
                     renderSubMesh(alphaTestSubMeshes.data[index]);
                 }
+
                 if (_this._transparencyShadow) {
                     for (index = 0; index < transparentSubMeshes.length; index++) {
                         renderSubMesh(transparentSubMeshes.data[index]);
@@ -95,6 +114,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ShadowGenerator, "FILTER_VARIANCESHADOWMAP", {
             get: function () {
                 return ShadowGenerator._FILTER_VARIANCESHADOWMAP;
@@ -102,6 +122,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ShadowGenerator, "FILTER_POISSONSAMPLING", {
             get: function () {
                 return ShadowGenerator._FILTER_POISSONSAMPLING;
@@ -109,6 +130,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ShadowGenerator.prototype, "useVarianceShadowMap", {
             get: function () {
                 return this.filter === ShadowGenerator.FILTER_VARIANCESHADOWMAP;
@@ -119,6 +141,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(ShadowGenerator.prototype, "usePoissonSampling", {
             get: function () {
                 return this.filter === ShadowGenerator.FILTER_POISSONSAMPLING;
@@ -129,15 +152,20 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         ShadowGenerator.prototype.isReady = function (subMesh, useInstances) {
             var defines = [];
+
             if (this.useVarianceShadowMap) {
                 defines.push("#define VSM");
             }
+
             var attribs = [BABYLON.VertexBuffer.PositionKind];
+
             var mesh = subMesh.getMesh();
             var scene = mesh.getScene();
             var material = subMesh.getMaterial();
+
             // Alpha test
             if (material && material.needAlphaTesting()) {
                 defines.push("#define ALPHATEST");
@@ -150,6 +178,7 @@ var BABYLON;
                     defines.push("#define UV2");
                 }
             }
+
             // Bones
             if (mesh.skeleton && scene.skeletonsEnabled && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
                 attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
@@ -157,6 +186,7 @@ var BABYLON;
                 defines.push("#define BONES");
                 defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
             }
+
             // Instances
             if (useInstances) {
                 defines.push("#define INSTANCES");
@@ -165,40 +195,53 @@ var BABYLON;
                 attribs.push("world2");
                 attribs.push("world3");
             }
-            // Get correct effect      
+
+            // Get correct effect
             var join = defines.join("\n");
             if (this._cachedDefines !== join) {
                 this._cachedDefines = join;
                 this._effect = this._scene.getEngine().createEffect("shadowMap", attribs, ["world", "mBones", "viewProjection", "diffuseMatrix"], ["diffuseSampler"], join);
             }
+
             return this._effect.isReady();
         };
+
         ShadowGenerator.prototype.getShadowMap = function () {
             return this._shadowMap;
         };
+
         ShadowGenerator.prototype.getLight = function () {
             return this._light;
         };
+
         // Methods
         ShadowGenerator.prototype.getTransformMatrix = function () {
             var lightPosition = this._light.position;
             var lightDirection = this._light.direction;
+
             if (this._light.computeTransformedPosition()) {
                 lightPosition = this._light.transformedPosition;
             }
+
             if (!this._cachedPosition || !this._cachedDirection || !lightPosition.equals(this._cachedPosition) || !lightDirection.equals(this._cachedDirection)) {
                 this._cachedPosition = lightPosition.clone();
                 this._cachedDirection = lightDirection.clone();
+
                 var activeCamera = this._scene.activeCamera;
+
                 BABYLON.Matrix.LookAtLHToRef(lightPosition, this._light.position.add(lightDirection), BABYLON.Vector3.Up(), this._viewMatrix);
                 BABYLON.Matrix.PerspectiveFovLHToRef(Math.PI / 2.0, 1.0, activeCamera.minZ, activeCamera.maxZ, this._projectionMatrix);
+
                 this._viewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);
             }
+
             return this._transformMatrix;
         };
+
         ShadowGenerator.prototype.getDarkness = function () {
             return this._darkness;
         };
+
         ShadowGenerator.prototype.setDarkness = function (darkness) {
             if (darkness >= 1.0)
                 this._darkness = 1.0;
@@ -207,9 +250,11 @@ var BABYLON;
             else
                 this._darkness = darkness;
         };
+
         ShadowGenerator.prototype.setTransparencyShadow = function (hasShadow) {
             this._transparencyShadow = hasShadow;
         };
+
         ShadowGenerator.prototype.dispose = function () {
             this._shadowMap.dispose();
         };
@@ -220,4 +265,4 @@ var BABYLON;
     })();
     BABYLON.ShadowGenerator = ShadowGenerator;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.shadowGenerator.js.map
+//# sourceMappingURL=babylon.shadowGenerator.js.map

+ 14 - 2
Babylon/Lights/babylon.directionalLight.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -11,45 +11,57 @@ var BABYLON;
         function DirectionalLight(name, direction, scene) {
             _super.call(this, name, scene);
             this.direction = direction;
+
             this.position = direction.scale(-1);
         }
         DirectionalLight.prototype.getAbsolutePosition = function () {
             return this.transformedPosition ? this.transformedPosition : this.position;
         };
+
         DirectionalLight.prototype.setDirectionToTarget = function (target) {
             this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
             return this.direction;
         };
+
         DirectionalLight.prototype.computeTransformedPosition = function () {
             if (this.parent && this.parent.getWorldMatrix) {
                 if (!this.transformedPosition) {
                     this.transformedPosition = BABYLON.Vector3.Zero();
                 }
+
                 BABYLON.Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this.transformedPosition);
                 return true;
             }
+
             return false;
         };
+
         DirectionalLight.prototype.transferToEffect = function (effect, directionUniformName) {
             if (this.parent && this.parent.getWorldMatrix) {
                 if (!this._transformedDirection) {
                     this._transformedDirection = BABYLON.Vector3.Zero();
                 }
+
                 BABYLON.Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
                 effect.setFloat4(directionUniformName, this._transformedDirection.x, this._transformedDirection.y, this._transformedDirection.z, 1);
+
                 return;
             }
+
             effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, 1);
         };
+
         DirectionalLight.prototype._getWorldMatrix = function () {
             if (!this._worldMatrix) {
                 this._worldMatrix = BABYLON.Matrix.Identity();
             }
+
             BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
+
             return this._worldMatrix;
         };
         return DirectionalLight;
     })(BABYLON.Light);
     BABYLON.DirectionalLight = DirectionalLight;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.directionalLight.js.map
+//# sourceMappingURL=babylon.directionalLight.js.map

+ 6 - 2
Babylon/Lights/babylon.hemisphericLight.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -17,22 +17,26 @@ var BABYLON;
             this.direction = BABYLON.Vector3.Normalize(target.subtract(BABYLON.Vector3.Zero()));
             return this.direction;
         };
+
         HemisphericLight.prototype.getShadowGenerator = function () {
             return null;
         };
+
         HemisphericLight.prototype.transferToEffect = function (effect, directionUniformName, groundColorUniformName) {
             var normalizeDirection = BABYLON.Vector3.Normalize(this.direction);
             effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, 0);
             effect.setColor3(groundColorUniformName, this.groundColor.scale(this.intensity));
         };
+
         HemisphericLight.prototype._getWorldMatrix = function () {
             if (!this._worldMatrix) {
                 this._worldMatrix = BABYLON.Matrix.Identity();
             }
+
             return this._worldMatrix;
         };
         return HemisphericLight;
     })(BABYLON.Light);
     BABYLON.HemisphericLight = HemisphericLight;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.hemisphericLight.js.map
+//# sourceMappingURL=babylon.hemisphericLight.js.map

+ 18 - 2
Babylon/Lights/babylon.light.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -18,48 +18,64 @@ var BABYLON;
             this.excludedMeshes = new Array();
             this._excludedMeshesIds = new Array();
             this._includedOnlyMeshesIds = new Array();
+
             scene.lights.push(this);
         }
         Light.prototype.getShadowGenerator = function () {
             return this._shadowGenerator;
         };
+
         Light.prototype.getAbsolutePosition = function () {
             return BABYLON.Vector3.Zero();
         };
+
         Light.prototype.transferToEffect = function (effect, uniformName0, uniformName1) {
         };
+
         Light.prototype._getWorldMatrix = function () {
             return BABYLON.Matrix.Identity();
         };
+
         Light.prototype.canAffectMesh = function (mesh) {
             if (!mesh) {
                 return true;
             }
+
             if (this.includedOnlyMeshes.length > 0 && this.includedOnlyMeshes.indexOf(mesh) === -1) {
                 return false;
             }
+
             if (this.excludedMeshes.length > 0 && this.excludedMeshes.indexOf(mesh) !== -1) {
                 return false;
             }
+
             return true;
         };
+
         Light.prototype.getWorldMatrix = function () {
             this._currentRenderId = this.getScene().getRenderId();
+
             var worldMatrix = this._getWorldMatrix();
+
             if (this.parent && this.parent.getWorldMatrix) {
                 if (!this._parentedWorldMatrix) {
                     this._parentedWorldMatrix = BABYLON.Matrix.Identity();
                 }
+
                 worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._parentedWorldMatrix);
+
                 return this._parentedWorldMatrix;
             }
+
             return worldMatrix;
         };
+
         Light.prototype.dispose = function () {
             if (this._shadowGenerator) {
                 this._shadowGenerator.dispose();
                 this._shadowGenerator = null;
             }
+
             // Remove from scene
             var index = this.getScene().lights.indexOf(this);
             this.getScene().lights.splice(index, 1);
@@ -68,4 +84,4 @@ var BABYLON;
     })(BABYLON.Node);
     BABYLON.Light = Light;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.light.js.map
+//# sourceMappingURL=babylon.light.js.map

+ 10 - 2
Babylon/Lights/babylon.pointLight.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -15,29 +15,37 @@ var BABYLON;
         PointLight.prototype.getAbsolutePosition = function () {
             return this._transformedPosition ? this._transformedPosition : this.position;
         };
+
         PointLight.prototype.transferToEffect = function (effect, positionUniformName) {
             if (this.parent && this.parent.getWorldMatrix) {
                 if (!this._transformedPosition) {
                     this._transformedPosition = BABYLON.Vector3.Zero();
                 }
+
                 BABYLON.Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this._transformedPosition);
                 effect.setFloat4(positionUniformName, this._transformedPosition.x, this._transformedPosition.y, this._transformedPosition.z, 0);
+
                 return;
             }
+
             effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, 0);
         };
+
         PointLight.prototype.getShadowGenerator = function () {
             return null;
         };
+
         PointLight.prototype._getWorldMatrix = function () {
             if (!this._worldMatrix) {
                 this._worldMatrix = BABYLON.Matrix.Identity();
             }
+
             BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
+
             return this._worldMatrix;
         };
         return PointLight;
     })(BABYLON.Light);
     BABYLON.PointLight = PointLight;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.pointLight.js.map
+//# sourceMappingURL=babylon.pointLight.js.map

+ 16 - 4
Babylon/Lights/babylon.spotLight.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -18,46 +18,58 @@ var BABYLON;
         SpotLight.prototype.getAbsolutePosition = function () {
             return this.transformedPosition ? this.transformedPosition : this.position;
         };
+
         SpotLight.prototype.setDirectionToTarget = function (target) {
             this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
             return this.direction;
         };
+
         SpotLight.prototype.computeTransformedPosition = function () {
             if (this.parent && this.parent.getWorldMatrix) {
                 if (!this.transformedPosition) {
                     this.transformedPosition = BABYLON.Vector3.Zero();
                 }
+
                 BABYLON.Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this.transformedPosition);
                 return true;
             }
+
             return false;
         };
+
         SpotLight.prototype.transferToEffect = function (effect, positionUniformName, directionUniformName) {
             var normalizeDirection;
+
             if (this.parent && this.parent.getWorldMatrix) {
                 if (!this._transformedDirection) {
                     this._transformedDirection = BABYLON.Vector3.Zero();
                 }
+
                 this.computeTransformedPosition();
+
                 BABYLON.Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
+
                 effect.setFloat4(positionUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, this.exponent);
                 normalizeDirection = BABYLON.Vector3.Normalize(this._transformedDirection);
-            }
-            else {
+            } else {
                 effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, this.exponent);
                 normalizeDirection = BABYLON.Vector3.Normalize(this.direction);
             }
+
             effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, Math.cos(this.angle * 0.5));
         };
+
         SpotLight.prototype._getWorldMatrix = function () {
             if (!this._worldMatrix) {
                 this._worldMatrix = BABYLON.Matrix.Identity();
             }
+
             BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
+
             return this._worldMatrix;
         };
         return SpotLight;
     })(BABYLON.Light);
     BABYLON.SpotLight = SpotLight;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.spotLight.js.map
+//# sourceMappingURL=babylon.spotLight.js.map

Plik diff jest za duży
+ 324 - 76
Babylon/Loading/Plugins/babylon.babylonFileLoader.js


+ 36 - 9
Babylon/Loading/babylon.sceneLoader.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var SceneLoader = (function () {
         function SceneLoader() {
@@ -13,6 +13,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(SceneLoader, "ShowLoadingScreen", {
             get: function () {
                 return SceneLoader._ShowLoadingScreen;
@@ -23,62 +25,79 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         SceneLoader._getPluginForFilename = function (sceneFilename) {
             var dotPosition = sceneFilename.lastIndexOf(".");
+
             var queryStringPosition = sceneFilename.indexOf("?");
             var extension = sceneFilename.substring(dotPosition, queryStringPosition).toLowerCase();
+
             for (var index = 0; index < this._registeredPlugins.length; index++) {
                 var plugin = this._registeredPlugins[index];
+
                 if (plugin.extensions.indexOf(extension) !== -1) {
                     return plugin;
                 }
             }
+
             return this._registeredPlugins[this._registeredPlugins.length - 1];
         };
+
         // Public functions
         SceneLoader.RegisterPlugin = function (plugin) {
             plugin.extensions = plugin.extensions.toLowerCase();
             SceneLoader._registeredPlugins.push(plugin);
         };
+
         SceneLoader.ImportMesh = function (meshesNames, rootUrl, sceneFilename, scene, onsuccess, progressCallBack, onerror) {
             var manifestChecked = function (success) {
                 scene.database = database;
+
                 var plugin = SceneLoader._getPluginForFilename(sceneFilename);
+
                 var importMeshFromData = function (data) {
                     var meshes = [];
                     var particleSystems = [];
                     var skeletons = [];
-                    try {
+
+                    try  {
                         if (!plugin.importMesh(meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons)) {
                             if (onerror) {
                                 onerror(scene, 'unable to load the scene');
                             }
+
                             return;
                         }
-                    }
-                    catch (e) {
+                    } catch (e) {
                         if (onerror) {
                             onerror(scene, e);
                         }
+
                         return;
                     }
+
                     if (onsuccess) {
                         scene.importedMeshesFiles.push(rootUrl + sceneFilename);
                         onsuccess(meshes, particleSystems, skeletons);
                     }
                 };
+
                 if (sceneFilename.substr && sceneFilename.substr(0, 5) === "data:") {
                     // Direct load
                     importMeshFromData(sceneFilename.substr(5));
                     return;
                 }
+
                 BABYLON.Tools.LoadFile(rootUrl + sceneFilename, function (data) {
                     importMeshFromData(data);
                 }, progressCallBack, database);
             };
+
             // Checking if a manifest file has been set for this scene and if offline mode has been requested
             var database = new BABYLON.Database(rootUrl + sceneFilename, manifestChecked);
         };
+
         /**
         * Load a scene
         * @param rootUrl a string that defines the root url for scene and resources
@@ -88,6 +107,7 @@ var BABYLON;
         SceneLoader.Load = function (rootUrl, sceneFilename, engine, onsuccess, progressCallBack, onerror) {
             SceneLoader.Append(rootUrl, sceneFilename, new BABYLON.Scene(engine), onsuccess, progressCallBack, onerror);
         };
+
         /**
         * Append a scene
         * @param rootUrl a string that defines the root url for scene and resources
@@ -97,51 +117,58 @@ var BABYLON;
         SceneLoader.Append = function (rootUrl, sceneFilename, scene, onsuccess, progressCallBack, onerror) {
             var plugin = this._getPluginForFilename(sceneFilename.name || sceneFilename);
             var database;
+
             if (SceneLoader.ShowLoadingScreen) {
                 scene.getEngine().displayLoadingUI();
             }
+
             var loadSceneFromData = function (data) {
                 scene.database = database;
+
                 if (!plugin.load(scene, data, rootUrl)) {
                     if (onerror) {
                         onerror(scene);
                     }
+
                     scene.getEngine().hideLoadingUI();
                     return;
                 }
+
                 if (onsuccess) {
                     onsuccess(scene);
                 }
+
                 if (SceneLoader.ShowLoadingScreen) {
                     scene.executeWhenReady(function () {
                         scene.getEngine().hideLoadingUI();
                     });
                 }
             };
+
             var manifestChecked = function (success) {
                 BABYLON.Tools.LoadFile(rootUrl + sceneFilename, loadSceneFromData, progressCallBack, database);
             };
+
             if (sceneFilename.substr && sceneFilename.substr(0, 5) === "data:") {
                 // Direct load
                 loadSceneFromData(sceneFilename.substr(5));
                 return;
             }
+
             if (rootUrl.indexOf("file:") === -1) {
                 // Checking if a manifest file has been set for this scene and if offline mode has been requested
                 database = new BABYLON.Database(rootUrl + sceneFilename, manifestChecked);
-            }
-            else {
+            } else {
                 BABYLON.Tools.ReadFile(sceneFilename, loadSceneFromData, progressCallBack);
             }
         };
-        // Flags
         SceneLoader._ForceFullSceneLoadingForIncremental = false;
         SceneLoader._ShowLoadingScreen = true;
-        // Members
+
         SceneLoader._registeredPlugins = new Array();
         return SceneLoader;
     })();
     BABYLON.SceneLoader = SceneLoader;
     ;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.sceneLoader.js.map
+//# sourceMappingURL=babylon.sceneLoader.js.map

+ 29 - 13
Babylon/Materials/Textures/Procedurals/babylon.customProceduralTexture.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -13,6 +13,7 @@ var BABYLON;
             this._animate = true;
             this._time = 0;
             this._texturePath = texturePath;
+
             //Try to load json
             this.loadJson(texturePath);
             this.refreshRate = 1;
@@ -20,74 +21,86 @@ var BABYLON;
         CustomProceduralTexture.prototype.loadJson = function (jsonUrl) {
             var _this = this;
             var that = this;
+
             function noConfigFile() {
                 BABYLON.Tools.Log("No config file found in " + jsonUrl + " trying to use ShaderStore or DOM element");
-                try {
+                try  {
                     that.setFragment(that._texturePath);
-                }
-                catch (ex) {
+                } catch (ex) {
                     BABYLON.Tools.Error("No json or ShaderStore or DOM element found for CustomProceduralTexture");
                 }
             }
+
             var configFileUrl = jsonUrl + "/config.json";
             var xhr = new XMLHttpRequest();
+
             xhr.open("GET", configFileUrl, true);
             xhr.addEventListener("load", function () {
                 if (xhr.status === 200 || BABYLON.Tools.ValidateXHRData(xhr, 1)) {
-                    try {
+                    try  {
                         _this._config = JSON.parse(xhr.response);
+
                         _this.updateShaderUniforms();
                         _this.updateTextures();
                         _this.setFragment(_this._texturePath + "/custom");
+
                         _this._animate = _this._config.animate;
                         _this.refreshRate = _this._config.refreshrate;
-                    }
-                    catch (ex) {
+                    } catch (ex) {
                         noConfigFile();
                     }
-                }
-                else {
+                } else {
                     noConfigFile();
                 }
             }, false);
+
             xhr.addEventListener("error", function (event) {
                 noConfigFile();
             }, false);
-            try {
+
+            try  {
                 xhr.send();
-            }
-            catch (ex) {
+            } catch (ex) {
                 BABYLON.Tools.Error("CustomProceduralTexture: Error on XHR send request.");
             }
         };
+
         CustomProceduralTexture.prototype.isReady = function () {
             if (!_super.prototype.isReady.call(this)) {
                 return false;
             }
+
             for (var name in this._textures) {
                 var texture = this._textures[name];
+
                 if (!texture.isReady()) {
                     return false;
                 }
             }
+
             return true;
         };
+
         CustomProceduralTexture.prototype.render = function (useCameraPostProcess) {
             if (this._animate) {
                 this._time += this.getScene().getAnimationRatio() * 0.03;
                 this.updateShaderUniforms();
             }
+
             _super.prototype.render.call(this, useCameraPostProcess);
         };
+
         CustomProceduralTexture.prototype.updateTextures = function () {
             for (var i = 0; i < this._config.sampler2Ds.length; i++) {
                 this.setTexture(this._config.sampler2Ds[i].sample2Dname, new BABYLON.Texture(this._texturePath + "/" + this._config.sampler2Ds[i].textureRelativeUrl, this.getScene()));
             }
         };
+
         CustomProceduralTexture.prototype.updateShaderUniforms = function () {
             if (this._config) {
                 for (var j = 0; j < this._config.uniforms.length; j++) {
                     var uniform = this._config.uniforms[j];
+
                     switch (uniform.type) {
                         case "float":
                             this.setFloat(uniform.name, uniform.value);
@@ -107,8 +120,10 @@ var BABYLON;
                     }
                 }
             }
+
             this.setFloat("time", this._time);
         };
+
         Object.defineProperty(CustomProceduralTexture.prototype, "animate", {
             get: function () {
                 return this._animate;
@@ -119,8 +134,9 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         return CustomProceduralTexture;
     })(BABYLON.ProceduralTexture);
     BABYLON.CustomProceduralTexture = CustomProceduralTexture;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.customProceduralTexture.js.map
+//# sourceMappingURL=babylon.customProceduralTexture.js.map

+ 72 - 5
Babylon/Materials/Textures/Procedurals/babylon.proceduralTexture.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -9,7 +9,7 @@ var BABYLON;
     var ProceduralTexture = (function (_super) {
         __extends(ProceduralTexture, _super);
         function ProceduralTexture(name, size, fragment, scene, fallbackTexture, generateMipMaps) {
-            if (generateMipMaps === void 0) { generateMipMaps = true; }
+            if (typeof generateMipMaps === "undefined") { generateMipMaps = true; }
             _super.call(this, null, scene, !generateMipMaps);
             this._currentRefreshId = -1;
             this._refreshRate = 1;
@@ -26,29 +26,39 @@ var BABYLON;
             this._vectors3 = new Array();
             this._matrices = new Array();
             this._fallbackTextureUsed = false;
+
             scene._proceduralTextures.push(this);
+
             this.name = name;
             this.isRenderTarget = true;
             this._size = size;
             this._generateMipMaps = generateMipMaps;
+
             this.setFragment(fragment);
+
             this._fallbackTexture = fallbackTexture;
+
             this._texture = scene.getEngine().createRenderTargetTexture(size, generateMipMaps);
+
             // VBO
             var vertices = [];
             vertices.push(1, 1);
             vertices.push(-1, 1);
             vertices.push(-1, -1);
             vertices.push(1, -1);
+
             this._vertexBuffer = scene.getEngine().createVertexBuffer(vertices);
+
             // Indices
             var indices = [];
             indices.push(0);
             indices.push(1);
             indices.push(2);
+
             indices.push(0);
             indices.push(2);
             indices.push(3);
+
             this._indexBuffer = scene.getEngine().createIndexBuffer(indices);
         }
         ProceduralTexture.prototype.reset = function () {
@@ -58,38 +68,48 @@ var BABYLON;
             var engine = this.getScene().getEngine();
             engine._releaseEffect(this._effect);
         };
+
         ProceduralTexture.prototype.isReady = function () {
             var _this = this;
             var engine = this.getScene().getEngine();
             var shaders;
+
             if (!this._fragment) {
                 return false;
             }
+
             if (this._fallbackTextureUsed) {
                 return true;
             }
+
             if (this._fragment.fragmentElement !== undefined) {
                 shaders = { vertex: "procedural", fragmentElement: this._fragment.fragmentElement };
-            }
-            else {
+            } else {
                 shaders = { vertex: "procedural", fragment: this._fragment };
             }
+
             this._effect = engine.createEffect(shaders, ["position"], this._uniforms, this._samplers, "", null, null, function () {
                 _this.releaseInternalTexture();
+
                 if (_this._fallbackTexture) {
                     _this._texture = _this._fallbackTexture._texture;
                     _this._texture.references++;
                 }
+
                 _this._fallbackTextureUsed = true;
             });
+
             return this._effect.isReady();
         };
+
         ProceduralTexture.prototype.resetRefreshCounter = function () {
             this._currentRefreshId = -1;
         };
+
         ProceduralTexture.prototype.setFragment = function (fragment) {
             this._fragment = fragment;
         };
+
         Object.defineProperty(ProceduralTexture.prototype, "refreshRate", {
             get: function () {
                 return this._refreshRate;
@@ -102,134 +122,181 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         ProceduralTexture.prototype._shouldRender = function () {
             if (!this.isReady() || !this._texture) {
                 return false;
             }
+
             if (this._fallbackTextureUsed) {
                 return false;
             }
+
             if (this._currentRefreshId === -1) {
                 this._currentRefreshId = 1;
                 return true;
             }
+
             if (this.refreshRate === this._currentRefreshId) {
                 this._currentRefreshId = 1;
                 return true;
             }
+
             this._currentRefreshId++;
             return false;
         };
+
         ProceduralTexture.prototype.getRenderSize = function () {
             return this._size;
         };
+
         ProceduralTexture.prototype.resize = function (size, generateMipMaps) {
             if (this._fallbackTextureUsed) {
                 return;
             }
+
             this.releaseInternalTexture();
             this._texture = this.getScene().getEngine().createRenderTargetTexture(size, generateMipMaps);
         };
+
         ProceduralTexture.prototype._checkUniform = function (uniformName) {
             if (this._uniforms.indexOf(uniformName) === -1) {
                 this._uniforms.push(uniformName);
             }
         };
+
         ProceduralTexture.prototype.setTexture = function (name, texture) {
             if (this._samplers.indexOf(name) === -1) {
                 this._samplers.push(name);
             }
             this._textures[name] = texture;
+
             return this;
         };
+
         ProceduralTexture.prototype.setFloat = function (name, value) {
             this._checkUniform(name);
             this._floats[name] = value;
+
             return this;
         };
+
         ProceduralTexture.prototype.setFloats = function (name, value) {
             this._checkUniform(name);
             this._floatsArrays[name] = value;
+
             return this;
         };
+
         ProceduralTexture.prototype.setColor3 = function (name, value) {
             this._checkUniform(name);
             this._colors3[name] = value;
+
             return this;
         };
+
         ProceduralTexture.prototype.setColor4 = function (name, value) {
             this._checkUniform(name);
             this._colors4[name] = value;
+
             return this;
         };
+
         ProceduralTexture.prototype.setVector2 = function (name, value) {
             this._checkUniform(name);
             this._vectors2[name] = value;
+
             return this;
         };
+
         ProceduralTexture.prototype.setVector3 = function (name, value) {
             this._checkUniform(name);
             this._vectors3[name] = value;
+
             return this;
         };
+
         ProceduralTexture.prototype.setMatrix = function (name, value) {
             this._checkUniform(name);
             this._matrices[name] = value;
+
             return this;
         };
+
         ProceduralTexture.prototype.render = function (useCameraPostProcess) {
             var scene = this.getScene();
             var engine = scene.getEngine();
+
             engine.bindFramebuffer(this._texture);
+
             // Clear
             engine.clear(scene.clearColor, true, true);
+
             // Render
             engine.enableEffect(this._effect);
             engine.setState(false);
+
             for (var name in this._textures) {
                 this._effect.setTexture(name, this._textures[name]);
             }
+
             for (name in this._floats) {
                 this._effect.setFloat(name, this._floats[name]);
             }
+
             for (name in this._floatsArrays) {
                 this._effect.setArray(name, this._floatsArrays[name]);
             }
+
             for (name in this._colors3) {
                 this._effect.setColor3(name, this._colors3[name]);
             }
+
             for (name in this._colors4) {
                 var color = this._colors4[name];
                 this._effect.setFloat4(name, color.r, color.g, color.b, color.a);
             }
+
             for (name in this._vectors2) {
                 this._effect.setVector2(name, this._vectors2[name]);
             }
+
             for (name in this._vectors3) {
                 this._effect.setVector3(name, this._vectors3[name]);
             }
+
             for (name in this._matrices) {
                 this._effect.setMatrix(name, this._matrices[name]);
             }
+
             // VBOs
             engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, this._effect);
+
             // Draw order
             engine.draw(true, 0, 6);
+
             // Unbind
             engine.unBindFramebuffer(this._texture);
         };
+
         ProceduralTexture.prototype.clone = function () {
             var textureSize = this.getSize();
             var newTexture = new ProceduralTexture(this.name, textureSize.width, this._fragment, this.getScene(), this._fallbackTexture, this._generateMipMaps);
+
             // Base texture
             newTexture.hasAlpha = this.hasAlpha;
             newTexture.level = this.level;
+
             // RenderTarget Texture
             newTexture.coordinatesMode = this.coordinatesMode;
+
             return newTexture;
         };
+
         ProceduralTexture.prototype.dispose = function () {
             var index = this.getScene()._proceduralTextures.indexOf(this);
+
             if (index >= 0) {
                 this.getScene()._proceduralTextures.splice(index, 1);
             }
@@ -239,4 +306,4 @@ var BABYLON;
     })(BABYLON.Texture);
     BABYLON.ProceduralTexture = ProceduralTexture;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.proceduralTexture.js.map
+//# sourceMappingURL=babylon.proceduralTexture.js.map

+ 55 - 2
Babylon/Materials/Textures/Procedurals/babylon.standardProceduralTexture.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -19,6 +19,7 @@ var BABYLON;
             this.setFloat("ampScale", this._ampScale);
             this.setColor3("woodColor", this._woodColor);
         };
+
         Object.defineProperty(WoodProceduralTexture.prototype, "ampScale", {
             get: function () {
                 return this._ampScale;
@@ -30,6 +31,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(WoodProceduralTexture.prototype, "woodColor", {
             get: function () {
                 return this._woodColor;
@@ -41,9 +44,11 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         return WoodProceduralTexture;
     })(BABYLON.ProceduralTexture);
     BABYLON.WoodProceduralTexture = WoodProceduralTexture;
+
     var FireProceduralTexture = (function (_super) {
         __extends(FireProceduralTexture, _super);
         function FireProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
@@ -69,6 +74,7 @@ var BABYLON;
             this.setColor3("c6", this._fireColors[5]);
             this.setFloat("alphaThreshold", this._alphaThreshold);
         };
+
         FireProceduralTexture.prototype.render = function (useCameraPostProcess) {
             if (this._autoGenerateTime) {
                 this._time += this.getScene().getAnimationRatio() * 0.03;
@@ -76,6 +82,7 @@ var BABYLON;
             }
             _super.prototype.render.call(this, useCameraPostProcess);
         };
+
         Object.defineProperty(FireProceduralTexture, "PurpleFireColors", {
             get: function () {
                 return [
@@ -90,6 +97,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(FireProceduralTexture, "GreenFireColors", {
             get: function () {
                 return [
@@ -104,6 +112,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(FireProceduralTexture, "RedFireColors", {
             get: function () {
                 return [
@@ -118,6 +127,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(FireProceduralTexture, "BlueFireColors", {
             get: function () {
                 return [
@@ -132,6 +142,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(FireProceduralTexture.prototype, "fireColors", {
             get: function () {
                 return this._fireColors;
@@ -143,6 +154,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(FireProceduralTexture.prototype, "time", {
             get: function () {
                 return this._time;
@@ -154,6 +167,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(FireProceduralTexture.prototype, "speed", {
             get: function () {
                 return this._speed;
@@ -165,6 +180,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(FireProceduralTexture.prototype, "shift", {
             get: function () {
                 return this._shift;
@@ -176,6 +193,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(FireProceduralTexture.prototype, "alphaThreshold", {
             get: function () {
                 return this._alphaThreshold;
@@ -187,9 +206,11 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         return FireProceduralTexture;
     })(BABYLON.ProceduralTexture);
     BABYLON.FireProceduralTexture = FireProceduralTexture;
+
     var CloudProceduralTexture = (function (_super) {
         __extends(CloudProceduralTexture, _super);
         function CloudProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
@@ -203,6 +224,7 @@ var BABYLON;
             this.setColor3("skyColor", this._skyColor);
             this.setColor3("cloudColor", this._cloudColor);
         };
+
         Object.defineProperty(CloudProceduralTexture.prototype, "skyColor", {
             get: function () {
                 return this._skyColor;
@@ -214,6 +236,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(CloudProceduralTexture.prototype, "cloudColor", {
             get: function () {
                 return this._cloudColor;
@@ -225,9 +249,11 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         return CloudProceduralTexture;
     })(BABYLON.ProceduralTexture);
     BABYLON.CloudProceduralTexture = CloudProceduralTexture;
+
     var GrassProceduralTexture = (function (_super) {
         __extends(GrassProceduralTexture, _super);
         function GrassProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
@@ -236,11 +262,13 @@ var BABYLON;
             this._herb2 = new BABYLON.Color3(0.36, 0.49, 0.09);
             this._herb3 = new BABYLON.Color3(0.51, 0.6, 0.28);
             this._groundColor = new BABYLON.Color3(1, 1, 1);
+
             this._grassColors = [
                 new BABYLON.Color3(0.29, 0.38, 0.02),
                 new BABYLON.Color3(0.36, 0.49, 0.09),
                 new BABYLON.Color3(0.51, 0.6, 0.28)
             ];
+
             this.updateShaderUniforms();
             this.refreshRate = 0;
         }
@@ -250,6 +278,7 @@ var BABYLON;
             this.setColor3("herb3Color", this._grassColors[2]);
             this.setColor3("groundColor", this._groundColor);
         };
+
         Object.defineProperty(GrassProceduralTexture.prototype, "grassColors", {
             get: function () {
                 return this._grassColors;
@@ -261,6 +290,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(GrassProceduralTexture.prototype, "groundColor", {
             get: function () {
                 return this._groundColor;
@@ -272,9 +303,11 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         return GrassProceduralTexture;
     })(BABYLON.ProceduralTexture);
     BABYLON.GrassProceduralTexture = GrassProceduralTexture;
+
     var RoadProceduralTexture = (function (_super) {
         __extends(RoadProceduralTexture, _super);
         function RoadProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
@@ -286,6 +319,7 @@ var BABYLON;
         RoadProceduralTexture.prototype.updateShaderUniforms = function () {
             this.setColor3("roadColor", this._roadColor);
         };
+
         Object.defineProperty(RoadProceduralTexture.prototype, "roadColor", {
             get: function () {
                 return this._roadColor;
@@ -297,9 +331,11 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         return RoadProceduralTexture;
     })(BABYLON.ProceduralTexture);
     BABYLON.RoadProceduralTexture = RoadProceduralTexture;
+
     var BrickProceduralTexture = (function (_super) {
         __extends(BrickProceduralTexture, _super);
         function BrickProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
@@ -317,6 +353,7 @@ var BABYLON;
             this.setColor3("brickColor", this._brickColor);
             this.setColor3("jointColor", this._jointColor);
         };
+
         Object.defineProperty(BrickProceduralTexture.prototype, "numberOfBricksHeight", {
             get: function () {
                 return this._numberOfBricksHeight;
@@ -324,6 +361,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(BrickProceduralTexture.prototype, "cloudColor", {
             set: function (value) {
                 this._numberOfBricksHeight = value;
@@ -332,6 +370,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(BrickProceduralTexture.prototype, "numberOfBricksWidth", {
             get: function () {
                 return this._numberOfBricksWidth;
@@ -343,6 +382,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(BrickProceduralTexture.prototype, "jointColor", {
             get: function () {
                 return this._jointColor;
@@ -354,6 +395,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(BrickProceduralTexture.prototype, "brickColor", {
             get: function () {
                 return this._brickColor;
@@ -365,9 +408,11 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         return BrickProceduralTexture;
     })(BABYLON.ProceduralTexture);
     BABYLON.BrickProceduralTexture = BrickProceduralTexture;
+
     var MarbleProceduralTexture = (function (_super) {
         __extends(MarbleProceduralTexture, _super);
         function MarbleProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
@@ -387,6 +432,7 @@ var BABYLON;
             this.setColor3("marbleColor", this._marbleColor);
             this.setColor3("jointColor", this._jointColor);
         };
+
         Object.defineProperty(MarbleProceduralTexture.prototype, "numberOfTilesHeight", {
             get: function () {
                 return this._numberOfTilesHeight;
@@ -398,6 +444,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(MarbleProceduralTexture.prototype, "numberOfTilesWidth", {
             get: function () {
                 return this._numberOfTilesWidth;
@@ -409,6 +457,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(MarbleProceduralTexture.prototype, "jointColor", {
             get: function () {
                 return this._jointColor;
@@ -420,6 +470,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(MarbleProceduralTexture.prototype, "marbleColor", {
             get: function () {
                 return this._marbleColor;
@@ -431,8 +483,9 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         return MarbleProceduralTexture;
     })(BABYLON.ProceduralTexture);
     BABYLON.MarbleProceduralTexture = MarbleProceduralTexture;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.standardProceduralTexture.js.map
+//# sourceMappingURL=babylon.standardProceduralTexture.js.map

+ 32 - 2
Babylon/Materials/Textures/babylon.baseTexture.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var BaseTexture = (function () {
         function BaseTexture(scene) {
@@ -20,43 +20,57 @@ var BABYLON;
         BaseTexture.prototype.getScene = function () {
             return this._scene;
         };
+
         BaseTexture.prototype.getTextureMatrix = function () {
             return null;
         };
+
         BaseTexture.prototype.getReflectionTextureMatrix = function () {
             return null;
         };
+
         BaseTexture.prototype.getInternalTexture = function () {
             return this._texture;
         };
+
         BaseTexture.prototype.isReady = function () {
             if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
                 return true;
             }
+
             if (this._texture) {
                 return this._texture.isReady;
             }
+
             return false;
         };
+
         BaseTexture.prototype.getSize = function () {
             if (this._texture._width) {
                 return { width: this._texture._width, height: this._texture._height };
             }
+
             if (this._texture._size) {
                 return { width: this._texture._size, height: this._texture._size };
             }
+
             return { width: 0, height: 0 };
         };
+
         BaseTexture.prototype.getBaseSize = function () {
             if (!this.isReady())
                 return { width: 0, height: 0 };
+
             if (this._texture._size) {
                 return { width: this._texture._size, height: this._texture._size };
             }
+
             return { width: this._texture._baseWidth, height: this._texture._baseHeight };
         };
+
         BaseTexture.prototype.scale = function (ratio) {
         };
+
         Object.defineProperty(BaseTexture.prototype, "canRescale", {
             get: function () {
                 return false;
@@ -64,20 +78,24 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         BaseTexture.prototype._removeFromCache = function (url, noMipmap) {
             var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
             for (var index = 0; index < texturesCache.length; index++) {
                 var texturesCacheEntry = texturesCache[index];
+
                 if (texturesCacheEntry.url === url && texturesCacheEntry.noMipmap === noMipmap) {
                     texturesCache.splice(index, 1);
                     return;
                 }
             }
         };
+
         BaseTexture.prototype._getFromCache = function (url, noMipmap, sampling) {
             var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
             for (var index = 0; index < texturesCache.length; index++) {
                 var texturesCacheEntry = texturesCache[index];
+
                 if (texturesCacheEntry.url === url && texturesCacheEntry.noMipmap === noMipmap) {
                     if (!sampling || sampling === texturesCacheEntry.samplingMode) {
                         texturesCacheEntry.references++;
@@ -85,37 +103,49 @@ var BABYLON;
                     }
                 }
             }
+
             return null;
         };
+
         BaseTexture.prototype.delayLoad = function () {
         };
+
         BaseTexture.prototype.releaseInternalTexture = function () {
             if (!this._texture) {
                 return;
             }
             var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
             this._texture.references--;
+
             // Final reference ?
             if (this._texture.references === 0) {
                 var index = texturesCache.indexOf(this._texture);
                 texturesCache.splice(index, 1);
+
                 this._scene.getEngine()._releaseTexture(this._texture);
+
                 delete this._texture;
             }
         };
+
         BaseTexture.prototype.clone = function () {
             return null;
         };
+
         BaseTexture.prototype.dispose = function () {
             // Remove from scene
             var index = this._scene.textures.indexOf(this);
+
             if (index >= 0) {
                 this._scene.textures.splice(index, 1);
             }
+
             if (this._texture === undefined) {
                 return;
             }
+
             this.releaseInternalTexture();
+
             // Callback
             if (this.onDispose) {
                 this.onDispose();
@@ -125,4 +155,4 @@ var BABYLON;
     })();
     BABYLON.BaseTexture = BaseTexture;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.baseTexture.js.map
+//# sourceMappingURL=babylon.baseTexture.js.map

+ 16 - 4
Babylon/Materials/Textures/babylon.cubeTexture.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -11,47 +11,59 @@ var BABYLON;
         function CubeTexture(rootUrl, scene, extensions, noMipmap) {
             _super.call(this, scene);
             this.coordinatesMode = BABYLON.Texture.CUBIC_MODE;
+
             this.name = rootUrl;
             this.url = rootUrl;
             this._noMipmap = noMipmap;
             this.hasAlpha = false;
+
             this._texture = this._getFromCache(rootUrl, noMipmap);
+
             if (!extensions) {
                 extensions = ["_px.jpg", "_py.jpg", "_pz.jpg", "_nx.jpg", "_ny.jpg", "_nz.jpg"];
             }
+
             this._extensions = extensions;
+
             if (!this._texture) {
                 if (!scene.useDelayedTextureLoading) {
                     this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, extensions, noMipmap);
-                }
-                else {
+                } else {
                     this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
                 }
             }
+
             this.isCube = true;
+
             this._textureMatrix = BABYLON.Matrix.Identity();
         }
         CubeTexture.prototype.clone = function () {
             var newTexture = new BABYLON.CubeTexture(this.url, this.getScene(), this._extensions, this._noMipmap);
+
             // Base texture
             newTexture.level = this.level;
             newTexture.wrapU = this.wrapU;
             newTexture.wrapV = this.wrapV;
             newTexture.coordinatesIndex = this.coordinatesIndex;
             newTexture.coordinatesMode = this.coordinatesMode;
+
             return newTexture;
         };
+
         // Methods
         CubeTexture.prototype.delayLoad = function () {
             if (this.delayLoadState != BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
                 return;
             }
+
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
             this._texture = this._getFromCache(this.url, this._noMipmap);
+
             if (!this._texture) {
                 this._texture = this.getScene().getEngine().createCubeTexture(this.url, this.getScene(), this._extensions);
             }
         };
+
         CubeTexture.prototype.getReflectionTextureMatrix = function () {
             return this._textureMatrix;
         };
@@ -59,4 +71,4 @@ var BABYLON;
     })(BABYLON.BaseTexture);
     BABYLON.CubeTexture = CubeTexture;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.cubeTexture.js.map
+//# sourceMappingURL=babylon.cubeTexture.js.map

+ 29 - 8
Babylon/Materials/Textures/babylon.dynamicTexture.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -9,26 +9,31 @@ var BABYLON;
     var DynamicTexture = (function (_super) {
         __extends(DynamicTexture, _super);
         function DynamicTexture(name, options, scene, generateMipMaps, samplingMode) {
-            if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
+            if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             _super.call(this, null, scene, !generateMipMaps);
+
             this.name = name;
+
             this.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
+
             this._generateMipMaps = generateMipMaps;
+
             if (options.getContext) {
                 this._canvas = options;
                 this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode);
-            }
-            else {
+            } else {
                 this._canvas = document.createElement("canvas");
+
                 if (options.width) {
                     this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode);
-                }
-                else {
+                } else {
                     this._texture = scene.getEngine().createDynamicTexture(options, options, generateMipMaps, samplingMode);
                 }
             }
+
             var textureSize = this.getSize();
+
             this._canvas.width = textureSize.width;
             this._canvas.height = textureSize.height;
             this._context = this._canvas.getContext("2d");
@@ -40,56 +45,72 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         DynamicTexture.prototype.scale = function (ratio) {
             var textureSize = this.getSize();
+
             textureSize.width *= ratio;
             textureSize.height *= ratio;
+
             this._canvas.width = textureSize.width;
             this._canvas.height = textureSize.height;
+
             this.releaseInternalTexture();
+
             this._texture = this.getScene().getEngine().createDynamicTexture(textureSize.width, textureSize.height, this._generateMipMaps, this._samplingMode);
         };
+
         DynamicTexture.prototype.getContext = function () {
             return this._context;
         };
+
         DynamicTexture.prototype.clear = function () {
             var size = this.getSize();
             this._context.fillRect(0, 0, size.width, size.height);
         };
+
         DynamicTexture.prototype.update = function (invertY) {
             this.getScene().getEngine().updateDynamicTexture(this._texture, this._canvas, invertY === undefined ? true : invertY);
         };
+
         DynamicTexture.prototype.drawText = function (text, x, y, font, color, clearColor, invertY, update) {
-            if (update === void 0) { update = true; }
+            if (typeof update === "undefined") { update = true; }
             var size = this.getSize();
             if (clearColor) {
                 this._context.fillStyle = clearColor;
                 this._context.fillRect(0, 0, size.width, size.height);
             }
+
             this._context.font = font;
             if (x === null) {
                 var textSize = this._context.measureText(text);
                 x = (size.width - textSize.width) / 2;
             }
+
             this._context.fillStyle = color;
             this._context.fillText(text, x, y);
+
             if (update) {
                 this.update(invertY);
             }
         };
+
         DynamicTexture.prototype.clone = function () {
             var textureSize = this.getSize();
             var newTexture = new DynamicTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
+
             // Base texture
             newTexture.hasAlpha = this.hasAlpha;
             newTexture.level = this.level;
+
             // Dynamic Texture
             newTexture.wrapU = this.wrapU;
             newTexture.wrapV = this.wrapV;
+
             return newTexture;
         };
         return DynamicTexture;
     })(BABYLON.Texture);
     BABYLON.DynamicTexture = DynamicTexture;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.dynamicTexture.js.map
+//# sourceMappingURL=babylon.dynamicTexture.js.map

+ 12 - 2
Babylon/Materials/Textures/babylon.mirrorTexture.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -14,33 +14,43 @@ var BABYLON;
             this.mirrorPlane = new BABYLON.Plane(0, 1, 0, 1);
             this._transformMatrix = BABYLON.Matrix.Zero();
             this._mirrorMatrix = BABYLON.Matrix.Zero();
+
             this.onBeforeRender = function () {
                 BABYLON.Matrix.ReflectionToRef(_this.mirrorPlane, _this._mirrorMatrix);
                 _this._savedViewMatrix = scene.getViewMatrix();
+
                 _this._mirrorMatrix.multiplyToRef(_this._savedViewMatrix, _this._transformMatrix);
+
                 scene.setTransformMatrix(_this._transformMatrix, scene.getProjectionMatrix());
+
                 scene.clipPlane = _this.mirrorPlane;
+
                 scene.getEngine().cullBackFaces = false;
             };
+
             this.onAfterRender = function () {
                 scene.setTransformMatrix(_this._savedViewMatrix, scene.getProjectionMatrix());
                 scene.getEngine().cullBackFaces = true;
+
                 delete scene.clipPlane;
             };
         }
         MirrorTexture.prototype.clone = function () {
             var textureSize = this.getSize();
             var newTexture = new BABYLON.MirrorTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
+
             // Base texture
             newTexture.hasAlpha = this.hasAlpha;
             newTexture.level = this.level;
+
             // Mirror Texture
             newTexture.mirrorPlane = this.mirrorPlane.clone();
             newTexture.renderList = this.renderList.slice(0);
+
             return newTexture;
         };
         return MirrorTexture;
     })(BABYLON.RenderTargetTexture);
     BABYLON.MirrorTexture = MirrorTexture;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.mirrorTexture.js.map
+//# sourceMappingURL=babylon.mirrorTexture.js.map

+ 26 - 20
Babylon/Materials/Textures/babylon.rawTexture.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -9,47 +9,53 @@ var BABYLON;
     var RawTexture = (function (_super) {
         __extends(RawTexture, _super);
         function RawTexture(data, width, height, format, scene, generateMipMaps, invertY, samplingMode) {
-            if (generateMipMaps === void 0) { generateMipMaps = true; }
-            if (invertY === void 0) { invertY = false; }
-            if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
+            if (typeof generateMipMaps === "undefined") { generateMipMaps = true; }
+            if (typeof invertY === "undefined") { invertY = false; }
+            if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             _super.call(this, null, scene, !generateMipMaps, invertY);
+
             this._texture = scene.getEngine().createRawTexture(data, width, height, format, generateMipMaps, invertY, samplingMode);
+
             this.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
         }
         // Statics
         RawTexture.CreateLuminanceTexture = function (data, width, height, scene, generateMipMaps, invertY, samplingMode) {
-            if (generateMipMaps === void 0) { generateMipMaps = true; }
-            if (invertY === void 0) { invertY = false; }
-            if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
+            if (typeof generateMipMaps === "undefined") { generateMipMaps = true; }
+            if (typeof invertY === "undefined") { invertY = false; }
+            if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             return new RawTexture(data, width, height, BABYLON.Engine.TEXTUREFORMAT_LUMINANCE, scene, generateMipMaps, invertY, samplingMode);
         };
+
         RawTexture.CreateLuminanceAlphaTexture = function (data, width, height, scene, generateMipMaps, invertY, samplingMode) {
-            if (generateMipMaps === void 0) { generateMipMaps = true; }
-            if (invertY === void 0) { invertY = false; }
-            if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
+            if (typeof generateMipMaps === "undefined") { generateMipMaps = true; }
+            if (typeof invertY === "undefined") { invertY = false; }
+            if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             return new RawTexture(data, width, height, BABYLON.Engine.TEXTUREFORMAT_LUMINANCE_ALPHA, scene, generateMipMaps, invertY, samplingMode);
         };
+
         RawTexture.CreateAlphaTexture = function (data, width, height, scene, generateMipMaps, invertY, samplingMode) {
-            if (generateMipMaps === void 0) { generateMipMaps = true; }
-            if (invertY === void 0) { invertY = false; }
-            if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
+            if (typeof generateMipMaps === "undefined") { generateMipMaps = true; }
+            if (typeof invertY === "undefined") { invertY = false; }
+            if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             return new RawTexture(data, width, height, BABYLON.Engine.TEXTUREFORMAT_ALPHA, scene, generateMipMaps, invertY, samplingMode);
         };
+
         RawTexture.CreateRGBTexture = function (data, width, height, scene, generateMipMaps, invertY, samplingMode) {
-            if (generateMipMaps === void 0) { generateMipMaps = true; }
-            if (invertY === void 0) { invertY = false; }
-            if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
+            if (typeof generateMipMaps === "undefined") { generateMipMaps = true; }
+            if (typeof invertY === "undefined") { invertY = false; }
+            if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             return new RawTexture(data, width, height, BABYLON.Engine.TEXTUREFORMAT_RGB, scene, generateMipMaps, invertY, samplingMode);
         };
+
         RawTexture.CreateRGBATexture = function (data, width, height, scene, generateMipMaps, invertY, samplingMode) {
-            if (generateMipMaps === void 0) { generateMipMaps = true; }
-            if (invertY === void 0) { invertY = false; }
-            if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
+            if (typeof generateMipMaps === "undefined") { generateMipMaps = true; }
+            if (typeof invertY === "undefined") { invertY = false; }
+            if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             return new RawTexture(data, width, height, BABYLON.Engine.TEXTUREFORMAT_RGBA, scene, generateMipMaps, invertY, samplingMode);
         };
         return RawTexture;
     })(BABYLON.Texture);
     BABYLON.RawTexture = RawTexture;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.rawTexture.js.map
+//# sourceMappingURL=babylon.rawTexture.js.map

+ 39 - 3
Babylon/Materials/Textures/babylon.renderTargetTexture.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -9,7 +9,7 @@ var BABYLON;
     var RenderTargetTexture = (function (_super) {
         __extends(RenderTargetTexture, _super);
         function RenderTargetTexture(name, size, scene, generateMipMaps, doNotChangeAspectRatio) {
-            if (doNotChangeAspectRatio === void 0) { doNotChangeAspectRatio = true; }
+            if (typeof doNotChangeAspectRatio === "undefined") { doNotChangeAspectRatio = true; }
             _super.call(this, null, scene, !generateMipMaps);
             this.renderList = new Array();
             this.renderParticles = true;
@@ -17,18 +17,22 @@ var BABYLON;
             this.coordinatesMode = BABYLON.Texture.PROJECTION_MODE;
             this._currentRefreshId = -1;
             this._refreshRate = 1;
+
             this.name = name;
             this.isRenderTarget = true;
             this._size = size;
             this._generateMipMaps = generateMipMaps;
             this._doNotChangeAspectRatio = doNotChangeAspectRatio;
+
             this._texture = scene.getEngine().createRenderTargetTexture(size, generateMipMaps);
+
             // Rendering groups
             this._renderingManager = new BABYLON.RenderingManager(scene);
         }
         RenderTargetTexture.prototype.resetRefreshCounter = function () {
             this._currentRefreshId = -1;
         };
+
         Object.defineProperty(RenderTargetTexture.prototype, "refreshRate", {
             get: function () {
                 return this._refreshRate;
@@ -41,27 +45,34 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         RenderTargetTexture.prototype._shouldRender = function () {
             if (this._currentRefreshId === -1) {
                 this._currentRefreshId = 1;
                 return true;
             }
+
             if (this.refreshRate == this._currentRefreshId) {
                 this._currentRefreshId = 1;
                 return true;
             }
+
             this._currentRefreshId++;
             return false;
         };
+
         RenderTargetTexture.prototype.isReady = function () {
             if (!this.getScene().renderTargetsEnabled) {
                 return false;
             }
             return _super.prototype.isReady.call(this);
         };
+
         RenderTargetTexture.prototype.getRenderSize = function () {
             return this._size;
         };
+
         Object.defineProperty(RenderTargetTexture.prototype, "canRescale", {
             get: function () {
                 return true;
@@ -69,45 +80,59 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         RenderTargetTexture.prototype.scale = function (ratio) {
             var newSize = this._size * ratio;
+
             this.resize(newSize, this._generateMipMaps);
         };
+
         RenderTargetTexture.prototype.resize = function (size, generateMipMaps) {
             this.releaseInternalTexture();
             this._texture = this.getScene().getEngine().createRenderTargetTexture(size, generateMipMaps);
         };
+
         RenderTargetTexture.prototype.render = function (useCameraPostProcess) {
             var scene = this.getScene();
             var engine = scene.getEngine();
+
             if (this._waitingRenderList) {
                 this.renderList = [];
                 for (var index = 0; index < this._waitingRenderList.length; index++) {
                     var id = this._waitingRenderList[index];
                     this.renderList.push(scene.getMeshByID(id));
                 }
+
                 delete this._waitingRenderList;
             }
+
             if (!this.renderList) {
                 return;
             }
+
             // Bind
             if (!useCameraPostProcess || !scene.postProcessManager._prepareFrame(this._texture)) {
                 engine.bindFramebuffer(this._texture);
             }
+
             // Clear
             engine.clear(scene.clearColor, true, true);
+
             this._renderingManager.reset();
+
             for (var meshIndex = 0; meshIndex < this.renderList.length; meshIndex++) {
                 var mesh = this.renderList[meshIndex];
+
                 if (mesh) {
                     if (!mesh.isReady() || (mesh.material && !mesh.material.isReady())) {
                         // Reset _currentRefreshId
                         this.resetRefreshCounter();
                         continue;
                     }
+
                     if (mesh.isEnabled() && mesh.isVisible && mesh.subMeshes && ((mesh.layerMask & scene.activeCamera.layerMask) != 0)) {
                         mesh._activate(scene.getRenderId());
+
                         for (var subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {
                             var subMesh = mesh.subMeshes[subIndex];
                             scene._activeVertices += subMesh.indexCount;
@@ -116,39 +141,50 @@ var BABYLON;
                     }
                 }
             }
+
             if (!this._doNotChangeAspectRatio) {
                 scene.updateTransformMatrix(true);
             }
+
             if (this.onBeforeRender) {
                 this.onBeforeRender();
             }
+
             // Render
             this._renderingManager.render(this.customRenderFunction, this.renderList, this.renderParticles, this.renderSprites);
+
             if (useCameraPostProcess) {
                 scene.postProcessManager._finalizeFrame(false, this._texture);
             }
+
             if (this.onAfterRender) {
                 this.onAfterRender();
             }
+
             // Unbind
             engine.unBindFramebuffer(this._texture);
+
             if (!this._doNotChangeAspectRatio) {
                 scene.updateTransformMatrix(true);
             }
         };
+
         RenderTargetTexture.prototype.clone = function () {
             var textureSize = this.getSize();
             var newTexture = new BABYLON.RenderTargetTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
+
             // Base texture
             newTexture.hasAlpha = this.hasAlpha;
             newTexture.level = this.level;
+
             // RenderTarget Texture
             newTexture.coordinatesMode = this.coordinatesMode;
             newTexture.renderList = this.renderList.slice(0);
+
             return newTexture;
         };
         return RenderTargetTexture;
     })(BABYLON.Texture);
     BABYLON.RenderTargetTexture = RenderTargetTexture;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.renderTargetTexture.js.map
+//# sourceMappingURL=babylon.renderTargetTexture.js.map

+ 42 - 13
Babylon/Materials/Textures/babylon.texture.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -9,11 +9,11 @@ var BABYLON;
     var Texture = (function (_super) {
         __extends(Texture, _super);
         function Texture(url, scene, noMipmap, invertY, samplingMode, onLoad, onError, buffer, deleteBuffer) {
-            if (samplingMode === void 0) { samplingMode = Texture.TRILINEAR_SAMPLINGMODE; }
-            if (onLoad === void 0) { onLoad = null; }
-            if (onError === void 0) { onError = null; }
-            if (buffer === void 0) { buffer = null; }
-            if (deleteBuffer === void 0) { deleteBuffer = false; }
+            if (typeof samplingMode === "undefined") { samplingMode = Texture.TRILINEAR_SAMPLINGMODE; }
+            if (typeof onLoad === "undefined") { onLoad = null; }
+            if (typeof onError === "undefined") { onError = null; }
+            if (typeof buffer === "undefined") { buffer = null; }
+            if (typeof deleteBuffer === "undefined") { deleteBuffer = false; }
             _super.call(this, scene);
             this.uOffset = 0;
             this.vOffset = 0;
@@ -22,6 +22,7 @@ var BABYLON;
             this.uAng = 0;
             this.vAng = 0;
             this.wAng = 0;
+
             this.name = url;
             this.url = url;
             this._noMipmap = noMipmap;
@@ -29,18 +30,20 @@ var BABYLON;
             this._samplingMode = samplingMode;
             this._buffer = buffer;
             this._deleteBuffer = deleteBuffer;
+
             if (!url) {
                 return;
             }
+
             this._texture = this._getFromCache(url, noMipmap, samplingMode);
+
             if (!this._texture) {
                 if (!scene.useDelayedTextureLoading) {
                     this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene, this._samplingMode, onLoad, onError, this._buffer);
                     if (deleteBuffer) {
                         delete this._buffer;
                     }
-                }
-                else {
+                } else {
                     this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
                 }
             }
@@ -49,8 +52,10 @@ var BABYLON;
             if (this.delayLoadState != BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
                 return;
             }
+
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
             this._texture = this._getFromCache(this.url, this._noMipmap, this._samplingMode);
+
             if (!this._texture) {
                 this._texture = this.getScene().getEngine().createTexture(this.url, this._noMipmap, this._invertY, this.getScene(), this._samplingMode, null, null, this._buffer);
                 if (this._deleteBuffer) {
@@ -58,21 +63,27 @@ var BABYLON;
                 }
             }
         };
+
         Texture.prototype._prepareRowForTextureGeneration = function (x, y, z, t) {
             x -= this.uOffset + 0.5;
             y -= this.vOffset + 0.5;
             z -= 0.5;
+
             BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(x, y, z, this._rowGenerationMatrix, t);
+
             t.x *= this.uScale;
             t.y *= this.vScale;
+
             t.x += 0.5;
             t.y += 0.5;
             t.z += 0.5;
         };
+
         Texture.prototype.getTextureMatrix = function () {
             if (this.uOffset === this._cachedUOffset && this.vOffset === this._cachedVOffset && this.uScale === this._cachedUScale && this.vScale === this._cachedVScale && this.uAng === this._cachedUAng && this.vAng === this._cachedVAng && this.wAng === this._cachedWAng) {
                 return this._cachedTextureMatrix;
             }
+
             this._cachedUOffset = this.uOffset;
             this._cachedVOffset = this.vOffset;
             this._cachedUScale = this.uScale;
@@ -80,6 +91,7 @@ var BABYLON;
             this._cachedUAng = this.uAng;
             this._cachedVAng = this.vAng;
             this._cachedWAng = this.wAng;
+
             if (!this._cachedTextureMatrix) {
                 this._cachedTextureMatrix = BABYLON.Matrix.Zero();
                 this._rowGenerationMatrix = new BABYLON.Matrix();
@@ -87,12 +99,16 @@ var BABYLON;
                 this._t1 = BABYLON.Vector3.Zero();
                 this._t2 = BABYLON.Vector3.Zero();
             }
+
             BABYLON.Matrix.RotationYawPitchRollToRef(this.vAng, this.uAng, this.wAng, this._rowGenerationMatrix);
+
             this._prepareRowForTextureGeneration(0, 0, 0, this._t0);
             this._prepareRowForTextureGeneration(1.0, 0, 0, this._t1);
             this._prepareRowForTextureGeneration(0, 1.0, 0, this._t2);
+
             this._t1.subtractInPlace(this._t0);
             this._t2.subtractInPlace(this._t0);
+
             BABYLON.Matrix.IdentityToRef(this._cachedTextureMatrix);
             this._cachedTextureMatrix.m[0] = this._t1.x;
             this._cachedTextureMatrix.m[1] = this._t1.y;
@@ -103,17 +119,22 @@ var BABYLON;
             this._cachedTextureMatrix.m[8] = this._t0.x;
             this._cachedTextureMatrix.m[9] = this._t0.y;
             this._cachedTextureMatrix.m[10] = this._t0.z;
+
             return this._cachedTextureMatrix;
         };
+
         Texture.prototype.getReflectionTextureMatrix = function () {
             if (this.uOffset === this._cachedUOffset && this.vOffset === this._cachedVOffset && this.uScale === this._cachedUScale && this.vScale === this._cachedVScale && this.coordinatesMode === this._cachedCoordinatesMode) {
                 return this._cachedTextureMatrix;
             }
+
             if (!this._cachedTextureMatrix) {
                 this._cachedTextureMatrix = BABYLON.Matrix.Zero();
                 this._projectionModeMatrix = BABYLON.Matrix.Zero();
             }
+
             this._cachedCoordinatesMode = this.coordinatesMode;
+
             switch (this.coordinatesMode) {
                 case BABYLON.Texture.SPHERICAL_MODE:
                     BABYLON.Matrix.IdentityToRef(this._cachedTextureMatrix);
@@ -131,6 +152,7 @@ var BABYLON;
                     break;
                 case BABYLON.Texture.PROJECTION_MODE:
                     BABYLON.Matrix.IdentityToRef(this._projectionModeMatrix);
+
                     this._projectionModeMatrix.m[0] = 0.5;
                     this._projectionModeMatrix.m[5] = -0.5;
                     this._projectionModeMatrix.m[10] = 0.0;
@@ -138,6 +160,7 @@ var BABYLON;
                     this._projectionModeMatrix.m[13] = 0.5;
                     this._projectionModeMatrix.m[14] = 1.0;
                     this._projectionModeMatrix.m[15] = 1.0;
+
                     this.getScene().getProjectionMatrix().multiplyToRef(this._projectionModeMatrix, this._cachedTextureMatrix);
                     break;
                 default:
@@ -146,8 +169,10 @@ var BABYLON;
             }
             return this._cachedTextureMatrix;
         };
+
         Texture.prototype.clone = function () {
             var newTexture = new BABYLON.Texture(this._texture.url, this.getScene(), this._noMipmap, this._invertY);
+
             // Base texture
             newTexture.hasAlpha = this.hasAlpha;
             newTexture.level = this.level;
@@ -155,6 +180,7 @@ var BABYLON;
             newTexture.wrapV = this.wrapV;
             newTexture.coordinatesIndex = this.coordinatesIndex;
             newTexture.coordinatesMode = this.coordinatesMode;
+
             // Texture
             newTexture.uOffset = this.uOffset;
             newTexture.vOffset = this.vOffset;
@@ -163,25 +189,28 @@ var BABYLON;
             newTexture.uAng = this.uAng;
             newTexture.vAng = this.vAng;
             newTexture.wAng = this.wAng;
+
             return newTexture;
         };
+
         // Statics
         Texture.CreateFromBase64String = function (data, name, scene, noMipmap, invertY, samplingMode, onLoad, onError) {
-            if (samplingMode === void 0) { samplingMode = Texture.TRILINEAR_SAMPLINGMODE; }
-            if (onLoad === void 0) { onLoad = null; }
-            if (onError === void 0) { onError = null; }
+            if (typeof samplingMode === "undefined") { samplingMode = Texture.TRILINEAR_SAMPLINGMODE; }
+            if (typeof onLoad === "undefined") { onLoad = null; }
+            if (typeof onError === "undefined") { onError = null; }
             return new Texture("data:" + name, scene, noMipmap, invertY, samplingMode, onLoad, onError, data);
         };
-        // Constants
         Texture.NEAREST_SAMPLINGMODE = 1;
         Texture.BILINEAR_SAMPLINGMODE = 2;
         Texture.TRILINEAR_SAMPLINGMODE = 3;
+
         Texture.EXPLICIT_MODE = 0;
         Texture.SPHERICAL_MODE = 1;
         Texture.PLANAR_MODE = 2;
         Texture.CUBIC_MODE = 3;
         Texture.PROJECTION_MODE = 4;
         Texture.SKYBOX_MODE = 5;
+
         Texture.CLAMP_ADDRESSMODE = 0;
         Texture.WRAP_ADDRESSMODE = 1;
         Texture.MIRROR_ADDRESSMODE = 2;
@@ -189,4 +218,4 @@ var BABYLON;
     })(BABYLON.BaseTexture);
     BABYLON.Texture = Texture;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.texture.js.map
+//# sourceMappingURL=babylon.texture.js.map

+ 14 - 3
Babylon/Materials/Textures/babylon.videoTexture.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -9,32 +9,40 @@ var BABYLON;
     var VideoTexture = (function (_super) {
         __extends(VideoTexture, _super);
         function VideoTexture(name, urls, size, scene, generateMipMaps, invertY, samplingMode) {
+            if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             var _this = this;
-            if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             _super.call(this, null, scene, !generateMipMaps, invertY);
             this._autoLaunch = true;
+
             this.name = name;
+
             this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
             this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
+
             var requiredWidth = size.width || size;
             var requiredHeight = size.height || size;
+
             this._texture = scene.getEngine().createDynamicTexture(requiredWidth, requiredHeight, generateMipMaps, samplingMode);
             var textureSize = this.getSize();
+
             this.video = document.createElement("video");
             this.video.width = textureSize.width;
             this.video.height = textureSize.height;
             this.video.autoplay = false;
             this.video.loop = true;
+
             this.video.addEventListener("canplaythrough", function () {
                 if (_this._texture) {
                     _this._texture.isReady = true;
                 }
             });
+
             urls.forEach(function (url) {
                 var source = document.createElement("source");
                 source.src = url;
                 _this.video.appendChild(source);
             });
+
             this._lastUpdate = BABYLON.Tools.Now;
         }
         VideoTexture.prototype.update = function () {
@@ -42,10 +50,13 @@ var BABYLON;
                 this._autoLaunch = false;
                 this.video.play();
             }
+
             var now = BABYLON.Tools.Now;
+
             if (now - this._lastUpdate < 15) {
                 return false;
             }
+
             this._lastUpdate = now;
             this.getScene().getEngine().updateVideoTexture(this._texture, this.video, this._invertY);
             return true;
@@ -54,4 +65,4 @@ var BABYLON;
     })(BABYLON.Texture);
     BABYLON.VideoTexture = VideoTexture;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.videoTexture.js.map
+//# sourceMappingURL=babylon.videoTexture.js.map

+ 102 - 16
Babylon/Materials/babylon.effect.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var EffectFallbacks = (function () {
         function EffectFallbacks() {
@@ -11,13 +11,17 @@ var BABYLON;
                 if (rank < this._currentRank) {
                     this._currentRank = rank;
                 }
+
                 if (rank > this._maxRank) {
                     this._maxRank = rank;
                 }
+
                 this._defines[rank] = new Array();
             }
+
             this._defines[rank].push(define);
         };
+
         Object.defineProperty(EffectFallbacks.prototype, "isMoreFallbacks", {
             get: function () {
                 return this._currentRank <= this._maxRank;
@@ -25,17 +29,22 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         EffectFallbacks.prototype.reduce = function (currentDefines) {
             var currentFallbacks = this._defines[this._currentRank];
+
             for (var index = 0; index < currentFallbacks.length; index++) {
                 currentDefines = currentDefines.replace("#define " + currentFallbacks[index], "");
             }
+
             this._currentRank++;
+
             return currentDefines;
         };
         return EffectFallbacks;
     })();
     BABYLON.EffectFallbacks = EffectFallbacks;
+
     var Effect = (function () {
         function Effect(baseName, attributesNames, uniformsNames, samplers, engine, defines, fallbacks, onCompiled, onError) {
             var _this = this;
@@ -48,28 +57,33 @@ var BABYLON;
             this._uniformsNames = uniformsNames.concat(samplers);
             this._samplers = samplers;
             this._attributesNames = attributesNames;
+
             this.onError = onError;
             this.onCompiled = onCompiled;
+
             var vertexSource;
             var fragmentSource;
+
             if (baseName.vertexElement) {
                 vertexSource = document.getElementById(baseName.vertexElement);
+
                 if (!vertexSource) {
                     vertexSource = baseName.vertexElement;
                 }
-            }
-            else {
+            } else {
                 vertexSource = baseName.vertex || baseName;
             }
+
             if (baseName.fragmentElement) {
                 fragmentSource = document.getElementById(baseName.fragmentElement);
+
                 if (!fragmentSource) {
                     fragmentSource = baseName.fragmentElement;
                 }
-            }
-            else {
+            } else {
                 fragmentSource = baseName.fragment || baseName;
             }
+
             this._loadVertexShader(vertexSource, function (vertexCode) {
                 _this._loadFragmentShader(fragmentSource, function (fragmentCode) {
                     _this._prepareEffect(vertexCode, fragmentCode, attributesNames, defines, fallbacks);
@@ -80,34 +94,45 @@ var BABYLON;
         Effect.prototype.isReady = function () {
             return this._isReady;
         };
+
         Effect.prototype.getProgram = function () {
             return this._program;
         };
+
         Effect.prototype.getAttributesNames = function () {
             return this._attributesNames;
         };
+
         Effect.prototype.getAttributeLocation = function (index) {
             return this._attributes[index];
         };
+
         Effect.prototype.getAttributeLocationByName = function (name) {
             var index = this._attributesNames.indexOf(name);
+
             return this._attributes[index];
         };
+
         Effect.prototype.getAttributesCount = function () {
             return this._attributes.length;
         };
+
         Effect.prototype.getUniformIndex = function (uniformName) {
             return this._uniformsNames.indexOf(uniformName);
         };
+
         Effect.prototype.getUniform = function (uniformName) {
             return this._uniforms[this._uniformsNames.indexOf(uniformName)];
         };
+
         Effect.prototype.getSamplers = function () {
             return this._samplers;
         };
+
         Effect.prototype.getCompilationError = function () {
             return this._compilationError;
         };
+
         // Methods
         Effect.prototype._loadVertexShader = function (vertex, callback) {
             // DOM element ?
@@ -116,21 +141,25 @@ var BABYLON;
                 callback(vertexCode);
                 return;
             }
+
             // Is in local store ?
             if (Effect.ShadersStore[vertex + "VertexShader"]) {
                 callback(Effect.ShadersStore[vertex + "VertexShader"]);
                 return;
             }
+
             var vertexShaderUrl;
+
             if (vertex[0] === ".") {
                 vertexShaderUrl = vertex;
-            }
-            else {
+            } else {
                 vertexShaderUrl = BABYLON.Engine.ShadersRepository + vertex;
             }
+
             // Vertex shader
             BABYLON.Tools.LoadFile(vertexShaderUrl + ".vertex.fx", callback);
         };
+
         Effect.prototype._loadFragmentShader = function (fragment, callback) {
             // DOM element ?
             if (fragment instanceof HTMLElement) {
@@ -138,77 +167,93 @@ var BABYLON;
                 callback(fragmentCode);
                 return;
             }
+
             // Is in local store ?
             if (Effect.ShadersStore[fragment + "PixelShader"]) {
                 callback(Effect.ShadersStore[fragment + "PixelShader"]);
                 return;
             }
+
             if (Effect.ShadersStore[fragment + "FragmentShader"]) {
                 callback(Effect.ShadersStore[fragment + "FragmentShader"]);
                 return;
             }
+
             var fragmentShaderUrl;
+
             if (fragment[0] === ".") {
                 fragmentShaderUrl = fragment;
-            }
-            else {
+            } else {
                 fragmentShaderUrl = BABYLON.Engine.ShadersRepository + fragment;
             }
+
             // Fragment shader
             BABYLON.Tools.LoadFile(fragmentShaderUrl + ".fragment.fx", callback);
         };
+
         Effect.prototype._prepareEffect = function (vertexSourceCode, fragmentSourceCode, attributesNames, defines, fallbacks) {
-            try {
+            try  {
                 var engine = this._engine;
+
                 this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
+
                 this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
                 this._attributes = engine.getAttributes(this._program, attributesNames);
+
                 for (var index = 0; index < this._samplers.length; index++) {
                     var sampler = this.getUniform(this._samplers[index]);
+
                     if (sampler == null) {
                         this._samplers.splice(index, 1);
                         index--;
                     }
                 }
                 engine.bindSamplers(this);
+
                 this._isReady = true;
                 if (this.onCompiled) {
                     this.onCompiled(this);
                 }
-            }
-            catch (e) {
+            } catch (e) {
                 // Is it a problem with precision?
                 if (e.message.indexOf("highp") !== -1) {
                     vertexSourceCode = vertexSourceCode.replace("precision highp float", "precision mediump float");
                     fragmentSourceCode = fragmentSourceCode.replace("precision highp float", "precision mediump float");
+
                     this._prepareEffect(vertexSourceCode, fragmentSourceCode, attributesNames, defines, fallbacks);
+
                     return;
                 }
+
                 // Let's go through fallbacks then
                 if (fallbacks && fallbacks.isMoreFallbacks) {
                     defines = fallbacks.reduce(defines);
                     this._prepareEffect(vertexSourceCode, fragmentSourceCode, attributesNames, defines, fallbacks);
-                }
-                else {
+                } else {
                     BABYLON.Tools.Error("Unable to compile effect: " + this.name);
                     BABYLON.Tools.Error("Defines: " + defines);
                     BABYLON.Tools.Error("Error: " + e.message);
                     this._compilationError = e.message;
+
                     if (this.onError) {
                         this.onError(this, this._compilationError);
                     }
                 }
             }
         };
+
         Effect.prototype._bindTexture = function (channel, texture) {
             this._engine._bindTexture(this._samplers.indexOf(channel), texture);
         };
+
         Effect.prototype.setTexture = function (channel, texture) {
             this._engine.setTexture(this._samplers.indexOf(channel), texture);
         };
+
         Effect.prototype.setTextureFromPostProcess = function (channel, postProcess) {
             this._engine.setTextureFromPostProcess(this._samplers.indexOf(channel), postProcess);
         };
+
         //public _cacheMatrix(uniformName, matrix) {
         //    if (!this._valueCache[uniformName]) {
         //        this._valueCache[uniformName] = new BABYLON.Matrix();
@@ -222,110 +267,151 @@ var BABYLON;
                 this._valueCache[uniformName] = [x, y];
                 return;
             }
+
             this._valueCache[uniformName][0] = x;
             this._valueCache[uniformName][1] = y;
         };
+
         Effect.prototype._cacheFloat3 = function (uniformName, x, y, z) {
             if (!this._valueCache[uniformName]) {
                 this._valueCache[uniformName] = [x, y, z];
                 return;
             }
+
             this._valueCache[uniformName][0] = x;
             this._valueCache[uniformName][1] = y;
             this._valueCache[uniformName][2] = z;
         };
+
         Effect.prototype._cacheFloat4 = function (uniformName, x, y, z, w) {
             if (!this._valueCache[uniformName]) {
                 this._valueCache[uniformName] = [x, y, z, w];
                 return;
             }
+
             this._valueCache[uniformName][0] = x;
             this._valueCache[uniformName][1] = y;
             this._valueCache[uniformName][2] = z;
             this._valueCache[uniformName][3] = w;
         };
+
         Effect.prototype.setArray = function (uniformName, array) {
             this._engine.setArray(this.getUniform(uniformName), array);
+
             return this;
         };
+
         Effect.prototype.setMatrices = function (uniformName, matrices) {
             this._engine.setMatrices(this.getUniform(uniformName), matrices);
+
             return this;
         };
+
         Effect.prototype.setMatrix = function (uniformName, matrix) {
             //if (this._valueCache[uniformName] && this._valueCache[uniformName].equals(matrix))
             //    return;
             //this._cacheMatrix(uniformName, matrix);
             this._engine.setMatrix(this.getUniform(uniformName), matrix);
+
             return this;
         };
+
         Effect.prototype.setFloat = function (uniformName, value) {
             if (this._valueCache[uniformName] && this._valueCache[uniformName] === value)
                 return this;
+
             this._valueCache[uniformName] = value;
+
             this._engine.setFloat(this.getUniform(uniformName), value);
+
             return this;
         };
+
         Effect.prototype.setBool = function (uniformName, bool) {
             if (this._valueCache[uniformName] && this._valueCache[uniformName] === bool)
                 return this;
+
             this._valueCache[uniformName] = bool;
+
             this._engine.setBool(this.getUniform(uniformName), bool ? 1 : 0);
+
             return this;
         };
+
         Effect.prototype.setVector2 = function (uniformName, vector2) {
             if (this._valueCache[uniformName] && this._valueCache[uniformName][0] === vector2.x && this._valueCache[uniformName][1] === vector2.y)
                 return this;
+
             this._cacheFloat2(uniformName, vector2.x, vector2.y);
             this._engine.setFloat2(this.getUniform(uniformName), vector2.x, vector2.y);
+
             return this;
         };
+
         Effect.prototype.setFloat2 = function (uniformName, x, y) {
             if (this._valueCache[uniformName] && this._valueCache[uniformName][0] === x && this._valueCache[uniformName][1] === y)
                 return this;
+
             this._cacheFloat2(uniformName, x, y);
             this._engine.setFloat2(this.getUniform(uniformName), x, y);
+
             return this;
         };
+
         Effect.prototype.setVector3 = function (uniformName, vector3) {
             if (this._valueCache[uniformName] && this._valueCache[uniformName][0] === vector3.x && this._valueCache[uniformName][1] === vector3.y && this._valueCache[uniformName][2] === vector3.z)
                 return this;
+
             this._cacheFloat3(uniformName, vector3.x, vector3.y, vector3.z);
+
             this._engine.setFloat3(this.getUniform(uniformName), vector3.x, vector3.y, vector3.z);
+
             return this;
         };
+
         Effect.prototype.setFloat3 = function (uniformName, x, y, z) {
             if (this._valueCache[uniformName] && this._valueCache[uniformName][0] === x && this._valueCache[uniformName][1] === y && this._valueCache[uniformName][2] === z)
                 return this;
+
             this._cacheFloat3(uniformName, x, y, z);
             this._engine.setFloat3(this.getUniform(uniformName), x, y, z);
+
             return this;
         };
+
         Effect.prototype.setFloat4 = function (uniformName, x, y, z, w) {
             if (this._valueCache[uniformName] && this._valueCache[uniformName][0] === x && this._valueCache[uniformName][1] === y && this._valueCache[uniformName][2] === z && this._valueCache[uniformName][3] === w)
                 return this;
+
             this._cacheFloat4(uniformName, x, y, z, w);
             this._engine.setFloat4(this.getUniform(uniformName), x, y, z, w);
+
             return this;
         };
+
         Effect.prototype.setColor3 = function (uniformName, color3) {
             if (this._valueCache[uniformName] && this._valueCache[uniformName][0] === color3.r && this._valueCache[uniformName][1] === color3.g && this._valueCache[uniformName][2] === color3.b)
                 return this;
+
             this._cacheFloat3(uniformName, color3.r, color3.g, color3.b);
             this._engine.setColor3(this.getUniform(uniformName), color3);
+
             return this;
         };
+
         Effect.prototype.setColor4 = function (uniformName, color3, alpha) {
             if (this._valueCache[uniformName] && this._valueCache[uniformName][0] === color3.r && this._valueCache[uniformName][1] === color3.g && this._valueCache[uniformName][2] === color3.b && this._valueCache[uniformName][3] === alpha)
                 return this;
+
             this._cacheFloat4(uniformName, color3.r, color3.g, color3.b, alpha);
             this._engine.setColor4(this.getUniform(uniformName), color3, alpha);
+
             return this;
         };
-        // Statics
+
         Effect.ShadersStore = {};
         return Effect;
     })();
     BABYLON.Effect = Effect;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.effect.js.map
+//# sourceMappingURL=babylon.effect.js.map

+ 28 - 2
Babylon/Materials/babylon.material.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var Material = (function () {
         function Material(name, scene, doNotAdd) {
@@ -12,7 +12,9 @@ var BABYLON;
             this._fillMode = Material.TriangleFillMode;
             this.pointSize = 1.0;
             this.id = name;
+
             this._scene = scene;
+
             if (!doNotAdd) {
                 scene.materials.push(this);
             }
@@ -24,6 +26,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(Material, "WireFrameFillMode", {
             get: function () {
                 return Material._WireFrameFillMode;
@@ -31,6 +34,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(Material, "PointFillMode", {
             get: function () {
                 return Material._PointFillMode;
@@ -38,6 +42,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(Material.prototype, "wireframe", {
             get: function () {
                 return this._fillMode === Material.WireFrameFillMode;
@@ -48,6 +53,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(Material.prototype, "pointsCloud", {
             get: function () {
                 return this._fillMode === Material.PointFillMode;
@@ -58,6 +65,8 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Object.defineProperty(Material.prototype, "fillMode", {
             get: function () {
                 return this._fillMode;
@@ -68,50 +77,67 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
+
         Material.prototype.isReady = function (mesh, useInstances) {
             return true;
         };
+
         Material.prototype.getEffect = function () {
             return this._effect;
         };
+
         Material.prototype.getScene = function () {
             return this._scene;
         };
+
         Material.prototype.needAlphaBlending = function () {
             return (this.alpha < 1.0);
         };
+
         Material.prototype.needAlphaTesting = function () {
             return false;
         };
+
         Material.prototype.getAlphaTestTexture = function () {
             return null;
         };
+
         Material.prototype.trackCreation = function (onCompiled, onError) {
         };
+
         Material.prototype._preBind = function () {
             var engine = this._scene.getEngine();
+
             engine.enableEffect(this._effect);
             engine.setState(this.backFaceCulling);
         };
+
         Material.prototype.bind = function (world, mesh) {
             this._scene._cachedMaterial = this;
+
             if (this.onBind) {
                 this.onBind(this);
             }
         };
+
         Material.prototype.bindOnlyWorldMatrix = function (world) {
         };
+
         Material.prototype.unbind = function () {
         };
+
         Material.prototype.dispose = function (forceDisposeEffect) {
             // Remove from scene
             var index = this._scene.materials.indexOf(this);
             this._scene.materials.splice(index, 1);
+
             // Shader are kept in cache for further use but we can get rid of this by using forceDisposeEffect
             if (forceDisposeEffect && this._effect) {
                 this._scene.getEngine()._releaseEffect(this._effect);
                 this._effect = null;
             }
+
             // Callback
             if (this.onDispose) {
                 this.onDispose();
@@ -124,4 +150,4 @@ var BABYLON;
     })();
     BABYLON.Material = Material;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.material.js.map
+//# sourceMappingURL=babylon.material.js.map

+ 6 - 2
Babylon/Materials/babylon.multiMaterial.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -11,6 +11,7 @@ var BABYLON;
         function MultiMaterial(name, scene) {
             _super.call(this, name, scene, true);
             this.subMaterials = new Array();
+
             scene.multiMaterials.push(this);
         }
         // Properties
@@ -18,8 +19,10 @@ var BABYLON;
             if (index < 0 || index >= this.subMaterials.length) {
                 return this.getScene().defaultMaterial;
             }
+
             return this.subMaterials[index];
         };
+
         // Methods
         MultiMaterial.prototype.isReady = function (mesh) {
             for (var index = 0; index < this.subMaterials.length; index++) {
@@ -30,10 +33,11 @@ var BABYLON;
                     }
                 }
             }
+
             return true;
         };
         return MultiMaterial;
     })(BABYLON.Material);
     BABYLON.MultiMaterial = MultiMaterial;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.multiMaterial.js.map
+//# sourceMappingURL=babylon.multiMaterial.js.map

+ 49 - 2
Babylon/Materials/babylon.shaderMaterial.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -20,148 +20,195 @@ var BABYLON;
             this._matrices = new Array();
             this._cachedWorldViewMatrix = new BABYLON.Matrix();
             this._shaderPath = shaderPath;
+
             options.needAlphaBlending = options.needAlphaBlending || false;
             options.needAlphaTesting = options.needAlphaTesting || false;
             options.attributes = options.attributes || ["position", "normal", "uv"];
             options.uniforms = options.uniforms || ["worldViewProjection"];
             options.samplers = options.samplers || [];
+
             this._options = options;
         }
         ShaderMaterial.prototype.needAlphaBlending = function () {
             return this._options.needAlphaBlending;
         };
+
         ShaderMaterial.prototype.needAlphaTesting = function () {
             return this._options.needAlphaTesting;
         };
+
         ShaderMaterial.prototype._checkUniform = function (uniformName) {
             if (this._options.uniforms.indexOf(uniformName) === -1) {
                 this._options.uniforms.push(uniformName);
             }
         };
+
         ShaderMaterial.prototype.setTexture = function (name, texture) {
             if (this._options.samplers.indexOf(name) === -1) {
                 this._options.samplers.push(name);
             }
             this._textures[name] = texture;
+
             return this;
         };
+
         ShaderMaterial.prototype.setFloat = function (name, value) {
             this._checkUniform(name);
             this._floats[name] = value;
+
             return this;
         };
+
         ShaderMaterial.prototype.setFloats = function (name, value) {
             this._checkUniform(name);
             this._floatsArrays[name] = value;
+
             return this;
         };
+
         ShaderMaterial.prototype.setColor3 = function (name, value) {
             this._checkUniform(name);
             this._colors3[name] = value;
+
             return this;
         };
+
         ShaderMaterial.prototype.setColor4 = function (name, value) {
             this._checkUniform(name);
             this._colors4[name] = value;
+
             return this;
         };
+
         ShaderMaterial.prototype.setVector2 = function (name, value) {
             this._checkUniform(name);
             this._vectors2[name] = value;
+
             return this;
         };
+
         ShaderMaterial.prototype.setVector3 = function (name, value) {
             this._checkUniform(name);
             this._vectors3[name] = value;
+
             return this;
         };
+
         ShaderMaterial.prototype.setMatrix = function (name, value) {
             this._checkUniform(name);
             this._matrices[name] = value;
+
             return this;
         };
+
         ShaderMaterial.prototype.isReady = function () {
             var scene = this.getScene();
             var engine = scene.getEngine();
+
             if (!this.checkReadyOnEveryCall) {
                 if (this._renderId === scene.getRenderId()) {
                     return true;
                 }
             }
+
             var previousEffect = this._effect;
             this._effect = engine.createEffect(this._shaderPath, this._options.attributes, this._options.uniforms, this._options.samplers, "", null, this.onCompiled, this.onError);
+
             if (!this._effect.isReady()) {
                 return false;
             }
+
             if (previousEffect !== this._effect) {
                 scene.resetCachedMaterial();
             }
+
             this._renderId = scene.getRenderId();
+
             return true;
         };
+
         ShaderMaterial.prototype.bindOnlyWorldMatrix = function (world) {
             var scene = this.getScene();
+
             if (this._options.uniforms.indexOf("world") !== -1) {
                 this._effect.setMatrix("world", world);
             }
+
             if (this._options.uniforms.indexOf("worldView") !== -1) {
                 world.multiplyToRef(scene.getViewMatrix(), this._cachedWorldViewMatrix);
                 this._effect.setMatrix("worldView", this._cachedWorldViewMatrix);
             }
+
             if (this._options.uniforms.indexOf("worldViewProjection") !== -1) {
                 this._effect.setMatrix("worldViewProjection", world.multiply(scene.getTransformMatrix()));
             }
         };
+
         ShaderMaterial.prototype.bind = function (world) {
             // Std values
             this.bindOnlyWorldMatrix(world);
+
             if (this.getScene().getCachedMaterial() !== this) {
                 if (this._options.uniforms.indexOf("view") !== -1) {
                     this._effect.setMatrix("view", this.getScene().getViewMatrix());
                 }
+
                 if (this._options.uniforms.indexOf("projection") !== -1) {
                     this._effect.setMatrix("projection", this.getScene().getProjectionMatrix());
                 }
+
                 if (this._options.uniforms.indexOf("viewProjection") !== -1) {
                     this._effect.setMatrix("viewProjection", this.getScene().getTransformMatrix());
                 }
+
                 for (var name in this._textures) {
                     this._effect.setTexture(name, this._textures[name]);
                 }
+
                 for (name in this._floats) {
                     this._effect.setFloat(name, this._floats[name]);
                 }
+
                 for (name in this._floatsArrays) {
                     this._effect.setArray(name, this._floatsArrays[name]);
                 }
+
                 for (name in this._colors3) {
                     this._effect.setColor3(name, this._colors3[name]);
                 }
+
                 for (name in this._colors4) {
                     var color = this._colors4[name];
                     this._effect.setFloat4(name, color.r, color.g, color.b, color.a);
                 }
+
                 for (name in this._vectors2) {
                     this._effect.setVector2(name, this._vectors2[name]);
                 }
+
                 for (name in this._vectors3) {
                     this._effect.setVector3(name, this._vectors3[name]);
                 }
+
                 for (name in this._matrices) {
                     this._effect.setMatrix(name, this._matrices[name]);
                 }
             }
+
             _super.prototype.bind.call(this, world, null);
         };
+
         ShaderMaterial.prototype.dispose = function (forceDisposeEffect) {
             for (var name in this._textures) {
                 this._textures[name].dispose();
             }
+
             this._textures = [];
+
             _super.prototype.dispose.call(this, forceDisposeEffect);
         };
         return ShaderMaterial;
     })(BABYLON.Material);
     BABYLON.ShaderMaterial = ShaderMaterial;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.shaderMaterial.js.map
+//# sourceMappingURL=babylon.shaderMaterial.js.map

Plik diff jest za duży
+ 157 - 35
Babylon/Materials/babylon.standardMaterial.js


Plik diff jest za duży
+ 582 - 36
Babylon/Math/babylon.math.js


+ 38 - 2
Babylon/Mesh/babylon.InstancedMesh.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -10,16 +10,23 @@ var BABYLON;
         __extends(InstancedMesh, _super);
         function InstancedMesh(name, source) {
             _super.call(this, name, source.getScene());
+
             source.instances.push(this);
+
             this._sourceMesh = source;
+
             this.position.copyFrom(source.position);
             this.rotation.copyFrom(source.rotation);
             this.scaling.copyFrom(source.scaling);
+
             if (source.rotationQuaternion) {
                 this.rotationQuaternion = source.rotationQuaternion.clone();
             }
+
             this.infiniteDistance = source.infiniteDistance;
+
             this.setPivotMatrix(source.getPivotMatrix());
+
             this.refreshBoundingInfo();
             this._syncSubMeshes();
         }
@@ -31,6 +38,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(InstancedMesh.prototype, "material", {
             get: function () {
                 return this._sourceMesh.material;
@@ -38,6 +46,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(InstancedMesh.prototype, "visibility", {
             get: function () {
                 return this._sourceMesh.visibility;
@@ -45,6 +54,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(InstancedMesh.prototype, "skeleton", {
             get: function () {
                 return this._sourceMesh.skeleton;
@@ -52,9 +62,11 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         InstancedMesh.prototype.getTotalVertices = function () {
             return this._sourceMesh.getTotalVertices();
         };
+
         Object.defineProperty(InstancedMesh.prototype, "sourceMesh", {
             get: function () {
                 return this._sourceMesh;
@@ -62,15 +74,19 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         InstancedMesh.prototype.getVerticesData = function (kind) {
             return this._sourceMesh.getVerticesData(kind);
         };
+
         InstancedMesh.prototype.isVerticesDataPresent = function (kind) {
             return this._sourceMesh.isVerticesDataPresent(kind);
         };
+
         InstancedMesh.prototype.getIndices = function () {
             return this._sourceMesh.getIndices();
         };
+
         Object.defineProperty(InstancedMesh.prototype, "_positions", {
             get: function () {
                 return this._sourceMesh._positions;
@@ -78,71 +94,91 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         InstancedMesh.prototype.refreshBoundingInfo = function () {
             var data = this._sourceMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
+
             if (data) {
                 var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._sourceMesh.getTotalVertices());
                 this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
             }
+
             this._updateBoundingInfo();
         };
+
         InstancedMesh.prototype._preActivate = function () {
             if (this._currentLOD) {
                 this._currentLOD._preActivate();
             }
         };
+
         InstancedMesh.prototype._activate = function (renderId) {
             if (this._currentLOD) {
                 this._currentLOD._registerInstanceForRenderId(this, renderId);
             }
         };
+
         InstancedMesh.prototype.getLOD = function (camera) {
             this._currentLOD = this.sourceMesh.getLOD(this.getScene().activeCamera, this.getBoundingInfo().boundingSphere);
+
             if (this._currentLOD === this.sourceMesh) {
                 return this;
             }
+
             return this._currentLOD;
         };
+
         InstancedMesh.prototype._syncSubMeshes = function () {
             this.releaseSubMeshes();
             for (var index = 0; index < this._sourceMesh.subMeshes.length; index++) {
                 this._sourceMesh.subMeshes[index].clone(this, this._sourceMesh);
             }
         };
+
         InstancedMesh.prototype._generatePointsArray = function () {
             return this._sourceMesh._generatePointsArray();
         };
+
         // Clone
         InstancedMesh.prototype.clone = function (name, newParent, doNotCloneChildren) {
             var result = this._sourceMesh.createInstance(name);
+
             // Deep copy
             BABYLON.Tools.DeepCopy(this, result, ["name"], []);
+
             // Bounding info
             this.refreshBoundingInfo();
+
             // Parent
             if (newParent) {
                 result.parent = newParent;
             }
+
             if (!doNotCloneChildren) {
                 for (var index = 0; index < this.getScene().meshes.length; index++) {
                     var mesh = this.getScene().meshes[index];
+
                     if (mesh.parent == this) {
                         mesh.clone(mesh.name, result);
                     }
                 }
             }
+
             result.computeWorldMatrix(true);
+
             return result;
         };
+
         // Dispoe
         InstancedMesh.prototype.dispose = function (doNotRecurse) {
             // Remove from mesh
             var index = this._sourceMesh.instances.indexOf(this);
             this._sourceMesh.instances.splice(index, 1);
+
             _super.prototype.dispose.call(this, doNotRecurse);
         };
         return InstancedMesh;
     })(BABYLON.AbstractMesh);
     BABYLON.InstancedMesh = InstancedMesh;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.instancedMesh.js.map
+//# sourceMappingURL=babylon.instancedMesh.js.map

+ 185 - 33
Babylon/Mesh/babylon.abstractMesh.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -68,6 +68,7 @@ var BABYLON;
             this._renderId = 0;
             this._intersectionsInProgress = new Array();
             this._onAfterWorldMatrixUpdate = new Array();
+
             scene.meshes.push(this);
         }
         Object.defineProperty(AbstractMesh, "BILLBOARDMODE_NONE", {
@@ -77,6 +78,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(AbstractMesh, "BILLBOARDMODE_X", {
             get: function () {
                 return AbstractMesh._BILLBOARDMODE_X;
@@ -84,6 +86,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(AbstractMesh, "BILLBOARDMODE_Y", {
             get: function () {
                 return AbstractMesh._BILLBOARDMODE_Y;
@@ -91,6 +94,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(AbstractMesh, "BILLBOARDMODE_Z", {
             get: function () {
                 return AbstractMesh._BILLBOARDMODE_Z;
@@ -98,6 +102,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(AbstractMesh, "BILLBOARDMODE_ALL", {
             get: function () {
                 return AbstractMesh._BILLBOARDMODE_ALL;
@@ -105,6 +110,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(AbstractMesh.prototype, "isBlocked", {
             // Methods
             get: function () {
@@ -113,44 +119,56 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         AbstractMesh.prototype.getLOD = function (camera) {
             return this;
         };
+
         AbstractMesh.prototype.getTotalVertices = function () {
             return 0;
         };
+
         AbstractMesh.prototype.getIndices = function () {
             return null;
         };
+
         AbstractMesh.prototype.getVerticesData = function (kind) {
             return null;
         };
+
         AbstractMesh.prototype.isVerticesDataPresent = function (kind) {
             return false;
         };
+
         AbstractMesh.prototype.getBoundingInfo = function () {
             if (this._masterMesh) {
                 return this._masterMesh.getBoundingInfo();
             }
+
             if (!this._boundingInfo) {
                 this._updateBoundingInfo();
             }
             return this._boundingInfo;
         };
+
         AbstractMesh.prototype._preActivate = function () {
         };
+
         AbstractMesh.prototype._activate = function (renderId) {
             this._renderId = renderId;
         };
+
         AbstractMesh.prototype.getWorldMatrix = function () {
             if (this._masterMesh) {
                 return this._masterMesh.getWorldMatrix();
             }
+
             if (this._currentRenderId !== this.getScene().getRenderId()) {
                 this.computeWorldMatrix();
             }
             return this._worldMatrix;
         };
+
         Object.defineProperty(AbstractMesh.prototype, "worldMatrixFromCache", {
             get: function () {
                 return this._worldMatrix;
@@ -158,6 +176,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(AbstractMesh.prototype, "absolutePosition", {
             get: function () {
                 return this._absolutePosition;
@@ -165,46 +184,53 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         AbstractMesh.prototype.rotate = function (axis, amount, space) {
             if (!this.rotationQuaternion) {
                 this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
                 this.rotation = BABYLON.Vector3.Zero();
             }
+
             if (!space || space == 0 /* LOCAL */) {
                 var rotationQuaternion = BABYLON.Quaternion.RotationAxis(axis, amount);
                 this.rotationQuaternion = this.rotationQuaternion.multiply(rotationQuaternion);
-            }
-            else {
+            } else {
                 if (this.parent) {
                     var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
                     invertParentWorldMatrix.invert();
+
                     axis = BABYLON.Vector3.TransformNormal(axis, invertParentWorldMatrix);
                 }
                 rotationQuaternion = BABYLON.Quaternion.RotationAxis(axis, amount);
                 this.rotationQuaternion = rotationQuaternion.multiply(this.rotationQuaternion);
             }
         };
+
         AbstractMesh.prototype.translate = function (axis, distance, space) {
             var displacementVector = axis.scale(distance);
+
             if (!space || space == 0 /* LOCAL */) {
                 var tempV3 = this.getPositionExpressedInLocalSpace().add(displacementVector);
                 this.setPositionWithLocalVector(tempV3);
-            }
-            else {
+            } else {
                 this.setAbsolutePosition(this.getAbsolutePosition().add(displacementVector));
             }
         };
+
         AbstractMesh.prototype.getAbsolutePosition = function () {
             this.computeWorldMatrix();
             return this._absolutePosition;
         };
+
         AbstractMesh.prototype.setAbsolutePosition = function (absolutePosition) {
             if (!absolutePosition) {
                 return;
             }
+
             var absolutePositionX;
             var absolutePositionY;
             var absolutePositionZ;
+
             if (absolutePosition.x === undefined) {
                 if (arguments.length < 3) {
                     return;
@@ -212,65 +238,78 @@ var BABYLON;
                 absolutePositionX = arguments[0];
                 absolutePositionY = arguments[1];
                 absolutePositionZ = arguments[2];
-            }
-            else {
+            } else {
                 absolutePositionX = absolutePosition.x;
                 absolutePositionY = absolutePosition.y;
                 absolutePositionZ = absolutePosition.z;
             }
+
             if (this.parent) {
                 var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
                 invertParentWorldMatrix.invert();
+
                 var worldPosition = new BABYLON.Vector3(absolutePositionX, absolutePositionY, absolutePositionZ);
+
                 this.position = BABYLON.Vector3.TransformCoordinates(worldPosition, invertParentWorldMatrix);
-            }
-            else {
+            } else {
                 this.position.x = absolutePositionX;
                 this.position.y = absolutePositionY;
                 this.position.z = absolutePositionZ;
             }
         };
+
         AbstractMesh.prototype.setPivotMatrix = function (matrix) {
             this._pivotMatrix = matrix;
             this._cache.pivotMatrixUpdated = true;
         };
+
         AbstractMesh.prototype.getPivotMatrix = function () {
             return this._pivotMatrix;
         };
+
         AbstractMesh.prototype._isSynchronized = function () {
             if (this._isDirty) {
                 return false;
             }
+
             if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE)
                 return false;
+
             if (this._cache.pivotMatrixUpdated) {
                 return false;
             }
+
             if (this.infiniteDistance) {
                 return false;
             }
+
             if (!this._cache.position.equals(this.position))
                 return false;
+
             if (this.rotationQuaternion) {
                 if (!this._cache.rotationQuaternion.equals(this.rotationQuaternion))
                     return false;
-            }
-            else {
+            } else {
                 if (!this._cache.rotation.equals(this.rotation))
                     return false;
             }
+
             if (!this._cache.scaling.equals(this.scaling))
                 return false;
+
             return true;
         };
+
         AbstractMesh.prototype._initCache = function () {
             _super.prototype._initCache.call(this);
+
             this._cache.localMatrixUpdated = false;
             this._cache.position = BABYLON.Vector3.Zero();
             this._cache.scaling = BABYLON.Vector3.Zero();
             this._cache.rotation = BABYLON.Vector3.Zero();
             this._cache.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 0);
         };
+
         AbstractMesh.prototype.markAsDirty = function (property) {
             if (property === "rotation") {
                 this.rotationQuaternion = null;
@@ -278,65 +317,79 @@ var BABYLON;
             this._currentRenderId = Number.MAX_VALUE;
             this._isDirty = true;
         };
+
         AbstractMesh.prototype._updateBoundingInfo = function () {
             this._boundingInfo = this._boundingInfo || new BABYLON.BoundingInfo(this.absolutePosition, this.absolutePosition);
+
             this._boundingInfo._update(this.worldMatrixFromCache);
+
             this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);
         };
+
         AbstractMesh.prototype._updateSubMeshesBoundingInfo = function (matrix) {
             if (!this.subMeshes) {
                 return;
             }
+
             for (var subIndex = 0; subIndex < this.subMeshes.length; subIndex++) {
                 var subMesh = this.subMeshes[subIndex];
+
                 subMesh.updateBoundingInfo(matrix);
             }
         };
+
         AbstractMesh.prototype.computeWorldMatrix = function (force) {
             if (!force && (this._currentRenderId == this.getScene().getRenderId() || this.isSynchronized(true))) {
                 return this._worldMatrix;
             }
+
             this._cache.position.copyFrom(this.position);
             this._cache.scaling.copyFrom(this.scaling);
             this._cache.pivotMatrixUpdated = false;
             this._currentRenderId = this.getScene().getRenderId();
             this._isDirty = false;
+
             // Scaling
             BABYLON.Matrix.ScalingToRef(this.scaling.x, this.scaling.y, this.scaling.z, this._localScaling);
+
             // Rotation
             if (this.rotationQuaternion) {
                 this.rotationQuaternion.toRotationMatrix(this._localRotation);
                 this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion);
-            }
-            else {
+            } else {
                 BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._localRotation);
                 this._cache.rotation.copyFrom(this.rotation);
             }
+
             // Translation
             if (this.infiniteDistance && !this.parent) {
                 var camera = this.getScene().activeCamera;
                 var cameraWorldMatrix = camera.getWorldMatrix();
+
                 var cameraGlobalPosition = new BABYLON.Vector3(cameraWorldMatrix.m[12], cameraWorldMatrix.m[13], cameraWorldMatrix.m[14]);
+
                 BABYLON.Matrix.TranslationToRef(this.position.x + cameraGlobalPosition.x, this.position.y + cameraGlobalPosition.y, this.position.z + cameraGlobalPosition.z, this._localTranslation);
-            }
-            else {
+            } else {
                 BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._localTranslation);
             }
+
             // Composing transformations
             this._pivotMatrix.multiplyToRef(this._localScaling, this._localPivotScaling);
             this._localPivotScaling.multiplyToRef(this._localRotation, this._localPivotScalingRotation);
+
             // Billboarding
             if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE && this.getScene().activeCamera) {
                 var localPosition = this.position.clone();
                 var zero = this.getScene().activeCamera.position.clone();
+
                 if (this.parent && this.parent.position) {
                     localPosition.addInPlace(this.parent.position);
                     BABYLON.Matrix.TranslationToRef(localPosition.x, localPosition.y, localPosition.z, this._localTranslation);
                 }
+
                 if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_ALL) === AbstractMesh.BILLBOARDMODE_ALL) {
                     zero = this.getScene().activeCamera.position;
-                }
-                else {
+                } else {
                     if (this.billboardMode & BABYLON.AbstractMesh.BILLBOARDMODE_X)
                         zero.x = localPosition.x + BABYLON.Engine.Epsilon;
                     if (this.billboardMode & BABYLON.AbstractMesh.BILLBOARDMODE_Y)
@@ -344,30 +397,39 @@ var BABYLON;
                     if (this.billboardMode & BABYLON.AbstractMesh.BILLBOARDMODE_Z)
                         zero.z = localPosition.z + 0.001;
                 }
+
                 BABYLON.Matrix.LookAtLHToRef(localPosition, zero, BABYLON.Vector3.Up(), this._localBillboard);
                 this._localBillboard.m[12] = this._localBillboard.m[13] = this._localBillboard.m[14] = 0;
+
                 this._localBillboard.invert();
+
                 this._localPivotScalingRotation.multiplyToRef(this._localBillboard, this._localWorld);
                 this._rotateYByPI.multiplyToRef(this._localWorld, this._localPivotScalingRotation);
             }
+
             // Local world
             this._localPivotScalingRotation.multiplyToRef(this._localTranslation, this._localWorld);
+
             // Parent
             if (this.parent && this.parent.getWorldMatrix && this.billboardMode === BABYLON.AbstractMesh.BILLBOARDMODE_NONE) {
                 this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
-            }
-            else {
+            } else {
                 this._worldMatrix.copyFrom(this._localWorld);
             }
+
             // Bounding info
             this._updateBoundingInfo();
+
             // Absolute position
             this._absolutePosition.copyFromFloats(this._worldMatrix.m[12], this._worldMatrix.m[13], this._worldMatrix.m[14]);
+
             for (var callbackIndex = 0; callbackIndex < this._onAfterWorldMatrixUpdate.length; callbackIndex++) {
                 this._onAfterWorldMatrixUpdate[callbackIndex](this);
             }
+
             return this._worldMatrix;
         };
+
         /**
         * If you'd like to be callbacked after the mesh position, rotation or scaling has been updated
         * @param func: callback function to add
@@ -375,26 +437,35 @@ var BABYLON;
         AbstractMesh.prototype.registerAfterWorldMatrixUpdate = function (func) {
             this._onAfterWorldMatrixUpdate.push(func);
         };
+
         AbstractMesh.prototype.unregisterAfterWorldMatrixUpdate = function (func) {
             var index = this._onAfterWorldMatrixUpdate.indexOf(func);
+
             if (index > -1) {
                 this._onAfterWorldMatrixUpdate.splice(index, 1);
             }
         };
+
         AbstractMesh.prototype.setPositionWithLocalVector = function (vector3) {
             this.computeWorldMatrix();
+
             this.position = BABYLON.Vector3.TransformNormal(vector3, this._localWorld);
         };
+
         AbstractMesh.prototype.getPositionExpressedInLocalSpace = function () {
             this.computeWorldMatrix();
             var invLocalWorldMatrix = this._localWorld.clone();
             invLocalWorldMatrix.invert();
+
             return BABYLON.Vector3.TransformNormal(this.position, invLocalWorldMatrix);
         };
+
         AbstractMesh.prototype.locallyTranslate = function (vector3) {
             this.computeWorldMatrix();
+
             this.position = BABYLON.Vector3.TransformCoordinates(vector3, this._localWorld);
         };
+
         AbstractMesh.prototype.lookAt = function (targetPoint, yawCor, pitchCor, rollCor) {
             /// <summary>Orients a mesh towards a target point. Mesh must be drawn facing user.</summary>
             /// <param name="targetPoint" type="BABYLON.Vector3">The position (must be in same space as current mesh) to look at</param>
@@ -402,154 +473,200 @@ var BABYLON;
             /// <param name="pitchCor" type="Number">optional pitch (x-axis) correction in radians</param>
             /// <param name="rollCor" type="Number">optional roll (z-axis) correction in radians</param>
             /// <returns>Mesh oriented towards targetMesh</returns>
-            yawCor = yawCor || 0; // default to zero if undefined 
+            yawCor = yawCor || 0; // default to zero if undefined
             pitchCor = pitchCor || 0;
             rollCor = rollCor || 0;
+
             var dv = targetPoint.subtract(this.position);
             var yaw = -Math.atan2(dv.z, dv.x) - Math.PI / 2;
             var len = Math.sqrt(dv.x * dv.x + dv.z * dv.z);
             var pitch = Math.atan2(dv.y, len);
             this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(yaw + yawCor, pitch + pitchCor, rollCor);
         };
+
         AbstractMesh.prototype.isInFrustum = function (frustumPlanes) {
             if (!this._boundingInfo.isInFrustum(frustumPlanes)) {
                 return false;
             }
+
             return true;
         };
+
         AbstractMesh.prototype.isCompletelyInFrustum = function (camera) {
             if (!camera) {
                 camera = this.getScene().activeCamera;
             }
+
             var transformMatrix = camera.getViewMatrix().multiply(camera.getProjectionMatrix());
+
             if (!this._boundingInfo.isCompletelyInFrustum(BABYLON.Frustum.GetPlanes(transformMatrix))) {
                 return false;
             }
+
             return true;
         };
+
         AbstractMesh.prototype.intersectsMesh = function (mesh, precise) {
             if (!this._boundingInfo || !mesh._boundingInfo) {
                 return false;
             }
+
             return this._boundingInfo.intersects(mesh._boundingInfo, precise);
         };
+
         AbstractMesh.prototype.intersectsPoint = function (point) {
             if (!this._boundingInfo) {
                 return false;
             }
+
             return this._boundingInfo.intersectsPoint(point);
         };
+
         // Physics
         AbstractMesh.prototype.setPhysicsState = function (impostor, options) {
             var physicsEngine = this.getScene().getPhysicsEngine();
+
             if (!physicsEngine) {
                 return;
             }
+
             if (impostor.impostor) {
                 // Old API
                 options = impostor;
                 impostor = impostor.impostor;
             }
+
             impostor = impostor || BABYLON.PhysicsEngine.NoImpostor;
+
             if (impostor === BABYLON.PhysicsEngine.NoImpostor) {
                 physicsEngine._unregisterMesh(this);
                 return;
             }
+
             options.mass = options.mass || 0;
             options.friction = options.friction || 0.2;
             options.restitution = options.restitution || 0.2;
+
             this._physicImpostor = impostor;
             this._physicsMass = options.mass;
             this._physicsFriction = options.friction;
             this._physicRestitution = options.restitution;
+
             return physicsEngine._registerMesh(this, impostor, options);
         };
+
         AbstractMesh.prototype.getPhysicsImpostor = function () {
             if (!this._physicImpostor) {
                 return BABYLON.PhysicsEngine.NoImpostor;
             }
+
             return this._physicImpostor;
         };
+
         AbstractMesh.prototype.getPhysicsMass = function () {
             if (!this._physicsMass) {
                 return 0;
             }
+
             return this._physicsMass;
         };
+
         AbstractMesh.prototype.getPhysicsFriction = function () {
             if (!this._physicsFriction) {
                 return 0;
             }
+
             return this._physicsFriction;
         };
+
         AbstractMesh.prototype.getPhysicsRestitution = function () {
             if (!this._physicRestitution) {
                 return 0;
             }
+
             return this._physicRestitution;
         };
+
         AbstractMesh.prototype.getPositionInCameraSpace = function (camera) {
             if (!camera) {
                 camera = this.getScene().activeCamera;
             }
+
             return BABYLON.Vector3.TransformCoordinates(this.absolutePosition, camera.getViewMatrix());
         };
+
         AbstractMesh.prototype.getDistanceToCamera = function (camera) {
             if (!camera) {
                 camera = this.getScene().activeCamera;
             }
+
             return this.absolutePosition.subtract(camera.position).length();
         };
+
         AbstractMesh.prototype.applyImpulse = function (force, contactPoint) {
             if (!this._physicImpostor) {
                 return;
             }
+
             this.getScene().getPhysicsEngine()._applyImpulse(this, force, contactPoint);
         };
+
         AbstractMesh.prototype.setPhysicsLinkWith = function (otherMesh, pivot1, pivot2, options) {
             if (!this._physicImpostor) {
                 return;
             }
+
             this.getScene().getPhysicsEngine()._createLink(this, otherMesh, pivot1, pivot2, options);
         };
+
         AbstractMesh.prototype.updatePhysicsBodyPosition = function () {
             if (!this._physicImpostor) {
                 return;
             }
             this.getScene().getPhysicsEngine()._updateBodyPosition(this);
         };
+
         // Collisions
         AbstractMesh.prototype.moveWithCollisions = function (velocity) {
             var globalPosition = this.getAbsolutePosition();
+
             globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPositionForCollisions);
             this._oldPositionForCollisions.addInPlace(this.ellipsoidOffset);
             this._collider.radius = this.ellipsoid;
+
             this.getScene()._getNewPosition(this._oldPositionForCollisions, velocity, this._collider, 3, this._newPositionForCollisions, this);
             this._newPositionForCollisions.subtractToRef(this._oldPositionForCollisions, this._diffPositionForCollisions);
+
             if (this._diffPositionForCollisions.length() > BABYLON.Engine.CollisionsEpsilon) {
                 this.position.addInPlace(this._diffPositionForCollisions);
             }
         };
+
         // Submeshes octree
         /**
         * This function will create an octree to help select the right submeshes for rendering, picking and collisions
         * Please note that you must have a decent number of submeshes to get performance improvements when using octree
         */
         AbstractMesh.prototype.createOrUpdateSubmeshesOctree = function (maxCapacity, maxDepth) {
-            if (maxCapacity === void 0) { maxCapacity = 64; }
-            if (maxDepth === void 0) { maxDepth = 2; }
+            if (typeof maxCapacity === "undefined") { maxCapacity = 64; }
+            if (typeof maxDepth === "undefined") { maxDepth = 2; }
             if (!this._submeshesOctree) {
                 this._submeshesOctree = new BABYLON.Octree(BABYLON.Octree.CreationFuncForSubMeshes, maxCapacity, maxDepth);
             }
+
             this.computeWorldMatrix(true);
+
             // Update octree
             var bbox = this.getBoundingInfo().boundingBox;
             this._submeshesOctree.update(bbox.minimumWorld, bbox.maximumWorld, this.subMeshes);
+
             return this._submeshesOctree;
         };
+
         // Collisions
         AbstractMesh.prototype._collideForSubMesh = function (subMesh, transformMatrix, collider) {
             this._generatePointsArray();
+
             // Transformation
             if (!subMesh._lastColliderWorldVertices || !subMesh._lastColliderTransformMatrix.equals(transformMatrix)) {
                 subMesh._lastColliderTransformMatrix = transformMatrix.clone();
@@ -561,81 +678,103 @@ var BABYLON;
                     subMesh._lastColliderWorldVertices.push(BABYLON.Vector3.TransformCoordinates(this._positions[i], transformMatrix));
                 }
             }
+
             // Collide
             collider._collide(subMesh, subMesh._lastColliderWorldVertices, this.getIndices(), subMesh.indexStart, subMesh.indexStart + subMesh.indexCount, subMesh.verticesStart);
         };
+
         AbstractMesh.prototype._processCollisionsForSubMeshes = function (collider, transformMatrix) {
             var subMeshes;
             var len;
+
             // Octrees
             if (this._submeshesOctree && this.useOctreeForCollisions) {
                 var radius = collider.velocityWorldLength + Math.max(collider.radius.x, collider.radius.y, collider.radius.z);
                 var intersections = this._submeshesOctree.intersects(collider.basePointWorld, radius);
+
                 len = intersections.length;
                 subMeshes = intersections.data;
-            }
-            else {
+            } else {
                 subMeshes = this.subMeshes;
                 len = subMeshes.length;
             }
+
             for (var index = 0; index < len; index++) {
                 var subMesh = subMeshes[index];
+
                 // Bounding test
                 if (len > 1 && !subMesh._checkCollision(collider))
                     continue;
+
                 this._collideForSubMesh(subMesh, transformMatrix, collider);
             }
         };
+
         AbstractMesh.prototype._checkCollision = function (collider) {
             // Bounding box test
             if (!this._boundingInfo._checkCollision(collider))
                 return;
+
             // Transformation matrix
             BABYLON.Matrix.ScalingToRef(1.0 / collider.radius.x, 1.0 / collider.radius.y, 1.0 / collider.radius.z, this._collisionsScalingMatrix);
             this.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix, this._collisionsTransformMatrix);
+
             this._processCollisionsForSubMeshes(collider, this._collisionsTransformMatrix);
         };
+
         // Picking
         AbstractMesh.prototype._generatePointsArray = function () {
             return false;
         };
+
         AbstractMesh.prototype.intersects = function (ray, fastCheck) {
             var pickingInfo = new BABYLON.PickingInfo();
+
             if (!this.subMeshes || !this._boundingInfo || !ray.intersectsSphere(this._boundingInfo.boundingSphere) || !ray.intersectsBox(this._boundingInfo.boundingBox)) {
                 return pickingInfo;
             }
+
             if (!this._generatePointsArray()) {
                 return pickingInfo;
             }
+
             var intersectInfo = null;
+
             // Octrees
             var subMeshes;
             var len;
+
             if (this._submeshesOctree && this.useOctreeForPicking) {
                 var worldRay = BABYLON.Ray.Transform(ray, this.getWorldMatrix());
                 var intersections = this._submeshesOctree.intersectsRay(worldRay);
+
                 len = intersections.length;
                 subMeshes = intersections.data;
-            }
-            else {
+            } else {
                 subMeshes = this.subMeshes;
                 len = subMeshes.length;
             }
+
             for (var index = 0; index < len; index++) {
                 var subMesh = subMeshes[index];
+
                 // Bounding test
                 if (len > 1 && !subMesh.canIntersects(ray))
                     continue;
+
                 var currentIntersectInfo = subMesh.intersects(ray, this._positions, this.getIndices(), fastCheck);
+
                 if (currentIntersectInfo) {
                     if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {
                         intersectInfo = currentIntersectInfo;
+
                         if (fastCheck) {
                             break;
                         }
                     }
                 }
             }
+
             if (intersectInfo) {
                 // Get picked point
                 var world = this.getWorldMatrix();
@@ -644,7 +783,9 @@ var BABYLON;
                 direction.normalize();
                 direction = direction.scale(intersectInfo.distance);
                 var worldDirection = BABYLON.Vector3.TransformNormal(direction, world);
+
                 var pickedPoint = worldOrigin.add(worldDirection);
+
                 // Return result
                 pickingInfo.hit = true;
                 pickingInfo.distance = BABYLON.Vector3.Distance(worldOrigin, pickedPoint);
@@ -655,40 +796,49 @@ var BABYLON;
                 pickingInfo.faceId = intersectInfo.faceId;
                 return pickingInfo;
             }
+
             return pickingInfo;
         };
+
         AbstractMesh.prototype.clone = function (name, newParent, doNotCloneChildren) {
             return null;
         };
+
         AbstractMesh.prototype.releaseSubMeshes = function () {
             if (this.subMeshes) {
                 while (this.subMeshes.length) {
                     this.subMeshes[0].dispose();
                 }
-            }
-            else {
+            } else {
                 this.subMeshes = new Array();
             }
         };
+
         AbstractMesh.prototype.dispose = function (doNotRecurse) {
             // Physics
             if (this.getPhysicsImpostor() != BABYLON.PhysicsEngine.NoImpostor) {
                 this.setPhysicsState(BABYLON.PhysicsEngine.NoImpostor);
             }
+
             for (index = 0; index < this._intersectionsInProgress.length; index++) {
                 var other = this._intersectionsInProgress[index];
+
                 var pos = other._intersectionsInProgress.indexOf(this);
                 other._intersectionsInProgress.splice(pos, 1);
             }
+
             this._intersectionsInProgress = [];
+
             // SubMeshes
             this.releaseSubMeshes();
+
             // Remove from scene
             var index = this.getScene().meshes.indexOf(this);
             if (index != -1) {
-                // Remove from the scene if mesh found 
+                // Remove from the scene if mesh found
                 this.getScene().meshes.splice(index, 1);
             }
+
             if (!doNotRecurse) {
                 for (index = 0; index < this.getScene().particleSystems.length; index++) {
                     if (this.getScene().particleSystems[index].emitter == this) {
@@ -696,6 +846,7 @@ var BABYLON;
                         index--;
                     }
                 }
+
                 // Children
                 var objects = this.getScene().meshes.slice(0);
                 for (index = 0; index < objects.length; index++) {
@@ -703,8 +854,7 @@ var BABYLON;
                         objects[index].dispose();
                     }
                 }
-            }
-            else {
+            } else {
                 for (index = 0; index < this.getScene().meshes.length; index++) {
                     var obj = this.getScene().meshes[index];
                     if (obj.parent === this) {
@@ -713,14 +863,16 @@ var BABYLON;
                     }
                 }
             }
+
             this._onAfterWorldMatrixUpdate = [];
+
             this._isDisposed = true;
+
             // Callback
             if (this.onDispose) {
                 this.onDispose();
             }
         };
-        // Statics
         AbstractMesh._BILLBOARDMODE_NONE = 0;
         AbstractMesh._BILLBOARDMODE_X = 1;
         AbstractMesh._BILLBOARDMODE_Y = 2;
@@ -730,4 +882,4 @@ var BABYLON;
     })(BABYLON.Node);
     BABYLON.AbstractMesh = AbstractMesh;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.abstractMesh.js.map
+//# sourceMappingURL=babylon.abstractMesh.js.map

+ 88 - 15
Babylon/Mesh/babylon.csg.js

@@ -1,7 +1,8 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     // Unique ID when we import meshes from Babylon to CSG
     var currentCSGMeshId = 0;
+
     // # class Vertex
     // Represents a vertex of a polygon. Use your own vertex class instead of this
     // one to provide additional features like texture coordinates and vertex
@@ -9,7 +10,7 @@ var BABYLON;
     // `flip()`, and `interpolate()` methods that behave analogous to the ones
     // defined by `BABYLON.CSG.Vertex`. This class provides `normal` so convenience
     // functions like `BABYLON.CSG.sphere()` can return a smooth vertex normal, but `normal`
-    // is not used anywhere else. 
+    // is not used anywhere else.
     // Same goes for uv, it allows to keep the original vertex uv coordinates of the 2 meshes
     var Vertex = (function () {
         function Vertex(pos, normal, uv) {
@@ -20,11 +21,13 @@ var BABYLON;
         Vertex.prototype.clone = function () {
             return new Vertex(this.pos.clone(), this.normal.clone(), this.uv.clone());
         };
+
         // Invert all orientation-specific data (e.g. vertex normal). Called when the
         // orientation of a polygon is flipped.
         Vertex.prototype.flip = function () {
             this.normal = this.normal.scale(-1);
         };
+
         // Create a new vertex between this vertex and `other` by linearly
         // interpolating all properties using a parameter of `t`. Subclasses should
         // override this to interpolate additional properties.
@@ -33,6 +36,7 @@ var BABYLON;
         };
         return Vertex;
     })();
+
     // # class Plane
     // Represents a plane in 3D space.
     var Plane = (function () {
@@ -43,19 +47,24 @@ var BABYLON;
         Plane.FromPoints = function (a, b, c) {
             var v0 = c.subtract(a);
             var v1 = b.subtract(a);
+
             if (v0.lengthSquared() === 0 || v1.lengthSquared() === 0) {
                 return null;
             }
+
             var n = BABYLON.Vector3.Normalize(BABYLON.Vector3.Cross(v0, v1));
             return new Plane(n, BABYLON.Vector3.Dot(n, a));
         };
+
         Plane.prototype.clone = function () {
             return new Plane(this.normal.clone(), this.w);
         };
+
         Plane.prototype.flip = function () {
             this.normal.scaleInPlace(-1);
             this.w = -this.w;
         };
+
         // Split `polygon` by this plane if needed, then put the polygon or polygon
         // fragments in the appropriate lists. Coplanar polygons go into either
         // `coplanarFront` or `coplanarBack` depending on their orientation with
@@ -66,6 +75,7 @@ var BABYLON;
             var FRONT = 1;
             var BACK = 2;
             var SPANNING = 3;
+
             // Classify each point as well as the entire polygon into one of the above
             // four classes.
             var polygonType = 0;
@@ -76,6 +86,7 @@ var BABYLON;
                 polygonType |= type;
                 types.push(type);
             }
+
             switch (polygonType) {
                 case COPLANAR:
                     (BABYLON.Vector3.Dot(this.normal, polygon.plane.normal) > 0 ? coplanarFront : coplanarBack).push(polygon);
@@ -105,26 +116,29 @@ var BABYLON;
                     }
                     if (f.length >= 3) {
                         var poly = new Polygon(f, polygon.shared);
+
                         if (poly.plane)
                             front.push(poly);
                     }
+
                     if (b.length >= 3) {
                         poly = new Polygon(b, polygon.shared);
+
                         if (poly.plane)
                             back.push(poly);
                     }
+
                     break;
             }
         };
-        // `BABYLON.CSG.Plane.EPSILON` is the tolerance used by `splitPolygon()` to decide if a
-        // point is on the plane.
         Plane.EPSILON = 1e-5;
         return Plane;
     })();
+
     // # class Polygon
     // Represents a convex polygon. The vertices used to initialize a polygon must
     // be coplanar and form a convex loop.
-    // 
+    //
     // Each convex polygon has a `shared` property, which is shared between all
     // polygons that are clones of each other or were split from the same polygon.
     // This can be used to define per-polygon properties (such as surface color).
@@ -135,9 +149,12 @@ var BABYLON;
             this.plane = Plane.FromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);
         }
         Polygon.prototype.clone = function () {
-            var vertices = this.vertices.map(function (v) { return v.clone(); });
+            var vertices = this.vertices.map(function (v) {
+                return v.clone();
+            });
             return new Polygon(vertices, this.shared);
         };
+
         Polygon.prototype.flip = function () {
             this.vertices.reverse().map(function (v) {
                 v.flip();
@@ -146,6 +163,7 @@ var BABYLON;
         };
         return Polygon;
     })();
+
     // # class Node
     // Holds a node in a BSP tree. A BSP tree is built from a collection of polygons
     // by picking a polygon to split along. That polygon (and all other coplanar
@@ -167,9 +185,12 @@ var BABYLON;
             node.plane = this.plane && this.plane.clone();
             node.front = this.front && this.front.clone();
             node.back = this.back && this.back.clone();
-            node.polygons = this.polygons.map(function (p) { return p.clone(); });
+            node.polygons = this.polygons.map(function (p) {
+                return p.clone();
+            });
             return node;
         };
+
         // Convert solid space to empty space and empty space to solid space.
         Node.prototype.invert = function () {
             for (var i = 0; i < this.polygons.length; i++) {
@@ -188,6 +209,7 @@ var BABYLON;
             this.front = this.back;
             this.back = temp;
         };
+
         // Recursively remove all polygons in `polygons` that are inside this BSP
         // tree.
         Node.prototype.clipPolygons = function (polygons) {
@@ -202,12 +224,12 @@ var BABYLON;
             }
             if (this.back) {
                 back = this.back.clipPolygons(back);
-            }
-            else {
+            } else {
                 back = [];
             }
             return front.concat(back);
         };
+
         // Remove all polygons in this BSP tree that are inside the other BSP tree
         // `bsp`.
         Node.prototype.clipTo = function (bsp) {
@@ -217,6 +239,7 @@ var BABYLON;
             if (this.back)
                 this.back.clipTo(bsp);
         };
+
         // Return a list of all polygons in this BSP tree.
         Node.prototype.allPolygons = function () {
             var polygons = this.polygons.slice();
@@ -226,6 +249,7 @@ var BABYLON;
                 polygons = polygons.concat(this.back.allPolygons());
             return polygons;
         };
+
         // Build a BSP tree out of `polygons`. When called on an existing tree, the
         // new polygons are filtered down to the bottom of the tree and become new
         // nodes there. Each set of polygons is partitioned using the first polygon
@@ -252,6 +276,7 @@ var BABYLON;
         };
         return Node;
     })();
+
     var CSG = (function () {
         function CSG() {
             this.polygons = new Array();
@@ -259,18 +284,21 @@ var BABYLON;
         // Convert BABYLON.Mesh to BABYLON.CSG
         CSG.FromMesh = function (mesh) {
             var vertex, normal, uv, position, polygon, polygons = [], vertices;
+
             if (mesh instanceof BABYLON.Mesh) {
                 mesh.computeWorldMatrix(true);
                 var matrix = mesh.getWorldMatrix();
                 var meshPosition = mesh.position.clone();
                 var meshRotation = mesh.rotation.clone();
                 var meshScaling = mesh.scaling.clone();
-            }
-            else {
+            } else {
                 throw 'BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh';
             }
+
             var indices = mesh.getIndices(), positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind), normals = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind), uvs = mesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
+
             var subMeshes = mesh.subMeshes;
+
             for (var sm = 0, sml = subMeshes.length; sm < sml; sm++) {
                 for (var i = subMeshes[sm].indexStart, il = subMeshes[sm].indexCount + subMeshes[sm].indexStart; i < il; i += 3) {
                     vertices = [];
@@ -280,39 +308,50 @@ var BABYLON;
                         var sourcePosition = new BABYLON.Vector3(positions[indices[i + j] * 3], positions[indices[i + j] * 3 + 1], positions[indices[i + j] * 3 + 2]);
                         position = BABYLON.Vector3.TransformCoordinates(sourcePosition, matrix);
                         normal = BABYLON.Vector3.TransformNormal(sourceNormal, matrix);
+
                         vertex = new Vertex(position, normal, uv);
                         vertices.push(vertex);
                     }
+
                     polygon = new Polygon(vertices, { subMeshId: sm, meshId: currentCSGMeshId, materialIndex: subMeshes[sm].materialIndex });
+
                     // To handle the case of degenerated triangle
                     // polygon.plane == null <=> the polygon does not represent 1 single plane <=> the triangle is degenerated
                     if (polygon.plane)
                         polygons.push(polygon);
                 }
             }
+
             var csg = CSG.FromPolygons(polygons);
             csg.matrix = matrix;
             csg.position = meshPosition;
             csg.rotation = meshRotation;
             csg.scaling = meshScaling;
             currentCSGMeshId++;
+
             return csg;
         };
+
         // Construct a BABYLON.CSG solid from a list of `BABYLON.CSG.Polygon` instances.
         CSG.FromPolygons = function (polygons) {
             var csg = new BABYLON.CSG();
             csg.polygons = polygons;
             return csg;
         };
+
         CSG.prototype.clone = function () {
             var csg = new BABYLON.CSG();
-            csg.polygons = this.polygons.map(function (p) { return p.clone(); });
+            csg.polygons = this.polygons.map(function (p) {
+                return p.clone();
+            });
             csg.copyTransformAttributes(this);
             return csg;
         };
+
         CSG.prototype.toPolygons = function () {
             return this.polygons;
         };
+
         CSG.prototype.union = function (csg) {
             var a = new Node(this.clone().polygons);
             var b = new Node(csg.clone().polygons);
@@ -324,17 +363,21 @@ var BABYLON;
             a.build(b.allPolygons());
             return CSG.FromPolygons(a.allPolygons()).copyTransformAttributes(this);
         };
+
         CSG.prototype.unionInPlace = function (csg) {
             var a = new Node(this.polygons);
             var b = new Node(csg.polygons);
+
             a.clipTo(b);
             b.clipTo(a);
             b.invert();
             b.clipTo(a);
             b.invert();
             a.build(b.allPolygons());
+
             this.polygons = a.allPolygons();
         };
+
         CSG.prototype.subtract = function (csg) {
             var a = new Node(this.clone().polygons);
             var b = new Node(csg.clone().polygons);
@@ -348,9 +391,11 @@ var BABYLON;
             a.invert();
             return CSG.FromPolygons(a.allPolygons()).copyTransformAttributes(this);
         };
+
         CSG.prototype.subtractInPlace = function (csg) {
             var a = new Node(this.polygons);
             var b = new Node(csg.polygons);
+
             a.invert();
             a.clipTo(b);
             b.clipTo(a);
@@ -359,8 +404,10 @@ var BABYLON;
             b.invert();
             a.build(b.allPolygons());
             a.invert();
+
             this.polygons = a.allPolygons();
         };
+
         CSG.prototype.intersect = function (csg) {
             var a = new Node(this.clone().polygons);
             var b = new Node(csg.clone().polygons);
@@ -373,9 +420,11 @@ var BABYLON;
             a.invert();
             return CSG.FromPolygons(a.allPolygons()).copyTransformAttributes(this);
         };
+
         CSG.prototype.intersectInPlace = function (csg) {
             var a = new Node(this.polygons);
             var b = new Node(csg.polygons);
+
             a.invert();
             b.clipTo(a);
             b.invert();
@@ -383,8 +432,10 @@ var BABYLON;
             b.clipTo(a);
             a.build(b.allPolygons());
             a.invert();
+
             this.polygons = a.allPolygons();
         };
+
         // Return a new BABYLON.CSG solid with solid and empty space switched. This solid is
         // not modified.
         CSG.prototype.inverse = function () {
@@ -392,11 +443,13 @@ var BABYLON;
             csg.inverseInPlace();
             return csg;
         };
+
         CSG.prototype.inverseInPlace = function () {
             this.polygons.map(function (p) {
                 p.flip();
             });
         };
+
         // This is used to keep meshes transformations so they can be restored
         // when we build back a Babylon Mesh
         // NB : All CSG operations are performed in world coordinates
@@ -405,27 +458,32 @@ var BABYLON;
             this.position = csg.position;
             this.rotation = csg.rotation;
             this.scaling = csg.scaling;
+
             return this;
         };
+
         // Build Raw mesh from CSG
         // Coordinates here are in world space
         CSG.prototype.buildMeshGeometry = function (name, scene, keepSubMeshes) {
             var matrix = this.matrix.clone();
             matrix.invert();
+
             var mesh = new BABYLON.Mesh(name, scene), vertices = [], indices = [], normals = [], uvs = [], vertex = BABYLON.Vector3.Zero(), normal = BABYLON.Vector3.Zero(), uv = BABYLON.Vector2.Zero(), polygons = this.polygons, polygonIndices = [0, 0, 0], polygon, vertice_dict = {}, vertex_idx, currentIndex = 0, subMesh_dict = {}, subMesh_obj;
+
             if (keepSubMeshes) {
                 // Sort Polygons, since subMeshes are indices range
                 polygons.sort(function (a, b) {
                     if (a.shared.meshId === b.shared.meshId) {
                         return a.shared.subMeshId - b.shared.subMeshId;
-                    }
-                    else {
+                    } else {
                         return a.shared.meshId - b.shared.meshId;
                     }
                 });
             }
+
             for (var i = 0, il = polygons.length; i < il; i++) {
                 polygon = polygons[i];
+
                 // Building SubMeshes
                 if (!subMesh_dict[polygon.shared.meshId]) {
                     subMesh_dict[polygon.shared.meshId] = {};
@@ -438,17 +496,21 @@ var BABYLON;
                     };
                 }
                 subMesh_obj = subMesh_dict[polygon.shared.meshId][polygon.shared.subMeshId];
+
                 for (var j = 2, jl = polygon.vertices.length; j < jl; j++) {
                     polygonIndices[0] = 0;
                     polygonIndices[1] = j - 1;
                     polygonIndices[2] = j;
+
                     for (var k = 0; k < 3; k++) {
                         vertex.copyFrom(polygon.vertices[polygonIndices[k]].pos);
                         normal.copyFrom(polygon.vertices[polygonIndices[k]].normal);
                         uv.copyFrom(polygon.vertices[polygonIndices[k]].uv);
                         var localVertex = BABYLON.Vector3.TransformCoordinates(vertex, matrix);
                         var localNormal = BABYLON.Vector3.TransformNormal(normal, matrix);
+
                         vertex_idx = vertice_dict[localVertex.x + ',' + localVertex.y + ',' + localVertex.z];
+
                         // Check if 2 points can be merged
                         if (!(typeof vertex_idx !== 'undefined' && normals[vertex_idx * 3] === localNormal.x && normals[vertex_idx * 3 + 1] === localNormal.y && normals[vertex_idx * 3 + 2] === localNormal.z && uvs[vertex_idx * 2] === uv.x && uvs[vertex_idx * 2 + 1] === uv.y)) {
                             vertices.push(localVertex.x, localVertex.y, localVertex.z);
@@ -456,21 +518,27 @@ var BABYLON;
                             normals.push(normal.x, normal.y, normal.z);
                             vertex_idx = vertice_dict[localVertex.x + ',' + localVertex.y + ',' + localVertex.z] = (vertices.length / 3) - 1;
                         }
+
                         indices.push(vertex_idx);
+
                         subMesh_obj.indexStart = Math.min(currentIndex, subMesh_obj.indexStart);
                         subMesh_obj.indexEnd = Math.max(currentIndex, subMesh_obj.indexEnd);
                         currentIndex++;
                     }
                 }
             }
+
             mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, vertices);
             mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals);
             mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
             mesh.setIndices(indices);
+
             if (keepSubMeshes) {
                 // We offset the materialIndex by the previous number of materials in the CSG mixed meshes
                 var materialIndexOffset = 0, materialMaxIndex;
+
                 mesh.subMeshes.length = 0;
+
                 for (var m in subMesh_dict) {
                     materialMaxIndex = -1;
                     for (var sm in subMesh_dict[m]) {
@@ -481,20 +549,25 @@ var BABYLON;
                     materialIndexOffset += ++materialMaxIndex;
                 }
             }
+
             return mesh;
         };
+
         // Build Mesh from CSG taking material and transforms into account
         CSG.prototype.toMesh = function (name, material, scene, keepSubMeshes) {
             var mesh = this.buildMeshGeometry(name, scene, keepSubMeshes);
+
             mesh.material = material;
+
             mesh.position.copyFrom(this.position);
             mesh.rotation.copyFrom(this.rotation);
             mesh.scaling.copyFrom(this.scaling);
             mesh.computeWorldMatrix(true);
+
             return mesh;
         };
         return CSG;
     })();
     BABYLON.CSG = CSG;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.csg.js.map
+//# sourceMappingURL=babylon.csg.js.map

+ 133 - 14
Babylon/Mesh/babylon.geometry.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -15,14 +15,15 @@ var BABYLON;
             this._engine = scene.getEngine();
             this._meshes = [];
             this._scene = scene;
+
             // vertexData
             if (vertexData) {
                 this.setAllVerticesData(vertexData, updatable);
-            }
-            else {
+            } else {
                 this._totalVertices = 0;
                 this._indices = [];
             }
+
             // applyToMesh
             if (mesh) {
                 this.applyToMesh(mesh);
@@ -31,27 +32,38 @@ var BABYLON;
         Geometry.prototype.getScene = function () {
             return this._scene;
         };
+
         Geometry.prototype.getEngine = function () {
             return this._engine;
         };
+
         Geometry.prototype.isReady = function () {
             return this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADED || this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NONE;
         };
+
         Geometry.prototype.setAllVerticesData = function (vertexData, updatable) {
             vertexData.applyToGeometry(this, updatable);
         };
+
         Geometry.prototype.setVerticesData = function (kind, data, updatable, stride) {
             this._vertexBuffers = this._vertexBuffers || {};
+
             if (this._vertexBuffers[kind]) {
                 this._vertexBuffers[kind].dispose();
             }
+
             this._vertexBuffers[kind] = new BABYLON.VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0, stride);
+
             if (kind === BABYLON.VertexBuffer.PositionKind) {
                 stride = this._vertexBuffers[kind].getStrideSize();
+
                 this._totalVertices = data.length / stride;
+
                 var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
+
                 var meshes = this._meshes;
                 var numOfMeshes = meshes.length;
+
                 for (var index = 0; index < numOfMeshes; index++) {
                     var mesh = meshes[index];
                     mesh._resetPointsArrayCache();
@@ -61,28 +73,39 @@ var BABYLON;
                 }
             }
         };
+
         Geometry.prototype.updateVerticesDataDirectly = function (kind, data, offset) {
             var vertexBuffer = this.getVertexBuffer(kind);
+
             if (!vertexBuffer) {
                 return;
             }
+
             vertexBuffer.updateDirectly(data, offset);
         };
+
         Geometry.prototype.updateVerticesData = function (kind, data, updateExtends) {
             var vertexBuffer = this.getVertexBuffer(kind);
+
             if (!vertexBuffer) {
                 return;
             }
+
             vertexBuffer.update(data);
+
             if (kind === BABYLON.VertexBuffer.PositionKind) {
                 var extend;
+
                 var stride = vertexBuffer.getStrideSize();
                 this._totalVertices = data.length / stride;
+
                 if (updateExtends) {
                     extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
                 }
+
                 var meshes = this._meshes;
                 var numOfMeshes = meshes.length;
+
                 for (var index = 0; index < numOfMeshes; index++) {
                     var mesh = meshes[index];
                     mesh._resetPointsArrayCache();
@@ -92,12 +115,15 @@ var BABYLON;
                 }
             }
         };
+
         Geometry.prototype.getTotalVertices = function () {
             if (!this.isReady()) {
                 return 0;
             }
+
             return this._totalVertices;
         };
+
         Geometry.prototype.getVerticesData = function (kind) {
             var vertexBuffer = this.getVertexBuffer(kind);
             if (!vertexBuffer) {
@@ -105,18 +131,21 @@ var BABYLON;
             }
             return vertexBuffer.getData();
         };
+
         Geometry.prototype.getVertexBuffer = function (kind) {
             if (!this.isReady()) {
                 return null;
             }
             return this._vertexBuffers[kind];
         };
+
         Geometry.prototype.getVertexBuffers = function () {
             if (!this.isReady()) {
                 return null;
             }
             return this._vertexBuffers;
         };
+
         Geometry.prototype.isVerticesDataPresent = function (kind) {
             if (!this._vertexBuffers) {
                 if (this._delayInfo) {
@@ -126,109 +155,138 @@ var BABYLON;
             }
             return this._vertexBuffers[kind] !== undefined;
         };
+
         Geometry.prototype.getVerticesDataKinds = function () {
             var result = [];
             if (!this._vertexBuffers && this._delayInfo) {
                 for (var kind in this._delayInfo) {
                     result.push(kind);
                 }
-            }
-            else {
+            } else {
                 for (kind in this._vertexBuffers) {
                     result.push(kind);
                 }
             }
+
             return result;
         };
+
         Geometry.prototype.setIndices = function (indices, totalVertices) {
             if (this._indexBuffer) {
                 this._engine._releaseBuffer(this._indexBuffer);
             }
+
             this._indices = indices;
             if (this._meshes.length !== 0 && this._indices) {
                 this._indexBuffer = this._engine.createIndexBuffer(this._indices);
             }
+
             if (totalVertices !== undefined) {
                 this._totalVertices = totalVertices;
             }
+
             var meshes = this._meshes;
             var numOfMeshes = meshes.length;
+
             for (var index = 0; index < numOfMeshes; index++) {
                 meshes[index]._createGlobalSubMesh();
             }
         };
+
         Geometry.prototype.getTotalIndices = function () {
             if (!this.isReady()) {
                 return 0;
             }
             return this._indices.length;
         };
+
         Geometry.prototype.getIndices = function () {
             if (!this.isReady()) {
                 return null;
             }
             return this._indices;
         };
+
         Geometry.prototype.getIndexBuffer = function () {
             if (!this.isReady()) {
                 return null;
             }
             return this._indexBuffer;
         };
+
         Geometry.prototype.releaseForMesh = function (mesh, shouldDispose) {
             var meshes = this._meshes;
             var index = meshes.indexOf(mesh);
+
             if (index === -1) {
                 return;
             }
+
             for (var kind in this._vertexBuffers) {
                 this._vertexBuffers[kind].dispose();
             }
+
             if (this._indexBuffer && this._engine._releaseBuffer(this._indexBuffer)) {
                 this._indexBuffer = null;
             }
+
             meshes.splice(index, 1);
+
             mesh._geometry = null;
+
             if (meshes.length === 0 && shouldDispose) {
                 this.dispose();
             }
         };
+
         Geometry.prototype.applyToMesh = function (mesh) {
             if (mesh._geometry === this) {
                 return;
             }
+
             var previousGeometry = mesh._geometry;
             if (previousGeometry) {
                 previousGeometry.releaseForMesh(mesh);
             }
+
             var meshes = this._meshes;
+
             // must be done before setting vertexBuffers because of mesh._createGlobalSubMesh()
             mesh._geometry = this;
+
             this._scene.pushGeometry(this);
+
             meshes.push(mesh);
+
             if (this.isReady()) {
                 this._applyToMesh(mesh);
-            }
-            else {
+            } else {
                 mesh._boundingInfo = this._boundingInfo;
             }
         };
+
         Geometry.prototype._applyToMesh = function (mesh) {
             var numOfMeshes = this._meshes.length;
+
             for (var kind in this._vertexBuffers) {
                 if (numOfMeshes === 1) {
                     this._vertexBuffers[kind].create();
                 }
                 this._vertexBuffers[kind]._buffer.references = numOfMeshes;
+
                 if (kind === BABYLON.VertexBuffer.PositionKind) {
                     mesh._resetPointsArrayCache();
+
                     var extend = BABYLON.Tools.ExtractMinAndMax(this._vertexBuffers[kind].getData(), 0, this._totalVertices);
                     mesh._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
+
                     mesh._createGlobalSubMesh();
+
                     //bounding info was just created again, world matrix should be applied again.
                     mesh._updateBoundingInfo();
                 }
             }
+
             // indexBuffer
             if (numOfMeshes === 1 && this._indices) {
                 this._indexBuffer = this._engine.createIndexBuffer(this._indices);
@@ -237,35 +295,44 @@ var BABYLON;
                 this._indexBuffer.references = numOfMeshes;
             }
         };
+
         Geometry.prototype.load = function (scene, onLoaded) {
             var _this = this;
             if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
                 return;
             }
+
             if (this.isReady()) {
                 if (onLoaded) {
                     onLoaded();
                 }
                 return;
             }
+
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADING;
+
             scene._addPendingData(this);
             BABYLON.Tools.LoadFile(this.delayLoadingFile, function (data) {
                 _this._delayLoadingFunction(JSON.parse(data), _this);
+
                 _this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
                 _this._delayInfo = [];
+
                 scene._removePendingData(_this);
+
                 var meshes = _this._meshes;
                 var numOfMeshes = meshes.length;
                 for (var index = 0; index < numOfMeshes; index++) {
                     _this._applyToMesh(meshes[index]);
                 }
+
                 if (onLoaded) {
                     onLoaded();
                 }
             }, function () {
             }, scene.database);
         };
+
         Geometry.prototype.dispose = function () {
             var meshes = this._meshes;
             var numOfMeshes = meshes.length;
@@ -274,64 +341,85 @@ var BABYLON;
                 this.releaseForMesh(meshes[index]);
             }
             this._meshes = [];
+
             for (var kind in this._vertexBuffers) {
                 this._vertexBuffers[kind].dispose();
             }
             this._vertexBuffers = [];
             this._totalVertices = 0;
+
             if (this._indexBuffer) {
                 this._engine._releaseBuffer(this._indexBuffer);
             }
             this._indexBuffer = null;
             this._indices = [];
+
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
             this.delayLoadingFile = null;
             this._delayLoadingFunction = null;
             this._delayInfo = [];
+
             this._boundingInfo = null; // todo: .dispose()
+
             var geometries = this._scene.getGeometries();
             index = geometries.indexOf(this);
+
             if (index > -1) {
                 geometries.splice(index, 1);
             }
         };
+
         Geometry.prototype.copy = function (id) {
             var vertexData = new BABYLON.VertexData();
+
             vertexData.indices = [];
+
             var indices = this.getIndices();
             for (var index = 0; index < indices.length; index++) {
                 vertexData.indices.push(indices[index]);
             }
+
             var updatable = false;
             var stopChecking = false;
+
             for (var kind in this._vertexBuffers) {
                 vertexData.set(this.getVerticesData(kind), kind);
+
                 if (!stopChecking) {
                     updatable = this.getVertexBuffer(kind).isUpdatable();
                     stopChecking = !updatable;
                 }
             }
+
             var geometry = new Geometry(id, this._scene, vertexData, updatable, null);
+
             geometry.delayLoadState = this.delayLoadState;
             geometry.delayLoadingFile = this.delayLoadingFile;
             geometry._delayLoadingFunction = this._delayLoadingFunction;
+
             for (kind in this._delayInfo) {
                 geometry._delayInfo = geometry._delayInfo || [];
                 geometry._delayInfo.push(kind);
             }
+
             // Bounding info
             var extend = BABYLON.Tools.ExtractMinAndMax(this.getVerticesData(BABYLON.VertexBuffer.PositionKind), 0, this.getTotalVertices());
             geometry._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
+
             return geometry;
         };
+
         // Statics
         Geometry.ExtractFromMesh = function (mesh, id) {
             var geometry = mesh._geometry;
+
             if (!geometry) {
                 return null;
             }
+
             return geometry.copy(id);
         };
+
         // from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523
         // be aware Math.random() could cause collisions
         Geometry.RandomId = function () {
@@ -343,10 +431,9 @@ var BABYLON;
         return Geometry;
     })();
     BABYLON.Geometry = Geometry;
-    /////// Primitives //////////////////////////////////////////////
-    var Geometry;
+
     (function (Geometry) {
-        var Primitives;
+        /////// Primitives //////////////////////////////////////////////
         (function (Primitives) {
             /// Abstract class
             var _Primitive = (function (_super) {
@@ -360,6 +447,7 @@ var BABYLON;
                 _Primitive.prototype.canBeRegenerated = function () {
                     return this._canBeRegenerated;
                 };
+
                 _Primitive.prototype.regenerate = function () {
                     if (!this._canBeRegenerated) {
                         return;
@@ -368,9 +456,11 @@ var BABYLON;
                     this.setAllVerticesData(this._regenerateVertexData(), false);
                     this._beingRegenerated = false;
                 };
+
                 _Primitive.prototype.asNewGeometry = function (id) {
                     return _super.prototype.copy.call(this, id);
                 };
+
                 // overrides
                 _Primitive.prototype.setAllVerticesData = function (vertexData, updatable) {
                     if (!this._beingRegenerated) {
@@ -378,108 +468,127 @@ var BABYLON;
                     }
                     _super.prototype.setAllVerticesData.call(this, vertexData, false);
                 };
+
                 _Primitive.prototype.setVerticesData = function (kind, data, updatable) {
                     if (!this._beingRegenerated) {
                         return;
                     }
                     _super.prototype.setVerticesData.call(this, kind, data, false);
                 };
+
                 // to override
                 // protected
                 _Primitive.prototype._regenerateVertexData = function () {
                     throw new Error("Abstract method");
                 };
+
                 _Primitive.prototype.copy = function (id) {
                     throw new Error("Must be overriden in sub-classes.");
                 };
                 return _Primitive;
             })(Geometry);
             Primitives._Primitive = _Primitive;
+
             var Box = (function (_super) {
                 __extends(Box, _super);
                 function Box(id, scene, size, canBeRegenerated, mesh) {
                     this.size = size;
+
                     _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
                 }
                 Box.prototype._regenerateVertexData = function () {
                     return BABYLON.VertexData.CreateBox(this.size);
                 };
+
                 Box.prototype.copy = function (id) {
                     return new Box(id, this.getScene(), this.size, this.canBeRegenerated(), null);
                 };
                 return Box;
             })(_Primitive);
             Primitives.Box = Box;
+
             var Sphere = (function (_super) {
                 __extends(Sphere, _super);
                 function Sphere(id, scene, segments, diameter, canBeRegenerated, mesh) {
                     this.segments = segments;
                     this.diameter = diameter;
+
                     _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
                 }
                 Sphere.prototype._regenerateVertexData = function () {
                     return BABYLON.VertexData.CreateSphere(this.segments, this.diameter);
                 };
+
                 Sphere.prototype.copy = function (id) {
                     return new Sphere(id, this.getScene(), this.segments, this.diameter, this.canBeRegenerated(), null);
                 };
                 return Sphere;
             })(_Primitive);
             Primitives.Sphere = Sphere;
+
             var Cylinder = (function (_super) {
                 __extends(Cylinder, _super);
                 function Cylinder(id, scene, height, diameterTop, diameterBottom, tessellation, subdivisions, canBeRegenerated, mesh) {
-                    if (subdivisions === void 0) { subdivisions = 1; }
+                    if (typeof subdivisions === "undefined") { subdivisions = 1; }
                     this.height = height;
                     this.diameterTop = diameterTop;
                     this.diameterBottom = diameterBottom;
                     this.tessellation = tessellation;
                     this.subdivisions = subdivisions;
+
                     _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
                 }
                 Cylinder.prototype._regenerateVertexData = function () {
                     return BABYLON.VertexData.CreateCylinder(this.height, this.diameterTop, this.diameterBottom, this.tessellation, this.subdivisions);
                 };
+
                 Cylinder.prototype.copy = function (id) {
                     return new Cylinder(id, this.getScene(), this.height, this.diameterTop, this.diameterBottom, this.tessellation, this.subdivisions, this.canBeRegenerated(), null);
                 };
                 return Cylinder;
             })(_Primitive);
             Primitives.Cylinder = Cylinder;
+
             var Torus = (function (_super) {
                 __extends(Torus, _super);
                 function Torus(id, scene, diameter, thickness, tessellation, canBeRegenerated, mesh) {
                     this.diameter = diameter;
                     this.thickness = thickness;
                     this.tessellation = tessellation;
+
                     _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
                 }
                 Torus.prototype._regenerateVertexData = function () {
                     return BABYLON.VertexData.CreateTorus(this.diameter, this.thickness, this.tessellation);
                 };
+
                 Torus.prototype.copy = function (id) {
                     return new Torus(id, this.getScene(), this.diameter, this.thickness, this.tessellation, this.canBeRegenerated(), null);
                 };
                 return Torus;
             })(_Primitive);
             Primitives.Torus = Torus;
+
             var Ground = (function (_super) {
                 __extends(Ground, _super);
                 function Ground(id, scene, width, height, subdivisions, canBeRegenerated, mesh) {
                     this.width = width;
                     this.height = height;
                     this.subdivisions = subdivisions;
+
                     _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
                 }
                 Ground.prototype._regenerateVertexData = function () {
                     return BABYLON.VertexData.CreateGround(this.width, this.height, this.subdivisions);
                 };
+
                 Ground.prototype.copy = function (id) {
                     return new Ground(id, this.getScene(), this.width, this.height, this.subdivisions, this.canBeRegenerated(), null);
                 };
                 return Ground;
             })(_Primitive);
             Primitives.Ground = Ground;
+
             var TiledGround = (function (_super) {
                 __extends(TiledGround, _super);
                 function TiledGround(id, scene, xmin, zmin, xmax, zmax, subdivisions, precision, canBeRegenerated, mesh) {
@@ -489,32 +598,38 @@ var BABYLON;
                     this.zmax = zmax;
                     this.subdivisions = subdivisions;
                     this.precision = precision;
+
                     _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
                 }
                 TiledGround.prototype._regenerateVertexData = function () {
                     return BABYLON.VertexData.CreateTiledGround(this.xmin, this.zmin, this.xmax, this.zmax, this.subdivisions, this.precision);
                 };
+
                 TiledGround.prototype.copy = function (id) {
                     return new TiledGround(id, this.getScene(), this.xmin, this.zmin, this.xmax, this.zmax, this.subdivisions, this.precision, this.canBeRegenerated(), null);
                 };
                 return TiledGround;
             })(_Primitive);
             Primitives.TiledGround = TiledGround;
+
             var Plane = (function (_super) {
                 __extends(Plane, _super);
                 function Plane(id, scene, size, canBeRegenerated, mesh) {
                     this.size = size;
+
                     _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
                 }
                 Plane.prototype._regenerateVertexData = function () {
                     return BABYLON.VertexData.CreatePlane(this.size);
                 };
+
                 Plane.prototype.copy = function (id) {
                     return new Plane(id, this.getScene(), this.size, this.canBeRegenerated(), null);
                 };
                 return Plane;
             })(_Primitive);
             Primitives.Plane = Plane;
+
             var TorusKnot = (function (_super) {
                 __extends(TorusKnot, _super);
                 function TorusKnot(id, scene, radius, tube, radialSegments, tubularSegments, p, q, canBeRegenerated, mesh) {
@@ -524,18 +639,22 @@ var BABYLON;
                     this.tubularSegments = tubularSegments;
                     this.p = p;
                     this.q = q;
+
                     _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
                 }
                 TorusKnot.prototype._regenerateVertexData = function () {
                     return BABYLON.VertexData.CreateTorusKnot(this.radius, this.tube, this.radialSegments, this.tubularSegments, this.p, this.q);
                 };
+
                 TorusKnot.prototype.copy = function (id) {
                     return new TorusKnot(id, this.getScene(), this.radius, this.tube, this.radialSegments, this.tubularSegments, this.p, this.q, this.canBeRegenerated(), null);
                 };
                 return TorusKnot;
             })(_Primitive);
             Primitives.TorusKnot = TorusKnot;
-        })(Primitives = Geometry.Primitives || (Geometry.Primitives = {}));
-    })(Geometry = BABYLON.Geometry || (BABYLON.Geometry = {}));
+        })(Geometry.Primitives || (Geometry.Primitives = {}));
+        var Primitives = Geometry.Primitives;
+    })(BABYLON.Geometry || (BABYLON.Geometry = {}));
+    var Geometry = BABYLON.Geometry;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.geometry.js.map
+//# sourceMappingURL=babylon.geometry.js.map

+ 9 - 2
Babylon/Mesh/babylon.groundMesh.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -20,22 +20,29 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         GroundMesh.prototype.optimize = function (chunksCount) {
             this.subdivide(this._subdivisions);
             this.createOrUpdateSubmeshesOctree(32);
         };
+
         GroundMesh.prototype.getHeightAtCoordinates = function (x, z) {
             var ray = new BABYLON.Ray(new BABYLON.Vector3(x, this.getBoundingInfo().boundingBox.maximumWorld.y + 1, z), new BABYLON.Vector3(0, -1, 0));
+
             this.getWorldMatrix().invertToRef(this._worldInverse);
+
             ray = BABYLON.Ray.Transform(ray, this._worldInverse);
+
             var pickInfo = this.intersects(ray);
+
             if (pickInfo.hit) {
                 return pickInfo.pickedPoint.y;
             }
+
             return 0;
         };
         return GroundMesh;
     })(BABYLON.Mesh);
     BABYLON.GroundMesh = GroundMesh;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.groundMesh.js.map
+//# sourceMappingURL=babylon.groundMesh.js.map

+ 16 - 3
Babylon/Mesh/babylon.linesMesh.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -9,11 +9,12 @@ var BABYLON;
     var LinesMesh = (function (_super) {
         __extends(LinesMesh, _super);
         function LinesMesh(name, scene, updatable) {
-            if (updatable === void 0) { updatable = false; }
+            if (typeof updatable === "undefined") { updatable = false; }
             _super.call(this, name, scene);
             this.color = new BABYLON.Color3(1, 1, 1);
             this.alpha = 1;
             this._indices = new Array();
+
             this._colorShader = new BABYLON.ShaderMaterial("colorShader", scene, "color", {
                 attributes: ["position"],
                 uniforms: ["worldViewProjection", "color"],
@@ -27,6 +28,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(LinesMesh.prototype, "isPickable", {
             get: function () {
                 return false;
@@ -34,6 +36,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(LinesMesh.prototype, "checkCollisions", {
             get: function () {
                 return false;
@@ -41,31 +44,41 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         LinesMesh.prototype._bind = function (subMesh, effect, fillMode) {
             var engine = this.getScene().getEngine();
+
             var indexToBind = this._geometry.getIndexBuffer();
+
             // VBOs
             engine.bindBuffers(this._geometry.getVertexBuffer(BABYLON.VertexBuffer.PositionKind).getBuffer(), indexToBind, [3], 3 * 4, this._colorShader.getEffect());
+
             // Color
             this._colorShader.setColor4("color", this.color.toColor4(this.alpha));
         };
+
         LinesMesh.prototype._draw = function (subMesh, fillMode, instancesCount) {
             if (!this._geometry || !this._geometry.getVertexBuffers() || !this._geometry.getIndexBuffer()) {
                 return;
             }
+
             var engine = this.getScene().getEngine();
+
             // Draw order
             engine.draw(false, subMesh.indexStart, subMesh.indexCount);
         };
+
         LinesMesh.prototype.intersects = function (ray, fastCheck) {
             return null;
         };
+
         LinesMesh.prototype.dispose = function (doNotRecurse) {
             this._colorShader.dispose();
+
             _super.prototype.dispose.call(this, doNotRecurse);
         };
         return LinesMesh;
     })(BABYLON.Mesh);
     BABYLON.LinesMesh = LinesMesh;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.linesMesh.js.map
+//# sourceMappingURL=babylon.linesMesh.js.map

Plik diff jest za duży
+ 289 - 39
Babylon/Mesh/babylon.mesh.js


+ 201 - 7
Babylon/Mesh/babylon.mesh.vertexData.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var VertexData = (function () {
         function VertexData() {
@@ -28,86 +28,113 @@ var BABYLON;
                     break;
             }
         };
+
         VertexData.prototype.applyToMesh = function (mesh, updatable) {
             this._applyTo(mesh, updatable);
         };
+
         VertexData.prototype.applyToGeometry = function (geometry, updatable) {
             this._applyTo(geometry, updatable);
         };
+
         VertexData.prototype.updateMesh = function (mesh, updateExtends, makeItUnique) {
             this._update(mesh);
         };
+
         VertexData.prototype.updateGeometry = function (geometry, updateExtends, makeItUnique) {
             this._update(geometry);
         };
+
         VertexData.prototype._applyTo = function (meshOrGeometry, updatable) {
             if (this.positions) {
                 meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.PositionKind, this.positions, updatable);
             }
+
             if (this.normals) {
                 meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.NormalKind, this.normals, updatable);
             }
+
             if (this.uvs) {
                 meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.UVKind, this.uvs, updatable);
             }
+
             if (this.uv2s) {
                 meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.UV2Kind, this.uv2s, updatable);
             }
+
             if (this.colors) {
                 meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.ColorKind, this.colors, updatable);
             }
+
             if (this.matricesIndices) {
                 meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, this.matricesIndices, updatable);
             }
+
             if (this.matricesWeights) {
                 meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, this.matricesWeights, updatable);
             }
+
             if (this.indices) {
                 meshOrGeometry.setIndices(this.indices);
             }
         };
+
         VertexData.prototype._update = function (meshOrGeometry, updateExtends, makeItUnique) {
             if (this.positions) {
                 meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.PositionKind, this.positions, updateExtends, makeItUnique);
             }
+
             if (this.normals) {
                 meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.NormalKind, this.normals, updateExtends, makeItUnique);
             }
+
             if (this.uvs) {
                 meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.UVKind, this.uvs, updateExtends, makeItUnique);
             }
+
             if (this.uv2s) {
                 meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.UV2Kind, this.uv2s, updateExtends, makeItUnique);
             }
+
             if (this.colors) {
                 meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.ColorKind, this.colors, updateExtends, makeItUnique);
             }
+
             if (this.matricesIndices) {
                 meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, this.matricesIndices, updateExtends, makeItUnique);
             }
+
             if (this.matricesWeights) {
                 meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, this.matricesWeights, updateExtends, makeItUnique);
             }
+
             if (this.indices) {
                 meshOrGeometry.setIndices(this.indices);
             }
         };
+
         VertexData.prototype.transform = function (matrix) {
             var transformed = BABYLON.Vector3.Zero();
+
             if (this.positions) {
                 var position = BABYLON.Vector3.Zero();
+
                 for (var index = 0; index < this.positions.length; index += 3) {
                     BABYLON.Vector3.FromArrayToRef(this.positions, index, position);
+
                     BABYLON.Vector3.TransformCoordinatesToRef(position, matrix, transformed);
                     this.positions[index] = transformed.x;
                     this.positions[index + 1] = transformed.y;
                     this.positions[index + 2] = transformed.z;
                 }
             }
+
             if (this.normals) {
                 var normal = BABYLON.Vector3.Zero();
+
                 for (index = 0; index < this.normals.length; index += 3) {
                     BABYLON.Vector3.FromArrayToRef(this.normals, index, normal);
+
                     BABYLON.Vector3.TransformNormalToRef(normal, matrix, transformed);
                     this.normals[index] = transformed.x;
                     this.normals[index + 1] = transformed.y;
@@ -115,24 +142,29 @@ var BABYLON;
                 }
             }
         };
+
         VertexData.prototype.merge = function (other) {
             if (other.indices) {
                 if (!this.indices) {
                     this.indices = [];
                 }
+
                 var offset = this.positions ? this.positions.length / 3 : 0;
                 for (var index = 0; index < other.indices.length; index++) {
                     this.indices.push(other.indices[index] + offset);
                 }
             }
+
             if (other.positions) {
                 if (!this.positions) {
                     this.positions = [];
                 }
+
                 for (index = 0; index < other.positions.length; index++) {
                     this.positions.push(other.positions[index]);
                 }
             }
+
             if (other.normals) {
                 if (!this.normals) {
                     this.normals = [];
@@ -141,6 +173,7 @@ var BABYLON;
                     this.normals.push(other.normals[index]);
                 }
             }
+
             if (other.uvs) {
                 if (!this.uvs) {
                     this.uvs = [];
@@ -149,6 +182,7 @@ var BABYLON;
                     this.uvs.push(other.uvs[index]);
                 }
             }
+
             if (other.uv2s) {
                 if (!this.uv2s) {
                     this.uv2s = [];
@@ -157,6 +191,7 @@ var BABYLON;
                     this.uv2s.push(other.uv2s[index]);
                 }
             }
+
             if (other.matricesIndices) {
                 if (!this.matricesIndices) {
                     this.matricesIndices = [];
@@ -165,6 +200,7 @@ var BABYLON;
                     this.matricesIndices.push(other.matricesIndices[index]);
                 }
             }
+
             if (other.matricesWeights) {
                 if (!this.matricesWeights) {
                     this.matricesWeights = [];
@@ -173,6 +209,7 @@ var BABYLON;
                     this.matricesWeights.push(other.matricesWeights[index]);
                 }
             }
+
             if (other.colors) {
                 if (!this.colors) {
                     this.colors = [];
@@ -182,39 +219,52 @@ var BABYLON;
                 }
             }
         };
+
         // Statics
         VertexData.ExtractFromMesh = function (mesh) {
             return VertexData._ExtractFrom(mesh);
         };
+
         VertexData.ExtractFromGeometry = function (geometry) {
             return VertexData._ExtractFrom(geometry);
         };
+
         VertexData._ExtractFrom = function (meshOrGeometry) {
             var result = new BABYLON.VertexData();
+
             if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
                 result.positions = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.PositionKind);
             }
+
             if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
                 result.normals = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.NormalKind);
             }
+
             if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
                 result.uvs = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.UVKind);
             }
+
             if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
                 result.uv2s = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.UV2Kind);
             }
+
             if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
                 result.colors = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.ColorKind);
             }
+
             if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind)) {
                 result.matricesIndices = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
             }
+
             if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
                 result.matricesWeights = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
             }
+
             result.indices = meshOrGeometry.getIndices();
+
             return result;
         };
+
         VertexData.CreateBox = function (size) {
             var normalsSource = [
                 new BABYLON.Vector3(0, 0, 1),
@@ -224,309 +274,396 @@ var BABYLON;
                 new BABYLON.Vector3(0, 1, 0),
                 new BABYLON.Vector3(0, -1, 0)
             ];
+
             var indices = [];
             var positions = [];
             var normals = [];
             var uvs = [];
+
             size = size || 1;
+
             for (var index = 0; index < normalsSource.length; index++) {
                 var normal = normalsSource[index];
+
                 // Get two vectors perpendicular to the face normal and to each other.
                 var side1 = new BABYLON.Vector3(normal.y, normal.z, normal.x);
                 var side2 = BABYLON.Vector3.Cross(normal, side1);
+
                 // Six indices (two triangles) per face.
                 var verticesLength = positions.length / 3;
                 indices.push(verticesLength);
                 indices.push(verticesLength + 1);
                 indices.push(verticesLength + 2);
+
                 indices.push(verticesLength);
                 indices.push(verticesLength + 2);
                 indices.push(verticesLength + 3);
+
                 // Four vertices per face.
                 var vertex = normal.subtract(side1).subtract(side2).scale(size / 2);
                 positions.push(vertex.x, vertex.y, vertex.z);
                 normals.push(normal.x, normal.y, normal.z);
                 uvs.push(1.0, 1.0);
+
                 vertex = normal.subtract(side1).add(side2).scale(size / 2);
                 positions.push(vertex.x, vertex.y, vertex.z);
                 normals.push(normal.x, normal.y, normal.z);
                 uvs.push(0.0, 1.0);
+
                 vertex = normal.add(side1).add(side2).scale(size / 2);
                 positions.push(vertex.x, vertex.y, vertex.z);
                 normals.push(normal.x, normal.y, normal.z);
                 uvs.push(0.0, 0.0);
+
                 vertex = normal.add(side1).subtract(side2).scale(size / 2);
                 positions.push(vertex.x, vertex.y, vertex.z);
                 normals.push(normal.x, normal.y, normal.z);
                 uvs.push(1.0, 0.0);
             }
+
             // Result
             var vertexData = new BABYLON.VertexData();
+
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
             vertexData.uvs = uvs;
+
             return vertexData;
         };
+
         VertexData.CreateSphere = function (segments, diameter) {
             segments = segments || 32;
             diameter = diameter || 1;
+
             var radius = diameter / 2;
+
             var totalZRotationSteps = 2 + segments;
             var totalYRotationSteps = 2 * totalZRotationSteps;
+
             var indices = [];
             var positions = [];
             var normals = [];
             var uvs = [];
+
             for (var zRotationStep = 0; zRotationStep <= totalZRotationSteps; zRotationStep++) {
                 var normalizedZ = zRotationStep / totalZRotationSteps;
                 var angleZ = (normalizedZ * Math.PI);
+
                 for (var yRotationStep = 0; yRotationStep <= totalYRotationSteps; yRotationStep++) {
                     var normalizedY = yRotationStep / totalYRotationSteps;
+
                     var angleY = normalizedY * Math.PI * 2;
+
                     var rotationZ = BABYLON.Matrix.RotationZ(-angleZ);
                     var rotationY = BABYLON.Matrix.RotationY(angleY);
                     var afterRotZ = BABYLON.Vector3.TransformCoordinates(BABYLON.Vector3.Up(), rotationZ);
                     var complete = BABYLON.Vector3.TransformCoordinates(afterRotZ, rotationY);
+
                     var vertex = complete.scale(radius);
                     var normal = BABYLON.Vector3.Normalize(vertex);
+
                     positions.push(vertex.x, vertex.y, vertex.z);
                     normals.push(normal.x, normal.y, normal.z);
                     uvs.push(normalizedZ, normalizedY);
                 }
+
                 if (zRotationStep > 0) {
                     var verticesCount = positions.length / 3;
                     for (var firstIndex = verticesCount - 2 * (totalYRotationSteps + 1); (firstIndex + totalYRotationSteps + 2) < verticesCount; firstIndex++) {
                         indices.push((firstIndex));
                         indices.push((firstIndex + 1));
                         indices.push(firstIndex + totalYRotationSteps + 1);
+
                         indices.push((firstIndex + totalYRotationSteps + 1));
                         indices.push((firstIndex + 1));
                         indices.push((firstIndex + totalYRotationSteps + 2));
                     }
                 }
             }
+
             // Result
             var vertexData = new BABYLON.VertexData();
+
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
             vertexData.uvs = uvs;
+
             return vertexData;
         };
+
         VertexData.CreateCylinder = function (height, diameterTop, diameterBottom, tessellation, subdivisions) {
-            if (subdivisions === void 0) { subdivisions = 1; }
+            if (typeof subdivisions === "undefined") { subdivisions = 1; }
             var radiusTop = diameterTop / 2;
             var radiusBottom = diameterBottom / 2;
             var indices = [];
             var positions = [];
             var normals = [];
             var uvs = [];
+
             height = height || 1;
             diameterTop = diameterTop || 0.5;
             diameterBottom = diameterBottom || 1;
             tessellation = tessellation || 16;
             subdivisions = subdivisions || 1;
             subdivisions = (subdivisions < 1) ? 1 : subdivisions;
+
             var getCircleVector = function (i) {
                 var angle = (i * 2.0 * Math.PI / tessellation);
                 var dx = Math.cos(angle);
                 var dz = Math.sin(angle);
+
                 return new BABYLON.Vector3(dx, 0, dz);
             };
+
             var createCylinderCap = function (isTop) {
                 var radius = isTop ? radiusTop : radiusBottom;
+
                 if (radius == 0) {
                     return;
                 }
                 var vbase = positions.length / 3;
+
                 var offset = new BABYLON.Vector3(0, height / 2, 0);
                 var textureScale = new BABYLON.Vector2(0.5, 0.5);
+
                 if (!isTop) {
                     offset.scaleInPlace(-1);
                     textureScale.x = -textureScale.x;
                 }
+
                 for (i = 0; i < tessellation; i++) {
                     var circleVector = getCircleVector(i);
                     var position = circleVector.scale(radius).add(offset);
                     var textureCoordinate = new BABYLON.Vector2(circleVector.x * textureScale.x + 0.5, circleVector.z * textureScale.y + 0.5);
+
                     positions.push(position.x, position.y, position.z);
                     uvs.push(textureCoordinate.x, textureCoordinate.y);
                 }
+
                 for (var i = 0; i < tessellation - 2; i++) {
                     if (!isTop) {
                         indices.push(vbase);
                         indices.push(vbase + (i + 2) % tessellation);
                         indices.push(vbase + (i + 1) % tessellation);
-                    }
-                    else {
+                    } else {
                         indices.push(vbase);
                         indices.push(vbase + (i + 1) % tessellation);
                         indices.push(vbase + (i + 2) % tessellation);
                     }
                 }
             };
+
             var base = new BABYLON.Vector3(0, -1, 0).scale(height / 2);
             var offset = new BABYLON.Vector3(0, 1, 0).scale(height / subdivisions);
             var stride = tessellation + 1;
+
             for (var i = 0; i <= tessellation; i++) {
                 var circleVector = getCircleVector(i);
                 var textureCoordinate = new BABYLON.Vector2(i / tessellation, 0);
                 var position, radius = radiusBottom;
+
                 for (var s = 0; s <= subdivisions; s++) {
                     // Update variables
                     position = circleVector.scale(radius);
                     position.addInPlace(base.add(offset.scale(s)));
                     textureCoordinate.y += 1 / subdivisions;
                     radius += (radiusTop - radiusBottom) / subdivisions;
+
                     // Push in arrays
                     positions.push(position.x, position.y, position.z);
                     uvs.push(textureCoordinate.x, textureCoordinate.y);
                 }
             }
+
             subdivisions += 1;
+
             for (var s = 0; s < subdivisions - 1; s++) {
                 for (var i = 0; i <= tessellation; i++) {
                     indices.push(i * subdivisions + s);
                     indices.push((i * subdivisions + (s + subdivisions)) % (stride * subdivisions));
                     indices.push(i * subdivisions + (s + 1));
+
                     indices.push(i * subdivisions + (s + 1));
                     indices.push((i * subdivisions + (s + subdivisions)) % (stride * subdivisions));
                     indices.push((i * subdivisions + (s + subdivisions + 1)) % (stride * subdivisions));
                 }
             }
+
             // Create flat triangle fan caps to seal the top and bottom.
             createCylinderCap(true);
             createCylinderCap(false);
+
             // Normals
             BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+
             // Result
             var vertexData = new BABYLON.VertexData();
+
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
             vertexData.uvs = uvs;
+
             return vertexData;
         };
+
         VertexData.CreateTorus = function (diameter, thickness, tessellation) {
             var indices = [];
             var positions = [];
             var normals = [];
             var uvs = [];
+
             diameter = diameter || 1;
             thickness = thickness || 0.5;
             tessellation = tessellation || 16;
+
             var stride = tessellation + 1;
+
             for (var i = 0; i <= tessellation; i++) {
                 var u = i / tessellation;
+
                 var outerAngle = i * Math.PI * 2.0 / tessellation - Math.PI / 2.0;
+
                 var transform = BABYLON.Matrix.Translation(diameter / 2.0, 0, 0).multiply(BABYLON.Matrix.RotationY(outerAngle));
+
                 for (var j = 0; j <= tessellation; j++) {
                     var v = 1 - j / tessellation;
+
                     var innerAngle = j * Math.PI * 2.0 / tessellation + Math.PI;
                     var dx = Math.cos(innerAngle);
                     var dy = Math.sin(innerAngle);
+
                     // Create a vertex.
                     var normal = new BABYLON.Vector3(dx, dy, 0);
                     var position = normal.scale(thickness / 2);
                     var textureCoordinate = new BABYLON.Vector2(u, v);
+
                     position = BABYLON.Vector3.TransformCoordinates(position, transform);
                     normal = BABYLON.Vector3.TransformNormal(normal, transform);
+
                     positions.push(position.x, position.y, position.z);
                     normals.push(normal.x, normal.y, normal.z);
                     uvs.push(textureCoordinate.x, textureCoordinate.y);
+
                     // And create indices for two triangles.
                     var nextI = (i + 1) % stride;
                     var nextJ = (j + 1) % stride;
+
                     indices.push(i * stride + j);
                     indices.push(i * stride + nextJ);
                     indices.push(nextI * stride + j);
+
                     indices.push(i * stride + nextJ);
                     indices.push(nextI * stride + nextJ);
                     indices.push(nextI * stride + j);
                 }
             }
+
             // Result
             var vertexData = new BABYLON.VertexData();
+
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
             vertexData.uvs = uvs;
+
             return vertexData;
         };
+
         VertexData.CreateLines = function (points) {
             var indices = [];
             var positions = [];
+
             for (var index = 0; index < points.length; index++) {
                 positions.push(points[index].x, points[index].y, points[index].z);
+
                 if (index > 0) {
                     indices.push(index - 1);
                     indices.push(index);
                 }
             }
+
             // Result
             var vertexData = new BABYLON.VertexData();
+
             vertexData.indices = indices;
             vertexData.positions = positions;
+
             return vertexData;
         };
+
         VertexData.CreateGround = function (width, height, subdivisions) {
             var indices = [];
             var positions = [];
             var normals = [];
             var uvs = [];
             var row, col;
+
             width = width || 1;
             height = height || 1;
             subdivisions = subdivisions || 1;
+
             for (row = 0; row <= subdivisions; row++) {
                 for (col = 0; col <= subdivisions; col++) {
                     var position = new BABYLON.Vector3((col * width) / subdivisions - (width / 2.0), 0, ((subdivisions - row) * height) / subdivisions - (height / 2.0));
                     var normal = new BABYLON.Vector3(0, 1.0, 0);
+
                     positions.push(position.x, position.y, position.z);
                     normals.push(normal.x, normal.y, normal.z);
                     uvs.push(col / subdivisions, 1.0 - row / subdivisions);
                 }
             }
+
             for (row = 0; row < subdivisions; row++) {
                 for (col = 0; col < subdivisions; col++) {
                     indices.push(col + 1 + (row + 1) * (subdivisions + 1));
                     indices.push(col + 1 + row * (subdivisions + 1));
                     indices.push(col + row * (subdivisions + 1));
+
                     indices.push(col + (row + 1) * (subdivisions + 1));
                     indices.push(col + 1 + (row + 1) * (subdivisions + 1));
                     indices.push(col + row * (subdivisions + 1));
                 }
             }
+
             // Result
             var vertexData = new BABYLON.VertexData();
+
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
             vertexData.uvs = uvs;
+
             return vertexData;
         };
+
         VertexData.CreateTiledGround = function (xmin, zmin, xmax, zmax, subdivisions, precision) {
-            if (subdivisions === void 0) { subdivisions = { w: 1, h: 1 }; }
-            if (precision === void 0) { precision = { w: 1, h: 1 }; }
+            if (typeof subdivisions === "undefined") { subdivisions = { w: 1, h: 1 }; }
+            if (typeof precision === "undefined") { precision = { w: 1, h: 1 }; }
             var indices = [];
             var positions = [];
             var normals = [];
             var uvs = [];
             var row, col, tileRow, tileCol;
+
             subdivisions.h = (subdivisions.w < 1) ? 1 : subdivisions.h;
             subdivisions.w = (subdivisions.w < 1) ? 1 : subdivisions.w;
             precision.w = (precision.w < 1) ? 1 : precision.w;
             precision.h = (precision.h < 1) ? 1 : precision.h;
+
             var tileSize = {
                 'w': (xmax - xmin) / subdivisions.w,
                 'h': (zmax - zmin) / subdivisions.h
             };
+
             for (tileRow = 0; tileRow < subdivisions.h; tileRow++) {
                 for (tileCol = 0; tileCol < subdivisions.w; tileCol++) {
                     applyTile(xmin + tileCol * tileSize.w, zmin + tileRow * tileSize.h, xmin + (tileCol + 1) * tileSize.w, zmin + (tileRow + 1) * tileSize.h);
                 }
             }
+
             function applyTile(xTileMin, zTileMin, xTileMax, zTileMax) {
                 // Indices
                 var base = positions.length / 3;
@@ -539,6 +676,7 @@ var BABYLON;
                             base + (col + 1) + (row + 1) * rowLength,
                             base + col + (row + 1) * rowLength
                         ];
+
                         indices.push(square[1]);
                         indices.push(square[2]);
                         indices.push(square[3]);
@@ -547,6 +685,7 @@ var BABYLON;
                         indices.push(square[3]);
                     }
                 }
+
                 // Position, normals and uvs
                 var position = BABYLON.Vector3.Zero();
                 var normal = new BABYLON.Vector3(0, 1.0, 0);
@@ -555,122 +694,156 @@ var BABYLON;
                     for (col = 0; col <= precision.w; col++) {
                         position.x = (col * (xTileMax - xTileMin)) / precision.w + xTileMin;
                         position.y = 0;
+
                         positions.push(position.x, position.y, position.z);
                         normals.push(normal.x, normal.y, normal.z);
                         uvs.push(col / precision.w, row / precision.h);
                     }
                 }
             }
+
             // Result
             var vertexData = new BABYLON.VertexData();
+
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
             vertexData.uvs = uvs;
+
             return vertexData;
         };
+
         VertexData.CreateGroundFromHeightMap = function (width, height, subdivisions, minHeight, maxHeight, buffer, bufferWidth, bufferHeight) {
             var indices = [];
             var positions = [];
             var normals = [];
             var uvs = [];
             var row, col;
+
             for (row = 0; row <= subdivisions; row++) {
                 for (col = 0; col <= subdivisions; col++) {
                     var position = new BABYLON.Vector3((col * width) / subdivisions - (width / 2.0), 0, ((subdivisions - row) * height) / subdivisions - (height / 2.0));
+
                     // Compute height
                     var heightMapX = (((position.x + width / 2) / width) * (bufferWidth - 1)) | 0;
                     var heightMapY = ((1.0 - (position.z + height / 2) / height) * (bufferHeight - 1)) | 0;
+
                     var pos = (heightMapX + heightMapY * bufferWidth) * 4;
                     var r = buffer[pos] / 255.0;
                     var g = buffer[pos + 1] / 255.0;
                     var b = buffer[pos + 2] / 255.0;
+
                     var gradient = r * 0.3 + g * 0.59 + b * 0.11;
+
                     position.y = minHeight + (maxHeight - minHeight) * gradient;
+
                     // Add  vertex
                     positions.push(position.x, position.y, position.z);
                     normals.push(0, 0, 0);
                     uvs.push(col / subdivisions, 1.0 - row / subdivisions);
                 }
             }
+
             for (row = 0; row < subdivisions; row++) {
                 for (col = 0; col < subdivisions; col++) {
                     indices.push(col + 1 + (row + 1) * (subdivisions + 1));
                     indices.push(col + 1 + row * (subdivisions + 1));
                     indices.push(col + row * (subdivisions + 1));
+
                     indices.push(col + (row + 1) * (subdivisions + 1));
                     indices.push(col + 1 + (row + 1) * (subdivisions + 1));
                     indices.push(col + row * (subdivisions + 1));
                 }
             }
+
             // Normals
             BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+
             // Result
             var vertexData = new BABYLON.VertexData();
+
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
             vertexData.uvs = uvs;
+
             return vertexData;
         };
+
         VertexData.CreatePlane = function (size) {
             var indices = [];
             var positions = [];
             var normals = [];
             var uvs = [];
+
             size = size || 1;
+
             // Vertices
             var halfSize = size / 2.0;
             positions.push(-halfSize, -halfSize, 0);
             normals.push(0, 0, -1.0);
             uvs.push(0.0, 0.0);
+
             positions.push(halfSize, -halfSize, 0);
             normals.push(0, 0, -1.0);
             uvs.push(1.0, 0.0);
+
             positions.push(halfSize, halfSize, 0);
             normals.push(0, 0, -1.0);
             uvs.push(1.0, 1.0);
+
             positions.push(-halfSize, halfSize, 0);
             normals.push(0, 0, -1.0);
             uvs.push(0.0, 1.0);
+
             // Indices
             indices.push(0);
             indices.push(1);
             indices.push(2);
+
             indices.push(0);
             indices.push(2);
             indices.push(3);
+
             // Result
             var vertexData = new BABYLON.VertexData();
+
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
             vertexData.uvs = uvs;
+
             return vertexData;
         };
+
         // based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
         VertexData.CreateTorusKnot = function (radius, tube, radialSegments, tubularSegments, p, q) {
             var indices = [];
             var positions = [];
             var normals = [];
             var uvs = [];
+
             radius = radius || 2;
             tube = tube || 0.5;
             radialSegments = radialSegments || 32;
             tubularSegments = tubularSegments || 32;
             p = p || 2;
             q = q || 3;
+
             // Helper
             var getPos = function (angle) {
                 var cu = Math.cos(angle);
                 var su = Math.sin(angle);
                 var quOverP = q / p * angle;
                 var cs = Math.cos(quOverP);
+
                 var tx = radius * (2 + cs) * 0.5 * cu;
                 var ty = radius * (2 + cs) * su * 0.5;
                 var tz = radius * Math.sin(quOverP) * 0.5;
+
                 return new BABYLON.Vector3(tx, ty, tz);
             };
+
             for (var i = 0; i <= radialSegments; i++) {
                 var modI = i % radialSegments;
                 var u = modI / radialSegments * 2 * p * Math.PI;
@@ -678,22 +851,28 @@ var BABYLON;
                 var p2 = getPos(u + 0.01);
                 var tang = p2.subtract(p1);
                 var n = p2.add(p1);
+
                 var bitan = BABYLON.Vector3.Cross(tang, n);
                 n = BABYLON.Vector3.Cross(bitan, tang);
+
                 bitan.normalize();
                 n.normalize();
+
                 for (var j = 0; j < tubularSegments; j++) {
                     var modJ = j % tubularSegments;
                     var v = modJ / tubularSegments * 2 * Math.PI;
                     var cx = -tube * Math.cos(v);
                     var cy = tube * Math.sin(v);
+
                     positions.push(p1.x + cx * n.x + cy * bitan.x);
                     positions.push(p1.y + cx * n.y + cy * bitan.y);
                     positions.push(p1.z + cx * n.z + cy * bitan.z);
+
                     uvs.push(i / radialSegments);
                     uvs.push(j / tubularSegments);
                 }
             }
+
             for (i = 0; i < radialSegments; i++) {
                 for (j = 0; j < tubularSegments; j++) {
                     var jNext = (j + 1) % tubularSegments;
@@ -701,6 +880,7 @@ var BABYLON;
                     var b = (i + 1) * tubularSegments + j;
                     var c = (i + 1) * tubularSegments + jNext;
                     var d = i * tubularSegments + jNext;
+
                     indices.push(d);
                     indices.push(b);
                     indices.push(a);
@@ -709,49 +889,63 @@ var BABYLON;
                     indices.push(b);
                 }
             }
+
             // Normals
             BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+
             // Result
             var vertexData = new BABYLON.VertexData();
+
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
             vertexData.uvs = uvs;
+
             return vertexData;
         };
+
         // Tools
         VertexData.ComputeNormals = function (positions, indices, normals) {
             var positionVectors = [];
             var facesOfVertices = [];
             var index;
+
             for (index = 0; index < positions.length; index += 3) {
                 var vector3 = new BABYLON.Vector3(positions[index], positions[index + 1], positions[index + 2]);
                 positionVectors.push(vector3);
                 facesOfVertices.push([]);
             }
+
             // Compute normals
             var facesNormals = [];
             for (index = 0; index < indices.length / 3; index++) {
                 var i1 = indices[index * 3];
                 var i2 = indices[index * 3 + 1];
                 var i3 = indices[index * 3 + 2];
+
                 var p1 = positionVectors[i1];
                 var p2 = positionVectors[i2];
                 var p3 = positionVectors[i3];
+
                 var p1p2 = p1.subtract(p2);
                 var p3p2 = p3.subtract(p2);
+
                 facesNormals[index] = BABYLON.Vector3.Normalize(BABYLON.Vector3.Cross(p1p2, p3p2));
                 facesOfVertices[i1].push(index);
                 facesOfVertices[i2].push(index);
                 facesOfVertices[i3].push(index);
             }
+
             for (index = 0; index < positionVectors.length; index++) {
                 var faces = facesOfVertices[index];
+
                 var normal = BABYLON.Vector3.Zero();
                 for (var faceIndex = 0; faceIndex < faces.length; faceIndex++) {
                     normal.addInPlace(facesNormals[faces[faceIndex]]);
                 }
+
                 normal = BABYLON.Vector3.Normalize(normal.scale(1.0 / faces.length));
+
                 normals[index * 3] = normal.x;
                 normals[index * 3 + 1] = normal.y;
                 normals[index * 3 + 2] = normal.z;
@@ -761,4 +955,4 @@ var BABYLON;
     })();
     BABYLON.VertexData = VertexData;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.mesh.vertexData.js.map
+//# sourceMappingURL=babylon.mesh.vertexData.js.map

+ 4 - 4
Babylon/Mesh/babylon.meshLODLevel.js

@@ -1,6 +1,5 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
-    var Internals;
     (function (Internals) {
         var MeshLODLevel = (function () {
             function MeshLODLevel(distance, mesh) {
@@ -10,6 +9,7 @@ var BABYLON;
             return MeshLODLevel;
         })();
         Internals.MeshLODLevel = MeshLODLevel;
-    })(Internals = BABYLON.Internals || (BABYLON.Internals = {}));
+    })(BABYLON.Internals || (BABYLON.Internals = {}));
+    var Internals = BABYLON.Internals;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.meshLODLevel.js.map
+//# sourceMappingURL=babylon.meshLODLevel.js.map

+ 1 - 1
Babylon/Mesh/babylon.meshSimplification.ts

@@ -552,7 +552,7 @@
                 + 2 * q.data[5] * y * z + 2 * q.data[6] * y + q.data[7] * z * z + 2 * q.data[8] * z + q.data[9];
         }
 
-        private calculateError(vertex1: DecimationVertex, vertex2: DecimationVertex, pointResult?: Vector3, normalResult?: Vector3, uvResult?: Vector2, colorResult?:Color4): number {
+        private calculateError(vertex1: DecimationVertex, vertex2: DecimationVertex, pointResult?: Vector3, normalResult?: Vector3, uvResult?: Vector2, colorResult?: Color4): number {
             var q = vertex1.q.add(vertex2.q);
             var border = vertex1.isBorder && vertex2.isBorder;
             var error: number = 0;

+ 36 - 13
Babylon/Mesh/babylon.polygonmesh.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -14,6 +14,7 @@ var BABYLON;
         }
         return IndexedVector2;
     })(BABYLON.Vector2);
+
     var PolygonPoints = (function () {
         function PolygonPoints() {
             this.elements = new Array();
@@ -28,27 +29,30 @@ var BABYLON;
                     _this.elements.push(newPoint);
                 }
             });
+
             return result;
         };
+
         PolygonPoints.prototype.computeBounds = function () {
             var lmin = new BABYLON.Vector2(this.elements[0].x, this.elements[0].y);
             var lmax = new BABYLON.Vector2(this.elements[0].x, this.elements[0].y);
+
             this.elements.forEach(function (point) {
                 // x
                 if (point.x < lmin.x) {
                     lmin.x = point.x;
-                }
-                else if (point.x > lmax.x) {
+                } else if (point.x > lmax.x) {
                     lmax.x = point.x;
                 }
+
                 // y
                 if (point.y < lmin.y) {
                     lmin.y = point.y;
-                }
-                else if (point.y > lmax.y) {
+                } else if (point.y > lmax.y) {
                     lmax.y = point.y;
                 }
             });
+
             return {
                 min: lmin,
                 max: lmax,
@@ -58,6 +62,7 @@ var BABYLON;
         };
         return PolygonPoints;
     })();
+
     var Polygon = (function () {
         function Polygon() {
         }
@@ -69,81 +74,99 @@ var BABYLON;
                 new BABYLON.Vector2(xmin, ymax)
             ];
         };
+
         Polygon.Circle = function (radius, cx, cy, numberOfSides) {
-            if (cx === void 0) { cx = 0; }
-            if (cy === void 0) { cy = 0; }
-            if (numberOfSides === void 0) { numberOfSides = 32; }
+            if (typeof cx === "undefined") { cx = 0; }
+            if (typeof cy === "undefined") { cy = 0; }
+            if (typeof numberOfSides === "undefined") { numberOfSides = 32; }
             var result = new Array();
+
             var angle = 0;
             var increment = (Math.PI * 2) / numberOfSides;
+
             for (var i = 0; i < numberOfSides; i++) {
                 result.push(new BABYLON.Vector2(cx + Math.cos(angle) * radius, cy + Math.sin(angle) * radius));
                 angle -= increment;
             }
+
             return result;
         };
+
         Polygon.Parse = function (input) {
-            var floats = input.split(/[^-+eE\.\d]+/).map(parseFloat).filter(function (val) { return (!isNaN(val)); });
+            var floats = input.split(/[^-+eE\.\d]+/).map(parseFloat).filter(function (val) {
+                return (!isNaN(val));
+            });
             var i, result = [];
             for (i = 0; i < (floats.length & 0x7FFFFFFE); i += 2) {
                 result.push(new poly2tri.Point(floats[i], floats[i + 1]));
             }
             return result;
         };
+
         Polygon.StartingAt = function (x, y) {
             return BABYLON.Path2.StartingAt(x, y);
         };
         return Polygon;
     })();
     BABYLON.Polygon = Polygon;
+
     var PolygonMeshBuilder = (function () {
         function PolygonMeshBuilder(name, contours, scene) {
             this._points = new PolygonPoints();
             if (!("poly2tri" in window)) {
                 throw "PolygonMeshBuilder cannot be used because poly2tri is not referenced";
             }
+
             this._name = name;
             this._scene = scene;
+
             var points;
             if (contours instanceof BABYLON.Path2) {
                 points = contours.getPoints();
-            }
-            else {
+            } else {
                 points = contours;
             }
+
             this._swctx = new poly2tri.SweepContext(this._points.add(points));
         }
         PolygonMeshBuilder.prototype.addHole = function (hole) {
             this._swctx.addHole(this._points.add(hole));
             return this;
         };
+
         PolygonMeshBuilder.prototype.build = function (updatable) {
-            if (updatable === void 0) { updatable = false; }
+            if (typeof updatable === "undefined") { updatable = false; }
             var result = new BABYLON.Mesh(this._name, this._scene);
+
             var normals = [];
             var positions = [];
             var uvs = [];
+
             var bounds = this._points.computeBounds();
             this._points.elements.forEach(function (p) {
                 normals.push(0, 1.0, 0);
                 positions.push(p.x, 0, p.y);
                 uvs.push((p.x - bounds.min.x) / bounds.width, (p.y - bounds.min.y) / bounds.height);
             });
+
             var indices = [];
+
             this._swctx.triangulate();
             this._swctx.getTriangles().forEach(function (triangle) {
                 triangle.getPoints().forEach(function (point) {
                     indices.push(point.index);
                 });
             });
+
             result.setVerticesData(positions, BABYLON.VertexBuffer.PositionKind, updatable);
             result.setVerticesData(normals, BABYLON.VertexBuffer.NormalKind, updatable);
             result.setVerticesData(uvs, BABYLON.VertexBuffer.UVKind, updatable);
             result.setIndices(indices);
+
             return result;
         };
         return PolygonMeshBuilder;
     })();
     BABYLON.PolygonMeshBuilder = PolygonMeshBuilder;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.polygonMesh.js.map
+//# sourceMappingURL=babylon.polygonMesh.js.map

+ 42 - 6
Babylon/Mesh/babylon.subMesh.js

@@ -1,8 +1,8 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var SubMesh = (function () {
         function SubMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh, renderingMesh, createBoundingBox) {
-            if (createBoundingBox === void 0) { createBoundingBox = true; }
+            if (typeof createBoundingBox === "undefined") { createBoundingBox = true; }
             this.materialIndex = materialIndex;
             this.verticesStart = verticesStart;
             this.verticesCount = verticesCount;
@@ -12,7 +12,9 @@ var BABYLON;
             this._mesh = mesh;
             this._renderingMesh = renderingMesh || mesh;
             mesh.subMeshes.push(this);
+
             this._id = mesh.subMeshes.length - 1;
+
             if (createBoundingBox) {
                 this.refreshBoundingInfo();
             }
@@ -20,124 +22,158 @@ var BABYLON;
         SubMesh.prototype.getBoundingInfo = function () {
             return this._boundingInfo;
         };
+
         SubMesh.prototype.getMesh = function () {
             return this._mesh;
         };
+
         SubMesh.prototype.getRenderingMesh = function () {
             return this._renderingMesh;
         };
+
         SubMesh.prototype.getMaterial = function () {
             var rootMaterial = this._renderingMesh.material;
+
             if (rootMaterial && rootMaterial instanceof BABYLON.MultiMaterial) {
                 var multiMaterial = rootMaterial;
                 return multiMaterial.getSubMaterial(this.materialIndex);
             }
+
             if (!rootMaterial) {
                 return this._mesh.getScene().defaultMaterial;
             }
+
             return rootMaterial;
         };
+
         // Methods
         SubMesh.prototype.refreshBoundingInfo = function () {
             var data = this._renderingMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
+
             if (!data) {
                 this._boundingInfo = this._mesh._boundingInfo;
                 return;
             }
+
             var indices = this._renderingMesh.getIndices();
             var extend;
+
             if (this.indexStart === 0 && this.indexCount === indices.length) {
                 extend = BABYLON.Tools.ExtractMinAndMax(data, this.verticesStart, this.verticesCount);
-            }
-            else {
+            } else {
                 extend = BABYLON.Tools.ExtractMinAndMaxIndexed(data, indices, this.indexStart, this.indexCount);
             }
             this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
         };
+
         SubMesh.prototype._checkCollision = function (collider) {
             return this._boundingInfo._checkCollision(collider);
         };
+
         SubMesh.prototype.updateBoundingInfo = function (world) {
             if (!this._boundingInfo) {
                 this.refreshBoundingInfo();
             }
             this._boundingInfo._update(world);
         };
+
         SubMesh.prototype.isInFrustum = function (frustumPlanes) {
             return this._boundingInfo.isInFrustum(frustumPlanes);
         };
+
         SubMesh.prototype.render = function () {
             this._renderingMesh.render(this);
         };
+
         SubMesh.prototype.getLinesIndexBuffer = function (indices, engine) {
             if (!this._linesIndexBuffer) {
                 var linesIndices = [];
+
                 for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 3) {
                     linesIndices.push(indices[index], indices[index + 1], indices[index + 1], indices[index + 2], indices[index + 2], indices[index]);
                 }
+
                 this._linesIndexBuffer = engine.createIndexBuffer(linesIndices);
                 this.linesIndexCount = linesIndices.length;
             }
             return this._linesIndexBuffer;
         };
+
         SubMesh.prototype.canIntersects = function (ray) {
             return ray.intersectsBox(this._boundingInfo.boundingBox);
         };
+
         SubMesh.prototype.intersects = function (ray, positions, indices, fastCheck) {
             var intersectInfo = null;
+
             for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 3) {
                 var p0 = positions[indices[index]];
                 var p1 = positions[indices[index + 1]];
                 var p2 = positions[indices[index + 2]];
+
                 var currentIntersectInfo = ray.intersectsTriangle(p0, p1, p2);
+
                 if (currentIntersectInfo) {
                     if (currentIntersectInfo.distance < 0) {
                         continue;
                     }
+
                     if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {
                         intersectInfo = currentIntersectInfo;
                         intersectInfo.faceId = index / 3;
+
                         if (fastCheck) {
                             break;
                         }
                     }
                 }
             }
+
             return intersectInfo;
         };
-        // Clone    
+
+        // Clone
         SubMesh.prototype.clone = function (newMesh, newRenderingMesh) {
             var result = new SubMesh(this.materialIndex, this.verticesStart, this.verticesCount, this.indexStart, this.indexCount, newMesh, newRenderingMesh, false);
+
             result._boundingInfo = new BABYLON.BoundingInfo(this._boundingInfo.minimum, this._boundingInfo.maximum);
+
             return result;
         };
+
         // Dispose
         SubMesh.prototype.dispose = function () {
             if (this._linesIndexBuffer) {
                 this._mesh.getScene().getEngine()._releaseBuffer(this._linesIndexBuffer);
                 this._linesIndexBuffer = null;
             }
+
             // Remove from mesh
             var index = this._mesh.subMeshes.indexOf(this);
             this._mesh.subMeshes.splice(index, 1);
         };
+
         // Statics
         SubMesh.CreateFromIndices = function (materialIndex, startIndex, indexCount, mesh, renderingMesh) {
             var minVertexIndex = Number.MAX_VALUE;
             var maxVertexIndex = -Number.MAX_VALUE;
+
             renderingMesh = renderingMesh || mesh;
             var indices = renderingMesh.getIndices();
+
             for (var index = startIndex; index < startIndex + indexCount; index++) {
                 var vertexIndex = indices[index];
+
                 if (vertexIndex < minVertexIndex)
                     minVertexIndex = vertexIndex;
                 if (vertexIndex > maxVertexIndex)
                     maxVertexIndex = vertexIndex;
             }
+
             return new BABYLON.SubMesh(materialIndex, minVertexIndex, maxVertexIndex - minVertexIndex + 1, startIndex, indexCount, mesh, renderingMesh);
         };
         return SubMesh;
     })();
     BABYLON.SubMesh = SubMesh;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.subMesh.js.map
+//# sourceMappingURL=babylon.subMesh.js.map

+ 29 - 8
Babylon/Mesh/babylon.vertexBuffer.js

@@ -1,23 +1,28 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var VertexBuffer = (function () {
         function VertexBuffer(engine, data, kind, updatable, postponeInternalCreation, stride) {
             if (engine instanceof BABYLON.Mesh) {
                 this._engine = engine.getScene().getEngine();
-            }
-            else {
+            } else {
                 this._engine = engine;
             }
+
             this._updatable = updatable;
+
             this._data = data;
+
             if (!postponeInternalCreation) {
                 this.create();
             }
+
             this._kind = kind;
+
             if (stride) {
                 this._strideSize = stride;
                 return;
             }
+
             switch (kind) {
                 case VertexBuffer.PositionKind:
                     this._strideSize = 3;
@@ -46,46 +51,56 @@ var BABYLON;
         VertexBuffer.prototype.isUpdatable = function () {
             return this._updatable;
         };
+
         VertexBuffer.prototype.getData = function () {
             return this._data;
         };
+
         VertexBuffer.prototype.getBuffer = function () {
             return this._buffer;
         };
+
         VertexBuffer.prototype.getStrideSize = function () {
             return this._strideSize;
         };
+
         // Methods
         VertexBuffer.prototype.create = function (data) {
             if (!data && this._buffer) {
-                return; // nothing to do
+                return;
             }
+
             data = data || this._data;
+
             if (!this._buffer) {
                 if (this._updatable) {
                     this._buffer = this._engine.createDynamicVertexBuffer(data.length * 4);
-                }
-                else {
+                } else {
                     this._buffer = this._engine.createVertexBuffer(data);
                 }
             }
+
             if (this._updatable) {
                 this._engine.updateDynamicVertexBuffer(this._buffer, data);
                 this._data = data;
             }
         };
+
         VertexBuffer.prototype.update = function (data) {
             this.create(data);
         };
+
         VertexBuffer.prototype.updateDirectly = function (data, offset) {
             if (!this._buffer) {
                 return;
             }
+
             if (this._updatable) {
                 this._engine.updateDynamicVertexBuffer(this._buffer, data, offset);
                 this._data = null;
             }
         };
+
         VertexBuffer.prototype.dispose = function () {
             if (!this._buffer) {
                 return;
@@ -94,6 +109,7 @@ var BABYLON;
                 this._buffer = null;
             }
         };
+
         Object.defineProperty(VertexBuffer, "PositionKind", {
             get: function () {
                 return VertexBuffer._PositionKind;
@@ -101,6 +117,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(VertexBuffer, "NormalKind", {
             get: function () {
                 return VertexBuffer._NormalKind;
@@ -108,6 +125,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(VertexBuffer, "UVKind", {
             get: function () {
                 return VertexBuffer._UVKind;
@@ -115,6 +133,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(VertexBuffer, "UV2Kind", {
             get: function () {
                 return VertexBuffer._UV2Kind;
@@ -122,6 +141,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(VertexBuffer, "ColorKind", {
             get: function () {
                 return VertexBuffer._ColorKind;
@@ -129,6 +149,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(VertexBuffer, "MatricesIndicesKind", {
             get: function () {
                 return VertexBuffer._MatricesIndicesKind;
@@ -136,6 +157,7 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+
         Object.defineProperty(VertexBuffer, "MatricesWeightsKind", {
             get: function () {
                 return VertexBuffer._MatricesWeightsKind;
@@ -143,7 +165,6 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
-        // Enums
         VertexBuffer._PositionKind = "position";
         VertexBuffer._NormalKind = "normal";
         VertexBuffer._UVKind = "uv";
@@ -155,4 +176,4 @@ var BABYLON;
     })();
     BABYLON.VertexBuffer = VertexBuffer;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.vertexBuffer.js.map
+//# sourceMappingURL=babylon.vertexBuffer.js.map

+ 2 - 2
Babylon/Particles/babylon.particle.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var Particle = (function () {
         function Particle() {
@@ -27,4 +27,4 @@ var BABYLON;
     })();
     BABYLON.Particle = Particle;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.particle.js.map
+//# sourceMappingURL=babylon.particle.js.map

+ 96 - 17
Babylon/Particles/babylon.particleSystem.js

@@ -1,12 +1,15 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var randomNumber = function (min, max) {
         if (min === max) {
             return (min);
         }
+
         var random = Math.random();
+
         return ((random * (max - min)) + min);
     };
+
     var ParticleSystem = (function () {
         function ParticleSystem(name, capacity, scene, customEffect) {
             var _this = this;
@@ -39,7 +42,7 @@ var BABYLON;
             this.textureMask = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
             this.particles = new Array();
             this._vertexDeclaration = [3, 4, 4];
-            this._vertexStrideSize = 11 * 4; // 11 floats per particle (x, y, z, r, g, b, a, angle, size, offsetX, offsetY)
+            this._vertexStrideSize = 11 * 4;
             this._stockParticles = new Array();
             this._newPartsExcess = 0;
             this._scaledColorStep = new BABYLON.Color4(0, 0, 0, 0);
@@ -52,11 +55,16 @@ var BABYLON;
             this._actualFrame = 0;
             this.id = name;
             this._capacity = capacity;
+
             this._scene = scene;
+
             this._customEffect = customEffect;
+
             scene.particleSystems.push(this);
+
             // VBO
             this._vertexBuffer = scene.getEngine().createDynamicVertexBuffer(capacity * this._vertexStrideSize * 4);
+
             var indices = [];
             var index = 0;
             for (var count = 0; count < capacity; count++) {
@@ -68,38 +76,49 @@ var BABYLON;
                 indices.push(index + 3);
                 index += 4;
             }
+
             this._indexBuffer = scene.getEngine().createIndexBuffer(indices);
+
             this._vertices = new Float32Array(capacity * this._vertexStrideSize);
+
             // Default behaviors
             this.startDirectionFunction = function (emitPower, worldMatrix, directionToUpdate) {
                 var randX = randomNumber(_this.direction1.x, _this.direction2.x);
                 var randY = randomNumber(_this.direction1.y, _this.direction2.y);
                 var randZ = randomNumber(_this.direction1.z, _this.direction2.z);
+
                 BABYLON.Vector3.TransformNormalFromFloatsToRef(randX * emitPower, randY * emitPower, randZ * emitPower, worldMatrix, directionToUpdate);
             };
+
             this.startPositionFunction = function (worldMatrix, positionToUpdate) {
                 var randX = randomNumber(_this.minEmitBox.x, _this.maxEmitBox.x);
                 var randY = randomNumber(_this.minEmitBox.y, _this.maxEmitBox.y);
                 var randZ = randomNumber(_this.minEmitBox.z, _this.maxEmitBox.z);
+
                 BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, worldMatrix, positionToUpdate);
             };
+
             this.updateFunction = function (particles) {
                 for (var index = 0; index < particles.length; index++) {
                     var particle = particles[index];
                     particle.age += _this._scaledUpdateSpeed;
+
                     if (particle.age >= particle.lifeTime) {
                         _this.recycleParticle(particle);
                         index--;
                         continue;
-                    }
-                    else {
+                    } else {
                         particle.colorStep.scaleToRef(_this._scaledUpdateSpeed, _this._scaledColorStep);
                         particle.color.addInPlace(_this._scaledColorStep);
+
                         if (particle.color.a < 0)
                             particle.color.a = 0;
+
                         particle.angle += particle.angularSpeed * _this._scaledUpdateSpeed;
+
                         particle.direction.scaleToRef(_this._scaledUpdateSpeed, _this._scaledDirection);
                         particle.position.addInPlace(_this._scaledDirection);
+
                         _this.gravity.scaleToRef(_this._scaledUpdateSpeed, _this._scaledGravity);
                         particle.direction.addInPlace(_this._scaledGravity);
                     }
@@ -108,28 +127,35 @@ var BABYLON;
         }
         ParticleSystem.prototype.recycleParticle = function (particle) {
             var lastParticle = this.particles.pop();
+
             if (lastParticle !== particle) {
                 lastParticle.copyTo(particle);
                 this._stockParticles.push(lastParticle);
             }
         };
+
         ParticleSystem.prototype.getCapacity = function () {
             return this._capacity;
         };
+
         ParticleSystem.prototype.isAlive = function () {
             return this._alive;
         };
+
         ParticleSystem.prototype.isStarted = function () {
             return this._started;
         };
+
         ParticleSystem.prototype.start = function () {
             this._started = true;
             this._stopped = false;
             this._actualFrame = 0;
         };
+
         ParticleSystem.prototype.stop = function () {
             this._stopped = true;
         };
+
         ParticleSystem.prototype._appendParticleVertex = function (index, particle, offsetX, offsetY) {
             var offset = index * 11;
             this._vertices[offset] = particle.position.x;
@@ -144,96 +170,127 @@ var BABYLON;
             this._vertices[offset + 9] = offsetX;
             this._vertices[offset + 10] = offsetY;
         };
+
         ParticleSystem.prototype._update = function (newParticles) {
             // Update current
             this._alive = this.particles.length > 0;
+
             this.updateFunction(this.particles);
+
             // Add new ones
             var worldMatrix;
+
             if (this.emitter.position) {
                 worldMatrix = this.emitter.getWorldMatrix();
-            }
-            else {
+            } else {
                 worldMatrix = BABYLON.Matrix.Translation(this.emitter.x, this.emitter.y, this.emitter.z);
             }
+
             for (var index = 0; index < newParticles; index++) {
                 if (this.particles.length === this._capacity) {
                     break;
                 }
+
                 if (this._stockParticles.length !== 0) {
                     var particle = this._stockParticles.pop();
                     particle.age = 0;
-                }
-                else {
+                } else {
                     particle = new BABYLON.Particle();
                 }
                 this.particles.push(particle);
+
                 var emitPower = randomNumber(this.minEmitPower, this.maxEmitPower);
+
                 this.startDirectionFunction(emitPower, worldMatrix, particle.direction);
+
                 particle.lifeTime = randomNumber(this.minLifeTime, this.maxLifeTime);
+
                 particle.size = randomNumber(this.minSize, this.maxSize);
                 particle.angularSpeed = randomNumber(this.minAngularSpeed, this.maxAngularSpeed);
+
                 this.startPositionFunction(worldMatrix, particle.position);
+
                 var step = randomNumber(0, 1.0);
+
                 BABYLON.Color4.LerpToRef(this.color1, this.color2, step, particle.color);
+
                 this.colorDead.subtractToRef(particle.color, this._colorDiff);
                 this._colorDiff.scaleToRef(1.0 / particle.lifeTime, particle.colorStep);
             }
         };
+
         ParticleSystem.prototype._getEffect = function () {
             if (this._customEffect) {
                 return this._customEffect;
             }
             ;
+
             var defines = [];
+
             if (this._scene.clipPlane) {
                 defines.push("#define CLIPPLANE");
             }
+
             // Effect
             var join = defines.join("\n");
             if (this._cachedDefines !== join) {
                 this._cachedDefines = join;
+
                 this._effect = this._scene.getEngine().createEffect("particles", ["position", "color", "options"], ["invView", "view", "projection", "vClipPlane", "textureMask"], ["diffuseSampler"], join);
             }
+
             return this._effect;
         };
+
         ParticleSystem.prototype.animate = function () {
             if (!this._started)
                 return;
+
             var effect = this._getEffect();
+
             // Check
             if (!this.emitter || !effect.isReady() || !this.particleTexture || !this.particleTexture.isReady())
                 return;
+
             if (this._currentRenderId === this._scene.getRenderId()) {
                 return;
             }
+
             this._currentRenderId = this._scene.getRenderId();
+
             this._scaledUpdateSpeed = this.updateSpeed * this._scene.getAnimationRatio();
-            // determine the number of particles we need to create   
+
+            // determine the number of particles we need to create
             var emitCout;
+
             if (this.manualEmitCount > -1) {
                 emitCout = this.manualEmitCount;
                 this.manualEmitCount = 0;
-            }
-            else {
+            } else {
                 emitCout = this.emitRate;
             }
+
             var newParticles = ((emitCout * this._scaledUpdateSpeed) >> 0);
             this._newPartsExcess += emitCout * this._scaledUpdateSpeed - newParticles;
+
             if (this._newPartsExcess > 1.0) {
                 newParticles += this._newPartsExcess >> 0;
                 this._newPartsExcess -= this._newPartsExcess >> 0;
             }
+
             this._alive = false;
+
             if (!this._stopped) {
                 this._actualFrame += this._scaledUpdateSpeed;
+
                 if (this.targetStopDuration && this._actualFrame >= this.targetStopDuration)
                     this.stop();
-            }
-            else {
+            } else {
                 newParticles = 0;
             }
+
             this._update(newParticles);
+
             // Stopped?
             if (this._stopped) {
                 if (!this._alive) {
@@ -243,10 +300,12 @@ var BABYLON;
                     }
                 }
             }
+
             // Update VBO
             var offset = 0;
             for (var index = 0; index < this.particles.length; index++) {
                 var particle = this.particles[index];
+
                 this._appendParticleVertex(offset++, particle, 0, 0);
                 this._appendParticleVertex(offset++, particle, 1, 0);
                 this._appendParticleVertex(offset++, particle, 1, 1);
@@ -255,20 +314,26 @@ var BABYLON;
             var engine = this._scene.getEngine();
             engine.updateDynamicVertexBuffer(this._vertexBuffer, this._vertices);
         };
+
         ParticleSystem.prototype.render = function () {
             var effect = this._getEffect();
+
             // Check
             if (!this.emitter || !effect.isReady() || !this.particleTexture || !this.particleTexture.isReady() || !this.particles.length)
                 return 0;
+
             var engine = this._scene.getEngine();
+
             // Render
             engine.enableEffect(effect);
             engine.setState(false);
+
             var viewMatrix = this._scene.getViewMatrix();
             effect.setTexture("diffuseSampler", this.particleTexture);
             effect.setMatrix("view", viewMatrix);
             effect.setMatrix("projection", this._scene.getProjectionMatrix());
             effect.setFloat4("textureMask", this.textureMask.r, this.textureMask.g, this.textureMask.b, this.textureMask.a);
+
             if (this._scene.clipPlane) {
                 var clipPlane = this._scene.clipPlane;
                 var invView = viewMatrix.clone();
@@ -276,62 +341,76 @@ var BABYLON;
                 effect.setMatrix("invView", invView);
                 effect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
             }
+
             // VBOs
             engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, effect);
+
             // Draw order
             if (this.blendMode === ParticleSystem.BLENDMODE_ONEONE) {
                 engine.setAlphaMode(BABYLON.Engine.ALPHA_ADD);
-            }
-            else {
+            } else {
                 engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE);
             }
+
             if (this.forceDepthWrite) {
                 engine.setDepthWrite(true);
             }
+
             engine.draw(true, 0, this.particles.length * 6);
             engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
+
             return this.particles.length;
         };
+
         ParticleSystem.prototype.dispose = function () {
             if (this._vertexBuffer) {
                 this._scene.getEngine()._releaseBuffer(this._vertexBuffer);
                 this._vertexBuffer = null;
             }
+
             if (this._indexBuffer) {
                 this._scene.getEngine()._releaseBuffer(this._indexBuffer);
                 this._indexBuffer = null;
             }
+
             if (this.particleTexture) {
                 this.particleTexture.dispose();
                 this.particleTexture = null;
             }
+
             // Remove from scene
             var index = this._scene.particleSystems.indexOf(this);
             this._scene.particleSystems.splice(index, 1);
+
             // Callback
             if (this.onDispose) {
                 this.onDispose();
             }
         };
+
         // Clone
         ParticleSystem.prototype.clone = function (name, newEmitter) {
             var result = new ParticleSystem(name, this._capacity, this._scene);
+
             BABYLON.Tools.DeepCopy(this, result, ["particles"], ["_vertexDeclaration", "_vertexStrideSize"]);
+
             if (newEmitter === undefined) {
                 newEmitter = this.emitter;
             }
+
             result.emitter = newEmitter;
             if (this.particleTexture) {
                 result.particleTexture = new BABYLON.Texture(this.particleTexture.url, this._scene);
             }
+
             result.start();
+
             return result;
         };
-        // Statics
         ParticleSystem.BLENDMODE_ONEONE = 0;
         ParticleSystem.BLENDMODE_STANDARD = 1;
         return ParticleSystem;
     })();
     BABYLON.ParticleSystem = ParticleSystem;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.particleSystem.js.map
+//# sourceMappingURL=babylon.particleSystem.js.map

+ 79 - 9
Babylon/Physics/Plugins/babylon.cannonJSPlugin.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var CannonJSPlugin = (function () {
         function CannonJSPlugin() {
@@ -9,8 +9,10 @@ var BABYLON;
                     var registeredMesh = this._registeredMeshes[index];
                     if (registeredMesh.mesh === mesh || registeredMesh.mesh === mesh.parent) {
                         var body = registeredMesh.body;
+
                         var center = mesh.getBoundingInfo().boundingBox.center;
                         body.position.set(center.x, center.z, center.y);
+
                         body.quaternion.x = mesh.rotationQuaternion.x;
                         body.quaternion.z = mesh.rotationQuaternion.y;
                         body.quaternion.y = mesh.rotationQuaternion.z;
@@ -21,55 +23,67 @@ var BABYLON;
             };
         }
         CannonJSPlugin.prototype.initialize = function (iterations) {
-            if (iterations === void 0) { iterations = 10; }
+            if (typeof iterations === "undefined") { iterations = 10; }
             this._world = new CANNON.World();
             this._world.broadphase = new CANNON.NaiveBroadphase();
             this._world.solver.iterations = iterations;
         };
+
         CannonJSPlugin.prototype._checkWithEpsilon = function (value) {
             return value < BABYLON.PhysicsEngine.Epsilon ? BABYLON.PhysicsEngine.Epsilon : value;
         };
+
         CannonJSPlugin.prototype.runOneStep = function (delta) {
             this._world.step(delta);
+
             for (var index = 0; index < this._registeredMeshes.length; index++) {
                 var registeredMesh = this._registeredMeshes[index];
+
                 if (registeredMesh.isChild) {
                     continue;
                 }
+
                 // Body position
                 var bodyX = registeredMesh.body.position.x, bodyY = registeredMesh.body.position.y, bodyZ = registeredMesh.body.position.z;
+
                 var deltaPos = registeredMesh.delta;
                 if (deltaPos) {
                     registeredMesh.mesh.position.x = bodyX + deltaPos.x;
                     registeredMesh.mesh.position.y = bodyZ + deltaPos.y;
                     registeredMesh.mesh.position.z = bodyY + deltaPos.z;
-                }
-                else {
+                } else {
                     registeredMesh.mesh.position.x = bodyX;
                     registeredMesh.mesh.position.y = bodyZ;
                     registeredMesh.mesh.position.z = bodyY;
                 }
+
                 if (!registeredMesh.mesh.rotationQuaternion) {
                     registeredMesh.mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
                 }
+
                 registeredMesh.mesh.rotationQuaternion.x = registeredMesh.body.quaternion.x;
                 registeredMesh.mesh.rotationQuaternion.y = registeredMesh.body.quaternion.z;
                 registeredMesh.mesh.rotationQuaternion.z = registeredMesh.body.quaternion.y;
                 registeredMesh.mesh.rotationQuaternion.w = -registeredMesh.body.quaternion.w;
             }
         };
+
         CannonJSPlugin.prototype.setGravity = function (gravity) {
             this._world.gravity.set(gravity.x, gravity.z, gravity.y);
         };
+
         CannonJSPlugin.prototype.registerMesh = function (mesh, impostor, options) {
             this.unregisterMesh(mesh);
+
             mesh.computeWorldMatrix(true);
+
             switch (impostor) {
                 case BABYLON.PhysicsEngine.SphereImpostor:
                     var bbox = mesh.getBoundingInfo().boundingBox;
                     var radiusX = bbox.maximumWorld.x - bbox.minimumWorld.x;
                     var radiusY = bbox.maximumWorld.y - bbox.minimumWorld.y;
                     var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
+
                     return this._createSphere(Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2, mesh, options);
                 case BABYLON.PhysicsEngine.BoxImpostor:
                     bbox = mesh.getBoundingInfo().boundingBox;
@@ -82,166 +96,222 @@ var BABYLON;
                 case BABYLON.PhysicsEngine.MeshImpostor:
                     var rawVerts = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
                     var rawFaces = mesh.getIndices();
+
                     return this._createConvexPolyhedron(rawVerts, rawFaces, mesh, options);
             }
+
             return null;
         };
+
         CannonJSPlugin.prototype._createSphere = function (radius, mesh, options) {
             var shape = new CANNON.Sphere(radius);
+
             if (!options) {
                 return shape;
             }
+
             return this._createRigidBodyFromShape(shape, mesh, options.mass, options.friction, options.restitution);
         };
+
         CannonJSPlugin.prototype._createBox = function (x, y, z, mesh, options) {
             var shape = new CANNON.Box(new CANNON.Vec3(x, z, y));
+
             if (!options) {
                 return shape;
             }
+
             return this._createRigidBodyFromShape(shape, mesh, options.mass, options.friction, options.restitution);
         };
+
         CannonJSPlugin.prototype._createPlane = function (mesh, options) {
             var shape = new CANNON.Plane();
+
             if (!options) {
                 return shape;
             }
+
             return this._createRigidBodyFromShape(shape, mesh, options.mass, options.friction, options.restitution);
         };
+
         CannonJSPlugin.prototype._createConvexPolyhedron = function (rawVerts, rawFaces, mesh, options) {
             var verts = [], faces = [];
+
             mesh.computeWorldMatrix(true);
+
             for (var i = 0; i < rawVerts.length; i += 3) {
                 var transformed = BABYLON.Vector3.Zero();
+
                 BABYLON.Vector3.TransformNormalFromFloatsToRef(rawVerts[i], rawVerts[i + 1], rawVerts[i + 2], mesh.getWorldMatrix(), transformed);
                 verts.push(new CANNON.Vec3(transformed.x, transformed.z, transformed.y));
             }
+
             for (var j = 0; j < rawFaces.length; j += 3) {
                 faces.push([rawFaces[j], rawFaces[j + 2], rawFaces[j + 1]]);
             }
+
             var shape = new CANNON.ConvexPolyhedron(verts, faces);
+
             if (!options) {
                 return shape;
             }
+
             return this._createRigidBodyFromShape(shape, mesh, options.mass, options.friction, options.restitution);
         };
+
         CannonJSPlugin.prototype._addMaterial = function (friction, restitution) {
             var index;
             var mat;
+
             for (index = 0; index < this._physicsMaterials.length; index++) {
                 mat = this._physicsMaterials[index];
+
                 if (mat.friction === friction && mat.restitution === restitution) {
                     return mat;
                 }
             }
+
             var currentMat = new CANNON.Material();
             currentMat.friction = friction;
             currentMat.restitution = restitution;
             this._physicsMaterials.push(currentMat);
+
             for (index = 0; index < this._physicsMaterials.length; index++) {
                 mat = this._physicsMaterials[index];
+
                 var contactMaterial = new CANNON.ContactMaterial(mat, currentMat, mat.friction * currentMat.friction, mat.restitution * currentMat.restitution);
                 contactMaterial.contactEquationStiffness = 1e10;
                 contactMaterial.contactEquationRegularizationTime = 10;
+
                 this._world.addContactMaterial(contactMaterial);
             }
+
             return currentMat;
         };
+
         CannonJSPlugin.prototype._createRigidBodyFromShape = function (shape, mesh, mass, friction, restitution) {
             var initialRotation = null;
+
             if (mesh.rotationQuaternion) {
                 initialRotation = mesh.rotationQuaternion.clone();
                 mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
             }
+
             // The delta between the mesh position and the mesh bounding box center
             var bbox = mesh.getBoundingInfo().boundingBox;
             var deltaPosition = mesh.position.subtract(bbox.center);
+
             var material = this._addMaterial(friction, restitution);
             var body = new CANNON.RigidBody(mass, shape, material);
+
             if (initialRotation) {
                 body.quaternion.x = initialRotation.x;
                 body.quaternion.z = initialRotation.y;
                 body.quaternion.y = initialRotation.z;
                 body.quaternion.w = -initialRotation.w;
             }
+
             body.position.set(bbox.center.x, bbox.center.z, bbox.center.y);
             this._world.add(body);
+
             this._registeredMeshes.push({ mesh: mesh, body: body, material: material, delta: deltaPosition });
+
             return body;
         };
+
         CannonJSPlugin.prototype.registerMeshesAsCompound = function (parts, options) {
             var compoundShape = new CANNON.Compound();
+
             for (var index = 0; index < parts.length; index++) {
                 var mesh = parts[index].mesh;
+
                 var shape = this.registerMesh(mesh, parts[index].impostor);
+
                 if (index == 0) {
                     compoundShape.addChild(shape, new CANNON.Vec3(0, 0, 0));
-                }
-                else {
+                } else {
                     compoundShape.addChild(shape, new CANNON.Vec3(mesh.position.x, mesh.position.z, mesh.position.y));
                 }
             }
+
             var initialMesh = parts[0].mesh;
             var body = this._createRigidBodyFromShape(compoundShape, initialMesh, options.mass, options.friction, options.restitution);
+
             body.parts = parts;
+
             return body;
         };
+
         CannonJSPlugin.prototype._unbindBody = function (body) {
             for (var index = 0; index < this._registeredMeshes.length; index++) {
                 var registeredMesh = this._registeredMeshes[index];
+
                 if (registeredMesh.body === body) {
                     registeredMesh.body = null;
                     registeredMesh.delta = 0;
                 }
             }
         };
+
         CannonJSPlugin.prototype.unregisterMesh = function (mesh) {
             for (var index = 0; index < this._registeredMeshes.length; index++) {
                 var registeredMesh = this._registeredMeshes[index];
+
                 if (registeredMesh.mesh === mesh) {
                     // Remove body
                     if (registeredMesh.body) {
                         this._world.remove(registeredMesh.body);
+
                         this._unbindBody(registeredMesh.body);
                     }
+
                     this._registeredMeshes.splice(index, 1);
                     return;
                 }
             }
         };
+
         CannonJSPlugin.prototype.applyImpulse = function (mesh, force, contactPoint) {
             var worldPoint = new CANNON.Vec3(contactPoint.x, contactPoint.z, contactPoint.y);
             var impulse = new CANNON.Vec3(force.x, force.z, force.y);
+
             for (var index = 0; index < this._registeredMeshes.length; index++) {
                 var registeredMesh = this._registeredMeshes[index];
+
                 if (registeredMesh.mesh === mesh) {
                     registeredMesh.body.applyImpulse(impulse, worldPoint);
                     return;
                 }
             }
         };
+
         CannonJSPlugin.prototype.createLink = function (mesh1, mesh2, pivot1, pivot2) {
             var body1 = null, body2 = null;
             for (var index = 0; index < this._registeredMeshes.length; index++) {
                 var registeredMesh = this._registeredMeshes[index];
+
                 if (registeredMesh.mesh === mesh1) {
                     body1 = registeredMesh.body;
-                }
-                else if (registeredMesh.mesh === mesh2) {
+                } else if (registeredMesh.mesh === mesh2) {
                     body2 = registeredMesh.body;
                 }
             }
+
             if (!body1 || !body2) {
                 return false;
             }
+
             var constraint = new CANNON.PointToPointConstraint(body1, new CANNON.Vec3(pivot1.x, pivot1.z, pivot1.y), body2, new CANNON.Vec3(pivot2.x, pivot2.z, pivot2.y));
             this._world.addConstraint(constraint);
+
             return true;
         };
+
         CannonJSPlugin.prototype.dispose = function () {
             while (this._registeredMeshes.length) {
                 this.unregisterMesh(this._registeredMeshes[0].mesh);
             }
         };
+
         CannonJSPlugin.prototype.isSupported = function () {
             return window.CANNON !== undefined;
         };
@@ -249,4 +319,4 @@ var BABYLON;
     })();
     BABYLON.CannonJSPlugin = CannonJSPlugin;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.cannonJSPlugin.js.map
+//# sourceMappingURL=babylon.cannonJSPlugin.js.map

+ 57 - 10
Babylon/Physics/Plugins/babylon.oimoJSPlugin.js

@@ -4,26 +4,30 @@ var BABYLON;
         function OimoJSPlugin() {
             this._registeredMeshes = [];
             /**
-             * Update the body position according to the mesh position
-             * @param mesh
-             */
+            * Update the body position according to the mesh position
+            * @param mesh
+            */
             this.updateBodyPosition = function (mesh) {
                 for (var index = 0; index < this._registeredMeshes.length; index++) {
                     var registeredMesh = this._registeredMeshes[index];
                     if (registeredMesh.mesh === mesh || registeredMesh.mesh === mesh.parent) {
                         var body = registeredMesh.body.body;
                         mesh.computeWorldMatrix(true);
+
                         var center = mesh.getBoundingInfo().boundingBox.center;
                         body.setPosition(center.x, center.y, center.z);
                         body.setRotation(mesh.rotation.x, mesh.rotation.y, mesh.rotation.z);
                         return;
                     }
+
                     // Case where the parent has been updated
                     if (registeredMesh.mesh.parent === mesh) {
                         mesh.computeWorldMatrix(true);
                         registeredMesh.mesh.computeWorldMatrix(true);
+
                         var absolutePosition = registeredMesh.mesh.getAbsolutePosition();
                         var absoluteRotation = mesh.rotation;
+
                         body = registeredMesh.body.body;
                         body.setPosition(absolutePosition.x, absolutePosition.y, absolutePosition.z);
                         body.setRotation(absoluteRotation.x, absoluteRotation.y, absoluteRotation.z);
@@ -35,17 +39,21 @@ var BABYLON;
         OimoJSPlugin.prototype._checkWithEpsilon = function (value) {
             return value < BABYLON.PhysicsEngine.Epsilon ? BABYLON.PhysicsEngine.Epsilon : value;
         };
+
         OimoJSPlugin.prototype.initialize = function (iterations) {
             this._world = new OIMO.World();
             this._world.clear();
         };
+
         OimoJSPlugin.prototype.setGravity = function (gravity) {
             this._world.gravity = gravity;
         };
+
         OimoJSPlugin.prototype.registerMesh = function (mesh, impostor, options) {
             var body = null;
             this.unregisterMesh(mesh);
             mesh.computeWorldMatrix(true);
+
             switch (impostor) {
                 case BABYLON.PhysicsEngine.SphereImpostor:
                     var initialRotation = null;
@@ -54,19 +62,24 @@ var BABYLON;
                         mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
                         mesh.computeWorldMatrix(true);
                     }
+
                     var bbox = mesh.getBoundingInfo().boundingBox;
                     var radiusX = bbox.maximumWorld.x - bbox.minimumWorld.x;
                     var radiusY = bbox.maximumWorld.y - bbox.minimumWorld.y;
                     var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
+
                     var size = Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2;
+
                     // The delta between the mesh position and the mesh bounding box center
                     var deltaPosition = mesh.position.subtract(bbox.center);
+
                     // Transform delta position with the rotation
                     if (initialRotation) {
                         var m = new BABYLON.Matrix();
                         initialRotation.toRotationMatrix(m);
                         deltaPosition = BABYLON.Vector3.TransformCoordinates(deltaPosition, m);
                     }
+
                     body = new OIMO.Body({
                         type: 'sphere',
                         size: [size],
@@ -76,16 +89,19 @@ var BABYLON;
                         config: [options.mass, options.friction, options.restitution],
                         world: this._world
                     });
+
                     // Restore rotation
                     if (initialRotation) {
                         body.setQuaternion(initialRotation);
                     }
+
                     this._registeredMeshes.push({
                         mesh: mesh,
                         body: body,
                         delta: deltaPosition
                     });
                     break;
+
                 case BABYLON.PhysicsEngine.PlaneImpostor:
                 case BABYLON.PhysicsEngine.BoxImpostor:
                     initialRotation = null;
@@ -94,6 +110,7 @@ var BABYLON;
                         mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
                         mesh.computeWorldMatrix(true);
                     }
+
                     bbox = mesh.getBoundingInfo().boundingBox;
                     var min = bbox.minimumWorld;
                     var max = bbox.maximumWorld;
@@ -101,14 +118,17 @@ var BABYLON;
                     var sizeX = this._checkWithEpsilon(box.x);
                     var sizeY = this._checkWithEpsilon(box.y);
                     var sizeZ = this._checkWithEpsilon(box.z);
+
                     // The delta between the mesh position and the mesh boudning box center
                     deltaPosition = mesh.position.subtract(bbox.center);
+
                     // Transform delta position with the rotation
                     if (initialRotation) {
                         m = new BABYLON.Matrix();
                         initialRotation.toRotationMatrix(m);
                         deltaPosition = BABYLON.Vector3.TransformCoordinates(deltaPosition, m);
                     }
+
                     body = new OIMO.Body({
                         type: 'box',
                         size: [sizeX, sizeY, sizeZ],
@@ -118,9 +138,11 @@ var BABYLON;
                         config: [options.mass, options.friction, options.restitution],
                         world: this._world
                     });
+
                     if (initialRotation) {
                         body.setQuaternion(initialRotation);
                     }
+
                     this._registeredMeshes.push({
                         mesh: mesh,
                         body: body,
@@ -130,9 +152,12 @@ var BABYLON;
             }
             return body;
         };
+
         OimoJSPlugin.prototype.registerMeshesAsCompound = function (parts, options) {
             var types = [], sizes = [], positions = [], rotations = [];
+
             var initialMesh = parts[0].mesh;
+
             for (var index = 0; index < parts.length; index++) {
                 var part = parts[index];
                 var bodyParameters = this._createBodyAsCompound(part, options, initialMesh);
@@ -141,6 +166,7 @@ var BABYLON;
                 positions.push.apply(positions, bodyParameters.pos);
                 rotations.push.apply(rotations, bodyParameters.rot);
             }
+
             var body = new OIMO.Body({
                 type: types,
                 size: sizes,
@@ -150,21 +176,26 @@ var BABYLON;
                 config: [options.mass, options.friction, options.restitution],
                 world: this._world
             });
+
             this._registeredMeshes.push({
                 mesh: initialMesh,
                 body: body
             });
+
             return body;
         };
+
         OimoJSPlugin.prototype._createBodyAsCompound = function (part, options, initialMesh) {
             var bodyParameters = null;
             var mesh = part.mesh;
+
             switch (part.impostor) {
                 case BABYLON.PhysicsEngine.SphereImpostor:
                     var bbox = mesh.getBoundingInfo().boundingBox;
                     var radiusX = bbox.maximumWorld.x - bbox.minimumWorld.x;
                     var radiusY = bbox.maximumWorld.y - bbox.minimumWorld.y;
                     var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
+
                     var size = Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2;
                     bodyParameters = {
                         type: 'sphere',
@@ -174,6 +205,7 @@ var BABYLON;
                         rot: [mesh.rotation.x / OIMO.TO_RAD, mesh.rotation.y / OIMO.TO_RAD, mesh.rotation.z / OIMO.TO_RAD]
                     };
                     break;
+
                 case BABYLON.PhysicsEngine.PlaneImpostor:
                 case BABYLON.PhysicsEngine.BoxImpostor:
                     bbox = mesh.getBoundingInfo().boundingBox;
@@ -192,8 +224,10 @@ var BABYLON;
                     };
                     break;
             }
+
             return bodyParameters;
         };
+
         OimoJSPlugin.prototype.unregisterMesh = function (mesh) {
             for (var index = 0; index < this._registeredMeshes.length; index++) {
                 var registeredMesh = this._registeredMeshes[index];
@@ -207,6 +241,7 @@ var BABYLON;
                 }
             }
         };
+
         OimoJSPlugin.prototype._unbindBody = function (body) {
             for (var index = 0; index < this._registeredMeshes.length; index++) {
                 var registeredMesh = this._registeredMeshes[index];
@@ -215,26 +250,28 @@ var BABYLON;
                 }
             }
         };
+
         OimoJSPlugin.prototype.applyImpulse = function (mesh, force, contactPoint) {
             for (var index = 0; index < this._registeredMeshes.length; index++) {
                 var registeredMesh = this._registeredMeshes[index];
                 if (registeredMesh.mesh === mesh || registeredMesh.mesh === mesh.parent) {
                     // Get object mass to have a behaviour similar to cannon.js
                     var mass = registeredMesh.body.body.massInfo.mass;
+
                     // The force is scaled with the mass of object
                     registeredMesh.body.body.applyImpulse(contactPoint.scale(OIMO.INV_SCALE), force.scale(OIMO.INV_SCALE * mass));
                     return;
                 }
             }
         };
+
         OimoJSPlugin.prototype.createLink = function (mesh1, mesh2, pivot1, pivot2, options) {
             var body1 = null, body2 = null;
             for (var index = 0; index < this._registeredMeshes.length; index++) {
                 var registeredMesh = this._registeredMeshes[index];
                 if (registeredMesh.mesh === mesh1) {
                     body1 = registeredMesh.body.body;
-                }
-                else if (registeredMesh.mesh === mesh2) {
+                } else if (registeredMesh.mesh === mesh2) {
                     body2 = registeredMesh.body.body;
                 }
             }
@@ -244,6 +281,7 @@ var BABYLON;
             if (!options) {
                 options = {};
             }
+
             new OIMO.Link({
                 type: options.type,
                 body1: body1,
@@ -258,17 +296,21 @@ var BABYLON;
                 spring: options.spring,
                 world: this._world
             });
+
             return true;
         };
+
         OimoJSPlugin.prototype.dispose = function () {
             this._world.clear();
             while (this._registeredMeshes.length) {
                 this.unregisterMesh(this._registeredMeshes[0].mesh);
             }
         };
+
         OimoJSPlugin.prototype.isSupported = function () {
             return OIMO !== undefined;
         };
+
         OimoJSPlugin.prototype._getLastShape = function (body) {
             var lastShape = body.shapes;
             while (lastShape.next) {
@@ -276,8 +318,10 @@ var BABYLON;
             }
             return lastShape;
         };
+
         OimoJSPlugin.prototype.runOneStep = function (time) {
             this._world.step();
+
             // Update the position of all registered meshes
             var i = this._registeredMeshes.length;
             var m;
@@ -285,6 +329,7 @@ var BABYLON;
                 var body = this._registeredMeshes[i].body.body;
                 var mesh = this._registeredMeshes[i].mesh;
                 var delta = this._registeredMeshes[i].delta;
+
                 if (!body.sleeping) {
                     if (body.shapes.next) {
                         var parentShape = this._getLastShape(body);
@@ -292,27 +337,29 @@ var BABYLON;
                         mesh.position.y = parentShape.position.y * OIMO.WORLD_SCALE;
                         mesh.position.z = parentShape.position.z * OIMO.WORLD_SCALE;
                         var mtx = BABYLON.Matrix.FromArray(body.getMatrix());
+
                         if (!mesh.rotationQuaternion) {
                             mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
                         }
                         mesh.rotationQuaternion.fromRotationMatrix(mtx);
                         mesh.computeWorldMatrix();
-                    }
-                    else {
+                    } else {
                         m = body.getMatrix();
                         mtx = BABYLON.Matrix.FromArray(m);
+
                         // Body position
                         var bodyX = mtx.m[12], bodyY = mtx.m[13], bodyZ = mtx.m[14];
+
                         if (!delta) {
                             mesh.position.x = bodyX;
                             mesh.position.y = bodyY;
                             mesh.position.z = bodyZ;
-                        }
-                        else {
+                        } else {
                             mesh.position.x = bodyX + delta.x;
                             mesh.position.y = bodyY + delta.y;
                             mesh.position.z = bodyZ + delta.z;
                         }
+
                         if (!mesh.rotationQuaternion) {
                             mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
                         }
@@ -326,4 +373,4 @@ var BABYLON;
     })();
     BABYLON.OimoJSPlugin = OimoJSPlugin;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.oimoJSPlugin.js.map
+//# sourceMappingURL=babylon.oimoJSPlugin.js.map

+ 15 - 5
Babylon/Physics/babylon.physicsEngine.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var PhysicsEngine = (function () {
         function PhysicsEngine(plugin) {
@@ -8,44 +8,54 @@ var BABYLON;
             this._currentPlugin.initialize();
             this._setGravity(gravity);
         };
+
         PhysicsEngine.prototype._runOneStep = function (delta) {
             if (delta > 0.1) {
                 delta = 0.1;
-            }
-            else if (delta <= 0) {
+            } else if (delta <= 0) {
                 delta = 1.0 / 60.0;
             }
+
             this._currentPlugin.runOneStep(delta);
         };
+
         PhysicsEngine.prototype._setGravity = function (gravity) {
             this.gravity = gravity || new BABYLON.Vector3(0, -9.82, 0);
             this._currentPlugin.setGravity(this.gravity);
         };
+
         PhysicsEngine.prototype._registerMesh = function (mesh, impostor, options) {
             return this._currentPlugin.registerMesh(mesh, impostor, options);
         };
+
         PhysicsEngine.prototype._registerMeshesAsCompound = function (parts, options) {
             return this._currentPlugin.registerMeshesAsCompound(parts, options);
         };
+
         PhysicsEngine.prototype._unregisterMesh = function (mesh) {
             this._currentPlugin.unregisterMesh(mesh);
         };
+
         PhysicsEngine.prototype._applyImpulse = function (mesh, force, contactPoint) {
             this._currentPlugin.applyImpulse(mesh, force, contactPoint);
         };
+
         PhysicsEngine.prototype._createLink = function (mesh1, mesh2, pivot1, pivot2, options) {
             return this._currentPlugin.createLink(mesh1, mesh2, pivot1, pivot2, options);
         };
+
         PhysicsEngine.prototype._updateBodyPosition = function (mesh) {
             this._currentPlugin.updateBodyPosition(mesh);
         };
+
         PhysicsEngine.prototype.dispose = function () {
             this._currentPlugin.dispose();
         };
+
         PhysicsEngine.prototype.isSupported = function () {
             return this._currentPlugin.isSupported();
         };
-        // Statics
+
         PhysicsEngine.NoImpostor = 0;
         PhysicsEngine.SphereImpostor = 1;
         PhysicsEngine.BoxImpostor = 2;
@@ -60,4 +70,4 @@ var BABYLON;
     })();
     BABYLON.PhysicsEngine = PhysicsEngine;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.physicsEngine.js.map
+//# sourceMappingURL=babylon.physicsEngine.js.map

+ 46 - 5
Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderEffect.js

@@ -5,10 +5,14 @@ var BABYLON;
             this._engine = engine;
             this._name = name;
             this._singleInstance = singleInstance || true;
+
             this._getPostProcess = getPostProcess;
+
             this._cameras = [];
             this._indicesForCamera = [];
+
             this._postProcesses = {};
+
             this._renderPasses = {};
             this._renderEffectAsPasses = {};
         }
@@ -17,18 +21,25 @@ var BABYLON;
                 this._renderPasses[renderPassName]._update();
             }
         };
+
         PostProcessRenderEffect.prototype.addPass = function (renderPass) {
             this._renderPasses[renderPass._name] = renderPass;
+
             this._linkParameters();
         };
+
         PostProcessRenderEffect.prototype.removePass = function (renderPass) {
             delete this._renderPasses[renderPass._name];
+
             this._linkParameters();
         };
+
         PostProcessRenderEffect.prototype.addRenderEffectAsPass = function (renderEffect) {
             this._renderEffectAsPasses[renderEffect._name] = renderEffect;
+
             this._linkParameters();
         };
+
         PostProcessRenderEffect.prototype.getPass = function (passName) {
             for (var renderPassName in this._renderPasses) {
                 if (renderPassName === passName) {
@@ -36,100 +47,130 @@ var BABYLON;
                 }
             }
         };
+
         PostProcessRenderEffect.prototype.emptyPasses = function () {
             this._renderPasses = {};
+
             this._linkParameters();
         };
+
         PostProcessRenderEffect.prototype._attachCameras = function (cameras) {
             var cameraKey;
+
             var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
+
             for (var i = 0; i < _cam.length; i++) {
                 var camera = _cam[i];
                 var cameraName = camera.name;
+
                 if (this._singleInstance) {
                     cameraKey = 0;
-                }
-                else {
+                } else {
                     cameraKey = cameraName;
                 }
+
                 this._postProcesses[cameraKey] = this._postProcesses[cameraKey] || this._getPostProcess();
+
                 var index = camera.attachPostProcess(this._postProcesses[cameraKey]);
+
                 if (!this._indicesForCamera[cameraName]) {
                     this._indicesForCamera[cameraName] = [];
                 }
+
                 this._indicesForCamera[cameraName].push(index);
+
                 if (this._cameras.indexOf(camera) === -1) {
                     this._cameras[cameraName] = camera;
                 }
+
                 for (var passName in this._renderPasses) {
                     this._renderPasses[passName]._incRefCount();
                 }
             }
+
             this._linkParameters();
         };
+
         PostProcessRenderEffect.prototype._detachCameras = function (cameras) {
             var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
+
             for (var i = 0; i < _cam.length; i++) {
                 var camera = _cam[i];
                 var cameraName = camera.name;
+
                 camera.detachPostProcess(this._postProcesses[this._singleInstance ? 0 : cameraName], this._indicesForCamera[cameraName]);
+
                 var index = this._cameras.indexOf(cameraName);
+
                 this._indicesForCamera.splice(index, 1);
                 this._cameras.splice(index, 1);
+
                 for (var passName in this._renderPasses) {
                     this._renderPasses[passName]._decRefCount();
                 }
             }
         };
+
         PostProcessRenderEffect.prototype._enable = function (cameras) {
             var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
+
             for (var i = 0; i < _cam.length; i++) {
                 var camera = _cam[i];
                 var cameraName = camera.name;
+
                 for (var j = 0; j < this._indicesForCamera[cameraName].length; j++) {
                     if (camera._postProcesses[this._indicesForCamera[cameraName][j]] === undefined) {
                         cameras[i].attachPostProcess(this._postProcesses[this._singleInstance ? 0 : cameraName], this._indicesForCamera[cameraName][j]);
                     }
                 }
+
                 for (var passName in this._renderPasses) {
                     this._renderPasses[passName]._incRefCount();
                 }
             }
         };
+
         PostProcessRenderEffect.prototype._disable = function (cameras) {
             var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
+
             for (var i = 0; i < _cam.length; i++) {
                 var camera = _cam[i];
                 var cameraName = camera.Name;
+
                 camera.detachPostProcess(this._postProcesses[this._singleInstance ? 0 : cameraName], this._indicesForCamera[cameraName]);
+
                 for (var passName in this._renderPasses) {
                     this._renderPasses[passName]._decRefCount();
                 }
             }
         };
+
         PostProcessRenderEffect.prototype.getPostProcess = function (camera) {
             if (this._singleInstance) {
                 return this._postProcesses[0];
-            }
-            else {
+            } else {
                 return this._postProcesses[camera.name];
             }
         };
+
         PostProcessRenderEffect.prototype._linkParameters = function () {
             var _this = this;
             for (var index in this._postProcesses) {
                 if (this.applyParameters) {
                     this.applyParameters(this._postProcesses[index]);
                 }
+
                 this._postProcesses[index].onBeforeRender = function (effect) {
                     _this._linkTextures(effect);
                 };
             }
         };
+
         PostProcessRenderEffect.prototype._linkTextures = function (effect) {
             for (var renderPassName in this._renderPasses) {
                 effect.setTexture(renderPassName, this._renderPasses[renderPassName].getRenderTexture());
             }
+
             for (var renderEffectName in this._renderEffectAsPasses) {
                 effect.setTextureFromPostProcess(renderEffectName + "Sampler", this._renderEffectAsPasses[renderEffectName].getPostProcess());
             }
@@ -138,4 +179,4 @@ var BABYLON;
     })();
     BABYLON.PostProcessRenderEffect = PostProcessRenderEffect;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.postProcessRenderEffect.js.map
+//# sourceMappingURL=babylon.postProcessRenderEffect.js.map

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

@@ -1,15 +1,19 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var PostProcessRenderPass = (function () {
         function PostProcessRenderPass(scene, name, size, renderList, beforeRender, afterRender) {
             this._enabled = true;
             this._refCount = 0;
             this._name = name;
+
             this._renderTexture = new BABYLON.RenderTargetTexture(name, size, scene);
             this.setRenderList(renderList);
+
             this._renderTexture.onBeforeRender = beforeRender;
             this._renderTexture.onAfterRender = afterRender;
+
             this._scene = scene;
+
             this._renderList = renderList;
         }
         // private
@@ -17,22 +21,29 @@ var BABYLON;
             if (this._refCount === 0) {
                 this._scene.customRenderTargets.push(this._renderTexture);
             }
+
             return ++this._refCount;
         };
+
         PostProcessRenderPass.prototype._decRefCount = function () {
             this._refCount--;
+
             if (this._refCount <= 0) {
                 this._scene.customRenderTargets.splice(this._scene.customRenderTargets.indexOf(this._renderTexture), 1);
             }
+
             return this._refCount;
         };
+
         PostProcessRenderPass.prototype._update = function () {
             this.setRenderList(this._renderList);
         };
+
         // public
         PostProcessRenderPass.prototype.setRenderList = function (renderList) {
             this._renderTexture.renderList = renderList;
         };
+
         PostProcessRenderPass.prototype.getRenderTexture = function () {
             return this._renderTexture;
         };
@@ -40,4 +51,4 @@ var BABYLON;
     })();
     BABYLON.PostProcessRenderPass = PostProcessRenderPass;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.postProcessRenderPass.js.map
+//# sourceMappingURL=babylon.postProcessRenderPass.js.map

+ 34 - 3
Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPipeline.js

@@ -4,76 +4,101 @@ var BABYLON;
         function PostProcessRenderPipeline(engine, name) {
             this._engine = engine;
             this._name = name;
+
             this._renderEffects = {};
             this._renderEffectsForIsolatedPass = {};
+
             this._cameras = [];
         }
         PostProcessRenderPipeline.prototype.addEffect = function (renderEffect) {
             this._renderEffects[renderEffect._name] = renderEffect;
         };
+
         PostProcessRenderPipeline.prototype._enableEffect = function (renderEffectName, cameras) {
             var renderEffects = this._renderEffects[renderEffectName];
+
             if (!renderEffects) {
                 return;
             }
+
             renderEffects._enable(BABYLON.Tools.MakeArray(cameras || this._cameras));
         };
+
         PostProcessRenderPipeline.prototype._disableEffect = function (renderEffectName, cameras) {
             var renderEffects = this._renderEffects[renderEffectName];
+
             if (!renderEffects) {
                 return;
             }
+
             renderEffects._disable(BABYLON.Tools.MakeArray(cameras || this._cameras));
         };
+
         PostProcessRenderPipeline.prototype._attachCameras = function (cameras, unique) {
             var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
+
             var indicesToDelete = [];
+
             for (var i = 0; i < _cam.length; i++) {
                 var camera = _cam[i];
                 var cameraName = camera.name;
+
                 if (this._cameras.indexOf(camera) === -1) {
                     this._cameras[cameraName] = camera;
-                }
-                else if (unique) {
+                } else if (unique) {
                     indicesToDelete.push(i);
                 }
             }
+
             for (var i = 0; i < indicesToDelete.length; i++) {
                 cameras.splice(indicesToDelete[i], 1);
             }
+
             for (var renderEffectName in this._renderEffects) {
                 this._renderEffects[renderEffectName]._attachCameras(_cam);
             }
         };
+
         PostProcessRenderPipeline.prototype._detachCameras = function (cameras) {
             var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
+
             for (var renderEffectName in this._renderEffects) {
                 this._renderEffects[renderEffectName]._detachCameras(_cam);
             }
+
             for (var i = 0; i < _cam.length; i++) {
                 this._cameras.splice(this._cameras.indexOf(_cam[i]), 1);
             }
         };
+
         PostProcessRenderPipeline.prototype._enableDisplayOnlyPass = function (passName, cameras) {
             var _this = this;
             var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
+
             var pass = null;
+
             for (var renderEffectName in this._renderEffects) {
                 pass = this._renderEffects[renderEffectName].getPass(passName);
+
                 if (pass != null) {
                     break;
                 }
             }
+
             if (pass === null) {
                 return;
             }
+
             for (var renderEffectName in this._renderEffects) {
                 this._renderEffects[renderEffectName]._disable(_cam);
             }
+
             pass._name = PostProcessRenderPipeline.PASS_SAMPLER_NAME;
+
             for (var i = 0; i < _cam.length; i++) {
                 var camera = _cam[i];
                 var cameraName = camera.name;
+
                 this._renderEffectsForIsolatedPass[cameraName] = this._renderEffectsForIsolatedPass[cameraName] || new BABYLON.PostProcessRenderEffect(this._engine, PostProcessRenderPipeline.PASS_EFFECT_NAME, function () {
                     return new BABYLON.DisplayPassPostProcess(PostProcessRenderPipeline.PASS_EFFECT_NAME, 1.0, null, null, _this._engine, true);
                 });
@@ -82,25 +107,31 @@ var BABYLON;
                 this._renderEffectsForIsolatedPass[cameraName]._attachCameras(camera);
             }
         };
+
         PostProcessRenderPipeline.prototype._disableDisplayOnlyPass = function (cameras) {
             var _this = this;
             var _cam = BABYLON.Tools.MakeArray(cameras || this._cameras);
+
             for (var i = 0; i < _cam.length; i++) {
                 var camera = _cam[i];
                 var cameraName = camera.name;
+
                 this._renderEffectsForIsolatedPass[cameraName] = this._renderEffectsForIsolatedPass[cameraName] || new BABYLON.PostProcessRenderEffect(this._engine, PostProcessRenderPipeline.PASS_EFFECT_NAME, function () {
                     return new BABYLON.DisplayPassPostProcess(PostProcessRenderPipeline.PASS_EFFECT_NAME, 1.0, null, null, _this._engine, true);
                 });
                 this._renderEffectsForIsolatedPass[cameraName]._disable(camera);
             }
+
             for (var renderEffectName in this._renderEffects) {
                 this._renderEffects[renderEffectName]._enable(_cam);
             }
         };
+
         PostProcessRenderPipeline.prototype._update = function () {
             for (var renderEffectName in this._renderEffects) {
                 this._renderEffects[renderEffectName]._update();
             }
+
             for (var i = 0; i < this._cameras.length; i++) {
                 var cameraName = this._cameras[i].name;
                 if (this._renderEffectsForIsolatedPass[cameraName]) {
@@ -114,4 +145,4 @@ var BABYLON;
     })();
     BABYLON.PostProcessRenderPipeline = PostProcessRenderPipeline;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.postProcessRenderPipeline.js.map
+//# sourceMappingURL=babylon.postProcessRenderPipeline.js.map

+ 20 - 1
Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPipelineManager.js

@@ -7,48 +7,67 @@ var BABYLON;
         PostProcessRenderPipelineManager.prototype.addPipeline = function (renderPipeline) {
             this._renderPipelines[renderPipeline._name] = renderPipeline;
         };
+
         PostProcessRenderPipelineManager.prototype.attachCamerasToRenderPipeline = function (renderPipelineName, cameras, unique) {
             var renderPipeline = this._renderPipelines[renderPipelineName];
+
             if (!renderPipeline) {
                 return;
             }
+
             renderPipeline._attachCameras(cameras, unique);
         };
+
         PostProcessRenderPipelineManager.prototype.detachCamerasFromRenderPipeline = function (renderPipelineName, cameras) {
             var renderPipeline = this._renderPipelines[renderPipelineName];
+
             if (!renderPipeline) {
                 return;
             }
+
             renderPipeline._detachCameras(cameras);
         };
+
         PostProcessRenderPipelineManager.prototype.enableEffectInPipeline = function (renderPipelineName, renderEffectName, cameras) {
             var renderPipeline = this._renderPipelines[renderPipelineName];
+
             if (!renderPipeline) {
                 return;
             }
+
             renderPipeline._enableEffect(renderEffectName, cameras);
         };
+
         PostProcessRenderPipelineManager.prototype.disableEffectInPipeline = function (renderPipelineName, renderEffectName, cameras) {
             var renderPipeline = this._renderPipelines[renderPipelineName];
+
             if (!renderPipeline) {
                 return;
             }
+
             renderPipeline._disableEffect(renderEffectName, cameras);
         };
+
         PostProcessRenderPipelineManager.prototype.enableDisplayOnlyPassInPipeline = function (renderPipelineName, passName, cameras) {
             var renderPipeline = this._renderPipelines[renderPipelineName];
+
             if (!renderPipeline) {
                 return;
             }
+
             renderPipeline._enableDisplayOnlyPass(passName, cameras);
         };
+
         PostProcessRenderPipelineManager.prototype.disableDisplayOnlyPassInPipeline = function (renderPipelineName, cameras) {
             var renderPipeline = this._renderPipelines[renderPipelineName];
+
             if (!renderPipeline) {
                 return;
             }
+
             renderPipeline._disableDisplayOnlyPass(cameras);
         };
+
         PostProcessRenderPipelineManager.prototype.update = function () {
             for (var renderPipelineName in this._renderPipelines) {
                 this._renderPipelines[renderPipelineName]._update();
@@ -58,4 +77,4 @@ var BABYLON;
     })();
     BABYLON.PostProcessRenderPipelineManager = PostProcessRenderPipelineManager;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.postProcessRenderPipelineManager.js.map
+//# sourceMappingURL=babylon.postProcessRenderPipelineManager.js.map

+ 2 - 2
Babylon/PostProcess/babylon.anaglyphPostProcess.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -15,4 +15,4 @@ var BABYLON;
     })(BABYLON.PostProcess);
     BABYLON.AnaglyphPostProcess = AnaglyphPostProcess;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.anaglyphPostProcess.js.map
+//# sourceMappingURL=babylon.anaglyphPostProcess.js.map

+ 2 - 2
Babylon/PostProcess/babylon.blackAndWhitePostProcess.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -15,4 +15,4 @@ var BABYLON;
     })(BABYLON.PostProcess);
     BABYLON.BlackAndWhitePostProcess = BlackAndWhitePostProcess;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.blackAndWhitePostProcess.js.map
+//# sourceMappingURL=babylon.blackAndWhitePostProcess.js.map

+ 3 - 3
Babylon/PostProcess/babylon.blurPostProcess.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -9,8 +9,8 @@ var BABYLON;
     var BlurPostProcess = (function (_super) {
         __extends(BlurPostProcess, _super);
         function BlurPostProcess(name, direction, blurWidth, ratio, camera, samplingMode, engine, reusable) {
+            if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.BILINEAR_SAMPLINGMODE; }
             var _this = this;
-            if (samplingMode === void 0) { samplingMode = BABYLON.Texture.BILINEAR_SAMPLINGMODE; }
             _super.call(this, name, "blur", ["screenSize", "direction", "blurWidth"], null, ratio, camera, samplingMode, engine, reusable);
             this.direction = direction;
             this.blurWidth = blurWidth;
@@ -24,4 +24,4 @@ var BABYLON;
     })(BABYLON.PostProcess);
     BABYLON.BlurPostProcess = BlurPostProcess;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.blurPostProcess.js.map
+//# sourceMappingURL=babylon.blurPostProcess.js.map

+ 3 - 4
Babylon/PostProcess/babylon.convolutionPostProcess.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -12,13 +12,12 @@ var BABYLON;
             var _this = this;
             _super.call(this, name, "convolution", ["kernel", "screenSize"], null, ratio, camera, samplingMode, engine, reusable);
             this.kernel = kernel;
+
             this.onApply = function (effect) {
                 effect.setFloat2("screenSize", _this.width, _this.height);
                 effect.setArray("kernel", _this.kernel);
             };
         }
-        // Statics
-        // Based on http://en.wikipedia.org/wiki/Kernel_(image_processing)
         ConvolutionPostProcess.EdgeDetect0Kernel = [1, 0, -1, 0, 0, 0, -1, 0, 1];
         ConvolutionPostProcess.EdgeDetect1Kernel = [0, 1, 0, 1, -4, 1, 0, 1, 0];
         ConvolutionPostProcess.EdgeDetect2Kernel = [-1, -1, -1, -1, 8, -1, -1, -1, -1];
@@ -29,4 +28,4 @@ var BABYLON;
     })(BABYLON.PostProcess);
     BABYLON.ConvolutionPostProcess = ConvolutionPostProcess;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.convolutionPostProcess.js.map
+//# sourceMappingURL=babylon.convolutionPostProcess.js.map

+ 2 - 2
Babylon/PostProcess/babylon.displayPassPostProcess.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -15,4 +15,4 @@ var BABYLON;
     })(BABYLON.PostProcess);
     BABYLON.DisplayPassPostProcess = DisplayPassPostProcess;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.displayPassPostProcess.js.map
+//# sourceMappingURL=babylon.displayPassPostProcess.js.map

+ 3 - 2
Babylon/PostProcess/babylon.filterPostProcess.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -12,6 +12,7 @@ var BABYLON;
             var _this = this;
             _super.call(this, name, "filter", ["kernelMatrix"], null, ratio, camera, samplingMode, engine, reusable);
             this.kernelMatrix = kernelMatrix;
+
             this.onApply = function (effect) {
                 effect.setMatrix("kernelMatrix", _this.kernelMatrix);
             };
@@ -20,4 +21,4 @@ var BABYLON;
     })(BABYLON.PostProcess);
     BABYLON.FilterPostProcess = FilterPostProcess;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.filterPostProcess.js.map
+//# sourceMappingURL=babylon.filterPostProcess.js.map

+ 3 - 2
Babylon/PostProcess/babylon.fxaaPostProcess.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -11,6 +11,7 @@ var BABYLON;
         function FxaaPostProcess(name, ratio, camera, samplingMode, engine, reusable) {
             var _this = this;
             _super.call(this, name, "fxaa", ["texelSize"], null, ratio, camera, samplingMode, engine, reusable);
+
             this.onSizeChanged = function () {
                 _this.texelWidth = 1.0 / _this.width;
                 _this.texelHeight = 1.0 / _this.height;
@@ -23,4 +24,4 @@ var BABYLON;
     })(BABYLON.PostProcess);
     BABYLON.FxaaPostProcess = FxaaPostProcess;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.fxaaPostProcess.js.map
+//# sourceMappingURL=babylon.fxaaPostProcess.js.map

+ 4 - 2
Babylon/PostProcess/babylon.oculusDistortionCorrectionPostProcess.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -17,10 +17,12 @@ var BABYLON;
                 'ScaleIn',
                 'HmdWarpParam'
             ], null, cameraSettings.PostProcessScaleFactor, camera, BABYLON.Texture.BILINEAR_SAMPLINGMODE, null, null);
+
             this._isRightEye = isRightEye;
             this._distortionFactors = cameraSettings.DistortionK;
             this._postProcessScaleFactor = cameraSettings.PostProcessScaleFactor;
             this._lensCenterOffset = cameraSettings.LensCenterOffset;
+
             this.onSizeChanged = function () {
                 _this.aspectRatio = _this.width * .5 / _this.height;
                 _this._scaleIn = new BABYLON.Vector2(2, 2 / _this.aspectRatio);
@@ -38,4 +40,4 @@ var BABYLON;
     })(BABYLON.PostProcess);
     BABYLON.OculusDistortionCorrectionPostProcess = OculusDistortionCorrectionPostProcess;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.oculusDistortionCorrectionPostProcess.js.map
+//# sourceMappingURL=babylon.oculusDistortionCorrectionPostProcess.js.map

+ 2 - 2
Babylon/PostProcess/babylon.passPostProcess.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+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;
@@ -15,4 +15,4 @@ var BABYLON;
     })(BABYLON.PostProcess);
     BABYLON.PassPostProcess = PassPostProcess;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.passPostProcess.js.map
+//# sourceMappingURL=babylon.passPostProcess.js.map

+ 0 - 0
Babylon/PostProcess/babylon.postProcess.js


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików