Example #1
0
    protected virtual async Task SaveCurrentObjectAnchorToCloudAsync()
    {
        CloudNativeAnchor nativeAnchor = this.GetComponent <CloudNativeAnchor>();

        nativeAnchor.SetPose(this.transform.position, this.transform.rotation);

        // If the cloud portion of the anchor hasn't been created yet, create it
        if (nativeAnchor.CloudAnchor == null)
        {
            nativeAnchor.NativeToCloud();
        }

        CloudSpatialAnchor cloudAnchor = nativeAnchor.CloudAnchor;

        cloudAnchor.Expiration = DateTimeOffset.Now.AddDays(7);

        while (!GetComponent <SpatialAnchorManager>().IsReadyForCreate)
        {
            await Task.Delay(330);

            float createProgress = GetComponent <SpatialAnchorManager>().SessionStatus.RecommendedForCreateProgress;
            feedback.text = $"Move your device to capture more environment data: {createProgress:0%}";
        }

        Pose anchorPose = cloudAnchor.GetPose();

        feedback.text = "Anchor Position: " + anchorPose.position + " Rotation: " + anchorPose.rotation;


        try
        {
            // Actually save
            await GetComponent <SpatialAnchorManager>().CreateAnchorAsync(cloudAnchor);

            feedback.text = "Saved: " + cloudAnchor.Identifier;
            // Store
            currentCloudAnchor = cloudAnchor;

            //    // Success?
            //    success = currentCloudAnchor != null;

            //    if (success && !isErrorActive)
            //    {
            //        // Await override, which may perform additional tasks
            //        // such as storing the key in the AnchorExchanger
            //        await OnSaveCloudAnchorSuccessfulAsync();
            //    }
            //    else
            //    {
            //        OnSaveCloudAnchorFailed(new Exception("Failed to save, but no exception was thrown."));
            //    }
        }
        catch (Exception ex)
        {
            feedback.text = ex.ToString();
            //    OnSaveCloudAnchorFailed(ex);
        }
    }
Example #2
0
        /// <summary>
        /// Saves the current object anchor to the cloud.
        /// </summary>
        ///

        protected virtual async Task SaveCurrentObjectAnchorToCloudAsync()
        {
            // Get the cloud-native anchor behavior
            CloudNativeAnchor cna = spawnedObject.GetComponent <CloudNativeAnchor>();

            // If the cloud portion of the anchor hasn't been created yet, create it
            if (cna.CloudAnchor == null)
            {
                cna.NativeToCloud();
            }

            // Get the cloud portion of the anchor
            CloudSpatialAnchor cloudAnchor = cna.CloudAnchor;

            // In this sample app we delete the cloud anchor explicitly, but here we show how to set an anchor to expire automatically
            cloudAnchor.Expiration = DateTimeOffset.Now.AddDays(7);

            while (!CloudManager.IsReadyForCreate)
            {
                await Task.Delay(330);

                float createProgress = CloudManager.SessionStatus.RecommendedForCreateProgress;
                feedbackBox.text = $"Move your device to capture more environment data: {createProgress:0%}";
            }

            bool success = false;

            feedbackBox.text = "Saving...";

            try
            {
                // Actually save
                await CloudManager.CreateAnchorAsync(cloudAnchor);

                // Store
                currentCloudAnchor = cloudAnchor;

                // Success?
                success = currentCloudAnchor != null;

                if (success)
                {
                    // Await override, which may perform additional tasks
                    // such as storing the key in the AnchorExchanger

                    await OnSaveCloudAnchorSuccessfulAsync();
                }
                else
                {
                    OnSaveCloudAnchorFailed(new Exception("Failed to save, but no exception was thrown."));
                }
            }
            catch (Exception ex)
            {
                OnSaveCloudAnchorFailed(ex);
            }
        }
        public CloudSpatialAnchor ConfirmNewAnchorAndGetCloudSpatialAnchor()
        {
            if (_placingAnchor == null)
            {
                throw new NullReferenceException("_placingAnchor");
            }

            _placingAnchor.NativeToCloud();
            IsPlacingAnchorExists = false;
            return(_placingAnchor.CloudAnchor);
        }
    // Copy pasted this method from DemoScriptBase to allow specifying gameobject to get cloudnativeanchor from that will be saved.
    public async Task SaveObjectAnchorToCloudAsyncTask(GameObject go, string recordingId)
    {
        // Get the cloud-native anchor behavior
        CloudNativeAnchor cna = go.GetComponent <CloudNativeAnchor>();

        // If the cloud portion of the anchor hasn't been created yet, create it
        if (cna.CloudAnchor == null)
        {
            cna.NativeToCloud();
        }

        // Get the cloud portion of the anchor
        CloudSpatialAnchor cloudAnchor = cna.CloudAnchor;

        while (!CloudManager.IsReadyForCreate)
        {
            await Task.Delay(330);

            float createProgress = CloudManager.SessionStatus.RecommendedForCreateProgress;
            Debug.Log($"Move your device to capture more environment data: {createProgress:0%}\n");
        }

        bool success = false;

        try
        {
            // Actually save
            await CloudManager.CreateAnchorAsync(cloudAnchor);

            // Success?
            success = cloudAnchor != null;

            if (success && !isErrorActive)
            {
                anchorStore.Save(cloudAnchor.Identifier, recordingId);

                await OnSaveCloudAnchorSuccessfulAsync();
            }
            else
            {
                OnSaveCloudAnchorFailed(new Exception("Failed to save, but no exception was thrown."));
            }
        }
        catch (Exception ex)
        {
            OnSaveCloudAnchorFailed(ex);
        }
    }
Example #5
0
    public async void PlaceAnchor()
    {
        CloudNativeAnchor cna = objectToPlace.AddComponent <CloudNativeAnchor>();

        if (cna.CloudAnchor == null)
        {
            Log.debug("Calling Native to Cloud");
            cna.NativeToCloud();
        }
        Log.debug($"CNA : {cna.enabled}");
        CloudSpatialAnchor cloudAnchor = cna.CloudAnchor;

        Debug.Log($"AnchorConverter exists : {anchorConverter != null}");
        await anchorConverter.CreateCloudAnchor(cloudAnchor, objectToPlace.GetComponent <AnchorProperties>());

        Destroy(objectToPlace);
        anchorConverter.FindAnchorsByLocation();
    }
        /// <summary>
        /// Save a local ARAnchor as a cloud anchor.
        /// </summary>
        private async void SaveAnchorToCloudAsync(GameObject gameObject)
        {
            CloudNativeAnchor cloudNativeAnchor = gameObject.AddComponent <CloudNativeAnchor>();

            await cloudNativeAnchor.NativeToCloud();

            CloudSpatialAnchor cloudSpatialAnchor = cloudNativeAnchor.CloudAnchor;

            // In this sample app, the cloud anchors are deleted explicitly.
            // Here, we show how to set an anchor to expire automatically.
            cloudSpatialAnchor.Expiration = DateTimeOffset.Now.AddDays(7);

            while (!m_cloudSpatialAnchorManager.IsReadyForCreate)
            {
                await Task.Delay(1000);

                float createProgress = m_cloudSpatialAnchorManager.SessionStatus.RecommendedForCreateProgress;
                Debug.Log($"Move your device to capture more environment data: {createProgress:0%}");
            }


            // Now that the cloud spatial anchor has been prepared, we can try the actual save here
            Debug.Log($"Saving cloud anchor...");
            await m_cloudSpatialAnchorManager.CreateAnchorAsync(cloudSpatialAnchor);

            bool saveSucceeded = cloudSpatialAnchor != null;

            if (!saveSucceeded)
            {
                Debug.LogError("Failed to save, but no exception was thrown.");
                return;
            }

            m_cloudSpatialAnchorIDs.Add(cloudSpatialAnchor.Identifier);
            Debug.Log($"Saved cloud anchor: {cloudSpatialAnchor.Identifier}");

            // Update the visuals of the gameobject
            gameObject.GetComponent <SampleSpatialAnchor>().Identifier = cloudSpatialAnchor.Identifier;
            gameObject.GetComponent <SampleSpatialAnchor>().Persisted  = true;
        }
Example #7
0
    protected async Task SaveCurrentObjectAnchorToCloudAsync()
    {
        CloudNativeAnchor cloudNativeAnchor = spawnedAnchorObject.GetComponent <CloudNativeAnchor>();

        if (cloudNativeAnchor.CloudAnchor == null)
        {
            cloudNativeAnchor.NativeToCloud();
        }

        CloudSpatialAnchor cloudSpatialAnchor = cloudNativeAnchor.CloudAnchor;

        cloudSpatialAnchor.Expiration = DateTimeOffset.Now.AddDays(2);

        while (!spatialAnchorManager.IsReadyForCreate)
        {
            await Task.Delay(200);

            float createProgress = spatialAnchorManager.SessionStatus.RecommendedForCreateProgress;
            appStateManager.currentOutputMessage = $"Move your device to capture more data points in the environment : {createProgress:0%}";
        }

        appStateManager.currentOutputMessage = $"Saving anchor to cloud ...";

        await spatialAnchorManager.CreateAnchorAsync(cloudSpatialAnchor);

        currentCloudSpatialAnchor = cloudSpatialAnchor;

        if (currentCloudSpatialAnchor != null)
        {
            OnSaveCloudAnchorSuccessful();
        }
        else
        {
            appStateManager.currentOutputMessage = $"Failed saving anchor to cloud.";
        }
    }
Example #8
0
    public async void PlaceAnchor(string anchorLabel)
    {
        //For some reason, we need to refresh TextProOnACircle component so that it
        //doesn't unravel and just display the text in a straight line.
        //note: this is a total band-aid fix that only kind of works anyway..
        //TODO: find out why this is happening and fix it at the source so we don't
        //      have to destroy and create stuff
        ARTapToPlace     arTapManager = FindObjectOfType <ARTapToPlace>();
        TextProOnACircle tpoac        = arTapManager.spawnedObject.transform.Find("Anchor Text").GetComponent <TextProOnACircle>();
        TMP_Text         targetText   = arTapManager.spawnedObject.transform.Find("Anchor Text").GetComponent <TMP_Text>();

        targetText.text = "";
        Destroy(tpoac);
        arTapManager.spawnedObject.transform.Find("Anchor Text").gameObject.AddComponent <TextProOnACircle>();
        int anchorLabelLength = 0;

        while (anchorLabelLength <= 26)
        {
            targetText.text   += anchorLabel + "    ";
            anchorLabelLength += anchorLabel.Length + 4;
        }

        //End of weird circle text refresh


        //check for the object first
        if (spawnedObject == null)
        {
            //haven't placed
            Debug.Log("Trying to make cloud anchor without local");
            return;
        }

        //gets the CloudNativeAnchor component
        CloudNativeAnchor cna = spawnedObject.GetComponent <CloudNativeAnchor>();

        //if the spawned object doesn't have a cloud anchor associated with it,
        //NativeToCloud will make one with the CloudNativeAnchor component we just got
        if (cna.CloudAnchor == null)
        {
            cna.NativeToCloud();
        }

        //Begin to convert ARFoundation anchor to a CloudSpatialAnchor
        CloudSpatialAnchor cloudAnchor = cna.CloudAnchor;

        //set app property for label
        cloudAnchor.AppProperties["label"] = anchorLabel;
        await cloudAnchorManager.CreateCloudAnchor(cloudAnchor);

        //now the anchor has been created, need to refresh session so it shows up maybe?


        //clean up the local instance of the cube and anchor we just placed
        //so we can reset and render the version from the cloud
        CleaupSpawnedObject();

        await cloudAnchorManager.ResetSession();

        cloudAnchorManager.findAnchorsByLocation();
    }
Example #9
0
    public virtual async Task SaveCurrentObjectAnchorToCloudAsync()
    {
        feedbackBox.text = "Saving Spawned Game Object";
        // Get the cloud-native anchor behavior
        CloudNativeAnchor cna = SpawnedObject.GetComponent <CloudNativeAnchor>();


        // If the cloud portion of the anchor hasn't been created yet, create it
        if (cna.CloudAnchor == null)
        {
            cna.NativeToCloud();
        }

        // Get the cloud portion of the anchor
        CloudSpatialAnchor cloudAnchor = cna.CloudAnchor;

        // In this sample app we delete the cloud anchor explicitly, but here we show how to set an anchor to expire automatically
        cloudAnchor.Expiration = DateTimeOffset.Now.AddDays(7);

        String test = CloudManager.SessionStatus == null ? "null" : "not null";

        feedbackBox.text = $"Cloud manager is ready: {CloudManager.IsReadyForCreate} and status: {test}";

        while (!CloudManager.IsReadyForCreate)
        {
            await Task.Delay(330);

            float createProgress = CloudManager.SessionStatus.RecommendedForCreateProgress;
            feedbackBox.text = $"Move your device to capture more environment data: {createProgress:0%}";
        }

        bool success = false;

        feedbackBox.text = "Saving...";

        try
        {
            // Actually save
            await CloudManager.CreateAnchorAsync(cloudAnchor);

            // Store
            var currentCloudAnchor = cloudAnchor;

            // Success?
            success = currentCloudAnchor != null;

            if (success && !isErrorActive)
            {
                // Await override, which may perform additional tasks
                // such as storing the key in the AnchorExchanger
                feedbackBox.text = $"Saved Anchor succesfully: {currentCloudAnchor.Identifier}";
                _savedAnchor     = currentCloudAnchor;

                //POSTING ANCHOR
                string jsonString = JsonUtility.ToJson(new  AnchorDTO {
                    identifier = currentCloudAnchor.Identifier, model = this.model, userId = this.currentUser.id, longitude = Input.location.lastData.longitude, latitude = Input.location.lastData.latitude, srid = 4326
                });
                Debug.Log("JSON ANCHOR : " + jsonString);

                using (HttpClient client = new HttpClient())
                {
                    HttpContent httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
                    print("MESSAGE : " + httpContent.ReadAsStringAsync().Result);
                    HttpResponseMessage httpResponseMessage = client.PostAsync($"{ApiURL}/api/AnchorsAPI", httpContent).Result;
                    if (httpResponseMessage.IsSuccessStatusCode)
                    {
                        HttpContent content  = httpResponseMessage.Content;
                        string      response = content.ReadAsStringAsync().Result;
                        feedbackBox.text += $"\n API Response: {response}";
                    }
                    else
                    {
                        feedbackBox.text += $"\n API ERROR Response: {httpResponseMessage.StatusCode}";
                    }
                }
                _uiHandler.SetScreenCaptureVisible(true);
                await OnSaveCloudAnchorSuccessfulAsync();
            }
            else
            {
                OnSaveCloudAnchorFailed(new Exception("Failed to save, but no exception was thrown."));
            }
        }
        catch (Exception ex)
        {
            OnSaveCloudAnchorFailed(ex);
        }
    }