Browse Source

Fixed bug with rig cameras target and position

David Catuhe 10 năm trước cách đây
mục cha
commit
614038b3c0

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/preview release - alpha/babylon.2.2.js


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

@@ -9844,10 +9844,10 @@ var BABYLON;
         Camera.prototype.detachControl = function (element) {
         };
         Camera.prototype._update = function () {
-            this._checkInputs();
             if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {
                 this._updateRigCameras();
             }
+            this._checkInputs();
         };
         Camera.prototype._checkInputs = function () {
         };
@@ -10312,11 +10312,11 @@ var BABYLON;
                         camRight.position.copyFrom(this.position);
                     }
                     else {
-                        camLeft.setTarget(this.getTarget());
-                        camRight.setTarget(this.getTarget());
                         //provisionnaly using _cameraRigParams.stereoHalfAngle instead of calculations based on _cameraRigParams.interaxialDistance:
                         this._getRigCamPosition(-this._cameraRigParams.stereoHalfAngle, camLeft.position);
                         this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle, camRight.position);
+                        camLeft.setTarget(this.getTarget());
+                        camRight.setTarget(this.getTarget());
                     }
                     break;
             }

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/preview release - alpha/babylon.2.2.noworker.js


+ 1 - 1
src/Cameras/babylon.camera.js

@@ -272,10 +272,10 @@ var BABYLON;
         Camera.prototype.detachControl = function (element) {
         };
         Camera.prototype._update = function () {
-            this._checkInputs();
             if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {
                 this._updateRigCameras();
             }
+            this._checkInputs();
         };
         Camera.prototype._checkInputs = function () {
         };

+ 16 - 16
src/Cameras/babylon.camera.ts

@@ -73,7 +73,7 @@
         private static _FOVMODE_VERTICAL_FIXED = 0;
         private static _FOVMODE_HORIZONTAL_FIXED = 1;
 
-        private static _RIG_MODE_NONE = 0;        
+        private static _RIG_MODE_NONE = 0;
         private static _RIG_MODE_STEREOSCOPIC_ANAGLYPH = 10;
         private static _RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL = 11;
         private static _RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED = 12;
@@ -107,14 +107,14 @@
         public static get RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL(): number {
             return Camera._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL;
         }
-        
+
         public static get RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED(): number {
             return Camera._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED;
         }
 
         public static get RIG_MODE_STEREOSCOPIC_OVERUNDER(): number {
             return Camera._RIG_MODE_STEREOSCOPIC_OVERUNDER;
-        }        
+        }
 
         public static get RIG_MODE_VR(): number {
             return Camera._RIG_MODE_VR;
@@ -275,10 +275,10 @@
         }
 
         public _update(): void {
-            this._checkInputs();
             if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {
                 this._updateRigCameras();
             }
+            this._checkInputs();
         }
 
         public _checkInputs(): void {
@@ -471,7 +471,7 @@
             }
             this.cameraRigMode = mode;
             this._cameraRigParams = {};
-        
+
             switch (this.cameraRigMode) {
                 case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:
                 case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:
@@ -481,14 +481,14 @@
                     //we have to implement stereo camera calcultating left and right viewpoints from interaxialDistance and target, 
                     //not from a given angle as it is now, but until that complete code rewriting provisional stereoHalfAngle value is introduced
                     this._cameraRigParams.stereoHalfAngle = Tools.ToRadians(this._cameraRigParams.interaxialDistance / 0.0637);
-                    
+
                     this._rigCameras.push(this.createRigCamera(this.name + "_L", 0));
                     this._rigCameras.push(this.createRigCamera(this.name + "_R", 1));
-                break;
+                    break;
             }
-            
+
             var postProcesses = new Array<PostProcess>();
-            
+
             switch (this.cameraRigMode) {
                 case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:
                     postProcesses.push(new PassPostProcess(this.name + "_passthru", 1.0, this._rigCameras[0]));
@@ -504,9 +504,9 @@
                 case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:
                 case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:
                     var isStereoscopicHoriz = (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL || this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED);
-                    var firstCamIndex = (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED)? 1 : 0;
+                    var firstCamIndex = (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED) ? 1 : 0;
                     var secondCamIndex = 1 - firstCamIndex;
-                    
+
                     postProcesses.push(new PassPostProcess(this.name + "_passthru", 1.0, this._rigCameras[firstCamIndex]));
                     this._rigCameras[firstCamIndex].isIntermediate = true;
 
@@ -516,7 +516,7 @@
                 case Camera.RIG_MODE_VR:
                     this._rigCameras.push(this.createRigCamera(this.name + "_L", 0));
                     this._rigCameras.push(this.createRigCamera(this.name + "_R", 1));
-                    
+
                     var metrics = rigParams.vrCameraMetrics || VRCameraMetrics.GetDefault();
                     this._rigCameras[0]._cameraRigParams.vrMetrics = metrics;
                     this._rigCameras[0].viewport = new Viewport(0, 0, 0.5, 1.0);
@@ -543,7 +543,7 @@
                     }
                     break;
             }
-            
+
             this._update();
         }
 
@@ -556,8 +556,8 @@
         public setCameraRigParameter(name: string, value: any) {
             this._cameraRigParams[name] = value;
             //provisionnally:
-            if (name === "interaxialDistance") { 
-		this._cameraRigParams.stereoHalfAngle = Tools.ToRadians(value / 0.0637); 
+            if (name === "interaxialDistance") {
+                this._cameraRigParams.stereoHalfAngle = Tools.ToRadians(value / 0.0637);
             }
         }
         
@@ -572,7 +572,7 @@
          * May needs to be overridden by children
          */
         public _updateRigCameras() {
-            for (var i=0 ; i<this._rigCameras.length ; i++) {
+            for (var i = 0; i < this._rigCameras.length; i++) {
                 this._rigCameras[i].minZ = this.minZ;
                 this._rigCameras[i].maxZ = this.maxZ;
                 this._rigCameras[i].fov = this.fov;

+ 2 - 2
src/Cameras/babylon.targetCamera.js

@@ -216,11 +216,11 @@ var BABYLON;
                         camRight.position.copyFrom(this.position);
                     }
                     else {
-                        camLeft.setTarget(this.getTarget());
-                        camRight.setTarget(this.getTarget());
                         //provisionnaly using _cameraRigParams.stereoHalfAngle instead of calculations based on _cameraRigParams.interaxialDistance:
                         this._getRigCamPosition(-this._cameraRigParams.stereoHalfAngle, camLeft.position);
                         this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle, camRight.position);
+                        camLeft.setTarget(this.getTarget());
+                        camRight.setTarget(this.getTarget());
                     }
                     break;
             }

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

@@ -21,15 +21,15 @@
         public _lookAtTemp = Matrix.Zero();
         public _tempMatrix = Matrix.Zero();
 
-        public _reset:() => void;
+        public _reset: () => void;
 
-        public _waitingLockedTargetId:string;
+        public _waitingLockedTargetId: string;
 
-        constructor(name:string, position:Vector3, scene:Scene) {
+        constructor(name: string, position: Vector3, scene: Scene) {
             super(name, position, scene);
         }
 
-        public _getLockedTargetPosition():Vector3 {
+        public _getLockedTargetPosition(): Vector3 {
             if (!this.lockedTarget) {
                 return null;
             }
@@ -44,7 +44,7 @@
             this._cache.rotation = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
         }
 
-        public _updateCache(ignoreParentClass?:boolean):void {
+        public _updateCache(ignoreParentClass?: boolean): void {
             if (!ignoreParentClass) {
                 super._updateCache();
             }
@@ -66,7 +66,7 @@
         }
 
         // Synchronized
-        public _isSynchronizedViewMatrix():boolean {
+        public _isSynchronizedViewMatrix(): boolean {
             if (!super._isSynchronizedViewMatrix()) {
                 return false;
             }
@@ -84,7 +84,7 @@
         }
 
         // Target
-        public setTarget(target:Vector3):void {
+        public setTarget(target: Vector3): void {
             this.upVector.normalize();
 
             Matrix.LookAtLHToRef(this.position, target, this.upVector, this._camMatrix);
@@ -115,19 +115,19 @@
             }
         }
 
-        public getTarget():Vector3 {
+        public getTarget(): Vector3 {
             return this._currentTarget;
         }
 
 
-        public _decideIfNeedsToMove():boolean {
+        public _decideIfNeedsToMove(): boolean {
             return Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;
         }
 
-        public _updatePosition():void{
+        public _updatePosition(): void {
             this.position.addInPlace(this.cameraDirection);
         }
-        public _checkInputs():void {
+        public _checkInputs(): void {
             var needToMove = this._decideIfNeedsToMove();
             var needToRotate = Math.abs(this.cameraRotation.x) > 0 || Math.abs(this.cameraRotation.y) > 0;
 
@@ -184,7 +184,7 @@
         }
 
 
-        public _getViewMatrix():Matrix {
+        public _getViewMatrix(): Matrix {
             if (!this.lockedTarget) {
                 // Compute
                 if (this.upVector.x !== 0 || this.upVector.y !== 1.0 || this.upVector.z !== 0) {
@@ -210,7 +210,7 @@
             Matrix.LookAtLHToRef(this.position, this._currentTarget, this.upVector, this._viewMatrix);
             return this._viewMatrix;
         }
-        
+
         public _getVRViewMatrix(): Matrix {
             Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
 
@@ -247,7 +247,7 @@
          * @override
          * Override Camera._updateRigCameras
          */
-        public _updateRigCameras(){
+        public _updateRigCameras() {
             switch (this.cameraRigMode) {
                 case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:
                 case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:
@@ -261,25 +261,25 @@
                         camLeft.rotation.x = camRight.rotation.x = this.rotation.x;
                         camLeft.rotation.y = camRight.rotation.y = this.rotation.y;
                         camLeft.rotation.z = camRight.rotation.z = this.rotation.z;
-                        
+
                         camLeft.position.copyFrom(this.position);
                         camRight.position.copyFrom(this.position);
-                        
+
                     } else {
-                        camLeft.setTarget(this.getTarget());
-                        camRight.setTarget(this.getTarget());
-                        
                         //provisionnaly using _cameraRigParams.stereoHalfAngle instead of calculations based on _cameraRigParams.interaxialDistance:
                         this._getRigCamPosition(-this._cameraRigParams.stereoHalfAngle, camLeft.position);
-                        this._getRigCamPosition( this._cameraRigParams.stereoHalfAngle, camRight.position);
+                        this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle, camRight.position);
+
+                        camLeft.setTarget(this.getTarget());
+                        camRight.setTarget(this.getTarget());
                     }
                     break;
             }
             super._updateRigCameras();
         }
-        
+
         private _getRigCamPosition(halfSpace: number, result: Vector3) {
-            if (!this._rigCamTransformMatrix){
+            if (!this._rigCamTransformMatrix) {
                 this._rigCamTransformMatrix = new Matrix();
             }
             var target = this.getTarget();