Преглед на файлове

further epsilon references fixed

Raanan Weber преди 9 години
родител
ревизия
31372b65be

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

@@ -482,11 +482,11 @@
                 this.inertialAlphaOffset *= this.inertia;
                 this.inertialBetaOffset *= this.inertia;
                 this.inertialRadiusOffset *= this.inertia;
-                if (Math.abs(this.inertialAlphaOffset) < Engine.Epsilon)
+                if (Math.abs(this.inertialAlphaOffset) < Epsilon)
                     this.inertialAlphaOffset = 0;
-                if (Math.abs(this.inertialBetaOffset) < Engine.Epsilon)
+                if (Math.abs(this.inertialBetaOffset) < Epsilon)
                     this.inertialBetaOffset = 0;
-                if (Math.abs(this.inertialRadiusOffset) < Engine.Epsilon)
+                if (Math.abs(this.inertialRadiusOffset) < Epsilon)
                     this.inertialRadiusOffset = 0;
             }
 
@@ -500,9 +500,9 @@
                 this.inertialPanningX *= this.inertia;
                 this.inertialPanningY *= this.inertia;
 
-                if (Math.abs(this.inertialPanningX) < Engine.Epsilon)
+                if (Math.abs(this.inertialPanningX) < Epsilon)
                     this.inertialPanningX = 0;
-                if (Math.abs(this.inertialPanningY) < Engine.Epsilon)
+                if (Math.abs(this.inertialPanningY) < Epsilon)
                     this.inertialPanningY = 0;
 
                 this._localDirection.copyFromFloats(this.inertialPanningX, this.inertialPanningY, this.inertialPanningY);

+ 5 - 5
src/Cameras/babylon.targetCamera.ts

@@ -166,26 +166,26 @@
 
             // Inertia
             if (needToMove) {
-                if (Math.abs(this.cameraDirection.x) < Engine.Epsilon) {
+                if (Math.abs(this.cameraDirection.x) < Epsilon) {
                     this.cameraDirection.x = 0;
                 }
 
-                if (Math.abs(this.cameraDirection.y) < Engine.Epsilon) {
+                if (Math.abs(this.cameraDirection.y) < Epsilon) {
                     this.cameraDirection.y = 0;
                 }
 
-                if (Math.abs(this.cameraDirection.z) < Engine.Epsilon) {
+                if (Math.abs(this.cameraDirection.z) < Epsilon) {
                     this.cameraDirection.z = 0;
                 }
 
                 this.cameraDirection.scaleInPlace(this.inertia);
             }
             if (needToRotate) {
-                if (Math.abs(this.cameraRotation.x) < Engine.Epsilon) {
+                if (Math.abs(this.cameraRotation.x) < Epsilon) {
                     this.cameraRotation.x = 0;
                 }
 
-                if (Math.abs(this.cameraRotation.y) < Engine.Epsilon) {
+                if (Math.abs(this.cameraRotation.y) < Epsilon) {
                     this.cameraRotation.y = 0;
                 }
                 this.cameraRotation.scaleInPlace(this.inertia);

+ 1 - 1
src/Culling/babylon.boundingBox.ts

@@ -101,7 +101,7 @@
         }
 
         public intersectsPoint(point: Vector3): boolean {
-            var delta = -Engine.Epsilon;
+            var delta = -Epsilon;
 
             if (this.maximumWorld.x - point.x < delta || delta > point.x - this.minimumWorld.x)
                 return false;

+ 1 - 1
src/Culling/babylon.boundingSphere.ts

@@ -40,7 +40,7 @@
 
             var distance = Math.sqrt((x * x) + (y * y) + (z * z));
 
-            if (Math.abs(this.radiusWorld - distance) < Engine.Epsilon)
+            if (Math.abs(this.radiusWorld - distance) < Epsilon)
                 return false;
 
             return true;

+ 171 - 0
src/Culling/babylon.ray.js

@@ -0,0 +1,171 @@
+var BABYLON;
+(function (BABYLON) {
+    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 = BABYLON.Vector3.Zero();
+                this._edge2 = BABYLON.Vector3.Zero();
+                this._pvec = BABYLON.Vector3.Zero();
+                this._tvec = BABYLON.Vector3.Zero();
+                this._qvec = BABYLON.Vector3.Zero();
+            }
+            vertex1.subtractToRef(vertex0, this._edge1);
+            vertex2.subtractToRef(vertex0, this._edge2);
+            BABYLON.Vector3.CrossToRef(this.direction, this._edge2, this._pvec);
+            var det = BABYLON.Vector3.Dot(this._edge1, this._pvec);
+            if (det === 0) {
+                return null;
+            }
+            var invdet = 1 / det;
+            this.origin.subtractToRef(vertex0, this._tvec);
+            var bu = BABYLON.Vector3.Dot(this._tvec, this._pvec) * invdet;
+            if (bu < 0 || bu > 1.0) {
+                return null;
+            }
+            BABYLON.Vector3.CrossToRef(this._tvec, this._edge1, this._qvec);
+            var bv = BABYLON.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 = BABYLON.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 = BABYLON.Vector3.Unproject(new BABYLON.Vector3(x, y, 0), viewportWidth, viewportHeight, world, view, projection);
+            var end = BABYLON.Vector3.Unproject(new BABYLON.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 = BABYLON.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 = BABYLON.Vector3.TransformCoordinates(ray.origin, matrix);
+            var newDirection = BABYLON.Vector3.TransformNormal(ray.direction, matrix);
+            return new Ray(newOrigin, newDirection, ray.length);
+        };
+        return Ray;
+    }());
+    BABYLON.Ray = Ray;
+})(BABYLON || (BABYLON = {}));

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

@@ -243,7 +243,7 @@
         constructor(private _mesh: Mesh) {
             this.aggressiveness = 7;
             this.decimationIterations = 100;
-            this.boundingBoxEpsilon = Engine.Epsilon;
+            this.boundingBoxEpsilon = Epsilon;
         }
 
         public simplify(settings: ISimplificationSettings, successCallback: (simplifiedMesh: Mesh) => void) {