# API

```
using AmazingAssets.VertexThicknessGenerator;
```

Now Unity [Mesh](https://docs.unity3d.com/ScriptReference/Mesh.html) and [GameObject](https://docs.unity3d.com/ScriptReference/GameObject.html) classes will have new <mark style="color:red;">**VertexThicknessGenerator**</mark> extension with the **Generate(**...**)** method calculating thickness per vertex.

```csharp
//Example of generating vertex thickness and baking it inside vertex color

using UnityEngine;

using AmazingAssets.VertexThicknessGenerator;


public class ExampleScript : MonoBehaviour
{
    public float rayLength = 0.1f;
    [Range(1, 180)] public float fov = 90;
    public bool useSmoothNormals;


    void Start()
    {
        //Generating per vertex thickness
        float[] thicknessValues = this.gameObject.VertexThicknessGenerator().Generate(rayLength, fov, useSmoothNormals);


        if (thicknessValues != null)
        {
            //Baking thickness inside vertex color
            Color[] vertexColor = new Color[thicknessValues.Length];
            for (int i = 0; i < thicknessValues.Length; i++)
            {
                vertexColor[i] = Color.Lerp(Color.black, Color.white * thicknessValues[i], thicknessValues[i]);
            }


            //Instantiating mesh and assigning vertex colors
            Mesh mesh = Instantiate(this.gameObject.GetComponent<MeshFilter>().sharedMesh);
            mesh.colors = vertexColor;

            this.gameObject.GetComponent<MeshFilter>().sharedMesh = mesh;


            //Make sure MeshRenderer's material uses shader with vertex color support - to render thickness baked inside vertex color
        }
    }
}
```

```csharp
float[] GenerateVertexThickness(float rayLength, float fieldOfView, bool useSmoothNormals)
```

Generates per-vertex thickness and returns it as the ***float*** values array, with the same size as the source mesh vertex count. Thickness values are in the range of \[0, 1].

If using with [GameObject](https://docs.unity3d.com/ScriptReference/GameObject.html) class then mesh is read from the [MeshFilter](https://docs.unity3d.com/ScriptReference/MeshFilter.html) or [skinnedMeshRenderer](https://docs.unity3d.com/ScriptReference/SkinnedMeshRenderer.html) components attached to this gameObject and thickness calculation method takes into account  its world space position/rotation/scale data (from [Transform](https://docs.unity3d.com/ScriptReference/Transform.html) component).
