码迷,mamicode.com
首页 > 其他好文 > 详细

通过组合mesh优化资源

时间:2015-11-18 09:14:35      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ConbineOpMesh : MonoBehaviour {

void Start () {
CombineToMesh (this.gameObject);
}

public void CombineToMesh(GameObject _go)
{
SkinnedMeshRenderer[] smr = _go.GetComponentsInChildren<SkinnedMeshRenderer> ();
List<CombineInstance> lcom = new List<CombineInstance> ();

List<Material> lmat = new List<Material> ();
List<Transform> ltra = new List<Transform> ();

for(int i = 0; i < smr.Length; i++)
{
lmat.AddRange(smr[i].materials);
ltra.AddRange(smr[i].bones);
for(int sub = 0; sub < smr[i].sharedMesh.subMeshCount; sub++)
{
CombineInstance ci = new CombineInstance();
ci.mesh = smr[i].sharedMesh;
ci.subMeshIndex = sub;
lcom.Add(ci);
}
Destroy (smr[i].gameObject);
}
SkinnedMeshRenderer _r = _go.GetComponent<SkinnedMeshRenderer> ();
if(_r == null)
{
_r = _go.AddComponent<SkinnedMeshRenderer>();
}
_r.sharedMesh = new Mesh ();
_r.bones = ltra.ToArray ();
_r.materials = new Material[]{lmat[0]};
_r.rootBone = _go.transform;
_r.sharedMesh.CombineMeshes (lcom.ToArray(),true,false);
}

void Update () {

}
}

通过组合mesh优化资源

标签:

原文地址:http://www.cnblogs.com/Akishimo/p/4973419.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!