Search Unity

Question Camera control

Discussion in 'Unity MARS' started by Jon-at-Kaio, Jun 18, 2020.

  1. Jon-at-Kaio

    Jon-at-Kaio

    Joined:
    Oct 17, 2007
    Posts:
    185
    So my project requires me to use Mars/AR to 'scan' the environment to generate equivalent geometry.
    I then need to switch to a non-AR mode to be able to visualize that geo.
    one way I could do this is simply create a list of the geometry (all the transforms and their respective meshes etc, well actually for the moment theyll just be cubes) in a monob. thats set to dontdestroyonload, and then load up a non-mars scene and recreate the geometry via script using the list.

    However I suspect there must be a way to just switch off the 'ar-camera' feed so we can render just a normal scene (I'd also need to switch off all the mars proxys etc as well)

    Surely there must be a way to do this without loading a scene ?
     
  2. mtschoen

    mtschoen

    Unity Technologies

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

    I think I know what you're trying to do, but I want to confirm one point. Are you interested in stopping just the scan, or do you want to also disable camera tracking?

    You can start/stop individual plane finding and point cloud using their Functionality Injection interfaces. For example https://docs.unity3d.com/Packages/c...DetectingPlanes_Unity_MARS_IUsesPlaneFinding_

    Here is a script that we use for some of our samples to control the session
    Code (CSharp):
    1. using System;
    2. using TMPro;
    3. using Unity.XRTools.ModuleLoader;
    4. using UnityEngine;
    5. using UnityEngine.Events;
    6.  
    7. namespace Unity.MARS
    8. {
    9.     public class SessionUI : MonoBehaviour, IUsesFunctionalityInjection
    10.     {
    11.         class Subscriber : IUsesSessionControl, IUsesPointCloud, IUsesPlaneFinding, IUsesMarkerTracking
    12.         {
    13.             IProvidesSessionControl IFunctionalitySubscriber<IProvidesSessionControl>.provider { get; set; }
    14.             IProvidesPointCloud IFunctionalitySubscriber<IProvidesPointCloud>.provider { get; set; }
    15.             IProvidesPlaneFinding IFunctionalitySubscriber<IProvidesPlaneFinding>.provider { get; set; }
    16.             IProvidesMarkerTracking IFunctionalitySubscriber<IProvidesMarkerTracking>.provider { get; set; }
    17.         }
    18.  
    19.         [Serializable]
    20.         class PauseEvent : UnityEvent<bool> { }
    21.  
    22.         const string k_PauseText = "Pause";
    23.         const string k_ResumeText = "Resume";
    24.  
    25. #pragma warning disable 649
    26.         [SerializeField]
    27.         TextMeshProUGUI m_Text;
    28. #pragma warning restore 649
    29.  
    30.         readonly Subscriber m_Subscriber = new Subscriber();
    31.  
    32.         IProvidesFunctionalityInjection IFunctionalitySubscriber<IProvidesFunctionalityInjection>.provider { get; set; }
    33.  
    34.         void Start()
    35.         {
    36.             m_Text.text = MARSCore.instance.paused ? k_ResumeText : k_PauseText;
    37.             this.InjectFunctionalitySingle(m_Subscriber);
    38.         }
    39.  
    40.         public void TogglePaused()
    41.         {
    42.             var paused = MARSCore.instance.paused;
    43.             if (paused)
    44.             {
    45.                 m_Text.text = k_PauseText;
    46.                 paused = false;
    47.             }
    48.             else
    49.             {
    50.                 m_Text.text = k_ResumeText;
    51.                 paused = true;
    52.             }
    53.  
    54.             MARSCore.instance.paused = paused;
    55.             if (paused)
    56.             {
    57.                 if (m_Subscriber.HasProvider<IProvidesPointCloud>())
    58.                     m_Subscriber.StopDetectingPoints();
    59.  
    60.                 if (m_Subscriber.HasProvider<IProvidesPlaneFinding>())
    61.                     m_Subscriber.StopDetectingPlanes();
    62.  
    63.                 if (m_Subscriber.HasProvider<IProvidesMarkerTracking>())
    64.                     m_Subscriber.StopTrackingMarkers();
    65.             }
    66.             else
    67.             {
    68.                 if (m_Subscriber.HasProvider<IProvidesPointCloud>())
    69.                     m_Subscriber.StartDetectingPoints();
    70.  
    71.                 if (m_Subscriber.HasProvider<IProvidesPlaneFinding>())
    72.                     m_Subscriber.StartDetectingPlanes();
    73.  
    74.                 if (m_Subscriber.HasProvider<IProvidesMarkerTracking>())
    75.                     m_Subscriber.StartTrackingMarkers();
    76.             }
    77.         }
    78.  
    79.         public void TriggerSessionReset()
    80.         {
    81.             if (m_Subscriber.HasProvider<IProvidesSessionControl>())
    82.                 m_Subscriber.ResetSession();
    83.         }
    84.     }
    85. }
    86.  
    If you also want to take control of the camera, I think you were on the right track. Just disable the AR camera and let it keep tracking, while you enable another camera to fly around the scene. If you really want to use our camera, you should be able to just disable the `MARSCamera` component and take control of it, but you might run into trouble this way.

    I hope this helps! Let me know if you have any more questions, or if I'm not understanding what you're trying to do here.
    Good luck!
     
    jmunozarUTech likes this.