I read in from some data file (.vtu) lines in 3D.
Now I want to visualize/render them in the game.
I’m storing the lines in a Mesh using MeshTopology.Lines.
I attach a MeshFilter and a MeshRenderer. I can see the line geometry
in the Inspector view, but not in the game.
I use the Material: DefaultLine.
I’m apparently missing something. Is this the wrong material/shader?
I just setup a small testing example and have no issues at all. I used the same material you did. The script just looks like this:
using UnityEngine;
public class CreateLineMesh : MonoBehaviour
{
void Start ()
{
var mesh = new Mesh();
mesh.name = "My lines";
mesh.vertices = new Vector3[] {
new Vector3(0,0,0), new Vector3(2,0,0),
new Vector3(0,0,0), new Vector3(0,2,0),
new Vector3(0,2,0), new Vector3(2,2,0),
};
mesh.colors = new Color[] {
Color.red, Color.red,
Color.blue, Color.blue,
Color.green, Color.yellow
};
mesh.SetIndices(new int[] {0,1, 2,3, 4,5 }, MeshTopology.Lines, 0, true);
GetComponent<MeshFilter>().sharedMesh = mesh;
}
}
As you can see the 3 lines just show up as they should. Since the Default-Line material uses the “Particles/Alpha Blended Premultiplied” shader it actually uses vertex colors. I’ve set the first line to be drawn red, the second line is drawn blue and the third line uses green and yellow so we get a gradient for that line.