Selaa lähdekoodia

Merge pull request #3198 from BabylonJS/strictFunctionTypes

strictFunctionTypes:
David Catuhe 7 vuotta sitten
vanhempi
commit
98fd68a70e

+ 1 - 1
Tools/Gulp/gulpfile.js

@@ -49,7 +49,7 @@ var tsConfig = {
     noImplicitThis: true,
     noUnusedLocals: true,
     strictNullChecks: true,
-    strictFunctionTypes: false
+    strictFunctionTypes: true
 };
 var tsProject = typescript.createProject(tsConfig);
 

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 2042 - 2040
dist/preview release/babylon.d.ts


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 40 - 40
dist/preview release/babylon.js


+ 317 - 24
dist/preview release/babylon.max.js

@@ -7863,7 +7863,7 @@ var BABYLON;
             }
         };
         var onerror = function (request, exception) {
-            if (onErrorCallBack) {
+            if (onErrorCallBack && request) {
                 onErrorCallBack(request.status + " " + request.statusText, exception);
             }
         };
@@ -11042,7 +11042,7 @@ var BABYLON;
                 isDDS = (extension === ".dds");
             }
             var onerror = function (request, exception) {
-                if (onError) {
+                if (onError && request) {
                     onError(request.status + " " + request.statusText, exception);
                 }
             };
@@ -11268,7 +11268,7 @@ var BABYLON;
             this._internalTexturesCache.push(texture);
             var onerror = function (request, exception) {
                 scene._removePendingData(texture);
-                if (onError) {
+                if (onError && request) {
                     onError(request.status + " " + request.statusText, exception);
                 }
             };
@@ -13442,15 +13442,18 @@ var BABYLON;
             return this;
         };
         /**
-         * Defines the passed mesh as the parent of the current mesh.
-         * Returns the AbstractMesh.
+         * Defines the passed node as the parent of the current node.
+         * Returns the TransformNode.
          */
-        TransformNode.prototype.setParent = function (mesh) {
-            var parent = mesh;
-            if (mesh == null) {
+        TransformNode.prototype.setParent = function (node) {
+            if (node == null) {
                 var rotation = BABYLON.Tmp.Quaternion[0];
                 var position = BABYLON.Tmp.Vector3[0];
                 var scale = BABYLON.Tmp.Vector3[1];
+                if (this.parent && this.parent.computeWorldMatrix) {
+                    this.parent.computeWorldMatrix(true);
+                }
+                this.computeWorldMatrix(true);
                 this.getWorldMatrix().decompose(scale, rotation, position);
                 if (this.rotationQuaternion) {
                     this.rotationQuaternion.copyFrom(rotation);
@@ -13463,13 +13466,34 @@ var BABYLON;
                 this.position.z = position.z;
             }
             else {
+                var rotation = BABYLON.Tmp.Quaternion[0];
                 var position = BABYLON.Tmp.Vector3[0];
-                var m1 = BABYLON.Tmp.Matrix[0];
-                parent.getWorldMatrix().invertToRef(m1);
-                BABYLON.Vector3.TransformCoordinatesToRef(this.position, m1, position);
-                this.position.copyFrom(position);
+                var scale = BABYLON.Tmp.Vector3[1];
+                var m0 = BABYLON.Tmp.Matrix[0];
+                var m1 = BABYLON.Tmp.Matrix[1];
+                var invParentMatrix = BABYLON.Tmp.Matrix[2];
+                node.computeWorldMatrix(true);
+                node.getWorldMatrix().decompose(scale, rotation, position);
+                rotation.toRotationMatrix(m0);
+                m1.setTranslation(position);
+                m1.multiplyToRef(m0, m0);
+                m0.invertToRef(invParentMatrix);
+                this.getWorldMatrix().multiplyToRef(invParentMatrix, m0);
+                m0.decompose(scale, rotation, position);
+                if (this.rotationQuaternion) {
+                    this.rotationQuaternion.copyFrom(rotation);
+                }
+                else {
+                    rotation.toEulerAnglesToRef(this.rotation);
+                }
+                node.getWorldMatrix().invertToRef(invParentMatrix);
+                this.getWorldMatrix().multiplyToRef(invParentMatrix, m0);
+                m0.decompose(scale, rotation, position);
+                this.position.x = position.x;
+                this.position.y = position.y;
+                this.position.z = position.z;
             }
-            this.parent = parent;
+            this.parent = node;
             return this;
         };
         Object.defineProperty(TransformNode.prototype, "nonUniformScaling", {
@@ -24169,10 +24193,9 @@ var BABYLON;
             return this;
         };
         Mesh.prototype._onBeforeDraw = function (isInstance, world, effectiveMaterial) {
-            if (isInstance) {
+            if (isInstance && effectiveMaterial) {
                 effectiveMaterial.bindOnlyWorldMatrix(world);
             }
-            return this;
         };
         /**
          * Returns an array populated with ParticleSystem objects whose the mesh is the emitter.
@@ -24393,7 +24416,8 @@ var BABYLON;
             }
             // Sources
             var meshes = this.getScene().meshes;
-            meshes.forEach(function (mesh) {
+            meshes.forEach(function (abstractMesh) {
+                var mesh = abstractMesh;
                 if (mesh._source && mesh._source === _this) {
                     mesh._source = null;
                 }
@@ -33261,6 +33285,9 @@ var BABYLON;
             }
             this._texture = texture;
             var callback = function (text) {
+                if (typeof text !== "string") {
+                    return;
+                }
                 var data = null;
                 var tempData = null;
                 var line;
@@ -44526,8 +44553,8 @@ var BABYLON;
             var _this = this;
             this._scaledPosition = BABYLON.Vector3.Zero();
             this._scaledVelocity = BABYLON.Vector3.Zero();
-            this.onMeshUpdated = function (mesh) {
-                _this._addUpdateMeshesList[mesh.uniqueId] = CollisionCoordinatorWorker.SerializeMesh(mesh);
+            this.onMeshUpdated = function (transformNode) {
+                _this._addUpdateMeshesList[transformNode.uniqueId] = CollisionCoordinatorWorker.SerializeMesh(transformNode);
             };
             this.onGeometryUpdated = function (geometry) {
                 _this._addUpdateGeometriesList[geometry.id] = CollisionCoordinatorWorker.SerializeGeometry(geometry);
@@ -49850,8 +49877,12 @@ var BABYLON;
                 this._connectedMesh = null;
             }
         };
-        Sound.prototype._onRegisterAfterWorldMatrixUpdate = function (connectedMesh) {
-            var boundingInfo = connectedMesh.getBoundingInfo();
+        Sound.prototype._onRegisterAfterWorldMatrixUpdate = function (node) {
+            if (!node.getBoundingInfo) {
+                return;
+            }
+            var mesh = node;
+            var boundingInfo = mesh.getBoundingInfo();
             this.setPosition(boundingInfo.boundingSphere.centerWorld);
             if (BABYLON.Engine.audioEngine.canUseWebAudio && this._isDirectional && this.isPlaying) {
                 this._updateDirection();
@@ -67269,6 +67300,9 @@ var BABYLON;
         PhysicsEngine.prototype.getPhysicsPlugin = function () {
             return this._physicsPlugin;
         };
+        PhysicsEngine.prototype.getImpostors = function () {
+            return this._impostors;
+        };
         PhysicsEngine.prototype.getImpostorForPhysicsObject = function (object) {
             for (var i = 0; i < this._impostors.length; ++i) {
                 if (this._impostors[i].object === object) {
@@ -67296,6 +67330,265 @@ var BABYLON;
 
 var BABYLON;
 (function (BABYLON) {
+    /**
+     * The strenght of the force in correspondence to the distance of the affected object
+     */
+    var PhysicsRadialImpulseFallof;
+    (function (PhysicsRadialImpulseFallof) {
+        PhysicsRadialImpulseFallof[PhysicsRadialImpulseFallof["Constant"] = 0] = "Constant";
+        PhysicsRadialImpulseFallof[PhysicsRadialImpulseFallof["Linear"] = 1] = "Linear"; // impulse gets weaker if it's further from the origin
+    })(PhysicsRadialImpulseFallof = BABYLON.PhysicsRadialImpulseFallof || (BABYLON.PhysicsRadialImpulseFallof = {}));
+    var PhysicsHelper = /** @class */ (function () {
+        function PhysicsHelper(scene) {
+            this._scene = scene;
+            this._physicsEngine = this._scene.getPhysicsEngine();
+            if (!this._physicsEngine) {
+                BABYLON.Tools.Warn('Physics engine not enabled. Please enable the physics before you can use the methods.');
+            }
+        }
+        /**
+         * @param {Vector3} origin the origin of the explosion
+         * @param {number} radius the explosion radius
+         * @param {number} strength the explosion strength
+         * @param {PhysicsRadialImpulseFallof} falloff possible options: Constant & Linear. Defaults to Constant
+         */
+        PhysicsHelper.prototype.applyRadialExplosionImpulse = function (origin, radius, strength, falloff) {
+            if (falloff === void 0) { falloff = PhysicsRadialImpulseFallof.Constant; }
+            if (!this._physicsEngine) {
+                BABYLON.Tools.Warn('Physics engine not enabled. Please enable the physics before you call this method.');
+                return null;
+            }
+            var impostors = this._physicsEngine.getImpostors();
+            if (impostors.length === 0) {
+                return null;
+            }
+            var event = new PhysicsRadialExplosionEvent(this._scene);
+            for (var i = 0; i < impostors.length; ++i) {
+                var impostor = impostors[i];
+                var impostorForceAndContactPoint = event.getImpostorForceAndContactPoint(impostor, origin, radius, strength, falloff);
+                if (impostorForceAndContactPoint === null) {
+                    continue;
+                }
+                impostor.applyImpulse(impostorForceAndContactPoint.force, impostorForceAndContactPoint.contactPoint);
+            }
+            event.cleanup(false);
+            return event;
+        };
+        /**
+         * @param {Vector3} origin the origin of the explosion
+         * @param {number} radius the explosion radius
+         * @param {number} strength the explosion strength
+         * @param {PhysicsRadialImpulseFallof} falloff possible options: Constant & Linear. Defaults to Constant
+         */
+        PhysicsHelper.prototype.applyRadialExplosionForce = function (origin, radius, strength, falloff) {
+            if (falloff === void 0) { falloff = PhysicsRadialImpulseFallof.Constant; }
+            if (!this._physicsEngine) {
+                BABYLON.Tools.Warn('Physics engine not enabled. Please enable the physics before you call the PhysicsHelper.');
+                return null;
+            }
+            var impostors = this._physicsEngine.getImpostors();
+            if (impostors.length === 0) {
+                return null;
+            }
+            var event = new PhysicsRadialExplosionEvent(this._scene);
+            for (var i = 0; i < impostors.length; ++i) {
+                var impostor = impostors[i];
+                var impostorForceAndContactPoint = event.getImpostorForceAndContactPoint(impostor, origin, radius, strength, falloff);
+                if (impostorForceAndContactPoint === null) {
+                    continue;
+                }
+                impostor.applyForce(impostorForceAndContactPoint.force, impostorForceAndContactPoint.contactPoint);
+            }
+            event.cleanup(false);
+            return event;
+        };
+        /**
+         * @param {Vector3} origin the origin of the explosion
+         * @param {number} radius the explosion radius
+         * @param {number} strength the explosion strength
+         * @param {PhysicsRadialImpulseFallof} falloff possible options: Constant & Linear. Defaults to Constant
+         */
+        PhysicsHelper.prototype.gravitationalField = function (origin, radius, strength, falloff) {
+            if (falloff === void 0) { falloff = PhysicsRadialImpulseFallof.Constant; }
+            if (!this._physicsEngine) {
+                BABYLON.Tools.Warn('Physics engine not enabled. Please enable the physics before you call the PhysicsHelper.');
+                return null;
+            }
+            var impostors = this._physicsEngine.getImpostors();
+            if (impostors.length === 0) {
+                return null;
+            }
+            var event = new PhysicsGravitationalFieldEvent(this, this._scene, origin, radius, strength, falloff);
+            event.cleanup(false);
+            return event;
+        };
+        return PhysicsHelper;
+    }());
+    BABYLON.PhysicsHelper = PhysicsHelper;
+    /***** Radial explosion *****/
+    var PhysicsRadialExplosionEvent = /** @class */ (function () {
+        function PhysicsRadialExplosionEvent(scene) {
+            this._rays = [];
+            this._dataFetched = false; // check if the data has been fetched. If not, do cleanup
+            this._scene = scene;
+        }
+        /**
+         * Returns the data related to the radial explosion event (radialSphere & rays).
+         * @returns {PhysicsRadialExplosionEventData}
+         */
+        PhysicsRadialExplosionEvent.prototype.getData = function () {
+            this._dataFetched = true;
+            return {
+                radialSphere: this._radialSphere,
+                rays: this._rays,
+            };
+        };
+        /**
+         * Returns the force and contact point of the impostor or false, if the impostor is not affected by the force/impulse.
+         * @param impostor
+         * @param {Vector3} origin the origin of the explosion
+         * @param {number} radius the explosion radius
+         * @param {number} strength the explosion strength
+         * @param {PhysicsRadialImpulseFallof} falloff possible options: Constant & Linear
+         * @returns {Nullable<PhysicsForceAndContactPoint>}
+         */
+        PhysicsRadialExplosionEvent.prototype.getImpostorForceAndContactPoint = function (impostor, origin, radius, strength, falloff) {
+            if (impostor.mass === 0) {
+                return null;
+            }
+            if (!this._intersectsWithRadialSphere(impostor, origin, radius)) {
+                return null;
+            }
+            var impostorObject = impostor.object;
+            var impostorObjectCenter = impostor.getObjectCenter();
+            var direction = impostorObjectCenter.subtract(origin);
+            var ray = new BABYLON.Ray(origin, direction, radius);
+            this._rays.push(ray);
+            var hit = ray.intersectsMesh(impostorObject);
+            var contactPoint = hit.pickedPoint;
+            if (!contactPoint) {
+                return null;
+            }
+            var distanceFromOrigin = BABYLON.Vector3.Distance(origin, contactPoint);
+            if (distanceFromOrigin > radius) {
+                return null;
+            }
+            var multiplier = falloff === PhysicsRadialImpulseFallof.Constant
+                ? strength
+                : strength * (1 - (distanceFromOrigin / radius));
+            var force = direction.multiplyByFloats(multiplier, multiplier, multiplier);
+            return { force: force, contactPoint: contactPoint };
+        };
+        /**
+         * Disposes the radialSphere.
+         * @param {bolean} force
+         */
+        PhysicsRadialExplosionEvent.prototype.cleanup = function (force) {
+            var _this = this;
+            if (force === void 0) { force = true; }
+            if (force) {
+                this._radialSphere.dispose();
+            }
+            else {
+                setTimeout(function () {
+                    if (!_this._dataFetched) {
+                        _this._radialSphere.dispose();
+                    }
+                }, 0);
+            }
+        };
+        /*** Helpers ***/
+        PhysicsRadialExplosionEvent.prototype._prepareRadialSphere = function () {
+            if (!this._radialSphere) {
+                this._radialSphere = BABYLON.Mesh.CreateSphere("radialSphere", 32, 1, this._scene);
+                this._radialSphere.isVisible = false;
+            }
+        };
+        PhysicsRadialExplosionEvent.prototype._intersectsWithRadialSphere = function (impostor, origin, radius) {
+            var impostorObject = impostor.object;
+            this._prepareRadialSphere();
+            this._radialSphere.position = origin;
+            this._radialSphere.scaling = new BABYLON.Vector3(radius * 2, radius * 2, radius * 2);
+            this._radialSphere._updateBoundingInfo();
+            this._radialSphere.computeWorldMatrix(true);
+            return this._radialSphere.intersectsMesh(impostorObject, true);
+        };
+        return PhysicsRadialExplosionEvent;
+    }());
+    BABYLON.PhysicsRadialExplosionEvent = PhysicsRadialExplosionEvent;
+    /***** Gravitational Field *****/
+    var PhysicsGravitationalFieldEvent = /** @class */ (function () {
+        function PhysicsGravitationalFieldEvent(physicsHelper, scene, origin, radius, strength, falloff) {
+            if (falloff === void 0) { falloff = PhysicsRadialImpulseFallof.Constant; }
+            this._dataFetched = false; // check if the has been fetched the data. If not, do cleanup
+            this._physicsHelper = physicsHelper;
+            this._scene = scene;
+            this._origin = origin;
+            this._radius = radius;
+            this._strength = strength;
+            this._falloff = falloff;
+            this._tickCallback = this._tick.bind(this);
+        }
+        /**
+         * Returns the data related to the gravitational field event (radialSphere).
+         * @returns {PhysicsGravitationalFieldEventData}
+         */
+        PhysicsGravitationalFieldEvent.prototype.getData = function () {
+            this._dataFetched = true;
+            return {
+                radialSphere: this._radialSphere,
+            };
+        };
+        /**
+         * Enables the gravitational field.
+         */
+        PhysicsGravitationalFieldEvent.prototype.enable = function () {
+            this._tickCallback.call(this);
+            this._scene.registerBeforeRender(this._tickCallback);
+        };
+        /**
+         * Disables the gravitational field.
+         */
+        PhysicsGravitationalFieldEvent.prototype.disable = function () {
+            this._scene.unregisterBeforeRender(this._tickCallback);
+        };
+        /**
+         * Disposes the radialSphere.
+         * @param {bolean} force
+         */
+        PhysicsGravitationalFieldEvent.prototype.cleanup = function (force) {
+            var _this = this;
+            if (force === void 0) { force = true; }
+            if (force) {
+                this._radialSphere.dispose();
+            }
+            else {
+                setTimeout(function () {
+                    if (!_this._dataFetched) {
+                        _this._radialSphere.dispose();
+                    }
+                }, 0);
+            }
+        };
+        PhysicsGravitationalFieldEvent.prototype._tick = function () {
+            // Since the params won't change, we fetch the event only once
+            if (this._radialSphere) {
+                this._physicsHelper.applyRadialExplosionForce(this._origin, this._radius, this._strength * -1, this._falloff);
+            }
+            else {
+                var radialExplosionEvent = this._physicsHelper.applyRadialExplosionForce(this._origin, this._radius, this._strength * -1, this._falloff);
+                this._radialSphere = radialExplosionEvent.getData().radialSphere.clone('radialSphereClone');
+            }
+        };
+        return PhysicsGravitationalFieldEvent;
+    }());
+    BABYLON.PhysicsGravitationalFieldEvent = PhysicsGravitationalFieldEvent;
+})(BABYLON || (BABYLON = {}));
+
+//# sourceMappingURL=babylon.physicsHelper.js.map
+
+var BABYLON;
+(function (BABYLON) {
     var CannonJSPlugin = /** @class */ (function () {
         function CannonJSPlugin(_useDeltaForWorldStep, iterations) {
             if (_useDeltaForWorldStep === void 0) { _useDeltaForWorldStep = true; }
@@ -74680,8 +74973,8 @@ var BABYLON;
             var onload = function () {
                 onSuccess();
             };
-            var onerror = function (msg, exception) {
-                onError(msg, exception);
+            var onerror = function (message, exception) {
+                onError(message, exception);
             };
             this.texture = new BABYLON.Texture(this.url, scene, this.noMipmap, this.invertY, this.samplingMode, onload, onerror);
         };
@@ -74703,8 +74996,8 @@ var BABYLON;
             var onload = function () {
                 onSuccess();
             };
-            var onerror = function (msg, exception) {
-                onError(msg, exception);
+            var onerror = function (message, exception) {
+                onError(message, exception);
             };
             this.texture = new BABYLON.CubeTexture(this.url, scene, this.extensions, this.noMipmap, this.files, onload, onerror);
         };

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 41 - 41
dist/preview release/babylon.worker.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
dist/preview release/loaders/babylon.objFileLoader.min.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
dist/preview release/loaders/babylonjs.loaders.min.js


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

@@ -57,3 +57,4 @@
 ## Breaking changes
 - `Gamepads` was removed in favor of `scene.gamepadManager`
 - `DynamicFloatArray`, `MapTexture` and `RectPakingMap` were removed because there were not used anymore
+- `IAssetTask` was removed in favor of `AbstractAssetTask` class

+ 8 - 4
src/Audio/babylon.sound.ts

@@ -39,7 +39,7 @@ module BABYLON {
         private _scene: Scene;
         private _connectedMesh: Nullable<AbstractMesh>;
         private _customAttenuationFunction: (currentVolume: number, currentDistance: number, maxDistance: number, refDistance: number, rolloffFactor: number) => number;
-        private _registerFunc: Nullable<(connectedMesh: AbstractMesh) => any>;
+        private _registerFunc: Nullable<(connectedMesh: TransformNode) => void>;
         private _isOutputConnected = false;
         private _htmlAudioElement: HTMLAudioElement;
         private _urlType: string = "Unknown";
@@ -547,7 +547,7 @@ module BABYLON {
                 }
             }
             this._onRegisterAfterWorldMatrixUpdate(this._connectedMesh);
-            this._registerFunc = (connectedMesh: AbstractMesh) => this._onRegisterAfterWorldMatrixUpdate(connectedMesh);
+            this._registerFunc = (connectedMesh: TransformNode) => this._onRegisterAfterWorldMatrixUpdate(connectedMesh);
             meshToConnectTo.registerAfterWorldMatrixUpdate(this._registerFunc);
         }
 
@@ -559,8 +559,12 @@ module BABYLON {
             }
         }
 
-        private _onRegisterAfterWorldMatrixUpdate(connectedMesh: AbstractMesh): void {
-            let boundingInfo = connectedMesh.getBoundingInfo();
+        private _onRegisterAfterWorldMatrixUpdate(node: TransformNode): void {
+            if (!(<any>node).getBoundingInfo) {
+                return;
+            }
+            let mesh = node as AbstractMesh;
+            let boundingInfo = mesh.getBoundingInfo();
             this.setPosition(boundingInfo.boundingSphere.centerWorld);
             if (Engine.audioEngine.canUseWebAudio && this._isDirectional && this.isPlaying) {
                 this._updateDirection();

+ 1 - 1
src/Behaviors/Cameras/babylon.bouncingBehavior.ts

@@ -77,7 +77,7 @@ module BABYLON {
         // Connection
         private _attachedCamera: Nullable<ArcRotateCamera>;
 		private _onAfterCheckInputsObserver: Nullable<Observer<Camera>>;	
-		private _onMeshTargetChangedObserver: Nullable<Observer<AbstractMesh>>;
+		private _onMeshTargetChangedObserver: Nullable<Observer<Nullable<AbstractMesh>>>;
 
 		public init(): void {
 			// Do notihng

+ 1 - 1
src/Behaviors/Cameras/babylon.framingBehavior.ts

@@ -142,7 +142,7 @@ module BABYLON {
         // Default behavior functions
         private _onPrePointerObservableObserver: Nullable<Observer<PointerInfoPre>>;
 		private _onAfterCheckInputsObserver: Nullable<Observer<Camera>>;
-		private _onMeshTargetChangedObserver: Nullable<Observer<AbstractMesh>>;
+		private _onMeshTargetChangedObserver: Nullable<Observer<Nullable<AbstractMesh>>>;
         private _attachedCamera: Nullable<ArcRotateCamera>;
         private _isPointerDown = false;
 		private _lastInteractionTime = -Infinity;

+ 3 - 3
src/Cameras/VR/babylon.vrExperienceHelper.ts

@@ -48,16 +48,16 @@ module BABYLON {
         private _xboxGamepadTeleportationRequestInitiated = false;
         private _rotationRightAsked = false;
         private _rotationLeftAsked = false;
-        private _teleportationCircle: BABYLON.Mesh;
+        private _teleportationCircle: Mesh;
         private _postProcessMove: ImageProcessingPostProcess;
         private _passProcessMove: PassPostProcess;
         private _teleportationFillColor: string = "#444444";
         private _teleportationBorderColor: string = "#FFFFFF";
         private _rotationAngle: number = 0;
-        private _haloCenter = new BABYLON.Vector3(0, 0, 0);
+        private _haloCenter = new Vector3(0, 0, 0);
         private _rayHelper: RayHelper;
 
-        public meshSelectionPredicate: (mesh: BABYLON.Mesh) => boolean;
+        public meshSelectionPredicate: (mesh: AbstractMesh) => boolean;
 
         public get deviceOrientationCamera(): DeviceOrientationCamera {
             return this._deviceOrientationCamera;

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

@@ -320,7 +320,7 @@
             }
         }
 
-        public onMeshTargetChangedObservable = new Observable<AbstractMesh>();
+        public onMeshTargetChangedObservable = new Observable<Nullable<AbstractMesh>>();
 
         // Collisions
         public onCollide: (collidedMesh: AbstractMesh) => void;

+ 2 - 2
src/Collisions/babylon.collisionCoordinator.ts

@@ -240,8 +240,8 @@ module BABYLON {
             this.onMeshUpdated(mesh);
         }
 
-        public onMeshUpdated = (mesh: AbstractMesh) => {
-            this._addUpdateMeshesList[mesh.uniqueId] = CollisionCoordinatorWorker.SerializeMesh(mesh);
+        public onMeshUpdated = (transformNode: TransformNode) => {
+            this._addUpdateMeshesList[transformNode.uniqueId] = CollisionCoordinatorWorker.SerializeMesh(transformNode as AbstractMesh);
         }
 
         public onMeshRemoved(mesh: AbstractMesh) {

+ 8 - 8
src/Engine/babylon.engine.ts

@@ -173,8 +173,8 @@
             }
         };
 
-        const onerror = (request: XMLHttpRequest, exception: any) => {
-            if (onErrorCallBack) {
+        const onerror = (request?: XMLHttpRequest, exception?: any) => {
+            if (onErrorCallBack && request) {
                 onErrorCallBack(request.status + " " + request.statusText, exception);
             }
         };
@@ -3938,8 +3938,8 @@
                 isDDS = (extension === ".dds");
             }
 
-            let onerror = (request: XMLHttpRequest, exception: any) => {
-                if (onError) {
+            let onerror = (request?: XMLHttpRequest, exception?: any) => {
+                if (onError && request) {
                     onError(request.status + " " + request.statusText, exception);
                 }
             }
@@ -4226,9 +4226,9 @@
             texture.url = url;
             this._internalTexturesCache.push(texture);
 
-            var onerror = (request: XMLHttpRequest, exception: any) => {
+            var onerror = (request?: XMLHttpRequest, exception?: any) => {
                 scene._removePendingData(texture);
-                if (onError) {
+                if (onError && request) {
                     onError(request.status + " " + request.statusText, exception);
                 }
             };
@@ -5001,13 +5001,13 @@
 
         public attachContextLostEvent(callback: ((event: WebGLContextEvent) => void)): void {
             if (this._renderingCanvas) {
-                this._renderingCanvas.addEventListener("webglcontextlost", callback, false);
+                this._renderingCanvas.addEventListener("webglcontextlost", <any>callback, false);
             }
         }
 
         public attachContextRestoredEvent(callback: ((event: WebGLContextEvent) => void)): void {
             if (this._renderingCanvas) {
-                this._renderingCanvas.addEventListener("webglcontextrestored", callback, false);
+                this._renderingCanvas.addEventListener("webglcontextrestored", <any>callback, false);
             }
         }
 

+ 1 - 1
src/LensFlare/babylon.lensFlareSystem.ts

@@ -3,7 +3,7 @@
         public lensFlares = new Array<LensFlare>();
         public borderLimit = 300;
         public viewportBorder = 0;
-        public meshesSelectionPredicate: (mesh: Mesh) => boolean;
+        public meshesSelectionPredicate: (mesh: AbstractMesh) => boolean;
         public layerMask: number = 0x0FFFFFFF;
         public id: string;
 

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

@@ -86,7 +86,12 @@ module BABYLON {
 
             this._texture = texture;
 
-            var callback = (text: string) => {
+            var callback = (text: string | ArrayBuffer) => {
+
+                if (typeof text !== "string") {
+                    return;
+                }
+
                 var data: Nullable<Uint8Array> = null;
                 var tempData: Nullable<Float32Array> = null;
 

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

@@ -103,7 +103,7 @@
             return this._samplingMode;
         }
 
-        constructor(url: Nullable<string>, scene: Nullable<Scene>, noMipmap: boolean = false, invertY: boolean = true, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE, onLoad: Nullable<() => void> = null, onError: Nullable<(message?: string, esception?: any) => void> = null, buffer: any = null, deleteBuffer: boolean = false, format?: number) {
+        constructor(url: Nullable<string>, scene: Nullable<Scene>, noMipmap: boolean = false, invertY: boolean = true, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE, onLoad: Nullable<() => void> = null, onError: Nullable<(message?: string, exception?: any) => void> = null, buffer: any = null, deleteBuffer: boolean = false, format?: number) {
             super(scene);
 
             this.name = url || "";

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

@@ -1338,11 +1338,10 @@
             return this;
         }
 
-        private _onBeforeDraw(isInstance: boolean, world: Matrix, effectiveMaterial: Material): Mesh {
-            if (isInstance) {
+        private _onBeforeDraw(isInstance: boolean, world: Matrix, effectiveMaterial?: Material): void {
+            if (isInstance && effectiveMaterial) {
                 effectiveMaterial.bindOnlyWorldMatrix(world);
             }
-            return this;
         }
 
         /**
@@ -1595,7 +1594,8 @@
 
             // Sources
             var meshes = this.getScene().meshes;
-            meshes.forEach((mesh: Mesh) => {
+            meshes.forEach((abstractMesh: AbstractMesh) => {
+                let mesh = abstractMesh as Mesh;
                 if (mesh._source && mesh._source === this) {
                     mesh._source = null;
                 }

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

@@ -448,7 +448,7 @@
             var dashSize = options.dashSize || 3;
 
             if (instance) {  //  dashed lines update
-                var positionFunction = (positions: number[]): void => {
+                var positionFunction = (positions: FloatArray): void => {
                     var curvect = Vector3.Zero();
                     var nbSeg = positions.length / 6;
                     var lg = 0;

+ 43 - 38
src/Tools/babylon.assetsManager.ts

@@ -7,30 +7,14 @@ module BABYLON {
         ERROR
     }
 
-    export interface IAssetTask<T extends AbstractAssetTask> {
-        onSuccess: (task: T) => void;
-        onError: (task: T, message?: string, exception?: any) => void;
-        isCompleted: boolean;
-        name: string;
-
-        taskState: AssetTaskState;
-        errorObject: {
-            message?: string;
-            exception?: any;
-        }
-
-        runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
-    }
-
-    export abstract class AbstractAssetTask implements IAssetTask<AbstractAssetTask> {
+    export abstract class AbstractAssetTask  {
+        public onSuccess: (task: any) => void;
+        public onError: (task: any, message?: string, exception?: any) => void;
 
         constructor(public name: string) {
             this.taskState = AssetTaskState.INIT;
         }
 
-        onSuccess: (task: this) => void;
-        onError: (task: this, message?: string, exception?: any) => void;
-
         isCompleted: boolean = false;
         taskState: AssetTaskState;
         errorObject: { message?: string; exception?: any; };
@@ -98,11 +82,14 @@ module BABYLON {
         }
     }
 
-    export class MeshAssetTask extends AbstractAssetTask implements IAssetTask<MeshAssetTask> {
+    export class MeshAssetTask extends AbstractAssetTask {
         public loadedMeshes: Array<AbstractMesh>;
         public loadedParticleSystems: Array<ParticleSystem>;
         public loadedSkeletons: Array<Skeleton>;
 
+        public onSuccess: (task: MeshAssetTask) => void;
+        public onError: (task: MeshAssetTask, message?: string, exception?: any) => void;
+
         constructor(public name: string, public meshesNames: any, public rootUrl: string, public sceneFilename: string) {
             super(name);
         }
@@ -121,9 +108,12 @@ module BABYLON {
         }
     }
 
-    export class TextFileAssetTask extends AbstractAssetTask implements IAssetTask<TextFileAssetTask> {
+    export class TextFileAssetTask extends AbstractAssetTask {
         public text: string;
 
+        public onSuccess: (task: TextFileAssetTask) => void;
+        public onError: (task: TextFileAssetTask, message?: string, exception?: any) => void;        
+
         constructor(public name: string, public url: string) {
             super(name);
         }
@@ -140,9 +130,12 @@ module BABYLON {
         }
     }
 
-    export class BinaryFileAssetTask extends AbstractAssetTask implements IAssetTask<BinaryFileAssetTask> {
+    export class BinaryFileAssetTask extends AbstractAssetTask {
         public data: ArrayBuffer;
 
+        public onSuccess: (task: BinaryFileAssetTask) => void;
+        public onError: (task: BinaryFileAssetTask, message?: string, exception?: any) => void;               
+
         constructor(public name: string, public url: string) {
             super(name);
         }
@@ -160,9 +153,12 @@ module BABYLON {
         }
     }
 
-    export class ImageAssetTask extends AbstractAssetTask implements IAssetTask<ImageAssetTask> {
+    export class ImageAssetTask extends AbstractAssetTask {
         public image: HTMLImageElement;
 
+        public onSuccess: (task: ImageAssetTask) => void;
+        public onError: (task: ImageAssetTask, message?: string, exception?: any) => void;            
+
         constructor(public name: string, public url: string) {
             super(name);
         }
@@ -185,12 +181,15 @@ module BABYLON {
         }
     }
 
-    export interface ITextureAssetTask<TEX extends BaseTexture, T extends AbstractAssetTask> extends IAssetTask<T> {
+    export interface ITextureAssetTask<TEX extends BaseTexture> {
         texture: TEX;
     }
 
-    export class TextureAssetTask extends AbstractAssetTask implements ITextureAssetTask<Texture, TextureAssetTask> {
+    export class TextureAssetTask extends AbstractAssetTask implements ITextureAssetTask<Texture> {
         public texture: Texture;
+        
+        public onSuccess: (task: TextureAssetTask) => void;
+        public onError: (task: TextureAssetTask, message?: string, exception?: any) => void;    
 
         constructor(public name: string, public url: string, public noMipmap?: boolean, public invertY?: boolean, public samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) {
             super(name);
@@ -202,17 +201,20 @@ module BABYLON {
                 onSuccess();
             };
 
-            var onerror = (msg: string, exception: any) => {
-                onError(msg, exception);
+            var onerror = (message?: string, exception?: any) => {
+                onError(message, exception);
             };
 
             this.texture = new Texture(this.url, scene, this.noMipmap, this.invertY, this.samplingMode, onload, onerror);
         }
     }
 
-    export class CubeTextureAssetTask extends AbstractAssetTask implements ITextureAssetTask<CubeTexture, CubeTextureAssetTask> {
+    export class CubeTextureAssetTask extends AbstractAssetTask implements ITextureAssetTask<CubeTexture> {
         public texture: CubeTexture;
 
+        public onSuccess: (task: CubeTextureAssetTask) => void;
+        public onError: (task: CubeTextureAssetTask, message?: string, exception?: any) => void;            
+
         constructor(public name: string, public url: string, public extensions?: string[], public noMipmap?: boolean, public files?: string[]) {
             super(name);
         }
@@ -223,17 +225,20 @@ module BABYLON {
                 onSuccess();
             };
 
-            var onerror = (msg: string, exception: any) => {
-                onError(msg, exception);
+            var onerror = (message?: string, exception?: any) => {
+                onError(message, exception);
             };
 
             this.texture = new CubeTexture(this.url, scene, this.extensions, this.noMipmap, this.files, onload, onerror);
         }
     }
 
-    export class HDRCubeTextureAssetTask extends AbstractAssetTask implements ITextureAssetTask<HDRCubeTexture, HDRCubeTextureAssetTask> {
+    export class HDRCubeTextureAssetTask extends AbstractAssetTask implements ITextureAssetTask<HDRCubeTexture> {
         public texture: HDRCubeTexture;
 
+        public onSuccess: (task: HDRCubeTextureAssetTask) => void;
+        public onError: (task: HDRCubeTextureAssetTask, message?: string, exception?: any) => void;               
+
         constructor(public name: string, public url: string, public size?: number, public noMipmap = false, public generateHarmonics = true, public useInGammaSpace = false, public usePMREMGenerator = false) {
             super(name);
         }
@@ -258,16 +263,16 @@ module BABYLON {
         protected tasks = new Array<AbstractAssetTask>();
         protected waitingTasksCount = 0;
 
-        public onFinish: (tasks: IAssetTask<AbstractAssetTask>[]) => void;
-        public onTaskSuccess: (task: IAssetTask<AbstractAssetTask>) => void;
-        public onTaskError: (task: IAssetTask<AbstractAssetTask>) => void;
-        public onProgress: (remainingCount: number, totalCount: number, task: IAssetTask<AbstractAssetTask>) => void;
+        public onFinish: (tasks: AbstractAssetTask[]) => void;
+        public onTaskSuccess: (task: AbstractAssetTask) => void;
+        public onTaskError: (task: AbstractAssetTask) => void;
+        public onProgress: (remainingCount: number, totalCount: number, task: AbstractAssetTask) => void;
 
         //Observables
 
-        public onTaskSuccessObservable = new Observable<IAssetTask<AbstractAssetTask>>();
-        public onTaskErrorObservable = new Observable<IAssetTask<AbstractAssetTask>>();
-        public onTasksDoneObservable = new Observable<IAssetTask<AbstractAssetTask>[]>();
+        public onTaskSuccessObservable = new Observable<AbstractAssetTask>();
+        public onTaskErrorObservable = new Observable<AbstractAssetTask>();
+        public onTasksDoneObservable = new Observable<AbstractAssetTask[]>();
         public onProgressObservable = new Observable<IAssetsProgressEvent>();
 
         public useDefaultLoadingScreen = true;

+ 2 - 2
src/Tools/babylon.observable.ts

@@ -45,7 +45,7 @@
      * Represent an Observer registered to a given Observable object.
      */
     export class Observer<T> {
-        constructor(public callback: (eventData: Nullable<T>, eventState: EventState) => void, public mask: number, public scope: any = null) {
+        constructor(public callback: (eventData: T, eventState: EventState) => void, public mask: number, public scope: any = null) {
         }
     }
 
@@ -176,7 +176,7 @@
          * @param eventData
          * @param mask
          */
-        public notifyObservers(eventData: Nullable<T>, mask: number = -1, target?: any, currentTarget?: any): boolean {
+        public notifyObservers(eventData: T, mask: number = -1, target?: any, currentTarget?: any): boolean {
             if (!this._observers.length) {
                 return true;
             }

+ 6 - 6
src/Tools/babylon.tools.ts

@@ -688,14 +688,14 @@
             return true;
         }
 
-        public static RegisterTopRootEvents(events: { name: string; handler: EventListener }[]): void {
+        public static RegisterTopRootEvents(events: { name: string; handler: Nullable<(e: FocusEvent) => any> }[]): void {
             for (var index = 0; index < events.length; index++) {
                 var event = events[index];
-                window.addEventListener(event.name, event.handler, false);
+                window.addEventListener(event.name, <any>event.handler, false);
 
                 try {
                     if (window.parent) {
-                        window.parent.addEventListener(event.name, event.handler, false);
+                        window.parent.addEventListener(event.name, <any>event.handler, false);
                     }
                 } catch (e) {
                     // Silently fails...
@@ -703,14 +703,14 @@
             }
         }
 
-        public static UnregisterTopRootEvents(events: { name: string; handler: EventListener }[]): void {
+        public static UnregisterTopRootEvents(events: { name: string; handler: Nullable<(e: FocusEvent) => any> }[]): void {
             for (var index = 0; index < events.length; index++) {
                 var event = events[index];
-                window.removeEventListener(event.name, event.handler);
+                window.removeEventListener(event.name, <any>event.handler);
 
                 try {
                     if (window.parent) {
-                        window.parent.removeEventListener(event.name, event.handler);
+                        window.parent.removeEventListener(event.name, <any>event.handler);
                     }
                 } catch (e) {
                     // Silently fails...

+ 12 - 12
src/babylon.scene.ts

@@ -558,8 +558,8 @@
          * Observable event triggered each time an keyboard event is received from the hosting window
          */
         public onKeyboardObservable = new Observable<KeyboardInfo>();
-        private _onKeyDown: (evt: Event) => void;
-        private _onKeyUp: (evt: Event) => void;
+        private _onKeyDown: (evt: KeyboardEvent) => void;
+        private _onKeyUp: (evt: KeyboardEvent) => void;
         private _onCanvasFocusObserver: Nullable<Observer<Engine>>;
         private _onCanvasBlurObserver: Nullable<Observer<Engine>>;
 
@@ -1786,18 +1786,18 @@
             }
 
             if (attachMove) {
-                canvas.addEventListener(eventPrefix + "move", this._onPointerMove, false);
+                canvas.addEventListener(eventPrefix + "move", <any>this._onPointerMove, false);
                 // Wheel
-                canvas.addEventListener('mousewheel', this._onPointerMove, false);
-                canvas.addEventListener('DOMMouseScroll', this._onPointerMove, false);
+                canvas.addEventListener('mousewheel', <any>this._onPointerMove, false);
+                canvas.addEventListener('DOMMouseScroll', <any>this._onPointerMove, false);
             }
 
             if (attachDown) {
-                canvas.addEventListener(eventPrefix + "down", this._onPointerDown, false);
+                canvas.addEventListener(eventPrefix + "down", <any>this._onPointerDown, false);
             }
 
             if (attachUp) {
-                window.addEventListener(eventPrefix + "up", this._onPointerUp, false);
+                window.addEventListener(eventPrefix + "up", <any>this._onPointerUp, false);
             }
 
             canvas.tabIndex = 1;
@@ -1812,9 +1812,9 @@
                 return;
             }
 
-            canvas.removeEventListener(eventPrefix + "move", this._onPointerMove);
-            canvas.removeEventListener(eventPrefix + "down", this._onPointerDown);
-            window.removeEventListener(eventPrefix + "up", this._onPointerUp);
+            canvas.removeEventListener(eventPrefix + "move", <any>this._onPointerMove);
+            canvas.removeEventListener(eventPrefix + "down", <any>this._onPointerDown);
+            window.removeEventListener(eventPrefix + "up", <any>this._onPointerUp);
 
             if (this._onCanvasBlurObserver) {
                 engine.onCanvasBlurObservable.remove(this._onCanvasBlurObserver);
@@ -1825,8 +1825,8 @@
             }
 
             // Wheel
-            canvas.removeEventListener('mousewheel', this._onPointerMove);
-            canvas.removeEventListener('DOMMouseScroll', this._onPointerMove);
+            canvas.removeEventListener('mousewheel', <any>this._onPointerMove);
+            canvas.removeEventListener('DOMMouseScroll', <any>this._onPointerMove);
 
             // Keyboard
             canvas.removeEventListener("keydown", this._onKeyDown);

+ 2 - 1
src/tsconfig.json

@@ -10,6 +10,7 @@
     "noImplicitReturns": true,
     "noImplicitThis": true,
     "noUnusedLocals": true,    
-    "strictNullChecks": true
+    "strictNullChecks": true,
+    "strictFunctionTypes": true
   }
 }