top of page

Mesh Combining

The Problem:

    For architectural VR projects, performance is key. Since building files usually contain at least ten-zillion tiny cubes, out of the box we get a crushing amount of draw calls. For this tool demo, I'll use a wall made of tiny cubes as a stand-in which plays back at a blazing 6 FPS.

What does the manual say?

    When an object is not going to be moving in our "game" marking it as static turns on a series of cool optimization features under the hood. However, when facing the problem of a large number of Game Objects, this doesn't help out a whole lot. After marking the cube wall as static, we are bumped from 6 to 7 FPS. We could go into our DCC software and have our models combined into larger chunks, or.... 

Lets combine the meshes in Unity

    This approach has a couple of practical benefits, including:

          - Avoids sending the object back to our DCC software when a single small object is out of place

          - Is faster than combining in many packages (I'm looking at you, Maya)

          - Can be automated with minimal additional effort

    For anyone savvy with C#, you can put together the pieces that you'll need by referencing the following unity methods:

          -  https://docs.unity3d.com/ScriptReference/Mesh.CombineMeshes.html

          -  https://docs.unity3d.com/ScriptReference/Mesh-vertexCount.html

          -  https://docs.unity3d.com/ScriptReference/Mesh-triangles.html

          -  https://docs.unity3d.com/ScriptReference/CombineInstance.html

Common problems when writing your own mesh combiner:

    - Unity has a limit to the number of vertices that can be in a single mesh. You'll have to sort and batch combine accordingly.

    - Your old Game Objects won't lower your frame rate once deactivated, but they will affect loading time. Consider deleting them before building

    - If a mesh has more than one material applied, it will be two submeshes under the hood. This in turn affects how you'll manage combineInstances

    - You'll generally want to combine only objects sharing the same material, or else you'll generate submeshes, adding more draw calls

    - A combined mesh will live in your scene file by default if not saved to a unity asset. Consider creating new assets as needed

With all those issues out of the way...

    Enjoy your 100+ FPS!

bottom of page