Sorry to ask about something so simple but I’ve been buggering around with this for an hour now and I can’t get the right indices or normals to show a textured rectangle.
This will draw the bottom right of the triangle but leaves the top left, I’ve looked behind it and it’s not even the wrong way and being culled it just isn’t being drawn:
var test;
var mesh:Mesh;
var width:float;
var height:float;
var grassTex:UnityEngine.Material;
function Start() {
mesh = new Mesh();
var verts : Vector3[] = new Vector3[4];
verts[0] = new Vector3(-width/2.0, 0, -height/2.0);
verts[1] = new Vector3(-width/2.0, 0, height/2.0);
verts[2] = new Vector3(width/2.0, 0, -height/2.0);
verts[3] = new Vector3(width/2.0, 0, height/2.0);
mesh.vertices = verts;
var indices: int[] = new int[6];
indices[0] = 0;
indices[1] = 2;
indices[2] = 3;
indices[3] = 0;
indices[4] = 3;
indices[1] = 1;
mesh.triangles = indices;
var norms:Vector3[] = new Vector3[4];
for (var i:int = 0; i < norms.Length; i++)
norms[i] = Vector3.up;
mesh.normals = norms;
var uvs:Vector2[] = new Vector2[4];
uvs[0] = new Vector2(0,0);
uvs[1] = new Vector2(1,0);
uvs[2] = new Vector2(0,1);
uvs[3] = new Vector2(1,1);
mesh.uv = uvs;
GetComponent(MeshFilter).mesh = mesh;
}
function Update () {
Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, grassTex, 0);
}
That was mashed together from old forum posts, I’ve tried different orders of indices but they haven’t worked.
To me the order should be 0,1,2, 1,3,2 as that would be clockwise I believe? But it doesn’t work.
Could someone help me out? Thanks.