public static Mesh Translate(this Mesh source, Vector3 position) { Mesh mesh = source.Copy(); Vector3[] origVerts = mesh.vertices; Vector3[] newVerts = new Vector3[origVerts.Length]; Matrix4x4 m = Matrix4x4.Translate(position); int i = 0; while (i < origVerts.Length) { newVerts[i] = m.MultiplyPoint3x4(origVerts[i]); i++; } mesh.vertices = newVerts; return(mesh); }
public static Mesh Transform(this Mesh source, Vector3 position, Vector3 rotation, Vector3 scale) { Mesh mesh = source.Copy(); Vector3[] origVerts = mesh.vertices; Vector3[] newVerts = new Vector3[origVerts.Length]; Quaternion rotationq = Quaternion.Euler(rotation.x, rotation.y, rotation.z); Matrix4x4 m = Matrix4x4.TRS(position, rotationq, scale); int i = 0; while (i < origVerts.Length) { newVerts[i] = m.MultiplyPoint3x4(origVerts[i]); i++; } mesh.vertices = newVerts; return(mesh); }