我正在尝试为我的 Unreal Engine 项目创建一个函数,它将接受一个 UV 坐标作为圆的中心点、像素空间中圆的半径和纹理的分辨率,并使用这个信息在圆圈中生成一组 UV 坐标。在我尝试针对 VR 进行优化时,是否有比我当前的代码更好的方法?我需要执行这个操作几十次,但目前单次迭代仍然需要一段时间。
TArray<FVector2D> Uread_write_text::CircularUV(FVector2D centre, int radius, FVector2D resolution) {
TArray<FVector2D> uvs;
// Iterate through pixel space, by getting the centre in UV space and finding it's
// equilavent in pixel space and then find the extents.
for (int i = FGenericPlatformMath::TruncToInt((centre.X * resolution.X) - radius);
i < FGenericPlatformMath::TruncToInt((centre.X * resolution.X) + radius);
i++) {
for (int j = FGenericPlatformMath::TruncToInt((centre.Y * resolution.Y) - radius);
j < FGenericPlatformMath::TruncToInt((centre.Y * resolution.Y) + radius);
j++) {
// Checks if i and j is within the circle radius, therefore the coordinates are within the circle
if ((i <= (centre.X * resolution.X) + radius) & (i >= (centre.X * resolution.X) - radius)) {
if ((j <= (centre.Y * resolution.Y) + radius) & (j >= (centre.Y * resolution.Y) - radius)) {
// Does the final conversion back to UV space once it has been confirmed that it is
// a correct coordinate
float x = i / resolution.X;
float y = j / resolution.Y;
// Adds it to the return value
uvs.Add(FVector2D(x, y));
}
}
}
}
return uvs;
}