David Catuhe 6 年之前
父节点
当前提交
c9cb6dff47

文件差异内容过多而无法显示
+ 5394 - 5381
Playground/babylon.d.txt


文件差异内容过多而无法显示
+ 5394 - 5381
dist/preview release/babylon.d.ts


文件差异内容过多而无法显示
+ 1 - 1
dist/preview release/babylon.js


+ 95 - 42
dist/preview release/babylon.max.js

@@ -5825,6 +5825,15 @@ var BABYLON;
             matrix.multiplyToRef(viewportMatrix, matrix);
             return Vector3.TransformCoordinates(vector, matrix);
         };
+        /** @hidden */
+        Vector3.UnprojectFromInvertedMatrixToRef = function (source, matrix, result) {
+            Vector3.TransformCoordinatesToRef(source, matrix, result);
+            var m = matrix.m;
+            var num = source.x * m[3] + source.y * m[7] + source.z * m[11] + m[15];
+            if (BABYLON.Scalar.WithinEpsilon(num, 1.0)) {
+                result.scaleInPlace(1.0 / num);
+            }
+        };
         /**
          * Unproject from screen space to object space
          * @param source defines the screen space Vector3 to use
@@ -5840,12 +5849,8 @@ var BABYLON;
             matrix.invert();
             source.x = source.x / viewportWidth * 2 - 1;
             source.y = -(source.y / viewportHeight * 2 - 1);
-            var vector = Vector3.TransformCoordinates(source, matrix);
-            var m = matrix.m;
-            var num = source.x * m[3] + source.y * m[7] + source.z * m[11] + m[15];
-            if (BABYLON.Scalar.WithinEpsilon(num, 1.0)) {
-                vector = vector.scale(1.0 / num);
-            }
+            var vector = new Vector3();
+            Vector3.UnprojectFromInvertedMatrixToRef(source, matrix, vector);
             return vector;
         };
         /**
@@ -5897,12 +5902,36 @@ var BABYLON;
             screenSource.x = sourceX / viewportWidth * 2 - 1;
             screenSource.y = -(sourceY / viewportHeight * 2 - 1);
             screenSource.z = 2 * sourceZ - 1.0;
-            Vector3.TransformCoordinatesToRef(screenSource, matrix, result);
-            var m = matrix.m;
-            var num = screenSource.x * m[3] + screenSource.y * m[7] + screenSource.z * m[11] + m[15];
-            if (BABYLON.Scalar.WithinEpsilon(num, 1.0)) {
-                result.scaleInPlace(1.0 / num);
-            }
+            Vector3.UnprojectFromInvertedMatrixToRef(screenSource, matrix, result);
+        };
+        /**
+          * Unproject a ray from screen space to object space
+          * @param sourceX defines the screen space x coordinate to use
+          * @param sourceY defines the screen space y coordinate to use
+          * @param viewportWidth defines the current width of the viewport
+          * @param viewportHeight defines the current height of the viewport
+          * @param world defines the world matrix to use (can be set to Identity to go to world space)
+          * @param view defines the view matrix to use
+          * @param projection defines the projection matrix to use
+          * @param ray defines the Ray where to store the result
+          */
+        Vector3.UnprojectRayToRef = function (sourceX, sourceY, viewportWidth, viewportHeight, world, view, projection, ray) {
+            var matrix = MathTmp.Matrix[0];
+            world.multiplyToRef(view, matrix);
+            matrix.multiplyToRef(projection, matrix);
+            matrix.invert();
+            var nearScreenSource = MathTmp.Vector3[0];
+            nearScreenSource.x = sourceX / viewportWidth * 2 - 1;
+            nearScreenSource.y = -(sourceY / viewportHeight * 2 - 1);
+            nearScreenSource.z = -1.0;
+            var farScreenSource = MathTmp.Vector3[1].copyFromFloats(nearScreenSource.x, nearScreenSource.y, 1.0);
+            var nearVec3 = MathTmp.Vector3[2];
+            var farVec3 = MathTmp.Vector3[3];
+            Vector3.UnprojectFromInvertedMatrixToRef(nearScreenSource, matrix, nearVec3);
+            Vector3.UnprojectFromInvertedMatrixToRef(farScreenSource, matrix, farVec3);
+            ray.origin.copyFrom(nearVec3);
+            farVec3.subtractToRef(nearVec3, ray.direction);
+            ray.direction.normalize();
         };
         /**
          * Gets the minimal coordinate values between two Vector3
@@ -25596,6 +25625,10 @@ var BABYLON;
             */
             _this.onAfterStepObservable = new BABYLON.Observable();
             /**
+             * An event triggered when the activeCamera property is updated
+             */
+            _this.onActiveCameraChanged = new BABYLON.Observable();
+            /**
              * This Observable will be triggered before rendering each renderingGroup of each rendered camera.
              * The RenderinGroupInfo class contains all the information about the context in which the observable is called
              * If you wish to register an Observer only for a given set of renderingGroup, use the mask with a combination of the renderingGroup index elevated to the power of two (1 for renderingGroup 0, 2 for renderingrOup1, 4 for 2 and 8 for 3)
@@ -26234,6 +26267,21 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(Scene.prototype, "activeCamera", {
+            /** Gets or sets the current active camera */
+            get: function () {
+                return this._activeCamera;
+            },
+            set: function (value) {
+                if (value === this._activeCamera) {
+                    return;
+                }
+                this._activeCamera = value;
+                this.onActiveCameraChanged.notifyObservers(this);
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(Scene.prototype, "defaultMaterial", {
             /** The default material used on meshes when no material is affected */
             get: function () {
@@ -27028,6 +27076,7 @@ var BABYLON;
                     canvas.focus();
                 }
                 _this._initClickEvent(_this.onPrePointerObservable, _this.onPointerObservable, evt, function (clickInfo, pickResult) {
+                    _this._pointerCaptures[evt.pointerId] = false;
                     // PreObservable support
                     if (_this.onPrePointerObservable.hasObservers()) {
                         if (!clickInfo.ignore) {
@@ -27051,7 +27100,6 @@ var BABYLON;
                     if (!_this.cameraToUseForPointers && !_this.activeCamera) {
                         return;
                     }
-                    _this._pointerCaptures[evt.pointerId] = false;
                     if (!_this.pointerUpPredicate) {
                         _this.pointerUpPredicate = function (mesh) {
                             return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.isEnabled();
@@ -29423,6 +29471,7 @@ var BABYLON;
             this.onPointerObservable.clear();
             this.onPreKeyboardObservable.clear();
             this.onKeyboardObservable.clear();
+            this.onActiveCameraChanged.clear();
             this.detachControl();
             // Detach cameras
             var canvas = this._engine.getRenderingCanvas();
@@ -29596,7 +29645,7 @@ var BABYLON;
             // Moving coordinates to local viewport world
             x = x / this._engine.getHardwareScalingLevel() - viewport.x;
             y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);
-            result.update(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), cameraViewSpace ? BABYLON.Matrix.Identity() : camera.getViewMatrix(), camera.getProjectionMatrix());
+            result.update(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.IdentityReadOnly, cameraViewSpace ? BABYLON.Matrix.IdentityReadOnly : camera.getViewMatrix(), camera.getProjectionMatrix());
             return this;
         };
         /**
@@ -58767,8 +58816,8 @@ var BABYLON;
          */
         Ray.prototype.intersectsBoxMinMax = function (minimum, maximum, intersectionTreshold) {
             if (intersectionTreshold === void 0) { intersectionTreshold = 0; }
-            var newMinimum = Ray._min.copyFromFloats(minimum.x - intersectionTreshold, minimum.y - intersectionTreshold, minimum.z - intersectionTreshold);
-            var newMaximum = Ray._max.copyFromFloats(maximum.x + intersectionTreshold, maximum.y + intersectionTreshold, maximum.z + intersectionTreshold);
+            var newMinimum = Ray.TmpVector3[0].copyFromFloats(minimum.x - intersectionTreshold, minimum.y - intersectionTreshold, minimum.z - intersectionTreshold);
+            var newMaximum = Ray.TmpVector3[1].copyFromFloats(maximum.x + intersectionTreshold, maximum.y + intersectionTreshold, maximum.z + intersectionTreshold);
             var d = 0.0;
             var maxValue = Number.MAX_VALUE;
             var inv;
@@ -58888,26 +58937,31 @@ var BABYLON;
          * @returns intersection information if hit
          */
         Ray.prototype.intersectsTriangle = function (vertex0, vertex1, vertex2) {
-            vertex1.subtractToRef(vertex0, Ray._edge1);
-            vertex2.subtractToRef(vertex0, Ray._edge2);
-            BABYLON.Vector3.CrossToRef(this.direction, Ray._edge2, Ray._pvec);
-            var det = BABYLON.Vector3.Dot(Ray._edge1, Ray._pvec);
+            var edge1 = Ray.TmpVector3[0];
+            var edge2 = Ray.TmpVector3[1];
+            var pvec = Ray.TmpVector3[2];
+            var tvec = Ray.TmpVector3[3];
+            var qvec = Ray.TmpVector3[4];
+            vertex1.subtractToRef(vertex0, edge1);
+            vertex2.subtractToRef(vertex0, edge2);
+            BABYLON.Vector3.CrossToRef(this.direction, edge2, pvec);
+            var det = BABYLON.Vector3.Dot(edge1, pvec);
             if (det === 0) {
                 return null;
             }
             var invdet = 1 / det;
-            this.origin.subtractToRef(vertex0, Ray._tvec);
-            var bu = BABYLON.Vector3.Dot(Ray._tvec, Ray._pvec) * invdet;
+            this.origin.subtractToRef(vertex0, tvec);
+            var bu = BABYLON.Vector3.Dot(tvec, pvec) * invdet;
             if (bu < 0 || bu > 1.0) {
                 return null;
             }
-            BABYLON.Vector3.CrossToRef(Ray._tvec, Ray._edge1, Ray._qvec);
-            var bv = BABYLON.Vector3.Dot(this.direction, Ray._qvec) * invdet;
+            BABYLON.Vector3.CrossToRef(tvec, edge1, qvec);
+            var bv = BABYLON.Vector3.Dot(this.direction, 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(Ray._edge2, Ray._qvec) * invdet;
+            var distance = BABYLON.Vector3.Dot(edge2, qvec) * invdet;
             if (distance > this.length) {
                 return null;
             }
@@ -58997,10 +59051,15 @@ var BABYLON;
          * @return the distance from the ray origin to the intersection point if there's intersection, or -1 if there's no intersection
          */
         Ray.prototype.intersectionSegment = function (sega, segb, threshold) {
-            var rsegb = this.origin.add(this.direction.multiplyByFloats(Ray.rayl, Ray.rayl, Ray.rayl));
-            var u = segb.subtract(sega);
-            var v = rsegb.subtract(this.origin);
-            var w = sega.subtract(this.origin);
+            var o = this.origin;
+            var u = BABYLON.Tmp.Vector3[0];
+            var rsegb = BABYLON.Tmp.Vector3[1];
+            var v = BABYLON.Tmp.Vector3[2];
+            var w = BABYLON.Tmp.Vector3[3];
+            segb.subtractToRef(sega, u);
+            this.direction.scaleToRef(Ray.rayl, v);
+            o.addToRef(v, rsegb);
+            sega.subtractToRef(o, w);
             var a = BABYLON.Vector3.Dot(u, u); // always >= 0
             var b = BABYLON.Vector3.Dot(u, v);
             var c = BABYLON.Vector3.Dot(v, v); // always >= 0
@@ -59062,8 +59121,11 @@ var BABYLON;
             sc = (Math.abs(sN) < Ray.smallnum ? 0.0 : sN / sD);
             tc = (Math.abs(tN) < Ray.smallnum ? 0.0 : tN / tD);
             // get the difference of the two closest points
-            var qtc = v.multiplyByFloats(tc, tc, tc);
-            var dP = w.add(u.multiplyByFloats(sc, sc, sc)).subtract(qtc); // = S1(sc) - S2(tc)
+            var qtc = BABYLON.Tmp.Vector3[4];
+            v.scaleToRef(tc, qtc);
+            var dP = BABYLON.Tmp.Vector3[5];
+            u.scaleToRef(sc, dP);
+            dP.addInPlace(w).subtractInPlace(qtc); // = S1(sc) - S2(tc)
             var isIntersected = (tc > 0) && (tc <= this.length) && (dP.lengthSquared() < (threshold * threshold)); // return intersection result
             if (isIntersected) {
                 return qtc.length();
@@ -59082,10 +59144,7 @@ var BABYLON;
          * @returns this ray updated
          */
         Ray.prototype.update = function (x, y, viewportWidth, viewportHeight, world, view, projection) {
-            BABYLON.Vector3.UnprojectFloatsToRef(x, y, 0, viewportWidth, viewportHeight, world, view, projection, this.origin);
-            BABYLON.Vector3.UnprojectFloatsToRef(x, y, 1, viewportWidth, viewportHeight, world, view, projection, BABYLON.Tmp.Vector3[0]);
-            BABYLON.Tmp.Vector3[0].subtractToRef(this.origin, this.direction);
-            this.direction.normalize();
+            BABYLON.Vector3.UnprojectRayToRef(x, y, viewportWidth, viewportHeight, world, view, projection, this);
             return this;
         };
         // Statics
@@ -59157,13 +59216,7 @@ var BABYLON;
                 result.length *= len;
             }
         };
-        Ray._edge1 = BABYLON.Vector3.Zero();
-        Ray._edge2 = BABYLON.Vector3.Zero();
-        Ray._pvec = BABYLON.Vector3.Zero();
-        Ray._tvec = BABYLON.Vector3.Zero();
-        Ray._qvec = BABYLON.Vector3.Zero();
-        Ray._min = BABYLON.Vector3.Zero();
-        Ray._max = BABYLON.Vector3.Zero();
+        Ray.TmpVector3 = BABYLON.Tools.BuildArray(6, BABYLON.Vector3.Zero);
         Ray.smallnum = 0.00000001;
         Ray.rayl = 10e8;
         return Ray;

+ 95 - 42
dist/preview release/babylon.no-module.max.js

@@ -5792,6 +5792,15 @@ var BABYLON;
             matrix.multiplyToRef(viewportMatrix, matrix);
             return Vector3.TransformCoordinates(vector, matrix);
         };
+        /** @hidden */
+        Vector3.UnprojectFromInvertedMatrixToRef = function (source, matrix, result) {
+            Vector3.TransformCoordinatesToRef(source, matrix, result);
+            var m = matrix.m;
+            var num = source.x * m[3] + source.y * m[7] + source.z * m[11] + m[15];
+            if (BABYLON.Scalar.WithinEpsilon(num, 1.0)) {
+                result.scaleInPlace(1.0 / num);
+            }
+        };
         /**
          * Unproject from screen space to object space
          * @param source defines the screen space Vector3 to use
@@ -5807,12 +5816,8 @@ var BABYLON;
             matrix.invert();
             source.x = source.x / viewportWidth * 2 - 1;
             source.y = -(source.y / viewportHeight * 2 - 1);
-            var vector = Vector3.TransformCoordinates(source, matrix);
-            var m = matrix.m;
-            var num = source.x * m[3] + source.y * m[7] + source.z * m[11] + m[15];
-            if (BABYLON.Scalar.WithinEpsilon(num, 1.0)) {
-                vector = vector.scale(1.0 / num);
-            }
+            var vector = new Vector3();
+            Vector3.UnprojectFromInvertedMatrixToRef(source, matrix, vector);
             return vector;
         };
         /**
@@ -5864,12 +5869,36 @@ var BABYLON;
             screenSource.x = sourceX / viewportWidth * 2 - 1;
             screenSource.y = -(sourceY / viewportHeight * 2 - 1);
             screenSource.z = 2 * sourceZ - 1.0;
-            Vector3.TransformCoordinatesToRef(screenSource, matrix, result);
-            var m = matrix.m;
-            var num = screenSource.x * m[3] + screenSource.y * m[7] + screenSource.z * m[11] + m[15];
-            if (BABYLON.Scalar.WithinEpsilon(num, 1.0)) {
-                result.scaleInPlace(1.0 / num);
-            }
+            Vector3.UnprojectFromInvertedMatrixToRef(screenSource, matrix, result);
+        };
+        /**
+          * Unproject a ray from screen space to object space
+          * @param sourceX defines the screen space x coordinate to use
+          * @param sourceY defines the screen space y coordinate to use
+          * @param viewportWidth defines the current width of the viewport
+          * @param viewportHeight defines the current height of the viewport
+          * @param world defines the world matrix to use (can be set to Identity to go to world space)
+          * @param view defines the view matrix to use
+          * @param projection defines the projection matrix to use
+          * @param ray defines the Ray where to store the result
+          */
+        Vector3.UnprojectRayToRef = function (sourceX, sourceY, viewportWidth, viewportHeight, world, view, projection, ray) {
+            var matrix = MathTmp.Matrix[0];
+            world.multiplyToRef(view, matrix);
+            matrix.multiplyToRef(projection, matrix);
+            matrix.invert();
+            var nearScreenSource = MathTmp.Vector3[0];
+            nearScreenSource.x = sourceX / viewportWidth * 2 - 1;
+            nearScreenSource.y = -(sourceY / viewportHeight * 2 - 1);
+            nearScreenSource.z = -1.0;
+            var farScreenSource = MathTmp.Vector3[1].copyFromFloats(nearScreenSource.x, nearScreenSource.y, 1.0);
+            var nearVec3 = MathTmp.Vector3[2];
+            var farVec3 = MathTmp.Vector3[3];
+            Vector3.UnprojectFromInvertedMatrixToRef(nearScreenSource, matrix, nearVec3);
+            Vector3.UnprojectFromInvertedMatrixToRef(farScreenSource, matrix, farVec3);
+            ray.origin.copyFrom(nearVec3);
+            farVec3.subtractToRef(nearVec3, ray.direction);
+            ray.direction.normalize();
         };
         /**
          * Gets the minimal coordinate values between two Vector3
@@ -25563,6 +25592,10 @@ var BABYLON;
             */
             _this.onAfterStepObservable = new BABYLON.Observable();
             /**
+             * An event triggered when the activeCamera property is updated
+             */
+            _this.onActiveCameraChanged = new BABYLON.Observable();
+            /**
              * This Observable will be triggered before rendering each renderingGroup of each rendered camera.
              * The RenderinGroupInfo class contains all the information about the context in which the observable is called
              * If you wish to register an Observer only for a given set of renderingGroup, use the mask with a combination of the renderingGroup index elevated to the power of two (1 for renderingGroup 0, 2 for renderingrOup1, 4 for 2 and 8 for 3)
@@ -26201,6 +26234,21 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(Scene.prototype, "activeCamera", {
+            /** Gets or sets the current active camera */
+            get: function () {
+                return this._activeCamera;
+            },
+            set: function (value) {
+                if (value === this._activeCamera) {
+                    return;
+                }
+                this._activeCamera = value;
+                this.onActiveCameraChanged.notifyObservers(this);
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(Scene.prototype, "defaultMaterial", {
             /** The default material used on meshes when no material is affected */
             get: function () {
@@ -26995,6 +27043,7 @@ var BABYLON;
                     canvas.focus();
                 }
                 _this._initClickEvent(_this.onPrePointerObservable, _this.onPointerObservable, evt, function (clickInfo, pickResult) {
+                    _this._pointerCaptures[evt.pointerId] = false;
                     // PreObservable support
                     if (_this.onPrePointerObservable.hasObservers()) {
                         if (!clickInfo.ignore) {
@@ -27018,7 +27067,6 @@ var BABYLON;
                     if (!_this.cameraToUseForPointers && !_this.activeCamera) {
                         return;
                     }
-                    _this._pointerCaptures[evt.pointerId] = false;
                     if (!_this.pointerUpPredicate) {
                         _this.pointerUpPredicate = function (mesh) {
                             return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.isEnabled();
@@ -29390,6 +29438,7 @@ var BABYLON;
             this.onPointerObservable.clear();
             this.onPreKeyboardObservable.clear();
             this.onKeyboardObservable.clear();
+            this.onActiveCameraChanged.clear();
             this.detachControl();
             // Detach cameras
             var canvas = this._engine.getRenderingCanvas();
@@ -29563,7 +29612,7 @@ var BABYLON;
             // Moving coordinates to local viewport world
             x = x / this._engine.getHardwareScalingLevel() - viewport.x;
             y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);
-            result.update(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), cameraViewSpace ? BABYLON.Matrix.Identity() : camera.getViewMatrix(), camera.getProjectionMatrix());
+            result.update(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.IdentityReadOnly, cameraViewSpace ? BABYLON.Matrix.IdentityReadOnly : camera.getViewMatrix(), camera.getProjectionMatrix());
             return this;
         };
         /**
@@ -58734,8 +58783,8 @@ var BABYLON;
          */
         Ray.prototype.intersectsBoxMinMax = function (minimum, maximum, intersectionTreshold) {
             if (intersectionTreshold === void 0) { intersectionTreshold = 0; }
-            var newMinimum = Ray._min.copyFromFloats(minimum.x - intersectionTreshold, minimum.y - intersectionTreshold, minimum.z - intersectionTreshold);
-            var newMaximum = Ray._max.copyFromFloats(maximum.x + intersectionTreshold, maximum.y + intersectionTreshold, maximum.z + intersectionTreshold);
+            var newMinimum = Ray.TmpVector3[0].copyFromFloats(minimum.x - intersectionTreshold, minimum.y - intersectionTreshold, minimum.z - intersectionTreshold);
+            var newMaximum = Ray.TmpVector3[1].copyFromFloats(maximum.x + intersectionTreshold, maximum.y + intersectionTreshold, maximum.z + intersectionTreshold);
             var d = 0.0;
             var maxValue = Number.MAX_VALUE;
             var inv;
@@ -58855,26 +58904,31 @@ var BABYLON;
          * @returns intersection information if hit
          */
         Ray.prototype.intersectsTriangle = function (vertex0, vertex1, vertex2) {
-            vertex1.subtractToRef(vertex0, Ray._edge1);
-            vertex2.subtractToRef(vertex0, Ray._edge2);
-            BABYLON.Vector3.CrossToRef(this.direction, Ray._edge2, Ray._pvec);
-            var det = BABYLON.Vector3.Dot(Ray._edge1, Ray._pvec);
+            var edge1 = Ray.TmpVector3[0];
+            var edge2 = Ray.TmpVector3[1];
+            var pvec = Ray.TmpVector3[2];
+            var tvec = Ray.TmpVector3[3];
+            var qvec = Ray.TmpVector3[4];
+            vertex1.subtractToRef(vertex0, edge1);
+            vertex2.subtractToRef(vertex0, edge2);
+            BABYLON.Vector3.CrossToRef(this.direction, edge2, pvec);
+            var det = BABYLON.Vector3.Dot(edge1, pvec);
             if (det === 0) {
                 return null;
             }
             var invdet = 1 / det;
-            this.origin.subtractToRef(vertex0, Ray._tvec);
-            var bu = BABYLON.Vector3.Dot(Ray._tvec, Ray._pvec) * invdet;
+            this.origin.subtractToRef(vertex0, tvec);
+            var bu = BABYLON.Vector3.Dot(tvec, pvec) * invdet;
             if (bu < 0 || bu > 1.0) {
                 return null;
             }
-            BABYLON.Vector3.CrossToRef(Ray._tvec, Ray._edge1, Ray._qvec);
-            var bv = BABYLON.Vector3.Dot(this.direction, Ray._qvec) * invdet;
+            BABYLON.Vector3.CrossToRef(tvec, edge1, qvec);
+            var bv = BABYLON.Vector3.Dot(this.direction, 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(Ray._edge2, Ray._qvec) * invdet;
+            var distance = BABYLON.Vector3.Dot(edge2, qvec) * invdet;
             if (distance > this.length) {
                 return null;
             }
@@ -58964,10 +59018,15 @@ var BABYLON;
          * @return the distance from the ray origin to the intersection point if there's intersection, or -1 if there's no intersection
          */
         Ray.prototype.intersectionSegment = function (sega, segb, threshold) {
-            var rsegb = this.origin.add(this.direction.multiplyByFloats(Ray.rayl, Ray.rayl, Ray.rayl));
-            var u = segb.subtract(sega);
-            var v = rsegb.subtract(this.origin);
-            var w = sega.subtract(this.origin);
+            var o = this.origin;
+            var u = BABYLON.Tmp.Vector3[0];
+            var rsegb = BABYLON.Tmp.Vector3[1];
+            var v = BABYLON.Tmp.Vector3[2];
+            var w = BABYLON.Tmp.Vector3[3];
+            segb.subtractToRef(sega, u);
+            this.direction.scaleToRef(Ray.rayl, v);
+            o.addToRef(v, rsegb);
+            sega.subtractToRef(o, w);
             var a = BABYLON.Vector3.Dot(u, u); // always >= 0
             var b = BABYLON.Vector3.Dot(u, v);
             var c = BABYLON.Vector3.Dot(v, v); // always >= 0
@@ -59029,8 +59088,11 @@ var BABYLON;
             sc = (Math.abs(sN) < Ray.smallnum ? 0.0 : sN / sD);
             tc = (Math.abs(tN) < Ray.smallnum ? 0.0 : tN / tD);
             // get the difference of the two closest points
-            var qtc = v.multiplyByFloats(tc, tc, tc);
-            var dP = w.add(u.multiplyByFloats(sc, sc, sc)).subtract(qtc); // = S1(sc) - S2(tc)
+            var qtc = BABYLON.Tmp.Vector3[4];
+            v.scaleToRef(tc, qtc);
+            var dP = BABYLON.Tmp.Vector3[5];
+            u.scaleToRef(sc, dP);
+            dP.addInPlace(w).subtractInPlace(qtc); // = S1(sc) - S2(tc)
             var isIntersected = (tc > 0) && (tc <= this.length) && (dP.lengthSquared() < (threshold * threshold)); // return intersection result
             if (isIntersected) {
                 return qtc.length();
@@ -59049,10 +59111,7 @@ var BABYLON;
          * @returns this ray updated
          */
         Ray.prototype.update = function (x, y, viewportWidth, viewportHeight, world, view, projection) {
-            BABYLON.Vector3.UnprojectFloatsToRef(x, y, 0, viewportWidth, viewportHeight, world, view, projection, this.origin);
-            BABYLON.Vector3.UnprojectFloatsToRef(x, y, 1, viewportWidth, viewportHeight, world, view, projection, BABYLON.Tmp.Vector3[0]);
-            BABYLON.Tmp.Vector3[0].subtractToRef(this.origin, this.direction);
-            this.direction.normalize();
+            BABYLON.Vector3.UnprojectRayToRef(x, y, viewportWidth, viewportHeight, world, view, projection, this);
             return this;
         };
         // Statics
@@ -59124,13 +59183,7 @@ var BABYLON;
                 result.length *= len;
             }
         };
-        Ray._edge1 = BABYLON.Vector3.Zero();
-        Ray._edge2 = BABYLON.Vector3.Zero();
-        Ray._pvec = BABYLON.Vector3.Zero();
-        Ray._tvec = BABYLON.Vector3.Zero();
-        Ray._qvec = BABYLON.Vector3.Zero();
-        Ray._min = BABYLON.Vector3.Zero();
-        Ray._max = BABYLON.Vector3.Zero();
+        Ray.TmpVector3 = BABYLON.Tools.BuildArray(6, BABYLON.Vector3.Zero);
         Ray.smallnum = 0.00000001;
         Ray.rayl = 10e8;
         return Ray;

文件差异内容过多而无法显示
+ 1 - 1
dist/preview release/babylon.worker.js


+ 95 - 42
dist/preview release/es6.js

@@ -5792,6 +5792,15 @@ var BABYLON;
             matrix.multiplyToRef(viewportMatrix, matrix);
             return Vector3.TransformCoordinates(vector, matrix);
         };
+        /** @hidden */
+        Vector3.UnprojectFromInvertedMatrixToRef = function (source, matrix, result) {
+            Vector3.TransformCoordinatesToRef(source, matrix, result);
+            var m = matrix.m;
+            var num = source.x * m[3] + source.y * m[7] + source.z * m[11] + m[15];
+            if (BABYLON.Scalar.WithinEpsilon(num, 1.0)) {
+                result.scaleInPlace(1.0 / num);
+            }
+        };
         /**
          * Unproject from screen space to object space
          * @param source defines the screen space Vector3 to use
@@ -5807,12 +5816,8 @@ var BABYLON;
             matrix.invert();
             source.x = source.x / viewportWidth * 2 - 1;
             source.y = -(source.y / viewportHeight * 2 - 1);
-            var vector = Vector3.TransformCoordinates(source, matrix);
-            var m = matrix.m;
-            var num = source.x * m[3] + source.y * m[7] + source.z * m[11] + m[15];
-            if (BABYLON.Scalar.WithinEpsilon(num, 1.0)) {
-                vector = vector.scale(1.0 / num);
-            }
+            var vector = new Vector3();
+            Vector3.UnprojectFromInvertedMatrixToRef(source, matrix, vector);
             return vector;
         };
         /**
@@ -5864,12 +5869,36 @@ var BABYLON;
             screenSource.x = sourceX / viewportWidth * 2 - 1;
             screenSource.y = -(sourceY / viewportHeight * 2 - 1);
             screenSource.z = 2 * sourceZ - 1.0;
-            Vector3.TransformCoordinatesToRef(screenSource, matrix, result);
-            var m = matrix.m;
-            var num = screenSource.x * m[3] + screenSource.y * m[7] + screenSource.z * m[11] + m[15];
-            if (BABYLON.Scalar.WithinEpsilon(num, 1.0)) {
-                result.scaleInPlace(1.0 / num);
-            }
+            Vector3.UnprojectFromInvertedMatrixToRef(screenSource, matrix, result);
+        };
+        /**
+          * Unproject a ray from screen space to object space
+          * @param sourceX defines the screen space x coordinate to use
+          * @param sourceY defines the screen space y coordinate to use
+          * @param viewportWidth defines the current width of the viewport
+          * @param viewportHeight defines the current height of the viewport
+          * @param world defines the world matrix to use (can be set to Identity to go to world space)
+          * @param view defines the view matrix to use
+          * @param projection defines the projection matrix to use
+          * @param ray defines the Ray where to store the result
+          */
+        Vector3.UnprojectRayToRef = function (sourceX, sourceY, viewportWidth, viewportHeight, world, view, projection, ray) {
+            var matrix = MathTmp.Matrix[0];
+            world.multiplyToRef(view, matrix);
+            matrix.multiplyToRef(projection, matrix);
+            matrix.invert();
+            var nearScreenSource = MathTmp.Vector3[0];
+            nearScreenSource.x = sourceX / viewportWidth * 2 - 1;
+            nearScreenSource.y = -(sourceY / viewportHeight * 2 - 1);
+            nearScreenSource.z = -1.0;
+            var farScreenSource = MathTmp.Vector3[1].copyFromFloats(nearScreenSource.x, nearScreenSource.y, 1.0);
+            var nearVec3 = MathTmp.Vector3[2];
+            var farVec3 = MathTmp.Vector3[3];
+            Vector3.UnprojectFromInvertedMatrixToRef(nearScreenSource, matrix, nearVec3);
+            Vector3.UnprojectFromInvertedMatrixToRef(farScreenSource, matrix, farVec3);
+            ray.origin.copyFrom(nearVec3);
+            farVec3.subtractToRef(nearVec3, ray.direction);
+            ray.direction.normalize();
         };
         /**
          * Gets the minimal coordinate values between two Vector3
@@ -25563,6 +25592,10 @@ var BABYLON;
             */
             _this.onAfterStepObservable = new BABYLON.Observable();
             /**
+             * An event triggered when the activeCamera property is updated
+             */
+            _this.onActiveCameraChanged = new BABYLON.Observable();
+            /**
              * This Observable will be triggered before rendering each renderingGroup of each rendered camera.
              * The RenderinGroupInfo class contains all the information about the context in which the observable is called
              * If you wish to register an Observer only for a given set of renderingGroup, use the mask with a combination of the renderingGroup index elevated to the power of two (1 for renderingGroup 0, 2 for renderingrOup1, 4 for 2 and 8 for 3)
@@ -26201,6 +26234,21 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(Scene.prototype, "activeCamera", {
+            /** Gets or sets the current active camera */
+            get: function () {
+                return this._activeCamera;
+            },
+            set: function (value) {
+                if (value === this._activeCamera) {
+                    return;
+                }
+                this._activeCamera = value;
+                this.onActiveCameraChanged.notifyObservers(this);
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(Scene.prototype, "defaultMaterial", {
             /** The default material used on meshes when no material is affected */
             get: function () {
@@ -26995,6 +27043,7 @@ var BABYLON;
                     canvas.focus();
                 }
                 _this._initClickEvent(_this.onPrePointerObservable, _this.onPointerObservable, evt, function (clickInfo, pickResult) {
+                    _this._pointerCaptures[evt.pointerId] = false;
                     // PreObservable support
                     if (_this.onPrePointerObservable.hasObservers()) {
                         if (!clickInfo.ignore) {
@@ -27018,7 +27067,6 @@ var BABYLON;
                     if (!_this.cameraToUseForPointers && !_this.activeCamera) {
                         return;
                     }
-                    _this._pointerCaptures[evt.pointerId] = false;
                     if (!_this.pointerUpPredicate) {
                         _this.pointerUpPredicate = function (mesh) {
                             return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.isEnabled();
@@ -29390,6 +29438,7 @@ var BABYLON;
             this.onPointerObservable.clear();
             this.onPreKeyboardObservable.clear();
             this.onKeyboardObservable.clear();
+            this.onActiveCameraChanged.clear();
             this.detachControl();
             // Detach cameras
             var canvas = this._engine.getRenderingCanvas();
@@ -29563,7 +29612,7 @@ var BABYLON;
             // Moving coordinates to local viewport world
             x = x / this._engine.getHardwareScalingLevel() - viewport.x;
             y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);
-            result.update(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), cameraViewSpace ? BABYLON.Matrix.Identity() : camera.getViewMatrix(), camera.getProjectionMatrix());
+            result.update(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.IdentityReadOnly, cameraViewSpace ? BABYLON.Matrix.IdentityReadOnly : camera.getViewMatrix(), camera.getProjectionMatrix());
             return this;
         };
         /**
@@ -58734,8 +58783,8 @@ var BABYLON;
          */
         Ray.prototype.intersectsBoxMinMax = function (minimum, maximum, intersectionTreshold) {
             if (intersectionTreshold === void 0) { intersectionTreshold = 0; }
-            var newMinimum = Ray._min.copyFromFloats(minimum.x - intersectionTreshold, minimum.y - intersectionTreshold, minimum.z - intersectionTreshold);
-            var newMaximum = Ray._max.copyFromFloats(maximum.x + intersectionTreshold, maximum.y + intersectionTreshold, maximum.z + intersectionTreshold);
+            var newMinimum = Ray.TmpVector3[0].copyFromFloats(minimum.x - intersectionTreshold, minimum.y - intersectionTreshold, minimum.z - intersectionTreshold);
+            var newMaximum = Ray.TmpVector3[1].copyFromFloats(maximum.x + intersectionTreshold, maximum.y + intersectionTreshold, maximum.z + intersectionTreshold);
             var d = 0.0;
             var maxValue = Number.MAX_VALUE;
             var inv;
@@ -58855,26 +58904,31 @@ var BABYLON;
          * @returns intersection information if hit
          */
         Ray.prototype.intersectsTriangle = function (vertex0, vertex1, vertex2) {
-            vertex1.subtractToRef(vertex0, Ray._edge1);
-            vertex2.subtractToRef(vertex0, Ray._edge2);
-            BABYLON.Vector3.CrossToRef(this.direction, Ray._edge2, Ray._pvec);
-            var det = BABYLON.Vector3.Dot(Ray._edge1, Ray._pvec);
+            var edge1 = Ray.TmpVector3[0];
+            var edge2 = Ray.TmpVector3[1];
+            var pvec = Ray.TmpVector3[2];
+            var tvec = Ray.TmpVector3[3];
+            var qvec = Ray.TmpVector3[4];
+            vertex1.subtractToRef(vertex0, edge1);
+            vertex2.subtractToRef(vertex0, edge2);
+            BABYLON.Vector3.CrossToRef(this.direction, edge2, pvec);
+            var det = BABYLON.Vector3.Dot(edge1, pvec);
             if (det === 0) {
                 return null;
             }
             var invdet = 1 / det;
-            this.origin.subtractToRef(vertex0, Ray._tvec);
-            var bu = BABYLON.Vector3.Dot(Ray._tvec, Ray._pvec) * invdet;
+            this.origin.subtractToRef(vertex0, tvec);
+            var bu = BABYLON.Vector3.Dot(tvec, pvec) * invdet;
             if (bu < 0 || bu > 1.0) {
                 return null;
             }
-            BABYLON.Vector3.CrossToRef(Ray._tvec, Ray._edge1, Ray._qvec);
-            var bv = BABYLON.Vector3.Dot(this.direction, Ray._qvec) * invdet;
+            BABYLON.Vector3.CrossToRef(tvec, edge1, qvec);
+            var bv = BABYLON.Vector3.Dot(this.direction, 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(Ray._edge2, Ray._qvec) * invdet;
+            var distance = BABYLON.Vector3.Dot(edge2, qvec) * invdet;
             if (distance > this.length) {
                 return null;
             }
@@ -58964,10 +59018,15 @@ var BABYLON;
          * @return the distance from the ray origin to the intersection point if there's intersection, or -1 if there's no intersection
          */
         Ray.prototype.intersectionSegment = function (sega, segb, threshold) {
-            var rsegb = this.origin.add(this.direction.multiplyByFloats(Ray.rayl, Ray.rayl, Ray.rayl));
-            var u = segb.subtract(sega);
-            var v = rsegb.subtract(this.origin);
-            var w = sega.subtract(this.origin);
+            var o = this.origin;
+            var u = BABYLON.Tmp.Vector3[0];
+            var rsegb = BABYLON.Tmp.Vector3[1];
+            var v = BABYLON.Tmp.Vector3[2];
+            var w = BABYLON.Tmp.Vector3[3];
+            segb.subtractToRef(sega, u);
+            this.direction.scaleToRef(Ray.rayl, v);
+            o.addToRef(v, rsegb);
+            sega.subtractToRef(o, w);
             var a = BABYLON.Vector3.Dot(u, u); // always >= 0
             var b = BABYLON.Vector3.Dot(u, v);
             var c = BABYLON.Vector3.Dot(v, v); // always >= 0
@@ -59029,8 +59088,11 @@ var BABYLON;
             sc = (Math.abs(sN) < Ray.smallnum ? 0.0 : sN / sD);
             tc = (Math.abs(tN) < Ray.smallnum ? 0.0 : tN / tD);
             // get the difference of the two closest points
-            var qtc = v.multiplyByFloats(tc, tc, tc);
-            var dP = w.add(u.multiplyByFloats(sc, sc, sc)).subtract(qtc); // = S1(sc) - S2(tc)
+            var qtc = BABYLON.Tmp.Vector3[4];
+            v.scaleToRef(tc, qtc);
+            var dP = BABYLON.Tmp.Vector3[5];
+            u.scaleToRef(sc, dP);
+            dP.addInPlace(w).subtractInPlace(qtc); // = S1(sc) - S2(tc)
             var isIntersected = (tc > 0) && (tc <= this.length) && (dP.lengthSquared() < (threshold * threshold)); // return intersection result
             if (isIntersected) {
                 return qtc.length();
@@ -59049,10 +59111,7 @@ var BABYLON;
          * @returns this ray updated
          */
         Ray.prototype.update = function (x, y, viewportWidth, viewportHeight, world, view, projection) {
-            BABYLON.Vector3.UnprojectFloatsToRef(x, y, 0, viewportWidth, viewportHeight, world, view, projection, this.origin);
-            BABYLON.Vector3.UnprojectFloatsToRef(x, y, 1, viewportWidth, viewportHeight, world, view, projection, BABYLON.Tmp.Vector3[0]);
-            BABYLON.Tmp.Vector3[0].subtractToRef(this.origin, this.direction);
-            this.direction.normalize();
+            BABYLON.Vector3.UnprojectRayToRef(x, y, viewportWidth, viewportHeight, world, view, projection, this);
             return this;
         };
         // Statics
@@ -59124,13 +59183,7 @@ var BABYLON;
                 result.length *= len;
             }
         };
-        Ray._edge1 = BABYLON.Vector3.Zero();
-        Ray._edge2 = BABYLON.Vector3.Zero();
-        Ray._pvec = BABYLON.Vector3.Zero();
-        Ray._tvec = BABYLON.Vector3.Zero();
-        Ray._qvec = BABYLON.Vector3.Zero();
-        Ray._min = BABYLON.Vector3.Zero();
-        Ray._max = BABYLON.Vector3.Zero();
+        Ray.TmpVector3 = BABYLON.Tools.BuildArray(6, BABYLON.Vector3.Zero);
         Ray.smallnum = 0.00000001;
         Ray.rayl = 10e8;
         return Ray;

+ 1 - 1
dist/preview release/gui/babylon.gui.d.ts

@@ -1484,7 +1484,7 @@ declare module BABYLON.GUI {
                 */
             keepsFocusWith(): BABYLON.Nullable<Control[]>;
             /** @hidden */
-            processKey(keyCode: number, key?: string): void;
+            processKey(keyCode: number, key?: string, evt?: KeyboardEvent): void;
             /** @hidden */
             processKeyboard(evt: KeyboardEvent): void;
             _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;

文件差异内容过多而无法显示
+ 1 - 1
dist/preview release/gui/babylon.gui.js


文件差异内容过多而无法显示
+ 1 - 1
dist/preview release/gui/babylon.gui.min.js


文件差异内容过多而无法显示
+ 1 - 1
dist/preview release/gui/babylon.gui.min.js.map


+ 2 - 2
dist/preview release/gui/babylon.gui.module.d.ts

@@ -1609,7 +1609,7 @@ declare module 'babylonjs-gui/2D/controls/inputText' {
                 */
             keepsFocusWith(): Nullable<Control[]>;
             /** @hidden */
-            processKey(keyCode: number, key?: string): void;
+            processKey(keyCode: number, key?: string, evt?: KeyboardEvent): void;
             /** @hidden */
             processKeyboard(evt: KeyboardEvent): void;
             _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -4428,7 +4428,7 @@ declare module BABYLON.GUI {
                 */
             keepsFocusWith(): BABYLON.Nullable<Control[]>;
             /** @hidden */
-            processKey(keyCode: number, key?: string): void;
+            processKey(keyCode: number, key?: string, evt?: KeyboardEvent): void;
             /** @hidden */
             processKeyboard(evt: KeyboardEvent): void;
             _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;

+ 0 - 7
dist/preview release/viewer/babylon.viewer.d.ts

@@ -1710,13 +1710,6 @@ declare module BabylonViewer {
     }
 }
 declare module BabylonViewer {
-    /**
-      * Force-apply material configuration right after a material was loaded.
-      */
-    export class ApplyMaterialConfigPlugin implements ILoaderPlugin {
-        onInit(loader: BABYLON.ISceneLoaderPlugin | BABYLON.ISceneLoaderPluginAsync, model: ViewerModel): void;
-        onMaterialLoaded(material: BABYLON.Material): void;
-    }
 }
 declare module BabylonViewer {
     /**

文件差异内容过多而无法显示
+ 1 - 1
dist/preview release/viewer/babylon.viewer.js


文件差异内容过多而无法显示
+ 1 - 1
dist/preview release/viewer/babylon.viewer.max.js


+ 1 - 10
dist/preview release/viewer/babylon.viewer.module.d.ts

@@ -1847,16 +1847,7 @@ declare module 'babylonjs-viewer/loader/plugins/msftLodLoaderPlugin' {
 }
 
 declare module 'babylonjs-viewer/loader/plugins/applyMaterialConfig' {
-    import { ISceneLoaderPlugin, ISceneLoaderPluginAsync, Material } from 'babylonjs';
-    import { ViewerModel } from 'babylonjs-viewer/model/viewerModel';
-    import { ILoaderPlugin } from 'babylonjs-viewer/loader/plugins/loaderPlugin';
-    /**
-      * Force-apply material configuration right after a material was loaded.
-      */
-    export class ApplyMaterialConfigPlugin implements ILoaderPlugin {
-        onInit(loader: ISceneLoaderPlugin | ISceneLoaderPluginAsync, model: ViewerModel): void;
-        onMaterialLoaded(material: Material): void;
-    }
+    
 }
 
 declare module 'babylonjs-viewer/loader/plugins/extendedMaterialLoaderPlugin' {

+ 21 - 2
src/babylon.scene.ts

@@ -507,6 +507,11 @@ module BABYLON {
         public onAfterStepObservable = new Observable<Scene>();
 
         /**
+         * An event triggered when the activeCamera property is updated
+         */
+        public onActiveCameraChanged = new Observable<Scene>();
+
+        /**
          * This Observable will be triggered before rendering each renderingGroup of each rendered camera.
          * The RenderinGroupInfo class contains all the information about the context in which the observable is called
          * If you wish to register an Observer only for a given set of renderingGroup, use the mask with a combination of the renderingGroup index elevated to the power of two (1 for renderingGroup 0, 2 for renderingrOup1, 4 for 2 and 8 for 3)
@@ -776,8 +781,21 @@ module BABYLON {
 
         /** All of the active cameras added to this scene. */
         public activeCameras = new Array<Camera>();
-        /** The current active camera */
-        public activeCamera: Nullable<Camera>;
+
+        private _activeCamera: Nullable<Camera>;
+        /** Gets or sets the current active camera */
+        public get activeCamera(): Nullable<Camera> {
+            return this._activeCamera;
+        }
+
+        public set activeCamera(value: Nullable<Camera>) {
+            if (value === this._activeCamera) {
+                return;
+            }
+
+            this._activeCamera = value;
+            this.onActiveCameraChanged.notifyObservers(this);
+        }
 
         private _defaultMaterial: Material;
 
@@ -4796,6 +4814,7 @@ module BABYLON {
             this.onPointerObservable.clear();
             this.onPreKeyboardObservable.clear();
             this.onKeyboardObservable.clear();
+            this.onActiveCameraChanged.clear();
 
             this.detachControl();