Explorar o código

address comments

Trevor Baron %!s(int64=6) %!d(string=hai) anos
pai
achega
a4a5ec3030

+ 12 - 12
src/Cameras/XR/babylon.webXRCamera.ts

@@ -4,7 +4,7 @@ module BABYLON {
      * @see https://doc.babylonjs.com/how_to/webxr
      * @see https://doc.babylonjs.com/how_to/webxr
      */
      */
     export class WebXRCamera extends FreeCamera {
     export class WebXRCamera extends FreeCamera {
-        private _tmpMatrix = new BABYLON.Matrix();
+        private static _TmpMatrix = new BABYLON.Matrix();
 
 
         /**
         /**
          * Creates a new webXRCamera, this should only be set at the camera after it has been updated by the xrSessionManager
          * Creates a new webXRCamera, this should only be set at the camera after it has been updated by the xrSessionManager
@@ -42,10 +42,10 @@ module BABYLON {
             this._updateNumberOfRigCameras(2);
             this._updateNumberOfRigCameras(2);
             this.rigCameras[0].viewport = new BABYLON.Viewport(0, 0, 0.5, 1.0);
             this.rigCameras[0].viewport = new BABYLON.Viewport(0, 0, 0.5, 1.0);
             this.rigCameras[0].position.x = -pupilDistance / 2;
             this.rigCameras[0].position.x = -pupilDistance / 2;
-            this.rigCameras[0].renderTarget = null;
+            this.rigCameras[0].outputRenderTarget = null;
             this.rigCameras[1].viewport = new BABYLON.Viewport(0.5, 0, 0.5, 1.0);
             this.rigCameras[1].viewport = new BABYLON.Viewport(0.5, 0, 0.5, 1.0);
             this.rigCameras[1].position.x = pupilDistance / 2;
             this.rigCameras[1].position.x = pupilDistance / 2;
-            this.rigCameras[1].renderTarget = null;
+            this.rigCameras[1].outputRenderTarget = null;
         }
         }
 
 
         /**
         /**
@@ -53,7 +53,7 @@ module BABYLON {
          * @param xrSessionManager the session containing pose information
          * @param xrSessionManager the session containing pose information
          */
          */
         public updateFromXRSessionManager(xrSessionManager: WebXRSessionManager) {
         public updateFromXRSessionManager(xrSessionManager: WebXRSessionManager) {
-            // Ensure all frame data is availible
+            // Ensure all frame data is available
             if (!xrSessionManager._currentXRFrame || !xrSessionManager._currentXRFrame.getDevicePose) {
             if (!xrSessionManager._currentXRFrame || !xrSessionManager._currentXRFrame.getDevicePose) {
                 return;
                 return;
             }
             }
@@ -63,13 +63,13 @@ module BABYLON {
             }
             }
 
 
             // Update the parent cameras matrix
             // Update the parent cameras matrix
-            BABYLON.Matrix.FromFloat32ArrayToRefScaled(pose.poseModelMatrix, 0, 1, this._tmpMatrix);
+            BABYLON.Matrix.FromFloat32ArrayToRefScaled(pose.poseModelMatrix, 0, 1, WebXRCamera._TmpMatrix);
             if (!this._scene.useRightHandedSystem) {
             if (!this._scene.useRightHandedSystem) {
-                BABYLON.Matrix._ToggleModelMatrixHandInPlace(this._tmpMatrix);
+                WebXRCamera._TmpMatrix.toggleModelMatrixHandInPlace();
             }
             }
-            this._tmpMatrix.getTranslationToRef(this.position);
-            this._tmpMatrix.getRotationMatrixToRef(this._tmpMatrix);
-            BABYLON.Quaternion.FromRotationMatrixToRef(this._tmpMatrix, this.rotationQuaternion);
+            WebXRCamera._TmpMatrix.getTranslationToRef(this.position);
+            WebXRCamera._TmpMatrix.getRotationMatrixToRef(WebXRCamera._TmpMatrix);
+            BABYLON.Quaternion.FromRotationMatrixToRef(WebXRCamera._TmpMatrix, this.rotationQuaternion);
             this.computeWorldMatrix();
             this.computeWorldMatrix();
 
 
             // Update camera rigs
             // Update camera rigs
@@ -79,8 +79,8 @@ module BABYLON {
                 BABYLON.Matrix.FromFloat32ArrayToRefScaled(pose.getViewMatrix(view), 0, 1, this.rigCameras[i]._computedViewMatrix);
                 BABYLON.Matrix.FromFloat32ArrayToRefScaled(pose.getViewMatrix(view), 0, 1, this.rigCameras[i]._computedViewMatrix);
                 BABYLON.Matrix.FromFloat32ArrayToRefScaled(view.projectionMatrix, 0, 1, this.rigCameras[i]._projectionMatrix);
                 BABYLON.Matrix.FromFloat32ArrayToRefScaled(view.projectionMatrix, 0, 1, this.rigCameras[i]._projectionMatrix);
                 if (!this._scene.useRightHandedSystem) {
                 if (!this._scene.useRightHandedSystem) {
-                    BABYLON.Matrix._ToggleModelMatrixHandInPlace(this.rigCameras[i]._computedViewMatrix);
-                    BABYLON.Matrix._ToggleProjectionMatrixHandInPlace(this.rigCameras[i]._projectionMatrix);
+                    this.rigCameras[i]._computedViewMatrix.toggleModelMatrixHandInPlace();
+                    this.rigCameras[i]._projectionMatrix.toggleProjectionMatrixHandInPlace();
                 }
                 }
 
 
                 // Update viewport
                 // Update viewport
@@ -93,7 +93,7 @@ module BABYLON {
                 this.rigCameras[i].viewport.y = viewport.y / height;
                 this.rigCameras[i].viewport.y = viewport.y / height;
 
 
                 // Set cameras to render to the session's render target
                 // Set cameras to render to the session's render target
-                this.rigCameras[i].renderTarget = xrSessionManager._sessionRenderTargetTexture;
+                this.rigCameras[i].outputRenderTarget = xrSessionManager._sessionRenderTargetTexture;
             });
             });
         }
         }
     }
     }

+ 7 - 1
src/Cameras/XR/babylon.webXRSessionManager.ts

@@ -28,6 +28,7 @@ module BABYLON {
          * Initializes the manager, this must be done with a user action (eg. button click event)
          * Initializes the manager, this must be done with a user action (eg. button click event)
          * After initialization enterXR can be called to start an XR session
          * After initialization enterXR can be called to start an XR session
          * @param scene
          * @param scene
+         * @returns Promise which resolves after it is initialized
          */
          */
         public initialize(): Promise<void> {
         public initialize(): Promise<void> {
              // Check if the browser supports webXR
              // Check if the browser supports webXR
@@ -45,6 +46,7 @@ module BABYLON {
         /**
         /**
          * Enters XR with the desired XR session options
          * Enters XR with the desired XR session options
          * @param sessionCreationOptions
          * @param sessionCreationOptions
+         * @returns Promise which resolves after it enters XR
          */
          */
         public enterXR(sessionCreationOptions: XRSessionCreationOptions, frameOfReferenceType: XRFrameOfReferenceType): Promise<void> {
         public enterXR(sessionCreationOptions: XRSessionCreationOptions, frameOfReferenceType: XRFrameOfReferenceType): Promise<void> {
             // initialize session
             // initialize session
@@ -70,6 +72,7 @@ module BABYLON {
 
 
         /**
         /**
          * Stops the xrSession and restores the renderloop
          * Stops the xrSession and restores the renderloop
+         * @returns Promise which resolves after it exits XR
          */
          */
         public exitXR() {
         public exitXR() {
             return new Promise((res) => {
             return new Promise((res) => {
@@ -86,6 +89,7 @@ module BABYLON {
         /**
         /**
          * Fires a ray and returns the closest hit in the xr sessions enviornment, useful to place objects in AR
          * Fires a ray and returns the closest hit in the xr sessions enviornment, useful to place objects in AR
          * @param ray ray to cast into the environment
          * @param ray ray to cast into the environment
+         * @returns Promise which resolves with a collision point in the environment if it exists
          */
          */
         public environmentPointHitTest(ray: BABYLON.Ray): Promise<Nullable<Vector3>> {
         public environmentPointHitTest(ray: BABYLON.Ray): Promise<Nullable<Vector3>> {
             return new Promise((res, rej) => {
             return new Promise((res, rej) => {
@@ -118,7 +122,9 @@ module BABYLON {
 
 
         /**
         /**
          * @hidden
          * @hidden
-         * Converts the render layer of xrSession to a render target
+         * Converts the render layer of xrSession to a render target 
+         * @param session session to create render target for
+         * @param scene scene the new render target should be created for
          */
          */
         public static _CreateRenderTargetTextureFromSession(session: XRSession, scene: BABYLON.Scene) {
         public static _CreateRenderTargetTextureFromSession(session: XRSession, scene: BABYLON.Scene) {
             // Create internal texture
             // Create internal texture

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

@@ -199,7 +199,7 @@ module BABYLON {
         public isStereoscopicSideBySide: boolean;
         public isStereoscopicSideBySide: boolean;
 
 
         /**
         /**
-         * Defines the list of custom render target the camera should render to.
+         * Defines the list of custom render target which are rendered to and then used as the input to this camera's render. Eg. display another camera view on a TV in the main scene
          * This is pretty helpfull if you wish to make a camera render to a texture you could reuse somewhere
          * This is pretty helpfull if you wish to make a camera render to a texture you could reuse somewhere
          * else in the scene.
          * else in the scene.
          */
          */
@@ -207,7 +207,7 @@ module BABYLON {
         /**
         /**
          * When set, the camera will render to this render target instead of the default canvas
          * When set, the camera will render to this render target instead of the default canvas
          */
          */
-        public renderTarget: Nullable<RenderTargetTexture> = null;
+        public outputRenderTarget: Nullable<RenderTargetTexture> = null;
 
 
         /**
         /**
          * Observable triggered when the camera view matrix has changed.
          * Observable triggered when the camera view matrix has changed.

+ 12 - 8
src/Math/babylon.math.ts

@@ -4879,22 +4879,26 @@ module BABYLON {
 
 
             return this;
             return this;
         }
         }
-
-        // Statics
-        /** @hidden */
-        public static _ToggleModelMatrixHandInPlace(matrix: Matrix) {
+        
+        /**
+         * Toggles model matrix from being right handed to left handed in place and vice versa
+         */
+        public toggleModelMatrixHandInPlace() {
             [2, 6, 8, 9, 14].forEach((num) => {
             [2, 6, 8, 9, 14].forEach((num) => {
-                matrix.m[num] *= -1;
+                this.m[num] *= -1;
             });
             });
         }
         }
 
 
-        /** @hidden */
-        public static _ToggleProjectionMatrixHandInPlace(matrix: Matrix) {
+        /**
+         * Toggles projection matrix from being right handed to left handed in place and vice versa
+         */
+        public toggleProjectionMatrixHandInPlace() {
             [8, 9, 10, 11].forEach((num) => {
             [8, 9, 10, 11].forEach((num) => {
-                matrix.m[num] *= -1;
+                this.m[num] *= -1;
             });
             });
         }
         }
 
 
+        // Statics
         /**
         /**
          * Creates a matrix from an array
          * Creates a matrix from an array
          * @param array defines the source array
          * @param array defines the source array

+ 2 - 2
src/babylon.scene.ts

@@ -4341,8 +4341,8 @@ module BABYLON {
 
 
                 this._intermediateRendering = false;
                 this._intermediateRendering = false;
 
 
-                if (this.activeCamera.renderTarget) {
-                    var internalTexture = this.activeCamera.renderTarget.getInternalTexture();
+                if (this.activeCamera.outputRenderTarget) {
+                    var internalTexture = this.activeCamera.outputRenderTarget.getInternalTexture();
                     if (internalTexture) {
                     if (internalTexture) {
                         engine.bindFramebuffer(internalTexture);
                         engine.bindFramebuffer(internalTexture);
                     }else {
                     }else {