Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vector2[] uvs = new Vector2[vertices.Length];
- int[] indices = new int[(resolution - 1) * (resolution - 1) * 6];
- float spacing = size / resolution;
- for (int z = 0, i = 0; z < resolution; z++)
- {
- for (int x = 0; x < resolution; x++, i++)
- {
- vertices[i] = new Vector3(x * spacing - size / 2, 0, z * spacing - size / 2);
- uvs[i] = new Vector2((float)x / resolution, (float)z / resolution);
- }
- }
- for (int z = 0, i = 0, j = 0; z < resolution - 1; z++)
- {
- for (int x = 0; x < resolution - 1; x++, i++, j += 6)
- {
- indices[j] = i;
- indices[j + 1] = i + (resolution - 1) + 1;
- indices[j + 2] = i + 1;
- indices[j + 3] = i + 1;
- indices[j + 4] = i + (resolution - 1) + 1;
- indices[j + 5] = i + (resolution - 1) + 2;
- }
- i++;
- }
- Mesh mesh = new Mesh()
- {
- indexFormat = UnityEngine.Rendering.IndexFormat.UInt32,
- vertices = vertices,
- triangles = indices,
- uv = uvs
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement