美文网首页
unity中合并网格

unity中合并网格

作者: 左撇子_7782 | 来源:发表于2018-06-21 17:56 被阅读0次

    using UnityEngine;using System.Collections;using System.Collections.Generic; public class CombineMeshes : MonoBehaviour{ void Start() { //获取MeshRender; MeshRenderer[] meshRenders = GetComponentsInChildren(); //材质; Material[] mats = new Material[meshRenders.Length]; for (int i = 0; i < meshRenders.Length; i++) { mats[i] = meshRenders[i].sharedMaterial; } //合并Mesh; MeshFilter[] meshFilters = GetComponentsInChildren(); CombineInstance[] combine = new CombineInstance[meshFilters.Length]; for (int i = 0; i < meshFilters.Length; i++) { combine[i].mesh = meshFilters[i].sharedMesh; combine[i].transform = meshFilters[i].transform.localToWorldMatrix; meshFilters[i].gameObject.SetActive(false); } MeshRenderer mr = gameObject.AddComponent(); MeshFilter mf = gameObject.AddComponent();

            mf.mesh = new Mesh();

            mf.mesh.CombineMeshes(combine, false);

            gameObject.SetActive(true);

            mr.sharedMaterials = mats;

        }

    相关文章

      网友评论

          本文标题:unity中合并网格

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