|
@@ -2,6 +2,18 @@ var BABYLON;
|
|
(function (BABYLON) {
|
|
(function (BABYLON) {
|
|
BABYLON.ToGammaSpace = 1 / 2.2;
|
|
BABYLON.ToGammaSpace = 1 / 2.2;
|
|
BABYLON.ToLinearSpace = 2.2;
|
|
BABYLON.ToLinearSpace = 2.2;
|
|
|
|
+ BABYLON.Epsilon = 0.001;
|
|
|
|
+ var MathTools = (function () {
|
|
|
|
+ function MathTools() {
|
|
|
|
+ }
|
|
|
|
+ MathTools.WithinEpsilon = function (a, b, epsilon) {
|
|
|
|
+ if (epsilon === void 0) { epsilon = 1.401298E-45; }
|
|
|
|
+ var num = a - b;
|
|
|
|
+ return -epsilon <= num && num <= epsilon;
|
|
|
|
+ };
|
|
|
|
+ return MathTools;
|
|
|
|
+ })();
|
|
|
|
+ BABYLON.MathTools = MathTools;
|
|
var Color3 = (function () {
|
|
var Color3 = (function () {
|
|
function Color3(r, g, b) {
|
|
function Color3(r, g, b) {
|
|
if (r === void 0) { r = 0; }
|
|
if (r === void 0) { r = 0; }
|
|
@@ -361,8 +373,8 @@ var BABYLON;
|
|
return otherVector && this.x === otherVector.x && this.y === otherVector.y;
|
|
return otherVector && this.x === otherVector.x && this.y === otherVector.y;
|
|
};
|
|
};
|
|
Vector2.prototype.equalsWithEpsilon = function (otherVector, epsilon) {
|
|
Vector2.prototype.equalsWithEpsilon = function (otherVector, epsilon) {
|
|
- if (epsilon === void 0) { epsilon = BABYLON.Engine.Epsilon; }
|
|
|
|
- return otherVector && BABYLON.Tools.WithinEpsilon(this.x, otherVector.x, epsilon) && BABYLON.Tools.WithinEpsilon(this.y, otherVector.y, epsilon);
|
|
|
|
|
|
+ if (epsilon === void 0) { epsilon = BABYLON.Epsilon; }
|
|
|
|
+ return otherVector && MathTools.WithinEpsilon(this.x, otherVector.x, epsilon) && MathTools.WithinEpsilon(this.y, otherVector.y, epsilon);
|
|
};
|
|
};
|
|
// Properties
|
|
// Properties
|
|
Vector2.prototype.length = function () {
|
|
Vector2.prototype.length = function () {
|
|
@@ -562,8 +574,8 @@ var BABYLON;
|
|
return otherVector && this.x === otherVector.x && this.y === otherVector.y && this.z === otherVector.z;
|
|
return otherVector && this.x === otherVector.x && this.y === otherVector.y && this.z === otherVector.z;
|
|
};
|
|
};
|
|
Vector3.prototype.equalsWithEpsilon = function (otherVector, epsilon) {
|
|
Vector3.prototype.equalsWithEpsilon = function (otherVector, epsilon) {
|
|
- if (epsilon === void 0) { epsilon = BABYLON.Engine.Epsilon; }
|
|
|
|
- return otherVector && BABYLON.Tools.WithinEpsilon(this.x, otherVector.x, epsilon) && BABYLON.Tools.WithinEpsilon(this.y, otherVector.y, epsilon) && BABYLON.Tools.WithinEpsilon(this.z, otherVector.z, epsilon);
|
|
|
|
|
|
+ if (epsilon === void 0) { epsilon = BABYLON.Epsilon; }
|
|
|
|
+ return otherVector && MathTools.WithinEpsilon(this.x, otherVector.x, epsilon) && MathTools.WithinEpsilon(this.y, otherVector.y, epsilon) && MathTools.WithinEpsilon(this.z, otherVector.z, epsilon);
|
|
};
|
|
};
|
|
Vector3.prototype.equalsToFloats = function (x, y, z) {
|
|
Vector3.prototype.equalsToFloats = function (x, y, z) {
|
|
return this.x === x && this.y === y && this.z === z;
|
|
return this.x === x && this.y === y && this.z === z;
|
|
@@ -806,7 +818,7 @@ var BABYLON;
|
|
source.y = -(source.y / viewportHeight * 2 - 1);
|
|
source.y = -(source.y / viewportHeight * 2 - 1);
|
|
var vector = Vector3.TransformCoordinates(source, matrix);
|
|
var vector = Vector3.TransformCoordinates(source, matrix);
|
|
var num = source.x * matrix.m[3] + source.y * matrix.m[7] + source.z * matrix.m[11] + matrix.m[15];
|
|
var num = source.x * matrix.m[3] + source.y * matrix.m[7] + source.z * matrix.m[11] + matrix.m[15];
|
|
- if (BABYLON.Tools.WithinEpsilon(num, 1.0)) {
|
|
|
|
|
|
+ if (MathTools.WithinEpsilon(num, 1.0)) {
|
|
vector = vector.scale(1.0 / num);
|
|
vector = vector.scale(1.0 / num);
|
|
}
|
|
}
|
|
return vector;
|
|
return vector;
|
|
@@ -817,7 +829,7 @@ var BABYLON;
|
|
var screenSource = new Vector3(source.x / viewportWidth * 2 - 1, -(source.y / viewportHeight * 2 - 1), source.z);
|
|
var screenSource = new Vector3(source.x / viewportWidth * 2 - 1, -(source.y / viewportHeight * 2 - 1), source.z);
|
|
var vector = Vector3.TransformCoordinates(screenSource, matrix);
|
|
var vector = Vector3.TransformCoordinates(screenSource, matrix);
|
|
var num = screenSource.x * matrix.m[3] + screenSource.y * matrix.m[7] + screenSource.z * matrix.m[11] + matrix.m[15];
|
|
var num = screenSource.x * matrix.m[3] + screenSource.y * matrix.m[7] + screenSource.z * matrix.m[11] + matrix.m[15];
|
|
- if (BABYLON.Tools.WithinEpsilon(num, 1.0)) {
|
|
|
|
|
|
+ if (MathTools.WithinEpsilon(num, 1.0)) {
|
|
vector = vector.scale(1.0 / num);
|
|
vector = vector.scale(1.0 / num);
|
|
}
|
|
}
|
|
return vector;
|
|
return vector;
|
|
@@ -881,10 +893,10 @@ var BABYLON;
|
|
// Rv3(u) = u1, and u1 belongs to plane xOz
|
|
// Rv3(u) = u1, and u1 belongs to plane xOz
|
|
// Rv3(w) = w1 = w invariant
|
|
// Rv3(w) = w1 = w invariant
|
|
var u1 = Tmp.Vector3[1];
|
|
var u1 = Tmp.Vector3[1];
|
|
- if (BABYLON.Tools.WithinEpsilon(w.z, 0, BABYLON.Engine.Epsilon)) {
|
|
|
|
|
|
+ if (MathTools.WithinEpsilon(w.z, 0, BABYLON.Epsilon)) {
|
|
z = 1.0;
|
|
z = 1.0;
|
|
}
|
|
}
|
|
- else if (BABYLON.Tools.WithinEpsilon(w.x, 0, BABYLON.Engine.Epsilon)) {
|
|
|
|
|
|
+ else if (MathTools.WithinEpsilon(w.x, 0, BABYLON.Epsilon)) {
|
|
x = 1.0;
|
|
x = 1.0;
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -918,7 +930,7 @@ var BABYLON;
|
|
y = 0.0;
|
|
y = 0.0;
|
|
z = 0.0;
|
|
z = 0.0;
|
|
sign = -1.0;
|
|
sign = -1.0;
|
|
- if (BABYLON.Tools.WithinEpsilon(w.z, 0, BABYLON.Engine.Epsilon)) {
|
|
|
|
|
|
+ if (MathTools.WithinEpsilon(w.z, 0, BABYLON.Epsilon)) {
|
|
x = 1.0;
|
|
x = 1.0;
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -1059,12 +1071,12 @@ var BABYLON;
|
|
return otherVector && this.x === otherVector.x && this.y === otherVector.y && this.z === otherVector.z && this.w === otherVector.w;
|
|
return otherVector && this.x === otherVector.x && this.y === otherVector.y && this.z === otherVector.z && this.w === otherVector.w;
|
|
};
|
|
};
|
|
Vector4.prototype.equalsWithEpsilon = function (otherVector, epsilon) {
|
|
Vector4.prototype.equalsWithEpsilon = function (otherVector, epsilon) {
|
|
- if (epsilon === void 0) { epsilon = BABYLON.Engine.Epsilon; }
|
|
|
|
|
|
+ if (epsilon === void 0) { epsilon = BABYLON.Epsilon; }
|
|
return otherVector
|
|
return otherVector
|
|
- && BABYLON.Tools.WithinEpsilon(this.x, otherVector.x, epsilon)
|
|
|
|
- && BABYLON.Tools.WithinEpsilon(this.y, otherVector.y, epsilon)
|
|
|
|
- && BABYLON.Tools.WithinEpsilon(this.z, otherVector.z, epsilon)
|
|
|
|
- && BABYLON.Tools.WithinEpsilon(this.w, otherVector.w, epsilon);
|
|
|
|
|
|
+ && MathTools.WithinEpsilon(this.x, otherVector.x, epsilon)
|
|
|
|
+ && MathTools.WithinEpsilon(this.y, otherVector.y, epsilon)
|
|
|
|
+ && MathTools.WithinEpsilon(this.z, otherVector.z, epsilon)
|
|
|
|
+ && MathTools.WithinEpsilon(this.w, otherVector.w, epsilon);
|
|
};
|
|
};
|
|
Vector4.prototype.equalsToFloats = function (x, y, z, w) {
|
|
Vector4.prototype.equalsToFloats = function (x, y, z, w) {
|
|
return this.x === x && this.y === y && this.z === z && this.w === w;
|
|
return this.x === x && this.y === y && this.z === z && this.w === w;
|
|
@@ -2308,174 +2320,6 @@ var BABYLON;
|
|
return Frustum;
|
|
return Frustum;
|
|
})();
|
|
})();
|
|
BABYLON.Frustum = Frustum;
|
|
BABYLON.Frustum = Frustum;
|
|
- var Ray = (function () {
|
|
|
|
- function Ray(origin, direction, length) {
|
|
|
|
- if (length === void 0) { length = Number.MAX_VALUE; }
|
|
|
|
- this.origin = origin;
|
|
|
|
- this.direction = direction;
|
|
|
|
- this.length = length;
|
|
|
|
- }
|
|
|
|
- // Methods
|
|
|
|
- Ray.prototype.intersectsBoxMinMax = function (minimum, maximum) {
|
|
|
|
- var d = 0.0;
|
|
|
|
- var maxValue = Number.MAX_VALUE;
|
|
|
|
- var inv;
|
|
|
|
- var min;
|
|
|
|
- var max;
|
|
|
|
- var temp;
|
|
|
|
- if (Math.abs(this.direction.x) < 0.0000001) {
|
|
|
|
- if (this.origin.x < minimum.x || this.origin.x > maximum.x) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- inv = 1.0 / this.direction.x;
|
|
|
|
- min = (minimum.x - this.origin.x) * inv;
|
|
|
|
- max = (maximum.x - this.origin.x) * inv;
|
|
|
|
- if (max === -Infinity) {
|
|
|
|
- max = Infinity;
|
|
|
|
- }
|
|
|
|
- if (min > max) {
|
|
|
|
- temp = min;
|
|
|
|
- min = max;
|
|
|
|
- max = temp;
|
|
|
|
- }
|
|
|
|
- d = Math.max(min, d);
|
|
|
|
- maxValue = Math.min(max, maxValue);
|
|
|
|
- if (d > maxValue) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (Math.abs(this.direction.y) < 0.0000001) {
|
|
|
|
- if (this.origin.y < minimum.y || this.origin.y > maximum.y) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- inv = 1.0 / this.direction.y;
|
|
|
|
- min = (minimum.y - this.origin.y) * inv;
|
|
|
|
- max = (maximum.y - this.origin.y) * inv;
|
|
|
|
- if (max === -Infinity) {
|
|
|
|
- max = Infinity;
|
|
|
|
- }
|
|
|
|
- if (min > max) {
|
|
|
|
- temp = min;
|
|
|
|
- min = max;
|
|
|
|
- max = temp;
|
|
|
|
- }
|
|
|
|
- d = Math.max(min, d);
|
|
|
|
- maxValue = Math.min(max, maxValue);
|
|
|
|
- if (d > maxValue) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (Math.abs(this.direction.z) < 0.0000001) {
|
|
|
|
- if (this.origin.z < minimum.z || this.origin.z > maximum.z) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- inv = 1.0 / this.direction.z;
|
|
|
|
- min = (minimum.z - this.origin.z) * inv;
|
|
|
|
- max = (maximum.z - this.origin.z) * inv;
|
|
|
|
- if (max === -Infinity) {
|
|
|
|
- max = Infinity;
|
|
|
|
- }
|
|
|
|
- if (min > max) {
|
|
|
|
- temp = min;
|
|
|
|
- min = max;
|
|
|
|
- max = temp;
|
|
|
|
- }
|
|
|
|
- d = Math.max(min, d);
|
|
|
|
- maxValue = Math.min(max, maxValue);
|
|
|
|
- if (d > maxValue) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- };
|
|
|
|
- Ray.prototype.intersectsBox = function (box) {
|
|
|
|
- return this.intersectsBoxMinMax(box.minimum, box.maximum);
|
|
|
|
- };
|
|
|
|
- Ray.prototype.intersectsSphere = function (sphere) {
|
|
|
|
- var x = sphere.center.x - this.origin.x;
|
|
|
|
- var y = sphere.center.y - this.origin.y;
|
|
|
|
- var z = sphere.center.z - this.origin.z;
|
|
|
|
- var pyth = (x * x) + (y * y) + (z * z);
|
|
|
|
- var rr = sphere.radius * sphere.radius;
|
|
|
|
- if (pyth <= rr) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- var dot = (x * this.direction.x) + (y * this.direction.y) + (z * this.direction.z);
|
|
|
|
- if (dot < 0.0) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- var temp = pyth - (dot * dot);
|
|
|
|
- return temp <= rr;
|
|
|
|
- };
|
|
|
|
- Ray.prototype.intersectsTriangle = function (vertex0, vertex1, vertex2) {
|
|
|
|
- if (!this._edge1) {
|
|
|
|
- this._edge1 = Vector3.Zero();
|
|
|
|
- this._edge2 = Vector3.Zero();
|
|
|
|
- this._pvec = Vector3.Zero();
|
|
|
|
- this._tvec = Vector3.Zero();
|
|
|
|
- this._qvec = Vector3.Zero();
|
|
|
|
- }
|
|
|
|
- vertex1.subtractToRef(vertex0, this._edge1);
|
|
|
|
- vertex2.subtractToRef(vertex0, this._edge2);
|
|
|
|
- Vector3.CrossToRef(this.direction, this._edge2, this._pvec);
|
|
|
|
- var det = Vector3.Dot(this._edge1, this._pvec);
|
|
|
|
- if (det === 0) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- var invdet = 1 / det;
|
|
|
|
- this.origin.subtractToRef(vertex0, this._tvec);
|
|
|
|
- var bu = Vector3.Dot(this._tvec, this._pvec) * invdet;
|
|
|
|
- if (bu < 0 || bu > 1.0) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- Vector3.CrossToRef(this._tvec, this._edge1, this._qvec);
|
|
|
|
- var bv = Vector3.Dot(this.direction, this._qvec) * invdet;
|
|
|
|
- if (bv < 0 || bu + bv > 1.0) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- //check if the distance is longer than the predefined length.
|
|
|
|
- var distance = Vector3.Dot(this._edge2, this._qvec) * invdet;
|
|
|
|
- if (distance > this.length) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- return new BABYLON.IntersectionInfo(bu, bv, distance);
|
|
|
|
- };
|
|
|
|
- // Statics
|
|
|
|
- Ray.CreateNew = function (x, y, viewportWidth, viewportHeight, world, view, projection) {
|
|
|
|
- var start = Vector3.Unproject(new Vector3(x, y, 0), viewportWidth, viewportHeight, world, view, projection);
|
|
|
|
- var end = Vector3.Unproject(new Vector3(x, y, 1), viewportWidth, viewportHeight, world, view, projection);
|
|
|
|
- var direction = end.subtract(start);
|
|
|
|
- direction.normalize();
|
|
|
|
- return new Ray(start, direction);
|
|
|
|
- };
|
|
|
|
- /**
|
|
|
|
- * Function will create a new transformed ray starting from origin and ending at the end point. Ray's length will be set, and ray will be
|
|
|
|
- * transformed to the given world matrix.
|
|
|
|
- * @param origin The origin point
|
|
|
|
- * @param end The end point
|
|
|
|
- * @param world a matrix to transform the ray to. Default is the identity matrix.
|
|
|
|
- */
|
|
|
|
- Ray.CreateNewFromTo = function (origin, end, world) {
|
|
|
|
- if (world === void 0) { world = Matrix.Identity(); }
|
|
|
|
- var direction = end.subtract(origin);
|
|
|
|
- var length = Math.sqrt((direction.x * direction.x) + (direction.y * direction.y) + (direction.z * direction.z));
|
|
|
|
- direction.normalize();
|
|
|
|
- return Ray.Transform(new Ray(origin, direction, length), world);
|
|
|
|
- };
|
|
|
|
- Ray.Transform = function (ray, matrix) {
|
|
|
|
- var newOrigin = Vector3.TransformCoordinates(ray.origin, matrix);
|
|
|
|
- var newDirection = Vector3.TransformNormal(ray.direction, matrix);
|
|
|
|
- return new Ray(newOrigin, newDirection, ray.length);
|
|
|
|
- };
|
|
|
|
- return Ray;
|
|
|
|
- })();
|
|
|
|
- BABYLON.Ray = Ray;
|
|
|
|
(function (Space) {
|
|
(function (Space) {
|
|
Space[Space["LOCAL"] = 0] = "LOCAL";
|
|
Space[Space["LOCAL"] = 0] = "LOCAL";
|
|
Space[Space["WORLD"] = 1] = "WORLD";
|
|
Space[Space["WORLD"] = 1] = "WORLD";
|
|
@@ -2574,63 +2418,6 @@ var BABYLON;
|
|
return Arc2;
|
|
return Arc2;
|
|
})();
|
|
})();
|
|
BABYLON.Arc2 = Arc2;
|
|
BABYLON.Arc2 = Arc2;
|
|
- var PathCursor = (function () {
|
|
|
|
- function PathCursor(path) {
|
|
|
|
- this.path = path;
|
|
|
|
- this._onchange = new Array();
|
|
|
|
- this.value = 0;
|
|
|
|
- this.animations = new Array();
|
|
|
|
- }
|
|
|
|
- PathCursor.prototype.getPoint = function () {
|
|
|
|
- var point = this.path.getPointAtLengthPosition(this.value);
|
|
|
|
- return new Vector3(point.x, 0, point.y);
|
|
|
|
- };
|
|
|
|
- PathCursor.prototype.moveAhead = function (step) {
|
|
|
|
- if (step === void 0) { step = 0.002; }
|
|
|
|
- this.move(step);
|
|
|
|
- return this;
|
|
|
|
- };
|
|
|
|
- PathCursor.prototype.moveBack = function (step) {
|
|
|
|
- if (step === void 0) { step = 0.002; }
|
|
|
|
- this.move(-step);
|
|
|
|
- return this;
|
|
|
|
- };
|
|
|
|
- PathCursor.prototype.move = function (step) {
|
|
|
|
- if (Math.abs(step) > 1) {
|
|
|
|
- throw "step size should be less than 1.";
|
|
|
|
- }
|
|
|
|
- this.value += step;
|
|
|
|
- this.ensureLimits();
|
|
|
|
- this.raiseOnChange();
|
|
|
|
- return this;
|
|
|
|
- };
|
|
|
|
- PathCursor.prototype.ensureLimits = function () {
|
|
|
|
- while (this.value > 1) {
|
|
|
|
- this.value -= 1;
|
|
|
|
- }
|
|
|
|
- while (this.value < 0) {
|
|
|
|
- this.value += 1;
|
|
|
|
- }
|
|
|
|
- return this;
|
|
|
|
- };
|
|
|
|
- // used by animation engine
|
|
|
|
- PathCursor.prototype.markAsDirty = function (propertyName) {
|
|
|
|
- this.ensureLimits();
|
|
|
|
- this.raiseOnChange();
|
|
|
|
- return this;
|
|
|
|
- };
|
|
|
|
- PathCursor.prototype.raiseOnChange = function () {
|
|
|
|
- var _this = this;
|
|
|
|
- this._onchange.forEach(function (f) { return f(_this); });
|
|
|
|
- return this;
|
|
|
|
- };
|
|
|
|
- PathCursor.prototype.onchange = function (f) {
|
|
|
|
- this._onchange.push(f);
|
|
|
|
- return this;
|
|
|
|
- };
|
|
|
|
- return PathCursor;
|
|
|
|
- })();
|
|
|
|
- BABYLON.PathCursor = PathCursor;
|
|
|
|
var Path2 = (function () {
|
|
var Path2 = (function () {
|
|
function Path2(x, y) {
|
|
function Path2(x, y) {
|
|
this._points = new Array();
|
|
this._points = new Array();
|
|
@@ -2842,13 +2629,13 @@ var BABYLON;
|
|
var normal0;
|
|
var normal0;
|
|
if (va === undefined || va === null) {
|
|
if (va === undefined || va === null) {
|
|
var point;
|
|
var point;
|
|
- if (!BABYLON.Tools.WithinEpsilon(vt.y, 1, BABYLON.Engine.Epsilon)) {
|
|
|
|
|
|
+ if (!MathTools.WithinEpsilon(vt.y, 1, BABYLON.Epsilon)) {
|
|
point = new Vector3(0, -1, 0);
|
|
point = new Vector3(0, -1, 0);
|
|
}
|
|
}
|
|
- else if (!BABYLON.Tools.WithinEpsilon(vt.x, 1, BABYLON.Engine.Epsilon)) {
|
|
|
|
|
|
+ else if (!MathTools.WithinEpsilon(vt.x, 1, BABYLON.Epsilon)) {
|
|
point = new Vector3(1, 0, 0);
|
|
point = new Vector3(1, 0, 0);
|
|
}
|
|
}
|
|
- else if (!BABYLON.Tools.WithinEpsilon(vt.z, 1, BABYLON.Engine.Epsilon)) {
|
|
|
|
|
|
+ else if (!MathTools.WithinEpsilon(vt.z, 1, BABYLON.Epsilon)) {
|
|
point = new Vector3(0, 0, 1);
|
|
point = new Vector3(0, 0, 1);
|
|
}
|
|
}
|
|
normal0 = Vector3.Cross(vt, point);
|
|
normal0 = Vector3.Cross(vt, point);
|