O
O
Obscutum2020-07-08 19:44:11
Unity
Obscutum, 2020-07-08 19:44:11

I'm trying to create a 1000*1000 square mesh object. Instead, I get 1000 * 6.5. Somewhere I made a very, very stupid cant, but I can not find it. Help?

List<Vector3> verts = new List<Vector3>();
        for(int y = 0; y < 1001; y++)
        {
            for (int x = 0; x < 1001; x++)
            {
                verts.Add(new Vector3(x, 0f, y));
            }
        }
        List<int> tris = new List<int>();
        for(int y = 0; y < 1000; y++)
        {
            for (int x = 0; x < 1000; x++)
            {
                tris.Add((y * 1001) + x);
                tris.Add(((y + 1) * 1001) + x);
                tris.Add((y * 1001) + x + 1);
                tris.Add(((y + 1) * 1001) + x);
                tris.Add(((y + 1) * 1001) + x + 1);
                tris.Add((y * 1001) + x + 1);
            }
        }
        var mf = one.GetComponent<MeshFilter>();
        mf.mesh.vertices = verts.ToArray();
        mf.mesh.triangles = tris.ToArray();
        mf.mesh.RecalculateBounds();

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question