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

Highlight Spatial Mesh polygon where collision occurs

Hello everyone,

For my application I would like to identify where collisions between my holograms and the Spatial Mesh occur. Is there a way to "paint" (e.g. with red) the exact Spatial Mesh polygon (where the collision occured) that caused the collision?

Thanks in advance,
Michael

Answers

  • Options

    I think the Holographic Academy can help you. The course Holograms 101 demonstrates HoloLens features including spatial mapping https://developer.microsoft.com/en-us/windows/holographic/holograms_101

  • Options

    Thanks askrips! However, I have gone through 101 but I still cannot understand how to identify where the collision was made and highlight the Spatial Mesh polygon. Any other ideas?

  • Options
    james_ashleyjames_ashley ✭✭✭✭
    edited December 2016

    @mdouk,

    You should be able to get a reference to the mesh you're hologram is colliding with using the OnTriggerEnter method. Here are the basics on using it, though you probably will want to find a video explaining how to use it for collision detection if you aren't already familiar, since there are a few gotchas.

    I believe OnTriggerEnter will pass you the collider, from which you can get the spatial mapping Surface object. From that, in turn, you can grab the mesh renderer and activate it like so:

        public void OnTriggerEnter(Collider other)
        {
            GameObject surface = other.gameObject;
            Renderer renderer = surface.GetComponent<MeshRenderer>();
            renderer.enabled = true;
        }
    

    At least I think this will work. I'd have to get to my dev computer to test it out.

    James Ashley
    VS 2017 v5.3.3, Unity 2017.3.0f3, MRTK 2017.1.2, W10 17063
    Microsoft MVP, Freelance HoloLens/MR Developer
    www.imaginativeuniversal.com

  • Options

    @james_ashley said:
    @mdouk,

    You should be able to get a reference to the mesh you're hologram is colliding with using the OnTriggerEnter method. Here are the basics on using it, though you probably will want to find a video explaining how to use it for collision detection if you aren't already familiar, since there are a few gotchas.

    I believe OnTriggerEnter will pass you the collider, from which you can get the spatial mapping Surface object. From that, in turn, you can grab the mesh renderer and activate it like so:

        public void OnTriggerEnter(Collider other)
        {
            GameObject surface = other.gameObject;
            Renderer renderer = surface.GetComponent<MeshRenderer>();
            renderer.enabled = true;
        }
    

    At least I think this will work. I'd have to get to my dev computer to test it out.

    May I ask a bit more: how to achieve something like RoboRaid? Render some spatial mesh from a certain point and radius?

  • Options

    @civitas,

    Hmmm. I have an idea on that. Let me work on a demo for a day and get back to you.

    James Ashley
    VS 2017 v5.3.3, Unity 2017.3.0f3, MRTK 2017.1.2, W10 17063
    Microsoft MVP, Freelance HoloLens/MR Developer
    www.imaginativeuniversal.com

  • Options

    @civitas said:

    @james_ashley said:
    @mdouk,

    You should be able to get a reference to the mesh you're hologram is colliding with using the OnTriggerEnter method. Here are the basics on using it, though you probably will want to find a video explaining how to use it for collision detection if you aren't already familiar, since there are a few gotchas.

    I believe OnTriggerEnter will pass you the collider, from which you can get the spatial mapping Surface object. From that, in turn, you can grab the mesh renderer and activate it like so:

        public void OnTriggerEnter(Collider other)
        {
            GameObject surface = other.gameObject;
            Renderer renderer = surface.GetComponent<MeshRenderer>();
            renderer.enabled = true;
        }
    

    At least I think this will work. I'd have to get to my dev computer to test it out.

    May I ask a bit more: how to achieve something like RoboRaid? Render some spatial mesh from a certain point and radius?

    I put this in an existing script that I attach to my GameObject and added the following code for the color change:
    transform.GetComponent<MeshRenderer>().material.color = Color.red;

    But still when a collider happens I dont see the Spatial Mesh polygon change color...What more should I do?

  • Options

    @james_ashley

    After a lot of tries, I cannot get this to work.
    The component MeshRenderer fetches the entire SpatialMesh and not the polygon where the collisions occured. Even in that case, the SpatialMesh does not change its colour upon collision. Although if I insert a kinematic game object (KGO) then its colour is being changed when my movable game object (MGO).

    My script follows. Pls note that it also changes the colour of my MGO which works just fine:

    `public class ColourChange : MonoBehaviour {

    public float colourChangeDelay = 10.0f;
    float currentDelay = 0.0f;
    bool colourChangeCollision = false;
    private Color MGOBlue = new Color (0f, 159f, 255f, 255f);
    private Color meshPolygon = new Color (255f, 0f, 0f, 255f);
    
    void OnTriggerEnter(Collider other) 
    {
        colourChangeCollision = true;
        currentDelay = Time.time + colourChangeDelay;
    
        //change the colour of the colliding mesh of the Spatial Mesh into Materials/meshPolygon
        GameObject surface = other.gameObject;
        MeshRenderer renderer = surface.GetComponent<MeshRenderer>();
        renderer.enabled = true;
        surface.transform.GetComponent<MeshRenderer>().material.color = meshPolygon;
    }
    
    void checkColourChange()
    {        
        if(colourChangeCollision)
        {
            transform.GetComponent<Renderer>().material.color = Color.yellow;
            if(Time.time > currentDelay)
            {
                // change the colour to Materials/MGOBlue
                transform.GetComponent<Renderer>().material.color = MGOBlue;
                colourChangeCollision = false;
            }
        }
    }
    
    void Update()
    {
        checkColourChange();
    }
    

    }`

    Moreover, I have found the following code, which may eventually be helpful:
    void OnCollisionEnter(Collision collision) { foreach (ContactPoint contact in collision.contacts) { Debug.DrawRay(contact.point, contact.normal, Color.red); }

    Any further ideas?
    Thanks in advance
    Micheal

  • Options

    up?

  • Options
    jbienzmsjbienzms mod
    edited February 2017

    In addition to what's already been shared, I recommend checking out Holograms 240. Just download the zip and open the Completed folder in Unity. Then, check out the CustomSpatialMapping prefab in the Holograms subfolder. It only shows the wireframe in specific areas where objects collide with it and it even generates polys that "fracture" away from the surface when an object collides. It's a very neat effect.

    Our Holographic world is here

    RoadToHolo.com      WikiHolo.net      @jbienz
    I work in Developer Experiences at Microsoft. My posts are based on my own experience and don't represent Microsoft or HoloLens.

  • Options
    trzytrzy ✭✭✭

    Not sure how Holograms 240 does it -- it may be just what you need -- but I've played around a bit with Microsoft's RemoveVertices component and discovered that the implementation is not quite correct.

    I implemented oriented bounding box/mesh intersection testing to determine which triangles a box collider intersects. Basically, you would want to do an intersection test of your object (hopefully a simple shape like a box, or even just a ray) against meshes, find the affected polygons, and then create a new GameObject with a mesh containing only those polygons.

    My intersection testing code is available on my Github under Assets/Scripts/OBBMeshIntersection.cs: https://github.com/trzy/hololens/tree/master/Experiments-Unity

  • Options

    @jbienzms @trzy
    Thanks for the further suggestions. I think the way to go would be a combination of both Tutorial 240 Spatial Mapping Deformation and bounding box/mesh intersection. Once I check it out I will let you know!

Sign In or Register to comment.