【发布时间】:2017-03-16 22:24:37
【问题描述】:
我有一个从房间的点云扫描生成的网格,根据房间的大小,顶点数有时会大于统一支持的最大值 (650,000)。
我可以将这些网格导入编辑器,Unity 会自动将它们拆分为子网格。有没有办法在运行时在脚本中访问这个例程?
【问题讨论】:
我有一个从房间的点云扫描生成的网格,根据房间的大小,顶点数有时会大于统一支持的最大值 (650,000)。
我可以将这些网格导入编辑器,Unity 会自动将它们拆分为子网格。有没有办法在运行时在脚本中访问这个例程?
【问题讨论】:
正如您所说,网格在运行时或编辑器中不能包含超过 650,000 个顶点。
在运行时,您应该分段生成网格。例如,给定 100000 个顶点,然后创建如下网格:
// Your mesh data from the point cloud scan of a room
long[] indices = ...;
Vector3[] positions = = ...;
// Split your mesh data into two parts:
// one that have 60000 vertices and another that have 40000 vertices.
// create meshes
{
Mesh mesh = new Mesh();
GameObject obj = new GameObject();
obj.AddComponent<MeshFilter>().sharedMesh = mesh;
var positions = new Vector3[60000];
var indices = new int[count_of_indices];//The value of count_of_indices depends on how you split the mesh data.
// copy first 60000 vertices to positions and indices
mesh.vertices = positions;
mesh.triangles = indices;
}
{
Mesh mesh = new Mesh();
GameObject obj = new GameObject();
obj.AddComponent<MeshFilter>().sharedMesh = mesh;
var positions = new Vector3[4000];
var indices = new int[count_of_indices];
// copy the remaining 40000 vertices to positions and indices
mesh.vertices = positions;
mesh.triangles = indices;
}