Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Windows Mixed Reality notify when Spatial Mapping Collider has a mesh.

Discussion in 'VR' started by theDawckta, Oct 10, 2018.

  1. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    50
    Hello!

    I am working on HoloLens project and can't for the life of me figure out how I can tell when there is an actual mesh is the scene that I can use to raycast against. Currently I have dependencies on spatial mapping that cannot run properly if there is not a spatial map collider created in the scene. I would think there would be some event that I could subscribe to or something that I could use to start the rest of my app when i know there is a spatial collider there.

    This has got to be something simple, please help!
     
  2. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    407
  3. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    50
    I have but the Spatial Mapping Collider component is doing everything I need just fine besides knowing when the mesh is available. Is it a better route to just pull what I need out of the toolkit (SpatialMappingManager/SpatialMappingObserver) and not use Spatial Mapping Collider?
     
  4. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    407
    I dug into this a bit, and it doesn't appear it's worthwhile to pull Spatial Mapping functionality out of HoloToolkit. That component is pretty well integrated into their SpatialMappingManager.

    So, instead here's a possible solution using SpatialMappingCollider: assign your own GameObject to the "SurfaceParent" property (in the Editor or in code). All surface object's created by SpatialMapping will be set as a child of this GO allowing you to query for MeshCollider components, indicating valid spatial mesh objects are present.

    Here's an example of using the SurfaceParent:

    Code (CSharp):
    1. public class SurfaceParent : MonoBehaviour {
    2.  
    3.     private bool foundCollider = false;
    4. ...
    5.     // Update is called once per frame
    6.     void Update () {
    7.  
    8.         if (!foundCollider)
    9.         {
    10.             var collider = gameObject.GetComponentInChildren<MeshCollider>();
    11.             if (collider != null)
    12.             {
    13.                 foundCollider = true;
    14.             }
    15.         }
    16.     }
    17. ...
    18.  

    I hope this helps.
     
  5. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    50
    Thanks for the reply! I ended up just adding the HoloToolkit into my project as pulling just the SpatialMapping stuff out of there was a pain (so many dependencies in there). I figure by the time this project is over Iw ill find more stuff I can use in there.

    I still am not using an event to know when I have a spatial surface however. I ended up using a RayCast when my project starts to see when I am staring at a spatial surface for 1 second then kick off my initialize functions. I figure if I am staring at a spatial surface for a second then it should be good to go.

    Thanks again for getting back to me!