David Catuhe 7 سال پیش
والد
کامیت
4e89757d69

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 12427 - 12409
dist/preview release/babylon.d.ts


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 22 - 21
dist/preview release/babylon.js


+ 171 - 69
dist/preview release/babylon.max.js

@@ -6106,19 +6106,19 @@ var BABYLON;
                 document.msCancelFullScreen();
                 document.msCancelFullScreen();
             }
             }
         };
         };
-        Tools.SetCorsBehavior = function (url, img) {
+        Tools.SetCorsBehavior = function (url, element) {
+            if (url && url.indexOf("data:") === 0) {
+                return;
+            }
             if (Tools.CorsBehavior) {
             if (Tools.CorsBehavior) {
-                switch (typeof (Tools.CorsBehavior)) {
-                    case "function":
-                        var result = Tools.CorsBehavior(url);
-                        if (result) {
-                            img.crossOrigin = result;
-                        }
-                        break;
-                    case "string":
-                    default:
-                        img.crossOrigin = Tools.CorsBehavior;
-                        break;
+                if (typeof (Tools.CorsBehavior) === 'string' || Tools.CorsBehavior instanceof String) {
+                    element.crossOrigin = Tools.CorsBehavior;
+                }
+                else {
+                    var result = Tools.CorsBehavior(url);
+                    if (result) {
+                        element.crossOrigin = result;
+                    }
                 }
                 }
             }
             }
         };
         };
@@ -6134,9 +6134,7 @@ var BABYLON;
             url = Tools.CleanUrl(url);
             url = Tools.CleanUrl(url);
             url = Tools.PreprocessUrl(url);
             url = Tools.PreprocessUrl(url);
             var img = new Image();
             var img = new Image();
-            if (url.substr(0, 5) !== "data:") {
-                Tools.SetCorsBehavior(url, img);
-            }
+            Tools.SetCorsBehavior(url, img);
             img.onload = function () {
             img.onload = function () {
                 onLoad(img);
                 onLoad(img);
             };
             };
@@ -6947,6 +6945,11 @@ var BABYLON;
             return hash;
             return hash;
         };
         };
         Tools.BaseUrl = "";
         Tools.BaseUrl = "";
+        /**
+         * Default behaviour for cors in the application.
+         * It can be a string if the expected behavior is identical in the entire app.
+         * Or a callback to be able to set it per url or on a group of them (in case of Video source for instance)
+         */
         Tools.CorsBehavior = "anonymous";
         Tools.CorsBehavior = "anonymous";
         Tools.UseFallbackTexture = true;
         Tools.UseFallbackTexture = true;
         /**
         /**
@@ -12692,6 +12695,10 @@ var BABYLON;
             }
             }
             return serializationRanges;
             return serializationRanges;
         };
         };
+        // override it in derived class
+        Node.prototype.computeWorldMatrix = function (force) {
+            return BABYLON.Matrix.Identity();
+        };
         Node.prototype.dispose = function () {
         Node.prototype.dispose = function () {
             this.parent = null;
             this.parent = null;
             // Callback
             // Callback
@@ -17152,6 +17159,9 @@ var BABYLON;
                     return function () { return new BABYLON.UniversalCamera(name, BABYLON.Vector3.Zero(), scene); };
                     return function () { return new BABYLON.UniversalCamera(name, BABYLON.Vector3.Zero(), scene); };
             }
             }
         };
         };
+        Camera.prototype.computeWorldMatrix = function () {
+            return this.getWorldMatrix();
+        };
         Camera.Parse = function (parsedCamera, scene) {
         Camera.Parse = function (parsedCamera, scene) {
             var type = parsedCamera.type;
             var type = parsedCamera.type;
             var construct = Camera.GetConstructorFromName(type, parsedCamera.name, scene, parsedCamera.interaxial_distance, parsedCamera.isStereoscopicSideBySide);
             var construct = Camera.GetConstructorFromName(type, parsedCamera.name, scene, parsedCamera.interaxial_distance, parsedCamera.isStereoscopicSideBySide);
@@ -20666,7 +20676,7 @@ var BABYLON;
                 var defaultFPS = (60.0 / 1000.0);
                 var defaultFPS = (60.0 / 1000.0);
                 var defaultFrameTime = 1000 / 60; // frame time in MS
                 var defaultFrameTime = 1000 / 60; // frame time in MS
                 if (this._physicsEngine) {
                 if (this._physicsEngine) {
-                    defaultFrameTime = this._physicsEngine.getTimeStep() / 1000; //timestep in physics engine is in seconds
+                    defaultFrameTime = this._physicsEngine.getTimeStep() / 1000;
                 }
                 }
                 var stepsTaken = 0;
                 var stepsTaken = 0;
                 var maxSubSteps = this._engine.getLockstepMaxSteps();
                 var maxSubSteps = this._engine.getLockstepMaxSteps();
@@ -21603,7 +21613,7 @@ var BABYLON;
             forEach = forEach || (function (item) { return; });
             forEach = forEach || (function (item) { return; });
             for (var i in list) {
             for (var i in list) {
                 var item = list[i];
                 var item = list[i];
-                if (BABYLON.Tags.MatchesQuery(item, tagsQuery)) {
+                if (BABYLON.Tags && BABYLON.Tags.MatchesQuery(item, tagsQuery)) {
                     listByTags.push(item);
                     listByTags.push(item);
                     forEach(item);
                     forEach(item);
                 }
                 }
@@ -23141,7 +23151,7 @@ var BABYLON;
                 // Deep copy
                 // Deep copy
                 BABYLON.Tools.DeepCopy(source, _this, ["name", "material", "skeleton", "instances", "parent", "uniqueId", "source"], ["_poseMatrix", "_source"]);
                 BABYLON.Tools.DeepCopy(source, _this, ["name", "material", "skeleton", "instances", "parent", "uniqueId", "source"], ["_poseMatrix", "_source"]);
                 // Tags
                 // Tags
-                if (BABYLON.Tags.HasTags(source)) {
+                if (BABYLON.Tags && BABYLON.Tags.HasTags(source)) {
                     BABYLON.Tags.AddTagsTo(_this, BABYLON.Tags.GetTags(source, true));
                     BABYLON.Tags.AddTagsTo(_this, BABYLON.Tags.GetTags(source, true));
                 }
                 }
                 _this.metadata = source.metadata;
                 _this.metadata = source.metadata;
@@ -49699,7 +49709,7 @@ var BABYLON;
                                         this._htmlAudioElement = new Audio(url);
                                         this._htmlAudioElement = new Audio(url);
                                         this._htmlAudioElement.controls = false;
                                         this._htmlAudioElement.controls = false;
                                         this._htmlAudioElement.loop = this.loop;
                                         this._htmlAudioElement.loop = this.loop;
-                                        this._htmlAudioElement.crossOrigin = "anonymous";
+                                        BABYLON.Tools.SetCorsBehavior(url, this._htmlAudioElement);
                                         this._htmlAudioElement.preload = "auto";
                                         this._htmlAudioElement.preload = "auto";
                                         this._htmlAudioElement.addEventListener("canplaythrough", function () {
                                         this._htmlAudioElement.addEventListener("canplaythrough", function () {
                                             _this._isReadyToPlay = true;
                                             _this._isReadyToPlay = true;
@@ -51723,6 +51733,7 @@ var BABYLON;
                 _this.video = document.createElement("video");
                 _this.video = document.createElement("video");
                 _this.video.autoplay = false;
                 _this.video.autoplay = false;
                 _this.video.loop = true;
                 _this.video.loop = true;
+                BABYLON.Tools.SetCorsBehavior(urls, _this.video);
             }
             }
             _this._engine = _this.getScene().getEngine();
             _this._engine = _this.getScene().getEngine();
             _this._generateMipMaps = generateMipMaps;
             _this._generateMipMaps = generateMipMaps;
@@ -55569,7 +55580,9 @@ var BABYLON;
             var serializationObject = {};
             var serializationObject = {};
             serializationObject.name = this.name;
             serializationObject.name = this.name;
             serializationObject.id = this.id;
             serializationObject.id = this.id;
-            serializationObject.tags = BABYLON.Tags.GetTags(this);
+            if (BABYLON.Tags) {
+                serializationObject.tags = BABYLON.Tags.GetTags(this);
+            }
             serializationObject.materials = [];
             serializationObject.materials = [];
             for (var matIndex = 0; matIndex < this.subMaterials.length; matIndex++) {
             for (var matIndex = 0; matIndex < this.subMaterials.length; matIndex++) {
                 var subMat = this.subMaterials[matIndex];
                 var subMat = this.subMaterials[matIndex];
@@ -71733,6 +71746,16 @@ var BABYLON;
                     if (webVrController.defaultModel) {
                     if (webVrController.defaultModel) {
                         webVrController.defaultModel.setEnabled(false);
                         webVrController.defaultModel.setEnabled(false);
                     }
                     }
+                    if (webVrController.hand === "right") {
+                        _this._rightController = null;
+                    }
+                    if (webVrController.hand === "left") {
+                        _this._rightController = null;
+                    }
+                    var controllerIndex = _this.controllers.indexOf(webVrController);
+                    if (controllerIndex !== -1) {
+                        _this.controllers.splice(controllerIndex, 1);
+                    }
                 }
                 }
             });
             });
             this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add(function (gamepad) {
             this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add(function (gamepad) {
@@ -72079,32 +72102,44 @@ var BABYLON;
             this._displayLaserPointer = true;
             this._displayLaserPointer = true;
             this._workingVector = BABYLON.Vector3.Zero();
             this._workingVector = BABYLON.Vector3.Zero();
             this._scene = scene;
             this._scene = scene;
+            this._canvas = scene.getEngine().getRenderingCanvas();
             this._defaultHeight = webVROptions.defaultHeight || 1.7;
             this._defaultHeight = webVROptions.defaultHeight || 1.7;
-            if (!this._scene.activeCamera || isNaN(this._scene.activeCamera.position.x)) {
-                this._position = new BABYLON.Vector3(0, this._defaultHeight, 0);
-                this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position.clone(), scene);
+            if (webVROptions.createFallbackVRDeviceOrientationFreeCamera === undefined) {
+                webVROptions.createFallbackVRDeviceOrientationFreeCamera = true;
             }
             }
-            else {
-                this._position = this._scene.activeCamera.position.clone();
-                this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position.clone(), scene);
-                this._deviceOrientationCamera.minZ = this._scene.activeCamera.minZ;
-                this._deviceOrientationCamera.maxZ = this._scene.activeCamera.maxZ;
-                // Set rotation from previous camera
-                if (this._scene.activeCamera instanceof BABYLON.TargetCamera && this._scene.activeCamera.rotation) {
-                    var targetCamera = this._scene.activeCamera;
-                    if (targetCamera.rotationQuaternion) {
-                        this._deviceOrientationCamera.rotationQuaternion.copyFrom(targetCamera.rotationQuaternion);
-                    }
-                    else {
-                        this._deviceOrientationCamera.rotationQuaternion.copyFrom(BABYLON.Quaternion.RotationYawPitchRoll(targetCamera.rotation.y, targetCamera.rotation.x, targetCamera.rotation.z));
+            if (webVROptions.createDeviceOrientationCamera === undefined) {
+                webVROptions.createDeviceOrientationCamera = true;
+            }
+            if (!this._scene.activeCamera || webVROptions.createDeviceOrientationCamera) {
+                if (!this._scene.activeCamera || isNaN(this._scene.activeCamera.position.x)) {
+                    this._position = new BABYLON.Vector3(0, this._defaultHeight, 0);
+                    this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position.clone(), scene);
+                }
+                else {
+                    this._position = this._scene.activeCamera.position.clone();
+                    this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position.clone(), scene);
+                    this._deviceOrientationCamera.minZ = this._scene.activeCamera.minZ;
+                    this._deviceOrientationCamera.maxZ = this._scene.activeCamera.maxZ;
+                    // Set rotation from previous camera
+                    if (this._scene.activeCamera instanceof BABYLON.TargetCamera && this._scene.activeCamera.rotation) {
+                        var targetCamera = this._scene.activeCamera;
+                        if (targetCamera.rotationQuaternion) {
+                            this._deviceOrientationCamera.rotationQuaternion.copyFrom(targetCamera.rotationQuaternion);
+                        }
+                        else {
+                            this._deviceOrientationCamera.rotationQuaternion.copyFrom(BABYLON.Quaternion.RotationYawPitchRoll(targetCamera.rotation.y, targetCamera.rotation.x, targetCamera.rotation.z));
+                        }
+                        this._deviceOrientationCamera.rotation = targetCamera.rotation.clone();
                     }
                     }
-                    this._deviceOrientationCamera.rotation = targetCamera.rotation.clone();
+                }
+                this._scene.activeCamera = this._deviceOrientationCamera;
+                if (this._canvas) {
+                    this._scene.activeCamera.attachControl(this._canvas);
                 }
                 }
             }
             }
-            this._scene.activeCamera = this._deviceOrientationCamera;
-            this._canvas = scene.getEngine().getRenderingCanvas();
-            if (this._canvas) {
-                this._scene.activeCamera.attachControl(this._canvas);
+            else {
+                this._existingCamera = this._scene.activeCamera;
+                this._position = this._scene.activeCamera.position.clone();
             }
             }
             if (webVROptions) {
             if (webVROptions) {
                 if (webVROptions.useCustomVRButton) {
                 if (webVROptions.useCustomVRButton) {
@@ -72156,8 +72191,15 @@ var BABYLON;
             document.addEventListener("mozfullscreenchange", function () { _this._onFullscreenChange(); }, false);
             document.addEventListener("mozfullscreenchange", function () { _this._onFullscreenChange(); }, false);
             document.addEventListener("webkitfullscreenchange", function () { _this._onFullscreenChange(); }, false);
             document.addEventListener("webkitfullscreenchange", function () { _this._onFullscreenChange(); }, false);
             document.addEventListener("msfullscreenchange", function () { _this._onFullscreenChange(); }, false);
             document.addEventListener("msfullscreenchange", function () { _this._onFullscreenChange(); }, false);
-            if (!this._useCustomVRButton) {
+            this._scene.getEngine().onVRDisplayChangedObservable.add(function (e) {
+                if (!_this._useCustomVRButton && !_this._btnVRDisplayed && e.vrDisplay) {
+                    document.body.appendChild(_this._btnVR);
+                    _this._btnVRDisplayed = true;
+                }
+            });
+            if (!this._useCustomVRButton && !this._btnVRDisplayed && webVROptions.createFallbackVRDeviceOrientationFreeCamera) {
                 document.body.appendChild(this._btnVR);
                 document.body.appendChild(this._btnVR);
+                this._btnVRDisplayed = true;
             }
             }
             // Exiting VR mode using 'ESC' key on desktop
             // Exiting VR mode using 'ESC' key on desktop
             this._onKeyDown = function (event) {
             this._onKeyDown = function (event) {
@@ -72191,10 +72233,13 @@ var BABYLON;
             scene.getEngine().onVRRequestPresentComplete.add(this._onVRRequestPresentComplete);
             scene.getEngine().onVRRequestPresentComplete.add(this._onVRRequestPresentComplete);
             window.addEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
             window.addEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
             // Create the cameras
             // Create the cameras
-            this._vrDeviceOrientationCamera = new BABYLON.VRDeviceOrientationFreeCamera("VRDeviceOrientationVRHelper", this._position, this._scene);
+            if (webVROptions.createFallbackVRDeviceOrientationFreeCamera) {
+                this._vrDeviceOrientationCamera = new BABYLON.VRDeviceOrientationFreeCamera("VRDeviceOrientationVRHelper", this._position, this._scene);
+            }
             this._webVRCamera = new BABYLON.WebVRFreeCamera("WebVRHelper", this._position, this._scene, webVROptions);
             this._webVRCamera = new BABYLON.WebVRFreeCamera("WebVRHelper", this._position, this._scene, webVROptions);
             this._webVRCamera.onControllerMeshLoadedObservable.add(function (webVRController) { return _this._onDefaultMeshLoaded(webVRController); });
             this._webVRCamera.onControllerMeshLoadedObservable.add(function (webVRController) { return _this._onDefaultMeshLoaded(webVRController); });
             this._scene.gamepadManager.onGamepadConnectedObservable.add(function (pad) { return _this._onNewGamepadConnected(pad); });
             this._scene.gamepadManager.onGamepadConnectedObservable.add(function (pad) { return _this._onNewGamepadConnected(pad); });
+            this._scene.gamepadManager.onGamepadDisconnectedObservable.add(function (pad) { return _this._onNewGamepadDisconnected(pad); });
             this.updateButtonVisibility();
             this.updateButtonVisibility();
             //create easing functions
             //create easing functions
             this._circleEase = new BABYLON.CircleEase();
             this._circleEase = new BABYLON.CircleEase();
@@ -72245,7 +72290,7 @@ var BABYLON;
                     return this._webVRCamera;
                     return this._webVRCamera;
                 }
                 }
                 else {
                 else {
-                    return this._vrDeviceOrientationCamera;
+                    return this._scene.activeCamera;
                 }
                 }
             },
             },
             enumerable: true,
             enumerable: true,
@@ -72363,7 +72408,7 @@ var BABYLON;
             }
             }
             if (this.onEnteringVR) {
             if (this.onEnteringVR) {
                 try {
                 try {
-                    this.onEnteringVR.notifyObservers({});
+                    this.onEnteringVR.notifyObservers(this);
                 }
                 }
                 catch (err) {
                 catch (err) {
                     BABYLON.Tools.Warn("Error in your custom logic onEnteringVR: " + err);
                     BABYLON.Tools.Warn("Error in your custom logic onEnteringVR: " + err);
@@ -72378,7 +72423,7 @@ var BABYLON;
                     this._scene.activeCamera = this._webVRCamera;
                     this._scene.activeCamera = this._webVRCamera;
                 }
                 }
             }
             }
-            else {
+            else if (this._vrDeviceOrientationCamera) {
                 this._vrDeviceOrientationCamera.position = this._position;
                 this._vrDeviceOrientationCamera.position = this._position;
                 this._scene.activeCamera = this._vrDeviceOrientationCamera;
                 this._scene.activeCamera = this._vrDeviceOrientationCamera;
                 this._scene.getEngine().switchFullscreen(true);
                 this._scene.getEngine().switchFullscreen(true);
@@ -72394,7 +72439,7 @@ var BABYLON;
         VRExperienceHelper.prototype.exitVR = function () {
         VRExperienceHelper.prototype.exitVR = function () {
             if (this.onExitingVR) {
             if (this.onExitingVR) {
                 try {
                 try {
-                    this.onExitingVR.notifyObservers({});
+                    this.onExitingVR.notifyObservers(this);
                 }
                 }
                 catch (err) {
                 catch (err) {
                     BABYLON.Tools.Warn("Error in your custom logic onExitingVR: " + err);
                     BABYLON.Tools.Warn("Error in your custom logic onExitingVR: " + err);
@@ -72406,10 +72451,16 @@ var BABYLON;
             if (this._scene.activeCamera) {
             if (this._scene.activeCamera) {
                 this._position = this._scene.activeCamera.position.clone();
                 this._position = this._scene.activeCamera.position.clone();
             }
             }
-            this._deviceOrientationCamera.position = this._position;
-            this._scene.activeCamera = this._deviceOrientationCamera;
-            if (this._canvas) {
-                this._scene.activeCamera.attachControl(this._canvas);
+            if (this._deviceOrientationCamera) {
+                this._deviceOrientationCamera.position = this._position;
+                this._scene.activeCamera = this._deviceOrientationCamera;
+                if (this._canvas) {
+                    this._scene.activeCamera.attachControl(this._canvas);
+                }
+            }
+            else if (this._existingCamera) {
+                this._existingCamera.position = this._position;
+                this._scene.activeCamera = this._existingCamera;
             }
             }
             this.updateButtonVisibility();
             this.updateButtonVisibility();
         };
         };
@@ -72464,11 +72515,29 @@ var BABYLON;
                     return true;
                     return true;
                 }
                 }
             }
             }
-            if (this._floorMeshName && mesh.name.indexOf(this._floorMeshName) !== -1) {
+            if (this._floorMeshName && mesh.name === this._floorMeshName) {
                 return true;
                 return true;
             }
             }
             return false;
             return false;
         };
         };
+        VRExperienceHelper.prototype.addFloorMesh = function (floorMesh) {
+            if (!this._floorMeshesCollection) {
+                return;
+            }
+            if (this._floorMeshesCollection.indexOf(floorMesh) > -1) {
+                return;
+            }
+            this._floorMeshesCollection.push(floorMesh);
+        };
+        VRExperienceHelper.prototype.removeFloorMesh = function (floorMesh) {
+            if (!this._floorMeshesCollection) {
+                return;
+            }
+            var meshIndex = this._floorMeshesCollection.indexOf(floorMesh);
+            if (meshIndex !== -1) {
+                this._floorMeshesCollection.splice(meshIndex, 1);
+            }
+        };
         VRExperienceHelper.prototype.enableTeleportation = function (vrTeleportationOptions) {
         VRExperienceHelper.prototype.enableTeleportation = function (vrTeleportationOptions) {
             if (vrTeleportationOptions === void 0) { vrTeleportationOptions = {}; }
             if (vrTeleportationOptions === void 0) { vrTeleportationOptions = {}; }
             if (!this._teleportationEnabled) {
             if (!this._teleportationEnabled) {
@@ -72580,6 +72649,26 @@ var BABYLON;
                 }
                 }
             }
             }
         };
         };
+        VRExperienceHelper.prototype._onNewGamepadDisconnected = function (gamepad) {
+            if (gamepad instanceof BABYLON.WebVRController) {
+                if (gamepad.hand === "left") {
+                    this._interactionsEnabledOnLeftController = false;
+                    this._teleportationEnabledOnLeftController = false;
+                    this._leftControllerReady = false;
+                    if (this._leftLaserPointer) {
+                        this._leftLaserPointer.dispose();
+                    }
+                }
+                if (gamepad.hand === "right") {
+                    this._interactionsEnabledOnRightController = false;
+                    this._teleportationEnabledOnRightController = false;
+                    this._rightControllerReady = false;
+                    if (this._rightLaserPointer) {
+                        this._rightLaserPointer.dispose();
+                    }
+                }
+            }
+        };
         VRExperienceHelper.prototype._enableInteractionOnController = function (webVRController) {
         VRExperienceHelper.prototype._enableInteractionOnController = function (webVRController) {
             var _this = this;
             var _this = this;
             var controllerMesh = webVRController.mesh;
             var controllerMesh = webVRController.mesh;
@@ -72791,6 +72880,9 @@ var BABYLON;
         };
         };
         VRExperienceHelper.prototype._rotateCamera = function (right) {
         VRExperienceHelper.prototype._rotateCamera = function (right) {
             var _this = this;
             var _this = this;
+            if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
+                return;
+            }
             if (right) {
             if (right) {
                 this._rotationAngle++;
                 this._rotationAngle++;
             }
             }
@@ -72866,7 +72958,7 @@ var BABYLON;
                 }
                 }
                 this._haloCenter.copyFrom(hit.pickedPoint);
                 this._haloCenter.copyFrom(hit.pickedPoint);
                 this._teleportationCircle.position.copyFrom(hit.pickedPoint);
                 this._teleportationCircle.position.copyFrom(hit.pickedPoint);
-                var pickNormal = hit.getNormal();
+                var pickNormal = hit.getNormal(true, false);
                 if (pickNormal) {
                 if (pickNormal) {
                     var axis1 = BABYLON.Vector3.Cross(BABYLON.Axis.Y, pickNormal);
                     var axis1 = BABYLON.Vector3.Cross(BABYLON.Axis.Y, pickNormal);
                     var axis2 = BABYLON.Vector3.Cross(pickNormal, axis1);
                     var axis2 = BABYLON.Vector3.Cross(pickNormal, axis1);
@@ -72877,10 +72969,19 @@ var BABYLON;
         };
         };
         VRExperienceHelper.prototype._teleportCamera = function () {
         VRExperienceHelper.prototype._teleportCamera = function () {
             var _this = this;
             var _this = this;
+            if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
+                return;
+            }
             // Teleport the hmd to where the user is looking by moving the anchor to where they are looking minus the
             // Teleport the hmd to where the user is looking by moving the anchor to where they are looking minus the
             // offset of the headset from the anchor. Then add the helper's position to account for user's height offset
             // offset of the headset from the anchor. Then add the helper's position to account for user's height offset
-            this.webVRCamera.leftCamera.globalPosition.subtractToRef(this.webVRCamera.position, this._workingVector);
-            this._haloCenter.subtractToRef(this._workingVector, this._workingVector);
+            if (this.webVRCamera.leftCamera) {
+                this._workingVector.copyFrom(this.webVRCamera.leftCamera.globalPosition);
+                this._workingVector.subtractInPlace(this.webVRCamera.position);
+                this._haloCenter.subtractToRef(this._workingVector, this._workingVector);
+            }
+            else {
+                this._workingVector.copyFrom(this._haloCenter);
+            }
             this._workingVector.y += this._defaultHeight;
             this._workingVector.y += this._defaultHeight;
             // Create animation from the camera's position to the new location
             // Create animation from the camera's position to the new location
             this.currentVRCamera.animations = [];
             this.currentVRCamera.animations = [];
@@ -72930,8 +73031,8 @@ var BABYLON;
             });
             });
             animationPP2.setKeys(vignetteStretchKeys);
             animationPP2.setKeys(vignetteStretchKeys);
             this._postProcessMove.animations.push(animationPP2);
             this._postProcessMove.animations.push(animationPP2);
-            this._postProcessMove.imageProcessingConfiguration.vignetteWeight = 8;
-            this._postProcessMove.imageProcessingConfiguration.vignetteStretch = 10;
+            this._postProcessMove.imageProcessingConfiguration.vignetteWeight = 0;
+            this._postProcessMove.imageProcessingConfiguration.vignetteStretch = 0;
             this._webVRCamera.attachPostProcess(this._postProcessMove);
             this._webVRCamera.attachPostProcess(this._postProcessMove);
             this._scene.beginAnimation(this._postProcessMove, 0, 11, false, 1, function () {
             this._scene.beginAnimation(this._postProcessMove, 0, 11, false, 1, function () {
                 _this._webVRCamera.detachPostProcess(_this._postProcessMove);
                 _this._webVRCamera.detachPostProcess(_this._postProcessMove);
@@ -72939,20 +73040,18 @@ var BABYLON;
             this._scene.beginAnimation(this.currentVRCamera, 0, 11, false, 1);
             this._scene.beginAnimation(this.currentVRCamera, 0, 11, false, 1);
         };
         };
         VRExperienceHelper.prototype._castRayAndSelectObject = function () {
         VRExperienceHelper.prototype._castRayAndSelectObject = function () {
+            if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
+                return;
+            }
             var ray;
             var ray;
-            if ((!this.currentVRCamera.rightController && !this.currentVRCamera.leftController) ||
-                (this._leftLaserPointer && !this._leftLaserPointer.isVisible && !this._rightLaserPointer) ||
-                (this._rightLaserPointer && !this._rightLaserPointer.isVisible && !this._leftLaserPointer) ||
-                (this._rightLaserPointer && this._leftLaserPointer && !this._rightLaserPointer.isVisible && !this._leftLaserPointer.isVisible)) {
-                ray = this.currentVRCamera.getForwardRay(this._rayLength);
+            if (this._leftLaserPointer && this._leftLaserPointer.isVisible && this.currentVRCamera.leftController) {
+                ray = this.currentVRCamera.leftController.getForwardRay(this._rayLength);
+            }
+            else if (this._rightLaserPointer && this._rightLaserPointer.isVisible && this.currentVRCamera.rightController) {
+                ray = this.currentVRCamera.rightController.getForwardRay(this._rayLength);
             }
             }
             else {
             else {
-                if (this._leftLaserPointer && this._leftLaserPointer.isVisible) {
-                    ray = this.currentVRCamera.leftController.getForwardRay(this._rayLength);
-                }
-                else {
-                    ray = this.currentVRCamera.rightController.getForwardRay(this._rayLength);
-                }
+                ray = this.currentVRCamera.getForwardRay(this._rayLength);
             }
             }
             var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
             var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
             // Moving the gazeTracker on the mesh face targetted
             // Moving the gazeTracker on the mesh face targetted
@@ -73074,7 +73173,9 @@ var BABYLON;
             if (this.isInVRMode()) {
             if (this.isInVRMode()) {
                 this.exitVR();
                 this.exitVR();
             }
             }
-            this._deviceOrientationCamera.dispose();
+            if (this._deviceOrientationCamera) {
+                this._deviceOrientationCamera.dispose();
+            }
             if (this._passProcessMove) {
             if (this._passProcessMove) {
                 this._passProcessMove.dispose();
                 this._passProcessMove.dispose();
             }
             }
@@ -73090,6 +73191,7 @@ var BABYLON;
             if (!this._useCustomVRButton) {
             if (!this._useCustomVRButton) {
                 document.body.removeChild(this._btnVR);
                 document.body.removeChild(this._btnVR);
             }
             }
+            this._floorMeshesCollection = [];
             document.removeEventListener("keydown", this._onKeyDown);
             document.removeEventListener("keydown", this._onKeyDown);
             window.removeEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
             window.removeEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
         };
         };

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 22 - 21
dist/preview release/babylon.worker.js


+ 171 - 69
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -6106,19 +6106,19 @@ var BABYLON;
                 document.msCancelFullScreen();
                 document.msCancelFullScreen();
             }
             }
         };
         };
-        Tools.SetCorsBehavior = function (url, img) {
+        Tools.SetCorsBehavior = function (url, element) {
+            if (url && url.indexOf("data:") === 0) {
+                return;
+            }
             if (Tools.CorsBehavior) {
             if (Tools.CorsBehavior) {
-                switch (typeof (Tools.CorsBehavior)) {
-                    case "function":
-                        var result = Tools.CorsBehavior(url);
-                        if (result) {
-                            img.crossOrigin = result;
-                        }
-                        break;
-                    case "string":
-                    default:
-                        img.crossOrigin = Tools.CorsBehavior;
-                        break;
+                if (typeof (Tools.CorsBehavior) === 'string' || Tools.CorsBehavior instanceof String) {
+                    element.crossOrigin = Tools.CorsBehavior;
+                }
+                else {
+                    var result = Tools.CorsBehavior(url);
+                    if (result) {
+                        element.crossOrigin = result;
+                    }
                 }
                 }
             }
             }
         };
         };
@@ -6134,9 +6134,7 @@ var BABYLON;
             url = Tools.CleanUrl(url);
             url = Tools.CleanUrl(url);
             url = Tools.PreprocessUrl(url);
             url = Tools.PreprocessUrl(url);
             var img = new Image();
             var img = new Image();
-            if (url.substr(0, 5) !== "data:") {
-                Tools.SetCorsBehavior(url, img);
-            }
+            Tools.SetCorsBehavior(url, img);
             img.onload = function () {
             img.onload = function () {
                 onLoad(img);
                 onLoad(img);
             };
             };
@@ -6947,6 +6945,11 @@ var BABYLON;
             return hash;
             return hash;
         };
         };
         Tools.BaseUrl = "";
         Tools.BaseUrl = "";
+        /**
+         * Default behaviour for cors in the application.
+         * It can be a string if the expected behavior is identical in the entire app.
+         * Or a callback to be able to set it per url or on a group of them (in case of Video source for instance)
+         */
         Tools.CorsBehavior = "anonymous";
         Tools.CorsBehavior = "anonymous";
         Tools.UseFallbackTexture = true;
         Tools.UseFallbackTexture = true;
         /**
         /**
@@ -12692,6 +12695,10 @@ var BABYLON;
             }
             }
             return serializationRanges;
             return serializationRanges;
         };
         };
+        // override it in derived class
+        Node.prototype.computeWorldMatrix = function (force) {
+            return BABYLON.Matrix.Identity();
+        };
         Node.prototype.dispose = function () {
         Node.prototype.dispose = function () {
             this.parent = null;
             this.parent = null;
             // Callback
             // Callback
@@ -17152,6 +17159,9 @@ var BABYLON;
                     return function () { return new BABYLON.UniversalCamera(name, BABYLON.Vector3.Zero(), scene); };
                     return function () { return new BABYLON.UniversalCamera(name, BABYLON.Vector3.Zero(), scene); };
             }
             }
         };
         };
+        Camera.prototype.computeWorldMatrix = function () {
+            return this.getWorldMatrix();
+        };
         Camera.Parse = function (parsedCamera, scene) {
         Camera.Parse = function (parsedCamera, scene) {
             var type = parsedCamera.type;
             var type = parsedCamera.type;
             var construct = Camera.GetConstructorFromName(type, parsedCamera.name, scene, parsedCamera.interaxial_distance, parsedCamera.isStereoscopicSideBySide);
             var construct = Camera.GetConstructorFromName(type, parsedCamera.name, scene, parsedCamera.interaxial_distance, parsedCamera.isStereoscopicSideBySide);
@@ -20666,7 +20676,7 @@ var BABYLON;
                 var defaultFPS = (60.0 / 1000.0);
                 var defaultFPS = (60.0 / 1000.0);
                 var defaultFrameTime = 1000 / 60; // frame time in MS
                 var defaultFrameTime = 1000 / 60; // frame time in MS
                 if (this._physicsEngine) {
                 if (this._physicsEngine) {
-                    defaultFrameTime = this._physicsEngine.getTimeStep() / 1000; //timestep in physics engine is in seconds
+                    defaultFrameTime = this._physicsEngine.getTimeStep() / 1000;
                 }
                 }
                 var stepsTaken = 0;
                 var stepsTaken = 0;
                 var maxSubSteps = this._engine.getLockstepMaxSteps();
                 var maxSubSteps = this._engine.getLockstepMaxSteps();
@@ -21603,7 +21613,7 @@ var BABYLON;
             forEach = forEach || (function (item) { return; });
             forEach = forEach || (function (item) { return; });
             for (var i in list) {
             for (var i in list) {
                 var item = list[i];
                 var item = list[i];
-                if (BABYLON.Tags.MatchesQuery(item, tagsQuery)) {
+                if (BABYLON.Tags && BABYLON.Tags.MatchesQuery(item, tagsQuery)) {
                     listByTags.push(item);
                     listByTags.push(item);
                     forEach(item);
                     forEach(item);
                 }
                 }
@@ -23141,7 +23151,7 @@ var BABYLON;
                 // Deep copy
                 // Deep copy
                 BABYLON.Tools.DeepCopy(source, _this, ["name", "material", "skeleton", "instances", "parent", "uniqueId", "source"], ["_poseMatrix", "_source"]);
                 BABYLON.Tools.DeepCopy(source, _this, ["name", "material", "skeleton", "instances", "parent", "uniqueId", "source"], ["_poseMatrix", "_source"]);
                 // Tags
                 // Tags
-                if (BABYLON.Tags.HasTags(source)) {
+                if (BABYLON.Tags && BABYLON.Tags.HasTags(source)) {
                     BABYLON.Tags.AddTagsTo(_this, BABYLON.Tags.GetTags(source, true));
                     BABYLON.Tags.AddTagsTo(_this, BABYLON.Tags.GetTags(source, true));
                 }
                 }
                 _this.metadata = source.metadata;
                 _this.metadata = source.metadata;
@@ -49545,7 +49555,7 @@ var BABYLON;
                                         this._htmlAudioElement = new Audio(url);
                                         this._htmlAudioElement = new Audio(url);
                                         this._htmlAudioElement.controls = false;
                                         this._htmlAudioElement.controls = false;
                                         this._htmlAudioElement.loop = this.loop;
                                         this._htmlAudioElement.loop = this.loop;
-                                        this._htmlAudioElement.crossOrigin = "anonymous";
+                                        BABYLON.Tools.SetCorsBehavior(url, this._htmlAudioElement);
                                         this._htmlAudioElement.preload = "auto";
                                         this._htmlAudioElement.preload = "auto";
                                         this._htmlAudioElement.addEventListener("canplaythrough", function () {
                                         this._htmlAudioElement.addEventListener("canplaythrough", function () {
                                             _this._isReadyToPlay = true;
                                             _this._isReadyToPlay = true;
@@ -51569,6 +51579,7 @@ var BABYLON;
                 _this.video = document.createElement("video");
                 _this.video = document.createElement("video");
                 _this.video.autoplay = false;
                 _this.video.autoplay = false;
                 _this.video.loop = true;
                 _this.video.loop = true;
+                BABYLON.Tools.SetCorsBehavior(urls, _this.video);
             }
             }
             _this._engine = _this.getScene().getEngine();
             _this._engine = _this.getScene().getEngine();
             _this._generateMipMaps = generateMipMaps;
             _this._generateMipMaps = generateMipMaps;
@@ -55415,7 +55426,9 @@ var BABYLON;
             var serializationObject = {};
             var serializationObject = {};
             serializationObject.name = this.name;
             serializationObject.name = this.name;
             serializationObject.id = this.id;
             serializationObject.id = this.id;
-            serializationObject.tags = BABYLON.Tags.GetTags(this);
+            if (BABYLON.Tags) {
+                serializationObject.tags = BABYLON.Tags.GetTags(this);
+            }
             serializationObject.materials = [];
             serializationObject.materials = [];
             for (var matIndex = 0; matIndex < this.subMaterials.length; matIndex++) {
             for (var matIndex = 0; matIndex < this.subMaterials.length; matIndex++) {
                 var subMat = this.subMaterials[matIndex];
                 var subMat = this.subMaterials[matIndex];
@@ -71579,6 +71592,16 @@ var BABYLON;
                     if (webVrController.defaultModel) {
                     if (webVrController.defaultModel) {
                         webVrController.defaultModel.setEnabled(false);
                         webVrController.defaultModel.setEnabled(false);
                     }
                     }
+                    if (webVrController.hand === "right") {
+                        _this._rightController = null;
+                    }
+                    if (webVrController.hand === "left") {
+                        _this._rightController = null;
+                    }
+                    var controllerIndex = _this.controllers.indexOf(webVrController);
+                    if (controllerIndex !== -1) {
+                        _this.controllers.splice(controllerIndex, 1);
+                    }
                 }
                 }
             });
             });
             this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add(function (gamepad) {
             this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add(function (gamepad) {
@@ -71925,32 +71948,44 @@ var BABYLON;
             this._displayLaserPointer = true;
             this._displayLaserPointer = true;
             this._workingVector = BABYLON.Vector3.Zero();
             this._workingVector = BABYLON.Vector3.Zero();
             this._scene = scene;
             this._scene = scene;
+            this._canvas = scene.getEngine().getRenderingCanvas();
             this._defaultHeight = webVROptions.defaultHeight || 1.7;
             this._defaultHeight = webVROptions.defaultHeight || 1.7;
-            if (!this._scene.activeCamera || isNaN(this._scene.activeCamera.position.x)) {
-                this._position = new BABYLON.Vector3(0, this._defaultHeight, 0);
-                this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position.clone(), scene);
+            if (webVROptions.createFallbackVRDeviceOrientationFreeCamera === undefined) {
+                webVROptions.createFallbackVRDeviceOrientationFreeCamera = true;
             }
             }
-            else {
-                this._position = this._scene.activeCamera.position.clone();
-                this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position.clone(), scene);
-                this._deviceOrientationCamera.minZ = this._scene.activeCamera.minZ;
-                this._deviceOrientationCamera.maxZ = this._scene.activeCamera.maxZ;
-                // Set rotation from previous camera
-                if (this._scene.activeCamera instanceof BABYLON.TargetCamera && this._scene.activeCamera.rotation) {
-                    var targetCamera = this._scene.activeCamera;
-                    if (targetCamera.rotationQuaternion) {
-                        this._deviceOrientationCamera.rotationQuaternion.copyFrom(targetCamera.rotationQuaternion);
-                    }
-                    else {
-                        this._deviceOrientationCamera.rotationQuaternion.copyFrom(BABYLON.Quaternion.RotationYawPitchRoll(targetCamera.rotation.y, targetCamera.rotation.x, targetCamera.rotation.z));
+            if (webVROptions.createDeviceOrientationCamera === undefined) {
+                webVROptions.createDeviceOrientationCamera = true;
+            }
+            if (!this._scene.activeCamera || webVROptions.createDeviceOrientationCamera) {
+                if (!this._scene.activeCamera || isNaN(this._scene.activeCamera.position.x)) {
+                    this._position = new BABYLON.Vector3(0, this._defaultHeight, 0);
+                    this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position.clone(), scene);
+                }
+                else {
+                    this._position = this._scene.activeCamera.position.clone();
+                    this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position.clone(), scene);
+                    this._deviceOrientationCamera.minZ = this._scene.activeCamera.minZ;
+                    this._deviceOrientationCamera.maxZ = this._scene.activeCamera.maxZ;
+                    // Set rotation from previous camera
+                    if (this._scene.activeCamera instanceof BABYLON.TargetCamera && this._scene.activeCamera.rotation) {
+                        var targetCamera = this._scene.activeCamera;
+                        if (targetCamera.rotationQuaternion) {
+                            this._deviceOrientationCamera.rotationQuaternion.copyFrom(targetCamera.rotationQuaternion);
+                        }
+                        else {
+                            this._deviceOrientationCamera.rotationQuaternion.copyFrom(BABYLON.Quaternion.RotationYawPitchRoll(targetCamera.rotation.y, targetCamera.rotation.x, targetCamera.rotation.z));
+                        }
+                        this._deviceOrientationCamera.rotation = targetCamera.rotation.clone();
                     }
                     }
-                    this._deviceOrientationCamera.rotation = targetCamera.rotation.clone();
+                }
+                this._scene.activeCamera = this._deviceOrientationCamera;
+                if (this._canvas) {
+                    this._scene.activeCamera.attachControl(this._canvas);
                 }
                 }
             }
             }
-            this._scene.activeCamera = this._deviceOrientationCamera;
-            this._canvas = scene.getEngine().getRenderingCanvas();
-            if (this._canvas) {
-                this._scene.activeCamera.attachControl(this._canvas);
+            else {
+                this._existingCamera = this._scene.activeCamera;
+                this._position = this._scene.activeCamera.position.clone();
             }
             }
             if (webVROptions) {
             if (webVROptions) {
                 if (webVROptions.useCustomVRButton) {
                 if (webVROptions.useCustomVRButton) {
@@ -72002,8 +72037,15 @@ var BABYLON;
             document.addEventListener("mozfullscreenchange", function () { _this._onFullscreenChange(); }, false);
             document.addEventListener("mozfullscreenchange", function () { _this._onFullscreenChange(); }, false);
             document.addEventListener("webkitfullscreenchange", function () { _this._onFullscreenChange(); }, false);
             document.addEventListener("webkitfullscreenchange", function () { _this._onFullscreenChange(); }, false);
             document.addEventListener("msfullscreenchange", function () { _this._onFullscreenChange(); }, false);
             document.addEventListener("msfullscreenchange", function () { _this._onFullscreenChange(); }, false);
-            if (!this._useCustomVRButton) {
+            this._scene.getEngine().onVRDisplayChangedObservable.add(function (e) {
+                if (!_this._useCustomVRButton && !_this._btnVRDisplayed && e.vrDisplay) {
+                    document.body.appendChild(_this._btnVR);
+                    _this._btnVRDisplayed = true;
+                }
+            });
+            if (!this._useCustomVRButton && !this._btnVRDisplayed && webVROptions.createFallbackVRDeviceOrientationFreeCamera) {
                 document.body.appendChild(this._btnVR);
                 document.body.appendChild(this._btnVR);
+                this._btnVRDisplayed = true;
             }
             }
             // Exiting VR mode using 'ESC' key on desktop
             // Exiting VR mode using 'ESC' key on desktop
             this._onKeyDown = function (event) {
             this._onKeyDown = function (event) {
@@ -72037,10 +72079,13 @@ var BABYLON;
             scene.getEngine().onVRRequestPresentComplete.add(this._onVRRequestPresentComplete);
             scene.getEngine().onVRRequestPresentComplete.add(this._onVRRequestPresentComplete);
             window.addEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
             window.addEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
             // Create the cameras
             // Create the cameras
-            this._vrDeviceOrientationCamera = new BABYLON.VRDeviceOrientationFreeCamera("VRDeviceOrientationVRHelper", this._position, this._scene);
+            if (webVROptions.createFallbackVRDeviceOrientationFreeCamera) {
+                this._vrDeviceOrientationCamera = new BABYLON.VRDeviceOrientationFreeCamera("VRDeviceOrientationVRHelper", this._position, this._scene);
+            }
             this._webVRCamera = new BABYLON.WebVRFreeCamera("WebVRHelper", this._position, this._scene, webVROptions);
             this._webVRCamera = new BABYLON.WebVRFreeCamera("WebVRHelper", this._position, this._scene, webVROptions);
             this._webVRCamera.onControllerMeshLoadedObservable.add(function (webVRController) { return _this._onDefaultMeshLoaded(webVRController); });
             this._webVRCamera.onControllerMeshLoadedObservable.add(function (webVRController) { return _this._onDefaultMeshLoaded(webVRController); });
             this._scene.gamepadManager.onGamepadConnectedObservable.add(function (pad) { return _this._onNewGamepadConnected(pad); });
             this._scene.gamepadManager.onGamepadConnectedObservable.add(function (pad) { return _this._onNewGamepadConnected(pad); });
+            this._scene.gamepadManager.onGamepadDisconnectedObservable.add(function (pad) { return _this._onNewGamepadDisconnected(pad); });
             this.updateButtonVisibility();
             this.updateButtonVisibility();
             //create easing functions
             //create easing functions
             this._circleEase = new BABYLON.CircleEase();
             this._circleEase = new BABYLON.CircleEase();
@@ -72091,7 +72136,7 @@ var BABYLON;
                     return this._webVRCamera;
                     return this._webVRCamera;
                 }
                 }
                 else {
                 else {
-                    return this._vrDeviceOrientationCamera;
+                    return this._scene.activeCamera;
                 }
                 }
             },
             },
             enumerable: true,
             enumerable: true,
@@ -72209,7 +72254,7 @@ var BABYLON;
             }
             }
             if (this.onEnteringVR) {
             if (this.onEnteringVR) {
                 try {
                 try {
-                    this.onEnteringVR.notifyObservers({});
+                    this.onEnteringVR.notifyObservers(this);
                 }
                 }
                 catch (err) {
                 catch (err) {
                     BABYLON.Tools.Warn("Error in your custom logic onEnteringVR: " + err);
                     BABYLON.Tools.Warn("Error in your custom logic onEnteringVR: " + err);
@@ -72224,7 +72269,7 @@ var BABYLON;
                     this._scene.activeCamera = this._webVRCamera;
                     this._scene.activeCamera = this._webVRCamera;
                 }
                 }
             }
             }
-            else {
+            else if (this._vrDeviceOrientationCamera) {
                 this._vrDeviceOrientationCamera.position = this._position;
                 this._vrDeviceOrientationCamera.position = this._position;
                 this._scene.activeCamera = this._vrDeviceOrientationCamera;
                 this._scene.activeCamera = this._vrDeviceOrientationCamera;
                 this._scene.getEngine().switchFullscreen(true);
                 this._scene.getEngine().switchFullscreen(true);
@@ -72240,7 +72285,7 @@ var BABYLON;
         VRExperienceHelper.prototype.exitVR = function () {
         VRExperienceHelper.prototype.exitVR = function () {
             if (this.onExitingVR) {
             if (this.onExitingVR) {
                 try {
                 try {
-                    this.onExitingVR.notifyObservers({});
+                    this.onExitingVR.notifyObservers(this);
                 }
                 }
                 catch (err) {
                 catch (err) {
                     BABYLON.Tools.Warn("Error in your custom logic onExitingVR: " + err);
                     BABYLON.Tools.Warn("Error in your custom logic onExitingVR: " + err);
@@ -72252,10 +72297,16 @@ var BABYLON;
             if (this._scene.activeCamera) {
             if (this._scene.activeCamera) {
                 this._position = this._scene.activeCamera.position.clone();
                 this._position = this._scene.activeCamera.position.clone();
             }
             }
-            this._deviceOrientationCamera.position = this._position;
-            this._scene.activeCamera = this._deviceOrientationCamera;
-            if (this._canvas) {
-                this._scene.activeCamera.attachControl(this._canvas);
+            if (this._deviceOrientationCamera) {
+                this._deviceOrientationCamera.position = this._position;
+                this._scene.activeCamera = this._deviceOrientationCamera;
+                if (this._canvas) {
+                    this._scene.activeCamera.attachControl(this._canvas);
+                }
+            }
+            else if (this._existingCamera) {
+                this._existingCamera.position = this._position;
+                this._scene.activeCamera = this._existingCamera;
             }
             }
             this.updateButtonVisibility();
             this.updateButtonVisibility();
         };
         };
@@ -72310,11 +72361,29 @@ var BABYLON;
                     return true;
                     return true;
                 }
                 }
             }
             }
-            if (this._floorMeshName && mesh.name.indexOf(this._floorMeshName) !== -1) {
+            if (this._floorMeshName && mesh.name === this._floorMeshName) {
                 return true;
                 return true;
             }
             }
             return false;
             return false;
         };
         };
+        VRExperienceHelper.prototype.addFloorMesh = function (floorMesh) {
+            if (!this._floorMeshesCollection) {
+                return;
+            }
+            if (this._floorMeshesCollection.indexOf(floorMesh) > -1) {
+                return;
+            }
+            this._floorMeshesCollection.push(floorMesh);
+        };
+        VRExperienceHelper.prototype.removeFloorMesh = function (floorMesh) {
+            if (!this._floorMeshesCollection) {
+                return;
+            }
+            var meshIndex = this._floorMeshesCollection.indexOf(floorMesh);
+            if (meshIndex !== -1) {
+                this._floorMeshesCollection.splice(meshIndex, 1);
+            }
+        };
         VRExperienceHelper.prototype.enableTeleportation = function (vrTeleportationOptions) {
         VRExperienceHelper.prototype.enableTeleportation = function (vrTeleportationOptions) {
             if (vrTeleportationOptions === void 0) { vrTeleportationOptions = {}; }
             if (vrTeleportationOptions === void 0) { vrTeleportationOptions = {}; }
             if (!this._teleportationEnabled) {
             if (!this._teleportationEnabled) {
@@ -72426,6 +72495,26 @@ var BABYLON;
                 }
                 }
             }
             }
         };
         };
+        VRExperienceHelper.prototype._onNewGamepadDisconnected = function (gamepad) {
+            if (gamepad instanceof BABYLON.WebVRController) {
+                if (gamepad.hand === "left") {
+                    this._interactionsEnabledOnLeftController = false;
+                    this._teleportationEnabledOnLeftController = false;
+                    this._leftControllerReady = false;
+                    if (this._leftLaserPointer) {
+                        this._leftLaserPointer.dispose();
+                    }
+                }
+                if (gamepad.hand === "right") {
+                    this._interactionsEnabledOnRightController = false;
+                    this._teleportationEnabledOnRightController = false;
+                    this._rightControllerReady = false;
+                    if (this._rightLaserPointer) {
+                        this._rightLaserPointer.dispose();
+                    }
+                }
+            }
+        };
         VRExperienceHelper.prototype._enableInteractionOnController = function (webVRController) {
         VRExperienceHelper.prototype._enableInteractionOnController = function (webVRController) {
             var _this = this;
             var _this = this;
             var controllerMesh = webVRController.mesh;
             var controllerMesh = webVRController.mesh;
@@ -72637,6 +72726,9 @@ var BABYLON;
         };
         };
         VRExperienceHelper.prototype._rotateCamera = function (right) {
         VRExperienceHelper.prototype._rotateCamera = function (right) {
             var _this = this;
             var _this = this;
+            if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
+                return;
+            }
             if (right) {
             if (right) {
                 this._rotationAngle++;
                 this._rotationAngle++;
             }
             }
@@ -72712,7 +72804,7 @@ var BABYLON;
                 }
                 }
                 this._haloCenter.copyFrom(hit.pickedPoint);
                 this._haloCenter.copyFrom(hit.pickedPoint);
                 this._teleportationCircle.position.copyFrom(hit.pickedPoint);
                 this._teleportationCircle.position.copyFrom(hit.pickedPoint);
-                var pickNormal = hit.getNormal();
+                var pickNormal = hit.getNormal(true, false);
                 if (pickNormal) {
                 if (pickNormal) {
                     var axis1 = BABYLON.Vector3.Cross(BABYLON.Axis.Y, pickNormal);
                     var axis1 = BABYLON.Vector3.Cross(BABYLON.Axis.Y, pickNormal);
                     var axis2 = BABYLON.Vector3.Cross(pickNormal, axis1);
                     var axis2 = BABYLON.Vector3.Cross(pickNormal, axis1);
@@ -72723,10 +72815,19 @@ var BABYLON;
         };
         };
         VRExperienceHelper.prototype._teleportCamera = function () {
         VRExperienceHelper.prototype._teleportCamera = function () {
             var _this = this;
             var _this = this;
+            if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
+                return;
+            }
             // Teleport the hmd to where the user is looking by moving the anchor to where they are looking minus the
             // Teleport the hmd to where the user is looking by moving the anchor to where they are looking minus the
             // offset of the headset from the anchor. Then add the helper's position to account for user's height offset
             // offset of the headset from the anchor. Then add the helper's position to account for user's height offset
-            this.webVRCamera.leftCamera.globalPosition.subtractToRef(this.webVRCamera.position, this._workingVector);
-            this._haloCenter.subtractToRef(this._workingVector, this._workingVector);
+            if (this.webVRCamera.leftCamera) {
+                this._workingVector.copyFrom(this.webVRCamera.leftCamera.globalPosition);
+                this._workingVector.subtractInPlace(this.webVRCamera.position);
+                this._haloCenter.subtractToRef(this._workingVector, this._workingVector);
+            }
+            else {
+                this._workingVector.copyFrom(this._haloCenter);
+            }
             this._workingVector.y += this._defaultHeight;
             this._workingVector.y += this._defaultHeight;
             // Create animation from the camera's position to the new location
             // Create animation from the camera's position to the new location
             this.currentVRCamera.animations = [];
             this.currentVRCamera.animations = [];
@@ -72776,8 +72877,8 @@ var BABYLON;
             });
             });
             animationPP2.setKeys(vignetteStretchKeys);
             animationPP2.setKeys(vignetteStretchKeys);
             this._postProcessMove.animations.push(animationPP2);
             this._postProcessMove.animations.push(animationPP2);
-            this._postProcessMove.imageProcessingConfiguration.vignetteWeight = 8;
-            this._postProcessMove.imageProcessingConfiguration.vignetteStretch = 10;
+            this._postProcessMove.imageProcessingConfiguration.vignetteWeight = 0;
+            this._postProcessMove.imageProcessingConfiguration.vignetteStretch = 0;
             this._webVRCamera.attachPostProcess(this._postProcessMove);
             this._webVRCamera.attachPostProcess(this._postProcessMove);
             this._scene.beginAnimation(this._postProcessMove, 0, 11, false, 1, function () {
             this._scene.beginAnimation(this._postProcessMove, 0, 11, false, 1, function () {
                 _this._webVRCamera.detachPostProcess(_this._postProcessMove);
                 _this._webVRCamera.detachPostProcess(_this._postProcessMove);
@@ -72785,20 +72886,18 @@ var BABYLON;
             this._scene.beginAnimation(this.currentVRCamera, 0, 11, false, 1);
             this._scene.beginAnimation(this.currentVRCamera, 0, 11, false, 1);
         };
         };
         VRExperienceHelper.prototype._castRayAndSelectObject = function () {
         VRExperienceHelper.prototype._castRayAndSelectObject = function () {
+            if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
+                return;
+            }
             var ray;
             var ray;
-            if ((!this.currentVRCamera.rightController && !this.currentVRCamera.leftController) ||
-                (this._leftLaserPointer && !this._leftLaserPointer.isVisible && !this._rightLaserPointer) ||
-                (this._rightLaserPointer && !this._rightLaserPointer.isVisible && !this._leftLaserPointer) ||
-                (this._rightLaserPointer && this._leftLaserPointer && !this._rightLaserPointer.isVisible && !this._leftLaserPointer.isVisible)) {
-                ray = this.currentVRCamera.getForwardRay(this._rayLength);
+            if (this._leftLaserPointer && this._leftLaserPointer.isVisible && this.currentVRCamera.leftController) {
+                ray = this.currentVRCamera.leftController.getForwardRay(this._rayLength);
+            }
+            else if (this._rightLaserPointer && this._rightLaserPointer.isVisible && this.currentVRCamera.rightController) {
+                ray = this.currentVRCamera.rightController.getForwardRay(this._rayLength);
             }
             }
             else {
             else {
-                if (this._leftLaserPointer && this._leftLaserPointer.isVisible) {
-                    ray = this.currentVRCamera.leftController.getForwardRay(this._rayLength);
-                }
-                else {
-                    ray = this.currentVRCamera.rightController.getForwardRay(this._rayLength);
-                }
+                ray = this.currentVRCamera.getForwardRay(this._rayLength);
             }
             }
             var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
             var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
             // Moving the gazeTracker on the mesh face targetted
             // Moving the gazeTracker on the mesh face targetted
@@ -72920,7 +73019,9 @@ var BABYLON;
             if (this.isInVRMode()) {
             if (this.isInVRMode()) {
                 this.exitVR();
                 this.exitVR();
             }
             }
-            this._deviceOrientationCamera.dispose();
+            if (this._deviceOrientationCamera) {
+                this._deviceOrientationCamera.dispose();
+            }
             if (this._passProcessMove) {
             if (this._passProcessMove) {
                 this._passProcessMove.dispose();
                 this._passProcessMove.dispose();
             }
             }
@@ -72936,6 +73037,7 @@ var BABYLON;
             if (!this._useCustomVRButton) {
             if (!this._useCustomVRButton) {
                 document.body.removeChild(this._btnVR);
                 document.body.removeChild(this._btnVR);
             }
             }
+            this._floorMeshesCollection = [];
             document.removeEventListener("keydown", this._onKeyDown);
             document.removeEventListener("keydown", this._onKeyDown);
             window.removeEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
             window.removeEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
         };
         };

+ 1 - 1
dist/preview release/gui/babylon.gui.js

@@ -3511,7 +3511,7 @@ var BABYLON;
                         _this._onImageLoaded();
                         _this._onImageLoaded();
                     };
                     };
                     if (value) {
                     if (value) {
-                        this._domImage.crossOrigin = "anonymous";
+                        BABYLON.Tools.SetCorsBehavior(value, this._domImage);
                         this._domImage.src = value;
                         this._domImage.src = value;
                     }
                     }
                 },
                 },

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/gui/babylon.gui.min.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/loaders/babylon.objFileLoader.min.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/loaders/babylonjs.loaders.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.customMaterial.js

@@ -1957,7 +1957,7 @@ vColor=color;\n\
             var name = "custom_" + CustomMaterial.ShaderIndexer;
             var name = "custom_" + CustomMaterial.ShaderIndexer;
             this.ReviewUniform("uniform", uniforms);
             this.ReviewUniform("uniform", uniforms);
             this.ReviewUniform("sampler", samplers);
             this.ReviewUniform("sampler", samplers);
-            var fn_afterBind = this._afterBind;
+            var fn_afterBind = this._afterBind.bind(this);
             this._afterBind = function (m, e) {
             this._afterBind = function (m, e) {
                 if (!e) {
                 if (!e) {
                     return;
                     return;

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylon.customMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylonjs.materials.js

@@ -5936,7 +5936,7 @@ vColor=color;\n\
             var name = "custom_" + CustomMaterial.ShaderIndexer;
             var name = "custom_" + CustomMaterial.ShaderIndexer;
             this.ReviewUniform("uniform", uniforms);
             this.ReviewUniform("uniform", uniforms);
             this.ReviewUniform("sampler", samplers);
             this.ReviewUniform("sampler", samplers);
-            var fn_afterBind = this._afterBind;
+            var fn_afterBind = this._afterBind.bind(this);
             this._afterBind = function (m, e) {
             this._afterBind = function (m, e) {
                 if (!e) {
                 if (!e) {
                     return;
                     return;

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylonjs.materials.min.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 42 - 42
dist/preview release/viewer/babylon.viewer.js


+ 242 - 245
materialsLibrary/src/custom/babylon.customMaterial.ts

@@ -1,9 +1,9 @@
 /// <reference path="../../../dist/preview release/babylon.d.ts"/>
 /// <reference path="../../../dist/preview release/babylon.d.ts"/>
 
 
-module BABYLON { 
-	
-   // old version of standard material updated every 3 months
-	 export class StandardMaterialDefines_OldVer extends MaterialDefines implements IImageProcessingConfigurationDefines {
+module BABYLON {
+
+    // old version of standard material updated every 3 months
+    export class StandardMaterialDefines_OldVer extends MaterialDefines implements IImageProcessingConfigurationDefines {
         public DIFFUSE = false;
         public DIFFUSE = false;
         public AMBIENT = false;
         public AMBIENT = false;
         public OPACITY = false;
         public OPACITY = false;
@@ -85,11 +85,11 @@ module BABYLON {
 
 
         public setReflectionMode(modeToEnable: string) {
         public setReflectionMode(modeToEnable: string) {
             var modes = [
             var modes = [
-                            "REFLECTIONMAP_CUBIC", "REFLECTIONMAP_EXPLICIT", "REFLECTIONMAP_PLANAR",
-                            "REFLECTIONMAP_PROJECTION", "REFLECTIONMAP_PROJECTION", "REFLECTIONMAP_SKYBOX",
-                            "REFLECTIONMAP_SPHERICAL", "REFLECTIONMAP_EQUIRECTANGULAR", "REFLECTIONMAP_EQUIRECTANGULAR_FIXED",
-                            "REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED"
-                        ];
+                "REFLECTIONMAP_CUBIC", "REFLECTIONMAP_EXPLICIT", "REFLECTIONMAP_PLANAR",
+                "REFLECTIONMAP_PROJECTION", "REFLECTIONMAP_PROJECTION", "REFLECTIONMAP_SKYBOX",
+                "REFLECTIONMAP_SPHERICAL", "REFLECTIONMAP_EQUIRECTANGULAR", "REFLECTIONMAP_EQUIRECTANGULAR_FIXED",
+                "REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED"
+            ];
 
 
             for (var mode of modes) {
             for (var mode of modes) {
                 (<any>this)[mode] = (mode === modeToEnable);
                 (<any>this)[mode] = (mode === modeToEnable);
@@ -109,39 +109,39 @@ module BABYLON {
         public ambientTexture: BaseTexture;
         public ambientTexture: BaseTexture;
 
 
         @serializeAsTexture("opacityTexture")
         @serializeAsTexture("opacityTexture")
-        private _opacityTexture: BaseTexture;        
+        private _opacityTexture: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public opacityTexture: BaseTexture;    
+        public opacityTexture: BaseTexture;
 
 
         @serializeAsTexture("reflectionTexture")
         @serializeAsTexture("reflectionTexture")
         private _reflectionTexture: BaseTexture;
         private _reflectionTexture: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public reflectionTexture: BaseTexture;        
+        public reflectionTexture: BaseTexture;
 
 
         @serializeAsTexture("emissiveTexture")
         @serializeAsTexture("emissiveTexture")
         private _emissiveTexture: BaseTexture;
         private _emissiveTexture: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public emissiveTexture: BaseTexture;     
+        public emissiveTexture: BaseTexture;
 
 
         @serializeAsTexture("specularTexture")
         @serializeAsTexture("specularTexture")
         private _specularTexture: BaseTexture;
         private _specularTexture: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public specularTexture: BaseTexture;             
+        public specularTexture: BaseTexture;
 
 
         @serializeAsTexture("bumpTexture")
         @serializeAsTexture("bumpTexture")
         private _bumpTexture: BaseTexture;
         private _bumpTexture: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public bumpTexture: BaseTexture;         
+        public bumpTexture: BaseTexture;
 
 
         @serializeAsTexture("lightmapTexture")
         @serializeAsTexture("lightmapTexture")
         private _lightmapTexture: BaseTexture;
         private _lightmapTexture: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public lightmapTexture: BaseTexture;            
+        public lightmapTexture: BaseTexture;
 
 
         @serializeAsTexture("refractionTexture")
         @serializeAsTexture("refractionTexture")
         private _refractionTexture: BaseTexture;
         private _refractionTexture: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public refractionTexture: BaseTexture;   
+        public refractionTexture: BaseTexture;
 
 
         @serializeAsColor3("ambient")
         @serializeAsColor3("ambient")
         public ambientColor = new Color3(0, 0, 0);
         public ambientColor = new Color3(0, 0, 0);
@@ -161,27 +161,27 @@ module BABYLON {
         @serialize("useAlphaFromDiffuseTexture")
         @serialize("useAlphaFromDiffuseTexture")
         private _useAlphaFromDiffuseTexture = false;
         private _useAlphaFromDiffuseTexture = false;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public useAlphaFromDiffuseTexture: boolean;      
+        public useAlphaFromDiffuseTexture: boolean;
 
 
         @serialize("useEmissiveAsIllumination")
         @serialize("useEmissiveAsIllumination")
         private _useEmissiveAsIllumination = false;
         private _useEmissiveAsIllumination = false;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public useEmissiveAsIllumination: boolean;           
-      
+        public useEmissiveAsIllumination: boolean;
+
         @serialize("linkEmissiveWithDiffuse")
         @serialize("linkEmissiveWithDiffuse")
         private _linkEmissiveWithDiffuse = false;
         private _linkEmissiveWithDiffuse = false;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public linkEmissiveWithDiffuse: boolean;                    
+        public linkEmissiveWithDiffuse: boolean;
 
 
         @serialize("useSpecularOverAlpha")
         @serialize("useSpecularOverAlpha")
         private _useSpecularOverAlpha = false;
         private _useSpecularOverAlpha = false;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public useSpecularOverAlpha: boolean;               
+        public useSpecularOverAlpha: boolean;
 
 
         @serialize("useReflectionOverAlpha")
         @serialize("useReflectionOverAlpha")
         private _useReflectionOverAlpha = false;
         private _useReflectionOverAlpha = false;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public useReflectionOverAlpha: boolean;               
+        public useReflectionOverAlpha: boolean;
 
 
         @serialize("disableLighting")
         @serialize("disableLighting")
         private _disableLighting = false;
         private _disableLighting = false;
@@ -191,12 +191,12 @@ module BABYLON {
         @serialize("useParallax")
         @serialize("useParallax")
         private _useParallax = false;
         private _useParallax = false;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public useParallax: boolean;            
+        public useParallax: boolean;
 
 
         @serialize("useParallaxOcclusion")
         @serialize("useParallaxOcclusion")
         private _useParallaxOcclusion = false;
         private _useParallaxOcclusion = false;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public useParallaxOcclusion: boolean;                  
+        public useParallaxOcclusion: boolean;
 
 
         @serialize()
         @serialize()
         public parallaxScaleBias = 0.05;
         public parallaxScaleBias = 0.05;
@@ -204,7 +204,7 @@ module BABYLON {
         @serialize("roughness")
         @serialize("roughness")
         private _roughness = 0;
         private _roughness = 0;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public roughness: number;            
+        public roughness: number;
 
 
         @serialize()
         @serialize()
         public indexOfRefraction = 0.98;
         public indexOfRefraction = 0.98;
@@ -215,49 +215,49 @@ module BABYLON {
         @serialize("useLightmapAsShadowmap")
         @serialize("useLightmapAsShadowmap")
         private _useLightmapAsShadowmap = false;
         private _useLightmapAsShadowmap = false;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public useLightmapAsShadowmap: boolean;             
+        public useLightmapAsShadowmap: boolean;
 
 
         // Fresnel
         // Fresnel
         @serializeAsFresnelParameters("diffuseFresnelParameters")
         @serializeAsFresnelParameters("diffuseFresnelParameters")
         private _diffuseFresnelParameters: FresnelParameters;
         private _diffuseFresnelParameters: FresnelParameters;
         @expandToProperty("_markAllSubMeshesAsFresnelDirty")
         @expandToProperty("_markAllSubMeshesAsFresnelDirty")
-        public diffuseFresnelParameters: FresnelParameters;            
+        public diffuseFresnelParameters: FresnelParameters;
 
 
         @serializeAsFresnelParameters("opacityFresnelParameters")
         @serializeAsFresnelParameters("opacityFresnelParameters")
         private _opacityFresnelParameters: FresnelParameters;
         private _opacityFresnelParameters: FresnelParameters;
         @expandToProperty("_markAllSubMeshesAsFresnelDirty")
         @expandToProperty("_markAllSubMeshesAsFresnelDirty")
-        public opacityFresnelParameters: FresnelParameters;            
-           
+        public opacityFresnelParameters: FresnelParameters;
+
 
 
         @serializeAsFresnelParameters("reflectionFresnelParameters")
         @serializeAsFresnelParameters("reflectionFresnelParameters")
         private _reflectionFresnelParameters: FresnelParameters;
         private _reflectionFresnelParameters: FresnelParameters;
         @expandToProperty("_markAllSubMeshesAsFresnelDirty")
         @expandToProperty("_markAllSubMeshesAsFresnelDirty")
-        public reflectionFresnelParameters: FresnelParameters;             
+        public reflectionFresnelParameters: FresnelParameters;
 
 
         @serializeAsFresnelParameters("refractionFresnelParameters")
         @serializeAsFresnelParameters("refractionFresnelParameters")
         private _refractionFresnelParameters: FresnelParameters;
         private _refractionFresnelParameters: FresnelParameters;
         @expandToProperty("_markAllSubMeshesAsFresnelDirty")
         @expandToProperty("_markAllSubMeshesAsFresnelDirty")
-        public refractionFresnelParameters: FresnelParameters;           
+        public refractionFresnelParameters: FresnelParameters;
 
 
         @serializeAsFresnelParameters("emissiveFresnelParameters")
         @serializeAsFresnelParameters("emissiveFresnelParameters")
         private _emissiveFresnelParameters: FresnelParameters;
         private _emissiveFresnelParameters: FresnelParameters;
         @expandToProperty("_markAllSubMeshesAsFresnelDirty")
         @expandToProperty("_markAllSubMeshesAsFresnelDirty")
-        public emissiveFresnelParameters: FresnelParameters;            
+        public emissiveFresnelParameters: FresnelParameters;
 
 
         @serialize("useReflectionFresnelFromSpecular")
         @serialize("useReflectionFresnelFromSpecular")
-        private _useReflectionFresnelFromSpecular = false;    
+        private _useReflectionFresnelFromSpecular = false;
         @expandToProperty("_markAllSubMeshesAsFresnelDirty")
         @expandToProperty("_markAllSubMeshesAsFresnelDirty")
-        public useReflectionFresnelFromSpecular: boolean;                 
+        public useReflectionFresnelFromSpecular: boolean;
 
 
         @serialize("useGlossinessFromSpecularMapAlpha")
         @serialize("useGlossinessFromSpecularMapAlpha")
         private _useGlossinessFromSpecularMapAlpha = false;
         private _useGlossinessFromSpecularMapAlpha = false;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public useGlossinessFromSpecularMapAlpha: boolean;           
-  
+        public useGlossinessFromSpecularMapAlpha: boolean;
+
         @serialize("maxSimultaneousLights")
         @serialize("maxSimultaneousLights")
         private _maxSimultaneousLights = 4;
         private _maxSimultaneousLights = 4;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public maxSimultaneousLights: number;                   
+        public maxSimultaneousLights: number;
 
 
         /**
         /**
          * If sets to true, x component of normal map value will invert (x = 1.0 - x).
          * If sets to true, x component of normal map value will invert (x = 1.0 - x).
@@ -281,7 +281,7 @@ module BABYLON {
         @serialize("twoSidedLighting")
         @serialize("twoSidedLighting")
         private _twoSidedLighting = false;
         private _twoSidedLighting = false;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public twoSidedLighting: boolean;     
+        public twoSidedLighting: boolean;
 
 
         /**
         /**
          * Default configuration related to image processing available in the standard Material.
          * Default configuration related to image processing available in the standard Material.
@@ -395,7 +395,7 @@ module BABYLON {
         public set cameraExposure(value: number) {
         public set cameraExposure(value: number) {
             this._imageProcessingConfiguration.exposure = value;
             this._imageProcessingConfiguration.exposure = value;
         };
         };
-        
+
         /**
         /**
          * Gets The camera contrast used on this material.
          * Gets The camera contrast used on this material.
          */
          */
@@ -409,7 +409,7 @@ module BABYLON {
         public set cameraContrast(value: number) {
         public set cameraContrast(value: number) {
             this._imageProcessingConfiguration.contrast = value;
             this._imageProcessingConfiguration.contrast = value;
         }
         }
-        
+
         /**
         /**
          * Gets the Color Grading 2D Lookup Texture.
          * Gets the Color Grading 2D Lookup Texture.
          */
          */
@@ -454,7 +454,7 @@ module BABYLON {
 
 
         public getClassName(): string {
         public getClassName(): string {
             return "StandardMaterial_OldVer";
             return "StandardMaterial_OldVer";
-        }        
+        }
 
 
         @serialize()
         @serialize()
         public get useLogarithmicDepth(): boolean {
         public get useLogarithmicDepth(): boolean {
@@ -486,7 +486,7 @@ module BABYLON {
         /**
         /**
          * Child classes can use it to update shaders
          * Child classes can use it to update shaders
          */
          */
-        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {            
+        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                     return true;
@@ -674,7 +674,7 @@ module BABYLON {
 
 
                 defines.EMISSIVEASILLUMINATION = this._useEmissiveAsIllumination;
                 defines.EMISSIVEASILLUMINATION = this._useEmissiveAsIllumination;
 
 
-                defines.LINKEMISSIVEWITHDIFFUSE = this._linkEmissiveWithDiffuse;       
+                defines.LINKEMISSIVEWITHDIFFUSE = this._linkEmissiveWithDiffuse;
 
 
                 defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;
                 defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;
             }
             }
@@ -702,9 +702,9 @@ module BABYLON {
 
 
                         defines.REFLECTIONFRESNELFROMSPECULAR = this._useReflectionFresnelFromSpecular;
                         defines.REFLECTIONFRESNELFROMSPECULAR = this._useReflectionFresnelFromSpecular;
 
 
-                        defines.REFRACTIONFRESNEL = (this._refractionFresnelParameters && this._refractionFresnelParameters.isEnabled) ;
+                        defines.REFRACTIONFRESNEL = (this._refractionFresnelParameters && this._refractionFresnelParameters.isEnabled);
 
 
-                        defines.EMISSIVEFRESNEL = (this._emissiveFresnelParameters && this._emissiveFresnelParameters.isEnabled) ;
+                        defines.EMISSIVEFRESNEL = (this._emissiveFresnelParameters && this._emissiveFresnelParameters.isEnabled);
 
 
                         defines._needNormals = true;
                         defines._needNormals = true;
                         defines.FRESNEL = true;
                         defines.FRESNEL = true;
@@ -814,9 +814,9 @@ module BABYLON {
                 MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
                 MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
                 MaterialHelper.PrepareAttributesForInstances(attribs, defines);
                 MaterialHelper.PrepareAttributesForInstances(attribs, defines);
                 MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, defines);
                 MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, defines);
-                
+
                 var shaderName = "default";
                 var shaderName = "default";
-                
+
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vDiffuseColor", "vSpecularColor", "vEmissiveColor",
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vDiffuseColor", "vSpecularColor", "vEmissiveColor",
                     "vFogInfos", "vFogColor", "pointSize",
                     "vFogInfos", "vFogColor", "pointSize",
                     "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
                     "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
@@ -834,10 +834,10 @@ module BABYLON {
                 ImageProcessingConfiguration.PrepareSamplers(samplers, defines);
                 ImageProcessingConfiguration.PrepareSamplers(samplers, defines);
 
 
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
-                    uniformsNames: uniforms, 
+                    uniformsNames: uniforms,
                     uniformBuffersNames: uniformBuffers,
                     uniformBuffersNames: uniformBuffers,
-                    samplers: samplers, 
-                    defines: defines, 
+                    samplers: samplers,
+                    defines: defines,
                     maxSimultaneousLights: this._maxSimultaneousLights
                     maxSimultaneousLights: this._maxSimultaneousLights
                 });
                 });
 
 
@@ -857,7 +857,7 @@ module BABYLON {
                     onError: this.onError,
                     onError: this.onError,
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS }
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS }
                 }, engine), defines);
                 }, engine), defines);
-                
+
                 this.buildUniformLayout();
                 this.buildUniformLayout();
             }
             }
 
 
@@ -946,7 +946,7 @@ module BABYLON {
             MaterialHelper.BindBonesParameters(mesh, effect);
             MaterialHelper.BindBonesParameters(mesh, effect);
             if (this._mustRebind(scene, effect, mesh.visibility)) {
             if (this._mustRebind(scene, effect, mesh.visibility)) {
                 this._uniformBuffer.bindToEffect(effect, "Material");
                 this._uniformBuffer.bindToEffect(effect, "Material");
-                
+
                 this.bindViewProjection(effect);
                 this.bindViewProjection(effect);
                 if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {
                 if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {
 
 
@@ -1035,7 +1035,7 @@ module BABYLON {
                                 }
                                 }
                             }
                             }
                             this._uniformBuffer.updateFloat4("vRefractionInfos", this._refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
                             this._uniformBuffer.updateFloat4("vRefractionInfos", this._refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
-                        }                    
+                        }
                     }
                     }
 
 
                     // Point size
                     // Point size
@@ -1051,7 +1051,7 @@ module BABYLON {
                     // Diffuse
                     // Diffuse
                     this._uniformBuffer.updateColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
                     this._uniformBuffer.updateColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
                 }
                 }
-                
+
                 // Textures     
                 // Textures     
                 if (scene.texturesEnabled) {
                 if (scene.texturesEnabled) {
                     if (this._diffuseTexture && StandardMaterial_OldVer.DiffuseTextureEnabled) {
                     if (this._diffuseTexture && StandardMaterial_OldVer.DiffuseTextureEnabled) {
@@ -1120,7 +1120,7 @@ module BABYLON {
                 if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE || this._reflectionTexture || this._refractionTexture) {
                 if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE || this._reflectionTexture || this._refractionTexture) {
                     this.bindView(effect);
                     this.bindView(effect);
                 }
                 }
-                
+
                 // Fog
                 // Fog
                 MaterialHelper.BindFogParameters(scene, mesh, effect);
                 MaterialHelper.BindFogParameters(scene, mesh, effect);
 
 
@@ -1340,8 +1340,8 @@ module BABYLON {
 
 
             StandardMaterial_OldVer._ReflectionTextureEnabled = value;
             StandardMaterial_OldVer._ReflectionTextureEnabled = value;
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
-        }        
-        
+        }
+
         static _EmissiveTextureEnabled = true;
         static _EmissiveTextureEnabled = true;
         public static get EmissiveTextureEnabled(): boolean {
         public static get EmissiveTextureEnabled(): boolean {
             return StandardMaterial_OldVer._EmissiveTextureEnabled;
             return StandardMaterial_OldVer._EmissiveTextureEnabled;
@@ -1353,7 +1353,7 @@ module BABYLON {
 
 
             StandardMaterial_OldVer._EmissiveTextureEnabled = value;
             StandardMaterial_OldVer._EmissiveTextureEnabled = value;
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
-        }       
+        }
 
 
         static _SpecularTextureEnabled = true;
         static _SpecularTextureEnabled = true;
         public static get SpecularTextureEnabled(): boolean {
         public static get SpecularTextureEnabled(): boolean {
@@ -1366,7 +1366,7 @@ module BABYLON {
 
 
             StandardMaterial_OldVer._SpecularTextureEnabled = value;
             StandardMaterial_OldVer._SpecularTextureEnabled = value;
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
-        }     
+        }
 
 
         static _BumpTextureEnabled = true;
         static _BumpTextureEnabled = true;
         public static get BumpTextureEnabled(): boolean {
         public static get BumpTextureEnabled(): boolean {
@@ -1379,7 +1379,7 @@ module BABYLON {
 
 
             StandardMaterial_OldVer._BumpTextureEnabled = value;
             StandardMaterial_OldVer._BumpTextureEnabled = value;
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
-        }         
+        }
 
 
         static _LightmapTextureEnabled = true;
         static _LightmapTextureEnabled = true;
         public static get LightmapTextureEnabled(): boolean {
         public static get LightmapTextureEnabled(): boolean {
@@ -1392,9 +1392,9 @@ module BABYLON {
 
 
             StandardMaterial_OldVer._LightmapTextureEnabled = value;
             StandardMaterial_OldVer._LightmapTextureEnabled = value;
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
-        }           
+        }
 
 
-        static _RefractionTextureEnabled = true;    
+        static _RefractionTextureEnabled = true;
         public static get RefractionTextureEnabled(): boolean {
         public static get RefractionTextureEnabled(): boolean {
             return StandardMaterial_OldVer._RefractionTextureEnabled;
             return StandardMaterial_OldVer._RefractionTextureEnabled;
         }
         }
@@ -1405,7 +1405,7 @@ module BABYLON {
 
 
             StandardMaterial_OldVer._RefractionTextureEnabled = value;
             StandardMaterial_OldVer._RefractionTextureEnabled = value;
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
-        }    
+        }
 
 
         static _ColorGradingTextureEnabled = true;
         static _ColorGradingTextureEnabled = true;
         public static get ColorGradingTextureEnabled(): boolean {
         public static get ColorGradingTextureEnabled(): boolean {
@@ -1418,7 +1418,7 @@ module BABYLON {
 
 
             StandardMaterial_OldVer._ColorGradingTextureEnabled = value;
             StandardMaterial_OldVer._ColorGradingTextureEnabled = value;
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
             Engine.MarkAllMaterialsAsDirty(Material.TextureDirtyFlag);
-        }           
+        }
 
 
         static _FresnelEnabled = true;
         static _FresnelEnabled = true;
         public static get FresnelEnabled(): boolean {
         public static get FresnelEnabled(): boolean {
@@ -1431,54 +1431,54 @@ module BABYLON {
 
 
             StandardMaterial_OldVer._FresnelEnabled = value;
             StandardMaterial_OldVer._FresnelEnabled = value;
             Engine.MarkAllMaterialsAsDirty(Material.FresnelDirtyFlag);
             Engine.MarkAllMaterialsAsDirty(Material.FresnelDirtyFlag);
-        }          
+        }
     }
     }
 
 
-   
-  export class CustomShaderStructure {
-      
-       public FragmentStore : string; 
-       public VertexStore : string; 
 
 
-       constructor(){
+    export class CustomShaderStructure {
 
 
-       }  
-  }
+        public FragmentStore: string;
+        public VertexStore: string;
 
 
-  export class  ShaderSpecialParts{
- 
-    constructor(){}
+        constructor() {
 
 
-    public Fragment_Begin:string;
-    public Fragment_Definitions:string;
-    public Fragment_MainBegin: string;
-    
-    // diffuseColor
-    public Fragment_Custom_Diffuse: string;
-    
-    // alpha
-    public Fragment_Custom_Alpha : string;
+        }
+    }
 
 
-    public Fragment_Before_FragColor: string;
+    export class ShaderSpecialParts {
 
 
-    public Vertex_Begin:string;
-    public Vertex_Definitions:string;
-    public Vertex_MainBegin: string;
-    
-    // positionUpdated
-    public Vertex_Before_PositionUpdated:string;
+        constructor() { }
 
 
-    // normalUpdated
-    public Vertex_Before_NormalUpdated : string;
-  }
+        public Fragment_Begin: string;
+        public Fragment_Definitions: string;
+        public Fragment_MainBegin: string;
 
 
-  export class ShaderForVer3_0 extends CustomShaderStructure {
+        // diffuseColor
+        public Fragment_Custom_Diffuse: string;
 
 
-       constructor() {
+        // alpha
+        public Fragment_Custom_Alpha: string;
+
+        public Fragment_Before_FragColor: string;
+
+        public Vertex_Begin: string;
+        public Vertex_Definitions: string;
+        public Vertex_MainBegin: string;
+
+        // positionUpdated
+        public Vertex_Before_PositionUpdated: string;
+
+        // normalUpdated
+        public Vertex_Before_NormalUpdated: string;
+    }
+
+    export class ShaderForVer3_0 extends CustomShaderStructure {
+
+        constructor() {
             super();
             super();
-            
+
             this.VertexStore = "";
             this.VertexStore = "";
-            
+
             this.FragmentStore = "#include<__decl__defaultFragment>\n\
             this.FragmentStore = "#include<__decl__defaultFragment>\n\
 #[Fragment_Begin]\n\
 #[Fragment_Begin]\n\
 #extension GL_OES_standard_derivatives : enable\n\
 #extension GL_OES_standard_derivatives : enable\n\
@@ -1780,7 +1780,7 @@ gl_FragColor=color;\n\
 }";
 }";
 
 
 
 
-this.VertexStore = "#include<__decl__defaultVertex>\n\
+            this.VertexStore = "#include<__decl__defaultVertex>\n\
 \n\
 \n\
 #[Vertex_Begin]\n\
 #[Vertex_Begin]\n\
 \n\
 \n\
@@ -1974,188 +1974,185 @@ vColor=color;\n\
 }";
 }";
 
 
 
 
-       }
+        }
+
+    }
 
 
-  }
 
 
- 
-   export class StandardShaderVersions{
+    export class StandardShaderVersions {
 
 
         public static Ver3_0 = "3.0.0";
         public static Ver3_0 = "3.0.0";
 
 
-   } 
-
-    export class CustomMaterial  extends StandardMaterial_OldVer {
-         public static ShaderIndexer = 1;
-         public CustomParts :  ShaderSpecialParts;
-         public ShaderVersion : CustomShaderStructure ;
-         _isCreatedShader : boolean;
-         _createdShaderName : string;
-         _customUniform : string[];
-         _newUniforms : string[];
-         _newUniformInstances : any[];
-         _newSamplerInstances : Texture[];
-
-         public AttachAfterBind(mesh:Mesh,effect:Effect){ 
-             for(var el in this._newUniformInstances){
-                 var ea = el.toString().split('-');
-                 if(ea[0] == 'vec2') effect.setVector2(ea[1],this._newUniformInstances[el]);
-                 else if(ea[0] == 'vec3') effect.setVector3(ea[1],this._newUniformInstances[el]);
-                 else if(ea[0] == 'vec4') effect.setVector4(ea[1],this._newUniformInstances[el]);
-                 else if(ea[0] == 'mat4') effect.setMatrix(ea[1],this._newUniformInstances[el]);
-                 else if(ea[0] == 'float') effect.setFloat(ea[1],this._newUniformInstances[el]); 
-             }
-
-              for(var el in this._newSamplerInstances){ 
-                 var ea = el.toString().split('-'); 
-                if(ea[0] == 'sampler2D' && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady())
-                     effect.setTexture(ea[1],this._newSamplerInstances[el]); 
-              }
-         }
-
-         public ReviewUniform(name:string, arr : string[] ) : string[]{
-             if(name == "uniform")
-              {
-                  for(var ind in this._newUniforms)
-                    if(this._customUniform[ind].indexOf('sampler')== -1) 
+    }
+
+    export class CustomMaterial extends StandardMaterial_OldVer {
+        public static ShaderIndexer = 1;
+        public CustomParts: ShaderSpecialParts;
+        public ShaderVersion: CustomShaderStructure;
+        _isCreatedShader: boolean;
+        _createdShaderName: string;
+        _customUniform: string[];
+        _newUniforms: string[];
+        _newUniformInstances: any[];
+        _newSamplerInstances: Texture[];
+
+        public AttachAfterBind(mesh: Mesh, effect: Effect) {
+            for (var el in this._newUniformInstances) {
+                var ea = el.toString().split('-');
+                if (ea[0] == 'vec2') effect.setVector2(ea[1], this._newUniformInstances[el]);
+                else if (ea[0] == 'vec3') effect.setVector3(ea[1], this._newUniformInstances[el]);
+                else if (ea[0] == 'vec4') effect.setVector4(ea[1], this._newUniformInstances[el]);
+                else if (ea[0] == 'mat4') effect.setMatrix(ea[1], this._newUniformInstances[el]);
+                else if (ea[0] == 'float') effect.setFloat(ea[1], this._newUniformInstances[el]);
+            }
+
+            for (var el in this._newSamplerInstances) {
+                var ea = el.toString().split('-');
+                if (ea[0] == 'sampler2D' && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady())
+                    effect.setTexture(ea[1], this._newSamplerInstances[el]);
+            }
+        }
+
+        public ReviewUniform(name: string, arr: string[]): string[] {
+            if (name == "uniform") {
+                for (var ind in this._newUniforms)
+                    if (this._customUniform[ind].indexOf('sampler') == -1)
                         arr.push(this._newUniforms[ind]);
                         arr.push(this._newUniforms[ind]);
-              }
+            }
 
 
-                 if(name == "sampler")
-              {
-                   for(var ind in this._newUniforms)
-                    if(this._customUniform[ind].indexOf('sampler')!= -1) 
+            if (name == "sampler") {
+                for (var ind in this._newUniforms)
+                    if (this._customUniform[ind].indexOf('sampler') != -1)
                         arr.push(this._newUniforms[ind]);
                         arr.push(this._newUniforms[ind]);
-              }
-
-             return arr;
-         }
-         public Builder(shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines_OldVer) : string {
-            
-            if(this._isCreatedShader) return this._createdShaderName;
-              this._isCreatedShader  = false;
-            
+            }
+
+            return arr;
+        }
+        public Builder(shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines_OldVer): string {
+
+            if (this._isCreatedShader) return this._createdShaderName;
+            this._isCreatedShader = false;
+
             CustomMaterial.ShaderIndexer++;
             CustomMaterial.ShaderIndexer++;
             var name: string = "custom_" + CustomMaterial.ShaderIndexer;
             var name: string = "custom_" + CustomMaterial.ShaderIndexer;
 
 
-            this.ReviewUniform("uniform",uniforms);
-            this.ReviewUniform("sampler",samplers);
-            
+            this.ReviewUniform("uniform", uniforms);
+            this.ReviewUniform("sampler", samplers);
 
 
-            var fn_afterBind = this._afterBind;
-            this._afterBind = (m,e) => { 
+
+            var fn_afterBind = this._afterBind.bind(this);
+            this._afterBind = (m, e) => {
                 if (!e) {
                 if (!e) {
                     return;
                     return;
                 }
                 }
                 this.AttachAfterBind(m, e);
                 this.AttachAfterBind(m, e);
-                try{fn_afterBind(m,e);}catch(e){};
-            } ;
-
-            BABYLON.Effect.ShadersStore[name+"VertexShader"] = this.ShaderVersion.VertexStore
-            .replace('#[Vertex_Begin]',(this.CustomParts.Vertex_Begin ? this.CustomParts.Vertex_Begin : ""))
-            .replace('#[Vertex_Definitions]',(this._customUniform? this._customUniform.join("\n"):"")+ (this.CustomParts.Vertex_Definitions ? this.CustomParts.Vertex_Definitions : ""))
-            .replace('#[Vertex_MainBegin]',(this.CustomParts.Vertex_MainBegin ? this.CustomParts.Vertex_MainBegin : ""))
-            .replace('#[Vertex_Before_PositionUpdated]',(this.CustomParts.Vertex_Before_PositionUpdated ? this.CustomParts.Vertex_Before_PositionUpdated : ""))
-            .replace('#[Vertex_Before_NormalUpdated]',(this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : "")) ;
-
-            BABYLON.Effect.ShadersStore[name+"PixelShader"] = this.ShaderVersion.FragmentStore
-            .replace('#[Fragment_Begin]',(this.CustomParts.Fragment_Begin ? this.CustomParts.Fragment_Begin : ""))
-            .replace('#[Fragment_MainBegin]',(this.CustomParts.Fragment_MainBegin  ? this.CustomParts.Fragment_MainBegin : ""))
-            .replace('#[Fragment_Definitions]',(this._customUniform? this._customUniform.join("\n"):"")+(this.CustomParts.Fragment_Definitions ? this.CustomParts.Fragment_Definitions : ""))
-            .replace('#[Fragment_Custom_Diffuse]',(this.CustomParts.Fragment_Custom_Diffuse ? this.CustomParts.Fragment_Custom_Diffuse : ""))
-            .replace('#[Fragment_Custom_Alpha]',(this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : ""))
-            .replace('#[Fragment_Before_FragColor]',(this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : "")) ;
- 
-             this._isCreatedShader  = true;
-              this._createdShaderName = name;
-           
-             return name ;
-         }
-
-      
-
-         public SelectVersion(ver:string){
-            switch(ver){
-                case "3.0.0" : this.ShaderVersion = new ShaderForVer3_0();break;
+                try { fn_afterBind(m, e); } catch (e) { };
+            };
+
+            BABYLON.Effect.ShadersStore[name + "VertexShader"] = this.ShaderVersion.VertexStore
+                .replace('#[Vertex_Begin]', (this.CustomParts.Vertex_Begin ? this.CustomParts.Vertex_Begin : ""))
+                .replace('#[Vertex_Definitions]', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Vertex_Definitions ? this.CustomParts.Vertex_Definitions : ""))
+                .replace('#[Vertex_MainBegin]', (this.CustomParts.Vertex_MainBegin ? this.CustomParts.Vertex_MainBegin : ""))
+                .replace('#[Vertex_Before_PositionUpdated]', (this.CustomParts.Vertex_Before_PositionUpdated ? this.CustomParts.Vertex_Before_PositionUpdated : ""))
+                .replace('#[Vertex_Before_NormalUpdated]', (this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : ""));
+
+            BABYLON.Effect.ShadersStore[name + "PixelShader"] = this.ShaderVersion.FragmentStore
+                .replace('#[Fragment_Begin]', (this.CustomParts.Fragment_Begin ? this.CustomParts.Fragment_Begin : ""))
+                .replace('#[Fragment_MainBegin]', (this.CustomParts.Fragment_MainBegin ? this.CustomParts.Fragment_MainBegin : ""))
+                .replace('#[Fragment_Definitions]', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Fragment_Definitions ? this.CustomParts.Fragment_Definitions : ""))
+                .replace('#[Fragment_Custom_Diffuse]', (this.CustomParts.Fragment_Custom_Diffuse ? this.CustomParts.Fragment_Custom_Diffuse : ""))
+                .replace('#[Fragment_Custom_Alpha]', (this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : ""))
+                .replace('#[Fragment_Before_FragColor]', (this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : ""));
+
+            this._isCreatedShader = true;
+            this._createdShaderName = name;
+
+            return name;
+        }
+
+
+
+        public SelectVersion(ver: string) {
+            switch (ver) {
+                case "3.0.0": this.ShaderVersion = new ShaderForVer3_0(); break;
             }
             }
-         }
-        
-         constructor(name:string,scene:Scene ){
-            super(name,scene);
+        }
+
+        constructor(name: string, scene: Scene) {
+            super(name, scene);
             this.CustomParts = new ShaderSpecialParts();
             this.CustomParts = new ShaderSpecialParts();
-            this.customShaderNameResolve = this.Builder;  
-            this.SelectVersion("3.0.0"); 
-         } 
-         public AddUniform(name:string,kind:string,param:any):CustomMaterial{
-             if(!this._customUniform)
-              {  
-                  this._customUniform = new Array();
-                  this._newUniforms = new Array();
-                  this._newSamplerInstances = new Array();
-                  this._newUniformInstances = new Array();
-              }
-              if(param){
-              if(kind.indexOf("sampler") == -1) {
-                    (<any>this._newUniformInstances)[kind+"-"+name] = param;
-              }
-              else{
-                (<any>this._newUniformInstances)[kind+"-"+name] = param;
-              }
-             }
-
-            this._customUniform.push("uniform "+kind+" "+name+";");
+            this.customShaderNameResolve = this.Builder;
+            this.SelectVersion("3.0.0");
+        }
+        public AddUniform(name: string, kind: string, param: any): CustomMaterial {
+            if (!this._customUniform) {
+                this._customUniform = new Array();
+                this._newUniforms = new Array();
+                this._newSamplerInstances = new Array();
+                this._newUniformInstances = new Array();
+            }
+            if (param) {
+                if (kind.indexOf("sampler") == -1) {
+                    (<any>this._newUniformInstances)[kind + "-" + name] = param;
+                }
+                else {
+                    (<any>this._newUniformInstances)[kind + "-" + name] = param;
+                }
+            }
+
+            this._customUniform.push("uniform " + kind + " " + name + ";");
             this._newUniforms.push(name);
             this._newUniforms.push(name);
-             
+
             return this;
             return this;
-         }
-         public Fragment_Begin(shaderPart:string):CustomMaterial{            
+        }
+        public Fragment_Begin(shaderPart: string): CustomMaterial {
             this.CustomParts.Fragment_Begin = shaderPart;
             this.CustomParts.Fragment_Begin = shaderPart;
             return this;
             return this;
-         }
+        }
 
 
-         public Fragment_Definitions(shaderPart:string):CustomMaterial{            
+        public Fragment_Definitions(shaderPart: string): CustomMaterial {
             this.CustomParts.Fragment_Definitions = shaderPart;
             this.CustomParts.Fragment_Definitions = shaderPart;
             return this;
             return this;
-         }
+        }
 
 
-         public Fragment_MainBegin(shaderPart:string):CustomMaterial{            
+        public Fragment_MainBegin(shaderPart: string): CustomMaterial {
             this.CustomParts.Fragment_MainBegin = shaderPart;
             this.CustomParts.Fragment_MainBegin = shaderPart;
             return this;
             return this;
-         }
-         public Fragment_Custom_Diffuse(shaderPart:string):CustomMaterial{            
-            this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace("result","diffuseColor");
+        }
+        public Fragment_Custom_Diffuse(shaderPart: string): CustomMaterial {
+            this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace("result", "diffuseColor");
             return this;
             return this;
-         }
-         public Fragment_Custom_Alpha(shaderPart:string):CustomMaterial{            
-            this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result","alpha");
+        }
+        public Fragment_Custom_Alpha(shaderPart: string): CustomMaterial {
+            this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
             return this;
             return this;
-         }
-         public Fragment_Before_FragColor(shaderPart:string):CustomMaterial{            
-            this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result","color");
+        }
+        public Fragment_Before_FragColor(shaderPart: string): CustomMaterial {
+            this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
             return this;
             return this;
-         }
-         public Vertex_Begin(shaderPart:string):CustomMaterial{            
+        }
+        public Vertex_Begin(shaderPart: string): CustomMaterial {
             this.CustomParts.Vertex_Begin = shaderPart;
             this.CustomParts.Vertex_Begin = shaderPart;
             return this;
             return this;
-         }
-         public Vertex_Definitions(shaderPart:string):CustomMaterial{            
+        }
+        public Vertex_Definitions(shaderPart: string): CustomMaterial {
             this.CustomParts.Vertex_Definitions = shaderPart;
             this.CustomParts.Vertex_Definitions = shaderPart;
             return this;
             return this;
-         }
-         public Vertex_MainBegin(shaderPart:string):CustomMaterial{            
+        }
+        public Vertex_MainBegin(shaderPart: string): CustomMaterial {
             this.CustomParts.Vertex_MainBegin = shaderPart;
             this.CustomParts.Vertex_MainBegin = shaderPart;
             return this;
             return this;
-         }
-         public Vertex_Before_PositionUpdated(shaderPart:string):CustomMaterial{            
-            this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result","positionUpdated");
+        }
+        public Vertex_Before_PositionUpdated(shaderPart: string): CustomMaterial {
+            this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
             return this;
             return this;
-         } 
-         
-          public Vertex_Before_NormalUpdated(shaderPart:string):CustomMaterial{            
-            this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result","normalUpdated");
+        }
+
+        public Vertex_Before_NormalUpdated(shaderPart: string): CustomMaterial {
+            this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
             return this;
             return this;
-         } 
-          
+        }
+
     }
     }
 }
 }
-     
+