Search Unity

Unite 2015 Bezier Mesh yt vid need help with one problem (Tangent ??)

Discussion in 'Scripting' started by tabrooksy, Feb 28, 2019.

?

is my code readable

  1. yes

    0 vote(s)
    0.0%
  2. hell no

    0 vote(s)
    0.0%
  3. a little

    0 vote(s)
    0.0%
  1. tabrooksy

    tabrooksy

    Joined:
    Jan 21, 2018
    Posts:
    6
    Hello all I am currently working on a bezier curve mesh generator

    thanks to this unity unite 2015 video

    If you look at the picture attached the blue areas are correct width just the (black circle ) middle for the life in me I can't figure out if
    i am a total noobie thanks for any help you can give... View attachment 380833





    Code (CSharp):
    1. private void createMesh(bool create, bool reset)
    2.     {
    3.         if (create)
    4.         {
    5.             t_Pos = new Vector3();
    6.             BezierLineBuiltPoints = new List<Vector3>();
    7.             points = new List<Vector3>();
    8.             Vector3 pts0 = BezierWorldPoints[0].position;
    9.             Vector3 pts1 = BezierWorldPoints[1].position;
    10.             Vector3 pts2 = BezierWorldPoints[2].position;
    11.             Vector3 pts3 = BezierWorldPoints[3].position;
    12.  
    13.  
    14.             for (float t = 0; t <= 1; t += gapSize)
    15.             {
    16.                 t_Pos = Mathf.Pow(1 - t, 3) * pts0 +
    17.                 3 * Mathf.Pow(1 - t, 2) * t * pts1 +
    18.                 3 * (1 - t) * Mathf.Pow(t, 2) * pts2 +
    19.                 Mathf.Pow(t, 3) * pts3;
    20.                 BezierLineBuiltPoints.Add(t_Pos);
    21.             }
    22.  
    23.             //Add last point to finish line
    24.             BezierLineBuiltPoints.Add(pts3);
    25.  
    26.             _linePoints = new Vector3[BezierLineBuiltPoints.Count];
    27.             for (int i = 0; i < BezierLineBuiltPoints.Count; i++)
    28.             {
    29.                 _linePoints[i] = new Vector3(BezierLineBuiltPoints[i].x, BezierLineBuiltPoints[i].y, BezierLineBuiltPoints[i].z);
    30.             }
    31.  
    32.             GameObject tempObj = null;
    33.             tempObj = new GameObject("Temp Line Pos");
    34.  
    35.  
    36.             line.positionCount = BezierLineBuiltPoints.Count;
    37.             line.SetPositions(_linePoints);
    38.             for (var i = 0; i < line.positionCount; i++)
    39.             {
    40.                 tempObj.transform.position = line.GetPosition(i);
    41.                 for (var si = 0; si < shape2d.shapePoints.Count; si++)
    42.                 {
    43.                     shape2dim = tempObj.transform.position + new Vector3(shape2d.shapePoints[si].x, shape2d.shapePoints[si].y, 0f);
    44.                     points.Add(shape2dim);
    45.                 }
    46.             }
    47.             DestroyImmediate(tempObj);
    48.  
    49.             Vector3[] verticies = new Vector3[points.Count];
    50.  
    51.             for (int i = 0; i < verticies.Length; i++)
    52.             {
    53.                 verticies[i] = points[i];
    54.             }
    55.  
    56.             routeSize = line.positionCount - 2;
    57.             shapeSize = shape2d.Total_Points - 1;
    58.             int[] triangles = new int[shapeSize * routeSize * 6];
    59.  
    60.             for (int ti = 0, vi = 0, y = 0; y < routeSize; y++, vi++)
    61.             {
    62.                 for (int x = 0; x < shapeSize; x++, ti += 6, vi++)
    63.                 {
    64.                     triangles[ti] = vi;
    65.                     triangles[ti + 3] = triangles[ti + 2] = vi + 1;
    66.                     triangles[ti + 4] = triangles[ti + 1] = vi + shapeSize + 1;
    67.                     triangles[ti + 5] = vi + shapeSize + 2;
    68.                 }
    69.             }
    70.             mesh = new Mesh();
    71.             mesh.vertices = verticies.ToArray();
    72.             mesh.triangles = triangles;
    73.             mesh.RecalculateNormals();
    74.         }
    75.     }
     
  2. tabrooksy

    tabrooksy

    Joined:
    Jan 21, 2018
    Posts:
    6
    nevermind i figured it out was binormals can close this