title: Determining uv coords for dynamically generated mesh in unity
body: <p>I have a mesh that represents portion of the surface of a sphere and I am having some trouble figuring out the UV coordinates for the verts. </p>
  
  <p>Given the generation code for the verts could someone explain / provide an example of how I can determine the uv coordinates?</p>
  
  <p>The "Region" passed in contains north, south, east, and west in degrees.
  The code converts the values to radians and determines the amount to step for the desired number of verts in both horizontal and vertical directions.</p>
  
  <p>That much works fine.</p>
  
  <p>For this "region" a portion of the surface of a sphere is generated and I want to place a texture on that portion where the corners of the texture are also the corners of the mesh.</p>
  
  <p>In other words how do I do the "todo" in the code below ...</p>
  
  <pre><code>public void BuildVerts(Voxels.Objects.PlanetRegion region, int planetSize, int verticals, int horizontals, out Vector3[] verts, out Vector2[] uvs)
  {
      // determine range and stepping variable
      var range = region.ToRadians();
      var verticalStep = (range.East - range.West) / horizontals;
      var horizontalStep = (range.North - range.South) / verticals;
  
      // define result containers
      var vertList = new List&lt;Vector3&gt;();
      var uvList = new List&lt;Vector2&gt;();
  
      // ok lets do this 
      for (double az = range.West; az &lt;= range.East; az += horizontalStep)
      {
          for (double inc = range.South; inc &lt;= range.North; inc += verticalStep)
          {
              var newVert = new Vector3(
                  (float)(planetSize * Math.Sin(az) * Math.Cos(inc)),
                  (float)(planetSize * Math.Sin(az) * Math.Sin(inc)),
                  (float)(planetSize * Math.Cos(az))
              );
  
              //TODO: Determine this!
              var newUv = new Vector2();
  
              vertList.Add(newVert);
              uvList.Add(newUv);
          }
      }
  
      verts = vertList.ToArray();
      uvs = uvList.ToArray();
  }
  </code></pre>