相对于设置Mesh的旋转角度,设置Scale会简单很多,直接上代码:
using UnityEngine;
namespace LDFW.Model
{
public class MeshScaler : MonoBehaviour
{
public static Mesh ScaleMesh(Mesh targetMesh, Vector3 scaleMultiplier)
{
if (targetMesh == null)
{
Debug.LogError("Target mesh cannot be null");
return null;
}
Mesh newMesh = MeshGenerator.DuplicateMesh(targetMesh);
Vector3[] oldVertices = newMesh.vertices;
Vector3[] newVertices = new Vector3[oldVertices.Length];
for (int i = 0; i < oldVertices.Length; i++)
{
newVertices[i] = Vector3.Scale(oldVertices[i], scaleMultiplier);
}
newMesh.vertices = newVertices;
newMesh.RecalculateBounds();
newMesh.RecalculateNormals();
System.GC.Collect();
return newMesh;
}
}
}
网友评论