我目前正在与UE4合作开发一个项目并编写了一个高度图生成器,并将他与delaunay-triangulator结合起来。然后我必须从输出文件中读取三角形/顶点。但我对紫外线有问题。每个顶点都想要定义U和V变量,但我不知道如何计算它们。基本上,我放在最终网格上的纹理应该看起来像一个大的纹理。我唯一能够工作的东西(只是玩0-1范围内的值)是每个三角形都有一个纹理显示,但没有与其他三角形对齐,所以它看起来像一个核电站爆炸。 / p>
以下是我从两个文件中读取所有顶点并指定UV随机类型的代码。
inStream >> vertexCount >> buffer >> buffer; // first element is the number of elements // skip second and third
TArray<FProceduralMeshTriangle> triangles;
for (int i = 0; i < vertexCount; i++){
FProceduralMeshTriangle triangle;
FProceduralMeshVertex v0, v1, v2;
int i1, i2, i3;
inStream >> buffer >> i1 >> i2 >> i3;
i1--;
i2--;
i3--;
v0.Position.X = nodes[i1].X;
v0.Position.Y = nodes[i1].Y;
v0.Position.Z = vectorPoints[nodes[i1].X][nodes[i1].Y].first;
//v0.Position.Z = 5;
v0.U = 0.0;
v0.V = 0.5;
v1.Position.X = nodes[i2].X;
v1.Position.Y = nodes[i2].Y;
v1.Position.Z = vectorPoints[nodes[i2].X][nodes[i2].Y].first;
v1.U = 0.5;
v1.V = 0.5;
v2.Position.X = nodes[i3].X;
v2.Position.Y = nodes[i3].Y;
v2.Position.Z = vectorPoints[nodes[i3].X][nodes[i3].Y].first;
v2.U = 0.0;
v2.V = 0.0;
triangle.Vertex0 = v0;
triangle.Vertex1 = v1;
triangle.Vertex2 = v2;
triangles.Add(triangle);
}
感谢您的帮助!
线框:
指定材料:
编辑:
好的,我添加了以下代码:
double range = (lowestX - highestX)*-1;
double offset = 0 - lowestX;
for (int i = 0; i < triangles.Num(); i++){
FProceduralMeshVertex vT;
vT = triangles[i].Vertex0;
vT.U = (vT.Position.X + offset) / range;
vT.V = 1 - vT.U;
triangles[i].Vertex0 = vT;
vT = triangles[i].Vertex1;
vT.U = (vT.Position.X + offset) / range;
vT.V = 1 - vT.U;
triangles[i].Vertex1 = vT;
vT = triangles[i].Vertex2;
vT.U = (vT.Position.X + offset) / range;
vT.V = 1 - vT.U;
triangles[i].Vertex2 = vT;
}
现在它看起来不像是一个核事故,但纹理在整个网格上拉伸,而不是重复,它仍然是轻微扭曲..