将多边形从 3d 空间展开到 2d 空间(使用三角形)以获得纹理坐标

发布于 2024-10-14 18:24:57 字数 550 浏览 3 评论 0原文

所以我在Ogre3D中创建了一个模型,这个模型由许多任意旋转和位置的三角形组成。我想像许多建模程序一样“展开”模型,以便所有三角形都映射到 2d (x,y),但保持三角形大小。这是为了应用贴花。必须保持三角形大小的原因是,应用纹理时不会出现任何拉伸。

这是我想要进入的方向,但我很难将其可视化并实现正确的算法:

//Verticies will have a converted bool;

func( triangle x):
     for each of x's vertices:
           map to x,y coordinates if not converted;
           check other triangles for common vertex if so call func(common_tri);

一旦返回,将出现所有三角形的转换版本,以便它们全部展开并可放置在纹理上,其中我遇到的麻烦是映射到 x,y 空间。我不确定如何在 3d 空间到 2d 空间中获得一个三角形,以便它保持其所有属性(例如从表面的角度视图到垂直视图)任何帮助将不胜感激。

So I have created a model in Ogre3D and this model is made up of a number of triangles of arbitrary rotation and position. I would like to "unwrap" the model like many modelling programs do so that all of the triangles are mapped to 2d (x,y) but the triangle sizes are maintained. This is for applying decals. The reason the triangle sizes must be maintained so that when the texture is applied there isn't any stretching.

This was the direction I was thinking of going in but I am having trouble visualizing it and achieving the correct algorithms:

//Verticies will have a converted bool;

func( triangle x):
     for each of x's vertices:
           map to x,y coordinates if not converted;
           check other triangles for common vertex if so call func(common_tri);

Once this returns there will be a converted version of all of the triangles so that they are all unwrapped and placeable on the texture, where I am having trouble is the mapping to x,y space. I'm not sure how to get a triangle in 3d space to 2d space so that it maintains all of its attributes (like going from an angled view to a perpedicular view of the surface) Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山田美奈子 2024-10-21 18:24:57

我会将顶点视为向量。

因此,您可以标准化每个向量,然后删除 Z 坐标,然后再次应用乘法。

tri = vec1,vec2,vec3, 
vec1Length = vec1.getLength()
newVec1 = vec1.normalize() * vec1Length

因为这将保留矢量的大小,但将它们映射到二维平面。
(或者应该,我不是 100% 这在数学上是正确的。)

您可以做到这一点的另一种方法是将三角形本身视为 2d 平面,然后将向量从该局部空间转换为 2d 平面世界空间平面。

例如,世界原点是 (0,0,0)。

三角形本身是由三个点定义的平面,您使用一个向量作为 X 坐标,找到一个垂直于该向量的向量,然后定义 y 坐标。您还可以通过 X 叉积 Y 定义 Z,这将为您提供距世界原点的“偏移量”,然后您可以将它们映射回由来自世界原点的 X、Y 向量表示的 2d 平面(即( 1,0) 和 (0,1))。许多基础计算机图形书籍中应该有数学知识来做到这一点。

I would think of the vertices as vectors.

So, you could normalize each vector, then remove the Z coordinate, and then apply the multiplication again.

i.e.

tri = vec1,vec2,vec3, 
vec1Length = vec1.getLength()
newVec1 = vec1.normalize() * vec1Length

As this will preserve the size of the vectors, but map them to a 2d plane.
(or it should, I'm not 100% that this is mathematically correct.)

The other way you could do this, is by thinking of the triangle itself as a 2d plane, and then transforming the vectors from that local space to the 2d plane of world space.

So for example, world origin is (0,0,0).

The triangle itself is a plane defined by the three points, you use one vector as the X coordinate, find a vector perpendicular to that, and you have the y coordinate defined. You can also define the Z by X cross product Y, this will give you an "offset" from the world origin, you can then map those back onto the 2d plane represented by the X, Y vectors from the world origin (i.e., (1,0) and (0,1)). There should be math to do this in lots of basic computer graphics books.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文