首页 文章

Unity中大型未分段网格的运行时加载

提问于
浏览
0

我有一个从房间的点 Cloud 扫描生成的网格,根据房间的大小,顶点的数量有时可能大于统一支持的最大值(650,000) .

我可以将这些网格导入到编辑器中,并且Unity会自动将它们拆分为子网格 . 有没有办法在运行时在脚本中访问此例程?

1 回答

  • 1

    正如您所说,网格在运行时或编辑器中不能包含超过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;
    }
    

相关问题