Skip to content

Instantly share code, notes, and snippets.

@Jatapiaro
Created July 28, 2017 17:51
Show Gist options
  • Save Jatapiaro/7d3d734872545a51478d2d677d8464b9 to your computer and use it in GitHub Desktop.
Save Jatapiaro/7d3d734872545a51478d2d677d8464b9 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ProceduralAirfoil : MonoBehaviour {
FileReader fr;
Mesh mesh;
// Use this for initialization
void Start () {
fr = this.GetComponent<FileReader> ();
List<Vector3>[] data = fr.ReadAirfoilTrianglePoints ();
GenerateMesh (data);
//seePoints (data);
}
// Update is called once per frame
void Update () {
}
void GenerateMesh (List<Vector3>[] data) {
List<float> colors = new List<float> ();
foreach (Vector3 color in data[2]) {
colors.Add (color.x);
}
colors.Sort ();
GetComponent<MeshFilter>().mesh = mesh = new Mesh();
mesh.name = "Procedural Airfoil";
mesh.vertices = data[0].ToArray();
int count = mesh.vertexCount;
int step = colors.Count / 3;
/*Color[] col = new Color[count];
for (int i = 0; i < count; i++) {
col [i] = Color.blue;
}*/
Vector4[] tangents = new Vector4[count];
Vector4 tangent = new Vector4(1f, 0f, 0f, -1f);
for (int i = 0; i < count; i++) {
tangents[i] = new Vector4(1f, 0f, 0f, -1f);
}
List<int> triangles = new List<int> ();
foreach (Vector3 triangle in data[1]) {
triangles.Add ((int)triangle.x);
triangles.Add ((int)triangle.y);
triangles.Add ((int)triangle.z);
}
//mesh.colors = col;
mesh.triangles = triangles.ToArray ();
mesh.RecalculateNormals();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment