Mesh Manipulation - Mesh设置Scale

作者: ealton | 来源:发表于2017-11-29 10:00 被阅读8次

    相对于设置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;
            }
            
        }
    
    }
    

    相关文章

      网友评论

        本文标题:Mesh Manipulation - Mesh设置Scale

        本文链接:https://www.haomeiwen.com/subject/urtubxtx.html