【问题标题】:Whats the proper way to UV Map a wall?对墙壁进行 UV 映射的正确方法是什么?
【发布时间】:2018-01-24 02:45:38
【问题描述】:

我目前正在开发一个地图工具,它将为我的游戏生成自定义地图。我已经让网格生成完美地工作,但我无法弄清楚如何正确地对我的脸进行 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));

【问题讨论】:

    标签: c# unity3d mesh uv-mapping


    【解决方案1】:

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

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

    3.然后我用这段代码进行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/

    【讨论】:

      【解决方案2】:

      我已经设法弄清楚了。我最终做的是取顶点的 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));
      

      【讨论】:

        猜你喜欢
        • 2013-11-22
        • 1970-01-01
        • 2015-05-29
        • 1970-01-01
        • 2018-08-05
        • 1970-01-01
        • 2012-07-30
        • 2019-06-19
        • 1970-01-01
        相关资源
        最近更新 更多