#Hololens – #SpatialMapping, tutorial search for simple surfaces (1×1 floor tile)

Hi !

In my previous posts I wrote on how to use Spatial Understanding to have a better control of the environment scanning process with Hololens. In that post I created a demo with the following steps

  • As soon as the App starts, Hololens started the scanning process
  • We defined a minimmun number of planes to be found, when we reach this number the scan process stopped
  • We have a FPS displaying the scan process

Today’s sample is the next required steps after last post to

  • Search for a simple surface in the floor with a size of 1×1
  • We start this search process with an AirTap / Click on a hologram

The next ugly animation shows the scanning process (at X6 speed) and then the floor mapping process.

2017 04 25 Hololens Spatial Understanding 01.gif

Tutorial simple steps.

  1. Create a 3D project in Unity3D
  2. Import HoloToolkit package
  3. Configure project to
    1. Support HoloLens projects (UWP, VR, etc)
    2. enable Spatial Mapping feature
  4. Clean Scene elements
  5. Add
    1. Hololens Camera
    2. Cursor With Feedback
    3. Input Manager
    4. Spatial Mapping
    5. Spatial Understanding
    6. FPS Display
  6. Add Empty element
    1. Rename to CodeManagers
    2. Add new C# Script named “GameStartScanner.cs”
  7. Add Empty Element
    1. Rename to HoloCollection
    2. Add 3D Cube element to HoloCollection
    3. Rename to “InteractiveCube”
  8. Set this properties to Cube
    1. Position: x: 0, y:0, z:1.2
    2. Scale: x: 0.2, y:0.2, z:0.2
  9. Add a new C# Script to the cube named “Scanner Analyzer”

The final project must be similar to this one


The source code for the ScannerAnalyzer.cs script is below. As always a couple of important notes on this script.

  • The sample is based on the Spatial Mapping sample included on HoloToolkit
  • I use several additional classes (mostly for drawing), you can find this classes as part of the project
    • AnimatedBox.cs
    • AnimationCurve3.cs
    • GameStartScanner.cs
    • Line.cs
    • LineData.cs
    • ScannerAnalyzer.cs
  • In simple terms, the new class starts when the scanning process stops. As a reminder the scanning process was defined in “GameStartScanner.cs”
  • In the Update() function we check if we are in “search tile process”. If we are looking, we draw blue tiles on the floor
  • The search process start on “OnInputClicked”, this one is triggered on an AirTap on he Cube
  • The variables minWidthOfWallSpace and minHeightAboveFloor defines the size of the tile to search
  • Line 54, this is the important section. Here we use the core of Spatial Understanding to start the search process. We use the functions
    • SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(_resultsTopology);
    • SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnFloor()
  • The 1st steps create a memory pointer with all the scanned elements. 2nd steps filter this for the elements which matches the query
  • The next lines are drawing lines. Most of this code is based on HoloToolkit Spatial Mapping samples. Tons on C# lines of code, which requires a nice refactoring

Sample code

You can download the complete code from GitHub (link).

Greetings @ Toronto

El Bruno


21 thoughts on “#Hololens – #SpatialMapping, tutorial search for simple surfaces (1×1 floor tile)”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.