/// <summary> /// Moves the specified anchored object. /// </summary> /// <param name="objectToMove">The anchored object to move.</param> /// <param name="worldPos">The world position.</param> /// <param name="worldRot">The world rotation.</param> /// <param name="cloudSpatialAnchor">The cloud spatial anchor.</param> protected virtual void MoveAnchoredObject(GameObject objectToMove, Vector3 worldPos, Quaternion worldRot, CloudSpatialAnchor cloudSpatialAnchor = null) { // Get the cloud-native anchor behavior CloudNativeAnchor cna = objectToMove.GetComponent <CloudNativeAnchor>(); // Warn and exit if the behavior is missing if (cna == null) { Debug.LogWarning($"The object {objectToMove.name} is missing the {nameof(CloudNativeAnchor)} behavior."); return; } // Is there a cloud anchor to apply if (cloudSpatialAnchor != null) { // Yes. Apply the cloud anchor, which also sets the pose. Debug.Log("!!!!!! MoveAnchoredObject (1)"); cna.CloudToNative(cloudSpatialAnchor); } else { // No. Just set the pose. Debug.Log("!!!!!! MoveAnchoredObject (2)"); cna.SetPose(worldPos, worldRot); } }
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); } }
/// <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 void CreateNewAnchor(Vector3 position) { // create new anchor view var view = _spatialAnchorViewFactory.Create(null); view.GameObject.transform.SetPositionAndRotation(position, Quaternion.identity); _placingAnchor = view.CloudNativeAnchor; IsPlacingAnchorExists = true; _spatialAnchorViews.Add(view); }
private void Construct(CloudSpatialAnchor cloudSpatialAnchor) { _cloudNativeAnchor = gameObject.AddComponent <CloudNativeAnchor>(); // restore existing anchor if cloudSpatialAnchor is not null // otherwise it is new one if (cloudSpatialAnchor == null) { return; } _cloudNativeAnchor.CloudToNative(cloudSpatialAnchor); }
private GameObject SpawnNewAnchoredObject(Vector3 position, Quaternion rotation) { GameObject newGameObject = GameObject.Instantiate(generalConfiguration.spatialAnchorGroupPrefab, position, rotation); newGameObject.AddComponent <CloudNativeAnchor>(); if (currentCloudSpatialAnchor != null) { CloudNativeAnchor cloudNativeAnchor = newGameObject.GetComponent <CloudNativeAnchor>(); cloudNativeAnchor.CloudToNative(currentCloudSpatialAnchor); } return(newGameObject); }
/// <summary> /// Spawns a new object. /// </summary> /// <param name="worldPos">The world position.</param> /// <param name="worldRot">The world rotation.</param> /// <param name="cloudSpatialAnchor">The cloud spatial anchor.</param> /// <returns><see cref="GameObject"/>.</returns> protected virtual GameObject SpawnNewAnchoredObject(Vector3 worldPos, Quaternion worldRot, CloudSpatialAnchor cloudSpatialAnchor) { // Create the object like usual GameObject newGameObject = SpawnNewAnchoredObject(worldPos, worldRot); // If a cloud anchor is passed, apply it to the native anchor if (cloudSpatialAnchor != null) { CloudNativeAnchor cloudNativeAnchor = newGameObject.GetComponent <CloudNativeAnchor>(); cloudNativeAnchor.CloudToNative(cloudSpatialAnchor); } // Return newly created object return(newGameObject); }
// 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); } }
/// <summary> /// Delete the cloud anchor corresponding to a local ARAnchor. /// </summary> private async void DeleteAnchorFromCloudAsync(GameObject gameObject) { CloudNativeAnchor cloudNativeAnchor = gameObject.GetComponent <CloudNativeAnchor>(); CloudSpatialAnchor cloudSpatialAnchor = cloudNativeAnchor.CloudAnchor; Debug.Log($"Deleting cloud anchor: {cloudSpatialAnchor.Identifier}"); await m_cloudSpatialAnchorManager.DeleteAnchorAsync(cloudSpatialAnchor); m_cloudSpatialAnchorIDs.Remove(cloudSpatialAnchor.Identifier); Destroy(cloudNativeAnchor); Debug.Log($"Cloud anchor deleted!"); // Update the visuals of the gameobject gameObject.GetComponent <SampleSpatialAnchor>().Persisted = false; gameObject.GetComponent <SampleSpatialAnchor>().Identifier = ""; }
protected override void OnAnchorInteraction(CloudNativeAnchor anchor) { if (anchor.CloudAnchor != null) { readyForObjectPlacement = false; currentAnchorId = anchor.CloudAnchor.Identifier; spatialNotesUI.setNoteText(saveStateController.getNoteText(currentAnchorId)); setAnchorSelected(currentAnchorId); spatialNotesUI.setConfirmButtonText("Update Note"); spatialNotesUI.setStatusText("Update the text of a saved note."); spatialNotesUI.showNoteUI(true, true, true, true); } else { Debug.LogError("OnAnchorInteraction :: anchor has not been saved to the cloud."); } }
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> /// Called when a touch object interaction occurs. /// </summary> /// <param name="hitPoint">The position.</param> /// <param name="target">The target.</param> protected override void OnSelectObjectInteraction(Vector3 hitPoint, object target, GameObject gameObject = null) { if (gameObject != null) { CloudNativeAnchor anchor = gameObject.GetComponent <CloudNativeAnchor>(); if (anchor != null) { OnAnchorInteraction(anchor); } } else if (IsPlacingObject()) { Quaternion rotation = Quaternion.AngleAxis(0, Vector3.up); SpawnOrMoveCurrentAnchoredObject(hitPoint, rotation); NewAnchorPlaced(); } }
/// <summary> /// Spawns a new object. /// </summary> /// <param name="worldPos">The world position.</param> /// <param name="worldRot">The world rotation.</param> /// <param name="cloudSpatialAnchor">The cloud spatial anchor.</param> /// <returns><see cref="GameObject"/>.</returns> protected virtual GameObject SpawnNewAnchoredObject(Vector3 worldPos, Quaternion worldRot, CloudSpatialAnchor cloudSpatialAnchor) { //Debug.Log("#### Base SpawnNewAnchoredObject Start cloudSpatialAnchor=" + cloudSpatialAnchor); // Create the object like usual GameObject newGameObject = SpawnNewAnchoredObject(worldPos, worldRot); // If a cloud anchor is passed, apply it to the native anchor if (cloudSpatialAnchor != null) { CloudNativeAnchor cloudNativeAnchor = newGameObject.GetComponent <CloudNativeAnchor>(); cloudNativeAnchor.CloudToNative(cloudSpatialAnchor); //Debug.Log("#### koko??? Base SpawnNewAnchoredObject OK ###"); } // Set color // newGameObject.GetComponent<MeshRenderer>().material.color = GetStepColor(); // Return newly created object return(newGameObject); }
// Update is called once per frame void Update() { if (cna == null) { // Get the cloud-native anchor behavior cna = GetComponent <CloudNativeAnchor>(); } // Warn and exit if the behavior is missing if (cna == null) { Debug.LogWarning($"The object {name} is missing the {nameof(CloudNativeAnchor)} behavior."); return; } if (isManipulate) { // No. Just set the pose. cna.SetPose(transform.position, transform.rotation); } }
/// <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; }
public void SetCloudSpatialAnchor(CloudSpatialAnchor cloudSpatialAnchor) { // Is there a cloud anchor to apply if (cloudSpatialAnchor != null) { if (cna == null) { // Get the cloud-native anchor behavior cna = GetComponent <CloudNativeAnchor>(); } // Yes. Apply the cloud anchor, which also sets the pose. cna.CloudToNative(cloudSpatialAnchor); if (handler != null) { handler.enabled = false; } if (AnchorsUpdate != null) { AnchorsUpdate.Invoke(cna, cloudSpatialAnchor); } } }
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."; } }
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); } }
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(); }
protected virtual void OnAnchorInteraction(CloudNativeAnchor anchor) { // To be overridden. }