C# 我可以创建一个网格(在唤醒中),但我看不到它
这是生成网格的代码部分,如果需要更多信息,请询问。 因此,在场景中我看不到它,我试图进入播放模式,但什么都没有,如果我进入检查器,我可以看到:4个顶点,2个tris,正确数量的tris和vertsC# 我可以创建一个网格(在唤醒中),但我看不到它,c#,unity3d,C#,Unity3d,这是生成网格的代码部分,如果需要更多信息,请询问。 因此,在场景中我看不到它,我试图进入播放模式,但什么都没有,如果我进入检查器,我可以看到:4个顶点,2个tris,正确数量的tris和verts public void ConstructMesh() { Vector3[] vertices = new Vector3[(resolution + 2) * (resolution + 2)]; int[] triangles = new int[(re
public void ConstructMesh()
{
Vector3[] vertices = new Vector3[(resolution + 2) * (resolution + 2)];
int[] triangles = new int[(resolution + 1) * (resolution + 1) * 6];
int triIndex = 0;
for (int y = 0; y < resolution; y++)
{
for (int x = 0; x < resolution; x++)
{
int i = x + y * resolution;
Vector2 percent = new Vector2(x, y) / (resolution - 1);
Vector3 pointOnUnitCode = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB;
vertices[i] = pointOnUnitCode;
triangles[triIndex] = i;
triangles[triIndex + 1] = i + resolution + 1;
triangles[triIndex + 2] = i + resolution;
triangles[triIndex + 3] = i;
triangles[triIndex + 4] = i + 1;
triangles[triIndex + 5] = i + resolution + 1;
triIndex += 6;
}
}
planet.Clear();
planet.vertices = vertices;
planet.triangles = triangles;
planet.RecalculateNormals();
}
public void ConstructMesh()
{
向量3[]顶点=新向量3[(分辨率+2)*(分辨率+2)];
int[]三角形=新int[(分辨率+1)*(分辨率+1)*6];
int-triIndex=0;
对于(int y=0;y<分辨率;y++)
{
对于(int x=0;x
您需要游戏对象中的网格渲染器和网格过滤器才能渲染网格
假设您的方法ConstructMesh是一个MonoBehavior,并且它附加到要显示网格的同一对象,则可以执行以下操作:
GetComponent<MeshFilter>().mesh = planet;
GetComponent().mesh=planet;
是否将网格指定给任何MeshRenderer
组件?是的,但我解决了,谢谢。