HoloLens Tutorial – Finalize Spatial Understanding

Last Updated: Apr 24, 2017

Tutorial Accomplishments

  1. Test for Spatial Understanding Completeness
  2. Add Input Manager
  3. Finalizing Spatial Understanding

 

This section of the tutorial will wrap up spatial mapping and spatial understanding setting us up to place some holograms in the next section. First we will test to make sure we have a certain level of quality in our spatial understanding. Second when the spatial understanding is high enough quality the user can air tap to Finalize Spatial Understanding.

 

Test for Spatial Understanding Completeness

Open SpatialUnderstandingState.cs and make these changes:

These changes cause the Primary Text color to change from White to Yellow when spatial understanding criteria specified in constants is met. The first change is made to the Get property of PrimaryColor. In the previous version it always returned White. This makes a call to DoesScanMeetMinBarForCompletion to determine if  the criteria have been met. In this method we call SpatialUnderstandingDll.Imports.QueryPlayspaceStats which returns an object of PlayspaceStats. This method compares the constants that have been added to determine if our spatial understanding is good enough for the application to continue.

 

Add Input Manager

To finalize spatial understanding the user will air tap. In order to detect user input from the HoloLens the HoloToolkit provides the Input Manager. Open the project in Unity and Add a new gameobject named “Control” in the Hierarchy. Drag the InputManager.prefab from the HoloToolkit (in the Input, Prefabs folder) into the new Control object. This results in a few gameobjects and components getting added to the Control Gameobject. This is everything that is needed to detect input from the HoloLens. The project should now look like this:

Finalizing Spatial Understanding

When the spatial understanding is good enough for our app, the message should both change color and instructions.  The instructions will also change to tell the user to air tap in order to finish mapping.

Update SpatialUnderstandingState.CS to this:

The class now implements the interfaces IInputClickHandler and ISourceStateHandler.  These interfaces contain OnInputClickedOnSourceDetected, and OnSourceLost.  The Start method is added making a call to the input manager telling it that this gameobject will subscribe to the input events.  When these events occur the methods implemented by the interfaces are called notifying this class of user input.  Visible hands detected are tracked so that the application can respond to the users hand coming into view. Air taps are detected allowing the user to finalize spatial understanding by calling RequestFinishScan which finalizes spatial understanding. Build the app and run it on the HoloLens.  Map your room and air tap to finalize spatial understanding.  Notice that after finalization is complete all of the gaps in the spatial map are approximated based on the rest of the spatial map.  This is done to make the spatial understanding “water tight” so there is not ambiguity on how objects should be placed.  Be careful not to allow the user to finalize with too many gaps in the spatial understanding or the results of object placement may be disappointing.

 

Tutorial Index

  Versions: Unity 2017.1.0p5 | MixedRealityToolkit-Unity v1.2017.1.0Visual Studio 2017 15.3.2
Unity 3D Project Creation How to create a HoloLens project in Unity 3D
Source Control Configure git for HoloLens / Unity work
Spatial Mapping How to spatial map a Room
Object Surface Observer Set up fake spatial map data for the Unity editor
TagAlongs and Billboarding   Tag along instructions to the user to force text on screen
Spatial Understanding Add spatial understanding to get play space detail
Finalizing Spatial Understanding Complete Spatial Understanding and Input Manager
Object Placement and Scaling Find valid locations for holograms in the play space
Hologram Management Manage the holograms you want to place in the world
Cursor and Voice Add a cursor and voice commands
Occlusion Add occlusion with the real world to your scene
Colliders and Rigidbodys Add Colliders and RigidBodys to your holograms

4 thoughts on “HoloLens Tutorial – Finalize Spatial Understanding

  • Posted on January 18, 2017 at 2:50 pm

    Following your tutorial. It’s been great.
    When will the next ones be up? Really interested in how you place your holograms and objects.
    Thanks!

    Reply
    • Posted on January 19, 2017 at 11:27 am

      I hope to add the next section of the tutorial next week, changes in the HoloToolkit have caused me to have to go back and redo some code…

      Reply
  • Posted on February 11, 2017 at 11:57 pm

    I’m not sure if I have an old or new version of Holotoolkit, but for this to work I had to update line 204:

    void IInputClickHandler.OnInputClicked(InputEventData eventData)

    to

    void IInputClickHandler.OnInputClicked(InputClickedEventData eventData)

    Reply
    • Posted on February 12, 2017 at 10:37 am

      You have a newer version of the HoloToolkit, that change appeared on Jan 14th, it moves fast…

      Reply

Leave a Reply