Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Asynchronous Mesh Loading at Runtime

Discussion in 'Physics' started by chr1swilli5ms, Aug 31, 2018.

  1. chr1swilli5ms


    Nov 5, 2015
    Hi guys,

    so I'm working on a tool that allows users to load big 3D models (photogrammetry models with big textures) from disk at runtime and to visualize them once loaded. These models can go from 60Mb up to 500Mb. We are currently using a plugin called TriLib (which uses Assimp for the file parsing). It provides us with a working solution for importing 3D models at runtime but there is a caveat.

    Although the file parsing step is asynchronous (reading data from the file can be put in a separate thread), the actual mesh generation causes the app to freeze for a good 10-20 seconds.

    The Unity profiler gives me some hints on where that time is spent.
    • Mesh collider baking (the infamous Mesh.Bake PhysX CollisionData which results from AddComponent<MeshCollider>() on the generated mesh).
    • Texture processing.

    Even after some research, I'm still trying to get my head around the mesh collider generation process. Basically I'd like to understand why it happens on the main thread (causing the app to freeze), and if is there a workaround to avoid this. Couldn't the mesh collider be generated on a different thread? On the GPU? Maybe steps by steps to spread the load across multiple frames? Would it be possible to handle the collider generation and then feed it back to Unity?

    If I import the same model in Maya, it takes about 10 seconds to parse the file and generate the mesh without even freezing the UI. So what's the difference between Maya's and Unity's respective approach?
    I'm not looking for speeding up the process, just to prevent our app from being unresponsive for 20 seconds.

    Let me know if there is good resource that I could read or watch (documentation, articles, postmortems, etc.) that explains how Unity handles that process. I personally haven't found anything relevant..

  2. Alexees


    Nov 8, 2017
    For loading textures, that's probably some work. I found this here which I found the best solution from what I've found so far as their internal async loading is a time sliced process as well:

    For Mesh.Bake PhysX CollisionData... well... split the mesh and add more colliders across frames. There is no way around that at the moment. Unless The opened up more of the PhysX API I did not find out about yet.