How to get visual part of the Spatial Mesh

Hi Guys,

I’m using the Spatial Mapping example from the Holograms 230 tutorial to create a mesh of the room. How can I get only the visual meshes, so the meshes that are currently in the field of vision?

My goals is to create a “heatmap” that indicates the distance between different surfaces and the user.

Thanks!

Hello,

The tutorial is a Microsoft project that uses the Holotool kit, the visual meshes usually are controlled by a shaders and materials.

In 5.5 and 5.6 you can use the spatial mapping Renderer component and render the visual mesh. If you use the default material for the visual mesh, it will add color to the mesh based on how far you are from the mesh.

Here are the numbers for the default materials colors:

  • A wireframe Shader that applies to all the component’s surfaces. The colors of the wireframe represent distances. The following are the distance-to-color mappings.

  • 0 to 1 meters = Black

  • 1 to 2 meters = Red

  • 2 to 3 meters = Green

  • 3 to 4 meters = Blue

  • 4 to 5 meters = Yellow

  • 5 to 6 meters = Cyan

  • 6 to 7 meters = Magenta

  • 7 to 8 meters = Maroon

  • 8 to 9 meters = Teal

  • 9 to 10 meters = Orange

  • 10 meters or greater = White

https://docs.unity3d.com/Manual/windowsholographic-sm-component.html

You can create your own materials for the visual mesh to create a similar affect, this might be able to give you a start.

Let me know if you have questions

Thank you,
Wesley

2 Likes

Hey Wesley,

Thank you for your answer, this seems to be more or less what I need. But I’m not quite sure how to use the spatial renderer component. If I add it to the Spatial Mapping Prefab of my current project, nothing happens and I’m not even able to access and edit the script. Same happens when I create a new Project and add the component to a new game object → nothing happens, can’t edit…

How am I supposed to use this?

Thanks!

Hello @CornKrue ,

When you drop the spatial rendering component into a scene, the default setting for Render State is occlusion which is set to be transparent. You need to change the Render State to Visualization, here is the link to the documentation.

https://docs.unity3d.com/Manual/windowsholographic-sm-component.html

You can access the the components through script by using UnityEngine.VR.WSA; then you can access the components.

1 Like

Thank you very much, its working!

Sorry for my inexperience: Do I understand it right, I can only access the component via the namespace UnityEngine.VR.WSA and use or override functions? Can’t I change the script itself to e.g. changing the color order (e.g. 0 -1 = darkred, 1 - 2 = red, 2 - 3 = light red) or the ranges (0.1 - 0.2 m …) and most importantly, get the distance values?

Want I want to achieve is an array (e.g. 36 x 24) that represent the field of vision of the HoloLens and every data point shows the distance to the nearest edge / vertex of the Spatial Mesh at this point. I therefore need to adapt the spatial mapping Renderer script or at least view the code of it.

You can access the component through the namespace to change the settings via script inside your app or game during runtime.

IT sounds like what you want to do is create a custom wireframe shader that will render what you want to see on a material. You can find information on this in our documentation in the unity manual.

Link:

You can compile and view the code of the default shader for the visual mesh, but I would recommend creating your own.