碧血红天的HomePage

U3d杂谈 — Mesh的合并

在研究动态生成NavMesh的时候,学习到了合并Mesh的方法。我们可以把多个静态的Mesh合成一个大的Mesh,这在优化方面也是非常有用的。下面我们简单讲解如何合并Mesh。

现在我们创建一个脚本,里面给一个列表,把要合并的Mesh对象添加进来。

public class MeshCombine : MonoBehaviour
{
    public List<GameObject> m_ReadyCombine = new List<GameObject>();
    // Start is called before the first frame update
    void Start()
    {
        MeshFilter[] list = GetAllMesh();
        Mesh msh = new Mesh();
        msh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
        List<CombineInstance> combineInstances = new List<CombineInstance>();
        for(int i = 0; i< list.Length;++i)
        {
            combineInstances.Add(new CombineInstance()
            {
                mesh = list[i].sharedMesh,
                transform = list[i].transform.localToWorldMatrix
            });
        }
        msh.CombineMeshes(combineInstances.ToArray());

        GameObject go = new GameObject(name);
        go.transform.position = Vector3.zero;
        go.transform.localScale = Vector3.one;
        go.transform.localRotation = Quaternion.identity;



        MeshFilter m = go.AddComponent<MeshFilter>();
        m.mesh = msh;

    }

    MeshFilter[] GetAllMesh()
    {
        List<MeshFilter> r = new List<MeshFilter>();
        for(int i = 0; i < m_ReadyCombine.Count; ++i)
        {
            MeshFilter s = m_ReadyCombine[i].GetComponent<MeshFilter>();
            if(s != null)
            {
                r.Add(s);
            }
        }
        return r.ToArray();
    }

}

Mesh有个CombineMeshes的函数,可以传入CombineInstance[]参数。这个是单个Mesh的实例。这样我们就把独立的Mesh合并为一个大的Mesh。

35 评论

  1. hi opp ggeis 2022 ert go fi

  2. viagra australia over the counter how can you get viagra online ildenafil citrate

  3. buy cialis by paypal cialis dosage strengths cialisВ® online

  4. tadalafil online paypal 200 mg tadalafil from india buy cialis uk no prescription

  5. tadalafil 5 mg generic cialis price per pill cheapest tadalafil tablets

  6. otc generic viagra viagra 50mg for sale viagra online sales

  7. cialis testimonials cialis generic online uk side effect of cialis

  8. safe place to buy viagra viagra 2010 where do you buy viagra

  9. indian pharmacy phentermine propecia inhouse pharmacy walmart pharmacy viagra

  10. permethrin online pharmacy online pharmacy delivery dubai walmart pharmacy oxycodone

  11. viagra in chennai pharmacy airmail pharmacy xanax Methocarbamol

  12. pharmacy delivery wedgewood pharmacy pet rx legitimate canada pharmacy

  13. canadian pharmacy with phentermine walgreens pharmacy store costco pharmacy prices celebrex

  14. viagra 25 mg daily viagra medicine price how to buy viagra over the counter

  15. sildenafil tablets 50mg cost of viagra per pill woman viagra

  16. pharmacy open near me Mobic adipex online us pharmacy

  17. where can you buy viagra over the counter uk purchase viagra in uk sildenafil 48 tabs 50 mg price

  18. buy 90 sildenafil 100mg price viagra price in india where to buy viagra in australia

  19. best cialis dose cialis goodrx purchase peptides tadalafil

  20. female viagra in australia buy sildenafil no prescription buy viagra online cheap no prescription

  21. sildenafil citrate tablets 100mg how to get viagra us buy online sildenafil citrate

  22. cialis 200 mg no prescription no prescription female cialis cialis maximum dose

  23. can a person buy tadalafil mylan tadalafil cost of cialis at cvs

  24. cialis 20 viagra/cialis black and gold 800 what’s the difference between viagra and cialis

  25. cialis manufacturer coupon free trial tadalafil (в„ћ) 20mg tablet tadalafil natural substitute

  26. walmart pharmacy cialis price trial pack cialis viagra levitro what does generic cialis look like

  27. cialis generic 2017 cialis sample tadalafil long term usage

  28. tadalafil vs viagra cialis diabetes does cialis make you last longer in bed

  29. viagra usa online buy sildenafil us sildenafil cheapest price in india

  30. australia viagra how much is viagra generic can i buy viagra over the counter

  31. ordering cialis online cialis free samples cialis ingredients

发表评论