Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to render cubes as lines?

Discussion in 'Scripting' started by olidadda, Jul 7, 2020.

  1. olidadda

    olidadda

    Joined:
    Jul 27, 2019
    Posts:
    37
    I'd like to render an 8x8 wall of cubes but I only want to render the lines that run between the cube's vertices.

    I understand I'm supposed to use Mesh.SetIndices and MeshTopology.lines but I'm rather at a loss as to how to actually start going about that as the Unity manual doesn't give any script examples.

    Any pointers are greatly appreciated!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    The Vectrosity package on the Asset Store has a cool tool that takes an arbitrary geometric shape and replaces the edges in it with the Vectrosity line geometry:

    https://assetstore.unity.com/packages/tools/particles-effects/vectrosity-82

    Vectrosity is just overall a fantastic package, and the guy who made it regularly answers questions in the forums here.

    Alternatively you can do your own calculations and produce geometry to go between the vertices you're interested in.

    And another approach is to find or make a shader that only draws the edges of polygons... I think that's a thing but I am not sure if it could be made quad-aware or if it would put lines on every triangle, ie, two per cube face. Haven't messed much with that sorta shader.