- Home /
Unique Triangles
Hi,
I'm trying to make each of the vertices in a triangle unique. Essentially I'm trying to split the vertices, I don't want any vertices shared. The problem is, I have no idea how to do this with my code. :(
private void CreateGrid () {
currentResolution = resolution;
mesh.Clear();
vertices = new Vector3[(resolution + 1) * (resolution + 1)];
colors = new Color[vertices.Length];
normals = new Vector3[vertices.Length];
Vector2[] uv = new Vector2[vertices.Length];
float stepSize = 1f / resolution;
for (int v = 0, z = 0; z <= resolution; z++) {
for (int x = 0; x <= resolution; x++, v++) {
vertices[v] = new Vector3(x * stepSize - 0.5f, 0f, z * stepSize - 0.5f);
colors[v] = Color.black;
normals[v] = Vector3.up;
uv[v] = new Vector2(x * stepSize, z * stepSize);
}
}
mesh.vertices = vertices;
mesh.colors = colors;
mesh.normals = normals;
mesh.uv = uv;
int[] triangles = new int[resolution * resolution * 6];
for (int t = 0, v = 0, y = 0; y < resolution; y++, v++) {
for (int x = 0; x < resolution; x++, v++, t += 6) {
triangles[t] = v;
triangles[t + 1] = v + resolution + 1;
triangles[t + 2] = v + 1;
triangles[t + 3] = v + 1;
triangles[t + 4] = v + resolution + 1;
triangles[t + 5] = v + resolution + 2;
}
}
mesh.triangles = triangles;
}
Comment