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.
Options

Miniature Map

Hi,

I'm using Spatial Mapping and Spatial Processing prefabs present in Holograms 230. I scan a room for 10 seconds and then once I have the mesh I make a copy of it using Instantiate and setting the scale of the new mesh to 1/7 of the original one to make a miniature version of the original scanned space.

When I run the code in Unity in editor mode, loading a space that was previously saved (as detailed in Holograms 230) I see that the miniature map looks exactly the same as the original one. Nevertheless, when I do this in real-time on the Hololens the copied mini mesh doesn't match the original mesh scanned through Spatial Mapping (seems like the triangles don't get copied in the right location).

Any ideas why this could be? I'm including pictures but it's a bit hard to see.

Thank you!

Best Answer

  • Options
    PatrickPatrick mod
    Answer ✓

    Hi Cdor,
    A couple of things might trip you up here.
    First, if you are instantiating the original spatial mapping object, I would guess that a world anchor gets attached to the new object. You need to remove that world anchor before changing the transform of the object. To be honest, I would not clone the original object, but instead instantiate a prefab that has a meshfilter and meshrenderer, and clone the vertices.

    Second, you likely need to transform your vertices based on the Mesh Filter. On the HoloLens the vertices of the meshes are relative to the mesh filter transform. In the Unity Editor the vertices are relative to the origin of the scene. So in the HoloLens you need to get your vertices relative to the origin of the scene. You can do so with code like (I haven't tested this, so it might need a tweak):

    List<MeshFilter> MeshFilters = SpatialMappingManager.Instance.GetMeshFilters();
                for (int index = 0; index < MeshFilters.Count; index++)
                {
                    MeshFilter filter = MeshFilters[index];
                    Mesh source = filter.sharedMesh;
                    Mesh clone = new Mesh();
                    List<Vector3> verts = new List<Vector3>();
                    verts.AddRange(source.vertices);
    
                    for(int vertIndex=0; vertIndex < verts.Count; vertIndex++)
                    {
                        verts[vertIndex] = filter.transform.TransformPoint(verts[vertIndex]);
                    }
    
                    clone.SetVertices(verts); 
                    clone.SetTriangles(source.triangles, 0);
    GameObject nextMiniMap = Instantiate(MiniMapPrefabMesh); 
    nextMiniMap.GetComponent<MeshFilter>().sharedMesh = clone;
    
                }
    

    ===
    This post provided as-is with no warranties and confers no rights. Using information provided is done at own risk.

    (Daddy, what does 'now formatting drive C:' mean?)

Answers

  • Options
    PatrickPatrick mod
    Answer ✓

    Hi Cdor,
    A couple of things might trip you up here.
    First, if you are instantiating the original spatial mapping object, I would guess that a world anchor gets attached to the new object. You need to remove that world anchor before changing the transform of the object. To be honest, I would not clone the original object, but instead instantiate a prefab that has a meshfilter and meshrenderer, and clone the vertices.

    Second, you likely need to transform your vertices based on the Mesh Filter. On the HoloLens the vertices of the meshes are relative to the mesh filter transform. In the Unity Editor the vertices are relative to the origin of the scene. So in the HoloLens you need to get your vertices relative to the origin of the scene. You can do so with code like (I haven't tested this, so it might need a tweak):

    List<MeshFilter> MeshFilters = SpatialMappingManager.Instance.GetMeshFilters();
                for (int index = 0; index < MeshFilters.Count; index++)
                {
                    MeshFilter filter = MeshFilters[index];
                    Mesh source = filter.sharedMesh;
                    Mesh clone = new Mesh();
                    List<Vector3> verts = new List<Vector3>();
                    verts.AddRange(source.vertices);
    
                    for(int vertIndex=0; vertIndex < verts.Count; vertIndex++)
                    {
                        verts[vertIndex] = filter.transform.TransformPoint(verts[vertIndex]);
                    }
    
                    clone.SetVertices(verts); 
                    clone.SetTriangles(source.triangles, 0);
    GameObject nextMiniMap = Instantiate(MiniMapPrefabMesh); 
    nextMiniMap.GetComponent<MeshFilter>().sharedMesh = clone;
    
                }
    

    ===
    This post provided as-is with no warranties and confers no rights. Using information provided is done at own risk.

    (Daddy, what does 'now formatting drive C:' mean?)

  • Options

    @Patrick said:
    Hi Cdor,
    A couple of things might trip you up here.
    First, if you are instantiating the original spatial mapping object, I would guess that a world anchor gets attached to the new object. You need to remove that world anchor before changing the transform of the object. To be honest, I would not clone the original object, but instead instantiate a prefab that has a meshfilter and meshrenderer, and clone the vertices.

    Second, you likely need to transform your vertices based on the Mesh Filter. On the HoloLens the vertices of the meshes are relative to the mesh filter transform. In the Unity Editor the vertices are relative to the origin of the scene. So in the HoloLens you need to get your vertices relative to the origin of the scene. You can do so with code like (I haven't tested this, so it might need a tweak):

    List<MeshFilter> MeshFilters = SpatialMappingManager.Instance.GetMeshFilters();
                for (int index = 0; index < MeshFilters.Count; index++)
                {
                    MeshFilter filter = MeshFilters[index];
                    Mesh source = filter.sharedMesh;
                    Mesh clone = new Mesh();
                    List<Vector3> verts = new List<Vector3>();
                    verts.AddRange(source.vertices);
                
                    for(int vertIndex=0; vertIndex < verts.Count; vertIndex++)
                    {
                        verts[vertIndex] = filter.transform.TransformPoint(verts[vertIndex]);
                    }
    
                    clone.SetVertices(verts); 
                    clone.SetTriangles(source.triangles, 0);
    GameObject nextMiniMap = Instantiate(MiniMapPrefabMesh); 
    nextMiniMap.GetComponent<MeshFilter>().sharedMesh = clone;
                  
                }
    

    do you have the complete code ,thankyou very much

Sign In or Register to comment.