国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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ó)家法律
建宁县| 五华县| 长治县| 宝鸡市| 中宁县| 墨玉县| 望谟县| 灵山县| 桂平市| 湾仔区| 临邑县| 阜阳市| 尼木县| 长海县| 始兴县| 河池市| 新营市| 博乐市| 门源| 滦南县| 北安市| 蚌埠市| 北流市| 察雅县| 离岛区| 潜江市| 郑州市| 松江区| 枣强县| 平泉县| 朝阳县| 西藏| 益阳市| 晋江市| 监利县| 措勤县| 吉安县| 台湾省| 盘锦市| 蕉岭县| 灵武市|