C# Unity中大型未分段网格的运行时负载
我有一个从房间的点云扫描生成的网格,根据房间的大小,顶点的数量有时会超过unity支持的最大值(650000)C# Unity中大型未分段网格的运行时负载,c#,unity3d,mesh,C#,Unity3d,Mesh,我有一个从房间的点云扫描生成的网格,根据房间的大小,顶点的数量有时会超过unity支持的最大值(650000) 我可以将这些网格导入编辑器,unity会自动将它们拆分为子网格。有没有办法在运行时在脚本中访问此例程?正如您所说,在运行时或编辑器中,网格不能包含超过650000个顶点 在运行时,您应该分段生成网格。例如,给定100000个顶点,然后按如下方式创建网格: // Your mesh data from the point cloud scan of a room long[] indic
我可以将这些网格导入编辑器,unity会自动将它们拆分为子网格。有没有办法在运行时在脚本中访问此例程?正如您所说,在运行时或编辑器中,网格不能包含超过650000个顶点 在运行时,您应该分段生成网格。例如,给定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;
}
//来自房间点云扫描的网格数据
长[]指数=。。。;
向量3[]位置==。。。;
//将网格数据拆分为两部分:
//一个有60000个顶点,另一个有40000个顶点。
//创建网格
{
网格=新网格();
GameObject obj=新GameObject();
obj.AddComponent().sharedMesh=网格;
var位置=新矢量3[60000];
var index=new int[count_of_index];//count_of_index的值取决于分割网格数据的方式。
//将前60000个顶点复制到位置和索引
网格顶点=位置;
网格。三角形=索引;
}
{
网格=新网格();
GameObject obj=新GameObject();
obj.AddComponent().sharedMesh=网格;
var位置=新矢量3[4000];
var指数=新整数[指数的计数];
//将剩余的40000个顶点复制到位置和索引
网格顶点=位置;
网格。三角形=索引;
}
刚刚快速查看了链接的类,是否可以在运行时在应用程序中使用这些类,或者它们是严格为编辑器提供的?它们仅在编辑器中可用。我将更新答案。啊,我希望我不必手动执行此操作,因为决定如何分割网格是非常重要的。感谢您迄今为止的帮助,您有关于如何分割网格数据的建议吗?那么这是另一个问题。也许我能帮上忙。或者只是谷歌一下,或者问另外一个问题。这种操作(虽然非常有趣!)超出了我的项目范围。我最终导出了网格的.obj组,然后使用应用商店中的简单obj在运行时快速加载它们。