Search Unity

Is it possible to draw a subset of the triangles in a Mesh?

Discussion in 'General Graphics' started by ViniciusGraciano, Oct 4, 2018.

  1. ViniciusGraciano

    ViniciusGraciano

    Joined:
    May 19, 2013
    Posts:
    13
    Hello everyone!

    When working in OpenGL, it is really easy to draw a subset of a particular mesh by using the glDrawElements method. For instance, I could create a VBO (with an associated element/indices array) and then call the procedure to draw the triangles formed by a subset of the element array (e.g., to render only the first ten triangles of the mesh).

    In Unity, the Mesh class allows us to specify a set of triangles by their vertices and indices (which I assume are somehow mapped into a VBO and element array when running on OpenGL), but I don't know whether it is possible to tell the engine to draw only a subset of the triangles using the mesh indices array. Is there some method overload, such as Graphics.DrawMesh, that take an offset and count parameter and draw such a subset? Or is this feature considered too low-level?

    I know that I can always copy the mesh and override its indices, but this is not an option, as I assume that there is too much memory overhead involved.

    Thank you very much for your time!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Sadly, no. Unity uses subindex rendering for all sorts of things, especially for static batch mesh rendering, but they do not expose that functionality to C#. It might be possible with a native plugin, but I'm not sure.