【问题标题】:Runtime load of large, unsegmented mesh in UnityUnity 中大型未分段网格的运行时负载
【发布时间】:2017-03-16 22:24:37
【问题描述】:

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

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

【问题讨论】:

    标签: c# unity3d mesh


    【解决方案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;
    }
    

    【讨论】:

    • 刚刚快速浏览了链接的类,是否可以在运行时在应用程序中使用这些类,或者它们是否仅限于编辑器?
    • 它们仅在编辑器中可用。我会更新答案。
    • 啊,我希望我不必手动执行此操作,因为决定如何分割网格并非易事。感谢您到目前为止的帮助,您对如何拆分网格数据有什么建议吗?
    • 那是另一个问题。也许this postthis 可以提供帮助。或者只是谷歌它或在 SO 中问另一个问题。
    • 这种操作(虽然超级有趣!)超出了我的项目范围。我最终导出了带有 .obj 组的网格,然后使用应用商店中的 Simple OBJ 在运行时快速加载它们。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-06
    • 2020-12-05
    相关资源
    最近更新 更多