8 using System.Collections.Generic;
12 #if UNITY_WSA || UNITY_STANDALONE_WIN 16 namespace HoloToolkit.Examples.SpatialUnderstandingFeatureOverview
21 public float kMinAreaForStats = 5.0f;
22 public float kMinAreaForComplete = 50.0f;
23 public float kMinHorizAreaForComplete = 25.0f;
24 public float kMinWallAreaForComplete = 10.0f;
34 public string SpaceQueryDescription
38 return spaceQueryDescription;
42 spaceQueryDescription = value;
43 objectPlacementDescription =
"";
47 public string ObjectPlacementDescription
51 return objectPlacementDescription;
55 objectPlacementDescription = value;
56 spaceQueryDescription =
"";
60 public bool DoesScanMeetMinBarForCompletion
80 if ((stats.TotalSurfaceArea > kMinAreaForComplete) ||
81 (stats.HorizSurfaceArea > kMinHorizAreaForComplete) ||
82 (stats.WallSurfaceArea > kMinWallAreaForComplete))
90 public string PrimaryText
95 if (!
string.IsNullOrEmpty(SpaceQueryDescription))
97 return SpaceQueryDescription;
99 else if (!
string.IsNullOrEmpty(ObjectPlacementDescription))
101 return ObjectPlacementDescription;
114 return "playspace stats query failed";
118 if (DoesScanMeetMinBarForCompletion)
120 return "When ready, air tap to finalize your playspace";
122 return "Walk around and scan in your playspace";
124 return "Finalizing scan (please wait)";
126 return "Scan complete - Use the menu to run queries";
135 public Color PrimaryColor
141 if (trackedHandsCount > 0)
143 return DoesScanMeetMinBarForCompletion ? Color.green : Color.red;
145 return DoesScanMeetMinBarForCompletion ? Color.yellow : Color.white;
149 Vector3 hitPos, hitNormal;
151 float alpha = AppCursor.
RayCastUI(out hitPos, out hitNormal, out hitButton) ? 0.15f : 1.0f;
154 return (!
string.IsNullOrEmpty(SpaceQueryDescription) || !
string.IsNullOrEmpty(ObjectPlacementDescription)) ?
155 (PrimaryText.Contains(
"processing") ?
new Color(1.0f, 0.0f, 0.0f, 1.0f) :
new Color(1.0f, 0.7f, 0.1f, alpha)) :
156 new Color(1.0f, 1.0f, 1.0f, alpha);
160 public string DetailsText
176 return "Playspace stats query failed";
181 if (stats.TotalSurfaceArea > kMinAreaForStats)
183 string subDisplayText =
string.Format(
"totalArea={0:0.0}, horiz={1:0.0}, wall={2:0.0}", stats.TotalSurfaceArea, stats.HorizSurfaceArea, stats.WallSurfaceArea);
184 subDisplayText +=
string.Format(
"\nnumFloorCells={0}, numCeilingCells={1}, numPlatformCells={2}", stats.NumFloor, stats.NumCeiling, stats.NumPlatform);
185 subDisplayText +=
string.Format(
"\npaintMode={0}, seenCells={1}, notSeen={2}", stats.CellCount_IsPaintMode, stats.CellCount_IsSeenQualtiy_Seen + stats.CellCount_IsSeenQualtiy_Good, stats.CellCount_IsSeenQualtiy_None);
186 return subDisplayText;
195 private string spaceQueryDescription;
196 private string objectPlacementDescription;
197 private uint trackedHandsCount = 0;
198 #if UNITY_WSA || UNITY_STANDALONE_WIN 199 private KeywordRecognizer keywordRecognizer;
206 Parent_Scene.transform.position = sceneOrigin;
211 var keywordsToActions =
new Dictionary<string, Action>
213 {
"Toggle Scanned Mesh", ToggleScannedMesh },
214 {
"Toggle Processed Mesh", ToggleProcessedMesh },
217 keywordRecognizer =
new KeywordRecognizer(keywordsToActions.Keys.ToArray());
218 keywordRecognizer.OnPhraseRecognized += args => keywordsToActions[args.text].Invoke();
219 keywordRecognizer.Start();
228 private void Update_DebugDisplay(
float deltaTime)
231 if (DebugDisplay == null)
237 DebugDisplay.text = PrimaryText;
238 DebugDisplay.color = PrimaryColor;
239 DebugSubDisplay.text = DetailsText;
242 private void Update_KeyboardInput(
float deltaTime)
245 if (Input.GetKeyDown(KeyCode.BackQuote) &&
246 (!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift)))
250 else if (Input.GetKeyDown(KeyCode.BackQuote) &&
251 (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
253 ToggleProcessedMesh();
257 private static void ToggleScannedMesh()
263 private static void ToggleProcessedMesh()
266 Debug.Log(
"SpatialUnderstanding -> SpatialUnderstanding.Instance.UnderstandingCustomMesh.DrawProcessedMesh=" +
SpatialUnderstanding.
Instance.UnderstandingCustomMesh.DrawProcessedMesh);
269 private void Update()
271 Update_DebugDisplay(Time.deltaTime);
272 Update_KeyboardInput(Time.deltaTime);