Run-time API

using AmazingAssets.LowpolyStyleMeshGenerator;

Now Unity mesh class will have new LowpolyStyleMeshGenerator extension with the Generate(...) method calculating lowpoly style mesh and baking provided textures inside its vertex color.

// 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;
    }
}

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.

solver

Baked vertex color style: AverageColor, CenterColor or FirstVertexColor.

textures

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. Passing null value bakes white texture.

uvIndex

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].

texturesTilingOffset

Baked textures tiling and offset values. Must be the same size as the textures array. Passing null value uses default (1, 1, 0, 0) parameters.

colors

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. Passing null value bakes white color.

sourceVertexColor

Combines mesh original vertex color with generated lowpoly color.

alphaType

Saved vertex color's alpha value.

Default value is calculated using: texture Alpha * color Alpha * original vertex color Alpha

saveLowpolyUV0

Calculates lowpoly UV0 and saves it inside XY or ZW channel of the generated mesh's UV0 buffer.

saveFaceCenter

Calculates triangle’s center position and saves it inside the chosen vertex buffer.

mergeSubmeshes

Combines sub-meshes in the generated lowpoly style mesh.

Last updated