Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Asynchronous Mesh Loading at Runtime

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

  1. chr1swilli5ms

    chr1swilli5ms

    Joined:
    Nov 5, 2015
    Posts:
    1
    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..

    Thanks!
     
  2. Alexees

    Alexees

    Joined:
    Nov 8, 2017
    Posts:
    105
    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:
    https://answers.unity.com/questions/1275362/non-blocking-construction-loading-and-copying-of-l.html

    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.