Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

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.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. 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. And always feel free to hit us up on Twitter @MxdRealityDev.

How to get 3d-points(x, y, z) data of Spatial Mapping Mesh??

Hi, I'm doing some projects for HoloLens

I want to get data for all points of Spatial Mapping Meshes

Does anyone have any idea for this?

Thanks

Best Answer

  • trzytrzy ✭✭✭
    Accepted Answer

    @Buster Sounds like you want to get the mesh data, which will give you all vertices. Assuming you've scanned your space using the SpatialMappingManager, you can get all the mesh filter objects like so:

    List< MeshFilter > meshFilters = SpatialMappingManager.Instance.GetMeshFilters();

    Then, you can access the mesh or sharedMesh (they will be the same for spatial mapping meshes, although I think accessing sharedMesh will prevent a needless copy from being made by Unity internally) property of each spatial mesh filter:

    foreach (MeshFilter meshFilter in meshFilters)
    {
    DoSomething(meshFilter.sharedMesh);
    }

    As for how the mesh object itself works, the Unity scripting reference is your friend: https://docs.unity3d.com/ScriptReference/Mesh.html

    Long story short, you can simply access the vertices property (which will create a copy of the data for you). This is an array of points (Vector3). Spatial meshes don't have any transforms applied, if I remember correctly, so the points should already be in world space but you might want to check that to be sure.

    If you want the raw point cloud from the depth camera, you're out of luck. Meshes is all we're allowed to get.

Answers

  • ReeleyReeley ✭✭✭
    edited July 2017

    The SpatialMapping creates a gameobject for each face found with the naming convention "Surface-" + someId. So you could Find all gameobjects which start with the name "Surface-"

  • trzytrzy ✭✭✭
    Accepted Answer

    @Buster Sounds like you want to get the mesh data, which will give you all vertices. Assuming you've scanned your space using the SpatialMappingManager, you can get all the mesh filter objects like so:

    List< MeshFilter > meshFilters = SpatialMappingManager.Instance.GetMeshFilters();

    Then, you can access the mesh or sharedMesh (they will be the same for spatial mapping meshes, although I think accessing sharedMesh will prevent a needless copy from being made by Unity internally) property of each spatial mesh filter:

    foreach (MeshFilter meshFilter in meshFilters)
    {
    DoSomething(meshFilter.sharedMesh);
    }

    As for how the mesh object itself works, the Unity scripting reference is your friend: https://docs.unity3d.com/ScriptReference/Mesh.html

    Long story short, you can simply access the vertices property (which will create a copy of the data for you). This is an array of points (Vector3). Spatial meshes don't have any transforms applied, if I remember correctly, so the points should already be in world space but you might want to check that to be sure.

    If you want the raw point cloud from the depth camera, you're out of luck. Meshes is all we're allowed to get.

  • BusterBuster
    edited July 2017

    @trzy Thank you for reply. As I checked your reply so late, I'd found to get vertices like you said, use MeshFilter.sharedMesh.vertices

    this method can read/write vertices So is what I've been looking for.

  • @trzy said:
    @Buster Sounds like you want to get the mesh data, which will give you all vertices. Assuming you've scanned your space using the SpatialMappingManager, you can get all the mesh filter objects like so:

    List< MeshFilter > meshFilters = SpatialMappingManager.Instance.GetMeshFilters();

    Then, you can access the mesh or sharedMesh (they will be the same for spatial mapping meshes, although I think accessing sharedMesh will prevent a needless copy from being made by Unity internally) property of each spatial mesh filter:

    foreach (MeshFilter meshFilter in meshFilters)
    {
    DoSomething(meshFilter.sharedMesh);
    }

    As for how the mesh object itself works, the Unity scripting reference is your friend: https://docs.unity3d.com/ScriptReference/Mesh.html

    Long story short, you can simply access the vertices property (which will create a copy of the data for you). This is an array of points (Vector3). Spatial meshes don't have any transforms applied, if I remember correctly, so the points should already be in world space but you might want to check that to be sure.

    If you want the raw point cloud from the depth camera, you're out of luck. Meshes is all we're allowed to get.

    Spatial Meshes do indeed have WorldAnchors on them though. If you want to capture and reload them, you will need to save off the world anchor that corresponds to the mesh.

Sign In or Register to comment.