public ARState GetState() { ARState state = new ARState { frameHandle = 0, sessionHandle = 0, tracked = false }; #if HAS_GOOGLE_ARCORE if (GetSelectedAR() == ARSDK.ARCORE) { NativeSession native = LifecycleManager.Instance.NativeSession; if (native != null) { state = new ARState { frameHandle = native.FrameHandle.ToInt32(), sessionHandle = native.SessionHandle.ToInt32(), tracked = LifecycleManager.Instance.SessionStatus == SessionStatus.Tracking }; } } #endif #if HAS_HUAWEI_ARENGINE if (GetSelectedAR() == ARSDK.ARENGINE) { NDKSession native = ARSessionManager.Instance.m_ndkSession; if (native != null) { state = new ARState { frameHandle = native.FrameHandle.ToInt32(), sessionHandle = native.SessionHandle.ToInt32(), tracked = ARFrame.GetTrackingState() == ARTrackable.TrackingState.TRACKING }; } } #endif return(state); }
private void Update() { //exporting if (threadSaving) { if (plugin.CallStatic <bool>("IsSaveFinished")) { bool success = plugin.CallStatic <bool>("IsSaveSuccessful"); Handheld.StopActivityIndicator(); arProvider.ResumeSession(); Utils.ShowAndroidToastMessage(success ? threadOpSave + " was saved successfully." : "Saving failed!"); if (success) { ObjReader.FilePath = threadOpSave.Replace(Application.persistentDataPath + "/", ""); SceneManager.LoadScene("ViewObj"); } threadOpSave = null; threadSaving = false; } return; } //meshing ARState state = arProvider.GetState(); if (!threadRunning && state.tracked) { ConfigurePlugin(); if (plugin != null) { int count = plugin.CallStatic <int>("OnBegin", state.sessionHandle, state.frameHandle); if (count >= 0) { threadRunning = true; ScanSettings scan = arProvider.GetSelectedAR() == ARSDK.ARENGINE ? AREngineSettings : ARCoreSettings; if (scan.colorizeMesh) { arProvider.GetCamera().targetTexture = cpuRTT; RenderTexture.active = cpuRTT; Camera cam = arProvider.GetCamera(); int mask = cam.cullingMask; cam.cullingMask = 0; cam.Render(); cam.cullingMask = mask; cpuTexture.ReadPixels(new Rect(0, 0, cpuWidth, cpuHeight), 0, 0); RenderTexture.active = null; arProvider.GetCamera().targetTexture = null; cpuPixels = cpuTexture.GetRawTextureData(); plugin.CallStatic("OnPixels", cpuWidth, cpuHeight, cpuPixels, cpuScale); } plugin.CallStatic("OnProcess"); GenerateJobs(count); } else { plugin.CallStatic("OnEnd"); } } } //visualize mesh DateTime t = DateTime.UtcNow; if (threadRunning) { while (true) { if ((DateTime.UtcNow - t).Milliseconds > 33) { break; } else if (jobs.Count > 0) { MeshingJob job = jobs[jobs.Count - 1]; foreach (Vizualisation vizualisation in vizualisations) { GameObject gameObject = vizualisation.OnMeshUpdate(job.id, job.vertices, job.normals, job.colors, job.indices); if (!gamesObjects.ContainsKey(job.id) && gameObject != null) { gamesObjects.Add(job.id, gameObject); } } jobs.RemoveAt(jobs.Count - 1); } else { Finish(); break; } } } //request save mesh if (!string.IsNullOrEmpty(threadOpSave) && !threadOpPause) { foreach (Vizualisation vizualisation in vizualisations) { vizualisation.OnMeshClear(); } GameObject.Find("UI").SetActive(false); GameObject.Find("SavingCanvas").GetComponentInChildren <Text>().text = "儲存中...\n不要關閉應用程式"; Handheld.StartActivityIndicator(); plugin.CallStatic("Save", threadOpSave); threadSaving = true; } }