c# - Unity 中是否有最大网格数?
问题描述
我正在尝试在统一 C# 中上传点云。因为没有直接绘制点的元素,所以我为点云的每个点创建了一个立方体。
因此,对于点云中的 n 个点,8n 个顶点(因为它是立方体),我的代码存在 12 个网格。
- 网格 = 3 索引 --> 立方体:12 网格 --> 3*12 索引(变量名称:三角形)
- 点 XYZ 保存在 PointList 中: List < Vector3 >
- 每个点在 ColorList 中都有颜色: List< Vector3 >
我检查了所有顶点和网格的值是否正确,并且绘制点(立方体)效果很好。
然而有一个问题。原始点云有 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);
}
解决方案
我找到了一个分析器!!!!
使用mesh时最大顶点数为65535!!!
只需添加一行即可解决此问题
mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
推荐阅读
- flutter - 如何传递参数 runApp(MyApp());
- java - 如何使用 oauth2 wso2 身份服务器获取授权代码以关闭登录页面
- javascript - 打字稿将数字类型转换为从不
- spring-boot - Zuul 和 Feign 客户端有什么区别?
- java - 如何使用 java 8 将 8 位 RGBA png 图像转换为 16 bpc RGBA png 图像?
- json - JSON 响应与 AJAX 不匹配
- laravel - Alpine.js 事件处理程序触发内部 livewire 点击处理程序两次
- java - 从文本中排除独立的撇号
- nginx - DigitalOcean Nginx - 未找到服务器
- python - '/' 或 '\' 用于路径?