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

Change Shaders on Gaze

Hello All,
I am looking for the simplest way to change the shaders of a gameobject when a person has their cursor on as gameobject.
I do not want the shader to change automatically on gaze entry and gaze exit, but on voice command only when the hololens cursor is on the gameobject.
Any help would save me!
Thank you!

Tagged:

Best Answers

  • Options
    dbarrettdbarrett ✭✭✭
    Answer ✓

    Here is a really simple implementation:

    RaycastHit hit;
    Vector3 fwd = camera.transform.TransformDirection(Vector3.forward);
    
     //if we hit something
     if (Physics.Raycast(camera.transform.position, fwd, out hit, 10))
     {
        GameObject hitObject = hit.transform.gameObject;
    
        //if what we hit is an object we're looking for
         if (hitObject.layer == LayerMask.NameToLayer("YourLayerName"))
         {
             //Do Something
          }
    

    AR Developer

  • Options
    holonutholonut
    Answer ✓

    Thank you! I will try it out.

Answers

  • Options
    dbarrettdbarrett ✭✭✭
    edited April 2018

    It sounds like all you need to do is create a script that inherits from IFocusbale in the MRTK. It has two methods, OnFocusEnter and OnFocusExit. That is if you wanted it to happen whenever you look at an object.

    EDIT: Sorry I misread your question.

    To do this with a keyword, you should create a method that does a raycast and then checks if it hits that object, through tag or layer or some other means, then you can change the shader. To set up a keyword, all you need is a SpeechInputSource and SpeechInputHandler component. Create your keyword and reference it to your method you created.

    AR Developer

  • Options

    Thank you! I will do my best to implement this. I do not know how to create a method that does a raycast and then checks if it hits that object, this through tag or layer or some other means. Both the SpeechInputSource and SpeechInputHandler are already in place for other global listener commands. The keyword is also in place for the command.
    I am a relatively weak coder so maybe I will just hire someone to take care of it for me.
    Thank you for your feedback!!

  • Options
    dbarrettdbarrett ✭✭✭
    Answer ✓

    Here is a really simple implementation:

    RaycastHit hit;
    Vector3 fwd = camera.transform.TransformDirection(Vector3.forward);
    
     //if we hit something
     if (Physics.Raycast(camera.transform.position, fwd, out hit, 10))
     {
        GameObject hitObject = hit.transform.gameObject;
    
        //if what we hit is an object we're looking for
         if (hitObject.layer == LayerMask.NameToLayer("YourLayerName"))
         {
             //Do Something
          }
    

    AR Developer

  • Options
    holonutholonut
    Answer ✓

    Thank you! I will try it out.

Sign In or Register to comment.