Last active
January 25, 2017 22:26
-
-
Save CameronVetter/fddc0928d44a3af9f36b1f28eeeaa4c2 to your computer and use it in GitHub Desktop.
SpatialUnderstandingState.cs - Part 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
using HoloToolkit.Unity; | |
using HoloToolkit.Unity.SpatialMapping; | |
public class SpatialUnderstandingState : Singleton<SpatialUnderstandingState> | |
{ | |
public float MinAreaForStats = 5.0f; | |
public TextMesh DebugDisplay; | |
public TextMesh DebugSubDisplay; | |
private bool _triggered; | |
public bool HideText = false; | |
private string _spaceQueryDescription; | |
public string SpaceQueryDescription | |
{ | |
get | |
{ | |
return _spaceQueryDescription; | |
} | |
set | |
{ | |
_spaceQueryDescription = value; | |
} | |
} | |
public string PrimaryText | |
{ | |
get | |
{ | |
if (HideText) | |
return string.Empty; | |
// Display the space and object query results (has priority) | |
if (!string.IsNullOrEmpty(SpaceQueryDescription)) | |
{ | |
return SpaceQueryDescription; | |
} | |
// Scan state | |
if (SpatialUnderstanding.Instance.AllowSpatialUnderstanding) | |
{ | |
switch (SpatialUnderstanding.Instance.ScanState) | |
{ | |
case SpatialUnderstanding.ScanStates.Scanning: | |
// Get the scan stats | |
IntPtr statsPtr = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticPlayspaceStatsPtr(); | |
if (SpatialUnderstandingDll.Imports.QueryPlayspaceStats(statsPtr) == 0) | |
{ | |
return "playspace stats query failed"; | |
} | |
return "Walk around and scan in your playspace"; | |
case SpatialUnderstanding.ScanStates.Finishing: | |
return "Finalizing scan (please wait)"; | |
case SpatialUnderstanding.ScanStates.Done: | |
return "Scan complete"; | |
default: | |
return "ScanState = " + SpatialUnderstanding.Instance.ScanState; | |
} | |
} | |
return string.Empty; | |
} | |
} | |
public Color PrimaryColor | |
{ | |
get | |
{ | |
return Color.white; | |
} | |
} | |
public string DetailsText | |
{ | |
get | |
{ | |
if (SpatialUnderstanding.Instance.ScanState == SpatialUnderstanding.ScanStates.None) | |
{ | |
return ""; | |
} | |
// Scanning stats get second priority | |
if ((SpatialUnderstanding.Instance.ScanState == SpatialUnderstanding.ScanStates.Scanning) && | |
(SpatialUnderstanding.Instance.AllowSpatialUnderstanding)) | |
{ | |
IntPtr statsPtr = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticPlayspaceStatsPtr(); | |
if (SpatialUnderstandingDll.Imports.QueryPlayspaceStats(statsPtr) == 0) | |
{ | |
return "Playspace stats query failed"; | |
} | |
SpatialUnderstandingDll.Imports.PlayspaceStats stats = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticPlayspaceStats(); | |
// Start showing the stats when they are no longer zero | |
if (stats.TotalSurfaceArea > MinAreaForStats) | |
{ | |
SpatialMappingManager.Instance.DrawVisualMeshes = false; | |
string subDisplayText = string.Format("totalArea={0:0.0}, horiz={1:0.0}, wall={2:0.0}", stats.TotalSurfaceArea, stats.HorizSurfaceArea, stats.WallSurfaceArea); | |
subDisplayText += string.Format("\nnumFloorCells={0}, numCeilingCells={1}, numPlatformCells={2}", stats.NumFloor, stats.NumCeiling, stats.NumPlatform); | |
subDisplayText += string.Format("\npaintMode={0}, seenCells={1}, notSeen={2}", stats.CellCount_IsPaintMode, stats.CellCount_IsSeenQualtiy_Seen + stats.CellCount_IsSeenQualtiy_Good, stats.CellCount_IsSeenQualtiy_None); | |
return subDisplayText; | |
} | |
return ""; | |
} | |
return ""; | |
} | |
} | |
private void Update_DebugDisplay() | |
{ | |
// Basic checks | |
if (DebugDisplay == null) | |
{ | |
return; | |
} | |
// Update display text | |
DebugDisplay.text = PrimaryText; | |
DebugDisplay.color = PrimaryColor; | |
DebugSubDisplay.text = DetailsText; | |
} | |
// Update is called once per frame | |
private void Update() | |
{ | |
// Updates | |
Update_DebugDisplay(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment