五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Unity中實(shí)時(shí)獲取網(wǎng)格上點(diǎn)的位置,還有對(duì)應(yīng)的面和法線

2023-03-09 19:22 作者:奇聞超解說  | 我要投稿

在Unity中,可以使用Mesh類來獲取一個(gè)網(wǎng)格上點(diǎn)的位置以及對(duì)應(yīng)的面和法線。以下是具體步驟:

步驟一:獲取網(wǎng)格對(duì)象

在腳本中,需要先獲取要操作的網(wǎng)格對(duì)象。可以使用以下代碼:

Mesh mesh = GetComponent<MeshFilter>().mesh;


其中,GetComponent<MeshFilter>()用于獲取該游戲?qū)ο笊系腗eshFilter組件,mesh屬性用于獲取該組件的網(wǎng)格對(duì)象。

步驟二:獲取網(wǎng)格上指定點(diǎn)的位置

獲取網(wǎng)格上指定點(diǎn)的位置可以使用以下代碼:

Vector3[] vertices = mesh.vertices;

Vector3 vertexPosition = vertices[vertexIndex];


其中,vertices是網(wǎng)格的頂點(diǎn)數(shù)組,vertexIndex為指定點(diǎn)在該數(shù)組中的索引,vertexPosition為該點(diǎn)的位置。

步驟三:獲取網(wǎng)格上指定點(diǎn)所在面的法線

獲取網(wǎng)格上指定點(diǎn)所在面的法線可以使用以下代碼:

int[] triangles = mesh.triangles;
int triangleIndex = triangles[vertexIndex / 3] * 3;
Vector3[] normals = mesh.normals;
Vector3 normal = normals[triangleIndex];


其中,triangles是網(wǎng)格的三角形索引數(shù)組,vertexIndex為指定點(diǎn)在該數(shù)組中的索引,由于一個(gè)三角形包含三個(gè)頂點(diǎn),所以需要除以3來獲取該點(diǎn)所在三角形的索引。triangleIndex為該點(diǎn)所在三角形的第一個(gè)頂點(diǎn)在triangles數(shù)組中的索引,normals為網(wǎng)格的法線數(shù)組,normal為該點(diǎn)所在面的法線。

步驟四:獲取網(wǎng)格上指定點(diǎn)所在面的索引

獲取網(wǎng)格上指定點(diǎn)所在面的索引可以使用以下代碼:

int[] triangles = mesh.triangles;
int triangleIndex = triangles[vertexIndex / 3];


其中,triangles是網(wǎng)格的三角形索引數(shù)組,vertexIndex為指定點(diǎn)在該數(shù)組中的索引,由于一個(gè)三角形包含三個(gè)頂點(diǎn),所以需要除以3來獲取該點(diǎn)所在三角形的索引。

以上就是在Unity中實(shí)時(shí)獲取一個(gè)網(wǎng)格上點(diǎn)的位置以及對(duì)應(yīng)的面和法線的方法。


Unity中實(shí)時(shí)獲取網(wǎng)格上點(diǎn)的位置,還有對(duì)應(yīng)的面和法線的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
香河县| 同心县| 珠海市| 仁布县| 台湾省| 广河县| 延川县| 邢台县| 长丰县| 钟祥市| 株洲市| 什邡市| 虎林市| 自贡市| 哈巴河县| 赣榆县| 藁城市| 东乡族自治县| 出国| 皋兰县| 太原市| 会理县| 宁安市| 张北县| 名山县| 临夏市| 瓮安县| 峡江县| 翁源县| 广东省| 临沭县| 南溪县| 郴州市| 宁陵县| 洞头县| 汉源县| 辽阳县| 邢台市| 靖宇县| 永吉县| 赤峰市|