internal static Anchor Factory(NativeSession nativeApi, IntPtr anchorNativeHandle, bool isCreate = true) { if (anchorNativeHandle == IntPtr.Zero) { return(null); } Anchor result; if (_anchorDict.TryGetValue(anchorNativeHandle, out result)) { // Release acquired handle and return cached result AnchorApi.Release(anchorNativeHandle); return(result); } if (isCreate) { Anchor anchor = (new GameObject()).AddComponent <Anchor>(); anchor.gameObject.name = "Anchor"; anchor._nativeHandle = anchorNativeHandle; anchor._nativeSession = nativeApi; anchor.Update(); _anchorDict.Add(anchorNativeHandle, anchor); return(anchor); } return(null); }
internal static XPAnchor Factory(NativeSession nativeSession, IntPtr anchorHandle, bool isCreate = true) { if (anchorHandle == IntPtr.Zero) { return(null); } XPAnchor result; if (s_AnchorDict.TryGetValue(anchorHandle, out result)) { // Release acquired handle and return cached result AnchorApi.Release(anchorHandle); return(result); } if (isCreate) { XPAnchor anchor = (new GameObject()).AddComponent <XPAnchor>(); anchor.gameObject.name = "XPAnchor"; anchor.CloudId = nativeSession.AnchorApi.GetCloudAnchorId(anchorHandle); anchor.NativeHandle = anchorHandle; anchor.NativeSession = nativeSession; anchor.Update(); s_AnchorDict.Add(anchorHandle, anchor); return(anchor); } return(null); }
private async void downloadAnchorFile() { try { Debug.Log("Check anchor file exist..."); AnchorApi api = new AnchorApi("http://" + serverHost); AnchorInfo anchorInfo = await api.QueryAnchorInfo(appId, roomId); Debug.Log("--Check result=" + anchorInfo); if (anchorInfo != null && anchorInfo.fileSize > 0) { downloadApi = new DownloadProgressAnchorApi( "http://" + serverHost, appId, roomId, anchorFilePath, anchorFileName, tempFilePath, anchorInfo.fileSize ); worker.SubmitWork(downloadApi); } } catch (Exception e) { downloadApi = null; downloadErrorString = e.ToString(); downloadFinish = true; } }
/// <summary> /// When the game object containing the ARCloudAnchor component is destroyed, the /// underlying native Cloud Anchor object will be detached and the resource will /// be released. /// </summary> public void OnDestroy() { if (_anchorHandle != IntPtr.Zero) { AnchorApi.Detach( ARCoreExtensions._instance.currentARCoreSessionHandle, _anchorHandle); AnchorApi.Release(_anchorHandle); _anchorHandle = IntPtr.Zero; } }
/// <summary> /// When the game object containing the ARCloudAnchor component is destroyed, the /// underlying native Cloud Anchor object will be detached and the resource will /// be released. /// </summary> public void OnDestroy() { if (m_AnchorHandle != IntPtr.Zero) { AnchorApi.Detach( ARCoreExtensions.Instance.CurrentARCoreSessionHandle, m_AnchorHandle); AnchorApi.Release(m_AnchorHandle); m_AnchorHandle = IntPtr.Zero; } }
private void UpdateCloudAnchorRequest( CloudAnchorRequest request, bool isNewRequest = false) { var cloudState = request.NativeSession.AnchorApi.GetCloudAnchorState(request.AnchorHandle); if (cloudState == ApiCloudAnchorState.Success) { XPAnchor xpAnchor = null; CloudServiceResponse response = CloudServiceResponse.Success; try { xpAnchor = XPAnchor.Factory(request.NativeSession, request.AnchorHandle); } catch (Exception e) { Debug.LogError("Failed to create XP Anchor: " + e.Message); response = CloudServiceResponse.ErrorInternal; } var result = new CloudAnchorResult() { Response = response, Anchor = xpAnchor, }; request.OnTaskComplete(result); request.IsComplete = true; } else if (cloudState != ApiCloudAnchorState.TaskInProgress) { if (request.NativeSession != null && !request.NativeSession.IsDestroyed) { request.NativeSession.AnchorApi.Detach(request.AnchorHandle); } AnchorApi.Release(request.AnchorHandle); var result = new CloudAnchorResult() { Response = cloudState.ToCloudServiceResponse(), Anchor = null }; request.OnTaskComplete(result); request.IsComplete = true; } else if (isNewRequest) { _cloudAnchorRequests.Add(request); } }
/// <summary> /// Unity Update method. /// </summary> public void Update() { // Get the current Pose. ApiPose apiPose = AnchorApi.GetAnchorPose( ARCoreExtensions._instance.currentARCoreSessionHandle, _anchorHandle); _pose = Translators.ToUnityPose(apiPose); // Update the Cloud Anchor transform to match. transform.localPosition = _pose.position; transform.localRotation = _pose.rotation; }
/// <summary> /// Unity Update method. /// </summary> public void Update() { // Get the current Pose. ApiPose apiPose = AnchorApi.GetAnchorPose( ARCoreExtensions.Instance.CurrentARCoreSessionHandle, m_AnchorHandle); m_Pose = Translators.ToUnityPose(apiPose); // Update the cloud reference point transform to match. transform.localPosition = m_Pose.position; transform.localRotation = m_Pose.rotation; }
private void OnDestroy() { if (NativeHandle == IntPtr.Zero) { return; } if (NativeSession != null && !NativeSession.IsDestroyed) { NativeSession.AnchorApi.Detach(NativeHandle); } s_AnchorDict.Remove(NativeHandle); AnchorApi.Release(NativeHandle); }
/// <summary> /// Unity Update method. /// </summary> public void Update() { #if UNITY_EDITOR _pose = ARCoreCloudAnchorsEditorDelegate.Instance.GetAnchorPose(ARCoreExtensions._instance.currentARCoreSessionHandle, _anchorHandle); #endif if (!Application.isEditor) { // Get the current Pose. ApiPose apiPose = AnchorApi.GetAnchorPose( ARCoreExtensions._instance.currentARCoreSessionHandle, _anchorHandle); _pose = apiPose.ToUnityPose(); } // Update the Cloud Anchor transform to match. transform.localPosition = _pose.position; transform.localRotation = _pose.rotation; }
private async void downloadAnchor() { AnchorApi api; try { api = new AnchorApi("http://" + serverHost, serverPort); Debug.Log("Download Anchor! app=" + appId + " room=" + roomId + " ip=" + api.host + " port=" + api.port); importedData = await api.DownloadAnchor(appId, roomId); } catch (Exception e) { downloadErrorString = e.ToString(); } downloadFinish = true; }
IEnumerator Start() { m_Anchors = new List <ARAnchor>(); yield return(new WaitForSeconds(1f)); for (int i = 0; i < m_Count; ++i) { var position = Random.insideUnitSphere * m_Radius + transform.position; var rotation = Quaternion.AngleAxis(Random.Range(0, 360), Random.onUnitSphere); var anchor = m_AnchorManager.AddAnchor(new Pose(position, rotation)); if (anchor != null) { m_Anchors.Add(anchor); } yield return(new WaitForSeconds(.5f)); } var previousPosition = transform.localPosition; while (enabled) { if (transform.hasChanged) { var delta = transform.position - previousPosition; previousPosition = transform.position; foreach (var anchor in m_Anchors) { var pose = new Pose(anchor.transform.position + delta, anchor.transform.rotation); AnchorApi.Update(anchor.trackableId, pose, TrackingState.Tracking); yield return(new WaitForSeconds(.5f)); } transform.hasChanged = false; } yield return(null); } }
/// <summary> /// 把内存数据上传 /// </summary> /// <param name="anchor"></param> private async void ToUploadAnchor(byte[] anchor) { AnchorApi api; try { api = new AnchorApi("http://" + serverHost, serverPort); Debug.Log("Upload Anchor! app=" + appId + " room=" + roomId + " ip=" + api.host + " port=" + api.port); var responseUpload = await api.UploadAnchor(appId, roomId, anchorFileName, anchor, 300); } catch (Exception e) { uploadErrorString = e.ToString(); } //Debug.Log(responseUpload, "Response [Upload]"); uploadFinish = true; //cbExportFinish(true, null); }
protected internal void CancelCloudAnchorRequest(string cloudAnchorId) { bool cancelledCloudAnchorRequest = false; foreach (var request in _cloudAnchorRequests) { if (request.CloudAnchorId == null || !request.CloudAnchorId.Equals(cloudAnchorId)) { continue; } if (request.NativeSession != null && !request.NativeSession.IsDestroyed) { request.NativeSession.AnchorApi.Detach(request.AnchorHandle); } AnchorApi.Release(request.AnchorHandle); var result = new CloudAnchorResult() { Response = CloudServiceResponse.ErrorRequestCancelled, Anchor = null, }; request.OnTaskComplete(result); request.IsComplete = true; cancelledCloudAnchorRequest = true; } _cloudAnchorRequests.RemoveAll(x => x.IsComplete); if (!cancelledCloudAnchorRequest) { Debug.LogWarning("Didn't find pending operation for cloudAnchorId: " + cloudAnchorId); } }
/// <summary> /// When the game object containing the <see cref="ARCloudAnchor"/> component is destroyed, /// the underlying native Cloud Anchor object will be detached and the resource will /// be released. /// </summary> public void OnDestroy() { if (_anchorHandle != IntPtr.Zero) { #if UNITY_EDITOR if (Application.isEditor) { return; } #endif if (ARCoreExtensions._instance == null || ARCoreExtensions._instance.Session == null) { Debug.LogError("Bug in ARCore Extensions: ARCoreExtensions._instance was destroyed before ARCloudAnchor.OnDestroy()"); return; } AnchorApi.Detach( ARCoreExtensions._instance.currentARCoreSessionHandle, _anchorHandle); AnchorApi.Release(_anchorHandle); _anchorHandle = IntPtr.Zero; } }