简体   繁体   English

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

[英]Unwrapping a polygon from 3d to 2d space (using triangles) for texture coordinates

So I have created a model in Ogre3D and this model is made up of a number of triangles of arbitrary rotation and position. 因此,我在Ogre3D中创建了一个模型,该模型由任意旋转和位置的多个三角形组成。 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. 我想像许多建模程序一样“解开”模型,以便将所有三角形都映射到2d(x,y),但保持三角形的大小。 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. 一旦返回,将有所有三角形的转换版本,以便它们都可以解开并放置在纹理上,而我遇到的麻烦是映射到x,y空间。 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. 我不确定如何在3d空间中将三角形变成2d空间,以使其保持其所有属性(例如,从角度视图变为曲面的垂直视图),将不胜感激。

I would think of the vertices as vectors. 我认为顶点是向量。

So, you could normalize each vector, then remove the Z coord, and then apply the multiplication again. 因此,您可以标准化每个向量,然后删除Z坐标,然后再次应用乘法。 ie tri = vec1,vec2,vec3, vec1Length = vec1.getLength() newVec1 = vec1.normalize() * vec1Length 即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. 因为这将保留矢量的大小,但是将它们映射到2d平面。 (or it should, I'm not 100% that this is mathematically correct.) (或者应该不是,我不是100%在数学上是正确的。)

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. 另一种方法是将三角形本身视为2d平面,然后将向量从该局部空间转换为世界空间的2d平面。

So for example, world origin is (0,0,0) 举例来说,世界原点是(0,0,0)

the triangle itself is a plane defined by the three points, you use one vector as the X coord, find a vector perpendicular to that, and you have the y coord defined. 三角形本身是由三个点定义的平面,您使用一个矢量作为X坐标,找到一个垂直于该坐标的矢量,并定义了y坐标。 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 reprsented by the X,Y vectors from the world origin (ie (1,0) and (0,1)). 您还可以通过X叉积Y定义Z,这将为您提供与世界原点的“偏移”,然后可以将其映射回由世界原点的X,Y向量表示的2d平面(即(1 ,0)和(0,1))。 There should be math to do this in lots of basic computer graphics books. 许多基本的计算机图形书籍中都应该有数学方法可以做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM