Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

Saving and Displaying Spatial Mapping Mesh

I'm trying to save the mesh created by the hololen's spatial mapping feature. What I want to do is the following

  • Map the room for some period of time
  • Save the mesh created by spatial mapping
  • Display that mesh as a hologram, e.g. a miniature version of the map

I am aware that you can download the mesh as a .obj file from device portal, but I need to do this within a script.

What I have been trying, with limited success, is calling SpatialMappingManager.Instance.GetMeshes(), then drawing these meshes in a new gameobject.

The problem is, when I draw the meshes I capture from the spatial mapping manager, they draw as a completely unrecognizable, jumbled mess in a cube.

So I'm capturing something, but when I draw it the output is not at all what I'm expecting, and least of all a map of the room I'm in.

Here is some of the code I'm using:

 //this runs after mapping the room for some period of time. 
    if(stopCount == 1)
        stateDisplay.text = "Drawing";          
        spatialMeshes = SpatialMappingManager.Instance.GetMeshes();     

        meshCount = spatialMeshes.Count;
        meshCountDisplay.text = "Meshcount = " + meshCount;
        SpatialMappingManager.Instance.DrawVisualMeshes = false;
        //SpatialMappingManager.Instance.enabled = false; //Hopefully this turns off spatial mapping but who knows 
        for (int i = 0; i < meshCount; i++)
            totalVerts += spatialMeshes[i].vertexCount;
        vertCountDisplay.text = "Total Vertexes = " + totalVerts;
        totalVerts = 0;
        stopCount = 5; //So this block only gets run once. 


  //This draws the meshes I'm capturing from spatial mapping 
public void drawMesh(Mesh meshIn)
    var spatialMesh = new GameObject();
    spatialMesh.GetComponent<MeshFilter>().mesh = meshIn;
    //spatialMesh.GetComponent<MeshFilter>().mesh.RecalculateNormals(); //I dunno if this will do anything useful 
    spatialMesh.GetComponent<Renderer>().material = material;       
    spatialMesh.transform.parent = meshObject.transform;
    spatialMesh.transform.position = meshObject.transform.position;
    spatialMesh.transform.localScale = meshObject.transform.localScale;     

Any advice or suggestions are appreciated. Thank you.

Sign In or Register to comment.