UV 贴图墙的正确方法是什么?

Whats the proper way to UV Map a wall?

我目前正在开发一种地图工具,可以为我的游戏生成自定义地图。我的网格生成工作得很好,但我看不出如何正确地对我的脸进行 UV 贴图以使纹理保持一致。我已经通过使用相应的坐标对使 UV 贴图在地板上完美工作,但墙壁似乎工作不一样。

有谁知道将 UV 贴图映射到垂直墙的正确方法吗?

这里有一些我现在的墙的例子:

我目前正在将其用于墙壁的 UV 映射

        currentMesh.uvs.Add(new Vector2(0, 0));
        currentMesh.uvs.Add(new Vector2(1, 0));
        currentMesh.uvs.Add(new Vector2(0, 1));
        currentMesh.uvs.Add(new Vector2(1, 1));

对于这种情况,我执行以下步骤:
1. 将纹理设为正方形(为了减少下面代码中的计算)。此外,使其无缝并环绕模式重复。
2. 像这样找出矩形的长和宽:

Length = (float)Vector3.Distance(mesh.vertices [0],mesh.vertices [1])
Width = (float)Vector3.Distance(mesh.vertices [0],mesh.vertices [3])

3.Then 我使用这个代码的UV贴图:

    Vector2[] uv = new Vector2[mesh.vertices.Length];
    float min = Length>Width?Length:Width;
    for (int i = 0, y = 0; i < uv.Length; i++){
        uv [i] = new Vector2 ((float)mesh.vertices [i].z / min, (float)mesh.vertices [i].y / min);    
    }

这里,我取了.z.y,因为我的平面在yz平面。这段代码所做的是,找到矩形的小臂并根据它拟合纹理。
这是结果的屏幕截图:

这是我使用的纹理:

我从这里学到的:
http://catlikecoding.com/unity/tutorials/procedural-grid/

我已经弄明白了。我最后做的是取顶点的 XZ 并根据墙的方向取两者的权重得到了我想要的结果

        Vector3 heading = new Vector3(floor2.x - floor1.x, 0, floor2.z - floor1.z);
        Vector3 direction = heading / heading.magnitude;

        currentMesh.uvs.Add(new Vector2(((floor1.x * direction.x) + (floor1.z * direction.z)) / scale, floor1.y / scale));
        currentMesh.uvs.Add(new Vector2(((floor2.x * direction.x) + (floor2.z * direction.z)) / scale, floor2.y / scale));
        currentMesh.uvs.Add(new Vector2(((ceil1.x * direction.x) + (ceil1.z * direction.z)) / scale, ceil1.y / scale));
        currentMesh.uvs.Add(new Vector2(((ceil2.x * direction.x) + (ceil2.z * direction.z)) / scale, ceil2.y / scale));