0

我正在生成一个能够缩放的平面,而纹理的边缘不会受到像素方面的影响。飞机需要能够保持其边界比例,但能够伸展到几乎任何尺寸。网格有 8 个顶点和 10 个三角形来构成边界。无论如何,这就是我得到的。忽略网格几何体上的数字。

在此处输入图像描述

是否可以编辑 UV 以获得所需的结果?这是代码:

Mesh mesh = new Mesh();
    var renderer = mesh.AddRenderer();


    //create verticies

    mesh.vertices = new Vector3[] {

        //vertices in order for convienience 
        Manager.GUI.ScreenToWorldPoint(new Vector3(0f,0f,0f)),                            //0
        Manager.GUI.ScreenToWorldPoint(new Vector3(padding,padding,0)),                   //1
        Manager.GUI.ScreenToWorldPoint(new Vector3(width - padding, padding,0f)),         //2
        Manager.GUI.ScreenToWorldPoint(new Vector3(width,0f,0f)),                         //3
        Manager.GUI.ScreenToWorldPoint(new Vector3(width - padding, height - padding,0f)),//4
        Manager.GUI.ScreenToWorldPoint(new Vector3(width,height,0f)),                     //5
        Manager.GUI.ScreenToWorldPoint(new Vector3(padding, height - padding, 0f)),       //6
        Manager.GUI.ScreenToWorldPoint(new Vector3(0f,height,0f)),                        //7
    };



    //create triangles
    mesh.triangles = new int[] {
        7,5,6,
        6,5,4,
        4,5,3,
        2,4,3,
        0,2,3,
        0,1,2,
        0,7,6,
        0,6,1,
        1,6,4,
        1,4,2
};

    //create UV's uvs are in order of creation for convienience
       mesh.uv = new Vector2[] {
           new Vector2(0f,0f),
           new Vector2(padding/width, padding/height),
           new Vector2((width-padding)/width, padding/height),
           new Vector2(1f,0f),
           new Vector2((width - padding)/width,(height-padding)/height),
           new Vector2(1f,1f),
           new Vector2(padding/width,(height-padding)/height),
           new Vector2(0f,1f)





    };



    mesh.calculateNormals();
    mesh.calculateBounds();
    renderer.Texture = mytex;
    return plane;
}

填充是忽略缩放的纹理周围定义的像素,而高度和宽度是形状的尺寸。

4

1 回答 1

0

正如 George 所说,我生成的网格使得无法在没有兴趣的情况下缩放图像。修复网格必须重新制作成可以工作的东西。代码现在

Mesh mesh = new Mesh();
    var renderer = mesh.AddRenderer();
         mesh.vertices = new Vector3[] {

                //vertices in order for convienience  
                Manager.GUI.ScreenToWorldPoint(new Vector3(0f,0f,0f)),                            //0
                Manager.GUI.ScreenToWorldPoint(new Vector3(padding,0f,0f)),                      //1
                Manager.GUI.ScreenToWorldPoint(new Vector3(padding,padding,0)),                   //2
                Manager.GUI.ScreenToWorldPoint(new Vector3(width - padding, 0f,0f)),              //3
                Manager.GUI.ScreenToWorldPoint(new Vector3(width - padding, padding,0f)),         //4
                Manager.GUI.ScreenToWorldPoint(new Vector3(width,0f,0f)),                         //5
                Manager.GUI.ScreenToWorldPoint(new Vector3(width,padding,0f)),                    //6
                Manager.GUI.ScreenToWorldPoint(new Vector3(width , height - padding,0f)),         //7
                Manager.GUI.ScreenToWorldPoint(new Vector3(width - padding, height - padding,0f)),//8
                Manager.GUI.ScreenToWorldPoint(new Vector3(width,height,0f)),                     //9
                Manager.GUI.ScreenToWorldPoint(new Vector3(width - padding,height,0f)),           //10
                Manager.GUI.ScreenToWorldPoint(new Vector3(padding, height, 0f)),                 //11
                Manager.GUI.ScreenToWorldPoint(new Vector3(padding, height - padding, 0f)),       //12
                Manager.GUI.ScreenToWorldPoint(new Vector3(0f,height,0f)),                        //13
                Manager.GUI.ScreenToWorldPoint(new Vector3(0f,height - padding,0f)),              //14
                Manager.GUI.ScreenToWorldPoint(new Vector3(0f,padding,0f)),                       //15
            };



            //create triangles
            mesh.triangles = new int[] {
                15,2,0,
                1,0,2,
                1,2,4,
                1,4,3,
                3,4,6,
                3,6,5,
                4,8,7,
                4,7,6,
                8,10,9,
                8,9,7,
                12,10,8,
                12,11,10,
                14,11,12,
                14,13,11,
                15,14,12,
                15,12,2,
                2,12,8,
                2,8,4

    };

            //create UV's uvs are in order of creation for convienience
               mesh.uv = new Vector2[] {
                   new Vector2(0f,0f),   //0
                   new Vector2(padding / width, 0f), //1
                   new Vector2(padding/width, padding/height), //2
                   new Vector2((width-padding)/width, 0f), //3
                   new Vector2((width-padding)/width, padding/height), //4
                   new Vector2(1f,0f), //5
                   new Vector2(1f,padding / height), //6
                    new Vector2(1f, (height - padding) / height), //7
                   new Vector2((width - padding)/width,(height-padding)/height),//8
                   new Vector2(1f,1f), //9
                    new Vector2((width -padding)/width,1f), //10
                    new Vector2(padding/width,1f), //11
                   new Vector2(padding/width,(height-padding)/height), //12
                   new Vector2(0f,1f), //13
                   new Vector2(0f,(height - padding) / height), //14
                   new Vector2(0f,padding / height) //15





            };



            mesh.RecalculateNormals();
            mesh.RecalculateBounds();

            return plane;

希望它可以帮助其他程序员

于 2013-05-14T21:53:30.130 回答