1// CreateLineMeshの引数のthicknessは廃止し、マテリアル側で設定することにする2 public static Mesh CreateLineMesh(Vector3 center,float length)3{4 var mesh = new Mesh();5 var triangles = new int[6];6 triangles[0]=0;7 triangles[1]=1;8 triangles[2]=2;9 triangles[3]=2;10 triangles[4]=3;11 triangles[5]=0;12 var vertices = new Vector3[4];1314// bottomとtopはcenter.yとし、現時点では太さのない潰れた長方形の状態にしておく15 var left = center.x - length /2.0f;16 var right = center.x + length /2.0f;17 var bottom = center.y;18 var top = center.y;1920 vertices[0]= new Vector3(left, bottom, center.z);21 vertices[1]= new Vector3(left, top, center.z);22 vertices[2]= new Vector3(right, top, center.z);23 vertices[3]= new Vector3(right, bottom, center.z);2425 var nornals = vertices.ToArray();2627// 各頂点に追加情報を埋め込む28// まずXYZには線分の逆末端の座標をいれておく29// (left側頂点にはright側の、right側頂点にはleft側の座標)30 var otherVertices = new Vector4[vertices.Length];31for(var i =0; i < otherVertices.Length; i++)32{33 otherVertices[i]= vertices[vertices.Length - i -1];34}3536// そしてWには0~3の数値を入れておく37// これは各頂点が4隅のうちどれであるかを特定する目的のもので、さしあたり38// 1ビット目がbottomかtopかを、2ビット目がleftかrightかを示すことにした39 otherVertices[0].w =0;40 otherVertices[1].w =1;41 otherVertices[2].w =3;42 otherVertices[3].w =2;4344 mesh.SetVertices(vertices);45 mesh.SetTriangles(triangles,0);46 mesh.SetNormals(nornals);4748// 追加情報の埋め込み先はUVを使わせてもらうことにした49 mesh.SetUVs(0, otherVertices);5051 mesh.RecalculateBounds();5253return mesh;54}
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2022/07/31 09:42
2022/07/31 21:34
2022/08/01 03:56
2022/08/01 22:27
2022/08/02 02:02
2022/08/03 18:43
2022/08/04 00:37