# Run-time API

```
using AmazingAssets.LowpolyStyleMeshGenerator;
```

Now Unity [mesh](https://docs.unity3d.com/ScriptReference/Mesh.html) class will have new <mark style="color:red;">**LowpolyStyleMeshGenerator**</mark> extension with the **Generate(**...**)** method calculating lowpoly style mesh and baking provided textures inside its vertex color.

```csharp
// Example of generating lowpoly style mesh with textures baked inside vertex color

using AmazingAssets.LowpolyStyleMeshGenerator;

public class ExampleScript : MonoBehaviour
{
    public LowpolyStyleMeshGeneratorEnum.Solver solver;
    public Texture2D[] textures;
    public int uvIndex = 0;

    void Start()
    {
        //Read mesh from MeshFilter
        Mesh sourceMesh = GetComponent<MeshFilter>().sharedMesh;


        //Generate lowpoly style mesh
        Mesh lowpolyMesh = sourceMesh.LowpolyStyleMeshGenerator().Generate(solver, textures, uvIndex, null, null);


        //Attach new mesh to the MeshFilter
        GetComponent<MeshFilter>().sharedMesh = lowpolyMesh;
    }
}
```

```csharp
Mesh Generate(LowpolyStyleMeshGeneratorEnum.Solver solver,     
              Texture2D[] textures,
              int uvIndex,
              Vector4[] texturesTilingOffset,
              Color[] colors,
              LowpolyStyleMeshGeneratorEnum.SourceVertexColor sourceVertexColor = LowpolyStyleMeshGeneratorEnum.SourceVertexColor.None,
              LowpolyStyleMeshGeneratorEnum.AlphaType alphaType = LowpolyStyleMeshGeneratorEnum.AlphaType.DefaultValue,
              LowpolyStyleMeshGeneratorEnum.LowpolyUV lowpolyUV0 = LowpolyStyleMeshGeneratorEnum.LowpolyUV.None,
              LowpolyStyleMeshGeneratorEnum.VertexAttribute saveFaceCenter = LowpolyStyleMeshGeneratorEnum.VertexAttribute.None,
              bool mergeSubmeshes = false)
```

Generates new lowpoly style mesh based on the provided parameters. Source mesh is not modified.

| <sup>solver</sup>               | <sup>Baked vertex color style:</sup> <sup></sup><sup>**AverageColor**</sup><sup>,</sup> <sup></sup><sup>**CenterColor**</sup> <sup></sup><sup>or</sup> <sup></sup><sup>**FirstVertexColor**</sup><sup>.</sup>                                                                                               |
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <sup>textures</sup>             | <p><sub>Array of the textures with the same size as the source mesh’s sub-mesh count. Each texture is baked corresponding to its sub-mesh index. In the case of providing only one texture, it is used for all sub-meshes.</sub><br><sub>Passing <strong>null</strong> value bakes white texture.</sub></p> |
| <sup>uvIndex</sup>              | <sup>Mesh UV index used for texture sampling for baking it inside vertex color. By default it is 0. Can be in the range of \[0, 7].</sup>                                                                                                                                                                   |
| <sup>texturesTilingOffset</sup> | <p><sup>Baked textures tiling and offset values. Must be the same size as the textures array.</sup><br><sup>Passing <strong>null</strong> value uses default (1, 1, 0, 0) parameters.</sup></p>                                                                                                             |
| <sup>colors</sup>               | <p><sup>Array of the baked colors with the same size as the source mesh’s sub-mesh count. Each color is baked corresponding to its sub-mesh index. In the case of providing only one color, it is used for all sub-meshes.</sup><br><sup>Passing <strong>null</strong> value bakes white color.</sup></p>   |
| <sup>sourceVertexColor</sup>    | <sup>Combines mesh original vertex color with generated lowpoly color.</sup>                                                                                                                                                                                                                                |
| <sup>alphaType</sup>            | <p><sup>Saved vertex color's alpha value.</sup></p><p><sup>Default value is calculated using: <em><mark style="background-color:red;">texture Alpha \* color Alpha \* original vertex color Alpha</mark></em></sup></p>                                                                                     |
| <sup>saveLowpolyUV0</sup>       | <sup>Calculates lowpoly UV0 and saves it inside</sup> <sup></sup><sup>**XY**</sup> <sup></sup><sup>or</sup> <sup></sup><sup>**ZW**</sup> <sup></sup><sup>channel of the generated mesh's UV0 buffer.</sup>                                                                                                  |
| <sup>saveFaceCenter</sup>       | <sup>Calculates triangle’s center position and saves it inside the chosen vertex buffer.</sup>                                                                                                                                                                                                              |
| <sup>mergeSubmeshes</sup>       | <sup>Combines sub-meshes in the generated lowpoly style mesh.</sup>                                                                                                                                                                                                                                         |
