Hello,

I import a mesh into Godot from Blender and I would like to, as I move around the mouse hovering above the mesh, be able to see the triangle (maybe even quad if this is possible) under the mouse cursor highlighted in green.

What are some of the key components to make this work? Is it a combination of raycasting and shaders? Not looking for a complete solution but more a high level overview of the thought process.

Thank you very much!

  • Megalomaniak replied to this.
  • There are two solutions I've used in the past:

    You can either use MeshDataTool to get information about a mesh, then give the triangles to some functions in the Geometry singleton to find out which one is hovered.

    The second approach is more complicated, but more performant: You create a new mesh where every triangle has a different vertex color. Then you put it into a Viewport with the same transform as the real thing. If you sample the pixel where the cursor is, you get the triangle ID.

    To actually render the highlight, you could dynamically create a new mesh or give the triangle position / ID to a shader and let it handle the rest.
    Some code examples are here, but I think understanding is more future-proof than copy-pasting in this case. I have different selection types in the linked addon. There is also one for quads.

    There are two solutions I've used in the past:

    You can either use MeshDataTool to get information about a mesh, then give the triangles to some functions in the Geometry singleton to find out which one is hovered.

    The second approach is more complicated, but more performant: You create a new mesh where every triangle has a different vertex color. Then you put it into a Viewport with the same transform as the real thing. If you sample the pixel where the cursor is, you get the triangle ID.

    To actually render the highlight, you could dynamically create a new mesh or give the triangle position / ID to a shader and let it handle the rest.
    Some code examples are here, but I think understanding is more future-proof than copy-pasting in this case. I have different selection types in the linked addon. There is also one for quads.

      nullfame as I move around the mouse hovering above the mesh, be able to see the triangle (maybe even quad if this is possible) under the mouse cursor highlighted in green.

      Do you mean in game or in editor? If former, see Jummit comment above. If in editor then you would likely also need to read up on the documentation for how to develop addons/editor plugins.

        Jummit Thanks, I really appreciate your taking the time to guide me in the right direction.

        Megalomaniak Thanks - Indeed I would like to implement this feature in game so I will follow Jummit's tips.