예제 #1
0
    private void GenerateMesh()
    {
        if (this.curPlatform == 0)
        {
            if (leftEye)
            {
                dataFloatX = pcPlugin.DistXLeft();
                dataFloatY = pcPlugin.DistYLeft();
            }

            else
            {
                dataFloatX = pcPlugin.DistXRight();
                dataFloatY = pcPlugin.DistYRight();
            }
        }

        else
        {
            if (leftEye)
            {
                dataFloatX = androidCalib.GetDistCorrectXLeft();
                dataFloatY = androidCalib.GetDistCorrectYLeft();
            }

            else
            {
                dataFloatX = androidCalib.GetDistCorrectXRight();
                dataFloatY = androidCalib.GetDistCorrectYRight();
            }
        }

        GetComponent <MeshFilter>().mesh       = mesh = new Mesh();
        GetComponent <MeshRenderer>().material = meshMat;
        mesh.name = "Procedural Grid";

        vertices = new Vector3[(xSize + 1) * (ySize + 1)];
        Vector2[] uv       = new Vector2[vertices.Length];
        Vector4[] tangents = new Vector4[vertices.Length];
        Vector4   tangent  = new Vector4(1f, 0f, 0f, -1f);

        for (int i = 0, y = 0; y <= ySize; y++)
        {
            for (int x = 0; x <= xSize; x++, i++)
            {
                vertices[i] = new Vector3(x, y);
                uv[i]       = new Vector2((float)x / xSize, (float)y / ySize);
                tangents[i] = tangent;
            }
        }
        mesh.vertices = vertices;
        mesh.uv       = uv;
        mesh.tangents = tangents;

        int[] triangles = new int[xSize * ySize * 6];
        for (int ti = 0, vi = 0, y = 0; y < ySize; y++, vi++)
        {
            for (int x = 0; x < xSize; x++, ti += 6, vi++)
            {
                triangles[ti]     = vi;
                triangles[ti + 3] = triangles[ti + 2] = vi + 1;
                triangles[ti + 4] = triangles[ti + 1] = vi + xSize + 1;
                triangles[ti + 5] = vi + xSize + 2;
            }
        }
        mesh.triangles = triangles;
        mesh.RecalculateNormals();
        this.transform.localScale = scale;
    }