首页 > 解决方案 > Unity 中是否有最大网格数?

问题描述

我正在尝试在统一 C# 中上传点云。因为没有直接绘制点的元素,所以我为点云的每个点创建了一个立方体。

因此,对于点云中的 n 个点,8n 个顶点(因为它是立方体),我的代码存在 12 个网格。

我检查了所有顶点和网格的值是否正确,并且绘制点(立方体)效果很好。

然而有一个问题。原始点云有 1412765 个点(image1)。并且顶点数与之相同。但!如果我试着把它们都画出来,也许其中一些没有画出来。(image2。我猜大约 10000 个立方体是最大值。)

有什么问题? 在此处输入图像描述

在此处输入图像描述

    float resolution = 2.5f;
    int pointSize = PointList.Count;
    MeshFilter mf = GetComponent<MeshFilter>();
    Mesh mesh = new Mesh();
    mf.mesh = mesh;
    Vector3[] vertices;
    vertices = new Vector3[pointSize * 8];
    for (int i = 0; i < pointSize; i++)
    {
        float x = PointList[i].x;
        float y = PointList[i].y;
        float z = PointList[i].z;
        vertices[i * 8 + 0] = new Vector3(x - resolution, y - resolution, z - resolution);
        vertices[i * 8 + 1] = new Vector3(x + resolution, y - resolution, z - resolution);
        vertices[i * 8 + 2] = new Vector3(x + resolution, y + resolution, z - resolution);
        vertices[i * 8 + 3] = new Vector3(x - resolution, y + resolution, z - resolution);
        vertices[i * 8 + 4] = new Vector3(x - resolution, y + resolution, z + resolution);
        vertices[i * 8 + 5] = new Vector3(x + resolution, y + resolution, z + resolution);
        vertices[i * 8 + 6] = new Vector3(x + resolution, y - resolution, z + resolution);
        vertices[i * 8 + 7] = new Vector3(x - resolution, y - resolution, z + resolution);
    }

    mesh.vertices = vertices;

    int[] triangles;
    triangles = new int[pointSize * 12 * 3];

    triangles[0] = 0;
    triangles[1] = 2;
    triangles[2] = 1;
    triangles[3] = 0;
    triangles[4] = 3;
    triangles[5] = 2;

    triangles[6] = 2;
    triangles[7] = 3;
    triangles[8] = 4;
    triangles[9] = 2;
    triangles[10] = 4;
    triangles[11] = 5;

    triangles[12] = 1;
    triangles[13] = 2;
    triangles[14] = 5;
    triangles[15] = 1;
    triangles[16] = 5;
    triangles[17] = 6;

    triangles[18] = 0;
    triangles[19] = 7;
    triangles[20] = 4;
    triangles[21] = 0;
    triangles[22] = 4;
    triangles[23] = 3;

    triangles[24] = 5;
    triangles[25] = 4;
    triangles[26] = 7;
    triangles[27] = 5;
    triangles[28] = 7;
    triangles[29] = 6;

    triangles[30] = 0;
    triangles[31] = 6;
    triangles[32] = 7;
    triangles[33] = 0;
    triangles[34] = 1;
    triangles[35] = 6;

    for (int i = 1; i < pointSize; i++)
    {
        for (int j = 0; j < 36; j++)
        {
            int val = triangles[j] + 8 * i;
            triangles[i * 36 + j] = triangles[j] + 8 * i;
        }
    }
    mesh.triangles = triangles;

    Color32[] colors = new Color32[mesh.vertices.Length];

    for (int i = 0; i < pointSize; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            Color32 newColor = new Color32(
            (byte)ColorList[i].x,
            (byte)ColorList[i].y,
            (byte)ColorList[i].z,
            255);
            colors[i * 8 + j] = newColor;
        }
    }

    mesh.colors32 = colors;

    Debug.Log("points : " + PointList.Count);
    Debug.Log("vertices  (point*8): " + mesh.vertices.Length);
    Debug.Log("triangles (point*36): " + mesh.triangles.Length);
    Debug.Log("colors (points*8): " + mesh.colors32.Length);
}

标签: c#unity3d

解决方案


我找到了一个分析器!!!!

使用mesh时最大顶点数为65535!!!

只需添加一行即可解决此问题

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

如何在 Unity 2018.1 中使用超过 64k 顶点的网格


推荐阅读