unity, Gizmos.DrawMesh一个坑

时间:2025-01-27 19:33:20

错误写法(画不出来):

void OnDrawGizmos(){

  Mesh mesh=new Mesh();

  mesh.vertices=...

  mesh.triangles=...

  //mesh.RecalculateBounds()

  Gizmos.DrawMesh(mesh);

}

正确写法1:

void OnDrawGizmos(){

  Mesh mesh=new Mesh();

  mesh.vertices=...

  mesh.triangles=...

  mesh.normals=...

  //mesh.RecalculateBounds()

  Gizmos.DrawMesh(mesh);

}

正确写法2:

void OnDrawGizmos(){

  Mesh mesh=new Mesh();

  mesh.vertices=...

  mesh.triangles=...

  mesh.RecalculateNormals ();

//mesh.RecalculateBounds()

  Gizmos.DrawMesh(mesh);

}