Unity Mesh教程 之 Mesh画的图形贴图UV处理。在使用Mesh画兔脒巛钒图形时,如果UV不作处理,当贴上贴图时,贴图会不对。本节介绍在Mesh画图时的UV处理的简单案例,具体如下
工具/原料
Unity
Mesh UV
一、知识要点
1、Mesh:A class that allows creat坡纠课柩ing or modifying meshes from scripts.Meshes contain vertices and multiple triangle arrays. See theProcedural example projectfor examples of using the mesh interface.The triangle arrays are simply indices into the vertex arrays; three indices for each triangle.For every vertex there can be a normal, two texture coordinates, color and tangent. These are optional though and can be removed at will. All vertex information is stored in separate arrays of the same size, so if your mesh has 10 vertices, you would also have 10-size arrays for normals and other attributes.
2、Mesh.uv:1)功能简介public Vector2[]uv;The base texture coordinates of the M髫潋啜缅esh.2)笔记NoteTexture coordinates have to be modified or created externally from the Mesh. In the script example above, the uvs is created as a new array, then the texture coordinates are assigned to that array. Once these are assigned, the array is assigned to theMesh.
二、Mesh教程 之 Mesh画的图形贴图UV处理
1、打开Unity,新建一个空工程,具体如下
2、根据绘制三角形的方法,绘制一个图形,其中三角形点的赋值过程、代码和画图结果,具体如下图
3、在场景中,新建一个“Quad”,把绘制的附上一样的材质,结果大概一样,具体如下图
4、但是当给他们附上同样的Image的时候 ,右边绘制的就与原本的“Quad”有不同了,具体如下图
5、回到脚本中添加图形的UV,即把几个列表的点顺序加上去,代码和代码说明如下图
6、脚本编译正确后,回到Unity界面,运行场景,再把图片拖给他们,结果与原本一样的,具体如下图
7、到此,《Unity Mesh教程 之 Mesh画的图形贴图UV处理》讲解结束,谢谢