为什么Unity的Graphics.DrawMesh在其任何构造函数重载中都不接受scale参数是有特定原因的吗?

Ste*_*low 1 unity-game-engine

当前Graphics.DrawMesh具有以下构造函数:

public static void DrawMesh(Mesh mesh, Vector3 position, Quaternion rotation);
public static void DrawMesh(Mesh mesh, Vector3 position, Quaternion rotation, int materialIndex);
public static void DrawMesh(Mesh mesh, Vector3 position, Quaternion rotation, Material material, int layer, Camera camera = null, int submeshIndex = 0, MaterialPropertyBlock properties = null, bool castShadows = true, bool receiveShadows = true);
public static void DrawMesh(Mesh mesh, Vector3 position, Quaternion rotation, Material material, int layer, Camera camera, int submeshIndex, MaterialPropertyBlock properties, Rendering.ShadowCastingMode castShadows, bool receiveShadows = true, Transform probeAnchor = null);
public static void DrawMesh(Mesh mesh, Matrix4x4 matrix);
public static void DrawMesh(Mesh mesh, Matrix4x4 matrix, int materialIndex);
public static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material material, int layer, Camera camera = null, int submeshIndex = 0, MaterialPropertyBlock properties = null, bool castShadows = true, bool receiveShadows = true);
public static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material material, int layer, Camera camera, int submeshIndex, MaterialPropertyBlock properties, Rendering.ShadowCastingMode castShadows, bool receiveShadows = true, Transform probeAnchor = null);
Run Code Online (Sandbox Code Playgroud)

位置旋转被暴露,没有过载的接受比例参数来设置刻度动态拉伸网状的。

  1. 是否有特定原因?
  2. 无论如何,最好的扩展方式是什么?

小智 5

您可以使用Matrix4x4.TRS函数创建一个结合位置,旋转和比例的矩阵,然后可以在Graphics.DrawMesh中使用它。例如:

Vector3 position = Random.insideUnitSphere;
Quaternion rotation = Random.rotation;
Vector3 scale = new Vector3(0.5f, 1, 2.5f);

Matrix4x4 matrix = Matrix4x4.TRS(position, rotation, scale);

Graphics.DrawMesh(mesh, matrix, material, 0);
Run Code Online (Sandbox Code Playgroud)