🌶️ MultiFastMesh

In certain situations, there is a need to showcase a 3D object that consists of numerous smaller sub-parts, each with its own color and visibility settings.

For instance, let's consider a 3D printing simulation where the final piece is built by adding a small amount of material at each step. If you were to recreate a 3D representation of this process, you would typically generate separate entities for each simulation step. At each step, you would then turn some entities visible/invisible and maybe change their color (to highlight the latest level or the latest motion in the simulation, for example).

This approach quickly becomes unfeasible due to the heavy impact a large number of individual meshes has on performance.

The best performances are achieved when all the individual meshes are merged into a single mesh. With a single mesh, however, it's not possible to specify color and visibility for the individual sub-meshes.

The MultiFastMesh entity is perfect to handle such situations: it is almost as fast as a single mesh while offering the possibility to specify color and visibility for individual sub-parts.

The following example shows how to build and show a MultiFastMesh:

``````//  Creating some geometry (3 quads):
//
//  0 ----- 2 ----- 4 ----- 6
//  |   __ /|   __ /|   __ /|
//  | /     | /     | /     |
//  1 ----- 3 ----- 5 ----- 7

float[] pos =
{
0, 0, 0,
1, 0, 0,
0, 1, 0,
1, 1, 0,
0, 2, 0,
1, 2, 0,
0, 3, 0,
1, 3, 0
};

float[] nrm = new float[pos.Length];
for (int i = 0; i < nrm.Length; i += 3)
{
nrm[i + 0] = 0.0f;
nrm[i + 1] = 0.0f;
nrm[i + 2] = 1.0f;
}

int[] tri =
{
0, 1, 3,
0, 3, 2,

2, 3, 5,
2, 5, 4,

4, 5, 7,
4, 7, 6
};

MultiFastMesh mfm = new MultiFastMesh(pos, nrm, tri, new[]
{
// each quad is a sub-mesh
new IntInterval(0, 5),       // Sub-mesh 1: from index 0 (inclusive) to index 5 (inclusive) in the triangles array
new IntInterval(6, 11),      // Sub-mesh 2: [6 , 11]
new IntInterval(12, 17),     // Sub-mesh 3: [12, 17]
});

// By filling SubMeshColors it is possible to specify which sub-meshes gets drawn and what is their color.
// If a sub-mesh is not present in this list, it won't be drawn.

// Example I
// ---------
// All the sub-meshes are visible and have the same color:
mfm.SubMeshIntervals = new List<MultiFastMesh.SubMeshInterval>
{
new MultiFastMesh.SubMeshInterval(0, 2 /* we specified 3 sub-meshes in the constructor */, Color.Green)
};

// Example II
// ----------
// Only sub-meshes 0 and 2 are visible and they have different colors:
mfm.SubMeshIntervals = new List<MultiFastMesh.SubMeshInterval>
{
new MultiFastMesh.SubMeshInterval(0, 0, Color.Green), // The 1st sub-mesh is visible and green
// the 2nd sub-mesh is not visible (not added to SubMeshColors)
new MultiFastMesh.SubMeshInterval(2, 2, Color.Orange) // the 3rd sub-mesh is visible and orange
};

``````

Example 1

Example 2