Pārlūkot izejas kodu

New UniversalCamera

David Catuhe 9 gadi atpakaļ
vecāks
revīzija
88d3f4b99f

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 19 - 19
dist/preview release/babylon.core.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 2807 - 2792
dist/preview release/babylon.d.ts


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 23 - 23
dist/preview release/babylon.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1117 - 1097
dist/preview release/babylon.max.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 25 - 25
dist/preview release/babylon.noworker.js


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

@@ -586,11 +586,11 @@ var BABYLON;
                 camera = new BABYLON.VRDeviceOrientationFreeCamera(parsedCamera.name, position, scene);
             }
             else if (parsedCamera.type === "FreeCamera") {
-                camera = new BABYLON.TouchCamera(parsedCamera.name, position, scene);
+                camera = new BABYLON.UniversalCamera(parsedCamera.name, position, scene);
             }
             else {
-                // Touch Camera is the default value
-                camera = new BABYLON.TouchCamera(parsedCamera.name, position, scene);
+                // Universal Camera is the default value
+                camera = new BABYLON.UniversalCamera(parsedCamera.name, position, scene);
             }
             // apply 3d rig, when found
             if (parsedCamera.cameraRigMode) {

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

@@ -663,11 +663,11 @@
                 camera = new VRDeviceOrientationFreeCamera(parsedCamera.name, position, scene);
 
             } else if (parsedCamera.type === "FreeCamera") {
-                camera = new BABYLON.TouchCamera(parsedCamera.name, position, scene);   
+                camera = new UniversalCamera(parsedCamera.name, position, scene);   
                         
             } else {
-                // Touch Camera is the default value
-                camera = new TouchCamera(parsedCamera.name, position, scene);
+                // Universal Camera is the default value
+                camera = new UniversalCamera(parsedCamera.name, position, scene);
             }
 
             // apply 3d rig, when found

+ 2 - 35
src/Cameras/babylon.gamepadCamera.js

@@ -9,43 +9,10 @@ var BABYLON;
     var GamepadCamera = (function (_super) {
         __extends(GamepadCamera, _super);
         function GamepadCamera(name, position, scene) {
-            var _this = this;
+            BABYLON.Tools.Warn("Deprecated. Please use Universal Camera instead.");
             _super.call(this, name, position, scene);
-            this.angularSensibility = 200;
-            this.moveSensibility = 75;
-            this._gamepads = new BABYLON.Gamepads(function (gamepad) { _this._onNewGameConnected(gamepad); });
         }
-        GamepadCamera.prototype._onNewGameConnected = function (gamepad) {
-            // Only the first gamepad can control the camera
-            if (gamepad.index === 0) {
-                this._gamepad = gamepad;
-            }
-        };
-        GamepadCamera.prototype._checkInputs = function () {
-            if (this._gamepad) {
-                var LSValues = this._gamepad.leftStick;
-                var normalizedLX = LSValues.x / this.moveSensibility;
-                var normalizedLY = LSValues.y / this.moveSensibility;
-                LSValues.x = Math.abs(normalizedLX) > 0.005 ? 0 + normalizedLX : 0;
-                LSValues.y = Math.abs(normalizedLY) > 0.005 ? 0 + normalizedLY : 0;
-                var RSValues = this._gamepad.rightStick;
-                var normalizedRX = RSValues.x / this.angularSensibility;
-                var normalizedRY = RSValues.y / this.angularSensibility;
-                RSValues.x = Math.abs(normalizedRX) > 0.001 ? 0 + normalizedRX : 0;
-                RSValues.y = Math.abs(normalizedRY) > 0.001 ? 0 + normalizedRY : 0;
-                var cameraTransform = BABYLON.Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
-                var speed = this._computeLocalCameraSpeed() * 50.0;
-                var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(LSValues.x * speed, 0, -LSValues.y * speed), cameraTransform);
-                this.cameraDirection = this.cameraDirection.add(deltaTransform);
-                this.cameraRotation = this.cameraRotation.add(new BABYLON.Vector2(RSValues.y, RSValues.x));
-            }
-            _super.prototype._checkInputs.call(this);
-        };
-        GamepadCamera.prototype.dispose = function () {
-            this._gamepads.dispose();
-            _super.prototype.dispose.call(this);
-        };
         return GamepadCamera;
-    })(BABYLON.FreeCamera);
+    })(BABYLON.UniversalCamera);
     BABYLON.GamepadCamera = GamepadCamera;
 })(BABYLON || (BABYLON = {}));

+ 2 - 44
src/Cameras/babylon.gamepadCamera.ts

@@ -1,51 +1,9 @@
 module BABYLON {
     // We're mainly based on the logic defined into the FreeCamera code
-    export class GamepadCamera extends FreeCamera {
-        private _gamepad: Gamepad;
-        private _gamepads: Gamepads;
-        public angularSensibility = 200;
-        public moveSensibility = 75;
-
+    export class GamepadCamera extends UniversalCamera {
         constructor(name: string, position: Vector3, scene: Scene) {
+            Tools.Warn("Deprecated. Please use Universal Camera instead.");
             super(name, position, scene);
-            this._gamepads = new Gamepads((gamepad: Gamepad) => { this._onNewGameConnected(gamepad); });
-        }
-
-        private _onNewGameConnected(gamepad: Gamepad) {
-            // Only the first gamepad can control the camera
-            if (gamepad.index === 0) {
-                this._gamepad = gamepad;
-            }
-        }
-
-        public _checkInputs(): void {
-            if (this._gamepad) {
-                var LSValues = this._gamepad.leftStick;
-                var normalizedLX = LSValues.x / this.moveSensibility;
-                var normalizedLY = LSValues.y / this.moveSensibility;
-                LSValues.x = Math.abs(normalizedLX) > 0.005 ? 0 + normalizedLX : 0;
-                LSValues.y = Math.abs(normalizedLY) > 0.005 ? 0 + normalizedLY : 0;
-
-                var RSValues = this._gamepad.rightStick;
-                var normalizedRX = RSValues.x / this.angularSensibility;
-                var normalizedRY = RSValues.y / this.angularSensibility;
-                RSValues.x = Math.abs(normalizedRX) > 0.001 ? 0 + normalizedRX : 0;
-                RSValues.y = Math.abs(normalizedRY) > 0.001 ? 0 + normalizedRY : 0;
-
-                var cameraTransform = Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
-
-                var speed = this._computeLocalCameraSpeed() * 50.0;
-                var deltaTransform = Vector3.TransformCoordinates(new Vector3(LSValues.x * speed, 0, -LSValues.y * speed), cameraTransform);
-                this.cameraDirection = this.cameraDirection.add(deltaTransform);
-                this.cameraRotation = this.cameraRotation.add(new Vector2(RSValues.y, RSValues.x));
-            }
-
-            super._checkInputs();
-        }
-
-        public dispose(): void {
-            this._gamepads.dispose();
-            super.dispose();
         }
     }
 }

+ 57 - 0
src/Cameras/babylon.universalCamera.js

@@ -0,0 +1,57 @@
+var __extends = (this && this.__extends) || function (d, b) {
+    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+    function __() { this.constructor = d; }
+    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var BABYLON;
+(function (BABYLON) {
+    // We're mainly based on the logic defined into the FreeCamera code
+    var UniversalCamera = (function (_super) {
+        __extends(UniversalCamera, _super);
+        function UniversalCamera(name, position, scene) {
+            var _this = this;
+            _super.call(this, name, position, scene);
+            this.gamepadAngularSensibility = 200;
+            this.gamepadMoveSensibility = 40;
+            this._gamepads = new BABYLON.Gamepads(function (gamepad) { _this._onNewGameConnected(gamepad); });
+        }
+        UniversalCamera.prototype._onNewGameConnected = function (gamepad) {
+            // Only the first gamepad can control the camera
+            if (gamepad.index === 0) {
+                this.gamepad = gamepad;
+            }
+        };
+        UniversalCamera.prototype.attachControl = function (canvas, noPreventDefault) {
+            _super.prototype.attachControl.call(this, canvas, false);
+        };
+        UniversalCamera.prototype.detachControl = function (canvas) {
+            _super.prototype.detachControl.call(this, canvas);
+        };
+        UniversalCamera.prototype._checkInputs = function () {
+            if (this.gamepad) {
+                var LSValues = this.gamepad.leftStick;
+                var normalizedLX = LSValues.x / this.gamepadMoveSensibility;
+                var normalizedLY = LSValues.y / this.gamepadMoveSensibility;
+                LSValues.x = Math.abs(normalizedLX) > 0.005 ? 0 + normalizedLX : 0;
+                LSValues.y = Math.abs(normalizedLY) > 0.005 ? 0 + normalizedLY : 0;
+                var RSValues = this.gamepad.rightStick;
+                var normalizedRX = RSValues.x / this.gamepadAngularSensibility;
+                var normalizedRY = RSValues.y / this.gamepadAngularSensibility;
+                RSValues.x = Math.abs(normalizedRX) > 0.001 ? 0 + normalizedRX : 0;
+                RSValues.y = Math.abs(normalizedRY) > 0.001 ? 0 + normalizedRY : 0;
+                var cameraTransform = BABYLON.Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
+                var speed = this._computeLocalCameraSpeed() * 50.0;
+                var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(LSValues.x * speed, 0, -LSValues.y * speed), cameraTransform);
+                this.cameraDirection = this.cameraDirection.add(deltaTransform);
+                this.cameraRotation = this.cameraRotation.add(new BABYLON.Vector2(RSValues.y, RSValues.x));
+            }
+            _super.prototype._checkInputs.call(this);
+        };
+        UniversalCamera.prototype.dispose = function () {
+            this._gamepads.dispose();
+            _super.prototype.dispose.call(this);
+        };
+        return UniversalCamera;
+    })(BABYLON.TouchCamera);
+    BABYLON.UniversalCamera = UniversalCamera;
+})(BABYLON || (BABYLON = {}));

+ 58 - 0
src/Cameras/babylon.universalCamera.ts

@@ -0,0 +1,58 @@
+module BABYLON {
+    // We're mainly based on the logic defined into the FreeCamera code
+    export class UniversalCamera extends TouchCamera {
+        public gamepad: Gamepad;
+        private _gamepads: Gamepads;
+        public gamepadAngularSensibility = 200;
+        public gamepadMoveSensibility = 40;
+
+        constructor(name: string, position: Vector3, scene: Scene) {
+            super(name, position, scene);
+            this._gamepads = new Gamepads((gamepad: Gamepad) => { this._onNewGameConnected(gamepad); });
+        }
+
+        private _onNewGameConnected(gamepad: Gamepad) {
+            // Only the first gamepad can control the camera
+            if (gamepad.index === 0) {
+                this.gamepad = gamepad;
+            }
+        }
+
+        public attachControl(canvas: HTMLCanvasElement, noPreventDefault: boolean): void {
+            super.attachControl(canvas, false);
+        }
+
+        public detachControl(canvas: HTMLCanvasElement): void {
+            super.detachControl(canvas);
+        }
+
+        public _checkInputs(): void {
+            if (this.gamepad) {
+                var LSValues = this.gamepad.leftStick;
+                var normalizedLX = LSValues.x / this.gamepadMoveSensibility;
+                var normalizedLY = LSValues.y / this.gamepadMoveSensibility;
+                LSValues.x = Math.abs(normalizedLX) > 0.005 ? 0 + normalizedLX : 0;
+                LSValues.y = Math.abs(normalizedLY) > 0.005 ? 0 + normalizedLY : 0;
+
+                var RSValues = this.gamepad.rightStick;
+                var normalizedRX = RSValues.x / this.gamepadAngularSensibility;
+                var normalizedRY = RSValues.y / this.gamepadAngularSensibility;
+                RSValues.x = Math.abs(normalizedRX) > 0.001 ? 0 + normalizedRX : 0;
+                RSValues.y = Math.abs(normalizedRY) > 0.001 ? 0 + normalizedRY : 0;
+
+                var cameraTransform = Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
+
+                var speed = this._computeLocalCameraSpeed() * 50.0;
+                var deltaTransform = Vector3.TransformCoordinates(new Vector3(LSValues.x * speed, 0, -LSValues.y * speed), cameraTransform);
+                this.cameraDirection = this.cameraDirection.add(deltaTransform);
+                this.cameraRotation = this.cameraRotation.add(new Vector2(RSValues.y, RSValues.x));
+            }
+            super._checkInputs();
+        }
+
+        public dispose(): void {
+            this._gamepads.dispose();
+            super.dispose();
+        }
+    }
+}

+ 35 - 8
src/Materials/Textures/Procedurals/babylon.proceduralTexture.js

@@ -7,9 +7,11 @@ var BABYLON;
 (function (BABYLON) {
     var ProceduralTexture = (function (_super) {
         __extends(ProceduralTexture, _super);
-        function ProceduralTexture(name, size, fragment, scene, fallbackTexture, generateMipMaps) {
+        function ProceduralTexture(name, size, fragment, scene, fallbackTexture, generateMipMaps, isCube) {
             if (generateMipMaps === void 0) { generateMipMaps = true; }
+            if (isCube === void 0) { isCube = false; }
             _super.call(this, null, scene, !generateMipMaps);
+            this.isCube = isCube;
             this.isEnabled = true;
             this._currentRefreshId = -1;
             this._refreshRate = 1;
@@ -33,7 +35,13 @@ var BABYLON;
             this._generateMipMaps = generateMipMaps;
             this.setFragment(fragment);
             this._fallbackTexture = fallbackTexture;
-            this._texture = scene.getEngine().createRenderTargetTexture(size, generateMipMaps);
+            if (isCube) {
+                this._texture = scene.getEngine().createRenderTargetCubeTexture(size, { generateMipMaps: generateMipMaps });
+                this.setFloat("face", 0);
+            }
+            else {
+                this._texture = scene.getEngine().createRenderTargetTexture(size, generateMipMaps);
+            }
             // VBO
             var vertices = [];
             vertices.push(1, 1);
@@ -180,9 +188,6 @@ var BABYLON;
         ProceduralTexture.prototype.render = function (useCameraPostProcess) {
             var scene = this.getScene();
             var engine = scene.getEngine();
-            engine.bindFramebuffer(this._texture);
-            // Clear
-            engine.clear(scene.clearColor, true, true);
             // Render
             engine.enableEffect(this._effect);
             engine.setState(false);
@@ -221,10 +226,32 @@ var BABYLON;
             }
             // VBOs
             engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, this._effect);
-            // Draw order
-            engine.draw(true, 0, 6);
+            if (this.isCube) {
+                for (var face = 0; face < 6; face++) {
+                    engine.bindFramebuffer(this._texture, face);
+                    this._effect.setFloat("face", face);
+                    // Clear
+                    engine.clear(scene.clearColor, true, true);
+                    // Draw order
+                    engine.draw(true, 0, 6);
+                    // Mipmaps
+                    if (face === 5) {
+                        engine.generateMipMapsForCubemap(this._texture);
+                    }
+                }
+            }
+            else {
+                engine.bindFramebuffer(this._texture);
+                // Clear
+                engine.clear(scene.clearColor, true, true);
+                // Draw order
+                engine.draw(true, 0, 6);
+            }
             // Unbind
-            engine.unBindFramebuffer(this._texture);
+            engine.unBindFramebuffer(this._texture, this.isCube);
+            if (this.onGenerated) {
+                this.onGenerated();
+            }
         };
         ProceduralTexture.prototype.clone = function () {
             var textureSize = this.getSize();

+ 41 - 10
src/Materials/Textures/Procedurals/babylon.proceduralTexture.ts

@@ -7,6 +7,8 @@
         private _currentRefreshId = -1;
         private _refreshRate = 1;
 
+        public onGenerated: () => void;
+
         private _vertexBuffer: WebGLBuffer;
         private _indexBuffer: WebGLBuffer;
         private _effect: Effect;
@@ -31,7 +33,7 @@
 
         private _fallbackTextureUsed = false;
 
-        constructor(name: string, size: any, fragment: any, scene: Scene, fallbackTexture?: Texture, generateMipMaps = true) {
+        constructor(name: string, size: any, fragment: any, scene: Scene, fallbackTexture?: Texture, generateMipMaps = true, public isCube = false) {
             super(null, scene, !generateMipMaps);
 
             scene._proceduralTextures.push(this);
@@ -45,7 +47,13 @@
 
             this._fallbackTexture = fallbackTexture;
 
-            this._texture = scene.getEngine().createRenderTargetTexture(size, generateMipMaps);
+            if (isCube) {
+                this._texture = scene.getEngine().createRenderTargetCubeTexture(size, { generateMipMaps: generateMipMaps });
+                this.setFloat("face", 0);
+            }
+            else {
+                this._texture = scene.getEngine().createRenderTargetTexture(size, generateMipMaps);
+            }
 
             // VBO
             var vertices = [];
@@ -237,11 +245,6 @@
             var scene = this.getScene();
             var engine = scene.getEngine();
 
-            engine.bindFramebuffer(this._texture);
-
-            // Clear
-            engine.clear(scene.clearColor, true, true);
-
             // Render
             engine.enableEffect(this._effect);
             engine.setState(false);
@@ -290,11 +293,39 @@
             // VBOs
             engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, this._effect);
 
-            // Draw order
-            engine.draw(true, 0, 6);
+            if (this.isCube) {
+                for (var face = 0; face < 6; face++) {
+                    engine.bindFramebuffer(this._texture, face);
+
+                    this._effect.setFloat("face", face);
+
+                    // Clear
+                    engine.clear(scene.clearColor, true, true);
+
+                    // Draw order
+                    engine.draw(true, 0, 6);
+
+                    // Mipmaps
+                    if (face === 5) {
+                        engine.generateMipMapsForCubemap(this._texture);
+                    }
+                }
+            } else {
+                engine.bindFramebuffer(this._texture);
+
+                // Clear
+                engine.clear(scene.clearColor, true, true);
+
+                // Draw order
+                engine.draw(true, 0, 6);
+            }
 
             // Unbind
-            engine.unBindFramebuffer(this._texture);
+            engine.unBindFramebuffer(this._texture, this.isCube);
+
+            if (this.onGenerated) {
+                this.onGenerated();
+            }
         }
 
         public clone(): ProceduralTexture {

+ 1 - 1
src/Mesh/babylon.mesh.ts

@@ -1762,7 +1762,7 @@
             return MeshBuilder.CreatePolyhedron(name, options, scene);
         }
 
-        public static CreateIcoSphere(name: string, options: { radius?: number, flat?: number, subdivisions?: number, sideOrientation?: number, updatable?: boolean }, scene: Scene): Mesh {
+        public static CreateIcoSphere(name: string, options: { radius?: number, flat?: boolean, subdivisions?: number, sideOrientation?: number, updatable?: boolean }, scene: Scene): Mesh {
             return MeshBuilder.CreateIcoSphere(name, options, scene);
         }
 

+ 1 - 1
src/Mesh/babylon.mesh.vertexData.ts

@@ -1465,7 +1465,7 @@
             return vertexData;
         }
 
-        public static CreateIcoSphere(options: { radius?: number, radiusX?: number, radiusY?: number, radiusZ?: number, flat?: number, subdivisions?: number, sideOrientation?: number }): VertexData {
+        public static CreateIcoSphere(options: { radius?: number, radiusX?: number, radiusY?: number, radiusZ?: number, flat?: boolean, subdivisions?: number, sideOrientation?: number }): VertexData {
             var sideOrientation = options.sideOrientation || Mesh.DEFAULTSIDE;
             var radius = options.radius || 1;
             var flat = (options.flat === undefined) ? true : options.flat;

+ 1 - 1
src/Mesh/babylon.meshBuilder.ts

@@ -27,7 +27,7 @@
             return disc;
         }
 
-        public static CreateIcoSphere(name: string, options: { radius?: number, radiusX?: number, radiusY?: number, radiusZ?: number, flat?: number, subdivisions?: number, sideOrientation?: number, updatable?: boolean }, scene: Scene): Mesh {
+        public static CreateIcoSphere(name: string, options: { radius?: number, radiusX?: number, radiusY?: number, radiusZ?: number, flat?: boolean, subdivisions?: number, sideOrientation?: number, updatable?: boolean }, scene: Scene): Mesh {
             var sphere = new Mesh(name, scene);
             var vertexData = VertexData.CreateIcoSphere(options);
 

+ 0 - 1
src/Shaders/default.fragment.fx

@@ -850,7 +850,6 @@ void main(void) {
 	// Reflection
 	vec3 reflectionColor = vec3(0., 0., 0.);
 
-
 #ifdef REFLECTION
 	vec3 vReflectionUVW = computeReflectionCoords(vec4(vPositionW, 1.0), normalW);
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 47
src/Tools/babylon.gamepads.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 59
src/Tools/babylon.gamepads.ts


+ 7 - 13
src/babylon.engine.js

@@ -291,7 +291,7 @@ var BABYLON;
             mag: magFilter
         };
     };
-    var prepareWebGLTexture = function (texture, gl, scene, width, height, invertY, noMipmap, isCompressed, processFunction, samplingMode) {
+    var prepareWebGLTexture = function (texture, gl, scene, width, height, invertY, noMipmap, isCompressed, processFunction, onLoad, samplingMode) {
         if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
         var engine = scene.getEngine();
         var potWidth = BABYLON.Tools.GetExponentOfTwo(width, engine.getCaps().maxTextureSize);
@@ -313,6 +313,9 @@ var BABYLON;
         gl.bindTexture(gl.TEXTURE_2D, null);
         engine.resetTextureCache();
         scene._removePendingData(texture);
+        if (onLoad) {
+            onLoad();
+        }
     };
     var partialLoad = function (url, index, loadedImages, scene, onfinish) {
         var img;
@@ -1420,10 +1423,7 @@ var BABYLON;
                     var header = BABYLON.Internals.TGATools.GetTGAHeader(data);
                     prepareWebGLTexture(texture, _this._gl, scene, header.width, header.height, invertY, noMipmap, false, function () {
                         BABYLON.Internals.TGATools.UploadContent(_this._gl, data);
-                        if (onLoad) {
-                            onLoad();
-                        }
-                    }, samplingMode);
+                    }, onLoad, samplingMode);
                 };
                 if (!(fromData instanceof Array))
                     BABYLON.Tools.LoadFile(url, function (arrayBuffer) {
@@ -1438,10 +1438,7 @@ var BABYLON;
                     var loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && !noMipmap && ((info.width >> (info.mipmapCount - 1)) === 1);
                     prepareWebGLTexture(texture, _this._gl, scene, info.width, info.height, invertY, !loadMipmap, info.isFourCC, function () {
                         BABYLON.Internals.DDSTools.UploadDDSLevels(_this._gl, _this.getCaps().s3tc, data, info, loadMipmap, 1);
-                        if (onLoad) {
-                            onLoad();
-                        }
-                    }, samplingMode);
+                    }, onLoad, samplingMode);
                 };
                 if (!(fromData instanceof Array))
                     BABYLON.Tools.LoadFile(url, function (data) {
@@ -1475,10 +1472,7 @@ var BABYLON;
                             }
                         }
                         _this._gl.texImage2D(_this._gl.TEXTURE_2D, 0, _this._gl.RGBA, _this._gl.RGBA, _this._gl.UNSIGNED_BYTE, isPot ? img : _this._workingCanvas);
-                        if (onLoad) {
-                            onLoad();
-                        }
-                    }, samplingMode);
+                    }, onLoad, samplingMode);
                 };
                 if (!(fromData instanceof Array))
                     BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);

+ 8 - 16
src/babylon.engine.ts

@@ -302,7 +302,7 @@
     }
 
     var prepareWebGLTexture = (texture: WebGLTexture, gl: WebGLRenderingContext, scene: Scene, width: number, height: number, invertY: boolean, noMipmap: boolean, isCompressed: boolean,
-        processFunction: (width: number, height: number) => void, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) => {
+        processFunction: (width: number, height: number) => void, onLoad: () => void, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) => {
         var engine = scene.getEngine();
         var potWidth = Tools.GetExponentOfTwo(width, engine.getCaps().maxTextureSize);
         var potHeight = Tools.GetExponentOfTwo(height, engine.getCaps().maxTextureSize);
@@ -331,6 +331,10 @@
 
         engine.resetTextureCache();
         scene._removePendingData(texture);
+
+        if (onLoad) {
+            onLoad();
+        }
     };
 
     var partialLoad = (url: string, index: number, loadedImages: any, scene,
@@ -1678,11 +1682,7 @@
 
                     prepareWebGLTexture(texture, this._gl, scene, header.width, header.height, invertY, noMipmap, false, () => {
                         Internals.TGATools.UploadContent(this._gl, data);
-
-                        if (onLoad) {
-                            onLoad();
-                        }
-                    }, samplingMode);
+                    }, onLoad, samplingMode);
                 };
                 if (!(fromData instanceof Array))
                     Tools.LoadFile(url, arrayBuffer => {
@@ -1699,11 +1699,7 @@
                     prepareWebGLTexture(texture, this._gl, scene, info.width, info.height, invertY, !loadMipmap, info.isFourCC, () => {
 
                         Internals.DDSTools.UploadDDSLevels(this._gl, this.getCaps().s3tc, data, info, loadMipmap, 1);
-
-                        if (onLoad) {
-                            onLoad();
-                        }
-                    }, samplingMode);
+                    }, onLoad, samplingMode);
                 };
 
                 if (!(fromData instanceof Array))
@@ -1742,11 +1738,7 @@
                         }
 
                         this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, isPot ? img : this._workingCanvas);
-
-                        if (onLoad) {
-                            onLoad();
-                        }
-                    }, samplingMode);
+                    }, onLoad, samplingMode);
                 };
 
 

+ 14 - 0
src/babylon.scene.js

@@ -771,6 +771,20 @@ var BABYLON;
             }
         };
         /**
+         * Switch active camera
+         * @param {Camera} newCamera - new active camera
+         * @param {boolean} attachControl - call attachControl for the new active camera (default: true)
+         */
+        Scene.prototype.swithActiveCamera = function (newCamera, attachControl) {
+            if (attachControl === void 0) { attachControl = true; }
+            var canvas = this._engine.getRenderingCanvas();
+            this.activeCamera.detachControl(canvas);
+            this.activeCamera = newCamera;
+            if (attachControl) {
+                newCamera.attachControl(canvas);
+            }
+        };
+        /**
          * sets the active camera of the scene using its ID
          * @param {string} id - the camera's ID
          * @return {BABYLON.Camera|null} the new active camera or null if none found.

+ 17 - 21
src/babylon.scene.ts

@@ -278,8 +278,8 @@
         private _depthRenderer: DepthRenderer;
 
         private _uniqueIdCounter = 0;
-        
-        private _pickedMeshName : string = null;
+
+        private _pickedMeshName: string = null;
 
         /**
          * @constructor
@@ -511,7 +511,7 @@
                     return;
                 }
 
-                this._updatePointerPosition(evt); 
+                this._updatePointerPosition(evt);
                 this._pickedMeshName = null;
                 this._startingPointerPosition.x = this._pointerX;
                 this._startingPointerPosition.y = this._pointerY;
@@ -611,9 +611,9 @@
                 var pickResult = this.pick(this._pointerX, this._pointerY, predicate, false, this.cameraToUseForPointers);
 
                 if (pickResult.hit && pickResult.pickedMesh) {
-                    if(this.onPointerPick && this._pickedMeshName != null && pickResult.pickedMesh.name == this._pickedMeshName){
-						this.onPointerPick(evt, pickResult);
-					}
+                    if (this.onPointerPick && this._pickedMeshName != null && pickResult.pickedMesh.name == this._pickedMeshName) {
+                        this.onPointerPick(evt, pickResult);
+                    }
                     if (pickResult.pickedMesh.actionManager) {
                         pickResult.pickedMesh.actionManager.processTrigger(ActionManager.OnPickUpTrigger, ActionEvent.CreateNew(pickResult.pickedMesh, evt));
 
@@ -1003,21 +1003,18 @@
         }
         
         /**
-         * Swith the active camera of the scene
-         * @param {Camera} newCamera - the new camera
-		 * @param {boolean} control - attachControl for the camera (default true)
+         * Switch active camera
+         * @param {Camera} newCamera - new active camera
+		 * @param {boolean} attachControl - call attachControl for the new active camera (default: true)
          */
-		public swithActiveCamera(newCamera: Camera, control: boolean) {	
-			if(control == undefined) {
-				control = true;
-			}			
-			var canvas = this._engine.getRenderingCanvas();
-			this.activeCamera.detachControl(canvas);			
-			this.activeCamera = newCamera;			
-			if(control) {
-				newCamera.attachControl(canvas);
-			}	
-		}
+        public swithActiveCamera(newCamera: Camera, attachControl = true) {
+            var canvas = this._engine.getRenderingCanvas();
+            this.activeCamera.detachControl(canvas);
+            this.activeCamera = newCamera;
+            if (attachControl) {
+                newCamera.attachControl(canvas);
+            }
+        }
 
         /**
          * sets the active camera of the scene using its ID
@@ -2581,4 +2578,3 @@
         }
     }
 }
-