【问题标题】:How to use meshes with more than 64k vertices in Unity 2018.1如何在 Unity 2018.1 中使用超过 64k 顶点的网格
【发布时间】:2018-10-30 05:27:47
【问题描述】:

我听说 Unity 现在支持 32 位索引缓冲区。但是当我尝试 Unity 2018.1 时,我无法让它工作。

我用这样的代码构建了网格:

    int nVertices = nx * ny;
    Vector3[] vertices = new Vector3[nVertices];
    Color[] colors = new Color[nVertices];
    for(int i = 0; i < nx; i++) {
        float x = i * w / (nx - 1);
        for (int j = 0; j < ny; j++) {
            float y = j * h / (ny - 1);
            int vindex = i * ny + j;
            vertices[vindex] = new Vector3(x, y, 0);
            float colorx = Mathf.Sin(x) / 2 + 0.5f;
            float colory = Mathf.Cos(y) / 2 + 0.5f;
            colors[vindex] = new Color(0, 0, 0, colorx * colory);
        }
    }
    List<int> triangles = new List<int>();
    for (int i = 1; i < nx; i++) {
        for (int j = 1; j < ny; j++) {
            int vindex1 = (i - 1) * ny + (j - 1);
            int vindex2 = (i - 1) * ny + j;
            int vindex3 = i * ny + (j - 1);
            int vindex4 = i * ny + j;
            triangles.Add(vindex1);
            triangles.Add(vindex2);
            triangles.Add(vindex3);
            triangles.Add(vindex4);
            triangles.Add(vindex3);
            triangles.Add(vindex2);
        }
    }
    Mesh mesh = new Mesh();
    mesh.SetVertices(vertices.ToList<Vector3>());
    mesh.SetIndices(triangles.ToArray(), MeshTopology.Triangles, 0);
    mesh.SetColors(colors.ToList<Color>());

我的着色器根据顶点颜色的 alpha 值绘制彩虹图案。

256 x 256 的网格是可以的,但 512 x 512 的网格只显示其 1/4 的面积和许多错误的三角形。

【问题讨论】:

    标签: c# unity3d rendering


    【解决方案1】:

    网格缓冲区默认为 16 位。见 Mesh-indexFormat:

    索引缓冲区可以是 16 位(最多支持 65535 个顶点) 网格)或 32 位(最多支持 40 亿个顶点)。默认索引 格式为 16 位,因为这样占用的内存和带宽更少。

    如果不仔细查看您的其余代码,我确实注意到您没有设置 32 位缓冲区。试试:

    mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-09
    • 2021-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    • 2015-06-09
    相关资源
    最近更新 更多