David Catuhe 10 gadi atpakaļ
vecāks
revīzija
c8400bee98

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 23 - 18
dist/preview release - alpha/babylon.2.2.js


+ 19 - 10
dist/preview release - alpha/babylon.2.2.max.js

@@ -8744,6 +8744,7 @@ var BABYLON;
             this.blurScale = 2;
             this._blurBoxOffset = 0;
             this._bias = 0.00005;
+            this._lightDirection = BABYLON.Vector3.Zero();
             this._darkness = 0;
             this._transparencyShadow = false;
             this._viewMatrix = BABYLON.Matrix.Zero();
@@ -9013,14 +9014,17 @@ var BABYLON;
             }
             this._currentRenderID = scene.getRenderId();
             var lightPosition = this._light.position;
-            var lightDirection = this._light.direction;
+            BABYLON.Vector3.NormalizeToRef(this._light.direction, this._lightDirection);
+            if (Math.abs(BABYLON.Vector3.Dot(this._lightDirection, BABYLON.Vector3.Up())) == 1.0) {
+                this._lightDirection.z = 0.0000000000001; // Need to avoid perfectly perpendicular light
+            }
             if (this._light.computeTransformedPosition()) {
                 lightPosition = this._light.transformedPosition;
             }
-            if (this._light.needRefreshPerFrame() || !this._cachedPosition || !this._cachedDirection || !lightPosition.equals(this._cachedPosition) || !lightDirection.equals(this._cachedDirection)) {
+            if (this._light.needRefreshPerFrame() || !this._cachedPosition || !this._cachedDirection || !lightPosition.equals(this._cachedPosition) || !this._lightDirection.equals(this._cachedDirection)) {
                 this._cachedPosition = lightPosition.clone();
-                this._cachedDirection = lightDirection.clone();
-                BABYLON.Matrix.LookAtLHToRef(lightPosition, this._light.position.add(lightDirection), BABYLON.Vector3.Up(), this._viewMatrix);
+                this._cachedDirection = this._lightDirection.clone();
+                BABYLON.Matrix.LookAtLHToRef(lightPosition, this._light.position.add(this._lightDirection), BABYLON.Vector3.Up(), this._viewMatrix);
                 this._light.setShadowProjectionMatrix(this._projectionMatrix, this._viewMatrix, this.getShadowMap().renderList);
                 this._viewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);
             }
@@ -10785,6 +10789,7 @@ var BABYLON;
             this.angularSensibility = 1000.0;
             this.wheelPrecision = 3.0;
             this.pinchPrecision = 2.0;
+            this.panningSensibility = 0.1;
             this.keysUp = [38];
             this.keysDown = [40];
             this.keysLeft = [37];
@@ -10924,8 +10929,8 @@ var BABYLON;
                                     _this._localDirection = BABYLON.Vector3.Zero();
                                     _this._transformedDirection = BABYLON.Vector3.Zero();
                                 }
-                                var diffx = (evt.clientX - _this._lastPanningPosition.x) * 0.1;
-                                var diffy = (evt.clientY - _this._lastPanningPosition.y) * 0.1;
+                                var diffx = (evt.clientX - _this._lastPanningPosition.x) * _this.panningSensibility;
+                                var diffy = (evt.clientY - _this._lastPanningPosition.y) * _this.panningSensibility;
                                 _this._localDirection.copyFromFloats(-diffx, diffy, 0);
                                 _this._viewMatrix.invertToRef(_this._cameraTransformMatrix);
                                 BABYLON.Vector3.TransformNormalToRef(_this._localDirection, _this._cameraTransformMatrix, _this._transformedDirection);
@@ -11219,14 +11224,16 @@ var BABYLON;
             }
             return this._viewMatrix;
         };
-        ArcRotateCamera.prototype.zoomOn = function (meshes) {
+        ArcRotateCamera.prototype.zoomOn = function (meshes, doNotUpdateMaxZ) {
+            if (doNotUpdateMaxZ === void 0) { doNotUpdateMaxZ = false; }
             meshes = meshes || this.getScene().meshes;
             var minMaxVector = BABYLON.Mesh.MinMax(meshes);
             var distance = BABYLON.Vector3.Distance(minMaxVector.min, minMaxVector.max);
             this.radius = distance * this.zoomOnFactor;
-            this.focusOn({ min: minMaxVector.min, max: minMaxVector.max, distance: distance });
+            this.focusOn({ min: minMaxVector.min, max: minMaxVector.max, distance: distance }, doNotUpdateMaxZ);
         };
-        ArcRotateCamera.prototype.focusOn = function (meshesOrMinMaxVectorAndDistance) {
+        ArcRotateCamera.prototype.focusOn = function (meshesOrMinMaxVectorAndDistance, doNotUpdateMaxZ) {
+            if (doNotUpdateMaxZ === void 0) { doNotUpdateMaxZ = false; }
             var meshesOrMinMaxVector;
             var distance;
             if (meshesOrMinMaxVectorAndDistance.min === undefined) {
@@ -11239,7 +11246,9 @@ var BABYLON;
                 distance = meshesOrMinMaxVectorAndDistance.distance;
             }
             this.target = BABYLON.Mesh.Center(meshesOrMinMaxVector);
-            this.maxZ = distance * 2;
+            if (!doNotUpdateMaxZ) {
+                this.maxZ = distance * 2;
+            }
         };
         /**
          * @override

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 23 - 18
dist/preview release - alpha/babylon.2.2.noworker.js


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

@@ -3,6 +3,7 @@
     - Meshes can now be attached to bones. See [documentation here](http://babylondoc.azurewebsites.net/page.php?p=22421) and [sample here](http://www.babylonjs-playground.com/#11BH6Z#18) [deltakosh](https://github.com/deltakosh)
     - HDR Rendering pipeline. See [demo here]() [julien-moreau](https://github.com/julien-moreau)
   - **Updates**
+    - New parameter for ArcRotateCamera.zoomOn to preserve maxZ [deltakosh](https://github.com/deltakosh)
     - PickingInfo.getNormal can now use either vertices normals or vertices positions [deltakosh](https://github.com/deltakosh)
     - Meshes can now support uv2, uv4, uv5 and uv6 for ShaderMaterials [deltakosh](https://github.com/deltakosh)
     - Panning support for ArcRotateCamera [julien-moreau](https://github.com/julien-moreau)

+ 11 - 6
src/Cameras/babylon.arcRotateCamera.js

@@ -28,6 +28,7 @@ var BABYLON;
             this.angularSensibility = 1000.0;
             this.wheelPrecision = 3.0;
             this.pinchPrecision = 2.0;
+            this.panningSensibility = 0.1;
             this.keysUp = [38];
             this.keysDown = [40];
             this.keysLeft = [37];
@@ -167,8 +168,8 @@ var BABYLON;
                                     _this._localDirection = BABYLON.Vector3.Zero();
                                     _this._transformedDirection = BABYLON.Vector3.Zero();
                                 }
-                                var diffx = (evt.clientX - _this._lastPanningPosition.x) * 0.1;
-                                var diffy = (evt.clientY - _this._lastPanningPosition.y) * 0.1;
+                                var diffx = (evt.clientX - _this._lastPanningPosition.x) * _this.panningSensibility;
+                                var diffy = (evt.clientY - _this._lastPanningPosition.y) * _this.panningSensibility;
                                 _this._localDirection.copyFromFloats(-diffx, diffy, 0);
                                 _this._viewMatrix.invertToRef(_this._cameraTransformMatrix);
                                 BABYLON.Vector3.TransformNormalToRef(_this._localDirection, _this._cameraTransformMatrix, _this._transformedDirection);
@@ -462,14 +463,16 @@ var BABYLON;
             }
             return this._viewMatrix;
         };
-        ArcRotateCamera.prototype.zoomOn = function (meshes) {
+        ArcRotateCamera.prototype.zoomOn = function (meshes, doNotUpdateMaxZ) {
+            if (doNotUpdateMaxZ === void 0) { doNotUpdateMaxZ = false; }
             meshes = meshes || this.getScene().meshes;
             var minMaxVector = BABYLON.Mesh.MinMax(meshes);
             var distance = BABYLON.Vector3.Distance(minMaxVector.min, minMaxVector.max);
             this.radius = distance * this.zoomOnFactor;
-            this.focusOn({ min: minMaxVector.min, max: minMaxVector.max, distance: distance });
+            this.focusOn({ min: minMaxVector.min, max: minMaxVector.max, distance: distance }, doNotUpdateMaxZ);
         };
-        ArcRotateCamera.prototype.focusOn = function (meshesOrMinMaxVectorAndDistance) {
+        ArcRotateCamera.prototype.focusOn = function (meshesOrMinMaxVectorAndDistance, doNotUpdateMaxZ) {
+            if (doNotUpdateMaxZ === void 0) { doNotUpdateMaxZ = false; }
             var meshesOrMinMaxVector;
             var distance;
             if (meshesOrMinMaxVectorAndDistance.min === undefined) {
@@ -482,7 +485,9 @@ var BABYLON;
                 distance = meshesOrMinMaxVectorAndDistance.distance;
             }
             this.target = BABYLON.Mesh.Center(meshesOrMinMaxVector);
-            this.maxZ = distance * 2;
+            if (!doNotUpdateMaxZ) {
+                this.maxZ = distance * 2;
+            }
         };
         /**
          * @override

+ 9 - 6
src/Cameras/babylon.arcRotateCamera.ts

@@ -14,6 +14,7 @@
         public angularSensibility = 1000.0;
         public wheelPrecision = 3.0;
         public pinchPrecision = 2.0;
+        public panningSensibility: number = 0.1;
         public keysUp = [38];
         public keysDown = [40];
         public keysLeft = [37];
@@ -171,8 +172,8 @@
                                     this._transformedDirection = Vector3.Zero();
                                 }
 
-                                var diffx = (evt.clientX - this._lastPanningPosition.x) * 0.1;
-                                var diffy = (evt.clientY - this._lastPanningPosition.y) * 0.1;
+                                var diffx = (evt.clientX - this._lastPanningPosition.x) * this.panningSensibility;
+                                var diffy = (evt.clientY - this._lastPanningPosition.y) * this.panningSensibility;
 
                                 this._localDirection.copyFromFloats(-diffx, diffy, 0);
                                 this._viewMatrix.invertToRef(this._cameraTransformMatrix);
@@ -550,7 +551,7 @@
             this._collisionTriggered = false;
         }
 
-        public zoomOn(meshes?: AbstractMesh[]): void {
+        public zoomOn(meshes?: AbstractMesh[], doNotUpdateMaxZ = false): void {
             meshes = meshes || this.getScene().meshes;
 
             var minMaxVector = Mesh.MinMax(meshes);
@@ -558,10 +559,10 @@
 
             this.radius = distance * this.zoomOnFactor;
 
-            this.focusOn({ min: minMaxVector.min, max: minMaxVector.max, distance: distance });
+            this.focusOn({ min: minMaxVector.min, max: minMaxVector.max, distance: distance }, doNotUpdateMaxZ);
         }
 
-        public focusOn(meshesOrMinMaxVectorAndDistance): void {
+        public focusOn(meshesOrMinMaxVectorAndDistance, doNotUpdateMaxZ = false): void {
             var meshesOrMinMaxVector;
             var distance;
 
@@ -577,7 +578,9 @@
 
             this.target = Mesh.Center(meshesOrMinMaxVector);
 
-            this.maxZ = distance * 2;
+            if (!doNotUpdateMaxZ) {
+                this.maxZ = distance * 2;
+            }
         }
         
         /**

+ 8 - 4
src/Lights/Shadows/babylon.shadowGenerator.js

@@ -8,6 +8,7 @@ var BABYLON;
             this.blurScale = 2;
             this._blurBoxOffset = 0;
             this._bias = 0.00005;
+            this._lightDirection = BABYLON.Vector3.Zero();
             this._darkness = 0;
             this._transparencyShadow = false;
             this._viewMatrix = BABYLON.Matrix.Zero();
@@ -277,14 +278,17 @@ var BABYLON;
             }
             this._currentRenderID = scene.getRenderId();
             var lightPosition = this._light.position;
-            var lightDirection = this._light.direction;
+            BABYLON.Vector3.NormalizeToRef(this._light.direction, this._lightDirection);
+            if (Math.abs(BABYLON.Vector3.Dot(this._lightDirection, BABYLON.Vector3.Up())) == 1.0) {
+                this._lightDirection.z = 0.0000000000001; // Need to avoid perfectly perpendicular light
+            }
             if (this._light.computeTransformedPosition()) {
                 lightPosition = this._light.transformedPosition;
             }
-            if (this._light.needRefreshPerFrame() || !this._cachedPosition || !this._cachedDirection || !lightPosition.equals(this._cachedPosition) || !lightDirection.equals(this._cachedDirection)) {
+            if (this._light.needRefreshPerFrame() || !this._cachedPosition || !this._cachedDirection || !lightPosition.equals(this._cachedPosition) || !this._lightDirection.equals(this._cachedDirection)) {
                 this._cachedPosition = lightPosition.clone();
-                this._cachedDirection = lightDirection.clone();
-                BABYLON.Matrix.LookAtLHToRef(lightPosition, this._light.position.add(lightDirection), BABYLON.Vector3.Up(), this._viewMatrix);
+                this._cachedDirection = this._lightDirection.clone();
+                BABYLON.Matrix.LookAtLHToRef(lightPosition, this._light.position.add(this._lightDirection), BABYLON.Vector3.Up(), this._viewMatrix);
                 this._light.setShadowProjectionMatrix(this._projectionMatrix, this._viewMatrix, this.getShadowMap().renderList);
                 this._viewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);
             }

+ 9 - 4
src/Lights/Shadows/babylon.shadowGenerator.ts

@@ -27,6 +27,7 @@
         public blurScale = 2;
         private _blurBoxOffset = 0;
         private _bias = 0.00005;
+        private _lightDirection = Vector3.Zero();
 
         public get bias(): number {
             return this._bias;
@@ -312,18 +313,22 @@
             this._currentRenderID = scene.getRenderId();
 
             var lightPosition = this._light.position;
-            var lightDirection = this._light.direction;
+            Vector3.NormalizeToRef(this._light.direction, this._lightDirection);
 
+            if (Math.abs(Vector3.Dot(this._lightDirection, Vector3.Up())) == 1.0) {
+                this._lightDirection.z = 0.0000000000001; // Need to avoid perfectly perpendicular light
+            }
+                
             if (this._light.computeTransformedPosition()) {
                 lightPosition = this._light.transformedPosition;
             }
 
-            if (this._light.needRefreshPerFrame() || !this._cachedPosition || !this._cachedDirection || !lightPosition.equals(this._cachedPosition) || !lightDirection.equals(this._cachedDirection)) {
+            if (this._light.needRefreshPerFrame() || !this._cachedPosition || !this._cachedDirection || !lightPosition.equals(this._cachedPosition) || !this._lightDirection.equals(this._cachedDirection)) {
 
                 this._cachedPosition = lightPosition.clone();
-                this._cachedDirection = lightDirection.clone();
+                this._cachedDirection = this._lightDirection.clone();
 
-                Matrix.LookAtLHToRef(lightPosition, this._light.position.add(lightDirection), Vector3.Up(), this._viewMatrix);
+                Matrix.LookAtLHToRef(lightPosition, this._light.position.add(this._lightDirection), Vector3.Up(), this._viewMatrix);
 
                 this._light.setShadowProjectionMatrix(this._projectionMatrix, this._viewMatrix, this.getShadowMap().renderList);