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

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

问题描述

我正在为自己的工具编写自己的uv编辑器,并且正在尝试为投影合并尽可能多的算法。我需要获取一个任意的网格,并为每个顶点创建uv坐标。



到目前为止,我有平面和最小二乘共形贴图。



我想结合更多的东西,例如三平面的,圆柱的,球形的,但是我很难找到信息来执行算法。三平面看起来会产生颜色,但是我需要将所有东西都放在UV坐标中。



非常感谢帮助!

解决方案

三平面



忘了它: it不是投影算法(一种可提供UV坐标的算法),并且无法从中获取UV坐标。这是一种渲染算法,为您提供一种颜色,该颜色是通过混合分别使用每个XYZ平面投影将获得的颜色而获得的。



圆柱,球面



类似于平面,这些都是非常简单的投影算法,可以直接从XYZ值获得UV值,而无需考虑与其他顶点。




  • 对于圆柱形:将(x,y,z)转换为圆柱坐标(ρ,φ,z),并将u =φ和v = z
  • $作为UV坐标使用b $ b
  • 对于球形:在中转换(x,y,z)球坐标(r,θ,φ),并用作UV坐标,u =θ,v =φ



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



三次



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





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




  • 如果n =(0.8,0.5,0.3),则对应的面是X(| nx |是最大且nx是正数)

  • 如果n =(0.3,0.8,0.5),则对应的脸是Y(| ny |是最大数,ny是正数)

  • 如果n =(0.3,-0.8,0.5),则对应的脸是-Y(| ny |最大,而ny为负)



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



下一步是将该值uv_temp∈[0,1] x [0,1]转换为图像中较小的正方形中包含的值uv以上。例如,如果您应用投影 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.

  • For cylindrical: convert (x, y, z) into Cylindrical Coordinates (ρ, φ, z), and use as UV coordinates u = φ and v = z
  • For spherical: convert (x, y, z) in Spherical Coordinates (r, θ, φ), and use as UV coordinates u = θ and v = φ

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天全站免登陆