Esempio n. 1
0
    public void LocalizeAnchor()
    {
        DispatcherQueue.Enqueue(() =>
        {
            if (_cloudSpatialAnchorSession == null)
            {
                Log("CloudSpatialAnchorSession was null. Weird.", Color.red);
                return;
            }
            else
            {
                // Initialize session fresh & clean
                CleanupObjects();
                _cloudSpatialAnchorSession.Stop();
                _cloudSpatialAnchorSession.Dispose();
                _cloudSpatialAnchorSession = null;
                InitializeSession();

                // Create a Watcher with anchor ID to locate the anchor that was created before
                AnchorLocateCriteria criteria = new AnchorLocateCriteria
                {
                    Identifiers = new string[] { _currentCloudAnchorId }
                };
                _cloudSpatialAnchorSession.CreateWatcher(criteria);

                Log($"Localizing anchor with {_cloudSpatialAnchorSession.GetActiveWatchers().Count} watchers.\r\nLook around to gather spatial data...");
            }
        });
    }
Esempio n. 2
0
    private IEnumerator CreateNewCloudSession()
    {
        cloudSpatialAnchorSession = new CloudSpatialAnchorSession();

        cloudSpatialAnchorSession.Configuration.AccountId = Globals.SpatialAnchorsAccountId;

        cloudSpatialAnchorSession.LogLevel = SessionLogLevel.Information;

        cloudSpatialAnchorSession.TokenRequired          += CloudSpatialAnchorSession_TokenRequired;
        cloudSpatialAnchorSession.OnLogDebug             += CloudSpatialAnchorSession_OnLogDebug;
        cloudSpatialAnchorSession.SessionUpdated         += CloudSpatialAnchorSession_SessionUpdated;
        cloudSpatialAnchorSession.AnchorLocated          += CloudSpatialAnchorSession_AnchorLocated;
        cloudSpatialAnchorSession.LocateAnchorsCompleted += CloudSpatialAnchorSession_LocateAnchorsCompleted;
        cloudSpatialAnchorSession.Error += CloudSpatialAnchorSession_Error;

#if UNITY_IOS
        cloudSpatialAnchorSession.Session = arkitSession.GetNativeSessionPtr();
#elif UNITY_ANDROID
        while (GoogleARCoreInternal.ARCoreAndroidLifecycleManager.Instance == null ||
               GoogleARCoreInternal.ARCoreAndroidLifecycleManager.Instance.NativeSession == null)
        {
            yield return(new WaitForSeconds(0.5f));
        }

        cloudSpatialAnchorSession.Session = GoogleARCoreInternal.ARCoreAndroidLifecycleManager.Instance.NativeSession.SessionHandle;
#elif UNITY_WSA || WINDOWS_UWP
        // No need to set a native session pointer for HoloLens.
#else
        throw new NotSupportedException("The platform is not supported.");
#endif

        yield break;
    }
Esempio n. 3
0
    /// <summary>
    /// Initializes a new CloudSpatialAnchorSessions.
    /// </summary>
    void InitializeSession()
    {
        Debug.Log("ASA Info: Initializing a CloudSpatialAnchorSession.");

        if (string.IsNullOrEmpty(SpatialAnchorsAccountId))
        {
            Debug.LogError("No account id set.");
            return;
        }

        if (string.IsNullOrEmpty(SpatialAnchorsAccountKey))
        {
            Debug.LogError("No account key set.");
            return;
        }

        cloudSpatialAnchorSession = new CloudSpatialAnchorSession();

        cloudSpatialAnchorSession.Configuration.AccountId  = SpatialAnchorsAccountId.Trim();
        cloudSpatialAnchorSession.Configuration.AccountKey = SpatialAnchorsAccountKey.Trim();

        cloudSpatialAnchorSession.LogLevel = SessionLogLevel.All;

        cloudSpatialAnchorSession.Error                  += CloudSpatialAnchorSession_Error;
        cloudSpatialAnchorSession.OnLogDebug             += CloudSpatialAnchorSession_OnLogDebug;
        cloudSpatialAnchorSession.SessionUpdated         += CloudSpatialAnchorSession_SessionUpdated;
        cloudSpatialAnchorSession.AnchorLocated          += CloudSpatialAnchorSession_AnchorLocated;
        cloudSpatialAnchorSession.LocateAnchorsCompleted += CloudSpatialAnchorSession_LocateAnchorsCompleted;

        cloudSpatialAnchorSession.Start();

        Debug.Log("ASA Info: Session was initialized.");
    }
Esempio n. 4
0
        private void Awake()
        {
            _cloudAnchorSession = new CloudSpatialAnchorSession();

            _cloudAnchorSession.Configuration.AccountId  = _accountId.Trim();
            _cloudAnchorSession.Configuration.AccountKey = _accountKey.Trim();
        }
Esempio n. 5
0
        private void CreateNewCloudSession()
        {
            cloudSpatialAnchorSession = new CloudSpatialAnchorSession();

            cloudSpatialAnchorSession.Configuration.AccountId  = SpatialAnchorsAccountId.Trim();
            cloudSpatialAnchorSession.Configuration.AccountKey = SpatialAnchorsAccountKey.Trim();
            cloudSpatialAnchorSession.LogLevel = SessionLogLevel.All;

            cloudSpatialAnchorSession.OnLogDebug             += CloudSpatialAnchorSession_OnLogDebug;
            cloudSpatialAnchorSession.SessionUpdated         += CloudSpatialAnchorSession_SessionUpdated;
            cloudSpatialAnchorSession.AnchorLocated          += CloudSpatialAnchorSession_AnchorLocated;
            cloudSpatialAnchorSession.LocateAnchorsCompleted += CloudSpatialAnchorSession_LocateAnchorsCompleted;
            cloudSpatialAnchorSession.Error += CloudSpatialAnchorSession_Error;

#if UNITY_WSA && !UNITY_EDITOR
            // AAD user token scenario to get an authentication token
            //cloudSpatialAnchorSession.TokenRequired += async (object sender, SpatialServices.TokenRequiredEventArgs args) =>
            //{
            //    CloudSpatialAnchorSessionDeferral deferral = args.GetDeferral();
            //    // AAD user token scenario to get an authentication token
            //    args.AuthenticationToken = await AuthenticationHelper.GetAuthenticationTokenAsync();
            //    deferral.Complete();
            //};
#endif

#if UNITY_IOS
            cloudSpatialAnchorSession.Session = arkitSession.GetNativeSessionPtr();
#elif UNITY_ANDROID
            cloudSpatialAnchorSession.Session = GoogleARCoreInternal.ARCoreAndroidLifecycleManager.Instance.NativeSession.SessionHandle;
#elif UNITY_WSA || WINDOWS_UWP
            // No need to set a native session pointer for HoloLens.
#else
            throw new NotSupportedException("The platform is not supported.");
#endif
        }
        /// </inheritdoc>
        public void StartSession(object context, object arScene)
        {
            this.context    = context as Context;
            this.arFragment = arScene as ArFragment;

            if (this.spatialAnchorsSession == null)
            {
                CloudServices.Initialize(this.context);
            }

            this.spatialAnchorsSession = new CloudSpatialAnchorSession();
            this.spatialAnchorsSession.Configuration.AccountKey = Constants.SpatialAnchorsAccountKey;
            this.spatialAnchorsSession.Configuration.AccountId  = Constants.SpatialAnchorsAccountId;
            this.spatialAnchorsSession.Session                 = this.arFragment.ArSceneView.Session;
            this.spatialAnchorsSession.AnchorLocated          += this.OnAnchorLocated;
            this.spatialAnchorsSession.LocateAnchorsCompleted += this.OnLocateAnchorsCompleted;
            this.spatialAnchorsSession.SessionUpdated         += this.SessionUpdated;
            this.spatialAnchorsSession.TokenRequired          += SpatialAnchorsSession_TokenRequired;
            this.spatialAnchorsSession.Error += (sender, e) =>
            {
                SessionErrorEvent eventArgs = e?.Args;
                if (eventArgs == null)
                {
                    return;
                }
                var message = $"{eventArgs.ErrorCode}: {eventArgs.ErrorMessage}";
                ShowMessage(this, message);
            };


            this.spatialAnchorsSession.Start();
            this.Status = SpatialAnchorStatus.Iddle;
            this.arFragment.TapArPlane += OnTapArPlane;
        }
Esempio n. 7
0
    /// <summary>
    /// 新しいCloudSpatialAnchorセッションを初期化
    /// </summary>
    void ASAInitializeSession()
    {
        Debug.Log("ASA Info: Initializing a CloudSpatialAnchorSession.");

        if (string.IsNullOrEmpty(SpatialAnchorsAccountId))
        {
            Debug.LogError("アカウントIDが設定されていません。");
            return;
        }

        if (string.IsNullOrEmpty(SpatialAnchorsAccountKey))
        {
            Debug.LogError("アカウントキーが設定されていません。");
            return;
        }

        cloudSpatialAnchorSession = new CloudSpatialAnchorSession();

        cloudSpatialAnchorSession.Configuration.AccountId  = SpatialAnchorsAccountId.Trim();
        cloudSpatialAnchorSession.Configuration.AccountKey = SpatialAnchorsAccountKey.Trim();

        cloudSpatialAnchorSession.LogLevel = SessionLogLevel.All;

        cloudSpatialAnchorSession.Error                  += CloudSpatialAnchorSession_Error;
        cloudSpatialAnchorSession.OnLogDebug             += CloudSpatialAnchorSession_OnLogDebug;
        cloudSpatialAnchorSession.SessionUpdated         += CloudSpatialAnchorSession_SessionUpdated;
        cloudSpatialAnchorSession.AnchorLocated          += CloudSpatialAnchorSession_AnchorLocated;
        cloudSpatialAnchorSession.LocateAnchorsCompleted += CloudSpatialAnchorSession_LocateAnchorsCompleted;

        cloudSpatialAnchorSession.Start();
        Debug.Log("ASA Info: セッションは初期化されました。");
    }
Esempio n. 8
0
    async Task OnSessionAsync()
    {
        if (this.cloudAnchorSession == null)
        {
            this.cloudAnchorSession = new CloudSpatialAnchorSession();
            this.cloudAnchorSession.Configuration.AccountId  = ACCOUNT_ID;
            this.cloudAnchorSession.Configuration.AccountKey = ACCOUNT_KEY;
            this.cloudAnchorSession.Error += async(s, e) => await this.SayAsync("Error");

            // for Load
            this.cloudAnchorSession.AnchorLocated          += OnAnchorLocated;
            this.cloudAnchorSession.LocateAnchorsCompleted += OnLocateAnchorsCompleted;

            this.cloudAnchorSession.Start();

            this.sessionButtonLabel.text = "Disconnect";
            this.logText.text            = "session connected";
            this.msgText.text            = "create cube with anchor";
            await this.SayAsync("session connected");
        }
        else
        {
            this.cloudAnchorSession.Dispose();
            this.cloudAnchorSession = null;

            this.sessionButtonLabel.text = "Connect";
            this.logText.text            = "session disconnected";
            this.msgText.text            = "exit or try again";
            await this.SayAsync("session disconnected");
        }
    }
Esempio n. 9
0
 private void DestroySession()
 {
     if (this.cloudSession != null)
     {
         this.cloudSession.Stop();
         this.cloudSession = null;
     }
 }
Esempio n. 10
0
        /// <inheritdoc/>
        protected override void OnManagedDispose()
        {
            base.OnManagedDispose();

            session?.Stop();
            session?.Dispose();
            session = null;
        }
Esempio n. 11
0
    /// <summary>
    /// Initializes a new CloudSpatialAnchorSession
    /// </summary>
    private void initializeSession()
    {
        Debug.Log("ASA Info: Initializing a CloudSpatialAnchorSession.");

        /*
         * Error Checks
         */
        if (string.IsNullOrEmpty(spatialAnchorsAccountId))
        {
            Debug.LogError("No account id set.");
            return;
        }

        if (string.IsNullOrEmpty(spatialAnchorsAccountKey))
        {
            Debug.LogError("No account key set.");
            return;
        }

        // Can't simulate on Unity Editor so we are just going to skip it
        if (Application.isEditor)
        {
            Debug.Log("ASA: Simulating initialization process in editor.");
            return;
        }

        /*
         * Initialization
         */
        // Create a session to interact with the ASA service
        CloudSpatialAnchorSession = new CloudSpatialAnchorSession();

        // Credentials
        CloudSpatialAnchorSession.Configuration.AccountId     = spatialAnchorsAccountId.Trim();
        CloudSpatialAnchorSession.Configuration.AccountKey    = spatialAnchorsAccountKey.Trim();
        CloudSpatialAnchorSession.Configuration.AccountDomain = spatialAnchorsDomain.Trim();

        // Debug Logs
        CloudSpatialAnchorSession.LogLevel = SessionLogLevel.All;

        // Logging Callbacks
        CloudSpatialAnchorSession.Error      += CloudSpatialAnchorSession_Error;
        CloudSpatialAnchorSession.OnLogDebug += CloudSpatialAnchorSession_OnLogDebug;

        // Anchor Creation Callback
        CloudSpatialAnchorSession.SessionUpdated += CloudSpatialAnchorSession_SessionUpdated;

        // Anchor Location Callbacks
        CloudSpatialAnchorSession.AnchorLocated          += CloudSpatialAnchorSession_AnchorLocated;
        CloudSpatialAnchorSession.LocateAnchorsCompleted += CloudSpatialAnchorSession_LocateAnchorsCompleted;

        // Start the Session
        CloudSpatialAnchorSession.Start();

        Debug.Log("ASA Info: Session was initialized.");
    }
        public AzureSpatialAnchorsManager(Google.AR.Core.Session arCoreSession)
        {
            spatialAnchorsSession = new CloudSpatialAnchorSession();
            spatialAnchorsSession.Configuration.AccountId  = SpatialAnchorsAccountId;
            spatialAnchorsSession.Configuration.AccountKey = SpatialAnchorsAccountKey;
            spatialAnchorsSession.Session  = arCoreSession;
            spatialAnchorsSession.LogLevel = SessionLogLevel.All;

            spatialAnchorsSession.LogDebug += SpatialAnchorsSession_LogDebug;
            spatialAnchorsSession.Error    += SpatialAnchorsSession_Error;
        }
 public AzureSpatialAnchorsManager(Session arCoreSession)
 {
     this.spatialAnchorsSession = new CloudSpatialAnchorSession();
     this.spatialAnchorsSession.Configuration.AccountKey = AccountDetails.SpatialAnchorsAccountKey;
     this.spatialAnchorsSession.Configuration.AccountId  = AccountDetails.SpatialAnchorsAccountId;
     this.spatialAnchorsSession.Session                 = arCoreSession;
     this.spatialAnchorsSession.LogDebug               += this.SpatialCloudSession_LogDebug;
     this.spatialAnchorsSession.Error                  += this.SpatialAnchorsSession_Error;
     this.spatialAnchorsSession.AnchorLocated          += this.SpatialAnchorsSession_AnchorLocated;
     this.spatialAnchorsSession.LocateAnchorsCompleted += this.SpatialAnchorsSession_LocateAnchorsCompleted;
     this.spatialAnchorsSession.SessionUpdated         += this.SpatialAnchorsSession_SessionUpdated;
 }
        /// <inheritdoc/>
        protected override void OnConfigureSession(CloudSpatialAnchorSession session)
        {
            // TODO anborod: This is a copy from DemoWrapper (it was commented), figure out what should be done here

            // AAD user token scenario to get an authentication token
            //cloudSpatialAnchorSession.TokenRequired += async (object sender, SpatialServices.TokenRequiredEventArgs args) =>
            //{
            //    CloudSpatialAnchorSessionDeferral deferral = args.GetDeferral();
            //    // AAD user token scenario to get an authentication token
            //    args.AuthenticationToken = await AuthenticationHelper.GetAuthenticationTokenAsync();
            //    deferral.Complete();
            //};
        }
Esempio n. 15
0
 /// <summary>
 /// Stop the Azure Spatial Anchor Service session
 /// </summary>
 public void StopSession()
 {
     if (this.cloudSpatialAnchorSession != null)
     {
         // stop session
         this.cloudSpatialAnchorSession.Stop();
         // clear event handlers
         this.cloudSpatialAnchorSession.Error                  -= this.OnCloudSessionError;
         this.cloudSpatialAnchorSession.AnchorLocated          -= OnAnchorLocated;
         this.cloudSpatialAnchorSession.LocateAnchorsCompleted -= OnLocateAnchorsCompleted;
         // cleanup
         this.cloudSpatialAnchorSession.Dispose();
         this.cloudSpatialAnchorSession = null;
     }
 }
        private void OnDestroy()
        {
            enableProcessing = false;

            if (cloudSpatialAnchorSession != null)
            {
                cloudSpatialAnchorSession.Dispose();
                cloudSpatialAnchorSession = null;
            }

            if (anchorLocateCriteria != null)
            {
                anchorLocateCriteria = null;
            }

            _instance = null;
        }
Esempio n. 17
0
        public void StopSession()
        {
            this.cloudSession.Stop();
            this.cloudAnchor  = null;
            this.localAnchor  = null;
            this.cloudSession = null;

            foreach (AnchorVisual visual in this.anchorVisuals.Values)
            {
                if (visual.node != null)
                {
                    visual.node.RemoveFromParentNode();
                }
            }

            this.anchorVisuals.Clear();
        }
Esempio n. 18
0
    // Initial Session
    private void InitializeCloudSession()
    {
        cloudSpatialAnchorSession = new CloudSpatialAnchorSession();

        cloudSpatialAnchorSession.Configuration.AccountId  = SpatialAnchorsAccountId.Trim();
        cloudSpatialAnchorSession.Configuration.AccountKey = SpatialAnchorsAccountKey.Trim();

        cloudSpatialAnchorSession.LogLevel = SessionLogLevel.All;

        cloudSpatialAnchorSession.Error                  += CloudSpatialAnchorSession_Error;
        cloudSpatialAnchorSession.OnLogDebug             += CloudSpatialAnchorSession_OnLogDebug;
        cloudSpatialAnchorSession.SessionUpdated         += CloudSpatialAnchorSession_SessionUpdated;
        cloudSpatialAnchorSession.AnchorLocated          += CloudSpatialAnchorSession_AnchorLocated;
        cloudSpatialAnchorSession.LocateAnchorsCompleted += CloudSpatialAnchorSession_LocateAnchorsCompleted;

        cloudSpatialAnchorSession.Start();
        Debug.Log("ASA Info: Session was initialized.");
    }
Esempio n. 19
0
    /// <summary>
    /// Starts a new Azure Spatial Anchor session.
    /// </summary>
    private void StartSession()
    {
#if !UNITY_EDITOR
        Debug.Log("Initializing Azure Spatial Anchor session.");

        if (string.IsNullOrEmpty(AzureSpatialAnchorsConfiguration.SpatialAnchorsAccountId))
        {
            Debug.LogError("Azure Spatial Anchor account ID is not set.");
            return;
        }

        if (string.IsNullOrEmpty(AzureSpatialAnchorsConfiguration.SpatialAnchorsAccountKey))
        {
            Debug.LogError("Azure Spatial Anchor account key is not set.");
            return;
        }

        if (string.IsNullOrEmpty(AzureSpatialAnchorsConfiguration.SpatialAnchorsAccountDomain))
        {
            Debug.LogError("Azure Spatial Anchor account domain is not set.");
            return;
        }

        cloudSpatialAnchorSession = new CloudSpatialAnchorSession();

        cloudSpatialAnchorSession.Configuration.AccountId     = AzureSpatialAnchorsConfiguration.SpatialAnchorsAccountId.Trim();
        cloudSpatialAnchorSession.Configuration.AccountKey    = AzureSpatialAnchorsConfiguration.SpatialAnchorsAccountKey.Trim();
        cloudSpatialAnchorSession.Configuration.AccountDomain = AzureSpatialAnchorsConfiguration.SpatialAnchorsAccountDomain.Trim();

        cloudSpatialAnchorSession.LogLevel = SessionLogLevel.All;

        cloudSpatialAnchorSession.Error                  += CloudSpatialAnchorSession_Error;
        cloudSpatialAnchorSession.OnLogDebug             += CloudSpatialAnchorSession_OnLogDebug;
        cloudSpatialAnchorSession.SessionUpdated         += CloudSpatialAnchorSession_SessionUpdated;
        cloudSpatialAnchorSession.AnchorLocated          += CloudSpatialAnchorSession_AnchorLocated;
        cloudSpatialAnchorSession.LocateAnchorsCompleted += CloudSpatialAnchorSession_LocateAnchorsCompleted;

        cloudSpatialAnchorSession.Start();
#else
        Debug.Log("Azure Spatial Anchor session can't be started when running in the Unity Editor.");
#endif
    }
Esempio n. 20
0
    void InitializeSession()
    {
        Log("Initializing CloudSpatialAnchorSession.");

        // TODO: Provide your Azure Spatial Anchors AccountId and Primary ASA Key below (ConstantsSecret is not part of the code repo)
        if (String.IsNullOrEmpty(ConstantsSecret.AsaAccountId) || String.IsNullOrEmpty(ConstantsSecret.AsaKey))
        {
            Log("Azure Spatial Anchors Account ID or Account Key are not set.", Color.red);
            return;
        }

        _cloudSpatialAnchorSession = new CloudSpatialAnchorSession();
        _cloudSpatialAnchorSession.Configuration.AccountId  = ConstantsSecret.AsaAccountId;
        _cloudSpatialAnchorSession.Configuration.AccountKey = ConstantsSecret.AsaKey;
        _cloudSpatialAnchorSession.SessionUpdated          += CloudSpatialAnchorSession_SessionUpdated;
        _cloudSpatialAnchorSession.AnchorLocated           += CloudSpatialAnchorSession_AnchorLocated;
        _cloudSpatialAnchorSession.Error += CloudSpatialAnchorSession_Error;
        _cloudSpatialAnchorSession.Start();

        Log("ASA session initialized.\r\n Gaze and tap to place an anchor.");
    }
Esempio n. 21
0
        /// <summary>
        /// Start the Azure Spatial Anchor Service session
        /// This must be called before calling create, populate or delete methods.
        /// </summary>
        public void StartSession()
        {
            if (this.cloudSpatialAnchorSession == null)
            {
                Debug.Assert(this.cloudSpatialAnchorSession == null);

                this.ThrowOnBadAuthConfiguration();
                // setup the session
                this.cloudSpatialAnchorSession = new CloudSpatialAnchorSession();
                // set the Azure configuration parameters
                this.cloudSpatialAnchorSession.Configuration.AccountId  = this.Profile.AzureAccountId;
                this.cloudSpatialAnchorSession.Configuration.AccountKey = this.Profile.AzureServiceKey;
                // register event handlers
                this.cloudSpatialAnchorSession.Error                  += this.OnCloudSessionError;
                this.cloudSpatialAnchorSession.AnchorLocated          += OnAnchorLocated;
                this.cloudSpatialAnchorSession.LocateAnchorsCompleted += OnLocateAnchorsCompleted;

                // start the session
                this.cloudSpatialAnchorSession.Start();
            }
        }
Esempio n. 22
0
    private void CreateNewCloudSession()
    {
        cloudSpatialAnchorSession = new CloudSpatialAnchorSession();
        string accountId  = "set this";
        string accountKey = "set this";

        cloudSpatialAnchorSession.Configuration.AccountId  = accountId.Trim();
        cloudSpatialAnchorSession.Configuration.AccountKey = accountKey.Trim();

        cloudSpatialAnchorSession.LogLevel = SessionLogLevel.Information;

        cloudSpatialAnchorSession.OnLogDebug             += CloudSpatialAnchorSession_OnLogDebug;
        cloudSpatialAnchorSession.SessionUpdated         += CloudSpatialAnchorSession_SessionUpdated;
        cloudSpatialAnchorSession.AnchorLocated          += CloudSpatialAnchorSession_AnchorLocated;
        cloudSpatialAnchorSession.LocateAnchorsCompleted += CloudSpatialAnchorSession_LocateAnchorsCompleted;
        cloudSpatialAnchorSession.Error += CloudSpatialAnchorSession_Error;
        feedback.text = "Starting the session!";

        cloudSpatialAnchorSession.Start();
        feedback.text = "Look for next";
    }
Esempio n. 23
0
        public void StartSession()
        {
            this.cloudSession = new CloudSpatialAnchorSession
            {
                Session  = this.sceneView.Session,
                LogLevel = SessionLogLevel.Information
            };
            this.cloudSession.Configuration.AccountId     = AccountDetails.SpatialAnchorsAccountId;
            this.cloudSession.Configuration.AccountKey    = AccountDetails.SpatialAnchorsAccountKey;
            this.cloudSession.Configuration.AccountDomain = AccountDetails.SpatialAnchorsAccountDomain;

            //Delegate events hook here
            this.cloudSession.OnLogDebug             += this.SpatialCloudSession_LogDebug;
            this.cloudSession.Error                  += this.SpatialAnchorsSession_Error;
            this.cloudSession.AnchorLocated          += this.SpatialAnchorsSession_AnchorLocated;
            this.cloudSession.LocateAnchorsCompleted += this.SpatialAnchorsSession_LocateAnchorsCompleted;
            this.cloudSession.SessionUpdated         += this.SpatialAnchorsSession_SessionUpdated;

            this.cloudSession.Start();
            this.enoughDataForSaving = false;
        }
        private void CreateNewCloudSession()
        {
            cloudSession = new CloudSpatialAnchorSession();
            cloudSession.Configuration.AccountId  = @"2c54fa04-44c0-4b61-a848-4f86395311aa";
            cloudSession.Configuration.AccountKey = @"JOmr5g1hpJyCOVqFs95MNQ5B1Z5w7S23mFoBeKRSm/I=";
#if UNITY_IOS
            cloudSpatialAnchorSession.Session = arkitSession.GetNativeSessionPtr();
#elif UNITY_ANDROID
            cloudSession.Session = GoogleARCoreInternal.ARCoreAndroidLifecycleManager.Instance.NativeSession.SessionHandle;
#elif UNITY_WSA || WINDOWS_UWP
            // No need to set a native session pointer for HoloLens.
#else
            throw new NotSupportedException("The platform is not supported.");
#endif
            cloudSession.LogLevel = SessionLogLevel.All;

            cloudSession.Error          += CloudSession_Error;
            cloudSession.OnLogDebug     += CloudSession_OnLogDebug;
            cloudSession.SessionUpdated += CloudSession_SessionUpdated;
            cloudSession.Start();

            Debug.Log(DEBUG_FILTER + "Session was initialized.");
        }
Esempio n. 25
0
        private CloudSpatialAnchorSession CreateSession()
        {
            CloudSpatialAnchorSession toReturn = new CloudSpatialAnchorSession();

            SetValue(spatialAnchorsConfiguration.AccessToken, s => toReturn.Configuration.AccessToken                 = s);
            SetValue(spatialAnchorsConfiguration.AccountDomain, s => toReturn.Configuration.AccountDomain             = s);
            SetValue(spatialAnchorsConfiguration.AccountId, s => toReturn.Configuration.AccountId                     = s);
            SetValue(spatialAnchorsConfiguration.AccountKey, s => toReturn.Configuration.AccountKey                   = s);
            SetValue(spatialAnchorsConfiguration.AuthenticationToken, s => toReturn.Configuration.AuthenticationToken = s);

            toReturn.LogLevel = SessionLogLevel.All;

            toReturn.Error          += OnSessionError;
            toReturn.OnLogDebug     += OnSessionLogDebug;
            toReturn.SessionUpdated += OnSessionUpdated;

            //TODO how to properly use this?
            //toReturn.LocateAnchorsCompleted += OnLocateAnchorsCompleted;

            OnConfigureSession(toReturn);

            return(toReturn);
        }
Esempio n. 26
0
        /// </inheritdoc>
        public void StartSession(object context, object arScene)
        {
            this.sceneView             = arScene as ARSCNView;
            this.spatialAnchorsSession = new CloudSpatialAnchorSession();

            this.spatialAnchorsSession.Configuration.AccountKey = Constants.SpatialAnchorsAccountKey;
            this.spatialAnchorsSession.Configuration.AccountId  = Constants.SpatialAnchorsAccountId;
            this.spatialAnchorsSession.Session                 = this.sceneView.Session;
            this.spatialAnchorsSession.AnchorLocated          += this.OnAnchorLocated;
            this.spatialAnchorsSession.LocateAnchorsCompleted += this.OnLocateAnchorsCompleted;
            this.spatialAnchorsSession.SessionUpdated         += this.SessionUpdated;
            this.spatialAnchorsSession.Error += (sender, e) =>
            {
                if (!string.IsNullOrWhiteSpace(e.ErrorMessage))
                {
                    ShowMessage(this, e.ErrorMessage);
                }
            };

            this.spatialAnchorsSession.Start();
            this.Status = SpatialAnchorStatus.Iddle;
            this.enoughDataForSaving = false;
        }
Esempio n. 27
0
        private async Task InitializeAsync(CancellationToken cancellationToken)
        {
            await OnInitializeAsync();

            session = CreateSession();
        }
Esempio n. 28
0
    private async Task createSessionAsync()
    {
        if (cloudSession != null)
        {
            //session already created, need to exit
            return;
        }



        cloudSession = new CloudSpatialAnchorSession();
        cloudSession.Configuration.AccountId   = "87f0e62e-2379-4bc4-bd1e-38dc699e8d6b";
        cloudSession.Configuration.AccessToken = "kF/SejjecfM8CatFa74V94iAsgApvPiaT1mY//qgK44=";
        cloudSession.Session = aRSession.subsystem.nativePtr.GetPlatformPointer();


#if UNITY_ANDROID // Android Only
        // We should only run the Java initialization once
        if (!javaInitialized)
        {
            // Create a TaskCompletionSource that we can use to know when
            // the Java plugin has completed initialization on the Android
            // thread.
            TaskCompletionSource <bool> pluginInit = new TaskCompletionSource <bool>();

            // Make sure ARCore is running. This code must be executed
            // on a Java thread provided by Android.
            AndroidHelper.Instance.DispatchUiThread(unityActivity =>
            {
                // Create the plugin
                using (AndroidJavaClass cloudServices = new AndroidJavaClass("com.microsoft.CloudServices"))
                {
                    // Initialize the plugin
                    cloudServices.CallStatic("initialize", unityActivity);

                    // Update static variable to say that the plugin has been initialized
                    javaInitialized = true;

                    // Set the task completion source so the CreateSession method can
                    // continue back on the Unity thread.
                    pluginInit.SetResult(true);
                }
            });

            // Wait for the plugin to complete initialization on the
            // Java thread.
            await pluginInit.Task;
        }
#endif


#if UNITY_ANDROID || UNITY_IOS
        var cameraParams = new XRCameraParams
        {
            zNear             = Camera.main.nearClipPlane,
            zFar              = Camera.main.farClipPlane,
            screenWidth       = Screen.width,
            screenHeight      = Screen.height,
            screenOrientation = Screen.orientation
        };

        XRCameraFrame xRCameraFrame;
        if (aRCameraManager.subsystem.TryGetLatestFrame(cameraParams, out xRCameraFrame))
        {
            long latestFrameTimeStamp = xRCameraFrame.timestampNs;

            bool newFrameToProcess = latestFrameTimeStamp > lastFrameProcessedTimeStamp;

            if (newFrameToProcess)
            {
                cloudSession.ProcessFrame(xRCameraFrame.nativePtr.GetPlatformPointer());
                lastFrameProcessedTimeStamp = latestFrameTimeStamp;
            }
        }
#endif
    }
Esempio n. 29
0
        /// <summary>
        /// Creates a new session if one does not exist.
        /// </summary>
        /// <returns>
        /// A <see cref="Task"/> that represents the operation.
        /// </returns>
#pragma warning disable CS1998 // Conditional compile statements are removing await
        public async Task CreateSessionAsync()
#pragma warning restore CS1998
        {
            // Warn if already created
            if (session != null)
            {
                Debug.LogWarning($"{nameof(CreateSessionAsync)} called but session is already created.");
                return;
            }

            // Only allow a session to be created the manager is properly configured.
            EnsureValidConfiguration(disable: false, exception: true);

            #if UNITY_ANDROID // Android Only
            // We should only run the Java initialization once
            if (!javaInitialized)
            {
                // Create a TaskCompletionSource that we can use to know when
                // the Java plugin has completed initialization on the Android
                // thread.
                TaskCompletionSource <bool> pluginInit = new TaskCompletionSource <bool>();

                // Make sure ARCore is running. This code must be executed
                // on a Java thread provided by Android.
                AndroidHelper.Instance.DispatchUiThread(unityActivity =>
                {
                    // Create the plugin
                    using (AndroidJavaClass cloudServices = new AndroidJavaClass("com.microsoft.CloudServices"))
                    {
                        // Initialize the plugin
                        cloudServices.CallStatic("initialize", unityActivity);

                        // Update static variable to say that the plugin has been initialized
                        javaInitialized = true;

                        // Set the task completion source so the CreateSession method can
                        // continue back on the Unity thread.
                        pluginInit.SetResult(true);
                    }
                });

                // Wait for the plugin to complete initialization on the
                // Java thread.
                await pluginInit.Task;
            }
            #elif UNITY_IOS // iOS Only
            // Make sure ARKit is running
            if (arkitSession == null)
            {
                arkitSession = UnityARSessionNativeInterface.GetARSessionNativeInterface();
                UnityARSessionNativeInterface.ARFrameUpdatedEvent += UnityARSessionNativeInterface_ARFrameUpdatedEvent;
            }
            #endif

            // Create the session instance
            session = new CloudSpatialAnchorSession();

            // Configure logging
            session.LogLevel = logLevel;

            // Configure authentication
            if (authenticationMode == AuthenticationMode.ApiKey)
            {
                // API Key mode just applies credentials directly
                session.Configuration.AccountId  = spatialAnchorsAccountId.Trim();
                session.Configuration.AccountKey = spatialAnchorsAccountKey.Trim();
            }
            else
            {
                // AAD mode requires an auth token workflow
                session.TokenRequired += Session_TokenRequired;
            }

            // Subscribe to session events
            session.OnLogDebug             += OnLogDebug;
            session.SessionUpdated         += OnSessionUpdated;
            session.AnchorLocated          += OnAnchorLocated;
            session.LocateAnchorsCompleted += OnLocateAnchorsCompleted;
            session.Error += OnError;


            #if UNITY_IOS
            session.Session = arkitSession.GetNativeSessionPtr();
            #elif UNITY_ANDROID
            session.Session = GoogleARCoreInternal.ARCoreAndroidLifecycleManager.Instance.NativeSession.SessionHandle;
            #elif UNITY_WSA || WINDOWS_UWP
            // No need to set a native session pointer for HoloLens.
            #else
            throw new NotSupportedException("The platform is not supported.");
            #endif
        }
Esempio n. 30
0
 /// <inheritdoc/>
 protected override void OnConfigureSession(CloudSpatialAnchorSession session)
 {
     session.Session = GoogleARCoreInternal.ARCoreAndroidLifecycleManager.Instance.NativeSession.SessionHandle;
 }