Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

How to highlight one face of a cube when gazing (using the HoloToolKit cursor)?

Discussion in 'VR' started by yaqinh0818, Jun 2, 2017.

  1. yaqinh0818

    yaqinh0818

    Joined:
    Mar 4, 2017
    Posts:
    5
    Hi guys,
    I am doing a Hololens app using Unity 3D engine now and I want to implement one specific function, which is when the user is looking a 3D game object (for example, like a cube), it could highlight (or simply change color) the face that the cursor is on.
    I did some research and find for me it is not an easy question. One solution I can think of is to first know which mesh triangle the user is gazing by getting it's index. And because every face has different triangle index so I could use some simple if else or case statement to determine which face the user is gazing. Then I would switch the color for all triangles in that face. When user changes the face he is gazing at, just set back to the original color.
    Am I doing this right? Or there is better solution? It would be great if someone could give a code example with some comments.
    Any advise or suggestion are welcome!
    Thanks!
     
  2. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    228
    Hi yaqinh0818 - sorry for the delayed response.

    I'm afraid we don't directly support the HoloToolkit here. For questions specific to that, I'm afraid I need to direct you to their GitHub page: https://github.com/Microsoft/Holotoolkit-Unity

    As far as general advice goes for highlighting specific faces of an object, I would think you'd need to do some custom shader and material work for that to happen. You could query for gaze information from the main camera in script, ray-cast against whatever object you'd like to highlight specific faces of, and depending on the results of that and the current transform of the object in question, you'd need to set the relevant shader values through the material (see https://docs.unity3d.com/ScriptReference/Material.html), and write the shader so that you render those faces differently.