Here is the 8th post in the series of Holographic App Development Using Microsoft HoloLens. In this post we are going to learn about Spatial Mapping and how to render Spatial Mapping Mesh of a real space in your holographic app . Spatial Mapping is one of the most important aspects of the HoloLens and Holographic app development. The Spatial mapping is to know where it is in the real space, how is the real space surface, where are different objects and how you can make holograms interact with the real space. Spatial mapping provides a detailed representation of real-world surfaces in the environment around HoloLens. This allows developers to mix holograms into the world around you.
The Spatial Mapping information can be accessible by Unity3D API’s or using Universal Windows Holographic API’s. Following are the main purposes of using Spatial Mapping in our app.
Refer to the following video to know more details of Spatial mapping
Following are the two primary object types used for spatial mapping for the real space
- Spatial Surface Observer
- Spatial Surface
SurfaceObserver in the application defined region of space that we need spatial mapping data for. Depends on the regions and volume the spatial apping will be provided with information set of Spatial surface.
Read more about Spatial Mapping here :
Rendering the Spatial Mesh
Consider your Unity Solution has HoloLens Unity Toolkit Included and have some object placed in your Unity Solution.
Adding the Spatial Mapping Prefab
Add the Spatial Mapping Prefab (Located in HoloToolkit –> SpatialMapping –>Prefabs) into the root of your Unity Hierarchy.
The SpatialMapping prefabs has three different scripts associated it.
SpatialMappingManager class allows app to use a SurfaceObserver (defined region of space that we need spatial mapping data for) and The SpatialMappingObserver class represent the SurfaceObserver into an easy to use object for the application to get the mapping coordinates to use with holographic apps.
You can use the different set of 2D texture to represent different set of empty objects or background elements from the Inspector tool.
Quick Unity 3D Tips
Unity 3D – How to rotate an object around and also along with a specific point ?
Enabling the Capabilities
From the Build dialog window, navigate to Player Settings. Under Publishing Setting options, navigate to Capabilities, and then enable the SpatialPerception by selecting the checkbox.
Build and Run
Once done, build and run the application on HoloLens emulator. You should be able to see the rendering spatial mesh for the selected room.
Side by side you can open the device portal to see the projection in real space along with the spatial mesh inside HoloLens Emulator.
Explore More with Spatial Mesh along with Room View
Projecting your Holographic apps in a Real Space Surroundings using HoloLens Emulator
This scripts which we have used here, are part of HoloLensToolkit-Unity. Incase you want to explore them by your own and want to use the Unity Specific API, you need to include following two namespaces in your script,
Refer this article for more details API implementations
Hope this helps ! Feel free to share your feedback and don’t hesitate to reach out incase any questions.