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

How to assign a tag to spatial mapping surface

Hi,
i'm building an application using Unity3d, i'd like to know if is there a way to assign a tag to the spatial mapping gameobject? I need to recognize it during the raycast.

Thank you

Marco

Best Answer

  • Options
    ahillierahillier mod
    edited November 2016 Answer ✓

    Hi @Brainy,
    If you want to use tags, then you have to create the tag in the editor first, as you cannot create a new tag during runtime. In general, the 'name' field is a better option. See this unity forum post for more information.

    However, when using raycasts, layers are the preferred approach. With layers, you can raycast to a specific layer (such as the 'SpatialMapping' layer), or to a combination of layers.

    If you did our Holograms 101 course, we set Layer 31 to be the spatial mapping layer, and all newly created spatial mapping meshes are assigned that layer. We can then perform a raycast against only that layer when we are placing objects on real-world surfaces (example below is from 'TapToPlaceParent.cs'):

            if (placing)
            {
                // Do a raycast into the world that will only hit the Spatial Mapping mesh.
                var headPosition = Camera.main.transform.position;
                var gazeDirection = Camera.main.transform.forward;
    
                RaycastHit hitInfo;
                if (Physics.Raycast(headPosition, gazeDirection, out hitInfo,
                    30.0f, SpatialMapping.PhysicsRaycastMask))
                {
                    // Do stuff...
                }
            }
    

    If you're using the prefab from HoloToolkit or the Holograms 230 course, it names each mesh coming from the HoloLens with the prefix 'Surface-' (Surface-0, Surface-1, Surface-2, etc) and assigns each mesh to layer 31. So, if you only want to do a single raycast across multiple layers (including the spatial mapping layer), then you would need to check either the layer, or the name of the gameObject that was hit, to see if it belongs to the spatial mapping mesh before decided how to respond to the raycast hit.

Answers

  • Options
    ahillierahillier mod
    edited November 2016 Answer ✓

    Hi @Brainy,
    If you want to use tags, then you have to create the tag in the editor first, as you cannot create a new tag during runtime. In general, the 'name' field is a better option. See this unity forum post for more information.

    However, when using raycasts, layers are the preferred approach. With layers, you can raycast to a specific layer (such as the 'SpatialMapping' layer), or to a combination of layers.

    If you did our Holograms 101 course, we set Layer 31 to be the spatial mapping layer, and all newly created spatial mapping meshes are assigned that layer. We can then perform a raycast against only that layer when we are placing objects on real-world surfaces (example below is from 'TapToPlaceParent.cs'):

            if (placing)
            {
                // Do a raycast into the world that will only hit the Spatial Mapping mesh.
                var headPosition = Camera.main.transform.position;
                var gazeDirection = Camera.main.transform.forward;
    
                RaycastHit hitInfo;
                if (Physics.Raycast(headPosition, gazeDirection, out hitInfo,
                    30.0f, SpatialMapping.PhysicsRaycastMask))
                {
                    // Do stuff...
                }
            }
    

    If you're using the prefab from HoloToolkit or the Holograms 230 course, it names each mesh coming from the HoloLens with the prefix 'Surface-' (Surface-0, Surface-1, Surface-2, etc) and assigns each mesh to layer 31. So, if you only want to do a single raycast across multiple layers (including the spatial mapping layer), then you would need to check either the layer, or the name of the gameObject that was hit, to see if it belongs to the spatial mapping mesh before decided how to respond to the raycast hit.

Sign In or Register to comment.