Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice
  2. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Resolved how to change device cam?

Discussion in 'Unity MARS' started by pigeon99, Feb 26, 2021.

  1. pigeon99

    pigeon99

    Joined:
    Nov 27, 2016
    Posts:
    3
    hi.

    i'm using mars 1.2.0 for ios and android app.

    I am making a button that allows users to change cameras themselves.

    but...when i using face recognition...mars only force user direction camera use.

    i need help. thanks..
     
  2. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    140
    Hi there! Let's see if we can get to the bottom of this issue.

    First off, we need some more information. What version of AR Foundation are you using? What have you tried already? Is it acceptable for you to change camera direction by switching scenes, or do you need to change camera direction within the same scene?

    If you're using AR Foundation 4, we expose the `requestedFacingDirection` via `IUsesCameraTexture.RequestCameraFacingDirection`. If you add a script to the scene that implements `IUsesCameraTexture`, you should be able to request a world-facing camera. However, having tried this on my end, I ran into some trouble in this version of MARS, so I think this is a bug. I'll update this thread if I can figure out a workaround.

    In the meantime, if you can switch between to scenes, one set up for face tracking, and one for world tracking, you should be able to use both types of AR in a single app.

    Thanks for using MARS. Hope this helps!
     
    pigeon99 likes this.
  3. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    140
    Hi again. :)

    I thought I'd share the script I am using to test this feature. I'm able to switch cameras but I'm seeing issues where MARS proxies don't match again after switching. Thankfully, these seem to be fixed in the latest update, which should be coming soon. Not knowing exactly how you have your scene set up, I can't be sure if you will see the same issues. In the meantime, see if this script does the trick:

    Code (CSharp):
    1. using Unity.MARS.Data;
    2. using Unity.MARS.Providers;
    3. using Unity.XRTools.ModuleLoader;
    4. using UnityEngine;
    5.  
    6. namespace SwitchCameraTest
    7. {
    8.     public class SwitchCameraController : MonoBehaviour, IUsesPlaneFinding, IUsesPointCloud, IUsesSessionControl, IUsesCameraTexture
    9.     {
    10.         IProvidesPlaneFinding IFunctionalitySubscriber<IProvidesPlaneFinding>.provider { get; set; }
    11.         IProvidesPointCloud IFunctionalitySubscriber<IProvidesPointCloud>.provider { get; set; }
    12.         IProvidesSessionControl IFunctionalitySubscriber<IProvidesSessionControl>.provider { get; set; }
    13.         IProvidesCameraTexture IFunctionalitySubscriber<IProvidesCameraTexture>.provider { get; set; }
    14.  
    15.         public void SwitchCamera()
    16.         {
    17.             var currentDirection = this.GetCameraFacingDirection();
    18.             var requestUserDirection = currentDirection == CameraFacingDirection.World;
    19.             var requestedDirection = requestUserDirection
    20.                 ? CameraFacingDirection.User
    21.                 : CameraFacingDirection.World;
    22.  
    23.             if (requestUserDirection)
    24.             {
    25.                 this.StopDetectingPlanes();
    26.                 this.StopDetectingPoints();
    27.             }
    28.             else
    29.             {
    30.                 this.StartDetectingPlanes();
    31.                 this.StartDetectingPoints();
    32.             }
    33.  
    34.             this.PauseSession();
    35.             this.RequestCameraFacingDirection(requestedDirection);
    36.             this.ResumeSession();
    37.         }
    38.     }
    39. }
    40.  
     
    pigeon99 likes this.
  4. pigeon99

    pigeon99

    Joined:
    Nov 27, 2016
    Posts:
    3

    VERY VERY THANKS!!!!!!!!
     
    jmunozarUTech likes this.
unityunity