14 [RequireComponent(typeof(SpatialUnderstandingSourceMesh))]
15 [RequireComponent(typeof(SpatialUnderstandingCustomMesh))]
19 public const float ScanSearchDistance = 8.0f;
32 [Tooltip(
"If set to false, scanning will only begin after RequestBeginScanning is called")]
33 public bool AutoBeginScanning =
true;
34 [Tooltip(
"Update period used during the scanning process (typically faster than after scanning is completed)")]
35 public float UpdatePeriod_DuringScanning = 1.0f;
36 [Tooltip(
"Update period used after the scanning process is completed")]
37 public float UpdatePeriod_AfterScanning = 4.0f;
43 public bool AllowSpatialUnderstanding
75 if (ScanStateChanged != null)
88 public bool ScanStatsReportStillWorking
92 if (AllowSpatialUnderstanding)
95 return (stats.IsWorkingOnStats != 0);
101 public delegate
void OnScanDoneDelegate();
117 private float timeSinceLastUpdate = 0.0f;
126 UnderstandingSourceMesh = GetComponent<SpatialUnderstandingSourceMesh>();
127 UnderstandingCustomMesh = GetComponent<SpatialUnderstandingCustomMesh>();
133 if (AllowSpatialUnderstanding)
139 private void Update()
141 if (!AllowSpatialUnderstanding)
148 timeSinceLastUpdate += Time.deltaTime;
149 if ((!UnderstandingCustomMesh.IsImportActive) &&
150 (Time.frameCount % 3 == 0))
153 Update_Scan(timeSinceLastUpdate);
154 timeSinceLastUpdate = 0;
161 if (AllowSpatialUnderstanding)
189 if (AllowSpatialUnderstanding)
201 private void Update_Scan(
float deltaTime)
204 if (AutoBeginScanning &&
207 RequestBeginScanning();
211 bool scanDone =
false;
215 (AllowSpatialUnderstanding))
219 Vector3 camPos = cameraTransform.position;
220 Vector3 camFwd = cameraTransform.forward;
221 Vector3 camUp = cameraTransform.up;
227 camPos.x, camPos.y, camPos.z,
228 camFwd.x, camFwd.y, camFwd.z,
229 camUp.x, camUp.y, camUp.z,
230 ScanSearchDistance, ScanSearchDistance);
237 if (UnderstandingSourceMesh.GetInputMeshList(out meshCount, out meshList))
239 var stopWatch =
System.Diagnostics.Stopwatch.StartNew();
243 camPos.x, camPos.y, camPos.z,
244 camFwd.x, camFwd.y, camFwd.z,
245 camUp.x, camUp.y, camUp.z,
250 if (stopWatch.Elapsed.TotalMilliseconds > (1000.0 / 30.0))
252 Debug.LogWarningFormat(
"SpatialUnderstandingDll.Imports.GeneratePlayspace_UpdateScan took {0,9:N2} ms", stopWatch.Elapsed.TotalMilliseconds);
260 (!UnderstandingCustomMesh.IsImportActive) &&
261 (UnderstandingCustomMesh != null))
264 StartCoroutine(UnderstandingCustomMesh.Import_UnderstandingMesh());
268 if (OnScanDone != null) OnScanDone.Invoke();