Search Unity

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:
    194
    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:
    194
    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.
  5. Aquabori

    Aquabori

    Joined:
    Sep 23, 2021
    Posts:
    1
    I used the script and it does allow me to switch between cameras but when I use the front camera it does track face, but when I switch to the back camera it doesn't track any face.
     
  6. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    194
    Hi there :)

    I believe this is expected. Are you expecting to track faces that are in view of the back camera? If so, this is not supported on ARKit or ARCore. On ARKit, it is possible to show the rear camera and do world tracking, while also tracking a face through the front-facing camera, as described here https://developer.apple.com/documen...mbining_user_face-tracking_and_world_tracking
     
  7. guiga_h

    guiga_h

    Joined:
    Sep 27, 2019
    Posts:
    3
    hi guys!!

    I'm not able to use mars with the front camera, whenever the app launches the rear camera is activated, I've already checked all the methods I know, including using the cameraFacingDirection.User, passing it as a unique attribute for the application and when I launch it switch to world without any intervention from me, do @mtschoen have any idea what could be causing this?
     
    hiagotruta likes this.
  8. hiagotruta

    hiagotruta

    Joined:
    Jan 27, 2015
    Posts:
    10


    HI, @mtschoen i also have the same problem of @guiga_h you can help us please? Do you have any idea how to fix that? Thankss
     
  9. CiaranWills

    CiaranWills

    Unity Technologies

    Joined:
    Apr 24, 2020
    Posts:
    199
    @guiga_h @hiagotruta - can you let me know the version of MARS, Unity & AR Foundation you are using, as well as what model of phone you are deploying to? Or even better file a bug report from the editor.

    I haven't been able to reproduce this yet.
     
  10. guiga_h

    guiga_h

    Joined:
    Sep 27, 2019
    Posts:
    3
    hi, I put the facetracking of mars in the project (having performed the switch platform for iOS) and inside unity it works, but after the build it doesn't work on the device (we tested with iphone x, iphone xs and iphone 11), the camera activated does not it's the selfie, but the rear camera. I've already tried to force the use of the selfie camera via script using cameraFacingDirection.User, but when executing the script, unusually, the attribute changes from .user to .world

    The versions are:

    Unity 2020.3.24f1
    Mars 1.4.1
    AR Foundation 4.2.1
    ARKit 4.1.7
     
  11. guiga_h

    guiga_h

    Joined:
    Sep 27, 2019
    Posts:
    3
    there is no related error in the console and i also didn't see anything in the xcode log