private void GenerateObstacleMesh(ref ObstacleController.ObstacleInitializer obstacle, float u, float angle)
        {
            Vector3 tangent = Spline.GetDerivative(u, 1).normalized;

            Vector3 normal = Spline.GetNormal(u).normalized;

            //make only half circle obstacles for now
            List <Vector3> vertices  = new List <Vector3>();
            List <int>     triangles = new List <int>();


            for (float x = 0; x < 180; x += 180.0f / Config.Instance.Global.Level.Mesh.Resolution.Normal)
            {
                float currAngle = angle + x;
                var   rotation  = Quaternion.AngleAxis(currAngle, tangent);
                //create vertex on the half circle
                Vector3 vertex = rotation * (normal * Config.Instance.Global.Level.Mesh.Radius);
                vertices.Add(vertex);
                //add a second translated one so the obstacle has thickness. Assumes the spline is straight for that short bit
                vertex += tangent;
                vertices.Add(vertex);

                //connect the vertices on the outside of the circle
                if (vertices.Count % 2 == 0 && vertices.Count > 2)
                {
                    int index = vertices.Count - 1;
                    triangles.AddRange(MakeQuad(index, index - 1, index - 3, index - 2));
                }
            }

            //close flat inside
            int lastIndex = vertices.Count - 1;

            triangles.AddRange(MakeQuad(0, 1, lastIndex, lastIndex - 1));

            //close sides
            for (int i = 2; i < vertices.Count - 3; i += 2)
            {
                triangles.AddRange(MakeTri(0, i, i + 2));
                triangles.AddRange(MakeTri(1, i + 1, i + 3));
            }


            obstacle.Triangles = triangles.ToArray();
            obstacle.Vertices  = vertices.ToArray();
        }
 private void GenerateObstacles()
 {
     for (float u = 0; u < Spline.Length; u += Config.Instance.Global.Level.Obstacles.Density)
     {
         //set up the initializer
         var initializer = new ObstacleController.ObstacleInitializer();
         initializer.Text     = "Test 1234 holdriö";
         initializer.Color    = new Color(1, 85 / 255.0f, 50 / 255.0f);
         initializer.Material = Resources.Load <Material>("Materials/ObstacleMaterial");
         //initializer.Material = this.GetComponent<MeshRenderer>().sharedMaterial;
         GenerateObstacleMesh(ref initializer, u, Random.value * 360);
         initializer.Forward = Spline.GetDerivative(u, 1);
         Vector3 normal = Spline.GetNormal(u);                //Vector3.Cross(_spline.GetDerivative(u, 2), _spline.GetDerivative(u, 1)));
         initializer.Up = Quaternion.AngleAxis(90, initializer.Forward) * normal;
         var obstacle = ObstacleController.Instantiate(initializer);
         obstacle.transform.position = Spline[u];
     }
 }