Просмотр исходного кода

Fixing quaternion.fromRotationMatrix

David catuhe 9 лет назад
Родитель
Сommit
a2a6260f54

Разница между файлами не показана из-за своего большого размера
+ 18 - 19
dist/preview release/babylon.core.js


Разница между файлами не показана из-за своего большого размера
+ 572 - 571
dist/preview release/babylon.d.ts


Разница между файлами не показана из-за своего большого размера
+ 21 - 21
dist/preview release/babylon.js


Разница между файлами не показана из-за своего большого размера
+ 115 - 70
dist/preview release/babylon.max.js


Разница между файлами не показана из-за своего большого размера
+ 18 - 18
dist/preview release/babylon.noworker.js


+ 1 - 13
src/Animations/babylon.animation.js

@@ -150,19 +150,7 @@ var BABYLON;
             return BABYLON.Color3.Lerp(startValue, endValue, gradient);
         };
         Animation.prototype.matrixInterpolateFunction = function (startValue, endValue, gradient) {
-            var startScale = new BABYLON.Vector3(0, 0, 0);
-            var startRotation = new BABYLON.Quaternion();
-            var startTranslation = new BABYLON.Vector3(0, 0, 0);
-            startValue.decompose(startScale, startRotation, startTranslation);
-            var endScale = new BABYLON.Vector3(0, 0, 0);
-            var endRotation = new BABYLON.Quaternion();
-            var endTranslation = new BABYLON.Vector3(0, 0, 0);
-            endValue.decompose(endScale, endRotation, endTranslation);
-            var resultScale = this.vector3InterpolateFunction(startScale, endScale, gradient);
-            var resultRotation = this.quaternionInterpolateFunction(startRotation, endRotation, gradient);
-            var resultTranslation = this.vector3InterpolateFunction(startTranslation, endTranslation, gradient);
-            var result = BABYLON.Matrix.Compose(resultScale, resultRotation, resultTranslation);
-            return result;
+            return BABYLON.Matrix.Lerp(startValue, endValue, gradient);
         };
         Animation.prototype.clone = function () {
             var clone = new Animation(this.name, this.targetPropertyPath.join("."), this.framePerSecond, this.dataType, this.loopMode);

+ 1 - 17
src/Animations/babylon.animation.ts

@@ -178,23 +178,7 @@
         }
 
         public matrixInterpolateFunction(startValue: Matrix, endValue: Matrix, gradient: number): Matrix {
-            var startScale = new Vector3(0, 0, 0);
-            var startRotation = new Quaternion();
-            var startTranslation = new Vector3(0, 0, 0);
-            startValue.decompose(startScale, startRotation, startTranslation);
-
-            var endScale = new Vector3(0, 0, 0);
-            var endRotation = new Quaternion();
-            var endTranslation = new Vector3(0, 0, 0);
-            endValue.decompose(endScale, endRotation, endTranslation);
-
-            var resultScale = this.vector3InterpolateFunction(startScale, endScale, gradient);
-            var resultRotation = this.quaternionInterpolateFunction(startRotation, endRotation, gradient);
-            var resultTranslation = this.vector3InterpolateFunction(startTranslation, endTranslation, gradient);
-
-            var result = Matrix.Compose(resultScale, resultRotation, resultTranslation);
-
-            return result;
+            return Matrix.Lerp(startValue, endValue, gradient);
         }
 
         public clone(): Animation {

+ 108 - 52
src/Math/babylon.math.js

@@ -1361,40 +1361,46 @@ var BABYLON;
             return result;
         };
         Quaternion.FromRotationMatrixToRef = function (matrix, result) {
-            var data = matrix.m;
-            var m11 = data[0], m12 = data[4], m13 = data[8];
-            var m21 = data[1], m22 = data[5], m23 = data[9];
-            var m31 = data[2], m32 = data[6], m33 = data[10];
-            var trace = m11 + m22 + m33;
-            var s;
-            if (trace > 0) {
-                s = 0.5 / Math.sqrt(trace + 1.0);
-                result.w = 0.25 / s;
-                result.x = (m32 - m23) * s;
-                result.y = (m13 - m31) * s;
-                result.z = (m21 - m12) * s;
-            }
-            else if (m11 > m22 && m11 > m33) {
-                s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
-                result.w = (m32 - m23) / s;
-                result.x = 0.25 * s;
-                result.y = (m12 + m21) / s;
-                result.z = (m13 + m31) / s;
-            }
-            else if (m22 > m33) {
-                s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
-                result.w = (m13 - m31) / s;
-                result.x = (m12 + m21) / s;
-                result.y = 0.25 * s;
-                result.z = (m23 + m32) / s;
-            }
-            else {
-                s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
-                result.w = (m21 - m12) / s;
-                result.x = (m13 + m31) / s;
-                result.y = (m23 + m32) / s;
-                result.z = 0.25 * s;
-            }
+            var absQ = Math.pow(matrix.determinant(), 1.0 / 3.0);
+            result.w = Math.sqrt(Math.max(0, absQ + matrix.m[0] + matrix.m[5] + matrix.m[10])) / 2;
+            result.x = Math.sqrt(Math.max(0, absQ + matrix.m[0] - matrix.m[5] - matrix.m[10])) / 2;
+            result.y = Math.sqrt(Math.max(0, absQ - matrix.m[0] + matrix.m[5] - matrix.m[10])) / 2;
+            result.z = Math.sqrt(Math.max(0, absQ - matrix.m[0] - matrix.m[5] + matrix.m[10])) / 2;
+            result.x = (matrix.m[6] - matrix.m[9]) < 0 ? -Math.abs(result.x) : Math.abs(result.x);
+            result.y = (matrix.m[8] - matrix.m[2]) < 0 ? -Math.abs(result.y) : Math.abs(result.y);
+            result.z = (matrix.m[1] - matrix.m[4]) < 0 ? -Math.abs(result.z) : Math.abs(result.z);
+            result.normalize();
+            //var data = matrix.m;
+            //var m11 = data[0], m12 = data[4], m13 = data[8];
+            //var m21 = data[1], m22 = data[5], m23 = data[9];
+            //var m31 = data[2], m32 = data[6], m33 = data[10];
+            //var trace = m11 + m22 + m33;
+            //var s;
+            //if (trace > 0) {
+            //    s = 0.5 / Math.sqrt(trace + 1.0);
+            //    result.w = 0.25 / s;
+            //    result.x = (m32 - m23) * s;
+            //    result.y = (m13 - m31) * s;
+            //    result.z = (m21 - m12) * s;
+            //} else if (m11 > m22 && m11 > m33) {
+            //    s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
+            //    result.w = (m32 - m23) / s;
+            //    result.x = 0.25 * s;
+            //    result.y = (m12 + m21) / s;
+            //    result.z = (m13 + m31) / s;
+            //} else if (m22 > m33) {
+            //    s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
+            //    result.w = (m13 - m31) / s;
+            //    result.x = (m12 + m21) / s;
+            //    result.y = 0.25 * s;
+            //    result.z = (m23 + m32) / s;
+            //} else {
+            //    s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
+            //    result.w = (m21 - m12) / s;
+            //    result.x = (m13 + m31) / s;
+            //    result.y = (m23 + m32) / s;
+            //    result.z = 0.25 * s;
+            //}
         };
         Quaternion.Inverse = function (q) {
             return new Quaternion(-q.x, -q.y, -q.z, q.w);
@@ -1454,27 +1460,63 @@ var BABYLON;
             result.z = Math.sin(halfGammaPlusAlpha) * Math.cos(halfBeta);
             result.w = Math.cos(halfGammaPlusAlpha) * Math.cos(halfBeta);
         };
+        // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
         Quaternion.Slerp = function (left, right, amount) {
-            var num2;
-            var num3;
-            var num = amount;
-            var num4 = (((left.x * right.x) + (left.y * right.y)) + (left.z * right.z)) + (left.w * right.w);
-            var flag = false;
-            if (num4 < 0) {
-                flag = true;
-                num4 = -num4;
-            }
-            if (num4 > 0.999999) {
-                num3 = 1 - num;
-                num2 = flag ? -num : num;
+            var cosHalfTheta = left.w * right.w + left.x * right.x + left.y * right.y + left.z * right.z;
+            var result = new Quaternion();
+            if (cosHalfTheta < 0) {
+                result.w = -right.w;
+                result.x = -right.x;
+                result.y = -right.y;
+                result.z = -right.z;
+                cosHalfTheta = -cosHalfTheta;
             }
             else {
-                var num5 = Math.acos(num4);
-                var num6 = (1.0 / Math.sin(num5));
-                num3 = (Math.sin((1.0 - num) * num5)) * num6;
-                num2 = flag ? ((-Math.sin(num * num5)) * num6) : ((Math.sin(num * num5)) * num6);
-            }
-            return new Quaternion((num3 * left.x) + (num2 * right.x), (num3 * left.y) + (num2 * right.y), (num3 * left.z) + (num2 * right.z), (num3 * left.w) + (num2 * right.w));
+                result.copyFrom(right);
+            }
+            if (Math.abs(cosHalfTheta) >= 1.0) {
+                result.w = left.w;
+                result.x = left.x;
+                result.y = left.y;
+                result.z = left.z;
+                return result;
+            }
+            var halfTheta = Math.acos(cosHalfTheta);
+            var sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta);
+            if (Math.abs(sinHalfTheta) < 0.001) {
+                result.w = 0.5 * (left.w + result.w);
+                result.x = 0.5 * (left.x + result.x);
+                result.y = 0.5 * (left.y + result.y);
+                result.z = 0.5 * (left.z + result.z);
+                return result;
+            }
+            var ratioA = Math.sin((1 - amount) * halfTheta) / sinHalfTheta;
+            var ratioB = Math.sin(amount * halfTheta) / sinHalfTheta;
+            result.w = (left.w * ratioA + result.w * ratioB);
+            result.x = (left.x * ratioA + result.x * ratioB);
+            result.y = (left.y * ratioA + result.y * ratioB);
+            result.z = (left.z * ratioA + result.z * ratioB);
+            return result;
+            //var num2;
+            //var num3;
+            //var num = amount;
+            //var num4 = (((left.x * right.x) + (left.y * right.y)) + (left.z * right.z)) + (left.w * right.w);
+            //var flag = false;
+            //if (num4 < 0) {
+            //    flag = true;
+            //    num4 = -num4;
+            //}
+            //if (num4 > 0.999999) {
+            //    num3 = 1 - num;
+            //    num2 = flag ? -num : num;
+            //}
+            //else {
+            //    var num5 = Math.acos(num4);
+            //    var num6 = (1.0 / Math.sin(num5));
+            //    num3 = (Math.sin((1.0 - num) * num5)) * num6;
+            //    num2 = flag ? ((-Math.sin(num * num5)) * num6) : ((Math.sin(num * num5)) * num6);
+            //}
+            //return new Quaternion((num3 * left.x) + (num2 * right.x), (num3 * left.y) + (num2 * right.y), (num3 * left.z) + (num2 * right.z), (num3 * left.w) + (num2 * right.w));
         };
         return Quaternion;
     })();
@@ -2093,6 +2135,20 @@ var BABYLON;
             result.m[14] = temp3 * plane.d;
             result.m[15] = 1.0;
         };
+        Matrix.Lerp = function (startValue, endValue, gradient) {
+            var startScale = new Vector3(0, 0, 0);
+            var startRotation = new Quaternion();
+            var startTranslation = new Vector3(0, 0, 0);
+            startValue.decompose(startScale, startRotation, startTranslation);
+            var endScale = new Vector3(0, 0, 0);
+            var endRotation = new Quaternion();
+            var endTranslation = new Vector3(0, 0, 0);
+            endValue.decompose(endScale, endRotation, endTranslation);
+            var resultScale = Vector3.Lerp(startScale, endScale, gradient);
+            var resultRotation = Quaternion.Slerp(startRotation, endRotation, gradient);
+            var resultTranslation = Vector3.Lerp(startTranslation, endTranslation, gradient);
+            return Matrix.Compose(resultScale, resultRotation, resultTranslation);
+        };
         Matrix._tempQuaternion = new Quaternion();
         Matrix._xAxis = Vector3.Zero();
         Matrix._yAxis = Vector3.Zero();

+ 124 - 48
src/Math/babylon.math.ts

@@ -1681,46 +1681,57 @@
         }
 
         public static FromRotationMatrixToRef(matrix: Matrix, result: Quaternion): void {
-            var data = matrix.m;
-            var m11 = data[0], m12 = data[4], m13 = data[8];
-            var m21 = data[1], m22 = data[5], m23 = data[9];
-            var m31 = data[2], m32 = data[6], m33 = data[10];
-            var trace = m11 + m22 + m33;
-            var s;
 
-            if (trace > 0) {
+            var absQ = Math.pow(matrix.determinant(), 1.0 / 3.0);
+            result.w = Math.sqrt(Math.max(0, absQ + matrix.m[0] + matrix.m[5] +matrix.m[10])) / 2;
+            result.x = Math.sqrt(Math.max(0, absQ + matrix.m[0] - matrix.m[5] -matrix.m[10])) / 2;
+            result.y = Math.sqrt(Math.max(0, absQ - matrix.m[0] + matrix.m[5] -matrix.m[10])) / 2;
+            result.z = Math.sqrt(Math.max(0, absQ - matrix.m[0] - matrix.m[5] + matrix.m[10])) / 2;
+            result.x = (matrix.m[6] - matrix.m[9]) < 0 ? -Math.abs(result.x) : Math.abs(result.x);
+            result.y = (matrix.m[8] - matrix.m[2]) < 0 ? -Math.abs(result.y) : Math.abs(result.y);
+            result.z = (matrix.m[1] - matrix.m[4]) < 0 ? -Math.abs(result.z) : Math.abs(result.z);
+            result.normalize(); 
 
-                s = 0.5 / Math.sqrt(trace + 1.0);
+            //var data = matrix.m;
+            //var m11 = data[0], m12 = data[4], m13 = data[8];
+            //var m21 = data[1], m22 = data[5], m23 = data[9];
+            //var m31 = data[2], m32 = data[6], m33 = data[10];
+            //var trace = m11 + m22 + m33;
+            //var s;
 
-                result.w = 0.25 / s;
-                result.x = (m32 - m23) * s;
-                result.y = (m13 - m31) * s;
-                result.z = (m21 - m12) * s;
-            } else if (m11 > m22 && m11 > m33) {
+            //if (trace > 0) {
 
-                s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
+            //    s = 0.5 / Math.sqrt(trace + 1.0);
 
-                result.w = (m32 - m23) / s;
-                result.x = 0.25 * s;
-                result.y = (m12 + m21) / s;
-                result.z = (m13 + m31) / s;
-            } else if (m22 > m33) {
+            //    result.w = 0.25 / s;
+            //    result.x = (m32 - m23) * s;
+            //    result.y = (m13 - m31) * s;
+            //    result.z = (m21 - m12) * s;
+            //} else if (m11 > m22 && m11 > m33) {
 
-                s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
+            //    s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
 
-                result.w = (m13 - m31) / s;
-                result.x = (m12 + m21) / s;
-                result.y = 0.25 * s;
-                result.z = (m23 + m32) / s;
-            } else {
+            //    result.w = (m32 - m23) / s;
+            //    result.x = 0.25 * s;
+            //    result.y = (m12 + m21) / s;
+            //    result.z = (m13 + m31) / s;
+            //} else if (m22 > m33) {
 
-                s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
+            //    s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
 
-                result.w = (m21 - m12) / s;
-                result.x = (m13 + m31) / s;
-                result.y = (m23 + m32) / s;
-                result.z = 0.25 * s;
-            }
+            //    result.w = (m13 - m31) / s;
+            //    result.x = (m12 + m21) / s;
+            //    result.y = 0.25 * s;
+            //    result.z = (m23 + m32) / s;
+            //} else {
+
+            //    s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
+
+            //    result.w = (m21 - m12) / s;
+            //    result.x = (m13 + m31) / s;
+            //    result.y = (m23 + m32) / s;
+            //    result.z = 0.25 * s;
+            //}
         }
 
         public static Inverse(q: Quaternion): Quaternion {
@@ -1798,30 +1809,77 @@
             result.w = Math.cos(halfGammaPlusAlpha) * Math.cos(halfBeta);
         }
 
+        // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
         public static Slerp(left: Quaternion, right: Quaternion, amount: number): Quaternion {
-            var num2;
-            var num3;
-            var num = amount;
-            var num4 = (((left.x * right.x) + (left.y * right.y)) + (left.z * right.z)) + (left.w * right.w);
-            var flag = false;
+            var cosHalfTheta = left.w * right.w + left.x * right.x + left.y * right.y + left.z * right.z;
+            var result = new Quaternion();
+
+            if (cosHalfTheta < 0) {
+                result.w = -right.w;
+                result.x = -right.x;
+                result.y = -right.y;
+                result.z = -right.z;
 
-            if (num4 < 0) {
-                flag = true;
-                num4 = -num4;
+                cosHalfTheta = -cosHalfTheta;
+            } else {
+                result.copyFrom(right);
             }
 
-            if (num4 > 0.999999) {
-                num3 = 1 - num;
-                num2 = flag ? -num : num;
+           	if (Math.abs(cosHalfTheta) >= 1.0) {
+                result.w = left.w;
+                result.x = left.x;
+                result.y = left.y;
+                result.z = left.z;
+
+                return result;
             }
-            else {
-                var num5 = Math.acos(num4);
-                var num6 = (1.0 / Math.sin(num5));
-                num3 = (Math.sin((1.0 - num) * num5)) * num6;
-                num2 = flag ? ((-Math.sin(num * num5)) * num6) : ((Math.sin(num * num5)) * num6);
+
+            var halfTheta = Math.acos(cosHalfTheta);
+            var sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta);
+
+            if (Math.abs(sinHalfTheta) < 0.001) {
+                result.w = 0.5 * (left.w + result.w);
+                result.x = 0.5 * (left.x + result.x);
+                result.y = 0.5 * (left.y + result.y);
+                result.z = 0.5 * (left.z + result.z);
+
+                return result;
             }
 
-            return new Quaternion((num3 * left.x) + (num2 * right.x), (num3 * left.y) + (num2 * right.y), (num3 * left.z) + (num2 * right.z), (num3 * left.w) + (num2 * right.w));
+            var ratioA = Math.sin((1 - amount) * halfTheta) / sinHalfTheta;
+            var ratioB = Math.sin(amount * halfTheta) / sinHalfTheta;
+
+            result.w = (left.w * ratioA + result.w * ratioB);
+            result.x = (left.x * ratioA + result.x * ratioB);
+            result.y = (left.y * ratioA + result.y * ratioB);
+            result.z = (left.z * ratioA + result.z * ratioB);
+
+
+            return result;
+
+            //var num2;
+            //var num3;
+            //var num = amount;
+            //var num4 = (((left.x * right.x) + (left.y * right.y)) + (left.z * right.z)) + (left.w * right.w);
+            //var flag = false;
+
+            //if (num4 < 0) {
+            //    flag = true;
+            //    num4 = -num4;
+            //}
+
+            //if (num4 > 0.999999) {
+            //    num3 = 1 - num;
+            //    num2 = flag ? -num : num;
+            //}
+            //else {
+            //    var num5 = Math.acos(num4);
+            //    var num6 = (1.0 / Math.sin(num5));
+            //    num3 = (Math.sin((1.0 - num) * num5)) * num6;
+            //    num2 = flag ? ((-Math.sin(num * num5)) * num6) : ((Math.sin(num * num5)) * num6);
+            //}
+
+            //return new Quaternion((num3 * left.x) + (num2 * right.x), (num3 * left.y) + (num2 * right.y), (num3 * left.z) + (num2 * right.z), (num3 * left.w) + (num2 * right.w));
         }
     }
 
@@ -2632,6 +2690,24 @@
             result.m[14] = temp3 * plane.d;
             result.m[15] = 1.0;
         }
+
+        public static Lerp(startValue: Matrix, endValue: Matrix, gradient: number): Matrix {
+            var startScale = new Vector3(0, 0, 0);
+            var startRotation = new Quaternion();
+            var startTranslation = new Vector3(0, 0, 0);
+            startValue.decompose(startScale, startRotation, startTranslation);
+
+            var endScale = new Vector3(0, 0, 0);
+            var endRotation = new Quaternion();
+            var endTranslation = new Vector3(0, 0, 0);
+            endValue.decompose(endScale, endRotation, endTranslation);
+
+            var resultScale = Vector3.Lerp(startScale, endScale, gradient);
+            var resultRotation = Quaternion.Slerp(startRotation, endRotation, gradient);
+            var resultTranslation = Vector3.Lerp(startTranslation, endTranslation, gradient);
+
+            return Matrix.Compose(resultScale, resultRotation, resultTranslation);
+        }
     }
 
     export class Plane {

+ 5 - 5
src/Particles/babylon.particleSystem.ts

@@ -55,8 +55,8 @@
         public color2 = new Color4(1.0, 1.0, 1.0, 1.0);
         public colorDead = new Color4(0, 0, 0, 1.0);
         public textureMask = new Color4(1.0, 1.0, 1.0, 1.0);
-        public startDirectionFunction: (emitPower: number, worldMatrix: Matrix, directionToUpdate: Vector3, particle:Particle) => void;
-        public startPositionFunction: (worldMatrix: Matrix, positionToUpdate: Vector3, particle:Particle) => void;
+        public startDirectionFunction: (emitPower: number, worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle) => void;
+        public startPositionFunction: (worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle) => void;
 
         private particles = new Array<Particle>();
 
@@ -115,7 +115,7 @@
             this._vertices = new Float32Array(capacity * this._vertexStrideSize);
 
             // Default behaviors
-            this.startDirectionFunction = (emitPower: number, worldMatrix: Matrix, directionToUpdate: Vector3, particle:Particle): void => {
+            this.startDirectionFunction = (emitPower: number, worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle): void => {
                 var randX = randomNumber(this.direction1.x, this.direction2.x);
                 var randY = randomNumber(this.direction1.y, this.direction2.y);
                 var randZ = randomNumber(this.direction1.z, this.direction2.z);
@@ -123,7 +123,7 @@
                 Vector3.TransformNormalFromFloatsToRef(randX * emitPower, randY * emitPower, randZ * emitPower, worldMatrix, directionToUpdate);
             }
 
-            this.startPositionFunction = (worldMatrix: Matrix, positionToUpdate: Vector3, particle:Particle): void => {
+            this.startPositionFunction = (worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle): void => {
                 var randX = randomNumber(this.minEmitBox.x, this.maxEmitBox.x);
                 var randY = randomNumber(this.minEmitBox.y, this.maxEmitBox.y);
                 var randZ = randomNumber(this.minEmitBox.z, this.maxEmitBox.z);
@@ -446,4 +446,4 @@
             return result;
         }
     }
-}  
+}  

+ 2 - 1
src/babylon.engine.js

@@ -315,6 +315,7 @@ var BABYLON;
         scene._removePendingData(texture);
     };
     var partialLoad = function (url, index, loadedImages, scene, onfinish) {
+        var img;
         var onload = function () {
             loadedImages[index] = img;
             loadedImages._internalCount++;
@@ -326,7 +327,7 @@ var BABYLON;
         var onerror = function () {
             scene._removePendingData(img);
         };
-        var img = BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
+        img = BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
         scene._addPendingData(img);
     };
     var cascadeLoad = function (rootUrl, scene, onfinish, extensions) {

+ 11 - 9
src/babylon.engine.ts

@@ -336,6 +336,8 @@
     var partialLoad = (url: string, index: number, loadedImages: any, scene,
         onfinish: (images: HTMLImageElement[]) => void) => {
 
+        var img: HTMLImageElement;
+
         var onload = () => {
             loadedImages[index] = img;
             loadedImages._internalCount++;
@@ -351,7 +353,7 @@
             scene._removePendingData(img);
         };
 
-        var img = Tools.LoadImage(url, onload, onerror, scene.database);
+        img = Tools.LoadImage(url, onload, onerror, scene.database);
         scene._addPendingData(img);
     }
 
@@ -1028,9 +1030,9 @@
             this._gl.bindBuffer(this._gl.ARRAY_BUFFER, vbo);
 
             if (vertices instanceof Float32Array) {
-                this._gl.bufferData(this._gl.ARRAY_BUFFER, vertices, this._gl.STATIC_DRAW);
+                this._gl.bufferData(this._gl.ARRAY_BUFFER, <Float32Array>vertices, this._gl.STATIC_DRAW);
             } else {
-                this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(vertices), this._gl.STATIC_DRAW);
+                this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(<number[]>vertices), this._gl.STATIC_DRAW);
             }
 
             this._resetVertexBufferBinding();
@@ -1055,9 +1057,9 @@
             }
 
             if (vertices instanceof Float32Array) {
-                this._gl.bufferSubData(this._gl.ARRAY_BUFFER, offset, vertices);
+                this._gl.bufferSubData(this._gl.ARRAY_BUFFER, offset, <Float32Array>vertices);
             } else {
-                this._gl.bufferSubData(this._gl.ARRAY_BUFFER, offset, new Float32Array(vertices));
+                this._gl.bufferSubData(this._gl.ARRAY_BUFFER, offset, new Float32Array(<number[]>vertices));
             }
 
             this._resetVertexBufferBinding();
@@ -1365,28 +1367,28 @@
             if (!uniform)
                 return;
 
-            this._gl.uniform1fv(uniform, array);
+            this._gl.uniform1fv(uniform, <any>array);
         }
 
         public setArray2(uniform: WebGLUniformLocation, array: number[]): void {
             if (!uniform || array.length % 2 !== 0)
                 return;
 
-            this._gl.uniform2fv(uniform, array);
+            this._gl.uniform2fv(uniform, <any>array);
         }
 
         public setArray3(uniform: WebGLUniformLocation, array: number[]): void {
             if (!uniform || array.length % 3 !== 0)
                 return;
 
-            this._gl.uniform3fv(uniform, array);
+            this._gl.uniform3fv(uniform, <any>array);
         }
 
         public setArray4(uniform: WebGLUniformLocation, array: number[]): void {
             if (!uniform || array.length % 4 !== 0)
                 return;
 
-            this._gl.uniform4fv(uniform, array);
+            this._gl.uniform4fv(uniform, <any>array);
         }
 
         public setMatrices(uniform: WebGLUniformLocation, matrices: Float32Array): void {