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 class then mesh is read from the or components attached to this gameObject and thickness calculation method takes into account its world space position/rotation/scale data (from component).
//Example script demonstrating usage of the GenerateVertexThickness method
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()
{
float[] thicknessValues = this.gameObject.GenerateVertexThickness(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
}
}
}