Search Unity

UV Seems!!! Why are there Seems?!?!? Creating a UV MAP

Discussion in 'General Graphics' started by DouglasPotesta, Mar 21, 2020.

  1. DouglasPotesta

    DouglasPotesta

    Joined:
    Nov 6, 2014
    Posts:
    109
    So I am trying to create a way to export a UV MAP of unity's generated lightmap uvs.
    From my implementation I end up with this (Unity Capsule). Below the image is my implementation.
    Are there supposed to be seams in the middle of the squares, along with the seam in the center of the far left rectangle? If not does anyone know where I may have gone wrong?
    upload_2020-3-21_15-18-49.png

    Code (CSharp):
    1.     private void OnRenderObject()
    2.     {
    3.         CreateLineMaterial();
    4.         lineMaterial.SetPass(0);
    5.         Vector3[] verts = mesh.vertices;
    6.         int[] tris = mesh.triangles;
    7.         Vector2[] uvs = null;
    8.         switch (uvToExport)
    9.         {
    10.             case UVGroup.Default:
    11.                 uvs = mesh.uv;
    12.                 break;
    13.             case UVGroup.Lightmap:
    14.                 uvs = mesh.uv2;
    15.                 break;
    16.         }
    17.  
    18.  
    19.         List<Edge> singleEdges = new List<Edge>();
    20.         List<Edge> doubleEdges = new List<Edge>();
    21.         for (int i = 0; i < tris.Length; i += 3)
    22.         {
    23.             int[] sortedTris = new int[] { tris[i], tris[i + 1], tris[i + 2] };
    24.             Array.Sort(sortedTris);
    25.             Edge edge0 = new Edge() { a = sortedTris[0], b = sortedTris[1] };
    26.             Edge edge1 = new Edge() { a = sortedTris[0], b = sortedTris[2] };
    27.             Edge edge2 = new Edge() { a = sortedTris[1], b = sortedTris[2] };
    28.             Action<Edge> insertEdge = (Edge edge) =>
    29.             {
    30.  
    31.                 {
    32.                     if (doubleEdges.Contains(edge))
    33.                     {
    34.                         doubleEdges.Remove(edge);
    35.                         singleEdges.Add(edge);
    36.                     }
    37.                     else if (singleEdges.Contains(edge))
    38.                     {
    39.                         singleEdges.Remove(edge);
    40.                         doubleEdges.Add(edge);
    41.                     }
    42.                     else
    43.                     {
    44.                         singleEdges.Add(edge);
    45.                     }
    46.                 }
    47.             };
    48.             insertEdge(edge0);
    49.             insertEdge(edge1);
    50.             insertEdge(edge2);
    51.         }
    52.         GL.PushMatrix();
    53.         GL.MultMatrix(transform.localToWorldMatrix);
    54.         for (int i = 0; i < singleEdges.Count; i++)
    55.         {
    56.             GL.Begin(GL.LINE_STRIP);
    57.             GL.Color(Color.green);
    58.             GL.Vertex(uvs[singleEdges[i].a]);
    59.             GL.Vertex(uvs[singleEdges[i].b]);
    60.             GL.End();
    61.         }
    62.         for (int i = 0; i < doubleEdges.Count; i++)
    63.         {
    64.             GL.Begin(GL.LINE_STRIP);
    65.             GL.Color(Color.white);
    66.             GL.Vertex(uvs[doubleEdges[i].a]);
    67.             GL.Vertex(uvs[doubleEdges[i].b]);
    68.             GL.End();
    69.         }
    70.         GL.PopMatrix();
    71.     }
     
  2. DouglasPotesta

    DouglasPotesta

    Joined:
    Nov 6, 2014
    Posts:
    109
    Nvm unity lightmap uvs are just jank like that.
    My code is perfect. I am number one!!!
     
  3. DouglasPotesta

    DouglasPotesta

    Joined:
    Nov 6, 2014
    Posts:
    109
    Although I did find it I had it flipped in the x... woops (image below is a view of the lightmap uvs in 3dsmax).
    upload_2020-3-21_17-25-20.png
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    The issue is the seams you see are going to be partially based on if the mesh has seams for other reasons, like from the primary UV which I expect the case here. The reason is splits from UVs, normals, or vertex colors result in actually splitting the mesh and duplicating those edge vertices. So in this case if your primary UVs are a cylindrical projection, that would cause there to be a seam down the side and up to the two points where the mesh was split and that seam would then also be visible in the lightmap UVs which are more akin to a box map.
     
    DouglasPotesta likes this.
  5. DouglasPotesta

    DouglasPotesta

    Joined:
    Nov 6, 2014
    Posts:
    109
    This is insightful. Thanks for the reply.
    I have a lot to learn before I can say I truly get it.