自动生成UV坐标算法 [英] Automatically generating UV coordinates algorithms

查看:58
本文介绍了自动生成UV坐标算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的工具编写自己的 uv 编辑器,并且我正在尝试合并尽可能多的算法来进行投影.我需要采用任意网格,并为每个顶点制作 uv 坐标.

到目前为止,我有平面和最小二乘等角贴图.

我想合并更多,例如三平面、圆柱、球面,但我很难找到执行算法的信息.三平面似乎生成颜色,但我需要在 UV 坐标中获取所有内容.

非常感谢您的帮助!!

解决方案

Tri-planar

忘记它:它不是投影算法(一种为您提供 UV 坐标的算法),并且您无法从中获取 UV 坐标.这是一种渲染算法,通过混合您分别使用每个 X-Y-Z 平面投影获得的颜色,为您提供一种颜色.

圆柱形、球形

与平面一样,这些都是非常简单的投影算法,可以直接根据 XYZ 值为您提供 UV 值,而无需考虑与其他顶点的连接性.

当然,您可以切换 X、Y 和 Z 的角色以使用不同的轴进行投影,或者执行一些平移/旋转/缩放以获得更多控制(与您可以控制投影的大小和方向相同的方式)用于平面投影的平面).

立方

首先,您需要确定将网格的每个面分配给哪个投影面".我将投影面命名为 X、-X、Y、-Y、Z 和 -Z,如下图所示(假设 X、Y 和 Z 轴分别具有红色、绿色和蓝色):

为此,您只需找到法线(nx,ny,nz)的哪个坐标具有最大的绝对值,并将其分配给与该轴和符号对应的面.例如:

然后,一旦知道将网格的每个面分配给哪个投影面,就可以将相应的平面投影应用于该面周围的顶点以获得临时值 (u_temp, v_temp) ∈ [0,1] x[0,1].

下一步是将此值 uv_temp ∈ [0,1] x [0,1] 转换为包含在较小正方形中的值 uv,如上图 A 所示.例如,如果你应用了投影X",那么你想要 uv ∈ [2/3, 3/3] x [2/4, 3/4],那么你会这样做:

u = 2./3.+ u_temp/3.;v = 2./4.+ v_temp/4.;

最后,最后一步不要忘记复制属于两个平面投影不同的面(图片上不同颜色之间的边界)的UV顶点.实际上,网格的某些顶点可以(并且在大多数情况下应该)在 UV 贴图中的多个位置进行分割,以获得不错的结果.

I'm writing my own uv editor for a tool of mine, and I'm trying to incorporate as many algorithms as I can for projections. I need to take an arbitrary mesh, and make uv coordinates for each vertex.

So far, I have planar, and Least Squares Conformal Map.

I'd like to incorporate more, such as tri-planar, cylinder, spherical, but I'm having a very difficult time locating the information to perform the algorithms. The tri-planar appear to generate a color, but I need to get everything in UV coordinates.

Help would be very appreciated!!

解决方案

Tri-planar

Forget about it: it is not a projection algorithm (an algorithm that gives you UV coordinates), and there is no way you can get UV coordinates out of it. It is a rendering algorithm that gives you a color obtained by blending what color you would obtained using each X-Y-Z planar projections separately.

Cylindrincal, Spherical

Like planar, those are very simple projection algorithms that give you a UV value directly from a XYZ value, without taking into account the connectivity with other vertices.

Of course, you can switch the roles of X, Y and Z to project using a different axis, or perform some translation/rotation/scaling to have more control (the same way that you can control the size and orientation of the plane you use for the planar projection).

Cubic

First, you need to determine to which "projection face" you assign each face of your mesh. I name the projection faces X, -X, Y, -Y, Z and -Z as in the figure below (where I assume the X, Y, and Z axis have respectively the colors Red, Green, and Blue):

For this, you simply find which coordinate of the normal (nx, ny, nz) has the greatest absolute value, and assign it to the face corresponding to this axis and sign. For instance:

  • if n = (0.8, 0.5, 0.3), then the corresponding face is X (|nx| is the greatest and nx is positive)
  • if n = (0.3, 0.8, 0.5), then the corresponding face is Y (|ny| is the greatest and ny is positive)
  • if n = (0.3, -0.8, 0.5), then the corresponding face is -Y (|ny| is the greatest and ny is negative)

Then, once you know to which projection face you assign every face of your mesh, you can apply the corresponding planar projection to the vertices around this face to get a temporary value (u_temp, v_temp) ∈ [0,1] x [0,1].

The next step is to transform this value uv_temp ∈ [0,1] x [0,1] into a value uv included in the smaller square as represented in the image A above. For instance, if you applied the projection "X", then you want uv ∈ [2/3, 3/3] x [2/4, 3/4], then you would do:

u = 2./3. + u_temp/3.;
v = 2./4. + v_temp/4.; 

Finally, the last step is not to forget to duplicate the UV vertices that belong to two faces with different planar projection (the borders between the different colors on the picture). Indeed, some vertices of the mesh can (and should in most cases) be split in several positions in the UV map to give decent results.

这篇关于自动生成UV坐标算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆