/// <summary> /// Update the scan progress. This function will initialize the scan, update it, /// and issue a final mesh import, when the scan is complete. /// </summary> /// <param name="deltaTime">The amount of time that has passed since the last update (typically Time.deltaTime)</param> private void Update_Scan(float deltaTime) { // If we auto-start scanning, do it now if (AutoBeginScanning && (ScanState == ScanStates.None)) { RequestBeginScanning(); } // Update the scan bool scanDone = false; if (((ScanState == ScanStates.ReadyToScan) || (ScanState == ScanStates.Scanning) || (ScanState == ScanStates.Finishing)) && (AllowSpatialUnderstanding)) { // Camera Vector3 camPos = Camera.main.transform.position; Vector3 camFwd = Camera.main.transform.forward; Vector3 camUp = Camera.main.transform.up; // If not yet initialized, do that now if (ScanState == ScanStates.ReadyToScan) { SpatialUnderstandingDll.Imports.GeneratePlayspace_InitScan( camPos.x, camPos.y, camPos.z, camFwd.x, camFwd.y, camFwd.z, camUp.x, camUp.y, camUp.z, ScanSearchDistance, ScanSearchDistance); ScanState = ScanStates.Scanning; } // Update int meshCount; IntPtr meshList; if (UnderstandingSourceMesh.GetInputMeshList(out meshCount, out meshList)) { scanDone = SpatialUnderstandingDll.Imports.GeneratePlayspace_UpdateScan( meshCount, meshList, camPos.x, camPos.y, camPos.z, camFwd.x, camFwd.y, camFwd.z, camUp.x, camUp.y, camUp.z, deltaTime) == 1; } } // If it's done, finish up if ((ScanState == ScanStates.Finishing) && (scanDone) && (!UnderstandingCustomMesh.IsImportActive) && (UnderstandingCustomMesh != null)) { // Final mesh import StartCoroutine(UnderstandingCustomMesh.Import_UnderstandingMesh()); // Mark it ScanState = ScanStates.Done; } }
/// <summary> /// Update the scan progress. This function will initialize the scan, update it, /// and issue a final mesh import, when the scan is complete. /// </summary> /// <param name="deltaTime">The amount of time that has passed since the last update (typically Time.deltaTime)</param> private void Update_Scan(float deltaTime) { // If we auto-start scanning, do it now if (AutoBeginScanning && (ScanState == ScanStates.None)) { RequestBeginScanning(); } // Update the scan bool scanDone = false; if (((ScanState == ScanStates.ReadyToScan) || (ScanState == ScanStates.Scanning) || (ScanState == ScanStates.Finishing)) && (AllowSpatialUnderstanding)) { // Camera Vector3 camPos = Camera.main.transform.position; Vector3 camFwd = Camera.main.transform.forward; Vector3 camUp = Camera.main.transform.up; // If not yet initialized, do that now if (ScanState == ScanStates.ReadyToScan) { SpatialUnderstandingDll.Imports.GeneratePlayspace_InitScan( camPos.x, camPos.y, camPos.z, camFwd.x, camFwd.y, camFwd.z, camUp.x, camUp.y, camUp.z, ScanSearchDistance, ScanSearchDistance); ScanState = ScanStates.Scanning; } // Update int meshCount; IntPtr meshList; if (UnderstandingSourceMesh.GetInputMeshList(out meshCount, out meshList)) { var stopWatch = System.Diagnostics.Stopwatch.StartNew(); scanDone = SpatialUnderstandingDll.Imports.GeneratePlayspace_UpdateScan( meshCount, meshList, camPos.x, camPos.y, camPos.z, camFwd.x, camFwd.y, camFwd.z, camUp.x, camUp.y, camUp.z, deltaTime) == 1; stopWatch.Stop(); if (stopWatch.Elapsed.TotalMilliseconds > (1000.0 / 30.0)) { Debug.LogWarningFormat("SpatialUnderstandingDll.Imports.GeneratePlayspace_UpdateScan took {0,9:N2} ms", stopWatch.Elapsed.TotalMilliseconds); } } } // If it's done, finish up if ((ScanState == ScanStates.Finishing) && (scanDone) && (!UnderstandingCustomMesh.IsImportActive) && (UnderstandingCustomMesh != null)) { // Final mesh import StartCoroutine(UnderstandingCustomMesh.Import_UnderstandingMesh()); // Mark it ScanState = ScanStates.Done; if (OnScanDone != null) { OnScanDone.Invoke(); } } }