UnityMesh教程之Mesh画的图形贴图UV处理。在使用Mesh画兔脒巛钒图形时,如果UV不作处理,当贴上贴图时,贴图会不对。本节介绍在Mesh画图时的UV处理的简单案例,具体如下
工具/原料
Unity
MeshUV
一、知识要点
1、Mesh:Aclassthatallowscreat坡纠课柩ingormodifyingmeshesfrom惺绅寨瞀scripts.Meshescontainverticesandmultipletrianglearrays.SeetheProceduralexampleprojectforexamplesofusingthemeshinterface.Thetrianglearraysaresimplyindicesintothevertexarrays;threeindicesforeachtriangle.Foreveryvertextherecanbeanormal,twotexturecoordinates,colorandtangent.Theseareoptionalthoughandcanberemovedatwill.Allvertexinformationisstoredinseparatearraysofthesamesize,soifyourmeshhas10vertices,youwouldalsohave10-sizearraysfornormalsandotherattributes.
2、Mesh.uv:1)功能简介publicVector2[]掼鸿乡羰uv;ThebasetexturecoordinatesoftheM髫潋啜缅esh.2)笔记NoteTexturecoordinateshavetobemodifiedorcreatedexternallyfromtheMesh.Inthescriptexampleabove,theuvsiscreatedasanewarray,thenthetexturecoordinatesareassignedtothatarray.Oncetheseareassigned,thearrayisassignedtotheMesh.
二、Mesh教程之Mesh画的图形贴图UV处理
1、打开Unity,新建一个空工程,具体如下
2、根据绘制三角形的方法,绘制一个图形,其中三角形点的赋值过程、代码和画图结果,具体如下图
3、在场景中,新建一个“Quad”,把绘制的附上一样的材质,结果大概一样,具体如下图
4、但是当给他们附上同样的Image的时候,右边绘制的就与原本的“Quad”有不同了,具体如下图
5、回到脚本中添加图形的UV,即把几个列表的点顺序加上去,代码和代码说明如下图
6、脚本编译正确后,回到Unity界面,运行场景,再把图片拖给他们,结果与原本一样的,具体如下图
7、到此,《UnityMesh教程之Mesh画的图形贴图UV处理》讲解结束,谢谢