Addendum: Low Level Meshing

See an example memory layout of a low level mesh.

Example Mesh Buffer

Mesh data is surfaced from the ARDK’s core library to the Unity C# world through buffers. A short description of the layout of those buffers is available in IARMesh; a different example is presented here with a memory layout for those buffers.

Mesh buffers are indexed by block. Every vertex and face belongs to one block only. Vertex and Index buffers are contiguous for one given block.

To illustrate the buffers, let’s use a simple flat mesh spanning two blocks.

../../../_images/meshing_image_0.png

The first block in yellow contains a square made of 2 faces and 4 vertices; the second block in blue contains one triangle represented by 1 face and 3 vertices.

Overall, this mesh contains 2 blocks, which means the block buffer has a size of 12 ints.

Here is what the block buffer looks like: the two blocks show different coordinates, and vertex and face counts corresponding to their respective contents.

../../../_images/meshing_image_1.png

In reality, blocks will contain hundreds of vertices and faces each. Iterating through blocks to split the mesh into submeshes can be a winning strategy to avoid unnecessary updates and costly recalculations.

The overall mesh contains 7 vertices, which means the vertex buffer has a size of 42 floats. The vertex buffer is made of two halves, the first one containing all positions as (x, y, z) 3D coordinates, and the second one containing all normal vectors as (nx, ny, nz) vectors, in the same order.

In this case the first 4 vertices belong to the first yellow block, and the next 3 belong to the second blue one. All positions are listed back-to-back, then all normals.

../../../_images/meshing_image_2.png

In this example, all vertices share a same normal vector pointing up, consistent with the geometry of a flat horizontal surface.

Notice that vertices 2 & 4, and 3 & 5, are identical but in different blocks.

Finally, this overall mesh contains 3 faces, which means the face buffer has a size of 9 ints. All faces are listed back-to-back in counter-clockwise vertex order, with the two faces of the first yellow block first, and the only face of the blue block last.

../../../_images/meshing_image_3.png

Each int value is the vertex index in the vertex buffer. Note that the index is not reset to 0 in new blocks.