void GenerateCalculationsMiniMesh()
{
GameObject calculationsMiniMeshGameObject = new GameObject("CalculationsMiniMesh");
calculationsMiniMeshGameObject.AddComponent("MeshFilter");
//calculationsMiniMeshGameObject.AddComponent("MeshRenderer");
calculationsMiniMesh = calculationsMiniMeshGameObject.GetComponent<MeshFilter>().mesh;
List<int> trisList = new List<int>();
List<Vector3> vertsList = new List<Vector3>();
List<Vector2> tempUVList = new List<Vector2>();
// initial line
for(int j = 0; j < verticesFrequencyDepthCount; j++)
{
vertsList.Add( new Vector3(0,0,j * zScale) );
tempUVList.Add( new Vector2(0,0) );
}
// populate the rest of the vertices, triangles
// use verticesFrequencyDepthCount to shift between frewuency collumns
// generate only one extra row for normals calculations
for(int i = 1; i < 2; i++)
{
for(int j = 0; j < verticesFrequencyDepthCount; j += 2)
{
// bottom left triangle
vertsList.Add( new Vector3(i * xScale,0, j * zScale) );
int currentListIndex = vertsList.Count -1;
trisList.Add(currentListIndex);
trisList.Add(currentListIndex - verticesFrequencyDepthCount);
trisList.Add(currentListIndex - verticesFrequencyDepthCount + 1);
// fill triangles in between this and previous triangle below
if( j > 0) // is not at the edge
{
// bottom left triangle
trisList.Add(currentListIndex -1);
trisList.Add(currentListIndex - verticesFrequencyDepthCount -1);
trisList.Add(currentListIndex - verticesFrequencyDepthCount);
// top right triangle
trisList.Add(currentListIndex);
trisList.Add(currentListIndex - 1);
trisList.Add(currentListIndex - verticesFrequencyDepthCount);
}
// top right triangle
vertsList.Add( new Vector3( i*xScale,0, (j + 1)*zScale ) );
currentListIndex++;
trisList.Add(currentListIndex);
trisList.Add(currentListIndex - 1);
trisList.Add(currentListIndex - verticesFrequencyDepthCount);
tempUVList.Add( new Vector2(0,0) );
tempUVList.Add( new Vector2(0,0) );
}
}
calculationsMiniMesh.Clear();
calculationsMiniMesh.MarkDynamic();
calculationsMiniMesh.vertices = vertsList.ToArray();
calculationsMiniMesh.uv = tempUVList.ToArray();
calculationsMiniMesh.triangles = trisList.ToArray();
calculationsMiniMesh.RecalculateNormals();
miniVertsArray = calculationsMiniMesh.normals;
}