瀏覽代碼

Cross Eye support for 180 and fixing wrong offset in 180 mode
Closing #8897

Raanan Weber 4 年之前
父節點
當前提交
a27bf0bc79
共有 1 個文件被更改,包括 35 次插入4 次删除
  1. 35 4
      src/Helpers/textureDome.ts

+ 35 - 4
src/Helpers/textureDome.ts

@@ -33,6 +33,7 @@ export abstract class TextureDome<T extends Texture> extends TransformNode {
     public static readonly MODE_SIDEBYSIDE = 2;
 
     private _halfDome: boolean = false;
+    private _crossEye: boolean = false;
 
     protected _useDirectMapping = false;
 
@@ -111,7 +112,7 @@ export abstract class TextureDome<T extends Texture> extends TransformNode {
     }
     /**
      * Sets the current texture mode for the texture. It can be:
-      * * TextureDome.MODE_MONOSCOPIC : Define the texture source as a Monoscopic panoramic 360.
+     * * TextureDome.MODE_MONOSCOPIC : Define the texture source as a Monoscopic panoramic 360.
      * * TextureDome.MODE_TOPBOTTOM  : Define the texture source as a Stereoscopic TopBottom/OverUnder panoramic 360.
      * * TextureDome.MODE_SIDEBYSIDE : Define the texture source as a Stereoscopic Side by Side panoramic 360.
      */
@@ -139,6 +140,20 @@ export abstract class TextureDome<T extends Texture> extends TransformNode {
     }
 
     /**
+     * Set the cross-eye mode. If set, images that can be seen when crossing eyes will render correctly
+     */
+    public set crossEye(enabled: boolean) {
+        this._crossEye = enabled;
+    }
+
+    /**
+     * Is it a cross-eye texture?
+     */
+    public get crossEye(): boolean {
+        return this._crossEye;
+    }
+
+    /**
      * Oberserver used in Stereoscopic VR Mode.
      */
     private _onBeforeCameraRenderObserver: Nullable<Observer<Camera>> = null;
@@ -166,6 +181,8 @@ export abstract class TextureDome<T extends Texture> extends TransformNode {
             faceForward?: boolean;
             useDirectMapping?: boolean;
             halfDomeMode?: boolean;
+            noMipMap?: boolean;
+            crossEyeMode?: boolean;
         },
         scene: Scene,
         protected onError: Nullable<(message?: string, exception?: any) => void> = null
@@ -247,6 +264,7 @@ export abstract class TextureDome<T extends Texture> extends TransformNode {
         this._texture.vScale = 1;
         this._texture.uOffset = 0;
         this._texture.vOffset = 0;
+        this._texture.vAng = 0;
 
         switch (value) {
             case TextureDome.MODE_MONOSCOPIC:
@@ -260,9 +278,17 @@ export abstract class TextureDome<T extends Texture> extends TransformNode {
                 // Use 0.99999 to boost perf by not switching program
                 this._texture.uScale = this._halfDome ? 0.99999 : 0.5;
                 const rightOffset = this._halfDome ? 0.0 : 0.5;
-                const leftOffset = this._halfDome ? 0.5 : 0.0;
+                const leftOffset = this._halfDome ? -0.5 : 0.0;
                 this._onBeforeCameraRenderObserver = this._scene.onBeforeCameraRenderObservable.add((camera) => {
-                    this._texture.uOffset = camera.isRightCamera ? rightOffset : leftOffset;
+                    let isRightCamera = camera.isRightCamera;
+                    if (this._crossEye) {
+                        isRightCamera = !isRightCamera;
+                    }
+                    if (isRightCamera) {
+                        this._texture.uOffset = rightOffset;
+                    } else {
+                        this._texture.uOffset = leftOffset;
+                    }
                 });
                 break;
             case TextureDome.MODE_TOPBOTTOM:
@@ -270,7 +296,12 @@ export abstract class TextureDome<T extends Texture> extends TransformNode {
                 // Use 0.99999 to boost perf by not switching program
                 this._texture.vScale = this._halfDome ? 0.99999 : 0.5;
                 this._onBeforeCameraRenderObserver = this._scene.onBeforeCameraRenderObservable.add((camera) => {
-                    this._texture.vOffset = camera.isRightCamera ? 0.5 : 0.0;
+                    let isRightCamera = camera.isRightCamera;
+                    // allow "cross-eye" if left and right were switched in this mode
+                    if (this._crossEye) {
+                        isRightCamera = !isRightCamera;
+                    }
+                    this._texture.vOffset = isRightCamera ? 0.5 : 0.0;
                 });
                 break;
         }