我有一个代表球体表面部分的网格,但在确定顶点的 UV 坐标时遇到了一些麻烦。
鉴于 verts 的生成代码,有人可以解释/提供我如何确定 uv 坐标的示例吗?
传入的“区域”包含北、南、东、西的度数。该代码将值转换为弧度,并确定在水平和垂直方向上所需的顶点数的步进量。
这么多工作正常。
对于这个“区域”,会生成球体表面的一部分,我想在该部分放置纹理,其中纹理的角也是网格的角。
换句话说,我如何在下面的代码中执行“待办事项”...
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<Vector3>();
var uvList = new List<Vector2>();
// ok lets do this
for (double az = range.West; az <= range.East; az += horizontalStep)
{
for (double inc = range.South; inc <= 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();
}